UNPKG

@laravel/stream-vue

Version:
70 lines (62 loc) 2.41 kB
import { Ref } from 'vue'; declare type EventStreamOptions = { eventName?: string | string[]; endSignal?: string; glue?: string; replace?: boolean; onMessage?: (event: MessageEvent) => void; onComplete?: () => void; onError?: (error: Event) => void; }; declare type EventStreamResult = { message: Readonly<Ref<string>>; messageParts: Readonly<Ref<readonly string[]>>; close: (resetMessage?: boolean) => void; clearMessage: () => void; }; declare type StreamOptions<TSendBody extends Record<string, any> = {}> = { id?: string; initialInput?: TSendBody; headers?: Record<string, string>; csrfToken?: string; json?: boolean; credentials?: RequestCredentials; onResponse?: (response: Response) => void; onData?: (data: string) => void; onCancel?: () => void; onFinish?: () => void; onError?: (error: Error) => void; onBeforeSend?: (request: RequestInit) => boolean | RequestInit | void; }; /** * Composable for handling server-sent events (SSE) streams * * @param url - The URL to connect to for the EventSource * @param options - Options for the stream * * @link https://laravel.com/docs/responses#event-streams * * @returns StreamResult object containing the accumulated response, close, and reset functions */ export declare const useEventStream: (url: string, { eventName, endSignal, glue, replace, onMessage, onComplete, onError, }?: EventStreamOptions) => EventStreamResult; export declare const useJsonStream: <TJsonData = null, TSendBody extends Record<string, any> = {}>(url: string, options?: Omit<StreamOptions<TSendBody>, "json">) => { isFetching: Readonly<Ref<boolean>>; isStreaming: Readonly<Ref<boolean>>; id: string; send: (body: TSendBody) => void; cancel: () => void; clearData: () => void; data: Readonly<TJsonData | null>; strData: Readonly<Ref<string, string>>; }; export declare const useStream: <TSendBody extends Record<string, any> = {}, TJsonData = null>(url: string, options?: StreamOptions<TSendBody>) => { data: Readonly<Ref<string>>; jsonData: Readonly<TJsonData | null>; isFetching: Readonly<Ref<boolean>>; isStreaming: Readonly<Ref<boolean>>; id: string; send: (body: TSendBody) => void; cancel: () => void; clearData: () => void; }; export { }