hyperdb-wasm 0.0.26792-dev.wasm.g72cc44c1 → 0.0.26845-dev.wasm.g5b622080
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/api.d.ts +9 -0
- package/dist/browser.js +40 -0
- package/dist/browser_worker.js +27 -4
- package/dist/client.d.ts +2 -0
- 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 -1
- package/dist/node.js +40 -0
- package/dist/node_worker.js +26 -4
- package/dist/protocol.d.ts +10 -0
- package/dist/raw.browser.js +26 -0
- package/dist/raw.node.js +20 -0
- package/dist/wasm_bindings.d.ts +3 -0
- package/dist/worker_setup.d.ts +1 -1
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export interface HyperDBClient {
|
|
|
19
19
|
insertArrowIPCFromPath(connection: number, path: string, name: string, schema: string | null, create: boolean, internal?: boolean): Promise<WasmResult>;
|
|
20
20
|
createTemporaryFile(bytes: Uint8Array): Promise<WasmResult>;
|
|
21
21
|
removeFile(path: string): Promise<WasmResult>;
|
|
22
|
+
registerExternalFile(name: string, url: string, size: number): Promise<WasmResult>;
|
|
23
|
+
removeExternalFile(path: string): Promise<WasmResult>;
|
|
22
24
|
pollQuery(query: number): Promise<WasmResult>;
|
|
23
25
|
cancelQuery(query: number): Promise<WasmResult>;
|
|
24
26
|
releaseQuery(query: number): Promise<WasmResult>;
|
|
@@ -33,6 +35,11 @@ export interface ArrowInsertOptions {
|
|
|
33
35
|
export interface DatabaseCreateOptions {
|
|
34
36
|
readonly storage?: 'memory' | 'persistent';
|
|
35
37
|
}
|
|
38
|
+
export interface ExternalFileRegistration {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly url: string;
|
|
41
|
+
readonly size: number;
|
|
42
|
+
}
|
|
36
43
|
export type HyperDBSettingValue = string | number | boolean | null | readonly HyperDBSettingValue[] | {
|
|
37
44
|
readonly [key: string]: HyperDBSettingValue;
|
|
38
45
|
};
|
|
@@ -59,6 +66,8 @@ export declare class HyperDB {
|
|
|
59
66
|
createDatabase(databaseName: string, options?: DatabaseCreateOptions): Promise<void>;
|
|
60
67
|
openDatabase(databaseName: string): Promise<void>;
|
|
61
68
|
listDatabases(): Promise<DatabaseMetadata[]>;
|
|
69
|
+
registerExternalFile(name: string, url: string, size: number): Promise<string>;
|
|
70
|
+
removeExternalFile(path: string): Promise<void>;
|
|
62
71
|
checkpointDatabase(databaseName: string): Promise<void>;
|
|
63
72
|
dropDatabase(databaseName: string): Promise<void>;
|
|
64
73
|
terminate(): Promise<void>;
|
package/dist/browser.js
CHANGED
|
@@ -139,6 +139,12 @@ var init_client = __esm({
|
|
|
139
139
|
removeFile(path) {
|
|
140
140
|
return this.request({ id: this.nextId++, type: "removeFile", path });
|
|
141
141
|
}
|
|
142
|
+
registerExternalFile(name, url, size) {
|
|
143
|
+
return this.request({ id: this.nextId++, type: "registerExternalFile", name, url, size });
|
|
144
|
+
}
|
|
145
|
+
removeExternalFile(path) {
|
|
146
|
+
return this.request({ id: this.nextId++, type: "removeExternalFile", path });
|
|
147
|
+
}
|
|
142
148
|
pollQuery(query) {
|
|
143
149
|
return this.request({ id: this.nextId++, type: "pollQuery", query });
|
|
144
150
|
}
|
|
@@ -211,6 +217,12 @@ function assertBrowserSupport(environment = globalThis) {
|
|
|
211
217
|
if (!environment.WebAssembly.validate(memory64Probe)) {
|
|
212
218
|
throw new Error("HyperDB cannot initialize because this browser does not yet support WebAssembly memory64. Support for platforms such as iOS is coming soon.");
|
|
213
219
|
}
|
|
220
|
+
try {
|
|
221
|
+
const Memory64 = environment.WebAssembly.Memory;
|
|
222
|
+
new Memory64({ initial: 1n, maximum: 262144n, shared: true, address: "i64" });
|
|
223
|
+
} catch {
|
|
224
|
+
throw new Error("HyperDB cannot initialize because this browser does not support a shared 16 GiB WebAssembly memory64 declaration");
|
|
225
|
+
}
|
|
214
226
|
if (typeof environment.BigInt !== "function") {
|
|
215
227
|
throw new Error("HyperDB cannot initialize because this browser does not yet support WebAssembly BigInt integration. Support for platforms such as iOS is coming soon.");
|
|
216
228
|
}
|
|
@@ -12270,6 +12282,34 @@ var HyperDB = class _HyperDB {
|
|
|
12270
12282
|
listDatabases() {
|
|
12271
12283
|
return this.runDatabaseOperation(async () => readDatabasesFromResult(await this.client.listDatabases()));
|
|
12272
12284
|
}
|
|
12285
|
+
async registerExternalFile(name, url, size) {
|
|
12286
|
+
if (!name) throw new Error("External file name must not be empty");
|
|
12287
|
+
if (name.includes("\0")) throw new Error("External file name must not contain NUL");
|
|
12288
|
+
if (name === "." || name === ".." || name.includes("/") || name.includes("\\")) {
|
|
12289
|
+
throw new Error("External file name must be a basename without path separators");
|
|
12290
|
+
}
|
|
12291
|
+
if (!Number.isSafeInteger(size) || size < 0) throw new Error("External file size must be a nonnegative safe integer");
|
|
12292
|
+
let scheme;
|
|
12293
|
+
try {
|
|
12294
|
+
scheme = new URL(url).protocol;
|
|
12295
|
+
} catch {
|
|
12296
|
+
throw new Error("External file URL must use the blob scheme");
|
|
12297
|
+
}
|
|
12298
|
+
if (scheme !== "blob:") throw new Error("External file URL must use the blob scheme");
|
|
12299
|
+
return this.runDatabaseOperation(async () => {
|
|
12300
|
+
const result = await this.client.registerExternalFile(name, url, size);
|
|
12301
|
+
expectOk(result, "register external file");
|
|
12302
|
+
const path = new TextDecoder("utf-8", { fatal: true }).decode(result.payload);
|
|
12303
|
+
if (!/^\/mnt\/external\/[^/]+\/[^/]+$/.test(path)) throw new Error("register external file returned an invalid path");
|
|
12304
|
+
return path;
|
|
12305
|
+
});
|
|
12306
|
+
}
|
|
12307
|
+
async removeExternalFile(path) {
|
|
12308
|
+
if (!path) throw new Error("External file path must not be empty");
|
|
12309
|
+
await this.runDatabaseOperation(async () => {
|
|
12310
|
+
expectOk(await this.client.removeExternalFile(path), "remove external file");
|
|
12311
|
+
});
|
|
12312
|
+
}
|
|
12273
12313
|
async checkpointDatabase(databaseName) {
|
|
12274
12314
|
validateDatabaseName(databaseName);
|
|
12275
12315
|
await this.runDatabaseOperation(async () => {
|
package/dist/browser_worker.js
CHANGED
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
checkpointDatabase;
|
|
23
23
|
dropDatabase;
|
|
24
24
|
shutdown;
|
|
25
|
+
registerExternalFile;
|
|
26
|
+
removeExternalFile;
|
|
25
27
|
attachDatabase;
|
|
26
28
|
detachDatabase;
|
|
27
29
|
startQuery;
|
|
@@ -44,6 +46,8 @@
|
|
|
44
46
|
this.checkpointDatabase = module.cwrap("hyperdb_wasm_checkpoint_database", "pointer", ["string"]);
|
|
45
47
|
this.dropDatabase = module.cwrap("hyperdb_wasm_drop_database", "pointer", ["string"]);
|
|
46
48
|
this.shutdown = module.cwrap("hyperdb_wasm_shutdown", "pointer", []);
|
|
49
|
+
this.registerExternalFile = module.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number"]);
|
|
50
|
+
this.removeExternalFile = module.cwrap("hyperdb_wasm_remove_external_file", "pointer", ["string"]);
|
|
47
51
|
this.attachDatabase = module.cwrap("hyperdb_wasm_attach_database", "pointer", ["number", "string", "string"]);
|
|
48
52
|
this.detachDatabase = module.cwrap("hyperdb_wasm_detach_database", "pointer", ["number", "string"]);
|
|
49
53
|
this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string"]);
|
|
@@ -66,6 +70,9 @@
|
|
|
66
70
|
this.module.FS.unlink(request.path);
|
|
67
71
|
return { response: { id: request.id, type: "response", result: { state: "ok", payload: new Uint8Array() } }, transfer: [] };
|
|
68
72
|
}
|
|
73
|
+
if ((request.type === "registerExternalFile" || request.type === "removeExternalFile") && !this.module.externalFileBackendAvailable) {
|
|
74
|
+
return { response: { id: request.id, type: "response", result: { state: "error", error: "External files are supported only by the browser client" } }, transfer: [] };
|
|
75
|
+
}
|
|
69
76
|
const pointer = safeInteger(this.invoke(request), "result pointer");
|
|
70
77
|
const result = this.decodeResult(pointer);
|
|
71
78
|
const response = { id: request.id, type: "response", result };
|
|
@@ -103,6 +110,13 @@
|
|
|
103
110
|
return this.detachDatabase(request.connection, request.alias);
|
|
104
111
|
case "shutdown":
|
|
105
112
|
return this.shutdown();
|
|
113
|
+
case "registerExternalFile":
|
|
114
|
+
validateCString(request.name, "external file name");
|
|
115
|
+
validateCString(request.url, "external file URL");
|
|
116
|
+
return this.registerExternalFile(request.name, request.url, safeInteger(request.size, "external file size"));
|
|
117
|
+
case "removeExternalFile":
|
|
118
|
+
validateCString(request.path, "external file path");
|
|
119
|
+
return this.removeExternalFile(request.path);
|
|
106
120
|
case "startQuery":
|
|
107
121
|
return this.startQuery(request.connection, request.sql);
|
|
108
122
|
case "insertArrowIPCFromPath": {
|
|
@@ -190,6 +204,10 @@
|
|
|
190
204
|
return hasKeys(value, ["id", "type", "bytes"]) && value.bytes instanceof Uint8Array;
|
|
191
205
|
case "removeFile":
|
|
192
206
|
return hasKeys(value, ["id", "type", "path"]) && typeof value.path === "string";
|
|
207
|
+
case "registerExternalFile":
|
|
208
|
+
return hasKeys(value, ["id", "type", "name", "url", "size"]) && typeof value.name === "string" && typeof value.url === "string" && typeof value.size === "number" && Number.isSafeInteger(value.size) && value.size >= 0;
|
|
209
|
+
case "removeExternalFile":
|
|
210
|
+
return hasKeys(value, ["id", "type", "path"]) && typeof value.path === "string";
|
|
193
211
|
case "pollQuery":
|
|
194
212
|
case "cancelQuery":
|
|
195
213
|
case "releaseQuery":
|
|
@@ -211,22 +229,26 @@
|
|
|
211
229
|
function allocate(module, bytes) {
|
|
212
230
|
const pointer = safePointer(module._malloc(bytes.byteLength || 1), "allocation pointer");
|
|
213
231
|
if (pointer === 0) throw new Error("wasm allocation failed");
|
|
214
|
-
|
|
215
|
-
module.HEAPU8
|
|
232
|
+
module.getValue(pointer, "i8");
|
|
233
|
+
const heap = module.HEAPU8;
|
|
234
|
+
if (pointer + bytes.byteLength > heap.byteLength) throw new Error("allocation exceeds the wasm heap");
|
|
235
|
+
heap.set(bytes, pointer);
|
|
216
236
|
return pointer;
|
|
217
237
|
}
|
|
218
238
|
function installHttpRuntime(module, transport) {
|
|
219
|
-
module.hyperdbWasmFetchStart = (id, url, offset, length) => {
|
|
239
|
+
module.hyperdbWasmFetchStart = (id, url, offset, length, expectedSize) => {
|
|
220
240
|
const headers = new Headers();
|
|
221
241
|
if (length > 0) headers.set("Range", `bytes=${offset}-${offset + length - 1}`);
|
|
222
242
|
void fetch(url, { headers, redirect: "manual" }).then(async (response) => {
|
|
223
243
|
if (!response.ok || response.type === "opaqueredirect" || (length === 0 ? response.status !== 200 : response.status !== 206)) {
|
|
244
|
+
void response.body?.cancel().catch(() => void 0);
|
|
224
245
|
module._hyperdb_wasm_fetch_complete(id, 0, -1);
|
|
225
246
|
return;
|
|
226
247
|
}
|
|
227
248
|
if (length > 0) {
|
|
228
249
|
const contentRange = /^bytes (\d+)-(\d+)\/(\d+)$/.exec(response.headers.get("content-range") ?? "");
|
|
229
|
-
if (!contentRange || contentRange[1] !== String(offset) || contentRange[2] !== String(offset + length - 1)) {
|
|
250
|
+
if (!contentRange || contentRange[1] !== String(offset) || contentRange[2] !== String(offset + length - 1) || expectedSize >= 0 && contentRange[3] !== String(expectedSize)) {
|
|
251
|
+
void response.body?.cancel().catch(() => void 0);
|
|
230
252
|
module._hyperdb_wasm_fetch_complete(id, 0, -1);
|
|
231
253
|
return;
|
|
232
254
|
}
|
|
@@ -356,6 +378,7 @@
|
|
|
356
378
|
};
|
|
357
379
|
self.Module = module;
|
|
358
380
|
configureWorker(module, transport, (runtime) => {
|
|
381
|
+
runtime.externalFileBackendAvailable = true;
|
|
359
382
|
if (!runtime.OPFS) throw new Error("OPFS backend is unavailable");
|
|
360
383
|
runtime.FS.mkdirTree("/opfs");
|
|
361
384
|
runtime.FS.mount(runtime.OPFS, {}, "/opfs");
|
package/dist/client.d.ts
CHANGED
|
@@ -26,6 +26,8 @@ export declare class HyperDBEngineClient {
|
|
|
26
26
|
insertArrowIPCFromPath(connection: number, path: string, name: string, schema: string | null, create: boolean, internal?: boolean): Promise<WasmResult>;
|
|
27
27
|
createTemporaryFile(bytes: Uint8Array): Promise<WasmResult>;
|
|
28
28
|
removeFile(path: string): Promise<WasmResult>;
|
|
29
|
+
registerExternalFile(name: string, url: string, size: number): Promise<WasmResult>;
|
|
30
|
+
removeExternalFile(path: string): Promise<WasmResult>;
|
|
29
31
|
pollQuery(query: number): Promise<WasmResult>;
|
|
30
32
|
cancelQuery(query: number): Promise<WasmResult>;
|
|
31
33
|
releaseQuery(query: number): Promise<WasmResult>;
|