/** * Rewrite pipeline: ordered when → vars → to. * * Each provider declares one or more rewrite rules. For an input URL the * pipeline strips `?query` and `#fragment`, finds the first rule whose * `when` regex matches, computes `vars` (templates over captures), and * renders the `to` template against captures + vars merged. The merged * context flows out so downstream header templates can interpolate the * same variables. * * Per design issue #113 §4 (vocabulary) and §5.2 (fragment/query * stripping must precede a greedy `(?.+)` capture). */ export interface RewriteRule { readonly when: string; readonly vars?: Record; readonly to: string; } export type RewriteOutcome = { readonly matched: true; readonly rewrittenUrl: string; readonly context: Record; } | { readonly matched: false; }; /** * Thrown when a rule's `when` field is not a compilable regex. */ export declare class InvalidRewriteRuleError extends Error { constructor(pattern: string, cause: unknown); } /** * Thrown when a `vars` key collides with a named capture in `when`. * Adopter must rename one — vars cannot shadow captures (the design's * intent is captures + vars in a single namespace). */ export declare class VarCaptureCollisionError extends Error { constructor(name: string); } /** * Apply an ordered list of rewrite rules to a URL. * * @returns `{ matched: true, rewrittenUrl, context }` for the first matching * rule, or `{ matched: false }` if no rule claims the URL. * @throws {InvalidRewriteRuleError} if a `when` field does not compile * @throws {VarCaptureCollisionError} if a vars name shadows a capture name * @throws {TemplateMissingVarError} from a template referencing an unknown name * @throws {TemplateSyntaxError} from a malformed template expression * @throws {UnknownTransformError} from a template calling an unknown transform */ export declare function rewriteUrl(url: string, rules: readonly RewriteRule[]): RewriteOutcome; //# sourceMappingURL=rewrite.d.ts.map