@hazae41/bobine 0.1.1 → 0.1.3

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.
@@ -24,6 +24,11 @@ export class RpcWorkerServer {
24
24
  }
25
25
  }
26
26
  async #route(request) {
27
+ if (request.method === "ping") {
28
+ const _ = request.params;
29
+ // NOOP
30
+ return "pong";
31
+ }
27
32
  if (request.method === "setup") {
28
33
  const _ = request.params;
29
34
  await this.runner.setup();
@@ -63,5 +68,6 @@ async function main() {
63
68
  const json = refs.toJSON();
64
69
  self.postMessage(json);
65
70
  }, { passive: true });
71
+ self.postMessage({ id: null, result: "pong" });
66
72
  }
67
73
  await main();
@@ -2,7 +2,7 @@ export declare class RpcWorkerClient {
2
2
  #private;
3
3
  readonly worker: Worker;
4
4
  constructor(worker: Worker);
5
- static spawn(uuid: string, path: string): RpcWorkerClient;
5
+ static spawn(uuid: string, path: string): Promise<RpcWorkerClient>;
6
6
  setup(): Promise<Uint8Array<ArrayBuffer>>;
7
7
  create(code: Uint8Array<ArrayBuffer>, salt: Uint8Array<ArrayBuffer>): Promise<string>;
8
8
  execute(module: string, method: string, params: Uint8Array<ArrayBuffer>, sparks: bigint): Promise<Uint8Array<ArrayBuffer>>;
@@ -50,18 +50,20 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
50
50
  var e = new Error(message);
51
51
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
52
52
  });
53
- import { RpcResponse } from "@hazae41/jsonrpc";
53
+ import { RpcRequest, RpcResponse } from "@hazae41/jsonrpc";
54
54
  export class RpcWorkerClient {
55
55
  worker;
56
56
  constructor(worker) {
57
57
  this.worker = worker;
58
58
  }
59
- static spawn(uuid, path) {
59
+ static async spawn(uuid, path) {
60
60
  const url = new URL(import.meta.resolve("./bin.js"));
61
61
  url.searchParams.set("uuid", uuid);
62
62
  url.searchParams.set("path", path);
63
63
  const worker = new Worker(url, { type: "module" });
64
- return new RpcWorkerClient(worker);
64
+ const client = new RpcWorkerClient(worker);
65
+ await client.#request({ id: null, method: "ping" });
66
+ return client;
65
67
  }
66
68
  async setup() {
67
69
  return await this.#request({ method: "setup" });
@@ -75,15 +77,20 @@ export class RpcWorkerClient {
75
77
  async simulate(module, method, params, sparks) {
76
78
  return await this.#request({ method: "simulate", params: [module, method, params, sparks] });
77
79
  }
78
- async #request(request) {
80
+ async #request(init) {
79
81
  const env_1 = { stack: [], error: void 0, hasError: false };
80
82
  try {
83
+ const { id = crypto.randomUUID(), method, params } = init;
81
84
  const stack = __addDisposableResource(env_1, new DisposableStack(), false);
82
85
  const future = Promise.withResolvers();
83
86
  const aborter = new AbortController();
84
87
  stack.defer(() => aborter.abort());
88
+ const request = new RpcRequest(id, method, params);
85
89
  this.worker.addEventListener("message", (event) => {
86
- RpcResponse.from(event.data).inspectSync(future.resolve).inspectErrSync(future.reject);
90
+ const response = RpcResponse.from(event.data);
91
+ if (response.id !== request.id)
92
+ return;
93
+ response.inspectSync(future.resolve).inspectErrSync(future.reject);
87
94
  }, { signal: aborter.signal });
88
95
  this.worker.addEventListener("error", (event) => {
89
96
  future.reject(event.error);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@hazae41/bobine",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "description": "WebAssembly-based metered chain of compute",
6
6
  "repository": "github:hazae41/bobine",
7
7
  "author": "hazae41",
@@ -23,13 +23,13 @@
23
23
  "@hazae41/binary": "^2.1.1",
24
24
  "@hazae41/cursor": "^2.2.0",
25
25
  "@hazae41/jsonrpc": "^1.2.1",
26
- "@hazae41/wasm": "^1.0.1",
26
+ "@hazae41/wasm": "^1.0.2",
27
27
  "@tursodatabase/database": "^0.8.4"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@hazae41/phobos": "^2.0.16",
31
31
  "@hazae41/tscousin": "^1.0.28",
32
- "@types/node": "^26.6.10",
32
+ "@types/node": "^26.6.11",
33
33
  "typescript": "^7.0.2"
34
34
  },
35
35
  "keywords": [