bpmn-elements 5.1.3 → 7.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.
Files changed (119) hide show
  1. package/CHANGELOG.md +322 -0
  2. package/README.md +9 -3
  3. package/dist/index.js +71 -39
  4. package/dist/src/Api.js +77 -76
  5. package/dist/src/Context.js +169 -164
  6. package/dist/src/Environment.js +90 -102
  7. package/dist/src/EventBroker.js +89 -88
  8. package/dist/src/ExtensionsMapper.js +2 -2
  9. package/dist/src/MessageFormatter.js +164 -95
  10. package/dist/src/Scripts.js +6 -2
  11. package/dist/src/Timers.js +4 -6
  12. package/dist/src/activity/Activity.js +1108 -901
  13. package/dist/src/activity/ActivityExecution.js +342 -297
  14. package/dist/src/activity/Dummy.js +3 -3
  15. package/dist/src/definition/Definition.js +498 -444
  16. package/dist/src/definition/DefinitionExecution.js +722 -409
  17. package/dist/src/error/Errors.js +17 -7
  18. package/dist/src/eventDefinitions/CancelEventDefinition.js +190 -150
  19. package/dist/src/eventDefinitions/CompensateEventDefinition.js +194 -161
  20. package/dist/src/eventDefinitions/ConditionalEventDefinition.js +197 -135
  21. package/dist/src/eventDefinitions/ErrorEventDefinition.js +207 -165
  22. package/dist/src/eventDefinitions/EscalationEventDefinition.js +175 -141
  23. package/dist/src/eventDefinitions/EventDefinitionExecution.js +157 -129
  24. package/dist/src/eventDefinitions/LinkEventDefinition.js +174 -149
  25. package/dist/src/eventDefinitions/MessageEventDefinition.js +213 -176
  26. package/dist/src/eventDefinitions/SignalEventDefinition.js +203 -161
  27. package/dist/src/eventDefinitions/TerminateEventDefinition.js +21 -23
  28. package/dist/src/eventDefinitions/TimerEventDefinition.js +243 -228
  29. package/dist/src/events/BoundaryEvent.js +180 -144
  30. package/dist/src/events/EndEvent.js +18 -23
  31. package/dist/src/events/IntermediateCatchEvent.js +44 -58
  32. package/dist/src/events/IntermediateThrowEvent.js +18 -23
  33. package/dist/src/events/StartEvent.js +109 -94
  34. package/dist/src/flows/Association.js +94 -101
  35. package/dist/src/flows/MessageFlow.js +86 -103
  36. package/dist/src/flows/SequenceFlow.js +172 -184
  37. package/dist/src/gateways/EventBasedGateway.js +88 -84
  38. package/dist/src/gateways/ExclusiveGateway.js +13 -16
  39. package/dist/src/gateways/InclusiveGateway.js +11 -14
  40. package/dist/src/gateways/ParallelGateway.js +11 -14
  41. package/dist/src/getPropertyValue.js +34 -34
  42. package/dist/src/io/BpmnIO.js +31 -0
  43. package/dist/src/io/EnvironmentDataObject.js +33 -29
  44. package/dist/src/io/EnvironmentDataStore.js +52 -0
  45. package/dist/src/io/EnvironmentDataStoreReference.js +52 -0
  46. package/dist/src/io/InputOutputSpecification.js +177 -168
  47. package/dist/src/io/Properties.js +252 -0
  48. package/dist/src/messageHelper.js +1 -1
  49. package/dist/src/process/Process.js +433 -359
  50. package/dist/src/process/ProcessExecution.js +744 -645
  51. package/dist/src/shared.js +3 -6
  52. package/dist/src/tasks/CallActivity.js +160 -0
  53. package/dist/src/tasks/LoopCharacteristics.js +309 -330
  54. package/dist/src/tasks/ReceiveTask.js +233 -182
  55. package/dist/src/tasks/ScriptTask.js +35 -41
  56. package/dist/src/tasks/ServiceImplementation.js +13 -20
  57. package/dist/src/tasks/ServiceTask.js +82 -75
  58. package/dist/src/tasks/SignalTask.js +97 -93
  59. package/dist/src/tasks/StandardLoopCharacteristics.js +1 -1
  60. package/dist/src/tasks/SubProcess.js +195 -175
  61. package/dist/src/tasks/Task.js +17 -19
  62. package/index.js +8 -0
  63. package/package.json +16 -15
  64. package/src/Api.js +65 -59
  65. package/src/Context.js +142 -132
  66. package/src/Environment.js +88 -100
  67. package/src/EventBroker.js +67 -68
  68. package/src/ExtensionsMapper.js +2 -2
  69. package/src/MessageFormatter.js +132 -74
  70. package/src/Timers.js +4 -4
  71. package/src/activity/Activity.js +916 -757
  72. package/src/activity/ActivityExecution.js +293 -247
  73. package/src/activity/Dummy.js +2 -2
  74. package/src/definition/Definition.js +436 -401
  75. package/src/definition/DefinitionExecution.js +603 -343
  76. package/src/error/Errors.js +11 -6
  77. package/src/eventDefinitions/CancelEventDefinition.js +164 -121
  78. package/src/eventDefinitions/CompensateEventDefinition.js +158 -124
  79. package/src/eventDefinitions/ConditionalEventDefinition.js +147 -104
  80. package/src/eventDefinitions/ErrorEventDefinition.js +190 -131
  81. package/src/eventDefinitions/EscalationEventDefinition.js +139 -101
  82. package/src/eventDefinitions/EventDefinitionExecution.js +127 -95
  83. package/src/eventDefinitions/LinkEventDefinition.js +160 -129
  84. package/src/eventDefinitions/MessageEventDefinition.js +178 -121
  85. package/src/eventDefinitions/SignalEventDefinition.js +162 -106
  86. package/src/eventDefinitions/TerminateEventDefinition.js +19 -19
  87. package/src/eventDefinitions/TimerEventDefinition.js +202 -167
  88. package/src/events/BoundaryEvent.js +156 -115
  89. package/src/events/EndEvent.js +15 -18
  90. package/src/events/IntermediateCatchEvent.js +40 -44
  91. package/src/events/IntermediateThrowEvent.js +15 -18
  92. package/src/events/StartEvent.js +84 -50
  93. package/src/flows/Association.js +98 -113
  94. package/src/flows/MessageFlow.js +81 -97
  95. package/src/flows/SequenceFlow.js +145 -163
  96. package/src/gateways/EventBasedGateway.js +75 -68
  97. package/src/gateways/ExclusiveGateway.js +8 -13
  98. package/src/gateways/InclusiveGateway.js +8 -13
  99. package/src/gateways/ParallelGateway.js +8 -13
  100. package/src/getPropertyValue.js +34 -33
  101. package/src/io/BpmnIO.js +20 -0
  102. package/src/io/EnvironmentDataObject.js +29 -18
  103. package/src/io/EnvironmentDataStore.js +33 -0
  104. package/src/io/EnvironmentDataStoreReference.js +33 -0
  105. package/src/io/InputOutputSpecification.js +154 -157
  106. package/src/io/Properties.js +199 -0
  107. package/src/process/Process.js +374 -333
  108. package/src/process/ProcessExecution.js +606 -554
  109. package/src/shared.js +1 -5
  110. package/src/tasks/CallActivity.js +130 -0
  111. package/src/tasks/LoopCharacteristics.js +290 -289
  112. package/src/tasks/ReceiveTask.js +174 -107
  113. package/src/tasks/ScriptTask.js +27 -30
  114. package/src/tasks/ServiceImplementation.js +13 -18
  115. package/src/tasks/ServiceTask.js +67 -60
  116. package/src/tasks/SignalTask.js +77 -52
  117. package/src/tasks/StandardLoopCharacteristics.js +1 -1
  118. package/src/tasks/SubProcess.js +184 -157
  119. package/src/tasks/Task.js +15 -19
package/dist/src/Api.js CHANGED
@@ -4,106 +4,107 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.ActivityApi = ActivityApi;
7
+ exports.Api = Api;
7
8
  exports.DefinitionApi = DefinitionApi;
8
- exports.ProcessApi = ProcessApi;
9
9
  exports.FlowApi = FlowApi;
10
- exports.Api = Api;
10
+ exports.ProcessApi = ProcessApi;
11
11
 
12
12
  var _messageHelper = require("./messageHelper");
13
13
 
14
14
  var _shared = require("./shared");
15
15
 
16
16
  function ActivityApi(broker, apiMessage, environment) {
17
- return Api('activity', broker, apiMessage, environment);
17
+ return new Api('activity', broker, apiMessage, environment);
18
18
  }
19
19
 
20
20
  function DefinitionApi(broker, apiMessage, environment) {
21
- return Api('definition', broker, apiMessage, environment);
21
+ return new Api('definition', broker, apiMessage, environment);
22
22
  }
23
23
 
24
24
  function ProcessApi(broker, apiMessage, environment) {
25
- return Api('process', broker, apiMessage, environment);
25
+ return new Api('process', broker, apiMessage, environment);
26
26
  }
27
27
 
28
28
  function FlowApi(broker, apiMessage, environment) {
29
- return Api('flow', broker, apiMessage, environment);
29
+ return new Api('flow', broker, apiMessage, environment);
30
30
  }
31
31
 
32
32
  function Api(pfx, broker, sourceMessage, environment) {
33
33
  if (!sourceMessage) throw new Error('Api requires message');
34
34
  const apiMessage = (0, _messageHelper.cloneMessage)(sourceMessage);
35
- const apiContent = apiMessage.content;
36
35
  const {
37
- id,
38
- type,
39
- name
40
- } = apiContent;
41
- const executionId = apiContent.executionId;
42
- const owner = broker.owner;
43
- environment = environment || broker.owner.environment;
44
- return {
45
36
  id,
46
37
  type,
47
38
  name,
48
- executionId,
49
- environment,
50
- fields: apiMessage.fields,
51
- content: apiContent,
52
- messageProperties: apiMessage.properties,
53
-
54
- get owner() {
55
- return owner;
56
- },
57
-
58
- cancel(message, options) {
59
- sendApiMessage('cancel', {
60
- message
61
- }, options);
62
- },
63
-
64
- discard() {
65
- sendApiMessage('discard');
66
- },
67
-
68
- signal(message, options) {
69
- sendApiMessage('signal', {
70
- message
71
- }, options);
72
- },
73
-
74
- stop() {
75
- sendApiMessage('stop');
76
- },
77
-
78
- resolveExpression(expression) {
79
- return environment.resolveExpression(expression, apiMessage, broker.owner);
80
- },
81
-
82
- sendApiMessage,
83
- createMessage,
84
- getPostponed
85
- };
39
+ executionId
40
+ } = apiMessage.content;
41
+ this.id = id;
42
+ this.type = type;
43
+ this.name = name;
44
+ this.executionId = executionId;
45
+ this.environment = environment || broker.owner.environment;
46
+ this.content = apiMessage.content;
47
+ this.fields = apiMessage.fields;
48
+ this.messageProperties = apiMessage.properties;
49
+ this.broker = broker;
50
+ this.owner = broker.owner;
51
+ this.messagePrefix = pfx;
52
+ }
86
53
 
87
- function sendApiMessage(action, content, options = {}) {
88
- if (!options.correlationId) options = { ...options,
89
- correlationId: (0, _shared.getUniqueId)(`${id || pfx}_signal`)
90
- };
91
- let key = `${pfx}.${action}`;
92
- if (executionId) key += `.${executionId}`;
93
- broker.publish('api', key, createMessage(content), { ...options,
94
- type: action
95
- });
96
- }
97
-
98
- function getPostponed(...args) {
99
- if (owner.getPostponed) return owner.getPostponed(...args);
100
- if (owner.isSubProcess && owner.execution) return owner.execution.getPostponed(...args);
101
- return [];
102
- }
103
-
104
- function createMessage(content = {}) {
105
- return { ...apiContent,
106
- ...content
107
- };
108
- }
109
- }
54
+ const proto = Api.prototype;
55
+
56
+ proto.cancel = function cancel(message, options) {
57
+ this.sendApiMessage('cancel', {
58
+ message
59
+ }, options);
60
+ };
61
+
62
+ proto.discard = function discard() {
63
+ this.sendApiMessage('discard');
64
+ };
65
+
66
+ proto.fail = function fail(error) {
67
+ this.sendApiMessage('error', {
68
+ error
69
+ });
70
+ };
71
+
72
+ proto.signal = function signal(message, options) {
73
+ this.sendApiMessage('signal', {
74
+ message
75
+ }, options);
76
+ };
77
+
78
+ proto.stop = function stop() {
79
+ this.sendApiMessage('stop');
80
+ };
81
+
82
+ proto.resolveExpression = function resolveExpression(expression) {
83
+ return this.environment.resolveExpression(expression, {
84
+ fields: this.fields,
85
+ content: this.content,
86
+ properties: this.messageProperties
87
+ }, this.owner);
88
+ };
89
+
90
+ proto.sendApiMessage = function sendApiMessage(action, content, options) {
91
+ const correlationId = options && options.correlationId || (0, _shared.getUniqueId)(`${this.id || this.messagePrefix}_signal`);
92
+ let key = `${this.messagePrefix}.${action}`;
93
+ if (this.executionId) key += `.${this.executionId}`;
94
+ this.broker.publish('api', key, this.createMessage(content), { ...options,
95
+ correlationId,
96
+ type: action
97
+ });
98
+ };
99
+
100
+ proto.getPostponed = function getPostponed(...args) {
101
+ if (this.owner.getPostponed) return this.owner.getPostponed(...args);
102
+ if (this.owner.isSubProcess && this.owner.execution) return this.owner.execution.getPostponed(...args);
103
+ return [];
104
+ };
105
+
106
+ proto.createMessage = function createMessage(content) {
107
+ return { ...this.content,
108
+ ...content
109
+ };
110
+ };
@@ -14,8 +14,8 @@ var _shared = require("./shared");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
16
  function Context(definitionContext, environment) {
17
- environment = environment ? environment.clone() : (0, _Environment.default)();
18
- return ContextInstance(definitionContext, environment);
17
+ environment = environment ? environment.clone() : new _Environment.default();
18
+ return new ContextInstance(definitionContext, environment);
19
19
  }
20
20
 
21
21
  function ContextInstance(definitionContext, environment) {
@@ -25,169 +25,174 @@ function ContextInstance(definitionContext, environment) {
25
25
  type = 'context'
26
26
  } = definitionContext;
27
27
  const sid = (0, _shared.getUniqueId)(id);
28
- const activityRefs = {},
29
- dataObjectRefs = {},
30
- messageFlows = [],
31
- processes = [],
32
- processRefs = {},
33
- sequenceFlowRefs = {},
34
- sequenceFlows = [],
35
- associationRefs = [];
36
- const context = {
37
- id,
38
- name,
39
- type,
40
- sid,
41
- definitionContext,
42
- environment,
43
- clone,
44
- getActivities,
45
- getActivityById,
46
- getAssociations,
47
- getExecutableProcesses,
48
- getDataObjectById,
49
- getInboundAssociations,
50
- getInboundSequenceFlows,
51
- getMessageFlows,
52
- getOutboundSequenceFlows,
53
- getOutboundAssociations,
54
- getProcessById,
55
- getProcesses,
56
- getSequenceFlowById,
57
- getSequenceFlows,
58
- getStartActivities,
59
- loadExtensions
28
+ this.id = id;
29
+ this.name = name;
30
+ this.type = type;
31
+ this.sid = sid;
32
+ this.definitionContext = definitionContext;
33
+ this.environment = environment;
34
+ this.extensionsMapper = (0, _ExtensionsMapper.default)(this);
35
+ this.refs = {
36
+ activityRefs: {},
37
+ associationRefs: [],
38
+ dataObjectRefs: {},
39
+ dataStoreRefs: {},
40
+ messageFlows: [],
41
+ processes: [],
42
+ processRefs: {},
43
+ sequenceFlowRefs: {},
44
+ sequenceFlows: []
60
45
  };
61
- const extensionsMapper = (0, _ExtensionsMapper.default)(context);
62
- return context;
63
-
64
- function getActivityById(activityId) {
65
- const activityInstance = activityRefs[activityId];
66
- if (activityInstance) return activityInstance;
67
- const activity = definitionContext.getActivityById(activityId);
68
- if (!activity) return null;
69
- return upsertActivity(activity);
70
- }
71
-
72
- function upsertActivity(activityDef) {
73
- let activityInstance = activityRefs[activityDef.id];
74
- if (activityInstance) return activityInstance;
75
- activityInstance = activityRefs[activityDef.id] = activityDef.Behaviour(activityDef, context);
76
- return activityInstance;
77
- }
78
-
79
- function getSequenceFlowById(sequenceFlowId) {
80
- const flowInstance = sequenceFlowRefs[sequenceFlowId];
81
- if (flowInstance) return flowInstance;
82
- const flowDef = definitionContext.getSequenceFlowById(sequenceFlowId);
83
- if (!flowDef) return null;
84
- return upsertSequenceFlow(flowDef);
85
- }
86
-
87
- function getInboundSequenceFlows(activityId) {
88
- return (definitionContext.getInboundSequenceFlows(activityId) || []).map(flow => upsertSequenceFlow(flow));
89
- }
90
-
91
- function getOutboundSequenceFlows(activityId) {
92
- return (definitionContext.getOutboundSequenceFlows(activityId) || []).map(flow => upsertSequenceFlow(flow));
93
- }
94
-
95
- function getInboundAssociations(activityId) {
96
- return (definitionContext.getInboundAssociations(activityId) || []).map(association => upsertAssociation(association));
97
- }
98
-
99
- function getOutboundAssociations(activityId) {
100
- return (definitionContext.getOutboundAssociations(activityId) || []).map(association => upsertAssociation(association));
101
- }
102
-
103
- function getActivities(scopeId) {
104
- return (definitionContext.getActivities(scopeId) || []).map(activityDef => upsertActivity(activityDef));
105
- }
106
-
107
- function getSequenceFlows(scopeId) {
108
- return (definitionContext.getSequenceFlows(scopeId) || []).map(flow => upsertSequenceFlow(flow));
109
- }
110
-
111
- function upsertSequenceFlow(flowDefinition) {
112
- let flowInstance = sequenceFlowRefs[flowDefinition.id];
113
- if (flowInstance) return flowInstance;
114
- flowInstance = sequenceFlowRefs[flowDefinition.id] = flowDefinition.Behaviour(flowDefinition, context);
115
- sequenceFlows.push(flowInstance);
116
- return flowInstance;
117
- }
118
-
119
- function getAssociations(scopeId) {
120
- return (definitionContext.getAssociations(scopeId) || []).map(association => upsertAssociation(association));
121
- }
122
-
123
- function upsertAssociation(associationDefinition) {
124
- let instance = associationRefs[associationDefinition.id];
125
- if (instance) return instance;
126
- instance = associationRefs[associationDefinition.id] = associationDefinition.Behaviour(associationDefinition, context);
127
- return instance;
128
- }
129
-
130
- function clone(newEnvironment) {
131
- return ContextInstance(definitionContext, newEnvironment || environment);
132
- }
133
-
134
- function getProcessById(processId) {
135
- let processInstance = processRefs[processId];
136
- if (processInstance) return processInstance;
137
- const processDefinition = definitionContext.getProcessById(processId);
138
- if (!processDefinition) return null;
139
- processInstance = processRefs[processId] = processDefinition.Behaviour(processDefinition, context);
140
- processes.push(processInstance);
141
- return processInstance;
142
- }
143
-
144
- function getProcesses() {
145
- return definitionContext.getProcesses().map(({
146
- id: processId
147
- }) => getProcessById(processId));
148
- }
149
-
150
- function getExecutableProcesses() {
151
- return definitionContext.getExecutableProcesses().map(({
152
- id: processId
153
- }) => getProcessById(processId));
154
- }
155
-
156
- function getMessageFlows(sourceId) {
157
- if (!messageFlows.length) {
158
- const flows = definitionContext.getMessageFlows() || [];
159
- messageFlows.push(...flows.map(flow => flow.Behaviour(flow, context)));
160
- }
161
-
162
- return messageFlows.filter(flow => flow.source.processId === sourceId);
163
- }
164
-
165
- function getDataObjectById(dataObjectId) {
166
- let dataObject;
167
- if (dataObject = dataObjectRefs[dataObjectId]) return dataObject;
168
- const dataObjectDef = definitionContext.getDataObjectById(dataObjectId);
169
- if (!dataObjectDef) return;
170
- dataObject = dataObjectRefs[dataObjectDef.id] = dataObjectDef.Behaviour(dataObjectDef, context);
171
- return dataObject;
172
- }
46
+ }
173
47
 
174
- function getStartActivities(filterOptions, scopeId) {
175
- const {
176
- referenceId,
177
- referenceType = 'unknown'
178
- } = filterOptions || {};
179
- return getActivities().filter(activity => {
180
- if (!activity.isStart) return false;
181
- if (scopeId && activity.parent.id !== scopeId) return false;
182
- if (!filterOptions) return true;
183
- if (!activity.behaviour.eventDefinitions && !activity.behaviour.eventDefinitions) return false;
184
- return activity.eventDefinitions.some(ed => {
185
- return ed.reference && ed.reference.id === referenceId && ed.reference.referenceType === referenceType;
186
- });
48
+ ContextInstance.prototype.getActivityById = function getActivityById(activityId) {
49
+ const activityInstance = this.refs.activityRefs[activityId];
50
+ if (activityInstance) return activityInstance;
51
+ const activity = this.definitionContext.getActivityById(activityId);
52
+ if (!activity) return null;
53
+ return this.upsertActivity(activity);
54
+ };
55
+
56
+ ContextInstance.prototype.upsertActivity = function upsertActivity(activityDef) {
57
+ let activityInstance = this.refs.activityRefs[activityDef.id];
58
+ if (activityInstance) return activityInstance;
59
+ activityInstance = this.refs.activityRefs[activityDef.id] = new activityDef.Behaviour(activityDef, this);
60
+ return activityInstance;
61
+ };
62
+
63
+ ContextInstance.prototype.getSequenceFlowById = function getSequenceFlowById(sequenceFlowId) {
64
+ const flowInstance = this.refs.sequenceFlowRefs[sequenceFlowId];
65
+ if (flowInstance) return flowInstance;
66
+ const flowDef = this.definitionContext.getSequenceFlowById(sequenceFlowId);
67
+ if (!flowDef) return null;
68
+ return this.upsertSequenceFlow(flowDef);
69
+ };
70
+
71
+ ContextInstance.prototype.getInboundSequenceFlows = function getInboundSequenceFlows(activityId) {
72
+ return (this.definitionContext.getInboundSequenceFlows(activityId) || []).map(flow => this.upsertSequenceFlow(flow));
73
+ };
74
+
75
+ ContextInstance.prototype.getOutboundSequenceFlows = function getOutboundSequenceFlows(activityId) {
76
+ return (this.definitionContext.getOutboundSequenceFlows(activityId) || []).map(flow => this.upsertSequenceFlow(flow));
77
+ };
78
+
79
+ ContextInstance.prototype.getInboundAssociations = function getInboundAssociations(activityId) {
80
+ return (this.definitionContext.getInboundAssociations(activityId) || []).map(association => this.upsertAssociation(association));
81
+ };
82
+
83
+ ContextInstance.prototype.getOutboundAssociations = function getOutboundAssociations(activityId) {
84
+ return (this.definitionContext.getOutboundAssociations(activityId) || []).map(association => this.upsertAssociation(association));
85
+ };
86
+
87
+ ContextInstance.prototype.getActivities = function getActivities(scopeId) {
88
+ return (this.definitionContext.getActivities(scopeId) || []).map(activityDef => this.upsertActivity(activityDef));
89
+ };
90
+
91
+ ContextInstance.prototype.getSequenceFlows = function getSequenceFlows(scopeId) {
92
+ return (this.definitionContext.getSequenceFlows(scopeId) || []).map(flow => this.upsertSequenceFlow(flow));
93
+ };
94
+
95
+ ContextInstance.prototype.upsertSequenceFlow = function upsertSequenceFlow(flowDefinition) {
96
+ const refs = this.refs.sequenceFlowRefs;
97
+ let flowInstance = refs[flowDefinition.id];
98
+ if (flowInstance) return flowInstance;
99
+ flowInstance = refs[flowDefinition.id] = new flowDefinition.Behaviour(flowDefinition, this);
100
+ this.refs.sequenceFlows.push(flowInstance);
101
+ return flowInstance;
102
+ };
103
+
104
+ ContextInstance.prototype.getAssociations = function getAssociations(scopeId) {
105
+ return (this.definitionContext.getAssociations(scopeId) || []).map(association => this.upsertAssociation(association));
106
+ };
107
+
108
+ ContextInstance.prototype.upsertAssociation = function upsertAssociation(associationDefinition) {
109
+ const refs = this.refs.associationRefs;
110
+ let instance = refs[associationDefinition.id];
111
+ if (instance) return instance;
112
+ instance = refs[associationDefinition.id] = new associationDefinition.Behaviour(associationDefinition, this);
113
+ return instance;
114
+ };
115
+
116
+ ContextInstance.prototype.clone = function clone(newEnvironment) {
117
+ return new ContextInstance(this.definitionContext, newEnvironment || this.environment);
118
+ };
119
+
120
+ ContextInstance.prototype.getProcessById = function getProcessById(processId) {
121
+ const refs = this.refs.processRefs;
122
+ let processInstance = this.refs.processRefs[processId];
123
+ if (processInstance) return processInstance;
124
+ const processDefinition = this.definitionContext.getProcessById(processId);
125
+ if (!processDefinition) return null;
126
+ processInstance = refs[processId] = new processDefinition.Behaviour(processDefinition, this);
127
+ this.refs.processes.push(processInstance);
128
+ return processInstance;
129
+ };
130
+
131
+ ContextInstance.prototype.getNewProcessById = function getNewProcessById(processId, processOptions) {
132
+ if (!this.getProcessById(processId)) return null;
133
+ const processDefinition = this.definitionContext.getProcessById(processId);
134
+ const processInstance = new processDefinition.Behaviour(processDefinition, this.clone(this.environment.clone({
135
+ output: {},
136
+ ...processOptions
137
+ })));
138
+ return processInstance;
139
+ };
140
+
141
+ ContextInstance.prototype.getProcesses = function getProcesses() {
142
+ return this.definitionContext.getProcesses().map(({
143
+ id: processId
144
+ }) => this.getProcessById(processId));
145
+ };
146
+
147
+ ContextInstance.prototype.getExecutableProcesses = function getExecutableProcesses() {
148
+ return this.definitionContext.getExecutableProcesses().map(({
149
+ id: processId
150
+ }) => this.getProcessById(processId));
151
+ };
152
+
153
+ ContextInstance.prototype.getMessageFlows = function getMessageFlows(sourceId) {
154
+ if (!this.refs.messageFlows.length) {
155
+ const flows = this.definitionContext.getMessageFlows() || [];
156
+ this.refs.messageFlows.push(...flows.map(flow => new flow.Behaviour(flow, this)));
157
+ }
158
+
159
+ return this.refs.messageFlows.filter(flow => flow.source.processId === sourceId);
160
+ };
161
+
162
+ ContextInstance.prototype.getDataObjectById = function getDataObjectById(referenceId) {
163
+ let dataObject;
164
+ if (dataObject = this.refs.dataObjectRefs[referenceId]) return dataObject;
165
+ const dataObjectDef = this.definitionContext.getDataObjectById(referenceId);
166
+ if (!dataObjectDef) return;
167
+ dataObject = this.refs.dataObjectRefs[dataObjectDef.id] = new dataObjectDef.Behaviour(dataObjectDef, this);
168
+ return dataObject;
169
+ };
170
+
171
+ ContextInstance.prototype.getDataStoreById = function getDataStoreById(referenceId) {
172
+ let dataStore;
173
+ if (dataStore = this.refs.dataStoreRefs[referenceId]) return dataStore;
174
+ const dataStoreDef = this.definitionContext.getDataStoreById(referenceId) || this.definitionContext.getDataStoreReferenceById(referenceId);
175
+ if (!dataStoreDef) return;
176
+ dataStore = this.refs.dataStoreRefs[dataStoreDef.id] = new dataStoreDef.Behaviour(dataStoreDef, this);
177
+ return dataStore;
178
+ };
179
+
180
+ ContextInstance.prototype.getStartActivities = function getStartActivities(filterOptions, scopeId) {
181
+ const {
182
+ referenceId,
183
+ referenceType = 'unknown'
184
+ } = filterOptions || {};
185
+ return this.getActivities().filter(activity => {
186
+ if (!activity.isStart) return false;
187
+ if (scopeId && activity.parent.id !== scopeId) return false;
188
+ if (!filterOptions) return true;
189
+ if (!activity.behaviour.eventDefinitions && !activity.behaviour.eventDefinitions) return false;
190
+ return activity.eventDefinitions.some(ed => {
191
+ return ed.reference && ed.reference.id === referenceId && ed.reference.referenceType === referenceType;
187
192
  });
188
- }
193
+ });
194
+ };
189
195
 
190
- function loadExtensions(activity) {
191
- return extensionsMapper.get(activity);
192
- }
193
- }
196
+ ContextInstance.prototype.loadExtensions = function loadExtensions(activity) {
197
+ return this.extensionsMapper.get(activity);
198
+ };