bpmn-elements 6.0.0 → 8.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/CHANGELOG.md +335 -0
- package/README.md +3 -0
- package/dist/index.js +52 -44
- package/dist/src/Api.js +77 -76
- package/dist/src/Context.js +176 -172
- package/dist/src/Environment.js +110 -102
- package/dist/src/EventBroker.js +89 -88
- package/dist/src/ExtensionsMapper.js +2 -2
- package/dist/src/MessageFormatter.js +164 -95
- package/dist/src/Scripts.js +6 -2
- package/dist/src/activity/Activity.js +1106 -916
- package/dist/src/activity/ActivityExecution.js +342 -297
- package/dist/src/activity/Dummy.js +3 -3
- package/dist/src/definition/Definition.js +498 -444
- package/dist/src/definition/DefinitionExecution.js +710 -408
- package/dist/src/error/Errors.js +17 -7
- package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
- package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
- package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
- package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
- package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
- package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
- package/dist/src/events/BoundaryEvent.js +180 -144
- package/dist/src/events/EndEvent.js +18 -23
- package/dist/src/events/IntermediateCatchEvent.js +44 -58
- package/dist/src/events/IntermediateThrowEvent.js +18 -23
- package/dist/src/events/StartEvent.js +109 -94
- package/dist/src/flows/Association.js +94 -100
- package/dist/src/flows/MessageFlow.js +86 -103
- package/dist/src/flows/SequenceFlow.js +173 -182
- package/dist/src/gateways/EventBasedGateway.js +88 -84
- package/dist/src/gateways/ExclusiveGateway.js +13 -16
- package/dist/src/gateways/InclusiveGateway.js +11 -14
- package/dist/src/gateways/ParallelGateway.js +11 -14
- package/dist/src/getPropertyValue.js +34 -34
- package/dist/src/io/BpmnIO.js +17 -14
- package/dist/src/io/EnvironmentDataObject.js +33 -29
- package/dist/src/io/EnvironmentDataStore.js +33 -29
- package/dist/src/io/EnvironmentDataStoreReference.js +35 -31
- package/dist/src/io/InputOutputSpecification.js +177 -168
- package/dist/src/io/Properties.js +117 -124
- package/dist/src/messageHelper.js +1 -1
- package/dist/src/process/Process.js +439 -362
- package/dist/src/process/ProcessExecution.js +748 -646
- package/dist/src/shared.js +2 -2
- package/dist/src/tasks/CallActivity.js +160 -0
- package/dist/src/tasks/LoopCharacteristics.js +309 -330
- package/dist/src/tasks/ReceiveTask.js +233 -182
- package/dist/src/tasks/ScriptTask.js +35 -41
- package/dist/src/tasks/ServiceImplementation.js +13 -20
- package/dist/src/tasks/ServiceTask.js +82 -75
- package/dist/src/tasks/SignalTask.js +97 -93
- package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/dist/src/tasks/SubProcess.js +193 -175
- package/dist/src/tasks/Task.js +17 -19
- package/index.js +2 -0
- package/package.json +15 -15
- package/src/Api.js +65 -59
- package/src/Context.js +145 -140
- package/src/Environment.js +116 -100
- package/src/EventBroker.js +67 -68
- package/src/ExtensionsMapper.js +2 -2
- package/src/MessageFormatter.js +132 -74
- package/src/activity/Activity.js +915 -775
- package/src/activity/ActivityExecution.js +293 -247
- package/src/activity/Dummy.js +2 -2
- package/src/definition/Definition.js +437 -401
- package/src/definition/DefinitionExecution.js +598 -340
- package/src/error/Errors.js +11 -6
- package/src/eventDefinitions/CancelEventDefinition.js +164 -121
- package/src/eventDefinitions/CompensateEventDefinition.js +159 -124
- package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
- package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
- package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
- package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
- package/src/eventDefinitions/LinkEventDefinition.js +160 -129
- package/src/eventDefinitions/MessageEventDefinition.js +178 -121
- package/src/eventDefinitions/SignalEventDefinition.js +162 -106
- package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
- package/src/eventDefinitions/TimerEventDefinition.js +202 -167
- package/src/events/BoundaryEvent.js +156 -115
- package/src/events/EndEvent.js +15 -18
- package/src/events/IntermediateCatchEvent.js +40 -44
- package/src/events/IntermediateThrowEvent.js +15 -18
- package/src/events/StartEvent.js +84 -50
- package/src/flows/Association.js +98 -112
- package/src/flows/MessageFlow.js +81 -97
- package/src/flows/SequenceFlow.js +146 -160
- package/src/gateways/EventBasedGateway.js +75 -68
- package/src/gateways/ExclusiveGateway.js +8 -13
- package/src/gateways/InclusiveGateway.js +8 -13
- package/src/gateways/ParallelGateway.js +8 -13
- package/src/getPropertyValue.js +34 -33
- package/src/io/BpmnIO.js +20 -15
- package/src/io/EnvironmentDataObject.js +29 -18
- package/src/io/EnvironmentDataStore.js +29 -18
- package/src/io/EnvironmentDataStoreReference.js +31 -20
- package/src/io/InputOutputSpecification.js +154 -157
- package/src/io/Properties.js +95 -97
- package/src/process/Process.js +378 -333
- package/src/process/ProcessExecution.js +603 -553
- package/src/tasks/CallActivity.js +130 -0
- package/src/tasks/LoopCharacteristics.js +290 -289
- package/src/tasks/ReceiveTask.js +174 -107
- package/src/tasks/ScriptTask.js +27 -30
- package/src/tasks/ServiceImplementation.js +13 -18
- package/src/tasks/ServiceTask.js +67 -60
- package/src/tasks/SignalTask.js +77 -52
- package/src/tasks/StandardLoopCharacteristics.js +1 -1
- package/src/tasks/SubProcess.js +184 -157
- package/src/tasks/Task.js +15 -19
package/src/Environment.js
CHANGED
|
@@ -2,122 +2,138 @@ import Expressions from './Expressions';
|
|
|
2
2
|
import {Scripts as IScripts} from './Scripts';
|
|
3
3
|
import {Timers} from './Timers';
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const kServices = Symbol.for('services');
|
|
6
|
+
const kVariables = Symbol.for('variables');
|
|
7
|
+
|
|
8
|
+
const defaultOptions = [
|
|
9
|
+
'expressions',
|
|
10
|
+
'extensions',
|
|
11
|
+
'Logger',
|
|
12
|
+
'output',
|
|
13
|
+
'scripts',
|
|
14
|
+
'services',
|
|
15
|
+
'settings',
|
|
16
|
+
'timers',
|
|
17
|
+
'variables',
|
|
18
|
+
];
|
|
6
19
|
|
|
7
20
|
export default function Environment(options = {}) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const environmentApi = {
|
|
21
|
-
options: initialOptions,
|
|
22
|
-
expressions,
|
|
23
|
-
extensions,
|
|
24
|
-
output,
|
|
25
|
-
scripts,
|
|
26
|
-
services,
|
|
27
|
-
settings,
|
|
28
|
-
timers,
|
|
29
|
-
get variables() {
|
|
30
|
-
return variables;
|
|
31
|
-
},
|
|
32
|
-
addService,
|
|
33
|
-
assignVariables,
|
|
34
|
-
clone,
|
|
35
|
-
getScript,
|
|
36
|
-
getServiceByName,
|
|
37
|
-
getState,
|
|
38
|
-
registerScript,
|
|
39
|
-
resolveExpression,
|
|
40
|
-
recover,
|
|
41
|
-
Logger,
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
return environmentApi;
|
|
21
|
+
this.options = validateOptions(options);
|
|
22
|
+
|
|
23
|
+
this.expressions = options.expressions || Expressions();
|
|
24
|
+
this.extensions = options.extensions;
|
|
25
|
+
this.output = options.output || {};
|
|
26
|
+
this.scripts = options.scripts || IScripts();
|
|
27
|
+
this.timers = options.timers || Timers();
|
|
28
|
+
this.settings = {...options.settings};
|
|
29
|
+
this.Logger = options.Logger || DummyLogger;
|
|
30
|
+
this[kServices] = options.services || {};
|
|
31
|
+
this[kVariables] = options.variables || {};
|
|
32
|
+
}
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
34
|
+
const proto = Environment.prototype;
|
|
35
|
+
|
|
36
|
+
Object.defineProperty(proto, 'variables', {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get() {
|
|
39
|
+
return this[kVariables];
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
Object.defineProperty(proto, 'services', {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get() {
|
|
46
|
+
return this[kServices];
|
|
47
|
+
},
|
|
48
|
+
set(value) {
|
|
49
|
+
const services = this[kServices];
|
|
50
|
+
for (const name in services) {
|
|
51
|
+
if (!(name in value)) delete services[name];
|
|
52
|
+
}
|
|
53
|
+
Object.assign(services, value);
|
|
54
|
+
},
|
|
55
|
+
});
|
|
53
56
|
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
proto.getState = function getState() {
|
|
58
|
+
return {
|
|
59
|
+
settings: {...this.settings},
|
|
60
|
+
variables: {...this[kVariables]},
|
|
61
|
+
output: {...this.output},
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
proto.recover = function recover(state) {
|
|
66
|
+
if (!state) return this;
|
|
67
|
+
|
|
68
|
+
if (state.settings) Object.assign(this.settings, state.settings);
|
|
69
|
+
if (state.variables) Object.assign(this[kVariables], state.variables);
|
|
70
|
+
if (state.output) Object.assign(this.output, state.output);
|
|
71
|
+
|
|
72
|
+
return this;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
proto.clone = function clone(overrideOptions = {}) {
|
|
76
|
+
const services = this[kServices];
|
|
77
|
+
const newOptions = {
|
|
78
|
+
settings: {...this.settings},
|
|
79
|
+
variables: {...this[kVariables]},
|
|
80
|
+
Logger: this.Logger,
|
|
81
|
+
extensions: this.extensions,
|
|
82
|
+
scripts: this.scripts,
|
|
83
|
+
timers: this.timers,
|
|
84
|
+
expressions: this.expressions,
|
|
85
|
+
...this.options,
|
|
86
|
+
...overrideOptions,
|
|
87
|
+
services,
|
|
88
|
+
};
|
|
56
89
|
|
|
57
|
-
|
|
58
|
-
Object.assign(options, recoverOptions);
|
|
90
|
+
if (overrideOptions.services) newOptions.services = {...services, ...overrideOptions.services};
|
|
59
91
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (state.output) Object.assign(output, state.output);
|
|
92
|
+
return new this.constructor(newOptions);
|
|
93
|
+
};
|
|
63
94
|
|
|
64
|
-
|
|
65
|
-
|
|
95
|
+
proto.assignVariables = function assignVariables(newVars) {
|
|
96
|
+
if (!newVars || typeof newVars !== 'object') return;
|
|
66
97
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Logger,
|
|
73
|
-
extensions,
|
|
74
|
-
scripts,
|
|
75
|
-
timers,
|
|
76
|
-
expressions,
|
|
77
|
-
...initialOptions,
|
|
78
|
-
...overrideOptions,
|
|
79
|
-
services,
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
if (overrideOptions.services) newOptions.services = {...services, ...overrideOptions.services};
|
|
83
|
-
|
|
84
|
-
return Environment(newOptions);
|
|
85
|
-
}
|
|
98
|
+
this[kVariables] = {
|
|
99
|
+
...this.variables,
|
|
100
|
+
...newVars,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
86
103
|
|
|
87
|
-
|
|
88
|
-
|
|
104
|
+
proto.assignSettings = function assignVariables(newSettings) {
|
|
105
|
+
if (!newSettings || typeof newSettings !== 'object') return;
|
|
89
106
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
107
|
+
this.settings = {
|
|
108
|
+
...this.settings,
|
|
109
|
+
...newSettings,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
95
112
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
113
|
+
proto.getScript = function getScript(...args) {
|
|
114
|
+
return this.scripts.getScript(...args);
|
|
115
|
+
};
|
|
99
116
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
117
|
+
proto.registerScript = function registerScript(...args) {
|
|
118
|
+
return this.scripts.register(...args);
|
|
119
|
+
};
|
|
103
120
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
121
|
+
proto.getServiceByName = function getServiceByName(serviceName) {
|
|
122
|
+
return this[kServices][serviceName];
|
|
123
|
+
};
|
|
107
124
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
125
|
+
proto.resolveExpression = function resolveExpression(expression, message = {}, expressionFnContext) {
|
|
126
|
+
const from = {
|
|
127
|
+
environment: this,
|
|
128
|
+
...message,
|
|
129
|
+
};
|
|
113
130
|
|
|
114
|
-
|
|
115
|
-
|
|
131
|
+
return this.expressions.resolveExpression(expression, from, expressionFnContext);
|
|
132
|
+
};
|
|
116
133
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
134
|
+
proto.addService = function addService(name, fn) {
|
|
135
|
+
this[kServices][name] = fn;
|
|
136
|
+
};
|
|
121
137
|
|
|
122
138
|
function validateOptions(input) {
|
|
123
139
|
const options = {};
|
package/src/EventBroker.js
CHANGED
|
@@ -23,7 +23,7 @@ function DefinitionBroker(owner, onBrokerReturn) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
function MessageFlowBroker(owner) {
|
|
26
|
-
const eventBroker = EventBroker(owner, {prefix: 'messageflow', autoDelete: false, durable: false});
|
|
26
|
+
const eventBroker = new EventBroker(owner, {prefix: 'messageflow', autoDelete: false, durable: false});
|
|
27
27
|
const broker = eventBroker.broker;
|
|
28
28
|
|
|
29
29
|
broker.assertExchange('message', 'topic', {durable: true, autoDelete: false});
|
|
@@ -34,7 +34,7 @@ function MessageFlowBroker(owner) {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
function ExecutionBroker(brokerOwner, prefix, onBrokerReturn) {
|
|
37
|
-
const eventBroker = EventBroker(brokerOwner, {prefix, autoDelete: false, durable: false}, onBrokerReturn);
|
|
37
|
+
const eventBroker = new EventBroker(brokerOwner, {prefix, autoDelete: false, durable: false}, onBrokerReturn);
|
|
38
38
|
const broker = eventBroker.broker;
|
|
39
39
|
|
|
40
40
|
broker.assertExchange('api', 'topic', {autoDelete: false, durable: false});
|
|
@@ -54,90 +54,89 @@ function ExecutionBroker(brokerOwner, prefix, onBrokerReturn) {
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function EventBroker(brokerOwner, options, onBrokerReturn) {
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
this.options = options;
|
|
58
|
+
this.eventPrefix = options.prefix;
|
|
59
59
|
|
|
60
|
+
const broker = this.broker = Broker(brokerOwner);
|
|
60
61
|
broker.assertExchange('event', 'topic', options);
|
|
61
|
-
broker.on('return', onBrokerReturn
|
|
62
|
+
broker.on('return', onBrokerReturn ? onBrokerReturn.bind(brokerOwner) : this._onBrokerReturnFn.bind(this));
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
emit,
|
|
70
|
-
emitFatal,
|
|
71
|
-
};
|
|
64
|
+
this.on = this.on.bind(this);
|
|
65
|
+
this.once = this.once.bind(this);
|
|
66
|
+
this.waitFor = this.waitFor.bind(this);
|
|
67
|
+
this.emit = this.emit.bind(this);
|
|
68
|
+
this.emitFatal = this.emitFatal.bind(this);
|
|
69
|
+
}
|
|
72
70
|
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
EventBroker.prototype.on = function on(eventName, callback, eventOptions = { once: false }) {
|
|
72
|
+
const key = this._getEventRoutingKey(eventName);
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
if (eventOptions.once) return this.broker.subscribeOnce('event', key, eventCallback, eventOptions);
|
|
75
|
+
return this.broker.subscribeTmp('event', key, eventCallback, {...eventOptions, noAck: true});
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
77
|
+
function eventCallback(routingKey, message, owner) {
|
|
78
|
+
if (eventName === 'error') return callback(makeErrorFromMessage(message));
|
|
79
|
+
callback(owner.getApi(message));
|
|
83
80
|
}
|
|
81
|
+
};
|
|
84
82
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
EventBroker.prototype.once = function once(eventName, callback, eventOptions = {}) {
|
|
84
|
+
return this.on(eventName, callback, {...eventOptions, once: true});
|
|
85
|
+
};
|
|
88
86
|
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
|
|
88
|
+
const key = this._getEventRoutingKey(eventName);
|
|
91
89
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
90
|
+
return new Promise((resolve, reject) => {
|
|
91
|
+
const consumers = [
|
|
92
|
+
this.broker.subscribeTmp('event', key, eventCallback, {noAck: true}),
|
|
93
|
+
this.broker.subscribeTmp('event', '*.error', errorCallback, {noAck: true}),
|
|
94
|
+
];
|
|
97
95
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
96
|
+
function eventCallback(routingKey, message, owner) {
|
|
97
|
+
if (onMessage && !onMessage(routingKey, message, owner)) return;
|
|
98
|
+
unsubscribe();
|
|
99
|
+
return resolve(owner.getApi(message));
|
|
100
|
+
}
|
|
103
101
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
102
|
+
function errorCallback(routingKey, message, owner) {
|
|
103
|
+
if (!message.properties.mandatory) return;
|
|
104
|
+
unsubscribe();
|
|
105
|
+
return reject(makeErrorFromMessage(message, owner));
|
|
106
|
+
}
|
|
109
107
|
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
function unsubscribe() {
|
|
109
|
+
for (const consumer of consumers) {
|
|
110
|
+
consumer.cancel();
|
|
112
111
|
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
function onBrokerReturnFn(message) {
|
|
117
|
-
if (message.properties.type === 'error') {
|
|
118
|
-
const err = makeErrorFromMessage(message);
|
|
119
|
-
throw err;
|
|
120
112
|
}
|
|
121
|
-
}
|
|
113
|
+
});
|
|
114
|
+
};
|
|
122
115
|
|
|
123
|
-
|
|
124
|
-
|
|
116
|
+
EventBroker.prototype.emit = function emit(eventName, content, props) {
|
|
117
|
+
this.broker.publish('event', `${this.eventPrefix}.${eventName}`, {...content}, {type: eventName, ...props});
|
|
118
|
+
};
|
|
125
119
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
default: {
|
|
131
|
-
return `${pfx}.${eventName}`;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
120
|
+
EventBroker.prototype.emitFatal = function emitFatal(error, content) {
|
|
121
|
+
this.emit('error', {...content, error}, {mandatory: true});
|
|
122
|
+
};
|
|
135
123
|
|
|
136
|
-
|
|
137
|
-
|
|
124
|
+
EventBroker.prototype._onBrokerReturnFn = function onBrokerReturnFn(message) {
|
|
125
|
+
if (message.properties.type === 'error') {
|
|
126
|
+
const err = makeErrorFromMessage(message);
|
|
127
|
+
throw err;
|
|
138
128
|
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
EventBroker.prototype._getEventRoutingKey = function getEventRoutingKey(eventName) {
|
|
132
|
+
if (eventName.indexOf('.') > -1) return eventName;
|
|
139
133
|
|
|
140
|
-
|
|
141
|
-
|
|
134
|
+
switch (eventName) {
|
|
135
|
+
case 'wait': {
|
|
136
|
+
return `activity.${eventName}`;
|
|
137
|
+
}
|
|
138
|
+
default: {
|
|
139
|
+
return `${this.eventPrefix}.${eventName}`;
|
|
140
|
+
}
|
|
142
141
|
}
|
|
143
|
-
}
|
|
142
|
+
};
|
package/src/ExtensionsMapper.js
CHANGED
|
@@ -20,10 +20,10 @@ export default function ExtensionsMapper(context) {
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
function activate(message) {
|
|
23
|
-
|
|
23
|
+
for (const extension of activityExtensions) extension.activate(message);
|
|
24
24
|
}
|
|
25
25
|
function deactivate(message) {
|
|
26
|
-
|
|
26
|
+
for (const extension of activityExtensions) extension.deactivate(message);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
|
package/src/MessageFormatter.js
CHANGED
|
@@ -1,96 +1,154 @@
|
|
|
1
|
-
import {cloneMessage
|
|
2
|
-
import {
|
|
1
|
+
import {cloneMessage} from './messageHelper';
|
|
2
|
+
import {getUniqueId} from './shared';
|
|
3
3
|
import {ActivityError} from './error/Errors';
|
|
4
4
|
import {getRoutingKeyPattern} from 'smqp';
|
|
5
5
|
|
|
6
|
+
const kOnMessage = Symbol.for('onMessage');
|
|
7
|
+
const kExecution = Symbol.for('execution');
|
|
8
|
+
|
|
6
9
|
export {Formatter};
|
|
7
10
|
|
|
8
11
|
function Formatter(element, formatQ) {
|
|
9
12
|
const {id, broker, logger} = element;
|
|
13
|
+
this.id = id;
|
|
14
|
+
this.broker = broker;
|
|
15
|
+
this.logger = logger;
|
|
16
|
+
this.formatQ = formatQ;
|
|
10
17
|
|
|
11
|
-
|
|
12
|
-
const startFormatMsg = formatQ.get();
|
|
13
|
-
if (!startFormatMsg) return callback(null, runMessage.content, false);
|
|
14
|
-
|
|
15
|
-
const pendingFormats = [];
|
|
16
|
-
const {fields, content} = runMessage;
|
|
17
|
-
const fundamentals = {
|
|
18
|
-
id: content.id,
|
|
19
|
-
type: content.type,
|
|
20
|
-
parent: cloneParent(content.parent),
|
|
21
|
-
attachedTo: content.attachedTo,
|
|
22
|
-
executionId: content.executionId,
|
|
23
|
-
isSubProcess: content.isSubProcess,
|
|
24
|
-
isMultiInstance: content.isMultiInstance,
|
|
25
|
-
};
|
|
26
|
-
if (content.inbound) {
|
|
27
|
-
fundamentals.inbound = content.inbound.slice();
|
|
28
|
-
}
|
|
29
|
-
if (content.outbound) {
|
|
30
|
-
fundamentals.outbound = content.outbound.slice();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
let formattingError;
|
|
34
|
-
let formattedContent = cloneContent(content);
|
|
18
|
+
this.pendingFormats = [];
|
|
35
19
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
depleted.cancel();
|
|
39
|
-
logger.debug(`<${id}> completed formatting ${fields.routingKey}`);
|
|
40
|
-
broker.cancel('_format-consumer');
|
|
41
|
-
if (formattingError) return callback(formattingError);
|
|
42
|
-
return callback(null, filterUndefined(formattedContent), true);
|
|
43
|
-
});
|
|
20
|
+
this[kOnMessage] = this._onMessage.bind(this);
|
|
21
|
+
}
|
|
44
22
|
|
|
45
|
-
|
|
46
|
-
|
|
23
|
+
Formatter.prototype.format = function format(message, callback) {
|
|
24
|
+
const correlationId = this._runId = getUniqueId(message.fields.routingKey);
|
|
25
|
+
const consumerTag = '_formatter-' + correlationId;
|
|
26
|
+
const formatQ = this.formatQ;
|
|
27
|
+
|
|
28
|
+
formatQ.queueMessage({
|
|
29
|
+
routingKey: '_formatting.exec',
|
|
30
|
+
}, {}, {
|
|
31
|
+
correlationId,
|
|
32
|
+
persistent: false,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
this[kExecution] = {
|
|
36
|
+
correlationId,
|
|
37
|
+
formatKey: message.fields.routingKey,
|
|
38
|
+
runMessage: cloneMessage(message),
|
|
39
|
+
callback,
|
|
40
|
+
pending: [],
|
|
41
|
+
formatted: false,
|
|
42
|
+
executeMessage: null,
|
|
43
|
+
};
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
formatQ.consume(this[kOnMessage], {
|
|
46
|
+
consumerTag,
|
|
47
|
+
prefetch: 100,
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
Formatter.prototype._onMessage = function onMessage(routingKey, message) {
|
|
52
|
+
const {formatKey, correlationId, pending, executeMessage} = this[kExecution];
|
|
53
|
+
const asyncFormatting = pending.length;
|
|
54
|
+
|
|
55
|
+
switch (routingKey) {
|
|
56
|
+
case '_formatting.exec':
|
|
57
|
+
if (message.properties.correlationId !== correlationId) return message.ack();
|
|
58
|
+
if (!asyncFormatting) {
|
|
59
|
+
message.ack();
|
|
60
|
+
return this._complete(message);
|
|
61
|
+
}
|
|
62
|
+
this[kExecution].executeMessage = message;
|
|
63
|
+
break;
|
|
64
|
+
default: {
|
|
65
|
+
message.ack();
|
|
50
66
|
|
|
67
|
+
const endRoutingKey = message.content && message.content.endRoutingKey;
|
|
51
68
|
if (endRoutingKey) {
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
this._decorate(message.content);
|
|
70
|
+
pending.push(message);
|
|
71
|
+
return this._debug(`start formatting ${formatKey} message content with formatter ${routingKey}`);
|
|
54
72
|
}
|
|
55
73
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
74
|
+
if (asyncFormatting) {
|
|
75
|
+
const {isError, message: startMessage} = this._popFormatStart(pending, routingKey);
|
|
76
|
+
if (startMessage) startMessage.ack();
|
|
59
77
|
|
|
60
|
-
formattedContent = {
|
|
61
|
-
...formattedContent,
|
|
62
|
-
...message.content,
|
|
63
|
-
...fundamentals,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
message.ack();
|
|
67
|
-
if (formatStart) {
|
|
68
78
|
if (isError) {
|
|
69
|
-
|
|
70
|
-
logger.debug(`<${id}> formatting of ${fields.routingKey} failed with ${routingKey}: ${errMessage}`);
|
|
71
|
-
formattingError = new ActivityError(errMessage, cloneMessage(runMessage, formattedContent), error);
|
|
72
|
-
pendingFormats.splice(0).forEach(({nack}) => nack(false, false));
|
|
79
|
+
return this._complete(message, true);
|
|
73
80
|
}
|
|
74
|
-
formatStart.ack(isError);
|
|
75
81
|
}
|
|
76
|
-
}
|
|
77
82
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const pendingFormat = pendingFormats[i];
|
|
81
|
-
const {endRoutingKey, errorRoutingKey = '#.error'} = pendingFormat.content;
|
|
82
|
-
|
|
83
|
-
if (getRoutingKeyPattern(endRoutingKey).test(routingKey)) {
|
|
84
|
-
logger.debug(`<${id}> completed formatting ${fields.routingKey} message content with formatter ${routingKey}`);
|
|
85
|
-
pendingFormats.splice(i, 1);
|
|
86
|
-
return {message: pendingFormat};
|
|
87
|
-
} else if (getRoutingKeyPattern(errorRoutingKey).test(routingKey)) {
|
|
88
|
-
pendingFormats.splice(i, 1);
|
|
89
|
-
return {isError: true, message: pendingFormat};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
83
|
+
this._decorate(message.content);
|
|
84
|
+
this._debug(`format ${message.fields.routingKey} message content with formatter ${routingKey}`);
|
|
92
85
|
|
|
93
|
-
|
|
86
|
+
if (executeMessage && asyncFormatting && !pending.length) {
|
|
87
|
+
this._complete(message);
|
|
88
|
+
}
|
|
94
89
|
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
Formatter.prototype._complete = function complete(message, isError) {
|
|
94
|
+
const {runMessage, formatKey, callback, formatted, executeMessage} = this[kExecution];
|
|
95
|
+
this[kExecution] = null;
|
|
96
|
+
if (executeMessage) executeMessage.ack();
|
|
97
|
+
|
|
98
|
+
this.broker.cancel(message.fields.consumerTag);
|
|
99
|
+
|
|
100
|
+
if (isError) {
|
|
101
|
+
const error = (message.content && message.content.error) || new Error('formatting failed');
|
|
102
|
+
const errMessage = error.message || 'formatting failed';
|
|
103
|
+
this._debug(`formatting of ${formatKey} failed with ${message.fields.routingKey}: ${errMessage}`);
|
|
104
|
+
return callback(new ActivityError(errMessage, cloneMessage(runMessage), error));
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return callback(null, runMessage.content, formatted);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
Formatter.prototype._decorate = function decorate(withContent) {
|
|
111
|
+
const content = this[kExecution].runMessage.content;
|
|
112
|
+
for (const key in withContent) {
|
|
113
|
+
switch (key) {
|
|
114
|
+
case 'id':
|
|
115
|
+
case 'type':
|
|
116
|
+
case 'parent':
|
|
117
|
+
case 'attachedTo':
|
|
118
|
+
case 'executionId':
|
|
119
|
+
case 'isSubProcess':
|
|
120
|
+
case 'isMultiInstance':
|
|
121
|
+
case 'inbound':
|
|
122
|
+
case 'outbound':
|
|
123
|
+
case 'endRoutingKey':
|
|
124
|
+
case 'errorRoutingKey':
|
|
125
|
+
break;
|
|
126
|
+
default: {
|
|
127
|
+
content[key] = withContent[key];
|
|
128
|
+
this[kExecution].formatted = true;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
Formatter.prototype._popFormatStart = function popFormattingStart(pending, routingKey) {
|
|
135
|
+
for (let idx = 0; idx < pending.length; idx++) {
|
|
136
|
+
const msg = pending[idx];
|
|
137
|
+
const {endRoutingKey, errorRoutingKey = '#.error'} = msg.content;
|
|
138
|
+
|
|
139
|
+
if (endRoutingKey && getRoutingKeyPattern(endRoutingKey).test(routingKey)) {
|
|
140
|
+
this._debug(`completed formatting ${msg.fields.routingKey} message content with formatter ${routingKey}`);
|
|
141
|
+
pending.splice(idx, 1);
|
|
142
|
+
return {message: msg};
|
|
143
|
+
} else if (getRoutingKeyPattern(errorRoutingKey).test(routingKey)) {
|
|
144
|
+
pending.splice(idx, 1);
|
|
145
|
+
return {isError: true, message: msg};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return {};
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
Formatter.prototype._debug = function debug(msg) {
|
|
153
|
+
this.logger.debug(`<${this.id}> ${msg}`);
|
|
154
|
+
};
|