import * as plugins from './webstore.plugins'; export interface IWebStoreOptions { dbName: string; storeName: string; } export class WebStore { public db: plugins.idb.IDBPDatabase; public objectStore: plugins.idb.IDBPObjectStore; public options: IWebStoreOptions; constructor(optionsArg: IWebStoreOptions) { this.options = optionsArg; } public async init () { this.db = await plugins.idb.openDB(this.options.dbName, 1, { upgrade: (db) => { db.createObjectStore(this.options.storeName); }, }); } async get(key) { return this.db.get(this.options.storeName, key); } async set(key, val) { return this.db.put(this.options.storeName, val, key); } async delete(key) { return this.db.delete(this.options.storeName, key); } async clear() { return this.db.clear(this.options.storeName); } async keys() { return this.db.getAllKeys(this.options.storeName); } }