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

Function layerHttpApi

packages/cluster/src/EntityProxyServer.ts:18–74  ·  view source on GitHub ↗
(
  api: HttpApi.HttpApi<ApiId, Groups, ApiE, ApiR>,
  name: Name,
  entity: Entity.Entity<Type, Rpcs>
)

Source from the content-addressed store, hash-verified

16 * @category Layers
17 */
18export const layerHttpApi = <
19 ApiId extends string,
20 Groups extends HttpApiGroup.Any,
21 ApiE,
22 ApiR,
23 Name extends HttpApiGroup.Name<Groups>,
24 Type extends string,
25 Rpcs extends Rpc.Any
26>(
27 api: HttpApi.HttpApi<ApiId, Groups, ApiE, ApiR>,
28 name: Name,
29 entity: Entity.Entity<Type, Rpcs>
30): Layer.Layer<ApiGroup<ApiId, Name>, never, Sharding | Rpc.Context<Rpcs>> =>
31 HttpApiBuilder.group(
32 api,
33 name,
34 Effect.fnUntraced(function*(handlers_) {
35 const client = yield* entity.client
36 let handlers = handlers_
37 for (const parentRpc_ of entity.protocol.requests.values()) {
38 const parentRpc = parentRpc_ as any as Rpc.AnyWithProps
39 handlers = handlers
40 .handle(
41 parentRpc._tag as any,
42 (({ path, payload }: { path: { entityId: string }; payload: any }) =>
43 (client(path.entityId) as any as Record<string, (p: any) => Effect.Effect<any>>)[parentRpc._tag](
44 payload
45 ).pipe(
46 Effect.tapDefect(Effect.logError),
47 Effect.annotateLogs({
48 module: "EntityProxyServer",
49 entity: entity.type,
50 entityId: path.entityId,
51 method: parentRpc._tag
52 })
53 )) as any
54 )
55 .handle(
56 `${parentRpc._tag}Discard` as any,
57 (({ path, payload }: { path: { entityId: string }; payload: any }) =>
58 (client(path.entityId) as any as Record<string, (p: any, o: {}) => Effect.Effect<any>>)[parentRpc._tag](
59 payload,
60 { discard: true }
61 ).pipe(
62 Effect.tapDefect(Effect.logError),
63 Effect.annotateLogs({
64 module: "EntityProxyServer",
65 entity: entity.type,
66 entityId: path.entityId,
67 method: `${parentRpc._tag}Discard`
68 })
69 )) as any
70 ) as any
71 }
72 return handlers as HttpApiBuilder.Handlers<never, never, never>
73 })
74 )
75

Callers

nothing calls this directly

Calls 5

clientFunction · 0.85
groupMethod · 0.65
handleMethod · 0.65
pipeMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…