bpmn-elements 8.2.0 → 8.2.2

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 (74) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/index.js +0 -49
  3. package/dist/src/Api.js +4 -19
  4. package/dist/src/Context.js +0 -35
  5. package/dist/src/Environment.js +18 -44
  6. package/dist/src/EventBroker.js +8 -27
  7. package/dist/src/Expressions.js +0 -13
  8. package/dist/src/ExtensionsMapper.js +0 -12
  9. package/dist/src/MessageFormatter.js +0 -33
  10. package/dist/src/Scripts.js +2 -9
  11. package/dist/src/Timers.js +0 -9
  12. package/dist/src/activity/Activity.js +39 -243
  13. package/dist/src/activity/ActivityExecution.js +8 -76
  14. package/dist/src/activity/Dummy.js +2 -3
  15. package/dist/src/activity/Escalation.js +4 -4
  16. package/dist/src/activity/ExecutionScope.js +0 -4
  17. package/dist/src/activity/Message.js +4 -4
  18. package/dist/src/activity/Signal.js +4 -4
  19. package/dist/src/definition/Definition.js +12 -133
  20. package/dist/src/definition/DefinitionExecution.js +10 -160
  21. package/dist/src/error/BpmnError.js +2 -3
  22. package/dist/src/error/Errors.js +0 -16
  23. package/dist/src/eventDefinitions/CancelEventDefinition.js +2 -35
  24. package/dist/src/eventDefinitions/CompensateEventDefinition.js +3 -34
  25. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +3 -42
  26. package/dist/src/eventDefinitions/ErrorEventDefinition.js +11 -41
  27. package/dist/src/eventDefinitions/EscalationEventDefinition.js +7 -37
  28. package/dist/src/eventDefinitions/EventDefinitionExecution.js +0 -30
  29. package/dist/src/eventDefinitions/LinkEventDefinition.js +11 -37
  30. package/dist/src/eventDefinitions/MessageEventDefinition.js +11 -44
  31. package/dist/src/eventDefinitions/SignalEventDefinition.js +9 -46
  32. package/dist/src/eventDefinitions/TerminateEventDefinition.js +0 -3
  33. package/dist/src/eventDefinitions/TimerEventDefinition.js +8 -52
  34. package/dist/src/events/BoundaryEvent.js +4 -44
  35. package/dist/src/events/EndEvent.js +2 -11
  36. package/dist/src/events/IntermediateCatchEvent.js +0 -13
  37. package/dist/src/events/IntermediateThrowEvent.js +2 -11
  38. package/dist/src/events/StartEvent.js +5 -25
  39. package/dist/src/flows/Association.js +4 -27
  40. package/dist/src/flows/MessageFlow.js +6 -18
  41. package/dist/src/flows/SequenceFlow.js +4 -39
  42. package/dist/src/gateways/EventBasedGateway.js +0 -21
  43. package/dist/src/gateways/ExclusiveGateway.js +0 -6
  44. package/dist/src/gateways/InclusiveGateway.js +0 -6
  45. package/dist/src/gateways/ParallelGateway.js +2 -7
  46. package/dist/src/getPropertyValue.js +0 -30
  47. package/dist/src/io/BpmnIO.js +2 -7
  48. package/dist/src/io/EnvironmentDataObject.js +0 -8
  49. package/dist/src/io/EnvironmentDataStore.js +0 -8
  50. package/dist/src/io/EnvironmentDataStoreReference.js +0 -8
  51. package/dist/src/io/InputOutputSpecification.js +12 -37
  52. package/dist/src/io/Properties.js +6 -39
  53. package/dist/src/messageHelper.js +10 -23
  54. package/dist/src/process/Process.js +10 -112
  55. package/dist/src/process/ProcessExecution.js +24 -170
  56. package/dist/src/shared.js +0 -7
  57. package/dist/src/tasks/CallActivity.js +2 -23
  58. package/dist/src/tasks/LoopCharacteristics.js +16 -67
  59. package/dist/src/tasks/ReceiveTask.js +8 -48
  60. package/dist/src/tasks/ScriptTask.js +1 -15
  61. package/dist/src/tasks/ServiceImplementation.js +0 -4
  62. package/dist/src/tasks/ServiceTask.js +0 -20
  63. package/dist/src/tasks/SignalTask.js +2 -21
  64. package/dist/src/tasks/StandardLoopCharacteristics.js +4 -5
  65. package/dist/src/tasks/SubProcess.js +4 -52
  66. package/dist/src/tasks/Task.js +0 -8
  67. package/dist/src/tasks/Transaction.js +0 -3
  68. package/package.json +7 -7
  69. package/src/Context.js +0 -1
  70. package/src/activity/Activity.js +1 -1
  71. package/src/gateways/EventBasedGateway.js +0 -1
  72. package/src/io/InputOutputSpecification.js +0 -1
  73. package/src/process/ProcessExecution.js +8 -1
  74. package/src/tasks/StandardLoopCharacteristics.js +0 -1
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _Api = require("../Api");
9
-
10
8
  var _messageHelper = require("../messageHelper");
11
-
12
9
  var _shared = require("../shared");
13
-
14
10
  var _default = ProcessExecution;
15
11
  exports.default = _default;
16
12
  const kActivated = Symbol.for('activated');
@@ -22,7 +18,6 @@ const kMessageHandlers = Symbol.for('messageHandlers');
22
18
  const kParent = Symbol.for('parent');
23
19
  const kStatus = Symbol.for('status');
24
20
  const kStopped = Symbol.for('stopped');
25
-
26
21
  function ProcessExecution(parentActivity, context) {
27
22
  const {
28
23
  id,
@@ -65,45 +60,35 @@ function ProcessExecution(parentActivity, context) {
65
60
  onMessageFlowEvent: this._onMessageFlowEvent.bind(this)
66
61
  };
67
62
  }
68
-
69
63
  const proto = ProcessExecution.prototype;
70
64
  Object.defineProperty(proto, 'stopped', {
71
65
  enumerable: true,
72
-
73
66
  get() {
74
67
  return this[kStopped];
75
68
  }
76
-
77
69
  });
78
70
  Object.defineProperty(proto, 'completed', {
79
71
  enumerable: true,
80
-
81
72
  get() {
82
73
  return this[kCompleted];
83
74
  }
84
-
85
75
  });
86
76
  Object.defineProperty(proto, 'status', {
87
77
  enumerable: true,
88
-
89
78
  get() {
90
79
  return this[kStatus];
91
80
  }
92
-
93
81
  });
94
82
  Object.defineProperty(proto, 'postponedCount', {
95
83
  get() {
96
84
  return this[kElements].postponed.length;
97
85
  }
98
-
99
86
  });
100
87
  Object.defineProperty(proto, 'isRunning', {
101
88
  get() {
102
89
  return this[kActivated];
103
90
  }
104
-
105
91
  });
106
-
107
92
  proto.execute = function execute(executeMessage) {
108
93
  if (!executeMessage) throw new Error('Process execution requires message');
109
94
  if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Process execution requires execution id');
@@ -118,37 +103,26 @@ proto.execute = function execute(executeMessage) {
118
103
  durable: true,
119
104
  autoDelete: false
120
105
  });
121
-
122
106
  if (executeMessage.fields.redelivered) {
123
107
  return this.resume();
124
108
  }
125
-
126
109
  this._debug(`execute ${this.isSubProcess ? 'sub process' : 'process'}`);
127
-
128
110
  this._activate();
129
-
130
111
  this._start();
131
-
132
112
  return true;
133
113
  };
134
-
135
114
  proto.resume = function resume() {
136
115
  this._debug(`resume process execution at ${this.status}`);
137
-
138
116
  if (this[kCompleted]) return this._complete('completed');
139
-
140
117
  this._activate();
141
-
142
118
  const {
143
119
  startActivities,
144
120
  detachedActivities,
145
121
  postponed
146
122
  } = this[kElements];
147
-
148
123
  if (startActivities.length > 1) {
149
124
  for (const a of startActivities) a.shake();
150
125
  }
151
-
152
126
  postponed.splice(0);
153
127
  detachedActivities.splice(0);
154
128
  this[kActivityQ].consume(this[kMessageHandlers].onChildMessage, {
@@ -156,18 +130,15 @@ proto.resume = function resume() {
156
130
  consumerTag: `_process-activity-${this.executionId}`
157
131
  });
158
132
  if (this[kCompleted]) return;
159
-
160
133
  switch (this.status) {
161
134
  case 'init':
162
135
  return this._start();
163
-
164
136
  case 'executing':
165
137
  {
166
138
  if (!postponed.length) return this._complete('completed');
167
139
  break;
168
140
  }
169
141
  }
170
-
171
142
  for (const {
172
143
  content
173
144
  } of postponed.slice()) {
@@ -177,43 +148,34 @@ proto.resume = function resume() {
177
148
  activity.resume();
178
149
  }
179
150
  };
180
-
181
151
  proto.recover = function recover(state) {
182
152
  if (!state) return this;
183
153
  this.executionId = state.executionId;
184
154
  this[kStopped] = state.stopped;
185
155
  this[kCompleted] = state.completed;
186
156
  this[kStatus] = state.status;
187
-
188
157
  this._debug(`recover process execution at ${this.status}`);
189
-
190
158
  if (state.messageFlows) {
191
159
  for (const flowState of state.messageFlows) {
192
160
  const flow = this._getMessageFlowById(flowState.id);
193
-
194
161
  if (!flow) continue;
195
162
  flow.recover(flowState);
196
163
  }
197
164
  }
198
-
199
165
  if (state.associations) {
200
166
  for (const associationState of state.associations) {
201
167
  const association = this._getAssociationById(associationState.id);
202
-
203
168
  if (!association) continue;
204
169
  association.recover(associationState);
205
170
  }
206
171
  }
207
-
208
172
  if (state.flows) {
209
173
  for (const flowState of state.flows) {
210
174
  const flow = this._getFlowById(flowState.id);
211
-
212
175
  if (!flow) continue;
213
176
  flow.recover(flowState);
214
177
  }
215
178
  }
216
-
217
179
  if (state.children) {
218
180
  for (const childState of state.children) {
219
181
  const child = this.getActivityById(childState.id);
@@ -221,32 +183,25 @@ proto.recover = function recover(state) {
221
183
  child.recover(childState);
222
184
  }
223
185
  }
224
-
225
186
  return this;
226
187
  };
227
-
228
188
  proto.shake = function shake(fromId) {
229
189
  let executing = true;
230
190
  const id = this.id;
231
-
232
191
  if (!this.isRunning) {
233
192
  executing = false;
234
193
  this.executionId = (0, _shared.getUniqueId)(id);
235
-
236
194
  this._activate();
237
195
  }
238
-
239
196
  const toShake = fromId ? [this.getActivityById(fromId)].filter(Boolean) : this[kElements].startActivities;
240
197
  const result = {};
241
198
  this.broker.subscribeTmp('event', '*.shake.*', (routingKey, {
242
199
  content
243
200
  }) => {
244
201
  let isLooped = false;
245
-
246
202
  switch (routingKey) {
247
203
  case 'flow.shake.loop':
248
204
  isLooped = true;
249
-
250
205
  case 'activity.shake.end':
251
206
  {
252
207
  const {
@@ -255,7 +210,8 @@ proto.shake = function shake(fromId) {
255
210
  } = content;
256
211
  if (shakeParent.id !== id) return;
257
212
  result[shakeId] = result[shakeId] || [];
258
- result[shakeId].push({ ...content,
213
+ result[shakeId].push({
214
+ ...content,
259
215
  isLooped
260
216
  });
261
217
  break;
@@ -265,31 +221,24 @@ proto.shake = function shake(fromId) {
265
221
  noAck: true,
266
222
  consumerTag: `_shaker-${this.executionId}`
267
223
  });
268
-
269
224
  for (const a of toShake) a.shake();
270
-
271
225
  if (!executing) this._deactivate();
272
226
  this.broker.cancel(`_shaker-${this.executionId}`);
273
227
  return result;
274
228
  };
275
-
276
229
  proto.stop = function stop() {
277
230
  this.getApi().stop();
278
231
  };
279
-
280
232
  proto.getPostponed = function getPostponed(filterFn) {
281
233
  return this[kElements].postponed.slice().reduce((result, msg) => {
282
234
  const api = this._getChildApi(msg);
283
-
284
235
  if (api) {
285
236
  if (filterFn && !filterFn(api)) return result;
286
237
  result.push(api);
287
238
  }
288
-
289
239
  return result;
290
240
  }, []);
291
241
  };
292
-
293
242
  proto.discard = function discard() {
294
243
  this[kStatus] = 'discard';
295
244
  return this[kActivityQ].queueMessage({
@@ -302,7 +251,6 @@ proto.discard = function discard() {
302
251
  type: 'discard'
303
252
  });
304
253
  };
305
-
306
254
  proto.getState = function getState() {
307
255
  const {
308
256
  children,
@@ -331,50 +279,40 @@ proto.getState = function getState() {
331
279
  })
332
280
  };
333
281
  };
334
-
335
282
  proto.getActivities = function getActivities() {
336
283
  return this[kElements].children.slice();
337
284
  };
338
-
339
285
  proto.getActivityById = function getActivityById(activityId) {
340
286
  return this[kElements].children.find(child => child.id === activityId);
341
287
  };
342
-
343
288
  proto.getSequenceFlows = function getSequenceFlows() {
344
289
  return this[kElements].flows.slice();
345
290
  };
346
-
347
291
  proto.getApi = function getApi(message) {
348
292
  if (!message) return (0, _Api.ProcessApi)(this.broker, this[kExecuteMessage]);
349
293
  const content = message.content;
350
-
351
294
  if (content.executionId !== this.executionId) {
352
295
  return this._getChildApi(message);
353
296
  }
354
-
355
297
  const api = (0, _Api.ProcessApi)(this.broker, message);
356
298
  const postponed = this[kElements].postponed;
357
299
  const self = this;
358
-
359
300
  api.getExecuting = function getExecuting() {
360
301
  return postponed.reduce((result, msg) => {
361
302
  const childApi = self._getChildApi(msg);
362
-
363
303
  if (childApi) result.push(childApi);
364
304
  return result;
365
305
  }, []);
366
306
  };
367
-
368
307
  return api;
369
308
  };
370
-
371
309
  proto._start = function start() {
372
310
  if (this[kElements].children.length === 0) {
373
311
  return this._complete('completed');
374
312
  }
375
-
376
313
  this[kStatus] = 'start';
377
- const executeContent = { ...this[kExecuteMessage].content,
314
+ const executeContent = {
315
+ ...this[kExecuteMessage].content,
378
316
  state: this.status
379
317
  };
380
318
  this.broker.publish(this._exchangeName, 'execute.start', (0, _messageHelper.cloneContent)(executeContent));
@@ -383,15 +321,11 @@ proto._start = function start() {
383
321
  postponed,
384
322
  detachedActivities
385
323
  } = this[kElements];
386
-
387
324
  if (startActivities.length > 1) {
388
325
  for (const a of startActivities) a.shake();
389
326
  }
390
-
391
327
  for (const a of startActivities) a.init();
392
-
393
328
  for (const a of startActivities) a.run();
394
-
395
329
  postponed.splice(0);
396
330
  detachedActivities.splice(0);
397
331
  this[kActivityQ].assertConsumer(this[kMessageHandlers].onChildMessage, {
@@ -399,7 +333,6 @@ proto._start = function start() {
399
333
  consumerTag: `_process-activity-${this.executionId}`
400
334
  });
401
335
  };
402
-
403
336
  proto._activate = function activate() {
404
337
  const {
405
338
  onApiMessage,
@@ -419,7 +352,6 @@ proto._activate = function activate() {
419
352
  triggeredByEvent,
420
353
  children
421
354
  } = this[kElements];
422
-
423
355
  for (const flow of outboundMessageFlows) {
424
356
  flow.activate();
425
357
  flow.broker.subscribeTmp('event', '#', onMessageFlowEvent, {
@@ -428,7 +360,6 @@ proto._activate = function activate() {
428
360
  priority: 200
429
361
  });
430
362
  }
431
-
432
363
  for (const flow of flows) {
433
364
  flow.broker.subscribeTmp('event', '#', onActivityEvent, {
434
365
  consumerTag: '_process-flow-controller',
@@ -436,7 +367,6 @@ proto._activate = function activate() {
436
367
  priority: 200
437
368
  });
438
369
  }
439
-
440
370
  for (const association of associations) {
441
371
  association.broker.subscribeTmp('event', '#', onActivityEvent, {
442
372
  consumerTag: '_process-association-controller',
@@ -444,10 +374,8 @@ proto._activate = function activate() {
444
374
  priority: 200
445
375
  });
446
376
  }
447
-
448
377
  startActivities.splice(0);
449
378
  triggeredByEvent.splice(0);
450
-
451
379
  for (const activity of children) {
452
380
  if (activity.placeholder) continue;
453
381
  activity.activate(this);
@@ -459,10 +387,8 @@ proto._activate = function activate() {
459
387
  if (activity.isStart) startActivities.push(activity);
460
388
  if (activity.triggeredByEvent) triggeredByEvent.push(activity);
461
389
  }
462
-
463
390
  this[kActivated] = true;
464
391
  };
465
-
466
392
  proto._deactivate = function deactivate() {
467
393
  const broker = this.broker;
468
394
  const executionId = this.executionId;
@@ -474,40 +400,32 @@ proto._deactivate = function deactivate() {
474
400
  associations,
475
401
  outboundMessageFlows
476
402
  } = this[kElements];
477
-
478
403
  for (const activity of children) {
479
404
  if (activity.placeholder) continue;
480
405
  activity.broker.cancel('_process-activity-consumer');
481
406
  activity.deactivate();
482
407
  }
483
-
484
408
  for (const flow of flows) {
485
409
  flow.broker.cancel('_process-flow-controller');
486
410
  }
487
-
488
411
  for (const association of associations) {
489
412
  association.broker.cancel('_process-association-controller');
490
413
  }
491
-
492
414
  for (const flow of outboundMessageFlows) {
493
415
  flow.deactivate();
494
416
  flow.broker.cancel('_process-message-consumer');
495
417
  }
496
-
497
418
  this[kActivated] = false;
498
419
  };
499
-
500
420
  proto._onDelegateEvent = function onDelegateEvent(message) {
501
421
  const eventType = message.properties.type;
502
422
  let delegate = true;
503
423
  const content = message.content;
504
-
505
424
  if (content.message && content.message.id) {
506
425
  this._debug(`delegate ${eventType} event with id <${content.message.id}>`);
507
426
  } else {
508
427
  this._debug(`delegate ${eventType} anonymous event`);
509
428
  }
510
-
511
429
  for (const activity of this[kElements].triggeredByEvent) {
512
430
  if (activity.getStartActivities({
513
431
  referenceId: content.message && content.message.id,
@@ -517,17 +435,14 @@ proto._onDelegateEvent = function onDelegateEvent(message) {
517
435
  activity.run(content.message);
518
436
  }
519
437
  }
520
-
521
438
  this.getApi().sendApiMessage(eventType, content, {
522
439
  delegate: true
523
440
  });
524
441
  return delegate;
525
442
  };
526
-
527
443
  proto._onMessageFlowEvent = function onMessageFlowEvent(routingKey, message) {
528
444
  this.broker.publish('message', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
529
445
  };
530
-
531
446
  proto._onActivityEvent = function onActivityEvent(routingKey, message) {
532
447
  if (message.fields.redelivered && message.properties.persistent === false) return;
533
448
  const content = message.content;
@@ -535,7 +450,6 @@ proto._onActivityEvent = function onActivityEvent(routingKey, message) {
535
450
  let delegate = message.properties.delegate;
536
451
  const shaking = message.properties.type === 'shake';
537
452
  const isDirectChild = content.parent.id === this.id;
538
-
539
453
  if (isDirectChild) {
540
454
  parent.executionId = this.executionId;
541
455
  } else {
@@ -545,16 +459,15 @@ proto._onActivityEvent = function onActivityEvent(routingKey, message) {
545
459
  executionId: this.executionId
546
460
  });
547
461
  }
548
-
549
462
  if (delegate) delegate = this._onDelegateEvent(message);
550
- this.broker.publish('event', routingKey, content, { ...message.properties,
463
+ this.broker.publish('event', routingKey, content, {
464
+ ...message.properties,
551
465
  delegate,
552
466
  mandatory: false
553
467
  });
554
468
  if (shaking) return this._onShookEnd(message);
555
469
  if (!isDirectChild) return;
556
470
  if (content.isAssociation) return;
557
-
558
471
  switch (routingKey) {
559
472
  case 'process.terminate':
560
473
  return this[kActivityQ].queueMessage({
@@ -563,92 +476,86 @@ proto._onActivityEvent = function onActivityEvent(routingKey, message) {
563
476
  type: 'terminate',
564
477
  persistent: true
565
478
  });
566
-
567
479
  case 'activity.stop':
568
480
  return;
569
481
  }
570
-
571
482
  this[kActivityQ].queueMessage(message.fields, (0, _messageHelper.cloneContent)(content), {
572
483
  persistent: true,
573
484
  ...message.properties
574
485
  });
575
486
  };
576
-
577
487
  proto._onChildMessage = function onChildMessage(routingKey, message) {
578
488
  if (message.fields.redelivered && message.properties.persistent === false) return message.ack();
579
489
  const content = message.content;
580
-
581
490
  switch (routingKey) {
582
491
  case 'execution.stop':
583
492
  message.ack();
584
493
  return this._stopExecution(message);
585
-
586
494
  case 'execution.terminate':
587
495
  message.ack();
588
496
  return this._terminate(message);
589
-
590
497
  case 'execution.discard':
591
498
  message.ack();
592
499
  return this._onDiscard(message);
593
-
500
+ case 'activity.error.caught':
501
+ {
502
+ const prevMsg = this[kElements].postponed.find(msg => {
503
+ return msg.content.executionId === content.executionId;
504
+ });
505
+ if (!prevMsg) return message.ack();
506
+ break;
507
+ }
594
508
  case 'activity.compensation.end':
595
509
  case 'flow.looped':
596
510
  case 'activity.leave':
597
511
  return this._onChildCompleted(message);
598
512
  }
599
-
600
513
  this._stateChangeMessage(message, true);
601
-
602
514
  switch (routingKey) {
603
515
  case 'activity.detach':
604
516
  {
605
517
  this[kElements].detachedActivities.push((0, _messageHelper.cloneMessage)(message));
606
518
  break;
607
519
  }
608
-
609
520
  case 'activity.discard':
610
521
  case 'activity.compensation.start':
611
522
  case 'activity.enter':
612
523
  {
613
524
  this[kStatus] = 'executing';
614
525
  if (!content.inbound) break;
615
-
616
526
  for (const inbound of content.inbound) {
617
527
  if (!inbound.isSequenceFlow) continue;
618
-
619
528
  const inboundMessage = this._popPostponed(inbound);
620
-
621
529
  if (inboundMessage) inboundMessage.ack();
622
530
  }
623
-
624
531
  break;
625
532
  }
626
-
627
533
  case 'activity.error':
628
534
  {
629
535
  const eventCaughtBy = this[kElements].postponed.find(msg => {
630
536
  if (msg.fields.routingKey !== 'activity.catch') return;
631
537
  return msg.content.source && msg.content.source.executionId === content.executionId;
632
538
  });
633
-
634
539
  if (eventCaughtBy) {
540
+ this[kActivityQ].queueMessage({
541
+ routingKey: 'activity.error.caught'
542
+ }, (0, _messageHelper.cloneContent)(content), {
543
+ persistent: true,
544
+ ...message.properties
545
+ });
635
546
  return this._debug('error was caught');
636
547
  }
637
-
638
548
  return this._complete('error', {
639
549
  error: content.error
640
550
  });
641
551
  }
642
552
  }
643
553
  };
644
-
645
554
  proto._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
646
555
  const previousMsg = this._popPostponed(message.content);
647
-
648
556
  if (previousMsg) previousMsg.ack();
649
557
  if (postponeMessage) this[kElements].postponed.push(message);
650
558
  };
651
-
652
559
  proto._popPostponed = function popPostponed(byContent) {
653
560
  const {
654
561
  postponed,
@@ -659,19 +566,15 @@ proto._popPostponed = function popPostponed(byContent) {
659
566
  return msg.content.executionId === byContent.executionId;
660
567
  });
661
568
  let postponedMsg;
662
-
663
569
  if (postponedIdx > -1) {
664
570
  postponedMsg = postponed.splice(postponedIdx, 1)[0];
665
571
  }
666
-
667
572
  const detachedIdx = detachedActivities.findIndex(msg => msg.content.executionId === byContent.executionId);
668
573
  if (detachedIdx > -1) detachedActivities.splice(detachedIdx, 1);
669
574
  return postponedMsg;
670
575
  };
671
-
672
576
  proto._onChildCompleted = function onChildCompleted(message) {
673
577
  this._stateChangeMessage(message, false);
674
-
675
578
  if (message.fields.redelivered) return message.ack();
676
579
  const {
677
580
  id,
@@ -684,29 +587,21 @@ proto._onChildCompleted = function onChildCompleted(message) {
684
587
  startActivities
685
588
  } = this[kElements];
686
589
  const postponedCount = postponed.length;
687
-
688
590
  if (!postponedCount) {
689
591
  this._debug(`left <${id}> (${type}), pending runs ${postponedCount}`);
690
-
691
592
  message.ack();
692
593
  return this._complete('completed');
693
594
  }
694
-
695
595
  this._debug(`left <${id}> (${type}), pending runs ${postponedCount}, ${postponed.map(a => a.content.id).join(',')}`);
696
-
697
596
  if (postponedCount === detachedActivities.length) {
698
597
  for (const api of this.getPostponed()) api.discard();
699
-
700
598
  return;
701
599
  }
702
-
703
600
  if (isEnd && startActivities.length) {
704
601
  const startSequences = this[kElements].startSequences;
705
-
706
602
  for (const msg of postponed) {
707
603
  const postponedId = msg.content.id;
708
604
  const startSequence = startSequences[postponedId];
709
-
710
605
  if (startSequence) {
711
606
  if (startSequence.content.sequence.some(({
712
607
  id: sid
@@ -717,84 +612,63 @@ proto._onChildCompleted = function onChildCompleted(message) {
717
612
  }
718
613
  }
719
614
  };
720
-
721
615
  proto._stopExecution = function stopExecution(message) {
722
616
  const postponedCount = this.postponedCount;
723
-
724
617
  this._debug(`stop process execution (stop child executions ${postponedCount})`);
725
-
726
618
  if (postponedCount) {
727
619
  for (const api of this.getPostponed()) api.stop();
728
620
  }
729
-
730
621
  this._deactivate();
731
-
732
622
  this[kStopped] = true;
733
- return this.broker.publish(this._exchangeName, `execution.stopped.${this.executionId}`, { ...this[kExecuteMessage].content,
623
+ return this.broker.publish(this._exchangeName, `execution.stopped.${this.executionId}`, {
624
+ ...this[kExecuteMessage].content,
734
625
  ...(message && message.content)
735
626
  }, {
736
627
  type: 'stopped',
737
628
  persistent: false
738
629
  });
739
630
  };
740
-
741
631
  proto._onDiscard = function onDiscard() {
742
632
  this._deactivate();
743
-
744
633
  const running = this[kElements].postponed.splice(0);
745
-
746
634
  this._debug(`discard process execution (discard child executions ${running.length})`);
747
-
748
635
  for (const flow of this.getSequenceFlows()) flow.stop();
749
-
750
636
  for (const msg of running) this._getChildApi(msg).discard();
751
-
752
637
  this[kActivityQ].purge();
753
638
  return this._complete('discard');
754
639
  };
755
-
756
640
  proto._onApiMessage = function onApiMessage(routingKey, message) {
757
641
  const executionId = this.executionId;
758
642
  const broker = this.broker;
759
-
760
643
  if (message.properties.delegate) {
761
644
  const correlationId = message.properties.correlationId || (0, _shared.getUniqueId)(executionId);
762
-
763
645
  this._debug(`delegate api ${routingKey} message to children, with correlationId <${correlationId}>`);
764
-
765
646
  let consumed = false;
766
647
  broker.subscribeTmp('event', 'activity.consumed', (_, msg) => {
767
648
  if (msg.properties.correlationId === correlationId) {
768
649
  consumed = true;
769
-
770
650
  this._debug(`delegated api message was consumed by ${msg.content ? msg.content.executionId : 'unknown'}`);
771
651
  }
772
652
  }, {
773
653
  consumerTag: `_ct-delegate-${correlationId}`,
774
654
  noAck: true
775
655
  });
776
-
777
656
  for (const child of this[kElements].children) {
778
657
  if (child.placeholder) continue;
779
658
  child.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
780
659
  if (consumed) break;
781
660
  }
782
-
783
661
  return broker.cancel(`_ct-delegate-${correlationId}`);
784
662
  }
785
-
786
663
  if (this.id !== message.content.id) {
787
664
  const child = this.getActivityById(message.content.id);
788
665
  if (!child) return null;
789
666
  return child.broker.publish('api', routingKey, message.content, message.properties);
790
667
  }
791
-
792
668
  if (this.executionId !== message.content.executionId) return;
793
-
794
669
  switch (message.properties.type) {
795
670
  case 'discard':
796
671
  return this.discard(message);
797
-
798
672
  case 'stop':
799
673
  this[kActivityQ].queueMessage({
800
674
  routingKey: 'execution.stop'
@@ -804,18 +678,16 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
804
678
  break;
805
679
  }
806
680
  };
807
-
808
681
  proto._complete = function complete(completionType, content) {
809
682
  this._deactivate();
810
-
811
683
  this._debug(`process execution ${completionType}`);
812
-
813
684
  this[kCompleted] = true;
814
685
  if (this.status !== 'terminated') this[kStatus] = completionType;
815
686
  const broker = this.broker;
816
687
  this[kActivityQ].delete();
817
688
  return broker.publish(this._exchangeName, `execution.${completionType}.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
818
- output: { ...this.environment.output
689
+ output: {
690
+ ...this.environment.output
819
691
  },
820
692
  ...content,
821
693
  state: completionType
@@ -824,16 +696,11 @@ proto._complete = function complete(completionType, content) {
824
696
  mandatory: completionType === 'error'
825
697
  });
826
698
  };
827
-
828
699
  proto._terminate = function terminate(message) {
829
700
  this[kStatus] = 'terminated';
830
-
831
701
  this._debug('terminating process execution');
832
-
833
702
  const running = this[kElements].postponed.splice(0);
834
-
835
703
  for (const flow of this.getSequenceFlows()) flow.stop();
836
-
837
704
  for (const msg of running) {
838
705
  const {
839
706
  id: postponedId,
@@ -841,54 +708,41 @@ proto._terminate = function terminate(message) {
841
708
  } = msg.content;
842
709
  if (postponedId === message.content.id) continue;
843
710
  if (isSequenceFlow) continue;
844
-
845
711
  this._getChildApi(msg).stop();
846
-
847
712
  msg.ack();
848
713
  }
849
-
850
714
  this[kActivityQ].purge();
851
715
  };
852
-
853
716
  proto._getFlowById = function getFlowById(flowId) {
854
717
  return this[kElements].flows.find(f => f.id === flowId);
855
718
  };
856
-
857
719
  proto._getAssociationById = function getAssociationById(associationId) {
858
720
  return this[kElements].associations.find(a => a.id === associationId);
859
721
  };
860
-
861
722
  proto._getMessageFlowById = function getMessageFlowById(flowId) {
862
723
  return this[kElements].outboundMessageFlows.find(f => f.id === flowId);
863
724
  };
864
-
865
725
  proto._getChildById = function getChildById(childId) {
866
726
  return this.getActivityById(childId) || this._getFlowById(childId);
867
727
  };
868
-
869
728
  proto._getChildApi = function getChildApi(message) {
870
729
  const content = message.content;
871
-
872
730
  let child = this._getChildById(content.id);
873
-
874
731
  if (child) return child.getApi(message);
875
732
  if (!content.parent) return;
876
733
  child = this._getChildById(content.parent.id);
877
734
  if (child) return child.getApi(message);
878
735
  if (!content.parent.path) return;
879
-
880
736
  for (const pp of content.parent.path) {
881
737
  child = this._getChildById(pp.id, message);
882
738
  if (child) return child.getApi(message);
883
739
  }
884
740
  };
885
-
886
741
  proto._onShookEnd = function onShookEnd(message) {
887
742
  const routingKey = message.fields.routingKey;
888
743
  if (routingKey !== 'activity.shake.end') return;
889
744
  this[kElements].startSequences[message.content.id] = (0, _messageHelper.cloneMessage)(message);
890
745
  };
891
-
892
746
  proto._debug = function debugMessage(logMessage) {
893
747
  this[kParent].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
894
748
  };