1 | import * as http from 'http'
|
2 | import * as http2 from 'http2'
|
3 | import * as https from 'https'
|
4 | import * as LightMyRequest from 'light-my-request'
|
5 |
|
6 | import { FastifyRequest, RequestGenericInterface } from './types/request'
|
7 | import { RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression } from './types/utils'
|
8 | import { FastifyLoggerInstance, FastifyLoggerOptions } from './types/logger'
|
9 | import { FastifyInstance } from './types/instance'
|
10 | import { FastifyServerFactory } from './types/serverFactory'
|
11 | import * as ajv from 'ajv'
|
12 | import { FastifyError } from 'fastify-error'
|
13 | import { FastifyReply } from './types/reply'
|
14 | import { FastifySchemaValidationError } from './types/schema'
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | declare function fastify<
|
25 | Server extends http2.Http2SecureServer,
|
26 | Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,
|
27 | Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
28 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
29 | >(opts: FastifyHttp2SecureOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger> & PromiseLike<FastifyInstance<Server, Request, Reply, Logger>>
|
30 | declare function fastify<
|
31 | Server extends http2.Http2Server,
|
32 | Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,
|
33 | Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
34 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
35 | >(opts: FastifyHttp2Options<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger> & PromiseLike<FastifyInstance<Server, Request, Reply, Logger>>
|
36 | declare function fastify<
|
37 | Server extends https.Server,
|
38 | Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,
|
39 | Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
40 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
41 | >(opts: FastifyHttpsOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger> & PromiseLike<FastifyInstance<Server, Request, Reply, Logger>>
|
42 | declare function fastify<
|
43 | Server extends http.Server,
|
44 | Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,
|
45 | Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,
|
46 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
47 | >(opts?: FastifyServerOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger> & PromiseLike<FastifyInstance<Server, Request, Reply, Logger>>
|
48 | export default fastify
|
49 |
|
50 | export type FastifyHttp2SecureOptions<
|
51 | Server extends http2.Http2SecureServer,
|
52 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
53 | > = FastifyServerOptions<Server, Logger> & {
|
54 | http2: true,
|
55 | https: http2.SecureServerOptions
|
56 | }
|
57 |
|
58 | export type FastifyHttp2Options<
|
59 | Server extends http2.Http2Server,
|
60 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
61 | > = FastifyServerOptions<Server, Logger> & {
|
62 | http2: true,
|
63 | http2SessionTimeout?: number,
|
64 | }
|
65 |
|
66 | export type FastifyHttpsOptions<
|
67 | Server extends https.Server,
|
68 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
69 | > = FastifyServerOptions<Server, Logger> & {
|
70 | https: https.ServerOptions
|
71 | }
|
72 | /**
|
73 | * Options for a fastify server instance. Utilizes conditional logic on the generic server parameter to enforce certain https and http2
|
74 | */
|
75 | export type FastifyServerOptions<
|
76 | RawServer extends RawServerBase = RawServerDefault,
|
77 | Logger extends FastifyLoggerInstance = FastifyLoggerInstance
|
78 | > = {
|
79 | ignoreTrailingSlash?: boolean,
|
80 | connectionTimeout?: number,
|
81 | keepAliveTimeout?: number,
|
82 | pluginTimeout?: number,
|
83 | bodyLimit?: number,
|
84 | maxParamLength?: number,
|
85 | disableRequestLogging?: boolean,
|
86 | exposeHeadRoutes?: boolean,
|
87 | onProtoPoisoning?: 'error' | 'remove' | 'ignore',
|
88 | onConstructorPoisoning?: 'error' | 'remove' | 'ignore',
|
89 | logger?: boolean | FastifyLoggerOptions<RawServer> | Logger,
|
90 | serverFactory?: FastifyServerFactory<RawServer>,
|
91 | caseSensitive?: boolean,
|
92 | requestIdHeader?: string,
|
93 | requestIdLogLabel?: string;
|
94 | genReqId?: <RequestGeneric extends RequestGenericInterface = RequestGenericInterface>(req: FastifyRequest<RequestGeneric, RawServer, RawRequestDefaultExpression<RawServer>>) => string,
|
95 | trustProxy?: boolean | string | string[] | number | TrustProxyFunction,
|
96 | querystringParser?: (str: string) => { [key: string]: unknown },
|
97 | versioning?: {
|
98 | storage(): {
|
99 | get(version: string): string | null,
|
100 | set(version: string, store: Function): void
|
101 | del(version: string): void,
|
102 | empty(): void
|
103 | },
|
104 | deriveVersion<Context>(req: Object, ctx?: Context): string
|
105 | },
|
106 | return503OnClosing?: boolean,
|
107 | ajv?: {
|
108 | customOptions?: ajv.Options,
|
109 | plugins?: Function[]
|
110 | },
|
111 | frameworkErrors?: <RequestGeneric extends RequestGenericInterface = RequestGenericInterface>(
|
112 | error: FastifyError,
|
113 | req: FastifyRequest<RequestGeneric, RawServer, RawRequestDefaultExpression<RawServer>>,
|
114 | res: FastifyReply<RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>>
|
115 | ) => void,
|
116 | rewriteUrl?: (req: RawRequestDefaultExpression<RawServer>) => string,
|
117 | schemaErrorFormatter?: (errors: FastifySchemaValidationError[], dataVar: string) => Error
|
118 | }
|
119 |
|
120 | type TrustProxyFunction = (address: string, hop: number) => boolean
|
121 |
|
122 | declare module 'fastify-error' {
|
123 | interface FastifyError {
|
124 | validation?: ValidationResult[];
|
125 | }
|
126 | }
|
127 |
|
128 | export interface ValidationResult {
|
129 | keyword: string;
|
130 | dataPath: string;
|
131 | schemaPath: string;
|
132 | params: Record<string, string | string[]>;
|
133 | message: string;
|
134 | }
|
135 |
|
136 |
|
137 | export { FastifyRequest, RequestGenericInterface } from './types/request'
|
138 | export { FastifyReply } from './types/reply'
|
139 | export { FastifyPluginCallback, FastifyPluginAsync, FastifyPluginOptions, FastifyPlugin } from './types/plugin'
|
140 | export { FastifyInstance } from './types/instance'
|
141 | export { FastifyLoggerOptions, FastifyLoggerInstance, FastifyLogFn, LogLevel } from './types/logger'
|
142 | export { FastifyContext } from './types/context'
|
143 | export { RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions, RouteShorthandOptionsWithHandler } from './types/route'
|
144 | export * from './types/register'
|
145 | export { FastifyBodyParser, FastifyContentTypeParser, AddContentTypeParser, hasContentTypeParser } from './types/content-type-parser'
|
146 | export { FastifyError } from 'fastify-error'
|
147 | export { FastifySchema, FastifySchemaCompiler } from './types/schema'
|
148 | export { HTTPMethods, RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault, ContextConfigDefault, RequestBodyDefault, RequestQuerystringDefault, RequestParamsDefault, RequestHeadersDefault } from './types/utils'
|
149 | export * from './types/hooks'
|
150 | export { FastifyServerFactory, FastifyServerFactoryHandler } from './types/serverFactory'
|
151 | export { fastify }
|