Skip to content

Commit 96b0774

Browse files
committed
start.
0 parents  commit 96b0774

Some content is hidden

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

59 files changed

+4629
-0
lines changed

.editorconfig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = tab
6+
tab_width = 4
7+
insert_final_newline = true
8+
trim_trailing_whitespace = true
9+
10+
[*.ts]
11+
quote_type = single
12+
13+
[*.md]
14+
indent_style = space
15+
max_line_length = off
16+
trim_trailing_whitespace = false

.eslintrc.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"plugins": [
5+
"@typescript-eslint"
6+
],
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:@typescript-eslint/eslint-recommended",
10+
"plugin:@typescript-eslint/recommended"
11+
],
12+
"rules": {
13+
"no-mixed-spaces-and-tabs": "off"
14+
}
15+
}

.github/workflows/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: main
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- develop
7+
jobs:
8+
build:
9+
name: Build
10+
runs-on: ${{matrix.os}}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest]
14+
node: [16]
15+
steps:
16+
- name: Checkout Repo
17+
uses: actions/checkout@v2
18+
- name: Setup Node 16
19+
uses: actions/setup-node@v2
20+
with:
21+
node-version: '16'
22+
- name: Packages
23+
run: bash .github/workflows/packages.sh

.github/workflows/packages.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
set -e
3+
4+
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
5+
6+
cd "$SCRIPT_DIR"
7+
yarn install
8+
yarn build
9+
yarn eslint
10+
yarn prettier
11+
yarn test:single

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.yarn/
2+
build/
3+
node_modules/
4+
coverage/
5+
.vscode/
6+
lib/
7+
dist/
8+
yarn-*.log

.prettierrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"printWidth": 140,
3+
"singleQuote": true,
4+
"trailingComma": "none",
5+
"semi": true,
6+
"useTabs": true,
7+
"arrowParens": "avoid"
8+
}

LICENSE

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2023 N4NO.com
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6+
7+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Sequential Workflow Machine
2+
3+
[![Build Status](https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fb4rtaz%2Fsequential-workflow-engine%2Fbadge%3Fref%3Dmain&style=flat-square)](https://actions-badge.atrox.dev/b4rtaz/sequential-workflow-engine/goto?ref=main) [![License: MIT](https://img.shields.io/github/license/mashape/apistatus.svg?style=flat-square)](/LICENSE) [![View this project on NPM](https://img.shields.io/npm/v/sequential-workflow-engine.svg?style=flat-square)](https://npmjs.org/package/sequential-workflow-engine)
4+
5+
The powerful sequential workflow machine for frontend and backend applications. It provides a simple API for creating own step execution handlers (activities). It supports multiple types of activities. Internally is uses the [xstate](https://github.com/statelyai/xstate) library.
6+
7+
This engine uses the same data model as the [Sequential Workflow Designer](https://github.com/nocode-js/sequential-workflow-designer). So you can create a workflow definition in the designer and then run it by this engine easily.
8+
9+
📝 Check the [documentation](https://nocode-js.com/docs/category/sequential-workflow-machine) for more details.
10+
11+
## 🚀 Installation
12+
13+
Install the following packages by NPM command:
14+
15+
```
16+
npm i sequential-workflow-model sequential-workflow-machine
17+
```
18+
19+
## 🎬 Usage
20+
21+
You can use the engine in a JavaScript or TypeScript application. We recommend to use TypeScript because a workflow uses a lot of data structures and it's hard to maintain data integrity.
22+
23+
At the beginning you need to define the type of your workflow definition.
24+
25+
```ts
26+
import { Definition } from 'sequential-workflow-model';
27+
28+
interface MyDefinition extends Definition {
29+
properties: {
30+
verbose: boolean;
31+
};
32+
}
33+
```
34+
35+
Next, define your step types.
36+
37+
```ts
38+
import { Step } from 'sequential-workflow-model';
39+
40+
interface DownloadHtmlStep extends Step {
41+
componentType: 'task';
42+
type: 'downloadHtml';
43+
properties: {
44+
pageUrl: string;
45+
};
46+
}
47+
48+
// ...
49+
```
50+
51+
Prepare the workflow definition.
52+
53+
```ts
54+
const definition: MyDefinition = {
55+
properties: {
56+
verbose: true,
57+
},
58+
sequence: [
59+
{
60+
id: '0x00001',
61+
componentType: 'task',
62+
type: 'downloadHtml',
63+
name: 'Download google.com',
64+
properties: {
65+
pageUrl: 'https://www.google.com',
66+
},
67+
},
68+
],
69+
};
70+
```
71+
72+
Prepare the global state interface.
73+
74+
```ts
75+
interface WorkflowGlobalState {
76+
html: string | null;
77+
}
78+
```
79+
80+
Prepare activities for your steps. The engine supports multiple types of activities. The basic activity is the atom activity. It's a simple handler that executes an atomic step and updates the global state.
81+
82+
```ts
83+
import { createAtomActivity } from 'sequential-workflow-machine';
84+
85+
interface DownloadHtmlStepState {
86+
attempt: number;
87+
}
88+
89+
const downloadHtmlActivity = createAtomActivity<DownloadHtmlStep, WorkflowGlobalState, DownloadHtmlStepState>({
90+
stepType: 'downloadHtml',
91+
init: () => ({
92+
attempt: 0,
93+
}),
94+
handler: async (step: DownloadHtmlStep, globalState: WorkflowGlobalState, activityState: DownloadHtmlStepState) => {
95+
globalState.html = await downloadHtml(step.properties.pageUrl);
96+
activityState.attempt++;
97+
},
98+
});
99+
```
100+
101+
Now we can create the activity set. The activity set is a collection of all supported activities.
102+
103+
```ts
104+
import { activitySet } from 'sequential-workflow-machine';
105+
106+
const activitySet = createActivitySet<WorkflowGlobalState>([
107+
downloadHtmlActivity,
108+
]);
109+
```
110+
111+
Finally, we can create the workflow machine and run it.
112+
113+
```ts
114+
import { createWorkflowMachineBuilder } from 'sequential-workflow-machine';
115+
116+
const builder = createWorkflowMachineBuilder<WorkflowGlobalState>(activitySet);
117+
const machine = builder.build(definition);
118+
const interpreter = machine.create({
119+
init: () => {
120+
return {
121+
html: null,
122+
};
123+
}
124+
});
125+
interpreter.onChange(() => { /* ... */ });
126+
interpreter.onDone(() => { /* ... */ });
127+
interpreter.start();
128+
```
129+
130+
That's it!
131+
132+
## 💡 License
133+
134+
This project is released under the MIT license.

machine/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
README.md
2+
LICENSE

machine/jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
preset: 'ts-jest/presets/default',
3+
testMatch: ['**/?(*.)+(spec|test).ts?(x)'],
4+
transform: {
5+
'^.+\\.(ts|js)x?$': 'ts-jest',
6+
},
7+
transformIgnorePatterns: ['^.+\\.js$'],
8+
};

0 commit comments

Comments
 (0)