|
1 | 1 | # Serverless Workflow Specification - Typescript SDK |
2 | 2 |
|
3 | | -Provides (TODO: add specifics) for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification) |
| 3 | +Provides the Java API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification) |
| 4 | + |
| 5 | + |
| 6 | +With the SDK you can: |
| 7 | +* Parse workflow JSON and YAML definitions |
| 8 | +* (_WIP_) Programmatically build workflow definitions |
| 9 | + |
| 10 | + |
| 11 | +## Getting Started |
| 12 | + |
| 13 | + |
| 14 | +### Building locally |
| 15 | + |
| 16 | +To build the project and run tests locally: |
| 17 | + |
| 18 | +``` |
| 19 | +git clone https://github.com/serverlessworkflow/sdk-typescript.git |
| 20 | +npm install && npm run test |
| 21 | +``` |
| 22 | + |
| 23 | + |
| 24 | +### Add as dependency to your project |
| 25 | +```sh |
| 26 | +npm install sdk-typescript |
| 27 | +``` |
| 28 | + |
| 29 | + |
| 30 | +### How to use |
| 31 | + |
| 32 | +#### Create Workflow using builder API |
| 33 | + |
| 34 | +```typescript |
| 35 | + |
| 36 | + const workflow = new WorkflowBuilder() |
| 37 | + .withId("helloworld") |
| 38 | + .withVersion("1.0") |
| 39 | + .withName("Hello World Workflow") |
| 40 | + .withDescription("Inject Hello World") |
| 41 | + .withStart("Hello State") |
| 42 | + .withStates([new InjectStateBuilder() |
| 43 | + .withName("Hello State") |
| 44 | + .withData({ |
| 45 | + "result": "Hello World!" |
| 46 | + }) |
| 47 | + .withEnd(true).build()]) |
| 48 | + .build(); |
| 49 | +``` |
| 50 | + |
| 51 | +#### Load a file JSON/YAML to a Workflow instance |
| 52 | + |
| 53 | +```typescript |
| 54 | + const workflow = BaseWorkflow.fromSource(source) |
| 55 | +``` |
| 56 | +Where source is the file location. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +#### Parse a Workflow instance to JSON/YAML |
| 61 | + |
| 62 | +Having the following workflow instance: |
| 63 | + |
| 64 | +```typescript |
| 65 | + const workflow = new WorkflowBuilder() |
| 66 | + .withId("helloworld") |
| 67 | + .withVersion("1.0") |
| 68 | + .withName("Hello World Workflow") |
| 69 | + .withDescription("Inject Hello World") |
| 70 | + .withStart("Hello State") |
| 71 | + .withStates([new InjectStateBuilder() |
| 72 | + .withName("Hello State") |
| 73 | + .withData({ |
| 74 | + "result": "Hello World!" |
| 75 | + }) |
| 76 | + .withEnd(true).build()]) |
| 77 | + .build(); |
| 78 | +``` |
| 79 | + |
| 80 | +You can convert it to its string representation in JSON or YAML format |
| 81 | +by using the static methods `toJSON` or `toYAML` respectively: |
| 82 | + |
| 83 | +```typescript |
| 84 | + const workflowAsJSON = BaseWorkflow.toJSON(workflow); |
| 85 | +``` |
| 86 | + |
| 87 | +```typescript |
| 88 | + const workFlowAsYAML = BaseWorkflow.toYAML(workflow); |
| 89 | +``` |
| 90 | + |
| 91 | + |
4 | 92 |
|
5 | | -(TODO: add description of features and small examples how to get started, use) |
|
0 commit comments