Repository navigation
feat(core,api,client): writes as document state strategy actions — save and act, rooted in the operations registry (5a) - #40
Merged
Conversation
🦋 Changeset detectedLatest commit: a6879ed The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. Next included review available in 59 minutes. View limit details
TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.
|
cursor
Bot
force-pushed
the
cursor/phase-4d-default-flow-02f8
branch
from
November 6, 2026 14:50
029b9bf to
b27fa37
Compare
cursor
Bot
force-pushed
the
cursor/write-actions-02f8
branch
from
November 6, 2026 14:50
013cd74 to
3dbbd75
Compare
cursor
Bot
changed the base branch from
cursor/phase-4d-default-flow-02f8
to
main
November 6, 2026 14:56
jherr
force-pushed
the
cursor/write-actions-02f8
branch
from
November 6, 2026 15:08
3dbbd75 to
a6879ed
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements cms-refactor-plan.md § Phase 5 (5a).
save()stays as sugar and returns{ doc, state, availableActions }.createDoc,saveDocandcreate_documentare unified.Merge chain: step 17 of 24. Base:
main. Merge it right after #34. The branch ismain3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit3dbbd75(tree0e2330b).What
A write registry beside
readVerbs.writeVerbsin@tanstack/cms-coredeclaressaveandact, with their schemassaveInputandactInput.save_documentagent tool, the HTTP op descriptions andopSchemasall derive from it.satisfies Record<WriteVerbName, CmsOperation>.actisagent: false, so it gets no agent tool.save({ collection, id, doc, create?, publish?, expectedRevision?, expectedPendingVersion?, instruction? })merges thedocpatch onto the caller's own open change set, or onto the live document. It then picks the action:submits.publishis ignored.edits. On a published document that's a draft, unlesspublishis set; withpublishset, or on a document that isn't published, it's a commit.submits.The strategy then decides.
create: truerefuses an id that already exists or is already proposed, withCONFLICT.actruns an offered action that carries no document:approve,reject,discard,schedule, or a custom step.FORBIDDEN.edit,submit,draftandimportfail withBAD_REQUEST, because they go throughsave.expectedVersionfails withCONFLICT.Both return
{ id, collection, doc, state, availableActions }.stateis{ label, published, revision, changeSet: { id, version, source, publishAt } | null }.docis what the caller now sees, redacted. It'snullafter a rejected create.documentWriteState(collection, id)readsstateon its own.gettakesstaged?: boolean(added in follow-up commits, see below). Withstaged: false, an edit or preview reader gets the committed row.Every surface:
cmsAs(cms, ctx).save/act,saveAs,actAs;saveop (content.write) and theactop;client.save/client.act;save_document.One write path.
createDoc,saveDoc,create_document,update_documentandactOnChangenow run onrunSave/runAct. They keep their bags, defaults and result shapes. They're deprecated, and Phase 6 removes them.Docs:
cms-core-server.mdandcms-client.md(both with type-checked examples), the op tables, and a new upgrading step (step 27 on the merge chain).Breaking changes (
write-verbs-save-act.md: core, api and client minor)save,actandsave_documentare now reserved operation names.saveDoc,createDoc,actOnChange,create_document,update_document.Merging 3a: conflicts between 2c/3a and 4a–4d
Textual conflicts (11 files):
core/src/server/store/review.tsreadDocumentAswith named system contexts.STAGE_BEFORE_READis now defined here.core/src/server/store/write.tssessionnow reachesafterChange/afterDeletethroughexecuteStrategyWriteanddeleteDocument.core/src/server/store/scheduling.tsapi/src/ops.tsOP_READ. 3a'sget/listsit beside 4c'sactOnChange.docs/deployment/upgrading.mdstore,plugins,readinesstests…As(systemContext('test')).characterization/workflow-suite.tscharacterization/save-paths.test.tsrunOptakes a context.app/prm/tests/crm.test.tsSemantic conflicts found after the textual merge:
systemContext('test').afterChangegets the writer's session fromexecuteStrategyWrite, so hooks see the same session on every write path.app/prm/bakeoff. Kept 3a's regenerated files.How verified
GitHub Actions is out of billing, so everything ran locally, on scratch merges into
origin/main3b4a112. The only merge conflict wasscripts/codemods/index.ts, between 2c and #22, and both codemods were kept. The latest run was at013cd74.pnpm install --frozen-lockfilepnpm test:ci(174 tasks, cold cache)@tanstack/cms-api:test:oxlinttest:dts/test:dialectstest:scriptsPackage suites: core 655, api 216, client 35, ui-react 85, app/prm 10. Core
tsc, knip,test:docsand kiira (132/132) are clean.New tests:
write-verbs.test.ts:CONFLICTs;actAs's cases;doc: null;staged: falsefor a pending update, a pending create, an unpublished row, a live reader and the agent tool.write-verbs.test.ts:getwithstaged: false.Assumptions (tasks 8–12 defaults)
actis not an agent tool. Agents propose and people decide. Exposing it later is one registry flag.actop is gated oncontent.read. Each action is then checked against what the strategy offers.by: 'human'.submit.savemerges a patch, withnullto clear a field.?staged=falsequery string isn't parsed as a boolean, the same aspopulatetoday, so HTTP callers send it as JSON.Divergence from plan
savetakescreate: trueinstead.actOnChange's error messages changed slightly. The codes are the same.save/actop keys are written out by hand, typed against the registry withsatisfies.staged: falseis a per-verb option.terminology.mdsays the choice between live and working copy is made by the context's read mode, "not a boolean". A third read mode would reachlist, populate, slug lookup and search. This option touches one verb, and only narrows what an edit or preview reader already sees.Reading the committed row (follow-up, two fast-forward commits)
#39 (3d) leaves read-modify-write sites on
readDocumentAs. In edit and system contexts,getoverlays staged changes, but these writes need the stored row.save's patch merge can't replace these reads, for three reasons:savemerges onto the caller's working copy, so a system write that publishes would also publish someone's open draft.getmisses unpublished rows.So
get({ staged: false })is the canonical form. In Phase 6,readDocumentAs(ctx, c, id)becomes(await getAs(ctx, { collection: c, id, staged: false, populate: false }))?.doc ?? null, which is the shape #39's codemod already writes. Each #39 site maps to that form:addToCartandcheckoutCartget({ staged: false })in a system context; the write stays a full-row commitcompleteLessonAndQuizget({ staged: false })in a system contextsendNewsletterIssueget({ staged: false })inctx.access, not asavepatch, which would publish the caller's open draftclaimListingget({ staged: false })in a system context;stageWritestaysget({ staged: false })with theVOTESsystem contextapp/basecommitted(),submitReport, WordPress evacuationget({ staged: false })withCHECKEDapp/prmimport_peopleand both scriptsget({ staged: false })in a system contextreadTenantPageget({ staged: false })inctx.access; this keeps today's resultNo
getform coversincludeDeleted(trash reads).A test merge of 3b (#35) over
013cd74is clean inops.tsandverbs.ts.For DocForm (#33)
onSubmit(patch, { doc, baseline, meta })can call:The result's
docbecomes the next baseline, andstate/availableActionsdrive the badge and buttons.Merge chain (local verification, CI down)
This PR's commits are squashed into one commit on the linear merge chain. That commit holds this PR's own changes, resolved against every PR before it, with the integration rehearsal's fixes for this PR applied. No conflicts. The commit was replayed from this PR's merge of 3a (
32d8e18). Its upgrading section is renumbered to step 27.The step numbers in the upgrade guide used to collide across 3a, 3b, 3c(i), 3d and 5a. The chain renumbers them in merge order, so that clean-up is done.
The chain tip's tree is exactly the integration rehearsal plus #46 (
c4e6d7c), and the tip passes the full local suite. I simulated merging every PR in order, with a merge commit or a fast-forward at each step, and every step is clean. A plain squash of the next PR would conflict, because the squash commit isn't an ancestor of the next branch. To squash instead, first rebase the branch's one commit onto the newmain; that rebase is always clean.