UNPKG

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