( streamSchema: HttpApiSchema.StreamSchema, options: SchemaAST.ParseOptions | undefined )
| 1430 | } |
| 1431 | |
| 1432 | function makeStreamBodyDecoder( |
| 1433 | streamSchema: HttpApiSchema.StreamSchema, |
| 1434 | options: SchemaAST.ParseOptions | undefined |
| 1435 | ): ( |
| 1436 | response: HttpClientResponse.HttpClientResponse, |
| 1437 | sseOptions: Sse.DecodeOptions | undefined |
| 1438 | ) => Stream.Stream<unknown, unknown, unknown> { |
| 1439 | if (HttpApiSchema.isStreamUint8Array(streamSchema)) { |
| 1440 | return (response) => response.stream |
| 1441 | } |
| 1442 | if (HttpApiSchema.isStreamNdjson(streamSchema)) { |
| 1443 | const decodeElement = Schema.decodeUnknownEffect(Schema.toCodecJson(streamSchema.schema), options) |
| 1444 | const maxElementBytes = ByteSize.toNumberUnsafe(streamSchema.maxElementBytes) |
| 1445 | return (response) => |
| 1446 | response.stream.pipe( |
| 1447 | Stream.pipeThroughChannel(Ndjson.decode({ ignoreEmptyLines: true, maxLineBytes: maxElementBytes })), |
| 1448 | Stream.mapError((error) => { |
| 1449 | if (!Ndjson.isNdjsonError(error)) return error |
| 1450 | if (error.reason !== "LineTooLarge") return ndjsonSchemaError(error) |
| 1451 | return new HttpClientError.HttpClientError({ |
| 1452 | reason: new HttpClientError.DecodeError({ |
| 1453 | request: response.request, |
| 1454 | response, |
| 1455 | description: `NDJSON line exceeds maxElementBytes of ${maxElementBytes} bytes` |
| 1456 | }) |
| 1457 | }) |
| 1458 | }), |
| 1459 | Stream.mapEffect((json) => decodeElement(json)) |
| 1460 | ) |
| 1461 | } |
| 1462 | const decoder = makeSseDecoder(streamSchema, options) |
| 1463 | return (response, sseOptions) => decodeSseStream(response.stream, streamSchema, decoder(sseOptions)) |
| 1464 | } |
| 1465 | |
| 1466 | // `JSON.stringify` found no JSON representation for an encoded element |
| 1467 | const isNdjsonPackError = (error: unknown): error is Ndjson.NdjsonError => |
no test coverage detected