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
package/dist/shared.js CHANGED
@@ -14,6 +14,8 @@ function generateId() {
14
14
  function brokerSafeId(id) {
15
15
  return id.replace(safePattern, '_');
16
16
  }
17
+
18
+ /** @param {string} prefix */
17
19
  function getUniqueId(prefix) {
18
20
  return `${brokerSafeId(prefix)}_${generateId()}`;
19
21
  }
@@ -3,15 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.CallActivity = CallActivity;
6
7
  exports.CallActivityBehaviour = CallActivityBehaviour;
7
- exports.default = CallActivity;
8
- var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
8
+ var _Activity = require("../activity/Activity.js");
9
9
  var _Errors = require("../error/Errors.js");
10
10
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ /**
12
+ * Call activity
13
+ * @param {import('moddle-context-serializer').Activity} activityDef
14
+ * @param {import('#types').ContextInstance} context
15
+ */
12
16
  function CallActivity(activityDef, context) {
13
- return new _Activity.default(CallActivityBehaviour, activityDef, context);
17
+ return new _Activity.Activity(CallActivityBehaviour, activityDef, context);
14
18
  }
19
+
20
+ /**
21
+ * Call activity behaviour
22
+ * @param {import('#types').Activity} activity
23
+ */
15
24
  function CallActivityBehaviour(activity) {
16
25
  const {
17
26
  id,
@@ -21,11 +30,17 @@ function CallActivityBehaviour(activity) {
21
30
  this.id = id;
22
31
  this.type = type;
23
32
  this.calledElement = behaviour.calledElement;
33
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
24
34
  this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
25
35
  this.activity = activity;
26
36
  this.broker = activity.broker;
27
37
  this.environment = activity.environment;
28
38
  }
39
+
40
+ /**
41
+ * @param {import('#types').ElementBrokerMessage} executeMessage
42
+ * @returns {void}
43
+ */
29
44
  CallActivityBehaviour.prototype.execute = function execute(executeMessage) {
30
45
  const executeContent = executeMessage.content;
31
46
  const loopCharacteristics = this.loopCharacteristics;
@@ -3,9 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = LoopCharacteristics;
6
+ exports.LoopCharacteristics = LoopCharacteristics;
7
7
  var _Errors = require("../error/Errors.js");
8
8
  var _messageHelper = require("../messageHelper.js");
9
+ /**
10
+ * Loop characteristics
11
+ * @param {import('#types').Activity} activity
12
+ * @param {import('moddle-context-serializer').SerializableElement} loopCharacteristics
13
+ */
9
14
  function LoopCharacteristics(activity, loopCharacteristics) {
10
15
  this.activity = activity;
11
16
  this.loopCharacteristics = loopCharacteristics;
@@ -18,10 +23,13 @@ function LoopCharacteristics(activity, loopCharacteristics) {
18
23
  isSequential = false,
19
24
  collection
20
25
  } = behaviour;
26
+ /** @type {boolean} */
21
27
  this.isSequential = isSequential;
28
+ /** @type {string | undefined} */
22
29
  this.collection = collection;
23
30
  let completionCondition, startCondition, loopCardinality;
24
31
  if ('loopCardinality' in behaviour) loopCardinality = behaviour.loopCardinality;else if ('loopMaximum' in behaviour) loopCardinality = behaviour.loopMaximum;
32
+ /** @type {number | undefined} */
25
33
  this.loopCardinality = loopCardinality;
26
34
  if (behaviour.loopCondition) {
27
35
  if (behaviour.testBefore) startCondition = behaviour.loopCondition;else completionCondition = behaviour.loopCondition;
@@ -31,11 +39,19 @@ function LoopCharacteristics(activity, loopCharacteristics) {
31
39
  }
32
40
  if (collection) {
33
41
  this.loopType = 'collection';
42
+ /** @type {string | undefined} */
34
43
  this.elementVariable = behaviour.elementVariable || 'item';
35
44
  } else if (completionCondition) this.loopType = 'complete condition';else if (startCondition) this.loopType = 'start condition';else if (loopCardinality) this.loopType = 'cardinality';
45
+
46
+ /** @type {Characteristics} */
36
47
  this.characteristics = null;
37
48
  this.execution = null;
38
49
  }
50
+
51
+ /**
52
+ * @param {import('#types').ElementBrokerMessage} executeMessage
53
+ * @returns {void}
54
+ */
39
55
  LoopCharacteristics.prototype.execute = function execute(executeMessage) {
40
56
  if (!executeMessage) throw new TypeError('LoopCharacteristics execution requires message');
41
57
  const chr = this.characteristics = this.characteristics || new Characteristics(this.activity, this.loopCharacteristics, executeMessage);
@@ -43,11 +59,21 @@ LoopCharacteristics.prototype.execute = function execute(executeMessage) {
43
59
  const execution = this.isSequential ? new SequentialLoopCharacteristics(this.activity, chr) : new ParallelLoopCharacteristics(this.activity, chr);
44
60
  return execution.execute(executeMessage);
45
61
  };
62
+
63
+ /**
64
+ * @param {import('#types').Activity} activity
65
+ * @param {Characteristics} characteristics
66
+ */
46
67
  function SequentialLoopCharacteristics(activity, characteristics) {
47
68
  this.activity = activity;
48
69
  this.id = activity.id;
49
70
  this.characteristics = characteristics;
50
71
  }
72
+
73
+ /**
74
+ * @param {import('#types').ElementBrokerMessage} executeMessage
75
+ * @returns {void}
76
+ */
51
77
  SequentialLoopCharacteristics.prototype.execute = function execute(executeMessage) {
52
78
  const {
53
79
  routingKey: executeRoutingKey,
@@ -71,10 +97,10 @@ SequentialLoopCharacteristics.prototype._startNext = function startNext(index, i
71
97
  if (chr.isStartConditionMet({
72
98
  content
73
99
  })) {
74
- chr.debug('start condition met');
100
+ chr._debug('start condition met');
75
101
  return;
76
102
  }
77
- chr.debug(`${ignoreIfExecuting ? 'resume' : 'start'} sequential iteration index ${content.index}`);
103
+ chr._debug(`${ignoreIfExecuting ? 'resume' : 'start'} sequential iteration index ${content.index}`);
78
104
  const broker = this.activity.broker;
79
105
  broker.publish('execution', 'execute.iteration.next', {
80
106
  ...content,
@@ -105,11 +131,16 @@ SequentialLoopCharacteristics.prototype._onCompleteMessage = function onComplete
105
131
  state: 'iteration.completed'
106
132
  });
107
133
  if (chr.isCompletionConditionMet(message, loopOutput)) {
108
- chr.debug('complete condition met');
134
+ chr._debug('complete condition met');
109
135
  } else if (this._startNext(content.index + 1)) return;
110
- chr.debug('sequential loop completed');
136
+ chr._debug('sequential loop completed');
111
137
  return chr.complete(content);
112
138
  };
139
+
140
+ /**
141
+ * @param {import('#types').Activity} activity
142
+ * @param {Characteristics} characteristics
143
+ */
113
144
  function ParallelLoopCharacteristics(activity, characteristics) {
114
145
  this.activity = activity;
115
146
  this.id = activity.id;
@@ -118,6 +149,11 @@ function ParallelLoopCharacteristics(activity, characteristics) {
118
149
  this.index = 0;
119
150
  this.discarded = 0;
120
151
  }
152
+
153
+ /**
154
+ * @param {import('#types').ElementBrokerMessage} executeMessage
155
+ * @returns {void}
156
+ */
121
157
  ParallelLoopCharacteristics.prototype.execute = function execute(executeMessage) {
122
158
  const chr = this.characteristics;
123
159
  if (!chr.cardinality) throw new _Errors.RunError(`<${this.id}> cardinality or collection is required in parallel loops`, executeMessage);
@@ -142,7 +178,7 @@ ParallelLoopCharacteristics.prototype._startBatch = function startBatch() {
142
178
  const batch = new Set();
143
179
  let startContent = chr.next(this.index);
144
180
  do {
145
- chr.debug(`start parallel iteration index ${this.index}`);
181
+ chr._debug(`start parallel iteration index ${this.index}`);
146
182
  batch.add(startContent);
147
183
  this.running++;
148
184
  this.index++;
@@ -194,6 +230,13 @@ ParallelLoopCharacteristics.prototype._onCompleteMessage = function onCompleteMe
194
230
  this._startBatch();
195
231
  }
196
232
  };
233
+
234
+ /**
235
+ * Per-execution snapshot of resolved loop characteristics (cardinality, collection, conditions).
236
+ * @param {import('#types').Activity} activity
237
+ * @param {import('moddle-context-serializer').SerializableElement} loopCharacteristics
238
+ * @param {import('#types').ElementBrokerMessage} executeMessage
239
+ */
197
240
  function Characteristics(activity, loopCharacteristics, executeMessage) {
198
241
  this.activity = activity;
199
242
  const behaviour = this.behaviour = loopCharacteristics.behaviour || {};
@@ -202,26 +245,34 @@ function Characteristics(activity, loopCharacteristics, executeMessage) {
202
245
  this.id = activity.id;
203
246
  this.broker = activity.broker;
204
247
  this.parentExecutionId = executeMessage.content.executionId;
248
+
249
+ /** @type {boolean} */
205
250
  this.isSequential = behaviour.isSequential || false;
206
251
  this.output = executeMessage.content.output || [];
207
252
  this.parent = (0, _messageHelper.unshiftParent)(executeMessage.content.parent, executeMessage.content);
208
- if ('loopCardinality' in behaviour) this.loopCardinality = behaviour.loopCardinality;else if ('loopMaximum' in behaviour) this.loopCardinality = behaviour.loopMaximum;
253
+ if ('loopCardinality' in behaviour) this.loopCardinality = /** @type {number} */behaviour.loopCardinality;else if ('loopMaximum' in behaviour) this.loopCardinality = /** @type {number} */behaviour.loopMaximum;
209
254
  if (behaviour.loopCondition) {
210
- if (behaviour.testBefore) this.startCondition = behaviour.loopCondition;else this.completionCondition = behaviour.loopCondition;
255
+ if (behaviour.testBefore) this.startCondition = /** @type {string} */behaviour.loopCondition;else this.completionCondition = /** @type {string} */behaviour.loopCondition;
211
256
  }
212
257
  if (behaviour.completionCondition) {
258
+ /** @type {string} */
213
259
  this.completionCondition = behaviour.completionCondition;
214
260
  }
215
261
  const collection = this.collection = this.getCollection();
216
262
  if (collection) {
263
+ /** @type {string} */
217
264
  this.elementVariable = behaviour.elementVariable || 'item';
218
265
  }
219
266
  this.cardinality = this.getCardinality(collection);
267
+
268
+ /** @private */
220
269
  this.onApiMessage = this.onApiMessage.bind(this);
221
270
  const environment = activity.environment;
222
271
  this.logger = environment.Logger(type.toLowerCase());
223
272
  this.batchSize = environment.settings.batchSize || 50;
224
273
  }
274
+
275
+ /** @returns {import('#types').ElementMessageContent} */
225
276
  Characteristics.prototype.getContent = function getContent() {
226
277
  return {
227
278
  ...(0, _messageHelper.cloneContent)(this.message.content),
@@ -230,6 +281,11 @@ Characteristics.prototype.getContent = function getContent() {
230
281
  output: undefined
231
282
  };
232
283
  };
284
+
285
+ /**
286
+ * @param {number} index
287
+ * @returns {import('#types').ElementMessageContent}
288
+ */
233
289
  Characteristics.prototype.next = function next(index) {
234
290
  const cardinality = this.cardinality;
235
291
  if (cardinality > 0 && index >= cardinality) return;
@@ -248,6 +304,11 @@ Characteristics.prototype.next = function next(index) {
248
304
  }
249
305
  return content;
250
306
  };
307
+
308
+ /**
309
+ * @param {any} [collection]
310
+ * @returns {number | undefined} cardinality
311
+ */
251
312
  Characteristics.prototype.getCardinality = function getCardinality(collection) {
252
313
  const collectionLen = this.collection && Array.isArray(collection) ? collection.length : undefined;
253
314
  if (!this.loopCardinality) {
@@ -260,21 +321,37 @@ Characteristics.prototype.getCardinality = function getCardinality(collection) {
260
321
  if (value === undefined) return collectionLen;
261
322
  return Number(value);
262
323
  };
324
+
325
+ /** @returns {Array | undefined} */
263
326
  Characteristics.prototype.getCollection = function getCollection() {
264
327
  const collectionExpression = this.behaviour.collection;
265
328
  if (!collectionExpression) return;
266
329
  return this.activity.environment.resolveExpression(collectionExpression, this.message);
267
330
  };
331
+
332
+ /**
333
+ * @param {import('#types').ElementBrokerMessage} message
334
+ */
268
335
  Characteristics.prototype.isStartConditionMet = function isStartConditionMet(message) {
269
336
  if (!this.startCondition) return false;
270
337
  return this.activity.environment.resolveExpression(this.startCondition, (0, _messageHelper.cloneMessage)(message));
271
338
  };
339
+
340
+ /**
341
+ * @param {import('#types').ElementBrokerMessage} message
342
+ */
272
343
  Characteristics.prototype.isCompletionConditionMet = function isCompletionConditionMet(message) {
273
344
  if (!this.completionCondition) return false;
274
345
  return this.activity.environment.resolveExpression(this.completionCondition, (0, _messageHelper.cloneMessage)(message, {
275
346
  loopOutput: this.output
276
347
  }));
277
348
  };
349
+
350
+ /**
351
+ * @param {import('#types').ElementMessageContent} content
352
+ * @param {boolean} [allDiscarded]
353
+ * @returns {void}
354
+ */
278
355
  Characteristics.prototype.complete = function complete(content, allDiscarded) {
279
356
  this.stop();
280
357
  return this.broker.publish('execution', 'execute.' + (allDiscarded ? 'discard' : 'completed'), {
@@ -283,6 +360,10 @@ Characteristics.prototype.complete = function complete(content, allDiscarded) {
283
360
  output: this.output
284
361
  });
285
362
  };
363
+
364
+ /**
365
+ * @param {import('#types').ElementBrokerMessage} onIterationCompleteMessage
366
+ */
286
367
  Characteristics.prototype.subscribe = function subscribe(onIterationCompleteMessage) {
287
368
  this.broker.subscribeTmp('api', `activity.*.${this.parentExecutionId}`, this.onApiMessage, {
288
369
  noAck: true,
@@ -305,6 +386,8 @@ Characteristics.prototype.subscribe = function subscribe(onIterationCompleteMess
305
386
  }
306
387
  }
307
388
  };
389
+
390
+ /** @internal */
308
391
  Characteristics.prototype.onApiMessage = function onApiMessage(_, message) {
309
392
  switch (message.properties.type) {
310
393
  case 'stop':
@@ -317,6 +400,8 @@ Characteristics.prototype.stop = function stop() {
317
400
  this.broker.cancel('_execute-q-multi-instance-tag');
318
401
  this.broker.cancel('_api-multi-instance-tag');
319
402
  };
320
- Characteristics.prototype.debug = function debug(msg) {
403
+
404
+ /** @internal */
405
+ Characteristics.prototype._debug = function debug(msg) {
321
406
  this.logger.debug(`<${this.parentExecutionId} (${this.id})> ${msg}`);
322
407
  };
@@ -3,17 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.ReceiveTask = ReceiveTask;
6
7
  exports.ReceiveTaskBehaviour = ReceiveTaskBehaviour;
7
- exports.default = ReceiveTask;
8
- var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
8
+ var _Activity = require("../activity/Activity.js");
9
9
  var _messageHelper = require("../messageHelper.js");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const kCompleted = Symbol.for('completed');
12
- const kExecuteMessage = Symbol.for('executeMessage');
13
- const kReferenceElement = Symbol.for('referenceElement');
14
- const kReferenceInfo = Symbol.for('referenceInfo');
10
+ var _constants = require("../constants.js");
11
+ /**
12
+ * Receive task
13
+ * @param {import('moddle-context-serializer').Activity} activityDef
14
+ * @param {import('#types').ContextInstance} context
15
+ */
15
16
  function ReceiveTask(activityDef, context) {
16
- const task = new _Activity.default(ReceiveTaskBehaviour, activityDef, context);
17
+ const task = new _Activity.Activity(ReceiveTaskBehaviour, activityDef, context);
17
18
  task.broker.assertQueue('message', {
18
19
  autoDelete: false,
19
20
  durable: true
@@ -23,6 +24,11 @@ function ReceiveTask(activityDef, context) {
23
24
  });
24
25
  return task;
25
26
  }
27
+
28
+ /**
29
+ * Receive task behaviour
30
+ * @param {import('#types').Activity} activity
31
+ */
26
32
  function ReceiveTaskBehaviour(activity) {
27
33
  const {
28
34
  id,
@@ -31,16 +37,25 @@ function ReceiveTaskBehaviour(activity) {
31
37
  } = activity;
32
38
  this.id = id;
33
39
  this.type = type;
34
- const reference = this.reference = {
40
+
41
+ /** @type {import('#types').EventReference} */
42
+ this.reference = {
35
43
  name: 'anonymous',
36
44
  ...behaviour.messageRef,
37
45
  referenceType: 'message'
38
46
  };
47
+
48
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined } */
39
49
  this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
40
50
  this.activity = activity;
41
51
  this.broker = activity.broker;
42
- this[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
52
+ this[_constants.K_REFERENCE_ELEMENT] = this.reference.id && activity.getActivityById(this.reference.id);
43
53
  }
54
+
55
+ /**
56
+ * @param {import('#types').ElementBrokerMessage} executeMessage
57
+ * @returns {void}
58
+ */
44
59
  ReceiveTaskBehaviour.prototype.execute = function execute(executeMessage) {
45
60
  return new ReceiveTaskExecution(this).execute(executeMessage);
46
61
  };
@@ -56,18 +71,18 @@ function ReceiveTaskExecution(parent) {
56
71
  this.reference = reference;
57
72
  this.broker = broker;
58
73
  this.loopCharacteristics = loopCharacteristics;
59
- this.referenceElement = parent[kReferenceElement];
60
- this[kCompleted] = false;
74
+ this.referenceElement = parent[_constants.K_REFERENCE_ELEMENT];
75
+ this[_constants.K_COMPLETED] = false;
61
76
  }
62
77
  ReceiveTaskExecution.prototype.execute = function execute(executeMessage) {
63
- this[kExecuteMessage] = executeMessage;
78
+ this[_constants.K_EXECUTE_MESSAGE] = executeMessage;
64
79
  const executeContent = executeMessage.content;
65
80
  const {
66
81
  executionId,
67
82
  isRootScope
68
83
  } = executeContent;
69
84
  this.executionId = executionId;
70
- const info = this[kReferenceInfo] = this._getReferenceInfo(executeMessage);
85
+ const info = this[_constants.K_REFERENCE_INFO] = this._getReferenceInfo(executeMessage);
71
86
  if (isRootScope) {
72
87
  this._setupMessageHandling(executionId);
73
88
  }
@@ -80,7 +95,7 @@ ReceiveTaskExecution.prototype.execute = function execute(executeMessage) {
80
95
  noAck: true,
81
96
  consumerTag: `_onmessage-${executionId}`
82
97
  });
83
- if (this[kCompleted]) return;
98
+ if (this[_constants.K_COMPLETED]) return;
84
99
  broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
85
100
  noAck: true,
86
101
  consumerTag: `_api-${executionId}`,
@@ -102,7 +117,7 @@ ReceiveTaskExecution.prototype._onCatchMessage = function onCatchMessage(routing
102
117
  const {
103
118
  message: referenceMessage,
104
119
  description
105
- } = this[kReferenceInfo];
120
+ } = this[_constants.K_REFERENCE_INFO];
106
121
  if (!referenceMessage.id && signalId || signalExecutionId) {
107
122
  if (this.loopCharacteristics && signalExecutionId !== this.executionId) return;
108
123
  if (signalId !== this.id && signalExecutionId !== this.executionId) return;
@@ -115,7 +130,7 @@ ReceiveTaskExecution.prototype._onCatchMessage = function onCatchMessage(routing
115
130
  correlationId
116
131
  } = message.properties;
117
132
  const broker = this.broker;
118
- const executeContent = this[kExecuteMessage].content;
133
+ const executeContent = this[_constants.K_EXECUTE_MESSAGE].content;
119
134
  broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(executeContent, {
120
135
  message: {
121
136
  ...message.content.message
@@ -149,9 +164,9 @@ ReceiveTaskExecution.prototype._onApiMessage = function onApiMessage(routingKey,
149
164
  }
150
165
  case 'discard':
151
166
  {
152
- this[kCompleted] = true;
167
+ this[_constants.K_COMPLETED] = true;
153
168
  this._stop();
154
- return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content), {
169
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content), {
155
170
  correlationId
156
171
  });
157
172
  }
@@ -162,9 +177,9 @@ ReceiveTaskExecution.prototype._onApiMessage = function onApiMessage(routingKey,
162
177
  }
163
178
  };
164
179
  ReceiveTaskExecution.prototype._complete = function complete(output, options) {
165
- this[kCompleted] = true;
180
+ this[_constants.K_COMPLETED] = true;
166
181
  this._stop();
167
- return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
182
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(this[_constants.K_EXECUTE_MESSAGE].content, {
168
183
  output
169
184
  }), options);
170
185
  };
@@ -3,16 +3,25 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.ScriptTask = ScriptTask;
6
7
  exports.ScriptTaskBehaviour = ScriptTaskBehaviour;
7
- exports.default = ScriptTask;
8
- var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
- var _ExecutionScope = _interopRequireDefault(require("../activity/ExecutionScope.js"));
8
+ var _Activity = require("../activity/Activity.js");
9
+ var _ExecutionScope = require("../activity/ExecutionScope.js");
10
10
  var _Errors = require("../error/Errors.js");
11
11
  var _messageHelper = require("../messageHelper.js");
12
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
+ /**
13
+ * Script task
14
+ * @param {import('moddle-context-serializer').Activity} activityDef
15
+ * @param {import('#types').ContextInstance} context
16
+ */
13
17
  function ScriptTask(activityDef, context) {
14
- return new _Activity.default(ScriptTaskBehaviour, activityDef, context);
18
+ return new _Activity.Activity(ScriptTaskBehaviour, activityDef, context);
15
19
  }
20
+
21
+ /**
22
+ * Script task behaviour
23
+ * @param {import('#types').Activity} activity
24
+ */
16
25
  function ScriptTaskBehaviour(activity) {
17
26
  const {
18
27
  id,
@@ -22,11 +31,18 @@ function ScriptTaskBehaviour(activity) {
22
31
  this.id = id;
23
32
  this.type = type;
24
33
  this.scriptFormat = behaviour.scriptFormat;
34
+
35
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
25
36
  this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
26
37
  this.activity = activity;
27
38
  const environment = this.environment = activity.environment;
28
39
  environment.registerScript(activity);
29
40
  }
41
+
42
+ /**
43
+ * @param {import('#types').ElementBrokerMessage} executeMessage
44
+ * @returns {void}
45
+ */
30
46
  ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
31
47
  const executeContent = executeMessage.content;
32
48
  const loopCharacteristics = this.loopCharacteristics;
@@ -39,7 +55,7 @@ ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
39
55
  if (!script) {
40
56
  return activity.emitFatal(new _Errors.ActivityError(`Script format ${scriptFormat} is unsupported or was not registered for <${activity.id}>`, executeMessage), executeContent);
41
57
  }
42
- return script.execute((0, _ExecutionScope.default)(activity, executeMessage), scriptCallback);
58
+ return script.execute((0, _ExecutionScope.ExecutionScope)(activity, executeMessage), scriptCallback);
43
59
  function scriptCallback(err, output) {
44
60
  if (err) {
45
61
  activity.logger.error(`<${executeContent.executionId} (${activity.id})>`, err);
@@ -3,9 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = ServiceImplementation;
7
- var _ExecutionScope = _interopRequireDefault(require("../activity/ExecutionScope.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
+ exports.ServiceImplementation = ServiceImplementation;
7
+ var _ExecutionScope = require("../activity/ExecutionScope.js");
8
+ /**
9
+ * Service implementation
10
+ * @param {import('#types').Activity} activity
11
+ */
9
12
  function ServiceImplementation(activity) {
10
13
  this.type = `${activity.type}:implementation`;
11
14
  this.implementation = activity.behaviour.implementation;
@@ -16,7 +19,7 @@ ServiceImplementation.prototype.execute = function execute(executionMessage, cal
16
19
  const implementation = this.implementation;
17
20
  const serviceFn = activity.environment.resolveExpression(implementation, executionMessage);
18
21
  if (typeof serviceFn !== 'function') return callback(new Error(`Implementation ${implementation} did not resolve to a function`));
19
- serviceFn.call(activity, (0, _ExecutionScope.default)(activity, executionMessage), (err, ...args) => {
22
+ serviceFn.call(activity, (0, _ExecutionScope.ExecutionScope)(activity, executionMessage), (err, ...args) => {
20
23
  callback(err, args);
21
24
  });
22
25
  };
@@ -3,15 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.ServiceTask = ServiceTask;
6
7
  exports.ServiceTaskBehaviour = ServiceTaskBehaviour;
7
- exports.default = ServiceTask;
8
- var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
8
+ var _Activity = require("../activity/Activity.js");
9
9
  var _Errors = require("../error/Errors.js");
10
10
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ /**
12
+ * Service task
13
+ * @param {import('moddle-context-serializer').Activity} activityDef
14
+ * @param {import('#types').ContextInstance} context
15
+ */
12
16
  function ServiceTask(activityDef, context) {
13
- return new _Activity.default(ServiceTaskBehaviour, activityDef, context);
17
+ return new _Activity.Activity(ServiceTaskBehaviour, activityDef, context);
14
18
  }
19
+
20
+ /**
21
+ * Service task behaviour
22
+ * @param {import('#types').Activity} activity
23
+ */
15
24
  function ServiceTaskBehaviour(activity) {
16
25
  const {
17
26
  id,
@@ -20,11 +29,17 @@ function ServiceTaskBehaviour(activity) {
20
29
  } = activity;
21
30
  this.id = id;
22
31
  this.type = type;
32
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
23
33
  this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
24
34
  this.activity = activity;
25
35
  this.environment = activity.environment;
26
36
  this.broker = activity.broker;
27
37
  }
38
+
39
+ /**
40
+ * @param {import('#types').ElementBrokerMessage} executeMessage
41
+ * @returns {void}
42
+ */
28
43
  ServiceTaskBehaviour.prototype.execute = function execute(executeMessage) {
29
44
  const executeContent = executeMessage.content;
30
45
  const loopCharacteristics = this.loopCharacteristics;
@@ -3,15 +3,24 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.SignalTask = SignalTask;
6
7
  exports.SignalTaskBehaviour = SignalTaskBehaviour;
7
- exports.default = SignalTask;
8
- var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
8
+ var _Activity = require("../activity/Activity.js");
9
9
  var _Errors = require("../error/Errors.js");
10
10
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
+ /**
12
+ * Signal task
13
+ * @param {import('moddle-context-serializer').Activity} activityDef
14
+ * @param {import('#types').ContextInstance} context
15
+ */
12
16
  function SignalTask(activityDef, context) {
13
- return new _Activity.default(SignalTaskBehaviour, activityDef, context);
17
+ return new _Activity.Activity(SignalTaskBehaviour, activityDef, context);
14
18
  }
19
+
20
+ /**
21
+ * Signal task behaviour
22
+ * @param {import('#types').Activity} activity
23
+ */
15
24
  function SignalTaskBehaviour(activity) {
16
25
  const {
17
26
  id,
@@ -20,10 +29,16 @@ function SignalTaskBehaviour(activity) {
20
29
  } = activity;
21
30
  this.id = id;
22
31
  this.type = type;
32
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
23
33
  this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
24
34
  this.activity = activity;
25
35
  this.broker = activity.broker;
26
36
  }
37
+
38
+ /**
39
+ * @param {import('#types').ElementBrokerMessage} executeMessage
40
+ * @returns {void}
41
+ */
27
42
  SignalTaskBehaviour.prototype.execute = function execute(executeMessage) {
28
43
  const executeContent = executeMessage.content;
29
44
  const loopCharacteristics = this.loopCharacteristics;
@@ -3,9 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = StandardLoopCharacteristics;
7
- var _LoopCharacteristics = _interopRequireDefault(require("./LoopCharacteristics.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
+ exports.StandardLoopCharacteristics = StandardLoopCharacteristics;
7
+ var _LoopCharacteristics = require("./LoopCharacteristics.js");
8
+ /**
9
+ * Standard loop characteristics
10
+ * @param {import('#types').Activity} activity
11
+ * @param {import('moddle-context-serializer').SerializableElement} loopCharacteristics
12
+ */
9
13
  function StandardLoopCharacteristics(activity, loopCharacteristics) {
10
14
  let {
11
15
  behaviour
@@ -14,7 +18,7 @@ function StandardLoopCharacteristics(activity, loopCharacteristics) {
14
18
  ...behaviour,
15
19
  isSequential: true
16
20
  };
17
- return new _LoopCharacteristics.default(activity, {
21
+ return new _LoopCharacteristics.LoopCharacteristics(activity, {
18
22
  ...loopCharacteristics,
19
23
  behaviour
20
24
  });