bpmn-elements 17.2.2 → 18.0.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 +3 -1
- package/dist/Api.js +83 -0
- package/dist/Context.js +228 -22
- package/dist/Environment.js +111 -31
- package/dist/EventBroker.js +57 -1
- package/dist/Expressions.js +3 -4
- package/dist/MessageFormatter.js +29 -16
- package/dist/Timers.js +13 -9
- package/dist/Tracker.js +1 -0
- package/dist/activity/Activity.js +458 -254
- package/dist/activity/ActivityExecution.js +113 -40
- package/dist/activity/Dummy.js +6 -1
- package/dist/activity/Escalation.js +36 -24
- package/dist/activity/ExecutionScope.js +1 -1
- package/dist/activity/Message.js +36 -24
- package/dist/activity/Signal.js +36 -24
- package/dist/activity/outbound-evaluator.js +1 -1
- package/dist/condition.js +12 -6
- package/dist/constants.js +21 -0
- package/dist/definition/Definition.js +182 -64
- package/dist/definition/DefinitionExecution.js +195 -82
- package/dist/error/BpmnError.js +12 -1
- package/dist/error/Errors.js +50 -9
- package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
- package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
- package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
- package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
- package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
- package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
- package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
- package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
- package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
- package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
- package/dist/eventDefinitions/index.js +20 -21
- package/dist/events/BoundaryEvent.js +52 -40
- package/dist/events/EndEvent.js +22 -8
- package/dist/events/IntermediateCatchEvent.js +26 -8
- package/dist/events/IntermediateThrowEvent.js +24 -9
- package/dist/events/StartEvent.js +30 -14
- package/dist/events/index.js +10 -11
- package/dist/flows/Association.js +50 -7
- package/dist/flows/MessageFlow.js +49 -10
- package/dist/flows/SequenceFlow.js +93 -22
- package/dist/flows/index.js +6 -7
- package/dist/gateways/EventBasedGateway.js +29 -15
- package/dist/gateways/ExclusiveGateway.js +20 -5
- package/dist/gateways/InclusiveGateway.js +21 -5
- package/dist/gateways/ParallelGateway.js +253 -15
- package/dist/gateways/index.js +8 -9
- package/dist/getPropertyValue.js +2 -2
- package/dist/index.js +42 -43
- package/dist/io/BpmnIO.js +15 -1
- package/dist/io/EnvironmentDataObject.js +29 -1
- package/dist/io/EnvironmentDataStore.js +24 -1
- package/dist/io/EnvironmentDataStoreReference.js +24 -1
- package/dist/io/InputOutputSpecification.js +21 -11
- package/dist/io/Properties.js +28 -17
- package/dist/messageHelper.js +41 -4
- package/dist/process/Lane.js +15 -4
- package/dist/process/Process.js +174 -76
- package/dist/process/ProcessExecution.js +362 -177
- package/dist/shared.js +2 -0
- package/dist/tasks/CallActivity.js +19 -4
- package/dist/tasks/LoopCharacteristics.js +94 -9
- package/dist/tasks/ReceiveTask.js +36 -21
- package/dist/tasks/ScriptTask.js +22 -6
- package/dist/tasks/ServiceImplementation.js +7 -4
- package/dist/tasks/ServiceTask.js +19 -4
- package/dist/tasks/SignalTask.js +19 -4
- package/dist/tasks/StandardLoopCharacteristics.js +8 -4
- package/dist/tasks/SubProcess.js +44 -29
- package/dist/tasks/Task.js +19 -4
- package/dist/tasks/Transaction.js +8 -4
- package/dist/tasks/index.js +16 -18
- package/package.json +31 -13
- package/src/Api.js +70 -0
- package/src/Context.js +200 -19
- package/src/Environment.js +99 -30
- package/src/EventBroker.js +46 -1
- package/src/Expressions.js +2 -3
- package/src/MessageFormatter.js +24 -16
- package/src/Timers.js +12 -9
- package/src/Tracker.js +1 -0
- package/src/activity/Activity.js +388 -231
- package/src/activity/ActivityExecution.js +93 -42
- package/src/activity/Dummy.js +6 -1
- package/src/activity/Escalation.js +25 -18
- package/src/activity/ExecutionScope.js +1 -1
- package/src/activity/Message.js +25 -18
- package/src/activity/Signal.js +25 -18
- package/src/activity/outbound-evaluator.js +1 -1
- package/src/condition.js +11 -5
- package/src/constants.js +15 -0
- package/src/definition/Definition.js +157 -62
- package/src/definition/DefinitionExecution.js +161 -83
- package/src/error/BpmnError.js +11 -1
- package/src/error/Errors.js +44 -5
- package/src/eventDefinitions/CancelEventDefinition.js +27 -13
- package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
- package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
- package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
- package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
- package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
- package/src/eventDefinitions/LinkEventDefinition.js +34 -120
- package/src/eventDefinitions/MessageEventDefinition.js +42 -31
- package/src/eventDefinitions/SignalEventDefinition.js +43 -32
- package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
- package/src/eventDefinitions/TimerEventDefinition.js +53 -35
- package/src/eventDefinitions/index.js +10 -23
- package/src/events/BoundaryEvent.js +50 -39
- package/src/events/EndEvent.js +19 -7
- package/src/events/IntermediateCatchEvent.js +24 -8
- package/src/events/IntermediateThrowEvent.js +24 -8
- package/src/events/StartEvent.js +25 -14
- package/src/events/index.js +5 -18
- package/src/flows/Association.js +43 -9
- package/src/flows/MessageFlow.js +41 -10
- package/src/flows/SequenceFlow.js +82 -19
- package/src/flows/index.js +3 -4
- package/src/gateways/EventBasedGateway.js +27 -15
- package/src/gateways/ExclusiveGateway.js +16 -3
- package/src/gateways/InclusiveGateway.js +16 -3
- package/src/gateways/ParallelGateway.js +301 -10
- package/src/gateways/index.js +4 -4
- package/src/getPropertyValue.js +2 -2
- package/src/index.js +19 -19
- package/src/io/BpmnIO.js +13 -1
- package/src/io/EnvironmentDataObject.js +26 -1
- package/src/io/EnvironmentDataStore.js +22 -1
- package/src/io/EnvironmentDataStoreReference.js +22 -1
- package/src/io/InputOutputSpecification.js +17 -8
- package/src/io/Properties.js +23 -13
- package/src/messageHelper.js +36 -4
- package/src/process/Lane.js +14 -4
- package/src/process/Process.js +154 -72
- package/src/process/ProcessExecution.js +326 -175
- package/src/shared.js +1 -0
- package/src/tasks/CallActivity.js +16 -2
- package/src/tasks/LoopCharacteristics.js +77 -11
- package/src/tasks/ReceiveTask.js +33 -22
- package/src/tasks/ScriptTask.js +17 -3
- package/src/tasks/ServiceImplementation.js +6 -3
- package/src/tasks/ServiceTask.js +16 -2
- package/src/tasks/SignalTask.js +16 -2
- package/src/tasks/StandardLoopCharacteristics.js +7 -3
- package/src/tasks/SubProcess.js +37 -23
- package/src/tasks/Task.js +16 -2
- package/src/tasks/Transaction.js +7 -3
- package/src/tasks/index.js +8 -9
- package/types/bundle-errors.d.ts +1 -0
- package/types/bundle.d.ts +97 -0
- package/types/index.d.ts +2614 -84
- package/types/interfaces.d.ts +636 -0
- package/types/types.d.ts +0 -765
|
@@ -1,66 +1,76 @@
|
|
|
1
|
-
import getPropertyValue from '../getPropertyValue.js';
|
|
1
|
+
import { getPropertyValue } from '../getPropertyValue.js';
|
|
2
2
|
import { brokerSafeId } from '../shared.js';
|
|
3
3
|
import { cloneContent, shiftParent } from '../messageHelper.js';
|
|
4
|
+
import { K_COMPLETED, K_EXECUTE_MESSAGE, K_MESSAGE_Q, K_REFERENCE_ELEMENT } from '../constants.js';
|
|
4
5
|
|
|
5
|
-
const
|
|
6
|
-
const kMessageQ = Symbol.for('messageQ');
|
|
7
|
-
const kExecuteMessage = Symbol.for('executeMessage');
|
|
8
|
-
const kReferenceElement = Symbol.for('referenceElement');
|
|
9
|
-
const kReference = Symbol.for('reference');
|
|
6
|
+
const K_REFERENCE = Symbol.for('reference');
|
|
10
7
|
|
|
11
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Escalation event definition
|
|
10
|
+
* @param {import('#types').Activity} activity
|
|
11
|
+
* @param {import('moddle-context-serializer').EventDefinition} eventDefinition
|
|
12
|
+
*/
|
|
13
|
+
export function EscalationEventDefinition(activity, eventDefinition) {
|
|
12
14
|
const { id, broker, environment, isThrowing } = activity;
|
|
13
15
|
const { type, behaviour = {} } = eventDefinition;
|
|
14
16
|
|
|
15
17
|
this.id = id;
|
|
16
18
|
this.type = type;
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
/** @type {import('#types').EventReference} */
|
|
21
|
+
this.reference = {
|
|
19
22
|
name: 'anonymous',
|
|
20
23
|
...behaviour.escalationRef,
|
|
21
24
|
referenceType: 'escalate',
|
|
22
|
-
}
|
|
25
|
+
};
|
|
23
26
|
|
|
24
27
|
this.isThrowing = isThrowing;
|
|
25
28
|
this.activity = activity;
|
|
26
29
|
this.broker = broker;
|
|
27
30
|
this.logger = environment.Logger(type.toLowerCase());
|
|
28
31
|
|
|
29
|
-
const referenceElement = (this[
|
|
32
|
+
const referenceElement = (this[K_REFERENCE_ELEMENT] = this.reference.id && activity.getActivityById(this.reference.id));
|
|
30
33
|
if (!isThrowing) {
|
|
31
|
-
this[
|
|
34
|
+
this[K_COMPLETED] = false;
|
|
32
35
|
const referenceId = referenceElement ? referenceElement.id : 'anonymous';
|
|
33
|
-
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
|
|
34
|
-
this[
|
|
35
|
-
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true, priority: 400 });
|
|
36
|
+
const messageQueueName = `${this.reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
|
|
37
|
+
this[K_MESSAGE_Q] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
|
|
38
|
+
broker.bindQueue(messageQueueName, 'api', `*.${this.reference.referenceType}.#`, { durable: true, priority: 400 });
|
|
36
39
|
}
|
|
37
40
|
}
|
|
38
41
|
|
|
39
42
|
Object.defineProperty(EscalationEventDefinition.prototype, 'executionId', {
|
|
43
|
+
/** @returns {string} */
|
|
40
44
|
get() {
|
|
41
|
-
return this[
|
|
45
|
+
return this[K_EXECUTE_MESSAGE]?.content.executionId;
|
|
42
46
|
},
|
|
43
47
|
});
|
|
44
48
|
|
|
49
|
+
/**
|
|
50
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
51
|
+
*/
|
|
45
52
|
EscalationEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
46
53
|
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
47
54
|
};
|
|
48
55
|
|
|
56
|
+
/**
|
|
57
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
58
|
+
*/
|
|
49
59
|
EscalationEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
|
|
50
|
-
this[
|
|
51
|
-
this[
|
|
60
|
+
this[K_EXECUTE_MESSAGE] = executeMessage;
|
|
61
|
+
this[K_COMPLETED] = false;
|
|
52
62
|
|
|
53
63
|
const executeContent = executeMessage.content;
|
|
54
64
|
const { executionId, parent } = executeContent;
|
|
55
65
|
|
|
56
|
-
const info = (this[
|
|
66
|
+
const info = (this[K_REFERENCE] = this._getReferenceInfo(executeMessage));
|
|
57
67
|
const broker = this.broker;
|
|
58
|
-
this[
|
|
68
|
+
this[K_MESSAGE_Q].consume(this._onCatchMessage.bind(this), {
|
|
59
69
|
noAck: true,
|
|
60
70
|
consumerTag: `_onescalate-${executionId}`,
|
|
61
71
|
});
|
|
62
72
|
|
|
63
|
-
if (this[
|
|
73
|
+
if (this[K_COMPLETED]) return;
|
|
64
74
|
|
|
65
75
|
broker.subscribeTmp('api', `activity.#.${executionId}`, this._onApiMessage.bind(this), {
|
|
66
76
|
noAck: true,
|
|
@@ -79,6 +89,9 @@ EscalationEventDefinition.prototype.executeCatch = function executeCatch(execute
|
|
|
79
89
|
broker.publish('event', 'activity.wait', waitContent);
|
|
80
90
|
};
|
|
81
91
|
|
|
92
|
+
/**
|
|
93
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
94
|
+
*/
|
|
82
95
|
EscalationEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
83
96
|
const executeContent = executeMessage.content;
|
|
84
97
|
const { executionId, parent } = executeContent;
|
|
@@ -100,17 +113,17 @@ EscalationEventDefinition.prototype.executeThrow = function executeThrow(execute
|
|
|
100
113
|
};
|
|
101
114
|
|
|
102
115
|
EscalationEventDefinition.prototype._onCatchMessage = function onCatchMessage(routingKey, message) {
|
|
103
|
-
const info = this[
|
|
116
|
+
const info = this[K_REFERENCE];
|
|
104
117
|
if (getPropertyValue(message, 'content.message.id') !== info.message.id) return;
|
|
105
118
|
|
|
106
119
|
const output = message.content.message;
|
|
107
|
-
this[
|
|
120
|
+
this[K_COMPLETED] = true;
|
|
108
121
|
|
|
109
122
|
this._stop();
|
|
110
123
|
|
|
111
124
|
this._debug(`caught ${info.description}`);
|
|
112
125
|
|
|
113
|
-
const executeContent = this[
|
|
126
|
+
const executeContent = this[K_EXECUTE_MESSAGE].content;
|
|
114
127
|
const { parent, ...content } = executeContent;
|
|
115
128
|
const catchContent = cloneContent(content, {
|
|
116
129
|
message: { ...output },
|
|
@@ -130,9 +143,9 @@ EscalationEventDefinition.prototype._onApiMessage = function onApiMessage(routin
|
|
|
130
143
|
return this._onCatchMessage(routingKey, message);
|
|
131
144
|
}
|
|
132
145
|
case 'discard': {
|
|
133
|
-
this[
|
|
146
|
+
this[K_COMPLETED] = true;
|
|
134
147
|
this._stop();
|
|
135
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(this[
|
|
148
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_EXECUTE_MESSAGE].content));
|
|
136
149
|
}
|
|
137
150
|
case 'stop': {
|
|
138
151
|
this._stop();
|
|
@@ -149,7 +162,7 @@ EscalationEventDefinition.prototype._stop = function stop() {
|
|
|
149
162
|
};
|
|
150
163
|
|
|
151
164
|
EscalationEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(message) {
|
|
152
|
-
const referenceElement = this[
|
|
165
|
+
const referenceElement = this[K_REFERENCE_ELEMENT];
|
|
153
166
|
if (!referenceElement) {
|
|
154
167
|
return {
|
|
155
168
|
message: { ...this.reference },
|
|
@@ -1,33 +1,39 @@
|
|
|
1
1
|
import { cloneContent, unshiftParent, shiftParent, cloneParent } from '../messageHelper.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
import { K_COMPLETED, K_EXECUTE_MESSAGE, K_STOPPED } from '../constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Event definition execution orchestrator. Drives a sequence of event definitions for the
|
|
6
|
+
* activity and publishes the completed routing key when the last definition completes.
|
|
7
|
+
* @param {import('#types').Activity} activity
|
|
8
|
+
* @param {import('#types').EventDefinition[]} eventDefinitions
|
|
9
|
+
* @param {string} [completedRoutingKey] Routing key to publish on completion, defaults to `execute.completed`
|
|
10
|
+
*/
|
|
11
|
+
export function EventDefinitionExecution(activity, eventDefinitions, completedRoutingKey = 'execute.completed') {
|
|
8
12
|
this.id = activity.id;
|
|
9
13
|
this.activity = activity;
|
|
10
14
|
this.broker = activity.broker;
|
|
11
15
|
this.eventDefinitions = eventDefinitions;
|
|
12
16
|
this.completedRoutingKey = completedRoutingKey;
|
|
13
|
-
this[
|
|
14
|
-
this[
|
|
15
|
-
this[
|
|
17
|
+
this[K_COMPLETED] = false;
|
|
18
|
+
this[K_STOPPED] = false;
|
|
19
|
+
this[K_EXECUTE_MESSAGE] = null;
|
|
16
20
|
}
|
|
17
21
|
|
|
18
|
-
Object.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
return this[kCompleted];
|
|
22
|
-
},
|
|
22
|
+
Object.defineProperty(EventDefinitionExecution.prototype, 'completed', {
|
|
23
|
+
get() {
|
|
24
|
+
return this[K_COMPLETED];
|
|
23
25
|
},
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
Object.defineProperty(EventDefinitionExecution.prototype, 'stopped', {
|
|
29
|
+
get() {
|
|
30
|
+
return this[K_STOPPED];
|
|
28
31
|
},
|
|
29
32
|
});
|
|
30
33
|
|
|
34
|
+
/**
|
|
35
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
36
|
+
*/
|
|
31
37
|
EventDefinitionExecution.prototype.execute = function execute(executeMessage) {
|
|
32
38
|
const content = executeMessage.content;
|
|
33
39
|
|
|
@@ -36,7 +42,7 @@ EventDefinitionExecution.prototype.execute = function execute(executeMessage) {
|
|
|
36
42
|
|
|
37
43
|
const broker = this.broker;
|
|
38
44
|
|
|
39
|
-
this[
|
|
45
|
+
this[K_EXECUTE_MESSAGE] = executeMessage;
|
|
40
46
|
const executionId = content.executionId;
|
|
41
47
|
|
|
42
48
|
broker.subscribeTmp('execution', 'execute.#', this._onExecuteMessage.bind(this), {
|
|
@@ -58,8 +64,8 @@ EventDefinitionExecution.prototype.execute = function execute(executeMessage) {
|
|
|
58
64
|
const eventDefinitions = this.eventDefinitions;
|
|
59
65
|
|
|
60
66
|
for (let index = 0; index < eventDefinitions.length; ++index) {
|
|
61
|
-
if (this[
|
|
62
|
-
if (this[
|
|
67
|
+
if (this[K_COMPLETED]) break;
|
|
68
|
+
if (this[K_STOPPED]) break;
|
|
63
69
|
|
|
64
70
|
const ed = eventDefinitions[index];
|
|
65
71
|
const edExecutionId = `${executionId}_${index}`;
|
|
@@ -110,12 +116,12 @@ EventDefinitionExecution.prototype._onExecuteMessage = function onExecuteMessage
|
|
|
110
116
|
|
|
111
117
|
EventDefinitionExecution.prototype._complete = function complete(message) {
|
|
112
118
|
const { executionId, type, index, parent } = message.content;
|
|
113
|
-
this[
|
|
119
|
+
this[K_COMPLETED] = true;
|
|
114
120
|
|
|
115
121
|
this._debug(executionId, `event definition ${type} completed, index ${index}`);
|
|
116
122
|
|
|
117
123
|
const completeContent = cloneContent(message.content, {
|
|
118
|
-
executionId: this[
|
|
124
|
+
executionId: this[K_EXECUTE_MESSAGE].content.executionId,
|
|
119
125
|
isRootScope: true,
|
|
120
126
|
isDefinitionScope: undefined,
|
|
121
127
|
});
|
|
@@ -133,7 +139,7 @@ EventDefinitionExecution.prototype._executeDefinition = function executeDefiniti
|
|
|
133
139
|
};
|
|
134
140
|
|
|
135
141
|
EventDefinitionExecution.prototype._stop = function stop() {
|
|
136
|
-
this[
|
|
142
|
+
this[K_STOPPED] = true;
|
|
137
143
|
this.broker.cancel('_eventdefinition-execution-execute-tag');
|
|
138
144
|
this.broker.cancel('_eventdefinition-execution-api-tag');
|
|
139
145
|
};
|
|
@@ -1,88 +1,75 @@
|
|
|
1
|
-
import getPropertyValue from '../getPropertyValue.js';
|
|
2
|
-
import { brokerSafeId } from '../shared.js';
|
|
3
1
|
import { cloneContent, shiftParent } from '../messageHelper.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
import { K_EXECUTE_MESSAGE } from '../constants.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Link event definition
|
|
6
|
+
* @param {import('#types').Activity} activity
|
|
7
|
+
* @param {import('moddle-context-serializer').EventDefinition} eventDefinition
|
|
8
|
+
*/
|
|
9
|
+
export function LinkEventDefinition(activity, eventDefinition) {
|
|
10
10
|
const { id, broker, environment, isThrowing } = activity;
|
|
11
11
|
const { type = 'LinkEventDefinition', behaviour } = eventDefinition;
|
|
12
12
|
|
|
13
13
|
this.id = id;
|
|
14
14
|
this.type = type;
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
/** @type {import('#types').EventReference} */
|
|
17
|
+
this.reference = {
|
|
18
|
+
id: behaviour.name,
|
|
17
19
|
linkName: behaviour.name,
|
|
18
20
|
referenceType: 'link',
|
|
19
|
-
}
|
|
21
|
+
};
|
|
20
22
|
|
|
21
23
|
this.isThrowing = isThrowing;
|
|
22
24
|
this.activity = activity;
|
|
23
25
|
this.broker = broker;
|
|
24
26
|
this.logger = environment.Logger(type.toLowerCase());
|
|
25
|
-
this[kCompleted] = false;
|
|
26
|
-
|
|
27
|
-
if (!isThrowing) {
|
|
28
|
-
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(reference.linkName)}-q`;
|
|
29
|
-
this[kMessageQ] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
|
|
30
|
-
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true });
|
|
31
|
-
} else {
|
|
32
|
-
broker.subscribeTmp('event', 'activity.discard', this._onDiscard.bind(this), {
|
|
33
|
-
noAck: true,
|
|
34
|
-
consumerTag: '_link-parent-discard',
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
27
|
}
|
|
38
28
|
|
|
39
29
|
Object.defineProperty(LinkEventDefinition.prototype, 'executionId', {
|
|
30
|
+
/** @returns {string} */
|
|
40
31
|
get() {
|
|
41
|
-
return this[
|
|
32
|
+
return this[K_EXECUTE_MESSAGE]?.content.executionId;
|
|
42
33
|
},
|
|
43
34
|
});
|
|
44
35
|
|
|
36
|
+
/**
|
|
37
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
38
|
+
*/
|
|
45
39
|
LinkEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
46
40
|
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
47
41
|
};
|
|
48
42
|
|
|
43
|
+
/**
|
|
44
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
45
|
+
*/
|
|
49
46
|
LinkEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
|
|
50
|
-
this[
|
|
51
|
-
this[kCompleted] = false;
|
|
47
|
+
this[K_EXECUTE_MESSAGE] = executeMessage;
|
|
52
48
|
|
|
53
49
|
const executeContent = executeMessage.content;
|
|
54
50
|
const { executionId, parent } = executeContent;
|
|
55
51
|
const parentExecutionId = parent.executionId;
|
|
56
52
|
|
|
57
|
-
|
|
58
|
-
noAck: true,
|
|
59
|
-
consumerTag: `_api-link-${executionId}`,
|
|
60
|
-
});
|
|
53
|
+
const linkMessage = executeContent.message ?? executeContent.input ?? { ...this.reference };
|
|
61
54
|
|
|
62
|
-
|
|
55
|
+
this.logger.debug(`<${executionId} (${this.activity.id})> caught link ${this.reference.linkName}`);
|
|
63
56
|
|
|
64
57
|
const broker = this.broker;
|
|
65
|
-
const
|
|
66
|
-
broker.subscribeTmp('api', `activity.stop.${parentExecutionId}`, onApiMessage, {
|
|
67
|
-
noAck: true,
|
|
68
|
-
consumerTag: `_api-parent-${executionId}`,
|
|
69
|
-
});
|
|
70
|
-
broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
|
|
71
|
-
noAck: true,
|
|
72
|
-
consumerTag: `_api-${executionId}`,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
this._debug(`expect link ${this.reference.linkName}`);
|
|
76
|
-
|
|
77
|
-
const waitContent = cloneContent(executeContent, {
|
|
78
|
-
executionId: parentExecutionId,
|
|
58
|
+
const catchContent = cloneContent(executeContent, {
|
|
79
59
|
link: { ...this.reference },
|
|
60
|
+
message: { ...linkMessage },
|
|
61
|
+
executionId: parentExecutionId,
|
|
80
62
|
});
|
|
81
|
-
|
|
63
|
+
catchContent.parent = shiftParent(parent);
|
|
82
64
|
|
|
83
|
-
broker.publish('event', 'activity.
|
|
65
|
+
broker.publish('event', 'activity.catch', catchContent, { type: 'catch' });
|
|
66
|
+
|
|
67
|
+
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output: linkMessage, state: 'catch' }));
|
|
84
68
|
};
|
|
85
69
|
|
|
70
|
+
/**
|
|
71
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
72
|
+
*/
|
|
86
73
|
LinkEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
87
74
|
const executeContent = executeMessage.content;
|
|
88
75
|
const { executionId, parent } = executeContent;
|
|
@@ -98,80 +85,7 @@ LinkEventDefinition.prototype.executeThrow = function executeThrow(executeMessag
|
|
|
98
85
|
});
|
|
99
86
|
linkContent.parent = shiftParent(parent);
|
|
100
87
|
|
|
101
|
-
broker.publish('event', 'activity.link', linkContent, { type: 'link'
|
|
88
|
+
broker.publish('event', 'activity.link', linkContent, { type: 'link' });
|
|
102
89
|
|
|
103
90
|
return broker.publish('execution', 'execute.completed', cloneContent(executeContent));
|
|
104
91
|
};
|
|
105
|
-
|
|
106
|
-
LinkEventDefinition.prototype._onCatchLink = function onCatchLink(routingKey, message) {
|
|
107
|
-
if (getPropertyValue(message, 'content.message.linkName') !== this.reference.linkName) return;
|
|
108
|
-
if (message.content.state === 'discard') return this._discard();
|
|
109
|
-
return this._complete('caught', message.content.message);
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
LinkEventDefinition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
113
|
-
const messageType = message.properties.type;
|
|
114
|
-
|
|
115
|
-
switch (messageType) {
|
|
116
|
-
case 'discard': {
|
|
117
|
-
return this._discard();
|
|
118
|
-
}
|
|
119
|
-
case 'stop': {
|
|
120
|
-
this._stop();
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
LinkEventDefinition.prototype._complete = function complete(verb, output) {
|
|
127
|
-
this[kCompleted] = true;
|
|
128
|
-
|
|
129
|
-
this._stop();
|
|
130
|
-
|
|
131
|
-
this._debug(`${verb} link ${this.reference.linkName}`);
|
|
132
|
-
|
|
133
|
-
const executeContent = this[kExecuteMessage].content;
|
|
134
|
-
const parent = executeContent.parent;
|
|
135
|
-
const catchContent = cloneContent(executeContent, {
|
|
136
|
-
link: { ...this.reference },
|
|
137
|
-
message: { ...output },
|
|
138
|
-
executionId: parent.executionId,
|
|
139
|
-
});
|
|
140
|
-
catchContent.parent = shiftParent(parent);
|
|
141
|
-
|
|
142
|
-
const broker = this.broker;
|
|
143
|
-
broker.publish('event', 'activity.catch', catchContent, { type: 'catch' });
|
|
144
|
-
|
|
145
|
-
return broker.publish('execution', 'execute.completed', cloneContent(executeContent, { output, state: 'catch' }));
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
LinkEventDefinition.prototype._discard = function discard() {
|
|
149
|
-
this[kCompleted] = true;
|
|
150
|
-
this._stop();
|
|
151
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(this[kExecuteMessage].content));
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
LinkEventDefinition.prototype._stop = function stop() {
|
|
155
|
-
const broker = this.broker,
|
|
156
|
-
executionId = this.executionId;
|
|
157
|
-
broker.cancel(`_api-link-${executionId}`);
|
|
158
|
-
broker.cancel(`_api-parent-${executionId}`);
|
|
159
|
-
broker.cancel(`_api-${executionId}`);
|
|
160
|
-
this[kMessageQ].purge();
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
LinkEventDefinition.prototype._onDiscard = function onDiscard(_, message) {
|
|
164
|
-
this.broker.publish(
|
|
165
|
-
'event',
|
|
166
|
-
'activity.link.discard',
|
|
167
|
-
cloneContent(message.content, {
|
|
168
|
-
message: { ...this.reference },
|
|
169
|
-
state: 'discard',
|
|
170
|
-
}),
|
|
171
|
-
{ type: 'link', delegate: true }
|
|
172
|
-
);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
LinkEventDefinition.prototype._debug = function debug(msg) {
|
|
176
|
-
this.logger.debug(`<${this.executionId} (${this.activity.id})> ${msg}`);
|
|
177
|
-
};
|
|
@@ -1,70 +1,78 @@
|
|
|
1
|
-
import getPropertyValue from '../getPropertyValue.js';
|
|
1
|
+
import { getPropertyValue } from '../getPropertyValue.js';
|
|
2
2
|
import { brokerSafeId } from '../shared.js';
|
|
3
3
|
import { cloneContent, shiftParent } from '../messageHelper.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export
|
|
4
|
+
import { K_COMPLETED, K_EXECUTE_MESSAGE, K_MESSAGE_Q, K_REFERENCE_ELEMENT, K_REFERENCE_INFO } from '../constants.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Message event definition
|
|
8
|
+
* @param {import('#types').Activity} activity
|
|
9
|
+
* @param {import('moddle-context-serializer').EventDefinition} eventDefinition
|
|
10
|
+
*/
|
|
11
|
+
export function MessageEventDefinition(activity, eventDefinition) {
|
|
12
12
|
const { id, broker, environment, isThrowing } = activity;
|
|
13
13
|
const { type = 'MessageEventDefinition', behaviour = {} } = eventDefinition;
|
|
14
14
|
|
|
15
15
|
this.id = id;
|
|
16
16
|
this.type = type;
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
/** @type {import('#types').EventReference} */
|
|
19
|
+
this.reference = {
|
|
19
20
|
name: 'anonymous',
|
|
20
21
|
...behaviour.messageRef,
|
|
21
22
|
referenceType: 'message',
|
|
22
|
-
}
|
|
23
|
+
};
|
|
23
24
|
|
|
24
25
|
this.isThrowing = isThrowing;
|
|
25
26
|
this.activity = activity;
|
|
26
27
|
this.broker = broker;
|
|
27
28
|
this.logger = environment.Logger(type.toLowerCase());
|
|
28
29
|
|
|
29
|
-
const referenceElement = (this[
|
|
30
|
+
const referenceElement = (this[K_REFERENCE_ELEMENT] = this.reference.id && activity.getActivityById(this.reference.id));
|
|
30
31
|
if (!isThrowing) {
|
|
31
|
-
this[
|
|
32
|
+
this[K_COMPLETED] = false;
|
|
32
33
|
const referenceId = referenceElement ? referenceElement.id : 'anonymous';
|
|
33
|
-
const messageQueueName = `${reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
|
|
34
|
-
this[
|
|
35
|
-
broker.bindQueue(messageQueueName, 'api', `*.${reference.referenceType}.#`, { durable: true });
|
|
34
|
+
const messageQueueName = `${this.reference.referenceType}-${brokerSafeId(id)}-${brokerSafeId(referenceId)}-q`;
|
|
35
|
+
this[K_MESSAGE_Q] = broker.assertQueue(messageQueueName, { autoDelete: false, durable: true });
|
|
36
|
+
broker.bindQueue(messageQueueName, 'api', `*.${this.reference.referenceType}.#`, { durable: true });
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
Object.defineProperty(MessageEventDefinition.prototype, 'executionId', {
|
|
41
|
+
/** @returns {string} */
|
|
40
42
|
get() {
|
|
41
|
-
return this[
|
|
43
|
+
return this[K_EXECUTE_MESSAGE]?.content.executionId;
|
|
42
44
|
},
|
|
43
45
|
});
|
|
44
46
|
|
|
47
|
+
/**
|
|
48
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
49
|
+
*/
|
|
45
50
|
MessageEventDefinition.prototype.execute = function execute(executeMessage) {
|
|
46
51
|
return this.isThrowing ? this.executeThrow(executeMessage) : this.executeCatch(executeMessage);
|
|
47
52
|
};
|
|
48
53
|
|
|
54
|
+
/**
|
|
55
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
56
|
+
*/
|
|
49
57
|
MessageEventDefinition.prototype.executeCatch = function executeCatch(executeMessage) {
|
|
50
|
-
this[
|
|
51
|
-
this[
|
|
58
|
+
this[K_EXECUTE_MESSAGE] = executeMessage;
|
|
59
|
+
this[K_COMPLETED] = false;
|
|
52
60
|
|
|
53
61
|
const executeContent = executeMessage.content;
|
|
54
62
|
const { executionId, parent } = executeContent;
|
|
55
63
|
const parentExecutionId = parent?.executionId;
|
|
56
64
|
|
|
57
|
-
const info = (this[
|
|
65
|
+
const info = (this[K_REFERENCE_INFO] = this._getReferenceInfo(executeMessage));
|
|
58
66
|
this._debug(`expect ${info.description}`);
|
|
59
67
|
|
|
60
68
|
const broker = this.broker;
|
|
61
69
|
const onCatchMessage = this._onCatchMessage.bind(this);
|
|
62
|
-
this[
|
|
70
|
+
this[K_MESSAGE_Q].consume(onCatchMessage, {
|
|
63
71
|
noAck: true,
|
|
64
72
|
consumerTag: `_api-message-${executionId}`,
|
|
65
73
|
});
|
|
66
74
|
|
|
67
|
-
if (this[
|
|
75
|
+
if (this[K_COMPLETED]) return;
|
|
68
76
|
|
|
69
77
|
const onApiMessage = this._onApiMessage.bind(this);
|
|
70
78
|
broker.subscribeTmp('api', `activity.#.${executionId}`, onApiMessage, {
|
|
@@ -91,6 +99,9 @@ MessageEventDefinition.prototype.executeCatch = function executeCatch(executeMes
|
|
|
91
99
|
broker.publish('event', 'activity.wait', waitContent);
|
|
92
100
|
};
|
|
93
101
|
|
|
102
|
+
/**
|
|
103
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
104
|
+
*/
|
|
94
105
|
MessageEventDefinition.prototype.executeThrow = function executeThrow(executeMessage) {
|
|
95
106
|
const executeContent = executeMessage.content;
|
|
96
107
|
const { executionId, parent } = executeContent;
|
|
@@ -112,13 +123,13 @@ MessageEventDefinition.prototype.executeThrow = function executeThrow(executeMes
|
|
|
112
123
|
};
|
|
113
124
|
|
|
114
125
|
MessageEventDefinition.prototype._onCatchMessage = function onCatchMessage(routingKey, message) {
|
|
115
|
-
if (getPropertyValue(message, 'content.message.id') !== this[
|
|
126
|
+
if (getPropertyValue(message, 'content.message.id') !== this[K_REFERENCE_INFO].message.id) return;
|
|
116
127
|
|
|
117
128
|
const { type, correlationId } = message.properties;
|
|
118
129
|
this.broker.publish(
|
|
119
130
|
'event',
|
|
120
131
|
'activity.consumed',
|
|
121
|
-
cloneContent(this[
|
|
132
|
+
cloneContent(this[K_EXECUTE_MESSAGE].content, {
|
|
122
133
|
message: { ...message.content.message },
|
|
123
134
|
}),
|
|
124
135
|
{
|
|
@@ -138,9 +149,9 @@ MessageEventDefinition.prototype._onApiMessage = function onApiMessage(routingKe
|
|
|
138
149
|
return this._complete('got signal with', message.content.message, { correlationId });
|
|
139
150
|
}
|
|
140
151
|
case 'discard': {
|
|
141
|
-
this[
|
|
152
|
+
this[K_COMPLETED] = true;
|
|
142
153
|
this._stop();
|
|
143
|
-
return this.broker.publish('execution', 'execute.discard', cloneContent(this[
|
|
154
|
+
return this.broker.publish('execution', 'execute.discard', cloneContent(this[K_EXECUTE_MESSAGE].content), { correlationId });
|
|
144
155
|
}
|
|
145
156
|
case 'stop': {
|
|
146
157
|
return this._stop();
|
|
@@ -149,13 +160,13 @@ MessageEventDefinition.prototype._onApiMessage = function onApiMessage(routingKe
|
|
|
149
160
|
};
|
|
150
161
|
|
|
151
162
|
MessageEventDefinition.prototype._complete = function complete(verb, output, options) {
|
|
152
|
-
this[
|
|
163
|
+
this[K_COMPLETED] = true;
|
|
153
164
|
|
|
154
165
|
this._stop();
|
|
155
|
-
this._debug(`${verb} ${this[
|
|
166
|
+
this._debug(`${verb} ${this[K_REFERENCE_INFO].description}`);
|
|
156
167
|
|
|
157
168
|
const broker = this.broker;
|
|
158
|
-
const executeContent = this[
|
|
169
|
+
const executeContent = this[K_EXECUTE_MESSAGE].content;
|
|
159
170
|
const catchContent = cloneContent(executeContent, {
|
|
160
171
|
message: { ...output },
|
|
161
172
|
executionId: executeContent.parent.executionId,
|
|
@@ -182,11 +193,11 @@ MessageEventDefinition.prototype._stop = function stop() {
|
|
|
182
193
|
broker.cancel(`_api-${executionId}`);
|
|
183
194
|
broker.cancel(`_api-parent-${executionId}`);
|
|
184
195
|
broker.cancel(`_api-delegated-${executionId}`);
|
|
185
|
-
this[
|
|
196
|
+
this[K_MESSAGE_Q].purge();
|
|
186
197
|
};
|
|
187
198
|
|
|
188
199
|
MessageEventDefinition.prototype._getReferenceInfo = function getReferenceInfo(message) {
|
|
189
|
-
const referenceElement = this[
|
|
200
|
+
const referenceElement = this[K_REFERENCE_ELEMENT];
|
|
190
201
|
if (!referenceElement) {
|
|
191
202
|
return {
|
|
192
203
|
message: { ...this.reference },
|