json-patch-to-crdt 0.1.1 → 0.1.3

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.
@@ -1,22 +1,5 @@
1
- import { $ as ObjNode, A as ApplyPatchAsActorResult, B as ElemId, C as toJson, D as ActorId, E as validateJsonPatch, F as CompilePatchOptions, G as JsonPatchToCrdtOptions, H as IntentOp, I as CrdtState, J as LwwReg, K as JsonPrimitive, L as DiffOptions, M as ApplyPatchOptions, N as ApplyResult, O as ApplyError, P as Clock, Q as ObjEntry, R as Doc, S as forkState, T as tryApplyPatchInPlace, U as JsonPatch, V as ForkStateOptions, W as JsonPatchOp, X as MergeStateOptions, Y as MergeDocOptions, Z as Node, _ as PatchError, a as tryMergeState, at as SerializedClock, b as applyPatchInPlace, c as serializeDoc, ct as SerializedRgaElem, d as compileJsonPatchToIntent, dt as TryApplyPatchResult, et as PatchErrorReason, f as diffJsonPatch, ft as TryMergeDocResult, g as stringifyJsonPointer, h as parseJsonPointer, ht as VersionVector, i as tryMergeDoc, it as RgaSeq, j as ApplyPatchInPlaceOptions, k as ApplyPatchAsActorOptions, l as serializeState, lt as SerializedState, m as jsonEquals, mt as ValidatePatchResult, n as mergeDoc, nt as ROOT_KEY, o as deserializeDoc, ot as SerializedDoc, p as getAtJson, pt as TryMergeStateResult, q as JsonValue, r as mergeState, rt as RgaElem, s as deserializeState, st as SerializedNode, t as MergeError, tt as PatchSemantics, u as PatchCompileError, ut as TryApplyPatchInPlaceResult, v as applyPatch, w as tryApplyPatch, x as createState, y as applyPatchAsActor, z as Dot } from "./merge-DQ_KDtnE.mjs";
1
+ import { $ as Doc, A as applyPatchAsActor, At as TryMergeDocResult, B as ApplyPatchAsActorOptions, C as cloneClock, Ct as SerializedNode, D as JsonValueValidationError, Dt as TombstoneCompactionStats, E as observeDot, Et as TombstoneCompactionOptions, F as tryApplyPatch, G as Clock, H as ApplyPatchInPlaceOptions, I as tryApplyPatchInPlace, J as CompilePatchOptions, K as CompactDocTombstonesResult, L as validateJsonPatch, M as createState, Mt as ValidatePatchResult, N as forkState, Nt as VersionVector, O as PatchError, Ot as TryApplyPatchInPlaceResult, P as toJson, Q as DiffOptions, R as ActorId, S as ClockValidationError, St as SerializedDoc, T as nextDotForActor, Tt as SerializedState, U as ApplyPatchOptions, V as ApplyPatchAsActorResult, W as ApplyResult, X as CreateStateOptions, Y as CrdtState, Z as DeserializeErrorReason, _ as diffJsonPatch, _t as PatchSemantics, a as MergeError, at as JsonPatchOp, b as parseJsonPointer, bt as RgaSeq, c as tryMergeDoc, ct as JsonValidationMode, d as deserializeDoc, dt as MergeDocOptions, et as Dot, f as deserializeState, ft as MergeStateOptions, g as compileJsonPatchToIntent, gt as PatchErrorReason, h as PatchCompileError, ht as ObjNode, i as compactStateTombstones, it as JsonPatch, j as applyPatchInPlace, jt as TryMergeStateResult, k as applyPatch, kt as TryApplyPatchResult, l as tryMergeState, lt as JsonValue, m as serializeState, mt as ObjEntry, n as TraversalDepthError, nt as ForkStateOptions, o as mergeDoc, ot as JsonPatchToCrdtOptions, p as serializeDoc, pt as Node, q as CompactStateTombstonesResult, r as compactDocTombstones, rt as IntentOp, s as mergeState, st as JsonPrimitive, t as MAX_TRAVERSAL_DEPTH, tt as ElemId, u as DeserializeError, ut as LwwReg, v as getAtJson, vt as ROOT_KEY, w as createClock, wt as SerializedRgaElem, x as stringifyJsonPointer, xt as SerializedClock, y as jsonEquals, yt as RgaElem, z as ApplyError } from "./depth-IvWvLAkt.mjs";
2
2
 
3
- //#region src/clock.d.ts
4
- /**
5
- * Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
6
- * @param actor - Unique identifier for this peer.
7
- * @param start - Initial counter value (defaults to 0).
8
- */
9
- declare function createClock(actor: ActorId, start?: number): Clock;
10
- /** Create an independent copy of a clock at the same counter position. */
11
- declare function cloneClock(clock: Clock): Clock;
12
- /**
13
- * Generate the next per-actor dot from a mutable version vector.
14
- * Useful when a server needs to mint dots for many actors.
15
- */
16
- declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
17
- /** Record an observed dot in a version vector. */
18
- declare function observeDot(vv: VersionVector, dot: Dot): void;
19
- //#endregion
20
3
  //#region src/doc.d.ts
21
4
  /**
22
5
  * Create a CRDT document from a JSON value, using fresh dots for each node.
@@ -41,23 +24,29 @@ declare function cloneDoc(doc: Doc): Doc;
41
24
  * @param newDot - A function that generates a unique `Dot` per mutation.
42
25
  * @param evalTestAgainst - Whether `test` ops are evaluated against `"head"` or `"base"`.
43
26
  * @param bumpCounterAbove - Optional hook that can fast-forward the underlying counter before inserts.
27
+ * @param options - Optional behavior toggles.
28
+ * @param options.strictParents - When `true`, reject array inserts whose base parent path is missing.
44
29
  * @returns `{ ok: true }` on success, or `{ ok: false, code: 409, message }` on conflict.
45
30
  */
46
- declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
31
+ declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, options?: {
32
+ strictParents?: boolean;
33
+ }): ApplyResult;
47
34
  /**
48
35
  * Convenience wrapper: compile a JSON Patch and apply it to a CRDT document.
49
36
  * Overloads:
50
- * - positional: `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?)`
51
- * - object: `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics? })`
37
+ * - positional:
38
+ * `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, strictParents?)`
39
+ * - object:
40
+ * `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics?, strictParents? })`
52
41
  */
53
42
  declare function jsonPatchToCrdt(options: JsonPatchToCrdtOptions): ApplyResult;
54
- declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
43
+ declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
55
44
  /**
56
45
  * Safe wrapper around `jsonPatchToCrdt`.
57
46
  * This function never throws and always returns an `ApplyResult`.
58
47
  */
59
48
  declare function jsonPatchToCrdtSafe(options: JsonPatchToCrdtOptions): ApplyResult;
60
- declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
49
+ declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
61
50
  /** Alias for codebases that prefer `try*` naming for non-throwing APIs. */
62
51
  declare const tryJsonPatchToCrdt: typeof jsonPatchToCrdtSafe;
63
52
  /**
@@ -75,7 +64,7 @@ declare function crdtToJsonPatch(base: Doc, head: Doc, options?: DiffOptions): J
75
64
  declare function crdtToFullReplace(doc: Doc): JsonPatchOp[];
76
65
  //#endregion
77
66
  //#region src/materialize.d.ts
78
- /** Recursively convert a CRDT node graph into a plain JSON value. */
67
+ /** Convert a CRDT node graph into a plain JSON value using an explicit stack. */
79
68
  declare function materialize(node: Node): JsonValue;
80
69
  //#endregion
81
70
  //#region src/dot.d.ts
@@ -91,13 +80,25 @@ declare function newReg(value: JsonValue, dot: Dot): LwwReg;
91
80
  declare function lwwSet(reg: LwwReg, value: JsonValue, dot: Dot): void;
92
81
  declare function objSet(obj: ObjNode, key: string, node: Node, dot: Dot): void;
93
82
  declare function objRemove(obj: ObjNode, key: string, dot: Dot): void;
83
+ /**
84
+ * Prune object tombstones that satisfy a caller-provided stability predicate.
85
+ * Returns the number of removed tombstone records.
86
+ */
87
+ declare function objCompactTombstones(obj: ObjNode, isStable: (dot: Dot) => boolean): number;
94
88
  //#endregion
95
89
  //#region src/rga.d.ts
96
90
  declare const HEAD: ElemId;
97
91
  declare function rgaLinearizeIds(seq: RgaSeq): ElemId[];
98
92
  declare function rgaInsertAfter(seq: RgaSeq, prev: ElemId, id: ElemId, insDot: Dot, value: Node): void;
99
93
  declare function rgaDelete(seq: RgaSeq, id: ElemId): void;
94
+ /**
95
+ * Prune tombstoned elements that are causally stable and have no live descendants
96
+ * depending on them for sequence traversal.
97
+ *
98
+ * Returns the number of removed elements.
99
+ */
100
+ declare function rgaCompactTombstones(seq: RgaSeq, isStable: (dot: Dot) => boolean): number;
100
101
  declare function rgaIdAtIndex(seq: RgaSeq, index: number): ElemId | undefined;
101
102
  declare function rgaPrevForInsertAtIndex(seq: RgaSeq, index: number): ElemId;
102
103
  //#endregion
103
- export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, type CompilePatchOptions, CrdtState, DiffOptions, type Doc, type Dot, type ElemId, ForkStateOptions, HEAD, type IntentOp, JsonPatch, JsonPatchOp, type JsonPatchToCrdtOptions, JsonPrimitive, JsonValue, type LwwReg, type MergeDocOptions, MergeError, MergeStateOptions, type Node, type ObjEntry, type ObjNode, PatchCompileError, PatchError, PatchErrorReason, PatchSemantics, ROOT_KEY, type RgaElem, type RgaSeq, type SerializedClock, type SerializedDoc, type SerializedNode, type SerializedRgaElem, SerializedState, TryApplyPatchInPlaceResult, TryApplyPatchResult, type TryMergeDocResult, TryMergeStateResult, ValidatePatchResult, type VersionVector, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compareDot, compileJsonPatchToIntent, crdtToFullReplace, crdtToJsonPatch, createClock, createState, deserializeDoc, deserializeState, diffJsonPatch, docFromJson, docFromJsonWithDot, dotToElemId, forkState, getAtJson, jsonEquals, jsonPatchToCrdt, jsonPatchToCrdtSafe, lwwSet, materialize, mergeDoc, mergeState, newObj, newReg, newSeq, nextDotForActor, objRemove, objSet, observeDot, parseJsonPointer, rgaDelete, rgaIdAtIndex, rgaInsertAfter, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchInPlace, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };
104
+ export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, ClockValidationError, type CompactDocTombstonesResult, type CompactStateTombstonesResult, type CompilePatchOptions, CrdtState, CreateStateOptions, DeserializeError, DeserializeErrorReason, DiffOptions, type Doc, type Dot, type ElemId, ForkStateOptions, HEAD, type IntentOp, JsonPatch, JsonPatchOp, type JsonPatchToCrdtOptions, JsonPrimitive, JsonValidationMode, JsonValue, JsonValueValidationError, type LwwReg, MAX_TRAVERSAL_DEPTH, type MergeDocOptions, MergeError, MergeStateOptions, type Node, type ObjEntry, type ObjNode, PatchCompileError, PatchError, PatchErrorReason, PatchSemantics, ROOT_KEY, type RgaElem, type RgaSeq, type SerializedClock, type SerializedDoc, type SerializedNode, type SerializedRgaElem, SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, TryApplyPatchInPlaceResult, TryApplyPatchResult, type TryMergeDocResult, TryMergeStateResult, ValidatePatchResult, type VersionVector, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compactDocTombstones, compactStateTombstones, compareDot, compileJsonPatchToIntent, crdtToFullReplace, crdtToJsonPatch, createClock, createState, deserializeDoc, deserializeState, diffJsonPatch, docFromJson, docFromJsonWithDot, dotToElemId, forkState, getAtJson, jsonEquals, jsonPatchToCrdt, jsonPatchToCrdtSafe, lwwSet, materialize, mergeDoc, mergeState, newObj, newReg, newSeq, nextDotForActor, objCompactTombstones, objRemove, objSet, observeDot, parseJsonPointer, rgaCompactTombstones, rgaDelete, rgaIdAtIndex, rgaInsertAfter, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchInPlace, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };
@@ -1,22 +1,5 @@
1
- import { $ as ObjNode, A as ApplyPatchAsActorResult, B as ElemId, C as toJson, D as ActorId, E as validateJsonPatch, F as CompilePatchOptions, G as JsonPatchToCrdtOptions, H as IntentOp, I as CrdtState, J as LwwReg, K as JsonPrimitive, L as DiffOptions, M as ApplyPatchOptions, N as ApplyResult, O as ApplyError, P as Clock, Q as ObjEntry, R as Doc, S as forkState, T as tryApplyPatchInPlace, U as JsonPatch, V as ForkStateOptions, W as JsonPatchOp, X as MergeStateOptions, Y as MergeDocOptions, Z as Node, _ as PatchError, a as tryMergeState, at as SerializedClock, b as applyPatchInPlace, c as serializeDoc, ct as SerializedRgaElem, d as compileJsonPatchToIntent, dt as TryApplyPatchResult, et as PatchErrorReason, f as diffJsonPatch, ft as TryMergeDocResult, g as stringifyJsonPointer, h as parseJsonPointer, ht as VersionVector, i as tryMergeDoc, it as RgaSeq, j as ApplyPatchInPlaceOptions, k as ApplyPatchAsActorOptions, l as serializeState, lt as SerializedState, m as jsonEquals, mt as ValidatePatchResult, n as mergeDoc, nt as ROOT_KEY, o as deserializeDoc, ot as SerializedDoc, p as getAtJson, pt as TryMergeStateResult, q as JsonValue, r as mergeState, rt as RgaElem, s as deserializeState, st as SerializedNode, t as MergeError, tt as PatchSemantics, u as PatchCompileError, ut as TryApplyPatchInPlaceResult, v as applyPatch, w as tryApplyPatch, x as createState, y as applyPatchAsActor, z as Dot } from "./merge-B8nmGV-o.js";
1
+ import { $ as Doc, A as applyPatchAsActor, At as TryMergeDocResult, B as ApplyPatchAsActorOptions, C as cloneClock, Ct as SerializedNode, D as JsonValueValidationError, Dt as TombstoneCompactionStats, E as observeDot, Et as TombstoneCompactionOptions, F as tryApplyPatch, G as Clock, H as ApplyPatchInPlaceOptions, I as tryApplyPatchInPlace, J as CompilePatchOptions, K as CompactDocTombstonesResult, L as validateJsonPatch, M as createState, Mt as ValidatePatchResult, N as forkState, Nt as VersionVector, O as PatchError, Ot as TryApplyPatchInPlaceResult, P as toJson, Q as DiffOptions, R as ActorId, S as ClockValidationError, St as SerializedDoc, T as nextDotForActor, Tt as SerializedState, U as ApplyPatchOptions, V as ApplyPatchAsActorResult, W as ApplyResult, X as CreateStateOptions, Y as CrdtState, Z as DeserializeErrorReason, _ as diffJsonPatch, _t as PatchSemantics, a as MergeError, at as JsonPatchOp, b as parseJsonPointer, bt as RgaSeq, c as tryMergeDoc, ct as JsonValidationMode, d as deserializeDoc, dt as MergeDocOptions, et as Dot, f as deserializeState, ft as MergeStateOptions, g as compileJsonPatchToIntent, gt as PatchErrorReason, h as PatchCompileError, ht as ObjNode, i as compactStateTombstones, it as JsonPatch, j as applyPatchInPlace, jt as TryMergeStateResult, k as applyPatch, kt as TryApplyPatchResult, l as tryMergeState, lt as JsonValue, m as serializeState, mt as ObjEntry, n as TraversalDepthError, nt as ForkStateOptions, o as mergeDoc, ot as JsonPatchToCrdtOptions, p as serializeDoc, pt as Node, q as CompactStateTombstonesResult, r as compactDocTombstones, rt as IntentOp, s as mergeState, st as JsonPrimitive, t as MAX_TRAVERSAL_DEPTH, tt as ElemId, u as DeserializeError, ut as LwwReg, v as getAtJson, vt as ROOT_KEY, w as createClock, wt as SerializedRgaElem, x as stringifyJsonPointer, xt as SerializedClock, y as jsonEquals, yt as RgaElem, z as ApplyError } from "./depth-Dl_yOAKU.js";
2
2
 
3
- //#region src/clock.d.ts
4
- /**
5
- * Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
6
- * @param actor - Unique identifier for this peer.
7
- * @param start - Initial counter value (defaults to 0).
8
- */
9
- declare function createClock(actor: ActorId, start?: number): Clock;
10
- /** Create an independent copy of a clock at the same counter position. */
11
- declare function cloneClock(clock: Clock): Clock;
12
- /**
13
- * Generate the next per-actor dot from a mutable version vector.
14
- * Useful when a server needs to mint dots for many actors.
15
- */
16
- declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
17
- /** Record an observed dot in a version vector. */
18
- declare function observeDot(vv: VersionVector, dot: Dot): void;
19
- //#endregion
20
3
  //#region src/doc.d.ts
21
4
  /**
22
5
  * Create a CRDT document from a JSON value, using fresh dots for each node.
@@ -41,23 +24,29 @@ declare function cloneDoc(doc: Doc): Doc;
41
24
  * @param newDot - A function that generates a unique `Dot` per mutation.
42
25
  * @param evalTestAgainst - Whether `test` ops are evaluated against `"head"` or `"base"`.
43
26
  * @param bumpCounterAbove - Optional hook that can fast-forward the underlying counter before inserts.
27
+ * @param options - Optional behavior toggles.
28
+ * @param options.strictParents - When `true`, reject array inserts whose base parent path is missing.
44
29
  * @returns `{ ok: true }` on success, or `{ ok: false, code: 409, message }` on conflict.
45
30
  */
46
- declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
31
+ declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, options?: {
32
+ strictParents?: boolean;
33
+ }): ApplyResult;
47
34
  /**
48
35
  * Convenience wrapper: compile a JSON Patch and apply it to a CRDT document.
49
36
  * Overloads:
50
- * - positional: `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?)`
51
- * - object: `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics? })`
37
+ * - positional:
38
+ * `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, strictParents?)`
39
+ * - object:
40
+ * `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics?, strictParents? })`
52
41
  */
53
42
  declare function jsonPatchToCrdt(options: JsonPatchToCrdtOptions): ApplyResult;
54
- declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
43
+ declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
55
44
  /**
56
45
  * Safe wrapper around `jsonPatchToCrdt`.
57
46
  * This function never throws and always returns an `ApplyResult`.
58
47
  */
59
48
  declare function jsonPatchToCrdtSafe(options: JsonPatchToCrdtOptions): ApplyResult;
60
- declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
49
+ declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
61
50
  /** Alias for codebases that prefer `try*` naming for non-throwing APIs. */
62
51
  declare const tryJsonPatchToCrdt: typeof jsonPatchToCrdtSafe;
63
52
  /**
@@ -75,7 +64,7 @@ declare function crdtToJsonPatch(base: Doc, head: Doc, options?: DiffOptions): J
75
64
  declare function crdtToFullReplace(doc: Doc): JsonPatchOp[];
76
65
  //#endregion
77
66
  //#region src/materialize.d.ts
78
- /** Recursively convert a CRDT node graph into a plain JSON value. */
67
+ /** Convert a CRDT node graph into a plain JSON value using an explicit stack. */
79
68
  declare function materialize(node: Node): JsonValue;
80
69
  //#endregion
81
70
  //#region src/dot.d.ts
@@ -91,13 +80,25 @@ declare function newReg(value: JsonValue, dot: Dot): LwwReg;
91
80
  declare function lwwSet(reg: LwwReg, value: JsonValue, dot: Dot): void;
92
81
  declare function objSet(obj: ObjNode, key: string, node: Node, dot: Dot): void;
93
82
  declare function objRemove(obj: ObjNode, key: string, dot: Dot): void;
83
+ /**
84
+ * Prune object tombstones that satisfy a caller-provided stability predicate.
85
+ * Returns the number of removed tombstone records.
86
+ */
87
+ declare function objCompactTombstones(obj: ObjNode, isStable: (dot: Dot) => boolean): number;
94
88
  //#endregion
95
89
  //#region src/rga.d.ts
96
90
  declare const HEAD: ElemId;
97
91
  declare function rgaLinearizeIds(seq: RgaSeq): ElemId[];
98
92
  declare function rgaInsertAfter(seq: RgaSeq, prev: ElemId, id: ElemId, insDot: Dot, value: Node): void;
99
93
  declare function rgaDelete(seq: RgaSeq, id: ElemId): void;
94
+ /**
95
+ * Prune tombstoned elements that are causally stable and have no live descendants
96
+ * depending on them for sequence traversal.
97
+ *
98
+ * Returns the number of removed elements.
99
+ */
100
+ declare function rgaCompactTombstones(seq: RgaSeq, isStable: (dot: Dot) => boolean): number;
100
101
  declare function rgaIdAtIndex(seq: RgaSeq, index: number): ElemId | undefined;
101
102
  declare function rgaPrevForInsertAtIndex(seq: RgaSeq, index: number): ElemId;
102
103
  //#endregion
103
- export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, type CompilePatchOptions, CrdtState, DiffOptions, type Doc, type Dot, type ElemId, ForkStateOptions, HEAD, type IntentOp, JsonPatch, JsonPatchOp, type JsonPatchToCrdtOptions, JsonPrimitive, JsonValue, type LwwReg, type MergeDocOptions, MergeError, MergeStateOptions, type Node, type ObjEntry, type ObjNode, PatchCompileError, PatchError, PatchErrorReason, PatchSemantics, ROOT_KEY, type RgaElem, type RgaSeq, type SerializedClock, type SerializedDoc, type SerializedNode, type SerializedRgaElem, SerializedState, TryApplyPatchInPlaceResult, TryApplyPatchResult, type TryMergeDocResult, TryMergeStateResult, ValidatePatchResult, type VersionVector, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compareDot, compileJsonPatchToIntent, crdtToFullReplace, crdtToJsonPatch, createClock, createState, deserializeDoc, deserializeState, diffJsonPatch, docFromJson, docFromJsonWithDot, dotToElemId, forkState, getAtJson, jsonEquals, jsonPatchToCrdt, jsonPatchToCrdtSafe, lwwSet, materialize, mergeDoc, mergeState, newObj, newReg, newSeq, nextDotForActor, objRemove, objSet, observeDot, parseJsonPointer, rgaDelete, rgaIdAtIndex, rgaInsertAfter, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchInPlace, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };
104
+ export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, ClockValidationError, type CompactDocTombstonesResult, type CompactStateTombstonesResult, type CompilePatchOptions, CrdtState, CreateStateOptions, DeserializeError, DeserializeErrorReason, DiffOptions, type Doc, type Dot, type ElemId, ForkStateOptions, HEAD, type IntentOp, JsonPatch, JsonPatchOp, type JsonPatchToCrdtOptions, JsonPrimitive, JsonValidationMode, JsonValue, JsonValueValidationError, type LwwReg, MAX_TRAVERSAL_DEPTH, type MergeDocOptions, MergeError, MergeStateOptions, type Node, type ObjEntry, type ObjNode, PatchCompileError, PatchError, PatchErrorReason, PatchSemantics, ROOT_KEY, type RgaElem, type RgaSeq, type SerializedClock, type SerializedDoc, type SerializedNode, type SerializedRgaElem, SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, TryApplyPatchInPlaceResult, TryApplyPatchResult, type TryMergeDocResult, TryMergeStateResult, ValidatePatchResult, type VersionVector, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compactDocTombstones, compactStateTombstones, compareDot, compileJsonPatchToIntent, crdtToFullReplace, crdtToJsonPatch, createClock, createState, deserializeDoc, deserializeState, diffJsonPatch, docFromJson, docFromJsonWithDot, dotToElemId, forkState, getAtJson, jsonEquals, jsonPatchToCrdt, jsonPatchToCrdtSafe, lwwSet, materialize, mergeDoc, mergeState, newObj, newReg, newSeq, nextDotForActor, objCompactTombstones, objRemove, objSet, observeDot, parseJsonPointer, rgaCompactTombstones, rgaDelete, rgaIdAtIndex, rgaInsertAfter, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchInPlace, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };
package/dist/internals.js CHANGED
@@ -1,60 +1,69 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_merge = require('./merge-BAfuC6bf.js');
2
+ const require_compact = require('./compact-DoM9CJNR.js');
3
3
 
4
- exports.HEAD = require_merge.HEAD;
5
- exports.MergeError = require_merge.MergeError;
6
- exports.PatchCompileError = require_merge.PatchCompileError;
7
- exports.PatchError = require_merge.PatchError;
8
- exports.ROOT_KEY = require_merge.ROOT_KEY;
9
- exports.applyIntentsToCrdt = require_merge.applyIntentsToCrdt;
10
- exports.applyPatch = require_merge.applyPatch;
11
- exports.applyPatchAsActor = require_merge.applyPatchAsActor;
12
- exports.applyPatchInPlace = require_merge.applyPatchInPlace;
13
- exports.cloneClock = require_merge.cloneClock;
14
- exports.cloneDoc = require_merge.cloneDoc;
15
- exports.compareDot = require_merge.compareDot;
16
- exports.compileJsonPatchToIntent = require_merge.compileJsonPatchToIntent;
17
- exports.crdtToFullReplace = require_merge.crdtToFullReplace;
18
- exports.crdtToJsonPatch = require_merge.crdtToJsonPatch;
19
- exports.createClock = require_merge.createClock;
20
- exports.createState = require_merge.createState;
21
- exports.deserializeDoc = require_merge.deserializeDoc;
22
- exports.deserializeState = require_merge.deserializeState;
23
- exports.diffJsonPatch = require_merge.diffJsonPatch;
24
- exports.docFromJson = require_merge.docFromJson;
25
- exports.docFromJsonWithDot = require_merge.docFromJsonWithDot;
26
- exports.dotToElemId = require_merge.dotToElemId;
27
- exports.forkState = require_merge.forkState;
28
- exports.getAtJson = require_merge.getAtJson;
29
- exports.jsonEquals = require_merge.jsonEquals;
30
- exports.jsonPatchToCrdt = require_merge.jsonPatchToCrdt;
31
- exports.jsonPatchToCrdtSafe = require_merge.jsonPatchToCrdtSafe;
32
- exports.lwwSet = require_merge.lwwSet;
33
- exports.materialize = require_merge.materialize;
34
- exports.mergeDoc = require_merge.mergeDoc;
35
- exports.mergeState = require_merge.mergeState;
36
- exports.newObj = require_merge.newObj;
37
- exports.newReg = require_merge.newReg;
38
- exports.newSeq = require_merge.newSeq;
39
- exports.nextDotForActor = require_merge.nextDotForActor;
40
- exports.objRemove = require_merge.objRemove;
41
- exports.objSet = require_merge.objSet;
42
- exports.observeDot = require_merge.observeDot;
43
- exports.parseJsonPointer = require_merge.parseJsonPointer;
44
- exports.rgaDelete = require_merge.rgaDelete;
45
- exports.rgaIdAtIndex = require_merge.rgaIdAtIndex;
46
- exports.rgaInsertAfter = require_merge.rgaInsertAfter;
47
- exports.rgaLinearizeIds = require_merge.rgaLinearizeIds;
48
- exports.rgaPrevForInsertAtIndex = require_merge.rgaPrevForInsertAtIndex;
49
- exports.serializeDoc = require_merge.serializeDoc;
50
- exports.serializeState = require_merge.serializeState;
51
- exports.stringifyJsonPointer = require_merge.stringifyJsonPointer;
52
- exports.toJson = require_merge.toJson;
53
- exports.tryApplyPatch = require_merge.tryApplyPatch;
54
- exports.tryApplyPatchInPlace = require_merge.tryApplyPatchInPlace;
55
- exports.tryJsonPatchToCrdt = require_merge.tryJsonPatchToCrdt;
56
- exports.tryMergeDoc = require_merge.tryMergeDoc;
57
- exports.tryMergeState = require_merge.tryMergeState;
58
- exports.validateJsonPatch = require_merge.validateJsonPatch;
59
- exports.vvHasDot = require_merge.vvHasDot;
60
- exports.vvMerge = require_merge.vvMerge;
4
+ exports.ClockValidationError = require_compact.ClockValidationError;
5
+ exports.DeserializeError = require_compact.DeserializeError;
6
+ exports.HEAD = require_compact.HEAD;
7
+ exports.JsonValueValidationError = require_compact.JsonValueValidationError;
8
+ exports.MAX_TRAVERSAL_DEPTH = require_compact.MAX_TRAVERSAL_DEPTH;
9
+ exports.MergeError = require_compact.MergeError;
10
+ exports.PatchCompileError = require_compact.PatchCompileError;
11
+ exports.PatchError = require_compact.PatchError;
12
+ exports.ROOT_KEY = require_compact.ROOT_KEY;
13
+ exports.TraversalDepthError = require_compact.TraversalDepthError;
14
+ exports.applyIntentsToCrdt = require_compact.applyIntentsToCrdt;
15
+ exports.applyPatch = require_compact.applyPatch;
16
+ exports.applyPatchAsActor = require_compact.applyPatchAsActor;
17
+ exports.applyPatchInPlace = require_compact.applyPatchInPlace;
18
+ exports.cloneClock = require_compact.cloneClock;
19
+ exports.cloneDoc = require_compact.cloneDoc;
20
+ exports.compactDocTombstones = require_compact.compactDocTombstones;
21
+ exports.compactStateTombstones = require_compact.compactStateTombstones;
22
+ exports.compareDot = require_compact.compareDot;
23
+ exports.compileJsonPatchToIntent = require_compact.compileJsonPatchToIntent;
24
+ exports.crdtToFullReplace = require_compact.crdtToFullReplace;
25
+ exports.crdtToJsonPatch = require_compact.crdtToJsonPatch;
26
+ exports.createClock = require_compact.createClock;
27
+ exports.createState = require_compact.createState;
28
+ exports.deserializeDoc = require_compact.deserializeDoc;
29
+ exports.deserializeState = require_compact.deserializeState;
30
+ exports.diffJsonPatch = require_compact.diffJsonPatch;
31
+ exports.docFromJson = require_compact.docFromJson;
32
+ exports.docFromJsonWithDot = require_compact.docFromJsonWithDot;
33
+ exports.dotToElemId = require_compact.dotToElemId;
34
+ exports.forkState = require_compact.forkState;
35
+ exports.getAtJson = require_compact.getAtJson;
36
+ exports.jsonEquals = require_compact.jsonEquals;
37
+ exports.jsonPatchToCrdt = require_compact.jsonPatchToCrdt;
38
+ exports.jsonPatchToCrdtSafe = require_compact.jsonPatchToCrdtSafe;
39
+ exports.lwwSet = require_compact.lwwSet;
40
+ exports.materialize = require_compact.materialize;
41
+ exports.mergeDoc = require_compact.mergeDoc;
42
+ exports.mergeState = require_compact.mergeState;
43
+ exports.newObj = require_compact.newObj;
44
+ exports.newReg = require_compact.newReg;
45
+ exports.newSeq = require_compact.newSeq;
46
+ exports.nextDotForActor = require_compact.nextDotForActor;
47
+ exports.objCompactTombstones = require_compact.objCompactTombstones;
48
+ exports.objRemove = require_compact.objRemove;
49
+ exports.objSet = require_compact.objSet;
50
+ exports.observeDot = require_compact.observeDot;
51
+ exports.parseJsonPointer = require_compact.parseJsonPointer;
52
+ exports.rgaCompactTombstones = require_compact.rgaCompactTombstones;
53
+ exports.rgaDelete = require_compact.rgaDelete;
54
+ exports.rgaIdAtIndex = require_compact.rgaIdAtIndex;
55
+ exports.rgaInsertAfter = require_compact.rgaInsertAfter;
56
+ exports.rgaLinearizeIds = require_compact.rgaLinearizeIds;
57
+ exports.rgaPrevForInsertAtIndex = require_compact.rgaPrevForInsertAtIndex;
58
+ exports.serializeDoc = require_compact.serializeDoc;
59
+ exports.serializeState = require_compact.serializeState;
60
+ exports.stringifyJsonPointer = require_compact.stringifyJsonPointer;
61
+ exports.toJson = require_compact.toJson;
62
+ exports.tryApplyPatch = require_compact.tryApplyPatch;
63
+ exports.tryApplyPatchInPlace = require_compact.tryApplyPatchInPlace;
64
+ exports.tryJsonPatchToCrdt = require_compact.tryJsonPatchToCrdt;
65
+ exports.tryMergeDoc = require_compact.tryMergeDoc;
66
+ exports.tryMergeState = require_compact.tryMergeState;
67
+ exports.validateJsonPatch = require_compact.validateJsonPatch;
68
+ exports.vvHasDot = require_compact.vvHasDot;
69
+ exports.vvMerge = require_compact.vvMerge;
@@ -1,3 +1,3 @@
1
- import { $ as vvMerge, A as compileJsonPatchToIntent, B as newSeq, C as crdtToJsonPatch, D as jsonPatchToCrdtSafe, E as jsonPatchToCrdt, F as stringifyJsonPointer, G as rgaDelete, H as objSet, I as ROOT_KEY, J as rgaLinearizeIds, K as rgaIdAtIndex, L as lwwSet, M as getAtJson, N as jsonEquals, O as tryJsonPatchToCrdt, P as parseJsonPointer, Q as vvHasDot, R as newObj, S as crdtToFullReplace, T as docFromJsonWithDot, U as materialize, V as objRemove, W as HEAD, X as compareDot, Y as rgaPrevForInsertAtIndex, Z as dotToElemId, _ as tryApplyPatch, a as tryMergeState, b as applyIntentsToCrdt, c as serializeDoc, d as applyPatch, et as cloneClock, f as applyPatchAsActor, g as toJson, h as forkState, i as tryMergeDoc, j as diffJsonPatch, k as PatchCompileError, l as serializeState, m as createState, n as mergeDoc, nt as nextDotForActor, o as deserializeDoc, p as applyPatchInPlace, q as rgaInsertAfter, r as mergeState, rt as observeDot, s as deserializeState, t as MergeError, tt as createClock, u as PatchError, v as tryApplyPatchInPlace, w as docFromJson, x as cloneDoc, y as validateJsonPatch, z as newReg } from "./merge-CKcP1ZPt.mjs";
1
+ import { $ as rgaInsertAfter, A as jsonPatchToCrdtSafe, B as JsonValueValidationError, C as applyIntentsToCrdt, D as docFromJson, E as crdtToJsonPatch, F as getAtJson, G as objCompactTombstones, H as newObj, I as jsonEquals, J as materialize, K as objRemove, L as parseJsonPointer, M as PatchCompileError, N as compileJsonPatchToIntent, O as docFromJsonWithDot, P as diffJsonPatch, Q as rgaIdAtIndex, R as stringifyJsonPointer, S as validateJsonPatch, T as crdtToFullReplace, U as newReg, V as lwwSet, W as newSeq, X as rgaCompactTombstones, Y as HEAD, Z as rgaDelete, _ as createState, a as mergeState, at as vvMerge, b as tryApplyPatch, c as DeserializeError, ct as ClockValidationError, d as serializeDoc, dt as nextDotForActor, et as rgaLinearizeIds, f as serializeState, ft as observeDot, g as applyPatchInPlace, h as applyPatchAsActor, i as mergeDoc, it as vvHasDot, j as tryJsonPatchToCrdt, k as jsonPatchToCrdt, l as deserializeDoc, lt as cloneClock, m as applyPatch, n as compactStateTombstones, nt as compareDot, o as tryMergeDoc, ot as MAX_TRAVERSAL_DEPTH, p as PatchError, q as objSet, r as MergeError, rt as dotToElemId, s as tryMergeState, st as TraversalDepthError, t as compactDocTombstones, tt as rgaPrevForInsertAtIndex, u as deserializeState, ut as createClock, v as forkState, w as cloneDoc, x as tryApplyPatchInPlace, y as toJson, z as ROOT_KEY } from "./compact-BdTuOQK-.mjs";
2
2
 
3
- export { HEAD, MergeError, PatchCompileError, PatchError, ROOT_KEY, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compareDot, compileJsonPatchToIntent, crdtToFullReplace, crdtToJsonPatch, createClock, createState, deserializeDoc, deserializeState, diffJsonPatch, docFromJson, docFromJsonWithDot, dotToElemId, forkState, getAtJson, jsonEquals, jsonPatchToCrdt, jsonPatchToCrdtSafe, lwwSet, materialize, mergeDoc, mergeState, newObj, newReg, newSeq, nextDotForActor, objRemove, objSet, observeDot, parseJsonPointer, rgaDelete, rgaIdAtIndex, rgaInsertAfter, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchInPlace, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };
3
+ export { ClockValidationError, DeserializeError, HEAD, JsonValueValidationError, MAX_TRAVERSAL_DEPTH, MergeError, PatchCompileError, PatchError, ROOT_KEY, TraversalDepthError, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compactDocTombstones, compactStateTombstones, compareDot, compileJsonPatchToIntent, crdtToFullReplace, crdtToJsonPatch, createClock, createState, deserializeDoc, deserializeState, diffJsonPatch, docFromJson, docFromJsonWithDot, dotToElemId, forkState, getAtJson, jsonEquals, jsonPatchToCrdt, jsonPatchToCrdtSafe, lwwSet, materialize, mergeDoc, mergeState, newObj, newReg, newSeq, nextDotForActor, objCompactTombstones, objRemove, objSet, observeDot, parseJsonPointer, rgaCompactTombstones, rgaDelete, rgaIdAtIndex, rgaInsertAfter, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchInPlace, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "json-patch-to-crdt",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Convert JSON Patch (RFC 6902) to and from a CRDT-friendly representation.",
5
5
  "keywords": [
6
6
  "crdt",
@@ -42,6 +42,12 @@
42
42
  "fmt:check": "oxfmt . --check",
43
43
  "typecheck": "tsc --noEmit",
44
44
  "build": "tsdown --config tsdown.config.mts",
45
+ "bench:sequential": "bun run bench/sequential-apply.microbench.ts",
46
+ "test:state-core": "bun test tests/state-core.test.ts",
47
+ "test:patch-diff-doc": "bun test tests/patch-diff-doc.test.ts",
48
+ "test:merge-compaction": "bun test tests/merge-compaction.test.ts",
49
+ "test:replica-session": "bun test tests/replica-session.test.ts",
50
+ "test:perf-regression": "bun test tests/perf-regression.test.ts",
45
51
  "ci:publish": "bun run build && changeset publish"
46
52
  },
47
53
  "devDependencies": {
@@ -54,5 +60,9 @@
54
60
  },
55
61
  "peerDependencies": {
56
62
  "typescript": "^5"
57
- }
63
+ },
64
+ "engines": {
65
+ "node": ">=18"
66
+ },
67
+ "packageManager": "bun@1.3.7"
58
68
  }