110110 set:
111111 variable: 'my first workflow'
112112` ;
113- const workflowDefinition = Classes .Workflow .deserialize (text );
113+ const workflow = Classes .Workflow .deserialize (text );
114114```
115115
116116#### 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:
120120import { Classes , Specification , validate } from ' @serverlessworkflow/sdk' ;
121121
122122// Simply cast an object:
123- const workflowDefinition = {
123+ const workflow = {
124124 document: {
125125 dsl: ' 1.0.0' ,
126126 name: ' test' ,
@@ -140,9 +140,9 @@ const workflowDefinition = {
140140
141141// Validate it
142142try {
143- validate (' Workflow' , workflowDefinition );
143+ validate (' Workflow' , workflow );
144144 // Serialize it
145- const definitionTxt = Classes .Workflow .serialize (workflowDefinition );
145+ const definitionTxt = Classes .Workflow .serialize (workflow );
146146}
147147catch (ex ) {
148148 // Invalid workflow definition
@@ -156,7 +156,7 @@ You can create a workflow definition by calling a constructor:
156156import { Classes , validate } from ' @serverlessworkflow/sdk' ;
157157
158158// Simply use the constructor
159- const workflowDefinition = new Classes .Workflow ({
159+ const workflow = new Classes .Workflow ({
160160 document: {
161161 dsl: ' 1.0.0' ,
162162 name: ' test' ,
@@ -173,7 +173,7 @@ const workflowDefinition = new Classes.Workflow({
173173 },
174174 */ ],
175175});
176- workflowDefinition .do .push ({
176+ workflow .do .push ({
177177 step1: new Classes .SetTask ({
178178 set: {
179179 variable: ' my first workflow' ,
@@ -183,9 +183,9 @@ workflowDefinition.do.push({
183183
184184// Validate it
185185try {
186- workflowDefinition .validate ();
186+ workflow .validate ();
187187 // Serialize it
188- const definitionTxt = workflowDefinition .serialize ();
188+ const definitionTxt = workflow .serialize ();
189189}
190190catch (ex ) {
191191 // Invalid workflow definition
@@ -198,7 +198,7 @@ You can use the fluent API to build a validated and normalized workflow definiti
198198``` typescript
199199import { documentBuilder , setTaskBuilder , taskListBuilder , workflowBuilder } from ' @serverlessworkflow/sdk' ;
200200
201- const workflowDefinition = workflowBuilder (/* workflowDefinitionObject */ )
201+ const workflow = workflowBuilder (/* workflowObject */ )
202202 .document (
203203 documentBuilder ()
204204 .dsl (' 1.0.0' )
@@ -230,12 +230,12 @@ You can serialize a workflow definition either by using its `serialize` method i
230230``` typescript
231231import { Classes } from ' @serverlessworkflow/sdk' ;
232232
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' */ );
236236}
237237else {
238- const json = Classes .Workflow .serialize (workflowDefinition , ' json' );
238+ const json = Classes .Workflow .serialize (workflow , ' json' );
239239}
240240```
241241> [ !NOTE]
@@ -247,13 +247,13 @@ Validation can be achieved in two ways: via the `validate` function or the insta
247247``` typescript
248248import { Classes , validate } from ' @serverlessworkflow/sdk' ;
249249
250- const workflowDefinition = /* <Your preferred method> */ ;
250+ const workflow = /* <Your preferred method> */ ;
251251try {
252- if (workflowDefinition instanceof Classes .Workflow ) {
253- workflowDefinition .validate ();
252+ if (workflow instanceof Classes .Workflow ) {
253+ workflow .validate ();
254254 }
255255 else {
256- validate (' Workflow' , workflowDefinition );
256+ validate (' Workflow' , workflow );
257257 }
258258}
259259catch (ex ) {
@@ -262,12 +262,14 @@ catch (ex) {
262262```
263263
264264#### 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) `
266268
267269``` typescript
268270import { buildGraph } from ' @serverlessworkflow/sdk' ;
269271
270- const workflowDefinition = {
272+ const workflow = {
271273 document: {
272274 dsl: ' 1.0.0' ,
273275 name: ' using-plain-object' ,
@@ -284,7 +286,9 @@ const workflowDefinition = {
284286 },
285287 ],
286288};
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);
288292/* {
289293 id: 'root',
290294 type: 'root',
@@ -298,12 +302,14 @@ const graph = buildGraph(workflowDefinition);
298302```
299303
300304#### 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) `
302308
303309``` typescript
304310import { convertToMermaidCode , MermaidDiagram } from ' @serverlessworkflow/sdk' ;
305311
306- const workflowDefinition = {
312+ const workflow = {
307313 document: {
308314 dsl: ' 1.0.0' ,
309315 name: ' using-plain-object' ,
@@ -320,7 +326,10 @@ const workflowDefinition = {
320326 },
321327 ],
322328};
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);
324333/*
325334flowchart TD
326335 root-entry-node(( ))
0 commit comments