bpmn-elements 8.2.4 → 9.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 (127) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/{src/Api.js → Api.js} +11 -12
  4. package/dist/{src/Context.js → Context.js} +26 -27
  5. package/dist/{src/Environment.js → Environment.js} +15 -16
  6. package/dist/{src/EventBroker.js → EventBroker.js} +5 -1
  7. package/dist/{src/Expressions.js → Expressions.js} +1 -1
  8. package/dist/{src/MessageFormatter.js → MessageFormatter.js} +3 -3
  9. package/dist/Tracker.js +89 -0
  10. package/dist/{src/activity → activity}/Activity.js +109 -120
  11. package/dist/{src/activity → activity}/ActivityExecution.js +28 -32
  12. package/dist/{src/activity → activity}/Dummy.js +1 -1
  13. package/dist/{src/activity → activity}/ExecutionScope.js +2 -2
  14. package/dist/{src/definition → definition}/Definition.js +64 -59
  15. package/dist/{src/definition → definition}/DefinitionExecution.js +68 -46
  16. package/dist/{src/error → error}/Errors.js +1 -1
  17. package/dist/eventDefinitions/CancelEventDefinition.js +127 -0
  18. package/dist/{src/eventDefinitions → eventDefinitions}/CompensateEventDefinition.js +64 -52
  19. package/dist/{src/eventDefinitions → eventDefinitions}/ConditionalEventDefinition.js +24 -16
  20. package/dist/{src/eventDefinitions → eventDefinitions}/ErrorEventDefinition.js +15 -14
  21. package/dist/{src/eventDefinitions → eventDefinitions}/EscalationEventDefinition.js +12 -13
  22. package/dist/{src/eventDefinitions → eventDefinitions}/EventDefinitionExecution.js +10 -11
  23. package/dist/{src/eventDefinitions → eventDefinitions}/LinkEventDefinition.js +14 -15
  24. package/dist/{src/eventDefinitions → eventDefinitions}/MessageEventDefinition.js +13 -14
  25. package/dist/{src/eventDefinitions → eventDefinitions}/SignalEventDefinition.js +13 -14
  26. package/dist/{src/eventDefinitions → eventDefinitions}/TerminateEventDefinition.js +1 -1
  27. package/dist/{src/eventDefinitions → eventDefinitions}/TimerEventDefinition.js +15 -16
  28. package/dist/{src/events → events}/BoundaryEvent.js +39 -25
  29. package/dist/{src/events → events}/EndEvent.js +3 -3
  30. package/dist/{src/events → events}/IntermediateCatchEvent.js +3 -3
  31. package/dist/{src/events → events}/IntermediateThrowEvent.js +3 -3
  32. package/dist/{src/events → events}/StartEvent.js +8 -9
  33. package/dist/{src/flows → flows}/Association.js +14 -22
  34. package/dist/{src/flows → flows}/MessageFlow.js +16 -14
  35. package/dist/{src/flows → flows}/SequenceFlow.js +16 -18
  36. package/dist/{src/gateways → gateways}/EventBasedGateway.js +3 -4
  37. package/dist/{src/gateways → gateways}/ExclusiveGateway.js +2 -2
  38. package/dist/{src/gateways → gateways}/InclusiveGateway.js +2 -2
  39. package/dist/{src/gateways → gateways}/ParallelGateway.js +2 -2
  40. package/dist/index.js +48 -48
  41. package/dist/{src/io → io}/InputOutputSpecification.js +8 -9
  42. package/dist/{src/io → io}/Properties.js +7 -8
  43. package/dist/package.json +3 -0
  44. package/dist/{src/process → process}/Process.js +44 -40
  45. package/dist/{src/process → process}/ProcessExecution.js +169 -78
  46. package/dist/{src/tasks → tasks}/CallActivity.js +7 -8
  47. package/dist/{src/tasks → tasks}/LoopCharacteristics.js +2 -2
  48. package/dist/{src/tasks → tasks}/ReceiveTask.js +14 -15
  49. package/dist/{src/tasks → tasks}/ScriptTask.js +4 -4
  50. package/dist/{src/tasks → tasks}/ServiceImplementation.js +1 -1
  51. package/dist/{src/tasks → tasks}/ServiceTask.js +6 -7
  52. package/dist/{src/tasks → tasks}/SignalTask.js +7 -8
  53. package/dist/{src/tasks → tasks}/StandardLoopCharacteristics.js +1 -1
  54. package/dist/{src/tasks → tasks}/SubProcess.js +19 -19
  55. package/dist/{src/tasks → tasks}/Task.js +2 -2
  56. package/dist/{src/tasks → tasks}/Transaction.js +1 -1
  57. package/package.json +31 -31
  58. package/src/Api.js +11 -13
  59. package/src/Context.js +26 -28
  60. package/src/Environment.js +15 -17
  61. package/src/EventBroker.js +2 -1
  62. package/src/Expressions.js +1 -1
  63. package/src/MessageFormatter.js +3 -3
  64. package/src/Tracker.js +73 -0
  65. package/src/activity/Activity.js +106 -114
  66. package/src/activity/ActivityExecution.js +28 -32
  67. package/src/activity/Dummy.js +1 -1
  68. package/src/activity/ExecutionScope.js +2 -2
  69. package/src/definition/Definition.js +65 -64
  70. package/src/definition/DefinitionExecution.js +71 -47
  71. package/src/error/Errors.js +1 -1
  72. package/src/eventDefinitions/CancelEventDefinition.js +32 -78
  73. package/src/eventDefinitions/CompensateEventDefinition.js +58 -52
  74. package/src/eventDefinitions/ConditionalEventDefinition.js +25 -17
  75. package/src/eventDefinitions/ErrorEventDefinition.js +15 -15
  76. package/src/eventDefinitions/EscalationEventDefinition.js +12 -14
  77. package/src/eventDefinitions/EventDefinitionExecution.js +10 -12
  78. package/src/eventDefinitions/LinkEventDefinition.js +14 -16
  79. package/src/eventDefinitions/MessageEventDefinition.js +13 -15
  80. package/src/eventDefinitions/SignalEventDefinition.js +13 -15
  81. package/src/eventDefinitions/TerminateEventDefinition.js +1 -1
  82. package/src/eventDefinitions/TimerEventDefinition.js +15 -17
  83. package/src/events/BoundaryEvent.js +34 -24
  84. package/src/events/EndEvent.js +3 -3
  85. package/src/events/IntermediateCatchEvent.js +3 -3
  86. package/src/events/IntermediateThrowEvent.js +3 -3
  87. package/src/events/StartEvent.js +8 -10
  88. package/src/flows/Association.js +14 -26
  89. package/src/flows/MessageFlow.js +14 -15
  90. package/src/flows/SequenceFlow.js +16 -20
  91. package/src/gateways/EventBasedGateway.js +3 -4
  92. package/src/gateways/ExclusiveGateway.js +2 -2
  93. package/src/gateways/InclusiveGateway.js +2 -2
  94. package/src/gateways/ParallelGateway.js +2 -2
  95. package/src/index.js +106 -0
  96. package/src/io/InputOutputSpecification.js +8 -10
  97. package/src/io/Properties.js +7 -9
  98. package/src/process/Process.js +45 -41
  99. package/src/process/ProcessExecution.js +167 -79
  100. package/src/tasks/CallActivity.js +7 -9
  101. package/src/tasks/LoopCharacteristics.js +2 -2
  102. package/src/tasks/ReceiveTask.js +215 -217
  103. package/src/tasks/ScriptTask.js +4 -4
  104. package/src/tasks/ServiceImplementation.js +1 -1
  105. package/src/tasks/ServiceTask.js +6 -8
  106. package/src/tasks/SignalTask.js +7 -9
  107. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  108. package/src/tasks/SubProcess.js +19 -20
  109. package/src/tasks/Task.js +2 -2
  110. package/src/tasks/Transaction.js +1 -1
  111. package/types/index.d.ts +520 -0
  112. package/dist/src/eventDefinitions/CancelEventDefinition.js +0 -184
  113. package/index.js +0 -106
  114. /package/dist/{src/ExtensionsMapper.js → ExtensionsMapper.js} +0 -0
  115. /package/dist/{src/Scripts.js → Scripts.js} +0 -0
  116. /package/dist/{src/Timers.js → Timers.js} +0 -0
  117. /package/dist/{src/activity → activity}/Escalation.js +0 -0
  118. /package/dist/{src/activity → activity}/Message.js +0 -0
  119. /package/dist/{src/activity → activity}/Signal.js +0 -0
  120. /package/dist/{src/error → error}/BpmnError.js +0 -0
  121. /package/dist/{src/getPropertyValue.js → getPropertyValue.js} +0 -0
  122. /package/dist/{src/io → io}/BpmnIO.js +0 -0
  123. /package/dist/{src/io → io}/EnvironmentDataObject.js +0 -0
  124. /package/dist/{src/io → io}/EnvironmentDataStore.js +0 -0
  125. /package/dist/{src/io → io}/EnvironmentDataStoreReference.js +0 -0
  126. /package/dist/{src/messageHelper.js → messageHelper.js} +0 -0
  127. /package/dist/{src/shared.js → shared.js} +0 -0
@@ -1,7 +1,7 @@
1
- import getPropertyValue from '../getPropertyValue';
2
- import {DefinitionApi} from '../Api';
3
- import {brokerSafeId} from '../shared';
4
- import {cloneContent, cloneMessage, pushParent, cloneParent} from '../messageHelper';
1
+ import getPropertyValue from '../getPropertyValue.js';
2
+ import {DefinitionApi} from '../Api.js';
3
+ import {brokerSafeId} from '../shared.js';
4
+ import {cloneContent, cloneMessage, pushParent, cloneParent} from '../messageHelper.js';
5
5
 
6
6
  const kActivated = Symbol.for('activated');
7
7
  const kProcessesQ = Symbol.for('processesQ');
@@ -61,49 +61,73 @@ export default function DefinitionExecution(definition, context) {
61
61
  };
62
62
  }
63
63
 
64
- const proto = DefinitionExecution.prototype;
65
-
66
- Object.defineProperty(proto, 'stopped', {
64
+ Object.defineProperty(DefinitionExecution.prototype, 'stopped', {
67
65
  enumerable: true,
68
66
  get() {
69
67
  return this[kStopped];
70
68
  },
71
69
  });
72
70
 
73
- Object.defineProperty(proto, 'completed', {
71
+ Object.defineProperty(DefinitionExecution.prototype, 'completed', {
74
72
  enumerable: true,
75
73
  get() {
76
74
  return this[kCompleted];
77
75
  },
78
76
  });
79
77
 
80
- Object.defineProperty(proto, 'status', {
78
+ Object.defineProperty(DefinitionExecution.prototype, 'status', {
81
79
  enumerable: true,
82
80
  get() {
83
81
  return this[kStatus];
84
82
  },
85
83
  });
86
84
 
87
- Object.defineProperty(proto, 'processes', {
85
+ Object.defineProperty(DefinitionExecution.prototype, 'processes', {
88
86
  enumerable: true,
89
87
  get() {
90
88
  return this[kProcesses].running;
91
89
  },
92
90
  });
93
91
 
94
- Object.defineProperty(proto, 'postponedCount', {
92
+ Object.defineProperty(DefinitionExecution.prototype, 'postponedCount', {
95
93
  get() {
96
94
  return this[kProcesses].postponed.length;
97
95
  },
98
96
  });
99
97
 
100
- Object.defineProperty(proto, 'isRunning', {
98
+ Object.defineProperty(DefinitionExecution.prototype, 'isRunning', {
101
99
  get() {
102
100
  return this[kActivated];
103
101
  },
104
102
  });
105
103
 
106
- proto.execute = function execute(executeMessage) {
104
+ Object.defineProperty(DefinitionExecution.prototype, 'activityStatus', {
105
+ get() {
106
+ let status = 'idle';
107
+ const running = this[kProcesses].running;
108
+ if (!running || !running.length) return status;
109
+
110
+ for (const bp of running) {
111
+ const bpStatus = bp.activityStatus;
112
+ switch (bp.activityStatus) {
113
+ case 'idle':
114
+ break;
115
+ case 'executing':
116
+ return bpStatus;
117
+ case 'timer':
118
+ status = bpStatus;
119
+ break;
120
+ case 'wait':
121
+ if (status === 'idle') status = bpStatus;
122
+ break;
123
+ }
124
+ }
125
+
126
+ return status;
127
+ },
128
+ });
129
+
130
+ DefinitionExecution.prototype.execute = function execute(executeMessage) {
107
131
  if (!executeMessage) throw new Error('Definition execution requires message');
108
132
  const content = executeMessage.content;
109
133
  const executionId = this.executionId = content.executionId;
@@ -139,7 +163,7 @@ proto.execute = function execute(executeMessage) {
139
163
  return true;
140
164
  };
141
165
 
142
- proto.resume = function resume() {
166
+ DefinitionExecution.prototype.resume = function resume() {
143
167
  this._debug(`resume ${this[kStatus]} definition execution`);
144
168
 
145
169
  if (this[kCompleted]) return this._complete('completed');
@@ -157,7 +181,7 @@ proto.resume = function resume() {
157
181
  for (const bp of running) bp.resume();
158
182
  };
159
183
 
160
- proto.recover = function recover(state) {
184
+ DefinitionExecution.prototype.recover = function recover(state) {
161
185
  if (!state) return this;
162
186
  this.executionId = state.executionId;
163
187
 
@@ -189,11 +213,11 @@ proto.recover = function recover(state) {
189
213
  return this;
190
214
  };
191
215
 
192
- proto.stop = function stop() {
216
+ DefinitionExecution.prototype.stop = function stop() {
193
217
  this.getApi().stop();
194
218
  };
195
219
 
196
- proto.getProcesses = function getProcesses() {
220
+ DefinitionExecution.prototype.getProcesses = function getProcesses() {
197
221
  const {running, processes} = this[kProcesses];
198
222
  const result = running.slice();
199
223
  for (const bp of processes) {
@@ -202,29 +226,29 @@ proto.getProcesses = function getProcesses() {
202
226
  return result;
203
227
  };
204
228
 
205
- proto.getProcessById = function getProcessById(processId) {
229
+ DefinitionExecution.prototype.getProcessById = function getProcessById(processId) {
206
230
  return this.getProcesses().find((bp) => bp.id === processId);
207
231
  };
208
232
 
209
- proto.getProcessesById = function getProcessesById(processId) {
233
+ DefinitionExecution.prototype.getProcessesById = function getProcessesById(processId) {
210
234
  return this.getProcesses().filter((bp) => bp.id === processId);
211
235
  };
212
236
 
213
- proto.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
237
+ DefinitionExecution.prototype.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
214
238
  const running = this[kProcesses].running;
215
239
  return running.find((bp) => bp.executionId === processExecutionId);
216
240
  };
217
241
 
218
- proto.getRunningProcesses = function getRunningProcesses() {
242
+ DefinitionExecution.prototype.getRunningProcesses = function getRunningProcesses() {
219
243
  const running = this[kProcesses].running;
220
244
  return running.filter((bp) => bp.executionId);
221
245
  };
222
246
 
223
- proto.getExecutableProcesses = function getExecutableProcesses() {
247
+ DefinitionExecution.prototype.getExecutableProcesses = function getExecutableProcesses() {
224
248
  return this[kProcesses].executable.slice();
225
249
  };
226
250
 
227
- proto.getState = function getState() {
251
+ DefinitionExecution.prototype.getState = function getState() {
228
252
  return {
229
253
  executionId: this.executionId,
230
254
  stopped: this[kStopped],
@@ -234,7 +258,7 @@ proto.getState = function getState() {
234
258
  };
235
259
  };
236
260
 
237
- proto.getApi = function getApi(apiMessage) {
261
+ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
238
262
  if (!apiMessage) apiMessage = this[kExecuteMessage] || {content: this._createMessage()};
239
263
 
240
264
  const content = apiMessage.content;
@@ -257,7 +281,7 @@ proto.getApi = function getApi(apiMessage) {
257
281
  return api;
258
282
  };
259
283
 
260
- proto.getPostponed = function getPostponed(...args) {
284
+ DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
261
285
  const running = this[kProcesses].running;
262
286
  return running.reduce((result, p) => {
263
287
  result = result.concat(p.getPostponed(...args));
@@ -265,7 +289,7 @@ proto.getPostponed = function getPostponed(...args) {
265
289
  }, []);
266
290
  };
267
291
 
268
- proto._start = function start() {
292
+ DefinitionExecution.prototype._start = function start() {
269
293
  const {ids, executable, postponed} = this[kProcesses];
270
294
  if (!ids.length) {
271
295
  return this._complete('completed');
@@ -287,7 +311,7 @@ proto._start = function start() {
287
311
  });
288
312
  };
289
313
 
290
- proto._activate = function activate(processList) {
314
+ DefinitionExecution.prototype._activate = function activate(processList) {
291
315
  this.broker.subscribeTmp('api', '#', this[kMessageHandlers].onApiMessage, {
292
316
  noAck: true,
293
317
  consumerTag: '_definition-api-consumer',
@@ -296,7 +320,7 @@ proto._activate = function activate(processList) {
296
320
  this[kActivated] = true;
297
321
  };
298
322
 
299
- proto._activateProcess = function activateProcess(bp) {
323
+ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
300
324
  const handlers = this[kMessageHandlers];
301
325
 
302
326
  bp.broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
@@ -330,7 +354,7 @@ proto._activateProcess = function activateProcess(bp) {
330
354
  });
331
355
  };
332
356
 
333
- proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
357
+ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey, originalMessage) {
334
358
  const message = cloneMessage(originalMessage);
335
359
  const content = message.content;
336
360
  const parent = content.parent = content.parent || {};
@@ -348,14 +372,14 @@ proto._onChildEvent = function onChildEvent(routingKey, originalMessage) {
348
372
  this[kProcessesQ].queueMessage(message.fields, cloneContent(content), message.properties);
349
373
  };
350
374
 
351
- proto._deactivate = function deactivate() {
375
+ DefinitionExecution.prototype._deactivate = function deactivate() {
352
376
  this.broker.cancel('_definition-api-consumer');
353
377
  this.broker.cancel(`_definition-activity-${this.executionId}`);
354
378
  for (const bp of this[kProcesses].running) this._deactivateProcess(bp);
355
379
  this[kActivated] = false;
356
380
  };
357
381
 
358
- proto._deactivateProcess = function deactivateProcess(bp) {
382
+ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp) {
359
383
  bp.broker.cancel('_definition-outbound-message-consumer');
360
384
  bp.broker.cancel('_definition-activity-consumer');
361
385
  bp.broker.cancel('_definition-signal-consumer');
@@ -364,7 +388,7 @@ proto._deactivateProcess = function deactivateProcess(bp) {
364
388
  bp.broker.cancel('_definition-call-cancel-consumer');
365
389
  };
366
390
 
367
- proto._onProcessMessage = function onProcessMessage(routingKey, message) {
391
+ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(routingKey, message) {
368
392
  const content = message.content;
369
393
  const isRedelivered = message.fields.redelivered;
370
394
  const {id: childId, inbound} = content;
@@ -429,7 +453,7 @@ proto._onProcessMessage = function onProcessMessage(routingKey, message) {
429
453
  }
430
454
  };
431
455
 
432
- proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
456
+ DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
433
457
  let previousMsg;
434
458
  const postponed = this[kProcesses].postponed;
435
459
  const idx = postponed.findIndex((msg) => msg.content.executionId === message.content.executionId);
@@ -441,7 +465,7 @@ proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage
441
465
  if (postponeMessage) postponed.push(message);
442
466
  };
443
467
 
444
- proto._onProcessCompleted = function onProcessCompleted(message) {
468
+ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(message) {
445
469
  this._stateChangeMessage(message, false);
446
470
  if (message.fields.redelivered) return message.ack();
447
471
 
@@ -459,7 +483,7 @@ proto._onProcessCompleted = function onProcessCompleted(message) {
459
483
  }
460
484
  };
461
485
 
462
- proto._onStopped = function onStopped(message) {
486
+ DefinitionExecution.prototype._onStopped = function onStopped(message) {
463
487
  const running = this[kProcesses].running;
464
488
  this._debug(`stop definition execution (stop process executions ${running.length})`);
465
489
  this[kProcessesQ].close();
@@ -472,7 +496,7 @@ proto._onStopped = function onStopped(message) {
472
496
  }), {type: 'stopped', persistent: false});
473
497
  };
474
498
 
475
- proto._onApiMessage = function onApiMessage(routingKey, message) {
499
+ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
476
500
  const messageType = message.properties.type;
477
501
  const delegate = message.properties.delegate;
478
502
 
@@ -494,7 +518,7 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
494
518
  }
495
519
  };
496
520
 
497
- proto._startProcessesByMessage = function startProcessesByMessage(reference) {
521
+ DefinitionExecution.prototype._startProcessesByMessage = function startProcessesByMessage(reference) {
498
522
  const {processes: bps, running} = this[kProcesses];
499
523
  if (bps.length < 2) return;
500
524
 
@@ -523,7 +547,7 @@ proto._startProcessesByMessage = function startProcessesByMessage(reference) {
523
547
  }
524
548
  };
525
549
 
526
- proto._onMessageOutbound = function onMessageOutbound(routingKey, message) {
550
+ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(routingKey, message) {
527
551
  const content = message.content;
528
552
  const {target, source} = content;
529
553
 
@@ -553,7 +577,7 @@ proto._onMessageOutbound = function onMessageOutbound(routingKey, message) {
553
577
  targetProcess.sendMessage(message);
554
578
  };
555
579
 
556
- proto._onCallActivity = function onCallActivity(routingKey, message) {
580
+ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingKey, message) {
557
581
  const content = message.content;
558
582
  const {calledElement, id: fromId, executionId: fromExecutionId, name: fromName, parent: fromParent} = content;
559
583
  if (!calledElement) return;
@@ -584,7 +608,7 @@ proto._onCallActivity = function onCallActivity(routingKey, message) {
584
608
  targetProcess.run({inbound: [cloneContent(content)]});
585
609
  };
586
610
 
587
- proto._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
611
+ DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
588
612
  const {calledElement, id: fromId, executionId: fromExecutionId, parent: fromParent} = message.content;
589
613
  if (!calledElement) return;
590
614
 
@@ -597,7 +621,7 @@ proto._onCancelCallActivity = function onCancelCallActivity(routingKey, message)
597
621
  targetProcess.getApi().discard();
598
622
  };
599
623
 
600
- proto._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
624
+ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
601
625
  const content = executeMessage.content;
602
626
  const messageType = executeMessage.properties.type;
603
627
  const delegateMessage = executeMessage.content.message;
@@ -623,14 +647,14 @@ proto._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage
623
647
  }), {type: messageType});
624
648
  };
625
649
 
626
- proto._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
650
+ DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
627
651
  const running = this[kProcesses].running;
628
652
  const idx = running.findIndex((p) => p.executionId === processExecutionId);
629
653
  if (idx === -1) return;
630
654
  return running.splice(idx, 1)[0];
631
655
  };
632
656
 
633
- proto._complete = function complete(completionType, content, options) {
657
+ DefinitionExecution.prototype._complete = function complete(completionType, content, options) {
634
658
  this._deactivate();
635
659
  const stateMessage = this[kExecuteMessage];
636
660
  this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
@@ -647,7 +671,7 @@ proto._complete = function complete(completionType, content, options) {
647
671
  }, {type: completionType, mandatory: completionType === 'error', ...options});
648
672
  };
649
673
 
650
- proto._createMessage = function createMessage(content = {}) {
674
+ DefinitionExecution.prototype._createMessage = function createMessage(content = {}) {
651
675
  return {
652
676
  id: this.id,
653
677
  type: this.type,
@@ -657,7 +681,7 @@ proto._createMessage = function createMessage(content = {}) {
657
681
  };
658
682
  };
659
683
 
660
- proto._getProcessApi = function getProcessApi(message) {
684
+ DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
661
685
  const content = message.content;
662
686
  let api = this._getProcessApiByExecutionId(content.executionId, message);
663
687
  if (api) return api;
@@ -675,12 +699,12 @@ proto._getProcessApi = function getProcessApi(message) {
675
699
  }
676
700
  };
677
701
 
678
- proto._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
702
+ DefinitionExecution.prototype._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
679
703
  const processInstance = this.getProcessByExecutionId(parentExecutionId);
680
704
  if (!processInstance) return;
681
705
  return processInstance.getApi(message);
682
706
  };
683
707
 
684
- proto._debug = function debug(logMessage) {
708
+ DefinitionExecution.prototype._debug = function debug(logMessage) {
685
709
  this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
686
710
  };
@@ -1,4 +1,4 @@
1
- import {cloneMessage} from '../messageHelper';
1
+ import {cloneMessage} from '../messageHelper.js';
2
2
 
3
3
  class ActivityError extends Error {
4
4
  constructor(description, sourceMessage, inner) {
@@ -1,7 +1,5 @@
1
- import {brokerSafeId} from '../shared';
2
- import {cloneContent, shiftParent} from '../messageHelper';
1
+ import {cloneContent, shiftParent} from '../messageHelper.js';
3
2
 
4
- const kMessageQ = Symbol.for('cancelQ');
5
3
  const kCompleted = Symbol.for('completed');
6
4
  const kExecuteMessage = Symbol.for('executeMessage');
7
5
 
@@ -11,35 +9,26 @@ export default function CancelEventDefinition(activity, eventDefinition) {
11
9
 
12
10
  this.id = id;
13
11
  this.type = type;
14
- const reference = this.reference = {referenceType: 'cancel'};
12
+ this.reference = {referenceType: 'cancel'};
15
13
  this.isThrowing = isThrowing;
16
14
  this.activity = activity;
17
15
  this.environment = environment;
18
16
  this.broker = broker;
19
17
  this.logger = environment.Logger(type.toLowerCase());
20
-
21
- if (!isThrowing) {
22
- this[kCompleted] = false;
23
- const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-q`;
24
- this[kMessageQ] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
25
- broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true, priority: 400});
26
- }
27
18
  }
28
19
 
29
- const proto = CancelEventDefinition.prototype;
30
-
31
- Object.defineProperty(proto, 'executionId', {
20
+ Object.defineProperty(CancelEventDefinition.prototype, 'executionId', {
32
21
  get() {
33
22
  const message = this[kExecuteMessage];
34
23
  return message && message.content.executionId;
35
24
  },
36
25
  });
37
26
 
38
- proto.execute = function execute(executeMessage) {
27
+ CancelEventDefinition.prototype.execute = function execute(executeMessage) {
39
28
  return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
40
29
  };
41
30
 
42
- proto.executeCatch = function executeCatch(executeMessage) {
31
+ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
43
32
  this[kExecuteMessage] = executeMessage;
44
33
  this[kCompleted] = false;
45
34
 
@@ -48,91 +37,60 @@ proto.executeCatch = function executeCatch(executeMessage) {
48
37
  const parentExecutionId = parent.executionId;
49
38
 
50
39
  const broker = this.broker;
51
- const onCatchMessage = this._onCatchMessage.bind(this);
52
- this[kMessageQ].consume(onCatchMessage, {
53
- noAck: true,
54
- consumerTag: `_oncancel-${executionId}`,
55
- });
56
40
 
57
- if (this[kCompleted]) return;
41
+ this._debug('expect cancel');
58
42
 
59
- const onApiMessage = this._onApiMessage.bind(this);
60
- broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
61
- noAck: true,
62
- consumerTag: `_api-parent-${executionId}`,
63
- });
64
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
43
+ broker.subscribeTmp('api', `activity.#.${parent.executionId}#`, this._onApiMessage.bind(this), {
65
44
  noAck: true,
66
45
  consumerTag: `_api-${executionId}`,
67
46
  });
68
47
 
69
- this._debug('expect cancel');
70
-
71
- const exchangeKey = `execute.canceled.${executionId}`;
72
- broker.subscribeOnce('execution', exchangeKey, onCatchMessage, {
48
+ const expectRoutingKey = `execute.cancelled.${executionId}`;
49
+ broker.subscribeOnce('execution', expectRoutingKey, this._onCatchMessage.bind(this), {
73
50
  consumerTag: `_onattached-cancel-${executionId}`,
74
51
  });
75
52
 
76
53
  broker.publish('execution', 'execute.expect', cloneContent(executeContent, {
77
- pattern: '#.cancel',
54
+ pattern: 'activity.execution.cancel',
78
55
  exchange: 'execution',
79
- exchangeKey,
56
+ expectRoutingKey,
80
57
  }));
58
+
59
+ const waitContent = cloneContent(executeContent, {
60
+ executionId: parentExecutionId,
61
+ condition: this.condition,
62
+ expect: 'cancel',
63
+ });
64
+ waitContent.parent = shiftParent(parent);
65
+
66
+ broker.publish('event', 'activity.wait', waitContent);
81
67
  };
82
68
 
83
- proto.executeThrow = function executeThrow(executeMessage) {
84
- const {isTransaction} = this.environment.variables.content || {};
69
+ CancelEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
85
70
  const executeContent = executeMessage.content;
86
71
  const {executionId, parent} = executeContent;
87
72
 
88
- this.logger.debug(`<${executionId} (${this.activity.id})> throw cancel${isTransaction ? ' transaction' : ''}`);
73
+ this.logger.debug(`<${executionId} (${this.activity.id})> throw cancel`);
89
74
 
90
75
  const broker = this.broker;
91
76
  const cancelContent = cloneContent(executeContent, {
92
- isTransaction,
93
77
  executionId: parent.executionId,
94
78
  state: 'throw',
95
79
  });
96
80
  cancelContent.parent = shiftParent(parent);
97
81
 
98
- broker.publish('event', 'activity.cancel', cancelContent, {type: 'cancel', delegate: isTransaction});
82
+ broker.publish('event', 'activity.cancel', cancelContent, { type: 'cancel' });
99
83
 
100
84
  return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
101
85
  };
102
86
 
103
- proto._onCatchMessage = function onCatchMessage(_, message) {
104
- if (message.content && message.content.isTransaction) return this._onCancelTransaction(_, message);
105
-
106
- this._debug(`cancel caught from <${message.content.id}>`);
107
- return this._complete(message.content.message);
108
- };
109
-
110
- proto._onCancelTransaction = function onCancelTransaction(_, message) {
111
- const broker = this.broker, executionId = this.executionId;
112
- const executeContent = this[kExecuteMessage].content;
113
- broker.cancel(`_oncancel-${executionId}`);
114
-
115
- this._debug(`cancel transaction thrown by <${message.content.id}>`);
116
-
117
- broker.assertExchange('cancel', 'topic');
118
- broker.publish('execution', 'execute.detach', cloneContent(executeContent, {
119
- pattern: '#',
120
- bindExchange: 'cancel',
121
- sourceExchange: 'event',
122
- sourcePattern: '#',
123
- }));
124
-
125
- broker.publish('event', 'activity.compensate', cloneContent(message.content, {
126
- state: 'throw',
127
- }), {type: 'compensate', delegate: true});
128
-
129
- broker.subscribeTmp('cancel', 'activity.leave', (__, {content: msg}) => {
130
- if (msg.id !== executeContent.attachedTo) return;
131
- return this._complete(message.content.message);
132
- }, {noAck: true, consumerTag: `_oncancelend-${executionId}`});
87
+ CancelEventDefinition.prototype._onCatchMessage = function onCatchMessage(_, message) {
88
+ const content = message.content;
89
+ this._debug(`cancel caught from <${content.id}>`);
90
+ return this._complete(content.message);
133
91
  };
134
92
 
135
- proto._complete = function complete(output) {
93
+ CancelEventDefinition.prototype._complete = function complete(output) {
136
94
  this[kCompleted] = true;
137
95
  this._stop();
138
96
  this._debug('completed');
@@ -143,7 +101,7 @@ proto._complete = function complete(output) {
143
101
  return this.broker.publish('execution', 'execute.completed', content);
144
102
  };
145
103
 
146
- proto._onApiMessage = function onApiMessage(routingKey, message) {
104
+ CancelEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
147
105
  switch (message.properties.type) {
148
106
  case 'discard': {
149
107
  this[kCompleted] = true;
@@ -158,16 +116,12 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
158
116
  }
159
117
  };
160
118
 
161
- proto._stop = function stop() {
119
+ CancelEventDefinition.prototype._stop = function stop() {
162
120
  const broker = this.broker, executionId = this.executionId;
163
- broker.cancel(`_api-parent-${executionId}`);
164
- broker.cancel(`_api-${executionId}`);
165
- broker.cancel(`_oncancel-${executionId}`);
166
- broker.cancel(`_oncancelend-${executionId}`);
167
121
  broker.cancel(`_onattached-cancel-${executionId}`);
168
- this[kMessageQ].purge();
122
+ broker.cancel(`_api-${executionId}`);
169
123
  };
170
124
 
171
- proto._debug = function debug(msg) {
125
+ CancelEventDefinition.prototype._debug = function debug(msg) {
172
126
  this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
173
127
  };