Skip to content

Commit

Permalink
- added current schemas/definitions/builders
Browse files Browse the repository at this point in the history
- added existing, non ported tests as .spec.old.ts
- added WorkflowValidator + README fix
- added builders extensions, used to specify a type for states
- modified definition formatting
- generated validators paths

Signed-off-by: JBBianchi <[email protected]>
  • Loading branch information
JBBianchi committed May 4, 2021
1 parent ae89b9a commit ac47afb
Show file tree
Hide file tree
Showing 94 changed files with 7,160 additions and 962 deletions.
71 changes: 38 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,22 @@ It will create a symbolic link from globally-installed `sdk-typescript` to `node
#### Create Workflow using builder API

```typescript
const workflow = workflowJsonBuilder()
.id("helloworld")
.version("1.0")
.name("Hello World Workflow")
.description("Inject Hello World")
.start("Hello State")
.states([injectstateBuilder()
.type("inject")
.name("Hello State")
.data({
"result": "Hello World!"
})
.end(true).build()])
.build());
const workflow = workflowBuilder()
.id("helloworld")
.version("1.0")
.name("Hello World Workflow")
.description("Inject Hello World")
.start("Hello State")
.states([injectstateBuilder()
.type("inject")
.name("Hello State")
.data({
"result": "Hello World!"
})
.end(true)
.build()
])
.build());
```

#### Load a file JSON/YAML to a Workflow instance
Expand All @@ -83,20 +85,22 @@ Where `source` is a JSON or a YAML string.
Having the following workflow instance:

```typescript
const workflow = workflowJsonBuilder()
.id("helloworld")
.version("1.0")
.name("Hello World Workflow")
.description("Inject Hello World")
.start("Hello State")
.states([injectstateBuilder()
.type("inject")
.name("Hello State")
.data({
"result": "Hello World!"
})
.end(true).build()])
.build());
const workflow = workflowBuilder()
.id("helloworld")
.version("1.0")
.name("Hello World Workflow")
.description("Inject Hello World")
.start("Hello State")
.states([injectstateBuilder()
.type("inject")
.name("Hello State")
.data({
"result": "Hello World!"
})
.end(true)
.build()
])
.build());
```

You can convert it to its string representation in JSON or YAML format
Expand All @@ -114,12 +118,13 @@ by using the static methods `toJson` or `toYaml` respectively:

The sdk provides a way to validate if a workflow object is compliant with the serverlessworkflow specification.

`validators` provides a map of validation functions:
`WorkflowValidator` class provides a validation method:

- `validate(): boolean`

```typescript
const validate = validators.get('WorkflowJson');
const isValid = validate(workflow);
if (!isValid) {
validate.errors.forEach(error => console.error(error.message));
const workflowValidator = new WorkflowValidator(workflow);
if (!workflowValidator.validate()) {
workflowValidator.validationErrors.forEach(error => console.error(error.message));
}
```
Loading

0 comments on commit ac47afb

Please sign in to comment.