(endpoint: Endpoint)
| 267 | } |
| 268 | |
| 269 | function assertPromiseEndpoint(endpoint: Endpoint) { |
| 270 | const name = `${endpoint.group}.${endpoint.endpoint.name}` |
| 271 | const payload = endpoint.payloads[0] |
| 272 | const payloadEncoding = payload === undefined ? undefined : resolveHttpApiEncoding(payload.ast) |
| 273 | if ( |
| 274 | payload !== undefined && |
| 275 | (payloadEncoding?._tag ?? (HttpMethod.hasBody(endpoint.endpoint.method) ? "Json" : "FormUrlEncoded")) !== "Json" |
| 276 | ) { |
| 277 | throw new GenerationError({ reason: `Unsupported Promise payload encoding: ${name}` }) |
| 278 | } |
| 279 | const success = endpoint.successes[0] |
| 280 | if (isStreamSchema(success)) { |
| 281 | if ( |
| 282 | success._tag !== "StreamSse" || |
| 283 | success.sseMode !== "data" || |
| 284 | !SchemaAST.isNever(Schema.toType(success.error).ast) |
| 285 | ) { |
| 286 | throw new GenerationError({ reason: `Unsupported Promise stream: ${name}` }) |
| 287 | } |
| 288 | } else if ( |
| 289 | !HttpApiSchema.isNoContent(success.ast) && |
| 290 | (resolveHttpApiEncoding(success.ast)?._tag ?? "Json") !== "Json" |
| 291 | ) { |
| 292 | throw new GenerationError({ reason: `Unsupported Promise success encoding: ${name}` }) |
| 293 | } |
| 294 | for (const error of endpoint.errors) { |
| 295 | if (declaredErrorFields(error.schema) === undefined) { |
| 296 | throw new GenerationError({ reason: `Promise error must have a literal discriminator: ${name}` }) |
| 297 | } |
| 298 | if ((resolveHttpApiEncoding(error.schema.ast)?._tag ?? "Json") !== "Json") { |
| 299 | throw new GenerationError({ reason: `Unsupported Promise error encoding: ${name}` }) |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | function operations(groups: ReadonlyArray<Group>) { |
| 305 | return groups.flatMap((group) => group.endpoints.map((endpoint) => endpoint.operation)) |
no test coverage detected