bpmn-elements 15.0.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.
@@ -10,13 +10,13 @@ var _Timers = require("./Timers.js");
10
10
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  const kServices = Symbol.for('services');
12
12
  const kVariables = Symbol.for('variables');
13
- const defaultOptions = ['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables'];
13
+ const defaultOptions = new Set(['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables']);
14
14
  function Environment(options = {}) {
15
15
  this.options = validateOptions(options);
16
16
  this.expressions = options.expressions || (0, _Expressions.default)();
17
17
  this.extensions = options.extensions;
18
18
  this.output = options.output || {};
19
- this.scripts = options.scripts || (0, _Scripts.Scripts)();
19
+ this.scripts = options.scripts || new _Scripts.Scripts();
20
20
  this.timers = options.timers || new _Timers.Timers();
21
21
  this.settings = {
22
22
  ...options.settings
@@ -124,7 +124,7 @@ Environment.prototype.addService = function addService(name, fn) {
124
124
  function validateOptions(input) {
125
125
  const options = {};
126
126
  for (const key in input) {
127
- if (defaultOptions.indexOf(key) === -1) {
127
+ if (!defaultOptions.has(key)) {
128
128
  options[key] = input[key];
129
129
  }
130
130
  }
package/dist/Scripts.js CHANGED
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Scripts = Scripts;
7
- function Scripts() {
8
- return {
9
- getScript,
10
- register
11
- };
12
- function getScript( /*scriptType, activity*/) {}
13
- function register( /*activity*/) {}
14
- }
7
+ function Scripts() {}
8
+ Scripts.prototype.getScript = function getScript( /*scriptType, activity*/) {};
9
+ Scripts.prototype.register = function register( /*activity*/) {};
@@ -87,7 +87,7 @@ function Activity(Behaviour, activityDef, context) {
87
87
  const flows = this[kFlows] = {
88
88
  inboundSequenceFlows,
89
89
  inboundAssociations,
90
- inboundJoinFlows: [],
90
+ inboundJoinFlows: new Set(),
91
91
  inboundTriggers,
92
92
  outboundSequenceFlows,
93
93
  outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows)
@@ -105,7 +105,7 @@ function Activity(Behaviour, activityDef, context) {
105
105
  isThrowing: activityDef.isThrowing,
106
106
  lane: activityDef.lane && activityDef.lane.id
107
107
  };
108
- this[kExec] = {};
108
+ this[kExec] = new Map();
109
109
  this[kMessageHandlers] = {
110
110
  onInbound: isParallelJoin ? this._onJoinInbound.bind(this) : this._onInbound.bind(this),
111
111
  onRunMessage: this._onRunMessage.bind(this),
@@ -127,12 +127,12 @@ Object.defineProperties(Activity.prototype, {
127
127
  },
128
128
  execution: {
129
129
  get() {
130
- return this[kExec].execution;
130
+ return this[kExec].get('execution');
131
131
  }
132
132
  },
133
133
  executionId: {
134
134
  get() {
135
- return this[kExec].executionId;
135
+ return this[kExec].get('executionId');
136
136
  }
137
137
  },
138
138
  extensions: {
@@ -257,7 +257,8 @@ Activity.prototype.deactivate = function deactivate() {
257
257
  Activity.prototype.init = function init(initContent) {
258
258
  const id = this.id;
259
259
  const exec = this[kExec];
260
- const executionId = exec.initExecutionId = exec.initExecutionId || (0, _shared.getUniqueId)(id);
260
+ const executionId = exec.has('initExecutionId') ? exec.get('initExecutionId') : (0, _shared.getUniqueId)(id);
261
+ exec.set('initExecutionId', executionId);
261
262
  this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
262
263
  this._publishEvent('init', this._createMessage({
263
264
  ...initContent,
@@ -268,8 +269,9 @@ Activity.prototype.run = function run(runContent) {
268
269
  const id = this.id;
269
270
  if (this.isRunning) throw new Error(`activity <${id}> is already running`);
270
271
  const exec = this[kExec];
271
- const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(id);
272
- exec.initExecutionId = null;
272
+ const executionId = exec.get('initExecutionId') || (0, _shared.getUniqueId)(id);
273
+ exec.set('executionId', executionId);
274
+ exec.delete('initExecutionId');
273
275
  this._consumeApi();
274
276
  const content = this._createMessage({
275
277
  ...runContent,
@@ -284,6 +286,8 @@ Activity.prototype.run = function run(runContent) {
284
286
  Activity.prototype.getState = function getState() {
285
287
  const status = this.status;
286
288
  const exec = this[kExec];
289
+ const execution = exec.get('execution');
290
+ const executionId = exec.get('executionId');
287
291
  const brokerState = this.broker.getState(true);
288
292
  if (!brokerState && this.environment.settings.disableTrackState) return;
289
293
  return {
@@ -292,11 +296,13 @@ Activity.prototype.getState = function getState() {
292
296
  ...(status && {
293
297
  status
294
298
  }),
295
- executionId: exec.executionId,
299
+ executionId,
296
300
  stopped: this.stopped,
297
301
  counters: this.counters,
298
302
  broker: brokerState,
299
- execution: exec.execution && exec.execution.getState()
303
+ ...(execution && {
304
+ execution: execution.getState()
305
+ })
300
306
  };
301
307
  };
302
308
  Activity.prototype.recover = function recover(state) {
@@ -305,13 +311,13 @@ Activity.prototype.recover = function recover(state) {
305
311
  this.stopped = state.stopped;
306
312
  this.status = state.status;
307
313
  const exec = this[kExec];
308
- exec.executionId = state.executionId;
314
+ exec.set('executionId', state.executionId);
309
315
  this[kCounters] = {
310
316
  ...this[kCounters],
311
317
  ...state.counters
312
318
  };
313
319
  if (state.execution) {
314
- exec.execution = new _ActivityExecution.default(this, this.context).recover(state.execution);
320
+ exec.set('execution', new _ActivityExecution.default(this, this.context).recover(state.execution));
315
321
  }
316
322
  this.broker.recover(state.broker);
317
323
  return this;
@@ -332,7 +338,7 @@ Activity.prototype.resume = function resume() {
332
338
  };
333
339
  Activity.prototype.discard = function discard(discardContent) {
334
340
  if (!this.status) return this._runDiscard(discardContent);
335
- const execution = this[kExec].execution;
341
+ const execution = this[kExec].get('execution');
336
342
  if (execution && !execution.completed) return execution.discard();
337
343
  this._deactivateRunConsumers();
338
344
  const broker = this.broker;
@@ -392,7 +398,7 @@ Activity.prototype.evaluateOutbound = function evaluateOutbound(fromMessage, dis
392
398
  return this[kFlows].outboundEvaluator.evaluate(fromMessage, discardRestAtTake, callback);
393
399
  };
394
400
  Activity.prototype.getApi = function getApi(message) {
395
- const execution = this[kExec].execution;
401
+ const execution = this[kExec].get('execution');
396
402
  if (execution && !execution.completed) return execution.getApi(message);
397
403
  return (0, _Api.ActivityApi)(this.broker, message || this[kStateMessage]);
398
404
  };
@@ -401,8 +407,9 @@ Activity.prototype.getActivityById = function getActivityById(elementId) {
401
407
  };
402
408
  Activity.prototype._runDiscard = function runDiscard(discardContent) {
403
409
  const exec = this[kExec];
404
- const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(this.id);
405
- exec.initExecutionId = null;
410
+ const executionId = exec.get('initExecutionId') || (0, _shared.getUniqueId)(this.id);
411
+ exec.set('executionId', executionId);
412
+ exec.delete('initExecutionId');
406
413
  this._consumeApi();
407
414
  const content = this._createMessage({
408
415
  ...discardContent,
@@ -415,7 +422,7 @@ Activity.prototype._runDiscard = function runDiscard(discardContent) {
415
422
  Activity.prototype._discardRun = function discardRun() {
416
423
  const status = this.status;
417
424
  if (!status) return;
418
- const execution = this[kExec].execution;
425
+ const execution = this[kExec].get('execution');
419
426
  if (execution && !execution.completed) return;
420
427
  switch (status) {
421
428
  case 'end':
@@ -500,39 +507,45 @@ Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message)
500
507
  content
501
508
  } = message;
502
509
  const {
503
- inboundSequenceFlows,
504
510
  inboundJoinFlows,
505
511
  inboundTriggers
506
512
  } = this[kFlows];
507
- const idx = inboundJoinFlows.findIndex(msg => msg.content.id === content.id);
508
- inboundJoinFlows.push(message);
509
- if (idx > -1) return;
510
- const allTouched = inboundJoinFlows.length >= inboundTriggers.length;
511
- if (!allTouched) {
512
- const remaining = inboundSequenceFlows.filter((inb, i, list) => list.indexOf(inb) === i).length - inboundJoinFlows.length;
513
+ let alreadyTouched = false;
514
+ const touched = new Set();
515
+ let taken;
516
+ for (const msg of inboundJoinFlows) {
517
+ const flowId = msg.content.id;
518
+ touched.add(flowId);
519
+ if (flowId === content.id) {
520
+ alreadyTouched = true;
521
+ }
522
+ }
523
+ inboundJoinFlows.add(message);
524
+ if (alreadyTouched) return;
525
+ const remaining = inboundTriggers.length - touched.size - 1;
526
+ if (remaining) {
513
527
  return this.logger.debug(`<${this.id}> inbound ${message.content.action} from <${message.content.id}>, ${remaining} remaining`);
514
528
  }
515
- const evaluatedInbound = inboundJoinFlows.splice(0);
516
- let taken;
517
- const inbound = evaluatedInbound.map(im => {
529
+ const inbound = [];
530
+ for (const im of inboundJoinFlows) {
518
531
  if (im.fields.routingKey === 'flow.take') taken = true;
519
532
  im.ack();
520
- return (0, _messageHelper.cloneContent)(im.content);
521
- });
522
- let discardSequence;
533
+ inbound.push((0, _messageHelper.cloneContent)(im.content));
534
+ }
535
+ const discardSequence = new Set();
523
536
  if (!taken) {
524
- discardSequence = [];
525
- for (const im of evaluatedInbound) {
537
+ for (const im of inboundJoinFlows) {
526
538
  if (!im.content.discardSequence) continue;
527
539
  for (const sourceId of im.content.discardSequence) {
528
- if (discardSequence.indexOf(sourceId) === -1) discardSequence.push(sourceId);
540
+ discardSequence.add(sourceId);
529
541
  }
530
542
  }
531
543
  }
544
+ inboundJoinFlows.clear();
532
545
  this.broker.cancel('_run-on-inbound');
533
546
  if (!taken) return this._runDiscard({
534
547
  inbound,
535
- discardSequence
548
+ discardSequence: [...discardSequence]
536
549
  });
537
550
  return this.run({
538
551
  inbound
@@ -609,7 +622,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
609
622
  this.logger.debug(`<${id}> enter`, isRedelivered ? 'redelivered' : '');
610
623
  this.status = 'entered';
611
624
  if (!isRedelivered) {
612
- this[kExec].execution = null;
625
+ this[kExec].delete('execution');
613
626
  if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
614
627
  this._publishEvent('enter', content, {
615
628
  correlationId
@@ -621,7 +634,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
621
634
  {
622
635
  this.logger.debug(`<${id}> discard`, isRedelivered ? 'redelivered' : '');
623
636
  this.status = 'discard';
624
- this[kExec].execution = null;
637
+ this[kExec].delete('execution');
625
638
  if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
626
639
  if (!isRedelivered) {
627
640
  this.broker.publish('run', 'run.discarded', content, {
@@ -660,12 +673,12 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
660
673
  this[kExecuteMessage] = message;
661
674
  const exec = this[kExec];
662
675
  if (isRedelivered && this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
663
- if (!exec.execution) exec.execution = new _ActivityExecution.default(this, this.context);
676
+ if (!exec.has('execution')) exec.set('execution', new _ActivityExecution.default(this, this.context));
664
677
  this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
665
678
  exclusive: true,
666
679
  consumerTag: '_activity-execution'
667
680
  });
668
- return exec.execution.execute(message);
681
+ return exec.get('execution').execute(message);
669
682
  }
670
683
  case 'run.end':
671
684
  {
@@ -920,7 +933,7 @@ Activity.prototype._onStop = function onStop(message) {
920
933
  }
921
934
  };
922
935
  Activity.prototype._consumeApi = function consumeApi() {
923
- const executionId = this[kExec].executionId;
936
+ const executionId = this[kExec].get('executionId');
924
937
  if (!executionId) return;
925
938
  const broker = this.broker;
926
939
  broker.cancel('_activity-api');
@@ -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');
@@ -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;
@@ -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':
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') {
@@ -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);
@@ -10,7 +10,7 @@ var _ProcessExecution = _interopRequireDefault(require("../process/ProcessExecut
10
10
  var _messageHelper = require("../messageHelper.js");
11
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  const kExecutions = Symbol.for('executions');
13
- const kMessageHandlers = Symbol.for('messageHandlers');
13
+ const kOnExecutionCompleted = Symbol.for('execution completed handler');
14
14
  function SubProcess(activityDef, context) {
15
15
  const triggeredByEvent = activityDef.behaviour && activityDef.behaviour.triggeredByEvent;
16
16
  const subProcess = new _Activity.default(SubProcessBehaviour, {
@@ -55,9 +55,7 @@ function SubProcessBehaviour(activity, context) {
55
55
  this.broker = activity.broker;
56
56
  this.executionId = undefined;
57
57
  this[kExecutions] = new Set();
58
- this[kMessageHandlers] = {
59
- onExecutionCompleted: this._onExecutionCompleted.bind(this)
60
- };
58
+ this[kOnExecutionCompleted] = this._onExecutionCompleted.bind(this);
61
59
  }
62
60
  Object.defineProperties(SubProcessBehaviour.prototype, {
63
61
  execution: {
@@ -143,7 +141,7 @@ SubProcessBehaviour.prototype._upsertExecution = function upsertExecution(execut
143
141
  return execution;
144
142
  };
145
143
  SubProcessBehaviour.prototype._addListeners = function addListeners(executionId) {
146
- this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kMessageHandlers].onExecutionCompleted, {
144
+ this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kOnExecutionCompleted], {
147
145
  noAck: true,
148
146
  consumerTag: `_sub-process-execution-${executionId}`
149
147
  });
@@ -179,7 +177,6 @@ SubProcessBehaviour.prototype._onExecutionCompleted = function onExecutionComple
179
177
  SubProcessBehaviour.prototype._completeExecution = function completeExecution(completeRoutingKey, content) {
180
178
  if (this.loopCharacteristics) {
181
179
  const execution = this._getExecutionById(content.executionId);
182
- if (!execution) return;
183
180
  this[kExecutions].delete(execution);
184
181
  }
185
182
  this.broker.publish('execution', completeRoutingKey, (0, _messageHelper.cloneContent)(content));
@@ -191,6 +188,7 @@ SubProcessBehaviour.prototype.getApi = function getApi(apiMessage) {
191
188
  if (execution = this._getExecutionById(content.parent.executionId)) {
192
189
  return execution.getApi(apiMessage);
193
190
  }
191
+ if (!content.parent.path) return;
194
192
  for (const pp of content.parent.path) {
195
193
  if (execution = this._getExecutionById(pp.executionId)) return execution.getApi(apiMessage);
196
194
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-elements",
3
- "version": "15.0.0",
3
+ "version": "15.0.1",
4
4
  "description": "Executable workflow elements based on BPMN 2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -72,7 +72,7 @@
72
72
  "@bonniernews/hot-bev": "^0.4.0",
73
73
  "@types/node": "^16.18.95",
74
74
  "bpmn-moddle": "^9.0.1",
75
- "c8": "^9.1.0",
75
+ "c8": "^10.1.1",
76
76
  "camunda-bpmn-moddle": "^7.0.1",
77
77
  "chai": "^5.1.0",
78
78
  "chronokinesis": "^6.0.0",
@@ -89,6 +89,6 @@
89
89
  },
90
90
  "dependencies": {
91
91
  "@0dep/piso": "^0.1.3",
92
- "smqp": "^9.0.1"
92
+ "smqp": "^9.0.2"
93
93
  }
94
94
  }
@@ -1,11 +1,11 @@
1
1
  import Expressions from './Expressions.js';
2
- import { Scripts as IScripts } from './Scripts.js';
2
+ import { Scripts } from './Scripts.js';
3
3
  import { Timers } from './Timers.js';
4
4
 
5
5
  const kServices = Symbol.for('services');
6
6
  const kVariables = Symbol.for('variables');
7
7
 
8
- const defaultOptions = ['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables'];
8
+ const defaultOptions = new Set(['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables']);
9
9
 
10
10
  export default function Environment(options = {}) {
11
11
  this.options = validateOptions(options);
@@ -13,7 +13,7 @@ export default function Environment(options = {}) {
13
13
  this.expressions = options.expressions || Expressions();
14
14
  this.extensions = options.extensions;
15
15
  this.output = options.output || {};
16
- this.scripts = options.scripts || IScripts();
16
+ this.scripts = options.scripts || new Scripts();
17
17
  this.timers = options.timers || new Timers();
18
18
  this.settings = { ...options.settings };
19
19
  this.Logger = options.Logger || DummyLogger;
@@ -125,7 +125,7 @@ Environment.prototype.addService = function addService(name, fn) {
125
125
  function validateOptions(input) {
126
126
  const options = {};
127
127
  for (const key in input) {
128
- if (defaultOptions.indexOf(key) === -1) {
128
+ if (!defaultOptions.has(key)) {
129
129
  options[key] = input[key];
130
130
  }
131
131
  }
package/src/Scripts.js CHANGED
@@ -1,9 +1,4 @@
1
- export function Scripts() {
2
- return {
3
- getScript,
4
- register,
5
- };
1
+ export function Scripts() {}
6
2
 
7
- function getScript(/*scriptType, activity*/) {}
8
- function register(/*activity*/) {}
9
- }
3
+ Scripts.prototype.getScript = function getScript(/*scriptType, activity*/) {};
4
+ Scripts.prototype.register = function register(/*activity*/) {};
@@ -71,7 +71,7 @@ function Activity(Behaviour, activityDef, context) {
71
71
  const flows = (this[kFlows] = {
72
72
  inboundSequenceFlows,
73
73
  inboundAssociations,
74
- inboundJoinFlows: [],
74
+ inboundJoinFlows: new Set(),
75
75
  inboundTriggers,
76
76
  outboundSequenceFlows,
77
77
  outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows),
@@ -90,7 +90,7 @@ function Activity(Behaviour, activityDef, context) {
90
90
  isThrowing: activityDef.isThrowing,
91
91
  lane: activityDef.lane && activityDef.lane.id,
92
92
  };
93
- this[kExec] = {};
93
+ this[kExec] = new Map();
94
94
 
95
95
  this[kMessageHandlers] = {
96
96
  onInbound: isParallelJoin ? this._onJoinInbound.bind(this) : this._onInbound.bind(this),
@@ -113,12 +113,12 @@ Object.defineProperties(Activity.prototype, {
113
113
  },
114
114
  execution: {
115
115
  get() {
116
- return this[kExec].execution;
116
+ return this[kExec].get('execution');
117
117
  },
118
118
  },
119
119
  executionId: {
120
120
  get() {
121
- return this[kExec].executionId;
121
+ return this[kExec].get('executionId');
122
122
  },
123
123
  },
124
124
  extensions: {
@@ -250,7 +250,8 @@ Activity.prototype.deactivate = function deactivate() {
250
250
  Activity.prototype.init = function init(initContent) {
251
251
  const id = this.id;
252
252
  const exec = this[kExec];
253
- const executionId = (exec.initExecutionId = exec.initExecutionId || getUniqueId(id));
253
+ const executionId = exec.has('initExecutionId') ? exec.get('initExecutionId') : getUniqueId(id);
254
+ exec.set('initExecutionId', executionId);
254
255
  this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
255
256
  this._publishEvent('init', this._createMessage({ ...initContent, executionId }));
256
257
  };
@@ -260,8 +261,9 @@ Activity.prototype.run = function run(runContent) {
260
261
  if (this.isRunning) throw new Error(`activity <${id}> is already running`);
261
262
 
262
263
  const exec = this[kExec];
263
- const executionId = (exec.executionId = exec.initExecutionId || getUniqueId(id));
264
- exec.initExecutionId = null;
264
+ const executionId = exec.get('initExecutionId') || getUniqueId(id);
265
+ exec.set('executionId', executionId);
266
+ exec.delete('initExecutionId');
265
267
 
266
268
  this._consumeApi();
267
269
 
@@ -278,6 +280,8 @@ Activity.prototype.run = function run(runContent) {
278
280
  Activity.prototype.getState = function getState() {
279
281
  const status = this.status;
280
282
  const exec = this[kExec];
283
+ const execution = exec.get('execution');
284
+ const executionId = exec.get('executionId');
281
285
  const brokerState = this.broker.getState(true);
282
286
  if (!brokerState && this.environment.settings.disableTrackState) return;
283
287
 
@@ -285,11 +289,11 @@ Activity.prototype.getState = function getState() {
285
289
  id: this.id,
286
290
  type: this.type,
287
291
  ...(status && { status }),
288
- executionId: exec.executionId,
292
+ executionId,
289
293
  stopped: this.stopped,
290
294
  counters: this.counters,
291
295
  broker: brokerState,
292
- execution: exec.execution && exec.execution.getState(),
296
+ ...(execution && { execution: execution.getState() }),
293
297
  };
294
298
  };
295
299
 
@@ -300,12 +304,12 @@ Activity.prototype.recover = function recover(state) {
300
304
  this.stopped = state.stopped;
301
305
  this.status = state.status;
302
306
  const exec = this[kExec];
303
- exec.executionId = state.executionId;
307
+ exec.set('executionId', state.executionId);
304
308
 
305
309
  this[kCounters] = { ...this[kCounters], ...state.counters };
306
310
 
307
311
  if (state.execution) {
308
- exec.execution = new ActivityExecution(this, this.context).recover(state.execution);
312
+ exec.set('execution', new ActivityExecution(this, this.context).recover(state.execution));
309
313
  }
310
314
 
311
315
  this.broker.recover(state.broker);
@@ -332,7 +336,7 @@ Activity.prototype.resume = function resume() {
332
336
 
333
337
  Activity.prototype.discard = function discard(discardContent) {
334
338
  if (!this.status) return this._runDiscard(discardContent);
335
- const execution = this[kExec].execution;
339
+ const execution = this[kExec].get('execution');
336
340
  if (execution && !execution.completed) return execution.discard();
337
341
 
338
342
  this._deactivateRunConsumers();
@@ -389,7 +393,7 @@ Activity.prototype.evaluateOutbound = function evaluateOutbound(fromMessage, dis
389
393
  };
390
394
 
391
395
  Activity.prototype.getApi = function getApi(message) {
392
- const execution = this[kExec].execution;
396
+ const execution = this[kExec].get('execution');
393
397
  if (execution && !execution.completed) return execution.getApi(message);
394
398
  return ActivityApi(this.broker, message || this[kStateMessage]);
395
399
  };
@@ -400,8 +404,9 @@ Activity.prototype.getActivityById = function getActivityById(elementId) {
400
404
 
401
405
  Activity.prototype._runDiscard = function runDiscard(discardContent) {
402
406
  const exec = this[kExec];
403
- const executionId = (exec.executionId = exec.initExecutionId || getUniqueId(this.id));
404
- exec.initExecutionId = null;
407
+ const executionId = exec.get('initExecutionId') || getUniqueId(this.id);
408
+ exec.set('executionId', executionId);
409
+ exec.delete('initExecutionId');
405
410
 
406
411
  this._consumeApi();
407
412
 
@@ -416,7 +421,7 @@ Activity.prototype._discardRun = function discardRun() {
416
421
  const status = this.status;
417
422
  if (!status) return;
418
423
 
419
- const execution = this[kExec].execution;
424
+ const execution = this[kExec].get('execution');
420
425
  if (execution && !execution.completed) return;
421
426
 
422
427
  switch (status) {
@@ -497,42 +502,50 @@ Activity.prototype._onInbound = function onInbound(routingKey, message) {
497
502
 
498
503
  Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message) {
499
504
  const { content } = message;
500
- const { inboundSequenceFlows, inboundJoinFlows, inboundTriggers } = this[kFlows];
501
- const idx = inboundJoinFlows.findIndex((msg) => msg.content.id === content.id);
505
+ const { inboundJoinFlows, inboundTriggers } = this[kFlows];
506
+ let alreadyTouched = false;
502
507
 
503
- inboundJoinFlows.push(message);
508
+ const touched = new Set();
504
509
 
505
- if (idx > -1) return;
510
+ let taken;
511
+ for (const msg of inboundJoinFlows) {
512
+ const flowId = msg.content.id;
513
+ touched.add(flowId);
514
+ if (flowId === content.id) {
515
+ alreadyTouched = true;
516
+ }
517
+ }
518
+
519
+ inboundJoinFlows.add(message);
520
+
521
+ if (alreadyTouched) return;
506
522
 
507
- const allTouched = inboundJoinFlows.length >= inboundTriggers.length;
508
- if (!allTouched) {
509
- const remaining = inboundSequenceFlows.filter((inb, i, list) => list.indexOf(inb) === i).length - inboundJoinFlows.length;
523
+ const remaining = inboundTriggers.length - touched.size - 1;
524
+ if (remaining) {
510
525
  return this.logger.debug(`<${this.id}> inbound ${message.content.action} from <${message.content.id}>, ${remaining} remaining`);
511
526
  }
512
527
 
513
- const evaluatedInbound = inboundJoinFlows.splice(0);
514
-
515
- let taken;
516
- const inbound = evaluatedInbound.map((im) => {
528
+ const inbound = [];
529
+ for (const im of inboundJoinFlows) {
517
530
  if (im.fields.routingKey === 'flow.take') taken = true;
518
531
  im.ack();
519
- return cloneContent(im.content);
520
- });
532
+ inbound.push(cloneContent(im.content));
533
+ }
521
534
 
522
- let discardSequence;
535
+ const discardSequence = new Set();
523
536
  if (!taken) {
524
- discardSequence = [];
525
- for (const im of evaluatedInbound) {
537
+ for (const im of inboundJoinFlows) {
526
538
  if (!im.content.discardSequence) continue;
527
539
  for (const sourceId of im.content.discardSequence) {
528
- if (discardSequence.indexOf(sourceId) === -1) discardSequence.push(sourceId);
540
+ discardSequence.add(sourceId);
529
541
  }
530
542
  }
531
543
  }
532
544
 
545
+ inboundJoinFlows.clear();
533
546
  this.broker.cancel('_run-on-inbound');
534
547
 
535
- if (!taken) return this._runDiscard({ inbound, discardSequence });
548
+ if (!taken) return this._runDiscard({ inbound, discardSequence: [...discardSequence] });
536
549
  return this.run({ inbound });
537
550
  };
538
551
 
@@ -606,7 +619,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
606
619
 
607
620
  this.status = 'entered';
608
621
  if (!isRedelivered) {
609
- this[kExec].execution = null;
622
+ this[kExec].delete('execution');
610
623
  if (this.extensions) this.extensions.activate(cloneMessage(message));
611
624
  this._publishEvent('enter', content, { correlationId });
612
625
  }
@@ -616,7 +629,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
616
629
  this.logger.debug(`<${id}> discard`, isRedelivered ? 'redelivered' : '');
617
630
 
618
631
  this.status = 'discard';
619
- this[kExec].execution = null;
632
+ this[kExec].delete('execution');
620
633
 
621
634
  if (this.extensions) this.extensions.activate(cloneMessage(message));
622
635
 
@@ -649,11 +662,11 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
649
662
 
650
663
  const exec = this[kExec];
651
664
  if (isRedelivered && this.extensions) this.extensions.activate(cloneMessage(message));
652
- if (!exec.execution) exec.execution = new ActivityExecution(this, this.context);
665
+ if (!exec.has('execution')) exec.set('execution', new ActivityExecution(this, this.context));
653
666
  this.broker
654
667
  .getQueue('execution-q')
655
668
  .assertConsumer(this[kMessageHandlers].onExecutionMessage, { exclusive: true, consumerTag: '_activity-execution' });
656
- return exec.execution.execute(message);
669
+ return exec.get('execution').execute(message);
657
670
  }
658
671
  case 'run.end': {
659
672
  this.logger.debug(`<${id}> end`, isRedelivered ? 'redelivered' : '');
@@ -904,7 +917,7 @@ Activity.prototype._onStop = function onStop(message) {
904
917
  };
905
918
 
906
919
  Activity.prototype._consumeApi = function consumeApi() {
907
- const executionId = this[kExec].executionId;
920
+ const executionId = this[kExec].get('executionId');
908
921
  if (!executionId) return;
909
922
  const broker = this.broker;
910
923
  broker.cancel('_activity-api');
@@ -41,7 +41,7 @@ export function Definition(context, options) {
41
41
  };
42
42
 
43
43
  this[kStopped] = false;
44
- this[kExec] = {};
44
+ this[kExec] = new Map();
45
45
 
46
46
  const onBrokerReturn = this._onBrokerReturnFn.bind(this);
47
47
  this[kMessageHandlers] = {
@@ -71,12 +71,12 @@ Object.defineProperties(Definition.prototype, {
71
71
  },
72
72
  execution: {
73
73
  get() {
74
- return this[kExec].execution;
74
+ return this[kExec].get('execution');
75
75
  },
76
76
  },
77
77
  executionId: {
78
78
  get() {
79
- return this[kExec].executionId;
79
+ return this[kExec].get('executionId');
80
80
  },
81
81
  },
82
82
  isRunning: {
@@ -97,7 +97,8 @@ Object.defineProperties(Definition.prototype, {
97
97
  },
98
98
  activityStatus: {
99
99
  get() {
100
- return (this[kExec].execution && this[kExec].execution.activityStatus) || 'idle';
100
+ const execution = this[kExec].get('execution');
101
+ return (execution && execution.activityStatus) || 'idle';
101
102
  },
102
103
  },
103
104
  });
@@ -115,7 +116,8 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
115
116
  }
116
117
 
117
118
  const exec = this[kExec];
118
- exec.executionId = getUniqueId(this.id);
119
+ const executionId = getUniqueId(this.id);
120
+ exec.set('executionId', executionId);
119
121
  const content = this._createMessage({ ...runOptions });
120
122
 
121
123
  const broker = this.broker;
@@ -123,7 +125,7 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
123
125
  broker.publish('run', 'run.start', cloneContent(content));
124
126
  broker.publish('run', 'run.execute', cloneContent(content));
125
127
 
126
- this.logger.debug(`<${this.executionId} (${this.id})> run`);
128
+ this.logger.debug(`<${executionId} (${this.id})> run`);
127
129
 
128
130
  this._activateRunConsumers();
129
131
 
@@ -171,7 +173,7 @@ Definition.prototype.recover = function recover(state) {
171
173
  this[kStatus] = state.status;
172
174
 
173
175
  const exec = this[kExec];
174
- exec.executionId = state.executionId;
176
+ exec.set('executionId', state.executionId);
175
177
  if (state.counters) {
176
178
  this[kCounters] = { ...this[kCounters], ...state.counters };
177
179
  }
@@ -179,7 +181,7 @@ Definition.prototype.recover = function recover(state) {
179
181
  this.environment.recover(state.environment);
180
182
 
181
183
  if (state.execution) {
182
- exec.execution = new DefinitionExecution(this, this.context).recover(state.execution);
184
+ exec.set('execution', new DefinitionExecution(this, this.context).recover(state.execution));
183
185
  }
184
186
 
185
187
  this.broker.recover(state.broker);
@@ -350,7 +352,7 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
350
352
  this[kStatus] = 'entered';
351
353
  if (fields.redelivered) break;
352
354
 
353
- exec.execution = undefined;
355
+ exec.delete('execution');
354
356
  this._publishEvent('enter', content);
355
357
  break;
356
358
  }
@@ -363,7 +365,8 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
363
365
  case 'run.execute': {
364
366
  this[kStatus] = 'executing';
365
367
  const executeMessage = cloneMessage(message);
366
- if (fields.redelivered && !exec.execution) {
368
+ let execution = exec.get('execution');
369
+ if (fields.redelivered && !execution) {
367
370
  executeMessage.fields.redelivered = undefined;
368
371
  }
369
372
  this[kExecuteMessage] = message;
@@ -372,13 +375,16 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
372
375
  consumerTag: '_definition-execution',
373
376
  });
374
377
 
375
- exec.execution = exec.execution || new DefinitionExecution(this, this.context);
378
+ if (!execution) {
379
+ execution = new DefinitionExecution(this, this.context);
380
+ exec.set('execution', execution);
381
+ }
376
382
 
377
383
  if (executeMessage.fields.redelivered) {
378
384
  this._publishEvent('resume', content);
379
385
  }
380
386
 
381
- return exec.execution.execute(executeMessage);
387
+ return execution.execute(executeMessage);
382
388
  }
383
389
  case 'run.end': {
384
390
  if (this[kStatus] === 'end') break;
@@ -502,7 +508,7 @@ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
502
508
  };
503
509
 
504
510
  Definition.prototype._reset = function reset() {
505
- this[kExec].executionId = undefined;
511
+ this[kExec].delete('executionId');
506
512
  this._deactivateRunConsumers();
507
513
  this.broker.purgeQueue('run-q');
508
514
  this.broker.purgeQueue('execution-q');
@@ -6,7 +6,7 @@ const kStopped = Symbol.for('stopped');
6
6
  const kTimerContent = Symbol.for('timerContent');
7
7
  const kTimer = Symbol.for('timer');
8
8
 
9
- const timerTypes = ['timeDuration', 'timeDate', 'timeCycle'];
9
+ const timerTypes = new Set(['timeDuration', 'timeDate', 'timeCycle']);
10
10
 
11
11
  export default function TimerEventDefinition(activity, eventDefinition) {
12
12
  const type = (this.type = eventDefinition.type || 'TimerEventDefinition');
@@ -36,7 +36,7 @@ export function Process(processDef, context) {
36
36
  discarded: 0,
37
37
  };
38
38
  this[kConsuming] = false;
39
- this[kExec] = {};
39
+ this[kExec] = new Map();
40
40
  this[kStatus] = undefined;
41
41
  this[kStopped] = false;
42
42
 
@@ -90,13 +90,13 @@ Object.defineProperties(Process.prototype, {
90
90
  },
91
91
  executionId: {
92
92
  get() {
93
- const { executionId, initExecutionId } = this[kExec];
94
- return executionId || initExecutionId;
93
+ const exec = this[kExec];
94
+ return exec.get('executionId') || exec.get('initExecutionId');
95
95
  },
96
96
  },
97
97
  execution: {
98
98
  get() {
99
- return this[kExec].execution;
99
+ return this[kExec].get('execution');
100
100
  },
101
101
  },
102
102
  status: {
@@ -106,14 +106,16 @@ Object.defineProperties(Process.prototype, {
106
106
  },
107
107
  activityStatus: {
108
108
  get() {
109
- return (this[kExec].execution && this[kExec].execution.activityStatus) || 'idle';
109
+ const execution = this[kExec].get('execution');
110
+ return (execution && execution.activityStatus) || 'idle';
110
111
  },
111
112
  },
112
113
  });
113
114
 
114
115
  Process.prototype.init = function init(useAsExecutionId) {
115
- const exec = this[kExec];
116
- const initExecutionId = (exec.initExecutionId = useAsExecutionId || getUniqueId(this.id));
116
+ const initExecutionId = useAsExecutionId || getUniqueId(this.id);
117
+ this[kExec].set('initExecutionId', initExecutionId);
118
+
117
119
  this._debug(`initialized with executionId <${initExecutionId}>`);
118
120
  this._publishEvent('init', this._createMessage({ executionId: initExecutionId }));
119
121
  };
@@ -122,8 +124,9 @@ Process.prototype.run = function run(runContent) {
122
124
  if (this.isRunning) throw new Error(`process <${this.id}> is already running`);
123
125
 
124
126
  const exec = this[kExec];
125
- const executionId = (exec.executionId = exec.initExecutionId || getUniqueId(this.id));
126
- exec.initExecutionId = undefined;
127
+ const executionId = exec.get('initExecutionId') || getUniqueId(this.id);
128
+ exec.delete('initExecutionId');
129
+ exec.set('executionId', executionId);
127
130
 
128
131
  const content = this._createMessage({ ...runContent, executionId });
129
132
 
@@ -168,12 +171,12 @@ Process.prototype.recover = function recover(state) {
168
171
  this[kStopped] = !!state.stopped;
169
172
  this[kStatus] = state.status;
170
173
  const exec = this[kExec];
171
- exec.executionId = state.executionId;
174
+ exec.set('executionId', state.executionId);
172
175
  this[kCounters] = { ...this[kCounters], ...state.counters };
173
176
  this.environment.recover(state.environment);
174
177
 
175
178
  if (state.execution) {
176
- exec.execution = new ProcessExecution(this, this.context).recover(state.execution);
179
+ exec.set('execution', new ProcessExecution(this, this.context).recover(state.execution));
177
180
  }
178
181
 
179
182
  this.broker.recover(state.broker);
@@ -228,7 +231,6 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
228
231
  return this._onResumeMessage(message);
229
232
  }
230
233
 
231
- const exec = this[kExec];
232
234
  this[kStateMessage] = message;
233
235
 
234
236
  switch (routingKey) {
@@ -238,7 +240,7 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
238
240
  this[kStatus] = 'entered';
239
241
  if (fields.redelivered) break;
240
242
 
241
- exec.execution = undefined;
243
+ this[kExec].delete('execution');
242
244
  this._publishEvent('enter', content);
243
245
 
244
246
  break;
@@ -250,9 +252,11 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
250
252
  break;
251
253
  }
252
254
  case 'run.execute': {
255
+ const exec = this[kExec];
253
256
  this[kStatus] = 'executing';
254
257
  const executeMessage = cloneMessage(message);
255
- if (fields.redelivered && !exec.execution) {
258
+ let execution = exec.get('execution');
259
+ if (fields.redelivered && !execution) {
256
260
  executeMessage.fields.redelivered = undefined;
257
261
  }
258
262
  this[kExecuteMessage] = message;
@@ -262,7 +266,8 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
262
266
  consumerTag: '_process-execution',
263
267
  });
264
268
 
265
- const execution = (exec.execution = exec.execution || new ProcessExecution(this, this.context));
269
+ execution = execution || new ProcessExecution(this, this.context);
270
+ exec.set('execution', execution);
266
271
  return execution.execute(executeMessage);
267
272
  }
268
273
  case 'run.error': {
package/src/shared.js CHANGED
@@ -12,14 +12,6 @@ export function getUniqueId(prefix) {
12
12
  return `${brokerSafeId(prefix)}_${generateId()}`;
13
13
  }
14
14
 
15
- export function filterUndefined(obj) {
16
- return Object.keys(obj).reduce((filtered, key) => {
17
- const objValue = obj[key];
18
- if (objValue !== undefined) filtered[key] = objValue;
19
- return filtered;
20
- }, {});
21
- }
22
-
23
15
  export function getOptionsAndCallback(optionsOrCallback, callback) {
24
16
  let options;
25
17
  if (typeof optionsOrCallback === 'function') {
@@ -29,8 +29,8 @@ ScriptTaskBehaviour.prototype.execute = function execute(executeMessage) {
29
29
  return loopCharacteristics.execute(executeMessage);
30
30
  }
31
31
 
32
- const activity = this.activity,
33
- scriptFormat = this.scriptFormat;
32
+ const activity = this.activity;
33
+ const scriptFormat = this.scriptFormat;
34
34
  const script = this.environment.getScript(scriptFormat, activity, cloneMessage(executeMessage));
35
35
  if (!script) {
36
36
  return activity.emitFatal(
@@ -3,7 +3,7 @@ import ProcessExecution from '../process/ProcessExecution.js';
3
3
  import { cloneContent } from '../messageHelper.js';
4
4
 
5
5
  const kExecutions = Symbol.for('executions');
6
- const kMessageHandlers = Symbol.for('messageHandlers');
6
+ const kOnExecutionCompleted = Symbol.for('execution completed handler');
7
7
 
8
8
  export default function SubProcess(activityDef, context) {
9
9
  const triggeredByEvent = activityDef.behaviour && activityDef.behaviour.triggeredByEvent;
@@ -39,9 +39,7 @@ export function SubProcessBehaviour(activity, context) {
39
39
  this.executionId = undefined;
40
40
 
41
41
  this[kExecutions] = new Set();
42
- this[kMessageHandlers] = {
43
- onExecutionCompleted: this._onExecutionCompleted.bind(this),
44
- };
42
+ this[kOnExecutionCompleted] = this._onExecutionCompleted.bind(this);
45
43
  }
46
44
 
47
45
  Object.defineProperties(SubProcessBehaviour.prototype, {
@@ -147,7 +145,7 @@ SubProcessBehaviour.prototype._upsertExecution = function upsertExecution(execut
147
145
  };
148
146
 
149
147
  SubProcessBehaviour.prototype._addListeners = function addListeners(executionId) {
150
- this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kMessageHandlers].onExecutionCompleted, {
148
+ this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kOnExecutionCompleted], {
151
149
  noAck: true,
152
150
  consumerTag: `_sub-process-execution-${executionId}`,
153
151
  });
@@ -184,7 +182,6 @@ SubProcessBehaviour.prototype._onExecutionCompleted = function onExecutionComple
184
182
  SubProcessBehaviour.prototype._completeExecution = function completeExecution(completeRoutingKey, content) {
185
183
  if (this.loopCharacteristics) {
186
184
  const execution = this._getExecutionById(content.executionId);
187
- if (!execution) return;
188
185
  this[kExecutions].delete(execution);
189
186
  }
190
187
 
@@ -201,6 +198,8 @@ SubProcessBehaviour.prototype.getApi = function getApi(apiMessage) {
201
198
  return execution.getApi(apiMessage);
202
199
  }
203
200
 
201
+ if (!content.parent.path) return;
202
+
204
203
  for (const pp of content.parent.path) {
205
204
  if ((execution = this._getExecutionById(pp.executionId))) return execution.getApi(apiMessage);
206
205
  }