bpmn-elements 17.3.0 → 18.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -1
- package/dist/Api.js +83 -0
- package/dist/Context.js +228 -22
- package/dist/Environment.js +111 -31
- package/dist/EventBroker.js +57 -1
- package/dist/Expressions.js +3 -4
- package/dist/MessageFormatter.js +29 -16
- package/dist/Timers.js +13 -9
- package/dist/Tracker.js +1 -0
- package/dist/activity/Activity.js +434 -233
- package/dist/activity/ActivityExecution.js +113 -40
- package/dist/activity/Dummy.js +6 -1
- package/dist/activity/Escalation.js +36 -24
- package/dist/activity/ExecutionScope.js +1 -1
- package/dist/activity/Message.js +36 -24
- package/dist/activity/Signal.js +36 -24
- package/dist/activity/outbound-evaluator.js +1 -1
- package/dist/condition.js +12 -6
- package/dist/constants.js +27 -0
- package/dist/definition/Definition.js +187 -64
- package/dist/definition/DefinitionExecution.js +198 -84
- package/dist/error/BpmnError.js +12 -1
- package/dist/error/Errors.js +50 -9
- package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
- package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
- package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
- package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
- package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
- package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
- package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
- package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
- package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
- package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
- package/dist/eventDefinitions/index.js +20 -21
- package/dist/events/BoundaryEvent.js +52 -40
- package/dist/events/EndEvent.js +22 -8
- package/dist/events/IntermediateCatchEvent.js +26 -8
- package/dist/events/IntermediateThrowEvent.js +24 -9
- package/dist/events/StartEvent.js +30 -14
- package/dist/events/index.js +10 -11
- package/dist/flows/Association.js +50 -7
- package/dist/flows/MessageFlow.js +49 -10
- package/dist/flows/SequenceFlow.js +93 -22
- package/dist/flows/index.js +6 -7
- package/dist/gateways/EventBasedGateway.js +29 -15
- package/dist/gateways/ExclusiveGateway.js +20 -5
- package/dist/gateways/InclusiveGateway.js +21 -5
- package/dist/gateways/ParallelGateway.js +253 -15
- package/dist/gateways/index.js +8 -9
- package/dist/getPropertyValue.js +1 -1
- package/dist/index.js +42 -43
- package/dist/io/BpmnIO.js +15 -1
- package/dist/io/EnvironmentDataObject.js +29 -1
- package/dist/io/EnvironmentDataStore.js +24 -1
- package/dist/io/EnvironmentDataStoreReference.js +24 -1
- package/dist/io/InputOutputSpecification.js +21 -11
- package/dist/io/Properties.js +28 -17
- package/dist/messageHelper.js +41 -4
- package/dist/process/Lane.js +15 -4
- package/dist/process/Process.js +176 -77
- package/dist/process/ProcessExecution.js +397 -178
- package/dist/shared.js +2 -0
- package/dist/tasks/CallActivity.js +19 -4
- package/dist/tasks/LoopCharacteristics.js +94 -9
- package/dist/tasks/ReceiveTask.js +36 -21
- package/dist/tasks/ScriptTask.js +22 -6
- package/dist/tasks/ServiceImplementation.js +7 -4
- package/dist/tasks/ServiceTask.js +19 -4
- package/dist/tasks/SignalTask.js +19 -4
- package/dist/tasks/StandardLoopCharacteristics.js +8 -4
- package/dist/tasks/SubProcess.js +44 -29
- package/dist/tasks/Task.js +19 -4
- package/dist/tasks/Transaction.js +8 -4
- package/dist/tasks/index.js +16 -18
- package/package.json +31 -13
- package/src/Api.js +70 -0
- package/src/Context.js +200 -19
- package/src/Environment.js +99 -30
- package/src/EventBroker.js +46 -1
- package/src/Expressions.js +2 -3
- package/src/MessageFormatter.js +24 -16
- package/src/Timers.js +12 -9
- package/src/Tracker.js +1 -0
- package/src/activity/Activity.js +372 -218
- package/src/activity/ActivityExecution.js +93 -42
- package/src/activity/Dummy.js +6 -1
- package/src/activity/Escalation.js +25 -18
- package/src/activity/ExecutionScope.js +1 -1
- package/src/activity/Message.js +25 -18
- package/src/activity/Signal.js +25 -18
- package/src/activity/outbound-evaluator.js +1 -1
- package/src/condition.js +11 -5
- package/src/constants.js +21 -0
- package/src/definition/Definition.js +165 -63
- package/src/definition/DefinitionExecution.js +164 -85
- package/src/error/BpmnError.js +11 -1
- package/src/error/Errors.js +44 -5
- package/src/eventDefinitions/CancelEventDefinition.js +27 -13
- package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
- package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
- package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
- package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
- package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
- package/src/eventDefinitions/LinkEventDefinition.js +34 -120
- package/src/eventDefinitions/MessageEventDefinition.js +42 -31
- package/src/eventDefinitions/SignalEventDefinition.js +43 -32
- package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
- package/src/eventDefinitions/TimerEventDefinition.js +53 -35
- package/src/eventDefinitions/index.js +10 -23
- package/src/events/BoundaryEvent.js +50 -39
- package/src/events/EndEvent.js +19 -7
- package/src/events/IntermediateCatchEvent.js +24 -8
- package/src/events/IntermediateThrowEvent.js +24 -8
- package/src/events/StartEvent.js +25 -14
- package/src/events/index.js +5 -18
- package/src/flows/Association.js +43 -9
- package/src/flows/MessageFlow.js +41 -10
- package/src/flows/SequenceFlow.js +82 -19
- package/src/flows/index.js +3 -4
- package/src/gateways/EventBasedGateway.js +27 -15
- package/src/gateways/ExclusiveGateway.js +16 -3
- package/src/gateways/InclusiveGateway.js +16 -3
- package/src/gateways/ParallelGateway.js +301 -10
- package/src/gateways/index.js +4 -4
- package/src/getPropertyValue.js +1 -1
- package/src/index.js +19 -19
- package/src/io/BpmnIO.js +13 -1
- package/src/io/EnvironmentDataObject.js +26 -1
- package/src/io/EnvironmentDataStore.js +22 -1
- package/src/io/EnvironmentDataStoreReference.js +22 -1
- package/src/io/InputOutputSpecification.js +17 -8
- package/src/io/Properties.js +23 -13
- package/src/messageHelper.js +36 -4
- package/src/process/Lane.js +14 -4
- package/src/process/Process.js +157 -74
- package/src/process/ProcessExecution.js +363 -176
- package/src/shared.js +1 -0
- package/src/tasks/CallActivity.js +16 -2
- package/src/tasks/LoopCharacteristics.js +77 -11
- package/src/tasks/ReceiveTask.js +33 -22
- package/src/tasks/ScriptTask.js +17 -3
- package/src/tasks/ServiceImplementation.js +6 -3
- package/src/tasks/ServiceTask.js +16 -2
- package/src/tasks/SignalTask.js +16 -2
- package/src/tasks/StandardLoopCharacteristics.js +7 -3
- package/src/tasks/SubProcess.js +37 -23
- package/src/tasks/Task.js +16 -2
- package/src/tasks/Transaction.js +7 -3
- package/src/tasks/index.js +8 -9
- package/types/bundle-errors.d.ts +1 -0
- package/types/bundle.d.ts +97 -0
- package/types/index.d.ts +2619 -84
- package/types/interfaces.d.ts +638 -0
- package/types/types.d.ts +0 -765
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,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.STATE_VERSION = 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');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* State version. Tracks the package major; bump on each major. Recovering an older major triggers
|
|
25
|
+
* migrations. Unstamped legacy states are treated as version 0.
|
|
26
|
+
*/
|
|
27
|
+
const STATE_VERSION = exports.STATE_VERSION = 18;
|
|
@@ -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,8 +169,14 @@ 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({
|
|
179
|
+
stateVersion: _constants.STATE_VERSION,
|
|
158
180
|
status: this.status,
|
|
159
181
|
stopped: this.stopped,
|
|
160
182
|
counters: this.counters,
|
|
@@ -163,27 +185,46 @@ Definition.prototype.getState = function getState() {
|
|
|
163
185
|
broker: this.broker.getState(true)
|
|
164
186
|
});
|
|
165
187
|
};
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Restore definition state captured by getState.
|
|
191
|
+
* @param {import('#types').DefinitionState} [state]
|
|
192
|
+
* @returns {this}
|
|
193
|
+
* @throws {Error} when called on a running definition
|
|
194
|
+
*/
|
|
166
195
|
Definition.prototype.recover = function recover(state) {
|
|
167
196
|
if (this.isRunning) throw new Error('cannot recover running definition');
|
|
168
197
|
if (!state) return this;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
198
|
+
const recoveredVersion = state.stateVersion || 0;
|
|
199
|
+
if (recoveredVersion !== _constants.STATE_VERSION) {
|
|
200
|
+
this.logger.debug(`<${this.id}> recover state version ${recoveredVersion} into runtime state version ${_constants.STATE_VERSION}`);
|
|
201
|
+
}
|
|
202
|
+
this[_constants.K_STOPPED] = !!state.stopped;
|
|
203
|
+
this[_constants.K_STATUS] = state.status;
|
|
204
|
+
const exec = this[_constants.K_EXECUTION];
|
|
172
205
|
exec.set('executionId', state.executionId);
|
|
173
206
|
if (state.counters) {
|
|
174
|
-
this[
|
|
175
|
-
...this[
|
|
207
|
+
this[_constants.K_COUNTERS] = {
|
|
208
|
+
...this[_constants.K_COUNTERS],
|
|
176
209
|
...state.counters
|
|
177
210
|
};
|
|
178
211
|
}
|
|
179
212
|
this.environment.recover(state.environment);
|
|
180
213
|
if (state.execution) {
|
|
181
|
-
exec.set('execution', new _DefinitionExecution.
|
|
214
|
+
exec.set('execution', new _DefinitionExecution.DefinitionExecution(this, this.context).recover(state.execution, recoveredVersion));
|
|
182
215
|
}
|
|
183
216
|
this.broker.recover(state.broker);
|
|
184
217
|
return this;
|
|
185
218
|
};
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Walk activity graphs to discover sequences. Limited to the activity's owning process
|
|
222
|
+
* when startId is given, otherwise all processes are shaken.
|
|
223
|
+
* @param {string} [startId]
|
|
224
|
+
* @returns {import('#types').ShakeResult | undefined}
|
|
225
|
+
*/
|
|
186
226
|
Definition.prototype.shake = function shake(startId) {
|
|
227
|
+
/** @type {import('#types').ShakeResult} */
|
|
187
228
|
let result = {};
|
|
188
229
|
let bps;
|
|
189
230
|
if (startId) {
|
|
@@ -201,6 +242,8 @@ Definition.prototype.shake = function shake(startId) {
|
|
|
201
242
|
});
|
|
202
243
|
return result;
|
|
203
244
|
};
|
|
245
|
+
|
|
246
|
+
/** @internal */
|
|
204
247
|
Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
|
|
205
248
|
let shovel;
|
|
206
249
|
if (!shakeBp.isRunning) {
|
|
@@ -216,24 +259,45 @@ Definition.prototype._shakeProcess = function shakeProcess(shakeBp, startId) {
|
|
|
216
259
|
if (shovel) shakeBp.broker.closeShovel('shaker');
|
|
217
260
|
return shakeResult;
|
|
218
261
|
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Get every process in the definition.
|
|
265
|
+
*/
|
|
219
266
|
Definition.prototype.getProcesses = function getProcesses() {
|
|
220
267
|
const execution = this.execution;
|
|
221
268
|
if (execution) return execution.getProcesses();
|
|
222
269
|
return this.context.getProcesses();
|
|
223
270
|
};
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Get processes flagged executable in the definition.
|
|
274
|
+
*/
|
|
224
275
|
Definition.prototype.getExecutableProcesses = function getExecutableProcesses() {
|
|
225
276
|
const execution = this.execution;
|
|
226
277
|
if (execution) return execution.getExecutableProcesses();
|
|
227
278
|
return this.context.getExecutableProcesses();
|
|
228
279
|
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Get processes that are currently running.
|
|
283
|
+
*/
|
|
229
284
|
Definition.prototype.getRunningProcesses = function getRunningProcesses() {
|
|
230
285
|
const execution = this.execution;
|
|
231
286
|
if (!execution) return [];
|
|
232
287
|
return execution.getRunningProcesses();
|
|
233
288
|
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* @param {string} processId
|
|
292
|
+
*/
|
|
234
293
|
Definition.prototype.getProcessById = function getProcessById(processId) {
|
|
235
294
|
return this.getProcesses().find(p => p.id === processId);
|
|
236
295
|
};
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Find an activity by id across all processes in the definition.
|
|
299
|
+
* @param {string} childId
|
|
300
|
+
*/
|
|
237
301
|
Definition.prototype.getActivityById = function getActivityById(childId) {
|
|
238
302
|
const bps = this.getProcesses();
|
|
239
303
|
for (const bp of bps) {
|
|
@@ -242,31 +306,62 @@ Definition.prototype.getActivityById = function getActivityById(childId) {
|
|
|
242
306
|
}
|
|
243
307
|
return null;
|
|
244
308
|
};
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Lookup any element (activity, flow, etc.) in the parsed definition by id.
|
|
312
|
+
* @param {string} elementId
|
|
313
|
+
*/
|
|
245
314
|
Definition.prototype.getElementById = function getElementById(elementId) {
|
|
246
315
|
return this.context.getActivityById(elementId);
|
|
247
316
|
};
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* List currently postponed activities as Api wrappers.
|
|
320
|
+
* @param {import('#types').filterPostponed} [filterFn]
|
|
321
|
+
*/
|
|
248
322
|
Definition.prototype.getPostponed = function getPostponed(...args) {
|
|
249
|
-
|
|
250
|
-
if (!execution) return [];
|
|
251
|
-
return execution.getPostponed(...args);
|
|
323
|
+
return this.execution?.getPostponed(...args) || [];
|
|
252
324
|
};
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Resolve a Definition Api wrapper, preferring the running execution if any.
|
|
328
|
+
* @param {import('#types').ElementBrokerMessage} [message]
|
|
329
|
+
* @returns {import('#types').IApi<this>}
|
|
330
|
+
* @throws {Error} when the definition is not running and no message is given
|
|
331
|
+
*/
|
|
253
332
|
Definition.prototype.getApi = function getApi(message) {
|
|
254
333
|
const execution = this.execution;
|
|
255
334
|
if (execution) return execution.getApi(message);
|
|
256
|
-
message = message || this[
|
|
335
|
+
message = message || this[_constants.K_STATE_MESSAGE];
|
|
257
336
|
if (!message) throw new Error('Definition is not running');
|
|
258
337
|
return (0, _Api.DefinitionApi)(this.broker, message);
|
|
259
338
|
};
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* Send a delegated signal to the running definition.
|
|
342
|
+
* @param {import('#types').signalMessage} [message]
|
|
343
|
+
*/
|
|
260
344
|
Definition.prototype.signal = function signal(message) {
|
|
261
345
|
return this.getApi().signal(message, {
|
|
262
346
|
delegate: true
|
|
263
347
|
});
|
|
264
348
|
};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Cancel a running activity inside the definition by delegated api message.
|
|
352
|
+
* @param {import('#types').signalMessage} [message]
|
|
353
|
+
*/
|
|
265
354
|
Definition.prototype.cancelActivity = function cancelActivity(message) {
|
|
266
355
|
return this.getApi().cancel(message, {
|
|
267
356
|
delegate: true
|
|
268
357
|
});
|
|
269
358
|
};
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Deliver a message to a referenced element. Resolves the message reference when the
|
|
362
|
+
* target element exposes a `resolve` method (e.g. message-, signal-, escalation events).
|
|
363
|
+
* @param {{ id?: string, [x: string]: any }} message
|
|
364
|
+
*/
|
|
270
365
|
Definition.prototype.sendMessage = function sendMessage(message) {
|
|
271
366
|
const messageContent = {
|
|
272
367
|
message
|
|
@@ -287,17 +382,23 @@ Definition.prototype.sendMessage = function sendMessage(message) {
|
|
|
287
382
|
delegate: true
|
|
288
383
|
});
|
|
289
384
|
};
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Stop the definition if running.
|
|
388
|
+
*/
|
|
290
389
|
Definition.prototype.stop = function stop() {
|
|
291
390
|
if (!this.isRunning) return;
|
|
292
391
|
this.getApi().stop();
|
|
293
392
|
};
|
|
393
|
+
|
|
394
|
+
/** @internal */
|
|
294
395
|
Definition.prototype._activateRunConsumers = function activateRunConsumers() {
|
|
295
|
-
this[
|
|
396
|
+
this[_constants.K_CONSUMING] = true;
|
|
296
397
|
const broker = this.broker;
|
|
297
398
|
const {
|
|
298
399
|
onApiMessage,
|
|
299
400
|
onRunMessage
|
|
300
|
-
} = this[
|
|
401
|
+
} = this[_constants.K_MESSAGE_HANDLERS];
|
|
301
402
|
broker.subscribeTmp('api', `definition.*.${this.executionId}`, onApiMessage, {
|
|
302
403
|
noAck: true,
|
|
303
404
|
consumerTag: '_definition-api'
|
|
@@ -307,13 +408,17 @@ Definition.prototype._activateRunConsumers = function activateRunConsumers() {
|
|
|
307
408
|
consumerTag: '_definition-run'
|
|
308
409
|
});
|
|
309
410
|
};
|
|
411
|
+
|
|
412
|
+
/** @internal */
|
|
310
413
|
Definition.prototype._deactivateRunConsumers = function deactivateRunConsumers() {
|
|
311
414
|
const broker = this.broker;
|
|
312
415
|
broker.cancel('_definition-api');
|
|
313
416
|
broker.cancel('_definition-run');
|
|
314
417
|
broker.cancel('_definition-execution');
|
|
315
|
-
this[
|
|
418
|
+
this[_constants.K_CONSUMING] = false;
|
|
316
419
|
};
|
|
420
|
+
|
|
421
|
+
/** @internal */
|
|
317
422
|
Definition.prototype._createMessage = function createMessage(override) {
|
|
318
423
|
return {
|
|
319
424
|
id: this.id,
|
|
@@ -323,6 +428,8 @@ Definition.prototype._createMessage = function createMessage(override) {
|
|
|
323
428
|
...override
|
|
324
429
|
};
|
|
325
430
|
};
|
|
431
|
+
|
|
432
|
+
/** @internal */
|
|
326
433
|
Definition.prototype._onRunMessage = function onRunMessage(routingKey, message) {
|
|
327
434
|
const {
|
|
328
435
|
content,
|
|
@@ -331,13 +438,13 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
331
438
|
if (routingKey === 'run.resume') {
|
|
332
439
|
return this._onResumeMessage(message);
|
|
333
440
|
}
|
|
334
|
-
const exec = this[
|
|
335
|
-
this[
|
|
441
|
+
const exec = this[_constants.K_EXECUTION];
|
|
442
|
+
this[_constants.K_STATE_MESSAGE] = message;
|
|
336
443
|
switch (routingKey) {
|
|
337
444
|
case 'run.enter':
|
|
338
445
|
{
|
|
339
446
|
this.logger.debug(`<${this.executionId} (${this.id})> enter`);
|
|
340
|
-
this[
|
|
447
|
+
this[_constants.K_STATUS] = 'entered';
|
|
341
448
|
if (fields.redelivered) break;
|
|
342
449
|
exec.delete('execution');
|
|
343
450
|
this._publishEvent('enter', content);
|
|
@@ -346,25 +453,25 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
346
453
|
case 'run.start':
|
|
347
454
|
{
|
|
348
455
|
this.logger.debug(`<${this.executionId} (${this.id})> start`);
|
|
349
|
-
this[
|
|
456
|
+
this[_constants.K_STATUS] = 'start';
|
|
350
457
|
this._publishEvent('start', content);
|
|
351
458
|
break;
|
|
352
459
|
}
|
|
353
460
|
case 'run.execute':
|
|
354
461
|
{
|
|
355
|
-
this[
|
|
462
|
+
this[_constants.K_STATUS] = 'executing';
|
|
356
463
|
const executeMessage = (0, _messageHelper.cloneMessage)(message);
|
|
357
464
|
let execution = exec.get('execution');
|
|
358
465
|
if (fields.redelivered && !execution) {
|
|
359
466
|
executeMessage.fields.redelivered = undefined;
|
|
360
467
|
}
|
|
361
|
-
this[
|
|
362
|
-
this.broker.getQueue('execution-q').assertConsumer(this[
|
|
468
|
+
this[_constants.K_EXECUTE_MESSAGE] = message;
|
|
469
|
+
this.broker.getQueue('execution-q').assertConsumer(this[_constants.K_MESSAGE_HANDLERS].onExecutionMessage, {
|
|
363
470
|
exclusive: true,
|
|
364
471
|
consumerTag: '_definition-execution'
|
|
365
472
|
});
|
|
366
473
|
if (!execution) {
|
|
367
|
-
execution = new _DefinitionExecution.
|
|
474
|
+
execution = new _DefinitionExecution.DefinitionExecution(this, this.context);
|
|
368
475
|
exec.set('execution', execution);
|
|
369
476
|
}
|
|
370
477
|
if (executeMessage.fields.redelivered) {
|
|
@@ -374,10 +481,10 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
374
481
|
}
|
|
375
482
|
case 'run.end':
|
|
376
483
|
{
|
|
377
|
-
if (this[
|
|
378
|
-
this[
|
|
484
|
+
if (this[_constants.K_STATUS] === 'end') break;
|
|
485
|
+
this[_constants.K_COUNTERS].completed++;
|
|
379
486
|
this.logger.debug(`<${this.executionId} (${this.id})> completed`);
|
|
380
|
-
this[
|
|
487
|
+
this[_constants.K_STATUS] = 'end';
|
|
381
488
|
this.broker.publish('run', 'run.leave', content);
|
|
382
489
|
this._publishEvent('end', content);
|
|
383
490
|
break;
|
|
@@ -394,16 +501,16 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
394
501
|
}
|
|
395
502
|
case 'run.discarded':
|
|
396
503
|
{
|
|
397
|
-
if (this[
|
|
398
|
-
this[
|
|
399
|
-
this[
|
|
504
|
+
if (this[_constants.K_STATUS] === 'discarded') break;
|
|
505
|
+
this[_constants.K_COUNTERS].discarded++;
|
|
506
|
+
this[_constants.K_STATUS] = 'discarded';
|
|
400
507
|
this.broker.publish('run', 'run.leave', content);
|
|
401
508
|
break;
|
|
402
509
|
}
|
|
403
510
|
case 'run.leave':
|
|
404
511
|
{
|
|
405
512
|
message.ack();
|
|
406
|
-
this[
|
|
513
|
+
this[_constants.K_STATUS] = undefined;
|
|
407
514
|
this._deactivateRunConsumers();
|
|
408
515
|
this._publishEvent('leave', this._createMessage());
|
|
409
516
|
return;
|
|
@@ -411,9 +518,11 @@ Definition.prototype._onRunMessage = function onRunMessage(routingKey, message)
|
|
|
411
518
|
}
|
|
412
519
|
message.ack();
|
|
413
520
|
};
|
|
521
|
+
|
|
522
|
+
/** @internal */
|
|
414
523
|
Definition.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
415
524
|
message.ack();
|
|
416
|
-
const stateMessage = this[
|
|
525
|
+
const stateMessage = this[_constants.K_STATE_MESSAGE];
|
|
417
526
|
switch (stateMessage.fields.routingKey) {
|
|
418
527
|
case 'run.discarded':
|
|
419
528
|
case 'run.end':
|
|
@@ -426,6 +535,8 @@ Definition.prototype._onResumeMessage = function onResumeMessage(message) {
|
|
|
426
535
|
this._debug(`resume from ${this.status}`);
|
|
427
536
|
return this.broker.publish('run', stateMessage.fields.routingKey, (0, _messageHelper.cloneContent)(stateMessage.content), stateMessage.properties);
|
|
428
537
|
};
|
|
538
|
+
|
|
539
|
+
/** @internal */
|
|
429
540
|
Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKey, message) {
|
|
430
541
|
const {
|
|
431
542
|
content,
|
|
@@ -449,10 +560,12 @@ Definition.prototype._onExecutionMessage = function onExecutionMessage(routingKe
|
|
|
449
560
|
this.broker.publish('run', 'run.end', content);
|
|
450
561
|
}
|
|
451
562
|
}
|
|
452
|
-
const executeMessage = this[
|
|
453
|
-
this[
|
|
563
|
+
const executeMessage = this[_constants.K_EXECUTE_MESSAGE];
|
|
564
|
+
this[_constants.K_EXECUTE_MESSAGE] = null;
|
|
454
565
|
executeMessage.ack();
|
|
455
566
|
};
|
|
567
|
+
|
|
568
|
+
/** @internal */
|
|
456
569
|
Definition.prototype._onApiMessage = function onApiMessage(routingKey, message) {
|
|
457
570
|
if (message.properties.type === 'stop') {
|
|
458
571
|
const execution = this.execution;
|
|
@@ -461,6 +574,8 @@ Definition.prototype._onApiMessage = function onApiMessage(routingKey, message)
|
|
|
461
574
|
}
|
|
462
575
|
}
|
|
463
576
|
};
|
|
577
|
+
|
|
578
|
+
/** @internal */
|
|
464
579
|
Definition.prototype._publishEvent = function publishEvent(action, content, msgOpts) {
|
|
465
580
|
const execution = this.execution;
|
|
466
581
|
this.broker.publish('event', `definition.${action}`, execution ? execution._createMessage(content) : (0, _messageHelper.cloneContent)(content), {
|
|
@@ -468,11 +583,15 @@ Definition.prototype._publishEvent = function publishEvent(action, content, msgO
|
|
|
468
583
|
...msgOpts
|
|
469
584
|
});
|
|
470
585
|
};
|
|
586
|
+
|
|
587
|
+
/** @internal */
|
|
471
588
|
Definition.prototype._onStop = function onStop() {
|
|
472
|
-
this[
|
|
589
|
+
this[_constants.K_STOPPED] = true;
|
|
473
590
|
this._deactivateRunConsumers();
|
|
474
591
|
return this._publishEvent('stop', this._createMessage());
|
|
475
592
|
};
|
|
593
|
+
|
|
594
|
+
/** @internal */
|
|
476
595
|
Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
|
|
477
596
|
if (message.properties.type === 'error') {
|
|
478
597
|
this._deactivateRunConsumers();
|
|
@@ -480,12 +599,16 @@ Definition.prototype._onBrokerReturnFn = function onBrokerReturn(message) {
|
|
|
480
599
|
throw err;
|
|
481
600
|
}
|
|
482
601
|
};
|
|
602
|
+
|
|
603
|
+
/** @internal */
|
|
483
604
|
Definition.prototype._reset = function reset() {
|
|
484
|
-
this[
|
|
605
|
+
this[_constants.K_EXECUTION].delete('executionId');
|
|
485
606
|
this._deactivateRunConsumers();
|
|
486
607
|
this.broker.purgeQueue('run-q');
|
|
487
608
|
this.broker.purgeQueue('execution-q');
|
|
488
609
|
};
|
|
610
|
+
|
|
611
|
+
/** @internal */
|
|
489
612
|
Definition.prototype._debug = function debug(msg) {
|
|
490
613
|
this.logger.debug(`<${this.id}> ${msg}`);
|
|
491
614
|
};
|