bpmn-elements 7.0.0 → 8.1.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 (72) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/src/Context.js +50 -40
  3. package/dist/src/Environment.js +39 -19
  4. package/dist/src/MessageFormatter.js +11 -11
  5. package/dist/src/activity/Activity.js +106 -106
  6. package/dist/src/activity/ActivityExecution.js +37 -37
  7. package/dist/src/activity/Message.js +2 -2
  8. package/dist/src/activity/Signal.js +2 -2
  9. package/dist/src/definition/Definition.js +50 -50
  10. package/dist/src/definition/DefinitionExecution.js +114 -125
  11. package/dist/src/eventDefinitions/CancelEventDefinition.js +16 -16
  12. package/dist/src/eventDefinitions/CompensateEventDefinition.js +24 -24
  13. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
  14. package/dist/src/eventDefinitions/ErrorEventDefinition.js +26 -26
  15. package/dist/src/eventDefinitions/EscalationEventDefinition.js +20 -20
  16. package/dist/src/eventDefinitions/EventDefinitionExecution.js +14 -14
  17. package/dist/src/eventDefinitions/LinkEventDefinition.js +15 -15
  18. package/dist/src/eventDefinitions/MessageEventDefinition.js +23 -23
  19. package/dist/src/eventDefinitions/SignalEventDefinition.js +24 -24
  20. package/dist/src/eventDefinitions/TimerEventDefinition.js +76 -53
  21. package/dist/src/events/BoundaryEvent.js +67 -38
  22. package/dist/src/events/EndEvent.js +3 -3
  23. package/dist/src/events/IntermediateCatchEvent.js +3 -3
  24. package/dist/src/events/IntermediateThrowEvent.js +3 -3
  25. package/dist/src/events/StartEvent.js +9 -9
  26. package/dist/src/flows/Association.js +7 -7
  27. package/dist/src/flows/MessageFlow.js +9 -9
  28. package/dist/src/flows/SequenceFlow.js +7 -7
  29. package/dist/src/gateways/EventBasedGateway.js +11 -11
  30. package/dist/src/io/InputOutputSpecification.js +4 -4
  31. package/dist/src/io/Properties.js +9 -9
  32. package/dist/src/process/Process.js +64 -61
  33. package/dist/src/process/ProcessExecution.js +93 -90
  34. package/dist/src/tasks/ReceiveTask.js +16 -16
  35. package/dist/src/tasks/SubProcess.js +16 -18
  36. package/package.json +15 -16
  37. package/src/Context.js +48 -40
  38. package/src/Environment.js +48 -20
  39. package/src/EventBroker.js +1 -1
  40. package/src/MessageFormatter.js +11 -11
  41. package/src/activity/Activity.js +99 -100
  42. package/src/activity/ActivityExecution.js +35 -35
  43. package/src/activity/Message.js +1 -1
  44. package/src/activity/Signal.js +1 -1
  45. package/src/definition/Definition.js +51 -50
  46. package/src/definition/DefinitionExecution.js +111 -113
  47. package/src/eventDefinitions/CancelEventDefinition.js +16 -16
  48. package/src/eventDefinitions/CompensateEventDefinition.js +25 -24
  49. package/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
  50. package/src/eventDefinitions/ErrorEventDefinition.js +26 -26
  51. package/src/eventDefinitions/EscalationEventDefinition.js +20 -20
  52. package/src/eventDefinitions/EventDefinitionExecution.js +14 -14
  53. package/src/eventDefinitions/LinkEventDefinition.js +15 -15
  54. package/src/eventDefinitions/MessageEventDefinition.js +23 -23
  55. package/src/eventDefinitions/SignalEventDefinition.js +24 -24
  56. package/src/eventDefinitions/TimerEventDefinition.js +61 -44
  57. package/src/events/BoundaryEvent.js +53 -36
  58. package/src/events/EndEvent.js +3 -3
  59. package/src/events/IntermediateCatchEvent.js +3 -3
  60. package/src/events/IntermediateThrowEvent.js +3 -3
  61. package/src/events/StartEvent.js +9 -9
  62. package/src/flows/Association.js +7 -7
  63. package/src/flows/MessageFlow.js +9 -9
  64. package/src/flows/SequenceFlow.js +7 -7
  65. package/src/gateways/EventBasedGateway.js +11 -11
  66. package/src/io/BpmnIO.js +5 -1
  67. package/src/io/InputOutputSpecification.js +4 -4
  68. package/src/io/Properties.js +9 -9
  69. package/src/process/Process.js +62 -58
  70. package/src/process/ProcessExecution.js +86 -88
  71. package/src/tasks/ReceiveTask.js +16 -16
  72. package/src/tasks/SubProcess.js +16 -16
@@ -5,15 +5,15 @@ import {ProcessBroker} from '../EventBroker';
5
5
  import {cloneMessage, cloneContent, cloneParent} from '../messageHelper';
6
6
  import {makeErrorFromMessage} from '../error/Errors';
7
7
 
8
- const consumingSymbol = Symbol.for('consuming');
9
- const countersSymbol = Symbol.for('counters');
10
- const execSymbol = Symbol.for('exec');
11
- const executeMessageSymbol = Symbol.for('executeMessage');
12
- const extensionsSymbol = Symbol.for('extensions');
13
- const messageHandlersSymbol = Symbol.for('messageHandlers');
14
- const stateMessageSymbol = Symbol.for('stateMessage');
15
- const statusSymbol = Symbol.for('status');
16
- const stoppedSymbol = Symbol.for('stopped');
8
+ const kConsuming = Symbol.for('consuming');
9
+ const kCounters = Symbol.for('counters');
10
+ const kExec = Symbol.for('execution');
11
+ const kExecuteMessage = Symbol.for('executeMessage');
12
+ const kExtensions = Symbol.for('extensions');
13
+ const kMessageHandlers = Symbol.for('messageHandlers');
14
+ const kStateMessage = Symbol.for('stateMessage');
15
+ const kStatus = Symbol.for('status');
16
+ const kStopped = Symbol.for('stopped');
17
17
 
18
18
  export default Process;
19
19
 
@@ -30,12 +30,14 @@ export function Process(processDef, context) {
30
30
 
31
31
  const environment = this.environment = context.environment;
32
32
  this.context = context;
33
- this[countersSymbol] = {
33
+ this[kCounters] = {
34
34
  completed: 0,
35
35
  discarded: 0,
36
36
  };
37
- this[stoppedSymbol] = false;
38
- this[execSymbol] = {};
37
+ this[kConsuming] = false;
38
+ this[kExec] = {};
39
+ this[kStatus] = undefined;
40
+ this[kStopped] = false;
39
41
 
40
42
  const {broker, on, once, waitFor} = ProcessBroker(this);
41
43
  this.broker = broker;
@@ -43,7 +45,7 @@ export function Process(processDef, context) {
43
45
  this.once = once;
44
46
  this.waitFor = waitFor;
45
47
 
46
- this[messageHandlersSymbol] = {
48
+ this[kMessageHandlers] = {
47
49
  onApiMessage: this._onApiMessage.bind(this),
48
50
  onRunMessage: this._onRunMessage.bind(this),
49
51
  onExecutionMessage: this._onExecutionMessage.bind(this),
@@ -51,7 +53,7 @@ export function Process(processDef, context) {
51
53
 
52
54
  this.logger = environment.Logger(type.toLowerCase());
53
55
 
54
- this[extensionsSymbol] = context.loadExtensions(this);
56
+ this[kExtensions] = context.loadExtensions(this);
55
57
  }
56
58
 
57
59
  const proto = Process.prototype;
@@ -59,28 +61,28 @@ const proto = Process.prototype;
59
61
  Object.defineProperty(proto, 'counters', {
60
62
  enumerable: true,
61
63
  get() {
62
- return {...this[countersSymbol]};
64
+ return {...this[kCounters]};
63
65
  },
64
66
  });
65
67
 
66
68
  Object.defineProperty(proto, 'extensions', {
67
69
  enumerable: true,
68
70
  get() {
69
- return this[extensionsSymbol];
71
+ return this[kExtensions];
70
72
  },
71
73
  });
72
74
 
73
75
  Object.defineProperty(proto, 'stopped', {
74
76
  enumerable: true,
75
77
  get() {
76
- return this[stoppedSymbol];
78
+ return this[kStopped];
77
79
  },
78
80
  });
79
81
 
80
82
  Object.defineProperty(proto, 'isRunning', {
81
83
  enumerable: true,
82
84
  get() {
83
- if (!this[consumingSymbol]) return false;
85
+ if (!this[kConsuming]) return false;
84
86
  return !!this.status;
85
87
  },
86
88
  });
@@ -88,7 +90,7 @@ Object.defineProperty(proto, 'isRunning', {
88
90
  Object.defineProperty(proto, 'executionId', {
89
91
  enumerable: true,
90
92
  get() {
91
- const {executionId, initExecutionId} = this[execSymbol];
93
+ const {executionId, initExecutionId} = this[kExec];
92
94
  return executionId || initExecutionId;
93
95
  },
94
96
  });
@@ -96,19 +98,19 @@ Object.defineProperty(proto, 'executionId', {
96
98
  Object.defineProperty(proto, 'execution', {
97
99
  enumerable: true,
98
100
  get() {
99
- return this[execSymbol].execution;
101
+ return this[kExec].execution;
100
102
  },
101
103
  });
102
104
 
103
105
  Object.defineProperty(proto, 'status', {
104
106
  enumerable: true,
105
107
  get() {
106
- return this[statusSymbol];
108
+ return this[kStatus];
107
109
  },
108
110
  });
109
111
 
110
112
  proto.init = function init(useAsExecutionId) {
111
- const exec = this[execSymbol];
113
+ const exec = this[kExec];
112
114
  const initExecutionId = exec.initExecutionId = useAsExecutionId || getUniqueId(this.id);
113
115
  this._debug(`initialized with executionId <${initExecutionId}>`);
114
116
  this._publishEvent('init', this._createMessage({executionId: initExecutionId}));
@@ -117,7 +119,7 @@ proto.init = function init(useAsExecutionId) {
117
119
  proto.run = function run(runContent) {
118
120
  if (this.isRunning) throw new Error(`process <${this.id}> is already running`);
119
121
 
120
- const exec = this[execSymbol];
122
+ const exec = this[kExec];
121
123
  const executionId = exec.executionId = exec.initExecutionId || getUniqueId(this.id);
122
124
  exec.initExecutionId = undefined;
123
125
 
@@ -135,7 +137,7 @@ proto.resume = function resume() {
135
137
  if (this.isRunning) throw new Error(`cannot resume running process <${this.id}>`);
136
138
  if (!this.status) return this;
137
139
 
138
- this[stoppedSymbol] = false;
140
+ this[kStopped] = false;
139
141
 
140
142
  const content = this._createMessage();
141
143
  this.broker.publish('run', 'run.resume', content, {persistent: false});
@@ -147,11 +149,11 @@ proto.recover = function recover(state) {
147
149
  if (this.isRunning) throw new Error(`cannot recover running process <${this.id}>`);
148
150
  if (!state) return this;
149
151
 
150
- this[stoppedSymbol] = !!state.stopped;
151
- this[statusSymbol] = state.status;
152
- const exec = this[execSymbol];
152
+ this[kStopped] = !!state.stopped;
153
+ this[kStatus] = state.status;
154
+ const exec = this[kExec];
153
155
  exec.executionId = state.executionId;
154
- this[countersSymbol] = {...this[countersSymbol], ...state.counters};
156
+ this[kCounters] = {...this[kCounters], ...state.counters};
155
157
  this.environment.recover(state.environment);
156
158
 
157
159
  if (state.execution) {
@@ -176,7 +178,7 @@ proto.stop = function stop() {
176
178
  proto.getApi = function getApi(message) {
177
179
  const execution = this.execution;
178
180
  if (execution) return execution.getApi(message);
179
- return ProcessApi(this.broker, message || this[stateMessageSymbol]);
181
+ return ProcessApi(this.broker, message || this[kStateMessage]);
180
182
  };
181
183
 
182
184
  proto.signal = function signal(message) {
@@ -191,7 +193,6 @@ proto.getState = function getState() {
191
193
  counters: this.counters,
192
194
  broker: this.broker.getState(true),
193
195
  execution: this.execution && this.execution.getState(),
194
- output: {...this.environment.output},
195
196
  });
196
197
  };
197
198
 
@@ -200,9 +201,9 @@ proto.cancelActivity = function cancelActivity(message) {
200
201
  };
201
202
 
202
203
  proto._activateRunConsumers = function activateRunConsumers() {
203
- this[consumingSymbol] = true;
204
+ this[kConsuming] = true;
204
205
  const broker = this.broker;
205
- const {onApiMessage, onRunMessage} = this[messageHandlersSymbol];
206
+ const {onApiMessage, onRunMessage} = this[kMessageHandlers];
206
207
  broker.subscribeTmp('api', `process.*.${this.executionId}`, onApiMessage, {noAck: true, consumerTag: '_process-api', priority: 100});
207
208
  broker.getQueue('run-q').assertConsumer(onRunMessage, {exclusive: true, consumerTag: '_process-run'});
208
209
  };
@@ -212,7 +213,7 @@ proto._deactivateRunConsumers = function deactivateRunConsumers() {
212
213
  broker.cancel('_process-api');
213
214
  broker.cancel('_process-run');
214
215
  broker.cancel('_process-execution');
215
- this[consumingSymbol] = false;
216
+ this[kConsuming] = false;
216
217
  };
217
218
 
218
219
  proto._onRunMessage = function onRunMessage(routingKey, message) {
@@ -222,14 +223,14 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
222
223
  return this._onResumeMessage(message);
223
224
  }
224
225
 
225
- const exec = this[execSymbol];
226
- this[stateMessageSymbol] = message;
226
+ const exec = this[kExec];
227
+ this[kStateMessage] = message;
227
228
 
228
229
  switch (routingKey) {
229
230
  case 'run.enter': {
230
231
  this._debug('enter');
231
232
 
232
- this[statusSymbol] = 'entered';
233
+ this[kStatus] = 'entered';
233
234
  if (fields.redelivered) break;
234
235
 
235
236
  exec.execution = undefined;
@@ -239,19 +240,19 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
239
240
  }
240
241
  case 'run.start': {
241
242
  this._debug('start');
242
- this[statusSymbol] = 'start';
243
+ this[kStatus] = 'start';
243
244
  this._publishEvent('start', content);
244
245
  break;
245
246
  }
246
247
  case 'run.execute': {
247
- this[statusSymbol] = 'executing';
248
+ this[kStatus] = 'executing';
248
249
  const executeMessage = cloneMessage(message);
249
250
  if (fields.redelivered && !exec.execution) {
250
251
  executeMessage.fields.redelivered = undefined;
251
252
  }
252
- this[executeMessageSymbol] = message;
253
+ this[kExecuteMessage] = message;
253
254
 
254
- this.broker.getQueue('execution-q').assertConsumer(this[messageHandlersSymbol].onExecutionMessage, {
255
+ this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
255
256
  exclusive: true,
256
257
  consumerTag: '_process-execution',
257
258
  });
@@ -260,18 +261,19 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
260
261
  return execution.execute(executeMessage);
261
262
  }
262
263
  case 'run.error': {
264
+ this[kStatus] = 'errored';
263
265
  this._publishEvent('error', cloneContent(content, {
264
266
  error: fields.redelivered ? makeErrorFromMessage(message) : content.error,
265
267
  }));
266
268
  break;
267
269
  }
268
270
  case 'run.end': {
269
- this[statusSymbol] = 'end';
271
+ this[kStatus] = 'end';
270
272
 
271
273
  if (fields.redelivered) break;
272
274
  this._debug('completed');
273
275
 
274
- this[countersSymbol].completed++;
276
+ this[kCounters].completed++;
275
277
 
276
278
  this.broker.publish('run', 'run.leave', content);
277
279
 
@@ -279,10 +281,10 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
279
281
  break;
280
282
  }
281
283
  case 'run.discarded': {
282
- this[statusSymbol] = 'discarded';
284
+ this[kStatus] = 'discarded';
283
285
  if (fields.redelivered) break;
284
286
 
285
- this[countersSymbol].discarded++;
287
+ this[kCounters].discarded++;
286
288
 
287
289
  this.broker.publish('run', 'run.leave', content);
288
290
 
@@ -290,7 +292,7 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
290
292
  break;
291
293
  }
292
294
  case 'run.leave': {
293
- this[statusSymbol] = undefined;
295
+ this[kStatus] = undefined;
294
296
  this.broker.cancel('_process-api');
295
297
  const {output, ...rest} = content; // eslint-disable-line no-unused-vars
296
298
  this._publishEvent('leave', rest);
@@ -304,7 +306,7 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
304
306
  proto._onResumeMessage = function onResumeMessage(message) {
305
307
  message.ack();
306
308
 
307
- const stateMessage = this[stateMessageSymbol];
309
+ const stateMessage = this[kStateMessage];
308
310
  switch (stateMessage.fields.routingKey) {
309
311
  case 'run.enter':
310
312
  case 'run.start':
@@ -345,11 +347,9 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
345
347
  }
346
348
  }
347
349
 
348
- const executeMessage = this[executeMessageSymbol];
349
- if (executeMessage) {
350
- this[executeMessageSymbol] = null;
351
- executeMessage.ack();
352
- }
350
+ const executeMessage = this[kExecuteMessage];
351
+ this[kExecuteMessage] = null;
352
+ executeMessage.ack();
353
353
  };
354
354
 
355
355
  proto._publishEvent = function publishEvent(state, content) {
@@ -358,7 +358,7 @@ proto._publishEvent = function publishEvent(state, content) {
358
358
  };
359
359
 
360
360
  proto.sendMessage = function sendMessage(message) {
361
- const messageContent = message.content;
361
+ const messageContent = message && message.content;
362
362
  if (!messageContent) return;
363
363
 
364
364
  let targetsFound = false;
@@ -374,12 +374,14 @@ proto.sendMessage = function sendMessage(message) {
374
374
  };
375
375
 
376
376
  proto.getActivityById = function getActivityById(childId) {
377
- if (this.execution) return this.execution.getActivityById(childId);
377
+ const execution = this.execution;
378
+ if (execution) return execution.getActivityById(childId);
378
379
  return this.context.getActivityById(childId);
379
380
  };
380
381
 
381
382
  proto.getActivities = function getActivities() {
382
- if (this.execution) return this.execution.getActivities();
383
+ const execution = this.execution;
384
+ if (execution) return execution.getActivities();
383
385
  return this.context.getActivities(this.id);
384
386
  };
385
387
 
@@ -388,13 +390,15 @@ proto.getStartActivities = function getStartActivities(filterOptions) {
388
390
  };
389
391
 
390
392
  proto.getSequenceFlows = function getSequenceFlows() {
391
- if (this.execution) return this.execution.getSequenceFlows();
393
+ const execution = this.execution;
394
+ if (execution) return execution.getSequenceFlows();
392
395
  return this.context.getSequenceFlows();
393
396
  };
394
397
 
395
398
  proto.getPostponed = function getPostponed(...args) {
396
- if (!this.execution) return [];
397
- return this.execution.getPostponed(...args);
399
+ const execution = this.execution;
400
+ if (!execution) return [];
401
+ return execution.getPostponed(...args);
398
402
  };
399
403
 
400
404
  proto._onApiMessage = function onApiMessage(routingKey, message) {
@@ -410,7 +414,7 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
410
414
  };
411
415
 
412
416
  proto._onStop = function onStop() {
413
- this[stoppedSymbol] = true;
417
+ this[kStopped] = true;
414
418
  this._deactivateRunConsumers();
415
419
  return this._publishEvent('stop');
416
420
  };