hyperdb-wasm 0.0.27001-dev.wasm.gc5d11398 → 0.0.27099-dev.wasm.g0a1be56f
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 +1 -1
- package/dist/browser.js +7 -6
- package/dist/browser_worker.js +28 -38
- package/dist/hyperdb-wasm.cjs +1 -1
- package/dist/hyperdb-wasm.js +1 -1
- package/dist/hyperdb-wasm.wasm.br +0 -0
- package/dist/node.js +7 -6
- package/dist/node_worker.js +26 -35
- package/dist/raw.browser.js +15 -5
- package/dist/raw.node.js +11 -1
- package/dist/worker_setup.d.ts +1 -2
- package/package.json +1 -1
package/dist/browser.d.ts
CHANGED
|
@@ -38,6 +38,6 @@ export declare class BrowserWorker implements WorkerTransport {
|
|
|
38
38
|
onClose(): () => void;
|
|
39
39
|
terminate(): void;
|
|
40
40
|
}
|
|
41
|
-
export declare function resolveBrowserWorkerUrl(workerUrl: string | URL, engineUrl: string | URL, wasmUrl?: string | URL, storagePath?: string): URL;
|
|
41
|
+
export declare function resolveBrowserWorkerUrl(workerUrl: string | URL, engineUrl: string | URL, wasmUrl?: string | URL, storagePath?: string, baseUrl?: string | URL): URL;
|
|
42
42
|
export declare function createBrowserClient(options?: BrowserClientOptions): HyperDBEngineClient;
|
|
43
43
|
export {};
|
package/dist/browser.js
CHANGED
|
@@ -228,10 +228,10 @@ function assertBrowserSupport(environment = globalThis) {
|
|
|
228
228
|
throw new Error("HyperDB cannot initialize because this browser does not support the origin-private file system");
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
|
-
function resolveBrowserWorkerUrl(workerUrl, engineUrl, wasmUrl, storagePath) {
|
|
232
|
-
const resolved = new URL(workerUrl);
|
|
233
|
-
resolved.searchParams.set("engineUrl", new URL(engineUrl).href);
|
|
234
|
-
if (wasmUrl != null) resolved.searchParams.set("wasmUrl", new URL(wasmUrl).href);
|
|
231
|
+
function resolveBrowserWorkerUrl(workerUrl, engineUrl, wasmUrl, storagePath, baseUrl = globalThis.document?.baseURI ?? globalThis.location?.href ?? import.meta.url) {
|
|
232
|
+
const resolved = new URL(workerUrl, baseUrl);
|
|
233
|
+
resolved.searchParams.set("engineUrl", new URL(engineUrl, baseUrl).href);
|
|
234
|
+
if (wasmUrl != null) resolved.searchParams.set("wasmUrl", new URL(wasmUrl, baseUrl).href);
|
|
235
235
|
if (storagePath != null) resolved.searchParams.set("storagePath", storagePath);
|
|
236
236
|
return resolved;
|
|
237
237
|
}
|
|
@@ -12236,8 +12236,7 @@ function expectOk(result, operation) {
|
|
|
12236
12236
|
if (result.state !== "ok") throw readErrorFromResult(result, operation);
|
|
12237
12237
|
}
|
|
12238
12238
|
async function initializeHyperDB(client, settings) {
|
|
12239
|
-
|
|
12240
|
-
const serialized = JSON.stringify(settings);
|
|
12239
|
+
const serialized = JSON.stringify(settings ?? {});
|
|
12241
12240
|
if (serialized === void 0) throw new Error("HyperDB settings must be JSON-serializable");
|
|
12242
12241
|
expectOk(await client.initialize(serialized), "initialize HyperDB settings");
|
|
12243
12242
|
}
|
|
@@ -12502,6 +12501,8 @@ var HyperDBConnection = class {
|
|
|
12502
12501
|
const result = (async () => {
|
|
12503
12502
|
const reader = await RecordBatchReader.from(stream.result);
|
|
12504
12503
|
if (!reader.isAsync() || !reader.isStream()) throw new Error("query did not produce an Arrow async stream");
|
|
12504
|
+
await reader.open();
|
|
12505
|
+
if (!reader.schema) throw new Error("query did not produce an Arrow schema");
|
|
12505
12506
|
return reader;
|
|
12506
12507
|
})();
|
|
12507
12508
|
return queryResult(result, stream.info);
|
package/dist/browser_worker.js
CHANGED
|
@@ -12,9 +12,12 @@
|
|
|
12
12
|
if (typeof number !== "number" || !Number.isSafeInteger(number) || number < 0) throw new Error(`${name} must be a nonnegative safe integer`);
|
|
13
13
|
return number;
|
|
14
14
|
}
|
|
15
|
+
function validateCStringContents(value, name) {
|
|
16
|
+
if (value.includes("\0")) throw new Error(`${name} must not contain NUL`);
|
|
17
|
+
}
|
|
15
18
|
function validateCString(value, name) {
|
|
16
19
|
if (!value) throw new Error(`${name} must not be empty`);
|
|
17
|
-
|
|
20
|
+
validateCStringContents(value, name);
|
|
18
21
|
}
|
|
19
22
|
function resultError(result) {
|
|
20
23
|
if (result.state === "error" || result.state === "busy") {
|
|
@@ -157,6 +160,7 @@
|
|
|
157
160
|
switch (request.type) {
|
|
158
161
|
case "initialize":
|
|
159
162
|
validateCString(request.settings, "settings");
|
|
163
|
+
validateCStringContents(this.module.hyperdbWasmStoragePath ?? "", "storage path");
|
|
160
164
|
return this.initialize(request.settings, this.module.hyperdbWasmStoragePath ?? "");
|
|
161
165
|
case "connect":
|
|
162
166
|
return this.connect();
|
|
@@ -170,9 +174,13 @@
|
|
|
170
174
|
validateCString(request.path, "external registration path");
|
|
171
175
|
return this.removeExternalRegistration(request.path);
|
|
172
176
|
case "startQuery":
|
|
177
|
+
validateCStringContents(request.sql, "SQL");
|
|
173
178
|
return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false));
|
|
174
179
|
case "insertArrowIPCFromPath": {
|
|
175
180
|
const path = request.internal || request.path.startsWith("/mnt/external/") ? request.path : this.module.resolveHyperDBPath?.(request.path) ?? request.path;
|
|
181
|
+
validateCString(path, "Arrow IPC input path");
|
|
182
|
+
validateCString(request.name, "Arrow insert table name");
|
|
183
|
+
validateCStringContents(request.schema ?? "", "Arrow insert schema name");
|
|
176
184
|
return this.insertArrowIPCFromPath(request.connection, path, request.name, request.schema ?? "", Number(request.create));
|
|
177
185
|
}
|
|
178
186
|
case "pollQuery":
|
|
@@ -227,9 +235,11 @@
|
|
|
227
235
|
if (!backend) {
|
|
228
236
|
return { response: { id: request.id, type: "response", result: { state: "error", error: "External directories are not supported by this client" } }, transfer: [] };
|
|
229
237
|
}
|
|
238
|
+
validateCString(request.path, "external registration path");
|
|
230
239
|
const registration = backend.register(source, request.mode);
|
|
231
240
|
let preserveBackend = false;
|
|
232
241
|
try {
|
|
242
|
+
validateCString(registration.locator, "external directory locator");
|
|
233
243
|
const pointer = safeInteger(this.registerExternalDirectory(request.path, registration.locator, Number(request.mode === "readwrite")), "result pointer");
|
|
234
244
|
const result = this.decodeResult(pointer);
|
|
235
245
|
if (result.state === "ok") {
|
|
@@ -385,6 +395,11 @@
|
|
|
385
395
|
);
|
|
386
396
|
}
|
|
387
397
|
function installHttpRuntime(module, transport) {
|
|
398
|
+
const fetches = /* @__PURE__ */ new Map();
|
|
399
|
+
const completeFetch = (id, pointer, length) => {
|
|
400
|
+
if (!fetches.delete(id)) return;
|
|
401
|
+
module._hyperdb_wasm_fetch_complete(id, pointer, length);
|
|
402
|
+
};
|
|
388
403
|
module.hyperdbWasmFetchStart = (id, url, offset, length, expectedSize) => {
|
|
389
404
|
if (url.startsWith("hyperdb-node-file:") || url.startsWith("hyperdb-node-host-file:") || url.startsWith("hyperdb-node-directory-file:") || url.startsWith("hyperdb-browser-file:")) {
|
|
390
405
|
const read = module.externalFileBackend?.read(url, offset, length, expectedSize) ?? module.externalDirectoryBackend?.read(url, offset, length, expectedSize);
|
|
@@ -401,63 +416,39 @@
|
|
|
401
416
|
}
|
|
402
417
|
const headers = new Headers();
|
|
403
418
|
if (length > 0) headers.set("Range", `bytes=${offset}-${offset + length - 1}`);
|
|
404
|
-
|
|
419
|
+
const controller = new AbortController();
|
|
420
|
+
fetches.set(id, controller);
|
|
421
|
+
void fetch(url, { headers, redirect: "manual", signal: controller.signal }).then(async (response) => {
|
|
405
422
|
if (!response.ok || response.type === "opaqueredirect" || (length === 0 ? response.status !== 200 : response.status !== 206)) {
|
|
406
423
|
void response.body?.cancel().catch(() => void 0);
|
|
407
|
-
|
|
424
|
+
completeFetch(id, 0, -1);
|
|
408
425
|
return;
|
|
409
426
|
}
|
|
410
427
|
if (length > 0) {
|
|
411
428
|
const contentRange = /^bytes (\d+)-(\d+)\/(\d+)$/.exec(response.headers.get("content-range") ?? "");
|
|
412
429
|
if (!contentRange || contentRange[1] !== String(offset) || contentRange[2] !== String(offset + length - 1) || expectedSize >= 0 && contentRange[3] !== String(expectedSize)) {
|
|
413
430
|
void response.body?.cancel().catch(() => void 0);
|
|
414
|
-
|
|
431
|
+
completeFetch(id, 0, -1);
|
|
415
432
|
return;
|
|
416
433
|
}
|
|
417
434
|
}
|
|
418
435
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
419
436
|
if (length > 0 && bytes.byteLength !== length) {
|
|
420
|
-
|
|
437
|
+
completeFetch(id, 0, -1);
|
|
421
438
|
return;
|
|
422
439
|
}
|
|
423
440
|
try {
|
|
424
|
-
|
|
441
|
+
completeFetch(id, allocate(module, bytes), bytes.byteLength);
|
|
425
442
|
} catch (error) {
|
|
426
443
|
transport.postMessage({ type: "log", text: `fetch failed: ${errorText(error)}` });
|
|
427
|
-
|
|
444
|
+
completeFetch(id, 0, -1);
|
|
428
445
|
}
|
|
429
446
|
}).catch(() => {
|
|
430
447
|
transport.postMessage({ type: "log", text: "fetch failed" });
|
|
431
|
-
|
|
432
|
-
});
|
|
433
|
-
};
|
|
434
|
-
module.hyperdbWasmHttpStart = (id, method, url, headerLines, bodyPointer, bodyLength) => {
|
|
435
|
-
const headers = new Headers();
|
|
436
|
-
for (const line of headerLines.split("\n")) {
|
|
437
|
-
const separator = line.indexOf(":");
|
|
438
|
-
if (separator > 0) headers.set(line.slice(0, separator), line.slice(separator + 1));
|
|
439
|
-
}
|
|
440
|
-
const pointer = safePointer(bodyPointer, "HTTP body pointer");
|
|
441
|
-
const bodyEnd = safePointer(pointer + bodyLength, "HTTP body end");
|
|
442
|
-
if (bodyEnd > module.HEAPU8.byteLength) throw new Error("HTTP body exceeds the wasm heap");
|
|
443
|
-
const body = bodyLength > 0 ? module.HEAPU8.slice(pointer, bodyEnd) : void 0;
|
|
444
|
-
const init = { method, headers };
|
|
445
|
-
if (body) init.body = body;
|
|
446
|
-
void fetch(url, init).then(async (response) => {
|
|
447
|
-
const responseBody = new Uint8Array(await response.arrayBuffer());
|
|
448
|
-
let responseHeaders = "";
|
|
449
|
-
response.headers.forEach((value, name) => {
|
|
450
|
-
responseHeaders += `${name.toLowerCase()}:${value}
|
|
451
|
-
`;
|
|
452
|
-
});
|
|
453
|
-
const headersPointer = responseHeaders ? safePointer(module.stringToNewUTF8(responseHeaders), "headers pointer") : 0;
|
|
454
|
-
const responseBodyPointer = responseBody.byteLength ? allocate(module, responseBody) : 0;
|
|
455
|
-
module._hyperdb_wasm_http_complete(id, response.status, headersPointer, responseBodyPointer, responseBody.byteLength);
|
|
456
|
-
}).catch((error) => {
|
|
457
|
-
const errorBytes = new TextEncoder().encode(errorText(error));
|
|
458
|
-
module._hyperdb_wasm_http_complete(id, -1, 0, allocate(module, errorBytes), errorBytes.byteLength);
|
|
448
|
+
completeFetch(id, 0, -1);
|
|
459
449
|
});
|
|
460
450
|
};
|
|
451
|
+
module.hyperdbWasmFetchCancel = (id) => fetches.get(id)?.abort();
|
|
461
452
|
}
|
|
462
453
|
function installExternalDirectoryRuntime(module) {
|
|
463
454
|
const backend = module.externalDirectoryBackend;
|
|
@@ -949,8 +940,7 @@
|
|
|
949
940
|
}
|
|
950
941
|
var storagePath = normalizeStoragePath(configuredStoragePath);
|
|
951
942
|
function isPthreadWorker() {
|
|
952
|
-
|
|
953
|
-
return self.name === "em-pthread" || location.search?.includes("pthread") === true;
|
|
943
|
+
return self.name === "em-pthread";
|
|
954
944
|
}
|
|
955
945
|
if (isPthreadWorker()) {
|
|
956
946
|
self.importScripts(resolvedEngineUrl.href);
|
|
@@ -998,7 +988,7 @@
|
|
|
998
988
|
runtime.hyperdbWasmStoragePath = storagePath;
|
|
999
989
|
runtime.resolveHyperDBPath = (path) => {
|
|
1000
990
|
const relativePath = normalizeStoragePath(path);
|
|
1001
|
-
return
|
|
991
|
+
return `/mnt/fs/${relativePath}`;
|
|
1002
992
|
};
|
|
1003
993
|
});
|
|
1004
994
|
self.importScripts(resolvedEngineUrl.href);
|