hyperdb-wasm 0.0.27136-dev.wasm.g077c0cd8 → 0.0.27136-dev.wasm.g5f4b267e

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.
@@ -2,7 +2,7 @@
2
2
  import { closeSync, createReadStream, fstatSync, openSync, read, statSync } from "node:fs";
3
3
  import { opendir as opendir2, stat } from "node:fs/promises";
4
4
  import { createRequire } from "node:module";
5
- import { basename as basename2, dirname, isAbsolute as isAbsolute2, join as join2, resolve as resolve2 } from "node:path";
5
+ import { basename as basename2, dirname, isAbsolute as isAbsolute2, join as join2, posix, resolve as resolve2 } from "node:path";
6
6
  import { randomUUID as randomUUID2 } from "node:crypto";
7
7
  import { Readable } from "node:stream";
8
8
  import { parentPort, workerData } from "node:worker_threads";
@@ -70,6 +70,7 @@ var HyperDBBindings = class {
70
70
  registerExternalFile;
71
71
  registerExternalDirectory;
72
72
  removeExternalRegistration;
73
+ refreshExternalDirectory;
73
74
  projectExternalFile;
74
75
  projectExternalDirectory;
75
76
  startQuery;
@@ -80,6 +81,7 @@ var HyperDBBindings = class {
80
81
  resultPayloadLength;
81
82
  free;
82
83
  mountedPaths = /* @__PURE__ */ new Set();
84
+ mountedDirectoryPaths = /* @__PURE__ */ new Set();
83
85
  constructor(module2) {
84
86
  this.module = module2;
85
87
  this.initialize = module2.cwrap("hyperdb_wasm_initialize", "pointer", ["string", "string", "number"]);
@@ -89,6 +91,7 @@ var HyperDBBindings = class {
89
91
  this.registerExternalFile = module2.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number", "number"]);
90
92
  this.registerExternalDirectory = module2.cwrap("hyperdb_wasm_register_external_directory", "pointer", ["string", "string", "number", "number"]);
91
93
  this.removeExternalRegistration = module2.cwrap("hyperdb_wasm_remove_external_registration", "pointer", ["string", "number"]);
94
+ this.refreshExternalDirectory = module2.cwrap("hyperdb_wasm_refresh_external_directory", "pointer", ["string", "number"]);
92
95
  this.projectExternalFile = module2.cwrap("hyperdb_wasm_project_external_file", "pointer", ["string", "string", "number", "number"]);
93
96
  this.projectExternalDirectory = module2.cwrap("hyperdb_wasm_project_external_directory", "pointer", ["string", "string", "number"]);
94
97
  this.startQuery = module2.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string", "number", "number"]);
@@ -117,11 +120,22 @@ var HyperDBBindings = class {
117
120
  if (request.type === "mount" && request.source.kind === "browser-file") {
118
121
  return this.mountFile(request, request.source.url, safeInteger(request.source.size, "external file size"));
119
122
  }
123
+ if (request.type === "refreshMount") {
124
+ validateCString(request.path, "external registration path");
125
+ const backend = this.module.externalDirectoryBackend;
126
+ if (!backend) return { response: { id: request.id, type: "response", result: { state: "error", error: "External directories are not supported by this client" } }, transfer: [] };
127
+ if (!this.mountedDirectoryPaths.has(request.path)) {
128
+ const error = this.mountedPaths.has(request.path) ? "Only directory mounts can be refreshed" : "External directory registration was not found";
129
+ return { response: { id: request.id, type: "response", result: { state: "error", error } }, transfer: [] };
130
+ }
131
+ backend.refresh(request.path);
132
+ }
120
133
  if (request.type === "unmount" && (this.module.externalFileBackend || this.module.externalDirectoryBackend)) {
121
134
  validateCString(request.path, "external registration path");
122
135
  const pointer2 = safeInteger(this.removeExternalRegistration(request.path, request.id), "result pointer");
123
136
  const result2 = this.decodeResult(pointer2);
124
137
  if (result2.state === "ok" || result2.state === "error" && result2.error === "External registration was not found" && this.mountedPaths.has(request.path)) {
138
+ this.mountedDirectoryPaths.delete(request.path);
125
139
  const cleanup = async () => {
126
140
  await Promise.all([
127
141
  this.module.externalFileBackend?.removed(request.path),
@@ -139,6 +153,8 @@ var HyperDBBindings = class {
139
153
  const pointer = safeInteger(this.invoke(request), "result pointer");
140
154
  const result = this.decodeResult(pointer);
141
155
  if (request.type === "shutdown" && result.state === "ok") {
156
+ this.mountedPaths.clear();
157
+ this.mountedDirectoryPaths.clear();
142
158
  const completion = completionFor([
143
159
  this.module.externalFileBackend?.shutdown(),
144
160
  this.module.externalDirectoryBackend?.shutdown()
@@ -150,6 +166,7 @@ var HyperDBBindings = class {
150
166
  };
151
167
  }
152
168
  const response = { id: request.id, type: "response", result };
169
+ if (request.type === "unmount" && result.state === "ok") this.mountedPaths.delete(request.path);
153
170
  return { response, transfer: result.state === "chunk" ? [result.payload.buffer] : [] };
154
171
  }
155
172
  invoke(request) {
@@ -173,6 +190,8 @@ var HyperDBBindings = class {
173
190
  case "unmount":
174
191
  validateCString(request.path, "external registration path");
175
192
  return this.removeExternalRegistration(request.path, request.id);
193
+ case "refreshMount":
194
+ return this.refreshExternalDirectory(request.path, request.id);
176
195
  case "startQuery":
177
196
  validateCStringContents(request.sql, "SQL");
178
197
  return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false), request.id);
@@ -243,12 +262,14 @@ var HyperDBBindings = class {
243
262
  if (projection.state !== "ok") throw new Error(resultError(projection));
244
263
  backend.registered(path, registration.locator);
245
264
  this.mountedPaths.add(path);
265
+ this.mountedDirectoryPaths.add(path);
246
266
  } catch (error) {
247
267
  const cleanupPointer = safeInteger(this.removeExternalRegistration(path, request.id), "result pointer");
248
268
  const cleanup = this.decodeResult(cleanupPointer);
249
269
  if (cleanup.state !== "ok") {
250
270
  backend.registered(path, registration.locator);
251
271
  this.mountedPaths.add(path);
272
+ this.mountedDirectoryPaths.add(path);
252
273
  preserveBackend = true;
253
274
  throw new Error(`mount failed and rollback also failed: ${resultError(cleanup)}`, { cause: error });
254
275
  }
@@ -352,6 +373,7 @@ function isEngineRequest(value) {
352
373
  }
353
374
  }
354
375
  case "unmount":
376
+ case "refreshMount":
355
377
  return hasKeys(value, ["id", "type", "path"]) && typeof value.path === "string" && !!value.path && !value.path.includes("\0");
356
378
  case "pollQuery":
357
379
  case "cancelQuery":
@@ -449,9 +471,14 @@ function installHttpRuntime(module2, transport2) {
449
471
  };
450
472
  module2.hyperdbWasmFetchCancel = (id) => fetches.get(id)?.abort();
451
473
  }
452
- function installExternalDirectoryRuntime(module2) {
474
+ function installExternalDirectoryRuntime(module2, transport2) {
453
475
  const backend = module2.externalDirectoryBackend;
454
476
  if (!backend) return;
477
+ module2.hyperdbWasmExternalDirectoryReleaseGeneration = (locator, generation) => {
478
+ void Promise.resolve().then(() => backend.releaseGeneration(locator, generation)).catch(() => {
479
+ transport2.postMessage({ type: "log", text: "External directory generation cleanup failed; mount removal will retry" });
480
+ });
481
+ };
455
482
  const listComplete = module2._hyperdb_wasm_external_directory_list_complete;
456
483
  const openComplete = module2._hyperdb_wasm_external_directory_open_complete;
457
484
  if (listComplete) {
@@ -464,8 +491,8 @@ function installExternalDirectoryRuntime(module2) {
464
491
  };
465
492
  }
466
493
  if (openComplete) {
467
- module2.hyperdbWasmExternalDirectoryOpenStart = (id, locator, path) => {
468
- void backend.open(locator, path).then((file) => {
494
+ module2.hyperdbWasmExternalDirectoryOpenStart = (id, locator, path, generation) => {
495
+ void backend.open(locator, path, generation).then((file) => {
469
496
  openComplete(id, safePointer(module2.stringToNewUTF8(file.locator), "external file locator pointer"), file.size);
470
497
  }).catch((error) => openComplete(id, 0, isNotFoundError(error) ? -2 : -1));
471
498
  };
@@ -554,8 +581,8 @@ function installFilesystemProjectionRuntime(module2) {
554
581
  complete(id, safePointer(module2.stringToNewUTF8(JSON.stringify(encoded)), "filesystem listing pointer"), 0);
555
582
  }).catch(() => complete(id, 0, -1));
556
583
  };
557
- module2.hyperdbWasmFilesystemLookupStart = (id, locator, path) => {
558
- const lookup = module2.externalDirectoryBackend?.lookup?.(locator, path);
584
+ module2.hyperdbWasmFilesystemLookupStart = (id, locator, path, generation) => {
585
+ const lookup = module2.externalDirectoryBackend?.lookup?.(locator, path, generation);
559
586
  if (!lookup) {
560
587
  complete(id, 0, -1);
561
588
  return;
@@ -591,22 +618,7 @@ function installFilesystemProjectionRuntime(module2) {
591
618
  function configureWorker(module2, transport2, configureFilesystem = () => void 0) {
592
619
  const queuedRequests = [];
593
620
  let bindings;
594
- let failed = false;
595
- const fail = (error) => {
596
- if (failed) return;
597
- failed = true;
598
- bindings = void 0;
599
- queuedRequests.length = 0;
600
- transport2.postMessage({ type: "fatal", error });
601
- module2.PThread?.terminateAllThreads();
602
- };
603
- const handleError = (request, error) => {
604
- if (failed) return;
605
- if (error instanceof WebAssembly.RuntimeError) fail(`engine trapped: ${errorText(error)}`);
606
- else transport2.postMessage({ id: request.id, type: "response", result: { state: "error", error: errorText(error) } });
607
- };
608
621
  const handle = (request) => {
609
- if (failed) return;
610
622
  if (!bindings) {
611
623
  queuedRequests.push(request);
612
624
  return;
@@ -614,14 +626,15 @@ function configureWorker(module2, transport2, configureFilesystem = () => void 0
614
626
  try {
615
627
  const result = bindings.handle(request);
616
628
  const complete = () => {
617
- if (failed) return;
618
629
  if (request.type === "shutdown" && result.response.result.state === "ok") module2.PThread.terminateAllThreads();
619
630
  transport2.postMessage(result.response, result.transfer);
620
631
  };
621
- if (result.completion) void result.completion.then(complete).catch((error) => handleError(request, error));
632
+ if (result.completion) void result.completion.then(complete, (error) => {
633
+ transport2.postMessage({ id: request.id, type: "response", result: { state: "error", error: errorText(error) } });
634
+ });
622
635
  else complete();
623
636
  } catch (error) {
624
- handleError(request, error);
637
+ transport2.postMessage({ id: request.id, type: "response", result: { state: "error", error: errorText(error) } });
625
638
  }
626
639
  };
627
640
  transport2.onMessage((message) => {
@@ -630,21 +643,20 @@ function configureWorker(module2, transport2, configureFilesystem = () => void 0
630
643
  module2.print = (text) => transport2.postMessage({ type: "log", text });
631
644
  module2.printErr = (text) => transport2.postMessage({ type: "log", text });
632
645
  module2.onRuntimeInitialized = () => {
633
- if (failed) return;
634
646
  try {
635
647
  configureFilesystem(module2);
636
648
  installHttpRuntime(module2, transport2);
637
649
  installHostFileRuntime(module2);
638
- installExternalDirectoryRuntime(module2);
650
+ installExternalDirectoryRuntime(module2, transport2);
639
651
  installFilesystemProjectionRuntime(module2);
640
652
  bindings = new HyperDBBindings(module2);
641
653
  transport2.postMessage({ type: "ready" });
642
654
  for (const request of queuedRequests.splice(0)) handle(request);
643
655
  } catch (error) {
644
- fail(`engine initialization failed: ${errorText(error)}`);
656
+ transport2.postMessage({ type: "fatal", error: `engine initialization failed: ${errorText(error)}` });
645
657
  }
646
658
  };
647
- module2.onAbort = (reason) => fail(`engine aborted: ${String(reason)}`);
659
+ module2.onAbort = (reason) => transport2.postMessage({ type: "fatal", error: `engine aborted: ${String(reason)}` });
648
660
  }
649
661
 
650
662
  // src/node_external_directory.ts
@@ -720,13 +732,31 @@ var NodeExternalDirectoryBackend = class {
720
732
  const info = lstatSync(root);
721
733
  if (info.isSymbolicLink() || !info.isDirectory()) throw new Error("External directory path must identify a directory");
722
734
  const locator = `${directoryLocatorPrefix}${randomUUID()}`;
723
- this.directories.set(locator, { root, mode, files: /* @__PURE__ */ new Map(), locators: /* @__PURE__ */ new Set(), temporaryPaths: /* @__PURE__ */ new Set() });
735
+ this.directories.set(locator, { root, mode, generations: /* @__PURE__ */ new Map(), locators: /* @__PURE__ */ new Set(), temporaryPaths: /* @__PURE__ */ new Set() });
724
736
  return { name: basename(root) || "root", locator };
725
737
  }
726
738
  registered(path, locator) {
727
739
  if (!this.directories.has(locator)) throw new Error("External directory registration is unavailable");
728
740
  this.paths.set(path, locator);
729
741
  }
742
+ /// Clears future path lookups, retaining descriptors until generation release
743
+ refresh(path) {
744
+ const locator = this.paths.get(path);
745
+ if (locator === void 0) throw new Error("External directory registration does not exist");
746
+ for (const generation of this.getDirectory(locator).generations.values()) generation.files.clear();
747
+ }
748
+ async releaseGeneration(locator, generation) {
749
+ const directory = this.directories.get(locator);
750
+ const state = directory?.generations.get(generation);
751
+ if (!directory || !state) return;
752
+ directory.generations.delete(generation);
753
+ await Promise.all([...state.locators].map(async (fileLocator) => {
754
+ const file = this.files.get(fileLocator);
755
+ if (file) await this.closeFile(file);
756
+ this.files.delete(fileLocator);
757
+ directory.locators.delete(fileLocator);
758
+ }));
759
+ }
730
760
  async removed(pathOrLocator) {
731
761
  const locator = this.paths.get(pathOrLocator) ?? pathOrLocator;
732
762
  const directory = this.directories.get(locator);
@@ -747,7 +777,7 @@ var NodeExternalDirectoryBackend = class {
747
777
  directory.locators.delete(fileLocator);
748
778
  continue;
749
779
  }
750
- fileCleanup.push(file.descriptor.close().then(() => {
780
+ fileCleanup.push(this.closeFile(file).then(() => {
751
781
  this.files.delete(fileLocator);
752
782
  directory.locators.delete(fileLocator);
753
783
  }));
@@ -797,7 +827,7 @@ var NodeExternalDirectoryBackend = class {
797
827
  entries.sort((left, right) => left.name.localeCompare(right.name));
798
828
  return entries;
799
829
  }
800
- async lookup(locator, path) {
830
+ async lookup(locator, path, generation) {
801
831
  const directory = this.getDirectory(locator);
802
832
  const segments = relativeSegments(path);
803
833
  await ensureDirectory(directory.root, segments.slice(0, -1), false);
@@ -807,15 +837,20 @@ var NodeExternalDirectoryBackend = class {
807
837
  if (info.isSymbolicLink()) throw new Error("External directory must not contain symbolic links");
808
838
  if (info.isDirectory()) return { kind: "directory" };
809
839
  if (!info.isFile()) throw new Error("External directory contains an unsupported entry");
810
- return { kind: "file", ...await this.open(locator, path) };
840
+ return { kind: "file", ...await this.open(locator, path, generation) };
811
841
  } catch (error) {
812
842
  if (isNotFound(error)) return void 0;
813
843
  throw error;
814
844
  }
815
845
  }
816
- async open(locator, path) {
846
+ async open(locator, path, generation) {
817
847
  const directory = this.getDirectory(locator);
818
- const cached = directory.files.get(path);
848
+ let state = directory.generations.get(generation);
849
+ if (!state) {
850
+ state = { files: /* @__PURE__ */ new Map(), locators: /* @__PURE__ */ new Set() };
851
+ directory.generations.set(generation, state);
852
+ }
853
+ const cached = state.files.get(path);
819
854
  if (cached) {
820
855
  const file = await cached;
821
856
  return { locator: file.locator, size: file.size };
@@ -834,18 +869,19 @@ var NodeExternalDirectoryBackend = class {
834
869
  const file = { locator: `${fileLocatorPrefix}${randomUUID()}`, descriptor, size: Number(openedInfo.size) };
835
870
  this.files.set(file.locator, file);
836
871
  directory.locators.add(file.locator);
872
+ state.locators.add(file.locator);
837
873
  return file;
838
874
  } catch (error) {
839
875
  await descriptor.close();
840
876
  throw error;
841
877
  }
842
878
  })();
843
- directory.files.set(path, snapshot);
879
+ state.files.set(path, snapshot);
844
880
  try {
845
881
  const file = await snapshot;
846
882
  return { locator: file.locator, size: file.size };
847
883
  } catch (error) {
848
- directory.files.delete(path);
884
+ if (state.files.get(path) === snapshot) state.files.delete(path);
849
885
  throw error;
850
886
  }
851
887
  }
@@ -942,7 +978,7 @@ var NodeExternalDirectoryBackend = class {
942
978
  }
943
979
  throw failure;
944
980
  }
945
- this.getDirectory(state.locator).files.delete(state.path);
981
+ for (const generation of this.getDirectory(state.locator).generations.values()) generation.files.delete(state.path);
946
982
  }, true);
947
983
  return operation.then(() => {
948
984
  this.writers.delete(writer);
@@ -960,7 +996,7 @@ var NodeExternalDirectoryBackend = class {
960
996
  }
961
997
  async shutdown() {
962
998
  await Promise.all([...this.directories.keys()].map((locator) => this.removed(locator)));
963
- await Promise.all([...this.files.values()].map((file) => file.descriptor.close()));
999
+ await Promise.all([...this.files.values()].map((file) => this.closeFile(file)));
964
1000
  this.files.clear();
965
1001
  this.paths.clear();
966
1002
  this.directories.clear();
@@ -981,8 +1017,14 @@ var NodeExternalDirectoryBackend = class {
981
1017
  if (!state || state.terminal) throw new Error("External directory writer is not open");
982
1018
  return state;
983
1019
  }
1020
+ closeFile(file) {
1021
+ return file.closing ??= file.descriptor.close().catch((error) => {
1022
+ delete file.closing;
1023
+ throw error;
1024
+ });
1025
+ }
984
1026
  async cleanupWriter(state) {
985
- this.directories.get(state.locator)?.files.delete(state.path);
1027
+ for (const generation of this.directories.get(state.locator)?.generations.values() ?? []) generation.files.delete(state.path);
986
1028
  if (state.descriptor) {
987
1029
  await state.descriptor.close();
988
1030
  state.descriptor = void 0;
@@ -1037,7 +1079,15 @@ configureWorker(module, transport, (runtime) => {
1037
1079
  runtime.FS.mount(nodeFS, { root: storagePath }, "/mnt/fs");
1038
1080
  runtime.FS.mkdirTree("/mnt/fs/logs");
1039
1081
  const nodeRuntimeFS = runtime.FS;
1040
- const shouldAccessHostPath = (path) => isAbsolute2(path) && !nodeRuntimeFS.analyzePath(path).exists;
1082
+ const shouldAccessHostPath = (path) => {
1083
+ if (!isAbsolute2(path)) return false;
1084
+ let prefix = "/";
1085
+ for (const component of path.split("/")) {
1086
+ prefix = posix.join(prefix, component);
1087
+ if (prefix === "/mnt/external") return false;
1088
+ }
1089
+ return !nodeRuntimeFS.analyzePath(path).exists;
1090
+ };
1041
1091
  runtime.hyperdbWasmShouldOpenHostFile = shouldAccessHostPath;
1042
1092
  runtime.hyperdbWasmShouldListHostDirectory = shouldAccessHostPath;
1043
1093
  runtime.externalDirectoryBackend = new NodeExternalDirectoryBackend();
@@ -51,6 +51,10 @@ export type EngineRequest = {
51
51
  id: RequestId;
52
52
  type: 'unmount';
53
53
  path: string;
54
+ } | {
55
+ id: RequestId;
56
+ type: 'refreshMount';
57
+ path: string;
54
58
  } | {
55
59
  id: RequestId;
56
60
  type: 'pollQuery';
@@ -93,6 +93,9 @@ var HyperDBEngineClient = class {
93
93
  unmount(path) {
94
94
  return this.request({ id: this.nextId++, type: "unmount", path });
95
95
  }
96
+ refreshMount(path) {
97
+ return this.request({ id: this.nextId++, type: "refreshMount", path });
98
+ }
96
99
  pollQuery(query) {
97
100
  return this.request({ id: this.nextId++, type: "pollQuery", query });
98
101
  }
@@ -209,6 +212,7 @@ var HyperDBBindings = class {
209
212
  registerExternalFile;
210
213
  registerExternalDirectory;
211
214
  removeExternalRegistration;
215
+ refreshExternalDirectory;
212
216
  projectExternalFile;
213
217
  projectExternalDirectory;
214
218
  startQuery;
@@ -219,6 +223,7 @@ var HyperDBBindings = class {
219
223
  resultPayloadLength;
220
224
  free;
221
225
  mountedPaths = /* @__PURE__ */ new Set();
226
+ mountedDirectoryPaths = /* @__PURE__ */ new Set();
222
227
  constructor(module) {
223
228
  this.module = module;
224
229
  this.initialize = module.cwrap("hyperdb_wasm_initialize", "pointer", ["string", "string", "number"]);
@@ -228,6 +233,7 @@ var HyperDBBindings = class {
228
233
  this.registerExternalFile = module.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number", "number"]);
229
234
  this.registerExternalDirectory = module.cwrap("hyperdb_wasm_register_external_directory", "pointer", ["string", "string", "number", "number"]);
230
235
  this.removeExternalRegistration = module.cwrap("hyperdb_wasm_remove_external_registration", "pointer", ["string", "number"]);
236
+ this.refreshExternalDirectory = module.cwrap("hyperdb_wasm_refresh_external_directory", "pointer", ["string", "number"]);
231
237
  this.projectExternalFile = module.cwrap("hyperdb_wasm_project_external_file", "pointer", ["string", "string", "number", "number"]);
232
238
  this.projectExternalDirectory = module.cwrap("hyperdb_wasm_project_external_directory", "pointer", ["string", "string", "number"]);
233
239
  this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string", "number", "number"]);
@@ -256,11 +262,22 @@ var HyperDBBindings = class {
256
262
  if (request.type === "mount" && request.source.kind === "browser-file") {
257
263
  return this.mountFile(request, request.source.url, safeInteger(request.source.size, "external file size"));
258
264
  }
265
+ if (request.type === "refreshMount") {
266
+ validateCString(request.path, "external registration path");
267
+ const backend = this.module.externalDirectoryBackend;
268
+ if (!backend) return { response: { id: request.id, type: "response", result: { state: "error", error: "External directories are not supported by this client" } }, transfer: [] };
269
+ if (!this.mountedDirectoryPaths.has(request.path)) {
270
+ const error = this.mountedPaths.has(request.path) ? "Only directory mounts can be refreshed" : "External directory registration was not found";
271
+ return { response: { id: request.id, type: "response", result: { state: "error", error } }, transfer: [] };
272
+ }
273
+ backend.refresh(request.path);
274
+ }
259
275
  if (request.type === "unmount" && (this.module.externalFileBackend || this.module.externalDirectoryBackend)) {
260
276
  validateCString(request.path, "external registration path");
261
277
  const pointer2 = safeInteger(this.removeExternalRegistration(request.path, request.id), "result pointer");
262
278
  const result2 = this.decodeResult(pointer2);
263
279
  if (result2.state === "ok" || result2.state === "error" && result2.error === "External registration was not found" && this.mountedPaths.has(request.path)) {
280
+ this.mountedDirectoryPaths.delete(request.path);
264
281
  const cleanup = async () => {
265
282
  await Promise.all([
266
283
  this.module.externalFileBackend?.removed(request.path),
@@ -278,6 +295,8 @@ var HyperDBBindings = class {
278
295
  const pointer = safeInteger(this.invoke(request), "result pointer");
279
296
  const result = this.decodeResult(pointer);
280
297
  if (request.type === "shutdown" && result.state === "ok") {
298
+ this.mountedPaths.clear();
299
+ this.mountedDirectoryPaths.clear();
281
300
  const completion = completionFor([
282
301
  this.module.externalFileBackend?.shutdown(),
283
302
  this.module.externalDirectoryBackend?.shutdown()
@@ -289,6 +308,7 @@ var HyperDBBindings = class {
289
308
  };
290
309
  }
291
310
  const response = { id: request.id, type: "response", result };
311
+ if (request.type === "unmount" && result.state === "ok") this.mountedPaths.delete(request.path);
292
312
  return { response, transfer: result.state === "chunk" ? [result.payload.buffer] : [] };
293
313
  }
294
314
  invoke(request) {
@@ -312,6 +332,8 @@ var HyperDBBindings = class {
312
332
  case "unmount":
313
333
  validateCString(request.path, "external registration path");
314
334
  return this.removeExternalRegistration(request.path, request.id);
335
+ case "refreshMount":
336
+ return this.refreshExternalDirectory(request.path, request.id);
315
337
  case "startQuery":
316
338
  validateCStringContents(request.sql, "SQL");
317
339
  return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false), request.id);
@@ -382,12 +404,14 @@ var HyperDBBindings = class {
382
404
  if (projection.state !== "ok") throw new Error(resultError(projection));
383
405
  backend.registered(path, registration.locator);
384
406
  this.mountedPaths.add(path);
407
+ this.mountedDirectoryPaths.add(path);
385
408
  } catch (error) {
386
409
  const cleanupPointer = safeInteger(this.removeExternalRegistration(path, request.id), "result pointer");
387
410
  const cleanup = this.decodeResult(cleanupPointer);
388
411
  if (cleanup.state !== "ok") {
389
412
  backend.registered(path, registration.locator);
390
413
  this.mountedPaths.add(path);
414
+ this.mountedDirectoryPaths.add(path);
391
415
  preserveBackend = true;
392
416
  throw new Error(`mount failed and rollback also failed: ${resultError(cleanup)}`, { cause: error });
393
417
  }
package/dist/raw.node.js CHANGED
@@ -93,6 +93,9 @@ var HyperDBEngineClient = class {
93
93
  unmount(path) {
94
94
  return this.request({ id: this.nextId++, type: "unmount", path });
95
95
  }
96
+ refreshMount(path) {
97
+ return this.request({ id: this.nextId++, type: "refreshMount", path });
98
+ }
96
99
  pollQuery(query) {
97
100
  return this.request({ id: this.nextId++, type: "pollQuery", query });
98
101
  }
@@ -209,6 +212,7 @@ var HyperDBBindings = class {
209
212
  registerExternalFile;
210
213
  registerExternalDirectory;
211
214
  removeExternalRegistration;
215
+ refreshExternalDirectory;
212
216
  projectExternalFile;
213
217
  projectExternalDirectory;
214
218
  startQuery;
@@ -219,6 +223,7 @@ var HyperDBBindings = class {
219
223
  resultPayloadLength;
220
224
  free;
221
225
  mountedPaths = /* @__PURE__ */ new Set();
226
+ mountedDirectoryPaths = /* @__PURE__ */ new Set();
222
227
  constructor(module) {
223
228
  this.module = module;
224
229
  this.initialize = module.cwrap("hyperdb_wasm_initialize", "pointer", ["string", "string", "number"]);
@@ -228,6 +233,7 @@ var HyperDBBindings = class {
228
233
  this.registerExternalFile = module.cwrap("hyperdb_wasm_register_external_file", "pointer", ["string", "string", "number", "number"]);
229
234
  this.registerExternalDirectory = module.cwrap("hyperdb_wasm_register_external_directory", "pointer", ["string", "string", "number", "number"]);
230
235
  this.removeExternalRegistration = module.cwrap("hyperdb_wasm_remove_external_registration", "pointer", ["string", "number"]);
236
+ this.refreshExternalDirectory = module.cwrap("hyperdb_wasm_refresh_external_directory", "pointer", ["string", "number"]);
231
237
  this.projectExternalFile = module.cwrap("hyperdb_wasm_project_external_file", "pointer", ["string", "string", "number", "number"]);
232
238
  this.projectExternalDirectory = module.cwrap("hyperdb_wasm_project_external_directory", "pointer", ["string", "string", "number"]);
233
239
  this.startQuery = module.cwrap("hyperdb_wasm_query_start", "pointer", ["number", "string", "number", "number"]);
@@ -256,11 +262,22 @@ var HyperDBBindings = class {
256
262
  if (request.type === "mount" && request.source.kind === "browser-file") {
257
263
  return this.mountFile(request, request.source.url, safeInteger(request.source.size, "external file size"));
258
264
  }
265
+ if (request.type === "refreshMount") {
266
+ validateCString(request.path, "external registration path");
267
+ const backend = this.module.externalDirectoryBackend;
268
+ if (!backend) return { response: { id: request.id, type: "response", result: { state: "error", error: "External directories are not supported by this client" } }, transfer: [] };
269
+ if (!this.mountedDirectoryPaths.has(request.path)) {
270
+ const error = this.mountedPaths.has(request.path) ? "Only directory mounts can be refreshed" : "External directory registration was not found";
271
+ return { response: { id: request.id, type: "response", result: { state: "error", error } }, transfer: [] };
272
+ }
273
+ backend.refresh(request.path);
274
+ }
259
275
  if (request.type === "unmount" && (this.module.externalFileBackend || this.module.externalDirectoryBackend)) {
260
276
  validateCString(request.path, "external registration path");
261
277
  const pointer2 = safeInteger(this.removeExternalRegistration(request.path, request.id), "result pointer");
262
278
  const result2 = this.decodeResult(pointer2);
263
279
  if (result2.state === "ok" || result2.state === "error" && result2.error === "External registration was not found" && this.mountedPaths.has(request.path)) {
280
+ this.mountedDirectoryPaths.delete(request.path);
264
281
  const cleanup = async () => {
265
282
  await Promise.all([
266
283
  this.module.externalFileBackend?.removed(request.path),
@@ -278,6 +295,8 @@ var HyperDBBindings = class {
278
295
  const pointer = safeInteger(this.invoke(request), "result pointer");
279
296
  const result = this.decodeResult(pointer);
280
297
  if (request.type === "shutdown" && result.state === "ok") {
298
+ this.mountedPaths.clear();
299
+ this.mountedDirectoryPaths.clear();
281
300
  const completion = completionFor([
282
301
  this.module.externalFileBackend?.shutdown(),
283
302
  this.module.externalDirectoryBackend?.shutdown()
@@ -289,6 +308,7 @@ var HyperDBBindings = class {
289
308
  };
290
309
  }
291
310
  const response = { id: request.id, type: "response", result };
311
+ if (request.type === "unmount" && result.state === "ok") this.mountedPaths.delete(request.path);
292
312
  return { response, transfer: result.state === "chunk" ? [result.payload.buffer] : [] };
293
313
  }
294
314
  invoke(request) {
@@ -312,6 +332,8 @@ var HyperDBBindings = class {
312
332
  case "unmount":
313
333
  validateCString(request.path, "external registration path");
314
334
  return this.removeExternalRegistration(request.path, request.id);
335
+ case "refreshMount":
336
+ return this.refreshExternalDirectory(request.path, request.id);
315
337
  case "startQuery":
316
338
  validateCStringContents(request.sql, "SQL");
317
339
  return this.startQuery(request.connection, request.sql, Number(request.sqlTestMode ?? false), request.id);
@@ -382,12 +404,14 @@ var HyperDBBindings = class {
382
404
  if (projection.state !== "ok") throw new Error(resultError(projection));
383
405
  backend.registered(path, registration.locator);
384
406
  this.mountedPaths.add(path);
407
+ this.mountedDirectoryPaths.add(path);
385
408
  } catch (error) {
386
409
  const cleanupPointer = safeInteger(this.removeExternalRegistration(path, request.id), "result pointer");
387
410
  const cleanup = this.decodeResult(cleanupPointer);
388
411
  if (cleanup.state !== "ok") {
389
412
  backend.registered(path, registration.locator);
390
413
  this.mountedPaths.add(path);
414
+ this.mountedDirectoryPaths.add(path);
391
415
  preserveBackend = true;
392
416
  throw new Error(`mount failed and rollback also failed: ${resultError(cleanup)}`, { cause: error });
393
417
  }
@@ -27,20 +27,22 @@ export interface ExternalDirectoryBackend {
27
27
  readonly locator: string;
28
28
  };
29
29
  registered(path: string, locator: string): void;
30
+ refresh(path: string): void;
31
+ releaseGeneration(locator: string, generation: string): void | Promise<void>;
30
32
  removed(path: string): void | Promise<void>;
31
33
  list(locator: string): Promise<readonly string[]>;
32
34
  listEntries?(locator: string, path: string): Promise<readonly {
33
35
  readonly name: string;
34
36
  readonly kind: 'file' | 'directory';
35
37
  }[]>;
36
- lookup?(locator: string, path: string): Promise<{
38
+ lookup?(locator: string, path: string, generation: string): Promise<{
37
39
  readonly kind: 'directory';
38
40
  } | {
39
41
  readonly kind: 'file';
40
42
  readonly locator: string;
41
43
  readonly size: number;
42
44
  } | undefined>;
43
- open(locator: string, path: string): Promise<{
45
+ open(locator: string, path: string, generation: string): Promise<{
44
46
  readonly locator: string;
45
47
  readonly size: number;
46
48
  }>;
@@ -80,6 +82,7 @@ export declare class HyperDBBindings {
80
82
  private readonly registerExternalFile;
81
83
  private readonly registerExternalDirectory;
82
84
  private readonly removeExternalRegistration;
85
+ private readonly refreshExternalDirectory;
83
86
  private readonly projectExternalFile;
84
87
  private readonly projectExternalDirectory;
85
88
  private readonly startQuery;
@@ -90,6 +93,7 @@ export declare class HyperDBBindings {
90
93
  private readonly resultPayloadLength;
91
94
  private readonly free;
92
95
  private readonly mountedPaths;
96
+ private readonly mountedDirectoryPaths;
93
97
  constructor(module: HyperDBWasmModule);
94
98
  handle(request: EngineRequest): BindingResponse;
95
99
  private invoke;
@@ -35,13 +35,14 @@ export interface HyperDBWasmRuntimeModule extends HyperDBWasmModule {
35
35
  hyperdbWasmHostFileClose?: (id: number) => void;
36
36
  hyperdbWasmHostDirectoryListStart?: (id: number, path: string) => void;
37
37
  hyperdbWasmExternalDirectoryListStart?: (id: number, locator: string) => void;
38
- hyperdbWasmExternalDirectoryOpenStart?: (id: number, locator: string, path: string) => void;
38
+ hyperdbWasmExternalDirectoryOpenStart?: (id: number, locator: string, path: string, generation: string) => void;
39
+ hyperdbWasmExternalDirectoryReleaseGeneration?: (locator: string, generation: string) => void;
39
40
  hyperdbWasmExternalDirectoryCreateDirectoriesStart?: (id: number, locator: string, path: string) => void;
40
41
  hyperdbWasmExternalDirectoryWriterWriteStart?: (writer: number, id: number, locator: string, path: string, offset: number, pointer: number | bigint, length: number) => void;
41
42
  hyperdbWasmExternalDirectoryWriterFinishStart?: (writer: number, id: number, locator: string, path: string, size: number) => void;
42
43
  hyperdbWasmExternalDirectoryWriterAbortStart?: (writer: number, id: number) => void;
43
44
  hyperdbWasmFilesystemListStart?: (id: number, locator: string, path: string) => void;
44
- hyperdbWasmFilesystemLookupStart?: (id: number, locator: string, path: string) => void;
45
+ hyperdbWasmFilesystemLookupStart?: (id: number, locator: string, path: string, generation: string) => void;
45
46
  hyperdbWasmFilesystemReadStart?: (id: number, locator: string, offset: number, length: number, expectedSize: number, pointer: number | bigint) => void;
46
47
  hyperdbWasmShouldOpenHostFile?: (path: string) => boolean;
47
48
  hyperdbWasmShouldListHostDirectory?: (path: string) => boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperdb-wasm",
3
- "version": "0.0.27136-dev.wasm.g077c0cd8",
3
+ "version": "0.0.27136-dev.wasm.g5f4b267e",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=24"