Skip to content

feat: snapshot function - #3

Merged
miguelramos merged 10 commits into
mainfrom
feat/rework
Apr 17, 2026
Merged

feat: snapshot function#3
miguelramos merged 10 commits into
mainfrom
feat/rework

Conversation

@miguelramos

Copy link
Copy Markdown
Member

No description provided.

Miguel Ramos added 10 commits April 17, 2026 09:22
Document every exported type, interface, and function across all modules
with JSDoc annotations including parameter descriptions, return types,
usage examples, and cross-references via @link tags.

Covers: diff.ts, patch.ts, utils.ts, types.ts, errors.ts, lcs.ts, rfc6902.ts
…extraction

Add a new public API to extract a sparse object containing only the values
that changed between two documents. Returns a ChangesResult with:
- updated: sparse nested object with added/replaced/moved values
- removed: array of RFC 6901 paths that were deleted
- diff: the full DiffResult for low-level access

Useful for HTTP PATCH payloads, form dirty tracking, audit logs, and
optimistic UI updates where only the delta is needed.
25 tests covering: no-change scenarios, object diffs (add/remove/replace),
nested structure preservation, root replacement, identity-based array
moves, options forwarding (ignore, maxDepth), changesFromDiff standalone
usage, and removal-only edge cases.
Add changes section to Usage with examples for sparse extraction,
nested structure preservation, removal-only cases, options forwarding,
and changesFromDiff standalone usage. Add ChangesResult to Types section
and update intro/features to reference the new API.
- Fix parentOf() in patch.ts to re-escape segments via joinPath,
  preventing corrupted arrays when keys contain `/` or `~`.
- Rewrite toRFC6902() to decompose delta moves into RFC 6902
  remove+add pairs with correct sequential ordering (removes desc,
  adds asc), fixing invalid patches for multi-move arrays.
- Add ARRAY_TOO_LARGE guard in LCS (25M entry threshold) to prevent
  OOM on large positional array diffs.
- Document moved+changed design choice on OpMove (cannot emit nested
  ops without breaking unpatch reverse reconstruction).
OpMove now carries an optional nestedDiff: DiffResult when the item
changed during a move. Paths are relative to the item root (e.g.
/role, not /items/2/role), sidestepping the index-ambiguity that
prevents emitting them as top-level ops.

patch/unpatch remain unchanged — they use value/oldValue snapshots
for reconstruction. nestedDiff is purely informational for consumers
who need field-level detail on moved items.
changes() now takes a DiffResult and returns JsonValue | null:
- Sparse object with only changed fields
- Removed keys appear as null
- Root replacements return the new value directly
- null when nothing changed

Removes changesFromDiff(), ChangesResult type, and the
changes(before, after) convenience overload.
Reserve the changes name for a future feature.
changeset add → changeset create
@miguelramos miguelramos self-assigned this Apr 17, 2026
@miguelramos
miguelramos merged commit b13ed7e into main Apr 17, 2026
8 checks passed
@miguelramos
miguelramos deleted the feat/rework branch April 17, 2026 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ TYPE: Feature New feature or capability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant