Skip to content

feat(core)!: locators — locatorStrategy, nested slugs, a unique per-locale locator index, and get({ locator }) through it (3c(i)) - #38

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

jherr merged 1 commit into
mainfrom
cursor/locators-a931

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements part (i) of cms-refactor-plan.md § Phase 3 (3c): item 2's locator work, and collision rules 1–5 and 8 from § "Decided: nested slugs". Part (ii) does the rest: rules 6 and 7 (shadowing and redirects), the default path(), the catch-all routes and the Starlight example.

Merge chain: step 20 of 24. Base: main. Merge it right after #39. The branch is main 3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit 31e8607 (tree 06dc155).

Merge order: 4b (#29) must merge before this PR, because of migration numbering (see below). On the merge chain it does: #29 is step 12.

What

  • One locator per document, per locale, derived by the collection's new locatorStrategy.
    • The default, slugOrId, is the normalized slug, or the id when the document has no slug. Normalizing drops leading, trailing and doubled /.
    • A localized slug gives one locator per locale.
    • The locator isn't a document field. get/list results carry it as locator next to id.
    • New client-safe exports: slugOrId, locatorStrategyOf, normalizeLocator, LocatorStrategy, LocatorInput.
  • nested: true on slug fields.
    • Each segment must be lowercase kebab-case, and slugify handles one segment at a time.
    • / alone is the collection root (locator ''), accepted on nested slug fields only.
  • Collision rules on every write path (commit, stage, approve, scheduling, restore). A violation is VALIDATION_FAILED on the slug field.
    • The full locator is unique per collection and locale.
    • A single-segment locator can't be another document's id.
    • There's one root per collection and locale.
    • Folder documents are allowed (guides next to guides/intro).
    • A trashed document gives up its locator.
    • Concurrent writes are caught by the storage key.
  • Storage.
    • DocumentIndex.locators? is new.
    • So is an optional StorageOps.findDocumentsByLocator(collection, locator, locale?). The SQL adapters (SQLite, libSQL, D1) and Postgres implement it, and the composite router forwards it.
    • Adapters without it, such as markdown, fall back to slug, id and scan lookups.
    • A new conformance case covers it.
  • The unique index.
    • SQLite v17 and Postgres v9 add an empty locators table, keyed (collection, locale, locator). Postgres adds an FK cascade and a down migration.
    • The engine fills the table on first start using each collection's strategy. That's also when it checks for duplicates: the lowest id keeps each shared locator, one warning lists the rest, and the site still boots.
    • A fingerprint in meta rebuilds the index when locator derivation changes.
  • get({ locator }) resolves through the index, replacing 3a's slug-or-id stopgap.
    • / or '' returns the root.
    • With locale, the lookup stays in that locale. Without it, the default locale is tried first, then the others.
    • A candidate the context can't see is skipped.
  • Fix: a localized slug with a per-locale value was regenerated from the title on save. It's now kept.
  • Starters.
    • documentation-kb gets a versionedSlug strategy (v1/install), matching its path().
    • multi-tenant-fleet gets a tenantSlug strategy (tenant-a/home).
    • headless-api's contract test gives its two staged items different titles.
  • Docs: collections-and-fields.md (with a new "Locators" section), cms-core-server.md, cms-core.md, routes-and-endpoints.md, operations-registry.md, terminology.md, and a new upgrading step (step 29 on the merge chain).
  • Changeset: .changeset/locators.md (core, api, client and store-postgres minor).

Migration numbering

This PR uses SQLite v17 / Postgres v9, leaving v16 / v8 to 4b (#29). Both runners only apply migrations above the current version.

  • If 4b merges first (the intended order, and the merge chain's), the numbers are contiguous and nothing collides.
  • If this PR merged first, databases migrated in between would skip 4b's v16 / v8 permanently. One of the two PRs would then have to renumber before merging.

Both PRs also append to SQL_MIGRATIONS and POSTGRES_MIGRATIONS, and both entries must stay in version order. transfer.test.ts compares the applied migrations against the migration list, so a gap in the numbering doesn't break it.

Breaking changes

  • Writes reject a taken locator, whether the slug is explicit or generated from the title. It's also rejected when a single-segment slug equals another document's id.
  • get({ locator }) no longer finds a slugged document by its id. Use get({ id }). The older slug-or-id verbs are unchanged.
  • get/list results gain locator.
  • Scoped slugs need a strategy. Apps whose slugs are only unique per tenant or version need a locatorStrategy that includes the scope.
  • Schema v17 / v9. On first start, the engine rewrites each writable row once to fill the index.

How verified

  • Core tests/locators.test.ts (21 tests) covers:
    • nested validation and normalization;
    • root, folder and nested lookups;
    • slug changes releasing a locator;
    • hidden documents;
    • custom strategies;
    • each collision rule, including trash/restore and concurrent writes;
    • locales;
    • the fallback adapter path;
    • building the index from a pre-locator database with duplicates;
    • fingerprint rebuilds.
  • Storage conformance: a locator case on SQLite, libSQL and Postgres.
  • Postgres: v9 creates an empty table, the index builds with the duplicate warning, the purge cascades, and down runs.
  • Local CI (GitHub Actions is out of billing): on a scratch branch, I merged head 540af28 into origin/main at 3b4a112. Two conflicts, both resolved by keeping both sides:
    • scripts/codemods/index.ts;
    • starters/multi-tenant-fleet/src/cms.config.ts, where main's bodyField sits next to locatorStrategy.
Check Result
pnpm install --frozen-lockfile passes
pnpm test:ci (174 tasks) Only the known @tanstack/cms-api:test:oxlint fails. core 619, api 207, client 35, store-postgres 102, store-libsql 64; every starter passes.
pnpm test:dts clean (226)
pnpm test:dialects exits 0
pnpm test:scripts 66 pass
E2E blog / base 28 / 12 pass

Assumptions (conservative defaults where the plan gives none)

  • Startup duplicates warn and boot rather than block, matching the existing rule for unique field indexes. Writes stay strict.
  • / is accepted only on nested slug fields.
  • Stored slugs are kept as entered. Only the locator is normalized, and lookups are case-sensitive.
  • A slugless document has its id as its locator in that locale.
  • The slug-vs-id check only looks within a locale.
  • Staged slug changes don't hold a locator until they're committed.
  • Rebuilds: a fingerprint change rebuilds automatically. Changing a strategy's logic without renaming it needs reindexDocuments().
  • ReadResult.locator is computed from the redacted document, so a hidden slug isn't leaked.
  • findDocumentsByLocator is optional, and the storage contract stays at version: 1.

Divergence from plan

  1. The duplicate check and backfill run in the engine, not in the SQL migration. SQL can't see a locatorStrategy or a localized slug's other locales. A SQL version of the check broke the scoped-slug starters.
  2. Duplicates found at startup warn instead of failing the upgrade. Failing would strand a Postgres deployment, whose admin couldn't start to fix the slugs.
  3. documentation-kb needed a locatorStrategy, because its slugs repeat across versions.

Seams for 3c(ii)

  • Default path(): /{publicPrefix}/{locator}. The catch-all route calls get({ locator: params._splat }).
  • Shadowing: createRoutes checks reserved route keys against findDocumentsByLocator at boot and on write.
  • Redirects: the old locators come from documentLocators on the stored row, and the new ones from denormalize(...).locators. A difference between the two is where a redirect gets written.

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.

Ten files conflicted, resolved as in the rehearsal: the docs, ops.ts, internal.ts, review.ts, verbs.ts, the starters' runtime configs, and the migrations. The migrations go in the order SQLite v16 then v17, and Postgres v8 then v9.

These changes had no textual conflict but were still needed:

  • suffixGeneratedSlug in 4b's staging prep in document-state.ts;
  • locatorStrategy in the two starters' cms.definition.ts;
  • the /definition export of LocatorInput and LocatorStrategy;
  • the migration-order tests.

Its upgrading section is step 29.

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 

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bf7f6e7

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-store-postgres 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-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

@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: 1d3937e
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Free
  • Run ID: ab7bba9b-4526-4664-989a-d11d20736e05
Commits

Reviewing files that changed from the base of the PR and between 1d3937e and bf7f6e7.

Files selected for processing: 40

  • .changeset/locators.md
  • docs/api/cms-core-server.md
  • docs/api/cms-core.md
  • docs/api/routes-and-endpoints.md
  • docs/architecture/terminology.md
  • docs/deployment/upgrading.md
  • docs/mcp/operations-registry.md
  • docs/schema/collections-and-fields.md
  • packages/api/src/outputs.ts
  • packages/api/tests/read-verbs.test.ts
  • packages/client/src/client.ts
  • packages/client/tests/client.test.ts
  • packages/core/src/definition.ts
  • packages/core/src/index.ts
  • packages/core/src/locator.ts
  • packages/core/src/ops.ts
  • packages/core/src/schema.ts
  • packages/core/src/server/indexing.ts
  • packages/core/src/server/locator-index.ts
  • packages/core/src/server/locators.ts
  • packages/core/src/server/storage.ts
  • packages/core/src/server/store/document-state.ts
  • packages/core/src/server/store/internal.ts
  • packages/core/src/server/store/verbs.ts
  • packages/core/src/server/store/write.ts
  • packages/core/src/storage.ts
  • packages/core/src/storage/conformance.ts
  • packages/core/src/storage/migrations.ts
  • packages/core/src/storage/sql-storage.ts
  • packages/core/src/storage/types.ts
  • packages/core/tests/locators.test.ts
  • packages/core/tests/migrations.test.ts
  • packages/core/tests/read-verbs.test.ts
  • packages/core/tests/transfer.test.ts
  • packages/store-postgres/src/index.ts
  • packages/store-postgres/src/migrations.ts
  • packages/store-postgres/tests/postgres.test.ts
  • starters/documentation-kb/src/cms.definition.ts
  • starters/headless-api/tests/contract.test.ts
  • starters/multi-tenant-fleet/src/cms.definition.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

cursor Bot pushed a commit that referenced this pull request Nov 6, 2026
#38 narrows get's locator to the locator index (the slug, or the id of a
document without one), so get({ locator: 'p1' }) no longer finds a post
whose slug is '/first'. Try the id first; this works before and after #38.

Co-authored-by: jherr <jherr@pobox.com>
@cursor
cursor Bot force-pushed the cursor/populate-sidecar-a931 branch from 3aecfb8 to 35ed2e9 Compare November 6, 2026 14:50
@cursor
cursor Bot force-pushed the cursor/locators-a931 branch from 29df10d to 31e8607 Compare November 6, 2026 14:50
@cursor
cursor Bot changed the base branch from cursor/populate-sidecar-a931 to main November 6, 2026 14:58
…ocale locator index, and get({ locator }) through it (3c(i)) (#38)

Chain step 20 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/locators-a931 branch from 31e8607 to bf7f6e7 Compare November 6, 2026 15:09
@jherr
jherr merged commit a82e4de into main Nov 6, 2026
1 check passed
@jherr
jherr deleted the cursor/locators-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