UNPKG

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