Skip to content

Commit 24c3fbf

Browse files
committed
add dsl example
1 parent 1f2bd71 commit 24c3fbf

19 files changed

+365
-1
lines changed

.scripts/copy-shared-files.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const ADDITIONAL_SAMPLES = [];
77
// that we don't want to overwrite
88
const TSCONFIG_EXCLUDE = ['nextjs-ecommerce-oneclick', 'monorepo-folders', 'fetch-esm', 'production', 'hello-world-js'];
99
const GITIGNORE_EXCLUDE = ['nextjs-ecommerce-oneclick', 'monorepo-folders', 'production', 'hello-world-js'];
10-
const ESLINTRC_EXCLUDE = ['nextjs-ecommerce-oneclick', 'monorepo-folders', 'fetch-esm', 'hello-world-js'];
10+
const ESLINTRC_EXCLUDE = ['nextjs-ecommerce-oneclick', 'monorepo-folders', 'fetch-esm', 'hello-world-js', 'dsl-interpreter'];
1111
const ESLINTIGNORE_EXCLUDE = ['production', 'monorepo-folders', 'hello-world-js'];
1212

1313
const POST_CREATE_EXCLUDE = [

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ Each directory in this repo is a sample Temporal project built with the [TypeScr
7676

7777
### Full Apps
7878

79+
- **Control Flow demonstrations**:
80+
- [**DSL Interpreter**](https://github.com/temporalio/samples-typescript/tree/main/dsl-interpreter): demonstrates how to make workflows interpret a custom YML based Domain Specific Language.
7981
- **Next.js**:
8082
- [**One-click e-commerce**](https://github.com/temporalio/samples-typescript/tree/main/nextjs-ecommerce-oneclick): Buy an item with one click, and the Workflow will wait 5 seconds to see if the user cancels before it executes the order.
8183
- Food Delivery: https://github.com/lorensr/food-delivery

dsl-interpreter/.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
lib
3+
.eslintrc.js

dsl-interpreter/.eslintrc.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
root: true,
3+
parser: '@typescript-eslint/parser',
4+
parserOptions: {
5+
project: './tsconfig.json',
6+
tsconfigRootDir: __dirname,
7+
},
8+
plugins: ['@typescript-eslint', 'deprecation'],
9+
extends: [
10+
'eslint:recommended',
11+
'plugin:@typescript-eslint/eslint-recommended',
12+
'plugin:@typescript-eslint/recommended',
13+
'prettier',
14+
],
15+
rules: {
16+
'@typescript-eslint/no-unused-vars': [
17+
'warn',
18+
{
19+
argsIgnorePattern: '^_',
20+
varsIgnorePattern: '^_',
21+
},
22+
],
23+
'@typescript-eslint/ban-ts-comment': 'off',
24+
'@typescript-eslint/no-explicit-any': 'off',
25+
'object-shorthand': ['error', 'always'],
26+
'deprecation/deprecation': 'warn',
27+
},
28+
};

dsl-interpreter/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lib
2+
node_modules

dsl-interpreter/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

dsl-interpreter/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
16

dsl-interpreter/.post-create

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
To begin development, start Temporal Server:
2+
3+
{cyan cd} ~/path/to/temporal/docker-compose/
4+
{cyan docker-compose up}
5+
6+
{dim.italic If you haven’t run Temporal Server before, visit:
7+
https://docs.temporal.io/docs/typescript/getting-started/}
8+
9+
Then, in the project directory, using two other shells, run these commands:
10+
11+
{cyan npm run start.watch}
12+
{cyan npm run workflow}

dsl-interpreter/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# DSL Interpreter Workflow
2+
3+
This sample demonstrates how to implement a DSL workflow, based on the [Go equivalent](https://github.com/temporalio/samples-go/tree/main/dsl). In this sample, we provide 2 sample yaml files each defines a custom workflow that can be processed by this DSL workflow sample code.
4+
5+
### Running this sample
6+
7+
1. Make sure Temporal Server is running locally (see the [quick install guide](https://docs.temporal.io/docs/server/quick-install/)).
8+
1. `npm install` to install dependencies.
9+
1. `npm run start.watch` to start the Worker.
10+
1. In another terminal, `npm run workflow1` or `npm run `workflow2` to run the Workflows accordingly

dsl-interpreter/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "temporal-dsl-interpreter",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "tsc --build",
7+
"build.watch": "tsc --build --watch",
8+
"start": "ts-node src/worker.ts",
9+
"start.watch": "nodemon src/worker.ts",
10+
"workflow1": "ts-node src/client.ts ../workflow1.yaml",
11+
"workflow2": "ts-node src/client.ts ../workflow2.yaml",
12+
"lint": "eslint ."
13+
},
14+
"nodemonConfig": {
15+
"execMap": {
16+
"ts": "ts-node"
17+
},
18+
"ext": "ts",
19+
"watch": [
20+
"src"
21+
]
22+
},
23+
"dependencies": {
24+
"node-yaml": "^4.0.1",
25+
"temporalio": "0.16.x"
26+
},
27+
"devDependencies": {
28+
"@tsconfig/node14": "^1.0.0",
29+
"@typescript-eslint/eslint-plugin": "^5.0.0",
30+
"@typescript-eslint/parser": "^5.0.0",
31+
"eslint": "^7.32.0",
32+
"eslint-config-prettier": "^8.3.0",
33+
"eslint-plugin-deprecation": "^1.2.1",
34+
"nodemon": "^2.0.12",
35+
"ts-node": "^10.2.1",
36+
"typescript": "^4.4.2"
37+
}
38+
}

0 commit comments

Comments
 (0)