import { FastifyError, FastifyInstance, FastifyReply, FastifyRequest, RouteOptions } from 'fastify'; import { Static, TDate, TSchema } from '@sinclair/typebox'; import { RateLimitOptions } from '@fastify/rate-limit'; import { AppContext, UploadFile } from './types.js'; export type FileOptions = { maxFileSize?: number; accept?: string[]; maxFiles?: number; }; export declare function DateString(defaultValue?: string | Date): TDate; export type OnSendHook = (this: RouteBuilder, request: RequestWithState, reply: FastifyReply, payload: unknown) => void | Promise; export type PreValidationHook = (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => void | Promise | false; export type OnRequestHook = (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => void | Promise; export type PreSerializationHook = (this: RouteBuilder, request: RequestWithState, reply: FastifyReply, payload: unknown) => void | Promise; export type OnResponseHook = (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => void | Promise; export type OnErrorHook = (this: RouteBuilder, error: FastifyError, request: RequestWithState, reply: FastifyReply) => void | Promise; export type ErrorHandlerHook = (this: RouteBuilder, error: FastifyError, request: RequestWithState, reply: FastifyReply) => void | Promise; export type PreParsingHook = (this: RouteBuilder, request: RequestWithState, reply: FastifyReply, payload: unknown) => void | Promise; export type GuardFn, TState> = (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => boolean | ResponseUnion | Promise> | void | Promise; export type StatusSchemas = Record; export type ResponseUnion = { [K in keyof TResponses]: K extends number ? { status: K; data: Static; } : never; }[keyof TResponses]; type MergeStatus = TCurrent & { [P in Code]: Schema; }; export type HookType = 'preHandler' | 'onRequest' | 'preValidation' | 'preParsing' | 'preSerialization' | 'onSend' | 'onResponse' | 'onError'; export type PrehandlerFn = (this: RouteBuilder, req: RequestWithState, reply: FastifyReply) => Promise | unknown; export type HandlerFn = (this: RouteBuilder, req: RequestWithState, reply: FastifyReply) => Promise | unknown; export interface RouteConfig { method: string; url: string; modify?: (routeConfig: RouteOptions) => Promise | RouteOptions; schema: { params?: TSchema; body?: TSchema; querystring?: TSchema; headers?: TSchema; response?: Record; consumes?: string[]; }; errorHandler?: ErrorHandlerHook; fileOptions?: Record; rateLimit?: false | RateLimitOptions; guards: Array>; preHandlers: Array | null; preValidation: PreValidationHook | null; preParsing: PreParsingHook | null; preSerialization: PreSerializationHook | null; onRequest: OnRequestHook | null; onSend: OnSendHook | null; onResponse: OnResponseHook | null; onError: OnErrorHook | null; resolver?: (req: FastifyRequest, reply: FastifyReply) => Promise> | (TState | ResponseUnion); responseHeaders: Record; isMultipart?: boolean; responseType?: string; cacheControl?: string; handler?: HandlerFn; prefix?: string; controller?: string; tags?: string[]; summary?: string; version?: string; description?: string; security?: Array<{ [key: string]: string[]; }>; operationId?: string; } export declare function trimSlashes(input: string): string; declare module 'fastify' { interface FastifyRequest { routeData?: unknown; tempFiles?: Array; session?: { user?: Record; jwt?: Record; isAuthenticated?: boolean; destroy(callback?: (err?: Error) => void): void; regenerate(): Promise; }; } } export type RequestWithState = FastifyRequest<{ Params: Static; Body: Static; Querystring: Static; Headers: Static; }> & { routeData: TState; }; export declare class RouteBuilder { private appContext; private extraMetaStorage; private config; private static registeredSchemaIds; /** * Clear the schema registry (useful for testing or hot reload scenarios) */ static clearSchemaRegistry(): void; /** * Legacy withRef - simple inline schema support (for legacyAutoSchemaRegistration mode) * Schemas without $id are passed inline to Fastify */ private withRefLegacy; /** * Modern withRef - uses schema registry with proper $id handling */ private withRefModern; withRef(schema: T): TSchema; fastify: FastifyInstance; constructor(appContext: AppContext>); setRequestFormat(contentType: string): this; controller(controllerPath: string): this; acceptJson(): this; acceptMultipart(): this; acceptText(): this; setResponseFormat(contentType: string): this; json(): this; binary(): this; rawResponse(contentType: string): this; multipart(): this; consumes(consumes: string[]): this; text(): this; responseType(type: string): this; version(version: string): this; get(path?: string): this; post(path?: string): this; put(path?: string): this; delete(path?: string): this; patch(path?: string): this; options(path?: string): this; tags(tags: string[]): this; summary(summary: string): this; description(description: string): this; operationId(id: string): this; private generateOperationId; auth(type?: "bearer" | "basic" | "apiKey", guard?: GuardFn): this; /** * Validate that schema has $id (required for route schemas in modern mode) * This method is NOT called in legacy mode - legacy mode allows inline schemas without $id */ private requireSchemaId; params(schema: T): RouteBuilder; body(schema: T): RouteBuilder; query(schema: T): RouteBuilder; headers(schema: T): RouteBuilder; code(code: Code, schema: T): RouteBuilder, TState>; codes>(responses: TNewResponses): RouteBuilder; guard(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => boolean | ResponseUnion | Promise> | void | Promise): this; onRequest(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => void | Promise): this; preValidation(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => void | Promise | false): this; preParsing(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply, payload: unknown) => void | Promise): this; preSerialization(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply, payload: unknown) => void | Promise): this; preHandler(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => void | Promise): this; onSend(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply, payload: unknown) => void | Promise): this; onResponse(fn: (this: RouteBuilder, request: RequestWithState, reply: FastifyReply) => void | Promise): this; onError(fn: (this: RouteBuilder, error: FastifyError, request: RequestWithState, reply: FastifyReply) => void | Promise): this; setErrorHandler(fn: (this: RouteBuilder, error: FastifyError, request: RequestWithState, reply: FastifyReply) => void | Promise): this; resolve(fn: (req: RequestWithState, reply: FastifyReply) => TNewState | Promise): RouteBuilder; handler(fn: (req: RequestWithState, reply: FastifyReply) => Promise | string> | (ResponseUnion | string)): this; responseHeader(name: string, value: string, statusCode: Code): this; cacheControl(value: string): this; rateLimit(options: false | RateLimitOptions): this; fileOptions(options: FileOptions, key?: keyof Static): this; modify(fn: (routeConfig: RouteOptions & { state?: TState; }) => Promise | RouteOptions): this; build(): Promise; } export {}; //# sourceMappingURL=route.d.ts.map