import { MatchResult, MatchedRouteRule, MatchedRouteRules, RouteRules, RuleHandlers } from "./types.mjs"; /** * Pre-merged registration data for one `(method, path)` pattern: the fully * resolved rule set of the pattern's subsumption chain (least → most specific, * `false` resets applied). At match time the most specific matched layer is the * complete merged result — no per-request layer merging. */ interface PreMergedRouteRules { /** The pattern this layer is registered at (params lookup key). */ route: string; rules: PreMergedRouteRuleEntry[]; } interface PreMergedRouteRuleEntry extends RouteRuleEntry { /** * Patterns whose layers contributed to this rule (chain order), when they * differ from `[route]`. Used to reproduce exact per-rule `params`: a rule's * params merge from exactly the matched layers that carried it. */ paramRoutes?: string[]; } /** * A single rule entry as stored in the matcher (one per rule name of a pattern). * This is the unit produced by exploding a normalized `RouteRules` object and the * shape carried in each rou3 layer's `.data` array (also emitted by the compiler). */ interface RouteRuleEntry { name: string; route: string; method?: string; options: unknown; handler?: MatchedRouteRule["handler"]; } /** * A matched rou3 layer: the entries registered for a pattern plus its params. * Data is either a plain entry array (merged per request) or a pre-merged layer * (`preMerge` mode — the most specific matched layer is the full result). */ interface RouteRuleLayer { data: RouteRuleEntry[] | PreMergedRouteRules; params?: Record; } /** * Dual-path merge + union. Resolve the raw (served) path and, * if provided, the canonical (decoded) path independently — so a rule's `false` * reset only affects the path it is configured for — then union: the canonical * pass can **add or override, never delete**, a rule the raw path resolved. On * overlap the canonical rule wins (it is applied last), regardless of whether * its pattern is more or less specific than the raw match. * * Pure: the caller supplies already-matched layers (least → most specific). */ declare function mergeMatchedRouteRules(rawLayers: RouteRuleLayer[] | undefined, canonicalLayers?: RouteRuleLayer[] | undefined): MatchedRouteRules; interface RouteRulesMatcherOptions { /** * Base URL prefix for all rule patterns (trailing slash trimmed). */ baseURL?: string; /** * Add or override rule handler constructors by name. * Registry defaults are `headers`, `redirect`, `basicAuth`; `cache` and * `proxy` are opt-in (register them from `h3-rules/cache` / `h3-rules/proxy`). * Setting a name to `undefined` makes that rule data-only. */ handlers?: RuleHandlers; /** * Pre-merge each pattern's subsumption chain at startup so per-request * resolution takes only the most specific matched layer instead of merging * all layers. Exact — but requires a **chain-clean** rule set: throws at * startup if two patterns partially overlap (e.g. `/a/*​/c` vs `/a/b/*`) or * use patterns that cannot be analyzed (regex params). * Composes with {@link memoizeRouteRulesMatcher}. */ preMerge?: boolean; } interface MatcherMemoizeOptions { /** * Maximum number of memoized `method + pathname` entries. On overflow the * oldest entry is evicted (FIFO). `0` (or negative) disables memoization. * @default 1024 */ max?: number; } type RouteRulesMatcher = (method: string, pathname: string) => MatchResult; /** A `findAllRoutes`-compatible lookup, as produced by `rou3/compiler` codegen. */ type FindRouteRules = (method: string, pathname: string) => RouteRuleLayer[]; /** * Create a route-rules matcher from a **normalized** rule set (see {@link normalizeRouteRules}). * Returns `(method, pathname) => { routeRules, routeRuleMiddleware }`. */ declare function createRouteRulesMatcher(rules: Record, opts?: RouteRulesMatcherOptions): RouteRulesMatcher; /** * Create a matcher from a `findAllRoutes`-compatible lookup — the integration * point for compiled matchers (`h3-rules/compiler` output). Runtime and compiled * matchers share this exact code path, so they produce identical results. * * Memoization is intentionally **not** wired in here: keeping the reference out * of this function lets an un-memoized compiled bundle tree-shake * {@link memoizeRouteRulesMatcher} away. Opt in by composing it explicitly — * `memoizeRouteRulesMatcher(createMatcherFromFind(findRouteRules))`. The same * composition wraps the matcher from `createRouteRulesMatcher`. */ declare function createMatcherFromFind(findRouteRules: FindRouteRules): RouteRulesMatcher; /** * Memoize a matcher per `method + pathname`. Exact: for a given path the merged * result (params included) is fully deterministic, so repeat requests skip both * rule lookups, `canonicalPath`, the merge, and middleware construction — a hot * path becomes a single map lookup. * * Memoized results are **shared across requests**: treat the returned * `routeRules` map and middleware array as immutable (rule `options` objects are * shared with the registered rule data either way). Entries are capped * (default 1024) with FIFO eviction, so unbounded dynamic paths cannot grow the * cache indefinitely — an evicted path is simply re-resolved on its next hit. */ declare function memoizeRouteRulesMatcher(matcher: RouteRulesMatcher, opts?: MatcherMemoizeOptions): RouteRulesMatcher; export { FindRouteRules, MatcherMemoizeOptions, RouteRuleEntry, RouteRuleLayer, RouteRulesMatcher, RouteRulesMatcherOptions, createMatcherFromFind, createRouteRulesMatcher, memoizeRouteRulesMatcher, mergeMatchedRouteRules };