All Projects → serverlessworkflow → sdk-typescript

serverlessworkflow / sdk-typescript

Licence: Apache-2.0 license
Typescript SDK for Serverless Workflow

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to sdk-typescript

sdk-go
Go SDK for Serverless Workflow
Stars: ✭ 57 (+35.71%)
Mutual labels:  cncf, serverless-workflow
sdk-java
Java SDK for Serverless Workflow
Stars: ✭ 48 (+14.29%)
Mutual labels:  cncf, serverless-workflow
Kops
Kubernetes Operations (kops) - Production Grade K8s Installation, Upgrades, and Management
Stars: ✭ 13,601 (+32283.33%)
Mutual labels:  cncf
Netdata
Real-time performance monitoring, done right! https://www.netdata.cloud
Stars: ✭ 57,056 (+135747.62%)
Mutual labels:  cncf
Harbor
An open source trusted cloud native registry project that stores, signs, and scans content.
Stars: ✭ 16,320 (+38757.14%)
Mutual labels:  cncf
Chubaofs
ChubaoFS (abbrev. CBFS) is a cloud native distributed file system and object store.
Stars: ✭ 2,482 (+5809.52%)
Mutual labels:  cncf
Hub
For the distributed charts search at hub.helm.sh
Stars: ✭ 239 (+469.05%)
Mutual labels:  cncf
Kuma
🐻 The Universal Service Mesh. CNCF Sandbox Project.
Stars: ✭ 2,516 (+5890.48%)
Mutual labels:  cncf
kubernetes-101-workshop
Kubernetes 101 workshop for beginners.
Stars: ✭ 17 (-59.52%)
Mutual labels:  cncf
Notary
Notary is a project that allows anyone to have trust over arbitrary collections of data
Stars: ✭ 2,715 (+6364.29%)
Mutual labels:  cncf
Contour
Contour is a Kubernetes ingress controller using Envoy proxy.
Stars: ✭ 2,985 (+7007.14%)
Mutual labels:  cncf
Foundation
☁️♮🏛File non-technical issues related to CNCF
Stars: ✭ 208 (+395.24%)
Mutual labels:  cncf
Sonobuoy
Sonobuoy is a diagnostic tool that makes it easier to understand the state of a Kubernetes cluster by running a set of Kubernetes conformance tests and other plugins in an accessible and non-destructive manner.
Stars: ✭ 2,442 (+5714.29%)
Mutual labels:  cncf
Artwork
🎨CNCF-related logos and artwork
Stars: ✭ 240 (+471.43%)
Mutual labels:  cncf
Jaeger
CNCF Jaeger, a Distributed Tracing Platform
Stars: ✭ 14,813 (+35169.05%)
Mutual labels:  cncf
Kubernetes
Production-Grade Container Scheduling and Management
Stars: ✭ 83,715 (+199221.43%)
Mutual labels:  cncf
Cloudskew
Create free cloud architecture diagrams
Stars: ✭ 183 (+335.71%)
Mutual labels:  cncf
Community
Helm community content
Stars: ✭ 211 (+402.38%)
Mutual labels:  cncf
Curriculum
📚Open Source Curriculum for CNCF Certification Courses
Stars: ✭ 3,257 (+7654.76%)
Mutual labels:  cncf
client-java
TiKV Java Client
Stars: ✭ 92 (+119.05%)
Mutual labels:  cncf

Node CI Gitpod ready-to-code

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
  • Programmatically build workflow definitions
  • Validate workflow definitions

Status

Latest Releases Conformance to spec version
v1.0.0 v0.6
v2.0.0 v0.7
v3.0.0 v0.8

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 build && npm run test

How to use

Install

Version >= 4.0.0

Note: Version 4.0.0 has not been released yet.

npm i @serverlessworkflow/sdk-typescript
Version < 4.0.0
npm i @severlessworkflow/sdk-typescript

Create Workflow using builder API

import { workflowBuilder, injectstateBuilder, Specification } from '@serverlessworkflow/sdk-typescript';

const workflow: Specification.Workflow = workflowBuilder()
  .id("helloworld")
  .specVersion("0.8")
  .version("1.0")
  .name("Hello World Workflow")
  .description("Inject Hello World")
  .start("Hello State")
  .states([
    injectstateBuilder()
      .name("Hello State")
      .data({
          "result": "Hello World!"
      })
      .build()
  ])
  .build();

Create Workflow from JSON/YAML source

import { Specification, Workflow } from '@serverlessworkflow/sdk-typescript';

const source = `id: helloworld
version: '1.0'
specVerion: '0.8'
name: Hello World Workflow
description: Inject Hello World
start: Hello State
states:
  - type: inject
    name: Hello State
    data:
      result: Hello World!
    end: true`

const workflow: Specification.Workflow = Workflow.fromSource(source);

Where source can be in both JSON or YAML format.

Parse a Workflow instance to JSON/YAML

Having the following workflow instance:

import { workflowBuilder, injectstateBuilder, Specification } from '@serverlessworkflow/sdk-typescript';

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

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

import {Specification, workflowBuilder} from "@severlessworkflow/sdk-typescript";

const workflow: Specification.Workflow = workflowBuilder()
    //...
    .build()

const workflowAsJson: string = Specification.Workflow.toJson(workflow);
import {Specification, workflowBuilder} from "@severlessworkflow/sdk-typescript";

const workflow: Specification.Workflow = workflowBuilder()
    //...
    .build()

const workflowAsYaml: string = Specification.Workflow.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 a validation method:

  • validate(): boolean
import {WorkflowValidator, Specification} from '@serverlessworkflow/sdk-typescript';
import {Workflow} from "./workflow";

const workflow = {
    id: 'helloworld',
    version: '1.0',
    specVersion: '0.3',
    name: 'Hello World Workflow',
    description: 'Inject Hello World',
    start: 'Hello State',
    states: [
        {
            type: 'inject',
            name: 'Hello State',
            end: true,
            data: {
                result: "Hello World!"
            }
        }
    ]
};

const workflowValidator: WorkflowValidator = new WorkflowValidator(Workflow.fromSource(JSON.stringify(workflow)));
if (!workflowValidator.isValid) {
    workflowValidator.errors.forEach(error => console.error((error as ValidationError).message));
}

You can also validate parts of a workflow using validators:

import { ValidateFunction } from 'ajv';
import { validators, Specification } from '@serverlessworkflow/sdk-typescript';

const injectionState: Specification.Injectstate = workflow.states[0];
const injectionStateValidator: ValidateFunction<Specification.Injectstate> = validators.get('Injectstate');
if (!injectionStateValidator(injectionState)) {
  injectionStateValidator.errors.forEach(error => console.error(error.message));
}

Generate workflow diagram

It is possible to generate the workflow diagram with Mermaid

const workflow = workflowBuilder()
    .id("helloworld")
    ....
    .build();

const mermaidSourceCode = new MermaidDiagram(workflow).sourceCode();

Here you can see a full example that uses mermaid in the browser to generate the workflow diagram.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].