hyperdb-wasm 0.0.26862-dev.wasm.g42f1012b → 0.0.26862-dev.wasm.g89537caa

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 CHANGED
@@ -9,15 +9,7 @@ export interface HyperDBClient {
9
9
  initialize(settings: string): Promise<WasmResult>;
10
10
  connect(): Promise<WasmResult>;
11
11
  disconnect(connection: number): Promise<WasmResult>;
12
- createDatabase(databaseName: string, persistent: boolean): Promise<WasmResult>;
13
- openDatabase(databaseName: string): Promise<WasmResult>;
14
- listDatabases(): Promise<WasmResult>;
15
- checkpointDatabase(databaseName: string): Promise<WasmResult>;
16
- dropDatabase(databaseName: string): Promise<WasmResult>;
17
- attachDatabase(connection: number, databaseName: string, alias: string): Promise<WasmResult>;
18
- detachDatabase(connection: number, alias: string): Promise<WasmResult>;
19
12
  startQuery(connection: number, sql: string): Promise<WasmResult>;
20
- startQueryWithInfo(connection: number, sql: string): Promise<WasmResult>;
21
13
  insertArrowIPCFromPath(connection: number, path: string, name: string, schema: string | null, create: boolean, internal?: boolean): Promise<WasmResult>;
22
14
  createTemporaryFile(bytes: Uint8Array): Promise<WasmResult>;
23
15
  removeFile(path: string): Promise<WasmResult>;
@@ -27,8 +19,7 @@ export interface HyperDBClient {
27
19
  removeExternalRegistration(path: string): Promise<WasmResult>;
28
20
  pollQuery(query: number): Promise<WasmResult>;
29
21
  cancelQuery(query: number): Promise<WasmResult>;
30
- releaseQuery(query: number): Promise<WasmResult>;
31
- releaseQueryWithInfo(query: number): Promise<WasmResult>;
22
+ finishQuery(query: number): Promise<WasmResult>;
32
23
  shutdown(): Promise<WasmResult>;
33
24
  terminate(): Promise<void>;
34
25
  }
@@ -37,9 +28,6 @@ export interface ArrowInsertOptions {
37
28
  readonly schema?: string;
38
29
  readonly create?: boolean;
39
30
  }
40
- export interface DatabaseCreateOptions {
41
- readonly storage?: 'transient' | 'persistent';
42
- }
43
31
  export interface ExternalFileRegistration {
44
32
  readonly name: string;
45
33
  readonly url: string;
@@ -60,10 +48,6 @@ export interface HyperDBCreateOptions {
60
48
  readonly settings?: HyperDBSettings;
61
49
  }
62
50
  export type BrowserCreateOptions = BrowserClientOptions & HyperDBCreateOptions;
63
- export interface DatabaseMetadata {
64
- readonly name: string;
65
- readonly storage: 'transient' | 'persistent';
66
- }
67
51
  export type QueryMetricValue = null | boolean | number | string | readonly QueryMetricValue[] | {
68
52
  readonly [key: string]: QueryMetricValue;
69
53
  };
@@ -114,14 +98,9 @@ export declare class HyperDB<ExternalFileArgs extends ExternalFileArguments = Br
114
98
  static create(options?: BrowserCreateOptions): Promise<HyperDB>;
115
99
  ready(): Promise<void>;
116
100
  connect(): Promise<HyperDBConnection>;
117
- createDatabase(databaseName: string, options?: DatabaseCreateOptions): Promise<void>;
118
- openDatabase(databaseName: string): Promise<void>;
119
- listDatabases(): Promise<DatabaseMetadata[]>;
120
101
  registerExternalFile(...args: ExternalFileArgs): Promise<string>;
121
102
  removeExternalRegistration(path: string): Promise<void>;
122
103
  protected registerExternalDirectorySource(source: unknown, mode: ExternalDirectoryMode): Promise<string>;
123
- checkpointDatabase(databaseName: string): Promise<void>;
124
- dropDatabase(databaseName: string): Promise<void>;
125
104
  terminate(): Promise<void>;
126
105
  private ensureRunning;
127
106
  protected runDatabaseOperation<Result>(operation: () => Promise<Result>): Promise<Result>;
@@ -135,8 +114,6 @@ export declare class HyperDBConnection {
135
114
  private closing;
136
115
  constructor(client: HyperDBClient, connection: number, onClose?: () => void);
137
116
  close(): Promise<void>;
138
- attachDatabase(databaseName: string, alias?: string): Promise<void>;
139
- detachDatabase(alias: string): Promise<void>;
140
117
  sendIPC(sql: string): QueryResult<AsyncIterable<Uint8Array>>;
141
118
  queryIPC(sql: string): QueryResult<Promise<Uint8Array>>;
142
119
  send<T extends TypeMap = {
@@ -149,8 +126,7 @@ export declare class HyperDBConnection {
149
126
  insertArrowIPCFromPath(path: string, options: ArrowInsertOptions): Promise<void>;
150
127
  private insertArrowIPCFromPathInternal;
151
128
  private ensureAvailable;
152
- private release;
153
- private releaseWithInfo;
129
+ private finishQuery;
154
130
  closeForTermination(): Promise<void>;
155
131
  }
156
132
  export type { HyperDBEngineClient };
package/dist/browser.d.ts CHANGED
@@ -11,6 +11,8 @@ export interface BrowserClientOptions {
11
11
  readonly workerUrl?: string | URL;
12
12
  readonly engineUrl?: string | URL;
13
13
  readonly wasmUrl?: string | URL;
14
+ /** OPFS-relative directory mounted as the durable filesystem root. */
15
+ readonly storagePath?: string;
14
16
  readonly onSetupProgress?: (progress: SetupProgress) => void;
15
17
  }
16
18
  type BrowserEnvironment = {
@@ -36,6 +38,6 @@ export declare class BrowserWorker implements WorkerTransport {
36
38
  onClose(): () => void;
37
39
  terminate(): void;
38
40
  }
39
- export declare function resolveBrowserWorkerUrl(workerUrl: string | URL, engineUrl: string | URL, wasmUrl?: string | URL): URL;
41
+ export declare function resolveBrowserWorkerUrl(workerUrl: string | URL, engineUrl: string | URL, wasmUrl?: string | URL, storagePath?: string): URL;
40
42
  export declare function createBrowserClient(options?: BrowserClientOptions): HyperDBEngineClient;
41
43
  export {};
package/dist/browser.js CHANGED
@@ -106,36 +106,12 @@ var init_client = __esm({
106
106
  disconnect(connection) {
107
107
  return this.request({ id: this.nextId++, type: "disconnect", connection });
108
108
  }
109
- createDatabase(databaseName, persistent) {
110
- return this.request({ id: this.nextId++, type: "createDatabase", databaseName, persistent });
111
- }
112
- openDatabase(databaseName) {
113
- return this.request({ id: this.nextId++, type: "openDatabase", databaseName });
114
- }
115
- listDatabases() {
116
- return this.request({ id: this.nextId++, type: "listDatabases" });
117
- }
118
- checkpointDatabase(databaseName) {
119
- return this.request({ id: this.nextId++, type: "checkpointDatabase", databaseName });
120
- }
121
- dropDatabase(databaseName) {
122
- return this.request({ id: this.nextId++, type: "dropDatabase", databaseName });
123
- }
124
- attachDatabase(connection, databaseName, alias) {
125
- return this.request({ id: this.nextId++, type: "attachDatabase", connection, databaseName, alias });
126
- }
127
- detachDatabase(connection, alias) {
128
- return this.request({ id: this.nextId++, type: "detachDatabase", connection, alias });
129
- }
130
109
  shutdown() {
131
110
  return this.request({ id: this.nextId++, type: "shutdown" });
132
111
  }
133
112
  startQuery(connection, sql, sqlTestMode = false) {
134
113
  return this.request({ id: this.nextId++, type: "startQuery", connection, sql, ...sqlTestMode && { sqlTestMode } });
135
114
  }
136
- startQueryWithInfo(connection, sql) {
137
- return this.request({ id: this.nextId++, type: "startQueryWithInfo", connection, sql });
138
- }
139
115
  insertArrowIPCFromPath(connection, path, name, schema, create, internal = false) {
140
116
  return this.request({ id: this.nextId++, type: "insertArrowIPCFromPath", connection, path, name, schema, create, internal });
141
117
  }
@@ -161,11 +137,8 @@ var init_client = __esm({
161
137
  cancelQuery(query) {
162
138
  return this.request({ id: this.nextId++, type: "cancelQuery", query });
163
139
  }
164
- releaseQuery(query) {
165
- return this.request({ id: this.nextId++, type: "releaseQuery", query });
166
- }
167
- releaseQueryWithInfo(query) {
168
- return this.request({ id: this.nextId++, type: "releaseQueryWithInfo", query });
140
+ finishQuery(query) {
141
+ return this.request({ id: this.nextId++, type: "finishQuery", query });
169
142
  }
170
143
  async terminate() {
171
144
  await this.transport.terminate();
@@ -258,10 +231,11 @@ function assertBrowserSupport(environment = globalThis) {
258
231
  throw new Error("HyperDB cannot initialize because this browser does not support the origin-private file system");
259
232
  }
260
233
  }
261
- function resolveBrowserWorkerUrl(workerUrl, engineUrl, wasmUrl) {
234
+ function resolveBrowserWorkerUrl(workerUrl, engineUrl, wasmUrl, storagePath) {
262
235
  const resolved = new URL(workerUrl);
263
236
  resolved.searchParams.set("engineUrl", new URL(engineUrl).href);
264
237
  if (wasmUrl != null) resolved.searchParams.set("wasmUrl", new URL(wasmUrl).href);
238
+ if (storagePath != null) resolved.searchParams.set("storagePath", storagePath);
265
239
  return resolved;
266
240
  }
267
241
  function createBrowserClient(options = {}) {
@@ -269,7 +243,7 @@ function createBrowserClient(options = {}) {
269
243
  const workerUrl = options.workerUrl ?? new URL("./browser_worker.js", import.meta.url);
270
244
  const engineUrl = options.engineUrl ?? new URL("./hyperdb-wasm.js", import.meta.url);
271
245
  return new HyperDBEngineClient(
272
- new BrowserWorker(new Worker(resolveBrowserWorkerUrl(workerUrl, engineUrl, options.wasmUrl), { type: "classic" })),
246
+ new BrowserWorker(new Worker(resolveBrowserWorkerUrl(workerUrl, engineUrl, options.wasmUrl, options.storagePath), { type: "classic" })),
273
247
  options.onSetupProgress
274
248
  );
275
249
  }
@@ -12166,7 +12140,6 @@ var HyperDBError = class extends Error {
12166
12140
  this.hint = hint;
12167
12141
  }
12168
12142
  };
12169
- var maxPersistentDatabaseNameLength = 200;
12170
12143
  function deferred() {
12171
12144
  let resolve;
12172
12145
  let reject;
@@ -12222,26 +12195,6 @@ function normalizeArrowInsertOptions(options) {
12222
12195
  if (!options.name) throw new Error("Arrow insert table name must not be empty");
12223
12196
  return { name: options.name, schema: options.schema ?? null, create: options.create ?? true };
12224
12197
  }
12225
- function validateDatabaseName(databaseName) {
12226
- if (!databaseName) throw new Error("Database name must not be empty");
12227
- if (databaseName.includes("\0")) throw new Error("Database name must not contain NUL");
12228
- }
12229
- function validatePersistentDatabaseName(databaseName) {
12230
- validateDatabaseName(databaseName);
12231
- if (databaseName.length > maxPersistentDatabaseNameLength) {
12232
- throw new Error(`Persistent database name must be at most ${maxPersistentDatabaseNameLength} characters`);
12233
- }
12234
- if (!/^[a-z0-9][a-z0-9_-]*$/.test(databaseName)) {
12235
- throw new Error("Persistent database name must start with a lowercase ASCII letter or digit and contain only lowercase ASCII letters, digits, hyphens, and underscores");
12236
- }
12237
- if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/.test(databaseName)) {
12238
- throw new Error("Persistent database name is reserved by Windows");
12239
- }
12240
- }
12241
- function validateDatabaseAlias(alias) {
12242
- if (!alias) throw new Error("Database alias must not be empty");
12243
- if (alias.includes("\0")) throw new Error("Database alias must not contain NUL");
12244
- }
12245
12198
  function materializeDictionaryColumns(table) {
12246
12199
  const dictionaryColumns = table.schema.fields.map((field, index) => DataType.isDictionary(field.type) ? index : -1).filter((index) => index !== -1);
12247
12200
  if (dictionaryColumns.length === 0) return table;
@@ -12282,34 +12235,6 @@ async function initializeHyperDB(client, settings) {
12282
12235
  if (serialized === void 0) throw new Error("HyperDB settings must be JSON-serializable");
12283
12236
  expectOk(await client.initialize(serialized), "initialize HyperDB settings");
12284
12237
  }
12285
- function readDatabasesFromResult(result) {
12286
- expectOk(result, "list databases");
12287
- const invalidResult = () => new Error("list databases returned invalid metadata");
12288
- if (result.payload.byteLength < 4) throw invalidResult();
12289
- const view = new DataView(result.payload.buffer, result.payload.byteOffset, result.payload.byteLength);
12290
- const count = view.getUint32(0, true);
12291
- let offset = 4;
12292
- const databases = [];
12293
- const decoder2 = new TextDecoder("utf-8", { fatal: true });
12294
- for (let index = 0; index < count; ++index) {
12295
- if (offset + 8 > result.payload.byteLength) throw invalidResult();
12296
- const rawStorage = view.getUint32(offset, true);
12297
- const nameLength = view.getUint32(offset + 4, true);
12298
- offset += 8;
12299
- if (nameLength > result.payload.byteLength - offset) throw invalidResult();
12300
- let name;
12301
- try {
12302
- name = decoder2.decode(result.payload.subarray(offset, offset + nameLength));
12303
- } catch {
12304
- throw invalidResult();
12305
- }
12306
- if (!name || name.includes("\0") || rawStorage !== 0 && rawStorage !== 1) throw invalidResult();
12307
- databases.push({ name, storage: rawStorage === 0 ? "transient" : "persistent" });
12308
- offset += nameLength;
12309
- }
12310
- if (offset !== result.payload.byteLength) throw invalidResult();
12311
- return databases;
12312
- }
12313
12238
  function yieldToEventLoop() {
12314
12239
  return new Promise((resolve) => setTimeout(resolve, 0));
12315
12240
  }
@@ -12349,25 +12274,6 @@ var HyperDB = class _HyperDB {
12349
12274
  this.connections.add(result);
12350
12275
  return result;
12351
12276
  }
12352
- async createDatabase(databaseName, options = {}) {
12353
- validateDatabaseName(databaseName);
12354
- if (options.storage !== void 0 && options.storage !== "transient" && options.storage !== "persistent") {
12355
- throw new Error(`Unsupported database storage: ${String(options.storage)}`);
12356
- }
12357
- if (options.storage === "persistent") validatePersistentDatabaseName(databaseName);
12358
- await this.runDatabaseOperation(async () => {
12359
- expectOk(await this.client.createDatabase(databaseName, options.storage === "persistent"), "create database");
12360
- });
12361
- }
12362
- async openDatabase(databaseName) {
12363
- validatePersistentDatabaseName(databaseName);
12364
- await this.runDatabaseOperation(async () => {
12365
- expectOk(await this.client.openDatabase(databaseName), "open database");
12366
- });
12367
- }
12368
- listDatabases() {
12369
- return this.runDatabaseOperation(async () => readDatabasesFromResult(await this.client.listDatabases()));
12370
- }
12371
12277
  async registerExternalFile(...args) {
12372
12278
  if (args.length === 1) {
12373
12279
  const [sourcePath] = args;
@@ -12419,18 +12325,6 @@ var HyperDB = class _HyperDB {
12419
12325
  return path;
12420
12326
  });
12421
12327
  }
12422
- async checkpointDatabase(databaseName) {
12423
- validateDatabaseName(databaseName);
12424
- await this.runDatabaseOperation(async () => {
12425
- expectOk(await this.client.checkpointDatabase(databaseName), "checkpoint database");
12426
- });
12427
- }
12428
- async dropDatabase(databaseName) {
12429
- validateDatabaseName(databaseName);
12430
- await this.runDatabaseOperation(async () => {
12431
- expectOk(await this.client.dropDatabase(databaseName), "drop database");
12432
- });
12433
- }
12434
12328
  async terminate() {
12435
12329
  if (this.terminated) return;
12436
12330
  if (this.activeDatabaseOperations !== 0) throw new Error("database has an active operation");
@@ -12502,25 +12396,6 @@ var HyperDBConnection = class {
12502
12396
  }
12503
12397
  await this.closing;
12504
12398
  }
12505
- async attachDatabase(databaseName, alias = databaseName) {
12506
- validateDatabaseName(databaseName);
12507
- validateDatabaseAlias(alias);
12508
- this.ensureAvailable();
12509
- try {
12510
- expectOk(await this.client.attachDatabase(this.connection, databaseName, alias), "attach database");
12511
- } finally {
12512
- this.active = false;
12513
- }
12514
- }
12515
- async detachDatabase(alias) {
12516
- validateDatabaseAlias(alias);
12517
- this.ensureAvailable();
12518
- try {
12519
- expectOk(await this.client.detachDatabase(this.connection, alias), "detach database");
12520
- } finally {
12521
- this.active = false;
12522
- }
12523
- }
12524
12399
  sendIPC(sql) {
12525
12400
  const connection = this;
12526
12401
  const queryInfo = deferred();
@@ -12532,7 +12407,7 @@ var HyperDBConnection = class {
12532
12407
  try {
12533
12408
  connection.ensureAvailable();
12534
12409
  acquired = true;
12535
- query = readHandleFromResult(await connection.client.startQueryWithInfo(connection.connection, sql), "start query");
12410
+ query = readHandleFromResult(await connection.client.startQuery(connection.connection, sql), "start query");
12536
12411
  for (; ; ) {
12537
12412
  let result2 = prefetched ? await prefetched : await connection.client.pollQuery(query);
12538
12413
  prefetched = void 0;
@@ -12574,7 +12449,7 @@ var HyperDBConnection = class {
12574
12449
  }
12575
12450
  }
12576
12451
  try {
12577
- info = await connection.releaseWithInfo(query);
12452
+ info = decodeQueryInfo(await connection.finishQuery(query));
12578
12453
  } catch (error) {
12579
12454
  cleanupError ??= error;
12580
12455
  }
@@ -12667,7 +12542,7 @@ var HyperDBConnection = class {
12667
12542
  }
12668
12543
  } finally {
12669
12544
  try {
12670
- if (query !== void 0) await this.release(query);
12545
+ if (query !== void 0) await this.finishQuery(query);
12671
12546
  } finally {
12672
12547
  if (acquire) this.active = false;
12673
12548
  }
@@ -12681,22 +12556,12 @@ var HyperDBConnection = class {
12681
12556
  }
12682
12557
  this.active = true;
12683
12558
  }
12684
- async release(query) {
12685
- let delay = 1;
12686
- for (; ; ) {
12687
- const result = await this.client.releaseQuery(query);
12688
- if (result.state === "ok") return;
12689
- if (result.state !== "pending") throw readErrorFromResult(result, "release query");
12690
- await new Promise((resolve) => setTimeout(resolve, delay));
12691
- delay = Math.min(delay * 2, 32);
12692
- }
12693
- }
12694
- async releaseWithInfo(query) {
12559
+ async finishQuery(query) {
12695
12560
  let delay = 1;
12696
12561
  for (; ; ) {
12697
- const result = await this.client.releaseQueryWithInfo(query);
12698
- if (result.state === "ok") return decodeQueryInfo(result.payload);
12699
- if (result.state !== "pending") throw readErrorFromResult(result, "release query");
12562
+ const result = await this.client.finishQuery(query);
12563
+ if (result.state === "ok") return result.payload;
12564
+ if (result.state !== "pending") throw readErrorFromResult(result, "finish query");
12700
12565
  await new Promise((resolve) => setTimeout(resolve, delay));
12701
12566
  delay = Math.min(delay * 2, 32);
12702
12567
  }
@@ -48,51 +48,33 @@
48
48
  initialize;
49
49
  connect;
50
50
  disconnect;
51
- createDatabase;
52
- openDatabase;
53
- listDatabases;
54
- checkpointDatabase;
55
- dropDatabase;
56
51
  shutdown;
57
52
  registerExternalFile;
58
53
  registerExternalDirectory;
59
54
  removeExternalRegistration;
60
- attachDatabase;
61
- detachDatabase;
62
55
  startQuery;
63
- startQueryWithInfo;
64
56
  insertArrowIPCFromPath;
65
57
  pollQuery;
66
58
  cancelQuery;
67
- releaseQuery;
68
- releaseQueryWithInfo;
59
+ finishQuery;
69
60
  resultState;
70
61
  resultPayloadLength;
71
62
  free;
72
63
  nextTemporaryFile = 1;
73
64
  constructor(module) {
74
65
  this.module = module;
75
- this.initialize = module.cwrap("hyperdb_wasm_initialize", "pointer", ["string"]);
66
+ this.initialize = module.cwrap("hyperdb_wasm_initialize", "pointer", ["string", "string"]);
76
67
  this.connect = module.cwrap("hyperdb_wasm_connect", "pointer", []);
77
68
  this.disconnect = module.cwrap("hyperdb_wasm_disconnect", "pointer", ["number"]);
78
- this.createDatabase = module.cwrap("hyperdb_wasm_create_database", "pointer", ["string", "number"]);
79
- this.openDatabase = module.cwrap("hyperdb_wasm_open_database", "pointer", ["string"]);
80
- this.listDatabases = module.cwrap("hyperdb_wasm_list_databases", "pointer", []);
81
- this.checkpointDatabase = module.cwrap("hyperdb_wasm_checkpoint_database", "pointer", ["string"]);
82
- this.dropDatabase = module.cwrap("hyperdb_wasm_drop_database", "pointer", ["string"]);
83
69
  this.shutdown = module.cwrap("hyperdb_wasm_shutdown", "pointer", []);
84
70
  this.registerExternalFile = module.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number"]);
85
71
  this.registerExternalDirectory = module.cwrap("hyperdb_wasm_register_external_directory", "pointer", ["string", "string", "number"]);
86
72
  this.removeExternalRegistration = module.cwrap("hyperdb_wasm_remove_external_registration", "pointer", ["string"]);
87
- this.attachDatabase = module.cwrap("hyperdb_wasm_attach_database", "pointer", ["number", "string", "string"]);
88
- this.detachDatabase = module.cwrap("hyperdb_wasm_detach_database", "pointer", ["number", "string"]);
89
73
  this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string", "number"]);
90
- this.startQueryWithInfo = module.cwrap("hyperdb_wasm_query_start_with_info", "pointer", ["number", "string"]);
91
74
  this.insertArrowIPCFromPath = module.cwrap("hyperdb_wasm_arrow_insert_from_path", "pointer", ["number", "string", "string", "string", "number"]);
92
75
  this.pollQuery = module.cwrap("hyperdb_wasm_query_poll", "pointer", ["number"]);
93
76
  this.cancelQuery = module.cwrap("hyperdb_wasm_query_cancel", "pointer", ["number"]);
94
- this.releaseQuery = module.cwrap("hyperdb_wasm_query_release", "pointer", ["number"]);
95
- this.releaseQueryWithInfo = module.cwrap("hyperdb_wasm_query_release_with_info", "pointer", ["number"]);
77
+ this.finishQuery = module.cwrap("hyperdb_wasm_query_finish", "pointer", ["number"]);
96
78
  this.resultState = module.cwrap("hyperdb_wasm_result_state", "number", ["number"]);
97
79
  this.resultPayloadLength = module.cwrap("hyperdb_wasm_result_payload_len", "number", ["number"]);
98
80
  this.free = module.cwrap("hyperdb_wasm_free", null, ["pointer"]);
@@ -201,32 +183,11 @@
201
183
  switch (request.type) {
202
184
  case "initialize":
203
185
  validateCString(request.settings, "settings");
204
- return this.initialize(request.settings);
186
+ return this.initialize(request.settings, this.module.hyperdbWasmStoragePath ?? "");
205
187
  case "connect":
206
188
  return this.connect();
207
189
  case "disconnect":
208
190
  return this.disconnect(request.connection);
209
- case "createDatabase":
210
- validateCString(request.databaseName, "database name");
211
- return this.createDatabase(request.databaseName, Number(request.persistent));
212
- case "openDatabase":
213
- validateCString(request.databaseName, "database name");
214
- return this.openDatabase(request.databaseName);
215
- case "listDatabases":
216
- return this.listDatabases();
217
- case "checkpointDatabase":
218
- validateCString(request.databaseName, "database name");
219
- return this.checkpointDatabase(request.databaseName);
220
- case "dropDatabase":
221
- validateCString(request.databaseName, "database name");
222
- return this.dropDatabase(request.databaseName);
223
- case "attachDatabase":
224
- validateCString(request.databaseName, "database name");
225
- validateCString(request.alias, "database alias");
226
- return this.attachDatabase(request.connection, request.databaseName, request.alias);
227
- case "detachDatabase":
228
- validateCString(request.alias, "database alias");
229
- return this.detachDatabase(request.connection, request.alias);
230
191
  case "shutdown":
231
192
  return this.shutdown();
232
193
  case "registerExternalFile":
@@ -241,8 +202,6 @@
241
202
  return this.removeExternalRegistration(request.path);
242
203
  case "startQuery":
243
204
  return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false));
244
- case "startQueryWithInfo":
245
- return this.startQueryWithInfo(request.connection, request.sql);
246
205
  case "insertArrowIPCFromPath": {
247
206
  const path = request.internal ? request.path : this.module.resolveHyperDBPath?.(request.path) ?? request.path;
248
207
  return this.insertArrowIPCFromPath(request.connection, path, request.name, request.schema ?? "", Number(request.create));
@@ -251,10 +210,8 @@
251
210
  return this.pollQuery(request.query);
252
211
  case "cancelQuery":
253
212
  return this.cancelQuery(request.query);
254
- case "releaseQuery":
255
- return this.releaseQuery(request.query);
256
- case "releaseQueryWithInfo":
257
- return this.releaseQueryWithInfo(request.query);
213
+ case "finishQuery":
214
+ return this.finishQuery(request.query);
258
215
  }
259
216
  }
260
217
  decodeResult(pointer) {
@@ -308,26 +265,13 @@
308
265
  case "initialize":
309
266
  return hasKeys(value, ["id", "type", "settings"]) && typeof value.settings === "string";
310
267
  case "connect":
311
- case "listDatabases":
312
268
  return hasKeys(value, ["id", "type"]);
313
269
  case "disconnect":
314
270
  return hasKeys(value, ["id", "type", "connection"]) && Number.isSafeInteger(value.connection);
315
- case "createDatabase":
316
- return hasKeys(value, ["id", "type", "databaseName", "persistent"]) && typeof value.databaseName === "string" && typeof value.persistent === "boolean";
317
- case "openDatabase":
318
- case "checkpointDatabase":
319
- case "dropDatabase":
320
- return hasKeys(value, ["id", "type", "databaseName"]) && typeof value.databaseName === "string";
321
271
  case "shutdown":
322
272
  return hasKeys(value, ["id", "type"]);
323
- case "attachDatabase":
324
- return hasKeys(value, ["id", "type", "connection", "databaseName", "alias"]) && Number.isSafeInteger(value.connection) && typeof value.databaseName === "string" && typeof value.alias === "string";
325
- case "detachDatabase":
326
- return hasKeys(value, ["id", "type", "connection", "alias"]) && Number.isSafeInteger(value.connection) && typeof value.alias === "string";
327
273
  case "startQuery":
328
274
  return (hasKeys(value, ["id", "type", "connection", "sql"]) || hasKeys(value, ["id", "type", "connection", "sql", "sqlTestMode"])) && Number.isSafeInteger(value.connection) && typeof value.sql === "string" && (value.sqlTestMode === void 0 || typeof value.sqlTestMode === "boolean");
329
- case "startQueryWithInfo":
330
- return hasKeys(value, ["id", "type", "connection", "sql"]) && Number.isSafeInteger(value.connection) && typeof value.sql === "string";
331
275
  case "insertArrowIPCFromPath":
332
276
  return hasKeys(value, ["id", "type", "connection", "path", "name", "schema", "create", "internal"]) && Number.isSafeInteger(value.connection) && typeof value.path === "string" && typeof value.name === "string" && (typeof value.schema === "string" || value.schema === null) && typeof value.create === "boolean" && typeof value.internal === "boolean";
333
277
  case "createTemporaryFile":
@@ -342,8 +286,7 @@
342
286
  return hasKeys(value, ["id", "type", "path"]) && typeof value.path === "string";
343
287
  case "pollQuery":
344
288
  case "cancelQuery":
345
- case "releaseQuery":
346
- case "releaseQueryWithInfo":
289
+ case "finishQuery":
347
290
  return hasKeys(value, ["id", "type", "query"]) && Number.isSafeInteger(value.query);
348
291
  default:
349
292
  return false;
@@ -846,6 +789,21 @@
846
789
  var resolvedEngineUrl = new URL(engineUrl, self.location.href);
847
790
  var configuredWasmUrl = new URL(self.location.href).searchParams.get("wasmUrl");
848
791
  var resolvedWasmUrl = configuredWasmUrl == null ? new URL("hyperdb-wasm.wasm.br", resolvedEngineUrl) : new URL(configuredWasmUrl);
792
+ var configuredStoragePath = new URL(self.location.href).searchParams.get("storagePath") ?? "";
793
+ function normalizeStoragePath(path) {
794
+ const parts = [];
795
+ for (const part of path.replace(/^\/+/, "").split("/")) {
796
+ if (!part || part === ".") continue;
797
+ if (part === "..") {
798
+ if (parts.length === 0) throw new Error(`Storage path is outside the OPFS root: ${path}`);
799
+ parts.pop();
800
+ } else {
801
+ parts.push(part);
802
+ }
803
+ }
804
+ return parts.join("/");
805
+ }
806
+ var storagePath = normalizeStoragePath(configuredStoragePath);
849
807
  function isPthreadWorker() {
850
808
  const location = self.location;
851
809
  return self.name === "em-pthread" || location.search?.includes("pthread") === true;
@@ -889,24 +847,14 @@
889
847
  runtime.externalFileBackendAvailable = true;
890
848
  runtime.externalDirectoryBackend = new BrowserExternalDirectoryBackend();
891
849
  if (!runtime.OPFS) throw new Error("OPFS backend is unavailable");
892
- runtime.FS.mkdirTree("/opfs");
893
- runtime.FS.mount(runtime.OPFS, {}, "/opfs");
894
- runtime.FS.mkdirTree("/hyperdb-persistent");
895
- runtime.FS.mount(runtime.OPFS, {}, "/hyperdb-persistent");
896
- runtime.FS.mkdirTree("/hyperdb-persistent/hyperdb");
897
- runtime.FS.mkdirTree("/hyperdb-persistent/logs");
850
+ runtime.FS.mkdirTree("/mnt/fs");
851
+ runtime.FS.mount(runtime.OPFS, {}, "/mnt/fs");
852
+ if (storagePath) runtime.FS.mkdirTree(`/mnt/fs/${storagePath}`);
853
+ runtime.FS.mkdirTree(`${storagePath ? `/mnt/fs/${storagePath}` : "/mnt/fs"}/logs`);
854
+ runtime.hyperdbWasmStoragePath = storagePath;
898
855
  runtime.resolveHyperDBPath = (path) => {
899
- const parts = [];
900
- for (const part of path.replace(/^\/+/, "").split("/")) {
901
- if (!part || part === ".") continue;
902
- if (part === "..") {
903
- if (parts.length === 0) throw new Error(`Arrow IPC path is outside the OPFS root: ${path}`);
904
- parts.pop();
905
- } else {
906
- parts.push(part);
907
- }
908
- }
909
- return `/opfs/${parts.join("/")}`;
856
+ const relativePath = normalizeStoragePath(path);
857
+ return `${storagePath ? `/mnt/fs/${storagePath}` : "/mnt/fs"}/${relativePath}`;
910
858
  };
911
859
  });
912
860
  self.importScripts(resolvedEngineUrl.href);
package/dist/client.d.ts CHANGED
@@ -14,16 +14,8 @@ export declare class HyperDBEngineClient {
14
14
  initialize(settings: string): Promise<WasmResult>;
15
15
  connect(): Promise<WasmResult>;
16
16
  disconnect(connection: number): Promise<WasmResult>;
17
- createDatabase(databaseName: string, persistent: boolean): Promise<WasmResult>;
18
- openDatabase(databaseName: string): Promise<WasmResult>;
19
- listDatabases(): Promise<WasmResult>;
20
- checkpointDatabase(databaseName: string): Promise<WasmResult>;
21
- dropDatabase(databaseName: string): Promise<WasmResult>;
22
- attachDatabase(connection: number, databaseName: string, alias: string): Promise<WasmResult>;
23
- detachDatabase(connection: number, alias: string): Promise<WasmResult>;
24
17
  shutdown(): Promise<WasmResult>;
25
18
  startQuery(connection: number, sql: string, sqlTestMode?: boolean): Promise<WasmResult>;
26
- startQueryWithInfo(connection: number, sql: string): Promise<WasmResult>;
27
19
  insertArrowIPCFromPath(connection: number, path: string, name: string, schema: string | null, create: boolean, internal?: boolean): Promise<WasmResult>;
28
20
  createTemporaryFile(bytes: Uint8Array): Promise<WasmResult>;
29
21
  removeFile(path: string): Promise<WasmResult>;
@@ -33,8 +25,7 @@ export declare class HyperDBEngineClient {
33
25
  removeExternalRegistration(path: string): Promise<WasmResult>;
34
26
  pollQuery(query: number): Promise<WasmResult>;
35
27
  cancelQuery(query: number): Promise<WasmResult>;
36
- releaseQuery(query: number): Promise<WasmResult>;
37
- releaseQueryWithInfo(query: number): Promise<WasmResult>;
28
+ finishQuery(query: number): Promise<WasmResult>;
38
29
  terminate(): Promise<void>;
39
30
  private request;
40
31
  private onMessage;