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
@@ -1,44 +1,51 @@
1
- import ProcessExecution from './ProcessExecution.js';
1
+ import { ProcessExecution } from './ProcessExecution.js';
2
2
  import { getUniqueId } from '../shared.js';
3
3
  import { ProcessApi } from '../Api.js';
4
4
  import { ProcessBroker } from '../EventBroker.js';
5
5
  import { cloneMessage, cloneContent, cloneParent } from '../messageHelper.js';
6
6
  import { makeErrorFromMessage } from '../error/Errors.js';
7
-
8
- const kConsuming = Symbol.for('consuming');
9
- const kCounters = Symbol.for('counters');
10
- const kExec = Symbol.for('execution');
11
- const kExecuteMessage = Symbol.for('executeMessage');
12
- const kExtensions = Symbol.for('extensions');
13
- const kLanes = Symbol.for('lanes');
14
- const kMessageHandlers = Symbol.for('messageHandlers');
15
- const kStateMessage = Symbol.for('stateMessage');
16
- const kStatus = Symbol.for('status');
17
- const kStopped = Symbol.for('stopped');
18
-
19
- export default Process;
20
-
7
+ import {
8
+ K_CONSUMING,
9
+ K_COUNTERS,
10
+ K_EXECUTE_MESSAGE,
11
+ K_EXECUTION,
12
+ K_EXTENSIONS,
13
+ K_MESSAGE_HANDLERS,
14
+ K_STATE_MESSAGE,
15
+ K_STATUS,
16
+ K_STOPPED,
17
+ } from '../constants.js';
18
+
19
+ const K_LANES = Symbol.for('lanes');
20
+
21
+ /**
22
+ * Owns one `<bpmn:process>`. Wraps the structural definition and orchestrates flow traversal,
23
+ * joins, and parallel activation through ProcessExecution.
24
+ * @param {import('moddle-context-serializer').Process} processDef
25
+ * @param {import('#types').ContextInstance} context
26
+ */
21
27
  export function Process(processDef, context) {
22
28
  const { id, type = 'process', name, parent, behaviour = {} } = processDef;
23
29
  this.id = id;
24
30
  this.type = type;
25
31
  this.name = name;
32
+ /** @type {import('#types').ElementParent} */
26
33
  this.parent = parent ? cloneParent(parent) : {};
34
+ /** @type {import('moddle-context-serializer').Process['behaviour']} */
27
35
  this.behaviour = behaviour;
28
36
 
29
- const { isExecutable } = behaviour;
30
- this.isExecutable = isExecutable;
37
+ this.isExecutable = behaviour.isExecutable;
31
38
 
32
39
  const environment = (this.environment = context.environment);
33
40
  this.context = context;
34
- this[kCounters] = {
41
+ this[K_COUNTERS] = {
35
42
  completed: 0,
36
43
  discarded: 0,
37
44
  };
38
- this[kConsuming] = false;
39
- this[kExec] = new Map();
40
- this[kStatus] = undefined;
41
- this[kStopped] = false;
45
+ this[K_CONSUMING] = false;
46
+ this[K_EXECUTION] = new Map();
47
+ this[K_STATUS] = undefined;
48
+ this[K_STOPPED] = false;
42
49
 
43
50
  const { broker, on, once, waitFor } = ProcessBroker(this);
44
51
  this.broker = broker;
@@ -46,7 +53,7 @@ export function Process(processDef, context) {
46
53
  this.once = once;
47
54
  this.waitFor = waitFor;
48
55
 
49
- this[kMessageHandlers] = {
56
+ this[K_MESSAGE_HANDLERS] = {
50
57
  onApiMessage: this._onApiMessage.bind(this),
51
58
  onRunMessage: this._onRunMessage.bind(this),
52
59
  onExecutionMessage: this._onExecutionMessage.bind(this),
@@ -55,73 +62,82 @@ export function Process(processDef, context) {
55
62
  this.logger = environment.Logger(type.toLowerCase());
56
63
 
57
64
  if (behaviour.lanes) {
58
- this[kLanes] = behaviour.lanes.map((lane) => new lane.Behaviour(this, lane));
65
+ this[K_LANES] = behaviour.lanes.map((lane) => new lane.Behaviour(this, lane));
59
66
  }
60
- this[kExtensions] = context.loadExtensions(this);
67
+ this[K_EXTENSIONS] = context.loadExtensions(this);
61
68
  }
62
69
 
63
70
  Object.defineProperties(Process.prototype, {
64
71
  counters: {
65
72
  get() {
66
- return { ...this[kCounters] };
73
+ return { ...this[K_COUNTERS] };
67
74
  },
68
75
  },
69
76
  lanes: {
70
77
  get() {
71
- return this[kLanes]?.slice();
78
+ return this[K_LANES]?.slice();
72
79
  },
73
80
  },
74
81
  extensions: {
75
82
  get() {
76
- return this[kExtensions];
83
+ return this[K_EXTENSIONS];
77
84
  },
78
85
  },
79
86
  stopped: {
80
87
  get() {
81
- return this[kStopped];
88
+ return this[K_STOPPED];
82
89
  },
83
90
  },
84
91
  isRunning: {
85
92
  get() {
86
- if (!this[kConsuming]) return false;
93
+ if (!this[K_CONSUMING]) return false;
87
94
  return !!this.status;
88
95
  },
89
96
  },
90
97
  executionId: {
91
98
  get() {
92
- const exec = this[kExec];
99
+ const exec = this[K_EXECUTION];
93
100
  return exec.get('executionId') || exec.get('initExecutionId');
94
101
  },
95
102
  },
96
103
  execution: {
97
104
  get() {
98
- return this[kExec].get('execution');
105
+ return this[K_EXECUTION].get('execution');
99
106
  },
100
107
  },
101
108
  status: {
102
109
  get() {
103
- return this[kStatus];
110
+ return this[K_STATUS];
104
111
  },
105
112
  },
106
113
  activityStatus: {
107
114
  get() {
108
- return this[kExec].get('execution')?.activityStatus || 'idle';
115
+ return this[K_EXECUTION].get('execution')?.activityStatus || 'idle';
109
116
  },
110
117
  },
111
118
  });
112
119
 
120
+ /**
121
+ * Allocate an executionId and emit init event without starting the run.
122
+ * @param {string} [useAsExecutionId] Override for the generated execution id
123
+ */
113
124
  Process.prototype.init = function init(useAsExecutionId) {
114
125
  const initExecutionId = useAsExecutionId || getUniqueId(this.id);
115
- this[kExec].set('initExecutionId', initExecutionId);
126
+ this[K_EXECUTION].set('initExecutionId', initExecutionId);
116
127
 
117
128
  this._debug(`initialized with executionId <${initExecutionId}>`);
118
129
  this._publishEvent('init', this._createMessage({ executionId: initExecutionId }));
119
130
  };
120
131
 
132
+ /**
133
+ * Start running the process by publishing run.enter, run.start, and run.execute.
134
+ * @param {Record<string, any>} [runContent] Optional content merged into the run message
135
+ * @throws {Error} when the process is already running
136
+ */
121
137
  Process.prototype.run = function run(runContent) {
122
138
  if (this.isRunning) throw new Error(`process <${this.id}> is already running`);
123
139
 
124
- const exec = this[kExec];
140
+ const exec = this[K_EXECUTION];
125
141
  const executionId = exec.get('initExecutionId') || getUniqueId(this.id);
126
142
  exec.delete('initExecutionId');
127
143
  exec.set('executionId', executionId);
@@ -136,11 +152,16 @@ Process.prototype.run = function run(runContent) {
136
152
  this._activateRunConsumers();
137
153
  };
138
154
 
155
+ /**
156
+ * Resume after recover by republishing the last run message.
157
+ * @returns {this}
158
+ * @throws {Error} when called on a running process
159
+ */
139
160
  Process.prototype.resume = function resume() {
140
161
  if (this.isRunning) throw new Error(`cannot resume running process <${this.id}>`);
141
162
  if (!this.status) return this;
142
163
 
143
- this[kStopped] = false;
164
+ this[K_STOPPED] = false;
144
165
 
145
166
  const content = this._createMessage();
146
167
  this.broker.publish('run', 'run.resume', content, { persistent: false });
@@ -148,6 +169,10 @@ Process.prototype.resume = function resume() {
148
169
  return this;
149
170
  };
150
171
 
172
+ /**
173
+ * Snapshot process state for recover.
174
+ * @returns {import('#types').ProcessState}
175
+ */
151
176
  Process.prototype.getState = function getState() {
152
177
  return {
153
178
  id: this.id,
@@ -162,15 +187,21 @@ Process.prototype.getState = function getState() {
162
187
  };
163
188
  };
164
189
 
190
+ /**
191
+ * Restore process state captured by getState.
192
+ * @param {import('#types').ProcessState} [state]
193
+ * @returns {this}
194
+ * @throws {Error} when called on a running process
195
+ */
165
196
  Process.prototype.recover = function recover(state) {
166
197
  if (this.isRunning) throw new Error(`cannot recover running process <${this.id}>`);
167
198
  if (!state) return this;
168
199
 
169
- this[kStopped] = !!state.stopped;
170
- this[kStatus] = state.status;
171
- const exec = this[kExec];
200
+ this[K_STOPPED] = !!state.stopped;
201
+ this[K_STATUS] = state.status;
202
+ const exec = this[K_EXECUTION];
172
203
  exec.set('executionId', state.executionId);
173
- this[kCounters] = { ...this[kCounters], ...state.counters };
204
+ this[K_COUNTERS] = { ...this[K_COUNTERS], ...state.counters };
174
205
  this.environment.recover(state.environment);
175
206
 
176
207
  if (state.execution) {
@@ -182,46 +213,70 @@ Process.prototype.recover = function recover(state) {
182
213
  return this;
183
214
  };
184
215
 
216
+ /**
217
+ * Walk activity graph from the given start id, or every start activity when omitted.
218
+ * @param {string} [startId]
219
+ * @returns {import('#types').ShakeResult}
220
+ */
185
221
  Process.prototype.shake = function shake(startId) {
186
222
  if (this.isRunning) return this.execution.shake(startId);
187
223
  return new ProcessExecution(this, this.context).shake(startId);
188
224
  };
189
225
 
226
+ /**
227
+ * Stop the process if running.
228
+ */
190
229
  Process.prototype.stop = function stop() {
191
230
  if (!this.isRunning) return;
192
231
  this.getApi().stop();
193
232
  };
194
233
 
234
+ /**
235
+ * Resolve a Process Api wrapper, preferring the running execution if any.
236
+ * @param {import('#types').ElementBrokerMessage} [message]
237
+ * @returns {import('#types').IApi<this>}
238
+ */
195
239
  Process.prototype.getApi = function getApi(message) {
196
240
  const execution = this.execution;
197
241
  if (execution) return execution.getApi(message);
198
- return ProcessApi(this.broker, message || this[kStateMessage]);
242
+ return ProcessApi(this.broker, message || this[K_STATE_MESSAGE]);
199
243
  };
200
244
 
245
+ /**
246
+ * Send a delegated signal to the running process.
247
+ * @param {import('#types').signalMessage} [message]
248
+ */
201
249
  Process.prototype.signal = function signal(message) {
202
250
  return this.getApi().signal(message, { delegate: true });
203
251
  };
204
252
 
253
+ /**
254
+ * Cancel a running activity inside the process by delegated api message.
255
+ * @param {import('#types').signalMessage} [message]
256
+ */
205
257
  Process.prototype.cancelActivity = function cancelActivity(message) {
206
258
  return this.getApi().cancel(message, { delegate: true });
207
259
  };
208
260
 
261
+ /** @internal */
209
262
  Process.prototype._activateRunConsumers = function activateRunConsumers() {
210
- this[kConsuming] = true;
263
+ this[K_CONSUMING] = true;
211
264
  const broker = this.broker;
212
- const { onApiMessage, onRunMessage } = this[kMessageHandlers];
265
+ const { onApiMessage, onRunMessage } = this[K_MESSAGE_HANDLERS];
213
266
  broker.subscribeTmp('api', `process.*.${this.executionId}`, onApiMessage, { noAck: true, consumerTag: '_process-api', priority: 100 });
214
267
  broker.getQueue('run-q').assertConsumer(onRunMessage, { exclusive: true, consumerTag: '_process-run' });
215
268
  };
216
269
 
270
+ /** @internal */
217
271
  Process.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
218
272
  const broker = this.broker;
219
273
  broker.cancel('_process-api');
220
274
  broker.cancel('_process-run');
221
275
  broker.cancel('_process-execution');
222
- this[kConsuming] = false;
276
+ this[K_CONSUMING] = false;
223
277
  };
224
278
 
279
+ /** @internal */
225
280
  Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
226
281
  const { content, fields } = message;
227
282
 
@@ -229,37 +284,37 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
229
284
  return this._onResumeMessage(message);
230
285
  }
231
286
 
232
- this[kStateMessage] = message;
287
+ this[K_STATE_MESSAGE] = message;
233
288
 
234
289
  switch (routingKey) {
235
290
  case 'run.enter': {
236
291
  this._debug('enter');
237
292
 
238
- this[kStatus] = 'entered';
293
+ this[K_STATUS] = 'entered';
239
294
  if (fields.redelivered) break;
240
295
 
241
- this[kExec].delete('execution');
296
+ this[K_EXECUTION].delete('execution');
242
297
  this._publishEvent('enter', content);
243
298
 
244
299
  break;
245
300
  }
246
301
  case 'run.start': {
247
302
  this._debug('start');
248
- this[kStatus] = 'start';
303
+ this[K_STATUS] = 'start';
249
304
  this._publishEvent('start', content);
250
305
  break;
251
306
  }
252
307
  case 'run.execute': {
253
- const exec = this[kExec];
254
- this[kStatus] = 'executing';
308
+ const exec = this[K_EXECUTION];
309
+ this[K_STATUS] = 'executing';
255
310
  const executeMessage = cloneMessage(message);
256
311
  let execution = exec.get('execution');
257
312
  if (fields.redelivered && !execution) {
258
313
  executeMessage.fields.redelivered = undefined;
259
314
  }
260
- this[kExecuteMessage] = message;
315
+ this[K_EXECUTE_MESSAGE] = message;
261
316
 
262
- this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
317
+ this.broker.getQueue('execution-q').assertConsumer(this[K_MESSAGE_HANDLERS].onExecutionMessage, {
263
318
  exclusive: true,
264
319
  consumerTag: '_process-execution',
265
320
  });
@@ -269,7 +324,7 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
269
324
  return execution.execute(executeMessage);
270
325
  }
271
326
  case 'run.error': {
272
- this[kStatus] = 'errored';
327
+ this[K_STATUS] = 'errored';
273
328
  this._publishEvent(
274
329
  'error',
275
330
  cloneContent(content, {
@@ -279,12 +334,12 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
279
334
  break;
280
335
  }
281
336
  case 'run.end': {
282
- this[kStatus] = 'end';
337
+ this[K_STATUS] = 'end';
283
338
 
284
339
  if (fields.redelivered) break;
285
340
  this._debug('completed');
286
341
 
287
- this[kCounters].completed++;
342
+ this[K_COUNTERS].completed++;
288
343
 
289
344
  this.broker.publish('run', 'run.leave', content);
290
345
 
@@ -292,10 +347,10 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
292
347
  break;
293
348
  }
294
349
  case 'run.discarded': {
295
- this[kStatus] = 'discarded';
350
+ this[K_STATUS] = 'discarded';
296
351
  if (fields.redelivered) break;
297
352
 
298
- this[kCounters].discarded++;
353
+ this[K_COUNTERS].discarded++;
299
354
 
300
355
  this.broker.publish('run', 'run.leave', content);
301
356
 
@@ -303,7 +358,7 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
303
358
  break;
304
359
  }
305
360
  case 'run.leave': {
306
- this[kStatus] = undefined;
361
+ this[K_STATUS] = undefined;
307
362
  message.ack();
308
363
  this._deactivateRunConsumers();
309
364
  const { output, ...rest } = content;
@@ -315,10 +370,11 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
315
370
  message.ack();
316
371
  };
317
372
 
373
+ /** @internal */
318
374
  Process.prototype._onResumeMessage = function onResumeMessage(message) {
319
375
  message.ack();
320
376
 
321
- const stateMessage = this[kStateMessage];
377
+ const stateMessage = this[K_STATE_MESSAGE];
322
378
  switch (stateMessage.fields.routingKey) {
323
379
  case 'run.enter':
324
380
  case 'run.start':
@@ -337,6 +393,7 @@ Process.prototype._onResumeMessage = function onResumeMessage(message) {
337
393
  return this.broker.publish('run', stateMessage.fields.routingKey, cloneContent(stateMessage.content), stateMessage.properties);
338
394
  };
339
395
 
396
+ /** @internal */
340
397
  Process.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
341
398
  const content = message.content;
342
399
  const messageType = message.properties.type;
@@ -359,16 +416,22 @@ Process.prototype._onExecutionMessage = function onExecutionMessage(routingKey,
359
416
  }
360
417
  }
361
418
 
362
- const executeMessage = this[kExecuteMessage];
363
- this[kExecuteMessage] = null;
419
+ const executeMessage = this[K_EXECUTE_MESSAGE];
420
+ this[K_EXECUTE_MESSAGE] = null;
364
421
  executeMessage.ack();
365
422
  };
366
423
 
424
+ /** @internal */
367
425
  Process.prototype._publishEvent = function publishEvent(state, content) {
368
426
  const eventContent = this._createMessage({ ...content, state });
369
427
  this.broker.publish('event', `process.${state}`, eventContent, { type: state, mandatory: state === 'error' });
370
428
  };
371
429
 
430
+ /**
431
+ * Deliver a message to a target activity or start activity that references it.
432
+ * Starts the process if a target is found and the process is idle.
433
+ * @param {import('#types').ElementBrokerMessage} message
434
+ */
372
435
  Process.prototype.sendMessage = function sendMessage(message) {
373
436
  const messageContent = message?.content;
374
437
  if (!messageContent) return;
@@ -388,44 +451,60 @@ Process.prototype.sendMessage = function sendMessage(message) {
388
451
  this.getApi().sendApiMessage(message.properties.type || 'message', cloneContent(messageContent), { delegate: true });
389
452
  };
390
453
 
454
+ /**
455
+ * @param {string} childId
456
+ */
391
457
  Process.prototype.getActivityById = function getActivityById(childId) {
392
458
  const execution = this.execution;
393
459
  if (execution) return execution.getActivityById(childId);
394
460
  return this.context.getActivityById(childId);
395
461
  };
396
462
 
463
+ /**
464
+ * Get every activity in the process scope.
465
+ */
397
466
  Process.prototype.getActivities = function getActivities() {
398
467
  const execution = this.execution;
399
468
  if (execution) return execution.getActivities();
400
469
  return this.context.getActivities(this.id);
401
470
  };
402
471
 
472
+ /**
473
+ * Get start activities, optionally filtered by referenced event definition.
474
+ * @param {import('#types').startActivityFilterOptions} [filterOptions]
475
+ */
403
476
  Process.prototype.getStartActivities = function getStartActivities(filterOptions) {
404
477
  return this.context.getStartActivities(filterOptions, this.id);
405
478
  };
406
479
 
480
+ /**
481
+ * Get sequence flows in the process scope.
482
+ */
407
483
  Process.prototype.getSequenceFlows = function getSequenceFlows() {
408
484
  const execution = this.execution;
409
485
  if (execution) return execution.getSequenceFlows();
410
486
  return this.context.getSequenceFlows();
411
487
  };
412
488
 
489
+ /**
490
+ * @param {string} laneId
491
+ * @returns {import('./Lane.js').Lane | undefined}
492
+ */
413
493
  Process.prototype.getLaneById = function getLaneById(laneId) {
414
- const lanes = this[kLanes];
415
- if (!lanes) return;
416
- return lanes.find((lane) => lane.id === laneId);
494
+ return this[K_LANES]?.find((lane) => lane.id === laneId);
417
495
  };
418
496
 
497
+ /**
498
+ * List currently postponed activities as Api wrappers.
499
+ * @param {import('#types').filterPostponed} [filterFn]
500
+ */
419
501
  Process.prototype.getPostponed = function getPostponed(...args) {
420
- const execution = this.execution;
421
- if (!execution) return [];
422
- return execution.getPostponed(...args);
502
+ return this.execution?.getPostponed(...args) || [];
423
503
  };
424
504
 
505
+ /** @internal */
425
506
  Process.prototype._onApiMessage = function onApiMessage(routingKey, message) {
426
- const messageType = message.properties.type;
427
-
428
- switch (messageType) {
507
+ switch (message.properties.type) {
429
508
  case 'stop': {
430
509
  if (this.execution && !this.execution.completed) return;
431
510
  this._onStop();
@@ -434,12 +513,14 @@ Process.prototype._onApiMessage = function onApiMessage(routingKey, message) {
434
513
  }
435
514
  };
436
515
 
516
+ /** @internal */
437
517
  Process.prototype._onStop = function onStop() {
438
- this[kStopped] = true;
518
+ this[K_STOPPED] = true;
439
519
  this._deactivateRunConsumers();
440
520
  return this._publishEvent('stop');
441
521
  };
442
522
 
523
+ /** @internal */
443
524
  Process.prototype._createMessage = function createMessage(override) {
444
525
  return {
445
526
  id: this.id,
@@ -451,6 +532,7 @@ Process.prototype._createMessage = function createMessage(override) {
451
532
  };
452
533
  };
453
534
 
535
+ /** @internal */
454
536
  Process.prototype._debug = function debug(msg) {
455
537
  this.logger.debug(`<${this.id}> ${msg}`);
456
538
  };