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.
@@ -3,6 +3,7 @@ import { type ActionFunction, type MachineConfig, type MachineContext, type Meta
3
3
  import type { z } from 'zod';
4
4
  import ArvoMachine from '.';
5
5
  import type { EnqueueArvoEventActionParam, ExtractOrchestratorType, InferServiceContract, ToParameterizedObject, ToProvidedActor } from './types';
6
+ import { NonEmptyArray } from '../types';
6
7
  /**
7
8
  * Establishes the foundation for creating Arvo-compatible state machines.
8
9
  *
@@ -133,20 +134,27 @@ export declare function setupArvoMachine<TContext extends MachineContext, TSelfC
133
134
  }>, ToParameterizedObject<TGuards>, never, TTag, InferVersionedArvoContract<TSelfContract>["accepts"], z.input<TSelfContract["emits"][ReturnType<typeof ArvoOrchestratorEventTypeGen.complete<ExtractOrchestratorType<TSelfContract["accepts"]["type"]>>>]> & {
134
135
  __id?: CreateArvoEvent<Record<string, unknown>, string>["id"];
135
136
  __executionunits?: CreateArvoEvent<Record<string, unknown>, string>["executionunits"];
137
+ __domain?: NonEmptyArray<string | null>;
136
138
  }, InferServiceContract<TServiceContracts>["emitted"], TMeta>>(config: TConfig & {
137
139
  id: string;
138
140
  version?: TSelfContract["version"];
139
- }) => ArvoMachine<string, TSelfContract["version"], TSelfContract, TServiceContracts, import("xstate").StateMachine<TContext, { [K in keyof TServiceContracts]: import("./types").InferEmittableEventsFromVersionedArvoContract<TServiceContracts[K]>; }[keyof TServiceContracts], {}, never, import("xstate").IsNever<TActions & {
141
+ }) => ArvoMachine<string, TSelfContract["version"], TSelfContract, TServiceContracts, import("xstate").StateMachine<TContext, { [K in keyof TServiceContracts]: import("./types").InferEmittableEventsFromVersionedArvoContract<TServiceContracts[K]>; }[keyof TServiceContracts], {}, never, (TActions & {
140
142
  enqueueArvoEvent: EnqueueArvoEventActionParam;
141
- }> extends true ? never : import("xstate").Values<{ [K_1 in (keyof TActions & string) | "enqueueArvoEvent"]: {
142
- type: K_1;
143
- params: (TActions & {
144
- enqueueArvoEvent: EnqueueArvoEventActionParam;
145
- })[K_1];
146
- }; }>, import("xstate").IsNever<TGuards> extends true ? never : import("xstate").Values<{ [K_2 in keyof TGuards & string]: {
147
- type: K_2;
143
+ } extends infer T extends Record<string, import("xstate").NonReducibleUnknown> ? { [K_1 in keyof T as K_1 & string]: {
144
+ type: K_1 & string;
145
+ params: T[K_1];
146
+ }; } : never)[keyof (TActions & {
147
+ enqueueArvoEvent: EnqueueArvoEventActionParam;
148
+ } extends infer T_1 extends Record<string, import("xstate").NonReducibleUnknown> ? { [K_1 in keyof T_1 as K_1 & string]: {
149
+ type: K_1 & string;
150
+ params: T_1[K_1];
151
+ }; } : never)], { [K_2 in keyof TGuards as K_2 & string]: {
152
+ type: K_2 & string;
153
+ params: TGuards[K_2];
154
+ }; }[keyof { [K_2 in keyof TGuards as K_2 & string]: {
155
+ type: K_2 & string;
148
156
  params: TGuards[K_2];
149
- }; }>, never, {} | {
157
+ }; }], never, {} | {
150
158
  [x: string]: {} | /*elided*/ any | {
151
159
  [x: string]: {} | /*elided*/ any | /*elided*/ any;
152
160
  };
@@ -154,5 +162,8 @@ export declare function setupArvoMachine<TContext extends MachineContext, TSelfC
154
162
  [x: string]: {} | {
155
163
  [x: string]: {} | /*elided*/ any | /*elided*/ any;
156
164
  } | /*elided*/ any;
157
- }, TTag, TSelfContract["accepts"]["schema"]["_output"], { [K_3 in string & keyof TSelfContract["emits"]]: import("arvo-core").InferArvoEvent<import("arvo-core").ArvoEvent<TSelfContract["emits"][K_3]["_output"], Record<string, any>, K_3>>; }[`arvo.orc.${ExtractOrchestratorType<TSelfContract["accepts"]["type"]>}.done`]["data"], { [K_4 in keyof TServiceContracts]: EnqueueArvoEventActionParam<z.input<TServiceContracts[K_4]["accepts"]["schema"]>, TServiceContracts[K_4]["accepts"]["type"], Record<string, string | number | boolean | null>>; }[keyof TServiceContracts], TMeta, any>>;
165
+ }, TTag, TSelfContract["accepts"]["schema"]["_output"], { [K_3 in string & keyof TSelfContract["emits"]]: import("arvo-core").InferArvoEvent<import("arvo-core").ArvoEvent<TSelfContract["emits"][K_3]["_output"], Record<string, any>, K_3>>; }[`arvo.orc.${ExtractOrchestratorType<TSelfContract["accepts"]["type"]>}.done`]["data"], { [K_4 in keyof TServiceContracts]: EnqueueArvoEventActionParam<z.input<TServiceContracts[K_4]["accepts"]["schema"]>, TServiceContracts[K_4]["accepts"]["type"], Record<string, string | number | boolean | null>>; }[keyof TServiceContracts], TMeta, {
166
+ id: any;
167
+ states: any;
168
+ }>>;
158
169
  };
@@ -1,6 +1,7 @@
1
1
  import type { ArvoContract, ArvoEventData, ArvoOrchestratorEventTypeGen, ArvoSemanticVersion, CloudEventExtension, CreateArvoEvent, InferVersionedArvoContract, VersionedArvoContract } from 'arvo-core';
2
2
  import type { Invert, IsNever, ParameterizedObject, UnknownActorLogic, Values } from 'xstate';
3
3
  import type { z } from 'zod';
4
+ import { NonEmptyArray } from '../types';
4
5
  /**
5
6
  * Represents an extended context for Arvo XState machines, including additional properties
6
7
  * for volatile and internal data.
@@ -34,7 +35,7 @@ export type EnqueueArvoEventActionParam<TData extends ArvoEventData = ArvoEventD
34
35
  /**
35
36
  * The domain configuration for multi-domain event broadcasting.
36
37
  */
37
- domain?: (string | null)[];
38
+ domain?: NonEmptyArray<string | null>;
38
39
  /**
39
40
  * Custom extensions for the CloudEvent.
40
41
  * Allows for additional metadata to be attached to the event.
@@ -39,6 +39,8 @@ var createEmittableEvent = function (_a, span) {
39
39
  var parentId = sourceEvent.id;
40
40
  var domain = (0, ArvoDomain_1.resolveEventDomain)({
41
41
  domainToResolve: _domain,
42
+ parentSubject: orchestrationParentSubject,
43
+ currentSubject: sourceEvent.subject,
42
44
  handlerSelfContract: selfContract,
43
45
  eventContract: null,
44
46
  triggeringEvent: sourceEvent,
@@ -54,6 +56,8 @@ var createEmittableEvent = function (_a, span) {
54
56
  parentId = initEventId;
55
57
  domain = (0, ArvoDomain_1.resolveEventDomain)({
56
58
  domainToResolve: _domain,
59
+ parentSubject: orchestrationParentSubject,
60
+ currentSubject: sourceEvent.subject,
57
61
  handlerSelfContract: selfContract,
58
62
  eventContract: selfContract,
59
63
  triggeringEvent: sourceEvent,
@@ -68,6 +72,8 @@ var createEmittableEvent = function (_a, span) {
68
72
  schema = serviceContractMap[event.type].accepts.schema;
69
73
  domain = (0, ArvoDomain_1.resolveEventDomain)({
70
74
  domainToResolve: _domain,
75
+ parentSubject: orchestrationParentSubject,
76
+ currentSubject: sourceEvent.subject,
71
77
  handlerSelfContract: selfContract,
72
78
  eventContract: contract,
73
79
  triggeringEvent: sourceEvent,
@@ -3,6 +3,7 @@ import { type ArvoContract, type ArvoEvent, type ArvoSemanticVersion, type OpenT
3
3
  import type { SyncEventResource } from '../SyncEventResource';
4
4
  import type { OrchestrationExecutionMemoryRecord } from './orchestrationExecutionState';
5
5
  import { type ArvoOrchestrationHandlerType } from './types';
6
+ import type { NonEmptyArray } from '../types';
6
7
  /**
7
8
  * Parameters for creating system error events during orchestration failures.
8
9
  */
@@ -20,13 +21,11 @@ export type CreateSystemErrorEventsParams = {
20
21
  /** Self contract defining error schema */
21
22
  selfContract: VersionedArvoContract<ArvoContract, ArvoSemanticVersion>;
22
23
  /** Optional domains for error event routing */
23
- systemErrorDomain?: (string | null)[];
24
+ systemErrorDomain: NonEmptyArray<string | null>;
24
25
  /** Execution units for error events */
25
26
  executionunits: number;
26
27
  /** Source identifier */
27
28
  source: string;
28
- /** Domain for error events */
29
- domain: string | null;
30
29
  /** Type of handler reporting the error */
31
30
  handlerType: ArvoOrchestrationHandlerType;
32
31
  };
@@ -40,7 +39,7 @@ export type CreateSystemErrorEventsParams = {
40
39
  * @param params - Error event creation parameters
41
40
  * @returns Array of system error events for each configured domain
42
41
  */
43
- export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject: _orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, domain, handlerType, }: CreateSystemErrorEventsParams & {
42
+ export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject: _orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, handlerType, }: CreateSystemErrorEventsParams & {
44
43
  error: Error;
45
44
  }) => ArvoEvent[];
46
45
  /**
@@ -66,7 +66,7 @@ var types_1 = require("./types");
66
66
  */
67
67
  var createSystemErrorEvents = function (_a) {
68
68
  var _b, _c, _d, _e, _f;
69
- var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders, _orchestrationParentSubject = _a.orchestrationParentSubject, initEventId = _a.initEventId, selfContract = _a.selfContract, systemErrorDomain = _a.systemErrorDomain, executionunits = _a.executionunits, source = _a.source, domain = _a.domain, handlerType = _a.handlerType;
69
+ var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders, _orchestrationParentSubject = _a.orchestrationParentSubject, initEventId = _a.initEventId, selfContract = _a.selfContract, systemErrorDomain = _a.systemErrorDomain, executionunits = _a.executionunits, source = _a.source, handlerType = _a.handlerType;
70
70
  // In case of none transaction errors like errors from
71
71
  // the machine or the event creation etc, the are workflow
72
72
  // error and shuold be handled by the workflow. Then are
@@ -86,18 +86,18 @@ var createSystemErrorEvents = function (_a) {
86
86
  });
87
87
  }
88
88
  }
89
- var domainSets = new Set((systemErrorDomain === null || systemErrorDomain === void 0 ? void 0 : systemErrorDomain.length)
90
- ? systemErrorDomain.map(function (item) {
91
- return (0, ArvoDomain_1.resolveEventDomain)({
92
- domainToResolve: item,
93
- handlerSelfContract: selfContract,
94
- eventContract: selfContract,
95
- triggeringEvent: event,
96
- });
97
- })
98
- : [event.domain, domain, null]);
89
+ var domainSets = systemErrorDomain.map(function (item) {
90
+ return (0, ArvoDomain_1.resolveEventDomain)({
91
+ parentSubject: orchestrationParentSubject,
92
+ currentSubject: event.subject,
93
+ domainToResolve: item,
94
+ handlerSelfContract: selfContract,
95
+ eventContract: selfContract,
96
+ triggeringEvent: event,
97
+ });
98
+ });
99
99
  var result = [];
100
- for (var _i = 0, _g = Array.from(domainSets); _i < _g.length; _i++) {
100
+ for (var _i = 0, _g = Array.from(new Set(domainSets)); _i < _g.length; _i++) {
101
101
  var _dom = _g[_i];
102
102
  var factoryBuilder = handlerType === 'handler' ? arvo_core_1.createArvoEventFactory : arvo_core_1.createArvoOrchestratorEventFactory;
103
103
  result.push(factoryBuilder(selfContract).systemError({
@@ -2,7 +2,7 @@ import { type Span } from '@opentelemetry/api';
2
2
  import { type ArvoEvent, type ArvoOrchestrationSubjectContent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract } from 'arvo-core';
3
3
  import type IArvoEventHandler from '../../IArvoEventHandler';
4
4
  import type { SyncEventResource } from '../../SyncEventResource';
5
- import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../../types';
5
+ import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions, NonEmptyArray } from '../../types';
6
6
  import type { OrchestrationExecutionMemoryRecord } from '../orchestrationExecutionState';
7
7
  import type { ArvoOrchestrationHandlerType } from '../types';
8
8
  /**
@@ -21,11 +21,9 @@ export type OrchestrationExecutionContext<TState extends OrchestrationExecutionM
21
21
  /** Maximum execution units per cycle */
22
22
  executionunits: number;
23
23
  /** Optional domains for system error routing */
24
- systemErrorDomain?: (string | null)[];
24
+ systemErrorDomain: NonEmptyArray<string | null>;
25
25
  /** Self contract defining orchestrator interface */
26
26
  selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
27
- /** Domain for event routing */
28
- domain: string | null;
29
27
  /** Type of orchestration handler */
30
28
  _handlerType: ArvoOrchestrationHandlerType;
31
29
  /** OpenTelemetry span configuration */
@@ -78,4 +76,4 @@ export declare const returnEventsWithLogging: (param: Awaited<ReturnType<IArvoEv
78
76
  * while allowing custom core logic via the execution function parameter.
79
77
  * @returns Emitted events from successful execution or error handling
80
78
  */
81
- export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry, spanOptions, source, syncEventResource, executionunits, systemErrorDomain, selfContract, domain, _handlerType, }: OrchestrationExecutionContext<TState>, coreExecutionFn: CoreExecutionFn<TState>) => Promise<Awaited<ReturnType<IArvoEventHandler["execute"]>>>;
79
+ export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry, spanOptions, source, syncEventResource, executionunits, systemErrorDomain, selfContract, _handlerType, }: OrchestrationExecutionContext<TState>, coreExecutionFn: CoreExecutionFn<TState>) => Promise<Awaited<ReturnType<IArvoEventHandler["execute"]>>>;
@@ -84,7 +84,7 @@ exports.returnEventsWithLogging = returnEventsWithLogging;
84
84
  */
85
85
  var executeWithOrchestrationWrapper = function (_a, coreExecutionFn_1) { return __awaiter(void 0, [_a, coreExecutionFn_1], void 0, function (_b, coreExecutionFn) {
86
86
  var otelConfig;
87
- var event = _b.event, opentelemetry = _b.opentelemetry, spanOptions = _b.spanOptions, source = _b.source, syncEventResource = _b.syncEventResource, executionunits = _b.executionunits, systemErrorDomain = _b.systemErrorDomain, selfContract = _b.selfContract, domain = _b.domain, _handlerType = _b._handlerType;
87
+ var event = _b.event, opentelemetry = _b.opentelemetry, spanOptions = _b.spanOptions, source = _b.source, syncEventResource = _b.syncEventResource, executionunits = _b.executionunits, systemErrorDomain = _b.systemErrorDomain, selfContract = _b.selfContract, _handlerType = _b._handlerType;
88
88
  return __generator(this, function (_c) {
89
89
  switch (_c.label) {
90
90
  case 0:
@@ -206,7 +206,6 @@ var executeWithOrchestrationWrapper = function (_a, coreExecutionFn_1) { return
206
206
  systemErrorDomain: systemErrorDomain,
207
207
  executionunits: executionunits,
208
208
  source: source,
209
- domain: domain,
210
209
  syncEventResource: syncEventResource,
211
210
  handlerType: _handlerType,
212
211
  }, span)];
@@ -18,7 +18,6 @@ import type { CreateArvoOrchestratorParam } from './types';
18
18
  * ```typescript
19
19
  * const orchestrator = createArvoOrchestrator({
20
20
  * memory: new SimpleMachineMemory(),
21
- * executionunits: 1,
22
21
  * machines: [userOnboardingMachine, paymentMachine]
23
22
  * });
24
23
  *
@@ -29,4 +28,4 @@ import type { CreateArvoOrchestratorParam } from './types';
29
28
  * @see {@link setupArvoMachine} for creating machine definitions
30
29
  * @see {@link ArvoOrchestrator} for direct instantiation with custom components
31
30
  */
32
- export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, spanOptions, requiresResourceLocking: _locking, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
31
+ export declare const createArvoOrchestrator: ({ executionunits, memory, machines, defaultEventEmissionDomains, spanOptions, requiresResourceLocking: _locking, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
@@ -32,7 +32,6 @@ var errors_1 = require("../errors");
32
32
  * ```typescript
33
33
  * const orchestrator = createArvoOrchestrator({
34
34
  * memory: new SimpleMachineMemory(),
35
- * executionunits: 1,
36
35
  * machines: [userOnboardingMachine, paymentMachine]
37
36
  * });
38
37
  *
@@ -44,23 +43,23 @@ var errors_1 = require("../errors");
44
43
  * @see {@link ArvoOrchestrator} for direct instantiation with custom components
45
44
  */
46
45
  var createArvoOrchestrator = function (_a) {
47
- var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions, _locking = _a.requiresResourceLocking;
46
+ var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, defaultEventEmissionDomains = _a.defaultEventEmissionDomains, spanOptions = _a.spanOptions, _locking = _a.requiresResourceLocking;
48
47
  if (!(machines === null || machines === void 0 ? void 0 : machines.length)) {
49
48
  throw new Error('At least one machine must be provided');
50
49
  }
51
50
  var registry = new (MachineRegistry_1.MachineRegistry.bind.apply(MachineRegistry_1.MachineRegistry, __spreadArray([void 0], machines, false)))();
52
51
  var requiresResourceLocking = _locking !== null && _locking !== void 0 ? _locking : machines.some(function (machine) { return machine.requiresResourceLocking; });
53
52
  var representativeMachine = registry.machines[0];
54
- var lastSeenVersions = [];
53
+ var lastSeenVersions = new Set();
55
54
  for (var _i = 0, _b = registry.machines; _i < _b.length; _i++) {
56
55
  var machine = _b[_i];
57
56
  if (representativeMachine.source !== machine.source) {
58
- throw new errors_1.ConfigViolation("All the machines in the orchestrator must have type '".concat(representativeMachine.source, "'"));
57
+ throw new errors_1.ConfigViolation("All the machines in the orchestrator must have source '".concat(representativeMachine.source, "'. Make sure all machine are implementing versions of the same self contract"));
59
58
  }
60
- if (lastSeenVersions.includes(machine.version)) {
59
+ if (lastSeenVersions.has(machine.version)) {
61
60
  throw new errors_1.ConfigViolation("An orchestrator must have unique machine versions. Machine ID:".concat(machine.id, " has duplicate version ").concat(machine.version, "."));
62
61
  }
63
- lastSeenVersions.push(machine.version);
62
+ lastSeenVersions.add(machine.version);
64
63
  }
65
64
  return new _1.ArvoOrchestrator({
66
65
  executionunits: executionunits,
@@ -68,7 +67,7 @@ var createArvoOrchestrator = function (_a) {
68
67
  registry: registry,
69
68
  executionEngine: new MachineExecutionEngine_1.MachineExecutionEngine(),
70
69
  requiresResourceLocking: requiresResourceLocking,
71
- systemErrorDomain: systemErrorDomain,
70
+ defaultEventEmissionDomains: defaultEventEmissionDomains,
72
71
  spanOptions: spanOptions,
73
72
  });
74
73
  };
@@ -22,8 +22,8 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
22
22
  readonly executionEngine: IMachineExectionEngine;
23
23
  /** Resource manager for state synchronization and memory access */
24
24
  readonly syncEventResource: SyncEventResource<MachineMemoryRecord>;
25
- /** Optional domains for routing system error events */
26
- readonly systemErrorDomain?: (string | null)[];
25
+ /** Domains for routing events */
26
+ readonly defaultEventEmissionDomains: Required<NonNullable<ArvoOrchestratorParam['defaultEventEmissionDomains']>>;
27
27
  /** OpenTelemetry span configuration for observability */
28
28
  readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
29
29
  /** Source identifier from the first registered machine */
@@ -34,7 +34,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
34
34
  get memory(): IMachineMemory<MachineMemoryRecord>;
35
35
  /** The contract-defined domain for the handler */
36
36
  get domain(): string | null;
37
- constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, spanOptions, }: ArvoOrchestratorParam);
37
+ constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, defaultEventEmissionDomains, spanOptions, }: ArvoOrchestratorParam);
38
38
  /**
39
39
  * Executes state machine orchestration for an incoming event.
40
40
  *
@@ -76,6 +76,5 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
76
76
  errorMessage: string;
77
77
  errorStack: string | null;
78
78
  }>;
79
- domain: (string | null)[] | undefined;
80
79
  };
81
80
  }
@@ -65,15 +65,13 @@ var ArvoDomain_1 = require("../ArvoDomain");
65
65
  var ArvoOrchestrator = /** @class */ (function () {
66
66
  function ArvoOrchestrator(_a) {
67
67
  var _b;
68
- var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
68
+ var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking, defaultEventEmissionDomains = _a.defaultEventEmissionDomains, spanOptions = _a.spanOptions;
69
69
  var _c, _d, _e, _f, _g, _h, _j;
70
- /** Optional domains for routing system error events */
71
- this.systemErrorDomain = undefined;
72
- this.executionunits = executionunits;
70
+ this.executionunits = executionunits !== null && executionunits !== void 0 ? executionunits : 0;
73
71
  this.registry = registry;
74
72
  this.executionEngine = executionEngine;
75
73
  this.syncEventResource = new SyncEventResource_1.SyncEventResource(memory, requiresResourceLocking);
76
- this.systemErrorDomain = systemErrorDomain;
74
+ this.defaultEventEmissionDomains = __assign({ systemError: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT], services: [ArvoDomain_1.ArvoDomain.LOCAL], complete: [ArvoDomain_1.ArvoDomain.ORCHESTRATION_CONTEXT] }, (defaultEventEmissionDomains !== null && defaultEventEmissionDomains !== void 0 ? defaultEventEmissionDomains : {}));
77
75
  this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, spanOptions), { attributes: __assign(__assign((_b = {}, _b[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.ORCHESTRATOR, _b[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _b), ((_c = spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': (_j = (_h = (_g = (_f = (_e = (_d = this === null || this === void 0 ? void 0 : this.registry) === null || _d === void 0 ? void 0 : _d.machines) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.contracts) === null || _g === void 0 ? void 0 : _g.self) === null || _h === void 0 ? void 0 : _h.uri) !== null && _j !== void 0 ? _j : 'N/A' }) });
78
76
  }
79
77
  Object.defineProperty(ArvoOrchestrator.prototype, "source", {
@@ -144,14 +142,13 @@ var ArvoOrchestrator = /** @class */ (function () {
144
142
  source: this.source,
145
143
  syncEventResource: this.syncEventResource,
146
144
  executionunits: this.executionunits,
147
- systemErrorDomain: this.systemErrorDomain,
145
+ systemErrorDomain: this.defaultEventEmissionDomains.systemError,
148
146
  selfContract: this.registry.machines[0].contracts.self,
149
- domain: this.domain,
150
147
  }, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
151
- var machine, inputValidation, executionResult, rawMachineEmittedEvents, emittables, newState;
152
- var _c, _d, _e, _f;
148
+ var machine, inputValidation, executionResult, rawMachineEmittedEvents, i, emittables, newState;
149
+ var _c, _d, _e, _f, _g, _h;
153
150
  var span = _b.span, otelHeaders = _b.otelHeaders, orchestrationParentSubject = _b.orchestrationParentSubject, initEventId = _b.initEventId, parsedEventSubject = _b.parsedEventSubject, state = _b.state;
154
- return __generator(this, function (_g) {
151
+ return __generator(this, function (_j) {
155
152
  (0, arvo_core_1.logToSpan)({
156
153
  level: 'INFO',
157
154
  message: "Resolving machine for event ".concat(event.type),
@@ -174,15 +171,22 @@ var ArvoOrchestrator = /** @class */ (function () {
174
171
  executionResult = this.executionEngine.execute({ state: (_c = state === null || state === void 0 ? void 0 : state.state) !== null && _c !== void 0 ? _c : null, event: event, machine: machine }, { inheritFrom: 'CONTEXT' });
175
172
  span.setAttribute('arvo.orchestration.status', executionResult.state.status);
176
173
  rawMachineEmittedEvents = executionResult.events;
174
+ // For all the service events (non final output) make sure
175
+ // that the default domain is this.defaultEventEmissionDomains.services.
176
+ // This is because the assumption is that all the normal services
177
+ // the orchestrator usually talks to are in the same local
178
+ // domain.
179
+ for (i = 0; i < rawMachineEmittedEvents.length; i++) {
180
+ rawMachineEmittedEvents[i].domain =
181
+ (_d = rawMachineEmittedEvents[i].domain) !== null && _d !== void 0 ? _d : this.defaultEventEmissionDomains.services;
182
+ }
177
183
  if (executionResult.finalOutput) {
178
184
  rawMachineEmittedEvents.push({
179
185
  type: machine.contracts.self.metadata.completeEventType,
180
186
  id: executionResult.finalOutput.__id,
181
187
  data: executionResult.finalOutput,
182
- to: (_e = (_d = parsedEventSubject.meta) === null || _d === void 0 ? void 0 : _d.redirectto) !== null && _e !== void 0 ? _e : parsedEventSubject.execution.initiator,
183
- domain: orchestrationParentSubject
184
- ? [arvo_core_1.ArvoOrchestrationSubject.parse(orchestrationParentSubject).execution.domain]
185
- : [ArvoDomain_1.ArvoDomain.LOCAL],
188
+ to: (_f = (_e = parsedEventSubject.meta) === null || _e === void 0 ? void 0 : _e.redirectto) !== null && _f !== void 0 ? _f : parsedEventSubject.execution.initiator,
189
+ domain: (_g = executionResult.finalOutput.__domain) !== null && _g !== void 0 ? _g : this.defaultEventEmissionDomains.complete,
186
190
  executionunits: executionResult.finalOutput.__executionunits,
187
191
  });
188
192
  }
@@ -207,7 +211,7 @@ var ArvoOrchestrator = /** @class */ (function () {
207
211
  subject: event.subject,
208
212
  parentSubject: orchestrationParentSubject,
209
213
  status: executionResult.state.status,
210
- value: (_f = executionResult.state.value) !== null && _f !== void 0 ? _f : null,
214
+ value: (_h = executionResult.state.value) !== null && _h !== void 0 ? _h : null,
211
215
  state: executionResult.state,
212
216
  events: {
213
217
  consumed: event.toJSON(),
@@ -231,7 +235,6 @@ var ArvoOrchestrator = /** @class */ (function () {
231
235
  return {
232
236
  type: this.registry.machines[0].contracts.self.systemError.type,
233
237
  schema: arvo_core_1.ArvoErrorSchema,
234
- domain: this.systemErrorDomain,
235
238
  };
236
239
  },
237
240
  enumerable: false,
@@ -5,7 +5,7 @@ import type { OrchestrationExecutionMemoryRecord } from '../ArvoOrchestrationUti
5
5
  import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
6
6
  import type { IMachineMemory } from '../MachineMemory/interface';
7
7
  import type { IMachineRegistry } from '../MachineRegistry/interface';
8
- import type { ArvoEventHandlerOtelSpanOptions } from '../types';
8
+ import type { ArvoEventHandlerOtelSpanOptions, NonEmptyArray } from '../types';
9
9
  /**
10
10
  * Discriminated union representing the result of a try operation.
11
11
  */
@@ -84,7 +84,7 @@ export type MachineMemoryRecord = OrchestrationExecutionMemoryRecord<{
84
84
  */
85
85
  export type ArvoOrchestratorParam = {
86
86
  /** Computational cost metric assigned to orchestrator operations */
87
- executionunits: number;
87
+ executionunits?: number;
88
88
  /** Memory interface for state persistence and retrieval */
89
89
  memory: IMachineMemory<MachineMemoryRecord>;
90
90
  /** Registry for managing and resolving machine instances */
@@ -93,20 +93,41 @@ export type ArvoOrchestratorParam = {
93
93
  executionEngine: IMachineExectionEngine;
94
94
  /** Whether to enforce resource locking for concurrent safety */
95
95
  requiresResourceLocking: boolean;
96
- /**
97
- * Optional domains for system error event routing.
98
- *
99
- * Overrides the default fallback sequence of:
100
- * `[event.domain, self.contract.domain, null]`
101
- *
102
- * Controls where structured `sys.*.error` events are emitted when
103
- * uncaught exceptions occur. Supports symbolic constants from {@link ArvoDomain}.
104
- *
105
- * @default undefined - uses standard fallback broadcast domains
106
- */
107
- systemErrorDomain?: (string | null)[];
108
96
  /** OpenTelemetry span configuration for distributed tracing */
109
97
  spanOptions?: ArvoEventHandlerOtelSpanOptions;
98
+ /**
99
+ * Optional default domains for the events emitted
100
+ * by the orchestrator.
101
+ */
102
+ defaultEventEmissionDomains?: {
103
+ /**
104
+ * Default domains for system error events emitted by this orchestrator.
105
+ *
106
+ * System errors are routed through these domains when the handler encounters
107
+ * unhandled exceptions or critical failures.
108
+ *
109
+ * @default [ArvoDomain.ORCHESTRATION_CONTEXT]
110
+ */
111
+ systemError?: NonEmptyArray<string | null>;
112
+ /**
113
+ * Default domains for service events emitted by this orchestrator.
114
+ *
115
+ * The service xstate.emit function can over-ride this default.
116
+ *
117
+ * @default [ArvoDomain.LOCAL]
118
+ */
119
+ services?: NonEmptyArray<string | null>;
120
+ /**
121
+ * Defauld domain for the final completion event emitted by this orchestrator
122
+ *
123
+ * Completion event is routed through these domains when the orchestrator successfully
124
+ * processes an init event. The machine 'output' transform function implementations can override
125
+ * this default.
126
+ *
127
+ * @default [ArvoDomain.ORCHESTRATION_CONTEXT]
128
+ */
129
+ complete?: NonEmptyArray<string | null>;
130
+ };
110
131
  };
111
132
  /**
112
133
  * Configuration parameters for creating an orchestrator via factory function.
@@ -114,7 +135,7 @@ export type ArvoOrchestratorParam = {
114
135
  * Simplified interface for {@link createArvoOrchestrator} that automatically
115
136
  * constructs default registry and execution engine components.
116
137
  */
117
- export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | 'systemErrorDomain'> & {
138
+ export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | 'defaultEventEmissionDomains'> & {
118
139
  /**
119
140
  * Optional override for resource locking requirement.
120
141
  *
@@ -29,7 +29,6 @@ import type { CreateArvoResumableParam } from './types';
29
29
  * // Handler implementation
30
30
  * }
31
31
  * },
32
- * executionunits: 1
33
32
  * });
34
33
  * ```
35
34
  *
@@ -31,7 +31,6 @@ var servicesValidation_1 = require("../ArvoOrchestrationUtils/servicesValidation
31
31
  * // Handler implementation
32
32
  * }
33
33
  * },
34
- * executionunits: 1
35
34
  * });
36
35
  * ```
37
36
  *
@@ -47,7 +46,7 @@ var createArvoResumable = function (param) {
47
46
  handler: param.handler,
48
47
  executionunits: (_a = param.executionunits) !== null && _a !== void 0 ? _a : 0,
49
48
  requiresResourceLocking: (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : Object.keys(param.contracts.services).length > 1,
50
- systemErrorDomain: param.systemErrorDomain,
49
+ defaultEventEmissionDomains: param.defaultEventEmissionDomains,
51
50
  spanOptions: param.spanOptions,
52
51
  });
53
52
  };
@@ -23,8 +23,8 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
23
23
  readonly syncEventResource: SyncEventResource<ArvoResumableState<TMemory>>;
24
24
  /** Versioned handler map for processing workflow events. */
25
25
  readonly handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
26
- /** Optional domains for routing system error events */
27
- readonly systemErrorDomain?: (string | null)[];
26
+ /** Optional domains for routing events */
27
+ readonly defaultEventEmissionDomains: Required<NonNullable<ArvoResumableParam<TMemory, TSelfContract, TServiceContract>['defaultEventEmissionDomains']>>;
28
28
  /** OpenTelemetry span configuration for observability */
29
29
  readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
30
30
  /** Source identifier from the first registered machine */
@@ -82,21 +82,17 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
82
82
  execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
83
83
  events: ArvoEvent[];
84
84
  }>;
85
- get systemErrorSchema(): {
86
- domain: (string | null)[] | undefined;
87
- type: `sys.arvo.orc.${string}.error`;
88
- schema: import("zod").ZodObject<{
89
- errorName: import("zod").ZodString;
90
- errorMessage: import("zod").ZodString;
91
- errorStack: import("zod").ZodNullable<import("zod").ZodString>;
92
- }, "strip", import("zod").ZodTypeAny, {
93
- errorName: string;
94
- errorMessage: string;
95
- errorStack: string | null;
96
- }, {
97
- errorName: string;
98
- errorMessage: string;
99
- errorStack: string | null;
100
- }>;
101
- };
85
+ get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.arvo.orc.${string}.error`, import("zod").ZodObject<{
86
+ errorName: import("zod").ZodString;
87
+ errorMessage: import("zod").ZodString;
88
+ errorStack: import("zod").ZodNullable<import("zod").ZodString>;
89
+ }, "strip", import("zod").ZodTypeAny, {
90
+ errorName: string;
91
+ errorMessage: string;
92
+ errorStack: string | null;
93
+ }, {
94
+ errorName: string;
95
+ errorMessage: string;
96
+ errorStack: string | null;
97
+ }>>;
102
98
  }