| 1109 | } |
| 1110 | |
| 1111 | function 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 | |
| 1147 | const reservedStreamFailureEvent = "effect/httpapi/stream/failure" |
| 1148 | |