@@ -16,14 +16,16 @@ export const apply = ({
1616export type Json = string | number | boolean | null | { [key: string]: Json } | Json[]
1717
1818export 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,22 +79,21 @@ export interface Database {
7779 } ) }
7880 }
7981 }`
80- ) }
82+ )
83+ }
8184 }
8285 Functions: {
83- ${ functions
84- . filter (
85- ( function_ ) =>
86- function_ . schema === schema . name && function_ . return_type !== 'trigger'
87- )
88- . map (
89- ( function_ ) => `${ JSON . stringify ( function_ . name ) } : {
86+ ${
87+ schemaFunctions . length === 0
88+ ? '[_ in never]: never'
89+ : schemaFunctions . map (
90+ ( func ) => `${ JSON . stringify ( func . name ) } : {
9091 Args: ${ ( ( ) => {
91- if ( function_ . argument_types === '' ) {
92+ if ( func . argument_types === '' ) {
9293 return 'Record<PropertyKey, never>'
9394 }
9495
95- const splitArgs = function_ . argument_types . split ( ',' ) . map ( ( arg ) => arg . trim ( ) )
96+ const splitArgs = func . argument_types . split ( ',' ) . map ( ( arg ) => arg . trim ( ) )
9697 if ( splitArgs . some ( ( arg ) => arg . includes ( '"' ) || ! arg . includes ( ' ' ) ) ) {
9798 return 'Record<string, unknown>'
9899 }
@@ -110,12 +111,13 @@ export interface Database {
110111 ( { name, type } ) => `${ JSON . stringify ( name ) } : ${ type } `
111112 ) } }`
112113 } ) ( ) }
113- Returns: ${ pgTypeToTsType ( function_ . return_type , types ) }
114+ Returns: ${ pgTypeToTsType ( func . return_type , types ) }
114115 }`
115- ) }
116+ )
117+ }
116118 }
117119 }`
118- ) }
120+ } ) }
119121}`
120122
121123 output = prettier . format ( output , {
0 commit comments