( firstHandler: ExpressRequestHandler, ...additionalHandlers: ExpressRequestHandler[] )
| 96 | * @typeParam CTX - Context type |
| 97 | */ |
| 98 | export function toInterceptor<CTX extends Context = InvocationContext>( |
| 99 | firstHandler: ExpressRequestHandler, |
| 100 | ...additionalHandlers: ExpressRequestHandler[] |
| 101 | ): GenericInterceptor<CTX> { |
| 102 | if (additionalHandlers.length === 0) { |
| 103 | const handlerFn = firstHandler; |
| 104 | return toInterceptorFromExpressMiddleware<CTX>(handlerFn); |
| 105 | } |
| 106 | const handlers = [firstHandler, ...additionalHandlers]; |
| 107 | const interceptorList = handlers.map(handler => toInterceptor<CTX>(handler)); |
| 108 | return async (invocationCtx, next) => { |
| 109 | const middlewareChain = new GenericInterceptorChain( |
| 110 | invocationCtx, |
| 111 | interceptorList, |
| 112 | ); |
| 113 | return middlewareChain.invokeInterceptors(next); |
| 114 | }; |
| 115 | } |
| 116 | |
| 117 | function toInterceptorFromExpressMiddleware< |
| 118 | CTX extends Context = InvocationContext, |
no test coverage detected