arvo-event-handler 3.0.3 → 3.0.4
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.
- package/README.md +65 -65
- package/dist/ArvoDomain.d.ts +57 -0
- package/dist/ArvoDomain.js +71 -0
- package/dist/ArvoEventHandler/helpers.d.ts +15 -26
- package/dist/ArvoEventHandler/helpers.js +15 -26
- package/dist/ArvoEventHandler/index.d.ts +64 -55
- package/dist/ArvoEventHandler/index.js +92 -66
- package/dist/ArvoEventHandler/types.d.ts +34 -12
- package/dist/ArvoMachine/types.d.ts +20 -12
- package/dist/ArvoOrchestrator/factory.d.ts +3 -2
- package/dist/ArvoOrchestrator/factory.js +4 -2
- package/dist/ArvoOrchestrator/index.d.ts +3 -8
- package/dist/ArvoOrchestrator/index.js +55 -27
- package/dist/ArvoOrchestrator/types.d.ts +18 -0
- package/dist/ArvoResumable/factory.d.ts +2 -10
- package/dist/ArvoResumable/factory.js +2 -10
- package/dist/ArvoResumable/index.d.ts +3 -34
- package/dist/ArvoResumable/index.js +59 -55
- package/dist/ArvoResumable/types.d.ts +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/package.json +1 -1
|
@@ -81,77 +81,86 @@ var arvo_core_1 = require("arvo-core");
|
|
|
81
81
|
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
82
82
|
var errors_1 = require("../errors");
|
|
83
83
|
var utils_1 = require("../utils");
|
|
84
|
+
var ArvoDomain_1 = require("../ArvoDomain");
|
|
84
85
|
/**
|
|
85
|
-
* ArvoEventHandler is the
|
|
86
|
-
*
|
|
86
|
+
* `ArvoEventHandler` is the foundational component for building stateless,
|
|
87
|
+
* contract-bound services in the Arvo system.
|
|
87
88
|
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* in its contract, or it will fail both at compile time and runtime.
|
|
89
|
+
* It enforces strict contract validation, version-aware handler resolution,
|
|
90
|
+
* and safe, observable event emission — all while maintaining type safety,
|
|
91
|
+
* traceability, and support for multi-domain workflows.
|
|
92
92
|
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
93
|
+
* ## What It Does
|
|
94
|
+
* - Ensures incoming events match the contract's `type` and `dataschema`
|
|
95
|
+
* - Resolves the correct contract version using `dataschema`
|
|
96
|
+
* - Validates input and output data via Zod schemas
|
|
97
|
+
* - Executes the version-specific handler function
|
|
98
|
+
* - Emits one or more response events based on the handler result
|
|
99
|
+
* - Supports multi-domain broadcasting via `domain[]` on the emitted events
|
|
100
|
+
* - Automatically emits system error events (`sys.*.error`) on failure
|
|
101
|
+
* - Integrates deeply with OpenTelemetry for tracing and observability
|
|
97
102
|
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
* ensures all conditions are met before and after processing.
|
|
103
|
+
* ## Error Boundaries
|
|
104
|
+
* ArvoEventHandler enforces a clear separation between:
|
|
101
105
|
*
|
|
102
|
-
*
|
|
106
|
+
* - **Violations** — structural, schema, or config errors that break the contract.
|
|
107
|
+
* These are thrown and must be handled explicitly by the caller.
|
|
103
108
|
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
* 3. **Schema Validation**: Validates event data against the contract's accepts schema
|
|
107
|
-
* 4. **Handler Execution**: Invokes the version-specific handler implementation
|
|
108
|
-
* 5. **Response Processing**: Validates and structures handler output into events
|
|
109
|
-
* 6. **Domain Broadcasting**: Creates multiple events for multi-domain distribution if specified
|
|
110
|
-
* 7. **Routing Configuration**: Applies routing logic based on handler output and event context
|
|
111
|
-
* 8. **Telemetry Integration**: Records processing metrics and tracing information
|
|
109
|
+
* - **System Errors** — runtime exceptions during execution that are caught and
|
|
110
|
+
* emitted as standardized `sys.<contract>.error` events.
|
|
112
111
|
*
|
|
113
|
-
* ##
|
|
112
|
+
* ## Domain Broadcasting
|
|
113
|
+
* The handler supports multi-domain event distribution. When the handler
|
|
114
|
+
* returns an event with a `domain` array, it is broadcast to one or more
|
|
115
|
+
* routing contexts.
|
|
114
116
|
*
|
|
115
|
-
*
|
|
117
|
+
* ### System Error Domain Control
|
|
118
|
+
* By default, system error events are broadcast into the source event’s domain,
|
|
119
|
+
* the handler’s contract domain, and the `null` domain. This fallback ensures errors
|
|
120
|
+
* are visible across all relevant contexts. Developers can override this behavior
|
|
121
|
+
* using the optional `systemErrorDomain` field to specify an explicit set of
|
|
122
|
+
* domain values, including symbolic constants from {@link ArvoDomain}.
|
|
116
123
|
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
124
|
+
* ### Supported Domain Values:
|
|
125
|
+
* - A **concrete domain string** like `'audit.orders'` or `'human.review'`
|
|
126
|
+
* - `null` to emit with no domain (standard internal flow)
|
|
127
|
+
* - A **symbolic reference** from {@link ArvoDomain}
|
|
121
128
|
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
* processing contexts (source event domain, handler contract domain, and null domain).
|
|
129
|
+
* ### Domain Resolution Rules:
|
|
130
|
+
* - Each item in the `domain` array is resolved via {@link resolveEventDomain}
|
|
131
|
+
* - Duplicate domains are deduplicated before emitting
|
|
132
|
+
* - If `domain` is omitted entirely, Arvo defaults to `[null]`
|
|
127
133
|
*
|
|
128
|
-
*
|
|
134
|
+
* ### Example:
|
|
135
|
+
* ```ts
|
|
136
|
+
* return {
|
|
137
|
+
* type: 'evt.user.registered',
|
|
138
|
+
* data: { ... },
|
|
139
|
+
* domain: ['analytics', ArvoDomain.FROM_TRIGGERING_EVENT, null]
|
|
140
|
+
* };
|
|
141
|
+
* ```
|
|
142
|
+
* This would emit at most 3 copies of the event, domained to:
|
|
143
|
+
* - `'analytics'`
|
|
144
|
+
* - the domain of the incoming event
|
|
145
|
+
* - no domain (default)
|
|
129
146
|
*
|
|
130
|
-
*
|
|
147
|
+
* ### Domain Usage Guidance
|
|
131
148
|
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* 2. **Undefined Resolution**: `undefined` elements resolve to: `event.domain ?? handler.contract.domain ?? null`
|
|
135
|
-
* 3. **Automatic Deduplication**: Duplicate domains are removed to prevent redundant events
|
|
136
|
-
* 4. **Default Behavior**: Omitted/undefined `domain` field defaults to `[null]` (single event, no domain)
|
|
149
|
+
* > **Avoid setting `contract.domain` unless fully intentional.**
|
|
150
|
+
* 99% emitted event should default to `null` (standard processing pipeline).
|
|
137
151
|
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* - `domain: ['analytics', undefined, null]` → Creates up to 3 events:
|
|
141
|
-
* - Event with `domain: 'analytics'`
|
|
142
|
-
* - Event with `domain: event.domain ?? handler.contract.domain ?? null`
|
|
143
|
-
* - Event with `domain: null`
|
|
144
|
-
* - `domain: [null]` → Single event with explicit no-domain routing
|
|
145
|
-
* - `domain: undefined` (or omitted) → Single event with `domain: null`
|
|
152
|
+
* Contract-level domains enforce implicit routing for every emitted event
|
|
153
|
+
* in that handler, making the behavior harder to override and debug.
|
|
146
154
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* -
|
|
150
|
-
* - Handler contract domain (`handler.contract.domain`)
|
|
151
|
-
* - No-domain context (`null`)
|
|
155
|
+
* Prefer:
|
|
156
|
+
* - Explicit per-event `domain` values in handler output
|
|
157
|
+
* - Using `null` or symbolic constants to control domain cleanly
|
|
152
158
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
159
|
+
* ## When to Use Domains
|
|
160
|
+
* Use domains when handling for specialized contexts:
|
|
161
|
+
* - `'human.review'` → for human-in-the-loop steps
|
|
162
|
+
* - `'analytics.workflow'` → to pipe events into observability systems
|
|
163
|
+
* - `'external.partner.sync'` → to route to external services
|
|
155
164
|
*/
|
|
156
165
|
var ArvoEventHandler = /** @class */ (function (_super) {
|
|
157
166
|
__extends(ArvoEventHandler, _super);
|
|
@@ -169,9 +178,11 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
169
178
|
var _a;
|
|
170
179
|
var _b, _c;
|
|
171
180
|
var _this = _super.call(this) || this;
|
|
181
|
+
_this.systemErrorDomain = undefined;
|
|
172
182
|
_this.contract = param.contract;
|
|
173
183
|
_this.executionunits = param.executionunits;
|
|
174
184
|
_this.handler = param.handler;
|
|
185
|
+
_this.systemErrorDomain = param.systemErrorDomain;
|
|
175
186
|
for (var _i = 0, _d = Object.keys(_this.contract.versions); _i < _d.length; _i++) {
|
|
176
187
|
var contractVersions = _d[_i];
|
|
177
188
|
if (!_this.handler[contractVersions]) {
|
|
@@ -231,7 +242,7 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
231
242
|
case 0:
|
|
232
243
|
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)("Handler<".concat(this.contract.uri, ">"), this.spanOptions, opentelemetry, event);
|
|
233
244
|
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
234
|
-
var otelSpanHeaders, _i, _a, _b, key, value, parsedDataSchema,
|
|
245
|
+
var otelSpanHeaders, _i, _a, _b, key, value, parsedDataSchema, handlerContract_1, inputEventValidation, _handleOutput, outputs, result, _c, outputs_1, item, __extensions, handlerResult, domains, _d, _e, _dom, _f, _g, _h, key, value, error_1, result, _j, _k, _dom, _l, _m, _o, key, value;
|
|
235
246
|
var _this = this;
|
|
236
247
|
var _p, _q, _r, _s, _t, _u, _v, _w, _x, _y;
|
|
237
248
|
return __generator(this, function (_z) {
|
|
@@ -266,33 +277,32 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
266
277
|
message: "Version resolution failed for event with dataschema '".concat(event.dataschema, "'. Defaulting to latest version (=").concat(this.contract.version('latest').version, ") of contract (uri=").concat(this.contract.uri, ")"),
|
|
267
278
|
});
|
|
268
279
|
}
|
|
269
|
-
handlerContract = void 0;
|
|
270
280
|
try {
|
|
271
|
-
|
|
281
|
+
handlerContract_1 = this.contract.version((_p = parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version) !== null && _p !== void 0 ? _p : 'latest');
|
|
272
282
|
}
|
|
273
283
|
catch (_0) {
|
|
274
284
|
throw new errors_1.ConfigViolation("Invalid contract version: ".concat(parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version, ". Available versions: ").concat(Object.keys(this.contract.versions).join(', ')));
|
|
275
285
|
}
|
|
276
286
|
(0, arvo_core_1.logToSpan)({
|
|
277
287
|
level: 'INFO',
|
|
278
|
-
message: "Processing event with contract version ".concat(
|
|
288
|
+
message: "Processing event with contract version ".concat(handlerContract_1.version),
|
|
279
289
|
});
|
|
280
|
-
inputEventValidation =
|
|
290
|
+
inputEventValidation = handlerContract_1.accepts.schema.safeParse(event.data);
|
|
281
291
|
if (inputEventValidation.error) {
|
|
282
292
|
throw new errors_1.ContractViolation("Input event payload validation failed: ".concat(inputEventValidation.error));
|
|
283
293
|
}
|
|
284
294
|
(0, arvo_core_1.logToSpan)({
|
|
285
295
|
level: 'INFO',
|
|
286
|
-
message: "Event payload validated successfully against contract ".concat(arvo_core_1.EventDataschemaUtil.create(
|
|
296
|
+
message: "Event payload validated successfully against contract ".concat(arvo_core_1.EventDataschemaUtil.create(handlerContract_1)),
|
|
287
297
|
});
|
|
288
298
|
(0, arvo_core_1.logToSpan)({
|
|
289
299
|
level: 'INFO',
|
|
290
300
|
message: "Executing handler for event type '".concat(event.type, "'"),
|
|
291
301
|
});
|
|
292
|
-
return [4 /*yield*/, this.handler[
|
|
302
|
+
return [4 /*yield*/, this.handler[handlerContract_1.version]({
|
|
293
303
|
event: event.toJSON(),
|
|
294
304
|
source: this.source,
|
|
295
|
-
contract:
|
|
305
|
+
contract: handlerContract_1,
|
|
296
306
|
domain: {
|
|
297
307
|
self: this.domain,
|
|
298
308
|
event: event.domain,
|
|
@@ -317,10 +327,17 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
317
327
|
item = outputs_1[_c];
|
|
318
328
|
try {
|
|
319
329
|
__extensions = item.__extensions, handlerResult = __rest(item, ["__extensions"]);
|
|
320
|
-
domains = (_r = (_q = handlerResult.domain) === null || _q === void 0 ? void 0 : _q.map(function (item) {
|
|
330
|
+
domains = (_r = (_q = handlerResult.domain) === null || _q === void 0 ? void 0 : _q.map(function (item) {
|
|
331
|
+
return (0, ArvoDomain_1.resolveEventDomain)({
|
|
332
|
+
domainToResolve: item,
|
|
333
|
+
handlerSelfContract: handlerContract_1,
|
|
334
|
+
eventContract: handlerContract_1,
|
|
335
|
+
triggeringEvent: event,
|
|
336
|
+
});
|
|
337
|
+
})) !== null && _r !== void 0 ? _r : [null];
|
|
321
338
|
for (_d = 0, _e = Array.from(new Set(domains)); _d < _e.length; _d++) {
|
|
322
339
|
_dom = _e[_d];
|
|
323
|
-
result.push((0, arvo_core_1.createArvoEventFactory)(
|
|
340
|
+
result.push((0, arvo_core_1.createArvoEventFactory)(handlerContract_1).emits(__assign(__assign({}, handlerResult), { traceparent: otelSpanHeaders.traceparent || undefined, tracestate: otelSpanHeaders.tracestate || undefined, source: this.source, subject: event.subject,
|
|
324
341
|
// 'source'
|
|
325
342
|
// prioritise returned 'to', 'redirectto' and then
|
|
326
343
|
to: (0, utils_1.coalesceOrDefault)([handlerResult.to, event.redirectto], event.source), executionunits: (0, utils_1.coalesce)(handlerResult.executionunits, this.executionunits), accesscontrol: (_t = (_s = handlerResult.accesscontrol) !== null && _s !== void 0 ? _s : event.accesscontrol) !== null && _t !== void 0 ? _t : undefined, parentid: event.id, domain: _dom }), __extensions));
|
|
@@ -356,7 +373,16 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
356
373
|
throw error_1;
|
|
357
374
|
}
|
|
358
375
|
result = [];
|
|
359
|
-
for (_j = 0, _k = Array.from(new Set(
|
|
376
|
+
for (_j = 0, _k = Array.from(new Set(this.systemErrorDomain
|
|
377
|
+
? this.systemErrorDomain.map(function (item) {
|
|
378
|
+
return (0, ArvoDomain_1.resolveEventDomain)({
|
|
379
|
+
domainToResolve: item,
|
|
380
|
+
handlerSelfContract: _this.contract.version('latest'),
|
|
381
|
+
eventContract: _this.contract.version('latest'),
|
|
382
|
+
triggeringEvent: event,
|
|
383
|
+
});
|
|
384
|
+
})
|
|
385
|
+
: [event.domain, this.domain, null])); _j < _k.length; _j++) {
|
|
360
386
|
_dom = _k[_j];
|
|
361
387
|
result.push((0, arvo_core_1.createArvoEventFactory)(this.contract.version('latest')).systemError({
|
|
362
388
|
source: this.source,
|
|
@@ -35,21 +35,29 @@ export type ArvoEventHandlerFunctionOutput<TContract extends VersionedArvoContra
|
|
|
35
35
|
/** Optional extensions for the event. */
|
|
36
36
|
__extensions?: Record<string, string | number | boolean>;
|
|
37
37
|
/**
|
|
38
|
-
* The
|
|
38
|
+
* The domain configuration for multi-domain event broadcasting.
|
|
39
39
|
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* - Duplicate domains are automatically removed to prevent redundant events
|
|
44
|
-
* - Omitting this field (or setting to `undefined`) defaults to `[null]`
|
|
40
|
+
* When an event is emitted with a `domain` array, Arvo generates a separate ArvoEvent
|
|
41
|
+
* for each resolved domain value. This enables parallel routing to multiple contexts
|
|
42
|
+
* such as analytics, auditing, human-in-the-loop systems, or external integrations.
|
|
45
43
|
*
|
|
46
|
-
* **
|
|
47
|
-
* -
|
|
48
|
-
* - `
|
|
49
|
-
* -
|
|
50
|
-
*
|
|
44
|
+
* **Accepted Values:**
|
|
45
|
+
* - A concrete domain string (e.g. `'audit.orders'`)
|
|
46
|
+
* - `null` for standard internal routing (no domain)
|
|
47
|
+
* - A symbolic value from {@link ArvoDomain}.
|
|
48
|
+
*
|
|
49
|
+
* **Broadcasting Rules:**
|
|
50
|
+
* - Each resolved domain in the array creates a separate ArvoEvent instance
|
|
51
|
+
* - Duplicate resolved domains are automatically removed
|
|
52
|
+
* - If the field is omitted, Arvo defaults to `[null]`
|
|
53
|
+
*
|
|
54
|
+
* **Examples:**
|
|
55
|
+
* - `['analytics.orders', 'audit.orders']` → Creates two routed events
|
|
56
|
+
* - `[ArvoDomain.FROM_TRIGGERING_EVENT, 'human.review', null]` → Mirrors source domain, routes to review, and standard consumer
|
|
57
|
+
* - `[null]` → Emits a single event with no domain routing
|
|
58
|
+
* - _Omitted_ → Same as `[null]`
|
|
51
59
|
*/
|
|
52
|
-
domain?: (string |
|
|
60
|
+
domain?: (string | null)[];
|
|
53
61
|
};
|
|
54
62
|
}[keyof TContract['emits']];
|
|
55
63
|
/**
|
|
@@ -81,4 +89,18 @@ export interface IArvoEventHandler<TContract extends ArvoContract> {
|
|
|
81
89
|
* The OpenTelemetry span options
|
|
82
90
|
*/
|
|
83
91
|
spanOptions?: SpanOptions;
|
|
92
|
+
/**
|
|
93
|
+
* Optional configuration to customize where system error events are emitted.
|
|
94
|
+
*
|
|
95
|
+
* This overrides the default system error domain fallback of:
|
|
96
|
+
* `[event.domain, handler.contract.domain, null]`
|
|
97
|
+
*
|
|
98
|
+
* Use this to precisely control the set of domains that should receive structured
|
|
99
|
+
* `sys.*.error` events when uncaught exceptions occur in the handler.
|
|
100
|
+
*
|
|
101
|
+
* Symbolic constants from {@link ArvoDomain} are supported.
|
|
102
|
+
*
|
|
103
|
+
* @default undefined — uses standard fallback broadcast domains
|
|
104
|
+
*/
|
|
105
|
+
systemErrorDomain?: (string | null)[];
|
|
84
106
|
}
|
|
@@ -36,21 +36,29 @@ export type ArvoMachineContext = {
|
|
|
36
36
|
*/
|
|
37
37
|
export type EnqueueArvoEventActionParam<TData extends ArvoEventData = ArvoEventData, TType extends string = string, TExtension extends CloudEventExtension = CloudEventExtension> = {
|
|
38
38
|
/**
|
|
39
|
-
* The
|
|
39
|
+
* The domain configuration for multi-domain event broadcasting.
|
|
40
40
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* - Duplicate domains are automatically removed to prevent redundant events
|
|
45
|
-
* - Omitting this field (or setting to `undefined`) defaults to `[null]`
|
|
41
|
+
* When an event is emitted with a `domain` array, Arvo generates a separate ArvoEvent
|
|
42
|
+
* for each resolved domain value. This enables parallel routing to multiple contexts
|
|
43
|
+
* such as analytics, auditing, human-in-the-loop systems, or external integrations.
|
|
46
44
|
*
|
|
47
|
-
* **
|
|
48
|
-
* -
|
|
49
|
-
* - `
|
|
50
|
-
* -
|
|
51
|
-
*
|
|
45
|
+
* **Accepted Values:**
|
|
46
|
+
* - A concrete domain string (e.g. `'audit.orders'`)
|
|
47
|
+
* - `null` for standard internal routing (no domain)
|
|
48
|
+
* - A symbolic value from {@link ArvoDomain}.
|
|
49
|
+
*
|
|
50
|
+
* **Broadcasting Rules:**
|
|
51
|
+
* - Each resolved domain in the array creates a separate ArvoEvent instance
|
|
52
|
+
* - Duplicate resolved domains are automatically removed
|
|
53
|
+
* - If the field is omitted, Arvo defaults to `[null]`
|
|
54
|
+
*
|
|
55
|
+
* **Examples:**
|
|
56
|
+
* - `['analytics.orders', 'audit.orders']` → Creates two routed events
|
|
57
|
+
* - `[ArvoDomain.FROM_TRIGGERING_EVENT, 'human.review', null]` → Mirrors source domain, routes to review, and standard consumer
|
|
58
|
+
* - `[null]` → Emits a single event with no domain routing
|
|
59
|
+
* - _Omitted_ → Same as `[null]`
|
|
52
60
|
*/
|
|
53
|
-
domain?: (string | null
|
|
61
|
+
domain?: (string | null)[];
|
|
54
62
|
/**
|
|
55
63
|
* Custom extensions for the CloudEvent.
|
|
56
64
|
* Allows for additional metadata to be attached to the event.
|
|
@@ -8,6 +8,7 @@ import type { ICreateArvoOrchestrator } from './types';
|
|
|
8
8
|
* @param config.memory - State persistence interface for storing machine states
|
|
9
9
|
* @param config.executionunits - Cost units for execution tracking
|
|
10
10
|
* @param config.machines - Array of state machines to manage. Their resource locking flags determine orchestrator's locking behavior
|
|
11
|
+
* @param config.systemErrorDomain - An optional array of system error domain overrides
|
|
11
12
|
* @returns Configured ArvoOrchestrator instance with default registry and execution engine
|
|
12
13
|
*
|
|
13
14
|
* @remarks
|
|
@@ -19,10 +20,10 @@ import type { ICreateArvoOrchestrator } from './types';
|
|
|
19
20
|
* @example
|
|
20
21
|
* ```typescript
|
|
21
22
|
* const orchestrator = createArvoOrchestrator({
|
|
22
|
-
* memory: new
|
|
23
|
+
* memory: new SimpleMachineMemory() // or, any other IMachineMemory implementation,
|
|
23
24
|
* executionunits: 1,
|
|
24
25
|
* machines: [machineA, machineB]
|
|
25
26
|
* });
|
|
26
27
|
* ```
|
|
27
28
|
*/
|
|
28
|
-
export declare const createArvoOrchestrator: ({ executionunits, memory, machines, }: ICreateArvoOrchestrator) => ArvoOrchestrator;
|
|
29
|
+
export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, }: ICreateArvoOrchestrator) => ArvoOrchestrator;
|
|
@@ -21,6 +21,7 @@ var MachineRegistry_1 = require("../MachineRegistry");
|
|
|
21
21
|
* @param config.memory - State persistence interface for storing machine states
|
|
22
22
|
* @param config.executionunits - Cost units for execution tracking
|
|
23
23
|
* @param config.machines - Array of state machines to manage. Their resource locking flags determine orchestrator's locking behavior
|
|
24
|
+
* @param config.systemErrorDomain - An optional array of system error domain overrides
|
|
24
25
|
* @returns Configured ArvoOrchestrator instance with default registry and execution engine
|
|
25
26
|
*
|
|
26
27
|
* @remarks
|
|
@@ -32,14 +33,14 @@ var MachineRegistry_1 = require("../MachineRegistry");
|
|
|
32
33
|
* @example
|
|
33
34
|
* ```typescript
|
|
34
35
|
* const orchestrator = createArvoOrchestrator({
|
|
35
|
-
* memory: new
|
|
36
|
+
* memory: new SimpleMachineMemory() // or, any other IMachineMemory implementation,
|
|
36
37
|
* executionunits: 1,
|
|
37
38
|
* machines: [machineA, machineB]
|
|
38
39
|
* });
|
|
39
40
|
* ```
|
|
40
41
|
*/
|
|
41
42
|
var createArvoOrchestrator = function (_a) {
|
|
42
|
-
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines;
|
|
43
|
+
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain;
|
|
43
44
|
if (!(machines === null || machines === void 0 ? void 0 : machines.length)) {
|
|
44
45
|
throw new Error('At least one machine must be provided');
|
|
45
46
|
}
|
|
@@ -51,6 +52,7 @@ var createArvoOrchestrator = function (_a) {
|
|
|
51
52
|
registry: registry,
|
|
52
53
|
executionEngine: new MachineExecutionEngine_1.MachineExecutionEngine(),
|
|
53
54
|
requiresResourceLocking: requiresResourceLocking,
|
|
55
|
+
systemErrorDomain: systemErrorDomain,
|
|
54
56
|
});
|
|
55
57
|
};
|
|
56
58
|
exports.createArvoOrchestrator = createArvoOrchestrator;
|
|
@@ -17,6 +17,7 @@ export declare class ArvoOrchestrator extends AbstractArvoEventHandler {
|
|
|
17
17
|
readonly registry: IMachineRegistry;
|
|
18
18
|
readonly executionEngine: IMachineExectionEngine;
|
|
19
19
|
readonly syncEventResource: SyncEventResource<MachineMemoryRecord>;
|
|
20
|
+
readonly systemErrorDomain?: (string | null)[];
|
|
20
21
|
get source(): any;
|
|
21
22
|
get requiresResourceLocking(): boolean;
|
|
22
23
|
get memory(): IMachineMemory<MachineMemoryRecord>;
|
|
@@ -26,7 +27,7 @@ export declare class ArvoOrchestrator extends AbstractArvoEventHandler {
|
|
|
26
27
|
* @param params - Configuration parameters
|
|
27
28
|
* @throws Error if machines in registry have different sources
|
|
28
29
|
*/
|
|
29
|
-
constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking }: IArvoOrchestrator);
|
|
30
|
+
constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, }: IArvoOrchestrator);
|
|
30
31
|
/**
|
|
31
32
|
* Creates emittable event from execution result
|
|
32
33
|
* @param event - Source event to emit
|
|
@@ -40,15 +41,9 @@ export declare class ArvoOrchestrator extends AbstractArvoEventHandler {
|
|
|
40
41
|
* @throws {ContractViolation} On schema/contract mismatch
|
|
41
42
|
* @throws {ExecutionViolation} On invalid parentSubject$$ format
|
|
42
43
|
*/
|
|
43
|
-
protected createEmittableEvent(event: EnqueueArvoEventActionParam, machine: ArvoMachine<any, any, any, any, any>, otelHeaders: OpenTelemetryHeaders, orchestrationParentSubject: string | null, sourceEvent: ArvoEvent, initEventId: string, _domain: string | null
|
|
44
|
+
protected createEmittableEvent(event: EnqueueArvoEventActionParam, machine: ArvoMachine<any, any, any, any, any>, otelHeaders: OpenTelemetryHeaders, orchestrationParentSubject: string | null, sourceEvent: ArvoEvent, initEventId: string, _domain: string | null): ArvoEvent;
|
|
44
45
|
/**
|
|
45
46
|
* Core orchestration method that executes state machines in response to events.
|
|
46
|
-
* Manages the complete event lifecycle:
|
|
47
|
-
* 1. Acquires lock and state
|
|
48
|
-
* 2. Validates events and contracts
|
|
49
|
-
* 3. Executes state machine
|
|
50
|
-
* 4. Persists new state
|
|
51
|
-
* 5. Generates response events with domain-based segregation
|
|
52
47
|
*
|
|
53
48
|
* @param event - Event triggering the execution
|
|
54
49
|
* @param opentelemetry - OpenTelemetry configuration
|