bpmn-elements 14.1.0 → 15.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/README.md +0 -4
  2. package/dist/Context.js +41 -35
  3. package/dist/Environment.js +4 -4
  4. package/dist/Expressions.js +1 -1
  5. package/dist/MessageFormatter.js +0 -1
  6. package/dist/Scripts.js +3 -8
  7. package/dist/Timers.js +5 -9
  8. package/dist/Tracker.js +15 -19
  9. package/dist/activity/Activity.js +68 -49
  10. package/dist/activity/ActivityExecution.js +43 -29
  11. package/dist/definition/Definition.js +20 -14
  12. package/dist/definition/DefinitionExecution.js +64 -55
  13. package/dist/eventDefinitions/EscalationEventDefinition.js +1 -1
  14. package/dist/eventDefinitions/LinkEventDefinition.js +1 -1
  15. package/dist/eventDefinitions/MessageEventDefinition.js +1 -1
  16. package/dist/eventDefinitions/SignalEventDefinition.js +1 -1
  17. package/dist/eventDefinitions/TimerEventDefinition.js +1 -1
  18. package/dist/events/BoundaryEvent.js +11 -9
  19. package/dist/events/EndEvent.js +1 -1
  20. package/dist/events/IntermediateCatchEvent.js +1 -1
  21. package/dist/events/IntermediateThrowEvent.js +1 -1
  22. package/dist/events/StartEvent.js +1 -1
  23. package/dist/flows/SequenceFlow.js +1 -1
  24. package/dist/gateways/EventBasedGateway.js +1 -1
  25. package/dist/gateways/ExclusiveGateway.js +1 -1
  26. package/dist/gateways/InclusiveGateway.js +1 -1
  27. package/dist/gateways/ParallelGateway.js +1 -1
  28. package/dist/index.js +1 -1
  29. package/dist/io/InputOutputSpecification.js +1 -1
  30. package/dist/io/Properties.js +1 -1
  31. package/dist/process/Process.js +20 -19
  32. package/dist/process/ProcessExecution.js +67 -40
  33. package/dist/shared.js +0 -8
  34. package/dist/tasks/CallActivity.js +1 -1
  35. package/dist/tasks/LoopCharacteristics.js +2 -2
  36. package/dist/tasks/ReceiveTask.js +1 -1
  37. package/dist/tasks/ScriptTask.js +3 -3
  38. package/dist/tasks/ServiceImplementation.js +1 -1
  39. package/dist/tasks/ServiceTask.js +1 -1
  40. package/dist/tasks/SignalTask.js +1 -1
  41. package/dist/tasks/StandardLoopCharacteristics.js +1 -1
  42. package/dist/tasks/SubProcess.js +30 -33
  43. package/dist/tasks/Task.js +1 -1
  44. package/dist/tasks/Transaction.js +1 -1
  45. package/package.json +4 -4
  46. package/src/Context.js +51 -35
  47. package/src/Environment.js +4 -4
  48. package/src/MessageFormatter.js +0 -3
  49. package/src/Scripts.js +3 -8
  50. package/src/Timers.js +5 -9
  51. package/src/Tracker.js +13 -17
  52. package/src/activity/Activity.js +57 -42
  53. package/src/activity/ActivityExecution.js +43 -26
  54. package/src/definition/Definition.js +19 -13
  55. package/src/definition/DefinitionExecution.js +64 -54
  56. package/src/eventDefinitions/TimerEventDefinition.js +1 -1
  57. package/src/events/BoundaryEvent.js +10 -8
  58. package/src/process/Process.js +20 -15
  59. package/src/process/ProcessExecution.js +70 -40
  60. package/src/shared.js +0 -8
  61. package/src/tasks/LoopCharacteristics.js +2 -2
  62. package/src/tasks/ScriptTask.js +2 -2
  63. package/src/tasks/SubProcess.js +31 -32
  64. package/types/types.d.ts +1 -1
@@ -8,7 +8,7 @@ exports.default = ServiceTask;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _Errors = require("../error/Errors.js");
10
10
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  function ServiceTask(activityDef, context) {
13
13
  return new _Activity.default(ServiceTaskBehaviour, activityDef, context);
14
14
  }
@@ -8,7 +8,7 @@ exports.default = SignalTask;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _Errors = require("../error/Errors.js");
10
10
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  function SignalTask(activityDef, context) {
13
13
  return new _Activity.default(SignalTaskBehaviour, activityDef, context);
14
14
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = StandardLoopCharacteristics;
7
7
  var _LoopCharacteristics = _interopRequireDefault(require("./LoopCharacteristics.js"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  function StandardLoopCharacteristics(activity, loopCharacteristics) {
10
10
  let {
11
11
  behaviour
@@ -8,9 +8,9 @@ exports.default = SubProcess;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _ProcessExecution = _interopRequireDefault(require("../process/ProcessExecution.js"));
10
10
  var _messageHelper = require("../messageHelper.js");
11
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
12
12
  const kExecutions = Symbol.for('executions');
13
- const kMessageHandlers = Symbol.for('messageHandlers');
13
+ const kOnExecutionCompleted = Symbol.for('execution completed handler');
14
14
  function SubProcess(activityDef, context) {
15
15
  const triggeredByEvent = activityDef.behaviour && activityDef.behaviour.triggeredByEvent;
16
16
  const subProcess = new _Activity.default(SubProcessBehaviour, {
@@ -54,20 +54,18 @@ function SubProcessBehaviour(activity, context) {
54
54
  this.environment = activity.environment;
55
55
  this.broker = activity.broker;
56
56
  this.executionId = undefined;
57
- this[kExecutions] = [];
58
- this[kMessageHandlers] = {
59
- onExecutionCompleted: this._onExecutionCompleted.bind(this)
60
- };
57
+ this[kExecutions] = new Set();
58
+ this[kOnExecutionCompleted] = this._onExecutionCompleted.bind(this);
61
59
  }
62
60
  Object.defineProperties(SubProcessBehaviour.prototype, {
63
61
  execution: {
64
62
  get() {
65
- return this[kExecutions][0];
63
+ return [...this[kExecutions]][0];
66
64
  }
67
65
  },
68
66
  executions: {
69
67
  get() {
70
- return this[kExecutions].slice();
68
+ return [...this[kExecutions]];
71
69
  }
72
70
  }
73
71
  });
@@ -87,47 +85,45 @@ SubProcessBehaviour.prototype.execute = function execute(executeMessage) {
87
85
  return processExecution.execute(executeMessage);
88
86
  };
89
87
  SubProcessBehaviour.prototype.getState = function getState() {
88
+ const states = [];
89
+ for (const pe of this[kExecutions]) {
90
+ const state = pe.getState();
91
+ state.environment = pe.environment.getState();
92
+ states.push(state);
93
+ }
90
94
  if (this.loopCharacteristics) {
91
95
  return {
92
- executions: this[kExecutions].map(pe => {
93
- const state = pe.getState();
94
- state.environment = pe.environment.getState();
95
- return state;
96
- })
96
+ executions: states
97
97
  };
98
98
  }
99
- const execution = this.execution;
100
- if (execution) {
101
- const state = execution.getState();
102
- state.environment = execution.environment.getState();
103
- return state;
104
- }
99
+ return states[0];
105
100
  };
106
101
  SubProcessBehaviour.prototype.recover = function recover(state) {
107
102
  if (!state) return;
108
103
  const executions = this[kExecutions];
109
104
  const loopCharacteristics = this.loopCharacteristics;
110
105
  if (loopCharacteristics && state.executions) {
111
- executions.splice(0);
106
+ executions.clear();
112
107
  for (const se of state.executions) {
113
108
  this.recover(se);
114
109
  }
115
110
  return;
116
111
  }
117
112
  if (!loopCharacteristics) {
118
- executions.splice(0);
113
+ executions.clear();
119
114
  }
120
115
  const subEnvironment = this.environment.clone().recover(state.environment);
121
116
  const subContext = this.context.clone(subEnvironment, this.activity);
122
117
  const execution = new _ProcessExecution.default(this.activity, subContext).recover(state);
123
- executions.push(execution);
118
+ executions.add(execution);
124
119
  return execution;
125
120
  };
126
121
  SubProcessBehaviour.prototype.getPostponed = function getPostponed() {
127
- return this[kExecutions].reduce((result, pe) => {
128
- result = result.concat(pe.getPostponed());
129
- return result;
130
- }, []);
122
+ let postponed = [];
123
+ for (const pe of this[kExecutions]) {
124
+ postponed = postponed.concat(pe.getPostponed());
125
+ }
126
+ return postponed;
131
127
  };
132
128
  SubProcessBehaviour.prototype._upsertExecution = function upsertExecution(executeMessage) {
133
129
  const content = executeMessage.content;
@@ -140,12 +136,12 @@ SubProcessBehaviour.prototype._upsertExecution = function upsertExecution(execut
140
136
  const subEnvironment = this.environment.clone();
141
137
  const subContext = this.context.clone(subEnvironment, this.activity);
142
138
  execution = new _ProcessExecution.default(this.activity, subContext);
143
- this[kExecutions].push(execution);
139
+ this[kExecutions].add(execution);
144
140
  this._addListeners(executionId);
145
141
  return execution;
146
142
  };
147
143
  SubProcessBehaviour.prototype._addListeners = function addListeners(executionId) {
148
- this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kMessageHandlers].onExecutionCompleted, {
144
+ this.broker.subscribeTmp('subprocess-execution', `execution.#.${executionId}`, this[kOnExecutionCompleted], {
149
145
  noAck: true,
150
146
  consumerTag: `_sub-process-execution-${executionId}`
151
147
  });
@@ -180,10 +176,8 @@ SubProcessBehaviour.prototype._onExecutionCompleted = function onExecutionComple
180
176
  };
181
177
  SubProcessBehaviour.prototype._completeExecution = function completeExecution(completeRoutingKey, content) {
182
178
  if (this.loopCharacteristics) {
183
- const executions = this[kExecutions];
184
- const executionIdx = executions.findIndex(pe => pe.executionId === content.executionId);
185
- if (executionIdx < 0) return;
186
- executions.splice(executionIdx, 1);
179
+ const execution = this._getExecutionById(content.executionId);
180
+ this[kExecutions].delete(execution);
187
181
  }
188
182
  this.broker.publish('execution', completeRoutingKey, (0, _messageHelper.cloneContent)(content));
189
183
  };
@@ -194,10 +188,13 @@ SubProcessBehaviour.prototype.getApi = function getApi(apiMessage) {
194
188
  if (execution = this._getExecutionById(content.parent.executionId)) {
195
189
  return execution.getApi(apiMessage);
196
190
  }
191
+ if (!content.parent.path) return;
197
192
  for (const pp of content.parent.path) {
198
193
  if (execution = this._getExecutionById(pp.executionId)) return execution.getApi(apiMessage);
199
194
  }
200
195
  };
201
196
  SubProcessBehaviour.prototype._getExecutionById = function getExecutionById(executionId) {
202
- return this[kExecutions].find(pe => pe.executionId === executionId);
197
+ for (const pe of this[kExecutions]) {
198
+ if (pe.executionId === executionId) return pe;
199
+ }
203
200
  };
@@ -7,7 +7,7 @@ exports.TaskBehaviour = TaskBehaviour;
7
7
  exports.default = Task;
8
8
  var _Activity = _interopRequireDefault(require("../activity/Activity.js"));
9
9
  var _messageHelper = require("../messageHelper.js");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
11
  function Task(activityDef, context) {
12
12
  return new _Activity.default(TaskBehaviour, activityDef, context);
13
13
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = Transaction;
7
7
  var _SubProcess = _interopRequireDefault(require("./SubProcess.js"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
9
  function Transaction(activityDef, context) {
10
10
  const transaction = {
11
11
  type: 'transaction',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-elements",
3
- "version": "14.1.0",
3
+ "version": "15.0.1",
4
4
  "description": "Executable workflow elements based on BPMN 2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -72,7 +72,7 @@
72
72
  "@bonniernews/hot-bev": "^0.4.0",
73
73
  "@types/node": "^16.18.95",
74
74
  "bpmn-moddle": "^9.0.1",
75
- "c8": "^9.1.0",
75
+ "c8": "^10.1.1",
76
76
  "camunda-bpmn-moddle": "^7.0.1",
77
77
  "chai": "^5.1.0",
78
78
  "chronokinesis": "^6.0.0",
@@ -85,10 +85,10 @@
85
85
  "moddle-context-serializer": "^4.1.2",
86
86
  "nock": "^13.5.3",
87
87
  "prettier": "^3.2.5",
88
- "texample": "^0.0.2"
88
+ "texample": "^0.0.5"
89
89
  },
90
90
  "dependencies": {
91
91
  "@0dep/piso": "^0.1.3",
92
- "smqp": "^8.2.4"
92
+ "smqp": "^9.0.2"
93
93
  }
94
94
  }
package/src/Context.js CHANGED
@@ -20,17 +20,15 @@ function ContextInstance(definitionContext, environment, owner) {
20
20
  this.definitionContext = definitionContext;
21
21
  this.environment = environment;
22
22
  this.extensionsMapper = new ExtensionsMapper(this);
23
- this.refs = {
24
- activityRefs: {},
25
- associationRefs: [],
26
- dataObjectRefs: {},
27
- dataStoreRefs: {},
28
- messageFlows: [],
29
- processes: [],
30
- processRefs: {},
31
- sequenceFlowRefs: {},
32
- sequenceFlows: [],
33
- };
23
+ this.refs = new Map([
24
+ ['activityRefs', new Map()],
25
+ ['sequenceFlowRefs', new Map()],
26
+ ['processRefs', new Map()],
27
+ ['messageFlows', new Set()],
28
+ ['associationRefs', new Map()],
29
+ ['dataObjectRefs', new Map()],
30
+ ['dataStoreRefs', new Map()],
31
+ ]);
34
32
  this[kOwner] = owner;
35
33
  }
36
34
 
@@ -41,7 +39,7 @@ Object.defineProperty(ContextInstance.prototype, 'owner', {
41
39
  });
42
40
 
43
41
  ContextInstance.prototype.getActivityById = function getActivityById(activityId) {
44
- const activityInstance = this.refs.activityRefs[activityId];
42
+ const activityInstance = this.refs.get('activityRefs').get(activityId);
45
43
  if (activityInstance) return activityInstance;
46
44
  const activity = this.definitionContext.getActivityById(activityId);
47
45
  if (!activity) return null;
@@ -49,16 +47,17 @@ ContextInstance.prototype.getActivityById = function getActivityById(activityId)
49
47
  };
50
48
 
51
49
  ContextInstance.prototype.upsertActivity = function upsertActivity(activityDef) {
52
- let activityInstance = this.refs.activityRefs[activityDef.id];
50
+ let activityInstance = this.refs.get('activityRefs').get(activityDef.id);
53
51
  if (activityInstance) return activityInstance;
54
52
 
55
- activityInstance = this.refs.activityRefs[activityDef.id] = new activityDef.Behaviour(activityDef, this);
53
+ activityInstance = new activityDef.Behaviour(activityDef, this);
54
+ this.refs.get('activityRefs').set(activityDef.id, activityInstance);
56
55
 
57
56
  return activityInstance;
58
57
  };
59
58
 
60
59
  ContextInstance.prototype.getSequenceFlowById = function getSequenceFlowById(sequenceFlowId) {
61
- const flowInstance = this.refs.sequenceFlowRefs[sequenceFlowId];
60
+ const flowInstance = this.refs.get('sequenceFlowRefs').get(sequenceFlowId);
62
61
  if (flowInstance) return flowInstance;
63
62
 
64
63
  const flowDef = this.definitionContext.getSequenceFlowById(sequenceFlowId);
@@ -91,12 +90,12 @@ ContextInstance.prototype.getSequenceFlows = function getSequenceFlows(scopeId)
91
90
  };
92
91
 
93
92
  ContextInstance.prototype.upsertSequenceFlow = function upsertSequenceFlow(flowDefinition) {
94
- const refs = this.refs.sequenceFlowRefs;
95
- let flowInstance = refs[flowDefinition.id];
93
+ const sequenceFlowRefs = this.refs.get('sequenceFlowRefs');
94
+ let flowInstance = sequenceFlowRefs.get(flowDefinition.id);
96
95
  if (flowInstance) return flowInstance;
97
96
 
98
- flowInstance = refs[flowDefinition.id] = new flowDefinition.Behaviour(flowDefinition, this);
99
- this.refs.sequenceFlows.push(flowInstance);
97
+ flowInstance = new flowDefinition.Behaviour(flowDefinition, this);
98
+ sequenceFlowRefs.set(flowDefinition.id, flowInstance);
100
99
 
101
100
  return flowInstance;
102
101
  };
@@ -106,11 +105,13 @@ ContextInstance.prototype.getAssociations = function getAssociations(scopeId) {
106
105
  };
107
106
 
108
107
  ContextInstance.prototype.upsertAssociation = function upsertAssociation(associationDefinition) {
109
- const refs = this.refs.associationRefs;
110
- let instance = refs[associationDefinition.id];
108
+ const associationRefs = this.refs.get('associationRefs');
109
+ let instance = associationRefs.get(associationDefinition.id);
111
110
  if (instance) return instance;
112
111
 
113
- instance = refs[associationDefinition.id] = new associationDefinition.Behaviour(associationDefinition, this);
112
+ instance = new associationDefinition.Behaviour(associationDefinition, this);
113
+
114
+ associationRefs.set(associationDefinition.id, instance);
114
115
 
115
116
  return instance;
116
117
  };
@@ -120,19 +121,18 @@ ContextInstance.prototype.clone = function clone(newEnvironment, newOwner) {
120
121
  };
121
122
 
122
123
  ContextInstance.prototype.getProcessById = function getProcessById(processId) {
123
- const refs = this.refs.processRefs;
124
- let bp = this.refs.processRefs[processId];
124
+ const processRefs = this.refs.get('processRefs');
125
+ let bp = processRefs.get(processId);
125
126
  if (bp) return bp;
126
127
 
127
128
  const processDefinition = this.definitionContext.getProcessById(processId);
128
129
  if (!processDefinition) return null;
129
130
 
130
131
  const bpContext = this.clone(this.environment.clone());
131
- bp = refs[processId] = new processDefinition.Behaviour(processDefinition, bpContext);
132
+ bp = new processDefinition.Behaviour(processDefinition, bpContext);
133
+ processRefs.set(processId, bp);
132
134
  bpContext[kOwner] = bp;
133
135
 
134
- this.refs.processes.push(bp);
135
-
136
136
  return bp;
137
137
  };
138
138
 
@@ -156,35 +156,51 @@ ContextInstance.prototype.getExecutableProcesses = function getExecutableProcess
156
156
  };
157
157
 
158
158
  ContextInstance.prototype.getMessageFlows = function getMessageFlows(sourceId) {
159
- if (!this.refs.messageFlows.length) {
160
- const flows = this.definitionContext.getMessageFlows() || [];
161
- this.refs.messageFlows.push(...flows.map((flow) => new flow.Behaviour(flow, this)));
159
+ const messageFlowRefs = this.refs.get('messageFlows');
160
+
161
+ const result = [];
162
+ if (!messageFlowRefs.size) {
163
+ const msgFlows = this.definitionContext.getMessageFlows() || [];
164
+ for (const msgFlow of msgFlows) {
165
+ const flow = new msgFlow.Behaviour(msgFlow, this);
166
+ messageFlowRefs.add(flow);
167
+
168
+ if (flow.source.processId === sourceId) result.push(flow);
169
+ }
170
+ } else {
171
+ for (const flow of messageFlowRefs) {
172
+ if (flow.source.processId === sourceId) result.push(flow);
173
+ }
162
174
  }
163
175
 
164
- return this.refs.messageFlows.filter((flow) => flow.source.processId === sourceId);
176
+ return result;
165
177
  };
166
178
 
167
179
  ContextInstance.prototype.getDataObjectById = function getDataObjectById(referenceId) {
180
+ const dataObjectRefs = this.refs.get('dataObjectRefs');
168
181
  let dataObject;
169
- if ((dataObject = this.refs.dataObjectRefs[referenceId])) return dataObject;
182
+ if ((dataObject = dataObjectRefs.get(referenceId))) return dataObject;
170
183
 
171
184
  const dataObjectDef = this.definitionContext.getDataObjectById(referenceId);
172
185
  if (!dataObjectDef) return;
173
186
 
174
- dataObject = this.refs.dataObjectRefs[dataObjectDef.id] = new dataObjectDef.Behaviour(dataObjectDef, this);
187
+ dataObject = new dataObjectDef.Behaviour(dataObjectDef, this);
188
+ dataObjectRefs.set(dataObjectDef.id, dataObject);
175
189
 
176
190
  return dataObject;
177
191
  };
178
192
 
179
193
  ContextInstance.prototype.getDataStoreById = function getDataStoreById(referenceId) {
194
+ const dataStoreRefs = this.refs.get('dataStoreRefs');
180
195
  let dataStore;
181
- if ((dataStore = this.refs.dataStoreRefs[referenceId])) return dataStore;
196
+ if ((dataStore = dataStoreRefs.get(referenceId))) return dataStore;
182
197
 
183
198
  const dataStoreDef =
184
199
  this.definitionContext.getDataStoreById(referenceId) || this.definitionContext.getDataStoreReferenceById(referenceId);
185
200
  if (!dataStoreDef) return;
186
201
 
187
- dataStore = this.refs.dataStoreRefs[dataStoreDef.id] = new dataStoreDef.Behaviour(dataStoreDef, this);
202
+ dataStore = new dataStoreDef.Behaviour(dataStoreDef, this);
203
+ dataStoreRefs.set(dataStoreDef.id, dataStore);
188
204
 
189
205
  return dataStore;
190
206
  };
@@ -1,11 +1,11 @@
1
1
  import Expressions from './Expressions.js';
2
- import { Scripts as IScripts } from './Scripts.js';
2
+ import { Scripts } from './Scripts.js';
3
3
  import { Timers } from './Timers.js';
4
4
 
5
5
  const kServices = Symbol.for('services');
6
6
  const kVariables = Symbol.for('variables');
7
7
 
8
- const defaultOptions = ['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables'];
8
+ const defaultOptions = new Set(['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables']);
9
9
 
10
10
  export default function Environment(options = {}) {
11
11
  this.options = validateOptions(options);
@@ -13,7 +13,7 @@ export default function Environment(options = {}) {
13
13
  this.expressions = options.expressions || Expressions();
14
14
  this.extensions = options.extensions;
15
15
  this.output = options.output || {};
16
- this.scripts = options.scripts || IScripts();
16
+ this.scripts = options.scripts || new Scripts();
17
17
  this.timers = options.timers || new Timers();
18
18
  this.settings = { ...options.settings };
19
19
  this.Logger = options.Logger || DummyLogger;
@@ -125,7 +125,7 @@ Environment.prototype.addService = function addService(name, fn) {
125
125
  function validateOptions(input) {
126
126
  const options = {};
127
127
  for (const key in input) {
128
- if (defaultOptions.indexOf(key) === -1) {
128
+ if (!defaultOptions.has(key)) {
129
129
  options[key] = input[key];
130
130
  }
131
131
  }
@@ -14,9 +14,6 @@ function Formatter(element, formatQ) {
14
14
  this.broker = broker;
15
15
  this.logger = logger;
16
16
  this.formatQ = formatQ;
17
-
18
- this.pendingFormats = [];
19
-
20
17
  this[kOnMessage] = this._onMessage.bind(this);
21
18
  }
22
19
 
package/src/Scripts.js CHANGED
@@ -1,9 +1,4 @@
1
- export function Scripts() {
2
- return {
3
- getScript,
4
- register,
5
- };
1
+ export function Scripts() {}
6
2
 
7
- function getScript(/*scriptType, activity*/) {}
8
- function register(/*activity*/) {}
9
- }
3
+ Scripts.prototype.getScript = function getScript(/*scriptType, activity*/) {};
4
+ Scripts.prototype.register = function register(/*activity*/) {};
package/src/Timers.js CHANGED
@@ -10,14 +10,14 @@ export function Timers(options) {
10
10
  clearTimeout,
11
11
  ...options,
12
12
  };
13
- this[kExecuting] = [];
13
+ this[kExecuting] = new Set();
14
14
  this.setTimeout = this.setTimeout.bind(this);
15
15
  this.clearTimeout = this.clearTimeout.bind(this);
16
16
  }
17
17
 
18
18
  Object.defineProperty(Timers.prototype, 'executing', {
19
19
  get() {
20
- return this[kExecuting].slice();
20
+ return [...this[kExecuting]];
21
21
  },
22
22
  });
23
23
 
@@ -30,10 +30,7 @@ Timers.prototype.setTimeout = function wrappedSetTimeout(callback, delay, ...arg
30
30
  };
31
31
 
32
32
  Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
33
- const executing = this[kExecuting];
34
- const idx = executing.indexOf(ref);
35
- if (idx > -1) {
36
- executing.splice(idx, 1);
33
+ if (this[kExecuting].delete(ref)) {
37
34
  ref.timerRef = this.options.clearTimeout(ref.timerRef);
38
35
  return;
39
36
  }
@@ -43,15 +40,14 @@ Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
43
40
  Timers.prototype._setTimeout = function setTimeout(owner, callback, delay, ...args) {
44
41
  const executing = this[kExecuting];
45
42
  const ref = this._getReference(owner, callback, delay, args);
46
- executing.push(ref);
43
+ executing.add(ref);
47
44
  if (delay < MAX_DELAY) {
48
45
  ref.timerRef = this.options.setTimeout(onTimeout, ref.delay, ...ref.args);
49
46
  }
50
47
  return ref;
51
48
 
52
49
  function onTimeout(...rargs) {
53
- const idx = executing.indexOf(ref);
54
- if (idx > -1) executing.splice(idx, 1);
50
+ executing.delete(ref);
55
51
  return callback(...rargs);
56
52
  }
57
53
  };
package/src/Tracker.js CHANGED
@@ -1,14 +1,14 @@
1
1
  export function ActivityTracker(parentId) {
2
2
  this.id = parentId;
3
- this.status = { wait: [], execute: [], timer: [] };
3
+ this.status = { wait: new Set(), execute: new Set(), timer: new Set() };
4
4
  }
5
5
 
6
6
  Object.defineProperty(ActivityTracker.prototype, 'activityStatus', {
7
7
  get() {
8
8
  const status = this.status;
9
- if (status.execute.length) return 'executing';
10
- if (status.timer.length) return 'timer';
11
- return status.wait.length ? 'wait' : 'idle';
9
+ if (status.execute.size) return 'executing';
10
+ if (status.timer.size) return 'timer';
11
+ return status.wait.size ? 'wait' : 'idle';
12
12
  },
13
13
  });
14
14
 
@@ -46,29 +46,25 @@ ActivityTracker.prototype.track = function track(routingKey, message) {
46
46
 
47
47
  ActivityTracker.prototype._executing = function executing(id) {
48
48
  const { wait, execute } = this.status;
49
- if (execute.indexOf(id) === -1) execute.push(id);
50
- let idx;
51
- if ((idx = wait.indexOf(id)) !== -1) wait.splice(idx, 1);
49
+ wait.delete(id);
50
+ execute.add(id);
52
51
  };
53
52
 
54
53
  ActivityTracker.prototype._waiting = function waiting(id) {
55
54
  const { wait, execute } = this.status;
56
- if (wait.indexOf(id) === -1) wait.push(id);
57
- let idx;
58
- if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);
55
+ execute.delete(id);
56
+ wait.add(id);
59
57
  };
60
58
 
61
59
  ActivityTracker.prototype._timer = function timerFn(id) {
62
60
  const { timer, execute } = this.status;
63
- if (timer.indexOf(id) === -1) timer.push(id);
64
- let idx;
65
- if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);
61
+ execute.delete(id);
62
+ timer.add(id);
66
63
  };
67
64
 
68
65
  ActivityTracker.prototype._leave = function leave(id) {
69
66
  const { wait, execute, timer } = this.status;
70
- let idx;
71
- if ((idx = wait.indexOf(id)) !== -1) wait.splice(idx, 1);
72
- if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);
73
- if ((idx = timer.indexOf(id)) !== -1) timer.splice(idx, 1);
67
+ execute.delete(id);
68
+ timer.delete(id);
69
+ wait.delete(id);
74
70
  };