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.

48 lines (47 loc) 1.69 kB
import type { Span } from '@opentelemetry/api'; import { type ArvoContract, type ArvoEvent, VersionedArvoContract } from 'arvo-core'; import type { z } from 'zod'; /** * Result type for event validation operations. * * Discriminated union representing all possible validation outcomes: * - VALID: Event passed all validation checks * - CONTRACT_UNRESOLVED: No matching contract found for the event * - INVALID: Event dataschema conflicts with contract (URI or version mismatch) * - INVALID_DATA: Event data doesn't match contract schema (Zod validation failure) */ export type EventValidationResult = { type: 'VALID'; contractType: 'self' | 'service'; } | { type: 'CONTRACT_UNRESOLVED'; } | { type: 'INVALID'; error: Error; } | { type: 'INVALID_DATA'; error: z.ZodError; }; /** * Configuration for event validation. */ export type EventValidationConfig = { /** The event to validate */ event: ArvoEvent; /** Self contract for initialization event validation */ selfContract: VersionedArvoContract<any, any> | ArvoContract; /** Service contracts for response event validation */ serviceContracts: Record<string, VersionedArvoContract<any, any>>; /** Optional OpenTelemetry span for logging */ span?: Span; }; /** * Validates an event against provided contracts. * * Performs comprehensive validation including: * - Dataschema parsing and resolution * - Contract resolution (self vs service) * - URI and version compatibility checks * - Schema-based data validation */ export declare function validateInputEvent({ event, selfContract, serviceContracts, span, }: EventValidationConfig): EventValidationResult;