Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions .changeset/definition-split.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
'@tanstack/cms-core': minor
'@tanstack/cms-cli': minor
'@tanstack/cms-skills': minor
'@tanstack/cms-connect-atproto': minor
---

Split plugins into a definition and a runtime, and attach a collection's
server-bound hooks, access, and storage in the runtime config.

**Breaking: `definePlugin({ definition, runtime })`.** A plugin's `name`,
`collections`, `adminNav`, `routes`, and `adminRoutes` go in
`definition: definePluginDefinition({ … })`; its `blockTypes`, `fieldTypes`,
`ops`, `eventHandlers`, and `onEvent` go in `runtime`. The flat
`definePlugin({ name, … })` form throws, and so does a key on the wrong side.
`@tanstack/cms-core/definition` exports `definePluginDefinition` (and the
`CmsPluginDefinition` type) in place of `definePlugin`, which is now
root-only. To migrate, run this from a TanStack CMS checkout:

```bash
pnpm codemod definition-split <path-to-your-app>
```

```ts
// before
definePlugin({ name: 'analytics', collections: [pageview], ops: [topPages] })
// after
definePlugin({
definition: definePluginDefinition({
name: 'analytics',
collections: [pageview],
}),
runtime: { ops: [topPages] },
})
```

List the plugin's definition in `defineCmsDefinition({ plugins })` and the
plugin in the runtime config's `plugins`; the runtime entry replaces the
definition entry of the same name. A plugin with no collections or routes,
like the AT Protocol connector, can sit in the runtime config alone. One-file
apps list the plugin once in `defineCms({ plugins })`, as before.

**Breaking: the runtime config's `collections` is an object keyed by
collection name.** `defineCms(definition, { collections: { post: { hooks,
access, storage } } })` attaches the server-bound half of a collection the
definition declares. Hooks are typed from the collection's fields. An unknown
name, any other key, or a hook or rule the definition already sets throws.
Before, the runtime config couldn't name `collections` at all.

- The same codemod writes `cms.definition.ts` next to each `cms.config.ts`
(collections, `admin`, plugin definitions, and what they depend on) and
rewrites the config to `defineCms(definition, runtime)` with
`Register { cms: typeof definition }`. Hooks and access that import server
code have to be moved to the runtime `collections` by hand.
- `defineInterfaceCollection` is exported from `@tanstack/cms-core/definition`.
- `@tanstack/cms-cli`: `tanstack-cms init` writes `src/cms.definition.ts` and a
`src/cms.config.ts` that calls `defineCms(definition, { … })`. If either file
exists, both are kept unless `--force` is passed.
- `@tanstack/cms-skills`: code-mode `applySkillToCode` adds a skill's
collections to `cms.definition.ts`, creating it and a `cms.config.ts` in a
new app. A one-file app still gets them appended to `cms.config.ts`.
- `@tanstack/cms-connect-atproto`: `createAtprotoConnector()` returns a
runtime-only plugin; add it to the runtime config's `plugins`.
15 changes: 13 additions & 2 deletions .claude/skills/astro-starlight-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ description: Migrate an Astro Starlight docs site to TanStack CMS 1.0 (@tanstack

Port an [Astro Starlight](https://starlight.astro.build) docs site onto
TanStack CMS: the target is a TanStack Start app whose app-specific code is a
`cms.config.ts` (the mapped schema and theme) plus the migrated content. The
`cms.definition.ts` (the mapped schema) and a `cms.config.ts` (blocks, seed,
theme) plus the migrated content. The
admin UI, docs layout with sidebar, block editor, drafts and review queue,
redirects, sitemap, HTTP API, and MCP come from `@tanstack/cms-core`,
`@tanstack/cms-api`, and `@tanstack/cms-ui-react`.
Expand Down Expand Up @@ -78,7 +79,17 @@ shape of [`examples/blog`](../../../examples/blog) (same as the Payload skill
- `src/router.tsx` — `import './cms.config'` then build the router from
`./routeTree.gen` (generated on first `dev`/`build`).

## 3. Map the schema → `src/cms.config.ts`
## 3. Map the schema → `src/cms.definition.ts`

Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
rules that need server code attach there by collection name
(`collections: { post: { hooks, access } }`). A small app may keep one file
(`defineCms({ collections, … })`).

One Starlight `docs` collection → one core collection. **Name it `page`** with
a `blocks` field: the public renderer (`/p/$id`), the docs layout, and the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* block — there is no Lexical step. With `--export <file>` it also writes a
* CMS export (`tanstack-cms-export` v1) to load with `tanstack-cms import`.
*
* This is the data half. The schema half is the hand-written src/cms.config.ts
* This is the data half. The schema half is the hand-written src/cms.definition.ts
* (see SKILL.md's frontmatter → field mapping table).
*/
import { readFileSync, writeFileSync, readdirSync, statSync } from 'node:fs'
Expand Down
19 changes: 14 additions & 5 deletions .claude/skills/emdash-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ description: Migrate an EmDash CMS site to TanStack CMS 1.0 (@tanstack/cms-core
# EmDash → TanStack CMS migration

Port an [EmDash](https://emdashcms.com) site onto TanStack CMS: the target is a
TanStack Start app whose app-specific code is a `cms.config.ts` (the mapped
schema) plus the migrated content. The admin UI, block editor, public renderer,
TanStack Start app whose app-specific code is a `cms.definition.ts` (the
mapped schema) and a `cms.config.ts` (blocks, seed, theme) plus the migrated
content. The admin UI, block editor, public renderer,
drafts, revisions, scheduling, review queue, search, HTTP API, and MCP/WebMCP
come from `@tanstack/cms-core`, `@tanstack/cms-api`, and
`@tanstack/cms-ui-react`.
Expand Down Expand Up @@ -92,9 +93,17 @@ Keep the real EmDash source app **out of the pnpm workspace** (it's an external
npm project with a large dependency tree) — see `examples/emdash-before` and the
`!examples/emdash-before` line in the root `pnpm-workspace.yaml`.

## 3. Map the schema → `src/cms.config.ts`

Write `cms.config.ts` calling `defineCms({ collections, blockTypes, … })`.
## 3. Map the schema → `src/cms.definition.ts`

Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
rules that need server code attach there by collection name
(`collections: { post: { hooks, access } }`). A small app may keep one file
(`defineCms({ collections, … })`).

**Collections.** Each EmDash collection → a core `Collection`. Name the
public page collection **`page` with a `blocks` field** and the blog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* seed. With `--export <file>` it also writes a CMS export
* (`tanstack-cms-export` v1) to load with `tanstack-cms import <file>`.
*
* This is the data half. The schema half is the hand-written src/cms.config.ts
* This is the data half. The schema half is the hand-written src/cms.definition.ts
* (see SKILL.md's field/collection mapping tables).
*/
import { readFileSync, writeFileSync } from 'node:fs'
Expand Down Expand Up @@ -183,7 +183,7 @@ function main() {
)
}

// multiselect options for cms.config.ts: every taxonomy's terms
// multiselect options for cms.definition.ts: every taxonomy's terms
for (const tax of seed.taxonomies ?? []) {
const terms = (tax.terms ?? []).map((t) => `${t.slug} (${t.label})`)
console.log(` taxonomy ${tax.name} options: ${terms.join(', ')}`)
Expand Down
37 changes: 27 additions & 10 deletions .claude/skills/payload-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ description: Migrate a Payload CMS (v3) project to TanStack CMS 1.0 (@tanstack/c
# Payload → TanStack CMS migration

Port a [Payload v3](https://payloadcms.com) project onto TanStack CMS: the
target is a TanStack Start app whose app-specific code is a `cms.config.ts`
(the mapped schema, access rules, and hooks) plus the migrated content.
target is a TanStack Start app whose app-specific code is a
`cms.definition.ts` (the mapped schema) and a `cms.config.ts` (the runtime:
blocks, auth, server-bound access rules and hooks) plus the migrated content.
The admin UI, block editor, public renderer, drafts and review queue, media
library, HTTP API, and MCP come from `@tanstack/cms-core`,
`@tanstack/cms-api`, and `@tanstack/cms-ui-react`.
Expand Down Expand Up @@ -48,7 +49,7 @@ nested docs), and custom React admin components — these drive the gap report.

Outside this repo, start from a TanStack Start app and run
`npx tanstack-cms init` (from `@tanstack/cms-cli`): it creates
`src/cms.config.ts`, adds `tanstackCms()` and `cmsVirtualRoutes()` to
`src/cms.definition.ts` and `src/cms.config.ts`, adds `tanstackCms()` and `cmsVirtualRoutes()` to
`vite.config.ts`, imports the config from `src/router.tsx`, and ignores
`.data/`. In this repo, copy the shape of [`examples/blog`](../../../examples/blog):

Expand All @@ -66,18 +67,30 @@ Outside this repo, start from a TanStack Start app and run
with `tanstackCms` from `@tanstack/cms-ui-react/vite` and `cmsVirtualRoutes`
from `@tanstack/cms-ui-react/virtual-routes`. Payload serves its admin at
`/admin`; keep that URL with `cmsVirtualRoutes({ adminBasePath: '/admin' })`
plus `defineCms({ admin: { basePath: '/admin' } })`.
plus `defineCmsDefinition({ admin: { basePath: '/admin' } })`.
- `vitest.config.ts` — a plain `defineConfig({ test: { environment: 'node', include: ['src/**/*.test.ts'] } })`
from `vitest/config`, so tests don't load the Start/Nitro plugins.
- `tsconfig.json` — `{ "extends": "../../tsconfig.base.json", "include": ["src/**/*.ts","src/**/*.tsx"] }`.
- `src/router.tsx` — `import './cms.config'` (side effect: registers the
model) then build the router from `./routeTree.gen` (generated on first
`dev`/`build`).

## 3. Map the schema → `src/cms.config.ts`

Write `cms.config.ts` calling `defineCms({ collections, blockTypes, … })` and
register its type (`declare module '@tanstack/cms-core' { interface Register { cms: typeof cms } }`).
## 3. Map the schema → `src/cms.definition.ts`

Write `cms.definition.ts` calling `defineCmsDefinition({ collections, admin })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, auth, seed, collections, … })` and
register the definition's type
(`declare module '@tanstack/cms-core' { interface Register { cms: typeof definition } }`).
The runtime `collections` is an object keyed by collection name that attaches
`hooks`, `access`, and `storage` to the definition's collections:
`collections: { post: { hooks: { afterChange }, access: { read } } }`. Put a
hook or access predicate there when it needs server code (store reads,
a database, secrets); role arrays and pure predicates can stay on the
collection. A small app may keep one file (`defineCms({ collections, … })`).
`cms.config.ts` is imported on the client too: read secrets lazily inside
functions (AI adapter factories, `webhooks[].secret: () => process.env.X`).

Expand Down Expand Up @@ -162,7 +175,9 @@ Payload `{ data, originalDoc, req, operation }` → core
`{ doc, id }` (`postRead`), `{ id, actor }` (`preDelete`). Return the
transformed doc from `preValidate` / `postValidate` / `postRead`; throw to
abort a write. Keep hooks under about 50ms. Replace `req.payload.find(…)` with
`queryDocuments`/`readDocument` from `@tanstack/cms-core/server`. Hooks that
`queryDocuments`/`readDocument` from `@tanstack/cms-core/server`, and attach
those hooks in the runtime config
(`defineCms(definition, { collections: { post: { hooks } } })`). Hooks that
only fan out to other systems (cache purges, search indexing) usually become
`defineCms({ webhooks })` instead. No equivalent: `beforeOperation`,
`afterOperation`, `beforeRead`, `afterError`, auth hooks.
Expand Down Expand Up @@ -288,7 +303,9 @@ judgment. Check at least:
- **Richer Lexical** — node types not converted.
- **Custom admin components** — Payload React field/view overrides don't
carry over automatically; rebuild custom field inputs with `field.input` or
`defineFieldType()`, and custom views or hooks with routes or `definePlugin()`.
`defineFieldType()`, and custom views or hooks with routes or
`definePlugin({ definition, runtime })` (collections and routes in
`definition`, ops and event handlers in `runtime`).
- **Databases** — Postgres/MongoDB adapters have no built-in equivalent
(SQLite and libSQL/Turso ship; custom `StorageAdapter`s are possible).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* `--export <file>` it also writes a CMS export (`tanstack-cms-export` v1) to
* load with `tanstack-cms import <file>`.
*
* This is the data half. The schema half is the hand-written src/cms.config.ts
* This is the data half. The schema half is the hand-written src/cms.definition.ts
* (see SKILL.md's field/block mapping tables).
*/
import { writeFileSync } from 'node:fs'
Expand Down Expand Up @@ -54,7 +54,7 @@ const OUT = join(here, '..', 'src', 'seed-data.ts')
const CONFIG = [
{
source: 'pages', // Payload collection slug
target: 'page', // core collection name (must match cms.config.ts)
target: 'page', // core collection name (must match cms.definition.ts)
id: (doc) => (doc.slug ?? '').replace(/^\//, '') || 'home',
fields: [
{ name: 'title', kind: 'scalar' },
Expand Down
13 changes: 8 additions & 5 deletions .claude/skills/voting/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: Build a native upvote/downvote (voting) feature on a TanStack CMS 1
Add Reddit/HN-style upvote/downvote voting to a TanStack CMS app. The worked
reference for everything below is
[`examples/blog-voting`](../../../examples/blog-voting): the blog example plus
`src/cms.config.ts` (the `vote` collection + count fields), `src/voting/`
`src/cms.definition.ts` (the `vote` collection + count fields), `src/voting/`
(the write/read paths, component, and tests), and `src/routes/top.tsx`. When
in doubt, read that.

Expand All @@ -25,7 +25,8 @@ All store functions from `@tanstack/cms-core/server` are **async** —

## 0. Prerequisites

- A TanStack CMS app (`cms.config.ts` + `cmsVirtualRoutes()`), e.g. a copy of
- A TanStack CMS app (`cms.definition.ts` + `cms.config.ts` +
`cmsVirtualRoutes()`), e.g. a copy of
[`examples/blog`](../../../examples/blog).
- An `auth` config (`createMockAuth()` from `@tanstack/cms-ui-react` for
demos, `auth: { getUser }` in production) so votes have a voter.
Expand All @@ -44,9 +45,11 @@ All store functions from `@tanstack/cms-core/server` are **async** —
| Review queue? | **No.** Votes commit directly | The review queue is for _content_ awaiting human approval. Votes are user interactions; the vote documents themselves are the audit trail (revisions give you who-voted-what-when) |
| Anonymous votes | Not by default | Anonymous voting invites brigading and can't do one-vote-per-user. If the product needs it, say so explicitly and accept the tradeoffs (§4) |

## 2. Model the schema → `src/cms.config.ts`
## 2. Model the schema → `src/cms.definition.ts`

Add a `vote` collection to the `collections` array and count fields on the votable collection:
Add a `vote` collection to the definition's `collections` array (in a one-file
app, `defineCms({ collections })` in `cms.config.ts`) and count fields on the
votable collection:

```ts
defineCollection({
Expand Down Expand Up @@ -267,7 +270,7 @@ A small component: up arrow, score, down arrow. Requirements:
Agents can read `post` scores through the standard tools, and you can expose
voting as a first-class operation and MCP/WebMCP/content-agent tool with
`defineOp({ name: 'cast_vote', access: 'content.write', agent: { kind: 'write' }, input, run })`
in `defineCms({ ops })` (where `ctx.session.user?.id` provides the authenticated
in `defineCms(definition, { ops })` (where `ctx.session.user?.id` provides the authenticated
voter id). Alternatively, keep `castVote` as a Start server function for the UI
only, or serve a custom MCP endpoint that checks `verifyMcpAccess(request)` from
`@tanstack/cms-core/server` and calls `castVoteForVoter` with the resolved
Expand Down
19 changes: 14 additions & 5 deletions .claude/skills/wordpress-to-tanstack-cms/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ description: Migrate a WordPress site to TanStack CMS 1.0 (@tanstack/cms-core +
# WordPress → TanStack CMS migration

Port a [WordPress](https://wordpress.org) site onto TanStack CMS: the target is
a TanStack Start app whose app-specific code is a `cms.config.ts` (the mapped
schema) plus the migrated content. The admin UI, block editor, public renderer,
a TanStack Start app whose app-specific code is a `cms.definition.ts` (the
mapped schema) and a `cms.config.ts` (blocks, seed, theme) plus the migrated
content. The admin UI, block editor, public renderer,
drafts, revisions, review queue, redirects, sitemap, HTTP API, and MCP/WebMCP
come from `@tanstack/cms-core`, `@tanstack/cms-api`, and
`@tanstack/cms-ui-react`.
Expand Down Expand Up @@ -85,9 +86,17 @@ migration skills' §2):
The WXR source (`<name>-before`) is just the export file + a README — not a
workspace app.

## 3. Map the schema → `src/cms.config.ts`

Write `cms.config.ts` calling `defineCms({ collections, blockTypes, … })`.
## 3. Map the schema → `src/cms.definition.ts`

Write `cms.definition.ts` calling `defineCmsDefinition({ collections })`,
importing only from `@tanstack/cms-core/definition` (`defineCollection`,
`redirectsCollection`, …): Vite config and client code load this file, and
`pnpm test:definitions` fails if it reaches React, Start, or server code.
Then write `cms.config.ts` calling
`defineCms(definition, { blockTypes, seed, theme, … })`. Hooks and access
rules that need server code attach there by collection name
(`collections: { post: { hooks, access } }`). A small app may keep one file
(`defineCms({ collections, … })`).

**Post types → collections.** Map the `page` post type to a core collection
**named `page` with a `blocks` field** and `post` to a core **`post`**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* `--export <file>` it also writes a CMS export (`tanstack-cms-export` v1) to
* load with `tanstack-cms import <file>`.
*
* This is the data half. The schema half is the hand-written src/cms.config.ts
* This is the data half. The schema half is the hand-written src/cms.definition.ts
* (see SKILL.md's field/collection mapping tables).
*/
import { readFileSync, writeFileSync } from 'node:fs'
Expand Down Expand Up @@ -71,7 +71,7 @@ const CONFIG = {
}),
},
}
const REDIRECTS = 'redirect' // the redirectsCollection() name in cms.config.ts
const REDIRECTS = 'redirect' // the redirectsCollection() name in cms.definition.ts
// ===========================================================================

/** Path of a WordPress permalink (`https://site/a-post/` → `/a-post/`), or null. */
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,6 @@ docs/superpowers
.claude/worktrees/*
/worktrees/
.claude/scheduled_tasks.lock

# Scratch apps scripts/verify-definitions.ts scaffolds
packages/cli/.verify-definitions-*/
Loading
Loading