import { LoggerService } from '@nestjs/common/services/logger.service'; import { Observable, ObservedValueOf, ReplaySubject, Subscription } from 'rxjs'; import { BaseRpcContext } from '../ctx-host/base-rpc.context'; import { Transport } from '../enums'; import { ClientOptions, MessageHandler, MicroserviceOptions, MsPattern, ReadPacket, WritePacket } from '../interfaces'; import { ConsumerDeserializer } from '../interfaces/deserializer.interface'; import { ConsumerSerializer } from '../interfaces/serializer.interface'; /** * @publicApi */ export declare abstract class Server = Record, Status extends string = string> { /** * Unique transport identifier. */ transportId?: Transport | symbol; protected readonly messageHandlers: Map>; protected readonly logger: LoggerService; protected serializer: ConsumerSerializer; protected deserializer: ConsumerDeserializer; protected onProcessingStartHook: (transportId: Transport | symbol, context: BaseRpcContext, done: () => Promise) => void; protected onProcessingEndHook: (transportId: Transport | symbol, context: BaseRpcContext) => void; protected _status$: ReplaySubject; /** * Returns an observable that emits status changes. */ get status(): Observable; /** * Registers an event listener for the given event. * @param event Event name * @param callback Callback to be executed when the event is emitted */ abstract on(event: EventKey, callback: EventCallback): any; /** * Returns an instance of the underlying server/broker instance, * or a group of servers if there are more than one. */ abstract unwrap(): T; /** * Method called when server is being initialized. * @param callback Function to be called upon initialization */ abstract listen(callback: (...optionalParams: unknown[]) => any): any; /** * Method called when server is being terminated. */ abstract close(): any; /** * Sets the transport identifier. * @param transportId Unique transport identifier. */ setTransportId(transportId: Transport | symbol): void; /** * Sets a hook that will be called when processing starts. */ setOnProcessingStartHook(hook: (transportId: Transport | symbol, context: unknown, done: () => Promise) => void): void; /** * Sets a hook that will be called when processing ends. */ setOnProcessingEndHook(hook: (transportId: Transport | symbol, context: unknown) => void): void; addHandler(pattern: any, callback: MessageHandler, isEventHandler?: boolean, extras?: Record): void; getHandlers(): Map; getHandlerByPattern(pattern: string): MessageHandler | null; send(stream$: Observable, respond: (data: WritePacket) => Promise | void): Subscription; handleEvent(pattern: string, packet: ReadPacket, context: BaseRpcContext): Promise; transformToObservable(resultOrDeferred: Observable | Promise): Observable; transformToObservable(resultOrDeferred: T): never extends Observable> ? Observable : Observable>; getOptionsProp(obj: Options, prop: Attribute): Options[Attribute]; getOptionsProp(obj: Options, prop: Attribute, defaultValue: DefaultValue): Required[Attribute]; protected handleError(error: string): void; protected loadPackage(name: string, ctx: string, loader?: Function): T; protected initializeSerializer(options: ClientOptions['options']): void; protected initializeDeserializer(options: ClientOptions['options']): void; /** * Transforms the server Pattern to valid type and returns a route for him. * * @param {string} pattern - server pattern * @returns string */ protected getRouteFromPattern(pattern: string): string; protected normalizePattern(pattern: MsPattern): string; }