hyperdb-wasm 0.0.26312-dev.wasm.g913ac019 → 0.0.26314-dev.wasm.g698c9427

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.d.ts CHANGED
@@ -13,6 +13,20 @@ export interface BrowserClientOptions {
13
13
  readonly wasmUrl?: string | URL;
14
14
  readonly onSetupProgress?: (progress: SetupProgress) => void;
15
15
  }
16
+ type BrowserEnvironment = {
17
+ readonly WebAssembly?: typeof WebAssembly;
18
+ readonly Worker?: unknown;
19
+ readonly SharedArrayBuffer?: unknown;
20
+ readonly Atomics?: unknown;
21
+ readonly BigInt?: unknown;
22
+ readonly crossOriginIsolated?: boolean;
23
+ readonly navigator?: {
24
+ readonly storage?: {
25
+ readonly getDirectory?: unknown;
26
+ };
27
+ };
28
+ };
29
+ export declare function assertBrowserSupport(environment?: BrowserEnvironment): void;
16
30
  export declare class BrowserWorker implements WorkerTransport {
17
31
  private readonly worker;
18
32
  constructor(worker: BrowserWorkerLike);
package/dist/browser.js CHANGED
@@ -200,9 +200,36 @@ var init_client = __esm({
200
200
  var browser_exports = {};
201
201
  __export(browser_exports, {
202
202
  BrowserWorker: () => BrowserWorker,
203
+ assertBrowserSupport: () => assertBrowserSupport,
203
204
  createBrowserClient: () => createBrowserClient,
204
205
  resolveBrowserWorkerUrl: () => resolveBrowserWorkerUrl
205
206
  });
207
+ function assertBrowserSupport(environment = globalThis) {
208
+ if (typeof environment.WebAssembly?.validate !== "function") {
209
+ throw new Error("HyperDB cannot initialize because this browser does not support WebAssembly");
210
+ }
211
+ if (!environment.WebAssembly.validate(memory64Probe)) {
212
+ throw new Error("HyperDB cannot initialize because this browser does not yet support WebAssembly memory64. Support for platforms such as iOS is coming soon.");
213
+ }
214
+ if (typeof environment.BigInt !== "function") {
215
+ throw new Error("HyperDB cannot initialize because this browser does not support WebAssembly BigInt integration");
216
+ }
217
+ if (!environment.WebAssembly.validate(threadsProbe) || typeof environment.SharedArrayBuffer !== "function" || typeof environment.Atomics !== "object") {
218
+ throw new Error("HyperDB cannot initialize because this browser does not support WebAssembly threads");
219
+ }
220
+ if (!environment.WebAssembly.validate(exceptionsProbe)) {
221
+ throw new Error("HyperDB cannot initialize because this browser does not support WebAssembly exception handling");
222
+ }
223
+ if (typeof environment.Worker !== "function") {
224
+ throw new Error("HyperDB cannot initialize because this browser does not support Web Workers");
225
+ }
226
+ if (environment.crossOriginIsolated !== true) {
227
+ throw new Error("HyperDB cannot initialize because this page is not cross-origin isolated");
228
+ }
229
+ if (typeof environment.navigator?.storage?.getDirectory !== "function") {
230
+ throw new Error("HyperDB cannot initialize because this browser does not support the origin-private file system");
231
+ }
232
+ }
206
233
  function resolveBrowserWorkerUrl(workerUrl, engineUrl, wasmUrl) {
207
234
  const resolved = new URL(workerUrl);
208
235
  resolved.searchParams.set("engineUrl", new URL(engineUrl).href);
@@ -210,6 +237,7 @@ function resolveBrowserWorkerUrl(workerUrl, engineUrl, wasmUrl) {
210
237
  return resolved;
211
238
  }
212
239
  function createBrowserClient(options = {}) {
240
+ assertBrowserSupport();
213
241
  const workerUrl = options.workerUrl ?? new URL("./browser_worker.js", import.meta.url);
214
242
  const engineUrl = options.engineUrl ?? new URL("./hyperdb-wasm.js", import.meta.url);
215
243
  return new HyperDBEngineClient(
@@ -217,11 +245,14 @@ function createBrowserClient(options = {}) {
217
245
  options.onSetupProgress
218
246
  );
219
247
  }
220
- var BrowserWorker;
248
+ var memory64Probe, threadsProbe, exceptionsProbe, BrowserWorker;
221
249
  var init_browser = __esm({
222
250
  "src/browser.ts"() {
223
251
  "use strict";
224
252
  init_client();
253
+ memory64Probe = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 5, 3, 1, 4, 1]);
254
+ threadsProbe = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 5, 4, 1, 3, 1, 1]);
255
+ exceptionsProbe = new Uint8Array([0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 13, 3, 1, 0, 0]);
225
256
  BrowserWorker = class {
226
257
  constructor(worker) {
227
258
  this.worker = worker;
@@ -12092,6 +12123,7 @@ RecordBatchFileWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12092
12123
  RecordBatchStreamWriter["throughDOM"] = recordBatchWriterThroughDOMStream;
12093
12124
 
12094
12125
  // src/api.ts
12126
+ var maxPersistentDatabaseNameLength = 200;
12095
12127
  function normalizeArrowInsertOptions(options) {
12096
12128
  if (!options.name) throw new Error("Arrow insert table name must not be empty");
12097
12129
  return { name: options.name, schema: options.schema ?? null, create: options.create ?? true };
@@ -12100,6 +12132,18 @@ function validateDatabaseName(databaseName) {
12100
12132
  if (!databaseName) throw new Error("Database name must not be empty");
12101
12133
  if (databaseName.includes("\0")) throw new Error("Database name must not contain NUL");
12102
12134
  }
12135
+ function validatePersistentDatabaseName(databaseName) {
12136
+ validateDatabaseName(databaseName);
12137
+ if (databaseName.length > maxPersistentDatabaseNameLength) {
12138
+ throw new Error(`Persistent database name must be at most ${maxPersistentDatabaseNameLength} characters`);
12139
+ }
12140
+ if (!/^[a-z0-9][a-z0-9_-]*$/.test(databaseName)) {
12141
+ 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");
12142
+ }
12143
+ if (/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])$/.test(databaseName)) {
12144
+ throw new Error("Persistent database name is reserved by Windows");
12145
+ }
12146
+ }
12103
12147
  function validateDatabaseAlias(alias) {
12104
12148
  if (!alias) throw new Error("Database alias must not be empty");
12105
12149
  if (alias.includes("\0")) throw new Error("Database alias must not contain NUL");
@@ -12212,12 +12256,13 @@ var HyperDB = class _HyperDB {
12212
12256
  if (options.storage !== void 0 && options.storage !== "memory" && options.storage !== "persistent") {
12213
12257
  throw new Error(`Unsupported database storage: ${String(options.storage)}`);
12214
12258
  }
12259
+ if (options.storage === "persistent") validatePersistentDatabaseName(databaseName);
12215
12260
  await this.runDatabaseOperation(async () => {
12216
12261
  expectOk(await this.client.createDatabase(databaseName, options.storage === "persistent"), "create database");
12217
12262
  });
12218
12263
  }
12219
12264
  async openDatabase(databaseName) {
12220
- validateDatabaseName(databaseName);
12265
+ validatePersistentDatabaseName(databaseName);
12221
12266
  await this.runDatabaseOperation(async () => {
12222
12267
  expectOk(await this.client.openDatabase(databaseName), "open database");
12223
12268
  });