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

Function layerClient

packages/rpc/src/RpcMiddleware.ts:287–306  ·  view source on GitHub ↗
(
  tag: Context.Tag<Id, S>,
  service: RpcMiddlewareClient<R> | Effect.Effect<RpcMiddlewareClient<R>, EX, RX>
)

Source from the content-addressed store, hash-verified

285 * @category client
286 */
287export const layerClient = <Id, S, R, EX = never, RX = never>(
288 tag: Context.Tag<Id, S>,
289 service: RpcMiddlewareClient<R> | Effect.Effect<RpcMiddlewareClient<R>, EX, RX>
290): Layer.Layer<ForClient<Id>, EX, R | Exclude<RX, Scope>> =>
291 Layer.scopedContext(Effect.gen(function*() {
292 const context = (yield* Effect.context<R | Scope>()).pipe(
293 Context.omit(Scope)
294 ) as Context.Context<R>
295 const middleware = Effect.isEffect(service) ? yield* service : service
296 return Context.unsafeMake(
297 new Map([[
298 `${tag.key}/Client`,
299 (options: any) =>
300 Effect.mapInputContext(
301 middleware(options),
302 (requestContext) => Context.merge(context, requestContext)
303 )
304 ]])
305 )
306 }))

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected