Skip to content

tsurdilo/sdk-typescript

 
 

Repository files navigation

Serverless Workflow Specification - Typescript SDK

Provides the Typescript API/SPI for the Serverless Workflow Specification

With the SDK you can:

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

Getting Started

Building locally

To build the project and run tests locally:

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

Add as dependency to your project

You can use npm link to add the sdk-typescript as dependency in your project.

  • Clone the sdk-typescript project and build it:
git clone https://github.com/serverlessworkflow/sdk-typescript.git
cd sdk-typescript
npm install && npm run build
  • Make the package visible globally to npm. Inside the sdk-typescript project folder run:
npm link
  • Navigate to the folder/project in which you want to use the sdk, and run the following command:
npm link sdk-typescript

It will create a symbolic link from globally-installed sdk-typescript to node_modules/ of the current folder.

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);

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
const isValid = new WorkflowValidator(workflow).isValid();
  • validate(): ValidationErrors
const validationErrors = new WorkflowValidator(workflow).validate();
validationErrors.errors().forEach(error => console.error(error.message()))

About

Typescript SDK for Serverless Workflow

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 100.0%
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy