bpmn-elements 17.3.0 → 18.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +3 -1
  2. package/dist/Api.js +83 -0
  3. package/dist/Context.js +228 -22
  4. package/dist/Environment.js +111 -31
  5. package/dist/EventBroker.js +57 -1
  6. package/dist/Expressions.js +3 -4
  7. package/dist/MessageFormatter.js +29 -16
  8. package/dist/Timers.js +13 -9
  9. package/dist/Tracker.js +1 -0
  10. package/dist/activity/Activity.js +434 -233
  11. package/dist/activity/ActivityExecution.js +113 -40
  12. package/dist/activity/Dummy.js +6 -1
  13. package/dist/activity/Escalation.js +36 -24
  14. package/dist/activity/ExecutionScope.js +1 -1
  15. package/dist/activity/Message.js +36 -24
  16. package/dist/activity/Signal.js +36 -24
  17. package/dist/activity/outbound-evaluator.js +1 -1
  18. package/dist/condition.js +12 -6
  19. package/dist/constants.js +21 -0
  20. package/dist/definition/Definition.js +182 -64
  21. package/dist/definition/DefinitionExecution.js +195 -82
  22. package/dist/error/BpmnError.js +12 -1
  23. package/dist/error/Errors.js +50 -9
  24. package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
  25. package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
  26. package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
  27. package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
  28. package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
  29. package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
  30. package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
  31. package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
  32. package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
  33. package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
  34. package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
  35. package/dist/eventDefinitions/index.js +20 -21
  36. package/dist/events/BoundaryEvent.js +52 -40
  37. package/dist/events/EndEvent.js +22 -8
  38. package/dist/events/IntermediateCatchEvent.js +26 -8
  39. package/dist/events/IntermediateThrowEvent.js +24 -9
  40. package/dist/events/StartEvent.js +30 -14
  41. package/dist/events/index.js +10 -11
  42. package/dist/flows/Association.js +50 -7
  43. package/dist/flows/MessageFlow.js +49 -10
  44. package/dist/flows/SequenceFlow.js +93 -22
  45. package/dist/flows/index.js +6 -7
  46. package/dist/gateways/EventBasedGateway.js +29 -15
  47. package/dist/gateways/ExclusiveGateway.js +20 -5
  48. package/dist/gateways/InclusiveGateway.js +21 -5
  49. package/dist/gateways/ParallelGateway.js +253 -15
  50. package/dist/gateways/index.js +8 -9
  51. package/dist/getPropertyValue.js +1 -1
  52. package/dist/index.js +42 -43
  53. package/dist/io/BpmnIO.js +15 -1
  54. package/dist/io/EnvironmentDataObject.js +29 -1
  55. package/dist/io/EnvironmentDataStore.js +24 -1
  56. package/dist/io/EnvironmentDataStoreReference.js +24 -1
  57. package/dist/io/InputOutputSpecification.js +21 -11
  58. package/dist/io/Properties.js +28 -17
  59. package/dist/messageHelper.js +41 -4
  60. package/dist/process/Lane.js +15 -4
  61. package/dist/process/Process.js +174 -76
  62. package/dist/process/ProcessExecution.js +362 -177
  63. package/dist/shared.js +2 -0
  64. package/dist/tasks/CallActivity.js +19 -4
  65. package/dist/tasks/LoopCharacteristics.js +94 -9
  66. package/dist/tasks/ReceiveTask.js +36 -21
  67. package/dist/tasks/ScriptTask.js +22 -6
  68. package/dist/tasks/ServiceImplementation.js +7 -4
  69. package/dist/tasks/ServiceTask.js +19 -4
  70. package/dist/tasks/SignalTask.js +19 -4
  71. package/dist/tasks/StandardLoopCharacteristics.js +8 -4
  72. package/dist/tasks/SubProcess.js +44 -29
  73. package/dist/tasks/Task.js +19 -4
  74. package/dist/tasks/Transaction.js +8 -4
  75. package/dist/tasks/index.js +16 -18
  76. package/package.json +31 -13
  77. package/src/Api.js +70 -0
  78. package/src/Context.js +200 -19
  79. package/src/Environment.js +99 -30
  80. package/src/EventBroker.js +46 -1
  81. package/src/Expressions.js +2 -3
  82. package/src/MessageFormatter.js +24 -16
  83. package/src/Timers.js +12 -9
  84. package/src/Tracker.js +1 -0
  85. package/src/activity/Activity.js +372 -218
  86. package/src/activity/ActivityExecution.js +93 -42
  87. package/src/activity/Dummy.js +6 -1
  88. package/src/activity/Escalation.js +25 -18
  89. package/src/activity/ExecutionScope.js +1 -1
  90. package/src/activity/Message.js +25 -18
  91. package/src/activity/Signal.js +25 -18
  92. package/src/activity/outbound-evaluator.js +1 -1
  93. package/src/condition.js +11 -5
  94. package/src/constants.js +15 -0
  95. package/src/definition/Definition.js +157 -62
  96. package/src/definition/DefinitionExecution.js +161 -83
  97. package/src/error/BpmnError.js +11 -1
  98. package/src/error/Errors.js +44 -5
  99. package/src/eventDefinitions/CancelEventDefinition.js +27 -13
  100. package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
  101. package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
  102. package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
  103. package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
  104. package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
  105. package/src/eventDefinitions/LinkEventDefinition.js +34 -120
  106. package/src/eventDefinitions/MessageEventDefinition.js +42 -31
  107. package/src/eventDefinitions/SignalEventDefinition.js +43 -32
  108. package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
  109. package/src/eventDefinitions/TimerEventDefinition.js +53 -35
  110. package/src/eventDefinitions/index.js +10 -23
  111. package/src/events/BoundaryEvent.js +50 -39
  112. package/src/events/EndEvent.js +19 -7
  113. package/src/events/IntermediateCatchEvent.js +24 -8
  114. package/src/events/IntermediateThrowEvent.js +24 -8
  115. package/src/events/StartEvent.js +25 -14
  116. package/src/events/index.js +5 -18
  117. package/src/flows/Association.js +43 -9
  118. package/src/flows/MessageFlow.js +41 -10
  119. package/src/flows/SequenceFlow.js +82 -19
  120. package/src/flows/index.js +3 -4
  121. package/src/gateways/EventBasedGateway.js +27 -15
  122. package/src/gateways/ExclusiveGateway.js +16 -3
  123. package/src/gateways/InclusiveGateway.js +16 -3
  124. package/src/gateways/ParallelGateway.js +301 -10
  125. package/src/gateways/index.js +4 -4
  126. package/src/getPropertyValue.js +1 -1
  127. package/src/index.js +19 -19
  128. package/src/io/BpmnIO.js +13 -1
  129. package/src/io/EnvironmentDataObject.js +26 -1
  130. package/src/io/EnvironmentDataStore.js +22 -1
  131. package/src/io/EnvironmentDataStoreReference.js +22 -1
  132. package/src/io/InputOutputSpecification.js +17 -8
  133. package/src/io/Properties.js +23 -13
  134. package/src/messageHelper.js +36 -4
  135. package/src/process/Lane.js +14 -4
  136. package/src/process/Process.js +154 -72
  137. package/src/process/ProcessExecution.js +326 -175
  138. package/src/shared.js +1 -0
  139. package/src/tasks/CallActivity.js +16 -2
  140. package/src/tasks/LoopCharacteristics.js +77 -11
  141. package/src/tasks/ReceiveTask.js +33 -22
  142. package/src/tasks/ScriptTask.js +17 -3
  143. package/src/tasks/ServiceImplementation.js +6 -3
  144. package/src/tasks/ServiceTask.js +16 -2
  145. package/src/tasks/SignalTask.js +16 -2
  146. package/src/tasks/StandardLoopCharacteristics.js +7 -3
  147. package/src/tasks/SubProcess.js +37 -23
  148. package/src/tasks/Task.js +16 -2
  149. package/src/tasks/Transaction.js +7 -3
  150. package/src/tasks/index.js +8 -9
  151. package/types/bundle-errors.d.ts +1 -0
  152. package/types/bundle.d.ts +97 -0
  153. package/types/index.d.ts +2614 -84
  154. package/types/interfaces.d.ts +636 -0
  155. package/types/types.d.ts +0 -765
package/src/shared.js CHANGED
@@ -8,6 +8,7 @@ export function brokerSafeId(id) {
8
8
  return id.replace(safePattern, '_');
9
9
  }
10
10
 
11
+ /** @param {string} prefix */
11
12
  export function getUniqueId(prefix) {
12
13
  return `${brokerSafeId(prefix)}_${generateId()}`;
13
14
  }
@@ -1,16 +1,26 @@
1
- import Activity from '../activity/Activity.js';
1
+ import { Activity } from '../activity/Activity.js';
2
2
  import { ActivityError } from '../error/Errors.js';
3
3
  import { cloneContent } from '../messageHelper.js';
4
4
 
5
- export default function CallActivity(activityDef, context) {
5
+ /**
6
+ * Call activity
7
+ * @param {import('moddle-context-serializer').Activity} activityDef
8
+ * @param {import('#types').ContextInstance} context
9
+ */
10
+ export function CallActivity(activityDef, context) {
6
11
  return new Activity(CallActivityBehaviour, activityDef, context);
7
12
  }
8
13
 
14
+ /**
15
+ * Call activity behaviour
16
+ * @param {import('#types').Activity} activity
17
+ */
9
18
  export function CallActivityBehaviour(activity) {
10
19
  const { id, type, behaviour = {} } = activity;
11
20
  this.id = id;
12
21
  this.type = type;
13
22
  this.calledElement = behaviour.calledElement;
23
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
14
24
  this.loopCharacteristics =
15
25
  behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
16
26
  this.activity = activity;
@@ -18,6 +28,10 @@ export function CallActivityBehaviour(activity) {
18
28
  this.environment = activity.environment;
19
29
  }
20
30
 
31
+ /**
32
+ * @param {import('#types').ElementBrokerMessage} executeMessage
33
+ * @returns {void}
34
+ */
21
35
  CallActivityBehaviour.prototype.execute = function execute(executeMessage) {
22
36
  const executeContent = executeMessage.content;
23
37
  const loopCharacteristics = this.loopCharacteristics;
@@ -1,18 +1,26 @@
1
1
  import { RunError } from '../error/Errors.js';
2
2
  import { cloneContent, cloneMessage, unshiftParent, cloneParent } from '../messageHelper.js';
3
3
 
4
- export default function LoopCharacteristics(activity, loopCharacteristics) {
4
+ /**
5
+ * Loop characteristics
6
+ * @param {import('#types').Activity} activity
7
+ * @param {import('moddle-context-serializer').SerializableElement} loopCharacteristics
8
+ */
9
+ export function LoopCharacteristics(activity, loopCharacteristics) {
5
10
  this.activity = activity;
6
11
  this.loopCharacteristics = loopCharacteristics;
7
12
  const { type = 'LoopCharacteristics', behaviour = {} } = loopCharacteristics;
8
13
  this.type = type;
9
14
  const { isSequential = false, collection } = behaviour;
15
+ /** @type {boolean} */
10
16
  this.isSequential = isSequential;
17
+ /** @type {string | undefined} */
11
18
  this.collection = collection;
12
19
 
13
20
  let completionCondition, startCondition, loopCardinality;
14
21
  if ('loopCardinality' in behaviour) loopCardinality = behaviour.loopCardinality;
15
22
  else if ('loopMaximum' in behaviour) loopCardinality = behaviour.loopMaximum;
23
+ /** @type {number | undefined} */
16
24
  this.loopCardinality = loopCardinality;
17
25
 
18
26
  if (behaviour.loopCondition) {
@@ -25,15 +33,21 @@ export default function LoopCharacteristics(activity, loopCharacteristics) {
25
33
 
26
34
  if (collection) {
27
35
  this.loopType = 'collection';
36
+ /** @type {string | undefined} */
28
37
  this.elementVariable = behaviour.elementVariable || 'item';
29
38
  } else if (completionCondition) this.loopType = 'complete condition';
30
39
  else if (startCondition) this.loopType = 'start condition';
31
40
  else if (loopCardinality) this.loopType = 'cardinality';
32
41
 
42
+ /** @type {Characteristics} */
33
43
  this.characteristics = null;
34
44
  this.execution = null;
35
45
  }
36
46
 
47
+ /**
48
+ * @param {import('#types').ElementBrokerMessage} executeMessage
49
+ * @returns {void}
50
+ */
37
51
  LoopCharacteristics.prototype.execute = function execute(executeMessage) {
38
52
  if (!executeMessage) throw new TypeError('LoopCharacteristics execution requires message');
39
53
  const chr = (this.characteristics = this.characteristics || new Characteristics(this.activity, this.loopCharacteristics, executeMessage));
@@ -45,12 +59,20 @@ LoopCharacteristics.prototype.execute = function execute(executeMessage) {
45
59
  return execution.execute(executeMessage);
46
60
  };
47
61
 
62
+ /**
63
+ * @param {import('#types').Activity} activity
64
+ * @param {Characteristics} characteristics
65
+ */
48
66
  function SequentialLoopCharacteristics(activity, characteristics) {
49
67
  this.activity = activity;
50
68
  this.id = activity.id;
51
69
  this.characteristics = characteristics;
52
70
  }
53
71
 
72
+ /**
73
+ * @param {import('#types').ElementBrokerMessage} executeMessage
74
+ * @returns {void}
75
+ */
54
76
  SequentialLoopCharacteristics.prototype.execute = function execute(executeMessage) {
55
77
  const { routingKey: executeRoutingKey, redelivered: isRedelivered } = executeMessage.fields || {};
56
78
  const chr = this.characteristics;
@@ -73,11 +95,11 @@ SequentialLoopCharacteristics.prototype._startNext = function startNext(index, i
73
95
  if (!content) return;
74
96
 
75
97
  if (chr.isStartConditionMet({ content })) {
76
- chr.debug('start condition met');
98
+ chr._debug('start condition met');
77
99
  return;
78
100
  }
79
101
 
80
- chr.debug(`${ignoreIfExecuting ? 'resume' : 'start'} sequential iteration index ${content.index}`);
102
+ chr._debug(`${ignoreIfExecuting ? 'resume' : 'start'} sequential iteration index ${content.index}`);
81
103
  const broker = this.activity.broker;
82
104
  broker.publish('execution', 'execute.iteration.next', {
83
105
  ...content,
@@ -108,14 +130,18 @@ SequentialLoopCharacteristics.prototype._onCompleteMessage = function onComplete
108
130
  });
109
131
 
110
132
  if (chr.isCompletionConditionMet(message, loopOutput)) {
111
- chr.debug('complete condition met');
133
+ chr._debug('complete condition met');
112
134
  } else if (this._startNext(content.index + 1)) return;
113
135
 
114
- chr.debug('sequential loop completed');
136
+ chr._debug('sequential loop completed');
115
137
 
116
138
  return chr.complete(content);
117
139
  };
118
140
 
141
+ /**
142
+ * @param {import('#types').Activity} activity
143
+ * @param {Characteristics} characteristics
144
+ */
119
145
  function ParallelLoopCharacteristics(activity, characteristics) {
120
146
  this.activity = activity;
121
147
  this.id = activity.id;
@@ -125,6 +151,10 @@ function ParallelLoopCharacteristics(activity, characteristics) {
125
151
  this.discarded = 0;
126
152
  }
127
153
 
154
+ /**
155
+ * @param {import('#types').ElementBrokerMessage} executeMessage
156
+ * @returns {void}
157
+ */
128
158
  ParallelLoopCharacteristics.prototype.execute = function execute(executeMessage) {
129
159
  const chr = this.characteristics;
130
160
  if (!chr.cardinality) throw new RunError(`<${this.id}> cardinality or collection is required in parallel loops`, executeMessage);
@@ -150,7 +180,7 @@ ParallelLoopCharacteristics.prototype._startBatch = function startBatch() {
150
180
 
151
181
  let startContent = chr.next(this.index);
152
182
  do {
153
- chr.debug(`start parallel iteration index ${this.index}`);
183
+ chr._debug(`start parallel iteration index ${this.index}`);
154
184
  batch.add(startContent);
155
185
  this.running++;
156
186
  this.index++;
@@ -211,6 +241,12 @@ ParallelLoopCharacteristics.prototype._onCompleteMessage = function onCompleteMe
211
241
  }
212
242
  };
213
243
 
244
+ /**
245
+ * Per-execution snapshot of resolved loop characteristics (cardinality, collection, conditions).
246
+ * @param {import('#types').Activity} activity
247
+ * @param {import('moddle-context-serializer').SerializableElement} loopCharacteristics
248
+ * @param {import('#types').ElementBrokerMessage} executeMessage
249
+ */
214
250
  function Characteristics(activity, loopCharacteristics, executeMessage) {
215
251
  this.activity = activity;
216
252
  const behaviour = (this.behaviour = loopCharacteristics.behaviour || {});
@@ -221,27 +257,31 @@ function Characteristics(activity, loopCharacteristics, executeMessage) {
221
257
  this.broker = activity.broker;
222
258
  this.parentExecutionId = executeMessage.content.executionId;
223
259
 
260
+ /** @type {boolean} */
224
261
  this.isSequential = behaviour.isSequential || false;
225
262
  this.output = executeMessage.content.output || [];
226
263
  this.parent = unshiftParent(executeMessage.content.parent, executeMessage.content);
227
264
 
228
- if ('loopCardinality' in behaviour) this.loopCardinality = behaviour.loopCardinality;
229
- else if ('loopMaximum' in behaviour) this.loopCardinality = behaviour.loopMaximum;
265
+ if ('loopCardinality' in behaviour) this.loopCardinality = /** @type {number} */ (behaviour.loopCardinality);
266
+ else if ('loopMaximum' in behaviour) this.loopCardinality = /** @type {number} */ (behaviour.loopMaximum);
230
267
 
231
268
  if (behaviour.loopCondition) {
232
- if (behaviour.testBefore) this.startCondition = behaviour.loopCondition;
233
- else this.completionCondition = behaviour.loopCondition;
269
+ if (behaviour.testBefore) this.startCondition = /** @type {string} */ (behaviour.loopCondition);
270
+ else this.completionCondition = /** @type {string} */ (behaviour.loopCondition);
234
271
  }
235
272
  if (behaviour.completionCondition) {
273
+ /** @type {string} */
236
274
  this.completionCondition = behaviour.completionCondition;
237
275
  }
238
276
 
239
277
  const collection = (this.collection = this.getCollection());
240
278
  if (collection) {
279
+ /** @type {string} */
241
280
  this.elementVariable = behaviour.elementVariable || 'item';
242
281
  }
243
282
  this.cardinality = this.getCardinality(collection);
244
283
 
284
+ /** @private */
245
285
  this.onApiMessage = this.onApiMessage.bind(this);
246
286
 
247
287
  const environment = activity.environment;
@@ -249,6 +289,7 @@ function Characteristics(activity, loopCharacteristics, executeMessage) {
249
289
  this.batchSize = environment.settings.batchSize || 50;
250
290
  }
251
291
 
292
+ /** @returns {import('#types').ElementMessageContent} */
252
293
  Characteristics.prototype.getContent = function getContent() {
253
294
  return {
254
295
  ...cloneContent(this.message.content),
@@ -258,6 +299,10 @@ Characteristics.prototype.getContent = function getContent() {
258
299
  };
259
300
  };
260
301
 
302
+ /**
303
+ * @param {number} index
304
+ * @returns {import('#types').ElementMessageContent}
305
+ */
261
306
  Characteristics.prototype.next = function next(index) {
262
307
  const cardinality = this.cardinality;
263
308
  if (cardinality > 0 && index >= cardinality) return;
@@ -281,6 +326,10 @@ Characteristics.prototype.next = function next(index) {
281
326
  return content;
282
327
  };
283
328
 
329
+ /**
330
+ * @param {any} [collection]
331
+ * @returns {number | undefined} cardinality
332
+ */
284
333
  Characteristics.prototype.getCardinality = function getCardinality(collection) {
285
334
  const collectionLen = this.collection && Array.isArray(collection) ? collection.length : undefined;
286
335
  if (!this.loopCardinality) {
@@ -294,22 +343,34 @@ Characteristics.prototype.getCardinality = function getCardinality(collection) {
294
343
  return Number(value);
295
344
  };
296
345
 
346
+ /** @returns {Array | undefined} */
297
347
  Characteristics.prototype.getCollection = function getCollection() {
298
348
  const collectionExpression = this.behaviour.collection;
299
349
  if (!collectionExpression) return;
300
350
  return this.activity.environment.resolveExpression(collectionExpression, this.message);
301
351
  };
302
352
 
353
+ /**
354
+ * @param {import('#types').ElementBrokerMessage} message
355
+ */
303
356
  Characteristics.prototype.isStartConditionMet = function isStartConditionMet(message) {
304
357
  if (!this.startCondition) return false;
305
358
  return this.activity.environment.resolveExpression(this.startCondition, cloneMessage(message));
306
359
  };
307
360
 
361
+ /**
362
+ * @param {import('#types').ElementBrokerMessage} message
363
+ */
308
364
  Characteristics.prototype.isCompletionConditionMet = function isCompletionConditionMet(message) {
309
365
  if (!this.completionCondition) return false;
310
366
  return this.activity.environment.resolveExpression(this.completionCondition, cloneMessage(message, { loopOutput: this.output }));
311
367
  };
312
368
 
369
+ /**
370
+ * @param {import('#types').ElementMessageContent} content
371
+ * @param {boolean} [allDiscarded]
372
+ * @returns {void}
373
+ */
313
374
  Characteristics.prototype.complete = function complete(content, allDiscarded) {
314
375
  this.stop();
315
376
 
@@ -320,6 +381,9 @@ Characteristics.prototype.complete = function complete(content, allDiscarded) {
320
381
  });
321
382
  };
322
383
 
384
+ /**
385
+ * @param {import('#types').ElementBrokerMessage} onIterationCompleteMessage
386
+ */
323
387
  Characteristics.prototype.subscribe = function subscribe(onIterationCompleteMessage) {
324
388
  this.broker.subscribeTmp(
325
389
  'api',
@@ -346,6 +410,7 @@ Characteristics.prototype.subscribe = function subscribe(onIterationCompleteMess
346
410
  }
347
411
  };
348
412
 
413
+ /** @internal */
349
414
  Characteristics.prototype.onApiMessage = function onApiMessage(_, message) {
350
415
  switch (message.properties.type) {
351
416
  case 'stop':
@@ -360,6 +425,7 @@ Characteristics.prototype.stop = function stop() {
360
425
  this.broker.cancel('_api-multi-instance-tag');
361
426
  };
362
427
 
363
- Characteristics.prototype.debug = function debug(msg) {
428
+ /** @internal */
429
+ Characteristics.prototype._debug = function debug(msg) {
364
430
  this.logger.debug(`<${this.parentExecutionId} (${this.id})> ${msg}`);
365
431
  };
@@ -1,12 +1,13 @@
1
- import Activity from '../activity/Activity.js';
1
+ import { Activity } from '../activity/Activity.js';
2
2
  import { cloneContent } from '../messageHelper.js';
3
-
4
- const kCompleted = Symbol.for('completed');
5
- const kExecuteMessage = Symbol.for('executeMessage');
6
- const kReferenceElement = Symbol.for('referenceElement');
7
- const kReferenceInfo = Symbol.for('referenceInfo');
8
-
9
- export default function ReceiveTask(activityDef, context) {
3
+ import { K_COMPLETED, K_EXECUTE_MESSAGE, K_REFERENCE_ELEMENT, K_REFERENCE_INFO } from '../constants.js';
4
+
5
+ /**
6
+ * Receive task
7
+ * @param {import('moddle-context-serializer').Activity} activityDef
8
+ * @param {import('#types').ContextInstance} context
9
+ */
10
+ export function ReceiveTask(activityDef, context) {
10
11
  const task = new Activity(ReceiveTaskBehaviour, activityDef, context);
11
12
 
12
13
  task.broker.assertQueue('message', { autoDelete: false, durable: true });
@@ -15,26 +16,36 @@ export default function ReceiveTask(activityDef, context) {
15
16
  return task;
16
17
  }
17
18
 
19
+ /**
20
+ * Receive task behaviour
21
+ * @param {import('#types').Activity} activity
22
+ */
18
23
  export function ReceiveTaskBehaviour(activity) {
19
24
  const { id, type, behaviour } = activity;
20
25
 
21
26
  this.id = id;
22
27
  this.type = type;
23
28
 
24
- const reference = (this.reference = {
29
+ /** @type {import('#types').EventReference} */
30
+ this.reference = {
25
31
  name: 'anonymous',
26
32
  ...behaviour.messageRef,
27
33
  referenceType: 'message',
28
- });
34
+ };
29
35
 
36
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined } */
30
37
  this.loopCharacteristics =
31
38
  behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
32
39
  this.activity = activity;
33
40
  this.broker = activity.broker;
34
41
 
35
- this[kReferenceElement] = reference.id && activity.getActivityById(reference.id);
42
+ this[K_REFERENCE_ELEMENT] = this.reference.id && activity.getActivityById(this.reference.id);
36
43
  }
37
44
 
45
+ /**
46
+ * @param {import('#types').ElementBrokerMessage} executeMessage
47
+ * @returns {void}
48
+ */
38
49
  ReceiveTaskBehaviour.prototype.execute = function execute(executeMessage) {
39
50
  return new ReceiveTaskExecution(this).execute(executeMessage);
40
51
  };
@@ -47,19 +58,19 @@ function ReceiveTaskExecution(parent) {
47
58
  this.reference = reference;
48
59
  this.broker = broker;
49
60
  this.loopCharacteristics = loopCharacteristics;
50
- this.referenceElement = parent[kReferenceElement];
61
+ this.referenceElement = parent[K_REFERENCE_ELEMENT];
51
62
 
52
- this[kCompleted] = false;
63
+ this[K_COMPLETED] = false;
53
64
  }
54
65
 
55
66
  ReceiveTaskExecution.prototype.execute = function execute(executeMessage) {
56
- this[kExecuteMessage] = executeMessage;
67
+ this[K_EXECUTE_MESSAGE] = executeMessage;
57
68
 
58
69
  const executeContent = executeMessage.content;
59
70
  const { executionId, isRootScope } = executeContent;
60
71
  this.executionId = executionId;
61
72
 
62
- const info = (this[kReferenceInfo] = this._getReferenceInfo(executeMessage));
73
+ const info = (this[K_REFERENCE_INFO] = this._getReferenceInfo(executeMessage));
63
74
 
64
75
  if (isRootScope) {
65
76
  this._setupMessageHandling(executionId);
@@ -76,7 +87,7 @@ ReceiveTaskExecution.prototype.execute = function execute(executeMessage) {
76
87
  consumerTag: `_onmessage-${executionId}`,
77
88
  });
78
89
 
79
- if (this[kCompleted]) return;
90
+ if (this[K_COMPLETED]) return;
80
91
 
81
92
  broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
82
93
  noAck: true,
@@ -93,7 +104,7 @@ ReceiveTaskExecution.prototype._onCatchMessage = function onCatchMessage(routing
93
104
  const content = message.content;
94
105
 
95
106
  const { id: signalId, executionId: signalExecutionId } = content.message || {};
96
- const { message: referenceMessage, description } = this[kReferenceInfo];
107
+ const { message: referenceMessage, description } = this[K_REFERENCE_INFO];
97
108
 
98
109
  if ((!referenceMessage.id && signalId) || signalExecutionId) {
99
110
  if (this.loopCharacteristics && signalExecutionId !== this.executionId) return;
@@ -106,7 +117,7 @@ ReceiveTaskExecution.prototype._onCatchMessage = function onCatchMessage(routing
106
117
 
107
118
  const { type: messageType, correlationId } = message.properties;
108
119
  const broker = this.broker;
109
- const executeContent = this[kExecuteMessage].content;
120
+ const executeContent = this[K_EXECUTE_MESSAGE].content;
110
121
 
111
122
  broker.publish('event', 'activity.consumed', cloneContent(executeContent, { message: { ...message.content.message } }), {
112
123
  correlationId,
@@ -128,9 +139,9 @@ ReceiveTaskExecution.prototype._onApiMessage = function onApiMessage(routingKey,
128
139
  return this._complete(message.content.message, { correlationId });
129
140
  }
130
141
  case 'discard': {
131
- this[kCompleted] = true;
142
+ this[K_COMPLETED] = true;
132
143
  this._stop();
133
- return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content), { correlationId });
144
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_EXECUTE_MESSAGE].content), { correlationId });
134
145
  }
135
146
  case 'stop': {
136
147
  return this._stop();
@@ -139,9 +150,9 @@ ReceiveTaskExecution.prototype._onApiMessage = function onApiMessage(routingKey,
139
150
  };
140
151
 
141
152
  ReceiveTaskExecution.prototype._complete = function complete(output, options) {
142
- this[kCompleted] = true;
153
+ this[K_COMPLETED] = true;
143
154
  this._stop();
144
- return this.broker.publish('execution', 'execute.completed', cloneContent(this[kExecuteMessage].content, { output }), options);
155
+ return this.broker.publish('execution', 'execute.completed', cloneContent(this[K_EXECUTE_MESSAGE].content, { output }), options);
145
156
  };
146
157
 
147
158
  ReceiveTaskExecution.prototype._stop = function stop() {
@@ -1,12 +1,21 @@
1
- import Activity from '../activity/Activity.js';
2
- import ExecutionScope from '../activity/ExecutionScope.js';
1
+ import { Activity } from '../activity/Activity.js';
2
+ import { ExecutionScope } from '../activity/ExecutionScope.js';
3
3
  import { ActivityError } from '../error/Errors.js';
4
4
  import { cloneContent, cloneMessage } from '../messageHelper.js';
5
5
 
6
- export default function ScriptTask(activityDef, context) {
6
+ /**
7
+ * Script task
8
+ * @param {import('moddle-context-serializer').Activity} activityDef
9
+ * @param {import('#types').ContextInstance} context
10
+ */
11
+ export function ScriptTask(activityDef, context) {
7
12
  return new Activity(ScriptTaskBehaviour, activityDef, context);
8
13
  }
9
14
 
15
+ /**
16
+ * Script task behaviour
17
+ * @param {import('#types').Activity} activity
18
+ */
10
19
  export function ScriptTaskBehaviour(activity) {
11
20
  const { id, type, behaviour } = activity;
12
21
 
@@ -14,6 +23,7 @@ export function ScriptTaskBehaviour(activity) {
14
23
  this.type = type;
15
24
  this.scriptFormat = behaviour.scriptFormat;
16
25
 
26
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
17
27
  this.loopCharacteristics =
18
28
  behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
19
29
  this.activity = activity;
@@ -22,6 +32,10 @@ export function ScriptTaskBehaviour(activity) {
22
32
  environment.registerScript(activity);
23
33
  }
24
34
 
35
+ /**
36
+ * @param {import('#types').ElementBrokerMessage} executeMessage
37
+ * @returns {void}
38
+ */
25
39
  ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
26
40
  const executeContent = executeMessage.content;
27
41
  const loopCharacteristics = this.loopCharacteristics;
@@ -1,6 +1,9 @@
1
- import ExecutionScope from '../activity/ExecutionScope.js';
2
-
3
- export default function ServiceImplementation(activity) {
1
+ import { ExecutionScope } from '../activity/ExecutionScope.js';
2
+ /**
3
+ * Service implementation
4
+ * @param {import('#types').Activity} activity
5
+ */
6
+ export function ServiceImplementation(activity) {
4
7
  this.type = `${activity.type}:implementation`;
5
8
  this.implementation = activity.behaviour.implementation;
6
9
  this.activity = activity;
@@ -1,16 +1,26 @@
1
- import Activity from '../activity/Activity.js';
1
+ import { Activity } from '../activity/Activity.js';
2
2
  import { ActivityError } from '../error/Errors.js';
3
3
  import { cloneMessage, cloneContent } from '../messageHelper.js';
4
4
 
5
- export default function ServiceTask(activityDef, context) {
5
+ /**
6
+ * Service task
7
+ * @param {import('moddle-context-serializer').Activity} activityDef
8
+ * @param {import('#types').ContextInstance} context
9
+ */
10
+ export function ServiceTask(activityDef, context) {
6
11
  return new Activity(ServiceTaskBehaviour, activityDef, context);
7
12
  }
8
13
 
14
+ /**
15
+ * Service task behaviour
16
+ * @param {import('#types').Activity} activity
17
+ */
9
18
  export function ServiceTaskBehaviour(activity) {
10
19
  const { id, type, behaviour } = activity;
11
20
 
12
21
  this.id = id;
13
22
  this.type = type;
23
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
14
24
  this.loopCharacteristics =
15
25
  behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
16
26
  this.activity = activity;
@@ -18,6 +28,10 @@ export function ServiceTaskBehaviour(activity) {
18
28
  this.broker = activity.broker;
19
29
  }
20
30
 
31
+ /**
32
+ * @param {import('#types').ElementBrokerMessage} executeMessage
33
+ * @returns {void}
34
+ */
21
35
  ServiceTaskBehaviour.prototype.execute = function execute(executeMessage) {
22
36
  const executeContent = executeMessage.content;
23
37
  const loopCharacteristics = this.loopCharacteristics;
@@ -1,22 +1,36 @@
1
- import Activity from '../activity/Activity.js';
1
+ import { Activity } from '../activity/Activity.js';
2
2
  import { ActivityError } from '../error/Errors.js';
3
3
  import { cloneContent } from '../messageHelper.js';
4
4
 
5
- export default function SignalTask(activityDef, context) {
5
+ /**
6
+ * Signal task
7
+ * @param {import('moddle-context-serializer').Activity} activityDef
8
+ * @param {import('#types').ContextInstance} context
9
+ */
10
+ export function SignalTask(activityDef, context) {
6
11
  return new Activity(SignalTaskBehaviour, activityDef, context);
7
12
  }
8
13
 
14
+ /**
15
+ * Signal task behaviour
16
+ * @param {import('#types').Activity} activity
17
+ */
9
18
  export function SignalTaskBehaviour(activity) {
10
19
  const { id, type, behaviour } = activity;
11
20
 
12
21
  this.id = id;
13
22
  this.type = type;
23
+ /** @type {import('./LoopCharacteristics.js').LoopCharacteristics | undefined} */
14
24
  this.loopCharacteristics =
15
25
  behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
16
26
  this.activity = activity;
17
27
  this.broker = activity.broker;
18
28
  }
19
29
 
30
+ /**
31
+ * @param {import('#types').ElementBrokerMessage} executeMessage
32
+ * @returns {void}
33
+ */
20
34
  SignalTaskBehaviour.prototype.execute = function execute(executeMessage) {
21
35
  const executeContent = executeMessage.content;
22
36
  const loopCharacteristics = this.loopCharacteristics;
@@ -1,6 +1,10 @@
1
- import LoopCharacteristics from './LoopCharacteristics.js';
2
-
3
- export default function StandardLoopCharacteristics(activity, loopCharacteristics) {
1
+ import { LoopCharacteristics } from './LoopCharacteristics.js';
2
+ /**
3
+ * Standard loop characteristics
4
+ * @param {import('#types').Activity} activity
5
+ * @param {import('moddle-context-serializer').SerializableElement} loopCharacteristics
6
+ */
7
+ export function StandardLoopCharacteristics(activity, loopCharacteristics) {
4
8
  let { behaviour } = loopCharacteristics;
5
9
  behaviour = { ...behaviour, isSequential: true };
6
10
  return new LoopCharacteristics(activity, { ...loopCharacteristics, behaviour });