@lobehub/chat
Version:
Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.
27 lines (22 loc) • 823 B
text/typescript
import { createStore, delMany, getMany, setMany } from 'idb-keyval';
import { StorageValue } from 'zustand/middleware';
export const createIndexedDB = <State extends any>(dbName: string = 'indexedDB') => ({
getItem: async <T extends State>(name: string): Promise<StorageValue<T> | undefined> => {
const [version, state] = await getMany(['version', 'state'], createStore(dbName, name));
if (!state) return undefined;
return { state, version };
},
removeItem: async (name: string) => {
await delMany(['version', 'state'], createStore(dbName, name));
},
setItem: async (name: string, state: any, version: number | undefined) => {
const store = createStore(dbName, name);
await setMany(
[
['version', version],
['state', state],
],
store,
);
},
});