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 = ReceiveTask;
7
6
  exports.ReceiveTaskBehaviour = ReceiveTaskBehaviour;
7
+ exports.default = ReceiveTask;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -12,8 +12,13 @@ var _messageHelper = require("../messageHelper");
12
12
 
13
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
14
 
15
+ const completedSymbol = Symbol.for('completed');
16
+ const executeMessageSymbol = Symbol.for('executeMessage');
17
+ const referenceElementSymbol = Symbol.for('referenceElement');
18
+ const referenceInfoSymbol = Symbol.for('referenceInfo');
19
+
15
20
  function ReceiveTask(activityDef, context) {
16
- const task = (0, _Activity.default)(ReceiveTaskBehaviour, activityDef, context);
21
+ const task = new _Activity.default(ReceiveTaskBehaviour, activityDef, context);
17
22
  task.broker.assertQueue('message', {
18
23
  autoDelete: false,
19
24
  durable: true
@@ -28,205 +33,251 @@ function ReceiveTaskBehaviour(activity) {
28
33
  const {
29
34
  id,
30
35
  type,
31
- broker,
32
- logger,
33
- behaviour = {},
34
- getActivityById
36
+ behaviour
35
37
  } = activity;
36
- const reference = behaviour.messageRef || {
37
- name: 'anonymous'
38
+ this.id = id;
39
+ this.type = type;
40
+ const reference = this.reference = {
41
+ name: 'anonymous',
42
+ ...behaviour.messageRef,
43
+ referenceType: 'message'
38
44
  };
39
- const referenceElement = reference.id && getActivityById(reference.id);
40
- const loopCharacteristics = behaviour.loopCharacteristics && behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
41
- const source = {
42
- id,
43
- type,
44
- reference: { ...reference,
45
- referenceType: 'message'
46
- },
47
- execute
48
- };
49
- return source;
45
+ this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
46
+ this.activity = activity;
47
+ this.broker = activity.broker;
48
+ this[referenceElementSymbol] = reference.id && activity.getActivityById(reference.id);
49
+ }
50
50
 
51
- function execute(executeMessage) {
52
- const content = executeMessage.content;
53
- const {
54
- executionId
55
- } = content;
56
- if (content.isRootScope) setupMessageHandling(executionId);
51
+ ReceiveTaskBehaviour.prototype.execute = function execute(executeMessage) {
52
+ return new ReceiveTaskExecution(this).execute(executeMessage);
53
+ };
57
54
 
58
- if (loopCharacteristics && content.isRootScope) {
59
- return loopCharacteristics.execute(executeMessage);
60
- }
55
+ function ReceiveTaskExecution(parent) {
56
+ const {
57
+ activity,
58
+ broker,
59
+ loopCharacteristics,
60
+ reference
61
+ } = parent;
62
+ this.id = activity.id;
63
+ this.logger = activity.logger;
64
+ this.reference = reference;
65
+ this.broker = broker;
66
+ this.loopCharacteristics = loopCharacteristics;
67
+ this.referenceElement = parent[referenceElementSymbol];
68
+ this[completedSymbol] = false;
69
+ }
61
70
 
62
- let completed;
63
- const {
64
- message: referenceMessage,
65
- description
66
- } = resolveReference(executeMessage);
67
- broker.consume('message', onCatchMessage, {
68
- noAck: true,
69
- consumerTag: `_onmessage-${executionId}`
70
- });
71
- if (completed) return;
72
- broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
73
- noAck: true,
74
- consumerTag: `_api-${executionId}`,
75
- priority: 400
76
- });
77
- logger.debug(`<${executionId} (${id})> expect ${description}`);
78
- broker.publish('event', 'activity.wait', (0, _messageHelper.cloneContent)(content, {
79
- message: { ...referenceMessage
80
- }
81
- }));
82
-
83
- function onCatchMessage(routingKey, message) {
84
- const {
85
- content: delegateContent
86
- } = message;
87
- const {
88
- id: signalId,
89
- executionId: signalExecutionId
90
- } = delegateContent.message || {};
91
-
92
- if (!referenceMessage.id && signalId || signalExecutionId) {
93
- if (loopCharacteristics && signalExecutionId !== executionId) return;
94
- if (signalId !== id && signalExecutionId !== executionId) return;
95
- logger.debug(`<${executionId} (${id})> caught direct message`);
96
- } else if (referenceMessage.id !== signalId) return;else {
97
- logger.debug(`<${executionId} (${id})> caught ${description}`);
98
- }
71
+ const proto = ReceiveTaskExecution.prototype;
99
72
 
100
- const {
101
- type: messageType,
102
- correlationId
103
- } = message.properties;
104
- broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(content, {
105
- message: { ...message.content.message
106
- }
107
- }), {
108
- correlationId,
109
- type: messageType
110
- });
111
- broker.publish('event', 'activity.catch', (0, _messageHelper.cloneContent)(content, {
112
- message: message.content.message
113
- }), {
114
- type: 'catch',
115
- correlationId
116
- });
117
- complete(message.content.message, {
118
- correlationId
119
- });
120
- }
73
+ proto.execute = function execute(executeMessage) {
74
+ this[executeMessageSymbol] = executeMessage;
75
+ const executeContent = executeMessage.content;
76
+ const {
77
+ executionId,
78
+ isRootScope
79
+ } = executeContent;
80
+ this.executionId = executionId;
121
81
 
122
- function onApiMessage(routingKey, message) {
123
- const {
124
- type: messageType,
125
- correlationId
126
- } = message.properties;
127
-
128
- switch (messageType) {
129
- case 'message':
130
- case 'signal':
131
- {
132
- return complete(message.content.message, {
133
- correlationId
134
- });
135
- }
136
-
137
- case 'discard':
138
- {
139
- completed = true;
140
- stop();
141
- return broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(content), {
142
- correlationId
143
- });
144
- }
145
-
146
- case 'stop':
147
- {
148
- return stop();
149
- }
150
- }
151
- }
82
+ const info = this[referenceInfoSymbol] = this._getReferenceInfo(executeMessage);
152
83
 
153
- function complete(output, options) {
154
- completed = true;
155
- stop();
156
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content, {
157
- output
158
- }), options);
159
- }
84
+ if (isRootScope) {
85
+ this._setupMessageHandling(executionId);
86
+ }
160
87
 
161
- function stop() {
162
- broker.cancel(`_onmessage-${executionId}`);
163
- broker.cancel(`_api-${executionId}`);
164
- }
88
+ const loopCharacteristics = this.loopCharacteristics;
89
+
90
+ if (loopCharacteristics && executeMessage.content.isRootScope) {
91
+ return loopCharacteristics.execute(executeMessage);
165
92
  }
166
93
 
167
- function setupMessageHandling(executionId) {
168
- broker.subscribeTmp('api', '#.signal.*', onDelegateMessage, {
169
- noAck: true,
170
- consumerTag: `_api-delegated-${executionId}`
171
- }, {
172
- noAck: true
173
- });
174
- broker.subscribeTmp('api', `activity.stop.${executionId}`, onStopApiMessage, {
175
- noAck: true,
176
- consumerTag: `_api-stop-${executionId}`,
177
- priority: 400
178
- });
179
- broker.subscribeTmp('execution', 'execute.#', onComplete, {
180
- noAck: true,
181
- consumerTag: `_execution-complete-${executionId}`
182
- }, {
183
- noAck: true
184
- });
185
-
186
- function onDelegateMessage(_, message) {
187
- if (!message.properties.delegate) return;
188
- broker.sendToQueue('message', message.content, message.properties);
94
+ const broker = this.broker;
95
+ broker.consume('message', this._onCatchMessage.bind(this), {
96
+ noAck: true,
97
+ consumerTag: `_onmessage-${executionId}`
98
+ });
99
+ if (this[completedSymbol]) return;
100
+ broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
101
+ noAck: true,
102
+ consumerTag: `_api-${executionId}`,
103
+ priority: 400
104
+ });
105
+
106
+ this._debug(`expect ${info.description}`);
107
+
108
+ broker.publish('event', 'activity.wait', (0, _messageHelper.cloneContent)(executeContent, {
109
+ message: { ...info.message
189
110
  }
111
+ }));
112
+ };
113
+
114
+ proto._onCatchMessage = function onCatchMessage(routingKey, message) {
115
+ const content = message.content;
116
+ const {
117
+ id: signalId,
118
+ executionId: signalExecutionId
119
+ } = content.message || {};
120
+ const {
121
+ message: referenceMessage,
122
+ description
123
+ } = this[referenceInfoSymbol];
190
124
 
191
- function onStopApiMessage() {
192
- stop(true);
125
+ if (!referenceMessage.id && signalId || signalExecutionId) {
126
+ if (this.loopCharacteristics && signalExecutionId !== this.executionId) return;
127
+ if (signalId !== this.id && signalExecutionId !== this.executionId) return;
128
+
129
+ this._debug('caught direct message');
130
+ } else if (referenceMessage.id !== signalId) return;else {
131
+ this._debug(`caught ${description}`);
132
+ }
133
+
134
+ const {
135
+ type: messageType,
136
+ correlationId
137
+ } = message.properties;
138
+ const broker = this.broker;
139
+ const executeContent = this[executeMessageSymbol].content;
140
+ broker.publish('event', 'activity.consumed', (0, _messageHelper.cloneContent)(executeContent, {
141
+ message: { ...message.content.message
193
142
  }
143
+ }), {
144
+ correlationId,
145
+ type: messageType
146
+ });
147
+ broker.publish('event', 'activity.catch', (0, _messageHelper.cloneContent)(executeContent, {
148
+ message: message.content.message
149
+ }), {
150
+ type: 'catch',
151
+ correlationId
152
+ });
153
+
154
+ this._complete(message.content.message, {
155
+ correlationId
156
+ });
157
+ };
194
158
 
195
- function onComplete(routingKey, {
196
- content
197
- }) {
198
- if (!content.isRootScope) return;
199
-
200
- switch (routingKey) {
201
- case 'execute.completed':
202
- case 'execute.error':
203
- case 'execute.discard':
204
- stop();
205
- break;
159
+ proto._onApiMessage = function onApiMessage(routingKey, message) {
160
+ const {
161
+ type: messageType,
162
+ correlationId
163
+ } = message.properties;
164
+
165
+ switch (messageType) {
166
+ case 'message':
167
+ case 'signal':
168
+ {
169
+ return this._complete(message.content.message, {
170
+ correlationId
171
+ });
206
172
  }
207
- }
208
173
 
209
- function stop(keepMessageQ) {
210
- broker.cancel(`_api-delegated-${executionId}`);
211
- broker.cancel(`_api-stop-${executionId}`);
212
- broker.cancel(`_execution-complete-${executionId}`);
213
- if (!keepMessageQ) broker.purgeQueue('message');
214
- }
174
+ case 'discard':
175
+ {
176
+ this[completedSymbol] = true;
177
+
178
+ this._stop();
179
+
180
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content), {
181
+ correlationId
182
+ });
183
+ }
184
+
185
+ case 'stop':
186
+ {
187
+ return this._stop();
188
+ }
215
189
  }
190
+ };
216
191
 
217
- function resolveReference(message) {
218
- if (!referenceElement) {
219
- return {
220
- message: { ...reference
221
- },
222
- description: 'anonymous message'
223
- };
224
- }
192
+ proto._complete = function complete(output, options) {
193
+ this[completedSymbol] = true;
194
+
195
+ this._stop();
196
+
197
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(this[executeMessageSymbol].content, {
198
+ output
199
+ }), options);
200
+ };
225
201
 
226
- const result = {
227
- message: referenceElement.resolve(message)
202
+ proto._stop = function stop() {
203
+ const broker = this.broker,
204
+ executionId = this.executionId;
205
+ broker.cancel(`_onmessage-${executionId}`);
206
+ broker.cancel(`_api-${executionId}`);
207
+ };
208
+
209
+ proto._setupMessageHandling = function setupMessageHandling(executionId) {
210
+ const broker = this.broker;
211
+ broker.subscribeTmp('api', '#.signal.*', this._onDelegateMessage.bind(this), {
212
+ noAck: true,
213
+ consumerTag: `_api-delegated-${executionId}`
214
+ }, {
215
+ noAck: true
216
+ });
217
+ broker.subscribeTmp('api', `activity.stop.${executionId}`, this._onStopApiMessage.bind(this), {
218
+ noAck: true,
219
+ consumerTag: `_api-stop-${executionId}`,
220
+ priority: 400
221
+ });
222
+ broker.subscribeTmp('execution', 'execute.#', this._onExecutionComplete.bind(this), {
223
+ noAck: true,
224
+ consumerTag: `_execution-complete-${executionId}`
225
+ }, {
226
+ noAck: true
227
+ });
228
+ };
229
+
230
+ proto._onDelegateMessage = function onDelegateMessage(_, message) {
231
+ if (!message.properties.delegate) return;
232
+ this.broker.sendToQueue('message', message.content, message.properties);
233
+ };
234
+
235
+ proto._onStopApiMessage = function onStopApiMessage() {
236
+ this._stopMessageHandling(true);
237
+ };
238
+
239
+ proto._onExecutionComplete = function onExecutionComplete(routingKey, {
240
+ content
241
+ }) {
242
+ if (!content.isRootScope) return;
243
+
244
+ switch (routingKey) {
245
+ case 'execute.completed':
246
+ case 'execute.error':
247
+ case 'execute.discard':
248
+ this._stopMessageHandling();
249
+
250
+ break;
251
+ }
252
+ };
253
+
254
+ proto._stopMessageHandling = function stop(keepMessageQ) {
255
+ const broker = this.broker,
256
+ executionId = this.executionId;
257
+ broker.cancel(`_api-delegated-${executionId}`);
258
+ broker.cancel(`_api-stop-${executionId}`);
259
+ broker.cancel(`_execution-complete-${executionId}`);
260
+ if (!keepMessageQ) broker.purgeQueue('message');
261
+ };
262
+
263
+ proto._getReferenceInfo = function getReferenceInfo(message) {
264
+ const referenceElement = this.referenceElement;
265
+
266
+ if (!referenceElement) {
267
+ return {
268
+ message: { ...this.reference
269
+ },
270
+ description: 'anonymous message'
228
271
  };
229
- result.description = `${result.message.name} <${result.message.id}>`;
230
- return result;
231
272
  }
232
- }
273
+
274
+ const result = {
275
+ message: referenceElement.resolve(message)
276
+ };
277
+ result.description = `${result.message.name} <${result.message.id}>`;
278
+ return result;
279
+ };
280
+
281
+ proto._debug = function debug(msg) {
282
+ this.logger.debug(`<${this.executionId} (${this.id})> ${msg}`);
283
+ };
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = ScriptTask;
7
6
  exports.ScriptTaskBehaviour = ScriptTaskBehaviour;
7
+ exports.default = ScriptTask;
8
8
 
9
9
  var _Activity = _interopRequireDefault(require("../activity/Activity"));
10
10
 
@@ -17,60 +17,54 @@ var _messageHelper = require("../messageHelper");
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
 
19
19
  function ScriptTask(activityDef, context) {
20
- return (0, _Activity.default)(ScriptTaskBehaviour, activityDef, context);
20
+ return new _Activity.default(ScriptTaskBehaviour, activityDef, context);
21
21
  }
22
22
 
23
23
  function ScriptTaskBehaviour(activity) {
24
24
  const {
25
25
  id,
26
26
  type,
27
- behaviour,
28
- broker,
29
- logger,
30
- environment,
31
- emitFatal
27
+ behaviour
32
28
  } = activity;
33
- const {
34
- scriptFormat
35
- } = activity.behaviour;
36
- const loopCharacteristics = behaviour.loopCharacteristics && behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
29
+ this.id = id;
30
+ this.type = type;
31
+ this.scriptFormat = behaviour.scriptFormat;
32
+ this.loopCharacteristics = behaviour.loopCharacteristics && new behaviour.loopCharacteristics.Behaviour(activity, behaviour.loopCharacteristics);
33
+ this.activity = activity;
34
+ const environment = this.environment = activity.environment;
37
35
  environment.registerScript(activity);
38
- const source = {
39
- id,
40
- type,
41
- loopCharacteristics,
42
- execute
43
- };
44
- return source;
45
-
46
- function execute(executeMessage) {
47
- const content = executeMessage.content;
36
+ }
48
37
 
49
- if (loopCharacteristics && content.isRootScope) {
50
- return loopCharacteristics.execute(executeMessage);
51
- }
38
+ ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
39
+ const executeContent = executeMessage.content;
40
+ const loopCharacteristics = this.loopCharacteristics;
52
41
 
53
- const script = environment.getScript(scriptFormat, activity, (0, _messageHelper.cloneMessage)(executeMessage));
42
+ if (loopCharacteristics && executeContent.isRootScope) {
43
+ return loopCharacteristics.execute(executeMessage);
44
+ }
54
45
 
55
- if (!script) {
56
- return emitFatal(new _Errors.ActivityError(`Script format ${scriptFormat} is unsupported or was not registered for <${activity.id}>`, executeMessage), content);
57
- }
46
+ const activity = this.activity,
47
+ scriptFormat = this.scriptFormat;
48
+ const script = this.environment.getScript(scriptFormat, activity, (0, _messageHelper.cloneMessage)(executeMessage));
58
49
 
59
- return script.execute((0, _ExecutionScope.default)(activity, executeMessage), scriptCallback);
50
+ if (!script) {
51
+ return activity.emitFatal(new _Errors.ActivityError(`Script format ${scriptFormat} is unsupported or was not registered for <${activity.id}>`, executeMessage), executeContent);
52
+ }
60
53
 
61
- function scriptCallback(err, output) {
62
- if (err) {
63
- logger.error(`<${content.executionId} (${id})>`, err);
64
- return broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(content, {
65
- error: new _Errors.ActivityError(err.message, executeMessage, err)
66
- }, {
67
- mandatory: true
68
- }));
69
- }
54
+ return script.execute((0, _ExecutionScope.default)(activity, executeMessage), scriptCallback);
70
55
 
71
- return broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(content, {
72
- output
56
+ function scriptCallback(err, output) {
57
+ if (err) {
58
+ activity.logger.error(`<${executeContent.executionId} (${activity.id})>`, err);
59
+ return activity.broker.publish('execution', 'execute.error', (0, _messageHelper.cloneContent)(executeContent, {
60
+ error: new _Errors.ActivityError(err.message, executeMessage, err)
61
+ }, {
62
+ mandatory: true
73
63
  }));
74
64
  }
65
+
66
+ return activity.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(executeContent, {
67
+ output
68
+ }));
75
69
  }
76
- }
70
+ };
@@ -10,24 +10,17 @@ var _ExecutionScope = _interopRequireDefault(require("../activity/ExecutionScope
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
12
12
  function ServiceImplementation(activity) {
13
- const {
14
- type: atype,
15
- behaviour,
16
- environment
17
- } = activity;
18
- const implementation = behaviour.implementation;
19
- const type = `${atype}:implementation`;
20
- return {
21
- type,
22
- implementation,
23
- execute
24
- };
13
+ this.type = `${activity.type}:implementation`;
14
+ this.implementation = activity.behaviour.implementation;
15
+ this.activity = activity;
16
+ }
25
17
 
26
- function execute(executionMessage, callback) {
27
- const serviceFn = environment.resolveExpression(implementation, executionMessage);
28
- if (typeof serviceFn !== 'function') return callback(new Error(`Implementation ${implementation} did not resolve to a function`));
29
- serviceFn.call(activity, (0, _ExecutionScope.default)(activity, executionMessage), (err, ...args) => {
30
- callback(err, args);
31
- });
32
- }
33
- }
18
+ ServiceImplementation.prototype.execute = function execute(executionMessage, callback) {
19
+ const activity = this.activity;
20
+ const implementation = this.implementation;
21
+ const serviceFn = activity.environment.resolveExpression(implementation, executionMessage);
22
+ if (typeof serviceFn !== 'function') return callback(new Error(`Implementation ${implementation} did not resolve to a function`));
23
+ serviceFn.call(activity, (0, _ExecutionScope.default)(activity, executionMessage), (err, ...args) => {
24
+ callback(err, args);
25
+ });
26
+ };