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

Function toResponseSchema

packages/effect/src/unstable/httpapi/HttpApiBuilder.ts:1132–1149  ·  view source on GitHub ↗
(getStatus: (schema: Schema.Constraint) => number)

Source from the content-addressed store, hash-verified

1130}
1131
1132function toResponseSchema(getStatus: (schema: Schema.Constraint) => number) {
1133 // WithHeaders wrappers share a single declaration AST, so they are cached by instance
1134 const cache = new WeakMap<object, Schema.Top>()
1135
1136 return (schema: Schema.Constraint): Schema.ConstraintEncoder<HttpServerResponse, unknown> => {
1137 const key = HttpApiSchema.isWithHeaders(schema) ? schema : schema.ast
1138 const cached = cache.get(key)
1139 if (cached !== undefined) {
1140 return cached as any
1141 }
1142 const bodySchema = HttpApiSchema.isWithHeaders(schema) ? schema.schema : schema
1143 const responseSchema = $HttpServerResponse.pipe(
1144 Schema.decodeTo(bodySchema, getResponseTransformation(getStatus, schema))
1145 )
1146 cache.set(key, responseSchema)
1147 return responseSchema
1148 }
1149}
1150
1151function getResponseTransformation(
1152 getStatus: (schema: Schema.Constraint) => number,

Callers 1

HttpApiBuilder.tsFile · 0.85

Calls 4

getMethod · 0.65
pipeMethod · 0.65
setMethod · 0.65

Tested by

no test coverage detected