bpmn-elements 17.3.0 → 18.0.1

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 +434 -233
  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 +27 -0
  20. package/dist/definition/Definition.js +187 -64
  21. package/dist/definition/DefinitionExecution.js +198 -84
  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 +1 -1
  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 +176 -77
  62. package/dist/process/ProcessExecution.js +397 -178
  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 +372 -218
  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 +21 -0
  95. package/src/definition/Definition.js +165 -63
  96. package/src/definition/DefinitionExecution.js +164 -85
  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 +1 -1
  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 +157 -74
  137. package/src/process/ProcessExecution.js +363 -176
  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 +2619 -84
  154. package/types/interfaces.d.ts +638 -0
  155. package/types/types.d.ts +0 -765
@@ -3,31 +3,33 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = DefinitionExecution;
7
- var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
6
+ exports.DefinitionExecution = DefinitionExecution;
8
7
  var _Api = require("../Api.js");
9
8
  var _shared = require("../shared.js");
10
9
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
- const kActivated = Symbol.for('activated');
13
- const kProcessesQ = Symbol.for('processesQ');
14
- const kCompleted = Symbol.for('completed');
15
- const kExecuteMessage = Symbol.for('executeMessage');
16
- const kMessageHandlers = Symbol.for('messageHandlers');
17
- const kParent = Symbol.for('definition');
18
- const kProcesses = Symbol.for('processes');
19
- const kStatus = Symbol.for('status');
20
- const kStopped = Symbol.for('stopped');
10
+ var _constants = require("../constants.js");
11
+ const K_PROCESSES_Q = Symbol.for('processesQ');
12
+ const K_PARENT = Symbol.for('definition');
13
+ const K_PROCESSES = Symbol.for('processes');
14
+
15
+ /**
16
+ * Drives the execution of a Definition. Activates executable processes, routes inter-process
17
+ * delegate messages and call activity hand-offs, and rolls completion up to the Definition.
18
+ * @param {import('./Definition.js').Definition} definition
19
+ * @param {import('../Context.js').ContextInstance} context
20
+ */
21
21
  function DefinitionExecution(definition, context) {
22
22
  const broker = definition.broker;
23
- this[kParent] = definition;
23
+ this[K_PARENT] = definition;
24
24
  this.id = definition.id;
25
25
  this.type = definition.type;
26
26
  this.broker = broker;
27
27
  const environment = this.environment = definition.environment;
28
28
  this.context = context;
29
29
  const processes = context.getProcesses();
30
+ /** @type {Set<string>} */
30
31
  const ids = new Set();
32
+ /** @type {Set<import('../process/Process.js').Process>} */
31
33
  const executable = new Set();
32
34
  for (const bp of processes) {
33
35
  bp.environment.assignVariables(environment.variables);
@@ -35,7 +37,7 @@ function DefinitionExecution(definition, context) {
35
37
  ids.add(bp.id);
36
38
  if (bp.isExecutable) executable.add(bp);
37
39
  }
38
- this[kProcesses] = {
40
+ this[K_PROCESSES] = {
39
41
  processes,
40
42
  ids,
41
43
  executable,
@@ -47,12 +49,12 @@ function DefinitionExecution(definition, context) {
47
49
  durable: true
48
50
  });
49
51
  this.executionId = undefined;
50
- this[kCompleted] = false;
51
- this[kStopped] = false;
52
- this[kActivated] = false;
53
- this[kStatus] = 'init';
54
- this[kProcessesQ] = undefined;
55
- this[kMessageHandlers] = {
52
+ this[_constants.K_COMPLETED] = false;
53
+ this[_constants.K_STOPPED] = false;
54
+ this[_constants.K_ACTIVATED] = false;
55
+ this[_constants.K_STATUS] = 'init';
56
+ this[K_PROCESSES_Q] = undefined;
57
+ this[_constants.K_MESSAGE_HANDLERS] = {
56
58
  onApiMessage: this._onApiMessage.bind(this),
57
59
  onCallActivity: this._onCallActivity.bind(this),
58
60
  onCancelCallActivity: this._onCancelCallActivity.bind(this),
@@ -65,38 +67,38 @@ function DefinitionExecution(definition, context) {
65
67
  Object.defineProperties(DefinitionExecution.prototype, {
66
68
  stopped: {
67
69
  get() {
68
- return this[kStopped];
70
+ return this[_constants.K_STOPPED];
69
71
  }
70
72
  },
71
73
  completed: {
72
74
  get() {
73
- return this[kCompleted];
75
+ return this[_constants.K_COMPLETED];
74
76
  }
75
77
  },
76
78
  status: {
77
79
  get() {
78
- return this[kStatus];
80
+ return this[_constants.K_STATUS];
79
81
  }
80
82
  },
81
83
  processes: {
82
84
  get() {
83
- return [...this[kProcesses].running];
85
+ return [...this[K_PROCESSES].running];
84
86
  }
85
87
  },
86
88
  postponedCount: {
87
89
  get() {
88
- return this[kProcesses].postponed.size;
90
+ return this[K_PROCESSES].postponed.size;
89
91
  }
90
92
  },
91
93
  isRunning: {
92
94
  get() {
93
- return this[kActivated];
95
+ return this[_constants.K_ACTIVATED];
94
96
  }
95
97
  },
96
98
  activityStatus: {
97
99
  get() {
98
100
  let status = 'idle';
99
- const running = this[kProcesses].running;
101
+ const running = this[K_PROCESSES].running;
100
102
  if (!running.size) return status;
101
103
  for (const bp of running) {
102
104
  const bpStatus = bp.activityStatus;
@@ -117,17 +119,24 @@ Object.defineProperties(DefinitionExecution.prototype, {
117
119
  }
118
120
  }
119
121
  });
122
+
123
+ /**
124
+ * Activate executable processes and start the definition execution. Resumes if the message
125
+ * is redelivered. When `content.processId` is set, only that process is started.
126
+ * @param {import('#types').ElementBrokerMessage} executeMessage
127
+ * @throws {Error} when message or executionId is missing
128
+ */
120
129
  DefinitionExecution.prototype.execute = function execute(executeMessage) {
121
130
  if (!executeMessage) throw new Error('Definition execution requires message');
122
131
  const content = executeMessage.content;
123
132
  const executionId = this.executionId = content.executionId;
124
133
  if (!executionId) throw new Error('Definition execution requires execution id');
125
- this[kExecuteMessage] = (0, _messageHelper.cloneMessage)(executeMessage, {
134
+ this[_constants.K_EXECUTE_MESSAGE] = (0, _messageHelper.cloneMessage)(executeMessage, {
126
135
  executionId,
127
136
  state: 'start'
128
137
  });
129
- this[kStopped] = false;
130
- this[kProcessesQ] = this.broker.assertQueue(`execute-${executionId}-q`, {
138
+ this[_constants.K_STOPPED] = false;
139
+ this[K_PROCESSES_Q] = this.broker.assertQueue(`execute-${executionId}-q`, {
131
140
  durable: true,
132
141
  autoDelete: false
133
142
  });
@@ -137,7 +146,7 @@ DefinitionExecution.prototype.execute = function execute(executeMessage) {
137
146
  const {
138
147
  running,
139
148
  executable
140
- } = this[kProcesses];
149
+ } = this[K_PROCESSES];
141
150
  if (content.processId) {
142
151
  const startWithProcess = this.getProcessById(content.processId);
143
152
  if (startWithProcess) {
@@ -153,30 +162,41 @@ DefinitionExecution.prototype.execute = function execute(executeMessage) {
153
162
  this._start();
154
163
  return true;
155
164
  };
165
+
166
+ /**
167
+ * Resume after recover by reactivating running processes.
168
+ */
156
169
  DefinitionExecution.prototype.resume = function resume() {
157
- this._debug(`resume ${this[kStatus]} definition execution`);
158
- if (this[kCompleted]) return this._complete('completed');
170
+ this._debug(`resume ${this[_constants.K_STATUS]} definition execution`);
171
+ if (this[_constants.K_COMPLETED]) return this._complete('completed');
159
172
  const {
160
173
  running,
161
174
  postponed
162
- } = this[kProcesses];
175
+ } = this[K_PROCESSES];
163
176
  this._activate(running);
164
177
  postponed.clear();
165
- this[kProcessesQ].consume(this[kMessageHandlers].onProcessMessage, {
178
+ this[K_PROCESSES_Q].consume(this[_constants.K_MESSAGE_HANDLERS].onProcessMessage, {
166
179
  prefetch: 1000,
167
180
  consumerTag: `_definition-activity-${this.executionId}`
168
181
  });
169
- if (this[kCompleted]) return;
182
+ if (this[_constants.K_COMPLETED]) return;
170
183
  for (const bp of running) bp.resume();
171
184
  };
172
- DefinitionExecution.prototype.recover = function recover(state) {
185
+
186
+ /**
187
+ * Restore execution state captured by getState. Reinstates running processes from the snapshot.
188
+ * @param {import('#types').DefinitionExecutionState} [state]
189
+ * @param {number} [recoveredVersion] State version
190
+ * @returns {this}
191
+ */
192
+ DefinitionExecution.prototype.recover = function recover(state, recoveredVersion) {
173
193
  if (!state) return this;
174
194
  this.executionId = state.executionId;
175
- this[kStopped] = state.stopped;
176
- this[kCompleted] = state.completed;
177
- this[kStatus] = state.status;
178
- this._debug(`recover ${this[kStatus]} definition execution`);
179
- const running = this[kProcesses].running;
195
+ this[_constants.K_STOPPED] = state.stopped;
196
+ this[_constants.K_COMPLETED] = state.completed;
197
+ this[_constants.K_STATUS] = state.status;
198
+ this._debug(`recover ${this[_constants.K_STATUS]} definition execution`);
199
+ const running = this[K_PROCESSES].running;
180
200
  running.clear();
181
201
  const ids = new Set();
182
202
  for (const bpState of state.processes) {
@@ -189,57 +209,101 @@ DefinitionExecution.prototype.recover = function recover(state) {
189
209
  }
190
210
  if (!bp) continue;
191
211
  ids.add(bpid);
192
- bp.recover(bpState);
212
+ bp.recover(bpState, recoveredVersion);
193
213
  running.add(bp);
194
214
  }
195
215
  return this;
196
216
  };
217
+
218
+ /**
219
+ * Stop the running execution via the api.
220
+ */
197
221
  DefinitionExecution.prototype.stop = function stop() {
198
222
  this.getApi().stop();
199
223
  };
224
+
225
+ /**
226
+ * Get every process in the definition (running first, then any non-running by id).
227
+ * @returns {import('../process/Process.js').Process[]}
228
+ */
200
229
  DefinitionExecution.prototype.getProcesses = function getProcesses() {
201
230
  const {
202
231
  running,
203
232
  processes
204
- } = this[kProcesses];
233
+ } = this[K_PROCESSES];
205
234
  const result = [...running];
206
235
  for (const bp of processes) {
207
236
  if (!result.find(runningBp => bp.id === runningBp.id)) result.push(bp);
208
237
  }
209
238
  return result;
210
239
  };
240
+
241
+ /**
242
+ * @param {string} processId
243
+ */
211
244
  DefinitionExecution.prototype.getProcessById = function getProcessById(processId) {
212
245
  return this.getProcesses().find(bp => bp.id === processId);
213
246
  };
247
+
248
+ /**
249
+ * Get every process matching the given id (call activities can spawn duplicates).
250
+ * @param {string} processId
251
+ */
214
252
  DefinitionExecution.prototype.getProcessesById = function getProcessesById(processId) {
215
253
  return this.getProcesses().filter(bp => bp.id === processId);
216
254
  };
255
+
256
+ /**
257
+ * @param {string} processExecutionId
258
+ * @returns {import('../process/Process.js').Process | undefined}
259
+ */
217
260
  DefinitionExecution.prototype.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
218
- for (const bp of this[kProcesses].running) {
261
+ for (const bp of this[K_PROCESSES].running) {
219
262
  if (bp.executionId === processExecutionId) return bp;
220
263
  }
221
264
  };
265
+
266
+ /**
267
+ * Get processes that have an executionId, i.e. are currently running.
268
+ * @returns {import('../process/Process.js').Process[]}
269
+ */
222
270
  DefinitionExecution.prototype.getRunningProcesses = function getRunningProcesses() {
223
- return [...this[kProcesses].running].filter(bp => bp.executionId);
271
+ return [...this[K_PROCESSES].running].filter(bp => bp.executionId);
224
272
  };
273
+
274
+ /**
275
+ * Get processes flagged executable in the definition.
276
+ * @returns {import('../process/Process.js').Process[]}
277
+ */
225
278
  DefinitionExecution.prototype.getExecutableProcesses = function getExecutableProcesses() {
226
- return [...this[kProcesses].executable];
279
+ return [...this[K_PROCESSES].executable];
227
280
  };
281
+
282
+ /**
283
+ * Snapshot execution state for recover.
284
+ * @returns {import('#types').DefinitionExecutionState}
285
+ */
228
286
  DefinitionExecution.prototype.getState = function getState() {
229
287
  const processes = [];
230
- for (const bp of this[kProcesses].running) {
288
+ for (const bp of this[K_PROCESSES].running) {
231
289
  processes.push(bp.getState());
232
290
  }
233
291
  return {
234
292
  executionId: this.executionId,
235
- stopped: this[kStopped],
236
- completed: this[kCompleted],
237
- status: this[kStatus],
293
+ stopped: this[_constants.K_STOPPED],
294
+ completed: this[_constants.K_COMPLETED],
295
+ status: this[_constants.K_STATUS],
238
296
  processes
239
297
  };
240
298
  };
299
+
300
+ /**
301
+ * Resolve a Definition Api or, when the message belongs to a child process, its process Api.
302
+ * @param {import('#types').ElementBrokerMessage} [apiMessage]
303
+ * @returns {import('#types').IApi<import('./Definition.js').Definition>}
304
+ */
241
305
  DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
242
- if (!apiMessage) apiMessage = this[kExecuteMessage] || {
306
+ if (!apiMessage) apiMessage = this[_constants.K_EXECUTE_MESSAGE] || {
243
307
  content: this._createMessage()
244
308
  };
245
309
  const content = apiMessage.content;
@@ -247,7 +311,7 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
247
311
  return this._getProcessApi(apiMessage);
248
312
  }
249
313
  const api = (0, _Api.DefinitionApi)(this.broker, apiMessage);
250
- const postponed = this[kProcesses].postponed;
314
+ const postponed = this[K_PROCESSES].postponed;
251
315
  const self = this;
252
316
  api.getExecuting = function getExecuting() {
253
317
  const apis = [];
@@ -259,19 +323,27 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
259
323
  };
260
324
  return api;
261
325
  };
326
+
327
+ /**
328
+ * List currently postponed activities across every running process.
329
+ * @param {import('#types').filterPostponed} [filterFn]
330
+ * @returns {import('#types').IApi<import('#types').Activity>}
331
+ */
262
332
  DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
263
333
  let result = [];
264
- for (const bp of this[kProcesses].running) {
334
+ for (const bp of this[K_PROCESSES].running) {
265
335
  result = result.concat(bp.getPostponed(...args));
266
336
  }
267
337
  return result;
268
338
  };
339
+
340
+ /** @internal */
269
341
  DefinitionExecution.prototype._start = function start() {
270
342
  const {
271
343
  ids,
272
344
  executable,
273
345
  postponed
274
- } = this[kProcesses];
346
+ } = this[K_PROCESSES];
275
347
  if (!ids.size) {
276
348
  return this._complete('completed');
277
349
  }
@@ -280,25 +352,29 @@ DefinitionExecution.prototype._start = function start() {
280
352
  error: new Error('No executable process')
281
353
  });
282
354
  }
283
- this[kStatus] = 'start';
355
+ this[_constants.K_STATUS] = 'start';
284
356
  for (const bp of executable) bp.init();
285
357
  for (const bp of executable) bp.run();
286
358
  postponed.clear();
287
- this[kProcessesQ].assertConsumer(this[kMessageHandlers].onProcessMessage, {
359
+ this[K_PROCESSES_Q].assertConsumer(this[_constants.K_MESSAGE_HANDLERS].onProcessMessage, {
288
360
  prefetch: 1000,
289
361
  consumerTag: `_definition-activity-${this.executionId}`
290
362
  });
291
363
  };
364
+
365
+ /** @internal */
292
366
  DefinitionExecution.prototype._activate = function activate(processList) {
293
- this.broker.subscribeTmp('api', '#', this[kMessageHandlers].onApiMessage, {
367
+ this.broker.subscribeTmp('api', '#', this[_constants.K_MESSAGE_HANDLERS].onApiMessage, {
294
368
  noAck: true,
295
369
  consumerTag: '_definition-api-consumer'
296
370
  });
297
371
  for (const bp of processList) this._activateProcess(bp);
298
- this[kActivated] = true;
372
+ this[_constants.K_ACTIVATED] = true;
299
373
  };
374
+
375
+ /** @internal */
300
376
  DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
301
- const handlers = this[kMessageHandlers];
377
+ const handlers = this[_constants.K_MESSAGE_HANDLERS];
302
378
  const broker = bp.broker;
303
379
  broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
304
380
  noAck: true,
@@ -334,11 +410,13 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
334
410
  priority: 100
335
411
  });
336
412
  };
413
+
414
+ /** @internal */
337
415
  DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey, originalMessage) {
338
416
  const message = (0, _messageHelper.cloneMessage)(originalMessage);
339
417
  const content = message.content;
340
418
  const parent = content.parent = content.parent || {};
341
- const isDirectChild = this[kProcesses].ids.has(content.id);
419
+ const isDirectChild = this[K_PROCESSES].ids.has(content.id);
342
420
  if (isDirectChild) {
343
421
  parent.executionId = this.executionId;
344
422
  } else {
@@ -349,14 +427,18 @@ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey,
349
427
  mandatory: false
350
428
  });
351
429
  if (!isDirectChild) return;
352
- this[kProcessesQ].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), message.properties);
430
+ this[K_PROCESSES_Q].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), message.properties);
353
431
  };
432
+
433
+ /** @internal */
354
434
  DefinitionExecution.prototype._deactivate = function deactivate() {
355
435
  this.broker.cancel('_definition-api-consumer');
356
436
  this.broker.cancel(`_definition-activity-${this.executionId}`);
357
- for (const bp of this[kProcesses].running) this._deactivateProcess(bp);
358
- this[kActivated] = false;
437
+ for (const bp of this[K_PROCESSES].running) this._deactivateProcess(bp);
438
+ this[_constants.K_ACTIVATED] = false;
359
439
  };
440
+
441
+ /** @internal */
360
442
  DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp) {
361
443
  bp.broker.cancel('_definition-outbound-message-consumer');
362
444
  bp.broker.cancel('_definition-activity-consumer');
@@ -364,6 +446,8 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
364
446
  bp.broker.cancel('_definition-call-consumer');
365
447
  bp.broker.cancel('_definition-call-cancel-consumer');
366
448
  };
449
+
450
+ /** @internal */
367
451
  DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(routingKey, message) {
368
452
  const content = message.content;
369
453
  const isRedelivered = message.fields.redelivered;
@@ -386,7 +470,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
386
470
  this._stateChangeMessage(message, true);
387
471
  switch (routingKey) {
388
472
  case 'process.enter':
389
- this[kStatus] = 'executing';
473
+ this[_constants.K_STATUS] = 'executing';
390
474
  break;
391
475
  case 'process.discarded':
392
476
  {
@@ -431,7 +515,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
431
515
  type: 'error'
432
516
  });
433
517
  } else {
434
- for (const bp of new Set(this[kProcesses].running)) {
518
+ for (const bp of new Set(this[K_PROCESSES].running)) {
435
519
  if (bp.id !== childId) bp.stop();
436
520
  }
437
521
  Object.assign(this.environment.output, content.output);
@@ -443,9 +527,11 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
443
527
  }
444
528
  }
445
529
  };
530
+
531
+ /** @internal */
446
532
  DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
447
533
  let previousMsg;
448
- const postponed = this[kProcesses].postponed;
534
+ const postponed = this[K_PROCESSES].postponed;
449
535
  for (const msg of postponed) {
450
536
  if (msg.content.executionId === message.content.executionId) {
451
537
  previousMsg = msg;
@@ -456,6 +542,8 @@ DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(
456
542
  if (previousMsg) previousMsg.ack();
457
543
  if (postponeMessage) postponed.add(message);
458
544
  };
545
+
546
+ /** @internal */
459
547
  DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(message) {
460
548
  this._stateChangeMessage(message, false);
461
549
  if (message.fields.redelivered) return message.ack();
@@ -475,49 +563,55 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
475
563
  this._complete('completed');
476
564
  }
477
565
  };
566
+
567
+ /** @internal */
478
568
  DefinitionExecution.prototype._onStopped = function onStopped(message) {
479
- const running = this[kProcesses].running;
569
+ const running = this[K_PROCESSES].running;
480
570
  this._debug(`stop definition execution (stop process executions ${running.size})`);
481
- this[kProcessesQ].close();
571
+ this[K_PROCESSES_Q].close();
482
572
  for (const bp of new Set(running)) bp.stop();
483
573
  this._deactivate();
484
- this[kStopped] = true;
485
- return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
574
+ this[_constants.K_STOPPED] = true;
575
+ return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
486
576
  ...message.content
487
577
  }), {
488
578
  type: 'stopped',
489
579
  persistent: false
490
580
  });
491
581
  };
582
+
583
+ /** @internal */
492
584
  DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
493
585
  const messageType = message.properties.type;
494
586
  const delegate = message.properties.delegate;
495
587
  if (delegate && this.id === message.content.id) {
496
- const referenceId = (0, _getPropertyValue.default)(message, 'content.message.id');
588
+ const referenceId = message.content.message?.id;
497
589
  this._startProcessesByMessage({
498
590
  referenceId,
499
591
  referenceType: messageType
500
592
  });
501
593
  }
502
594
  if (delegate) {
503
- for (const bp of new Set(this[kProcesses].running)) {
595
+ for (const bp of new Set(this[K_PROCESSES].running)) {
504
596
  bp.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
505
597
  }
506
598
  }
507
599
  if (this.executionId !== message.content.executionId) return;
508
600
  if (messageType === 'stop') {
509
- this[kProcessesQ].queueMessage({
601
+ this[K_PROCESSES_Q].queueMessage({
510
602
  routingKey: 'execution.stop'
511
603
  }, (0, _messageHelper.cloneContent)(message.content), {
512
604
  persistent: false
513
605
  });
514
606
  }
515
607
  };
608
+
609
+ /** @internal */
516
610
  DefinitionExecution.prototype._startProcessesByMessage = function startProcessesByMessage(reference) {
517
611
  const {
518
612
  processes: bps,
519
613
  running
520
- } = this[kProcesses];
614
+ } = this[K_PROCESSES];
521
615
  if (bps.length < 2) return;
522
616
  for (const bp of bps) {
523
617
  if (bp.isExecutable) continue;
@@ -540,6 +634,8 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
540
634
  if (reference.referenceType === 'message') return;
541
635
  }
542
636
  };
637
+
638
+ /** @internal */
543
639
  DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(routingKey, message) {
544
640
  const content = message.content;
545
641
  const {
@@ -561,11 +657,13 @@ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(ro
561
657
  if (found) return;
562
658
  targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
563
659
  this._activateProcess(targetProcess);
564
- this[kProcesses].running.add(targetProcess);
660
+ this[K_PROCESSES].running.add(targetProcess);
565
661
  targetProcess.init();
566
662
  targetProcess.run();
567
663
  targetProcess.sendMessage(message);
568
664
  };
665
+
666
+ /** @internal */
569
667
  DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingKey, message) {
570
668
  const content = message.content;
571
669
  const {
@@ -593,12 +691,14 @@ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingK
593
691
  if (!targetProcess) return;
594
692
  this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
595
693
  this._activateProcess(targetProcess);
596
- this[kProcesses].running.add(targetProcess);
694
+ this[K_PROCESSES].running.add(targetProcess);
597
695
  targetProcess.init(bpExecutionId);
598
696
  targetProcess.run({
599
697
  inbound: [(0, _messageHelper.cloneContent)(content)]
600
698
  });
601
699
  };
700
+
701
+ /** @internal */
602
702
  DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
603
703
  const {
604
704
  calledElement,
@@ -622,6 +722,8 @@ DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActiv
622
722
  targetProcess.getApi().discard();
623
723
  }
624
724
  };
725
+
726
+ /** @internal */
625
727
  DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
626
728
  const content = executeMessage.content;
627
729
  const messageType = executeMessage.properties.type;
@@ -648,19 +750,23 @@ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(ro
648
750
  type: messageType
649
751
  });
650
752
  };
753
+
754
+ /** @internal */
651
755
  DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
652
756
  const bp = this.getProcessByExecutionId(processExecutionId);
653
- if (bp) this[kProcesses].running.delete(bp);
757
+ if (bp) this[K_PROCESSES].running.delete(bp);
654
758
  return bp;
655
759
  };
760
+
761
+ /** @internal */
656
762
  DefinitionExecution.prototype._complete = function complete(completionType, content, options) {
657
763
  this._deactivate();
658
- const stateMessage = this[kExecuteMessage];
764
+ const stateMessage = this[_constants.K_EXECUTE_MESSAGE];
659
765
  this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
660
766
  if (!content) content = this._createMessage();
661
- this[kCompleted] = true;
662
- this[kStatus] = completionType;
663
- this.broker.deleteQueue(this[kProcessesQ].name);
767
+ this[_constants.K_COMPLETED] = true;
768
+ this[_constants.K_STATUS] = completionType;
769
+ this.broker.deleteQueue(this[K_PROCESSES_Q].name);
664
770
  return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, {
665
771
  ...stateMessage.content,
666
772
  output: {
@@ -674,15 +780,19 @@ DefinitionExecution.prototype._complete = function complete(completionType, cont
674
780
  ...options
675
781
  });
676
782
  };
783
+
784
+ /** @internal */
677
785
  DefinitionExecution.prototype._createMessage = function createMessage(content) {
678
786
  return {
679
787
  id: this.id,
680
788
  type: this.type,
681
789
  executionId: this.executionId,
682
- status: this[kStatus],
790
+ status: this[_constants.K_STATUS],
683
791
  ...content
684
792
  };
685
793
  };
794
+
795
+ /** @internal */
686
796
  DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
687
797
  const content = message.content;
688
798
  let api = this._getProcessApiByExecutionId(content.executionId, message);
@@ -696,11 +806,15 @@ DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
696
806
  if (api) return api;
697
807
  }
698
808
  };
809
+
810
+ /** @internal */
699
811
  DefinitionExecution.prototype._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
700
812
  const processInstance = this.getProcessByExecutionId(parentExecutionId);
701
813
  if (!processInstance) return;
702
814
  return processInstance.getApi(message);
703
815
  };
816
+
817
+ /** @internal */
704
818
  DefinitionExecution.prototype._debug = function debug(logMessage) {
705
- this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
819
+ this[K_PARENT].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
706
820
  };
@@ -3,7 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = BpmnErrorActivity;
6
+ exports.BpmnErrorActivity = BpmnErrorActivity;
7
+ /**
8
+ * BPMN error.
9
+ * @param {import('moddle-context-serializer').SerializableElement} errorDef
10
+ * @param {import('#types').ContextInstance} context
11
+ */
7
12
  function BpmnErrorActivity(errorDef, context) {
8
13
  const {
9
14
  id,
@@ -21,11 +26,17 @@ function BpmnErrorActivity(errorDef, context) {
21
26
  errorCode: behaviour.errorCode,
22
27
  resolve
23
28
  };
29
+
30
+ /**
31
+ * @param {import('#types').ElementBrokerMessage} executionMessage
32
+ * @param {Error} [error]
33
+ */
24
34
  function resolve(executionMessage, error) {
25
35
  const resolveCtx = {
26
36
  ...executionMessage,
27
37
  error
28
38
  };
39
+ /** @type {{ id?: string; type?: string; messageType: string; name: string; code: string | undefined; inner?: Error }} */
29
40
  const result = {
30
41
  id,
31
42
  type,