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

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/client.d.ts ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Creates a Web Worker running the swls language server (browser/web hosts).
3
+ *
4
+ * The returned worker speaks whole JSON-RPC messages over `postMessage` (no
5
+ * `Content-Length` framing) and emits a `{ method: "swls/ready" }` notification
6
+ * once the wasm has finished initializing.
7
+ *
8
+ * @param options Extra worker options; `type` is always `"module"`.
9
+ */
10
+ export function createSwlsWorker(options?: Omit<WorkerOptions, "type">): Worker;
package/client.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Creates a Web Worker running the swls language server (browser/web hosts).
3
+ *
4
+ * The returned worker speaks whole JSON-RPC messages over `postMessage` (no
5
+ * `Content-Length` framing) and emits a `{ method: "swls/ready" }` notification
6
+ * once the wasm has finished initializing.
7
+ *
8
+ * Kept in its own entry (`swls-wasm/client`) rather than the package root so
9
+ * that Node/bundler consumers importing `swls-wasm` never pull in a nested
10
+ * `Worker`/wasm chunk they don't use.
11
+ *
12
+ * @param {WorkerOptions} [options] Extra worker options; `type` is always
13
+ * `"module"`. (Kept after the spread so bundlers can statically read `type`.)
14
+ * @returns {Worker}
15
+ */
16
+ export function createSwlsWorker(options) {
17
+ return new Worker(new URL("./worker.js", import.meta.url), {
18
+ ...options,
19
+ type: "module",
20
+ });
21
+ }
package/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { default, initSync, WasmLsp, start_wasm_lsp } from "./swls_wasm.js";
2
+ export { createSwlsServer } from "./pump.js";
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { default, initSync, WasmLsp, start_wasm_lsp } from "./swls_wasm.js";
2
+ export { createSwlsServer } from "./pump.js";
package/package.json CHANGED
@@ -4,17 +4,40 @@
4
4
  "collaborators": [
5
5
  "ajuvercr <arthur.vercruysse@outlook.com>"
6
6
  ],
7
- "version": "0.3.2-alpha.1",
7
+ "version": "0.3.2-alpha.2",
8
8
  "files": [
9
9
  "swls_wasm_bg.wasm",
10
10
  "swls_wasm.js",
11
- "swls_wasm_bg.js",
12
- "swls_wasm.d.ts"
11
+ "swls_wasm.d.ts",
12
+ "index.js",
13
+ "index.d.ts",
14
+ "pump.js",
15
+ "pump.d.ts",
16
+ "worker.js",
17
+ "client.js",
18
+ "client.d.ts"
13
19
  ],
14
- "main": "swls_wasm.js",
15
- "types": "swls_wasm.d.ts",
20
+ "main": "index.js",
21
+ "types": "index.d.ts",
16
22
  "sideEffects": [
17
- "./swls_wasm.js",
18
- "./snippets/*"
19
- ]
23
+ "./worker.js"
24
+ ],
25
+ "module": "index.js",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./index.d.ts",
29
+ "default": "./index.js"
30
+ },
31
+ "./client": {
32
+ "types": "./client.d.ts",
33
+ "default": "./client.js"
34
+ },
35
+ "./worker": "./worker.js",
36
+ "./swls_wasm.js": {
37
+ "types": "./swls_wasm.d.ts",
38
+ "default": "./swls_wasm.js"
39
+ },
40
+ "./swls_wasm_bg.wasm": "./swls_wasm_bg.wasm",
41
+ "./package.json": "./package.json"
42
+ }
20
43
  }
package/pump.d.ts ADDED
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Boots the swls wasm LSP and wires it to a host transport.
3
+ *
4
+ * Host-agnostic: the caller decides how outgoing messages are delivered
5
+ * (`post`) and feeds incoming messages into the returned function. Both
6
+ * directions exchange whole JSON-RPC messages with no `Content-Length`
7
+ * framing — `post` receives already-parsed objects, and the returned feed
8
+ * accepts either a parsed object or a raw JSON string.
9
+ *
10
+ * @param post Called with each outgoing JSON-RPC message (already parsed).
11
+ * @param options.debug The server's debug-log sink.
12
+ * @param options.wasm Overrides the module/URL forwarded to the wasm `init()`
13
+ * (defaults to the sibling `swls_wasm_bg.wasm`); pass it when the host cannot
14
+ * fetch that sibling itself (e.g. Node, which can't `fetch` a `file://` URL).
15
+ * @returns Resolves once wasm is initialized to a function that feeds one
16
+ * incoming message (object or string) to the server.
17
+ */
18
+ export function createSwlsServer(
19
+ post: (message: unknown) => void,
20
+ options?: {
21
+ debug?: (message: string) => void;
22
+ wasm?: string | URL | Request | BufferSource | WebAssembly.Module;
23
+ },
24
+ ): Promise<(data: unknown) => void>;
package/pump.js ADDED
@@ -0,0 +1,36 @@
1
+ import init, { WasmLsp } from "./swls_wasm.js";
2
+
3
+ /**
4
+ * Boots the swls wasm LSP and wires it to a host transport.
5
+ *
6
+ * Host-agnostic: the caller decides how outgoing messages are delivered
7
+ * (`post`) and feeds incoming messages into the returned function. Both
8
+ * directions exchange whole JSON-RPC messages with no `Content-Length`
9
+ * framing — `post` receives already-parsed objects, and the returned feed
10
+ * accepts either a parsed object or a raw JSON string.
11
+ *
12
+ * Used directly by non-DOM hosts (e.g. a VS Code `worker_threads` server or
13
+ * the web-extension host); browser consumers get this wrapped in a Worker via
14
+ * {@link createSwlsWorker} (see `swls-wasm/client`).
15
+ *
16
+ * @param {(message: unknown) => void} post
17
+ * Called with each outgoing JSON-RPC message (already parsed).
18
+ * @param {{
19
+ * debug?: (message: string) => void,
20
+ * wasm?: string | URL | Request | BufferSource | WebAssembly.Module,
21
+ * }} [options]
22
+ * `debug` is the server's debug-log sink. `wasm` overrides the module/URL
23
+ * forwarded to the wasm `init()` (defaults to the sibling
24
+ * `swls_wasm_bg.wasm`); pass it when the host cannot fetch that sibling
25
+ * itself (e.g. Node, which can't `fetch` a `file://` URL).
26
+ * @returns {Promise<(data: unknown) => void>}
27
+ * Resolves once wasm is initialized to a function that feeds one incoming
28
+ * message (object or string) to the server.
29
+ */
30
+ export async function createSwlsServer(post, options = {}) {
31
+ const { debug, wasm } = options;
32
+ await init(wasm === undefined ? undefined : { module_or_path: wasm });
33
+ const lsp = new WasmLsp((message) => post(JSON.parse(message)), debug);
34
+ return (data) =>
35
+ lsp.send(typeof data === "string" ? data : JSON.stringify(data));
36
+ }
package/swls_wasm.d.ts CHANGED
@@ -24,3 +24,46 @@ export class WasmLsp {
24
24
  }
25
25
 
26
26
  export function start_wasm_lsp(): Promise<void>;
27
+
28
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
29
+
30
+ export interface InitOutput {
31
+ readonly memory: WebAssembly.Memory;
32
+ readonly __wbg_wasmlsp_free: (a: number, b: number) => void;
33
+ readonly start_wasm_lsp: () => void;
34
+ readonly wasmlsp_new: (a: any, b: number) => number;
35
+ readonly wasmlsp_send: (a: number, b: number, c: number) => void;
36
+ readonly wasm_bindgen__convert__closures_____invoke__h5d8169a9c6a0716a: (a: number, b: number, c: any) => [number, number];
37
+ readonly wasm_bindgen__convert__closures_____invoke__h0a08a9b6706aa208: (a: number, b: number, c: any, d: any) => void;
38
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
39
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
40
+ readonly __wbindgen_exn_store: (a: number) => void;
41
+ readonly __externref_table_alloc: () => number;
42
+ readonly __wbindgen_externrefs: WebAssembly.Table;
43
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
44
+ readonly __wbindgen_destroy_closure: (a: number, b: number) => void;
45
+ readonly __externref_table_dealloc: (a: number) => void;
46
+ readonly __wbindgen_start: () => void;
47
+ }
48
+
49
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
50
+
51
+ /**
52
+ * Instantiates the given `module`, which can either be bytes or
53
+ * a precompiled `WebAssembly.Module`.
54
+ *
55
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
56
+ *
57
+ * @returns {InitOutput}
58
+ */
59
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
60
+
61
+ /**
62
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
63
+ * for everything else, calls `WebAssembly.instantiate` directly.
64
+ *
65
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
66
+ *
67
+ * @returns {Promise<InitOutput>}
68
+ */
69
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;