/** * Search parameter schema types and runtime utilities. * * Provides a lightweight schema system for typed query parameters. * When a route defines a `search` schema, ctx.searchParams becomes * a typed object with parsed values instead of raw URLSearchParams. */ /** Supported scalar types for search params (append ? for optional). */ export type SearchSchemaValue = "string" | "number" | "boolean" | "string?" | "number?" | "boolean?"; /** A search schema maps param names to their type descriptors. */ export type SearchSchema = Record; /** Strip trailing `?` from a schema value to get the base type. */ type BaseType = T extends `${infer B}?` ? B : T; /** Map a base type string to its TypeScript type. */ type ResolveBaseType = T extends "string" ? string : T extends "number" ? number : T extends "boolean" ? boolean : never; /** Keys whose schema value does NOT end with `?`. */ type RequiredKeys = { [K in keyof T]: T[K] extends `${string}?` ? never : K; }[keyof T]; /** Keys whose schema value ends with `?`. */ type OptionalKeys = { [K in keyof T]: T[K] extends `${string}?` ? K : never; }[keyof T]; /** Flatten an intersection type into a single object type. */ type Simplify = { [K in keyof T]: T[K]; }; /** * Resolve a SearchSchema to its typed object. * * @example * type S = { q: "string"; page: "number?"; sort: "string?" }; * type R = ResolveSearchSchema; * // { q: string; page?: number; sort?: string } */ export type ResolveSearchSchema = Simplify<{ [K in RequiredKeys & string]: ResolveBaseType>; } & { [K in OptionalKeys & string]?: ResolveBaseType>; }>; /** Resolve the global route map from RegisteredRoutes or GeneratedRouteMap. */ type GlobalRouteMap = keyof RSCRouter.RegisteredRoutes extends never ? keyof RSCRouter.GeneratedRouteMap extends never ? Record : RSCRouter.GeneratedRouteMap : RSCRouter.RegisteredRoutes; /** * Extract the resolved search params type for a named route. * Looks up the search schema from the route map and resolves it. * * @example * ```typescript * // Given: path("/search", handler, { name: "search", search: { q: "string", page: "number?" } }) * type Params = RouteSearchParams<"search">; * // { q: string; page?: number } * ``` */ export type RouteSearchParams = [TRouteMap] extends [never] ? ExtractAndResolveSearch : ExtractAndResolveSearch; type ExtractAndResolveSearch = TName extends keyof TRouteMap ? TRouteMap[TName] extends { readonly search: infer S extends SearchSchema; } ? ResolveSearchSchema : {} : {}; /** * Extract the route params type for a named route. * Looks up the path pattern from the route map and extracts params. * * @example * ```typescript * // Given: path("/blog/:slug", handler, { name: "blogPost" }) * type Params = RouteParams<"blogPost">; * // { slug: string } * ``` */ export type RouteParams = [TRouteMap] extends [never] ? ExtractRouteParamsFromMap : ExtractRouteParamsFromMap; type ExtractRouteParamsFromMap = TName extends keyof TRouteMap ? TRouteMap[TName] extends string ? ExtractParamsFromPattern : TRouteMap[TName] extends { readonly path: infer P extends string; } ? ExtractParamsFromPattern

: {} : {}; /** Minimal inline param extraction (avoids importing from types.ts to prevent circular deps). */ type ExtractParamsFromPattern = T extends `${string}:${infer Param}/${infer Rest}` ? Param extends `${infer Name}?` ? { [K in Name]?: string; } & ExtractParamsFromPattern<`/${Rest}`> : Param extends `${infer Name}(${string})` ? { [K in Name]: string; } & ExtractParamsFromPattern<`/${Rest}`> : { [K in Param]: string; } & ExtractParamsFromPattern<`/${Rest}`> : T extends `${string}:${infer Param}` ? Param extends `${infer Name}?` ? { [K in Name]?: string; } : Param extends `${infer Name}(${string})` ? { [K in Name]: string; } : { [K in Param]: string; } : {}; /** * Parse URLSearchParams into a typed object using the given schema. * * - `"string"` / `"string?"` - kept as-is * - `"number"` / `"number?"` - coerced via `Number()`; NaN treated as missing * - `"boolean"` / `"boolean?"` - `"true"` / `"1"` -> true, `"false"` / `"0"` / `""` -> false * * Missing required params are set to their zero value (empty string / 0 / false). */ export declare function parseSearchParams(searchParams: URLSearchParams, schema: T): ResolveSearchSchema; /** * Serialize a typed search params object to a query string (without leading `?`). * Skips `undefined` and `null` values. */ export declare function serializeSearchParams(params: Record): string; export {}; //# sourceMappingURL=search-params.d.ts.map