src/store/indexeddb.js
function degradable(func, fallback) {
    return async function(...args) {
        try {
            return await func.call(this, ...args);
        } catch (e) {
            console.error("IndexedDBStore failure, degrading to MemoryStore", e);
            this.emit("degraded", e);
            try {
                // We try to delete IndexedDB after degrading since this store is only a
                // cache (the app will still function correctly without the data).
                // It's possible that deleting repair IndexedDB for the next app load,
                // potenially by making a little more space available.
                console.log("IndexedDBStore trying to delete degraded data");
                await this.backend.clearDatabase();
                console.log("IndexedDBStore delete after degrading succeeeded");
            } catch (e) {
                console.warn("IndexedDBStore delete after degrading failed", e);
            }
            // Degrade the store from being an instance of `IndexedDBStore` to instead be
            // an instance of `MemoryStore` so that future API calls use the memory path
            // directly and skip IndexedDB entirely. This should be safe as
            // `IndexedDBStore` already extends from `MemoryStore`, so we are making the
            // store become its parent type in a way. The mutator methods of
            // `IndexedDBStore` also maintain the state that `MemoryStore` uses (many are
            // not overridden at all).
            Object.setPrototypeOf(this, MemoryStore.prototype);
            if (fallback) {
                return await MemoryStore.prototype[fallback].call(this, ...args);
            }
        }
    };
}
function degradable(func, fallback) {
    return async function(...args) {
        try {
            return await func.call(this, ...args);
        } catch (e) {
            console.error("IndexedDBStore failure, degrading to MemoryStore", e);
            this.emit("degraded", e);
            try {
                // We try to delete IndexedDB after degrading since this store is only a
                // cache (the app will still function correctly without the data).
                // It's possible that deleting repair IndexedDB for the next app load,
                // potenially by making a little more space available.
                console.log("IndexedDBStore trying to delete degraded data");
                await this.backend.clearDatabase();
                console.log("IndexedDBStore delete after degrading succeeeded");
            } catch (e) {
                console.warn("IndexedDBStore delete after degrading failed", e);
            }
            // Degrade the store from being an instance of `IndexedDBStore` to instead be
            // an instance of `MemoryStore` so that future API calls use the memory path
            // directly and skip IndexedDB entirely. This should be safe as
            // `IndexedDBStore` already extends from `MemoryStore`, so we are making the
            // store become its parent type in a way. The mutator methods of
            // `IndexedDBStore` also maintain the state that `MemoryStore` uses (many are
            // not overridden at all).
            Object.setPrototypeOf(this, MemoryStore.prototype);
            if (fallback) {
                return await MemoryStore.prototype[fallback].call(this, ...args);
            }
        }
    };
}
function degradable ( func , fallback ) { return async function ( ... args ) { try { return await func . call ( this , ... args ) ; } catch ( e ) { console . error ( "IndexedDBStore failure, degrading to MemoryStore" , e ) ; this . emit ( "degraded" , e ) ; try { // We try to delete IndexedDB after degrading since this store is only a // cache (the app will still function correctly without the data). // It's possible that deleting repair IndexedDB for the next app load, // potenially by making a little more space available. console . log ( "IndexedDBStore trying to delete degraded data" ) ; await this . backend . clearDatabase ( ) ; console . log ( "IndexedDBStore delete after degrading succeeeded" ) ; } catch ( e ) { console . warn ( "IndexedDBStore delete after degrading failed" , e ) ; } // Degrade the store from being an instance of `IndexedDBStore` to instead be // an instance of `MemoryStore` so that future API calls use the memory path // directly and skip IndexedDB entirely. This should be safe as // `IndexedDBStore` already extends from `MemoryStore`, so we are making the // store become its parent type in a way. The mutator methods of // `IndexedDBStore` also maintain the state that `MemoryStore` uses (many are // not overridden at all). Object . setPrototypeOf ( this , MemoryStore . prototype ) ; if ( fallback ) { return await MemoryStore . prototype [ fallback ] . call ( this , ... args ) ; } } } ; }
All member functions of `IndexedDBStore` that access the backend use this wrapper to
watch for failures after initial store startup, including `QuotaExceededError` as
free disk space changes, etc.

When IndexedDB fails via any of these paths, we degrade this back to a `MemoryStore`
in place so that the current operation and all future ones are in-memory only.

@param {Function} func The degradable work to do.
@param {String} fallback The method name for fallback.
@returns {Function} A wrapped member function.
All member functions of IndexedDBStore that access the backend use this wrapper to watch for failures after initial store startup including QuotaExceededError as free disk space changes etc .