@evolu/common 8.6.2 → 8.8.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/Array.d.ts +21 -21
- package/dist/src/Array.js +5 -5
- package/dist/src/Assert.d.ts +478 -141
- package/dist/src/Assert.d.ts.map +1 -1
- package/dist/src/Assert.js +644 -99
- package/dist/src/Binary.d.ts +254 -0
- package/dist/src/Binary.d.ts.map +1 -0
- package/dist/src/Binary.js +958 -0
- package/dist/src/Console.d.ts +2 -10
- package/dist/src/Console.d.ts.map +1 -1
- package/dist/src/Console.js +6 -12
- package/dist/src/Crypto.d.ts +5 -5
- package/dist/src/Crypto.js +1 -1
- package/dist/src/Eq.d.ts +35 -40
- package/dist/src/Eq.d.ts.map +1 -1
- package/dist/src/Eq.js +51 -87
- package/dist/src/Function.d.ts +9 -14
- package/dist/src/Function.d.ts.map +1 -1
- package/dist/src/Function.js +7 -9
- package/dist/src/Http.d.ts +6 -7
- package/dist/src/Http.d.ts.map +1 -1
- package/dist/src/LeakDetector.d.ts.map +1 -1
- package/dist/src/LeakDetector.js +1 -0
- package/dist/src/LockManager.d.ts +1 -1
- package/dist/src/LockManager.js +1 -1
- package/dist/src/Lookup.d.ts +3 -2
- package/dist/src/Lookup.d.ts.map +1 -1
- package/dist/src/Lookup.js +4 -3
- package/dist/src/Number.d.ts +1 -1
- package/dist/src/Number.d.ts.map +1 -1
- package/dist/src/Number.js +1 -1
- package/dist/src/Object.d.ts +4 -4
- package/dist/src/Object.d.ts.map +1 -1
- package/dist/src/Object.js +5 -4
- package/dist/src/Option.d.ts +1 -2
- package/dist/src/Option.d.ts.map +1 -1
- package/dist/src/Option.js +1 -2
- package/dist/src/Platform.js +2 -0
- package/dist/src/Polyfills.js +4 -1
- package/dist/src/Random.d.ts +1 -1
- package/dist/src/Result.d.ts +49 -54
- package/dist/src/Result.d.ts.map +1 -1
- package/dist/src/Result.js +17 -22
- package/dist/src/Set.d.ts +6 -6
- package/dist/src/Set.js +2 -2
- package/dist/src/Sqlite.js +1 -1
- package/dist/src/String.js +3 -2
- package/dist/src/Task.d.ts +32 -32
- package/dist/src/Task.d.ts.map +1 -1
- package/dist/src/Task.js +20 -22
- package/dist/src/Test.d.ts +31 -3
- package/dist/src/Test.d.ts.map +1 -1
- package/dist/src/Test.js +46 -3
- package/dist/src/Time.d.ts +3 -11
- package/dist/src/Time.d.ts.map +1 -1
- package/dist/src/Time.js +10 -18
- package/dist/src/Type.d.ts +87 -85
- package/dist/src/Type.d.ts.map +1 -1
- package/dist/src/Type.js +70 -63
- package/dist/src/Types.d.ts +12 -12
- package/dist/src/Types.js +1 -1
- package/dist/src/WebSocket.d.ts +4 -7
- package/dist/src/WebSocket.d.ts.map +1 -1
- package/dist/src/Worker.d.ts +1 -1
- package/dist/src/Worker.js +7 -7
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/intl/_en.d.ts.map +1 -1
- package/dist/src/intl/_en.js +1 -1
- package/dist/src/intl/ar.d.ts.map +1 -1
- package/dist/src/intl/ar.js +1 -1
- package/dist/src/intl/bn.d.ts.map +1 -1
- package/dist/src/intl/bn.js +1 -1
- package/dist/src/intl/ca.d.ts.map +1 -1
- package/dist/src/intl/ca.js +1 -1
- package/dist/src/intl/cs.d.ts.map +1 -1
- package/dist/src/intl/cs.js +1 -1
- package/dist/src/intl/da.d.ts.map +1 -1
- package/dist/src/intl/da.js +1 -1
- package/dist/src/intl/de.d.ts.map +1 -1
- package/dist/src/intl/de.js +1 -1
- package/dist/src/intl/el.d.ts.map +1 -1
- package/dist/src/intl/el.js +1 -1
- package/dist/src/intl/es.d.ts.map +1 -1
- package/dist/src/intl/es.js +1 -1
- package/dist/src/intl/fa.d.ts.map +1 -1
- package/dist/src/intl/fa.js +1 -1
- package/dist/src/intl/fi.d.ts.map +1 -1
- package/dist/src/intl/fi.js +1 -1
- package/dist/src/intl/fil.d.ts.map +1 -1
- package/dist/src/intl/fil.js +1 -1
- package/dist/src/intl/fr.d.ts.map +1 -1
- package/dist/src/intl/fr.js +1 -1
- package/dist/src/intl/he.d.ts.map +1 -1
- package/dist/src/intl/he.js +1 -1
- package/dist/src/intl/hi.d.ts.map +1 -1
- package/dist/src/intl/hi.js +1 -1
- package/dist/src/intl/hr.d.ts.map +1 -1
- package/dist/src/intl/hr.js +1 -1
- package/dist/src/intl/hu.d.ts.map +1 -1
- package/dist/src/intl/hu.js +1 -1
- package/dist/src/intl/id.d.ts.map +1 -1
- package/dist/src/intl/id.js +1 -1
- package/dist/src/intl/it.d.ts.map +1 -1
- package/dist/src/intl/it.js +1 -1
- package/dist/src/intl/ja.d.ts.map +1 -1
- package/dist/src/intl/ja.js +1 -1
- package/dist/src/intl/ko.d.ts.map +1 -1
- package/dist/src/intl/ko.js +1 -1
- package/dist/src/intl/ml.d.ts.map +1 -1
- package/dist/src/intl/ml.js +1 -1
- package/dist/src/intl/mr.d.ts.map +1 -1
- package/dist/src/intl/mr.js +1 -1
- package/dist/src/intl/ms.d.ts.map +1 -1
- package/dist/src/intl/ms.js +1 -1
- package/dist/src/intl/nb.d.ts.map +1 -1
- package/dist/src/intl/nb.js +1 -1
- package/dist/src/intl/nl.d.ts.map +1 -1
- package/dist/src/intl/nl.js +1 -1
- package/dist/src/intl/pa.d.ts.map +1 -1
- package/dist/src/intl/pa.js +1 -1
- package/dist/src/intl/pl.d.ts.map +1 -1
- package/dist/src/intl/pl.js +1 -1
- package/dist/src/intl/pt-BR.d.ts.map +1 -1
- package/dist/src/intl/pt-BR.js +1 -1
- package/dist/src/intl/pt.d.ts.map +1 -1
- package/dist/src/intl/pt.js +1 -1
- package/dist/src/intl/ro.d.ts.map +1 -1
- package/dist/src/intl/ro.js +1 -1
- package/dist/src/intl/sk.d.ts.map +1 -1
- package/dist/src/intl/sk.js +1 -1
- package/dist/src/intl/sl.d.ts.map +1 -1
- package/dist/src/intl/sl.js +1 -1
- package/dist/src/intl/sv.d.ts.map +1 -1
- package/dist/src/intl/sv.js +1 -1
- package/dist/src/intl/sw.d.ts.map +1 -1
- package/dist/src/intl/sw.js +1 -1
- package/dist/src/intl/ta.d.ts.map +1 -1
- package/dist/src/intl/ta.js +1 -1
- package/dist/src/intl/te.d.ts.map +1 -1
- package/dist/src/intl/te.js +1 -1
- package/dist/src/intl/th.d.ts.map +1 -1
- package/dist/src/intl/th.js +1 -1
- package/dist/src/intl/tr.d.ts.map +1 -1
- package/dist/src/intl/tr.js +1 -1
- package/dist/src/intl/uk.d.ts.map +1 -1
- package/dist/src/intl/uk.js +1 -1
- package/dist/src/intl/ur.d.ts.map +1 -1
- package/dist/src/intl/ur.js +1 -1
- package/dist/src/intl/vi.d.ts.map +1 -1
- package/dist/src/intl/vi.js +1 -1
- package/dist/src/intl/zh-CN.d.ts.map +1 -1
- package/dist/src/intl/zh-CN.js +1 -1
- package/dist/src/intl/zh-TW.d.ts.map +1 -1
- package/dist/src/intl/zh-TW.js +1 -1
- package/dist/src/local-first/Evolu.d.ts +12 -12
- package/dist/src/local-first/Evolu.d.ts.map +1 -1
- package/dist/src/local-first/Evolu.js +2 -2
- package/dist/src/local-first/Protocol.d.ts +28 -76
- package/dist/src/local-first/Protocol.d.ts.map +1 -1
- package/dist/src/local-first/Protocol.js +45 -229
- package/dist/src/local-first/Query.d.ts +11 -11
- package/dist/src/local-first/Query.js +6 -6
- package/dist/src/local-first/Relay.d.ts +2 -2
- package/dist/src/local-first/Schema.d.ts +3 -5
- package/dist/src/local-first/Schema.d.ts.map +1 -1
- package/dist/src/local-first/Schema.js +2 -4
- package/dist/src/local-first/Shared.d.ts.map +1 -1
- package/dist/src/local-first/Shared.js +5 -5
- package/dist/src/local-first/Storage.js +4 -4
- package/dist/src/local-first/Timestamp.d.ts +9 -0
- package/dist/src/local-first/Timestamp.d.ts.map +1 -1
- package/dist/src/local-first/Timestamp.js +13 -10
- package/package.json +7 -5
- package/src/Array.test.ts +809 -0
- package/src/Array.ts +21 -21
- package/src/Assert.test.ts +1181 -0
- package/src/Assert.ts +971 -227
- package/src/BigInt.test.ts +28 -0
- package/src/Binary.test.ts +1128 -0
- package/src/Binary.ts +1377 -0
- package/src/Brand.test.ts +90 -0
- package/src/Cache.test.ts +183 -0
- package/src/Callbacks.test.ts +66 -0
- package/src/Console.test.ts +809 -0
- package/src/Console.ts +9 -17
- package/src/Crypto.test.ts +138 -0
- package/src/Crypto.ts +5 -5
- package/src/Eq.test.ts +333 -0
- package/src/Eq.ts +110 -176
- package/src/Error.test.ts +118 -0
- package/src/Function.test.ts +204 -0
- package/src/Function.ts +10 -15
- package/src/Http.test.ts +816 -0
- package/src/Http.ts +6 -7
- package/src/LeakDetector.test.ts +210 -0
- package/src/LeakDetector.ts +1 -0
- package/src/LockManager.ts +2 -2
- package/src/Lookup.test.ts +418 -0
- package/src/Lookup.ts +4 -3
- package/src/Microtask.test.ts +140 -0
- package/src/Number.test.ts +218 -0
- package/src/Number.ts +2 -2
- package/src/Object.test.ts +293 -0
- package/src/Object.ts +5 -4
- package/src/Option.test.ts +104 -0
- package/src/Option.ts +1 -2
- package/src/Order.test.ts +56 -0
- package/src/Platform.ts +2 -0
- package/src/Polyfills.ts +3 -4
- package/src/Random.test.ts +89 -0
- package/src/Random.ts +1 -1
- package/src/Ref.test.ts +139 -0
- package/src/RefCount.test.ts +184 -0
- package/src/Relation.test.ts +505 -0
- package/src/Resource.test.ts +4623 -0
- package/src/Result.test.ts +1829 -0
- package/src/Result.ts +49 -54
- package/src/Schedule.test.ts +1554 -0
- package/src/Set.test.ts +279 -0
- package/src/Set.ts +6 -6
- package/src/Sqlite.ts +1 -1
- package/src/Store.test.ts +288 -0
- package/src/String.test.ts +54 -0
- package/src/String.ts +3 -3
- package/src/Task.test.ts +10820 -0
- package/src/Task.ts +38 -43
- package/src/Test.test.ts +88 -0
- package/src/Test.ts +49 -3
- package/src/Time.test.ts +926 -0
- package/src/Time.ts +13 -21
- package/src/Type.base64.test.ts +88 -0
- package/src/Type.test.ts +20465 -0
- package/src/Type.ts +114 -111
- package/src/Types.test.ts +324 -0
- package/src/Types.ts +13 -13
- package/src/WebSocket.ts +4 -7
- package/src/Worker.test.ts +755 -0
- package/src/Worker.ts +13 -18
- package/src/index.ts +1 -1
- package/src/intl/_en.ts +1 -1
- package/src/intl/ar.ts +1 -1
- package/src/intl/bn.ts +1 -1
- package/src/intl/ca.ts +1 -1
- package/src/intl/cs.ts +1 -1
- package/src/intl/da.ts +1 -1
- package/src/intl/de.ts +1 -1
- package/src/intl/el.ts +1 -1
- package/src/intl/es.ts +1 -1
- package/src/intl/fa.ts +1 -1
- package/src/intl/fi.ts +1 -1
- package/src/intl/fil.ts +1 -1
- package/src/intl/fr.ts +1 -1
- package/src/intl/he.ts +1 -1
- package/src/intl/hi.ts +1 -1
- package/src/intl/hr.ts +1 -1
- package/src/intl/hu.ts +1 -1
- package/src/intl/id.ts +1 -1
- package/src/intl/intl.test.ts +3106 -0
- package/src/intl/it.ts +1 -1
- package/src/intl/ja.ts +1 -1
- package/src/intl/ko.ts +1 -1
- package/src/intl/ml.ts +1 -1
- package/src/intl/mr.ts +1 -1
- package/src/intl/ms.ts +1 -1
- package/src/intl/nb.ts +1 -1
- package/src/intl/nl.ts +1 -1
- package/src/intl/pa.ts +1 -1
- package/src/intl/pl.ts +1 -1
- package/src/intl/pt-BR.ts +1 -1
- package/src/intl/pt.ts +1 -1
- package/src/intl/ro.ts +1 -1
- package/src/intl/sk.ts +1 -1
- package/src/intl/sl.ts +1 -1
- package/src/intl/sv.ts +1 -1
- package/src/intl/sw.ts +1 -1
- package/src/intl/ta.ts +1 -1
- package/src/intl/te.ts +1 -1
- package/src/intl/th.ts +1 -1
- package/src/intl/tr.ts +1 -1
- package/src/intl/uk.ts +1 -1
- package/src/intl/ur.ts +1 -1
- package/src/intl/vi.ts +1 -1
- package/src/intl/zh-CN.ts +1 -1
- package/src/intl/zh-TW.ts +1 -1
- package/src/local-first/Evolu.test.ts +1921 -0
- package/src/local-first/Evolu.ts +18 -14
- package/src/local-first/Owner.test.ts +83 -0
- package/src/local-first/Protocol.test.ts +1037 -0
- package/src/local-first/Protocol.ts +75 -290
- package/src/local-first/Query.test.ts +349 -0
- package/src/local-first/Query.ts +11 -11
- package/src/local-first/Relay.ts +2 -2
- package/src/local-first/Schema.ts +3 -5
- package/src/local-first/Shared.test.ts +1828 -0
- package/src/local-first/Shared.ts +9 -8
- package/src/local-first/Storage.ts +4 -4
- package/src/local-first/Timestamp.test.ts +374 -0
- package/src/local-first/Timestamp.ts +22 -10
- package/dist/src/Buffer.d.ts +0 -122
- package/dist/src/Buffer.d.ts.map +0 -1
- package/dist/src/Buffer.js +0 -69
- package/src/Buffer.ts +0 -206
package/src/Buffer.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Binary data handling and byte array utilities.
|
|
3
|
-
*
|
|
4
|
-
* @module
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { Result } from "./Result.ts";
|
|
8
|
-
import { NonNegativeInt, zeroNonNegativeInt } from "./Type.ts";
|
|
9
|
-
export {
|
|
10
|
-
bytesToHex,
|
|
11
|
-
bytesToUtf8,
|
|
12
|
-
concatBytes,
|
|
13
|
-
hexToBytes,
|
|
14
|
-
utf8ToBytes,
|
|
15
|
-
} from "@noble/ciphers/utils.js";
|
|
16
|
-
|
|
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 class BufferError extends Error {
|
|
22
|
-
constructor(message: string) {
|
|
23
|
-
super(message);
|
|
24
|
-
this.name = this.constructor.name;
|
|
25
|
-
|
|
26
|
-
Error.captureStackTrace(this, this.constructor);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* A Buffer is a dynamic, resizable container for binary data, optimized for
|
|
32
|
-
* scenarios where the final size is unknown. It grows exponentially (doubling
|
|
33
|
-
* its capacity) to minimize memory reallocations and uses `subarray` for
|
|
34
|
-
* efficient, copy-free data access in methods like `unwrap` and `shift`.
|
|
35
|
-
*
|
|
36
|
-
* ## Recommended Usage
|
|
37
|
-
*
|
|
38
|
-
* Create as few Buffers as possible—typically one main Buffer for the final
|
|
39
|
-
* output. Temporary Buffers are allowed when necessary (e.g., for
|
|
40
|
-
* variable-length headers), but avoid excessive allocations. Buffers can be
|
|
41
|
-
* reused within functions by leveraging `reset` to clear contents while
|
|
42
|
-
* preserving capacity, or `truncate` to adjust the length to a specific size,
|
|
43
|
-
* reducing the need for new allocations. Pass Buffers to `encode*` functions to
|
|
44
|
-
* append serialized data and use `decode*` functions to extract data. Both
|
|
45
|
-
* `shift` and `shiftN` throw an {@link BufferError} with message "Buffer parse
|
|
46
|
-
* ended prematurely" on failure, as do higher-level `decode*` functions,
|
|
47
|
-
* providing stack traces for debugging instead of using {@link Result}. This
|
|
48
|
-
* avoids allocation overhead in success cases and leverages exceptions'
|
|
49
|
-
* diagnostic benefits.
|
|
50
|
-
*
|
|
51
|
-
* ### Example
|
|
52
|
-
*
|
|
53
|
-
* ```ts
|
|
54
|
-
* import {
|
|
55
|
-
* assert,
|
|
56
|
-
* assertEqual,
|
|
57
|
-
* assertErr,
|
|
58
|
-
* createBuffer,
|
|
59
|
-
* createIdFromString,
|
|
60
|
-
* IdBytes,
|
|
61
|
-
* idBytesToId,
|
|
62
|
-
* idBytesTypeValueLength,
|
|
63
|
-
* idToIdBytes,
|
|
64
|
-
* NonNegativeInt,
|
|
65
|
-
* trySync,
|
|
66
|
-
* } from "@evolu/common";
|
|
67
|
-
* import {
|
|
68
|
-
* decodeNonNegativeInt,
|
|
69
|
-
* encodeNonNegativeInt,
|
|
70
|
-
* } from "@evolu/common/local-first";
|
|
71
|
-
*
|
|
72
|
-
* const buffer = createBuffer();
|
|
73
|
-
* const id = createIdFromString("buffer-example");
|
|
74
|
-
* encodeNonNegativeInt(buffer, NonNegativeInt.orThrow(300));
|
|
75
|
-
* buffer.extend(idToIdBytes(id));
|
|
76
|
-
*
|
|
77
|
-
* const decoder = createBuffer(buffer.unwrap());
|
|
78
|
-
* assertEqual(decodeNonNegativeInt(decoder), 300);
|
|
79
|
-
* const decodedId = idBytesToId(
|
|
80
|
-
* IdBytes.orThrow(decoder.shiftN(idBytesTypeValueLength)),
|
|
81
|
-
* );
|
|
82
|
-
* assertEqual(decodedId, id);
|
|
83
|
-
* const result = trySync(() => decodeNonNegativeInt(decoder));
|
|
84
|
-
* assertErr(result);
|
|
85
|
-
* assert(
|
|
86
|
-
* result.error instanceof Error &&
|
|
87
|
-
* result.error.message === "Buffer parse ended prematurely",
|
|
88
|
-
* "Expected the premature-buffer-end error.",
|
|
89
|
-
* );
|
|
90
|
-
* ```
|
|
91
|
-
*
|
|
92
|
-
* For more on exponential growth, see:
|
|
93
|
-
* https://blog.mozilla.org/nnethercote/2014/11/04/please-grow-your-buffers-exponentially
|
|
94
|
-
*/
|
|
95
|
-
export interface Buffer {
|
|
96
|
-
/** Returns the current capacity of the buffer. */
|
|
97
|
-
getCapacity: () => NonNegativeInt;
|
|
98
|
-
|
|
99
|
-
/** Returns the current number of bytes stored in the buffer. */
|
|
100
|
-
getLength: () => NonNegativeInt;
|
|
101
|
-
|
|
102
|
-
/**
|
|
103
|
-
* Appends binary data to the buffer, resizing if necessary. Throws if
|
|
104
|
-
* `arg.length` is not a non-negative integer.
|
|
105
|
-
*/
|
|
106
|
-
extend: (arg: Uint8Array | ArrayLike<number>) => void;
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Removes and returns the first byte. Throws an `Error` with message "Buffer
|
|
110
|
-
* parse ended prematurely" if the buffer is empty.
|
|
111
|
-
*/
|
|
112
|
-
shift: () => NonNegativeInt;
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Removes and returns the first `n` bytes. Throws an `Error` with message
|
|
116
|
-
* "Buffer parse ended prematurely" if fewer than `n` bytes remain.
|
|
117
|
-
*/
|
|
118
|
-
shiftN: (n: NonNegativeInt) => Uint8Array;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Truncates the buffer to the specified length, discarding data from the end.
|
|
122
|
-
* Throws if the new length is greater than the current length.
|
|
123
|
-
*/
|
|
124
|
-
truncate: (length: NonNegativeInt) => void;
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Resets the buffer to its initial empty state, preserving its capacity.
|
|
128
|
-
*
|
|
129
|
-
* This allows efficient buffer reuse without reallocating memory. Use this
|
|
130
|
-
* when you want to clear the buffer and write new data, avoiding unnecessary
|
|
131
|
-
* allocations.
|
|
132
|
-
*/
|
|
133
|
-
reset: () => void;
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Returns a view of the buffer’s current data. Do not modify this array, as
|
|
137
|
-
* it directly alters the buffer’s internal state, potentially breaking
|
|
138
|
-
* subsequent operations.
|
|
139
|
-
*/
|
|
140
|
-
unwrap: () => Uint8Array;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** Creates a {@link Buffer} for efficient byte operations. */
|
|
144
|
-
export const createBuffer = (
|
|
145
|
-
arrayLike?: Uint8Array | ArrayLike<number>,
|
|
146
|
-
): Buffer => {
|
|
147
|
-
let value = arrayLike
|
|
148
|
-
? new globalThis.Uint8Array(arrayLike)
|
|
149
|
-
: new globalThis.Uint8Array(512);
|
|
150
|
-
let length = NonNegativeInt.orThrow(arrayLike ? arrayLike.length : 0);
|
|
151
|
-
|
|
152
|
-
const buffer: Buffer = {
|
|
153
|
-
getCapacity: () => NonNegativeInt.orThrow(value.length),
|
|
154
|
-
|
|
155
|
-
getLength: () => length,
|
|
156
|
-
|
|
157
|
-
extend: (arg) => {
|
|
158
|
-
const targetSize = length + arg.length;
|
|
159
|
-
if (value.length < targetSize) {
|
|
160
|
-
const oldValue = value;
|
|
161
|
-
const newCapacity = Math.max(value.length * 2, targetSize);
|
|
162
|
-
value = new globalThis.Uint8Array(newCapacity);
|
|
163
|
-
value.set(oldValue);
|
|
164
|
-
}
|
|
165
|
-
value.set(arg, length);
|
|
166
|
-
length = NonNegativeInt.orThrow(length + arg.length);
|
|
167
|
-
},
|
|
168
|
-
|
|
169
|
-
shift: () => {
|
|
170
|
-
if (length === 0) {
|
|
171
|
-
throw new BufferError("Buffer parse ended prematurely");
|
|
172
|
-
}
|
|
173
|
-
const first = value[0];
|
|
174
|
-
value = value.subarray(1);
|
|
175
|
-
length--;
|
|
176
|
-
return NonNegativeInt.orThrow(first);
|
|
177
|
-
},
|
|
178
|
-
|
|
179
|
-
shiftN: (n) => {
|
|
180
|
-
if (length < n) {
|
|
181
|
-
throw new BufferError("Buffer parse ended prematurely");
|
|
182
|
-
}
|
|
183
|
-
const subarray = value.subarray(0, n);
|
|
184
|
-
value = value.subarray(n);
|
|
185
|
-
length = NonNegativeInt.orThrow(length - n);
|
|
186
|
-
return subarray;
|
|
187
|
-
},
|
|
188
|
-
|
|
189
|
-
truncate: (newLength) => {
|
|
190
|
-
if (newLength > length) {
|
|
191
|
-
throw new BufferError(
|
|
192
|
-
"Cannot truncate to a length greater than current",
|
|
193
|
-
);
|
|
194
|
-
}
|
|
195
|
-
length = newLength;
|
|
196
|
-
},
|
|
197
|
-
|
|
198
|
-
reset: () => {
|
|
199
|
-
length = zeroNonNegativeInt;
|
|
200
|
-
},
|
|
201
|
-
|
|
202
|
-
unwrap: () => value.subarray(0, length),
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
return buffer;
|
|
206
|
-
};
|