@fossil-lang/wasm 0.3.0-alpha.2 → 0.3.0-alpha.21
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/README.md +98 -32
- package/dist/client.d.ts +206 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +250 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +144 -215
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -195
- package/dist/index.js.map +1 -1
- package/dist/load.d.ts +14 -20
- package/dist/load.d.ts.map +1 -1
- package/dist/load.js +23 -15
- package/dist/load.js.map +1 -1
- package/dist/program.d.ts +68 -0
- package/dist/program.d.ts.map +1 -0
- package/dist/program.js +117 -0
- package/dist/program.js.map +1 -0
- package/package.json +6 -5
- package/pkg/fossil_wasm.d.ts +231 -133
- package/pkg/fossil_wasm.js +348 -282
- package/pkg/fossil_wasm_bg.wasm +0 -0
- package/pkg/fossil_wasm_bg.wasm.d.ts +19 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,246 +1,175 @@
|
|
|
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
|
|
5
|
-
*
|
|
6
|
-
* - {@link
|
|
7
|
-
*
|
|
8
|
-
* - {@link
|
|
4
|
+
* Public API (one of the @fossil-lang/* packages; `git ls-files packages` is
|
|
5
|
+
* the list):
|
|
6
|
+
* - {@link initFossilWasm} — boots the module; its `.wasm` is a bundler asset. A failed boot is
|
|
7
|
+
* forgotten, so the next call tries again.
|
|
8
|
+
* - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
|
|
9
|
+
* - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
|
|
10
|
+
* - {@link openProgram} — one program open for an editor: the workspace, the push-before-ask
|
|
11
|
+
* discipline and the document resolution a host would otherwise write, shaped to spread into
|
|
12
|
+
* `@fossil-lang/codemirror-fossil`'s `fossil()`. What a host with one editor calls.
|
|
13
|
+
* - {@link FossilWorkspace} — Workspace API class: open / update / close,
|
|
14
|
+
* `check`, the three position queries (`hover`, `completions`,
|
|
15
|
+
* `gotoDefinition`) and `semanticTokens` an editor draws its IDE surface from, and the documents
|
|
16
|
+
* and sources a program reads (`missingDocuments`, `registerDocument`,
|
|
17
|
+
* `sources`) that a host resolves through its `Host`.
|
|
9
18
|
*
|
|
10
|
-
* Consumer pattern (wasm-bindgen --target web
|
|
19
|
+
* Consumer pattern (wasm-bindgen --target web):
|
|
11
20
|
*
|
|
12
|
-
* import {
|
|
13
|
-
* import
|
|
21
|
+
* import { openProgram } from '@fossil-lang/wasm';
|
|
22
|
+
* import { fossil } from '@fossil-lang/codemirror-fossil';
|
|
14
23
|
*
|
|
15
|
-
* await
|
|
16
|
-
* const
|
|
24
|
+
* const program = await openProgram('job.fossil', { host, text });
|
|
25
|
+
* const extensions = fossil({ ...program, onNavigate });
|
|
17
26
|
*/
|
|
18
|
-
import { FileHandle as RawFileHandle } from '../pkg/fossil_wasm.js';
|
|
19
|
-
import type { TokenRow, SemanticTokensLegend } from '@fossil-lang/types';
|
|
20
27
|
export { initFossilWasm } from './load.js';
|
|
21
|
-
export type {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* `
|
|
28
|
+
export type { InitInput } from './load.js';
|
|
29
|
+
export { tokenize, tokenKinds, FossilWorkspace, refs, providers, } from './client.js';
|
|
30
|
+
export type { FileHandle } from './client.js';
|
|
31
|
+
export { openProgram } from './program.js';
|
|
32
|
+
export type { FossilProgram, OpenProgramOptions } from './program.js';
|
|
33
|
+
/** One external reference a program makes — the typed lineage returned by
|
|
34
|
+
* {@link refs}. Mirrors `fossil_lineage::SourceRefInfo`. `connection` is the `@conn` alias the reference
|
|
35
|
+
* targets, or `null` for a direct URL/path; `role` is where it appears in the
|
|
36
|
+
* source constructor. The host resolves `@conn` → `{base}/path` itself. */
|
|
37
|
+
export interface SourceRefInfo {
|
|
38
|
+
connection: string | null;
|
|
39
|
+
path: string;
|
|
40
|
+
role: 'data' | 'schema';
|
|
41
|
+
}
|
|
42
|
+
/** One data-source provider returned by {@link providers}. Mirrors
|
|
43
|
+
* `fossil_lineage::ProviderInfo`: the short name (`csv`, `rdf`, …), the file
|
|
44
|
+
* extensions it reads (no leading dot), and how it can be used. */
|
|
45
|
+
export interface ProviderInfo {
|
|
46
|
+
name: string;
|
|
47
|
+
extensions: string[];
|
|
48
|
+
kind: 'schema' | 'data' | 'both';
|
|
49
|
+
}
|
|
50
|
+
/** The rows {@link FossilWorkspace.check} and {@link FossilWorkspace.diagnosticsFor} return —
|
|
51
|
+
* defined in `@fossil-lang/types`, beside the `Code` and `ProblemData` that type them. */
|
|
52
|
+
export type { CheckRow, CheckRelated } from '@fossil-lang/types';
|
|
53
|
+
/** An LSP range: zero-based lines, `character` in UTF-16 code units — the units
|
|
54
|
+
* a JavaScript string is indexed in, so no byte arithmetic converts it. (The
|
|
55
|
+
* lexer's {@link TokenRow} offsets are the other thing: those ARE bytes.) */
|
|
56
|
+
export interface LspRange {
|
|
57
|
+
start: {
|
|
58
|
+
line: number;
|
|
59
|
+
character: number;
|
|
60
|
+
};
|
|
61
|
+
end: {
|
|
62
|
+
line: number;
|
|
63
|
+
character: number;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/** What {@link FossilWorkspace.hover} found: the rendered Markdown — a
|
|
67
|
+
* ` ```fossil ` fence, the type of what you wrote and where it came from, and
|
|
68
|
+
* a second block with the type the target shape demands of that predicate when
|
|
69
|
+
* the shape resolves — and the range it applies to. */
|
|
70
|
+
export interface HoverRow {
|
|
71
|
+
markdown: string;
|
|
72
|
+
range: LspRange;
|
|
73
|
+
}
|
|
74
|
+
/** One candidate from {@link FossilWorkspace.completions}.
|
|
37
75
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
*
|
|
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.
|
|
76
|
+
* `kind` is the LSP `CompletionItemKind` **by name**, lowercased —
|
|
77
|
+
* `"function"`, `"field"`, `"enum_member"` — and `""` when the item carries
|
|
78
|
+
* none. Rust owns that table (`fossil_wasm::ide::kind_name`, total over the
|
|
79
|
+
* twenty-five the spec defines) because a table in TypeScript is one nothing
|
|
80
|
+
* can check: the deleted predecessor of `@fossil-lang/codemirror-fossil`
|
|
81
|
+
* hard-copied the lexer's discriminants and was wrong in nine places by the
|
|
82
|
+
* time it went.
|
|
56
83
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
84
|
+
* `detail` is the signature, the shape property's IRI, or the source field's
|
|
85
|
+
* inferred type — whatever the compiler wrote beside the label; `""` when it
|
|
86
|
+
* wrote none. Neither field is optional, on purpose: an absent optional is the
|
|
87
|
+
* one shape `serde_json` and `serde_wasm_bindgen` are measured to disagree
|
|
88
|
+
* about. */
|
|
89
|
+
export interface CompletionRow {
|
|
90
|
+
label: string;
|
|
91
|
+
kind: string;
|
|
92
|
+
detail: string;
|
|
93
|
+
/** What picking the row writes: the label's one spelling — the label itself,
|
|
94
|
+
* or `"Person.id"` for a column whose name is not an identifier. Never
|
|
95
|
+
* empty. */
|
|
96
|
+
insert: string;
|
|
97
|
+
}
|
|
98
|
+
/** One place {@link FossilWorkspace.gotoDefinition} found a definition.
|
|
67
99
|
*
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
*
|
|
73
|
-
|
|
74
|
-
* `fossil_ide::LineIndex` for UTF-16 ranges).
|
|
75
|
-
*/
|
|
76
|
-
export interface CheckRow {
|
|
100
|
+
* `uri` is the key the buffer was opened under, VERBATIM — matching
|
|
101
|
+
* {@link CheckRow.uri}, and not a `file://` URI. Two of the four positions
|
|
102
|
+
* goto-def recognises resolve into the shape document, so a target in another
|
|
103
|
+
* file is the ordinary case and a host with one editor pane has to read this
|
|
104
|
+
* before it moves a cursor. */
|
|
105
|
+
export interface DefinitionRow {
|
|
77
106
|
uri: string;
|
|
78
|
-
range:
|
|
79
|
-
start: {
|
|
80
|
-
line: number;
|
|
81
|
-
character: number;
|
|
82
|
-
};
|
|
83
|
-
end: {
|
|
84
|
-
line: number;
|
|
85
|
-
character: number;
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
severity: number;
|
|
89
|
-
message: string;
|
|
107
|
+
range: LspRange;
|
|
90
108
|
}
|
|
91
|
-
/**
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
/** One classified span from {@link FossilWorkspace.semanticTokens} — what the
|
|
110
|
+
* compiler knows about a stretch of the program that the lexer cannot: that
|
|
111
|
+
* `Person` is a shape, `users` a binding being declared, `@warehouse` a
|
|
112
|
+
* connection inside a string.
|
|
113
|
+
*
|
|
114
|
+
* `kind` is the semantic-token type by legend NAME (`"type"`, `"namespace"`,
|
|
115
|
+
* `"function"`, `"property"`, `"parameter"`, `"variable"`, `"keyword"`,
|
|
116
|
+
* `"string"`, `"number"`, `"operator"`, `"comment"`); `modifiers` likewise
|
|
117
|
+
* (`"declaration"`), empty when there are none. Names and not indices, for the
|
|
118
|
+
* reason {@link CompletionRow.kind} is one. Rows are in source order and never
|
|
119
|
+
* overlap; a range may cross a line. */
|
|
120
|
+
export interface SemanticTokenRow {
|
|
121
|
+
range: LspRange;
|
|
122
|
+
kind: string;
|
|
123
|
+
modifiers: string[];
|
|
100
124
|
}
|
|
101
125
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
104
|
-
* map 1:1 to the `Primitive` enum in HIR (Integer, Float, String, Bool, Date,
|
|
105
|
-
* DateTime, Time, GYear, AnyURI).
|
|
126
|
+
* The primitive lattice, as `fossil-graph-schema` serialises it — the same enum
|
|
127
|
+
* the checker types against, not a set of names it looks up.
|
|
106
128
|
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
*
|
|
129
|
+
* A value outside this union is REJECTED when the descriptor is registered:
|
|
130
|
+
* `registerInferredDescriptor` returns the serde error naming the offending
|
|
131
|
+
* value. It is no longer coerced to `string` with a diagnostic three crates
|
|
132
|
+
* later, so a host that sends a type fossil does not carry finds out at the
|
|
133
|
+
* call, not in a compile.
|
|
111
134
|
*/
|
|
112
|
-
export type InferredPrimitive = '
|
|
135
|
+
export type InferredPrimitive = 'string' | 'integer' | 'float' | 'bool' | 'date' | 'date_time' | 'time' | 'g_year' | 'any_uri';
|
|
113
136
|
/** One column from a host-introspected source. */
|
|
114
137
|
export interface InferredColumnJson {
|
|
115
138
|
name: string;
|
|
116
139
|
primitive: InferredPrimitive;
|
|
117
140
|
}
|
|
118
141
|
/**
|
|
119
|
-
* Host-introspected input schema. Produced by
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
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.
|
|
148
|
-
*
|
|
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.
|
|
142
|
+
* Host-introspected input schema. Produced by a `DESCRIBE SELECT * FROM
|
|
143
|
+
* <reader>('<url>')` the host runs — `DuckDB-WASM` in a browser — where the
|
|
144
|
+
* reader is the one the binding's `io.` constructor names: `read_csv_auto`,
|
|
145
|
+
* `read_json_auto` or `read_parquet`. `@fossil-lang/introspect` is the one home
|
|
146
|
+
* for that, and picking the reader off the constructor is not a nicety: a
|
|
147
|
+
* Parquet file read as CSV fails DuckDB's sniffer outright, and a JSON array
|
|
148
|
+
* read as CSV introspects to a single column named `[`.
|
|
152
149
|
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
150
|
+
* Consumed by the Rust compiler via
|
|
151
|
+
* {@link FossilWorkspace.registerInferredDescriptor}. There is no metadata
|
|
152
|
+
* sidecar for the user to write and keep in sync: the host introspects the
|
|
153
|
+
* real file and feeds the compiler ahead of `compile()`.
|
|
157
154
|
*/
|
|
158
|
-
export
|
|
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[];
|
|
155
|
+
export interface InferredDescriptorJson {
|
|
212
156
|
/**
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* `HirDb::output_descriptor_kind` see the new schema atomically.
|
|
157
|
+
* The source URI exactly as the program writes it — the string inside
|
|
158
|
+
* `io.csv("examples/users.csv")`. NOT the binding name, and NOT the URL the
|
|
159
|
+
* host resolved in order to read the file: the checker only ever sees what
|
|
160
|
+
* the program says.
|
|
218
161
|
*/
|
|
219
|
-
|
|
162
|
+
uri: string;
|
|
163
|
+
/** Ordered columns — order is significant for column-position fallback. */
|
|
164
|
+
columns: InferredColumnJson[];
|
|
220
165
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
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
|
|
166
|
+
* Opaque token identifying the state of the source this was read from. The
|
|
167
|
+
* cache compares it and nothing interprets it: an ETag, a digest, a
|
|
168
|
+
* `Last-Modified`, whatever the host can get cheaply. Empty means "I cannot
|
|
169
|
+
* tell", which the cache reads as never-fresh, so that source is
|
|
170
|
+
* re-introspected on every compile.
|
|
242
171
|
*/
|
|
243
|
-
|
|
172
|
+
freshness_token: string;
|
|
244
173
|
}
|
|
245
|
-
export type { TokenRow,
|
|
174
|
+
export type { TokenRow, Host, MissingDocument, UnreadDocument, DocumentWorkspace, ProgramSource, } from '@fossil-lang/types';
|
|
246
175
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAUH,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C,OAAO,EACL,QAAQ,EACR,UAAU,EACV,eAAe,EACf,IAAI,EACJ,SAAS,GACV,MAAM,aAAa,CAAC;AACrB,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEtE;;;4EAG4E;AAC5E,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC;CACzB;AAED;;oEAEoE;AACpE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,IAAI,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;CAClC;AAED;2FAC2F;AAC3F,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEjE;;8EAE8E;AAC9E,MAAM,WAAW,QAAQ;IACvB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3C,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC;CAC1C;AAED;;;wDAGwD;AACxD,MAAM,WAAW,QAAQ;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED;;;;;;;;;;;;;;aAca;AACb,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf;;iBAEa;IACb,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;gCAMgC;AAChC,MAAM,WAAW,aAAa;IAC5B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,QAAQ,CAAC;CACjB;AAED;;;;;;;;;;yCAUyC;AACzC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,QAAQ,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;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,EACV,QAAQ,EACR,IAAI,EACJ,eAAe,EACf,cAAc,EACd,iBAAiB,EACjB,aAAa,GACd,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
|
|
5
|
-
*
|
|
6
|
-
* - {@link
|
|
7
|
-
*
|
|
8
|
-
* - {@link
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
4
|
+
* Public API (one of the @fossil-lang/* packages; `git ls-files packages` is
|
|
5
|
+
* the list):
|
|
6
|
+
* - {@link initFossilWasm} — boots the module; its `.wasm` is a bundler asset. A failed boot is
|
|
7
|
+
* forgotten, so the next call tries again.
|
|
8
|
+
* - {@link tokenize} — calls the Rust lexer, returns TokenRow[].
|
|
9
|
+
* - {@link tokenKinds} — the legend for TokenRow.kind: variant names by index.
|
|
10
|
+
* - {@link openProgram} — one program open for an editor: the workspace, the push-before-ask
|
|
11
|
+
* discipline and the document resolution a host would otherwise write, shaped to spread into
|
|
12
|
+
* `@fossil-lang/codemirror-fossil`'s `fossil()`. What a host with one editor calls.
|
|
13
|
+
* - {@link FossilWorkspace} — Workspace API class: open / update / close,
|
|
14
|
+
* `check`, the three position queries (`hover`, `completions`,
|
|
15
|
+
* `gotoDefinition`) and `semanticTokens` an editor draws its IDE surface from, and the documents
|
|
16
|
+
* and sources a program reads (`missingDocuments`, `registerDocument`,
|
|
17
|
+
* `sources`) that a host resolves through its `Host`.
|
|
18
|
+
*
|
|
19
|
+
* Consumer pattern (wasm-bindgen --target web):
|
|
20
|
+
*
|
|
21
|
+
* import { openProgram } from '@fossil-lang/wasm';
|
|
22
|
+
* import { fossil } from '@fossil-lang/codemirror-fossil';
|
|
23
|
+
*
|
|
24
|
+
* const program = await openProgram('job.fossil', { host, text });
|
|
25
|
+
* const extensions = fossil({ ...program, onNavigate });
|
|
17
26
|
*/
|
|
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
27
|
export { initFossilWasm } from './load.js';
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
}
|
|
28
|
+
export { tokenize, tokenKinds, FossilWorkspace, refs, providers, } from './client.js';
|
|
29
|
+
export { openProgram } from './program.js';
|
|
201
30
|
//# sourceMappingURL=index.js.map
|