Skip to content

Commit 769dc0e

Browse files
authored
Merge pull request #1 from antmendoza/initial-sdk
initial-sdk
2 parents 0e284f5 + 4948184 commit 769dc0e

25 files changed

+3221
-2
lines changed

README.md

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,111 @@
11
# Serverless Workflow Specification - Typescript SDK
22

3-
Provides (TODO: add specifics) for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification)
3+
Provides the Typescript API/SPI for the [Serverless Workflow Specification](https://github.com/serverlessworkflow/specification)
4+
5+
6+
With the SDK you can:
7+
* Parse workflow JSON and YAML definitions
8+
* (_WIP_) Programmatically build workflow definitions
9+
10+
11+
## Getting Started
12+
13+
14+
### Building locally
15+
16+
To build the project and run tests locally:
17+
18+
```sh
19+
git clone https://github.com/serverlessworkflow/sdk-typescript.git
20+
cd sdk-typescript
21+
npm install && npm run test
22+
```
23+
24+
25+
### Add as dependency to your project
26+
You can use [npm link](https://docs.npmjs.com/cli/v7/commands/npm-link) to add the `sdk-typescript`
27+
as dependency in your project.
28+
29+
- Clone the `sdk-typescript` project and build it:
30+
```sh
31+
git clone https://github.com/serverlessworkflow/sdk-typescript.git
32+
cd sdk-typescript
33+
npm install && npm run build
34+
```
35+
36+
- Make the package visible globally to npm. Inside the `sdk-typescript` project folder run:
37+
```sh
38+
npm link
39+
```
40+
41+
- Navigate to the folder/project in which you want to use the sdk, and run the following command:
42+
```sh
43+
npm link sdk-typescript
44+
```
45+
46+
It will create a symbolic link from globally-installed `sdk-typescript` to `node_modules/` of the current folder.
47+
48+
49+
### How to use
50+
51+
#### Create Workflow using builder API
52+
53+
```typescript
54+
55+
const workflow = new WorkflowBuilder()
56+
.withId("helloworld")
57+
.withVersion("1.0")
58+
.withName("Hello World Workflow")
59+
.withDescription("Inject Hello World")
60+
.withStart("Hello State")
61+
.withStates([new InjectStateBuilder()
62+
.withName("Hello State")
63+
.withData({
64+
"result": "Hello World!"
65+
})
66+
.withEnd(true).build()])
67+
.build();
68+
```
69+
70+
#### Load a file JSON/YAML to a Workflow instance
71+
72+
```typescript
73+
const workflow = BaseWorkflow.fromSource(source)
74+
```
75+
Where `source` is the file location.
76+
77+
78+
79+
#### Parse a Workflow instance to JSON/YAML
80+
81+
Having the following workflow instance:
82+
83+
```typescript
84+
const workflow = new WorkflowBuilder()
85+
.withId("helloworld")
86+
.withVersion("1.0")
87+
.withName("Hello World Workflow")
88+
.withDescription("Inject Hello World")
89+
.withStart("Hello State")
90+
.withStates([new InjectStateBuilder()
91+
.withName("Hello State")
92+
.withData({
93+
"result": "Hello World!"
94+
})
95+
.withEnd(true).build()])
96+
.build();
97+
```
98+
99+
You can convert it to its string representation in JSON or YAML format
100+
by using the static methods `toJSON` or `toYAML` respectively:
101+
102+
```typescript
103+
const workflowAsJSON = BaseWorkflow.toJSON(workflow);
104+
```
105+
106+
```typescript
107+
const workflowAsYAML = BaseWorkflow.toYAML(workflow);
108+
```
109+
110+
4111

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

0 commit comments

Comments
 (0)