( endpoint: HttpApiEndpoint.Top, options: SchemaAST.ParseOptions | undefined )
| 1218 | } |
| 1219 | |
| 1220 | function makeStreamEncoder( |
| 1221 | endpoint: HttpApiEndpoint.Top, |
| 1222 | options: SchemaAST.ParseOptions | undefined |
| 1223 | ): StreamEncoder | undefined { |
| 1224 | const successSchema = getStreamSuccessSchema(endpoint) |
| 1225 | if (successSchema === undefined) { |
| 1226 | return undefined |
| 1227 | } |
| 1228 | |
| 1229 | const streamSchema = successSchema.body |
| 1230 | const hasBuffered = hasBufferedSuccess(endpoint) |
| 1231 | const status = HttpApiSchema.getStatusSuccessSchema(successSchema.schema) |
| 1232 | const contentType = streamSchema.contentType |
| 1233 | |
| 1234 | const encodeBody = makeStreamBodyEncoder(streamSchema, options) |
| 1235 | |
| 1236 | return (response, context) => { |
| 1237 | if (!Stream.isStream(response)) { |
| 1238 | return hasBuffered ? undefined : new Schema.SchemaError( |
| 1239 | new SchemaIssue.InvalidValue({ message: "Expected a streaming response" }) |
| 1240 | ) |
| 1241 | } |
| 1242 | |
| 1243 | return Effect.succeed(Response.stream( |
| 1244 | Stream.provideContext( |
| 1245 | encodeBody(response), |
| 1246 | context as Context.Context<unknown> |
| 1247 | ), |
| 1248 | { status, contentType } |
| 1249 | )) |
| 1250 | } |
| 1251 | } |
| 1252 | |
| 1253 | function makeStreamBodyEncoder( |
| 1254 | streamSchema: HttpApiSchema.StreamSchema, |
no test coverage detected