You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit c4c810f
Browse filesBrowse the repository at this point in the historyBrowse files
`get` and `list` populate relations by default. The related documents come back beside each document under `relations`, keyed by relation field path (`author`, `blocks.2.author`), while `doc` keeps the ids. Population is one level deep, so cycles and self-references can't recurse, and it is batched: a page costs one storage read per target collection. Read a relation with the new `related(result, path)` (from `@tanstack/cms-core` and `@tanstack/cms-client`), typed from `Register`. `get`/`list` results are typed with their collection name.
8
+
9
+
`populate` takes `false` (ids only), `true`, or a list of paths (`['author', 'blocks']`), on every verb that accepts it. The agent tools `list_documents` and `search_documents` return ids unless the agent passes `populate`; `get_document` populates like `get`. The older verbs still populate only when asked.
10
+
11
+
**Breaking:**
12
+
13
+
-`get`, `list`, `client.get/list`, the `get`/`list` operations and `get_document` return `relations` unless called with `populate: false`.
14
+
- Populated relations skip trashed documents: a relation to one is `null` (dropped from a `many` array), like a missing document.
Copy file name to clipboardExpand all lines: docs/api/cms-client.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,19 +70,22 @@ console.log(`${items.length} of ${total} posts`)
70
70
The canonical reads, the `get` and `list` operations. They take the same bags as [`getAs` and `listAs`](./cms-core-server#getasctx-options-and-listasctx-options) on the server, and their document types come from `Register`.
`get` resolves to `{ id, collection, doc }`, or `null` when the document is missing or the caller can't see it. `list` resolves to `{ items: [{ id, collection, doc }], total, nextCursor? }`. Both are public: anonymous callers read published documents, and callers who may read drafts see the working copy unless the client's `mode` is `live`.
86
+
`get` resolves to `{ id, collection, doc, relations }`, or `null` when the document is missing or the caller can't see it. `list` resolves to `{ items: [{ id, collection, doc, relations }], total, nextCursor? }`. Both are public: anonymous callers read published documents, and callers who may read drafts see the working copy unless the client's `mode` is `live`.
87
+
88
+
Relations are populated by default, one level deep, under `relations` keyed by field path; `doc` keeps the ids. `related(result, path)` reads one back, typed from `Register` (the target's document type, an array for `many: true`, `null` when missing or hidden). Pass `populate: false` for ids only, or an array of paths (`populate: ['author']`) to populate just those.
interface ListResult<TDoc = Doc, C extends string = string> {
167
+
items: Array<ReadResult<TDoc, C>>
166
168
total: number
167
169
nextCursor?: string
168
170
}
@@ -175,16 +177,24 @@ The canonical reads. One bag each, the same at every layer: the store (`cmsAs(cm
175
177
176
178
A`locator`isthedocument's slug or its id, with leading slashes ignored. A document that is missing, or that `ctx` can'tsee, is`null`from`get`andabsentfrom`list`. Documentsareredactedfor`ctx`, andfilteringorsortingonafielditcan't read is `FORBIDDEN`. Both functions validate the bag (`getInput`, `listInput` from `@tanstack/cms-core`) and throw `BAD_REQUEST` for an invalid one.
Bothverbspopulaterelationsbydefault. Therelateddocumentscomebackbesidethedocument, under`relations`, keyedbyrelationfieldpath (`author`, `seo.image`, `blocks.2.author`); `doc`keepstheids. Populationisoneleveldeep: arelateddocument's own relation fields stay ids, so cycles and self-references can'trecurse. Arelateddocumentisreadandredactedas`ctx`readsit. Amissing, trashedorhiddentargetis`null`, ordroppedfroma`many`array, andarelationintoacollection`ctx`can't read is left out. `list` batches the reads: one storage read per target collection for the whole page, not one per row. Pass `populate: false` for ids only, or an array of paths to populate just those (and the relations under them). `related(result, path)` from `@tanstack/cms-core` reads one relation back, typed from `Register`: a registered relation field gives the target'sdocumenttype, oranarrayfor`many: true`.
collections?: Array<string> // restrict a cross-collection query
204
214
query?: string // full-text search over title and content
205
215
locale?: string
206
-
populate?: boolean // attach `relations` to each item
216
+
populate?: PopulateSelection // attach `relations` to each item (default false)
207
217
where?: Record<string, unknown> | ReadonlyArray<WhereClause> // see "Filters" below
208
218
sort?: { field: string; dir?: 'asc' | 'desc' } // a system column or a field path (`seo.score`)
209
219
limit?: number
@@ -380,7 +390,7 @@ function populateRelationsAs(ctx: AccessContext, collectionName: string, doc: Do
380
390
function populateRelations(collectionName: string, doc: Doc): Promise<Record<string, Doc | Array<Doc> | null>> // deprecated: reads as publicContext()
381
391
```
382
392
383
-
Resolvesevery`relation`fieldof`doc`tothetargetdocument(s) `ctx`canread, keyedbyfieldname. A`publicRead`contextseespublishedtargetsthewayitseespublishedsources. Fieldswhosetargetcollection`ctx`can't read are left out.
393
+
Resolvesevery`relation`fieldof`doc`tothetargetdocument(s) `ctx`canread, keyedbyfieldname. Amissing, trashedorhiddentargetis`null` (droppedfroma`many`array). A`publicRead`contextseespublishedtargetsthewayitseespublishedsources. Fieldswhosetargetcollection`ctx`can't read are left out.
Copy file name to clipboardExpand all lines: docs/api/cms-core.md
+11Lines changed: 11 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -646,6 +646,17 @@ The agent tool set, shared by the content agent, the HTTP MCP server, and WebMCP
646
646
647
647
These agent tools are separate from the HTTP API operations (`saveDoc`, `getPublicDocument`, …) in [`@tanstack/cms-api`](./cms-api).
648
648
649
+
### `related(result, path)`
650
+
651
+
```ts
652
+
function related<Cextendsstring, PextendsRelationPath<C>>(
653
+
result: { collection:C; relations?:Relations },
654
+
path:P,
655
+
):RelatedAt<C, P>
656
+
```
657
+
658
+
The related document(s) at `path` of a populated `get`/`list` result (see [`getAs`and`listAs`](./cms-core-server#getasctx-options-and-listasctx-options)). Paths are relation field paths as `relations` keys them (`author`, `seo.image`, `blocks.2.author`). For a top-level relation field of a registered collection, the result is typed as the target's document (anarrayfor`many: true`). It is `null` when the path wasn't populated, or the target is missing or hidden. `@tanstack/cms-client` exports the same function.
Copy file name to clipboardExpand all lines: docs/api/routes-and-endpoints.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -214,8 +214,8 @@ Every operation is also a TanStack Start server function in [`@tanstack/cms-api/
214
214
| Operation | Method | Access | Input | Result |
215
215
| --- | --- | --- | --- | --- |
216
216
|`getAuthSession`| GET | public |`{}`| The caller's `CmsSession` plus `ai: { text, image }` capabilities. |
217
-
|`get`| GET | public |`{ collection, id \| locator, locale?, populate? }`|`{ id, collection, doc, relations? }` or `null`. The canonical read ([`getAs`](./cms-core-server#getasctx-options-and-listasctx-options)): published only, except for callers who may read drafts of the collection and don't ask for `live`; drafts are read with staged changes overlaid. |
218
-
|`list`| GET | public |`{ collection?, locale?, where?, sort?: { field, dir? }, limit? (1–500, default 100), offset?, cursor?, populate? }`|`{ items: [{ id, collection, doc, relations? }], total, nextCursor? }`. The canonical list, with the same visibility as `get`. |
217
+
|`get`| GET | public |`{ collection, id \| locator, locale?, populate? }`|`{ id, collection, doc, relations? }` or `null`. The canonical read ([`getAs`](./cms-core-server#getasctx-options-and-listasctx-options)): published only, except for callers who may read drafts of the collection and don't ask for `live`; drafts are read with staged changes overlaid. Relations are populated one level deep unless `populate` is `false` (or a list of paths). |
218
+
|`list`| GET | public |`{ collection?, locale?, where?, sort?: { field, dir? }, limit? (1–500, default 100), offset?, cursor?, populate? }`|`{ items: [{ id, collection, doc, relations? }], total, nextCursor? }`. The canonical list, with the same visibility and populate default as `get`. |
|`getDocument`| GET |`content.read`|`{ collection, id }`|`{ doc, isPending, pendingId?, pendingSource?, livePublished }`, including any staged change. |
221
221
|`resolveRedirect`| GET | public |`{ path }`|`{ to, status }` or `null`|
Copy file name to clipboardExpand all lines: docs/mcp/operations-registry.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -163,10 +163,10 @@ Agents get a smaller, task-shaped set of tools. `opSchemas` (`packages/core/src/
163
163
| Tool | Kind | Behavior |
164
164
| --- | --- | --- |
165
165
|`list_collections`| read | Collections and their fields |
166
-
|`list_documents`| read | The canonical `list`: documents of one collection (or every readable one) with `locale`, `where`, `sort`, paging (`limit`, `offset`, `cursor`) and `populate`. Returns `{ items: [{ id, collection, doc }], total, nextCursor? }`|
167
-
|`get_document`| read | The canonical `get`: one document by `id` or `locator`, including staged creates and updates in the agent's `edit` mode. Returns `{ id, collection, doc }` or `null`|
166
+
|`list_documents`| read | The canonical `list`: documents of one collection (or every readable one) with `locale`, `where`, `sort`, paging (`limit`, `offset`, `cursor`) and `populate` (default `false`: relation fields stay ids). Returns `{ items: [{ id, collection, doc, relations? }], total, nextCursor? }`|
167
+
|`get_document`| read | The canonical `get`: one document by `id` or `locator`, including staged creates and updates in the agent's `edit` mode, with its relations populated (`populate: false` for ids only). Returns `{ id, collection, doc, relations }` or `null`|
168
168
|`read_document`| read | Deprecated, use `get_document`. One document by id, including staged creates and updates; `NOT_FOUND` when missing |
169
-
|`search_documents`| read | Full-text search and structured `where` / `sort` queries with collection, locale, a read `mode` (`live` for published only; never wider than the caller's), and pagination (`limit`, `offset`, `cursor`) |
169
+
|`search_documents`| read | Full-text search and structured `where` / `sort` queries with collection, locale, a read `mode` (`live` for published only; never wider than the caller's), pagination (`limit`, `offset`, `cursor`), and `populate` (default `false`) |
170
170
|`list_revisions`| read | Revision history, newest first |
171
171
|`list_translations`| read | A document's locale variants |
172
172
|`create_document`| write | Stage a new document |
@@ -176,7 +176,7 @@ Agents get a smaller, task-shaped set of tools. `opSchemas` (`packages/core/src/
176
176
|`restore_revision`| write | Stage restoring a revision |
177
177
|`schedule_document`| write | Stage setting or clearing `publishAt`|
178
178
179
-
The read tools come from the canonical read vocabulary, `readVerbs`: each verb's agent tool name is derived as `<verb>_<noun>` (`get` → `get_document`, `list` → `list_documents`, see `agentToolName`), and its input schema is the verb's bag (`getInput`, `listInput`), the same one the `get` and `list` operations, `client.get/list` and `cmsAs(cms, ctx).get/list` take. Full-text search stays its own tool, `search_documents`.
179
+
The read tools come from the canonical read vocabulary, `readVerbs`: each verb's agent tool name is derived as `<verb>_<noun>` (`get` → `get_document`, `list` → `list_documents`, see `agentToolName`), and its input schema is the verb's bag (`getInput`, `listInput`), the same one the `get` and `list` operations, `client.get/list` and `cmsAs(cms, ctx).get/list` take. The one difference is the populate default: `get_document` populates like `get`, while `list_documents` and `search_documents` return ids unless the agent asks (`populate: true`, or the paths it needs), to keep tool results small. Full-text search stays its own tool, `search_documents`.
180
180
181
181
Two server-side pieces in `@tanstack/cms-core/server` attach behavior:
0 commit comments