Skip to content

feat: make the reference field type merge-ready - #2799

Closed
saariuslystoned wants to merge 47 commits into
emdash-cms:mainfrom
saariuslystoned:codex/emdash-1928-merge-ready-20260830
Closed

saariuslystoned wants to merge 47 commits into
emdash-cms:mainfrom
saariuslystoned:codex/emdash-1928-merge-ready-20260830

Conversation

@saariuslystoned

@saariuslystoned saariuslystoned commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What does this PR do?

This is a tested, author-preserving continuation of #1928, opened directly against upstream main so the result can run through EmDash's authoritative CI, bot, preview, visual, query-count, security, and review rails.

MA2153's work remains the foundation:

  • The merge commit keeps the exact feat: relations, and reference fields as entry pickers #1928 head, 808cde87a34fa818a2f29ddafacf5053d3859398, as its first parent and preserves the original commits and authors.
  • It merges upstream main at 1717d31b351164a5f78e95fe004ee582c7c50f40 and resolves the three conflicts in the content editor, transaction helper, and route tests.
  • Focused continuation commits enforce required and single-reference constraints across create, update, direct edge writes, and seed application, including translation-create inheritance.
  • Storage-less reference fields stay outside body.data validation while the existing top-level references payload remains accepted.
  • No legacy-data migration, public-query hydration, MCP behavior, Block Kit work, Dinkus work, or unrelated cleanup is included.

This follows the maintainer direction on #1928 to resolve the current-main conflicts without adding migration scope. It does not automatically close #1928; maintainers can coordinate which PR remains canonical.

Approved feature discussion: #386

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

AI-generated code disclosure

Screenshots / test output

Exact identities

  • Original feat: relations, and reference fields as entry pickers #1928 head: 808cde87a34fa818a2f29ddafacf5053d3859398
  • Immutable upstream base: 1717d31b351164a5f78e95fe004ee582c7c50f40
  • Initial continuation head reviewed by EmDashBot: 20bb470b68e143a6b3dc0f16b9a47726b4ca7a62
  • Current repaired head: cf146124f939aa5efd23c2e6bf800e14b3fc9534

EmDashBot repair cycle 1

The first EmDashBot review found two blocker classes across three inline comments. Current head cf146124f939 addresses all three:

  1. Storage-less references cannot be indexed. Core now rejects indexed reference fields with FIELD_NOT_INDEXABLE; seed preflight rejects them; admin hides the Indexed toggle and clears stale invalid state.
  2. D1-safe reference replacement. Reference edges now insert in derived 16-row batches: six binds per edge, 96 binds per statement, under D1's 100-parameter ceiling. Global sort_order is preserved across chunks.

The regression proof includes registry create/update/seed rejection, seed preflight, admin visibility/save normalization, SQL parameter shape, and a real Workerd/D1 replacement of an old edge with 17 ordered children.

The D1 test proves the deterministic bind-limit failure is fixed. It does not claim all-or-nothing behavior across an unrelated outage between D1 statements; true atomic replacement would require a separate D1Database.batch() adapter or generation/pointer design.

Current-head verification

  • focused core: 77 passed
  • focused admin FieldEditor: 39 passed
  • real Workerd/D1 17-child replacement: 1 passed
  • broad related core suites: 255 passed across 8 files under Node 22.23.2
  • combined Workerd/D1 reference suites: 2 passed
  • lint: 0 diagnostics across 2,774 files
  • format: passed across 3,138 files
  • core and admin tsgo --noEmit: passed
  • GitHub Actions Typecheck, Lint, Format, Smoke, Integration, Browser, all 8 browser E2E shards, all 8 Cloudflare E2E shards, E2E aggregate, CodeQL, zizmor, query-count, visual-regression, preview, changeset, version, CLA, and compliance checks: passed

At the requested monitoring cutoff, GitHub reported 42 successful checks, one expected skipped Dependabot check, one still-pending aggregate CI / Tests job, and zero failures. This records the exact cutoff rather than claiming that the aggregate or an admin-triggered second review completed.

Independent exact-head review

  • Immutable base: 1717d31b351164a5f78e95fe004ee582c7c50f40
  • Submitted/current head: cf146124f939aa5efd23c2e6bf800e14b3fc9534
  • Spark-2 OpenClaw blocking branch review, Codex / gpt-5.6-sol, high reasoning
  • Result: completed / clean; no accepted or actionable findings; patch correct at 0.99 confidence
  • Review cycle: 1
  • Gates: read-only review; no edits, merge, deployment, sends, secrets, or destructive cleanup

Immutable repaired-head proof packet: release, receipt, hashes, and exact-head OpenClaw result

Visual proof provenance

The captures below were made at predecessor head 20bb470b68e1. The repair does not change the picker flow, so they remain useful behavior evidence, but they are deliberately not represented as newly captured at cf146124.

State Evidence
Picker open with eligible Pages entry JPEG
Reference selected in editor JPEG
Reference persisted after save/reload JPEG
Interaction sequence MP4

Reference picker open

Reference selected

Reference persisted after save and reload

The MP4 is a four-state sequence assembled from actual browser states; it is not a continuous screen recording.

The old CHANGES_REQUESTED review is bound to predecessor head 20bb470b68e1. The current label is review/needs-rereview; current head cf146124f939 is ready for a maintainer-triggered EmDashBot rereview.

MA2153 and others added 30 commits July 10, 2026 11:42
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`handleContentCreate`/`handleContentUpdate` already accept a `references`
body key, but the zod schemas didn't list it, so `parseBody` silently
stripped it before it reached the handler.
Creating a reference field now creates its backing relation def
transactionally, updating the field's label PATCHes the relation's
childLabel, and deleting the field deletes the relation and its edges.
The admin no longer has to orchestrate these multi-step writes itself.

Also fixes withTransaction to short-circuit when already inside a
transaction (db.isTransaction), rather than attempting an illegal
nested .transaction() call — required for the field-create/update/
delete handlers to nest their relation writes with SchemaRegistry's
own internally-transacted field writes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Type STORAGELESS_FIELD_TYPES as ReadonlySet<string> so membership checks
against DB-sourced field types need no cast, resolving the lint diagnostic
introduced with stripStoragelessDataKeys.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Reference fields are storage-less, so a seed defining one now creates the
backing relation (like the schema handler) and writes a $ref value in the
field's data as a content-reference edge instead of a table column. Previously
applySeed threw "no such column" for any seed using a reference field.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
- resolveEntries now attaches a display `title` (entry `title`, then `name`,
  else null) to every EntryRef, so picked entries and backlinks show a
  readable label instead of a slug; hydrated through content GET and the
  admin editor/backlinks sidebar.
- Wire the relation and reference-edge API routes into injectCoreRoutes;
  they existed but were never registered, so /_emdash/api/relations 404'd
  and the "Referenced by" panel silently hid itself.
- Preserve `targetCollection` and `multiple` on reference field validation
  so the create handler no longer rejects the field for a missing target.
- Backlinks sidebar resolves relations by translation_group, not name.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
# Conflicts:
#	packages/core/src/api/handlers/content.ts
# Conflicts:
#	packages/admin/src/components/ContentEditor.tsx
#	packages/admin/src/router.tsx
- Add `title` to entryRefSchema so the response contract matches the
  runtime EntryRef (no more OpenAPI/generated-type drift).
- Validate the target collection in createFieldRelation, rejecting a
  reference field whose target does not exist (rolls back in-transaction,
  leaving no orphan field or relation row). Adds a lifecycle test.
- Remove the misleading cross-locale badge from the reference list and
  backlinks sidebar: edges are keyed by translation_group, so labelling a
  resolved variant's locale implies a per-locale binding that doesn't
  exist. Titles already resolve at the current entry's locale via
  pickVariant. Drops the now-dead entryLocale plumbing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…d-admin-ui

# Conflicts:
#	packages/core/src/astro/routes/api/content/[collection]/[id].ts
#	packages/core/src/seed/apply.ts
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been inactive for 14 days. It will be closed automatically in 7 days if there is no further activity.

If you're still working on this, please push an update or leave a comment.

@ascorbic

Copy link
Copy Markdown
Member

Superseded by #1928, which landed relations and reference fields as entry pickers.

@ascorbic ascorbic closed this Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants