Skip to content

feat!: get/list populate relations by default — depth 1, batched, cycle-safe, with typed related() (3b) - #35

Merged
jherr merged 1 commit into
mainfrom
cursor/populate-sidecar-a931
Nov 6, 2026
Merged

jherr merged 1 commit into
mainfrom
cursor/populate-sidecar-a931

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements cms-refactor-plan.md § Phase 3 (3b): item 6 ("populated reads and agent defaults"), item 5's MCP default override, question 15 (option B, the relations sidecar) and question 16 (option ii).

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

What

  • Populated by default on the new verbs only.
    • get and list return related documents under relations, keyed by relation field path (author, seo.image, blocks.2.author). doc keeps the ids exactly as stored.
    • This applies on every surface: the store, HTTP, Start and the client.
  • Depth 1 and cycle-safe. Related documents come back as stored, without nested relations.
  • Batched.
    • resolveRelationsAs(ctx, items, select) groups every relation id on a page by target collection. It reads each target collection once with storage.getDocuments, in chunks of 500 ids.
    • So a 23-item page whose posts all point at authors costs one storage read.
    • queryDocumentsAs({ populate }) and populateRelationsAs use it too.
  • Missing, trashed and hidden targets are all null, or are dropped from a many array. A reader can't tell hidden from missing. Every related document is read and redacted the way the context reads.
  • Selection:
    • populate takes true, false, or an array of paths, using the new PopulateSelection type.
    • The older verbs keep populate off by default.
  • Typed related(result, path):
    • It's exported from @tanstack/cms-core, and from @tanstack/cms-client as a local copy.
    • For a top-level relation of a registered collection, it returns RegisteredDoc<Target> | null, or Array<…> | null for many.
    • ReadResult and ListResult gain a collection type parameter.
  • Agent defaults (Q16, option ii):
    • get_document populates.
    • list_documents and search_documents return ids unless the agent passes populate.
    • The override lives in the code that derives the agent tools from the registry; the canonical bags are unchanged.
  • Old defaults kept. listPublishedDocuments doesn't populate. The deprecated read_document still returns the bare document.
  • Docs: the core-server, core, client, routes and operations-registry pages are updated. Upgrading gains a new step, step 28 on the merge chain.
  • Changeset: .changeset/populate-sidecar.md, minor for core, api and client.

Breaking changes

  • New default. The new verbs and get_document return relations by default. Pass populate: false to get the 3a shape.
  • Trashed relations. A relation to a trashed document is now null, or is dropped from a many array. It used to come back with a deletedAt stamp, because storage.getDocuments doesn't filter trashed rows. This applies to every verb with populate.
  • Unreadable collections. A relation into a collection the reader can't read is null (or []) instead of being left out, per the plan's "existence doesn't leak" rule. The 2c assertions in access-context.test.ts and field-access.test.ts are updated.

How verified

  • Core tests/read-verbs.test.ts (19 tests) covers:
    • the populated default and opting out;
    • path selection;
    • depth 1 with an A↔B cycle and a self-reference;
    • trashed, purged, draft and hidden-collection targets;
    • batching (one getDocuments call per target collection, checked with a spy);
    • the agent defaults and the registry derivation.
  • Api tests: HTTP get/list populate for an anonymous reader.
  • Client: tests for populate, plus type tests for related().
  • Payload measurements for the task 9 revisit: JSON bytes with populate off and on, read with publicContext().
Fixture list off list on get off get on
PRM person (13) 17,317 21,851 1,907 2,721
PRM talk (9) 3,106 17,227 370 2,468
PRM personSource (6) 1,838 11,743 343 2,221
ecommerce variant (30) 6,112 12,352 — —

Small lists that point at a person grow 5–7×, because each related person is a large document. So the ids-only default for list_documents and search_documents still looks right. At these sizes, populated lists take under 2 ms.

  • Local CI (GitHub Actions is out of billing): on a scratch branch, I merged head 3aecfb8 into origin/main at 3b4a112. The only conflict was scripts/codemods/index.ts, where I kept both codemods.
Check Result
pnpm install --frozen-lockfile passes
pnpm test:ci (174 tasks) Only the known @tanstack/cms-api:test:oxlint failure on a type cast. Core 595 passed (30 skipped), api 207, client 35.
pnpm test:dts clean (225)
pnpm test:dialects exits 0
pnpm test:scripts 66 pass
E2E blog / base 28 / 12 pass

Assumptions (conservative defaults where the plan gives none)

  • Path selection:
    • Paths match by prefix. [] means none.
    • A selection holds at most 64 paths.
  • related() types: many relations type as Array<…> | null, and nested paths as Doc | Array<Doc> | null.
  • The client's related is a local one-line copy, so the client still imports only types from core.
  • No codemod.

Divergence from plan

  1. The plan's "read_document populated" is implemented on get_document, the canonical tool per Q18. The deprecated read_document stays bare.
  2. related() types are slightly wider than the plan's examples: | null on many, and arrays on nested paths.
  3. Related documents aren't deduplicated across list items (question 15a). That stays a later transport optimization.

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. Two conflicts: the get and list rows in routes-and-endpoints.md, and upgrading step 28.

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

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: TanStack/cms
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 1bd8f7e
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Free
  • Run ID: 75f08abf-5e74-49f8-8fdf-ff6418276efd
Commits

Reviewing files that changed from the base of the PR and between 1bd8f7e and 7bfcfe5.

Files selected for processing: 24

  • .changeset/populate-sidecar.md
  • docs/api/cms-client.md
  • docs/api/cms-core-server.md
  • docs/api/cms-core.md
  • docs/api/routes-and-endpoints.md
  • docs/deployment/upgrading.md
  • docs/mcp/operations-registry.md
  • packages/api/src/ops.ts
  • packages/api/tests/read-verbs.test.ts
  • packages/client/src/client.ts
  • packages/client/src/index.ts
  • packages/client/tests/client.test.ts
  • packages/client/tests/register.test.ts
  • packages/core/src/index.ts
  • packages/core/src/ops.ts
  • packages/core/src/related.ts
  • packages/core/src/server/cms-as.ts
  • packages/core/src/server/cms-ops.ts
  • packages/core/src/server/store/query.ts
  • packages/core/src/server/store/read.ts
  • packages/core/src/server/store/verbs.ts
  • packages/core/tests/access-context.test.ts
  • packages/core/tests/field-access.test.ts
  • packages/core/tests/read-verbs.test.ts

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: 7bfcfe5

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-core Minor
@tanstack/cms-api Minor
@tanstack/cms-client Minor
@tanstack/cms-cli Minor
@tanstack/cms-connect-atproto Patch
@tanstack/cms-migrate-wp Patch
@tanstack/cms-skills Patch
@tanstack/cms-media-s3 Minor
@tanstack/search-cms Patch
@tanstack/cms-store-libsql Minor
@tanstack/cms-store-postgres Patch
@tanstack/cms-ui-dom Patch
@tanstack/cms-ui-react Minor

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

…le-safe, with typed related() (3b) (#35)

Chain step 18 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/populate-sidecar-a931 branch from 35ed2e9 to 7bfcfe5 Compare November 6, 2026 15:09
@jherr
jherr merged commit 282f2a9 into main Nov 6, 2026
1 of 3 checks passed
@jherr
jherr deleted the cursor/populate-sidecar-a931 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