assertFreshBase
assertFreshBase(
props):void
Defined in: packages/core/src/db/staleWrite.ts:160
Rejects a write whose caller edited a stale copy of a field — the stale-write guard’s one
rule, run inside the writing mutation so no other write can land between the check and the
write. Callers run it after prepareEdit, so the caller’s permission is checked first and
a denied caller learns nothing about stored values.
A key is checked only when it is named in base AND present in next (the write sets
it). It conflicts when the stored value’s fingerprint differs from base[key] AND the
stored value differs from the one the write stores — two writers saving the same value
never conflict, including two writers clearing the same field.
commitTs fields are skipped: they are not editable, and readers see them converted to ms.
Parameters
Section titled “Parameters”VexWriteBase | undefined
The caller’s base, or undefined to skip the check.
documentId?
Section titled “documentId?”string
The id of the row stored was read from, returned in the error so
a client looking at a different row of the same document (the published row, after
someone else started a draft) can switch to the row that holds the newer values.
fields
Section titled “fields”Record<string, AdminField>
The collection’s or global’s field map.
Record<string, unknown>
The values the write stores, keyed by field, as prepareEdit resolved
them (so a null that unsets a non-nullable field is undefined, matching a stored
absent key, while a nullable field keeps null). Build it with fieldsSetByPatch
or fieldsSetByReplace.
stored
Section titled “stored”Record<string, unknown>
The stored user fields the write merges onto.
Returns
Section titled “Returns”void
Throws
Section titled “Throws”{ code: "STALE_WRITE", message, fields, documentId? }, listing every
conflicting key.