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/README.md
CHANGED
|
@@ -30,6 +30,7 @@ The following elements are tested and supported.
|
|
|
30
30
|
- ErrorEventDefinition
|
|
31
31
|
- throw
|
|
32
32
|
- catch
|
|
33
|
+
- [Escalation](/docs/MessageElements.md)
|
|
33
34
|
- EscalationEventDefinition
|
|
34
35
|
- throw
|
|
35
36
|
- catch
|
|
@@ -42,6 +43,7 @@ The following elements are tested and supported.
|
|
|
42
43
|
- LinkEventDefinition
|
|
43
44
|
- throw
|
|
44
45
|
- catch
|
|
46
|
+
- [Message](/docs/MessageElements.md)
|
|
45
47
|
- MessageEventDefinition
|
|
46
48
|
- throw
|
|
47
49
|
- catch
|
|
@@ -58,7 +60,7 @@ The following elements are tested and supported.
|
|
|
58
60
|
- [ServiceTask](/docs/ServiceTask.md)
|
|
59
61
|
- BusinessRuleTask: Same behaviour as ServiceTask
|
|
60
62
|
- SendTask: Same behaviour as ServiceTask
|
|
61
|
-
- Signal
|
|
63
|
+
- [Signal](/docs/MessageElements.md)
|
|
62
64
|
- SignalEventDefinition
|
|
63
65
|
- throw
|
|
64
66
|
- catch
|
package/dist/Api.js
CHANGED
|
@@ -10,18 +10,54 @@ exports.FlowApi = FlowApi;
|
|
|
10
10
|
exports.ProcessApi = ProcessApi;
|
|
11
11
|
var _messageHelper = require("./messageHelper.js");
|
|
12
12
|
var _shared = require("./shared.js");
|
|
13
|
+
/**
|
|
14
|
+
* Build an activity-scoped Api wrapper. Routing keys are published under `activity.*`.
|
|
15
|
+
* @param {any} broker
|
|
16
|
+
* @param {import('#types').ElementBrokerMessage} apiMessage
|
|
17
|
+
* @param {import('#types').Environment} [environment]
|
|
18
|
+
*/
|
|
13
19
|
function ActivityApi(broker, apiMessage, environment) {
|
|
14
20
|
return new Api('activity', broker, apiMessage, environment);
|
|
15
21
|
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Build a definition-scoped Api wrapper. Routing keys are published under `definition.*`.
|
|
25
|
+
* @param {any} broker
|
|
26
|
+
* @param {import('#types').ElementBrokerMessage} apiMessage
|
|
27
|
+
* @param {import('#types').Environment} [environment]
|
|
28
|
+
*/
|
|
16
29
|
function DefinitionApi(broker, apiMessage, environment) {
|
|
17
30
|
return new Api('definition', broker, apiMessage, environment);
|
|
18
31
|
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Build a process-scoped Api wrapper. Routing keys are published under `process.*`.
|
|
35
|
+
* @param {any} broker
|
|
36
|
+
* @param {import('#types').ElementBrokerMessage} apiMessage
|
|
37
|
+
* @param {import('#types').Environment} [environment]
|
|
38
|
+
*/
|
|
19
39
|
function ProcessApi(broker, apiMessage, environment) {
|
|
20
40
|
return new Api('process', broker, apiMessage, environment);
|
|
21
41
|
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Build a flow-scoped Api wrapper. Routing keys are published under `flow.*`.
|
|
45
|
+
* @param {any} broker
|
|
46
|
+
* @param {import('#types').ElementBrokerMessage} apiMessage
|
|
47
|
+
* @param {import('#types').Environment} [environment]
|
|
48
|
+
*/
|
|
22
49
|
function FlowApi(broker, apiMessage, environment) {
|
|
23
50
|
return new Api('flow', broker, apiMessage, environment);
|
|
24
51
|
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Lightweight wrapper over the broker that exposes signal/cancel/fail/stop and other api actions.
|
|
55
|
+
* @param {string} pfx Message prefix, e.g. `activity`, `process`, `definition`, `flow`
|
|
56
|
+
* @param {any} broker
|
|
57
|
+
* @param {import('#types').ElementBrokerMessage} sourceMessage Cloned to back the api
|
|
58
|
+
* @param {import('#types').Environment} [environment] Defaults to `broker.owner.environment`
|
|
59
|
+
* @throws {Error} when sourceMessage is missing
|
|
60
|
+
*/
|
|
25
61
|
function Api(pfx, broker, sourceMessage, environment) {
|
|
26
62
|
if (!sourceMessage) throw new Error('Api requires message');
|
|
27
63
|
const apiMessage = (0, _messageHelper.cloneMessage)(sourceMessage);
|
|
@@ -43,27 +79,57 @@ function Api(pfx, broker, sourceMessage, environment) {
|
|
|
43
79
|
this.owner = broker.owner;
|
|
44
80
|
this.messagePrefix = pfx;
|
|
45
81
|
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Send a cancel api message.
|
|
85
|
+
* @param {import('#types').signalMessage} [message]
|
|
86
|
+
* @param {any} [options]
|
|
87
|
+
*/
|
|
46
88
|
Api.prototype.cancel = function cancel(message, options) {
|
|
47
89
|
this.sendApiMessage('cancel', {
|
|
48
90
|
message
|
|
49
91
|
}, options);
|
|
50
92
|
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Send a discard api message.
|
|
96
|
+
*/
|
|
51
97
|
Api.prototype.discard = function discard() {
|
|
52
98
|
this.sendApiMessage('discard');
|
|
53
99
|
};
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Send an error api message that fails the activity.
|
|
103
|
+
* @param {Error} error
|
|
104
|
+
*/
|
|
54
105
|
Api.prototype.fail = function fail(error) {
|
|
55
106
|
this.sendApiMessage('error', {
|
|
56
107
|
error
|
|
57
108
|
});
|
|
58
109
|
};
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Send a signal api message.
|
|
113
|
+
* @param {import('#types').signalMessage} [message]
|
|
114
|
+
* @param {any} [options]
|
|
115
|
+
*/
|
|
59
116
|
Api.prototype.signal = function signal(message, options) {
|
|
60
117
|
this.sendApiMessage('signal', {
|
|
61
118
|
message
|
|
62
119
|
}, options);
|
|
63
120
|
};
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Send a stop api message.
|
|
124
|
+
*/
|
|
64
125
|
Api.prototype.stop = function stop() {
|
|
65
126
|
this.sendApiMessage('stop');
|
|
66
127
|
};
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Resolve an expression with the api message as scope and the broker owner as context.
|
|
131
|
+
* @param {string} expression
|
|
132
|
+
*/
|
|
67
133
|
Api.prototype.resolveExpression = function resolveExpression(expression) {
|
|
68
134
|
return this.environment.resolveExpression(expression, {
|
|
69
135
|
fields: this.fields,
|
|
@@ -71,6 +137,13 @@ Api.prototype.resolveExpression = function resolveExpression(expression) {
|
|
|
71
137
|
properties: this.messageProperties
|
|
72
138
|
}, this.owner);
|
|
73
139
|
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Publish a custom api message to the broker.
|
|
143
|
+
* @param {string} action Routing key suffix, e.g. `signal`, `cancel`
|
|
144
|
+
* @param {import('#types').signalMessage} [content] Merged into the message content
|
|
145
|
+
* @param {any} [options]
|
|
146
|
+
*/
|
|
74
147
|
Api.prototype.sendApiMessage = function sendApiMessage(action, content, options) {
|
|
75
148
|
const correlationId = options?.correlationId || (0, _shared.getUniqueId)(`${this.id || this.messagePrefix}_signal`);
|
|
76
149
|
let key = `${this.messagePrefix}.${action}`;
|
|
@@ -81,11 +154,21 @@ Api.prototype.sendApiMessage = function sendApiMessage(action, content, options)
|
|
|
81
154
|
type: action
|
|
82
155
|
});
|
|
83
156
|
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* List currently postponed activities, falling back to a sub-process execution when applicable.
|
|
160
|
+
* @param {import('#types').filterPostponed} [filterFn]
|
|
161
|
+
*/
|
|
84
162
|
Api.prototype.getPostponed = function getPostponed(...args) {
|
|
85
163
|
if (this.owner.getPostponed) return this.owner.getPostponed(...args);
|
|
86
164
|
if (this.owner.isSubProcess && this.owner.execution) return this.owner.execution.getPostponed(...args);
|
|
87
165
|
return [];
|
|
88
166
|
};
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Build a message body by merging the given content onto the source content.
|
|
170
|
+
* @param {Record<string, any>} [content]
|
|
171
|
+
*/
|
|
89
172
|
Api.prototype.createMessage = function createMessage(content) {
|
|
90
173
|
return {
|
|
91
174
|
...this.content,
|
package/dist/Context.js
CHANGED
|
@@ -3,39 +3,64 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
var
|
|
6
|
+
exports.Context = Context;
|
|
7
|
+
exports.ContextInstance = ContextInstance;
|
|
8
|
+
var _BpmnIO = require("./io/BpmnIO.js");
|
|
9
|
+
var _Environment = require("./Environment.js");
|
|
9
10
|
var _shared = require("./shared.js");
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
11
|
+
var _constants = require("./constants.js");
|
|
12
|
+
const K_OWNER = Symbol.for('owner');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Build a runtime Context from a parsed BPMN definition.
|
|
16
|
+
* @param {import('moddle-context-serializer').SerializableContext} definitionContext
|
|
17
|
+
* @param {import('#types').Environment} [environment] Existing environment to clone; a fresh one is created when omitted
|
|
18
|
+
*/
|
|
13
19
|
function Context(definitionContext, environment) {
|
|
14
|
-
environment = environment ? environment.clone() : new _Environment.
|
|
20
|
+
environment = environment ? environment.clone() : new _Environment.Environment();
|
|
15
21
|
return new ContextInstance(definitionContext, environment);
|
|
16
22
|
}
|
|
17
|
-
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Per-execution registry that lazily upserts activities, flows, and processes from the parsed BPMN definition.
|
|
26
|
+
* @param {import('moddle-context-serializer').SerializableContext} definitionContext
|
|
27
|
+
* @param {import('#types').Environment} environment
|
|
28
|
+
* @param {import('#types').Process | import('#types').Activity} [owner] Process or sub-process activity that owns this context
|
|
29
|
+
* @param {Map<string, any>} [peersCache] Shared converging parallel gateway peer cache; created at the root and propagated to every clone
|
|
30
|
+
*/
|
|
31
|
+
function ContextInstance(definitionContext, environment, owner, peersCache) {
|
|
18
32
|
const {
|
|
19
33
|
id = 'Def',
|
|
20
34
|
name,
|
|
21
35
|
type = 'context'
|
|
22
36
|
} = definitionContext;
|
|
23
|
-
const sid = (0, _shared.getUniqueId)(id);
|
|
24
37
|
this.id = id;
|
|
25
38
|
this.name = name;
|
|
26
39
|
this.type = type;
|
|
27
|
-
|
|
40
|
+
/** Unique instance id */
|
|
41
|
+
this.sid = (0, _shared.getUniqueId)(id);
|
|
28
42
|
this.definitionContext = definitionContext;
|
|
29
43
|
this.environment = environment;
|
|
44
|
+
/** Discovered parallel gateway peers, keyed by gateway id, shared with all clones. Runtime-only, not serialized. */
|
|
45
|
+
this.peersCache = peersCache || new Map();
|
|
46
|
+
/** @type {import('#types').IExtensionsMapper} */
|
|
30
47
|
this.extensionsMapper = new ExtensionsMapper(this);
|
|
48
|
+
/** @private */
|
|
31
49
|
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()]]);
|
|
32
|
-
this[
|
|
50
|
+
this[K_OWNER] = owner;
|
|
33
51
|
}
|
|
34
52
|
Object.defineProperty(ContextInstance.prototype, 'owner', {
|
|
53
|
+
/** @returns {import('#types').Process | import('#types').Activity | undefined} Process or sub-process activity that owns this context */
|
|
35
54
|
get() {
|
|
36
|
-
return this[
|
|
55
|
+
return this[K_OWNER];
|
|
37
56
|
}
|
|
38
57
|
});
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get or create the activity instance for the given id.
|
|
61
|
+
* @param {string} activityId
|
|
62
|
+
* @returns {import('./activity/Activity.js').Activity | null}
|
|
63
|
+
*/
|
|
39
64
|
ContextInstance.prototype.getActivityById = function getActivityById(activityId) {
|
|
40
65
|
const activityInstance = this.refs.get('activityRefs').get(activityId);
|
|
41
66
|
if (activityInstance) return activityInstance;
|
|
@@ -43,6 +68,12 @@ ContextInstance.prototype.getActivityById = function getActivityById(activityId)
|
|
|
43
68
|
if (!activity) return null;
|
|
44
69
|
return this.upsertActivity(activity);
|
|
45
70
|
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Return the cached activity instance, instantiating it the first time it is referenced.
|
|
74
|
+
* @param {import('moddle-context-serializer').SerializableElement} activityDef
|
|
75
|
+
* @returns {import('./activity/Activity.js').Activity}
|
|
76
|
+
*/
|
|
46
77
|
ContextInstance.prototype.upsertActivity = function upsertActivity(activityDef) {
|
|
47
78
|
let activityInstance = this.refs.get('activityRefs').get(activityDef.id);
|
|
48
79
|
if (activityInstance) return activityInstance;
|
|
@@ -50,6 +81,12 @@ ContextInstance.prototype.upsertActivity = function upsertActivity(activityDef)
|
|
|
50
81
|
this.refs.get('activityRefs').set(activityDef.id, activityInstance);
|
|
51
82
|
return activityInstance;
|
|
52
83
|
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Get or create the sequence flow instance for the given id.
|
|
87
|
+
* @param {string} sequenceFlowId
|
|
88
|
+
* @returns {import('./flows/SequenceFlow.js').SequenceFlow | null}
|
|
89
|
+
*/
|
|
53
90
|
ContextInstance.prototype.getSequenceFlowById = function getSequenceFlowById(sequenceFlowId) {
|
|
54
91
|
const flowInstance = this.refs.get('sequenceFlowRefs').get(sequenceFlowId);
|
|
55
92
|
if (flowInstance) return flowInstance;
|
|
@@ -57,24 +94,56 @@ ContextInstance.prototype.getSequenceFlowById = function getSequenceFlowById(seq
|
|
|
57
94
|
if (!flowDef) return null;
|
|
58
95
|
return this.upsertSequenceFlow(flowDef);
|
|
59
96
|
};
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {string} activityId
|
|
100
|
+
*/
|
|
60
101
|
ContextInstance.prototype.getInboundSequenceFlows = function getInboundSequenceFlows(activityId) {
|
|
61
102
|
return (this.definitionContext.getInboundSequenceFlows(activityId) || []).map(flow => this.upsertSequenceFlow(flow));
|
|
62
103
|
};
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @param {string} activityId
|
|
107
|
+
*/
|
|
63
108
|
ContextInstance.prototype.getOutboundSequenceFlows = function getOutboundSequenceFlows(activityId) {
|
|
64
109
|
return (this.definitionContext.getOutboundSequenceFlows(activityId) || []).map(flow => this.upsertSequenceFlow(flow));
|
|
65
110
|
};
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @param {string} activityId
|
|
114
|
+
*/
|
|
66
115
|
ContextInstance.prototype.getInboundAssociations = function getInboundAssociations(activityId) {
|
|
67
116
|
return (this.definitionContext.getInboundAssociations(activityId) || []).map(association => this.upsertAssociation(association));
|
|
68
117
|
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {string} activityId
|
|
121
|
+
*/
|
|
69
122
|
ContextInstance.prototype.getOutboundAssociations = function getOutboundAssociations(activityId) {
|
|
70
123
|
return (this.definitionContext.getOutboundAssociations(activityId) || []).map(association => this.upsertAssociation(association));
|
|
71
124
|
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Get every activity in the definition, optionally narrowed to a parent scope.
|
|
128
|
+
* @param {string} [scopeId] Process or sub-process id
|
|
129
|
+
*/
|
|
72
130
|
ContextInstance.prototype.getActivities = function getActivities(scopeId) {
|
|
73
131
|
return (this.definitionContext.getActivities(scopeId) || []).map(activityDef => this.upsertActivity(activityDef));
|
|
74
132
|
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get every sequence flow in the definition, optionally narrowed to a parent scope.
|
|
136
|
+
* @param {string} [scopeId] Process or sub-process id
|
|
137
|
+
*/
|
|
75
138
|
ContextInstance.prototype.getSequenceFlows = function getSequenceFlows(scopeId) {
|
|
76
139
|
return (this.definitionContext.getSequenceFlows(scopeId) || []).map(flow => this.upsertSequenceFlow(flow));
|
|
77
140
|
};
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Return the cached sequence flow, instantiating it the first time it is referenced.
|
|
144
|
+
* @param {import('moddle-context-serializer').SerializableElement} flowDefinition
|
|
145
|
+
* @returns {import('./flows/SequenceFlow.js').SequenceFlow}
|
|
146
|
+
*/
|
|
78
147
|
ContextInstance.prototype.upsertSequenceFlow = function upsertSequenceFlow(flowDefinition) {
|
|
79
148
|
const sequenceFlowRefs = this.refs.get('sequenceFlowRefs');
|
|
80
149
|
let flowInstance = sequenceFlowRefs.get(flowDefinition.id);
|
|
@@ -83,9 +152,19 @@ ContextInstance.prototype.upsertSequenceFlow = function upsertSequenceFlow(flowD
|
|
|
83
152
|
sequenceFlowRefs.set(flowDefinition.id, flowInstance);
|
|
84
153
|
return flowInstance;
|
|
85
154
|
};
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get association flows
|
|
158
|
+
* @param {string} [scopeId] Process or sub-process id
|
|
159
|
+
*/
|
|
86
160
|
ContextInstance.prototype.getAssociations = function getAssociations(scopeId) {
|
|
87
161
|
return (this.definitionContext.getAssociations(scopeId) || []).map(association => this.upsertAssociation(association));
|
|
88
162
|
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* @param {import('moddle-context-serializer').SerializableElement} associationDefinition
|
|
166
|
+
* @returns {import('./flows/Association.js').Association}
|
|
167
|
+
*/
|
|
89
168
|
ContextInstance.prototype.upsertAssociation = function upsertAssociation(associationDefinition) {
|
|
90
169
|
const associationRefs = this.refs.get('associationRefs');
|
|
91
170
|
let instance = associationRefs.get(associationDefinition.id);
|
|
@@ -94,9 +173,39 @@ ContextInstance.prototype.upsertAssociation = function upsertAssociation(associa
|
|
|
94
173
|
associationRefs.set(associationDefinition.id, instance);
|
|
95
174
|
return instance;
|
|
96
175
|
};
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Create a new context that shares the parsed definition but optionally swaps environment and owner.
|
|
179
|
+
* @param {import('#types').Environment} [newEnvironment]
|
|
180
|
+
* @param {import('#types').Process | import('#types').Activity} [newOwner]
|
|
181
|
+
*/
|
|
97
182
|
ContextInstance.prototype.clone = function clone(newEnvironment, newOwner) {
|
|
98
|
-
return new ContextInstance(this.definitionContext, newEnvironment || this.environment, newOwner);
|
|
183
|
+
return new ContextInstance(this.definitionContext, newEnvironment || this.environment, newOwner, this.peersCache);
|
|
99
184
|
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Cached converging parallel gateway peers discovered by an earlier shake.
|
|
188
|
+
* @param {string} gatewayId
|
|
189
|
+
* @returns {Array<[string, string[]]> | undefined}
|
|
190
|
+
*/
|
|
191
|
+
ContextInstance.prototype.getShakenPeers = function getShakenPeers(gatewayId) {
|
|
192
|
+
return this.peersCache.get(gatewayId);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Store converging parallel gateway peers so subsequent runs can skip the graph shake.
|
|
197
|
+
* @param {string} gatewayId
|
|
198
|
+
* @param {Array<[string, string[]]>} peers
|
|
199
|
+
*/
|
|
200
|
+
ContextInstance.prototype.setShakenPeers = function setShakenPeers(gatewayId, peers) {
|
|
201
|
+
this.peersCache.set(gatewayId, peers);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Get or create the process instance for the given id. Each process gets its own cloned environment.
|
|
206
|
+
* @param {string} processId
|
|
207
|
+
* @returns {import('#types').Process | null}
|
|
208
|
+
*/
|
|
100
209
|
ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
101
210
|
const processRefs = this.refs.get('processRefs');
|
|
102
211
|
let bp = processRefs.get(processId);
|
|
@@ -106,27 +215,49 @@ ContextInstance.prototype.getProcessById = function getProcessById(processId) {
|
|
|
106
215
|
const bpContext = this.clone(this.environment.clone());
|
|
107
216
|
bp = new processDefinition.Behaviour(processDefinition, bpContext);
|
|
108
217
|
processRefs.set(processId, bp);
|
|
109
|
-
bpContext[
|
|
218
|
+
bpContext[K_OWNER] = bp;
|
|
110
219
|
return bp;
|
|
111
220
|
};
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Build a fresh, uncached process instance for the given id. Used by call activities.
|
|
224
|
+
* @param {string} processId
|
|
225
|
+
* @returns {import('#types').Process | null}
|
|
226
|
+
*/
|
|
112
227
|
ContextInstance.prototype.getNewProcessById = function getNewProcessById(processId) {
|
|
113
228
|
if (!this.getProcessById(processId)) return null;
|
|
114
229
|
const bpDef = this.definitionContext.getProcessById(processId);
|
|
115
230
|
const bpContext = this.clone(this.environment.clone());
|
|
116
231
|
const bp = new bpDef.Behaviour(bpDef, bpContext);
|
|
117
|
-
bpContext[
|
|
232
|
+
bpContext[K_OWNER] = bp;
|
|
118
233
|
return bp;
|
|
119
234
|
};
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Get every process in the definition.
|
|
238
|
+
* @returns {import('#types').Process[]}
|
|
239
|
+
*/
|
|
120
240
|
ContextInstance.prototype.getProcesses = function getProcesses() {
|
|
121
241
|
return this.definitionContext.getProcesses().map(({
|
|
122
242
|
id: processId
|
|
123
243
|
}) => this.getProcessById(processId));
|
|
124
244
|
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Get processes flagged executable in the definition.
|
|
248
|
+
* @returns {import('#types').Process[]}
|
|
249
|
+
*/
|
|
125
250
|
ContextInstance.prototype.getExecutableProcesses = function getExecutableProcesses() {
|
|
126
251
|
return this.definitionContext.getExecutableProcesses().map(({
|
|
127
252
|
id: processId
|
|
128
253
|
}) => this.getProcessById(processId));
|
|
129
254
|
};
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Get message flows that originate from the given process id.
|
|
258
|
+
* @param {string} sourceId Source process id
|
|
259
|
+
* @returns {import('./flows/MessageFlow.js').MessageFlow[]}
|
|
260
|
+
*/
|
|
130
261
|
ContextInstance.prototype.getMessageFlows = function getMessageFlows(sourceId) {
|
|
131
262
|
const messageFlowRefs = this.refs.get('messageFlows');
|
|
132
263
|
const result = [];
|
|
@@ -144,6 +275,12 @@ ContextInstance.prototype.getMessageFlows = function getMessageFlows(sourceId) {
|
|
|
144
275
|
}
|
|
145
276
|
return result;
|
|
146
277
|
};
|
|
278
|
+
|
|
279
|
+
/**
|
|
280
|
+
* Get or create a data object instance for the given reference id.
|
|
281
|
+
* @param {string} referenceId
|
|
282
|
+
* @return {import('#types').IIOData | undefined}
|
|
283
|
+
*/
|
|
147
284
|
ContextInstance.prototype.getDataObjectById = function getDataObjectById(referenceId) {
|
|
148
285
|
const dataObjectRefs = this.refs.get('dataObjectRefs');
|
|
149
286
|
let dataObject;
|
|
@@ -154,6 +291,12 @@ ContextInstance.prototype.getDataObjectById = function getDataObjectById(referen
|
|
|
154
291
|
dataObjectRefs.set(dataObjectDef.id, dataObject);
|
|
155
292
|
return dataObject;
|
|
156
293
|
};
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Get or create a data store instance for the given reference id.
|
|
297
|
+
* @param {string} referenceId
|
|
298
|
+
* @return {import('#types').IIOData | undefined}
|
|
299
|
+
*/
|
|
157
300
|
ContextInstance.prototype.getDataStoreById = function getDataStoreById(referenceId) {
|
|
158
301
|
const dataStoreRefs = this.refs.get('dataStoreRefs');
|
|
159
302
|
let dataStore;
|
|
@@ -164,6 +307,12 @@ ContextInstance.prototype.getDataStoreById = function getDataStoreById(reference
|
|
|
164
307
|
dataStoreRefs.set(dataStoreDef.id, dataStore);
|
|
165
308
|
return dataStore;
|
|
166
309
|
};
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Get start activities, optionally filtered by referenced event definition or restricted to a parent scope.
|
|
313
|
+
* @param {import('#types').startActivityFilterOptions} [filterOptions]
|
|
314
|
+
* @param {string} [scopeId] Process or sub-process id
|
|
315
|
+
*/
|
|
167
316
|
ContextInstance.prototype.getStartActivities = function getStartActivities(filterOptions, scopeId) {
|
|
168
317
|
const referenceId = filterOptions?.referenceId;
|
|
169
318
|
const referenceType = filterOptions?.referenceType || 'unknown';
|
|
@@ -183,15 +332,70 @@ ContextInstance.prototype.getStartActivities = function getStartActivities(filte
|
|
|
183
332
|
}
|
|
184
333
|
return result;
|
|
185
334
|
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Inspect an activity def for link event definitions.
|
|
338
|
+
* @param {import('moddle-context-serializer').Activity} activityDef
|
|
339
|
+
* @returns {{ linkBehaviour?: Function, linkNames?: string[] }}
|
|
340
|
+
*/
|
|
341
|
+
ContextInstance.prototype.getLinkEventDefinitionInfo = function getLinkEventDefinitionInfo(activityDef) {
|
|
342
|
+
const eds = activityDef.behaviour?.eventDefinitions;
|
|
343
|
+
if (!eds) return {};
|
|
344
|
+
let linkBehaviour;
|
|
345
|
+
const names = new Set();
|
|
346
|
+
for (const ed of eds) {
|
|
347
|
+
if (linkBehaviour ? ed.Behaviour === linkBehaviour : ed.type?.endsWith('LinkEventDefinition')) {
|
|
348
|
+
if (!linkBehaviour) linkBehaviour = ed.Behaviour;
|
|
349
|
+
if (ed.behaviour?.name) names.add(ed.behaviour.name);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
if (!linkBehaviour || !names.size) return {};
|
|
353
|
+
return {
|
|
354
|
+
linkBehaviour,
|
|
355
|
+
linkNames: [...names]
|
|
356
|
+
};
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* Get activities whose event definitions include the given Behaviour with a matching name.
|
|
361
|
+
* @param {Function} Behaviour Behaviour constructor to match against `ed.Behaviour`
|
|
362
|
+
* @param {string[] | Iterable<string>} names
|
|
363
|
+
* @param {string} [scopeId] Process or sub-process id
|
|
364
|
+
*/
|
|
365
|
+
ContextInstance.prototype.getActivitiesByEventDefinitionBehaviour = function getActivitiesByEventDefinitionBehaviour(Behaviour, names, scopeId) {
|
|
366
|
+
const wanted = new Set(names);
|
|
367
|
+
if (!Behaviour || !wanted.size) return [];
|
|
368
|
+
const result = [];
|
|
369
|
+
const rawDefs = this.definitionContext.getActivities(scopeId) || [];
|
|
370
|
+
for (const rawDef of rawDefs) {
|
|
371
|
+
const eds = rawDef.behaviour?.eventDefinitions;
|
|
372
|
+
if (!eds) continue;
|
|
373
|
+
if (!eds.some(ed => ed.Behaviour === Behaviour && wanted.has(ed.behaviour?.name))) continue;
|
|
374
|
+
result.push(this.upsertActivity(rawDef));
|
|
375
|
+
}
|
|
376
|
+
return result;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Resolve user-registered extensions and the built-in BpmnIO extension for an activity.
|
|
381
|
+
* Returns undefined when the activity has no extensions to attach.
|
|
382
|
+
* @param {import('#types').ElementBase} activity
|
|
383
|
+
* @returns {import('#types').IExtension | undefined}
|
|
384
|
+
*/
|
|
186
385
|
ContextInstance.prototype.loadExtensions = function loadExtensions(activity) {
|
|
187
|
-
const io = new _BpmnIO.
|
|
386
|
+
const io = new _BpmnIO.BpmnIO(activity, this);
|
|
188
387
|
const extensions = this.extensionsMapper.get(activity);
|
|
189
388
|
if (io.hasIo) extensions.extensions.push(io);
|
|
190
389
|
if (!extensions.extensions.length) return;
|
|
191
390
|
return extensions;
|
|
192
391
|
};
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Resolve the parent process or sub-process activity that owns the given activity.
|
|
395
|
+
* @param {string} activityId
|
|
396
|
+
*/
|
|
193
397
|
ContextInstance.prototype.getActivityParentById = function getActivityParentById(activityId) {
|
|
194
|
-
const owner = this[
|
|
398
|
+
const owner = this[K_OWNER];
|
|
195
399
|
if (owner) return owner;
|
|
196
400
|
const activity = this.getActivityById(activityId);
|
|
197
401
|
const parentId = activity.parent.id;
|
|
@@ -203,6 +407,8 @@ function ExtensionsMapper(context) {
|
|
|
203
407
|
ExtensionsMapper.prototype.get = function get(activity) {
|
|
204
408
|
return new Extensions(activity, this.context, this._getExtensions());
|
|
205
409
|
};
|
|
410
|
+
|
|
411
|
+
/** @internal */
|
|
206
412
|
ExtensionsMapper.prototype._getExtensions = function getExtensions() {
|
|
207
413
|
let extensions;
|
|
208
414
|
if (!(extensions = this.context.environment.extensions)) return [];
|
|
@@ -214,7 +420,7 @@ function Extensions(activity, context, extensions) {
|
|
|
214
420
|
const extension = Extension(activity, context);
|
|
215
421
|
if (extension) result.push(extension);
|
|
216
422
|
}
|
|
217
|
-
this[
|
|
423
|
+
this[_constants.K_ACTIVATED] = false;
|
|
218
424
|
}
|
|
219
425
|
Object.defineProperty(Extensions.prototype, 'count', {
|
|
220
426
|
get() {
|
|
@@ -222,12 +428,12 @@ Object.defineProperty(Extensions.prototype, 'count', {
|
|
|
222
428
|
}
|
|
223
429
|
});
|
|
224
430
|
Extensions.prototype.activate = function activate(message) {
|
|
225
|
-
if (this[
|
|
226
|
-
this[
|
|
431
|
+
if (this[_constants.K_ACTIVATED]) return;
|
|
432
|
+
this[_constants.K_ACTIVATED] = true;
|
|
227
433
|
for (const extension of this.extensions) extension.activate(message);
|
|
228
434
|
};
|
|
229
435
|
Extensions.prototype.deactivate = function deactivate(message) {
|
|
230
|
-
if (!this[
|
|
231
|
-
this[
|
|
436
|
+
if (!this[_constants.K_ACTIVATED]) return;
|
|
437
|
+
this[_constants.K_ACTIVATED] = false;
|
|
232
438
|
for (const extension of this.extensions) extension.deactivate(message);
|
|
233
439
|
};
|