bpmn-elements 5.1.3 → 7.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 (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. package/src/tasks/Task.js +15 -19
@@ -2,142 +2,173 @@ import getPropertyValue from '../getPropertyValue';
2
2
  import {brokerSafeId} from '../shared';
3
3
  import {cloneContent, shiftParent} from '../messageHelper';
4
4
 
5
+ const completedSymbol = Symbol.for('completed');
6
+ const messageQSymbol = Symbol.for('messageQ');
7
+ const executeMessageSymbol = Symbol.for('executeMessage');
8
+
5
9
  export default function LinkEventDefinition(activity, eventDefinition) {
6
10
  const {id, broker, environment, isThrowing} = activity;
7
- const {type} = eventDefinition;
8
- const {debug} = environment.Logger(type.toLowerCase());
9
- const reference = {linkName: eventDefinition.behaviour.name};
10
- const linkQueueName = `link-${brokerSafeId(id)}-${brokerSafeId(reference.linkName)}-q`;
11
-
12
- if (!isThrowing) setupCatch();
13
- else setupThrow();
14
-
15
- const source = {
16
- id,
17
- type,
18
- reference: {...reference, referenceType: 'link'},
19
- execute: isThrowing ? executeThrow : executeCatch,
20
- };
21
-
22
- return source;
23
-
24
- function executeCatch(executeMessage) {
25
- let completed;
26
-
27
- const messageContent = cloneContent(executeMessage.content);
28
- const {executionId, parent} = messageContent;
29
- const parentExecutionId = parent && parent.executionId;
11
+ const {type = 'LinkEventDefinition', behaviour} = eventDefinition;
30
12
 
31
- const description = messageDescription();
32
- broker.consume(linkQueueName, onCatchLink, {noAck: true, consumerTag: `_api-link-${executionId}`});
13
+ this.id = id;
14
+ this.type = type;
33
15
 
34
- if (completed) return;
35
-
36
- broker.subscribeTmp('api', `activity.stop.${parentExecutionId}`, onApiMessage, {noAck: true, consumerTag: `_api-parent-${parentExecutionId}`});
37
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`});
38
-
39
- debug(`<${executionId} (${id})> expect ${description}`);
16
+ const reference = this.reference = {
17
+ linkName: behaviour.name,
18
+ referenceType: 'link',
19
+ };
40
20
 
41
- broker.publish('event', 'activity.wait', {
42
- ...messageContent,
43
- executionId: parentExecutionId,
44
- parent: shiftParent(parent),
45
- link: {...reference},
21
+ this.isThrowing = isThrowing;
22
+ this.activity = activity;
23
+ this.broker = broker;
24
+ this.logger = environment.Logger(type.toLowerCase());
25
+ this[completedSymbol] = false;
26
+
27
+ if (!isThrowing) {
28
+ const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(reference.linkName)}-q`;
29
+ this[messageQSymbol] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
30
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true});
31
+ } else {
32
+ broker.subscribeTmp('event', 'activity.discard', this._onDiscard.bind(this), {
33
+ noAck: true,
34
+ consumerTag: '_link-parent-discard',
46
35
  });
47
-
48
- function onCatchLink(routingKey, message) {
49
- if (getPropertyValue(message, 'content.message.linkName') !== reference.linkName) return;
50
- if (message.content.state === 'discard') return discard();
51
- return complete('caught', message.content.message);
52
- }
53
-
54
- function onApiMessage(routingKey, message) {
55
- const messageType = message.properties.type;
56
-
57
- switch (messageType) {
58
- case 'link': {
59
- return complete('got link with', message.content.message);
60
- }
61
- case 'discard': {
62
- return discard();
63
- }
64
- case 'stop': {
65
- stop();
66
- break;
67
- }
68
- }
69
- }
70
-
71
- function complete(verb, output) {
72
- completed = true;
73
-
74
- stop();
75
-
76
- debug(`<${executionId} (${id})> ${verb} ${description}`);
77
-
78
- broker.publish('event', 'activity.catch', {
79
- ...messageContent,
80
- link: {...reference},
81
- message: {...output},
82
- executionId: parentExecutionId || executionId,
83
- parent: shiftParent(executeMessage.content.parent),
84
- }, {type: 'catch'});
85
-
86
- return broker.publish('execution', 'execute.completed', {...messageContent, output, state: 'catch'});
87
- }
88
-
89
- function discard() {
90
- completed = true;
91
- stop();
92
- return broker.publish('execution', 'execute.discard', {...messageContent});
93
- }
94
-
95
- function stop() {
96
- broker.cancel(`_api-link-${executionId}`);
97
- broker.cancel(`_api-parent-${parentExecutionId}`);
98
- broker.cancel(`_api-${executionId}`);
99
- broker.purgeQueue(linkQueueName);
100
- }
101
- }
102
-
103
- function executeThrow(executeMessage) {
104
- const messageContent = cloneContent(executeMessage.content);
105
- const {executionId, parent} = messageContent;
106
- const parentExecutionId = parent && parent.executionId;
107
-
108
- const description = messageDescription();
109
-
110
- debug(`<${executionId} (${id})> throw ${description}`);
111
-
112
- broker.publish('event', 'activity.link', {
113
- ...cloneContent(messageContent),
114
- executionId: parentExecutionId,
115
- parent: shiftParent(parent),
116
- message: {...reference},
117
- state: 'throw',
118
- }, {type: 'link', delegate: true});
119
-
120
- return broker.publish('execution', 'execute.completed', messageContent);
121
- }
122
-
123
- function messageDescription() {
124
- return `link ${reference.linkName}`;
125
- }
126
-
127
- function setupCatch() {
128
- broker.assertQueue(linkQueueName, {autoDelete: false, durable: true});
129
- broker.bindQueue(linkQueueName, 'api', '*.link.#', {durable: true});
130
36
  }
37
+ }
131
38
 
132
- function setupThrow() {
133
- broker.subscribeTmp('event', 'activity.discard', onDiscard, {noAck: true, consumerTag: '_link-parent-discard'});
134
-
135
- function onDiscard(_, message) {
136
- broker.publish('event', 'activity.link.discard', {
137
- ...cloneContent(message.content),
138
- message: {...reference},
139
- state: 'discard',
140
- }, {type: 'link', delegate: true});
39
+ const proto = LinkEventDefinition.prototype;
40
+
41
+ Object.defineProperty(proto, 'executionId', {
42
+ get() {
43
+ const message = this[executeMessageSymbol];
44
+ return message && message.content.executionId;
45
+ },
46
+ });
47
+
48
+ proto.execute = function execute(executeMessage) {
49
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
50
+ };
51
+
52
+ proto.executeCatch = function executeCatch(executeMessage) {
53
+ this[executeMessageSymbol] = executeMessage;
54
+ this[completedSymbol] = false;
55
+
56
+ const executeContent = executeMessage.content;
57
+ const {executionId, parent} = executeContent;
58
+ const parentExecutionId = parent.executionId;
59
+
60
+ this[messageQSymbol].consume(this._onCatchLink.bind(this), {
61
+ noAck: true,
62
+ consumerTag: `_api-link-${executionId}`,
63
+ });
64
+
65
+ if (this[completedSymbol]) return;
66
+
67
+ const broker = this.broker;
68
+ const onApiMessage = this._onApiMessage.bind(this);
69
+ broker.subscribeTmp('api', `activity.stop.${parentExecutionId}`, onApiMessage, {
70
+ noAck: true,
71
+ consumerTag: `_api-parent-${executionId}`,
72
+ });
73
+ broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
74
+ noAck: true,
75
+ consumerTag: `_api-${executionId}`,
76
+ });
77
+
78
+ this._debug(`expect link ${this.reference.linkName}`);
79
+
80
+ const waitContent = cloneContent(executeContent, {
81
+ executionId: parentExecutionId,
82
+ link: {...this.reference},
83
+ });
84
+ waitContent.parent = shiftParent(parent);
85
+
86
+ broker.publish('event', 'activity.wait', waitContent);
87
+ };
88
+
89
+ proto.executeThrow = function executeThrow(executeMessage) {
90
+ const executeContent = executeMessage.content;
91
+ const {executionId, parent} = executeContent;
92
+ const parentExecutionId = parent && parent.executionId;
93
+
94
+ this.logger.debug(`<${executionId} (${this.activity.id})> throw link ${this.reference.linkName}`);
95
+
96
+ const broker = this.broker;
97
+ const linkContent = cloneContent(executeContent, {
98
+ executionId: parentExecutionId,
99
+ message: {...this.reference},
100
+ state: 'throw',
101
+ });
102
+ linkContent.parent = shiftParent(parent);
103
+
104
+ broker.publish('event', 'activity.link', linkContent, {type: 'link', delegate: true});
105
+
106
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
107
+ };
108
+
109
+ proto._onCatchLink = function onCatchLink(routingKey, message) {
110
+ if (getPropertyValue(message, 'content.message.linkName') !== this.reference.linkName) return;
111
+ if (message.content.state === 'discard') return this._discard();
112
+ return this._complete('caught', message.content.message);
113
+ };
114
+
115
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
116
+ const messageType = message.properties.type;
117
+
118
+ switch (messageType) {
119
+ case 'discard': {
120
+ return this._discard();
121
+ }
122
+ case 'stop': {
123
+ this._stop();
124
+ break;
141
125
  }
142
126
  }
143
- }
127
+ };
128
+
129
+ proto._complete = function complete(verb, output) {
130
+ this[completedSymbol] = true;
131
+
132
+ this._stop();
133
+
134
+ this._debug(`${verb} link ${this.reference.linkName}`);
135
+
136
+ const executeContent = this[executeMessageSymbol].content;
137
+ const parent = executeContent.parent;
138
+ const catchContent = cloneContent(executeContent, {
139
+ link: {...this.reference},
140
+ message: {...output},
141
+ executionId: parent.executionId,
142
+ });
143
+ catchContent.parent = shiftParent(parent);
144
+
145
+ const broker = this.broker;
146
+ broker.publish('event', 'activity.catch', catchContent, {type: 'catch'});
147
+
148
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {output, state: 'catch'}));
149
+ };
150
+
151
+ proto._discard = function discard() {
152
+ this[completedSymbol] = true;
153
+ this._stop();
154
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[executeMessageSymbol].content));
155
+ };
156
+
157
+ proto._stop = function stop() {
158
+ const broker = this.broker, executionId = this.executionId;
159
+ broker.cancel(`_api-link-${executionId}`);
160
+ broker.cancel(`_api-parent-${executionId}`);
161
+ broker.cancel(`_api-${executionId}`);
162
+ this[messageQSymbol].purge();
163
+ };
164
+
165
+ proto._onDiscard = function onDiscard(_, message) {
166
+ this.broker.publish('event', 'activity.link.discard', cloneContent(message.content, {
167
+ message: {...this.reference},
168
+ state: 'discard',
169
+ }), {type: 'link', delegate: true});
170
+ };
171
+
172
+ proto._debug = function debug(msg) {
173
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
174
+ };
@@ -2,142 +2,199 @@ import getPropertyValue from '../getPropertyValue';
2
2
  import {brokerSafeId} from '../shared';
3
3
  import {cloneContent, shiftParent} from '../messageHelper';
4
4
 
5
+ const completedSymbol = Symbol.for('completed');
6
+ const messageQSymbol = Symbol.for('messageQ');
7
+ const executeMessageSymbol = Symbol.for('executeMessage');
8
+ const referenceElementSymbol = Symbol.for('referenceElement');
9
+ const referenceInfoSymbol = Symbol.for('referenceInfo');
10
+
5
11
  export default function MessageEventDefinition(activity, eventDefinition) {
6
- const {id, broker, environment, isStart, isThrowing, getActivityById} = activity;
12
+ const {id, broker, environment, isThrowing} = activity;
7
13
  const {type = 'MessageEventDefinition', behaviour = {}} = eventDefinition;
8
- const {debug} = environment.Logger(type.toLowerCase());
9
- const reference = behaviour.messageRef || {name: 'anonymous'};
10
- const referenceElement = reference.id && getActivityById(reference.id);
11
- const messageId = referenceElement ? referenceElement.id : 'anonymous';
12
- const messageQueueName = `message-${brokerSafeId(id)}-${brokerSafeId(messageId)}-q`;
13
14
 
14
- if (!isThrowing || isStart) setupCatch();
15
+ this.id = id;
16
+ this.type = type;
15
17
 
16
- const source = {
17
- id,
18
- type,
19
- reference: {...reference, referenceType: 'message'},
20
- execute: isThrowing ? executeThrow : executeCatch,
18
+ const reference = this.reference = {
19
+ name: 'anonymous',
20
+ ...behaviour.messageRef,
21
+ referenceType: 'message',
21
22
  };
22
23
 
23
- return source;
24
-
25
- function executeCatch(executeMessage) {
26
- let completed;
27
-
28
- const messageContent = cloneContent(executeMessage.content);
29
- const {executionId, parent} = messageContent;
30
- const parentExecutionId = parent && parent.executionId;
31
-
32
- const {message: referenceMessage, description} = resolveReference(executeMessage);
33
- broker.consume(messageQueueName, onCatchMessage, {noAck: true, consumerTag: `_onmessage-${executionId}`});
34
-
35
- if (completed) return;
36
-
37
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {noAck: true, consumerTag: `_api-${executionId}`, priority: 400});
38
- if (parentExecutionId) broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {noAck: true, consumerTag: `_api-parent-${executionId}`, priority: 400});
39
- broker.subscribeTmp('api', '#.signal.*', onCatchMessage, {noAck: true, consumerTag: `_api-delegated-${executionId}`});
40
-
41
- debug(`<${executionId} (${id})> expect ${description}`);
42
-
43
- broker.publish('event', 'activity.wait', {
44
- ...messageContent,
45
- executionId: parentExecutionId || executionId,
46
- parent: shiftParent(parent),
47
- message: {...referenceMessage},
48
- });
49
-
50
- function onCatchMessage(routingKey, message) {
51
- if (getPropertyValue(message, 'content.message.id') !== referenceMessage.id) return;
24
+ this.isThrowing = isThrowing;
25
+ this.activity = activity;
26
+ this.broker = broker;
27
+ this.logger = environment.Logger(type.toLowerCase());
28
+
29
+ const referenceElement = this[referenceElementSymbol] = reference.id && activity.getActivityById(reference.id);
30
+ if (!isThrowing) {
31
+ this[completedSymbol] = false;
32
+ const referenceId = referenceElement ? referenceElement.id : 'anonymous';
33
+ const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
34
+ this[messageQSymbol] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
35
+ broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true});
36
+ }
37
+ }
52
38
 
53
- const {type: messageType, correlationId} = message.properties;
54
- broker.publish('event', 'activity.consumed', cloneContent(messageContent, {message: {...message.content.message}}), {correlationId, type: messageType});
39
+ const proto = MessageEventDefinition.prototype;
40
+
41
+ Object.defineProperty(proto, 'executionId', {
42
+ get() {
43
+ const message = this[executeMessageSymbol];
44
+ return message && message.content.executionId;
45
+ },
46
+ });
47
+
48
+ proto.execute = function execute(executeMessage) {
49
+ return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
50
+ };
51
+
52
+ proto.executeCatch = function executeCatch(executeMessage) {
53
+ this[executeMessageSymbol] = executeMessage;
54
+ this[completedSymbol] = false;
55
+
56
+ const executeContent = executeMessage.content;
57
+ const {executionId, parent} = executeContent;
58
+ const parentExecutionId = parent && parent.executionId;
59
+
60
+ const info = this[referenceInfoSymbol] = this._getReferenceInfo(executeMessage);
61
+ this._debug(`expect ${info.description}`);
62
+
63
+ const broker = this.broker;
64
+ const onCatchMessage = this._onCatchMessage.bind(this);
65
+ this[messageQSymbol].consume(onCatchMessage, {
66
+ noAck: true,
67
+ consumerTag: `_api-message-${executionId}`,
68
+ });
69
+
70
+ if (this[completedSymbol]) return;
71
+
72
+ const onApiMessage = this._onApiMessage.bind(this);
73
+ broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
74
+ noAck: true,
75
+ consumerTag: `_api-${executionId}`,
76
+ priority: 400,
77
+ });
78
+ broker.subscribeTmp('api', `activity.#.${parentExecutionId}`, onApiMessage, {
79
+ noAck: true,
80
+ consumerTag: `_api-parent-${executionId}`,
81
+ priority: 400,
82
+ });
83
+ broker.subscribeTmp('api', '#.signal.*', onCatchMessage, {
84
+ noAck: true,
85
+ consumerTag: `_api-delegated-${executionId}`,
86
+ });
87
+
88
+ const waitContent = cloneContent(executeContent, {
89
+ executionId: parentExecutionId,
90
+ message: {...info.message},
91
+ });
92
+ waitContent.parent = shiftParent(parent);
93
+
94
+ broker.publish('event', 'activity.wait', waitContent);
95
+ };
96
+
97
+ proto.executeThrow = function executeThrow(executeMessage) {
98
+ const executeContent = executeMessage.content;
99
+ const {executionId, parent} = executeContent;
100
+ const info = this._getReferenceInfo(executeMessage);
101
+
102
+ this.logger.debug(`<${executionId} (${this.activity.id})> message ${info.description}`);
103
+
104
+ const broker = this.broker;
105
+ const throwContent = cloneContent(executeContent, {
106
+ executionId: parent.executionId,
107
+ message: {...executeContent.input, ...info.message},
108
+ state: 'throw',
109
+ });
110
+ throwContent.parent = shiftParent(parent);
111
+
112
+ broker.publish('event', 'activity.message', throwContent, {type: 'message', delegate: true});
113
+
114
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
115
+ };
116
+
117
+ proto._onCatchMessage = function onCatchMessage(routingKey, message) {
118
+ if (getPropertyValue(message, 'content.message.id') !== this[referenceInfoSymbol].message.id) return;
119
+
120
+ const {type, correlationId} = message.properties;
121
+ this.broker.publish('event', 'activity.consumed', cloneContent(this[executeMessageSymbol].content, {
122
+ message: {...message.content.message},
123
+ }), {
124
+ correlationId,
125
+ type,
126
+ });
55
127
 
56
- complete('caught', message.content.message, {correlationId});
57
- }
128
+ this._complete('caught', message.content.message, {correlationId});
129
+ };
58
130
 
59
- function onApiMessage(routingKey, message) {
60
- const {type: messageType, correlationId} = message.properties;
61
- switch (messageType) {
62
- case 'message':
63
- case 'signal': {
64
- return complete('got signal with', message.content.message, {correlationId});
65
- }
66
- case 'discard': {
67
- completed = true;
68
- stop();
69
- return broker.publish('execution', 'execute.discard', {...messageContent}, {correlationId});
70
- }
71
- case 'stop': {
72
- return stop();
73
- }
74
- }
131
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
132
+ const {type, correlationId} = message.properties;
133
+ switch (type) {
134
+ case 'message':
135
+ case 'signal': {
136
+ return this._complete('got signal with', message.content.message, {correlationId});
75
137
  }
76
-
77
- function complete(verb, output, options) {
78
- completed = true;
79
-
80
- stop();
81
-
82
- debug(`<${executionId} (${id})> ${verb} ${description}`);
83
- broker.publish('event', 'activity.catch', {
84
- ...messageContent,
85
- message: {...output},
86
- executionId: parentExecutionId || executionId,
87
- parent: shiftParent(executeMessage.content.parent),
88
- }, {type: 'catch'});
89
-
90
- return broker.publish('execution', 'execute.completed', {...messageContent, output, state: 'catch'}, options);
138
+ case 'discard': {
139
+ this[completedSymbol] = true;
140
+ this._stop();
141
+ return this.broker.publish('execution', 'execute.discard', cloneContent(this[executeMessageSymbol].content), {correlationId});
91
142
  }
92
-
93
- function stop() {
94
- broker.cancel(`_onmessage-${executionId}`);
95
- broker.cancel(`_api-${executionId}`);
96
- broker.cancel(`_api-parent-${executionId}`);
97
- broker.cancel(`_api-delegated-${executionId}`);
98
- broker.purgeQueue(messageQueueName);
143
+ case 'stop': {
144
+ return this._stop();
99
145
  }
100
146
  }
101
-
102
- function executeThrow(executeMessage) {
103
- const messageContent = cloneContent(executeMessage.content);
104
- const {executionId, parent} = messageContent;
105
- const parentExecutionId = parent && parent.executionId;
106
-
107
- const {message: referenceMessage, description} = resolveReference(executeMessage);
108
-
109
- debug(`<${executionId} (${id})> message ${description}`);
110
-
111
- broker.publish('event', 'activity.message', {
112
- ...cloneContent(messageContent),
113
- executionId: parentExecutionId || executionId,
114
- parent: shiftParent(parent),
115
- message: {...messageContent.input, ...referenceMessage},
116
- state: 'throw',
117
- }, {type: 'message', delegate: true});
118
-
119
- return broker.publish('execution', 'execute.completed', {...messageContent});
147
+ };
148
+
149
+ proto._complete = function complete(verb, output, options) {
150
+ this[completedSymbol] = true;
151
+
152
+ this._stop();
153
+ this._debug(`${verb} ${this[referenceInfoSymbol].description}`);
154
+
155
+ const broker = this.broker;
156
+ const executeContent = this[executeMessageSymbol].content;
157
+ const catchContent = cloneContent(executeContent, {
158
+ message: {...output},
159
+ executionId: executeContent.parent.executionId,
160
+ });
161
+ catchContent.parent = shiftParent(executeContent.parent);
162
+
163
+ broker.publish('event', 'activity.catch', catchContent, {type: 'catch'});
164
+
165
+ return broker.publish('execution', 'execute.completed', cloneContent(executeContent, {
166
+ output,
167
+ state: 'catch',
168
+ }), options);
169
+ };
170
+
171
+ proto._stop = function stop() {
172
+ const broker = this.broker, executionId = this.executionId;
173
+ broker.cancel(`_api-message-${executionId}`);
174
+ broker.cancel(`_api-${executionId}`);
175
+ broker.cancel(`_api-parent-${executionId}`);
176
+ broker.cancel(`_api-delegated-${executionId}`);
177
+ this[messageQSymbol].purge();
178
+ };
179
+
180
+ proto._getReferenceInfo = function getReferenceInfo(message) {
181
+ const referenceElement = this[referenceElementSymbol];
182
+ if (!referenceElement) {
183
+ return {
184
+ message: {...this.reference},
185
+ description: 'anonymous message',
186
+ };
120
187
  }
121
188
 
122
- function resolveReference(message) {
123
- if (!referenceElement) {
124
- return {
125
- message: {...reference},
126
- description: 'anonymous message',
127
- };
128
- }
129
-
130
- const result = {
131
- message: referenceElement.resolve(message),
132
- };
189
+ const result = {
190
+ message: referenceElement.resolve(message),
191
+ };
133
192
 
134
- result.description = `${result.message.name} <${result.message.id}>`;
193
+ result.description = `${result.message.name} <${result.message.id}>`;
135
194
 
136
- return result;
137
- }
195
+ return result;
196
+ };
138
197
 
139
- function setupCatch() {
140
- broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
141
- broker.bindQueue(messageQueueName, 'api', '*.message.#', {durable: true});
142
- }
143
- }
198
+ proto._debug = function debug(msg) {
199
+ this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
200
+ };