import { CloudEvent } from "../types"; import { PublishOptions, SubscribeOptions } from "./io-options"; interface ConnectionOptions { url: string; exchange: string; exchangeType: 'topic' | 'direct' | 'fanout'; deadLetterExchange: string; retryExchange: string; } interface ConsumerOptions { prefetch?: number; autoAck: boolean; } interface ProducerOptions { persistent: boolean; mandatory: boolean; } export interface EventBusOptions { connection: ConnectionOptions; consumer?: Partial; producer?: Partial; } export const DEFAULT_OPTIONS: Omit, 'connection'> & { connection: Omit } = { connection: { exchange: 'events', exchangeType: 'topic', deadLetterExchange: 'events.dlx', retryExchange: 'events.retry' }, consumer: { prefetch: 1, autoAck: false }, producer: { persistent: true, mandatory: true } }; export type ValidatedEventBusOptions = Required & { connection: Required; consumer: Required; producer: Required; }; export interface EventBus { publish(event: CloudEvent, options?: PublishOptions): Promise; subscribe( type: E | E[], handler: (event: CloudEvent) => Promise, options?: SubscribeOptions ): Promise; unsubscribe(consumerTag: string): Promise; close(): Promise; }