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

Function streamToResponse

packages/effect/src/http-api/HttpApiClient.ts:1408–1430  ·  view source on GitHub ↗
(
  successSchema: StreamSuccessSchema,
  options: SchemaAST.ParseOptions | undefined,
  headersOptions: SchemaAST.ParseOptions | undefined
)

Source from the content-addressed store, hash-verified

1406}
1407
1408function streamToResponse(
1409 successSchema: StreamSuccessSchema,
1410 options: SchemaAST.ParseOptions | undefined,
1411 headersOptions: SchemaAST.ParseOptions | undefined
1412) {
1413 const isWithHeaders = isWithHeadersStreamSuccess(successSchema)
1414 const streamSchema = isWithHeaders ? successSchema.schema : successSchema
1415 const decodeBody = makeStreamBodyDecoder(streamSchema, options)
1416 const toStream: ResponseDecoder = (response, sseOptions) =>
1417 Effect.map(Effect.context<never>(), (context) =>
1418 Stream.provideContext(
1419 decodeBody(response, sseOptions),
1420 context as Context.Context<unknown>
1421 ))
1422 if (!isWithHeaders) return toStream
1423
1424 const decodeHeaders = Schema.decodeUnknownEffect(successSchema.headers, headersOptions)
1425 return (response: HttpClientResponse.HttpClientResponse, sseOptions?: Sse.DecodeOptions) =>
1426 Effect.flatMap(
1427 decodeHeaders(response.headers),
1428 (headers) => Effect.map(toStream(response, sseOptions), (body) => HttpApiSchema.withHeaders({ body, headers }))
1429 )
1430}
1431
1432function makeStreamBodyDecoder(
1433 streamSchema: HttpApiSchema.StreamSchema,

Callers 1

HttpApiClient.tsFile · 0.85

Calls 5

makeStreamBodyDecoderFunction · 0.85
decodeHeadersFunction · 0.85
toStreamFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected