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