@@ -2,6 +2,8 @@ import PostgrestQueryBuilder from './PostgrestQueryBuilder'
22import PostgrestFilterBuilder from './PostgrestFilterBuilder'
33import { Fetch , GenericSchema , ClientServerOptions } from './types/common/common'
44import { GetRpcFunctionFilterBuilderByArgs } from './types/common/rpc'
5+ import { PostgrestQueryBuilderOptions , PostgrestQueryBuilderOptionsWithSchema } from './types/types'
6+ import { mergeHeaders } from './utils'
57
68/**
79 * PostgREST client.
@@ -18,21 +20,21 @@ export default class PostgrestClient<
1820 ClientOptions extends ClientServerOptions = Database extends {
1921 __InternalSupabase : infer I extends ClientServerOptions
2022 }
21- ? I
22- : { } ,
23+ ? I
24+ : { } ,
2325 SchemaName extends string &
24- keyof Omit < Database , '__InternalSupabase' > = 'public' extends keyof Omit <
26+ keyof Omit < Database , '__InternalSupabase' > = 'public' extends keyof Omit <
2527 Database ,
2628 '__InternalSupabase'
2729 >
28- ? 'public'
29- : string & keyof Omit < Database , '__InternalSupabase' > ,
30+ ? 'public'
31+ : string & keyof Omit < Database , '__InternalSupabase' > ,
3032 Schema extends GenericSchema = Omit <
3133 Database ,
3234 '__InternalSupabase'
3335 > [ SchemaName ] extends GenericSchema
34- ? Omit < Database , '__InternalSupabase' > [ SchemaName ]
35- : any ,
36+ ? Omit < Database , '__InternalSupabase' > [ SchemaName ]
37+ : any ,
3638> {
3739 url : string
3840 headers : Headers
@@ -55,11 +57,7 @@ export default class PostgrestClient<
5557 headers = { } ,
5658 schema,
5759 fetch,
58- } : {
59- headers ?: HeadersInit
60- schema ?: SchemaName
61- fetch ?: Fetch
62- } = { }
60+ } : PostgrestQueryBuilderOptionsWithSchema < SchemaName > = { }
6361 ) {
6462 this . url = url
6563 this . headers = new Headers ( headers )
@@ -69,21 +67,28 @@ export default class PostgrestClient<
6967 from <
7068 TableName extends string & keyof Schema [ 'Tables' ] ,
7169 Table extends Schema [ 'Tables' ] [ TableName ] ,
72- > ( relation : TableName ) : PostgrestQueryBuilder < ClientOptions , Schema , Table , TableName >
70+ > (
71+ relation : TableName ,
72+ options ?: PostgrestQueryBuilderOptions
73+ ) : PostgrestQueryBuilder < ClientOptions , Schema , Table , TableName > ;
7374 from < ViewName extends string & keyof Schema [ 'Views' ] , View extends Schema [ 'Views' ] [ ViewName ] > (
74- relation : ViewName
75- ) : PostgrestQueryBuilder < ClientOptions , Schema , View , ViewName >
75+ relation : ViewName ,
76+ options ?: PostgrestQueryBuilderOptions
77+ ) : PostgrestQueryBuilder < ClientOptions , Schema , View , ViewName > ;
7678 /**
7779 * Perform a query on a table or a view.
7880 *
7981 * @param relation - The table or view name to query
8082 */
81- from ( relation : string ) : PostgrestQueryBuilder < ClientOptions , Schema , any , any > {
83+ from (
84+ relation : string ,
85+ options ?: PostgrestQueryBuilderOptions
86+ ) : PostgrestQueryBuilder < ClientOptions , Schema , any , any > {
8287 const url = new URL ( `${ this . url } /${ relation } ` )
8388 return new PostgrestQueryBuilder ( url , {
84- headers : new Headers ( this . headers ) ,
89+ headers : mergeHeaders ( this . headers , options ? .headers ) ,
8590 schema : this . schemaName ,
86- fetch : this . fetch ,
91+ fetch : options ?. fetch ?? this . fetch ,
8792 } )
8893 }
8994
0 commit comments