MCPcopy
hub / github.com/Effect-TS/effect / applyMiddleware

Function applyMiddleware

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

Source from the content-addressed store, hash-verified

706}
707
708const applyMiddleware = <A extends Effect.Effect<any, any, any>>(
709 middleware: MiddlewareMap,
710 handler: A
711) => {
712 for (const entry of middleware.values()) {
713 const effect = HttpApiMiddleware.SecurityTypeId in entry.tag ? makeSecurityMiddleware(entry as any) : entry.effect
714 if (entry.tag.optional) {
715 const previous = handler
716 handler = Effect.matchEffect(effect, {
717 onFailure: () => previous,
718 onSuccess: entry.tag.provides !== undefined
719 ? (value) => Effect.provideService(previous, entry.tag.provides as any, value)
720 : (_) => previous
721 }) as any
722 } else {
723 handler = entry.tag.provides !== undefined
724 ? Effect.provideServiceEffect(handler, entry.tag.provides as any, effect) as any
725 : Effect.zipRight(effect, handler) as any
726 }
727 }
728 return handler
729}
730
731const securityMiddlewareCache = globalValue<WeakMap<any, Effect.Effect<any, any, any>>>(
732 "securityMiddlewareCache",

Callers 2

HttpApiBuilder.tsFile · 0.70
handlerToRouteFunction · 0.70

Calls 2

makeSecurityMiddlewareFunction · 0.85
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…