Skip to content

Latest commit

 

History

History
92 lines (63 loc) · 2.04 KB

README.md

File metadata and controls

92 lines (63 loc) · 2.04 KB

Serverless Workflow Specification - Typescript SDK

Provides the Java API/SPI for the Serverless Workflow Specification

With the SDK you can:

  • Parse workflow JSON and YAML definitions
  • (WIP) Programmatically build workflow definitions

Getting Started

Building locally

To build the project and run tests locally:

git clone https://github.com/serverlessworkflow/sdk-typescript.git
npm install && npm run test

Add as dependency to your project

npm install sdk-typescript

How to use

Create Workflow using builder API

    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({
                "result": "Hello World!"
            })
            .withEnd(true).build()])
        .build();

Load a file JSON/YAML to a Workflow instance

    const workflow = BaseWorkflow.fromSource(source)

Where source is the file location.

Parse a Workflow instance to JSON/YAML

Having the following workflow instance:

    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({
                "result": "Hello World!"
            })
            .withEnd(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:

    const workflowAsJSON = BaseWorkflow.toJSON(workflow);
    const workFlowAsYAML = BaseWorkflow.toYAML(workflow);