import type { Maybe } from '@dereekb/util'; import { type PredicateBranch } from './predicate-evaluator'; import type { FoldedPathSegment } from './storagefile-path-fold'; /** * Marker comment that pairs a `storage.rules` match block with a TypeScript policy key * in `STORAGE_FILE_PURPOSE_UPLOAD_POLICIES`. The capture group is the policy key constant * name, e.g. `USER_AVATAR_PURPOSE`. */ export declare const MIRRORS_POLICY_KEY_MARKER_REGEX: RegExp; /** * One disjunct of an `allow write: if ...` predicate after helper-function expansion. * Always carries a numeric byte cap plus at least one MIME constraint (literal or regex). * * Structurally identical to the evaluator's {@link PredicateBranch}; the alias keeps the * existing public type name stable for downstream consumers. */ export type ParsedRuleBranch = PredicateBranch; /** * One leaf `match /` block in `storage.rules` that carries an `allow write|create|update` * predicate. `branches` carries the disjunction of (size, MIME) tuples extracted from the * predicate; `unsupported` is set when the parser cannot reduce the predicate to >=1 valid * branch. `matchPath` is the full accumulated path stack used to pair the block with a folded * upload-policy path. `mirrorsPolicyKey` is the legacy `// Mirrors ...` marker key when present * — purely informational now that pairing is by path, retained for backward compatibility. */ export interface ParsedStorageRulesBlock { readonly mirrorsPolicyKey?: Maybe; readonly matchPath: string; readonly branches: readonly ParsedRuleBranch[]; readonly sourceLine: number; readonly sourceColumn: number; readonly unsupported?: string; } /** * Converts a parsed leaf block's `matchPath` (e.g. `/uploads/u/{uid}/jr/{shortKey}`) into a * structural segment list for comparison against a folded upload-policy path. Empty segments * (leading/trailing/duplicate slashes) are dropped; `{var}` / `{var=**}` path variables become * wildcards; every other segment is a literal. * * @param matchPath - The accumulated match-path string. * @returns The structural segment list. */ export declare function rulesMatchPathToSegments(matchPath: string): FoldedPathSegment[]; /** * Parses a `storage.rules` source string and returns every leaf `match` block that carries an * `allow write|create|update` predicate, each with its full accumulated `matchPath`. Catch-all * deny blocks are skipped; the rest of the tree is walked normally. Pairing with TypeScript * upload policies is by path (see {@link rulesMatchPathToSegments}); the `// Mirrors ...` marker * is no longer required. * * @param source - The raw rules source text. * @returns Parsed leaf blocks in source order. */ export declare function parseStorageRules(source: string): ParsedStorageRulesBlock[];