arvo-event-handler
Version:
A complete set of orthogonal event handler and orchestration primitives for Arvo based applications, featuring declarative state machines (XState), imperative resumables for agentic workflows, contract-based routing, OpenTelemetry observability, and in-me
57 lines (56 loc) • 3.04 kB
TypeScript
import { type ArvoContract, type ArvoEvent } from 'arvo-core';
import type IArvoEventHandler from '../IArvoEventHandler';
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
import type { ArvoEventHandlerFunction, ArvoEventHandlerParam } from './types';
/**
* The foundational component for building stateless,
* contract-bound services in the Arvo system.
*/
export default class ArvoEventHandler<TContract extends ArvoContract> implements IArvoEventHandler {
/** Contract instance that defines the event schema and validation rules */
readonly contract: TContract;
/** Computational cost metric associated with event handling operations */
readonly executionunits: number;
/** OpenTelemetry configuration for event handling spans */
readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
/** Version-specific event handler implementation map */
readonly handler: ArvoEventHandlerFunction<TContract>;
/** The source identifier for events produced by this handler */
get source(): TContract['type'];
/** Domains for routing events */
readonly defaultEventEmissionDomains: Required<NonNullable<ArvoEventHandlerParam<TContract>['defaultEventEmissionDomains']>>;
/** The contract-defined domain for the handler */
get domain(): string | null;
constructor(param: ArvoEventHandlerParam<TContract>);
/**
* Processes an incoming event according to the handler's contract specifications. This method
* handles the complete lifecycle of event processing including validation, execution, error
* handling, and multi-domain event broadcasting, while maintaining detailed telemetry through OpenTelemetry.
*
* @throws {ContractViolation} when input or output event data violates the contract schema,
* or when event emission fails due to invalid data
* @throws {ConfigViolation} when event type doesn't match contract type, when the
* contract version expected by the event does not exist
* in handler configuration, or when contract URI mismatch occurs
* @throws {ExecutionViolation} for explicitly handled runtime errors that should bubble up
*/
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
events: ArvoEvent[];
}>;
/**
* Provides access to the system error event schema configuration.
*/
get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.${string}.error`, import("zod").ZodObject<{
errorName: import("zod").ZodString;
errorMessage: import("zod").ZodString;
errorStack: import("zod").ZodNullable<import("zod").ZodString>;
}, "strip", import("zod").ZodTypeAny, {
errorName: string;
errorMessage: string;
errorStack: string | null;
}, {
errorName: string;
errorMessage: string;
errorStack: string | null;
}>>;
}