fix: remove bad URL constructor

This commit is contained in:
2024-03-04 13:09:09 +00:00
parent 6785ef72e1
commit 99b4d01ff7
5 changed files with 61 additions and 26 deletions

View File

@ -11,17 +11,16 @@ export class WorkerRelayInterface {
/**
* Interface wrapper for worker relay
* @param path Path to worker script or Worker script object
* @param scriptPath Path to worker script or Worker script object
* @param sqlite3Dir Directory to search for sqlite3 depends
*/
constructor(path?: string | Worker, sqlite3Dir?: string) {
if (path instanceof Worker) {
this.#worker = path;
constructor(scriptPath?: string | URL | Worker, sqlite3Dir?: string) {
this.#sqliteDir = sqlite3Dir;
if (scriptPath instanceof Worker) {
this.#worker = scriptPath;
} else {
const sqliteBase = new URL("@sqlite.org/sqlite-wasm?url", import.meta.url);
this.#sqliteDir = sqlite3Dir ?? sqliteBase.href;
const scriptPath = path ? new URL(path) : new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
this.#worker = new Worker(scriptPath, { type: "module" })
const sp = scriptPath ? scriptPath : new URL("@snort/worker-relay/dist/esm/worker.mjs", import.meta.url);
this.#worker = new Worker(sp, { type: "module" })
};
this.#worker.onerror = e => {
console.error(e.message, e);