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

Function StreamSse

packages/effect/src/unstable/httpapi/HttpApiSchema.ts:361–384  ·  view source on GitHub ↗
(options: {
  readonly contentType?: string | undefined
  readonly events?: Sse.EventCodec | undefined
  readonly data?: Schema.Constraint | undefined
  readonly error?: Schema.Constraint | undefined
})

Source from the content-addressed store, hash-verified

359 readonly error?: Error | undefined
360 }): StreamSse<SseEventFromData<Data>, Error, Data["Type"]>
361} = (options: {
362 readonly contentType?: string | undefined
363 readonly events?: Sse.EventCodec | undefined
364 readonly data?: Schema.Constraint | undefined
365 readonly error?: Schema.Constraint | undefined
366}): StreamSse<Sse.EventCodec, Schema.Top, unknown> => {
367 const events = options.events ?? (options.data === undefined ? undefined : Schema.Struct({
368 id: Schema.UndefinedOr(Schema.String),
369 event: Schema.String,
370 data: Schema.fromJsonString(options.data)
371 }))
372 if (events === undefined) {
373 throw new Error("StreamSse requires either an events schema or a data schema")
374 }
375 return Schema.make<StreamSse<Sse.EventCodec, Schema.Top, unknown>>(streamSchema.ast, {
376 [StreamSchemaTypeId]: StreamSchemaTypeId,
377 _tag: "StreamSse",
378 mode: "sse",
379 sseMode: options.events === undefined ? "data" : "events",
380 contentType: options.contentType ?? defaultStreamContentType("sse"),
381 events,
382 error: options.error ?? Schema.Never
383 })
384}
385
386/**
387 * Creates a streaming `Uint8Array` success response schema.

Callers

nothing calls this directly

Calls 2

defaultStreamContentTypeFunction · 0.85
makeMethod · 0.65

Tested by

no test coverage detected