arvo-event-handler 3.0.13 → 3.0.15

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 (39) hide show
  1. package/dist/ArvoEventHandler/index.d.ts +20 -123
  2. package/dist/ArvoEventHandler/index.js +5 -112
  3. package/dist/ArvoMachine/createMachine.d.ts +103 -158
  4. package/dist/ArvoMachine/createMachine.js +59 -181
  5. package/dist/ArvoMachine/index.d.ts +5 -57
  6. package/dist/ArvoMachine/index.js +8 -117
  7. package/dist/ArvoMachine/types.d.ts +0 -82
  8. package/dist/ArvoMachine/utils.d.ts +0 -15
  9. package/dist/ArvoMachine/utils.js +0 -15
  10. package/dist/ArvoOrchestrationUtils/createEmitableEvent.d.ts +31 -0
  11. package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +18 -0
  12. package/dist/ArvoOrchestrationUtils/error.d.ts +22 -0
  13. package/dist/ArvoOrchestrationUtils/error.js +21 -0
  14. package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +32 -4
  15. package/dist/ArvoOrchestrationUtils/handlerErrors.js +19 -2
  16. package/dist/ArvoOrchestrationUtils/inputValidation.d.ts +47 -0
  17. package/dist/ArvoOrchestrationUtils/inputValidation.js +120 -0
  18. package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.d.ts +24 -1
  19. package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.js +9 -1
  20. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.d.ts +5 -1
  21. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.js +5 -1
  22. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +44 -5
  23. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +17 -5
  24. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.d.ts +6 -1
  25. package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.js +6 -1
  26. package/dist/ArvoOrchestrationUtils/servicesValidation.d.ts +14 -6
  27. package/dist/ArvoOrchestrationUtils/servicesValidation.js +14 -6
  28. package/dist/ArvoOrchestrator/factory.d.ts +18 -15
  29. package/dist/ArvoOrchestrator/factory.js +19 -16
  30. package/dist/ArvoOrchestrator/index.d.ts +51 -19
  31. package/dist/ArvoOrchestrator/index.js +29 -17
  32. package/dist/ArvoOrchestrator/types.d.ts +74 -49
  33. package/dist/ArvoResumable/factory.d.ts +31 -36
  34. package/dist/ArvoResumable/factory.js +29 -18
  35. package/dist/ArvoResumable/index.d.ts +69 -65
  36. package/dist/ArvoResumable/index.js +49 -92
  37. package/dist/ArvoResumable/types.d.ts +177 -72
  38. package/dist/IArvoEventHandler/index.d.ts +29 -15
  39. package/package.json +2 -2
@@ -6,6 +6,9 @@ import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface
6
6
  import type { IMachineMemory } from '../MachineMemory/interface';
7
7
  import type { IMachineRegistry } from '../MachineRegistry/interface';
8
8
  import type { ArvoEventHandlerOtelSpanOptions } from '../types';
9
+ /**
10
+ * Discriminated union representing the result of a try operation.
11
+ */
9
12
  export type TryFunctionOutput<TData, TError extends Error> = {
10
13
  type: 'success';
11
14
  data: TData;
@@ -14,101 +17,123 @@ export type TryFunctionOutput<TData, TError extends Error> = {
14
17
  error: TError;
15
18
  };
16
19
  /**
17
- * Represents the state record stored in machine memory.
20
+ * State record persisted in machine memory for orchestration execution.
21
+ *
22
+ * Extends the base orchestration execution record with machine-specific state
23
+ * including XState snapshots, event history, and hierarchical orchestration context.
18
24
  */
19
25
  export type MachineMemoryRecord = OrchestrationExecutionMemoryRecord<{
20
- /** Unique identifier for the machine instance */
26
+ /** Unique identifier for this orchestration instance */
21
27
  subject: string;
22
28
  /**
23
- * Reference to the parent orchestration's subject when orchestrations are nested or chained.
24
- * This enables hierarchical orchestration patterns where one orchestration can spawn
25
- * sub-orchestrations. When the current orchestration completes, its completion event
26
- * is routed back to this parent subject rather than staying within the current context.
29
+ * Parent orchestration subject for nested workflows.
27
30
  *
28
- * - For root orchestrations: null
29
- * - For nested orchestrations: contains the subject of the parent orchestration
30
- * - Extracted from the `parentSubject$$` field in initialization events
31
+ * Enables hierarchical orchestration patterns where one orchestration spawns
32
+ * sub-orchestrations. When the current orchestration completes, its completion
33
+ * event routes back to this parent subject.
34
+ *
35
+ * - Root orchestrations: `null`
36
+ * - Nested orchestrations: parent's subject identifier
37
+ * - Source: `parentSubject$$` field in initialization events
31
38
  */
32
39
  parentSubject: string | null;
33
40
  /**
34
- * The unique identifier of the event that originally initiated this entire orchestration workflow.
35
- * This serves as the root identifier for tracking the complete execution chain from start to finish.
41
+ * ID of the event that initiated this orchestration workflow.
36
42
  *
37
- * - For new orchestrations: set to the current event's ID
38
- * - For resumed orchestrations: retrieved from the stored state
39
- * - Used as the `parentid` for completion events to create a direct lineage back to the workflow's origin
43
+ * Serves as the root identifier for tracing the complete execution chain.
44
+ * Used as `parentid` for completion events to maintain lineage back to
45
+ * the workflow's origin.
40
46
  *
41
- * This enables tracing the entire execution path and ensures completion events reference
42
- * the original triggering event rather than just the immediate previous step.
47
+ * - New orchestrations: set to current event's ID
48
+ * - Resumed orchestrations: retrieved from stored state
43
49
  */
44
50
  initEventId: string;
45
51
  /**
46
- * Current execution status of the machine. The status field represents the current
47
- * state of the machine's lifecycle. While commonly used values are:
48
- * - 'active': Machine is currently executing
49
- * - 'done': Machine has completed its execution successfully
50
- * - 'error': Machine encountered an error during execution
51
- * - 'stopped': Machine execution was explicitly stopped
52
+ * Current machine execution status.
53
+ *
54
+ * Common values include:
55
+ * - `'active'`: Machine is executing
56
+ * - `'done'`: Machine completed successfully
57
+ * - `'error'`: Machine encountered an error
58
+ * - `'stopped'`: Machine was explicitly stopped
52
59
  *
53
- * Due to XState dependency, the status can be any string value defined in the
54
- * state machine definition. This allows for custom states specific to the
55
- * business logic implemented in the state machine.
60
+ * Custom values can be defined in the state machine configuration.
56
61
  */
57
62
  status: string;
58
- /** Current value stored in the machine state */
63
+ /** Current state value (string for simple states, object for compound states) */
59
64
  value: string | Record<string, any> | null;
60
- /** XState snapshot representing the machine's current state */
65
+ /** XState snapshot representing the complete machine state */
61
66
  state: Snapshot<any>;
67
+ /**
68
+ * Event history from the last execution session.
69
+ */
62
70
  events: {
63
- /** The event consumed by the machine in the last session */
71
+ /** Event consumed by the machine in the last session */
64
72
  consumed: InferArvoEvent<ArvoEvent> | null;
65
- /**
66
- * The events produced by the machine in the last session
67
- */
73
+ /** Events produced by the machine in the last session */
68
74
  produced: InferArvoEvent<ArvoEvent>[];
69
75
  };
70
- /** Machine definition string */
76
+ /** Serialized machine definition for debugging and inspection */
71
77
  machineDefinition: string | null;
72
78
  }>;
73
79
  /**
74
- * Interface defining the core components of an Arvo orchestrator.
80
+ * Configuration parameters for ArvoOrchestrator constructor.
81
+ *
82
+ * Defines all required components and settings for orchestrator initialization.
83
+ * For simplified creation with default components, use {@link createArvoOrchestrator}.
75
84
  */
76
85
  export type ArvoOrchestratorParam = {
77
- /** The cost of the execution of the orchestrator */
86
+ /** Computational cost metric assigned to orchestrator operations */
78
87
  executionunits: number;
79
- /** Memory interface for storing and retrieving machine state */
88
+ /** Memory interface for state persistence and retrieval */
80
89
  memory: IMachineMemory<MachineMemoryRecord>;
81
90
  /** Registry for managing and resolving machine instances */
82
91
  registry: IMachineRegistry;
83
- /** Engine responsible for machine execution */
92
+ /** Engine responsible for executing state machine logic */
84
93
  executionEngine: IMachineExectionEngine;
94
+ /** Whether to enforce resource locking for concurrent safety */
85
95
  requiresResourceLocking: boolean;
86
96
  /**
87
- * Optional configuration to customize where system error events are emitted.
97
+ * Optional domains for system error event routing.
88
98
  *
89
- * This overrides the default system error domain fallback of:
99
+ * Overrides the default fallback sequence of:
90
100
  * `[event.domain, self.contract.domain, null]`
91
101
  *
92
- * Use this to precisely control the set of domains that should receive structured
93
- * `sys.*.error` events when uncaught exceptions occur in the handler.
102
+ * Controls where structured `sys.*.error` events are emitted when
103
+ * uncaught exceptions occur. Supports symbolic constants from {@link ArvoDomain}.
94
104
  *
95
- * Symbolic constants from {@link ArvoDomain} are supported.
96
- *
97
- * @default undefined — uses standard fallback broadcast domains
105
+ * @default undefined - uses standard fallback broadcast domains
98
106
  */
99
107
  systemErrorDomain?: (string | null)[];
100
- /**
101
- * The OpenTelemetry span options
102
- */
108
+ /** OpenTelemetry span configuration for distributed tracing */
103
109
  spanOptions?: ArvoEventHandlerOtelSpanOptions;
104
110
  };
105
111
  /**
106
- * Configuration interface for creating an Arvo orchestrator instance.
112
+ * Configuration parameters for creating an orchestrator via factory function.
113
+ *
114
+ * Simplified interface for {@link createArvoOrchestrator} that automatically
115
+ * constructs default registry and execution engine components.
107
116
  */
108
117
  export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | 'systemErrorDomain'> & {
109
118
  /**
110
- * Collection of state machines to be managed by the orchestrator.
111
- * All machines must have the same source identifier.
119
+ * Optional override for resource locking requirement.
120
+ *
121
+ * When undefined, locking is automatically enabled if any machine requires it.
122
+ * Explicitly set to control locking behavior regardless of machine requirements.
123
+ *
124
+ * Resource locking is needed when:
125
+ * - Machines contain parallel states with simultaneous active states
126
+ * - Preventing race conditions in concurrent event processing
127
+ * - Maintaining state consistency across distributed executions
128
+ *
129
+ * @default undefined - auto-determined from machines
130
+ */
131
+ requiresResourceLocking?: ArvoOrchestratorParam['requiresResourceLocking'];
132
+ /**
133
+ * State machines to register with the orchestrator.
134
+ *
135
+ * All machines must share the same source identifier and have unique versions.
136
+ * At least one machine is required.
112
137
  */
113
138
  machines: ArvoMachine<any, any, any, any, any>[];
114
139
  };
@@ -1,44 +1,39 @@
1
1
  import type { ArvoOrchestratorContract, VersionedArvoContract } from 'arvo-core';
2
2
  import { ArvoResumable } from '.';
3
- import type { IMachineMemory } from '../MachineMemory/interface';
4
- import type { ArvoEventHandlerOtelSpanOptions } from '../types';
5
- import type { ArvoResumableHandler, ArvoResumableState } from './types';
3
+ import type { CreateArvoResumableParam } from './types';
6
4
  /**
7
- * Factory function for creating ArvoResumable orchestrator instances
5
+ * Creates a new {@link ArvoResumable} orchestrator instance.
8
6
  *
9
- * Creates a new ArvoResumable orchestrator with type safety and sensible defaults.
10
- * ArvoResumable provides handler-based workflow orchestration with explicit context management,
11
- * contract validation, and distributed locking capabilities.
7
+ * Factory function that constructs a resumable workflow handler with automatic
8
+ * resource locking determination and contract validation. Validates that service
9
+ * contracts have unique URIs and no circular dependencies exist.
12
10
  *
13
- * @param param - Configuration object for the orchestrator
14
- * @param param.types - Optional type hints for better TypeScript inference
15
- * @param param.types.context - Partial type hint for the workflow context structure (not used at runtime)
16
- * @param param.contracts - Contract definitions for the orchestrator and its services
17
- * @param param.contracts.self - The orchestrator's own contract defining accepted events and emitted events
18
- * @param param.contracts.services - Record of service contracts this orchestrator can invoke, keyed by service name
19
- * @param param.memory - Generic memory interface for state persistence, locking, and retrieval operations
20
- * @param param.handler - Versioned orchestration logic handlers mapped by semantic version
21
- * @param param.executionunits - Resource allocation cost for this orchestrator's execution (default: 0)
22
- * @param param.requiresResourceLocking - Enable distributed locking for concurrent safety (default: auto-determined by service count)
23
- * @param param.systemErrorDomain - The domain override of the system error events. (default [event.domain, self.contract.domain, null])
11
+ * @param param - Configuration parameters for the resumable
12
+ * @returns Configured ArvoResumable instance ready for event handling
24
13
  *
25
- * @returns A new ArvoResumable orchestrator instance configured with the provided parameters
14
+ * @throws {ConfigViolation} When service contracts have duplicate URIs
15
+ * @throws {ConfigViolation} When circular dependency detected (self contract registered as service)
26
16
  *
27
- * @throws {Error} Service contracts have duplicate URIs - Multiple versions of the same contract are not allowed
28
- * @throws {Error} Circular dependency detected - Self contract is registered as a service, creating execution loops
17
+ * @example
18
+ * ```typescript
19
+ * const resumable = createArvoResumable({
20
+ * contracts: {
21
+ * self: myOrchestratorContract,
22
+ * services: {
23
+ * userService: userContract.version('1.0.0'),
24
+ * paymentService: paymentContract.version('1.0.0') }
25
+ * },
26
+ * memory: new SimpleMachineMemory(),
27
+ * handler: {
28
+ * '1.0.0': async ({ input, service, context }) => {
29
+ * // Handler implementation
30
+ * }
31
+ * },
32
+ * executionunits: 1
33
+ * });
34
+ * ```
35
+ *
36
+ * @see {@link ArvoResumable} For the orchestrator class documentation
37
+ * @see {@link ArvoResumableHandler} For handler interface details
29
38
  */
30
- export declare const createArvoResumable: <TMemory extends Record<string, any>, TSelfContract extends ArvoOrchestratorContract = ArvoOrchestratorContract, TServiceContract extends Record<string, VersionedArvoContract<any, any>> = Record<string, VersionedArvoContract<any, any>>>(param: {
31
- types?: {
32
- context?: Partial<TMemory>;
33
- };
34
- contracts: {
35
- self: TSelfContract;
36
- services: TServiceContract;
37
- };
38
- memory: IMachineMemory<Record<string, any>>;
39
- handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
40
- executionunits?: number;
41
- requiresResourceLocking?: boolean;
42
- systemErrorDomain?: (string | null)[];
43
- spanOptions?: ArvoEventHandlerOtelSpanOptions;
44
- }) => ArvoResumable<TMemory, TSelfContract, TServiceContract>;
39
+ export declare const createArvoResumable: <TMemory extends Record<string, any> = Record<string, any>, TSelfContract extends ArvoOrchestratorContract = ArvoOrchestratorContract, TServiceContract extends Record<string, VersionedArvoContract<any, any>> = Record<string, VersionedArvoContract<any, any>>>(param: CreateArvoResumableParam<TMemory, TSelfContract, TServiceContract>) => ArvoResumable<TMemory, TSelfContract, TServiceContract>;
@@ -4,28 +4,39 @@ exports.createArvoResumable = void 0;
4
4
  var _1 = require(".");
5
5
  var servicesValidation_1 = require("../ArvoOrchestrationUtils/servicesValidation");
6
6
  /**
7
- * Factory function for creating ArvoResumable orchestrator instances
7
+ * Creates a new {@link ArvoResumable} orchestrator instance.
8
8
  *
9
- * Creates a new ArvoResumable orchestrator with type safety and sensible defaults.
10
- * ArvoResumable provides handler-based workflow orchestration with explicit context management,
11
- * contract validation, and distributed locking capabilities.
9
+ * Factory function that constructs a resumable workflow handler with automatic
10
+ * resource locking determination and contract validation. Validates that service
11
+ * contracts have unique URIs and no circular dependencies exist.
12
12
  *
13
- * @param param - Configuration object for the orchestrator
14
- * @param param.types - Optional type hints for better TypeScript inference
15
- * @param param.types.context - Partial type hint for the workflow context structure (not used at runtime)
16
- * @param param.contracts - Contract definitions for the orchestrator and its services
17
- * @param param.contracts.self - The orchestrator's own contract defining accepted events and emitted events
18
- * @param param.contracts.services - Record of service contracts this orchestrator can invoke, keyed by service name
19
- * @param param.memory - Generic memory interface for state persistence, locking, and retrieval operations
20
- * @param param.handler - Versioned orchestration logic handlers mapped by semantic version
21
- * @param param.executionunits - Resource allocation cost for this orchestrator's execution (default: 0)
22
- * @param param.requiresResourceLocking - Enable distributed locking for concurrent safety (default: auto-determined by service count)
23
- * @param param.systemErrorDomain - The domain override of the system error events. (default [event.domain, self.contract.domain, null])
13
+ * @param param - Configuration parameters for the resumable
14
+ * @returns Configured ArvoResumable instance ready for event handling
24
15
  *
25
- * @returns A new ArvoResumable orchestrator instance configured with the provided parameters
16
+ * @throws {ConfigViolation} When service contracts have duplicate URIs
17
+ * @throws {ConfigViolation} When circular dependency detected (self contract registered as service)
26
18
  *
27
- * @throws {Error} Service contracts have duplicate URIs - Multiple versions of the same contract are not allowed
28
- * @throws {Error} Circular dependency detected - Self contract is registered as a service, creating execution loops
19
+ * @example
20
+ * ```typescript
21
+ * const resumable = createArvoResumable({
22
+ * contracts: {
23
+ * self: myOrchestratorContract,
24
+ * services: {
25
+ * userService: userContract.version('1.0.0'),
26
+ * paymentService: paymentContract.version('1.0.0') }
27
+ * },
28
+ * memory: new SimpleMachineMemory(),
29
+ * handler: {
30
+ * '1.0.0': async ({ input, service, context }) => {
31
+ * // Handler implementation
32
+ * }
33
+ * },
34
+ * executionunits: 1
35
+ * });
36
+ * ```
37
+ *
38
+ * @see {@link ArvoResumable} For the orchestrator class documentation
39
+ * @see {@link ArvoResumableHandler} For handler interface details
29
40
  */
30
41
  var createArvoResumable = function (param) {
31
42
  var _a, _b;
@@ -1,98 +1,102 @@
1
1
  import { type Span } from '@opentelemetry/api';
2
2
  import { type ArvoEvent, type ArvoOrchestratorContract, type VersionedArvoContract } from 'arvo-core';
3
- import type { z } from 'zod';
3
+ import { type EventValidationResult } from '../ArvoOrchestrationUtils/inputValidation';
4
4
  import type IArvoEventHandler from '../IArvoEventHandler';
5
5
  import type { IMachineMemory } from '../MachineMemory/interface';
6
6
  import { SyncEventResource } from '../SyncEventResource/index';
7
7
  import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
8
- import type { ArvoResumableHandler, ArvoResumableState } from './types';
8
+ import type { ArvoResumableHandler, ArvoResumableParam, ArvoResumableState } from './types';
9
9
  /**
10
- * ArvoResumable - A stateful orchestration handler for managing distributed workflows
10
+ * ArvoResumable complements {@link ArvoOrchestrator} by providing imperative
11
+ * handler functions for orchestration logic instead of declarative state machines.
12
+ * While ArvoOrchestrator excels at complex static workflows with deterministic
13
+ * branching, ArvoResumable handles dynamic orchestrations where branching logic
14
+ * depends on runtime context and event data.
11
15
  *
12
- * ArvoResumable provides a handler-based approach to workflow orchestration that prioritizes
13
- * explicit control and simplicity over declarative abstractions. It excels at straightforward
14
- * request-response patterns and linear workflows while maintaining full type safety and
15
- * contract validation throughout the execution lifecycle.
16
- *
17
- * This class addresses fundamental issues in event-driven architecture including:
18
- * - Contract management with runtime validation and type safety
19
- * - Graduated complexity allowing simple workflows to remain simple
20
- * - Unified event handling across initialization and service responses
21
- * - Explicit state management without hidden abstractions
22
- *
23
- * Key capabilities:
24
- * - Handler-based workflow orchestration with explicit state control
25
- * - Contract-driven event validation with runtime schema enforcement
26
- * - Distributed resource locking for transaction safety
27
- * - Comprehensive OpenTelemetry integration for observability
28
- * - Automatic error handling with system error event generation
29
- * - Support for orchestrator chaining and nested workflow patterns
30
- * - Domain-based event routing and organization
31
- *
32
- * Unlike state machine approaches, ArvoResumable uses imperative handler functions
33
- * that provide direct control over workflow logic. This makes debugging easier and
34
- * reduces the learning curve for teams familiar with traditional programming patterns.
35
- *
36
- * @see {@link createArvoResumable} Factory function for creating instances
37
- * @see {@link ArvoResumableHandler} Handler interface documentation
38
- * @see {@link ArvoResumableState} State structure documentation
16
+ * Use this for dynamic orchestrations with context-dependent branching
17
+ * or when preferring imperative programming patterns over state machines.
39
18
  */
40
19
  export declare class ArvoResumable<TMemory extends Record<string, any> = Record<string, any>, TSelfContract extends ArvoOrchestratorContract = ArvoOrchestratorContract, TServiceContract extends Record<string, VersionedArvoContract<any, any>> = Record<string, VersionedArvoContract<any, any>>> implements IArvoEventHandler {
20
+ /** Computational cost metric for workflow operations */
41
21
  readonly executionunits: number;
22
+ /** Resource manager for state synchronization and memory access */
42
23
  readonly syncEventResource: SyncEventResource<ArvoResumableState<TMemory>>;
43
- readonly source: string;
24
+ /** Versioned handler map for processing workflow events. */
44
25
  readonly handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
26
+ /** Optional domains for routing system error events */
45
27
  readonly systemErrorDomain?: (string | null)[];
46
- private readonly spanOptions;
28
+ /** OpenTelemetry span configuration for observability */
29
+ readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
30
+ /** Source identifier from the first registered machine */
31
+ readonly source: string;
32
+ /**
33
+ * Contract definitions for the resumable's event interface.
34
+ * Defines accepted events, emitted events, and service integrations.
35
+ */
47
36
  readonly contracts: {
37
+ /**
38
+ * Self contract defining initialization input and completion output structures.
39
+ */
48
40
  self: TSelfContract;
41
+ /**
42
+ * Service contracts defining external service interfaces.
43
+ */
49
44
  services: TServiceContract;
50
45
  };
46
+ /** Whether this resumable requires resource locking for concurrent safety */
51
47
  get requiresResourceLocking(): boolean;
48
+ /** Memory interface for state persistence and retrieval */
52
49
  get memory(): IMachineMemory<ArvoResumableState<TMemory>>;
50
+ /** The contract-defined domain for the handler */
53
51
  get domain(): string | null;
54
- constructor(param: {
55
- contracts: {
56
- self: TSelfContract;
57
- services: TServiceContract;
58
- };
59
- executionunits: number;
60
- memory: IMachineMemory<ArvoResumableState<TMemory>>;
61
- requiresResourceLocking?: boolean;
62
- handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
63
- systemErrorDomain?: (string | null)[];
64
- spanOptions?: ArvoEventHandlerOtelSpanOptions;
65
- });
66
- protected validateInput(event: ArvoEvent, span: Span): {
67
- contractType: 'self' | 'service';
68
- };
52
+ constructor(param: ArvoResumableParam<TMemory, TSelfContract, TServiceContract>);
69
53
  /**
70
- * Executes the orchestration workflow for an incoming event
54
+ * Validates incoming event against self or service contracts.
55
+ *
56
+ * Resolves the appropriate contract (self for initialization, service for responses),
57
+ * validates schema compatibility, and ensures event data matches contract requirements.
71
58
  *
72
- * @param event - The triggering event to process
73
- * @param opentelemetry - OpenTelemetry configuration for trace inheritance
59
+ * See {@link validateInputEvent} for more infromation
60
+ */
61
+ protected validateInput(event: ArvoEvent, span?: Span): EventValidationResult;
62
+ /**
63
+ * Executes the workflow handler for an incoming event.
74
64
  *
75
- * @returns Object containing domained events
65
+ * Processes initialization events or service responses through the versioned handler,
66
+ * manages state persistence, tracks expected events, and generates output events.
67
+ * Workflows in 'done' status ignore subsequent events without processing.
68
+ *
69
+ * For violation errors (transaction, config, contract), the error is thrown to enable
70
+ * retry mechanisms. For non-violation errors, system error events are emitted to the
71
+ * workflow initiator, and the workflow enters a terminal failure state.
72
+ *
73
+ * @param event - The incoming event triggering handler execution
74
+ * @param opentelemetry - Optional OpenTelemetry configuration for tracing
75
+ * @returns Object containing emitted events from the handler or system errors
76
76
  *
77
77
  * @throws {TransactionViolation} When distributed lock acquisition fails
78
78
  * @throws {ConfigViolation} When handler resolution or contract validation fails
79
79
  * @throws {ContractViolation} When event schema validation fails
80
- * @throws {ExecutionViolation} When workflow execution encounters critical errors
80
+ * @throws {ExecutionViolation} When workflow execution encounters critical errors defined by the handler developer
81
81
  */
82
82
  execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
83
83
  events: ArvoEvent[];
84
84
  }>;
85
- get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.arvo.orc.${string}.error`, z.ZodObject<{
86
- errorName: z.ZodString;
87
- errorMessage: z.ZodString;
88
- errorStack: z.ZodNullable<z.ZodString>;
89
- }, "strip", z.ZodTypeAny, {
90
- errorName: string;
91
- errorMessage: string;
92
- errorStack: string | null;
93
- }, {
94
- errorName: string;
95
- errorMessage: string;
96
- errorStack: string | null;
97
- }>>;
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
+ };
98
102
  }