import type { Maybe } from '@dereekb/util'; /** * One `match /` block in `firestore.rules`. Nested matches appear as `children`. * `collectionName` is the first bare-identifier segment of the match path (e.g. `pr`, * `gbe`, `sys`); it is `null` only when the match path is purely a `{path=**}` wildcard * with no following collection segment. */ export interface ParsedFirestoreMatchBlock { /** * Raw unmasked path segment from `match /` (e.g. `/pr/{profile}`, * `/{path=**}/gbe/{guestbookEntry}`, `/sys/hellosubscheckhqcompany`). */ readonly pathSegment: string; /** * First bare-identifier collection token in the path, or `null` when none. Used to pair * a model identity's `collectionName` (e.g. `gb`, `gbe`) against a rules block. */ readonly collectionName: Maybe; /** * True when the match path starts with `/{path=**}/` — a collection-group rule that * matches the collection at any depth. */ readonly isCollectionGroup: boolean; /** * Children nested inside this block's body, in source order. */ readonly children: readonly ParsedFirestoreMatchBlock[]; /** * Raw allow directive names declared on this block (e.g. `get`, `list`, `read`, `write`, * `create`, `update`, `delete`). Empty when the block declares no `allow` statements at * its own scope (children may still declare their own). */ readonly allowDirectives: readonly string[]; readonly sourceLine: number; readonly sourceColumn: number; } /** * Parses a `firestore.rules` source string and returns the tree of `match` blocks rooted * at the implicit `match /databases/{database}/documents` envelope. Each block's * `collectionName` is the first bare-identifier segment of its match path; nested * subcollection matches appear as `children`. * * @param source - The raw rules source text. * @returns The list of top-level match blocks in source order. * * @example * ```ts * const blocks = parseFirestoreRules(` * service cloud.firestore { * match /databases/{database}/documents { * match /gb/{guestbook} { * match /gbe/{guestbookEntry} { allow get: if false; } * } * } * } * `); * // blocks[0].collectionName === 'gb' * // blocks[0].children[0].collectionName === 'gbe' * ``` */ export declare function parseFirestoreRules(source: string): ParsedFirestoreMatchBlock[];