UNPKG

9.03 kBTypeScriptView Raw
1import { RequestMethod, VersioningOptions } from '@nestjs/common';
2import { VersionValue } from '@nestjs/common/interfaces';
3import { CorsOptions, CorsOptionsDelegate } from '@nestjs/common/interfaces/external/cors-options.interface';
4import { AbstractHttpAdapter } from '@nestjs/core/adapters/http-adapter';
5import { FastifyBaseLogger, FastifyBodyParser, FastifyInstance, FastifyPluginAsync, FastifyPluginCallback, FastifyRegister, FastifyReply, FastifyRequest, FastifyServerOptions, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestGenericInterface } from 'fastify';
6import * as http2 from 'http2';
7import * as https from 'https';
8import * as http from 'http';
9import { InjectOptions, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request';
10import { NestFastifyBodyParserOptions } from '../interfaces';
11import { FastifyStaticOptions, FastifyViewOptions } from '../interfaces/external';
12type FastifyAdapterBaseOptions<Server extends RawServerBase = RawServerDefault, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyServerOptions<Server, Logger> & {
13 skipMiddie?: boolean;
14};
15type FastifyHttp2SecureOptions<Server extends http2.Http2SecureServer, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyAdapterBaseOptions<Server, Logger> & {
16 http2: true;
17 https: http2.SecureServerOptions;
18};
19type FastifyHttp2Options<Server extends http2.Http2Server, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyAdapterBaseOptions<Server, Logger> & {
20 http2: true;
21 http2SessionTimeout?: number;
22};
23type FastifyHttpsOptions<Server extends https.Server, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyAdapterBaseOptions<Server, Logger> & {
24 https: https.ServerOptions;
25};
26type FastifyHttpOptions<Server extends http.Server, Logger extends FastifyBaseLogger = FastifyBaseLogger> = FastifyAdapterBaseOptions<Server, Logger> & {
27 http: http.ServerOptions;
28};
29type VersionedRoute<TRequest, TResponse> = ((req: TRequest, res: TResponse, next: Function) => Function) & {
30 version: VersionValue;
31 versioningOptions: VersioningOptions;
32};
33/**
34 * The following type assertion is valid as we enforce "middie" plugin registration
35 * which enhances the FastifyRequest.RawRequest with the "originalUrl" property.
36 * ref https://github.com/fastify/middie/pull/16
37 * ref https://github.com/fastify/fastify/pull/559
38 */
39type FastifyRawRequest<TServer extends RawServerBase> = RawRequestDefaultExpression<TServer> & {
40 originalUrl?: string;
41};
42/**
43 * @publicApi
44 */
45export declare class FastifyAdapter<TServer extends RawServerBase = RawServerDefault, TRawRequest extends FastifyRawRequest<TServer> = FastifyRawRequest<TServer>, TRawResponse extends RawReplyDefaultExpression<TServer> = RawReplyDefaultExpression<TServer>, TRequest extends FastifyRequest<RequestGenericInterface, TServer, TRawRequest> = FastifyRequest<RequestGenericInterface, TServer, TRawRequest>, TReply extends FastifyReply<TServer, TRawRequest, TRawResponse> = FastifyReply<TServer, TRawRequest, TRawResponse>, TInstance extends FastifyInstance<TServer, TRawRequest, TRawResponse> = FastifyInstance<TServer, TRawRequest, TRawResponse>> extends AbstractHttpAdapter<TServer, TRequest, TReply> {
46 protected readonly instance: TInstance;
47 private _isParserRegistered;
48 private isMiddieRegistered;
49 private versioningOptions?;
50 private readonly versionConstraint;
51 get isParserRegistered(): boolean;
52 constructor(instanceOrOptions?: TInstance | FastifyHttp2Options<any> | FastifyHttp2SecureOptions<any> | FastifyHttpsOptions<any> | FastifyHttpOptions<any> | FastifyAdapterBaseOptions<TServer>);
53 init(): Promise<void>;
54 listen(port: string | number, callback?: () => void): void;
55 listen(port: string | number, hostname: string, callback?: () => void): void;
56 get(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
57 post(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
58 head(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
59 delete(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
60 put(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
61 patch(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
62 options(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
63 search(...args: any[]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
64 applyVersionFilter(handler: Function, version: VersionValue, versioningOptions: VersioningOptions): VersionedRoute<TRequest, TReply>;
65 reply(response: TRawResponse | TReply, body: any, statusCode?: number): FastifyReply<TServer, TRawRequest, TRawResponse, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
66 status(response: TRawResponse | TReply, statusCode: number): TRawResponse | FastifyReply<TServer, TRawRequest, TRawResponse, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
67 end(response: TReply, message?: string): void;
68 render(response: TReply & {
69 view: Function;
70 }, view: string, options: any): any;
71 redirect(response: TReply, statusCode: number, url: string): FastifyReply<TServer, TRawRequest, TRawResponse, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
72 setErrorHandler(handler: Parameters<TInstance['setErrorHandler']>[0]): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProvider>;
73 setNotFoundHandler(handler: Function): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault>;
74 getHttpServer<T = TServer>(): T;
75 getInstance<T = TInstance>(): T;
76 register<TRegister extends Parameters<FastifyRegister<TInstance>>>(plugin: TRegister['0'], opts?: TRegister['1']): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<undefined>;
77 inject(): LightMyRequestChain;
78 inject(opts: InjectOptions | string): Promise<LightMyRequestResponse>;
79 close(): Promise<undefined>;
80 initHttpServer(): void;
81 useStaticAssets(options: FastifyStaticOptions): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<undefined>;
82 setViewEngine(options: FastifyViewOptions | string): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<undefined>;
83 isHeadersSent(response: TReply): boolean;
84 getHeader?(response: any, name: string): any;
85 setHeader(response: TReply, name: string, value: string): FastifyReply<TServer, TRawRequest, TRawResponse, import("fastify").RouteGenericInterface, unknown, import("fastify").FastifySchema, import("fastify").FastifyTypeProviderDefault, unknown>;
86 appendHeader?(response: any, name: string, value: string): void;
87 getRequestHostname(request: TRequest): string;
88 getRequestMethod(request: TRequest): string;
89 getRequestUrl(request: TRequest): string;
90 getRequestUrl(request: TRawRequest): string;
91 enableCors(options: CorsOptions | CorsOptionsDelegate<TRequest>): void;
92 registerParserMiddleware(prefix?: string, rawBody?: boolean): void;
93 useBodyParser(type: string | string[] | RegExp, rawBody: boolean, options?: NestFastifyBodyParserOptions, parser?: FastifyBodyParser<Buffer, TServer>): void;
94 createMiddlewareFactory(requestMethod: RequestMethod): Promise<(path: string, callback: Function) => any>;
95 getType(): string;
96 protected registerWithPrefix(factory: FastifyPluginCallback<any> | FastifyPluginAsync<any> | Promise<{
97 default: FastifyPluginCallback<any>;
98 }> | Promise<{
99 default: FastifyPluginAsync<any>;
100 }>, prefix?: string): FastifyInstance<TServer, TRawRequest, TRawResponse, FastifyBaseLogger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<undefined>;
101 private isNativeResponse;
102 private registerJsonContentParser;
103 private registerUrlencodedContentParser;
104 private registerMiddie;
105 private getRequestOriginalUrl;
106 private injectRouteOptions;
107}
108export {};