bpmn-elements 5.1.3 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. package/src/tasks/Task.js +15 -19
@@ -1,206 +1,241 @@
1
- import {cloneContent, cloneMessage} from '../messageHelper';
1
+ import {cloneContent} from '../messageHelper';
2
2
  import {toSeconds, parse} from 'iso8601-duration';
3
3
 
4
+ const stoppedSymbol = Symbol.for('stopped');
5
+ const timerContentSymbol = Symbol.for('timerContent');
6
+ const timerSymbol = Symbol.for('timer');
7
+
4
8
  export default function TimerEventDefinition(activity, eventDefinition) {
5
- const {id, broker, environment} = activity;
6
- const {type = 'TimerEventDefinition', behaviour = {}} = eventDefinition;
7
-
8
- const logger = environment.Logger(type.toLowerCase());
9
- const {timeDuration, timeCycle, timeDate} = behaviour;
10
- const foundTimers = {
11
- ...(timeDuration ? {timeDuration} : undefined),
12
- ...(timeCycle ? {timeCycle} : undefined),
13
- ...(timeDate ? {timeDate} : undefined),
14
- };
9
+ const type = this.type = eventDefinition.type || 'TimerEventDefinition';
10
+ this.activity = activity;
11
+ const environment = this.environment = activity.environment;
12
+ this.eventDefinition = eventDefinition;
15
13
 
16
- let stopped = false;
17
- let timerRef;
14
+ const {timeDuration, timeCycle, timeDate} = eventDefinition.behaviour || {};
15
+ if (timeDuration) this.timeDuration = timeDuration;
16
+ if (timeCycle) this.timeCycle = timeCycle;
17
+ if (timeDate) this.timeDate = timeDate;
18
18
 
19
- const source = {
20
- type,
21
- ...foundTimers,
22
- execute,
23
- stop() {
24
- if (timerRef) timerRef = environment.timers.clearTimeout(timerRef);
25
- },
26
- };
19
+ this.broker = activity.broker;
20
+ this.logger = environment.Logger(type.toLowerCase());
27
21
 
28
- Object.defineProperty(source, 'timer', {
29
- get() {
30
- return timerRef;
31
- },
32
- });
22
+ this[stoppedSymbol] = false;
23
+ this[timerSymbol] = null;
24
+ }
33
25
 
34
- return source;
26
+ const proto = TimerEventDefinition.prototype;
27
+
28
+ Object.defineProperty(proto, 'executionId', {
29
+ get() {
30
+ const content = this[timerContentSymbol];
31
+ return content && content.executionId;
32
+ },
33
+ });
34
+
35
+ Object.defineProperty(proto, 'stopped', {
36
+ enumerable: true,
37
+ get() {
38
+ return this[stoppedSymbol];
39
+ },
40
+ });
41
+
42
+ Object.defineProperty(proto, 'timer', {
43
+ enumerable: true,
44
+ get() {
45
+ return this[timerSymbol];
46
+ },
47
+ });
48
+
49
+ proto.execute = function execute(executeMessage) {
50
+ const {routingKey: executeKey, redelivered: isResumed} = executeMessage.fields;
51
+ const timer = this[timerSymbol];
52
+ if (timer && executeKey === 'execute.timer') {
53
+ return;
54
+ }
35
55
 
36
- function execute(executeMessage) {
37
- const {routingKey: executeKey, redelivered: isResumed} = executeMessage.fields;
38
- const running = !!timerRef;
39
- if (running && executeKey === 'execute.timer') {
40
- return;
41
- }
56
+ if (timer) this[timerSymbol] = this.environment.timers.clearTimeout(timer);
57
+ this[stoppedSymbol] = false;
42
58
 
43
- if (timerRef) timerRef = environment.timers.clearTimeout(timerRef);
44
- stopped = false;
59
+ const content = executeMessage.content;
60
+ const executionId = content.executionId;
61
+ const startedAt = this.startedAt = 'startedAt' in content ? new Date(content.startedAt) : new Date();
45
62
 
46
- const {executionId} = executeMessage.content;
63
+ const resolvedTimer = this._getTimers(executeMessage);
64
+ const timerContent = this[timerContentSymbol] = cloneContent(content, {
65
+ ...resolvedTimer,
66
+ ...(isResumed ? {isResumed} : undefined),
67
+ startedAt,
68
+ state: 'timer',
69
+ });
47
70
 
48
- const messageContent = executeMessage.content;
49
- const startedAt = 'startedAt' in messageContent ? new Date(messageContent.startedAt) : new Date();
71
+ const broker = this.broker;
72
+ broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
73
+ noAck: true, consumerTag: `_api-${executionId}`,
74
+ priority: 400,
75
+ });
76
+ broker.subscribeTmp('api', '#.cancel.*', this._onDelegatedApiMessage.bind(this), {
77
+ noAck: true, consumerTag: `_api-delegated-${executionId}`,
78
+ });
50
79
 
51
- const resolvedTimer = getTimers(foundTimers, executeMessage);
52
- const timerContent = cloneContent(messageContent, {
53
- ...resolvedTimer,
54
- ...(isResumed ? {isResumed} : undefined),
55
- startedAt,
56
- state: 'timer',
57
- });
80
+ broker.publish('execution', 'execute.timer', cloneContent(timerContent));
81
+ broker.publish('event', 'activity.timer', cloneContent(timerContent));
58
82
 
59
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`, priority: 400});
60
- broker.subscribeTmp('api', '#.cancel.*', onDelegatedApiMessage, {noAck: true, consumerTag: `_api-delegated-${executionId}`});
83
+ if (this.stopped) return;
61
84
 
62
- broker.publish('execution', 'execute.timer', timerContent);
63
- broker.publish('event', 'activity.timer', cloneContent(timerContent));
85
+ if (timerContent.timeout === undefined) return this._debug(`waiting for ${timerContent.timerType || 'signal'}`);
86
+ if (timerContent.timeout <= 0) return this._completed();
64
87
 
65
- if (stopped) return;
88
+ const timers = this.environment.timers.register(timerContent);
89
+ this[timerSymbol] = timers.setTimeout(this._completed.bind(this), timerContent.timeout, {
90
+ id: content.id,
91
+ type: this.type,
92
+ executionId,
93
+ state: 'timeout',
94
+ });
95
+ };
66
96
 
67
- if (timerContent.timeout === undefined) return logger.debug(`<${executionId} (${id})> waiting for ${timerContent.timerType || 'signal'}`);
68
- if (timerContent.timeout <= 0) return completed();
97
+ proto.stop = function stopTimer() {
98
+ const timer = this[timerSymbol];
99
+ if (timer) this[timerSymbol] = this.environment.timers.clearTimeout(timer);
100
+ };
69
101
 
70
- const timers = environment.timers.register(timerContent);
102
+ proto._completed = function completed(completeContent, options) {
103
+ this._stop();
71
104
 
72
- timerRef = timers.setTimeout(completed, timerContent.timeout, cloneMessage(executeMessage, timerContent));
105
+ const stoppedAt = new Date();
73
106
 
74
- function completed(completeContent, options) {
75
- stop();
107
+ const runningTime = stoppedAt.getTime() - this.startedAt.getTime();
108
+ this._debug(`completed in ${runningTime}ms`);
76
109
 
77
- const stoppedAt = new Date();
110
+ const timerContent = this[timerContentSymbol];
111
+ const content = {stoppedAt, runningTime, state: 'timeout', ...completeContent};
78
112
 
79
- const runningTime = stoppedAt.getTime() - startedAt.getTime();
80
- logger.debug(`<${executionId} (${id})> completed in ${runningTime}ms`);
113
+ const broker = this.broker;
114
+ broker.publish('event', 'activity.timeout', cloneContent(timerContent, content), options);
115
+ broker.publish('execution', 'execute.completed', cloneContent(timerContent, content), options);
116
+ };
81
117
 
82
- const completedContent = {...timerContent, stoppedAt, runningTime, state: 'timeout', ...completeContent};
118
+ proto._onDelegatedApiMessage = function onDelegatedApiMessage(routingKey, message) {
119
+ if (!message.properties.delegate) return;
83
120
 
84
- broker.publish('event', 'activity.timeout', cloneContent(messageContent, completedContent), options);
85
- broker.publish('execution', 'execute.completed', cloneContent(messageContent, completedContent), options);
86
- }
121
+ const content = message.content;
122
+ if (!content.message) return;
87
123
 
88
- function onDelegatedApiMessage(routingKey, message) {
89
- if (!message.properties.delegate) return;
90
- const {content: delegateContent} = message;
91
- if (!delegateContent.message) return;
124
+ const {id: signalId, executionId: signalExecutionId} = content.message;
92
125
 
93
- const {id: signalId, executionId: signalExecutionId} = delegateContent.message;
94
- if (signalId !== id && signalExecutionId !== executionId) return;
95
- if (signalExecutionId && signalId === id && signalExecutionId !== executionId) return;
126
+ const executionId = this.executionId;
127
+ const id = this.activity.id;
128
+ if (signalId !== id && signalExecutionId !== executionId) return;
129
+ if (signalExecutionId && signalId === id && signalExecutionId !== executionId) return;
96
130
 
97
- const {type: messageType, correlationId} = message.properties;
98
- broker.publish('event', 'activity.consumed', cloneContent(timerContent, {message: {...delegateContent.message}}), {correlationId, type: messageType});
99
- return onApiMessage(routingKey, message);
100
- }
131
+ const {type, correlationId} = message.properties;
132
+ this.broker.publish('event', 'activity.consumed', cloneContent(this[timerContentSymbol], {
133
+ message: {
134
+ ...content.message,
135
+ },
136
+ }), {correlationId, type});
101
137
 
102
- function onApiMessage(routingKey, message) {
103
- const {type: messageType, correlationId} = message.properties;
138
+ return this._onApiMessage(routingKey, message);
139
+ };
104
140
 
105
- switch (messageType) {
106
- case 'cancel': {
107
- stop();
108
- return completed({
109
- state: 'cancel',
110
- ...(message.content.message ? {message: message.content.message} : undefined),
111
- }, {correlationId});
112
- }
113
- case 'stop': {
114
- stop();
115
- return logger.debug(`<${executionId} (${id})> stopped`);
116
- }
117
- case 'discard': {
118
- stop();
119
- logger.debug(`<${executionId} (${id})> discarded`);
120
- return broker.publish('execution', 'execute.discard', cloneContent(timerContent, {state: 'discard'}), {correlationId});
121
- }
122
- }
123
- }
141
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
142
+ const {type: messageType, correlationId} = message.properties;
124
143
 
125
- function stop() {
126
- stopped = true;
127
- if (timerRef) timerRef = environment.timers.clearTimeout(timerRef);
128
- broker.cancel(`_api-${executionId}`);
129
- broker.cancel(`_api-delegated-${executionId}`);
144
+ switch (messageType) {
145
+ case 'cancel': {
146
+ this._stop();
147
+ return this._completed({
148
+ state: 'cancel',
149
+ ...(message.content.message ? {message: message.content.message} : undefined),
150
+ }, {correlationId});
130
151
  }
131
- }
132
-
133
- function getTimers(timers, executionMessage) {
134
- const content = executionMessage.content;
135
-
136
- let expireAt;
137
- if ('expireAt' in content) {
138
- expireAt = new Date(content.expireAt);
152
+ case 'stop': {
153
+ this._stop();
154
+ return this._debug('stopped');
139
155
  }
156
+ case 'discard': {
157
+ this._stop();
158
+ this._debug('discarded');
159
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[timerContentSymbol], {state: 'discard'}), {correlationId});
160
+ }
161
+ }
162
+ };
163
+
164
+ proto._stop = function stop() {
165
+ this[stoppedSymbol] = true;
166
+ const timer = this[timerSymbol];
167
+ if (timer) this[timerSymbol] = this.environment.timers.clearTimeout(timer);
168
+ const broker = this.broker;
169
+ broker.cancel(`_api-${this.executionId}`);
170
+ broker.cancel(`_api-delegated-${this.executionId}`);
171
+ };
172
+
173
+ proto._getTimers = function getTimers(executeMessage) {
174
+ const content = executeMessage.content;
175
+
176
+ const now = Date.now();
177
+ const result = {
178
+ ...('expireAt' in content ? {expireAt: new Date(content.expireAt)} : undefined),
179
+ };
140
180
 
141
- const now = Date.now();
142
-
143
- const timerContent = ['timeDuration', 'timeDate', 'timeCycle'].reduce((result, t) => {
144
- if (t in content) result[t] = content[t];
145
- else if (t in timers) result[t] = environment.resolveExpression(timers[t], executionMessage);
146
- else return result;
147
-
148
- let expireAtDate;
149
- switch (t) {
150
- case 'timeDuration': {
151
- const durationStr = result[t];
152
- if (durationStr) {
153
- const delay = getDurationInMilliseconds(durationStr);
154
- if (delay !== undefined) expireAtDate = new Date(now + delay);
155
- } else {
156
- expireAtDate = new Date(now);
157
- }
158
- break;
159
- }
160
- case 'timeDate': {
161
- const dateStr = result[t];
162
- if (dateStr) {
163
- const ms = Date.parse(dateStr);
164
- if (isNaN(ms)) {
165
- logger.warn(`<${content.executionId} (${id})> invalid timeDate >${dateStr}<`);
166
- break;
167
- }
168
- expireAtDate = new Date(ms);
169
- } else {
170
- expireAtDate = new Date(now);
171
- }
172
- break;
173
- }
181
+ for (const t of ['timeDuration', 'timeDate', 'timeCycle']) {
182
+ if (t in content) result[t] = content[t];
183
+ else if (t in this) result[t] = this.environment.resolveExpression(this[t], executeMessage);
184
+ else continue;
185
+
186
+ let expireAtDate;
187
+ if (t === 'timeDuration') {
188
+ const durationStr = result[t];
189
+ if (durationStr) {
190
+ const delay = this._getDurationInMilliseconds(durationStr);
191
+ if (delay !== undefined) expireAtDate = new Date(now + delay);
192
+ } else {
193
+ expireAtDate = new Date(now);
174
194
  }
175
-
176
- if (!expireAtDate) return result;
177
-
178
- if (!('expireAt' in result) || result.expireAt > expireAtDate) {
179
- result.timerType = t;
180
- result.expireAt = expireAtDate;
195
+ } else if (t === 'timeDate') {
196
+ const dateStr = result[t];
197
+ if (dateStr) {
198
+ const ms = Date.parse(dateStr);
199
+ if (!isNaN(ms)) {
200
+ expireAtDate = new Date(ms);
201
+ } else {
202
+ this._warn(`invalid timeDate >${dateStr}<`);
203
+ }
204
+ } else {
205
+ expireAtDate = new Date(now);
181
206
  }
207
+ }
182
208
 
183
- return result;
184
- }, {
185
- ...(expireAt ? {expireAt} : undefined),
186
- });
187
-
188
- if ('expireAt' in timerContent) {
189
- timerContent.timeout = timerContent.expireAt - now;
190
- } else if ('timeout' in content) {
191
- timerContent.timeout = content.timeout;
192
- } else if (!Object.keys(timerContent).length) {
193
- timerContent.timeout = 0;
209
+ if (!expireAtDate) continue;
210
+ if (!('expireAt' in result) || result.expireAt > expireAtDate) {
211
+ result.timerType = t;
212
+ result.expireAt = expireAtDate;
194
213
  }
214
+ }
195
215
 
196
- return timerContent;
216
+ if ('expireAt' in result) {
217
+ result.timeout = result.expireAt - now;
218
+ } else if ('timeout' in content) {
219
+ result.timeout = content.timeout;
220
+ } else if (!Object.keys(result).length) {
221
+ result.timeout = 0;
222
+ }
197
223
 
198
- function getDurationInMilliseconds(duration) {
199
- try {
200
- return toSeconds(parse(duration)) * 1000;
201
- } catch (err) {
202
- logger.warn(`<${content.executionId} (${id})> failed to parse timeDuration >${duration}<: ${err.message}`);
203
- }
204
- }
224
+ return result;
225
+ };
226
+
227
+ proto._getDurationInMilliseconds = function getDurationInMilliseconds(duration) {
228
+ try {
229
+ return toSeconds(parse(duration)) * 1000;
230
+ } catch (err) {
231
+ this._warn(`failed to parse timeDuration >${duration}<: ${err.message}`);
205
232
  }
206
- }
233
+ };
234
+
235
+ proto._debug = function debug(msg) {
236
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
237
+ };
238
+
239
+ proto._warn = function debug(msg) {
240
+ this.logger.warn(`<${this.executionId} (${this.activity.id})> ${msg}`);
241
+ };