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

Function applyMiddleware

packages/platform/src/HttpApiBuilder.ts:719–740  ·  view source on GitHub ↗
(
  middleware: MiddlewareMap,
  handler: A
)

Source from the content-addressed store, hash-verified

717}
718
719const applyMiddleware = <A extends Effect.Effect<any, any, any>>(
720 middleware: MiddlewareMap,
721 handler: A
722) => {
723 for (const entry of middleware.values()) {
724 const effect = HttpApiMiddleware.SecurityTypeId in entry.tag ? makeSecurityMiddleware(entry as any) : entry.effect
725 if (entry.tag.optional) {
726 const previous = handler
727 handler = Effect.matchEffect(effect, {
728 onFailure: () => previous,
729 onSuccess: entry.tag.provides !== undefined
730 ? (value) => Effect.provideService(previous, entry.tag.provides as any, value)
731 : (_) => previous
732 }) as any
733 } else {
734 handler = entry.tag.provides !== undefined
735 ? Effect.provideServiceEffect(handler, entry.tag.provides as any, effect) as any
736 : Effect.zipRight(effect, handler) as any
737 }
738 }
739 return handler
740}
741
742const securityMiddlewareCache = globalValue<WeakMap<any, Effect.Effect<any, any, any>>>(
743 "securityMiddlewareCache",

Callers 2

HttpApiBuilder.tsFile · 0.70
handlerToRouteFunction · 0.70

Calls 2

makeSecurityMiddlewareFunction · 0.85
valuesMethod · 0.45

Tested by

no test coverage detected