From f6dbeb4d08acdef205e4fa8ddd1ea1f858a4ec71 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bianchi Date: Fri, 9 Aug 2024 16:43:30 +0200 Subject: [PATCH] Created legacy branch for spec v0.9 Signed-off-by: Jean-Baptiste Bianchi --- .eslintrc.js | 3 ++- README.md | 11 +++++++---- examples/browser/index.html | 2 +- examples/browser/mermaid.html | 2 +- package.json | 10 +++++----- src/lib/diagram/mermaidDiagram.ts | 2 +- src/lib/diagram/mermaidState.ts | 12 +++++++----- src/lib/utils.ts | 4 ++-- src/lib/validators.ts | 2 +- tests/examples/applicantrequest.json | 2 +- tests/examples/applicantrequest.spec.ts | 2 +- tests/examples/booklending.json | 2 +- tests/examples/booklending.spec.ts | 2 +- tests/examples/carauctionbids.json | 2 +- tests/examples/carauctionbids.spec.ts | 2 +- tests/examples/checkcarvitals.json | 2 +- tests/examples/checkcarvitals.spec.ts | 2 +- tests/examples/jobmonitoring.json | 2 +- tests/examples/jobmonitoring.spec.ts | 2 +- tests/examples/parallel.json | 2 +- tests/examples/parallel.spec.ts | 2 +- tests/examples/provisionorder.json | 2 +- tests/examples/provisionorder.spec.ts | 2 +- tests/examples/sendcloudevent.json | 2 +- tests/examples/sendcloudevent.spec.ts | 2 +- tests/examples/solvemathproblems.json | 2 +- tests/examples/solvemathproblems.spec.ts | 2 +- tests/lib/definitions/action.spec.ts | 6 +++--- tests/lib/definitions/branch.spec.ts | 2 +- tests/lib/definitions/eventdef.spec.ts | 4 ++-- tests/lib/definitions/schedule.spec.ts | 2 +- tests/lib/definitions/util.spec.ts | 16 +++++++--------- .../workflow-converter-hello-world.json | 2 +- .../workflow-converter-hello-world.yaml | 2 +- .../workflow-converter-hello-world.yml | 2 +- tests/lib/definitions/workflow.spec.ts | 18 +++++++++--------- tests/lib/diagram/wf_with_compensation.json | 2 +- tests/lib/workflow-validator.spec.ts | 5 ++--- tools/utils.ts | 2 +- 39 files changed, 75 insertions(+), 72 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 74b489e..bb6e356 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -12,6 +12,7 @@ module.exports = { ], rules: { '@typescript-eslint/no-explicit-any': 0, - '@typescript-eslint/no-inferrable-types': 0 + '@typescript-eslint/no-inferrable-types': 0, + '@typescript-eslint/ban-types': 0 } }; \ No newline at end of file diff --git a/README.md b/README.md index 0381af1..ae41d97 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +> [!CAUTION] +> This is a legacy branch. It is not officially supported by the ServerlessWorkflow organisation anymore but still accepts community contributions. + ![Node CI](https://github.com/serverlessworkflow/sdk-typescript/workflows/Node%20CI/badge.svg) [![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/serverlessworkflow/sdk-typescript) # Serverless Workflow Specification - Typescript SDK @@ -17,6 +20,7 @@ With the SDK you can: | [v1.0.0](https://github.com/serverlessworkflow/sdk-typescript/releases/) | [v0.6](https://github.com/serverlessworkflow/specification/tree/0.6.x) | | [v2.0.0](https://github.com/serverlessworkflow/sdk-typescript/releases/) | [v0.7](https://github.com/serverlessworkflow/specification/tree/0.7.x) | | [v3.0.0](https://github.com/serverlessworkflow/sdk-typescript/releases/) | [v0.8](https://github.com/serverlessworkflow/specification/tree/0.8.x) | +| [v4.0.0](https://github.com/serverlessworkflow/sdk-typescript/releases/) | [v0.9](https://github.com/serverlessworkflow/specification/tree/0.9.x) | @@ -39,7 +43,6 @@ npm install && npm run build && npm run test ##### Version >= 4.0.0 -Note: Version 4.0.0 has not been released yet. ```sh npm i @serverlessworkflow/sdk-typescript ``` @@ -59,7 +62,7 @@ import { workflowBuilder, injectstateBuilder, Specification } from '@serverlessw const workflow: Specification.Workflow = workflowBuilder() .id("helloworld") - .specVersion("0.8") + .specVersion("0.9") .version("1.0") .name("Hello World Workflow") .description("Inject Hello World") @@ -107,7 +110,7 @@ import { workflowBuilder, injectstateBuilder, Specification } from '@serverlessw const workflow: Specification.Workflow = workflowBuilder() .id("helloworld") .version("1.0") - .specVersion("0.8") + .specVersion("0.9") .name("Hello World Workflow") .description("Inject Hello World") .start("Hello State") @@ -162,7 +165,7 @@ import {Workflow} from "./workflow"; const workflow = { id: 'helloworld', version: '1.0', - specVersion: '0.3', + specVersion: '0.9', name: 'Hello World Workflow', description: 'Inject Hello World', start: 'Hello State', diff --git a/examples/browser/index.html b/examples/browser/index.html index 717fdb2..dac111d 100644 --- a/examples/browser/index.html +++ b/examples/browser/index.html @@ -19,7 +19,7 @@ const workflow = workflowBuilder() .id("helloworld") .version("1.0") - .specVersion("0.8") + .specVersion("0.9") .name("Hello World Workflow") .description("Inject Hello World") .start("Hello State") diff --git a/examples/browser/mermaid.html b/examples/browser/mermaid.html index 95c1249..7c0e91e 100644 --- a/examples/browser/mermaid.html +++ b/examples/browser/mermaid.html @@ -21,7 +21,7 @@ const workflow = workflowBuilder() .id("helloworld") .version("1.0") - .specVersion("0.8") + .specVersion("0.9") .name("Hello World Workflow") .description("Inject Hello World") .start("Hello State") diff --git a/package.json b/package.json index e5f7e1e..8a39524 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "@serverlessworkflow/sdk-typescript", - "version": "4.0.0", - "schemaVersion": "0.8", + "name": "@severlessworkflow/sdk-typescript", + "version": "4.0.0-rc1", + "schemaVersion": "0.9", "description": "Typescript SDK for Serverless Workflow Specification", "main": "umd/index.umd.min.js", "browser": "umd/index.umd.min.js", @@ -28,7 +28,7 @@ "prebuild": "npx rimraf dist", "build": "npx rollup -c rollup.config.ts && npx shx mv ./dist/src/lib ./dist/lib && npx shx mv ./dist/src/*d.ts.map ./dist/src/*d.ts ./dist && npx rimraf ./dist/src", "postbuild": "npx shx cp ./package.json ./README.md ./LICENSE ./dist/", - "verify-publish-directory": "node -e 'if (!process.cwd().endsWith(\"dist\")) { console.error(\"Packaging/Publishing should be done from ./dist/\"); process.exitCode = 1; } process.exit();'", + "verify-publish-directory": "node -e \"if (!process.cwd().endsWith('dist')) { console.error('Packaging/Publishing should be done from ./dist/'); process.exitCode = 1; } process.exit();\"", "prepack": "npm run verify-publish-directory", "prepublishOnly": "npm run verify-publish-directory", "prepublish": "husky install" @@ -72,7 +72,7 @@ }, "repository": { "type": "git", - "url": "https://github.com/serverlessworkflow/sdk-typescript.git" + "url": "git+https://github.com/serverlessworkflow/sdk-typescript.git" }, "author": { "name": "Serverless Workflow Contributors", diff --git a/src/lib/diagram/mermaidDiagram.ts b/src/lib/diagram/mermaidDiagram.ts index a8ef7ea..db42741 100644 --- a/src/lib/diagram/mermaidDiagram.ts +++ b/src/lib/diagram/mermaidDiagram.ts @@ -19,7 +19,7 @@ import { MermaidState } from './mermaidState'; export class MermaidDiagram { constructor(private workflow: Specification.Workflow) {} - sourceCode() { + sourceCode(): string { const mermaidStateDiagramVersion = 'stateDiagram-v2'; return ( mermaidStateDiagramVersion + diff --git a/src/lib/diagram/mermaidState.ts b/src/lib/diagram/mermaidState.ts index cf23e98..72ba04b 100644 --- a/src/lib/diagram/mermaidState.ts +++ b/src/lib/diagram/mermaidState.ts @@ -30,7 +30,7 @@ export class MermaidState { private isFirstState: boolean = false ) {} - sourceCode() { + sourceCode(): string { const stateDefinition = this.definitions(); const stateTransitions = this.transitions(); @@ -145,7 +145,7 @@ export class MermaidState { const end = this.state.end as Specification.End; if (end.produceEvents) { - transitionLabel = 'Produced event = [' + end.produceEvents!.map((pe) => pe.eventRef).join(',') + ']'; + transitionLabel = 'Produced event = [' + end.produceEvents.map((pe) => pe.eventRef).join(',') + ']'; } } @@ -211,7 +211,7 @@ export class MermaidState { case 'parallel': definition = this.parallelStateDetails(); break; - case 'switch': + case 'switch': { const switchState: any = this.state; if (switchState.dataConditions) { definition = this.dataBasedSwitchStateDetails(); @@ -222,6 +222,7 @@ export class MermaidState { break; } throw new Error(`Unexpected switch type; \n state value= ${JSON.stringify(this.state, null, 4)}`); + } case 'inject': // NOTHING break; @@ -243,12 +244,13 @@ export class MermaidState { return definition ? definition : undefined; } - private definitionType() { + private definitionType(): string { const type = this.state.type; + if (!type) return ''; return this.stateDescription( this.stateKeyDiagram(this.state.name), 'type', - type!.charAt(0).toUpperCase() + type!.slice(1) + ' State' + type.charAt(0).toUpperCase() + type.slice(1) + ' State' ); } diff --git a/src/lib/utils.ts b/src/lib/utils.ts index dca73b2..1eb405c 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -22,7 +22,7 @@ import { validators } from './validators'; * @param data {object} The data to validate * @returns {boolean} True if valid, throws if invalid */ -export const validate = (typeName: string, data: any): boolean => { +export const validate = (typeName: string, data: unknown): boolean => { const validateFn: ValidateFunction | undefined = validators.get(typeName); if (!validateFn) { @@ -44,7 +44,7 @@ export const validate = (typeName: string, data: any): boolean => { * @param value The data * @returns {boolean} True if the provided value is an object */ -export const isObject = (value: any): boolean => { +export const isObject = (value: unknown): boolean => { if (!value) return false; const type = typeof value; return type === 'object'; diff --git a/src/lib/validators.ts b/src/lib/validators.ts index 394bd1a..c6335ad 100644 --- a/src/lib/validators.ts +++ b/src/lib/validators.ts @@ -43,7 +43,7 @@ const schemas: any[] = [ ]; const strict: boolean = false; const ajv = new Ajv({ schemas, strict }); -ajv.addFormat('uri', (uri: string): boolean => true); +ajv.addFormat('uri', (): boolean => true); /** * A Map of validation functions, where the key is the name of the schema to validate with */ diff --git a/tests/examples/applicantrequest.json b/tests/examples/applicantrequest.json index 6a295a9..94b29f1 100644 --- a/tests/examples/applicantrequest.json +++ b/tests/examples/applicantrequest.json @@ -3,7 +3,7 @@ "name": "Applicant Request Decision Workflow", "version": "1.0.0", "description": "Determine if applicant request is valid", - "specVersion": "0.8", + "specVersion": "0.9", "start": "CheckApplication", "states": [ { diff --git a/tests/examples/applicantrequest.spec.ts b/tests/examples/applicantrequest.spec.ts index 2f00b4e..5c3cd4e 100644 --- a/tests/examples/applicantrequest.spec.ts +++ b/tests/examples/applicantrequest.spec.ts @@ -31,7 +31,7 @@ describe('applicationrequest workflow example', () => { const workflow = workflowBuilder() .id('applicantrequest') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Applicant Request Decision Workflow') .description('Determine if applicant request is valid') .start('CheckApplication') diff --git a/tests/examples/booklending.json b/tests/examples/booklending.json index fc3c8df..a69067c 100644 --- a/tests/examples/booklending.json +++ b/tests/examples/booklending.json @@ -2,7 +2,7 @@ "id": "booklending", "name": "Book Lending Workflow", "version": "1.0.0", - "specVersion": "0.8", + "specVersion": "0.9", "start": "Book Lending Request", "states": [ { diff --git a/tests/examples/booklending.spec.ts b/tests/examples/booklending.spec.ts index bda3e65..6d639c2 100644 --- a/tests/examples/booklending.spec.ts +++ b/tests/examples/booklending.spec.ts @@ -36,7 +36,7 @@ describe('booklending workflow example', () => { .id('booklending') .name('Book Lending Workflow') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .start('Book Lending Request') .states([ eventstateBuilder() diff --git a/tests/examples/carauctionbids.json b/tests/examples/carauctionbids.json index 9c6ac0d..ec2e777 100644 --- a/tests/examples/carauctionbids.json +++ b/tests/examples/carauctionbids.json @@ -3,7 +3,7 @@ "name": "Car Auction Bidding Workflow", "version": "1.0.0", "description": "Store a single bid whole the car auction is active", - "specVersion": "0.8", + "specVersion": "0.9", "start": { "stateName": "StoreCarAuctionBid", "schedule": "R/PT2H" diff --git a/tests/examples/carauctionbids.spec.ts b/tests/examples/carauctionbids.spec.ts index 12f6b01..a1b714a 100644 --- a/tests/examples/carauctionbids.spec.ts +++ b/tests/examples/carauctionbids.spec.ts @@ -30,7 +30,7 @@ describe('carauctionbids workflow example', () => { const workflow = workflowBuilder() .id('handleCarAuctionBid') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Car Auction Bidding Workflow') .description('Store a single bid whole the car auction is active') .start(startdefBuilder().stateName('StoreCarAuctionBid').schedule('R/PT2H').build()) diff --git a/tests/examples/checkcarvitals.json b/tests/examples/checkcarvitals.json index 79a61d6..ca492c2 100644 --- a/tests/examples/checkcarvitals.json +++ b/tests/examples/checkcarvitals.json @@ -2,7 +2,7 @@ "id": "checkcarvitals", "name": "Check Car Vitals Workflow", "version": "1.0.0", - "specVersion": "0.8", + "specVersion": "0.9", "start": "WhenCarIsOn", "states": [ { diff --git a/tests/examples/checkcarvitals.spec.ts b/tests/examples/checkcarvitals.spec.ts index d4e954a..156ec95 100644 --- a/tests/examples/checkcarvitals.spec.ts +++ b/tests/examples/checkcarvitals.spec.ts @@ -34,7 +34,7 @@ describe('checkcarvitals workflow example', () => { .id('checkcarvitals') .name('Check Car Vitals Workflow') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .start('WhenCarIsOn') .states([ eventstateBuilder() diff --git a/tests/examples/jobmonitoring.json b/tests/examples/jobmonitoring.json index 6ec7505..5bc3e23 100644 --- a/tests/examples/jobmonitoring.json +++ b/tests/examples/jobmonitoring.json @@ -3,7 +3,7 @@ "name": "Job Monitoring", "version": "1.0.0", "description": "Monitor finished execution of a submitted job", - "specVersion": "0.8", + "specVersion": "0.9", "start": "SubmitJob", "states": [ { diff --git a/tests/examples/jobmonitoring.spec.ts b/tests/examples/jobmonitoring.spec.ts index 67e2051..5f06242 100644 --- a/tests/examples/jobmonitoring.spec.ts +++ b/tests/examples/jobmonitoring.spec.ts @@ -34,7 +34,7 @@ describe('jobmonitoring workflow example', () => { const workflow = workflowBuilder() .id('jobmonitoring') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Job Monitoring') .description('Monitor finished execution of a submitted job') .start('SubmitJob') diff --git a/tests/examples/parallel.json b/tests/examples/parallel.json index 3cc3e50..d4468c6 100644 --- a/tests/examples/parallel.json +++ b/tests/examples/parallel.json @@ -3,7 +3,7 @@ "name": "Parallel Execution Workflow", "version": "1.0.0", "description": "Executes two branches in parallel", - "specVersion": "0.8", + "specVersion": "0.9", "start": "ParallelExec", "states": [ { diff --git a/tests/examples/parallel.spec.ts b/tests/examples/parallel.spec.ts index 420c0dc..9ac5fe8 100644 --- a/tests/examples/parallel.spec.ts +++ b/tests/examples/parallel.spec.ts @@ -22,7 +22,7 @@ describe('parallel workflow example', () => { const workflow = workflowBuilder() .id('parallelexec') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Parallel Execution Workflow') .description('Executes two branches in parallel') .start('ParallelExec') diff --git a/tests/examples/provisionorder.json b/tests/examples/provisionorder.json index 8523975..d8ec6fb 100644 --- a/tests/examples/provisionorder.json +++ b/tests/examples/provisionorder.json @@ -3,7 +3,7 @@ "name": "Provision Orders", "version": "1.0.0", "description": "Provision Orders and handle errors thrown", - "specVersion": "0.8", + "specVersion": "0.9", "start": "ProvisionOrder", "states": [ { diff --git a/tests/examples/provisionorder.spec.ts b/tests/examples/provisionorder.spec.ts index c49bf80..a037177 100644 --- a/tests/examples/provisionorder.spec.ts +++ b/tests/examples/provisionorder.spec.ts @@ -31,7 +31,7 @@ describe('provisionorder workflow example', () => { const workflow = workflowBuilder() .id('provisionorders') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Provision Orders') .description('Provision Orders and handle errors thrown') .start('ProvisionOrder') diff --git a/tests/examples/sendcloudevent.json b/tests/examples/sendcloudevent.json index 8ba8023..f0d40aa 100644 --- a/tests/examples/sendcloudevent.json +++ b/tests/examples/sendcloudevent.json @@ -2,7 +2,7 @@ "id": "sendcloudeventonprovision", "name": "Send CloudEvent on provision completion", "version": "1.0.0", - "specVersion": "0.8", + "specVersion": "0.9", "start": "ProvisionOrdersState", "states": [ { diff --git a/tests/examples/sendcloudevent.spec.ts b/tests/examples/sendcloudevent.spec.ts index 38b323e..b4dd6ab 100644 --- a/tests/examples/sendcloudevent.spec.ts +++ b/tests/examples/sendcloudevent.spec.ts @@ -30,7 +30,7 @@ describe('sendcloudevent workflow example', () => { const workflow = workflowBuilder() .id('sendcloudeventonprovision') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Send CloudEvent on provision completion') .start('ProvisionOrdersState') .events([ diff --git a/tests/examples/solvemathproblems.json b/tests/examples/solvemathproblems.json index 9a887ac..31aa938 100644 --- a/tests/examples/solvemathproblems.json +++ b/tests/examples/solvemathproblems.json @@ -3,7 +3,7 @@ "name": "Solve Math Problems Workflow", "version": "1.0.0", "description": "Solve math problems", - "specVersion": "0.8", + "specVersion": "0.9", "start": "Solve", "states": [ { diff --git a/tests/examples/solvemathproblems.spec.ts b/tests/examples/solvemathproblems.spec.ts index f3e717a..0974506 100644 --- a/tests/examples/solvemathproblems.spec.ts +++ b/tests/examples/solvemathproblems.spec.ts @@ -28,7 +28,7 @@ describe('solvemathproblems workflow example', () => { const workflow = workflowBuilder() .id('solvemathproblems') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Solve Math Problems Workflow') .description('Solve math problems') .start('Solve') diff --git a/tests/lib/definitions/action.spec.ts b/tests/lib/definitions/action.spec.ts index 5c239e8..204cff5 100644 --- a/tests/lib/definitions/action.spec.ts +++ b/tests/lib/definitions/action.spec.ts @@ -27,8 +27,8 @@ describe('Action ', () => { const model = new Action(data); - expect(model.functionRef!.constructor.name).toBe('Functionref'); - expect(model.eventRef!.constructor.name).toBe('Eventref'); - expect(model.actionDataFilter!.constructor.name).toBe('Actiondatafilter'); + expect(model.functionRef?.constructor.name).toBe('Functionref'); + expect(model.eventRef?.constructor.name).toBe('Eventref'); + expect(model.actionDataFilter?.constructor.name).toBe('Actiondatafilter'); }); }); diff --git a/tests/lib/definitions/branch.spec.ts b/tests/lib/definitions/branch.spec.ts index 976113b..7cbf91c 100644 --- a/tests/lib/definitions/branch.spec.ts +++ b/tests/lib/definitions/branch.spec.ts @@ -25,6 +25,6 @@ describe('Branch ', () => { const model = new Branch(data); - expect(model.actions![0].constructor.name).toBe('Action'); + expect(model.actions?.[0].constructor.name).toBe('Action'); }); }); diff --git a/tests/lib/definitions/eventdef.spec.ts b/tests/lib/definitions/eventdef.spec.ts index 7f08731..e048d2a 100644 --- a/tests/lib/definitions/eventdef.spec.ts +++ b/tests/lib/definitions/eventdef.spec.ts @@ -26,7 +26,7 @@ describe('Eventdef ', () => { const model = new Eventdef(data); - expect(model.correlation![0].constructor.name).toBe('CorrelationDef'); - expect(model.metadata!.constructor.name).toBe('Metadata'); + expect(model.correlation?.[0].constructor.name).toBe('CorrelationDef'); + expect(model.metadata?.constructor.name).toBe('Metadata'); }); }); diff --git a/tests/lib/definitions/schedule.spec.ts b/tests/lib/definitions/schedule.spec.ts index 0d3ca43..51b427e 100644 --- a/tests/lib/definitions/schedule.spec.ts +++ b/tests/lib/definitions/schedule.spec.ts @@ -24,7 +24,7 @@ describe('schedule ', () => { }; const model = new Schedule(data); - expect(model.cron!.constructor.name).toBe('Crondef'); + expect(model.cron?.constructor.name).toBe('Crondef'); }); it('should not convert primitive properties', () => { diff --git a/tests/lib/definitions/util.spec.ts b/tests/lib/definitions/util.spec.ts index 2ed49dd..44a3d75 100644 --- a/tests/lib/definitions/util.spec.ts +++ b/tests/lib/definitions/util.spec.ts @@ -37,9 +37,10 @@ describe('Util ', () => { Object.assign(target, source); overwritePropertyAsPlainType('data', target); - expect(target.data!.key).toBe('action'); - source.data!.key = 'action2'; - expect(target.data!.key).toBe('action'); + expect(target.data?.key).toBe('action'); + source.data = source.data || ({} as { key: string }); + source.data.key = 'action2'; + expect(target.data?.key).toBe('action'); }); it('should create a copy of data property', () => { @@ -61,12 +62,9 @@ describe('Util ', () => { Object.assign(target, source); overwritePropertyAsPlainType('data', target); - // @ts-ignore - expect(target!.data['key1']).toBe('value1'); - // @ts-ignore - source!.data['key1'] = 'value2'; - // @ts-ignore - expect(target!.data['key1']).toBe('value1'); + expect((target.data as any)['key1']).toBe('value1'); + (source.data as any)['key1'] = 'value2'; + expect((target.data as any)['key1']).toBe('value1'); }); }); diff --git a/tests/lib/definitions/workflow-converter-hello-world.json b/tests/lib/definitions/workflow-converter-hello-world.json index d68b1ee..08e9ab6 100644 --- a/tests/lib/definitions/workflow-converter-hello-world.json +++ b/tests/lib/definitions/workflow-converter-hello-world.json @@ -1,7 +1,7 @@ { "id": "helloworld", "version": "1.0", - "specVersion": "0.8", + "specVersion": "0.9", "name": "Hello World Workflow", "description": "Inject Hello World", "start": "Hello State", diff --git a/tests/lib/definitions/workflow-converter-hello-world.yaml b/tests/lib/definitions/workflow-converter-hello-world.yaml index e606003..41dc4c8 100644 --- a/tests/lib/definitions/workflow-converter-hello-world.yaml +++ b/tests/lib/definitions/workflow-converter-hello-world.yaml @@ -1,6 +1,6 @@ id: helloworld version: '1.0' -specVersion": '0.8' +specVersion": '0.9' name: Hello World Workflow description: Inject Hello World start: Hello State diff --git a/tests/lib/definitions/workflow-converter-hello-world.yml b/tests/lib/definitions/workflow-converter-hello-world.yml index e606003..41dc4c8 100644 --- a/tests/lib/definitions/workflow-converter-hello-world.yml +++ b/tests/lib/definitions/workflow-converter-hello-world.yml @@ -1,6 +1,6 @@ id: helloworld version: '1.0' -specVersion": '0.8' +specVersion": '0.9' name: Hello World Workflow description: Inject Hello World start: Hello State diff --git a/tests/lib/definitions/workflow.spec.ts b/tests/lib/definitions/workflow.spec.ts index 0ce6f75..450558b 100644 --- a/tests/lib/definitions/workflow.spec.ts +++ b/tests/lib/definitions/workflow.spec.ts @@ -83,11 +83,11 @@ describe('workflow ', () => { const model = new Workflow(data); - expect(model.functions![0]!.constructor.name).toBe('Function'); - expect(model.timeouts!.constructor.name).toBe('Timeouts'); - expect(model.metadata!.constructor.name).toBe('Metadata'); - expect(model.events![0]!.constructor.name).toBe('Eventdef'); - expect(model.retries![0]!.constructor.name).toBe('Retrydef'); + expect(model.functions?.[0]?.constructor.name).toBe('Function'); + expect(model.timeouts?.constructor.name).toBe('Timeouts'); + expect(model.metadata?.constructor.name).toBe('Metadata'); + expect(model.events?.[0]?.constructor.name).toBe('Eventdef'); + expect(model.retries?.[0]?.constructor.name).toBe('Retrydef'); }); it('should generate JSON from workflow object', () => { @@ -95,7 +95,7 @@ describe('workflow ', () => { workflowBuilder() .id('helloworld') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Hello World Workflow') .description('Inject Hello World') .start('Hello State') @@ -116,7 +116,7 @@ describe('workflow ', () => { '"name":"Hello World Workflow",' + '"version":"1.0.0",' + '"description":"Inject Hello World",' + - '"specVersion":"0.8",' + + '"specVersion":"0.9",' + '"start":"Hello State",' + '"states":[' + '{' + @@ -137,7 +137,7 @@ describe('workflow ', () => { workflowBuilder() .id('helloworld') .version('1.0.0') - .specVersion('0.8') + .specVersion('0.9') .name('Hello World Workflow') .description('Inject Hello World') .start('Hello State') @@ -157,7 +157,7 @@ describe('workflow ', () => { 'name: Hello World Workflow\n' + 'version: 1.0.0\n' + 'description: Inject Hello World\n' + - "specVersion: '0.8'\n" + + "specVersion: '0.9'\n" + 'start: Hello State\n' + 'states:\n' + ' - name: Hello State\n' + diff --git a/tests/lib/diagram/wf_with_compensation.json b/tests/lib/diagram/wf_with_compensation.json index 627fcf4..877e932 100644 --- a/tests/lib/diagram/wf_with_compensation.json +++ b/tests/lib/diagram/wf_with_compensation.json @@ -1,7 +1,7 @@ { "id": "newItemPurchaseWorkflow", "version": "1.0", - "specVersion": "0.8", + "specVersion": "0.9", "name": "New Item Purchase Workflow", "states": [ { diff --git a/tests/lib/workflow-validator.spec.ts b/tests/lib/workflow-validator.spec.ts index 9e9c868..8366f88 100644 --- a/tests/lib/workflow-validator.spec.ts +++ b/tests/lib/workflow-validator.spec.ts @@ -22,7 +22,7 @@ describe('workflow-validator, invalid state', () => { const validWorkflow = { id: 'helloworld', version: '1.0.0', - specVersion: '0.8', + specVersion: '0.9', name: 'Hello World Workflow', description: 'Inject Hello World', start: 'Hello State', @@ -41,8 +41,7 @@ describe('workflow-validator, invalid state', () => { it('should return errors instance of ValidationError if the workflow provided is not valid', () => { const workflowWithEmptyStates = Workflow.fromSource(JSON.stringify(validWorkflow)); - // @ts-ignore - workflowWithEmptyStates.states = []; + workflowWithEmptyStates.states = [] as any; const workflowValidator = new WorkflowValidator(workflowWithEmptyStates); diff --git a/tools/utils.ts b/tools/utils.ts index 36ee7cc..231b529 100644 --- a/tools/utils.ts +++ b/tools/utils.ts @@ -174,7 +174,7 @@ export const mergeSchemas = ( }; /** Resets the destination directory, recursively deletes everything and adds the README */ -export const reset = async (destDir: string) => +export const reset = async (destDir: string): Promise => rimrafP(destDir) .then(() => mkdir(destDir, { recursive: true })) .then(() => writeFile(path.resolve(destDir, 'README.md'), readMeDisclaimer));