strong-tie/inbound-calls
0
1import { ErrorObject } from '@fastify/ajv-compiler'2import { FastifyContextConfig } from './context'3import { FastifyInstance } from './instance'4import { FastifyBaseLogger } from './logger'5import { FastifyRouteConfig, RouteGenericInterface, RouteHandlerMethod } from './route'6import { FastifySchema } from './schema'7import { FastifyRequestType, FastifyTypeProvider, FastifyTypeProviderDefault, ResolveFastifyRequestType } from './type-provider'8import { ContextConfigDefault, HTTPMethods, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestBodyDefault, RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from './utils'9 10type HTTPRequestPart = 'body' | 'query' | 'querystring' | 'params' | 'headers'11export interface RequestGenericInterface {12 Body?: RequestBodyDefault;13 Querystring?: RequestQuerystringDefault;14 Params?: RequestParamsDefault;15 Headers?: RequestHeadersDefault;16}17 18export interface ValidationFunction {19 (input: any): boolean20 errors?: null | ErrorObject[];21}22 23export interface RequestRouteOptions<ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema> {24 method: HTTPMethods | HTTPMethods[];25 // `url` can be `undefined` for instance when `request.is404` is true26 url: string | undefined;27 bodyLimit: number;28 attachValidation: boolean;29 logLevel: string;30 exposeHeadRoute: boolean;31 prefixTrailingSlash: string;32 config: FastifyContextConfig & FastifyRouteConfig & ContextConfig;33 schema?: SchemaCompiler; // it is empty for 404 requests34 handler: RouteHandlerMethod;35}36 37/**38 * FastifyRequest is an instance of the standard http or http2 request objects.39 * It defaults to http.IncomingMessage, and it also extends the relative request object.40 */41export interface FastifyRequest<RouteGeneric extends RouteGenericInterface = RouteGenericInterface,42 RawServer extends RawServerBase = RawServerDefault,43 RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,44 SchemaCompiler extends FastifySchema = FastifySchema,45 TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,46 ContextConfig = ContextConfigDefault,47 Logger extends FastifyBaseLogger = FastifyBaseLogger,48 RequestType extends FastifyRequestType = ResolveFastifyRequestType<TypeProvider, SchemaCompiler, RouteGeneric>49// ^ Temporary Note: RequestType has been re-ordered to be the last argument in50// generic list. This generic argument is now considered optional as it can be51// automatically inferred from the SchemaCompiler, RouteGeneric and TypeProvider52// arguments. Implementations that already pass this argument can either omit53// the RequestType (preferred) or swap Logger and RequestType arguments when54// creating custom types of FastifyRequest. Related issue #412355> {56 id: string;57 params: RequestType['params']; // deferred inference58 raw: RawRequest;59 query: RequestType['query'];60 headers: RawRequest['headers'] & RequestType['headers']; // this enables the developer to extend the existing http(s|2) headers list61 log: Logger;62 server: FastifyInstance;63 body: RequestType['body'];64 65 /** in order for this to be used the user should ensure they have set the attachValidation option. */66 validationError?: Error & { validation: any; validationContext: string };67 68 /**69 * @deprecated Use `raw` property70 */71 readonly req: RawRequest & RouteGeneric['Headers']; // this enables the developer to extend the existing http(s|2) headers list72 readonly ip: string;73 readonly ips?: string[];74 readonly host: string;75 readonly port: number;76 readonly hostname: string;77 readonly url: string;78 readonly originalUrl: string;79 readonly protocol: 'http' | 'https';80 readonly method: string;81 readonly routeOptions: Readonly<RequestRouteOptions<ContextConfig, SchemaCompiler>>82 readonly is404: boolean;83 readonly socket: RawRequest['socket'];84 85 getValidationFunction(httpPart: HTTPRequestPart): ValidationFunction86 getValidationFunction(schema: { [key: string]: any }): ValidationFunction87 compileValidationSchema(schema: { [key: string]: any }, httpPart?: HTTPRequestPart): ValidationFunction88 validateInput(input: any, schema: { [key: string]: any }, httpPart?: HTTPRequestPart): boolean89 validateInput(input: any, httpPart?: HTTPRequestPart): boolean90}91 