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

Function schemasToResponse

packages/effect/src/unstable/httpapi/HttpApiClient.ts:729–744  ·  view source on GitHub ↗
(schemas: readonly [Schema.Constraint, ...Array<Schema.Constraint>])

Source from the content-addressed store, hash-verified

727}
728
729function schemasToResponse(schemas: readonly [Schema.Constraint, ...Array<Schema.Constraint>]) {
730 const hasWithHeaders = schemas.some((schema) =>
731 HttpApiSchema.isWithHeaders(schema) || HttpApiSchema.getWithHeadersAnnotation(schema.ast) !== undefined
732 )
733 const codec = hasWithHeaders
734 ? Schema.Union(schemas.map(toCodecArrayBufferWithHeaders))
735 : toCodecArrayBuffer(schemas)
736 const decode = Schema.decodeEffect(codec)
737 return (response: HttpClientResponse.HttpClientResponse) =>
738 Effect.flatMap(
739 response.arrayBuffer,
740 hasWithHeaders
741 ? (body) => decode({ body, headers: response.headers })
742 : decode
743 )
744}
745
746function toCodecArrayBufferWithHeaders(schema: Schema.Constraint): Schema.Top {
747 const isWithHeaders = HttpApiSchema.isWithHeaders(schema)

Callers 1

onEndpointFunction · 0.85

Calls 4

toCodecArrayBufferFunction · 0.85
someMethod · 0.80
decodeFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected