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
To build the project and run tests locally:
git clone https://github.com/serverlessworkflow/sdk-typescript.git
cd sdk-typescript
npm install && npm run update-code-base && npm run test
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.
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!"
})
.end(true).build()])
.build());
const workflow = WorkflowConverter.fromString(source)
Where source
is a JSON or a YAML string.
Having the following workflow instance:
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!"
})
.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:
const workflowAsJson = WorkflowConverter.toJson(workflow);
const workflowAsYaml = WorkflowConverter.toYaml(workflow);
The sdk provides a way to validate if a workflow object is compliant with the serverlessworkflow specification.
validators
provides a map of validation functions:
const validate = validators.get('WorkflowJson');
const isValid = validate(workflow);
if (!isValid) {
validate.errors.forEach(error => console.error(error.message));
}