1 | import { ErrorObject } from '@fastify/ajv-compiler'
|
2 | import { FastifyRequestContext, FastifyContextConfig } from './context'
|
3 | import { FastifyInstance } from './instance'
|
4 | import { FastifyBaseLogger } from './logger'
|
5 | import { RouteGenericInterface, FastifyRouteConfig, RouteHandlerMethod } from './route'
|
6 | import { FastifySchema } from './schema'
|
7 | import { FastifyRequestType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyRequestType } from './type-provider'
|
8 | import { ContextConfigDefault, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestBodyDefault, RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from './utils'
|
9 |
|
10 | type HTTPRequestPart = 'body' | 'query' | 'querystring' | 'params' | 'headers'
|
11 | export interface RequestGenericInterface {
|
12 | Body?: RequestBodyDefault;
|
13 | Querystring?: RequestQuerystringDefault;
|
14 | Params?: RequestParamsDefault;
|
15 | Headers?: RequestHeadersDefault;
|
16 | }
|
17 |
|
18 | export interface ValidationFunction {
|
19 | (input: any): boolean
|
20 | errors?: null | ErrorObject[];
|
21 | }
|
22 |
|
23 | export interface RequestRouteOptions<ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema> {
|
24 | method: string;
|
25 |
|
26 | url: string | undefined;
|
27 | bodyLimit: number;
|
28 | attachValidation: boolean;
|
29 | logLevel: string;
|
30 | version: string | undefined;
|
31 | exposeHeadRoute: boolean;
|
32 | prefixTrailingSlash: string;
|
33 | config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;
|
34 | schema?: SchemaCompiler;
|
35 | handler: RouteHandlerMethod;
|
36 | }
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 | export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = RouteGenericInterface,
|
43 | RawServer extends RawServerBase = RawServerDefault,
|
44 | RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,
|
45 | SchemaCompiler extends FastifySchema = FastifySchema,
|
46 | TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,
|
47 | ContextConfig = ContextConfigDefault,
|
48 | Logger extends FastifyBaseLogger = FastifyBaseLogger,
|
49 | RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>
|
50 | // ^ Temporary Note: RequestType has been re-ordered to be the last argument in
|
51 | // generic list. This generic argument is now considered optional as it can be
|
52 | // automatically inferred from the SchemaCompiler, RouteGeneric and TypeProvider
|
53 | // arguments. Implementations that already pass this argument can either omit
|
54 | // the RequestType (preferred) or swap Logger and RequestType arguments when
|
55 | // creating custom types of FastifyRequest. Related issue #4123
|
56 | > {
|
57 | id: string;
|
58 | params: RequestType['params'];
|
59 | raw: RawRequest;
|
60 | query: RequestType['query'];
|
61 | headers: RawRequest['headers'] & RequestType['headers'];
|
62 | log: Logger;
|
63 | server: FastifyInstance;
|
64 | body: RequestType['body'];
|
65 | context: FastifyRequestContext<ContextConfig>;
|
66 | routeConfig: FastifyRequestContext<ContextConfig>['config'];
|
67 | routeSchema?: FastifySchema;
|
68 |
|
69 |
|
70 | validationError?: Error & { validation: any; validationContext: string };
|
71 |
|
72 | |
73 |
|
74 |
|
75 | readonly req: RawRequest & RouteGeneric['Headers'];
|
76 | readonly ip: string;
|
77 | readonly ips?: string[];
|
78 | readonly hostname: string;
|
79 | readonly url: string;
|
80 | readonly originalUrl: string;
|
81 | readonly protocol: 'http' | 'https';
|
82 | readonly method: string;
|
83 | readonly routerPath: string;
|
84 | readonly routerMethod: string;
|
85 | readonly routeOptions: Readonly<RequestRouteOptions<ContextConfig, SchemaCompiler>>
|
86 | readonly is404: boolean;
|
87 | readonly socket: RawRequest['socket'];
|
88 |
|
89 | getValidationFunction(httpPart: HTTPRequestPart): ValidationFunction
|
90 | getValidationFunction(schema: {[key: string]: any}): ValidationFunction
|
91 | compileValidationSchema(schema: {[key: string]: any}, httpPart?: HTTPRequestPart): ValidationFunction
|
92 | validateInput(input: any, schema: {[key: string]: any}, httpPart?: HTTPRequestPart): boolean
|
93 | validateInput(input: any, httpPart?: HTTPRequestPart): boolean
|
94 |
|
95 |
|
96 |
|
97 | readonly connection: RawRequest['socket'];
|
98 | }
|