/** * The state model: a nested map plus the two operations over it, {@link merge} * and {@link diff} — together a JSON Merge Patch (RFC 7386). * * One structure serves every typed shape layered on top — what the keys *mean* * is a compile-time concern this module never knows. `merge` applies a delta, * `diff` produces one. The merge is * **idempotent** (applying a delta twice changes nothing) and * **last-writer-wins** — all an authoritative, in-order sender needs — so there * are no counters, timestamps, or clocks. * * Deliberately small and dependency-free (no third-party packages); it * transpiles to a few hundred bytes of ES5. */ /** A scalar leaf. Plain objects are branches; everything else is a value. */ export type Scalar = string | number | boolean; /** A value stored at a leaf — a scalar or an array of scalars (arrays overwrite). */ export type StateValue = Scalar | ReadonlyArray; /** A nested map of values: the structure every typed shape layers on top of. */ export type State = { readonly [key: string]: StateValue | State; }; /** * A change to apply to a {@link State} of type `T`. The same shape with every * key optional, except a `null` leaf **deletes** its key — the merge-patch * tombstone — and a branch recurses into a nested {@link Delta}. */ export type Delta = { readonly [K in keyof T]?: T[K] extends State ? Delta | null : T[K] | null; }; /** * Apply `delta` to `state`, returning a new state. Inputs are never mutated; * branches left unchanged are shared by reference. * * Branches merge recursively; a scalar/array leaf overwrites; a `null` leaf * removes the key. Idempotent: `merge(merge(s, d), d)` equals `merge(s, d)`. */ export declare function merge(state: T, delta: Delta): T; /** * Produce the minimal {@link Delta} that turns `a` into `b` — the inverse of * {@link merge}, so `merge(a, diff(a, b))` equals `b`. * * Keys dropped in `b` become `null` tombstones; unchanged paths are omitted. */ export declare function diff(a: T, b: T): Delta;