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
1
  import getPropertyValue from '../getPropertyValue.js';
2
- import {DefinitionApi} from '../Api.js';
3
- import {brokerSafeId} from '../shared.js';
4
- import {cloneContent, cloneMessage, pushParent, cloneParent} from '../messageHelper.js';
2
+ import { DefinitionApi } from '../Api.js';
3
+ import { brokerSafeId } from '../shared.js';
4
+ import { cloneContent, cloneMessage, pushParent, cloneParent } from '../messageHelper.js';
5
5
 
6
6
  const kActivated = Symbol.for('activated');
7
7
  const kProcessesQ = Symbol.for('processesQ');
@@ -20,7 +20,7 @@ export default function DefinitionExecution(definition, context) {
20
20
  this.id = definition.id;
21
21
  this.type = definition.type;
22
22
  this.broker = broker;
23
- const environment = this.environment = definition.environment;
23
+ const environment = (this.environment = definition.environment);
24
24
  this.context = context;
25
25
 
26
26
  const processes = context.getProcesses();
@@ -41,7 +41,7 @@ export default function DefinitionExecution(definition, context) {
41
41
  postponed: [],
42
42
  };
43
43
 
44
- broker.assertExchange('execution', 'topic', {autoDelete: false, durable: true});
44
+ broker.assertExchange('execution', 'topic', { autoDelete: false, durable: true });
45
45
 
46
46
  this.executionId = undefined;
47
47
  this[kCompleted] = false;
@@ -122,7 +122,7 @@ Object.defineProperties(DefinitionExecution.prototype, {
122
122
  DefinitionExecution.prototype.execute = function execute(executeMessage) {
123
123
  if (!executeMessage) throw new Error('Definition execution requires message');
124
124
  const content = executeMessage.content;
125
- const executionId = this.executionId = content.executionId;
125
+ const executionId = (this.executionId = content.executionId);
126
126
  if (!executionId) throw new Error('Definition execution requires execution id');
127
127
 
128
128
  this[kExecuteMessage] = cloneMessage(executeMessage, {
@@ -132,13 +132,13 @@ DefinitionExecution.prototype.execute = function execute(executeMessage) {
132
132
 
133
133
  this[kStopped] = false;
134
134
 
135
- this[kProcessesQ] = this.broker.assertQueue(`execute-${executionId}-q`, {durable: true, autoDelete: false});
135
+ this[kProcessesQ] = this.broker.assertQueue(`execute-${executionId}-q`, { durable: true, autoDelete: false });
136
136
 
137
137
  if (executeMessage.fields.redelivered) {
138
138
  return this.resume();
139
139
  }
140
140
 
141
- const {running, executable} = this[kProcesses];
141
+ const { running, executable } = this[kProcesses];
142
142
 
143
143
  if (content.processId) {
144
144
  const startWithProcess = this.getProcessById(content.processId);
@@ -160,7 +160,7 @@ DefinitionExecution.prototype.resume = function resume() {
160
160
 
161
161
  if (this[kCompleted]) return this._complete('completed');
162
162
 
163
- const {running, postponed} = this[kProcesses];
163
+ const { running, postponed } = this[kProcesses];
164
164
  this._activate(running);
165
165
  postponed.splice(0);
166
166
  this[kProcessesQ].consume(this[kMessageHandlers].onProcessMessage, {
@@ -210,7 +210,7 @@ DefinitionExecution.prototype.stop = function stop() {
210
210
  };
211
211
 
212
212
  DefinitionExecution.prototype.getProcesses = function getProcesses() {
213
- const {running, processes} = this[kProcesses];
213
+ const { running, processes } = this[kProcesses];
214
214
  const result = running.slice();
215
215
  for (const bp of processes) {
216
216
  if (!result.find((runningBp) => bp.id === runningBp.id)) result.push(bp);
@@ -251,7 +251,7 @@ DefinitionExecution.prototype.getState = function getState() {
251
251
  };
252
252
 
253
253
  DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
254
- if (!apiMessage) apiMessage = this[kExecuteMessage] || {content: this._createMessage()};
254
+ if (!apiMessage) apiMessage = this[kExecuteMessage] || { content: this._createMessage() };
255
255
 
256
256
  const content = apiMessage.content;
257
257
  if (content.executionId !== this.executionId) {
@@ -282,13 +282,13 @@ DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
282
282
  };
283
283
 
284
284
  DefinitionExecution.prototype._start = function start() {
285
- const {ids, executable, postponed} = this[kProcesses];
285
+ const { ids, executable, postponed } = this[kProcesses];
286
286
  if (!ids.length) {
287
287
  return this._complete('completed');
288
288
  }
289
289
 
290
290
  if (!executable.length) {
291
- return this._complete('error', {error: new Error('No executable process')});
291
+ return this._complete('error', { error: new Error('No executable process') });
292
292
  }
293
293
 
294
294
  this[kStatus] = 'start';
@@ -321,10 +321,10 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
321
321
  consumerTag: '_definition-outbound-message-consumer',
322
322
  });
323
323
 
324
- const delegateEventQ = broker.assertQueue('_delegate-event-q', {autoDelete: false, durable: false});
325
- delegateEventQ.consume(handlers.onDelegateMessage, {noAck: true, consumerTag: '_definition-signal-consumer'});
326
- broker.bindQueue('_delegate-event-q', 'event', 'activity.signal', {priority: 200});
327
- broker.bindQueue('_delegate-event-q', 'event', 'activity.message', {priority: 200});
324
+ const delegateEventQ = broker.assertQueue('_delegate-event-q', { autoDelete: false, durable: false });
325
+ delegateEventQ.consume(handlers.onDelegateMessage, { noAck: true, consumerTag: '_definition-signal-consumer' });
326
+ broker.bindQueue('_delegate-event-q', 'event', 'activity.signal', { priority: 200 });
327
+ broker.bindQueue('_delegate-event-q', 'event', 'activity.message', { priority: 200 });
328
328
 
329
329
  broker.subscribeTmp('event', 'activity.call', handlers.onCallActivity, {
330
330
  noAck: true,
@@ -346,7 +346,7 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
346
346
  DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey, originalMessage) {
347
347
  const message = cloneMessage(originalMessage);
348
348
  const content = message.content;
349
- const parent = content.parent = content.parent || {};
349
+ const parent = (content.parent = content.parent || {});
350
350
 
351
351
  const isDirectChild = this[kProcesses].ids.indexOf(content.id) > -1;
352
352
  if (isDirectChild) {
@@ -355,7 +355,7 @@ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey,
355
355
  content.parent = pushParent(parent, this);
356
356
  }
357
357
 
358
- this.broker.publish('event', routingKey, content, {...message.properties, mandatory: false});
358
+ this.broker.publish('event', routingKey, content, { ...message.properties, mandatory: false });
359
359
  if (!isDirectChild) return;
360
360
 
361
361
  this[kProcessesQ].queueMessage(message.fields, cloneContent(content), message.properties);
@@ -379,7 +379,7 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
379
379
  DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(routingKey, message) {
380
380
  const content = message.content;
381
381
  const isRedelivered = message.fields.redelivered;
382
- const {id: childId, inbound} = content;
382
+ const { id: childId, inbound } = content;
383
383
 
384
384
  if (isRedelivered && message.properties.persistent === false) return;
385
385
 
@@ -402,7 +402,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
402
402
  case 'process.discarded': {
403
403
  if (inbound && inbound.length) {
404
404
  const calledFrom = inbound[0];
405
- this._getProcessApi({content: calledFrom}).cancel({
405
+ this._getProcessApi({ content: calledFrom }).cancel({
406
406
  executionId: calledFrom.executionId,
407
407
  });
408
408
  }
@@ -412,9 +412,9 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
412
412
  if (inbound && inbound.length) {
413
413
  const calledFrom = inbound[0];
414
414
 
415
- this._getProcessApi({content: calledFrom}).signal({
415
+ this._getProcessApi({ content: calledFrom }).signal({
416
416
  executionId: calledFrom.executionId,
417
- output: {...content.output},
417
+ output: { ...content.output },
418
418
  });
419
419
  } else {
420
420
  Object.assign(this.environment.output, content.output);
@@ -422,20 +422,25 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
422
422
  break;
423
423
  }
424
424
  case 'process.error': {
425
- // message.ack();
426
425
  if (inbound && inbound.length) {
427
426
  const calledFrom = inbound[0];
428
427
 
429
- this._getProcessApi({content: calledFrom}).sendApiMessage('error', {
430
- executionId: calledFrom.executionId,
431
- error: content.error,
432
- }, {mandatory: true, type: 'error'});
428
+ this._getProcessApi({ content: calledFrom }).sendApiMessage(
429
+ 'error',
430
+ {
431
+ executionId: calledFrom.executionId,
432
+ error: content.error,
433
+ },
434
+ { mandatory: true, type: 'error' },
435
+ );
433
436
  } else {
434
437
  for (const bp of this[kProcesses].running.slice()) {
435
438
  if (bp.id !== childId) bp.stop();
436
439
  }
437
440
 
438
- this._complete('error', {error: content.error});
441
+ Object.assign(this.environment.output, content.output);
442
+
443
+ this._complete('error', { error: content.error });
439
444
  }
440
445
  break;
441
446
  }
@@ -458,7 +463,7 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
458
463
  this._stateChangeMessage(message, false);
459
464
  if (message.fields.redelivered) return message.ack();
460
465
 
461
- const {id, executionId, type, inbound} = message.content;
466
+ const { id, executionId, type, inbound } = message.content;
462
467
  message.ack();
463
468
  this._debug(`left <${executionId} (${id})> (${type}), pending runs ${this.postponedCount}`);
464
469
 
@@ -480,9 +485,14 @@ DefinitionExecution.prototype._onStopped = function onStopped(message) {
480
485
  this._deactivate();
481
486
 
482
487
  this[kStopped] = true;
483
- return this.broker.publish('execution', `execution.stopped.${this.executionId}`, cloneContent(this[kExecuteMessage].content, {
484
- ...message.content,
485
- }), {type: 'stopped', persistent: false});
488
+ return this.broker.publish(
489
+ 'execution',
490
+ `execution.stopped.${this.executionId}`,
491
+ cloneContent(this[kExecuteMessage].content, {
492
+ ...message.content,
493
+ }),
494
+ { type: 'stopped', persistent: false },
495
+ );
486
496
  };
487
497
 
488
498
  DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
@@ -491,7 +501,7 @@ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey,
491
501
 
492
502
  if (delegate && this.id === message.content.id) {
493
503
  const referenceId = getPropertyValue(message, 'content.message.id');
494
- this._startProcessesByMessage({referenceId, referenceType: messageType});
504
+ this._startProcessesByMessage({ referenceId, referenceType: messageType });
495
505
  }
496
506
 
497
507
  if (delegate) {
@@ -503,12 +513,12 @@ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey,
503
513
  if (this.executionId !== message.content.executionId) return;
504
514
 
505
515
  if (messageType === 'stop') {
506
- this[kProcessesQ].queueMessage({routingKey: 'execution.stop'}, cloneContent(message.content), {persistent: false});
516
+ this[kProcessesQ].queueMessage({ routingKey: 'execution.stop' }, cloneContent(message.content), { persistent: false });
507
517
  }
508
518
  };
509
519
 
510
520
  DefinitionExecution.prototype._startProcessesByMessage = function startProcessesByMessage(reference) {
511
- const {processes: bps, running} = this[kProcesses];
521
+ const { processes: bps, running } = this[kProcesses];
512
522
  if (bps.length < 2) return;
513
523
 
514
524
  for (const bp of bps) {
@@ -538,9 +548,12 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
538
548
 
539
549
  DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(routingKey, message) {
540
550
  const content = message.content;
541
- const {target, source} = content;
551
+ const { target, source } = content;
542
552
 
543
- this._debug(`conveying message from <${source.processId}.${source.id}> to`, target.id ? `<${target.processId}.${target.id}>` : `<${target.processId}>`);
553
+ this._debug(
554
+ `conveying message from <${source.processId}.${source.id}> to`,
555
+ target.id ? `<${target.processId}.${target.id}>` : `<${target.processId}>`,
556
+ );
544
557
 
545
558
  const targetProcesses = this.getProcessesById(target.processId);
546
559
  if (!targetProcesses.length) return;
@@ -568,7 +581,7 @@ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(ro
568
581
 
569
582
  DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingKey, message) {
570
583
  const content = message.content;
571
- const {calledElement, id: fromId, executionId: fromExecutionId, name: fromName, parent: fromParent} = content;
584
+ const { calledElement, id: fromId, executionId: fromExecutionId, name: fromName, parent: fromParent } = content;
572
585
  if (!calledElement) return;
573
586
 
574
587
  const bpExecutionId = `${brokerSafeId(calledElement)}_${fromExecutionId}`;
@@ -594,11 +607,11 @@ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingK
594
607
  this._activateProcess(targetProcess);
595
608
  this[kProcesses].running.push(targetProcess);
596
609
  targetProcess.init(bpExecutionId);
597
- targetProcess.run({inbound: [cloneContent(content)]});
610
+ targetProcess.run({ inbound: [cloneContent(content)] });
598
611
  };
599
612
 
600
613
  DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
601
- const {calledElement, id: fromId, executionId: fromExecutionId, parent: fromParent} = message.content;
614
+ const { calledElement, id: fromId, executionId: fromExecutionId, parent: fromParent } = message.content;
602
615
  if (!calledElement) return;
603
616
 
604
617
  const bpExecutionId = `${brokerSafeId(calledElement)}_${fromExecutionId}`;
@@ -608,12 +621,14 @@ DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActiv
608
621
  this._debug(`cancel call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
609
622
 
610
623
  if (!targetProcess.isRunning) {
611
- targetProcess.getApi({
612
- content: {
613
- id: targetProcess.id,
614
- executionId: targetProcess.executionId,
615
- },
616
- }).discard();
624
+ targetProcess
625
+ .getApi({
626
+ content: {
627
+ id: targetProcess.id,
628
+ executionId: targetProcess.executionId,
629
+ },
630
+ })
631
+ .discard();
617
632
  } else {
618
633
  targetProcess.getApi().discard();
619
634
  }
@@ -627,22 +642,33 @@ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(ro
627
642
  const reference = this.context.getActivityById(delegateMessage.id);
628
643
  const message = reference && reference.resolve(executeMessage);
629
644
 
630
- this._debug(`<${reference ? `${messageType} ${delegateMessage.id}>` : `anonymous ${messageType}`} event received from <${content.parent.id}.${content.id}>. Delegating.`);
645
+ this._debug(
646
+ `<${reference ? `${messageType} ${delegateMessage.id}>` : `anonymous ${messageType}`} event received from <${content.parent.id}.${content.id}>. Delegating.`,
647
+ );
631
648
 
632
- this.getApi().sendApiMessage(messageType, {
633
- source: {
634
- id: content.id,
635
- executionId: content.executionId,
636
- type: content.type,
637
- parent: cloneParent(content.parent),
649
+ this.getApi().sendApiMessage(
650
+ messageType,
651
+ {
652
+ source: {
653
+ id: content.id,
654
+ executionId: content.executionId,
655
+ type: content.type,
656
+ parent: cloneParent(content.parent),
657
+ },
658
+ message,
659
+ originalMessage: content.message,
638
660
  },
639
- message,
640
- originalMessage: content.message,
641
- }, {delegate: true, type: messageType});
661
+ { delegate: true, type: messageType },
662
+ );
642
663
 
643
- this.broker.publish('event', `definition.${messageType}`, this._createMessage({
644
- message: message && cloneContent(message),
645
- }), {type: messageType});
664
+ this.broker.publish(
665
+ 'event',
666
+ `definition.${messageType}`,
667
+ this._createMessage({
668
+ message: message && cloneContent(message),
669
+ }),
670
+ { type: messageType },
671
+ );
646
672
  };
647
673
 
648
674
  DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
@@ -661,12 +687,17 @@ DefinitionExecution.prototype._complete = function complete(completionType, cont
661
687
  this[kStatus] = completionType;
662
688
  this.broker.deleteQueue(this[kProcessesQ].name);
663
689
 
664
- return this.broker.publish('execution', `execution.${completionType}.${this.executionId}`, {
665
- ...stateMessage.content,
666
- output: {...this.environment.output},
667
- ...content,
668
- state: completionType,
669
- }, {type: completionType, mandatory: completionType === 'error', ...options});
690
+ return this.broker.publish(
691
+ 'execution',
692
+ `execution.${completionType}.${this.executionId}`,
693
+ {
694
+ ...stateMessage.content,
695
+ output: { ...this.environment.output },
696
+ ...content,
697
+ state: completionType,
698
+ },
699
+ { type: completionType, mandatory: completionType === 'error', ...options },
700
+ );
670
701
  };
671
702
 
672
703
  DefinitionExecution.prototype._createMessage = function createMessage(content = {}) {
@@ -1,6 +1,6 @@
1
1
  export default function BpmnErrorActivity(errorDef, context) {
2
- const {id, type, name = 'BpmnError', behaviour = {}} = errorDef;
3
- const {environment} = context;
2
+ const { id, type, name = 'BpmnError', behaviour = {} } = errorDef;
3
+ const { environment } = context;
4
4
 
5
5
  return {
6
6
  id,
@@ -11,7 +11,7 @@ export default function BpmnErrorActivity(errorDef, context) {
11
11
  };
12
12
 
13
13
  function resolve(executionMessage, error) {
14
- const resolveCtx = {...executionMessage, error};
14
+ const resolveCtx = { ...executionMessage, error };
15
15
  const result = {
16
16
  id,
17
17
  type,
@@ -1,4 +1,4 @@
1
- import {cloneMessage} from '../messageHelper.js';
1
+ import { cloneMessage } from '../messageHelper.js';
2
2
 
3
3
  class ActivityError extends Error {
4
4
  constructor(description, sourceMessage, inner) {
@@ -6,7 +6,8 @@ class ActivityError extends Error {
6
6
  this.type = 'ActivityError';
7
7
  this.name = this.constructor.name;
8
8
  this.description = description;
9
- if (sourceMessage) this.source = cloneMessage(sourceMessage, (sourceMessage.content && sourceMessage.content.error) && {error: undefined});
9
+ if (sourceMessage)
10
+ this.source = cloneMessage(sourceMessage, sourceMessage.content && sourceMessage.content.error && { error: undefined });
10
11
  if (inner) {
11
12
  this.inner = inner;
12
13
  if (inner.name) this.name = inner.name;
@@ -15,11 +16,16 @@ class ActivityError extends Error {
15
16
  }
16
17
  }
17
18
 
18
- class RunError extends ActivityError {}
19
+ class RunError extends ActivityError {
20
+ constructor(...args) {
21
+ super(...args);
22
+ this.type = 'RunError';
23
+ }
24
+ }
19
25
 
20
26
  class BpmnError extends Error {
21
27
  constructor(description, behaviour = {}, sourceMessage, inner) {
22
- const {errorCode} = behaviour;
28
+ const { errorCode } = behaviour;
23
29
 
24
30
  super(description);
25
31
  this.type = 'BpmnError';
@@ -27,31 +33,37 @@ class BpmnError extends Error {
27
33
  this.description = description;
28
34
  this.code = ('errorCode' in behaviour && errorCode && errorCode.toString()) || behaviour.code;
29
35
  this.id = behaviour.id;
30
- if (sourceMessage) this.source = cloneMessage(sourceMessage, (sourceMessage.content && sourceMessage.content.error) && {error: undefined});
36
+ if (sourceMessage)
37
+ this.source = cloneMessage(sourceMessage, sourceMessage.content && sourceMessage.content.error && { error: undefined });
31
38
  if (inner) this.inner = inner;
32
39
  }
33
40
  }
34
41
 
35
- export {
36
- ActivityError,
37
- BpmnError,
38
- RunError,
39
- makeErrorFromMessage
40
- };
42
+ export { ActivityError, BpmnError, RunError, makeErrorFromMessage };
41
43
 
42
44
  function makeErrorFromMessage(errorMessage) {
43
- const {content} = errorMessage;
45
+ const { content } = errorMessage;
46
+
44
47
  if (isKnownError(content)) return content;
45
48
 
46
- const {error} = content;
49
+ const { error } = content;
47
50
  if (!error) return new Error(`Malformatted error message with routing key ${errorMessage.fields && errorMessage.fields.routingKey}`);
48
51
 
49
52
  if (isKnownError(error)) return error;
53
+
50
54
  switch (error.type) {
51
55
  case 'ActivityError':
52
- return new ActivityError(error.message || error.description, error.source, error.inner ? error.inner : {code: error.code, name: error.name});
56
+ return new ActivityError(
57
+ error.message || error.description,
58
+ error.source,
59
+ error.inner ? error.inner : { code: error.code, name: error.name },
60
+ );
53
61
  case 'RunError':
54
- return new RunError(error.message || error.description, error.source, error.inner ? error.inner : {code: error.code, name: error.name});
62
+ return new RunError(
63
+ error.message || error.description,
64
+ error.source,
65
+ error.inner ? error.inner : { code: error.code, name: error.name },
66
+ );
55
67
  case 'BpmnError':
56
68
  return new BpmnError(error.message || error.description, error, error.source);
57
69
  }
@@ -1,15 +1,15 @@
1
- import {cloneContent, shiftParent} from '../messageHelper.js';
1
+ import { cloneContent, shiftParent } from '../messageHelper.js';
2
2
 
3
3
  const kCompleted = Symbol.for('completed');
4
4
  const kExecuteMessage = Symbol.for('executeMessage');
5
5
 
6
6
  export default function CancelEventDefinition(activity, eventDefinition) {
7
- const {id, broker, environment, isThrowing} = activity;
7
+ const { id, broker, environment, isThrowing } = activity;
8
8
  const type = eventDefinition.type;
9
9
 
10
10
  this.id = id;
11
11
  this.type = type;
12
- this.reference = {referenceType: 'cancel'};
12
+ this.reference = { referenceType: 'cancel' };
13
13
  this.isThrowing = isThrowing;
14
14
  this.activity = activity;
15
15
  this.environment = environment;
@@ -33,7 +33,7 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
33
33
  this[kCompleted] = false;
34
34
 
35
35
  const executeContent = executeMessage.content;
36
- const {executionId, parent} = executeContent;
36
+ const { executionId, parent } = executeContent;
37
37
  const parentExecutionId = parent.executionId;
38
38
 
39
39
  const broker = this.broker;
@@ -50,11 +50,15 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
50
50
  consumerTag: `_onattached-cancel-${executionId}`,
51
51
  });
52
52
 
53
- broker.publish('execution', 'execute.expect', cloneContent(executeContent, {
54
- pattern: 'activity.execution.cancel',
55
- exchange: 'execution',
56
- expectRoutingKey,
57
- }));
53
+ broker.publish(
54
+ 'execution',
55
+ 'execute.expect',
56
+ cloneContent(executeContent, {
57
+ pattern: 'activity.execution.cancel',
58
+ exchange: 'execution',
59
+ expectRoutingKey,
60
+ }),
61
+ );
58
62
 
59
63
  const waitContent = cloneContent(executeContent, {
60
64
  executionId: parentExecutionId,
@@ -68,7 +72,7 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
68
72
 
69
73
  CancelEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
70
74
  const executeContent = executeMessage.content;
71
- const {executionId, parent} = executeContent;
75
+ const { executionId, parent } = executeContent;
72
76
 
73
77
  this.logger.debug(`<${executionId} (${this.activity.id})> throw cancel`);
74
78
 
@@ -117,7 +121,8 @@ CancelEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey
117
121
  };
118
122
 
119
123
  CancelEventDefinition.prototype._stop = function stop() {
120
- const broker = this.broker, executionId = this.executionId;
124
+ const broker = this.broker,
125
+ executionId = this.executionId;
121
126
  broker.cancel(`_onattached-cancel-${executionId}`);
122
127
  broker.cancel(`_api-${executionId}`);
123
128
  };
@@ -1,5 +1,5 @@
1
- import {brokerSafeId} from '../shared.js';
2
- import {cloneContent, cloneMessage, shiftParent} from '../messageHelper.js';
1
+ import { brokerSafeId } from '../shared.js';
2
+ import { cloneContent, cloneMessage, shiftParent } from '../messageHelper.js';
3
3
 
4
4
  const kCompleted = Symbol.for('completed');
5
5
  const kExecuteMessage = Symbol.for('executeMessage');
@@ -8,11 +8,11 @@ const kCompensateQ = Symbol.for('compensateQ');
8
8
  const kAssociations = Symbol.for('associations');
9
9
 
10
10
  export default function CompensateEventDefinition(activity, eventDefinition, context) {
11
- const {id, broker, environment, isThrowing} = activity;
11
+ const { id, broker, environment, isThrowing } = activity;
12
12
 
13
13
  this.id = id;
14
- const type = this.type = eventDefinition.type;
15
- const reference = this.reference = {referenceType: 'compensate'};
14
+ const type = (this.type = eventDefinition.type);
15
+ const reference = (this.reference = { referenceType: 'compensate' });
16
16
  this.isThrowing = isThrowing;
17
17
  this.activity = activity;
18
18
  this.broker = broker;
@@ -22,9 +22,9 @@ export default function CompensateEventDefinition(activity, eventDefinition, con
22
22
  this[kCompleted] = false;
23
23
  this[kAssociations] = context.getOutboundAssociations(id);
24
24
  const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-q`;
25
- this[kMessageQ] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
26
- this[kCompensateQ] = broker.assertQueue('compensate-q', {autoDelete: false, durable: true});
27
- broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true, priority: 400});
25
+ this[kMessageQ] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
26
+ this[kCompensateQ] = broker.assertQueue('compensate-q', { autoDelete: false, durable: true });
27
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true, priority: 400 });
28
28
  }
29
29
  }
30
30
 
@@ -49,7 +49,7 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
49
49
  }
50
50
 
51
51
  const executeContent = executeMessage.content;
52
- const {executionId, parent} = executeContent;
52
+ const { executionId, parent } = executeContent;
53
53
 
54
54
  this._debug('expect compensate');
55
55
 
@@ -73,16 +73,20 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
73
73
  consumerTag: `_api-${executionId}`,
74
74
  });
75
75
 
76
- broker.publish('execution', 'execute.detach', cloneContent(executeContent, {
77
- sourceExchange: 'execution',
78
- bindExchange: 'compensate',
79
- expect: 'compensate',
80
- }));
76
+ broker.publish(
77
+ 'execution',
78
+ 'execute.detach',
79
+ cloneContent(executeContent, {
80
+ sourceExchange: 'execution',
81
+ bindExchange: 'compensate',
82
+ expect: 'compensate',
83
+ }),
84
+ );
81
85
  };
82
86
 
83
87
  CompensateEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
84
88
  const executeContent = executeMessage.content;
85
- const {parent} = executeContent;
89
+ const { parent } = executeContent;
86
90
  const parentExecutionId = parent && parent.executionId;
87
91
 
88
92
  this.logger.debug(`<${parentExecutionId} (${this.id})> throw compensate`);
@@ -93,7 +97,7 @@ CompensateEventDefinition.prototype.executeThrow = function executeThrow(execute
93
97
  state: 'throw',
94
98
  });
95
99
  throwContent.parent = shiftParent(parent);
96
- broker.publish('event', 'activity.compensate', throwContent, {type: 'compensate', delegate: true});
100
+ broker.publish('event', 'activity.compensate', throwContent, { type: 'compensate', delegate: true });
97
101
 
98
102
  return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
99
103
  };
@@ -118,28 +122,28 @@ CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompens
118
122
  this._debug('caught compensate event');
119
123
 
120
124
  const catchContent = cloneContent(executeContent, {
121
- message: {...output},
125
+ message: { ...output },
122
126
  executionId: executeContent.parent.executionId,
123
127
  });
124
128
  catchContent.parent = shiftParent(catchContent.parent);
125
129
 
126
- this[kCompensateQ].queueMessage({routingKey: 'execute.compensated'}, cloneContent(executeContent));
130
+ this[kCompensateQ].queueMessage({ routingKey: 'execute.compensated' }, cloneContent(executeContent));
127
131
 
128
- broker.publish('execution', 'execute.compensating', cloneContent(executeContent, {message: {...output}}));
129
- broker.publish('event', 'activity.catch', catchContent, {type: 'catch'});
132
+ broker.publish('execution', 'execute.compensating', cloneContent(executeContent, { message: { ...output } }));
133
+ broker.publish('event', 'activity.catch', catchContent, { type: 'catch' });
130
134
 
131
135
  return this._compensate();
132
136
  };
133
137
 
134
138
  CompensateEventDefinition.prototype._compensate = function compensate() {
135
- return this[kCompensateQ].consume(this._onCollected.bind(this), {noAck: true, consumerTag: '_convey-messages'});
139
+ return this[kCompensateQ].consume(this._onCollected.bind(this), { noAck: true, consumerTag: '_convey-messages' });
136
140
  };
137
141
 
138
142
  CompensateEventDefinition.prototype._onCollected = function onCollected(routingKey, message) {
139
143
  if (routingKey === 'execute.compensated') {
140
144
  const broker = this.broker;
141
145
  broker.cancel('_convey-messages');
142
- return this.broker.publish('execution', 'execute.completed', cloneContent(message.content, {cancelActivity: false}));
146
+ return this.broker.publish('execution', 'execute.completed', cloneContent(message.content, { cancelActivity: false }));
143
147
  }
144
148
  for (const association of this[kAssociations]) association.take(cloneMessage(message));
145
149
  };
@@ -168,7 +172,8 @@ CompensateEventDefinition.prototype._onApiMessage = function onApiMessage(routin
168
172
  };
169
173
 
170
174
  CompensateEventDefinition.prototype._stopCollect = function stopCollect() {
171
- const broker = this.broker, executionId = this.executionId;
175
+ const broker = this.broker,
176
+ executionId = this.executionId;
172
177
  broker.cancel(`_api-${executionId}`);
173
178
  broker.cancel(`_oncompensate-${executionId}`);
174
179
  broker.cancel('_oncollect-messages');