Skip to content

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.

DataModel extends GenericDataModel

The Convex data model (inferred from ctx).

Resolved target + merge inputs.

AccessCallOptions<string>

VexApiAuth

VexConfig

GenericMutationCtx<DataModel>

Record<string, unknown>

number

VersionedTargetRows<DataModel>

CollectionOrGlobal

Promise<string>

The draft row’s _id, as a string.

Propagated from prepareEdit on validation failure.

When the caller is not permitted to save this draft.