@@ -72,6 +72,9 @@ describe('embeded functions select', () => {
7272 } )
7373 )
7474 let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
75+ // Assert over the keys of the expected and result objects to ensure consistency between versions of types
76+ // should always fallback to a SelectQueryError if the relation cannot be found
77+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
7578 expectType < TypeEqual < typeof result , typeof expected > > ( true )
7679 ExpectedSchema . parse ( res . data )
7780 } )
@@ -130,6 +133,7 @@ describe('embeded functions select', () => {
130133 } )
131134 )
132135 let expected : z . infer < typeof ExpectedSchema >
136+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
133137 expectType < TypeEqual < typeof result , typeof expected > > ( true )
134138 ExpectedSchema . parse ( res . data )
135139 } )
@@ -204,6 +208,7 @@ describe('embeded functions select', () => {
204208 } )
205209 )
206210 let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
211+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
207212 expectType < TypeEqual < typeof result , typeof expected > > ( true )
208213 ExpectedSchema . parse ( res . data )
209214 } )
@@ -268,6 +273,7 @@ describe('embeded functions select', () => {
268273 } )
269274 )
270275 let expected : z . infer < typeof ExpectedSchema >
276+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
271277 expectType < TypeEqual < typeof result , typeof expected > > ( true )
272278 ExpectedSchema . parse ( res . data )
273279 } )
@@ -336,6 +342,7 @@ describe('embeded functions select', () => {
336342 } )
337343 )
338344 let expected : z . infer < typeof ExpectedSchema >
345+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
339346 expectType < TypeEqual < typeof result , typeof expected > > ( true )
340347 ExpectedSchema . parse ( res . data )
341348 } )
@@ -390,6 +397,7 @@ describe('embeded functions select', () => {
390397 } )
391398 )
392399 let expected : z . infer < typeof ExpectedSchema >
400+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
393401 expectType < TypeEqual < typeof result , typeof expected > > ( true )
394402 ExpectedSchema . parse ( res . data )
395403 } )
@@ -454,14 +462,17 @@ describe('embeded functions select', () => {
454462 } )
455463 )
456464 let expected : z . infer < typeof ExpectedSchema >
465+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
457466 expectType < TypeEqual < typeof result , typeof expected > > ( true )
458467 ExpectedSchema . parse ( res . data )
459468 } )
460469
461470 test ( 'embeded_setof_row_one_function_not_nullable - function returning a single row embeded table not nullable' , async ( ) => {
462471 const res = await postgrest
463472 . from ( 'users' )
464- . select ( 'username, user_called_profile_not_null:get_user_profile_non_nullable(*)' )
473+ // Inner join to ensure the join result is not nullable can also be set at relation level
474+ // by setting isNotNullable for the function SetofOptions definition to true
475+ . select ( 'username, user_called_profile_not_null:get_user_profile_non_nullable!inner(*)' )
465476 expect ( res ) . toMatchInlineSnapshot ( `
466477 Object {
467478 "count": null,
@@ -473,22 +484,6 @@ describe('embeded functions select', () => {
473484 },
474485 "username": "supabot",
475486 },
476- Object {
477- "user_called_profile_not_null": null,
478- "username": "kiwicopple",
479- },
480- Object {
481- "user_called_profile_not_null": null,
482- "username": "awailas",
483- },
484- Object {
485- "user_called_profile_not_null": null,
486- "username": "jsonuser",
487- },
488- Object {
489- "user_called_profile_not_null": null,
490- "username": "dragarcia",
491- },
492487 ],
493488 "error": null,
494489 "status": 200,
@@ -509,22 +504,10 @@ describe('embeded functions select', () => {
509504 } )
510505 )
511506 let expected : z . infer < typeof ExpectedSchema >
507+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
512508 expectType < TypeEqual < typeof result , typeof expected > > ( true )
513- // Parsing with the non-nullable schema should throw, because there are nulls in the data.
514- expect ( ( ) => ExpectedSchema . parse ( res . data ) ) . toThrowError ( )
515- // However, parsing with a nullable schema should succeed.
516- const ExpectedNullable = z . array (
517- z . object ( {
518- username : z . string ( ) ,
519- user_called_profile_not_null : z
520- . object ( {
521- id : z . number ( ) ,
522- username : z . string ( ) . nullable ( ) ,
523- } )
524- . nullable ( ) ,
525- } )
526- )
527- ExpectedNullable . parse ( res . data )
509+ // Can parse the data because the !inner ensure the join result from function is not nullable
510+ ExpectedSchema . parse ( res . data )
528511 } )
529512
530513 test ( 'embeded_setof_row_one_function_with_fields_selection - function returning a single row embeded table with fields selection' , async ( ) => {
@@ -581,6 +564,7 @@ describe('embeded functions select', () => {
581564 } )
582565 )
583566 let expected : z . infer < typeof ExpectedSchema >
567+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
584568 expectType < TypeEqual < typeof result , typeof expected > > ( true )
585569 ExpectedSchema . parse ( res . data )
586570 } )
@@ -655,6 +639,7 @@ describe('embeded functions select', () => {
655639 } )
656640 )
657641 let expected : z . infer < typeof ExpectedSchema >
642+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
658643 expectType < TypeEqual < typeof result , typeof expected > > ( true )
659644 ExpectedSchema . parse ( res . data )
660645 } )
@@ -729,6 +714,7 @@ describe('embeded functions select', () => {
729714 } )
730715 )
731716 let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
717+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
732718 expectType < TypeEqual < typeof result , typeof expected > > ( true )
733719 ExpectedSchema . parse ( res . data )
734720 } )
@@ -801,6 +787,7 @@ describe('embeded functions select', () => {
801787 } )
802788 )
803789 let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
790+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
804791 expectType < TypeEqual < typeof result , typeof expected > > ( true )
805792 ExpectedSchema . parse ( res . data )
806793 } )
@@ -877,6 +864,7 @@ describe('embeded functions select', () => {
877864 } )
878865 )
879866 let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
867+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
880868 expectType < TypeEqual < typeof result , typeof expected > > ( true )
881869 ExpectedSchema . parse ( res . data )
882870 } )
@@ -949,6 +937,7 @@ describe('embeded functions select', () => {
949937 } )
950938 )
951939 let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
940+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
952941 expectType < TypeEqual < typeof result , typeof expected > > ( true )
953942 ExpectedSchema . parse ( res . data )
954943 } )
@@ -1017,6 +1006,7 @@ describe('embeded functions select', () => {
10171006 } )
10181007 )
10191008 let expected : z . infer < typeof ExpectedSchema >
1009+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
10201010 expectType < TypeEqual < typeof result , typeof expected > > ( true )
10211011 ExpectedSchema . parse ( res . data )
10221012 } )
@@ -1088,6 +1078,7 @@ describe('embeded functions select', () => {
10881078 } )
10891079 )
10901080 let expected : z . infer < typeof ExpectedSchema >
1081+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
10911082 expectType < TypeEqual < typeof result , typeof expected > > ( true )
10921083 ExpectedSchema . parse ( res . data )
10931084 } )
@@ -1175,6 +1166,7 @@ describe('embeded functions select', () => {
11751166 } )
11761167 )
11771168 let expected : z . infer < typeof ExpectedSchema >
1169+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
11781170 expectType < TypeEqual < typeof result , typeof expected > > ( true )
11791171 ExpectedSchema . parse ( res . data )
11801172 } )
@@ -1229,6 +1221,7 @@ describe('embeded functions select', () => {
12291221 } )
12301222 )
12311223 let expected : z . infer < typeof ExpectedSchema >
1224+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
12321225 expectType < TypeEqual < typeof result , typeof expected > > ( true )
12331226 ExpectedSchema . parse ( res . data )
12341227 } )
0 commit comments