(
group: HttpApiGroup.Top,
endpoint: HttpApiEndpoint.Top,
request: HttpClientRequest.HttpClientRequest,
clientPath: ClientPath,
middlewareKeys: ReadonlyArray<string>,
index: number
)
| 439 | ) |
| 440 | |
| 441 | function executeMiddleware( |
| 442 | group: HttpApiGroup.Top, |
| 443 | endpoint: HttpApiEndpoint.Top, |
| 444 | request: HttpClientRequest.HttpClientRequest, |
| 445 | clientPath: ClientPath, |
| 446 | middlewareKeys: ReadonlyArray<string>, |
| 447 | index: number |
| 448 | ): Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> { |
| 449 | if (index === -1) { |
| 450 | // Only the endpoint request gets the template, not requests sent by middleware. |
| 451 | // Without its own redaction, it keeps the redaction of an enclosing endpoint. |
| 452 | return Effect.updateService( |
| 453 | httpClient.execute(request), |
| 454 | CurrentClientPath, |
| 455 | (inherited) => clientPath.redacted === undefined ? { ...inherited, ...clientPath } : clientPath |
| 456 | ) as unknown as Effect.Effect< |
| 457 | HttpClientResponse.HttpClientResponse, |
| 458 | HttpClientError.HttpClientError |
| 459 | > |
| 460 | } |
| 461 | const middleware = services.mapUnsafe.get(middlewareKeys[index]) as |
| 462 | | HttpApiMiddleware.HttpApiMiddlewareClient<any, any, any> |
| 463 | | undefined |
| 464 | if (middleware === undefined) { |
| 465 | return executeMiddleware(group, endpoint, request, clientPath, middlewareKeys, index - 1) |
| 466 | } |
| 467 | return middleware({ |
| 468 | endpoint, |
| 469 | group, |
| 470 | request, |
| 471 | next(request) { |
| 472 | return executeMiddleware(group, endpoint, request, clientPath, middlewareKeys, index - 1) |
| 473 | } |
| 474 | }) as Effect.Effect<HttpClientResponse.HttpClientResponse, HttpClientError.HttpClientError> |
| 475 | } |
| 476 | |
| 477 | HttpApi.reflect(api, { |
| 478 | predicate: options?.predicate, |
no test coverage detected