Skip to content

Commit

Permalink
initial-sdk
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Mendoza Pérez <[email protected]>
  • Loading branch information
antmendoza committed Apr 4, 2021
1 parent 0e284f5 commit a26c08a
Show file tree
Hide file tree
Showing 25 changed files with 3,202 additions and 2 deletions.
91 changes: 89 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,92 @@
# Serverless Workflow Specification - Typescript SDK

Provides (TODO: add specifics) for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification)
Provides the Java API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/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
```sh
npm install sdk-typescript
```


### How to use

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

#### Load a file JSON/YAML to a Workflow instance

```typescript
const workflow = BaseWorkflow.fromSource(source)
```
Where source is the file location.



#### Parse a Workflow instance to JSON/YAML

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({
"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:

```typescript
const workflowAsJSON = BaseWorkflow.toJSON(workflow);
```

```typescript
const workFlowAsYAML = BaseWorkflow.toYAML(workflow);
```



(TODO: add description of features and small examples how to get started, use)
Loading

0 comments on commit a26c08a

Please sign in to comment.