MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeWithHeadersEncoder

Function makeWithHeadersEncoder

packages/effect/src/http-api/HttpApiBuilder.ts:1189–1218  ·  view source on GitHub ↗
(
  endpoint: HttpApiEndpoint.Top,
  options: SchemaAST.ParseOptions | undefined,
  headersOptions: SchemaAST.ParseOptions | undefined
)

Source from the content-addressed store, hash-verified

1187}
1188
1189function 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
1220function makeStreamEncoder(
1221 endpoint: HttpApiEndpoint.Top,

Callers 1

handlerToHttpEffectFunction · 0.85

Calls 2

setMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected