| /** | |
| * Parses and renders Server-Sent Events text streams. | |
| * | |
| * Server-Sent Events, or SSE, are the text format used by `EventSource` for | |
| * one-way server-to-client updates. This module includes parsers, encoders, | |
| * channel helpers, and schema-based helpers for the `id`, `event`, and `data` | |
| * fields of each event. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| import type { NonEmptyReadonlyArray } from "../../Array.ts"; | |
| import * as Channel from "../../Channel.ts"; | |
| import * as Duration from "../../Duration.ts"; | |
| import * as Result from "../../Result.ts"; | |
| import * as Schema from "../../Schema.ts"; | |
| import * as SchemaTransformation from "../../SchemaTransformation.ts"; | |
| /** | |
| * Creates a channel that parses Server-Sent Events text chunks into `Event` values. | |
| * | |
| * **Details** | |
| * | |
| * SSE `retry` directives are emitted as `Retry` failures so callers can | |
| * reconnect with the requested delay. | |
| * | |
| * @category decoding | |
| * @since 4.0.0 | |
| */ | |
| export declare const decode: <IE, Done>() => Channel.Channel<NonEmptyReadonlyArray<Event>, IE | Retry, Done, NonEmptyReadonlyArray<string>, IE, Done>; | |
| /** | |
| * A constraint for schemas that can decode SSE events. | |
| * | |
| * @category decoding | |
| * @since 4.0.0 | |
| */ | |
| export interface EventCodec extends Schema.Codec<any, { | |
| readonly id?: string | undefined; | |
| readonly event?: string | undefined; | |
| readonly data: string; | |
| }, any, any> { | |
| } | |
| /** | |
| * Creates an SSE decoder channel that decodes each parsed event with a schema. | |
| * | |
| * **Details** | |
| * | |
| * The schema receives the untagged event shape containing `id`, `event`, and | |
| * string `data`. | |
| * | |
| * @category decoding | |
| * @since 4.0.0 | |
| */ | |
| export declare const decodeSchema: <S extends EventCodec, IE, Done>(schema: S) => Channel.Channel<NonEmptyReadonlyArray<S["Type"]>, IE | Retry | Schema.SchemaError, Done, NonEmptyReadonlyArray<string>, IE, Done, S["DecodingServices"]>; | |
| /** | |
| * Creates an SSE decoder channel that JSON-decodes each event `data` field with a schema. | |
| * | |
| * **Details** | |
| * | |
| * The output preserves the SSE `event` name and optional `id` while replacing | |
| * `data` with the decoded value. | |
| * | |
| * @category decoding | |
| * @since 4.0.0 | |
| */ | |
| export declare const decodeDataSchema: <Type, DecodingServices, IE, Done>(schema: Schema.Decoder<Type, DecodingServices>) => Channel.Channel<NonEmptyReadonlyArray<{ | |
| readonly event: string; | |
| readonly id: string | undefined; | |
| readonly data: Type; | |
| }>, IE | Retry | Schema.SchemaError, Done, NonEmptyReadonlyArray<string>, IE, Done, DecodingServices>; | |
| /** | |
| * Creates a stateful Server-Sent Events parser. | |
| * | |
| * **Details** | |
| * | |
| * Call `feed` with text chunks to parse `Event` and `Retry` values through the | |
| * callback, and call `reset` to clear any buffered event state. | |
| * | |
| * @category decoding | |
| * @since 4.0.0 | |
| */ | |
| export declare function makeParser(onParse: (event: AnyEvent) => void): Parser; | |
| /** | |
| * Stateful Server-Sent Events parser returned by `makeParser`. | |
| * | |
| * **Details** | |
| * | |
| * `feed` accepts additional text chunks and `reset` clears buffered parser state. | |
| * | |
| * @category decoding | |
| * @since 4.0.0 | |
| */ | |
| export interface Parser { | |
| feed(chunk: string): void; | |
| reset(): void; | |
| } | |
| /** | |
| * Creates a channel that encodes `Event` values as Server-Sent Events text. | |
| * | |
| * **Details** | |
| * | |
| * If the upstream channel fails with `Retry`, the retry directive is written and | |
| * the encoder completes. | |
| * | |
| * @category encoding | |
| * @since 4.0.0 | |
| */ | |
| export declare const encode: <IE, Done>() => Channel.Channel<NonEmptyReadonlyArray<string>, IE, void, NonEmptyReadonlyArray<Event>, IE | Retry, Done>; | |
| /** | |
| * Creates an SSE encoder channel for values accepted by a schema. | |
| * | |
| * **Details** | |
| * | |
| * Values are schema-encoded to the untagged SSE event shape, transformed to | |
| * `Event`, and then written as Server-Sent Events text. | |
| * | |
| * @category encoding | |
| * @since 4.0.0 | |
| */ | |
| export declare const encodeSchema: <S extends EventCodec, IE, Done>(schema: S) => Channel.Channel<NonEmptyReadonlyArray<string>, IE | Schema.SchemaError, void, NonEmptyReadonlyArray<S["Type"]>, IE | Retry, Done, S["EncodingServices"]>; | |
| /** | |
| * Encoder capable of rendering an `Event` or `Retry` value as Server-Sent | |
| * Events text. | |
| * | |
| * @category encoding | |
| * @since 4.0.0 | |
| */ | |
| export interface Encoder { | |
| write(event: AnyEvent): string; | |
| } | |
| /** | |
| * Tagged model for a Server-Sent Events message containing the event name, optional event ID, and string data payload. | |
| * | |
| * @category models | |
| * @since 4.0.0 | |
| */ | |
| export interface Event { | |
| readonly _tag: "Event"; | |
| readonly event: string; | |
| readonly id: string | undefined; | |
| readonly data: string; | |
| } | |
| /** | |
| * Schema for the untagged Server-Sent Events payload shape containing an optional `id`, `event`, and string `data` fields. | |
| * | |
| * @category models | |
| * @since 4.0.0 | |
| */ | |
| export declare const EventEncoded: Schema.Struct<{ | |
| readonly id: Schema.optional<Schema.String>; | |
| readonly event: Schema.String; | |
| readonly data: Schema.String; | |
| }>; | |
| /** | |
| * Schema for the tagged Server-Sent Events message model that adds `_tag: "Event"` to the event name, optional event ID, and string data payload. | |
| * | |
| * @category models | |
| * @since 4.0.0 | |
| */ | |
| export declare const Event: Schema.Struct<{ | |
| readonly _tag: Schema.tag<"Event">; | |
| readonly id: Schema.UndefinedOr<Schema.String>; | |
| readonly event: Schema.String; | |
| readonly data: Schema.String; | |
| }>; | |
| /** | |
| * Schema for transforming untagged SSE event payloads into tagged `Event` | |
| * models. | |
| * | |
| * @category models | |
| * @since 4.0.0 | |
| */ | |
| export declare const transformEvent: SchemaTransformation.Transformation<{ | |
| readonly id?: string | undefined; | |
| readonly event?: string | undefined; | |
| readonly data: string; | |
| }, { | |
| readonly _tag: "Event"; | |
| readonly id: string | undefined; | |
| readonly event: string; | |
| readonly data: string; | |
| }, never, never>; | |
| /** | |
| * Untagged Server-Sent Events payload shape containing the event name, optional event ID, and string data payload. | |
| * | |
| * @category models | |
| * @since 4.0.0 | |
| */ | |
| export interface EventEncoded { | |
| readonly event: string; | |
| readonly id?: string | undefined; | |
| readonly data: string; | |
| } | |
| declare const RetryTypeId: "~effect/encoding/Sse/Retry"; | |
| declare const Retry_base: new <A extends Record<string, any> = {}>(args: import("../../Types.ts").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => Readonly<A> & { | |
| readonly _tag: "Retry"; | |
| } & import("../../Pipeable.ts").Pipeable; | |
| /** | |
| * Represents a Server-Sent Events retry directive. | |
| * | |
| * **Details** | |
| * | |
| * Decoders surface this value as a failure to request reconnection after | |
| * `duration`; encoders serialize an upstream `Retry` failure as a `retry:` line. | |
| * | |
| * @category models | |
| * @since 4.0.0 | |
| */ | |
| export declare class Retry extends Retry_base<{ | |
| readonly duration: Duration.Duration; | |
| readonly lastEventId: string | undefined; | |
| }> { | |
| /** | |
| * Marks this value as an SSE retry directive for runtime guards. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| readonly [RetryTypeId]: typeof RetryTypeId; | |
| /** | |
| * Returns `true` when the value is an SSE retry directive. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| static is(u: unknown): u is Retry; | |
| /** | |
| * Separates SSE retry directives from regular event values. | |
| * | |
| * @since 4.0.0 | |
| */ | |
| static filter<A>(u: A): Result.Result<Retry, Exclude<A, Retry>>; | |
| } | |
| /** | |
| * Union of SSE values that can be rendered by an `Encoder`: regular events and | |
| * retry directives. | |
| * | |
| * @category models | |
| * @since 4.0.0 | |
| */ | |
| export type AnyEvent = Event | Retry; | |
| /** | |
| * Default Server-Sent Events encoder. | |
| * | |
| * **Details** | |
| * | |
| * It renders `Event` values as `id`, `event`, and `data` lines and renders | |
| * `Retry` values as `retry:` directives. | |
| * | |
| * @category encoding | |
| * @since 4.0.0 | |
| */ | |
| export declare const encoder: Encoder; | |
| export {}; | |
| //# sourceMappingURL=Sse.d.ts.map |
Xet Storage Details
- Size:
- 7.76 kB
- Xet hash:
- e9f87bda6b041596b0de8f24e56d58d3e772a04e040aedea7c22558954de7d80
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.