UNPKG

arvo-event-handler

Version:

Type-safe event handler system with versioning, telemetry, and contract validation for distributed Arvo event-driven architectures, featuring routing and multi-handler support.

65 lines (64 loc) 3.35 kB
import { type ArvoContractRecord, type ArvoEvent, type OpenTelemetryHeaders } from 'arvo-core'; import type ArvoMachine from '../ArvoMachine'; import type { EnqueueArvoEventActionParam } from '../ArvoMachine/types'; import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface'; import type { IMachineMemory } from '../MachineMemory/interface'; import type { IMachineRegistry } from '../MachineRegistry/interface'; import type { IArvoOrchestrator, MachineMemoryRecord } from './types'; import { SyncEventResource } from '../SyncEventResource'; import AbstractArvoEventHandler from '../AbstractArvoEventHandler'; import type { ArvoEventHandlerOpenTelemetryOptions } from '../types'; /** * Orchestrates state machine execution and lifecycle management. * Handles machine resolution, state management, event processing and error handling. */ export declare class ArvoOrchestrator extends AbstractArvoEventHandler { readonly executionunits: number; readonly registry: IMachineRegistry; readonly executionEngine: IMachineExectionEngine; readonly syncEventResource: SyncEventResource<MachineMemoryRecord>; readonly systemErrorDomain?: (string | null)[]; get source(): any; get requiresResourceLocking(): boolean; get memory(): IMachineMemory<MachineMemoryRecord>; get domain(): string | null; /** * Creates a new orchestrator instance * @param params - Configuration parameters * @throws Error if machines in registry have different sources */ constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, }: IArvoOrchestrator); /** * Creates emittable event from execution result * @param event - Source event to emit * @param machine - Machine that generated event * @param otelHeaders - OpenTelemetry headers * @param orchestrationParentSubject - Parent orchestration subject * @param sourceEvent - Original triggering event * @param initEventId - The id of the event which initiated the orchestration in the first place * @param _domain - The domain of the event. * * @throws {ContractViolation} On schema/contract mismatch * @throws {ExecutionViolation} On invalid parentSubject$$ format */ protected createEmittableEvent(event: EnqueueArvoEventActionParam, machine: ArvoMachine<any, any, any, any, any>, otelHeaders: OpenTelemetryHeaders, orchestrationParentSubject: string | null, sourceEvent: ArvoEvent, initEventId: string, _domain: string | null): ArvoEvent; /** * Core orchestration method that executes state machines in response to events. * * @param event - Event triggering the execution * @param opentelemetry - OpenTelemetry configuration * @returns Object containing domained events * * @throws {TransactionViolation} Lock/state operations failed * @throws {ExecutionViolation} Invalid event structure/flow * @throws {ContractViolation} Schema/contract mismatch * @throws {ConfigViolation} Missing/invalid machine version */ execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{ events: ArvoEvent[]; }>; /** * Gets the error schema for this orchestrator */ get systemErrorSchema(): ArvoContractRecord; }