diff --git a/packages/frontend/src/scripts/idb-proxy.ts b/packages/frontend/src/scripts/idb-proxy.ts index 20f51660c7..425225fc42 100644 --- a/packages/frontend/src/scripts/idb-proxy.ts +++ b/packages/frontend/src/scripts/idb-proxy.ts @@ -26,6 +26,7 @@ if (window.Cypress) { console.log('Cypress detected. It will use localStorage.'); } +// Check for the availability of indexedDB. if (idbAvailable) { await iset('idb-test', 'test') .catch(err => { @@ -37,16 +38,36 @@ if (idbAvailable) { console.error('indexedDB is unavailable. It will use localStorage.'); } +/** + * Get a value from indexedDB (or localStorage as a fallback). + * + * @param key The key of the item to retrieve. + * + * @returns The value of the item. + */ export async function get(key: string) { if (idbAvailable) return iget(key); return miLocalStorage.getItemAsJson(`${PREFIX}${key}`); } +/** + * Set a value in indexedDB (or localStorage as a fallback). + * + * @param {string} key - The key of the item to set. + * @param {any} val - The value of the item to set. + * @returns {Promise} - A promise that resolves when the value has been set.` + */ export async function set(key: string, val: any) { if (idbAvailable) return iset(key, val); return miLocalStorage.setItemAsJson(`${PREFIX}${key}`, val); } +/** + * Delete a value from indexedDB (or localStorage as a fallback). + * + * @param {string} key - The key of the item to delete. + * @returns {Promise} - A promise that resolves when the value has been deleted. + */ export async function del(key: string) { if (idbAvailable) return idel(key); return miLocalStorage.removeItem(`${PREFIX}${key}`);