@@ -251,6 +251,10 @@ export const apply = async (meta: GeneratorMetadata): Promise<string> => {
251
251
. filter ( ( t ) => t . schema === defaultSchema . name )
252
252
. sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
253
253
254
+ const defaultSchemaViews = [ ...views ]
255
+ . filter ( ( v ) => v . schema === defaultSchema . name )
256
+ . sort ( ( { name : a } , { name : b } ) => a . localeCompare ( b ) )
257
+
254
258
// Helpers are now defined at the top of the file
255
259
256
260
const makeListShapeLine = ( col : PostgresColumn , ctx : PgTypeCtx ) => {
@@ -281,7 +285,7 @@ export const apply = async (meta: GeneratorMetadata): Promise<string> => {
281
285
type : 'to-one' ,
282
286
targetTable : relation . referenced_relation ,
283
287
targetKey : relation . referenced_columns [ 0 ] ,
284
- sourceKey : relation . columns [ 0 ]
288
+ sourceKey : relation . columns [ 0 ] ,
285
289
} )
286
290
typeVal = withNullable ( typeVal , true )
287
291
@@ -305,16 +309,17 @@ export const apply = async (meta: GeneratorMetadata): Promise<string> => {
305
309
${ zodHelperScript }
306
310
307
311
export const supabaseZodSchemas = {
308
- ${ defaultSchemaTables
309
- . map ( ( table ) => {
312
+ ${ [ ...defaultSchemaTables , ...defaultSchemaViews ]
313
+ . map ( ( tableOrView ) => {
314
+ const isView = defaultSchemaViews . includes ( tableOrView as any )
310
315
const ctx : PgTypeCtx = { types, schemas, tables, views }
311
- const cols = columnsByTableId [ table . id ] ?? [ ]
316
+ const cols = columnsByTableId [ tableOrView . id ] ?? [ ]
312
317
const relevantRels = relationships
313
318
. filter (
314
319
( relationship ) =>
315
- relationship . schema === table . schema &&
316
- relationship . referenced_schema === table . schema &&
317
- relationship . relation === table . name
320
+ relationship . schema === tableOrView . schema &&
321
+ relationship . referenced_schema === tableOrView . schema &&
322
+ relationship . relation === tableOrView . name
318
323
)
319
324
. sort (
320
325
( a , b ) =>
@@ -329,7 +334,7 @@ export const supabaseZodSchemas = {
329
334
. join ( ',\n ' )
330
335
331
336
// Get many-to-many relationships for this table
332
- const manyToManyRels = tableToManyToMany [ table . name ] || [ ]
337
+ const manyToManyRels = tableToManyToMany [ tableOrView . name ] || [ ]
333
338
const manyToManyShape = manyToManyRels
334
339
. filter ( ( relatedTable ) => {
335
340
// Don't add if there's already a relevant relationship with the same table
@@ -359,7 +364,15 @@ export const supabaseZodSchemas = {
359
364
. filter ( ( shape ) => shape . length > 0 )
360
365
. join ( ',\n ' )
361
366
362
- return `${ JSON . stringify ( table . name ) } : {
367
+ if ( isView ) {
368
+ return `${ JSON . stringify ( tableOrView . name ) } : {
369
+ list: z.object({
370
+ ${ finalListShape }
371
+ }),
372
+ }`
373
+ }
374
+
375
+ return `${ JSON . stringify ( tableOrView . name ) } : {
363
376
list: z.object({
364
377
${ finalListShape }
365
378
}),
0 commit comments