Skip to content

Commit 219768d

Browse files
authored
order-properties-on-serialization (#159)
1 parent 96763b9 commit 219768d

22 files changed

+187
-151
lines changed

src/lib/definitions/callbackstate.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ export class Callbackstate {
4747
constructor(model: any) {
4848
this.sourceModel = Object.assign({}, model);
4949

50-
const defaultModel = { type: 'callback', usedForCompensation: false };
50+
const defaultModel = {
51+
id: undefined,
52+
name: undefined,
53+
type: 'callback',
54+
usedForCompensation: false,
55+
};
5156
Object.assign(this, defaultModel, model);
5257

5358
overwriteAction(this);
@@ -59,7 +64,6 @@ export class Callbackstate {
5964
overwriteEnd(this);
6065
overwriteMetadata(this);
6166
}
62-
6367
/**
6468
* Unique state id
6569
*/

src/lib/definitions/databasedswitchstate.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class Databasedswitchstate {
4040
constructor(model: any) {
4141
this.sourceModel = Object.assign({}, model);
4242

43-
const defaultModel = { type: 'switch', usedForCompensation: false };
43+
const defaultModel = { id: undefined, name: undefined, type: 'switch', usedForCompensation: false };
4444
Object.assign(this, defaultModel, model);
4545

4646
overwriteStateDataFilter(this);

src/lib/definitions/eventbasedswitchstate.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ export class Eventbasedswitchstate {
4040
constructor(model: any) {
4141
this.sourceModel = Object.assign({}, model);
4242

43-
const defaultModel = {
44-
type: 'switch',
45-
usedForCompensation: false,
46-
};
43+
const defaultModel = { id: undefined, name: undefined, type: 'switch', usedForCompensation: false };
4744
Object.assign(this, defaultModel, model);
4845

4946
overwriteStateDataFilter(this);
@@ -53,7 +50,6 @@ export class Eventbasedswitchstate {
5350
overwriteDefaultCondition(this);
5451
overwriteMetadata(this);
5552
}
56-
5753
/**
5854
* Unique State id
5955
*/

src/lib/definitions/eventstate.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { Onevents } from './onevents';
2020
import { Statedatafilter } from './statedatafilter';
2121
import { Transition } from './transition';
2222
import {
23+
cleanSourceModelProperty,
2324
normalizeEnd,
2425
normalizeExclusive,
2526
normalizeOnErrors,
@@ -30,10 +31,9 @@ import {
3031
overwriteOnErrors,
3132
overwriteOnEvents,
3233
overwriteStateDataFilter,
34+
overwriteTimeoutWithStateExecTimeout,
3335
overwriteTransition,
3436
setEndValueIfNoTransition,
35-
overwriteTimeoutWithStateExecTimeout,
36-
cleanSourceModelProperty,
3737
} from './utils';
3838
import { ActionExecTimeout, EventTimeout } from './types';
3939
import { StateExecTimeout } from './stateExecTimeout';
@@ -44,7 +44,12 @@ export class Eventstate /* This state is used to wait for events from event sour
4444
constructor(model: any) {
4545
this.sourceModel = Object.assign({}, model);
4646

47-
const defaultModel = { type: 'event', exclusive: true };
47+
const defaultModel = {
48+
id: undefined,
49+
name: undefined,
50+
type: 'event',
51+
exclusive: true,
52+
};
4853
Object.assign(this, defaultModel, model);
4954

5055
overwriteOnEvents(this);

src/lib/definitions/foreachstate.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ import { Metadata } from './metadata';
2020
import { Statedatafilter } from './statedatafilter';
2121
import { Transition } from './transition';
2222
import {
23+
cleanSourceModelProperty,
2324
normalizeActions,
2425
normalizeEnd,
26+
normalizeMode,
2527
normalizeOnErrors,
2628
normalizeTransition,
2729
normalizeUsedForCompensation,
@@ -30,11 +32,9 @@ import {
3032
overwriteMetadata,
3133
overwriteOnErrors,
3234
overwriteStateDataFilter,
35+
overwriteTimeoutWithStateExecTimeout,
3336
overwriteTransition,
3437
setEndValueIfNoTransition,
35-
normalizeMode,
36-
overwriteTimeoutWithStateExecTimeout,
37-
cleanSourceModelProperty,
3838
} from './utils';
3939
import { ActionExecTimeout } from './types';
4040
import { StateExecTimeout } from './stateExecTimeout';
@@ -45,7 +45,13 @@ export class Foreachstate {
4545
constructor(model: any) {
4646
this.sourceModel = Object.assign({}, model);
4747

48-
const defaultModel = { type: 'foreach', usedForCompensation: false, mode: 'parallel' };
48+
const defaultModel = {
49+
id: undefined,
50+
name: undefined,
51+
type: 'foreach',
52+
usedForCompensation: false,
53+
mode: 'parallel',
54+
};
4955
Object.assign(this, defaultModel, model);
5056

5157
overwriteEnd(this);
@@ -120,7 +126,6 @@ export class Foreachstate {
120126
* If true, this state is used to compensate another state. Default is false
121127
*/
122128
usedForCompensation?: boolean;
123-
124129
/**
125130
* Specifies how iterations are to be performed (sequentially or in parallel)
126131
*/

src/lib/definitions/injectstate.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,12 @@ export class Injectstate {
3939
constructor(model: any) {
4040
this.sourceModel = Object.assign({}, model);
4141

42-
const defaultModel = { type: 'inject', usedForCompensation: false };
42+
const defaultModel = {
43+
id: undefined,
44+
name: undefined,
45+
type: 'inject',
46+
usedForCompensation: false,
47+
};
4348
Object.assign(this, defaultModel, model);
4449

4550
overwriteEnd(this);

src/lib/definitions/operationstate.ts

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export class Operationstate {
4646
this.sourceModel = Object.assign({}, model);
4747

4848
const defaultModel = {
49+
id: undefined,
50+
name: undefined,
4951
type: 'operation',
5052
actionMode: 'sequential',
5153
usedForCompensation: false,

src/lib/definitions/parallelstate.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { Metadata } from './metadata';
2121
import { Statedatafilter } from './statedatafilter';
2222
import { Transition } from './transition';
2323
import {
24+
cleanSourceModelProperty,
2425
normalizeBranches,
2526
normalizeCompletionType,
2627
normalizeEnd,
@@ -32,10 +33,9 @@ import {
3233
overwriteMetadata,
3334
overwriteOnErrors,
3435
overwriteStateDataFilter,
36+
overwriteTimeoutWithStateExecTimeout,
3537
overwriteTransition,
3638
setEndValueIfNoTransition,
37-
overwriteTimeoutWithStateExecTimeout,
38-
cleanSourceModelProperty,
3939
} from './utils';
4040
import { BranchExecTimeout } from './types';
4141
import { StateExecTimeout } from './stateExecTimeout';
@@ -47,6 +47,8 @@ export class Parallelstate {
4747
this.sourceModel = Object.assign({}, model);
4848

4949
const defaultModel = {
50+
id: undefined,
51+
name: undefined,
5052
type: 'parallel',
5153
completionType: 'allOf',
5254
usedForCompensation: false,

src/lib/definitions/sleepstate.ts

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export class Sleepstate {
4242
this.sourceModel = Object.assign({}, model);
4343

4444
const defaultModel = {
45+
id: undefined,
46+
name: undefined,
4547
type: 'sleep',
4648
usedForCompensation: false,
4749
};

src/lib/definitions/workflow.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,20 @@ export class Workflow {
5151
this.sourceModel = Object.assign({}, model);
5252

5353
const defaultModel = {
54+
id: undefined,
55+
name: undefined,
56+
version: undefined,
57+
description: undefined,
58+
specVersion: undefined,
59+
start: undefined,
60+
states: undefined,
61+
functions: undefined,
62+
events: undefined,
63+
retries: undefined,
64+
timeouts: undefined,
5465
expressionLang: 'jq',
5566
keepActive: true,
56-
} as Specification.Workflow;
67+
};
5768

5869
Object.assign(this, defaultModel, model);
5970

tests/examples/applicantrequest.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
11
{
22
"id": "applicantrequest",
3-
"version": "1.0",
4-
"specVersion": "0.8",
53
"name": "Applicant Request Decision Workflow",
4+
"version": "1.0",
65
"description": "Determine if applicant request is valid",
6+
"specVersion": "0.8",
77
"start": "CheckApplication",
8-
"functions": [
9-
{
10-
"name": "sendRejectionEmailFunction",
11-
"operation": "http://myapis.org/applicationapi.json#emailRejection"
12-
}
13-
],
148
"states":[
159
{
16-
"type":"switch",
1710
"name":"CheckApplication",
11+
"type":"switch",
1812
"dataConditions": [
1913
{
2014
"condition": "${ .applicants | .age >= 18 }",
@@ -30,8 +24,8 @@
3024
}
3125
},
3226
{
33-
"type": "operation",
3427
"name": "StartApplication",
28+
"type": "operation",
3529
"actions": [
3630
{
3731
"subFlowRef": "startApplicationWorkflowId"
@@ -40,9 +34,9 @@
4034
"end": true
4135
},
4236
{
37+
"name":"RejectApplication",
4338
"type":"operation",
4439
"actionMode":"sequential",
45-
"name":"RejectApplication",
4640
"actions":[
4741
{
4842
"functionRef": {
@@ -55,5 +49,11 @@
5549
],
5650
"end": true
5751
}
52+
],
53+
"functions": [
54+
{
55+
"name": "sendRejectionEmailFunction",
56+
"operation": "http://myapis.org/applicationapi.json#emailRejection"
57+
}
5858
]
5959
}

tests/examples/booklending.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"start": "Book Lending Request",
77
"states": [
88
{
9-
"type": "event",
109
"name": "Book Lending Request",
10+
"type": "event",
1111
"onEvents": [
1212
{
1313
"eventRefs": ["Book Lending Request Event"]
@@ -16,8 +16,8 @@
1616
"transition": "Get Book Status"
1717
},
1818
{
19-
"type": "operation",
2019
"name": "Get Book Status",
20+
"type": "operation",
2121
"actions": [
2222
{
2323
"functionRef": {
@@ -31,8 +31,8 @@
3131
"transition": "Book Status Decision"
3232
},
3333
{
34-
"type": "switch",
3534
"name": "Book Status Decision",
35+
"type": "switch",
3636
"dataConditions": [
3737
{
3838
"name": "Book is on loan",
@@ -50,8 +50,8 @@
5050
}
5151
},
5252
{
53-
"type": "operation",
5453
"name": "Report Status To Lender",
54+
"type": "operation",
5555
"actions": [
5656
{
5757
"functionRef": {
@@ -66,8 +66,8 @@
6666
"transition": "Wait for Lender response"
6767
},
6868
{
69-
"type": "switch",
7069
"name": "Wait for Lender response",
70+
"type": "switch",
7171
"eventConditions": [
7272
{
7373
"name": "Hold Book",
@@ -85,8 +85,8 @@
8585
}
8686
},
8787
{
88-
"type": "operation",
8988
"name": "Request Hold",
89+
"type": "operation",
9090
"actions": [
9191
{
9292
"functionRef": {
@@ -101,14 +101,14 @@
101101
"transition": "Sleep two weeks"
102102
},
103103
{
104-
"type": "sleep",
105104
"name": "Sleep two weeks",
105+
"type": "sleep",
106106
"duration": "PT2W",
107107
"transition": "Get Book Status"
108108
},
109109
{
110-
"type": "operation",
111110
"name": "Check Out Book",
111+
"type": "operation",
112112
"actions": [
113113
{
114114
"functionRef": {

0 commit comments

Comments
 (0)