@zakkster/lite-bake-stream 1.0.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.
@@ -0,0 +1,92 @@
1
+ // Type declarations for @zakkster/lite-bake-stream/writer
2
+ // Copyright (c) 2026 Zahary Shinikchiev. MIT.
3
+
4
+ export const VERSION: string;
5
+
6
+ export type LaneKindName = 'f64' | 'u32';
7
+ export type LaneKindNumeric = 1 | 3; // 1 = F64, 3 = U32
8
+
9
+ export interface FieldDeclaration {
10
+ name: string;
11
+ /** 'f64' | 'u32' | 1 | 3. */
12
+ laneKind?: LaneKindName | LaneKindNumeric;
13
+ }
14
+
15
+ export interface Schema {
16
+ /** Field names (all F64) or field declarations (mixed lanes). */
17
+ fields: (string | FieldDeclaration)[];
18
+ }
19
+
20
+ export interface WriterOptions {
21
+ schema?: Schema;
22
+ /** Target output bytes per shard. Default 32 MB. */
23
+ targetShardBytes?: number;
24
+ /**
25
+ * Bytes of input to observe before freezing an inferred schema. Only used
26
+ * in sample-and-infer mode (no explicit schema). Default = targetShardBytes.
27
+ */
28
+ sampleBytes?: number;
29
+ }
30
+
31
+ export interface FrozenField {
32
+ name: string;
33
+ /** 1 = F64, 3 = U32. */
34
+ laneKind: LaneKindNumeric;
35
+ offsetInRow: number;
36
+ }
37
+
38
+ export interface FrozenSchema {
39
+ fields: FrozenField[];
40
+ rowStride: number;
41
+ }
42
+
43
+ export interface Container {
44
+ buffer: ArrayBuffer;
45
+ totalRows: number;
46
+ shardCount: number;
47
+ schema: FrozenSchema;
48
+ }
49
+
50
+ export class Writer implements TokenizerSinkForWriter {
51
+ constructor(opts?: WriterOptions);
52
+ /**
53
+ * Sink protocol — the Tokenizer calls these. Byte ranges are ephemeral.
54
+ */
55
+ onStartObject(): void;
56
+ onEndObject(): void;
57
+ onStartArray(): void;
58
+ onEndArray(): void;
59
+ onKey(bytes: Uint8Array, from: number, to: number): void;
60
+ onNumber(value: number): void;
61
+ onString(bytes: Uint8Array, from: number, to: number): void;
62
+ onTrue(): void;
63
+ onFalse(): void;
64
+ onNull(): void;
65
+ onEnd(): void;
66
+ /** Optional: set the current input byte offset for byte-estimate tracking. */
67
+ setInputByteOffset(n: number): void;
68
+ /**
69
+ * Seal the container and return the LBK1 binary. Call once, after the
70
+ * Tokenizer has been given `end()`.
71
+ */
72
+ finalize(): Container;
73
+ readonly schema: FrozenSchema | null;
74
+ readonly totalRows: number;
75
+ readonly shardCount: number;
76
+ }
77
+
78
+ // Structural type — the Writer conforms to the Tokenizer's sink protocol.
79
+ // (Redeclared here so the /writer subpath is self-contained.)
80
+ interface TokenizerSinkForWriter {
81
+ onStartObject(): void;
82
+ onEndObject(): void;
83
+ onKey(bytes: Uint8Array, from: number, to: number): void;
84
+ onNumber(value: number): void;
85
+ onString(bytes: Uint8Array, from: number, to: number): void;
86
+ }
87
+
88
+ export class WriterError extends Error {
89
+ code: string;
90
+ name: 'WriterError';
91
+ constructor(code: string, message: string);
92
+ }
@@ -0,0 +1,58 @@
1
+ // Type declarations for @zakkster/lite-bake-stream (root entry)
2
+ // Copyright (c) 2026 Zahary Shinikchiev. MIT.
3
+
4
+ export { Tokenizer, TokenizerError } from './Tokenizer.d.ts';
5
+ export type { TokenizerSink, TokenizerOptions } from './Tokenizer.d.ts';
6
+ export { Writer, WriterError } from './Writer.d.ts';
7
+ export type {
8
+ Schema, FieldDeclaration, WriterOptions,
9
+ FrozenField, FrozenSchema, Container,
10
+ LaneKindName, LaneKindNumeric,
11
+ } from './Writer.d.ts';
12
+ export { Reader, ReaderError } from './Reader.d.ts';
13
+ export type {
14
+ ShardHandle, StringTableView, Bounds, FindShardsOptions,
15
+ } from './Reader.d.ts';
16
+ export { StringTable } from './StringTable.d.ts';
17
+ export { PreserveTokenizer, PreserveTokenizerError } from './PreserveTokenizer.d.ts';
18
+ export type { PreserveSink, PreserveTokenizerOptions } from './PreserveTokenizer.d.ts';
19
+ export { PreserveWriter, PreserveWriterError } from './PreserveWriter.d.ts';
20
+ export type { PreserveWriterOptions, PreserveContainer } from './PreserveWriter.d.ts';
21
+ export { PreserveReader, PreserveReaderError } from './PreserveReader.d.ts';
22
+ export type { PreserveShardHandle } from './PreserveReader.d.ts';
23
+
24
+ export const VERSION: string;
25
+
26
+ export interface SerializeOptions {
27
+ /** When true, use preserve mode: opaque byte blobs, any JSON shape. */
28
+ preserve?: boolean;
29
+ framing?: 'ndjson' | 'array' | 'auto';
30
+ /**
31
+ * Writer options. Union of schema-mode and preserve-mode fields.
32
+ * Schema mode reads schema/targetShardBytes/sampleBytes.
33
+ * Preserve mode reads targetShardBytes/maxRecordBytes.
34
+ */
35
+ writer?: import('./Writer.d.ts').WriterOptions & import('./PreserveWriter.d.ts').PreserveWriterOptions;
36
+ }
37
+
38
+ /**
39
+ * One-shot compile input data to an LBK1 container.
40
+ * Schema mode (default): F64/U32 lane packing, query pruning.
41
+ * Preserve mode (opts.preserve=true): opaque byte blobs, any JSON shape.
42
+ */
43
+ export function serialize(
44
+ input: Uint8Array | string | Iterable<object>,
45
+ opts?: SerializeOptions
46
+ ): Uint8Array;
47
+ export function serialize(
48
+ input: ReadableStream<Uint8Array> | AsyncIterable<Uint8Array>,
49
+ opts?: SerializeOptions
50
+ ): Promise<Uint8Array>;
51
+
52
+ /**
53
+ * Deserialize LBK1 bytes into the right Reader for the container's mode.
54
+ * Auto-detects preserve vs schema via the header flag byte.
55
+ */
56
+ export function deserialize(
57
+ bytes: Uint8Array | ArrayBuffer
58
+ ): import('./Reader.d.ts').Reader | import('./PreserveReader.d.ts').PreserveReader;