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