110
110
set:
111
111
variable: 'my first workflow'
112
112
` ;
113
- const workflowDefinition = Classes .Workflow .deserialize (text );
113
+ const workflow = Classes .Workflow .deserialize (text );
114
114
```
115
115
116
116
#### Create a Workflow Definition by Casting an Object
@@ -120,7 +120,7 @@ You can type-cast an object to match the structure of a workflow definition:
120
120
import { Classes , Specification , validate } from ' @serverlessworkflow/sdk' ;
121
121
122
122
// Simply cast an object:
123
- const workflowDefinition = {
123
+ const workflow = {
124
124
document: {
125
125
dsl: ' 1.0.0' ,
126
126
name: ' test' ,
@@ -140,9 +140,9 @@ const workflowDefinition = {
140
140
141
141
// Validate it
142
142
try {
143
- validate (' Workflow' , workflowDefinition );
143
+ validate (' Workflow' , workflow );
144
144
// Serialize it
145
- const definitionTxt = Classes .Workflow .serialize (workflowDefinition );
145
+ const definitionTxt = Classes .Workflow .serialize (workflow );
146
146
}
147
147
catch (ex ) {
148
148
// Invalid workflow definition
@@ -156,7 +156,7 @@ You can create a workflow definition by calling a constructor:
156
156
import { Classes , validate } from ' @serverlessworkflow/sdk' ;
157
157
158
158
// Simply use the constructor
159
- const workflowDefinition = new Classes .Workflow ({
159
+ const workflow = new Classes .Workflow ({
160
160
document: {
161
161
dsl: ' 1.0.0' ,
162
162
name: ' test' ,
@@ -173,7 +173,7 @@ const workflowDefinition = new Classes.Workflow({
173
173
},
174
174
*/ ],
175
175
});
176
- workflowDefinition .do .push ({
176
+ workflow .do .push ({
177
177
step1: new Classes .SetTask ({
178
178
set: {
179
179
variable: ' my first workflow' ,
@@ -183,9 +183,9 @@ workflowDefinition.do.push({
183
183
184
184
// Validate it
185
185
try {
186
- workflowDefinition .validate ();
186
+ workflow .validate ();
187
187
// Serialize it
188
- const definitionTxt = workflowDefinition .serialize ();
188
+ const definitionTxt = workflow .serialize ();
189
189
}
190
190
catch (ex ) {
191
191
// Invalid workflow definition
@@ -198,7 +198,7 @@ You can use the fluent API to build a validated and normalized workflow definiti
198
198
``` typescript
199
199
import { documentBuilder , setTaskBuilder , taskListBuilder , workflowBuilder } from ' @serverlessworkflow/sdk' ;
200
200
201
- const workflowDefinition = workflowBuilder (/* workflowDefinitionObject */ )
201
+ const workflow = workflowBuilder (/* workflowObject */ )
202
202
.document (
203
203
documentBuilder ()
204
204
.dsl (' 1.0.0' )
@@ -230,12 +230,12 @@ You can serialize a workflow definition either by using its `serialize` method i
230
230
``` typescript
231
231
import { Classes } from ' @serverlessworkflow/sdk' ;
232
232
233
- // const workflowDefinition = <Your preferred method>;
234
- if (workflowDefinition instanceof Classes .Workflow ) {
235
- const yaml = workflowDefinition .serialize (/* 'yaml' | 'json' */ );
233
+ // const workflow = <Your preferred method>;
234
+ if (workflow instanceof Classes .Workflow ) {
235
+ const yaml = workflow .serialize (/* 'yaml' | 'json' */ );
236
236
}
237
237
else {
238
- const json = Classes .Workflow .serialize (workflowDefinition , ' json' );
238
+ const json = Classes .Workflow .serialize (workflow , ' json' );
239
239
}
240
240
```
241
241
> [ !NOTE]
@@ -247,13 +247,13 @@ Validation can be achieved in two ways: via the `validate` function or the insta
247
247
``` typescript
248
248
import { Classes , validate } from ' @serverlessworkflow/sdk' ;
249
249
250
- const workflowDefinition = /* <Your preferred method> */ ;
250
+ const workflow = /* <Your preferred method> */ ;
251
251
try {
252
- if (workflowDefinition instanceof Classes .Workflow ) {
253
- workflowDefinition .validate ();
252
+ if (workflow instanceof Classes .Workflow ) {
253
+ workflow .validate ();
254
254
}
255
255
else {
256
- validate (' Workflow' , workflowDefinition );
256
+ validate (' Workflow' , workflow );
257
257
}
258
258
}
259
259
catch (ex ) {
@@ -262,12 +262,14 @@ catch (ex) {
262
262
```
263
263
264
264
#### Generate a directed graph
265
- A [ directed graph] ( https://en.wikipedia.org/wiki/Directed_graph ) of a workflow can be generated using the ` buildGraph ` function:
265
+ A [ directed graph] ( https://en.wikipedia.org/wiki/Directed_graph ) of a workflow can be generated using the ` buildGraph ` function, or alternatives:
266
+ - Workflow instance ` .toGraph(); `
267
+ - Static ` Classes.Workflow.toGraph(workflow) `
266
268
267
269
``` typescript
268
270
import { buildGraph } from ' @serverlessworkflow/sdk' ;
269
271
270
- const workflowDefinition = {
272
+ const workflow = {
271
273
document: {
272
274
dsl: ' 1.0.0' ,
273
275
name: ' using-plain-object' ,
@@ -284,7 +286,9 @@ const workflowDefinition = {
284
286
},
285
287
],
286
288
};
287
- const graph = buildGraph (workflowDefinition );
289
+ const graph = buildGraph (workflow );
290
+ // const workflow = new Classes.Workflow({...}); const graph = workflow.toGraph();
291
+ // const graph = Classes.Workflow.toGraph(workflow);
288
292
/* {
289
293
id: 'root',
290
294
type: 'root',
@@ -298,12 +302,14 @@ const graph = buildGraph(workflowDefinition);
298
302
```
299
303
300
304
#### Generate a MermaidJS flowchart
301
- Generating a [ MermaidJS] ( https://mermaid.js.org/ ) flowchart can be achieved in two ways: using the ` convertToMermaidCode ` or the legacy ` MermaidDiagram ` class.
305
+ Generating a [ MermaidJS] ( https://mermaid.js.org/ ) flowchart can be achieved in two ways: using the ` convertToMermaidCode ` , the legacy ` MermaidDiagram ` class, or alternatives:
306
+ - Workflow instance ` .toMermaidCode(); `
307
+ - Static ` Classes.Workflow.toMermaidCode(workflow) `
302
308
303
309
``` typescript
304
310
import { convertToMermaidCode , MermaidDiagram } from ' @serverlessworkflow/sdk' ;
305
311
306
- const workflowDefinition = {
312
+ const workflow = {
307
313
document: {
308
314
dsl: ' 1.0.0' ,
309
315
name: ' using-plain-object' ,
@@ -320,7 +326,10 @@ const workflowDefinition = {
320
326
},
321
327
],
322
328
};
323
- const mermaidCode = convertToMermaidCode (workflowDefinition ) /* or new MermaidDiagram(workflowDefinition).sourceCode() */ ;
329
+ const mermaidCode = convertToMermaidCode (workflow ) /* or */ ;
330
+ // const mermaidCode = new MermaidDiagram(workflow).sourceCode();
331
+ // const workflow = new Classes.Workflow({...}); const mermaidCode = workflow.toMermaidCode();
332
+ // const mermaidCode = Classes.Workflow.toMermaidCode(workflow);
324
333
/*
325
334
flowchart TD
326
335
root-entry-node(( ))
0 commit comments