bpmn-elements 7.0.0 → 8.1.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 +23 -0
- package/dist/src/Context.js +50 -40
- package/dist/src/Environment.js +39 -19
- package/dist/src/MessageFormatter.js +11 -11
- package/dist/src/activity/Activity.js +106 -106
- package/dist/src/activity/ActivityExecution.js +37 -37
- package/dist/src/activity/Message.js +2 -2
- package/dist/src/activity/Signal.js +2 -2
- package/dist/src/definition/Definition.js +50 -50
- package/dist/src/definition/DefinitionExecution.js +114 -125
- package/dist/src/eventDefinitions/CancelEventDefinition.js +16 -16
- package/dist/src/eventDefinitions/CompensateEventDefinition.js +24 -24
- package/dist/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
- package/dist/src/eventDefinitions/ErrorEventDefinition.js +26 -26
- package/dist/src/eventDefinitions/EscalationEventDefinition.js +20 -20
- package/dist/src/eventDefinitions/EventDefinitionExecution.js +14 -14
- package/dist/src/eventDefinitions/LinkEventDefinition.js +15 -15
- package/dist/src/eventDefinitions/MessageEventDefinition.js +23 -23
- package/dist/src/eventDefinitions/SignalEventDefinition.js +24 -24
- package/dist/src/eventDefinitions/TimerEventDefinition.js +76 -53
- package/dist/src/events/BoundaryEvent.js +67 -38
- package/dist/src/events/EndEvent.js +3 -3
- package/dist/src/events/IntermediateCatchEvent.js +3 -3
- package/dist/src/events/IntermediateThrowEvent.js +3 -3
- package/dist/src/events/StartEvent.js +9 -9
- package/dist/src/flows/Association.js +7 -7
- package/dist/src/flows/MessageFlow.js +9 -9
- package/dist/src/flows/SequenceFlow.js +7 -7
- package/dist/src/gateways/EventBasedGateway.js +11 -11
- package/dist/src/io/InputOutputSpecification.js +4 -4
- package/dist/src/io/Properties.js +9 -9
- package/dist/src/process/Process.js +64 -61
- package/dist/src/process/ProcessExecution.js +93 -90
- package/dist/src/tasks/ReceiveTask.js +16 -16
- package/dist/src/tasks/SubProcess.js +16 -18
- package/package.json +15 -16
- package/src/Context.js +48 -40
- package/src/Environment.js +48 -20
- package/src/EventBroker.js +1 -1
- package/src/MessageFormatter.js +11 -11
- package/src/activity/Activity.js +99 -100
- package/src/activity/ActivityExecution.js +35 -35
- package/src/activity/Message.js +1 -1
- package/src/activity/Signal.js +1 -1
- package/src/definition/Definition.js +51 -50
- package/src/definition/DefinitionExecution.js +111 -113
- package/src/eventDefinitions/CancelEventDefinition.js +16 -16
- package/src/eventDefinitions/CompensateEventDefinition.js +25 -24
- package/src/eventDefinitions/ConditionalEventDefinition.js +8 -8
- package/src/eventDefinitions/ErrorEventDefinition.js +26 -26
- package/src/eventDefinitions/EscalationEventDefinition.js +20 -20
- package/src/eventDefinitions/EventDefinitionExecution.js +14 -14
- package/src/eventDefinitions/LinkEventDefinition.js +15 -15
- package/src/eventDefinitions/MessageEventDefinition.js +23 -23
- package/src/eventDefinitions/SignalEventDefinition.js +24 -24
- package/src/eventDefinitions/TimerEventDefinition.js +61 -44
- package/src/events/BoundaryEvent.js +53 -36
- package/src/events/EndEvent.js +3 -3
- package/src/events/IntermediateCatchEvent.js +3 -3
- package/src/events/IntermediateThrowEvent.js +3 -3
- package/src/events/StartEvent.js +9 -9
- package/src/flows/Association.js +7 -7
- package/src/flows/MessageFlow.js +9 -9
- package/src/flows/SequenceFlow.js +7 -7
- package/src/gateways/EventBasedGateway.js +11 -11
- package/src/io/BpmnIO.js +5 -1
- package/src/io/InputOutputSpecification.js +4 -4
- package/src/io/Properties.js +9 -9
- package/src/process/Process.js +62 -58
- package/src/process/ProcessExecution.js +86 -88
- package/src/tasks/ReceiveTask.js +16 -16
- package/src/tasks/SubProcess.js +16 -16
|
@@ -14,8 +14,8 @@ var _messageHelper = require("../messageHelper");
|
|
|
14
14
|
|
|
15
15
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
16
|
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const kExecutions = Symbol.for('executions');
|
|
18
|
+
const kMessageHandlers = Symbol.for('messageHandlers');
|
|
19
19
|
|
|
20
20
|
function SubProcess(activityDef, context) {
|
|
21
21
|
const triggeredByEvent = activityDef.behaviour && activityDef.behaviour.triggeredByEvent;
|
|
@@ -62,8 +62,8 @@ function SubProcessBehaviour(activity, context) {
|
|
|
62
62
|
this.environment = activity.environment;
|
|
63
63
|
this.broker = activity.broker;
|
|
64
64
|
this.executionId = undefined;
|
|
65
|
-
this[
|
|
66
|
-
this[
|
|
65
|
+
this[kExecutions] = [];
|
|
66
|
+
this[kMessageHandlers] = {
|
|
67
67
|
onApiRootMessage: this._onApiRootMessage.bind(this),
|
|
68
68
|
onExecutionCompleted: this._onExecutionCompleted.bind(this)
|
|
69
69
|
};
|
|
@@ -72,13 +72,13 @@ function SubProcessBehaviour(activity, context) {
|
|
|
72
72
|
const proto = SubProcessBehaviour.prototype;
|
|
73
73
|
Object.defineProperty(proto, 'execution', {
|
|
74
74
|
get() {
|
|
75
|
-
return this[
|
|
75
|
+
return this[kExecutions][0];
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
});
|
|
79
79
|
Object.defineProperty(proto, 'executions', {
|
|
80
80
|
get() {
|
|
81
|
-
return this[
|
|
81
|
+
return this[kExecutions].slice();
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
});
|
|
@@ -94,7 +94,7 @@ proto.execute = function execute(executeMessage) {
|
|
|
94
94
|
const loopCharacteristics = this.loopCharacteristics;
|
|
95
95
|
|
|
96
96
|
if (loopCharacteristics && content.isRootScope) {
|
|
97
|
-
this.broker.subscribeTmp('api', `activity.#.${executionId}`, this[
|
|
97
|
+
this.broker.subscribeTmp('api', `activity.#.${executionId}`, this[kMessageHandlers].onApiRootMessage, {
|
|
98
98
|
noAck: true,
|
|
99
99
|
consumerTag: `_api-${executionId}`,
|
|
100
100
|
priority: 200
|
|
@@ -109,7 +109,7 @@ proto.execute = function execute(executeMessage) {
|
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
proto.stop = function stop() {
|
|
112
|
-
for (const execution of this[
|
|
112
|
+
for (const execution of this[kExecutions]) {
|
|
113
113
|
this.broker.cancel(`_sub-process-execution-${execution.executionId}`);
|
|
114
114
|
this.broker.cancel(`_sub-process-api-${execution.executionId}`);
|
|
115
115
|
execution.stop();
|
|
@@ -117,7 +117,7 @@ proto.stop = function stop() {
|
|
|
117
117
|
};
|
|
118
118
|
|
|
119
119
|
proto.discard = function discard() {
|
|
120
|
-
for (const execution of this[
|
|
120
|
+
for (const execution of this[kExecutions]) {
|
|
121
121
|
this.broker.cancel(`_sub-process-execution-${execution.executionId}`);
|
|
122
122
|
this.broker.cancel(`_sub-process-api-${execution.executionId}`);
|
|
123
123
|
execution.discard();
|
|
@@ -127,7 +127,7 @@ proto.discard = function discard() {
|
|
|
127
127
|
proto.getState = function getState() {
|
|
128
128
|
if (this.loopCharacteristics) {
|
|
129
129
|
return {
|
|
130
|
-
executions: this[
|
|
130
|
+
executions: this[kExecutions].map(pe => {
|
|
131
131
|
const state = pe.getState();
|
|
132
132
|
state.environment = pe.environment.getState();
|
|
133
133
|
return state;
|
|
@@ -146,7 +146,7 @@ proto.getState = function getState() {
|
|
|
146
146
|
|
|
147
147
|
proto.recover = function recover(state) {
|
|
148
148
|
if (!state) return;
|
|
149
|
-
const executions = this[
|
|
149
|
+
const executions = this[kExecutions];
|
|
150
150
|
const loopCharacteristics = this.loopCharacteristics;
|
|
151
151
|
|
|
152
152
|
if (loopCharacteristics && state.executions) {
|
|
@@ -171,7 +171,7 @@ proto.recover = function recover(state) {
|
|
|
171
171
|
};
|
|
172
172
|
|
|
173
173
|
proto.getPostponed = function getPostponed() {
|
|
174
|
-
return this[
|
|
174
|
+
return this[kExecutions].reduce((result, pe) => {
|
|
175
175
|
result = result.concat(pe.getPostponed());
|
|
176
176
|
return result;
|
|
177
177
|
}, []);
|
|
@@ -204,12 +204,10 @@ proto._upsertExecution = function upsertExecution(executeMessage) {
|
|
|
204
204
|
return execution;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
const subEnvironment = this.environment.clone(
|
|
208
|
-
output: {}
|
|
209
|
-
});
|
|
207
|
+
const subEnvironment = this.environment.clone();
|
|
210
208
|
const subContext = this.context.clone(subEnvironment);
|
|
211
209
|
execution = new _ProcessExecution.default(this.activity, subContext);
|
|
212
|
-
this[
|
|
210
|
+
this[kExecutions].push(execution);
|
|
213
211
|
|
|
214
212
|
this._addListeners(execution, executionId);
|
|
215
213
|
|
|
@@ -217,7 +215,7 @@ proto._upsertExecution = function upsertExecution(executeMessage) {
|
|
|
217
215
|
};
|
|
218
216
|
|
|
219
217
|
proto._addListeners = function addListeners(processExecution, executionId) {
|
|
220
|
-
this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[
|
|
218
|
+
this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kMessageHandlers].onExecutionCompleted, {
|
|
221
219
|
noAck: true,
|
|
222
220
|
consumerTag: `_sub-process-execution-${executionId}`
|
|
223
221
|
});
|
|
@@ -278,5 +276,5 @@ proto.getApi = function getApi(apiMessage) {
|
|
|
278
276
|
};
|
|
279
277
|
|
|
280
278
|
proto._getExecutionById = function getExecutionById(executionId) {
|
|
281
|
-
return this[
|
|
279
|
+
return this[kExecutions].find(pe => pe.executionId === executionId);
|
|
282
280
|
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bpmn-elements",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.1.0",
|
|
4
4
|
"description": "Executable workflow elements based on BPMN 2.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "index.js",
|
|
7
|
+
"sideEffects": false,
|
|
7
8
|
"scripts": {
|
|
8
9
|
"test": "mocha -R dot",
|
|
9
10
|
"posttest": "npm run dist && eslint . --cache",
|
|
@@ -11,9 +12,7 @@
|
|
|
11
12
|
"cov:html": "nyc mocha -R dot && nyc report --reporter=html",
|
|
12
13
|
"test:lcov": "nyc mocha -R dot && nyc report --reporter lcov && npm run posttest",
|
|
13
14
|
"dist": "babel index.js -d dist && babel src -d dist/src",
|
|
14
|
-
"predist": "node -e \"fs.rmdirSync('./dist/src', {recursive: true});\""
|
|
15
|
-
"test-md": "node scripts/test-markdown ./API.md && node scripts/test-markdown ./docs/Examples.md",
|
|
16
|
-
"toc": "node scripts/generate-api-toc ./API.md,./docs/Examples.md,./docs/Form.md"
|
|
15
|
+
"predist": "node -e \"fs.rmdirSync('./dist/src', {recursive: true});\""
|
|
17
16
|
},
|
|
18
17
|
"repository": {
|
|
19
18
|
"type": "git",
|
|
@@ -46,26 +45,26 @@
|
|
|
46
45
|
"index.js"
|
|
47
46
|
],
|
|
48
47
|
"devDependencies": {
|
|
49
|
-
"@aircall/expression-parser": "^1.0.
|
|
50
|
-
"@babel/cli": "^7.
|
|
51
|
-
"@babel/core": "^7.
|
|
52
|
-
"@babel/preset-env": "^7.
|
|
53
|
-
"@babel/register": "^7.
|
|
48
|
+
"@aircall/expression-parser": "^1.0.4",
|
|
49
|
+
"@babel/cli": "^7.18.6",
|
|
50
|
+
"@babel/core": "^7.18.6",
|
|
51
|
+
"@babel/preset-env": "^7.18.6",
|
|
52
|
+
"@babel/register": "^7.18.6",
|
|
54
53
|
"bpmn-moddle": "^7.1.2",
|
|
55
|
-
"camunda-bpmn-moddle": "^6.1.
|
|
54
|
+
"camunda-bpmn-moddle": "^6.1.2",
|
|
56
55
|
"chai": "^4.3.6",
|
|
57
56
|
"chronokinesis": "^3.0.0",
|
|
58
|
-
"debug": "^4.3.
|
|
57
|
+
"debug": "^4.3.4",
|
|
59
58
|
"eslint": "^7.32.0",
|
|
60
|
-
"got": "^11.8.
|
|
61
|
-
"mocha": "^9.2.
|
|
59
|
+
"got": "^11.8.5",
|
|
60
|
+
"mocha": "^9.2.2",
|
|
62
61
|
"mocha-cakes-2": "^3.3.0",
|
|
63
|
-
"moddle-context-serializer": "^2.
|
|
64
|
-
"nock": "^13.2.
|
|
62
|
+
"moddle-context-serializer": "^2.1.0",
|
|
63
|
+
"nock": "^13.2.8",
|
|
65
64
|
"nyc": "^15.1.0"
|
|
66
65
|
},
|
|
67
66
|
"dependencies": {
|
|
68
|
-
"iso8601-duration": "^1.
|
|
67
|
+
"iso8601-duration": "^2.1.1",
|
|
69
68
|
"smqp": "^6.0.0"
|
|
70
69
|
}
|
|
71
70
|
}
|
package/src/Context.js
CHANGED
|
@@ -30,7 +30,9 @@ function ContextInstance(definitionContext, environment) {
|
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
ContextInstance.prototype
|
|
33
|
+
const proto = ContextInstance.prototype;
|
|
34
|
+
|
|
35
|
+
proto.getActivityById = function getActivityById(activityId) {
|
|
34
36
|
const activityInstance = this.refs.activityRefs[activityId];
|
|
35
37
|
if (activityInstance) return activityInstance;
|
|
36
38
|
const activity = this.definitionContext.getActivityById(activityId);
|
|
@@ -38,7 +40,7 @@ ContextInstance.prototype.getActivityById = function getActivityById(activityId)
|
|
|
38
40
|
return this.upsertActivity(activity);
|
|
39
41
|
};
|
|
40
42
|
|
|
41
|
-
|
|
43
|
+
proto.upsertActivity = function upsertActivity(activityDef) {
|
|
42
44
|
let activityInstance = this.refs.activityRefs[activityDef.id];
|
|
43
45
|
if (activityInstance) return activityInstance;
|
|
44
46
|
|
|
@@ -47,7 +49,7 @@ ContextInstance.prototype.upsertActivity = function upsertActivity(activityDef)
|
|
|
47
49
|
return activityInstance;
|
|
48
50
|
};
|
|
49
51
|
|
|
50
|
-
|
|
52
|
+
proto.getSequenceFlowById = function getSequenceFlowById(sequenceFlowId) {
|
|
51
53
|
const flowInstance = this.refs.sequenceFlowRefs[sequenceFlowId];
|
|
52
54
|
if (flowInstance) return flowInstance;
|
|
53
55
|
|
|
@@ -56,31 +58,31 @@ ContextInstance.prototype.getSequenceFlowById = function getSequenceFlowById(seq
|
|
|
56
58
|
return this.upsertSequenceFlow(flowDef);
|
|
57
59
|
};
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
proto.getInboundSequenceFlows = function getInboundSequenceFlows(activityId) {
|
|
60
62
|
return (this.definitionContext.getInboundSequenceFlows(activityId) || []).map((flow) => this.upsertSequenceFlow(flow));
|
|
61
63
|
};
|
|
62
64
|
|
|
63
|
-
|
|
65
|
+
proto.getOutboundSequenceFlows = function getOutboundSequenceFlows(activityId) {
|
|
64
66
|
return (this.definitionContext.getOutboundSequenceFlows(activityId) || []).map((flow) => this.upsertSequenceFlow(flow));
|
|
65
67
|
};
|
|
66
68
|
|
|
67
|
-
|
|
69
|
+
proto.getInboundAssociations = function getInboundAssociations(activityId) {
|
|
68
70
|
return (this.definitionContext.getInboundAssociations(activityId) || []).map((association) => this.upsertAssociation(association));
|
|
69
71
|
};
|
|
70
72
|
|
|
71
|
-
|
|
73
|
+
proto.getOutboundAssociations = function getOutboundAssociations(activityId) {
|
|
72
74
|
return (this.definitionContext.getOutboundAssociations(activityId) || []).map((association) => this.upsertAssociation(association));
|
|
73
75
|
};
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
proto.getActivities = function getActivities(scopeId) {
|
|
76
78
|
return (this.definitionContext.getActivities(scopeId) || []).map((activityDef) => this.upsertActivity(activityDef));
|
|
77
79
|
};
|
|
78
80
|
|
|
79
|
-
|
|
81
|
+
proto.getSequenceFlows = function getSequenceFlows(scopeId) {
|
|
80
82
|
return (this.definitionContext.getSequenceFlows(scopeId) || []).map((flow) => this.upsertSequenceFlow(flow));
|
|
81
83
|
};
|
|
82
84
|
|
|
83
|
-
|
|
85
|
+
proto.upsertSequenceFlow = function upsertSequenceFlow(flowDefinition) {
|
|
84
86
|
const refs = this.refs.sequenceFlowRefs;
|
|
85
87
|
let flowInstance = refs[flowDefinition.id];
|
|
86
88
|
if (flowInstance) return flowInstance;
|
|
@@ -91,11 +93,11 @@ ContextInstance.prototype.upsertSequenceFlow = function upsertSequenceFlow(flowD
|
|
|
91
93
|
return flowInstance;
|
|
92
94
|
};
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
proto.getAssociations = function getAssociations(scopeId) {
|
|
95
97
|
return (this.definitionContext.getAssociations(scopeId) || []).map((association) => this.upsertAssociation(association));
|
|
96
98
|
};
|
|
97
99
|
|
|
98
|
-
|
|
100
|
+
proto.upsertAssociation = function upsertAssociation(associationDefinition) {
|
|
99
101
|
const refs = this.refs.associationRefs;
|
|
100
102
|
let instance = refs[associationDefinition.id];
|
|
101
103
|
if (instance) return instance;
|
|
@@ -105,40 +107,41 @@ ContextInstance.prototype.upsertAssociation = function upsertAssociation(associa
|
|
|
105
107
|
return instance;
|
|
106
108
|
};
|
|
107
109
|
|
|
108
|
-
|
|
110
|
+
proto.clone = function clone(newEnvironment) {
|
|
109
111
|
return new ContextInstance(this.definitionContext, newEnvironment || this.environment);
|
|
110
112
|
};
|
|
111
113
|
|
|
112
|
-
|
|
114
|
+
proto.getProcessById = function getProcessById(processId) {
|
|
113
115
|
const refs = this.refs.processRefs;
|
|
114
|
-
let
|
|
115
|
-
if (
|
|
116
|
+
let bp = this.refs.processRefs[processId];
|
|
117
|
+
if (bp) return bp;
|
|
116
118
|
|
|
117
119
|
const processDefinition = this.definitionContext.getProcessById(processId);
|
|
118
120
|
if (!processDefinition) return null;
|
|
119
121
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
const bpContext = this.clone(this.environment.clone());
|
|
123
|
+
bp = refs[processId] = new processDefinition.Behaviour(processDefinition, bpContext);
|
|
124
|
+
this.refs.processes.push(bp);
|
|
122
125
|
|
|
123
|
-
return
|
|
126
|
+
return bp;
|
|
124
127
|
};
|
|
125
128
|
|
|
126
|
-
|
|
129
|
+
proto.getNewProcessById = function getNewProcessById(processId) {
|
|
127
130
|
if (!this.getProcessById(processId)) return null;
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
return
|
|
131
|
+
const bpDef = this.definitionContext.getProcessById(processId);
|
|
132
|
+
const bp = new bpDef.Behaviour(bpDef, this.clone(this.environment.clone()));
|
|
133
|
+
return bp;
|
|
131
134
|
};
|
|
132
135
|
|
|
133
|
-
|
|
136
|
+
proto.getProcesses = function getProcesses() {
|
|
134
137
|
return this.definitionContext.getProcesses().map(({id: processId}) => this.getProcessById(processId));
|
|
135
138
|
};
|
|
136
139
|
|
|
137
|
-
|
|
140
|
+
proto.getExecutableProcesses = function getExecutableProcesses() {
|
|
138
141
|
return this.definitionContext.getExecutableProcesses().map(({id: processId}) => this.getProcessById(processId));
|
|
139
142
|
};
|
|
140
143
|
|
|
141
|
-
|
|
144
|
+
proto.getMessageFlows = function getMessageFlows(sourceId) {
|
|
142
145
|
if (!this.refs.messageFlows.length) {
|
|
143
146
|
const flows = this.definitionContext.getMessageFlows() || [];
|
|
144
147
|
this.refs.messageFlows.push(...flows.map((flow) => new flow.Behaviour(flow, this)));
|
|
@@ -147,7 +150,7 @@ ContextInstance.prototype.getMessageFlows = function getMessageFlows(sourceId) {
|
|
|
147
150
|
return this.refs.messageFlows.filter((flow) => flow.source.processId === sourceId);
|
|
148
151
|
};
|
|
149
152
|
|
|
150
|
-
|
|
153
|
+
proto.getDataObjectById = function getDataObjectById(referenceId) {
|
|
151
154
|
let dataObject;
|
|
152
155
|
if ((dataObject = this.refs.dataObjectRefs[referenceId])) return dataObject;
|
|
153
156
|
|
|
@@ -159,7 +162,7 @@ ContextInstance.prototype.getDataObjectById = function getDataObjectById(referen
|
|
|
159
162
|
return dataObject;
|
|
160
163
|
};
|
|
161
164
|
|
|
162
|
-
|
|
165
|
+
proto.getDataStoreById = function getDataStoreById(referenceId) {
|
|
163
166
|
let dataStore;
|
|
164
167
|
if ((dataStore = this.refs.dataStoreRefs[referenceId])) return dataStore;
|
|
165
168
|
|
|
@@ -171,23 +174,28 @@ ContextInstance.prototype.getDataStoreById = function getDataStoreById(reference
|
|
|
171
174
|
return dataStore;
|
|
172
175
|
};
|
|
173
176
|
|
|
174
|
-
|
|
177
|
+
proto.getStartActivities = function getStartActivities(filterOptions, scopeId) {
|
|
175
178
|
const {referenceId, referenceType = 'unknown'} = filterOptions || {};
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
179
|
+
const result = [];
|
|
180
|
+
for (const activity of this.getActivities()) {
|
|
181
|
+
if (!activity.isStart) continue;
|
|
182
|
+
if (scopeId && activity.parent.id !== scopeId) continue;
|
|
183
|
+
if (!filterOptions) {
|
|
184
|
+
result.push(activity);
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (!activity.behaviour.eventDefinitions && !activity.behaviour.eventDefinitions) continue;
|
|
189
|
+
|
|
190
|
+
const ref = activity.eventDefinitions.some((ed) => {
|
|
185
191
|
return ed.reference && ed.reference.id === referenceId && ed.reference.referenceType === referenceType;
|
|
186
192
|
});
|
|
187
|
-
|
|
193
|
+
if (ref) result.push(activity);
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
188
196
|
};
|
|
189
197
|
|
|
190
|
-
|
|
198
|
+
proto.loadExtensions = function loadExtensions(activity) {
|
|
191
199
|
return this.extensionsMapper.get(activity);
|
|
192
200
|
};
|
|
193
201
|
|
package/src/Environment.js
CHANGED
|
@@ -2,24 +2,33 @@ import Expressions from './Expressions';
|
|
|
2
2
|
import {Scripts as IScripts} from './Scripts';
|
|
3
3
|
import {Timers} from './Timers';
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const defaultOptions = [
|
|
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
|
+
];
|
|
9
19
|
|
|
10
20
|
export default function Environment(options = {}) {
|
|
11
|
-
this[optionsSymbol] = options;
|
|
12
21
|
this.options = validateOptions(options);
|
|
13
22
|
|
|
14
23
|
this.expressions = options.expressions || Expressions();
|
|
15
24
|
this.extensions = options.extensions;
|
|
16
25
|
this.output = options.output || {};
|
|
17
26
|
this.scripts = options.scripts || IScripts();
|
|
18
|
-
this.services = options.services || {};
|
|
19
|
-
this.settings = {...options.settings};
|
|
20
27
|
this.timers = options.timers || Timers();
|
|
28
|
+
this.settings = {...options.settings};
|
|
21
29
|
this.Logger = options.Logger || DummyLogger;
|
|
22
|
-
this[
|
|
30
|
+
this[kServices] = options.services || {};
|
|
31
|
+
this[kVariables] = options.variables || {};
|
|
23
32
|
}
|
|
24
33
|
|
|
25
34
|
const proto = Environment.prototype;
|
|
@@ -27,14 +36,28 @@ const proto = Environment.prototype;
|
|
|
27
36
|
Object.defineProperty(proto, 'variables', {
|
|
28
37
|
enumerable: true,
|
|
29
38
|
get() {
|
|
30
|
-
return this[
|
|
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);
|
|
31
54
|
},
|
|
32
55
|
});
|
|
33
56
|
|
|
34
57
|
proto.getState = function getState() {
|
|
35
58
|
return {
|
|
36
59
|
settings: {...this.settings},
|
|
37
|
-
variables: {...this
|
|
60
|
+
variables: {...this[kVariables]},
|
|
38
61
|
output: {...this.output},
|
|
39
62
|
};
|
|
40
63
|
};
|
|
@@ -42,22 +65,18 @@ proto.getState = function getState() {
|
|
|
42
65
|
proto.recover = function recover(state) {
|
|
43
66
|
if (!state) return this;
|
|
44
67
|
|
|
45
|
-
const recoverOptions = validateOptions(state);
|
|
46
|
-
Object.assign(this[optionsSymbol], recoverOptions);
|
|
47
|
-
|
|
48
68
|
if (state.settings) Object.assign(this.settings, state.settings);
|
|
49
|
-
if (state.variables) Object.assign(this[
|
|
69
|
+
if (state.variables) Object.assign(this[kVariables], state.variables);
|
|
50
70
|
if (state.output) Object.assign(this.output, state.output);
|
|
51
71
|
|
|
52
72
|
return this;
|
|
53
73
|
};
|
|
54
74
|
|
|
55
75
|
proto.clone = function clone(overrideOptions = {}) {
|
|
56
|
-
const services = this
|
|
76
|
+
const services = this[kServices];
|
|
57
77
|
const newOptions = {
|
|
58
78
|
settings: {...this.settings},
|
|
59
|
-
variables: {...this
|
|
60
|
-
output: {...this.output},
|
|
79
|
+
variables: {...this[kVariables]},
|
|
61
80
|
Logger: this.Logger,
|
|
62
81
|
extensions: this.extensions,
|
|
63
82
|
scripts: this.scripts,
|
|
@@ -76,12 +95,21 @@ proto.clone = function clone(overrideOptions = {}) {
|
|
|
76
95
|
proto.assignVariables = function assignVariables(newVars) {
|
|
77
96
|
if (!newVars || typeof newVars !== 'object') return;
|
|
78
97
|
|
|
79
|
-
this[
|
|
98
|
+
this[kVariables] = {
|
|
80
99
|
...this.variables,
|
|
81
100
|
...newVars,
|
|
82
101
|
};
|
|
83
102
|
};
|
|
84
103
|
|
|
104
|
+
proto.assignSettings = function assignVariables(newSettings) {
|
|
105
|
+
if (!newSettings || typeof newSettings !== 'object') return;
|
|
106
|
+
|
|
107
|
+
this.settings = {
|
|
108
|
+
...this.settings,
|
|
109
|
+
...newSettings,
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
|
|
85
113
|
proto.getScript = function getScript(...args) {
|
|
86
114
|
return this.scripts.getScript(...args);
|
|
87
115
|
};
|
|
@@ -91,7 +119,7 @@ proto.registerScript = function registerScript(...args) {
|
|
|
91
119
|
};
|
|
92
120
|
|
|
93
121
|
proto.getServiceByName = function getServiceByName(serviceName) {
|
|
94
|
-
return this
|
|
122
|
+
return this[kServices][serviceName];
|
|
95
123
|
};
|
|
96
124
|
|
|
97
125
|
proto.resolveExpression = function resolveExpression(expression, message = {}, expressionFnContext) {
|
|
@@ -104,7 +132,7 @@ proto.resolveExpression = function resolveExpression(expression, message = {}, e
|
|
|
104
132
|
};
|
|
105
133
|
|
|
106
134
|
proto.addService = function addService(name, fn) {
|
|
107
|
-
this
|
|
135
|
+
this[kServices][name] = fn;
|
|
108
136
|
};
|
|
109
137
|
|
|
110
138
|
function validateOptions(input) {
|
package/src/EventBroker.js
CHANGED
|
@@ -90,7 +90,7 @@ EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
|
|
|
90
90
|
return new Promise((resolve, reject) => {
|
|
91
91
|
const consumers = [
|
|
92
92
|
this.broker.subscribeTmp('event', key, eventCallback, {noAck: true}),
|
|
93
|
-
this.broker.subscribeTmp('event', '*.error', errorCallback, {noAck: true})
|
|
93
|
+
this.broker.subscribeTmp('event', '*.error', errorCallback, {noAck: true}),
|
|
94
94
|
];
|
|
95
95
|
|
|
96
96
|
function eventCallback(routingKey, message, owner) {
|
package/src/MessageFormatter.js
CHANGED
|
@@ -3,8 +3,8 @@ import {getUniqueId} from './shared';
|
|
|
3
3
|
import {ActivityError} from './error/Errors';
|
|
4
4
|
import {getRoutingKeyPattern} from 'smqp';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const kOnMessage = Symbol.for('onMessage');
|
|
7
|
+
const kExecution = Symbol.for('execution');
|
|
8
8
|
|
|
9
9
|
export {Formatter};
|
|
10
10
|
|
|
@@ -17,7 +17,7 @@ function Formatter(element, formatQ) {
|
|
|
17
17
|
|
|
18
18
|
this.pendingFormats = [];
|
|
19
19
|
|
|
20
|
-
this[
|
|
20
|
+
this[kOnMessage] = this._onMessage.bind(this);
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
Formatter.prototype.format = function format(message, callback) {
|
|
@@ -32,7 +32,7 @@ Formatter.prototype.format = function format(message, callback) {
|
|
|
32
32
|
persistent: false,
|
|
33
33
|
});
|
|
34
34
|
|
|
35
|
-
this[
|
|
35
|
+
this[kExecution] = {
|
|
36
36
|
correlationId,
|
|
37
37
|
formatKey: message.fields.routingKey,
|
|
38
38
|
runMessage: cloneMessage(message),
|
|
@@ -42,14 +42,14 @@ Formatter.prototype.format = function format(message, callback) {
|
|
|
42
42
|
executeMessage: null,
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
formatQ.consume(this[
|
|
45
|
+
formatQ.consume(this[kOnMessage], {
|
|
46
46
|
consumerTag,
|
|
47
47
|
prefetch: 100,
|
|
48
48
|
});
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
Formatter.prototype._onMessage = function onMessage(routingKey, message) {
|
|
52
|
-
const {formatKey, correlationId, pending, executeMessage} = this[
|
|
52
|
+
const {formatKey, correlationId, pending, executeMessage} = this[kExecution];
|
|
53
53
|
const asyncFormatting = pending.length;
|
|
54
54
|
|
|
55
55
|
switch (routingKey) {
|
|
@@ -59,7 +59,7 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
|
|
|
59
59
|
message.ack();
|
|
60
60
|
return this._complete(message);
|
|
61
61
|
}
|
|
62
|
-
this[
|
|
62
|
+
this[kExecution].executeMessage = message;
|
|
63
63
|
break;
|
|
64
64
|
default: {
|
|
65
65
|
message.ack();
|
|
@@ -91,8 +91,8 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
Formatter.prototype._complete = function complete(message, isError) {
|
|
94
|
-
const {runMessage, formatKey, callback, formatted, executeMessage} = this[
|
|
95
|
-
this[
|
|
94
|
+
const {runMessage, formatKey, callback, formatted, executeMessage} = this[kExecution];
|
|
95
|
+
this[kExecution] = null;
|
|
96
96
|
if (executeMessage) executeMessage.ack();
|
|
97
97
|
|
|
98
98
|
this.broker.cancel(message.fields.consumerTag);
|
|
@@ -108,7 +108,7 @@ Formatter.prototype._complete = function complete(message, isError) {
|
|
|
108
108
|
};
|
|
109
109
|
|
|
110
110
|
Formatter.prototype._decorate = function decorate(withContent) {
|
|
111
|
-
const content = this[
|
|
111
|
+
const content = this[kExecution].runMessage.content;
|
|
112
112
|
for (const key in withContent) {
|
|
113
113
|
switch (key) {
|
|
114
114
|
case 'id':
|
|
@@ -125,7 +125,7 @@ Formatter.prototype._decorate = function decorate(withContent) {
|
|
|
125
125
|
break;
|
|
126
126
|
default: {
|
|
127
127
|
content[key] = withContent[key];
|
|
128
|
-
this[
|
|
128
|
+
this[kExecution].formatted = true;
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|