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
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _Api = require("../Api");
8
- var _messageHelper = require("../messageHelper");
7
+ var _Api = require("../Api.js");
8
+ var _messageHelper = require("../messageHelper.js");
9
9
  const kCompleted = Symbol.for('completed');
10
10
  const kExecuteQ = Symbol.for('executeQ');
11
11
  const kExecuteMessage = Symbol.for('executeMessage');
@@ -29,14 +29,13 @@ function ActivityExecution(activity, context) {
29
29
  onExecuteMessage: this._onExecuteMessage.bind(this)
30
30
  };
31
31
  }
32
- const proto = ActivityExecution.prototype;
33
- Object.defineProperty(proto, 'completed', {
32
+ Object.defineProperty(ActivityExecution.prototype, 'completed', {
34
33
  enumerable: true,
35
34
  get() {
36
35
  return this[kCompleted];
37
36
  }
38
37
  });
39
- proto.execute = function execute(executeMessage) {
38
+ ActivityExecution.prototype.execute = function execute(executeMessage) {
40
39
  if (!executeMessage) throw new Error('Execution requires message');
41
40
  const executionId = executeMessage.content && executeMessage.content.executionId;
42
41
  if (!executionId) throw new Error('Execution requires execution id');
@@ -60,7 +59,7 @@ proto.execute = function execute(executeMessage) {
60
59
  this.source = new this.activity.Behaviour(this.activity, this.context);
61
60
  this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(initMessage.content));
62
61
  };
63
- proto.activate = function activate() {
62
+ ActivityExecution.prototype.activate = function activate() {
64
63
  if (this[kCompleted]) return;
65
64
  const broker = this.broker;
66
65
  const batchSize = this.activity.environment.settings.batchSize || 50;
@@ -84,19 +83,19 @@ proto.activate = function activate() {
84
83
  priority: 200
85
84
  });
86
85
  };
87
- proto.deactivate = function deactivate() {
86
+ ActivityExecution.prototype.deactivate = function deactivate() {
88
87
  const broker = this.broker;
89
88
  broker.cancel('_activity-api-execution');
90
89
  broker.cancel('_activity-execute');
91
90
  broker.unbindQueue('execute-q', 'execution', 'execute.#');
92
91
  };
93
- proto.discard = function discard() {
92
+ ActivityExecution.prototype.discard = function discard() {
94
93
  if (this[kCompleted]) return;
95
94
  const initMessage = this[kExecuteMessage];
96
95
  if (!initMessage) return this.activity.logger.warn(`<${this.id}> is not executing`);
97
96
  this.getApi(initMessage).discard();
98
97
  };
99
- proto.getApi = function getApi(apiMessage) {
98
+ ActivityExecution.prototype.getApi = function getApi(apiMessage) {
100
99
  const self = this;
101
100
  if (!apiMessage) apiMessage = this[kExecuteMessage];
102
101
  if (self.source.getApi) {
@@ -113,17 +112,17 @@ proto.getApi = function getApi(apiMessage) {
113
112
  };
114
113
  return api;
115
114
  };
116
- proto.passthrough = function passthrough(executeMessage) {
115
+ ActivityExecution.prototype.passthrough = function passthrough(executeMessage) {
117
116
  if (!this.source) return this.execute(executeMessage);
118
117
  return this._sourceExecute(executeMessage);
119
118
  };
120
- proto.getPostponed = function getPostponed() {
119
+ ActivityExecution.prototype.getPostponed = function getPostponed() {
121
120
  let apis = this[kPostponed].map(msg => this.getApi(msg));
122
121
  if (!this.activity.isSubProcess || !this.source) return apis;
123
122
  apis = apis.concat(this.source.getPostponed());
124
123
  return apis;
125
124
  };
126
- proto.getState = function getState() {
125
+ ActivityExecution.prototype.getState = function getState() {
127
126
  const result = {
128
127
  completed: this[kCompleted]
129
128
  };
@@ -134,7 +133,7 @@ proto.getState = function getState() {
134
133
  ...source.getState()
135
134
  };
136
135
  };
137
- proto.recover = function recover(state) {
136
+ ActivityExecution.prototype.recover = function recover(state) {
138
137
  this[kPostponed].splice(0);
139
138
  if (!state) return this;
140
139
  if ('completed' in state) this[kCompleted] = state.completed;
@@ -144,12 +143,12 @@ proto.recover = function recover(state) {
144
143
  }
145
144
  return this;
146
145
  };
147
- proto.stop = function stop() {
146
+ ActivityExecution.prototype.stop = function stop() {
148
147
  const executeMessage = this[kExecuteMessage];
149
148
  if (!executeMessage) return;
150
149
  this.getApi(executeMessage).stop();
151
150
  };
152
- proto._sourceExecute = function sourceExecute(executeMessage) {
151
+ ActivityExecution.prototype._sourceExecute = function sourceExecute(executeMessage) {
153
152
  try {
154
153
  return this.source.execute(executeMessage);
155
154
  } catch (error) {
@@ -158,7 +157,7 @@ proto._sourceExecute = function sourceExecute(executeMessage) {
158
157
  }));
159
158
  }
160
159
  };
161
- proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
160
+ ActivityExecution.prototype._onExecuteMessage = function onExecuteMessage(routingKey, message) {
162
161
  const {
163
162
  fields,
164
163
  content,
@@ -172,10 +171,12 @@ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
172
171
  if (!this[kPostponed].length) return this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content));
173
172
  break;
174
173
  }
174
+ case 'execute.cancel':
175
+ return this._onExecutionDiscarded('cancel', message);
175
176
  case 'execute.error':
177
+ return this._onExecutionDiscarded('error', message);
176
178
  case 'execute.discard':
177
- return this._onExecutionDiscarded(message);
178
- case 'execute.cancel':
179
+ return this._onExecutionDiscarded('discard', message);
179
180
  case 'execute.completed':
180
181
  {
181
182
  if (isRedelivered) {
@@ -209,7 +210,7 @@ proto._onExecuteMessage = function onExecuteMessage(routingKey, message) {
209
210
  }
210
211
  }
211
212
  };
212
- proto._onStateChangeMessage = function onStateChangeMessage(message) {
213
+ ActivityExecution.prototype._onStateChangeMessage = function onStateChangeMessage(message) {
213
214
  const {
214
215
  ignoreIfExecuting,
215
216
  executionId
@@ -229,7 +230,7 @@ proto._onStateChangeMessage = function onStateChangeMessage(message) {
229
230
  postponed.push(message);
230
231
  return true;
231
232
  };
232
- proto._onExecutionCompleted = function onExecutionCompleted(message) {
233
+ ActivityExecution.prototype._onExecutionCompleted = function onExecutionCompleted(message) {
233
234
  const postponedMsg = this._ackPostponed(message);
234
235
  if (!postponedMsg) return;
235
236
  const postponed = this[kPostponed];
@@ -258,7 +259,7 @@ proto._onExecutionCompleted = function onExecutionCompleted(message) {
258
259
  ...message.content
259
260
  }, message.properties.correlationId);
260
261
  };
261
- proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
262
+ ActivityExecution.prototype._onExecutionDiscarded = function onExecutionDiscarded(discardType, message) {
262
263
  const postponedMsg = this._ackPostponed(message);
263
264
  const {
264
265
  isRootScope,
@@ -281,14 +282,9 @@ proto._onExecutionDiscarded = function onExecutionDiscarded(message) {
281
282
  const subApis = this.getPostponed();
282
283
  postponed.splice(0);
283
284
  for (const api of subApis) api.discard();
284
- if (error) {
285
- return this._publishExecutionCompleted('error', (0, _messageHelper.cloneContent)(message.content, {
286
- error
287
- }), correlationId);
288
- }
289
- this._publishExecutionCompleted('discard', message.content, correlationId);
285
+ this._publishExecutionCompleted(discardType, (0, _messageHelper.cloneContent)(message.content), correlationId);
290
286
  };
291
- proto._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
287
+ ActivityExecution.prototype._publishExecutionCompleted = function publishExecutionCompleted(completionType, completeContent, correlationId) {
292
288
  this[kCompleted] = true;
293
289
  this.broker.publish('execution', `execution.${completionType}`, {
294
290
  ...completeContent,
@@ -298,7 +294,7 @@ proto._publishExecutionCompleted = function publishExecutionCompleted(completion
298
294
  correlationId
299
295
  });
300
296
  };
301
- proto._ackPostponed = function ackPostponed(completeMessage) {
297
+ ActivityExecution.prototype._ackPostponed = function ackPostponed(completeMessage) {
302
298
  const {
303
299
  executionId: eid
304
300
  } = completeMessage.content;
@@ -311,7 +307,7 @@ proto._ackPostponed = function ackPostponed(completeMessage) {
311
307
  msg.ack();
312
308
  return msg;
313
309
  };
314
- proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
310
+ ActivityExecution.prototype._onParentApiMessage = function onParentApiMessage(routingKey, message) {
315
311
  switch (message.properties.type) {
316
312
  case 'error':
317
313
  return this[kExecuteQ].queueMessage({
@@ -329,7 +325,7 @@ proto._onParentApiMessage = function onParentApiMessage(routingKey, message) {
329
325
  }
330
326
  }
331
327
  };
332
- proto._onStop = function onStop(message) {
328
+ ActivityExecution.prototype._onStop = function onStop(message) {
333
329
  const stoppedId = message && message.content && message.content.executionId;
334
330
  const running = this.getPostponed();
335
331
  for (const api of running) {
@@ -340,7 +336,7 @@ proto._onStop = function onStop(message) {
340
336
  this.broker.cancel('_activity-execute');
341
337
  this.broker.cancel('_activity-api-execution');
342
338
  };
343
- proto._debug = function debug(logMessage, executionId) {
339
+ ActivityExecution.prototype._debug = function debug(logMessage, executionId) {
344
340
  executionId = executionId || this.executionId;
345
341
  this.activity.logger.debug(`<${executionId} (${this.id})> ${logMessage}`);
346
342
  };
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = DummyActivity;
7
- var _messageHelper = require("../messageHelper");
7
+ var _messageHelper = require("../messageHelper.js");
8
8
  function DummyActivity(activityDef) {
9
9
  const {
10
10
  id,
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = ExecutionScope;
7
- var _messageHelper = require("../messageHelper");
8
- var _Errors = require("../error/Errors");
7
+ var _messageHelper = require("../messageHelper.js");
8
+ var _Errors = require("../error/Errors.js");
9
9
  function ExecutionScope(activity, initMessage) {
10
10
  const {
11
11
  id,
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Definition = Definition;
7
7
  exports.default = void 0;
8
- var _DefinitionExecution = _interopRequireDefault(require("./DefinitionExecution"));
9
- var _Api = require("../Api");
10
- var _EventBroker = require("../EventBroker");
11
- var _shared = require("../shared");
12
- var _Errors = require("../error/Errors");
13
- var _messageHelper = require("../messageHelper");
8
+ var _DefinitionExecution = _interopRequireDefault(require("./DefinitionExecution.js"));
9
+ var _Api = require("../Api.js");
10
+ var _EventBroker = require("../EventBroker.js");
11
+ var _shared = require("../shared.js");
12
+ var _Errors = require("../error/Errors.js");
13
+ var _messageHelper = require("../messageHelper.js");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
  const kConsuming = Symbol.for('consuming');
16
16
  const kCounters = Symbol.for('counters');
@@ -70,8 +70,7 @@ function Definition(context, options) {
70
70
  this.emitFatal = emitFatal;
71
71
  this.logger = environment.Logger(type.toLowerCase());
72
72
  }
73
- const proto = Definition.prototype;
74
- Object.defineProperty(proto, 'counters', {
73
+ Object.defineProperty(Definition.prototype, 'counters', {
75
74
  enumerable: true,
76
75
  get() {
77
76
  return {
@@ -79,38 +78,43 @@ Object.defineProperty(proto, 'counters', {
79
78
  };
80
79
  }
81
80
  });
82
- Object.defineProperty(proto, 'execution', {
81
+ Object.defineProperty(Definition.prototype, 'execution', {
83
82
  enumerable: true,
84
83
  get() {
85
84
  return this[kExec].execution;
86
85
  }
87
86
  });
88
- Object.defineProperty(proto, 'executionId', {
87
+ Object.defineProperty(Definition.prototype, 'executionId', {
89
88
  enumerable: true,
90
89
  get() {
91
90
  return this[kExec].executionId;
92
91
  }
93
92
  });
94
- Object.defineProperty(proto, 'isRunning', {
93
+ Object.defineProperty(Definition.prototype, 'isRunning', {
95
94
  enumerable: true,
96
95
  get() {
97
96
  if (!this[kConsuming]) return false;
98
97
  return !!this.status;
99
98
  }
100
99
  });
101
- Object.defineProperty(proto, 'status', {
100
+ Object.defineProperty(Definition.prototype, 'status', {
102
101
  enumerable: true,
103
102
  get() {
104
103
  return this[kStatus];
105
104
  }
106
105
  });
107
- Object.defineProperty(proto, 'stopped', {
106
+ Object.defineProperty(Definition.prototype, 'stopped', {
108
107
  enumerable: true,
109
108
  get() {
110
109
  return this[kStopped];
111
110
  }
112
111
  });
113
- proto.run = function run(optionsOrCallback, optionalCallback) {
112
+ Object.defineProperty(Definition.prototype, 'activityStatus', {
113
+ get() {
114
+ return this[kExec].execution && this[kExec].execution.activityStatus || 'idle';
115
+ }
116
+ });
117
+ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
114
118
  const [runOptions, callback] = (0, _shared.getOptionsAndCallback)(optionsOrCallback, optionalCallback);
115
119
  if (this.isRunning) {
116
120
  const err = new Error('definition is already running');
@@ -133,7 +137,7 @@ proto.run = function run(optionsOrCallback, optionalCallback) {
133
137
  this._activateRunConsumers();
134
138
  return this;
135
139
  };
136
- proto.resume = function resume(callback) {
140
+ Definition.prototype.resume = function resume(callback) {
137
141
  if (this.isRunning) {
138
142
  const err = new Error('cannot resume running definition');
139
143
  if (callback) return callback(err);
@@ -152,7 +156,7 @@ proto.resume = function resume(callback) {
152
156
  this._activateRunConsumers();
153
157
  return this;
154
158
  };
155
- proto.recover = function recover(state) {
159
+ Definition.prototype.recover = function recover(state) {
156
160
  if (this.isRunning) throw new Error('cannot recover running definition');
157
161
  if (!state) return this;
158
162
  this[kStopped] = !!state.stopped;
@@ -172,9 +176,8 @@ proto.recover = function recover(state) {
172
176
  this.broker.recover(state.broker);
173
177
  return this;
174
178
  };
175
- proto.shake = function shake(startId) {
179
+ Definition.prototype.shake = function shake(startId) {
176
180
  let result = {};
177
- const broker = this.broker;
178
181
  let bps;
179
182
  if (startId) {
180
183
  const startActivity = this.getActivityById(startId);
@@ -183,28 +186,30 @@ proto.shake = function shake(startId) {
183
186
  if (!bp) return;
184
187
  bps = [bp];
185
188
  } else bps = this.getProcesses();
186
- bps.forEach(shakeProcess);
187
- return result;
188
- function shakeProcess(shakeBp) {
189
- let shovel;
190
- if (!shakeBp.isRunning) {
191
- shovel = shakeBp.broker.createShovel('shaker', {
192
- exchange: 'event',
193
- pattern: '*.shake#'
194
- }, {
195
- broker,
196
- exchange: 'event'
197
- });
198
- }
199
- const shakeResult = shakeBp.shake(startId);
200
- if (shovel) shakeBp.broker.closeShovel('shaker');
189
+ bps.forEach(bp => {
201
190
  result = {
202
191
  ...result,
203
- ...shakeResult
192
+ ...this._shakeProcess(bp, startId)
204
193
  };
194
+ });
195
+ return result;
196
+ };
197
+ Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
198
+ let shovel;
199
+ if (!shakeBp.isRunning) {
200
+ shovel = shakeBp.broker.createShovel('shaker', {
201
+ exchange: 'event',
202
+ pattern: '*.shake#'
203
+ }, {
204
+ broker: this.broker,
205
+ exchange: 'event'
206
+ });
205
207
  }
208
+ const shakeResult = shakeBp.shake(startId);
209
+ if (shovel) shakeBp.broker.closeShovel('shaker');
210
+ return shakeResult;
206
211
  };
207
- proto.getState = function getState() {
212
+ Definition.prototype.getState = function getState() {
208
213
  return this._createMessage({
209
214
  status: this.status,
210
215
  stopped: this.stopped,
@@ -214,25 +219,25 @@ proto.getState = function getState() {
214
219
  broker: this.broker.getState(true)
215
220
  });
216
221
  };
217
- proto.getProcesses = function getProcesses() {
222
+ Definition.prototype.getProcesses = function getProcesses() {
218
223
  const execution = this.execution;
219
224
  if (execution) return execution.getProcesses();
220
225
  return this.context.getProcesses();
221
226
  };
222
- proto.getExecutableProcesses = function getExecutableProcesses() {
227
+ Definition.prototype.getExecutableProcesses = function getExecutableProcesses() {
223
228
  const execution = this.execution;
224
229
  if (execution) return execution.getExecutableProcesses();
225
230
  return this.context.getExecutableProcesses();
226
231
  };
227
- proto.getRunningProcesses = function getRunningProcesses() {
232
+ Definition.prototype.getRunningProcesses = function getRunningProcesses() {
228
233
  const execution = this.execution;
229
234
  if (!execution) return [];
230
235
  return execution.getRunningProcesses();
231
236
  };
232
- proto.getProcessById = function getProcessById(processId) {
237
+ Definition.prototype.getProcessById = function getProcessById(processId) {
233
238
  return this.getProcesses().find(p => p.id === processId);
234
239
  };
235
- proto.getActivityById = function getActivityById(childId) {
240
+ Definition.prototype.getActivityById = function getActivityById(childId) {
236
241
  const bps = this.getProcesses();
237
242
  for (const bp of bps) {
238
243
  const child = bp.getActivityById(childId);
@@ -240,32 +245,32 @@ proto.getActivityById = function getActivityById(childId) {
240
245
  }
241
246
  return null;
242
247
  };
243
- proto.getElementById = function getElementById(elementId) {
248
+ Definition.prototype.getElementById = function getElementById(elementId) {
244
249
  return this.context.getActivityById(elementId);
245
250
  };
246
- proto.getPostponed = function getPostponed(...args) {
251
+ Definition.prototype.getPostponed = function getPostponed(...args) {
247
252
  const execution = this.execution;
248
253
  if (!execution) return [];
249
254
  return execution.getPostponed(...args);
250
255
  };
251
- proto.getApi = function getApi(message) {
256
+ Definition.prototype.getApi = function getApi(message) {
252
257
  const execution = this.execution;
253
258
  if (execution) return execution.getApi(message);
254
259
  message = message || this[kStateMessage];
255
260
  if (!message) throw new Error('Definition is not running');
256
261
  return (0, _Api.DefinitionApi)(this.broker, message);
257
262
  };
258
- proto.signal = function signal(message) {
263
+ Definition.prototype.signal = function signal(message) {
259
264
  return this.getApi().signal(message, {
260
265
  delegate: true
261
266
  });
262
267
  };
263
- proto.cancelActivity = function cancelActivity(message) {
268
+ Definition.prototype.cancelActivity = function cancelActivity(message) {
264
269
  return this.getApi().cancel(message, {
265
270
  delegate: true
266
271
  });
267
272
  };
268
- proto.sendMessage = function sendMessage(message) {
273
+ Definition.prototype.sendMessage = function sendMessage(message) {
269
274
  const messageContent = {
270
275
  message
271
276
  };
@@ -285,11 +290,11 @@ proto.sendMessage = function sendMessage(message) {
285
290
  delegate: true
286
291
  });
287
292
  };
288
- proto.stop = function stop() {
293
+ Definition.prototype.stop = function stop() {
289
294
  if (!this.isRunning) return;
290
295
  this.getApi().stop();
291
296
  };
292
- proto._activateRunConsumers = function activateRunConsumers() {
297
+ Definition.prototype._activateRunConsumers = function activateRunConsumers() {
293
298
  this[kConsuming] = true;
294
299
  const broker = this.broker;
295
300
  const {
@@ -305,14 +310,14 @@ proto._activateRunConsumers = function activateRunConsumers() {
305
310
  consumerTag: '_definition-run'
306
311
  });
307
312
  };
308
- proto._deactivateRunConsumers = function deactivateRunConsumers() {
313
+ Definition.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
309
314
  const broker = this.broker;
310
315
  broker.cancel('_definition-api');
311
316
  broker.cancel('_definition-run');
312
317
  broker.cancel('_definition-execution');
313
318
  this[kConsuming] = false;
314
319
  };
315
- proto._createMessage = function createMessage(override) {
320
+ Definition.prototype._createMessage = function createMessage(override) {
316
321
  return {
317
322
  id: this.id,
318
323
  type: this.type,
@@ -321,7 +326,7 @@ proto._createMessage = function createMessage(override) {
321
326
  ...override
322
327
  };
323
328
  };
324
- proto._onRunMessage = function onRunMessage(routingKey, message) {
329
+ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message) {
325
330
  const {
326
331
  content,
327
332
  fields
@@ -405,7 +410,7 @@ proto._onRunMessage = function onRunMessage(routingKey, message) {
405
410
  }
406
411
  message.ack();
407
412
  };
408
- proto._onResumeMessage = function onResumeMessage(message) {
413
+ Definition.prototype._onResumeMessage = function onResumeMessage(message) {
409
414
  message.ack();
410
415
  const stateMessage = this[kStateMessage];
411
416
  switch (stateMessage.fields.routingKey) {
@@ -420,7 +425,7 @@ proto._onResumeMessage = function onResumeMessage(message) {
420
425
  this._debug(`resume from ${this.status}`);
421
426
  return this.broker.publish('run', stateMessage.fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
422
427
  };
423
- proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
428
+ Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
424
429
  const {
425
430
  content,
426
431
  properties
@@ -447,7 +452,7 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
447
452
  this[kExecuteMessage] = null;
448
453
  executeMessage.ack();
449
454
  };
450
- proto._onApiMessage = function onApiMessage(routingKey, message) {
455
+ Definition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
451
456
  if (message.properties.type === 'stop') {
452
457
  const execution = this.execution;
453
458
  if (!execution || execution.completed) {
@@ -455,32 +460,32 @@ proto._onApiMessage = function onApiMessage(routingKey, message) {
455
460
  }
456
461
  }
457
462
  };
458
- proto._publishEvent = function publishEvent(action, content, msgOpts) {
463
+ Definition.prototype._publishEvent = function publishEvent(action, content, msgOpts) {
459
464
  const execution = this.execution;
460
465
  this.broker.publish('event', `definition.${action}`, execution ? execution._createMessage(content) : (0, _messageHelper.cloneContent)(content), {
461
466
  type: action,
462
467
  ...msgOpts
463
468
  });
464
469
  };
465
- proto._onStop = function onStop() {
470
+ Definition.prototype._onStop = function onStop() {
466
471
  this[kStopped] = true;
467
472
  this._deactivateRunConsumers();
468
473
  return this._publishEvent('stop', this._createMessage());
469
474
  };
470
- proto._onBrokerReturnFn = function onBrokerReturn(message) {
475
+ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
471
476
  if (message.properties.type === 'error') {
472
477
  this._deactivateRunConsumers();
473
478
  const err = (0, _Errors.makeErrorFromMessage)(message);
474
479
  throw err;
475
480
  }
476
481
  };
477
- proto._reset = function reset() {
482
+ Definition.prototype._reset = function reset() {
478
483
  this[kExec].executionId = undefined;
479
484
  this._deactivateRunConsumers();
480
485
  this.broker.purgeQueue('run-q');
481
486
  this.broker.purgeQueue('execution-q');
482
487
  };
483
- proto._debug = function debug(msg) {
488
+ Definition.prototype._debug = function debug(msg) {
484
489
  this.logger.debug(`<${this.id}> ${msg}`);
485
490
  };
486
491
  function addConsumerCallbacks(definition, callback) {