@fossil-lang/wasm 0.3.0-alpha.2 → 0.3.0-alpha.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.
package/dist/index.d.ts CHANGED
@@ -1,73 +1,46 @@
1
1
  /**
2
2
  * @fossil-lang/wasm — JS/TS wrapper around the fossil-wasm wasm-bindgen artifacts.
3
3
  *
4
- * Public API (one of the six @fossil-lang/* packages per ADR-0028):
4
+ * Public API (one of the @fossil-lang/* packages; `git ls-files packages` is
5
+ * the list):
5
6
  * - {@link initFossilWasm} — consumer-controlled .wasm URL loader (memoised).
6
- * - {@link tokenize} — calls the Rust lexer, returns TokenRow[] (ADR-0030).
7
- * - {@link semanticLegend} — returns the LSP SemanticTokensLegend (Phase-6 06-07).
8
- * - {@link FossilPlayground} — Workspace API class (ADR-0024) for the LSP.
7
+ * - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
8
+ * - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
9
+ * - {@link semanticLegend} — returns the LSP SemanticTokensLegend.
10
+ * - {@link FossilPlayground} — Workspace API class: open / update / close,
11
+ * `check`, and the three position queries (`hover`, `completions`,
12
+ * `gotoDefinition`) an editor draws its IDE surface from.
9
13
  *
10
- * Consumer pattern (wasm-bindgen --target web — RESEARCH.md Pattern 3):
14
+ * Consumer pattern (wasm-bindgen --target web):
11
15
  *
12
16
  * import { initFossilWasm, tokenize } from '@fossil-lang/wasm';
13
17
  * import wasmUrl from '@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm?url'; // Vite
14
18
  *
15
19
  * await initFossilWasm({ wasmUrl });
16
- * const tokens = tokenize('prefix ex: <https://example.org/>');
20
+ * const tokens = tokenize('User := io.csv("data/people.csv")');
17
21
  */
18
- import { FileHandle as RawFileHandle } from '../pkg/fossil_wasm.js';
19
- import type { TokenRow, SemanticTokensLegend } from '@fossil-lang/types';
20
22
  export { initFossilWasm } from './load.js';
21
23
  export type { InitFossilWasmOpts } from './load.js';
22
- /**
23
- * Install the LSP-over-postMessage dispatcher on the current Worker scope.
24
- *
25
- * Per ADR-0024 (`fossil-wasm` IS the LSP server-side) + Phase 7 plan 07-03
26
- * (the 16-route dispatch loop). The Rust function (re-exported from
27
- * `crates/fossil-wasm/src/lsp_worker.rs`) installs `self.onmessage` on the
28
- * Worker scope and owns LSP JSON-RPC dispatch from that point forward —
29
- * including per-file `textDocument/publishDiagnostics` drains (B3 fix from
30
- * 07-03), `textDocument/semanticTokens/full` (06-07), hover, completion,
31
- * definition, references, rename, formatting, code actions, document
32
- * symbols, signature help.
33
- *
34
- * MUST be called inside a Web Worker scope, AFTER {@link initFossilWasm} has
35
- * resolved. Calling it on the main thread is a no-op (the dispatcher needs
36
- * `DedicatedWorkerGlobalScope.onmessage`).
37
- *
38
- * Consumed by `@fossil-lang/playground`'s `src/workers/lsp.worker.ts` —
39
- * the React component's LSP Worker entry boots the WASM module then calls
40
- * this function once.
41
- */
42
- export declare function start_lsp_worker(): void;
43
- /**
44
- * Opaque file-handle returned by {@link FossilPlayground.openFile}. Pass it
45
- * back into the matching `updateFile` / `closeFile` / `diagnosticsFor`
46
- * calls. JS code cannot construct one directly (the wasm-bindgen
47
- * class has a private constructor) — that is intentional per ADR-0024:
48
- * handles are minted only by `openFile` on the Rust side, where they index a
49
- * `HashMap<FileHandle, SourceFile>` keyed by a `u32` newtype.
50
- */
51
- export type FileHandle = RawFileHandle;
52
- /**
53
- * Tokenize a Fossil source string. Returns the byte-range tokens from the
54
- * canonical Rust lexer (`fossil_syntax::lexer::raw_lex`) — single grammar
55
- * source of truth per ADR-0030.
56
- *
57
- * MUST be called after {@link initFossilWasm} has resolved; otherwise the
58
- * underlying wasm-bindgen function throws (the wasm module is not yet
59
- * instantiated).
60
- */
61
- export declare function tokenize(text: string): TokenRow[];
62
- /**
63
- * Returns the LSP `SemanticTokensLegend` (token types + modifiers list) the
64
- * editor uses to map LSP `semanticTokens/full` response indices to highlight
65
- * categories. Re-export of `fossil_ide::semantic_legend` (Phase-6 06-07) over
66
- * the wasm-bindgen boundary — NO duplicate legend definition lives here.
67
- *
68
- * MUST be called after {@link initFossilWasm} has resolved.
69
- */
70
- export declare function semanticLegend(): SemanticTokensLegend;
24
+ export { start_lsp_worker, tokenize, tokenKinds, semanticLegend, FossilPlayground, refs, providers, } from './client.js';
25
+ export type { FileHandle } from './client.js';
26
+ /** One external reference a program makes — the typed lineage returned by
27
+ * {@link refs}. Mirrors `fossil_lineage::SourceRefInfo` (the SAME struct the
28
+ * native `fossil refs` emits). `connection` is the `@conn` alias the reference
29
+ * targets, or `null` for a direct URL/path; `role` is where it appears in the
30
+ * source constructor. The host resolves `@conn` → `{base}/path` itself. */
31
+ export interface SourceRefInfo {
32
+ connection: string | null;
33
+ path: string;
34
+ role: 'data' | 'schema';
35
+ }
36
+ /** One data-source provider returned by {@link providers}. Mirrors
37
+ * `fossil_lineage::ProviderInfo`: the short name (`csv`, `rdf`, …), the file
38
+ * extensions it reads (no leading dot), and how it can be used. */
39
+ export interface ProviderInfo {
40
+ name: string;
41
+ extensions: string[];
42
+ kind: 'schema' | 'data' | 'both';
43
+ }
71
44
  /** Diagnostic row returned by {@link FossilPlayground.check} and
72
45
  * {@link FossilPlayground.diagnosticsFor} — mirrors `fossil-wasm`'s
73
46
  * `CheckRow` JSON shape (the LSP `Diagnostic` projected through
@@ -75,172 +48,110 @@ export declare function semanticLegend(): SemanticTokensLegend;
75
48
  */
76
49
  export interface CheckRow {
77
50
  uri: string;
78
- range: {
79
- start: {
80
- line: number;
81
- character: number;
82
- };
83
- end: {
84
- line: number;
85
- character: number;
86
- };
87
- };
51
+ range: LspRange;
88
52
  severity: number;
89
53
  message: string;
90
54
  }
91
- /** Stdlib classification entry returned by {@link FossilPlayground.classification}.
92
- * `wasm_class` indicates whether a stdlib function can execute in-browser
93
- * (`"pure_sql"`) or requires the native runtime (`"native_udf_only"`). The
94
- * playground reads this once at startup to render `native_udf_only` functions
95
- * as disabled (STDL-07 / SC#1 playground half).
96
- */
97
- export interface StdlibClass {
98
- name: string;
99
- wasm_class: 'pure_sql' | 'native_udf_only';
55
+ /** An LSP range: zero-based lines, `character` in UTF-16 code units — the units
56
+ * a JavaScript string is indexed in, so no byte arithmetic converts it. (The
57
+ * lexer's {@link TokenRow} offsets are the other thing: those ARE bytes.) */
58
+ export interface LspRange {
59
+ start: {
60
+ line: number;
61
+ character: number;
62
+ };
63
+ end: {
64
+ line: number;
65
+ character: number;
66
+ };
67
+ }
68
+ /** What {@link FossilPlayground.hover} found: the rendered Markdown — a
69
+ * ` ```fossil ` fence, the type of what you wrote and where it came from, and
70
+ * a second block with the type the target shape demands of that predicate when
71
+ * the shape resolves — and the range it applies to. */
72
+ export interface HoverRow {
73
+ markdown: string;
74
+ range: LspRange;
75
+ }
76
+ /** One candidate from {@link FossilPlayground.completions}.
77
+ *
78
+ * `kind` is the LSP `CompletionItemKind` **by name**, lowercased —
79
+ * `"function"`, `"field"`, `"enum_member"` — and `""` when the item carries
80
+ * none. Rust owns that table (`fossil_wasm::ide::kind_name`, total over the
81
+ * twenty-five the spec defines) because a table in TypeScript is one nothing
82
+ * can check: the deleted predecessor of `@fossil-lang/codemirror-fossil`
83
+ * hard-copied the lexer's discriminants and was wrong in nine places by the
84
+ * time it went.
85
+ *
86
+ * `detail` is the signature, the shape property's IRI, or the source field's
87
+ * inferred type — whatever the compiler wrote beside the label; `""` when it
88
+ * wrote none. Neither field is optional, on purpose: an absent optional is the
89
+ * one shape `serde_json` and `serde_wasm_bindgen` are measured to disagree
90
+ * about. */
91
+ export interface CompletionRow {
92
+ label: string;
93
+ kind: string;
94
+ detail: string;
95
+ }
96
+ /** One place {@link FossilPlayground.gotoDefinition} found a definition.
97
+ *
98
+ * `uri` is the key the buffer was opened under, VERBATIM — matching
99
+ * {@link CheckRow.uri}, and not a `file://` URI. Two of the four positions
100
+ * goto-def recognises resolve into the shape document, so a target in another
101
+ * file is the ordinary case and a host with one editor pane has to read this
102
+ * before it moves a cursor. */
103
+ export interface DefinitionRow {
104
+ uri: string;
105
+ range: LspRange;
100
106
  }
101
107
  /**
102
- * Canonical primitive names for inferred-descriptor columns. Must match the
103
- * lookup table in `fossil-hir::infer::primitive_from_name` (ADR-0037). Names
104
- * map 1:1 to the `Primitive` enum in HIR (Integer, Float, String, Bool, Date,
105
- * DateTime, Time, GYear, AnyURI).
108
+ * The primitive lattice, as `fossil-graph-schema` serialises it — the same enum
109
+ * the checker types against, not a set of names it looks up.
106
110
  *
107
- * Unknown / non-canonical strings are accepted on the wire — the Rust side
108
- * coerces them to `String` and emits a `D-INFERRED-UNKNOWN-DATATYPE`
109
- * diagnostic. Hosts SHOULD canonicalise their DuckDB `DESCRIBE` output to
110
- * these names before registering.
111
+ * A value outside this union is REJECTED when the descriptor is registered:
112
+ * `registerInferredDescriptor` returns the serde error naming the offending
113
+ * value. It is no longer coerced to `string` with a diagnostic three crates
114
+ * later, so a host that sends a type fossil does not carry finds out at the
115
+ * call, not in a compile.
111
116
  */
112
- export type InferredPrimitive = 'String' | 'Integer' | 'Float' | 'Bool' | 'Date' | 'DateTime' | 'Time' | 'GYear' | 'AnyURI';
117
+ export type InferredPrimitive = 'string' | 'integer' | 'float' | 'bool' | 'date' | 'date_time' | 'time' | 'g_year' | 'any_uri';
113
118
  /** One column from a host-introspected source. */
114
119
  export interface InferredColumnJson {
115
120
  name: string;
116
121
  primitive: InferredPrimitive;
117
122
  }
118
123
  /**
119
- * Host-introspected input schema. Produced by the playground's browser-side
120
- * `DuckDB-WASM` `DESCRIBE read_csv_auto('<url>')` call (see plan 13-04b);
121
- * consumed by the Rust compiler via
122
- * {@link FossilPlayground.registerInferredDescriptor}. See ADR-0037 for the
123
- * full architectural rationale (drop user-facing CSVW; host-side
124
- * introspection feeds the compiler ahead of `compile()`).
125
- */
126
- export interface InferredDescriptorJson {
127
- /** Source binding name (e.g. `"users"` for `users := io.csv(...)`). */
128
- source_name: string;
129
- /** Ordered columns — order is significant for column-position fallback. */
130
- columns: InferredColumnJson[];
131
- /**
132
- * Opaque content-hash. Empty string means "let the Rust side derive a
133
- * deterministic hash from the column tuple list" (used for Salsa keying).
134
- * Hosts that already maintain a per-file content-hash (e.g. resolver-side)
135
- * MAY supply it.
136
- */
137
- content_hash: string;
138
- }
139
- /**
140
- * Workspace API class (ADR-0024). Thin TS wrapper around the wasm-bindgen
141
- * `FossilPlayground` that exposes camelCase method names for JS idiom + better
142
- * TS inference (the raw bindings use snake_case from the Rust impl block).
143
- *
144
- * One instance per browser tab / Node process — the instance owns the Salsa
145
- * store + `Arc<OutputDescriptorKind>` for the schema slot. Subsequent
146
- * `openFile` calls intern fresh `SourceFile` inputs under the same Salsa
147
- * revision so `updateFile` benefits from incremental memoisation.
124
+ * Host-introspected input schema. Produced by a `DESCRIBE SELECT * FROM
125
+ * <reader>('<url>')` the host runs — `DuckDB-WASM` in a browser — where the
126
+ * reader is the one the binding's `io.` constructor names: `read_csv_auto`,
127
+ * `read_json_auto` or `read_parquet`. `@fossil-lang/introspect` is the one home
128
+ * for that, and picking the reader off the constructor is not a nicety: a
129
+ * Parquet file read as CSV fails DuckDB's sniffer outright, and a JSON array
130
+ * read as CSV introspects to a single column named `[`.
148
131
  *
149
- * The Phase 7 LSP Worker (07-03) drives this class via postMessage; the React
150
- * component in `@fossil-lang/playground` (08-09) does the same via the
151
- * WorkerTransport adapter.
152
- *
153
- * NOTE: {@link FileHandle} is opaque — JS cannot construct one. Callers receive
154
- * a handle from `openFile` and pass it back to subsequent operations. The Rust
155
- * side keeps a `HashMap<FileHandle, SourceFile>` indexed by a `u32` newtype;
156
- * the wasm-bindgen wrapper exposes that as a class with `private constructor()`.
132
+ * Consumed by the Rust compiler via
133
+ * {@link FossilPlayground.registerInferredDescriptor}. There is no metadata
134
+ * sidecar for the user to write and keep in sync: the host introspects the
135
+ * real file and feeds the compiler ahead of `compile()`.
157
136
  */
158
- export declare class FossilPlayground {
159
- private _inner;
160
- constructor();
161
- /**
162
- * Free the underlying WASM-side Salsa store. Call when the playground is no
163
- * longer needed (e.g. component unmount). Idempotent in spirit — subsequent
164
- * method calls on a freed playground throw.
165
- */
166
- free(): void;
167
- /**
168
- * Return the stdlib classification manifest (STDL-07). The playground reads
169
- * this once at startup to render `native_udf_only` functions as disabled
170
- * with a "native-only — unavailable in the browser" tooltip.
171
- */
172
- classification(): StdlibClass[];
173
- /**
174
- * Open a file in the workspace. Returns the {@link FileHandle} subsequent
175
- * `updateFile` / `closeFile` / `diagnosticsFor` calls key
176
- * on. `path` is the URI / virtual path diagnostics carry back to the LSP
177
- * client (e.g. `"file:///tmp/a.fossil"` or `"untitled:Untitled-1"`).
178
- *
179
- * Mirrors `ty_wasm::Workspace::open_file` (Astral). Interns a fresh
180
- * `fossil_base::SourceFile` under the current Salsa revision.
181
- */
182
- openFile(path: string, contents: string): FileHandle;
183
- /**
184
- * Apply an edit to an open file. Mutates the SAME `SourceFile` via the
185
- * Salsa `Setter` (`set_text`) — this BUMPS THE REVISION (ADR-0022), the
186
- * real cancellation trigger. NO new `SourceFile` is interned, so memoised
187
- * downstream queries (`def_map`, `typecheck_mapping`) invalidate
188
- * incrementally instead of falling off a cliff.
189
- */
190
- updateFile(handle: FileHandle, contents: string): void;
191
- /**
192
- * Close a file in the workspace. Strict in signal: closing an unknown /
193
- * already-closed handle throws so JS-side bugs surface loudly (mirrors
194
- * `ty_wasm`).
195
- */
196
- closeFile(handle: FileHandle): void;
197
- /**
198
- * Workspace-wide diagnostic drain. Runs `parse → def_map →
199
- * typecheck_mapping` across every open file and returns a flat array of
200
- * {@link CheckRow}. The LSP Worker (07-03) republishes these grouped by URI
201
- * as `textDocument/publishDiagnostics` notifications.
202
- */
203
- check(): CheckRow[];
204
- /**
205
- * Per-file diagnostic drain — the B3 follow-up accessor the LSP Worker uses
206
- * for its per-file `publishDiagnostics` notifications. `check()` returns
207
- * the workspace-wide flat array; `diagnosticsFor` returns just one file's
208
- * rows so 07-03 can dispatch one notification per affected URI without
209
- * partitioning the workspace array on the JS side.
210
- */
211
- diagnosticsFor(handle: FileHandle): CheckRow[];
137
+ export interface InferredDescriptorJson {
212
138
  /**
213
- * Install a user-supplied ShEx schema as the active output descriptor. On
214
- * parse failure the previously-installed descriptor is RETAINED (no
215
- * half-applied state — same contract as `fossil-lsp::load_sibling_shex` in
216
- * 06-09). Future `fossil-ide` feature calls (hover, completion) reading
217
- * `HirDb::output_descriptor_kind` see the new schema atomically.
139
+ * The source URI exactly as the program writes it — the string inside
140
+ * `io.csv("examples/users.csv")`. NOT the binding name, and NOT the URL the
141
+ * host resolved in order to read the file: the checker only ever sees what
142
+ * the program says.
218
143
  */
219
- setTargetShex(text: string): void;
144
+ uri: string;
145
+ /** Ordered columns — order is significant for column-position fallback. */
146
+ columns: InferredColumnJson[];
220
147
  /**
221
- * Register an {@link InferredDescriptorJson} for a source binding name
222
- * BEFORE invoking {@link check}. The Rust compiler reads from this
223
- * registration during forward type propagation (Phase 3 CORE-05 rewired in
224
- * plan 13-02).
225
- *
226
- * The browser-side orchestration runs DuckDB-WASM
227
- * `DESCRIBE read_csv_auto('<resolved-url>')` for each `io.csv("...")`
228
- * reference in the source, canonicalises the columns to the
229
- * {@link InferredPrimitive} catalog, and calls this method with the
230
- * resulting descriptor before {@link check}. See ADR-0037 for the full
231
- * architectural rationale.
232
- *
233
- * Keyed by source-binding name (e.g. `"users"` for
234
- * `users := io.csv("...")`), NOT by URL. Idempotent — re-registering with
235
- * the same `source_name` overwrites the previous entry.
236
- *
237
- * @throws Error if the descriptor JSON fails to deserialise on the Rust
238
- * side (e.g. missing required fields). The error message includes
239
- * the underlying serde_json diagnostic.
240
- *
241
- * @see ADR-0037 — drop user-facing CSVW; infer via DuckDB DESCRIBE
148
+ * Opaque token identifying the state of the source this was read from. The
149
+ * cache compares it and nothing interprets it: an ETag, a digest, a
150
+ * `Last-Modified`, whatever the host can get cheaply. Empty means "I cannot
151
+ * tell", which the cache reads as never-fresh, so that source is
152
+ * re-introspected on every compile.
242
153
  */
243
- registerInferredDescriptor(descriptor: InferredDescriptorJson): void;
154
+ freshness_token: string;
244
155
  }
245
156
  export type { TokenRow, SemanticTokensLegend } from '@fossil-lang/types';
246
157
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,EAEL,UAAU,IAAI,aAAa,EAI5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAEvC;AAED;;;;;;;GAOG;AACH,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC;AAEvC;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,EAAE,CAMjD;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,oBAAoB,CAErD;AAED;;;;GAIG;AACH,MAAM,WAAW,QAAQ;IACvB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE;QACL,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;QAC3C,GAAG,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,SAAS,EAAE,MAAM,CAAA;SAAE,CAAC;KAC1C,CAAC;IACF,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,UAAU,GAAG,iBAAiB,CAAC;CAC5C;AAED;;;;;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AAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;gCAMgC;AAChC,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,QAAQ,CAAC;CACjB;AAYD;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GACzB,QAAQ,GACR,SAAS,GACT,OAAO,GACP,MAAM,GACN,MAAM,GACN,WAAW,GACX,MAAM,GACN,QAAQ,GACR,SAAS,CAAC;AAEd,kDAAkD;AAClD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,iBAAiB,CAAC;CAC9B;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,2EAA2E;IAC3E,OAAO,EAAE,kBAAkB,EAAE,CAAC;IAC9B;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,CAAC;CACzB;AAKD,YAAY,EAAE,QAAQ,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,201 +1,30 @@
1
1
  /**
2
2
  * @fossil-lang/wasm — JS/TS wrapper around the fossil-wasm wasm-bindgen artifacts.
3
3
  *
4
- * Public API (one of the six @fossil-lang/* packages per ADR-0028):
4
+ * Public API (one of the @fossil-lang/* packages; `git ls-files packages` is
5
+ * the list):
5
6
  * - {@link initFossilWasm} — consumer-controlled .wasm URL loader (memoised).
6
- * - {@link tokenize} — calls the Rust lexer, returns TokenRow[] (ADR-0030).
7
- * - {@link semanticLegend} — returns the LSP SemanticTokensLegend (Phase-6 06-07).
8
- * - {@link FossilPlayground} — Workspace API class (ADR-0024) for the LSP.
7
+ * - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
8
+ * - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
9
+ * - {@link semanticLegend} — returns the LSP SemanticTokensLegend.
10
+ * - {@link FossilPlayground} — Workspace API class: open / update / close,
11
+ * `check`, and the three position queries (`hover`, `completions`,
12
+ * `gotoDefinition`) an editor draws its IDE surface from.
9
13
  *
10
- * Consumer pattern (wasm-bindgen --target web — RESEARCH.md Pattern 3):
14
+ * Consumer pattern (wasm-bindgen --target web):
11
15
  *
12
16
  * import { initFossilWasm, tokenize } from '@fossil-lang/wasm';
13
17
  * import wasmUrl from '@fossil-lang/wasm/pkg/fossil_wasm_bg.wasm?url'; // Vite
14
18
  *
15
19
  * await initFossilWasm({ wasmUrl });
16
- * const tokens = tokenize('prefix ex: <https://example.org/>');
20
+ * const tokens = tokenize('User := io.csv("data/people.csv")');
17
21
  */
18
- // '../pkg/fossil_wasm.js' is a wasm-bindgen --target web output emitted by `pnpm run build:wasm`.
19
- // Gitignored at the repo root (`packages/wasm/pkg/`) but always present at build time. The accompanying
20
- // .d.ts is consumed via the file's `/* @ts-self-types="./fossil_wasm.d.ts" */` pragma.
21
- import { FossilPlayground as RawFossilPlayground, FileHandle as RawFileHandle, tokenize as rawTokenize, semantic_legend as rawSemanticLegend, start_lsp_worker as rawStartLspWorker, } from '../pkg/fossil_wasm.js';
22
+ // The wasm-bindgen glue (`../pkg/fossil_wasm.js`) is imported ONLY from leaf
23
+ // modules — `load.ts` (init) and `client.ts` (the lexer / LSP / Workspace API) —
24
+ // never here in the entry. See `client.ts`: importing the stateful glue from the
25
+ // package entry lets a `sideEffects:false` bundler duplicate it, splitting
26
+ // `init()`'s wasm instance from the one the functions use (the crash the
27
+ // codemirror tokenizer hit on the main thread). This entry only re-exports.
22
28
  export { initFossilWasm } from './load.js';
23
- /**
24
- * Install the LSP-over-postMessage dispatcher on the current Worker scope.
25
- *
26
- * Per ADR-0024 (`fossil-wasm` IS the LSP server-side) + Phase 7 plan 07-03
27
- * (the 16-route dispatch loop). The Rust function (re-exported from
28
- * `crates/fossil-wasm/src/lsp_worker.rs`) installs `self.onmessage` on the
29
- * Worker scope and owns LSP JSON-RPC dispatch from that point forward —
30
- * including per-file `textDocument/publishDiagnostics` drains (B3 fix from
31
- * 07-03), `textDocument/semanticTokens/full` (06-07), hover, completion,
32
- * definition, references, rename, formatting, code actions, document
33
- * symbols, signature help.
34
- *
35
- * MUST be called inside a Web Worker scope, AFTER {@link initFossilWasm} has
36
- * resolved. Calling it on the main thread is a no-op (the dispatcher needs
37
- * `DedicatedWorkerGlobalScope.onmessage`).
38
- *
39
- * Consumed by `@fossil-lang/playground`'s `src/workers/lsp.worker.ts` —
40
- * the React component's LSP Worker entry boots the WASM module then calls
41
- * this function once.
42
- */
43
- export function start_lsp_worker() {
44
- rawStartLspWorker();
45
- }
46
- /**
47
- * Tokenize a Fossil source string. Returns the byte-range tokens from the
48
- * canonical Rust lexer (`fossil_syntax::lexer::raw_lex`) — single grammar
49
- * source of truth per ADR-0030.
50
- *
51
- * MUST be called after {@link initFossilWasm} has resolved; otherwise the
52
- * underlying wasm-bindgen function throws (the wasm module is not yet
53
- * instantiated).
54
- */
55
- export function tokenize(text) {
56
- // The wasm-bindgen wrapper returns a `JsValue` typed as `any`; the Rust side
57
- // (crates/fossil-wasm/src/tokenize.rs) serializes `Vec<TokenRow>` via
58
- // `serde_wasm_bindgen::to_value`, so the shape matches `{ kind, start, end }`
59
- // exactly. Cast is safe because the Rust ↔ JS contract is enforced upstream.
60
- return rawTokenize(text);
61
- }
62
- /**
63
- * Returns the LSP `SemanticTokensLegend` (token types + modifiers list) the
64
- * editor uses to map LSP `semanticTokens/full` response indices to highlight
65
- * categories. Re-export of `fossil_ide::semantic_legend` (Phase-6 06-07) over
66
- * the wasm-bindgen boundary — NO duplicate legend definition lives here.
67
- *
68
- * MUST be called after {@link initFossilWasm} has resolved.
69
- */
70
- export function semanticLegend() {
71
- return rawSemanticLegend();
72
- }
73
- /**
74
- * Workspace API class (ADR-0024). Thin TS wrapper around the wasm-bindgen
75
- * `FossilPlayground` that exposes camelCase method names for JS idiom + better
76
- * TS inference (the raw bindings use snake_case from the Rust impl block).
77
- *
78
- * One instance per browser tab / Node process — the instance owns the Salsa
79
- * store + `Arc<OutputDescriptorKind>` for the schema slot. Subsequent
80
- * `openFile` calls intern fresh `SourceFile` inputs under the same Salsa
81
- * revision so `updateFile` benefits from incremental memoisation.
82
- *
83
- * The Phase 7 LSP Worker (07-03) drives this class via postMessage; the React
84
- * component in `@fossil-lang/playground` (08-09) does the same via the
85
- * WorkerTransport adapter.
86
- *
87
- * NOTE: {@link FileHandle} is opaque — JS cannot construct one. Callers receive
88
- * a handle from `openFile` and pass it back to subsequent operations. The Rust
89
- * side keeps a `HashMap<FileHandle, SourceFile>` indexed by a `u32` newtype;
90
- * the wasm-bindgen wrapper exposes that as a class with `private constructor()`.
91
- */
92
- export class FossilPlayground {
93
- _inner;
94
- constructor() {
95
- this._inner = new RawFossilPlayground();
96
- }
97
- /**
98
- * Free the underlying WASM-side Salsa store. Call when the playground is no
99
- * longer needed (e.g. component unmount). Idempotent in spirit — subsequent
100
- * method calls on a freed playground throw.
101
- */
102
- free() {
103
- this._inner.free();
104
- }
105
- /**
106
- * Return the stdlib classification manifest (STDL-07). The playground reads
107
- * this once at startup to render `native_udf_only` functions as disabled
108
- * with a "native-only — unavailable in the browser" tooltip.
109
- */
110
- classification() {
111
- return this._inner.classification();
112
- }
113
- /**
114
- * Open a file in the workspace. Returns the {@link FileHandle} subsequent
115
- * `updateFile` / `closeFile` / `diagnosticsFor` calls key
116
- * on. `path` is the URI / virtual path diagnostics carry back to the LSP
117
- * client (e.g. `"file:///tmp/a.fossil"` or `"untitled:Untitled-1"`).
118
- *
119
- * Mirrors `ty_wasm::Workspace::open_file` (Astral). Interns a fresh
120
- * `fossil_base::SourceFile` under the current Salsa revision.
121
- */
122
- openFile(path, contents) {
123
- return this._inner.open_file(path, contents);
124
- }
125
- /**
126
- * Apply an edit to an open file. Mutates the SAME `SourceFile` via the
127
- * Salsa `Setter` (`set_text`) — this BUMPS THE REVISION (ADR-0022), the
128
- * real cancellation trigger. NO new `SourceFile` is interned, so memoised
129
- * downstream queries (`def_map`, `typecheck_mapping`) invalidate
130
- * incrementally instead of falling off a cliff.
131
- */
132
- updateFile(handle, contents) {
133
- this._inner.update_file(handle, contents);
134
- }
135
- /**
136
- * Close a file in the workspace. Strict in signal: closing an unknown /
137
- * already-closed handle throws so JS-side bugs surface loudly (mirrors
138
- * `ty_wasm`).
139
- */
140
- closeFile(handle) {
141
- this._inner.close_file(handle);
142
- }
143
- /**
144
- * Workspace-wide diagnostic drain. Runs `parse → def_map →
145
- * typecheck_mapping` across every open file and returns a flat array of
146
- * {@link CheckRow}. The LSP Worker (07-03) republishes these grouped by URI
147
- * as `textDocument/publishDiagnostics` notifications.
148
- */
149
- check() {
150
- return this._inner.check();
151
- }
152
- /**
153
- * Per-file diagnostic drain — the B3 follow-up accessor the LSP Worker uses
154
- * for its per-file `publishDiagnostics` notifications. `check()` returns
155
- * the workspace-wide flat array; `diagnosticsFor` returns just one file's
156
- * rows so 07-03 can dispatch one notification per affected URI without
157
- * partitioning the workspace array on the JS side.
158
- */
159
- diagnosticsFor(handle) {
160
- return this._inner.diagnostics_for(handle);
161
- }
162
- /**
163
- * Install a user-supplied ShEx schema as the active output descriptor. On
164
- * parse failure the previously-installed descriptor is RETAINED (no
165
- * half-applied state — same contract as `fossil-lsp::load_sibling_shex` in
166
- * 06-09). Future `fossil-ide` feature calls (hover, completion) reading
167
- * `HirDb::output_descriptor_kind` see the new schema atomically.
168
- */
169
- setTargetShex(text) {
170
- this._inner.set_target_shex(text);
171
- }
172
- /**
173
- * Register an {@link InferredDescriptorJson} for a source binding name
174
- * BEFORE invoking {@link check}. The Rust compiler reads from this
175
- * registration during forward type propagation (Phase 3 CORE-05 rewired in
176
- * plan 13-02).
177
- *
178
- * The browser-side orchestration runs DuckDB-WASM
179
- * `DESCRIBE read_csv_auto('<resolved-url>')` for each `io.csv("...")`
180
- * reference in the source, canonicalises the columns to the
181
- * {@link InferredPrimitive} catalog, and calls this method with the
182
- * resulting descriptor before {@link check}. See ADR-0037 for the full
183
- * architectural rationale.
184
- *
185
- * Keyed by source-binding name (e.g. `"users"` for
186
- * `users := io.csv("...")`), NOT by URL. Idempotent — re-registering with
187
- * the same `source_name` overwrites the previous entry.
188
- *
189
- * @throws Error if the descriptor JSON fails to deserialise on the Rust
190
- * side (e.g. missing required fields). The error message includes
191
- * the underlying serde_json diagnostic.
192
- *
193
- * @see ADR-0037 — drop user-facing CSVW; infer via DuckDB DESCRIBE
194
- */
195
- registerInferredDescriptor(descriptor) {
196
- // The wasm-bindgen wrapper exposes `registerInferredDescriptor(string)` —
197
- // it accepts a JSON string. Serialise here so callers pass a typed object.
198
- this._inner.registerInferredDescriptor(JSON.stringify(descriptor));
199
- }
200
- }
29
+ export { start_lsp_worker, tokenize, tokenKinds, semanticLegend, FossilPlayground, refs, providers, } from './client.js';
201
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,kGAAkG;AAClG,wGAAwG;AACxG,uFAAuF;AACvF,OAAO,EACL,gBAAgB,IAAI,mBAAmB,EACvC,UAAU,IAAI,aAAa,EAC3B,QAAQ,IAAI,WAAW,EACvB,eAAe,IAAI,iBAAiB,EACpC,gBAAgB,IAAI,iBAAiB,GACtC,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,gBAAgB;IAC9B,iBAAiB,EAAE,CAAC;AACtB,CAAC;AAYD;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAY;IACnC,6EAA6E;IAC7E,sEAAsE;IACtE,8EAA8E;IAC9E,6EAA6E;IAC7E,OAAO,WAAW,CAAC,I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AC,UAAkC;QAC3D,0EAA0E;QAC1E,2EAA2E;QAC3E,IAAI,CAAC,MAAM,CAAC,0BAA0B,CAAC,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC;IACrE,CAAC;CACF"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,6EAA6E;AAC7E,iFAAiF;AACjF,iFAAiF;AACjF,2EAA2E;AAC3E,yEAAyE;AACzE,4EAA4E;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3C,OAAO,EACL,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,cAAc,EACd,gBAAgB,EAChB,IAAI,EACJ,SAAS,GACV,MAAM,aAAa,CAAC"}
package/dist/load.d.ts CHANGED
@@ -17,7 +17,7 @@ export interface InitFossilWasmOpts {
17
17
  * {@link tokenize}, {@link semanticLegend}, or instantiating
18
18
  * {@link FossilPlayground}. Memoised — subsequent calls return the same promise.
19
19
  *
20
- * Per 08-RESEARCH.md Pattern 3 (wasm-bindgen --target web), consumers control
20
+ * With `wasm-bindgen --target web`, consumers control
21
21
  * the `.wasm` URL — this avoids tying library users to a specific bundler's
22
22
  * `.wasm` import magic. See `packages/wasm/README.md` for consumer patterns.
23
23
  */
package/dist/load.js CHANGED
@@ -9,7 +9,7 @@ let _initPromise = null;
9
9
  * {@link tokenize}, {@link semanticLegend}, or instantiating
10
10
  * {@link FossilPlayground}. Memoised — subsequent calls return the same promise.
11
11
  *
12
- * Per 08-RESEARCH.md Pattern 3 (wasm-bindgen --target web), consumers control
12
+ * With `wasm-bindgen --target web`, consumers control
13
13
  * the `.wasm` URL — this avoids tying library users to a specific bundler's
14
14
  * `.wasm` import magic. See `packages/wasm/README.md` for consumer patterns.
15
15
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fossil-lang/wasm",
3
- "version": "0.3.0-alpha.2",
3
+ "version": "0.3.0-alpha.5",
4
4
  "description": "JS/TS wrapper around the fossil-wasm wasm-bindgen artifacts (--target web). Exposes initFossilWasm + tokenize + semanticLegend + FossilPlayground class for downstream @fossil-lang/* packages.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  ],
34
34
  "sideEffects": false,
35
35
  "dependencies": {
36
- "@fossil-lang/types": "0.3.0-alpha.2"
36
+ "@fossil-lang/types": "0.3.0-alpha.5"
37
37
  },
38
38
  "devDependencies": {
39
39
  "typescript": "^5.6.0",