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

Function makeSecurityMiddleware

packages/platform/src/HttpApiBuilder.ts:747–769  ·  view source on GitHub ↗
(
  entry: {
    readonly tag: HttpApiMiddleware.TagClassSecurityAny
    readonly effect: Record<string, (_: any) => Effect.Effect<any, any>>
  }
)

Source from the content-addressed store, hash-verified

745)
746
747const makeSecurityMiddleware = (
748 entry: {
749 readonly tag: HttpApiMiddleware.TagClassSecurityAny
750 readonly effect: Record<string, (_: any) => Effect.Effect<any, any>>
751 }
752): Effect.Effect<any, any, any> => {
753 if (securityMiddlewareCache.has(entry)) {
754 return securityMiddlewareCache.get(entry)!
755 }
756
757 let effect: Effect.Effect<any, any, any> | undefined
758 for (const [key, security] of Object.entries(entry.tag.security)) {
759 const decode = securityDecode(security)
760 const handler = entry.effect[key]
761 const middleware = Effect.flatMap(decode, handler)
762 effect = effect === undefined ? middleware : Effect.catchAll(effect, () => middleware)
763 }
764 if (effect === undefined) {
765 effect = Effect.void
766 }
767 securityMiddlewareCache.set(entry, effect)
768 return effect
769}
770
771const responseSchema = Schema.declare(HttpServerResponse.isServerResponse)
772

Callers 1

applyMiddlewareFunction · 0.85

Calls 4

securityDecodeFunction · 0.85
entriesMethod · 0.80
getMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected