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

Function decodeDataSchema

packages/effect/src/encoding/Sse.ts:237–264  ·  view source on GitHub ↗
(
  schema: Schema.ConstraintDecoder<Type, DecodingServices>,
  options?: DecodeOptions
)

Source from the content-addressed store, hash-verified

235 * @since 4.0.0
236 */
237export const decodeDataSchema = <Type, DecodingServices, IE, Done>(
238 schema: Schema.ConstraintDecoder<Type, DecodingServices>,
239 options?: DecodeOptions
240): Channel.Channel<
241 NonEmptyReadonlyArray<{
242 readonly event: string
243 readonly id: string | undefined
244 readonly data: Type
245 }>,
246 IE | Retry | SseError | Schema.SchemaError,
247 Done,
248 NonEmptyReadonlyArray<string>,
249 IE,
250 Done,
251 DecodingServices
252> => {
253 const eventSchema = Schema.Struct({
254 ...EventEncoded.fields,
255 data: Schema.fromJsonString(schema)
256 })
257 return Channel.pipeTo(
258 decode<IE, Done>(options),
259 Channel.map(
260 ChannelSchema.decode(eventSchema)(),
261 Arr.map((event) => ({ ...event, id: event.id }))
262 )
263 )
264}
265
266/**
267 * Creates a stateful Server-Sent Events parser.

Callers

nothing calls this directly

Calls 3

decodeFunction · 0.70
mapMethod · 0.45
decodeMethod · 0.45

Tested by

no test coverage detected