/** * Router Pattern Matching * * Route pattern compilation and matching utilities. */ import type { RouteEntry } from "../types"; import type { EntryData } from "../server/context"; /** * Parsed segment info */ export interface ParsedSegment { type: "static" | "param" | "wildcard"; value: string; optional: boolean; constraint?: string[]; } /** * Parse a route pattern into segments * * Supports: * - Static: /blog, /about * - Params: /:slug, /:id * - Optional: /:locale?, /:page? * - Constrained: /:locale(en|gb), /:type(post|page) * - Optional + Constrained: /:locale(en|gb)? * - Wildcard: /* */ export declare function parsePattern(pattern: string): ParsedSegment[]; /** * Compiled pattern result containing regex, param metadata, and trailing slash info. */ export interface CompiledPattern { regex: RegExp; paramNames: string[]; optionalParams: Set; hasTrailingSlash: boolean; } /** * Get a compiled pattern from cache or compile and cache it. * Avoids O(routes) regex compilations per request in the fallback path. */ export declare function getCompiledPattern(pattern: string): CompiledPattern; /** * Return the current size of the compiled pattern cache. * Exposed for testing. */ export declare function getPatternCacheSize(): number; /** * Clear the compiled pattern cache. * Exposed for testing. */ export declare function clearPatternCache(): void; /** * Compile a route pattern to regex * * Supports: * - Static segments: /blog, /about * - Dynamic params: /:slug, /:id * - Optional params: /:locale?, /:page? * - Constrained params: /:locale(en|gb) * - Optional + constrained: /:locale(en|gb)? * - Wildcard: /* * * @example * compilePattern("/blog/:slug") // matches /blog/hello * compilePattern("/:locale?/blog") // matches /blog or /en/blog * compilePattern("/:locale(en|gb)/blog") // matches /en/blog or /gb/blog * compilePattern("/:locale(en|gb)?/blog") // matches /blog, /en/blog, or /gb/blog */ export declare function compilePattern(pattern: string): CompiledPattern; /** * Extract the static prefix from a route pattern. * Returns everything before the first param/wildcard. * * Called ONCE at registration time, not at match time. * * Examples: * - "/api" → "/api" * - "/site/:locale" → "/site" * - "/:locale" → "" * - "/admin/users/:id" → "/admin/users" * - "/api/*" → "/api" */ export declare function extractStaticPrefix(pattern: string): string; /** * Match a pathname against registered routes * * Note: Optional params that are absent in the path will have empty string value. * Use the pattern definition to determine if a param is optional. * * Trailing slash handling (priority order): * 1. Per-route `trailingSlash` config from route() * 2. Pattern-based detection (pattern ending with `/`) * * Modes: * - "never": Redirect to no trailing slash * - "always": Redirect to with trailing slash * - "ignore": Match both, no redirect */ /** * Result of a route match */ export interface RouteMatchResult { entry: RouteEntry; routeKey: string; params: Record; optionalParams: Set; redirectTo?: string; /** Ancestry shortCodes for layout pruning (from trie match) */ ancestry?: string[]; /** Route has pre-rendered data available (from trie) */ pr?: true; /** Passthrough: handler kept for live fallback on unknown params (from trie) */ pt?: true; /** Response type for non-RSC routes (json, text, image, any) */ responseType?: string; /** Negotiate variants: response-type routes sharing this path */ negotiateVariants?: Array<{ routeKey: string; responseType: string; }>; /** RSC-first: RSC route was defined before response-type variants */ rscFirst?: true; } /** * Result when a lazy entry needs evaluation before matching */ export interface LazyEvaluationNeeded { lazyEntry: RouteEntry; } /** * Type guard to check if result is a lazy evaluation needed response */ export declare function isLazyEvaluationNeeded(result: RouteMatchResult | LazyEvaluationNeeded | null): result is LazyEvaluationNeeded; interface MatchDebugStats { entriesChecked: number; entriesSkipped: number; routesChecked: number; } export declare function enableMatchDebug(enabled: boolean): void; export declare function getMatchDebugStats(): MatchDebugStats; export declare function findMatch(pathname: string, routesEntries: RouteEntry[]): RouteMatchResult | LazyEvaluationNeeded | null; /** * Traverse from entry to bottom to top, yielding each EntryData * e.g. {child -> parent -> grandparent ...} */ export declare function traverseBack(entry: EntryData): Generator; export {}; //# sourceMappingURL=pattern-matching.d.ts.map