From 139f1daffbecde01b1dcfd502e5119db7eb0ffa1 Mon Sep 17 00:00:00 2001 From: Sam Willis Date: Tue, 30 Jul 2024 07:36:27 +0100 Subject: [PATCH] WIP --- packages/pglite/examples/worker-process.js | 2 +- packages/pglite/src/worker/index.ts | 7 ++++++- packages/pglite/tests/targets/base.js | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/pglite/examples/worker-process.js b/packages/pglite/examples/worker-process.js index 88414b986..438ea6451 100644 --- a/packages/pglite/examples/worker-process.js +++ b/packages/pglite/examples/worker-process.js @@ -5,7 +5,7 @@ import { vector } from "../dist/vector/index.js"; worker({ async init() { const pg = new PGlite({ - dataDir: "idb://worker-example", + debug:1, extensions: { vector, }, diff --git a/packages/pglite/src/worker/index.ts b/packages/pglite/src/worker/index.ts index eecf8b422..74191ad09 100644 --- a/packages/pglite/src/worker/index.ts +++ b/packages/pglite/src/worker/index.ts @@ -160,6 +160,7 @@ export class PGliteWorker implements PGliteInterface { }); this.#broadcastChannel.addEventListener("message", async (event) => { + // console.log("broadcast message", event.data); if (event.data.type === "leader-here") { this.#connected = false; this.#eventTarget.dispatchEvent(new Event("leader-change")); @@ -170,6 +171,7 @@ export class PGliteWorker implements PGliteInterface { }); this.#tabChannel.addEventListener("message", async (event) => { + // console.log("tab message", event.data); if (event.data.type === "connected") { this.#connected = true; this.#eventTarget.dispatchEvent(new Event("connected")); @@ -179,6 +181,7 @@ export class PGliteWorker implements PGliteInterface { }); this.#workerProcess.addEventListener("message", async (event) => { + // console.log("worker message", event.data); if (event.data.type === "leader-now") { this.#isLeader = true; this.#eventTarget.dispatchEvent(new Event("leader-change")); @@ -597,6 +600,7 @@ function connectTab( const api = makeWorkerApi(pg); tabChannel.addEventListener("message", async (event) => { + // console.log("worker: tab message", event.data); const msg = event.data; switch (msg.type) { case "rpc-call": @@ -612,10 +616,11 @@ function connectTab( result, } satisfies WorkerRpcResult); } catch (error) { + console.error(error); tabChannel.postMessage({ type: "rpc-error", callId, - error, + error: { message: (error as Error).message }, } satisfies WorkerRpcError); } break; diff --git a/packages/pglite/tests/targets/base.js b/packages/pglite/tests/targets/base.js index 05c503d81..8d166baca 100644 --- a/packages/pglite/tests/targets/base.js +++ b/packages/pglite/tests/targets/base.js @@ -152,7 +152,7 @@ export function tests(env, dbFilename, target) { }); }); - if (env === "node") { + if (env === "node" || env === "webkit") { // Skip the rest of the tests for node as they are browser specific return; }