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

Function makeStreamEncoder

packages/effect/src/http-api/HttpApiBuilder.ts:1220–1251  ·  view source on GitHub ↗
(
  endpoint: HttpApiEndpoint.Top,
  options: SchemaAST.ParseOptions | undefined
)

Source from the content-addressed store, hash-verified

1218}
1219
1220function 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
1253function makeStreamBodyEncoder(
1254 streamSchema: HttpApiSchema.StreamSchema,

Callers 1

handlerToHttpEffectFunction · 0.85

Calls 5

getStreamSuccessSchemaFunction · 0.85
hasBufferedSuccessFunction · 0.85
makeStreamBodyEncoderFunction · 0.85
streamMethod · 0.65
succeedMethod · 0.45

Tested by

no test coverage detected