bpmn-elements 8.2.0 → 8.2.2

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 (74) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/index.js +0 -49
  3. package/dist/src/Api.js +4 -19
  4. package/dist/src/Context.js +0 -35
  5. package/dist/src/Environment.js +18 -44
  6. package/dist/src/EventBroker.js +8 -27
  7. package/dist/src/Expressions.js +0 -13
  8. package/dist/src/ExtensionsMapper.js +0 -12
  9. package/dist/src/MessageFormatter.js +0 -33
  10. package/dist/src/Scripts.js +2 -9
  11. package/dist/src/Timers.js +0 -9
  12. package/dist/src/activity/Activity.js +39 -243
  13. package/dist/src/activity/ActivityExecution.js +8 -76
  14. package/dist/src/activity/Dummy.js +2 -3
  15. package/dist/src/activity/Escalation.js +4 -4
  16. package/dist/src/activity/ExecutionScope.js +0 -4
  17. package/dist/src/activity/Message.js +4 -4
  18. package/dist/src/activity/Signal.js +4 -4
  19. package/dist/src/definition/Definition.js +12 -133
  20. package/dist/src/definition/DefinitionExecution.js +10 -160
  21. package/dist/src/error/BpmnError.js +2 -3
  22. package/dist/src/error/Errors.js +0 -16
  23. package/dist/src/eventDefinitions/CancelEventDefinition.js +2 -35
  24. package/dist/src/eventDefinitions/CompensateEventDefinition.js +3 -34
  25. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +3 -42
  26. package/dist/src/eventDefinitions/ErrorEventDefinition.js +11 -41
  27. package/dist/src/eventDefinitions/EscalationEventDefinition.js +7 -37
  28. package/dist/src/eventDefinitions/EventDefinitionExecution.js +0 -30
  29. package/dist/src/eventDefinitions/LinkEventDefinition.js +11 -37
  30. package/dist/src/eventDefinitions/MessageEventDefinition.js +11 -44
  31. package/dist/src/eventDefinitions/SignalEventDefinition.js +9 -46
  32. package/dist/src/eventDefinitions/TerminateEventDefinition.js +0 -3
  33. package/dist/src/eventDefinitions/TimerEventDefinition.js +8 -52
  34. package/dist/src/events/BoundaryEvent.js +4 -44
  35. package/dist/src/events/EndEvent.js +2 -11
  36. package/dist/src/events/IntermediateCatchEvent.js +0 -13
  37. package/dist/src/events/IntermediateThrowEvent.js +2 -11
  38. package/dist/src/events/StartEvent.js +5 -25
  39. package/dist/src/flows/Association.js +4 -27
  40. package/dist/src/flows/MessageFlow.js +6 -18
  41. package/dist/src/flows/SequenceFlow.js +4 -39
  42. package/dist/src/gateways/EventBasedGateway.js +0 -21
  43. package/dist/src/gateways/ExclusiveGateway.js +0 -6
  44. package/dist/src/gateways/InclusiveGateway.js +0 -6
  45. package/dist/src/gateways/ParallelGateway.js +2 -7
  46. package/dist/src/getPropertyValue.js +0 -30
  47. package/dist/src/io/BpmnIO.js +2 -7
  48. package/dist/src/io/EnvironmentDataObject.js +0 -8
  49. package/dist/src/io/EnvironmentDataStore.js +0 -8
  50. package/dist/src/io/EnvironmentDataStoreReference.js +0 -8
  51. package/dist/src/io/InputOutputSpecification.js +12 -37
  52. package/dist/src/io/Properties.js +6 -39
  53. package/dist/src/messageHelper.js +10 -23
  54. package/dist/src/process/Process.js +10 -112
  55. package/dist/src/process/ProcessExecution.js +24 -170
  56. package/dist/src/shared.js +0 -7
  57. package/dist/src/tasks/CallActivity.js +2 -23
  58. package/dist/src/tasks/LoopCharacteristics.js +16 -67
  59. package/dist/src/tasks/ReceiveTask.js +8 -48
  60. package/dist/src/tasks/ScriptTask.js +1 -15
  61. package/dist/src/tasks/ServiceImplementation.js +0 -4
  62. package/dist/src/tasks/ServiceTask.js +0 -20
  63. package/dist/src/tasks/SignalTask.js +2 -21
  64. package/dist/src/tasks/StandardLoopCharacteristics.js +4 -5
  65. package/dist/src/tasks/SubProcess.js +4 -52
  66. package/dist/src/tasks/Task.js +0 -8
  67. package/dist/src/tasks/Transaction.js +0 -3
  68. package/package.json +7 -7
  69. package/src/Context.js +0 -1
  70. package/src/activity/Activity.js +1 -1
  71. package/src/gateways/EventBasedGateway.js +0 -1
  72. package/src/io/InputOutputSpecification.js +0 -1
  73. package/src/process/ProcessExecution.js +8 -1
  74. package/src/tasks/StandardLoopCharacteristics.js +0 -1
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _ActivityExecution = _interopRequireDefault(require("./ActivityExecution"));
9
-
10
8
  var _shared = require("../shared");
11
-
12
9
  var _Api = require("../Api");
13
-
14
10
  var _EventBroker = require("../EventBroker");
15
-
16
11
  var _MessageFormatter = require("../MessageFormatter");
17
-
18
12
  var _messageHelper = require("../messageHelper");
19
-
20
13
  var _Errors = require("../error/Errors");
21
-
22
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23
-
24
15
  const kActivityDef = Symbol.for('activityDefinition');
25
16
  const kConsuming = Symbol.for('consuming');
26
17
  const kCounters = Symbol.for('counters');
@@ -35,7 +26,6 @@ const kMessageHandlers = Symbol.for('messageHandlers');
35
26
  const kStateMessage = Symbol.for('stateMessage');
36
27
  var _default = Activity;
37
28
  exports.default = _default;
38
-
39
29
  function Activity(Behaviour, activityDef, context) {
40
30
  const {
41
31
  id,
@@ -51,7 +41,8 @@ function Activity(Behaviour, activityDef, context) {
51
41
  this.id = id;
52
42
  this.type = type;
53
43
  this.name = name;
54
- this.behaviour = { ...behaviour,
44
+ this.behaviour = {
45
+ ...behaviour,
55
46
  eventDefinitions
56
47
  };
57
48
  this.Behaviour = Behaviour;
@@ -64,12 +55,10 @@ function Activity(Behaviour, activityDef, context) {
64
55
  discarded: 0
65
56
  };
66
57
  let attachedToActivity, attachedTo;
67
-
68
58
  if (attachedToRef) {
69
59
  attachedTo = attachedToRef.id;
70
60
  attachedToActivity = context.getActivityById(attachedToRef.id);
71
61
  }
72
-
73
62
  const {
74
63
  broker,
75
64
  on,
@@ -114,14 +103,11 @@ function Activity(Behaviour, activityDef, context) {
114
103
  onApiMessage: this._onApiMessage.bind(this),
115
104
  onExecutionMessage: this._onExecutionMessage.bind(this)
116
105
  };
117
-
118
106
  const onInboundEvent = this._onInboundEvent.bind(this);
119
-
120
107
  broker.assertQueue('inbound-q', {
121
108
  durable: true,
122
109
  autoDelete: false
123
110
  });
124
-
125
111
  if (isForCompensation) {
126
112
  for (const trigger of inboundAssociations) {
127
113
  trigger.broker.subscribeTmp('event', '#', onInboundEvent, {
@@ -140,57 +126,45 @@ function Activity(Behaviour, activityDef, context) {
140
126
  });
141
127
  }
142
128
  }
143
-
144
129
  this[kEventDefinitions] = eventDefinitions && eventDefinitions.map(ed => new ed.Behaviour(this, ed, this.context));
145
130
  this[kExtensions] = context.loadExtensions(this);
146
131
  }
147
-
148
132
  const proto = Activity.prototype;
149
133
  Object.defineProperty(proto, 'counters', {
150
134
  enumerable: true,
151
-
152
135
  get() {
153
- return { ...this[kCounters]
136
+ return {
137
+ ...this[kCounters]
154
138
  };
155
139
  }
156
-
157
140
  });
158
141
  Object.defineProperty(proto, 'execution', {
159
142
  enumerable: true,
160
-
161
143
  get() {
162
144
  return this[kExec].execution;
163
145
  }
164
-
165
146
  });
166
147
  Object.defineProperty(proto, 'executionId', {
167
148
  enumerable: true,
168
-
169
149
  get() {
170
150
  return this[kExec].executionId;
171
151
  }
172
-
173
152
  });
174
153
  Object.defineProperty(proto, 'extensions', {
175
154
  enumerable: true,
176
-
177
155
  get() {
178
156
  return this[kExtensions];
179
157
  }
180
-
181
158
  });
182
159
  Object.defineProperty(proto, 'bpmnIo', {
183
160
  enumerable: true,
184
-
185
161
  get() {
186
162
  const extensions = this[kExtensions];
187
163
  return extensions && extensions.extensions.find(e => e.type === 'bpmnio');
188
164
  }
189
-
190
165
  });
191
166
  Object.defineProperty(proto, 'formatter', {
192
167
  enumerable: true,
193
-
194
168
  get() {
195
169
  let formatter = this[kFormatter];
196
170
  if (formatter) return formatter;
@@ -202,150 +176,117 @@ Object.defineProperty(proto, 'formatter', {
202
176
  }, broker.getQueue('format-run-q'));
203
177
  return formatter;
204
178
  }
205
-
206
179
  });
207
180
  Object.defineProperty(proto, 'isRunning', {
208
181
  enumerable: true,
209
-
210
182
  get() {
211
183
  if (!this[kConsuming]) return false;
212
184
  return !!this.status;
213
185
  }
214
-
215
186
  });
216
187
  Object.defineProperty(proto, 'outbound', {
217
188
  enumerable: true,
218
-
219
189
  get() {
220
190
  return this[kFlows].outboundSequenceFlows;
221
191
  }
222
-
223
192
  });
224
193
  Object.defineProperty(proto, 'inbound', {
225
194
  enumerable: true,
226
-
227
195
  get() {
228
196
  return this[kFlows].inboundSequenceFlows;
229
197
  }
230
-
231
198
  });
232
199
  Object.defineProperty(proto, 'isEnd', {
233
200
  enumerable: true,
234
-
235
201
  get() {
236
202
  return this[kFlags].isEnd;
237
203
  }
238
-
239
204
  });
240
205
  Object.defineProperty(proto, 'isStart', {
241
206
  enumerable: true,
242
-
243
207
  get() {
244
208
  return this[kFlags].isStart;
245
209
  }
246
-
247
210
  });
248
211
  Object.defineProperty(proto, 'isSubProcess', {
249
212
  enumerable: true,
250
-
251
213
  get() {
252
214
  return this[kFlags].isSubProcess;
253
215
  }
254
-
255
216
  });
256
217
  Object.defineProperty(proto, 'isMultiInstance', {
257
218
  enumerable: true,
258
-
259
219
  get() {
260
220
  return this[kFlags].isMultiInstance;
261
221
  }
262
-
263
222
  });
264
223
  Object.defineProperty(proto, 'isThrowing', {
265
224
  enumerable: true,
266
-
267
225
  get() {
268
226
  return this[kFlags].isThrowing;
269
227
  }
270
-
271
228
  });
272
229
  Object.defineProperty(proto, 'isForCompensation', {
273
230
  enumerable: true,
274
-
275
231
  get() {
276
232
  return this[kFlags].isForCompensation;
277
233
  }
278
-
279
234
  });
280
235
  Object.defineProperty(proto, 'triggeredByEvent', {
281
236
  enumerable: true,
282
-
283
237
  get() {
284
238
  return this[kActivityDef].triggeredByEvent;
285
239
  }
286
-
287
240
  });
288
241
  Object.defineProperty(proto, 'attachedTo', {
289
242
  enumerable: true,
290
-
291
243
  get() {
292
244
  const attachedToId = this[kFlags].attachedTo;
293
245
  if (!attachedToId) return null;
294
246
  return this.getActivityById(attachedToId);
295
247
  }
296
-
297
248
  });
298
249
  Object.defineProperty(proto, 'eventDefinitions', {
299
250
  enumerable: true,
300
-
301
251
  get() {
302
252
  return this[kEventDefinitions];
303
253
  }
304
-
305
254
  });
306
-
307
255
  proto.activate = function activate() {
308
256
  if (this[kFlags].isForCompensation) return;
309
257
  return this._consumeInbound();
310
258
  };
311
-
312
259
  proto.deactivate = function deactivate() {
313
260
  const broker = this.broker;
314
261
  broker.cancel('_run-on-inbound');
315
262
  broker.cancel('_format-consumer');
316
263
  };
317
-
318
264
  proto.init = function init(initContent) {
319
265
  const id = this.id;
320
266
  const exec = this[kExec];
321
267
  const executionId = exec.initExecutionId = exec.initExecutionId || (0, _shared.getUniqueId)(id);
322
268
  this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
323
-
324
- this._publishEvent('init', this._createMessage({ ...initContent,
269
+ this._publishEvent('init', this._createMessage({
270
+ ...initContent,
325
271
  executionId
326
272
  }));
327
273
  };
328
-
329
274
  proto.run = function run(runContent) {
330
275
  const id = this.id;
331
276
  if (this.isRunning) throw new Error(`activity <${id}> is already running`);
332
277
  const exec = this[kExec];
333
278
  const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(id);
334
279
  exec.initExecutionId = null;
335
-
336
280
  this._consumeApi();
337
-
338
- const content = this._createMessage({ ...runContent,
281
+ const content = this._createMessage({
282
+ ...runContent,
339
283
  executionId
340
284
  });
341
-
342
285
  const broker = this.broker;
343
286
  broker.publish('run', 'run.enter', content);
344
287
  broker.publish('run', 'run.start', (0, _messageHelper.cloneContent)(content));
345
-
346
288
  this._consumeRunQ();
347
289
  };
348
-
349
290
  proto.recover = function recover(state) {
350
291
  if (this.isRunning) throw new Error(`cannot recover running activity <${this.id}>`);
351
292
  if (!state) return;
@@ -353,56 +294,43 @@ proto.recover = function recover(state) {
353
294
  this.status = state.status;
354
295
  const exec = this[kExec];
355
296
  exec.executionId = state.executionId;
356
- this[kCounters] = { ...this[kCounters],
297
+ this[kCounters] = {
298
+ ...this[kCounters],
357
299
  ...state.counters
358
300
  };
359
-
360
301
  if (state.execution) {
361
302
  exec.execution = new _ActivityExecution.default(this, this.context).recover(state.execution);
362
303
  }
363
-
364
304
  this.broker.recover(state.broker);
365
305
  return this;
366
306
  };
367
-
368
307
  proto.resume = function resume() {
369
308
  if (this[kConsuming]) {
370
309
  throw new Error(`cannot resume running activity <${this.id}>`);
371
310
  }
372
-
373
311
  if (!this.status) return this.activate();
374
312
  this.stopped = false;
375
-
376
313
  this._consumeApi();
377
-
378
314
  const content = this._createMessage();
379
-
380
315
  this.broker.publish('run', 'run.resume', content, {
381
316
  persistent: false
382
317
  });
383
-
384
318
  this._consumeRunQ();
385
319
  };
386
-
387
320
  proto.discard = function discard(discardContent) {
388
321
  if (!this.status) return this._runDiscard(discardContent);
389
322
  const execution = this[kExec].execution;
390
323
  if (execution && !execution.completed) return execution.discard();
391
-
392
324
  this._deactivateRunConsumers();
393
-
394
325
  const broker = this.broker;
395
326
  broker.getQueue('run-q').purge();
396
327
  broker.publish('run', 'run.discard', (0, _messageHelper.cloneContent)(this[kStateMessage].content));
397
-
398
328
  this._consumeRunQ();
399
329
  };
400
-
401
330
  proto.stop = function stop() {
402
331
  if (!this[kConsuming]) return;
403
332
  return this.getApi().stop();
404
333
  };
405
-
406
334
  proto.next = function next() {
407
335
  if (!this.environment.settings.step) return;
408
336
  const stateMessage = this[kStateMessage];
@@ -413,82 +341,68 @@ proto.next = function next() {
413
341
  stateMessage.ack();
414
342
  return current;
415
343
  };
416
-
417
344
  proto.shake = function shake() {
418
345
  this._shakeOutbound({
419
346
  content: this._createMessage()
420
347
  });
421
348
  };
422
-
423
349
  proto.evaluateOutbound = function evaluateOutbound(fromMessage, discardRestAtTake, callback) {
424
350
  return this[kFlows].outboundEvaluator.evaluate(fromMessage, discardRestAtTake, callback);
425
351
  };
426
-
427
352
  proto.getState = function getState() {
428
353
  const msg = this._createMessage();
429
-
430
354
  const exec = this[kExec];
431
- return { ...msg,
355
+ return {
356
+ ...msg,
432
357
  executionId: exec.executionId,
433
358
  stopped: this.stopped,
434
- behaviour: { ...this.behaviour
359
+ behaviour: {
360
+ ...this.behaviour
435
361
  },
436
362
  counters: this.counters,
437
363
  broker: this.broker.getState(true),
438
364
  execution: exec.execution && exec.execution.getState()
439
365
  };
440
366
  };
441
-
442
367
  proto.getApi = function getApi(message) {
443
368
  const execution = this[kExec].execution;
444
369
  if (execution && !execution.completed) return execution.getApi(message);
445
370
  return (0, _Api.ActivityApi)(this.broker, message || this[kStateMessage]);
446
371
  };
447
-
448
372
  proto.getActivityById = function getActivityById(elementId) {
449
373
  return this.context.getActivityById(elementId);
450
374
  };
451
-
452
375
  proto._runDiscard = function runDiscard(discardContent) {
453
376
  const exec = this[kExec];
454
377
  const executionId = exec.executionId = exec.initExecutionId || (0, _shared.getUniqueId)(this.id);
455
378
  exec.initExecutionId = null;
456
-
457
379
  this._consumeApi();
458
-
459
- const content = this._createMessage({ ...discardContent,
380
+ const content = this._createMessage({
381
+ ...discardContent,
460
382
  executionId
461
383
  });
462
-
463
384
  this.broker.publish('run', 'run.discard', content);
464
-
465
385
  this._consumeRunQ();
466
386
  };
467
-
468
387
  proto._discardRun = function discardRun() {
469
388
  const status = this.status;
470
389
  if (!status) return;
471
390
  const execution = this[kExec].execution;
472
391
  if (execution && !execution.completed) return;
473
-
474
392
  switch (status) {
475
393
  case 'executing':
476
394
  case 'error':
477
395
  case 'discarded':
478
396
  return;
479
397
  }
480
-
481
398
  this._deactivateRunConsumers();
482
-
483
399
  const message = this[kStateMessage];
484
400
  if (this.extensions) this.extensions.deactivate((0, _messageHelper.cloneMessage)(message));
485
401
  const broker = this.broker;
486
402
  broker.getQueue('run-q').purge();
487
403
  broker.publish('run', 'run.discard', (0, _messageHelper.cloneContent)(message.content));
488
-
489
404
  this._consumeRunQ();
490
405
  };
491
-
492
406
  proto._shakeOutbound = function shakeOutbound(sourceMessage) {
493
407
  const message = (0, _messageHelper.cloneMessage)(sourceMessage);
494
408
  message.content.sequence = message.content.sequence || [];
@@ -501,33 +415,27 @@ proto._shakeOutbound = function shakeOutbound(sourceMessage) {
501
415
  persistent: false,
502
416
  type: 'shake'
503
417
  });
504
-
505
418
  if (this[kFlags].isEnd) {
506
419
  return broker.publish('event', 'activity.shake.end', message.content, {
507
420
  persistent: false,
508
421
  type: 'shake'
509
422
  });
510
423
  }
511
-
512
424
  for (const flow of this[kFlows].outboundSequenceFlows) flow.shake(message);
513
425
  };
514
-
515
426
  proto._consumeInbound = function consumeInbound() {
516
427
  if (this.status) return;
517
428
  const inboundQ = this.broker.getQueue('inbound-q');
518
-
519
429
  if (this[kFlags].isParallelJoin) {
520
430
  return inboundQ.consume(this[kMessageHandlers].onInbound, {
521
431
  consumerTag: '_run-on-inbound',
522
432
  prefetch: 1000
523
433
  });
524
434
  }
525
-
526
435
  return inboundQ.consume(this[kMessageHandlers].onInbound, {
527
436
  consumerTag: '_run-on-inbound'
528
437
  });
529
438
  };
530
-
531
439
  proto._onInbound = function onInbound(routingKey, message) {
532
440
  message.ack();
533
441
  const id = this.id;
@@ -535,7 +443,6 @@ proto._onInbound = function onInbound(routingKey, message) {
535
443
  broker.cancel('_run-on-inbound');
536
444
  const content = message.content;
537
445
  const inbound = [(0, _messageHelper.cloneContent)(content)];
538
-
539
446
  switch (routingKey) {
540
447
  case 'association.take':
541
448
  case 'flow.take':
@@ -545,7 +452,6 @@ proto._onInbound = function onInbound(routingKey, message) {
545
452
  message: content.message,
546
453
  inbound
547
454
  });
548
-
549
455
  case 'flow.discard':
550
456
  case 'activity.discard':
551
457
  {
@@ -556,7 +462,6 @@ proto._onInbound = function onInbound(routingKey, message) {
556
462
  discardSequence
557
463
  });
558
464
  }
559
-
560
465
  case 'association.complete':
561
466
  {
562
467
  broker.cancel('_run-on-inbound');
@@ -568,7 +473,6 @@ proto._onInbound = function onInbound(routingKey, message) {
568
473
  }
569
474
  }
570
475
  };
571
-
572
476
  proto._onJoinInbound = function onJoinInbound(routingKey, message) {
573
477
  const {
574
478
  content
@@ -582,12 +486,10 @@ proto._onJoinInbound = function onJoinInbound(routingKey, message) {
582
486
  inboundJoinFlows.push(message);
583
487
  if (idx > -1) return;
584
488
  const allTouched = inboundJoinFlows.length >= inboundTriggers.length;
585
-
586
489
  if (!allTouched) {
587
490
  const remaining = inboundSequenceFlows.filter((inb, i, list) => list.indexOf(inb) === i).length - inboundJoinFlows.length;
588
491
  return this.logger.debug(`<${this.id}> inbound ${message.content.action} from <${message.content.id}>, ${remaining} remaining`);
589
492
  }
590
-
591
493
  const evaluatedInbound = inboundJoinFlows.splice(0);
592
494
  let taken;
593
495
  const inbound = evaluatedInbound.map(im => {
@@ -597,11 +499,9 @@ proto._onJoinInbound = function onJoinInbound(routingKey, message) {
597
499
  });
598
500
  const discardSequence = !taken && evaluatedInbound.reduce((result, im) => {
599
501
  if (!im.content.discardSequence) return result;
600
-
601
502
  for (const sourceId of im.content.discardSequence) {
602
503
  if (result.indexOf(sourceId) === -1) result.push(sourceId);
603
504
  }
604
-
605
505
  return result;
606
506
  }, []);
607
507
  this.broker.cancel('_run-on-inbound');
@@ -613,7 +513,6 @@ proto._onJoinInbound = function onJoinInbound(routingKey, message) {
613
513
  inbound
614
514
  });
615
515
  };
616
-
617
516
  proto._onInboundEvent = function onInboundEvent(routingKey, message) {
618
517
  const {
619
518
  fields,
@@ -622,7 +521,6 @@ proto._onInboundEvent = function onInboundEvent(routingKey, message) {
622
521
  } = message;
623
522
  const id = this.id;
624
523
  const inboundQ = this.broker.getQueue('inbound-q');
625
-
626
524
  switch (routingKey) {
627
525
  case 'activity.enter':
628
526
  case 'activity.discard':
@@ -630,43 +528,35 @@ proto._onInboundEvent = function onInboundEvent(routingKey, message) {
630
528
  if (content.id === this[kFlags].attachedTo) {
631
529
  inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
632
530
  }
633
-
634
531
  break;
635
532
  }
636
-
637
533
  case 'flow.shake':
638
534
  {
639
535
  return this._shakeOutbound(message);
640
536
  }
641
-
642
537
  case 'association.take':
643
538
  case 'flow.take':
644
539
  case 'flow.discard':
645
540
  return inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
646
-
647
541
  case 'association.discard':
648
542
  {
649
543
  this.logger.debug(`<${id}> compensation discarded`);
650
544
  return inboundQ.purge();
651
545
  }
652
-
653
546
  case 'association.complete':
654
547
  {
655
548
  if (!this[kFlags].isForCompensation) break;
656
549
  inboundQ.queueMessage(fields, (0, _messageHelper.cloneContent)(content), properties);
657
550
  const compensationId = `${(0, _shared.brokerSafeId)(id)}_${(0, _shared.brokerSafeId)(content.sequenceId)}`;
658
-
659
551
  this._publishEvent('compensation.start', this._createMessage({
660
552
  executionId: compensationId,
661
553
  placeholder: true
662
554
  }));
663
-
664
555
  this.logger.debug(`<${id}> start compensation with id <${compensationId}>`);
665
556
  return this._consumeInbound();
666
557
  }
667
558
  }
668
559
  };
669
-
670
560
  proto._consumeRunQ = function consumeRunQ() {
671
561
  if (this[kConsuming]) return;
672
562
  this[kConsuming] = true;
@@ -675,31 +565,26 @@ proto._consumeRunQ = function consumeRunQ() {
675
565
  consumerTag: '_activity-run'
676
566
  });
677
567
  };
678
-
679
568
  proto._onRunMessage = function onRunMessage(routingKey, message, messageProperties) {
680
569
  switch (routingKey) {
681
570
  case 'run.outbound.discard':
682
571
  case 'run.outbound.take':
683
572
  case 'run.next':
684
573
  return this._continueRunMessage(routingKey, message, messageProperties);
685
-
686
574
  case 'run.resume':
687
575
  {
688
576
  return this._onResumeMessage(message);
689
577
  }
690
578
  }
691
-
692
579
  const preStatus = this.status;
693
580
  this.status = 'formatting';
694
581
  return this.formatter.format(message, (err, formattedContent, formatted) => {
695
582
  if (err) return this.emitFatal(err, message.content);
696
583
  if (formatted) message.content = formattedContent;
697
584
  this.status = preStatus;
698
-
699
585
  this._continueRunMessage(routingKey, message, messageProperties);
700
586
  });
701
587
  };
702
-
703
588
  proto._continueRunMessage = function continueRunMessage(routingKey, message) {
704
589
  const isRedelivered = message.fields.redelivered;
705
590
  const content = (0, _messageHelper.cloneContent)(message.content);
@@ -707,71 +592,56 @@ proto._continueRunMessage = function continueRunMessage(routingKey, message) {
707
592
  const id = this.id;
708
593
  const step = this.environment.settings.step;
709
594
  this[kStateMessage] = message;
710
-
711
595
  switch (routingKey) {
712
596
  case 'run.enter':
713
597
  {
714
598
  this.logger.debug(`<${id}> enter`, isRedelivered ? 'redelivered' : '');
715
599
  this.status = 'entered';
716
-
717
600
  if (!isRedelivered) {
718
601
  this[kExec].execution = null;
719
602
  if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
720
-
721
603
  this._publishEvent('enter', content, {
722
604
  correlationId
723
605
  });
724
606
  }
725
-
726
607
  break;
727
608
  }
728
-
729
609
  case 'run.discard':
730
610
  {
731
611
  this.logger.debug(`<${id}> discard`, isRedelivered ? 'redelivered' : '');
732
612
  this.status = 'discard';
733
613
  this[kExec].execution = null;
734
614
  if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
735
-
736
615
  if (!isRedelivered) {
737
616
  this.broker.publish('run', 'run.discarded', content, {
738
617
  correlationId
739
618
  });
740
-
741
619
  this._publishEvent('discard', content);
742
620
  }
743
-
744
621
  break;
745
622
  }
746
-
747
623
  case 'run.start':
748
624
  {
749
625
  this.logger.debug(`<${id}> start`, isRedelivered ? 'redelivered' : '');
750
626
  this.status = 'started';
751
-
752
627
  if (!isRedelivered) {
753
628
  this.broker.publish('run', 'run.execute', content, {
754
629
  correlationId
755
630
  });
756
-
757
631
  this._publishEvent('start', content, {
758
632
  correlationId
759
633
  });
760
634
  }
761
-
762
635
  break;
763
636
  }
764
-
765
637
  case 'run.execute.passthrough':
766
638
  {
767
639
  const execution = this.execution;
768
-
769
640
  if (!isRedelivered && execution) {
770
641
  this[kExecuteMessage] = message;
771
642
  return execution.passthrough(message);
772
643
  }
773
644
  }
774
-
775
645
  case 'run.execute':
776
646
  {
777
647
  this.status = 'executing';
@@ -785,7 +655,6 @@ proto._continueRunMessage = function continueRunMessage(routingKey, message) {
785
655
  });
786
656
  return exec.execution.execute(message);
787
657
  }
788
-
789
658
  case 'run.end':
790
659
  {
791
660
  this.logger.debug(`<${id}> end`, isRedelivered ? 'redelivered' : '');
@@ -796,97 +665,79 @@ proto._continueRunMessage = function continueRunMessage(routingKey, message) {
796
665
  this._publishEvent('end', content, {
797
666
  correlationId
798
667
  });
799
-
800
668
  if (!step) message.ack();
801
669
  });
802
670
  }
803
-
804
671
  case 'run.error':
805
672
  {
806
- this._publishEvent('error', { ...content,
673
+ this._publishEvent('error', {
674
+ ...content,
807
675
  error: isRedelivered ? (0, _Errors.makeErrorFromMessage)(message) : content.error
808
676
  }, {
809
677
  correlationId
810
678
  });
811
-
812
679
  break;
813
680
  }
814
-
815
681
  case 'run.discarded':
816
682
  {
817
683
  this.logger.debug(`<${content.executionId} (${id})> discarded`);
818
684
  this[kCounters].discarded++;
819
685
  this.status = 'discarded';
820
686
  content.outbound = undefined;
821
-
822
687
  if (!isRedelivered) {
823
688
  return this._doRunLeave(message, true, () => {
824
689
  if (!step) message.ack();
825
690
  });
826
691
  }
827
-
828
692
  break;
829
693
  }
830
-
831
694
  case 'run.outbound.take':
832
695
  {
833
696
  const flow = this._getOutboundSequenceFlowById(content.flow.id);
834
-
835
697
  message.ack();
836
698
  return flow.take(content.flow);
837
699
  }
838
-
839
700
  case 'run.outbound.discard':
840
701
  {
841
702
  const flow = this._getOutboundSequenceFlowById(content.flow.id);
842
-
843
703
  message.ack();
844
704
  return flow.discard(content.flow);
845
705
  }
846
-
847
706
  case 'run.leave':
848
707
  {
849
708
  this.status = undefined;
850
709
  if (this.extensions) this.extensions.deactivate((0, _messageHelper.cloneMessage)(message));
851
-
852
710
  if (!isRedelivered) {
853
711
  this.broker.publish('run', 'run.next', content, {
854
712
  persistent: false
855
713
  });
856
-
857
714
  this._publishEvent('leave', content, {
858
715
  correlationId
859
716
  });
860
717
  }
861
-
862
718
  break;
863
719
  }
864
-
865
720
  case 'run.next':
866
721
  this._consumeInbound();
867
-
868
722
  break;
869
723
  }
870
-
871
724
  if (!step) message.ack();
872
725
  };
873
-
874
726
  proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
875
727
  const executeMessage = this[kExecuteMessage];
876
- const content = (0, _messageHelper.cloneContent)({ ...executeMessage.content,
728
+ const content = (0, _messageHelper.cloneContent)({
729
+ ...executeMessage.content,
877
730
  ...message.content,
878
731
  executionId: executeMessage.content.executionId,
879
- parent: { ...this.parent
732
+ parent: {
733
+ ...this.parent
880
734
  }
881
735
  });
882
736
  const {
883
737
  correlationId
884
738
  } = message.properties;
885
-
886
739
  this._publishEvent(routingKey, content, message.properties);
887
-
888
740
  const broker = this.broker;
889
-
890
741
  switch (routingKey) {
891
742
  case 'execution.outbound.take':
892
743
  {
@@ -899,7 +750,6 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
899
750
  return this._ackRunExecuteMessage();
900
751
  });
901
752
  }
902
-
903
753
  case 'execution.error':
904
754
  {
905
755
  this.status = 'error';
@@ -911,14 +761,12 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
911
761
  });
912
762
  break;
913
763
  }
914
-
915
764
  case 'execution.discard':
916
765
  this.status = 'discarded';
917
766
  broker.publish('run', 'run.discarded', content, {
918
767
  correlationId
919
768
  });
920
769
  break;
921
-
922
770
  default:
923
771
  {
924
772
  this.status = 'executed';
@@ -927,43 +775,38 @@ proto._onExecutionMessage = function onExecutionMessage(routingKey, message) {
927
775
  });
928
776
  }
929
777
  }
930
-
931
778
  message.ack();
932
-
933
779
  this._ackRunExecuteMessage();
934
780
  };
935
-
936
781
  proto._ackRunExecuteMessage = function ackRunExecuteMessage() {
937
782
  if (this.environment.settings.step) return;
938
783
  const executeMessage = this[kExecuteMessage];
939
784
  this[kExecuteMessage] = null;
940
785
  executeMessage.ack();
941
786
  };
942
-
943
787
  proto._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
944
788
  const {
945
789
  content,
946
790
  properties
947
791
  } = message;
948
792
  const correlationId = properties.correlationId;
949
-
950
793
  if (content.ignoreOutbound) {
951
794
  this.broker.publish('run', 'run.leave', (0, _messageHelper.cloneContent)(content), {
952
795
  correlationId
953
796
  });
954
797
  return onOutbound();
955
798
  }
956
-
957
799
  return this._doOutbound((0, _messageHelper.cloneMessage)(message), isDiscarded, (err, outbound) => {
958
800
  if (err) {
959
- return this._publishEvent('error', { ...content,
801
+ return this._publishEvent('error', {
802
+ ...content,
960
803
  error: err
961
804
  }, {
962
805
  correlationId
963
806
  });
964
807
  }
965
-
966
- this.broker.publish('run', 'run.leave', (0, _messageHelper.cloneContent)(content, { ...(outbound.length && {
808
+ this.broker.publish('run', 'run.leave', (0, _messageHelper.cloneContent)(content, {
809
+ ...(outbound.length && {
967
810
  outbound
968
811
  })
969
812
  }), {
@@ -972,19 +815,15 @@ proto._doRunLeave = function doRunLeave(message, isDiscarded, onOutbound) {
972
815
  onOutbound();
973
816
  });
974
817
  };
975
-
976
818
  proto._doOutbound = function doOutbound(fromMessage, isDiscarded, callback) {
977
819
  const outboundSequenceFlows = this[kFlows].outboundSequenceFlows;
978
820
  if (!outboundSequenceFlows.length) return callback(null, []);
979
821
  const fromContent = fromMessage.content;
980
822
  let discardSequence = fromContent.discardSequence;
981
-
982
823
  if (isDiscarded && !discardSequence && this[kFlags].attachedTo && fromContent.inbound && fromContent.inbound[0]) {
983
824
  discardSequence = [fromContent.inbound[0].id];
984
825
  }
985
-
986
826
  let outboundFlows;
987
-
988
827
  if (isDiscarded) {
989
828
  outboundFlows = outboundSequenceFlows.map(flow => formatFlowAction(flow, {
990
829
  action: 'discard'
@@ -992,22 +831,16 @@ proto._doOutbound = function doOutbound(fromMessage, isDiscarded, callback) {
992
831
  } else if (fromContent.outbound && fromContent.outbound.length) {
993
832
  outboundFlows = outboundSequenceFlows.map(flow => formatFlowAction(flow, fromContent.outbound.filter(f => f.id === flow.id).pop()));
994
833
  }
995
-
996
834
  if (outboundFlows) {
997
835
  this._doRunOutbound(outboundFlows, fromContent, discardSequence);
998
-
999
836
  return callback(null, outboundFlows);
1000
837
  }
1001
-
1002
838
  return this.evaluateOutbound(fromMessage, fromContent.outboundTakeOne, (err, evaluatedOutbound) => {
1003
839
  if (err) return callback(new _Errors.ActivityError(err.message, fromMessage, err));
1004
-
1005
840
  const outbound = this._doRunOutbound(evaluatedOutbound, fromContent, discardSequence);
1006
-
1007
841
  return callback(null, outbound);
1008
842
  });
1009
843
  };
1010
-
1011
844
  proto._doRunOutbound = function doRunOutbound(outboundList, content, discardSequence) {
1012
845
  for (const outboundFlow of outboundList) {
1013
846
  const {
@@ -1015,7 +848,8 @@ proto._doRunOutbound = function doRunOutbound(outboundList, content, discardSequ
1015
848
  action
1016
849
  } = outboundFlow;
1017
850
  this.broker.publish('run', 'run.outbound.' + action, (0, _messageHelper.cloneContent)(content, {
1018
- flow: { ...outboundFlow,
851
+ flow: {
852
+ ...outboundFlow,
1019
853
  sequenceId: (0, _shared.getUniqueId)(`${flowId}_${action}`),
1020
854
  ...(discardSequence && {
1021
855
  discardSequence: discardSequence.slice()
@@ -1023,16 +857,13 @@ proto._doRunOutbound = function doRunOutbound(outboundList, content, discardSequ
1023
857
  }
1024
858
  }));
1025
859
  }
1026
-
1027
860
  return outboundList;
1028
861
  };
1029
-
1030
862
  proto._onResumeMessage = function onResumeMessage(message) {
1031
863
  message.ack();
1032
864
  const stateMessage = this[kStateMessage];
1033
865
  const fields = stateMessage.fields;
1034
866
  if (!fields.redelivered) return;
1035
-
1036
867
  switch (fields.routingKey) {
1037
868
  case 'run.enter':
1038
869
  case 'run.start':
@@ -1040,26 +871,23 @@ proto._onResumeMessage = function onResumeMessage(message) {
1040
871
  case 'run.end':
1041
872
  case 'run.leave':
1042
873
  break;
1043
-
1044
874
  default:
1045
875
  return;
1046
876
  }
1047
-
1048
877
  if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(stateMessage));
1049
878
  this.logger.debug(`<${this.id}> resume from ${message.content.status}`);
1050
879
  return this.broker.publish('run', fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
1051
880
  };
1052
-
1053
881
  proto._publishEvent = function publishEvent(state, content, properties = {}) {
1054
882
  this.broker.publish('event', `activity.${state}`, (0, _messageHelper.cloneContent)(content, {
1055
883
  state
1056
- }), { ...properties,
884
+ }), {
885
+ ...properties,
1057
886
  type: state,
1058
887
  mandatory: state === 'error',
1059
888
  persistent: 'persistent' in properties ? properties.persistent : state !== 'stop'
1060
889
  });
1061
890
  };
1062
-
1063
891
  proto._onStop = function onStop(message) {
1064
892
  const running = this[kConsuming];
1065
893
  this.stopped = true;
@@ -1070,14 +898,11 @@ proto._onStop = function onStop(message) {
1070
898
  broker.cancel('_activity-execution');
1071
899
  broker.cancel('_run-on-inbound');
1072
900
  broker.cancel('_format-consumer');
1073
-
1074
901
  if (running) {
1075
- if (this.extensions) this.extensions.deactivate(message ? (0, _messageHelper.cloneMessage)(message) : this._createMessage());
1076
-
902
+ if (this.extensions) this.extensions.deactivate((0, _messageHelper.cloneMessage)(message));
1077
903
  this._publishEvent('stop', this._createMessage());
1078
904
  }
1079
905
  };
1080
-
1081
906
  proto._consumeApi = function consumeApi() {
1082
907
  const executionId = this[kExec].executionId;
1083
908
  if (!executionId) return;
@@ -1089,31 +914,28 @@ proto._consumeApi = function consumeApi() {
1089
914
  priority: 100
1090
915
  });
1091
916
  };
1092
-
1093
917
  proto._onApiMessage = function onApiMessage(routingKey, message) {
1094
918
  switch (message.properties.type) {
1095
919
  case 'discard':
1096
920
  {
1097
921
  return this._discardRun(message);
1098
922
  }
1099
-
1100
923
  case 'stop':
1101
924
  {
1102
925
  return this._onStop(message);
1103
926
  }
1104
-
1105
927
  case 'shake':
1106
928
  {
1107
929
  return this._shakeOutbound(message);
1108
930
  }
1109
931
  }
1110
932
  };
1111
-
1112
933
  proto._createMessage = function createMessage(override) {
1113
934
  const name = this.name,
1114
- status = this.status,
1115
- parent = this.parent;
1116
- const result = { ...override,
935
+ status = this.status,
936
+ parent = this.parent;
937
+ const result = {
938
+ ...override,
1117
939
  id: this.id,
1118
940
  type: this.type,
1119
941
  ...(name && {
@@ -1126,18 +948,14 @@ proto._createMessage = function createMessage(override) {
1126
948
  parent: (0, _messageHelper.cloneParent)(parent)
1127
949
  })
1128
950
  };
1129
-
1130
951
  for (const [flag, value] of Object.entries(this[kFlags])) {
1131
952
  if (value) result[flag] = value;
1132
953
  }
1133
-
1134
954
  return result;
1135
955
  };
1136
-
1137
956
  proto._getOutboundSequenceFlowById = function getOutboundSequenceFlowById(flowId) {
1138
957
  return this[kFlows].outboundSequenceFlows.find(flow => flow.id === flowId);
1139
958
  };
1140
-
1141
959
  proto._deactivateRunConsumers = function _deactivateRunConsumers() {
1142
960
  const broker = this.broker;
1143
961
  broker.cancel('_activity-api');
@@ -1145,7 +963,6 @@ proto._deactivateRunConsumers = function _deactivateRunConsumers() {
1145
963
  broker.cancel('_activity-execution');
1146
964
  this[kConsuming] = false;
1147
965
  };
1148
-
1149
966
  function OutboundEvaluator(activity, outboundFlows) {
1150
967
  this.activity = activity;
1151
968
  this.broker = activity.broker;
@@ -1153,19 +970,16 @@ function OutboundEvaluator(activity, outboundFlows) {
1153
970
  const defaultFlowIdx = flows.findIndex(({
1154
971
  isDefault
1155
972
  }) => isDefault);
1156
-
1157
973
  if (defaultFlowIdx > -1) {
1158
974
  const [defaultFlow] = flows.splice(defaultFlowIdx, 1);
1159
975
  flows.push(defaultFlow);
1160
976
  }
1161
-
1162
977
  this.defaultFlowIdx = outboundFlows.findIndex(({
1163
978
  isDefault
1164
979
  }) => isDefault);
1165
980
  this._onEvaluated = this.onEvaluated.bind(this);
1166
981
  this.evaluateArgs = {};
1167
982
  }
1168
-
1169
983
  OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRestAtTake, callback) {
1170
984
  const outboundFlows = this.outboundFlows;
1171
985
  const args = this.evaluateArgs = {
@@ -1184,7 +998,6 @@ OutboundEvaluator.prototype.evaluate = function evaluate(fromMessage, discardRes
1184
998
  });
1185
999
  return this.evaluateFlow(flows.shift());
1186
1000
  };
1187
-
1188
1001
  OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, message) {
1189
1002
  const content = message.content;
1190
1003
  const {
@@ -1193,45 +1006,35 @@ OutboundEvaluator.prototype.onEvaluated = function onEvaluated(routingKey, messa
1193
1006
  evaluationId
1194
1007
  } = message.content;
1195
1008
  const args = this.evaluateArgs;
1196
-
1197
1009
  if (action === 'take') {
1198
1010
  args.takenCount++;
1199
1011
  args.conditionMet = true;
1200
1012
  }
1201
-
1202
1013
  args.result[flowId] = content;
1203
-
1204
1014
  if ('result' in content) {
1205
1015
  this.activity.logger.debug(`<${evaluationId} (${this.activity.id})> flow <${flowId}> evaluated to: ${!!content.result}`);
1206
1016
  }
1207
-
1208
1017
  let nextFlow = args.flows.shift();
1209
1018
  if (!nextFlow) return this.completed();
1210
-
1211
1019
  if (args.discardRestAtTake && args.conditionMet) {
1212
1020
  do {
1213
1021
  args.result[nextFlow.id] = formatFlowAction(nextFlow, {
1214
1022
  action: 'discard'
1215
1023
  });
1216
1024
  } while (nextFlow = args.flows.shift());
1217
-
1218
1025
  return this.completed();
1219
1026
  }
1220
-
1221
1027
  if (args.conditionMet && nextFlow.isDefault) {
1222
1028
  args.result[nextFlow.id] = formatFlowAction(nextFlow, {
1223
1029
  action: 'discard'
1224
1030
  });
1225
1031
  return this.completed();
1226
1032
  }
1227
-
1228
1033
  message.ack();
1229
1034
  this.evaluateFlow(nextFlow);
1230
1035
  };
1231
-
1232
1036
  OutboundEvaluator.prototype.evaluateFlow = function evaluateFlow(flow) {
1233
1037
  const broker = this.broker;
1234
-
1235
1038
  if (flow.isDefault) {
1236
1039
  return broker.publish('execution', 'evaluate.flow.take', formatFlowAction(flow, {
1237
1040
  action: 'take'
@@ -1239,9 +1042,7 @@ OutboundEvaluator.prototype.evaluateFlow = function evaluateFlow(flow) {
1239
1042
  persistent: false
1240
1043
  });
1241
1044
  }
1242
-
1243
1045
  const flowCondition = flow.getCondition();
1244
-
1245
1046
  if (!flowCondition) {
1246
1047
  return broker.publish('execution', 'evaluate.flow.take', formatFlowAction(flow, {
1247
1048
  action: 'take'
@@ -1249,7 +1050,6 @@ OutboundEvaluator.prototype.evaluateFlow = function evaluateFlow(flow) {
1249
1050
  persistent: false
1250
1051
  });
1251
1052
  }
1252
-
1253
1053
  const {
1254
1054
  fromMessage,
1255
1055
  evaluationId
@@ -1266,7 +1066,6 @@ OutboundEvaluator.prototype.evaluateFlow = function evaluateFlow(flow) {
1266
1066
  });
1267
1067
  });
1268
1068
  };
1269
-
1270
1069
  OutboundEvaluator.prototype.completed = function completed(err) {
1271
1070
  const {
1272
1071
  callback,
@@ -1277,28 +1076,25 @@ OutboundEvaluator.prototype.completed = function completed(err) {
1277
1076
  } = this.evaluateArgs;
1278
1077
  this.broker.cancel(`_flow-evaluation-${evaluationId}`);
1279
1078
  if (err) return callback(err);
1280
-
1281
1079
  if (!takenCount && this.outboundFlows.length) {
1282
1080
  const nonTakenError = new _Errors.ActivityError(`<${this.activity.id}> no conditional flow taken`, fromMessage);
1283
1081
  return callback(nonTakenError);
1284
1082
  }
1285
-
1286
1083
  const message = fromMessage.content.message;
1287
1084
  const evaluationResult = [];
1288
-
1289
1085
  for (const flow of Object.values(result)) {
1290
- evaluationResult.push({ ...flow,
1086
+ evaluationResult.push({
1087
+ ...flow,
1291
1088
  ...(message !== undefined && {
1292
1089
  message
1293
1090
  })
1294
1091
  });
1295
1092
  }
1296
-
1297
1093
  return callback(null, evaluationResult);
1298
1094
  };
1299
-
1300
1095
  function formatFlowAction(flow, options) {
1301
- return { ...options,
1096
+ return {
1097
+ ...options,
1302
1098
  id: flow.id,
1303
1099
  action: options.action,
1304
1100
  ...(flow.isDefault && {