fix(api): menu REST API with camelCase responses#1052
Open
Rimander wants to merge 4 commits into
Open
Conversation
…schema validation, and repository-pattern implementation.
…a transaction-scoped existence check and throwing MenuGoneError
🦋 Changeset detectedLatest commit: 11cfdc7 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
Contributor
Scope checkThis PR changes 2,345 lines across 14 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/blocks
@emdash-cms/cloudflare
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
… remove legacy query string support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Addresses the menu API problems reported in #932.
What detected while tracing the flow:
POST /menus/:name/itemswithcustom_url(snake_case) returned201withcustom_url: null. The Zod schema only knows the documented camelCase keys (customUrl,sortOrder, …), and Zod's default.object()silently strips unknown keys.DELETE /menus/:name/items/:idreturned the SSR 404 HTML page because menus were the only resource using a query-string id (/items?id=); every other resource (content, taxonomies, redirects, sections, widget-areas) uses path-style[id].ts.custom_url,menu_id, …) — every other resource (content, media, taxonomies, comments, redirects) goes through a*Repository.rowToX()mapper that produces camelCase. Menus had no repository at all; all SQL lived inhandlers/menus.ts.What changed:
MenuRepositorynext to the other repositories. All SQL and snake_case ↔ camelCase mapping lives there.handlers/menus.tsis now a thin orchestrator.createdAt,menuId,parentId,sortOrder,customUrl,referenceCollection, …).createMenuItemBody/updateMenuItemBodyare.strict()— unknown keys (custom_url,url,sort_order) now fail with400 VALIDATION_ERRORinstead of being silently dropped.typeis validated against the canonical enum (custom | page | post | taxonomy | collection).PUTandDELETE /_emdash/api/menus/:name/items/:id(path-style).Heads-up for theme authors: if your theme renders a custom menu block on the frontend by reading the REST API directly (rather than going through
getMenu()from the runtime), the response keys have changed from snake_case to camelCase.getMenu()already returned camelCase — themes using it are unaffected.Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
Repository test:
tests/integration/database/menu-repository.test.ts(12 cases — row mapping, item counts, translation cloning, atomic setItems, scoped delete/reorder, listTranslations).Handler/schema/route test:
tests/integration/api/menus-handlers.test.ts(9 cases —.strict()rejects snake_case, enum rejectstype: "link", customUrl persists and is returned in camelCase, path-style route module exists with PUT/DELETE).