Skip to content

Commit e6eca29

Browse files
committed
Fix TypeScript build errors and double-wrap guard
1 parent 71c40cf commit e6eca29

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

packages/core/src/integrations/supabase/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const FILTER_MAPPINGS = {
5050
not: 'not',
5151
};
5252

53-
export const DB_OPERATIONS_TO_INSTRUMENT = ['select', 'insert', 'upsert', 'update', 'delete'] as const;
53+
export const DB_OPERATIONS_TO_INSTRUMENT = ['select', 'insert', 'upsert', 'update', 'delete'];
5454

5555
export const QUEUE_RPC_OPERATIONS = new Set(['send', 'send_batch', 'pop', 'receive', 'read']);
5656

packages/core/src/integrations/supabase/postgrest.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -228,12 +228,8 @@ export function _instrumentPostgRESTFilterBuilderInstance(builder: PostgRESTFilt
228228
return;
229229
}
230230

231-
// Check if the instance has its own .then property (not inherited from prototype)
232-
const hasOwnThen = Object.prototype.hasOwnProperty.call(builder, 'then');
233-
234-
// If the instance has its own .then that's not instrumented, we need to instrument it
235-
// even if the prototype's .then is already instrumented
236-
if (_isInstrumented(originalThen) && !hasOwnThen) {
231+
// Skip if already instrumented (whether from prototype or own property)
232+
if (_isInstrumented(originalThen)) {
237233
return;
238234
}
239235

@@ -259,22 +255,18 @@ export function _instrumentPostgRESTQueryBuilder(PostgRESTQueryBuilder: new () =
259255
// We need to wrap _all_ operations despite them sharing the same `PostgRESTFilterBuilder`
260256
// constructor, as we don't know which method will be called first, and we don't want to miss any calls.
261257
for (const operation of DB_OPERATIONS_TO_INSTRUMENT) {
262-
type PostgRESTOperation = keyof Pick<PostgRESTQueryBuilder, 'select' | 'insert' | 'upsert' | 'update' | 'delete'>;
263-
const prototypeWithOps = PostgRESTQueryBuilder.prototype as Partial<
264-
Record<PostgRESTOperation, PostgRESTQueryBuilder[PostgRESTOperation]>
265-
>;
266-
267-
const originalOperation = prototypeWithOps[operation];
258+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
259+
const prototypeWithOps = PostgRESTQueryBuilder.prototype as Record<string, any>;
268260

269-
if (_isInstrumented(originalOperation)) {
261+
if (_isInstrumented(prototypeWithOps[operation])) {
270262
continue;
271263
}
272264

273-
if (!originalOperation) {
265+
if (!prototypeWithOps[operation]) {
274266
continue;
275267
}
276268

277-
const wrappedOperation = new Proxy(originalOperation, {
269+
prototypeWithOps[operation] = new Proxy(prototypeWithOps[operation], {
278270
apply(target: PostgRESTQueryOperationFn, thisArg: unknown, argumentsList: Parameters<PostgRESTQueryOperationFn>) {
279271
const rv = Reflect.apply(target, thisArg, argumentsList);
280272
const PostgRESTFilterBuilderCtor = rv.constructor;
@@ -288,9 +280,7 @@ export function _instrumentPostgRESTQueryBuilder(PostgRESTQueryBuilder: new () =
288280
},
289281
});
290282

291-
prototypeWithOps[operation] = wrappedOperation;
292-
293-
_markAsInstrumented(wrappedOperation);
283+
_markAsInstrumented(prototypeWithOps[operation]);
294284
}
295285
}
296286

0 commit comments

Comments
 (0)