@elaraai/east 1.0.55 → 1.0.57
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/serialization/beast2/index.d.ts +5 -3
- package/dist/src/serialization/beast2/index.d.ts.map +1 -1
- package/dist/src/serialization/beast2/index.js +1 -1
- package/dist/src/serialization/beast2/index.js.map +1 -1
- package/dist/src/serialization/beast2/v5/codec.d.ts +8 -1
- package/dist/src/serialization/beast2/v5/codec.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/codec.js +67 -15
- package/dist/src/serialization/beast2/v5/codec.js.map +1 -1
- package/dist/src/serialization/beast2/v5/frames.d.ts +13 -8
- package/dist/src/serialization/beast2/v5/frames.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/frames.js +16 -10
- package/dist/src/serialization/beast2/v5/frames.js.map +1 -1
- package/dist/src/serialization/beast2/v5/index.spec.js +300 -24
- package/dist/src/serialization/beast2/v5/index.spec.js.map +1 -1
- package/dist/src/serialization/beast2/v5/inflate.d.ts +19 -0
- package/dist/src/serialization/beast2/v5/inflate.d.ts.map +1 -0
- package/dist/src/serialization/beast2/v5/inflate.js +273 -0
- package/dist/src/serialization/beast2/v5/inflate.js.map +1 -0
- package/dist/src/serialization/beast2/v5/stream.d.ts +126 -5
- package/dist/src/serialization/beast2/v5/stream.d.ts.map +1 -1
- package/dist/src/serialization/beast2/v5/stream.js +405 -21
- package/dist/src/serialization/beast2/v5/stream.js.map +1 -1
- package/dist/src/serialization/index.d.ts +1 -1
- package/dist/src/serialization/index.d.ts.map +1 -1
- package/dist/src/serialization/index.js +1 -1
- package/dist/src/serialization/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Dual-licensed under AGPL-3.0 and commercial license. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Portable raw-DEFLATE (RFC 1951) inflate for beast2 v5 frames.
|
|
7
|
+
*
|
|
8
|
+
* **Why we ship our own inflate.** v5 deflate frames must decode wherever
|
|
9
|
+
* East values are read, and the synchronous decode surface
|
|
10
|
+
* (`decodeBeast2For`) is embedded in call sites that cannot become async —
|
|
11
|
+
* React renderers, platform-function bodies, extension hosts. Node has
|
|
12
|
+
* `node:zlib`; browsers expose only the async `DecompressionStream`, which
|
|
13
|
+
* cannot back a synchronous decoder. This module closes that gap: a
|
|
14
|
+
* dependency-free inflate used whenever zlib is absent, so the sync entry
|
|
15
|
+
* points work in every runtime. `frames.ts` still prefers zlib when present,
|
|
16
|
+
* and the async decode entry points still use the platform's native
|
|
17
|
+
* decompressor for throughput.
|
|
18
|
+
*
|
|
19
|
+
* Decodes the full format — stored, fixed-Huffman and dynamic-Huffman blocks.
|
|
20
|
+
* Our own deterministic encoder emits only single fixed-Huffman blocks, but
|
|
21
|
+
* foreign writers (east-c's miniz, CPython's zlib, node's zlib) may emit any
|
|
22
|
+
* mix, and inflate must stay liberal for the format's interoperability
|
|
23
|
+
* guarantee to hold.
|
|
24
|
+
*
|
|
25
|
+
* The structure follows Mark Adler's canonical "puff" reference decoder:
|
|
26
|
+
* canonical-Huffman decode via per-length counts rather than lookup tables.
|
|
27
|
+
* That trades peak speed for being small and auditable; frames on the
|
|
28
|
+
* browser sync path (UI payloads) inflate in well under a millisecond.
|
|
29
|
+
*/
|
|
30
|
+
/** Longest Huffman code the format permits. */
|
|
31
|
+
const MAXBITS = 15;
|
|
32
|
+
// RFC 1951 §3.2.5 length and distance tables (length symbols 257–285,
|
|
33
|
+
// distance symbols 0–29).
|
|
34
|
+
const LEN_BASE = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258];
|
|
35
|
+
const LEN_EXTRA = [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0];
|
|
36
|
+
const DIST_BASE = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577];
|
|
37
|
+
const DIST_EXTRA = [0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13];
|
|
38
|
+
// RFC 1951 §3.2.7: the order in which code-length-code lengths are stored.
|
|
39
|
+
const CLC_ORDER = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
|
|
40
|
+
/** LSB-first bit source over the compressed payload, as DEFLATE requires. */
|
|
41
|
+
class BitReader {
|
|
42
|
+
src;
|
|
43
|
+
pos = 0;
|
|
44
|
+
bitBuf = 0;
|
|
45
|
+
bitCnt = 0;
|
|
46
|
+
constructor(src) {
|
|
47
|
+
this.src = src;
|
|
48
|
+
}
|
|
49
|
+
/** Reads `count` bits (least-significant bit first), `count` ≤ 13. */
|
|
50
|
+
bits(count) {
|
|
51
|
+
while (this.bitCnt < count) {
|
|
52
|
+
if (this.pos >= this.src.length) {
|
|
53
|
+
throw new Error(`beast2 v5: truncated DEFLATE stream`);
|
|
54
|
+
}
|
|
55
|
+
this.bitBuf |= this.src[this.pos++] << this.bitCnt;
|
|
56
|
+
this.bitCnt += 8;
|
|
57
|
+
}
|
|
58
|
+
const value = this.bitBuf & ((1 << count) - 1);
|
|
59
|
+
this.bitBuf >>>= count;
|
|
60
|
+
this.bitCnt -= count;
|
|
61
|
+
return value;
|
|
62
|
+
}
|
|
63
|
+
/** Discards buffered bits up to the next byte boundary. After any `bits()`
|
|
64
|
+
* call at most 7 bits of the current byte remain buffered, so dropping the
|
|
65
|
+
* buffer IS the alignment. */
|
|
66
|
+
align() {
|
|
67
|
+
this.bitBuf = 0;
|
|
68
|
+
this.bitCnt = 0;
|
|
69
|
+
}
|
|
70
|
+
/** Reads `len` raw bytes (call only when byte-aligned). */
|
|
71
|
+
bytes(len) {
|
|
72
|
+
if (this.pos + len > this.src.length) {
|
|
73
|
+
throw new Error(`beast2 v5: truncated DEFLATE stream`);
|
|
74
|
+
}
|
|
75
|
+
const view = this.src.subarray(this.pos, this.pos + len);
|
|
76
|
+
this.pos += len;
|
|
77
|
+
return view;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Builds a canonical Huffman code from the first `n` code lengths.
|
|
81
|
+
* Over-subscribed codes are rejected; incomplete codes are permitted (an
|
|
82
|
+
* unassigned code simply fails to decode if the stream ever uses it). */
|
|
83
|
+
function buildHuffman(lengths, n) {
|
|
84
|
+
const count = new Int32Array(MAXBITS + 1);
|
|
85
|
+
for (let i = 0; i < n; i++)
|
|
86
|
+
count[lengths[i]]++;
|
|
87
|
+
if (count[0] === n) {
|
|
88
|
+
return { count, symbol: new Int32Array(0) };
|
|
89
|
+
}
|
|
90
|
+
let left = 1;
|
|
91
|
+
for (let len = 1; len <= MAXBITS; len++) {
|
|
92
|
+
left <<= 1;
|
|
93
|
+
left -= count[len];
|
|
94
|
+
if (left < 0) {
|
|
95
|
+
throw new Error(`beast2 v5: over-subscribed Huffman code in DEFLATE stream`);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
const offs = new Int32Array(MAXBITS + 1);
|
|
99
|
+
for (let len = 1; len < MAXBITS; len++) {
|
|
100
|
+
offs[len + 1] = offs[len] + count[len];
|
|
101
|
+
}
|
|
102
|
+
const symbol = new Int32Array(n);
|
|
103
|
+
for (let i = 0; i < n; i++) {
|
|
104
|
+
if (lengths[i] !== 0)
|
|
105
|
+
symbol[offs[lengths[i]]++] = i;
|
|
106
|
+
}
|
|
107
|
+
return { count, symbol };
|
|
108
|
+
}
|
|
109
|
+
/** Decodes one symbol, reading the code bit-by-bit (codes are packed
|
|
110
|
+
* most-significant bit first within the LSB-first bitstream). */
|
|
111
|
+
function decodeSym(br, h) {
|
|
112
|
+
let code = 0;
|
|
113
|
+
let first = 0;
|
|
114
|
+
let index = 0;
|
|
115
|
+
for (let len = 1; len <= MAXBITS; len++) {
|
|
116
|
+
code |= br.bits(1);
|
|
117
|
+
const count = h.count[len];
|
|
118
|
+
if (code - first < count) {
|
|
119
|
+
return h.symbol[index + (code - first)];
|
|
120
|
+
}
|
|
121
|
+
index += count;
|
|
122
|
+
first = (first + count) << 1;
|
|
123
|
+
code <<= 1;
|
|
124
|
+
}
|
|
125
|
+
throw new Error(`beast2 v5: invalid Huffman code in DEFLATE stream`);
|
|
126
|
+
}
|
|
127
|
+
let fixedLit = null;
|
|
128
|
+
let fixedDist = null;
|
|
129
|
+
/** The fixed-Huffman tables of RFC 1951 §3.2.6, built once on first use. */
|
|
130
|
+
function fixedTables() {
|
|
131
|
+
if (!fixedLit || !fixedDist) {
|
|
132
|
+
const litLengths = new Uint8Array(288);
|
|
133
|
+
litLengths.fill(8, 0, 144);
|
|
134
|
+
litLengths.fill(9, 144, 256);
|
|
135
|
+
litLengths.fill(7, 256, 280);
|
|
136
|
+
litLengths.fill(8, 280, 288);
|
|
137
|
+
fixedLit = buildHuffman(litLengths, 288);
|
|
138
|
+
const distLengths = new Uint8Array(30);
|
|
139
|
+
distLengths.fill(5);
|
|
140
|
+
fixedDist = buildHuffman(distLengths, 30);
|
|
141
|
+
}
|
|
142
|
+
return [fixedLit, fixedDist];
|
|
143
|
+
}
|
|
144
|
+
/** Reads a dynamic block's header (RFC 1951 §3.2.7) and builds its tables. */
|
|
145
|
+
function dynamicTables(br) {
|
|
146
|
+
const hlit = br.bits(5) + 257;
|
|
147
|
+
const hdist = br.bits(5) + 1;
|
|
148
|
+
const hclen = br.bits(4) + 4;
|
|
149
|
+
if (hlit > 286 || hdist > 30) {
|
|
150
|
+
throw new Error(`beast2 v5: DEFLATE dynamic block declares too many codes (${hlit} literal/length, ${hdist} distance)`);
|
|
151
|
+
}
|
|
152
|
+
const clcLengths = new Uint8Array(19);
|
|
153
|
+
for (let i = 0; i < hclen; i++) {
|
|
154
|
+
clcLengths[CLC_ORDER[i]] = br.bits(3);
|
|
155
|
+
}
|
|
156
|
+
const clc = buildHuffman(clcLengths, 19);
|
|
157
|
+
const lengths = new Uint8Array(hlit + hdist);
|
|
158
|
+
let i = 0;
|
|
159
|
+
while (i < hlit + hdist) {
|
|
160
|
+
const sym = decodeSym(br, clc);
|
|
161
|
+
if (sym < 16) {
|
|
162
|
+
lengths[i++] = sym;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
let value = 0;
|
|
166
|
+
let repeat;
|
|
167
|
+
if (sym === 16) {
|
|
168
|
+
if (i === 0) {
|
|
169
|
+
throw new Error(`beast2 v5: DEFLATE repeat code with no previous length`);
|
|
170
|
+
}
|
|
171
|
+
value = lengths[i - 1];
|
|
172
|
+
repeat = 3 + br.bits(2);
|
|
173
|
+
}
|
|
174
|
+
else if (sym === 17) {
|
|
175
|
+
repeat = 3 + br.bits(3);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
repeat = 11 + br.bits(7);
|
|
179
|
+
}
|
|
180
|
+
if (i + repeat > hlit + hdist) {
|
|
181
|
+
throw new Error(`beast2 v5: DEFLATE length repeat runs past the declared code count`);
|
|
182
|
+
}
|
|
183
|
+
while (repeat-- > 0)
|
|
184
|
+
lengths[i++] = value;
|
|
185
|
+
}
|
|
186
|
+
if (lengths[256] === 0) {
|
|
187
|
+
throw new Error(`beast2 v5: DEFLATE dynamic block has no end-of-block code`);
|
|
188
|
+
}
|
|
189
|
+
return [buildHuffman(lengths, hlit), buildHuffman(lengths.subarray(hlit), hdist)];
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Decompresses a raw DEFLATE stream without platform support.
|
|
193
|
+
*
|
|
194
|
+
* Accepts any valid RFC 1951 stream (stored, fixed and dynamic blocks, in
|
|
195
|
+
* any mix) and enforces the beast2 frame contract: the stream must inflate
|
|
196
|
+
* to exactly `uncompressedLen` bytes.
|
|
197
|
+
*
|
|
198
|
+
* @param payload - the raw DEFLATE stream (no zlib header or trailer)
|
|
199
|
+
* @param uncompressedLen - the expected output length from the frame header
|
|
200
|
+
* @returns the decompressed bytes
|
|
201
|
+
* @throws {Error} When the stream is truncated or corrupt, or its output
|
|
202
|
+
* length disagrees with `uncompressedLen`.
|
|
203
|
+
*/
|
|
204
|
+
export function inflateRawPure(payload, uncompressedLen) {
|
|
205
|
+
const out = new Uint8Array(uncompressedLen);
|
|
206
|
+
let outPos = 0;
|
|
207
|
+
const br = new BitReader(payload);
|
|
208
|
+
for (;;) {
|
|
209
|
+
const bfinal = br.bits(1);
|
|
210
|
+
const btype = br.bits(2);
|
|
211
|
+
if (btype === 3) {
|
|
212
|
+
throw new Error(`beast2 v5: invalid DEFLATE block type 3`);
|
|
213
|
+
}
|
|
214
|
+
if (btype === 0) {
|
|
215
|
+
br.align();
|
|
216
|
+
const header = br.bytes(4);
|
|
217
|
+
const len = header[0] | (header[1] << 8);
|
|
218
|
+
const nlen = header[2] | (header[3] << 8);
|
|
219
|
+
if ((len ^ 0xffff) !== nlen) {
|
|
220
|
+
throw new Error(`beast2 v5: stored DEFLATE block length check failed`);
|
|
221
|
+
}
|
|
222
|
+
if (outPos + len > uncompressedLen) {
|
|
223
|
+
throw new Error(`beast2 v5: frame inflated past the declared ${uncompressedLen} bytes`);
|
|
224
|
+
}
|
|
225
|
+
out.set(br.bytes(len), outPos);
|
|
226
|
+
outPos += len;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const [lit, dist] = btype === 1 ? fixedTables() : dynamicTables(br);
|
|
230
|
+
for (;;) {
|
|
231
|
+
const sym = decodeSym(br, lit);
|
|
232
|
+
if (sym < 256) {
|
|
233
|
+
if (outPos >= uncompressedLen) {
|
|
234
|
+
throw new Error(`beast2 v5: frame inflated past the declared ${uncompressedLen} bytes`);
|
|
235
|
+
}
|
|
236
|
+
out[outPos++] = sym;
|
|
237
|
+
}
|
|
238
|
+
else if (sym === 256) {
|
|
239
|
+
break;
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
if (sym > 285) {
|
|
243
|
+
throw new Error(`beast2 v5: invalid DEFLATE length symbol ${sym}`);
|
|
244
|
+
}
|
|
245
|
+
const length = LEN_BASE[sym - 257] + br.bits(LEN_EXTRA[sym - 257]);
|
|
246
|
+
const dsym = decodeSym(br, dist);
|
|
247
|
+
if (dsym > 29) {
|
|
248
|
+
throw new Error(`beast2 v5: invalid DEFLATE distance symbol ${dsym}`);
|
|
249
|
+
}
|
|
250
|
+
const distance = DIST_BASE[dsym] + br.bits(DIST_EXTRA[dsym]);
|
|
251
|
+
if (distance > outPos) {
|
|
252
|
+
throw new Error(`beast2 v5: DEFLATE match distance ${distance} reaches before the start of output`);
|
|
253
|
+
}
|
|
254
|
+
if (outPos + length > uncompressedLen) {
|
|
255
|
+
throw new Error(`beast2 v5: frame inflated past the declared ${uncompressedLen} bytes`);
|
|
256
|
+
}
|
|
257
|
+
// Byte-by-byte so overlapping matches replicate, as LZ77 requires.
|
|
258
|
+
for (let k = 0; k < length; k++) {
|
|
259
|
+
out[outPos] = out[outPos - distance];
|
|
260
|
+
outPos++;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
if (bfinal)
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
if (outPos !== uncompressedLen) {
|
|
269
|
+
throw new Error(`beast2 v5: frame inflated to ${outPos} bytes, header declared ${uncompressedLen}`);
|
|
270
|
+
}
|
|
271
|
+
return out;
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=inflate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inflate.js","sourceRoot":"","sources":["../../../../../src/serialization/beast2/v5/inflate.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;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,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;wBAChC,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,QAAQ,CAAE,CAAC;wBACtC,MAAM,EAAE,CAAC;oBACX,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAI,MAAM;YAAE,MAAM;IACpB,CAAC;IACD,IAAI,MAAM,KAAK,eAAe,EAAE,CAAC;QAC/B,MAAM,IAAI,KAAK,CAAC,gCAAgC,MAAM,2BAA2B,eAAe,EAAE,CAAC,CAAC;IACtG,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -69,6 +69,9 @@ export declare class Beast2Writer<T extends EastType = EastType> {
|
|
|
69
69
|
private readonly ctx;
|
|
70
70
|
private readonly encodeElems;
|
|
71
71
|
private readonly index;
|
|
72
|
+
private readonly orderCmp;
|
|
73
|
+
private lastKey;
|
|
74
|
+
private hasLast;
|
|
72
75
|
private bytesWritten;
|
|
73
76
|
private finished;
|
|
74
77
|
/**
|
|
@@ -84,8 +87,15 @@ export declare class Beast2Writer<T extends EastType = EastType> {
|
|
|
84
87
|
* Empty batches are skipped — a segment count is never zero, so the stream
|
|
85
88
|
* terminator stays unambiguous.
|
|
86
89
|
*
|
|
90
|
+
* Set/Dict batches must continue the stream's strict East (key) order:
|
|
91
|
+
* segment content is the canonical value split at segment boundaries, so
|
|
92
|
+
* each batch must be internally ascending and start above the previous
|
|
93
|
+
* batch's last key. Pre-sort into batches (a `SortedMap`/`SortedSet` slice,
|
|
94
|
+
* or an external sort), or encode arrival order as an Array of entries.
|
|
95
|
+
*
|
|
87
96
|
* @param batch - a value of the declared collection type
|
|
88
|
-
* @throws {Error} When called after {@link finish}
|
|
97
|
+
* @throws {Error} When called after {@link finish}, or when a Set/Dict
|
|
98
|
+
* batch violates the stream's strict ascending (key) order.
|
|
89
99
|
*/
|
|
90
100
|
write(batch: ValueTypeOf<T>): void;
|
|
91
101
|
/**
|
|
@@ -93,6 +103,9 @@ export declare class Beast2Writer<T extends EastType = EastType> {
|
|
|
93
103
|
* the index and footer. Idempotent.
|
|
94
104
|
*/
|
|
95
105
|
finish(): void;
|
|
106
|
+
/** Validates that a Set/Dict batch continues the stream's strict ascent
|
|
107
|
+
* in East (key) order — within the batch and against the previous batch. */
|
|
108
|
+
private checkAscent;
|
|
96
109
|
private emit;
|
|
97
110
|
}
|
|
98
111
|
/**
|
|
@@ -106,6 +119,49 @@ export declare class Beast2Writer<T extends EastType = EastType> {
|
|
|
106
119
|
* @throws {TypeError} When `type` is not an Array, Set or Dict type.
|
|
107
120
|
*/
|
|
108
121
|
export declare function encodeBeast2SegmentsFor<T extends EastType>(type: T | EastTypeValue, options?: Beast2WriterOptions): (batches: Iterable<ValueTypeOf<T>>) => Uint8Array;
|
|
122
|
+
/** Default element cap per segment for {@link encodeBeast2PagedFor}. Small
|
|
123
|
+
* enough that one segment decodes cheaply, large enough that frames stay far
|
|
124
|
+
* above the compression threshold and per-segment overhead (frame header +
|
|
125
|
+
* index entry) is negligible. */
|
|
126
|
+
export declare const BEAST2_PAGED_BATCH_DEFAULT = 1000;
|
|
127
|
+
/** Default wire-byte target per segment for {@link encodeBeast2PagedFor}.
|
|
128
|
+
* Wide rows would otherwise make element-capped segments arbitrarily large —
|
|
129
|
+
* and a paging reader decodes whole segments, so segment size IS the random-
|
|
130
|
+
* access cost. Batching adapts toward this target from measured output. */
|
|
131
|
+
export declare const BEAST2_PAGED_TARGET_BYTES_DEFAULT: number;
|
|
132
|
+
/** Options accepted by {@link encodeBeast2PagedFor}. */
|
|
133
|
+
export type Beast2PagedEncodeOptions = {
|
|
134
|
+
/** Element (pair for Dict roots) cap per segment. Defaults to
|
|
135
|
+
* {@link BEAST2_PAGED_BATCH_DEFAULT}. */
|
|
136
|
+
batchSize?: number;
|
|
137
|
+
/** Wire-byte target per segment — batches shrink below `batchSize` when
|
|
138
|
+
* measured element size would exceed it. Defaults to
|
|
139
|
+
* {@link BEAST2_PAGED_TARGET_BYTES_DEFAULT}. */
|
|
140
|
+
targetSegmentBytes?: number;
|
|
141
|
+
/** Per-frame codec. Defaults to `"deflate"`. */
|
|
142
|
+
codec?: Beast2Codec;
|
|
143
|
+
/** Source map for function values in the stream, written to the header. */
|
|
144
|
+
sourceMap?: SourceMap | null;
|
|
145
|
+
};
|
|
146
|
+
/**
|
|
147
|
+
* Builds a curried paged encoder: `encode(value)` writes one whole collection
|
|
148
|
+
* value as a segmented, self-contained, indexed v5 blob — `batchSize` elements
|
|
149
|
+
* per segment.
|
|
150
|
+
*
|
|
151
|
+
* The write-side sibling of {@link openBeast2PagesFor}: a blob written this
|
|
152
|
+
* way supports random access ({@link Beast2Pages.segment} /
|
|
153
|
+
* {@link Beast2Pages.element} / {@link Beast2Pages.slice}) without decoding
|
|
154
|
+
* the rest. Decoding the whole blob through the ordinary entry points yields
|
|
155
|
+
* exactly the input value. Note the bytes differ from the whole-value
|
|
156
|
+
* `encodeBeast2For` encode of the same value (segment framing is part of the
|
|
157
|
+
* bytes), so content-addressed stores hash the two forms differently.
|
|
158
|
+
*
|
|
159
|
+
* @param type - the collection type (Array/Set/Dict)
|
|
160
|
+
* @param options - batch size, codec, and source map options
|
|
161
|
+
* @returns a function encoding a collection value to an indexed v5 blob
|
|
162
|
+
* @throws {TypeError} When `type` is not an Array, Set or Dict type.
|
|
163
|
+
*/
|
|
164
|
+
export declare function encodeBeast2PagedFor<T extends EastType>(type: T | EastTypeValue, options?: Beast2PagedEncodeOptions): (value: ValueTypeOf<T>) => Uint8Array;
|
|
109
165
|
/**
|
|
110
166
|
* Builds a curried segment iterator: `segments(data)` yields one decoded
|
|
111
167
|
* collection per root segment, in stream order, with O(segment) decoded
|
|
@@ -124,23 +180,37 @@ export declare function iterBeast2SegmentsFor<T extends EastType>(type: T | East
|
|
|
124
180
|
* {@link segment} seeks to and decodes exactly one segment. Requires the blob
|
|
125
181
|
* to carry an index (written by default by {@link Beast2Writer}); random
|
|
126
182
|
* access additionally requires self-contained segments.
|
|
183
|
+
*
|
|
184
|
+
* Set/Dict blobs page like Arrays: the wire holds the canonical value split
|
|
185
|
+
* at segment boundaries (strictly ascending, disjoint segments), so row
|
|
186
|
+
* windows ({@link slice}) and key lookups ({@link get}) address the sorted
|
|
187
|
+
* order directly. The first Set/Dict access verifies the segment fences
|
|
188
|
+
* (each segment's first key, probed without decoding whole segments) ascend
|
|
189
|
+
* strictly, and every decoded segment is validated internally and against
|
|
190
|
+
* the next fence — a blob violating the canonical-order contract fails with
|
|
191
|
+
* a corruption error rather than mis-addressing rows.
|
|
127
192
|
*/
|
|
128
193
|
export declare class Beast2Pages<T extends EastType = EastType> {
|
|
129
194
|
/** Per-segment element counts from the index (pairs for Dict roots). */
|
|
130
195
|
readonly counts: readonly number[];
|
|
131
|
-
/** Sum of all segment counts
|
|
132
|
-
*
|
|
133
|
-
*
|
|
196
|
+
/** Sum of all segment counts — the exact element (pair) count for every
|
|
197
|
+
* root kind: Set/Dict segments are disjoint ranges of the canonical
|
|
198
|
+
* value, so counts never overlap. */
|
|
134
199
|
readonly elementCount: number;
|
|
135
200
|
/** Whether segments are independently decodable. */
|
|
136
201
|
readonly selfContained: boolean;
|
|
137
202
|
private readonly data;
|
|
138
203
|
private readonly indexData;
|
|
139
204
|
private readonly kind;
|
|
205
|
+
private readonly typeValue;
|
|
140
206
|
private readonly sourceMap;
|
|
141
207
|
private readonly decodeSegment;
|
|
142
208
|
private readonly platform;
|
|
143
209
|
private readonly cumulative;
|
|
210
|
+
private readonly orderCmp;
|
|
211
|
+
/** First key/element of each segment, in segment order (Set/Dict only). */
|
|
212
|
+
private fences;
|
|
213
|
+
private fenceDec;
|
|
144
214
|
/** @internal Use {@link openBeast2PagesFor}. */
|
|
145
215
|
constructor(data: Uint8Array, typeValue: EastTypeValue, options?: Beast2DecodeOptions);
|
|
146
216
|
/** Number of segments in the blob. */
|
|
@@ -148,12 +218,31 @@ export declare class Beast2Pages<T extends EastType = EastType> {
|
|
|
148
218
|
/**
|
|
149
219
|
* Decodes one segment by index.
|
|
150
220
|
*
|
|
221
|
+
* Set/Dict segments are validated for strict internal ascent as they
|
|
222
|
+
* decode (the canonical-order contract); a violation is a corruption
|
|
223
|
+
* error, not data.
|
|
224
|
+
*
|
|
151
225
|
* @param i - zero-based segment index
|
|
152
226
|
* @returns the segment's decoded collection
|
|
153
227
|
* @throws {Error} When the blob is not self-contained (segments cannot be
|
|
154
|
-
* decoded independently)
|
|
228
|
+
* decoded independently), `i` is out of range, or a Set/Dict segment
|
|
229
|
+
* violates strict ascending order.
|
|
155
230
|
*/
|
|
156
231
|
segment(i: number): ValueTypeOf<T>;
|
|
232
|
+
/** Seeks to and decodes segment `i`, threading the caller's order state. */
|
|
233
|
+
private decodeSegmentCore;
|
|
234
|
+
/** Decodes just the first key/element of segment `i` — a bounded probe
|
|
235
|
+
* (one frame inflate, one element decode), not a whole-segment decode. */
|
|
236
|
+
private firstKey;
|
|
237
|
+
/** Probes and verifies the segment fences once: each segment's first
|
|
238
|
+
* key/element must ascend strictly across segments. */
|
|
239
|
+
private verifyFences;
|
|
240
|
+
/** Decodes segment `i` with order threading, then checks its tail stays
|
|
241
|
+
* below the next segment's fence (segments must be disjoint ranges). */
|
|
242
|
+
private decodeDisjoint;
|
|
243
|
+
/** Binary-searches the cumulative counts for the segment owning `row`,
|
|
244
|
+
* returning its index and the global row of its first element. */
|
|
245
|
+
private rowSegment;
|
|
157
246
|
/**
|
|
158
247
|
* Reads one element by row index (Array roots only): binary-searches the
|
|
159
248
|
* index, decodes that single segment, and returns the row.
|
|
@@ -163,6 +252,38 @@ export declare class Beast2Pages<T extends EastType = EastType> {
|
|
|
163
252
|
* @throws {Error} When the root is not an Array or `row` is out of range.
|
|
164
253
|
*/
|
|
165
254
|
element(row: number): ValueTypeOf<T> extends (infer E)[] ? E : never;
|
|
255
|
+
/**
|
|
256
|
+
* Reads a window of the collection by row range, decoding only the
|
|
257
|
+
* segments the window touches.
|
|
258
|
+
*
|
|
259
|
+
* Rows address stream order — for Array roots the element order, for
|
|
260
|
+
* Set/Dict roots the canonical East (key) order, since segments are
|
|
261
|
+
* disjoint ascending ranges. Returns a collection value of the root kind
|
|
262
|
+
* holding the window (an array, `Set`, or `Map` in that order).
|
|
263
|
+
*
|
|
264
|
+
* Clamps like `Array.prototype.slice`: a window past the end returns the
|
|
265
|
+
* available tail (or an empty collection), never throws for being short.
|
|
266
|
+
*
|
|
267
|
+
* @param offset - zero-based row of the window's first element
|
|
268
|
+
* @param limit - maximum number of elements (pairs) to return
|
|
269
|
+
* @returns a collection of the root kind with the window's contents
|
|
270
|
+
* @throws {Error} When `offset`/`limit` are negative or fractional, the
|
|
271
|
+
* blob is not self-contained, or a Set/Dict blob violates the
|
|
272
|
+
* canonical-order contract (non-ascending or overlapping segments).
|
|
273
|
+
*/
|
|
274
|
+
slice(offset: number, limit: number): ValueTypeOf<T>;
|
|
275
|
+
/**
|
|
276
|
+
* Looks up one Set element or Dict value by key (Set/Dict roots only):
|
|
277
|
+
* binary-searches the verified segment fences for the only segment whose
|
|
278
|
+
* range can hold the key, decodes it, and scans for an East-equal match.
|
|
279
|
+
*
|
|
280
|
+
* @param key - the Set element or Dict key to look up
|
|
281
|
+
* @returns the Dict value (or the stored Set element) for `key`, or
|
|
282
|
+
* `undefined` when the collection does not contain it
|
|
283
|
+
* @throws {Error} When the root is an Array, the blob is not
|
|
284
|
+
* self-contained, or the blob violates the canonical-order contract.
|
|
285
|
+
*/
|
|
286
|
+
get(key: ValueTypeOf<T> extends Map<infer K, any> ? K : ValueTypeOf<T> extends Set<infer E> ? E : never): (ValueTypeOf<T> extends Map<any, infer V> ? V : ValueTypeOf<T> extends Set<infer E> ? E : never) | undefined;
|
|
166
287
|
}
|
|
167
288
|
/**
|
|
168
289
|
* Builds a curried pages opener: `open(data)` parses the header, footer and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../src/serialization/beast2/v5/stream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../../../src/serialization/beast2/v5/stream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAIjD,OAAO,EAAE,KAAK,mBAAmB,EAAwB,MAAM,cAAc,CAAC;AAE9E,OAAO,EAAE,KAAK,WAAW,EAA2B,MAAM,aAAa,CAAC;AAsCxE,oFAAoF;AACpF,MAAM,MAAM,mBAAmB,GAAG;IAChC,gDAAgD;IAChD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;6CACyC;IACzC,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB;8BAC0B;IAC1B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC;CAC9B,CAAC;AAMF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,YAAY,CAAC,CAAC,SAAS,QAAQ,GAAG,QAAQ;IACrD,yCAAyC;IACzC,QAAQ,SAAK;IACb,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAgB;IACrC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA8B;IACnD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAc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