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
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = BoundaryEvent;
7
6
  exports.BoundaryEventBehaviour = BoundaryEventBehaviour;
7
+ exports.default = BoundaryEvent;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -16,165 +16,201 @@ var _shared = require("../shared");
16
16
 
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
 
19
+ const attachedTagsSymbol = Symbol.for('attachedConsumers');
20
+ const completeContentSymbol = Symbol.for('completeContent');
21
+ const executeMessageSymbol = Symbol.for('executeMessage');
22
+ const executionSymbol = Symbol.for('execution');
23
+ const shovelsSymbol = Symbol.for('shovels');
24
+
19
25
  function BoundaryEvent(activityDef, context) {
20
- return (0, _Activity.default)(BoundaryEventBehaviour, activityDef, context);
26
+ return new _Activity.default(BoundaryEventBehaviour, activityDef, context);
21
27
  }
22
28
 
23
29
  function BoundaryEventBehaviour(activity) {
24
- const {
25
- id,
26
- type = 'BoundaryEvent',
27
- broker,
28
- environment,
29
- attachedTo,
30
- behaviour = {},
31
- eventDefinitions,
32
- logger
33
- } = activity;
34
- const attachedToId = attachedTo.id;
35
- const cancelActivity = 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
36
- const eventDefinitionExecution = eventDefinitions && (0, _EventDefinitionExecution.default)(activity, eventDefinitions, 'execute.bound.completed');
37
- return {
38
- id,
39
- type,
40
- attachedTo,
41
- cancelActivity,
42
- execute
43
- };
44
-
45
- function execute(executeMessage) {
46
- const executeContent = (0, _messageHelper.cloneContent)(executeMessage.content);
47
- const {
48
- isRootScope,
49
- executionId,
50
- inbound
51
- } = executeContent;
52
- let parentExecutionId, completeContent;
53
- const errorConsumerTags = [];
54
- const shovels = [];
55
-
56
- if (isRootScope) {
57
- parentExecutionId = executionId;
58
-
59
- if (eventDefinitionExecution && !environment.settings.strict) {
60
- broker.subscribeTmp('execution', 'execute.expect', onExpectMessage, {
61
- noAck: true,
62
- consumerTag: '_expect-tag'
63
- });
64
- }
65
-
66
- attachedTo.broker.subscribeTmp('event', 'activity.leave', onAttachedLeave, {
67
- noAck: true,
68
- consumerTag: `_bound-listener-${parentExecutionId}`,
69
- priority: 300
70
- });
71
- broker.subscribeOnce('execution', 'execute.detach', onDetachMessage, {
72
- consumerTag: '_detach-tag'
73
- });
74
- broker.subscribeOnce('api', `activity.#.${parentExecutionId}`, onApiMessage, {
75
- consumerTag: `_api-${parentExecutionId}`
76
- });
77
- broker.subscribeOnce('execution', 'execute.bound.completed', onCompleted, {
78
- consumerTag: `_execution-completed-${parentExecutionId}`
79
- });
80
- }
30
+ this.id = activity.id;
31
+ this.type = activity.type;
32
+ this.attachedTo = activity.attachedTo;
33
+ this.activity = activity;
34
+ this.environment = activity.environment;
35
+ this.broker = activity.broker;
36
+ this[executionSymbol] = activity.eventDefinitions && new _EventDefinitionExecution.default(activity, activity.eventDefinitions, 'execute.bound.completed');
37
+ this[shovelsSymbol] = [];
38
+ this[attachedTagsSymbol] = [];
39
+ }
81
40
 
82
- if (eventDefinitionExecution) eventDefinitionExecution.execute(executeMessage);
41
+ const proto = BoundaryEventBehaviour.prototype;
42
+ Object.defineProperty(proto, 'executionId', {
43
+ get() {
44
+ const message = this[executeMessageSymbol];
45
+ return message && message.content.executionId;
46
+ }
83
47
 
84
- function onCompleted(_, message) {
85
- if (!cancelActivity && !message.content.cancelActivity) {
86
- stop();
87
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(message.content));
88
- }
48
+ });
49
+ Object.defineProperty(proto, 'cancelActivity', {
50
+ enumerable: true,
89
51
 
90
- completeContent = message.content;
91
- const attachedToContent = inbound && inbound[0];
92
- logger.debug(`<${executionId} (id)> cancel ${attachedTo.status} activity <${attachedToContent.executionId} (${attachedToContent.id})>`);
93
- attachedTo.getApi({
94
- content: attachedToContent
95
- }).discard();
96
- }
52
+ get() {
53
+ const behaviour = this.activity.behaviour || {};
54
+ return 'cancelActivity' in behaviour ? behaviour.cancelActivity : true;
55
+ }
97
56
 
98
- function onAttachedLeave(routingKey, message) {
99
- if (message.content.id !== attachedToId) return;
100
- stop();
101
- if (!completeContent) return broker.publish('execution', 'execute.discard', executeContent);
102
- return broker.publish('execution', 'execute.completed', completeContent);
103
- }
57
+ });
104
58
 
105
- function onExpectMessage(_, message) {
106
- const errorConsumerTag = `_bound-error-listener-${message.content.executionId}`;
107
- errorConsumerTags.push(errorConsumerTag);
108
- attachedTo.broker.subscribeTmp('event', 'activity.error', attachedErrorHandler(message.content.expectRoutingKey), {
109
- noAck: true,
110
- consumerTag: errorConsumerTag,
111
- priority: 300
112
- });
113
- }
59
+ proto.execute = function execute(executeMessage) {
60
+ const {
61
+ isRootScope,
62
+ executionId
63
+ } = executeMessage.content;
64
+ const eventDefinitionExecution = this[executionSymbol];
114
65
 
115
- function attachedErrorHandler(routingKey) {
116
- return function onAttachedError(_, message) {
117
- if (message.content.id !== attachedToId) return;
118
- broker.publish('execution', routingKey, (0, _messageHelper.cloneContent)(message.content));
119
- };
120
- }
66
+ if (isRootScope) {
67
+ this[executeMessageSymbol] = executeMessage;
68
+ const broker = this.broker;
121
69
 
122
- function onDetachMessage(_, {
123
- content
124
- }) {
125
- logger.debug(`<${parentExecutionId} (${id})> detach from activity <${attachedTo.id}>`);
126
- stop(true);
127
- const {
128
- executionId: detachId,
129
- bindExchange,
130
- sourceExchange = 'execution',
131
- sourcePattern
132
- } = content;
133
- const shovelName = `_detached-${(0, _shared.brokerSafeId)(id)}_${detachId}`;
134
- shovels.push(shovelName);
135
- attachedTo.broker.createShovel(shovelName, {
136
- exchange: sourceExchange,
137
- pattern: sourcePattern
138
- }, {
139
- broker,
140
- exchange: bindExchange
141
- }, {
142
- cloneMessage: _messageHelper.cloneMessage
143
- });
144
- broker.subscribeOnce('execution', 'execute.bound.completed', onDetachedCompleted, {
145
- consumerTag: `_execution-completed-${parentExecutionId}`
70
+ if (eventDefinitionExecution && !this.environment.settings.strict) {
71
+ broker.subscribeTmp('execution', 'execute.expect', this._onExpectMessage.bind(this), {
72
+ noAck: true,
73
+ consumerTag: '_expect-tag'
146
74
  });
147
75
  }
148
76
 
149
- function onDetachedCompleted(_, message) {
150
- stop();
151
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(message.content));
152
- }
77
+ const consumerTag = `_bound-listener-${executionId}`;
78
+ this.attachedTo.broker.subscribeTmp('event', 'activity.leave', this._onAttachedLeave.bind(this), {
79
+ noAck: true,
80
+ consumerTag,
81
+ priority: 300
82
+ });
83
+ this[attachedTagsSymbol].push(consumerTag);
84
+ broker.subscribeOnce('execution', 'execute.detach', this._onDetachMessage.bind(this), {
85
+ consumerTag: '_detach-tag'
86
+ });
87
+ broker.subscribeOnce('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
88
+ consumerTag: `_api-${executionId}`
89
+ });
90
+ broker.subscribeOnce('execution', 'execute.bound.completed', this._onCompleted.bind(this), {
91
+ consumerTag: `_execution-completed-${executionId}`
92
+ });
93
+ }
153
94
 
154
- function onApiMessage(_, message) {
155
- const messageType = message.properties.type;
95
+ if (eventDefinitionExecution) {
96
+ return eventDefinitionExecution.execute(executeMessage);
97
+ }
98
+ };
156
99
 
157
- switch (messageType) {
158
- case 'discard':
159
- stop();
160
- break;
100
+ proto._onCompleted = function onCompleted(_, {
101
+ content
102
+ }) {
103
+ if (!this.cancelActivity && !content.cancelActivity) {
104
+ this._stop();
161
105
 
162
- case 'stop':
163
- stop();
164
- break;
165
- }
166
- }
106
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content));
107
+ }
167
108
 
168
- function stop(detach) {
169
- attachedTo.broker.cancel(`_bound-listener-${parentExecutionId}`);
170
- attachedTo.broker.cancel(`_bound-error-listener-${parentExecutionId}`);
171
- errorConsumerTags.splice(0).forEach(tag => attachedTo.broker.cancel(tag));
172
- shovels.splice(0).forEach(shovelName => attachedTo.broker.closeShovel(shovelName));
173
- broker.cancel('_expect-tag');
174
- broker.cancel('_detach-tag');
175
- broker.cancel(`_execution-completed-${parentExecutionId}`);
176
- if (detach) return;
177
- broker.cancel(`_api-${parentExecutionId}`);
178
- }
109
+ this[completeContentSymbol] = content;
110
+ const {
111
+ inbound
112
+ } = this[executeMessageSymbol].content;
113
+ const attachedToContent = inbound && inbound[0];
114
+ const attachedTo = this.attachedTo;
115
+ this.activity.logger.debug(`<${this.executionId} (${this.id})> cancel ${attachedTo.status} activity <${attachedToContent.executionId} (${attachedToContent.id})>`);
116
+ attachedTo.getApi({
117
+ content: attachedToContent
118
+ }).discard();
119
+ };
120
+
121
+ proto._onAttachedLeave = function onAttachedLeave(_, {
122
+ content
123
+ }) {
124
+ if (content.id !== this.attachedTo.id) return;
125
+
126
+ this._stop();
127
+
128
+ const completeContent = this[completeContentSymbol];
129
+ if (!completeContent) return this.broker.publish('execution', 'execute.discard', this[executeMessageSymbol].content);
130
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(completeContent));
131
+ };
132
+
133
+ proto._onExpectMessage = function onExpectMessage(_, {
134
+ content
135
+ }) {
136
+ const {
137
+ executionId,
138
+ expectRoutingKey
139
+ } = content;
140
+ const attachedTo = this.attachedTo;
141
+ const errorConsumerTag = `_bound-error-listener-${executionId}`;
142
+ this[attachedTagsSymbol].push(errorConsumerTag);
143
+ attachedTo.broker.subscribeTmp('event', 'activity.error', (__, errorMessage) => {
144
+ if (errorMessage.content.id !== attachedTo.id) return;
145
+ this.broker.publish('execution', expectRoutingKey, (0, _messageHelper.cloneContent)(errorMessage.content));
146
+ }, {
147
+ noAck: true,
148
+ consumerTag: errorConsumerTag,
149
+ priority: 300
150
+ });
151
+ };
152
+
153
+ proto._onDetachMessage = function onDetachMessage(_, {
154
+ content
155
+ }) {
156
+ const id = this.id,
157
+ executionId = this.executionId,
158
+ attachedTo = this.attachedTo;
159
+ this.activity.logger.debug(`<${executionId} (${id})> detach from activity <${attachedTo.id}>`);
160
+
161
+ this._stop(true);
162
+
163
+ const {
164
+ executionId: detachId,
165
+ bindExchange,
166
+ sourceExchange,
167
+ sourcePattern
168
+ } = content;
169
+ const shovelName = `_detached-${(0, _shared.brokerSafeId)(id)}_${detachId}`;
170
+ this[shovelsSymbol].push(shovelName);
171
+ const broker = this.broker;
172
+ attachedTo.broker.createShovel(shovelName, {
173
+ exchange: sourceExchange,
174
+ pattern: sourcePattern
175
+ }, {
176
+ broker,
177
+ exchange: bindExchange
178
+ }, {
179
+ cloneMessage: _messageHelper.cloneMessage
180
+ });
181
+ broker.subscribeOnce('execution', 'execute.bound.completed', (__, {
182
+ content: completeContent
183
+ }) => {
184
+ this._stop();
185
+
186
+ this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(completeContent));
187
+ }, {
188
+ consumerTag: `_execution-completed-${executionId}`
189
+ });
190
+ };
191
+
192
+ proto._onApiMessage = function onApiMessage(_, message) {
193
+ switch (message.properties.type) {
194
+ case 'discard':
195
+ case 'stop':
196
+ this._stop();
197
+
198
+ break;
179
199
  }
180
- }
200
+ };
201
+
202
+ proto._stop = function stop(detach) {
203
+ const attachedTo = this.attachedTo,
204
+ broker = this.broker,
205
+ executionId = this.executionId;
206
+
207
+ for (const tag of this[attachedTagsSymbol].splice(0)) attachedTo.broker.cancel(tag);
208
+
209
+ for (const shovelName of this[shovelsSymbol].splice(0)) attachedTo.broker.closeShovel(shovelName);
210
+
211
+ broker.cancel('_expect-tag');
212
+ broker.cancel('_detach-tag');
213
+ broker.cancel(`_execution-completed-${executionId}`);
214
+ if (detach) return;
215
+ broker.cancel(`_api-${executionId}`);
216
+ };
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = EndEvent;
7
6
  exports.EndEventBehaviour = EndEventBehaviour;
7
+ exports.default = EndEvent;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -14,32 +14,27 @@ var _messageHelper = require("../messageHelper");
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
17
+ const executionSymbol = Symbol.for('execution');
18
+
17
19
  function EndEvent(activityDef, context) {
18
- return (0, _Activity.default)(EndEventBehaviour, { ...activityDef,
20
+ return new _Activity.default(EndEventBehaviour, { ...activityDef,
19
21
  isThrowing: true
20
22
  }, context);
21
23
  }
22
24
 
23
25
  function EndEventBehaviour(activity) {
24
- const {
25
- id,
26
- type,
27
- broker,
28
- eventDefinitions
29
- } = activity;
30
- const eventDefinitionExecution = eventDefinitions && (0, _EventDefinitionExecution.default)(activity, eventDefinitions);
31
- const source = {
32
- id,
33
- type,
34
- execute
35
- };
36
- return source;
37
-
38
- function execute(executeMessage) {
39
- if (eventDefinitionExecution) {
40
- return eventDefinitionExecution.execute(executeMessage);
41
- }
42
-
43
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeMessage.content));
26
+ this.id = activity.id;
27
+ this.type = activity.type;
28
+ this.broker = activity.broker;
29
+ this[executionSymbol] = activity.eventDefinitions && new _EventDefinitionExecution.default(activity, activity.eventDefinitions);
30
+ }
31
+
32
+ EndEventBehaviour.prototype.execute = function execute(executeMessage) {
33
+ const execution = this[executionSymbol];
34
+
35
+ if (execution) {
36
+ return execution.execute(executeMessage);
44
37
  }
45
- }
38
+
39
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeMessage.content));
40
+ };
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = IntermediateCatchEvent;
7
6
  exports.IntermediateCatchEventBehaviour = IntermediateCatchEventBehaviour;
7
+ exports.default = IntermediateCatchEvent;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -14,72 +14,58 @@ var _messageHelper = require("../messageHelper");
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
17
+ const executionSymbol = Symbol.for('execution');
18
+
17
19
  function IntermediateCatchEvent(activityDef, context) {
18
- return (0, _Activity.default)(IntermediateCatchEventBehaviour, activityDef, context);
20
+ return new _Activity.default(IntermediateCatchEventBehaviour, activityDef, context);
19
21
  }
20
22
 
21
23
  function IntermediateCatchEventBehaviour(activity) {
22
- const {
23
- id,
24
- type,
25
- broker,
26
- eventDefinitions
27
- } = activity;
28
- const eventDefinitionExecution = eventDefinitions && (0, _EventDefinitionExecution.default)(activity, eventDefinitions);
29
- const source = {
30
- id,
31
- type,
32
- execute
33
- };
34
- return source;
35
-
36
- function execute(executeMessage) {
37
- if (eventDefinitionExecution) {
38
- return eventDefinitionExecution.execute(executeMessage);
39
- }
40
-
41
- const content = (0, _messageHelper.cloneContent)(executeMessage.content);
42
- const {
43
- executionId
44
- } = content;
45
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
46
- noAck: true,
47
- consumerTag: `_api-${executionId}`
48
- });
49
- return broker.publish('event', 'activity.wait', (0, _messageHelper.cloneContent)(content));
24
+ this.id = activity.id;
25
+ this.type = activity.type;
26
+ this.broker = activity.broker;
27
+ this[executionSymbol] = activity.eventDefinitions && new _EventDefinitionExecution.default(activity, activity.eventDefinitions);
28
+ }
50
29
 
51
- function onApiMessage(routingKey, message) {
52
- const messageType = message.properties.type;
30
+ IntermediateCatchEventBehaviour.prototype.execute = function execute(executeMessage) {
31
+ const execution = this[executionSymbol];
53
32
 
54
- switch (messageType) {
55
- case 'message':
56
- case 'signal':
57
- {
58
- return complete(message.content.message);
59
- }
33
+ if (execution) {
34
+ return execution.execute(executeMessage);
35
+ }
60
36
 
61
- case 'discard':
62
- {
63
- stop();
64
- return broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(content));
65
- }
37
+ const executeContent = executeMessage.content;
38
+ const executionId = executeContent.executionId;
39
+ const broker = this.broker;
40
+ broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this, executeMessage), {
41
+ noAck: true,
42
+ consumerTag: '_api-behaviour-execution'
43
+ });
44
+ return broker.publish('event', 'activity.wait', (0, _messageHelper.cloneContent)(executeContent));
45
+ };
66
46
 
67
- case 'stop':
68
- {
69
- return stop();
70
- }
47
+ IntermediateCatchEventBehaviour.prototype._onApiMessage = function onApiMessage(executeMessage, routingKey, message) {
48
+ switch (message.properties.type) {
49
+ case 'message':
50
+ case 'signal':
51
+ {
52
+ const broker = this.broker;
53
+ broker.cancel('_api-behaviour-execution');
54
+ return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeMessage.content, {
55
+ output: message.content.message
56
+ }));
71
57
  }
72
- }
73
58
 
74
- function complete(output) {
75
- stop();
76
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content, {
77
- output
78
- }));
79
- }
59
+ case 'discard':
60
+ {
61
+ const broker = this.broker;
62
+ broker.cancel('_api-behaviour-execution');
63
+ return broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(executeMessage.content));
64
+ }
80
65
 
81
- function stop() {
82
- broker.cancel(`_api-${executionId}`);
83
- }
66
+ case 'stop':
67
+ {
68
+ return this.broker.cancel('_api-behaviour-execution');
69
+ }
84
70
  }
85
- }
71
+ };
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = IntermediateThrowEvent;
7
6
  exports.IntermediateThrowEventBehaviour = IntermediateThrowEventBehaviour;
7
+ exports.default = IntermediateThrowEvent;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -14,32 +14,27 @@ var _messageHelper = require("../messageHelper");
14
14
 
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
 
17
+ const executionSymbol = Symbol.for('execution');
18
+
17
19
  function IntermediateThrowEvent(activityDef, context) {
18
- return (0, _Activity.default)(IntermediateThrowEventBehaviour, { ...activityDef,
20
+ return new _Activity.default(IntermediateThrowEventBehaviour, { ...activityDef,
19
21
  isThrowing: true
20
22
  }, context);
21
23
  }
22
24
 
23
25
  function IntermediateThrowEventBehaviour(activity) {
24
- const {
25
- id,
26
- type,
27
- broker,
28
- eventDefinitions
29
- } = activity;
30
- const eventDefinitionExecution = eventDefinitions && (0, _EventDefinitionExecution.default)(activity, eventDefinitions);
31
- const source = {
32
- id,
33
- type,
34
- execute
35
- };
36
- return source;
37
-
38
- function execute(executeMessage) {
39
- if (eventDefinitionExecution) {
40
- return eventDefinitionExecution.execute(executeMessage);
41
- }
42
-
43
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeMessage.content));
26
+ this.id = activity.id;
27
+ this.type = activity.type;
28
+ this.broker = activity.broker;
29
+ this[executionSymbol] = activity.eventDefinitions && new _EventDefinitionExecution.default(activity, activity.eventDefinitions);
30
+ }
31
+
32
+ IntermediateThrowEventBehaviour.prototype.execute = function execute(executeMessage) {
33
+ const execution = this[executionSymbol];
34
+
35
+ if (execution) {
36
+ return execution.execute(executeMessage);
44
37
  }
45
- }
38
+
39
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeMessage.content));
40
+ };