@ztimson/utils 0.25.4 → 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.
- package/dist/database.d.ts +2 -2
- package/dist/index.cjs +4 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +4 -5
- 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,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
|
-
|
|
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;
|
|
@@ -419,15 +420,13 @@ ${opts.message || this.desc}`;
|
|
|
419
420
|
req.onupgradeneeded = () => {
|
|
420
421
|
const db = req.result;
|
|
421
422
|
const existingTables = new ASet(Array.from(db.objectStoreNames));
|
|
422
|
-
console.log("delete", existingTables.difference(tableNames));
|
|
423
423
|
existingTables.difference(tableNames).forEach((name) => db.deleteObjectStore(name));
|
|
424
|
-
console.log("create", tableNames.difference(existingTables));
|
|
425
424
|
tableNames.difference(existingTables).forEach((name) => db.createObjectStore(name));
|
|
426
425
|
};
|
|
427
426
|
});
|
|
428
427
|
}
|
|
429
428
|
includes(name) {
|
|
430
|
-
return this.tables.
|
|
429
|
+
return !!this.tables.find((t) => t.name == name.toString());
|
|
431
430
|
}
|
|
432
431
|
table(name) {
|
|
433
432
|
return new Table(this, name.toString());
|