@fossil-lang/wasm 0.3.0-alpha.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.
@@ -0,0 +1,284 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Opaque handle the JS side keys on. Plain `u32` newtype; NOT the Salsa
6
+ * interned id (which doesn't cross the JS boundary).
7
+ *
8
+ * `Copy + Clone + Eq + Hash` so it can be a `HashMap` key on the Rust
9
+ * side; `#[wasm_bindgen]` so JS can pass it back across the boundary.
10
+ */
11
+ export class FileHandle {
12
+ private constructor();
13
+ free(): void;
14
+ [Symbol.dispose](): void;
15
+ }
16
+
17
+ /**
18
+ * JS-facing handle for the Fossil compiler running inside a WASM module.
19
+ *
20
+ * One instance owns one [`WasmDb`] (Salsa store + injected [`WasmSystem`]
21
+ * + `Arc<OutputDescriptorKind>`). Hosts construct a single playground per
22
+ * browser tab / Node process and reuse it across all method calls to
23
+ * amortise the Salsa interning + memoisation overhead.
24
+ */
25
+ export class FossilPlayground {
26
+ free(): void;
27
+ [Symbol.dispose](): void;
28
+ /**
29
+ * Run `parse → def_map → typecheck_mapping` across every open file and
30
+ * return a flat JS array of `{ uri, range, severity, message }` rows
31
+ * keyed by file URI. The LSP Worker (07-03) republishes these grouped
32
+ * by URI as `textDocument/publishDiagnostics` notifications.
33
+ *
34
+ * `range` is the UTF-16 LSP range (via `fossil_ide::LineIndex` — the
35
+ * rust-analyzer model from 06-05). `severity` is the LSP integer
36
+ * constant (1 = error, 2 = warning, 3 = info). `message` carries any
37
+ * `suggestion_source` as a `\nhelp: ...` suffix (mirroring `fossil-lsp`
38
+ * `to_lsp_diagnostic` in 06-09).
39
+ *
40
+ * # Errors
41
+ *
42
+ * Returns a JS error only if the result fails to serialize to `JsValue`.
43
+ */
44
+ check(): any;
45
+ /**
46
+ * Return the stdlib classification manifest as a JS array of
47
+ * `{ name, wasm_class }` objects (STDL-07).
48
+ *
49
+ * `wasm_class` is the string `"pure_sql"` or `"native_udf_only"`. The
50
+ * playground reads this once at startup to render `native_udf_only`
51
+ * functions as disabled with a "native-only — unavailable in the browser"
52
+ * tooltip (SC#1 playground half). `DuckDB`-WASM cannot register the Rust
53
+ * UDFs those functions need (Pitfall 3), so the classification is the
54
+ * authority on what is runnable in-browser.
55
+ *
56
+ * This is pure read-only data projected from the `&'static`-ready
57
+ * `fossil_registry::FunctionRegistry` — no `DuckDB`, no native UDF code,
58
+ * WASM-clean.
59
+ *
60
+ * # Errors
61
+ *
62
+ * Returns a JS error only if the manifest fails to serialize to `JsValue`.
63
+ */
64
+ classification(): any;
65
+ /**
66
+ * Close a file in the workspace. Idempotent in spirit but strict in
67
+ * signal: closing an unknown / already-closed handle is an error so
68
+ * JS-side bugs surface loudly (mirrors `ty_wasm`).
69
+ *
70
+ * # Errors
71
+ *
72
+ * Returns a JS error if `handle` was never opened or was already closed.
73
+ */
74
+ close_file(handle: FileHandle): void;
75
+ /**
76
+ * Per-file diagnostic drain — the B3 follow-up accessor the LSP Worker
77
+ * (07-03) consumes for its per-file `publishDiagnostics` notifications.
78
+ * `check()` returns the workspace-wide flat array; `diagnostics_for`
79
+ * returns just one file's rows so 07-03 can dispatch one notification
80
+ * per affected URI without partitioning the workspace array on the JS
81
+ * side.
82
+ *
83
+ * # Errors
84
+ *
85
+ * Returns a JS error if `handle` is unknown, or if serialization fails.
86
+ */
87
+ diagnostics_for(handle: FileHandle): any;
88
+ /**
89
+ * Construct a new playground.
90
+ *
91
+ * Installs `console_error_panic_hook` (idempotent — RESEARCH.md
92
+ * Don't-Hand-Roll #8) so any panic inside compiler-core surfaces as a
93
+ * `console.error` stack trace in the host (browser `DevTools` or Node).
94
+ */
95
+ constructor();
96
+ /**
97
+ * Open a file in the workspace. Returns a [`FileHandle`] the JS side
98
+ * keys subsequent `update_file` / `close_file` / `compile_file` calls
99
+ * on. `path` is the URI / virtual path the diagnostics carry back to
100
+ * the LSP client.
101
+ *
102
+ * Mirrors `ty_wasm::Workspace::open_file` (Astral). Interns a fresh
103
+ * [`fossil_base::SourceFile`] under the current Salsa revision.
104
+ *
105
+ * # Errors
106
+ *
107
+ * Returns a JS error only if the internal counter is exhausted
108
+ * (`u32::MAX` files — would require a runaway loop in JS, not a normal
109
+ * failure mode).
110
+ */
111
+ open_file(path: string, contents: string): FileHandle;
112
+ /**
113
+ * Register an [`fossil_descriptors_input::InferredDescriptor`] for a
114
+ * source binding name BEFORE invoking [`Self::compile`] /
115
+ * [`Self::compile_file`]. The Rust compiler reads from this registration
116
+ * during forward type propagation (Phase 3 CORE-05 rewired in plan
117
+ * 13-02).
118
+ *
119
+ * `descriptor_json` is the JSON serialisation of `InferredDescriptor`;
120
+ * the canonical shape is exposed in `packages/wasm/src/index.ts` as
121
+ * `InferredDescriptorJson`:
122
+ *
123
+ * ```json
124
+ * {
125
+ * "source_name": "users",
126
+ * "columns": [
127
+ * { "name": "id", "primitive": "Integer" },
128
+ * { "name": "name", "primitive": "String" }
129
+ * ],
130
+ * "content_hash": ""
131
+ * }
132
+ * ```
133
+ *
134
+ * Called by the browser-side playground orchestration AFTER running
135
+ * DuckDB-WASM `DESCRIBE read_csv_auto('<resolved-url>')` and BEFORE
136
+ * invoking `compile()` / `compile_file()`. Keyed by source-binding
137
+ * name (`"users"` for `users := io.csv("...")`), NOT by URL.
138
+ *
139
+ * Idempotent: re-registering with the same `source_name` OVERWRITES the
140
+ * previous entry — intentional, since the host may re-introspect when
141
+ * file content changes.
142
+ *
143
+ * # Errors
144
+ *
145
+ * - Malformed JSON / missing required fields → JS `Error` with the
146
+ * underlying `serde_json` message.
147
+ *
148
+ * Implementation: thin shim over the pure-Rust
149
+ * [`Self::register_inferred_descriptor_native`] helper.
150
+ */
151
+ registerInferredDescriptor(descriptor_json: string): void;
152
+ /**
153
+ * Install a user-supplied `ShEx` schema as the active output descriptor.
154
+ * On parse failure the previously-installed descriptor is RETAINED (no
155
+ * half-applied state — a broken schema must never wedge the editor;
156
+ * same contract as `fossil-lsp`'s `load_sibling_shex` in 06-09).
157
+ *
158
+ * The schema is parsed via
159
+ * [`fossil_descriptors_output::ShExDescriptor::from_reader`] (no
160
+ * network access — Pitfall 1) and wrapped in
161
+ * [`OutputDescriptorKind::ShEx`]. The resulting `Arc` is swapped into
162
+ * the [`WasmDb`]'s descriptor slot atomically; future `fossil-ide`
163
+ * feature calls (hover, completion) reading
164
+ * [`HirDb::output_descriptor_kind`] see the new schema.
165
+ *
166
+ * # Errors
167
+ *
168
+ * Returns a JS error if the text is not a parseable `ShEx` schema.
169
+ */
170
+ set_target_shex(text: string): void;
171
+ /**
172
+ * Apply an edit to an open file. Mutates the SAME `SourceFile` via the
173
+ * Salsa [`salsa::Setter`] (`set_text`) — this BUMPS THE REVISION, the
174
+ * real cancellation trigger (ADR-0022): any in-flight analysis from the
175
+ * previous keystroke observes the new revision at its next cooperative
176
+ * checkpoint. NO new `SourceFile` is interned — the Salsa input
177
+ * identity stays stable across the file's lifetime, so memoised
178
+ * downstream queries (`def_map`, `typecheck_mapping`) invalidate
179
+ * incrementally instead of falling off a cliff.
180
+ *
181
+ * # Errors
182
+ *
183
+ * Returns a JS error if `handle` was never opened or was already closed.
184
+ */
185
+ update_file(handle: FileHandle, contents: string): void;
186
+ }
187
+
188
+ /**
189
+ * `JS`-facing re-export of the Phase-6 06-07 semantic-token legend.
190
+ *
191
+ * Returns `{ tokenTypes: string[], tokenModifiers: string[] }` — the exact
192
+ * LSP `SemanticTokensLegend` shape. `CodeMirror` (plan 08-08 +
193
+ * `packages/codemirror-fossil/src/tags.ts`) uses this to translate
194
+ * LSP `semanticTokens/full` response indices into highlight tag names.
195
+ *
196
+ * Delegates to [`fossil_ide::semantic_legend`] (the 06-07 authoritative
197
+ * definition) — NO duplicate legend definition lives here.
198
+ *
199
+ * # Errors
200
+ *
201
+ * Returns a JS error only if `serde_wasm_bindgen` fails (impossible in
202
+ * practice for the legend shape).
203
+ */
204
+ export function semantic_legend(): any;
205
+
206
+ /**
207
+ * Worker entrypoint. Idempotent in spirit — calling twice replaces the
208
+ * previous `onmessage` handler (the leaked Closure from the first call
209
+ * stays alive but is no longer referenced by the global scope).
210
+ *
211
+ * Must be called from a `DedicatedWorker` global scope; returns a JS error
212
+ * otherwise (e.g. if called from the main thread).
213
+ *
214
+ * # Errors
215
+ *
216
+ * Returns a JS error when not running inside a `DedicatedWorker` scope.
217
+ */
218
+ export function start_lsp_worker(): void;
219
+
220
+ /**
221
+ * `JS`-facing tokenize. Returns the same row stream as [`tokenize_native`],
222
+ * serialised via `serde_wasm_bindgen`. Consumed by
223
+ * `@fossil-lang/codemirror-fossil`'s `StreamParser` (plan 08-08).
224
+ *
225
+ * # Errors
226
+ *
227
+ * Returns a JS error only if `serde_wasm_bindgen` fails to serialise the
228
+ * row vector (effectively impossible for `Vec<{u32,u32,u32}>` — kept on the
229
+ * signature for forward compatibility if `TokenRow` ever grows non-trivial
230
+ * fields).
231
+ */
232
+ export function tokenize(text: string): any;
233
+
234
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
235
+
236
+ export interface InitOutput {
237
+ readonly memory: WebAssembly.Memory;
238
+ readonly start_lsp_worker: () => [number, number];
239
+ readonly tokenize: (a: number, b: number) => [number, number, number];
240
+ readonly semantic_legend: () => [number, number, number];
241
+ readonly __wbg_filehandle_free: (a: number, b: number) => void;
242
+ readonly __wbg_fossilplayground_free: (a: number, b: number) => void;
243
+ readonly fossilplayground_new: () => number;
244
+ readonly fossilplayground_classification: (a: number) => [number, number, number];
245
+ readonly fossilplayground_open_file: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
246
+ readonly fossilplayground_update_file: (a: number, b: number, c: number, d: number) => [number, number];
247
+ readonly fossilplayground_close_file: (a: number, b: number) => [number, number];
248
+ readonly fossilplayground_check: (a: number) => [number, number, number];
249
+ readonly fossilplayground_diagnostics_for: (a: number, b: number) => [number, number, number];
250
+ readonly fossilplayground_set_target_shex: (a: number, b: number, c: number) => [number, number];
251
+ readonly fossilplayground_registerInferredDescriptor: (a: number, b: number, c: number) => [number, number];
252
+ readonly wasm_bindgen__convert__closures_____invoke__h4393dedb0066ad40: (a: number, b: number, c: any) => void;
253
+ readonly __wbindgen_malloc_command_export: (a: number, b: number) => number;
254
+ readonly __wbindgen_realloc_command_export: (a: number, b: number, c: number, d: number) => number;
255
+ readonly __wbindgen_exn_store_command_export: (a: number) => void;
256
+ readonly __externref_table_alloc_command_export: () => number;
257
+ readonly __wbindgen_externrefs: WebAssembly.Table;
258
+ readonly __wbindgen_free_command_export: (a: number, b: number, c: number) => void;
259
+ readonly __wbindgen_destroy_closure_command_export: (a: number, b: number) => void;
260
+ readonly __externref_table_dealloc_command_export: (a: number) => void;
261
+ readonly __wbindgen_start: () => void;
262
+ }
263
+
264
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
265
+
266
+ /**
267
+ * Instantiates the given `module`, which can either be bytes or
268
+ * a precompiled `WebAssembly.Module`.
269
+ *
270
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
271
+ *
272
+ * @returns {InitOutput}
273
+ */
274
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
275
+
276
+ /**
277
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
278
+ * for everything else, calls `WebAssembly.instantiate` directly.
279
+ *
280
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
281
+ *
282
+ * @returns {Promise<InitOutput>}
283
+ */
284
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;