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