MCPcopy Index your code
hub / github.com/Effect-TS/effect / layerClient

Function layerClient

packages/rpc/src/RpcMiddleware.ts:286–305  ·  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

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

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