bpmn-elements 17.3.0 → 18.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +434 -233
- 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 +27 -0
- package/dist/definition/Definition.js +187 -64
- package/dist/definition/DefinitionExecution.js +198 -84
- 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 +1 -1
- 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 +176 -77
- package/dist/process/ProcessExecution.js +397 -178
- 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 +372 -218
- 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 +21 -0
- package/src/definition/Definition.js +165 -63
- package/src/definition/DefinitionExecution.js +164 -85
- 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 +1 -1
- 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 +157 -74
- package/src/process/ProcessExecution.js +363 -176
- 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 +2619 -84
- package/types/interfaces.d.ts +638 -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,44 @@ 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
|
|
|
178
|
-
|
|
189
|
+
/**
|
|
190
|
+
* Restore execution state captured by getState. Reinstates running processes from the snapshot.
|
|
191
|
+
* @param {import('#types').DefinitionExecutionState} [state]
|
|
192
|
+
* @param {number} [recoveredVersion] State version
|
|
193
|
+
* @returns {this}
|
|
194
|
+
*/
|
|
195
|
+
DefinitionExecution.prototype.recover = function recover(state, recoveredVersion) {
|
|
179
196
|
if (!state) return this;
|
|
180
197
|
this.executionId = state.executionId;
|
|
181
198
|
|
|
182
|
-
this[
|
|
183
|
-
this[
|
|
184
|
-
this[
|
|
199
|
+
this[K_STOPPED] = state.stopped;
|
|
200
|
+
this[K_COMPLETED] = state.completed;
|
|
201
|
+
this[K_STATUS] = state.status;
|
|
185
202
|
|
|
186
|
-
this._debug(`recover ${this[
|
|
203
|
+
this._debug(`recover ${this[K_STATUS]} definition execution`);
|
|
187
204
|
|
|
188
|
-
const running = this[
|
|
205
|
+
const running = this[K_PROCESSES].running;
|
|
189
206
|
running.clear();
|
|
190
207
|
|
|
191
208
|
const ids = new Set();
|
|
@@ -200,19 +217,26 @@ DefinitionExecution.prototype.recover = function recover(state) {
|
|
|
200
217
|
if (!bp) continue;
|
|
201
218
|
|
|
202
219
|
ids.add(bpid);
|
|
203
|
-
bp.recover(bpState);
|
|
220
|
+
bp.recover(bpState, recoveredVersion);
|
|
204
221
|
running.add(bp);
|
|
205
222
|
}
|
|
206
223
|
|
|
207
224
|
return this;
|
|
208
225
|
};
|
|
209
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Stop the running execution via the api.
|
|
229
|
+
*/
|
|
210
230
|
DefinitionExecution.prototype.stop = function stop() {
|
|
211
231
|
this.getApi().stop();
|
|
212
232
|
};
|
|
213
233
|
|
|
234
|
+
/**
|
|
235
|
+
* Get every process in the definition (running first, then any non-running by id).
|
|
236
|
+
* @returns {import('../process/Process.js').Process[]}
|
|
237
|
+
*/
|
|
214
238
|
DefinitionExecution.prototype.getProcesses = function getProcesses() {
|
|
215
|
-
const { running, processes } = this[
|
|
239
|
+
const { running, processes } = this[K_PROCESSES];
|
|
216
240
|
const result = [...running];
|
|
217
241
|
for (const bp of processes) {
|
|
218
242
|
if (!result.find((runningBp) => bp.id === runningBp.id)) result.push(bp);
|
|
@@ -220,45 +244,73 @@ DefinitionExecution.prototype.getProcesses = function getProcesses() {
|
|
|
220
244
|
return result;
|
|
221
245
|
};
|
|
222
246
|
|
|
247
|
+
/**
|
|
248
|
+
* @param {string} processId
|
|
249
|
+
*/
|
|
223
250
|
DefinitionExecution.prototype.getProcessById = function getProcessById(processId) {
|
|
224
251
|
return this.getProcesses().find((bp) => bp.id === processId);
|
|
225
252
|
};
|
|
226
253
|
|
|
254
|
+
/**
|
|
255
|
+
* Get every process matching the given id (call activities can spawn duplicates).
|
|
256
|
+
* @param {string} processId
|
|
257
|
+
*/
|
|
227
258
|
DefinitionExecution.prototype.getProcessesById = function getProcessesById(processId) {
|
|
228
259
|
return this.getProcesses().filter((bp) => bp.id === processId);
|
|
229
260
|
};
|
|
230
261
|
|
|
262
|
+
/**
|
|
263
|
+
* @param {string} processExecutionId
|
|
264
|
+
* @returns {import('../process/Process.js').Process | undefined}
|
|
265
|
+
*/
|
|
231
266
|
DefinitionExecution.prototype.getProcessByExecutionId = function getProcessByExecutionId(processExecutionId) {
|
|
232
|
-
for (const bp of this[
|
|
267
|
+
for (const bp of this[K_PROCESSES].running) {
|
|
233
268
|
if (bp.executionId === processExecutionId) return bp;
|
|
234
269
|
}
|
|
235
270
|
};
|
|
236
271
|
|
|
272
|
+
/**
|
|
273
|
+
* Get processes that have an executionId, i.e. are currently running.
|
|
274
|
+
* @returns {import('../process/Process.js').Process[]}
|
|
275
|
+
*/
|
|
237
276
|
DefinitionExecution.prototype.getRunningProcesses = function getRunningProcesses() {
|
|
238
|
-
return [...this[
|
|
277
|
+
return [...this[K_PROCESSES].running].filter((bp) => bp.executionId);
|
|
239
278
|
};
|
|
240
279
|
|
|
280
|
+
/**
|
|
281
|
+
* Get processes flagged executable in the definition.
|
|
282
|
+
* @returns {import('../process/Process.js').Process[]}
|
|
283
|
+
*/
|
|
241
284
|
DefinitionExecution.prototype.getExecutableProcesses = function getExecutableProcesses() {
|
|
242
|
-
return [...this[
|
|
285
|
+
return [...this[K_PROCESSES].executable];
|
|
243
286
|
};
|
|
244
287
|
|
|
288
|
+
/**
|
|
289
|
+
* Snapshot execution state for recover.
|
|
290
|
+
* @returns {import('#types').DefinitionExecutionState}
|
|
291
|
+
*/
|
|
245
292
|
DefinitionExecution.prototype.getState = function getState() {
|
|
246
293
|
const processes = [];
|
|
247
|
-
for (const bp of this[
|
|
294
|
+
for (const bp of this[K_PROCESSES].running) {
|
|
248
295
|
processes.push(bp.getState());
|
|
249
296
|
}
|
|
250
297
|
|
|
251
298
|
return {
|
|
252
299
|
executionId: this.executionId,
|
|
253
|
-
stopped: this[
|
|
254
|
-
completed: this[
|
|
255
|
-
status: this[
|
|
300
|
+
stopped: this[K_STOPPED],
|
|
301
|
+
completed: this[K_COMPLETED],
|
|
302
|
+
status: this[K_STATUS],
|
|
256
303
|
processes,
|
|
257
304
|
};
|
|
258
305
|
};
|
|
259
306
|
|
|
307
|
+
/**
|
|
308
|
+
* Resolve a Definition Api or, when the message belongs to a child process, its process Api.
|
|
309
|
+
* @param {import('#types').ElementBrokerMessage} [apiMessage]
|
|
310
|
+
* @returns {import('#types').IApi<import('./Definition.js').Definition>}
|
|
311
|
+
*/
|
|
260
312
|
DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
|
|
261
|
-
if (!apiMessage) apiMessage = this[
|
|
313
|
+
if (!apiMessage) apiMessage = this[K_EXECUTE_MESSAGE] || { content: this._createMessage() };
|
|
262
314
|
|
|
263
315
|
const content = apiMessage.content;
|
|
264
316
|
if (content.executionId !== this.executionId) {
|
|
@@ -266,7 +318,7 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
|
|
|
266
318
|
}
|
|
267
319
|
|
|
268
320
|
const api = DefinitionApi(this.broker, apiMessage);
|
|
269
|
-
const postponed = this[
|
|
321
|
+
const postponed = this[K_PROCESSES].postponed;
|
|
270
322
|
const self = this;
|
|
271
323
|
|
|
272
324
|
api.getExecuting = function getExecuting() {
|
|
@@ -281,16 +333,22 @@ DefinitionExecution.prototype.getApi = function getApi(apiMessage) {
|
|
|
281
333
|
return api;
|
|
282
334
|
};
|
|
283
335
|
|
|
336
|
+
/**
|
|
337
|
+
* List currently postponed activities across every running process.
|
|
338
|
+
* @param {import('#types').filterPostponed} [filterFn]
|
|
339
|
+
* @returns {import('#types').IApi<import('#types').Activity>}
|
|
340
|
+
*/
|
|
284
341
|
DefinitionExecution.prototype.getPostponed = function getPostponed(...args) {
|
|
285
342
|
let result = [];
|
|
286
|
-
for (const bp of this[
|
|
343
|
+
for (const bp of this[K_PROCESSES].running) {
|
|
287
344
|
result = result.concat(bp.getPostponed(...args));
|
|
288
345
|
}
|
|
289
346
|
return result;
|
|
290
347
|
};
|
|
291
348
|
|
|
349
|
+
/** @internal */
|
|
292
350
|
DefinitionExecution.prototype._start = function start() {
|
|
293
|
-
const { ids, executable, postponed } = this[
|
|
351
|
+
const { ids, executable, postponed } = this[K_PROCESSES];
|
|
294
352
|
if (!ids.size) {
|
|
295
353
|
return this._complete('completed');
|
|
296
354
|
}
|
|
@@ -299,29 +357,31 @@ DefinitionExecution.prototype._start = function start() {
|
|
|
299
357
|
return this._complete('error', { error: new Error('No executable process') });
|
|
300
358
|
}
|
|
301
359
|
|
|
302
|
-
this[
|
|
360
|
+
this[K_STATUS] = 'start';
|
|
303
361
|
|
|
304
362
|
for (const bp of executable) bp.init();
|
|
305
363
|
for (const bp of executable) bp.run();
|
|
306
364
|
|
|
307
365
|
postponed.clear();
|
|
308
|
-
this[
|
|
366
|
+
this[K_PROCESSES_Q].assertConsumer(this[K_MESSAGE_HANDLERS].onProcessMessage, {
|
|
309
367
|
prefetch: 1000,
|
|
310
368
|
consumerTag: `_definition-activity-${this.executionId}`,
|
|
311
369
|
});
|
|
312
370
|
};
|
|
313
371
|
|
|
372
|
+
/** @internal */
|
|
314
373
|
DefinitionExecution.prototype._activate = function activate(processList) {
|
|
315
|
-
this.broker.subscribeTmp('api', '#', this[
|
|
374
|
+
this.broker.subscribeTmp('api', '#', this[K_MESSAGE_HANDLERS].onApiMessage, {
|
|
316
375
|
noAck: true,
|
|
317
376
|
consumerTag: '_definition-api-consumer',
|
|
318
377
|
});
|
|
319
378
|
for (const bp of processList) this._activateProcess(bp);
|
|
320
|
-
this[
|
|
379
|
+
this[K_ACTIVATED] = true;
|
|
321
380
|
};
|
|
322
381
|
|
|
382
|
+
/** @internal */
|
|
323
383
|
DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
324
|
-
const handlers = this[
|
|
384
|
+
const handlers = this[K_MESSAGE_HANDLERS];
|
|
325
385
|
const broker = bp.broker;
|
|
326
386
|
|
|
327
387
|
broker.subscribeTmp('message', 'message.outbound', handlers.onMessageOutbound, {
|
|
@@ -351,12 +411,13 @@ DefinitionExecution.prototype._activateProcess = function activateProcess(bp) {
|
|
|
351
411
|
});
|
|
352
412
|
};
|
|
353
413
|
|
|
414
|
+
/** @internal */
|
|
354
415
|
DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey, originalMessage) {
|
|
355
416
|
const message = cloneMessage(originalMessage);
|
|
356
417
|
const content = message.content;
|
|
357
418
|
const parent = (content.parent = content.parent || {});
|
|
358
419
|
|
|
359
|
-
const isDirectChild = this[
|
|
420
|
+
const isDirectChild = this[K_PROCESSES].ids.has(content.id);
|
|
360
421
|
if (isDirectChild) {
|
|
361
422
|
parent.executionId = this.executionId;
|
|
362
423
|
} else {
|
|
@@ -366,16 +427,18 @@ DefinitionExecution.prototype._onChildEvent = function onChildEvent(routingKey,
|
|
|
366
427
|
this.broker.publish('event', routingKey, content, { ...message.properties, mandatory: false });
|
|
367
428
|
if (!isDirectChild) return;
|
|
368
429
|
|
|
369
|
-
this[
|
|
430
|
+
this[K_PROCESSES_Q].queueMessage(message.fields, cloneContent(content), message.properties);
|
|
370
431
|
};
|
|
371
432
|
|
|
433
|
+
/** @internal */
|
|
372
434
|
DefinitionExecution.prototype._deactivate = function deactivate() {
|
|
373
435
|
this.broker.cancel('_definition-api-consumer');
|
|
374
436
|
this.broker.cancel(`_definition-activity-${this.executionId}`);
|
|
375
|
-
for (const bp of this[
|
|
376
|
-
this[
|
|
437
|
+
for (const bp of this[K_PROCESSES].running) this._deactivateProcess(bp);
|
|
438
|
+
this[K_ACTIVATED] = false;
|
|
377
439
|
};
|
|
378
440
|
|
|
441
|
+
/** @internal */
|
|
379
442
|
DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp) {
|
|
380
443
|
bp.broker.cancel('_definition-outbound-message-consumer');
|
|
381
444
|
bp.broker.cancel('_definition-activity-consumer');
|
|
@@ -384,6 +447,7 @@ DefinitionExecution.prototype._deactivateProcess = function deactivateProcess(bp
|
|
|
384
447
|
bp.broker.cancel('_definition-call-cancel-consumer');
|
|
385
448
|
};
|
|
386
449
|
|
|
450
|
+
/** @internal */
|
|
387
451
|
DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(routingKey, message) {
|
|
388
452
|
const content = message.content;
|
|
389
453
|
const isRedelivered = message.fields.redelivered;
|
|
@@ -405,7 +469,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
405
469
|
|
|
406
470
|
switch (routingKey) {
|
|
407
471
|
case 'process.enter':
|
|
408
|
-
this[
|
|
472
|
+
this[K_STATUS] = 'executing';
|
|
409
473
|
break;
|
|
410
474
|
case 'process.discarded': {
|
|
411
475
|
if (inbound?.length) {
|
|
@@ -442,7 +506,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
442
506
|
{ mandatory: true, type: 'error' }
|
|
443
507
|
);
|
|
444
508
|
} else {
|
|
445
|
-
for (const bp of new Set(this[
|
|
509
|
+
for (const bp of new Set(this[K_PROCESSES].running)) {
|
|
446
510
|
if (bp.id !== childId) bp.stop();
|
|
447
511
|
}
|
|
448
512
|
|
|
@@ -455,9 +519,10 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
|
|
|
455
519
|
}
|
|
456
520
|
};
|
|
457
521
|
|
|
522
|
+
/** @internal */
|
|
458
523
|
DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(message, postponeMessage) {
|
|
459
524
|
let previousMsg;
|
|
460
|
-
const postponed = this[
|
|
525
|
+
const postponed = this[K_PROCESSES].postponed;
|
|
461
526
|
for (const msg of postponed) {
|
|
462
527
|
if (msg.content.executionId === message.content.executionId) {
|
|
463
528
|
previousMsg = msg;
|
|
@@ -470,6 +535,7 @@ DefinitionExecution.prototype._stateChangeMessage = function stateChangeMessage(
|
|
|
470
535
|
if (postponeMessage) postponed.add(message);
|
|
471
536
|
};
|
|
472
537
|
|
|
538
|
+
/** @internal */
|
|
473
539
|
DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(message) {
|
|
474
540
|
this._stateChangeMessage(message, false);
|
|
475
541
|
if (message.fields.redelivered) return message.ack();
|
|
@@ -488,35 +554,37 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
|
|
|
488
554
|
}
|
|
489
555
|
};
|
|
490
556
|
|
|
557
|
+
/** @internal */
|
|
491
558
|
DefinitionExecution.prototype._onStopped = function onStopped(message) {
|
|
492
|
-
const running = this[
|
|
559
|
+
const running = this[K_PROCESSES].running;
|
|
493
560
|
this._debug(`stop definition execution (stop process executions ${running.size})`);
|
|
494
|
-
this[
|
|
561
|
+
this[K_PROCESSES_Q].close();
|
|
495
562
|
for (const bp of new Set(running)) bp.stop();
|
|
496
563
|
this._deactivate();
|
|
497
564
|
|
|
498
|
-
this[
|
|
565
|
+
this[K_STOPPED] = true;
|
|
499
566
|
return this.broker.publish(
|
|
500
567
|
'execution',
|
|
501
568
|
`execution.stopped.${this.executionId}`,
|
|
502
|
-
cloneContent(this[
|
|
569
|
+
cloneContent(this[K_EXECUTE_MESSAGE].content, {
|
|
503
570
|
...message.content,
|
|
504
571
|
}),
|
|
505
572
|
{ type: 'stopped', persistent: false }
|
|
506
573
|
);
|
|
507
574
|
};
|
|
508
575
|
|
|
576
|
+
/** @internal */
|
|
509
577
|
DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
510
578
|
const messageType = message.properties.type;
|
|
511
579
|
const delegate = message.properties.delegate;
|
|
512
580
|
|
|
513
581
|
if (delegate && this.id === message.content.id) {
|
|
514
|
-
const referenceId =
|
|
582
|
+
const referenceId = message.content.message?.id;
|
|
515
583
|
this._startProcessesByMessage({ referenceId, referenceType: messageType });
|
|
516
584
|
}
|
|
517
585
|
|
|
518
586
|
if (delegate) {
|
|
519
|
-
for (const bp of new Set(this[
|
|
587
|
+
for (const bp of new Set(this[K_PROCESSES].running)) {
|
|
520
588
|
bp.broker.publish('api', routingKey, cloneContent(message.content), message.properties);
|
|
521
589
|
}
|
|
522
590
|
}
|
|
@@ -524,12 +592,13 @@ DefinitionExecution.prototype._onApiMessage = function onApiMessage(routingKey,
|
|
|
524
592
|
if (this.executionId !== message.content.executionId) return;
|
|
525
593
|
|
|
526
594
|
if (messageType === 'stop') {
|
|
527
|
-
this[
|
|
595
|
+
this[K_PROCESSES_Q].queueMessage({ routingKey: 'execution.stop' }, cloneContent(message.content), { persistent: false });
|
|
528
596
|
}
|
|
529
597
|
};
|
|
530
598
|
|
|
599
|
+
/** @internal */
|
|
531
600
|
DefinitionExecution.prototype._startProcessesByMessage = function startProcessesByMessage(reference) {
|
|
532
|
-
const { processes: bps, running } = this[
|
|
601
|
+
const { processes: bps, running } = this[K_PROCESSES];
|
|
533
602
|
if (bps.length < 2) return;
|
|
534
603
|
|
|
535
604
|
for (const bp of bps) {
|
|
@@ -557,6 +626,7 @@ DefinitionExecution.prototype._startProcessesByMessage = function startProcesses
|
|
|
557
626
|
}
|
|
558
627
|
};
|
|
559
628
|
|
|
629
|
+
/** @internal */
|
|
560
630
|
DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(routingKey, message) {
|
|
561
631
|
const content = message.content;
|
|
562
632
|
const { target, source } = content;
|
|
@@ -584,12 +654,13 @@ DefinitionExecution.prototype._onMessageOutbound = function onMessageOutbound(ro
|
|
|
584
654
|
targetProcess = targetProcess || this.context.getNewProcessById(target.processId);
|
|
585
655
|
|
|
586
656
|
this._activateProcess(targetProcess);
|
|
587
|
-
this[
|
|
657
|
+
this[K_PROCESSES].running.add(targetProcess);
|
|
588
658
|
targetProcess.init();
|
|
589
659
|
targetProcess.run();
|
|
590
660
|
targetProcess.sendMessage(message);
|
|
591
661
|
};
|
|
592
662
|
|
|
663
|
+
/** @internal */
|
|
593
664
|
DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingKey, message) {
|
|
594
665
|
const content = message.content;
|
|
595
666
|
const { calledElement, id: fromId, executionId: fromExecutionId, name: fromName, parent: fromParent } = content;
|
|
@@ -616,11 +687,12 @@ DefinitionExecution.prototype._onCallActivity = function onCallActivity(routingK
|
|
|
616
687
|
this._debug(`call from <${fromParent.id}.${fromId}> to <${calledElement}>`);
|
|
617
688
|
|
|
618
689
|
this._activateProcess(targetProcess);
|
|
619
|
-
this[
|
|
690
|
+
this[K_PROCESSES].running.add(targetProcess);
|
|
620
691
|
targetProcess.init(bpExecutionId);
|
|
621
692
|
targetProcess.run({ inbound: [cloneContent(content)] });
|
|
622
693
|
};
|
|
623
694
|
|
|
695
|
+
/** @internal */
|
|
624
696
|
DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActivity(routingKey, message) {
|
|
625
697
|
const { calledElement, id: fromId, executionId: fromExecutionId, parent: fromParent } = message.content;
|
|
626
698
|
if (!calledElement) return;
|
|
@@ -645,6 +717,7 @@ DefinitionExecution.prototype._onCancelCallActivity = function onCancelCallActiv
|
|
|
645
717
|
}
|
|
646
718
|
};
|
|
647
719
|
|
|
720
|
+
/** @internal */
|
|
648
721
|
DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(routingKey, executeMessage) {
|
|
649
722
|
const content = executeMessage.content;
|
|
650
723
|
const messageType = executeMessage.properties.type;
|
|
@@ -682,20 +755,22 @@ DefinitionExecution.prototype._onDelegateMessage = function onDelegateMessage(ro
|
|
|
682
755
|
);
|
|
683
756
|
};
|
|
684
757
|
|
|
758
|
+
/** @internal */
|
|
685
759
|
DefinitionExecution.prototype._removeProcessByExecutionId = function removeProcessByExecutionId(processExecutionId) {
|
|
686
760
|
const bp = this.getProcessByExecutionId(processExecutionId);
|
|
687
|
-
if (bp) this[
|
|
761
|
+
if (bp) this[K_PROCESSES].running.delete(bp);
|
|
688
762
|
return bp;
|
|
689
763
|
};
|
|
690
764
|
|
|
765
|
+
/** @internal */
|
|
691
766
|
DefinitionExecution.prototype._complete = function complete(completionType, content, options) {
|
|
692
767
|
this._deactivate();
|
|
693
|
-
const stateMessage = this[
|
|
768
|
+
const stateMessage = this[K_EXECUTE_MESSAGE];
|
|
694
769
|
this._debug(`definition execution ${completionType} in ${Date.now() - stateMessage.properties.timestamp}ms`);
|
|
695
770
|
if (!content) content = this._createMessage();
|
|
696
|
-
this[
|
|
697
|
-
this[
|
|
698
|
-
this.broker.deleteQueue(this[
|
|
771
|
+
this[K_COMPLETED] = true;
|
|
772
|
+
this[K_STATUS] = completionType;
|
|
773
|
+
this.broker.deleteQueue(this[K_PROCESSES_Q].name);
|
|
699
774
|
|
|
700
775
|
return this.broker.publish(
|
|
701
776
|
'execution',
|
|
@@ -710,16 +785,18 @@ DefinitionExecution.prototype._complete = function complete(completionType, cont
|
|
|
710
785
|
);
|
|
711
786
|
};
|
|
712
787
|
|
|
788
|
+
/** @internal */
|
|
713
789
|
DefinitionExecution.prototype._createMessage = function createMessage(content) {
|
|
714
790
|
return {
|
|
715
791
|
id: this.id,
|
|
716
792
|
type: this.type,
|
|
717
793
|
executionId: this.executionId,
|
|
718
|
-
status: this[
|
|
794
|
+
status: this[K_STATUS],
|
|
719
795
|
...content,
|
|
720
796
|
};
|
|
721
797
|
};
|
|
722
798
|
|
|
799
|
+
/** @internal */
|
|
723
800
|
DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
|
|
724
801
|
const content = message.content;
|
|
725
802
|
let api = this._getProcessApiByExecutionId(content.executionId, message);
|
|
@@ -738,12 +815,14 @@ DefinitionExecution.prototype._getProcessApi = function getProcessApi(message) {
|
|
|
738
815
|
}
|
|
739
816
|
};
|
|
740
817
|
|
|
818
|
+
/** @internal */
|
|
741
819
|
DefinitionExecution.prototype._getProcessApiByExecutionId = function getProcessApiByExecutionId(parentExecutionId, message) {
|
|
742
820
|
const processInstance = this.getProcessByExecutionId(parentExecutionId);
|
|
743
821
|
if (!processInstance) return;
|
|
744
822
|
return processInstance.getApi(message);
|
|
745
823
|
};
|
|
746
824
|
|
|
825
|
+
/** @internal */
|
|
747
826
|
DefinitionExecution.prototype._debug = function debug(logMessage) {
|
|
748
|
-
this[
|
|
827
|
+
this[K_PARENT].logger.debug(`<${this.executionId} (${this.id})> ${logMessage}`);
|
|
749
828
|
};
|
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,
|