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

Function schemaBodyForm

packages/effect/src/unstable/http/HttpServerRequest.ts:268–287  ·  view source on GitHub ↗
(
  schema: Schema.ConstraintCodec<A, I, RD, unknown>,
  options?: ParseOptions | undefined
)

Source from the content-addressed store, hash-verified

266 * @since 4.0.0
267 */
268export const schemaBodyForm = <A, I extends Partial<Multipart.Persisted>, RD>(
269 schema: Schema.ConstraintCodec<A, I, RD, unknown>,
270 options?: ParseOptions | undefined
271) => {
272 const parseMultipart = Multipart.schemaPersisted(schema)
273 const parseUrlParams = HttpIncomingMessage.schemaBodyUrlParams(
274 schema as Schema.ConstraintCodec<A, any, RD, unknown>,
275 options
276 )
277 return Effect.flatMap(HttpServerRequest, (request): Effect.Effect<
278 A,
279 Multipart.MultipartError | Schema.SchemaError | HttpServerError,
280 RD | HttpServerRequest | Scope.Scope | FileSystem.FileSystem | Path.Path
281 > => {
282 if (isMultipart(request)) {
283 return Effect.flatMap(request.multipart, (_) => parseMultipart(_, options))
284 }
285 return parseUrlParams(request)
286 })
287}
288
289/**
290 * Reads the current request body as URL-encoded parameters and decodes them with

Callers

nothing calls this directly

Calls 1

isMultipartFunction · 0.85

Tested by

no test coverage detected