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

Function layerRpcHandlers

packages/cluster/src/EntityProxyServer.ts:80–105  ·  view source on GitHub ↗
(entity: Entity.Entity<Type, Rpcs>)

Source from the content-addressed store, hash-verified

78 * @category Layers
79 */
80export const layerRpcHandlers = <
81 const Type extends string,
82 Rpcs extends Rpc.Any
83>(entity: Entity.Entity<Type, Rpcs>): Layer.Layer<RpcHandlers<Rpcs, Type>, never, Sharding | Rpc.Context<Rpcs>> =>
84 Layer.effectContext(Effect.gen(function*() {
85 const context = yield* Effect.context<never>()
86 const client = yield* entity.client
87 const handlers = new Map<string, Rpc.Handler<string>>()
88 for (const parentRpc_ of entity.protocol.requests.values()) {
89 const parentRpc = parentRpc_ as any as Rpc.AnyWithProps
90 const tag = `${entity.type}.${parentRpc._tag}` as const
91 const key = `@effect/rpc/Rpc/${tag}`
92 handlers.set(key, {
93 context,
94 tag,
95 handler: ({ entityId, payload }: any) => (client(entityId) as any)[parentRpc._tag](payload) as any
96 } as any)
97 handlers.set(`${key}Discard`, {
98 context,
99 tag,
100 handler: ({ entityId, payload }: any) =>
101 (client(entityId) as any)[parentRpc._tag](payload, { discard: true }) as any
102 } as any)
103 }
104 return Context.unsafeMake(handlers)
105 }))
106
107/**
108 * @since 1.0.0

Callers

nothing calls this directly

Calls 4

clientFunction · 0.85
contextMethod · 0.65
setMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…