bpmn-elements 17.2.2 → 18.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 (155) hide show
  1. package/README.md +3 -1
  2. package/dist/Api.js +83 -0
  3. package/dist/Context.js +228 -22
  4. package/dist/Environment.js +111 -31
  5. package/dist/EventBroker.js +57 -1
  6. package/dist/Expressions.js +3 -4
  7. package/dist/MessageFormatter.js +29 -16
  8. package/dist/Timers.js +13 -9
  9. package/dist/Tracker.js +1 -0
  10. package/dist/activity/Activity.js +458 -254
  11. package/dist/activity/ActivityExecution.js +113 -40
  12. package/dist/activity/Dummy.js +6 -1
  13. package/dist/activity/Escalation.js +36 -24
  14. package/dist/activity/ExecutionScope.js +1 -1
  15. package/dist/activity/Message.js +36 -24
  16. package/dist/activity/Signal.js +36 -24
  17. package/dist/activity/outbound-evaluator.js +1 -1
  18. package/dist/condition.js +12 -6
  19. package/dist/constants.js +21 -0
  20. package/dist/definition/Definition.js +182 -64
  21. package/dist/definition/DefinitionExecution.js +195 -82
  22. package/dist/error/BpmnError.js +12 -1
  23. package/dist/error/Errors.js +50 -9
  24. package/dist/eventDefinitions/CancelEventDefinition.js +29 -11
  25. package/dist/eventDefinitions/CompensateEventDefinition.js +51 -31
  26. package/dist/eventDefinitions/ConditionalEventDefinition.js +21 -9
  27. package/dist/eventDefinitions/ErrorEventDefinition.js +46 -30
  28. package/dist/eventDefinitions/EscalationEventDefinition.js +44 -27
  29. package/dist/eventDefinitions/EventDefinitionExecution.js +30 -23
  30. package/dist/eventDefinitions/LinkEventDefinition.js +45 -120
  31. package/dist/eventDefinitions/MessageEventDefinition.js +44 -29
  32. package/dist/eventDefinitions/SignalEventDefinition.js +46 -31
  33. package/dist/eventDefinitions/TerminateEventDefinition.js +10 -1
  34. package/dist/eventDefinitions/TimerEventDefinition.js +57 -37
  35. package/dist/eventDefinitions/index.js +20 -21
  36. package/dist/events/BoundaryEvent.js +52 -40
  37. package/dist/events/EndEvent.js +22 -8
  38. package/dist/events/IntermediateCatchEvent.js +26 -8
  39. package/dist/events/IntermediateThrowEvent.js +24 -9
  40. package/dist/events/StartEvent.js +30 -14
  41. package/dist/events/index.js +10 -11
  42. package/dist/flows/Association.js +50 -7
  43. package/dist/flows/MessageFlow.js +49 -10
  44. package/dist/flows/SequenceFlow.js +93 -22
  45. package/dist/flows/index.js +6 -7
  46. package/dist/gateways/EventBasedGateway.js +29 -15
  47. package/dist/gateways/ExclusiveGateway.js +20 -5
  48. package/dist/gateways/InclusiveGateway.js +21 -5
  49. package/dist/gateways/ParallelGateway.js +253 -15
  50. package/dist/gateways/index.js +8 -9
  51. package/dist/getPropertyValue.js +2 -2
  52. package/dist/index.js +42 -43
  53. package/dist/io/BpmnIO.js +15 -1
  54. package/dist/io/EnvironmentDataObject.js +29 -1
  55. package/dist/io/EnvironmentDataStore.js +24 -1
  56. package/dist/io/EnvironmentDataStoreReference.js +24 -1
  57. package/dist/io/InputOutputSpecification.js +21 -11
  58. package/dist/io/Properties.js +28 -17
  59. package/dist/messageHelper.js +41 -4
  60. package/dist/process/Lane.js +15 -4
  61. package/dist/process/Process.js +174 -76
  62. package/dist/process/ProcessExecution.js +362 -177
  63. package/dist/shared.js +2 -0
  64. package/dist/tasks/CallActivity.js +19 -4
  65. package/dist/tasks/LoopCharacteristics.js +94 -9
  66. package/dist/tasks/ReceiveTask.js +36 -21
  67. package/dist/tasks/ScriptTask.js +22 -6
  68. package/dist/tasks/ServiceImplementation.js +7 -4
  69. package/dist/tasks/ServiceTask.js +19 -4
  70. package/dist/tasks/SignalTask.js +19 -4
  71. package/dist/tasks/StandardLoopCharacteristics.js +8 -4
  72. package/dist/tasks/SubProcess.js +44 -29
  73. package/dist/tasks/Task.js +19 -4
  74. package/dist/tasks/Transaction.js +8 -4
  75. package/dist/tasks/index.js +16 -18
  76. package/package.json +31 -13
  77. package/src/Api.js +70 -0
  78. package/src/Context.js +200 -19
  79. package/src/Environment.js +99 -30
  80. package/src/EventBroker.js +46 -1
  81. package/src/Expressions.js +2 -3
  82. package/src/MessageFormatter.js +24 -16
  83. package/src/Timers.js +12 -9
  84. package/src/Tracker.js +1 -0
  85. package/src/activity/Activity.js +388 -231
  86. package/src/activity/ActivityExecution.js +93 -42
  87. package/src/activity/Dummy.js +6 -1
  88. package/src/activity/Escalation.js +25 -18
  89. package/src/activity/ExecutionScope.js +1 -1
  90. package/src/activity/Message.js +25 -18
  91. package/src/activity/Signal.js +25 -18
  92. package/src/activity/outbound-evaluator.js +1 -1
  93. package/src/condition.js +11 -5
  94. package/src/constants.js +15 -0
  95. package/src/definition/Definition.js +157 -62
  96. package/src/definition/DefinitionExecution.js +161 -83
  97. package/src/error/BpmnError.js +11 -1
  98. package/src/error/Errors.js +44 -5
  99. package/src/eventDefinitions/CancelEventDefinition.js +27 -13
  100. package/src/eventDefinitions/CompensateEventDefinition.js +48 -32
  101. package/src/eventDefinitions/ConditionalEventDefinition.js +20 -10
  102. package/src/eventDefinitions/ErrorEventDefinition.js +44 -33
  103. package/src/eventDefinitions/EscalationEventDefinition.js +39 -26
  104. package/src/eventDefinitions/EventDefinitionExecution.js +30 -24
  105. package/src/eventDefinitions/LinkEventDefinition.js +34 -120
  106. package/src/eventDefinitions/MessageEventDefinition.js +42 -31
  107. package/src/eventDefinitions/SignalEventDefinition.js +43 -32
  108. package/src/eventDefinitions/TerminateEventDefinition.js +9 -1
  109. package/src/eventDefinitions/TimerEventDefinition.js +53 -35
  110. package/src/eventDefinitions/index.js +10 -23
  111. package/src/events/BoundaryEvent.js +50 -39
  112. package/src/events/EndEvent.js +19 -7
  113. package/src/events/IntermediateCatchEvent.js +24 -8
  114. package/src/events/IntermediateThrowEvent.js +24 -8
  115. package/src/events/StartEvent.js +25 -14
  116. package/src/events/index.js +5 -18
  117. package/src/flows/Association.js +43 -9
  118. package/src/flows/MessageFlow.js +41 -10
  119. package/src/flows/SequenceFlow.js +82 -19
  120. package/src/flows/index.js +3 -4
  121. package/src/gateways/EventBasedGateway.js +27 -15
  122. package/src/gateways/ExclusiveGateway.js +16 -3
  123. package/src/gateways/InclusiveGateway.js +16 -3
  124. package/src/gateways/ParallelGateway.js +301 -10
  125. package/src/gateways/index.js +4 -4
  126. package/src/getPropertyValue.js +2 -2
  127. package/src/index.js +19 -19
  128. package/src/io/BpmnIO.js +13 -1
  129. package/src/io/EnvironmentDataObject.js +26 -1
  130. package/src/io/EnvironmentDataStore.js +22 -1
  131. package/src/io/EnvironmentDataStoreReference.js +22 -1
  132. package/src/io/InputOutputSpecification.js +17 -8
  133. package/src/io/Properties.js +23 -13
  134. package/src/messageHelper.js +36 -4
  135. package/src/process/Lane.js +14 -4
  136. package/src/process/Process.js +154 -72
  137. package/src/process/ProcessExecution.js +326 -175
  138. package/src/shared.js +1 -0
  139. package/src/tasks/CallActivity.js +16 -2
  140. package/src/tasks/LoopCharacteristics.js +77 -11
  141. package/src/tasks/ReceiveTask.js +33 -22
  142. package/src/tasks/ScriptTask.js +17 -3
  143. package/src/tasks/ServiceImplementation.js +6 -3
  144. package/src/tasks/ServiceTask.js +16 -2
  145. package/src/tasks/SignalTask.js +16 -2
  146. package/src/tasks/StandardLoopCharacteristics.js +7 -3
  147. package/src/tasks/SubProcess.js +37 -23
  148. package/src/tasks/Task.js +16 -2
  149. package/src/tasks/Transaction.js +7 -3
  150. package/src/tasks/index.js +8 -9
  151. package/types/bundle-errors.d.ts +1 -0
  152. package/types/bundle.d.ts +97 -0
  153. package/types/index.d.ts +2614 -84
  154. package/types/interfaces.d.ts +636 -0
  155. package/types/types.d.ts +0 -765
@@ -3,75 +3,105 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = Environment;
7
- var _Expressions = _interopRequireDefault(require("./Expressions.js"));
6
+ exports.Environment = Environment;
7
+ var _Expressions = require("./Expressions.js");
8
8
  var _Scripts = require("./Scripts.js");
9
9
  var _Timers = require("./Timers.js");
10
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
- const kServices = Symbol.for('services');
12
- const kVariables = Symbol.for('variables');
10
+ const K_SERVICES = Symbol.for('services');
11
+ const K_VARIABLES = Symbol.for('variables');
13
12
  const defaultOptions = new Set(['expressions', 'extensions', 'Logger', 'output', 'scripts', 'services', 'settings', 'timers', 'variables']);
13
+
14
+ /**
15
+ * Holds global execution config: variables, injected services, timers, scripts engine,
16
+ * expressions, Logger factory, and settings such as `batchSize`. Cloned and merged per Definition.
17
+ * @param {import('#types').EnvironmentOptions} [options]
18
+ */
14
19
  function Environment(options = {}) {
15
20
  this.options = validateOptions(options);
16
- this.expressions = options.expressions || (0, _Expressions.default)();
21
+
22
+ /** @type {import('#types').IExpressions} */
23
+ this.expressions = options.expressions || (0, _Expressions.Expressions)();
17
24
  this.extensions = options.extensions;
18
25
  this.output = options.output || {};
26
+ /** @type {import('#types').IScripts} */
19
27
  this.scripts = options.scripts || new _Scripts.Scripts();
28
+ /** @type {import('#types').ITimers} */
20
29
  this.timers = options.timers || new _Timers.Timers();
30
+ /** @type {import('#types').EnvironmentSettings} */
21
31
  this.settings = {
22
32
  ...options.settings
23
33
  };
34
+ /** @type {import('#types').LoggerFactory} */
24
35
  this.Logger = options.Logger || DummyLogger;
25
- this[kServices] = options.services || {};
26
- this[kVariables] = options.variables || {};
36
+ this[K_SERVICES] = options.services || {};
37
+ this[K_VARIABLES] = options.variables || {};
27
38
  }
28
- Object.defineProperties(Environment.prototype, {
29
- variables: {
30
- get() {
31
- return this[kVariables];
32
- }
39
+ Object.defineProperty(Environment.prototype, 'variables', {
40
+ /** @returns {Record<string, any>} */
41
+ get() {
42
+ return this[K_VARIABLES];
43
+ }
44
+ });
45
+ Object.defineProperty(Environment.prototype, 'services', {
46
+ /** @returns {Record<string, CallableFunction>} */
47
+ get() {
48
+ return this[K_SERVICES];
33
49
  },
34
- services: {
35
- get() {
36
- return this[kServices];
37
- },
38
- set(value) {
39
- const services = this[kServices];
40
- for (const name in services) {
41
- if (!(name in value)) delete services[name];
42
- }
43
- Object.assign(services, value);
50
+ set(value) {
51
+ const services = this[K_SERVICES];
52
+ for (const name in services) {
53
+ if (!(name in value)) delete services[name];
44
54
  }
55
+ Object.assign(services, value);
45
56
  }
46
57
  });
58
+
59
+ /**
60
+ * Snapshot environment state for recover.
61
+ * @returns {import('#types').EnvironmentState}
62
+ */
47
63
  Environment.prototype.getState = function getState() {
48
64
  return {
49
65
  settings: {
50
66
  ...this.settings
51
67
  },
52
68
  variables: {
53
- ...this[kVariables]
69
+ ...this[K_VARIABLES]
54
70
  },
55
71
  output: {
56
72
  ...this.output
57
73
  }
58
74
  };
59
75
  };
76
+
77
+ /**
78
+ * Restore environment state captured by getState. Merges into the existing settings,
79
+ * variables, and output rather than replacing them.
80
+ * @param {import('#types').EnvironmentState} [state]
81
+ * @returns {this}
82
+ */
60
83
  Environment.prototype.recover = function recover(state) {
61
84
  if (!state) return this;
62
85
  if (state.settings) Object.assign(this.settings, state.settings);
63
- if (state.variables) Object.assign(this[kVariables], state.variables);
86
+ if (state.variables) Object.assign(this[K_VARIABLES], state.variables);
64
87
  if (state.output) Object.assign(this.output, state.output);
65
88
  return this;
66
89
  };
90
+
91
+ /**
92
+ * Clone the environment, optionally overriding options. Services are merged when
93
+ * `overrideOptions.services` is supplied.
94
+ * @param {import('#types').EnvironmentOptions} [overrideOptions]
95
+ * @returns {Environment}
96
+ */
67
97
  Environment.prototype.clone = function clone(overrideOptions) {
68
- const services = this[kServices];
98
+ const services = this[K_SERVICES];
69
99
  const newOptions = {
70
100
  settings: {
71
101
  ...this.settings
72
102
  },
73
103
  variables: {
74
- ...this[kVariables]
104
+ ...this[K_VARIABLES]
75
105
  },
76
106
  Logger: this.Logger,
77
107
  extensions: this.extensions,
@@ -88,29 +118,64 @@ Environment.prototype.clone = function clone(overrideOptions) {
88
118
  };
89
119
  return new this.constructor(newOptions);
90
120
  };
121
+
122
+ /**
123
+ * Merge variables into the environment. Non-objects are ignored.
124
+ * @param {Record<string, any>} newVars
125
+ */
91
126
  Environment.prototype.assignVariables = function assignVariables(newVars) {
92
127
  if (!newVars || typeof newVars !== 'object') return;
93
- this[kVariables] = {
128
+ this[K_VARIABLES] = {
94
129
  ...this.variables,
95
130
  ...newVars
96
131
  };
97
132
  };
133
+
134
+ /**
135
+ * Merge settings into the environment. Non-objects are ignored.
136
+ * @param {import('#types').EnvironmentSettings} newSettings
137
+ * @returns {this}
138
+ */
98
139
  Environment.prototype.assignSettings = function assignSettings(newSettings) {
99
- if (!newSettings || typeof newSettings !== 'object') return;
140
+ if (!newSettings || typeof newSettings !== 'object') return this;
100
141
  this.settings = {
101
142
  ...this.settings,
102
143
  ...newSettings
103
144
  };
145
+ return this;
104
146
  };
147
+
148
+ /**
149
+ * Resolve a registered script by language and identifier.
150
+ * @param {string} language
151
+ * @param {{ id: string, [x: string]: any }} identifier
152
+ */
105
153
  Environment.prototype.getScript = function getScript(...args) {
106
154
  return this.scripts.getScript(...args);
107
155
  };
156
+
157
+ /**
158
+ * Register a script for an activity, delegating to the configured scripts engine.
159
+ * @param {any} activity
160
+ */
108
161
  Environment.prototype.registerScript = function registerScript(...args) {
109
162
  return this.scripts.register(...args);
110
163
  };
164
+
165
+ /**
166
+ * Lookup a registered service by name.
167
+ * @param {string} serviceName
168
+ */
111
169
  Environment.prototype.getServiceByName = function getServiceByName(serviceName) {
112
- return this[kServices][serviceName];
170
+ return this[K_SERVICES][serviceName];
113
171
  };
172
+
173
+ /**
174
+ * Resolve an expression with the environment as scope, optionally extended by an element message.
175
+ * @param {string} expression
176
+ * @param {import('#types').ElementBrokerMessage} [message] Element message merged onto the resolution scope
177
+ * @param {any} [expressionFnContext]
178
+ */
114
179
  Environment.prototype.resolveExpression = function resolveExpression(expression, message, expressionFnContext) {
115
180
  const from = {
116
181
  environment: this,
@@ -118,9 +183,20 @@ Environment.prototype.resolveExpression = function resolveExpression(expression,
118
183
  };
119
184
  return this.expressions.resolveExpression(expression, from, expressionFnContext);
120
185
  };
186
+
187
+ /**
188
+ * Register a service callable by name.
189
+ * @param {string} name service function name
190
+ * @param {CallableFunction} fn service function
191
+ */
121
192
  Environment.prototype.addService = function addService(name, fn) {
122
- this[kServices][name] = fn;
193
+ this[K_SERVICES][name] = fn;
123
194
  };
195
+
196
+ /**
197
+ * @param {import('#types').EnvironmentOptions} input
198
+ * @returns {import('#types').EnvironmentOptions} validated options
199
+ */
124
200
  function validateOptions(input) {
125
201
  const options = {};
126
202
  for (const key in input) {
@@ -145,6 +221,10 @@ function validateOptions(input) {
145
221
  }
146
222
  return options;
147
223
  }
224
+
225
+ /**
226
+ * @returns {import('#types').ILogger}
227
+ */
148
228
  function DummyLogger() {
149
229
  return {
150
230
  debug,
@@ -10,10 +10,21 @@ exports.MessageFlowBroker = MessageFlowBroker;
10
10
  exports.ProcessBroker = ProcessBroker;
11
11
  var _smqp = require("smqp");
12
12
  var _Errors = require("./error/Errors.js");
13
+ /**
14
+ * Build the broker for an activity, including run/format/execution/api exchanges and queues.
15
+ * @param {import('#types').Activity} activity
16
+ * @returns {import('#types').EventBroker<import('#types').Activity>}
17
+ */
13
18
  function ActivityBroker(activity) {
14
19
  const executionBroker = ExecutionBroker(activity, 'activity');
15
20
  return executionBroker;
16
21
  }
22
+
23
+ /**
24
+ * Build the broker for a process, with an additional api-q bound to all api routing keys.
25
+ * @param {import('#types').Process} owner
26
+ * @returns {import('#types').EventBroker<import('#types').Process>}
27
+ */
17
28
  function ProcessBroker(owner) {
18
29
  const executionBroker = ExecutionBroker(owner, 'process');
19
30
  executionBroker.broker.assertQueue('api-q', {
@@ -23,9 +34,22 @@ function ProcessBroker(owner) {
23
34
  executionBroker.broker.bindQueue('api-q', 'api', '#');
24
35
  return executionBroker;
25
36
  }
37
+
38
+ /**
39
+ * Build the broker for a definition. Optionally registers a custom return-message handler.
40
+ * @param {import('#types').Definition} owner
41
+ * @param {(message: import('#types').ElementBrokerMessage) => void} [onBrokerReturn]
42
+ * @returns {import('#types').EventBroker<import('#types').Definition>}
43
+ */
26
44
  function DefinitionBroker(owner, onBrokerReturn) {
27
45
  return ExecutionBroker(owner, 'definition', onBrokerReturn);
28
46
  }
47
+
48
+ /**
49
+ * Build the broker for a message flow with a durable message exchange and message-q.
50
+ * @param {import('./flows/MessageFlow.js').MessageFlow} owner
51
+ * @returns {import('#types').EventBroker<import('./flows/MessageFlow.js').MessageFlow>}
52
+ */
29
53
  function MessageFlowBroker(owner) {
30
54
  const eventBroker = new EventBroker(owner, {
31
55
  prefix: 'messageflow',
@@ -85,10 +109,17 @@ function ExecutionBroker(brokerOwner, prefix, onBrokerReturn) {
85
109
  broker.bindQueue(executionQ.name, 'execution', 'execution.#');
86
110
  return eventBroker;
87
111
  }
112
+
113
+ /**
114
+ * Owns an smqp Broker on behalf of the calling element and exposes prefixed event helpers.
115
+ * @param {any} brokerOwner Element that owns the broker, accessed as `broker.owner`
116
+ * @param {{ prefix: string, autoDelete?: boolean, durable?: boolean }} options
117
+ * @param {(message: import('#types').ElementBrokerMessage) => void} [onBrokerReturn] Override for unrouted return messages
118
+ */
88
119
  function EventBroker(brokerOwner, options, onBrokerReturn) {
89
120
  this.options = options;
90
121
  this.eventPrefix = options.prefix;
91
- const broker = this.broker = (0, _smqp.Broker)(brokerOwner);
122
+ const broker = this.broker = new _smqp.Broker(brokerOwner);
92
123
  broker.assertExchange('event', 'topic', options);
93
124
  broker.on('return', onBrokerReturn ? onBrokerReturn.bind(brokerOwner) : this._onBrokerReturnFn.bind(this));
94
125
  this.on = this.on.bind(this);
@@ -97,6 +128,11 @@ function EventBroker(brokerOwner, options, onBrokerReturn) {
97
128
  this.emit = this.emit.bind(this);
98
129
  this.emitFatal = this.emitFatal.bind(this);
99
130
  }
131
+
132
+ /**
133
+ * Subscribe to a prefixed event. Errors are unwrapped via `makeErrorFromMessage`,
134
+ * other events resolve to the owner's Api wrapper.
135
+ */
100
136
  EventBroker.prototype.on = function on(eventName, callback, eventOptions = {
101
137
  once: false
102
138
  }) {
@@ -111,12 +147,20 @@ EventBroker.prototype.on = function on(eventName, callback, eventOptions = {
111
147
  callback(owner.getApi(message));
112
148
  }
113
149
  };
150
+
151
+ /**
152
+ * Subscribe to the next occurrence of an event.
153
+ */
114
154
  EventBroker.prototype.once = function once(eventName, callback, eventOptions) {
115
155
  return this.on(eventName, callback, {
116
156
  ...eventOptions,
117
157
  once: true
118
158
  });
119
159
  };
160
+
161
+ /**
162
+ * Promise-style wait for an event. Rejects on a mandatory `*.error` message.
163
+ */
120
164
  EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
121
165
  const key = this._getEventRoutingKey(eventName);
122
166
  return new Promise((resolve, reject) => {
@@ -142,6 +186,10 @@ EventBroker.prototype.waitFor = function waitFor(eventName, onMessage) {
142
186
  }
143
187
  });
144
188
  };
189
+
190
+ /**
191
+ * Publish a prefixed event message.
192
+ */
145
193
  EventBroker.prototype.emit = function emit(eventName, content, props) {
146
194
  this.broker.publish('event', `${this.eventPrefix}.${eventName}`, {
147
195
  ...content
@@ -150,6 +198,10 @@ EventBroker.prototype.emit = function emit(eventName, content, props) {
150
198
  ...props
151
199
  });
152
200
  };
201
+
202
+ /**
203
+ * Emit a mandatory error event. Surfaces via `on('error', ...)` or causes a return message to throw.
204
+ */
153
205
  EventBroker.prototype.emitFatal = function emitFatal(error, content) {
154
206
  this.emit('error', {
155
207
  ...content,
@@ -158,12 +210,16 @@ EventBroker.prototype.emitFatal = function emitFatal(error, content) {
158
210
  mandatory: true
159
211
  });
160
212
  };
213
+
214
+ /** @internal */
161
215
  EventBroker.prototype._onBrokerReturnFn = function onBrokerReturnFn(message) {
162
216
  if (message.properties.type === 'error') {
163
217
  const err = (0, _Errors.makeErrorFromMessage)(message);
164
218
  throw err;
165
219
  }
166
220
  };
221
+
222
+ /** @internal */
167
223
  EventBroker.prototype._getEventRoutingKey = function getEventRoutingKey(eventName) {
168
224
  if (eventName.indexOf('.') > -1) return eventName;
169
225
  switch (eventName) {
@@ -3,9 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = Expressions;
7
- var _getPropertyValue = _interopRequireDefault(require("./getPropertyValue.js"));
8
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
6
+ exports.Expressions = Expressions;
7
+ var _getPropertyValue = require("./getPropertyValue.js");
9
8
  const isExpressionPattern = /^\${(.+?)}$/;
10
9
  const expressionPattern = /\${(.+?)}/;
11
10
  function Expressions() {
@@ -30,7 +29,7 @@ function resolveExpression(templatedString, context, expressionFnContext) {
30
29
  const n = Number(innerProperty);
31
30
  if (!isNaN(n)) return n;
32
31
  }
33
- const contextValue = (0, _getPropertyValue.default)(context, innerProperty, expressionFnContext);
32
+ const contextValue = (0, _getPropertyValue.getPropertyValue)(context, innerProperty, expressionFnContext);
34
33
  if (expressionMatch.input === expressionMatch[0]) {
35
34
  return contextValue;
36
35
  }
@@ -8,13 +8,15 @@ var _messageHelper = require("./messageHelper.js");
8
8
  var _shared = require("./shared.js");
9
9
  var _Errors = require("./error/Errors.js");
10
10
  var _smqp = require("smqp");
11
- const kOnMessage = Symbol.for('onMessage');
12
- const kExecution = Symbol.for('execution');
11
+ var _constants = require("./constants.js");
12
+ const K_ON_MESSAGE = Symbol.for('onMessage');
13
13
  const EXEC_ROUTING_KEY = 'run._formatting.exec';
14
14
 
15
15
  /**
16
- * Message formatter used to enrich an element run message before continuing to the next run message
17
- * @param {import('types').ElementBase} element
16
+ * Enriches an element run message via async format start/end messages on the `format` exchange
17
+ * before the run message is continued. Handlers publish enrichment by responding to a start
18
+ * message with a matching end (or error) routing key.
19
+ * @param {import('#types').ElementBase} element
18
20
  */
19
21
  function Formatter(element) {
20
22
  const {
@@ -25,13 +27,14 @@ function Formatter(element) {
25
27
  this.id = id;
26
28
  this.broker = broker;
27
29
  this.logger = logger;
28
- this[kOnMessage] = this._onMessage.bind(this);
30
+ this[K_ON_MESSAGE] = this._onMessage.bind(this);
29
31
  }
30
32
 
31
33
  /**
32
- * Format message
33
- * @param {import('types').ElementBrokerMessage} message
34
- * @param {CallableFunction} callback
34
+ * Format the given run message. Callback fires with `(err, content, formatted)` once
35
+ * formatting completes; `formatted` is true when content was actually enriched.
36
+ * @param {import('#types').ElementBrokerMessage} message
37
+ * @param {(err: Error | null, content?: import('#types').ElementMessageContent, formatted?: boolean) => void} callback
35
38
  */
36
39
  Formatter.prototype.format = function format(message, callback) {
37
40
  const correlationId = this._runId = (0, _shared.getUniqueId)(message.fields.routingKey);
@@ -41,7 +44,7 @@ Formatter.prototype.format = function format(message, callback) {
41
44
  correlationId,
42
45
  persistent: false
43
46
  });
44
- this[kExecution] = {
47
+ this[_constants.K_EXECUTION] = {
45
48
  correlationId,
46
49
  formatKey: message.fields.routingKey,
47
50
  runMessage: (0, _messageHelper.cloneMessage)(message),
@@ -50,18 +53,20 @@ Formatter.prototype.format = function format(message, callback) {
50
53
  formatted: false,
51
54
  executeMessage: null
52
55
  };
53
- broker.consume('format-run-q', this[kOnMessage], {
56
+ broker.consume('format-run-q', this[K_ON_MESSAGE], {
54
57
  consumerTag,
55
58
  prefetch: 100
56
59
  });
57
60
  };
61
+
62
+ /** @internal */
58
63
  Formatter.prototype._onMessage = function onMessage(routingKey, message) {
59
64
  const {
60
65
  formatKey,
61
66
  correlationId,
62
67
  pending,
63
68
  executeMessage
64
- } = this[kExecution];
69
+ } = this[_constants.K_EXECUTION];
65
70
  const asyncFormatting = pending.size;
66
71
  if (routingKey === EXEC_ROUTING_KEY) {
67
72
  if (message.properties.correlationId !== correlationId) return message.ack();
@@ -69,7 +74,7 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
69
74
  if (!asyncFormatting) {
70
75
  return this._complete(message);
71
76
  }
72
- this[kExecution].executeMessage = message;
77
+ this[_constants.K_EXECUTION].executeMessage = message;
73
78
  } else {
74
79
  message.ack();
75
80
  const endRoutingKey = message.content?.endRoutingKey;
@@ -91,6 +96,8 @@ Formatter.prototype._onMessage = function onMessage(routingKey, message) {
91
96
  }
92
97
  }
93
98
  };
99
+
100
+ /** @internal */
94
101
  Formatter.prototype._complete = function complete(message, isError) {
95
102
  const {
96
103
  runMessage,
@@ -98,8 +105,8 @@ Formatter.prototype._complete = function complete(message, isError) {
98
105
  callback,
99
106
  formatted,
100
107
  executeMessage
101
- } = this[kExecution];
102
- this[kExecution] = null;
108
+ } = this[_constants.K_EXECUTION];
109
+ this[_constants.K_EXECUTION] = null;
103
110
  if (executeMessage) executeMessage.ack();
104
111
  this.broker.cancel(message.fields.consumerTag);
105
112
  if (isError) {
@@ -110,8 +117,10 @@ Formatter.prototype._complete = function complete(message, isError) {
110
117
  }
111
118
  return callback(null, runMessage.content, formatted);
112
119
  };
120
+
121
+ /** @internal */
113
122
  Formatter.prototype._enrich = function enrich(withContent) {
114
- const content = this[kExecution].runMessage.content;
123
+ const content = this[_constants.K_EXECUTION].runMessage.content;
115
124
  for (const key in withContent) {
116
125
  switch (key) {
117
126
  case 'id':
@@ -129,11 +138,13 @@ Formatter.prototype._enrich = function enrich(withContent) {
129
138
  default:
130
139
  {
131
140
  content[key] = withContent[key];
132
- this[kExecution].formatted = true;
141
+ this[_constants.K_EXECUTION].formatted = true;
133
142
  }
134
143
  }
135
144
  }
136
145
  };
146
+
147
+ /** @internal */
137
148
  Formatter.prototype._popFormatStart = function popFormattingStart(pending, routingKey) {
138
149
  for (const msg of pending) {
139
150
  const {
@@ -156,6 +167,8 @@ Formatter.prototype._popFormatStart = function popFormattingStart(pending, routi
156
167
  }
157
168
  return {};
158
169
  };
170
+
171
+ /** @internal */
159
172
  Formatter.prototype._debug = function debug(msg) {
160
173
  this.logger.debug(`<${this.id}> ${msg}`);
161
174
  };
package/dist/Timers.js CHANGED
@@ -4,9 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Timers = Timers;
7
- const kExecuting = Symbol.for('executing');
8
- const kTimerApi = Symbol.for('timers api');
7
+ const K_EXECUTING = Symbol.for('executing');
8
+ const K_TIMER_API = Symbol.for('timers api');
9
9
  const MAX_DELAY = 2147483647;
10
+
11
+ /**
12
+ * @param {import('#types').TimersOptions} options
13
+ */
10
14
  function Timers(options) {
11
15
  this.count = 0;
12
16
  this.options = {
@@ -14,13 +18,13 @@ function Timers(options) {
14
18
  clearTimeout,
15
19
  ...options
16
20
  };
17
- this[kExecuting] = new Set();
21
+ this[K_EXECUTING] = new Set();
18
22
  this.setTimeout = this.setTimeout.bind(this);
19
23
  this.clearTimeout = this.clearTimeout.bind(this);
20
24
  }
21
25
  Object.defineProperty(Timers.prototype, 'executing', {
22
26
  get() {
23
- return [...this[kExecuting]];
27
+ return [...this[K_EXECUTING]];
24
28
  }
25
29
  });
26
30
  Timers.prototype.register = function register(owner) {
@@ -30,14 +34,14 @@ Timers.prototype.setTimeout = function wrappedSetTimeout(callback, delay, ...arg
30
34
  return this._setTimeout(null, callback, delay, ...args);
31
35
  };
32
36
  Timers.prototype.clearTimeout = function wrappedClearTimeout(ref) {
33
- if (this[kExecuting].delete(ref)) {
37
+ if (this[K_EXECUTING].delete(ref)) {
34
38
  ref.timerRef = this.options.clearTimeout(ref.timerRef);
35
39
  return;
36
40
  }
37
41
  return this.options.clearTimeout(ref);
38
42
  };
39
43
  Timers.prototype._setTimeout = function setTimeout(owner, callback, delay, ...args) {
40
- const executing = this[kExecuting];
44
+ const executing = this[K_EXECUTING];
41
45
  const ref = this._getReference(owner, callback, delay, args);
42
46
  executing.add(ref);
43
47
  if (delay < MAX_DELAY) {
@@ -53,17 +57,17 @@ Timers.prototype._getReference = function getReference(owner, callback, delay, a
53
57
  return new Timer(owner, `timer_${this.count++}`, callback, delay, args);
54
58
  };
55
59
  function RegisteredTimers(timersApi, owner) {
56
- this[kTimerApi] = timersApi;
60
+ this[K_TIMER_API] = timersApi;
57
61
  this.owner = owner;
58
62
  this.setTimeout = this.setTimeout.bind(this);
59
63
  this.clearTimeout = this.clearTimeout.bind(this);
60
64
  }
61
65
  RegisteredTimers.prototype.setTimeout = function registeredSetTimeout(callback, delay, ...args) {
62
- const timersApi = this[kTimerApi];
66
+ const timersApi = this[K_TIMER_API];
63
67
  return timersApi._setTimeout(this.owner, callback, delay, ...args);
64
68
  };
65
69
  RegisteredTimers.prototype.clearTimeout = function registeredClearTimeout(ref) {
66
- this[kTimerApi].clearTimeout(ref);
70
+ this[K_TIMER_API].clearTimeout(ref);
67
71
  };
68
72
  function Timer(owner, timerId, callback, delay, args) {
69
73
  this.callback = callback;
package/dist/Tracker.js CHANGED
@@ -36,6 +36,7 @@ ActivityTracker.prototype.track = function track(routingKey, message) {
36
36
  this._executing(executionId);
37
37
  break;
38
38
  case 'activity.execution.outbound.take':
39
+ case 'activity.converge':
39
40
  case 'activity.detach':
40
41
  case 'activity.call':
41
42
  case 'activity.wait':