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.
- package/README.md +103 -3
- package/dist/{merge-CKcP1ZPt.mjs → compact-BdTuOQK-.mjs} +1191 -268
- package/dist/{merge-BAfuC6bf.js → compact-DoM9CJNR.js} +1244 -267
- package/dist/{merge-B8nmGV-o.d.ts → depth-Dl_yOAKU.d.ts} +153 -7
- package/dist/{merge-DQ_KDtnE.d.mts → depth-IvWvLAkt.d.mts} +153 -7
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +22 -16
- package/dist/index.mjs +2 -2
- package/dist/internals.d.mts +26 -25
- package/dist/internals.d.ts +26 -25
- package/dist/internals.js +67 -58
- package/dist/internals.mjs +2 -2
- package/package.json +12 -2
|
@@ -14,6 +14,13 @@ type JsonPrimitive = null | boolean | number | string;
|
|
|
14
14
|
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
15
15
|
[k: string]: JsonValue;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Runtime handling mode for non-JSON inputs received through `any` / untyped callers.
|
|
19
|
+
* - `"none"`: keep current behavior (no extra runtime guardrails).
|
|
20
|
+
* - `"strict"`: reject invalid values (e.g. `NaN`, `Infinity`, `undefined`).
|
|
21
|
+
* - `"normalize"`: coerce invalid values into JSON-safe output.
|
|
22
|
+
*/
|
|
23
|
+
type JsonValidationMode = "none" | "strict" | "normalize";
|
|
17
24
|
/** Mutable clock that tracks an actor's identity and monotonic counter. */
|
|
18
25
|
type Clock = {
|
|
19
26
|
actor: ActorId;
|
|
@@ -92,6 +99,8 @@ type SerializedState = {
|
|
|
92
99
|
doc: SerializedDoc;
|
|
93
100
|
clock: SerializedClock;
|
|
94
101
|
};
|
|
102
|
+
/** Typed reasons for rejecting malformed serialized CRDT payloads. */
|
|
103
|
+
type DeserializeErrorReason = "INVALID_SERIALIZED_SHAPE" | "INVALID_SERIALIZED_INVARIANT";
|
|
95
104
|
/**
|
|
96
105
|
* Internal intent operations produced by compiling RFC 6902 JSON Patch ops.
|
|
97
106
|
* Each variant maps to a specific CRDT mutation.
|
|
@@ -161,6 +170,16 @@ type CrdtState = {
|
|
|
161
170
|
doc: Doc;
|
|
162
171
|
clock: Clock;
|
|
163
172
|
};
|
|
173
|
+
/** Options for `createState`. */
|
|
174
|
+
interface CreateStateOptions {
|
|
175
|
+
actor: ActorId;
|
|
176
|
+
start?: number;
|
|
177
|
+
/**
|
|
178
|
+
* Runtime guardrails for non-JSON values from untyped callers.
|
|
179
|
+
* Defaults to `"none"` for backward compatibility.
|
|
180
|
+
*/
|
|
181
|
+
jsonValidation?: JsonValidationMode;
|
|
182
|
+
}
|
|
164
183
|
/** Options for `forkState`. */
|
|
165
184
|
interface ForkStateOptions {
|
|
166
185
|
/**
|
|
@@ -179,9 +198,11 @@ type ApplyPatchAsActorOptions = {
|
|
|
179
198
|
base?: Doc;
|
|
180
199
|
testAgainst?: "head" | "base";
|
|
181
200
|
semantics?: PatchSemantics;
|
|
201
|
+
strictParents?: boolean;
|
|
202
|
+
jsonValidation?: JsonValidationMode;
|
|
182
203
|
};
|
|
183
204
|
/** Typed failure reason used across patch/merge helpers. */
|
|
184
|
-
type PatchErrorReason = "INVALID_PATCH" | "INVALID_POINTER" | "MISSING_PARENT" | "MISSING_TARGET" | "INVALID_TARGET" | "OUT_OF_BOUNDS" | "TEST_FAILED" | "INVALID_MOVE" | "LINEAGE_MISMATCH";
|
|
205
|
+
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";
|
|
185
206
|
/** Structured conflict payload used by non-throwing APIs. */
|
|
186
207
|
type ApplyError = {
|
|
187
208
|
ok: false; /** HTTP-friendly status code for conflict-style failures. */
|
|
@@ -211,6 +232,17 @@ type ApplyPatchOptions = {
|
|
|
211
232
|
base?: CrdtState;
|
|
212
233
|
testAgainst?: "head" | "base";
|
|
213
234
|
semantics?: PatchSemantics;
|
|
235
|
+
/**
|
|
236
|
+
* Reject array inserts when the base parent path is missing.
|
|
237
|
+
* Defaults to `false` to preserve legacy behavior that can auto-create
|
|
238
|
+
* missing arrays for index `0` / append intents.
|
|
239
|
+
*/
|
|
240
|
+
strictParents?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Runtime guardrails for patch payload values from untyped callers.
|
|
243
|
+
* Defaults to `"none"` for backward compatibility.
|
|
244
|
+
*/
|
|
245
|
+
jsonValidation?: JsonValidationMode;
|
|
214
246
|
};
|
|
215
247
|
/** Options for in-place patch application (`applyPatchInPlace` / `tryApplyPatchInPlace`). */
|
|
216
248
|
type ApplyPatchInPlaceOptions = ApplyPatchOptions & {
|
|
@@ -275,6 +307,34 @@ type TryMergeStateResult = {
|
|
|
275
307
|
ok: false;
|
|
276
308
|
error: ApplyError;
|
|
277
309
|
};
|
|
310
|
+
/** Options for tombstone compaction helpers. */
|
|
311
|
+
type TombstoneCompactionOptions = {
|
|
312
|
+
/**
|
|
313
|
+
* Causally stable checkpoint. Only tombstones at or below this checkpoint
|
|
314
|
+
* are candidates for pruning.
|
|
315
|
+
*/
|
|
316
|
+
stable: VersionVector;
|
|
317
|
+
/**
|
|
318
|
+
* Mutate the input value in place.
|
|
319
|
+
* Defaults to `false` (immutable output).
|
|
320
|
+
*/
|
|
321
|
+
mutate?: boolean;
|
|
322
|
+
};
|
|
323
|
+
/** Counts emitted by tombstone compaction helpers. */
|
|
324
|
+
type TombstoneCompactionStats = {
|
|
325
|
+
objectTombstonesRemoved: number;
|
|
326
|
+
sequenceTombstonesRemoved: number;
|
|
327
|
+
};
|
|
328
|
+
/** Result for `compactDocTombstones`. */
|
|
329
|
+
type CompactDocTombstonesResult = {
|
|
330
|
+
doc: Doc;
|
|
331
|
+
stats: TombstoneCompactionStats;
|
|
332
|
+
};
|
|
333
|
+
/** Result for `compactStateTombstones`. */
|
|
334
|
+
type CompactStateTombstonesResult = {
|
|
335
|
+
state: CrdtState;
|
|
336
|
+
stats: TombstoneCompactionStats;
|
|
337
|
+
};
|
|
278
338
|
/** Options-object overload shape for low-level JSON Patch -> CRDT conversion. */
|
|
279
339
|
type JsonPatchToCrdtOptions = {
|
|
280
340
|
base: Doc;
|
|
@@ -284,10 +344,28 @@ type JsonPatchToCrdtOptions = {
|
|
|
284
344
|
evalTestAgainst?: "head" | "base";
|
|
285
345
|
bumpCounterAbove?: (ctr: number) => void;
|
|
286
346
|
semantics?: PatchSemantics;
|
|
347
|
+
strictParents?: boolean;
|
|
287
348
|
};
|
|
288
349
|
/** Options for `crdtToJsonPatch` and `diffJsonPatch`. */
|
|
289
350
|
type DiffOptions = {
|
|
351
|
+
/**
|
|
352
|
+
* Array diff mode.
|
|
353
|
+
* - `"lcs"` (default): index-level edits using LCS.
|
|
354
|
+
* - `"atomic"`: one-op root/field replacement for changed arrays.
|
|
355
|
+
*/
|
|
290
356
|
arrayStrategy?: "atomic" | "lcs";
|
|
357
|
+
/**
|
|
358
|
+
* Maximum LCS matrix cells (`(base.length + 1) * (next.length + 1)`) before
|
|
359
|
+
* falling back to atomic replacement. Defaults to `250_000`.
|
|
360
|
+
*
|
|
361
|
+
* Set to `Number.POSITIVE_INFINITY` to always allow LCS.
|
|
362
|
+
*/
|
|
363
|
+
lcsMaxCells?: number;
|
|
364
|
+
/**
|
|
365
|
+
* Runtime guardrails for diff inputs from untyped callers.
|
|
366
|
+
* Defaults to `"none"` for backward compatibility.
|
|
367
|
+
*/
|
|
368
|
+
jsonValidation?: JsonValidationMode;
|
|
291
369
|
};
|
|
292
370
|
/**
|
|
293
371
|
* Internal sentinel key used in `IntentOp` to represent root-level operations.
|
|
@@ -311,10 +389,7 @@ declare class PatchError extends Error {
|
|
|
311
389
|
* @param options - Actor ID and optional starting counter.
|
|
312
390
|
* @returns A new `CrdtState` containing the document and clock.
|
|
313
391
|
*/
|
|
314
|
-
declare function createState(initial: JsonValue, options:
|
|
315
|
-
actor: ActorId;
|
|
316
|
-
start?: number;
|
|
317
|
-
}): CrdtState;
|
|
392
|
+
declare function createState(initial: JsonValue, options: CreateStateOptions): CrdtState;
|
|
318
393
|
/**
|
|
319
394
|
* Fork a replica from a shared origin state while assigning a new local actor ID.
|
|
320
395
|
* The forked state has an independent document clone and clock.
|
|
@@ -359,6 +434,39 @@ declare function validateJsonPatch(base: JsonValue, patch: JsonPatchOp[], option
|
|
|
359
434
|
*/
|
|
360
435
|
declare function applyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): ApplyPatchAsActorResult;
|
|
361
436
|
//#endregion
|
|
437
|
+
//#region src/json-value.d.ts
|
|
438
|
+
/**
|
|
439
|
+
* Runtime validation error for values that are not JSON-compatible.
|
|
440
|
+
* `path` is an RFC 6901 pointer relative to the validated root.
|
|
441
|
+
*/
|
|
442
|
+
declare class JsonValueValidationError extends TypeError {
|
|
443
|
+
readonly path: string;
|
|
444
|
+
readonly detail: string;
|
|
445
|
+
constructor(path: string, detail: string);
|
|
446
|
+
}
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/clock.d.ts
|
|
449
|
+
type ClockValidationErrorReason = "INVALID_ACTOR" | "INVALID_COUNTER";
|
|
450
|
+
declare class ClockValidationError extends TypeError {
|
|
451
|
+
readonly reason: ClockValidationErrorReason;
|
|
452
|
+
constructor(reason: ClockValidationErrorReason, message: string);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
|
|
456
|
+
* @param actor - Unique identifier for this peer.
|
|
457
|
+
* @param start - Initial counter value (defaults to 0).
|
|
458
|
+
*/
|
|
459
|
+
declare function createClock(actor: ActorId, start?: number): Clock;
|
|
460
|
+
/** Create an independent copy of a clock at the same counter position. */
|
|
461
|
+
declare function cloneClock(clock: Clock): Clock;
|
|
462
|
+
/**
|
|
463
|
+
* Generate the next per-actor dot from a mutable version vector.
|
|
464
|
+
* Useful when a server needs to mint dots for many actors.
|
|
465
|
+
*/
|
|
466
|
+
declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
|
|
467
|
+
/** Record an observed dot in a version vector. */
|
|
468
|
+
declare function observeDot(vv: VersionVector, dot: Dot): void;
|
|
469
|
+
//#endregion
|
|
362
470
|
//#region src/patch.d.ts
|
|
363
471
|
/** Structured compile error used to map patch validation failures to typed reasons. */
|
|
364
472
|
declare class PatchCompileError extends Error {
|
|
@@ -403,6 +511,12 @@ declare function diffJsonPatch(base: JsonValue, next: JsonValue, options?: DiffO
|
|
|
403
511
|
declare function jsonEquals(a: JsonValue, b: JsonValue): boolean;
|
|
404
512
|
//#endregion
|
|
405
513
|
//#region src/serialize.d.ts
|
|
514
|
+
declare class DeserializeError extends Error {
|
|
515
|
+
readonly code: 409;
|
|
516
|
+
readonly reason: DeserializeErrorReason;
|
|
517
|
+
readonly path: string;
|
|
518
|
+
constructor(reason: DeserializeErrorReason, path: string, message: string);
|
|
519
|
+
}
|
|
406
520
|
/** Serialize a CRDT document to a JSON-safe representation (Maps become plain objects). */
|
|
407
521
|
declare function serializeDoc(doc: Doc): SerializedDoc;
|
|
408
522
|
/** Reconstruct a CRDT document from its serialized form. */
|
|
@@ -416,7 +530,7 @@ declare function deserializeState(data: SerializedState): CrdtState;
|
|
|
416
530
|
/** Error thrown by throwing merge helpers (`mergeDoc` / `mergeState`). */
|
|
417
531
|
declare class MergeError extends Error {
|
|
418
532
|
readonly code: 409;
|
|
419
|
-
readonly reason:
|
|
533
|
+
readonly reason: PatchErrorReason;
|
|
420
534
|
readonly path?: string;
|
|
421
535
|
constructor(error: ApplyError);
|
|
422
536
|
}
|
|
@@ -451,4 +565,36 @@ declare function mergeState(a: CrdtState, b: CrdtState, options?: MergeStateOpti
|
|
|
451
565
|
/** Non-throwing `mergeState` variant with structured conflict details. */
|
|
452
566
|
declare function tryMergeState(a: CrdtState, b: CrdtState, options?: MergeStateOptions): TryMergeStateResult;
|
|
453
567
|
//#endregion
|
|
454
|
-
|
|
568
|
+
//#region src/compact.d.ts
|
|
569
|
+
/**
|
|
570
|
+
* Compact causally-stable tombstones in a document.
|
|
571
|
+
*
|
|
572
|
+
* Safety note:
|
|
573
|
+
* - Only compact at checkpoints that are causally stable across all peers you
|
|
574
|
+
* may still merge with.
|
|
575
|
+
* - Do not merge this compacted document with replicas that might be behind
|
|
576
|
+
* the provided checkpoint.
|
|
577
|
+
*/
|
|
578
|
+
declare function compactDocTombstones(doc: Doc, options: TombstoneCompactionOptions): CompactDocTombstonesResult;
|
|
579
|
+
/**
|
|
580
|
+
* Compact causally-stable tombstones in a state document.
|
|
581
|
+
*
|
|
582
|
+
* Safety note:
|
|
583
|
+
* - Only compact at checkpoints that are causally stable across all peers you
|
|
584
|
+
* may still merge with.
|
|
585
|
+
* - Do not merge this compacted state with replicas that might be behind the
|
|
586
|
+
* provided checkpoint.
|
|
587
|
+
*/
|
|
588
|
+
declare function compactStateTombstones(state: CrdtState, options: TombstoneCompactionOptions): CompactStateTombstonesResult;
|
|
589
|
+
//#endregion
|
|
590
|
+
//#region src/depth.d.ts
|
|
591
|
+
declare const MAX_TRAVERSAL_DEPTH = 16384;
|
|
592
|
+
declare class TraversalDepthError extends Error {
|
|
593
|
+
readonly code: 409;
|
|
594
|
+
readonly reason: "MAX_DEPTH_EXCEEDED";
|
|
595
|
+
readonly depth: number;
|
|
596
|
+
readonly maxDepth: number;
|
|
597
|
+
constructor(depth: number, maxDepth?: number);
|
|
598
|
+
}
|
|
599
|
+
//#endregion
|
|
600
|
+
export { Doc as $, applyPatchAsActor as A, TryMergeDocResult as At, ApplyPatchAsActorOptions as B, cloneClock as C, SerializedNode as Ct, JsonValueValidationError as D, TombstoneCompactionStats as Dt, observeDot as E, TombstoneCompactionOptions as Et, tryApplyPatch as F, Clock as G, ApplyPatchInPlaceOptions as H, tryApplyPatchInPlace as I, CompilePatchOptions as J, CompactDocTombstonesResult as K, validateJsonPatch as L, createState as M, ValidatePatchResult as Mt, forkState as N, VersionVector as Nt, PatchError as O, TryApplyPatchInPlaceResult as Ot, toJson as P, DiffOptions as Q, ActorId as R, ClockValidationError as S, SerializedDoc as St, nextDotForActor as T, SerializedState as Tt, ApplyPatchOptions as U, ApplyPatchAsActorResult as V, ApplyResult as W, CreateStateOptions as X, CrdtState as Y, DeserializeErrorReason as Z, diffJsonPatch as _, PatchSemantics as _t, MergeError as a, JsonPatchOp as at, parseJsonPointer as b, RgaSeq as bt, tryMergeDoc as c, JsonValidationMode as ct, deserializeDoc as d, MergeDocOptions as dt, Dot as et, deserializeState as f, MergeStateOptions as ft, compileJsonPatchToIntent as g, PatchErrorReason as gt, PatchCompileError as h, ObjNode as ht, compactStateTombstones as i, JsonPatch as it, applyPatchInPlace as j, TryMergeStateResult as jt, applyPatch as k, TryApplyPatchResult as kt, tryMergeState as l, JsonValue as lt, serializeState as m, ObjEntry as mt, TraversalDepthError as n, ForkStateOptions as nt, mergeDoc as o, JsonPatchToCrdtOptions as ot, serializeDoc as p, Node as pt, CompactStateTombstonesResult as q, compactDocTombstones as r, IntentOp as rt, mergeState as s, JsonPrimitive as st, MAX_TRAVERSAL_DEPTH as t, ElemId as tt, DeserializeError as u, LwwReg as ut, getAtJson as v, ROOT_KEY as vt, createClock as w, SerializedRgaElem as wt, stringifyJsonPointer as x, SerializedClock as xt, jsonEquals as y, RgaElem as yt, ApplyError as z };
|
|
@@ -14,6 +14,13 @@ type JsonPrimitive = null | boolean | number | string;
|
|
|
14
14
|
type JsonValue = JsonPrimitive | JsonValue[] | {
|
|
15
15
|
[k: string]: JsonValue;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Runtime handling mode for non-JSON inputs received through `any` / untyped callers.
|
|
19
|
+
* - `"none"`: keep current behavior (no extra runtime guardrails).
|
|
20
|
+
* - `"strict"`: reject invalid values (e.g. `NaN`, `Infinity`, `undefined`).
|
|
21
|
+
* - `"normalize"`: coerce invalid values into JSON-safe output.
|
|
22
|
+
*/
|
|
23
|
+
type JsonValidationMode = "none" | "strict" | "normalize";
|
|
17
24
|
/** Mutable clock that tracks an actor's identity and monotonic counter. */
|
|
18
25
|
type Clock = {
|
|
19
26
|
actor: ActorId;
|
|
@@ -92,6 +99,8 @@ type SerializedState = {
|
|
|
92
99
|
doc: SerializedDoc;
|
|
93
100
|
clock: SerializedClock;
|
|
94
101
|
};
|
|
102
|
+
/** Typed reasons for rejecting malformed serialized CRDT payloads. */
|
|
103
|
+
type DeserializeErrorReason = "INVALID_SERIALIZED_SHAPE" | "INVALID_SERIALIZED_INVARIANT";
|
|
95
104
|
/**
|
|
96
105
|
* Internal intent operations produced by compiling RFC 6902 JSON Patch ops.
|
|
97
106
|
* Each variant maps to a specific CRDT mutation.
|
|
@@ -161,6 +170,16 @@ type CrdtState = {
|
|
|
161
170
|
doc: Doc;
|
|
162
171
|
clock: Clock;
|
|
163
172
|
};
|
|
173
|
+
/** Options for `createState`. */
|
|
174
|
+
interface CreateStateOptions {
|
|
175
|
+
actor: ActorId;
|
|
176
|
+
start?: number;
|
|
177
|
+
/**
|
|
178
|
+
* Runtime guardrails for non-JSON values from untyped callers.
|
|
179
|
+
* Defaults to `"none"` for backward compatibility.
|
|
180
|
+
*/
|
|
181
|
+
jsonValidation?: JsonValidationMode;
|
|
182
|
+
}
|
|
164
183
|
/** Options for `forkState`. */
|
|
165
184
|
interface ForkStateOptions {
|
|
166
185
|
/**
|
|
@@ -179,9 +198,11 @@ type ApplyPatchAsActorOptions = {
|
|
|
179
198
|
base?: Doc;
|
|
180
199
|
testAgainst?: "head" | "base";
|
|
181
200
|
semantics?: PatchSemantics;
|
|
201
|
+
strictParents?: boolean;
|
|
202
|
+
jsonValidation?: JsonValidationMode;
|
|
182
203
|
};
|
|
183
204
|
/** Typed failure reason used across patch/merge helpers. */
|
|
184
|
-
type PatchErrorReason = "INVALID_PATCH" | "INVALID_POINTER" | "MISSING_PARENT" | "MISSING_TARGET" | "INVALID_TARGET" | "OUT_OF_BOUNDS" | "TEST_FAILED" | "INVALID_MOVE" | "LINEAGE_MISMATCH";
|
|
205
|
+
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";
|
|
185
206
|
/** Structured conflict payload used by non-throwing APIs. */
|
|
186
207
|
type ApplyError = {
|
|
187
208
|
ok: false; /** HTTP-friendly status code for conflict-style failures. */
|
|
@@ -211,6 +232,17 @@ type ApplyPatchOptions = {
|
|
|
211
232
|
base?: CrdtState;
|
|
212
233
|
testAgainst?: "head" | "base";
|
|
213
234
|
semantics?: PatchSemantics;
|
|
235
|
+
/**
|
|
236
|
+
* Reject array inserts when the base parent path is missing.
|
|
237
|
+
* Defaults to `false` to preserve legacy behavior that can auto-create
|
|
238
|
+
* missing arrays for index `0` / append intents.
|
|
239
|
+
*/
|
|
240
|
+
strictParents?: boolean;
|
|
241
|
+
/**
|
|
242
|
+
* Runtime guardrails for patch payload values from untyped callers.
|
|
243
|
+
* Defaults to `"none"` for backward compatibility.
|
|
244
|
+
*/
|
|
245
|
+
jsonValidation?: JsonValidationMode;
|
|
214
246
|
};
|
|
215
247
|
/** Options for in-place patch application (`applyPatchInPlace` / `tryApplyPatchInPlace`). */
|
|
216
248
|
type ApplyPatchInPlaceOptions = ApplyPatchOptions & {
|
|
@@ -275,6 +307,34 @@ type TryMergeStateResult = {
|
|
|
275
307
|
ok: false;
|
|
276
308
|
error: ApplyError;
|
|
277
309
|
};
|
|
310
|
+
/** Options for tombstone compaction helpers. */
|
|
311
|
+
type TombstoneCompactionOptions = {
|
|
312
|
+
/**
|
|
313
|
+
* Causally stable checkpoint. Only tombstones at or below this checkpoint
|
|
314
|
+
* are candidates for pruning.
|
|
315
|
+
*/
|
|
316
|
+
stable: VersionVector;
|
|
317
|
+
/**
|
|
318
|
+
* Mutate the input value in place.
|
|
319
|
+
* Defaults to `false` (immutable output).
|
|
320
|
+
*/
|
|
321
|
+
mutate?: boolean;
|
|
322
|
+
};
|
|
323
|
+
/** Counts emitted by tombstone compaction helpers. */
|
|
324
|
+
type TombstoneCompactionStats = {
|
|
325
|
+
objectTombstonesRemoved: number;
|
|
326
|
+
sequenceTombstonesRemoved: number;
|
|
327
|
+
};
|
|
328
|
+
/** Result for `compactDocTombstones`. */
|
|
329
|
+
type CompactDocTombstonesResult = {
|
|
330
|
+
doc: Doc;
|
|
331
|
+
stats: TombstoneCompactionStats;
|
|
332
|
+
};
|
|
333
|
+
/** Result for `compactStateTombstones`. */
|
|
334
|
+
type CompactStateTombstonesResult = {
|
|
335
|
+
state: CrdtState;
|
|
336
|
+
stats: TombstoneCompactionStats;
|
|
337
|
+
};
|
|
278
338
|
/** Options-object overload shape for low-level JSON Patch -> CRDT conversion. */
|
|
279
339
|
type JsonPatchToCrdtOptions = {
|
|
280
340
|
base: Doc;
|
|
@@ -284,10 +344,28 @@ type JsonPatchToCrdtOptions = {
|
|
|
284
344
|
evalTestAgainst?: "head" | "base";
|
|
285
345
|
bumpCounterAbove?: (ctr: number) => void;
|
|
286
346
|
semantics?: PatchSemantics;
|
|
347
|
+
strictParents?: boolean;
|
|
287
348
|
};
|
|
288
349
|
/** Options for `crdtToJsonPatch` and `diffJsonPatch`. */
|
|
289
350
|
type DiffOptions = {
|
|
351
|
+
/**
|
|
352
|
+
* Array diff mode.
|
|
353
|
+
* - `"lcs"` (default): index-level edits using LCS.
|
|
354
|
+
* - `"atomic"`: one-op root/field replacement for changed arrays.
|
|
355
|
+
*/
|
|
290
356
|
arrayStrategy?: "atomic" | "lcs";
|
|
357
|
+
/**
|
|
358
|
+
* Maximum LCS matrix cells (`(base.length + 1) * (next.length + 1)`) before
|
|
359
|
+
* falling back to atomic replacement. Defaults to `250_000`.
|
|
360
|
+
*
|
|
361
|
+
* Set to `Number.POSITIVE_INFINITY` to always allow LCS.
|
|
362
|
+
*/
|
|
363
|
+
lcsMaxCells?: number;
|
|
364
|
+
/**
|
|
365
|
+
* Runtime guardrails for diff inputs from untyped callers.
|
|
366
|
+
* Defaults to `"none"` for backward compatibility.
|
|
367
|
+
*/
|
|
368
|
+
jsonValidation?: JsonValidationMode;
|
|
291
369
|
};
|
|
292
370
|
/**
|
|
293
371
|
* Internal sentinel key used in `IntentOp` to represent root-level operations.
|
|
@@ -311,10 +389,7 @@ declare class PatchError extends Error {
|
|
|
311
389
|
* @param options - Actor ID and optional starting counter.
|
|
312
390
|
* @returns A new `CrdtState` containing the document and clock.
|
|
313
391
|
*/
|
|
314
|
-
declare function createState(initial: JsonValue, options:
|
|
315
|
-
actor: ActorId;
|
|
316
|
-
start?: number;
|
|
317
|
-
}): CrdtState;
|
|
392
|
+
declare function createState(initial: JsonValue, options: CreateStateOptions): CrdtState;
|
|
318
393
|
/**
|
|
319
394
|
* Fork a replica from a shared origin state while assigning a new local actor ID.
|
|
320
395
|
* The forked state has an independent document clone and clock.
|
|
@@ -359,6 +434,39 @@ declare function validateJsonPatch(base: JsonValue, patch: JsonPatchOp[], option
|
|
|
359
434
|
*/
|
|
360
435
|
declare function applyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): ApplyPatchAsActorResult;
|
|
361
436
|
//#endregion
|
|
437
|
+
//#region src/json-value.d.ts
|
|
438
|
+
/**
|
|
439
|
+
* Runtime validation error for values that are not JSON-compatible.
|
|
440
|
+
* `path` is an RFC 6901 pointer relative to the validated root.
|
|
441
|
+
*/
|
|
442
|
+
declare class JsonValueValidationError extends TypeError {
|
|
443
|
+
readonly path: string;
|
|
444
|
+
readonly detail: string;
|
|
445
|
+
constructor(path: string, detail: string);
|
|
446
|
+
}
|
|
447
|
+
//#endregion
|
|
448
|
+
//#region src/clock.d.ts
|
|
449
|
+
type ClockValidationErrorReason = "INVALID_ACTOR" | "INVALID_COUNTER";
|
|
450
|
+
declare class ClockValidationError extends TypeError {
|
|
451
|
+
readonly reason: ClockValidationErrorReason;
|
|
452
|
+
constructor(reason: ClockValidationErrorReason, message: string);
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
|
|
456
|
+
* @param actor - Unique identifier for this peer.
|
|
457
|
+
* @param start - Initial counter value (defaults to 0).
|
|
458
|
+
*/
|
|
459
|
+
declare function createClock(actor: ActorId, start?: number): Clock;
|
|
460
|
+
/** Create an independent copy of a clock at the same counter position. */
|
|
461
|
+
declare function cloneClock(clock: Clock): Clock;
|
|
462
|
+
/**
|
|
463
|
+
* Generate the next per-actor dot from a mutable version vector.
|
|
464
|
+
* Useful when a server needs to mint dots for many actors.
|
|
465
|
+
*/
|
|
466
|
+
declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
|
|
467
|
+
/** Record an observed dot in a version vector. */
|
|
468
|
+
declare function observeDot(vv: VersionVector, dot: Dot): void;
|
|
469
|
+
//#endregion
|
|
362
470
|
//#region src/patch.d.ts
|
|
363
471
|
/** Structured compile error used to map patch validation failures to typed reasons. */
|
|
364
472
|
declare class PatchCompileError extends Error {
|
|
@@ -403,6 +511,12 @@ declare function diffJsonPatch(base: JsonValue, next: JsonValue, options?: DiffO
|
|
|
403
511
|
declare function jsonEquals(a: JsonValue, b: JsonValue): boolean;
|
|
404
512
|
//#endregion
|
|
405
513
|
//#region src/serialize.d.ts
|
|
514
|
+
declare class DeserializeError extends Error {
|
|
515
|
+
readonly code: 409;
|
|
516
|
+
readonly reason: DeserializeErrorReason;
|
|
517
|
+
readonly path: string;
|
|
518
|
+
constructor(reason: DeserializeErrorReason, path: string, message: string);
|
|
519
|
+
}
|
|
406
520
|
/** Serialize a CRDT document to a JSON-safe representation (Maps become plain objects). */
|
|
407
521
|
declare function serializeDoc(doc: Doc): SerializedDoc;
|
|
408
522
|
/** Reconstruct a CRDT document from its serialized form. */
|
|
@@ -416,7 +530,7 @@ declare function deserializeState(data: SerializedState): CrdtState;
|
|
|
416
530
|
/** Error thrown by throwing merge helpers (`mergeDoc` / `mergeState`). */
|
|
417
531
|
declare class MergeError extends Error {
|
|
418
532
|
readonly code: 409;
|
|
419
|
-
readonly reason:
|
|
533
|
+
readonly reason: PatchErrorReason;
|
|
420
534
|
readonly path?: string;
|
|
421
535
|
constructor(error: ApplyError);
|
|
422
536
|
}
|
|
@@ -451,4 +565,36 @@ declare function mergeState(a: CrdtState, b: CrdtState, options?: MergeStateOpti
|
|
|
451
565
|
/** Non-throwing `mergeState` variant with structured conflict details. */
|
|
452
566
|
declare function tryMergeState(a: CrdtState, b: CrdtState, options?: MergeStateOptions): TryMergeStateResult;
|
|
453
567
|
//#endregion
|
|
454
|
-
|
|
568
|
+
//#region src/compact.d.ts
|
|
569
|
+
/**
|
|
570
|
+
* Compact causally-stable tombstones in a document.
|
|
571
|
+
*
|
|
572
|
+
* Safety note:
|
|
573
|
+
* - Only compact at checkpoints that are causally stable across all peers you
|
|
574
|
+
* may still merge with.
|
|
575
|
+
* - Do not merge this compacted document with replicas that might be behind
|
|
576
|
+
* the provided checkpoint.
|
|
577
|
+
*/
|
|
578
|
+
declare function compactDocTombstones(doc: Doc, options: TombstoneCompactionOptions): CompactDocTombstonesResult;
|
|
579
|
+
/**
|
|
580
|
+
* Compact causally-stable tombstones in a state document.
|
|
581
|
+
*
|
|
582
|
+
* Safety note:
|
|
583
|
+
* - Only compact at checkpoints that are causally stable across all peers you
|
|
584
|
+
* may still merge with.
|
|
585
|
+
* - Do not merge this compacted state with replicas that might be behind the
|
|
586
|
+
* provided checkpoint.
|
|
587
|
+
*/
|
|
588
|
+
declare function compactStateTombstones(state: CrdtState, options: TombstoneCompactionOptions): CompactStateTombstonesResult;
|
|
589
|
+
//#endregion
|
|
590
|
+
//#region src/depth.d.ts
|
|
591
|
+
declare const MAX_TRAVERSAL_DEPTH = 16384;
|
|
592
|
+
declare class TraversalDepthError extends Error {
|
|
593
|
+
readonly code: 409;
|
|
594
|
+
readonly reason: "MAX_DEPTH_EXCEEDED";
|
|
595
|
+
readonly depth: number;
|
|
596
|
+
readonly maxDepth: number;
|
|
597
|
+
constructor(depth: number, maxDepth?: number);
|
|
598
|
+
}
|
|
599
|
+
//#endregion
|
|
600
|
+
export { Doc as $, applyPatchAsActor as A, TryMergeDocResult as At, ApplyPatchAsActorOptions as B, cloneClock as C, SerializedNode as Ct, JsonValueValidationError as D, TombstoneCompactionStats as Dt, observeDot as E, TombstoneCompactionOptions as Et, tryApplyPatch as F, Clock as G, ApplyPatchInPlaceOptions as H, tryApplyPatchInPlace as I, CompilePatchOptions as J, CompactDocTombstonesResult as K, validateJsonPatch as L, createState as M, ValidatePatchResult as Mt, forkState as N, VersionVector as Nt, PatchError as O, TryApplyPatchInPlaceResult as Ot, toJson as P, DiffOptions as Q, ActorId as R, ClockValidationError as S, SerializedDoc as St, nextDotForActor as T, SerializedState as Tt, ApplyPatchOptions as U, ApplyPatchAsActorResult as V, ApplyResult as W, CreateStateOptions as X, CrdtState as Y, DeserializeErrorReason as Z, diffJsonPatch as _, PatchSemantics as _t, MergeError as a, JsonPatchOp as at, parseJsonPointer as b, RgaSeq as bt, tryMergeDoc as c, JsonValidationMode as ct, deserializeDoc as d, MergeDocOptions as dt, Dot as et, deserializeState as f, MergeStateOptions as ft, compileJsonPatchToIntent as g, PatchErrorReason as gt, PatchCompileError as h, ObjNode as ht, compactStateTombstones as i, JsonPatch as it, applyPatchInPlace as j, TryMergeStateResult as jt, applyPatch as k, TryApplyPatchResult as kt, tryMergeState as l, JsonValue as lt, serializeState as m, ObjEntry as mt, TraversalDepthError as n, ForkStateOptions as nt, mergeDoc as o, JsonPatchToCrdtOptions as ot, serializeDoc as p, Node as pt, CompactStateTombstonesResult as q, compactDocTombstones as r, IntentOp as rt, mergeState as s, JsonPrimitive as st, MAX_TRAVERSAL_DEPTH as t, ElemId as tt, DeserializeError as u, LwwReg as ut, getAtJson as v, ROOT_KEY as vt, createClock as w, SerializedRgaElem as wt, stringifyJsonPointer as x, SerializedClock as xt, jsonEquals as y, RgaElem as yt, ApplyError as z };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, type CrdtState, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValue, MergeError, type MergeStateOptions, PatchError, type PatchErrorReason, type PatchSemantics, type SerializedState, type TryApplyPatchInPlaceResult, type TryApplyPatchResult, type TryMergeStateResult, type ValidatePatchResult, applyPatch, applyPatchInPlace, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryMergeState, validateJsonPatch };
|
|
1
|
+
import { D as JsonValueValidationError, Dt as TombstoneCompactionStats, Et as TombstoneCompactionOptions, F as tryApplyPatch, H as ApplyPatchInPlaceOptions, I as tryApplyPatchInPlace, L as validateJsonPatch, M as createState, Mt as ValidatePatchResult, N as forkState, O as PatchError, Ot as TryApplyPatchInPlaceResult, P as toJson, Q as DiffOptions, R as ActorId, S as ClockValidationError, Tt as SerializedState, U as ApplyPatchOptions, X as CreateStateOptions, Y as CrdtState, Z as DeserializeErrorReason, _ as diffJsonPatch, _t as PatchSemantics, a as MergeError, at as JsonPatchOp, ct as JsonValidationMode, f as deserializeState, ft as MergeStateOptions, gt as PatchErrorReason, 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, n as TraversalDepthError, nt as ForkStateOptions, q as CompactStateTombstonesResult, s as mergeState, st as JsonPrimitive, t as MAX_TRAVERSAL_DEPTH, u as DeserializeError, z as ApplyError } from "./depth-IvWvLAkt.mjs";
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, type CrdtState, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValue, MergeError, type MergeStateOptions, PatchError, type PatchErrorReason, type PatchSemantics, type SerializedState, type TryApplyPatchInPlaceResult, type TryApplyPatchResult, type TryMergeStateResult, type ValidatePatchResult, applyPatch, applyPatchInPlace, createState, deserializeState, diffJsonPatch, forkState, mergeState, serializeState, toJson, tryApplyPatch, tryApplyPatchInPlace, tryMergeState, validateJsonPatch };
|
|
1
|
+
import { D as JsonValueValidationError, Dt as TombstoneCompactionStats, Et as TombstoneCompactionOptions, F as tryApplyPatch, H as ApplyPatchInPlaceOptions, I as tryApplyPatchInPlace, L as validateJsonPatch, M as createState, Mt as ValidatePatchResult, N as forkState, O as PatchError, Ot as TryApplyPatchInPlaceResult, P as toJson, Q as DiffOptions, R as ActorId, S as ClockValidationError, Tt as SerializedState, U as ApplyPatchOptions, X as CreateStateOptions, Y as CrdtState, Z as DeserializeErrorReason, _ as diffJsonPatch, _t as PatchSemantics, a as MergeError, at as JsonPatchOp, ct as JsonValidationMode, f as deserializeState, ft as MergeStateOptions, gt as PatchErrorReason, 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, n as TraversalDepthError, nt as ForkStateOptions, q as CompactStateTombstonesResult, s as mergeState, st as JsonPrimitive, t as MAX_TRAVERSAL_DEPTH, u as DeserializeError, z as ApplyError } from "./depth-Dl_yOAKU.js";
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
2
|
+
const require_compact = require('./compact-DoM9CJNR.js');
|
|
3
3
|
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
6
|
-
exports.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
exports.
|
|
11
|
-
exports.
|
|
12
|
-
exports.
|
|
13
|
-
exports.
|
|
14
|
-
exports.
|
|
15
|
-
exports.
|
|
16
|
-
exports.
|
|
17
|
-
exports.
|
|
18
|
-
exports.
|
|
4
|
+
exports.ClockValidationError = require_compact.ClockValidationError;
|
|
5
|
+
exports.DeserializeError = require_compact.DeserializeError;
|
|
6
|
+
exports.JsonValueValidationError = require_compact.JsonValueValidationError;
|
|
7
|
+
exports.MAX_TRAVERSAL_DEPTH = require_compact.MAX_TRAVERSAL_DEPTH;
|
|
8
|
+
exports.MergeError = require_compact.MergeError;
|
|
9
|
+
exports.PatchError = require_compact.PatchError;
|
|
10
|
+
exports.TraversalDepthError = require_compact.TraversalDepthError;
|
|
11
|
+
exports.applyPatch = require_compact.applyPatch;
|
|
12
|
+
exports.applyPatchInPlace = require_compact.applyPatchInPlace;
|
|
13
|
+
exports.compactStateTombstones = require_compact.compactStateTombstones;
|
|
14
|
+
exports.createState = require_compact.createState;
|
|
15
|
+
exports.deserializeState = require_compact.deserializeState;
|
|
16
|
+
exports.diffJsonPatch = require_compact.diffJsonPatch;
|
|
17
|
+
exports.forkState = require_compact.forkState;
|
|
18
|
+
exports.mergeState = require_compact.mergeState;
|
|
19
|
+
exports.serializeState = require_compact.serializeState;
|
|
20
|
+
exports.toJson = require_compact.toJson;
|
|
21
|
+
exports.tryApplyPatch = require_compact.tryApplyPatch;
|
|
22
|
+
exports.tryApplyPatchInPlace = require_compact.tryApplyPatchInPlace;
|
|
23
|
+
exports.tryMergeState = require_compact.tryMergeState;
|
|
24
|
+
exports.validateJsonPatch = require_compact.validateJsonPatch;
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { _ as
|
|
1
|
+
import { B as JsonValueValidationError, P as diffJsonPatch, S as validateJsonPatch, _ as createState, a as mergeState, b as tryApplyPatch, c as DeserializeError, ct as ClockValidationError, f as serializeState, g as applyPatchInPlace, m as applyPatch, n as compactStateTombstones, ot as MAX_TRAVERSAL_DEPTH, p as PatchError, r as MergeError, s as tryMergeState, st as TraversalDepthError, u as deserializeState, v as forkState, x as tryApplyPatchInPlace, y as toJson } from "./compact-BdTuOQK-.mjs";
|
|
2
2
|
|
|
3
|
-
export { MergeError, PatchError, applyPatch, applyPatchInPlace, 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, tryMergeState, validateJsonPatch };
|