json-patch-to-crdt 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -31,10 +31,7 @@ Node.js `>=18`.
31
31
  ```ts
32
32
  import { applyPatch, createState, toJson, type JsonPatchOp } from "json-patch-to-crdt";
33
33
 
34
- const state = createState(
35
- { todos: ["write docs"], done: false },
36
- { actor: "client-A" },
37
- );
34
+ const state = createState({ todos: ["write docs"], done: false }, { actor: "client-A" });
38
35
 
39
36
  const patch: JsonPatchOp[] = [
40
37
  { op: "add", path: "/todos/-", value: "ship package" },
@@ -88,8 +85,29 @@ console.log(delta);
88
85
  // { op: "add", path: "/profile/active", value: true },
89
86
  // { op: "add", path: "/tags/1", value: "b" }
90
87
  // ]
88
+
89
+ const reordered = diffJsonPatch(
90
+ { tags: ["a", "b", "c"] },
91
+ { tags: ["b", "a", "c"] },
92
+ { arrayStrategy: "lcs", emitMoves: true },
93
+ );
94
+
95
+ console.log(reordered);
96
+ // [{ op: "move", from: "/tags/0", path: "/tags/1" }]
91
97
  ```
92
98
 
99
+ For array-heavy snapshots, `diffJsonPatch` and `crdtToJsonPatch` support:
100
+
101
+ - `arrayStrategy: "lcs"`: deterministic index-level array edits using the classic LCS matrix. This is the default.
102
+ - `arrayStrategy: "lcs-linear"`: deterministic index-level array edits using a lower-memory linear-space LCS traversal.
103
+ - `arrayStrategy: "atomic"`: replace the whole array with a single patch operation.
104
+
105
+ `lcsMaxCells` only applies to `arrayStrategy: "lcs"`. If the classic LCS matrix would exceed the configured cap, the diff falls back to an atomic array `replace`. Use `lcs-linear` when you want index-level patches for larger arrays without allocating the full matrix, but note that it still has `O(n * m)` time complexity and does not automatically fall back for very large unmatched windows.
106
+
107
+ `diffJsonPatch` keeps the existing `add`/`remove`/`replace` output by default. Set
108
+ `emitMoves` and/or `emitCopies` to opt into deterministic RFC 6902 `move`/`copy`
109
+ rewrites.
110
+
93
111
  ## Serialize / Restore State
94
112
 
95
113
  ```ts