Files
edentext/tests/fakeIdb.ts
T
Steffen Becker 6abc7f7704 refactor: the kept versions are offered at a failed load, not in the menu
A list of timestamps in both file menus paid for itself only on the day
something went wrong, and it was in the way on every other. The entries
are gone; loadDocument now offers the versions where the browser copy has
actually failed the reader — newest first, one question each, and the one
taken up starts under the boot flag like any other document. The store
loses its reactive singleton with them.
2026-09-04 19:30:13 +02:00

28 lines
1000 B
TypeScript

// A two-call IndexedDB in memory — what openDb/idbRequest (storage/idb.ts) ask for.
export function fakeIndexedDb() {
const data = new Map<number, unknown>();
const req = (result: unknown) => {
const r: Record<string, unknown> = { result };
queueMicrotask(() => (r.onsuccess as (() => void) | undefined)?.());
return r;
};
const store = {
put: (v: unknown, k: number) => { data.set(k, v); return req(undefined); },
get: (k: number) => req(data.get(k)),
getAllKeys: () => req([...data.keys()]),
delete: (k: number) => { data.delete(k); return req(undefined); },
};
const db = { transaction: () => ({ objectStore: () => store }), createObjectStore: () => {}, close: () => {} };
return {
data,
open: () => {
const r: Record<string, unknown> = { result: db };
queueMicrotask(() => {
(r.onupgradeneeded as (() => void) | undefined)?.();
(r.onsuccess as (() => void) | undefined)?.();
});
return r;
},
};
}