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

Function jsonSchema

packages/effect/src/unstable/http/HttpBody.ts:320–330  ·  view source on GitHub ↗
(
  schema: S,
  options?: ParseOptions | undefined
)

Source from the content-addressed store, hash-verified

318 * @since 4.0.0
319 */
320export const jsonSchema = <S extends Schema.Constraint>(
321 schema: S,
322 options?: ParseOptions | undefined
323) => {
324 const encode = SchemaParser.encodeUnknownEffect(Schema.toCodecJson(schema))
325 return (body: S["Type"], contentType?: string): Effect.Effect<Uint8Array, HttpBodyError, S["EncodingServices"]> =>
326 encode(body, options).pipe(
327 Effect.mapError((issue) => new HttpBodyError({ reason: { _tag: "SchemaError", issue }, cause: issue })),
328 Effect.flatMap((body) => json(body, contentType))
329 )
330}
331
332/**
333 * Creates an `application/x-www-form-urlencoded` HTTP body from `UrlParams`.

Callers

nothing calls this directly

Calls 4

jsonFunction · 0.70
pipeMethod · 0.65
encodeFunction · 0.50
toCodecJsonMethod · 0.45

Tested by

no test coverage detected