@rindle/wasm 0.1.0-rc.5

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,261 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * The in-memory live-query engine, callable from JavaScript. See the module docs.
6
+ */
7
+ export class Db {
8
+ free(): void;
9
+ [Symbol.dispose](): void;
10
+ /**
11
+ * Tear down a registered query: drop its sink + reclaim its pipeline (disconnect from
12
+ * the shared sources, free its slots — [`Graph::destroy_pipeline`]). Other queries
13
+ * and the shared sources are untouched. A no-op for an unknown id.
14
+ */
15
+ destroyQuery(query_id: number): void;
16
+ constructor();
17
+ /**
18
+ * Register a live query from a Zero-wire AST under the caller's opaque `query_id`.
19
+ * Lowers it into the shared graph, sinks it in a change-sink, and hydrates. Returns
20
+ * `{ queryId, comparatorVersion, schema, snapshot }` — the `hello` + hydrate
21
+ * snapshot for the JS `ArrayView` (snapshot cells **bare**). A malformed AST /
22
+ * unknown table / unknown column throws a JS `Error` carrying a `.kind`.
23
+ */
24
+ query(query_id: number, ast_json: any): any;
25
+ /**
26
+ * Register a base table from a `SchemaSpec` (`{ columns, primaryKey, sort? }` —
27
+ * [`marshal::schema_from_js`]; any `relationships` in the spec are ignored — nesting
28
+ * is query-local via `sub`). Seeds an empty shared source. Idempotent per name.
29
+ */
30
+ registerTable(table: string, schema: any): void;
31
+ /**
32
+ * Open a §1.3 reconcile cycle against the coherent server delta `deltas` —
33
+ * an array of base-table row ops `{ table, type: "add"|"remove"|"edit", row,
34
+ * old? }` (the cv-released normalized batch, bare cells). Runs the rewind
35
+ * (steps 1–4): the engine's input becomes the authoritative state `S'`, with
36
+ * every optimistic write un-applied and the server delta folded in; `sync`
37
+ * re-forks. Nothing is delivered yet — the JS side now **re-invokes each
38
+ * still-pending client mutator** (ordinary `write()`/`commit()` calls, whose
39
+ * events buffer into the cycle), then calls
40
+ * [`server_batch_end`](Db::server_batch_end) for the one coalesced delivery.
41
+ *
42
+ * Errors if a cycle is already open, on an unknown table, or on a push failure
43
+ * — after which the optimistic state is poisoned (a partial rewind may have
44
+ * applied): the only safe recovery is to discard this `Db` and re-hydrate.
45
+ */
46
+ serverBatchBegin(deltas: any): void;
47
+ /**
48
+ * Close the open cycle: deliver the whole buffered event stream (rewind +
49
+ * re-invocations) per query, **in order**, as `[{ queryId, events: FlatChange[] }]`
50
+ * — one batch per affected query. The stream is forwarded RAW: the IVM sink emits
51
+ * changes in a valid incremental order (`FLAT-CHANGES-DESIGN.md` §5.4), so the
52
+ * receiver folds them in order to reach `view(head_new)`. The §3 "notify once"
53
+ * boundary is the view's own — one `applyChanges` per batch, settling before it
54
+ * notifies. Queries the cycle never touched are omitted.
55
+ *
56
+ * Note: a still-pending write whose re-invocation reproduced its prediction emits a
57
+ * balanced `remove`+`add` here. That nets to no observable change once the view
58
+ * settles, but it is no longer suppressed *at this boundary* (the netting/reordering
59
+ * that did so was the source of the coalescer correctness bugs). Restoring
60
+ * no-op-cycle ⇒ no-notify is a view-level optimization (Step 2 of the removal).
61
+ */
62
+ serverBatchEnd(): any;
63
+ /**
64
+ * Remove a base table previously added by [`register_table`](Self::register_table): free
65
+ * its source node, drop its optimistic baseline, and forget it from the source map — the
66
+ * inverse of `register_table`. For a SYNTHETIC aggregate table (`__agg_*`) whose last
67
+ * reading query has been destroyed (`AGGREGATE-SYNC-DESIGN.md` §4): aggregate state is
68
+ * reclaimed, not permanent. Idempotent for an unknown/already-removed table. Throws a JS
69
+ * `Error` if the table still has a live query connected to it — the caller must
70
+ * `destroy_query` every reader first (the optimistic/normalized backend refcounts so this
71
+ * holds).
72
+ */
73
+ unregisterTable(table: string): void;
74
+ /**
75
+ * Open a write transaction. Stage row ops with [`WriteTxn::add`]/`remove`/`edit`,
76
+ * then [`WriteTxn::commit`] to apply them as one batch and get the per-query flat
77
+ * changes back. Dropping (or `rollback`) without committing applies nothing.
78
+ */
79
+ write(): WriteTxn;
80
+ }
81
+
82
+ /**
83
+ * A built, hydrated query view, callable from JavaScript.
84
+ */
85
+ export class RindleView {
86
+ private constructor();
87
+ free(): void;
88
+ [Symbol.dispose](): void;
89
+ /**
90
+ * Build + hydrate a view from an AST (JS JSON) and a table→schema map.
91
+ *
92
+ * - `ast_json`: the query AST — Zero's wire shape (see `src/ast.rs`).
93
+ * - `schemas`: `{ tableName: <SchemaSpec> }` (see [`marshal::schema_from_js`]).
94
+ * - `data`: optional `{ tableName: row[][] }` initial rows (each row a cell
95
+ * array, positional with the schema's `columns`); a table absent here seeds
96
+ * empty.
97
+ *
98
+ * A `BuildError`/`RindleError` is thrown as a JS `Error` with a `.kind` tag.
99
+ */
100
+ static build(ast_json: any, schemas: any, data: any): RindleView;
101
+ /**
102
+ * The current materialized view tree as a JS value (array / object / `null`).
103
+ */
104
+ data(): any;
105
+ /**
106
+ * Close the current transaction: fire listeners with the new snapshot.
107
+ */
108
+ flush(): void;
109
+ /**
110
+ * Push one source change `{ type: 'add'|'remove'|'edit', row, old? }` to `table`.
111
+ * Does **not** flush — call [`RindleView::flush`] to close the transaction (so a JS
112
+ * client can batch several pushes into one notification).
113
+ */
114
+ push(table: string, change: any): void;
115
+ /**
116
+ * The view's current result type (`"unknown" | "complete" | "error"`).
117
+ */
118
+ resultType(): any;
119
+ /**
120
+ * Resolve the async result type (the `queryComplete` transition); fires
121
+ * listeners out of band. Accepts `"complete" | "error" | "unknown"`.
122
+ */
123
+ setResultType(rt: string): void;
124
+ /**
125
+ * Subscribe a JS callback `(data, resultType) => void`, fired **once
126
+ * immediately** and on every subsequent [`RindleView::flush`]. Returns the
127
+ * listener index.
128
+ */
129
+ subscribe(cb: Function): number;
130
+ }
131
+
132
+ /**
133
+ * An open write transaction: a staging buffer of row ops applied atomically at
134
+ * [`commit`](WriteTxn::commit). Nothing touches the engine until commit, so a dropped or
135
+ * rolled-back txn is a clean no-op (no `Drop` undo needed).
136
+ */
137
+ export class WriteTxn {
138
+ private constructor();
139
+ free(): void;
140
+ [Symbol.dispose](): void;
141
+ /**
142
+ * Stage an add of `row` (a positional cell array, width-checked against the table's
143
+ * schema) to `table`.
144
+ */
145
+ add(table: string, row: any): void;
146
+ /**
147
+ * Apply the staged ops (push through the shared sources, fanning to every dependent
148
+ * query), drain each affected query's sink, and return `[{ queryId, events:
149
+ * FlatChange[] }]` for the queries that changed (empties omitted, like
150
+ * `Publisher::commit`). Consumes the transaction.
151
+ *
152
+ * **Inside a server-batch cycle** (a pending mutator re-invocation between
153
+ * [`Db::server_batch_begin`] and [`Db::server_batch_end`]) the drained events
154
+ * buffer into the cycle instead and an **empty** array returns — the §3
155
+ * notify-once boundary: the whole cycle delivers exactly once, coalesced, at
156
+ * `serverBatchEnd`.
157
+ */
158
+ commit(): any;
159
+ /**
160
+ * Stage an edit of `old` → `new_row` in `table` (both width-checked).
161
+ *
162
+ * **Partial (optimistic) edit (`PROJECTION-SUPPORT-DESIGN.md` §8 / OQ-3).** An
163
+ * [`OwnedValue::Absent`] cell in `new_row` means *"not touching this column — leave it
164
+ * unchanged"*: it falls through to the current **effective** row (the live engine under
165
+ * this txn's staged overlay, i.e. what [`WriteTxn::get`] would return). The merge is
166
+ * resolved **here, at the staging boundary**, into a concrete full-width
167
+ * [`SourceChange::Edit`] whose `old` is that effective row — so operators, indexes, and
168
+ * the overlay never learn about merge semantics (they keep seeing whole rows), and a
169
+ * re-invocation after a server rebase re-reads the *new* effective row and re-merges.
170
+ * Presence is **monotonic**: a partial edit only *sets* columns (or leaves them), never
171
+ * narrows — narrowing is sync-only (§4.2). A full `new_row` (no `Absent`) stages verbatim,
172
+ * byte-identical to before (§7).
173
+ */
174
+ edit(table: string, old: any, new_row: any): void;
175
+ /**
176
+ * The current row of `table` whose primary key equals `pk` (an array of the PK
177
+ * column cells, in `primaryKey` order), or `undefined`. Reads the live engine
178
+ * state **plus this transaction's own staged ops** (later staged ops win), so a
179
+ * read-dependent client mutator sees its prior writes — the §4.1 contract. During
180
+ * a server-batch cycle the live state is the rebased base (`S'` + the pending
181
+ * mutations re-invoked so far), which is exactly what re-invocation must read.
182
+ */
183
+ get(table: string, pk: any): any;
184
+ /**
185
+ * Stage a remove of `row` from `table`.
186
+ */
187
+ remove(table: string, row: any): void;
188
+ /**
189
+ * Discard the staged ops without applying anything. (Nothing was applied, so this
190
+ * just consumes the handle; it exists for a symmetric, explicit API.)
191
+ */
192
+ rollback(): void;
193
+ }
194
+
195
+ /**
196
+ * Install the panic hook so a residual wasm panic surfaces a legible JS `Error`
197
+ * (with a Rust message) instead of an opaque `RuntimeError: unreachable` (WS09.6).
198
+ * Runs once on module load.
199
+ */
200
+ export function __rindle_wasm_start(): void;
201
+
202
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
203
+
204
+ export interface InitOutput {
205
+ readonly memory: WebAssembly.Memory;
206
+ readonly __rindle_wasm_start: () => void;
207
+ readonly __wbg_db_free: (a: number, b: number) => void;
208
+ readonly __wbg_rindleview_free: (a: number, b: number) => void;
209
+ readonly __wbg_writetxn_free: (a: number, b: number) => void;
210
+ readonly db_destroyQuery: (a: number, b: number) => void;
211
+ readonly db_new: () => number;
212
+ readonly db_query: (a: number, b: number, c: any) => [number, number, number];
213
+ readonly db_registerTable: (a: number, b: number, c: number, d: any) => [number, number];
214
+ readonly db_serverBatchBegin: (a: number, b: any) => [number, number];
215
+ readonly db_serverBatchEnd: (a: number) => [number, number, number];
216
+ readonly db_unregisterTable: (a: number, b: number, c: number) => [number, number];
217
+ readonly db_write: (a: number) => number;
218
+ readonly rindleview_build: (a: any, b: any, c: any) => [number, number, number];
219
+ readonly rindleview_data: (a: number) => any;
220
+ readonly rindleview_flush: (a: number) => void;
221
+ readonly rindleview_push: (a: number, b: number, c: number, d: any) => [number, number];
222
+ readonly rindleview_resultType: (a: number) => any;
223
+ readonly rindleview_setResultType: (a: number, b: number, c: number) => void;
224
+ readonly rindleview_subscribe: (a: number, b: any) => number;
225
+ readonly writetxn_add: (a: number, b: number, c: number, d: any) => [number, number];
226
+ readonly writetxn_commit: (a: number) => [number, number, number];
227
+ readonly writetxn_edit: (a: number, b: number, c: number, d: any, e: any) => [number, number];
228
+ readonly writetxn_get: (a: number, b: number, c: number, d: any) => [number, number, number];
229
+ readonly writetxn_remove: (a: number, b: number, c: number, d: any) => [number, number];
230
+ readonly writetxn_rollback: (a: number) => void;
231
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
232
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
233
+ readonly __wbindgen_exn_store: (a: number) => void;
234
+ readonly __externref_table_alloc: () => number;
235
+ readonly __wbindgen_externrefs: WebAssembly.Table;
236
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
237
+ readonly __externref_table_dealloc: (a: number) => void;
238
+ readonly __wbindgen_start: () => void;
239
+ }
240
+
241
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
242
+
243
+ /**
244
+ * Instantiates the given `module`, which can either be bytes or
245
+ * a precompiled `WebAssembly.Module`.
246
+ *
247
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
248
+ *
249
+ * @returns {InitOutput}
250
+ */
251
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
252
+
253
+ /**
254
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
255
+ * for everything else, calls `WebAssembly.instantiate` directly.
256
+ *
257
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
258
+ *
259
+ * @returns {Promise<InitOutput>}
260
+ */
261
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;