bpmn-elements 17.2.2 → 18.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 (155) hide show
  1. package/README.md +3 -1
  2. package/dist/Api.js +83 -0
  3. package/dist/Context.js +228 -22
  4. package/dist/Environment.js +111 -31
  5. package/dist/EventBroker.js +57 -1
  6. package/dist/Expressions.js +3 -4
  7. package/dist/MessageFormatter.js +29 -16
  8. package/dist/Timers.js +13 -9
  9. package/dist/Tracker.js +1 -0
  10. package/dist/activity/Activity.js +458 -254
  11. package/dist/activity/ActivityExecution.js +113 -40
  12. package/dist/activity/Dummy.js +6 -1
  13. package/dist/activity/Escalation.js +36 -24
  14. package/dist/activity/ExecutionScope.js +1 -1
  15. package/dist/activity/Message.js +36 -24
  16. package/dist/activity/Signal.js +36 -24
  17. package/dist/activity/outbound-evaluator.js +1 -1
  18. package/dist/condition.js +12 -6
  19. package/dist/constants.js +21 -0
  20. package/dist/definition/Definition.js +182 -64
  21. package/dist/definition/DefinitionExecution.js +195 -82
  22. package/dist/error/BpmnError.js +12 -1
  23. package/dist/error/Errors.js +50 -9
  24. package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
  25. package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
  26. package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
  27. package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
  28. package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
  29. package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
  30. package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
  31. package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
  32. package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
  33. package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
  34. package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
  35. package/dist/eventDefinitions/index.js +20 -21
  36. package/dist/events/BoundaryEvent.js +52 -40
  37. package/dist/events/EndEvent.js +22 -8
  38. package/dist/events/IntermediateCatchEvent.js +26 -8
  39. package/dist/events/IntermediateThrowEvent.js +24 -9
  40. package/dist/events/StartEvent.js +30 -14
  41. package/dist/events/index.js +10 -11
  42. package/dist/flows/Association.js +50 -7
  43. package/dist/flows/MessageFlow.js +49 -10
  44. package/dist/flows/SequenceFlow.js +93 -22
  45. package/dist/flows/index.js +6 -7
  46. package/dist/gateways/EventBasedGateway.js +29 -15
  47. package/dist/gateways/ExclusiveGateway.js +20 -5
  48. package/dist/gateways/InclusiveGateway.js +21 -5
  49. package/dist/gateways/ParallelGateway.js +253 -15
  50. package/dist/gateways/index.js +8 -9
  51. package/dist/getPropertyValue.js +2 -2
  52. package/dist/index.js +42 -43
  53. package/dist/io/BpmnIO.js +15 -1
  54. package/dist/io/EnvironmentDataObject.js +29 -1
  55. package/dist/io/EnvironmentDataStore.js +24 -1
  56. package/dist/io/EnvironmentDataStoreReference.js +24 -1
  57. package/dist/io/InputOutputSpecification.js +21 -11
  58. package/dist/io/Properties.js +28 -17
  59. package/dist/messageHelper.js +41 -4
  60. package/dist/process/Lane.js +15 -4
  61. package/dist/process/Process.js +174 -76
  62. package/dist/process/ProcessExecution.js +362 -177
  63. package/dist/shared.js +2 -0
  64. package/dist/tasks/CallActivity.js +19 -4
  65. package/dist/tasks/LoopCharacteristics.js +94 -9
  66. package/dist/tasks/ReceiveTask.js +36 -21
  67. package/dist/tasks/ScriptTask.js +22 -6
  68. package/dist/tasks/ServiceImplementation.js +7 -4
  69. package/dist/tasks/ServiceTask.js +19 -4
  70. package/dist/tasks/SignalTask.js +19 -4
  71. package/dist/tasks/StandardLoopCharacteristics.js +8 -4
  72. package/dist/tasks/SubProcess.js +44 -29
  73. package/dist/tasks/Task.js +19 -4
  74. package/dist/tasks/Transaction.js +8 -4
  75. package/dist/tasks/index.js +16 -18
  76. package/package.json +31 -13
  77. package/src/Api.js +70 -0
  78. package/src/Context.js +200 -19
  79. package/src/Environment.js +99 -30
  80. package/src/EventBroker.js +46 -1
  81. package/src/Expressions.js +2 -3
  82. package/src/MessageFormatter.js +24 -16
  83. package/src/Timers.js +12 -9
  84. package/src/Tracker.js +1 -0
  85. package/src/activity/Activity.js +388 -231
  86. package/src/activity/ActivityExecution.js +93 -42
  87. package/src/activity/Dummy.js +6 -1
  88. package/src/activity/Escalation.js +25 -18
  89. package/src/activity/ExecutionScope.js +1 -1
  90. package/src/activity/Message.js +25 -18
  91. package/src/activity/Signal.js +25 -18
  92. package/src/activity/outbound-evaluator.js +1 -1
  93. package/src/condition.js +11 -5
  94. package/src/constants.js +15 -0
  95. package/src/definition/Definition.js +157 -62
  96. package/src/definition/DefinitionExecution.js +161 -83
  97. package/src/error/BpmnError.js +11 -1
  98. package/src/error/Errors.js +44 -5
  99. package/src/eventDefinitions/CancelEventDefinition.js +27 -13
  100. package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
  101. package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
  102. package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
  103. package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
  104. package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
  105. package/src/eventDefinitions/LinkEventDefinition.js +34 -120
  106. package/src/eventDefinitions/MessageEventDefinition.js +42 -31
  107. package/src/eventDefinitions/SignalEventDefinition.js +43 -32
  108. package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
  109. package/src/eventDefinitions/TimerEventDefinition.js +53 -35
  110. package/src/eventDefinitions/index.js +10 -23
  111. package/src/events/BoundaryEvent.js +50 -39
  112. package/src/events/EndEvent.js +19 -7
  113. package/src/events/IntermediateCatchEvent.js +24 -8
  114. package/src/events/IntermediateThrowEvent.js +24 -8
  115. package/src/events/StartEvent.js +25 -14
  116. package/src/events/index.js +5 -18
  117. package/src/flows/Association.js +43 -9
  118. package/src/flows/MessageFlow.js +41 -10
  119. package/src/flows/SequenceFlow.js +82 -19
  120. package/src/flows/index.js +3 -4
  121. package/src/gateways/EventBasedGateway.js +27 -15
  122. package/src/gateways/ExclusiveGateway.js +16 -3
  123. package/src/gateways/InclusiveGateway.js +16 -3
  124. package/src/gateways/ParallelGateway.js +301 -10
  125. package/src/gateways/index.js +4 -4
  126. package/src/getPropertyValue.js +2 -2
  127. package/src/index.js +19 -19
  128. package/src/io/BpmnIO.js +13 -1
  129. package/src/io/EnvironmentDataObject.js +26 -1
  130. package/src/io/EnvironmentDataStore.js +22 -1
  131. package/src/io/EnvironmentDataStoreReference.js +22 -1
  132. package/src/io/InputOutputSpecification.js +17 -8
  133. package/src/io/Properties.js +23 -13
  134. package/src/messageHelper.js +36 -4
  135. package/src/process/Lane.js +14 -4
  136. package/src/process/Process.js +154 -72
  137. package/src/process/ProcessExecution.js +326 -175
  138. package/src/shared.js +1 -0
  139. package/src/tasks/CallActivity.js +16 -2
  140. package/src/tasks/LoopCharacteristics.js +77 -11
  141. package/src/tasks/ReceiveTask.js +33 -22
  142. package/src/tasks/ScriptTask.js +17 -3
  143. package/src/tasks/ServiceImplementation.js +6 -3
  144. package/src/tasks/ServiceTask.js +16 -2
  145. package/src/tasks/SignalTask.js +16 -2
  146. package/src/tasks/StandardLoopCharacteristics.js +7 -3
  147. package/src/tasks/SubProcess.js +37 -23
  148. package/src/tasks/Task.js +16 -2
  149. package/src/tasks/Transaction.js +7 -3
  150. package/src/tasks/index.js +8 -9
  151. package/types/bundle-errors.d.ts +1 -0
  152. package/types/bundle.d.ts +97 -0
  153. package/types/index.d.ts +2614 -84
  154. package/types/interfaces.d.ts +636 -0
  155. package/types/types.d.ts +0 -765
@@ -3,22 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.ProcessExecution = ProcessExecution;
7
7
  var _Api = require("../Api.js");
8
8
  var _messageHelper = require("../messageHelper.js");
9
9
  var _shared = require("../shared.js");
10
10
  var _Tracker = require("../Tracker.js");
11
- var _default = exports.default = ProcessExecution;
12
- const kActivated = Symbol.for('activated');
13
- const kActivityQ = Symbol.for('activityQ');
14
- const kCompleted = Symbol.for('completed');
15
- const kElements = Symbol.for('elements');
16
- const kExecuteMessage = Symbol.for('executeMessage');
17
- const kMessageHandlers = Symbol.for('messageHandlers');
18
- const kParent = Symbol.for('parent');
19
- const kStatus = Symbol.for('status');
20
- const kStopped = Symbol.for('stopped');
21
- const kTracker = Symbol.for('activity tracker');
11
+ var _constants = require("../constants.js");
12
+ const K_ACTIVITY_Q = Symbol.for('activityQ');
13
+ const K_ELEMENTS = Symbol.for('elements');
14
+ const K_PARENT = Symbol.for('parent');
15
+ const K_TRACKER = Symbol.for('activity tracker');
16
+ const K_PEERS_DISCOVERED = Symbol.for('peers discovered');
17
+
18
+ /**
19
+ * Drives the execution of a single process or sub-process: activates children, routes activity
20
+ * events, and rolls completion up to the owning Process or sub-process Activity.
21
+ * @param {import('#types').Process | import('#types').Activity} parentActivity
22
+ * @param {import('#types').ContextInstance} context
23
+ */
22
24
  function ProcessExecution(parentActivity, context) {
23
25
  const {
24
26
  id,
@@ -27,7 +29,7 @@ function ProcessExecution(parentActivity, context) {
27
29
  isSubProcess,
28
30
  isTransaction
29
31
  } = parentActivity;
30
- this[kParent] = parentActivity;
32
+ this[K_PARENT] = parentActivity;
31
33
  this.id = id;
32
34
  this.type = type;
33
35
  this.isSubProcess = isSubProcess;
@@ -35,29 +37,30 @@ function ProcessExecution(parentActivity, context) {
35
37
  this.broker = broker;
36
38
  this.environment = context.environment;
37
39
  this.context = context;
38
- this[kElements] = {
40
+ this[K_ELEMENTS] = {
39
41
  postponed: new Set(),
40
42
  children: context.getActivities(id),
41
43
  associations: context.getAssociations(id),
42
44
  flows: context.getSequenceFlows(id),
43
45
  outboundMessageFlows: context.getMessageFlows(id),
44
46
  startActivities: new Set(),
47
+ startEventCount: 0,
45
48
  triggeredByEvent: new Set(),
46
49
  detachedActivities: new Set(),
47
- startSequences: {}
50
+ convergingGateways: new Set()
48
51
  };
49
52
  const exchangeName = this._exchangeName = isSubProcess ? 'subprocess-execution' : 'execution';
50
53
  broker.assertExchange(exchangeName, 'topic', {
51
54
  autoDelete: false,
52
55
  durable: true
53
56
  });
54
- this[kCompleted] = false;
55
- this[kStopped] = false;
56
- this[kActivated] = false;
57
- this[kStatus] = 'init';
58
- this[kTracker] = new _Tracker.ActivityTracker(id);
57
+ this[_constants.K_COMPLETED] = false;
58
+ this[_constants.K_STOPPED] = false;
59
+ this[_constants.K_ACTIVATED] = false;
60
+ this[_constants.K_STATUS] = 'init';
61
+ this[K_TRACKER] = new _Tracker.ActivityTracker(id);
59
62
  this.executionId = undefined;
60
- this[kMessageHandlers] = {
63
+ this[_constants.K_MESSAGE_HANDLERS] = {
61
64
  onActivityEvent: this._onActivityEvent.bind(this),
62
65
  onApiMessage: this._onApiMessage.bind(this),
63
66
  onChildMessage: this._onChildMessage.bind(this),
@@ -67,46 +70,52 @@ function ProcessExecution(parentActivity, context) {
67
70
  Object.defineProperties(ProcessExecution.prototype, {
68
71
  stopped: {
69
72
  get() {
70
- return this[kStopped];
73
+ return this[_constants.K_STOPPED];
71
74
  }
72
75
  },
73
76
  completed: {
74
77
  get() {
75
- return this[kCompleted];
78
+ return this[_constants.K_COMPLETED];
76
79
  }
77
80
  },
78
81
  status: {
79
82
  get() {
80
- return this[kStatus];
83
+ return this[_constants.K_STATUS];
81
84
  }
82
85
  },
83
86
  postponedCount: {
84
87
  get() {
85
- return this[kElements].postponed.size;
88
+ return this[K_ELEMENTS].postponed.size;
86
89
  }
87
90
  },
88
91
  isRunning: {
89
92
  get() {
90
- return this[kActivated];
93
+ return this[_constants.K_ACTIVATED];
91
94
  }
92
95
  },
93
96
  activityStatus: {
94
97
  get() {
95
- return this[kTracker].activityStatus;
98
+ return this[K_TRACKER].activityStatus;
96
99
  }
97
100
  }
98
101
  });
102
+
103
+ /**
104
+ * Activate children and start the process execution. Resumes if the message is redelivered.
105
+ * @param {import('#types').ElementBrokerMessage} executeMessage
106
+ * @throws {Error} when message or executionId is missing
107
+ */
99
108
  ProcessExecution.prototype.execute = function execute(executeMessage) {
100
109
  if (!executeMessage) throw new Error('Process execution requires message');
101
110
  if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Process execution requires execution id');
102
111
  const executionId = this.executionId = executeMessage.content.executionId;
103
- this[kExecuteMessage] = (0, _messageHelper.cloneMessage)(executeMessage, {
112
+ this[_constants.K_EXECUTE_MESSAGE] = (0, _messageHelper.cloneMessage)(executeMessage, {
104
113
  executionId,
105
114
  state: 'start'
106
115
  });
107
- this[kStopped] = false;
116
+ this[_constants.K_STOPPED] = false;
108
117
  this.environment.assignVariables(executeMessage);
109
- this[kActivityQ] = this.broker.assertQueue(`execute-${executionId}-q`, {
118
+ this[K_ACTIVITY_Q] = this.broker.assertQueue(`execute-${executionId}-q`, {
110
119
  durable: true,
111
120
  autoDelete: false
112
121
  });
@@ -118,28 +127,29 @@ ProcessExecution.prototype.execute = function execute(executeMessage) {
118
127
  this._start();
119
128
  return true;
120
129
  };
130
+
131
+ /**
132
+ * Resume after recover, resuming any postponed children.
133
+ */
121
134
  ProcessExecution.prototype.resume = function resume() {
122
135
  this._debug(`resume process execution at ${this.status}`);
123
- if (this[kCompleted]) return this._complete('completed');
136
+ if (this[_constants.K_COMPLETED]) return this._complete('completed');
124
137
  this._activate();
125
138
  const {
126
- startActivities,
127
- detachedActivities,
128
- postponed
129
- } = this[kElements];
130
- if (startActivities.size > 1) {
131
- for (const a of startActivities) a.shake();
132
- }
139
+ postponed,
140
+ detachedActivities
141
+ } = this[K_ELEMENTS];
142
+ this._shakeOnStart();
133
143
  postponed.clear();
134
144
  detachedActivities.clear();
135
- this[kActivityQ].consume(this[kMessageHandlers].onChildMessage, {
145
+ this[K_ACTIVITY_Q].consume(this[_constants.K_MESSAGE_HANDLERS].onChildMessage, {
136
146
  prefetch: 1000,
137
147
  consumerTag: `_process-activity-${this.executionId}`
138
148
  });
139
- if (this[kCompleted]) return;
149
+ if (this[_constants.K_COMPLETED]) return;
140
150
  const status = this.status;
141
151
  if (status === 'init') return this._start();
142
- const tracker = this[kTracker];
152
+ const tracker = this[K_TRACKER];
143
153
  for (const msg of new Set(postponed)) {
144
154
  const activity = this.getActivityById(msg.content.id);
145
155
  if (!activity) continue;
@@ -152,16 +162,21 @@ ProcessExecution.prototype.resume = function resume() {
152
162
  tracker.track(msg.fields.routingKey, msg);
153
163
  activity.resume();
154
164
  }
155
- if (this[kCompleted]) return;
165
+ if (this[_constants.K_COMPLETED]) return;
156
166
  if (!postponed.size && status === 'executing') return this._complete('completed');
157
167
  };
168
+
169
+ /**
170
+ * Snapshot execution state including children, flows, message flows, and associations.
171
+ * @returns {import('#types').ProcessExecutionState}
172
+ */
158
173
  ProcessExecution.prototype.getState = function getState() {
159
174
  const {
160
175
  children,
161
176
  flows,
162
177
  outboundMessageFlows,
163
178
  associations
164
- } = this[kElements];
179
+ } = this[K_ELEMENTS];
165
180
  const flowStates = flows.reduce((result, flow) => {
166
181
  const elmState = flow.getState();
167
182
  if (elmState) result.push(elmState);
@@ -169,8 +184,8 @@ ProcessExecution.prototype.getState = function getState() {
169
184
  }, []);
170
185
  return {
171
186
  executionId: this.executionId,
172
- stopped: this[kStopped],
173
- completed: this[kCompleted],
187
+ stopped: this[_constants.K_STOPPED],
188
+ completed: this[_constants.K_COMPLETED],
174
189
  status: this.status,
175
190
  children: children.reduce((result, activity) => {
176
191
  if (activity.placeholder) return result;
@@ -189,12 +204,18 @@ ProcessExecution.prototype.getState = function getState() {
189
204
  })
190
205
  };
191
206
  };
207
+
208
+ /**
209
+ * Restore execution state captured by getState.
210
+ * @param {import('#types').ProcessExecutionState} [state]
211
+ * @returns {this}
212
+ */
192
213
  ProcessExecution.prototype.recover = function recover(state) {
193
214
  if (!state) return this;
194
215
  this.executionId = state.executionId;
195
- this[kStopped] = state.stopped;
196
- this[kCompleted] = state.completed;
197
- this[kStatus] = state.status;
216
+ this[_constants.K_STOPPED] = state.stopped;
217
+ this[_constants.K_COMPLETED] = state.completed;
218
+ this[_constants.K_STATUS] = state.status;
198
219
  this._debug(`recover process execution at ${this.status}`);
199
220
  if (state.messageFlows) {
200
221
  for (const flowState of state.messageFlows) {
@@ -226,53 +247,30 @@ ProcessExecution.prototype.recover = function recover(state) {
226
247
  }
227
248
  return this;
228
249
  };
250
+
251
+ /**
252
+ * Walk activity graph from the given start id, or every start activity when omitted.
253
+ * @param {string} [fromId]
254
+ * @returns {import('#types').ShakeResult}
255
+ */
229
256
  ProcessExecution.prototype.shake = function shake(fromId) {
230
- let executing = true;
231
- const id = this.id;
232
- if (!this.isRunning) {
233
- executing = false;
234
- this.executionId = (0, _shared.getUniqueId)(id);
235
- this._activate();
236
- }
237
- const toShake = fromId ? [this.getActivityById(fromId)].filter(Boolean) : this[kElements].startActivities;
238
- const result = {};
239
- this.broker.subscribeTmp('event', '*.shake.*', (routingKey, {
240
- content
241
- }) => {
242
- let isLooped = false;
243
- switch (routingKey) {
244
- case 'flow.shake.loop':
245
- isLooped = true;
246
- case 'activity.shake.end':
247
- {
248
- const {
249
- id: shakeId,
250
- parent: shakeParent
251
- } = content;
252
- if (shakeParent.id !== id) return;
253
- result[shakeId] = result[shakeId] || [];
254
- result[shakeId].push({
255
- ...content,
256
- isLooped
257
- });
258
- break;
259
- }
260
- }
261
- }, {
262
- noAck: true,
263
- consumerTag: `_shaker-${this.executionId}`
264
- });
265
- for (const a of toShake) a.shake();
266
- if (!executing) this._deactivate();
267
- this.broker.cancel(`_shaker-${this.executionId}`);
268
- return result;
257
+ return Object.fromEntries(this._shakeElements(fromId).sequences);
269
258
  };
259
+
260
+ /**
261
+ * Stop the running process execution via the api.
262
+ */
270
263
  ProcessExecution.prototype.stop = function stop() {
271
264
  this.getApi().stop();
272
265
  };
266
+
267
+ /**
268
+ * List currently postponed children as Api wrappers.
269
+ * @param {import('#types').filterPostponed} [filterFn]
270
+ */
273
271
  ProcessExecution.prototype.getPostponed = function getPostponed(filterFn) {
274
272
  const result = [];
275
- for (const msg of this[kElements].postponed) {
273
+ for (const msg of this[K_ELEMENTS].postponed) {
276
274
  const api = this._getChildApi(msg);
277
275
  if (!api) continue;
278
276
  if (filterFn && !filterFn(api)) continue;
@@ -280,9 +278,13 @@ ProcessExecution.prototype.getPostponed = function getPostponed(filterFn) {
280
278
  }
281
279
  return result;
282
280
  };
281
+
282
+ /**
283
+ * Queue a discard message that propagates to all running children.
284
+ */
283
285
  ProcessExecution.prototype.discard = function discard() {
284
- this[kStatus] = 'discard';
285
- return this[kActivityQ].queueMessage({
286
+ this[_constants.K_STATUS] = 'discard';
287
+ this[K_ACTIVITY_Q].queueMessage({
286
288
  routingKey: 'execution.discard'
287
289
  }, {
288
290
  id: this.id,
@@ -292,8 +294,12 @@ ProcessExecution.prototype.discard = function discard() {
292
294
  type: 'discard'
293
295
  });
294
296
  };
297
+
298
+ /**
299
+ * Queue a cancel message that propagates to all running children.
300
+ */
295
301
  ProcessExecution.prototype.cancel = function discard() {
296
- return this[kActivityQ].queueMessage({
302
+ this[K_ACTIVITY_Q].queueMessage({
297
303
  routingKey: 'execution.cancel'
298
304
  }, {
299
305
  id: this.id,
@@ -303,26 +309,52 @@ ProcessExecution.prototype.cancel = function discard() {
303
309
  type: 'cancel'
304
310
  });
305
311
  };
312
+
313
+ /**
314
+ * Get child activities in the process scope.
315
+ * @returns {import('#types').Activity[]}
316
+ */
306
317
  ProcessExecution.prototype.getActivities = function getActivities() {
307
- return this[kElements].children.slice();
318
+ return this[K_ELEMENTS].children.slice();
308
319
  };
320
+
321
+ /**
322
+ * @param {string} activityId
323
+ * @returns {import('#types').Activity}
324
+ */
309
325
  ProcessExecution.prototype.getActivityById = function getActivityById(activityId) {
310
- return this[kElements].children.find(child => child.id === activityId);
326
+ return this[K_ELEMENTS].children.find(child => child.id === activityId);
311
327
  };
328
+
329
+ /**
330
+ * Get sequence flows in the process scope.
331
+ * @returns {import('#types').SequenceFlow}
332
+ */
312
333
  ProcessExecution.prototype.getSequenceFlows = function getSequenceFlows() {
313
- return this[kElements].flows.slice();
334
+ return this[K_ELEMENTS].flows.slice();
314
335
  };
336
+
337
+ /**
338
+ * Get associations in the process scope.
339
+ * @returns {import('../flows/Association.js').Association}
340
+ */
315
341
  ProcessExecution.prototype.getAssociations = function getAssociations() {
316
- return this[kElements].associations.slice();
342
+ return this[K_ELEMENTS].associations.slice();
317
343
  };
344
+
345
+ /**
346
+ * Resolve a process or child Api for the given message.
347
+ * @param {import('#types').ElementBrokerMessage} [message]
348
+ * @returns {import('#types').IApi<import('#types').Process>}
349
+ */
318
350
  ProcessExecution.prototype.getApi = function getApi(message) {
319
- if (!message) return (0, _Api.ProcessApi)(this.broker, this[kExecuteMessage]);
351
+ if (!message) return (0, _Api.ProcessApi)(this.broker, this[_constants.K_EXECUTE_MESSAGE]);
320
352
  const content = message.content;
321
353
  if (content.executionId !== this.executionId) {
322
354
  return this._getChildApi(message);
323
355
  }
324
356
  const api = (0, _Api.ProcessApi)(this.broker, message);
325
- const postponed = this[kElements].postponed;
357
+ const postponed = this[K_ELEMENTS].postponed;
326
358
  const self = this;
327
359
  api.getExecuting = function getExecuting() {
328
360
  const result = [];
@@ -334,13 +366,15 @@ ProcessExecution.prototype.getApi = function getApi(message) {
334
366
  };
335
367
  return api;
336
368
  };
369
+
370
+ /** @internal */
337
371
  ProcessExecution.prototype._start = function start() {
338
- if (this[kElements].children.length === 0) {
372
+ if (!this[K_ELEMENTS].children.length) {
339
373
  return this._complete('completed');
340
374
  }
341
- this[kStatus] = 'start';
375
+ this[_constants.K_STATUS] = 'start';
342
376
  const executeContent = {
343
- ...this[kExecuteMessage].content,
377
+ ...this[_constants.K_EXECUTE_MESSAGE].content,
344
378
  state: this.status
345
379
  };
346
380
  this.broker.publish(this._exchangeName, 'execute.start', (0, _messageHelper.cloneContent)(executeContent));
@@ -348,26 +382,31 @@ ProcessExecution.prototype._start = function start() {
348
382
  startActivities,
349
383
  postponed,
350
384
  detachedActivities
351
- } = this[kElements];
352
- if (startActivities.size > 1) {
353
- for (const a of startActivities) a.shake();
354
- }
385
+ } = this[K_ELEMENTS];
386
+ this._shakeOnStart();
355
387
  for (const a of startActivities) a.init();
356
- this[kStatus] = 'executing';
388
+ this[_constants.K_STATUS] = 'executing';
357
389
  for (const a of startActivities) a.run();
390
+ if (!startActivities.size) {
391
+ for (const a of this[K_ELEMENTS].triggeredByEvent) {
392
+ if (a.isCatching && !a.isRunning) a.run();
393
+ }
394
+ }
358
395
  postponed.clear();
359
396
  detachedActivities.clear();
360
- this[kActivityQ].assertConsumer(this[kMessageHandlers].onChildMessage, {
397
+ this[K_ACTIVITY_Q].assertConsumer(this[_constants.K_MESSAGE_HANDLERS].onChildMessage, {
361
398
  prefetch: 1000,
362
399
  consumerTag: `_process-activity-${this.executionId}`
363
400
  });
364
401
  };
402
+
403
+ /** @internal */
365
404
  ProcessExecution.prototype._activate = function activate() {
366
405
  const {
367
406
  onApiMessage,
368
407
  onMessageFlowEvent,
369
408
  onActivityEvent
370
- } = this[kMessageHandlers];
409
+ } = this[_constants.K_MESSAGE_HANDLERS];
371
410
  if (!this.isSubProcess) {
372
411
  this.broker.consume('api-q', onApiMessage, {
373
412
  noAck: true,
@@ -387,8 +426,9 @@ ProcessExecution.prototype._activate = function activate() {
387
426
  associations,
388
427
  startActivities,
389
428
  triggeredByEvent,
429
+ convergingGateways,
390
430
  children
391
- } = this[kElements];
431
+ } = this[K_ELEMENTS];
392
432
  for (const flow of outboundMessageFlows) {
393
433
  flow.activate();
394
434
  flow.broker.subscribeTmp('event', '#', onMessageFlowEvent, {
@@ -413,6 +453,7 @@ ProcessExecution.prototype._activate = function activate() {
413
453
  }
414
454
  startActivities.clear();
415
455
  triggeredByEvent.clear();
456
+ let startEventCount = 0;
416
457
  for (const activity of children) {
417
458
  if (activity.placeholder) continue;
418
459
  activity.activate(this);
@@ -421,11 +462,18 @@ ProcessExecution.prototype._activate = function activate() {
421
462
  consumerTag: '_process-activity-consumer',
422
463
  priority: 200
423
464
  });
424
- if (activity.isStart) startActivities.add(activity);
425
- if (activity.triggeredByEvent) triggeredByEvent.add(activity);
465
+ if (activity.isStart) {
466
+ startActivities.add(activity);
467
+ if (activity.isStartEvent) startEventCount++;
468
+ }
469
+ if (activity.triggeredByEvent || activity.isCatching) triggeredByEvent.add(activity);
470
+ if (activity.isParallelGateway) convergingGateways.add(activity);
426
471
  }
427
- this[kActivated] = true;
472
+ this[K_ELEMENTS].startEventCount = startEventCount;
473
+ this[_constants.K_ACTIVATED] = true;
428
474
  };
475
+
476
+ /** @internal */
429
477
  ProcessExecution.prototype._deactivate = function deactivate() {
430
478
  const broker = this.broker;
431
479
  const executionId = this.executionId;
@@ -436,7 +484,7 @@ ProcessExecution.prototype._deactivate = function deactivate() {
436
484
  flows,
437
485
  associations,
438
486
  outboundMessageFlows
439
- } = this[kElements];
487
+ } = this[K_ELEMENTS];
440
488
  for (const activity of children) {
441
489
  if (activity.placeholder) continue;
442
490
  activity.broker.cancel('_process-activity-consumer');
@@ -452,8 +500,105 @@ ProcessExecution.prototype._deactivate = function deactivate() {
452
500
  flow.deactivate();
453
501
  flow.broker.cancel('_process-message-consumer');
454
502
  }
455
- this[kActivated] = false;
503
+ this[_constants.K_ACTIVATED] = false;
504
+ };
505
+
506
+ /**
507
+ * Discover converging parallel gateway peers for the peer monitor, reusing already discovered ones.
508
+ * @internal
509
+ */
510
+ ProcessExecution.prototype._shakeOnStart = function shakeOnStart() {
511
+ const convergingGateways = this[K_ELEMENTS].convergingGateways;
512
+ if (!convergingGateways.size) return;
513
+ if (this._peersDiscovered()) {
514
+ this._debug(`reuse discovered parallel gateway peers (${convergingGateways.size})`);
515
+ return;
516
+ }
517
+ this._shakeElements();
518
+ this._debug(`forced shake to discover converging gateway peers (${convergingGateways.size})`);
519
+ };
520
+
521
+ /**
522
+ * Whether every converging parallel gateway has discovered its peers in this runtime instance.
523
+ * Peers are a runtime cache and absent after recover, so a changed source is reshaken.
524
+ * @internal
525
+ */
526
+ ProcessExecution.prototype._peersDiscovered = function peersDiscovered() {
527
+ const convergingGateways = this[K_ELEMENTS].convergingGateways;
528
+ for (const gateway of convergingGateways) {
529
+ if (!gateway[K_PEERS_DISCOVERED]) return false;
530
+ }
531
+ return true;
532
+ };
533
+
534
+ /** @internal */
535
+ ProcessExecution.prototype._shakeElements = function shakeElements(fromId) {
536
+ let executing = true;
537
+ const id = this.id;
538
+ if (!this.isRunning) {
539
+ executing = false;
540
+ this.executionId = (0, _shared.getUniqueId)(id);
541
+ this._activate();
542
+ }
543
+ const toShake = fromId ? [this.getActivityById(fromId)].filter(Boolean) : this[K_ELEMENTS].startActivities;
544
+ const result = {
545
+ sequences: new Map()
546
+ };
547
+ const convergingGateways = new Map();
548
+ const consumerTag = `_shaker-${this.executionId}`;
549
+ this.broker.subscribeTmp('event', '*.shake.*', (routingKey, {
550
+ content
551
+ }) => {
552
+ if (content.parent.id !== this.id) return;
553
+ switch (routingKey) {
554
+ case 'activity.shake.join':
555
+ {
556
+ const join = convergingGateways.get(content.join);
557
+ if (!join) {
558
+ convergingGateways.set(content.join, content);
559
+ } else {
560
+ join.sequence = join.sequence.concat(content.sequence);
561
+ }
562
+ break;
563
+ }
564
+ case 'flow.shake.loop':
565
+ case 'activity.shake.linked':
566
+ case 'activity.shake.end':
567
+ {
568
+ const {
569
+ id: shakeId,
570
+ parent: shakeParent
571
+ } = content;
572
+ if (shakeParent.id !== id) return;
573
+ let seqnce;
574
+ if (!(seqnce = result.sequences.get(shakeId))) {
575
+ seqnce = [];
576
+ result.sequences.set(shakeId, seqnce);
577
+ }
578
+ seqnce.push({
579
+ ...content,
580
+ isLooped: routingKey === 'flow.shake.loop'
581
+ });
582
+ break;
583
+ }
584
+ }
585
+ }, {
586
+ noAck: true,
587
+ consumerTag
588
+ });
589
+ for (const a of toShake) a.shake();
590
+ for (const [aid, c] of convergingGateways.entries()) {
591
+ this._debug(`manual shake of converging gateway <${aid}>`);
592
+ this.getActivityById(aid).broker.publish('api', 'activity.shake.continue', c, {
593
+ type: 'shake'
594
+ });
595
+ }
596
+ if (!executing) this._deactivate();
597
+ this.broker.cancel(consumerTag);
598
+ return result;
456
599
  };
600
+
601
+ /** @internal */
457
602
  ProcessExecution.prototype._onDelegateEvent = function onDelegateEvent(message) {
458
603
  const eventType = message.properties.type;
459
604
  let delegate = true;
@@ -463,8 +608,8 @@ ProcessExecution.prototype._onDelegateEvent = function onDelegateEvent(message)
463
608
  } else {
464
609
  this._debug(`delegate ${eventType} anonymous event`);
465
610
  }
466
- for (const activity of this[kElements].triggeredByEvent) {
467
- if (activity.getStartActivities({
611
+ for (const activity of this[K_ELEMENTS].triggeredByEvent) {
612
+ if (activity.isSubProcess && activity.getStartActivities({
468
613
  referenceId: content.message?.id,
469
614
  referenceType: eventType
470
615
  }).length) {
@@ -477,15 +622,23 @@ ProcessExecution.prototype._onDelegateEvent = function onDelegateEvent(message)
477
622
  });
478
623
  return delegate;
479
624
  };
625
+
626
+ /** @internal */
480
627
  ProcessExecution.prototype._onMessageFlowEvent = function onMessageFlowEvent(routingKey, message) {
481
628
  this.broker.publish('message', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
482
629
  };
630
+
631
+ /** @internal */
483
632
  ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKey, message) {
484
- if (message.fields.redelivered && message.properties.persistent === false) return;
485
- const content = message.content;
633
+ const {
634
+ fields,
635
+ content,
636
+ properties
637
+ } = message;
638
+ if (fields.redelivered && properties.persistent === false) return;
486
639
  const parent = content.parent = content.parent || {};
487
- let delegate = message.properties.delegate;
488
- const shaking = message.properties.type === 'shake';
640
+ let delegate = properties.delegate;
641
+ const shaking = properties.type === 'shake';
489
642
  const isDirectChild = content.parent.id === this.id;
490
643
  if (isDirectChild) {
491
644
  parent.executionId = this.executionId;
@@ -497,17 +650,17 @@ ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKe
497
650
  });
498
651
  }
499
652
  if (delegate) delegate = this._onDelegateEvent(message);
500
- this[kTracker].track(routingKey, message);
653
+ this[K_TRACKER].track(routingKey, message);
501
654
  this.broker.publish('event', routingKey, content, {
502
- ...message.properties,
655
+ ...properties,
503
656
  delegate,
504
657
  mandatory: false
505
658
  });
506
- if (shaking) return this._onShookEnd(message);
659
+ if (shaking) return;
507
660
  if (!isDirectChild) return;
508
661
  switch (routingKey) {
509
662
  case 'process.terminate':
510
- return this[kActivityQ].queueMessage({
663
+ return this[K_ACTIVITY_Q].queueMessage({
511
664
  routingKey: 'execution.terminate'
512
665
  }, (0, _messageHelper.cloneContent)(content), {
513
666
  type: 'terminate',
@@ -516,11 +669,13 @@ ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKe
516
669
  case 'activity.stop':
517
670
  return;
518
671
  }
519
- this[kActivityQ].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), {
672
+ this[K_ACTIVITY_Q].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), {
520
673
  persistent: true,
521
674
  ...message.properties
522
675
  });
523
676
  };
677
+
678
+ /** @internal */
524
679
  ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey, message) {
525
680
  if (message.fields.redelivered && message.properties.persistent === false) return message.ack();
526
681
  const content = message.content;
@@ -537,7 +692,7 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
537
692
  case 'execution.discard.detached':
538
693
  {
539
694
  message.ack();
540
- for (const detached of this[kElements].detachedActivities) {
695
+ for (const detached of this[K_ELEMENTS].detachedActivities) {
541
696
  this._getChildApi(detached).discard();
542
697
  }
543
698
  return;
@@ -548,7 +703,7 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
548
703
  case 'activity.error.caught':
549
704
  {
550
705
  let prevMsg;
551
- for (const msg of this[kElements].postponed) {
706
+ for (const msg of this[K_ELEMENTS].postponed) {
552
707
  if (msg.content.executionId === content.executionId) {
553
708
  prevMsg = msg;
554
709
  break;
@@ -557,7 +712,6 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
557
712
  if (!prevMsg) return message.ack();
558
713
  break;
559
714
  }
560
- case 'flow.looped':
561
715
  case 'activity.leave':
562
716
  return this._onChildCompleted(message);
563
717
  }
@@ -565,7 +719,7 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
565
719
  switch (routingKey) {
566
720
  case 'activity.detach':
567
721
  {
568
- this[kElements].detachedActivities.add((0, _messageHelper.cloneMessage)(message));
722
+ this[K_ELEMENTS].detachedActivities.add((0, _messageHelper.cloneMessage)(message));
569
723
  break;
570
724
  }
571
725
  case 'activity.cancel':
@@ -584,17 +738,31 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
584
738
  }
585
739
  break;
586
740
  }
741
+ case 'activity.end':
742
+ {
743
+ if (!content.isStartEvent) break;
744
+ const elements = this[K_ELEMENTS];
745
+ if (elements.startEventCount <= 1) break;
746
+ const startPeers = new Set();
747
+ for (const msg of elements.postponed) {
748
+ const peerId = msg.content.id;
749
+ if (peerId !== content.id && msg.content.isStartEvent) startPeers.add(msg);
750
+ }
751
+ elements.startEventCount = 0;
752
+ for (const msg of startPeers) this._getChildApi(msg).discard();
753
+ break;
754
+ }
587
755
  case 'activity.error':
588
756
  {
589
757
  let eventCaughtBy;
590
- for (const msg of this[kElements].postponed) {
758
+ for (const msg of this[K_ELEMENTS].postponed) {
591
759
  if (msg.fields.routingKey === 'activity.catch' && msg.content.source?.executionId === content.executionId) {
592
760
  eventCaughtBy = msg;
593
761
  break;
594
762
  }
595
763
  }
596
764
  if (eventCaughtBy) {
597
- this[kActivityQ].queueMessage({
765
+ this[K_ACTIVITY_Q].queueMessage({
598
766
  routingKey: 'activity.error.caught'
599
767
  }, (0, _messageHelper.cloneContent)(content), {
600
768
  persistent: true,
@@ -608,16 +776,20 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
608
776
  }
609
777
  }
610
778
  };
779
+
780
+ /** @internal */
611
781
  ProcessExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
612
782
  const previousMsg = this._popPostponed(message.content);
613
783
  if (previousMsg) previousMsg.ack();
614
- if (postponeMessage) this[kElements].postponed.add(message);
784
+ if (postponeMessage) this[K_ELEMENTS].postponed.add(message);
615
785
  };
786
+
787
+ /** @internal */
616
788
  ProcessExecution.prototype._popPostponed = function popPostponed(byContent) {
617
789
  const {
618
790
  postponed,
619
791
  detachedActivities
620
- } = this[kElements];
792
+ } = this[K_ELEMENTS];
621
793
  let postponedMsg;
622
794
  if (byContent.sequenceId) {
623
795
  for (const msg of postponed) {
@@ -644,19 +816,25 @@ ProcessExecution.prototype._popPostponed = function popPostponed(byContent) {
644
816
  }
645
817
  return postponedMsg;
646
818
  };
819
+
820
+ /** @internal */
647
821
  ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message) {
648
822
  this._stateChangeMessage(message, false);
649
823
  if (message.fields.redelivered) return message.ack();
650
824
  const {
651
825
  id,
652
826
  type,
653
- isEnd
827
+ isParallelGateway
654
828
  } = message.content;
829
+ if (isParallelGateway) {
830
+ for (const inb of message.content.inbound) {
831
+ this._popPostponed(inb)?.ack();
832
+ }
833
+ }
655
834
  const {
656
835
  postponed,
657
- detachedActivities,
658
- startActivities
659
- } = this[kElements];
836
+ detachedActivities
837
+ } = this[K_ELEMENTS];
660
838
  const postponedCount = postponed.size;
661
839
  if (!postponedCount) {
662
840
  this._debug(`left <${id}> (${type}), pending runs ${postponedCount}`);
@@ -664,9 +842,9 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
664
842
  return this._complete('completed');
665
843
  }
666
844
  message.ack();
667
- this._debug(`left <${id}> (${type}), pending activities ${postponedCount}`);
845
+ this._debug(`left <${id}> (${type}), pending activities ${postponedCount} ${[...postponed].map(m => m.content.id)}`);
668
846
  if (postponedCount && postponedCount === detachedActivities.size) {
669
- return this[kActivityQ].queueMessage({
847
+ return this[K_ACTIVITY_Q].queueMessage({
670
848
  routingKey: 'execution.discard.detached'
671
849
  }, {
672
850
  id: this.id,
@@ -676,21 +854,9 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
676
854
  type: 'cancel'
677
855
  });
678
856
  }
679
- if (isEnd && startActivities.size) {
680
- const startSequences = this[kElements].startSequences;
681
- for (const msg of postponed) {
682
- const postponedId = msg.content.id;
683
- const startSequence = startSequences[postponedId];
684
- if (startSequence) {
685
- if (startSequence.content.sequence.some(({
686
- id: sid
687
- }) => sid === id)) {
688
- this._getChildApi(msg).discard();
689
- }
690
- }
691
- }
692
- }
693
857
  };
858
+
859
+ /** @internal */
694
860
  ProcessExecution.prototype._stopExecution = function stopExecution(message) {
695
861
  const postponedCount = this.postponedCount;
696
862
  this._debug(`stop process execution (stop child executions ${postponedCount})`);
@@ -698,18 +864,20 @@ ProcessExecution.prototype._stopExecution = function stopExecution(message) {
698
864
  for (const api of this.getPostponed()) api.stop();
699
865
  }
700
866
  this._deactivate();
701
- this[kStopped] = true;
867
+ this[_constants.K_STOPPED] = true;
702
868
  return this.broker.publish(this._exchangeName, `execution.stopped.${this.executionId}`, {
703
- ...this[kExecuteMessage].content,
869
+ ...this[_constants.K_EXECUTE_MESSAGE].content,
704
870
  ...(message && message.content)
705
871
  }, {
706
872
  type: 'stopped',
707
873
  persistent: false
708
874
  });
709
875
  };
876
+
877
+ /** @internal */
710
878
  ProcessExecution.prototype._onDiscard = function onDiscard() {
711
879
  this._deactivate();
712
- const postponed = this[kElements].postponed;
880
+ const postponed = this[K_ELEMENTS].postponed;
713
881
  const running = new Set(postponed);
714
882
  postponed.clear();
715
883
  this._debug(`discard process execution (discard child executions ${running.size})`);
@@ -720,17 +888,19 @@ ProcessExecution.prototype._onDiscard = function onDiscard() {
720
888
  for (const flow of this.getAssociations()) flow.stop();
721
889
  for (const msg of running) this._getChildApi(msg).discard();
722
890
  }
723
- this[kActivityQ].purge();
891
+ this[K_ACTIVITY_Q].purge();
724
892
  return this._complete('discard');
725
893
  };
894
+
895
+ /** @internal */
726
896
  ProcessExecution.prototype._onCancel = function onCancel() {
727
- const postponed = this[kElements].postponed;
897
+ const postponed = this[K_ELEMENTS].postponed;
728
898
  const running = new Set(postponed);
729
899
  const isTransaction = this.isTransaction;
730
900
  if (isTransaction) {
731
901
  this._debug(`cancel transaction execution (cancel child executions ${running.size})`);
732
- this[kStatus] = 'cancel';
733
- this.broker.publish('event', 'transaction.cancel', (0, _messageHelper.cloneMessage)(this[kExecuteMessage], {
902
+ this[_constants.K_STATUS] = 'cancel';
903
+ this.broker.publish('event', 'transaction.cancel', (0, _messageHelper.cloneMessage)(this[_constants.K_EXECUTE_MESSAGE], {
734
904
  state: 'cancel'
735
905
  }));
736
906
  for (const msg of running) {
@@ -747,6 +917,8 @@ ProcessExecution.prototype._onCancel = function onCancel() {
747
917
  }
748
918
  }
749
919
  };
920
+
921
+ /** @internal */
750
922
  ProcessExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
751
923
  if (message.properties.delegate) {
752
924
  return this._delegateApiMessage(routingKey, message);
@@ -763,7 +935,7 @@ ProcessExecution.prototype._onApiMessage = function onApiMessage(routingKey, mes
763
935
  case 'discard':
764
936
  return this.discard(message);
765
937
  case 'stop':
766
- this[kActivityQ].queueMessage({
938
+ this[K_ACTIVITY_Q].queueMessage({
767
939
  routingKey: 'execution.stop'
768
940
  }, (0, _messageHelper.cloneContent)(message.content), {
769
941
  persistent: false
@@ -771,6 +943,8 @@ ProcessExecution.prototype._onApiMessage = function onApiMessage(routingKey, mes
771
943
  break;
772
944
  }
773
945
  };
946
+
947
+ /** @internal */
774
948
  ProcessExecution.prototype._delegateApiMessage = function delegateApiMessage(routingKey, message, continueOnConsumed) {
775
949
  const correlationId = message.properties.correlationId || (0, _shared.getUniqueId)(this.executionId);
776
950
  this._debug(`delegate api ${routingKey} message to children, with correlationId <${correlationId}>`);
@@ -785,16 +959,18 @@ ProcessExecution.prototype._delegateApiMessage = function delegateApiMessage(rou
785
959
  consumerTag: `_ct-delegate-${correlationId}`,
786
960
  noAck: true
787
961
  });
788
- for (const child of this[kElements].children) {
962
+ for (const child of this[K_ELEMENTS].children) {
789
963
  if (child.placeholder) continue;
790
964
  child.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
791
965
  if (consumed && !continueOnConsumed) break;
792
966
  }
793
967
  return broker.cancel(`_ct-delegate-${correlationId}`);
794
968
  };
969
+
970
+ /** @internal */
795
971
  ProcessExecution.prototype._complete = function complete(completionType, content) {
796
972
  this._deactivate();
797
- this[kCompleted] = true;
973
+ this[_constants.K_COMPLETED] = true;
798
974
  const status = this.status;
799
975
  switch (this.status) {
800
976
  case 'cancel':
@@ -806,11 +982,11 @@ ProcessExecution.prototype._complete = function complete(completionType, content
806
982
  break;
807
983
  default:
808
984
  this._debug(`process execution ${completionType}`);
809
- this[kStatus] = completionType;
985
+ this[_constants.K_STATUS] = completionType;
810
986
  }
811
987
  const broker = this.broker;
812
- this[kActivityQ].delete();
813
- return broker.publish(this._exchangeName, `execution.${completionType}.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
988
+ this[K_ACTIVITY_Q].delete();
989
+ broker.publish(this._exchangeName, `execution.${completionType}.${this.executionId}`, (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
814
990
  output: {
815
991
  ...this.environment.output
816
992
  },
@@ -821,10 +997,12 @@ ProcessExecution.prototype._complete = function complete(completionType, content
821
997
  mandatory: completionType === 'error'
822
998
  });
823
999
  };
1000
+
1001
+ /** @internal */
824
1002
  ProcessExecution.prototype._terminate = function terminate(message) {
825
- this[kStatus] = 'terminated';
1003
+ this[_constants.K_STATUS] = 'terminated';
826
1004
  this._debug('terminating process execution');
827
- const postponed = this[kElements].postponed;
1005
+ const postponed = this[K_ELEMENTS].postponed;
828
1006
  const running = new Set(postponed);
829
1007
  postponed.clear();
830
1008
  for (const flow of this.getSequenceFlows()) flow.stop();
@@ -840,20 +1018,30 @@ ProcessExecution.prototype._terminate = function terminate(message) {
840
1018
  this._getChildApi(msg).stop();
841
1019
  msg.ack();
842
1020
  }
843
- this[kActivityQ].purge();
1021
+ this[K_ACTIVITY_Q].purge();
844
1022
  };
1023
+
1024
+ /** @internal */
845
1025
  ProcessExecution.prototype._getFlowById = function getFlowById(flowId) {
846
- return this[kElements].flows.find(f => f.id === flowId);
1026
+ return this[K_ELEMENTS].flows.find(f => f.id === flowId);
847
1027
  };
1028
+
1029
+ /** @internal */
848
1030
  ProcessExecution.prototype._getAssociationById = function getAssociationById(associationId) {
849
- return this[kElements].associations.find(a => a.id === associationId);
1031
+ return this[K_ELEMENTS].associations.find(a => a.id === associationId);
850
1032
  };
1033
+
1034
+ /** @internal */
851
1035
  ProcessExecution.prototype._getMessageFlowById = function getMessageFlowById(flowId) {
852
- return this[kElements].outboundMessageFlows.find(f => f.id === flowId);
1036
+ return this[K_ELEMENTS].outboundMessageFlows.find(f => f.id === flowId);
853
1037
  };
1038
+
1039
+ /** @internal */
854
1040
  ProcessExecution.prototype._getChildById = function getChildById(childId) {
855
1041
  return this.getActivityById(childId) || this._getFlowById(childId);
856
1042
  };
1043
+
1044
+ /** @internal */
857
1045
  ProcessExecution.prototype._getChildApi = function getChildApi(message) {
858
1046
  const content = message.content;
859
1047
  let child = this._getChildById(content.id);
@@ -867,11 +1055,8 @@ ProcessExecution.prototype._getChildApi = function getChildApi(message) {
867
1055
  if (child) return child.getApi(message);
868
1056
  }
869
1057
  };
870
- ProcessExecution.prototype._onShookEnd = function onShookEnd(message) {
871
- const routingKey = message.fields.routingKey;
872
- if (routingKey !== 'activity.shake.end') return;
873
- this[kElements].startSequences[message.content.id] = (0, _messageHelper.cloneMessage)(message);
874
- };
1058
+
1059
+ /** @internal */
875
1060
  ProcessExecution.prototype._debug = function debugMessage(logMessage) {
876
- this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
1061
+ this[K_PARENT].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
877
1062
  };