@@ -12,12 +12,6 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '
1212import { captureException } from '../exports' ;
1313import { SPAN_STATUS_ERROR , SPAN_STATUS_OK } from '../tracing' ;
1414
15- export interface SupabaseClientConstructor {
16- prototype : {
17- from : ( table : string ) => PostgrestQueryBuilder ;
18- } ;
19- }
20-
2115const AUTH_OPERATIONS_TO_INSTRUMENT = [
2216 'reauthenticate' ,
2317 'signInAnonymously' ,
@@ -40,9 +34,43 @@ const AUTH_ADMIN_OPERATIONS_TO_INSTRUMENT = [
4034 'inviteUserByEmail' ,
4135] ;
4236
37+ export const FILTER_MAPPINGS = {
38+ eq : 'eq' ,
39+ neq : 'neq' ,
40+ gt : 'gt' ,
41+ gte : 'gte' ,
42+ lt : 'lt' ,
43+ lte : 'lte' ,
44+ like : 'like' ,
45+ 'like(all)' : 'likeAllOf' ,
46+ 'like(any)' : 'likeAnyOf' ,
47+ ilike : 'ilike' ,
48+ 'ilike(all)' : 'ilikeAllOf' ,
49+ 'ilike(any)' : 'ilikeAnyOf' ,
50+ is : 'is' ,
51+ in : 'in' ,
52+ cs : 'contains' ,
53+ cd : 'containedBy' ,
54+ sr : 'rangeGt' ,
55+ nxl : 'rangeGte' ,
56+ sl : 'rangeLt' ,
57+ nxr : 'rangeLte' ,
58+ adj : 'rangeAdjacent' ,
59+ ov : 'overlaps' ,
60+ fts : '' ,
61+ plfts : 'plain' ,
62+ phfts : 'phrase' ,
63+ wfts : 'websearch' ,
64+ not : 'not' ,
65+ } ;
66+
67+ export const AVAILABLE_OPERATIONS = [ 'select' , 'insert' , 'upsert' , 'update' , 'delete' ] ;
68+
4369type AuthOperationFn = ( ...args : unknown [ ] ) => Promise < unknown > ;
4470type AuthOperationName = ( typeof AUTH_OPERATIONS_TO_INSTRUMENT ) [ number ] ;
4571type AuthAdminOperationName = ( typeof AUTH_ADMIN_OPERATIONS_TO_INSTRUMENT ) [ number ] ;
72+ type PostgrestQueryOperationName = ( typeof AVAILABLE_OPERATIONS ) [ number ] ;
73+ type PostgrestQueryOperationFn = ( ...args : unknown [ ] ) => PostgrestFilterBuilder ;
4674
4775export interface SupabaseClientInstance {
4876 auth : {
@@ -51,11 +79,7 @@ export interface SupabaseClientInstance {
5179}
5280
5381export interface PostgrestQueryBuilder {
54- select : ( ...args : unknown [ ] ) => PostgrestFilterBuilder ;
55- insert : ( ...args : unknown [ ] ) => PostgrestFilterBuilder ;
56- upsert : ( ...args : unknown [ ] ) => PostgrestFilterBuilder ;
57- update : ( ...args : unknown [ ] ) => PostgrestFilterBuilder ;
58- delete : ( ...args : unknown [ ] ) => PostgrestFilterBuilder ;
82+ [ key : PostgrestQueryOperationName ] : PostgrestQueryOperationFn ;
5983}
6084
6185export interface PostgrestFilterBuilder {
@@ -90,37 +114,18 @@ export interface SupabaseBreadcrumb {
90114 } ;
91115}
92116
93- export const AVAILABLE_OPERATIONS = [ 'select' , 'insert' , 'upsert' , 'update' , 'delete' ] ;
117+ export interface SupabaseClientConstructor {
118+ prototype : {
119+ from : ( table : string ) => PostgrestQueryBuilder ;
120+ } ;
121+ }
94122
95- export const FILTER_MAPPINGS = {
96- eq : 'eq' ,
97- neq : 'neq' ,
98- gt : 'gt' ,
99- gte : 'gte' ,
100- lt : 'lt' ,
101- lte : 'lte' ,
102- like : 'like' ,
103- 'like(all)' : 'likeAllOf' ,
104- 'like(any)' : 'likeAnyOf' ,
105- ilike : 'ilike' ,
106- 'ilike(all)' : 'ilikeAllOf' ,
107- 'ilike(any)' : 'ilikeAnyOf' ,
108- is : 'is' ,
109- in : 'in' ,
110- cs : 'contains' ,
111- cd : 'containedBy' ,
112- sr : 'rangeGt' ,
113- nxl : 'rangeGte' ,
114- sl : 'rangeLt' ,
115- nxr : 'rangeLte' ,
116- adj : 'rangeAdjacent' ,
117- ov : 'overlaps' ,
118- fts : '' ,
119- plfts : 'plain' ,
120- phfts : 'phrase' ,
121- wfts : 'websearch' ,
122- not : 'not' ,
123- } ;
123+ export interface PostgrestProtoThenable {
124+ then : < T > (
125+ onfulfilled ?: ( ( value : T ) => T | PromiseLike < T > ) | null ,
126+ onrejected ?: ( ( reason : any ) => T | PromiseLike < T > ) | null ,
127+ ) => Promise < T > ;
128+ }
124129
125130const instrumented = new Map ( ) ;
126131
@@ -289,32 +294,11 @@ function instrumentPostgrestFilterBuilder(PostgrestFilterBuilder: PostgrestFilte
289294 }
290295
291296 instrumented . set ( PostgrestFilterBuilder , {
292- then : (
293- PostgrestFilterBuilder . prototype as unknown as {
294- then : < T > (
295- onfulfilled ?: ( ( value : T ) => T | PromiseLike < T > ) | null ,
296- onrejected ?: ( ( reason : any ) => T | PromiseLike < T > ) | null ,
297- ) => Promise < T > ;
298- }
299- ) . then ,
297+ then : ( PostgrestFilterBuilder . prototype as unknown as PostgrestProtoThenable ) . then ,
300298 } ) ;
301299
302- (
303- PostgrestFilterBuilder . prototype as unknown as {
304- then : < T > (
305- onfulfilled ?: ( ( value : T ) => T | PromiseLike < T > ) | null ,
306- onrejected ?: ( ( reason : any ) => T | PromiseLike < T > ) | null ,
307- ) => Promise < T > ;
308- }
309- ) . then = new Proxy (
310- (
311- PostgrestFilterBuilder . prototype as unknown as {
312- then : < T > (
313- onfulfilled ?: ( ( value : T ) => T | PromiseLike < T > ) | null ,
314- onrejected ?: ( ( reason : any ) => T | PromiseLike < T > ) | null ,
315- ) => Promise < T > ;
316- }
317- ) . then ,
300+ ( PostgrestFilterBuilder . prototype as unknown as PostgrestProtoThenable ) . then = new Proxy (
301+ ( PostgrestFilterBuilder . prototype as unknown as PostgrestProtoThenable ) . then ,
318302 {
319303 apply ( target , thisArg , argumentsList ) {
320304 const operations = AVAILABLE_OPERATIONS ;
0 commit comments