CoolFace
Apppublic

strong-tie/inbound-calls

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
fastify.d.ts240 linesDownload Raw Back to fastify
1import * as http from 'node:http'2import * as http2 from 'node:http2'3import * as https from 'node:https'4import { Socket } from 'node:net'5 6import { Options as AjvOptions, ValidatorFactory } from '@fastify/ajv-compiler'7import { FastifyError } from '@fastify/error'8import { Options as FJSOptions, SerializerFactory } from '@fastify/fast-json-stringify-compiler'9import { ConstraintStrategy, HTTPVersion } from 'find-my-way'10import { InjectOptions, CallbackFunc as LightMyRequestCallback, Chain as LightMyRequestChain, Response as LightMyRequestResponse } from 'light-my-request'11 12import { AddContentTypeParser, ConstructorAction, FastifyBodyParser, FastifyContentTypeParser, getDefaultJsonParser, hasContentTypeParser, ProtoAction } from './types/content-type-parser'13import { FastifyContextConfig, FastifyReplyContext, FastifyRequestContext } from './types/context'14import { FastifyErrorCodes } from './types/errors'15import { DoneFuncWithErrOrRes, HookHandlerDoneFunction, onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onListenAsyncHookHandler, onListenHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onRegisterHookHandler, onRequestAbortAsyncHookHandler, onRequestAbortHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preCloseAsyncHookHandler, preCloseHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler, RequestPayload } from './types/hooks'16import { FastifyInstance, FastifyListenOptions, PrintRoutesOptions } from './types/instance'17import {18  FastifyBaseLogger,19  FastifyChildLoggerFactory,20  FastifyLogFn,21  FastifyLoggerInstance,22  FastifyLoggerOptions,23  LogLevel,24  PinoLoggerOptions25} from './types/logger'26import { FastifyPlugin, FastifyPluginAsync, FastifyPluginCallback, FastifyPluginOptions } from './types/plugin'27import { FastifyRegister, FastifyRegisterOptions, RegisterOptions } from './types/register'28import { FastifyReply } from './types/reply'29import { FastifyRequest, RequestGenericInterface } from './types/request'30import { RouteGenericInterface, RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions, RouteShorthandOptionsWithHandler } from './types/route'31import { FastifySchema, FastifySchemaCompiler, FastifySchemaValidationError, SchemaErrorDataVar, SchemaErrorFormatter } from './types/schema'32import { FastifyServerFactory, FastifyServerFactoryHandler } from './types/serverFactory'33import { FastifyTypeProvider, FastifyTypeProviderDefault, SafePromiseLike } from './types/type-provider'34import { ContextConfigDefault, HTTPMethods, RawReplyDefaultExpression, RawRequestDefaultExpression, RawServerBase, RawServerDefault, RequestBodyDefault, RequestHeadersDefault, RequestParamsDefault, RequestQuerystringDefault } from './types/utils'35 36declare module '@fastify/error' {37  interface FastifyError {38    validationContext?: SchemaErrorDataVar;39    validation?: FastifySchemaValidationError[];40  }41}42 43type Fastify = typeof fastify44 45declare namespace fastify {46  export const errorCodes: FastifyErrorCodes47 48  export type FastifyHttp2SecureOptions<49    Server extends http2.Http2SecureServer,50    Logger extends FastifyBaseLogger = FastifyBaseLogger51  > = FastifyServerOptions<Server, Logger> & {52    http2: true,53    https: http2.SecureServerOptions,54    http2SessionTimeout?: number55  }56 57  export type FastifyHttp2Options<58    Server extends http2.Http2Server,59    Logger extends FastifyBaseLogger = FastifyBaseLogger60  > = FastifyServerOptions<Server, Logger> & {61    http2: true,62    http2SessionTimeout?: number63  }64 65  export type FastifyHttpsOptions<66    Server extends https.Server,67    Logger extends FastifyBaseLogger = FastifyBaseLogger68  > = FastifyServerOptions<Server, Logger> & {69    https: https.ServerOptions | null70  }71 72  export type FastifyHttpOptions<73    Server extends http.Server,74    Logger extends FastifyBaseLogger = FastifyBaseLogger75  > = FastifyServerOptions<Server, Logger> & {76    http?: http.ServerOptions | null77  }78 79  type FindMyWayVersion<RawServer extends RawServerBase> = RawServer extends http.Server ? HTTPVersion.V1 : HTTPVersion.V280 81  export interface ConnectionError extends Error {82    code: string,83    bytesParsed: number,84    rawPacket: {85      type: string,86      data: number[]87    }88  }89 90  type TrustProxyFunction = (address: string, hop: number) => boolean91 92  /**93   * Options for a fastify server instance. Utilizes conditional logic on the generic server parameter to enforce certain https and http294   */95  export type FastifyServerOptions<96    RawServer extends RawServerBase = RawServerDefault,97    Logger extends FastifyBaseLogger = FastifyBaseLogger98  > = {99    ignoreTrailingSlash?: boolean,100    ignoreDuplicateSlashes?: boolean,101    connectionTimeout?: number,102    keepAliveTimeout?: number,103    maxRequestsPerSocket?: number,104    forceCloseConnections?: boolean | 'idle',105    requestTimeout?: number,106    pluginTimeout?: number,107    bodyLimit?: number,108    maxParamLength?: number,109    disableRequestLogging?: boolean,110    exposeHeadRoutes?: boolean,111    onProtoPoisoning?: ProtoAction,112    onConstructorPoisoning?: ConstructorAction,113    logger?: boolean | FastifyLoggerOptions<RawServer> & PinoLoggerOptions,114    loggerInstance?: Logger115    serializerOpts?: FJSOptions | Record<string, unknown>,116    serverFactory?: FastifyServerFactory<RawServer>,117    caseSensitive?: boolean,118    allowUnsafeRegex?: boolean,119    requestIdHeader?: string | false,120    requestIdLogLabel?: string;121    useSemicolonDelimiter?: boolean,122    genReqId?: (req: RawRequestDefaultExpression<RawServer>) => string,123    trustProxy?: boolean | string | string[] | number | TrustProxyFunction,124    querystringParser?: (str: string) => { [key: string]: unknown },125    constraints?: {126      [name: string]: ConstraintStrategy<FindMyWayVersion<RawServer>, unknown>,127    },128    schemaController?: {129      bucket?: (parentSchemas?: unknown) => {130        add(schema: unknown): FastifyInstance;131        getSchema(schemaId: string): unknown;132        getSchemas(): Record<string, unknown>;133      };134      compilersFactory?: {135        buildValidator?: ValidatorFactory;136        buildSerializer?: SerializerFactory;137      };138    };139    return503OnClosing?: boolean,140    ajv?: {141      customOptions?: AjvOptions,142      plugins?: (Function | [Function, unknown])[]143    },144    frameworkErrors?: <RequestGeneric extends RequestGenericInterface = RequestGenericInterface, TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault, SchemaCompiler extends FastifySchema = FastifySchema>(145      error: FastifyError,146      req: FastifyRequest<RequestGeneric, RawServer, RawRequestDefaultExpression<RawServer>, FastifySchema, TypeProvider>,147      res: FastifyReply<RequestGeneric, RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, FastifyContextConfig, SchemaCompiler, TypeProvider>148    ) => void,149    rewriteUrl?: (150      // The RawRequestDefaultExpression, RawReplyDefaultExpression, and FastifyTypeProviderDefault parameters151      // should be narrowed further but those generic parameters are not passed to this FastifyServerOptions type152      this: FastifyInstance<RawServer, RawRequestDefaultExpression<RawServer>, RawReplyDefaultExpression<RawServer>, Logger, FastifyTypeProviderDefault>,153      req: RawRequestDefaultExpression<RawServer>154    ) => string,155    schemaErrorFormatter?: SchemaErrorFormatter,156    /**157     * listener to error events emitted by client connections158     */159    clientErrorHandler?: (error: ConnectionError, socket: Socket) => void,160    childLoggerFactory?: FastifyChildLoggerFactory161  }162 163  /**164   * @deprecated use {@link FastifySchemaValidationError}165   */166  export type ValidationResult = FastifySchemaValidationError167 168  /* Export additional types */169  export type {170    LightMyRequestChain, InjectOptions, LightMyRequestResponse, LightMyRequestCallback, // 'light-my-request'171    FastifyRequest, RequestGenericInterface, // './types/request'172    FastifyReply, // './types/reply'173    FastifyPluginCallback, FastifyPluginAsync, FastifyPluginOptions, FastifyPlugin, // './types/plugin'174    FastifyListenOptions, FastifyInstance, PrintRoutesOptions, // './types/instance'175    FastifyLoggerOptions, FastifyBaseLogger, FastifyLoggerInstance, FastifyLogFn, LogLevel, // './types/logger'176    FastifyRequestContext, FastifyContextConfig, FastifyReplyContext, // './types/context'177    RouteHandler, RouteHandlerMethod, RouteOptions, RouteShorthandMethod, RouteShorthandOptions, RouteShorthandOptionsWithHandler, RouteGenericInterface, // './types/route'178    FastifyRegister, FastifyRegisterOptions, RegisterOptions, // './types/register'179    FastifyBodyParser, FastifyContentTypeParser, AddContentTypeParser, hasContentTypeParser, getDefaultJsonParser, ProtoAction, ConstructorAction, // './types/content-type-parser'180    FastifyError, // '@fastify/error'181    FastifySchema, FastifySchemaCompiler, // './types/schema'182    HTTPMethods, RawServerBase, RawRequestDefaultExpression, RawReplyDefaultExpression, RawServerDefault, ContextConfigDefault, RequestBodyDefault, RequestQuerystringDefault, RequestParamsDefault, RequestHeadersDefault, // './types/utils'183    DoneFuncWithErrOrRes, HookHandlerDoneFunction, RequestPayload, onCloseAsyncHookHandler, onCloseHookHandler, onErrorAsyncHookHandler, onErrorHookHandler, onReadyAsyncHookHandler, onReadyHookHandler, onListenAsyncHookHandler, onListenHookHandler, onRegisterHookHandler, onRequestAsyncHookHandler, onRequestHookHandler, onResponseAsyncHookHandler, onResponseHookHandler, onRouteHookHandler, onSendAsyncHookHandler, onSendHookHandler, onTimeoutAsyncHookHandler, onTimeoutHookHandler, preHandlerAsyncHookHandler, preHandlerHookHandler, preParsingAsyncHookHandler, preParsingHookHandler, preSerializationAsyncHookHandler, preSerializationHookHandler, preValidationAsyncHookHandler, preValidationHookHandler, onRequestAbortHookHandler, onRequestAbortAsyncHookHandler, preCloseAsyncHookHandler, preCloseHookHandler, // './types/hooks'184    FastifyServerFactory, FastifyServerFactoryHandler, // './types/serverFactory'185    FastifyTypeProvider, FastifyTypeProviderDefault, SafePromiseLike, // './types/type-provider'186    FastifyErrorCodes // './types/errors'187  }188  // named export189  // import { plugin } from 'plugin'190  // const { plugin } = require('plugin')191  export const fastify: Fastify192  // default export193  // import plugin from 'plugin'194  export { fastify as default }195}196 197/**198 * Fastify factory function for the standard fastify http, https, or http2 server instance.199 *200 * The default function utilizes http201 *202 * @param opts Fastify server options203 * @returns Fastify server instance204 */205declare function fastify<206  Server extends http2.Http2SecureServer,207  Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,208  Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,209  Logger extends FastifyBaseLogger = FastifyBaseLogger,210  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault211> (opts: fastify.FastifyHttp2SecureOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger, TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>212 213declare function fastify<214  Server extends http2.Http2Server,215  Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,216  Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,217  Logger extends FastifyBaseLogger = FastifyBaseLogger,218  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault219> (opts: fastify.FastifyHttp2Options<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger, TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>220 221declare function fastify<222  Server extends https.Server,223  Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,224  Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,225  Logger extends FastifyBaseLogger = FastifyBaseLogger,226  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault227> (opts: fastify.FastifyHttpsOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger, TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>228 229declare function fastify<230  Server extends http.Server,231  Request extends RawRequestDefaultExpression<Server> = RawRequestDefaultExpression<Server>,232  Reply extends RawReplyDefaultExpression<Server> = RawReplyDefaultExpression<Server>,233  Logger extends FastifyBaseLogger = FastifyBaseLogger,234  TypeProvider extends FastifyTypeProvider = FastifyTypeProviderDefault235> (opts?: fastify.FastifyHttpOptions<Server, Logger>): FastifyInstance<Server, Request, Reply, Logger, TypeProvider> & SafePromiseLike<FastifyInstance<Server, Request, Reply, Logger, TypeProvider>>236 237// CJS export238// const fastify = require('fastify')239export = fastify240