import { OnModuleDestroy, Type } from '@nestjs/common'; import { ModuleRef } from '@nestjs/core'; import { InstanceWrapper } from '@nestjs/core/injector/instance-wrapper'; import { Observable, Subscription } from 'rxjs'; import { CommandBus } from './command-bus'; import { CqrsModuleOptions, EventIdProvider, IEvent, IEventBus, IEventHandler, IEventPublisher, ISaga } from './interfaces'; import { AsyncContext } from './scopes'; import { UnhandledExceptionBus } from './unhandled-exception-bus'; import { ObservableBus } from './utils'; export type EventHandlerType = Type>; /** * @publicApi */ export declare class EventBus extends ObservableBus implements IEventBus, OnModuleDestroy { private readonly commandBus; private readonly moduleRef; private readonly unhandledExceptionBus; private readonly options?; protected eventIdProvider: EventIdProvider; protected readonly subscriptions: Subscription[]; private _publisher; private readonly _logger; constructor(commandBus: CommandBus, moduleRef: ModuleRef, unhandledExceptionBus: UnhandledExceptionBus, options?: CqrsModuleOptions | undefined); /** * Returns the publisher. * Default publisher is `DefaultPubSub` (in memory). */ get publisher(): IEventPublisher; /** * Sets the publisher. * Default publisher is `DefaultPubSub` (in memory). * @param _publisher The publisher to set. */ set publisher(_publisher: IEventPublisher); onModuleDestroy(): void; /** * Publishes an event. * @param event The event to publish. */ publish(event: TEvent): any; /** * Publishes an event. * @param event The event to publish. * @param asyncContext Async context */ publish(event: TEvent, asyncContext: AsyncContext): any; /** * Publishes an event. * @param event The event to publish. * @param dispatcherContext Dispatcher context */ publish(event: TEvent, dispatcherContext: TContext): any; /** * Publishes an event. * @param event The event to publish. * @param dispatcherContext Dispatcher context * @param asyncContext Async context */ publish(event: TEvent, dispatcherContext: TContext, asyncContext: AsyncContext): any; /** * Publishes multiple events. * @param events The events to publish. */ publishAll(events: TEvent[]): any; /** * Publishes multiple events. * @param events The events to publish. * @param asyncContext Async context */ publishAll(events: TEvent[], asyncContext: AsyncContext): any; /** * Publishes multiple events. * @param events The events to publish. * @param dispatcherContext Dispatcher context */ publishAll(events: TEvent[], dispatcherContext: TContext): any; /** * Publishes multiple events. * @param events The events to publish. * @param dispatcherContext Dispatcher context * @param asyncContext Async context */ publishAll(events: TEvent[], dispatcherContext: TContext, asyncContext: AsyncContext): any; bind(handler: InstanceWrapper>, id: string): void; registerSagas(wrappers?: InstanceWrapper[]): void; register(handlers?: InstanceWrapper>[]): void; protected registerHandler(handler: InstanceWrapper>): void; protected ofEventId(id: string): Observable; protected registerSaga(saga: ISaga): void; private reflectEvents; private useDefaultPublisher; private mapToUnhandledErrorInfo; }