Skip to content

Commit ae89b9a

Browse files
committed
Updated README
- updated README to match the current API Signed-off-by: JBBianchi <[email protected]>
1 parent b3adf2e commit ae89b9a

File tree

1 file changed

+39
-48
lines changed

1 file changed

+39
-48
lines changed

README.md

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Provides the Typescript API/SPI for the [Serverless Workflow Specification](http
77

88
With the SDK you can:
99
* Parse workflow JSON and YAML definitions
10-
* (_WIP_) Programmatically build workflow definitions
11-
* (_WIP_) Validate workflow definitions
10+
* Programmatically build workflow definitions
11+
* Validate workflow definitions
1212

1313
## Getting Started
1414

@@ -20,7 +20,7 @@ To build the project and run tests locally:
2020
```sh
2121
git clone https://github.com/serverlessworkflow/sdk-typescript.git
2222
cd sdk-typescript
23-
npm install && npm run test
23+
npm install && npm run update-code-base && npm run test
2424
```
2525

2626

@@ -53,28 +53,28 @@ It will create a symbolic link from globally-installed `sdk-typescript` to `node
5353
#### Create Workflow using builder API
5454

5555
```typescript
56-
57-
const workflow = new WorkflowBuilder()
58-
.withId("helloworld")
59-
.withVersion("1.0")
60-
.withName("Hello World Workflow")
61-
.withDescription("Inject Hello World")
62-
.withStart("Hello State")
63-
.withStates([new InjectStateBuilder()
64-
.withName("Hello State")
65-
.withData({
56+
const workflow = workflowJsonBuilder()
57+
.id("helloworld")
58+
.version("1.0")
59+
.name("Hello World Workflow")
60+
.description("Inject Hello World")
61+
.start("Hello State")
62+
.states([injectstateBuilder()
63+
.type("inject")
64+
.name("Hello State")
65+
.data({
6666
"result": "Hello World!"
6767
})
68-
.withEnd(true).build()])
69-
.build();
68+
.end(true).build()])
69+
.build());
7070
```
7171

7272
#### Load a file JSON/YAML to a Workflow instance
7373

7474
```typescript
75-
const workflow = BaseWorkflow.fromSource(source)
75+
const workflow = WorkflowConverter.fromString(source)
7676
```
77-
Where `source` is the file location.
77+
Where `source` is a JSON or a YAML string.
7878

7979

8080

@@ -83,52 +83,43 @@ Where `source` is the file location.
8383
Having the following workflow instance:
8484

8585
```typescript
86-
const workflow = new WorkflowBuilder()
87-
.withId("helloworld")
88-
.withVersion("1.0")
89-
.withName("Hello World Workflow")
90-
.withDescription("Inject Hello World")
91-
.withStart("Hello State")
92-
.withStates([new InjectStateBuilder()
93-
.withName("Hello State")
94-
.withData({
86+
const workflow = workflowJsonBuilder()
87+
.id("helloworld")
88+
.version("1.0")
89+
.name("Hello World Workflow")
90+
.description("Inject Hello World")
91+
.start("Hello State")
92+
.states([injectstateBuilder()
93+
.type("inject")
94+
.name("Hello State")
95+
.data({
9596
"result": "Hello World!"
9697
})
97-
.withEnd(true).build()])
98-
.build();
98+
.end(true).build()])
99+
.build());
99100
```
100101

101102
You can convert it to its string representation in JSON or YAML format
102-
by using the static methods `toJSON` or `toYAML` respectively:
103+
by using the static methods `toJson` or `toYaml` respectively:
103104

104105
```typescript
105-
const workflowAsJSON = BaseWorkflow.toJSON(workflow);
106+
const workflowAsJson = WorkflowConverter.toJson(workflow);
106107
```
107108

108109
```typescript
109-
const workflowAsYAML = BaseWorkflow.toYAML(workflow);
110+
const workflowAsYaml = WorkflowConverter.toYaml(workflow);
110111
```
111112

112113
#### Validate workflow definitions
113114

114115
The sdk provides a way to validate if a workflow object is compliant with the serverlessworkflow specification.
115116

116-
`WorkflowValidator` class provides two methods:
117-
118-
- `isValid(): boolean`
119-
120-
```typescript
121-
122-
const isValid = new WorkflowValidator(workflow).isValid();
123-
124-
```
125-
126-
- `validate(): ValidationErrors`
117+
`validators` provides a map of validation functions:
127118

128119
```typescript
129-
130-
const validationErrors = new WorkflowValidator(workflow).validate();
131-
validationErrors.errors().forEach(error => console.error(error.message()))
132-
133-
134-
```
120+
const validate = validators.get('WorkflowJson');
121+
const isValid = validate(workflow);
122+
if (!isValid) {
123+
validate.errors.forEach(error => console.error(error.message));
124+
}
125+
```

0 commit comments

Comments
 (0)