@evolu/common 8.6.1 → 8.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/Buffer.d.ts +67 -8
- package/dist/src/Buffer.d.ts.map +1 -1
- package/dist/src/Buffer.js +722 -15
- package/dist/src/Sqlite.d.ts +23 -9
- package/dist/src/Sqlite.d.ts.map +1 -1
- package/dist/src/Sqlite.js +14 -9
- package/dist/src/local-first/Db.d.ts.map +1 -1
- package/dist/src/local-first/Db.js +1 -0
- package/dist/src/local-first/Protocol.d.ts +19 -5
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +28 -35
- package/dist/src/local-first/Query.d.ts +2 -3
- package/dist/src/local-first/Query.d.ts.map +1 -1
- package/dist/src/local-first/Query.js +1 -1
- package/dist/src/local-first/Schema.d.ts +15 -1
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +3 -2
- package/dist/src/local-first/Storage.d.ts +2 -2
- package/dist/src/local-first/Storage.d.ts.map +1 -1
- package/package.json +1 -2
- package/src/Buffer.ts +966 -22
- package/src/Sqlite.ts +34 -16
- package/src/local-first/Db.ts +3 -1
- package/src/local-first/Protocol.ts +30 -42
- package/src/local-first/Query.ts +5 -5
- package/src/local-first/Schema.ts +22 -7
package/dist/src/Buffer.d.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Binary data handling and byte array utilities.
|
|
3
3
|
*
|
|
4
|
+
* Buffer-based decoding functions intentionally throw errors instead of
|
|
5
|
+
* returning {@link Result}. This is a deliberate micro-optimization for Evolu
|
|
6
|
+
* Protocol's hot paths: Result is inexpensive, but returning decoded values
|
|
7
|
+
* directly avoids its success-case allocation, and using `Error` objects
|
|
8
|
+
* preserves stack traces. In the future, we will try returning `Error` objects
|
|
9
|
+
* in `Result` values to measure the real-world performance impact.
|
|
10
|
+
*
|
|
4
11
|
* @module
|
|
5
12
|
*/
|
|
6
|
-
import { NonNegativeInt } from "./Type.ts";
|
|
13
|
+
import type { JsonValue, NonNegativeInt } from "./Type.ts";
|
|
7
14
|
export { bytesToHex, bytesToUtf8, concatBytes, hexToBytes, utf8ToBytes, } from "@noble/ciphers/utils.js";
|
|
8
15
|
/**
|
|
9
16
|
* Custom error for {@link Buffer}-related failures like premature end of data.
|
|
@@ -26,12 +33,7 @@ export declare class BufferError extends Error {
|
|
|
26
33
|
* reused within functions by leveraging `reset` to clear contents while
|
|
27
34
|
* preserving capacity, or `truncate` to adjust the length to a specific size,
|
|
28
35
|
* reducing the need for new allocations. Pass Buffers to `encode*` functions to
|
|
29
|
-
* append serialized data and use `decode*` functions to extract data.
|
|
30
|
-
* `shift` and `shiftN` throw an {@link BufferError} with message "Buffer parse
|
|
31
|
-
* ended prematurely" on failure, as do higher-level `decode*` functions,
|
|
32
|
-
* providing stack traces for debugging instead of using {@link Result}. This
|
|
33
|
-
* avoids allocation overhead in success cases and leverages exceptions'
|
|
34
|
-
* diagnostic benefits.
|
|
36
|
+
* append serialized data and use `decode*` functions to extract data.
|
|
35
37
|
*
|
|
36
38
|
* ### Example
|
|
37
39
|
*
|
|
@@ -84,7 +86,7 @@ export interface Buffer {
|
|
|
84
86
|
getLength: () => NonNegativeInt;
|
|
85
87
|
/**
|
|
86
88
|
* Appends binary data to the buffer, resizing if necessary. Throws if
|
|
87
|
-
* `arg.length` is not a non-negative integer.
|
|
89
|
+
* `arg.length` is not a non-negative safe integer.
|
|
88
90
|
*/
|
|
89
91
|
extend: (arg: Uint8Array | ArrayLike<number>) => void;
|
|
90
92
|
/**
|
|
@@ -119,4 +121,61 @@ export interface Buffer {
|
|
|
119
121
|
}
|
|
120
122
|
/** Creates a {@link Buffer} for efficient byte operations. */
|
|
121
123
|
export declare const createBuffer: (arrayLike?: Uint8Array | ArrayLike<number>) => Buffer;
|
|
124
|
+
/**
|
|
125
|
+
* Encodes a {@link JsonValue} using the MessagePack format.
|
|
126
|
+
*
|
|
127
|
+
* ### Example
|
|
128
|
+
*
|
|
129
|
+
* ```ts
|
|
130
|
+
* import {
|
|
131
|
+
* assertEqual,
|
|
132
|
+
* createBuffer,
|
|
133
|
+
* encodeJsonValue,
|
|
134
|
+
* JsonValue,
|
|
135
|
+
* } from "@evolu/common";
|
|
136
|
+
*
|
|
137
|
+
* const buffer = createBuffer();
|
|
138
|
+
* const value = JsonValue.orThrow({ name: "Ada" });
|
|
139
|
+
*
|
|
140
|
+
* encodeJsonValue(buffer, value);
|
|
141
|
+
*
|
|
142
|
+
* assertEqual(
|
|
143
|
+
* buffer.unwrap(),
|
|
144
|
+
* new Uint8Array([
|
|
145
|
+
* 0x81, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa3, 0x41, 0x64, 0x61,
|
|
146
|
+
* ]),
|
|
147
|
+
* );
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* Encoding is artificially limited to 1,000 nested arrays or objects to keep
|
|
151
|
+
* recursive encoding and decoding safe and symmetric. JSON data should not
|
|
152
|
+
* require such depth; flatten or split deeply nested data, or use a
|
|
153
|
+
* purpose-built serialization format.
|
|
154
|
+
*/
|
|
155
|
+
export declare const encodeJsonValue: (buffer: Buffer, value: JsonValue) => void;
|
|
156
|
+
/**
|
|
157
|
+
* Decodes a {@link JsonValue} using the MessagePack format.
|
|
158
|
+
*
|
|
159
|
+
* Throws a {@link BufferError} without modifying the Buffer if the encoded value
|
|
160
|
+
* is malformed, truncated, unsupported, outside the JsonValue domain, or
|
|
161
|
+
* exceeds 1,000 nested arrays or objects.
|
|
162
|
+
*
|
|
163
|
+
* ### Example
|
|
164
|
+
*
|
|
165
|
+
* ```ts
|
|
166
|
+
* import {
|
|
167
|
+
* assertEqual,
|
|
168
|
+
* createBuffer,
|
|
169
|
+
* decodeJsonValue,
|
|
170
|
+
* } from "@evolu/common";
|
|
171
|
+
*
|
|
172
|
+
* const buffer = createBuffer([
|
|
173
|
+
* 0x81, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa3, 0x41, 0x64, 0x61,
|
|
174
|
+
* ]);
|
|
175
|
+
*
|
|
176
|
+
* assertEqual(decodeJsonValue(buffer), { name: "Ada" });
|
|
177
|
+
* assertEqual(buffer.unwrap(), new Uint8Array());
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
export declare const decodeJsonValue: (buffer: Buffer) => JsonValue;
|
|
122
181
|
//# sourceMappingURL=Buffer.d.ts.map
|
package/dist/src/Buffer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Buffer.d.ts","sourceRoot":"","sources":["../../src/Buffer.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"Buffer.d.ts","sourceRoot":"","sources":["../../src/Buffer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EACL,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,WAAW,GACZ,MAAM,yBAAyB,CAAC;AAEjC;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAO,EAAE,MAAM,EAK1B;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AACH,MAAM,WAAW,MAAM;IACrB,kDAAkD;IAClD,WAAW,EAAE,MAAM,cAAc,CAAC;IAElC,gEAAgE;IAChE,SAAS,EAAE,MAAM,cAAc,CAAC;IAEhC;;;OAGG;IACH,MAAM,EAAE,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC;IAEtD;;;OAGG;IACH,KAAK,EAAE,MAAM,cAAc,CAAC;IAE5B;;;OAGG;IACH,MAAM,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,UAAU,CAAC;IAE1C;;;OAGG;IACH,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,CAAC;IAE3C;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAElB;;;;OAIG;IACH,MAAM,EAAE,MAAM,UAAU,CAAC;CAC1B;AAED,8DAA8D;AAC9D,eAAO,MAAM,YAAY,eACX,UAAU,GAAG,SAAS,CAAC,MAAM,CAAC,KACzC,MAgEF,CAAC;AAqDF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,SAAS,SAAS,KAAG,IAelE,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,eAAO,MAAM,eAAe,WAAY,MAAM,KAAG,SAwBhD,CAAC"}
|