hyperdb-wasm 0.0.26308-dev.wasm.gae25030d → 0.0.26312-dev.wasm.g57edd738
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/dist/browser.d.ts +4 -2
- package/dist/browser.js +23 -11
- package/dist/browser_worker.js +31 -4
- package/dist/client.d.ts +3 -2
- package/dist/hyperdb-wasm.cjs +1 -1
- package/dist/hyperdb-wasm.js +1 -1
- package/dist/hyperdb-wasm.wasm.br +0 -0
- package/dist/index.d.ts +1 -0
- package/dist/node.js +23 -11
- package/dist/node_worker.js +1 -0
- package/dist/protocol.d.ts +7 -1
- package/dist/raw.browser.d.ts +1 -1
- package/dist/raw.browser.js +23 -11
- package/dist/raw.d.ts +1 -1
- package/dist/raw.node.js +17 -9
- package/dist/worker_setup.d.ts +1 -0
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HyperDBEngineClient } from './client.js';
|
|
2
|
-
import type { EngineRequest, WorkerTransport } from './protocol.js';
|
|
2
|
+
import type { EngineRequest, InstantiationProgress, WorkerTransport } from './protocol.js';
|
|
3
3
|
type BrowserListener = (event: unknown) => void;
|
|
4
4
|
export interface BrowserWorkerLike {
|
|
5
5
|
postMessage(message: unknown, transfer: ArrayBuffer[]): void;
|
|
@@ -10,6 +10,8 @@ export interface BrowserWorkerLike {
|
|
|
10
10
|
export interface BrowserClientOptions {
|
|
11
11
|
readonly workerUrl?: string | URL;
|
|
12
12
|
readonly engineUrl?: string | URL;
|
|
13
|
+
readonly wasmUrl?: string | URL;
|
|
14
|
+
readonly onInitialisationProgress?: (progress: InstantiationProgress) => void;
|
|
13
15
|
}
|
|
14
16
|
export declare class BrowserWorker implements WorkerTransport {
|
|
15
17
|
private readonly worker;
|
|
@@ -20,6 +22,6 @@ export declare class BrowserWorker implements WorkerTransport {
|
|
|
20
22
|
onClose(): () => void;
|
|
21
23
|
terminate(): void;
|
|
22
24
|
}
|
|
23
|
-
export declare function resolveBrowserWorkerUrl(workerUrl: string | URL, engineUrl: string | URL): URL;
|
|
25
|
+
export declare function resolveBrowserWorkerUrl(workerUrl: string | URL, engineUrl: string | URL, wasmUrl?: string | URL): URL;
|
|
24
26
|
export declare function createBrowserClient(options?: BrowserClientOptions): HyperDBEngineClient;
|
|
25
27
|
export {};
|
package/dist/browser.js
CHANGED
|
@@ -43,6 +43,8 @@ function isWorkerEvent(message) {
|
|
|
43
43
|
switch (message.type) {
|
|
44
44
|
case "ready":
|
|
45
45
|
return hasKeys(message, ["type"]);
|
|
46
|
+
case "progress":
|
|
47
|
+
return hasKeys(message, ["type", "bytesLoaded", "bytesTotal"]) && typeof message.bytesLoaded === "number" && Number.isSafeInteger(message.bytesLoaded) && message.bytesLoaded >= 0 && typeof message.bytesTotal === "number" && Number.isSafeInteger(message.bytesTotal) && message.bytesTotal >= 0;
|
|
46
48
|
case "fatal":
|
|
47
49
|
return hasKeys(message, ["type", "error"]) && typeof message.error === "string";
|
|
48
50
|
case "log":
|
|
@@ -66,15 +68,8 @@ var init_client = __esm({
|
|
|
66
68
|
"use strict";
|
|
67
69
|
init_protocol();
|
|
68
70
|
HyperDBEngineClient = class {
|
|
69
|
-
transport
|
|
70
|
-
|
|
71
|
-
readyPromise;
|
|
72
|
-
resolveReady;
|
|
73
|
-
rejectReady;
|
|
74
|
-
nextId = 1;
|
|
75
|
-
failed;
|
|
76
|
-
unsubscribe;
|
|
77
|
-
constructor(transport) {
|
|
71
|
+
constructor(transport, onInitialisationProgress) {
|
|
72
|
+
this.onInitialisationProgress = onInitialisationProgress;
|
|
78
73
|
this.transport = transport;
|
|
79
74
|
this.readyPromise = new Promise((resolve, reject) => {
|
|
80
75
|
this.resolveReady = resolve;
|
|
@@ -86,6 +81,15 @@ var init_client = __esm({
|
|
|
86
81
|
transport.onClose((error) => this.fail(error))
|
|
87
82
|
];
|
|
88
83
|
}
|
|
84
|
+
onInitialisationProgress;
|
|
85
|
+
transport;
|
|
86
|
+
pending = /* @__PURE__ */ new Map();
|
|
87
|
+
readyPromise;
|
|
88
|
+
resolveReady;
|
|
89
|
+
rejectReady;
|
|
90
|
+
nextId = 1;
|
|
91
|
+
failed;
|
|
92
|
+
unsubscribe;
|
|
89
93
|
ready() {
|
|
90
94
|
return this.readyPromise;
|
|
91
95
|
}
|
|
@@ -166,6 +170,10 @@ var init_client = __esm({
|
|
|
166
170
|
this.resolveReady();
|
|
167
171
|
return;
|
|
168
172
|
}
|
|
173
|
+
if (message.type === "progress") {
|
|
174
|
+
this.onInitialisationProgress?.({ bytesLoaded: message.bytesLoaded, bytesTotal: message.bytesTotal });
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
169
177
|
if (message.type === "fatal") {
|
|
170
178
|
this.fail(new Error(message.error || "engine aborted"));
|
|
171
179
|
return;
|
|
@@ -195,15 +203,19 @@ __export(browser_exports, {
|
|
|
195
203
|
createBrowserClient: () => createBrowserClient,
|
|
196
204
|
resolveBrowserWorkerUrl: () => resolveBrowserWorkerUrl
|
|
197
205
|
});
|
|
198
|
-
function resolveBrowserWorkerUrl(workerUrl, engineUrl) {
|
|
206
|
+
function resolveBrowserWorkerUrl(workerUrl, engineUrl, wasmUrl) {
|
|
199
207
|
const resolved = new URL(workerUrl);
|
|
200
208
|
resolved.searchParams.set("engineUrl", new URL(engineUrl).href);
|
|
209
|
+
if (wasmUrl != null) resolved.searchParams.set("wasmUrl", new URL(wasmUrl).href);
|
|
201
210
|
return resolved;
|
|
202
211
|
}
|
|
203
212
|
function createBrowserClient(options = {}) {
|
|
204
213
|
const workerUrl = options.workerUrl ?? new URL("./browser_worker.js", import.meta.url);
|
|
205
214
|
const engineUrl = options.engineUrl ?? new URL("./hyperdb-wasm.js", import.meta.url);
|
|
206
|
-
return new HyperDBEngineClient(
|
|
215
|
+
return new HyperDBEngineClient(
|
|
216
|
+
new BrowserWorker(new Worker(resolveBrowserWorkerUrl(workerUrl, engineUrl, options.wasmUrl), { type: "classic" })),
|
|
217
|
+
options.onInitialisationProgress
|
|
218
|
+
);
|
|
207
219
|
}
|
|
208
220
|
var BrowserWorker;
|
|
209
221
|
var init_browser = __esm({
|
package/dist/browser_worker.js
CHANGED
|
@@ -296,6 +296,8 @@
|
|
|
296
296
|
var configuredEngineUrl = new URL(self.location.href).searchParams.get("engineUrl");
|
|
297
297
|
var engineUrl = self.HYPERDB_WASM_ENGINE_URL ?? configuredEngineUrl ?? "hyperdb-wasm.js";
|
|
298
298
|
var resolvedEngineUrl = new URL(engineUrl, self.location.href);
|
|
299
|
+
var configuredWasmUrl = new URL(self.location.href).searchParams.get("wasmUrl");
|
|
300
|
+
var resolvedWasmUrl = configuredWasmUrl == null ? new URL("hyperdb-wasm.wasm.br", resolvedEngineUrl) : new URL(configuredWasmUrl);
|
|
299
301
|
function isPthreadWorker() {
|
|
300
302
|
const location = self.location;
|
|
301
303
|
return self.name === "em-pthread" || location.search?.includes("pthread") === true;
|
|
@@ -303,14 +305,38 @@
|
|
|
303
305
|
if (isPthreadWorker()) {
|
|
304
306
|
self.importScripts(resolvedEngineUrl.href);
|
|
305
307
|
} else {
|
|
306
|
-
const module = {
|
|
307
|
-
locateFile: (path, prefix) => path === "hyperdb-wasm.wasm" ? new URL("hyperdb-wasm.wasm.br", resolvedEngineUrl).href : `${prefix}${path}`
|
|
308
|
-
};
|
|
309
|
-
self.Module = module;
|
|
310
308
|
const transport = {
|
|
311
309
|
postMessage: (message, transfer = []) => self.postMessage(message, [...transfer]),
|
|
312
310
|
onMessage: (listener) => self.addEventListener("message", (event) => listener(event.data))
|
|
313
311
|
};
|
|
312
|
+
const module = {
|
|
313
|
+
locateFile: (path, prefix) => path === "hyperdb-wasm.wasm" ? resolvedWasmUrl.href : `${prefix}${path}`,
|
|
314
|
+
instantiateWasm: (imports, receiveInstance) => {
|
|
315
|
+
void (async () => {
|
|
316
|
+
const response = await fetch(resolvedWasmUrl, { credentials: "same-origin" });
|
|
317
|
+
if (!response.ok) throw new Error(`failed to fetch HyperDB Wasm: ${response.status} ${response.statusText}`);
|
|
318
|
+
const bytesTotal = response.headers.has("content-encoding") ? 0 : Number(response.headers.get("content-length")) || 0;
|
|
319
|
+
let bytesLoaded = 0;
|
|
320
|
+
transport.postMessage({ type: "progress", bytesLoaded, bytesTotal });
|
|
321
|
+
const body = response.body?.pipeThrough(new TransformStream({
|
|
322
|
+
transform(chunk, controller) {
|
|
323
|
+
bytesLoaded += chunk.byteLength;
|
|
324
|
+
transport.postMessage({ type: "progress", bytesLoaded, bytesTotal });
|
|
325
|
+
controller.enqueue(chunk);
|
|
326
|
+
}
|
|
327
|
+
}));
|
|
328
|
+
const result = body == null ? await WebAssembly.instantiate(await response.arrayBuffer(), imports) : await WebAssembly.instantiateStreaming(new Response(body, response), imports);
|
|
329
|
+
receiveInstance(result.instance, result.module);
|
|
330
|
+
})().catch((error) => {
|
|
331
|
+
transport.postMessage({
|
|
332
|
+
type: "fatal",
|
|
333
|
+
error: `engine instantiation failed: ${error instanceof Error ? error.message : String(error)}`
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
return {};
|
|
337
|
+
}
|
|
338
|
+
};
|
|
339
|
+
self.Module = module;
|
|
314
340
|
configureWorker(module, transport, (runtime) => {
|
|
315
341
|
if (!runtime.OPFS) throw new Error("OPFS backend is unavailable");
|
|
316
342
|
runtime.FS.mkdirTree("/opfs");
|
|
@@ -318,6 +344,7 @@
|
|
|
318
344
|
runtime.FS.mkdirTree("/hyperdb-persistent");
|
|
319
345
|
runtime.FS.mount(runtime.OPFS, {}, "/hyperdb-persistent");
|
|
320
346
|
runtime.FS.mkdirTree("/hyperdb-persistent/hyperdb");
|
|
347
|
+
runtime.FS.mkdirTree("/hyperdb-persistent/logs");
|
|
321
348
|
runtime.resolveHyperDBPath = (path) => {
|
|
322
349
|
const parts = [];
|
|
323
350
|
for (const part of path.replace(/^\/+/, "").split("/")) {
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import type { WasmResult, WorkerTransport } from './protocol.js';
|
|
1
|
+
import type { InstantiationProgress, WasmResult, WorkerTransport } from './protocol.js';
|
|
2
2
|
export declare class HyperDBEngineClient {
|
|
3
|
+
private readonly onInitialisationProgress?;
|
|
3
4
|
private readonly transport;
|
|
4
5
|
private readonly pending;
|
|
5
6
|
private readonly readyPromise;
|
|
@@ -8,7 +9,7 @@ export declare class HyperDBEngineClient {
|
|
|
8
9
|
private nextId;
|
|
9
10
|
private failed;
|
|
10
11
|
private readonly unsubscribe;
|
|
11
|
-
constructor(transport: WorkerTransport);
|
|
12
|
+
constructor(transport: WorkerTransport, onInitialisationProgress?: ((progress: InstantiationProgress) => void) | undefined);
|
|
12
13
|
ready(): Promise<void>;
|
|
13
14
|
initialize(settings: string): Promise<WasmResult>;
|
|
14
15
|
connect(): Promise<WasmResult>;
|