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
package/dist/condition.js
CHANGED
|
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.ExpressionCondition = ExpressionCondition;
|
|
7
7
|
exports.ScriptCondition = ScriptCondition;
|
|
8
|
-
var _ExecutionScope =
|
|
9
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
var _ExecutionScope = require("./activity/ExecutionScope.js");
|
|
10
9
|
/**
|
|
11
10
|
* Script condition
|
|
12
|
-
* @param {import('types').ElementBase} owner
|
|
11
|
+
* @param {import('#types').ElementBase} owner
|
|
13
12
|
* @param {any} script
|
|
14
13
|
* @param {string} language
|
|
15
14
|
*/
|
|
@@ -28,7 +27,7 @@ function ScriptCondition(owner, script, language) {
|
|
|
28
27
|
ScriptCondition.prototype.execute = function execute(message, callback) {
|
|
29
28
|
const owner = this._owner;
|
|
30
29
|
try {
|
|
31
|
-
return this._script.execute((0, _ExecutionScope.
|
|
30
|
+
return this._script.execute((0, _ExecutionScope.ExecutionScope)(owner, message), callback);
|
|
32
31
|
} catch (err) {
|
|
33
32
|
if (!callback) throw err;
|
|
34
33
|
owner.logger.error(`<${owner.id}>`, err);
|
|
@@ -38,7 +37,7 @@ ScriptCondition.prototype.execute = function execute(message, callback) {
|
|
|
38
37
|
|
|
39
38
|
/**
|
|
40
39
|
* Expression condition
|
|
41
|
-
* @param {import('types').ElementBase} owner
|
|
40
|
+
* @param {import('#types').ElementBase} owner
|
|
42
41
|
* @param {string} expression
|
|
43
42
|
*/
|
|
44
43
|
function ExpressionCondition(owner, expression) {
|
|
@@ -49,13 +48,20 @@ function ExpressionCondition(owner, expression) {
|
|
|
49
48
|
|
|
50
49
|
/**
|
|
51
50
|
* Execute
|
|
52
|
-
* @param {
|
|
51
|
+
* @param {import('#types').ElementBrokerMessage} message
|
|
53
52
|
* @param {CallableFunction} callback
|
|
54
53
|
*/
|
|
55
54
|
ExpressionCondition.prototype.execute = function execute(message, callback) {
|
|
56
55
|
const owner = this._owner;
|
|
57
56
|
try {
|
|
58
57
|
const result = owner.environment.resolveExpression(this.expression, message);
|
|
58
|
+
if (typeof result === 'function') {
|
|
59
|
+
const scope = (0, _ExecutionScope.ExecutionScope)(owner, message);
|
|
60
|
+
if (callback && result.length > 1) return result.call(owner, scope, callback);
|
|
61
|
+
const conditionResult = result.call(owner, scope);
|
|
62
|
+
if (callback) return callback(null, conditionResult);
|
|
63
|
+
return conditionResult;
|
|
64
|
+
}
|
|
59
65
|
if (callback) return callback(null, result);
|
|
60
66
|
return result;
|
|
61
67
|
} catch (err) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.K_TARGETS = exports.K_STOPPED = exports.K_STATUS = exports.K_STATE_MESSAGE = exports.K_REFERENCE_INFO = exports.K_REFERENCE_ELEMENT = exports.K_MESSAGE_Q = exports.K_MESSAGE_HANDLERS = exports.K_EXTENSIONS = exports.K_EXECUTION = exports.K_EXECUTE_MESSAGE = exports.K_COUNTERS = exports.K_CONSUMING = exports.K_COMPLETED = exports.K_ACTIVATED = void 0;
|
|
7
|
+
const K_ACTIVATED = exports.K_ACTIVATED = Symbol.for('activated');
|
|
8
|
+
const K_COMPLETED = exports.K_COMPLETED = Symbol.for('completed');
|
|
9
|
+
const K_CONSUMING = exports.K_CONSUMING = Symbol.for('consuming');
|
|
10
|
+
const K_COUNTERS = exports.K_COUNTERS = Symbol.for('counters');
|
|
11
|
+
const K_EXECUTE_MESSAGE = exports.K_EXECUTE_MESSAGE = Symbol.for('executeMessage');
|
|
12
|
+
const K_EXECUTION = exports.K_EXECUTION = Symbol.for('execution');
|
|
13
|
+
const K_EXTENSIONS = exports.K_EXTENSIONS = Symbol.for('extensions');
|
|
14
|
+
const K_MESSAGE_HANDLERS = exports.K_MESSAGE_HANDLERS = Symbol.for('messageHandlers');
|
|
15
|
+
const K_MESSAGE_Q = exports.K_MESSAGE_Q = Symbol.for('messageQ');
|
|
16
|
+
const K_REFERENCE_ELEMENT = exports.K_REFERENCE_ELEMENT = Symbol.for('referenceElement');
|
|
17
|
+
const K_REFERENCE_INFO = exports.K_REFERENCE_INFO = Symbol.for('referenceInfo');
|
|
18
|
+
const K_STATE_MESSAGE = exports.K_STATE_MESSAGE = Symbol.for('stateMessage');
|
|
19
|
+
const K_STATUS = exports.K_STATUS = Symbol.for('status');
|
|
20
|
+
const K_STOPPED = exports.K_STOPPED = Symbol.for('stopped');
|
|
21
|
+
const K_TARGETS = exports.K_TARGETS = Symbol.for('targets');
|
|
@@ -4,25 +4,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Definition = Definition;
|
|
7
|
-
|
|
8
|
-
var _DefinitionExecution = _interopRequireDefault(require("./DefinitionExecution.js"));
|
|
7
|
+
var _DefinitionExecution = require("./DefinitionExecution.js");
|
|
9
8
|
var _Api = require("../Api.js");
|
|
10
9
|
var _EventBroker = require("../EventBroker.js");
|
|
11
10
|
var _shared = require("../shared.js");
|
|
12
11
|
var _Errors = require("../error/Errors.js");
|
|
13
12
|
var _messageHelper = require("../messageHelper.js");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const kStatus = Symbol.for('status');
|
|
22
|
-
const kStopped = Symbol.for('stopped');
|
|
23
|
-
var _default = exports.default = Definition;
|
|
13
|
+
var _constants = require("../constants.js");
|
|
14
|
+
/**
|
|
15
|
+
* Top-level wrapper for an executable BPMN definition. Owns its DefinitionExecution and
|
|
16
|
+
* mediates inter-process messaging.
|
|
17
|
+
* @param {import('../Context.js').ContextInstance} context
|
|
18
|
+
* @param {import('#types').EnvironmentOptions} [options] When provided, environment is cloned and settings merged
|
|
19
|
+
*/
|
|
24
20
|
function Definition(context, options) {
|
|
25
|
-
if (!(this instanceof Definition)) return new Definition(context, options);
|
|
26
21
|
if (!context) throw new Error('No context');
|
|
27
22
|
const {
|
|
28
23
|
id,
|
|
@@ -30,24 +25,27 @@ function Definition(context, options) {
|
|
|
30
25
|
type = 'definition'
|
|
31
26
|
} = context;
|
|
32
27
|
this.id = id;
|
|
28
|
+
/** @type {string} */
|
|
33
29
|
this.type = type;
|
|
34
30
|
this.name = name;
|
|
35
|
-
|
|
31
|
+
|
|
32
|
+
/** @type {import('../Environment.js').Environment} */
|
|
33
|
+
this.environment = undefined;
|
|
36
34
|
if (options) {
|
|
37
|
-
|
|
38
|
-
this.context = context.clone(environment);
|
|
35
|
+
this.environment = context.environment.clone(options).assignSettings(options.settings);
|
|
36
|
+
this.context = context.clone(this.environment);
|
|
39
37
|
} else {
|
|
40
|
-
|
|
38
|
+
this.environment = context.environment;
|
|
41
39
|
this.context = context;
|
|
42
40
|
}
|
|
43
|
-
this[
|
|
41
|
+
this[_constants.K_COUNTERS] = {
|
|
44
42
|
completed: 0,
|
|
45
43
|
discarded: 0
|
|
46
44
|
};
|
|
47
|
-
this[
|
|
48
|
-
this[
|
|
45
|
+
this[_constants.K_STOPPED] = false;
|
|
46
|
+
this[_constants.K_EXECUTION] = new Map();
|
|
49
47
|
const onBrokerReturn = this._onBrokerReturnFn.bind(this);
|
|
50
|
-
this[
|
|
48
|
+
this[_constants.K_MESSAGE_HANDLERS] = {
|
|
51
49
|
onBrokerReturn,
|
|
52
50
|
onApiMessage: this._onApiMessage.bind(this),
|
|
53
51
|
onRunMessage: this._onRunMessage.bind(this),
|
|
@@ -67,49 +65,60 @@ function Definition(context, options) {
|
|
|
67
65
|
this.waitFor = waitFor;
|
|
68
66
|
this.emit = emit;
|
|
69
67
|
this.emitFatal = emitFatal;
|
|
70
|
-
|
|
68
|
+
|
|
69
|
+
/** @type {import('#types').ILogger} */
|
|
70
|
+
this.logger = this.environment.Logger(type.toLowerCase());
|
|
71
71
|
}
|
|
72
72
|
Object.defineProperties(Definition.prototype, {
|
|
73
73
|
counters: {
|
|
74
74
|
get() {
|
|
75
75
|
return {
|
|
76
|
-
...this[
|
|
76
|
+
...this[_constants.K_COUNTERS]
|
|
77
77
|
};
|
|
78
78
|
}
|
|
79
79
|
},
|
|
80
80
|
execution: {
|
|
81
81
|
get() {
|
|
82
|
-
return this[
|
|
82
|
+
return this[_constants.K_EXECUTION].get('execution');
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
executionId: {
|
|
86
86
|
get() {
|
|
87
|
-
return this[
|
|
87
|
+
return this[_constants.K_EXECUTION].get('executionId');
|
|
88
88
|
}
|
|
89
89
|
},
|
|
90
90
|
isRunning: {
|
|
91
91
|
get() {
|
|
92
|
-
if (!this[
|
|
92
|
+
if (!this[_constants.K_CONSUMING]) return false;
|
|
93
93
|
return !!this.status;
|
|
94
94
|
}
|
|
95
95
|
},
|
|
96
96
|
status: {
|
|
97
97
|
get() {
|
|
98
|
-
return this[
|
|
98
|
+
return this[_constants.K_STATUS];
|
|
99
99
|
}
|
|
100
100
|
},
|
|
101
101
|
stopped: {
|
|
102
102
|
get() {
|
|
103
|
-
return this[
|
|
103
|
+
return this[_constants.K_STOPPED];
|
|
104
104
|
}
|
|
105
105
|
},
|
|
106
106
|
activityStatus: {
|
|
107
107
|
get() {
|
|
108
|
-
const execution = this[
|
|
108
|
+
const execution = this[_constants.K_EXECUTION].get('execution');
|
|
109
109
|
return execution?.activityStatus || 'idle';
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
});
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Start running the definition. Accepts run options, a callback, or both.
|
|
116
|
+
* The callback fires once on leave, stop, or error.
|
|
117
|
+
* @param {Record<string, any> | import('#types').runCallback} [optionsOrCallback]
|
|
118
|
+
* @param {import('#types').runCallback} [optionalCallback]
|
|
119
|
+
* @returns {this}
|
|
120
|
+
* @throws {Error} when already running and no callback is supplied
|
|
121
|
+
*/
|
|
113
122
|
Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
|
|
114
123
|
const [runOptions, callback] = (0, _shared.getOptionsAndCallback)(optionsOrCallback, optionalCallback);
|
|
115
124
|
if (this.isRunning) {
|
|
@@ -120,7 +129,7 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
|
|
|
120
129
|
if (callback) {
|
|
121
130
|
addConsumerCallbacks(this, callback);
|
|
122
131
|
}
|
|
123
|
-
const exec = this[
|
|
132
|
+
const exec = this[_constants.K_EXECUTION];
|
|
124
133
|
const executionId = (0, _shared.getUniqueId)(this.id);
|
|
125
134
|
exec.set('executionId', executionId);
|
|
126
135
|
const content = this._createMessage({
|
|
@@ -134,13 +143,20 @@ Definition.prototype.run = function run(optionsOrCallback, optionalCallback) {
|
|
|
134
143
|
this._activateRunConsumers();
|
|
135
144
|
return this;
|
|
136
145
|
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Resume after recover by republishing the last run message. The callback fires once on
|
|
149
|
+
* leave, stop, or error.
|
|
150
|
+
* @param {import('#types').runCallback} [callback]
|
|
151
|
+
* @returns {this}
|
|
152
|
+
*/
|
|
137
153
|
Definition.prototype.resume = function resume(callback) {
|
|
138
154
|
if (this.isRunning) {
|
|
139
155
|
const err = new Error('cannot resume running definition');
|
|
140
156
|
if (callback) return callback(err);
|
|
141
157
|
throw err;
|
|
142
158
|
}
|
|
143
|
-
this[
|
|
159
|
+
this[_constants.K_STOPPED] = false;
|
|
144
160
|
if (!this.status) return this;
|
|
145
161
|
if (callback) {
|
|
146
162
|
addConsumerCallbacks(this, callback);
|
|
@@ -153,6 +169,11 @@ Definition.prototype.resume = function resume(callback) {
|
|
|
153
169
|
this._activateRunConsumers();
|
|
154
170
|
return this;
|
|
155
171
|
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Snapshot definition state for recover.
|
|
175
|
+
* @returns {import('#types').DefinitionState}
|
|
176
|
+
*/
|
|
156
177
|
Definition.prototype.getState = function getState() {
|
|
157
178
|
return this._createMessage({
|
|
158
179
|
status: this.status,
|
|
@@ -163,27 +184,42 @@ Definition.prototype.getState = function getState() {
|
|
|
163
184
|
broker: this.broker.getState(true)
|
|
164
185
|
});
|
|
165
186
|
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Restore definition state captured by getState.
|
|
190
|
+
* @param {import('#types').DefinitionState} [state]
|
|
191
|
+
* @returns {this}
|
|
192
|
+
* @throws {Error} when called on a running definition
|
|
193
|
+
*/
|
|
166
194
|
Definition.prototype.recover = function recover(state) {
|
|
167
195
|
if (this.isRunning) throw new Error('cannot recover running definition');
|
|
168
196
|
if (!state) return this;
|
|
169
|
-
this[
|
|
170
|
-
this[
|
|
171
|
-
const exec = this[
|
|
197
|
+
this[_constants.K_STOPPED] = !!state.stopped;
|
|
198
|
+
this[_constants.K_STATUS] = state.status;
|
|
199
|
+
const exec = this[_constants.K_EXECUTION];
|
|
172
200
|
exec.set('executionId', state.executionId);
|
|
173
201
|
if (state.counters) {
|
|
174
|
-
this[
|
|
175
|
-
...this[
|
|
202
|
+
this[_constants.K_COUNTERS] = {
|
|
203
|
+
...this[_constants.K_COUNTERS],
|
|
176
204
|
...state.counters
|
|
177
205
|
};
|
|
178
206
|
}
|
|
179
207
|
this.environment.recover(state.environment);
|
|
180
208
|
if (state.execution) {
|
|
181
|
-
exec.set('execution', new _DefinitionExecution.
|
|
209
|
+
exec.set('execution', new _DefinitionExecution.DefinitionExecution(this, this.context).recover(state.execution));
|
|
182
210
|
}
|
|
183
211
|
this.broker.recover(state.broker);
|
|
184
212
|
return this;
|
|
185
213
|
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Walk activity graphs to discover sequences. Limited to the activity's owning process
|
|
217
|
+
* when startId is given, otherwise all processes are shaken.
|
|
218
|
+
* @param {string} [startId]
|
|
219
|
+
* @returns {import('#types').ShakeResult | undefined}
|
|
220
|
+
*/
|
|
186
221
|
Definition.prototype.shake = function shake(startId) {
|
|
222
|
+
/** @type {import('#types').ShakeResult} */
|
|
187
223
|
let result = {};
|
|
188
224
|
let bps;
|
|
189
225
|
if (startId) {
|
|
@@ -201,6 +237,8 @@ Definition.prototype.shake = function shake(startId) {
|
|
|
201
237
|
});
|
|
202
238
|
return result;
|
|
203
239
|
};
|
|
240
|
+
|
|
241
|
+
/** @internal */
|
|
204
242
|
Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
|
|
205
243
|
let shovel;
|
|
206
244
|
if (!shakeBp.isRunning) {
|
|
@@ -216,24 +254,45 @@ Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
|
|
|
216
254
|
if (shovel) shakeBp.broker.closeShovel('shaker');
|
|
217
255
|
return shakeResult;
|
|
218
256
|
};
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Get every process in the definition.
|
|
260
|
+
*/
|
|
219
261
|
Definition.prototype.getProcesses = function getProcesses() {
|
|
220
262
|
const execution = this.execution;
|
|
221
263
|
if (execution) return execution.getProcesses();
|
|
222
264
|
return this.context.getProcesses();
|
|
223
265
|
};
|
|
266
|
+
|
|
267
|
+
/**
|
|
268
|
+
* Get processes flagged executable in the definition.
|
|
269
|
+
*/
|
|
224
270
|
Definition.prototype.getExecutableProcesses = function getExecutableProcesses() {
|
|
225
271
|
const execution = this.execution;
|
|
226
272
|
if (execution) return execution.getExecutableProcesses();
|
|
227
273
|
return this.context.getExecutableProcesses();
|
|
228
274
|
};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Get processes that are currently running.
|
|
278
|
+
*/
|
|
229
279
|
Definition.prototype.getRunningProcesses = function getRunningProcesses() {
|
|
230
280
|
const execution = this.execution;
|
|
231
281
|
if (!execution) return [];
|
|
232
282
|
return execution.getRunningProcesses();
|
|
233
283
|
};
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @param {string} processId
|
|
287
|
+
*/
|
|
234
288
|
Definition.prototype.getProcessById = function getProcessById(processId) {
|
|
235
289
|
return this.getProcesses().find(p => p.id === processId);
|
|
236
290
|
};
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Find an activity by id across all processes in the definition.
|
|
294
|
+
* @param {string} childId
|
|
295
|
+
*/
|
|
237
296
|
Definition.prototype.getActivityById = function getActivityById(childId) {
|
|
238
297
|
const bps = this.getProcesses();
|
|
239
298
|
for (const bp of bps) {
|
|
@@ -242,31 +301,62 @@ Definition.prototype.getActivityById = function getActivityById(childId) {
|
|
|
242
301
|
}
|
|
243
302
|
return null;
|
|
244
303
|
};
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Lookup any element (activity, flow, etc.) in the parsed definition by id.
|
|
307
|
+
* @param {string} elementId
|
|
308
|
+
*/
|
|
245
309
|
Definition.prototype.getElementById = function getElementById(elementId) {
|
|
246
310
|
return this.context.getActivityById(elementId);
|
|
247
311
|
};
|
|
312
|
+
|
|
313
|
+
/**
|
|
314
|
+
* List currently postponed activities as Api wrappers.
|
|
315
|
+
* @param {import('#types').filterPostponed} [filterFn]
|
|
316
|
+
*/
|
|
248
317
|
Definition.prototype.getPostponed = function getPostponed(...args) {
|
|
249
|
-
|
|
250
|
-
if (!execution) return [];
|
|
251
|
-
return execution.getPostponed(...args);
|
|
318
|
+
return this.execution?.getPostponed(...args) || [];
|
|
252
319
|
};
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Resolve a Definition Api wrapper, preferring the running execution if any.
|
|
323
|
+
* @param {import('#types').ElementBrokerMessage} [message]
|
|
324
|
+
* @returns {import('#types').IApi<this>}
|
|
325
|
+
* @throws {Error} when the definition is not running and no message is given
|
|
326
|
+
*/
|
|
253
327
|
Definition.prototype.getApi = function getApi(message) {
|
|
254
328
|
const execution = this.execution;
|
|
255
329
|
if (execution) return execution.getApi(message);
|
|
256
|
-
message = message || this[
|
|
330
|
+
message = message || this[_constants.K_STATE_MESSAGE];
|
|
257
331
|
if (!message) throw new Error('Definition is not running');
|
|
258
332
|
return (0, _Api.DefinitionApi)(this.broker, message);
|
|
259
333
|
};
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Send a delegated signal to the running definition.
|
|
337
|
+
* @param {import('#types').signalMessage} [message]
|
|
338
|
+
*/
|
|
260
339
|
Definition.prototype.signal = function signal(message) {
|
|
261
340
|
return this.getApi().signal(message, {
|
|
262
341
|
delegate: true
|
|
263
342
|
});
|
|
264
343
|
};
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Cancel a running activity inside the definition by delegated api message.
|
|
347
|
+
* @param {import('#types').signalMessage} [message]
|
|
348
|
+
*/
|
|
265
349
|
Definition.prototype.cancelActivity = function cancelActivity(message) {
|
|
266
350
|
return this.getApi().cancel(message, {
|
|
267
351
|
delegate: true
|
|
268
352
|
});
|
|
269
353
|
};
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Deliver a message to a referenced element. Resolves the message reference when the
|
|
357
|
+
* target element exposes a `resolve` method (e.g. message-, signal-, escalation events).
|
|
358
|
+
* @param {{ id?: string, [x: string]: any }} message
|
|
359
|
+
*/
|
|
270
360
|
Definition.prototype.sendMessage = function sendMessage(message) {
|
|
271
361
|
const messageContent = {
|
|
272
362
|
message
|
|
@@ -287,17 +377,23 @@ Definition.prototype.sendMessage = function sendMessage(message) {
|
|
|
287
377
|
delegate: true
|
|
288
378
|
});
|
|
289
379
|
};
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Stop the definition if running.
|
|
383
|
+
*/
|
|
290
384
|
Definition.prototype.stop = function stop() {
|
|
291
385
|
if (!this.isRunning) return;
|
|
292
386
|
this.getApi().stop();
|
|
293
387
|
};
|
|
388
|
+
|
|
389
|
+
/** @internal */
|
|
294
390
|
Definition.prototype._activateRunConsumers = function activateRunConsumers() {
|
|
295
|
-
this[
|
|
391
|
+
this[_constants.K_CONSUMING] = true;
|
|
296
392
|
const broker = this.broker;
|
|
297
393
|
const {
|
|
298
394
|
onApiMessage,
|
|
299
395
|
onRunMessage
|
|
300
|
-
} = this[
|
|
396
|
+
} = this[_constants.K_MESSAGE_HANDLERS];
|
|
301
397
|
broker.subscribeTmp('api', `definition.*.${this.executionId}`, onApiMessage, {
|
|
302
398
|
noAck: true,
|
|
303
399
|
consumerTag: '_definition-api'
|
|
@@ -307,13 +403,17 @@ Definition.prototype._activateRunConsumers = function activateRunConsumers() {
|
|
|
307
403
|
consumerTag: '_definition-run'
|
|
308
404
|
});
|
|
309
405
|
};
|
|
406
|
+
|
|
407
|
+
/** @internal */
|
|
310
408
|
Definition.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
311
409
|
const broker = this.broker;
|
|
312
410
|
broker.cancel('_definition-api');
|
|
313
411
|
broker.cancel('_definition-run');
|
|
314
412
|
broker.cancel('_definition-execution');
|
|
315
|
-
this[
|
|
413
|
+
this[_constants.K_CONSUMING] = false;
|
|
316
414
|
};
|
|
415
|
+
|
|
416
|
+
/** @internal */
|
|
317
417
|
Definition.prototype._createMessage = function createMessage(override) {
|
|
318
418
|
return {
|
|
319
419
|
id: this.id,
|
|
@@ -323,6 +423,8 @@ Definition.prototype._createMessage = function createMessage(override) {
|
|
|
323
423
|
...override
|
|
324
424
|
};
|
|
325
425
|
};
|
|
426
|
+
|
|
427
|
+
/** @internal */
|
|
326
428
|
Definition.prototype._onRunMessage = function onRunMessage(routingKey, message) {
|
|
327
429
|
const {
|
|
328
430
|
content,
|
|
@@ -331,13 +433,13 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
331
433
|
if (routingKey === 'run.resume') {
|
|
332
434
|
return this._onResumeMessage(message);
|
|
333
435
|
}
|
|
334
|
-
const exec = this[
|
|
335
|
-
this[
|
|
436
|
+
const exec = this[_constants.K_EXECUTION];
|
|
437
|
+
this[_constants.K_STATE_MESSAGE] = message;
|
|
336
438
|
switch (routingKey) {
|
|
337
439
|
case 'run.enter':
|
|
338
440
|
{
|
|
339
441
|
this.logger.debug(`<${this.executionId} (${this.id})> enter`);
|
|
340
|
-
this[
|
|
442
|
+
this[_constants.K_STATUS] = 'entered';
|
|
341
443
|
if (fields.redelivered) break;
|
|
342
444
|
exec.delete('execution');
|
|
343
445
|
this._publishEvent('enter', content);
|
|
@@ -346,25 +448,25 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
346
448
|
case 'run.start':
|
|
347
449
|
{
|
|
348
450
|
this.logger.debug(`<${this.executionId} (${this.id})> start`);
|
|
349
|
-
this[
|
|
451
|
+
this[_constants.K_STATUS] = 'start';
|
|
350
452
|
this._publishEvent('start', content);
|
|
351
453
|
break;
|
|
352
454
|
}
|
|
353
455
|
case 'run.execute':
|
|
354
456
|
{
|
|
355
|
-
this[
|
|
457
|
+
this[_constants.K_STATUS] = 'executing';
|
|
356
458
|
const executeMessage = (0, _messageHelper.cloneMessage)(message);
|
|
357
459
|
let execution = exec.get('execution');
|
|
358
460
|
if (fields.redelivered && !execution) {
|
|
359
461
|
executeMessage.fields.redelivered = undefined;
|
|
360
462
|
}
|
|
361
|
-
this[
|
|
362
|
-
this.broker.getQueue('execution-q').assertConsumer(this[
|
|
463
|
+
this[_constants.K_EXECUTE_MESSAGE] = message;
|
|
464
|
+
this.broker.getQueue('execution-q').assertConsumer(this[_constants.K_MESSAGE_HANDLERS].onExecutionMessage, {
|
|
363
465
|
exclusive: true,
|
|
364
466
|
consumerTag: '_definition-execution'
|
|
365
467
|
});
|
|
366
468
|
if (!execution) {
|
|
367
|
-
execution = new _DefinitionExecution.
|
|
469
|
+
execution = new _DefinitionExecution.DefinitionExecution(this, this.context);
|
|
368
470
|
exec.set('execution', execution);
|
|
369
471
|
}
|
|
370
472
|
if (executeMessage.fields.redelivered) {
|
|
@@ -374,10 +476,10 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
374
476
|
}
|
|
375
477
|
case 'run.end':
|
|
376
478
|
{
|
|
377
|
-
if (this[
|
|
378
|
-
this[
|
|
479
|
+
if (this[_constants.K_STATUS] === 'end') break;
|
|
480
|
+
this[_constants.K_COUNTERS].completed++;
|
|
379
481
|
this.logger.debug(`<${this.executionId} (${this.id})> completed`);
|
|
380
|
-
this[
|
|
482
|
+
this[_constants.K_STATUS] = 'end';
|
|
381
483
|
this.broker.publish('run', 'run.leave', content);
|
|
382
484
|
this._publishEvent('end', content);
|
|
383
485
|
break;
|
|
@@ -394,16 +496,16 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
394
496
|
}
|
|
395
497
|
case 'run.discarded':
|
|
396
498
|
{
|
|
397
|
-
if (this[
|
|
398
|
-
this[
|
|
399
|
-
this[
|
|
499
|
+
if (this[_constants.K_STATUS] === 'discarded') break;
|
|
500
|
+
this[_constants.K_COUNTERS].discarded++;
|
|
501
|
+
this[_constants.K_STATUS] = 'discarded';
|
|
400
502
|
this.broker.publish('run', 'run.leave', content);
|
|
401
503
|
break;
|
|
402
504
|
}
|
|
403
505
|
case 'run.leave':
|
|
404
506
|
{
|
|
405
507
|
message.ack();
|
|
406
|
-
this[
|
|
508
|
+
this[_constants.K_STATUS] = undefined;
|
|
407
509
|
this._deactivateRunConsumers();
|
|
408
510
|
this._publishEvent('leave', this._createMessage());
|
|
409
511
|
return;
|
|
@@ -411,9 +513,11 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
411
513
|
}
|
|
412
514
|
message.ack();
|
|
413
515
|
};
|
|
516
|
+
|
|
517
|
+
/** @internal */
|
|
414
518
|
Definition.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
415
519
|
message.ack();
|
|
416
|
-
const stateMessage = this[
|
|
520
|
+
const stateMessage = this[_constants.K_STATE_MESSAGE];
|
|
417
521
|
switch (stateMessage.fields.routingKey) {
|
|
418
522
|
case 'run.discarded':
|
|
419
523
|
case 'run.end':
|
|
@@ -426,6 +530,8 @@ Definition.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
|
426
530
|
this._debug(`resume from ${this.status}`);
|
|
427
531
|
return this.broker.publish('run', stateMessage.fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
|
|
428
532
|
};
|
|
533
|
+
|
|
534
|
+
/** @internal */
|
|
429
535
|
Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
430
536
|
const {
|
|
431
537
|
content,
|
|
@@ -449,10 +555,12 @@ Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKe
|
|
|
449
555
|
this.broker.publish('run', 'run.end', content);
|
|
450
556
|
}
|
|
451
557
|
}
|
|
452
|
-
const executeMessage = this[
|
|
453
|
-
this[
|
|
558
|
+
const executeMessage = this[_constants.K_EXECUTE_MESSAGE];
|
|
559
|
+
this[_constants.K_EXECUTE_MESSAGE] = null;
|
|
454
560
|
executeMessage.ack();
|
|
455
561
|
};
|
|
562
|
+
|
|
563
|
+
/** @internal */
|
|
456
564
|
Definition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
457
565
|
if (message.properties.type === 'stop') {
|
|
458
566
|
const execution = this.execution;
|
|
@@ -461,6 +569,8 @@ Definition.prototype._onApiMessage = function onApiMessage(routingKey, message)
|
|
|
461
569
|
}
|
|
462
570
|
}
|
|
463
571
|
};
|
|
572
|
+
|
|
573
|
+
/** @internal */
|
|
464
574
|
Definition.prototype._publishEvent = function publishEvent(action, content, msgOpts) {
|
|
465
575
|
const execution = this.execution;
|
|
466
576
|
this.broker.publish('event', `definition.${action}`, execution ? execution._createMessage(content) : (0, _messageHelper.cloneContent)(content), {
|
|
@@ -468,11 +578,15 @@ Definition.prototype._publishEvent = function publishEvent(action, content, msgO
|
|
|
468
578
|
...msgOpts
|
|
469
579
|
});
|
|
470
580
|
};
|
|
581
|
+
|
|
582
|
+
/** @internal */
|
|
471
583
|
Definition.prototype._onStop = function onStop() {
|
|
472
|
-
this[
|
|
584
|
+
this[_constants.K_STOPPED] = true;
|
|
473
585
|
this._deactivateRunConsumers();
|
|
474
586
|
return this._publishEvent('stop', this._createMessage());
|
|
475
587
|
};
|
|
588
|
+
|
|
589
|
+
/** @internal */
|
|
476
590
|
Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
|
|
477
591
|
if (message.properties.type === 'error') {
|
|
478
592
|
this._deactivateRunConsumers();
|
|
@@ -480,12 +594,16 @@ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
|
|
|
480
594
|
throw err;
|
|
481
595
|
}
|
|
482
596
|
};
|
|
597
|
+
|
|
598
|
+
/** @internal */
|
|
483
599
|
Definition.prototype._reset = function reset() {
|
|
484
|
-
this[
|
|
600
|
+
this[_constants.K_EXECUTION].delete('executionId');
|
|
485
601
|
this._deactivateRunConsumers();
|
|
486
602
|
this.broker.purgeQueue('run-q');
|
|
487
603
|
this.broker.purgeQueue('execution-q');
|
|
488
604
|
};
|
|
605
|
+
|
|
606
|
+
/** @internal */
|
|
489
607
|
Definition.prototype._debug = function debug(msg) {
|
|
490
608
|
this.logger.debug(`<${this.id}> ${msg}`);
|
|
491
609
|
};
|