Skip to content

Commit f104d94

Browse files
committed
wip
1 parent a789624 commit f104d94

File tree

6 files changed

+669
-308
lines changed

6 files changed

+669
-308
lines changed

src/PostgrestClient.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ export default class PostgrestClient<
210210
Fn['Returns'] extends any[]
211211
? Fn['Returns'][number] extends Record<string, unknown>
212212
? Fn['Returns'][number]
213-
: never
214-
: never,
213+
: {}
214+
: {},
215215
Fn['Returns'],
216216
FnName,
217217
null,

src/select-query-parser/utils.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -484,19 +484,6 @@ export type ResolveForwardRelationship<
484484
: SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`>
485485
: SelectQueryError<`could not find the relation between ${CurrentTableOrView} and ${Field['name']}`>
486486

487-
type ResolveEmbededFunctionJoinTableRelationship<
488-
Schema extends GenericSchema,
489-
CurrentTableOrView extends keyof TablesAndViews<Schema> & string,
490-
FieldName extends string
491-
> = FindMatchingFunctionBySetofFrom<
492-
Schema['Functions'][FieldName],
493-
CurrentTableOrView
494-
> extends infer Fn
495-
? Fn extends GenericFunction
496-
? Fn['SetofOptions']
497-
: false
498-
: false
499-
500487
/**
501488
* Given a CurrentTableOrView, finds all join tables to this relation.
502489
* For example, if products and categories are linked via product_categories table:
@@ -535,6 +522,19 @@ type ResolveJoinTableRelationship<
535522
: never
536523
}[keyof TablesAndViews<Schema>]
537524

525+
type ResolveEmbededFunctionJoinTableRelationship<
526+
Schema extends GenericSchema,
527+
CurrentTableOrView extends keyof TablesAndViews<Schema> & string,
528+
FieldName extends string
529+
> = FindMatchingFunctionBySetofFrom<
530+
Schema['Functions'][FieldName],
531+
CurrentTableOrView
532+
> extends infer Fn
533+
? Fn extends GenericFunction
534+
? Fn['SetofOptions']
535+
: false
536+
: false
537+
538538
export type FindJoinTableRelationship<
539539
Schema extends GenericSchema,
540540
CurrentTableOrView extends keyof TablesAndViews<Schema> & string,

test/advanced_rpc.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ describe('rpc', () => {
522522
user_row: { username: 'supabot' },
523523
})
524524
.select('id, username, users(username, catchphrase)')
525+
//@ts-expect-error will complain about missing the rest of the params
525526
.eq('username', 'nope')
526527

527528
expect(res).toMatchInlineSnapshot(`
@@ -551,6 +552,32 @@ describe('rpc', () => {
551552
"statusText": "OK",
552553
}
553554
`)
555+
const res3 = await postgrest
556+
.rpc('get_user_profile', {
557+
//@ts-expect-error will complain about missing the rest of the params
558+
user_row: { username: 'supabot' },
559+
})
560+
// should also be able to fitler before the select
561+
.eq('username', 'supabot')
562+
.select('username, users(username, catchphrase)')
563+
564+
expect(res3).toMatchInlineSnapshot(`
565+
Object {
566+
"count": null,
567+
"data": Array [
568+
Object {
569+
"username": "supabot",
570+
"users": Object {
571+
"catchphrase": "'cat' 'fat'",
572+
"username": "supabot",
573+
},
574+
},
575+
],
576+
"error": null,
577+
"status": 200,
578+
"statusText": "OK",
579+
}
580+
`)
554581
})
555582

556583
test('unresolvable function with text param', async () => {

0 commit comments

Comments
 (0)