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.

38 lines (37 loc) 1.69 kB
import { type ArvoEvent } from 'arvo-core'; import type ArvoMachine from '../ArvoMachine'; import type { IMachineRegistry } from './interface'; import type { ArvoEventHandlerOpenTelemetryOptions } from '../types'; /** * Registry for managing and resolving ArvoMachine instances. * Provides functionality to store multiple machine instances and resolve them based on events. * * @remarks * The registry must contain at least one machine upon initialization. * Each machine in the registry should have a unique combination of version and source. */ export declare class MachineRegistry implements IMachineRegistry { machines: ArvoMachine<any, any, any, any, any>[]; /** * Creates a new MachineRegistry instance with the provided machines. * * @param args - Variable number of ArvoMachine instances to register * @throws {Error} When no machines are provided during initialization */ constructor(...args: ArvoMachine<any, any, any, any, any>[]); /** * Resolves and returns a machine instance based on the provided event. * The resolution is performed using the orchestrator information in the event's subject. * * @param event - The event containing orchestration subject information * @param opentelemetry Telemetry configuration for tracing * @returns The matching ArvoMachine instance or null if not found * * @example * ```typescript * const machine = registry.resolve(incomingEvent); * // Use resolved machine for event processing * ``` */ resolve(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): ArvoMachine<any, any, any, any, any> | null; }