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/Environment.js
CHANGED
|
@@ -3,75 +3,105 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _Expressions =
|
|
6
|
+
exports.Environment = Environment;
|
|
7
|
+
var _Expressions = require("./Expressions.js");
|
|
8
8
|
var _Scripts = require("./Scripts.js");
|
|
9
9
|
var _Timers = require("./Timers.js");
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
const kVariables = Symbol.for('variables');
|
|
10
|
+
const K_SERVICES = Symbol.for('services');
|
|
11
|
+
const K_VARIABLES = Symbol.for('variables');
|
|
13
12
|
const defaultOptions = new Set(['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables']);
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Holds global execution config: variables, injected services, timers, scripts engine,
|
|
16
|
+
* expressions, Logger factory, and settings such as `batchSize`. Cloned and merged per Definition.
|
|
17
|
+
* @param {import('#types').EnvironmentOptions} [options]
|
|
18
|
+
*/
|
|
14
19
|
function Environment(options = {}) {
|
|
15
20
|
this.options = validateOptions(options);
|
|
16
|
-
|
|
21
|
+
|
|
22
|
+
/** @type {import('#types').IExpressions} */
|
|
23
|
+
this.expressions = options.expressions || (0, _Expressions.Expressions)();
|
|
17
24
|
this.extensions = options.extensions;
|
|
18
25
|
this.output = options.output || {};
|
|
26
|
+
/** @type {import('#types').IScripts} */
|
|
19
27
|
this.scripts = options.scripts || new _Scripts.Scripts();
|
|
28
|
+
/** @type {import('#types').ITimers} */
|
|
20
29
|
this.timers = options.timers || new _Timers.Timers();
|
|
30
|
+
/** @type {import('#types').EnvironmentSettings} */
|
|
21
31
|
this.settings = {
|
|
22
32
|
...options.settings
|
|
23
33
|
};
|
|
34
|
+
/** @type {import('#types').LoggerFactory} */
|
|
24
35
|
this.Logger = options.Logger || DummyLogger;
|
|
25
|
-
this[
|
|
26
|
-
this[
|
|
36
|
+
this[K_SERVICES] = options.services || {};
|
|
37
|
+
this[K_VARIABLES] = options.variables || {};
|
|
27
38
|
}
|
|
28
|
-
Object.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
Object.defineProperty(Environment.prototype, 'variables', {
|
|
40
|
+
/** @returns {Record<string, any>} */
|
|
41
|
+
get() {
|
|
42
|
+
return this[K_VARIABLES];
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
Object.defineProperty(Environment.prototype, 'services', {
|
|
46
|
+
/** @returns {Record<string, CallableFunction>} */
|
|
47
|
+
get() {
|
|
48
|
+
return this[K_SERVICES];
|
|
33
49
|
},
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
set(value) {
|
|
39
|
-
const services = this[kServices];
|
|
40
|
-
for (const name in services) {
|
|
41
|
-
if (!(name in value)) delete services[name];
|
|
42
|
-
}
|
|
43
|
-
Object.assign(services, value);
|
|
50
|
+
set(value) {
|
|
51
|
+
const services = this[K_SERVICES];
|
|
52
|
+
for (const name in services) {
|
|
53
|
+
if (!(name in value)) delete services[name];
|
|
44
54
|
}
|
|
55
|
+
Object.assign(services, value);
|
|
45
56
|
}
|
|
46
57
|
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Snapshot environment state for recover.
|
|
61
|
+
* @returns {import('#types').EnvironmentState}
|
|
62
|
+
*/
|
|
47
63
|
Environment.prototype.getState = function getState() {
|
|
48
64
|
return {
|
|
49
65
|
settings: {
|
|
50
66
|
...this.settings
|
|
51
67
|
},
|
|
52
68
|
variables: {
|
|
53
|
-
...this[
|
|
69
|
+
...this[K_VARIABLES]
|
|
54
70
|
},
|
|
55
71
|
output: {
|
|
56
72
|
...this.output
|
|
57
73
|
}
|
|
58
74
|
};
|
|
59
75
|
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Restore environment state captured by getState. Merges into the existing settings,
|
|
79
|
+
* variables, and output rather than replacing them.
|
|
80
|
+
* @param {import('#types').EnvironmentState} [state]
|
|
81
|
+
* @returns {this}
|
|
82
|
+
*/
|
|
60
83
|
Environment.prototype.recover = function recover(state) {
|
|
61
84
|
if (!state) return this;
|
|
62
85
|
if (state.settings) Object.assign(this.settings, state.settings);
|
|
63
|
-
if (state.variables) Object.assign(this[
|
|
86
|
+
if (state.variables) Object.assign(this[K_VARIABLES], state.variables);
|
|
64
87
|
if (state.output) Object.assign(this.output, state.output);
|
|
65
88
|
return this;
|
|
66
89
|
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Clone the environment, optionally overriding options. Services are merged when
|
|
93
|
+
* `overrideOptions.services` is supplied.
|
|
94
|
+
* @param {import('#types').EnvironmentOptions} [overrideOptions]
|
|
95
|
+
* @returns {Environment}
|
|
96
|
+
*/
|
|
67
97
|
Environment.prototype.clone = function clone(overrideOptions) {
|
|
68
|
-
const services = this[
|
|
98
|
+
const services = this[K_SERVICES];
|
|
69
99
|
const newOptions = {
|
|
70
100
|
settings: {
|
|
71
101
|
...this.settings
|
|
72
102
|
},
|
|
73
103
|
variables: {
|
|
74
|
-
...this[
|
|
104
|
+
...this[K_VARIABLES]
|
|
75
105
|
},
|
|
76
106
|
Logger: this.Logger,
|
|
77
107
|
extensions: this.extensions,
|
|
@@ -88,29 +118,64 @@ Environment.prototype.clone = function clone(overrideOptions) {
|
|
|
88
118
|
};
|
|
89
119
|
return new this.constructor(newOptions);
|
|
90
120
|
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Merge variables into the environment. Non-objects are ignored.
|
|
124
|
+
* @param {Record<string, any>} newVars
|
|
125
|
+
*/
|
|
91
126
|
Environment.prototype.assignVariables = function assignVariables(newVars) {
|
|
92
127
|
if (!newVars || typeof newVars !== 'object') return;
|
|
93
|
-
this[
|
|
128
|
+
this[K_VARIABLES] = {
|
|
94
129
|
...this.variables,
|
|
95
130
|
...newVars
|
|
96
131
|
};
|
|
97
132
|
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Merge settings into the environment. Non-objects are ignored.
|
|
136
|
+
* @param {import('#types').EnvironmentSettings} newSettings
|
|
137
|
+
* @returns {this}
|
|
138
|
+
*/
|
|
98
139
|
Environment.prototype.assignSettings = function assignSettings(newSettings) {
|
|
99
|
-
if (!newSettings || typeof newSettings !== 'object') return;
|
|
140
|
+
if (!newSettings || typeof newSettings !== 'object') return this;
|
|
100
141
|
this.settings = {
|
|
101
142
|
...this.settings,
|
|
102
143
|
...newSettings
|
|
103
144
|
};
|
|
145
|
+
return this;
|
|
104
146
|
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Resolve a registered script by language and identifier.
|
|
150
|
+
* @param {string} language
|
|
151
|
+
* @param {{ id: string, [x: string]: any }} identifier
|
|
152
|
+
*/
|
|
105
153
|
Environment.prototype.getScript = function getScript(...args) {
|
|
106
154
|
return this.scripts.getScript(...args);
|
|
107
155
|
};
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Register a script for an activity, delegating to the configured scripts engine.
|
|
159
|
+
* @param {any} activity
|
|
160
|
+
*/
|
|
108
161
|
Environment.prototype.registerScript = function registerScript(...args) {
|
|
109
162
|
return this.scripts.register(...args);
|
|
110
163
|
};
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Lookup a registered service by name.
|
|
167
|
+
* @param {string} serviceName
|
|
168
|
+
*/
|
|
111
169
|
Environment.prototype.getServiceByName = function getServiceByName(serviceName) {
|
|
112
|
-
return this[
|
|
170
|
+
return this[K_SERVICES][serviceName];
|
|
113
171
|
};
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Resolve an expression with the environment as scope, optionally extended by an element message.
|
|
175
|
+
* @param {string} expression
|
|
176
|
+
* @param {import('#types').ElementBrokerMessage} [message] Element message merged onto the resolution scope
|
|
177
|
+
* @param {any} [expressionFnContext]
|
|
178
|
+
*/
|
|
114
179
|
Environment.prototype.resolveExpression = function resolveExpression(expression, message, expressionFnContext) {
|
|
115
180
|
const from = {
|
|
116
181
|
environment: this,
|
|
@@ -118,9 +183,20 @@ Environment.prototype.resolveExpression = function resolveExpression(expression,
|
|
|
118
183
|
};
|
|
119
184
|
return this.expressions.resolveExpression(expression, from, expressionFnContext);
|
|
120
185
|
};
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Register a service callable by name.
|
|
189
|
+
* @param {string} name service function name
|
|
190
|
+
* @param {CallableFunction} fn service function
|
|
191
|
+
*/
|
|
121
192
|
Environment.prototype.addService = function addService(name, fn) {
|
|
122
|
-
this[
|
|
193
|
+
this[K_SERVICES][name] = fn;
|
|
123
194
|
};
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* @param {import('#types').EnvironmentOptions} input
|
|
198
|
+
* @returns {import('#types').EnvironmentOptions} validated options
|
|
199
|
+
*/
|
|
124
200
|
function validateOptions(input) {
|
|
125
201
|
const options = {};
|
|
126
202
|
for (const key in input) {
|
|
@@ -145,6 +221,10 @@ function validateOptions(input) {
|
|
|
145
221
|
}
|
|
146
222
|
return options;
|
|
147
223
|
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* @returns {import('#types').ILogger}
|
|
227
|
+
*/
|
|
148
228
|
function DummyLogger() {
|
|
149
229
|
return {
|
|
150
230
|
debug,
|
package/dist/EventBroker.js
CHANGED
|
@@ -10,10 +10,21 @@ exports.MessageFlowBroker = MessageFlowBroker;
|
|
|
10
10
|
exports.ProcessBroker = ProcessBroker;
|
|
11
11
|
var _smqp = require("smqp");
|
|
12
12
|
var _Errors = require("./error/Errors.js");
|
|
13
|
+
/**
|
|
14
|
+
* Build the broker for an activity, including run/format/execution/api exchanges and queues.
|
|
15
|
+
* @param {import('#types').Activity} activity
|
|
16
|
+
* @returns {import('#types').EventBroker<import('#types').Activity>}
|
|
17
|
+
*/
|
|
13
18
|
function ActivityBroker(activity) {
|
|
14
19
|
const executionBroker = ExecutionBroker(activity, 'activity');
|
|
15
20
|
return executionBroker;
|
|
16
21
|
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Build the broker for a process, with an additional api-q bound to all api routing keys.
|
|
25
|
+
* @param {import('#types').Process} owner
|
|
26
|
+
* @returns {import('#types').EventBroker<import('#types').Process>}
|
|
27
|
+
*/
|
|
17
28
|
function ProcessBroker(owner) {
|
|
18
29
|
const executionBroker = ExecutionBroker(owner, 'process');
|
|
19
30
|
executionBroker.broker.assertQueue('api-q', {
|
|
@@ -23,9 +34,22 @@ function ProcessBroker(owner) {
|
|
|
23
34
|
executionBroker.broker.bindQueue('api-q', 'api', '#');
|
|
24
35
|
return executionBroker;
|
|
25
36
|
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Build the broker for a definition. Optionally registers a custom return-message handler.
|
|
40
|
+
* @param {import('#types').Definition} owner
|
|
41
|
+
* @param {(message: import('#types').ElementBrokerMessage) => void} [onBrokerReturn]
|
|
42
|
+
* @returns {import('#types').EventBroker<import('#types').Definition>}
|
|
43
|
+
*/
|
|
26
44
|
function DefinitionBroker(owner, onBrokerReturn) {
|
|
27
45
|
return ExecutionBroker(owner, 'definition', onBrokerReturn);
|
|
28
46
|
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Build the broker for a message flow with a durable message exchange and message-q.
|
|
50
|
+
* @param {import('./flows/MessageFlow.js').MessageFlow} owner
|
|
51
|
+
* @returns {import('#types').EventBroker<import('./flows/MessageFlow.js').MessageFlow>}
|
|
52
|
+
*/
|
|
29
53
|
function MessageFlowBroker(owner) {
|
|
30
54
|
const eventBroker = new EventBroker(owner, {
|
|
31
55
|
prefix: 'messageflow',
|
|
@@ -85,10 +109,17 @@ function ExecutionBroker(brokerOwner, prefix, onBrokerReturn) {
|
|
|
85
109
|
broker.bindQueue(executionQ.name, 'execution', 'execution.#');
|
|
86
110
|
return eventBroker;
|
|
87
111
|
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Owns an smqp Broker on behalf of the calling element and exposes prefixed event helpers.
|
|
115
|
+
* @param {any} brokerOwner Element that owns the broker, accessed as `broker.owner`
|
|
116
|
+
* @param {{ prefix: string, autoDelete?: boolean, durable?: boolean }} options
|
|
117
|
+
* @param {(message: import('#types').ElementBrokerMessage) => void} [onBrokerReturn] Override for unrouted return messages
|
|
118
|
+
*/
|
|
88
119
|
function EventBroker(brokerOwner, options, onBrokerReturn) {
|
|
89
120
|
this.options = options;
|
|
90
121
|
this.eventPrefix = options.prefix;
|
|
91
|
-
const broker = this.broker =
|
|
122
|
+
const broker = this.broker = new _smqp.Broker(brokerOwner);
|
|
92
123
|
broker.assertExchange('event', 'topic', options);
|
|
93
124
|
broker.on('return', onBrokerReturn ? onBrokerReturn.bind(brokerOwner) : this._onBrokerReturnFn.bind(this));
|
|
94
125
|
this.on = this.on.bind(this);
|
|
@@ -97,6 +128,11 @@ function EventBroker(brokerOwner, options, onBrokerReturn) {
|
|
|
97
128
|
this.emit = this.emit.bind(this);
|
|
98
129
|
this.emitFatal = this.emitFatal.bind(this);
|
|
99
130
|
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Subscribe to a prefixed event. Errors are unwrapped via `makeErrorFromMessage`,
|
|
134
|
+
* other events resolve to the owner's Api wrapper.
|
|
135
|
+
*/
|
|
100
136
|
EventBroker.prototype.on = function on(eventName, callback, eventOptions = {
|
|
101
137
|
once: false
|
|
102
138
|
}) {
|
|
@@ -111,12 +147,20 @@ EventBroker.prototype.on = function on(eventName, callback, eventOptions = {
|
|
|
111
147
|
callback(owner.getApi(message));
|
|
112
148
|
}
|
|
113
149
|
};
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Subscribe to the next occurrence of an event.
|
|
153
|
+
*/
|
|
114
154
|
EventBroker.prototype.once = function once(eventName, callback, eventOptions) {
|
|
115
155
|
return this.on(eventName, callback, {
|
|
116
156
|
...eventOptions,
|
|
117
157
|
once: true
|
|
118
158
|
});
|
|
119
159
|
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Promise-style wait for an event. Rejects on a mandatory `*.error` message.
|
|
163
|
+
*/
|
|
120
164
|
EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
|
|
121
165
|
const key = this._getEventRoutingKey(eventName);
|
|
122
166
|
return new Promise((resolve, reject) => {
|
|
@@ -142,6 +186,10 @@ EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
|
|
|
142
186
|
}
|
|
143
187
|
});
|
|
144
188
|
};
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Publish a prefixed event message.
|
|
192
|
+
*/
|
|
145
193
|
EventBroker.prototype.emit = function emit(eventName, content, props) {
|
|
146
194
|
this.broker.publish('event', `${this.eventPrefix}.${eventName}`, {
|
|
147
195
|
...content
|
|
@@ -150,6 +198,10 @@ EventBroker.prototype.emit = function emit(eventName, content, props) {
|
|
|
150
198
|
...props
|
|
151
199
|
});
|
|
152
200
|
};
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Emit a mandatory error event. Surfaces via `on('error', ...)` or causes a return message to throw.
|
|
204
|
+
*/
|
|
153
205
|
EventBroker.prototype.emitFatal = function emitFatal(error, content) {
|
|
154
206
|
this.emit('error', {
|
|
155
207
|
...content,
|
|
@@ -158,12 +210,16 @@ EventBroker.prototype.emitFatal = function emitFatal(error, content) {
|
|
|
158
210
|
mandatory: true
|
|
159
211
|
});
|
|
160
212
|
};
|
|
213
|
+
|
|
214
|
+
/** @internal */
|
|
161
215
|
EventBroker.prototype._onBrokerReturnFn = function onBrokerReturnFn(message) {
|
|
162
216
|
if (message.properties.type === 'error') {
|
|
163
217
|
const err = (0, _Errors.makeErrorFromMessage)(message);
|
|
164
218
|
throw err;
|
|
165
219
|
}
|
|
166
220
|
};
|
|
221
|
+
|
|
222
|
+
/** @internal */
|
|
167
223
|
EventBroker.prototype._getEventRoutingKey = function getEventRoutingKey(eventName) {
|
|
168
224
|
if (eventName.indexOf('.') > -1) return eventName;
|
|
169
225
|
switch (eventName) {
|
package/dist/Expressions.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var _getPropertyValue =
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
6
|
+
exports.Expressions = Expressions;
|
|
7
|
+
var _getPropertyValue = require("./getPropertyValue.js");
|
|
9
8
|
const isExpressionPattern = /^\${(.+?)}$/;
|
|
10
9
|
const expressionPattern = /\${(.+?)}/;
|
|
11
10
|
function Expressions() {
|
|
@@ -30,7 +29,7 @@ function resolveExpression(templatedString, context, expressionFnContext) {
|
|
|
30
29
|
const n = Number(innerProperty);
|
|
31
30
|
if (!isNaN(n)) return n;
|
|
32
31
|
}
|
|
33
|
-
const contextValue = (0, _getPropertyValue.
|
|
32
|
+
const contextValue = (0, _getPropertyValue.getPropertyValue)(context, innerProperty, expressionFnContext);
|
|
34
33
|
if (expressionMatch.input === expressionMatch[0]) {
|
|
35
34
|
return contextValue;
|
|
36
35
|
}
|
package/dist/MessageFormatter.js
CHANGED
|
@@ -8,13 +8,15 @@ var _messageHelper = require("./messageHelper.js");
|
|
|
8
8
|
var _shared = require("./shared.js");
|
|
9
9
|
var _Errors = require("./error/Errors.js");
|
|
10
10
|
var _smqp = require("smqp");
|
|
11
|
-
|
|
12
|
-
const
|
|
11
|
+
var _constants = require("./constants.js");
|
|
12
|
+
const K_ON_MESSAGE = Symbol.for('onMessage');
|
|
13
13
|
const EXEC_ROUTING_KEY = 'run._formatting.exec';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Enriches an element run message via async format start/end messages on the `format` exchange
|
|
17
|
+
* before the run message is continued. Handlers publish enrichment by responding to a start
|
|
18
|
+
* message with a matching end (or error) routing key.
|
|
19
|
+
* @param {import('#types').ElementBase} element
|
|
18
20
|
*/
|
|
19
21
|
function Formatter(element) {
|
|
20
22
|
const {
|
|
@@ -25,13 +27,14 @@ function Formatter(element) {
|
|
|
25
27
|
this.id = id;
|
|
26
28
|
this.broker = broker;
|
|
27
29
|
this.logger = logger;
|
|
28
|
-
this[
|
|
30
|
+
this[K_ON_MESSAGE] = this._onMessage.bind(this);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
|
-
* Format message
|
|
33
|
-
*
|
|
34
|
-
* @param {
|
|
34
|
+
* Format the given run message. Callback fires with `(err, content, formatted)` once
|
|
35
|
+
* formatting completes; `formatted` is true when content was actually enriched.
|
|
36
|
+
* @param {import('#types').ElementBrokerMessage} message
|
|
37
|
+
* @param {(err: Error | null, content?: import('#types').ElementMessageContent, formatted?: boolean) => void} callback
|
|
35
38
|
*/
|
|
36
39
|
Formatter.prototype.format = function format(message, callback) {
|
|
37
40
|
const correlationId = this._runId = (0, _shared.getUniqueId)(message.fields.routingKey);
|
|
@@ -41,7 +44,7 @@ Formatter.prototype.format = function format(message, callback) {
|
|
|
41
44
|
correlationId,
|
|
42
45
|
persistent: false
|
|
43
46
|
});
|
|
44
|
-
this[
|
|
47
|
+
this[_constants.K_EXECUTION] = {
|
|
45
48
|
correlationId,
|
|
46
49
|
formatKey: message.fields.routingKey,
|
|
47
50
|
runMessage: (0, _messageHelper.cloneMessage)(message),
|
|
@@ -50,18 +53,20 @@ Formatter.prototype.format = function format(message, callback) {
|
|
|
50
53
|
formatted: false,
|
|
51
54
|
executeMessage: null
|
|
52
55
|
};
|
|
53
|
-
broker.consume('format-run-q', this[
|
|
56
|
+
broker.consume('format-run-q', this[K_ON_MESSAGE], {
|
|
54
57
|
consumerTag,
|
|
55
58
|
prefetch: 100
|
|
56
59
|
});
|
|
57
60
|
};
|
|
61
|
+
|
|
62
|
+
/** @internal */
|
|
58
63
|
Formatter.prototype._onMessage = function onMessage(routingKey, message) {
|
|
59
64
|
const {
|
|
60
65
|
formatKey,
|
|
61
66
|
correlationId,
|
|
62
67
|
pending,
|
|
63
68
|
executeMessage
|
|
64
|
-
} = this[
|
|
69
|
+
} = this[_constants.K_EXECUTION];
|
|
65
70
|
const asyncFormatting = pending.size;
|
|
66
71
|
if (routingKey === EXEC_ROUTING_KEY) {
|
|
67
72
|
if (message.properties.correlationId !== correlationId) return message.ack();
|
|
@@ -69,7 +74,7 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
|
|
|
69
74
|
if (!asyncFormatting) {
|
|
70
75
|
return this._complete(message);
|
|
71
76
|
}
|
|
72
|
-
this[
|
|
77
|
+
this[_constants.K_EXECUTION].executeMessage = message;
|
|
73
78
|
} else {
|
|
74
79
|
message.ack();
|
|
75
80
|
const endRoutingKey = message.content?.endRoutingKey;
|
|
@@ -91,6 +96,8 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
|
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
};
|
|
99
|
+
|
|
100
|
+
/** @internal */
|
|
94
101
|
Formatter.prototype._complete = function complete(message, isError) {
|
|
95
102
|
const {
|
|
96
103
|
runMessage,
|
|
@@ -98,8 +105,8 @@ Formatter.prototype._complete = function complete(message, isError) {
|
|
|
98
105
|
callback,
|
|
99
106
|
formatted,
|
|
100
107
|
executeMessage
|
|
101
|
-
} = this[
|
|
102
|
-
this[
|
|
108
|
+
} = this[_constants.K_EXECUTION];
|
|
109
|
+
this[_constants.K_EXECUTION] = null;
|
|
103
110
|
if (executeMessage) executeMessage.ack();
|
|
104
111
|
this.broker.cancel(message.fields.consumerTag);
|
|
105
112
|
if (isError) {
|
|
@@ -110,8 +117,10 @@ Formatter.prototype._complete = function complete(message, isError) {
|
|
|
110
117
|
}
|
|
111
118
|
return callback(null, runMessage.content, formatted);
|
|
112
119
|
};
|
|
120
|
+
|
|
121
|
+
/** @internal */
|
|
113
122
|
Formatter.prototype._enrich = function enrich(withContent) {
|
|
114
|
-
const content = this[
|
|
123
|
+
const content = this[_constants.K_EXECUTION].runMessage.content;
|
|
115
124
|
for (const key in withContent) {
|
|
116
125
|
switch (key) {
|
|
117
126
|
case 'id':
|
|
@@ -129,11 +138,13 @@ Formatter.prototype._enrich = function enrich(withContent) {
|
|
|
129
138
|
default:
|
|
130
139
|
{
|
|
131
140
|
content[key] = withContent[key];
|
|
132
|
-
this[
|
|
141
|
+
this[_constants.K_EXECUTION].formatted = true;
|
|
133
142
|
}
|
|
134
143
|
}
|
|
135
144
|
}
|
|
136
145
|
};
|
|
146
|
+
|
|
147
|
+
/** @internal */
|
|
137
148
|
Formatter.prototype._popFormatStart = function popFormattingStart(pending, routingKey) {
|
|
138
149
|
for (const msg of pending) {
|
|
139
150
|
const {
|
|
@@ -156,6 +167,8 @@ Formatter.prototype._popFormatStart = function popFormattingStart(pending, routi
|
|
|
156
167
|
}
|
|
157
168
|
return {};
|
|
158
169
|
};
|
|
170
|
+
|
|
171
|
+
/** @internal */
|
|
159
172
|
Formatter.prototype._debug = function debug(msg) {
|
|
160
173
|
this.logger.debug(`<${this.id}> ${msg}`);
|
|
161
174
|
};
|
package/dist/Timers.js
CHANGED
|
@@ -4,9 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Timers = Timers;
|
|
7
|
-
const
|
|
8
|
-
const
|
|
7
|
+
const K_EXECUTING = Symbol.for('executing');
|
|
8
|
+
const K_TIMER_API = Symbol.for('timers api');
|
|
9
9
|
const MAX_DELAY = 2147483647;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {import('#types').TimersOptions} options
|
|
13
|
+
*/
|
|
10
14
|
function Timers(options) {
|
|
11
15
|
this.count = 0;
|
|
12
16
|
this.options = {
|
|
@@ -14,13 +18,13 @@ function Timers(options) {
|
|
|
14
18
|
clearTimeout,
|
|
15
19
|
...options
|
|
16
20
|
};
|
|
17
|
-
this[
|
|
21
|
+
this[K_EXECUTING] = new Set();
|
|
18
22
|
this.setTimeout = this.setTimeout.bind(this);
|
|
19
23
|
this.clearTimeout = this.clearTimeout.bind(this);
|
|
20
24
|
}
|
|
21
25
|
Object.defineProperty(Timers.prototype, 'executing', {
|
|
22
26
|
get() {
|
|
23
|
-
return [...this[
|
|
27
|
+
return [...this[K_EXECUTING]];
|
|
24
28
|
}
|
|
25
29
|
});
|
|
26
30
|
Timers.prototype.register = function register(owner) {
|
|
@@ -30,14 +34,14 @@ Timers.prototype.setTimeout = function wrappedSetTimeout(callback, delay, ...arg
|
|
|
30
34
|
return this._setTimeout(null, callback, delay, ...args);
|
|
31
35
|
};
|
|
32
36
|
Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
|
|
33
|
-
if (this[
|
|
37
|
+
if (this[K_EXECUTING].delete(ref)) {
|
|
34
38
|
ref.timerRef = this.options.clearTimeout(ref.timerRef);
|
|
35
39
|
return;
|
|
36
40
|
}
|
|
37
41
|
return this.options.clearTimeout(ref);
|
|
38
42
|
};
|
|
39
43
|
Timers.prototype._setTimeout = function setTimeout(owner, callback, delay, ...args) {
|
|
40
|
-
const executing = this[
|
|
44
|
+
const executing = this[K_EXECUTING];
|
|
41
45
|
const ref = this._getReference(owner, callback, delay, args);
|
|
42
46
|
executing.add(ref);
|
|
43
47
|
if (delay < MAX_DELAY) {
|
|
@@ -53,17 +57,17 @@ Timers.prototype._getReference = function getReference(owner, callback, delay, a
|
|
|
53
57
|
return new Timer(owner, `timer_${this.count++}`, callback, delay, args);
|
|
54
58
|
};
|
|
55
59
|
function RegisteredTimers(timersApi, owner) {
|
|
56
|
-
this[
|
|
60
|
+
this[K_TIMER_API] = timersApi;
|
|
57
61
|
this.owner = owner;
|
|
58
62
|
this.setTimeout = this.setTimeout.bind(this);
|
|
59
63
|
this.clearTimeout = this.clearTimeout.bind(this);
|
|
60
64
|
}
|
|
61
65
|
RegisteredTimers.prototype.setTimeout = function registeredSetTimeout(callback, delay, ...args) {
|
|
62
|
-
const timersApi = this[
|
|
66
|
+
const timersApi = this[K_TIMER_API];
|
|
63
67
|
return timersApi._setTimeout(this.owner, callback, delay, ...args);
|
|
64
68
|
};
|
|
65
69
|
RegisteredTimers.prototype.clearTimeout = function registeredClearTimeout(ref) {
|
|
66
|
-
this[
|
|
70
|
+
this[K_TIMER_API].clearTimeout(ref);
|
|
67
71
|
};
|
|
68
72
|
function Timer(owner, timerId, callback, delay, args) {
|
|
69
73
|
this.callback = callback;
|
package/dist/Tracker.js
CHANGED
|
@@ -36,6 +36,7 @@ ActivityTracker.prototype.track = function track(routingKey, message) {
|
|
|
36
36
|
this._executing(executionId);
|
|
37
37
|
break;
|
|
38
38
|
case 'activity.execution.outbound.take':
|
|
39
|
+
case 'activity.converge':
|
|
39
40
|
case 'activity.detach':
|
|
40
41
|
case 'activity.call':
|
|
41
42
|
case 'activity.wait':
|