Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/fix-emdash-types-schema-export.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"emdash": patch
---

Fixes `emdash types` crashing 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.
6 changes: 5 additions & 1 deletion packages/core/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ export class EmDashClient {

/** Export full schema as JSON (used by `emdash types`) */
async schemaExport(): Promise<SchemaExport> {
return this.request<SchemaExport>("GET", "/schema");
// 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;
Comment on lines +390 to +394
}

/** Export schema as TypeScript type definitions (used by `emdash types`) */
Expand Down
33 changes: 33 additions & 0 deletions packages/core/tests/unit/client/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,4 +737,37 @@ describe("EmDashClient", () => {
expect(result[0]!.name).toBe("primary");
});
});

describe("schemaExport()", () => {
it("returns the un-enveloped /schema response body", async () => {
// The /schema endpoint returns a bare { collections, version }
// object — it is NOT wrapped in the standard { data } envelope.
const schemaBody = {
collections: [{ slug: "posts", label: "Posts", fields: [] }],
version: "abc123",
};
const backend = createMockBackend([
{
method: "GET",
path: "/schema",
handler: () =>
new Response(JSON.stringify(schemaBody), {
status: 200,
headers: { "Content-Type": "application/json" },
}),
},
]);

const client = new EmDashClient({
baseUrl: "http://localhost:4321",
token: "test",
interceptors: [backend],
});

const schema = await client.schemaExport();
expect(schema.collections).toHaveLength(1);
expect(schema.collections[0]!.slug).toBe("posts");
expect(schema.version).toBe("abc123");
});
});
});
Loading