import { ObjectSchema } from '@sigiljs/seal'; import { InferSchema } from '@sigiljs/seal/types'; import { ModifierConstructor } from './modifier'; import { DebugOptions } from '../sigil/types'; import { Internal } from '../types'; import { default as RouteRequests } from './route-requests'; type Constructor = (readonly ModifierConstructor[]) | undefined; /** * Configuration options for the Route. * * @template Modifier a tuple of modifier constructors to apply. */ export interface RouteOptions { /** Array of modifier constructors to apply to this route. */ modifiers?: Modifier; /** Tags to associate with this route (for documentation). */ tags?: string[]; /** Custom logger instance. */ logger?: Internal.AbstractLogger; /** Debugging options for validation and logging. */ debug?: Partial; } type MetaDescriptor> = Partial>>>; /** * Main router class for registering HTTP routes and metadata. * Extends RouteRequests to offer schema-based validation and * automatic type derivation for request handlers. * * @template Modifiers tuple of modifier constructors applied to this route. * @template BodySchema shape of the request body schema, if applied. * @template HeadersSchema shape of the request headers schema, if applied. * @template QuerySchema shape of the request query schema, if applied. */ export default class Route[] | undefined = undefined, BodySchema extends Record | undefined = undefined, HeadersSchema extends Record = Record, QuerySchema extends Record = Record> extends RouteRequests { /** * Creates a new Route instance with optional configuration. * Instantiates the underlying Pathfinder router and applies modifiers. * * @param options configuration options for the router. */ constructor(options?: RouteOptions); /** * Registers a validation schema for the request body of the next handler. * After calling this, GET routes will be disabled until a new router clone is created. * * @param schema object schema defining the expected request body. * @param meta optional metadata (e.g., name, description) for documentation. * @returns temporary cloned router with the body schema applied (without `get` method if appropriate). */ body(schema: Schema | [Schema, MetaDescriptor | undefined], meta?: MetaDescriptor): Omit>, HeadersSchema, QuerySchema>, "get">; /** * Registers a validation schema for the request headers of the next handler. * * @param schema object schema defining the expected headers. * @returns temporary cloned router with the headers schema applied. */ headers(schema: Schema | [Schema, MetaDescriptor | undefined]): (BodySchema extends Record ? Omit; }, QuerySchema>, "get"> : Route; }, QuerySchema>); /** * Registers a validation schema for the query parameters of the next handler. * * @param schema object schema defining the expected query parameters. * @returns temporary cloned router with the query schema applied. */ query(schema: Schema | [Schema, MetaDescriptor | undefined]): (BodySchema extends Record ? Omit; }>, "get"> : Route; }>); /** * Registers a validation schema for the path parameters of the next handler. * * @param schema object schema defining the expected path parameters. * @returns temporary cloned router with the params schema applied. */ params(schema: Schema | [Schema, MetaDescriptor | undefined]): this; /** * Internal method that clones the current router instance and applies a new schema. * Used to isolate schema settings per handler registration. * * @param key schema type key ("body", "headers", "query", or "params"). * @param schema validation schema object. * @param meta optional metadata to attach to the schema. * @returns cloned Route instance with the updated schema. * @private */ private $cloneWithSchema; /** * Internal helper to attach metadata (name, description, example, etc.) * to a given schema. * * @param schema ObjectSchema to which metadata will be applied. * @param meta partial metadata properties to assign. * @returns schema instance with metadata applied. * @private */ private $applyMetadata; } export {};