MCPcopy Create free account
hub / github.com/Effect-TS/effect / executeMiddleware

Function executeMiddleware

packages/effect/src/http-api/HttpApiClient.ts:441–475  ·  view source on GitHub ↗
(
      group: HttpApiGroup.Top,
      endpoint: HttpApiEndpoint.Top,
      request: HttpClientRequest.HttpClientRequest,
      clientPath: ClientPath,
      middlewareKeys: ReadonlyArray<string>,
      index: number
    )

Source from the content-addressed store, hash-verified

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,

Callers 2

nextFunction · 0.85
onEndpointFunction · 0.85

Calls 3

middlewareFunction · 0.70
getMethod · 0.65
executeMethod · 0.45

Tested by

no test coverage detected