Skip to content

Commit

Permalink
Created legacy branch for spec v0.9
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Baptiste Bianchi <[email protected]>
  • Loading branch information
JBBianchi committed Aug 9, 2024
1 parent af7a343 commit f6dbeb4
Show file tree
Hide file tree
Showing 39 changed files with 75 additions and 72 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
};
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) |



Expand All @@ -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
```
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/browser/mermaid.html
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/lib/diagram/mermaidDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Expand Down
12 changes: 7 additions & 5 deletions src/lib/diagram/mermaidState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export class MermaidState {
private isFirstState: boolean = false
) {}

sourceCode() {
sourceCode(): string {
const stateDefinition = this.definitions();
const stateTransitions = this.transitions();

Expand Down Expand Up @@ -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(',') + ']';
}
}

Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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'
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/applicantrequest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/applicantrequest.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/booklending.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/booklending.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/carauctionbids.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/carauctionbids.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/checkcarvitals.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "checkcarvitals",
"name": "Check Car Vitals Workflow",
"version": "1.0.0",
"specVersion": "0.8",
"specVersion": "0.9",
"start": "WhenCarIsOn",
"states": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/checkcarvitals.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/jobmonitoring.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/jobmonitoring.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/parallel.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/parallel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/provisionorder.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/provisionorder.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/sendcloudevent.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/sendcloudevent.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/solvemathproblems.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
{
Expand Down
2 changes: 1 addition & 1 deletion tests/examples/solvemathproblems.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
6 changes: 3 additions & 3 deletions tests/lib/definitions/action.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion tests/lib/definitions/branch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
4 changes: 2 additions & 2 deletions tests/lib/definitions/eventdef.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});
2 changes: 1 addition & 1 deletion tests/lib/definitions/schedule.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
Loading

0 comments on commit f6dbeb4

Please sign in to comment.