arvo-event-handler 2.3.1 → 3.0.1
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/AbstractArvoEventHandler/index.d.ts +1 -1
- package/dist/ArvoEventHandler/helpers.d.ts +40 -6
- package/dist/ArvoEventHandler/helpers.js +40 -6
- package/dist/ArvoEventHandler/index.d.ts +78 -49
- package/dist/ArvoEventHandler/index.js +151 -81
- package/dist/ArvoEventHandler/types.d.ts +25 -2
- package/dist/ArvoMachine/createMachine.d.ts +208 -0
- package/dist/ArvoMachine/createMachine.js +283 -0
- package/dist/ArvoMachine/index.d.ts +93 -0
- package/dist/ArvoMachine/index.js +160 -0
- package/dist/ArvoMachine/types.d.ts +194 -0
- package/dist/ArvoMachine/utils.d.ts +40 -0
- package/dist/ArvoMachine/utils.js +70 -0
- package/dist/ArvoOrchestrator/error.d.ts +16 -0
- package/dist/ArvoOrchestrator/error.js +43 -0
- package/dist/ArvoOrchestrator/factory.d.ts +28 -0
- package/dist/ArvoOrchestrator/factory.js +56 -0
- package/dist/ArvoOrchestrator/index.d.ts +69 -0
- package/dist/ArvoOrchestrator/index.js +597 -0
- package/dist/ArvoOrchestrator/types.d.ts +98 -0
- package/dist/ArvoResumable/factory.d.ts +50 -0
- package/dist/ArvoResumable/factory.js +70 -0
- package/dist/ArvoResumable/index.d.ts +141 -0
- package/dist/ArvoResumable/index.js +694 -0
- package/dist/ArvoResumable/types.d.ts +147 -0
- package/dist/ArvoResumable/types.js +2 -0
- package/dist/MachineExecutionEngine/index.d.ts +29 -0
- package/dist/MachineExecutionEngine/index.js +132 -0
- package/dist/MachineExecutionEngine/interface.d.ts +14 -0
- package/dist/MachineExecutionEngine/interface.js +2 -0
- package/dist/MachineExecutionEngine/types.d.ts +14 -0
- package/dist/MachineExecutionEngine/types.js +2 -0
- package/dist/MachineMemory/Simple.d.ts +51 -0
- package/dist/MachineMemory/Simple.js +158 -0
- package/dist/MachineMemory/TelemetredSimple.d.ts +51 -0
- package/dist/MachineMemory/TelemetredSimple.js +230 -0
- package/dist/MachineMemory/interface.d.ts +57 -0
- package/dist/MachineMemory/interface.js +2 -0
- package/dist/MachineMemory/utils.d.ts +1 -0
- package/dist/MachineMemory/utils.js +18 -0
- package/dist/MachineRegistry/index.d.ts +37 -0
- package/dist/MachineRegistry/index.js +87 -0
- package/dist/MachineRegistry/interface.d.ts +21 -0
- package/dist/MachineRegistry/interface.js +2 -0
- package/dist/SyncEventResource/index.d.ts +110 -0
- package/dist/SyncEventResource/index.js +280 -0
- package/dist/SyncEventResource/types.d.ts +2 -0
- package/dist/SyncEventResource/types.js +2 -0
- package/dist/index.d.ts +26 -8
- package/dist/index.js +39 -16
- package/dist/utils/SimpleEventBroker/helper.d.ts +166 -0
- package/dist/utils/SimpleEventBroker/helper.js +276 -0
- package/dist/utils/SimpleEventBroker/index.d.ts +96 -0
- package/dist/utils/SimpleEventBroker/index.js +259 -0
- package/dist/utils/SimpleEventBroker/types.d.ts +6 -0
- package/dist/utils/SimpleEventBroker/types.js +2 -0
- package/dist/utils/SimpleEventBroker/utils.d.ts +1 -0
- package/dist/utils/SimpleEventBroker/utils.js +10 -0
- package/dist/{utils.d.ts → utils/index.d.ts} +3 -36
- package/dist/utils/index.js +91 -0
- package/dist/utils/object/index.d.ts +37 -0
- package/dist/utils/object/index.js +63 -0
- package/package.json +6 -12
- package/dist/ArvoEventRouter/helpers.d.ts +0 -19
- package/dist/ArvoEventRouter/helpers.js +0 -22
- package/dist/ArvoEventRouter/index.d.ts +0 -89
- package/dist/ArvoEventRouter/index.js +0 -267
- package/dist/ArvoEventRouter/types.d.ts +0 -36
- package/dist/ArvoEventRouter/utils.d.ts +0 -29
- package/dist/ArvoEventRouter/utils.js +0 -42
- package/dist/MultiArvoEventHandler/helpers.d.ts +0 -48
- package/dist/MultiArvoEventHandler/helpers.js +0 -56
- package/dist/MultiArvoEventHandler/index.d.ts +0 -68
- package/dist/MultiArvoEventHandler/index.js +0 -205
- package/dist/MultiArvoEventHandler/types.d.ts +0 -64
- package/dist/utils.js +0 -190
- /package/dist/{ArvoEventRouter → ArvoMachine}/types.js +0 -0
- /package/dist/{MultiArvoEventHandler → ArvoOrchestrator}/types.js +0 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { ArvoEvent, InferArvoEvent } from 'arvo-core';
|
|
2
|
+
import type { Snapshot } from 'xstate';
|
|
3
|
+
import type ArvoMachine from '../ArvoMachine';
|
|
4
|
+
import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
|
|
5
|
+
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
6
|
+
import type { IMachineRegistry } from '../MachineRegistry/interface';
|
|
7
|
+
export type TryFunctionOutput<TData, TError extends Error> = {
|
|
8
|
+
type: 'success';
|
|
9
|
+
data: TData;
|
|
10
|
+
} | {
|
|
11
|
+
type: 'error';
|
|
12
|
+
error: TError;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Represents the state record stored in machine memory.
|
|
16
|
+
*/
|
|
17
|
+
export type MachineMemoryRecord = {
|
|
18
|
+
/** Unique identifier for the machine instance */
|
|
19
|
+
subject: string;
|
|
20
|
+
/**
|
|
21
|
+
* Reference to the parent orchestration's subject when orchestrations are nested or chained.
|
|
22
|
+
* This enables hierarchical orchestration patterns where one orchestration can spawn
|
|
23
|
+
* sub-orchestrations. When the current orchestration completes, its completion event
|
|
24
|
+
* is routed back to this parent subject rather than staying within the current context.
|
|
25
|
+
*
|
|
26
|
+
* - For root orchestrations: null
|
|
27
|
+
* - For nested orchestrations: contains the subject of the parent orchestration
|
|
28
|
+
* - Extracted from the `parentSubject$$` field in initialization events
|
|
29
|
+
*/
|
|
30
|
+
parentSubject: string | null;
|
|
31
|
+
/**
|
|
32
|
+
* The unique identifier of the event that originally initiated this entire orchestration workflow.
|
|
33
|
+
* This serves as the root identifier for tracking the complete execution chain from start to finish.
|
|
34
|
+
*
|
|
35
|
+
* - For new orchestrations: set to the current event's ID
|
|
36
|
+
* - For resumed orchestrations: retrieved from the stored state
|
|
37
|
+
* - Used as the `parentid` for completion events to create a direct lineage back to the workflow's origin
|
|
38
|
+
*
|
|
39
|
+
* This enables tracing the entire execution path and ensures completion events reference
|
|
40
|
+
* the original triggering event rather than just the immediate previous step.
|
|
41
|
+
*/
|
|
42
|
+
initEventId: string;
|
|
43
|
+
/**
|
|
44
|
+
* Current execution status of the machine. The status field represents the current
|
|
45
|
+
* state of the machine's lifecycle. While commonly used values are:
|
|
46
|
+
* - 'active': Machine is currently executing
|
|
47
|
+
* - 'done': Machine has completed its execution successfully
|
|
48
|
+
* - 'error': Machine encountered an error during execution
|
|
49
|
+
* - 'stopped': Machine execution was explicitly stopped
|
|
50
|
+
*
|
|
51
|
+
* Due to XState dependency, the status can be any string value defined in the
|
|
52
|
+
* state machine definition. This allows for custom states specific to the
|
|
53
|
+
* business logic implemented in the state machine.
|
|
54
|
+
*/
|
|
55
|
+
status: string;
|
|
56
|
+
/** Current value stored in the machine state */
|
|
57
|
+
value: string | Record<string, any> | null;
|
|
58
|
+
/** XState snapshot representing the machine's current state */
|
|
59
|
+
state: Snapshot<any>;
|
|
60
|
+
events: {
|
|
61
|
+
/** The event consumed by the machine in the last session */
|
|
62
|
+
consumed: InferArvoEvent<ArvoEvent> | null;
|
|
63
|
+
/**
|
|
64
|
+
* The events produced by the machine in the last session
|
|
65
|
+
*/
|
|
66
|
+
produced: InferArvoEvent<ArvoEvent>[];
|
|
67
|
+
};
|
|
68
|
+
/** Machine definition string */
|
|
69
|
+
machineDefinition: string | null;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Interface defining the core components of an Arvo orchestrator.
|
|
73
|
+
*/
|
|
74
|
+
export interface IArvoOrchestrator {
|
|
75
|
+
/** The cost of the execution of the orchestrator */
|
|
76
|
+
executionunits: number;
|
|
77
|
+
/** Memory interface for storing and retrieving machine state */
|
|
78
|
+
memory: IMachineMemory<MachineMemoryRecord>;
|
|
79
|
+
/** Registry for managing and resolving machine instances */
|
|
80
|
+
registry: IMachineRegistry;
|
|
81
|
+
/** Engine responsible for machine execution */
|
|
82
|
+
executionEngine: IMachineExectionEngine;
|
|
83
|
+
requiresResourceLocking: boolean;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Configuration interface for creating an Arvo orchestrator instance.
|
|
87
|
+
*/
|
|
88
|
+
export interface ICreateArvoOrchestrator {
|
|
89
|
+
/** Memory interface for storing and retrieving machine state */
|
|
90
|
+
memory: IMachineMemory<MachineMemoryRecord>;
|
|
91
|
+
/** The cost of the execution of the orchestrator */
|
|
92
|
+
executionunits: number;
|
|
93
|
+
/**
|
|
94
|
+
* Collection of state machines to be managed by the orchestrator.
|
|
95
|
+
* All machines must have the same source identifier.
|
|
96
|
+
*/
|
|
97
|
+
machines: ArvoMachine<any, any, any, any, any>[];
|
|
98
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { ArvoOrchestratorContract, VersionedArvoContract } from 'arvo-core';
|
|
2
|
+
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
3
|
+
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
4
|
+
import { ArvoResumable } from '.';
|
|
5
|
+
/**
|
|
6
|
+
* Factory function for creating ArvoResumable orchestrator instances
|
|
7
|
+
*
|
|
8
|
+
* Creates a new ArvoResumable orchestrator with type safety and sensible defaults.
|
|
9
|
+
* ArvoResumable provides handler-based workflow orchestration with explicit context management,
|
|
10
|
+
* contract validation, and distributed locking capabilities.
|
|
11
|
+
*
|
|
12
|
+
* @param param - Configuration object for the orchestrator
|
|
13
|
+
* @param param.types - Optional type hints for better TypeScript inference
|
|
14
|
+
* @param param.types.context - Partial type hint for the workflow context structure (not used at runtime)
|
|
15
|
+
* @param param.contracts - Contract definitions for the orchestrator and its services
|
|
16
|
+
* @param param.contracts.self - The orchestrator's own contract defining accepted events and emitted events
|
|
17
|
+
* @param param.contracts.services - Record of service contracts this orchestrator can invoke, keyed by service name
|
|
18
|
+
* @param param.memory - Generic memory interface for state persistence, locking, and retrieval operations
|
|
19
|
+
* @param param.handler - Versioned orchestration logic handlers mapped by semantic version
|
|
20
|
+
* @param param.executionunits - Resource allocation cost for this orchestrator's execution (default: 0)
|
|
21
|
+
* @param param.requiresResourceLocking - Enable distributed locking for concurrent safety (default: auto-determined by service count)
|
|
22
|
+
*
|
|
23
|
+
* @returns A new ArvoResumable orchestrator instance configured with the provided parameters
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} Service contracts have duplicate URIs - Multiple versions of the same contract are not allowed
|
|
26
|
+
* @throws {Error} Circular dependency detected - Self contract is registered as a service, creating execution loops
|
|
27
|
+
*
|
|
28
|
+
* @remarks
|
|
29
|
+
* **Resource Locking:**
|
|
30
|
+
* When `requiresResourceLocking` is not specified, it defaults to `true` when multiple
|
|
31
|
+
* services are configured (indicating potential concurrent operations) and `false` for
|
|
32
|
+
* single-service orchestrations.
|
|
33
|
+
*
|
|
34
|
+
* **Contract Validation:**
|
|
35
|
+
* The factory validates that all service contracts have unique URIs and prevents
|
|
36
|
+
* circular dependencies where the orchestrator's own contract is registered as a service.
|
|
37
|
+
*/
|
|
38
|
+
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: {
|
|
39
|
+
types?: {
|
|
40
|
+
context?: Partial<TMemory>;
|
|
41
|
+
};
|
|
42
|
+
contracts: {
|
|
43
|
+
self: TSelfContract;
|
|
44
|
+
services: TServiceContract;
|
|
45
|
+
};
|
|
46
|
+
memory: IMachineMemory<Record<string, any>>;
|
|
47
|
+
handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
48
|
+
executionunits?: number;
|
|
49
|
+
requiresResourceLocking?: boolean;
|
|
50
|
+
}) => ArvoResumable<TMemory, TSelfContract, TServiceContract>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.createArvoResumable = void 0;
|
|
15
|
+
var _1 = require(".");
|
|
16
|
+
var utils_1 = require("../ArvoMachine/utils");
|
|
17
|
+
var uuid_1 = require("uuid");
|
|
18
|
+
/**
|
|
19
|
+
* Factory function for creating ArvoResumable orchestrator instances
|
|
20
|
+
*
|
|
21
|
+
* Creates a new ArvoResumable orchestrator with type safety and sensible defaults.
|
|
22
|
+
* ArvoResumable provides handler-based workflow orchestration with explicit context management,
|
|
23
|
+
* contract validation, and distributed locking capabilities.
|
|
24
|
+
*
|
|
25
|
+
* @param param - Configuration object for the orchestrator
|
|
26
|
+
* @param param.types - Optional type hints for better TypeScript inference
|
|
27
|
+
* @param param.types.context - Partial type hint for the workflow context structure (not used at runtime)
|
|
28
|
+
* @param param.contracts - Contract definitions for the orchestrator and its services
|
|
29
|
+
* @param param.contracts.self - The orchestrator's own contract defining accepted events and emitted events
|
|
30
|
+
* @param param.contracts.services - Record of service contracts this orchestrator can invoke, keyed by service name
|
|
31
|
+
* @param param.memory - Generic memory interface for state persistence, locking, and retrieval operations
|
|
32
|
+
* @param param.handler - Versioned orchestration logic handlers mapped by semantic version
|
|
33
|
+
* @param param.executionunits - Resource allocation cost for this orchestrator's execution (default: 0)
|
|
34
|
+
* @param param.requiresResourceLocking - Enable distributed locking for concurrent safety (default: auto-determined by service count)
|
|
35
|
+
*
|
|
36
|
+
* @returns A new ArvoResumable orchestrator instance configured with the provided parameters
|
|
37
|
+
*
|
|
38
|
+
* @throws {Error} Service contracts have duplicate URIs - Multiple versions of the same contract are not allowed
|
|
39
|
+
* @throws {Error} Circular dependency detected - Self contract is registered as a service, creating execution loops
|
|
40
|
+
*
|
|
41
|
+
* @remarks
|
|
42
|
+
* **Resource Locking:**
|
|
43
|
+
* When `requiresResourceLocking` is not specified, it defaults to `true` when multiple
|
|
44
|
+
* services are configured (indicating potential concurrent operations) and `false` for
|
|
45
|
+
* single-service orchestrations.
|
|
46
|
+
*
|
|
47
|
+
* **Contract Validation:**
|
|
48
|
+
* The factory validates that all service contracts have unique URIs and prevents
|
|
49
|
+
* circular dependencies where the orchestrator's own contract is registered as a service.
|
|
50
|
+
*/
|
|
51
|
+
var createArvoResumable = function (param) {
|
|
52
|
+
var _a;
|
|
53
|
+
var _b, _c;
|
|
54
|
+
var __areServiceContractsUnique = (0, utils_1.areServiceContractsUnique)(param.contracts.services);
|
|
55
|
+
if (!__areServiceContractsUnique.result) {
|
|
56
|
+
throw new Error("The service contracts must have unique URIs. Multiple versions of the same contract are not allow. The contracts '".concat(__areServiceContractsUnique.keys[0], "' and '").concat(__areServiceContractsUnique.keys[1], "' have the same URI '").concat(__areServiceContractsUnique.contractUri, "'"));
|
|
57
|
+
}
|
|
58
|
+
var __checkIfSelfIsAService = (0, utils_1.areServiceContractsUnique)(__assign(__assign({}, param.contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = param.contracts.self, _a)));
|
|
59
|
+
if (!__checkIfSelfIsAService.result) {
|
|
60
|
+
throw new Error("Circular dependency detected: Machine with URI '".concat(param.contracts.self.uri, "' is registered as service '").concat(__checkIfSelfIsAService.keys[1], "'. Self-referential services create execution loops and are prohibited."));
|
|
61
|
+
}
|
|
62
|
+
return new _1.ArvoResumable({
|
|
63
|
+
contracts: param.contracts,
|
|
64
|
+
memory: param.memory,
|
|
65
|
+
handler: param.handler,
|
|
66
|
+
executionunits: (_b = param.executionunits) !== null && _b !== void 0 ? _b : 0,
|
|
67
|
+
requiresResourceLocking: (_c = param.requiresResourceLocking) !== null && _c !== void 0 ? _c : Object.keys(param.contracts.services).length > 1,
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.createArvoResumable = createArvoResumable;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { type ArvoEvent, type ArvoOrchestratorContract, type VersionedArvoContract, type OpenTelemetryHeaders, type ArvoSemanticVersion } from 'arvo-core';
|
|
2
|
+
import type { z } from 'zod';
|
|
3
|
+
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
4
|
+
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
5
|
+
import { SyncEventResource } from '../SyncEventResource/index';
|
|
6
|
+
import type { EnqueueArvoEventActionParam } from '../ArvoMachine/types';
|
|
7
|
+
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
8
|
+
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
9
|
+
/**
|
|
10
|
+
* ArvoResumable - A stateful orchestration handler for managing distributed workflows
|
|
11
|
+
*
|
|
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
|
|
39
|
+
*/
|
|
40
|
+
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>>> extends AbstractArvoEventHandler {
|
|
41
|
+
readonly executionunits: number;
|
|
42
|
+
readonly syncEventResource: SyncEventResource<ArvoResumableState<TMemory>>;
|
|
43
|
+
readonly source: string;
|
|
44
|
+
readonly handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
45
|
+
readonly contracts: {
|
|
46
|
+
self: TSelfContract;
|
|
47
|
+
services: TServiceContract;
|
|
48
|
+
};
|
|
49
|
+
get requiresResourceLocking(): boolean;
|
|
50
|
+
get memory(): IMachineMemory<ArvoResumableState<TMemory>>;
|
|
51
|
+
get domain(): string | null;
|
|
52
|
+
constructor(param: {
|
|
53
|
+
contracts: {
|
|
54
|
+
self: TSelfContract;
|
|
55
|
+
services: TServiceContract;
|
|
56
|
+
};
|
|
57
|
+
executionunits: number;
|
|
58
|
+
memory: IMachineMemory<ArvoResumableState<TMemory>>;
|
|
59
|
+
requiresResourceLocking?: boolean;
|
|
60
|
+
handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
61
|
+
});
|
|
62
|
+
protected validateInput(event: ArvoEvent): {
|
|
63
|
+
contractType: 'self' | 'service';
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Creates emittable event from execution result
|
|
67
|
+
* @param event - Source event to emit
|
|
68
|
+
* @param otelHeaders - OpenTelemetry headers
|
|
69
|
+
* @param orchestrationParentSubject - Parent orchestration subject
|
|
70
|
+
* @param sourceEvent - Original triggering event
|
|
71
|
+
* @param selfVersionedContract - The self versioned contract
|
|
72
|
+
* @param initEventId - The id of the event which initiated the orchestration in the first place
|
|
73
|
+
* @param _domain - The domain of the event.
|
|
74
|
+
*
|
|
75
|
+
* @throws {ContractViolation} On schema/contract mismatch
|
|
76
|
+
* @throws {ExecutionViolation} On invalid parentSubject$$ format
|
|
77
|
+
*/
|
|
78
|
+
protected createEmittableEvent(event: EnqueueArvoEventActionParam, otelHeaders: OpenTelemetryHeaders, orchestrationParentSubject: string | null, sourceEvent: ArvoEvent, selfVersionedContract: VersionedArvoContract<TSelfContract, ArvoSemanticVersion>, initEventId: string, _domain: string | null | undefined): ArvoEvent;
|
|
79
|
+
/**
|
|
80
|
+
* Executes the orchestration workflow for an incoming event
|
|
81
|
+
*
|
|
82
|
+
* This is the main orchestration entry point that coordinates the complete event
|
|
83
|
+
* processing lifecycle. It implements the core workflow execution pattern including
|
|
84
|
+
* validation, locking, state management, handler invocation, event creation, and
|
|
85
|
+
* persistence with comprehensive error handling and observability.
|
|
86
|
+
*
|
|
87
|
+
* The execution process follows these phases:
|
|
88
|
+
* 1. **Validation & Setup** - Subject parsing, handler resolution, contract validation
|
|
89
|
+
* 2. **Resource Management** - Distributed lock acquisition and state loading
|
|
90
|
+
* 3. **Handler Execution** - Context preparation and user handler invocation
|
|
91
|
+
* 4. **Event Processing** - Result transformation and emittable event creation
|
|
92
|
+
* 5. **State Persistence** - Atomic state updates and event tracking
|
|
93
|
+
* 6. **Cleanup & Return** - Resource release and structured result return
|
|
94
|
+
*
|
|
95
|
+
* @param event - The triggering event to process
|
|
96
|
+
* @param opentelemetry - OpenTelemetry configuration for trace inheritance
|
|
97
|
+
*
|
|
98
|
+
* @returns Object containing domained events
|
|
99
|
+
*
|
|
100
|
+
* @throws {TransactionViolation} When distributed lock acquisition fails
|
|
101
|
+
* @throws {ConfigViolation} When handler resolution or contract validation fails
|
|
102
|
+
* @throws {ContractViolation} When event schema validation fails
|
|
103
|
+
* @throws {ExecutionViolation} When workflow execution encounters critical errors
|
|
104
|
+
*
|
|
105
|
+
* @remarks
|
|
106
|
+
* **Execution Safety:**
|
|
107
|
+
* The method implements comprehensive error recovery with proper resource cleanup
|
|
108
|
+
* in all execution paths. ViolationErrors are rethrown for system handling while
|
|
109
|
+
* workflow errors become system error events for graceful degradation.
|
|
110
|
+
*
|
|
111
|
+
* **State Management:**
|
|
112
|
+
* Workflow state is managed atomically with optimistic concurrency control.
|
|
113
|
+
* Status transitions from 'active' to 'done' occur only when completion events
|
|
114
|
+
* are generated, ensuring proper workflow lifecycle management.
|
|
115
|
+
*
|
|
116
|
+
* **Observability:**
|
|
117
|
+
* Complete execution is traced using OpenTelemetry with detailed span attributes
|
|
118
|
+
* for debugging and monitoring. Event metadata includes processing context and
|
|
119
|
+
* routing information for operational visibility.
|
|
120
|
+
*
|
|
121
|
+
* **Terminal State Handling:**
|
|
122
|
+
* Workflows in 'done' status ignore additional events to prevent state corruption
|
|
123
|
+
* while preserving audit trails for completed workflow executions.
|
|
124
|
+
*/
|
|
125
|
+
execute(event: ArvoEvent, opentelemetry: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
126
|
+
events: ArvoEvent[];
|
|
127
|
+
}>;
|
|
128
|
+
get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.arvo.orc.${string}.error`, z.ZodObject<{
|
|
129
|
+
errorName: z.ZodString;
|
|
130
|
+
errorMessage: z.ZodString;
|
|
131
|
+
errorStack: z.ZodNullable<z.ZodString>;
|
|
132
|
+
}, "strip", z.ZodTypeAny, {
|
|
133
|
+
errorName: string;
|
|
134
|
+
errorMessage: string;
|
|
135
|
+
errorStack: string | null;
|
|
136
|
+
}, {
|
|
137
|
+
errorName: string;
|
|
138
|
+
errorMessage: string;
|
|
139
|
+
errorStack: string | null;
|
|
140
|
+
}>>;
|
|
141
|
+
}
|