@ztimson/utils 0.25.5 → 0.25.6

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.
@@ -4,11 +4,11 @@ export type TableOptions = {
4
4
  };
5
5
  export declare class Database {
6
6
  readonly database: string;
7
- readonly tables: (string | TableOptions)[];
8
7
  version?: number | undefined;
9
8
  connection: Promise<IDBDatabase>;
9
+ tables: TableOptions[];
10
10
  constructor(database: string, tables: (string | TableOptions)[], version?: number | undefined);
11
- includes(name: string): boolean;
11
+ includes(name: any): boolean;
12
12
  table<K extends IDBValidKey = any, T = any>(name: any): Table<K, T>;
13
13
  }
14
14
  export declare class Table<K extends IDBValidKey = any, T = any> {
package/dist/index.cjs CHANGED
@@ -399,12 +399,13 @@ ${opts.message || this.desc}`;
399
399
  class Database {
400
400
  constructor(database, tables, version) {
401
401
  __publicField(this, "connection");
402
+ __publicField(this, "tables");
402
403
  this.database = database;
403
- this.tables = tables;
404
404
  this.version = version;
405
405
  this.connection = new Promise((resolve, reject) => {
406
406
  const req = indexedDB.open(this.database, this.version);
407
- const tableNames = new ASet(tables.map((t) => (typeof t == "object" ? t.name : t).toString()));
407
+ this.tables = tables.map((t) => typeof t == "object" ? t : { name: t });
408
+ const tableNames = new ASet(this.tables.map((t) => t.name));
408
409
  req.onerror = () => reject(req.error);
409
410
  req.onsuccess = () => {
410
411
  const db = req.result;
@@ -425,7 +426,7 @@ ${opts.message || this.desc}`;
425
426
  });
426
427
  }
427
428
  includes(name) {
428
- return this.tables.some((t) => typeof t === "string" ? name === t : name === t.name);
429
+ return !!this.tables.find((t) => t.name == name.toString());
429
430
  }
430
431
  table(name) {
431
432
  return new Table(this, name.toString());