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
@@ -9,7 +9,7 @@ var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _EventDefinitionExecution = _interopRequireDefault(require("../eventDefinitions/EventDefinitionExecution.js"));
10
10
  var _messageHelper = require("../messageHelper.js");
11
11
  var _shared = require("../shared.js");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  const kAttachedTags = Symbol.for('attachedConsumers');
14
14
  const kCompleteContent = Symbol.for('completeContent');
15
15
  const kExecuteMessage = Symbol.for('executeMessage');
@@ -26,8 +26,8 @@ function BoundaryEventBehaviour(activity) {
26
26
  this.environment = activity.environment;
27
27
  this.broker = activity.broker;
28
28
  this[kExecution] = activity.eventDefinitions && new _EventDefinitionExecution.default(activity, activity.eventDefinitions, 'execute.bound.completed');
29
- this[kShovels] = [];
30
- this[kAttachedTags] = [];
29
+ this[kShovels] = new Set();
30
+ this[kAttachedTags] = new Set();
31
31
  }
32
32
  Object.defineProperties(BoundaryEventBehaviour.prototype, {
33
33
  executionId: {
@@ -62,7 +62,7 @@ BoundaryEventBehaviour.prototype.execute = function execute(executeMessage) {
62
62
  consumerTag,
63
63
  priority: 300
64
64
  });
65
- this[kAttachedTags].push(consumerTag);
65
+ this[kAttachedTags].add(consumerTag);
66
66
  broker.subscribeOnce('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
67
67
  consumerTag: `_api-${executionId}`
68
68
  });
@@ -117,7 +117,7 @@ BoundaryEventBehaviour.prototype._onCompleted = function onCompleted(_, {
117
117
  this.activity.logger.debug(`<${executionId} (${this.id})> cancel ${attachedTo.status} activity <${attachedToContent.executionId} (${attachedToContent.id})>`);
118
118
  if (content.isRecovered && !attachedTo.isRunning) {
119
119
  const attachedExecuteTag = `_on-attached-execute-${executionId}`;
120
- this[kAttachedTags].push(attachedExecuteTag);
120
+ this[kAttachedTags].add(attachedExecuteTag);
121
121
  attachedTo.broker.subscribeOnce('execution', '#', () => {
122
122
  attachedTo.getApi({
123
123
  content: attachedToContent
@@ -151,7 +151,7 @@ BoundaryEventBehaviour.prototype._onExpectMessage = function onExpectMessage(_,
151
151
  } = content;
152
152
  const attachedTo = this.attachedTo;
153
153
  const errorConsumerTag = `_bound-error-listener-${executionId}`;
154
- this[kAttachedTags].push(errorConsumerTag);
154
+ this[kAttachedTags].add(errorConsumerTag);
155
155
  attachedTo.broker.subscribeTmp('event', pattern, (__, message) => {
156
156
  if (message.content.id !== attachedTo.id) return;
157
157
  this.broker.publish(exchange, expectRoutingKey, (0, _messageHelper.cloneContent)(message.content, {
@@ -183,7 +183,7 @@ BoundaryEventBehaviour.prototype._onDetachMessage = function onDetachMessage(_,
183
183
  sourcePattern
184
184
  } = content;
185
185
  const shovelName = `_detached-${(0, _shared.brokerSafeId)(id)}_${detachId}`;
186
- this[kShovels].push(shovelName);
186
+ this[kShovels].add(shovelName);
187
187
  const broker = this.broker;
188
188
  attachedTo.broker.createShovel(shovelName, {
189
189
  exchange: sourceExchange,
@@ -231,8 +231,10 @@ BoundaryEventBehaviour.prototype._stop = function stop(detach) {
231
231
  const attachedTo = this.attachedTo,
232
232
  broker = this.broker,
233
233
  executionId = this.executionId;
234
- for (const tag of this[kAttachedTags].splice(0)) attachedTo.broker.cancel(tag);
235
- for (const shovelName of this[kShovels].splice(0)) attachedTo.broker.closeShovel(shovelName);
234
+ for (const tag of this[kAttachedTags]) attachedTo.broker.cancel(tag);
235
+ this[kAttachedTags].clear();
236
+ for (const shovelName of this[kShovels]) attachedTo.broker.closeShovel(shovelName);
237
+ this[kShovels].clear();
236
238
  broker.cancel('_execution-tag');
237
239
  broker.cancel(`_execution-completed-${executionId}`);
238
240
  if (detach) return;
@@ -8,7 +8,7 @@ exports.default = EndEvent;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _EventDefinitionExecution = _interopRequireDefault(require("../eventDefinitions/EventDefinitionExecution.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 kExecution = Symbol.for('execution');
13
13
  function EndEvent(activityDef, context) {
14
14
  return new _Activity.default(EndEventBehaviour, {
@@ -8,7 +8,7 @@ exports.default = IntermediateCatchEvent;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _EventDefinitionExecution = _interopRequireDefault(require("../eventDefinitions/EventDefinitionExecution.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 kExecution = Symbol.for('execution');
13
13
  function IntermediateCatchEvent(activityDef, context) {
14
14
  return new _Activity.default(IntermediateCatchEventBehaviour, activityDef, context);
@@ -8,7 +8,7 @@ exports.default = IntermediateThrowEvent;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _EventDefinitionExecution = _interopRequireDefault(require("../eventDefinitions/EventDefinitionExecution.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 kExecution = Symbol.for('execution');
13
13
  function IntermediateThrowEvent(activityDef, context) {
14
14
  return new _Activity.default(IntermediateThrowEventBehaviour, {
@@ -8,7 +8,7 @@ exports.default = StartEvent;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _EventDefinitionExecution = _interopRequireDefault(require("../eventDefinitions/EventDefinitionExecution.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 kExecuteMessage = Symbol.for('executeMessage');
13
13
  const kExecution = Symbol.for('execution');
14
14
  function StartEvent(activityDef, context) {
@@ -9,7 +9,7 @@ var _messageHelper = require("../messageHelper.js");
9
9
  var _shared = require("../shared.js");
10
10
  var _EventBroker = require("../EventBroker.js");
11
11
  var _Api = require("../Api.js");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  const kCounters = Symbol.for('counters');
14
14
  var _default = exports.default = SequenceFlow;
15
15
  function SequenceFlow(flowDef, {
@@ -7,7 +7,7 @@ exports.EventBasedGatewayBehaviour = EventBasedGatewayBehaviour;
7
7
  exports.default = EventBasedGateway;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.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 kTargets = Symbol.for('targets');
13
13
  function EventBasedGateway(activityDef, context) {
@@ -7,7 +7,7 @@ exports.ExclusiveGatewayBehaviour = ExclusiveGatewayBehaviour;
7
7
  exports.default = ExclusiveGateway;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.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
  function ExclusiveGateway(activityDef, context) {
12
12
  return new _Activity.default(ExclusiveGatewayBehaviour, activityDef, context);
13
13
  }
@@ -7,7 +7,7 @@ exports.InclusiveGatewayBehaviour = InclusiveGatewayBehaviour;
7
7
  exports.default = InclusiveGateway;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.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
  function InclusiveGateway(activityDef, context) {
12
12
  return new _Activity.default(InclusiveGatewayBehaviour, activityDef, context);
13
13
  }
@@ -7,7 +7,7 @@ exports.ParallelGatewayBehaviour = ParallelGatewayBehaviour;
7
7
  exports.default = ParallelGateway;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.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
  function ParallelGateway(activityDef, context) {
12
12
  return new _Activity.default(ParallelGatewayBehaviour, {
13
13
  ...activityDef,
package/dist/index.js CHANGED
@@ -408,4 +408,4 @@ var _TimerEventDefinition = _interopRequireDefault(require("./eventDefinitions/T
408
408
  var _Transaction = _interopRequireDefault(require("./tasks/Transaction.js"));
409
409
  var _Timers = require("./Timers.js");
410
410
  var _Errors = require("./error/Errors.js");
411
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
411
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = IoSpecification;
7
7
  var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
8
8
  var _shared = require("../shared.js");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
10
  const kConsuming = Symbol.for('consuming');
11
11
  function IoSpecification(activity, ioSpecificationDef, context) {
12
12
  const {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = Properties;
7
7
  var _getPropertyValue = _interopRequireDefault(require("../getPropertyValue.js"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  const kProperties = Symbol.for('properties');
10
10
  const kConsuming = Symbol.for('consuming');
11
11
  function Properties(activity, propertiesDef, context) {
@@ -11,7 +11,7 @@ var _Api = require("../Api.js");
11
11
  var _EventBroker = require("../EventBroker.js");
12
12
  var _messageHelper = require("../messageHelper.js");
13
13
  var _Errors = require("../error/Errors.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');
@@ -47,7 +47,7 @@ function Process(processDef, context) {
47
47
  discarded: 0
48
48
  };
49
49
  this[kConsuming] = false;
50
- this[kExec] = {};
50
+ this[kExec] = new Map();
51
51
  this[kStatus] = undefined;
52
52
  this[kStopped] = false;
53
53
  const {
@@ -103,16 +103,13 @@ Object.defineProperties(Process.prototype, {
103
103
  },
104
104
  executionId: {
105
105
  get() {
106
- const {
107
- executionId,
108
- initExecutionId
109
- } = this[kExec];
110
- return executionId || initExecutionId;
106
+ const exec = this[kExec];
107
+ return exec.get('executionId') || exec.get('initExecutionId');
111
108
  }
112
109
  },
113
110
  execution: {
114
111
  get() {
115
- return this[kExec].execution;
112
+ return this[kExec].get('execution');
116
113
  }
117
114
  },
118
115
  status: {
@@ -122,13 +119,14 @@ Object.defineProperties(Process.prototype, {
122
119
  },
123
120
  activityStatus: {
124
121
  get() {
125
- return this[kExec].execution && this[kExec].execution.activityStatus || 'idle';
122
+ const execution = this[kExec].get('execution');
123
+ return execution && execution.activityStatus || 'idle';
126
124
  }
127
125
  }
128
126
  });
129
127
  Process.prototype.init = function init(useAsExecutionId) {
130
- const exec = this[kExec];
131
- const initExecutionId = exec.initExecutionId = useAsExecutionId || (0, _shared.getUniqueId)(this.id);
128
+ const initExecutionId = useAsExecutionId || (0, _shared.getUniqueId)(this.id);
129
+ this[kExec].set('initExecutionId', initExecutionId);
132
130
  this._debug(`initialized with executionId <${initExecutionId}>`);
133
131
  this._publishEvent('init', this._createMessage({
134
132
  executionId: initExecutionId
@@ -137,8 +135,9 @@ Process.prototype.init = function init(useAsExecutionId) {
137
135
  Process.prototype.run = function run(runContent) {
138
136
  if (this.isRunning) throw new Error(`process <${this.id}> is already running`);
139
137
  const exec = this[kExec];
140
- const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(this.id);
141
- exec.initExecutionId = undefined;
138
+ const executionId = exec.get('initExecutionId') || (0, _shared.getUniqueId)(this.id);
139
+ exec.delete('initExecutionId');
140
+ exec.set('executionId', executionId);
142
141
  const content = this._createMessage({
143
142
  ...runContent,
144
143
  executionId
@@ -179,14 +178,14 @@ Process.prototype.recover = function recover(state) {
179
178
  this[kStopped] = !!state.stopped;
180
179
  this[kStatus] = state.status;
181
180
  const exec = this[kExec];
182
- exec.executionId = state.executionId;
181
+ exec.set('executionId', state.executionId);
183
182
  this[kCounters] = {
184
183
  ...this[kCounters],
185
184
  ...state.counters
186
185
  };
187
186
  this.environment.recover(state.environment);
188
187
  if (state.execution) {
189
- exec.execution = new _ProcessExecution.default(this, this.context).recover(state.execution);
188
+ exec.set('execution', new _ProcessExecution.default(this, this.context).recover(state.execution));
190
189
  }
191
190
  this.broker.recover(state.broker);
192
191
  return this;
@@ -246,7 +245,6 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
246
245
  if (routingKey === 'run.resume') {
247
246
  return this._onResumeMessage(message);
248
247
  }
249
- const exec = this[kExec];
250
248
  this[kStateMessage] = message;
251
249
  switch (routingKey) {
252
250
  case 'run.enter':
@@ -254,7 +252,7 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
254
252
  this._debug('enter');
255
253
  this[kStatus] = 'entered';
256
254
  if (fields.redelivered) break;
257
- exec.execution = undefined;
255
+ this[kExec].delete('execution');
258
256
  this._publishEvent('enter', content);
259
257
  break;
260
258
  }
@@ -267,9 +265,11 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
267
265
  }
268
266
  case 'run.execute':
269
267
  {
268
+ const exec = this[kExec];
270
269
  this[kStatus] = 'executing';
271
270
  const executeMessage = (0, _messageHelper.cloneMessage)(message);
272
- if (fields.redelivered && !exec.execution) {
271
+ let execution = exec.get('execution');
272
+ if (fields.redelivered && !execution) {
273
273
  executeMessage.fields.redelivered = undefined;
274
274
  }
275
275
  this[kExecuteMessage] = message;
@@ -277,7 +277,8 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
277
277
  exclusive: true,
278
278
  consumerTag: '_process-execution'
279
279
  });
280
- const execution = exec.execution = exec.execution || new _ProcessExecution.default(this, this.context);
280
+ execution = execution || new _ProcessExecution.default(this, this.context);
281
+ exec.set('execution', execution);
281
282
  return execution.execute(executeMessage);
282
283
  }
283
284
  case 'run.error':
@@ -36,15 +36,15 @@ function ProcessExecution(parentActivity, context) {
36
36
  this.environment = context.environment;
37
37
  this.context = context;
38
38
  this[kElements] = {
39
+ postponed: new Set(),
39
40
  children: context.getActivities(id),
40
41
  associations: context.getAssociations(id),
41
42
  flows: context.getSequenceFlows(id),
42
43
  outboundMessageFlows: context.getMessageFlows(id),
43
44
  startActivities: [],
44
45
  triggeredByEvent: [],
45
- detachedActivities: [],
46
- startSequences: {},
47
- postponed: []
46
+ detachedActivities: new Set(),
47
+ startSequences: {}
48
48
  };
49
49
  const exchangeName = this._exchangeName = isSubProcess ? 'subprocess-execution' : 'execution';
50
50
  broker.assertExchange(exchangeName, 'topic', {
@@ -82,7 +82,7 @@ Object.defineProperties(ProcessExecution.prototype, {
82
82
  },
83
83
  postponedCount: {
84
84
  get() {
85
- return this[kElements].postponed.length;
85
+ return this[kElements].postponed.size;
86
86
  }
87
87
  },
88
88
  isRunning: {
@@ -130,8 +130,8 @@ ProcessExecution.prototype.resume = function resume() {
130
130
  if (startActivities.length > 1) {
131
131
  for (const a of startActivities) a.shake();
132
132
  }
133
- postponed.splice(0);
134
- detachedActivities.splice(0);
133
+ postponed.clear();
134
+ detachedActivities.clear();
135
135
  this[kActivityQ].consume(this[kMessageHandlers].onChildMessage, {
136
136
  prefetch: 1000,
137
137
  consumerTag: `_process-activity-${this.executionId}`
@@ -140,7 +140,7 @@ ProcessExecution.prototype.resume = function resume() {
140
140
  const status = this.status;
141
141
  if (status === 'init') return this._start();
142
142
  const tracker = this[kTracker];
143
- for (const msg of postponed.slice()) {
143
+ for (const msg of new Set(postponed)) {
144
144
  const activity = this.getActivityById(msg.content.id);
145
145
  if (!activity) continue;
146
146
  if (msg.content.placeholder) continue;
@@ -153,7 +153,7 @@ ProcessExecution.prototype.resume = function resume() {
153
153
  activity.resume();
154
154
  }
155
155
  if (this[kCompleted]) return;
156
- if (!postponed.length && status === 'executing') return this._complete('completed');
156
+ if (!postponed.size && status === 'executing') return this._complete('completed');
157
157
  };
158
158
  ProcessExecution.prototype.getState = function getState() {
159
159
  const {
@@ -272,7 +272,7 @@ ProcessExecution.prototype.stop = function stop() {
272
272
  };
273
273
  ProcessExecution.prototype.getPostponed = function getPostponed(filterFn) {
274
274
  const result = [];
275
- for (const msg of this[kElements].postponed.slice()) {
275
+ for (const msg of this[kElements].postponed) {
276
276
  const api = this._getChildApi(msg);
277
277
  if (!api) continue;
278
278
  if (filterFn && !filterFn(api)) continue;
@@ -325,11 +325,12 @@ ProcessExecution.prototype.getApi = function getApi(message) {
325
325
  const postponed = this[kElements].postponed;
326
326
  const self = this;
327
327
  api.getExecuting = function getExecuting() {
328
- return postponed.reduce((result, msg) => {
328
+ const result = [];
329
+ for (const msg of postponed) {
329
330
  const childApi = self._getChildApi(msg);
330
331
  if (childApi) result.push(childApi);
331
- return result;
332
- }, []);
332
+ }
333
+ return result;
333
334
  };
334
335
  return api;
335
336
  };
@@ -354,8 +355,8 @@ ProcessExecution.prototype._start = function start() {
354
355
  for (const a of startActivities) a.init();
355
356
  this[kStatus] = 'executing';
356
357
  for (const a of startActivities) a.run();
357
- postponed.splice(0);
358
- detachedActivities.splice(0);
358
+ postponed.clear();
359
+ detachedActivities.clear();
359
360
  this[kActivityQ].assertConsumer(this[kMessageHandlers].onChildMessage, {
360
361
  prefetch: 1000,
361
362
  consumerTag: `_process-activity-${this.executionId}`
@@ -546,9 +547,13 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
546
547
  return this._onCancel(message);
547
548
  case 'activity.error.caught':
548
549
  {
549
- const prevMsg = this[kElements].postponed.find(msg => {
550
- return msg.content.executionId === content.executionId;
551
- });
550
+ let prevMsg;
551
+ for (const msg of this[kElements].postponed) {
552
+ if (msg.content.executionId === content.executionId) {
553
+ prevMsg = msg;
554
+ break;
555
+ }
556
+ }
552
557
  if (!prevMsg) return message.ack();
553
558
  break;
554
559
  }
@@ -560,7 +565,7 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
560
565
  switch (routingKey) {
561
566
  case 'activity.detach':
562
567
  {
563
- this[kElements].detachedActivities.push((0, _messageHelper.cloneMessage)(message));
568
+ this[kElements].detachedActivities.add((0, _messageHelper.cloneMessage)(message));
564
569
  break;
565
570
  }
566
571
  case 'activity.cancel':
@@ -581,10 +586,13 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
581
586
  }
582
587
  case 'activity.error':
583
588
  {
584
- const eventCaughtBy = this[kElements].postponed.find(msg => {
585
- if (msg.fields.routingKey !== 'activity.catch') return;
586
- return msg.content.source && msg.content.source.executionId === content.executionId;
587
- });
589
+ let eventCaughtBy;
590
+ for (const msg of this[kElements].postponed) {
591
+ if (msg.fields.routingKey === 'activity.catch' && msg.content.source && msg.content.source.executionId === content.executionId) {
592
+ eventCaughtBy = msg;
593
+ break;
594
+ }
595
+ }
588
596
  if (eventCaughtBy) {
589
597
  this[kActivityQ].queueMessage({
590
598
  routingKey: 'activity.error.caught'
@@ -603,23 +611,37 @@ ProcessExecution.prototype._onChildMessage = function onChildMessage(routingKey,
603
611
  ProcessExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
604
612
  const previousMsg = this._popPostponed(message.content);
605
613
  if (previousMsg) previousMsg.ack();
606
- if (postponeMessage) this[kElements].postponed.push(message);
614
+ if (postponeMessage) this[kElements].postponed.add(message);
607
615
  };
608
616
  ProcessExecution.prototype._popPostponed = function popPostponed(byContent) {
609
617
  const {
610
618
  postponed,
611
619
  detachedActivities
612
620
  } = this[kElements];
613
- const postponedIdx = postponed.findIndex(msg => {
614
- if (msg.content.isSequenceFlow || msg.content.isAssociation) return msg.content.sequenceId === byContent.sequenceId;
615
- return msg.content.executionId === byContent.executionId;
616
- });
617
621
  let postponedMsg;
618
- if (postponedIdx > -1) {
619
- postponedMsg = postponed.splice(postponedIdx, 1)[0];
622
+ if (byContent.sequenceId) {
623
+ for (const msg of postponed) {
624
+ if (!msg.content.isSequenceFlow && !msg.content.isAssociation) continue;
625
+ if (msg.content.sequenceId === byContent.sequenceId) {
626
+ postponedMsg = msg;
627
+ break;
628
+ }
629
+ }
630
+ } else {
631
+ for (const msg of postponed) {
632
+ if (msg.content.executionId === byContent.executionId) {
633
+ postponedMsg = msg;
634
+ break;
635
+ }
636
+ }
637
+ }
638
+ if (postponedMsg) postponed.delete(postponedMsg);
639
+ for (const msg of detachedActivities) {
640
+ if (msg.content.executionId === byContent.executionId) {
641
+ detachedActivities.delete(msg);
642
+ break;
643
+ }
620
644
  }
621
- const detachedIdx = detachedActivities.findIndex(msg => msg.content.executionId === byContent.executionId);
622
- if (detachedIdx > -1) detachedActivities.splice(detachedIdx, 1);
623
645
  return postponedMsg;
624
646
  };
625
647
  ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message) {
@@ -635,15 +657,15 @@ ProcessExecution.prototype._onChildCompleted = function onChildCompleted(message
635
657
  detachedActivities,
636
658
  startActivities
637
659
  } = this[kElements];
638
- const postponedCount = postponed.length;
660
+ const postponedCount = postponed.size;
639
661
  if (!postponedCount) {
640
662
  this._debug(`left <${id}> (${type}), pending runs ${postponedCount}`);
641
663
  message.ack();
642
664
  return this._complete('completed');
643
665
  }
644
666
  message.ack();
645
- this._debug(`left <${id}> (${type}), pending runs ${postponedCount}, ${postponed.map(a => a.content.id).join(',')}`);
646
- if (postponedCount && postponedCount === detachedActivities.length) {
667
+ this._debug(`left <${id}> (${type}), pending activities ${postponedCount}`);
668
+ if (postponedCount && postponedCount === detachedActivities.size) {
647
669
  return this[kActivityQ].queueMessage({
648
670
  routingKey: 'execution.discard.detached'
649
671
  }, {
@@ -687,8 +709,10 @@ ProcessExecution.prototype._stopExecution = function stopExecution(message) {
687
709
  };
688
710
  ProcessExecution.prototype._onDiscard = function onDiscard() {
689
711
  this._deactivate();
690
- const running = this[kElements].postponed.splice(0);
691
- this._debug(`discard process execution (discard child executions ${running.length})`);
712
+ const postponed = this[kElements].postponed;
713
+ const running = new Set(postponed);
714
+ postponed.clear();
715
+ this._debug(`discard process execution (discard child executions ${running.size})`);
692
716
  if (this.isSubProcess) {
693
717
  this.stop();
694
718
  } else {
@@ -700,10 +724,11 @@ ProcessExecution.prototype._onDiscard = function onDiscard() {
700
724
  return this._complete('discard');
701
725
  };
702
726
  ProcessExecution.prototype._onCancel = function onCancel() {
703
- const running = this[kElements].postponed.slice(0);
727
+ const postponed = this[kElements].postponed;
728
+ const running = new Set(postponed);
704
729
  const isTransaction = this.isTransaction;
705
730
  if (isTransaction) {
706
- this._debug(`cancel transaction execution (cancel child executions ${running.length})`);
731
+ this._debug(`cancel transaction execution (cancel child executions ${running.size})`);
707
732
  this[kStatus] = 'cancel';
708
733
  this.broker.publish('event', 'transaction.cancel', (0, _messageHelper.cloneMessage)(this[kExecuteMessage], {
709
734
  state: 'cancel'
@@ -716,7 +741,7 @@ ProcessExecution.prototype._onCancel = function onCancel() {
716
741
  }
717
742
  }
718
743
  } else {
719
- this._debug(`cancel process execution (cancel child executions ${running.length})`);
744
+ this._debug(`cancel process execution (cancel child executions ${running.size})`);
720
745
  for (const msg of running) {
721
746
  this._getChildApi(msg).discard();
722
747
  }
@@ -799,7 +824,9 @@ ProcessExecution.prototype._complete = function complete(completionType, content
799
824
  ProcessExecution.prototype._terminate = function terminate(message) {
800
825
  this[kStatus] = 'terminated';
801
826
  this._debug('terminating process execution');
802
- const running = this[kElements].postponed.splice(0);
827
+ const postponed = this[kElements].postponed;
828
+ const running = new Set(postponed);
829
+ postponed.clear();
803
830
  for (const flow of this.getSequenceFlows()) flow.stop();
804
831
  for (const flow of this.getAssociations()) flow.stop();
805
832
  for (const msg of running) {
package/dist/shared.js CHANGED
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.brokerSafeId = brokerSafeId;
7
- exports.filterUndefined = filterUndefined;
8
7
  exports.generateId = generateId;
9
8
  exports.getOptionsAndCallback = getOptionsAndCallback;
10
9
  exports.getUniqueId = getUniqueId;
@@ -18,13 +17,6 @@ function brokerSafeId(id) {
18
17
  function getUniqueId(prefix) {
19
18
  return `${brokerSafeId(prefix)}_${generateId()}`;
20
19
  }
21
- function filterUndefined(obj) {
22
- return Object.keys(obj).reduce((filtered, key) => {
23
- const objValue = obj[key];
24
- if (objValue !== undefined) filtered[key] = objValue;
25
- return filtered;
26
- }, {});
27
- }
28
20
  function getOptionsAndCallback(optionsOrCallback, callback) {
29
21
  let options;
30
22
  if (typeof optionsOrCallback === 'function') {
@@ -8,7 +8,7 @@ exports.default = CallActivity;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _Errors = require("../error/Errors.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
  function CallActivity(activityDef, context) {
13
13
  return new _Activity.default(CallActivityBehaviour, activityDef, context);
14
14
  }
@@ -139,11 +139,11 @@ ParallelLoopCharacteristics.prototype.execute = function execute(executeMessage)
139
139
  ParallelLoopCharacteristics.prototype._startBatch = function startBatch() {
140
140
  const chr = this.characteristics;
141
141
  const cardinality = chr.cardinality;
142
- const batch = [];
142
+ const batch = new Set();
143
143
  let startContent = chr.next(this.index);
144
144
  do {
145
145
  chr.debug(`start parallel iteration index ${this.index}`);
146
- batch.push(startContent);
146
+ batch.add(startContent);
147
147
  this.running++;
148
148
  this.index++;
149
149
  if (this.index >= cardinality || this.running >= chr.batchSize) {
@@ -7,7 +7,7 @@ exports.ReceiveTaskBehaviour = ReceiveTaskBehaviour;
7
7
  exports.default = ReceiveTask;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.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 kExecuteMessage = Symbol.for('executeMessage');
13
13
  const kReferenceElement = Symbol.for('referenceElement');
@@ -9,7 +9,7 @@ var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _ExecutionScope = _interopRequireDefault(require("../activity/ExecutionScope.js"));
10
10
  var _Errors = require("../error/Errors.js");
11
11
  var _messageHelper = require("../messageHelper.js");
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
13
  function ScriptTask(activityDef, context) {
14
14
  return new _Activity.default(ScriptTaskBehaviour, activityDef, context);
15
15
  }
@@ -33,8 +33,8 @@ ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
33
33
  if (loopCharacteristics && executeContent.isRootScope) {
34
34
  return loopCharacteristics.execute(executeMessage);
35
35
  }
36
- const activity = this.activity,
37
- scriptFormat = this.scriptFormat;
36
+ const activity = this.activity;
37
+ const scriptFormat = this.scriptFormat;
38
38
  const script = this.environment.getScript(scriptFormat, activity, (0, _messageHelper.cloneMessage)(executeMessage));
39
39
  if (!script) {
40
40
  return activity.emitFatal(new _Errors.ActivityError(`Script format ${scriptFormat} is unsupported or was not registered for <${activity.id}>`, executeMessage), executeContent);
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = ServiceImplementation;
7
7
  var _ExecutionScope = _interopRequireDefault(require("../activity/ExecutionScope.js"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  function ServiceImplementation(activity) {
10
10
  this.type = `${activity.type}:implementation`;
11
11
  this.implementation = activity.behaviour.implementation;