/** * Page-scoped request store (ADR-SVC-0011 addendum 2026-11-14): pieces of one * page that send the same request share one in-flight request, one outcome and * one retry. Pure TypeScript, memory only: entries live while they have * subscribers and are never persisted, logged or read by key from outside. * * Optional retention (ADR-SVC-0016, decisions 5-8): a store created with * `retain` keeps settled entries that pass `keep` after their last subscriber * leaves (at most `max`, least recently used out) and serves them again * without a request. `clear()` flushes the store. */ /** A started request: the promise never needs to reject, and `abort` cancels it. */ export type RequestRun = { promise: Promise; abort: () => void; }; export type RequestEntry = { status: 'loading'; } | { status: 'settled'; settled: Settled; }; export type RequestStoreOptions = { /** * Keep settled entries without subscribers: at most `max` of them, least * recently used out, and only those for which `keep` is true (an error * outcome is never kept). */ retain?: { max: number; keep: (settled: Settled) => boolean; }; }; export type RequestStore = { /** * Subscribes to `key`. The first subscriber starts `run`; later ones share * it. `listener` is called right away with the current entry and on every * change. Returns the unsubscribe function. */ subscribe: (key: string, run: () => RequestRun, listener: (entry: RequestEntry) => void) => () => void; /** Re-runs a settled entry once for all of its subscribers; no-op otherwise. */ retry: (key: string) => void; /** * Flushes the store: entries without subscribers are deleted; entries with * subscribers are restarted once (their older request is aborted and its * answer discarded) and their subscribers go back to loading. */ clear: () => void; /** Number of entries, subscribed or retained. Keys are never exposed. */ size: () => number; }; export declare const createRequestStore: (options?: RequestStoreOptions | undefined) => RequestStore;