bpmn-elements 14.1.0 → 15.0.1

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 (64) hide show
  1. package/README.md +0 -4
  2. package/dist/Context.js +41 -35
  3. package/dist/Environment.js +4 -4
  4. package/dist/Expressions.js +1 -1
  5. package/dist/MessageFormatter.js +0 -1
  6. package/dist/Scripts.js +3 -8
  7. package/dist/Timers.js +5 -9
  8. package/dist/Tracker.js +15 -19
  9. package/dist/activity/Activity.js +68 -49
  10. package/dist/activity/ActivityExecution.js +43 -29
  11. package/dist/definition/Definition.js +20 -14
  12. package/dist/definition/DefinitionExecution.js +64 -55
  13. package/dist/eventDefinitions/EscalationEventDefinition.js +1 -1
  14. package/dist/eventDefinitions/LinkEventDefinition.js +1 -1
  15. package/dist/eventDefinitions/MessageEventDefinition.js +1 -1
  16. package/dist/eventDefinitions/SignalEventDefinition.js +1 -1
  17. package/dist/eventDefinitions/TimerEventDefinition.js +1 -1
  18. package/dist/events/BoundaryEvent.js +11 -9
  19. package/dist/events/EndEvent.js +1 -1
  20. package/dist/events/IntermediateCatchEvent.js +1 -1
  21. package/dist/events/IntermediateThrowEvent.js +1 -1
  22. package/dist/events/StartEvent.js +1 -1
  23. package/dist/flows/SequenceFlow.js +1 -1
  24. package/dist/gateways/EventBasedGateway.js +1 -1
  25. package/dist/gateways/ExclusiveGateway.js +1 -1
  26. package/dist/gateways/InclusiveGateway.js +1 -1
  27. package/dist/gateways/ParallelGateway.js +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/io/InputOutputSpecification.js +1 -1
  30. package/dist/io/Properties.js +1 -1
  31. package/dist/process/Process.js +20 -19
  32. package/dist/process/ProcessExecution.js +67 -40
  33. package/dist/shared.js +0 -8
  34. package/dist/tasks/CallActivity.js +1 -1
  35. package/dist/tasks/LoopCharacteristics.js +2 -2
  36. package/dist/tasks/ReceiveTask.js +1 -1
  37. package/dist/tasks/ScriptTask.js +3 -3
  38. package/dist/tasks/ServiceImplementation.js +1 -1
  39. package/dist/tasks/ServiceTask.js +1 -1
  40. package/dist/tasks/SignalTask.js +1 -1
  41. package/dist/tasks/StandardLoopCharacteristics.js +1 -1
  42. package/dist/tasks/SubProcess.js +30 -33
  43. package/dist/tasks/Task.js +1 -1
  44. package/dist/tasks/Transaction.js +1 -1
  45. package/package.json +4 -4
  46. package/src/Context.js +51 -35
  47. package/src/Environment.js +4 -4
  48. package/src/MessageFormatter.js +0 -3
  49. package/src/Scripts.js +3 -8
  50. package/src/Timers.js +5 -9
  51. package/src/Tracker.js +13 -17
  52. package/src/activity/Activity.js +57 -42
  53. package/src/activity/ActivityExecution.js +43 -26
  54. package/src/definition/Definition.js +19 -13
  55. package/src/definition/DefinitionExecution.js +64 -54
  56. package/src/eventDefinitions/TimerEventDefinition.js +1 -1
  57. package/src/events/BoundaryEvent.js +10 -8
  58. package/src/process/Process.js +20 -15
  59. package/src/process/ProcessExecution.js +70 -40
  60. package/src/shared.js +0 -8
  61. package/src/tasks/LoopCharacteristics.js +2 -2
  62. package/src/tasks/ScriptTask.js +2 -2
  63. package/src/tasks/SubProcess.js +31 -32
  64. package/types/types.d.ts +1 -1
@@ -17,7 +17,7 @@ function ActivityExecution(activity, context) {
17
17
  this.context = context;
18
18
  this.id = activity.id;
19
19
  this.broker = activity.broker;
20
- this[kPostponed] = [];
20
+ this[kPostponed] = new Set();
21
21
  this[kCompleted] = false;
22
22
  this[kExecuteQ] = this.broker.assertQueue('execute-q', {
23
23
  durable: true,
@@ -44,7 +44,7 @@ ActivityExecution.prototype.execute = function execute(executeMessage) {
44
44
  isRootScope: true
45
45
  });
46
46
  if (executeMessage.fields.redelivered) {
47
- this[kPostponed].splice(0);
47
+ this[kPostponed].clear();
48
48
  this._debug('resume execution');
49
49
  if (!this.source) this.source = new this.activity.Behaviour(this.activity, this.context);
50
50
  this.activate();
@@ -102,11 +102,12 @@ ActivityExecution.prototype.getApi = function getApi(apiMessage) {
102
102
  }
103
103
  const api = (0, _Api.ActivityApi)(self.broker, apiMessage);
104
104
  api.getExecuting = function getExecuting() {
105
- return self[kPostponed].reduce((result, msg) => {
106
- if (msg.content.executionId === apiMessage.content.executionId) return result;
105
+ const result = [];
106
+ for (const msg of self[kPostponed]) {
107
+ if (msg.content.executionId === apiMessage.content.executionId) continue;
107
108
  result.push(self.getApi(msg));
108
- return result;
109
- }, []);
109
+ }
110
+ return result;
110
111
  };
111
112
  return api;
112
113
  };
@@ -115,7 +116,10 @@ ActivityExecution.prototype.passthrough = function passthrough(executeMessage) {
115
116
  return this._sourceExecute(executeMessage);
116
117
  };
117
118
  ActivityExecution.prototype.getPostponed = function getPostponed() {
118
- let apis = this[kPostponed].map(msg => this.getApi(msg));
119
+ let apis = [];
120
+ for (const msg of this[kPostponed]) {
121
+ apis.push(this.getApi(msg));
122
+ }
119
123
  if (!this.activity.isSubProcess || !this.source) return apis;
120
124
  apis = apis.concat(this.source.getPostponed());
121
125
  return apis;
@@ -132,7 +136,7 @@ ActivityExecution.prototype.getState = function getState() {
132
136
  };
133
137
  };
134
138
  ActivityExecution.prototype.recover = function recover(state) {
135
- this[kPostponed].splice(0);
139
+ this[kPostponed].clear();
136
140
  if (!state) return this;
137
141
  if ('completed' in state) this[kCompleted] = state.completed;
138
142
  const source = this.source = new this.activity.Behaviour(this.activity, this.context);
@@ -166,7 +170,7 @@ ActivityExecution.prototype._onExecuteMessage = function onExecuteMessage(routin
166
170
  switch (routingKey) {
167
171
  case 'execute.resume.execution':
168
172
  {
169
- if (!this[kPostponed].length) return this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content));
173
+ if (!this[kPostponed].size) return this.broker.publish('execution', 'execute.start', (0, _messageHelper.cloneContent)(this[kExecuteMessage].content));
170
174
  break;
171
175
  }
172
176
  case 'execute.cancel':
@@ -214,19 +218,23 @@ ActivityExecution.prototype._onStateChangeMessage = function onStateChangeMessag
214
218
  executionId
215
219
  } = message.content;
216
220
  const postponed = this[kPostponed];
217
- const idx = postponed.findIndex(msg => msg.content.executionId === executionId);
218
221
  let previousMsg;
219
- if (idx > -1) {
222
+ for (const msg of postponed) {
223
+ if (msg.content.executionId === executionId) previousMsg = msg;
224
+ }
225
+ if (previousMsg) {
220
226
  if (ignoreIfExecuting) {
221
227
  message.ack();
222
228
  return false;
223
229
  }
224
- previousMsg = postponed.splice(idx, 1, message)[0];
230
+ postponed.delete(previousMsg);
231
+ postponed.add(message);
225
232
  previousMsg.ack();
226
233
  return true;
234
+ } else {
235
+ postponed.add(message);
236
+ return true;
227
237
  }
228
- postponed.push(message);
229
- return true;
230
238
  };
231
239
  ActivityExecution.prototype._onExecutionCompleted = function onExecutionCompleted(message) {
232
240
  const postponedMsg = this._ackPostponed(message);
@@ -240,8 +248,11 @@ ActivityExecution.prototype._onExecutionCompleted = function onExecutionComplete
240
248
  if (!isRootScope) {
241
249
  this._debug('completed sub execution');
242
250
  if (!keep) message.ack();
243
- if (postponed.length === 1 && postponed[0].content.isRootScope && !postponed[0].content.preventComplete) {
244
- return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(postponed[0].content));
251
+ if (postponed.size === 1) {
252
+ const onlyMessage = postponed.values().next().value;
253
+ if (onlyMessage.content.isRootScope && !onlyMessage.content.preventComplete) {
254
+ return this.broker.publish('execution', 'execute.completed', (0, _messageHelper.cloneContent)(onlyMessage.content));
255
+ }
245
256
  }
246
257
  return;
247
258
  }
@@ -250,7 +261,7 @@ ActivityExecution.prototype._onExecutionCompleted = function onExecutionComplete
250
261
  message.ack(true);
251
262
  this.deactivate();
252
263
  const subApis = this.getPostponed();
253
- postponed.splice(0);
264
+ postponed.clear();
254
265
  for (const api of subApis) api.discard();
255
266
  this._publishExecutionCompleted('completed', {
256
267
  ...postponedMsg.content,
@@ -268,17 +279,20 @@ ActivityExecution.prototype._onExecutionDiscarded = function onExecutionDiscarde
268
279
  const correlationId = message.properties.correlationId;
269
280
  if (!error && !isRootScope) {
270
281
  message.ack();
271
- if (postponed.length === 1 && postponed[0].content.isRootScope) {
272
- return this.broker.publish('execution', 'execute.discard', postponed[0].content, {
273
- correlationId
274
- });
282
+ if (postponed.size === 1) {
283
+ const onlyMessage = postponed.values().next().value;
284
+ if (onlyMessage.content.isRootScope) {
285
+ return this.broker.publish('execution', 'execute.discard', onlyMessage.content, {
286
+ correlationId
287
+ });
288
+ }
275
289
  }
276
290
  return;
277
291
  }
278
292
  message.ack(true);
279
293
  this.deactivate();
280
294
  const subApis = this.getPostponed();
281
- postponed.splice(0);
295
+ postponed.clear();
282
296
  for (const api of subApis) api.discard();
283
297
  this._publishExecutionCompleted(discardType, (0, _messageHelper.cloneContent)(message.content), correlationId);
284
298
  };
@@ -297,13 +311,13 @@ ActivityExecution.prototype._ackPostponed = function ackPostponed(completeMessag
297
311
  executionId: eid
298
312
  } = completeMessage.content;
299
313
  const postponed = this[kPostponed];
300
- const idx = postponed.findIndex(({
301
- content: c
302
- }) => c.executionId === eid);
303
- if (idx === -1) return;
304
- const [msg] = postponed.splice(idx, 1);
305
- msg.ack();
306
- return msg;
314
+ for (const msg of postponed) {
315
+ if (msg.content.executionId === eid) {
316
+ postponed.delete(msg);
317
+ msg.ack();
318
+ return msg;
319
+ }
320
+ }
307
321
  };
308
322
  ActivityExecution.prototype._onParentApiMessage = function onParentApiMessage(routingKey, message) {
309
323
  switch (message.properties.type) {
@@ -11,7 +11,7 @@ var _EventBroker = require("../EventBroker.js");
11
11
  var _shared = require("../shared.js");
12
12
  var _Errors = require("../error/Errors.js");
13
13
  var _messageHelper = require("../messageHelper.js");
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
15
  const kConsuming = Symbol.for('consuming');
16
16
  const kCounters = Symbol.for('counters');
17
17
  const kExec = Symbol.for('execution');
@@ -45,7 +45,7 @@ function Definition(context, options) {
45
45
  discarded: 0
46
46
  };
47
47
  this[kStopped] = false;
48
- this[kExec] = {};
48
+ this[kExec] = new Map();
49
49
  const onBrokerReturn = this._onBrokerReturnFn.bind(this);
50
50
  this[kMessageHandlers] = {
51
51
  onBrokerReturn,
@@ -79,12 +79,12 @@ Object.defineProperties(Definition.prototype, {
79
79
  },
80
80
  execution: {
81
81
  get() {
82
- return this[kExec].execution;
82
+ return this[kExec].get('execution');
83
83
  }
84
84
  },
85
85
  executionId: {
86
86
  get() {
87
- return this[kExec].executionId;
87
+ return this[kExec].get('executionId');
88
88
  }
89
89
  },
90
90
  isRunning: {
@@ -105,7 +105,8 @@ Object.defineProperties(Definition.prototype, {
105
105
  },
106
106
  activityStatus: {
107
107
  get() {
108
- return this[kExec].execution && this[kExec].execution.activityStatus || 'idle';
108
+ const execution = this[kExec].get('execution');
109
+ return execution && execution.activityStatus || 'idle';
109
110
  }
110
111
  }
111
112
  });
@@ -120,7 +121,8 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
120
121
  addConsumerCallbacks(this, callback);
121
122
  }
122
123
  const exec = this[kExec];
123
- exec.executionId = (0, _shared.getUniqueId)(this.id);
124
+ const executionId = (0, _shared.getUniqueId)(this.id);
125
+ exec.set('executionId', executionId);
124
126
  const content = this._createMessage({
125
127
  ...runOptions
126
128
  });
@@ -128,7 +130,7 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
128
130
  broker.publish('run', 'run.enter', content);
129
131
  broker.publish('run', 'run.start', (0, _messageHelper.cloneContent)(content));
130
132
  broker.publish('run', 'run.execute', (0, _messageHelper.cloneContent)(content));
131
- this.logger.debug(`<${this.executionId} (${this.id})> run`);
133
+ this.logger.debug(`<${executionId} (${this.id})> run`);
132
134
  this._activateRunConsumers();
133
135
  return this;
134
136
  };
@@ -167,7 +169,7 @@ Definition.prototype.recover = function recover(state) {
167
169
  this[kStopped] = !!state.stopped;
168
170
  this[kStatus] = state.status;
169
171
  const exec = this[kExec];
170
- exec.executionId = state.executionId;
172
+ exec.set('executionId', state.executionId);
171
173
  if (state.counters) {
172
174
  this[kCounters] = {
173
175
  ...this[kCounters],
@@ -176,7 +178,7 @@ Definition.prototype.recover = function recover(state) {
176
178
  }
177
179
  this.environment.recover(state.environment);
178
180
  if (state.execution) {
179
- exec.execution = new _DefinitionExecution.default(this, this.context).recover(state.execution);
181
+ exec.set('execution', new _DefinitionExecution.default(this, this.context).recover(state.execution));
180
182
  }
181
183
  this.broker.recover(state.broker);
182
184
  return this;
@@ -337,7 +339,7 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
337
339
  this.logger.debug(`<${this.executionId} (${this.id})> enter`);
338
340
  this[kStatus] = 'entered';
339
341
  if (fields.redelivered) break;
340
- exec.execution = undefined;
342
+ exec.delete('execution');
341
343
  this._publishEvent('enter', content);
342
344
  break;
343
345
  }
@@ -352,7 +354,8 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
352
354
  {
353
355
  this[kStatus] = 'executing';
354
356
  const executeMessage = (0, _messageHelper.cloneMessage)(message);
355
- if (fields.redelivered && !exec.execution) {
357
+ let execution = exec.get('execution');
358
+ if (fields.redelivered && !execution) {
356
359
  executeMessage.fields.redelivered = undefined;
357
360
  }
358
361
  this[kExecuteMessage] = message;
@@ -360,11 +363,14 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
360
363
  exclusive: true,
361
364
  consumerTag: '_definition-execution'
362
365
  });
363
- exec.execution = exec.execution || new _DefinitionExecution.default(this, this.context);
366
+ if (!execution) {
367
+ execution = new _DefinitionExecution.default(this, this.context);
368
+ exec.set('execution', execution);
369
+ }
364
370
  if (executeMessage.fields.redelivered) {
365
371
  this._publishEvent('resume', content);
366
372
  }
367
- return exec.execution.execute(executeMessage);
373
+ return execution.execute(executeMessage);
368
374
  }
369
375
  case 'run.end':
370
376
  {
@@ -475,7 +481,7 @@ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
475
481
  }
476
482
  };
477
483
  Definition.prototype._reset = function reset() {
478
- this[kExec].executionId = undefined;
484
+ this[kExec].delete('executionId');
479
485
  this._deactivateRunConsumers();
480
486
  this.broker.purgeQueue('run-q');
481
487
  this.broker.purgeQueue('execution-q');
@@ -8,7 +8,7 @@ var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js")
8
8
  var _Api = require("../Api.js");
9
9
  var _shared = require("../shared.js");
10
10
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  const kActivated = Symbol.for('activated');
13
13
  const kProcessesQ = Symbol.for('processesQ');
14
14
  const kCompleted = Symbol.for('completed');
@@ -27,20 +27,20 @@ function DefinitionExecution(definition, context) {
27
27
  const environment = this.environment = definition.environment;
28
28
  this.context = context;
29
29
  const processes = context.getProcesses();
30
- const ids = [];
31
- const executable = [];
30
+ const ids = new Set();
31
+ const executable = new Set();
32
32
  for (const bp of processes) {
33
33
  bp.environment.assignVariables(environment.variables);
34
34
  bp.environment.assignSettings(environment.settings);
35
- ids.push(bp.id);
36
- if (bp.isExecutable) executable.push(bp);
35
+ ids.add(bp.id);
36
+ if (bp.isExecutable) executable.add(bp);
37
37
  }
38
38
  this[kProcesses] = {
39
39
  processes,
40
- running: [],
41
40
  ids,
42
41
  executable,
43
- postponed: []
42
+ running: new Set(),
43
+ postponed: new Set()
44
44
  };
45
45
  broker.assertExchange('execution', 'topic', {
46
46
  autoDelete: false,
@@ -80,12 +80,12 @@ Object.defineProperties(DefinitionExecution.prototype, {
80
80
  },
81
81
  processes: {
82
82
  get() {
83
- return this[kProcesses].running;
83
+ return [...this[kProcesses].running];
84
84
  }
85
85
  },
86
86
  postponedCount: {
87
87
  get() {
88
- return this[kProcesses].postponed.length;
88
+ return this[kProcesses].postponed.size;
89
89
  }
90
90
  },
91
91
  isRunning: {
@@ -97,7 +97,7 @@ Object.defineProperties(DefinitionExecution.prototype, {
97
97
  get() {
98
98
  let status = 'idle';
99
99
  const running = this[kProcesses].running;
100
- if (!running || !running.length) return status;
100
+ if (!running.size) return status;
101
101
  for (const bp of running) {
102
102
  const bpStatus = bp.activityStatus;
103
103
  switch (bp.activityStatus) {
@@ -141,12 +141,14 @@ DefinitionExecution.prototype.execute = function execute(executeMessage) {
141
141
  if (content.processId) {
142
142
  const startWithProcess = this.getProcessById(content.processId);
143
143
  if (startWithProcess) {
144
- executable.splice(0);
145
- executable.push(startWithProcess);
144
+ executable.clear();
145
+ executable.add(startWithProcess);
146
146
  }
147
147
  }
148
148
  this._debug('execute definition');
149
- running.push(...executable);
149
+ for (const bp of executable) {
150
+ running.add(bp);
151
+ }
150
152
  this._activate(executable);
151
153
  this._start();
152
154
  return true;
@@ -159,7 +161,7 @@ DefinitionExecution.prototype.resume = function resume() {
159
161
  postponed
160
162
  } = this[kProcesses];
161
163
  this._activate(running);
162
- postponed.splice(0);
164
+ postponed.clear();
163
165
  this[kProcessesQ].consume(this[kMessageHandlers].onProcessMessage, {
164
166
  prefetch: 1000,
165
167
  consumerTag: `_definition-activity-${this.executionId}`
@@ -175,20 +177,20 @@ DefinitionExecution.prototype.recover = function recover(state) {
175
177
  this[kStatus] = state.status;
176
178
  this._debug(`recover ${this[kStatus]} definition execution`);
177
179
  const running = this[kProcesses].running;
178
- running.splice(0);
179
- const ids = [];
180
+ running.clear();
181
+ const ids = new Set();
180
182
  for (const bpState of state.processes) {
181
183
  const bpid = bpState.id;
182
184
  let bp;
183
- if (ids.indexOf(bpid) > -1) {
185
+ if (ids.has(bpid)) {
184
186
  bp = this.context.getNewProcessById(bpid);
185
187
  } else {
186
188
  bp = this.getProcessById(bpid);
187
189
  }
188
190
  if (!bp) continue;
189
- ids.push(bpid);
191
+ ids.add(bpid);
190
192
  bp.recover(bpState);
191
- running.push(bp);
193
+ running.add(bp);
192
194
  }
193
195
  return this;
194
196
  };
@@ -200,7 +202,7 @@ DefinitionExecution.prototype.getProcesses = function getProcesses() {
200
202
  running,
201
203
  processes
202
204
  } = this[kProcesses];
203
- const result = running.slice();
205
+ const result = [...running];
204
206
  for (const bp of processes) {
205
207
  if (!result.find(runningBp => bp.id === runningBp.id)) result.push(bp);
206
208
  }
@@ -213,23 +215,27 @@ DefinitionExecution.prototype.getProcessesById = function getProcessesById(proce
213
215
  return this.getProcesses().filter(bp => bp.id === processId);
214
216
  };
215
217
  DefinitionExecution.prototype.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
216
- const running = this[kProcesses].running;
217
- return running.find(bp => bp.executionId === processExecutionId);
218
+ for (const bp of this[kProcesses].running) {
219
+ if (bp.executionId === processExecutionId) return bp;
220
+ }
218
221
  };
219
222
  DefinitionExecution.prototype.getRunningProcesses = function getRunningProcesses() {
220
- const running = this[kProcesses].running;
221
- return running.filter(bp => bp.executionId);
223
+ return [...this[kProcesses].running].filter(bp => bp.executionId);
222
224
  };
223
225
  DefinitionExecution.prototype.getExecutableProcesses = function getExecutableProcesses() {
224
- return this[kProcesses].executable.slice();
226
+ return [...this[kProcesses].executable];
225
227
  };
226
228
  DefinitionExecution.prototype.getState = function getState() {
229
+ const processes = [];
230
+ for (const bp of this[kProcesses].running) {
231
+ processes.push(bp.getState());
232
+ }
227
233
  return {
228
234
  executionId: this.executionId,
229
235
  stopped: this[kStopped],
230
236
  completed: this[kCompleted],
231
237
  status: this[kStatus],
232
- processes: this[kProcesses].running.map(bp => bp.getState())
238
+ processes
233
239
  };
234
240
  };
235
241
  DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
@@ -244,20 +250,21 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
244
250
  const postponed = this[kProcesses].postponed;
245
251
  const self = this;
246
252
  api.getExecuting = function getExecuting() {
247
- return postponed.reduce((result, msg) => {
253
+ const apis = [];
254
+ for (const msg of postponed) {
248
255
  const bpApi = self._getProcessApi(msg);
249
- if (bpApi) result.push(bpApi);
250
- return result;
251
- }, []);
256
+ if (bpApi) apis.push(bpApi);
257
+ }
258
+ return apis;
252
259
  };
253
260
  return api;
254
261
  };
255
262
  DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
256
- const running = this[kProcesses].running;
257
- return running.reduce((result, p) => {
258
- result = result.concat(p.getPostponed(...args));
259
- return result;
260
- }, []);
263
+ let result = [];
264
+ for (const bp of this[kProcesses].running) {
265
+ result = result.concat(bp.getPostponed(...args));
266
+ }
267
+ return result;
261
268
  };
262
269
  DefinitionExecution.prototype._start = function start() {
263
270
  const {
@@ -265,10 +272,10 @@ DefinitionExecution.prototype._start = function start() {
265
272
  executable,
266
273
  postponed
267
274
  } = this[kProcesses];
268
- if (!ids.length) {
275
+ if (!ids.size) {
269
276
  return this._complete('completed');
270
277
  }
271
- if (!executable.length) {
278
+ if (!executable.size) {
272
279
  return this._complete('error', {
273
280
  error: new Error('No executable process')
274
281
  });
@@ -276,7 +283,7 @@ DefinitionExecution.prototype._start = function start() {
276
283
  this[kStatus] = 'start';
277
284
  for (const bp of executable) bp.init();
278
285
  for (const bp of executable) bp.run();
279
- postponed.splice(0);
286
+ postponed.clear();
280
287
  this[kProcessesQ].assertConsumer(this[kMessageHandlers].onProcessMessage, {
281
288
  prefetch: 1000,
282
289
  consumerTag: `_definition-activity-${this.executionId}`
@@ -331,7 +338,7 @@ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey,
331
338
  const message = (0, _messageHelper.cloneMessage)(originalMessage);
332
339
  const content = message.content;
333
340
  const parent = content.parent = content.parent || {};
334
- const isDirectChild = this[kProcesses].ids.indexOf(content.id) > -1;
341
+ const isDirectChild = this[kProcesses].ids.has(content.id);
335
342
  if (isDirectChild) {
336
343
  parent.executionId = this.executionId;
337
344
  } else {
@@ -424,7 +431,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
424
431
  type: 'error'
425
432
  });
426
433
  } else {
427
- for (const bp of this[kProcesses].running.slice()) {
434
+ for (const bp of new Set(this[kProcesses].running)) {
428
435
  if (bp.id !== childId) bp.stop();
429
436
  }
430
437
  Object.assign(this.environment.output, content.output);
@@ -439,12 +446,15 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
439
446
  DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
440
447
  let previousMsg;
441
448
  const postponed = this[kProcesses].postponed;
442
- const idx = postponed.findIndex(msg => msg.content.executionId === message.content.executionId);
443
- if (idx > -1) {
444
- previousMsg = postponed.splice(idx, 1)[0];
449
+ for (const msg of postponed) {
450
+ if (msg.content.executionId === message.content.executionId) {
451
+ previousMsg = msg;
452
+ postponed.delete(msg);
453
+ break;
454
+ }
445
455
  }
446
456
  if (previousMsg) previousMsg.ack();
447
- if (postponeMessage) postponed.push(message);
457
+ if (postponeMessage) postponed.add(message);
448
458
  };
449
459
  DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(message) {
450
460
  this._stateChangeMessage(message, false);
@@ -467,9 +477,9 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
467
477
  };
468
478
  DefinitionExecution.prototype._onStopped = function onStopped(message) {
469
479
  const running = this[kProcesses].running;
470
- this._debug(`stop definition execution (stop process executions ${running.length})`);
480
+ this._debug(`stop definition execution (stop process executions ${running.size})`);
471
481
  this[kProcessesQ].close();
472
- for (const bp of running.slice()) bp.stop();
482
+ for (const bp of new Set(running)) bp.stop();
473
483
  this._deactivate();
474
484
  this[kStopped] = true;
475
485
  return this.broker.publish('execution', `execution.stopped.${this.executionId}`, (0, _messageHelper.cloneContent)(this[kExecuteMessage].content, {
@@ -490,7 +500,7 @@ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey,
490
500
  });
491
501
  }
492
502
  if (delegate) {
493
- for (const bp of this[kProcesses].running.slice()) {
503
+ for (const bp of new Set(this[kProcesses].running)) {
494
504
  bp.broker.publish('api', routingKey, (0, _messageHelper.cloneContent)(message.content), message.properties);
495
505
  }
496
506
  }
@@ -515,7 +525,7 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
515
525
  if (!bp.executionId) {
516
526
  this._debug(`start <${bp.id}> by <${reference.referenceId}> (${reference.referenceType})`);
517
527
  this._activateProcess(bp);
518
- running.push(bp);
528
+ running.add(bp);
519
529
  bp.init();
520
530
  bp.run();
521
531
  if (reference.referenceType === 'message') return;
@@ -524,7 +534,7 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
524
534
  this._debug(`start new <${bp.id}> by <${reference.referenceId}> (${reference.referenceType})`);
525
535
  const targetProcess = this.context.getNewProcessById(bp.id);
526
536
  this._activateProcess(targetProcess);
527
- running.push(targetProcess);
537
+ running.add(targetProcess);
528
538
  targetProcess.init();
529
539
  targetProcess.run();
530
540
  if (reference.referenceType === 'message') return;
@@ -551,7 +561,7 @@ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(ro
551
561
  if (found) return;
552
562
  targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
553
563
  this._activateProcess(targetProcess);
554
- this[kProcesses].running.push(targetProcess);
564
+ this[kProcesses].running.add(targetProcess);
555
565
  targetProcess.init();
556
566
  targetProcess.run();
557
567
  targetProcess.sendMessage(message);
@@ -583,7 +593,7 @@ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingK
583
593
  if (!targetProcess) return;
584
594
  this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
585
595
  this._activateProcess(targetProcess);
586
- this[kProcesses].running.push(targetProcess);
596
+ this[kProcesses].running.add(targetProcess);
587
597
  targetProcess.init(bpExecutionId);
588
598
  targetProcess.run({
589
599
  inbound: [(0, _messageHelper.cloneContent)(content)]
@@ -639,10 +649,9 @@ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(ro
639
649
  });
640
650
  };
641
651
  DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
642
- const running = this[kProcesses].running;
643
- const idx = running.findIndex(p => p.executionId === processExecutionId);
644
- if (idx === -1) return;
645
- return running.splice(idx, 1)[0];
652
+ const bp = this.getProcessByExecutionId(processExecutionId);
653
+ if (bp) this[kProcesses].running.delete(bp);
654
+ return bp;
646
655
  };
647
656
  DefinitionExecution.prototype._complete = function complete(completionType, content, options) {
648
657
  this._deactivate();
@@ -7,7 +7,7 @@ exports.default = EscalationEventDefinition;
7
7
  var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
8
8
  var _shared = require("../shared.js");
9
9
  var _messageHelper = require("../messageHelper.js");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  const kCompleted = Symbol.for('completed');
12
12
  const kMessageQ = Symbol.for('messageQ');
13
13
  const kExecuteMessage = Symbol.for('executeMessage');
@@ -7,7 +7,7 @@ exports.default = LinkEventDefinition;
7
7
  var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
8
8
  var _shared = require("../shared.js");
9
9
  var _messageHelper = require("../messageHelper.js");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  const kCompleted = Symbol.for('completed');
12
12
  const kMessageQ = Symbol.for('messageQ');
13
13
  const kExecuteMessage = Symbol.for('executeMessage');
@@ -7,7 +7,7 @@ exports.default = MessageEventDefinition;
7
7
  var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
8
8
  var _shared = require("../shared.js");
9
9
  var _messageHelper = require("../messageHelper.js");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  const kCompleted = Symbol.for('completed');
12
12
  const kMessageQ = Symbol.for('messageQ');
13
13
  const kExecuteMessage = Symbol.for('executeMessage');
@@ -7,7 +7,7 @@ exports.default = SignalEventDefinition;
7
7
  var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
8
8
  var _shared = require("../shared.js");
9
9
  var _messageHelper = require("../messageHelper.js");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  const kCompleted = Symbol.for('completed');
12
12
  const kMessageQ = Symbol.for('messageQ');
13
13
  const kExecuteMessage = Symbol.for('executeMessage');
@@ -10,7 +10,7 @@ var _Errors = require("../error/Errors.js");
10
10
  const kStopped = Symbol.for('stopped');
11
11
  const kTimerContent = Symbol.for('timerContent');
12
12
  const kTimer = Symbol.for('timer');
13
- const timerTypes = ['timeDuration', 'timeDate', 'timeCycle'];
13
+ const timerTypes = new Set(['timeDuration', 'timeDate', 'timeCycle']);
14
14
  function TimerEventDefinition(activity, eventDefinition) {
15
15
  const type = this.type = eventDefinition.type || 'TimerEventDefinition';
16
16
  this.activity = activity;