Files
outline/app/utils/developer.ts
T
Claude 9a3b075bcc refactor: Opt stores into persistence via a persistable property
Stores now declare persistence with `persistable = true` and RootStore
sweeps all persistable stores, deriving each database name from the
store's apiEndpoint, instead of RootStore hard-coding the policies
store. The deleteAllDatabases fallback uses the same sweep.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XisV6sRdexfnPSiehurKoV
2026-08-16 11:56:11 -04:00

51 lines
1.4 KiB
TypeScript

import { flatten } from "es-toolkit/compat";
import stores from "~/stores";
import Store from "~/stores/base/Store";
import StorePersistence from "~/stores/base/StorePersistence";
import { flattenTree } from "@shared/utils/tree";
/**
* Delete all databases in the browser.
*
* @returns A promise that resolves when all databases have been deleted.
*/
export async function deleteAllDatabases() {
if (!window.indexedDB) {
return;
}
const teamId = stores.auth.currentTeamId;
if (teamId) {
Object.values(stores).forEach((store) => {
if (store instanceof Store && store.persistable) {
window.indexedDB.deleteDatabase(
StorePersistence.databaseName(store.apiEndpoint, teamId)
);
}
});
}
if ("databases" in window.indexedDB) {
const databases = await window.indexedDB.databases();
for (const database of databases) {
if (database.name) {
window.indexedDB.deleteDatabase(database.name);
}
}
return;
}
// If the browser does not support listing databases, we need to manually delete as best we can
// by iterating over all known collections and documents.
await Promise.all(
stores.collections.orderedData.map(async (collection) => {
const nodes = flatten(collection.documents?.map(flattenTree));
return nodes.map(async (node) => {
window.indexedDB.deleteDatabase(`document.${node.id}`);
});
})
);
}