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

Function schemaJson

packages/effect/src/http/HttpServerResponse.ts:338–357  ·  view source on GitHub ↗
(
  schema: Schema.ConstraintCodec<A, unknown, unknown, RE>,
  options?: ParseOptions | undefined
)

Source from the content-addressed store, hash-verified

336 * @since 4.0.0
337 */
338export const schemaJson = <A, RE>(
339 schema: Schema.ConstraintCodec<A, unknown, unknown, RE>,
340 options?: ParseOptions | undefined
341) => {
342 const encode = Body.jsonSchema(schema, options)
343 return (
344 body: A,
345 options?: Options.WithContentType | undefined
346 ): Effect.Effect<HttpServerResponse, Body.HttpBodyError, RE> => {
347 const headers = options?.headers ? Headers.fromInput(options.headers) : Headers.empty
348 return Effect.map(encode(body, getContentType(options, headers)), (body) =>
349 makeResponse({
350 status: options?.status ?? 200,
351 statusText: options?.statusText,
352 headers,
353 cookies: options?.cookies,
354 body
355 }))
356 }
357}
358
359/**
360 * Creates a JSON HTTP response synchronously.

Callers

nothing calls this directly

Calls 4

getContentTypeFunction · 0.85
makeResponseFunction · 0.70
encodeFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected