From ae89b9a664e1df4fef9bf8d494f28b4c5a3faa1e Mon Sep 17 00:00:00 2001 From: JBBianchi Date: Mon, 3 May 2021 14:35:03 +0200 Subject: [PATCH] Updated README - updated README to match the current API Signed-off-by: JBBianchi --- README.md | 87 +++++++++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index ddc8432..f3f9050 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 ``` @@ -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. @@ -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)); +} +``` \ No newline at end of file