Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
- updated README to match the current API

Signed-off-by: JBBianchi <[email protected]>
  • Loading branch information
JBBianchi committed May 3, 2021
1 parent b3adf2e commit ae89b9a
Showing 1 changed file with 39 additions and 48 deletions.
87 changes: 39 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Provides the Typescript API/SPI for the [Serverless Workflow Specification](http

With the SDK you can:
* Parse workflow JSON and YAML definitions
* (_WIP_) Programmatically build workflow definitions
* (_WIP_) Validate workflow definitions
* Programmatically build workflow definitions
* Validate workflow definitions

## Getting Started

Expand All @@ -20,7 +20,7 @@ To build the project and run tests locally:
```sh
git clone https://github.com/serverlessworkflow/sdk-typescript.git
cd sdk-typescript
npm install && npm run test
npm install && npm run update-code-base && npm run test
```


Expand Down Expand Up @@ -53,28 +53,28 @@ It will create a symbolic link from globally-installed `sdk-typescript` to `node
#### Create Workflow using builder API

```typescript

const workflow = new WorkflowBuilder()
.withId("helloworld")
.withVersion("1.0")
.withName("Hello World Workflow")
.withDescription("Inject Hello World")
.withStart("Hello State")
.withStates([new InjectStateBuilder()
.withName("Hello State")
.withData({
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!"
})
.withEnd(true).build()])
.build();
.end(true).build()])
.build());
```

#### Load a file JSON/YAML to a Workflow instance

```typescript
const workflow = BaseWorkflow.fromSource(source)
const workflow = WorkflowConverter.fromString(source)
```
Where `source` is the file location.
Where `source` is a JSON or a YAML string.



Expand All @@ -83,52 +83,43 @@ Where `source` is the file location.
Having the following workflow instance:

```typescript
const workflow = new WorkflowBuilder()
.withId("helloworld")
.withVersion("1.0")
.withName("Hello World Workflow")
.withDescription("Inject Hello World")
.withStart("Hello State")
.withStates([new InjectStateBuilder()
.withName("Hello State")
.withData({
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!"
})
.withEnd(true).build()])
.build();
.end(true).build()])
.build());
```

You can convert it to its string representation in JSON or YAML format
by using the static methods `toJSON` or `toYAML` respectively:
by using the static methods `toJson` or `toYaml` respectively:

```typescript
const workflowAsJSON = BaseWorkflow.toJSON(workflow);
const workflowAsJson = WorkflowConverter.toJson(workflow);
```

```typescript
const workflowAsYAML = BaseWorkflow.toYAML(workflow);
const workflowAsYaml = WorkflowConverter.toYaml(workflow);
```

#### Validate workflow definitions

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

`WorkflowValidator` class provides two methods:

- `isValid(): boolean`

```typescript

const isValid = new WorkflowValidator(workflow).isValid();

```

- `validate(): ValidationErrors`
`validators` provides a map of validation functions:

```typescript

const validationErrors = new WorkflowValidator(workflow).validate();
validationErrors.errors().forEach(error => console.error(error.message()))


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

0 comments on commit ae89b9a

Please sign in to comment.