@@ -24,7 +24,7 @@ npm install && npm run update-code-base && npm run test
2424
2525
2626### 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`
2828as dependency in your project.
2929
3030- Clone the ` sdk-typescript ` project and build it:
@@ -34,38 +34,40 @@ cd sdk-typescript
3434npm install && npm run build
3535```
3636
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:
3838``` sh
3939npm link
4040```
4141
4242- Navigate to the folder/project in which you want to use the sdk, and run the following command:
4343``` sh
44- npm link sdk-typescript
44+ npm link @severlessworkflow/ sdk-typescript
4545```
4646
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.
4848
4949
5050### How to use
5151
5252#### Create Workflow using builder API
5353
5454``` typescript
55+ import { workflowBuilder , injectstateBuilder , Specification } from ' @severlessworkflow/sdk-typescript' ;
5556
5657const workflow: Specification .Workflow = workflowBuilder ()
5758 .id (" helloworld" )
5859 .version (" 1.0" )
5960 .name (" Hello World Workflow" )
6061 .description (" Inject Hello World" )
6162 .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 ()
6971 ])
7072 .build ();
7173```
@@ -74,6 +76,8 @@ const workflow: Specification.Workflow = workflowBuilder()
7476#### Create Workflow using object literals
7577
7678``` typescript
79+ import { Specification } from ' @severlessworkflow/sdk-typescript' ;
80+
7781const workflow: Specification .Workflow = {
7882 id: ' helloworld' ,
7983 version: ' 1.0' ,
@@ -97,7 +101,9 @@ const workflow: Specification.Workflow = {
97101#### Load a file JSON/YAML to a Workflow instance
98102
99103``` typescript
100- const workflow = WorkflowConverter .fromString (source )
104+ import { Specification , WorkflowConverter } from ' @severlessworkflow/sdk-typescript' ;
105+
106+ const workflow: Specification .Workflow = WorkflowConverter .fromString (source );
101107```
102108Where ` source ` is a JSON or a YAML string.
103109
@@ -107,19 +113,22 @@ Where `source` is a JSON or a YAML string.
107113Having the following workflow instance:
108114
109115``` typescript
110- const workflow = workflowBuilder ()
116+ import { workflowBuilder , injectstateBuilder , Specification } from ' @severlessworkflow/sdk-typescript' ;
117+
118+ const workflow: Specification .Workflow = workflowBuilder ()
111119 .id (" helloworld" )
112120 .version (" 1.0" )
113121 .name (" Hello World Workflow" )
114122 .description (" Inject Hello World" )
115123 .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 ()
123132 ])
124133 .build ();
125134```
@@ -128,11 +137,15 @@ You can convert it to its string representation in JSON or YAML format
128137by using the static methods ` toJson ` or ` toYaml ` respectively:
129138
130139``` typescript
131- const workflowAsJson = WorkflowConverter .toJson (workflow );
140+ import { WorkflowConverter } from ' @severlessworkflow/sdk-typescript' ;
141+
142+ const workflowAsJson: string = WorkflowConverter .toJson (workflow );
132143```
133144
134145``` typescript
135- const workflowAsYaml = WorkflowConverter .toYaml (workflow );
146+ import { WorkflowConverter } from ' @severlessworkflow/sdk-typescript' ;
147+
148+ const workflowAsYaml: string = WorkflowConverter .toYaml (workflow );
136149```
137150
138151
@@ -145,8 +158,40 @@ The sdk provides a way to validate if a workflow object is compliant with the se
145158- ` validate(): boolean `
146159
147160``` 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 );
149181if (! 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 ));
151196}
152197```
0 commit comments