/** * Text-preserving JSON edits: change the value of a key, or add a key that is * missing, and keep every other byte of the file — key order, spacing, a * 20-digit integer, an array written on one line. faf uses it for the one * JSON file it shares with its owner, a registry `server.json`, where faf owns * only the identity keys (`faf server-card`, `faf cards --target registry`). * * A patch is a plain object. For each key: a plain-object value is a folder to * go into (the file's value must be an object too); any other value replaces * the value's text when it differs, or is added when the key is missing. * Nothing is ever deleted, and `undefined` is skipped. When the file cannot be * edited that way — not valid JSON, not an object, a key it repeats on the way, * a value faf would have to replace to go into it, or an object or array in the * file where faf sets a plain value — a JsonEditError says why in one line and * nothing is changed. * * Two more edits keep the same promise: {@link upsertJsonRows} updates or * appends faf's own rows in an array (the `faf cards` catalog), and * {@link removeJsonKey} takes out one key faf added (its render hash). */ /** Why a JSON text cannot be edited in place (one line). */ export declare class JsonEditError extends Error { constructor(message: string); } /** Where to add a missing key: after the first of these keys the object has * (else after its last key). Keyed by the dotted path of the object ('' is the root). */ export type InsertAfter = Record>; /** * Apply `patch` to the JSON `text`, changing only the value text of the keys * it names and adding the keys it has that the text lacks (see the file * header). Returns the new text and whether it changed. Throws a * JsonEditError, having changed nothing, when the text cannot be edited that * way. `after` says where a missing key goes (default: after the object's last key). */ export declare function editJsonText(text: string, patch: Record, after?: InsertAfter): { text: string; changed: boolean; }; /** * Update or add rows in the array at the root key `key`, changing nothing * else: a row whose `id` value is exactly a row's in the file is updated in * place — only the values of its `update` keys change (or are added) — and any * other row is appended after the file's last item, laid out like the items * around it (the array, or the key, is added when missing). Every item faf * does not update stays byte for byte. Never matched by anything but `id`. * Throws a JsonEditError, having changed nothing, when the text cannot be * edited that way: not a JSON object, `key` not an array or there more than * once, a row's id there more than once, or a value faf sets that is an object * or array in the file. */ export declare function upsertJsonRows(text: string, key: string, rows: readonly Record[], opts: { id: string; update: readonly string[]; }): { text: string; changed: boolean; }; /** * The value at `path` in the JSON object `text` (each step a key of an * object): `count` 1 with its parsed `value`, 0 when a step is missing or not * an object, more than 1 when a key on the way is repeated. Throws a * JsonEditError when `text` is not a JSON object. */ export declare function locateJsonKey(text: string, path: readonly string[]): { count: number; value?: unknown; }; /** * `text` with the key at `path` taken out — the reverse of {@link editJsonText} * adding it (see {@link removal}); every other byte stays. With * `dropEmptyParent`, when that key is its object's only key, the object's own * key is taken out instead. Returns null when the key is not there exactly * once; throws a JsonEditError when `text` is not a JSON object. */ export declare function removeJsonKey(text: string, path: readonly string[], opts?: { dropEmptyParent?: boolean; }): string | null;