feat: snapshot function - #3
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.