Every document-scoped key now goes through docKey(), which hangs it off the tab's document id; the first document keeps the empty id, so existing browser copies read back unchanged. A fresh tab takes up the most recently used document no live tab holds, else starts a new one — one signed timestamp per document (edentext-live@id) says which, written only by the tab holding it. Snapshots and embedded fonts get a database per document. The picture store stays shared and content-addressed, so its sweep now drops only keys no stored document names any more, instead of the open document's own.
28 lines
1020 B
TypeScript
28 lines
1020 B
TypeScript
// A two-call IndexedDB in memory — what openDb/idbRequest (storage/idb.ts) ask for.
|
|
export function fakeIndexedDb() {
|
|
const data = new Map<IDBValidKey, 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: IDBValidKey) => { data.set(k, v); return req(undefined); },
|
|
get: (k: IDBValidKey) => req(data.get(k)),
|
|
getAllKeys: () => req([...data.keys()]),
|
|
delete: (k: IDBValidKey) => { 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;
|
|
},
|
|
};
|
|
}
|