UNPKG

@nestjs/core

Version:

The core of NestJS, a TypeScript framework for Node.js backends: modules, dependency injection and the request pipeline, on Express, Fastify or node:http.

80 lines (79 loc) • 5.59 kB
import type { ArgumentMetadata, ContextType, RouteParamMetadata, SseOptions } from '@nestjs/common'; import { type CanActivate, type HttpServer, type ParamData, type PipeTransform, type RequestMethod } from '@nestjs/common'; import { type Controller, RouteParamtypes } from '@nestjs/common/internal'; import type { StandardSchemaV1 } from '@standard-schema/spec'; import { GuardsConsumer, GuardsContextCreator } from '../guards/index.js'; import { ExecutionContextHost } from '../helpers/execution-context-host.js'; import { HandleResponseFn, HandlerMetadata } from '../helpers/handler-metadata-storage.js'; import { InterceptorsConsumer } from '../interceptors/interceptors-consumer.js'; import { InterceptorsContextCreator } from '../interceptors/interceptors-context-creator.js'; import { PipesConsumer } from '../pipes/pipes-consumer.js'; import { PipesContextCreator } from '../pipes/pipes-context-creator.js'; import { IRouteParamsFactory } from './interfaces/route-params-factory.interface.js'; import { CustomHeader, RedirectResponse } from './router-response-controller.js'; export interface ParamProperties { index: number; type: RouteParamtypes | string; data: ParamData; pipes: PipeTransform[]; extractValue: <TRequest, TResponse>(req: TRequest, res: TResponse, next: Function) => any; schema?: StandardSchemaV1; } export declare class RouterExecutionContext { private readonly paramsFactory; private readonly pipesContextCreator; private readonly pipesConsumer; private readonly guardsContextCreator; private readonly guardsConsumer; private readonly interceptorsContextCreator; private readonly interceptorsConsumer; readonly applicationRef: HttpServer; private readonly handlerMetadataStorage; private readonly contextUtils; private readonly responseController; constructor(paramsFactory: IRouteParamsFactory, pipesContextCreator: PipesContextCreator, pipesConsumer: PipesConsumer, guardsContextCreator: GuardsContextCreator, guardsConsumer: GuardsConsumer, interceptorsContextCreator: InterceptorsContextCreator, interceptorsConsumer: InterceptorsConsumer, applicationRef: HttpServer); create(instance: Controller, callback: (...args: any[]) => unknown, methodName: string, moduleKey: string, requestMethod: RequestMethod, contextId?: import("../index.js").ContextId, inquirerId?: string): <TRequest, TResponse>(req: TRequest, res: TResponse, next: Function) => Promise<void>; getMetadata<TContext extends ContextType = ContextType>(instance: Controller, callback: (...args: any[]) => any, methodName: string, moduleKey: string, requestMethod: RequestMethod, contextType: TContext): HandlerMetadata; reflectRedirect(callback: (...args: unknown[]) => unknown): RedirectResponse; reflectHttpStatusCode(callback: (...args: unknown[]) => unknown): number; reflectRenderTemplate(callback: (...args: unknown[]) => unknown): string; reflectResponseHeaders(callback: (...args: unknown[]) => unknown): CustomHeader[]; reflectSse(callback: (...args: unknown[]) => unknown): string; reflectSseOptions(callback: (...args: unknown[]) => unknown): SseOptions | undefined; exchangeKeysForValues(keys: string[], metadata: Record<number, RouteParamMetadata>, moduleContext: string, contextId?: import("../index.js").ContextId, inquirerId?: string, contextFactory?: (args: unknown[]) => ExecutionContextHost): ParamProperties[]; getParamValue<T>(value: T, metadata: ArgumentMetadata, pipes: PipeTransform[]): Promise<unknown>; isPipeable(type: number | string): boolean; createGuardsFn<TContext extends string = ContextType>(guards: CanActivate[], instance: Controller, callback: (...args: any[]) => any, contextType?: TContext): ((args: any[]) => Promise<void>) | null; createPipesFn(pipes: PipeTransform[], paramsOptions: (ParamProperties & { metatype?: any; })[]): (<TRequest, TResponse>(args: any[], req: TRequest, res: TResponse, next: Function) => Promise<unknown> | undefined) | null; createHandleResponseFn(callback: (...args: unknown[]) => unknown, isResponseHandled: boolean, redirectResponse?: RedirectResponse, httpStatusCode?: number): HandleResponseFn; /** * The stream to send, if any: the one the interceptors handed back, or the * one in the plain object they wrapped it in (`{ data: stream }`), which * cannot go out that way, unless they read it to build their own result. It * is never the handler's own in place of what they returned: they may have * replaced it with a stream that leaves something out, or with something * that is not a stream (a notice, nothing at all), which is sent as it is. */ private pickStreamingBody; /** * Releases streams that are not sent once the response is over: sent, or * its connection closed. The connection is watched as well, since a * pipelined response that still waits for its turn never learns that it is * gone. */ private releaseOnceResponseIsOver; private trackHandlerStream; private observeHandlerResult; /** * Emits once the client connection closes, or right away if it already has. * With interceptors, watching starts only once the route handler itself * produces an Observable, and starts over each time it does (e.g. on a * retry). Picks the close source the same way `RouterResponseController#sse()` * does, so the two disconnect watchers cannot drift apart. */ private fromClientDisconnect; private isResponseHandled; private attachSseAbortSignal; }