/** * Thin shim over rSpace's local-first storage for markwhen source adapters. * * Keeps adapters free of direct dependencies on the concrete storage class, * so they remain unit-testable with plain in-memory docs. Wire the real * implementation in server/local-first at bootstrap via `setDocLoader`. */ export interface DocLoader { loadDoc(docId: string): Promise; listDocIds(prefix: string): Promise; } let impl: DocLoader | null = null; export function setDocLoader(loader: DocLoader): void { impl = loader; } export async function loadDoc(docId: string): Promise { if (!impl) throw new Error('markwhen doc-loader not wired — call setDocLoader at bootstrap'); return impl.loadDoc(docId); } export async function listDocIds(prefix: string): Promise { if (!impl) throw new Error('markwhen doc-loader not wired — call setDocLoader at bootstrap'); return impl.listDocIds(prefix); }