Skip to content

Commit 935f528

Browse files
committed
fix(typegen): {} -> { [_ in never]: never }
1 parent a6b9015 commit 935f528

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

src/lib/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,18 @@ export {
88
PostgresConfig,
99
PostgresExtension,
1010
PostgresFunction,
11+
PostgresFunctionCreate,
1112
PostgresPolicy,
1213
PostgresPrimaryKey,
1314
PostgresPublication,
1415
PostgresRelationship,
1516
PostgresRole,
1617
PostgresSchema,
18+
PostgresSchemaCreate,
19+
PostgresSchemaUpdate,
1720
PostgresTable,
1821
PostgresTrigger,
1922
PostgresType,
2023
PostgresVersion,
24+
PostgresView,
2125
} from './types'

src/server/app.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ if (EXPORT_DOCS) {
9292
GENERATE_TYPES_INCLUDED_SCHEMAS.includes(name)
9393
),
9494
tables,
95-
functions: functions.filter((f) => !['trigger', 'event_trigger'].includes(f.return_type)),
95+
functions: functions.filter(
96+
({ return_type }) => !['trigger', 'event_trigger'].includes(return_type)
97+
),
9698
types,
9799
})
98100
)

src/server/routes/generators/typescript.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ export default async (fastify: FastifyInstance) => {
5555
(includedSchemas.length === 0 || includedSchemas.includes(name))
5656
),
5757
tables,
58-
functions: functions.filter((f) => !['trigger', 'event_trigger'].includes(f.return_type)),
58+
functions: functions.filter(
59+
({ return_type }) => !['trigger', 'event_trigger'].includes(return_type)
60+
),
5961
types,
6062
})
6163
})

src/server/templates/typescript.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ export const apply = ({
1616
export type Json = string | number | boolean | null | { [key: string]: Json } | Json[]
1717
1818
export interface Database {
19-
${schemas.map(
20-
(schema) =>
21-
`${JSON.stringify(schema.name)}: {
19+
${schemas.map((schema) => {
20+
const schemaTables = tables.filter((table) => table.schema === schema.name)
21+
const schemaFunctions = functions.filter((func) => func.schema === schema.name)
22+
return `${JSON.stringify(schema.name)}: {
2223
Tables: {
23-
${tables
24-
.filter((table) => table.schema === schema.name)
25-
.map(
26-
(table) => `${JSON.stringify(table.name)}: {
24+
${
25+
schemaTables.length === 0
26+
? '[_ in never]: never'
27+
: schemaTables.map(
28+
(table) => `${JSON.stringify(table.name)}: {
2729
Row: {
2830
${table.columns.map(
2931
(column) =>
@@ -77,13 +79,15 @@ export interface Database {
7779
})}
7880
}
7981
}`
80-
)}
82+
)
83+
}
8184
}
8285
Functions: {
83-
${functions
84-
.filter((func) => func.schema === schema.name)
85-
.map(
86-
(func) => `${JSON.stringify(func.name)}: {
86+
${
87+
schemaFunctions.length === 0
88+
? '[_ in never]: never'
89+
: schemaFunctions.map(
90+
(func) => `${JSON.stringify(func.name)}: {
8791
Args: ${(() => {
8892
if (func.argument_types === '') {
8993
return 'Record<PropertyKey, never>'
@@ -109,10 +113,11 @@ export interface Database {
109113
})()}
110114
Returns: ${pgTypeToTsType(func.return_type, types)}
111115
}`
112-
)}
116+
)
117+
}
113118
}
114119
}`
115-
)}
120+
})}
116121
}`
117122

118123
output = prettier.format(output, {

0 commit comments

Comments
 (0)