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

Function decodeDataSchema

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

Source from the content-addressed store, hash-verified

207 * @since 4.0.0
208 */
209export const decodeDataSchema = <Type, DecodingServices, IE, Done>(
210 schema: Schema.ConstraintDecoder<Type, DecodingServices>,
211 options?: DecodeOptions
212): Channel.Channel<
213 NonEmptyReadonlyArray<{
214 readonly event: string
215 readonly id: string | undefined
216 readonly data: Type
217 }>,
218 IE | Retry | SseError | Schema.SchemaError,
219 Done,
220 NonEmptyReadonlyArray<string>,
221 IE,
222 Done,
223 DecodingServices
224> => {
225 const eventSchema = Schema.Struct({
226 ...EventEncoded.fields,
227 data: Schema.fromJsonString(schema)
228 })
229 return Channel.pipeTo(
230 decode<IE, Done>(options),
231 Channel.map(
232 ChannelSchema.decode(eventSchema)(),
233 Arr.map((event) => ({ ...event, id: event.id }))
234 )
235 )
236}
237
238/**
239 * Creates a stateful Server-Sent Events parser.

Callers

nothing calls this directly

Calls 2

decodeFunction · 0.70
mapMethod · 0.45

Tested by

no test coverage detected