( endpoint: HttpApiEndpoint.Top, options: SchemaAST.ParseOptions | undefined, headersOptions: SchemaAST.ParseOptions | undefined )
| 1187 | } |
| 1188 | |
| 1189 | function makeWithHeadersEncoder( |
| 1190 | endpoint: HttpApiEndpoint.Top, |
| 1191 | options: SchemaAST.ParseOptions | undefined, |
| 1192 | headersOptions: SchemaAST.ParseOptions | undefined |
| 1193 | ): WithHeadersEncoders | undefined { |
| 1194 | const encodeHeaders = new Map<number, WithHeadersEncoder>() |
| 1195 | const bodySchemas: Array<Schema.ConstraintEncoder<HttpServerResponse, unknown>> = [] |
| 1196 | for (const schema of endpoint.success) { |
| 1197 | if (!HttpApiSchema.isWithHeaders(schema)) continue |
| 1198 | encodeHeaders.set( |
| 1199 | HttpApiSchema.getStatusSuccessSchema(schema), |
| 1200 | Schema.encodeUnknownEffect(schema.headers, headersOptions) |
| 1201 | ) |
| 1202 | if (!HttpApiSchema.isStreamSchema(schema.schema)) { |
| 1203 | bodySchemas.push(toResponseSuccessSchema(schema, headersOptions)) |
| 1204 | } |
| 1205 | } |
| 1206 | if (encodeHeaders.size === 0) return undefined |
| 1207 | // Branded response bodies encode against the header-carrying members only, so |
| 1208 | // the encoded status always has a matching header schema. |
| 1209 | const bodySchema: Schema.ConstraintEncoder<HttpServerResponse, unknown> = bodySchemas.length === 0 |
| 1210 | ? Schema.Never |
| 1211 | : bodySchemas.length === 1 |
| 1212 | ? bodySchemas[0] |
| 1213 | : Schema.Union(bodySchemas) |
| 1214 | return { |
| 1215 | encodeBody: Schema.encodeUnknownEffect(bodySchema, options), |
| 1216 | encodeHeaders |
| 1217 | } |
| 1218 | } |
| 1219 | |
| 1220 | function makeStreamEncoder( |
| 1221 | endpoint: HttpApiEndpoint.Top, |
no test coverage detected