swls-wasm 0.3.2-alpha.2 → 0.3.2-alpha.4

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 CHANGED
@@ -1,86 +1,67 @@
1
- # SWLS-Web
1
+ # swls-wasm
2
2
 
3
- WASM bindings for the semantic web language server.
3
+ The [Semantic Web Language Server](https://github.com/SemanticWebLanguageServer/swls)
4
+ (Turtle, TriG, SPARQL, JSON-LD) compiled to WebAssembly, plus thin helpers for
5
+ running it as a worker. Built with `wasm-pack --target web`, so it loads in
6
+ browsers, bundlers, Web Workers and Node without any bundler plugins.
4
7
 
5
- As SWLS is not yet published, this package expects SWLS to be present in the parent directory.
8
+ Both directions exchange whole JSON-RPC messages over `postMessage` with **no
9
+ `Content-Length` framing**.
6
10
 
7
- ## 🚴 Usage
11
+ ## Browser / bundler — `createSwlsWorker()`
8
12
 
9
- ### 🛠️ Build with `wasm-pack build`
13
+ The easiest path: get a ready-to-use Web Worker. Works with Vite, webpack, etc.
14
+ (the bundler picks up the worker and its `.wasm` automatically).
10
15
 
11
- ```
12
- wasm-pack build
13
- ```
14
-
15
- ### 🔬 Test in Headless Browsers with `wasm-pack test`
16
+ ```js
17
+ import { createSwlsWorker } from "swls-wasm/client";
16
18
 
19
+ const worker = createSwlsWorker();
20
+ // hand `worker` to your editor's LSP client (e.g. swls-codemirror, monaco)
17
21
  ```
18
- wasm-pack test --headless --firefox
19
- ```
20
-
21
- ### 🎁 Publish to NPM with `wasm-pack publish`
22
-
23
- ```
24
- wasm-pack publish
25
- ```
26
-
27
-
28
- ## Custom LSP Requests
29
-
30
- The WASM LSP server sends custom requests **from server to client** that the host must handle. All requests use `params: { url: string }`.
31
22
 
32
- If a handler is not implemented, the server falls back to a sensible default.
23
+ The worker emits `{ jsonrpc: "2.0", method: "swls/ready" }` once the wasm has
24
+ finished initializing.
33
25
 
34
- ### `custom/readFile`
26
+ ## From a CDN — no build step
35
27
 
36
- Reads the contents of a file.
28
+ `worker.js` and its sibling `swls_wasm_bg.wasm` are both published, so a worker
29
+ can be loaded straight from a CDN:
37
30
 
38
- ```ts
39
- params: { url: string }
40
- result: { content: string } | { error: string }
31
+ ```js
32
+ const worker = new Worker(
33
+ "https://cdn.jsdelivr.net/npm/swls-wasm@0.3/worker.js",
34
+ { type: "module" },
35
+ );
41
36
  ```
42
37
 
43
- ### `custom/readDir`
38
+ The worker resolves `swls_wasm_bg.wasm` relative to its own URL, so it is fetched
39
+ from the same CDN path. Cross-origin module workers need permissive CORS (jsDelivr
40
+ and unpkg send it); Safari is stricter about cross-origin worker scripts, so if you
41
+ need to support it, load a small same-origin bootstrap that `import()`s the CDN URL.
44
42
 
45
- Lists the entries of a directory.
43
+ ## Custom host `createSwlsServer()`
46
44
 
47
- ```ts
48
- params: { url: string }
49
- result: Array<{ name: string; path: string; is_dir: boolean }>
50
- // fallback: returns null/error → treated as empty
51
- ```
52
-
53
- ### `custom/isFile`
54
-
55
- Returns whether the given URL refers to a file.
56
-
57
- ```ts
58
- params: { url: string }
59
- result: boolean
60
- // fallback: true when URL does not end with '/'
61
- ```
45
+ For hosts that aren't a DOM `Worker` (a Node `worker_threads` worker, the VS Code
46
+ web-extension host, …): wire the server to your own transport. `post` receives
47
+ each outgoing message (already parsed); feed incoming messages (object or string)
48
+ into the returned function.
62
49
 
63
- ### `custom/isDir`
50
+ ```js
51
+ import { createSwlsServer } from "swls-wasm";
64
52
 
65
- Returns whether the given URL refers to a directory.
53
+ const feed = await createSwlsServer((message) => sendToClient(message), {
54
+ debug: (line) => console.log(line),
55
+ // Optional: override how the wasm is loaded. Defaults to fetching the sibling
56
+ // `swls_wasm_bg.wasm`; pass bytes/URL when the host can't fetch that itself
57
+ // (e.g. Node, which can't `fetch` a `file://` URL).
58
+ wasm: undefined,
59
+ });
66
60
 
67
- ```ts
68
- params: { url: string }
69
- result: boolean
70
- // fallback: true when URL ends with '/'
61
+ feed({ jsonrpc: "2.0", id: 1, method: "initialize", params: { /* … */ } });
71
62
  ```
72
63
 
73
- ### `custom/canonicalize`
74
-
75
- Resolves a URL to its canonical form.
76
-
77
- ```ts
78
- params: { url: string }
79
- result: { url: string }
80
- // fallback: returns the input URL unchanged
81
- ```
82
-
83
- ## License
84
-
85
- * MIT license ([LICENSE](LICENSE) or http://opensource.org/licenses/MIT)
64
+ ## Low-level — `WasmLsp`
86
65
 
66
+ `WasmLsp` (and the wasm `init` default export) are also re-exported for full
67
+ control. `createSwlsServer` is just a thin wrapper around them.
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "collaborators": [
5
5
  "ajuvercr <arthur.vercruysse@outlook.com>"
6
6
  ],
7
- "version": "0.3.2-alpha.2",
7
+ "version": "0.3.2-alpha.4",
8
8
  "files": [
9
9
  "swls_wasm_bg.wasm",
10
10
  "swls_wasm.js",
package/swls_wasm.js CHANGED
@@ -329,7 +329,7 @@ function __wbg_get_imports() {
329
329
  return ret;
330
330
  },
331
331
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
332
- // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 4783, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
332
+ // Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 4958, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
333
333
  const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h5d8169a9c6a0716a);
334
334
  return ret;
335
335
  },
package/swls_wasm_bg.wasm CHANGED
Binary file