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
48 lines (47 loc) • 1.69 kB
TypeScript
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;