@a0n/aeon 5.0.1
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/LICENSE +15 -0
- package/README.md +199 -0
- package/dist/CryptoProvider-SLWjqByk.d.cts +407 -0
- package/dist/CryptoProvider-SLWjqByk.d.ts +407 -0
- package/dist/compression/index.cjs +1445 -0
- package/dist/compression/index.cjs.map +1 -0
- package/dist/compression/index.d.cts +451 -0
- package/dist/compression/index.d.ts +451 -0
- package/dist/compression/index.js +1426 -0
- package/dist/compression/index.js.map +1 -0
- package/dist/core/index.cjs +4 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +212 -0
- package/dist/core/index.d.ts +212 -0
- package/dist/core/index.js +3 -0
- package/dist/core/index.js.map +1 -0
- package/dist/crypto/index.cjs +130 -0
- package/dist/crypto/index.cjs.map +1 -0
- package/dist/crypto/index.d.cts +56 -0
- package/dist/crypto/index.d.ts +56 -0
- package/dist/crypto/index.js +124 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/distributed/index.cjs +2586 -0
- package/dist/distributed/index.cjs.map +1 -0
- package/dist/distributed/index.d.cts +1005 -0
- package/dist/distributed/index.d.ts +1005 -0
- package/dist/distributed/index.js +2580 -0
- package/dist/distributed/index.js.map +1 -0
- package/dist/index.cjs +10953 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1953 -0
- package/dist/index.d.ts +1953 -0
- package/dist/index.js +10828 -0
- package/dist/index.js.map +1 -0
- package/dist/offline/index.cjs +419 -0
- package/dist/offline/index.cjs.map +1 -0
- package/dist/offline/index.d.cts +148 -0
- package/dist/offline/index.d.ts +148 -0
- package/dist/offline/index.js +415 -0
- package/dist/offline/index.js.map +1 -0
- package/dist/optimization/index.cjs +800 -0
- package/dist/optimization/index.cjs.map +1 -0
- package/dist/optimization/index.d.cts +347 -0
- package/dist/optimization/index.d.ts +347 -0
- package/dist/optimization/index.js +790 -0
- package/dist/optimization/index.js.map +1 -0
- package/dist/persistence/index.cjs +207 -0
- package/dist/persistence/index.cjs.map +1 -0
- package/dist/persistence/index.d.cts +95 -0
- package/dist/persistence/index.d.ts +95 -0
- package/dist/persistence/index.js +204 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/presence/index.cjs +489 -0
- package/dist/presence/index.cjs.map +1 -0
- package/dist/presence/index.d.cts +283 -0
- package/dist/presence/index.d.ts +283 -0
- package/dist/presence/index.js +485 -0
- package/dist/presence/index.js.map +1 -0
- package/dist/types-CMxO7QF0.d.cts +33 -0
- package/dist/types-CMxO7QF0.d.ts +33 -0
- package/dist/utils/index.cjs +64 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +38 -0
- package/dist/utils/index.d.ts +38 -0
- package/dist/utils/index.js +57 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/versioning/index.cjs +1164 -0
- package/dist/versioning/index.cjs.map +1 -0
- package/dist/versioning/index.d.cts +537 -0
- package/dist/versioning/index.d.ts +537 -0
- package/dist/versioning/index.js +1159 -0
- package/dist/versioning/index.js.map +1 -0
- package/package.json +194 -0
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
import { Operation } from '../core/index.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Compression Engine (Phase 12)
|
|
5
|
+
*
|
|
6
|
+
* Provides compression for delta operations using native CompressionStream API.
|
|
7
|
+
* Falls back gracefully when native compression is unavailable.
|
|
8
|
+
*/
|
|
9
|
+
interface CompressedBatch {
|
|
10
|
+
id: string;
|
|
11
|
+
compressed: Uint8Array;
|
|
12
|
+
originalSize: number;
|
|
13
|
+
compressedSize: number;
|
|
14
|
+
compressionRatio: number;
|
|
15
|
+
algorithm: 'gzip' | 'deflate' | 'none';
|
|
16
|
+
timestamp: number;
|
|
17
|
+
}
|
|
18
|
+
interface CompressedChunk {
|
|
19
|
+
chunkId: string;
|
|
20
|
+
batchId: string;
|
|
21
|
+
data: Uint8Array;
|
|
22
|
+
index: number;
|
|
23
|
+
total: number;
|
|
24
|
+
checksum: string;
|
|
25
|
+
}
|
|
26
|
+
interface CompressionStats {
|
|
27
|
+
totalCompressed: number;
|
|
28
|
+
totalDecompressed: number;
|
|
29
|
+
totalOriginalBytes: number;
|
|
30
|
+
totalCompressedBytes: number;
|
|
31
|
+
averageCompressionRatio: number;
|
|
32
|
+
compressionTimeMs: number;
|
|
33
|
+
decompressionTimeMs: number;
|
|
34
|
+
}
|
|
35
|
+
declare class CompressionEngine {
|
|
36
|
+
private stats;
|
|
37
|
+
private preferredAlgorithm;
|
|
38
|
+
constructor(preferredAlgorithm?: 'gzip' | 'deflate');
|
|
39
|
+
/**
|
|
40
|
+
* Check if native compression is available
|
|
41
|
+
*/
|
|
42
|
+
supportsNativeCompression(): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Compress data
|
|
45
|
+
*/
|
|
46
|
+
compress(data: Uint8Array | string): Promise<CompressedBatch>;
|
|
47
|
+
/**
|
|
48
|
+
* Decompress data
|
|
49
|
+
*/
|
|
50
|
+
decompress(batch: CompressedBatch): Promise<Uint8Array>;
|
|
51
|
+
/**
|
|
52
|
+
* Compress using native CompressionStream
|
|
53
|
+
*/
|
|
54
|
+
private compressNative;
|
|
55
|
+
/**
|
|
56
|
+
* Decompress using native DecompressionStream
|
|
57
|
+
*/
|
|
58
|
+
private decompressNative;
|
|
59
|
+
/**
|
|
60
|
+
* Split compressed batch into chunks for transmission
|
|
61
|
+
*/
|
|
62
|
+
splitIntoChunks(batch: CompressedBatch, chunkSize?: number): CompressedChunk[];
|
|
63
|
+
/**
|
|
64
|
+
* Reassemble chunks into compressed batch
|
|
65
|
+
*/
|
|
66
|
+
reassembleChunks(chunks: CompressedChunk[]): Uint8Array;
|
|
67
|
+
/**
|
|
68
|
+
* Simple checksum for chunk verification
|
|
69
|
+
*/
|
|
70
|
+
private simpleChecksum;
|
|
71
|
+
/**
|
|
72
|
+
* Update average compression ratio
|
|
73
|
+
*/
|
|
74
|
+
private updateAverageRatio;
|
|
75
|
+
/**
|
|
76
|
+
* Get statistics
|
|
77
|
+
*/
|
|
78
|
+
getStats(): CompressionStats;
|
|
79
|
+
/**
|
|
80
|
+
* Reset statistics
|
|
81
|
+
*/
|
|
82
|
+
resetStats(): void;
|
|
83
|
+
}
|
|
84
|
+
declare function getCompressionEngine(): CompressionEngine;
|
|
85
|
+
declare function resetCompressionEngine(): void;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Delta Sync Optimizer (Phase 12)
|
|
89
|
+
*
|
|
90
|
+
* Implements field-level change detection to reduce payload size.
|
|
91
|
+
* Computes delta between current and previous operation state.
|
|
92
|
+
*
|
|
93
|
+
* Performance Impact:
|
|
94
|
+
* - Delta sync alone: 70-80% payload reduction
|
|
95
|
+
* - Combined with compression: 80-90% total reduction
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Delta operation - represents only changed fields
|
|
100
|
+
*/
|
|
101
|
+
interface DeltaOperation {
|
|
102
|
+
id: string;
|
|
103
|
+
type: 'full' | 'delta';
|
|
104
|
+
operationId: string;
|
|
105
|
+
operationType: Operation['type'];
|
|
106
|
+
sessionId: string;
|
|
107
|
+
timestamp: number;
|
|
108
|
+
changes?: Record<string, unknown>;
|
|
109
|
+
changeMask?: string[];
|
|
110
|
+
fullData?: Record<string, unknown>;
|
|
111
|
+
priority?: 'high' | 'normal' | 'low';
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Batch of delta operations
|
|
115
|
+
*/
|
|
116
|
+
interface DeltaBatch {
|
|
117
|
+
batchId: string;
|
|
118
|
+
operations: DeltaOperation[];
|
|
119
|
+
timestamp: number;
|
|
120
|
+
totalOriginalSize: number;
|
|
121
|
+
totalDeltaSize: number;
|
|
122
|
+
reductionPercent: number;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Statistics about delta sync performance
|
|
126
|
+
*/
|
|
127
|
+
interface DeltaStats {
|
|
128
|
+
totalOperations: number;
|
|
129
|
+
totalFull: number;
|
|
130
|
+
totalDelta: number;
|
|
131
|
+
totalOriginalSize: number;
|
|
132
|
+
totalDeltaSize: number;
|
|
133
|
+
averageReductionPercent: number;
|
|
134
|
+
lastSyncTime: number;
|
|
135
|
+
fullOperationThreshold: number;
|
|
136
|
+
}
|
|
137
|
+
declare class DeltaSyncOptimizer {
|
|
138
|
+
private static readonly MAX_HISTORY_SIZE;
|
|
139
|
+
private operationHistory;
|
|
140
|
+
private stats;
|
|
141
|
+
constructor(fullOperationThreshold?: number);
|
|
142
|
+
/**
|
|
143
|
+
* Compute delta for single operation
|
|
144
|
+
*/
|
|
145
|
+
computeDelta(operation: Operation): DeltaOperation;
|
|
146
|
+
/**
|
|
147
|
+
* Compute deltas for batch of operations
|
|
148
|
+
*/
|
|
149
|
+
computeBatchDeltas(operations: Operation[]): DeltaBatch;
|
|
150
|
+
/**
|
|
151
|
+
* Decompress delta operation back to full operation
|
|
152
|
+
*/
|
|
153
|
+
decompressDelta(delta: DeltaOperation): Operation;
|
|
154
|
+
/**
|
|
155
|
+
* Update history after successful sync
|
|
156
|
+
*/
|
|
157
|
+
updateHistory(operations: Operation[]): void;
|
|
158
|
+
/**
|
|
159
|
+
* Clear history for specific operations
|
|
160
|
+
*/
|
|
161
|
+
clearHistory(operationIds: string[]): void;
|
|
162
|
+
/**
|
|
163
|
+
* Get current performance statistics
|
|
164
|
+
*/
|
|
165
|
+
getStats(): DeltaStats;
|
|
166
|
+
/**
|
|
167
|
+
* Reset statistics
|
|
168
|
+
*/
|
|
169
|
+
resetStats(): void;
|
|
170
|
+
/**
|
|
171
|
+
* Set the full operation threshold
|
|
172
|
+
*/
|
|
173
|
+
setFullOperationThreshold(bytes: number): void;
|
|
174
|
+
/**
|
|
175
|
+
* Get history size for memory monitoring
|
|
176
|
+
*/
|
|
177
|
+
getHistorySize(): number;
|
|
178
|
+
/**
|
|
179
|
+
* Get memory footprint estimate
|
|
180
|
+
*/
|
|
181
|
+
getMemoryEstimate(): number;
|
|
182
|
+
/**
|
|
183
|
+
* Deep equality check for nested objects
|
|
184
|
+
*/
|
|
185
|
+
private deepEqual;
|
|
186
|
+
}
|
|
187
|
+
declare function getDeltaSyncOptimizer(threshold?: number): DeltaSyncOptimizer;
|
|
188
|
+
declare function resetDeltaSyncOptimizer(): void;
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Compression Codecs — Pluggable implementations for topological compression.
|
|
192
|
+
*
|
|
193
|
+
* Each codec implements the same interface. The TopologicalCompressor races
|
|
194
|
+
* them per chunk — different data regions get different codecs automatically.
|
|
195
|
+
*
|
|
196
|
+
* Pure-JS codecs (0-3, 6-7) — zero dependencies, work everywhere.
|
|
197
|
+
* Platform codecs (4-5) wrap node:zlib for brotli/gzip when available.
|
|
198
|
+
*
|
|
199
|
+
* Codec lineup:
|
|
200
|
+
* 0: Raw (identity) 4: Brotli (node:zlib)
|
|
201
|
+
* 1: RLE 5: Gzip (node:zlib)
|
|
202
|
+
* 2: Delta 6: Huffman (entropy coding)
|
|
203
|
+
* 3: LZ77 7: Dictionary (web content)
|
|
204
|
+
*/
|
|
205
|
+
interface CompressionCodec {
|
|
206
|
+
/** Unique identifier (stored in compressed frame header) */
|
|
207
|
+
readonly id: number;
|
|
208
|
+
/** Human-readable name */
|
|
209
|
+
readonly name: string;
|
|
210
|
+
/** Compress data. Returns compressed bytes (may be larger than input). */
|
|
211
|
+
encode(data: Uint8Array): Uint8Array;
|
|
212
|
+
/** Decompress data back to original. */
|
|
213
|
+
decode(data: Uint8Array, originalSize: number): Uint8Array;
|
|
214
|
+
}
|
|
215
|
+
declare class RawCodec implements CompressionCodec {
|
|
216
|
+
readonly id = 0;
|
|
217
|
+
readonly name = "raw";
|
|
218
|
+
encode(data: Uint8Array): Uint8Array;
|
|
219
|
+
decode(data: Uint8Array): Uint8Array;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* RLE — excellent for data with long runs of repeated bytes.
|
|
223
|
+
*
|
|
224
|
+
* Format: [byte, count_high, count_low] triplets.
|
|
225
|
+
* Count is u16 (max run = 65535). Non-runs still emit count=1.
|
|
226
|
+
*
|
|
227
|
+
* Best for: repeated patterns, sparse data, zeroed buffers.
|
|
228
|
+
* Worst for: high-entropy data (3x expansion).
|
|
229
|
+
*/
|
|
230
|
+
declare class RLECodec implements CompressionCodec {
|
|
231
|
+
readonly id = 1;
|
|
232
|
+
readonly name = "rle";
|
|
233
|
+
encode(data: Uint8Array): Uint8Array;
|
|
234
|
+
decode(data: Uint8Array, originalSize: number): Uint8Array;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Delta encoding — stores differences between consecutive bytes.
|
|
238
|
+
*
|
|
239
|
+
* Best for: sequential/incremental data, sensor readings, coordinates.
|
|
240
|
+
* Worst for: random data (no benefit, slight overhead from first byte).
|
|
241
|
+
*/
|
|
242
|
+
declare class DeltaCodec implements CompressionCodec {
|
|
243
|
+
readonly id = 2;
|
|
244
|
+
readonly name = "delta";
|
|
245
|
+
encode(data: Uint8Array): Uint8Array;
|
|
246
|
+
decode(data: Uint8Array, originalSize: number): Uint8Array;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Simplified LZ77 — sliding window compression with back-references.
|
|
250
|
+
*
|
|
251
|
+
* Format: control byte per group of 8 items.
|
|
252
|
+
* - Bit 0 = literal byte follows
|
|
253
|
+
* - Bit 1 = back-reference follows: [offset_high:4 | length:4, offset_low:8]
|
|
254
|
+
* offset = 12 bits (max 4095), length = 4 bits + 3 (range 3–18)
|
|
255
|
+
*
|
|
256
|
+
* Window size: 4096 bytes. Min match: 3. Max match: 18.
|
|
257
|
+
*
|
|
258
|
+
* Best for: general-purpose data with repeated patterns.
|
|
259
|
+
* Worst for: truly random data (slight overhead from control bytes).
|
|
260
|
+
*/
|
|
261
|
+
declare class LZ77Codec implements CompressionCodec {
|
|
262
|
+
readonly id = 3;
|
|
263
|
+
readonly name = "lz77";
|
|
264
|
+
private static readonly WINDOW_SIZE;
|
|
265
|
+
private static readonly MIN_MATCH;
|
|
266
|
+
private static readonly MAX_MATCH;
|
|
267
|
+
encode(data: Uint8Array): Uint8Array;
|
|
268
|
+
decode(data: Uint8Array, originalSize: number): Uint8Array;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Brotli via node:zlib — best general-purpose compression ratio.
|
|
272
|
+
*
|
|
273
|
+
* Only available on Node/Bun/Deno. The TopologicalCompressor races it
|
|
274
|
+
* per-chunk against pure-JS codecs — brotli wins on text, raw wins on
|
|
275
|
+
* already-compressed binary. This is the key insight: topological
|
|
276
|
+
* compression adapts per-chunk even when one codec dominates globally.
|
|
277
|
+
*
|
|
278
|
+
* Quality 4 matches nginx on-the-fly default.
|
|
279
|
+
*/
|
|
280
|
+
declare class BrotliCodec implements CompressionCodec {
|
|
281
|
+
readonly id = 4;
|
|
282
|
+
readonly name = "brotli";
|
|
283
|
+
private readonly quality;
|
|
284
|
+
constructor(quality?: number);
|
|
285
|
+
encode(data: Uint8Array): Uint8Array;
|
|
286
|
+
decode(data: Uint8Array): Uint8Array;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Gzip via node:zlib — universal fallback, slightly worse ratio than brotli.
|
|
290
|
+
*
|
|
291
|
+
* Level 6 matches nginx default.
|
|
292
|
+
*/
|
|
293
|
+
declare class GzipCodec implements CompressionCodec {
|
|
294
|
+
readonly id = 5;
|
|
295
|
+
readonly name = "gzip";
|
|
296
|
+
private readonly level;
|
|
297
|
+
constructor(level?: number);
|
|
298
|
+
encode(data: Uint8Array): Uint8Array;
|
|
299
|
+
decode(data: Uint8Array): Uint8Array;
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Canonical Huffman coding — entropy-optimal per-byte compression.
|
|
303
|
+
*
|
|
304
|
+
* Captures the entropy coding stage of Zstandard/DEFLATE. Pure JS,
|
|
305
|
+
* works everywhere. Excels on data with skewed byte distributions
|
|
306
|
+
* where a few byte values dominate.
|
|
307
|
+
*
|
|
308
|
+
* Format:
|
|
309
|
+
* [0..255] u8×256 code_lengths (one per possible byte value)
|
|
310
|
+
* [256..259] u32 total_bits in the encoded stream
|
|
311
|
+
* [260..] packed bits (MSB-first)
|
|
312
|
+
*
|
|
313
|
+
* Overhead: 260 bytes. Only wins on chunks where entropy coding
|
|
314
|
+
* saves more than 260 bytes — the race handles this automatically.
|
|
315
|
+
*/
|
|
316
|
+
declare class HuffmanCodec implements CompressionCodec {
|
|
317
|
+
readonly id = 6;
|
|
318
|
+
readonly name = "huffman";
|
|
319
|
+
encode(data: Uint8Array): Uint8Array;
|
|
320
|
+
decode(data: Uint8Array, originalSize: number): Uint8Array;
|
|
321
|
+
}
|
|
322
|
+
declare class DictionaryCodec implements CompressionCodec {
|
|
323
|
+
readonly id = 7;
|
|
324
|
+
readonly name = "dictionary";
|
|
325
|
+
encode(data: Uint8Array): Uint8Array;
|
|
326
|
+
decode(data: Uint8Array, originalSize: number): Uint8Array;
|
|
327
|
+
}
|
|
328
|
+
/** Pure-JS codecs — zero dependencies, work everywhere */
|
|
329
|
+
declare const PURE_JS_CODECS: CompressionCodec[];
|
|
330
|
+
/** All built-in codecs including platform codecs (brotli/gzip via node:zlib) */
|
|
331
|
+
declare const BUILTIN_CODECS: CompressionCodec[];
|
|
332
|
+
/** Look up a codec by ID */
|
|
333
|
+
declare function getCodecById(id: number): CompressionCodec;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Topological Compressor — Fork/Race/Fold Applied to Compression
|
|
337
|
+
*
|
|
338
|
+
* Two-level fork/race/fold:
|
|
339
|
+
*
|
|
340
|
+
* LEVEL 1 (stream): Fork the entire input into global strategies.
|
|
341
|
+
* - Path A: Global brotli on the whole stream (cross-chunk dictionary)
|
|
342
|
+
* - Path B: Global gzip on the whole stream
|
|
343
|
+
* - Path C: Per-chunk topological compression (Level 2)
|
|
344
|
+
* Race all paths. Fold to smallest.
|
|
345
|
+
*
|
|
346
|
+
* LEVEL 2 (chunk): For each chunk, fork all codecs.
|
|
347
|
+
* - Race codecs per chunk. Smallest wins.
|
|
348
|
+
* - Vent codecs whose output >= raw.
|
|
349
|
+
* - Fold: self-describing frame per chunk.
|
|
350
|
+
*
|
|
351
|
+
* Stream-level format (when streamRace is enabled):
|
|
352
|
+
* [0] u8 strategy (0 = per-chunk, N>0 = global codec ID)
|
|
353
|
+
* [1..4] u32 original_size
|
|
354
|
+
* [5..] [u8] compressed data
|
|
355
|
+
*
|
|
356
|
+
* Per-chunk frame format:
|
|
357
|
+
* [0] u8 codec_id
|
|
358
|
+
* [1..4] u32 original_size
|
|
359
|
+
* [5..8] u32 compressed_size
|
|
360
|
+
* [9..] [u8] compressed_data
|
|
361
|
+
*
|
|
362
|
+
* Zero dependencies. Works on CF Workers, Deno, Node, Bun, browsers.
|
|
363
|
+
*/
|
|
364
|
+
|
|
365
|
+
/** Per-chunk compression result — which codec won and why */
|
|
366
|
+
interface ChunkResult {
|
|
367
|
+
/** Index of this chunk in the original data */
|
|
368
|
+
chunkIndex: number;
|
|
369
|
+
/** The codec that won the race for this chunk */
|
|
370
|
+
codecId: number;
|
|
371
|
+
/** Codec name (for diagnostics) */
|
|
372
|
+
codecName: string;
|
|
373
|
+
/** Original size of this chunk in bytes */
|
|
374
|
+
originalSize: number;
|
|
375
|
+
/** Compressed size of this chunk in bytes (including 9-byte header) */
|
|
376
|
+
compressedSize: number;
|
|
377
|
+
/** Compression ratio for this chunk (0 = no compression, 1 = perfect) */
|
|
378
|
+
ratio: number;
|
|
379
|
+
/** How many codecs were vented (output >= input) */
|
|
380
|
+
vented: number;
|
|
381
|
+
}
|
|
382
|
+
/** Overall compression result */
|
|
383
|
+
interface TopologicalCompressionResult {
|
|
384
|
+
/** The compressed output — concatenated self-describing frames */
|
|
385
|
+
data: Uint8Array;
|
|
386
|
+
/** Per-chunk results */
|
|
387
|
+
chunks: ChunkResult[];
|
|
388
|
+
/** Total original size */
|
|
389
|
+
originalSize: number;
|
|
390
|
+
/** Total compressed size */
|
|
391
|
+
compressedSize: number;
|
|
392
|
+
/** Overall compression ratio */
|
|
393
|
+
ratio: number;
|
|
394
|
+
/** Number of distinct codecs used across all chunks */
|
|
395
|
+
codecsUsed: number;
|
|
396
|
+
/** β₁ during compression (number of parallel codec paths - 1) */
|
|
397
|
+
bettiNumber: number;
|
|
398
|
+
/** Compression time in milliseconds */
|
|
399
|
+
timeMs: number;
|
|
400
|
+
/** Strategy that won the stream-level race (only set when streamRace=true) */
|
|
401
|
+
strategy?: string;
|
|
402
|
+
}
|
|
403
|
+
/** Compressor configuration */
|
|
404
|
+
interface TopologicalCompressorConfig {
|
|
405
|
+
/** Chunk size in bytes. Smaller = more adaptive, larger = better ratio. */
|
|
406
|
+
chunkSize: number;
|
|
407
|
+
/** Codecs to race. Default: all built-in codecs. */
|
|
408
|
+
codecs: CompressionCodec[];
|
|
409
|
+
/** Enable two-level race: global codecs vs per-chunk topological. Default: false. */
|
|
410
|
+
streamRace?: boolean;
|
|
411
|
+
}
|
|
412
|
+
declare class TopologicalCompressor {
|
|
413
|
+
private readonly config;
|
|
414
|
+
constructor(config?: Partial<TopologicalCompressorConfig>);
|
|
415
|
+
/**
|
|
416
|
+
* Compress data using fork/race/fold.
|
|
417
|
+
*
|
|
418
|
+
* When streamRace=false (default): per-chunk race only.
|
|
419
|
+
* When streamRace=true: two-level race — global codecs vs per-chunk topo.
|
|
420
|
+
*/
|
|
421
|
+
compress(data: Uint8Array): TopologicalCompressionResult;
|
|
422
|
+
/**
|
|
423
|
+
* Decompress data produced by compress().
|
|
424
|
+
*/
|
|
425
|
+
decompress(compressed: Uint8Array): Uint8Array;
|
|
426
|
+
private compressChunked;
|
|
427
|
+
private decompressChunked;
|
|
428
|
+
/**
|
|
429
|
+
* Two-level fork/race/fold:
|
|
430
|
+
*
|
|
431
|
+
* FORK (stream level):
|
|
432
|
+
* ├─ Path 0: Per-chunk topological (Level 2)
|
|
433
|
+
* ├─ Path 1: Global codec A on entire stream
|
|
434
|
+
* ├─ Path 2: Global codec B on entire stream
|
|
435
|
+
* └─ ...
|
|
436
|
+
* RACE: Smallest total output wins
|
|
437
|
+
* FOLD: 5-byte strategy header + compressed data
|
|
438
|
+
*
|
|
439
|
+
* On homogeneous text, global brotli wins (cross-chunk dictionary).
|
|
440
|
+
* On mixed content, per-chunk topo wins (adapts per region).
|
|
441
|
+
* The topology decides — not the programmer.
|
|
442
|
+
*/
|
|
443
|
+
private compressTwoLevel;
|
|
444
|
+
private decompressTwoLevel;
|
|
445
|
+
/** Get the codecs available for racing. */
|
|
446
|
+
getCodecs(): ReadonlyArray<CompressionCodec>;
|
|
447
|
+
/** Get the chunk size. */
|
|
448
|
+
getChunkSize(): number;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export { BUILTIN_CODECS, BrotliCodec, type ChunkResult, type CompressedBatch, type CompressedChunk, type CompressionCodec, CompressionEngine, type CompressionStats, type DeltaBatch, DeltaCodec, type DeltaOperation, type DeltaStats, DeltaSyncOptimizer, DictionaryCodec, GzipCodec, HuffmanCodec, LZ77Codec, PURE_JS_CODECS, RLECodec, RawCodec, type TopologicalCompressionResult, TopologicalCompressor, type TopologicalCompressorConfig, getCodecById, getCompressionEngine, getDeltaSyncOptimizer, resetCompressionEngine, resetDeltaSyncOptimizer };
|