fix(core): emdash types reads un-enveloped /schema response#1143
fix(core): emdash types reads un-enveloped /schema response#1143nesmachny wants to merge 2 commits into
Conversation
`emdash types` crashed with "Cannot read properties of undefined
(reading 'collections')". The client's schemaExport() routed through the
enveloped request() helper, but the /schema endpoint returns a bare
{ collections, version } object — it now reads the raw response directly.
Adds a failing-then-passing unit test and a changeset.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: d2cbda4 The changes in this PR will be included in the next version bump. This PR includes changesets to release 14 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 |
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
@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: |
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes a crash in emdash types by updating schemaExport() to correctly handle the /schema endpoint’s non-enveloped JSON response, instead of assuming the standard { data } wrapper.
Changes:
- Updated
EmDashClient.schemaExport()to userequestRaw()+assertOk()and parse the response body directly. - Added a unit test covering the un-enveloped
/schemaresponse shape. - Added a patch changeset documenting the CLI crash fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| packages/core/src/client/index.ts | Reads /schema as a raw JSON body (no { data } envelope), preventing schemaExport() from returning undefined. |
| packages/core/tests/unit/client/client.test.ts | Adds regression coverage for /schema returning { collections, version } directly. |
| .changeset/fix-emdash-types-schema-export.md | Publishes a patch note for the fixed emdash types crash. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // The /schema endpoint returns a bare { collections, version } object, | ||
| // not the standard { data } envelope — parse the raw response directly. | ||
| const response = await this.requestRaw("GET", "/schema"); | ||
| await this.assertOk(response); | ||
| return (await response.json()) as SchemaExport; |
| }); | ||
|
|
||
| describe("schemaExport()", () => { | ||
| it("returns the un-enveloped /schema response body", async () => { |
What does this PR do?
emdash typescrashes withTypeError: Cannot read properties of undefined (reading 'collections').The CLI's
typescommand callsclient.schemaExport(), which routed through the privaterequest()helper.request()unwraps the standard{ data }API envelope and returnsjson.data. ButGET /_emdash/api/schemareturns a bare{ collections, version }object — there is nodatawrapper — soschemaExport()returnedundefined, and the CLI then threw onschema.collections.schemaExport()now reads the raw response directly (requestRaw()+assertOk()), mirroring its siblingschemaTypes(). The/schemaendpoint and its other consumers are unchanged — this is a non-breaking, client-side fix.Type of change
Checklist
pnpm typecheckpassespnpm lintpasses (0 errors)pnpm testpasses (or targeted tests for my change) —packages/core/tests/unit/client/client.test.ts, 18/18pnpm formathas been runAI-generated code disclosure
Screenshots / test output
The new test reproduces the bug: against the un-enveloped
/schemaresponse it failed with the exact production error before the fix, and passes after it.