UNPKG

arvo-xstate

Version:

This package allows you to use xstate Actors and State Machines to act as orchestrators in an Arvo Event Driven System

36 lines (35 loc) 1.31 kB
import type { ArvoEvent } from 'arvo-core'; import type { AbstractArvoEventHandler } from 'arvo-event-handler'; import { SimpleEventBroker } from '.'; /** * Creates a local event broker configured with domain event handlers. * * The broker automatically wires each handler to its source topic and propagates * resulting events. Includes default error handling with console logging. * * @param eventHandlers - Array of event handlers to register with the broker * @param options - Configuration options * @param options.onError - Custom error handler for broker errors * @param options.onDomainedEvents - Callback for handling domain-specific events * @returns Configured SimpleEventBroker instance with handlers subscribed * * @example * ```typescript * const broker = createSimpleEventBroker([ * createArvoOrchestrator(...), * createArvoEventHandler(...) * ]); * * await broker.publish(createArvoEvent({ * type: 'com.openai.completion', * data: {...} * })); * ``` */ export declare const createSimpleEventBroker: (eventHandlers: AbstractArvoEventHandler[], options?: { onError?: (error: Error, event: ArvoEvent) => void; onDomainedEvents?: (param: { events: Record<string, ArvoEvent[]>; broker: SimpleEventBroker; }) => void; }) => SimpleEventBroker;