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