Skip to content

Commit 6de17ec

Browse files
authored
Merge pull request #82 from neuroglia-io/alternative-approach
Alternative approach
2 parents f131d4c + 52f01d8 commit 6de17ec

File tree

148 files changed

+7036
-5201
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+7036
-5201
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Thumbs.db
1313

1414
# Ignore built ts files
1515
dist/**/*
16+
out-tsc
1617

1718
# ignore yarn.lock
1819
yarn.lock

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
registry=https://registry.npmjs.org

README.md

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ Provides the Typescript API/SPI for the [Serverless Workflow Specification](http
77

88
With the SDK you can:
99
* Parse workflow JSON and YAML definitions
10-
* (_WIP_) Programmatically build workflow definitions
11-
* (_WIP_) Validate workflow definitions
10+
* Programmatically build workflow definitions
11+
* Validate workflow definitions
1212

1313
## Getting Started
1414

@@ -20,7 +20,7 @@ To build the project and run tests locally:
2020
```sh
2121
git clone https://github.com/serverlessworkflow/sdk-typescript.git
2222
cd sdk-typescript
23-
npm install && npm run test
23+
npm install && npm run update-code-base && npm run test
2424
```
2525

2626

@@ -53,28 +53,29 @@ It will create a symbolic link from globally-installed `sdk-typescript` to `node
5353
#### Create Workflow using builder API
5454

5555
```typescript
56-
57-
const workflow = new WorkflowBuilder()
58-
.withId("helloworld")
59-
.withVersion("1.0")
60-
.withName("Hello World Workflow")
61-
.withDescription("Inject Hello World")
62-
.withStart("Hello State")
63-
.withStates([new InjectStateBuilder()
64-
.withName("Hello State")
65-
.withData({
66-
"result": "Hello World!"
67-
})
68-
.withEnd(true).build()])
69-
.build();
56+
const workflow = workflowBuilder()
57+
.id("helloworld")
58+
.version("1.0")
59+
.name("Hello World Workflow")
60+
.description("Inject Hello World")
61+
.start("Hello State")
62+
.states([injectstateBuilder()
63+
.name("Hello State")
64+
.data({
65+
"result": "Hello World!"
66+
})
67+
.end(true)
68+
.build()
69+
])
70+
.build();
7071
```
7172

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

7475
```typescript
75-
const workflow = BaseWorkflow.fromSource(source)
76+
const workflow = WorkflowConverter.fromString(source)
7677
```
77-
Where `source` is the file location.
78+
Where `source` is a JSON or a YAML string.
7879

7980

8081

@@ -83,52 +84,45 @@ Where `source` is the file location.
8384
Having the following workflow instance:
8485

8586
```typescript
86-
const workflow = new WorkflowBuilder()
87-
.withId("helloworld")
88-
.withVersion("1.0")
89-
.withName("Hello World Workflow")
90-
.withDescription("Inject Hello World")
91-
.withStart("Hello State")
92-
.withStates([new InjectStateBuilder()
93-
.withName("Hello State")
94-
.withData({
95-
"result": "Hello World!"
96-
})
97-
.withEnd(true).build()])
98-
.build();
87+
const workflow = workflowBuilder()
88+
.id("helloworld")
89+
.version("1.0")
90+
.name("Hello World Workflow")
91+
.description("Inject Hello World")
92+
.start("Hello State")
93+
.states([injectstateBuilder()
94+
.name("Hello State")
95+
.data({
96+
"result": "Hello World!"
97+
})
98+
.end(true)
99+
.build()
100+
])
101+
.build();
99102
```
100103

101104
You can convert it to its string representation in JSON or YAML format
102-
by using the static methods `toJSON` or `toYAML` respectively:
105+
by using the static methods `toJson` or `toYaml` respectively:
103106

104107
```typescript
105-
const workflowAsJSON = BaseWorkflow.toJSON(workflow);
108+
const workflowAsJson = WorkflowConverter.toJson(workflow);
106109
```
107110

108111
```typescript
109-
const workflowAsYAML = BaseWorkflow.toYAML(workflow);
112+
const workflowAsYaml = WorkflowConverter.toYaml(workflow);
110113
```
111114

112115
#### Validate workflow definitions
113116

114117
The sdk provides a way to validate if a workflow object is compliant with the serverlessworkflow specification.
115118

116-
`WorkflowValidator` class provides two methods:
119+
`WorkflowValidator` class provides a validation method:
117120

118-
- `isValid(): boolean`
121+
- `validate(): boolean`
119122

120123
```typescript
121-
122-
const isValid = new WorkflowValidator(workflow).isValid();
123-
124-
```
125-
126-
- `validate(): ValidationErrors`
127-
128-
```typescript
129-
130-
const validationErrors = new WorkflowValidator(workflow).validate();
131-
validationErrors.errors().forEach(error => console.error(error.message()))
132-
133-
134-
```
124+
const workflowValidator = new WorkflowValidator(workflow);
125+
if (!workflowValidator.validate()) {
126+
workflowValidator.validationErrors.forEach(error => console.error(error.message));
127+
}
128+
```

0 commit comments

Comments
 (0)