Skip to content

Commit b630367

Browse files
committed
Clean up
1 parent d387514 commit b630367

File tree

1 file changed

+49
-65
lines changed

1 file changed

+49
-65
lines changed

packages/core/src/integrations/supabase.ts

Lines changed: 49 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ import { SEMANTIC_ATTRIBUTE_SENTRY_OP, SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN } from '
1212
import { captureException } from '../exports';
1313
import { SPAN_STATUS_ERROR, SPAN_STATUS_OK } from '../tracing';
1414

15-
export interface SupabaseClientConstructor {
16-
prototype: {
17-
from: (table: string) => PostgrestQueryBuilder;
18-
};
19-
}
20-
2115
const 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+
4369
type AuthOperationFn = (...args: unknown[]) => Promise<unknown>;
4470
type AuthOperationName = (typeof AUTH_OPERATIONS_TO_INSTRUMENT)[number];
4571
type AuthAdminOperationName = (typeof AUTH_ADMIN_OPERATIONS_TO_INSTRUMENT)[number];
72+
type PostgrestQueryOperationName = (typeof AVAILABLE_OPERATIONS)[number];
73+
type PostgrestQueryOperationFn = (...args: unknown[]) => PostgrestFilterBuilder;
4674

4775
export interface SupabaseClientInstance {
4876
auth: {
@@ -51,11 +79,7 @@ export interface SupabaseClientInstance {
5179
}
5280

5381
export 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

6185
export 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

125130
const 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

Comments
 (0)