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

Function schemaJson

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

Source from the content-addressed store, hash-verified

87 * @since 4.0.0
88 */
89export const schemaJson = <
90 A,
91 I extends {
92 readonly status?: number | undefined
93 readonly headers?: Readonly<Record<string, string | undefined>> | undefined
94 readonly body?: unknown
95 },
96 RD
97>(
98 schema: Schema.ConstraintCodec<A, I, RD, unknown>,
99 options?: ParseOptions | undefined
100) => {
101 const decode = Schema.decodeEffect(Schema.toCodecJson(schema).annotate({ options }))
102 return (
103 self: HttpClientResponse
104 ): Effect.Effect<A, Schema.SchemaError | Error.HttpClientError, RD> =>
105 Effect.flatMap(self.json, (body) =>
106 decode({
107 status: self.status,
108 headers: self.headers,
109 body
110 }))
111}
112
113/**
114 * Creates a decoder for a response's status and headers without reading a response body.

Callers

nothing calls this directly

Calls 3

annotateMethod · 0.65
decodeFunction · 0.50
toCodecJsonMethod · 0.45

Tested by

no test coverage detected