Skip to content

Commit 96bd800

Browse files
committed
wip
1 parent f104d94 commit 96bd800

File tree

9 files changed

+1559
-1675
lines changed

9 files changed

+1559
-1675
lines changed

src/PostgrestClient.ts

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export type GetRpcFunctionFilterBuilderByArgs<
3434
// on the function arguments provided
3535
Args extends GenericFunction['Args']
3636
? FindMatchingFunctionByArgs<Schema['Functions'][FnName], Args>
37+
: // If we can't find a matching function by args, we try to find one by function name
38+
ExtractExactFunction<Schema['Functions'][FnName], Args> extends GenericFunction
39+
? ExtractExactFunction<Schema['Functions'][FnName], Args>
3740
: any
3841
}[1] extends infer Fn
3942
? // If we are dealing with an non-typed client everything is any
@@ -192,9 +195,17 @@ export default class PostgrestClient<
192195
* `"estimated"`: Uses exact count for low numbers and planned count for high
193196
* numbers.
194197
*/
195-
rpc<FnName extends string & keyof Schema['Functions'], Fn extends Schema['Functions'][FnName]>(
198+
rpc<
199+
FnName extends string & keyof Schema['Functions'],
200+
Args extends Schema['Functions'][FnName]['Args'] = {},
201+
FilterBuilder extends GetRpcFunctionFilterBuilderByArgs<
202+
Schema,
203+
FnName,
204+
Args
205+
> = GetRpcFunctionFilterBuilderByArgs<Schema, FnName, Args>
206+
>(
196207
fn: FnName,
197-
args: Fn['Args'] = {},
208+
args: Args = {} as Args,
198209
{
199210
head = false,
200211
get = false,
@@ -207,14 +218,10 @@ export default class PostgrestClient<
207218
): PostgrestFilterBuilder<
208219
ClientOptions,
209220
Schema,
210-
Fn['Returns'] extends any[]
211-
? Fn['Returns'][number] extends Record<string, unknown>
212-
? Fn['Returns'][number]
213-
: {}
214-
: {},
215-
Fn['Returns'],
216-
FnName,
217-
null,
221+
FilterBuilder['Row'],
222+
FilterBuilder['Result'],
223+
FilterBuilder['RelationName'],
224+
FilterBuilder['Relationships'],
218225
'RPC'
219226
> {
220227
let method: 'HEAD' | 'GET' | 'POST'

src/select-query-parser/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { GenericSetofOption } from '../types'
12
import { Ast } from './parser'
23
import {
34
AggregateFunctions,
@@ -653,8 +654,8 @@ type MatchingFunctionBySetofFrom<
653654
> = Fn['SetofOptions'] extends GenericSetofOption
654655
? TableName extends Fn['SetofOptions']['from']
655656
? Fn
656-
: never
657-
: never
657+
: false
658+
: false
658659

659660
type FindMatchingFunctionBySetofFrom<
660661
FnUnion,

test/advanced_rpc.test-d.ts

Lines changed: 0 additions & 322 deletions
This file was deleted.

0 commit comments

Comments
 (0)