@@ -68,7 +68,6 @@ describe('embeded functions select', () => {
68
68
id : z . number ( ) ,
69
69
message : z . string ( ) . nullable ( ) ,
70
70
username : z . string ( ) ,
71
- blurb_message : z . string ( ) . nullable ( ) ,
72
71
} )
73
72
) ,
74
73
} )
@@ -198,7 +197,6 @@ describe('embeded functions select', () => {
198
197
z . object ( {
199
198
channel_id : z . number ( ) ,
200
199
data : z . unknown ( ) . nullable ( ) ,
201
- blurb_message : z . string ( ) . nullable ( ) ,
202
200
id : z . number ( ) ,
203
201
message : z . string ( ) . nullable ( ) ,
204
202
username : z . string ( ) ,
@@ -367,6 +365,9 @@ describe('embeded functions select', () => {
367
365
}
368
366
` )
369
367
let result : Exclude < typeof res . data , null >
368
+ // The override marks this as not nullable, but the data can be null at runtime.
369
+ // So the correct runtime schema is nullable, but the type is not.
370
+ // We check that the type is as expected (not nullable), but parsing will fail.
370
371
const ExpectedSchema = z . array (
371
372
z . object ( {
372
373
username : z . string ( ) ,
@@ -378,7 +379,21 @@ describe('embeded functions select', () => {
378
379
)
379
380
let expected : z . infer < typeof ExpectedSchema >
380
381
expectType < TypeEqual < typeof result , typeof expected > > ( true )
381
- ExpectedSchema . parse ( res . data )
382
+ // Parsing with the non-nullable schema should throw, because there are nulls in the data.
383
+ expect ( ( ) => ExpectedSchema . parse ( res . data ) ) . toThrowError ( )
384
+ // However, parsing with a nullable schema should succeed.
385
+ const ExpectedNullable = z . array (
386
+ z . object ( {
387
+ username : z . string ( ) ,
388
+ user_called_profile_not_null : z
389
+ . object ( {
390
+ id : z . number ( ) ,
391
+ username : z . string ( ) . nullable ( ) ,
392
+ } )
393
+ . nullable ( ) ,
394
+ } )
395
+ )
396
+ ExpectedNullable . parse ( res . data )
382
397
} )
383
398
384
399
test ( 'embeded_setof_row_one_function_with_fields_selection - function returning a single row embeded table with fields selection' , async ( ) => {
@@ -572,7 +587,6 @@ describe('embeded functions select', () => {
572
587
id : z . number ( ) ,
573
588
message : z . string ( ) . nullable ( ) ,
574
589
username : z . string ( ) ,
575
- blurb_message : z . string ( ) . nullable ( ) ,
576
590
} )
577
591
) ,
578
592
} )
@@ -645,7 +659,6 @@ describe('embeded functions select', () => {
645
659
id : z . number ( ) ,
646
660
message : z . string ( ) . nullable ( ) ,
647
661
username : z . string ( ) ,
648
- blurb_message : z . string ( ) . nullable ( ) ,
649
662
} )
650
663
) ,
651
664
} )
@@ -888,10 +901,8 @@ describe('embeded functions select', () => {
888
901
}
889
902
` )
890
903
let result : Exclude < typeof res . data , null >
891
- const ExpectedSchema = z . array ( z . never ( ) )
892
- let expected : z . infer < typeof ExpectedSchema >
904
+ let expected : never [ ]
893
905
expectType < TypeEqual < typeof result , typeof expected > > ( true )
894
- ExpectedSchema . parse ( res . data )
895
906
} )
896
907
897
908
test ( 'embeded_function_returning_single_row - can embed single row returns function with row single param' , async ( ) => {
0 commit comments