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.
- package/dist/ArvoEventHandler/index.d.ts +20 -123
- package/dist/ArvoEventHandler/index.js +5 -112
- package/dist/ArvoMachine/createMachine.d.ts +103 -158
- package/dist/ArvoMachine/createMachine.js +59 -181
- package/dist/ArvoMachine/index.d.ts +5 -57
- package/dist/ArvoMachine/index.js +8 -117
- package/dist/ArvoMachine/types.d.ts +0 -82
- package/dist/ArvoMachine/utils.d.ts +0 -15
- package/dist/ArvoMachine/utils.js +0 -15
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.d.ts +31 -0
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +18 -0
- package/dist/ArvoOrchestrationUtils/error.d.ts +22 -0
- package/dist/ArvoOrchestrationUtils/error.js +21 -0
- package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +32 -4
- package/dist/ArvoOrchestrationUtils/handlerErrors.js +19 -2
- package/dist/ArvoOrchestrationUtils/inputValidation.d.ts +47 -0
- package/dist/ArvoOrchestrationUtils/inputValidation.js +120 -0
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.d.ts +24 -1
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionState.js +9 -1
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.d.ts +5 -1
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.js +5 -1
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +44 -5
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +17 -5
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.d.ts +6 -1
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.js +6 -1
- package/dist/ArvoOrchestrationUtils/servicesValidation.d.ts +14 -6
- package/dist/ArvoOrchestrationUtils/servicesValidation.js +14 -6
- package/dist/ArvoOrchestrator/factory.d.ts +18 -15
- package/dist/ArvoOrchestrator/factory.js +19 -16
- package/dist/ArvoOrchestrator/index.d.ts +51 -19
- package/dist/ArvoOrchestrator/index.js +29 -17
- package/dist/ArvoOrchestrator/types.d.ts +74 -49
- package/dist/ArvoResumable/factory.d.ts +31 -36
- package/dist/ArvoResumable/factory.js +29 -18
- package/dist/ArvoResumable/index.d.ts +69 -65
- package/dist/ArvoResumable/index.js +49 -92
- package/dist/ArvoResumable/types.d.ts +177 -72
- package/dist/IArvoEventHandler/index.d.ts +29 -15
- 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
|
-
*
|
|
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
|
|
26
|
+
/** Unique identifier for this orchestration instance */
|
|
21
27
|
subject: string;
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
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
|
-
*
|
|
29
|
-
* -
|
|
30
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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
|
-
*
|
|
42
|
-
*
|
|
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
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* - '
|
|
50
|
-
* - '
|
|
51
|
-
* - '
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
76
|
+
/** Serialized machine definition for debugging and inspection */
|
|
71
77
|
machineDefinition: string | null;
|
|
72
78
|
}>;
|
|
73
79
|
/**
|
|
74
|
-
*
|
|
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
|
-
/**
|
|
86
|
+
/** Computational cost metric assigned to orchestrator operations */
|
|
78
87
|
executionunits: number;
|
|
79
|
-
/** Memory interface for
|
|
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
|
|
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
|
|
97
|
+
* Optional domains for system error event routing.
|
|
88
98
|
*
|
|
89
|
-
*
|
|
99
|
+
* Overrides the default fallback sequence of:
|
|
90
100
|
* `[event.domain, self.contract.domain, null]`
|
|
91
101
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
102
|
+
* Controls where structured `sys.*.error` events are emitted when
|
|
103
|
+
* uncaught exceptions occur. Supports symbolic constants from {@link ArvoDomain}.
|
|
94
104
|
*
|
|
95
|
-
*
|
|
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
|
|
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
|
-
*
|
|
111
|
-
*
|
|
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 {
|
|
4
|
-
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
5
|
-
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
3
|
+
import type { CreateArvoResumableParam } from './types';
|
|
6
4
|
/**
|
|
7
|
-
*
|
|
5
|
+
* Creates a new {@link ArvoResumable} orchestrator instance.
|
|
8
6
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
14
|
-
* @
|
|
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
|
-
* @
|
|
14
|
+
* @throws {ConfigViolation} When service contracts have duplicate URIs
|
|
15
|
+
* @throws {ConfigViolation} When circular dependency detected (self contract registered as service)
|
|
26
16
|
*
|
|
27
|
-
* @
|
|
28
|
-
*
|
|
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
|
-
*
|
|
7
|
+
* Creates a new {@link ArvoResumable} orchestrator instance.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
|
14
|
-
* @
|
|
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
|
-
* @
|
|
16
|
+
* @throws {ConfigViolation} When service contracts have duplicate URIs
|
|
17
|
+
* @throws {ConfigViolation} When circular dependency detected (self contract registered as service)
|
|
26
18
|
*
|
|
27
|
-
* @
|
|
28
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
13
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
73
|
-
|
|
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
|
-
*
|
|
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():
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
}
|