"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const kv_store_1 = tslib_1.__importDefault(require("expo-sqlite/kv-store"));
const lock_1 = require("./lock");
// Needed because concurrent calls seem to return with a locked database
const lock = new lock_1.Lock();
class NativeStorage {
    async getItem(key) {
        return lock.critical(async () => {
            try {
                const value = await kv_store_1.default.getItem(key);
                return value ?? null;
            }
            catch (e) {
                console.error(`error in NativeStorage.getItem: ${e}`);
                throw e;
            }
        });
    }
    async setItem(key, value) {
        return lock.critical(async () => {
            try {
                await kv_store_1.default.setItem(key, value);
            }
            catch (e) {
                console.error(`error in NativeStorage.setItem: ${e}`);
                throw e;
            }
        });
    }
    async removeItem(key) {
        return lock.critical(async () => {
            try {
                await kv_store_1.default.removeItem(key);
            }
            catch (e) {
                console.error(`error in NativeStorage.removeItem: ${e}`);
                throw e;
            }
        });
    }
}
exports.default = NativeStorage;
//# sourceMappingURL=storage.native.js.map