arvo-event-handler 3.0.23 → 3.0.26

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.
@@ -69,16 +69,14 @@ var ArvoDomain_1 = require("../ArvoDomain");
69
69
  var ArvoResumable = /** @class */ (function () {
70
70
  function ArvoResumable(param) {
71
71
  var _a;
72
- var _b, _c, _d;
73
- /** Optional domains for routing system error events */
74
- this.systemErrorDomain = undefined;
72
+ var _b, _c, _d, _e;
75
73
  this.executionunits = param.executionunits;
76
74
  this.source = param.contracts.self.type;
77
75
  this.syncEventResource = new index_1.SyncEventResource(param.memory, (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : true);
78
76
  this.contracts = param.contracts;
79
77
  this.handler = param.handler;
80
- this.systemErrorDomain = param.systemErrorDomain;
81
- this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.RESUMABLE, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_d = (_c = param.spanOptions) === null || _c === void 0 ? void 0 : _c.attributes) !== null && _d !== void 0 ? _d : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': this.contracts.self.uri }) });
78
+ this.defaultEventEmissionDomains = __assign({ systemError: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT], services: [ArvoDomain_1.ArvoDomain.LOCAL], complete: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT] }, ((_c = param.defaultEventEmissionDomains) !== null && _c !== void 0 ? _c : {}));
79
+ this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.RESUMABLE, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_e = (_d = param.spanOptions) === null || _d === void 0 ? void 0 : _d.attributes) !== null && _e !== void 0 ? _e : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': this.contracts.self.uri }) });
82
80
  }
83
81
  Object.defineProperty(ArvoResumable.prototype, "requiresResourceLocking", {
84
82
  /** Whether this resumable requires resource locking for concurrent safety */
@@ -156,15 +154,14 @@ var ArvoResumable = /** @class */ (function () {
156
154
  source: this.source,
157
155
  syncEventResource: this.syncEventResource,
158
156
  executionunits: this.executionunits,
159
- systemErrorDomain: this.systemErrorDomain,
157
+ systemErrorDomain: this.defaultEventEmissionDomains.systemError,
160
158
  selfContract: this.contracts.self.version('latest'),
161
- domain: this.domain,
162
159
  }, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
163
- var inputValidation, contractType, eventTypeToExpectedEvent, _i, _c, _d, _, eventList, _e, eventList_1, _evt, handler, versionedSelfContract, executionResult, rawEvents, emittables, eventTrackingState, newState;
164
- var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
160
+ var inputValidation, contractType, eventTypeToExpectedEvent, _i, _c, _d, _, eventList, _e, eventList_1, _evt, handler, versionedSelfContract, executionResult, rawEvents, i, emittables, eventTrackingState, newState;
161
+ var _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
165
162
  var span = _b.span, otelHeaders = _b.otelHeaders, orchestrationParentSubject = _b.orchestrationParentSubject, initEventId = _b.initEventId, parsedEventSubject = _b.parsedEventSubject, state = _b.state;
166
- return __generator(this, function (_v) {
167
- switch (_v.label) {
163
+ return __generator(this, function (_y) {
164
+ switch (_y.label) {
168
165
  case 0:
169
166
  (0, arvo_core_1.logToSpan)({
170
167
  level: 'INFO',
@@ -231,17 +228,18 @@ var ArvoResumable = /** @class */ (function () {
231
228
  },
232
229
  })];
233
230
  case 1:
234
- executionResult = _v.sent();
231
+ executionResult = _y.sent();
235
232
  rawEvents = (_o = executionResult === null || executionResult === void 0 ? void 0 : executionResult.services) !== null && _o !== void 0 ? _o : [];
233
+ for (i = 0; i < rawEvents.length; i++) {
234
+ rawEvents[i].domain = (_p = rawEvents[i].domain) !== null && _p !== void 0 ? _p : this.defaultEventEmissionDomains.services;
235
+ }
236
236
  if (executionResult === null || executionResult === void 0 ? void 0 : executionResult.output) {
237
237
  rawEvents.push({
238
238
  id: executionResult.output.__id,
239
239
  data: executionResult.output,
240
240
  type: this.contracts.self.metadata.completeEventType,
241
- to: (_q = (_p = parsedEventSubject.meta) === null || _p === void 0 ? void 0 : _p.redirectto) !== null && _q !== void 0 ? _q : parsedEventSubject.execution.initiator,
242
- domain: orchestrationParentSubject
243
- ? [arvo_core_1.ArvoOrchestrationSubject.parse(orchestrationParentSubject).execution.domain]
244
- : [ArvoDomain_1.ArvoDomain.LOCAL],
241
+ to: (_r = (_q = parsedEventSubject.meta) === null || _q === void 0 ? void 0 : _q.redirectto) !== null && _r !== void 0 ? _r : parsedEventSubject.execution.initiator,
242
+ domain: (_t = (_s = executionResult.output) === null || _s === void 0 ? void 0 : _s.__domain) !== null && _t !== void 0 ? _t : this.defaultEventEmissionDomains.complete,
245
243
  executionunits: executionResult.output.__executionunits,
246
244
  });
247
245
  }
@@ -264,7 +262,7 @@ var ArvoResumable = /** @class */ (function () {
264
262
  consumed: event.toJSON(),
265
263
  expected: emittables.length
266
264
  ? Object.fromEntries(emittables.map(function (item) { return [item.id, []]; }))
267
- : ((_s = (_r = state === null || state === void 0 ? void 0 : state.events) === null || _r === void 0 ? void 0 : _r.expected) !== null && _s !== void 0 ? _s : null),
265
+ : ((_v = (_u = state === null || state === void 0 ? void 0 : state.events) === null || _u === void 0 ? void 0 : _u.expected) !== null && _v !== void 0 ? _v : null),
268
266
  produced: emittables.map(function (item) { return item.toJSON(); }),
269
267
  };
270
268
  newState = {
@@ -274,7 +272,7 @@ var ArvoResumable = /** @class */ (function () {
274
272
  parentSubject: orchestrationParentSubject,
275
273
  subject: event.subject,
276
274
  events: eventTrackingState,
277
- state$$: (_u = (_t = executionResult === null || executionResult === void 0 ? void 0 : executionResult.context) !== null && _t !== void 0 ? _t : state === null || state === void 0 ? void 0 : state.state$$) !== null && _u !== void 0 ? _u : null,
275
+ state$$: (_x = (_w = executionResult === null || executionResult === void 0 ? void 0 : executionResult.context) !== null && _w !== void 0 ? _w : state === null || state === void 0 ? void 0 : state.state$$) !== null && _x !== void 0 ? _x : null,
278
276
  };
279
277
  return [2 /*return*/, { emittables: emittables, newState: newState }];
280
278
  }
@@ -287,7 +285,7 @@ var ArvoResumable = /** @class */ (function () {
287
285
  };
288
286
  Object.defineProperty(ArvoResumable.prototype, "systemErrorSchema", {
289
287
  get: function () {
290
- return __assign(__assign({}, this.contracts.self.systemError), { domain: this.systemErrorDomain });
288
+ return this.contracts.self.systemError;
291
289
  },
292
290
  enumerable: false,
293
291
  configurable: true
@@ -3,7 +3,7 @@ import type { ArvoContract, ArvoEvent, ArvoOrchestratorContract, ArvoSemanticVer
3
3
  import type { EnqueueArvoEventActionParam } from '../ArvoMachine/types';
4
4
  import type { OrchestrationExecutionMemoryRecord } from '../ArvoOrchestrationUtils/orchestrationExecutionState';
5
5
  import type { IMachineMemory } from '../MachineMemory/interface';
6
- import type { ArvoEventHandlerOtelSpanOptions } from '../types';
6
+ import type { ArvoEventHandlerOtelSpanOptions, NonEmptyArray } from '../types';
7
7
  /**
8
8
  * Extracts all possible event types (including system errors) from service contracts.
9
9
  */
@@ -98,6 +98,7 @@ type Handler<TState extends ArvoResumableState<Record<string, any>>, TSelfContra
98
98
  }[keyof InferVersionedArvoContract<TSelfContract>['emits']] & {
99
99
  __id?: CreateArvoEvent<Record<string, unknown>, string>['id'];
100
100
  __executionunits?: CreateArvoEvent<Record<string, unknown>, string>['executionunits'];
101
+ __domain?: NonEmptyArray<string | null>;
101
102
  };
102
103
  /**
103
104
  * Service call events to emit.
@@ -219,10 +220,47 @@ export type ArvoResumableParam<TMemory extends Record<string, any>, TSelfContrac
219
220
  * Each contract version maps to its corresponding handler implementation.
220
221
  */
221
222
  handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
222
- /** Optional domains for system error event routing */
223
- systemErrorDomain?: (string | null)[];
223
+ /**
224
+ * Optional domains for system error event routing
225
+ *
226
+ * @default [ArvoDomain.FROM_PARENT_SUBJECT]
227
+ */
228
+ systemErrorDomain?: NonEmptyArray<string | null>;
224
229
  /** OpenTelemetry span configuration for distributed tracing */
225
230
  spanOptions?: ArvoEventHandlerOtelSpanOptions;
231
+ /**
232
+ * Optional default domains for the events emitted
233
+ * by the orchestrator.
234
+ */
235
+ defaultEventEmissionDomains?: {
236
+ /**
237
+ * Default domains for system error events emitted by this orchestrator.
238
+ *
239
+ * System errors are routed through these domains when the handler encounters
240
+ * unhandled exceptions or critical failures.
241
+ *
242
+ * @default [ArvoDomain.ORCHESTRATION_CONTEXT]
243
+ */
244
+ systemError?: NonEmptyArray<string | null>;
245
+ /**
246
+ * Default domains for service events emitted by this orchestrator.
247
+ *
248
+ * The service xstate.emit function can over-ride this default.
249
+ *
250
+ * @default [ArvoDomain.LOCAL]
251
+ */
252
+ services?: NonEmptyArray<string | null>;
253
+ /**
254
+ * Defauld domain for the final completion event emitted by this orchestrator
255
+ *
256
+ * Completion event is routed through these domains when the orchestrator successfully
257
+ * processes an init event. The machine 'output' transform function implementations can override
258
+ * this default.
259
+ *
260
+ * @default [ArvoDomain.ORCHESTRATION_CONTEXT]
261
+ */
262
+ complete?: NonEmptyArray<string | null>;
263
+ };
226
264
  };
227
265
  /**
228
266
  * Configuration parameters for creating an ArvoResumable instance.
@@ -252,9 +290,8 @@ export type CreateArvoResumableParam<TMemory extends Record<string, any>, TSelfC
252
290
  * @default true if multiple service contracts, false otherwise
253
291
  */
254
292
  requiresResourceLocking?: boolean;
255
- /** Optional domains for system error event routing */
256
- systemErrorDomain?: (string | null)[];
257
293
  /** OpenTelemetry span configuration for distributed tracing */
258
294
  spanOptions?: ArvoEventHandlerOtelSpanOptions;
295
+ defaultEventEmissionDomains?: ArvoResumableParam<TMemory, TSelfContract, TServiceContract>['defaultEventEmissionDomains'];
259
296
  };
260
297
  export {};
@@ -42,9 +42,6 @@ export default interface IArvoEventHandler {
42
42
  *
43
43
  * @property type - The error event type identifier
44
44
  * @property schema - Zod schema defining the error event data structure
45
- * @property domain - Optional domains for error event routing and distribution
46
45
  */
47
- systemErrorSchema: ArvoContractRecord & {
48
- domain?: (string | null)[];
49
- };
46
+ systemErrorSchema: ArvoContractRecord;
50
47
  }
package/dist/types.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { SpanOptions } from '@opentelemetry/api';
2
2
  import type { ArvoEvent } from 'arvo-core';
3
3
  import type IArvoEventHandler from './IArvoEventHandler';
4
+ export type NonEmptyArray<T> = [T, ...T[]];
4
5
  /**
5
6
  * Makes properties optional except specified keys
6
7
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-event-handler",
3
- "version": "3.0.23",
3
+ "version": "3.0.26",
4
4
  "description": "A complete set of orthogonal event handler and orchestration primitives for Arvo based applications, featuring declarative state machines (XState), imperative resumables for agentic workflows, contract-based routing, OpenTelemetry observability, and in-memory event broker for building composable event-driven architectures.",
5
5
  "main": "dist/index.js",
6
6
  "repository": {
@@ -36,10 +36,12 @@
36
36
  "observability"
37
37
  ],
38
38
  "author": "Saad Ahmad <saadkwi12@hotmail.com>",
39
+ "homepage": "https://www.arvo.land",
39
40
  "license": "MIT",
40
41
  "devDependencies": {
41
42
  "@biomejs/biome": "1.9.4",
42
43
  "@jest/globals": "29.7.0",
44
+ "@opentelemetry/core": "2.2.0",
43
45
  "@opentelemetry/auto-instrumentations-node": "0.49.1",
44
46
  "@opentelemetry/exporter-metrics-otlp-proto": "0.52.1",
45
47
  "@opentelemetry/exporter-trace-otlp-grpc": "0.53.0",
@@ -64,11 +66,10 @@
64
66
  },
65
67
  "dependencies": {
66
68
  "@opentelemetry/api": "1.9.0",
67
- "@opentelemetry/core": "1.30.1",
68
- "arvo-core": "3.0.23",
69
+ "arvo-core": "3.0.26",
69
70
  "uuid": "11.1.0",
70
- "xstate": "5.24.0",
71
- "zod": "3.25.74",
71
+ "xstate": "5.25.0",
72
+ "zod": "3.25.76",
72
73
  "zod-to-json-schema": "3.25.0"
73
74
  },
74
75
  "engines": {