| 235 | * @since 4.0.0 |
| 236 | */ |
| 237 | export 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. |