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

Function schemaJson

packages/platform/src/internal/httpRouter.ts:47–82  ·  view source on GitHub ↗
(
  schema: Schema.Schema<A, I, R>,
  options?: ParseOptions | undefined
)

Source from the content-addressed store, hash-verified

45
46/** @internal */
47export const schemaJson = <
48 R,
49 I extends Partial<{
50 readonly method: Method.HttpMethod
51 readonly url: string
52 readonly cookies: Readonly<Record<string, string | undefined>>
53 readonly headers: Readonly<Record<string, string | undefined>>
54 readonly pathParams: Readonly<Record<string, string | undefined>>
55 readonly searchParams: Readonly<Record<string, string | ReadonlyArray<string> | undefined>>
56 readonly body: any
57 }>,
58 A
59>(
60 schema: Schema.Schema<A, I, R>,
61 options?: ParseOptions | undefined
62) => {
63 const parse = Schema.decodeUnknown(schema, options)
64 return Effect.flatMap(
65 Effect.context<ServerRequest.HttpServerRequest | ServerRequest.ParsedSearchParams | Router.RouteContext>(),
66 (context) => {
67 const request = Context.get(context, ServerRequest.HttpServerRequest)
68 const searchParams = Context.get(context, ServerRequest.ParsedSearchParams)
69 const routeContext = Context.get(context, RouteContext)
70 return Effect.flatMap(request.json, (body) =>
71 parse({
72 method: request.method,
73 url: request.url,
74 headers: request.headers,
75 cookies: request.cookies,
76 pathParams: routeContext.params,
77 searchParams,
78 body
79 }))
80 }
81 )
82}
83
84/** @internal */
85export const schemaNoBody = <

Callers

nothing calls this directly

Calls 3

parseFunction · 0.70
contextMethod · 0.65
getMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…