saveDraftShared
saveDraftShared<
DataModel>(props):Promise<string>
Defined in: packages/core/src/versions/saveDraft.ts:47
Kind-agnostic saveDraft implementation shared by both versioned
collections and versioned globals. Every per-kind difference — which table
the rows live in, how a row’s user fields are extracted, and how a draft
row’s insert/patch payload is shaped (flat on a collection row, nested
under data on a vex_globals row) — is already resolved into rows
(see resolveVersionedTarget); this function never branches on
target.kind itself.
Mirrors the original collection-only saveDraft (and upsertGlobal’s
former versioned-draft branch) step for step: bootstrap (or reuse) the
draft row, snapshotting the pre-edit published state the first time a
draft branches off it; run the shared prepareEdit merge/validate
pipeline against the draft row’s stored content; patch the draft row; and
record one "draft"-status history row.
Authorization is evaluated against the STORED draft row, never
against the incoming payload — prepareEdit passes changes: data to
hasPermission internally, which is what lets a field-level permission
map deny individual keys.
Stamps only on: "all" commitTs fields — on: "save"/on: "publish"
fields are untouched; an autosave tick is not a real edit of the live
document.
Type Parameters
Section titled “Type Parameters”DataModel
Section titled “DataModel”DataModel extends GenericDataModel
The Convex data model (inferred from ctx).
Parameters
Section titled “Parameters”Resolved target + merge inputs.
access?
Section titled “access?”AccessCallOptions<string>
config
Section titled “config”GenericMutationCtx<DataModel>
Record<string, unknown>
restoredFrom?
Section titled “restoredFrom?”number
VersionedTargetRows<DataModel>
target
Section titled “target”Returns
Section titled “Returns”Promise<string>
The draft row’s _id, as a string.
Throws
Section titled “Throws”Propagated from prepareEdit on validation failure.
Throws
Section titled “Throws”When the caller is not permitted to save this draft.