(...interceptorOrKeys: InterceptorOrKey[])
| 281 | * resolved to be interceptors |
| 282 | */ |
| 283 | export 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 |
no test coverage detected