@@ -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