idb
idb copied to clipboard
Add type exports for openDB callbacks
Is your feature request related to a problem? Please describe.
I was was using idb to implement a local data store for my work project. I suggest adding export types for openDB callbacks.
Describe the solution you'd like
For instance, the types for openDB callbacks for upgrade and blocked are defined like this:
upgrade?(database: IDBPDatabase<DBTypes>, oldVersion: number, newVersion: number | null, transaction: IDBPTransaction<DBTypes, StoreNames<DBTypes>[], 'versionchange'>, event: IDBVersionChangeEvent): void;
/**
* Called if there are older versions of the database open on the origin, so this version cannot
* open.
*
* @param currentVersion Version of the database that's blocking this one.
* @param blockedVersion The version of the database being blocked (whatever version you provided to `openDB`).
* @param event The event object for the associated `blocked` event.
*/
blocked?(currentVersion: number, blockedVersion: number | null, event: IDBVersionChangeEvent): void;
I suggest we can export them as a separate types, for better modularity. A pseudo-sample code is written below:
export type IDBUpgrade = (database: IDBPDatabase<DBTypes>, oldVersion: number, newVersion: number | null, transaction: IDBPTransaction<DBTypes, StoreNames<DBTypes>[], 'versionchange'>, event: IDBVersionChangeEvent) => void
and then we can use it in the OpenDBCallbacks type as:
// ...some code
upgrade?: IDBUpgrade;
// ...some other code
This way I can use this type outside of the library if I am defining a custom upgrade or blocking function elsewhere that I might use later.