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

Function getPayload

packages/effect/src/unstable/httpapi/HttpApiEndpoint.ts:1111–1145  ·  view source on GitHub ↗
(
  payload: Schema.Constraint | ReadonlyArray<Schema.Constraint> | Schema.Struct.Fields | undefined,
  method: HttpMethod,
  disableCodecs: boolean
)

Source from the content-addressed store, hash-verified

1109}
1110
1111function getPayload(
1112 payload: Schema.Constraint | ReadonlyArray<Schema.Constraint> | Schema.Struct.Fields | undefined,
1113 method: HttpMethod,
1114 disableCodecs: boolean
1115): PayloadMap {
1116 const result: Map<
1117 string,
1118 { encoding: HttpApiSchema.PayloadEncoding; schemas: [Schema.Top, ...Array<Schema.Top>] }
1119 > = new Map()
1120 if (payload === undefined) return result
1121 const schemas: Array<Schema.Top> = Array.isArray(payload)
1122 ? payload
1123 : Schema.isSchema(payload)
1124 ? [payload]
1125 : [(Schema.Struct(payload as any)).pipe(HttpApiSchema.asFormUrlEncoded())]
1126 const transform = disableCodecs ? identity : transformPayload
1127
1128 for (const schema of schemas) {
1129 const encoding = HttpApiSchema.getPayloadEncoding(schema.ast, method)
1130 const contentType = MediaType.normalize(encoding.contentType)
1131 const existing = result.get(contentType)
1132 if (existing) {
1133 if (existing.encoding._tag !== encoding._tag) {
1134 throw new Error(`Multiple payload encodings for content-type: ${encoding.contentType}`)
1135 }
1136 if (existing.encoding._tag === "Multipart") {
1137 throw new Error(`Multiple multipart payloads for content-type: ${encoding.contentType}`)
1138 }
1139 existing.schemas.push(transform(schema, method))
1140 } else {
1141 result.set(contentType, { encoding, schemas: [transform(schema, method)] })
1142 }
1143 }
1144 return result
1145}
1146
1147const reservedStreamFailureEvent = "effect/httpapi/stream/failure"
1148

Callers 1

makeFunction · 0.85

Calls 5

pushMethod · 0.80
pipeMethod · 0.65
getMethod · 0.65
setMethod · 0.65
transformFunction · 0.50

Tested by

no test coverage detected