import { type BeforeApplicationShutdown, type OnApplicationBootstrap, type OnApplicationShutdown, type OnModuleDestroy, type OnModuleInit } from '@nestjs/common'; import { type Event, type EventClass, type EventOptions, Matador, type SendResult } from '@zdavison/matador'; import { SubscriberDiscoveryService } from '../discovery/subscriber-discovery.service.js'; import type { MatadorModuleOptions } from '../types.js'; /** * Injectable service that wraps Matador and integrates with NestJS lifecycle. * * This service handles: * - Building the Matador instance with discovered subscribers * - Starting Matador at the configured lifecycle hook * - Graceful shutdown with drain timeout * - Preventing event sending during shutdown * * @example * ```typescript * @Injectable() * export class OrderService { * constructor(private readonly matador: MatadorService) {} * * async createOrder(data: CreateOrderDto) { * // ... create order logic ... * await this.matador.send(OrderCreatedEvent, { orderId: order.id }); * } * } * ``` */ export declare class MatadorService implements OnModuleInit, OnApplicationBootstrap, OnModuleDestroy, BeforeApplicationShutdown, OnApplicationShutdown { private readonly options; private readonly discoveryService; private readonly logger; private matador; private isShuttingDown; private isStarted; constructor(options: MatadorModuleOptions, discoveryService: SubscriberDiscoveryService); /** * Called when MatadorModule is initialized. * Builds Matador instance and starts if startOn === 'onModuleInit'. */ onModuleInit(): Promise; /** * Called after all modules are initialized and the app is ready to start. * Starts Matador if startOn === 'onApplicationBootstrap' (default). */ onApplicationBootstrap(): Promise; /** * Called when MatadorModule is destroyed. * Shuts down Matador if shutdownOn === 'onModuleDestroy'. */ onModuleDestroy(): Promise; /** * Called when the application receives a shutdown signal (SIGTERM, etc). * Shuts down Matador if shutdownOn === 'beforeApplicationShutdown' (default). */ beforeApplicationShutdown(): Promise; /** * Called after beforeApplicationShutdown completes. * Shuts down Matador if shutdownOn === 'onApplicationShutdown'. */ onApplicationShutdown(): Promise; /** * Sends an event to all registered subscribers. * * @throws Error if called during shutdown * * @example * ```typescript * // Pass the event class and data directly * await matadorService.send(UserCreatedEvent, { userId: '123' }); * * // Or pass an event instance * const event = new UserCreatedEvent({ userId: '123' }); * await matadorService.send(event); * ``` */ send(eventClass: EventClass, data: T, options?: EventOptions): Promise; send(event: Event, options?: EventOptions): Promise; /** * Gets the underlying Matador instance for advanced operations. */ getMatador(): Matador; /** * Starts consuming (if autoStart was false). */ start(): Promise; /** * Checks if connected to transport. */ isConnected(): boolean; /** * Checks if shutdown is in progress. */ isShutdownInProgress(): boolean; /** * Waits for all pending messages to be processed. */ waitForIdle(timeoutMs?: number): Promise; /** * Stops receiving new messages without performing full shutdown. * After calling this, no new messages will be delivered from the transport. * The transport remains connected for later shutdown. * * Use this when you need to coordinate shutdown across multiple systems: * 1. Call stopReceiving() to stop new message delivery * 2. Wait for both Matador and your other systems to idle * 3. Let NestJS lifecycle handle disconnect via app.close() * * @returns true if receiving was stopped, false if not started or already stopped * * @example * ```typescript * // In your graceful shutdown handler: * await matadorService.stopReceiving(); * await Promise.all([ * matadorService.waitForIdle(30000), * myOtherService.waitForPendingWork() * ]); * await app.close(); // NestJS lifecycle will disconnect transport * ``` */ stopReceiving(): Promise; /** * Initializes the Matador instance with discovered schema. */ private initializeMatador; private shouldAutoStart; private doStart; private doShutdown; } //# sourceMappingURL=matador.service.d.ts.map