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,10 +1,10 @@
1
- import ActivityExecution from './ActivityExecution';
2
- import {brokerSafeId, getUniqueId} from '../shared';
3
- import {ActivityApi} from '../Api';
4
- import {ActivityBroker} from '../EventBroker';
5
- import {Formatter} from '../MessageFormatter';
6
- import {cloneContent, cloneParent, cloneMessage} from '../messageHelper';
7
- import {makeErrorFromMessage, ActivityError} from '../error/Errors';
1
+ import ActivityExecution from './ActivityExecution.js';
2
+ import {getUniqueId} from '../shared.js';
3
+ import {ActivityApi} from '../Api.js';
4
+ import {ActivityBroker} from '../EventBroker.js';
5
+ import {Formatter} from '../MessageFormatter.js';
6
+ import {cloneContent, cloneParent, cloneMessage} from '../messageHelper.js';
7
+ import {makeErrorFromMessage, ActivityError} from '../error/Errors.js';
8
8
 
9
9
  const kActivityDef = Symbol.for('activityDefinition');
10
10
  const kConsuming = Symbol.for('consuming');
@@ -18,6 +18,7 @@ const kFlows = Symbol.for('flows');
18
18
  const kFormatter = Symbol.for('formatter');
19
19
  const kMessageHandlers = Symbol.for('messageHandlers');
20
20
  const kStateMessage = Symbol.for('stateMessage');
21
+ const kActivated = Symbol.for('activated');
21
22
 
22
23
  export default Activity;
23
24
 
@@ -39,6 +40,7 @@ function Activity(Behaviour, activityDef, context) {
39
40
  taken: 0,
40
41
  discarded: 0,
41
42
  };
43
+ const isForCompensation = !!behaviour.isForCompensation;
42
44
 
43
45
  let attachedToActivity, attachedTo;
44
46
  if (attachedToRef) {
@@ -56,7 +58,14 @@ function Activity(Behaviour, activityDef, context) {
56
58
 
57
59
  const inboundSequenceFlows = context.getInboundSequenceFlows(id);
58
60
  const inboundAssociations = context.getInboundAssociations(id);
59
- const inboundTriggers = attachedToActivity ? [attachedToActivity] : inboundSequenceFlows.slice();
61
+ let inboundTriggers;
62
+ if (attachedToActivity) {
63
+ inboundTriggers = [attachedToActivity];
64
+ } else if (isForCompensation) {
65
+ inboundTriggers = inboundAssociations.slice();
66
+ } else {
67
+ inboundTriggers = inboundSequenceFlows.slice();
68
+ }
60
69
  const outboundSequenceFlows = context.getOutboundSequenceFlows(id);
61
70
  const flows = this[kFlows] = {
62
71
  inboundSequenceFlows,
@@ -67,7 +76,6 @@ function Activity(Behaviour, activityDef, context) {
67
76
  outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows),
68
77
  };
69
78
 
70
- const isForCompensation = !!behaviour.isForCompensation;
71
79
  const isParallelJoin = activityDef.isParallelGateway && flows.inboundSequenceFlows.length > 1;
72
80
  this[kFlags] = {
73
81
  isEnd: flows.outboundSequenceFlows.length === 0,
@@ -89,54 +97,39 @@ function Activity(Behaviour, activityDef, context) {
89
97
  onExecutionMessage: this._onExecutionMessage.bind(this),
90
98
  };
91
99
 
92
- const onInboundEvent = this._onInboundEvent.bind(this);
93
- broker.assertQueue('inbound-q', {durable: true, autoDelete: false});
94
- if (isForCompensation) {
95
- for (const trigger of inboundAssociations) {
96
- trigger.broker.subscribeTmp('event', '#', onInboundEvent, {noAck: true, consumerTag: `_inbound-${id}`});
97
- }
98
- } else {
99
- for (const trigger of inboundTriggers) {
100
- if (trigger.isSequenceFlow) trigger.broker.subscribeTmp('event', 'flow.#', onInboundEvent, {noAck: true, consumerTag: `_inbound-${id}`});
101
- else trigger.broker.subscribeTmp('event', 'activity.#', onInboundEvent, {noAck: true, consumerTag: `_inbound-${id}`});
102
- }
103
- }
104
-
105
100
  this[kEventDefinitions] = eventDefinitions && eventDefinitions.map((ed) => new ed.Behaviour(this, ed, this.context));
106
101
  this[kExtensions] = context.loadExtensions(this);
107
102
  }
108
103
 
109
- const proto = Activity.prototype;
110
-
111
- Object.defineProperty(proto, 'counters', {
104
+ Object.defineProperty(Activity.prototype, 'counters', {
112
105
  enumerable: true,
113
106
  get() {
114
107
  return {...this[kCounters]};
115
108
  },
116
109
  });
117
110
 
118
- Object.defineProperty(proto, 'execution', {
111
+ Object.defineProperty(Activity.prototype, 'execution', {
119
112
  enumerable: true,
120
113
  get() {
121
114
  return this[kExec].execution;
122
115
  },
123
116
  });
124
117
 
125
- Object.defineProperty(proto, 'executionId', {
118
+ Object.defineProperty(Activity.prototype, 'executionId', {
126
119
  enumerable: true,
127
120
  get() {
128
121
  return this[kExec].executionId;
129
122
  },
130
123
  });
131
124
 
132
- Object.defineProperty(proto, 'extensions', {
125
+ Object.defineProperty(Activity.prototype, 'extensions', {
133
126
  enumerable: true,
134
127
  get() {
135
128
  return this[kExtensions];
136
129
  },
137
130
  });
138
131
 
139
- Object.defineProperty(proto, 'bpmnIo', {
132
+ Object.defineProperty(Activity.prototype, 'bpmnIo', {
140
133
  enumerable: true,
141
134
  get() {
142
135
  const extensions = this[kExtensions];
@@ -144,7 +137,7 @@ Object.defineProperty(proto, 'bpmnIo', {
144
137
  },
145
138
  });
146
139
 
147
- Object.defineProperty(proto, 'formatter', {
140
+ Object.defineProperty(Activity.prototype, 'formatter', {
148
141
  enumerable: true,
149
142
  get() {
150
143
  let formatter = this[kFormatter];
@@ -160,7 +153,7 @@ Object.defineProperty(proto, 'formatter', {
160
153
  },
161
154
  });
162
155
 
163
- Object.defineProperty(proto, 'isRunning', {
156
+ Object.defineProperty(Activity.prototype, 'isRunning', {
164
157
  enumerable: true,
165
158
  get() {
166
159
  if (!this[kConsuming]) return false;
@@ -168,66 +161,72 @@ Object.defineProperty(proto, 'isRunning', {
168
161
  },
169
162
  });
170
163
 
171
- Object.defineProperty(proto, 'outbound', {
164
+ Object.defineProperty(Activity.prototype, 'outbound', {
172
165
  enumerable: true,
173
166
  get() {
174
167
  return this[kFlows].outboundSequenceFlows;
175
168
  },
176
169
  });
177
170
 
178
- Object.defineProperty(proto, 'inbound', {
171
+ Object.defineProperty(Activity.prototype, 'inbound', {
179
172
  enumerable: true,
180
173
  get() {
181
174
  return this[kFlows].inboundSequenceFlows;
182
175
  },
183
176
  });
184
177
 
185
- Object.defineProperty(proto, 'isEnd', {
178
+ Object.defineProperty(Activity.prototype, 'isEnd', {
186
179
  enumerable: true,
187
180
  get() {
188
181
  return this[kFlags].isEnd;
189
182
  },
190
183
  });
191
- Object.defineProperty(proto, 'isStart', {
184
+ Object.defineProperty(Activity.prototype, 'isStart', {
192
185
  enumerable: true,
193
186
  get() {
194
187
  return this[kFlags].isStart;
195
188
  },
196
189
  });
197
- Object.defineProperty(proto, 'isSubProcess', {
190
+ Object.defineProperty(Activity.prototype, 'isSubProcess', {
198
191
  enumerable: true,
199
192
  get() {
200
193
  return this[kFlags].isSubProcess;
201
194
  },
202
195
  });
196
+ Object.defineProperty(Activity.prototype, 'isTransaction', {
197
+ enumerable: true,
198
+ get() {
199
+ return this[kFlags].isTransaction;
200
+ },
201
+ });
203
202
 
204
- Object.defineProperty(proto, 'isMultiInstance', {
203
+ Object.defineProperty(Activity.prototype, 'isMultiInstance', {
205
204
  enumerable: true,
206
205
  get() {
207
206
  return this[kFlags].isMultiInstance;
208
207
  },
209
208
  });
210
209
 
211
- Object.defineProperty(proto, 'isThrowing', {
210
+ Object.defineProperty(Activity.prototype, 'isThrowing', {
212
211
  enumerable: true,
213
212
  get() {
214
213
  return this[kFlags].isThrowing;
215
214
  },
216
215
  });
217
- Object.defineProperty(proto, 'isForCompensation', {
216
+ Object.defineProperty(Activity.prototype, 'isForCompensation', {
218
217
  enumerable: true,
219
218
  get() {
220
219
  return this[kFlags].isForCompensation;
221
220
  },
222
221
  });
223
- Object.defineProperty(proto, 'triggeredByEvent', {
222
+ Object.defineProperty(Activity.prototype, 'triggeredByEvent', {
224
223
  enumerable: true,
225
224
  get() {
226
225
  return this[kActivityDef].triggeredByEvent;
227
226
  },
228
227
  });
229
228
 
230
- Object.defineProperty(proto, 'attachedTo', {
229
+ Object.defineProperty(Activity.prototype, 'attachedTo', {
231
230
  enumerable: true,
232
231
  get() {
233
232
  const attachedToId = this[kFlags].attachedTo;
@@ -236,25 +235,28 @@ Object.defineProperty(proto, 'attachedTo', {
236
235
  },
237
236
  });
238
237
 
239
- Object.defineProperty(proto, 'eventDefinitions', {
238
+ Object.defineProperty(Activity.prototype, 'eventDefinitions', {
240
239
  enumerable: true,
241
240
  get() {
242
241
  return this[kEventDefinitions];
243
242
  },
244
243
  });
245
244
 
246
- proto.activate = function activate() {
247
- if (this[kFlags].isForCompensation) return;
245
+ Activity.prototype.activate = function activate() {
246
+ this[kActivated] = true;
247
+ this.addInboundListeners();
248
248
  return this._consumeInbound();
249
249
  };
250
250
 
251
- proto.deactivate = function deactivate() {
251
+ Activity.prototype.deactivate = function deactivate() {
252
+ this[kActivated] = false;
252
253
  const broker = this.broker;
254
+ this.removeInboundListeners();
253
255
  broker.cancel('_run-on-inbound');
254
256
  broker.cancel('_format-consumer');
255
257
  };
256
258
 
257
- proto.init = function init(initContent) {
259
+ Activity.prototype.init = function init(initContent) {
258
260
  const id = this.id;
259
261
  const exec = this[kExec];
260
262
  const executionId = exec.initExecutionId = exec.initExecutionId || getUniqueId(id);
@@ -262,7 +264,7 @@ proto.init = function init(initContent) {
262
264
  this._publishEvent('init', this._createMessage({...initContent, executionId}));
263
265
  };
264
266
 
265
- proto.run = function run(runContent) {
267
+ Activity.prototype.run = function run(runContent) {
266
268
  const id = this.id;
267
269
  if (this.isRunning) throw new Error(`activity <${id}> is already running`);
268
270
 
@@ -281,7 +283,7 @@ proto.run = function run(runContent) {
281
283
  this._consumeRunQ();
282
284
  };
283
285
 
284
- proto.recover = function recover(state) {
286
+ Activity.prototype.recover = function recover(state) {
285
287
  if (this.isRunning) throw new Error(`cannot recover running activity <${this.id}>`);
286
288
  if (!state) return;
287
289
 
@@ -301,7 +303,7 @@ proto.recover = function recover(state) {
301
303
  return this;
302
304
  };
303
305
 
304
- proto.resume = function resume() {
306
+ Activity.prototype.resume = function resume() {
305
307
  if (this[kConsuming]) {
306
308
  throw new Error(`cannot resume running activity <${this.id}>`);
307
309
  }
@@ -316,7 +318,7 @@ proto.resume = function resume() {
316
318
  this._consumeRunQ();
317
319
  };
318
320
 
319
- proto.discard = function discard(discardContent) {
321
+ Activity.prototype.discard = function discard(discardContent) {
320
322
  if (!this.status) return this._runDiscard(discardContent);
321
323
  const execution = this[kExec].execution;
322
324
  if (execution && !execution.completed) return execution.discard();
@@ -328,12 +330,29 @@ proto.discard = function discard(discardContent) {
328
330
  this._consumeRunQ();
329
331
  };
330
332
 
331
- proto.stop = function stop() {
332
- if (!this[kConsuming]) return;
333
- return this.getApi().stop();
333
+ Activity.prototype.addInboundListeners = function addInboundListeners() {
334
+ const onInboundEvent = this._onInboundEvent.bind(this);
335
+ const triggerConsumerTag = `_inbound-${this.id}`;
336
+ for (const trigger of this[kFlows].inboundTriggers) {
337
+ if (trigger.isSequenceFlow) trigger.broker.subscribeTmp('event', 'flow.#', onInboundEvent, {noAck: true, consumerTag: triggerConsumerTag});
338
+ else if (this.isForCompensation) trigger.broker.subscribeTmp('event', 'association.#', onInboundEvent, {noAck: true, consumerTag: triggerConsumerTag});
339
+ else trigger.broker.subscribeTmp('event', 'activity.#', onInboundEvent, {noAck: true, consumerTag: triggerConsumerTag});
340
+ }
334
341
  };
335
342
 
336
- proto.next = function next() {
343
+ Activity.prototype.removeInboundListeners = function removeInboundListeners() {
344
+ const triggerConsumerTag = `_inbound-${this.id}`;
345
+ for (const trigger of this[kFlows].inboundTriggers) {
346
+ trigger.broker.cancel(triggerConsumerTag);
347
+ }
348
+ };
349
+
350
+ Activity.prototype.stop = function stop() {
351
+ if (!this[kConsuming]) return this.broker.cancel('_run-on-inbound');
352
+ return this.getApi(this[kStateMessage]).stop();
353
+ };
354
+
355
+ Activity.prototype.next = function next() {
337
356
  if (!this.environment.settings.step) return;
338
357
  const stateMessage = this[kStateMessage];
339
358
  if (!stateMessage) return;
@@ -344,15 +363,15 @@ proto.next = function next() {
344
363
  return current;
345
364
  };
346
365
 
347
- proto.shake = function shake() {
366
+ Activity.prototype.shake = function shake() {
348
367
  this._shakeOutbound({content: this._createMessage()});
349
368
  };
350
369
 
351
- proto.evaluateOutbound = function evaluateOutbound(fromMessage, discardRestAtTake, callback) {
370
+ Activity.prototype.evaluateOutbound = function evaluateOutbound(fromMessage, discardRestAtTake, callback) {
352
371
  return this[kFlows].outboundEvaluator.evaluate(fromMessage, discardRestAtTake, callback);
353
372
  };
354
373
 
355
- proto.getState = function getState() {
374
+ Activity.prototype.getState = function getState() {
356
375
  const msg = this._createMessage();
357
376
 
358
377
  const exec = this[kExec];
@@ -367,17 +386,17 @@ proto.getState = function getState() {
367
386
  };
368
387
  };
369
388
 
370
- proto.getApi = function getApi(message) {
389
+ Activity.prototype.getApi = function getApi(message) {
371
390
  const execution = this[kExec].execution;
372
391
  if (execution && !execution.completed) return execution.getApi(message);
373
392
  return ActivityApi(this.broker, message || this[kStateMessage]);
374
393
  };
375
394
 
376
- proto.getActivityById = function getActivityById(elementId) {
395
+ Activity.prototype.getActivityById = function getActivityById(elementId) {
377
396
  return this.context.getActivityById(elementId);
378
397
  };
379
398
 
380
- proto._runDiscard = function runDiscard(discardContent) {
399
+ Activity.prototype._runDiscard = function runDiscard(discardContent) {
381
400
  const exec = this[kExec];
382
401
  const executionId = exec.executionId = exec.initExecutionId || getUniqueId(this.id);
383
402
  exec.initExecutionId = null;
@@ -390,12 +409,13 @@ proto._runDiscard = function runDiscard(discardContent) {
390
409
  this._consumeRunQ();
391
410
  };
392
411
 
393
- proto._discardRun = function discardRun() {
412
+ Activity.prototype._discardRun = function discardRun() {
394
413
  const status = this.status;
395
414
  if (!status) return;
396
415
 
397
416
  const execution = this[kExec].execution;
398
417
  if (execution && !execution.completed) return;
418
+
399
419
  switch (status) {
400
420
  case 'executing':
401
421
  case 'error':
@@ -413,7 +433,7 @@ proto._discardRun = function discardRun() {
413
433
  this._consumeRunQ();
414
434
  };
415
435
 
416
- proto._shakeOutbound = function shakeOutbound(sourceMessage) {
436
+ Activity.prototype._shakeOutbound = function shakeOutbound(sourceMessage) {
417
437
  const message = cloneMessage(sourceMessage);
418
438
  message.content.sequence = message.content.sequence || [];
419
439
  message.content.sequence.push({id: this.id, type: this.type});
@@ -428,7 +448,9 @@ proto._shakeOutbound = function shakeOutbound(sourceMessage) {
428
448
  for (const flow of this[kFlows].outboundSequenceFlows) flow.shake(message);
429
449
  };
430
450
 
431
- proto._consumeInbound = function consumeInbound() {
451
+ Activity.prototype._consumeInbound = function consumeInbound() {
452
+ if (!this[kActivated]) return;
453
+
432
454
  if (this.status) return;
433
455
  const inboundQ = this.broker.getQueue('inbound-q');
434
456
  if (this[kFlags].isParallelJoin) {
@@ -438,9 +460,8 @@ proto._consumeInbound = function consumeInbound() {
438
460
  return inboundQ.consume(this[kMessageHandlers].onInbound, {consumerTag: '_run-on-inbound'});
439
461
  };
440
462
 
441
- proto._onInbound = function onInbound(routingKey, message) {
463
+ Activity.prototype._onInbound = function onInbound(routingKey, message) {
442
464
  message.ack();
443
- const id = this.id;
444
465
  const broker = this.broker;
445
466
  broker.cancel('_run-on-inbound');
446
467
 
@@ -462,20 +483,10 @@ proto._onInbound = function onInbound(routingKey, message) {
462
483
  if (content.discardSequence) discardSequence = content.discardSequence.slice();
463
484
  return this._runDiscard({inbound, discardSequence});
464
485
  }
465
- case 'association.complete': {
466
- broker.cancel('_run-on-inbound');
467
-
468
- const compensationId = `${brokerSafeId(id)}_${brokerSafeId(content.sequenceId)}`;
469
- this.logger.debug(`<${id}> completed compensation with id <${compensationId}>`);
470
-
471
- return this._publishEvent('compensation.end', this._createMessage({
472
- executionId: compensationId,
473
- }));
474
- }
475
486
  }
476
487
  };
477
488
 
478
- proto._onJoinInbound = function onJoinInbound(routingKey, message) {
489
+ Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message) {
479
490
  const {content} = message;
480
491
  const {inboundSequenceFlows, inboundJoinFlows, inboundTriggers} = this[kFlows];
481
492
  const idx = inboundJoinFlows.findIndex((msg) => msg.content.id === content.id);
@@ -516,9 +527,8 @@ proto._onJoinInbound = function onJoinInbound(routingKey, message) {
516
527
  return this.run({inbound});
517
528
  };
518
529
 
519
- proto._onInboundEvent = function onInboundEvent(routingKey, message) {
530
+ Activity.prototype._onInboundEvent = function onInboundEvent(routingKey, message) {
520
531
  const {fields, content, properties} = message;
521
- const id = this.id;
522
532
  const inboundQ = this.broker.getQueue('inbound-q');
523
533
 
524
534
  switch (routingKey) {
@@ -536,36 +546,17 @@ proto._onInboundEvent = function onInboundEvent(routingKey, message) {
536
546
  case 'flow.take':
537
547
  case 'flow.discard':
538
548
  return inboundQ.queueMessage(fields, cloneContent(content), properties);
539
- case 'association.discard': {
540
- this.logger.debug(`<${id}> compensation discarded`);
541
- return inboundQ.purge();
542
- }
543
- case 'association.complete': {
544
- if (!this[kFlags].isForCompensation) break;
545
-
546
- inboundQ.queueMessage(fields, cloneContent(content), properties);
547
-
548
- const compensationId = `${brokerSafeId(id)}_${brokerSafeId(content.sequenceId)}`;
549
- this._publishEvent('compensation.start', this._createMessage({
550
- executionId: compensationId,
551
- placeholder: true,
552
- }));
553
-
554
- this.logger.debug(`<${id}> start compensation with id <${compensationId}>`);
555
-
556
- return this._consumeInbound();
557
- }
558
549
  }
559
550
  };
560
551
 
561
- proto._consumeRunQ = function consumeRunQ() {
552
+ Activity.prototype._consumeRunQ = function consumeRunQ() {
562
553
  if (this[kConsuming]) return;
563
554
 
564
555
  this[kConsuming] = true;
565
556
  this.broker.getQueue('run-q').assertConsumer(this[kMessageHandlers].onRunMessage, {exclusive: true, consumerTag: '_activity-run'});
566
557
  };
567
558
 
568
- proto._onRunMessage = function onRunMessage(routingKey, message, messageProperties) {
559
+ Activity.prototype._onRunMessage = function onRunMessage(routingKey, message, messageProperties) {
569
560
  switch (routingKey) {
570
561
  case 'run.outbound.discard':
571
562
  case 'run.outbound.take':
@@ -586,7 +577,7 @@ proto._onRunMessage = function onRunMessage(routingKey, message, messageProperti
586
577
  });
587
578
  };
588
579
 
589
- proto._continueRunMessage = function continueRunMessage(routingKey, message) {
580
+ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey, message) {
590
581
  const isRedelivered = message.fields.redelivered;
591
582
  const content = cloneContent(message.content);
592
583
  const correlationId = message.properties.correlationId;
@@ -633,6 +624,7 @@ proto._continueRunMessage = function continueRunMessage(routingKey, message) {
633
624
  case 'run.execute.passthrough': {
634
625
  const execution = this.execution;
635
626
  if (!isRedelivered && execution) {
627
+ if (execution.completed) return message.ack();
636
628
  this[kExecuteMessage] = message;
637
629
  return execution.passthrough(message);
638
630
  }
@@ -712,7 +704,7 @@ proto._continueRunMessage = function continueRunMessage(routingKey, message) {
712
704
  if (!step) message.ack();
713
705
  };
714
706
 
715
- proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
707
+ Activity.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
716
708
  const executeMessage = this[kExecuteMessage];
717
709
  const content = cloneContent({
718
710
  ...executeMessage.content,
@@ -741,6 +733,7 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
741
733
  broker.publish('run', 'run.discarded', content, {correlationId});
742
734
  break;
743
735
  }
736
+ case 'execution.cancel':
744
737
  case 'execution.discard':
745
738
  this.status = 'discarded';
746
739
  broker.publish('run', 'run.discarded', content, {correlationId});
@@ -755,14 +748,13 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
755
748
  this._ackRunExecuteMessage();
756
749
  };
757
750
 
758
- proto._ackRunExecuteMessage = function ackRunExecuteMessage() {
751
+ Activity.prototype._ackRunExecuteMessage = function ackRunExecuteMessage() {
759
752
  if (this.environment.settings.step) return;
760
753
  const executeMessage = this[kExecuteMessage];
761
- this[kExecuteMessage] = null;
762
754
  executeMessage.ack();
763
755
  };
764
756
 
765
- proto._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
757
+ Activity.prototype._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
766
758
  const {content, properties} = message;
767
759
  const correlationId = properties.correlationId;
768
760
  if (content.ignoreOutbound) {
@@ -783,7 +775,7 @@ proto._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
783
775
  });
784
776
  };
785
777
 
786
- proto._doOutbound = function doOutbound(fromMessage, isDiscarded, callback) {
778
+ Activity.prototype._doOutbound = function doOutbound(fromMessage, isDiscarded, callback) {
787
779
  const outboundSequenceFlows = this[kFlows].outboundSequenceFlows;
788
780
  if (!outboundSequenceFlows.length) return callback(null, []);
789
781
 
@@ -813,7 +805,7 @@ proto._doOutbound = function doOutbound(fromMessage, isDiscarded, callback) {
813
805
  });
814
806
  };
815
807
 
816
- proto._doRunOutbound = function doRunOutbound(outboundList, content, discardSequence) {
808
+ Activity.prototype._doRunOutbound = function doRunOutbound(outboundList, content, discardSequence) {
817
809
  for (const outboundFlow of outboundList) {
818
810
  const {id: flowId, action} = outboundFlow;
819
811
  this.broker.publish('run', 'run.outbound.' + action, cloneContent(content, {
@@ -827,7 +819,7 @@ proto._doRunOutbound = function doRunOutbound(outboundList, content, discardSequ
827
819
  return outboundList;
828
820
  };
829
821
 
830
- proto._onResumeMessage = function onResumeMessage(message) {
822
+ Activity.prototype._onResumeMessage = function onResumeMessage(message) {
831
823
  message.ack();
832
824
 
833
825
  const stateMessage = this[kStateMessage];
@@ -852,7 +844,7 @@ proto._onResumeMessage = function onResumeMessage(message) {
852
844
  return this.broker.publish('run', fields.routingKey, cloneContent(stateMessage.content), stateMessage.properties);
853
845
  };
854
846
 
855
- proto._publishEvent = function publishEvent(state, content, properties = {}) {
847
+ Activity.prototype._publishEvent = function publishEvent(state, content, properties = {}) {
856
848
  this.broker.publish('event', `activity.${state}`, cloneContent(content, {state}), {
857
849
  ...properties,
858
850
  type: state,
@@ -861,7 +853,7 @@ proto._publishEvent = function publishEvent(state, content, properties = {}) {
861
853
  });
862
854
  };
863
855
 
864
- proto._onStop = function onStop(message) {
856
+ Activity.prototype._onStop = function onStop(message) {
865
857
  const running = this[kConsuming];
866
858
 
867
859
  this.stopped = true;
@@ -880,7 +872,7 @@ proto._onStop = function onStop(message) {
880
872
  }
881
873
  };
882
874
 
883
- proto._consumeApi = function consumeApi() {
875
+ Activity.prototype._consumeApi = function consumeApi() {
884
876
  const executionId = this[kExec].executionId;
885
877
  if (!executionId) return;
886
878
  const broker = this.broker;
@@ -888,7 +880,7 @@ proto._consumeApi = function consumeApi() {
888
880
  broker.subscribeTmp('api', `activity.*.${executionId}`, this[kMessageHandlers].onApiMessage, {noAck: true, consumerTag: '_activity-api', priority: 100});
889
881
  };
890
882
 
891
- proto._onApiMessage = function onApiMessage(routingKey, message) {
883
+ Activity.prototype._onApiMessage = function onApiMessage(routingKey, message) {
892
884
  switch (message.properties.type) {
893
885
  case 'discard': {
894
886
  return this._discardRun(message);
@@ -902,7 +894,7 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
902
894
  }
903
895
  };
904
896
 
905
- proto._createMessage = function createMessage(override) {
897
+ Activity.prototype._createMessage = function createMessage(override) {
906
898
  const name = this.name, status = this.status, parent = this.parent;
907
899
  const result = {
908
900
  ...override,
@@ -920,11 +912,11 @@ proto._createMessage = function createMessage(override) {
920
912
  return result;
921
913
  };
922
914
 
923
- proto._getOutboundSequenceFlowById = function getOutboundSequenceFlowById(flowId) {
915
+ Activity.prototype._getOutboundSequenceFlowById = function getOutboundSequenceFlowById(flowId) {
924
916
  return this[kFlows].outboundSequenceFlows.find((flow) => flow.id === flowId);
925
917
  };
926
918
 
927
- proto._deactivateRunConsumers = function _deactivateRunConsumers() {
919
+ Activity.prototype._deactivateRunConsumers = function _deactivateRunConsumers() {
928
920
  const broker = this.broker;
929
921
  broker.cancel('_activity-api');
930
922
  broker.cancel('_activity-run');