// `loadWebStore` is the [StoreLoader] used by the browser build
// target. It opens the shared `galaxy-ui` IndexedDB connection and
// hands the same handle to both the keystore and the cache, so the
// page boots one DB connection regardless of which subsystem touches
// storage first.

import type { Store, StoreLoader } from "./index";
import { dbConnection } from "./idb";
import { IDBCache } from "./idb-cache";
import { WebCryptoKeyStore } from "./webcrypto-keystore";

export const loadWebStore: StoreLoader = async (): Promise<Store> => {
	const db = await dbConnection();
	return {
		keyStore: new WebCryptoKeyStore(db),
		cache: new IDBCache(db),
	};
};
