Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add type exports for openDB callbacks #314

Open
shoebilyas123 opened this issue Jun 16, 2024 · 0 comments
Open

Add type exports for openDB callbacks #314

shoebilyas123 opened this issue Jun 16, 2024 · 0 comments

Comments

@shoebilyas123
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant