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
@@ -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,19 +187,26 @@ Process.prototype.getState = function getState() {
162
187
  };
163
188
  };
164
189
 
165
- Process.prototype.recover = function recover(state) {
190
+ /**
191
+ * Restore process state captured by getState.
192
+ * @param {import('#types').ProcessState} [state]
193
+ * @param {number} [recoveredVersion] State version
194
+ * @returns {this}
195
+ * @throws {Error} when called on a running process
196
+ */
197
+ Process.prototype.recover = function recover(state, recoveredVersion) {
166
198
  if (this.isRunning) throw new Error(`cannot recover running process <${this.id}>`);
167
199
  if (!state) return this;
168
200
 
169
- this[kStopped] = !!state.stopped;
170
- this[kStatus] = state.status;
171
- const exec = this[kExec];
201
+ this[K_STOPPED] = !!state.stopped;
202
+ this[K_STATUS] = state.status;
203
+ const exec = this[K_EXECUTION];
172
204
  exec.set('executionId', state.executionId);
173
- this[kCounters] = { ...this[kCounters], ...state.counters };
205
+ this[K_COUNTERS] = { ...this[K_COUNTERS], ...state.counters };
174
206
  this.environment.recover(state.environment);
175
207
 
176
208
  if (state.execution) {
177
- exec.set('execution', new ProcessExecution(this, this.context).recover(state.execution));
209
+ exec.set('execution', new ProcessExecution(this, this.context).recover(state.execution, recoveredVersion));
178
210
  }
179
211
 
180
212
  this.broker.recover(state.broker);
@@ -182,46 +214,70 @@ Process.prototype.recover = function recover(state) {
182
214
  return this;
183
215
  };
184
216
 
217
+ /**
218
+ * Walk activity graph from the given start id, or every start activity when omitted.
219
+ * @param {string} [startId]
220
+ * @returns {import('#types').ShakeResult}
221
+ */
185
222
  Process.prototype.shake = function shake(startId) {
186
223
  if (this.isRunning) return this.execution.shake(startId);
187
224
  return new ProcessExecution(this, this.context).shake(startId);
188
225
  };
189
226
 
227
+ /**
228
+ * Stop the process if running.
229
+ */
190
230
  Process.prototype.stop = function stop() {
191
231
  if (!this.isRunning) return;
192
232
  this.getApi().stop();
193
233
  };
194
234
 
235
+ /**
236
+ * Resolve a Process Api wrapper, preferring the running execution if any.
237
+ * @param {import('#types').ElementBrokerMessage} [message]
238
+ * @returns {import('#types').IApi<this>}
239
+ */
195
240
  Process.prototype.getApi = function getApi(message) {
196
241
  const execution = this.execution;
197
242
  if (execution) return execution.getApi(message);
198
- return ProcessApi(this.broker, message || this[kStateMessage]);
243
+ return ProcessApi(this.broker, message || this[K_STATE_MESSAGE]);
199
244
  };
200
245
 
246
+ /**
247
+ * Send a delegated signal to the running process.
248
+ * @param {import('#types').signalMessage} [message]
249
+ */
201
250
  Process.prototype.signal = function signal(message) {
202
251
  return this.getApi().signal(message, { delegate: true });
203
252
  };
204
253
 
254
+ /**
255
+ * Cancel a running activity inside the process by delegated api message.
256
+ * @param {import('#types').signalMessage} [message]
257
+ */
205
258
  Process.prototype.cancelActivity = function cancelActivity(message) {
206
259
  return this.getApi().cancel(message, { delegate: true });
207
260
  };
208
261
 
262
+ /** @internal */
209
263
  Process.prototype._activateRunConsumers = function activateRunConsumers() {
210
- this[kConsuming] = true;
264
+ this[K_CONSUMING] = true;
211
265
  const broker = this.broker;
212
- const { onApiMessage, onRunMessage } = this[kMessageHandlers];
266
+ const { onApiMessage, onRunMessage } = this[K_MESSAGE_HANDLERS];
213
267
  broker.subscribeTmp('api', `process.*.${this.executionId}`, onApiMessage, { noAck: true, consumerTag: '_process-api', priority: 100 });
214
268
  broker.getQueue('run-q').assertConsumer(onRunMessage, { exclusive: true, consumerTag: '_process-run' });
215
269
  };
216
270
 
271
+ /** @internal */
217
272
  Process.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
218
273
  const broker = this.broker;
219
274
  broker.cancel('_process-api');
220
275
  broker.cancel('_process-run');
221
276
  broker.cancel('_process-execution');
222
- this[kConsuming] = false;
277
+ this[K_CONSUMING] = false;
223
278
  };
224
279
 
280
+ /** @internal */
225
281
  Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
226
282
  const { content, fields } = message;
227
283
 
@@ -229,37 +285,37 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
229
285
  return this._onResumeMessage(message);
230
286
  }
231
287
 
232
- this[kStateMessage] = message;
288
+ this[K_STATE_MESSAGE] = message;
233
289
 
234
290
  switch (routingKey) {
235
291
  case 'run.enter': {
236
292
  this._debug('enter');
237
293
 
238
- this[kStatus] = 'entered';
294
+ this[K_STATUS] = 'entered';
239
295
  if (fields.redelivered) break;
240
296
 
241
- this[kExec].delete('execution');
297
+ this[K_EXECUTION].delete('execution');
242
298
  this._publishEvent('enter', content);
243
299
 
244
300
  break;
245
301
  }
246
302
  case 'run.start': {
247
303
  this._debug('start');
248
- this[kStatus] = 'start';
304
+ this[K_STATUS] = 'start';
249
305
  this._publishEvent('start', content);
250
306
  break;
251
307
  }
252
308
  case 'run.execute': {
253
- const exec = this[kExec];
254
- this[kStatus] = 'executing';
309
+ const exec = this[K_EXECUTION];
310
+ this[K_STATUS] = 'executing';
255
311
  const executeMessage = cloneMessage(message);
256
312
  let execution = exec.get('execution');
257
313
  if (fields.redelivered && !execution) {
258
314
  executeMessage.fields.redelivered = undefined;
259
315
  }
260
- this[kExecuteMessage] = message;
316
+ this[K_EXECUTE_MESSAGE] = message;
261
317
 
262
- this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
318
+ this.broker.getQueue('execution-q').assertConsumer(this[K_MESSAGE_HANDLERS].onExecutionMessage, {
263
319
  exclusive: true,
264
320
  consumerTag: '_process-execution',
265
321
  });
@@ -269,7 +325,7 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
269
325
  return execution.execute(executeMessage);
270
326
  }
271
327
  case 'run.error': {
272
- this[kStatus] = 'errored';
328
+ this[K_STATUS] = 'errored';
273
329
  this._publishEvent(
274
330
  'error',
275
331
  cloneContent(content, {
@@ -279,12 +335,12 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
279
335
  break;
280
336
  }
281
337
  case 'run.end': {
282
- this[kStatus] = 'end';
338
+ this[K_STATUS] = 'end';
283
339
 
284
340
  if (fields.redelivered) break;
285
341
  this._debug('completed');
286
342
 
287
- this[kCounters].completed++;
343
+ this[K_COUNTERS].completed++;
288
344
 
289
345
  this.broker.publish('run', 'run.leave', content);
290
346
 
@@ -292,10 +348,10 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
292
348
  break;
293
349
  }
294
350
  case 'run.discarded': {
295
- this[kStatus] = 'discarded';
351
+ this[K_STATUS] = 'discarded';
296
352
  if (fields.redelivered) break;
297
353
 
298
- this[kCounters].discarded++;
354
+ this[K_COUNTERS].discarded++;
299
355
 
300
356
  this.broker.publish('run', 'run.leave', content);
301
357
 
@@ -303,7 +359,7 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
303
359
  break;
304
360
  }
305
361
  case 'run.leave': {
306
- this[kStatus] = undefined;
362
+ this[K_STATUS] = undefined;
307
363
  message.ack();
308
364
  this._deactivateRunConsumers();
309
365
  const { output, ...rest } = content;
@@ -315,10 +371,11 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
315
371
  message.ack();
316
372
  };
317
373
 
374
+ /** @internal */
318
375
  Process.prototype._onResumeMessage = function onResumeMessage(message) {
319
376
  message.ack();
320
377
 
321
- const stateMessage = this[kStateMessage];
378
+ const stateMessage = this[K_STATE_MESSAGE];
322
379
  switch (stateMessage.fields.routingKey) {
323
380
  case 'run.enter':
324
381
  case 'run.start':
@@ -337,6 +394,7 @@ Process.prototype._onResumeMessage = function onResumeMessage(message) {
337
394
  return this.broker.publish('run', stateMessage.fields.routingKey, cloneContent(stateMessage.content), stateMessage.properties);
338
395
  };
339
396
 
397
+ /** @internal */
340
398
  Process.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
341
399
  const content = message.content;
342
400
  const messageType = message.properties.type;
@@ -359,16 +417,22 @@ Process.prototype._onExecutionMessage = function onExecutionMessage(routingKey,
359
417
  }
360
418
  }
361
419
 
362
- const executeMessage = this[kExecuteMessage];
363
- this[kExecuteMessage] = null;
420
+ const executeMessage = this[K_EXECUTE_MESSAGE];
421
+ this[K_EXECUTE_MESSAGE] = null;
364
422
  executeMessage.ack();
365
423
  };
366
424
 
425
+ /** @internal */
367
426
  Process.prototype._publishEvent = function publishEvent(state, content) {
368
427
  const eventContent = this._createMessage({ ...content, state });
369
428
  this.broker.publish('event', `process.${state}`, eventContent, { type: state, mandatory: state === 'error' });
370
429
  };
371
430
 
431
+ /**
432
+ * Deliver a message to a target activity or start activity that references it.
433
+ * Starts the process if a target is found and the process is idle.
434
+ * @param {import('#types').ElementBrokerMessage} message
435
+ */
372
436
  Process.prototype.sendMessage = function sendMessage(message) {
373
437
  const messageContent = message?.content;
374
438
  if (!messageContent) return;
@@ -388,44 +452,60 @@ Process.prototype.sendMessage = function sendMessage(message) {
388
452
  this.getApi().sendApiMessage(message.properties.type || 'message', cloneContent(messageContent), { delegate: true });
389
453
  };
390
454
 
455
+ /**
456
+ * @param {string} childId
457
+ */
391
458
  Process.prototype.getActivityById = function getActivityById(childId) {
392
459
  const execution = this.execution;
393
460
  if (execution) return execution.getActivityById(childId);
394
461
  return this.context.getActivityById(childId);
395
462
  };
396
463
 
464
+ /**
465
+ * Get every activity in the process scope.
466
+ */
397
467
  Process.prototype.getActivities = function getActivities() {
398
468
  const execution = this.execution;
399
469
  if (execution) return execution.getActivities();
400
470
  return this.context.getActivities(this.id);
401
471
  };
402
472
 
473
+ /**
474
+ * Get start activities, optionally filtered by referenced event definition.
475
+ * @param {import('#types').startActivityFilterOptions} [filterOptions]
476
+ */
403
477
  Process.prototype.getStartActivities = function getStartActivities(filterOptions) {
404
478
  return this.context.getStartActivities(filterOptions, this.id);
405
479
  };
406
480
 
481
+ /**
482
+ * Get sequence flows in the process scope.
483
+ */
407
484
  Process.prototype.getSequenceFlows = function getSequenceFlows() {
408
485
  const execution = this.execution;
409
486
  if (execution) return execution.getSequenceFlows();
410
487
  return this.context.getSequenceFlows();
411
488
  };
412
489
 
490
+ /**
491
+ * @param {string} laneId
492
+ * @returns {import('./Lane.js').Lane | undefined}
493
+ */
413
494
  Process.prototype.getLaneById = function getLaneById(laneId) {
414
- const lanes = this[kLanes];
415
- if (!lanes) return;
416
- return lanes.find((lane) => lane.id === laneId);
495
+ return this[K_LANES]?.find((lane) => lane.id === laneId);
417
496
  };
418
497
 
498
+ /**
499
+ * List currently postponed activities as Api wrappers.
500
+ * @param {import('#types').filterPostponed} [filterFn]
501
+ */
419
502
  Process.prototype.getPostponed = function getPostponed(...args) {
420
- const execution = this.execution;
421
- if (!execution) return [];
422
- return execution.getPostponed(...args);
503
+ return this.execution?.getPostponed(...args) || [];
423
504
  };
424
505
 
506
+ /** @internal */
425
507
  Process.prototype._onApiMessage = function onApiMessage(routingKey, message) {
426
- const messageType = message.properties.type;
427
-
428
- switch (messageType) {
508
+ switch (message.properties.type) {
429
509
  case 'stop': {
430
510
  if (this.execution && !this.execution.completed) return;
431
511
  this._onStop();
@@ -434,12 +514,14 @@ Process.prototype._onApiMessage = function onApiMessage(routingKey, message) {
434
514
  }
435
515
  };
436
516
 
517
+ /** @internal */
437
518
  Process.prototype._onStop = function onStop() {
438
- this[kStopped] = true;
519
+ this[K_STOPPED] = true;
439
520
  this._deactivateRunConsumers();
440
521
  return this._publishEvent('stop');
441
522
  };
442
523
 
524
+ /** @internal */
443
525
  Process.prototype._createMessage = function createMessage(override) {
444
526
  return {
445
527
  id: this.id,
@@ -451,6 +533,7 @@ Process.prototype._createMessage = function createMessage(override) {
451
533
  };
452
534
  };
453
535
 
536
+ /** @internal */
454
537
  Process.prototype._debug = function debug(msg) {
455
538
  this.logger.debug(`<${this.id}> ${msg}`);
456
539
  };