MCPcopy Create free account
hub / github.com/effect-app/libs / makeParser

Function makeParser

repos/effect/packages/effect/src/unstable/encoding/Sse.ts:178–328  ·  view source on GitHub ↗
(onParse: (event: AnyEvent) => void)

Source from the content-addressed store, hash-verified

176 S extends EventCodec,
177 IE,
178 Done
179>(
180 schema: S,
181 options?: DecodeOptions
182): Channel.Channel<
183 NonEmptyReadonlyArray<S["Type"]>,
184 IE | Retry | SseError | Schema.SchemaError,
185 Done,
186 NonEmptyReadonlyArray<string>,
187 IE,
188 Done,
189 S["DecodingServices"]
190> =>
191 Channel.pipeTo(
192 decode<IE, Done>(options),
193 ChannelSchema.decode(EventEncoded.pipe(
194 Schema.decodeTo(schema)
195 ))()
196 )
197
198/**
199 * Creates an SSE decoder channel that JSON-decodes each event `data` field with a schema.
200 *
201 * **Details**
202 *
203 * The output preserves the SSE `event` name and optional `id` while replacing
204 * `data` with the decoded value.
205 *
206 * @category decoding
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 )

Callers 1

decodeFunction · 0.70

Calls 1

resetFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…