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
package/dist/process/Process.js
CHANGED
|
@@ -4,25 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Process = Process;
|
|
7
|
-
|
|
8
|
-
var _ProcessExecution = _interopRequireDefault(require("./ProcessExecution.js"));
|
|
7
|
+
var _ProcessExecution = require("./ProcessExecution.js");
|
|
9
8
|
var _shared = require("../shared.js");
|
|
10
9
|
var _Api = require("../Api.js");
|
|
11
10
|
var _EventBroker = require("../EventBroker.js");
|
|
12
11
|
var _messageHelper = require("../messageHelper.js");
|
|
13
12
|
var _Errors = require("../error/Errors.js");
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const kStatus = Symbol.for('status');
|
|
24
|
-
const kStopped = Symbol.for('stopped');
|
|
25
|
-
var _default = exports.default = Process;
|
|
13
|
+
var _constants = require("../constants.js");
|
|
14
|
+
const K_LANES = Symbol.for('lanes');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Owns one `<bpmn:process>`. Wraps the structural definition and orchestrates flow traversal,
|
|
18
|
+
* joins, and parallel activation through ProcessExecution.
|
|
19
|
+
* @param {import('moddle-context-serializer').Process} processDef
|
|
20
|
+
* @param {import('#types').ContextInstance} context
|
|
21
|
+
*/
|
|
26
22
|
function Process(processDef, context) {
|
|
27
23
|
const {
|
|
28
24
|
id,
|
|
@@ -34,22 +30,21 @@ function Process(processDef, context) {
|
|
|
34
30
|
this.id = id;
|
|
35
31
|
this.type = type;
|
|
36
32
|
this.name = name;
|
|
33
|
+
/** @type {import('#types').ElementParent} */
|
|
37
34
|
this.parent = parent ? (0, _messageHelper.cloneParent)(parent) : {};
|
|
35
|
+
/** @type {import('moddle-context-serializer').Process['behaviour']} */
|
|
38
36
|
this.behaviour = behaviour;
|
|
39
|
-
|
|
40
|
-
isExecutable
|
|
41
|
-
} = behaviour;
|
|
42
|
-
this.isExecutable = isExecutable;
|
|
37
|
+
this.isExecutable = behaviour.isExecutable;
|
|
43
38
|
const environment = this.environment = context.environment;
|
|
44
39
|
this.context = context;
|
|
45
|
-
this[
|
|
40
|
+
this[_constants.K_COUNTERS] = {
|
|
46
41
|
completed: 0,
|
|
47
42
|
discarded: 0
|
|
48
43
|
};
|
|
49
|
-
this[
|
|
50
|
-
this[
|
|
51
|
-
this[
|
|
52
|
-
this[
|
|
44
|
+
this[_constants.K_CONSUMING] = false;
|
|
45
|
+
this[_constants.K_EXECUTION] = new Map();
|
|
46
|
+
this[_constants.K_STATUS] = undefined;
|
|
47
|
+
this[_constants.K_STOPPED] = false;
|
|
53
48
|
const {
|
|
54
49
|
broker,
|
|
55
50
|
on,
|
|
@@ -60,79 +55,90 @@ function Process(processDef, context) {
|
|
|
60
55
|
this.on = on;
|
|
61
56
|
this.once = once;
|
|
62
57
|
this.waitFor = waitFor;
|
|
63
|
-
this[
|
|
58
|
+
this[_constants.K_MESSAGE_HANDLERS] = {
|
|
64
59
|
onApiMessage: this._onApiMessage.bind(this),
|
|
65
60
|
onRunMessage: this._onRunMessage.bind(this),
|
|
66
61
|
onExecutionMessage: this._onExecutionMessage.bind(this)
|
|
67
62
|
};
|
|
68
63
|
this.logger = environment.Logger(type.toLowerCase());
|
|
69
64
|
if (behaviour.lanes) {
|
|
70
|
-
this[
|
|
65
|
+
this[K_LANES] = behaviour.lanes.map(lane => new lane.Behaviour(this, lane));
|
|
71
66
|
}
|
|
72
|
-
this[
|
|
67
|
+
this[_constants.K_EXTENSIONS] = context.loadExtensions(this);
|
|
73
68
|
}
|
|
74
69
|
Object.defineProperties(Process.prototype, {
|
|
75
70
|
counters: {
|
|
76
71
|
get() {
|
|
77
72
|
return {
|
|
78
|
-
...this[
|
|
73
|
+
...this[_constants.K_COUNTERS]
|
|
79
74
|
};
|
|
80
75
|
}
|
|
81
76
|
},
|
|
82
77
|
lanes: {
|
|
83
78
|
get() {
|
|
84
|
-
return this[
|
|
79
|
+
return this[K_LANES]?.slice();
|
|
85
80
|
}
|
|
86
81
|
},
|
|
87
82
|
extensions: {
|
|
88
83
|
get() {
|
|
89
|
-
return this[
|
|
84
|
+
return this[_constants.K_EXTENSIONS];
|
|
90
85
|
}
|
|
91
86
|
},
|
|
92
87
|
stopped: {
|
|
93
88
|
get() {
|
|
94
|
-
return this[
|
|
89
|
+
return this[_constants.K_STOPPED];
|
|
95
90
|
}
|
|
96
91
|
},
|
|
97
92
|
isRunning: {
|
|
98
93
|
get() {
|
|
99
|
-
if (!this[
|
|
94
|
+
if (!this[_constants.K_CONSUMING]) return false;
|
|
100
95
|
return !!this.status;
|
|
101
96
|
}
|
|
102
97
|
},
|
|
103
98
|
executionId: {
|
|
104
99
|
get() {
|
|
105
|
-
const exec = this[
|
|
100
|
+
const exec = this[_constants.K_EXECUTION];
|
|
106
101
|
return exec.get('executionId') || exec.get('initExecutionId');
|
|
107
102
|
}
|
|
108
103
|
},
|
|
109
104
|
execution: {
|
|
110
105
|
get() {
|
|
111
|
-
return this[
|
|
106
|
+
return this[_constants.K_EXECUTION].get('execution');
|
|
112
107
|
}
|
|
113
108
|
},
|
|
114
109
|
status: {
|
|
115
110
|
get() {
|
|
116
|
-
return this[
|
|
111
|
+
return this[_constants.K_STATUS];
|
|
117
112
|
}
|
|
118
113
|
},
|
|
119
114
|
activityStatus: {
|
|
120
115
|
get() {
|
|
121
|
-
return this[
|
|
116
|
+
return this[_constants.K_EXECUTION].get('execution')?.activityStatus || 'idle';
|
|
122
117
|
}
|
|
123
118
|
}
|
|
124
119
|
});
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Allocate an executionId and emit init event without starting the run.
|
|
123
|
+
* @param {string} [useAsExecutionId] Override for the generated execution id
|
|
124
|
+
*/
|
|
125
125
|
Process.prototype.init = function init(useAsExecutionId) {
|
|
126
126
|
const initExecutionId = useAsExecutionId || (0, _shared.getUniqueId)(this.id);
|
|
127
|
-
this[
|
|
127
|
+
this[_constants.K_EXECUTION].set('initExecutionId', initExecutionId);
|
|
128
128
|
this._debug(`initialized with executionId <${initExecutionId}>`);
|
|
129
129
|
this._publishEvent('init', this._createMessage({
|
|
130
130
|
executionId: initExecutionId
|
|
131
131
|
}));
|
|
132
132
|
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Start running the process by publishing run.enter, run.start, and run.execute.
|
|
136
|
+
* @param {Record<string, any>} [runContent] Optional content merged into the run message
|
|
137
|
+
* @throws {Error} when the process is already running
|
|
138
|
+
*/
|
|
133
139
|
Process.prototype.run = function run(runContent) {
|
|
134
140
|
if (this.isRunning) throw new Error(`process <${this.id}> is already running`);
|
|
135
|
-
const exec = this[
|
|
141
|
+
const exec = this[_constants.K_EXECUTION];
|
|
136
142
|
const executionId = exec.get('initExecutionId') || (0, _shared.getUniqueId)(this.id);
|
|
137
143
|
exec.delete('initExecutionId');
|
|
138
144
|
exec.set('executionId', executionId);
|
|
@@ -146,10 +152,16 @@ Process.prototype.run = function run(runContent) {
|
|
|
146
152
|
broker.publish('run', 'run.execute', (0, _messageHelper.cloneContent)(content));
|
|
147
153
|
this._activateRunConsumers();
|
|
148
154
|
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Resume after recover by republishing the last run message.
|
|
158
|
+
* @returns {this}
|
|
159
|
+
* @throws {Error} when called on a running process
|
|
160
|
+
*/
|
|
149
161
|
Process.prototype.resume = function resume() {
|
|
150
162
|
if (this.isRunning) throw new Error(`cannot resume running process <${this.id}>`);
|
|
151
163
|
if (!this.status) return this;
|
|
152
|
-
this[
|
|
164
|
+
this[_constants.K_STOPPED] = false;
|
|
153
165
|
const content = this._createMessage();
|
|
154
166
|
this.broker.publish('run', 'run.resume', content, {
|
|
155
167
|
persistent: false
|
|
@@ -157,6 +169,11 @@ Process.prototype.resume = function resume() {
|
|
|
157
169
|
this._activateRunConsumers();
|
|
158
170
|
return this;
|
|
159
171
|
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Snapshot process state for recover.
|
|
175
|
+
* @returns {import('#types').ProcessState}
|
|
176
|
+
*/
|
|
160
177
|
Process.prototype.getState = function getState() {
|
|
161
178
|
return {
|
|
162
179
|
id: this.id,
|
|
@@ -170,54 +187,89 @@ Process.prototype.getState = function getState() {
|
|
|
170
187
|
execution: this.execution?.getState()
|
|
171
188
|
};
|
|
172
189
|
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Restore process state captured by getState.
|
|
193
|
+
* @param {import('#types').ProcessState} [state]
|
|
194
|
+
* @returns {this}
|
|
195
|
+
* @throws {Error} when called on a running process
|
|
196
|
+
*/
|
|
173
197
|
Process.prototype.recover = function recover(state) {
|
|
174
198
|
if (this.isRunning) throw new Error(`cannot recover running process <${this.id}>`);
|
|
175
199
|
if (!state) return this;
|
|
176
|
-
this[
|
|
177
|
-
this[
|
|
178
|
-
const exec = this[
|
|
200
|
+
this[_constants.K_STOPPED] = !!state.stopped;
|
|
201
|
+
this[_constants.K_STATUS] = state.status;
|
|
202
|
+
const exec = this[_constants.K_EXECUTION];
|
|
179
203
|
exec.set('executionId', state.executionId);
|
|
180
|
-
this[
|
|
181
|
-
...this[
|
|
204
|
+
this[_constants.K_COUNTERS] = {
|
|
205
|
+
...this[_constants.K_COUNTERS],
|
|
182
206
|
...state.counters
|
|
183
207
|
};
|
|
184
208
|
this.environment.recover(state.environment);
|
|
185
209
|
if (state.execution) {
|
|
186
|
-
exec.set('execution', new _ProcessExecution.
|
|
210
|
+
exec.set('execution', new _ProcessExecution.ProcessExecution(this, this.context).recover(state.execution));
|
|
187
211
|
}
|
|
188
212
|
this.broker.recover(state.broker);
|
|
189
213
|
return this;
|
|
190
214
|
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Walk activity graph from the given start id, or every start activity when omitted.
|
|
218
|
+
* @param {string} [startId]
|
|
219
|
+
* @returns {import('#types').ShakeResult}
|
|
220
|
+
*/
|
|
191
221
|
Process.prototype.shake = function shake(startId) {
|
|
192
222
|
if (this.isRunning) return this.execution.shake(startId);
|
|
193
|
-
return new _ProcessExecution.
|
|
223
|
+
return new _ProcessExecution.ProcessExecution(this, this.context).shake(startId);
|
|
194
224
|
};
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Stop the process if running.
|
|
228
|
+
*/
|
|
195
229
|
Process.prototype.stop = function stop() {
|
|
196
230
|
if (!this.isRunning) return;
|
|
197
231
|
this.getApi().stop();
|
|
198
232
|
};
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Resolve a Process Api wrapper, preferring the running execution if any.
|
|
236
|
+
* @param {import('#types').ElementBrokerMessage} [message]
|
|
237
|
+
* @returns {import('#types').IApi<this>}
|
|
238
|
+
*/
|
|
199
239
|
Process.prototype.getApi = function getApi(message) {
|
|
200
240
|
const execution = this.execution;
|
|
201
241
|
if (execution) return execution.getApi(message);
|
|
202
|
-
return (0, _Api.ProcessApi)(this.broker, message || this[
|
|
242
|
+
return (0, _Api.ProcessApi)(this.broker, message || this[_constants.K_STATE_MESSAGE]);
|
|
203
243
|
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Send a delegated signal to the running process.
|
|
247
|
+
* @param {import('#types').signalMessage} [message]
|
|
248
|
+
*/
|
|
204
249
|
Process.prototype.signal = function signal(message) {
|
|
205
250
|
return this.getApi().signal(message, {
|
|
206
251
|
delegate: true
|
|
207
252
|
});
|
|
208
253
|
};
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Cancel a running activity inside the process by delegated api message.
|
|
257
|
+
* @param {import('#types').signalMessage} [message]
|
|
258
|
+
*/
|
|
209
259
|
Process.prototype.cancelActivity = function cancelActivity(message) {
|
|
210
260
|
return this.getApi().cancel(message, {
|
|
211
261
|
delegate: true
|
|
212
262
|
});
|
|
213
263
|
};
|
|
264
|
+
|
|
265
|
+
/** @internal */
|
|
214
266
|
Process.prototype._activateRunConsumers = function activateRunConsumers() {
|
|
215
|
-
this[
|
|
267
|
+
this[_constants.K_CONSUMING] = true;
|
|
216
268
|
const broker = this.broker;
|
|
217
269
|
const {
|
|
218
270
|
onApiMessage,
|
|
219
271
|
onRunMessage
|
|
220
|
-
} = this[
|
|
272
|
+
} = this[_constants.K_MESSAGE_HANDLERS];
|
|
221
273
|
broker.subscribeTmp('api', `process.*.${this.executionId}`, onApiMessage, {
|
|
222
274
|
noAck: true,
|
|
223
275
|
consumerTag: '_process-api',
|
|
@@ -228,13 +280,17 @@ Process.prototype._activateRunConsumers = function activateRunConsumers() {
|
|
|
228
280
|
consumerTag: '_process-run'
|
|
229
281
|
});
|
|
230
282
|
};
|
|
283
|
+
|
|
284
|
+
/** @internal */
|
|
231
285
|
Process.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
232
286
|
const broker = this.broker;
|
|
233
287
|
broker.cancel('_process-api');
|
|
234
288
|
broker.cancel('_process-run');
|
|
235
289
|
broker.cancel('_process-execution');
|
|
236
|
-
this[
|
|
290
|
+
this[_constants.K_CONSUMING] = false;
|
|
237
291
|
};
|
|
292
|
+
|
|
293
|
+
/** @internal */
|
|
238
294
|
Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
|
|
239
295
|
const {
|
|
240
296
|
content,
|
|
@@ -243,45 +299,45 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
243
299
|
if (routingKey === 'run.resume') {
|
|
244
300
|
return this._onResumeMessage(message);
|
|
245
301
|
}
|
|
246
|
-
this[
|
|
302
|
+
this[_constants.K_STATE_MESSAGE] = message;
|
|
247
303
|
switch (routingKey) {
|
|
248
304
|
case 'run.enter':
|
|
249
305
|
{
|
|
250
306
|
this._debug('enter');
|
|
251
|
-
this[
|
|
307
|
+
this[_constants.K_STATUS] = 'entered';
|
|
252
308
|
if (fields.redelivered) break;
|
|
253
|
-
this[
|
|
309
|
+
this[_constants.K_EXECUTION].delete('execution');
|
|
254
310
|
this._publishEvent('enter', content);
|
|
255
311
|
break;
|
|
256
312
|
}
|
|
257
313
|
case 'run.start':
|
|
258
314
|
{
|
|
259
315
|
this._debug('start');
|
|
260
|
-
this[
|
|
316
|
+
this[_constants.K_STATUS] = 'start';
|
|
261
317
|
this._publishEvent('start', content);
|
|
262
318
|
break;
|
|
263
319
|
}
|
|
264
320
|
case 'run.execute':
|
|
265
321
|
{
|
|
266
|
-
const exec = this[
|
|
267
|
-
this[
|
|
322
|
+
const exec = this[_constants.K_EXECUTION];
|
|
323
|
+
this[_constants.K_STATUS] = 'executing';
|
|
268
324
|
const executeMessage = (0, _messageHelper.cloneMessage)(message);
|
|
269
325
|
let execution = exec.get('execution');
|
|
270
326
|
if (fields.redelivered && !execution) {
|
|
271
327
|
executeMessage.fields.redelivered = undefined;
|
|
272
328
|
}
|
|
273
|
-
this[
|
|
274
|
-
this.broker.getQueue('execution-q').assertConsumer(this[
|
|
329
|
+
this[_constants.K_EXECUTE_MESSAGE] = message;
|
|
330
|
+
this.broker.getQueue('execution-q').assertConsumer(this[_constants.K_MESSAGE_HANDLERS].onExecutionMessage, {
|
|
275
331
|
exclusive: true,
|
|
276
332
|
consumerTag: '_process-execution'
|
|
277
333
|
});
|
|
278
|
-
execution = execution || new _ProcessExecution.
|
|
334
|
+
execution = execution || new _ProcessExecution.ProcessExecution(this, this.context);
|
|
279
335
|
exec.set('execution', execution);
|
|
280
336
|
return execution.execute(executeMessage);
|
|
281
337
|
}
|
|
282
338
|
case 'run.error':
|
|
283
339
|
{
|
|
284
|
-
this[
|
|
340
|
+
this[_constants.K_STATUS] = 'errored';
|
|
285
341
|
this._publishEvent('error', (0, _messageHelper.cloneContent)(content, {
|
|
286
342
|
error: fields.redelivered ? (0, _Errors.makeErrorFromMessage)(message) : content.error
|
|
287
343
|
}));
|
|
@@ -289,26 +345,26 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
289
345
|
}
|
|
290
346
|
case 'run.end':
|
|
291
347
|
{
|
|
292
|
-
this[
|
|
348
|
+
this[_constants.K_STATUS] = 'end';
|
|
293
349
|
if (fields.redelivered) break;
|
|
294
350
|
this._debug('completed');
|
|
295
|
-
this[
|
|
351
|
+
this[_constants.K_COUNTERS].completed++;
|
|
296
352
|
this.broker.publish('run', 'run.leave', content);
|
|
297
353
|
this._publishEvent('end', content);
|
|
298
354
|
break;
|
|
299
355
|
}
|
|
300
356
|
case 'run.discarded':
|
|
301
357
|
{
|
|
302
|
-
this[
|
|
358
|
+
this[_constants.K_STATUS] = 'discarded';
|
|
303
359
|
if (fields.redelivered) break;
|
|
304
|
-
this[
|
|
360
|
+
this[_constants.K_COUNTERS].discarded++;
|
|
305
361
|
this.broker.publish('run', 'run.leave', content);
|
|
306
362
|
this._publishEvent('discarded', content);
|
|
307
363
|
break;
|
|
308
364
|
}
|
|
309
365
|
case 'run.leave':
|
|
310
366
|
{
|
|
311
|
-
this[
|
|
367
|
+
this[_constants.K_STATUS] = undefined;
|
|
312
368
|
message.ack();
|
|
313
369
|
this._deactivateRunConsumers();
|
|
314
370
|
const {
|
|
@@ -321,9 +377,11 @@ Process.prototype._onRunMessage = function onRunMessage(routingKey, message) {
|
|
|
321
377
|
}
|
|
322
378
|
message.ack();
|
|
323
379
|
};
|
|
380
|
+
|
|
381
|
+
/** @internal */
|
|
324
382
|
Process.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
325
383
|
message.ack();
|
|
326
|
-
const stateMessage = this[
|
|
384
|
+
const stateMessage = this[_constants.K_STATE_MESSAGE];
|
|
327
385
|
switch (stateMessage.fields.routingKey) {
|
|
328
386
|
case 'run.enter':
|
|
329
387
|
case 'run.start':
|
|
@@ -338,6 +396,8 @@ Process.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
|
338
396
|
this._debug(`resume from ${this.status}`);
|
|
339
397
|
return this.broker.publish('run', stateMessage.fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
|
|
340
398
|
};
|
|
399
|
+
|
|
400
|
+
/** @internal */
|
|
341
401
|
Process.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
342
402
|
const content = message.content;
|
|
343
403
|
const messageType = message.properties.type;
|
|
@@ -361,10 +421,12 @@ Process.prototype._onExecutionMessage = function onExecutionMessage(routingKey,
|
|
|
361
421
|
this.broker.publish('run', 'run.end', content);
|
|
362
422
|
}
|
|
363
423
|
}
|
|
364
|
-
const executeMessage = this[
|
|
365
|
-
this[
|
|
424
|
+
const executeMessage = this[_constants.K_EXECUTE_MESSAGE];
|
|
425
|
+
this[_constants.K_EXECUTE_MESSAGE] = null;
|
|
366
426
|
executeMessage.ack();
|
|
367
427
|
};
|
|
428
|
+
|
|
429
|
+
/** @internal */
|
|
368
430
|
Process.prototype._publishEvent = function publishEvent(state, content) {
|
|
369
431
|
const eventContent = this._createMessage({
|
|
370
432
|
...content,
|
|
@@ -375,6 +437,12 @@ Process.prototype._publishEvent = function publishEvent(state, content) {
|
|
|
375
437
|
mandatory: state === 'error'
|
|
376
438
|
});
|
|
377
439
|
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Deliver a message to a target activity or start activity that references it.
|
|
443
|
+
* Starts the process if a target is found and the process is idle.
|
|
444
|
+
* @param {import('#types').ElementBrokerMessage} message
|
|
445
|
+
*/
|
|
378
446
|
Process.prototype.sendMessage = function sendMessage(message) {
|
|
379
447
|
const messageContent = message?.content;
|
|
380
448
|
if (!messageContent) return;
|
|
@@ -393,37 +461,61 @@ Process.prototype.sendMessage = function sendMessage(message) {
|
|
|
393
461
|
delegate: true
|
|
394
462
|
});
|
|
395
463
|
};
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @param {string} childId
|
|
467
|
+
*/
|
|
396
468
|
Process.prototype.getActivityById = function getActivityById(childId) {
|
|
397
469
|
const execution = this.execution;
|
|
398
470
|
if (execution) return execution.getActivityById(childId);
|
|
399
471
|
return this.context.getActivityById(childId);
|
|
400
472
|
};
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Get every activity in the process scope.
|
|
476
|
+
*/
|
|
401
477
|
Process.prototype.getActivities = function getActivities() {
|
|
402
478
|
const execution = this.execution;
|
|
403
479
|
if (execution) return execution.getActivities();
|
|
404
480
|
return this.context.getActivities(this.id);
|
|
405
481
|
};
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* Get start activities, optionally filtered by referenced event definition.
|
|
485
|
+
* @param {import('#types').startActivityFilterOptions} [filterOptions]
|
|
486
|
+
*/
|
|
406
487
|
Process.prototype.getStartActivities = function getStartActivities(filterOptions) {
|
|
407
488
|
return this.context.getStartActivities(filterOptions, this.id);
|
|
408
489
|
};
|
|
490
|
+
|
|
491
|
+
/**
|
|
492
|
+
* Get sequence flows in the process scope.
|
|
493
|
+
*/
|
|
409
494
|
Process.prototype.getSequenceFlows = function getSequenceFlows() {
|
|
410
495
|
const execution = this.execution;
|
|
411
496
|
if (execution) return execution.getSequenceFlows();
|
|
412
497
|
return this.context.getSequenceFlows();
|
|
413
498
|
};
|
|
499
|
+
|
|
500
|
+
/**
|
|
501
|
+
* @param {string} laneId
|
|
502
|
+
* @returns {import('./Lane.js').Lane | undefined}
|
|
503
|
+
*/
|
|
414
504
|
Process.prototype.getLaneById = function getLaneById(laneId) {
|
|
415
|
-
|
|
416
|
-
if (!lanes) return;
|
|
417
|
-
return lanes.find(lane => lane.id === laneId);
|
|
505
|
+
return this[K_LANES]?.find(lane => lane.id === laneId);
|
|
418
506
|
};
|
|
507
|
+
|
|
508
|
+
/**
|
|
509
|
+
* List currently postponed activities as Api wrappers.
|
|
510
|
+
* @param {import('#types').filterPostponed} [filterFn]
|
|
511
|
+
*/
|
|
419
512
|
Process.prototype.getPostponed = function getPostponed(...args) {
|
|
420
|
-
|
|
421
|
-
if (!execution) return [];
|
|
422
|
-
return execution.getPostponed(...args);
|
|
513
|
+
return this.execution?.getPostponed(...args) || [];
|
|
423
514
|
};
|
|
515
|
+
|
|
516
|
+
/** @internal */
|
|
424
517
|
Process.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
425
|
-
|
|
426
|
-
switch (messageType) {
|
|
518
|
+
switch (message.properties.type) {
|
|
427
519
|
case 'stop':
|
|
428
520
|
{
|
|
429
521
|
if (this.execution && !this.execution.completed) return;
|
|
@@ -432,11 +524,15 @@ Process.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
|
432
524
|
}
|
|
433
525
|
}
|
|
434
526
|
};
|
|
527
|
+
|
|
528
|
+
/** @internal */
|
|
435
529
|
Process.prototype._onStop = function onStop() {
|
|
436
|
-
this[
|
|
530
|
+
this[_constants.K_STOPPED] = true;
|
|
437
531
|
this._deactivateRunConsumers();
|
|
438
532
|
return this._publishEvent('stop');
|
|
439
533
|
};
|
|
534
|
+
|
|
535
|
+
/** @internal */
|
|
440
536
|
Process.prototype._createMessage = function createMessage(override) {
|
|
441
537
|
return {
|
|
442
538
|
id: this.id,
|
|
@@ -449,6 +545,8 @@ Process.prototype._createMessage = function createMessage(override) {
|
|
|
449
545
|
...override
|
|
450
546
|
};
|
|
451
547
|
};
|
|
548
|
+
|
|
549
|
+
/** @internal */
|
|
452
550
|
Process.prototype._debug = function debug(msg) {
|
|
453
551
|
this.logger.debug(`<${this.id}> ${msg}`);
|
|
454
552
|
};
|