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

Function schemaJson

packages/effect/src/http/HttpClientResponse.ts:161–184  ·  view source on GitHub ↗
(
  schema: Schema.ConstraintCodec<A, I, RD, unknown>,
  options?: (ParseOptions & HttpIncomingMessage.JsonOptions) | undefined
)

Source from the content-addressed store, hash-verified

159 * @since 4.0.0
160 */
161export const schemaJson = <
162 A,
163 I extends {
164 readonly status?: number | undefined
165 readonly headers?: Readonly<Record<string, string | undefined>> | undefined
166 readonly body?: unknown
167 },
168 RD
169>(
170 schema: Schema.ConstraintCodec<A, I, RD, unknown>,
171 options?: (ParseOptions & HttpIncomingMessage.JsonOptions) | undefined
172) => {
173 const decode = Schema.decodeEffect(Schema.toCodecJson(schema), options)
174 const decodeBody = HttpIncomingMessage.schemaBodyJson(Schema.Unknown, options)
175 return (
176 self: HttpClientResponse
177 ): Effect.Effect<A, Schema.SchemaError | Error.HttpClientError, RD> =>
178 Effect.flatMap(decodeBody(self), (body) =>
179 decode({
180 status: self.status,
181 headers: self.headers,
182 body: body as Schema.Json
183 }))
184}
185
186/**
187 * Creates a decoder for a response's status and headers without reading a response body.

Callers

nothing calls this directly

Calls 3

toCodecJsonMethod · 0.65
decodeFunction · 0.50
decodeEffectMethod · 0.45

Tested by

no test coverage detected