Skip to content
Merged
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-ingest-assignability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@chkit/plugin-codegen": patch
---

Generate row types as type aliases instead of interfaces to satisfy TypeScript's Record<string, unknown> assignability requirement. Fixes TypeScript error TS2322 when passing typed row arrays to ingest functions.
2 changes: 1 addition & 1 deletion packages/cli/src/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ describe('plugin runtime', () => {
expect(payload.outFile).toBe(outFile)

const content = await readFile(outFile, 'utf8')
expect(content).toContain('export interface AppUsersRow')
expect(content).toContain('export type AppUsersRow = {')
expect(content.endsWith('\n')).toBe(true)
} finally {
await rm(fixture.dir, { recursive: true, force: true })
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-codegen/src/generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ function renderTableInterface(
interfaceName: string,
options: Required<CodegenPluginOptions>
): { lines: string[]; findings: CodegenFinding[] } {
const lines: string[] = [`export interface ${interfaceName} {`]
const lines: string[] = [`export type ${interfaceName} = {`]
const findings: CodegenFinding[] = []
const zodFields: string[] = []

Expand Down Expand Up @@ -279,7 +279,7 @@ function renderViewInterface(
const kind = definition.kind === 'view' ? 'view' : 'materialized_view'
return {
lines: [
`export interface ${interfaceName} {`,
`export type ${interfaceName} = {`,
' [key: string]: unknown',
'}',
'',
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin-codegen/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ describe('@chkit/plugin-codegen generation', () => {
})

expect(result.content).toBe(
`// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nexport interface AppUsersRow {\n id: string\n email: string\n created_at: string\n}\n`
`// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nexport type AppUsersRow = {\n id: string\n email: string\n created_at: string\n}\n`
)
expect(result.content.endsWith('\n')).toBe(true)
expect(result.declarationCount).toBe(1)
Expand Down Expand Up @@ -364,7 +364,7 @@ describe('@chkit/plugin-codegen generation', () => {
})

expect(result.content).toBe(
`// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nimport { z } from 'zod'\n\nexport interface AppUsersRow {\n id: string\n email: string | null\n}\n\nexport const AppUsersRowSchema = z.object({\n id: z.string(),\n email: z.string().nullable(),\n})\n\nexport type AppUsersRowInput = z.input<typeof AppUsersRowSchema>\nexport type AppUsersRowOutput = z.output<typeof AppUsersRowSchema>\n`
`// This file is auto-generated by chkit codegen — do not edit manually.\n// chkit-codegen-version: 0.1.0\n\nimport { z } from 'zod'\n\nexport type AppUsersRow = {\n id: string\n email: string | null\n}\n\nexport const AppUsersRowSchema = z.object({\n id: z.string(),\n email: z.string().nullable(),\n})\n\nexport type AppUsersRowInput = z.input<typeof AppUsersRowSchema>\nexport type AppUsersRowOutput = z.output<typeof AppUsersRowSchema>\n`
)
})
})
Expand Down