aboutsummaryrefslogtreecommitdiff
path: root/packages/bun-types/globals.d.ts
diff options
context:
space:
mode:
authorGravatar Ciro Spaciari <ciro.spaciari@gmail.com> 2023-06-18 00:54:50 -0300
committerGravatar GitHub <noreply@github.com> 2023-06-17 20:54:50 -0700
commitb2af1984ed6db162468f3dd8c6d460420d4f4a2e (patch)
tree4d0776e093ba823d79369b5e733fd5be527af900 /packages/bun-types/globals.d.ts
parent065713aeca2ae3013bdf5b3d2f04263459631598 (diff)
downloadbun-b2af1984ed6db162468f3dd8c6d460420d4f4a2e.tar.gz
bun-b2af1984ed6db162468f3dd8c6d460420d4f4a2e.tar.zst
bun-b2af1984ed6db162468f3dd8c6d460420d4f4a2e.zip
[eventsource] SSE Client (#3074)
* fix flush * remove logs * add HTTP/1.1 eventsource * fix parse spec * multiple data in one event * get lastEventId for reconnection * fix parsing add reconnect * fix reconnection retry * add retry option * move eventsource to builtins * remove duplicate interface on globals.d.ts * move test to TS * fmt * allow no Content-Length or Transfer Encoding * udpate builtins * hardcoded * merge * revert /src/out * updated * Update .gitignore * Make the tests fail * Cleanup EventSource getter * fixup * fixup TS * fmt * update builtins * fix tests * Clear existing timeouts * Add `ref` and `unref` methods * Use `super` to make prototype pollution slightly harder * Reduce test timeout * Regenerate builtins * prettier + ref/unref * Outdated * forgot to commit this --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
Diffstat (limited to 'packages/bun-types/globals.d.ts')
-rw-r--r--packages/bun-types/globals.d.ts79
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;
+};