@@ -53,20 +53,22 @@ 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
- const workflow = workflowJsonBuilder ()
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
- .type (" inject" )
64
- .name (" Hello State" )
65
- .data ({
66
- " result" : " Hello World!"
67
- })
68
- .end (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
+ .type (" inject" )
64
+ .name (" Hello State" )
65
+ .data ({
66
+ " result" : " Hello World!"
67
+ })
68
+ .end (true )
69
+ .build ()
70
+ ])
71
+ .build ());
70
72
```
71
73
72
74
#### Load a file JSON/YAML to a Workflow instance
@@ -83,20 +85,22 @@ Where `source` is a JSON or a YAML string.
83
85
Having the following workflow instance:
84
86
85
87
``` typescript
86
- const workflow = workflowJsonBuilder ()
87
- .id (" helloworld" )
88
- .version (" 1.0" )
89
- .name (" Hello World Workflow" )
90
- .description (" Inject Hello World" )
91
- .start (" Hello State" )
92
- .states ([injectstateBuilder ()
93
- .type (" inject" )
94
- .name (" Hello State" )
95
- .data ({
96
- " result" : " Hello World!"
97
- })
98
- .end (true ).build ()])
99
- .build ());
88
+ const workflow = workflowBuilder ()
89
+ .id (" helloworld" )
90
+ .version (" 1.0" )
91
+ .name (" Hello World Workflow" )
92
+ .description (" Inject Hello World" )
93
+ .start (" Hello State" )
94
+ .states ([injectstateBuilder ()
95
+ .type (" inject" )
96
+ .name (" Hello State" )
97
+ .data ({
98
+ " result" : " Hello World!"
99
+ })
100
+ .end (true )
101
+ .build ()
102
+ ])
103
+ .build ());
100
104
```
101
105
102
106
You can convert it to its string representation in JSON or YAML format
@@ -114,12 +118,13 @@ by using the static methods `toJson` or `toYaml` respectively:
114
118
115
119
The sdk provides a way to validate if a workflow object is compliant with the serverlessworkflow specification.
116
120
117
- ` validators ` provides a map of validation functions:
121
+ ` WorkflowValidator ` class provides a validation method:
122
+
123
+ - ` validate(): boolean `
118
124
119
125
``` typescript
120
- const validate = validators .get (' WorkflowJson' );
121
- const isValid = validate (workflow );
122
- if (! isValid ) {
123
- validate .errors .forEach (error => console .error (error .message ));
126
+ const workflowValidator = new WorkflowValidator (workflow );
127
+ if (! workflowValidator .validate ()) {
128
+ workflowValidator .validationErrors .forEach (error => console .error (error .message ));
124
129
}
125
130
```
0 commit comments