Skip to content

Add JSON Delta API (v5.0.0-alpha.0)#379

Merged
ltwlf merged 4 commits intomasterfrom
feature/json-delta-v5
Mar 8, 2026
Merged

Add JSON Delta API (v5.0.0-alpha.0)#379
ltwlf merged 4 commits intomasterfrom
feature/json-delta-v5

Conversation

@ltwlf
Copy link
Owner

@ltwlf ltwlf commented Mar 7, 2026

Summary

  • Add first-class JSON Delta support as an adapter layer over existing v4 internals
  • New public APIs: diffDelta, applyDelta, revertDelta, invertDelta, toDelta, fromDelta, validateDelta
  • New files: src/jsonDelta.ts, src/deltaPath.ts, conformance fixtures, CLAUDE.md
  • 143 new tests (245 total), all passing
  • README rewritten to position JSON Delta as primary API
  • All v4 APIs preserved unchanged — no breaking changes to existing code
  • Version bumped to 5.0.0-alpha.0

Key design decisions

  • Adapter pattern: new code converts between v4 internal IChange[] tree and JSON Delta format without modifying src/jsonDiff.ts
  • Canonical typed filter literals: diffDelta produces [?(@.id==42)] (number), not [?(@.id=='42')] (string)
  • fromDelta returns IAtomicChange[]: 1:1 mapping with delta operations for transparency
  • Sequential apply: applyDelta processes operations one-at-a-time with dedicated root handling
  • REMOVE+ADD merge: type changes produce single replace operations in delta output

Test plan

  • 68 deltaPath tests (parsing, building, conversion, round-trips)
  • 75 jsonDelta tests (validate, diffDelta, toDelta, fromDelta, applyDelta, revertDelta, invertDelta)
  • 6 conformance fixture tests (Level 1 + Level 2 for both fixtures)
  • 4 integration round-trip tests
  • All 102 existing tests pass unchanged
  • Build produces CJS + ESM + .d.ts with all new exports
  • Lint clean

Implement first-class JSON Delta support as an adapter layer over the
existing v4 internals. New APIs produce, consume, apply, and revert
spec-conformant JSON Delta documents while preserving all v4 APIs unchanged.

New public functions: diffDelta, applyDelta, revertDelta, invertDelta,
toDelta, fromDelta, validateDelta.

New files: src/jsonDelta.ts, src/deltaPath.ts, CLAUDE.md, conformance
fixtures, and comprehensive tests (143 new tests, all 245 pass).

README rewritten to position JSON Delta as the primary API with
practical examples for audit logging, undo/redo, and state sync.
Copilot AI review requested due to automatic review settings March 7, 2026 22:58
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

❌ Patch coverage is 98.62745% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/jsonDelta.ts 98.17% 5 Missing ⚠️
src/deltaPath.ts 99.14% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Add 19 new tests covering error paths, edge cases, and validation
branches in deltaPath.ts and jsonDelta.ts. Add istanbul ignore
comments to unreachable defensive branches (exhaustive switch
defaults, function-key paths that diff() never produces).

Coverage: deltaPath.ts 100%, jsonDelta.ts 97.8%, overall 96.96%.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a first-class JSON Delta (v1) API surface as an adapter over the existing v4 jsonDiff internals, plus path parsing/canonicalization helpers and extensive conformance + integration tests.

Changes:

  • Added src/jsonDelta.ts implementing diffDelta, applyDelta, revertDelta, invertDelta, toDelta, fromDelta, validateDelta.
  • Added src/deltaPath.ts for JSON Delta path parsing/building and v4 atomic-path conversion utilities.
  • Reworked README to position JSON Delta as the primary API; added fixtures and a large new test suite.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/jsonDelta.ts New JSON Delta API adapter layer over v4 diff/apply/atomize/unatomize.
src/deltaPath.ts JSON Delta path parsing + canonicalization + v4 path interop helpers.
src/index.ts Exports JSON Delta module from the package entrypoint.
tests/jsonDelta.test.ts New test coverage for validate/diff/apply/revert/invert/bridge operations + fixtures.
tests/deltaPath.test.ts Unit tests for delta path parsing/building and conversion helpers.
tests/__fixtures__/json-delta/basic-replace.json Conformance fixture for basic replace semantics.
tests/__fixtures__/json-delta/keyed-array-update.json Conformance fixture for keyed-array update/add/remove semantics.
README.md Documentation rewrite focusing on JSON Delta API and migration/bridge guidance.
package.json Version bump to 5.0.0-alpha.0.
CLAUDE.md Added contributor/AI-assistance architecture notes and conventions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ltwlf added 2 commits March 8, 2026 00:26
- Fix applyRootOp Array↔Object root replace bug (only mutate plain obj→obj)
- Reject NaN/Infinity in formatFilterLiteral
- Fix )] in quoted strings breaking filter parsing (new findFilterClose helper)
- Change applyDelta/revertDelta return type from T to any (root ops change type)
- Reject non-JSON numeric formats in parseFilterLiteral (hex, octal, etc.)
- Fix CLAUDE.md spec path reference to GitHub URL
- Add prototype pollution warning to README Data Sync example
- Add 8 new tests covering all fixes (272 total)
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 8, 2026

@ltwlf ltwlf merged commit 99c9af7 into master Mar 8, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants