bpmn-elements 13.1.2 → 14.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 (76) hide show
  1. package/README.md +1 -2
  2. package/dist/Context.js +36 -2
  3. package/dist/activity/Activity.js +32 -15
  4. package/dist/definition/DefinitionExecution.js +1 -1
  5. package/dist/error/Errors.js +6 -1
  6. package/dist/eventDefinitions/TimerEventDefinition.js +18 -31
  7. package/dist/getPropertyValue.js +1 -2
  8. package/dist/index.js +13 -5
  9. package/package.json +16 -14
  10. package/src/Api.js +18 -20
  11. package/src/Context.js +49 -7
  12. package/src/Environment.js +10 -20
  13. package/src/EventBroker.js +21 -27
  14. package/src/MessageFormatter.js +23 -19
  15. package/src/Tracker.js +4 -4
  16. package/src/activity/Activity.js +174 -121
  17. package/src/activity/ActivityExecution.js +38 -29
  18. package/src/activity/Dummy.js +3 -3
  19. package/src/activity/Escalation.js +4 -4
  20. package/src/activity/ExecutionScope.js +4 -4
  21. package/src/activity/Message.js +5 -5
  22. package/src/activity/Signal.js +5 -5
  23. package/src/definition/Definition.js +44 -36
  24. package/src/definition/DefinitionExecution.js +97 -66
  25. package/src/error/BpmnError.js +3 -3
  26. package/src/error/Errors.js +27 -15
  27. package/src/eventDefinitions/CancelEventDefinition.js +16 -11
  28. package/src/eventDefinitions/CompensateEventDefinition.js +28 -23
  29. package/src/eventDefinitions/ConditionalEventDefinition.js +42 -23
  30. package/src/eventDefinitions/ErrorEventDefinition.js +47 -34
  31. package/src/eventDefinitions/EscalationEventDefinition.js +21 -20
  32. package/src/eventDefinitions/EventDefinitionExecution.js +6 -6
  33. package/src/eventDefinitions/LinkEventDefinition.js +28 -22
  34. package/src/eventDefinitions/MessageEventDefinition.js +47 -36
  35. package/src/eventDefinitions/SignalEventDefinition.js +42 -31
  36. package/src/eventDefinitions/TerminateEventDefinition.js +4 -4
  37. package/src/eventDefinitions/TimerEventDefinition.js +56 -57
  38. package/src/events/BoundaryEvent.js +81 -46
  39. package/src/events/EndEvent.js +2 -2
  40. package/src/events/IntermediateCatchEvent.js +8 -4
  41. package/src/events/IntermediateThrowEvent.js +2 -2
  42. package/src/events/StartEvent.js +29 -18
  43. package/src/flows/Association.js +11 -11
  44. package/src/flows/MessageFlow.js +16 -14
  45. package/src/flows/SequenceFlow.js +22 -20
  46. package/src/gateways/EventBasedGateway.js +7 -6
  47. package/src/gateways/ExclusiveGateway.js +4 -4
  48. package/src/gateways/InclusiveGateway.js +3 -3
  49. package/src/gateways/ParallelGateway.js +4 -4
  50. package/src/getPropertyValue.js +3 -6
  51. package/src/index.js +3 -3
  52. package/src/io/BpmnIO.js +5 -6
  53. package/src/io/EnvironmentDataObject.js +2 -3
  54. package/src/io/EnvironmentDataStore.js +2 -2
  55. package/src/io/EnvironmentDataStoreReference.js +2 -2
  56. package/src/io/InputOutputSpecification.js +60 -54
  57. package/src/io/Properties.js +45 -33
  58. package/src/messageHelper.js +16 -23
  59. package/src/process/Lane.js +3 -3
  60. package/src/process/Process.js +40 -34
  61. package/src/process/ProcessExecution.js +122 -78
  62. package/src/tasks/CallActivity.js +109 -57
  63. package/src/tasks/LoopCharacteristics.js +30 -18
  64. package/src/tasks/ReceiveTask.js +59 -38
  65. package/src/tasks/ScriptTask.js +17 -8
  66. package/src/tasks/ServiceTask.js +16 -9
  67. package/src/tasks/SignalTask.js +47 -28
  68. package/src/tasks/StandardLoopCharacteristics.js +3 -3
  69. package/src/tasks/SubProcess.js +9 -8
  70. package/src/tasks/Task.js +4 -3
  71. package/src/tasks/Transaction.js +1 -1
  72. package/types/index.d.ts +6 -6
  73. package/types/types.d.ts +39 -35
  74. package/CHANGELOG.md +0 -459
  75. package/src/ExtensionsMapper.js +0 -42
  76. package/src/iso-duration.js +0 -91
@@ -1,7 +1,7 @@
1
- import {ProcessApi} from '../Api.js';
2
- import {cloneContent, cloneMessage, pushParent} from '../messageHelper.js';
3
- import {getUniqueId} from '../shared.js';
4
- import {ActivityTracker} from '../Tracker.js';
1
+ import { ProcessApi } from '../Api.js';
2
+ import { cloneContent, cloneMessage, pushParent } from '../messageHelper.js';
3
+ import { getUniqueId } from '../shared.js';
4
+ import { ActivityTracker } from '../Tracker.js';
5
5
 
6
6
  export default ProcessExecution;
7
7
 
@@ -17,7 +17,7 @@ const kStopped = Symbol.for('stopped');
17
17
  const kTracker = Symbol.for('activity tracker');
18
18
 
19
19
  function ProcessExecution(parentActivity, context) {
20
- const {id, type, broker, isSubProcess, isTransaction} = parentActivity;
20
+ const { id, type, broker, isSubProcess, isTransaction } = parentActivity;
21
21
 
22
22
  this[kParent] = parentActivity;
23
23
  this.id = id;
@@ -40,8 +40,8 @@ function ProcessExecution(parentActivity, context) {
40
40
  postponed: [],
41
41
  };
42
42
 
43
- const exchangeName = this._exchangeName = isSubProcess ? 'subprocess-execution' : 'execution';
44
- broker.assertExchange(exchangeName, 'topic', {autoDelete: false, durable: true});
43
+ const exchangeName = (this._exchangeName = isSubProcess ? 'subprocess-execution' : 'execution');
44
+ broker.assertExchange(exchangeName, 'topic', { autoDelete: false, durable: true });
45
45
 
46
46
  this[kCompleted] = false;
47
47
  this[kStopped] = false;
@@ -95,7 +95,7 @@ ProcessExecution.prototype.execute = function execute(executeMessage) {
95
95
  if (!executeMessage) throw new Error('Process execution requires message');
96
96
  if (!executeMessage.content || !executeMessage.content.executionId) throw new Error('Process execution requires execution id');
97
97
 
98
- const executionId = this.executionId = executeMessage.content.executionId;
98
+ const executionId = (this.executionId = executeMessage.content.executionId);
99
99
 
100
100
  this[kExecuteMessage] = cloneMessage(executeMessage, {
101
101
  executionId,
@@ -105,7 +105,7 @@ ProcessExecution.prototype.execute = function execute(executeMessage) {
105
105
  this[kStopped] = false;
106
106
 
107
107
  this.environment.assignVariables(executeMessage);
108
- this[kActivityQ] = this.broker.assertQueue(`execute-${executionId}-q`, {durable: true, autoDelete: false});
108
+ this[kActivityQ] = this.broker.assertQueue(`execute-${executionId}-q`, { durable: true, autoDelete: false });
109
109
 
110
110
  if (executeMessage.fields.redelivered) {
111
111
  return this.resume();
@@ -124,7 +124,7 @@ ProcessExecution.prototype.resume = function resume() {
124
124
 
125
125
  this._activate();
126
126
 
127
- const {startActivities, detachedActivities, postponed} = this[kElements];
127
+ const { startActivities, detachedActivities, postponed } = this[kElements];
128
128
 
129
129
  if (startActivities.length > 1) {
130
130
  for (const a of startActivities) a.shake();
@@ -164,7 +164,7 @@ ProcessExecution.prototype.resume = function resume() {
164
164
  };
165
165
 
166
166
  ProcessExecution.prototype.getState = function getState() {
167
- const {children, flows, outboundMessageFlows, associations} = this[kElements];
167
+ const { children, flows, outboundMessageFlows, associations } = this[kElements];
168
168
 
169
169
  const flowStates = flows.reduce((result, flow) => {
170
170
  const elmState = flow.getState();
@@ -184,7 +184,9 @@ ProcessExecution.prototype.getState = function getState() {
184
184
  return result;
185
185
  }, []),
186
186
  ...(flows.length && { flows: flowStates }),
187
- ...(outboundMessageFlows.length && { messageFlows: outboundMessageFlows.length && outboundMessageFlows.map((f) => f.getState()).filter(Boolean) }),
187
+ ...(outboundMessageFlows.length && {
188
+ messageFlows: outboundMessageFlows.length && outboundMessageFlows.map((f) => f.getState()).filter(Boolean),
189
+ }),
188
190
  ...(associations.length && { associations: associations.map((f) => f.getState()).filter(Boolean) }),
189
191
  };
190
192
  };
@@ -246,21 +248,26 @@ ProcessExecution.prototype.shake = function shake(fromId) {
246
248
  const toShake = fromId ? [this.getActivityById(fromId)].filter(Boolean) : this[kElements].startActivities;
247
249
 
248
250
  const result = {};
249
- this.broker.subscribeTmp('event', '*.shake.*', (routingKey, {content}) => {
250
- let isLooped = false;
251
- switch (routingKey) {
252
- case 'flow.shake.loop':
253
- isLooped = true;
254
- case 'activity.shake.end': {
255
- const {id: shakeId, parent: shakeParent} = content;
256
- if (shakeParent.id !== id) return;
257
-
258
- result[shakeId] = result[shakeId] || [];
259
- result[shakeId].push({...content, isLooped});
260
- break;
251
+ this.broker.subscribeTmp(
252
+ 'event',
253
+ '*.shake.*',
254
+ (routingKey, { content }) => {
255
+ let isLooped = false;
256
+ switch (routingKey) {
257
+ case 'flow.shake.loop':
258
+ isLooped = true;
259
+ case 'activity.shake.end': {
260
+ const { id: shakeId, parent: shakeParent } = content;
261
+ if (shakeParent.id !== id) return;
262
+
263
+ result[shakeId] = result[shakeId] || [];
264
+ result[shakeId].push({ ...content, isLooped });
265
+ break;
266
+ }
261
267
  }
262
- }
263
- }, {noAck: true, consumerTag: `_shaker-${this.executionId}`});
268
+ },
269
+ { noAck: true, consumerTag: `_shaker-${this.executionId}` },
270
+ );
264
271
 
265
272
  for (const a of toShake) a.shake();
266
273
 
@@ -287,19 +294,27 @@ ProcessExecution.prototype.getPostponed = function getPostponed(filterFn) {
287
294
 
288
295
  ProcessExecution.prototype.discard = function discard() {
289
296
  this[kStatus] = 'discard';
290
- return this[kActivityQ].queueMessage({routingKey: 'execution.discard'}, {
291
- id: this.id,
292
- type: this.type,
293
- executionId: this.executionId,
294
- }, {type: 'discard'});
297
+ return this[kActivityQ].queueMessage(
298
+ { routingKey: 'execution.discard' },
299
+ {
300
+ id: this.id,
301
+ type: this.type,
302
+ executionId: this.executionId,
303
+ },
304
+ { type: 'discard' },
305
+ );
295
306
  };
296
307
 
297
308
  ProcessExecution.prototype.cancel = function discard() {
298
- return this[kActivityQ].queueMessage({ routingKey: 'execution.cancel' }, {
299
- id: this.id,
300
- type: this.type,
301
- executionId: this.executionId,
302
- }, { type: 'cancel' });
309
+ return this[kActivityQ].queueMessage(
310
+ { routingKey: 'execution.cancel' },
311
+ {
312
+ id: this.id,
313
+ type: this.type,
314
+ executionId: this.executionId,
315
+ },
316
+ { type: 'cancel' },
317
+ );
303
318
  };
304
319
 
305
320
  ProcessExecution.prototype.getActivities = function getActivities() {
@@ -349,11 +364,11 @@ ProcessExecution.prototype._start = function start() {
349
364
 
350
365
  this[kStatus] = 'start';
351
366
 
352
- const executeContent = {...this[kExecuteMessage].content, state: this.status};
367
+ const executeContent = { ...this[kExecuteMessage].content, state: this.status };
353
368
 
354
369
  this.broker.publish(this._exchangeName, 'execute.start', cloneContent(executeContent));
355
370
 
356
- const {startActivities, postponed, detachedActivities} = this[kElements];
371
+ const { startActivities, postponed, detachedActivities } = this[kElements];
357
372
  if (startActivities.length > 1) {
358
373
  for (const a of startActivities) a.shake();
359
374
  }
@@ -371,7 +386,7 @@ ProcessExecution.prototype._start = function start() {
371
386
  };
372
387
 
373
388
  ProcessExecution.prototype._activate = function activate() {
374
- const {onApiMessage, onMessageFlowEvent, onActivityEvent} = this[kMessageHandlers];
389
+ const { onApiMessage, onMessageFlowEvent, onActivityEvent } = this[kMessageHandlers];
375
390
 
376
391
  if (!this.isSubProcess) {
377
392
  this.broker.consume('api-q', onApiMessage, {
@@ -387,7 +402,7 @@ ProcessExecution.prototype._activate = function activate() {
387
402
  });
388
403
  }
389
404
 
390
- const {outboundMessageFlows, flows, associations, startActivities, triggeredByEvent, children} = this[kElements];
405
+ const { outboundMessageFlows, flows, associations, startActivities, triggeredByEvent, children } = this[kElements];
391
406
 
392
407
  for (const flow of outboundMessageFlows) {
393
408
  flow.activate();
@@ -438,7 +453,7 @@ ProcessExecution.prototype._deactivate = function deactivate() {
438
453
  broker.cancel(`_process-api-consumer-${executionId}`);
439
454
  broker.cancel(`_process-activity-${executionId}`);
440
455
 
441
- const {children, flows, associations, outboundMessageFlows} = this[kElements];
456
+ const { children, flows, associations, outboundMessageFlows } = this[kElements];
442
457
 
443
458
  for (const activity of children) {
444
459
  if (activity.placeholder) continue;
@@ -474,13 +489,13 @@ ProcessExecution.prototype._onDelegateEvent = function onDelegateEvent(message)
474
489
  }
475
490
 
476
491
  for (const activity of this[kElements].triggeredByEvent) {
477
- if (activity.getStartActivities({referenceId: content.message && content.message.id, referenceType: eventType}).length) {
492
+ if (activity.getStartActivities({ referenceId: content.message && content.message.id, referenceType: eventType }).length) {
478
493
  delegate = false;
479
494
  activity.run(content.message);
480
495
  }
481
496
  }
482
497
 
483
- this.getApi().sendApiMessage(eventType, content, {delegate: true});
498
+ this.getApi().sendApiMessage(eventType, content, { delegate: true });
484
499
 
485
500
  return delegate;
486
501
  };
@@ -493,7 +508,7 @@ ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKe
493
508
  if (message.fields.redelivered && message.properties.persistent === false) return;
494
509
 
495
510
  const content = message.content;
496
- const parent = content.parent = content.parent || {};
511
+ const parent = (content.parent = content.parent || {});
497
512
  let delegate = message.properties.delegate;
498
513
  const shaking = message.properties.type === 'shake';
499
514
 
@@ -501,24 +516,27 @@ ProcessExecution.prototype._onActivityEvent = function onActivityEvent(routingKe
501
516
  if (isDirectChild) {
502
517
  parent.executionId = this.executionId;
503
518
  } else {
504
- content.parent = pushParent(parent, {id: this.id, type: this.type, executionId: this.executionId});
519
+ content.parent = pushParent(parent, { id: this.id, type: this.type, executionId: this.executionId });
505
520
  }
506
521
 
507
522
  if (delegate) delegate = this._onDelegateEvent(message);
508
523
 
509
524
  this[kTracker].track(routingKey, message);
510
- this.broker.publish('event', routingKey, content, {...message.properties, delegate, mandatory: false});
525
+ this.broker.publish('event', routingKey, content, { ...message.properties, delegate, mandatory: false });
511
526
  if (shaking) return this._onShookEnd(message);
512
527
  if (!isDirectChild) return;
513
528
 
514
529
  switch (routingKey) {
515
530
  case 'process.terminate':
516
- return this[kActivityQ].queueMessage({routingKey: 'execution.terminate'}, cloneContent(content), {type: 'terminate', persistent: true});
531
+ return this[kActivityQ].queueMessage({ routingKey: 'execution.terminate' }, cloneContent(content), {
532
+ type: 'terminate',
533
+ persistent: true,
534
+ });
517
535
  case 'activity.stop':
518
536
  return;
519
537
  }
520
538
 
521
- this[kActivityQ].queueMessage(message.fields, cloneContent(content), {persistent: true, ...message.properties});
539
+ this[kActivityQ].queueMessage(message.fields, cloneContent(content), { persistent: true, ...message.properties });
522
540
  };
523
541
 
524
542
  ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey, message) {
@@ -587,10 +605,13 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
587
605
  return msg.content.source && msg.content.source.executionId === content.executionId;
588
606
  });
589
607
  if (eventCaughtBy) {
590
- this[kActivityQ].queueMessage({routingKey: 'activity.error.caught'}, cloneContent(content), {persistent: true, ...message.properties});
608
+ this[kActivityQ].queueMessage({ routingKey: 'activity.error.caught' }, cloneContent(content), {
609
+ persistent: true,
610
+ ...message.properties,
611
+ });
591
612
  return this._debug('error was caught');
592
613
  }
593
- return this._complete('error', {error: content.error});
614
+ return this._complete('error', { error: content.error });
594
615
  }
595
616
  }
596
617
  };
@@ -602,7 +623,7 @@ ProcessExecution.prototype._stateChangeMessage = function stateChangeMessage(mes
602
623
  };
603
624
 
604
625
  ProcessExecution.prototype._popPostponed = function popPostponed(byContent) {
605
- const {postponed, detachedActivities} = this[kElements];
626
+ const { postponed, detachedActivities } = this[kElements];
606
627
 
607
628
  const postponedIdx = postponed.findIndex((msg) => {
608
629
  if (msg.content.isSequenceFlow || msg.content.isAssociation) return msg.content.sequenceId === byContent.sequenceId;
@@ -624,9 +645,9 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
624
645
  this._stateChangeMessage(message, false);
625
646
  if (message.fields.redelivered) return message.ack();
626
647
 
627
- const {id, type, isEnd} = message.content;
648
+ const { id, type, isEnd } = message.content;
628
649
 
629
- const {postponed, detachedActivities, startActivities} = this[kElements];
650
+ const { postponed, detachedActivities, startActivities } = this[kElements];
630
651
  const postponedCount = postponed.length;
631
652
 
632
653
  if (!postponedCount) {
@@ -639,11 +660,15 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
639
660
  this._debug(`left <${id}> (${type}), pending runs ${postponedCount}, ${postponed.map((a) => a.content.id).join(',')}`);
640
661
 
641
662
  if (postponedCount && postponedCount === detachedActivities.length) {
642
- return this[kActivityQ].queueMessage({ routingKey: 'execution.discard.detached' }, {
643
- id: this.id,
644
- type: this.type,
645
- executionId: this.executionId,
646
- }, { type: 'cancel' });
663
+ return this[kActivityQ].queueMessage(
664
+ { routingKey: 'execution.discard.detached' },
665
+ {
666
+ id: this.id,
667
+ type: this.type,
668
+ executionId: this.executionId,
669
+ },
670
+ { type: 'cancel' },
671
+ );
647
672
  }
648
673
 
649
674
  if (isEnd && startActivities.length) {
@@ -652,7 +677,7 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
652
677
  const postponedId = msg.content.id;
653
678
  const startSequence = startSequences[postponedId];
654
679
  if (startSequence) {
655
- if (startSequence.content.sequence.some(({id: sid}) => sid === id)) {
680
+ if (startSequence.content.sequence.some(({ id: sid }) => sid === id)) {
656
681
  this._getChildApi(msg).discard();
657
682
  }
658
683
  }
@@ -668,10 +693,15 @@ ProcessExecution.prototype._stopExecution = function stopExecution(message) {
668
693
  }
669
694
  this._deactivate();
670
695
  this[kStopped] = true;
671
- return this.broker.publish(this._exchangeName, `execution.stopped.${this.executionId}`, {
672
- ...this[kExecuteMessage].content,
673
- ...(message && message.content),
674
- }, {type: 'stopped', persistent: false});
696
+ return this.broker.publish(
697
+ this._exchangeName,
698
+ `execution.stopped.${this.executionId}`,
699
+ {
700
+ ...this[kExecuteMessage].content,
701
+ ...(message && message.content),
702
+ },
703
+ { type: 'stopped', persistent: false },
704
+ );
675
705
  };
676
706
 
677
707
  ProcessExecution.prototype._onDiscard = function onDiscard() {
@@ -698,9 +728,13 @@ ProcessExecution.prototype._onCancel = function onCancel() {
698
728
  if (isTransaction) {
699
729
  this._debug(`cancel transaction execution (cancel child executions ${running.length})`);
700
730
  this[kStatus] = 'cancel';
701
- this.broker.publish('event', 'transaction.cancel', cloneMessage(this[kExecuteMessage], {
702
- state: 'cancel',
703
- }));
731
+ this.broker.publish(
732
+ 'event',
733
+ 'transaction.cancel',
734
+ cloneMessage(this[kExecuteMessage], {
735
+ state: 'cancel',
736
+ }),
737
+ );
704
738
 
705
739
  for (const msg of running) {
706
740
  if (msg.content.expect === 'compensate') {
@@ -747,12 +781,17 @@ ProcessExecution.prototype._delegateApiMessage = function delegateApiMessage(rou
747
781
 
748
782
  const broker = this.broker;
749
783
  let consumed = false;
750
- broker.subscribeTmp('event', 'activity.consumed', (_, msg) => {
751
- if (msg.properties.correlationId === correlationId) {
752
- consumed = true;
753
- this._debug(`delegated api message was consumed by ${msg.content ? msg.content.executionId : 'unknown'}`);
754
- }
755
- }, { consumerTag: `_ct-delegate-${correlationId}`, noAck: true });
784
+ broker.subscribeTmp(
785
+ 'event',
786
+ 'activity.consumed',
787
+ (_, msg) => {
788
+ if (msg.properties.correlationId === correlationId) {
789
+ consumed = true;
790
+ this._debug(`delegated api message was consumed by ${msg.content ? msg.content.executionId : 'unknown'}`);
791
+ }
792
+ },
793
+ { consumerTag: `_ct-delegate-${correlationId}`, noAck: true },
794
+ );
756
795
 
757
796
  for (const child of this[kElements].children) {
758
797
  if (child.placeholder) continue;
@@ -784,11 +823,16 @@ ProcessExecution.prototype._complete = function complete(completionType, content
784
823
  const broker = this.broker;
785
824
  this[kActivityQ].delete();
786
825
 
787
- return broker.publish(this._exchangeName, `execution.${completionType}.${this.executionId}`, cloneContent(this[kExecuteMessage].content, {
788
- output: {...this.environment.output},
789
- ...content,
790
- state: completionType,
791
- }), {type: completionType, mandatory: completionType === 'error'});
826
+ return broker.publish(
827
+ this._exchangeName,
828
+ `execution.${completionType}.${this.executionId}`,
829
+ cloneContent(this[kExecuteMessage].content, {
830
+ output: { ...this.environment.output },
831
+ ...content,
832
+ state: completionType,
833
+ }),
834
+ { type: completionType, mandatory: completionType === 'error' },
835
+ );
792
836
  };
793
837
 
794
838
  ProcessExecution.prototype._terminate = function terminate(message) {
@@ -800,7 +844,7 @@ ProcessExecution.prototype._terminate = function terminate(message) {
800
844
  for (const flow of this.getAssociations()) flow.stop();
801
845
 
802
846
  for (const msg of running) {
803
- const {id: postponedId, isSequenceFlow, isAssociation} = msg.content;
847
+ const { id: postponedId, isSequenceFlow, isAssociation } = msg.content;
804
848
  if (postponedId === message.content.id) continue;
805
849
  if (isSequenceFlow || isAssociation) continue;
806
850
  this._getChildApi(msg).stop();
@@ -1,18 +1,19 @@
1
1
  import Activity from '../activity/Activity.js';
2
- import {ActivityError} from '../error/Errors.js';
3
- import {cloneContent} from '../messageHelper.js';
2
+ import { ActivityError } from '../error/Errors.js';
3
+ import { cloneContent } from '../messageHelper.js';
4
4
 
5
5
  export default function CallActivity(activityDef, context) {
6
6
  return new Activity(CallActivityBehaviour, activityDef, context);
7
7
  }
8
8
 
9
9
  export function CallActivityBehaviour(activity) {
10
- const {id, type, behaviour = {}} = activity;
10
+ const { id, type, behaviour = {} } = activity;
11
11
 
12
12
  this.id = id;
13
13
  this.type = type;
14
14
  this.calledElement = behaviour.calledElement;
15
- this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
15
+ this.loopCharacteristics =
16
+ behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
16
17
  this.activity = activity;
17
18
  this.broker = activity.broker;
18
19
  this.environment = activity.environment;
@@ -29,95 +30,146 @@ CallActivityBehaviour.prototype.execute = function execute(executeMessage) {
29
30
  try {
30
31
  var calledElement = this.environment.resolveExpression(this.calledElement); // eslint-disable-line no-var
31
32
  } catch (err) {
32
- return broker.publish('execution', 'execute.error', cloneContent(executeContent, {
33
- error: new ActivityError(err.message, executeMessage, err),
34
- }, {
35
- mandatory: true,
36
- }));
33
+ return broker.publish(
34
+ 'execution',
35
+ 'execute.error',
36
+ cloneContent(
37
+ executeContent,
38
+ {
39
+ error: new ActivityError(err.message, executeMessage, err),
40
+ },
41
+ {
42
+ mandatory: true,
43
+ },
44
+ ),
45
+ );
37
46
  }
38
47
 
39
48
  const executionId = executeContent.executionId;
40
- broker.subscribeTmp('api', `activity.#.${executionId}`, (...args) => {
41
- this._onApiMessage(calledElement, executeMessage, ...args);
42
- }, {
43
- noAck: true,
44
- consumerTag: `_api-${executionId}`,
45
- priority: 300,
46
- });
49
+ broker.subscribeTmp(
50
+ 'api',
51
+ `activity.#.${executionId}`,
52
+ (...args) => {
53
+ this._onApiMessage(calledElement, executeMessage, ...args);
54
+ },
55
+ {
56
+ noAck: true,
57
+ consumerTag: `_api-${executionId}`,
58
+ priority: 300,
59
+ },
60
+ );
47
61
  broker.subscribeTmp('api', '#.signal.*', (...args) => this._onDelegatedApiMessage(calledElement, executeMessage, ...args), {
48
62
  noAck: true,
49
63
  consumerTag: `_api-delegated-${executionId}`,
50
64
  });
51
65
 
52
- broker.publish('event', 'activity.call', cloneContent(executeContent, {
53
- state: 'wait',
54
- calledElement,
55
- }), {
56
- type: 'call',
57
- });
66
+ broker.publish(
67
+ 'event',
68
+ 'activity.call',
69
+ cloneContent(executeContent, {
70
+ state: 'wait',
71
+ calledElement,
72
+ }),
73
+ {
74
+ type: 'call',
75
+ },
76
+ );
58
77
  };
59
78
 
60
- CallActivityBehaviour.prototype._onDelegatedApiMessage = function onDelegatedApiMessage(calledElement, executeMessage, routingKey, message) {
79
+ CallActivityBehaviour.prototype._onDelegatedApiMessage = function onDelegatedApiMessage(
80
+ calledElement,
81
+ executeMessage,
82
+ routingKey,
83
+ message,
84
+ ) {
61
85
  if (!message.properties.delegate) return;
62
- const {content: delegateContent} = message;
86
+ const { content: delegateContent } = message;
63
87
  if (!delegateContent || !delegateContent.message) return;
64
88
 
65
89
  const executeContent = executeMessage.content;
66
90
 
67
- const {id: signalId, executionId: signalExecutionId} = delegateContent.message;
91
+ const { id: signalId, executionId: signalExecutionId } = delegateContent.message;
68
92
  if (this.loopCharacteristics && signalExecutionId !== executeContent.executionId) return;
69
93
  if (signalId !== this.id && signalExecutionId !== executeContent.executionId) return;
70
94
 
71
- const {type: messageType, correlationId} = message.properties;
95
+ const { type: messageType, correlationId } = message.properties;
72
96
 
73
- this.broker.publish('event', 'activity.consumed', cloneContent(executeContent, {
74
- message: { ...delegateContent.message},
75
- }), {
76
- correlationId,
77
- type: messageType,
78
- });
97
+ this.broker.publish(
98
+ 'event',
99
+ 'activity.consumed',
100
+ cloneContent(executeContent, {
101
+ message: { ...delegateContent.message },
102
+ }),
103
+ {
104
+ correlationId,
105
+ type: messageType,
106
+ },
107
+ );
79
108
 
80
109
  return this._onApiMessage(calledElement, executeMessage, routingKey, message);
81
110
  };
82
111
 
83
112
  CallActivityBehaviour.prototype._onApiMessage = function onApiMessage(calledElement, executeMessage, routingKey, message) {
84
- const {type: messageType, correlationId} = message.properties;
113
+ const { type: messageType, correlationId } = message.properties;
85
114
  const executeContent = executeMessage.content;
86
115
 
87
116
  switch (messageType) {
88
117
  case 'stop':
89
118
  return this._stop(executeContent.executionId);
90
119
  case 'cancel': {
91
- this.broker.publish('event', 'activity.call.cancel', cloneContent(executeContent, {
92
- state: 'cancel',
93
- calledElement,
94
- }), {
95
- type: 'cancel',
96
- });
120
+ this.broker.publish(
121
+ 'event',
122
+ 'activity.call.cancel',
123
+ cloneContent(executeContent, {
124
+ state: 'cancel',
125
+ calledElement,
126
+ }),
127
+ {
128
+ type: 'cancel',
129
+ },
130
+ );
97
131
  }
98
132
  case 'signal':
99
133
  this._stop(executeContent.executionId);
100
- return this.broker.publish('execution', 'execute.completed', cloneContent(executeContent, {
101
- output: message.content.message,
102
- state: messageType,
103
- }), {
104
- correlationId,
105
- });
134
+ return this.broker.publish(
135
+ 'execution',
136
+ 'execute.completed',
137
+ cloneContent(executeContent, {
138
+ output: message.content.message,
139
+ state: messageType,
140
+ }),
141
+ {
142
+ correlationId,
143
+ },
144
+ );
106
145
  case 'error':
107
146
  this._stop(executeContent.executionId);
108
- return this.broker.publish('execution', 'execute.error', cloneContent(executeContent, {
109
- error: new ActivityError(message.content.message, executeMessage, message.content),
110
- }, {
111
- mandatory: true,
112
- correlationId,
113
- }));
147
+ return this.broker.publish(
148
+ 'execution',
149
+ 'execute.error',
150
+ cloneContent(
151
+ executeContent,
152
+ {
153
+ error: new ActivityError(message.content.message, executeMessage, message.content),
154
+ },
155
+ {
156
+ mandatory: true,
157
+ correlationId,
158
+ },
159
+ ),
160
+ );
114
161
  case 'discard':
115
- return this.broker.publish('event', 'activity.call.cancel', cloneContent(executeContent, {
116
- state: 'discard',
117
- calledElement,
118
- }), {
119
- type: 'discard',
120
- });
162
+ return this.broker.publish(
163
+ 'event',
164
+ 'activity.call.cancel',
165
+ cloneContent(executeContent, {
166
+ state: 'discard',
167
+ calledElement,
168
+ }),
169
+ {
170
+ type: 'discard',
171
+ },
172
+ );
121
173
  }
122
174
  };
123
175