bpmn-elements 6.0.0 → 8.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 (116) hide show
  1. package/CHANGELOG.md +335 -0
  2. package/README.md +3 -0
  3. package/dist/index.js +52 -44
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +176 -172
  6. package/dist/src/Environment.js +110 -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/activity/Activity.js +1106 -916
  12. package/dist/src/activity/ActivityExecution.js +342 -297
  13. package/dist/src/activity/Dummy.js +3 -3
  14. package/dist/src/definition/Definition.js +498 -444
  15. package/dist/src/definition/DefinitionExecution.js +710 -408
  16. package/dist/src/error/Errors.js +17 -7
  17. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  18. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  19. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  20. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  21. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  22. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  23. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  24. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  25. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  26. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  27. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  28. package/dist/src/events/BoundaryEvent.js +180 -144
  29. package/dist/src/events/EndEvent.js +18 -23
  30. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  31. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  32. package/dist/src/events/StartEvent.js +109 -94
  33. package/dist/src/flows/Association.js +94 -100
  34. package/dist/src/flows/MessageFlow.js +86 -103
  35. package/dist/src/flows/SequenceFlow.js +173 -182
  36. package/dist/src/gateways/EventBasedGateway.js +88 -84
  37. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  38. package/dist/src/gateways/InclusiveGateway.js +11 -14
  39. package/dist/src/gateways/ParallelGateway.js +11 -14
  40. package/dist/src/getPropertyValue.js +34 -34
  41. package/dist/src/io/BpmnIO.js +17 -14
  42. package/dist/src/io/EnvironmentDataObject.js +33 -29
  43. package/dist/src/io/EnvironmentDataStore.js +33 -29
  44. package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
  45. package/dist/src/io/InputOutputSpecification.js +177 -168
  46. package/dist/src/io/Properties.js +117 -124
  47. package/dist/src/messageHelper.js +1 -1
  48. package/dist/src/process/Process.js +439 -362
  49. package/dist/src/process/ProcessExecution.js +748 -646
  50. package/dist/src/shared.js +2 -2
  51. package/dist/src/tasks/CallActivity.js +160 -0
  52. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  53. package/dist/src/tasks/ReceiveTask.js +233 -182
  54. package/dist/src/tasks/ScriptTask.js +35 -41
  55. package/dist/src/tasks/ServiceImplementation.js +13 -20
  56. package/dist/src/tasks/ServiceTask.js +82 -75
  57. package/dist/src/tasks/SignalTask.js +97 -93
  58. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  59. package/dist/src/tasks/SubProcess.js +193 -175
  60. package/dist/src/tasks/Task.js +17 -19
  61. package/index.js +2 -0
  62. package/package.json +15 -15
  63. package/src/Api.js +65 -59
  64. package/src/Context.js +145 -140
  65. package/src/Environment.js +116 -100
  66. package/src/EventBroker.js +67 -68
  67. package/src/ExtensionsMapper.js +2 -2
  68. package/src/MessageFormatter.js +132 -74
  69. package/src/activity/Activity.js +915 -775
  70. package/src/activity/ActivityExecution.js +293 -247
  71. package/src/activity/Dummy.js +2 -2
  72. package/src/definition/Definition.js +437 -401
  73. package/src/definition/DefinitionExecution.js +598 -340
  74. package/src/error/Errors.js +11 -6
  75. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  76. package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
  77. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  78. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  79. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  80. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  81. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  82. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  83. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  84. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  85. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  86. package/src/events/BoundaryEvent.js +156 -115
  87. package/src/events/EndEvent.js +15 -18
  88. package/src/events/IntermediateCatchEvent.js +40 -44
  89. package/src/events/IntermediateThrowEvent.js +15 -18
  90. package/src/events/StartEvent.js +84 -50
  91. package/src/flows/Association.js +98 -112
  92. package/src/flows/MessageFlow.js +81 -97
  93. package/src/flows/SequenceFlow.js +146 -160
  94. package/src/gateways/EventBasedGateway.js +75 -68
  95. package/src/gateways/ExclusiveGateway.js +8 -13
  96. package/src/gateways/InclusiveGateway.js +8 -13
  97. package/src/gateways/ParallelGateway.js +8 -13
  98. package/src/getPropertyValue.js +34 -33
  99. package/src/io/BpmnIO.js +20 -15
  100. package/src/io/EnvironmentDataObject.js +29 -18
  101. package/src/io/EnvironmentDataStore.js +29 -18
  102. package/src/io/EnvironmentDataStoreReference.js +31 -20
  103. package/src/io/InputOutputSpecification.js +154 -157
  104. package/src/io/Properties.js +95 -97
  105. package/src/process/Process.js +378 -333
  106. package/src/process/ProcessExecution.js +603 -553
  107. package/src/tasks/CallActivity.js +130 -0
  108. package/src/tasks/LoopCharacteristics.js +290 -289
  109. package/src/tasks/ReceiveTask.js +174 -107
  110. package/src/tasks/ScriptTask.js +27 -30
  111. package/src/tasks/ServiceImplementation.js +13 -18
  112. package/src/tasks/ServiceTask.js +67 -60
  113. package/src/tasks/SignalTask.js +77 -52
  114. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  115. package/src/tasks/SubProcess.js +184 -157
  116. 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 kCompleted = Symbol.for('completed');
16
+ const kExecuteMessage = Symbol.for('executeMessage');
17
+ const kReferenceElement = Symbol.for('referenceElement');
18
+ const kReferenceInfo = 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[kReferenceElement] = 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[kReferenceElement];
68
+ this[kCompleted] = 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[kExecuteMessage] = 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[kReferenceInfo] = 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[kCompleted]) 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[kReferenceInfo];
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[kExecuteMessage].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[kCompleted] = true;
177
+
178
+ this._stop();
179
+
180
+ return this.broker.publish('execution', 'execute.discard', (0, _messageHelper.cloneContent)(this[kExecuteMessage].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[kCompleted] = true;
194
+
195
+ this._stop();
196
+
197
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(this[kExecuteMessage].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
+ };