Skip to content

Add diff-based revert OT generation for arbitrary JSON documents - #5

Merged
edocevol merged 2 commits into
masterfrom
copilot/add-version-compare-recovery
Apr 17, 2026
Merged

edocevol merged 2 commits into
masterfrom
copilot/add-version-compare-recovery

Conversation

Copilot AI commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

This change adds version-compare restore support by generating revert JSON OT from any two JSON documents. Given current and previous, the library can now emit an operation that transforms current back to previous, including full-document restores.

  • What this enables

    • Introduces a Diff API on JSONOperationTransformer to generate OT from from -> to
    • Supports revert/rollback flows without requiring pre-recorded inverse operations
    • Handles arbitrary root document types, not just object subtrees
  • Diff generation

    • Diffs objects recursively by key
    • Emits na for numeric deltas where possible
    • Falls back to subtree replacement for incompatible shape changes and array length changes
    • Produces valid OT for both nested fields and root-level document replacement
  • Root-level OT support

    • Extends apply logic to handle p: []
    • Allows whole-document replace/delete/insert semantics when the revert target changes document type
    • Updates operation serialization/validation so root-scoped operations round-trip correctly
  • Docs

    • Adds Diff usage to README.md and README.zh-CN.md
    • Documents revert/version-restore usage and subtree replacement fallback behavior
ot := jsonot.NewJSONOperationTransformer()

current, _ := jsonot.UnmarshalValue([]byte(`{"version":2,"items":[1,2,3]}`))
previous, _ := jsonot.UnmarshalValue([]byte(`{"version":1,"items":[1,3]}`))

revertOp := ot.Diff(context.Background(), current, previous)
restored := ot.Apply(context.Background(), current, revertOp.MustGet())

Copilot AI and others added 2 commits April 16, 2026 16:25
Agent-Logs-Url: https://github.com/edocevol/jsonot/sessions/5d57ab3b-def6-437d-8cef-6028e294edae

Co-authored-by: edocevol <9777120+edocevol@users.noreply.github.com>
Agent-Logs-Url: https://github.com/edocevol/jsonot/sessions/5d57ab3b-def6-437d-8cef-6028e294edae

Co-authored-by: edocevol <9777120+edocevol@users.noreply.github.com>
@edocevol
edocevol marked this pull request as ready for review April 17, 2026 02:31
@edocevol
edocevol merged commit a3eac74 into master Apr 17, 2026
1 check passed
@edocevol
edocevol deleted the copilot/add-version-compare-recovery branch April 17, 2026 04:48
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