json-patch-to-crdt 0.1.3 → 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 +81 -410
- package/dist/{compact-BdTuOQK-.mjs → compact-BS7F604m.mjs} +1310 -192
- package/dist/{compact-DoM9CJNR.js → compact-BToZE6Q6.js} +1345 -191
- package/dist/{depth-Dl_yOAKU.d.ts → depth-BTHjgY18.d.mts} +67 -4
- package/dist/{depth-IvWvLAkt.d.mts → depth-DSl2ghKu.d.ts} +67 -4
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -1
- package/dist/index.mjs +2 -2
- package/dist/internals.d.mts +31 -4
- package/dist/internals.d.ts +31 -4
- package/dist/internals.js +7 -1
- package/dist/internals.mjs +2 -2
- package/package.json +4 -1
|
@@ -39,7 +39,8 @@ type ElemId = string;
|
|
|
39
39
|
type RgaElem = {
|
|
40
40
|
id: ElemId; /** Predecessor element ID (`"HEAD"` for the first element). */
|
|
41
41
|
prev: ElemId; /** Whether this element has been logically deleted. */
|
|
42
|
-
tombstone: boolean; /**
|
|
42
|
+
tombstone: boolean; /** Dot for the latest delete event that tombstoned this element (if retained). */
|
|
43
|
+
delDot?: Dot; /** The child CRDT node stored at this position. */
|
|
43
44
|
value: Node; /** Dot used for deterministic ordering among concurrent inserts with the same predecessor. */
|
|
44
45
|
insDot: Dot;
|
|
45
46
|
};
|
|
@@ -66,6 +67,7 @@ type SerializedRgaElem = {
|
|
|
66
67
|
id: ElemId;
|
|
67
68
|
prev: ElemId;
|
|
68
69
|
tombstone: boolean;
|
|
70
|
+
delDot?: Dot;
|
|
69
71
|
value: SerializedNode;
|
|
70
72
|
insDot: Dot;
|
|
71
73
|
};
|
|
@@ -101,6 +103,19 @@ type SerializedState = {
|
|
|
101
103
|
};
|
|
102
104
|
/** Typed reasons for rejecting malformed serialized CRDT payloads. */
|
|
103
105
|
type DeserializeErrorReason = "INVALID_SERIALIZED_SHAPE" | "INVALID_SERIALIZED_INVARIANT";
|
|
106
|
+
/** Structured failure payload used by non-throwing deserialize helpers. */
|
|
107
|
+
type DeserializeFailure = {
|
|
108
|
+
code: 409;
|
|
109
|
+
reason: DeserializeErrorReason;
|
|
110
|
+
path: string;
|
|
111
|
+
message: string;
|
|
112
|
+
} | {
|
|
113
|
+
code: 409;
|
|
114
|
+
reason: "MAX_DEPTH_EXCEEDED";
|
|
115
|
+
message: string;
|
|
116
|
+
depth: number;
|
|
117
|
+
maxDepth: number;
|
|
118
|
+
};
|
|
104
119
|
/**
|
|
105
120
|
* Internal intent operations produced by compiling RFC 6902 JSON Patch ops.
|
|
106
121
|
* Each variant maps to a specific CRDT mutation.
|
|
@@ -201,6 +216,13 @@ type ApplyPatchAsActorOptions = {
|
|
|
201
216
|
strictParents?: boolean;
|
|
202
217
|
jsonValidation?: JsonValidationMode;
|
|
203
218
|
};
|
|
219
|
+
/** Non-throwing result for internals-only `tryApplyPatchAsActor`. */
|
|
220
|
+
type TryApplyPatchAsActorResult = ({
|
|
221
|
+
ok: true;
|
|
222
|
+
} & ApplyPatchAsActorResult) | {
|
|
223
|
+
ok: false;
|
|
224
|
+
error: ApplyError;
|
|
225
|
+
};
|
|
204
226
|
/** Typed failure reason used across patch/merge helpers. */
|
|
205
227
|
type PatchErrorReason = "INVALID_PATCH" | "INVALID_POINTER" | "MISSING_PARENT" | "MISSING_TARGET" | "INVALID_TARGET" | "OUT_OF_BOUNDS" | "TEST_FAILED" | "INVALID_MOVE" | "DOT_GENERATION_EXHAUSTED" | "MAX_DEPTH_EXCEEDED" | "LINEAGE_MISMATCH";
|
|
206
228
|
/** Structured conflict payload used by non-throwing APIs. */
|
|
@@ -216,6 +238,22 @@ type ApplyError = {
|
|
|
216
238
|
type ApplyResult = {
|
|
217
239
|
ok: true;
|
|
218
240
|
} | ApplyError;
|
|
241
|
+
/** Non-throwing result for `deserializeDoc`. */
|
|
242
|
+
type TryDeserializeDocResult = {
|
|
243
|
+
ok: true;
|
|
244
|
+
doc: Doc;
|
|
245
|
+
} | {
|
|
246
|
+
ok: false;
|
|
247
|
+
error: DeserializeFailure;
|
|
248
|
+
};
|
|
249
|
+
/** Non-throwing result for `deserializeState`. */
|
|
250
|
+
type TryDeserializeStateResult = {
|
|
251
|
+
ok: true;
|
|
252
|
+
state: CrdtState;
|
|
253
|
+
} | {
|
|
254
|
+
ok: false;
|
|
255
|
+
error: DeserializeFailure;
|
|
256
|
+
};
|
|
219
257
|
/** How JSON Patch operations are interpreted during application. */
|
|
220
258
|
type PatchSemantics = "base" | "sequential";
|
|
221
259
|
/** Options for compile/validation helpers. */
|
|
@@ -351,16 +389,30 @@ type DiffOptions = {
|
|
|
351
389
|
/**
|
|
352
390
|
* Array diff mode.
|
|
353
391
|
* - `"lcs"` (default): index-level edits using LCS.
|
|
392
|
+
* - `"lcs-linear"`: index-level edits using a lower-memory LCS variant.
|
|
393
|
+
* This reduces memory use but still has `O(n * m)` time complexity and no
|
|
394
|
+
* automatic fallback for very large unmatched windows.
|
|
354
395
|
* - `"atomic"`: one-op root/field replacement for changed arrays.
|
|
355
396
|
*/
|
|
356
|
-
arrayStrategy?: "atomic" | "lcs";
|
|
397
|
+
arrayStrategy?: "atomic" | "lcs" | "lcs-linear";
|
|
357
398
|
/**
|
|
358
399
|
* Maximum LCS matrix cells (`(base.length + 1) * (next.length + 1)`) before
|
|
359
|
-
* falling back to atomic replacement
|
|
400
|
+
* falling back to atomic replacement for `arrayStrategy: "lcs"`.
|
|
401
|
+
* Defaults to `250_000`.
|
|
360
402
|
*
|
|
361
403
|
* Set to `Number.POSITIVE_INFINITY` to always allow LCS.
|
|
362
404
|
*/
|
|
363
405
|
lcsMaxCells?: number;
|
|
406
|
+
/**
|
|
407
|
+
* Emit RFC 6902 `move` operations when a deterministic remove/add rewrite is available.
|
|
408
|
+
* Defaults to `false` for backward compatibility.
|
|
409
|
+
*/
|
|
410
|
+
emitMoves?: boolean;
|
|
411
|
+
/**
|
|
412
|
+
* Emit RFC 6902 `copy` operations when a deterministic existing-value source is available.
|
|
413
|
+
* Defaults to `false` for backward compatibility.
|
|
414
|
+
*/
|
|
415
|
+
emitCopies?: boolean;
|
|
364
416
|
/**
|
|
365
417
|
* Runtime guardrails for diff inputs from untyped callers.
|
|
366
418
|
* Defaults to `"none"` for backward compatibility.
|
|
@@ -433,6 +485,8 @@ declare function validateJsonPatch(base: JsonValue, patch: JsonPatchOp[], option
|
|
|
433
485
|
* Returns the updated state and a new version vector snapshot.
|
|
434
486
|
*/
|
|
435
487
|
declare function applyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): ApplyPatchAsActorResult;
|
|
488
|
+
/** Non-throwing `applyPatchAsActor` variant for internals sync flows. */
|
|
489
|
+
declare function tryApplyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): TryApplyPatchAsActorResult;
|
|
436
490
|
//#endregion
|
|
437
491
|
//#region src/json-value.d.ts
|
|
438
492
|
/**
|
|
@@ -501,6 +555,11 @@ declare function compileJsonPatchToIntent(baseJson: JsonValue, patch: JsonPatchO
|
|
|
501
555
|
* Compute a JSON Patch delta between two JSON values.
|
|
502
556
|
* By default arrays use a deterministic LCS strategy.
|
|
503
557
|
* Pass `{ arrayStrategy: "atomic" }` for single-op array replacement.
|
|
558
|
+
* Pass `{ arrayStrategy: "lcs-linear" }` for a lower-memory LCS variant.
|
|
559
|
+
* Note that `lcs-linear` still runs in `O(n * m)` time and does not have an
|
|
560
|
+
* automatic fallback for very large unmatched windows.
|
|
561
|
+
* Pass `{ emitMoves: true }` or `{ emitCopies: true }` to opt into RFC 6902
|
|
562
|
+
* move/copy emission when a deterministic rewrite is available.
|
|
504
563
|
* @param base - The original JSON value.
|
|
505
564
|
* @param next - The target JSON value.
|
|
506
565
|
* @param options - Diff options.
|
|
@@ -521,10 +580,14 @@ declare class DeserializeError extends Error {
|
|
|
521
580
|
declare function serializeDoc(doc: Doc): SerializedDoc;
|
|
522
581
|
/** Reconstruct a CRDT document from its serialized form. */
|
|
523
582
|
declare function deserializeDoc(data: SerializedDoc): Doc;
|
|
583
|
+
/** Non-throwing `deserializeDoc` variant with typed validation details. */
|
|
584
|
+
declare function tryDeserializeDoc(data: SerializedDoc): TryDeserializeDocResult;
|
|
524
585
|
/** Serialize a full CRDT state (document + clock) to a JSON-safe representation. */
|
|
525
586
|
declare function serializeState(state: CrdtState): SerializedState;
|
|
526
587
|
/** Reconstruct a full CRDT state from its serialized form, restoring the clock. */
|
|
527
588
|
declare function deserializeState(data: SerializedState): CrdtState;
|
|
589
|
+
/** Non-throwing `deserializeState` variant with typed validation details. */
|
|
590
|
+
declare function tryDeserializeState(data: SerializedState): TryDeserializeStateResult;
|
|
528
591
|
//#endregion
|
|
529
592
|
//#region src/merge.d.ts
|
|
530
593
|
/** Error thrown by throwing merge helpers (`mergeDoc` / `mergeState`). */
|
|
@@ -597,4 +660,4 @@ declare class TraversalDepthError extends Error {
|
|
|
597
660
|
constructor(depth: number, maxDepth?: number);
|
|
598
661
|
}
|
|
599
662
|
//#endregion
|
|
600
|
-
export {
|
|
663
|
+
export { CreateStateOptions as $, PatchError as A, TombstoneCompactionOptions as At, validateJsonPatch as B, VersionVector as Bt, stringifyJsonPointer as C, RgaElem as Ct, nextDotForActor as D, SerializedNode as Dt, createClock as E, SerializedDoc as Et, forkState as F, TryDeserializeDocResult as Ft, ApplyPatchInPlaceOptions as G, ApplyError as H, toJson as I, TryDeserializeStateResult as It, Clock as J, ApplyPatchOptions as K, tryApplyPatch as L, TryMergeDocResult as Lt, applyPatchAsActor as M, TryApplyPatchAsActorResult as Mt, applyPatchInPlace as N, TryApplyPatchInPlaceResult as Nt, observeDot as O, SerializedRgaElem as Ot, createState as P, TryApplyPatchResult as Pt, CrdtState as Q, tryApplyPatchAsActor as R, TryMergeStateResult as Rt, parseJsonPointer as S, ROOT_KEY as St, cloneClock as T, SerializedClock as Tt, ApplyPatchAsActorOptions as U, ActorId as V, ApplyPatchAsActorResult as W, CompactStateTombstonesResult as X, CompactDocTombstonesResult as Y, CompilePatchOptions as Z, PatchCompileError as _, Node as _t, MergeError as a, ElemId as at, getAtJson as b, PatchErrorReason as bt, tryMergeDoc as c, JsonPatch as ct, deserializeDoc as d, JsonPrimitive as dt, DeserializeErrorReason as et, deserializeState as f, JsonValidationMode as ft, tryDeserializeState as g, MergeStateOptions as gt, tryDeserializeDoc as h, MergeDocOptions as ht, compactStateTombstones as i, Dot as it, applyPatch as j, TombstoneCompactionStats as jt, JsonValueValidationError as k, SerializedState as kt, tryMergeState as l, JsonPatchOp as lt, serializeState as m, LwwReg as mt, TraversalDepthError as n, DiffOptions as nt, mergeDoc as o, ForkStateOptions as ot, serializeDoc as p, JsonValue as pt, ApplyResult as q, compactDocTombstones as r, Doc as rt, mergeState as s, IntentOp as st, MAX_TRAVERSAL_DEPTH as t, DeserializeFailure as tt, DeserializeError as u, JsonPatchToCrdtOptions as ut, compileJsonPatchToIntent as v, ObjEntry as vt, ClockValidationError as w, RgaSeq as wt, jsonEquals as x, PatchSemantics as xt, diffJsonPatch as y, ObjNode as yt, tryApplyPatchInPlace as z, ValidatePatchResult as zt };
|
|
@@ -39,7 +39,8 @@ type ElemId = string;
|
|
|
39
39
|
type RgaElem = {
|
|
40
40
|
id: ElemId; /** Predecessor element ID (`"HEAD"` for the first element). */
|
|
41
41
|
prev: ElemId; /** Whether this element has been logically deleted. */
|
|
42
|
-
tombstone: boolean; /**
|
|
42
|
+
tombstone: boolean; /** Dot for the latest delete event that tombstoned this element (if retained). */
|
|
43
|
+
delDot?: Dot; /** The child CRDT node stored at this position. */
|
|
43
44
|
value: Node; /** Dot used for deterministic ordering among concurrent inserts with the same predecessor. */
|
|
44
45
|
insDot: Dot;
|
|
45
46
|
};
|
|
@@ -66,6 +67,7 @@ type SerializedRgaElem = {
|
|
|
66
67
|
id: ElemId;
|
|
67
68
|
prev: ElemId;
|
|
68
69
|
tombstone: boolean;
|
|
70
|
+
delDot?: Dot;
|
|
69
71
|
value: SerializedNode;
|
|
70
72
|
insDot: Dot;
|
|
71
73
|
};
|
|
@@ -101,6 +103,19 @@ type SerializedState = {
|
|
|
101
103
|
};
|
|
102
104
|
/** Typed reasons for rejecting malformed serialized CRDT payloads. */
|
|
103
105
|
type DeserializeErrorReason = "INVALID_SERIALIZED_SHAPE" | "INVALID_SERIALIZED_INVARIANT";
|
|
106
|
+
/** Structured failure payload used by non-throwing deserialize helpers. */
|
|
107
|
+
type DeserializeFailure = {
|
|
108
|
+
code: 409;
|
|
109
|
+
reason: DeserializeErrorReason;
|
|
110
|
+
path: string;
|
|
111
|
+
message: string;
|
|
112
|
+
} | {
|
|
113
|
+
code: 409;
|
|
114
|
+
reason: "MAX_DEPTH_EXCEEDED";
|
|
115
|
+
message: string;
|
|
116
|
+
depth: number;
|
|
117
|
+
maxDepth: number;
|
|
118
|
+
};
|
|
104
119
|
/**
|
|
105
120
|
* Internal intent operations produced by compiling RFC 6902 JSON Patch ops.
|
|
106
121
|
* Each variant maps to a specific CRDT mutation.
|
|
@@ -201,6 +216,13 @@ type ApplyPatchAsActorOptions = {
|
|
|
201
216
|
strictParents?: boolean;
|
|
202
217
|
jsonValidation?: JsonValidationMode;
|
|
203
218
|
};
|
|
219
|
+
/** Non-throwing result for internals-only `tryApplyPatchAsActor`. */
|
|
220
|
+
type TryApplyPatchAsActorResult = ({
|
|
221
|
+
ok: true;
|
|
222
|
+
} & ApplyPatchAsActorResult) | {
|
|
223
|
+
ok: false;
|
|
224
|
+
error: ApplyError;
|
|
225
|
+
};
|
|
204
226
|
/** Typed failure reason used across patch/merge helpers. */
|
|
205
227
|
type PatchErrorReason = "INVALID_PATCH" | "INVALID_POINTER" | "MISSING_PARENT" | "MISSING_TARGET" | "INVALID_TARGET" | "OUT_OF_BOUNDS" | "TEST_FAILED" | "INVALID_MOVE" | "DOT_GENERATION_EXHAUSTED" | "MAX_DEPTH_EXCEEDED" | "LINEAGE_MISMATCH";
|
|
206
228
|
/** Structured conflict payload used by non-throwing APIs. */
|
|
@@ -216,6 +238,22 @@ type ApplyError = {
|
|
|
216
238
|
type ApplyResult = {
|
|
217
239
|
ok: true;
|
|
218
240
|
} | ApplyError;
|
|
241
|
+
/** Non-throwing result for `deserializeDoc`. */
|
|
242
|
+
type TryDeserializeDocResult = {
|
|
243
|
+
ok: true;
|
|
244
|
+
doc: Doc;
|
|
245
|
+
} | {
|
|
246
|
+
ok: false;
|
|
247
|
+
error: DeserializeFailure;
|
|
248
|
+
};
|
|
249
|
+
/** Non-throwing result for `deserializeState`. */
|
|
250
|
+
type TryDeserializeStateResult = {
|
|
251
|
+
ok: true;
|
|
252
|
+
state: CrdtState;
|
|
253
|
+
} | {
|
|
254
|
+
ok: false;
|
|
255
|
+
error: DeserializeFailure;
|
|
256
|
+
};
|
|
219
257
|
/** How JSON Patch operations are interpreted during application. */
|
|
220
258
|
type PatchSemantics = "base" | "sequential";
|
|
221
259
|
/** Options for compile/validation helpers. */
|
|
@@ -351,16 +389,30 @@ type DiffOptions = {
|
|
|
351
389
|
/**
|
|
352
390
|
* Array diff mode.
|
|
353
391
|
* - `"lcs"` (default): index-level edits using LCS.
|
|
392
|
+
* - `"lcs-linear"`: index-level edits using a lower-memory LCS variant.
|
|
393
|
+
* This reduces memory use but still has `O(n * m)` time complexity and no
|
|
394
|
+
* automatic fallback for very large unmatched windows.
|
|
354
395
|
* - `"atomic"`: one-op root/field replacement for changed arrays.
|
|
355
396
|
*/
|
|
356
|
-
arrayStrategy?: "atomic" | "lcs";
|
|
397
|
+
arrayStrategy?: "atomic" | "lcs" | "lcs-linear";
|
|
357
398
|
/**
|
|
358
399
|
* Maximum LCS matrix cells (`(base.length + 1) * (next.length + 1)`) before
|
|
359
|
-
* falling back to atomic replacement
|
|
400
|
+
* falling back to atomic replacement for `arrayStrategy: "lcs"`.
|
|
401
|
+
* Defaults to `250_000`.
|
|
360
402
|
*
|
|
361
403
|
* Set to `Number.POSITIVE_INFINITY` to always allow LCS.
|
|
362
404
|
*/
|
|
363
405
|
lcsMaxCells?: number;
|
|
406
|
+
/**
|
|
407
|
+
* Emit RFC 6902 `move` operations when a deterministic remove/add rewrite is available.
|
|
408
|
+
* Defaults to `false` for backward compatibility.
|
|
409
|
+
*/
|
|
410
|
+
emitMoves?: boolean;
|
|
411
|
+
/**
|
|
412
|
+
* Emit RFC 6902 `copy` operations when a deterministic existing-value source is available.
|
|
413
|
+
* Defaults to `false` for backward compatibility.
|
|
414
|
+
*/
|
|
415
|
+
emitCopies?: boolean;
|
|
364
416
|
/**
|
|
365
417
|
* Runtime guardrails for diff inputs from untyped callers.
|
|
366
418
|
* Defaults to `"none"` for backward compatibility.
|
|
@@ -433,6 +485,8 @@ declare function validateJsonPatch(base: JsonValue, patch: JsonPatchOp[], option
|
|
|
433
485
|
* Returns the updated state and a new version vector snapshot.
|
|
434
486
|
*/
|
|
435
487
|
declare function applyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): ApplyPatchAsActorResult;
|
|
488
|
+
/** Non-throwing `applyPatchAsActor` variant for internals sync flows. */
|
|
489
|
+
declare function tryApplyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): TryApplyPatchAsActorResult;
|
|
436
490
|
//#endregion
|
|
437
491
|
//#region src/json-value.d.ts
|
|
438
492
|
/**
|
|
@@ -501,6 +555,11 @@ declare function compileJsonPatchToIntent(baseJson: JsonValue, patch: JsonPatchO
|
|
|
501
555
|
* Compute a JSON Patch delta between two JSON values.
|
|
502
556
|
* By default arrays use a deterministic LCS strategy.
|
|
503
557
|
* Pass `{ arrayStrategy: "atomic" }` for single-op array replacement.
|
|
558
|
+
* Pass `{ arrayStrategy: "lcs-linear" }` for a lower-memory LCS variant.
|
|
559
|
+
* Note that `lcs-linear` still runs in `O(n * m)` time and does not have an
|
|
560
|
+
* automatic fallback for very large unmatched windows.
|
|
561
|
+
* Pass `{ emitMoves: true }` or `{ emitCopies: true }` to opt into RFC 6902
|
|
562
|
+
* move/copy emission when a deterministic rewrite is available.
|
|
504
563
|
* @param base - The original JSON value.
|
|
505
564
|
* @param next - The target JSON value.
|
|
506
565
|
* @param options - Diff options.
|
|
@@ -521,10 +580,14 @@ declare class DeserializeError extends Error {
|
|
|
521
580
|
declare function serializeDoc(doc: Doc): SerializedDoc;
|
|
522
581
|
/** Reconstruct a CRDT document from its serialized form. */
|
|
523
582
|
declare function deserializeDoc(data: SerializedDoc): Doc;
|
|
583
|
+
/** Non-throwing `deserializeDoc` variant with typed validation details. */
|
|
584
|
+
declare function tryDeserializeDoc(data: SerializedDoc): TryDeserializeDocResult;
|
|
524
585
|
/** Serialize a full CRDT state (document + clock) to a JSON-safe representation. */
|
|
525
586
|
declare function serializeState(state: CrdtState): SerializedState;
|
|
526
587
|
/** Reconstruct a full CRDT state from its serialized form, restoring the clock. */
|
|
527
588
|
declare function deserializeState(data: SerializedState): CrdtState;
|
|
589
|
+
/** Non-throwing `deserializeState` variant with typed validation details. */
|
|
590
|
+
declare function tryDeserializeState(data: SerializedState): TryDeserializeStateResult;
|
|
528
591
|
//#endregion
|
|
529
592
|
//#region src/merge.d.ts
|
|
530
593
|
/** Error thrown by throwing merge helpers (`mergeDoc` / `mergeState`). */
|
|
@@ -597,4 +660,4 @@ declare class TraversalDepthError extends Error {
|
|
|
597
660
|
constructor(depth: number, maxDepth?: number);
|
|
598
661
|
}
|
|
599
662
|
//#endregion
|
|
600
|
-
export {
|
|
663
|
+
export { CreateStateOptions as $, PatchError as A, TombstoneCompactionOptions as At, validateJsonPatch as B, VersionVector as Bt, stringifyJsonPointer as C, RgaElem as Ct, nextDotForActor as D, SerializedNode as Dt, createClock as E, SerializedDoc as Et, forkState as F, TryDeserializeDocResult as Ft, ApplyPatchInPlaceOptions as G, ApplyError as H, toJson as I, TryDeserializeStateResult as It, Clock as J, ApplyPatchOptions as K, tryApplyPatch as L, TryMergeDocResult as Lt, applyPatchAsActor as M, TryApplyPatchAsActorResult as Mt, applyPatchInPlace as N, TryApplyPatchInPlaceResult as Nt, observeDot as O, SerializedRgaElem as Ot, createState as P, TryApplyPatchResult as Pt, CrdtState as Q, tryApplyPatchAsActor as R, TryMergeStateResult as Rt, parseJsonPointer as S, ROOT_KEY as St, cloneClock as T, SerializedClock as Tt, ApplyPatchAsActorOptions as U, ActorId as V, ApplyPatchAsActorResult as W, CompactStateTombstonesResult as X, CompactDocTombstonesResult as Y, CompilePatchOptions as Z, PatchCompileError as _, Node as _t, MergeError as a, ElemId as at, getAtJson as b, PatchErrorReason as bt, tryMergeDoc as c, JsonPatch as ct, deserializeDoc as d, JsonPrimitive as dt, DeserializeErrorReason as et, deserializeState as f, JsonValidationMode as ft, tryDeserializeState as g, MergeStateOptions as gt, tryDeserializeDoc as h, MergeDocOptions as ht, compactStateTombstones as i, Dot as it, applyPatch as j, TombstoneCompactionStats as jt, JsonValueValidationError as k, SerializedState as kt, tryMergeState as l, JsonPatchOp as lt, serializeState as m, LwwReg as mt, TraversalDepthError as n, DiffOptions as nt, mergeDoc as o, ForkStateOptions as ot, serializeDoc as p, JsonValue as pt, ApplyResult as q, compactDocTombstones as r, Doc as rt, mergeState as s, IntentOp as st, MAX_TRAVERSAL_DEPTH as t, DeserializeFailure as tt, DeserializeError as u, JsonPatchToCrdtOptions as ut, compileJsonPatchToIntent as v, ObjEntry as vt, ClockValidationError as w, RgaSeq as wt, jsonEquals as x, PatchSemantics as xt, diffJsonPatch as y, ObjNode as yt, tryApplyPatchInPlace as z, ValidatePatchResult as zt };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, ClockValidationError, type CompactStateTombstonesResult, type CrdtState, type CreateStateOptions, DeserializeError, type DeserializeErrorReason, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValidationMode, type JsonValue, JsonValueValidationError, MAX_TRAVERSAL_DEPTH, MergeError, type MergeStateOptions, PatchError, type PatchErrorReason, type PatchSemantics, type SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, type TryApplyPatchInPlaceResult, type TryApplyPatchResult, type TryMergeStateResult, type ValidatePatchResult, applyPatch, applyPatchInPlace, compactStateTombstones, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryMergeState, validateJsonPatch };
|
|
1
|
+
import { $ as CreateStateOptions, A as PatchError, At as TombstoneCompactionOptions, B as validateJsonPatch, F as forkState, G as ApplyPatchInPlaceOptions, H as ApplyError, I as toJson, It as TryDeserializeStateResult, K as ApplyPatchOptions, L as tryApplyPatch, N as applyPatchInPlace, Nt as TryApplyPatchInPlaceResult, P as createState, Pt as TryApplyPatchResult, Q as CrdtState, Rt as TryMergeStateResult, V as ActorId, X as CompactStateTombstonesResult, a as MergeError, bt as PatchErrorReason, ct as JsonPatch, dt as JsonPrimitive, et as DeserializeErrorReason, f as deserializeState, ft as JsonValidationMode, g as tryDeserializeState, gt as MergeStateOptions, i as compactStateTombstones, j as applyPatch, jt as TombstoneCompactionStats, k as JsonValueValidationError, kt as SerializedState, l as tryMergeState, lt as JsonPatchOp, m as serializeState, n as TraversalDepthError, nt as DiffOptions, ot as ForkStateOptions, pt as JsonValue, s as mergeState, t as MAX_TRAVERSAL_DEPTH, tt as DeserializeFailure, u as DeserializeError, w as ClockValidationError, xt as PatchSemantics, y as diffJsonPatch, z as tryApplyPatchInPlace, zt as ValidatePatchResult } from "./depth-BTHjgY18.mjs";
|
|
2
|
+
export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, ClockValidationError, type CompactStateTombstonesResult, type CrdtState, type CreateStateOptions, DeserializeError, type DeserializeErrorReason, type DeserializeFailure, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValidationMode, type JsonValue, JsonValueValidationError, MAX_TRAVERSAL_DEPTH, MergeError, type MergeStateOptions, PatchError, type PatchErrorReason, type PatchSemantics, type SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, type TryApplyPatchInPlaceResult, type TryApplyPatchResult, type TryDeserializeStateResult, type TryMergeStateResult, type ValidatePatchResult, applyPatch, applyPatchInPlace, compactStateTombstones, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryDeserializeState, tryMergeState, validateJsonPatch };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, ClockValidationError, type CompactStateTombstonesResult, type CrdtState, type CreateStateOptions, DeserializeError, type DeserializeErrorReason, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValidationMode, type JsonValue, JsonValueValidationError, MAX_TRAVERSAL_DEPTH, MergeError, type MergeStateOptions, PatchError, type PatchErrorReason, type PatchSemantics, type SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, type TryApplyPatchInPlaceResult, type TryApplyPatchResult, type TryMergeStateResult, type ValidatePatchResult, applyPatch, applyPatchInPlace, compactStateTombstones, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryMergeState, validateJsonPatch };
|
|
1
|
+
import { $ as CreateStateOptions, A as PatchError, At as TombstoneCompactionOptions, B as validateJsonPatch, F as forkState, G as ApplyPatchInPlaceOptions, H as ApplyError, I as toJson, It as TryDeserializeStateResult, K as ApplyPatchOptions, L as tryApplyPatch, N as applyPatchInPlace, Nt as TryApplyPatchInPlaceResult, P as createState, Pt as TryApplyPatchResult, Q as CrdtState, Rt as TryMergeStateResult, V as ActorId, X as CompactStateTombstonesResult, a as MergeError, bt as PatchErrorReason, ct as JsonPatch, dt as JsonPrimitive, et as DeserializeErrorReason, f as deserializeState, ft as JsonValidationMode, g as tryDeserializeState, gt as MergeStateOptions, i as compactStateTombstones, j as applyPatch, jt as TombstoneCompactionStats, k as JsonValueValidationError, kt as SerializedState, l as tryMergeState, lt as JsonPatchOp, m as serializeState, n as TraversalDepthError, nt as DiffOptions, ot as ForkStateOptions, pt as JsonValue, s as mergeState, t as MAX_TRAVERSAL_DEPTH, tt as DeserializeFailure, u as DeserializeError, w as ClockValidationError, xt as PatchSemantics, y as diffJsonPatch, z as tryApplyPatchInPlace, zt as ValidatePatchResult } from "./depth-DSl2ghKu.js";
|
|
2
|
+
export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, ClockValidationError, type CompactStateTombstonesResult, type CrdtState, type CreateStateOptions, DeserializeError, type DeserializeErrorReason, type DeserializeFailure, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValidationMode, type JsonValue, JsonValueValidationError, MAX_TRAVERSAL_DEPTH, MergeError, type MergeStateOptions, PatchError, type PatchErrorReason, type PatchSemantics, type SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, type TryApplyPatchInPlaceResult, type TryApplyPatchResult, type TryDeserializeStateResult, type TryMergeStateResult, type ValidatePatchResult, applyPatch, applyPatchInPlace, compactStateTombstones, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryDeserializeState, tryMergeState, validateJsonPatch };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_compact = require('./compact-
|
|
2
|
+
const require_compact = require('./compact-BToZE6Q6.js');
|
|
3
3
|
|
|
4
4
|
exports.ClockValidationError = require_compact.ClockValidationError;
|
|
5
5
|
exports.DeserializeError = require_compact.DeserializeError;
|
|
@@ -20,5 +20,6 @@ exports.serializeState = require_compact.serializeState;
|
|
|
20
20
|
exports.toJson = require_compact.toJson;
|
|
21
21
|
exports.tryApplyPatch = require_compact.tryApplyPatch;
|
|
22
22
|
exports.tryApplyPatchInPlace = require_compact.tryApplyPatchInPlace;
|
|
23
|
+
exports.tryDeserializeState = require_compact.tryDeserializeState;
|
|
23
24
|
exports.tryMergeState = require_compact.tryMergeState;
|
|
24
25
|
exports.validateJsonPatch = require_compact.validateJsonPatch;
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { R as diffJsonPatch, S as tryApplyPatch, T as validateJsonPatch, W as JsonValueValidationError, a as mergeState, b as forkState, c as DeserializeError, f as serializeState, ft as MAX_TRAVERSAL_DEPTH, g as applyPatch, h as PatchError, m as tryDeserializeState, mt as ClockValidationError, n as compactStateTombstones, pt as TraversalDepthError, r as MergeError, s as tryMergeState, u as deserializeState, v as applyPatchInPlace, w as tryApplyPatchInPlace, x as toJson, y as createState } from "./compact-BS7F604m.mjs";
|
|
2
2
|
|
|
3
|
-
export { ClockValidationError, DeserializeError, JsonValueValidationError, MAX_TRAVERSAL_DEPTH, MergeError, PatchError, TraversalDepthError, applyPatch, applyPatchInPlace, compactStateTombstones, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryMergeState, validateJsonPatch };
|
|
3
|
+
export { ClockValidationError, DeserializeError, JsonValueValidationError, MAX_TRAVERSAL_DEPTH, MergeError, PatchError, TraversalDepthError, applyPatch, applyPatchInPlace, compactStateTombstones, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryDeserializeState, tryMergeState, validateJsonPatch };
|
package/dist/internals.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as CreateStateOptions, A as PatchError, At as TombstoneCompactionOptions, B as validateJsonPatch, Bt as VersionVector, C as stringifyJsonPointer, Ct as RgaElem, D as nextDotForActor, Dt as SerializedNode, E as createClock, Et as SerializedDoc, F as forkState, Ft as TryDeserializeDocResult, G as ApplyPatchInPlaceOptions, H as ApplyError, I as toJson, It as TryDeserializeStateResult, J as Clock, K as ApplyPatchOptions, L as tryApplyPatch, Lt as TryMergeDocResult, M as applyPatchAsActor, Mt as TryApplyPatchAsActorResult, N as applyPatchInPlace, Nt as TryApplyPatchInPlaceResult, O as observeDot, Ot as SerializedRgaElem, P as createState, Pt as TryApplyPatchResult, Q as CrdtState, R as tryApplyPatchAsActor, Rt as TryMergeStateResult, S as parseJsonPointer, St as ROOT_KEY, T as cloneClock, Tt as SerializedClock, U as ApplyPatchAsActorOptions, V as ActorId, W as ApplyPatchAsActorResult, X as CompactStateTombstonesResult, Y as CompactDocTombstonesResult, Z as CompilePatchOptions, _ as PatchCompileError, _t as Node, a as MergeError, at as ElemId, b as getAtJson, bt as PatchErrorReason, c as tryMergeDoc, ct as JsonPatch, d as deserializeDoc, dt as JsonPrimitive, et as DeserializeErrorReason, f as deserializeState, ft as JsonValidationMode, g as tryDeserializeState, gt as MergeStateOptions, h as tryDeserializeDoc, ht as MergeDocOptions, i as compactStateTombstones, it as Dot, j as applyPatch, jt as TombstoneCompactionStats, k as JsonValueValidationError, kt as SerializedState, l as tryMergeState, lt as JsonPatchOp, m as serializeState, mt as LwwReg, n as TraversalDepthError, nt as DiffOptions, o as mergeDoc, ot as ForkStateOptions, p as serializeDoc, pt as JsonValue, q as ApplyResult, r as compactDocTombstones, rt as Doc, s as mergeState, st as IntentOp, t as MAX_TRAVERSAL_DEPTH, tt as DeserializeFailure, u as DeserializeError, ut as JsonPatchToCrdtOptions, v as compileJsonPatchToIntent, vt as ObjEntry, w as ClockValidationError, wt as RgaSeq, x as jsonEquals, xt as PatchSemantics, y as diffJsonPatch, yt as ObjNode, z as tryApplyPatchInPlace, zt as ValidatePatchResult } from "./depth-BTHjgY18.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/doc.d.ts
|
|
4
4
|
/**
|
|
@@ -53,10 +53,12 @@ declare const tryJsonPatchToCrdt: typeof jsonPatchToCrdtSafe;
|
|
|
53
53
|
* Generate a JSON Patch delta between two CRDT documents.
|
|
54
54
|
* @param base - The base document snapshot.
|
|
55
55
|
* @param head - The current document state.
|
|
56
|
-
* @param options - Diff options (e.g. `{ arrayStrategy: "lcs" }`).
|
|
56
|
+
* @param options - Diff options (e.g. `{ arrayStrategy: "lcs" }` or `{ arrayStrategy: "lcs-linear" }`).
|
|
57
57
|
* @returns An array of JSON Patch operations that transform base into head.
|
|
58
58
|
*/
|
|
59
59
|
declare function crdtToJsonPatch(base: Doc, head: Doc, options?: DiffOptions): JsonPatchOp[];
|
|
60
|
+
/** Internals-only helper for diffing CRDT nodes from an existing traversal depth. */
|
|
61
|
+
declare function crdtNodesToJsonPatch(baseNode: Node, headNode: Node, options?: DiffOptions, depth?: number): JsonPatchOp[];
|
|
60
62
|
/**
|
|
61
63
|
* Emit a single root `replace` patch representing the full document state.
|
|
62
64
|
* Use `crdtToJsonPatch(base, head)` for delta patches instead.
|
|
@@ -88,9 +90,34 @@ declare function objCompactTombstones(obj: ObjNode, isStable: (dot: Dot) => bool
|
|
|
88
90
|
//#endregion
|
|
89
91
|
//#region src/rga.d.ts
|
|
90
92
|
declare const HEAD: ElemId;
|
|
93
|
+
type RgaValidationIssue = {
|
|
94
|
+
code: "MISSING_PREDECESSOR";
|
|
95
|
+
id: ElemId;
|
|
96
|
+
prev: ElemId;
|
|
97
|
+
message: string;
|
|
98
|
+
} | {
|
|
99
|
+
code: "PREDECESSOR_CYCLE";
|
|
100
|
+
id: ElemId;
|
|
101
|
+
prev: ElemId;
|
|
102
|
+
message: string;
|
|
103
|
+
} | {
|
|
104
|
+
code: "ORPHANED_ELEMENT";
|
|
105
|
+
id: ElemId;
|
|
106
|
+
prev: ElemId;
|
|
107
|
+
message: string;
|
|
108
|
+
};
|
|
109
|
+
type RgaValidationResult = {
|
|
110
|
+
ok: true;
|
|
111
|
+
issues: [];
|
|
112
|
+
} | {
|
|
113
|
+
ok: false;
|
|
114
|
+
issues: RgaValidationIssue[];
|
|
115
|
+
};
|
|
91
116
|
declare function rgaLinearizeIds(seq: RgaSeq): ElemId[];
|
|
92
117
|
declare function rgaInsertAfter(seq: RgaSeq, prev: ElemId, id: ElemId, insDot: Dot, value: Node): void;
|
|
93
|
-
declare function
|
|
118
|
+
declare function rgaInsertAfterChecked(seq: RgaSeq, prev: ElemId, id: ElemId, insDot: Dot, value: Node): void;
|
|
119
|
+
declare function rgaDelete(seq: RgaSeq, id: ElemId, delDot?: Dot): void;
|
|
120
|
+
declare function validateRgaSeq(seq: RgaSeq): RgaValidationResult;
|
|
94
121
|
/**
|
|
95
122
|
* Prune tombstoned elements that are causally stable and have no live descendants
|
|
96
123
|
* depending on them for sequence traversal.
|
|
@@ -101,4 +128,4 @@ declare function rgaCompactTombstones(seq: RgaSeq, isStable: (dot: Dot) => boole
|
|
|
101
128
|
declare function rgaIdAtIndex(seq: RgaSeq, index: number): ElemId | undefined;
|
|
102
129
|
declare function rgaPrevForInsertAtIndex(seq: RgaSeq, index: number): ElemId;
|
|
103
130
|
//#endregion
|
|
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 };
|
|
131
|
+
export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, ClockValidationError, type CompactDocTombstonesResult, type CompactStateTombstonesResult, type CompilePatchOptions, CrdtState, CreateStateOptions, DeserializeError, DeserializeErrorReason, type DeserializeFailure, 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 RgaValidationIssue, type RgaValidationResult, type SerializedClock, type SerializedDoc, type SerializedNode, type SerializedRgaElem, SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, type TryApplyPatchAsActorResult, TryApplyPatchInPlaceResult, TryApplyPatchResult, type TryDeserializeDocResult, TryDeserializeStateResult, type TryMergeDocResult, TryMergeStateResult, ValidatePatchResult, type VersionVector, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compactDocTombstones, compactStateTombstones, compareDot, compileJsonPatchToIntent, crdtNodesToJsonPatch, 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, rgaInsertAfterChecked, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchAsActor, tryApplyPatchInPlace, tryDeserializeDoc, tryDeserializeState, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, validateRgaSeq, vvHasDot, vvMerge };
|
package/dist/internals.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as CreateStateOptions, A as PatchError, At as TombstoneCompactionOptions, B as validateJsonPatch, Bt as VersionVector, C as stringifyJsonPointer, Ct as RgaElem, D as nextDotForActor, Dt as SerializedNode, E as createClock, Et as SerializedDoc, F as forkState, Ft as TryDeserializeDocResult, G as ApplyPatchInPlaceOptions, H as ApplyError, I as toJson, It as TryDeserializeStateResult, J as Clock, K as ApplyPatchOptions, L as tryApplyPatch, Lt as TryMergeDocResult, M as applyPatchAsActor, Mt as TryApplyPatchAsActorResult, N as applyPatchInPlace, Nt as TryApplyPatchInPlaceResult, O as observeDot, Ot as SerializedRgaElem, P as createState, Pt as TryApplyPatchResult, Q as CrdtState, R as tryApplyPatchAsActor, Rt as TryMergeStateResult, S as parseJsonPointer, St as ROOT_KEY, T as cloneClock, Tt as SerializedClock, U as ApplyPatchAsActorOptions, V as ActorId, W as ApplyPatchAsActorResult, X as CompactStateTombstonesResult, Y as CompactDocTombstonesResult, Z as CompilePatchOptions, _ as PatchCompileError, _t as Node, a as MergeError, at as ElemId, b as getAtJson, bt as PatchErrorReason, c as tryMergeDoc, ct as JsonPatch, d as deserializeDoc, dt as JsonPrimitive, et as DeserializeErrorReason, f as deserializeState, ft as JsonValidationMode, g as tryDeserializeState, gt as MergeStateOptions, h as tryDeserializeDoc, ht as MergeDocOptions, i as compactStateTombstones, it as Dot, j as applyPatch, jt as TombstoneCompactionStats, k as JsonValueValidationError, kt as SerializedState, l as tryMergeState, lt as JsonPatchOp, m as serializeState, mt as LwwReg, n as TraversalDepthError, nt as DiffOptions, o as mergeDoc, ot as ForkStateOptions, p as serializeDoc, pt as JsonValue, q as ApplyResult, r as compactDocTombstones, rt as Doc, s as mergeState, st as IntentOp, t as MAX_TRAVERSAL_DEPTH, tt as DeserializeFailure, u as DeserializeError, ut as JsonPatchToCrdtOptions, v as compileJsonPatchToIntent, vt as ObjEntry, w as ClockValidationError, wt as RgaSeq, x as jsonEquals, xt as PatchSemantics, y as diffJsonPatch, yt as ObjNode, z as tryApplyPatchInPlace, zt as ValidatePatchResult } from "./depth-DSl2ghKu.js";
|
|
2
2
|
|
|
3
3
|
//#region src/doc.d.ts
|
|
4
4
|
/**
|
|
@@ -53,10 +53,12 @@ declare const tryJsonPatchToCrdt: typeof jsonPatchToCrdtSafe;
|
|
|
53
53
|
* Generate a JSON Patch delta between two CRDT documents.
|
|
54
54
|
* @param base - The base document snapshot.
|
|
55
55
|
* @param head - The current document state.
|
|
56
|
-
* @param options - Diff options (e.g. `{ arrayStrategy: "lcs" }`).
|
|
56
|
+
* @param options - Diff options (e.g. `{ arrayStrategy: "lcs" }` or `{ arrayStrategy: "lcs-linear" }`).
|
|
57
57
|
* @returns An array of JSON Patch operations that transform base into head.
|
|
58
58
|
*/
|
|
59
59
|
declare function crdtToJsonPatch(base: Doc, head: Doc, options?: DiffOptions): JsonPatchOp[];
|
|
60
|
+
/** Internals-only helper for diffing CRDT nodes from an existing traversal depth. */
|
|
61
|
+
declare function crdtNodesToJsonPatch(baseNode: Node, headNode: Node, options?: DiffOptions, depth?: number): JsonPatchOp[];
|
|
60
62
|
/**
|
|
61
63
|
* Emit a single root `replace` patch representing the full document state.
|
|
62
64
|
* Use `crdtToJsonPatch(base, head)` for delta patches instead.
|
|
@@ -88,9 +90,34 @@ declare function objCompactTombstones(obj: ObjNode, isStable: (dot: Dot) => bool
|
|
|
88
90
|
//#endregion
|
|
89
91
|
//#region src/rga.d.ts
|
|
90
92
|
declare const HEAD: ElemId;
|
|
93
|
+
type RgaValidationIssue = {
|
|
94
|
+
code: "MISSING_PREDECESSOR";
|
|
95
|
+
id: ElemId;
|
|
96
|
+
prev: ElemId;
|
|
97
|
+
message: string;
|
|
98
|
+
} | {
|
|
99
|
+
code: "PREDECESSOR_CYCLE";
|
|
100
|
+
id: ElemId;
|
|
101
|
+
prev: ElemId;
|
|
102
|
+
message: string;
|
|
103
|
+
} | {
|
|
104
|
+
code: "ORPHANED_ELEMENT";
|
|
105
|
+
id: ElemId;
|
|
106
|
+
prev: ElemId;
|
|
107
|
+
message: string;
|
|
108
|
+
};
|
|
109
|
+
type RgaValidationResult = {
|
|
110
|
+
ok: true;
|
|
111
|
+
issues: [];
|
|
112
|
+
} | {
|
|
113
|
+
ok: false;
|
|
114
|
+
issues: RgaValidationIssue[];
|
|
115
|
+
};
|
|
91
116
|
declare function rgaLinearizeIds(seq: RgaSeq): ElemId[];
|
|
92
117
|
declare function rgaInsertAfter(seq: RgaSeq, prev: ElemId, id: ElemId, insDot: Dot, value: Node): void;
|
|
93
|
-
declare function
|
|
118
|
+
declare function rgaInsertAfterChecked(seq: RgaSeq, prev: ElemId, id: ElemId, insDot: Dot, value: Node): void;
|
|
119
|
+
declare function rgaDelete(seq: RgaSeq, id: ElemId, delDot?: Dot): void;
|
|
120
|
+
declare function validateRgaSeq(seq: RgaSeq): RgaValidationResult;
|
|
94
121
|
/**
|
|
95
122
|
* Prune tombstoned elements that are causally stable and have no live descendants
|
|
96
123
|
* depending on them for sequence traversal.
|
|
@@ -101,4 +128,4 @@ declare function rgaCompactTombstones(seq: RgaSeq, isStable: (dot: Dot) => boole
|
|
|
101
128
|
declare function rgaIdAtIndex(seq: RgaSeq, index: number): ElemId | undefined;
|
|
102
129
|
declare function rgaPrevForInsertAtIndex(seq: RgaSeq, index: number): ElemId;
|
|
103
130
|
//#endregion
|
|
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 };
|
|
131
|
+
export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, ClockValidationError, type CompactDocTombstonesResult, type CompactStateTombstonesResult, type CompilePatchOptions, CrdtState, CreateStateOptions, DeserializeError, DeserializeErrorReason, type DeserializeFailure, 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 RgaValidationIssue, type RgaValidationResult, type SerializedClock, type SerializedDoc, type SerializedNode, type SerializedRgaElem, SerializedState, type TombstoneCompactionOptions, type TombstoneCompactionStats, TraversalDepthError, type TryApplyPatchAsActorResult, TryApplyPatchInPlaceResult, TryApplyPatchResult, type TryDeserializeDocResult, TryDeserializeStateResult, type TryMergeDocResult, TryMergeStateResult, ValidatePatchResult, type VersionVector, applyIntentsToCrdt, applyPatch, applyPatchAsActor, applyPatchInPlace, cloneClock, cloneDoc, compactDocTombstones, compactStateTombstones, compareDot, compileJsonPatchToIntent, crdtNodesToJsonPatch, 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, rgaInsertAfterChecked, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchAsActor, tryApplyPatchInPlace, tryDeserializeDoc, tryDeserializeState, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, validateRgaSeq, vvHasDot, vvMerge };
|
package/dist/internals.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_compact = require('./compact-
|
|
2
|
+
const require_compact = require('./compact-BToZE6Q6.js');
|
|
3
3
|
|
|
4
4
|
exports.ClockValidationError = require_compact.ClockValidationError;
|
|
5
5
|
exports.DeserializeError = require_compact.DeserializeError;
|
|
@@ -21,6 +21,7 @@ exports.compactDocTombstones = require_compact.compactDocTombstones;
|
|
|
21
21
|
exports.compactStateTombstones = require_compact.compactStateTombstones;
|
|
22
22
|
exports.compareDot = require_compact.compareDot;
|
|
23
23
|
exports.compileJsonPatchToIntent = require_compact.compileJsonPatchToIntent;
|
|
24
|
+
exports.crdtNodesToJsonPatch = require_compact.crdtNodesToJsonPatch;
|
|
24
25
|
exports.crdtToFullReplace = require_compact.crdtToFullReplace;
|
|
25
26
|
exports.crdtToJsonPatch = require_compact.crdtToJsonPatch;
|
|
26
27
|
exports.createClock = require_compact.createClock;
|
|
@@ -53,6 +54,7 @@ exports.rgaCompactTombstones = require_compact.rgaCompactTombstones;
|
|
|
53
54
|
exports.rgaDelete = require_compact.rgaDelete;
|
|
54
55
|
exports.rgaIdAtIndex = require_compact.rgaIdAtIndex;
|
|
55
56
|
exports.rgaInsertAfter = require_compact.rgaInsertAfter;
|
|
57
|
+
exports.rgaInsertAfterChecked = require_compact.rgaInsertAfterChecked;
|
|
56
58
|
exports.rgaLinearizeIds = require_compact.rgaLinearizeIds;
|
|
57
59
|
exports.rgaPrevForInsertAtIndex = require_compact.rgaPrevForInsertAtIndex;
|
|
58
60
|
exports.serializeDoc = require_compact.serializeDoc;
|
|
@@ -60,10 +62,14 @@ exports.serializeState = require_compact.serializeState;
|
|
|
60
62
|
exports.stringifyJsonPointer = require_compact.stringifyJsonPointer;
|
|
61
63
|
exports.toJson = require_compact.toJson;
|
|
62
64
|
exports.tryApplyPatch = require_compact.tryApplyPatch;
|
|
65
|
+
exports.tryApplyPatchAsActor = require_compact.tryApplyPatchAsActor;
|
|
63
66
|
exports.tryApplyPatchInPlace = require_compact.tryApplyPatchInPlace;
|
|
67
|
+
exports.tryDeserializeDoc = require_compact.tryDeserializeDoc;
|
|
68
|
+
exports.tryDeserializeState = require_compact.tryDeserializeState;
|
|
64
69
|
exports.tryJsonPatchToCrdt = require_compact.tryJsonPatchToCrdt;
|
|
65
70
|
exports.tryMergeDoc = require_compact.tryMergeDoc;
|
|
66
71
|
exports.tryMergeState = require_compact.tryMergeState;
|
|
67
72
|
exports.validateJsonPatch = require_compact.validateJsonPatch;
|
|
73
|
+
exports.validateRgaSeq = require_compact.validateRgaSeq;
|
|
68
74
|
exports.vvHasDot = require_compact.vvHasDot;
|
|
69
75
|
exports.vvMerge = require_compact.vvMerge;
|
package/dist/internals.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { $ as
|
|
1
|
+
import { $ as HEAD, A as crdtToJsonPatch, B as jsonEquals, C as tryApplyPatchAsActor, D as cloneDoc, E as applyIntentsToCrdt, F as tryJsonPatchToCrdt, G as lwwSet, H as stringifyJsonPointer, I as PatchCompileError, J as newSeq, K as newObj, L as compileJsonPatchToIntent, M as docFromJsonWithDot, N as jsonPatchToCrdt, O as crdtNodesToJsonPatch, P as jsonPatchToCrdtSafe, Q as materialize, R as diffJsonPatch, S as tryApplyPatch, T as validateJsonPatch, U as ROOT_KEY, V as parseJsonPointer, W as JsonValueValidationError, X as objRemove, Y as objCompactTombstones, Z as objSet, _ as applyPatchAsActor, _t as nextDotForActor, a as mergeState, at as rgaLinearizeIds, b as forkState, c as DeserializeError, ct as compareDot, d as serializeDoc, dt as vvMerge, et as rgaCompactTombstones, f as serializeState, ft as MAX_TRAVERSAL_DEPTH, g as applyPatch, gt as createClock, h as PatchError, ht as cloneClock, i as mergeDoc, it as rgaInsertAfterChecked, j as docFromJson, k as crdtToFullReplace, l as deserializeDoc, lt as dotToElemId, m as tryDeserializeState, mt as ClockValidationError, n as compactStateTombstones, nt as rgaIdAtIndex, o as tryMergeDoc, ot as rgaPrevForInsertAtIndex, p as tryDeserializeDoc, pt as TraversalDepthError, q as newReg, r as MergeError, rt as rgaInsertAfter, s as tryMergeState, st as validateRgaSeq, t as compactDocTombstones, tt as rgaDelete, u as deserializeState, ut as vvHasDot, v as applyPatchInPlace, vt as observeDot, w as tryApplyPatchInPlace, x as toJson, y as createState, z as getAtJson } from "./compact-BS7F604m.mjs";
|
|
2
2
|
|
|
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 };
|
|
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, crdtNodesToJsonPatch, 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, rgaInsertAfterChecked, rgaLinearizeIds, rgaPrevForInsertAtIndex, serializeDoc, serializeState, stringifyJsonPointer, toJson, tryApplyPatch, tryApplyPatchAsActor, tryApplyPatchInPlace, tryDeserializeDoc, tryDeserializeState, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, validateRgaSeq, vvHasDot, vvMerge };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "json-patch-to-crdt",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Convert JSON Patch (RFC 6902) to and from a CRDT-friendly representation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"crdt",
|
|
@@ -42,6 +42,9 @@
|
|
|
42
42
|
"fmt:check": "oxfmt . --check",
|
|
43
43
|
"typecheck": "tsc --noEmit",
|
|
44
44
|
"build": "tsdown --config tsdown.config.mts",
|
|
45
|
+
"bench:array-diff": "bun run bench/array-diff.microbench.ts",
|
|
46
|
+
"bench:crdt-diff": "bun run bench/crdt-diff.microbench.ts",
|
|
47
|
+
"bench:object-diff": "bun run bench/object-diff.microbench.ts",
|
|
45
48
|
"bench:sequential": "bun run bench/sequential-apply.microbench.ts",
|
|
46
49
|
"test:state-core": "bun test tests/state-core.test.ts",
|
|
47
50
|
"test:patch-diff-doc": "bun test tests/patch-diff-doc.test.ts",
|