bpmn-elements 8.2.4 → 9.1.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 (127) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +1 -1
  3. package/dist/{src/Api.js → Api.js} +11 -12
  4. package/dist/{src/Context.js → Context.js} +26 -27
  5. package/dist/{src/Environment.js → Environment.js} +15 -16
  6. package/dist/{src/EventBroker.js → EventBroker.js} +5 -1
  7. package/dist/{src/Expressions.js → Expressions.js} +1 -1
  8. package/dist/{src/MessageFormatter.js → MessageFormatter.js} +3 -3
  9. package/dist/Tracker.js +89 -0
  10. package/dist/{src/activity → activity}/Activity.js +109 -120
  11. package/dist/{src/activity → activity}/ActivityExecution.js +28 -32
  12. package/dist/{src/activity → activity}/Dummy.js +1 -1
  13. package/dist/{src/activity → activity}/ExecutionScope.js +2 -2
  14. package/dist/{src/definition → definition}/Definition.js +64 -59
  15. package/dist/{src/definition → definition}/DefinitionExecution.js +68 -46
  16. package/dist/{src/error → error}/Errors.js +1 -1
  17. package/dist/eventDefinitions/CancelEventDefinition.js +127 -0
  18. package/dist/{src/eventDefinitions → eventDefinitions}/CompensateEventDefinition.js +64 -52
  19. package/dist/{src/eventDefinitions → eventDefinitions}/ConditionalEventDefinition.js +24 -16
  20. package/dist/{src/eventDefinitions → eventDefinitions}/ErrorEventDefinition.js +15 -14
  21. package/dist/{src/eventDefinitions → eventDefinitions}/EscalationEventDefinition.js +12 -13
  22. package/dist/{src/eventDefinitions → eventDefinitions}/EventDefinitionExecution.js +10 -11
  23. package/dist/{src/eventDefinitions → eventDefinitions}/LinkEventDefinition.js +14 -15
  24. package/dist/{src/eventDefinitions → eventDefinitions}/MessageEventDefinition.js +13 -14
  25. package/dist/{src/eventDefinitions → eventDefinitions}/SignalEventDefinition.js +13 -14
  26. package/dist/{src/eventDefinitions → eventDefinitions}/TerminateEventDefinition.js +1 -1
  27. package/dist/{src/eventDefinitions → eventDefinitions}/TimerEventDefinition.js +15 -16
  28. package/dist/{src/events → events}/BoundaryEvent.js +39 -25
  29. package/dist/{src/events → events}/EndEvent.js +3 -3
  30. package/dist/{src/events → events}/IntermediateCatchEvent.js +3 -3
  31. package/dist/{src/events → events}/IntermediateThrowEvent.js +3 -3
  32. package/dist/{src/events → events}/StartEvent.js +8 -9
  33. package/dist/{src/flows → flows}/Association.js +14 -22
  34. package/dist/{src/flows → flows}/MessageFlow.js +16 -14
  35. package/dist/{src/flows → flows}/SequenceFlow.js +16 -18
  36. package/dist/{src/gateways → gateways}/EventBasedGateway.js +3 -4
  37. package/dist/{src/gateways → gateways}/ExclusiveGateway.js +2 -2
  38. package/dist/{src/gateways → gateways}/InclusiveGateway.js +2 -2
  39. package/dist/{src/gateways → gateways}/ParallelGateway.js +2 -2
  40. package/dist/index.js +48 -48
  41. package/dist/{src/io → io}/InputOutputSpecification.js +8 -9
  42. package/dist/{src/io → io}/Properties.js +7 -8
  43. package/dist/package.json +3 -0
  44. package/dist/{src/process → process}/Process.js +44 -40
  45. package/dist/{src/process → process}/ProcessExecution.js +169 -78
  46. package/dist/{src/tasks → tasks}/CallActivity.js +7 -8
  47. package/dist/{src/tasks → tasks}/LoopCharacteristics.js +2 -2
  48. package/dist/{src/tasks → tasks}/ReceiveTask.js +14 -15
  49. package/dist/{src/tasks → tasks}/ScriptTask.js +4 -4
  50. package/dist/{src/tasks → tasks}/ServiceImplementation.js +1 -1
  51. package/dist/{src/tasks → tasks}/ServiceTask.js +6 -7
  52. package/dist/{src/tasks → tasks}/SignalTask.js +7 -8
  53. package/dist/{src/tasks → tasks}/StandardLoopCharacteristics.js +1 -1
  54. package/dist/{src/tasks → tasks}/SubProcess.js +19 -19
  55. package/dist/{src/tasks → tasks}/Task.js +2 -2
  56. package/dist/{src/tasks → tasks}/Transaction.js +1 -1
  57. package/package.json +31 -31
  58. package/src/Api.js +11 -13
  59. package/src/Context.js +26 -28
  60. package/src/Environment.js +15 -17
  61. package/src/EventBroker.js +2 -1
  62. package/src/Expressions.js +1 -1
  63. package/src/MessageFormatter.js +3 -3
  64. package/src/Tracker.js +73 -0
  65. package/src/activity/Activity.js +106 -114
  66. package/src/activity/ActivityExecution.js +28 -32
  67. package/src/activity/Dummy.js +1 -1
  68. package/src/activity/ExecutionScope.js +2 -2
  69. package/src/definition/Definition.js +65 -64
  70. package/src/definition/DefinitionExecution.js +71 -47
  71. package/src/error/Errors.js +1 -1
  72. package/src/eventDefinitions/CancelEventDefinition.js +32 -78
  73. package/src/eventDefinitions/CompensateEventDefinition.js +58 -52
  74. package/src/eventDefinitions/ConditionalEventDefinition.js +25 -17
  75. package/src/eventDefinitions/ErrorEventDefinition.js +15 -15
  76. package/src/eventDefinitions/EscalationEventDefinition.js +12 -14
  77. package/src/eventDefinitions/EventDefinitionExecution.js +10 -12
  78. package/src/eventDefinitions/LinkEventDefinition.js +14 -16
  79. package/src/eventDefinitions/MessageEventDefinition.js +13 -15
  80. package/src/eventDefinitions/SignalEventDefinition.js +13 -15
  81. package/src/eventDefinitions/TerminateEventDefinition.js +1 -1
  82. package/src/eventDefinitions/TimerEventDefinition.js +15 -17
  83. package/src/events/BoundaryEvent.js +34 -24
  84. package/src/events/EndEvent.js +3 -3
  85. package/src/events/IntermediateCatchEvent.js +3 -3
  86. package/src/events/IntermediateThrowEvent.js +3 -3
  87. package/src/events/StartEvent.js +8 -10
  88. package/src/flows/Association.js +14 -26
  89. package/src/flows/MessageFlow.js +14 -15
  90. package/src/flows/SequenceFlow.js +16 -20
  91. package/src/gateways/EventBasedGateway.js +3 -4
  92. package/src/gateways/ExclusiveGateway.js +2 -2
  93. package/src/gateways/InclusiveGateway.js +2 -2
  94. package/src/gateways/ParallelGateway.js +2 -2
  95. package/src/index.js +106 -0
  96. package/src/io/InputOutputSpecification.js +8 -10
  97. package/src/io/Properties.js +7 -9
  98. package/src/process/Process.js +45 -41
  99. package/src/process/ProcessExecution.js +167 -79
  100. package/src/tasks/CallActivity.js +7 -9
  101. package/src/tasks/LoopCharacteristics.js +2 -2
  102. package/src/tasks/ReceiveTask.js +215 -217
  103. package/src/tasks/ScriptTask.js +4 -4
  104. package/src/tasks/ServiceImplementation.js +1 -1
  105. package/src/tasks/ServiceTask.js +6 -8
  106. package/src/tasks/SignalTask.js +7 -9
  107. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  108. package/src/tasks/SubProcess.js +19 -20
  109. package/src/tasks/Task.js +2 -2
  110. package/src/tasks/Transaction.js +1 -1
  111. package/types/index.d.ts +520 -0
  112. package/dist/src/eventDefinitions/CancelEventDefinition.js +0 -184
  113. package/index.js +0 -106
  114. /package/dist/{src/ExtensionsMapper.js → ExtensionsMapper.js} +0 -0
  115. /package/dist/{src/Scripts.js → Scripts.js} +0 -0
  116. /package/dist/{src/Timers.js → Timers.js} +0 -0
  117. /package/dist/{src/activity → activity}/Escalation.js +0 -0
  118. /package/dist/{src/activity → activity}/Message.js +0 -0
  119. /package/dist/{src/activity → activity}/Signal.js +0 -0
  120. /package/dist/{src/error → error}/BpmnError.js +0 -0
  121. /package/dist/{src/getPropertyValue.js → getPropertyValue.js} +0 -0
  122. /package/dist/{src/io → io}/BpmnIO.js +0 -0
  123. /package/dist/{src/io → io}/EnvironmentDataObject.js +0 -0
  124. /package/dist/{src/io → io}/EnvironmentDataStore.js +0 -0
  125. /package/dist/{src/io → io}/EnvironmentDataStoreReference.js +0 -0
  126. /package/dist/{src/messageHelper.js → messageHelper.js} +0 -0
  127. /package/dist/{src/shared.js → shared.js} +0 -0
@@ -1,5 +1,5 @@
1
- import {ActivityApi} from '../Api';
2
- import {cloneContent, cloneMessage} from '../messageHelper';
1
+ import {ActivityApi} from '../Api.js';
2
+ import {cloneContent, cloneMessage} from '../messageHelper.js';
3
3
 
4
4
  const kCompleted = Symbol.for('completed');
5
5
  const kExecuteQ = Symbol.for('executeQ');
@@ -24,16 +24,14 @@ function ActivityExecution(activity, context) {
24
24
  };
25
25
  }
26
26
 
27
- const proto = ActivityExecution.prototype;
28
-
29
- Object.defineProperty(proto, 'completed', {
27
+ Object.defineProperty(ActivityExecution.prototype, 'completed', {
30
28
  enumerable: true,
31
29
  get() {
32
30
  return this[kCompleted];
33
31
  },
34
32
  });
35
33
 
36
- proto.execute = function execute(executeMessage) {
34
+ ActivityExecution.prototype.execute = function execute(executeMessage) {
37
35
  if (!executeMessage) throw new Error('Execution requires message');
38
36
  const executionId = executeMessage.content && executeMessage.content.executionId;
39
37
  if (!executionId) throw new Error('Execution requires execution id');
@@ -61,7 +59,7 @@ proto.execute = function execute(executeMessage) {
61
59
  this.broker.publish('execution', 'execute.start', cloneContent(initMessage.content));
62
60
  };
63
61
 
64
- proto.activate = function activate() {
62
+ ActivityExecution.prototype.activate = function activate() {
65
63
  if (this[kCompleted]) return;
66
64
 
67
65
  const broker = this.broker;
@@ -85,21 +83,21 @@ proto.activate = function activate() {
85
83
  });
86
84
  };
87
85
 
88
- proto.deactivate = function deactivate() {
86
+ ActivityExecution.prototype.deactivate = function deactivate() {
89
87
  const broker = this.broker;
90
88
  broker.cancel('_activity-api-execution');
91
89
  broker.cancel('_activity-execute');
92
90
  broker.unbindQueue('execute-q', 'execution', 'execute.#');
93
91
  };
94
92
 
95
- proto.discard = function discard() {
93
+ ActivityExecution.prototype.discard = function discard() {
96
94
  if (this[kCompleted]) return;
97
95
  const initMessage = this[kExecuteMessage];
98
96
  if (!initMessage) return this.activity.logger.warn(`<${this.id}> is not executing`);
99
97
  this.getApi(initMessage).discard();
100
98
  };
101
99
 
102
- proto.getApi = function getApi(apiMessage) {
100
+ ActivityExecution.prototype.getApi = function getApi(apiMessage) {
103
101
  const self = this;
104
102
  if (!apiMessage) apiMessage = this[kExecuteMessage];
105
103
 
@@ -121,19 +119,19 @@ proto.getApi = function getApi(apiMessage) {
121
119
  return api;
122
120
  };
123
121
 
124
- proto.passthrough = function passthrough(executeMessage) {
122
+ ActivityExecution.prototype.passthrough = function passthrough(executeMessage) {
125
123
  if (!this.source) return this.execute(executeMessage);
126
124
  return this._sourceExecute(executeMessage);
127
125
  };
128
126
 
129
- proto.getPostponed = function getPostponed() {
127
+ ActivityExecution.prototype.getPostponed = function getPostponed() {
130
128
  let apis = this[kPostponed].map((msg) => this.getApi(msg));
131
129
  if (!this.activity.isSubProcess || !this.source) return apis;
132
130
  apis = apis.concat(this.source.getPostponed());
133
131
  return apis;
134
132
  };
135
133
 
136
- proto.getState = function getState() {
134
+ ActivityExecution.prototype.getState = function getState() {
137
135
  const result = {completed: this[kCompleted]};
138
136
  const source = this.source;
139
137
 
@@ -141,7 +139,7 @@ proto.getState = function getState() {
141
139
  return {...result, ...source.getState()};
142
140
  };
143
141
 
144
- proto.recover = function recover(state) {
142
+ ActivityExecution.prototype.recover = function recover(state) {
145
143
  this[kPostponed].splice(0);
146
144
 
147
145
  if (!state) return this;
@@ -155,13 +153,13 @@ proto.recover = function recover(state) {
155
153
  return this;
156
154
  };
157
155
 
158
- proto.stop = function stop() {
156
+ ActivityExecution.prototype.stop = function stop() {
159
157
  const executeMessage = this[kExecuteMessage];
160
158
  if (!executeMessage) return;
161
159
  this.getApi(executeMessage).stop();
162
160
  };
163
161
 
164
- proto._sourceExecute = function sourceExecute(executeMessage) {
162
+ ActivityExecution.prototype._sourceExecute = function sourceExecute(executeMessage) {
165
163
  try {
166
164
  return this.source.execute(executeMessage);
167
165
  } catch (error) {
@@ -169,7 +167,7 @@ proto._sourceExecute = function sourceExecute(executeMessage) {
169
167
  }
170
168
  };
171
169
 
172
- proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
170
+ ActivityExecution.prototype._onExecuteMessage = function onExecuteMessage(routingKey, message) {
173
171
  const {fields, content, properties} = message;
174
172
  const isRedelivered = fields.redelivered;
175
173
 
@@ -180,10 +178,12 @@ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
180
178
  if (!this[kPostponed].length) return this.broker.publish('execution', 'execute.start', cloneContent(this[kExecuteMessage].content));
181
179
  break;
182
180
  }
181
+ case 'execute.cancel':
182
+ return this._onExecutionDiscarded('cancel', message);
183
183
  case 'execute.error':
184
+ return this._onExecutionDiscarded('error', message);
184
185
  case 'execute.discard':
185
- return this._onExecutionDiscarded(message);
186
- case 'execute.cancel':
186
+ return this._onExecutionDiscarded('discard', message);
187
187
  case 'execute.completed': {
188
188
  if (isRedelivered) {
189
189
  message.ack();
@@ -213,7 +213,7 @@ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
213
213
  }
214
214
  };
215
215
 
216
- proto._onStateChangeMessage = function onStateChangeMessage(message) {
216
+ ActivityExecution.prototype._onStateChangeMessage = function onStateChangeMessage(message) {
217
217
  const {ignoreIfExecuting, executionId} = message.content;
218
218
  const postponed = this[kPostponed];
219
219
  const idx = postponed.findIndex((msg) => msg.content.executionId === executionId);
@@ -234,7 +234,7 @@ proto._onStateChangeMessage = function onStateChangeMessage(message) {
234
234
  return true;
235
235
  };
236
236
 
237
- proto._onExecutionCompleted = function onExecutionCompleted(message) {
237
+ ActivityExecution.prototype._onExecutionCompleted = function onExecutionCompleted(message) {
238
238
  const postponedMsg = this._ackPostponed(message);
239
239
  if (!postponedMsg) return;
240
240
  const postponed = this[kPostponed];
@@ -263,7 +263,7 @@ proto._onExecutionCompleted = function onExecutionCompleted(message) {
263
263
  this._publishExecutionCompleted('completed', {...postponedMsg.content, ...message.content}, message.properties.correlationId);
264
264
  };
265
265
 
266
- proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
266
+ ActivityExecution.prototype._onExecutionDiscarded = function onExecutionDiscarded(discardType, message) {
267
267
  const postponedMsg = this._ackPostponed(message);
268
268
  const {isRootScope, error} = message.content;
269
269
  if (!isRootScope && !postponedMsg) return;
@@ -286,14 +286,10 @@ proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
286
286
  postponed.splice(0);
287
287
  for (const api of subApis) api.discard();
288
288
 
289
- if (error) {
290
- return this._publishExecutionCompleted('error', cloneContent(message.content, {error}), correlationId);
291
- }
292
-
293
- this._publishExecutionCompleted('discard', message.content, correlationId);
289
+ this._publishExecutionCompleted(discardType, cloneContent(message.content), correlationId);
294
290
  };
295
291
 
296
- proto._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
292
+ ActivityExecution.prototype._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
297
293
  this[kCompleted] = true;
298
294
 
299
295
  this.broker.publish('execution', `execution.${completionType}`, {
@@ -302,7 +298,7 @@ proto._publishExecutionCompleted = function publishExecutionCompleted(completion
302
298
  }, {type: completionType, correlationId});
303
299
  };
304
300
 
305
- proto._ackPostponed = function ackPostponed(completeMessage) {
301
+ ActivityExecution.prototype._ackPostponed = function ackPostponed(completeMessage) {
306
302
  const {executionId: eid} = completeMessage.content;
307
303
 
308
304
  const postponed = this[kPostponed];
@@ -313,7 +309,7 @@ proto._ackPostponed = function ackPostponed(completeMessage) {
313
309
  return msg;
314
310
  };
315
311
 
316
- proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
312
+ ActivityExecution.prototype._onParentApiMessage = function onParentApiMessage(routingKey, message) {
317
313
  switch (message.properties.type) {
318
314
  case 'error':
319
315
  return this[kExecuteQ].queueMessage({routingKey: 'execute.error'}, {error: message.content.error});
@@ -325,7 +321,7 @@ proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
325
321
  }
326
322
  };
327
323
 
328
- proto._onStop = function onStop(message) {
324
+ ActivityExecution.prototype._onStop = function onStop(message) {
329
325
  const stoppedId = message && message.content && message.content.executionId;
330
326
  const running = this.getPostponed();
331
327
  for (const api of running) {
@@ -338,7 +334,7 @@ proto._onStop = function onStop(message) {
338
334
  this.broker.cancel('_activity-api-execution');
339
335
  };
340
336
 
341
- proto._debug = function debug(logMessage, executionId) {
337
+ ActivityExecution.prototype._debug = function debug(logMessage, executionId) {
342
338
  executionId = executionId || this.executionId;
343
339
  this.activity.logger.debug(`<${executionId} (${this.id})> ${logMessage}`);
344
340
  };
@@ -1,4 +1,4 @@
1
- import {cloneParent} from '../messageHelper';
1
+ import {cloneParent} from '../messageHelper.js';
2
2
 
3
3
  export default function DummyActivity(activityDef) {
4
4
  const {id, type = 'dummy', name, parent, behaviour} = activityDef;
@@ -1,5 +1,5 @@
1
- import {cloneMessage} from '../messageHelper';
2
- import {ActivityError, BpmnError} from '../error/Errors';
1
+ import {cloneMessage} from '../messageHelper.js';
2
+ import {ActivityError, BpmnError} from '../error/Errors.js';
3
3
 
4
4
  export default function ExecutionScope(activity, initMessage) {
5
5
  const {id, type, environment, logger} = activity;
@@ -1,9 +1,9 @@
1
- import DefinitionExecution from './DefinitionExecution';
2
- import {DefinitionApi} from '../Api';
3
- import {DefinitionBroker} from '../EventBroker';
4
- import {getUniqueId, getOptionsAndCallback} from '../shared';
5
- import {makeErrorFromMessage} from '../error/Errors';
6
- import {cloneMessage, cloneContent} from '../messageHelper';
1
+ import DefinitionExecution from './DefinitionExecution.js';
2
+ import {DefinitionApi} from '../Api.js';
3
+ import {DefinitionBroker} from '../EventBroker.js';
4
+ import {getUniqueId, getOptionsAndCallback} from '../shared.js';
5
+ import {makeErrorFromMessage} from '../error/Errors.js';
6
+ import {cloneMessage, cloneContent} from '../messageHelper.js';
7
7
 
8
8
  const kConsuming = Symbol.for('consuming');
9
9
  const kCounters = Symbol.for('counters');
@@ -63,30 +63,28 @@ export function Definition(context, options) {
63
63
  this.logger = environment.Logger(type.toLowerCase());
64
64
  }
65
65
 
66
- const proto = Definition.prototype;
67
-
68
- Object.defineProperty(proto, 'counters', {
66
+ Object.defineProperty(Definition.prototype, 'counters', {
69
67
  enumerable: true,
70
68
  get() {
71
69
  return {...this[kCounters]};
72
70
  },
73
71
  });
74
72
 
75
- Object.defineProperty(proto, 'execution', {
73
+ Object.defineProperty(Definition.prototype, 'execution', {
76
74
  enumerable: true,
77
75
  get() {
78
76
  return this[kExec].execution;
79
77
  },
80
78
  });
81
79
 
82
- Object.defineProperty(proto, 'executionId', {
80
+ Object.defineProperty(Definition.prototype, 'executionId', {
83
81
  enumerable: true,
84
82
  get() {
85
83
  return this[kExec].executionId;
86
84
  },
87
85
  });
88
86
 
89
- Object.defineProperty(proto, 'isRunning', {
87
+ Object.defineProperty(Definition.prototype, 'isRunning', {
90
88
  enumerable: true,
91
89
  get() {
92
90
  if (!this[kConsuming]) return false;
@@ -94,21 +92,27 @@ Object.defineProperty(proto, 'isRunning', {
94
92
  },
95
93
  });
96
94
 
97
- Object.defineProperty(proto, 'status', {
95
+ Object.defineProperty(Definition.prototype, 'status', {
98
96
  enumerable: true,
99
97
  get() {
100
98
  return this[kStatus];
101
99
  },
102
100
  });
103
101
 
104
- Object.defineProperty(proto, 'stopped', {
102
+ Object.defineProperty(Definition.prototype, 'stopped', {
105
103
  enumerable: true,
106
104
  get() {
107
105
  return this[kStopped];
108
106
  },
109
107
  });
110
108
 
111
- proto.run = function run(optionsOrCallback, optionalCallback) {
109
+ Object.defineProperty(Definition.prototype, 'activityStatus', {
110
+ get() {
111
+ return this[kExec].execution && this[kExec].execution.activityStatus || 'idle';
112
+ },
113
+ });
114
+
115
+ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
112
116
  const [runOptions, callback] = getOptionsAndCallback(optionsOrCallback, optionalCallback);
113
117
  if (this.isRunning) {
114
118
  const err = new Error('definition is already running');
@@ -136,7 +140,7 @@ proto.run = function run(optionsOrCallback, optionalCallback) {
136
140
  return this;
137
141
  };
138
142
 
139
- proto.resume = function resume(callback) {
143
+ Definition.prototype.resume = function resume(callback) {
140
144
  if (this.isRunning) {
141
145
  const err = new Error('cannot resume running definition');
142
146
  if (callback) return callback(err);
@@ -158,7 +162,7 @@ proto.resume = function resume(callback) {
158
162
  return this;
159
163
  };
160
164
 
161
- proto.recover = function recover(state) {
165
+ Definition.prototype.recover = function recover(state) {
162
166
  if (this.isRunning) throw new Error('cannot recover running definition');
163
167
  if (!state) return this;
164
168
 
@@ -182,10 +186,8 @@ proto.recover = function recover(state) {
182
186
  return this;
183
187
  };
184
188
 
185
- proto.shake = function shake(startId) {
189
+ Definition.prototype.shake = function shake(startId) {
186
190
  let result = {};
187
- const broker = this.broker;
188
-
189
191
  let bps;
190
192
  if (startId) {
191
193
  const startActivity = this.getActivityById(startId);
@@ -195,33 +197,32 @@ proto.shake = function shake(startId) {
195
197
  bps = [bp];
196
198
  } else bps = this.getProcesses();
197
199
 
198
- bps.forEach(shakeProcess);
200
+ bps.forEach((bp) => {
201
+ result = {...result, ...this._shakeProcess(bp, startId)};
202
+ });
199
203
 
200
204
  return result;
205
+ };
201
206
 
202
- function shakeProcess(shakeBp) {
203
- let shovel;
204
- if (!shakeBp.isRunning) {
205
- shovel = shakeBp.broker.createShovel('shaker', {
206
- exchange: 'event',
207
- pattern: '*.shake#',
208
- }, {
209
- broker,
210
- exchange: 'event',
211
- });
212
- }
207
+ Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
208
+ let shovel;
209
+ if (!shakeBp.isRunning) {
210
+ shovel = shakeBp.broker.createShovel('shaker', {
211
+ exchange: 'event',
212
+ pattern: '*.shake#',
213
+ }, {
214
+ broker: this.broker,
215
+ exchange: 'event',
216
+ });
217
+ }
213
218
 
214
- const shakeResult = shakeBp.shake(startId);
215
- if (shovel) shakeBp.broker.closeShovel('shaker');
219
+ const shakeResult = shakeBp.shake(startId);
220
+ if (shovel) shakeBp.broker.closeShovel('shaker');
216
221
 
217
- result = {
218
- ...result,
219
- ...shakeResult,
220
- };
221
- }
222
+ return shakeResult;
222
223
  };
223
224
 
224
- proto.getState = function getState() {
225
+ Definition.prototype.getState = function getState() {
225
226
  return this._createMessage({
226
227
  status: this.status,
227
228
  stopped: this.stopped,
@@ -232,29 +233,29 @@ proto.getState = function getState() {
232
233
  });
233
234
  };
234
235
 
235
- proto.getProcesses = function getProcesses() {
236
+ Definition.prototype.getProcesses = function getProcesses() {
236
237
  const execution = this.execution;
237
238
  if (execution) return execution.getProcesses();
238
239
  return this.context.getProcesses();
239
240
  };
240
241
 
241
- proto.getExecutableProcesses = function getExecutableProcesses() {
242
+ Definition.prototype.getExecutableProcesses = function getExecutableProcesses() {
242
243
  const execution = this.execution;
243
244
  if (execution) return execution.getExecutableProcesses();
244
245
  return this.context.getExecutableProcesses();
245
246
  };
246
247
 
247
- proto.getRunningProcesses = function getRunningProcesses() {
248
+ Definition.prototype.getRunningProcesses = function getRunningProcesses() {
248
249
  const execution = this.execution;
249
250
  if (!execution) return [];
250
251
  return execution.getRunningProcesses();
251
252
  };
252
253
 
253
- proto.getProcessById = function getProcessById(processId) {
254
+ Definition.prototype.getProcessById = function getProcessById(processId) {
254
255
  return this.getProcesses().find((p) => p.id === processId);
255
256
  };
256
257
 
257
- proto.getActivityById = function getActivityById(childId) {
258
+ Definition.prototype.getActivityById = function getActivityById(childId) {
258
259
  const bps = this.getProcesses();
259
260
  for (const bp of bps) {
260
261
  const child = bp.getActivityById(childId);
@@ -263,17 +264,17 @@ proto.getActivityById = function getActivityById(childId) {
263
264
  return null;
264
265
  };
265
266
 
266
- proto.getElementById = function getElementById(elementId) {
267
+ Definition.prototype.getElementById = function getElementById(elementId) {
267
268
  return this.context.getActivityById(elementId);
268
269
  };
269
270
 
270
- proto.getPostponed = function getPostponed(...args) {
271
+ Definition.prototype.getPostponed = function getPostponed(...args) {
271
272
  const execution = this.execution;
272
273
  if (!execution) return [];
273
274
  return execution.getPostponed(...args);
274
275
  };
275
276
 
276
- proto.getApi = function getApi(message) {
277
+ Definition.prototype.getApi = function getApi(message) {
277
278
  const execution = this.execution;
278
279
  if (execution) return execution.getApi(message);
279
280
  message = message || this[kStateMessage];
@@ -281,15 +282,15 @@ proto.getApi = function getApi(message) {
281
282
  return DefinitionApi(this.broker, message);
282
283
  };
283
284
 
284
- proto.signal = function signal(message) {
285
+ Definition.prototype.signal = function signal(message) {
285
286
  return this.getApi().signal(message, {delegate: true});
286
287
  };
287
288
 
288
- proto.cancelActivity = function cancelActivity(message) {
289
+ Definition.prototype.cancelActivity = function cancelActivity(message) {
289
290
  return this.getApi().cancel(message, {delegate: true});
290
291
  };
291
292
 
292
- proto.sendMessage = function sendMessage(message) {
293
+ Definition.prototype.sendMessage = function sendMessage(message) {
293
294
  const messageContent = {message};
294
295
  let messageType = 'message';
295
296
  const reference = message && message.id && this.getElementById(message.id);
@@ -302,12 +303,12 @@ proto.sendMessage = function sendMessage(message) {
302
303
  return this.getApi().sendApiMessage(messageType, messageContent, {delegate: true});
303
304
  };
304
305
 
305
- proto.stop = function stop() {
306
+ Definition.prototype.stop = function stop() {
306
307
  if (!this.isRunning) return;
307
308
  this.getApi().stop();
308
309
  };
309
310
 
310
- proto._activateRunConsumers = function activateRunConsumers() {
311
+ Definition.prototype._activateRunConsumers = function activateRunConsumers() {
311
312
  this[kConsuming] = true;
312
313
  const broker = this.broker;
313
314
  const {onApiMessage, onRunMessage} = this[kMessageHandlers];
@@ -321,7 +322,7 @@ proto._activateRunConsumers = function activateRunConsumers() {
321
322
  });
322
323
  };
323
324
 
324
- proto._deactivateRunConsumers = function deactivateRunConsumers() {
325
+ Definition.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
325
326
  const broker = this.broker;
326
327
  broker.cancel('_definition-api');
327
328
  broker.cancel('_definition-run');
@@ -329,7 +330,7 @@ proto._deactivateRunConsumers = function deactivateRunConsumers() {
329
330
  this[kConsuming] = false;
330
331
  };
331
332
 
332
- proto._createMessage = function createMessage(override) {
333
+ Definition.prototype._createMessage = function createMessage(override) {
333
334
  return {
334
335
  id: this.id,
335
336
  type: this.type,
@@ -339,7 +340,7 @@ proto._createMessage = function createMessage(override) {
339
340
  };
340
341
  };
341
342
 
342
- proto._onRunMessage = function onRunMessage(routingKey, message) {
343
+ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message) {
343
344
  const {content, fields} = message;
344
345
  if (routingKey === 'run.resume') {
345
346
  return this._onResumeMessage(message);
@@ -425,7 +426,7 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
425
426
  message.ack();
426
427
  };
427
428
 
428
- proto._onResumeMessage = function onResumeMessage(message) {
429
+ Definition.prototype._onResumeMessage = function onResumeMessage(message) {
429
430
  message.ack();
430
431
 
431
432
  const stateMessage = this[kStateMessage];
@@ -446,7 +447,7 @@ proto._onResumeMessage = function onResumeMessage(message) {
446
447
  return this.broker.publish('run', stateMessage.fields.routingKey, cloneContent(stateMessage.content), stateMessage.properties);
447
448
  };
448
449
 
449
- proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
450
+ Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
450
451
  const {content, properties} = message;
451
452
  const messageType = properties.type;
452
453
 
@@ -471,7 +472,7 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
471
472
  executeMessage.ack();
472
473
  };
473
474
 
474
- proto._onApiMessage = function onApiMessage(routingKey, message) {
475
+ Definition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
475
476
  if (message.properties.type === 'stop') {
476
477
  const execution = this.execution;
477
478
  if (!execution || execution.completed) {
@@ -480,7 +481,7 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
480
481
  }
481
482
  };
482
483
 
483
- proto._publishEvent = function publishEvent(action, content, msgOpts) {
484
+ Definition.prototype._publishEvent = function publishEvent(action, content, msgOpts) {
484
485
  const execution = this.execution;
485
486
  this.broker.publish('event', `definition.${action}`, execution ? execution._createMessage(content) : cloneContent(content), {
486
487
  type: action,
@@ -488,13 +489,13 @@ proto._publishEvent = function publishEvent(action, content, msgOpts) {
488
489
  });
489
490
  };
490
491
 
491
- proto._onStop = function onStop() {
492
+ Definition.prototype._onStop = function onStop() {
492
493
  this[kStopped] = true;
493
494
  this._deactivateRunConsumers();
494
495
  return this._publishEvent('stop', this._createMessage());
495
496
  };
496
497
 
497
- proto._onBrokerReturnFn = function onBrokerReturn(message) {
498
+ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
498
499
  if (message.properties.type === 'error') {
499
500
  this._deactivateRunConsumers();
500
501
  const err = makeErrorFromMessage(message);
@@ -502,14 +503,14 @@ proto._onBrokerReturnFn = function onBrokerReturn(message) {
502
503
  }
503
504
  };
504
505
 
505
- proto._reset = function reset() {
506
+ Definition.prototype._reset = function reset() {
506
507
  this[kExec].executionId = undefined;
507
508
  this._deactivateRunConsumers();
508
509
  this.broker.purgeQueue('run-q');
509
510
  this.broker.purgeQueue('execution-q');
510
511
  };
511
512
 
512
- proto._debug = function debug(msg) {
513
+ Definition.prototype._debug = function debug(msg) {
513
514
  this.logger.debug(`<${this.id}> ${msg}`);
514
515
  };
515
516