( name: Name, entity: Entity.Entity<Type, Rpcs> )
| 189 | * @since 4.0.0 |
| 190 | */ |
| 191 | export 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 |
| 220 | const tagToPath = (tag: string): string => |
nothing calls this directly
no test coverage detected