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
|
@@ -1,7 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enumeration of possible orchestration execution statuses.
|
|
3
|
+
*
|
|
4
|
+
* Determines whether an orchestration is executing normally or has encountered
|
|
5
|
+
* a terminal failure requiring error event emission.
|
|
6
|
+
*/
|
|
1
7
|
export declare const OrchestrationExecutionStatus: {
|
|
2
|
-
|
|
8
|
+
/** Orchestration is executing normally */
|
|
3
9
|
readonly NORMAL: "normal";
|
|
10
|
+
/** Orchestration has failed and entered terminal error state */
|
|
11
|
+
readonly FAILURE: "failure";
|
|
4
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Discriminated union representing persisted orchestration state.
|
|
15
|
+
*
|
|
16
|
+
* The execution status discriminates between normal execution state (containing
|
|
17
|
+
* full orchestration data) and failure state (containing minimal error context).
|
|
18
|
+
*
|
|
19
|
+
* **Normal state**: Contains complete orchestration data including machine state,
|
|
20
|
+
* event history, and all custom fields from type parameter T.
|
|
21
|
+
*
|
|
22
|
+
* **Failure state**: Contains only essential error information (error object, subject)
|
|
23
|
+
* with partial custom fields. Once in failure state, the orchestration ignores
|
|
24
|
+
* subsequent events and does not execute further.
|
|
25
|
+
*
|
|
26
|
+
* @template T - Custom state fields specific to the orchestration type
|
|
27
|
+
*/
|
|
5
28
|
export type OrchestrationExecutionMemoryRecord<T extends Record<string, unknown>> = (T & {
|
|
6
29
|
executionStatus: typeof OrchestrationExecutionStatus.NORMAL;
|
|
7
30
|
}) | (Partial<T> & {
|
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.OrchestrationExecutionStatus = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enumeration of possible orchestration execution statuses.
|
|
6
|
+
*
|
|
7
|
+
* Determines whether an orchestration is executing normally or has encountered
|
|
8
|
+
* a terminal failure requiring error event emission.
|
|
9
|
+
*/
|
|
4
10
|
exports.OrchestrationExecutionStatus = {
|
|
5
|
-
|
|
11
|
+
/** Orchestration is executing normally */
|
|
6
12
|
NORMAL: 'normal',
|
|
13
|
+
/** Orchestration has failed and entered terminal error state */
|
|
14
|
+
FAILURE: 'failure',
|
|
7
15
|
};
|
package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.d.ts
CHANGED
|
@@ -3,6 +3,10 @@ import { type ArvoEvent } from 'arvo-core';
|
|
|
3
3
|
import type { SyncEventResource } from '../../SyncEventResource';
|
|
4
4
|
import type { AcquiredLockStatusType } from '../../SyncEventResource/types';
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* Acquires an exclusive lock for event processing with validation.
|
|
7
|
+
*
|
|
8
|
+
* Attempts to obtain a lock on the event's subject to ensure exclusive access during
|
|
9
|
+
* processing. Throws if lock cannot be acquired, preventing concurrent modifications.
|
|
10
|
+
* @throws {TransactionViolation} When lock cannot be acquired
|
|
7
11
|
*/
|
|
8
12
|
export declare const acquireLockWithValidation: (syncEventResource: SyncEventResource<Record<string, any>>, event: ArvoEvent, span: Span) => Promise<AcquiredLockStatusType>;
|
package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/acquireLockWithValidation.js
CHANGED
|
@@ -40,7 +40,11 @@ exports.acquireLockWithValidation = void 0;
|
|
|
40
40
|
var arvo_core_1 = require("arvo-core");
|
|
41
41
|
var error_1 = require("../error");
|
|
42
42
|
/**
|
|
43
|
-
*
|
|
43
|
+
* Acquires an exclusive lock for event processing with validation.
|
|
44
|
+
*
|
|
45
|
+
* Attempts to obtain a lock on the event's subject to ensure exclusive access during
|
|
46
|
+
* processing. Throws if lock cannot be acquired, preventing concurrent modifications.
|
|
47
|
+
* @throws {TransactionViolation} When lock cannot be acquired
|
|
44
48
|
*/
|
|
45
49
|
var acquireLockWithValidation = function (syncEventResource, event, span) { return __awaiter(void 0, void 0, void 0, function () {
|
|
46
50
|
var acquiredLock;
|
|
@@ -5,38 +5,77 @@ import type { SyncEventResource } from '../../SyncEventResource';
|
|
|
5
5
|
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../../types';
|
|
6
6
|
import type { OrchestrationExecutionMemoryRecord } from '../orchestrationExecutionState';
|
|
7
7
|
import type { ArvoOrchestrationHandlerType } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Configuration context for orchestration execution.
|
|
10
|
+
* Contains all resources and settings needed for the execution lifecycle.
|
|
11
|
+
*/
|
|
8
12
|
export type OrchestrationExecutionContext<TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>> = {
|
|
13
|
+
/** Event triggering the orchestration */
|
|
9
14
|
event: ArvoEvent;
|
|
15
|
+
/** OpenTelemetry configuration for tracing */
|
|
10
16
|
opentelemetry: ArvoEventHandlerOpenTelemetryOptions;
|
|
17
|
+
/** Source identifier for the orchestrator */
|
|
11
18
|
source: string;
|
|
19
|
+
/** Resource manager for state and lock operations */
|
|
12
20
|
syncEventResource: SyncEventResource<TState>;
|
|
21
|
+
/** Maximum execution units per cycle */
|
|
13
22
|
executionunits: number;
|
|
23
|
+
/** Optional domains for system error routing */
|
|
14
24
|
systemErrorDomain?: (string | null)[];
|
|
25
|
+
/** Self contract defining orchestrator interface */
|
|
15
26
|
selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
|
|
27
|
+
/** Domain for event routing */
|
|
16
28
|
domain: string | null;
|
|
29
|
+
/** Type of orchestration handler */
|
|
17
30
|
_handlerType: ArvoOrchestrationHandlerType;
|
|
31
|
+
/** OpenTelemetry span configuration */
|
|
18
32
|
spanOptions: ArvoEventHandlerOtelSpanOptions & {
|
|
19
33
|
spanName: NonNullable<ArvoEventHandlerOtelSpanOptions['spanName']>;
|
|
20
34
|
};
|
|
21
35
|
};
|
|
36
|
+
/**
|
|
37
|
+
* Core execution function signature for orchestration logic.
|
|
38
|
+
* Receives prepared context and returns emitted events with new state.
|
|
39
|
+
*/
|
|
22
40
|
export type CoreExecutionFn<TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>> = (params: {
|
|
41
|
+
/** OpenTelemetry span for tracing */
|
|
23
42
|
span: any;
|
|
43
|
+
/** Current OpenTelemetry headers */
|
|
24
44
|
otelHeaders: OpenTelemetryHeaders;
|
|
45
|
+
/** Parent orchestration subject if nested */
|
|
25
46
|
orchestrationParentSubject: string | null;
|
|
47
|
+
/** ID of the initialization event */
|
|
26
48
|
initEventId: string;
|
|
49
|
+
/** Parsed event subject content */
|
|
27
50
|
parsedEventSubject: ArvoOrchestrationSubjectContent;
|
|
51
|
+
/** Current persisted state or null for new orchestrations */
|
|
28
52
|
state: TState | null;
|
|
53
|
+
/** Type of handler executing */
|
|
29
54
|
_handlerType: ArvoOrchestrationHandlerType;
|
|
30
55
|
}) => Promise<{
|
|
56
|
+
/** Events to emit from this execution */
|
|
31
57
|
emittables: ArvoEvent[];
|
|
58
|
+
/** New state to persist */
|
|
32
59
|
newState: TState;
|
|
33
60
|
}>;
|
|
61
|
+
/**
|
|
62
|
+
* Helper to log and return execution results.
|
|
63
|
+
* @returns The same result after logging
|
|
64
|
+
*/
|
|
34
65
|
export declare const returnEventsWithLogging: (param: Awaited<ReturnType<IArvoEventHandler["execute"]>>, span: Span) => Awaited<ReturnType<IArvoEventHandler["execute"]>>;
|
|
35
66
|
/**
|
|
36
|
-
* Wraps orchestration execution with
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* -
|
|
40
|
-
* -
|
|
67
|
+
* Wraps orchestration execution with infrastructure concerns.
|
|
68
|
+
*
|
|
69
|
+
* Provides a complete execution wrapper that handles:
|
|
70
|
+
* - OpenTelemetry span creation and management
|
|
71
|
+
* - Event subject validation and parsing
|
|
72
|
+
* - Lock acquisition for concurrent safety
|
|
73
|
+
* - State retrieval and persistence
|
|
74
|
+
* - Error handling with system error event generation
|
|
75
|
+
* - Lock release in all scenarios
|
|
76
|
+
*
|
|
77
|
+
* This wrapper ensures consistent behavior across all orchestration handlers
|
|
78
|
+
* while allowing custom core logic via the execution function parameter.
|
|
79
|
+
* @returns Emitted events from successful execution or error handling
|
|
41
80
|
*/
|
|
42
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"]>>>;
|
|
@@ -54,6 +54,10 @@ var utils_1 = require("../../utils");
|
|
|
54
54
|
var handlerErrors_1 = require("../handlerErrors");
|
|
55
55
|
var acquireLockWithValidation_1 = require("./acquireLockWithValidation");
|
|
56
56
|
var validateAndParseSubject_1 = require("./validateAndParseSubject");
|
|
57
|
+
/**
|
|
58
|
+
* Helper to log and return execution results.
|
|
59
|
+
* @returns The same result after logging
|
|
60
|
+
*/
|
|
57
61
|
var returnEventsWithLogging = function (param, span) {
|
|
58
62
|
var _a, _b;
|
|
59
63
|
(0, arvo_core_1.logToSpan)({
|
|
@@ -64,11 +68,19 @@ var returnEventsWithLogging = function (param, span) {
|
|
|
64
68
|
};
|
|
65
69
|
exports.returnEventsWithLogging = returnEventsWithLogging;
|
|
66
70
|
/**
|
|
67
|
-
* Wraps orchestration execution with
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
* -
|
|
71
|
-
* -
|
|
71
|
+
* Wraps orchestration execution with infrastructure concerns.
|
|
72
|
+
*
|
|
73
|
+
* Provides a complete execution wrapper that handles:
|
|
74
|
+
* - OpenTelemetry span creation and management
|
|
75
|
+
* - Event subject validation and parsing
|
|
76
|
+
* - Lock acquisition for concurrent safety
|
|
77
|
+
* - State retrieval and persistence
|
|
78
|
+
* - Error handling with system error event generation
|
|
79
|
+
* - Lock release in all scenarios
|
|
80
|
+
*
|
|
81
|
+
* This wrapper ensures consistent behavior across all orchestration handlers
|
|
82
|
+
* while allowing custom core logic via the execution function parameter.
|
|
83
|
+
* @returns Emitted events from successful execution or error handling
|
|
72
84
|
*/
|
|
73
85
|
var executeWithOrchestrationWrapper = function (_a, coreExecutionFn_1) { return __awaiter(void 0, [_a, coreExecutionFn_1], void 0, function (_b, coreExecutionFn) {
|
|
74
86
|
var otelConfig;
|
package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.d.ts
CHANGED
|
@@ -2,6 +2,11 @@ import type { Span } from '@opentelemetry/api';
|
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestrationSubjectContent } from 'arvo-core';
|
|
3
3
|
import type { SyncEventResource } from '../../SyncEventResource';
|
|
4
4
|
/**
|
|
5
|
-
* Validates and parses orchestration subject
|
|
5
|
+
* Validates and parses an orchestration event's subject.
|
|
6
|
+
*
|
|
7
|
+
* Ensures the event subject is valid and matches the expected orchestrator source.
|
|
8
|
+
* Returns null if validation fails, allowing graceful handling of mismatched events.
|
|
9
|
+
*
|
|
10
|
+
* @returns Parsed subject content or null if validation fails
|
|
6
11
|
*/
|
|
7
12
|
export declare const validateAndParseSubject: (event: ArvoEvent, expectedSource: string, syncEventResource: SyncEventResource<any>, span: Span, handlerType: "orchestrator" | "resumable") => ArvoOrchestrationSubjectContent | null;
|
package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/validateAndParseSubject.js
CHANGED
|
@@ -3,7 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.validateAndParseSubject = void 0;
|
|
4
4
|
var arvo_core_1 = require("arvo-core");
|
|
5
5
|
/**
|
|
6
|
-
* Validates and parses orchestration subject
|
|
6
|
+
* Validates and parses an orchestration event's subject.
|
|
7
|
+
*
|
|
8
|
+
* Ensures the event subject is valid and matches the expected orchestrator source.
|
|
9
|
+
* Returns null if validation fails, allowing graceful handling of mismatched events.
|
|
10
|
+
*
|
|
11
|
+
* @returns Parsed subject content or null if validation fails
|
|
7
12
|
*/
|
|
8
13
|
var validateAndParseSubject = function (event, expectedSource, syncEventResource, span, handlerType) {
|
|
9
14
|
var _a;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type { ArvoContract, VersionedArvoContract } from 'arvo-core';
|
|
2
2
|
import { type ArvoOrchestrationHandlerType } from './types';
|
|
3
3
|
/**
|
|
4
|
-
* Validates that all service contracts
|
|
4
|
+
* Validates that all service contracts have unique URIs.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
* Multiple versions of the same contract (
|
|
8
|
-
*
|
|
9
|
-
* @param contracts - A record mapping contract keys to their respective ArvoContract objects
|
|
10
|
-
* @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
|
|
6
|
+
* Ensures no duplicate contract URIs exist in the service collection.
|
|
7
|
+
* Multiple versions of the same contract (same URI) are not permitted as
|
|
8
|
+
* they create ambiguity in event routing and contract resolution.
|
|
11
9
|
*/
|
|
12
10
|
export declare const areServiceContractsUnique: (contracts: Record<string, ArvoContract | VersionedArvoContract<any, any>>) => {
|
|
13
11
|
result: false;
|
|
@@ -16,6 +14,16 @@ export declare const areServiceContractsUnique: (contracts: Record<string, ArvoC
|
|
|
16
14
|
} | {
|
|
17
15
|
result: true;
|
|
18
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Validates service contracts for orchestration handlers.
|
|
19
|
+
*
|
|
20
|
+
* Performs two critical validations:
|
|
21
|
+
* 1. Ensures all service contracts have unique URIs (no duplicate contracts)
|
|
22
|
+
* 2. Prevents circular dependencies (self contract not registered as service)
|
|
23
|
+
*
|
|
24
|
+
* These validations prevent configuration errors that would cause runtime
|
|
25
|
+
* failures or infinite execution loops in orchestration workflows.
|
|
26
|
+
*/
|
|
19
27
|
export declare const servicesValidation: (contracts: {
|
|
20
28
|
self: ArvoContract | VersionedArvoContract<any, any>;
|
|
21
29
|
services: Record<string, VersionedArvoContract<any, any>>;
|
|
@@ -16,13 +16,11 @@ var uuid_1 = require("uuid");
|
|
|
16
16
|
var errors_1 = require("../errors");
|
|
17
17
|
var types_1 = require("./types");
|
|
18
18
|
/**
|
|
19
|
-
* Validates that all service contracts
|
|
19
|
+
* Validates that all service contracts have unique URIs.
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
* Multiple versions of the same contract (
|
|
23
|
-
*
|
|
24
|
-
* @param contracts - A record mapping contract keys to their respective ArvoContract objects
|
|
25
|
-
* @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
|
|
21
|
+
* Ensures no duplicate contract URIs exist in the service collection.
|
|
22
|
+
* Multiple versions of the same contract (same URI) are not permitted as
|
|
23
|
+
* they create ambiguity in event routing and contract resolution.
|
|
26
24
|
*/
|
|
27
25
|
var areServiceContractsUnique = function (contracts) {
|
|
28
26
|
var uriToKeyMap = {};
|
|
@@ -42,6 +40,16 @@ var areServiceContractsUnique = function (contracts) {
|
|
|
42
40
|
};
|
|
43
41
|
};
|
|
44
42
|
exports.areServiceContractsUnique = areServiceContractsUnique;
|
|
43
|
+
/**
|
|
44
|
+
* Validates service contracts for orchestration handlers.
|
|
45
|
+
*
|
|
46
|
+
* Performs two critical validations:
|
|
47
|
+
* 1. Ensures all service contracts have unique URIs (no duplicate contracts)
|
|
48
|
+
* 2. Prevents circular dependencies (self contract not registered as service)
|
|
49
|
+
*
|
|
50
|
+
* These validations prevent configuration errors that would cause runtime
|
|
51
|
+
* failures or infinite execution loops in orchestration workflows.
|
|
52
|
+
*/
|
|
45
53
|
var servicesValidation = function (contracts, _handlerType) {
|
|
46
54
|
var _a;
|
|
47
55
|
var __areServiceContractsUnique = (0, exports.areServiceContractsUnique)(contracts.services);
|
|
@@ -2,28 +2,31 @@ import { ArvoOrchestrator } from '.';
|
|
|
2
2
|
import type { CreateArvoOrchestratorParam } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new Arvo orchestrator instance with default components.
|
|
5
|
-
* For custom components, use ArvoOrchestrator constructor directly.
|
|
6
5
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @param config.machines - Array of state machines to manage. Their resource locking flags determine orchestrator's locking behavior
|
|
11
|
-
* @param config.systemErrorDomain - An optional array of system error domain overrides
|
|
12
|
-
* @returns Configured ArvoOrchestrator instance with default registry and execution engine
|
|
6
|
+
* Factory function that constructs an orchestrator with standard execution engine
|
|
7
|
+
* and registry implementations. Validates that all machines share the same source
|
|
8
|
+
* identifier and have unique versions.
|
|
13
9
|
*
|
|
14
|
-
* @
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
10
|
+
* @param params - Configuration parameters for the orchestrator
|
|
11
|
+
* @returns Configured ArvoOrchestrator instance ready for event handling
|
|
12
|
+
*
|
|
13
|
+
* @throws {Error} When no machines are provided
|
|
14
|
+
* @throws {ConfigViolation} When machines have different source identifiers
|
|
15
|
+
* @throws {ConfigViolation} When machines have duplicate versions
|
|
19
16
|
*
|
|
20
17
|
* @example
|
|
21
18
|
* ```typescript
|
|
22
19
|
* const orchestrator = createArvoOrchestrator({
|
|
23
|
-
* memory: new SimpleMachineMemory()
|
|
20
|
+
* memory: new SimpleMachineMemory(),
|
|
24
21
|
* executionunits: 1,
|
|
25
|
-
* machines: [
|
|
22
|
+
* machines: [userOnboardingMachine, paymentMachine]
|
|
26
23
|
* });
|
|
24
|
+
*
|
|
25
|
+
* // Process events
|
|
26
|
+
* const result = await orchestrator.execute(event);
|
|
27
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* @see {@link setupArvoMachine} for creating machine definitions
|
|
30
|
+
* @see {@link ArvoOrchestrator} for direct instantiation with custom components
|
|
28
31
|
*/
|
|
29
|
-
export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, spanOptions, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
|
|
32
|
+
export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, spanOptions, requiresResourceLocking: _locking, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
|
|
@@ -16,37 +16,40 @@ var MachineRegistry_1 = require("../MachineRegistry");
|
|
|
16
16
|
var errors_1 = require("../errors");
|
|
17
17
|
/**
|
|
18
18
|
* Creates a new Arvo orchestrator instance with default components.
|
|
19
|
-
* For custom components, use ArvoOrchestrator constructor directly.
|
|
20
19
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* @param config.machines - Array of state machines to manage. Their resource locking flags determine orchestrator's locking behavior
|
|
25
|
-
* @param config.systemErrorDomain - An optional array of system error domain overrides
|
|
26
|
-
* @returns Configured ArvoOrchestrator instance with default registry and execution engine
|
|
20
|
+
* Factory function that constructs an orchestrator with standard execution engine
|
|
21
|
+
* and registry implementations. Validates that all machines share the same source
|
|
22
|
+
* identifier and have unique versions.
|
|
27
23
|
*
|
|
28
|
-
* @
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
24
|
+
* @param params - Configuration parameters for the orchestrator
|
|
25
|
+
* @returns Configured ArvoOrchestrator instance ready for event handling
|
|
26
|
+
*
|
|
27
|
+
* @throws {Error} When no machines are provided
|
|
28
|
+
* @throws {ConfigViolation} When machines have different source identifiers
|
|
29
|
+
* @throws {ConfigViolation} When machines have duplicate versions
|
|
33
30
|
*
|
|
34
31
|
* @example
|
|
35
32
|
* ```typescript
|
|
36
33
|
* const orchestrator = createArvoOrchestrator({
|
|
37
|
-
* memory: new SimpleMachineMemory()
|
|
34
|
+
* memory: new SimpleMachineMemory(),
|
|
38
35
|
* executionunits: 1,
|
|
39
|
-
* machines: [
|
|
36
|
+
* machines: [userOnboardingMachine, paymentMachine]
|
|
40
37
|
* });
|
|
38
|
+
*
|
|
39
|
+
* // Process events
|
|
40
|
+
* const result = await orchestrator.execute(event);
|
|
41
41
|
* ```
|
|
42
|
+
*
|
|
43
|
+
* @see {@link setupArvoMachine} for creating machine definitions
|
|
44
|
+
* @see {@link ArvoOrchestrator} for direct instantiation with custom components
|
|
42
45
|
*/
|
|
43
46
|
var createArvoOrchestrator = function (_a) {
|
|
44
|
-
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
|
|
47
|
+
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions, _locking = _a.requiresResourceLocking;
|
|
45
48
|
if (!(machines === null || machines === void 0 ? void 0 : machines.length)) {
|
|
46
49
|
throw new Error('At least one machine must be provided');
|
|
47
50
|
}
|
|
48
51
|
var registry = new (MachineRegistry_1.MachineRegistry.bind.apply(MachineRegistry_1.MachineRegistry, __spreadArray([void 0], machines, false)))();
|
|
49
|
-
var requiresResourceLocking = machines.some(function (machine) { return machine.requiresResourceLocking; });
|
|
52
|
+
var requiresResourceLocking = _locking !== null && _locking !== void 0 ? _locking : machines.some(function (machine) { return machine.requiresResourceLocking; });
|
|
50
53
|
var representativeMachine = registry.machines[0];
|
|
51
54
|
var lastSeenVersions = [];
|
|
52
55
|
for (var _i = 0, _b = registry.machines; _i < _b.length; _i++) {
|
|
@@ -1,49 +1,81 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type ArvoEvent } from 'arvo-core';
|
|
2
2
|
import type IArvoEventHandler from '../IArvoEventHandler';
|
|
3
3
|
import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
|
|
4
4
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
5
5
|
import type { IMachineRegistry } from '../MachineRegistry/interface';
|
|
6
6
|
import { SyncEventResource } from '../SyncEventResource';
|
|
7
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
7
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
8
8
|
import type { ArvoOrchestratorParam, MachineMemoryRecord } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* Orchestrates state machine execution and lifecycle management.
|
|
11
|
-
*
|
|
11
|
+
*
|
|
12
|
+
* Coordinates machine resolution, state persistence, event processing, and error handling
|
|
13
|
+
* for Arvo's event-driven orchestration workflows. Manages the complete lifecycle from
|
|
14
|
+
* event receipt through machine execution to emitting result events.
|
|
12
15
|
*/
|
|
13
16
|
export declare class ArvoOrchestrator implements IArvoEventHandler {
|
|
17
|
+
/** Computational cost metric associated with event handling operations */
|
|
14
18
|
readonly executionunits: number;
|
|
19
|
+
/** Registry containing available state machines */
|
|
15
20
|
readonly registry: IMachineRegistry;
|
|
21
|
+
/** Engine responsible for executing state machine logic */
|
|
16
22
|
readonly executionEngine: IMachineExectionEngine;
|
|
23
|
+
/** Resource manager for state synchronization and memory access */
|
|
17
24
|
readonly syncEventResource: SyncEventResource<MachineMemoryRecord>;
|
|
25
|
+
/** Optional domains for routing system error events */
|
|
18
26
|
readonly systemErrorDomain?: (string | null)[];
|
|
19
|
-
|
|
27
|
+
/** OpenTelemetry span configuration for observability */
|
|
28
|
+
readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
|
|
29
|
+
/** Source identifier from the first registered machine */
|
|
20
30
|
get source(): any;
|
|
31
|
+
/** Whether this orchestrator requires resource locking for concurrent safety */
|
|
21
32
|
get requiresResourceLocking(): boolean;
|
|
33
|
+
/** Memory interface for state persistence and retrieval */
|
|
22
34
|
get memory(): IMachineMemory<MachineMemoryRecord>;
|
|
35
|
+
/** The contract-defined domain for the handler */
|
|
23
36
|
get domain(): string | null;
|
|
24
|
-
/**
|
|
25
|
-
* Creates a new orchestrator instance
|
|
26
|
-
* @param params - Configuration parameters
|
|
27
|
-
* @throws Error if machines in registry have different sources
|
|
28
|
-
*/
|
|
29
37
|
constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, spanOptions, }: ArvoOrchestratorParam);
|
|
30
38
|
/**
|
|
31
|
-
*
|
|
39
|
+
* Executes state machine orchestration for an incoming event.
|
|
40
|
+
*
|
|
41
|
+
* Performs the complete orchestration workflow: resolves the appropriate machine,
|
|
42
|
+
* validates input, executes the machine logic, processes emitted events, and persists
|
|
43
|
+
* the new state. Handles both new orchestrations and continuation of existing ones.
|
|
44
|
+
*
|
|
45
|
+
* For violation errors (transaction, execution, contract, config), the error is thrown
|
|
46
|
+
* to enable retry mechanisms. For non-violation errors, system error events are emitted
|
|
47
|
+
* to the workflow initiator, and the orchestration enters a terminal failure state.
|
|
32
48
|
*
|
|
33
|
-
* @param event -
|
|
34
|
-
* @param opentelemetry - OpenTelemetry configuration
|
|
35
|
-
* @returns Object containing
|
|
49
|
+
* @param event - The incoming event triggering orchestration
|
|
50
|
+
* @param opentelemetry - Optional OpenTelemetry configuration for tracing
|
|
51
|
+
* @returns Object containing emitted events from the orchestration or system errors
|
|
36
52
|
*
|
|
37
|
-
* @throws {TransactionViolation}
|
|
38
|
-
* @throws {
|
|
39
|
-
* @throws {
|
|
40
|
-
* @throws {
|
|
53
|
+
* @throws {TransactionViolation} When lock acquisition or state operations fail (retriable)
|
|
54
|
+
* @throws {ContractViolation} When event data doesn't match contract schema (retriable)
|
|
55
|
+
* @throws {ConfigViolation} When machine resolution fails or version is missing (retriable)
|
|
56
|
+
* @throws {ExecutionViolation} When workflow execution encounters critical errors defined by the handler developer
|
|
41
57
|
*/
|
|
42
58
|
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
43
59
|
events: ArvoEvent[];
|
|
44
60
|
}>;
|
|
45
61
|
/**
|
|
46
|
-
*
|
|
62
|
+
* Provides access to the system error event schema configuration.
|
|
47
63
|
*/
|
|
48
|
-
get systemErrorSchema():
|
|
64
|
+
get systemErrorSchema(): {
|
|
65
|
+
type: any;
|
|
66
|
+
schema: import("zod").ZodObject<{
|
|
67
|
+
errorName: import("zod").ZodString;
|
|
68
|
+
errorMessage: import("zod").ZodString;
|
|
69
|
+
errorStack: import("zod").ZodNullable<import("zod").ZodString>;
|
|
70
|
+
}, "strip", import("zod").ZodTypeAny, {
|
|
71
|
+
errorName: string;
|
|
72
|
+
errorMessage: string;
|
|
73
|
+
errorStack: string | null;
|
|
74
|
+
}, {
|
|
75
|
+
errorName: string;
|
|
76
|
+
errorMessage: string;
|
|
77
|
+
errorStack: string | null;
|
|
78
|
+
}>;
|
|
79
|
+
domain: (string | null)[] | undefined;
|
|
80
|
+
};
|
|
49
81
|
}
|
|
@@ -56,19 +56,18 @@ var SyncEventResource_1 = require("../SyncEventResource");
|
|
|
56
56
|
var errors_1 = require("../errors");
|
|
57
57
|
/**
|
|
58
58
|
* Orchestrates state machine execution and lifecycle management.
|
|
59
|
-
*
|
|
59
|
+
*
|
|
60
|
+
* Coordinates machine resolution, state persistence, event processing, and error handling
|
|
61
|
+
* for Arvo's event-driven orchestration workflows. Manages the complete lifecycle from
|
|
62
|
+
* event receipt through machine execution to emitting result events.
|
|
60
63
|
*/
|
|
61
64
|
var ArvoOrchestrator = /** @class */ (function () {
|
|
62
|
-
/**
|
|
63
|
-
* Creates a new orchestrator instance
|
|
64
|
-
* @param params - Configuration parameters
|
|
65
|
-
* @throws Error if machines in registry have different sources
|
|
66
|
-
*/
|
|
67
65
|
function ArvoOrchestrator(_a) {
|
|
68
66
|
var _b;
|
|
69
67
|
var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
|
|
70
68
|
var _c, _d, _e, _f, _g, _h, _j;
|
|
71
|
-
|
|
69
|
+
/** Optional domains for routing system error events */
|
|
70
|
+
this.systemErrorDomain = undefined;
|
|
72
71
|
this.executionunits = executionunits;
|
|
73
72
|
this.registry = registry;
|
|
74
73
|
this.executionEngine = executionEngine;
|
|
@@ -77,6 +76,7 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
77
76
|
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
77
|
}
|
|
79
78
|
Object.defineProperty(ArvoOrchestrator.prototype, "source", {
|
|
79
|
+
/** Source identifier from the first registered machine */
|
|
80
80
|
get: function () {
|
|
81
81
|
return this.registry.machines[0].source;
|
|
82
82
|
},
|
|
@@ -84,6 +84,7 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
84
84
|
configurable: true
|
|
85
85
|
});
|
|
86
86
|
Object.defineProperty(ArvoOrchestrator.prototype, "requiresResourceLocking", {
|
|
87
|
+
/** Whether this orchestrator requires resource locking for concurrent safety */
|
|
87
88
|
get: function () {
|
|
88
89
|
return this.syncEventResource.requiresResourceLocking;
|
|
89
90
|
},
|
|
@@ -91,6 +92,7 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
91
92
|
configurable: true
|
|
92
93
|
});
|
|
93
94
|
Object.defineProperty(ArvoOrchestrator.prototype, "memory", {
|
|
95
|
+
/** Memory interface for state persistence and retrieval */
|
|
94
96
|
get: function () {
|
|
95
97
|
return this.syncEventResource.memory;
|
|
96
98
|
},
|
|
@@ -98,6 +100,7 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
98
100
|
configurable: true
|
|
99
101
|
});
|
|
100
102
|
Object.defineProperty(ArvoOrchestrator.prototype, "domain", {
|
|
103
|
+
/** The contract-defined domain for the handler */
|
|
101
104
|
get: function () {
|
|
102
105
|
return this.registry.machines[0].contracts.self.domain;
|
|
103
106
|
},
|
|
@@ -105,16 +108,24 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
105
108
|
configurable: true
|
|
106
109
|
});
|
|
107
110
|
/**
|
|
108
|
-
*
|
|
111
|
+
* Executes state machine orchestration for an incoming event.
|
|
112
|
+
*
|
|
113
|
+
* Performs the complete orchestration workflow: resolves the appropriate machine,
|
|
114
|
+
* validates input, executes the machine logic, processes emitted events, and persists
|
|
115
|
+
* the new state. Handles both new orchestrations and continuation of existing ones.
|
|
116
|
+
*
|
|
117
|
+
* For violation errors (transaction, execution, contract, config), the error is thrown
|
|
118
|
+
* to enable retry mechanisms. For non-violation errors, system error events are emitted
|
|
119
|
+
* to the workflow initiator, and the orchestration enters a terminal failure state.
|
|
109
120
|
*
|
|
110
|
-
* @param event -
|
|
111
|
-
* @param opentelemetry - OpenTelemetry configuration
|
|
112
|
-
* @returns Object containing
|
|
121
|
+
* @param event - The incoming event triggering orchestration
|
|
122
|
+
* @param opentelemetry - Optional OpenTelemetry configuration for tracing
|
|
123
|
+
* @returns Object containing emitted events from the orchestration or system errors
|
|
113
124
|
*
|
|
114
|
-
* @throws {TransactionViolation}
|
|
115
|
-
* @throws {
|
|
116
|
-
* @throws {
|
|
117
|
-
* @throws {
|
|
125
|
+
* @throws {TransactionViolation} When lock acquisition or state operations fail (retriable)
|
|
126
|
+
* @throws {ContractViolation} When event data doesn't match contract schema (retriable)
|
|
127
|
+
* @throws {ConfigViolation} When machine resolution fails or version is missing (retriable)
|
|
128
|
+
* @throws {ExecutionViolation} When workflow execution encounters critical errors defined by the handler developer
|
|
118
129
|
*/
|
|
119
130
|
ArvoOrchestrator.prototype.execute = function (event, opentelemetry) {
|
|
120
131
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -152,7 +163,7 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
152
163
|
level: 'INFO',
|
|
153
164
|
message: "Input validation started for event ".concat(event.type, " on machine ").concat(machine.source),
|
|
154
165
|
}, span);
|
|
155
|
-
inputValidation = machine.validateInput(event);
|
|
166
|
+
inputValidation = machine.validateInput(event, span);
|
|
156
167
|
if (inputValidation.type === 'CONTRACT_UNRESOLVED') {
|
|
157
168
|
throw new errors_1.ConfigViolation('Contract validation failed - Event does not match any registered contract schemas in the machine');
|
|
158
169
|
}
|
|
@@ -212,12 +223,13 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
212
223
|
};
|
|
213
224
|
Object.defineProperty(ArvoOrchestrator.prototype, "systemErrorSchema", {
|
|
214
225
|
/**
|
|
215
|
-
*
|
|
226
|
+
* Provides access to the system error event schema configuration.
|
|
216
227
|
*/
|
|
217
228
|
get: function () {
|
|
218
229
|
return {
|
|
219
230
|
type: this.registry.machines[0].contracts.self.systemError.type,
|
|
220
231
|
schema: arvo_core_1.ArvoErrorSchema,
|
|
232
|
+
domain: this.systemErrorDomain,
|
|
221
233
|
};
|
|
222
234
|
},
|
|
223
235
|
enumerable: false,
|