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

Function schemaBodyFormJson

packages/effect/src/http/HttpServerRequest.ts:396–429  ·  view source on GitHub ↗
(
  schema: Schema.ConstraintDecoder<A, RD>,
  options?: (ParseOptions & HttpIncomingMessage.JsonOptions) | undefined
)

Source from the content-addressed store, hash-verified

394 * @since 4.0.0
395 */
396export const schemaBodyFormJson = <A, RD>(
397 schema: Schema.ConstraintDecoder<A, RD>,
398 options?: (ParseOptions & HttpIncomingMessage.JsonOptions) | undefined
399) => {
400 const parseMultipart = Multipart.schemaJson(schema, options)
401 return (field: string) => {
402 const parseUrlParams = Schema.JsonFromUrlParamsField(field, options).pipe(
403 Schema.decodeTo(schema),
404 Schema.decodeEffect
405 )
406 return Effect.flatMap(
407 HttpServerRequest,
408 (request): Effect.Effect<
409 A,
410 Schema.SchemaError | HttpServerError,
411 RD | FileSystem.FileSystem | Path.Path | Scope.Scope | HttpServerRequest
412 > => {
413 if (isMultipart(request)) {
414 return Effect.flatMap(
415 Effect.mapError(request.multipart, (cause) =>
416 new HttpServerError({
417 reason: new RequestParseError({
418 request,
419 cause
420 })
421 })),
422 parseMultipart(field)
423 )
424 }
425 return Effect.flatMap(request.urlParamsBody, (_) => parseUrlParams(_, options))
426 }
427 )
428 }
429}
430
431/**
432 * Creates an `HttpServerRequest` view of an `HttpClientRequest`.

Callers

nothing calls this directly

Calls 2

isMultipartFunction · 0.85
pipeMethod · 0.65

Tested by

no test coverage detected