import { FastifyCorsOptions } from '@fastify/cors'; import { Logger, RequestMethod, VersioningOptions } from '@nestjs/common'; import { VersionValue } from '@nestjs/common/interfaces'; import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter'; import { FastifyBaseLogger, FastifyBodyParser, FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyRegister, FastifyReply, FastifyRequest, FastifyServerOptions, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface, RouteGenericInterface } from 'fastify'; import * as http from 'http'; import * as http2 from 'http2'; import * as https from 'https'; import { InjectOptions, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request'; import { NestFastifyBodyParserOptions } from '../interfaces'; import { FastifyStaticOptions, FastifyViewOptions } from '../interfaces/external'; type FastifyAdapterBaseOptions = FastifyServerOptions & { skipMiddie?: boolean; }; type FastifyHttp2SecureOptions = FastifyAdapterBaseOptions & { http2: true; https: http2.SecureServerOptions; }; type FastifyHttp2Options = FastifyAdapterBaseOptions & { http2: true; http2SessionTimeout?: number; }; type FastifyHttpsOptions = FastifyAdapterBaseOptions & { https: https.ServerOptions; }; type FastifyHttpOptions = FastifyAdapterBaseOptions & { http: http.ServerOptions; }; type VersionedRoute = ((req: TRequest, res: TResponse, next: Function) => Function) & { version: VersionValue; versioningOptions: VersioningOptions; }; /** * The following type assertion is valid as we enforce "middie" plugin registration * which enhances the FastifyRequest.RawRequest with the "originalUrl" property. * ref https://github.com/fastify/middie/pull/16 * ref https://github.com/fastify/fastify/pull/559 */ type FastifyRawRequest = RawRequestDefaultExpression & { originalUrl?: string; }; /** * @publicApi */ export declare class FastifyAdapter = FastifyRawRequest, TRawResponse extends RawReplyDefaultExpression = RawReplyDefaultExpression, TRequest extends FastifyRequest = FastifyRequest, TReply extends FastifyReply = FastifyReply, TInstance extends FastifyInstance = FastifyInstance> extends AbstractHttpAdapter { protected readonly logger: Logger; protected readonly instance: TInstance; protected _pathPrefix?: string; private _isParserRegistered; private onRequestHook?; private onResponseHook?; private isMiddieRegistered; private pendingMiddlewares; private versioningOptions?; private readonly versionConstraint; get isParserRegistered(): boolean; constructor(instanceOrOptions?: TInstance | FastifyHttp2Options | FastifyHttp2SecureOptions | FastifyHttpsOptions | FastifyHttpOptions | FastifyAdapterBaseOptions); setOnRequestHook(hook: (request: TRequest, reply: TReply, done: (err?: Error) => void) => void | Promise): void; setOnResponseHook(hook: (request: TRequest, reply: TReply, done: (err?: Error) => void) => void | Promise): void; init(): Promise; listen(port: string | number, callback?: () => void): void; listen(port: string | number, hostname: string, callback?: () => void): void; get(...args: any[]): FastifyInstance; post(...args: any[]): FastifyInstance; head(...args: any[]): FastifyInstance; delete(...args: any[]): FastifyInstance; put(...args: any[]): FastifyInstance; patch(...args: any[]): FastifyInstance; options(...args: any[]): FastifyInstance; search(...args: any[]): FastifyInstance; propfind(...args: any[]): FastifyInstance; proppatch(...args: any[]): FastifyInstance; mkcol(...args: any[]): FastifyInstance; copy(...args: any[]): FastifyInstance; move(...args: any[]): FastifyInstance; lock(...args: any[]): FastifyInstance; unlock(...args: any[]): FastifyInstance; applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute; reply(response: TRawResponse | TReply, body: any, statusCode?: number): FastifyReply; status(response: TRawResponse | TReply, statusCode: number): any; end(response: TReply, message?: string): void; render(response: TReply & { view: Function; }, view: string, options: any): any; redirect(response: TReply, statusCode: number, url: string): FastifyReply; setErrorHandler(handler: Parameters[0]): FastifyInstance; setNotFoundHandler(handler: Function): FastifyInstance; getHttpServer(): T; getInstance(): T; register>>>(plugin: TRegister['0'], opts?: TRegister['1']): any; inject(): LightMyRequestChain; inject(opts: InjectOptions | string): Promise; close(): Promise; initHttpServer(): void; useStaticAssets(options: FastifyStaticOptions): any; setViewEngine(options: FastifyViewOptions | string): any; isHeadersSent(response: TReply): boolean; getHeader(response: any, name: string): any; setHeader(response: TReply, name: string, value: string): FastifyReply; appendHeader(response: any, name: string, value: string): void; getRequestHostname(request: TRequest): string; getRequestMethod(request: TRequest): string; getRequestUrl(request: TRequest): string; getRequestUrl(request: TRawRequest): string; enableCors(options?: FastifyCorsOptions): void; registerParserMiddleware(prefix?: string, rawBody?: boolean): void; useBodyParser(type: string | string[] | RegExp, rawBody: boolean, options?: NestFastifyBodyParserOptions, parser?: FastifyBodyParser): void; createMiddlewareFactory(requestMethod: RequestMethod): Promise<(path: string, callback: Function) => any>; getType(): string; use(...args: any[]): any; protected registerWithPrefix(factory: FastifyPluginCallback | FastifyPluginAsync | Promise<{ default: FastifyPluginCallback; }> | Promise<{ default: FastifyPluginAsync; }>, prefix?: string): FastifyInstance & PromiseLike & { __linterBrands: "SafePromiseLike"; }; private isNativeResponse; private registerJsonContentParser; private registerUrlencodedContentParser; private registerMiddie; private getRequestOriginalUrl; private injectRouteOptions; private sanitizeUrl; private removeDuplicateSlashes; private trimLastSlash; } export {};