@evolu/common 8.8.0 → 8.10.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/Assert.d.ts +21 -1
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +31 -27
- package/dist/src/Bytes.d.ts +647 -0
- package/dist/src/Bytes.d.ts.map +1 -0
- package/dist/src/{Binary.js → Bytes.js} +266 -16
- package/dist/src/Config.d.ts +142 -0
- package/dist/src/Config.d.ts.map +1 -0
- package/dist/src/Config.js +181 -0
- package/dist/src/Fs.d.ts +302 -0
- package/dist/src/Fs.d.ts.map +1 -0
- package/dist/src/Fs.js +111 -0
- package/dist/src/Number.d.ts +50 -7
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +47 -8
- package/dist/src/Object.d.ts +32 -0
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +41 -0
- package/dist/src/Polyfills.d.ts +6 -0
- package/dist/src/Polyfills.d.ts.map +1 -1
- package/dist/src/Polyfills.js +6 -0
- package/dist/src/Sqlite.js +1 -1
- package/dist/src/Time.d.ts +74 -12
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +40 -2
- package/dist/src/Type.d.ts +1451 -79
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +1303 -96
- package/dist/src/index.d.ts +3 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -1
- package/dist/src/intl/_en.d.ts +24 -1
- package/dist/src/intl/_en.d.ts.map +1 -1
- package/dist/src/intl/_en.js +20 -0
- package/dist/src/intl/ar.d.ts +24 -1
- package/dist/src/intl/ar.d.ts.map +1 -1
- package/dist/src/intl/ar.js +20 -0
- package/dist/src/intl/bn.d.ts +24 -1
- package/dist/src/intl/bn.d.ts.map +1 -1
- package/dist/src/intl/bn.js +20 -0
- package/dist/src/intl/ca.d.ts +24 -1
- package/dist/src/intl/ca.d.ts.map +1 -1
- package/dist/src/intl/ca.js +20 -0
- package/dist/src/intl/cs.d.ts +24 -1
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +20 -0
- package/dist/src/intl/da.d.ts +24 -1
- package/dist/src/intl/da.d.ts.map +1 -1
- package/dist/src/intl/da.js +20 -0
- package/dist/src/intl/de.d.ts +24 -1
- package/dist/src/intl/de.d.ts.map +1 -1
- package/dist/src/intl/de.js +20 -0
- package/dist/src/intl/el.d.ts +24 -1
- package/dist/src/intl/el.d.ts.map +1 -1
- package/dist/src/intl/el.js +20 -0
- package/dist/src/intl/es.d.ts +24 -1
- package/dist/src/intl/es.d.ts.map +1 -1
- package/dist/src/intl/es.js +20 -0
- package/dist/src/intl/fa.d.ts +24 -1
- package/dist/src/intl/fa.d.ts.map +1 -1
- package/dist/src/intl/fa.js +20 -0
- package/dist/src/intl/fi.d.ts +24 -1
- package/dist/src/intl/fi.d.ts.map +1 -1
- package/dist/src/intl/fi.js +20 -0
- package/dist/src/intl/fil.d.ts +24 -1
- package/dist/src/intl/fil.d.ts.map +1 -1
- package/dist/src/intl/fil.js +20 -0
- package/dist/src/intl/fr.d.ts +24 -1
- package/dist/src/intl/fr.d.ts.map +1 -1
- package/dist/src/intl/fr.js +20 -0
- package/dist/src/intl/he.d.ts +24 -1
- package/dist/src/intl/he.d.ts.map +1 -1
- package/dist/src/intl/he.js +20 -0
- package/dist/src/intl/hi.d.ts +24 -1
- package/dist/src/intl/hi.d.ts.map +1 -1
- package/dist/src/intl/hi.js +20 -0
- package/dist/src/intl/hr.d.ts +24 -1
- package/dist/src/intl/hr.d.ts.map +1 -1
- package/dist/src/intl/hr.js +20 -0
- package/dist/src/intl/hu.d.ts +22 -1
- package/dist/src/intl/hu.d.ts.map +1 -1
- package/dist/src/intl/hu.js +18 -0
- package/dist/src/intl/id.d.ts +24 -1
- package/dist/src/intl/id.d.ts.map +1 -1
- package/dist/src/intl/id.js +20 -0
- package/dist/src/intl/it.d.ts +24 -1
- package/dist/src/intl/it.d.ts.map +1 -1
- package/dist/src/intl/it.js +20 -0
- package/dist/src/intl/ja.d.ts +24 -1
- package/dist/src/intl/ja.d.ts.map +1 -1
- package/dist/src/intl/ja.js +20 -0
- package/dist/src/intl/ko.d.ts +24 -1
- package/dist/src/intl/ko.d.ts.map +1 -1
- package/dist/src/intl/ko.js +20 -0
- package/dist/src/intl/ml.d.ts +24 -1
- package/dist/src/intl/ml.d.ts.map +1 -1
- package/dist/src/intl/ml.js +20 -0
- package/dist/src/intl/mr.d.ts +24 -1
- package/dist/src/intl/mr.d.ts.map +1 -1
- package/dist/src/intl/mr.js +20 -0
- package/dist/src/intl/ms.d.ts +24 -1
- package/dist/src/intl/ms.d.ts.map +1 -1
- package/dist/src/intl/ms.js +20 -0
- package/dist/src/intl/nb.d.ts +22 -1
- package/dist/src/intl/nb.d.ts.map +1 -1
- package/dist/src/intl/nb.js +18 -0
- package/dist/src/intl/nl.d.ts +24 -1
- package/dist/src/intl/nl.d.ts.map +1 -1
- package/dist/src/intl/nl.js +20 -0
- package/dist/src/intl/pa.d.ts +24 -1
- package/dist/src/intl/pa.d.ts.map +1 -1
- package/dist/src/intl/pa.js +20 -0
- package/dist/src/intl/pl.d.ts +23 -0
- package/dist/src/intl/pl.d.ts.map +1 -1
- package/dist/src/intl/pl.js +20 -0
- package/dist/src/intl/pt-BR.d.ts +24 -1
- package/dist/src/intl/pt-BR.d.ts.map +1 -1
- package/dist/src/intl/pt-BR.js +20 -0
- package/dist/src/intl/pt.d.ts +24 -1
- package/dist/src/intl/pt.d.ts.map +1 -1
- package/dist/src/intl/pt.js +20 -0
- package/dist/src/intl/ro.d.ts +24 -1
- package/dist/src/intl/ro.d.ts.map +1 -1
- package/dist/src/intl/ro.js +20 -0
- package/dist/src/intl/sk.d.ts +24 -1
- package/dist/src/intl/sk.d.ts.map +1 -1
- package/dist/src/intl/sk.js +20 -0
- package/dist/src/intl/sl.d.ts +24 -1
- package/dist/src/intl/sl.d.ts.map +1 -1
- package/dist/src/intl/sl.js +20 -0
- package/dist/src/intl/sv.d.ts +24 -1
- package/dist/src/intl/sv.d.ts.map +1 -1
- package/dist/src/intl/sv.js +20 -0
- package/dist/src/intl/sw.d.ts +21 -0
- package/dist/src/intl/sw.d.ts.map +1 -1
- package/dist/src/intl/sw.js +18 -0
- package/dist/src/intl/ta.d.ts +24 -1
- package/dist/src/intl/ta.d.ts.map +1 -1
- package/dist/src/intl/ta.js +20 -0
- package/dist/src/intl/te.d.ts +24 -1
- package/dist/src/intl/te.d.ts.map +1 -1
- package/dist/src/intl/te.js +20 -0
- package/dist/src/intl/th.d.ts +24 -1
- package/dist/src/intl/th.d.ts.map +1 -1
- package/dist/src/intl/th.js +20 -0
- package/dist/src/intl/tr.d.ts +24 -1
- package/dist/src/intl/tr.d.ts.map +1 -1
- package/dist/src/intl/tr.js +20 -0
- package/dist/src/intl/uk.d.ts +80 -57
- package/dist/src/intl/uk.d.ts.map +1 -1
- package/dist/src/intl/uk.js +174 -149
- package/dist/src/intl/ur.d.ts +24 -1
- package/dist/src/intl/ur.d.ts.map +1 -1
- package/dist/src/intl/ur.js +20 -0
- package/dist/src/intl/vi.d.ts +24 -1
- package/dist/src/intl/vi.d.ts.map +1 -1
- package/dist/src/intl/vi.js +20 -0
- package/dist/src/intl/zh-CN.d.ts +24 -1
- package/dist/src/intl/zh-CN.d.ts.map +1 -1
- package/dist/src/intl/zh-CN.js +20 -0
- package/dist/src/intl/zh-TW.d.ts +24 -1
- package/dist/src/intl/zh-TW.d.ts.map +1 -1
- package/dist/src/intl/zh-TW.js +20 -0
- package/dist/src/local-first/Protocol.d.ts +1 -1
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +1 -1
- package/dist/src/local-first/Schema.d.ts +10 -0
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Storage.js +1 -1
- package/dist/src/local-first/Timestamp.js +1 -1
- package/package.json +1 -1
- package/src/Assert.test.ts +51 -0
- package/src/Assert.ts +56 -4
- package/src/{Binary.test.ts → Bytes.test.ts} +286 -1
- package/src/{Binary.ts → Bytes.ts} +652 -21
- package/src/Config.test.ts +672 -0
- package/src/Config.ts +410 -0
- package/src/Fs.test.ts +105 -0
- package/src/Fs.ts +414 -0
- package/src/Number.test.ts +82 -18
- package/src/Number.ts +76 -8
- package/src/Object.test.ts +115 -1
- package/src/Object.ts +44 -0
- package/src/Polyfills.ts +6 -0
- package/src/Sqlite.ts +1 -1
- package/src/Time.test.ts +82 -11
- package/src/Time.ts +141 -16
- package/src/Type.test.ts +3114 -157
- package/src/Type.ts +2553 -196
- package/src/index.ts +3 -1
- package/src/intl/_en.ts +70 -0
- package/src/intl/ar.ts +71 -0
- package/src/intl/bn.ts +70 -0
- package/src/intl/ca.ts +70 -0
- package/src/intl/cs.ts +70 -0
- package/src/intl/da.ts +70 -0
- package/src/intl/de.ts +70 -0
- package/src/intl/el.ts +70 -0
- package/src/intl/es.ts +70 -0
- package/src/intl/fa.ts +70 -0
- package/src/intl/fi.ts +70 -0
- package/src/intl/fil.ts +70 -0
- package/src/intl/fr.ts +70 -0
- package/src/intl/he.ts +70 -0
- package/src/intl/hi.ts +70 -0
- package/src/intl/hr.ts +70 -0
- package/src/intl/hu.ts +69 -0
- package/src/intl/id.ts +70 -0
- package/src/intl/intl.test.ts +819 -1
- package/src/intl/it.ts +70 -0
- package/src/intl/ja.ts +70 -0
- package/src/intl/ko.ts +68 -0
- package/src/intl/ml.ts +70 -0
- package/src/intl/mr.ts +70 -0
- package/src/intl/ms.ts +71 -0
- package/src/intl/nb.ts +69 -0
- package/src/intl/nl.ts +70 -0
- package/src/intl/pa.ts +70 -0
- package/src/intl/pl.ts +63 -0
- package/src/intl/pt-BR.ts +70 -0
- package/src/intl/pt.ts +71 -0
- package/src/intl/ro.ts +70 -0
- package/src/intl/sk.ts +71 -0
- package/src/intl/sl.ts +70 -0
- package/src/intl/sv.ts +70 -0
- package/src/intl/sw.ts +62 -0
- package/src/intl/ta.ts +70 -0
- package/src/intl/te.ts +70 -0
- package/src/intl/th.ts +68 -0
- package/src/intl/tr.ts +70 -0
- package/src/intl/uk.ts +228 -155
- package/src/intl/ur.ts +70 -0
- package/src/intl/vi.ts +70 -0
- package/src/intl/zh-CN.ts +68 -0
- package/src/intl/zh-TW.ts +68 -0
- package/src/local-first/Protocol.test.ts +1 -1
- package/src/local-first/Protocol.ts +1 -1
- package/src/local-first/Schema.ts +11 -0
- package/src/local-first/Storage.ts +1 -1
- package/src/local-first/Timestamp.ts +1 -1
- package/dist/src/Binary.d.ts +0 -254
- package/dist/src/Binary.d.ts.map +0 -1
package/dist/src/Binary.d.ts
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Binary data handling and byte array utilities.
|
|
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
|
-
*
|
|
11
|
-
* @module
|
|
12
|
-
*/
|
|
13
|
-
import { bytesToUtf8, utf8ToBytes } from "@noble/ciphers/utils.js";
|
|
14
|
-
import type { FiniteNumber, JsonValue, NonNegativeInt, PositiveInt } from "./Type.ts";
|
|
15
|
-
export { bytesToHex, concatBytes, hexToBytes } from "@noble/ciphers/utils.js";
|
|
16
|
-
export { bytesToUtf8, utf8ToBytes };
|
|
17
|
-
/**
|
|
18
|
-
* Custom error for {@link Buffer}-related failures like premature end of data.
|
|
19
|
-
* Provides better stack traces for debugging binary protocol issues.
|
|
20
|
-
*/
|
|
21
|
-
export declare class BufferError extends Error {
|
|
22
|
-
constructor(message: string);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* A Buffer is a dynamic, resizable container for binary data, optimized for
|
|
26
|
-
* scenarios where the final size is unknown. It grows exponentially (doubling
|
|
27
|
-
* its capacity) to minimize memory reallocations and uses `subarray` for
|
|
28
|
-
* efficient, copy-free data access in methods like `unwrap` and `shift`.
|
|
29
|
-
*
|
|
30
|
-
* ## Recommended Usage
|
|
31
|
-
*
|
|
32
|
-
* Create as few Buffers as possible—typically one main Buffer for the final
|
|
33
|
-
* output. Temporary Buffers are allowed when necessary (e.g., for
|
|
34
|
-
* variable-length headers), but avoid excessive allocations. Buffers can be
|
|
35
|
-
* reused within functions by leveraging `reset` to clear contents while
|
|
36
|
-
* preserving capacity, or `truncate` to adjust the length to a specific size,
|
|
37
|
-
* reducing the need for new allocations. Pass Buffers to `encode*` functions to
|
|
38
|
-
* append serialized data and use `decode*` functions to extract data.
|
|
39
|
-
*
|
|
40
|
-
* ### Example
|
|
41
|
-
*
|
|
42
|
-
* ```ts
|
|
43
|
-
* import {
|
|
44
|
-
* assertEqual,
|
|
45
|
-
* assertErr,
|
|
46
|
-
* assertInstanceOf,
|
|
47
|
-
* createBuffer,
|
|
48
|
-
* createIdFromString,
|
|
49
|
-
* IdBytes,
|
|
50
|
-
* idBytesToId,
|
|
51
|
-
* idBytesTypeValueLength,
|
|
52
|
-
* idToIdBytes,
|
|
53
|
-
* NonNegativeInt,
|
|
54
|
-
* trySync,
|
|
55
|
-
* decodeNonNegativeInt,
|
|
56
|
-
* encodeNonNegativeInt,
|
|
57
|
-
* } from "@evolu/common";
|
|
58
|
-
*
|
|
59
|
-
* const buffer = createBuffer();
|
|
60
|
-
* const id = createIdFromString("buffer-example");
|
|
61
|
-
* encodeNonNegativeInt(buffer, NonNegativeInt.orThrow(300));
|
|
62
|
-
* buffer.extend(idToIdBytes(id));
|
|
63
|
-
*
|
|
64
|
-
* const decoder = createBuffer(buffer.unwrap());
|
|
65
|
-
* assertEqual(decodeNonNegativeInt(decoder), 300);
|
|
66
|
-
* const decodedId = idBytesToId(
|
|
67
|
-
* IdBytes.orThrow(decoder.shiftN(idBytesTypeValueLength)),
|
|
68
|
-
* );
|
|
69
|
-
* assertEqual(decodedId, id);
|
|
70
|
-
* const result = trySync(() => decodeNonNegativeInt(decoder));
|
|
71
|
-
* assertErr(result);
|
|
72
|
-
* assertInstanceOf(result.error, Error);
|
|
73
|
-
* assertEqual(result.error.message, "Buffer parse ended prematurely");
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* For more on exponential growth, see:
|
|
77
|
-
* https://blog.mozilla.org/nnethercote/2014/11/04/please-grow-your-buffers-exponentially
|
|
78
|
-
*/
|
|
79
|
-
export interface Buffer {
|
|
80
|
-
/** Returns the current capacity of the buffer. */
|
|
81
|
-
getCapacity: () => NonNegativeInt;
|
|
82
|
-
/** Returns the current number of bytes stored in the buffer. */
|
|
83
|
-
getLength: () => NonNegativeInt;
|
|
84
|
-
/**
|
|
85
|
-
* Appends binary data to the buffer, resizing if necessary. Throws if
|
|
86
|
-
* `arg.length` is not a non-negative safe integer.
|
|
87
|
-
*/
|
|
88
|
-
extend: (arg: Uint8Array | ArrayLike<number>) => void;
|
|
89
|
-
/**
|
|
90
|
-
* Removes and returns the first byte. Throws an `Error` with message "Buffer
|
|
91
|
-
* parse ended prematurely" if the buffer is empty.
|
|
92
|
-
*/
|
|
93
|
-
shift: () => NonNegativeInt;
|
|
94
|
-
/**
|
|
95
|
-
* Removes and returns the first `n` bytes. Throws an `Error` with message
|
|
96
|
-
* "Buffer parse ended prematurely" if fewer than `n` bytes remain.
|
|
97
|
-
*/
|
|
98
|
-
shiftN: (n: NonNegativeInt) => Uint8Array;
|
|
99
|
-
/**
|
|
100
|
-
* Truncates the buffer to the specified length, discarding data from the end.
|
|
101
|
-
* Throws if the new length is greater than the current length.
|
|
102
|
-
*/
|
|
103
|
-
truncate: (length: NonNegativeInt) => void;
|
|
104
|
-
/**
|
|
105
|
-
* Resets the buffer to its initial empty state, preserving its capacity.
|
|
106
|
-
*
|
|
107
|
-
* This allows efficient buffer reuse without reallocating memory. Use this
|
|
108
|
-
* when you want to clear the buffer and write new data, avoiding unnecessary
|
|
109
|
-
* allocations.
|
|
110
|
-
*/
|
|
111
|
-
reset: () => void;
|
|
112
|
-
/**
|
|
113
|
-
* Returns a view of the buffer’s current data. Do not modify this array, as
|
|
114
|
-
* it directly alters the buffer’s internal state, potentially breaking
|
|
115
|
-
* subsequent operations.
|
|
116
|
-
*/
|
|
117
|
-
unwrap: () => Uint8Array;
|
|
118
|
-
}
|
|
119
|
-
/** Creates a {@link Buffer} for efficient byte operations. */
|
|
120
|
-
export declare const createBuffer: (arrayLike?: Uint8Array | ArrayLike<number>) => Buffer;
|
|
121
|
-
/**
|
|
122
|
-
* Evolu uses MessagePack to handle finite numbers except for NonNegativeInt.
|
|
123
|
-
* For NonNegativeInt, Evolu provides more efficient encoding.
|
|
124
|
-
*/
|
|
125
|
-
export declare const encodeNumber: (buffer: Buffer, number: FiniteNumber) => void;
|
|
126
|
-
export declare const decodeNumber: (buffer: Buffer) => FiniteNumber;
|
|
127
|
-
/**
|
|
128
|
-
* Encodes an array of boolean flags into a single byte.
|
|
129
|
-
*
|
|
130
|
-
* Each element in the array corresponds to a bit (0-7). Array can have 0-8
|
|
131
|
-
* elements.
|
|
132
|
-
*
|
|
133
|
-
* ### Example
|
|
134
|
-
*
|
|
135
|
-
* ```ts
|
|
136
|
-
* import { assertEqual, createBuffer, encodeFlags } from "@evolu/common";
|
|
137
|
-
*
|
|
138
|
-
* const buffer = createBuffer();
|
|
139
|
-
* encodeFlags(buffer, [true, false, true]);
|
|
140
|
-
*
|
|
141
|
-
* assertEqual(buffer.unwrap(), new Uint8Array([0b101]));
|
|
142
|
-
* ```
|
|
143
|
-
*/
|
|
144
|
-
export declare const encodeFlags: (buffer: Buffer, flags: ReadonlyArray<boolean>) => void;
|
|
145
|
-
/**
|
|
146
|
-
* Decodes a byte into an array of boolean flags.
|
|
147
|
-
*
|
|
148
|
-
* ### Example
|
|
149
|
-
*
|
|
150
|
-
* ```ts
|
|
151
|
-
* import {
|
|
152
|
-
* assertEqual,
|
|
153
|
-
* createBuffer,
|
|
154
|
-
* decodeFlags,
|
|
155
|
-
* PositiveInt,
|
|
156
|
-
* } from "@evolu/common";
|
|
157
|
-
*
|
|
158
|
-
* const buffer = createBuffer([0b101]);
|
|
159
|
-
* const flags = decodeFlags(buffer, PositiveInt.orThrow(3));
|
|
160
|
-
*
|
|
161
|
-
* assertEqual(flags, [true, false, true]);
|
|
162
|
-
* assertEqual(buffer.getLength(), 0);
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export declare const decodeFlags: (buffer: Buffer, count: PositiveInt) => ReadonlyArray<boolean>;
|
|
166
|
-
/**
|
|
167
|
-
* Encodes a non-negative integer into a variable-length integer format. It's
|
|
168
|
-
* more efficient than encoding via {@link encodeNumber}.
|
|
169
|
-
*
|
|
170
|
-
* https://en.wikipedia.org/wiki/Variable-length_quantity
|
|
171
|
-
*/
|
|
172
|
-
export declare const encodeNonNegativeInt: (buffer: Buffer, value: NonNegativeInt) => void;
|
|
173
|
-
/**
|
|
174
|
-
* Decodes a non-negative integer from a variable-length integer format.
|
|
175
|
-
*
|
|
176
|
-
* https://en.wikipedia.org/wiki/Variable-length_quantity
|
|
177
|
-
*/
|
|
178
|
-
export declare const decodeNonNegativeInt: (buffer: Buffer) => NonNegativeInt;
|
|
179
|
-
/** Encodes the length of an array-like value. */
|
|
180
|
-
export declare const encodeLength: (buffer: Buffer, value: ArrayLike<unknown>) => void;
|
|
181
|
-
/** Decodes an array-like value length. */
|
|
182
|
-
export declare const decodeLength: typeof decodeNonNegativeInt;
|
|
183
|
-
/** Encodes a length-prefixed UTF-8 string. */
|
|
184
|
-
export declare const encodeString: (buffer: Buffer, value: string) => void;
|
|
185
|
-
/** Decodes a length-prefixed UTF-8 string. */
|
|
186
|
-
export declare const decodeString: (buffer: Buffer) => string;
|
|
187
|
-
/** Incrementally encodes consecutive equal values using run-length encoding. */
|
|
188
|
-
export interface RunLengthEncoder<T> {
|
|
189
|
-
readonly add: (value: T) => void;
|
|
190
|
-
readonly getLength: () => NonNegativeInt;
|
|
191
|
-
readonly unwrap: () => Uint8Array;
|
|
192
|
-
}
|
|
193
|
-
/** Creates an incremental run-length encoder. */
|
|
194
|
-
export declare const createRunLengthEncoder: <T>(encodeValue: (buffer: Buffer, value: T) => void) => RunLengthEncoder<T>;
|
|
195
|
-
/** Decodes a run-length encoded sequence. */
|
|
196
|
-
export declare const decodeRle: <T>(buffer: Buffer, length: NonNegativeInt, decodeValue: () => T) => ReadonlyArray<T>;
|
|
197
|
-
/**
|
|
198
|
-
* Encodes a {@link JsonValue} using the MessagePack format.
|
|
199
|
-
*
|
|
200
|
-
* ### Example
|
|
201
|
-
*
|
|
202
|
-
* ```ts
|
|
203
|
-
* import {
|
|
204
|
-
* assertEqual,
|
|
205
|
-
* createBuffer,
|
|
206
|
-
* encodeJsonValue,
|
|
207
|
-
* JsonValue,
|
|
208
|
-
* } from "@evolu/common";
|
|
209
|
-
*
|
|
210
|
-
* const buffer = createBuffer();
|
|
211
|
-
* const value = JsonValue.orThrow({ name: "Ada" });
|
|
212
|
-
*
|
|
213
|
-
* encodeJsonValue(buffer, value);
|
|
214
|
-
*
|
|
215
|
-
* assertEqual(
|
|
216
|
-
* buffer.unwrap(),
|
|
217
|
-
* new Uint8Array([
|
|
218
|
-
* 0x81, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa3, 0x41, 0x64, 0x61,
|
|
219
|
-
* ]),
|
|
220
|
-
* );
|
|
221
|
-
* ```
|
|
222
|
-
*
|
|
223
|
-
* Encoding is artificially limited to 1,000 nested arrays or objects to keep
|
|
224
|
-
* recursive encoding and decoding safe and symmetric. JSON data should not
|
|
225
|
-
* require such depth; flatten or split deeply nested data, or use a
|
|
226
|
-
* purpose-built serialization format.
|
|
227
|
-
*/
|
|
228
|
-
export declare const encodeJsonValue: (buffer: Buffer, value: JsonValue) => void;
|
|
229
|
-
/**
|
|
230
|
-
* Decodes a {@link JsonValue} using the MessagePack format.
|
|
231
|
-
*
|
|
232
|
-
* Throws a {@link BufferError} without modifying the Buffer if the encoded value
|
|
233
|
-
* is malformed, truncated, unsupported, outside the JsonValue domain, or
|
|
234
|
-
* exceeds 1,000 nested arrays or objects.
|
|
235
|
-
*
|
|
236
|
-
* ### Example
|
|
237
|
-
*
|
|
238
|
-
* ```ts
|
|
239
|
-
* import {
|
|
240
|
-
* assertEqual,
|
|
241
|
-
* createBuffer,
|
|
242
|
-
* decodeJsonValue,
|
|
243
|
-
* } from "@evolu/common";
|
|
244
|
-
*
|
|
245
|
-
* const buffer = createBuffer([
|
|
246
|
-
* 0x81, 0xa4, 0x6e, 0x61, 0x6d, 0x65, 0xa3, 0x41, 0x64, 0x61,
|
|
247
|
-
* ]);
|
|
248
|
-
*
|
|
249
|
-
* assertEqual(decodeJsonValue(buffer), { name: "Ada" });
|
|
250
|
-
* assertEqual(buffer.unwrap(), new Uint8Array());
|
|
251
|
-
* ```
|
|
252
|
-
*/
|
|
253
|
-
export declare const decodeJsonValue: (buffer: Buffer) => JsonValue;
|
|
254
|
-
//# sourceMappingURL=Binary.d.ts.map
|
package/dist/src/Binary.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Binary.d.ts","sourceRoot":"","sources":["../../src/Binary.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEnE,OAAO,KAAK,EACV,YAAY,EACZ,SAAS,EACT,cAAc,EACd,WAAW,EACZ,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAEpC;;;GAGG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAO,EAAE,MAAM,EAK1B;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