hyperdb-wasm 0.0.26792-dev.wasm.g72cc44c1 → 0.0.26862-dev.wasm.g42f1012b

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/raw.node.js CHANGED
@@ -17,12 +17,16 @@ function isWasmResult(value) {
17
17
  case "done":
18
18
  return hasKeys(value, ["state"]);
19
19
  case "error":
20
+ return hasKeys(value, ["state", "error"]) && (typeof value.error === "string" || isHyperDBErrorData(value.error));
20
21
  case "busy":
21
22
  return hasKeys(value, ["state", "error"]) && typeof value.error === "string";
22
23
  default:
23
24
  return false;
24
25
  }
25
26
  }
27
+ function isHyperDBErrorData(value) {
28
+ return isRecord(value) && hasKeys(value, ["sqlState", "errorSource", "message", "detail", "hint"]) && typeof value.sqlState === "string" && /^[0-9A-Z]{5}$/.test(value.sqlState) && (value.errorSource === "User" || value.errorSource === "System" || value.errorSource === "OverloadRejection") && typeof value.message === "string" && typeof value.detail === "string" && typeof value.hint === "string";
29
+ }
26
30
  function isWorkerEvent(message) {
27
31
  if (!isRecord(message) || typeof message.type !== "string") return false;
28
32
  switch (message.type) {
@@ -101,8 +105,11 @@ var HyperDBEngineClient = class {
101
105
  shutdown() {
102
106
  return this.request({ id: this.nextId++, type: "shutdown" });
103
107
  }
104
- startQuery(connection, sql) {
105
- return this.request({ id: this.nextId++, type: "startQuery", connection, sql });
108
+ startQuery(connection, sql, sqlTestMode = false) {
109
+ return this.request({ id: this.nextId++, type: "startQuery", connection, sql, ...sqlTestMode && { sqlTestMode } });
110
+ }
111
+ startQueryWithInfo(connection, sql) {
112
+ return this.request({ id: this.nextId++, type: "startQueryWithInfo", connection, sql });
106
113
  }
107
114
  insertArrowIPCFromPath(connection, path, name, schema, create, internal = false) {
108
115
  return this.request({ id: this.nextId++, type: "insertArrowIPCFromPath", connection, path, name, schema, create, internal });
@@ -114,6 +121,15 @@ var HyperDBEngineClient = class {
114
121
  removeFile(path) {
115
122
  return this.request({ id: this.nextId++, type: "removeFile", path });
116
123
  }
124
+ registerExternalFile(pathOrName, url, size) {
125
+ return url === void 0 || size === void 0 ? this.request({ id: this.nextId++, type: "registerExternalFile", path: pathOrName }) : this.request({ id: this.nextId++, type: "registerExternalFile", name: pathOrName, url, size });
126
+ }
127
+ registerExternalDirectory(source, mode) {
128
+ return typeof source === "string" ? this.request({ id: this.nextId++, type: "registerExternalDirectory", path: source, mode }) : this.request({ id: this.nextId++, type: "registerExternalDirectory", handle: source, mode });
129
+ }
130
+ removeExternalRegistration(path) {
131
+ return this.request({ id: this.nextId++, type: "removeExternalRegistration", path });
132
+ }
117
133
  pollQuery(query) {
118
134
  return this.request({ id: this.nextId++, type: "pollQuery", query });
119
135
  }
@@ -123,6 +139,9 @@ var HyperDBEngineClient = class {
123
139
  releaseQuery(query) {
124
140
  return this.request({ id: this.nextId++, type: "releaseQuery", query });
125
141
  }
142
+ releaseQueryWithInfo(query) {
143
+ return this.request({ id: this.nextId++, type: "releaseQueryWithInfo", query });
144
+ }
126
145
  async terminate() {
127
146
  await this.transport.terminate();
128
147
  this.fail(new Error("engine worker terminated"));
@@ -170,7 +189,12 @@ var HyperDBEngineClient = class {
170
189
  };
171
190
 
172
191
  // src/wasm_bindings.ts
173
- var resultStates = ["ok", "pending", "chunk", "done", "error", "busy"];
192
+ function completionFor(cleanups) {
193
+ const pending = cleanups.filter((cleanup) => cleanup !== void 0);
194
+ return pending.length === 0 ? void 0 : Promise.all(pending).then(() => void 0);
195
+ }
196
+ var resultStates = ["ok", "pending", "chunk", "done", "error", "busy", "structuredError"];
197
+ var structuredErrorMagic = new Uint8Array([72, 68, 66, 69]);
174
198
  function safeInteger(value, name) {
175
199
  const number = typeof value === "bigint" && value <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(value) : value;
176
200
  if (typeof number !== "number" || !Number.isSafeInteger(number) || number < 0) throw new Error(`${name} must be a nonnegative safe integer`);
@@ -180,6 +204,33 @@ function validateCString(value, name) {
180
204
  if (!value) throw new Error(`${name} must not be empty`);
181
205
  if (value.includes("\0")) throw new Error(`${name} must not contain NUL`);
182
206
  }
207
+ function decodeStructuredError(payload) {
208
+ if (!structuredErrorMagic.every((byte, index) => payload[index] === byte)) throw new Error("structured error has invalid magic");
209
+ const view = new DataView(payload.buffer, payload.byteOffset, payload.byteLength);
210
+ if (payload.byteLength < 8 || view.getUint32(4, true) !== 1) throw new Error("unsupported structured error version");
211
+ let offset = 8;
212
+ const decoder = new TextDecoder("utf-8", { fatal: true });
213
+ const readField = () => {
214
+ if (offset + 4 > payload.byteLength) throw new Error("truncated structured error field");
215
+ const length = view.getUint32(offset, true);
216
+ offset += 4;
217
+ if (length > payload.byteLength - offset) throw new Error("truncated structured error field");
218
+ const value = decoder.decode(payload.subarray(offset, offset + length));
219
+ offset += length;
220
+ return value;
221
+ };
222
+ const sqlState = readField();
223
+ const errorSource = readField();
224
+ const message = readField();
225
+ const detail = readField();
226
+ const hint = readField();
227
+ if (offset !== payload.byteLength) throw new Error("structured error has trailing bytes");
228
+ if (!/^[0-9A-Z]{5}$/.test(sqlState)) throw new Error("structured error has invalid SQLSTATE");
229
+ if (errorSource !== "User" && errorSource !== "System" && errorSource !== "OverloadRejection") {
230
+ throw new Error("structured error has invalid source");
231
+ }
232
+ return { sqlState, errorSource, message, detail, hint };
233
+ }
183
234
  var HyperDBBindings = class {
184
235
  module;
185
236
  initialize;
@@ -191,13 +242,18 @@ var HyperDBBindings = class {
191
242
  checkpointDatabase;
192
243
  dropDatabase;
193
244
  shutdown;
245
+ registerExternalFile;
246
+ registerExternalDirectory;
247
+ removeExternalRegistration;
194
248
  attachDatabase;
195
249
  detachDatabase;
196
250
  startQuery;
251
+ startQueryWithInfo;
197
252
  insertArrowIPCFromPath;
198
253
  pollQuery;
199
254
  cancelQuery;
200
255
  releaseQuery;
256
+ releaseQueryWithInfo;
201
257
  resultState;
202
258
  resultPayloadLength;
203
259
  free;
@@ -213,13 +269,18 @@ var HyperDBBindings = class {
213
269
  this.checkpointDatabase = module.cwrap("hyperdb_wasm_checkpoint_database", "pointer", ["string"]);
214
270
  this.dropDatabase = module.cwrap("hyperdb_wasm_drop_database", "pointer", ["string"]);
215
271
  this.shutdown = module.cwrap("hyperdb_wasm_shutdown", "pointer", []);
272
+ this.registerExternalFile = module.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number"]);
273
+ this.registerExternalDirectory = module.cwrap("hyperdb_wasm_register_external_directory", "pointer", ["string", "string", "number"]);
274
+ this.removeExternalRegistration = module.cwrap("hyperdb_wasm_remove_external_registration", "pointer", ["string"]);
216
275
  this.attachDatabase = module.cwrap("hyperdb_wasm_attach_database", "pointer", ["number", "string", "string"]);
217
276
  this.detachDatabase = module.cwrap("hyperdb_wasm_detach_database", "pointer", ["number", "string"]);
218
- this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string"]);
277
+ this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string", "number"]);
278
+ this.startQueryWithInfo = module.cwrap("hyperdb_wasm_query_start_with_info", "pointer", ["number", "string"]);
219
279
  this.insertArrowIPCFromPath = module.cwrap("hyperdb_wasm_arrow_insert_from_path", "pointer", ["number", "string", "string", "string", "number"]);
220
280
  this.pollQuery = module.cwrap("hyperdb_wasm_query_poll", "pointer", ["number"]);
221
281
  this.cancelQuery = module.cwrap("hyperdb_wasm_query_cancel", "pointer", ["number"]);
222
282
  this.releaseQuery = module.cwrap("hyperdb_wasm_query_release", "pointer", ["number"]);
283
+ this.releaseQueryWithInfo = module.cwrap("hyperdb_wasm_query_release_with_info", "pointer", ["number"]);
223
284
  this.resultState = module.cwrap("hyperdb_wasm_result_state", "number", ["number"]);
224
285
  this.resultPayloadLength = module.cwrap("hyperdb_wasm_result_payload_len", "number", ["number"]);
225
286
  this.free = module.cwrap("hyperdb_wasm_free", null, ["pointer"]);
@@ -235,8 +296,92 @@ var HyperDBBindings = class {
235
296
  this.module.FS.unlink(request.path);
236
297
  return { response: { id: request.id, type: "response", result: { state: "ok", payload: new Uint8Array() } }, transfer: [] };
237
298
  }
299
+ if (request.type === "registerExternalFile" && "path" in request) {
300
+ if (!this.module.externalFileBackend) {
301
+ return { response: { id: request.id, type: "response", result: { state: "error", error: "Host external files are supported only by the Node client" } }, transfer: [] };
302
+ }
303
+ const registration = this.module.externalFileBackend.register(request.path);
304
+ try {
305
+ const pointer2 = safeInteger(this.registerExternalFile(registration.name, registration.locator, registration.size), "result pointer");
306
+ const result2 = this.decodeResult(pointer2);
307
+ if (result2.state === "ok") {
308
+ const path = new TextDecoder("utf-8", { fatal: true }).decode(result2.payload);
309
+ try {
310
+ this.module.externalFileBackend.registered(path, registration.locator);
311
+ } catch (error) {
312
+ const cleanupPointer = safeInteger(this.removeExternalRegistration(path), "result pointer");
313
+ this.decodeResult(cleanupPointer);
314
+ throw error;
315
+ }
316
+ } else {
317
+ this.module.externalFileBackend.removed(registration.locator);
318
+ }
319
+ return { response: { id: request.id, type: "response", result: result2 }, transfer: [] };
320
+ } catch (error) {
321
+ this.module.externalFileBackend.removed(registration.locator);
322
+ throw error;
323
+ }
324
+ }
325
+ if (request.type === "registerExternalFile" && !this.module.externalFileBackendAvailable) {
326
+ return { response: { id: request.id, type: "response", result: { state: "error", error: "Blob external files are supported only by the browser client" } }, transfer: [] };
327
+ }
328
+ if (request.type === "registerExternalDirectory") {
329
+ const backend = this.module.externalDirectoryBackend;
330
+ if (!backend) {
331
+ return { response: { id: request.id, type: "response", result: { state: "error", error: "External directories are not supported by this client" } }, transfer: [] };
332
+ }
333
+ const registration = backend.register("handle" in request ? request.handle : request.path, request.mode);
334
+ try {
335
+ const pointer2 = safeInteger(this.registerExternalDirectory(registration.name, registration.locator, Number(request.mode === "readwrite")), "result pointer");
336
+ const result2 = this.decodeResult(pointer2);
337
+ if (result2.state === "ok") {
338
+ const path = new TextDecoder("utf-8", { fatal: true }).decode(result2.payload);
339
+ try {
340
+ backend.registered(path, registration.locator);
341
+ } catch (error) {
342
+ const cleanupPointer = safeInteger(this.removeExternalRegistration(path), "result pointer");
343
+ this.decodeResult(cleanupPointer);
344
+ throw error;
345
+ }
346
+ } else {
347
+ const completion = completionFor([backend.removed(registration.locator)]);
348
+ return { response: { id: request.id, type: "response", result: result2 }, transfer: [], ...completion && { completion } };
349
+ }
350
+ return { response: { id: request.id, type: "response", result: result2 }, transfer: [] };
351
+ } catch (error) {
352
+ void Promise.resolve(backend.removed(registration.locator)).catch(() => void 0);
353
+ throw error;
354
+ }
355
+ }
356
+ if (request.type === "removeExternalRegistration" && (this.module.externalFileBackend || this.module.externalDirectoryBackend)) {
357
+ validateCString(request.path, "external registration path");
358
+ const pointer2 = safeInteger(this.removeExternalRegistration(request.path), "result pointer");
359
+ const result2 = this.decodeResult(pointer2);
360
+ if (result2.state === "ok") {
361
+ const completion = completionFor([
362
+ this.module.externalFileBackend?.removed(request.path),
363
+ this.module.externalDirectoryBackend?.removed(request.path)
364
+ ]);
365
+ return { response: { id: request.id, type: "response", result: result2 }, transfer: [], ...completion && { completion } };
366
+ }
367
+ return { response: { id: request.id, type: "response", result: result2 }, transfer: [] };
368
+ }
369
+ if (request.type === "removeExternalRegistration" && !this.module.externalFileBackendAvailable) {
370
+ return { response: { id: request.id, type: "response", result: { state: "error", error: "External files are not supported by this client" } }, transfer: [] };
371
+ }
238
372
  const pointer = safeInteger(this.invoke(request), "result pointer");
239
373
  const result = this.decodeResult(pointer);
374
+ if (request.type === "shutdown" && result.state === "ok") {
375
+ const completion = completionFor([
376
+ this.module.externalFileBackend?.shutdown(),
377
+ this.module.externalDirectoryBackend?.shutdown()
378
+ ]);
379
+ return {
380
+ response: { id: request.id, type: "response", result },
381
+ transfer: [],
382
+ ...completion && { completion }
383
+ };
384
+ }
240
385
  const response = { id: request.id, type: "response", result };
241
386
  return { response, transfer: result.state === "chunk" ? [result.payload.buffer] : [] };
242
387
  }
@@ -272,8 +417,20 @@ var HyperDBBindings = class {
272
417
  return this.detachDatabase(request.connection, request.alias);
273
418
  case "shutdown":
274
419
  return this.shutdown();
420
+ case "registerExternalFile":
421
+ if ("path" in request) throw new Error("host external file request has no backend");
422
+ validateCString(request.name, "external file name");
423
+ validateCString(request.url, "external file URL");
424
+ return this.registerExternalFile(request.name, request.url, safeInteger(request.size, "external file size"));
425
+ case "registerExternalDirectory":
426
+ throw new Error("external directory request has no backend");
427
+ case "removeExternalRegistration":
428
+ validateCString(request.path, "external registration path");
429
+ return this.removeExternalRegistration(request.path);
275
430
  case "startQuery":
276
- return this.startQuery(request.connection, request.sql);
431
+ return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false));
432
+ case "startQueryWithInfo":
433
+ return this.startQueryWithInfo(request.connection, request.sql);
277
434
  case "insertArrowIPCFromPath": {
278
435
  const path = request.internal ? request.path : this.module.resolveHyperDBPath?.(request.path) ?? request.path;
279
436
  return this.insertArrowIPCFromPath(request.connection, path, request.name, request.schema ?? "", Number(request.create));
@@ -284,6 +441,8 @@ var HyperDBBindings = class {
284
441
  return this.cancelQuery(request.query);
285
442
  case "releaseQuery":
286
443
  return this.releaseQuery(request.query);
444
+ case "releaseQueryWithInfo":
445
+ return this.releaseQueryWithInfo(request.query);
287
446
  }
288
447
  }
289
448
  decodeResult(pointer) {
@@ -313,6 +472,8 @@ var HyperDBBindings = class {
313
472
  return { state, error: new TextDecoder().decode(payload) };
314
473
  case "busy":
315
474
  return { state, error: new TextDecoder().decode(payload) };
475
+ case "structuredError":
476
+ return { state: "error", error: decodeStructuredError(payload) };
316
477
  }
317
478
  } finally {
318
479
  this.free(pointer);
@@ -356,7 +517,7 @@ function resolveNodeEnginePath(engineUrl) {
356
517
  function createNodeClient(options = {}) {
357
518
  const workerUrl = options.workerUrl ?? new URL("./node_worker.js", import.meta.url);
358
519
  const engineUrl = options.engineUrl ?? resolveNodeEnginePath(new URL("./hyperdb-wasm.cjs", import.meta.url));
359
- return new HyperDBEngineClient(new NodeWorker(new NativeWorker(workerUrl, { workerData: { engineUrl, hostPath: options.hostPath } })));
520
+ return new HyperDBEngineClient(new NodeWorker(new NativeWorker(workerUrl, { workerData: { engineUrl, storagePath: options.storagePath } })));
360
521
  }
361
522
  export {
362
523
  HyperDBBindings,
@@ -1,5 +1,42 @@
1
1
  import type { EngineRequest, WasmResponse } from './protocol.js';
2
2
  type CFunction = (...args: readonly unknown[]) => unknown;
3
+ export interface ExternalFileBackend {
4
+ register(path: string): {
5
+ readonly name: string;
6
+ readonly locator: string;
7
+ readonly size: number;
8
+ };
9
+ registered(path: string, locator: string): void;
10
+ removed(path: string): void;
11
+ openHostFile(path: string): {
12
+ readonly id: number;
13
+ readonly size: number;
14
+ };
15
+ closeHostFile(id: number): void;
16
+ listHostDirectory(path: string): Promise<readonly string[]>;
17
+ read(locator: string, offset: number, length: number, expectedSize: number): Promise<Uint8Array> | undefined;
18
+ shutdown(): void;
19
+ }
20
+ export interface ExternalDirectoryBackend {
21
+ register(handle: unknown, mode: 'read' | 'readwrite'): {
22
+ readonly name: string;
23
+ readonly locator: string;
24
+ };
25
+ registered(path: string, locator: string): void;
26
+ removed(path: string): void | Promise<void>;
27
+ list(locator: string): Promise<readonly string[]>;
28
+ open(locator: string, path: string): Promise<{
29
+ readonly locator: string;
30
+ readonly size: number;
31
+ }>;
32
+ read(locator: string, offset: number, length: number, expectedSize: number): Promise<Uint8Array> | undefined;
33
+ createDirectories(locator: string, path: string): Promise<void>;
34
+ openWriter(writer: number, locator: string, path: string): Promise<void>;
35
+ write(writer: number, offset: number, bytes: Uint8Array): Promise<void>;
36
+ finish(writer: number, size: number): Promise<void>;
37
+ abort(writer: number): Promise<void>;
38
+ shutdown(): void | Promise<void>;
39
+ }
3
40
  export interface HyperDBWasmModule {
4
41
  readonly HEAPU8: Uint8Array;
5
42
  getValue(pointer: number, type: string): number;
@@ -10,12 +47,16 @@ export interface HyperDBWasmModule {
10
47
  unlink(path: string): void;
11
48
  };
12
49
  resolveHyperDBPath?(path: string): string;
50
+ externalFileBackendAvailable?: boolean;
51
+ externalFileBackend?: ExternalFileBackend;
52
+ externalDirectoryBackend?: ExternalDirectoryBackend;
13
53
  _malloc(size: number): number | bigint;
14
54
  cwrap(name: string, returnType?: string | null, argumentTypes?: readonly string[]): CFunction;
15
55
  }
16
56
  export type BindingResponse = {
17
57
  response: WasmResponse;
18
58
  transfer: readonly ArrayBuffer[];
59
+ completion?: Promise<void>;
19
60
  };
20
61
  export declare class HyperDBBindings {
21
62
  private readonly module;
@@ -28,13 +69,18 @@ export declare class HyperDBBindings {
28
69
  private readonly checkpointDatabase;
29
70
  private readonly dropDatabase;
30
71
  private readonly shutdown;
72
+ private readonly registerExternalFile;
73
+ private readonly registerExternalDirectory;
74
+ private readonly removeExternalRegistration;
31
75
  private readonly attachDatabase;
32
76
  private readonly detachDatabase;
33
77
  private readonly startQuery;
78
+ private readonly startQueryWithInfo;
34
79
  private readonly insertArrowIPCFromPath;
35
80
  private readonly pollQuery;
36
81
  private readonly cancelQuery;
37
82
  private readonly releaseQuery;
83
+ private readonly releaseQueryWithInfo;
38
84
  private readonly resultState;
39
85
  private readonly resultPayloadLength;
40
86
  private readonly free;
@@ -11,6 +11,13 @@ export interface HyperDBWasmRuntimeModule extends HyperDBWasmModule {
11
11
  };
12
12
  _malloc(size: number): number | bigint;
13
13
  _hyperdb_wasm_fetch_complete(id: number, pointer: number, length: number): void;
14
+ _hyperdb_wasm_host_file_open_complete?(id: number, hostFileId: number, size: number): void;
15
+ _hyperdb_wasm_external_directory_list_complete?(id: number, paths: number, error: number): void;
16
+ _hyperdb_wasm_external_directory_open_complete?(id: number, locator: number, size: number): void;
17
+ _hyperdb_wasm_external_directory_create_directories_complete?(id: number, error: number): void;
18
+ _hyperdb_wasm_external_directory_writer_write_complete?(id: number, error: number): void;
19
+ _hyperdb_wasm_external_directory_writer_finish_complete?(id: number, error: number): void;
20
+ _hyperdb_wasm_external_directory_writer_abort_complete?(id: number, error: number): void;
14
21
  _hyperdb_wasm_http_complete(id: number, status: number, headersPointer: number, bodyPointer: number, bodyLength: number): void;
15
22
  stringToNewUTF8(value: string): number | bigint;
16
23
  NODEFS?: unknown;
@@ -23,7 +30,18 @@ export interface HyperDBWasmRuntimeModule extends HyperDBWasmModule {
23
30
  onAbort?: (reason: unknown) => void;
24
31
  locateFile?: (path: string, prefix: string) => string;
25
32
  instantiateWasm?: (imports: WebAssembly.Imports, receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void) => Record<string, never>;
26
- hyperdbWasmFetchStart?: (id: number, url: string, offset: number, length: number) => void;
33
+ hyperdbWasmFetchStart?: (id: number, url: string, offset: number, length: number, expectedSize: number) => void;
34
+ hyperdbWasmHostFileOpenStart?: (id: number, path: string) => void;
35
+ hyperdbWasmHostFileClose?: (id: number) => void;
36
+ hyperdbWasmHostDirectoryListStart?: (id: number, path: string) => void;
37
+ hyperdbWasmExternalDirectoryListStart?: (id: number, locator: string) => void;
38
+ hyperdbWasmExternalDirectoryOpenStart?: (id: number, locator: string, path: string) => void;
39
+ hyperdbWasmExternalDirectoryCreateDirectoriesStart?: (id: number, locator: string, path: string) => void;
40
+ hyperdbWasmExternalDirectoryWriterWriteStart?: (writer: number, id: number, locator: string, path: string, offset: number, pointer: number | bigint, length: number) => void;
41
+ hyperdbWasmExternalDirectoryWriterFinishStart?: (writer: number, id: number, locator: string, path: string, size: number) => void;
42
+ hyperdbWasmExternalDirectoryWriterAbortStart?: (writer: number, id: number) => void;
43
+ hyperdbWasmShouldOpenHostFile?: (path: string) => boolean;
44
+ hyperdbWasmShouldListHostDirectory?: (path: string) => boolean;
27
45
  hyperdbWasmHttpStart?: (id: number, method: string, url: string, headers: string, bodyPointer: number | bigint, bodyLength: number) => void;
28
46
  }
29
47
  export declare function configureWorker(module: HyperDBWasmRuntimeModule, transport: WorkerHostTransport, configureFilesystem?: (module: HyperDBWasmRuntimeModule) => void): void;
@@ -31,17 +31,17 @@
31
31
  await connection.attachDatabase('readings');
32
32
  await connection.attachDatabase(persistentName, 'sensors');
33
33
 
34
- await connection.queryIPC('create table readings.public.values_table(sensor_id integer, reading integer)');
35
- await connection.queryIPC('insert into readings.public.values_table values (101, 18), (202, 22)');
36
- await connection.queryIPC('create table sensors.public.locations(sensor_id integer, location text)');
37
- await connection.queryIPC("insert into sensors.public.locations values (101, 'office'), (202, 'lab')");
34
+ await connection.queryIPC('create table readings.public.values_table(sensor_id integer, reading integer)').result;
35
+ await connection.queryIPC('insert into readings.public.values_table values (101, 18), (202, 22)').result;
36
+ await connection.queryIPC('create table sensors.public.locations(sensor_id integer, location text)').result;
37
+ await connection.queryIPC("insert into sensors.public.locations values (101, 'office'), (202, 'lab')").result;
38
38
 
39
39
  const table = await connection.query(`
40
40
  select locations.location, values_table.reading
41
41
  from readings.public.values_table
42
42
  join sensors.public.locations using (sensor_id)
43
43
  order by locations.location
44
- `);
44
+ `).result;
45
45
  const names = table.schema.fields.map(({ name }) => name);
46
46
  const tableElement = document.createElement('table');
47
47
  const header = tableElement.createTHead().insertRow();
@@ -65,7 +65,7 @@ order by sensor_id</textarea>
65
65
  run.disabled = true;
66
66
  status.textContent = 'Running...';
67
67
  try {
68
- const table = await connection.query(sql.value);
68
+ const table = await connection.query(sql.value).result;
69
69
  render(table);
70
70
  status.textContent = `${table.numRows} row(s)`;
71
71
  } catch (error) {
@@ -3,8 +3,8 @@ import { mkdtemp, rm } from 'node:fs/promises';
3
3
  import { tmpdir } from 'node:os';
4
4
  import { join } from 'node:path';
5
5
 
6
- const hostPath = await mkdtemp(join(tmpdir(), 'hyperdb-wasm-attachments-'));
7
- const database = await HyperDB.create({ hostPath });
6
+ const storagePath = await mkdtemp(join(tmpdir(), 'hyperdb-wasm-attachments-'));
7
+ const database = await HyperDB.create({ storagePath });
8
8
  const connection = await database.connect();
9
9
 
10
10
  try {
@@ -13,17 +13,17 @@ try {
13
13
  await connection.attachDatabase('readings');
14
14
  await connection.attachDatabase('sensors');
15
15
 
16
- await connection.queryIPC('create table readings.public.values_table(sensor_id integer, reading integer)');
17
- await connection.queryIPC('insert into readings.public.values_table values (101, 18), (202, 22)');
18
- await connection.queryIPC('create table sensors.public.locations(sensor_id integer, location text)');
19
- await connection.queryIPC("insert into sensors.public.locations values (101, 'office'), (202, 'lab')");
16
+ await connection.queryIPC('create table readings.public.values_table(sensor_id integer, reading integer)').result;
17
+ await connection.queryIPC('insert into readings.public.values_table values (101, 18), (202, 22)').result;
18
+ await connection.queryIPC('create table sensors.public.locations(sensor_id integer, location text)').result;
19
+ await connection.queryIPC("insert into sensors.public.locations values (101, 'office'), (202, 'lab')").result;
20
20
 
21
21
  const result = await connection.query(`
22
22
  select locations.location, values_table.reading
23
23
  from readings.public.values_table
24
24
  join sensors.public.locations using (sensor_id)
25
25
  order by locations.location
26
- `);
26
+ `).result;
27
27
  console.table(result.toArray().map((row) => row.toJSON()));
28
28
  } finally {
29
29
  await connection.detachDatabase('readings');
@@ -32,5 +32,5 @@ try {
32
32
  await database.dropDatabase('readings');
33
33
  await database.dropDatabase('sensors');
34
34
  await database.terminate();
35
- await rm(hostPath, { recursive: true, force: true });
35
+ await rm(storagePath, { recursive: true, force: true });
36
36
  }
package/examples/node.mjs CHANGED
@@ -10,8 +10,9 @@ function rows(table) {
10
10
  ));
11
11
  }
12
12
 
13
- const temporaryDirectory = await mkdtemp(join(tmpdir(), 'hyperdb-wasm-'));
14
- const database = await HyperDB.create({ hostPath: temporaryDirectory });
13
+ const storageDirectory = await mkdtemp(join(tmpdir(), 'hyperdb-wasm-storage-'));
14
+ const inputDirectory = await mkdtemp(join(tmpdir(), 'hyperdb-wasm-input-'));
15
+ const database = await HyperDB.create({ storagePath: storageDirectory });
15
16
  const connection = await database.connect();
16
17
 
17
18
  try {
@@ -19,7 +20,7 @@ try {
19
20
  select
20
21
  6 * 7 as answer,
21
22
  upper('query Hyper from Node.js') as message
22
- `);
23
+ `).result;
23
24
  console.table(rows(expressions));
24
25
 
25
26
  const grouped = await connection.query(`
@@ -31,14 +32,14 @@ try {
31
32
  ) as readings(sensor_id, reading)
32
33
  group by sensor_id
33
34
  order by sensor_id
34
- `);
35
+ `).result;
35
36
  console.table(rows(grouped));
36
37
 
37
38
  const reader = await connection.send(`
38
39
  select value, value * value as square
39
40
  from generate_series(1, 5) as numbers(value)
40
41
  order by value
41
- `);
42
+ `).result;
42
43
  for await (const batch of reader) {
43
44
  console.log(`streamed Arrow batch with ${batch.numRows} rows`);
44
45
  }
@@ -53,16 +54,17 @@ try {
53
54
  sensor_id: new Int32Array([505, 606]),
54
55
  reading: new Int32Array([29, 31]),
55
56
  });
56
- const readingsPath = join(temporaryDirectory, 'arrow-readings.arrows');
57
+ const readingsPath = join(inputDirectory, 'arrow-readings.arrows');
57
58
  await writeFile(readingsPath, tableToIPC(temporaryReadings, 'stream'));
58
59
  await connection.insertArrowIPCFromPath(readingsPath, { name: 'temporary_readings' });
59
60
 
60
61
  console.log('Arrow IPC staged in the in-memory WasmFS:');
61
- console.table(rows(await connection.query('select * from memory_readings order by sensor_id')));
62
+ console.table(rows(await connection.query('select * from memory_readings order by sensor_id').result));
62
63
  console.log(`Arrow IPC read from the Node temporary file ${readingsPath}:`);
63
- console.table(rows(await connection.query('select * from temporary_readings order by sensor_id')));
64
+ console.table(rows(await connection.query('select * from temporary_readings order by sensor_id').result));
64
65
  } finally {
65
66
  await connection.close();
66
67
  await database.terminate();
67
- await rm(temporaryDirectory, { recursive: true, force: true });
68
+ await rm(storageDirectory, { recursive: true, force: true });
69
+ await rm(inputDirectory, { recursive: true, force: true });
68
70
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperdb-wasm",
3
- "version": "0.0.26792-dev.wasm.g72cc44c1",
3
+ "version": "0.0.26862-dev.wasm.g42f1012b",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"