bpmn-elements 14.1.0 → 15.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 +0 -4
- package/dist/Context.js +41 -35
- package/dist/Environment.js +4 -4
- package/dist/Expressions.js +1 -1
- package/dist/MessageFormatter.js +0 -1
- package/dist/Scripts.js +3 -8
- package/dist/Timers.js +5 -9
- package/dist/Tracker.js +15 -19
- package/dist/activity/Activity.js +68 -49
- package/dist/activity/ActivityExecution.js +43 -29
- package/dist/definition/Definition.js +20 -14
- package/dist/definition/DefinitionExecution.js +64 -55
- package/dist/eventDefinitions/EscalationEventDefinition.js +1 -1
- package/dist/eventDefinitions/LinkEventDefinition.js +1 -1
- package/dist/eventDefinitions/MessageEventDefinition.js +1 -1
- package/dist/eventDefinitions/SignalEventDefinition.js +1 -1
- package/dist/eventDefinitions/TimerEventDefinition.js +1 -1
- package/dist/events/BoundaryEvent.js +11 -9
- package/dist/events/EndEvent.js +1 -1
- package/dist/events/IntermediateCatchEvent.js +1 -1
- package/dist/events/IntermediateThrowEvent.js +1 -1
- package/dist/events/StartEvent.js +1 -1
- package/dist/flows/SequenceFlow.js +1 -1
- package/dist/gateways/EventBasedGateway.js +1 -1
- package/dist/gateways/ExclusiveGateway.js +1 -1
- package/dist/gateways/InclusiveGateway.js +1 -1
- package/dist/gateways/ParallelGateway.js +1 -1
- package/dist/index.js +1 -1
- package/dist/io/InputOutputSpecification.js +1 -1
- package/dist/io/Properties.js +1 -1
- package/dist/process/Process.js +20 -19
- package/dist/process/ProcessExecution.js +67 -40
- package/dist/shared.js +0 -8
- package/dist/tasks/CallActivity.js +1 -1
- package/dist/tasks/LoopCharacteristics.js +2 -2
- package/dist/tasks/ReceiveTask.js +1 -1
- package/dist/tasks/ScriptTask.js +3 -3
- package/dist/tasks/ServiceImplementation.js +1 -1
- package/dist/tasks/ServiceTask.js +1 -1
- package/dist/tasks/SignalTask.js +1 -1
- package/dist/tasks/StandardLoopCharacteristics.js +1 -1
- package/dist/tasks/SubProcess.js +30 -33
- package/dist/tasks/Task.js +1 -1
- package/dist/tasks/Transaction.js +1 -1
- package/package.json +4 -4
- package/src/Context.js +51 -35
- package/src/Environment.js +4 -4
- package/src/MessageFormatter.js +0 -3
- package/src/Scripts.js +3 -8
- package/src/Timers.js +5 -9
- package/src/Tracker.js +13 -17
- package/src/activity/Activity.js +57 -42
- package/src/activity/ActivityExecution.js +43 -26
- package/src/definition/Definition.js +19 -13
- package/src/definition/DefinitionExecution.js +64 -54
- package/src/eventDefinitions/TimerEventDefinition.js +1 -1
- package/src/events/BoundaryEvent.js +10 -8
- package/src/process/Process.js +20 -15
- package/src/process/ProcessExecution.js +70 -40
- package/src/shared.js +0 -8
- package/src/tasks/LoopCharacteristics.js +2 -2
- package/src/tasks/ScriptTask.js +2 -2
- package/src/tasks/SubProcess.js +31 -32
- package/types/types.d.ts +1 -1
package/README.md
CHANGED
|
@@ -76,7 +76,3 @@ The following elements are tested and supported.
|
|
|
76
76
|
- Transaction
|
|
77
77
|
|
|
78
78
|
All activities share the same [base](/docs/Activity.md) and and [api](/docs/SharedApi.md).
|
|
79
|
-
|
|
80
|
-
# Acknowledgments
|
|
81
|
-
|
|
82
|
-
ISO 8601 duration parser [iso8601-duration](https://www.npmjs.com/package/iso8601-duration) source is copied and extended with repeat pattern. License [MIT @ tolu](https://tolu.mit-license.org/)
|
package/dist/Context.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.default = Context;
|
|
|
7
7
|
var _BpmnIO = _interopRequireDefault(require("./io/BpmnIO.js"));
|
|
8
8
|
var _Environment = _interopRequireDefault(require("./Environment.js"));
|
|
9
9
|
var _shared = require("./shared.js");
|
|
10
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
const kOwner = Symbol.for('owner');
|
|
12
12
|
const kActivated = Symbol.for('activated');
|
|
13
13
|
function Context(definitionContext, environment) {
|
|
@@ -28,17 +28,7 @@ function ContextInstance(definitionContext, environment, owner) {
|
|
|
28
28
|
this.definitionContext = definitionContext;
|
|
29
29
|
this.environment = environment;
|
|
30
30
|
this.extensionsMapper = new ExtensionsMapper(this);
|
|
31
|
-
this.refs =
|
|
32
|
-
activityRefs: {},
|
|
33
|
-
associationRefs: [],
|
|
34
|
-
dataObjectRefs: {},
|
|
35
|
-
dataStoreRefs: {},
|
|
36
|
-
messageFlows: [],
|
|
37
|
-
processes: [],
|
|
38
|
-
processRefs: {},
|
|
39
|
-
sequenceFlowRefs: {},
|
|
40
|
-
sequenceFlows: []
|
|
41
|
-
};
|
|
31
|
+
this.refs = new Map([['activityRefs', new Map()], ['sequenceFlowRefs', new Map()], ['processRefs', new Map()], ['messageFlows', new Set()], ['associationRefs', new Map()], ['dataObjectRefs', new Map()], ['dataStoreRefs', new Map()]]);
|
|
42
32
|
this[kOwner] = owner;
|
|
43
33
|
}
|
|
44
34
|
Object.defineProperty(ContextInstance.prototype, 'owner', {
|
|
@@ -47,20 +37,21 @@ Object.defineProperty(ContextInstance.prototype, 'owner', {
|
|
|
47
37
|
}
|
|
48
38
|
});
|
|
49
39
|
ContextInstance.prototype.getActivityById = function getActivityById(activityId) {
|
|
50
|
-
const activityInstance = this.refs.activityRefs
|
|
40
|
+
const activityInstance = this.refs.get('activityRefs').get(activityId);
|
|
51
41
|
if (activityInstance) return activityInstance;
|
|
52
42
|
const activity = this.definitionContext.getActivityById(activityId);
|
|
53
43
|
if (!activity) return null;
|
|
54
44
|
return this.upsertActivity(activity);
|
|
55
45
|
};
|
|
56
46
|
ContextInstance.prototype.upsertActivity = function upsertActivity(activityDef) {
|
|
57
|
-
let activityInstance = this.refs.activityRefs
|
|
47
|
+
let activityInstance = this.refs.get('activityRefs').get(activityDef.id);
|
|
58
48
|
if (activityInstance) return activityInstance;
|
|
59
|
-
activityInstance =
|
|
49
|
+
activityInstance = new activityDef.Behaviour(activityDef, this);
|
|
50
|
+
this.refs.get('activityRefs').set(activityDef.id, activityInstance);
|
|
60
51
|
return activityInstance;
|
|
61
52
|
};
|
|
62
53
|
ContextInstance.prototype.getSequenceFlowById = function getSequenceFlowById(sequenceFlowId) {
|
|
63
|
-
const flowInstance = this.refs.sequenceFlowRefs
|
|
54
|
+
const flowInstance = this.refs.get('sequenceFlowRefs').get(sequenceFlowId);
|
|
64
55
|
if (flowInstance) return flowInstance;
|
|
65
56
|
const flowDef = this.definitionContext.getSequenceFlowById(sequenceFlowId);
|
|
66
57
|
if (!flowDef) return null;
|
|
@@ -85,36 +76,37 @@ ContextInstance.prototype.getSequenceFlows = function getSequenceFlows(scopeId)
|
|
|
85
76
|
return (this.definitionContext.getSequenceFlows(scopeId) || []).map(flow => this.upsertSequenceFlow(flow));
|
|
86
77
|
};
|
|
87
78
|
ContextInstance.prototype.upsertSequenceFlow = function upsertSequenceFlow(flowDefinition) {
|
|
88
|
-
const
|
|
89
|
-
let flowInstance =
|
|
79
|
+
const sequenceFlowRefs = this.refs.get('sequenceFlowRefs');
|
|
80
|
+
let flowInstance = sequenceFlowRefs.get(flowDefinition.id);
|
|
90
81
|
if (flowInstance) return flowInstance;
|
|
91
|
-
flowInstance =
|
|
92
|
-
|
|
82
|
+
flowInstance = new flowDefinition.Behaviour(flowDefinition, this);
|
|
83
|
+
sequenceFlowRefs.set(flowDefinition.id, flowInstance);
|
|
93
84
|
return flowInstance;
|
|
94
85
|
};
|
|
95
86
|
ContextInstance.prototype.getAssociations = function getAssociations(scopeId) {
|
|
96
87
|
return (this.definitionContext.getAssociations(scopeId) || []).map(association => this.upsertAssociation(association));
|
|
97
88
|
};
|
|
98
89
|
ContextInstance.prototype.upsertAssociation = function upsertAssociation(associationDefinition) {
|
|
99
|
-
const
|
|
100
|
-
let instance =
|
|
90
|
+
const associationRefs = this.refs.get('associationRefs');
|
|
91
|
+
let instance = associationRefs.get(associationDefinition.id);
|
|
101
92
|
if (instance) return instance;
|
|
102
|
-
instance =
|
|
93
|
+
instance = new associationDefinition.Behaviour(associationDefinition, this);
|
|
94
|
+
associationRefs.set(associationDefinition.id, instance);
|
|
103
95
|
return instance;
|
|
104
96
|
};
|
|
105
97
|
ContextInstance.prototype.clone = function clone(newEnvironment, newOwner) {
|
|
106
98
|
return new ContextInstance(this.definitionContext, newEnvironment || this.environment, newOwner);
|
|
107
99
|
};
|
|
108
100
|
ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
109
|
-
const
|
|
110
|
-
let bp =
|
|
101
|
+
const processRefs = this.refs.get('processRefs');
|
|
102
|
+
let bp = processRefs.get(processId);
|
|
111
103
|
if (bp) return bp;
|
|
112
104
|
const processDefinition = this.definitionContext.getProcessById(processId);
|
|
113
105
|
if (!processDefinition) return null;
|
|
114
106
|
const bpContext = this.clone(this.environment.clone());
|
|
115
|
-
bp =
|
|
107
|
+
bp = new processDefinition.Behaviour(processDefinition, bpContext);
|
|
108
|
+
processRefs.set(processId, bp);
|
|
116
109
|
bpContext[kOwner] = bp;
|
|
117
|
-
this.refs.processes.push(bp);
|
|
118
110
|
return bp;
|
|
119
111
|
};
|
|
120
112
|
ContextInstance.prototype.getNewProcessById = function getNewProcessById(processId) {
|
|
@@ -136,26 +128,40 @@ ContextInstance.prototype.getExecutableProcesses = function getExecutableProcess
|
|
|
136
128
|
}) => this.getProcessById(processId));
|
|
137
129
|
};
|
|
138
130
|
ContextInstance.prototype.getMessageFlows = function getMessageFlows(sourceId) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
131
|
+
const messageFlowRefs = this.refs.get('messageFlows');
|
|
132
|
+
const result = [];
|
|
133
|
+
if (!messageFlowRefs.size) {
|
|
134
|
+
const msgFlows = this.definitionContext.getMessageFlows() || [];
|
|
135
|
+
for (const msgFlow of msgFlows) {
|
|
136
|
+
const flow = new msgFlow.Behaviour(msgFlow, this);
|
|
137
|
+
messageFlowRefs.add(flow);
|
|
138
|
+
if (flow.source.processId === sourceId) result.push(flow);
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
for (const flow of messageFlowRefs) {
|
|
142
|
+
if (flow.source.processId === sourceId) result.push(flow);
|
|
143
|
+
}
|
|
142
144
|
}
|
|
143
|
-
return
|
|
145
|
+
return result;
|
|
144
146
|
};
|
|
145
147
|
ContextInstance.prototype.getDataObjectById = function getDataObjectById(referenceId) {
|
|
148
|
+
const dataObjectRefs = this.refs.get('dataObjectRefs');
|
|
146
149
|
let dataObject;
|
|
147
|
-
if (dataObject =
|
|
150
|
+
if (dataObject = dataObjectRefs.get(referenceId)) return dataObject;
|
|
148
151
|
const dataObjectDef = this.definitionContext.getDataObjectById(referenceId);
|
|
149
152
|
if (!dataObjectDef) return;
|
|
150
|
-
dataObject =
|
|
153
|
+
dataObject = new dataObjectDef.Behaviour(dataObjectDef, this);
|
|
154
|
+
dataObjectRefs.set(dataObjectDef.id, dataObject);
|
|
151
155
|
return dataObject;
|
|
152
156
|
};
|
|
153
157
|
ContextInstance.prototype.getDataStoreById = function getDataStoreById(referenceId) {
|
|
158
|
+
const dataStoreRefs = this.refs.get('dataStoreRefs');
|
|
154
159
|
let dataStore;
|
|
155
|
-
if (dataStore =
|
|
160
|
+
if (dataStore = dataStoreRefs.get(referenceId)) return dataStore;
|
|
156
161
|
const dataStoreDef = this.definitionContext.getDataStoreById(referenceId) || this.definitionContext.getDataStoreReferenceById(referenceId);
|
|
157
162
|
if (!dataStoreDef) return;
|
|
158
|
-
dataStore =
|
|
163
|
+
dataStore = new dataStoreDef.Behaviour(dataStoreDef, this);
|
|
164
|
+
dataStoreRefs.set(dataStoreDef.id, dataStore);
|
|
159
165
|
return dataStore;
|
|
160
166
|
};
|
|
161
167
|
ContextInstance.prototype.getStartActivities = function getStartActivities(filterOptions, scopeId) {
|
package/dist/Environment.js
CHANGED
|
@@ -7,16 +7,16 @@ exports.default = Environment;
|
|
|
7
7
|
var _Expressions = _interopRequireDefault(require("./Expressions.js"));
|
|
8
8
|
var _Scripts = require("./Scripts.js");
|
|
9
9
|
var _Timers = require("./Timers.js");
|
|
10
|
-
function _interopRequireDefault(
|
|
10
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
const kServices = Symbol.for('services');
|
|
12
12
|
const kVariables = Symbol.for('variables');
|
|
13
|
-
const defaultOptions = ['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables'];
|
|
13
|
+
const defaultOptions = new Set(['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables']);
|
|
14
14
|
function Environment(options = {}) {
|
|
15
15
|
this.options = validateOptions(options);
|
|
16
16
|
this.expressions = options.expressions || (0, _Expressions.default)();
|
|
17
17
|
this.extensions = options.extensions;
|
|
18
18
|
this.output = options.output || {};
|
|
19
|
-
this.scripts = options.scripts ||
|
|
19
|
+
this.scripts = options.scripts || new _Scripts.Scripts();
|
|
20
20
|
this.timers = options.timers || new _Timers.Timers();
|
|
21
21
|
this.settings = {
|
|
22
22
|
...options.settings
|
|
@@ -124,7 +124,7 @@ Environment.prototype.addService = function addService(name, fn) {
|
|
|
124
124
|
function validateOptions(input) {
|
|
125
125
|
const options = {};
|
|
126
126
|
for (const key in input) {
|
|
127
|
-
if (defaultOptions.
|
|
127
|
+
if (!defaultOptions.has(key)) {
|
|
128
128
|
options[key] = input[key];
|
|
129
129
|
}
|
|
130
130
|
}
|
package/dist/Expressions.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = Expressions;
|
|
7
7
|
var _getPropertyValue = _interopRequireDefault(require("./getPropertyValue.js"));
|
|
8
|
-
function _interopRequireDefault(
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
9
|
const isExpressionPattern = /^\${(.+?)}$/;
|
|
10
10
|
const expressionPattern = /\${(.+?)}/;
|
|
11
11
|
function Expressions() {
|
package/dist/MessageFormatter.js
CHANGED
|
@@ -20,7 +20,6 @@ function Formatter(element, formatQ) {
|
|
|
20
20
|
this.broker = broker;
|
|
21
21
|
this.logger = logger;
|
|
22
22
|
this.formatQ = formatQ;
|
|
23
|
-
this.pendingFormats = [];
|
|
24
23
|
this[kOnMessage] = this._onMessage.bind(this);
|
|
25
24
|
}
|
|
26
25
|
Formatter.prototype.format = function format(message, callback) {
|
package/dist/Scripts.js
CHANGED
|
@@ -4,11 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.Scripts = Scripts;
|
|
7
|
-
function Scripts() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
register
|
|
11
|
-
};
|
|
12
|
-
function getScript( /*scriptType, activity*/) {}
|
|
13
|
-
function register( /*activity*/) {}
|
|
14
|
-
}
|
|
7
|
+
function Scripts() {}
|
|
8
|
+
Scripts.prototype.getScript = function getScript( /*scriptType, activity*/) {};
|
|
9
|
+
Scripts.prototype.register = function register( /*activity*/) {};
|
package/dist/Timers.js
CHANGED
|
@@ -14,13 +14,13 @@ function Timers(options) {
|
|
|
14
14
|
clearTimeout,
|
|
15
15
|
...options
|
|
16
16
|
};
|
|
17
|
-
this[kExecuting] =
|
|
17
|
+
this[kExecuting] = new Set();
|
|
18
18
|
this.setTimeout = this.setTimeout.bind(this);
|
|
19
19
|
this.clearTimeout = this.clearTimeout.bind(this);
|
|
20
20
|
}
|
|
21
21
|
Object.defineProperty(Timers.prototype, 'executing', {
|
|
22
22
|
get() {
|
|
23
|
-
return this[kExecuting]
|
|
23
|
+
return [...this[kExecuting]];
|
|
24
24
|
}
|
|
25
25
|
});
|
|
26
26
|
Timers.prototype.register = function register(owner) {
|
|
@@ -30,10 +30,7 @@ Timers.prototype.setTimeout = function wrappedSetTimeout(callback, delay, ...arg
|
|
|
30
30
|
return this._setTimeout(null, callback, delay, ...args);
|
|
31
31
|
};
|
|
32
32
|
Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
|
|
33
|
-
|
|
34
|
-
const idx = executing.indexOf(ref);
|
|
35
|
-
if (idx > -1) {
|
|
36
|
-
executing.splice(idx, 1);
|
|
33
|
+
if (this[kExecuting].delete(ref)) {
|
|
37
34
|
ref.timerRef = this.options.clearTimeout(ref.timerRef);
|
|
38
35
|
return;
|
|
39
36
|
}
|
|
@@ -42,14 +39,13 @@ Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
|
|
|
42
39
|
Timers.prototype._setTimeout = function setTimeout(owner, callback, delay, ...args) {
|
|
43
40
|
const executing = this[kExecuting];
|
|
44
41
|
const ref = this._getReference(owner, callback, delay, args);
|
|
45
|
-
executing.
|
|
42
|
+
executing.add(ref);
|
|
46
43
|
if (delay < MAX_DELAY) {
|
|
47
44
|
ref.timerRef = this.options.setTimeout(onTimeout, ref.delay, ...ref.args);
|
|
48
45
|
}
|
|
49
46
|
return ref;
|
|
50
47
|
function onTimeout(...rargs) {
|
|
51
|
-
|
|
52
|
-
if (idx > -1) executing.splice(idx, 1);
|
|
48
|
+
executing.delete(ref);
|
|
53
49
|
return callback(...rargs);
|
|
54
50
|
}
|
|
55
51
|
};
|
package/dist/Tracker.js
CHANGED
|
@@ -7,17 +7,17 @@ exports.ActivityTracker = ActivityTracker;
|
|
|
7
7
|
function ActivityTracker(parentId) {
|
|
8
8
|
this.id = parentId;
|
|
9
9
|
this.status = {
|
|
10
|
-
wait:
|
|
11
|
-
execute:
|
|
12
|
-
timer:
|
|
10
|
+
wait: new Set(),
|
|
11
|
+
execute: new Set(),
|
|
12
|
+
timer: new Set()
|
|
13
13
|
};
|
|
14
14
|
}
|
|
15
15
|
Object.defineProperty(ActivityTracker.prototype, 'activityStatus', {
|
|
16
16
|
get() {
|
|
17
17
|
const status = this.status;
|
|
18
|
-
if (status.execute.
|
|
19
|
-
if (status.timer.
|
|
20
|
-
return status.wait.
|
|
18
|
+
if (status.execute.size) return 'executing';
|
|
19
|
+
if (status.timer.size) return 'timer';
|
|
20
|
+
return status.wait.size ? 'wait' : 'idle';
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
23
|
ActivityTracker.prototype.track = function track(routingKey, message) {
|
|
@@ -55,27 +55,24 @@ ActivityTracker.prototype._executing = function executing(id) {
|
|
|
55
55
|
wait,
|
|
56
56
|
execute
|
|
57
57
|
} = this.status;
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if ((idx = wait.indexOf(id)) !== -1) wait.splice(idx, 1);
|
|
58
|
+
wait.delete(id);
|
|
59
|
+
execute.add(id);
|
|
61
60
|
};
|
|
62
61
|
ActivityTracker.prototype._waiting = function waiting(id) {
|
|
63
62
|
const {
|
|
64
63
|
wait,
|
|
65
64
|
execute
|
|
66
65
|
} = this.status;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);
|
|
66
|
+
execute.delete(id);
|
|
67
|
+
wait.add(id);
|
|
70
68
|
};
|
|
71
69
|
ActivityTracker.prototype._timer = function timerFn(id) {
|
|
72
70
|
const {
|
|
73
71
|
timer,
|
|
74
72
|
execute
|
|
75
73
|
} = this.status;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);
|
|
74
|
+
execute.delete(id);
|
|
75
|
+
timer.add(id);
|
|
79
76
|
};
|
|
80
77
|
ActivityTracker.prototype._leave = function leave(id) {
|
|
81
78
|
const {
|
|
@@ -83,8 +80,7 @@ ActivityTracker.prototype._leave = function leave(id) {
|
|
|
83
80
|
execute,
|
|
84
81
|
timer
|
|
85
82
|
} = this.status;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
if ((idx = timer.indexOf(id)) !== -1) timer.splice(idx, 1);
|
|
83
|
+
execute.delete(id);
|
|
84
|
+
timer.delete(id);
|
|
85
|
+
wait.delete(id);
|
|
90
86
|
};
|
|
@@ -11,7 +11,7 @@ var _EventBroker = require("../EventBroker.js");
|
|
|
11
11
|
var _MessageFormatter = require("../MessageFormatter.js");
|
|
12
12
|
var _messageHelper = require("../messageHelper.js");
|
|
13
13
|
var _Errors = require("../error/Errors.js");
|
|
14
|
-
function _interopRequireDefault(
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
15
|
const kActivityDef = Symbol.for('activityDefinition');
|
|
16
16
|
const kConsuming = Symbol.for('consuming');
|
|
17
17
|
const kConsumingRunQ = Symbol.for('run queue consumer');
|
|
@@ -87,7 +87,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
87
87
|
const flows = this[kFlows] = {
|
|
88
88
|
inboundSequenceFlows,
|
|
89
89
|
inboundAssociations,
|
|
90
|
-
inboundJoinFlows:
|
|
90
|
+
inboundJoinFlows: new Set(),
|
|
91
91
|
inboundTriggers,
|
|
92
92
|
outboundSequenceFlows,
|
|
93
93
|
outboundEvaluator: new OutboundEvaluator(this, outboundSequenceFlows)
|
|
@@ -105,7 +105,7 @@ function Activity(Behaviour, activityDef, context) {
|
|
|
105
105
|
isThrowing: activityDef.isThrowing,
|
|
106
106
|
lane: activityDef.lane && activityDef.lane.id
|
|
107
107
|
};
|
|
108
|
-
this[kExec] =
|
|
108
|
+
this[kExec] = new Map();
|
|
109
109
|
this[kMessageHandlers] = {
|
|
110
110
|
onInbound: isParallelJoin ? this._onJoinInbound.bind(this) : this._onInbound.bind(this),
|
|
111
111
|
onRunMessage: this._onRunMessage.bind(this),
|
|
@@ -127,12 +127,12 @@ Object.defineProperties(Activity.prototype, {
|
|
|
127
127
|
},
|
|
128
128
|
execution: {
|
|
129
129
|
get() {
|
|
130
|
-
return this[kExec].execution;
|
|
130
|
+
return this[kExec].get('execution');
|
|
131
131
|
}
|
|
132
132
|
},
|
|
133
133
|
executionId: {
|
|
134
134
|
get() {
|
|
135
|
-
return this[kExec].executionId;
|
|
135
|
+
return this[kExec].get('executionId');
|
|
136
136
|
}
|
|
137
137
|
},
|
|
138
138
|
extensions: {
|
|
@@ -257,7 +257,8 @@ Activity.prototype.deactivate = function deactivate() {
|
|
|
257
257
|
Activity.prototype.init = function init(initContent) {
|
|
258
258
|
const id = this.id;
|
|
259
259
|
const exec = this[kExec];
|
|
260
|
-
const executionId = exec.initExecutionId
|
|
260
|
+
const executionId = exec.has('initExecutionId') ? exec.get('initExecutionId') : (0, _shared.getUniqueId)(id);
|
|
261
|
+
exec.set('initExecutionId', executionId);
|
|
261
262
|
this.logger.debug(`<${id}> initialized with executionId <${executionId}>`);
|
|
262
263
|
this._publishEvent('init', this._createMessage({
|
|
263
264
|
...initContent,
|
|
@@ -268,8 +269,9 @@ Activity.prototype.run = function run(runContent) {
|
|
|
268
269
|
const id = this.id;
|
|
269
270
|
if (this.isRunning) throw new Error(`activity <${id}> is already running`);
|
|
270
271
|
const exec = this[kExec];
|
|
271
|
-
const executionId = exec.
|
|
272
|
-
exec.
|
|
272
|
+
const executionId = exec.get('initExecutionId') || (0, _shared.getUniqueId)(id);
|
|
273
|
+
exec.set('executionId', executionId);
|
|
274
|
+
exec.delete('initExecutionId');
|
|
273
275
|
this._consumeApi();
|
|
274
276
|
const content = this._createMessage({
|
|
275
277
|
...runContent,
|
|
@@ -284,6 +286,8 @@ Activity.prototype.run = function run(runContent) {
|
|
|
284
286
|
Activity.prototype.getState = function getState() {
|
|
285
287
|
const status = this.status;
|
|
286
288
|
const exec = this[kExec];
|
|
289
|
+
const execution = exec.get('execution');
|
|
290
|
+
const executionId = exec.get('executionId');
|
|
287
291
|
const brokerState = this.broker.getState(true);
|
|
288
292
|
if (!brokerState && this.environment.settings.disableTrackState) return;
|
|
289
293
|
return {
|
|
@@ -292,11 +296,13 @@ Activity.prototype.getState = function getState() {
|
|
|
292
296
|
...(status && {
|
|
293
297
|
status
|
|
294
298
|
}),
|
|
295
|
-
executionId
|
|
299
|
+
executionId,
|
|
296
300
|
stopped: this.stopped,
|
|
297
301
|
counters: this.counters,
|
|
298
302
|
broker: brokerState,
|
|
299
|
-
execution
|
|
303
|
+
...(execution && {
|
|
304
|
+
execution: execution.getState()
|
|
305
|
+
})
|
|
300
306
|
};
|
|
301
307
|
};
|
|
302
308
|
Activity.prototype.recover = function recover(state) {
|
|
@@ -305,13 +311,13 @@ Activity.prototype.recover = function recover(state) {
|
|
|
305
311
|
this.stopped = state.stopped;
|
|
306
312
|
this.status = state.status;
|
|
307
313
|
const exec = this[kExec];
|
|
308
|
-
exec.executionId
|
|
314
|
+
exec.set('executionId', state.executionId);
|
|
309
315
|
this[kCounters] = {
|
|
310
316
|
...this[kCounters],
|
|
311
317
|
...state.counters
|
|
312
318
|
};
|
|
313
319
|
if (state.execution) {
|
|
314
|
-
exec.execution
|
|
320
|
+
exec.set('execution', new _ActivityExecution.default(this, this.context).recover(state.execution));
|
|
315
321
|
}
|
|
316
322
|
this.broker.recover(state.broker);
|
|
317
323
|
return this;
|
|
@@ -332,7 +338,7 @@ Activity.prototype.resume = function resume() {
|
|
|
332
338
|
};
|
|
333
339
|
Activity.prototype.discard = function discard(discardContent) {
|
|
334
340
|
if (!this.status) return this._runDiscard(discardContent);
|
|
335
|
-
const execution = this[kExec].execution;
|
|
341
|
+
const execution = this[kExec].get('execution');
|
|
336
342
|
if (execution && !execution.completed) return execution.discard();
|
|
337
343
|
this._deactivateRunConsumers();
|
|
338
344
|
const broker = this.broker;
|
|
@@ -345,16 +351,22 @@ Activity.prototype.addInboundListeners = function addInboundListeners() {
|
|
|
345
351
|
const onInboundEvent = this._onInboundEvent.bind(this);
|
|
346
352
|
const triggerConsumerTag = `_inbound-${this.id}`;
|
|
347
353
|
for (const trigger of this[kFlows].inboundTriggers) {
|
|
348
|
-
if (trigger.isSequenceFlow)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
354
|
+
if (trigger.isSequenceFlow) {
|
|
355
|
+
trigger.broker.subscribeTmp('event', 'flow.#', onInboundEvent, {
|
|
356
|
+
noAck: true,
|
|
357
|
+
consumerTag: triggerConsumerTag
|
|
358
|
+
});
|
|
359
|
+
} else if (this.isForCompensation) {
|
|
360
|
+
trigger.broker.subscribeTmp('event', 'association.#', onInboundEvent, {
|
|
361
|
+
noAck: true,
|
|
362
|
+
consumerTag: triggerConsumerTag
|
|
363
|
+
});
|
|
364
|
+
} else {
|
|
365
|
+
trigger.broker.subscribeTmp('event', 'activity.#', onInboundEvent, {
|
|
366
|
+
noAck: true,
|
|
367
|
+
consumerTag: triggerConsumerTag
|
|
368
|
+
});
|
|
369
|
+
}
|
|
358
370
|
}
|
|
359
371
|
};
|
|
360
372
|
Activity.prototype.removeInboundListeners = function removeInboundListeners() {
|
|
@@ -386,7 +398,7 @@ Activity.prototype.evaluateOutbound = function evaluateOutbound(fromMessage, dis
|
|
|
386
398
|
return this[kFlows].outboundEvaluator.evaluate(fromMessage, discardRestAtTake, callback);
|
|
387
399
|
};
|
|
388
400
|
Activity.prototype.getApi = function getApi(message) {
|
|
389
|
-
const execution = this[kExec].execution;
|
|
401
|
+
const execution = this[kExec].get('execution');
|
|
390
402
|
if (execution && !execution.completed) return execution.getApi(message);
|
|
391
403
|
return (0, _Api.ActivityApi)(this.broker, message || this[kStateMessage]);
|
|
392
404
|
};
|
|
@@ -395,8 +407,9 @@ Activity.prototype.getActivityById = function getActivityById(elementId) {
|
|
|
395
407
|
};
|
|
396
408
|
Activity.prototype._runDiscard = function runDiscard(discardContent) {
|
|
397
409
|
const exec = this[kExec];
|
|
398
|
-
const executionId = exec.
|
|
399
|
-
exec.
|
|
410
|
+
const executionId = exec.get('initExecutionId') || (0, _shared.getUniqueId)(this.id);
|
|
411
|
+
exec.set('executionId', executionId);
|
|
412
|
+
exec.delete('initExecutionId');
|
|
400
413
|
this._consumeApi();
|
|
401
414
|
const content = this._createMessage({
|
|
402
415
|
...discardContent,
|
|
@@ -409,7 +422,7 @@ Activity.prototype._runDiscard = function runDiscard(discardContent) {
|
|
|
409
422
|
Activity.prototype._discardRun = function discardRun() {
|
|
410
423
|
const status = this.status;
|
|
411
424
|
if (!status) return;
|
|
412
|
-
const execution = this[kExec].execution;
|
|
425
|
+
const execution = this[kExec].get('execution');
|
|
413
426
|
if (execution && !execution.completed) return;
|
|
414
427
|
switch (status) {
|
|
415
428
|
case 'end':
|
|
@@ -494,39 +507,45 @@ Activity.prototype._onJoinInbound = function onJoinInbound(routingKey, message)
|
|
|
494
507
|
content
|
|
495
508
|
} = message;
|
|
496
509
|
const {
|
|
497
|
-
inboundSequenceFlows,
|
|
498
510
|
inboundJoinFlows,
|
|
499
511
|
inboundTriggers
|
|
500
512
|
} = this[kFlows];
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
|
|
513
|
+
let alreadyTouched = false;
|
|
514
|
+
const touched = new Set();
|
|
515
|
+
let taken;
|
|
516
|
+
for (const msg of inboundJoinFlows) {
|
|
517
|
+
const flowId = msg.content.id;
|
|
518
|
+
touched.add(flowId);
|
|
519
|
+
if (flowId === content.id) {
|
|
520
|
+
alreadyTouched = true;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
inboundJoinFlows.add(message);
|
|
524
|
+
if (alreadyTouched) return;
|
|
525
|
+
const remaining = inboundTriggers.length - touched.size - 1;
|
|
526
|
+
if (remaining) {
|
|
507
527
|
return this.logger.debug(`<${this.id}> inbound ${message.content.action} from <${message.content.id}>, ${remaining} remaining`);
|
|
508
528
|
}
|
|
509
|
-
const
|
|
510
|
-
|
|
511
|
-
const inbound = evaluatedInbound.map(im => {
|
|
529
|
+
const inbound = [];
|
|
530
|
+
for (const im of inboundJoinFlows) {
|
|
512
531
|
if (im.fields.routingKey === 'flow.take') taken = true;
|
|
513
532
|
im.ack();
|
|
514
|
-
|
|
515
|
-
}
|
|
516
|
-
|
|
533
|
+
inbound.push((0, _messageHelper.cloneContent)(im.content));
|
|
534
|
+
}
|
|
535
|
+
const discardSequence = new Set();
|
|
517
536
|
if (!taken) {
|
|
518
|
-
|
|
519
|
-
for (const im of evaluatedInbound) {
|
|
537
|
+
for (const im of inboundJoinFlows) {
|
|
520
538
|
if (!im.content.discardSequence) continue;
|
|
521
539
|
for (const sourceId of im.content.discardSequence) {
|
|
522
|
-
|
|
540
|
+
discardSequence.add(sourceId);
|
|
523
541
|
}
|
|
524
542
|
}
|
|
525
543
|
}
|
|
544
|
+
inboundJoinFlows.clear();
|
|
526
545
|
this.broker.cancel('_run-on-inbound');
|
|
527
546
|
if (!taken) return this._runDiscard({
|
|
528
547
|
inbound,
|
|
529
|
-
discardSequence
|
|
548
|
+
discardSequence: [...discardSequence]
|
|
530
549
|
});
|
|
531
550
|
return this.run({
|
|
532
551
|
inbound
|
|
@@ -603,7 +622,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
603
622
|
this.logger.debug(`<${id}> enter`, isRedelivered ? 'redelivered' : '');
|
|
604
623
|
this.status = 'entered';
|
|
605
624
|
if (!isRedelivered) {
|
|
606
|
-
this[kExec].execution
|
|
625
|
+
this[kExec].delete('execution');
|
|
607
626
|
if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
|
|
608
627
|
this._publishEvent('enter', content, {
|
|
609
628
|
correlationId
|
|
@@ -615,7 +634,7 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
615
634
|
{
|
|
616
635
|
this.logger.debug(`<${id}> discard`, isRedelivered ? 'redelivered' : '');
|
|
617
636
|
this.status = 'discard';
|
|
618
|
-
this[kExec].execution
|
|
637
|
+
this[kExec].delete('execution');
|
|
619
638
|
if (this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
|
|
620
639
|
if (!isRedelivered) {
|
|
621
640
|
this.broker.publish('run', 'run.discarded', content, {
|
|
@@ -654,12 +673,12 @@ Activity.prototype._continueRunMessage = function continueRunMessage(routingKey,
|
|
|
654
673
|
this[kExecuteMessage] = message;
|
|
655
674
|
const exec = this[kExec];
|
|
656
675
|
if (isRedelivered && this.extensions) this.extensions.activate((0, _messageHelper.cloneMessage)(message));
|
|
657
|
-
if (!exec.execution) exec.execution
|
|
676
|
+
if (!exec.has('execution')) exec.set('execution', new _ActivityExecution.default(this, this.context));
|
|
658
677
|
this.broker.getQueue('execution-q').assertConsumer(this[kMessageHandlers].onExecutionMessage, {
|
|
659
678
|
exclusive: true,
|
|
660
679
|
consumerTag: '_activity-execution'
|
|
661
680
|
});
|
|
662
|
-
return exec.execution.execute(message);
|
|
681
|
+
return exec.get('execution').execute(message);
|
|
663
682
|
}
|
|
664
683
|
case 'run.end':
|
|
665
684
|
{
|
|
@@ -914,7 +933,7 @@ Activity.prototype._onStop = function onStop(message) {
|
|
|
914
933
|
}
|
|
915
934
|
};
|
|
916
935
|
Activity.prototype._consumeApi = function consumeApi() {
|
|
917
|
-
const executionId = this[kExec].executionId;
|
|
936
|
+
const executionId = this[kExec].get('executionId');
|
|
918
937
|
if (!executionId) return;
|
|
919
938
|
const broker = this.broker;
|
|
920
939
|
broker.cancel('_activity-api');
|