// Stops one device from silently overwriting a study another device has saved since. The browser sends // the `lastEdited` of the server copy it last saw (X-Base-Edited); if the server's copy has moved past // that, the save is refused with 409 and the person chooses whose version to keep. // stored: the server copy's lastEdited (null when there is none); base: what the client last saw // (null/undefined when it never synced this study); force: the person chose "keep mine". export function isSaveConflict({ stored, base, force = false }) { if (force || stored == null) return false; if (!Number.isFinite(base)) return false; // a device that never saw the server's copy has nothing to compare return stored > base; } // Reads the base header; anything that isn't a plain number is treated as "unknown". export function parseBase(header) { if (header == null || header === '') return null; const n = Number(header); return Number.isFinite(n) ? n : null; }