UNPKG

@nestjs/common

Version:

Nest - modern, fast, powerful node.js web framework (@common)

92 lines (91 loc) 3.49 kB
import { Observable } from 'rxjs'; import { ExceptionFilter } from './exceptions/exception-filter.interface.js'; import { CanActivate } from './features/can-activate.interface.js'; import { NestInterceptor } from './features/nest-interceptor.interface.js'; import { PipeTransform } from './features/pipe-transform.interface.js'; import { ITransportServer } from './microservices/transport-server.interface.js'; import { PreRequestHook } from './microservices/pre-request-hook.interface.js'; import { INestApplicationContext } from './nest-application-context.interface.js'; import { WebSocketAdapter } from './websockets/web-socket-adapter.interface.js'; /** * Interface describing Microservice Context. * * @publicApi */ export interface INestMicroservice extends INestApplicationContext { /** * Starts the microservice. * * @returns {void} */ listen(): Promise<any>; /** * Registers a web socket adapter that will be used for Gateways. * Use to override the default `socket.io` library. * * @param {WebSocketAdapter} adapter * @returns {this} */ useWebSocketAdapter(adapter: WebSocketAdapter): this; /** * Registers global exception filters (will be used for every pattern handler). * * @param {...ExceptionFilter} filters */ useGlobalFilters(...filters: ExceptionFilter[]): this; /** * Registers global pipes (will be used for every pattern handler). * * @param {...PipeTransform} pipes */ useGlobalPipes(...pipes: PipeTransform<any>[]): this; /** * Registers global interceptors (will be used for every pattern handler). * * @param {...NestInterceptor} interceptors */ useGlobalInterceptors(...interceptors: NestInterceptor[]): this; /** * Registers global guards (will be used for every pattern handler). * * @param {...CanActivate} guards */ useGlobalGuards(...guards: CanActivate[]): this; /** * Registers a global preRequest hook (executed before all enhancers for every pattern handler). * Hooks receive an `ExecutionContext` and a `next` function that executes the rest of the pipeline. * Useful for setting up AsyncLocalStorage context, tracing, or correlation IDs. * * @param {...PreRequestHook} hooks */ registerPreRequestHook(...hooks: PreRequestHook[]): this; /** * Terminates the application. * * @returns {Promise<void>} */ close(): Promise<void>; /** * Returns an observable that emits status changes. * * @returns {Observable<string>} */ status: Observable<string>; /** * Registers an event listener for the given event. * @param event Event name * @param callback Callback to be executed when the event is emitted */ on<EventsMap extends Record<string, Function> = Record<string, Function>, EventKey extends keyof EventsMap = keyof EventsMap, EventCallback extends EventsMap[EventKey] = EventsMap[EventKey]>(event: EventKey, callback: EventCallback): void; /** * Returns an instance of the underlying server/broker instance, * or a group of servers if there are more than one. */ unwrap<T>(): T; /** * Returns the underlying transport server instance. * Use this to close only the transport (port/connection) without * triggering the full application shutdown lifecycle. */ getTransportServer(): ITransportServer; }