"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DATABASE_VERSION = exports.DATABASE_NAME = void 0;
exports.connect = connect;
const NOOP_1 = require("../NOOP");
exports.DATABASE_NAME = 'unit';
exports.DATABASE_VERSION = 1;
async function connect(system, name, version, onupgradeneeded = NOOP_1.NOOP) {
    const { api: { db }, } = system;
    return new Promise((resolve, reject) => {
        const request = db.open(name, version);
        request.onerror = (event) => {
            reject(
            // @ts-ignore
            new Error('Could not connect to IndexedDB: ' + event.target.errorCode));
        };
        request.onsuccess = (event) => {
            if (event && event.target) {
                const db = event.target.result;
                resolve(db);
            }
        };
        request.onupgradeneeded = (event) => {
            const db = event.target.result;
            onupgradeneeded(db);
        };
    });
}
//# sourceMappingURL=database.js.map