MCPcopy
hub / github.com/Effect-TS/effect / toHttpApiGroup

Function toHttpApiGroup

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

Source from the content-addressed store, hash-verified

160 * @category Constructors
161 */
162export const toHttpApiGroup = <const Name extends string, Type extends string, Rpcs extends Rpc.Any>(
163 name: Name,
164 entity: Entity.Entity<Type, Rpcs>
165): HttpApiGroup.HttpApiGroup<Name, ConvertHttpApi<Rpcs>> => {
166 let group = HttpApiGroup.make(name)
167 for (const parentRpc_ of entity.protocol.requests.values()) {
168 const parentRpc = parentRpc_ as any as Rpc.AnyWithProps
169 const endpoint = HttpApiEndpoint.post(parentRpc._tag, `/${tagToPath(parentRpc._tag)}/:entityId`)
170 .setPath(entityIdPath)
171 .setPayload(parentRpc.payloadSchema)
172 .addSuccess(parentRpc.successSchema)
173 .addError(Schema.Union(parentRpc.errorSchema, ...clientErrors))
174 .annotateContext(parentRpc.annotations)
175 const endpointDiscard = HttpApiEndpoint.post(
176 `${parentRpc._tag}Discard`,
177 `/${tagToPath(parentRpc._tag)}/:entityId/discard`
178 )
179 .setPath(entityIdPath)
180 .setPayload(parentRpc.payloadSchema)
181 .addError(Schema.Union(...clientErrors))
182 .annotateContext(parentRpc.annotations)
183
184 group = group.add(endpoint).add(endpointDiscard) as any
185 }
186 return group as any as HttpApiGroup.HttpApiGroup<Name, ConvertHttpApi<Rpcs>>
187}
188
189const tagToPath = (tag: string): string =>
190 tag

Callers

nothing calls this directly

Calls 9

addSuccessMethod · 0.80
setPathMethod · 0.80
tagToPathFunction · 0.70
makeMethod · 0.65
annotateContextMethod · 0.65
addErrorMethod · 0.65
setPayloadMethod · 0.65
addMethod · 0.65
valuesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…