json-patch-to-crdt 0.1.2 → 0.2.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.
@@ -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;
@@ -94,6 +101,19 @@ type SerializedState = {
94
101
  };
95
102
  /** Typed reasons for rejecting malformed serialized CRDT payloads. */
96
103
  type DeserializeErrorReason = "INVALID_SERIALIZED_SHAPE" | "INVALID_SERIALIZED_INVARIANT";
104
+ /** Structured failure payload used by non-throwing deserialize helpers. */
105
+ type DeserializeFailure = {
106
+ code: 409;
107
+ reason: DeserializeErrorReason;
108
+ path: string;
109
+ message: string;
110
+ } | {
111
+ code: 409;
112
+ reason: "MAX_DEPTH_EXCEEDED";
113
+ message: string;
114
+ depth: number;
115
+ maxDepth: number;
116
+ };
97
117
  /**
98
118
  * Internal intent operations produced by compiling RFC 6902 JSON Patch ops.
99
119
  * Each variant maps to a specific CRDT mutation.
@@ -163,6 +183,16 @@ type CrdtState = {
163
183
  doc: Doc;
164
184
  clock: Clock;
165
185
  };
186
+ /** Options for `createState`. */
187
+ interface CreateStateOptions {
188
+ actor: ActorId;
189
+ start?: number;
190
+ /**
191
+ * Runtime guardrails for non-JSON values from untyped callers.
192
+ * Defaults to `"none"` for backward compatibility.
193
+ */
194
+ jsonValidation?: JsonValidationMode;
195
+ }
166
196
  /** Options for `forkState`. */
167
197
  interface ForkStateOptions {
168
198
  /**
@@ -181,6 +211,15 @@ type ApplyPatchAsActorOptions = {
181
211
  base?: Doc;
182
212
  testAgainst?: "head" | "base";
183
213
  semantics?: PatchSemantics;
214
+ strictParents?: boolean;
215
+ jsonValidation?: JsonValidationMode;
216
+ };
217
+ /** Non-throwing result for internals-only `tryApplyPatchAsActor`. */
218
+ type TryApplyPatchAsActorResult = ({
219
+ ok: true;
220
+ } & ApplyPatchAsActorResult) | {
221
+ ok: false;
222
+ error: ApplyError;
184
223
  };
185
224
  /** Typed failure reason used across patch/merge helpers. */
186
225
  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";
@@ -197,6 +236,22 @@ type ApplyError = {
197
236
  type ApplyResult = {
198
237
  ok: true;
199
238
  } | ApplyError;
239
+ /** Non-throwing result for `deserializeDoc`. */
240
+ type TryDeserializeDocResult = {
241
+ ok: true;
242
+ doc: Doc;
243
+ } | {
244
+ ok: false;
245
+ error: DeserializeFailure;
246
+ };
247
+ /** Non-throwing result for `deserializeState`. */
248
+ type TryDeserializeStateResult = {
249
+ ok: true;
250
+ state: CrdtState;
251
+ } | {
252
+ ok: false;
253
+ error: DeserializeFailure;
254
+ };
200
255
  /** How JSON Patch operations are interpreted during application. */
201
256
  type PatchSemantics = "base" | "sequential";
202
257
  /** Options for compile/validation helpers. */
@@ -213,6 +268,17 @@ type ApplyPatchOptions = {
213
268
  base?: CrdtState;
214
269
  testAgainst?: "head" | "base";
215
270
  semantics?: PatchSemantics;
271
+ /**
272
+ * Reject array inserts when the base parent path is missing.
273
+ * Defaults to `false` to preserve legacy behavior that can auto-create
274
+ * missing arrays for index `0` / append intents.
275
+ */
276
+ strictParents?: boolean;
277
+ /**
278
+ * Runtime guardrails for patch payload values from untyped callers.
279
+ * Defaults to `"none"` for backward compatibility.
280
+ */
281
+ jsonValidation?: JsonValidationMode;
216
282
  };
217
283
  /** Options for in-place patch application (`applyPatchInPlace` / `tryApplyPatchInPlace`). */
218
284
  type ApplyPatchInPlaceOptions = ApplyPatchOptions & {
@@ -314,6 +380,7 @@ type JsonPatchToCrdtOptions = {
314
380
  evalTestAgainst?: "head" | "base";
315
381
  bumpCounterAbove?: (ctr: number) => void;
316
382
  semantics?: PatchSemantics;
383
+ strictParents?: boolean;
317
384
  };
318
385
  /** Options for `crdtToJsonPatch` and `diffJsonPatch`. */
319
386
  type DiffOptions = {
@@ -330,6 +397,11 @@ type DiffOptions = {
330
397
  * Set to `Number.POSITIVE_INFINITY` to always allow LCS.
331
398
  */
332
399
  lcsMaxCells?: number;
400
+ /**
401
+ * Runtime guardrails for diff inputs from untyped callers.
402
+ * Defaults to `"none"` for backward compatibility.
403
+ */
404
+ jsonValidation?: JsonValidationMode;
333
405
  };
334
406
  /**
335
407
  * Internal sentinel key used in `IntentOp` to represent root-level operations.
@@ -353,10 +425,7 @@ declare class PatchError extends Error {
353
425
  * @param options - Actor ID and optional starting counter.
354
426
  * @returns A new `CrdtState` containing the document and clock.
355
427
  */
356
- declare function createState(initial: JsonValue, options: {
357
- actor: ActorId;
358
- start?: number;
359
- }): CrdtState;
428
+ declare function createState(initial: JsonValue, options: CreateStateOptions): CrdtState;
360
429
  /**
361
430
  * Fork a replica from a shared origin state while assigning a new local actor ID.
362
431
  * The forked state has an independent document clone and clock.
@@ -400,6 +469,41 @@ declare function validateJsonPatch(base: JsonValue, patch: JsonPatchOp[], option
400
469
  * Returns the updated state and a new version vector snapshot.
401
470
  */
402
471
  declare function applyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): ApplyPatchAsActorResult;
472
+ /** Non-throwing `applyPatchAsActor` variant for internals sync flows. */
473
+ declare function tryApplyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): TryApplyPatchAsActorResult;
474
+ //#endregion
475
+ //#region src/json-value.d.ts
476
+ /**
477
+ * Runtime validation error for values that are not JSON-compatible.
478
+ * `path` is an RFC 6901 pointer relative to the validated root.
479
+ */
480
+ declare class JsonValueValidationError extends TypeError {
481
+ readonly path: string;
482
+ readonly detail: string;
483
+ constructor(path: string, detail: string);
484
+ }
485
+ //#endregion
486
+ //#region src/clock.d.ts
487
+ type ClockValidationErrorReason = "INVALID_ACTOR" | "INVALID_COUNTER";
488
+ declare class ClockValidationError extends TypeError {
489
+ readonly reason: ClockValidationErrorReason;
490
+ constructor(reason: ClockValidationErrorReason, message: string);
491
+ }
492
+ /**
493
+ * Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
494
+ * @param actor - Unique identifier for this peer.
495
+ * @param start - Initial counter value (defaults to 0).
496
+ */
497
+ declare function createClock(actor: ActorId, start?: number): Clock;
498
+ /** Create an independent copy of a clock at the same counter position. */
499
+ declare function cloneClock(clock: Clock): Clock;
500
+ /**
501
+ * Generate the next per-actor dot from a mutable version vector.
502
+ * Useful when a server needs to mint dots for many actors.
503
+ */
504
+ declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
505
+ /** Record an observed dot in a version vector. */
506
+ declare function observeDot(vv: VersionVector, dot: Dot): void;
403
507
  //#endregion
404
508
  //#region src/patch.d.ts
405
509
  /** Structured compile error used to map patch validation failures to typed reasons. */
@@ -455,10 +559,14 @@ declare class DeserializeError extends Error {
455
559
  declare function serializeDoc(doc: Doc): SerializedDoc;
456
560
  /** Reconstruct a CRDT document from its serialized form. */
457
561
  declare function deserializeDoc(data: SerializedDoc): Doc;
562
+ /** Non-throwing `deserializeDoc` variant with typed validation details. */
563
+ declare function tryDeserializeDoc(data: SerializedDoc): TryDeserializeDocResult;
458
564
  /** Serialize a full CRDT state (document + clock) to a JSON-safe representation. */
459
565
  declare function serializeState(state: CrdtState): SerializedState;
460
566
  /** Reconstruct a full CRDT state from its serialized form, restoring the clock. */
461
567
  declare function deserializeState(data: SerializedState): CrdtState;
568
+ /** Non-throwing `deserializeState` variant with typed validation details. */
569
+ declare function tryDeserializeState(data: SerializedState): TryDeserializeStateResult;
462
570
  //#endregion
463
571
  //#region src/merge.d.ts
464
572
  /** Error thrown by throwing merge helpers (`mergeDoc` / `mergeState`). */
@@ -531,4 +639,4 @@ declare class TraversalDepthError extends Error {
531
639
  constructor(depth: number, maxDepth?: number);
532
640
  }
533
641
  //#endregion
534
- export { JsonPatchToCrdtOptions as $, tryApplyPatchInPlace as A, CompactDocTombstonesResult as B, applyPatch as C, TryMergeStateResult as Ct, forkState as D, createState as E, ApplyPatchAsActorResult as F, DiffOptions as G, CompilePatchOptions as H, ApplyPatchInPlaceOptions as I, ElemId as J, Doc as K, ApplyPatchOptions as L, ActorId as M, ApplyError as N, toJson as O, ApplyPatchAsActorOptions as P, JsonPatchOp as Q, ApplyResult as R, PatchError as S, TryMergeDocResult as St, applyPatchInPlace as T, VersionVector as Tt, CrdtState as U, CompactStateTombstonesResult as V, DeserializeErrorReason as W, IntentOp as X, ForkStateOptions as Y, JsonPatch as Z, diffJsonPatch as _, SerializedState as _t, MergeError as a, Node as at, parseJsonPointer as b, TryApplyPatchInPlaceResult as bt, tryMergeDoc as c, PatchErrorReason as ct, deserializeDoc as d, RgaElem as dt, JsonPrimitive as et, deserializeState as f, RgaSeq as ft, compileJsonPatchToIntent as g, SerializedRgaElem as gt, PatchCompileError as h, SerializedNode as ht, compactStateTombstones as i, MergeStateOptions as it, validateJsonPatch as j, tryApplyPatch as k, tryMergeState as l, PatchSemantics as lt, serializeState as m, SerializedDoc as mt, TraversalDepthError as n, LwwReg as nt, mergeDoc as o, ObjEntry as ot, serializeDoc as p, SerializedClock as pt, Dot as q, compactDocTombstones as r, MergeDocOptions as rt, mergeState as s, ObjNode as st, MAX_TRAVERSAL_DEPTH as t, JsonValue as tt, DeserializeError as u, ROOT_KEY as ut, getAtJson as v, TombstoneCompactionOptions as vt, applyPatchAsActor as w, ValidatePatchResult as wt, stringifyJsonPointer as x, TryApplyPatchResult as xt, jsonEquals as y, TombstoneCompactionStats as yt, Clock as z };
642
+ 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 };
@@ -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;
@@ -94,6 +101,19 @@ type SerializedState = {
94
101
  };
95
102
  /** Typed reasons for rejecting malformed serialized CRDT payloads. */
96
103
  type DeserializeErrorReason = "INVALID_SERIALIZED_SHAPE" | "INVALID_SERIALIZED_INVARIANT";
104
+ /** Structured failure payload used by non-throwing deserialize helpers. */
105
+ type DeserializeFailure = {
106
+ code: 409;
107
+ reason: DeserializeErrorReason;
108
+ path: string;
109
+ message: string;
110
+ } | {
111
+ code: 409;
112
+ reason: "MAX_DEPTH_EXCEEDED";
113
+ message: string;
114
+ depth: number;
115
+ maxDepth: number;
116
+ };
97
117
  /**
98
118
  * Internal intent operations produced by compiling RFC 6902 JSON Patch ops.
99
119
  * Each variant maps to a specific CRDT mutation.
@@ -163,6 +183,16 @@ type CrdtState = {
163
183
  doc: Doc;
164
184
  clock: Clock;
165
185
  };
186
+ /** Options for `createState`. */
187
+ interface CreateStateOptions {
188
+ actor: ActorId;
189
+ start?: number;
190
+ /**
191
+ * Runtime guardrails for non-JSON values from untyped callers.
192
+ * Defaults to `"none"` for backward compatibility.
193
+ */
194
+ jsonValidation?: JsonValidationMode;
195
+ }
166
196
  /** Options for `forkState`. */
167
197
  interface ForkStateOptions {
168
198
  /**
@@ -181,6 +211,15 @@ type ApplyPatchAsActorOptions = {
181
211
  base?: Doc;
182
212
  testAgainst?: "head" | "base";
183
213
  semantics?: PatchSemantics;
214
+ strictParents?: boolean;
215
+ jsonValidation?: JsonValidationMode;
216
+ };
217
+ /** Non-throwing result for internals-only `tryApplyPatchAsActor`. */
218
+ type TryApplyPatchAsActorResult = ({
219
+ ok: true;
220
+ } & ApplyPatchAsActorResult) | {
221
+ ok: false;
222
+ error: ApplyError;
184
223
  };
185
224
  /** Typed failure reason used across patch/merge helpers. */
186
225
  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";
@@ -197,6 +236,22 @@ type ApplyError = {
197
236
  type ApplyResult = {
198
237
  ok: true;
199
238
  } | ApplyError;
239
+ /** Non-throwing result for `deserializeDoc`. */
240
+ type TryDeserializeDocResult = {
241
+ ok: true;
242
+ doc: Doc;
243
+ } | {
244
+ ok: false;
245
+ error: DeserializeFailure;
246
+ };
247
+ /** Non-throwing result for `deserializeState`. */
248
+ type TryDeserializeStateResult = {
249
+ ok: true;
250
+ state: CrdtState;
251
+ } | {
252
+ ok: false;
253
+ error: DeserializeFailure;
254
+ };
200
255
  /** How JSON Patch operations are interpreted during application. */
201
256
  type PatchSemantics = "base" | "sequential";
202
257
  /** Options for compile/validation helpers. */
@@ -213,6 +268,17 @@ type ApplyPatchOptions = {
213
268
  base?: CrdtState;
214
269
  testAgainst?: "head" | "base";
215
270
  semantics?: PatchSemantics;
271
+ /**
272
+ * Reject array inserts when the base parent path is missing.
273
+ * Defaults to `false` to preserve legacy behavior that can auto-create
274
+ * missing arrays for index `0` / append intents.
275
+ */
276
+ strictParents?: boolean;
277
+ /**
278
+ * Runtime guardrails for patch payload values from untyped callers.
279
+ * Defaults to `"none"` for backward compatibility.
280
+ */
281
+ jsonValidation?: JsonValidationMode;
216
282
  };
217
283
  /** Options for in-place patch application (`applyPatchInPlace` / `tryApplyPatchInPlace`). */
218
284
  type ApplyPatchInPlaceOptions = ApplyPatchOptions & {
@@ -314,6 +380,7 @@ type JsonPatchToCrdtOptions = {
314
380
  evalTestAgainst?: "head" | "base";
315
381
  bumpCounterAbove?: (ctr: number) => void;
316
382
  semantics?: PatchSemantics;
383
+ strictParents?: boolean;
317
384
  };
318
385
  /** Options for `crdtToJsonPatch` and `diffJsonPatch`. */
319
386
  type DiffOptions = {
@@ -330,6 +397,11 @@ type DiffOptions = {
330
397
  * Set to `Number.POSITIVE_INFINITY` to always allow LCS.
331
398
  */
332
399
  lcsMaxCells?: number;
400
+ /**
401
+ * Runtime guardrails for diff inputs from untyped callers.
402
+ * Defaults to `"none"` for backward compatibility.
403
+ */
404
+ jsonValidation?: JsonValidationMode;
333
405
  };
334
406
  /**
335
407
  * Internal sentinel key used in `IntentOp` to represent root-level operations.
@@ -353,10 +425,7 @@ declare class PatchError extends Error {
353
425
  * @param options - Actor ID and optional starting counter.
354
426
  * @returns A new `CrdtState` containing the document and clock.
355
427
  */
356
- declare function createState(initial: JsonValue, options: {
357
- actor: ActorId;
358
- start?: number;
359
- }): CrdtState;
428
+ declare function createState(initial: JsonValue, options: CreateStateOptions): CrdtState;
360
429
  /**
361
430
  * Fork a replica from a shared origin state while assigning a new local actor ID.
362
431
  * The forked state has an independent document clone and clock.
@@ -400,6 +469,41 @@ declare function validateJsonPatch(base: JsonValue, patch: JsonPatchOp[], option
400
469
  * Returns the updated state and a new version vector snapshot.
401
470
  */
402
471
  declare function applyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): ApplyPatchAsActorResult;
472
+ /** Non-throwing `applyPatchAsActor` variant for internals sync flows. */
473
+ declare function tryApplyPatchAsActor(doc: Doc, vv: VersionVector, actor: ActorId, patch: JsonPatchOp[], options?: ApplyPatchAsActorOptions): TryApplyPatchAsActorResult;
474
+ //#endregion
475
+ //#region src/json-value.d.ts
476
+ /**
477
+ * Runtime validation error for values that are not JSON-compatible.
478
+ * `path` is an RFC 6901 pointer relative to the validated root.
479
+ */
480
+ declare class JsonValueValidationError extends TypeError {
481
+ readonly path: string;
482
+ readonly detail: string;
483
+ constructor(path: string, detail: string);
484
+ }
485
+ //#endregion
486
+ //#region src/clock.d.ts
487
+ type ClockValidationErrorReason = "INVALID_ACTOR" | "INVALID_COUNTER";
488
+ declare class ClockValidationError extends TypeError {
489
+ readonly reason: ClockValidationErrorReason;
490
+ constructor(reason: ClockValidationErrorReason, message: string);
491
+ }
492
+ /**
493
+ * Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
494
+ * @param actor - Unique identifier for this peer.
495
+ * @param start - Initial counter value (defaults to 0).
496
+ */
497
+ declare function createClock(actor: ActorId, start?: number): Clock;
498
+ /** Create an independent copy of a clock at the same counter position. */
499
+ declare function cloneClock(clock: Clock): Clock;
500
+ /**
501
+ * Generate the next per-actor dot from a mutable version vector.
502
+ * Useful when a server needs to mint dots for many actors.
503
+ */
504
+ declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
505
+ /** Record an observed dot in a version vector. */
506
+ declare function observeDot(vv: VersionVector, dot: Dot): void;
403
507
  //#endregion
404
508
  //#region src/patch.d.ts
405
509
  /** Structured compile error used to map patch validation failures to typed reasons. */
@@ -455,10 +559,14 @@ declare class DeserializeError extends Error {
455
559
  declare function serializeDoc(doc: Doc): SerializedDoc;
456
560
  /** Reconstruct a CRDT document from its serialized form. */
457
561
  declare function deserializeDoc(data: SerializedDoc): Doc;
562
+ /** Non-throwing `deserializeDoc` variant with typed validation details. */
563
+ declare function tryDeserializeDoc(data: SerializedDoc): TryDeserializeDocResult;
458
564
  /** Serialize a full CRDT state (document + clock) to a JSON-safe representation. */
459
565
  declare function serializeState(state: CrdtState): SerializedState;
460
566
  /** Reconstruct a full CRDT state from its serialized form, restoring the clock. */
461
567
  declare function deserializeState(data: SerializedState): CrdtState;
568
+ /** Non-throwing `deserializeState` variant with typed validation details. */
569
+ declare function tryDeserializeState(data: SerializedState): TryDeserializeStateResult;
462
570
  //#endregion
463
571
  //#region src/merge.d.ts
464
572
  /** Error thrown by throwing merge helpers (`mergeDoc` / `mergeState`). */
@@ -531,4 +639,4 @@ declare class TraversalDepthError extends Error {
531
639
  constructor(depth: number, maxDepth?: number);
532
640
  }
533
641
  //#endregion
534
- export { JsonPatchToCrdtOptions as $, tryApplyPatchInPlace as A, CompactDocTombstonesResult as B, applyPatch as C, TryMergeStateResult as Ct, forkState as D, createState as E, ApplyPatchAsActorResult as F, DiffOptions as G, CompilePatchOptions as H, ApplyPatchInPlaceOptions as I, ElemId as J, Doc as K, ApplyPatchOptions as L, ActorId as M, ApplyError as N, toJson as O, ApplyPatchAsActorOptions as P, JsonPatchOp as Q, ApplyResult as R, PatchError as S, TryMergeDocResult as St, applyPatchInPlace as T, VersionVector as Tt, CrdtState as U, CompactStateTombstonesResult as V, DeserializeErrorReason as W, IntentOp as X, ForkStateOptions as Y, JsonPatch as Z, diffJsonPatch as _, SerializedState as _t, MergeError as a, Node as at, parseJsonPointer as b, TryApplyPatchInPlaceResult as bt, tryMergeDoc as c, PatchErrorReason as ct, deserializeDoc as d, RgaElem as dt, JsonPrimitive as et, deserializeState as f, RgaSeq as ft, compileJsonPatchToIntent as g, SerializedRgaElem as gt, PatchCompileError as h, SerializedNode as ht, compactStateTombstones as i, MergeStateOptions as it, validateJsonPatch as j, tryApplyPatch as k, tryMergeState as l, PatchSemantics as lt, serializeState as m, SerializedDoc as mt, TraversalDepthError as n, LwwReg as nt, mergeDoc as o, ObjEntry as ot, serializeDoc as p, SerializedClock as pt, Dot as q, compactDocTombstones as r, MergeDocOptions as rt, mergeState as s, ObjNode as st, MAX_TRAVERSAL_DEPTH as t, JsonValue as tt, DeserializeError as u, ROOT_KEY as ut, getAtJson as v, TombstoneCompactionOptions as vt, applyPatchAsActor as w, ValidatePatchResult as wt, stringifyJsonPointer as x, TryApplyPatchResult as xt, jsonEquals as y, TombstoneCompactionStats as yt, Clock as z };
642
+ 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 { A as tryApplyPatchInPlace, C as applyPatch, Ct as TryMergeStateResult, D as forkState, E as createState, G as DiffOptions, I as ApplyPatchInPlaceOptions, L as ApplyPatchOptions, M as ActorId, N as ApplyError, O as toJson, Q as JsonPatchOp, S as PatchError, T as applyPatchInPlace, U as CrdtState, V as CompactStateTombstonesResult, W as DeserializeErrorReason, Y as ForkStateOptions, Z as JsonPatch, _ as diffJsonPatch, _t as SerializedState, a as MergeError, bt as TryApplyPatchInPlaceResult, ct as PatchErrorReason, et as JsonPrimitive, f as deserializeState, i as compactStateTombstones, it as MergeStateOptions, j as validateJsonPatch, k as tryApplyPatch, l as tryMergeState, lt as PatchSemantics, m as serializeState, n as TraversalDepthError, s as mergeState, t as MAX_TRAVERSAL_DEPTH, tt as JsonValue, u as DeserializeError, vt as TombstoneCompactionOptions, wt as ValidatePatchResult, xt as TryApplyPatchResult, yt as TombstoneCompactionStats } from "./depth-wDeQ1hO1.mjs";
2
- export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, type CompactStateTombstonesResult, type CrdtState, DeserializeError, type DeserializeErrorReason, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValue, 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-Cd3nyHWy.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 { A as tryApplyPatchInPlace, C as applyPatch, Ct as TryMergeStateResult, D as forkState, E as createState, G as DiffOptions, I as ApplyPatchInPlaceOptions, L as ApplyPatchOptions, M as ActorId, N as ApplyError, O as toJson, Q as JsonPatchOp, S as PatchError, T as applyPatchInPlace, U as CrdtState, V as CompactStateTombstonesResult, W as DeserializeErrorReason, Y as ForkStateOptions, Z as JsonPatch, _ as diffJsonPatch, _t as SerializedState, a as MergeError, bt as TryApplyPatchInPlaceResult, ct as PatchErrorReason, et as JsonPrimitive, f as deserializeState, i as compactStateTombstones, it as MergeStateOptions, j as validateJsonPatch, k as tryApplyPatch, l as tryMergeState, lt as PatchSemantics, m as serializeState, n as TraversalDepthError, s as mergeState, t as MAX_TRAVERSAL_DEPTH, tt as JsonValue, u as DeserializeError, vt as TombstoneCompactionOptions, wt as ValidatePatchResult, xt as TryApplyPatchResult, yt as TombstoneCompactionStats } from "./depth-p6fX9Ak7.js";
2
- export { type ActorId, type ApplyError, type ApplyPatchInPlaceOptions, type ApplyPatchOptions, type CompactStateTombstonesResult, type CrdtState, DeserializeError, type DeserializeErrorReason, type DiffOptions, type ForkStateOptions, type JsonPatch, type JsonPatchOp, type JsonPrimitive, type JsonValue, 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-tcJ8L1dj.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,7 +1,9 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_compact = require('./compact-CkLd4Yh5.js');
2
+ const require_compact = require('./compact-DrmgKiVW.js');
3
3
 
4
+ exports.ClockValidationError = require_compact.ClockValidationError;
4
5
  exports.DeserializeError = require_compact.DeserializeError;
6
+ exports.JsonValueValidationError = require_compact.JsonValueValidationError;
5
7
  exports.MAX_TRAVERSAL_DEPTH = require_compact.MAX_TRAVERSAL_DEPTH;
6
8
  exports.MergeError = require_compact.MergeError;
7
9
  exports.PatchError = require_compact.PatchError;
@@ -18,5 +20,6 @@ exports.serializeState = require_compact.serializeState;
18
20
  exports.toJson = require_compact.toJson;
19
21
  exports.tryApplyPatch = require_compact.tryApplyPatch;
20
22
  exports.tryApplyPatchInPlace = require_compact.tryApplyPatchInPlace;
23
+ exports.tryDeserializeState = require_compact.tryDeserializeState;
21
24
  exports.tryMergeState = require_compact.tryMergeState;
22
25
  exports.validateJsonPatch = require_compact.validateJsonPatch;
package/dist/index.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { P as diffJsonPatch, S as validateJsonPatch, _ as createState, a as mergeState, at as MAX_TRAVERSAL_DEPTH, b as tryApplyPatch, c as DeserializeError, f as serializeState, g as applyPatchInPlace, m as applyPatch, n as compactStateTombstones, ot as TraversalDepthError, p as PatchError, r as MergeError, s as tryMergeState, u as deserializeState, v as forkState, x as tryApplyPatchInPlace, y as toJson } from "./compact-BJBGW9tC.mjs";
1
+ import { L as diffJsonPatch, S as tryApplyPatch, T as validateJsonPatch, U as JsonValueValidationError, a as mergeState, b as forkState, c as DeserializeError, dt as ClockValidationError, f as serializeState, g as applyPatch, h as PatchError, lt as MAX_TRAVERSAL_DEPTH, m as tryDeserializeState, n as compactStateTombstones, r as MergeError, s as tryMergeState, u as deserializeState, ut as TraversalDepthError, v as applyPatchInPlace, w as tryApplyPatchInPlace, x as toJson, y as createState } from "./compact-BE9UsxEo.mjs";
2
2
 
3
- export { DeserializeError, 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 };
@@ -1,22 +1,5 @@
1
- import { $ as JsonPatchToCrdtOptions, A as tryApplyPatchInPlace, B as CompactDocTombstonesResult, C as applyPatch, Ct as TryMergeStateResult, D as forkState, E as createState, F as ApplyPatchAsActorResult, G as DiffOptions, H as CompilePatchOptions, I as ApplyPatchInPlaceOptions, J as ElemId, K as Doc, L as ApplyPatchOptions, M as ActorId, N as ApplyError, O as toJson, P as ApplyPatchAsActorOptions, Q as JsonPatchOp, R as ApplyResult, S as PatchError, St as TryMergeDocResult, T as applyPatchInPlace, Tt as VersionVector, U as CrdtState, V as CompactStateTombstonesResult, W as DeserializeErrorReason, X as IntentOp, Y as ForkStateOptions, Z as JsonPatch, _ as diffJsonPatch, _t as SerializedState, a as MergeError, at as Node, b as parseJsonPointer, bt as TryApplyPatchInPlaceResult, c as tryMergeDoc, ct as PatchErrorReason, d as deserializeDoc, dt as RgaElem, et as JsonPrimitive, f as deserializeState, ft as RgaSeq, g as compileJsonPatchToIntent, gt as SerializedRgaElem, h as PatchCompileError, ht as SerializedNode, i as compactStateTombstones, it as MergeStateOptions, j as validateJsonPatch, k as tryApplyPatch, l as tryMergeState, lt as PatchSemantics, m as serializeState, mt as SerializedDoc, n as TraversalDepthError, nt as LwwReg, o as mergeDoc, ot as ObjEntry, p as serializeDoc, pt as SerializedClock, q as Dot, r as compactDocTombstones, rt as MergeDocOptions, s as mergeState, st as ObjNode, t as MAX_TRAVERSAL_DEPTH, tt as JsonValue, u as DeserializeError, ut as ROOT_KEY, v as getAtJson, vt as TombstoneCompactionOptions, w as applyPatchAsActor, wt as ValidatePatchResult, x as stringifyJsonPointer, xt as TryApplyPatchResult, y as jsonEquals, yt as TombstoneCompactionStats, z as Clock } from "./depth-wDeQ1hO1.mjs";
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-Cd3nyHWy.mjs";
2
2
 
3
- //#region src/clock.d.ts
4
- /**
5
- * Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
6
- * @param actor - Unique identifier for this peer.
7
- * @param start - Initial counter value (defaults to 0).
8
- */
9
- declare function createClock(actor: ActorId, start?: number): Clock;
10
- /** Create an independent copy of a clock at the same counter position. */
11
- declare function cloneClock(clock: Clock): Clock;
12
- /**
13
- * Generate the next per-actor dot from a mutable version vector.
14
- * Useful when a server needs to mint dots for many actors.
15
- */
16
- declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
17
- /** Record an observed dot in a version vector. */
18
- declare function observeDot(vv: VersionVector, dot: Dot): void;
19
- //#endregion
20
3
  //#region src/doc.d.ts
21
4
  /**
22
5
  * Create a CRDT document from a JSON value, using fresh dots for each node.
@@ -41,23 +24,29 @@ declare function cloneDoc(doc: Doc): Doc;
41
24
  * @param newDot - A function that generates a unique `Dot` per mutation.
42
25
  * @param evalTestAgainst - Whether `test` ops are evaluated against `"head"` or `"base"`.
43
26
  * @param bumpCounterAbove - Optional hook that can fast-forward the underlying counter before inserts.
27
+ * @param options - Optional behavior toggles.
28
+ * @param options.strictParents - When `true`, reject array inserts whose base parent path is missing.
44
29
  * @returns `{ ok: true }` on success, or `{ ok: false, code: 409, message }` on conflict.
45
30
  */
46
- declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
31
+ declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, options?: {
32
+ strictParents?: boolean;
33
+ }): ApplyResult;
47
34
  /**
48
35
  * Convenience wrapper: compile a JSON Patch and apply it to a CRDT document.
49
36
  * Overloads:
50
- * - positional: `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?)`
51
- * - object: `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics? })`
37
+ * - positional:
38
+ * `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, strictParents?)`
39
+ * - object:
40
+ * `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics?, strictParents? })`
52
41
  */
53
42
  declare function jsonPatchToCrdt(options: JsonPatchToCrdtOptions): ApplyResult;
54
- declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
43
+ declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
55
44
  /**
56
45
  * Safe wrapper around `jsonPatchToCrdt`.
57
46
  * This function never throws and always returns an `ApplyResult`.
58
47
  */
59
48
  declare function jsonPatchToCrdtSafe(options: JsonPatchToCrdtOptions): ApplyResult;
60
- declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
49
+ declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
61
50
  /** Alias for codebases that prefer `try*` naming for non-throwing APIs. */
62
51
  declare const tryJsonPatchToCrdt: typeof jsonPatchToCrdtSafe;
63
52
  /**
@@ -112,4 +101,4 @@ declare function rgaCompactTombstones(seq: RgaSeq, isStable: (dot: Dot) => boole
112
101
  declare function rgaIdAtIndex(seq: RgaSeq, index: number): ElemId | undefined;
113
102
  declare function rgaPrevForInsertAtIndex(seq: RgaSeq, index: number): ElemId;
114
103
  //#endregion
115
- export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, type CompactDocTombstonesResult, type CompactStateTombstonesResult, type CompilePatchOptions, CrdtState, DeserializeError, DeserializeErrorReason, DiffOptions, type Doc, type Dot, type ElemId, ForkStateOptions, HEAD, type IntentOp, JsonPatch, JsonPatchOp, type JsonPatchToCrdtOptions, JsonPrimitive, JsonValue, 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 };
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, 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 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, 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, tryApplyPatchAsActor, tryApplyPatchInPlace, tryDeserializeDoc, tryDeserializeState, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };
@@ -1,22 +1,5 @@
1
- import { $ as JsonPatchToCrdtOptions, A as tryApplyPatchInPlace, B as CompactDocTombstonesResult, C as applyPatch, Ct as TryMergeStateResult, D as forkState, E as createState, F as ApplyPatchAsActorResult, G as DiffOptions, H as CompilePatchOptions, I as ApplyPatchInPlaceOptions, J as ElemId, K as Doc, L as ApplyPatchOptions, M as ActorId, N as ApplyError, O as toJson, P as ApplyPatchAsActorOptions, Q as JsonPatchOp, R as ApplyResult, S as PatchError, St as TryMergeDocResult, T as applyPatchInPlace, Tt as VersionVector, U as CrdtState, V as CompactStateTombstonesResult, W as DeserializeErrorReason, X as IntentOp, Y as ForkStateOptions, Z as JsonPatch, _ as diffJsonPatch, _t as SerializedState, a as MergeError, at as Node, b as parseJsonPointer, bt as TryApplyPatchInPlaceResult, c as tryMergeDoc, ct as PatchErrorReason, d as deserializeDoc, dt as RgaElem, et as JsonPrimitive, f as deserializeState, ft as RgaSeq, g as compileJsonPatchToIntent, gt as SerializedRgaElem, h as PatchCompileError, ht as SerializedNode, i as compactStateTombstones, it as MergeStateOptions, j as validateJsonPatch, k as tryApplyPatch, l as tryMergeState, lt as PatchSemantics, m as serializeState, mt as SerializedDoc, n as TraversalDepthError, nt as LwwReg, o as mergeDoc, ot as ObjEntry, p as serializeDoc, pt as SerializedClock, q as Dot, r as compactDocTombstones, rt as MergeDocOptions, s as mergeState, st as ObjNode, t as MAX_TRAVERSAL_DEPTH, tt as JsonValue, u as DeserializeError, ut as ROOT_KEY, v as getAtJson, vt as TombstoneCompactionOptions, w as applyPatchAsActor, wt as ValidatePatchResult, x as stringifyJsonPointer, xt as TryApplyPatchResult, y as jsonEquals, yt as TombstoneCompactionStats, z as Clock } from "./depth-p6fX9Ak7.js";
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-tcJ8L1dj.js";
2
2
 
3
- //#region src/clock.d.ts
4
- /**
5
- * Create a new clock for the given actor. Each call to `clock.next()` yields a fresh `Dot`.
6
- * @param actor - Unique identifier for this peer.
7
- * @param start - Initial counter value (defaults to 0).
8
- */
9
- declare function createClock(actor: ActorId, start?: number): Clock;
10
- /** Create an independent copy of a clock at the same counter position. */
11
- declare function cloneClock(clock: Clock): Clock;
12
- /**
13
- * Generate the next per-actor dot from a mutable version vector.
14
- * Useful when a server needs to mint dots for many actors.
15
- */
16
- declare function nextDotForActor(vv: VersionVector, actor: ActorId): Dot;
17
- /** Record an observed dot in a version vector. */
18
- declare function observeDot(vv: VersionVector, dot: Dot): void;
19
- //#endregion
20
3
  //#region src/doc.d.ts
21
4
  /**
22
5
  * Create a CRDT document from a JSON value, using fresh dots for each node.
@@ -41,23 +24,29 @@ declare function cloneDoc(doc: Doc): Doc;
41
24
  * @param newDot - A function that generates a unique `Dot` per mutation.
42
25
  * @param evalTestAgainst - Whether `test` ops are evaluated against `"head"` or `"base"`.
43
26
  * @param bumpCounterAbove - Optional hook that can fast-forward the underlying counter before inserts.
27
+ * @param options - Optional behavior toggles.
28
+ * @param options.strictParents - When `true`, reject array inserts whose base parent path is missing.
44
29
  * @returns `{ ok: true }` on success, or `{ ok: false, code: 409, message }` on conflict.
45
30
  */
46
- declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
31
+ declare function applyIntentsToCrdt(base: Doc, head: Doc, intents: IntentOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, options?: {
32
+ strictParents?: boolean;
33
+ }): ApplyResult;
47
34
  /**
48
35
  * Convenience wrapper: compile a JSON Patch and apply it to a CRDT document.
49
36
  * Overloads:
50
- * - positional: `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?)`
51
- * - object: `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics? })`
37
+ * - positional:
38
+ * `jsonPatchToCrdt(base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, strictParents?)`
39
+ * - object:
40
+ * `jsonPatchToCrdt({ base, head, patch, newDot, evalTestAgainst?, bumpCounterAbove?, semantics?, strictParents? })`
52
41
  */
53
42
  declare function jsonPatchToCrdt(options: JsonPatchToCrdtOptions): ApplyResult;
54
- declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
43
+ declare function jsonPatchToCrdt(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
55
44
  /**
56
45
  * Safe wrapper around `jsonPatchToCrdt`.
57
46
  * This function never throws and always returns an `ApplyResult`.
58
47
  */
59
48
  declare function jsonPatchToCrdtSafe(options: JsonPatchToCrdtOptions): ApplyResult;
60
- declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void): ApplyResult;
49
+ declare function jsonPatchToCrdtSafe(base: Doc, head: Doc, patch: JsonPatchOp[], newDot: () => Dot, evalTestAgainst?: "head" | "base", bumpCounterAbove?: (ctr: number) => void, strictParents?: boolean): ApplyResult;
61
50
  /** Alias for codebases that prefer `try*` naming for non-throwing APIs. */
62
51
  declare const tryJsonPatchToCrdt: typeof jsonPatchToCrdtSafe;
63
52
  /**
@@ -112,4 +101,4 @@ declare function rgaCompactTombstones(seq: RgaSeq, isStable: (dot: Dot) => boole
112
101
  declare function rgaIdAtIndex(seq: RgaSeq, index: number): ElemId | undefined;
113
102
  declare function rgaPrevForInsertAtIndex(seq: RgaSeq, index: number): ElemId;
114
103
  //#endregion
115
- export { ActorId, ApplyError, type ApplyPatchAsActorOptions, type ApplyPatchAsActorResult, ApplyPatchInPlaceOptions, ApplyPatchOptions, type ApplyResult, type Clock, type CompactDocTombstonesResult, type CompactStateTombstonesResult, type CompilePatchOptions, CrdtState, DeserializeError, DeserializeErrorReason, DiffOptions, type Doc, type Dot, type ElemId, ForkStateOptions, HEAD, type IntentOp, JsonPatch, JsonPatchOp, type JsonPatchToCrdtOptions, JsonPrimitive, JsonValue, 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 };
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, 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 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, 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, tryApplyPatchAsActor, tryApplyPatchInPlace, tryDeserializeDoc, tryDeserializeState, tryJsonPatchToCrdt, tryMergeDoc, tryMergeState, validateJsonPatch, vvHasDot, vvMerge };