@@ -72,6 +72,9 @@ describe('embeded functions select', () => {
72
72
} )
73
73
)
74
74
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 )
75
78
expectType < TypeEqual < typeof result , typeof expected > > ( true )
76
79
ExpectedSchema . parse ( res . data )
77
80
} )
@@ -130,6 +133,7 @@ describe('embeded functions select', () => {
130
133
} )
131
134
)
132
135
let expected : z . infer < typeof ExpectedSchema >
136
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
133
137
expectType < TypeEqual < typeof result , typeof expected > > ( true )
134
138
ExpectedSchema . parse ( res . data )
135
139
} )
@@ -204,6 +208,7 @@ describe('embeded functions select', () => {
204
208
} )
205
209
)
206
210
let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
211
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
207
212
expectType < TypeEqual < typeof result , typeof expected > > ( true )
208
213
ExpectedSchema . parse ( res . data )
209
214
} )
@@ -268,6 +273,7 @@ describe('embeded functions select', () => {
268
273
} )
269
274
)
270
275
let expected : z . infer < typeof ExpectedSchema >
276
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
271
277
expectType < TypeEqual < typeof result , typeof expected > > ( true )
272
278
ExpectedSchema . parse ( res . data )
273
279
} )
@@ -336,6 +342,7 @@ describe('embeded functions select', () => {
336
342
} )
337
343
)
338
344
let expected : z . infer < typeof ExpectedSchema >
345
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
339
346
expectType < TypeEqual < typeof result , typeof expected > > ( true )
340
347
ExpectedSchema . parse ( res . data )
341
348
} )
@@ -390,6 +397,7 @@ describe('embeded functions select', () => {
390
397
} )
391
398
)
392
399
let expected : z . infer < typeof ExpectedSchema >
400
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
393
401
expectType < TypeEqual < typeof result , typeof expected > > ( true )
394
402
ExpectedSchema . parse ( res . data )
395
403
} )
@@ -454,14 +462,17 @@ describe('embeded functions select', () => {
454
462
} )
455
463
)
456
464
let expected : z . infer < typeof ExpectedSchema >
465
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
457
466
expectType < TypeEqual < typeof result , typeof expected > > ( true )
458
467
ExpectedSchema . parse ( res . data )
459
468
} )
460
469
461
470
test ( 'embeded_setof_row_one_function_not_nullable - function returning a single row embeded table not nullable' , async ( ) => {
462
471
const res = await postgrest
463
472
. 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(*)' )
465
476
expect ( res ) . toMatchInlineSnapshot ( `
466
477
Object {
467
478
"count": null,
@@ -473,22 +484,6 @@ describe('embeded functions select', () => {
473
484
},
474
485
"username": "supabot",
475
486
},
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
- },
492
487
],
493
488
"error": null,
494
489
"status": 200,
@@ -509,22 +504,10 @@ describe('embeded functions select', () => {
509
504
} )
510
505
)
511
506
let expected : z . infer < typeof ExpectedSchema >
507
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
512
508
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 )
528
511
} )
529
512
530
513
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', () => {
581
564
} )
582
565
)
583
566
let expected : z . infer < typeof ExpectedSchema >
567
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
584
568
expectType < TypeEqual < typeof result , typeof expected > > ( true )
585
569
ExpectedSchema . parse ( res . data )
586
570
} )
@@ -655,6 +639,7 @@ describe('embeded functions select', () => {
655
639
} )
656
640
)
657
641
let expected : z . infer < typeof ExpectedSchema >
642
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
658
643
expectType < TypeEqual < typeof result , typeof expected > > ( true )
659
644
ExpectedSchema . parse ( res . data )
660
645
} )
@@ -729,6 +714,7 @@ describe('embeded functions select', () => {
729
714
} )
730
715
)
731
716
let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
717
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
732
718
expectType < TypeEqual < typeof result , typeof expected > > ( true )
733
719
ExpectedSchema . parse ( res . data )
734
720
} )
@@ -801,6 +787,7 @@ describe('embeded functions select', () => {
801
787
} )
802
788
)
803
789
let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
790
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
804
791
expectType < TypeEqual < typeof result , typeof expected > > ( true )
805
792
ExpectedSchema . parse ( res . data )
806
793
} )
@@ -877,6 +864,7 @@ describe('embeded functions select', () => {
877
864
} )
878
865
)
879
866
let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
867
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
880
868
expectType < TypeEqual < typeof result , typeof expected > > ( true )
881
869
ExpectedSchema . parse ( res . data )
882
870
} )
@@ -949,6 +937,7 @@ describe('embeded functions select', () => {
949
937
} )
950
938
)
951
939
let expected : RequiredDeep < z . infer < typeof ExpectedSchema > >
940
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
952
941
expectType < TypeEqual < typeof result , typeof expected > > ( true )
953
942
ExpectedSchema . parse ( res . data )
954
943
} )
@@ -1017,6 +1006,7 @@ describe('embeded functions select', () => {
1017
1006
} )
1018
1007
)
1019
1008
let expected : z . infer < typeof ExpectedSchema >
1009
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
1020
1010
expectType < TypeEqual < typeof result , typeof expected > > ( true )
1021
1011
ExpectedSchema . parse ( res . data )
1022
1012
} )
@@ -1088,6 +1078,7 @@ describe('embeded functions select', () => {
1088
1078
} )
1089
1079
)
1090
1080
let expected : z . infer < typeof ExpectedSchema >
1081
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
1091
1082
expectType < TypeEqual < typeof result , typeof expected > > ( true )
1092
1083
ExpectedSchema . parse ( res . data )
1093
1084
} )
@@ -1175,6 +1166,7 @@ describe('embeded functions select', () => {
1175
1166
} )
1176
1167
)
1177
1168
let expected : z . infer < typeof ExpectedSchema >
1169
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
1178
1170
expectType < TypeEqual < typeof result , typeof expected > > ( true )
1179
1171
ExpectedSchema . parse ( res . data )
1180
1172
} )
@@ -1229,6 +1221,7 @@ describe('embeded functions select', () => {
1229
1221
} )
1230
1222
)
1231
1223
let expected : z . infer < typeof ExpectedSchema >
1224
+ expectType < TypeEqual < keyof ( typeof expected ) [ number ] , keyof ( typeof result ) [ number ] > > ( true )
1232
1225
expectType < TypeEqual < typeof result , typeof expected > > ( true )
1233
1226
ExpectedSchema . parse ( res . data )
1234
1227
} )
0 commit comments