| 207 | * @since 4.0.0 |
| 208 | */ |
| 209 | export 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. |