| /** | |
| * Serves the proxy APIs generated from clustered entities. | |
| * | |
| * Proxy handlers read the target `entityId`, call the entity client, and | |
| * forward the payload to the matching entity RPC method. This module provides | |
| * handlers for HTTP API groups created by `EntityProxy.toHttpApiGroup` and RPC | |
| * handler services for RPC groups created by `EntityProxy.toRpcGroup`. Both | |
| * normal requests and discard requests are forwarded to the underlying entity | |
| * client. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| import * as Context from "../../Context.js"; | |
| import * as Effect from "../../Effect.js"; | |
| import * as Layer from "../../Layer.js"; | |
| import * as HttpApiBuilder from "../httpapi/HttpApiBuilder.js"; | |
| /** | |
| * Creates HTTP API handlers for an entity proxy group. | |
| * | |
| * **Details** | |
| * | |
| * Each generated endpoint reads the `entityId` path parameter and forwards the | |
| * request payload to the corresponding entity client method, including discard | |
| * endpoints. | |
| * | |
| * @category layers | |
| * @since 4.0.0 | |
| */ | |
| export const layerHttpApi = (api, name, entity) => HttpApiBuilder.group(api, name, Effect.fnUntraced(function* (handlers_) { | |
| const client = yield* entity.client; | |
| let handlers = handlers_; | |
| for (const parentRpc_ of entity.protocol.requests.values()) { | |
| const parentRpc = parentRpc_; | |
| handlers = handlers.handle(parentRpc._tag, ({ | |
| params, | |
| payload | |
| }) => client(params.entityId)[parentRpc._tag](payload).pipe(Effect.tapDefect(Effect.logError), Effect.annotateLogs({ | |
| module: "EntityProxyServer", | |
| entity: entity.type, | |
| entityId: params.entityId, | |
| method: parentRpc._tag | |
| }))).handle(`${parentRpc._tag}Discard`, ({ | |
| params, | |
| payload | |
| }) => client(params.entityId)[parentRpc._tag](payload, { | |
| discard: true | |
| }).pipe(Effect.tapDefect(Effect.logError), Effect.annotateLogs({ | |
| module: "EntityProxyServer", | |
| entity: entity.type, | |
| entityId: params.entityId, | |
| method: `${parentRpc._tag}Discard` | |
| }))); | |
| } | |
| return handlers; | |
| })); | |
| /** | |
| * Creates RPC handlers for the group produced by `EntityProxy.toRpcGroup`. | |
| * | |
| * **Details** | |
| * | |
| * The handlers forward each prefixed proxy RPC to the target entity client using | |
| * the `entityId` embedded in the proxy payload. | |
| * | |
| * @category layers | |
| * @since 4.0.0 | |
| */ | |
| export const layerRpcHandlers = entity => Layer.effectContext(Effect.gen(function* () { | |
| const context = yield* Effect.context(); | |
| const client = yield* entity.client; | |
| const handlers = new Map(); | |
| for (const parentRpc_ of entity.protocol.requests.values()) { | |
| const parentRpc = parentRpc_; | |
| const tag = `${entity.type}.${parentRpc._tag}`; | |
| const key = `effect/rpc/Rpc/${tag}`; | |
| handlers.set(key, { | |
| context, | |
| tag, | |
| handler: ({ | |
| entityId, | |
| payload | |
| }) => client(entityId)[parentRpc._tag](payload) | |
| }); | |
| handlers.set(`${key}Discard`, { | |
| context, | |
| tag, | |
| handler: ({ | |
| entityId, | |
| payload | |
| }) => client(entityId)[parentRpc._tag](payload, { | |
| discard: true | |
| }) | |
| }); | |
| } | |
| return Context.makeUnsafe(handlers); | |
| })); | |
| //# sourceMappingURL=EntityProxyServer.js.map |
Xet Storage Details
- Size:
- 3.13 kB
- Xet hash:
- 3102ddc191c2e8fc57151b32ef97a0dd34dbb224c9bf4a01fdebd7f7792c6e4e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.