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

Function schemaJson

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

Source from the content-addressed store, hash-verified

315 * @since 4.0.0
316 */
317export const schemaJson = <A, RE>(
318 schema: Schema.ConstraintCodec<A, unknown, unknown, RE>,
319 options?: ParseOptions | undefined
320) => {
321 const encode = Body.jsonSchema(schema, options)
322 return (
323 body: A,
324 options?: Options.WithContentType | undefined
325 ): Effect.Effect<HttpServerResponse, Body.HttpBodyError, RE> => {
326 const headers = options?.headers ? Headers.fromInput(options.headers) : Headers.empty
327 return Effect.map(encode(body, getContentType(options, headers)), (body) =>
328 makeResponse({
329 status: options?.status ?? 200,
330 statusText: options?.statusText,
331 headers,
332 cookies: options?.cookies,
333 body
334 }))
335 }
336}
337
338/**
339 * 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