eventsource
Advanced tools
Comparing version
@@ -6,3 +6,3 @@ /** | ||
*/ | ||
export declare interface AddEventListenerOptions extends EventListenerOptions { | ||
declare interface AddEventListenerOptions_2 extends EventListenerOptions_2 { | ||
/** When `true`, the listener is automatically removed when it is first invoked. Default: `false`. */ | ||
@@ -15,2 +15,3 @@ once?: boolean | ||
} | ||
export {AddEventListenerOptions_2 as AddEventListenerOptions} | ||
@@ -24,3 +25,3 @@ /** | ||
*/ | ||
export declare class ErrorEvent extends Event { | ||
declare class ErrorEvent_2 extends Event { | ||
/** | ||
@@ -40,4 +41,18 @@ * HTTP status code, if this was triggered by an HTTP error | ||
message?: string | undefined | ||
constructor(type: string, code?: number, message?: string) | ||
/** | ||
* Constructs a new `ErrorEvent` instance. This is typically not called directly, | ||
* but rather emitted by the `EventSource` object when an error occurs. | ||
* | ||
* @param type - The type of the event (should be "error") | ||
* @param errorEventInitDict - Optional properties to include in the error event | ||
*/ | ||
constructor( | ||
type: string, | ||
errorEventInitDict?: { | ||
message?: string | undefined | ||
code?: number | undefined | ||
}, | ||
) | ||
} | ||
export {ErrorEvent_2 as ErrorEvent} | ||
@@ -49,5 +64,6 @@ /** | ||
*/ | ||
export declare interface EventListener { | ||
declare interface EventListener_2 { | ||
(evt: Event | MessageEvent): void | ||
} | ||
export {EventListener_2 as EventListener} | ||
@@ -59,5 +75,6 @@ /** | ||
*/ | ||
export declare interface EventListenerObject { | ||
declare interface EventListenerObject_2 { | ||
handleEvent(object: Event): void | ||
} | ||
export {EventListenerObject_2 as EventListenerObject} | ||
@@ -69,6 +86,7 @@ /** | ||
*/ | ||
export declare interface EventListenerOptions { | ||
declare interface EventListenerOptions_2 { | ||
/** Not directly used by Node.js. Added for API completeness. Default: `false`. */ | ||
capture?: boolean | ||
} | ||
export {EventListenerOptions_2 as EventListenerOptions} | ||
@@ -80,3 +98,4 @@ /** | ||
*/ | ||
export declare type EventListenerOrEventListenerObject = EventListener | EventListenerObject | ||
declare type EventListenerOrEventListenerObject_2 = EventListener_2 | EventListenerObject_2 | ||
export {EventListenerOrEventListenerObject_2 as EventListenerOrEventListenerObject} | ||
@@ -163,4 +182,4 @@ /** | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/error_event) */ | ||
get onerror(): ((ev: ErrorEvent) => unknown) | null | ||
set onerror(value: ((ev: ErrorEvent) => unknown) | null) | ||
get onerror(): ((ev: ErrorEvent_2) => unknown) | null | ||
set onerror(value: ((ev: ErrorEvent_2) => unknown) | null) | ||
/** [MDN Reference](https://developer.mozilla.org/docs/Web/API/EventSource/message_event) */ | ||
@@ -172,6 +191,6 @@ get onmessage(): ((ev: MessageEvent) => unknown) | null | ||
set onopen(value: ((ev: Event) => unknown) | null) | ||
addEventListener<K extends keyof EventSourceEventMap>( | ||
addEventListener<K extends keyof EventSourceEventMap_2>( | ||
type: K, | ||
listener: (this: EventSource_2, ev: EventSourceEventMap[K]) => unknown, | ||
options?: boolean | AddEventListenerOptions, | ||
listener: (this: EventSource_2, ev: EventSourceEventMap_2[K]) => unknown, | ||
options?: boolean | AddEventListenerOptions_2, | ||
): void | ||
@@ -181,13 +200,13 @@ addEventListener( | ||
listener: (this: EventSource_2, event: MessageEvent) => unknown, | ||
options?: boolean | AddEventListenerOptions, | ||
options?: boolean | AddEventListenerOptions_2, | ||
): void | ||
addEventListener( | ||
type: string, | ||
listener: EventListenerOrEventListenerObject, | ||
options?: boolean | AddEventListenerOptions, | ||
listener: EventListenerOrEventListenerObject_2, | ||
options?: boolean | AddEventListenerOptions_2, | ||
): void | ||
removeEventListener<K extends keyof EventSourceEventMap>( | ||
removeEventListener<K extends keyof EventSourceEventMap_2>( | ||
type: K, | ||
listener: (this: EventSource_2, ev: EventSourceEventMap[K]) => unknown, | ||
options?: boolean | EventListenerOptions, | ||
listener: (this: EventSource_2, ev: EventSourceEventMap_2[K]) => unknown, | ||
options?: boolean | EventListenerOptions_2, | ||
): void | ||
@@ -197,10 +216,10 @@ removeEventListener( | ||
listener: (this: EventSource_2, event: MessageEvent) => unknown, | ||
options?: boolean | EventListenerOptions, | ||
options?: boolean | EventListenerOptions_2, | ||
): void | ||
removeEventListener( | ||
type: string, | ||
listener: EventListenerOrEventListenerObject, | ||
options?: boolean | EventListenerOptions, | ||
listener: EventListenerOrEventListenerObject_2, | ||
options?: boolean | EventListenerOptions_2, | ||
): void | ||
constructor(url: string | URL, eventSourceInitDict?: EventSourceInit) | ||
constructor(url: string | URL, eventSourceInitDict?: EventSourceInit_2) | ||
/** | ||
@@ -222,7 +241,8 @@ * Aborts any instances of the fetch algorithm started for this EventSource object, and sets the readyState attribute to CLOSED. | ||
*/ | ||
export declare interface EventSourceEventMap { | ||
error: ErrorEvent | ||
declare interface EventSourceEventMap_2 { | ||
error: ErrorEvent_2 | ||
message: MessageEvent | ||
open: Event | ||
} | ||
export {EventSourceEventMap_2 as EventSourceEventMap} | ||
@@ -234,3 +254,3 @@ /** | ||
*/ | ||
export declare interface EventSourceInit { | ||
declare interface EventSourceInit_2 { | ||
/** | ||
@@ -246,2 +266,3 @@ * A boolean value, defaulting to `false`, indicating if CORS should be set to `include` credentials. | ||
} | ||
export {EventSourceInit_2 as EventSourceInit} | ||
@@ -312,3 +333,3 @@ /** | ||
done: false | ||
value: unknown | ||
value: ArrayBufferLike | ||
} | ||
@@ -315,0 +336,0 @@ | { |
import { createParser } from "eventsource-parser"; | ||
class ErrorEvent extends Event { | ||
constructor(type, code, message) { | ||
super(type), this.code = code != null ? code : void 0, this.message = message != null ? message : void 0; | ||
/** | ||
* Constructs a new `ErrorEvent` instance. This is typically not called directly, | ||
* but rather emitted by the `EventSource` object when an error occurs. | ||
* | ||
* @param type - The type of the event (should be "error") | ||
* @param errorEventInitDict - Optional properties to include in the error event | ||
*/ | ||
constructor(type, errorEventInitDict) { | ||
var _a, _b; | ||
super(type), this.code = (_a = errorEventInitDict == null ? void 0 : errorEventInitDict.code) != null ? _a : void 0, this.message = (_b = errorEventInitDict == null ? void 0 : errorEventInitDict.message) != null ? _b : void 0; | ||
} | ||
/** | ||
* Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance, | ||
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging, | ||
* we explicitly include the properties in the `inspect` method. | ||
* | ||
* This is automatically called by Node.js when you `console.log` an instance of this class. | ||
* | ||
* @param _depth - The current depth | ||
* @param options - The options passed to `util.inspect` | ||
* @param inspect - The inspect function to use (prevents having to import it from `util`) | ||
* @returns A string representation of the error | ||
*/ | ||
[Symbol.for("nodejs.util.inspect.custom")](_depth, options, inspect) { | ||
return inspect(inspectableError(this), options); | ||
} | ||
/** | ||
* Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance, | ||
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging, | ||
* we explicitly include the properties in the `inspect` method. | ||
* | ||
* This is automatically called by Deno when you `console.log` an instance of this class. | ||
* | ||
* @param inspect - The inspect function to use (prevents having to import it from `util`) | ||
* @param options - The options passed to `Deno.inspect` | ||
* @returns A string representation of the error | ||
*/ | ||
[Symbol.for("Deno.customInspect")](inspect, options) { | ||
return inspect(inspectableError(this), options); | ||
} | ||
} | ||
@@ -14,2 +51,12 @@ function syntaxError(message) { | ||
} | ||
function inspectableError(err) { | ||
return { | ||
type: err.type, | ||
message: err.message, | ||
code: err.code, | ||
defaultPrevented: err.defaultPrevented, | ||
cancelable: err.cancelable, | ||
timeStamp: err.timeStamp | ||
}; | ||
} | ||
var __typeError = (msg) => { | ||
@@ -184,6 +231,6 @@ throw TypeError(msg); | ||
*/ | ||
failConnection_fn = function(error, code) { | ||
failConnection_fn = function(message, code) { | ||
var _a; | ||
__privateGet(this, _readyState) !== this.CLOSED && __privateSet(this, _readyState, this.CLOSED); | ||
const errorEvent = new ErrorEvent("error", code, error); | ||
const errorEvent = new ErrorEvent("error", { code, message }); | ||
(_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent); | ||
@@ -193,7 +240,7 @@ }, /** | ||
* | ||
* @param error - The error causing the connection to fail | ||
* @param message - The error causing the connection to fail | ||
* @param code - The HTTP status code, if available | ||
* @internal | ||
*/ | ||
scheduleReconnect_fn = function(error, code) { | ||
scheduleReconnect_fn = function(message, code) { | ||
var _a; | ||
@@ -203,3 +250,3 @@ if (__privateGet(this, _readyState) === this.CLOSED) | ||
__privateSet(this, _readyState, this.CONNECTING); | ||
const errorEvent = new ErrorEvent("error", code, error); | ||
const errorEvent = new ErrorEvent("error", { code, message }); | ||
(_a = __privateGet(this, _onError)) == null || _a.call(this, errorEvent), this.dispatchEvent(errorEvent), __privateSet(this, _reconnectTimer, setTimeout(__privateGet(this, _reconnect), __privateGet(this, _reconnectInterval))); | ||
@@ -206,0 +253,0 @@ }, _reconnect = /* @__PURE__ */ new WeakMap(), /** |
{ | ||
"name": "eventsource", | ||
"version": "3.0.4", | ||
"version": "3.0.5-umd.0", | ||
"description": "WhatWG/W3C compliant EventSource client for Node.js and browsers", | ||
@@ -17,2 +17,3 @@ "sideEffects": false, | ||
"require": "./dist/index.cjs", | ||
"umd": "./dist/index.umd.cjs", | ||
"default": "./dist/index.js" | ||
@@ -70,3 +71,3 @@ }, | ||
"devDependencies": { | ||
"@sanity/pkg-utils": "^6.11.10", | ||
"@sanity/pkg-utils": "^7.1.0", | ||
"@sanity/semantic-release-preset": "^5.0.0", | ||
@@ -77,3 +78,3 @@ "@tsconfig/strictest": "^2.0.5", | ||
"@typescript-eslint/parser": "^6.11.0", | ||
"esbuild": "^0.24.0", | ||
"esbuild": "^0.25.1", | ||
"eslint": "^8.57.0", | ||
@@ -84,3 +85,3 @@ "eslint-config-prettier": "^9.1.0", | ||
"playwright": "^1.48.2", | ||
"prettier": "^3.2.5", | ||
"prettier": "^3.5.3", | ||
"rimraf": "^5.0.5", | ||
@@ -91,3 +92,3 @@ "rollup-plugin-visualizer": "^5.12.0", | ||
"tsx": "^4.19.2", | ||
"typescript": "^5.6.3", | ||
"typescript": "^5.8.2", | ||
"undici": "^6.20.1" | ||
@@ -131,6 +132,3 @@ }, | ||
} | ||
}, | ||
"publishConfig": { | ||
"provenance": true | ||
} | ||
} |
@@ -25,7 +25,55 @@ /** | ||
constructor(type: string, code?: number, message?: string) { | ||
/** | ||
* Constructs a new `ErrorEvent` instance. This is typically not called directly, | ||
* but rather emitted by the `EventSource` object when an error occurs. | ||
* | ||
* @param type - The type of the event (should be "error") | ||
* @param errorEventInitDict - Optional properties to include in the error event | ||
*/ | ||
constructor( | ||
type: string, | ||
errorEventInitDict?: {message?: string | undefined; code?: number | undefined}, | ||
) { | ||
super(type) | ||
this.code = code ?? undefined | ||
this.message = message ?? undefined | ||
this.code = errorEventInitDict?.code ?? undefined | ||
this.message = errorEventInitDict?.message ?? undefined | ||
} | ||
/** | ||
* Node.js "hides" the `message` and `code` properties of the `ErrorEvent` instance, | ||
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging, | ||
* we explicitly include the properties in the `inspect` method. | ||
* | ||
* This is automatically called by Node.js when you `console.log` an instance of this class. | ||
* | ||
* @param _depth - The current depth | ||
* @param options - The options passed to `util.inspect` | ||
* @param inspect - The inspect function to use (prevents having to import it from `util`) | ||
* @returns A string representation of the error | ||
*/ | ||
[Symbol.for('nodejs.util.inspect.custom')]( | ||
_depth: number, | ||
options: {colors: boolean}, | ||
inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string, | ||
): string { | ||
return inspect(inspectableError(this), options) | ||
} | ||
/** | ||
* Deno "hides" the `message` and `code` properties of the `ErrorEvent` instance, | ||
* when it is `console.log`'ed. This makes it harder to debug errors. To ease debugging, | ||
* we explicitly include the properties in the `inspect` method. | ||
* | ||
* This is automatically called by Deno when you `console.log` an instance of this class. | ||
* | ||
* @param inspect - The inspect function to use (prevents having to import it from `util`) | ||
* @param options - The options passed to `Deno.inspect` | ||
* @returns A string representation of the error | ||
*/ | ||
[Symbol.for('Deno.customInspect')]( | ||
inspect: (obj: unknown, inspectOptions: {colors: boolean}) => string, | ||
options: {colors: boolean}, | ||
): string { | ||
return inspect(inspectableError(this), options) | ||
} | ||
} | ||
@@ -77,1 +125,19 @@ | ||
} | ||
/** | ||
* Convert an `ErrorEvent` instance into a plain object for inspection. | ||
* | ||
* @param err - The `ErrorEvent` instance to inspect | ||
* @returns A plain object representation of the error | ||
* @internal | ||
*/ | ||
function inspectableError(err: ErrorEvent) { | ||
return { | ||
type: err.type, | ||
message: err.message, | ||
code: err.code, | ||
defaultPrevented: err.defaultPrevented, | ||
cancelable: err.cancelable, | ||
timeStamp: err.timeStamp, | ||
} | ||
} |
@@ -520,3 +520,3 @@ import {createParser, type EventSourceMessage, type EventSourceParser} from 'eventsource-parser' | ||
*/ | ||
#failConnection(error?: string, code?: number) { | ||
#failConnection(message?: string, code?: number) { | ||
// [spec] …if the readyState attribute is set to a value other than CLOSED, | ||
@@ -534,3 +534,3 @@ // [spec] sets the readyState attribute to CLOSED… | ||
// Printing to console is not very programatically helpful, though, so we emit a custom event. | ||
const errorEvent = new ErrorEvent('error', code, error) | ||
const errorEvent = new ErrorEvent('error', {code, message}) | ||
@@ -544,7 +544,7 @@ this.#onError?.(errorEvent) | ||
* | ||
* @param error - The error causing the connection to fail | ||
* @param message - The error causing the connection to fail | ||
* @param code - The HTTP status code, if available | ||
* @internal | ||
*/ | ||
#scheduleReconnect(error?: string, code?: number) { | ||
#scheduleReconnect(message?: string, code?: number) { | ||
// [spec] If the readyState attribute is set to CLOSED, abort the task. | ||
@@ -559,3 +559,3 @@ if (this.#readyState === this.CLOSED) { | ||
// [spec] Fire an event named `error` at the EventSource object. | ||
const errorEvent = new ErrorEvent('error', code, error) | ||
const errorEvent = new ErrorEvent('error', {code, message}) | ||
this.#onError?.(errorEvent) | ||
@@ -562,0 +562,0 @@ this.dispatchEvent(errorEvent) |
@@ -43,3 +43,3 @@ import type {ErrorEvent} from './errors.js' | ||
export interface ReaderLike { | ||
read(): Promise<{done: false; value: unknown} | {done: true; value?: undefined}> | ||
read(): Promise<{done: false; value: ArrayBufferLike} | {done: true; value?: undefined}> | ||
cancel(): Promise<void> | ||
@@ -46,0 +46,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
203193
53.85%16
23.08%2254
52.71%1
Infinity%