@@ -24,7 +24,7 @@ npm install && npm run update-code-base && npm run test
24
24
25
25
26
26
### Add as dependency to your project
27
- You can use [ npm link] ( https://docs.npmjs.com/cli/v7/commands/npm-link ) to add the ` sdk-typescript `
27
+ You can use [ npm link] ( https://docs.npmjs.com/cli/v7/commands/npm-link ) to add the ` @severlessworkflow/ sdk-typescript`
28
28
as dependency in your project.
29
29
30
30
- Clone the ` sdk-typescript ` project and build it:
@@ -34,38 +34,40 @@ cd sdk-typescript
34
34
npm install && npm run build
35
35
```
36
36
37
- - Make the package visible globally to npm. Inside the ` sdk-typescript ` project folder run:
37
+ - Make the package visible globally to npm. Inside the ` sdk-typescript\dist ` project folder run:
38
38
``` sh
39
39
npm link
40
40
```
41
41
42
42
- Navigate to the folder/project in which you want to use the sdk, and run the following command:
43
43
``` sh
44
- npm link sdk-typescript
44
+ npm link @severlessworkflow/ sdk-typescript
45
45
```
46
46
47
- It will create a symbolic link from globally-installed ` sdk-typescript ` to ` node_modules/ ` of the current folder.
47
+ It will create a symbolic link from globally-installed ` @severlessworkflow/ sdk-typescript` to ` node_modules/ ` of the current folder.
48
48
49
49
50
50
### How to use
51
51
52
52
#### Create Workflow using builder API
53
53
54
54
``` typescript
55
+ import { workflowBuilder , injectstateBuilder , Specification } from ' @severlessworkflow/sdk-typescript' ;
55
56
56
57
const workflow: Specification .Workflow = workflowBuilder ()
57
58
.id (" helloworld" )
58
59
.version (" 1.0" )
59
60
.name (" Hello World Workflow" )
60
61
.description (" Inject Hello World" )
61
62
.start (" Hello State" )
62
- .states ([injectstateBuilder ()
63
- .name (" Hello State" )
64
- .data ({
65
- " result" : " Hello World!"
66
- })
67
- .end (true )
68
- .build ()
63
+ .states ([
64
+ injectstateBuilder ()
65
+ .name (" Hello State" )
66
+ .data ({
67
+ " result" : " Hello World!"
68
+ })
69
+ .end (true )
70
+ .build ()
69
71
])
70
72
.build ();
71
73
```
@@ -74,6 +76,8 @@ const workflow: Specification.Workflow = workflowBuilder()
74
76
#### Create Workflow using object literals
75
77
76
78
``` typescript
79
+ import { Specification } from ' @severlessworkflow/sdk-typescript' ;
80
+
77
81
const workflow: Specification .Workflow = {
78
82
id: ' helloworld' ,
79
83
version: ' 1.0' ,
@@ -97,7 +101,9 @@ const workflow: Specification.Workflow = {
97
101
#### Load a file JSON/YAML to a Workflow instance
98
102
99
103
``` typescript
100
- const workflow = WorkflowConverter .fromString (source )
104
+ import { Specification , WorkflowConverter } from ' @severlessworkflow/sdk-typescript' ;
105
+
106
+ const workflow: Specification .Workflow = WorkflowConverter .fromString (source );
101
107
```
102
108
Where ` source ` is a JSON or a YAML string.
103
109
@@ -107,19 +113,22 @@ Where `source` is a JSON or a YAML string.
107
113
Having the following workflow instance:
108
114
109
115
``` typescript
110
- const workflow = workflowBuilder ()
116
+ import { workflowBuilder , injectstateBuilder , Specification } from ' @severlessworkflow/sdk-typescript' ;
117
+
118
+ const workflow: Specification .Workflow = workflowBuilder ()
111
119
.id (" helloworld" )
112
120
.version (" 1.0" )
113
121
.name (" Hello World Workflow" )
114
122
.description (" Inject Hello World" )
115
123
.start (" Hello State" )
116
- .states ([injectstateBuilder ()
117
- .name (" Hello State" )
118
- .data ({
119
- " result" : " Hello World!"
120
- })
121
- .end (true )
122
- .build ()
124
+ .states ([
125
+ injectstateBuilder ()
126
+ .name (" Hello State" )
127
+ .data ({
128
+ " result" : " Hello World!"
129
+ })
130
+ .end (true )
131
+ .build ()
123
132
])
124
133
.build ();
125
134
```
@@ -128,11 +137,15 @@ You can convert it to its string representation in JSON or YAML format
128
137
by using the static methods ` toJson ` or ` toYaml ` respectively:
129
138
130
139
``` typescript
131
- const workflowAsJson = WorkflowConverter .toJson (workflow );
140
+ import { WorkflowConverter } from ' @severlessworkflow/sdk-typescript' ;
141
+
142
+ const workflowAsJson: string = WorkflowConverter .toJson (workflow );
132
143
```
133
144
134
145
``` typescript
135
- const workflowAsYaml = WorkflowConverter .toYaml (workflow );
146
+ import { WorkflowConverter } from ' @severlessworkflow/sdk-typescript' ;
147
+
148
+ const workflowAsYaml: string = WorkflowConverter .toYaml (workflow );
136
149
```
137
150
138
151
@@ -145,8 +158,40 @@ The sdk provides a way to validate if a workflow object is compliant with the se
145
158
- ` validate(): boolean `
146
159
147
160
``` typescript
148
- const workflowValidator = new WorkflowValidator (workflow );
161
+ import { WorkflowValidator , Specification } from ' @severlessworkflow/sdk-typescript' ;
162
+
163
+ const workflow: Specification .Workflow = {
164
+ id: ' helloworld' ,
165
+ version: ' 1.0' ,
166
+ name: ' Hello World Workflow' ,
167
+ description: ' Inject Hello World' ,
168
+ start: ' Hello State' ,
169
+ states: [
170
+ {
171
+ type: ' inject' ,
172
+ name: ' Hello State' ,
173
+ end: true ,
174
+ data: {
175
+ result: " Hello World!"
176
+ }
177
+ } as Specification .Injectstate
178
+ ]
179
+ };
180
+ const workflowValidator: WorkflowValidator = new WorkflowValidator (workflow );
149
181
if (! workflowValidator .validate ()) {
150
- workflowValidator .validationErrors .forEach (error => console .error (error .message ));
182
+ workflowValidator .errors .forEach (error => console .error (error .message ));
183
+ }
184
+ ```
185
+
186
+ You can also validate parts of a workflow using ` validators ` :
187
+
188
+ ``` typescript
189
+ import { ValidateFunction } from ' ajv' ;
190
+ import { validators , Specification } from ' @severlessworkflow/sdk-typescript' ;
191
+
192
+ const injectionState: Specification .Injectstate = workflow .states [0 ];
193
+ const injectionStateValidator: ValidateFunction <Specification .Injectstate > = validators .get (' Injectstate' );
194
+ if (! injectionStateValidator (injectionState )) {
195
+ injectionStateValidator .errors .forEach (error => console .error (error .message ));
151
196
}
152
197
```
0 commit comments