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

Function layerHttpApi

packages/effect/src/unstable/cluster/EntityProxyServer.ts:35–87  ·  view source on GitHub ↗
(
  api: HttpApi.HttpApi<ApiId, Groups>,
  identifier: Identifier,
  entity: Entity.Entity<Type, Rpcs>
)

Source from the content-addressed store, hash-verified

33 * @since 4.0.0
34 */
35export const layerHttpApi = <
36 ApiId extends string,
37 Groups extends HttpApiGroup.Constraint,
38 Identifier extends HttpApiGroup.Identifier<Groups>,
39 Type extends string,
40 Rpcs extends Rpc.Any
41>(
42 api: HttpApi.HttpApi<ApiId, Groups>,
43 identifier: Identifier,
44 entity: Entity.Entity<Type, Rpcs>
45): Layer.Layer<HttpApiGroup.Service<ApiId, Identifier>, never, Sharding | Rpc.ServicesServer<Rpcs>> =>
46 HttpApiBuilder.group(
47 api,
48 identifier,
49 Effect.fnUntraced(function*(handlers: any) {
50 const client = yield* entity.client
51 for (const parentRpc of entity.protocol.requests.values()) {
52 handlers = handlers
53 .handle(
54 parentRpc._tag,
55 ({ params, payload }: { params: { entityId: string }; payload: any }) =>
56 (client(params.entityId) as any as Record<string, (p: any) => Effect.Effect<any>>)[parentRpc._tag](
57 payload
58 ).pipe(
59 Effect.tapDefect(Effect.logError),
60 Effect.annotateLogs({
61 module: "EntityProxyServer",
62 entity: entity.type,
63 entityId: params.entityId,
64 method: parentRpc._tag
65 })
66 )
67 )
68 .handle(
69 `${parentRpc._tag}Discard`,
70 ({ params, payload }: { params: { entityId: string }; payload: any }) =>
71 (client(params.entityId) as any as Record<string, (p: any, o: {}) => Effect.Effect<any>>)[parentRpc._tag](
72 payload,
73 { discard: true }
74 ).pipe(
75 Effect.tapDefect(Effect.logError),
76 Effect.annotateLogs({
77 module: "EntityProxyServer",
78 entity: entity.type,
79 entityId: params.entityId,
80 method: `${parentRpc._tag}Discard`
81 })
82 )
83 )
84 }
85 return handlers as HttpApiBuilder.Handlers<never>
86 })
87 )
88
89/**
90 * Creates RPC handlers for the group produced by `EntityProxy.toRpcGroup`.

Callers

nothing calls this directly

Calls 4

clientFunction · 0.85
groupMethod · 0.80
handleMethod · 0.65
pipeMethod · 0.65

Tested by

no test coverage detected