CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
route.d.ts186 linesDownload Raw Back to types
1import { FastifyError } from '@fastify/error'2import { ConstraintStrategy } from 'find-my-way'3import { FastifyContextConfig } from './context'4import { onErrorMetaHookHandler, onRequestAbortMetaHookHandler, onRequestMetaHookHandler, onResponseMetaHookHandler, onSendMetaHookHandler, onTimeoutMetaHookHandler, preHandlerMetaHookHandler, preParsingMetaHookHandler, preSerializationMetaHookHandler, preValidationMetaHookHandler } from './hooks'5import { FastifyInstance } from './instance'6import { FastifyBaseLogger, FastifyChildLoggerFactory, LogLevel } from './logger'7import { FastifyReply, ReplyGenericInterface } from './reply'8import { FastifyRequest, RequestGenericInterface } from './request'9import { FastifySchema, FastifySchemaCompiler, FastifySerializerCompiler, SchemaErrorFormatter } from './schema'10import {11  FastifyTypeProvider,12  FastifyTypeProviderDefault,13  ResolveFastifyReplyReturnType14} from './type-provider'15import { ContextConfigDefault, HTTPMethods, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault } from './utils'16 17export interface FastifyRouteConfig {18  url: string;19  method: HTTPMethods | HTTPMethods[];20}21 22export interface RouteGenericInterface extends RequestGenericInterface, ReplyGenericInterface { }23 24export type RouteConstraintType = Omit<ConstraintStrategy<any>, 'deriveConstraint'> & {25  deriveConstraint<Context>(req: RawRequestDefaultExpression<RawServerDefault>, ctx?: Context, done?: (err: Error, ...args: any) => any): any,26}27 28export interface RouteConstraint {29  version?: string30  host?: RegExp | string31  [name: string]: unknown32}33 34/**35 * Route shorthand options for the various shorthand methods36 */37export interface RouteShorthandOptions<38  RawServer extends RawServerBase = RawServerDefault,39  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,40  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,41  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,42  ContextConfig = ContextConfigDefault,43  SchemaCompiler extends FastifySchema = FastifySchema,44  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,45  Logger extends FastifyBaseLogger = FastifyBaseLogger46> {47  schema?: SchemaCompiler, // originally FastifySchema48  attachValidation?: boolean;49  exposeHeadRoute?: boolean;50 51  validatorCompiler?: FastifySchemaCompiler<NoInfer<SchemaCompiler>>;52  serializerCompiler?: FastifySerializerCompiler<NoInfer<SchemaCompiler>>;53  bodyLimit?: number;54  logLevel?: LogLevel;55  config?: FastifyContextConfig & ContextConfig;56  constraints?: RouteConstraint,57  prefixTrailingSlash?: 'slash' | 'no-slash' | 'both';58  errorHandler?: (59    this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,60    error: FastifyError,61    request: FastifyRequest<RouteGeneric, RawServer, RawRequest, NoInfer<SchemaCompiler>, TypeProvider, ContextConfig, Logger>,62    reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider>63  ) => void;64  childLoggerFactory?: FastifyChildLoggerFactory<RawServer, RawRequest, RawReply, Logger, TypeProvider>;65  schemaErrorFormatter?: SchemaErrorFormatter;66 67  // hooks68  onRequest?: onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>69  | onRequestMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];70  preParsing?: preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>71  | preParsingMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];72  preValidation?: preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>73  | preValidationMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];74  preHandler?: preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>75  | preHandlerMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];76  preSerialization?: preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>77  | preSerializationMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];78  onSend?: onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>79  | onSendMetaHookHandler<unknown, RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];80  onResponse?: onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>81  | onResponseMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];82  onTimeout?: onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>83  | onTimeoutMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];84  onError?: onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInfer<SchemaCompiler>, TypeProvider, Logger>85  | onErrorMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, FastifyError, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];86  onRequestAbort?: onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>87  | onRequestAbortMetaHookHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>[];88}89/**90 * Route handler method declaration.91 */92export type RouteHandlerMethod<93  RawServer extends RawServerBase = RawServerDefault,94  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,95  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,96  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,97  ContextConfig = ContextConfigDefault,98  SchemaCompiler extends FastifySchema = FastifySchema,99  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,100  Logger extends FastifyBaseLogger = FastifyBaseLogger101> = (102  this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,103  request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,104  reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>105  // This return type used to be a generic type argument. Due to TypeScript's inference of return types, this rendered returns unchecked.106) => ResolveFastifyReplyReturnType<TypeProvider, SchemaCompiler, RouteGeneric>107 108/**109 * Shorthand options including the handler function property110 */111export interface RouteShorthandOptionsWithHandler<112  RawServer extends RawServerBase = RawServerDefault,113  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,114  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,115  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,116  ContextConfig = ContextConfigDefault,117  SchemaCompiler extends FastifySchema = FastifySchema,118  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,119  Logger extends FastifyBaseLogger = FastifyBaseLogger120> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {121  handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, NoInfer<SchemaCompiler>, TypeProvider, Logger>;122}123 124/**125 * Fastify Router Shorthand method type that is similar to the Express/Restify approach126 */127export interface RouteShorthandMethod<128  RawServer extends RawServerBase = RawServerDefault,129  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,130  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,131  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,132  Logger extends FastifyBaseLogger = FastifyBaseLogger133> {134  <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(135    path: string,136    opts: RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>,137    handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>138  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;139  <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(140    path: string,141    handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>142  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;143  <RouteGeneric extends RouteGenericInterface = RouteGenericInterface, ContextConfig = ContextConfigDefault, const SchemaCompiler extends FastifySchema = FastifySchema>(144    path: string,145    opts: RouteShorthandOptionsWithHandler<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>146  ): FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>;147}148 149/**150 * Fastify route method options.151 */152export interface RouteOptions<153  RawServer extends RawServerBase = RawServerDefault,154  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,155  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,156  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,157  ContextConfig = ContextConfigDefault,158  SchemaCompiler extends FastifySchema = FastifySchema,159  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,160  Logger extends FastifyBaseLogger = FastifyBaseLogger161> extends RouteShorthandOptions<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger> {162  method: HTTPMethods | HTTPMethods[];163  url: string;164  handler: RouteHandlerMethod<RawServer, RawRequest, RawReply, RouteGeneric, ContextConfig, SchemaCompiler, TypeProvider, Logger>;165}166 167export type RouteHandler<168  RouteGeneric extends RouteGenericInterface = RouteGenericInterface,169  RawServer extends RawServerBase = RawServerDefault,170  RawRequest extends RawRequestDefaultExpression<RawServer> = RawRequestDefaultExpression<RawServer>,171  RawReply extends RawReplyDefaultExpression<RawServer> = RawReplyDefaultExpression<RawServer>,172  ContextConfig = ContextConfigDefault,173  SchemaCompiler extends FastifySchema = FastifySchema,174  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault,175  Logger extends FastifyBaseLogger = FastifyBaseLogger176> = (177  this: FastifyInstance<RawServer, RawRequest, RawReply, Logger, TypeProvider>,178  request: FastifyRequest<RouteGeneric, RawServer, RawRequest, SchemaCompiler, TypeProvider, ContextConfig, Logger>,179  reply: FastifyReply<RouteGeneric, RawServer, RawRequest, RawReply, ContextConfig, SchemaCompiler, TypeProvider>180) => RouteGeneric['Reply'] | void | Promise<RouteGeneric['Reply'] | void>181 182export type DefaultRoute<Request, Reply> = (183  req: Request,184  res: Reply,185) => void186