Skip to content

refactor: starters, examples and docs read with get/list; read-verbs codemod (3d) - #39

Merged
jherr merged 1 commit into
mainfrom
cursor/read-verbs-migration-d21e
Nov 6, 2026
Merged

jherr merged 1 commit into
mainfrom
cursor/read-verbs-migration-d21e

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements cms-refactor-plan.md § Phase 3 (3d), the "Wrap, migrate, then remove in phase 6" step of item 5. The older verbs stay as wrappers that keep their old defaults.

Merge chain: step 19 of 24. Base: main. Merge it right after #35. The branch is main 3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit 62d6dfe (tree bb98cb3).

What

  • The codemod pnpm codemod read-verbs (scripts/codemods/read-verbs.ts, ts-morph) rewrites:

    • queryDocumentsAs to listAs. It adds populate: false, and turns a one-name collections: [x] into collection: x.
    • readDocumentAs to (await getAs(ctx, { collection, id, populate: false }))?.doc ?? null.
    • readDocumentBySlugAs to an id-first lookup, (await getAs(…, { id: key })) ?? (await getAs(…, { locator: key })), which matches the old behaviour. If the key or context can't safely be written twice, or the read isn't awaited, it falls back to a single locator read with a locator TODO.
    • the deprecated context-free forms, which read as publicContext();
    • cmsAs(cms, ctx) handle methods;
    • imports, including dynamic await import() and code fences in Markdown.

    It adds a // TODO(read-verbs): … and a warning in four cases:

    • overlay: the context isn't provably live.
    • limit: the result now stops at 100.
    • dynamicLimit: a non-literal limit, which may exceed list's maximum of 500.
    • shape: the code reads title or published.

    It leaves the call alone, with a warning, for:

    • findDocumentBySlug(As);
    • full-text query;
    • a multi-name collections;
    • unknown keys;
    • limits over 500;
    • spread options;
    • unawaited reads;
    • aliased imports;
    • nested reads.

    The fixtures cover each case, including the locator fallback.

  • Hand migration, limited to read call sites:

    • Starters: documentation-kb, ecommerce-storefront, editorial-publication, membership-course, multi-tenant-fleet and runtime-tables, plus their CMS-INTEGRATION.md files.
    • Examples: blog-voting, db-markdown, and the four *-after parity tests. The parity tests went through the codemod and were then tidied.
    • app/base: the dashboard reports and report rows. Unit and E2E tests check that a scoped session can't call get/list, and that an anonymous GET /api/cms/v1/ops/list gets 401.
    • CLI: atproto publish reads with getAs(publicContext()) (patch changeset).
    • Skills: voting and the four migration skills.
  • Docs: building-pages.md (with new type-checked snippets), cms-core-server.md, cms-api.md, routes-and-endpoints.md, operations-registry.md, cli.md, data-layer.md, terminology.md, the migration pages, and two upgrading steps (5, and this PR's get/list step).

  • The dialect baseline drops from 221 to 171 non-test matches (table below). No marker retires.

Breaking changes

None in published packages. Two changes affect starter code that apps copy:

  • multi-tenant-fleet: listTenantPages/listTenantAssets items are { id, collection, doc }, with no title or published. The starter's tests and UI only use id and doc.
  • blog-voting: getTopPosts derives title from doc.title, falling back to the id, as before.

Sites left on the older verbs, and why

  • Reads that feed a write in an edit or system context. get would overlay staged changes, but the write has to see the stored row. These are:

    • the ecommerce carts;
    • membership enrolment;
    • sendNewsletterIssue;
    • claimListing;
    • the blog-voting votes;
    • the app/base read-modify-writes;
    • the app/prm import and scripts.

    5a (feat(core,api,client): writes as document state strategy actions — save and act, rooted in the operations registry (5a) #40) adds get({ staged: false }) for Phase 6 to move these to.

  • multi-tenant-fleet readTenantPage: an edit-mode read whose result the overlay would change.

  • getPublicDocument / findDocumentBySlugAs with preferred: a cross-collection lookup, which get can't express.

  • Admin editor reads, package internals and package tests. Phase 6 handles these.

  • Storage-adapter calls and ScopedCmsClient methods.

  • app/base/scripts/smoke-docker.mjs: it needs Docker.

Dialect inventory (non-test matches; test counts in brackets)

Marker Baseline before At 3b head After
queryDocuments 98 (20) 96 (24) 75 (24)
readDocument 24 (9) 24 (12) 18 (12)
readDocumentBySlug 13 (7) 13 (13) 10 (13)
findDocumentBySlug 9 (1) 9 (3) 9 (3)
getPublicDocument 31 (13) 30 (13) 23 (13)
listPublishedDocuments 46 (20) 46 (22) 36 (22)
Total 221 (70) 218 (87) 171 (87)

queryDocuments and readDocument no longer appear in starters, examples or .claude/skills.

How verified

GitHub Actions is out of billing, so everything ran locally. On a scratch branch, I merged 77e80a9 into origin/main at 3b4a112. The only conflict was scripts/codemods/index.ts, where I kept all four codemods. I then added the docs-only d951055 and reran kiira and both E2E suites.

Check Result
pnpm install --frozen-lockfile passes
pnpm test:ci (174 tasks) Only the known @tanstack/cms-api:test:oxlint fails. Core 595 (30 skipped), api 207, client 35, CLI 25, base 42, prm 9, blog-voting 8, *-after 5 each, all 13 starters, kiira 127/127.
pnpm test:dts clean
pnpm test:dialects exits 0 against the new baseline
pnpm test:scripts 72 pass, including the codemod fixtures
pnpm test:definitions Not run then, because the script arrives with 1e (#24/#25). On the merge chain, which includes #24 and #25, it passes 26/26.
E2E blog / base 28 / 12 pass

Assumptions (conservative defaults where the plan gives none)

  • The codemod pins populate: false, so migrated results keep relation ids.
  • A read that feeds a write stays on readDocumentAs in edit and system contexts. List reads migrate in any mode, because listAs reads what queryDocumentsAs read.
  • "Return every match" becomes a cursor loop of 500 per page, not a larger limit.
  • A lookup that can receive an id reads by id first, then by locator. That applies to blog-voting resolvePost, the voting skill and the codemod's output. Under 3c(i) (feat(core)!: locators — locatorStrategy, nested slugs, a unique per-locale locator index, and get({ locator }) through it (3c(i)) #38), a locator is the slug, or the id only when there's no slug, so these lookups keep working. Sites whose key is always a URL slug use locator alone: the emdash parity test and the building-pages.md examples.
  • The codemod skips package internals and package tests. It has no changeset, because scripts/ isn't published.

Divergence from plan

  1. Not every read moves to get. The sites listed above keep their old verbs, because get would change the result or has no equivalent.
  2. The dialect baseline drops without a marker retiring. On the merge chain the baseline is regenerated at this step.
  3. A 3b doc sentence is corrected: list returns committed documents and doesn't overlay staged changes.
  4. The migrated *-after tests drop the codemod's populate: false where they only read counts or fields.

Follow-up (b4e4171, a fast-forward from d951055)

The cross-stack integration rehearsal found that, combined with #38, blog-voting's get({ locator: postId }) fails all 8 of its tests.

  • 2be56ab: blog-voting resolvePost and the voting skill look up by id, then by locator.
  • 197be9c: the codemod's readDocumentBySlug(As) rewrite emits the same two-step lookup. The fixtures are updated, and there's a new fallback case.
  • b4e4171: three doc sentences no longer describe a locator read as slug-or-id (cms-core-server.md, building-pages.md, and the get/list upgrading step).

Verification on b4e4171:

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. Five conflicts: the emdash and payload skills, cms-core-server.md, from-sanity.md and scripts/codemods/index.ts. The dialect baseline is refreshed.

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 new main; that rebase is always clean.

Open in Web Open in Cursor 

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Explain Change →

Caution

Review failed

The pull request is closed.

TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.

  • Ask an admin to upgrade

Open in CodeRabbit

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 79e3126

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/cms-cli Patch
@tanstack/cms-api Patch
@tanstack/cms-client Patch
@tanstack/cms-core Patch
@tanstack/cms-media-s3 Patch
@tanstack/cms-store-libsql Patch
@tanstack/cms-ui-react Patch
@tanstack/cms-connect-atproto Patch
@tanstack/cms-migrate-wp Patch
@tanstack/cms-skills Patch
@tanstack/search-cms Patch
@tanstack/cms-store-postgres Patch
@tanstack/cms-ui-dom Patch

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

cursor Bot pushed a commit that referenced this pull request Nov 6, 2026
…tion rehearsal

Co-authored-by: jherr <jherr@pobox.com>
@cursor
cursor Bot force-pushed the cursor/read-verbs-migration-d21e branch from b4e4171 to 62d6dfe Compare November 6, 2026 14:50
@cursor
cursor Bot force-pushed the cursor/populate-sidecar-a931 branch from 3aecfb8 to 35ed2e9 Compare November 6, 2026 14:50
@cursor
cursor Bot changed the base branch from cursor/populate-sidecar-a931 to main November 6, 2026 14:57
…codemod (3d) (#39)

Chain step 19 of the linear merge chain onto main 3b4a112: this PR's own changes, resolved against the PRs before it in the merge order.

Co-authored-by: jherr <jherr@pobox.com>
@jherr
jherr force-pushed the cursor/read-verbs-migration-d21e branch from 62d6dfe to 79e3126 Compare November 6, 2026 15:09
@jherr
jherr merged commit 1d3937e into main Nov 6, 2026
1 check passed
@jherr
jherr deleted the cursor/read-verbs-migration-d21e branch November 8, 2026 01:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants