/** * Shared, dependency-free core for round-trip AST validation. * * This module is intentionally self-contained — it imports no parser or * deparser — so it can be lifted verbatim into an upstream package (e.g. * `@pgsql/round-trip`) and shared between: * * - pgsql-parser's test fixtures (`cleanTree` / `expectParseDeparse`), which * parse → deparse → re-parse and assert the normalized ASTs are equal, and * - downstream mutation-aware validators (this package's * round-trip check), which compare a *mutated* AST against the AST obtained * by re-parsing the deparsed output. * * The upstream `cleanTree` is expressed here as a preset over the generic * `normalizeTree` engine; the downstream fortified normalizer layers extra * volatile keys, lazy-datum filtering, and body-sentinel handling on top of * the same engine (see round-trip.ts). */ export interface NormalizeTreeOptions { /** Object keys dropped entirely (volatile / non-semantic fields). */ volatileKeys?: ReadonlySet; /** Sort object keys so comparison is insensitive to key order. Default false. */ sortKeys?: boolean; /** Array items for which this returns true are removed before recursing. */ dropArrayItem?: (item: unknown) => boolean; /** * Per-key transform hooks keyed by object-property name. The hook receives * the value at that key plus a `recurse` callback (which re-enters * `normalizeTree` with the same options) and returns the replacement value. */ keyHandlers?: Record any) => any>; } /** * Deep-clone an AST while dropping volatile keys, optionally sorting keys, * filtering array items, and applying per-key transform hooks. Primitives are * returned as-is; Dates are cloned (parity with the original upstream * `transform` helper). */ export declare function normalizeTree(node: any, options?: NormalizeTreeOptions): any; /** * Return the JSON path of the first structural difference between two trees, * or null if they are deeply equal. Useful for actionable mismatch messages. */ export declare function firstDifference(a: any, b: any, path?: string): string | null; /** Position/length fields stripped by the upstream `cleanTree`. */ export declare const CLEAN_TREE_VOLATILE_KEYS: ReadonlySet; /** * Trim the function/DO body string carried by a `DefElem` with defname "as". * Mirrors the in-place trimming in pgsql-parser's `cleanTree` so the body * text (whose surrounding whitespace legitimately shifts on deparse) does not * cause spurious AST mismatches. Mutates the passed DefElem in place. */ export declare function trimDefElemBody(defElem: any): void; /** * Upstream-compatible normalization: strips `stmt_len` / `stmt_location` / * `location` and trims `DefElem` "as" body strings. Equivalent to * pgsql-parser's deparser `cleanTree`, provided here so upstream can adopt the * shared core without behavior change. */ export declare function cleanTree(tree: any): any;