bpmn-elements 17.3.0 → 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 +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 +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 +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 +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 +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 +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 +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 +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,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,40 @@ 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
  };
185
+
186
+ /**
187
+ * Restore execution state captured by getState. Reinstates running processes from the snapshot.
188
+ * @param {import('#types').DefinitionExecutionState} [state]
189
+ * @returns {this}
190
+ */
172
191
  DefinitionExecution.prototype.recover = function recover(state) {
173
192
  if (!state) return this;
174
193
  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;
194
+ this[_constants.K_STOPPED] = state.stopped;
195
+ this[_constants.K_COMPLETED] = state.completed;
196
+ this[_constants.K_STATUS] = state.status;
197
+ this._debug(`recover ${this[_constants.K_STATUS]} definition execution`);
198
+ const running = this[K_PROCESSES].running;
180
199
  running.clear();
181
200
  const ids = new Set();
182
201
  for (const bpState of state.processes) {
@@ -194,52 +213,96 @@ DefinitionExecution.prototype.recover = function recover(state) {
194
213
  }
195
214
  return this;
196
215
  };
216
+
217
+ /**
218
+ * Stop the running execution via the api.
219
+ */
197
220
  DefinitionExecution.prototype.stop = function stop() {
198
221
  this.getApi().stop();
199
222
  };
223
+
224
+ /**
225
+ * Get every process in the definition (running first, then any non-running by id).
226
+ * @returns {import('../process/Process.js').Process[]}
227
+ */
200
228
  DefinitionExecution.prototype.getProcesses = function getProcesses() {
201
229
  const {
202
230
  running,
203
231
  processes
204
- } = this[kProcesses];
232
+ } = this[K_PROCESSES];
205
233
  const result = [...running];
206
234
  for (const bp of processes) {
207
235
  if (!result.find(runningBp => bp.id === runningBp.id)) result.push(bp);
208
236
  }
209
237
  return result;
210
238
  };
239
+
240
+ /**
241
+ * @param {string} processId
242
+ */
211
243
  DefinitionExecution.prototype.getProcessById = function getProcessById(processId) {
212
244
  return this.getProcesses().find(bp => bp.id === processId);
213
245
  };
246
+
247
+ /**
248
+ * Get every process matching the given id (call activities can spawn duplicates).
249
+ * @param {string} processId
250
+ */
214
251
  DefinitionExecution.prototype.getProcessesById = function getProcessesById(processId) {
215
252
  return this.getProcesses().filter(bp => bp.id === processId);
216
253
  };
254
+
255
+ /**
256
+ * @param {string} processExecutionId
257
+ * @returns {import('../process/Process.js').Process | undefined}
258
+ */
217
259
  DefinitionExecution.prototype.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
218
- for (const bp of this[kProcesses].running) {
260
+ for (const bp of this[K_PROCESSES].running) {
219
261
  if (bp.executionId === processExecutionId) return bp;
220
262
  }
221
263
  };
264
+
265
+ /**
266
+ * Get processes that have an executionId, i.e. are currently running.
267
+ * @returns {import('../process/Process.js').Process[]}
268
+ */
222
269
  DefinitionExecution.prototype.getRunningProcesses = function getRunningProcesses() {
223
- return [...this[kProcesses].running].filter(bp => bp.executionId);
270
+ return [...this[K_PROCESSES].running].filter(bp => bp.executionId);
224
271
  };
272
+
273
+ /**
274
+ * Get processes flagged executable in the definition.
275
+ * @returns {import('../process/Process.js').Process[]}
276
+ */
225
277
  DefinitionExecution.prototype.getExecutableProcesses = function getExecutableProcesses() {
226
- return [...this[kProcesses].executable];
278
+ return [...this[K_PROCESSES].executable];
227
279
  };
280
+
281
+ /**
282
+ * Snapshot execution state for recover.
283
+ * @returns {import('#types').DefinitionExecutionState}
284
+ */
228
285
  DefinitionExecution.prototype.getState = function getState() {
229
286
  const processes = [];
230
- for (const bp of this[kProcesses].running) {
287
+ for (const bp of this[K_PROCESSES].running) {
231
288
  processes.push(bp.getState());
232
289
  }
233
290
  return {
234
291
  executionId: this.executionId,
235
- stopped: this[kStopped],
236
- completed: this[kCompleted],
237
- status: this[kStatus],
292
+ stopped: this[_constants.K_STOPPED],
293
+ completed: this[_constants.K_COMPLETED],
294
+ status: this[_constants.K_STATUS],
238
295
  processes
239
296
  };
240
297
  };
298
+
299
+ /**
300
+ * Resolve a Definition Api or, when the message belongs to a child process, its process Api.
301
+ * @param {import('#types').ElementBrokerMessage} [apiMessage]
302
+ * @returns {import('#types').IApi<import('./Definition.js').Definition>}
303
+ */
241
304
  DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
242
- if (!apiMessage) apiMessage = this[kExecuteMessage] || {
305
+ if (!apiMessage) apiMessage = this[_constants.K_EXECUTE_MESSAGE] || {
243
306
  content: this._createMessage()
244
307
  };
245
308
  const content = apiMessage.content;
@@ -247,7 +310,7 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
247
310
  return this._getProcessApi(apiMessage);
248
311
  }
249
312
  const api = (0, _Api.DefinitionApi)(this.broker, apiMessage);
250
- const postponed = this[kProcesses].postponed;
313
+ const postponed = this[K_PROCESSES].postponed;
251
314
  const self = this;
252
315
  api.getExecuting = function getExecuting() {
253
316
  const apis = [];
@@ -259,19 +322,27 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
259
322
  };
260
323
  return api;
261
324
  };
325
+
326
+ /**
327
+ * List currently postponed activities across every running process.
328
+ * @param {import('#types').filterPostponed} [filterFn]
329
+ * @returns {import('#types').IApi<import('#types').Activity>}
330
+ */
262
331
  DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
263
332
  let result = [];
264
- for (const bp of this[kProcesses].running) {
333
+ for (const bp of this[K_PROCESSES].running) {
265
334
  result = result.concat(bp.getPostponed(...args));
266
335
  }
267
336
  return result;
268
337
  };
338
+
339
+ /** @internal */
269
340
  DefinitionExecution.prototype._start = function start() {
270
341
  const {
271
342
  ids,
272
343
  executable,
273
344
  postponed
274
- } = this[kProcesses];
345
+ } = this[K_PROCESSES];
275
346
  if (!ids.size) {
276
347
  return this._complete('completed');
277
348
  }
@@ -280,25 +351,29 @@ DefinitionExecution.prototype._start = function start() {
280
351
  error: new Error('No executable process')
281
352
  });
282
353
  }
283
- this[kStatus] = 'start';
354
+ this[_constants.K_STATUS] = 'start';
284
355
  for (const bp of executable) bp.init();
285
356
  for (const bp of executable) bp.run();
286
357
  postponed.clear();
287
- this[kProcessesQ].assertConsumer(this[kMessageHandlers].onProcessMessage, {
358
+ this[K_PROCESSES_Q].assertConsumer(this[_constants.K_MESSAGE_HANDLERS].onProcessMessage, {
288
359
  prefetch: 1000,
289
360
  consumerTag: `_definition-activity-${this.executionId}`
290
361
  });
291
362
  };
363
+
364
+ /** @internal */
292
365
  DefinitionExecution.prototype._activate = function activate(processList) {
293
- this.broker.subscribeTmp('api', '#', this[kMessageHandlers].onApiMessage, {
366
+ this.broker.subscribeTmp('api', '#', this[_constants.K_MESSAGE_HANDLERS].onApiMessage, {
294
367
  noAck: true,
295
368
  consumerTag: '_definition-api-consumer'
296
369
  });
297
370
  for (const bp of processList) this._activateProcess(bp);
298
- this[kActivated] = true;
371
+ this[_constants.K_ACTIVATED] = true;
299
372
  };
373
+
374
+ /** @internal */
300
375
  DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
301
- const handlers = this[kMessageHandlers];
376
+ const handlers = this[_constants.K_MESSAGE_HANDLERS];
302
377
  const broker = bp.broker;
303
378
  broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
304
379
  noAck: true,
@@ -334,11 +409,13 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
334
409
  priority: 100
335
410
  });
336
411
  };
412
+
413
+ /** @internal */
337
414
  DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey, originalMessage) {
338
415
  const message = (0, _messageHelper.cloneMessage)(originalMessage);
339
416
  const content = message.content;
340
417
  const parent = content.parent = content.parent || {};
341
- const isDirectChild = this[kProcesses].ids.has(content.id);
418
+ const isDirectChild = this[K_PROCESSES].ids.has(content.id);
342
419
  if (isDirectChild) {
343
420
  parent.executionId = this.executionId;
344
421
  } else {
@@ -349,14 +426,18 @@ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey,
349
426
  mandatory: false
350
427
  });
351
428
  if (!isDirectChild) return;
352
- this[kProcessesQ].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), message.properties);
429
+ this[K_PROCESSES_Q].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), message.properties);
353
430
  };
431
+
432
+ /** @internal */
354
433
  DefinitionExecution.prototype._deactivate = function deactivate() {
355
434
  this.broker.cancel('_definition-api-consumer');
356
435
  this.broker.cancel(`_definition-activity-${this.executionId}`);
357
- for (const bp of this[kProcesses].running) this._deactivateProcess(bp);
358
- this[kActivated] = false;
436
+ for (const bp of this[K_PROCESSES].running) this._deactivateProcess(bp);
437
+ this[_constants.K_ACTIVATED] = false;
359
438
  };
439
+
440
+ /** @internal */
360
441
  DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp) {
361
442
  bp.broker.cancel('_definition-outbound-message-consumer');
362
443
  bp.broker.cancel('_definition-activity-consumer');
@@ -364,6 +445,8 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
364
445
  bp.broker.cancel('_definition-call-consumer');
365
446
  bp.broker.cancel('_definition-call-cancel-consumer');
366
447
  };
448
+
449
+ /** @internal */
367
450
  DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(routingKey, message) {
368
451
  const content = message.content;
369
452
  const isRedelivered = message.fields.redelivered;
@@ -386,7 +469,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
386
469
  this._stateChangeMessage(message, true);
387
470
  switch (routingKey) {
388
471
  case 'process.enter':
389
- this[kStatus] = 'executing';
472
+ this[_constants.K_STATUS] = 'executing';
390
473
  break;
391
474
  case 'process.discarded':
392
475
  {
@@ -431,7 +514,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
431
514
  type: 'error'
432
515
  });
433
516
  } else {
434
- for (const bp of new Set(this[kProcesses].running)) {
517
+ for (const bp of new Set(this[K_PROCESSES].running)) {
435
518
  if (bp.id !== childId) bp.stop();
436
519
  }
437
520
  Object.assign(this.environment.output, content.output);
@@ -443,9 +526,11 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
443
526
  }
444
527
  }
445
528
  };
529
+
530
+ /** @internal */
446
531
  DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
447
532
  let previousMsg;
448
- const postponed = this[kProcesses].postponed;
533
+ const postponed = this[K_PROCESSES].postponed;
449
534
  for (const msg of postponed) {
450
535
  if (msg.content.executionId === message.content.executionId) {
451
536
  previousMsg = msg;
@@ -456,6 +541,8 @@ DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(
456
541
  if (previousMsg) previousMsg.ack();
457
542
  if (postponeMessage) postponed.add(message);
458
543
  };
544
+
545
+ /** @internal */
459
546
  DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(message) {
460
547
  this._stateChangeMessage(message, false);
461
548
  if (message.fields.redelivered) return message.ack();
@@ -475,49 +562,55 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
475
562
  this._complete('completed');
476
563
  }
477
564
  };
565
+
566
+ /** @internal */
478
567
  DefinitionExecution.prototype._onStopped = function onStopped(message) {
479
- const running = this[kProcesses].running;
568
+ const running = this[K_PROCESSES].running;
480
569
  this._debug(`stop definition execution (stop process executions ${running.size})`);
481
- this[kProcessesQ].close();
570
+ this[K_PROCESSES_Q].close();
482
571
  for (const bp of new Set(running)) bp.stop();
483
572
  this._deactivate();
484
- this[kStopped] = true;
485
- return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
573
+ this[_constants.K_STOPPED] = true;
574
+ return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
486
575
  ...message.content
487
576
  }), {
488
577
  type: 'stopped',
489
578
  persistent: false
490
579
  });
491
580
  };
581
+
582
+ /** @internal */
492
583
  DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
493
584
  const messageType = message.properties.type;
494
585
  const delegate = message.properties.delegate;
495
586
  if (delegate && this.id === message.content.id) {
496
- const referenceId = (0, _getPropertyValue.default)(message, 'content.message.id');
587
+ const referenceId = message.content.message?.id;
497
588
  this._startProcessesByMessage({
498
589
  referenceId,
499
590
  referenceType: messageType
500
591
  });
501
592
  }
502
593
  if (delegate) {
503
- for (const bp of new Set(this[kProcesses].running)) {
594
+ for (const bp of new Set(this[K_PROCESSES].running)) {
504
595
  bp.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
505
596
  }
506
597
  }
507
598
  if (this.executionId !== message.content.executionId) return;
508
599
  if (messageType === 'stop') {
509
- this[kProcessesQ].queueMessage({
600
+ this[K_PROCESSES_Q].queueMessage({
510
601
  routingKey: 'execution.stop'
511
602
  }, (0, _messageHelper.cloneContent)(message.content), {
512
603
  persistent: false
513
604
  });
514
605
  }
515
606
  };
607
+
608
+ /** @internal */
516
609
  DefinitionExecution.prototype._startProcessesByMessage = function startProcessesByMessage(reference) {
517
610
  const {
518
611
  processes: bps,
519
612
  running
520
- } = this[kProcesses];
613
+ } = this[K_PROCESSES];
521
614
  if (bps.length < 2) return;
522
615
  for (const bp of bps) {
523
616
  if (bp.isExecutable) continue;
@@ -540,6 +633,8 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
540
633
  if (reference.referenceType === 'message') return;
541
634
  }
542
635
  };
636
+
637
+ /** @internal */
543
638
  DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(routingKey, message) {
544
639
  const content = message.content;
545
640
  const {
@@ -561,11 +656,13 @@ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(ro
561
656
  if (found) return;
562
657
  targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
563
658
  this._activateProcess(targetProcess);
564
- this[kProcesses].running.add(targetProcess);
659
+ this[K_PROCESSES].running.add(targetProcess);
565
660
  targetProcess.init();
566
661
  targetProcess.run();
567
662
  targetProcess.sendMessage(message);
568
663
  };
664
+
665
+ /** @internal */
569
666
  DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingKey, message) {
570
667
  const content = message.content;
571
668
  const {
@@ -593,12 +690,14 @@ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingK
593
690
  if (!targetProcess) return;
594
691
  this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
595
692
  this._activateProcess(targetProcess);
596
- this[kProcesses].running.add(targetProcess);
693
+ this[K_PROCESSES].running.add(targetProcess);
597
694
  targetProcess.init(bpExecutionId);
598
695
  targetProcess.run({
599
696
  inbound: [(0, _messageHelper.cloneContent)(content)]
600
697
  });
601
698
  };
699
+
700
+ /** @internal */
602
701
  DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
603
702
  const {
604
703
  calledElement,
@@ -622,6 +721,8 @@ DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActiv
622
721
  targetProcess.getApi().discard();
623
722
  }
624
723
  };
724
+
725
+ /** @internal */
625
726
  DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
626
727
  const content = executeMessage.content;
627
728
  const messageType = executeMessage.properties.type;
@@ -648,19 +749,23 @@ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(ro
648
749
  type: messageType
649
750
  });
650
751
  };
752
+
753
+ /** @internal */
651
754
  DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
652
755
  const bp = this.getProcessByExecutionId(processExecutionId);
653
- if (bp) this[kProcesses].running.delete(bp);
756
+ if (bp) this[K_PROCESSES].running.delete(bp);
654
757
  return bp;
655
758
  };
759
+
760
+ /** @internal */
656
761
  DefinitionExecution.prototype._complete = function complete(completionType, content, options) {
657
762
  this._deactivate();
658
- const stateMessage = this[kExecuteMessage];
763
+ const stateMessage = this[_constants.K_EXECUTE_MESSAGE];
659
764
  this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
660
765
  if (!content) content = this._createMessage();
661
- this[kCompleted] = true;
662
- this[kStatus] = completionType;
663
- this.broker.deleteQueue(this[kProcessesQ].name);
766
+ this[_constants.K_COMPLETED] = true;
767
+ this[_constants.K_STATUS] = completionType;
768
+ this.broker.deleteQueue(this[K_PROCESSES_Q].name);
664
769
  return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, {
665
770
  ...stateMessage.content,
666
771
  output: {
@@ -674,15 +779,19 @@ DefinitionExecution.prototype._complete = function complete(completionType, cont
674
779
  ...options
675
780
  });
676
781
  };
782
+
783
+ /** @internal */
677
784
  DefinitionExecution.prototype._createMessage = function createMessage(content) {
678
785
  return {
679
786
  id: this.id,
680
787
  type: this.type,
681
788
  executionId: this.executionId,
682
- status: this[kStatus],
789
+ status: this[_constants.K_STATUS],
683
790
  ...content
684
791
  };
685
792
  };
793
+
794
+ /** @internal */
686
795
  DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
687
796
  const content = message.content;
688
797
  let api = this._getProcessApiByExecutionId(content.executionId, message);
@@ -696,11 +805,15 @@ DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
696
805
  if (api) return api;
697
806
  }
698
807
  };
808
+
809
+ /** @internal */
699
810
  DefinitionExecution.prototype._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
700
811
  const processInstance = this.getProcessByExecutionId(parentExecutionId);
701
812
  if (!processInstance) return;
702
813
  return processInstance.getApi(message);
703
814
  };
815
+
816
+ /** @internal */
704
817
  DefinitionExecution.prototype._debug = function debug(logMessage) {
705
- this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
818
+ this[K_PARENT].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
706
819
  };
@@ -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,