diff options
Diffstat (limited to 'packages/bun-types/globals.d.ts')
-rw-r--r-- | packages/bun-types/globals.d.ts | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts index 4ca1a8d3e..a5d011b52 100644 --- a/packages/bun-types/globals.d.ts +++ b/packages/bun-types/globals.d.ts @@ -3197,3 +3197,82 @@ declare module "*.txt" { var text: string; export = text; } + +interface EventSourceEventMap { + error: Event; + message: MessageEvent; + open: Event; +} + +interface EventSource extends EventTarget { + onerror: ((this: EventSource, ev: ErrorEvent) => any) | null; + onmessage: ((this: EventSource, ev: MessageEvent) => any) | null; + onopen: ((this: EventSource, ev: Event) => any) | null; + /** Returns the state of this EventSource object's connection. It can have the values described below. */ + readonly readyState: number; + /** Returns the URL providing the event stream. */ + readonly url: string; + /** Returns true if the credentials mode for connection requests to the URL providing the event stream is set to "include", and false otherwise. + * + * Not supported in Bun + * + */ + readonly withCredentials: boolean; + /** Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED. */ + close(): void; + readonly CLOSED: number; + readonly CONNECTING: number; + readonly OPEN: number; + addEventListener<K extends keyof EventSourceEventMap>( + type: K, + listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, + options?: boolean | AddEventListenerOptions, + ): void; + addEventListener( + type: string, + listener: (this: EventSource, event: MessageEvent) => any, + options?: boolean | AddEventListenerOptions, + ): void; + addEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | AddEventListenerOptions, + ): void; + removeEventListener<K extends keyof EventSourceEventMap>( + type: K, + listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, + options?: boolean | EventListenerOptions, + ): void; + removeEventListener( + type: string, + listener: (this: EventSource, event: MessageEvent) => any, + options?: boolean | EventListenerOptions, + ): void; + removeEventListener( + type: string, + listener: EventListenerOrEventListenerObject, + options?: boolean | EventListenerOptions, + ): void; + + /** + * Keep the event loop alive while connection is open or reconnecting + * + * Not available in browsers + */ + ref(): void; + + /** + * Do not keep the event loop alive while connection is open or reconnecting + * + * Not available in browsers + */ + unref(): void; +} + +declare var EventSource: { + prototype: EventSource; + new (url: string | URL, eventSourceInitDict?: EventSourceInit): EventSource; + readonly CLOSED: number; + readonly CONNECTING: number; + readonly OPEN: number; +}; |