import { FastifyInstance } from './instance' import { FastifyRequest, RequestGenericInterface } from './request' import { FastifyReply, ReplyGenericInterface } from './reply' import { FastifySchema, FastifySchemaCompiler, FastifySchemaValidationError, FastifySerializerCompiler } from './schema' import { HTTPMethods, RawServerBase, RawServerDefault, RawRequestDefaultExpression, RawReplyDefaultExpression, ContextConfigDefault } from './utils' import { LogLevel } from './logger' import { preValidationHookHandler, preHandlerHookHandler, preSerializationHookHandler, onRequestHookHandler, preParsingHookHandler, onResponseHookHandler, onSendHookHandler, onErrorHookHandler, onTimeoutHookHandler } from './hooks' import { FastifyError } from 'fastify-error' import { FastifyContext } from './context' export interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface {} /** * Route shorthand options for the various shorthand methods */ export interface RouteShorthandOptions< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression = RawRequestDefaultExpression, RawReply extends RawReplyDefaultExpression = RawReplyDefaultExpression, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, > { schema?: FastifySchema; attachValidation?: boolean; exposeHeadRoute?: boolean; validatorCompiler?: FastifySchemaCompiler; serializerCompiler?: FastifySerializerCompiler; bodyLimit?: number; logLevel?: LogLevel; config?: FastifyContext['config']; version?: string; constraints?: { [name: string]: any }, prefixTrailingSlash?: 'slash'|'no-slash'|'both'; errorHandler?: (this: FastifyInstance, error: FastifyError, request: FastifyRequest, reply: FastifyReply) => void; // TODO: Change to actual type. schemaErrorFormatter?: (errors: FastifySchemaValidationError[], dataVar: string) => Error; // hooks onRequest?: onRequestHookHandler | onRequestHookHandler[]; preParsing?: preParsingHookHandler | preParsingHookHandler[]; preValidation?: preValidationHookHandler | preValidationHookHandler[]; preHandler?: preHandlerHookHandler | preHandlerHookHandler[]; preSerialization?: preSerializationHookHandler | preSerializationHookHandler[]; onSend?: onSendHookHandler | onSendHookHandler[]; onResponse?: onResponseHookHandler | onResponseHookHandler[]; onTimeout?: onTimeoutHookHandler | onTimeoutHookHandler[]; onError?: onErrorHookHandler | onErrorHookHandler[]; } /** * Route handler method declaration. */ export type RouteHandlerMethod< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression = RawRequestDefaultExpression, RawReply extends RawReplyDefaultExpression = RawReplyDefaultExpression, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault > = ( this: FastifyInstance, request: FastifyRequest, reply: FastifyReply ) => void | Promise /** * Shorthand options including the handler function property */ export interface RouteShorthandOptionsWithHandler< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression = RawRequestDefaultExpression, RawReply extends RawReplyDefaultExpression = RawReplyDefaultExpression, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, > extends RouteShorthandOptions { handler: RouteHandlerMethod; } /** * Fastify Router Shorthand method type that is similar to the Express/Restify approach */ export interface RouteShorthandMethod< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression = RawRequestDefaultExpression, RawReply extends RawReplyDefaultExpression = RawReplyDefaultExpression, > { ( path: string, opts: RouteShorthandOptions, handler: RouteHandlerMethod ): FastifyInstance; ( path: string, handler: RouteHandlerMethod ): FastifyInstance; ( path: string, opts: RouteShorthandOptionsWithHandler ): FastifyInstance; } /** * Fastify route method options. */ export interface RouteOptions< RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression = RawRequestDefaultExpression, RawReply extends RawReplyDefaultExpression = RawReplyDefaultExpression, RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, SchemaCompiler = FastifySchema, > extends RouteShorthandOptions { method: HTTPMethods | HTTPMethods[]; url: string; handler: RouteHandlerMethod; } export type RouteHandler< RouteGeneric extends RouteGenericInterface = RouteGenericInterface, RawServer extends RawServerBase = RawServerDefault, RawRequest extends RawRequestDefaultExpression = RawRequestDefaultExpression, RawReply extends RawReplyDefaultExpression = RawReplyDefaultExpression, ContextConfig = ContextConfigDefault > = ( this: FastifyInstance, request: FastifyRequest, reply: FastifyReply ) => void | Promise export type DefaultRoute = ( req: Request, res: Reply, ) => void;