@@ -7,8 +7,8 @@ Provides the Typescript API/SPI for the [Serverless Workflow Specification](http
7
7
8
8
With the SDK you can:
9
9
* 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
12
12
13
13
## Getting Started
14
14
@@ -20,7 +20,7 @@ To build the project and run tests locally:
20
20
``` sh
21
21
git clone https://github.com/serverlessworkflow/sdk-typescript.git
22
22
cd sdk-typescript
23
- npm install && npm run test
23
+ npm install && npm run update-code-base && npm run test
24
24
```
25
25
26
26
@@ -53,28 +53,29 @@ It will create a symbolic link from globally-installed `sdk-typescript` to `node
53
53
#### Create Workflow using builder API
54
54
55
55
``` 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 ({
66
- " result" : " Hello World!"
67
- })
68
- .withEnd (true ).build ()])
69
- .build ();
56
+ const workflow = workflowBuilder ()
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
+ .name (" Hello State" )
64
+ .data ({
65
+ " result" : " Hello World!"
66
+ })
67
+ .end (true )
68
+ .build ()
69
+ ])
70
+ .build ();
70
71
```
71
72
72
73
#### Load a file JSON/YAML to a Workflow instance
73
74
74
75
``` typescript
75
- const workflow = BaseWorkflow . fromSource (source )
76
+ const workflow = WorkflowConverter . fromString (source )
76
77
```
77
- Where ` source ` is the file location .
78
+ Where ` source ` is a JSON or a YAML string .
78
79
79
80
80
81
@@ -83,52 +84,45 @@ Where `source` is the file location.
83
84
Having the following workflow instance:
84
85
85
86
``` 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 ({
95
- " result" : " Hello World!"
96
- })
97
- .withEnd (true ).build ()])
98
- .build ();
87
+ const workflow = workflowBuilder ()
88
+ .id (" helloworld" )
89
+ .version (" 1.0" )
90
+ .name (" Hello World Workflow" )
91
+ .description (" Inject Hello World" )
92
+ .start (" Hello State" )
93
+ .states ([injectstateBuilder ()
94
+ .name (" Hello State" )
95
+ .data ({
96
+ " result" : " Hello World!"
97
+ })
98
+ .end (true )
99
+ .build ()
100
+ ])
101
+ .build ();
99
102
```
100
103
101
104
You can convert it to its string representation in JSON or YAML format
102
- by using the static methods ` toJSON ` or ` toYAML ` respectively:
105
+ by using the static methods ` toJson ` or ` toYaml ` respectively:
103
106
104
107
``` typescript
105
- const workflowAsJSON = BaseWorkflow . toJSON (workflow );
108
+ const workflowAsJson = WorkflowConverter . toJson (workflow );
106
109
```
107
110
108
111
``` typescript
109
- const workflowAsYAML = BaseWorkflow . toYAML (workflow );
112
+ const workflowAsYaml = WorkflowConverter . toYaml (workflow );
110
113
```
111
114
112
115
#### Validate workflow definitions
113
116
114
117
The sdk provides a way to validate if a workflow object is compliant with the serverlessworkflow specification.
115
118
116
- ` WorkflowValidator ` class provides two methods :
119
+ ` WorkflowValidator ` class provides a validation method :
117
120
118
- - ` isValid (): boolean`
121
+ - ` validate (): boolean`
119
122
120
123
``` typescript
121
-
122
- const isValid = new WorkflowValidator (workflow ).isValid ();
123
-
124
- ```
125
-
126
- - ` validate(): ValidationErrors `
127
-
128
- ``` typescript
129
-
130
- const validationErrors = new WorkflowValidator (workflow ).validate ();
131
- validationErrors .errors ().forEach (error => console .error (error .message ()))
132
-
133
-
134
- ```
124
+ const workflowValidator = new WorkflowValidator (workflow );
125
+ if (! workflowValidator .validate ()) {
126
+ workflowValidator .validationErrors .forEach (error => console .error (error .message ));
127
+ }
128
+ ```
0 commit comments