colbin 0.0.0-stage → 0.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/core.js ADDED
@@ -0,0 +1,360 @@
1
+ // The `Codec` handle — INTERNALS.md §16.2.
2
+ //
3
+ // Everything the module can do hangs off one instance, and the instance is
4
+ // what holds the schema. That is the shape the format's recommended delivery
5
+ // already implies: a section is sent once per connection, so the thing that
6
+ // parses it should outlive the message that follows it.
7
+ //
8
+ // # Why the operations are synchronous
9
+ //
10
+ // `Codec.open()` is async because compiling WebAssembly is, and there is no
11
+ // synchronous escape — `new WebAssembly.Module` is blocked on the main thread
12
+ // above 4 KB and this module is 244 KB. Everything after that is not:
13
+ // `new WebAssembly.Instance` over an already-compiled module is synchronous,
14
+ // so `open` instantiates once and every call afterwards is a straight run of
15
+ // wasm calls with no `await` in it.
16
+ //
17
+ // That is what lets one instance back the whole handle rather than the pool
18
+ // `web/src/lib/codec.ts` needed. The pool existed because that file compiled
19
+ // lazily inside each call, so two calls fired with `Promise.all` could both be
20
+ // waiting on `compile()` and then interleave their writes into one instance's
21
+ // `INPUT`. With the compile hoisted into `open`, a call cannot be preempted
22
+ // between writing its input and reading its output, because there is nothing
23
+ // in it to preempt.
24
+ import { ColbinError } from "./errors.js";
25
+ import { readRows, readColumns } from "./materialize.js";
26
+ /** Encode flags, mirroring `colbin::build`. */
27
+ const SELF_DESCRIBING = 1;
28
+ const VERIFY = 2;
29
+ /** Byte 0 of a message, with bit 2 set, says the section is in front of the
30
+ * body. See `rust/wasm/src/lib.rs` and ENCODER.md. */
31
+ const ROOT_SCHEMA_BIT = 0x04;
32
+ const ROOT_FIRST = 0xd0;
33
+ const ROOT_LAST = 0xdf;
34
+ const encoder = new TextEncoder();
35
+ const decoder = new TextDecoder();
36
+ /**
37
+ * The handle. One WebAssembly instance, the schema it holds, and the module's
38
+ * whole surface.
39
+ *
40
+ * Construct it with `Codec.open()` from whichever entry point suits — `colbin`
41
+ * carries the module inline, `colbin/asset` resolves it as a URL beside
42
+ * itself.
43
+ */
44
+ export class Codec {
45
+ #exports;
46
+ /** The section last written into this instance, by identity. Holding it is
47
+ * what keeps a handle from re-parsing the same section once per message. */
48
+ #applied = null;
49
+ #held = null;
50
+ #lastPath = 'json';
51
+ constructor(exports) {
52
+ this.#exports = exports;
53
+ }
54
+ /**
55
+ * Compiles the module and instantiates it. Async because compiling
56
+ * WebAssembly is; nothing after it is.
57
+ */
58
+ static async open(options = {}) {
59
+ const module = options.module ?? (await compile(options.wasm));
60
+ return Codec.fromModule(module);
61
+ }
62
+ /** A second handle over an already-compiled module — its own instance, its
63
+ * own schema, no compile. */
64
+ static fromModule(module) {
65
+ // No imports: the module does not abort, and a missing import would be a
66
+ // link error rather than a trap on first use.
67
+ const instance = new WebAssembly.Instance(module, {});
68
+ return new Codec(instance.exports);
69
+ }
70
+ /**
71
+ * Holds a schema section for the messages that follow — the delivery the
72
+ * format recommends, where the section is sent once per connection and every
73
+ * message after it carries only its body. `null` clears it.
74
+ *
75
+ * A self-describing message ignores this and uses its own.
76
+ */
77
+ setSchema(section) {
78
+ this.#held = section && section.length > 0 ? section : null;
79
+ }
80
+ /** Which path the last {@link unmarshal} took: a caller that wants to know
81
+ * it landed on the slow one should not have to guess. */
82
+ get lastPath() {
83
+ return this.#lastPath;
84
+ }
85
+ /**
86
+ * A message to real objects, without JSON text in the middle when the shape
87
+ * allows it.
88
+ *
89
+ * The fast path is the one that is exact past 2^53: a column whose values do
90
+ * not fit a `Number` comes back as `bigint`, where the JSON fallback goes
91
+ * through `JSON.parse` and rounds like any other JSON reader would.
92
+ * {@link lastPath} says which ran.
93
+ */
94
+ unmarshal(message, options = {}) {
95
+ const e = this.#exports;
96
+ this.#schema(options.section);
97
+ // A module built without `materialize` has no fast path to try, and that
98
+ // is not an error — the text path answers every shape. Treated exactly
99
+ // like the materializer declining the shape.
100
+ const length = this.canMaterialize ? this.#call(e.materialize(this.#write(message))) : 0;
101
+ if (length > 0) {
102
+ this.#lastPath = 'materialize';
103
+ // A copy this call owns outright, not a live view: `readRows` builds
104
+ // several typed-array views over it, and any later `alloc` that grows
105
+ // the module's memory would detach every one of them.
106
+ const at = e.result_ptr();
107
+ return readRows(e.memory.buffer.slice(at, at + length), options);
108
+ }
109
+ // Not the table shape the materializer covers — the text path.
110
+ this.#lastPath = 'json';
111
+ return JSON.parse(this.toJSONText(message, options));
112
+ }
113
+ /**
114
+ * The columns themselves, for a caller feeding a grid or a chart that never
115
+ * wants row objects — it skips even the 7 µs the row build costs.
116
+ *
117
+ * Returns `null` when the message is not the table shape the fast path covers, since
118
+ * there is no honest column view of a nested document; such a caller should
119
+ * fall back to {@link unmarshal}.
120
+ */
121
+ columns(message, options = {}) {
122
+ const e = this.#exports;
123
+ this.#needs('materialize', 'materialize', 'rebuild the module with --features materialize');
124
+ this.#schema(options.section);
125
+ const length = this.#call(e.materialize(this.#write(message)));
126
+ if (length === 0)
127
+ return null;
128
+ const at = e.result_ptr();
129
+ return readColumns(e.memory.buffer.slice(at, at + length));
130
+ }
131
+ /** A message back to JSON text. Every shape, and the only path for the ones
132
+ * {@link unmarshal} reports as `json`. */
133
+ toJSONText(message, options = {}) {
134
+ const e = this.#exports;
135
+ this.#schema(options.section);
136
+ const length = this.#call(e.decode(this.#write(message)));
137
+ return decoder.decode(this.#result(length));
138
+ }
139
+ /**
140
+ * A value or JSON text to a colbin message.
141
+ *
142
+ * A string is taken as JSON text and handed to the module as it stands;
143
+ * anything else goes through `JSON.stringify` first — which means an integer
144
+ * past 2^53 must arrive as text, since by the time it is a JavaScript
145
+ * `Number` it has already been rounded.
146
+ */
147
+ marshal(value, options = {}) {
148
+ const e = this.#exports;
149
+ this.#needs('encode', 'encode', 'rebuild the module with --features encode');
150
+ const text = typeof value === 'string' ? value : JSON.stringify(value);
151
+ const flags = options.verify ? VERIFY : 0;
152
+ const length = this.#call(e.encode(this.#write(encoder.encode(text)), flags));
153
+ const message = this.#result(length);
154
+ const section = this.#result(this.#call(e.section()));
155
+ // Warnings ride in the same envelope as errors, and reading them
156
+ // overwrites the output — so both copies are already taken above.
157
+ const warnings = this.#diagnostic().warnings;
158
+ let standalone;
159
+ return {
160
+ message,
161
+ section,
162
+ warnings,
163
+ get standalone() {
164
+ // The self-describing form is the same body behind the same section,
165
+ // with bit 2 of the root byte set — so it is composed here rather than
166
+ // encoded a second time. `js/tests/package.test.mjs` asserts this
167
+ // against what the module writes for `SELF_DESCRIBING` over the whole
168
+ // corpus, which is what makes the shortcut checkable rather than
169
+ // merely plausible.
170
+ if (standalone)
171
+ return standalone;
172
+ // A typed narrow message has no root byte unless its key run begins in
173
+ // the root range, so the root is the message's own first byte only then.
174
+ const rooted = message.length > 0 && message[0] >= ROOT_FIRST && message[0] <= ROOT_LAST;
175
+ const body = rooted ? message.subarray(1) : message;
176
+ const out = new Uint8Array(1 + section.length + body.length);
177
+ out[0] = (rooted ? message[0] : ROOT_FIRST) | ROOT_SCHEMA_BIT;
178
+ out.set(section, 1);
179
+ out.set(body, 1 + section.length);
180
+ standalone = out;
181
+ return out;
182
+ },
183
+ };
184
+ }
185
+ /**
186
+ * The field tree of a message, with every node's byte span — absolute
187
+ * offsets into the bytes handed in, so a hex view needs no arithmetic.
188
+ *
189
+ * Needs a module built with the `inspect` feature, which is **not** the one
190
+ * `colbin` and `colbin/asset` carry: the span walk is 15 KB that nothing but
191
+ * a tool drawing the bytes ever calls, so it has a module of its own behind
192
+ * `colbin/inspect`.
193
+ */
194
+ inspect(message, options = {}) {
195
+ const e = this.#exports;
196
+ this.#needs('inspect_message', 'inspect', "import { Codec } from 'colbin/inspect'");
197
+ this.#schema(options.section);
198
+ const length = this.#call(e.inspect_message(this.#write(message)));
199
+ return JSON.parse(decoder.decode(this.#result(length)));
200
+ }
201
+ /** Whether this handle's module can {@link inspect} — i.e. whether it came
202
+ * from `colbin/inspect` or another build with the feature on. */
203
+ get canInspect() {
204
+ return typeof this.#exports.inspect_message === 'function';
205
+ }
206
+ /** Whether this handle's module carries the fast path. True of every build
207
+ * this package ships; false only for a module a caller supplied. */
208
+ get canMaterialize() {
209
+ return typeof this.#exports.materialize === 'function';
210
+ }
211
+ /** The flag the encoder needs to write a document that carries its own
212
+ * schema, for a caller composing `encode` flags directly. */
213
+ static get SELF_DESCRIBING() {
214
+ return SELF_DESCRIBING;
215
+ }
216
+ // --- the boundary ------------------------------------------------------
217
+ /**
218
+ * Writes `input` into the module and returns its length, which is what every
219
+ * export takes. Allocate first and take the view second: allocating may grow
220
+ * memory, and growing detaches every view taken before it.
221
+ */
222
+ #write(input) {
223
+ const e = this.#exports;
224
+ const at = e.alloc(input.length);
225
+ new Uint8Array(e.memory.buffer).set(input, at);
226
+ return input.length;
227
+ }
228
+ /** A copy of the module's last output. */
229
+ #result(length) {
230
+ const e = this.#exports;
231
+ const at = e.result_ptr();
232
+ return new Uint8Array(e.memory.buffer).slice(at, at + length);
233
+ }
234
+ /**
235
+ * Refuses a call the module was not built to answer, by name, before it
236
+ * becomes a `TypeError: e.inspect_message is not a function` several frames
237
+ * from anything a caller can act on.
238
+ *
239
+ * Which exports exist is a property of the bytes, not of this wrapper: the
240
+ * module is built per feature set (`rust/wasm/Cargo.toml`), and the entries
241
+ * differ in which build they carry.
242
+ */
243
+ #needs(exported, feature, fix) {
244
+ if (typeof this.#exports[exported] === 'function')
245
+ return;
246
+ throw new Error(`colbin: this module was built without \`${feature}\`, so it has no ` +
247
+ `\`${exported}\` export. ${fix}`);
248
+ }
249
+ /** Turns the ABI's negative length into the thrown `ColbinError`. */
250
+ #call(length) {
251
+ if (length < 0)
252
+ throw new ColbinError(this.#diagnostic());
253
+ return length;
254
+ }
255
+ #diagnostic() {
256
+ const e = this.#exports;
257
+ return JSON.parse(decoder.decode(this.#result(e.last_error())));
258
+ }
259
+ /**
260
+ * Makes this instance hold `section` — the per-call one when there is one,
261
+ * the handle's own otherwise.
262
+ *
263
+ * Compared by identity, not by content: re-parsing a section the instance
264
+ * already holds is exactly the cost a handle exists to avoid, and
265
+ * a caller who mutates a section's bytes in place and passes the same object
266
+ * again is not a case worth a memcmp per message.
267
+ */
268
+ #schema(section) {
269
+ const want = section && section.length > 0 ? section : this.#held;
270
+ if (want === this.#applied)
271
+ return;
272
+ const e = this.#exports;
273
+ this.#call(want === null ? e.set_schema(0) : e.set_schema(this.#write(want)));
274
+ this.#applied = want;
275
+ }
276
+ }
277
+ /** Turns whatever `open` was given into a compiled module. */
278
+ async function compile(source) {
279
+ if (source === undefined) {
280
+ throw new TypeError('colbin: no module to compile — pass `wasm` or `module` to Codec.open(), ' +
281
+ "or import an entry that carries one ('colbin' or 'colbin/asset')");
282
+ }
283
+ const resolved = await source;
284
+ if (resolved instanceof WebAssembly.Module)
285
+ return resolved;
286
+ if (typeof resolved === 'string' || resolved instanceof URL) {
287
+ return compileResponse(await fetch(resolved));
288
+ }
289
+ if (typeof Response !== 'undefined' && resolved instanceof Response) {
290
+ return compileResponse(resolved);
291
+ }
292
+ return WebAssembly.compile(resolved);
293
+ }
294
+ async function compileResponse(response) {
295
+ if (!response.ok) {
296
+ throw new Error(`colbin: ${response.url || 'the module'} answered ${response.status}`);
297
+ }
298
+ // `compileStreaming` needs the right content type and some static hosts do
299
+ // not set it, so fall back on the header rather than fail on it.
300
+ if (typeof WebAssembly.compileStreaming === 'function' &&
301
+ response.headers.get('content-type')?.includes('application/wasm')) {
302
+ return WebAssembly.compileStreaming(response);
303
+ }
304
+ return WebAssembly.compile(await response.arrayBuffer());
305
+ }
306
+ /**
307
+ * The `Codec` an entry point exports: `open()` with the entry's own way of
308
+ * finding the module already wired in, overridable per call.
309
+ *
310
+ * Compiled once per entry and cached, so a page that opens a second handle
311
+ * pays for an instance and not for a compile.
312
+ */
313
+ export function codecFor(source) {
314
+ let compiled;
315
+ const module = () => (compiled ??= compile(source()));
316
+ return {
317
+ async open(options = {}) {
318
+ if (options.module)
319
+ return Codec.fromModule(options.module);
320
+ if (options.wasm !== undefined)
321
+ return Codec.open(options);
322
+ return Codec.fromModule(await module());
323
+ },
324
+ fromModule: Codec.fromModule,
325
+ preload() {
326
+ void module().catch(() => { });
327
+ },
328
+ };
329
+ }
330
+ /**
331
+ * The free functions each entry re-exports — `unmarshal(bytes)` without
332
+ * holding a handle, for the caller who has one message to read and no
333
+ * connection to hold a schema for.
334
+ *
335
+ * They share one lazily-opened codec rather than opening a fresh one per call:
336
+ * a fresh instance per message is what the handle exists to avoid, and none of these
337
+ * hold a schema across calls, so there is nothing for the sharing to leak.
338
+ */
339
+ export function convenience(entry) {
340
+ let held;
341
+ const codec = () => (held ??= entry.open());
342
+ return {
343
+ async unmarshal(message, options) {
344
+ return (await codec()).unmarshal(message, options);
345
+ },
346
+ async columns(message, options) {
347
+ return (await codec()).columns(message, options);
348
+ },
349
+ async toJSONText(message, options) {
350
+ return (await codec()).toJSONText(message, options);
351
+ },
352
+ async marshal(value, options) {
353
+ return (await codec()).marshal(value, options);
354
+ },
355
+ async inspect(message, options) {
356
+ return (await codec()).inspect(message, options);
357
+ },
358
+ };
359
+ }
360
+ //# sourceMappingURL=core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,2CAA2C;AAC3C,EAAE;AACF,2EAA2E;AAC3E,6EAA6E;AAC7E,4EAA4E;AAC5E,wDAAwD;AACxD,EAAE;AACF,uCAAuC;AACvC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,sEAAsE;AACtE,6EAA6E;AAC7E,6EAA6E;AAC7E,oCAAoC;AACpC,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,+EAA+E;AAC/E,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,oBAAoB;AAEpB,OAAO,EAAE,WAAW,EAAmB,MAAM,aAAa,CAAA;AAC1D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAA0C,MAAM,kBAAkB,CAAA;AAEhG,+CAA+C;AAC/C,MAAM,eAAe,GAAG,CA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,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO;YAC5B,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAClD,CAAC;QACD,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO;YAC/B,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QACrD,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO;YAC1B,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAChD,CAAC;QACD,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO;YAC5B,OAAO,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;QAClD,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The one failure type. INTERNALS.md §16.2: a thrown error rather than an
3
+ * `Outcome` union, because a library consumer's normal path is success and a
4
+ * page that wants a union can wrap this in three lines.
5
+ *
6
+ * Every field the module's diagnostic carries survives onto the error, so a
7
+ * caller can point at the byte that failed rather than re-deriving it from a
8
+ * message string.
9
+ */
10
+ export declare class ColbinError extends Error {
11
+ /** The module's diagnostic code. `2` is the wire-level refusal every
12
+ * decode-only build can still produce; the encoder's parser uses its own. */
13
+ readonly code: number;
14
+ /** Byte offset into the input the failure was found at, or -1. */
15
+ readonly offset: number;
16
+ /** 1-based line, for a failure in JSON text, or -1. */
17
+ readonly line: number;
18
+ /** The path through the document — `records[3].price` — or `''`. */
19
+ readonly path: string;
20
+ /** Warnings the module gathered before it gave up. Usually empty. */
21
+ readonly warnings: string[];
22
+ constructor(diagnostic: Diagnostic);
23
+ }
24
+ /** The JSON envelope `colbin::diag::Diag::encode` writes. */
25
+ export type Diagnostic = {
26
+ code: number;
27
+ offset: number;
28
+ line: number;
29
+ path: string;
30
+ message: string;
31
+ warnings: string[];
32
+ };
33
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;iFAC6E;IAC7E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,kEAAkE;IAClE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,qEAAqE;IACrE,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;gBAEf,UAAU,EAAE,UAAU;CASnC;AAED,6DAA6D;AAC7D,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB,CAAA"}
package/dist/errors.js ADDED
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The one failure type. INTERNALS.md §16.2: a thrown error rather than an
3
+ * `Outcome` union, because a library consumer's normal path is success and a
4
+ * page that wants a union can wrap this in three lines.
5
+ *
6
+ * Every field the module's diagnostic carries survives onto the error, so a
7
+ * caller can point at the byte that failed rather than re-deriving it from a
8
+ * message string.
9
+ */
10
+ export class ColbinError extends Error {
11
+ /** The module's diagnostic code. `2` is the wire-level refusal every
12
+ * decode-only build can still produce; the encoder's parser uses its own. */
13
+ code;
14
+ /** Byte offset into the input the failure was found at, or -1. */
15
+ offset;
16
+ /** 1-based line, for a failure in JSON text, or -1. */
17
+ line;
18
+ /** The path through the document — `records[3].price` — or `''`. */
19
+ path;
20
+ /** Warnings the module gathered before it gave up. Usually empty. */
21
+ warnings;
22
+ constructor(diagnostic) {
23
+ super(diagnostic.message);
24
+ this.name = 'ColbinError';
25
+ this.code = diagnostic.code;
26
+ this.offset = diagnostic.offset;
27
+ this.line = diagnostic.line;
28
+ this.path = diagnostic.path;
29
+ this.warnings = diagnostic.warnings ?? [];
30
+ }
31
+ }
32
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC;iFAC6E;IACpE,IAAI,CAAQ;IACrB,kEAAkE;IACzD,MAAM,CAAQ;IACvB,uDAAuD;IAC9C,IAAI,CAAQ;IACrB,oEAAoE;IAC3D,IAAI,CAAQ;IACrB,qEAAqE;IAC5D,QAAQ,CAAU;IAE3B,YAAY,UAAsB;QAChC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,MAAM,CAAA;QAC/B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAA;QAC3B,IAAI,CAAC,QAAQ,GAAG,UAAU,CAAC,QAAQ,IAAI,EAAE,CAAA;IAC3C,CAAC;CACF"}