import { openDB } from 'idb';
/**
 * This file is a ES module (.mts) instead of CommonJS. It was converted to ESM to resolve
 * an import issue with the `idb` package.
 *
 * When it was CommonJS the `npm run check` failed with error:
 * "The current file is a CommonJS module whose imports will produce 'require' calls;
 * however, the referenced file is an ECMAScript module and cannot be imported with 'require'.
 * Consider writing a dynamic 'import("idb")' call instead."
 *
 * Although `idb` has a default export of "index.cjs", switching to ESM fixed the issue.
 * If we find another solution, we may revert this file to CommonJS.
 *
 * See https://github.com/streamr-dev/network/pull/2848
 */
export default class BrowserPersistence {
    db;
    static async createInstance(opts) {
        const db = await openDB(`streamr-sdk::${opts.ownerId}`, 1, {
            upgrade(db) {
                opts.namespaces.forEach((namespace) => db.createObjectStore(namespace));
            }
        });
        return new BrowserPersistence(db);
    }
    constructor(db) {
        this.db = db;
    }
    async get(key, namespace) {
        return this.db.get(namespace, key);
    }
    async set(key, value, namespace) {
        await this.db.put(namespace, value, key);
    }
    // eslint-disable-next-line class-methods-use-this
    async close() {
        // noop
    }
}
//# sourceMappingURL=BrowserPersistence.mjs.map