/** * Byte-surgical YAML value updater. * * The motivating problem: editing one value in an adopter's config file with the * naive `doc.setIn(...); doc.toString()` round-trip reflows the ENTIRE document — * collapsing flow sequences, re-wrapping long scalars, shifting comment alignment, * normalising quote styles. That destroys hand-authored formatting the user never * asked us to touch. * * This module instead changes the **minimum bytes possible**: * * - **Replace** an existing scalar: locate its source byte range via the parsed * node and splice the new serialized token in place. Every other byte is * identical. * - **Insert** a new key: render ONLY the new nested fragment, indent it to the * target map's child column, and splice it in after the map's last item. The * rest of the document is never re-rendered. * * `verifyConfinedYamlEdit` is the double-checker: it re-parses before/after and * asserts the edit landed, no other leaf value drifted, and no comment was lost. * `updateYamlIn` calls it internally as a defensive post-condition. * * No filesystem access — these are pure string transforms. */ /** A path into a YAML document: map keys (strings) and/or sequence indices. */ export type YamlPath = (string | number)[]; /** A scalar value this module knows how to serialize as a single YAML token. */ export type YamlScalarValue = string | number | boolean | null; /** * Upsert a single scalar at `path` in `text`, changing the minimum bytes possible. * * - If `path` already resolves to a scalar, its source token is replaced in place * (byte-identical output except the one value, including surrounding comments, * alignment whitespace, flow-collection padding, and sibling formatting). * - If `path` does not yet exist, a new nested fragment is rendered and spliced * into the deepest existing ancestor map at the correct child indentation — * without re-rendering (and thus reflowing) the rest of the document. * * The input's EOL style (`\n` vs `\r\n`) is detected and preserved. * * @param text - The full YAML source document. * @param path - Key/index path to the scalar to set. * @param value - The scalar value to write (string, number, boolean, or null). * @returns The updated document text. * @throws If `text` is not valid YAML, if `path` is empty, or if `path` resolves * to a collection that would be clobbered by a scalar (or an intermediate * ancestor is a scalar that cannot hold a child). * * @example * updateYamlIn('model: haiku # note\n', ['model'], 'opus') * // => 'model: opus # note\n' (alignment + comment preserved) */ export declare function updateYamlIn(text: string, path: YamlPath, value: YamlScalarValue): string; /** * Re-parse `before` and `after` and assert the edit was correct and confined: * * 1. **Correctness** — every entry in `changedPaths` resolves in `after`. * 2. **Confinement** — every other leaf path present in `before` has a deep-equal * value in `after` (no collateral value edits). * 3. **Comment preservation** — the multiset of all comment strings is unchanged. * * Safe to call as an internal assertion from {@link updateYamlIn}. * * @param before - The original document text. * @param after - The edited document text. * @param changedPaths - The paths the caller intended to change. * @throws A descriptive `Error` naming the offending path or lost comment on any * violation. */ export declare function verifyConfinedYamlEdit(before: string, after: string, changedPaths: YamlPath[]): void; //# sourceMappingURL=surgical-yaml.d.ts.map