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,22 +1,22 @@
|
|
|
1
|
-
import getPropertyValue from '../getPropertyValue.js';
|
|
2
1
|
import { DefinitionApi } from '../Api.js';
|
|
3
2
|
import { brokerSafeId } from '../shared.js';
|
|
4
3
|
import { cloneContent, cloneMessage, pushParent, cloneParent } from '../messageHelper.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
import { K_ACTIVATED, K_COMPLETED, K_EXECUTE_MESSAGE, K_MESSAGE_HANDLERS, K_STATUS, K_STOPPED } from '../constants.js';
|
|
5
|
+
|
|
6
|
+
const K_PROCESSES_Q = Symbol.for('processesQ');
|
|
7
|
+
const K_PARENT = Symbol.for('definition');
|
|
8
|
+
const K_PROCESSES = Symbol.for('processes');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Drives the execution of a Definition. Activates executable processes, routes inter-process
|
|
12
|
+
* delegate messages and call activity hand-offs, and rolls completion up to the Definition.
|
|
13
|
+
* @param {import('./Definition.js').Definition} definition
|
|
14
|
+
* @param {import('../Context.js').ContextInstance} context
|
|
15
|
+
*/
|
|
16
|
+
export function DefinitionExecution(definition, context) {
|
|
17
17
|
const broker = definition.broker;
|
|
18
18
|
|
|
19
|
-
this[
|
|
19
|
+
this[K_PARENT] = definition;
|
|
20
20
|
this.id = definition.id;
|
|
21
21
|
this.type = definition.type;
|
|
22
22
|
this.broker = broker;
|
|
@@ -24,7 +24,9 @@ export default function DefinitionExecution(definition, context) {
|
|
|
24
24
|
this.context = context;
|
|
25
25
|
|
|
26
26
|
const processes = context.getProcesses();
|
|
27
|
+
/** @type {Set<string>} */
|
|
27
28
|
const ids = new Set();
|
|
29
|
+
/** @type {Set<import('../process/Process.js').Process>} */
|
|
28
30
|
const executable = new Set();
|
|
29
31
|
for (const bp of processes) {
|
|
30
32
|
bp.environment.assignVariables(environment.variables);
|
|
@@ -33,7 +35,7 @@ export default function DefinitionExecution(definition, context) {
|
|
|
33
35
|
if (bp.isExecutable) executable.add(bp);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
|
-
this[
|
|
38
|
+
this[K_PROCESSES] = {
|
|
37
39
|
processes,
|
|
38
40
|
ids,
|
|
39
41
|
executable,
|
|
@@ -44,13 +46,13 @@ export default function DefinitionExecution(definition, context) {
|
|
|
44
46
|
broker.assertExchange('execution', 'topic', { autoDelete: false, durable: true });
|
|
45
47
|
|
|
46
48
|
this.executionId = undefined;
|
|
47
|
-
this[
|
|
48
|
-
this[
|
|
49
|
-
this[
|
|
50
|
-
this[
|
|
51
|
-
this[
|
|
49
|
+
this[K_COMPLETED] = false;
|
|
50
|
+
this[K_STOPPED] = false;
|
|
51
|
+
this[K_ACTIVATED] = false;
|
|
52
|
+
this[K_STATUS] = 'init';
|
|
53
|
+
this[K_PROCESSES_Q] = undefined;
|
|
52
54
|
|
|
53
|
-
this[
|
|
55
|
+
this[K_MESSAGE_HANDLERS] = {
|
|
54
56
|
onApiMessage: this._onApiMessage.bind(this),
|
|
55
57
|
onCallActivity: this._onCallActivity.bind(this),
|
|
56
58
|
onCancelCallActivity: this._onCancelCallActivity.bind(this),
|
|
@@ -64,38 +66,38 @@ export default function DefinitionExecution(definition, context) {
|
|
|
64
66
|
Object.defineProperties(DefinitionExecution.prototype, {
|
|
65
67
|
stopped: {
|
|
66
68
|
get() {
|
|
67
|
-
return this[
|
|
69
|
+
return this[K_STOPPED];
|
|
68
70
|
},
|
|
69
71
|
},
|
|
70
72
|
completed: {
|
|
71
73
|
get() {
|
|
72
|
-
return this[
|
|
74
|
+
return this[K_COMPLETED];
|
|
73
75
|
},
|
|
74
76
|
},
|
|
75
77
|
status: {
|
|
76
78
|
get() {
|
|
77
|
-
return this[
|
|
79
|
+
return this[K_STATUS];
|
|
78
80
|
},
|
|
79
81
|
},
|
|
80
82
|
processes: {
|
|
81
83
|
get() {
|
|
82
|
-
return [...this[
|
|
84
|
+
return [...this[K_PROCESSES].running];
|
|
83
85
|
},
|
|
84
86
|
},
|
|
85
87
|
postponedCount: {
|
|
86
88
|
get() {
|
|
87
|
-
return this[
|
|
89
|
+
return this[K_PROCESSES].postponed.size;
|
|
88
90
|
},
|
|
89
91
|
},
|
|
90
92
|
isRunning: {
|
|
91
93
|
get() {
|
|
92
|
-
return this[
|
|
94
|
+
return this[K_ACTIVATED];
|
|
93
95
|
},
|
|
94
96
|
},
|
|
95
97
|
activityStatus: {
|
|
96
98
|
get() {
|
|
97
99
|
let status = 'idle';
|
|
98
|
-
const running = this[
|
|
100
|
+
const running = this[K_PROCESSES].running;
|
|
99
101
|
if (!running.size) return status;
|
|
100
102
|
|
|
101
103
|
for (const bp of running) {
|
|
@@ -119,26 +121,32 @@ Object.defineProperties(DefinitionExecution.prototype, {
|
|
|
119
121
|
},
|
|
120
122
|
});
|
|
121
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Activate executable processes and start the definition execution. Resumes if the message
|
|
126
|
+
* is redelivered. When `content.processId` is set, only that process is started.
|
|
127
|
+
* @param {import('#types').ElementBrokerMessage} executeMessage
|
|
128
|
+
* @throws {Error} when message or executionId is missing
|
|
129
|
+
*/
|
|
122
130
|
DefinitionExecution.prototype.execute = function execute(executeMessage) {
|
|
123
131
|
if (!executeMessage) throw new Error('Definition execution requires message');
|
|
124
132
|
const content = executeMessage.content;
|
|
125
133
|
const executionId = (this.executionId = content.executionId);
|
|
126
134
|
if (!executionId) throw new Error('Definition execution requires execution id');
|
|
127
135
|
|
|
128
|
-
this[
|
|
136
|
+
this[K_EXECUTE_MESSAGE] = cloneMessage(executeMessage, {
|
|
129
137
|
executionId,
|
|
130
138
|
state: 'start',
|
|
131
139
|
});
|
|
132
140
|
|
|
133
|
-
this[
|
|
141
|
+
this[K_STOPPED] = false;
|
|
134
142
|
|
|
135
|
-
this[
|
|
143
|
+
this[K_PROCESSES_Q] = this.broker.assertQueue(`execute-${executionId}-q`, { durable: true, autoDelete: false });
|
|
136
144
|
|
|
137
145
|
if (executeMessage.fields.redelivered) {
|
|
138
146
|
return this.resume();
|
|
139
147
|
}
|
|
140
148
|
|
|
141
|
-
const { running, executable } = this[
|
|
149
|
+
const { running, executable } = this[K_PROCESSES];
|
|
142
150
|
|
|
143
151
|
if (content.processId) {
|
|
144
152
|
const startWithProcess = this.getProcessById(content.processId);
|
|
@@ -157,35 +165,43 @@ DefinitionExecution.prototype.execute = function execute(executeMessage) {
|
|
|
157
165
|
return true;
|
|
158
166
|
};
|
|
159
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Resume after recover by reactivating running processes.
|
|
170
|
+
*/
|
|
160
171
|
DefinitionExecution.prototype.resume = function resume() {
|
|
161
|
-
this._debug(`resume ${this[
|
|
172
|
+
this._debug(`resume ${this[K_STATUS]} definition execution`);
|
|
162
173
|
|
|
163
|
-
if (this[
|
|
174
|
+
if (this[K_COMPLETED]) return this._complete('completed');
|
|
164
175
|
|
|
165
|
-
const { running, postponed } = this[
|
|
176
|
+
const { running, postponed } = this[K_PROCESSES];
|
|
166
177
|
this._activate(running);
|
|
167
178
|
postponed.clear();
|
|
168
|
-
this[
|
|
179
|
+
this[K_PROCESSES_Q].consume(this[K_MESSAGE_HANDLERS].onProcessMessage, {
|
|
169
180
|
prefetch: 1000,
|
|
170
181
|
consumerTag: `_definition-activity-${this.executionId}`,
|
|
171
182
|
});
|
|
172
183
|
|
|
173
|
-
if (this[
|
|
184
|
+
if (this[K_COMPLETED]) return;
|
|
174
185
|
|
|
175
186
|
for (const bp of running) bp.resume();
|
|
176
187
|
};
|
|
177
188
|
|
|
189
|
+
/**
|
|
190
|
+
* Restore execution state captured by getState. Reinstates running processes from the snapshot.
|
|
191
|
+
* @param {import('#types').DefinitionExecutionState} [state]
|
|
192
|
+
* @returns {this}
|
|
193
|
+
*/
|
|
178
194
|
DefinitionExecution.prototype.recover = function recover(state) {
|
|
179
195
|
if (!state) return this;
|
|
180
196
|
this.executionId = state.executionId;
|
|
181
197
|
|
|
182
|
-
this[
|
|
183
|
-
this[
|
|
184
|
-
this[
|
|
198
|
+
this[K_STOPPED] = state.stopped;
|
|
199
|
+
this[K_COMPLETED] = state.completed;
|
|
200
|
+
this[K_STATUS] = state.status;
|
|
185
201
|
|
|
186
|
-
this._debug(`recover ${this[
|
|
202
|
+
this._debug(`recover ${this[K_STATUS]} definition execution`);
|
|
187
203
|
|
|
188
|
-
const running = this[
|
|
204
|
+
const running = this[K_PROCESSES].running;
|
|
189
205
|
running.clear();
|
|
190
206
|
|
|
191
207
|
const ids = new Set();
|
|
@@ -207,12 +223,19 @@ DefinitionExecution.prototype.recover = function recover(state) {
|
|
|
207
223
|
return this;
|
|
208
224
|
};
|
|
209
225
|
|
|
226
|
+
/**
|
|
227
|
+
* Stop the running execution via the api.
|
|
228
|
+
*/
|
|
210
229
|
DefinitionExecution.prototype.stop = function stop() {
|
|
211
230
|
this.getApi().stop();
|
|
212
231
|
};
|
|
213
232
|
|
|
233
|
+
/**
|
|
234
|
+
* Get every process in the definition (running first, then any non-running by id).
|
|
235
|
+
* @returns {import('../process/Process.js').Process[]}
|
|
236
|
+
*/
|
|
214
237
|
DefinitionExecution.prototype.getProcesses = function getProcesses() {
|
|
215
|
-
const { running, processes } = this[
|
|
238
|
+
const { running, processes } = this[K_PROCESSES];
|
|
216
239
|
const result = [...running];
|
|
217
240
|
for (const bp of processes) {
|
|
218
241
|
if (!result.find((runningBp) => bp.id === runningBp.id)) result.push(bp);
|
|
@@ -220,45 +243,73 @@ DefinitionExecution.prototype.getProcesses = function getProcesses() {
|
|
|
220
243
|
return result;
|
|
221
244
|
};
|
|
222
245
|
|
|
246
|
+
/**
|
|
247
|
+
* @param {string} processId
|
|
248
|
+
*/
|
|
223
249
|
DefinitionExecution.prototype.getProcessById = function getProcessById(processId) {
|
|
224
250
|
return this.getProcesses().find((bp) => bp.id === processId);
|
|
225
251
|
};
|
|
226
252
|
|
|
253
|
+
/**
|
|
254
|
+
* Get every process matching the given id (call activities can spawn duplicates).
|
|
255
|
+
* @param {string} processId
|
|
256
|
+
*/
|
|
227
257
|
DefinitionExecution.prototype.getProcessesById = function getProcessesById(processId) {
|
|
228
258
|
return this.getProcesses().filter((bp) => bp.id === processId);
|
|
229
259
|
};
|
|
230
260
|
|
|
261
|
+
/**
|
|
262
|
+
* @param {string} processExecutionId
|
|
263
|
+
* @returns {import('../process/Process.js').Process | undefined}
|
|
264
|
+
*/
|
|
231
265
|
DefinitionExecution.prototype.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
|
|
232
|
-
for (const bp of this[
|
|
266
|
+
for (const bp of this[K_PROCESSES].running) {
|
|
233
267
|
if (bp.executionId === processExecutionId) return bp;
|
|
234
268
|
}
|
|
235
269
|
};
|
|
236
270
|
|
|
271
|
+
/**
|
|
272
|
+
* Get processes that have an executionId, i.e. are currently running.
|
|
273
|
+
* @returns {import('../process/Process.js').Process[]}
|
|
274
|
+
*/
|
|
237
275
|
DefinitionExecution.prototype.getRunningProcesses = function getRunningProcesses() {
|
|
238
|
-
return [...this[
|
|
276
|
+
return [...this[K_PROCESSES].running].filter((bp) => bp.executionId);
|
|
239
277
|
};
|
|
240
278
|
|
|
279
|
+
/**
|
|
280
|
+
* Get processes flagged executable in the definition.
|
|
281
|
+
* @returns {import('../process/Process.js').Process[]}
|
|
282
|
+
*/
|
|
241
283
|
DefinitionExecution.prototype.getExecutableProcesses = function getExecutableProcesses() {
|
|
242
|
-
return [...this[
|
|
284
|
+
return [...this[K_PROCESSES].executable];
|
|
243
285
|
};
|
|
244
286
|
|
|
287
|
+
/**
|
|
288
|
+
* Snapshot execution state for recover.
|
|
289
|
+
* @returns {import('#types').DefinitionExecutionState}
|
|
290
|
+
*/
|
|
245
291
|
DefinitionExecution.prototype.getState = function getState() {
|
|
246
292
|
const processes = [];
|
|
247
|
-
for (const bp of this[
|
|
293
|
+
for (const bp of this[K_PROCESSES].running) {
|
|
248
294
|
processes.push(bp.getState());
|
|
249
295
|
}
|
|
250
296
|
|
|
251
297
|
return {
|
|
252
298
|
executionId: this.executionId,
|
|
253
|
-
stopped: this[
|
|
254
|
-
completed: this[
|
|
255
|
-
status: this[
|
|
299
|
+
stopped: this[K_STOPPED],
|
|
300
|
+
completed: this[K_COMPLETED],
|
|
301
|
+
status: this[K_STATUS],
|
|
256
302
|
processes,
|
|
257
303
|
};
|
|
258
304
|
};
|
|
259
305
|
|
|
306
|
+
/**
|
|
307
|
+
* Resolve a Definition Api or, when the message belongs to a child process, its process Api.
|
|
308
|
+
* @param {import('#types').ElementBrokerMessage} [apiMessage]
|
|
309
|
+
* @returns {import('#types').IApi<import('./Definition.js').Definition>}
|
|
310
|
+
*/
|
|
260
311
|
DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
|
|
261
|
-
if (!apiMessage) apiMessage = this[
|
|
312
|
+
if (!apiMessage) apiMessage = this[K_EXECUTE_MESSAGE] || { content: this._createMessage() };
|
|
262
313
|
|
|
263
314
|
const content = apiMessage.content;
|
|
264
315
|
if (content.executionId !== this.executionId) {
|
|
@@ -266,7 +317,7 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
|
|
|
266
317
|
}
|
|
267
318
|
|
|
268
319
|
const api = DefinitionApi(this.broker, apiMessage);
|
|
269
|
-
const postponed = this[
|
|
320
|
+
const postponed = this[K_PROCESSES].postponed;
|
|
270
321
|
const self = this;
|
|
271
322
|
|
|
272
323
|
api.getExecuting = function getExecuting() {
|
|
@@ -281,16 +332,22 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
|
|
|
281
332
|
return api;
|
|
282
333
|
};
|
|
283
334
|
|
|
335
|
+
/**
|
|
336
|
+
* List currently postponed activities across every running process.
|
|
337
|
+
* @param {import('#types').filterPostponed} [filterFn]
|
|
338
|
+
* @returns {import('#types').IApi<import('#types').Activity>}
|
|
339
|
+
*/
|
|
284
340
|
DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
|
|
285
341
|
let result = [];
|
|
286
|
-
for (const bp of this[
|
|
342
|
+
for (const bp of this[K_PROCESSES].running) {
|
|
287
343
|
result = result.concat(bp.getPostponed(...args));
|
|
288
344
|
}
|
|
289
345
|
return result;
|
|
290
346
|
};
|
|
291
347
|
|
|
348
|
+
/** @internal */
|
|
292
349
|
DefinitionExecution.prototype._start = function start() {
|
|
293
|
-
const { ids, executable, postponed } = this[
|
|
350
|
+
const { ids, executable, postponed } = this[K_PROCESSES];
|
|
294
351
|
if (!ids.size) {
|
|
295
352
|
return this._complete('completed');
|
|
296
353
|
}
|
|
@@ -299,29 +356,31 @@ DefinitionExecution.prototype._start = function start() {
|
|
|
299
356
|
return this._complete('error', { error: new Error('No executable process') });
|
|
300
357
|
}
|
|
301
358
|
|
|
302
|
-
this[
|
|
359
|
+
this[K_STATUS] = 'start';
|
|
303
360
|
|
|
304
361
|
for (const bp of executable) bp.init();
|
|
305
362
|
for (const bp of executable) bp.run();
|
|
306
363
|
|
|
307
364
|
postponed.clear();
|
|
308
|
-
this[
|
|
365
|
+
this[K_PROCESSES_Q].assertConsumer(this[K_MESSAGE_HANDLERS].onProcessMessage, {
|
|
309
366
|
prefetch: 1000,
|
|
310
367
|
consumerTag: `_definition-activity-${this.executionId}`,
|
|
311
368
|
});
|
|
312
369
|
};
|
|
313
370
|
|
|
371
|
+
/** @internal */
|
|
314
372
|
DefinitionExecution.prototype._activate = function activate(processList) {
|
|
315
|
-
this.broker.subscribeTmp('api', '#', this[
|
|
373
|
+
this.broker.subscribeTmp('api', '#', this[K_MESSAGE_HANDLERS].onApiMessage, {
|
|
316
374
|
noAck: true,
|
|
317
375
|
consumerTag: '_definition-api-consumer',
|
|
318
376
|
});
|
|
319
377
|
for (const bp of processList) this._activateProcess(bp);
|
|
320
|
-
this[
|
|
378
|
+
this[K_ACTIVATED] = true;
|
|
321
379
|
};
|
|
322
380
|
|
|
381
|
+
/** @internal */
|
|
323
382
|
DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
324
|
-
const handlers = this[
|
|
383
|
+
const handlers = this[K_MESSAGE_HANDLERS];
|
|
325
384
|
const broker = bp.broker;
|
|
326
385
|
|
|
327
386
|
broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
@@ -351,12 +410,13 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
|
351
410
|
});
|
|
352
411
|
};
|
|
353
412
|
|
|
413
|
+
/** @internal */
|
|
354
414
|
DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
355
415
|
const message = cloneMessage(originalMessage);
|
|
356
416
|
const content = message.content;
|
|
357
417
|
const parent = (content.parent = content.parent || {});
|
|
358
418
|
|
|
359
|
-
const isDirectChild = this[
|
|
419
|
+
const isDirectChild = this[K_PROCESSES].ids.has(content.id);
|
|
360
420
|
if (isDirectChild) {
|
|
361
421
|
parent.executionId = this.executionId;
|
|
362
422
|
} else {
|
|
@@ -366,16 +426,18 @@ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey,
|
|
|
366
426
|
this.broker.publish('event', routingKey, content, { ...message.properties, mandatory: false });
|
|
367
427
|
if (!isDirectChild) return;
|
|
368
428
|
|
|
369
|
-
this[
|
|
429
|
+
this[K_PROCESSES_Q].queueMessage(message.fields, cloneContent(content), message.properties);
|
|
370
430
|
};
|
|
371
431
|
|
|
432
|
+
/** @internal */
|
|
372
433
|
DefinitionExecution.prototype._deactivate = function deactivate() {
|
|
373
434
|
this.broker.cancel('_definition-api-consumer');
|
|
374
435
|
this.broker.cancel(`_definition-activity-${this.executionId}`);
|
|
375
|
-
for (const bp of this[
|
|
376
|
-
this[
|
|
436
|
+
for (const bp of this[K_PROCESSES].running) this._deactivateProcess(bp);
|
|
437
|
+
this[K_ACTIVATED] = false;
|
|
377
438
|
};
|
|
378
439
|
|
|
440
|
+
/** @internal */
|
|
379
441
|
DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp) {
|
|
380
442
|
bp.broker.cancel('_definition-outbound-message-consumer');
|
|
381
443
|
bp.broker.cancel('_definition-activity-consumer');
|
|
@@ -384,6 +446,7 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
|
|
|
384
446
|
bp.broker.cancel('_definition-call-cancel-consumer');
|
|
385
447
|
};
|
|
386
448
|
|
|
449
|
+
/** @internal */
|
|
387
450
|
DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
388
451
|
const content = message.content;
|
|
389
452
|
const isRedelivered = message.fields.redelivered;
|
|
@@ -405,7 +468,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
405
468
|
|
|
406
469
|
switch (routingKey) {
|
|
407
470
|
case 'process.enter':
|
|
408
|
-
this[
|
|
471
|
+
this[K_STATUS] = 'executing';
|
|
409
472
|
break;
|
|
410
473
|
case 'process.discarded': {
|
|
411
474
|
if (inbound?.length) {
|
|
@@ -442,7 +505,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
442
505
|
{ mandatory: true, type: 'error' }
|
|
443
506
|
);
|
|
444
507
|
} else {
|
|
445
|
-
for (const bp of new Set(this[
|
|
508
|
+
for (const bp of new Set(this[K_PROCESSES].running)) {
|
|
446
509
|
if (bp.id !== childId) bp.stop();
|
|
447
510
|
}
|
|
448
511
|
|
|
@@ -455,9 +518,10 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
455
518
|
}
|
|
456
519
|
};
|
|
457
520
|
|
|
521
|
+
/** @internal */
|
|
458
522
|
DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
459
523
|
let previousMsg;
|
|
460
|
-
const postponed = this[
|
|
524
|
+
const postponed = this[K_PROCESSES].postponed;
|
|
461
525
|
for (const msg of postponed) {
|
|
462
526
|
if (msg.content.executionId === message.content.executionId) {
|
|
463
527
|
previousMsg = msg;
|
|
@@ -470,6 +534,7 @@ DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(
|
|
|
470
534
|
if (postponeMessage) postponed.add(message);
|
|
471
535
|
};
|
|
472
536
|
|
|
537
|
+
/** @internal */
|
|
473
538
|
DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(message) {
|
|
474
539
|
this._stateChangeMessage(message, false);
|
|
475
540
|
if (message.fields.redelivered) return message.ack();
|
|
@@ -488,35 +553,37 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
|
|
|
488
553
|
}
|
|
489
554
|
};
|
|
490
555
|
|
|
556
|
+
/** @internal */
|
|
491
557
|
DefinitionExecution.prototype._onStopped = function onStopped(message) {
|
|
492
|
-
const running = this[
|
|
558
|
+
const running = this[K_PROCESSES].running;
|
|
493
559
|
this._debug(`stop definition execution (stop process executions ${running.size})`);
|
|
494
|
-
this[
|
|
560
|
+
this[K_PROCESSES_Q].close();
|
|
495
561
|
for (const bp of new Set(running)) bp.stop();
|
|
496
562
|
this._deactivate();
|
|
497
563
|
|
|
498
|
-
this[
|
|
564
|
+
this[K_STOPPED] = true;
|
|
499
565
|
return this.broker.publish(
|
|
500
566
|
'execution',
|
|
501
567
|
`execution.stopped.${this.executionId}`,
|
|
502
|
-
cloneContent(this[
|
|
568
|
+
cloneContent(this[K_EXECUTE_MESSAGE].content, {
|
|
503
569
|
...message.content,
|
|
504
570
|
}),
|
|
505
571
|
{ type: 'stopped', persistent: false }
|
|
506
572
|
);
|
|
507
573
|
};
|
|
508
574
|
|
|
575
|
+
/** @internal */
|
|
509
576
|
DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
510
577
|
const messageType = message.properties.type;
|
|
511
578
|
const delegate = message.properties.delegate;
|
|
512
579
|
|
|
513
580
|
if (delegate && this.id === message.content.id) {
|
|
514
|
-
const referenceId =
|
|
581
|
+
const referenceId = message.content.message?.id;
|
|
515
582
|
this._startProcessesByMessage({ referenceId, referenceType: messageType });
|
|
516
583
|
}
|
|
517
584
|
|
|
518
585
|
if (delegate) {
|
|
519
|
-
for (const bp of new Set(this[
|
|
586
|
+
for (const bp of new Set(this[K_PROCESSES].running)) {
|
|
520
587
|
bp.broker.publish('api', routingKey, cloneContent(message.content), message.properties);
|
|
521
588
|
}
|
|
522
589
|
}
|
|
@@ -524,12 +591,13 @@ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey,
|
|
|
524
591
|
if (this.executionId !== message.content.executionId) return;
|
|
525
592
|
|
|
526
593
|
if (messageType === 'stop') {
|
|
527
|
-
this[
|
|
594
|
+
this[K_PROCESSES_Q].queueMessage({ routingKey: 'execution.stop' }, cloneContent(message.content), { persistent: false });
|
|
528
595
|
}
|
|
529
596
|
};
|
|
530
597
|
|
|
598
|
+
/** @internal */
|
|
531
599
|
DefinitionExecution.prototype._startProcessesByMessage = function startProcessesByMessage(reference) {
|
|
532
|
-
const { processes: bps, running } = this[
|
|
600
|
+
const { processes: bps, running } = this[K_PROCESSES];
|
|
533
601
|
if (bps.length < 2) return;
|
|
534
602
|
|
|
535
603
|
for (const bp of bps) {
|
|
@@ -557,6 +625,7 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
|
|
|
557
625
|
}
|
|
558
626
|
};
|
|
559
627
|
|
|
628
|
+
/** @internal */
|
|
560
629
|
DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(routingKey, message) {
|
|
561
630
|
const content = message.content;
|
|
562
631
|
const { target, source } = content;
|
|
@@ -584,12 +653,13 @@ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(ro
|
|
|
584
653
|
targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
|
|
585
654
|
|
|
586
655
|
this._activateProcess(targetProcess);
|
|
587
|
-
this[
|
|
656
|
+
this[K_PROCESSES].running.add(targetProcess);
|
|
588
657
|
targetProcess.init();
|
|
589
658
|
targetProcess.run();
|
|
590
659
|
targetProcess.sendMessage(message);
|
|
591
660
|
};
|
|
592
661
|
|
|
662
|
+
/** @internal */
|
|
593
663
|
DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingKey, message) {
|
|
594
664
|
const content = message.content;
|
|
595
665
|
const { calledElement, id: fromId, executionId: fromExecutionId, name: fromName, parent: fromParent } = content;
|
|
@@ -616,11 +686,12 @@ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingK
|
|
|
616
686
|
this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
617
687
|
|
|
618
688
|
this._activateProcess(targetProcess);
|
|
619
|
-
this[
|
|
689
|
+
this[K_PROCESSES].running.add(targetProcess);
|
|
620
690
|
targetProcess.init(bpExecutionId);
|
|
621
691
|
targetProcess.run({ inbound: [cloneContent(content)] });
|
|
622
692
|
};
|
|
623
693
|
|
|
694
|
+
/** @internal */
|
|
624
695
|
DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
|
|
625
696
|
const { calledElement, id: fromId, executionId: fromExecutionId, parent: fromParent } = message.content;
|
|
626
697
|
if (!calledElement) return;
|
|
@@ -645,6 +716,7 @@ DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActiv
|
|
|
645
716
|
}
|
|
646
717
|
};
|
|
647
718
|
|
|
719
|
+
/** @internal */
|
|
648
720
|
DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
|
|
649
721
|
const content = executeMessage.content;
|
|
650
722
|
const messageType = executeMessage.properties.type;
|
|
@@ -682,20 +754,22 @@ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(ro
|
|
|
682
754
|
);
|
|
683
755
|
};
|
|
684
756
|
|
|
757
|
+
/** @internal */
|
|
685
758
|
DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
|
|
686
759
|
const bp = this.getProcessByExecutionId(processExecutionId);
|
|
687
|
-
if (bp) this[
|
|
760
|
+
if (bp) this[K_PROCESSES].running.delete(bp);
|
|
688
761
|
return bp;
|
|
689
762
|
};
|
|
690
763
|
|
|
764
|
+
/** @internal */
|
|
691
765
|
DefinitionExecution.prototype._complete = function complete(completionType, content, options) {
|
|
692
766
|
this._deactivate();
|
|
693
|
-
const stateMessage = this[
|
|
767
|
+
const stateMessage = this[K_EXECUTE_MESSAGE];
|
|
694
768
|
this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
|
|
695
769
|
if (!content) content = this._createMessage();
|
|
696
|
-
this[
|
|
697
|
-
this[
|
|
698
|
-
this.broker.deleteQueue(this[
|
|
770
|
+
this[K_COMPLETED] = true;
|
|
771
|
+
this[K_STATUS] = completionType;
|
|
772
|
+
this.broker.deleteQueue(this[K_PROCESSES_Q].name);
|
|
699
773
|
|
|
700
774
|
return this.broker.publish(
|
|
701
775
|
'execution',
|
|
@@ -710,16 +784,18 @@ DefinitionExecution.prototype._complete = function complete(completionType, cont
|
|
|
710
784
|
);
|
|
711
785
|
};
|
|
712
786
|
|
|
787
|
+
/** @internal */
|
|
713
788
|
DefinitionExecution.prototype._createMessage = function createMessage(content) {
|
|
714
789
|
return {
|
|
715
790
|
id: this.id,
|
|
716
791
|
type: this.type,
|
|
717
792
|
executionId: this.executionId,
|
|
718
|
-
status: this[
|
|
793
|
+
status: this[K_STATUS],
|
|
719
794
|
...content,
|
|
720
795
|
};
|
|
721
796
|
};
|
|
722
797
|
|
|
798
|
+
/** @internal */
|
|
723
799
|
DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
|
|
724
800
|
const content = message.content;
|
|
725
801
|
let api = this._getProcessApiByExecutionId(content.executionId, message);
|
|
@@ -738,12 +814,14 @@ DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
|
|
|
738
814
|
}
|
|
739
815
|
};
|
|
740
816
|
|
|
817
|
+
/** @internal */
|
|
741
818
|
DefinitionExecution.prototype._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
|
|
742
819
|
const processInstance = this.getProcessByExecutionId(parentExecutionId);
|
|
743
820
|
if (!processInstance) return;
|
|
744
821
|
return processInstance.getApi(message);
|
|
745
822
|
};
|
|
746
823
|
|
|
824
|
+
/** @internal */
|
|
747
825
|
DefinitionExecution.prototype._debug = function debug(logMessage) {
|
|
748
|
-
this[
|
|
826
|
+
this[K_PARENT].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
749
827
|
};
|
package/src/error/BpmnError.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* BPMN error.
|
|
3
|
+
* @param {import('moddle-context-serializer').SerializableElement} errorDef
|
|
4
|
+
* @param {import('#types').ContextInstance} context
|
|
5
|
+
*/
|
|
6
|
+
export function BpmnErrorActivity(errorDef, context) {
|
|
2
7
|
const { id, type, name = 'BpmnError', behaviour = {} } = errorDef;
|
|
3
8
|
const { environment } = context;
|
|
4
9
|
|
|
@@ -10,8 +15,13 @@ export default function BpmnErrorActivity(errorDef, context) {
|
|
|
10
15
|
resolve,
|
|
11
16
|
};
|
|
12
17
|
|
|
18
|
+
/**
|
|
19
|
+
* @param {import('#types').ElementBrokerMessage} executionMessage
|
|
20
|
+
* @param {Error} [error]
|
|
21
|
+
*/
|
|
13
22
|
function resolve(executionMessage, error) {
|
|
14
23
|
const resolveCtx = { ...executionMessage, error };
|
|
24
|
+
/** @type {{ id?: string; type?: string; messageType: string; name: string; code: string | undefined; inner?: Error }} */
|
|
15
25
|
const result = {
|
|
16
26
|
id,
|
|
17
27
|
type,
|