@loro-dev/json-patch 0.0.0-stage → 0.1.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.
@@ -0,0 +1,74 @@
1
+ import { A as valuesEqual, C as assertValidUtf16Boundary, D as pathsEqual, E as numbersEqual, O as pathsOverlap, S as assertNoLoneSurrogates, T as isPlainObject, _ as JsonOp, a as PatternSeg, b as JsonValue, c as diffStringAt, d as patternMatches, f as ApplyError, g as JsonObject, h as DecodeErrorKind, i as KeyExtractor, k as validateJsonValue, l as lisMask, m as DecodeError, n as ANY_SEG, o as TreeDiffSpec, p as ApplyErrorKind, r as DiffOptions, s as diff, t as ANY_REST_SEG, u as lisMovePairs, v as JsonPatch, w as assertValidUtf16Range, x as PathSeg, y as JsonPath } from "./diff.cjs";
2
+
3
+ //#region src/apply.d.ts
4
+
5
+ /**
6
+ * Applies a single {@link JsonOp} copy-on-write without mutating `state`.
7
+ * @throws {@link ApplyError} on invalid path, out-of-bounds index, type mismatch, or bad UTF-16 boundary.
8
+ */
9
+ declare function applyOp(state: JsonValue, op: JsonOp, opIndex?: number): JsonValue;
10
+ /**
11
+ * Structural-sharing Copy-on-Write `apply`.
12
+ * - Never mutates `state` or `patch` (atomic rollback on any error is guaranteed).
13
+ * - Uses transient batch ownership on newly allocated nodes to avoid re-cloning them per op.
14
+ * Total cost also includes container copies, array shifts, string scans, value validation,
15
+ * and deep equality checks; it is not bounded solely by operation count and path depth.
16
+ * - Preserves `===` object/array identities for all untouched subtrees and moved subtrees.
17
+ */
18
+ declare function apply(state: JsonValue, patch: JsonPatch): JsonValue;
19
+ //#endregion
20
+ //#region src/codec.d.ts
21
+ /**
22
+ * Controls how `Uint8Array` values inside {@link JsonValue} are represented in JSON text:
23
+ * - `"tagged"`: encodes `Uint8Array` as `{"$bytes":"<base64>"}` and escapes literal `$bytes` / `$esc` keys.
24
+ * - `"reject"`: throws {@link DecodeError} (`"BytesRejected"`) whenever `Uint8Array` or `$bytes`/`$esc` keys appear.
25
+ */
26
+ type BytesJsonMode = "tagged" | "reject";
27
+ /** Options for {@link encodeJson} and {@link decodeJson}. */
28
+ interface JsonCodecOptions {
29
+ /** Byte-array serialization policy. Defaults to `"tagged"`. */
30
+ readonly bytesMode?: BytesJsonMode;
31
+ }
32
+ /**
33
+ * Serializes a {@link JsonPatch} to lossless wire JSON (preserving exact 64-bit `bigint` integers,
34
+ * rejecting non-finite floats / lone surrogates, and encoding `Uint8Array` per `options.bytesMode`).
35
+ * @throws {@link DecodeError} on invalid integers, floats, paths, or bytes.
36
+ */
37
+ declare function encodeJson(patch: JsonPatch, options?: JsonCodecOptions): string;
38
+ /**
39
+ * Parses wire JSON text back into a validated {@link JsonOp} array, restoring out-of-safe-range integers
40
+ * as `bigint` and `{"$bytes":"..."}` as `Uint8Array` (when `bytesMode` is `"tagged"`).
41
+ * @throws {@link DecodeError} on malformed JSON, unknown op names, or invalid values/paths.
42
+ */
43
+ declare function decodeJson(input: string, options?: JsonCodecOptions): JsonOp[];
44
+ /**
45
+ * Encodes a {@link JsonPatch} into compact binary MessagePack op-tuples (`[opCode, ...]`)
46
+ * compatible with the Rust `loro-json-patch` codec.
47
+ * @throws {@link DecodeError} on invalid paths, values, or integer bounds.
48
+ */
49
+ declare function encodeMsgpack(patch: JsonPatch): Uint8Array;
50
+ /**
51
+ * Decodes compact binary MessagePack op-tuples back into validated {@link JsonOp} operations.
52
+ * @throws {@link DecodeError} on unknown op codes, unsupported MsgPack extensions, or trailing bytes.
53
+ */
54
+ declare function decodeMsgpack(bytes: Uint8Array): JsonOp[];
55
+ /**
56
+ * Encodes one plain JSON value as MessagePack with the same value rules as the compact patch codec
57
+ * (sorted object keys, minimal integer widths, i64/u64 as bigint, `Uint8Array` as `bin`, no extension types).
58
+ */
59
+ declare function encodeMsgpackValue(value: JsonValue): Uint8Array;
60
+ /**
61
+ * Decodes one MessagePack value with the same value rules as the compact patch codec: integers in the
62
+ * safe range are numbers, larger i64/u64 are bigint, `bin` is `Uint8Array`, extension types, non-finite
63
+ * floats and trailing bytes are rejected with `DecodeError`.
64
+ */
65
+ declare function decodeMsgpackValue(bytes: Uint8Array): JsonValue;
66
+ //#endregion
67
+ //#region src/compact.d.ts
68
+ /**
69
+ * Stateless O(M) compactor for slow consumers and streaming patches.
70
+ * Preserves unvalidated non-root prefixes and statically invalid ops as barriers.
71
+ */
72
+ declare function compact(patch: JsonPatch): JsonOp[];
73
+ //#endregion
74
+ export { ANY_REST_SEG, ANY_SEG, ApplyError, type ApplyErrorKind, type BytesJsonMode, DecodeError, type DecodeErrorKind, type DiffOptions, type JsonCodecOptions, type JsonObject, type JsonOp, type JsonPatch, type JsonPath, type JsonValue, type KeyExtractor, type PathSeg, type PatternSeg, type TreeDiffSpec, apply, applyOp, assertNoLoneSurrogates, assertValidUtf16Boundary, assertValidUtf16Range, compact, decodeJson, decodeMsgpack, decodeMsgpackValue, diff, diffStringAt, encodeJson, encodeMsgpack, encodeMsgpackValue, isPlainObject, lisMask, lisMovePairs, numbersEqual, pathsEqual, pathsOverlap, patternMatches, validateJsonValue, valuesEqual };
@@ -0,0 +1,74 @@
1
+ import { A as valuesEqual, C as assertValidUtf16Boundary, D as pathsEqual, E as numbersEqual, O as pathsOverlap, S as assertNoLoneSurrogates, T as isPlainObject, _ as JsonOp, a as PatternSeg, b as JsonValue, c as diffStringAt, d as patternMatches, f as ApplyError, g as JsonObject, h as DecodeErrorKind, i as KeyExtractor, k as validateJsonValue, l as lisMask, m as DecodeError, n as ANY_SEG, o as TreeDiffSpec, p as ApplyErrorKind, r as DiffOptions, s as diff, t as ANY_REST_SEG, u as lisMovePairs, v as JsonPatch, w as assertValidUtf16Range, x as PathSeg, y as JsonPath } from "./diff.js";
2
+
3
+ //#region src/apply.d.ts
4
+
5
+ /**
6
+ * Applies a single {@link JsonOp} copy-on-write without mutating `state`.
7
+ * @throws {@link ApplyError} on invalid path, out-of-bounds index, type mismatch, or bad UTF-16 boundary.
8
+ */
9
+ declare function applyOp(state: JsonValue, op: JsonOp, opIndex?: number): JsonValue;
10
+ /**
11
+ * Structural-sharing Copy-on-Write `apply`.
12
+ * - Never mutates `state` or `patch` (atomic rollback on any error is guaranteed).
13
+ * - Uses transient batch ownership on newly allocated nodes to avoid re-cloning them per op.
14
+ * Total cost also includes container copies, array shifts, string scans, value validation,
15
+ * and deep equality checks; it is not bounded solely by operation count and path depth.
16
+ * - Preserves `===` object/array identities for all untouched subtrees and moved subtrees.
17
+ */
18
+ declare function apply(state: JsonValue, patch: JsonPatch): JsonValue;
19
+ //#endregion
20
+ //#region src/codec.d.ts
21
+ /**
22
+ * Controls how `Uint8Array` values inside {@link JsonValue} are represented in JSON text:
23
+ * - `"tagged"`: encodes `Uint8Array` as `{"$bytes":"<base64>"}` and escapes literal `$bytes` / `$esc` keys.
24
+ * - `"reject"`: throws {@link DecodeError} (`"BytesRejected"`) whenever `Uint8Array` or `$bytes`/`$esc` keys appear.
25
+ */
26
+ type BytesJsonMode = "tagged" | "reject";
27
+ /** Options for {@link encodeJson} and {@link decodeJson}. */
28
+ interface JsonCodecOptions {
29
+ /** Byte-array serialization policy. Defaults to `"tagged"`. */
30
+ readonly bytesMode?: BytesJsonMode;
31
+ }
32
+ /**
33
+ * Serializes a {@link JsonPatch} to lossless wire JSON (preserving exact 64-bit `bigint` integers,
34
+ * rejecting non-finite floats / lone surrogates, and encoding `Uint8Array` per `options.bytesMode`).
35
+ * @throws {@link DecodeError} on invalid integers, floats, paths, or bytes.
36
+ */
37
+ declare function encodeJson(patch: JsonPatch, options?: JsonCodecOptions): string;
38
+ /**
39
+ * Parses wire JSON text back into a validated {@link JsonOp} array, restoring out-of-safe-range integers
40
+ * as `bigint` and `{"$bytes":"..."}` as `Uint8Array` (when `bytesMode` is `"tagged"`).
41
+ * @throws {@link DecodeError} on malformed JSON, unknown op names, or invalid values/paths.
42
+ */
43
+ declare function decodeJson(input: string, options?: JsonCodecOptions): JsonOp[];
44
+ /**
45
+ * Encodes a {@link JsonPatch} into compact binary MessagePack op-tuples (`[opCode, ...]`)
46
+ * compatible with the Rust `loro-json-patch` codec.
47
+ * @throws {@link DecodeError} on invalid paths, values, or integer bounds.
48
+ */
49
+ declare function encodeMsgpack(patch: JsonPatch): Uint8Array;
50
+ /**
51
+ * Decodes compact binary MessagePack op-tuples back into validated {@link JsonOp} operations.
52
+ * @throws {@link DecodeError} on unknown op codes, unsupported MsgPack extensions, or trailing bytes.
53
+ */
54
+ declare function decodeMsgpack(bytes: Uint8Array): JsonOp[];
55
+ /**
56
+ * Encodes one plain JSON value as MessagePack with the same value rules as the compact patch codec
57
+ * (sorted object keys, minimal integer widths, i64/u64 as bigint, `Uint8Array` as `bin`, no extension types).
58
+ */
59
+ declare function encodeMsgpackValue(value: JsonValue): Uint8Array;
60
+ /**
61
+ * Decodes one MessagePack value with the same value rules as the compact patch codec: integers in the
62
+ * safe range are numbers, larger i64/u64 are bigint, `bin` is `Uint8Array`, extension types, non-finite
63
+ * floats and trailing bytes are rejected with `DecodeError`.
64
+ */
65
+ declare function decodeMsgpackValue(bytes: Uint8Array): JsonValue;
66
+ //#endregion
67
+ //#region src/compact.d.ts
68
+ /**
69
+ * Stateless O(M) compactor for slow consumers and streaming patches.
70
+ * Preserves unvalidated non-root prefixes and statically invalid ops as barriers.
71
+ */
72
+ declare function compact(patch: JsonPatch): JsonOp[];
73
+ //#endregion
74
+ export { ANY_REST_SEG, ANY_SEG, ApplyError, type ApplyErrorKind, type BytesJsonMode, DecodeError, type DecodeErrorKind, type DiffOptions, type JsonCodecOptions, type JsonObject, type JsonOp, type JsonPatch, type JsonPath, type JsonValue, type KeyExtractor, type PathSeg, type PatternSeg, type TreeDiffSpec, apply, applyOp, assertNoLoneSurrogates, assertValidUtf16Boundary, assertValidUtf16Range, compact, decodeJson, decodeMsgpack, decodeMsgpackValue, diff, diffStringAt, encodeJson, encodeMsgpack, encodeMsgpackValue, isPlainObject, lisMask, lisMovePairs, numbersEqual, pathsEqual, pathsOverlap, patternMatches, validateJsonValue, valuesEqual };