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