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

Function layerClient

packages/effect/src/http-api/HttpApiMiddleware.ts:623–648  ·  view source on GitHub ↗
(
  tag: Context.Key<Id, S>,
  service:
    | HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R>
    | Effect.Effect<
      HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R>,
      EX,
      RX
    >
)

Source from the content-addressed store, hash-verified

621 * @since 4.0.0
622 */
623export const layerClient = <Id extends AnyId, S, R, EX = never, RX = never>(
624 tag: Context.Key<Id, S>,
625 service:
626 | HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R>
627 | Effect.Effect<
628 HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R>,
629 EX,
630 RX
631 >
632): Layer.Layer<ForClient<Id>, EX, R | Exclude<RX, Scope>> =>
633 Layer.effectContext(Effect.gen(function*() {
634 const services = (yield* Effect.context<R | Scope>()).pipe(
635 Context.omit(Scope)
636 ) as Context.Context<R>
637 const middleware = Effect.isEffect(service) ? yield* service : service
638 return Context.makeUnsafe(
639 new Map([[
640 `${tag.key}/Client`,
641 (options: any) =>
642 Effect.updateContext(
643 middleware(options),
644 (requestContext) => Context.merge(services, requestContext)
645 )
646 ]])
647 )
648 }))
649
650/**
651 * Creates a client middleware layer that runs a credential effect for each request

Callers 1

layerClientSecurityFunction · 0.70

Calls 5

contextMethod · 0.80
middlewareFunction · 0.70
pipeMethod · 0.65
omitMethod · 0.65
mergeMethod · 0.65

Tested by

no test coverage detected