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

Function layerClient

packages/effect/src/unstable/httpapi/HttpApiMiddleware.ts:504–529  ·  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

502 * @since 4.0.0
503 */
504export const layerClient = <Id extends AnyId, S, R, EX = never, RX = never>(
505 tag: Context.Key<Id, S>,
506 service:
507 | HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R>
508 | Effect.Effect<
509 HttpApiMiddlewareClient<Error<Id>, Id[typeof TypeId]["clientError"], R>,
510 EX,
511 RX
512 >
513): Layer.Layer<ForClient<Id>, EX, R | Exclude<RX, Scope>> =>
514 Layer.effectContext(Effect.gen(function*() {
515 const services = (yield* Effect.context<R | Scope>()).pipe(
516 Context.omit(Scope)
517 ) as Context.Context<R>
518 const middleware = Effect.isEffect(service) ? yield* service : service
519 return Context.makeUnsafe(
520 new Map([[
521 `${tag.key}/Client`,
522 (options: any) =>
523 Effect.updateContext(
524 middleware(options),
525 (requestContext) => Context.merge(services, requestContext)
526 )
527 ]])
528 )
529 }))

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected