MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / intercept

Function intercept

packages/context/src/interceptor.ts:283–316  ·  view source on GitHub ↗
(...interceptorOrKeys: InterceptorOrKey[])

Source from the content-addressed store, hash-verified

281 * resolved to be interceptors
282 */
283export function intercept(...interceptorOrKeys: InterceptorOrKey[]) {
284 return function interceptDecoratorForClassOrMethod(
285 // Class or a prototype
286 // eslint-disable-next-line @typescript-eslint/no-explicit-any
287 target: any,
288 method?: string,
289 // Use `any` to for `TypedPropertyDescriptor`
290 // See https://github.com/loopbackio/loopback-next/pull/2704
291 // eslint-disable-next-line @typescript-eslint/no-explicit-any
292 methodDescriptor?: TypedPropertyDescriptor<any>,
293 ) {
294 if (method && methodDescriptor) {
295 // Method
296 return InterceptMethodDecoratorFactory.createDecorator(
297 INTERCEPT_METHOD_KEY,
298 interceptorOrKeys,
299 {decoratorName: '@intercept'},
300 )(target, method, methodDescriptor!);
301 }
302 if (typeof target === 'function' && !method && !methodDescriptor) {
303 // Class
304 return InterceptClassDecoratorFactory.createDecorator(
305 INTERCEPT_CLASS_KEY,
306 interceptorOrKeys,
307 {decoratorName: '@intercept'},
308 )(target);
309 }
310 // Not on a class or method
311 throw new Error(
312 '@intercept cannot be used on a property: ' +
313 DecoratorFactory.getTargetName(target, method, methodDescriptor),
314 );
315 };
316}
317
318/**
319 * Invoke a method with the given context

Callers 10

MyControllerClass · 0.85
MyControllerClass · 0.85
MyControllerClass · 0.85
MyControllerClass · 0.85
logInvocationFunction · 0.85

Calls 2

getTargetNameMethod · 0.80
createDecoratorMethod · 0.45

Tested by

no test coverage detected