bpmn-elements 13.1.1 → 13.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -2
- package/dist/Context.js +36 -2
- package/dist/definition/DefinitionExecution.js +2 -1
- package/dist/getPropertyValue.js +1 -2
- package/dist/index.js +1 -1
- package/package.json +14 -13
- package/src/Api.js +18 -20
- package/src/Context.js +49 -7
- package/src/Environment.js +10 -20
- package/src/EventBroker.js +21 -27
- package/src/MessageFormatter.js +23 -19
- package/src/Tracker.js +4 -4
- package/src/activity/Activity.js +141 -109
- package/src/activity/ActivityExecution.js +38 -29
- package/src/activity/Dummy.js +3 -3
- package/src/activity/Escalation.js +4 -4
- package/src/activity/ExecutionScope.js +4 -4
- package/src/activity/Message.js +5 -5
- package/src/activity/Signal.js +5 -5
- package/src/definition/Definition.js +44 -36
- package/src/definition/DefinitionExecution.js +98 -66
- package/src/error/BpmnError.js +3 -3
- package/src/error/Errors.js +19 -14
- package/src/eventDefinitions/CancelEventDefinition.js +16 -11
- package/src/eventDefinitions/CompensateEventDefinition.js +28 -23
- package/src/eventDefinitions/ConditionalEventDefinition.js +42 -23
- package/src/eventDefinitions/ErrorEventDefinition.js +47 -34
- package/src/eventDefinitions/EscalationEventDefinition.js +21 -20
- package/src/eventDefinitions/EventDefinitionExecution.js +6 -6
- package/src/eventDefinitions/LinkEventDefinition.js +28 -22
- package/src/eventDefinitions/MessageEventDefinition.js +47 -36
- package/src/eventDefinitions/SignalEventDefinition.js +42 -31
- package/src/eventDefinitions/TerminateEventDefinition.js +4 -4
- package/src/eventDefinitions/TimerEventDefinition.js +41 -29
- package/src/events/BoundaryEvent.js +81 -46
- package/src/events/EndEvent.js +2 -2
- package/src/events/IntermediateCatchEvent.js +8 -4
- package/src/events/IntermediateThrowEvent.js +2 -2
- package/src/events/StartEvent.js +29 -18
- package/src/flows/Association.js +11 -11
- package/src/flows/MessageFlow.js +16 -14
- package/src/flows/SequenceFlow.js +22 -20
- package/src/gateways/EventBasedGateway.js +7 -6
- package/src/gateways/ExclusiveGateway.js +4 -4
- package/src/gateways/InclusiveGateway.js +3 -3
- package/src/gateways/ParallelGateway.js +4 -4
- package/src/getPropertyValue.js +3 -6
- package/src/index.js +1 -1
- package/src/io/BpmnIO.js +5 -6
- package/src/io/EnvironmentDataObject.js +2 -3
- package/src/io/EnvironmentDataStore.js +2 -2
- package/src/io/EnvironmentDataStoreReference.js +2 -2
- package/src/io/InputOutputSpecification.js +60 -54
- package/src/io/Properties.js +45 -33
- package/src/iso-duration.js +9 -13
- package/src/messageHelper.js +16 -23
- package/src/process/Lane.js +3 -3
- package/src/process/Process.js +40 -34
- package/src/process/ProcessExecution.js +122 -78
- package/src/tasks/CallActivity.js +109 -57
- package/src/tasks/LoopCharacteristics.js +30 -18
- package/src/tasks/ReceiveTask.js +59 -38
- package/src/tasks/ScriptTask.js +17 -8
- package/src/tasks/ServiceTask.js +16 -9
- package/src/tasks/SignalTask.js +47 -28
- package/src/tasks/StandardLoopCharacteristics.js +3 -3
- package/src/tasks/SubProcess.js +9 -8
- package/src/tasks/Task.js +4 -3
- package/src/tasks/Transaction.js +1 -1
- package/types/index.d.ts +6 -6
- package/types/types.d.ts +39 -35
- package/CHANGELOG.md +0 -455
- package/src/ExtensionsMapper.js +0 -42
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import getPropertyValue from '../getPropertyValue.js';
|
|
2
|
-
import {DefinitionApi} from '../Api.js';
|
|
3
|
-
import {brokerSafeId} from '../shared.js';
|
|
4
|
-
import {cloneContent, cloneMessage, pushParent, cloneParent} from '../messageHelper.js';
|
|
2
|
+
import { DefinitionApi } from '../Api.js';
|
|
3
|
+
import { brokerSafeId } from '../shared.js';
|
|
4
|
+
import { cloneContent, cloneMessage, pushParent, cloneParent } from '../messageHelper.js';
|
|
5
5
|
|
|
6
6
|
const kActivated = Symbol.for('activated');
|
|
7
7
|
const kProcessesQ = Symbol.for('processesQ');
|
|
@@ -20,7 +20,7 @@ export default function DefinitionExecution(definition, context) {
|
|
|
20
20
|
this.id = definition.id;
|
|
21
21
|
this.type = definition.type;
|
|
22
22
|
this.broker = broker;
|
|
23
|
-
const environment = this.environment = definition.environment;
|
|
23
|
+
const environment = (this.environment = definition.environment);
|
|
24
24
|
this.context = context;
|
|
25
25
|
|
|
26
26
|
const processes = context.getProcesses();
|
|
@@ -41,7 +41,7 @@ export default function DefinitionExecution(definition, context) {
|
|
|
41
41
|
postponed: [],
|
|
42
42
|
};
|
|
43
43
|
|
|
44
|
-
broker.assertExchange('execution', 'topic', {autoDelete: false, durable: true});
|
|
44
|
+
broker.assertExchange('execution', 'topic', { autoDelete: false, durable: true });
|
|
45
45
|
|
|
46
46
|
this.executionId = undefined;
|
|
47
47
|
this[kCompleted] = false;
|
|
@@ -122,7 +122,7 @@ Object.defineProperties(DefinitionExecution.prototype, {
|
|
|
122
122
|
DefinitionExecution.prototype.execute = function execute(executeMessage) {
|
|
123
123
|
if (!executeMessage) throw new Error('Definition execution requires message');
|
|
124
124
|
const content = executeMessage.content;
|
|
125
|
-
const executionId = this.executionId = content.executionId;
|
|
125
|
+
const executionId = (this.executionId = content.executionId);
|
|
126
126
|
if (!executionId) throw new Error('Definition execution requires execution id');
|
|
127
127
|
|
|
128
128
|
this[kExecuteMessage] = cloneMessage(executeMessage, {
|
|
@@ -132,13 +132,13 @@ DefinitionExecution.prototype.execute = function execute(executeMessage) {
|
|
|
132
132
|
|
|
133
133
|
this[kStopped] = false;
|
|
134
134
|
|
|
135
|
-
this[kProcessesQ] = this.broker.assertQueue(`execute-${executionId}-q`, {durable: true, autoDelete: false});
|
|
135
|
+
this[kProcessesQ] = this.broker.assertQueue(`execute-${executionId}-q`, { durable: true, autoDelete: false });
|
|
136
136
|
|
|
137
137
|
if (executeMessage.fields.redelivered) {
|
|
138
138
|
return this.resume();
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
const {running, executable} = this[kProcesses];
|
|
141
|
+
const { running, executable } = this[kProcesses];
|
|
142
142
|
|
|
143
143
|
if (content.processId) {
|
|
144
144
|
const startWithProcess = this.getProcessById(content.processId);
|
|
@@ -160,7 +160,7 @@ DefinitionExecution.prototype.resume = function resume() {
|
|
|
160
160
|
|
|
161
161
|
if (this[kCompleted]) return this._complete('completed');
|
|
162
162
|
|
|
163
|
-
const {running, postponed} = this[kProcesses];
|
|
163
|
+
const { running, postponed } = this[kProcesses];
|
|
164
164
|
this._activate(running);
|
|
165
165
|
postponed.splice(0);
|
|
166
166
|
this[kProcessesQ].consume(this[kMessageHandlers].onProcessMessage, {
|
|
@@ -210,7 +210,7 @@ DefinitionExecution.prototype.stop = function stop() {
|
|
|
210
210
|
};
|
|
211
211
|
|
|
212
212
|
DefinitionExecution.prototype.getProcesses = function getProcesses() {
|
|
213
|
-
const {running, processes} = this[kProcesses];
|
|
213
|
+
const { running, processes } = this[kProcesses];
|
|
214
214
|
const result = running.slice();
|
|
215
215
|
for (const bp of processes) {
|
|
216
216
|
if (!result.find((runningBp) => bp.id === runningBp.id)) result.push(bp);
|
|
@@ -251,7 +251,7 @@ DefinitionExecution.prototype.getState = function getState() {
|
|
|
251
251
|
};
|
|
252
252
|
|
|
253
253
|
DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
|
|
254
|
-
if (!apiMessage) apiMessage = this[kExecuteMessage] || {content: this._createMessage()};
|
|
254
|
+
if (!apiMessage) apiMessage = this[kExecuteMessage] || { content: this._createMessage() };
|
|
255
255
|
|
|
256
256
|
const content = apiMessage.content;
|
|
257
257
|
if (content.executionId !== this.executionId) {
|
|
@@ -282,13 +282,13 @@ DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
|
|
|
282
282
|
};
|
|
283
283
|
|
|
284
284
|
DefinitionExecution.prototype._start = function start() {
|
|
285
|
-
const {ids, executable, postponed} = this[kProcesses];
|
|
285
|
+
const { ids, executable, postponed } = this[kProcesses];
|
|
286
286
|
if (!ids.length) {
|
|
287
287
|
return this._complete('completed');
|
|
288
288
|
}
|
|
289
289
|
|
|
290
290
|
if (!executable.length) {
|
|
291
|
-
return this._complete('error', {error: new Error('No executable process')});
|
|
291
|
+
return this._complete('error', { error: new Error('No executable process') });
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
this[kStatus] = 'start';
|
|
@@ -321,10 +321,10 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
|
321
321
|
consumerTag: '_definition-outbound-message-consumer',
|
|
322
322
|
});
|
|
323
323
|
|
|
324
|
-
const delegateEventQ = broker.assertQueue('_delegate-event-q', {autoDelete: false, durable: false});
|
|
325
|
-
delegateEventQ.consume(handlers.onDelegateMessage, {noAck: true, consumerTag: '_definition-signal-consumer'});
|
|
326
|
-
broker.bindQueue('_delegate-event-q', 'event', 'activity.signal', {priority: 200});
|
|
327
|
-
broker.bindQueue('_delegate-event-q', 'event', 'activity.message', {priority: 200});
|
|
324
|
+
const delegateEventQ = broker.assertQueue('_delegate-event-q', { autoDelete: false, durable: false });
|
|
325
|
+
delegateEventQ.consume(handlers.onDelegateMessage, { noAck: true, consumerTag: '_definition-signal-consumer' });
|
|
326
|
+
broker.bindQueue('_delegate-event-q', 'event', 'activity.signal', { priority: 200 });
|
|
327
|
+
broker.bindQueue('_delegate-event-q', 'event', 'activity.message', { priority: 200 });
|
|
328
328
|
|
|
329
329
|
broker.subscribeTmp('event', 'activity.call', handlers.onCallActivity, {
|
|
330
330
|
noAck: true,
|
|
@@ -346,7 +346,7 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
|
346
346
|
DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
347
347
|
const message = cloneMessage(originalMessage);
|
|
348
348
|
const content = message.content;
|
|
349
|
-
const parent = content.parent = content.parent || {};
|
|
349
|
+
const parent = (content.parent = content.parent || {});
|
|
350
350
|
|
|
351
351
|
const isDirectChild = this[kProcesses].ids.indexOf(content.id) > -1;
|
|
352
352
|
if (isDirectChild) {
|
|
@@ -355,7 +355,7 @@ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey,
|
|
|
355
355
|
content.parent = pushParent(parent, this);
|
|
356
356
|
}
|
|
357
357
|
|
|
358
|
-
this.broker.publish('event', routingKey, content, {...message.properties, mandatory: false});
|
|
358
|
+
this.broker.publish('event', routingKey, content, { ...message.properties, mandatory: false });
|
|
359
359
|
if (!isDirectChild) return;
|
|
360
360
|
|
|
361
361
|
this[kProcessesQ].queueMessage(message.fields, cloneContent(content), message.properties);
|
|
@@ -379,7 +379,7 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
|
|
|
379
379
|
DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
380
380
|
const content = message.content;
|
|
381
381
|
const isRedelivered = message.fields.redelivered;
|
|
382
|
-
const {id: childId, inbound} = content;
|
|
382
|
+
const { id: childId, inbound } = content;
|
|
383
383
|
|
|
384
384
|
if (isRedelivered && message.properties.persistent === false) return;
|
|
385
385
|
|
|
@@ -402,7 +402,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
402
402
|
case 'process.discarded': {
|
|
403
403
|
if (inbound && inbound.length) {
|
|
404
404
|
const calledFrom = inbound[0];
|
|
405
|
-
this._getProcessApi({content: calledFrom}).cancel({
|
|
405
|
+
this._getProcessApi({ content: calledFrom }).cancel({
|
|
406
406
|
executionId: calledFrom.executionId,
|
|
407
407
|
});
|
|
408
408
|
}
|
|
@@ -412,9 +412,9 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
412
412
|
if (inbound && inbound.length) {
|
|
413
413
|
const calledFrom = inbound[0];
|
|
414
414
|
|
|
415
|
-
this._getProcessApi({content: calledFrom}).signal({
|
|
415
|
+
this._getProcessApi({ content: calledFrom }).signal({
|
|
416
416
|
executionId: calledFrom.executionId,
|
|
417
|
-
output: {...content.output},
|
|
417
|
+
output: { ...content.output },
|
|
418
418
|
});
|
|
419
419
|
} else {
|
|
420
420
|
Object.assign(this.environment.output, content.output);
|
|
@@ -425,16 +425,22 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
425
425
|
if (inbound && inbound.length) {
|
|
426
426
|
const calledFrom = inbound[0];
|
|
427
427
|
|
|
428
|
-
this._getProcessApi({content: calledFrom}).sendApiMessage(
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
428
|
+
this._getProcessApi({ content: calledFrom }).sendApiMessage(
|
|
429
|
+
'error',
|
|
430
|
+
{
|
|
431
|
+
executionId: calledFrom.executionId,
|
|
432
|
+
error: content.error,
|
|
433
|
+
},
|
|
434
|
+
{ mandatory: true, type: 'error' },
|
|
435
|
+
);
|
|
432
436
|
} else {
|
|
433
437
|
for (const bp of this[kProcesses].running.slice()) {
|
|
434
438
|
if (bp.id !== childId) bp.stop();
|
|
435
439
|
}
|
|
436
440
|
|
|
437
|
-
this.
|
|
441
|
+
Object.assign(this.environment.output, content.output);
|
|
442
|
+
|
|
443
|
+
this._complete('error', { error: content.error });
|
|
438
444
|
}
|
|
439
445
|
break;
|
|
440
446
|
}
|
|
@@ -457,7 +463,8 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
|
|
|
457
463
|
this._stateChangeMessage(message, false);
|
|
458
464
|
if (message.fields.redelivered) return message.ack();
|
|
459
465
|
|
|
460
|
-
const {id, executionId, type, inbound} = message.content;
|
|
466
|
+
const { id, executionId, type, inbound } = message.content;
|
|
467
|
+
message.ack();
|
|
461
468
|
this._debug(`left <${executionId} (${id})> (${type}), pending runs ${this.postponedCount}`);
|
|
462
469
|
|
|
463
470
|
if (inbound && inbound.length) {
|
|
@@ -466,7 +473,6 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
|
|
|
466
473
|
}
|
|
467
474
|
|
|
468
475
|
if (!this.postponedCount) {
|
|
469
|
-
message.ack();
|
|
470
476
|
this._complete('completed');
|
|
471
477
|
}
|
|
472
478
|
};
|
|
@@ -479,9 +485,14 @@ DefinitionExecution.prototype._onStopped = function onStopped(message) {
|
|
|
479
485
|
this._deactivate();
|
|
480
486
|
|
|
481
487
|
this[kStopped] = true;
|
|
482
|
-
return this.broker.publish(
|
|
483
|
-
|
|
484
|
-
|
|
488
|
+
return this.broker.publish(
|
|
489
|
+
'execution',
|
|
490
|
+
`execution.stopped.${this.executionId}`,
|
|
491
|
+
cloneContent(this[kExecuteMessage].content, {
|
|
492
|
+
...message.content,
|
|
493
|
+
}),
|
|
494
|
+
{ type: 'stopped', persistent: false },
|
|
495
|
+
);
|
|
485
496
|
};
|
|
486
497
|
|
|
487
498
|
DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
@@ -490,7 +501,7 @@ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey,
|
|
|
490
501
|
|
|
491
502
|
if (delegate && this.id === message.content.id) {
|
|
492
503
|
const referenceId = getPropertyValue(message, 'content.message.id');
|
|
493
|
-
this._startProcessesByMessage({referenceId, referenceType: messageType});
|
|
504
|
+
this._startProcessesByMessage({ referenceId, referenceType: messageType });
|
|
494
505
|
}
|
|
495
506
|
|
|
496
507
|
if (delegate) {
|
|
@@ -502,12 +513,12 @@ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey,
|
|
|
502
513
|
if (this.executionId !== message.content.executionId) return;
|
|
503
514
|
|
|
504
515
|
if (messageType === 'stop') {
|
|
505
|
-
this[kProcessesQ].queueMessage({routingKey: 'execution.stop'}, cloneContent(message.content), {persistent: false});
|
|
516
|
+
this[kProcessesQ].queueMessage({ routingKey: 'execution.stop' }, cloneContent(message.content), { persistent: false });
|
|
506
517
|
}
|
|
507
518
|
};
|
|
508
519
|
|
|
509
520
|
DefinitionExecution.prototype._startProcessesByMessage = function startProcessesByMessage(reference) {
|
|
510
|
-
const {processes: bps, running} = this[kProcesses];
|
|
521
|
+
const { processes: bps, running } = this[kProcesses];
|
|
511
522
|
if (bps.length < 2) return;
|
|
512
523
|
|
|
513
524
|
for (const bp of bps) {
|
|
@@ -537,9 +548,12 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
|
|
|
537
548
|
|
|
538
549
|
DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(routingKey, message) {
|
|
539
550
|
const content = message.content;
|
|
540
|
-
const {target, source} = content;
|
|
551
|
+
const { target, source } = content;
|
|
541
552
|
|
|
542
|
-
this._debug(
|
|
553
|
+
this._debug(
|
|
554
|
+
`conveying message from <${source.processId}.${source.id}> to`,
|
|
555
|
+
target.id ? `<${target.processId}.${target.id}>` : `<${target.processId}>`,
|
|
556
|
+
);
|
|
543
557
|
|
|
544
558
|
const targetProcesses = this.getProcessesById(target.processId);
|
|
545
559
|
if (!targetProcesses.length) return;
|
|
@@ -567,7 +581,7 @@ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(ro
|
|
|
567
581
|
|
|
568
582
|
DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingKey, message) {
|
|
569
583
|
const content = message.content;
|
|
570
|
-
const {calledElement, id: fromId, executionId: fromExecutionId, name: fromName, parent: fromParent} = content;
|
|
584
|
+
const { calledElement, id: fromId, executionId: fromExecutionId, name: fromName, parent: fromParent } = content;
|
|
571
585
|
if (!calledElement) return;
|
|
572
586
|
|
|
573
587
|
const bpExecutionId = `${brokerSafeId(calledElement)}_${fromExecutionId}`;
|
|
@@ -593,11 +607,11 @@ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingK
|
|
|
593
607
|
this._activateProcess(targetProcess);
|
|
594
608
|
this[kProcesses].running.push(targetProcess);
|
|
595
609
|
targetProcess.init(bpExecutionId);
|
|
596
|
-
targetProcess.run({inbound: [cloneContent(content)]});
|
|
610
|
+
targetProcess.run({ inbound: [cloneContent(content)] });
|
|
597
611
|
};
|
|
598
612
|
|
|
599
613
|
DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
|
|
600
|
-
const {calledElement, id: fromId, executionId: fromExecutionId, parent: fromParent} = message.content;
|
|
614
|
+
const { calledElement, id: fromId, executionId: fromExecutionId, parent: fromParent } = message.content;
|
|
601
615
|
if (!calledElement) return;
|
|
602
616
|
|
|
603
617
|
const bpExecutionId = `${brokerSafeId(calledElement)}_${fromExecutionId}`;
|
|
@@ -607,12 +621,14 @@ DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActiv
|
|
|
607
621
|
this._debug(`cancel call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
608
622
|
|
|
609
623
|
if (!targetProcess.isRunning) {
|
|
610
|
-
targetProcess
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
624
|
+
targetProcess
|
|
625
|
+
.getApi({
|
|
626
|
+
content: {
|
|
627
|
+
id: targetProcess.id,
|
|
628
|
+
executionId: targetProcess.executionId,
|
|
629
|
+
},
|
|
630
|
+
})
|
|
631
|
+
.discard();
|
|
616
632
|
} else {
|
|
617
633
|
targetProcess.getApi().discard();
|
|
618
634
|
}
|
|
@@ -626,22 +642,33 @@ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(ro
|
|
|
626
642
|
const reference = this.context.getActivityById(delegateMessage.id);
|
|
627
643
|
const message = reference && reference.resolve(executeMessage);
|
|
628
644
|
|
|
629
|
-
this._debug(
|
|
645
|
+
this._debug(
|
|
646
|
+
`<${reference ? `${messageType} ${delegateMessage.id}>` : `anonymous ${messageType}`} event received from <${content.parent.id}.${content.id}>. Delegating.`,
|
|
647
|
+
);
|
|
630
648
|
|
|
631
|
-
this.getApi().sendApiMessage(
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
649
|
+
this.getApi().sendApiMessage(
|
|
650
|
+
messageType,
|
|
651
|
+
{
|
|
652
|
+
source: {
|
|
653
|
+
id: content.id,
|
|
654
|
+
executionId: content.executionId,
|
|
655
|
+
type: content.type,
|
|
656
|
+
parent: cloneParent(content.parent),
|
|
657
|
+
},
|
|
658
|
+
message,
|
|
659
|
+
originalMessage: content.message,
|
|
637
660
|
},
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
}, {delegate: true, type: messageType});
|
|
661
|
+
{ delegate: true, type: messageType },
|
|
662
|
+
);
|
|
641
663
|
|
|
642
|
-
this.broker.publish(
|
|
643
|
-
|
|
644
|
-
|
|
664
|
+
this.broker.publish(
|
|
665
|
+
'event',
|
|
666
|
+
`definition.${messageType}`,
|
|
667
|
+
this._createMessage({
|
|
668
|
+
message: message && cloneContent(message),
|
|
669
|
+
}),
|
|
670
|
+
{ type: messageType },
|
|
671
|
+
);
|
|
645
672
|
};
|
|
646
673
|
|
|
647
674
|
DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
|
|
@@ -660,12 +687,17 @@ DefinitionExecution.prototype._complete = function complete(completionType, cont
|
|
|
660
687
|
this[kStatus] = completionType;
|
|
661
688
|
this.broker.deleteQueue(this[kProcessesQ].name);
|
|
662
689
|
|
|
663
|
-
return this.broker.publish(
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
690
|
+
return this.broker.publish(
|
|
691
|
+
'execution',
|
|
692
|
+
`execution.${completionType}.${this.executionId}`,
|
|
693
|
+
{
|
|
694
|
+
...stateMessage.content,
|
|
695
|
+
output: { ...this.environment.output },
|
|
696
|
+
...content,
|
|
697
|
+
state: completionType,
|
|
698
|
+
},
|
|
699
|
+
{ type: completionType, mandatory: completionType === 'error', ...options },
|
|
700
|
+
);
|
|
669
701
|
};
|
|
670
702
|
|
|
671
703
|
DefinitionExecution.prototype._createMessage = function createMessage(content = {}) {
|
package/src/error/BpmnError.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export default function BpmnErrorActivity(errorDef, context) {
|
|
2
|
-
const {id, type, name = 'BpmnError', behaviour = {}} = errorDef;
|
|
3
|
-
const {environment} = context;
|
|
2
|
+
const { id, type, name = 'BpmnError', behaviour = {} } = errorDef;
|
|
3
|
+
const { environment } = context;
|
|
4
4
|
|
|
5
5
|
return {
|
|
6
6
|
id,
|
|
@@ -11,7 +11,7 @@ export default function BpmnErrorActivity(errorDef, context) {
|
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
function resolve(executionMessage, error) {
|
|
14
|
-
const resolveCtx = {...executionMessage, error};
|
|
14
|
+
const resolveCtx = { ...executionMessage, error };
|
|
15
15
|
const result = {
|
|
16
16
|
id,
|
|
17
17
|
type,
|
package/src/error/Errors.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {cloneMessage} from '../messageHelper.js';
|
|
1
|
+
import { cloneMessage } from '../messageHelper.js';
|
|
2
2
|
|
|
3
3
|
class ActivityError extends Error {
|
|
4
4
|
constructor(description, sourceMessage, inner) {
|
|
@@ -6,7 +6,8 @@ class ActivityError extends Error {
|
|
|
6
6
|
this.type = 'ActivityError';
|
|
7
7
|
this.name = this.constructor.name;
|
|
8
8
|
this.description = description;
|
|
9
|
-
if (sourceMessage)
|
|
9
|
+
if (sourceMessage)
|
|
10
|
+
this.source = cloneMessage(sourceMessage, sourceMessage.content && sourceMessage.content.error && { error: undefined });
|
|
10
11
|
if (inner) {
|
|
11
12
|
this.inner = inner;
|
|
12
13
|
if (inner.name) this.name = inner.name;
|
|
@@ -19,7 +20,7 @@ class RunError extends ActivityError {}
|
|
|
19
20
|
|
|
20
21
|
class BpmnError extends Error {
|
|
21
22
|
constructor(description, behaviour = {}, sourceMessage, inner) {
|
|
22
|
-
const {errorCode} = behaviour;
|
|
23
|
+
const { errorCode } = behaviour;
|
|
23
24
|
|
|
24
25
|
super(description);
|
|
25
26
|
this.type = 'BpmnError';
|
|
@@ -27,31 +28,35 @@ class BpmnError extends Error {
|
|
|
27
28
|
this.description = description;
|
|
28
29
|
this.code = ('errorCode' in behaviour && errorCode && errorCode.toString()) || behaviour.code;
|
|
29
30
|
this.id = behaviour.id;
|
|
30
|
-
if (sourceMessage)
|
|
31
|
+
if (sourceMessage)
|
|
32
|
+
this.source = cloneMessage(sourceMessage, sourceMessage.content && sourceMessage.content.error && { error: undefined });
|
|
31
33
|
if (inner) this.inner = inner;
|
|
32
34
|
}
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
export {
|
|
36
|
-
ActivityError,
|
|
37
|
-
BpmnError,
|
|
38
|
-
RunError,
|
|
39
|
-
makeErrorFromMessage
|
|
40
|
-
};
|
|
37
|
+
export { ActivityError, BpmnError, RunError, makeErrorFromMessage };
|
|
41
38
|
|
|
42
39
|
function makeErrorFromMessage(errorMessage) {
|
|
43
|
-
const {content} = errorMessage;
|
|
40
|
+
const { content } = errorMessage;
|
|
44
41
|
if (isKnownError(content)) return content;
|
|
45
42
|
|
|
46
|
-
const {error} = content;
|
|
43
|
+
const { error } = content;
|
|
47
44
|
if (!error) return new Error(`Malformatted error message with routing key ${errorMessage.fields && errorMessage.fields.routingKey}`);
|
|
48
45
|
|
|
49
46
|
if (isKnownError(error)) return error;
|
|
50
47
|
switch (error.type) {
|
|
51
48
|
case 'ActivityError':
|
|
52
|
-
return new ActivityError(
|
|
49
|
+
return new ActivityError(
|
|
50
|
+
error.message || error.description,
|
|
51
|
+
error.source,
|
|
52
|
+
error.inner ? error.inner : { code: error.code, name: error.name },
|
|
53
|
+
);
|
|
53
54
|
case 'RunError':
|
|
54
|
-
return new RunError(
|
|
55
|
+
return new RunError(
|
|
56
|
+
error.message || error.description,
|
|
57
|
+
error.source,
|
|
58
|
+
error.inner ? error.inner : { code: error.code, name: error.name },
|
|
59
|
+
);
|
|
55
60
|
case 'BpmnError':
|
|
56
61
|
return new BpmnError(error.message || error.description, error, error.source);
|
|
57
62
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import {cloneContent, shiftParent} from '../messageHelper.js';
|
|
1
|
+
import { cloneContent, shiftParent } from '../messageHelper.js';
|
|
2
2
|
|
|
3
3
|
const kCompleted = Symbol.for('completed');
|
|
4
4
|
const kExecuteMessage = Symbol.for('executeMessage');
|
|
5
5
|
|
|
6
6
|
export default function CancelEventDefinition(activity, eventDefinition) {
|
|
7
|
-
const {id, broker, environment, isThrowing} = activity;
|
|
7
|
+
const { id, broker, environment, isThrowing } = activity;
|
|
8
8
|
const type = eventDefinition.type;
|
|
9
9
|
|
|
10
10
|
this.id = id;
|
|
11
11
|
this.type = type;
|
|
12
|
-
this.reference = {referenceType: 'cancel'};
|
|
12
|
+
this.reference = { referenceType: 'cancel' };
|
|
13
13
|
this.isThrowing = isThrowing;
|
|
14
14
|
this.activity = activity;
|
|
15
15
|
this.environment = environment;
|
|
@@ -33,7 +33,7 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
|
|
|
33
33
|
this[kCompleted] = false;
|
|
34
34
|
|
|
35
35
|
const executeContent = executeMessage.content;
|
|
36
|
-
const {executionId, parent} = executeContent;
|
|
36
|
+
const { executionId, parent } = executeContent;
|
|
37
37
|
const parentExecutionId = parent.executionId;
|
|
38
38
|
|
|
39
39
|
const broker = this.broker;
|
|
@@ -50,11 +50,15 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
|
|
|
50
50
|
consumerTag: `_onattached-cancel-${executionId}`,
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
broker.publish(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
broker.publish(
|
|
54
|
+
'execution',
|
|
55
|
+
'execute.expect',
|
|
56
|
+
cloneContent(executeContent, {
|
|
57
|
+
pattern: 'activity.execution.cancel',
|
|
58
|
+
exchange: 'execution',
|
|
59
|
+
expectRoutingKey,
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
58
62
|
|
|
59
63
|
const waitContent = cloneContent(executeContent, {
|
|
60
64
|
executionId: parentExecutionId,
|
|
@@ -68,7 +72,7 @@ CancelEventDefinition.prototype.executeCatch = function executeCatch(executeMess
|
|
|
68
72
|
|
|
69
73
|
CancelEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
70
74
|
const executeContent = executeMessage.content;
|
|
71
|
-
const {executionId, parent} = executeContent;
|
|
75
|
+
const { executionId, parent } = executeContent;
|
|
72
76
|
|
|
73
77
|
this.logger.debug(`<${executionId} (${this.activity.id})> throw cancel`);
|
|
74
78
|
|
|
@@ -117,7 +121,8 @@ CancelEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey
|
|
|
117
121
|
};
|
|
118
122
|
|
|
119
123
|
CancelEventDefinition.prototype._stop = function stop() {
|
|
120
|
-
const broker = this.broker,
|
|
124
|
+
const broker = this.broker,
|
|
125
|
+
executionId = this.executionId;
|
|
121
126
|
broker.cancel(`_onattached-cancel-${executionId}`);
|
|
122
127
|
broker.cancel(`_api-${executionId}`);
|
|
123
128
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {brokerSafeId} from '../shared.js';
|
|
2
|
-
import {cloneContent, cloneMessage, shiftParent} from '../messageHelper.js';
|
|
1
|
+
import { brokerSafeId } from '../shared.js';
|
|
2
|
+
import { cloneContent, cloneMessage, shiftParent } from '../messageHelper.js';
|
|
3
3
|
|
|
4
4
|
const kCompleted = Symbol.for('completed');
|
|
5
5
|
const kExecuteMessage = Symbol.for('executeMessage');
|
|
@@ -8,11 +8,11 @@ const kCompensateQ = Symbol.for('compensateQ');
|
|
|
8
8
|
const kAssociations = Symbol.for('associations');
|
|
9
9
|
|
|
10
10
|
export default function CompensateEventDefinition(activity, eventDefinition, context) {
|
|
11
|
-
const {id, broker, environment, isThrowing} = activity;
|
|
11
|
+
const { id, broker, environment, isThrowing } = activity;
|
|
12
12
|
|
|
13
13
|
this.id = id;
|
|
14
|
-
const type = this.type = eventDefinition.type;
|
|
15
|
-
const reference = this.reference = {referenceType: 'compensate'};
|
|
14
|
+
const type = (this.type = eventDefinition.type);
|
|
15
|
+
const reference = (this.reference = { referenceType: 'compensate' });
|
|
16
16
|
this.isThrowing = isThrowing;
|
|
17
17
|
this.activity = activity;
|
|
18
18
|
this.broker = broker;
|
|
@@ -22,9 +22,9 @@ export default function CompensateEventDefinition(activity, eventDefinition, con
|
|
|
22
22
|
this[kCompleted] = false;
|
|
23
23
|
this[kAssociations] = context.getOutboundAssociations(id);
|
|
24
24
|
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-q`;
|
|
25
|
-
this[kMessageQ] = broker.assertQueue(messageQueueName, {autoDelete: false, durable: true});
|
|
26
|
-
this[kCompensateQ] = broker.assertQueue('compensate-q', {autoDelete: false, durable: true});
|
|
27
|
-
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, {durable: true, priority: 400});
|
|
25
|
+
this[kMessageQ] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
|
|
26
|
+
this[kCompensateQ] = broker.assertQueue('compensate-q', { autoDelete: false, durable: true });
|
|
27
|
+
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true, priority: 400 });
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -49,7 +49,7 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
|
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
const executeContent = executeMessage.content;
|
|
52
|
-
const {executionId, parent} = executeContent;
|
|
52
|
+
const { executionId, parent } = executeContent;
|
|
53
53
|
|
|
54
54
|
this._debug('expect compensate');
|
|
55
55
|
|
|
@@ -73,16 +73,20 @@ CompensateEventDefinition.prototype.executeCatch = function executeCatch(execute
|
|
|
73
73
|
consumerTag: `_api-${executionId}`,
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
-
broker.publish(
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
broker.publish(
|
|
77
|
+
'execution',
|
|
78
|
+
'execute.detach',
|
|
79
|
+
cloneContent(executeContent, {
|
|
80
|
+
sourceExchange: 'execution',
|
|
81
|
+
bindExchange: 'compensate',
|
|
82
|
+
expect: 'compensate',
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
81
85
|
};
|
|
82
86
|
|
|
83
87
|
CompensateEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
84
88
|
const executeContent = executeMessage.content;
|
|
85
|
-
const {parent} = executeContent;
|
|
89
|
+
const { parent } = executeContent;
|
|
86
90
|
const parentExecutionId = parent && parent.executionId;
|
|
87
91
|
|
|
88
92
|
this.logger.debug(`<${parentExecutionId} (${this.id})> throw compensate`);
|
|
@@ -93,7 +97,7 @@ CompensateEventDefinition.prototype.executeThrow = function executeThrow(execute
|
|
|
93
97
|
state: 'throw',
|
|
94
98
|
});
|
|
95
99
|
throwContent.parent = shiftParent(parent);
|
|
96
|
-
broker.publish('event', 'activity.compensate', throwContent, {type: 'compensate', delegate: true});
|
|
100
|
+
broker.publish('event', 'activity.compensate', throwContent, { type: 'compensate', delegate: true });
|
|
97
101
|
|
|
98
102
|
return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
|
|
99
103
|
};
|
|
@@ -118,28 +122,28 @@ CompensateEventDefinition.prototype._onCompensateApiMessage = function onCompens
|
|
|
118
122
|
this._debug('caught compensate event');
|
|
119
123
|
|
|
120
124
|
const catchContent = cloneContent(executeContent, {
|
|
121
|
-
message: {...output},
|
|
125
|
+
message: { ...output },
|
|
122
126
|
executionId: executeContent.parent.executionId,
|
|
123
127
|
});
|
|
124
128
|
catchContent.parent = shiftParent(catchContent.parent);
|
|
125
129
|
|
|
126
|
-
this[kCompensateQ].queueMessage({routingKey: 'execute.compensated'}, cloneContent(executeContent));
|
|
130
|
+
this[kCompensateQ].queueMessage({ routingKey: 'execute.compensated' }, cloneContent(executeContent));
|
|
127
131
|
|
|
128
|
-
broker.publish('execution', 'execute.compensating', cloneContent(executeContent, {message: {...output}}));
|
|
129
|
-
broker.publish('event', 'activity.catch', catchContent, {type: 'catch'});
|
|
132
|
+
broker.publish('execution', 'execute.compensating', cloneContent(executeContent, { message: { ...output } }));
|
|
133
|
+
broker.publish('event', 'activity.catch', catchContent, { type: 'catch' });
|
|
130
134
|
|
|
131
135
|
return this._compensate();
|
|
132
136
|
};
|
|
133
137
|
|
|
134
138
|
CompensateEventDefinition.prototype._compensate = function compensate() {
|
|
135
|
-
return this[kCompensateQ].consume(this._onCollected.bind(this), {noAck: true, consumerTag: '_convey-messages'});
|
|
139
|
+
return this[kCompensateQ].consume(this._onCollected.bind(this), { noAck: true, consumerTag: '_convey-messages' });
|
|
136
140
|
};
|
|
137
141
|
|
|
138
142
|
CompensateEventDefinition.prototype._onCollected = function onCollected(routingKey, message) {
|
|
139
143
|
if (routingKey === 'execute.compensated') {
|
|
140
144
|
const broker = this.broker;
|
|
141
145
|
broker.cancel('_convey-messages');
|
|
142
|
-
return this.broker.publish('execution', 'execute.completed', cloneContent(message.content, {cancelActivity: false}));
|
|
146
|
+
return this.broker.publish('execution', 'execute.completed', cloneContent(message.content, { cancelActivity: false }));
|
|
143
147
|
}
|
|
144
148
|
for (const association of this[kAssociations]) association.take(cloneMessage(message));
|
|
145
149
|
};
|
|
@@ -168,7 +172,8 @@ CompensateEventDefinition.prototype._onApiMessage = function onApiMessage(routin
|
|
|
168
172
|
};
|
|
169
173
|
|
|
170
174
|
CompensateEventDefinition.prototype._stopCollect = function stopCollect() {
|
|
171
|
-
const broker = this.broker,
|
|
175
|
+
const broker = this.broker,
|
|
176
|
+
executionId = this.executionId;
|
|
172
177
|
broker.cancel(`_api-${executionId}`);
|
|
173
178
|
broker.cancel(`_oncompensate-${executionId}`);
|
|
174
179
|
broker.cancel('_oncollect-messages');
|