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

Function toHttpApiGroup

packages/effect/src/unstable/cluster/EntityProxy.ts:191–217  ·  view source on GitHub ↗
(
  name: Name,
  entity: Entity.Entity<Type, Rpcs>
)

Source from the content-addressed store, hash-verified

189 * @since 4.0.0
190 */
191export const toHttpApiGroup = <const Name extends string, Type extends string, Rpcs extends Rpc.Any>(
192 name: Name,
193 entity: Entity.Entity<Type, Rpcs>
194): HttpApiGroup.HttpApiGroup<Name, ConvertHttpApi<Rpcs>> => {
195 let group = HttpApiGroup.make(name)
196 for (const parentRpc_ of entity.protocol.requests.values()) {
197 const parentRpc = parentRpc_ as any as Rpc.AnyWithProps
198 const endpoint = HttpApiEndpoint.post(parentRpc._tag, `/${tagToPath(parentRpc._tag)}/:entityId`, {
199 params: entityIdPath,
200 payload: parentRpc.payloadSchema,
201 success: parentRpc.successSchema,
202 error: [parentRpc.errorSchema, ...requestErrors]
203 }).annotateMerge(parentRpc.annotations)
204 const endpointDiscard = HttpApiEndpoint.post(
205 `${parentRpc._tag}Discard`,
206 `/${tagToPath(parentRpc._tag)}/:entityId/discard`,
207 {
208 params: entityIdPath,
209 payload: parentRpc.payloadSchema,
210 error: clientErrors
211 }
212 ).annotateMerge(parentRpc.annotations)
213
214 group = group.add(endpoint).add(endpointDiscard) as any
215 }
216 return group as any as HttpApiGroup.HttpApiGroup<Name, ConvertHttpApi<Rpcs>>
217}
218
219// TODO: type level equivalent
220const tagToPath = (tag: string): string =>

Callers

nothing calls this directly

Calls 4

tagToPathFunction · 0.70
makeMethod · 0.65
annotateMergeMethod · 0.65
addMethod · 0.65

Tested by

no test coverage detected