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,50 +1,56 @@
1
- import DefinitionExecution from './DefinitionExecution.js';
1
+ import { DefinitionExecution } from './DefinitionExecution.js';
2
2
  import { DefinitionApi } from '../Api.js';
3
3
  import { DefinitionBroker } from '../EventBroker.js';
4
4
  import { getUniqueId, getOptionsAndCallback } from '../shared.js';
5
5
  import { makeErrorFromMessage } from '../error/Errors.js';
6
6
  import { cloneMessage, cloneContent } from '../messageHelper.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 kMessageHandlers = Symbol.for('messageHandlers');
13
- const kStateMessage = Symbol.for('stateMessage');
14
- const kStatus = Symbol.for('status');
15
- const kStopped = Symbol.for('stopped');
16
-
17
- export default Definition;
18
-
7
+ import {
8
+ K_CONSUMING,
9
+ K_COUNTERS,
10
+ K_EXECUTE_MESSAGE,
11
+ K_EXECUTION,
12
+ K_MESSAGE_HANDLERS,
13
+ K_STATE_MESSAGE,
14
+ K_STATUS,
15
+ K_STOPPED,
16
+ } from '../constants.js';
17
+
18
+ /**
19
+ * Top-level wrapper for an executable BPMN definition. Owns its DefinitionExecution and
20
+ * mediates inter-process messaging.
21
+ * @param {import('../Context.js').ContextInstance} context
22
+ * @param {import('#types').EnvironmentOptions} [options] When provided, environment is cloned and settings merged
23
+ */
19
24
  export function Definition(context, options) {
20
- if (!(this instanceof Definition)) return new Definition(context, options);
21
25
  if (!context) throw new Error('No context');
22
26
 
23
27
  const { id, name, type = 'definition' } = context;
24
28
 
25
29
  this.id = id;
30
+ /** @type {string} */
26
31
  this.type = type;
27
32
  this.name = name;
28
33
 
29
- let environment;
34
+ /** @type {import('../Environment.js').Environment} */
35
+ this.environment = undefined;
30
36
  if (options) {
31
- environment = this.environment = context.environment.clone(options);
32
- this.context = context.clone(environment);
37
+ this.environment = context.environment.clone(options).assignSettings(options.settings);
38
+ this.context = context.clone(this.environment);
33
39
  } else {
34
- environment = this.environment = context.environment;
40
+ this.environment = context.environment;
35
41
  this.context = context;
36
42
  }
37
43
 
38
- this[kCounters] = {
44
+ this[K_COUNTERS] = {
39
45
  completed: 0,
40
46
  discarded: 0,
41
47
  };
42
48
 
43
- this[kStopped] = false;
44
- this[kExec] = new Map();
49
+ this[K_STOPPED] = false;
50
+ this[K_EXECUTION] = new Map();
45
51
 
46
52
  const onBrokerReturn = this._onBrokerReturnFn.bind(this);
47
- this[kMessageHandlers] = {
53
+ this[K_MESSAGE_HANDLERS] = {
48
54
  onBrokerReturn,
49
55
  onApiMessage: this._onApiMessage.bind(this),
50
56
  onRunMessage: this._onRunMessage.bind(this),
@@ -60,49 +66,58 @@ export function Definition(context, options) {
60
66
  this.emit = emit;
61
67
  this.emitFatal = emitFatal;
62
68
 
63
- this.logger = environment.Logger(type.toLowerCase());
69
+ /** @type {import('#types').ILogger} */
70
+ this.logger = this.environment.Logger(type.toLowerCase());
64
71
  }
65
72
 
66
73
  Object.defineProperties(Definition.prototype, {
67
74
  counters: {
68
75
  get() {
69
- return { ...this[kCounters] };
76
+ return { ...this[K_COUNTERS] };
70
77
  },
71
78
  },
72
79
  execution: {
73
80
  get() {
74
- return this[kExec].get('execution');
81
+ return this[K_EXECUTION].get('execution');
75
82
  },
76
83
  },
77
84
  executionId: {
78
85
  get() {
79
- return this[kExec].get('executionId');
86
+ return this[K_EXECUTION].get('executionId');
80
87
  },
81
88
  },
82
89
  isRunning: {
83
90
  get() {
84
- if (!this[kConsuming]) return false;
91
+ if (!this[K_CONSUMING]) return false;
85
92
  return !!this.status;
86
93
  },
87
94
  },
88
95
  status: {
89
96
  get() {
90
- return this[kStatus];
97
+ return this[K_STATUS];
91
98
  },
92
99
  },
93
100
  stopped: {
94
101
  get() {
95
- return this[kStopped];
102
+ return this[K_STOPPED];
96
103
  },
97
104
  },
98
105
  activityStatus: {
99
106
  get() {
100
- const execution = this[kExec].get('execution');
107
+ const execution = this[K_EXECUTION].get('execution');
101
108
  return execution?.activityStatus || 'idle';
102
109
  },
103
110
  },
104
111
  });
105
112
 
113
+ /**
114
+ * Start running the definition. Accepts run options, a callback, or both.
115
+ * The callback fires once on leave, stop, or error.
116
+ * @param {Record<string, any> | import('#types').runCallback} [optionsOrCallback]
117
+ * @param {import('#types').runCallback} [optionalCallback]
118
+ * @returns {this}
119
+ * @throws {Error} when already running and no callback is supplied
120
+ */
106
121
  Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
107
122
  const [runOptions, callback] = getOptionsAndCallback(optionsOrCallback, optionalCallback);
108
123
  if (this.isRunning) {
@@ -115,7 +130,7 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
115
130
  addConsumerCallbacks(this, callback);
116
131
  }
117
132
 
118
- const exec = this[kExec];
133
+ const exec = this[K_EXECUTION];
119
134
  const executionId = getUniqueId(this.id);
120
135
  exec.set('executionId', executionId);
121
136
  const content = this._createMessage({ ...runOptions });
@@ -132,6 +147,12 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
132
147
  return this;
133
148
  };
134
149
 
150
+ /**
151
+ * Resume after recover by republishing the last run message. The callback fires once on
152
+ * leave, stop, or error.
153
+ * @param {import('#types').runCallback} [callback]
154
+ * @returns {this}
155
+ */
135
156
  Definition.prototype.resume = function resume(callback) {
136
157
  if (this.isRunning) {
137
158
  const err = new Error('cannot resume running definition');
@@ -139,7 +160,7 @@ Definition.prototype.resume = function resume(callback) {
139
160
  throw err;
140
161
  }
141
162
 
142
- this[kStopped] = false;
163
+ this[K_STOPPED] = false;
143
164
  if (!this.status) return this;
144
165
 
145
166
  if (callback) {
@@ -154,6 +175,10 @@ Definition.prototype.resume = function resume(callback) {
154
175
  return this;
155
176
  };
156
177
 
178
+ /**
179
+ * Snapshot definition state for recover.
180
+ * @returns {import('#types').DefinitionState}
181
+ */
157
182
  Definition.prototype.getState = function getState() {
158
183
  return this._createMessage({
159
184
  status: this.status,
@@ -165,17 +190,23 @@ Definition.prototype.getState = function getState() {
165
190
  });
166
191
  };
167
192
 
193
+ /**
194
+ * Restore definition state captured by getState.
195
+ * @param {import('#types').DefinitionState} [state]
196
+ * @returns {this}
197
+ * @throws {Error} when called on a running definition
198
+ */
168
199
  Definition.prototype.recover = function recover(state) {
169
200
  if (this.isRunning) throw new Error('cannot recover running definition');
170
201
  if (!state) return this;
171
202
 
172
- this[kStopped] = !!state.stopped;
173
- this[kStatus] = state.status;
203
+ this[K_STOPPED] = !!state.stopped;
204
+ this[K_STATUS] = state.status;
174
205
 
175
- const exec = this[kExec];
206
+ const exec = this[K_EXECUTION];
176
207
  exec.set('executionId', state.executionId);
177
208
  if (state.counters) {
178
- this[kCounters] = { ...this[kCounters], ...state.counters };
209
+ this[K_COUNTERS] = { ...this[K_COUNTERS], ...state.counters };
179
210
  }
180
211
 
181
212
  this.environment.recover(state.environment);
@@ -189,7 +220,14 @@ Definition.prototype.recover = function recover(state) {
189
220
  return this;
190
221
  };
191
222
 
223
+ /**
224
+ * Walk activity graphs to discover sequences. Limited to the activity's owning process
225
+ * when startId is given, otherwise all processes are shaken.
226
+ * @param {string} [startId]
227
+ * @returns {import('#types').ShakeResult | undefined}
228
+ */
192
229
  Definition.prototype.shake = function shake(startId) {
230
+ /** @type {import('#types').ShakeResult} */
193
231
  let result = {};
194
232
  let bps;
195
233
  if (startId) {
@@ -207,6 +245,7 @@ Definition.prototype.shake = function shake(startId) {
207
245
  return result;
208
246
  };
209
247
 
248
+ /** @internal */
210
249
  Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
211
250
  let shovel;
212
251
  if (!shakeBp.isRunning) {
@@ -229,28 +268,44 @@ Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
229
268
  return shakeResult;
230
269
  };
231
270
 
271
+ /**
272
+ * Get every process in the definition.
273
+ */
232
274
  Definition.prototype.getProcesses = function getProcesses() {
233
275
  const execution = this.execution;
234
276
  if (execution) return execution.getProcesses();
235
277
  return this.context.getProcesses();
236
278
  };
237
279
 
280
+ /**
281
+ * Get processes flagged executable in the definition.
282
+ */
238
283
  Definition.prototype.getExecutableProcesses = function getExecutableProcesses() {
239
284
  const execution = this.execution;
240
285
  if (execution) return execution.getExecutableProcesses();
241
286
  return this.context.getExecutableProcesses();
242
287
  };
243
288
 
289
+ /**
290
+ * Get processes that are currently running.
291
+ */
244
292
  Definition.prototype.getRunningProcesses = function getRunningProcesses() {
245
293
  const execution = this.execution;
246
294
  if (!execution) return [];
247
295
  return execution.getRunningProcesses();
248
296
  };
249
297
 
298
+ /**
299
+ * @param {string} processId
300
+ */
250
301
  Definition.prototype.getProcessById = function getProcessById(processId) {
251
302
  return this.getProcesses().find((p) => p.id === processId);
252
303
  };
253
304
 
305
+ /**
306
+ * Find an activity by id across all processes in the definition.
307
+ * @param {string} childId
308
+ */
254
309
  Definition.prototype.getActivityById = function getActivityById(childId) {
255
310
  const bps = this.getProcesses();
256
311
  for (const bp of bps) {
@@ -260,32 +315,57 @@ Definition.prototype.getActivityById = function getActivityById(childId) {
260
315
  return null;
261
316
  };
262
317
 
318
+ /**
319
+ * Lookup any element (activity, flow, etc.) in the parsed definition by id.
320
+ * @param {string} elementId
321
+ */
263
322
  Definition.prototype.getElementById = function getElementById(elementId) {
264
323
  return this.context.getActivityById(elementId);
265
324
  };
266
325
 
326
+ /**
327
+ * List currently postponed activities as Api wrappers.
328
+ * @param {import('#types').filterPostponed} [filterFn]
329
+ */
267
330
  Definition.prototype.getPostponed = function getPostponed(...args) {
268
- const execution = this.execution;
269
- if (!execution) return [];
270
- return execution.getPostponed(...args);
331
+ return this.execution?.getPostponed(...args) || [];
271
332
  };
272
333
 
334
+ /**
335
+ * Resolve a Definition Api wrapper, preferring the running execution if any.
336
+ * @param {import('#types').ElementBrokerMessage} [message]
337
+ * @returns {import('#types').IApi<this>}
338
+ * @throws {Error} when the definition is not running and no message is given
339
+ */
273
340
  Definition.prototype.getApi = function getApi(message) {
274
341
  const execution = this.execution;
275
342
  if (execution) return execution.getApi(message);
276
- message = message || this[kStateMessage];
343
+ message = message || this[K_STATE_MESSAGE];
277
344
  if (!message) throw new Error('Definition is not running');
278
345
  return DefinitionApi(this.broker, message);
279
346
  };
280
347
 
348
+ /**
349
+ * Send a delegated signal to the running definition.
350
+ * @param {import('#types').signalMessage} [message]
351
+ */
281
352
  Definition.prototype.signal = function signal(message) {
282
353
  return this.getApi().signal(message, { delegate: true });
283
354
  };
284
355
 
356
+ /**
357
+ * Cancel a running activity inside the definition by delegated api message.
358
+ * @param {import('#types').signalMessage} [message]
359
+ */
285
360
  Definition.prototype.cancelActivity = function cancelActivity(message) {
286
361
  return this.getApi().cancel(message, { delegate: true });
287
362
  };
288
363
 
364
+ /**
365
+ * Deliver a message to a referenced element. Resolves the message reference when the
366
+ * target element exposes a `resolve` method (e.g. message-, signal-, escalation events).
367
+ * @param {{ id?: string, [x: string]: any }} message
368
+ */
289
369
  Definition.prototype.sendMessage = function sendMessage(message) {
290
370
  const messageContent = { message };
291
371
  let messageType = 'message';
@@ -299,15 +379,19 @@ Definition.prototype.sendMessage = function sendMessage(message) {
299
379
  return this.getApi().sendApiMessage(messageType, messageContent, { delegate: true });
300
380
  };
301
381
 
382
+ /**
383
+ * Stop the definition if running.
384
+ */
302
385
  Definition.prototype.stop = function stop() {
303
386
  if (!this.isRunning) return;
304
387
  this.getApi().stop();
305
388
  };
306
389
 
390
+ /** @internal */
307
391
  Definition.prototype._activateRunConsumers = function activateRunConsumers() {
308
- this[kConsuming] = true;
392
+ this[K_CONSUMING] = true;
309
393
  const broker = this.broker;
310
- const { onApiMessage, onRunMessage } = this[kMessageHandlers];
394
+ const { onApiMessage, onRunMessage } = this[K_MESSAGE_HANDLERS];
311
395
  broker.subscribeTmp('api', `definition.*.${this.executionId}`, onApiMessage, {
312
396
  noAck: true,
313
397
  consumerTag: '_definition-api',
@@ -318,14 +402,16 @@ Definition.prototype._activateRunConsumers = function activateRunConsumers() {
318
402
  });
319
403
  };
320
404
 
405
+ /** @internal */
321
406
  Definition.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
322
407
  const broker = this.broker;
323
408
  broker.cancel('_definition-api');
324
409
  broker.cancel('_definition-run');
325
410
  broker.cancel('_definition-execution');
326
- this[kConsuming] = false;
411
+ this[K_CONSUMING] = false;
327
412
  };
328
413
 
414
+ /** @internal */
329
415
  Definition.prototype._createMessage = function createMessage(override) {
330
416
  return {
331
417
  id: this.id,
@@ -336,20 +422,21 @@ Definition.prototype._createMessage = function createMessage(override) {
336
422
  };
337
423
  };
338
424
 
425
+ /** @internal */
339
426
  Definition.prototype._onRunMessage = function onRunMessage(routingKey, message) {
340
427
  const { content, fields } = message;
341
428
  if (routingKey === 'run.resume') {
342
429
  return this._onResumeMessage(message);
343
430
  }
344
431
 
345
- const exec = this[kExec];
346
- this[kStateMessage] = message;
432
+ const exec = this[K_EXECUTION];
433
+ this[K_STATE_MESSAGE] = message;
347
434
 
348
435
  switch (routingKey) {
349
436
  case 'run.enter': {
350
437
  this.logger.debug(`<${this.executionId} (${this.id})> enter`);
351
438
 
352
- this[kStatus] = 'entered';
439
+ this[K_STATUS] = 'entered';
353
440
  if (fields.redelivered) break;
354
441
 
355
442
  exec.delete('execution');
@@ -358,19 +445,19 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
358
445
  }
359
446
  case 'run.start': {
360
447
  this.logger.debug(`<${this.executionId} (${this.id})> start`);
361
- this[kStatus] = 'start';
448
+ this[K_STATUS] = 'start';
362
449
  this._publishEvent('start', content);
363
450
  break;
364
451
  }
365
452
  case 'run.execute': {
366
- this[kStatus] = 'executing';
453
+ this[K_STATUS] = 'executing';
367
454
  const executeMessage = cloneMessage(message);
368
455
  let execution = exec.get('execution');
369
456
  if (fields.redelivered && !execution) {
370
457
  executeMessage.fields.redelivered = undefined;
371
458
  }
372
- this[kExecuteMessage] = message;
373
- this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
459
+ this[K_EXECUTE_MESSAGE] = message;
460
+ this.broker.getQueue('execution-q').assertConsumer(this[K_MESSAGE_HANDLERS].onExecutionMessage, {
374
461
  exclusive: true,
375
462
  consumerTag: '_definition-execution',
376
463
  });
@@ -387,12 +474,12 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
387
474
  return execution.execute(executeMessage);
388
475
  }
389
476
  case 'run.end': {
390
- if (this[kStatus] === 'end') break;
477
+ if (this[K_STATUS] === 'end') break;
391
478
 
392
- this[kCounters].completed++;
479
+ this[K_COUNTERS].completed++;
393
480
 
394
481
  this.logger.debug(`<${this.executionId} (${this.id})> completed`);
395
- this[kStatus] = 'end';
482
+ this[K_STATUS] = 'end';
396
483
  this.broker.publish('run', 'run.leave', content);
397
484
  this._publishEvent('end', content);
398
485
  break;
@@ -409,17 +496,17 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
409
496
  break;
410
497
  }
411
498
  case 'run.discarded': {
412
- if (this[kStatus] === 'discarded') break;
499
+ if (this[K_STATUS] === 'discarded') break;
413
500
 
414
- this[kCounters].discarded++;
501
+ this[K_COUNTERS].discarded++;
415
502
 
416
- this[kStatus] = 'discarded';
503
+ this[K_STATUS] = 'discarded';
417
504
  this.broker.publish('run', 'run.leave', content);
418
505
  break;
419
506
  }
420
507
  case 'run.leave': {
421
508
  message.ack();
422
- this[kStatus] = undefined;
509
+ this[K_STATUS] = undefined;
423
510
  this._deactivateRunConsumers();
424
511
 
425
512
  this._publishEvent('leave', this._createMessage());
@@ -430,10 +517,11 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
430
517
  message.ack();
431
518
  };
432
519
 
520
+ /** @internal */
433
521
  Definition.prototype._onResumeMessage = function onResumeMessage(message) {
434
522
  message.ack();
435
523
 
436
- const stateMessage = this[kStateMessage];
524
+ const stateMessage = this[K_STATE_MESSAGE];
437
525
 
438
526
  switch (stateMessage.fields.routingKey) {
439
527
  case 'run.discarded':
@@ -451,6 +539,7 @@ Definition.prototype._onResumeMessage = function onResumeMessage(message) {
451
539
  return this.broker.publish('run', stateMessage.fields.routingKey, cloneContent(stateMessage.content), stateMessage.properties);
452
540
  };
453
541
 
542
+ /** @internal */
454
543
  Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
455
544
  const { content, properties } = message;
456
545
  const messageType = properties.type;
@@ -471,11 +560,12 @@ Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKe
471
560
  }
472
561
  }
473
562
 
474
- const executeMessage = this[kExecuteMessage];
475
- this[kExecuteMessage] = null;
563
+ const executeMessage = this[K_EXECUTE_MESSAGE];
564
+ this[K_EXECUTE_MESSAGE] = null;
476
565
  executeMessage.ack();
477
566
  };
478
567
 
568
+ /** @internal */
479
569
  Definition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
480
570
  if (message.properties.type === 'stop') {
481
571
  const execution = this.execution;
@@ -485,6 +575,7 @@ Definition.prototype._onApiMessage = function onApiMessage(routingKey, message)
485
575
  }
486
576
  };
487
577
 
578
+ /** @internal */
488
579
  Definition.prototype._publishEvent = function publishEvent(action, content, msgOpts) {
489
580
  const execution = this.execution;
490
581
  this.broker.publish('event', `definition.${action}`, execution ? execution._createMessage(content) : cloneContent(content), {
@@ -493,12 +584,14 @@ Definition.prototype._publishEvent = function publishEvent(action, content, msgO
493
584
  });
494
585
  };
495
586
 
587
+ /** @internal */
496
588
  Definition.prototype._onStop = function onStop() {
497
- this[kStopped] = true;
589
+ this[K_STOPPED] = true;
498
590
  this._deactivateRunConsumers();
499
591
  return this._publishEvent('stop', this._createMessage());
500
592
  };
501
593
 
594
+ /** @internal */
502
595
  Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
503
596
  if (message.properties.type === 'error') {
504
597
  this._deactivateRunConsumers();
@@ -507,13 +600,15 @@ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
507
600
  }
508
601
  };
509
602
 
603
+ /** @internal */
510
604
  Definition.prototype._reset = function reset() {
511
- this[kExec].delete('executionId');
605
+ this[K_EXECUTION].delete('executionId');
512
606
  this._deactivateRunConsumers();
513
607
  this.broker.purgeQueue('run-q');
514
608
  this.broker.purgeQueue('execution-q');
515
609
  };
516
610
 
611
+ /** @internal */
517
612
  Definition.prototype._debug = function debug(msg) {
518
613
  this.logger.debug(`<${this.id}> ${msg}`);
519
614
  };