MCPcopy Create free account
hub / github.com/HelloCSV/HelloCSV / setIndexedDBState

Function setIndexedDBState

src/importer/storage.ts:45–72  ·  view source on GitHub ↗
(
  state: ImporterState,
  customKey?: string | null
)

Source from the content-addressed store, hash-verified

43}
44
45export async function setIndexedDBState(
46 state: ImporterState,
47 customKey?: string | null
48): Promise<void> {
49 return new Promise((resolve, reject) => {
50 const key = stateKey(state.sheetDefinitions, customKey);
51 const value = { ...state } as any;
52 delete value.sheetDefinitions; // sheetDefinitions have functions within, this should not be saved in the database
53 const request = indexedDB.open(DB_NAME, DB_VERSION);
54
55 request.onerror = () => reject(request.error);
56 request.onsuccess = () => {
57 const db = request.result;
58 const transaction = db.transaction(STORE_NAME, 'readwrite');
59 const store = transaction.objectStore(STORE_NAME);
60 const putRequest = store.put(value, key);
61
62 putRequest.onerror = () => reject(putRequest.error);
63 putRequest.onsuccess = () => resolve();
64 };
65 request.onupgradeneeded = (event) => {
66 const db = (event.target as IDBOpenDBRequest).result;
67 if (!db.objectStoreNames.contains(STORE_NAME)) {
68 db.createObjectStore(STORE_NAME);
69 }
70 };
71 });
72}
73
74function stateKey(
75 sheetDefinitions: SheetDefinition[],

Callers 2

buildStateWithIndexedDBFunction · 0.90
usePersistedReducerFunction · 0.90

Calls 1

stateKeyFunction · 0.85

Tested by

no test coverage detected