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