export type ItemAttributes = { readonly cdat: number; readonly mdat: number; }; export type ApprovalEntry = ItemAttributes & { readonly value: string; readonly readStartedAt: number; }; export type ApprovalAnswer = { readonly kind: "approved"; readonly value: string; readonly attributes: ItemAttributes; } | { readonly kind: "denied"; } | { readonly kind: "missing"; }; export type ApprovalClock = { readonly nowSeconds: () => number; readonly sleepMs: (ms: number) => Promise; }; /** * A cached `approve` answer serves a read only while `` is exactly the item that answer read: equal `cdat` and `mdat`, * and `floor(mdat) < floor(readStartedAt)` so any write after the approval read started (which lands in that second or * later) invalidates it. A clock that went backwards since then drops the entry (design 3.5). */ export declare function isEntryValid(entry: ApprovalEntry, current: ItemAttributes, nowSeconds: number): boolean; export type ApprovalCache = ReturnType; /** * One cache per process (design 3.2 step 3; addendum rows 12, 13, 22, 23): the validated answer, the one in-flight * `approve` every caller attaches to, and a remembered "Deny" that only background paths honor. */ export declare function createApprovalCache(clock?: ApprovalClock): { consume(current: ItemAttributes): string | null; deniedForBackground: () => boolean; /** * Runs `approve` at most once at a time per process: later callers attach to the pending answer instead of opening a * second dialog, and a late answer still fills the cache after a caller's bounded wait expired (3.2 step 4). */ /** The `approve` already running in this process, which a new caller attaches to before taking any lock. */ inFlight: () => Promise | null; approve(run: () => Promise): Promise; /** * After this process wrote a non-owned item under the session lock, keep serving it: take the written value, hold * the lock until the clock has left the write's second, then re-stamp from a fresh attribute read. Any later foreign * write lands in a later second and fails validation (3.2 step 3, "This process's own writes keep it valid"). */ afterOwnWrite(value: string, readAttributes: () => Promise): Promise; drop(): void; }; export declare const processApprovalCache: () => ApprovalCache;