bpmn-elements 13.1.1 → 13.2.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 (73) hide show
  1. package/README.md +1 -2
  2. package/dist/Context.js +36 -2
  3. package/dist/definition/DefinitionExecution.js +2 -1
  4. package/dist/getPropertyValue.js +1 -2
  5. package/dist/index.js +1 -1
  6. package/package.json +14 -13
  7. package/src/Api.js +18 -20
  8. package/src/Context.js +49 -7
  9. package/src/Environment.js +10 -20
  10. package/src/EventBroker.js +21 -27
  11. package/src/MessageFormatter.js +23 -19
  12. package/src/Tracker.js +4 -4
  13. package/src/activity/Activity.js +141 -109
  14. package/src/activity/ActivityExecution.js +38 -29
  15. package/src/activity/Dummy.js +3 -3
  16. package/src/activity/Escalation.js +4 -4
  17. package/src/activity/ExecutionScope.js +4 -4
  18. package/src/activity/Message.js +5 -5
  19. package/src/activity/Signal.js +5 -5
  20. package/src/definition/Definition.js +44 -36
  21. package/src/definition/DefinitionExecution.js +98 -66
  22. package/src/error/BpmnError.js +3 -3
  23. package/src/error/Errors.js +19 -14
  24. package/src/eventDefinitions/CancelEventDefinition.js +16 -11
  25. package/src/eventDefinitions/CompensateEventDefinition.js +28 -23
  26. package/src/eventDefinitions/ConditionalEventDefinition.js +42 -23
  27. package/src/eventDefinitions/ErrorEventDefinition.js +47 -34
  28. package/src/eventDefinitions/EscalationEventDefinition.js +21 -20
  29. package/src/eventDefinitions/EventDefinitionExecution.js +6 -6
  30. package/src/eventDefinitions/LinkEventDefinition.js +28 -22
  31. package/src/eventDefinitions/MessageEventDefinition.js +47 -36
  32. package/src/eventDefinitions/SignalEventDefinition.js +42 -31
  33. package/src/eventDefinitions/TerminateEventDefinition.js +4 -4
  34. package/src/eventDefinitions/TimerEventDefinition.js +41 -29
  35. package/src/events/BoundaryEvent.js +81 -46
  36. package/src/events/EndEvent.js +2 -2
  37. package/src/events/IntermediateCatchEvent.js +8 -4
  38. package/src/events/IntermediateThrowEvent.js +2 -2
  39. package/src/events/StartEvent.js +29 -18
  40. package/src/flows/Association.js +11 -11
  41. package/src/flows/MessageFlow.js +16 -14
  42. package/src/flows/SequenceFlow.js +22 -20
  43. package/src/gateways/EventBasedGateway.js +7 -6
  44. package/src/gateways/ExclusiveGateway.js +4 -4
  45. package/src/gateways/InclusiveGateway.js +3 -3
  46. package/src/gateways/ParallelGateway.js +4 -4
  47. package/src/getPropertyValue.js +3 -6
  48. package/src/index.js +1 -1
  49. package/src/io/BpmnIO.js +5 -6
  50. package/src/io/EnvironmentDataObject.js +2 -3
  51. package/src/io/EnvironmentDataStore.js +2 -2
  52. package/src/io/EnvironmentDataStoreReference.js +2 -2
  53. package/src/io/InputOutputSpecification.js +60 -54
  54. package/src/io/Properties.js +45 -33
  55. package/src/iso-duration.js +9 -13
  56. package/src/messageHelper.js +16 -23
  57. package/src/process/Lane.js +3 -3
  58. package/src/process/Process.js +40 -34
  59. package/src/process/ProcessExecution.js +122 -78
  60. package/src/tasks/CallActivity.js +109 -57
  61. package/src/tasks/LoopCharacteristics.js +30 -18
  62. package/src/tasks/ReceiveTask.js +59 -38
  63. package/src/tasks/ScriptTask.js +17 -8
  64. package/src/tasks/ServiceTask.js +16 -9
  65. package/src/tasks/SignalTask.js +47 -28
  66. package/src/tasks/StandardLoopCharacteristics.js +3 -3
  67. package/src/tasks/SubProcess.js +9 -8
  68. package/src/tasks/Task.js +4 -3
  69. package/src/tasks/Transaction.js +1 -1
  70. package/types/index.d.ts +6 -6
  71. package/types/types.d.ts +39 -35
  72. package/CHANGELOG.md +0 -455
  73. package/src/ExtensionsMapper.js +0 -42
package/README.md CHANGED
@@ -1,5 +1,4 @@
1
- bpmn-elements
2
- =============
1
+ # bpmn-elements
3
2
 
4
3
  [![Build](https://github.com/paed01/bpmn-elements/actions/workflows/build.yaml/badge.svg)](https://github.com/paed01/bpmn-elements/actions/workflows/build.yaml)[![Coverage Status](https://coveralls.io/repos/github/paed01/bpmn-elements/badge.svg?branch=master)](https://coveralls.io/github/paed01/bpmn-elements?branch=master)
5
4
 
package/dist/Context.js CHANGED
@@ -6,10 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = Context;
7
7
  var _BpmnIO = _interopRequireDefault(require("./io/BpmnIO.js"));
8
8
  var _Environment = _interopRequireDefault(require("./Environment.js"));
9
- var _ExtensionsMapper = _interopRequireDefault(require("./ExtensionsMapper.js"));
10
9
  var _shared = require("./shared.js");
11
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
11
  const kOwner = Symbol.for('owner');
12
+ const kActivated = Symbol.for('activated');
13
13
  function Context(definitionContext, environment) {
14
14
  environment = environment ? environment.clone() : new _Environment.default();
15
15
  return new ContextInstance(definitionContext, environment);
@@ -27,7 +27,7 @@ function ContextInstance(definitionContext, environment, owner) {
27
27
  this.sid = sid;
28
28
  this.definitionContext = definitionContext;
29
29
  this.environment = environment;
30
- this.extensionsMapper = new _ExtensionsMapper.default(this);
30
+ this.extensionsMapper = new ExtensionsMapper(this);
31
31
  this.refs = {
32
32
  activityRefs: {},
33
33
  associationRefs: [],
@@ -192,4 +192,38 @@ ContextInstance.prototype.getActivityParentById = function getActivityParentById
192
192
  const activity = this.getActivityById(activityId);
193
193
  const parentId = activity.parent.id;
194
194
  return this.getProcessById(parentId) || this.getActivityById(parentId);
195
+ };
196
+ function ExtensionsMapper(context) {
197
+ this.context = context;
198
+ }
199
+ ExtensionsMapper.prototype.get = function get(activity) {
200
+ return new Extensions(activity, this.context, this._getExtensions());
201
+ };
202
+ ExtensionsMapper.prototype._getExtensions = function getExtensions() {
203
+ let extensions;
204
+ if (!(extensions = this.context.environment.extensions)) return [];
205
+ return Object.values(extensions);
206
+ };
207
+ function Extensions(activity, context, extensions) {
208
+ const result = this.extensions = [];
209
+ for (const Extension of extensions) {
210
+ const extension = Extension(activity, context);
211
+ if (extension) result.push(extension);
212
+ }
213
+ this[kActivated] = false;
214
+ }
215
+ Object.defineProperty(Extensions.prototype, 'count', {
216
+ get() {
217
+ return this.extensions.length;
218
+ }
219
+ });
220
+ Extensions.prototype.activate = function activate(message) {
221
+ if (this[kActivated]) return;
222
+ this[kActivated] = true;
223
+ for (const extension of this.extensions) extension.activate(message);
224
+ };
225
+ Extensions.prototype.deactivate = function deactivate(message) {
226
+ if (!this[kActivated]) return;
227
+ this[kActivated] = false;
228
+ for (const extension of this.extensions) extension.deactivate(message);
195
229
  };
@@ -427,6 +427,7 @@ DefinitionExecution.prototype._onProcessMessage = function onProcessMessage(rout
427
427
  for (const bp of this[kProcesses].running.slice()) {
428
428
  if (bp.id !== childId) bp.stop();
429
429
  }
430
+ Object.assign(this.environment.output, content.output);
430
431
  this._complete('error', {
431
432
  error: content.error
432
433
  });
@@ -454,13 +455,13 @@ DefinitionExecution.prototype._onProcessCompleted = function onProcessCompleted(
454
455
  type,
455
456
  inbound
456
457
  } = message.content;
458
+ message.ack();
457
459
  this._debug(`left <${executionId} (${id})> (${type}), pending runs ${this.postponedCount}`);
458
460
  if (inbound && inbound.length) {
459
461
  const bp = this._removeProcessByExecutionId(executionId);
460
462
  this._deactivateProcess(bp);
461
463
  }
462
464
  if (!this.postponedCount) {
463
- message.ack();
464
465
  this._complete('completed');
465
466
  }
466
467
  };
@@ -48,7 +48,6 @@ function executeFn(fn, args, base, fnScope) {
48
48
  }
49
49
  if (!fnScope) return fn.apply(null, callArguments);
50
50
  return function ScopedIIFE() {
51
- // eslint-disable-line no-extra-parens
52
51
  return fn.apply(this, callArguments);
53
52
  }.call(fnScope);
54
53
  }
@@ -65,7 +64,7 @@ function splitArguments(args, base, fnScope) {
65
64
  argCompleted = true;
66
65
  } else if (charPos !== ' ') {
67
66
  arg += charPos;
68
- if (charPos === '\'' || charPos === '"') {
67
+ if (charPos === "'" || charPos === '"') {
69
68
  insideString = true;
70
69
  delimiter = charPos;
71
70
  }
package/dist/index.js CHANGED
@@ -399,5 +399,5 @@ var _Timers = require("./Timers.js");
399
399
  var ISODuration = _interopRequireWildcard(require("./iso-duration.js"));
400
400
  exports.ISODuration = ISODuration;
401
401
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
402
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
402
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
403
403
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bpmn-elements",
3
- "version": "13.1.1",
3
+ "version": "13.2.0",
4
4
  "description": "Executable workflow elements based on BPMN 2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -33,7 +33,7 @@
33
33
  "scripts": {
34
34
  "test": "mocha -R @bonniernews/hot-bev -p -t 3000",
35
35
  "posttest": "npm run lint && npm run dist",
36
- "lint": "eslint . --cache",
36
+ "lint": "eslint . --cache && prettier . --check --cache",
37
37
  "prepack": "npm run dist",
38
38
  "cov:html": "c8 -r html -r text mocha -R @bonniernews/hot-bev -p -t 3000",
39
39
  "test:lcov": "c8 -r lcov mocha && npm run lint",
@@ -64,25 +64,26 @@
64
64
  ],
65
65
  "devDependencies": {
66
66
  "@aircall/expression-parser": "^1.0.4",
67
- "@babel/cli": "^7.23.9",
68
- "@babel/core": "^7.23.9",
69
- "@babel/preset-env": "^7.23.9",
67
+ "@babel/cli": "^7.24.1",
68
+ "@babel/core": "^7.24.4",
69
+ "@babel/preset-env": "^7.24.4",
70
70
  "@babel/register": "^7.23.7",
71
71
  "@bonniernews/hot-bev": "^0.4.0",
72
- "@types/node": "^16.18.80",
73
- "bpmn-moddle": "^8.1.0",
72
+ "@types/node": "^16.18.95",
73
+ "bpmn-moddle": "^9.0.1",
74
74
  "c8": "^9.1.0",
75
75
  "camunda-bpmn-moddle": "^7.0.1",
76
- "chai": "^5.0.3",
76
+ "chai": "^5.1.0",
77
77
  "chronokinesis": "^6.0.0",
78
78
  "debug": "^4.3.4",
79
- "eslint": "^8.56.0",
80
- "eslint-plugin-import": "^2.29.1",
81
- "got": "^14.2.0",
82
- "mocha": "^10.3.0",
79
+ "eslint": "^9.0.0",
80
+ "globals": "^15.0.0",
81
+ "got": "^14.2.1",
82
+ "mocha": "^10.4.0",
83
83
  "mocha-cakes-2": "^3.3.0",
84
84
  "moddle-context-serializer": "^4.1.2",
85
- "nock": "^13.5.1"
85
+ "nock": "^13.5.3",
86
+ "prettier": "^3.2.5"
86
87
  },
87
88
  "dependencies": {
88
89
  "smqp": "^8.2.2"
package/src/Api.js CHANGED
@@ -1,13 +1,7 @@
1
- import {cloneMessage} from './messageHelper.js';
2
- import {getUniqueId} from './shared.js';
3
-
4
- export {
5
- ActivityApi,
6
- DefinitionApi,
7
- ProcessApi,
8
- FlowApi,
9
- Api,
10
- };
1
+ import { cloneMessage } from './messageHelper.js';
2
+ import { getUniqueId } from './shared.js';
3
+
4
+ export { ActivityApi, DefinitionApi, ProcessApi, FlowApi, Api };
11
5
 
12
6
  function ActivityApi(broker, apiMessage, environment) {
13
7
  return new Api('activity', broker, apiMessage, environment);
@@ -30,7 +24,7 @@ function Api(pfx, broker, sourceMessage, environment) {
30
24
 
31
25
  const apiMessage = cloneMessage(sourceMessage);
32
26
 
33
- const {id, type, name, executionId} = apiMessage.content;
27
+ const { id, type, name, executionId } = apiMessage.content;
34
28
  this.id = id;
35
29
  this.type = type;
36
30
  this.name = name;
@@ -45,7 +39,7 @@ function Api(pfx, broker, sourceMessage, environment) {
45
39
  }
46
40
 
47
41
  Api.prototype.cancel = function cancel(message, options) {
48
- this.sendApiMessage('cancel', {message}, options);
42
+ this.sendApiMessage('cancel', { message }, options);
49
43
  };
50
44
 
51
45
  Api.prototype.discard = function discard() {
@@ -53,11 +47,11 @@ Api.prototype.discard = function discard() {
53
47
  };
54
48
 
55
49
  Api.prototype.fail = function fail(error) {
56
- this.sendApiMessage('error', {error});
50
+ this.sendApiMessage('error', { error });
57
51
  };
58
52
 
59
53
  Api.prototype.signal = function signal(message, options) {
60
- this.sendApiMessage('signal', {message}, options);
54
+ this.sendApiMessage('signal', { message }, options);
61
55
  };
62
56
 
63
57
  Api.prototype.stop = function stop() {
@@ -65,18 +59,22 @@ Api.prototype.stop = function stop() {
65
59
  };
66
60
 
67
61
  Api.prototype.resolveExpression = function resolveExpression(expression) {
68
- return this.environment.resolveExpression(expression, {
69
- fields: this.fields,
70
- content: this.content,
71
- properties: this.messageProperties,
72
- }, this.owner);
62
+ return this.environment.resolveExpression(
63
+ expression,
64
+ {
65
+ fields: this.fields,
66
+ content: this.content,
67
+ properties: this.messageProperties,
68
+ },
69
+ this.owner,
70
+ );
73
71
  };
74
72
 
75
73
  Api.prototype.sendApiMessage = function sendApiMessage(action, content, options) {
76
74
  const correlationId = (options && options.correlationId) || getUniqueId(`${this.id || this.messagePrefix}_signal`);
77
75
  let key = `${this.messagePrefix}.${action}`;
78
76
  if (this.executionId) key += `.${this.executionId}`;
79
- this.broker.publish('api', key, this.createMessage(content), {...options, correlationId, type: action});
77
+ this.broker.publish('api', key, this.createMessage(content), { ...options, correlationId, type: action });
80
78
  };
81
79
 
82
80
  Api.prototype.getPostponed = function getPostponed(...args) {
package/src/Context.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import BpmnIO from './io/BpmnIO.js';
2
2
  import Environment from './Environment.js';
3
- import ExtensionsMapper from './ExtensionsMapper.js';
4
- import {getUniqueId} from './shared.js';
3
+ import { getUniqueId } from './shared.js';
5
4
 
6
5
  const kOwner = Symbol.for('owner');
6
+ const kActivated = Symbol.for('activated');
7
7
 
8
8
  export default function Context(definitionContext, environment) {
9
9
  environment = environment ? environment.clone() : new Environment();
@@ -11,7 +11,7 @@ export default function Context(definitionContext, environment) {
11
11
  }
12
12
 
13
13
  function ContextInstance(definitionContext, environment, owner) {
14
- const {id = 'Def', name, type = 'context'} = definitionContext;
14
+ const { id = 'Def', name, type = 'context' } = definitionContext;
15
15
  const sid = getUniqueId(id);
16
16
  this.id = id;
17
17
  this.name = name;
@@ -148,11 +148,11 @@ ContextInstance.prototype.getNewProcessById = function getNewProcessById(process
148
148
  };
149
149
 
150
150
  ContextInstance.prototype.getProcesses = function getProcesses() {
151
- return this.definitionContext.getProcesses().map(({id: processId}) => this.getProcessById(processId));
151
+ return this.definitionContext.getProcesses().map(({ id: processId }) => this.getProcessById(processId));
152
152
  };
153
153
 
154
154
  ContextInstance.prototype.getExecutableProcesses = function getExecutableProcesses() {
155
- return this.definitionContext.getExecutableProcesses().map(({id: processId}) => this.getProcessById(processId));
155
+ return this.definitionContext.getExecutableProcesses().map(({ id: processId }) => this.getProcessById(processId));
156
156
  };
157
157
 
158
158
  ContextInstance.prototype.getMessageFlows = function getMessageFlows(sourceId) {
@@ -180,7 +180,8 @@ ContextInstance.prototype.getDataStoreById = function getDataStoreById(reference
180
180
  let dataStore;
181
181
  if ((dataStore = this.refs.dataStoreRefs[referenceId])) return dataStore;
182
182
 
183
- const dataStoreDef = this.definitionContext.getDataStoreById(referenceId) || this.definitionContext.getDataStoreReferenceById(referenceId);
183
+ const dataStoreDef =
184
+ this.definitionContext.getDataStoreById(referenceId) || this.definitionContext.getDataStoreReferenceById(referenceId);
184
185
  if (!dataStoreDef) return;
185
186
 
186
187
  dataStore = this.refs.dataStoreRefs[dataStoreDef.id] = new dataStoreDef.Behaviour(dataStoreDef, this);
@@ -189,7 +190,7 @@ ContextInstance.prototype.getDataStoreById = function getDataStoreById(reference
189
190
  };
190
191
 
191
192
  ContextInstance.prototype.getStartActivities = function getStartActivities(filterOptions, scopeId) {
192
- const {referenceId, referenceType = 'unknown'} = filterOptions || {};
193
+ const { referenceId, referenceType = 'unknown' } = filterOptions || {};
193
194
  const result = [];
194
195
  for (const activity of this.getActivities()) {
195
196
  if (!activity.isStart) continue;
@@ -224,3 +225,44 @@ ContextInstance.prototype.getActivityParentById = function getActivityParentById
224
225
  const parentId = activity.parent.id;
225
226
  return this.getProcessById(parentId) || this.getActivityById(parentId);
226
227
  };
228
+
229
+ function ExtensionsMapper(context) {
230
+ this.context = context;
231
+ }
232
+
233
+ ExtensionsMapper.prototype.get = function get(activity) {
234
+ return new Extensions(activity, this.context, this._getExtensions());
235
+ };
236
+
237
+ ExtensionsMapper.prototype._getExtensions = function getExtensions() {
238
+ let extensions;
239
+ if (!(extensions = this.context.environment.extensions)) return [];
240
+ return Object.values(extensions);
241
+ };
242
+
243
+ function Extensions(activity, context, extensions) {
244
+ const result = (this.extensions = []);
245
+ for (const Extension of extensions) {
246
+ const extension = Extension(activity, context);
247
+ if (extension) result.push(extension);
248
+ }
249
+ this[kActivated] = false;
250
+ }
251
+
252
+ Object.defineProperty(Extensions.prototype, 'count', {
253
+ get() {
254
+ return this.extensions.length;
255
+ },
256
+ });
257
+
258
+ Extensions.prototype.activate = function activate(message) {
259
+ if (this[kActivated]) return;
260
+ this[kActivated] = true;
261
+ for (const extension of this.extensions) extension.activate(message);
262
+ };
263
+
264
+ Extensions.prototype.deactivate = function deactivate(message) {
265
+ if (!this[kActivated]) return;
266
+ this[kActivated] = false;
267
+ for (const extension of this.extensions) extension.deactivate(message);
268
+ };
@@ -1,21 +1,11 @@
1
1
  import Expressions from './Expressions.js';
2
- import {Scripts as IScripts} from './Scripts.js';
3
- import {Timers} from './Timers.js';
2
+ import { Scripts as IScripts } from './Scripts.js';
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 = [
9
- 'expressions',
10
- 'extensions',
11
- 'Logger',
12
- 'output',
13
- 'scripts',
14
- 'services',
15
- 'settings',
16
- 'timers',
17
- 'variables',
18
- ];
8
+ const defaultOptions = ['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables'];
19
9
 
20
10
  export default function Environment(options = {}) {
21
11
  this.options = validateOptions(options);
@@ -25,7 +15,7 @@ export default function Environment(options = {}) {
25
15
  this.output = options.output || {};
26
16
  this.scripts = options.scripts || IScripts();
27
17
  this.timers = options.timers || new Timers();
28
- this.settings = {...options.settings};
18
+ this.settings = { ...options.settings };
29
19
  this.Logger = options.Logger || DummyLogger;
30
20
  this[kServices] = options.services || {};
31
21
  this[kVariables] = options.variables || {};
@@ -53,9 +43,9 @@ Object.defineProperties(Environment.prototype, {
53
43
 
54
44
  Environment.prototype.getState = function getState() {
55
45
  return {
56
- settings: {...this.settings},
57
- variables: {...this[kVariables]},
58
- output: {...this.output},
46
+ settings: { ...this.settings },
47
+ variables: { ...this[kVariables] },
48
+ output: { ...this.output },
59
49
  };
60
50
  };
61
51
 
@@ -72,8 +62,8 @@ Environment.prototype.recover = function recover(state) {
72
62
  Environment.prototype.clone = function clone(overrideOptions = {}) {
73
63
  const services = this[kServices];
74
64
  const newOptions = {
75
- settings: {...this.settings},
76
- variables: {...this[kVariables]},
65
+ settings: { ...this.settings },
66
+ variables: { ...this[kVariables] },
77
67
  Logger: this.Logger,
78
68
  extensions: this.extensions,
79
69
  scripts: this.scripts,
@@ -84,7 +74,7 @@ Environment.prototype.clone = function clone(overrideOptions = {}) {
84
74
  services,
85
75
  };
86
76
 
87
- if (overrideOptions.services) newOptions.services = {...services, ...overrideOptions.services};
77
+ if (overrideOptions.services) newOptions.services = { ...services, ...overrideOptions.services };
88
78
 
89
79
  return new this.constructor(newOptions);
90
80
  };
@@ -1,13 +1,7 @@
1
1
  import { Broker } from 'smqp';
2
2
  import { makeErrorFromMessage } from './error/Errors.js';
3
3
 
4
- export {
5
- ActivityBroker,
6
- DefinitionBroker,
7
- MessageFlowBroker,
8
- ProcessBroker,
9
- EventBroker
10
- };
4
+ export { ActivityBroker, DefinitionBroker, MessageFlowBroker, ProcessBroker, EventBroker };
11
5
 
12
6
  function ActivityBroker(activity) {
13
7
  const executionBroker = ExecutionBroker(activity, 'activity');
@@ -16,7 +10,7 @@ function ActivityBroker(activity) {
16
10
 
17
11
  function ProcessBroker(owner) {
18
12
  const executionBroker = ExecutionBroker(owner, 'process');
19
- executionBroker.broker.assertQueue('api-q', {durable: false, autoDelete: false});
13
+ executionBroker.broker.assertQueue('api-q', { durable: false, autoDelete: false });
20
14
  executionBroker.broker.bindQueue('api-q', 'api', '#');
21
15
  return executionBroker;
22
16
  }
@@ -26,29 +20,29 @@ function DefinitionBroker(owner, onBrokerReturn) {
26
20
  }
27
21
 
28
22
  function MessageFlowBroker(owner) {
29
- const eventBroker = new EventBroker(owner, {prefix: 'messageflow', autoDelete: false, durable: false});
23
+ const eventBroker = new EventBroker(owner, { prefix: 'messageflow', autoDelete: false, durable: false });
30
24
  const broker = eventBroker.broker;
31
25
 
32
- broker.assertExchange('message', 'topic', {durable: true, autoDelete: false});
33
- broker.assertQueue('message-q', {durable: true, autoDelete: false});
26
+ broker.assertExchange('message', 'topic', { durable: true, autoDelete: false });
27
+ broker.assertQueue('message-q', { durable: true, autoDelete: false });
34
28
  broker.bindQueue('message-q', 'message', 'message.#');
35
29
 
36
30
  return eventBroker;
37
31
  }
38
32
 
39
33
  function ExecutionBroker(brokerOwner, prefix, onBrokerReturn) {
40
- const eventBroker = new EventBroker(brokerOwner, {prefix, autoDelete: false, durable: false}, onBrokerReturn);
34
+ const eventBroker = new EventBroker(brokerOwner, { prefix, autoDelete: false, durable: false }, onBrokerReturn);
41
35
  const broker = eventBroker.broker;
42
36
 
43
- broker.assertExchange('api', 'topic', {autoDelete: false, durable: false});
44
- broker.assertExchange('run', 'topic', {autoDelete: false});
45
- broker.assertExchange('format', 'topic', {autoDelete: false});
46
- broker.assertExchange('execution', 'topic', {autoDelete: false});
37
+ broker.assertExchange('api', 'topic', { autoDelete: false, durable: false });
38
+ broker.assertExchange('run', 'topic', { autoDelete: false });
39
+ broker.assertExchange('format', 'topic', { autoDelete: false });
40
+ broker.assertExchange('execution', 'topic', { autoDelete: false });
47
41
 
48
- const runQ = broker.assertQueue('run-q', {durable: true, autoDelete: false});
49
- const formatRunQ = broker.assertQueue('format-run-q', {durable: true, autoDelete: false});
50
- const executionQ = broker.assertQueue('execution-q', {durable: true, autoDelete: false});
51
- broker.assertQueue('inbound-q', {durable: true, autoDelete: false});
42
+ const runQ = broker.assertQueue('run-q', { durable: true, autoDelete: false });
43
+ const formatRunQ = broker.assertQueue('format-run-q', { durable: true, autoDelete: false });
44
+ const executionQ = broker.assertQueue('execution-q', { durable: true, autoDelete: false });
45
+ broker.assertQueue('inbound-q', { durable: true, autoDelete: false });
52
46
 
53
47
  broker.bindQueue(runQ.name, 'run', 'run.#');
54
48
  broker.bindQueue(formatRunQ.name, 'format', 'run.#');
@@ -61,7 +55,7 @@ function EventBroker(brokerOwner, options, onBrokerReturn) {
61
55
  this.options = options;
62
56
  this.eventPrefix = options.prefix;
63
57
 
64
- const broker = this.broker = Broker(brokerOwner);
58
+ const broker = (this.broker = Broker(brokerOwner));
65
59
  broker.assertExchange('event', 'topic', options);
66
60
  broker.on('return', onBrokerReturn ? onBrokerReturn.bind(brokerOwner) : this._onBrokerReturnFn.bind(this));
67
61
 
@@ -76,7 +70,7 @@ EventBroker.prototype.on = function on(eventName, callback, eventOptions = { onc
76
70
  const key = this._getEventRoutingKey(eventName);
77
71
 
78
72
  if (eventOptions.once) return this.broker.subscribeOnce('event', key, eventCallback, eventOptions);
79
- return this.broker.subscribeTmp('event', key, eventCallback, {...eventOptions, noAck: true});
73
+ return this.broker.subscribeTmp('event', key, eventCallback, { ...eventOptions, noAck: true });
80
74
 
81
75
  function eventCallback(routingKey, message, owner) {
82
76
  if (eventName === 'error') return callback(makeErrorFromMessage(message));
@@ -85,7 +79,7 @@ EventBroker.prototype.on = function on(eventName, callback, eventOptions = { onc
85
79
  };
86
80
 
87
81
  EventBroker.prototype.once = function once(eventName, callback, eventOptions = {}) {
88
- return this.on(eventName, callback, {...eventOptions, once: true});
82
+ return this.on(eventName, callback, { ...eventOptions, once: true });
89
83
  };
90
84
 
91
85
  EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
@@ -93,8 +87,8 @@ EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
93
87
 
94
88
  return new Promise((resolve, reject) => {
95
89
  const consumers = [
96
- this.broker.subscribeTmp('event', key, eventCallback, {noAck: true}),
97
- this.broker.subscribeTmp('event', '*.error', errorCallback, {noAck: true}),
90
+ this.broker.subscribeTmp('event', key, eventCallback, { noAck: true }),
91
+ this.broker.subscribeTmp('event', '*.error', errorCallback, { noAck: true }),
98
92
  ];
99
93
 
100
94
  function eventCallback(routingKey, message, owner) {
@@ -118,11 +112,11 @@ EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
118
112
  };
119
113
 
120
114
  EventBroker.prototype.emit = function emit(eventName, content, props) {
121
- this.broker.publish('event', `${this.eventPrefix}.${eventName}`, {...content}, {type: eventName, ...props});
115
+ this.broker.publish('event', `${this.eventPrefix}.${eventName}`, { ...content }, { type: eventName, ...props });
122
116
  };
123
117
 
124
118
  EventBroker.prototype.emitFatal = function emitFatal(error, content) {
125
- this.emit('error', {...content, error}, {mandatory: true});
119
+ this.emit('error', { ...content, error }, { mandatory: true });
126
120
  };
127
121
 
128
122
  EventBroker.prototype._onBrokerReturnFn = function onBrokerReturnFn(message) {
@@ -1,15 +1,15 @@
1
- import {cloneMessage} from './messageHelper.js';
2
- import {getUniqueId} from './shared.js';
3
- import {ActivityError} from './error/Errors.js';
4
- import {getRoutingKeyPattern} from 'smqp';
1
+ import { cloneMessage } from './messageHelper.js';
2
+ import { getUniqueId } from './shared.js';
3
+ import { ActivityError } from './error/Errors.js';
4
+ import { getRoutingKeyPattern } from 'smqp';
5
5
 
6
6
  const kOnMessage = Symbol.for('onMessage');
7
7
  const kExecution = Symbol.for('execution');
8
8
 
9
- export {Formatter};
9
+ export { Formatter };
10
10
 
11
11
  function Formatter(element, formatQ) {
12
- const {id, broker, logger} = element;
12
+ const { id, broker, logger } = element;
13
13
  this.id = id;
14
14
  this.broker = broker;
15
15
  this.logger = logger;
@@ -21,16 +21,20 @@ function Formatter(element, formatQ) {
21
21
  }
22
22
 
23
23
  Formatter.prototype.format = function format(message, callback) {
24
- const correlationId = this._runId = getUniqueId(message.fields.routingKey);
24
+ const correlationId = (this._runId = getUniqueId(message.fields.routingKey));
25
25
  const consumerTag = '_formatter-' + correlationId;
26
26
  const formatQ = this.formatQ;
27
27
 
28
- formatQ.queueMessage({
29
- routingKey: '_formatting.exec',
30
- }, {}, {
31
- correlationId,
32
- persistent: false,
33
- });
28
+ formatQ.queueMessage(
29
+ {
30
+ routingKey: '_formatting.exec',
31
+ },
32
+ {},
33
+ {
34
+ correlationId,
35
+ persistent: false,
36
+ },
37
+ );
34
38
 
35
39
  this[kExecution] = {
36
40
  correlationId,
@@ -49,7 +53,7 @@ Formatter.prototype.format = function format(message, callback) {
49
53
  };
50
54
 
51
55
  Formatter.prototype._onMessage = function onMessage(routingKey, message) {
52
- const {formatKey, correlationId, pending, executeMessage} = this[kExecution];
56
+ const { formatKey, correlationId, pending, executeMessage } = this[kExecution];
53
57
  const asyncFormatting = pending.length;
54
58
 
55
59
  switch (routingKey) {
@@ -72,7 +76,7 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
72
76
  }
73
77
 
74
78
  if (asyncFormatting) {
75
- const {isError, message: startMessage} = this._popFormatStart(pending, routingKey);
79
+ const { isError, message: startMessage } = this._popFormatStart(pending, routingKey);
76
80
  if (startMessage) startMessage.ack();
77
81
 
78
82
  if (isError) {
@@ -91,7 +95,7 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
91
95
  };
92
96
 
93
97
  Formatter.prototype._complete = function complete(message, isError) {
94
- const {runMessage, formatKey, callback, formatted, executeMessage} = this[kExecution];
98
+ const { runMessage, formatKey, callback, formatted, executeMessage } = this[kExecution];
95
99
  this[kExecution] = null;
96
100
  if (executeMessage) executeMessage.ack();
97
101
 
@@ -134,15 +138,15 @@ Formatter.prototype._decorate = function decorate(withContent) {
134
138
  Formatter.prototype._popFormatStart = function popFormattingStart(pending, routingKey) {
135
139
  for (let idx = 0; idx < pending.length; idx++) {
136
140
  const msg = pending[idx];
137
- const {endRoutingKey, errorRoutingKey = '#.error'} = msg.content;
141
+ const { endRoutingKey, errorRoutingKey = '#.error' } = msg.content;
138
142
 
139
143
  if (endRoutingKey && getRoutingKeyPattern(endRoutingKey).test(routingKey)) {
140
144
  this._debug(`completed formatting ${msg.fields.routingKey} message content with formatter ${routingKey}`);
141
145
  pending.splice(idx, 1);
142
- return {message: msg};
146
+ return { message: msg };
143
147
  } else if (getRoutingKeyPattern(errorRoutingKey).test(routingKey)) {
144
148
  pending.splice(idx, 1);
145
- return {isError: true, message: msg};
149
+ return { isError: true, message: msg };
146
150
  }
147
151
  }
148
152
 
package/src/Tracker.js CHANGED
@@ -45,28 +45,28 @@ ActivityTracker.prototype.track = function track(routingKey, message) {
45
45
  };
46
46
 
47
47
  ActivityTracker.prototype._executing = function executing(id) {
48
- const {wait, execute} = this.status;
48
+ const { wait, execute } = this.status;
49
49
  if (execute.indexOf(id) === -1) execute.push(id);
50
50
  let idx;
51
51
  if ((idx = wait.indexOf(id)) !== -1) wait.splice(idx, 1);
52
52
  };
53
53
 
54
54
  ActivityTracker.prototype._waiting = function waiting(id) {
55
- const {wait, execute} = this.status;
55
+ const { wait, execute } = this.status;
56
56
  if (wait.indexOf(id) === -1) wait.push(id);
57
57
  let idx;
58
58
  if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);
59
59
  };
60
60
 
61
61
  ActivityTracker.prototype._timer = function timerFn(id) {
62
- const {timer, execute} = this.status;
62
+ const { timer, execute } = this.status;
63
63
  if (timer.indexOf(id) === -1) timer.push(id);
64
64
  let idx;
65
65
  if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);
66
66
  };
67
67
 
68
68
  ActivityTracker.prototype._leave = function leave(id) {
69
- const {wait, execute, timer} = this.status;
69
+ const { wait, execute, timer } = this.status;
70
70
  let idx;
71
71
  if ((idx = wait.indexOf(id)) !== -1) wait.splice(idx, 1);
72
72
  if ((idx = execute.indexOf(id)) !== -1) execute.splice(idx, 1);