@ztimson/utils 0.25.5 → 0.25.7
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/database.d.ts +2 -2
- package/dist/index.cjs +7 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +7 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/database.d.ts
CHANGED
|
@@ -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:
|
|
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,16 @@ ${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
|
-
|
|
407
|
+
this.tables = tables.map((t) => {
|
|
408
|
+
t = typeof t == "object" ? t : { name: t };
|
|
409
|
+
return { ...t, name: t.name.toString() };
|
|
410
|
+
});
|
|
411
|
+
const tableNames = new ASet(this.tables.map((t) => t.name));
|
|
408
412
|
req.onerror = () => reject(req.error);
|
|
409
413
|
req.onsuccess = () => {
|
|
410
414
|
const db = req.result;
|
|
@@ -425,7 +429,7 @@ ${opts.message || this.desc}`;
|
|
|
425
429
|
});
|
|
426
430
|
}
|
|
427
431
|
includes(name) {
|
|
428
|
-
return this.tables.
|
|
432
|
+
return !!this.tables.find((t) => t.name == name.toString());
|
|
429
433
|
}
|
|
430
434
|
table(name) {
|
|
431
435
|
return new Table(this, name.toString());
|