snapreq 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -5
- package/build/capabilities.d.ts +17 -17
- package/build/capabilities.d.ts.map +1 -1
- package/build/control.d.ts +12 -0
- package/build/control.d.ts.map +1 -0
- package/build/control.js +27 -0
- package/build/errors.d.ts +16 -16
- package/build/errors.d.ts.map +1 -1
- package/build/headers.d.ts +6 -6
- package/build/headers.d.ts.map +1 -1
- package/build/request.d.ts +15 -15
- package/build/request.d.ts.map +1 -1
- package/build/response.d.ts +27 -17
- package/build/response.d.ts.map +1 -1
- package/build/response.js +26 -2
- package/build/retry.d.ts +38 -37
- package/build/retry.d.ts.map +1 -1
- package/build/retry.js +40 -34
- package/build/snap-req.d.ts +116 -153
- package/build/snap-req.d.ts.map +1 -1
- package/build/snap-req.js +57 -102
- package/build/transports/fetch-transport.d.ts +10 -4
- package/build/transports/fetch-transport.d.ts.map +1 -1
- package/build/transports/fetch-transport.js +58 -12
- package/build/transports/fetch.d.ts.map +1 -1
- package/build/transports/node-transport.d.ts +23 -22
- package/build/transports/node-transport.d.ts.map +1 -1
- package/build/transports/node-transport.js +45 -10
- package/build/transports/proxy-bounce-transport.d.ts +4 -4
- package/build/transports/proxy-bounce-transport.d.ts.map +1 -1
- package/build/transports/select.d.ts +21 -21
- package/build/transports/select.d.ts.map +1 -1
- package/build/transports/xhr-transport.d.ts +2 -2
- package/build/transports/xhr-transport.d.ts.map +1 -1
- package/build/transports/xhr.d.ts.map +1 -1
- package/build/websocket/websocket-channel.d.ts +33 -22
- package/build/websocket/websocket-channel.d.ts.map +1 -1
- package/build/websocket/websocket-channel.js +27 -11
- package/build/websocket/websocket-client.d.ts +113 -71
- package/build/websocket/websocket-client.d.ts.map +1 -1
- package/build/websocket/websocket-client.js +142 -58
- package/build/websocket/websocket-connection.d.ts +19 -16
- package/build/websocket/websocket-connection.d.ts.map +1 -1
- package/build/websocket/websocket-connection.js +11 -3
- package/build/websocket.d.ts.map +1 -1
- package/package.json +8 -4
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import SnapReqWebSocketConnection from "./websocket-connection.js";
|
|
2
|
+
import SnapReqWebSocketChannel from "./websocket-channel.js";
|
|
1
3
|
/**
|
|
2
4
|
* A small WebSocket client that mirrors simple HTTP-style calls and channel
|
|
3
5
|
* subscriptions over `globalThis.WebSocket`, so the same code runs on web, Expo
|
|
@@ -9,57 +11,6 @@
|
|
|
9
11
|
* `json()`.
|
|
10
12
|
*/
|
|
11
13
|
export default class SnapReqWebSocketClient {
|
|
12
|
-
/**
|
|
13
|
-
* @param {object} args - Options object.
|
|
14
|
-
* @param {string} args.url - Full WebSocket URL, e.g. `ws://localhost:3006/websocket`.
|
|
15
|
-
* @param {boolean} [args.autoReconnect] - Enable auto-reconnect with exponential backoff.
|
|
16
|
-
* @param {boolean} [args.debug] - Whether to log debug output.
|
|
17
|
-
* @param {{getIsOnline?: () => boolean | Promise<boolean>, subscribe?: (callback: (isOnline: boolean) => void) => (() => void) | {remove: () => void}}} [args.networkMonitor] - Optional online-state adapter. When provided, auto-reconnect can wait for the network to report online before reconnecting, and open sockets are closed when the monitor reports offline.
|
|
18
|
-
* @param {number[]} [args.reconnectDelays] - Backoff delays in ms (default: [1000, 2000, 4000, 8000, 15000]).
|
|
19
|
-
* @param {{get: () => string | null | undefined | Promise<string | null | undefined>, set: (sessionId: string) => void | Promise<void>, clear: () => void | Promise<void>}} [args.sessionStore] - Optional sessionId persistence hook surviving reloads (localStorage, a cookie, SQLite, etc.).
|
|
20
|
-
* @param {(value: any) => any} [args.deserialize] - Optional transform applied to a response body inside `response.json()`. Lets an app re-hydrate its own wire format. Defaults to identity.
|
|
21
|
-
* @param {typeof globalThis.WebSocket} [args.webSocketImplementation] - WebSocket constructor to use instead of `globalThis.WebSocket`. Inject Node's `ws` here to get real WS ping/pong heartbeats and socket `unref` (the browser/undici global exposes neither).
|
|
22
|
-
* @param {number} [args.heartbeatIntervalMs] - When > 0 and the WebSocket implementation supports `.ping()` (Node `ws`), send a protocol ping every this-many ms and drop the socket if the peer did not pong since the previous ping (so a vanished peer is noticed within ~2× this interval). Default 0 (disabled).
|
|
23
|
-
* @param {boolean} [args.unref] - When the underlying socket exposes `unref()` (Node `ws`), unref it so an idle connection can never keep the process/event loop alive on its own. Best-effort no-op on browser/undici. Default false.
|
|
24
|
-
*/
|
|
25
|
-
constructor({ autoReconnect, debug, deserialize, heartbeatIntervalMs, networkMonitor, reconnectDelays, sessionStore, unref, url, webSocketImplementation }?: {
|
|
26
|
-
url: string;
|
|
27
|
-
autoReconnect?: boolean;
|
|
28
|
-
debug?: boolean;
|
|
29
|
-
networkMonitor?: {
|
|
30
|
-
getIsOnline?: () => boolean | Promise<boolean>;
|
|
31
|
-
subscribe?: (callback: (isOnline: boolean) => void) => (() => void) | {
|
|
32
|
-
remove: () => void;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
reconnectDelays?: number[];
|
|
36
|
-
sessionStore?: {
|
|
37
|
-
get: () => string | null | undefined | Promise<string | null | undefined>;
|
|
38
|
-
set: (sessionId: string) => void | Promise<void>;
|
|
39
|
-
clear: () => void | Promise<void>;
|
|
40
|
-
};
|
|
41
|
-
deserialize?: (value: any) => any;
|
|
42
|
-
webSocketImplementation?: typeof globalThis.WebSocket;
|
|
43
|
-
heartbeatIntervalMs?: number;
|
|
44
|
-
unref?: boolean;
|
|
45
|
-
});
|
|
46
|
-
/** @type {Map<string, {reject: (error: unknown) => void, resolve: (response: SnapReqWebSocketResponse) => void}>} */
|
|
47
|
-
pendingRequests: Map<string, {
|
|
48
|
-
reject: (error: unknown) => void;
|
|
49
|
-
resolve: (response: SnapReqWebSocketResponse) => void;
|
|
50
|
-
}>;
|
|
51
|
-
/** @type {Map<string, {reject: (error: unknown) => void, resolve: (value?: void) => void}>} */
|
|
52
|
-
pendingSubscriptions: Map<string, {
|
|
53
|
-
reject: (error: unknown) => void;
|
|
54
|
-
resolve: (value?: void) => void;
|
|
55
|
-
}>;
|
|
56
|
-
/** @type {Map<string, {callbacks: Set<(payload: any) => void>, channel: string, params: Record<string, any> | undefined, ready: Promise<void>}>} */
|
|
57
|
-
listeners: Map<string, {
|
|
58
|
-
callbacks: Set<(payload: any) => void>;
|
|
59
|
-
channel: string;
|
|
60
|
-
params: Record<string, any> | undefined;
|
|
61
|
-
ready: Promise<void>;
|
|
62
|
-
}>;
|
|
63
14
|
/** @type {(value: any) => any} */
|
|
64
15
|
_deserialize: (value: any) => any;
|
|
65
16
|
/** @type {boolean} */
|
|
@@ -130,6 +81,63 @@ export default class SnapReqWebSocketClient {
|
|
|
130
81
|
};
|
|
131
82
|
/** @type {boolean} */
|
|
132
83
|
_waitingForOnline: boolean;
|
|
84
|
+
/** @type {number} - Operations currently depending on the shared in-flight connect. */
|
|
85
|
+
_connectWaiters: number;
|
|
86
|
+
/** @type {WeakSet<object>} - Sockets whose terminal lifecycle has already been processed. */
|
|
87
|
+
_closedSockets: WeakSet<object>;
|
|
88
|
+
socket: WebSocket;
|
|
89
|
+
connectPromise: Promise<any>;
|
|
90
|
+
/** @type {Map<string, {reject: (error: unknown) => void, resolve: (response: SnapReqWebSocketResponse) => void}>} */
|
|
91
|
+
pendingRequests: Map<string, {
|
|
92
|
+
reject: (error: unknown) => void;
|
|
93
|
+
resolve: (response: SnapReqWebSocketResponse) => void;
|
|
94
|
+
}>;
|
|
95
|
+
/** @type {Map<string, {reject: (error: unknown) => void, resolve: (value?: void) => void}>} */
|
|
96
|
+
pendingSubscriptions: Map<string, {
|
|
97
|
+
reject: (error: unknown) => void;
|
|
98
|
+
resolve: (value?: void) => void;
|
|
99
|
+
}>;
|
|
100
|
+
/** @type {Map<string, {callbacks: Set<(payload: any) => void>, channel: string, params: Record<string, any> | undefined, ready: Promise<void>}>} */
|
|
101
|
+
listeners: Map<string, {
|
|
102
|
+
callbacks: Set<(payload: any) => void>;
|
|
103
|
+
channel: string;
|
|
104
|
+
params: Record<string, any> | undefined;
|
|
105
|
+
ready: Promise<void>;
|
|
106
|
+
}>;
|
|
107
|
+
/**
|
|
108
|
+
* @param {object} args - Options object.
|
|
109
|
+
* @param {string} args.url - Full WebSocket URL, e.g. `ws://localhost:3006/websocket`.
|
|
110
|
+
* @param {boolean} [args.autoReconnect] - Enable auto-reconnect with exponential backoff.
|
|
111
|
+
* @param {boolean} [args.debug] - Whether to log debug output.
|
|
112
|
+
* @param {{getIsOnline?: () => boolean | Promise<boolean>, subscribe?: (callback: (isOnline: boolean) => void) => (() => void) | {remove: () => void}}} [args.networkMonitor] - Optional online-state adapter. When provided, auto-reconnect can wait for the network to report online before reconnecting, and open sockets are closed when the monitor reports offline.
|
|
113
|
+
* @param {number[]} [args.reconnectDelays] - Backoff delays in ms (default: [1000, 2000, 4000, 8000, 15000]).
|
|
114
|
+
* @param {{get: () => string | null | undefined | Promise<string | null | undefined>, set: (sessionId: string) => void | Promise<void>, clear: () => void | Promise<void>}} [args.sessionStore] - Optional sessionId persistence hook surviving reloads (localStorage, a cookie, SQLite, etc.).
|
|
115
|
+
* @param {(value: any) => any} [args.deserialize] - Optional transform applied to a response body inside `response.json()`. Lets an app re-hydrate its own wire format. Defaults to identity.
|
|
116
|
+
* @param {typeof globalThis.WebSocket} [args.webSocketImplementation] - WebSocket constructor to use instead of `globalThis.WebSocket`. Inject Node's `ws` here to get real WS ping/pong heartbeats and socket `unref` (the browser/undici global exposes neither).
|
|
117
|
+
* @param {number} [args.heartbeatIntervalMs] - When > 0 and the WebSocket implementation supports `.ping()` (Node `ws`), send a protocol ping every this-many ms and drop the socket if the peer did not pong since the previous ping (so a vanished peer is noticed within ~2× this interval). Default 0 (disabled).
|
|
118
|
+
* @param {boolean} [args.unref] - When the underlying socket exposes `unref()` (Node `ws`), unref it so an idle connection can never keep the process/event loop alive on its own. Best-effort no-op on browser/undici. Default false.
|
|
119
|
+
*/
|
|
120
|
+
constructor({ autoReconnect, debug, deserialize, heartbeatIntervalMs, networkMonitor, reconnectDelays, sessionStore, unref, url, webSocketImplementation }?: {
|
|
121
|
+
url: string;
|
|
122
|
+
autoReconnect?: boolean;
|
|
123
|
+
debug?: boolean;
|
|
124
|
+
networkMonitor?: {
|
|
125
|
+
getIsOnline?: () => boolean | Promise<boolean>;
|
|
126
|
+
subscribe?: (callback: (isOnline: boolean) => void) => (() => void) | {
|
|
127
|
+
remove: () => void;
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
reconnectDelays?: number[];
|
|
131
|
+
sessionStore?: {
|
|
132
|
+
get: () => string | null | undefined | Promise<string | null | undefined>;
|
|
133
|
+
set: (sessionId: string) => void | Promise<void>;
|
|
134
|
+
clear: () => void | Promise<void>;
|
|
135
|
+
};
|
|
136
|
+
deserialize?: (value: any) => any;
|
|
137
|
+
webSocketImplementation?: typeof globalThis.WebSocket;
|
|
138
|
+
heartbeatIntervalMs?: number;
|
|
139
|
+
unref?: boolean;
|
|
140
|
+
});
|
|
133
141
|
/** @returns {boolean} - Whether the socket is open. */
|
|
134
142
|
isOpen(): boolean;
|
|
135
143
|
/** @returns {boolean} - Whether the session is ready for app messages. */
|
|
@@ -138,11 +146,13 @@ export default class SnapReqWebSocketClient {
|
|
|
138
146
|
* Opens a 1:1 connection of the given type against the server. Requires the
|
|
139
147
|
* socket to already be connected (call `connect()` first).
|
|
140
148
|
* @param {string} connectionType - Name the server registered the class under.
|
|
141
|
-
* @param {{params?: Record<string, any>, onConnect?: () => void, onMessage?: (body: any) => void, onDisconnect?: () => void, onResume?: () => void, onClose?: (reason: string) => void}} [options] - Connection options.
|
|
149
|
+
* @param {{params?: Record<string, any>, timeoutMs?: number, signal?: AbortSignal, onConnect?: () => void, onMessage?: (body: any) => void, onDisconnect?: () => void, onResume?: () => void, onClose?: (reason: string) => void}} [options] - Connection options.
|
|
142
150
|
* @returns {SnapReqWebSocketConnection} - The connection handle.
|
|
143
151
|
*/
|
|
144
152
|
openConnection(connectionType: string, options?: {
|
|
145
153
|
params?: Record<string, any>;
|
|
154
|
+
timeoutMs?: number;
|
|
155
|
+
signal?: AbortSignal;
|
|
146
156
|
onConnect?: () => void;
|
|
147
157
|
onMessage?: (body: any) => void;
|
|
148
158
|
onDisconnect?: () => void;
|
|
@@ -159,12 +169,14 @@ export default class SnapReqWebSocketClient {
|
|
|
159
169
|
* Subscribes to a named channel. If the socket is not yet open, the
|
|
160
170
|
* subscription is queued and sent once a connection is established.
|
|
161
171
|
* @param {string} channelType - Name the server registered the channel under.
|
|
162
|
-
* @param {{params?: Record<string, any>, lastEventId?: string, onMessage?: (body: any) => void, onDisconnect?: () => void, onResume?: () => void, onClose?: (reason: string) => void}} [options] - Subscription options.
|
|
172
|
+
* @param {{params?: Record<string, any>, lastEventId?: string, timeoutMs?: number, signal?: AbortSignal, onMessage?: (body: any) => void, onDisconnect?: () => void, onResume?: () => void, onClose?: (reason: string) => void}} [options] - Subscription options.
|
|
163
173
|
* @returns {SnapReqWebSocketChannel} - The subscription handle.
|
|
164
174
|
*/
|
|
165
175
|
subscribeChannel(channelType: string, options?: {
|
|
166
176
|
params?: Record<string, any>;
|
|
167
177
|
lastEventId?: string;
|
|
178
|
+
timeoutMs?: number;
|
|
179
|
+
signal?: AbortSignal;
|
|
168
180
|
onMessage?: (body: any) => void;
|
|
169
181
|
onDisconnect?: () => void;
|
|
170
182
|
onResume?: () => void;
|
|
@@ -203,16 +215,28 @@ export default class SnapReqWebSocketClient {
|
|
|
203
215
|
/**
|
|
204
216
|
* Ensures a WebSocket connection is open. Auto-reconnect and online gating are
|
|
205
217
|
* enabled by default.
|
|
206
|
-
* @param {{autoReconnect?: boolean, waitForOnline?: boolean, resetReconnectState?: boolean}} [options] - Connect options.
|
|
218
|
+
* @param {{autoReconnect?: boolean, waitForOnline?: boolean, resetReconnectState?: boolean, timeoutMs?: number, signal?: AbortSignal}} [options] - Connect options.
|
|
207
219
|
* @returns {Promise<void>} - Resolves once connected and the session is ready.
|
|
208
220
|
*/
|
|
209
|
-
connect({ autoReconnect, waitForOnline, resetReconnectState }?: {
|
|
221
|
+
connect({ autoReconnect, waitForOnline, resetReconnectState, timeoutMs, signal }?: {
|
|
222
|
+
autoReconnect?: boolean;
|
|
223
|
+
waitForOnline?: boolean;
|
|
224
|
+
resetReconnectState?: boolean;
|
|
225
|
+
timeoutMs?: number;
|
|
226
|
+
signal?: AbortSignal;
|
|
227
|
+
}): Promise<void>;
|
|
228
|
+
/**
|
|
229
|
+
* @param {object} [options] - Internal connect options.
|
|
230
|
+
* @param {boolean} [options.autoReconnect] - Whether reconnect remains enabled.
|
|
231
|
+
* @param {boolean} [options.waitForOnline] - Whether to honor the online gate.
|
|
232
|
+
* @param {boolean} [options.resetReconnectState] - Whether to reset backoff state.
|
|
233
|
+
* @returns {Promise<void>} - Opens the socket and waits for session readiness.
|
|
234
|
+
*/
|
|
235
|
+
_connect({ autoReconnect, waitForOnline, resetReconnectState }?: {
|
|
210
236
|
autoReconnect?: boolean;
|
|
211
237
|
waitForOnline?: boolean;
|
|
212
238
|
resetReconnectState?: boolean;
|
|
213
239
|
}): Promise<void>;
|
|
214
|
-
connectPromise: Promise<any>;
|
|
215
|
-
socket: WebSocket;
|
|
216
240
|
/**
|
|
217
241
|
* Closes the WebSocket and clears pending state.
|
|
218
242
|
* @returns {Promise<void>} - Resolves once closed.
|
|
@@ -233,20 +257,24 @@ export default class SnapReqWebSocketClient {
|
|
|
233
257
|
* Performs a POST request over the WebSocket.
|
|
234
258
|
* @param {string} path - Path.
|
|
235
259
|
* @param {any} [body] - Request body.
|
|
236
|
-
* @param {{headers?: Record<string, string
|
|
260
|
+
* @param {{headers?: Record<string, string>, timeoutMs?: number, signal?: AbortSignal}} [options] - Request options such as headers and operation controls.
|
|
237
261
|
* @returns {Promise<SnapReqWebSocketResponse>} - The response.
|
|
238
262
|
*/
|
|
239
263
|
post(path: string, body?: any, options?: {
|
|
240
264
|
headers?: Record<string, string>;
|
|
265
|
+
timeoutMs?: number;
|
|
266
|
+
signal?: AbortSignal;
|
|
241
267
|
}): Promise<SnapReqWebSocketResponse>;
|
|
242
268
|
/**
|
|
243
269
|
* Performs a GET request over the WebSocket.
|
|
244
270
|
* @param {string} path - Path.
|
|
245
|
-
* @param {{headers?: Record<string, string
|
|
271
|
+
* @param {{headers?: Record<string, string>, timeoutMs?: number, signal?: AbortSignal}} [options] - Request options such as headers and operation controls.
|
|
246
272
|
* @returns {Promise<SnapReqWebSocketResponse>} - The response.
|
|
247
273
|
*/
|
|
248
274
|
get(path: string, options?: {
|
|
249
275
|
headers?: Record<string, string>;
|
|
276
|
+
timeoutMs?: number;
|
|
277
|
+
signal?: AbortSignal;
|
|
250
278
|
}): Promise<SnapReqWebSocketResponse>;
|
|
251
279
|
/**
|
|
252
280
|
* Subscribes to a channel for server-sent events.
|
|
@@ -267,26 +295,30 @@ export default class SnapReqWebSocketClient {
|
|
|
267
295
|
/**
|
|
268
296
|
* Subscribes to a channel for server-sent events with optional params.
|
|
269
297
|
* @param {string} channel - Channel name.
|
|
270
|
-
* @param {{lastEventId?: string, params?: Record<string, any
|
|
298
|
+
* @param {{lastEventId?: string, params?: Record<string, any>, timeoutMs?: number, signal?: AbortSignal}} options - Subscription options.
|
|
271
299
|
* @param {(payload: any, message?: Record<string, any>) => void} callback - Callback function.
|
|
272
300
|
* @returns {(() => void) & {ready: Promise<void>}} - Unsubscribe function with readiness promise.
|
|
273
301
|
*/
|
|
274
302
|
subscribe(channel: string, options: {
|
|
275
303
|
lastEventId?: string;
|
|
276
304
|
params?: Record<string, any>;
|
|
305
|
+
timeoutMs?: number;
|
|
306
|
+
signal?: AbortSignal;
|
|
277
307
|
}, callback: (payload: any, message?: Record<string, any>) => void): (() => void) & {
|
|
278
308
|
ready: Promise<void>;
|
|
279
309
|
};
|
|
280
310
|
/**
|
|
281
311
|
* Subscribes to a channel and waits until the server acknowledges it.
|
|
282
312
|
* @param {string} channel - Channel name.
|
|
283
|
-
* @param {{lastEventId?: string, params?: Record<string, any
|
|
313
|
+
* @param {{lastEventId?: string, params?: Record<string, any>, timeoutMs?: number, signal?: AbortSignal}} options - Subscription options.
|
|
284
314
|
* @param {(payload: any, message?: Record<string, any>) => void} callback - Callback function.
|
|
285
315
|
* @returns {Promise<(() => void) & {ready: Promise<void>}>} - Ready unsubscribe handle.
|
|
286
316
|
*/
|
|
287
317
|
subscribeAndWait(channel: string, options: {
|
|
288
318
|
lastEventId?: string;
|
|
289
319
|
params?: Record<string, any>;
|
|
320
|
+
timeoutMs?: number;
|
|
321
|
+
signal?: AbortSignal;
|
|
290
322
|
}, callback: (payload: any, message?: Record<string, any>) => void): Promise<(() => void) & {
|
|
291
323
|
ready: Promise<void>;
|
|
292
324
|
}>;
|
|
@@ -296,11 +328,15 @@ export default class SnapReqWebSocketClient {
|
|
|
296
328
|
* @param {object} [options] - Options object.
|
|
297
329
|
* @param {any} [options.body] - Request body.
|
|
298
330
|
* @param {Record<string, string>} [options.headers] - Header list.
|
|
331
|
+
* @param {number} [options.timeoutMs] - Deadline for connect/session readiness and the response.
|
|
332
|
+
* @param {AbortSignal} [options.signal] - Cancels only this pending request.
|
|
299
333
|
* @returns {Promise<SnapReqWebSocketResponse>} - The response.
|
|
300
334
|
*/
|
|
301
|
-
request(method: string, path: string, { body, headers }?: {
|
|
335
|
+
request(method: string, path: string, { body, headers, timeoutMs, signal }?: {
|
|
302
336
|
body?: any;
|
|
303
337
|
headers?: Record<string, string>;
|
|
338
|
+
timeoutMs?: number;
|
|
339
|
+
signal?: AbortSignal;
|
|
304
340
|
}): Promise<SnapReqWebSocketResponse>;
|
|
305
341
|
/**
|
|
306
342
|
* @param {MessageEvent<any>} event - Event payload.
|
|
@@ -333,7 +369,15 @@ export default class SnapReqWebSocketClient {
|
|
|
333
369
|
* @returns {void}
|
|
334
370
|
*/
|
|
335
371
|
_stopSocketKeepalive(): void;
|
|
336
|
-
|
|
372
|
+
/**
|
|
373
|
+
* Processes one socket's terminal lifecycle exactly once.
|
|
374
|
+
* @param {object} socket - Socket that closed or is being torn down.
|
|
375
|
+
* @param {unknown} [error] - Failure propagated to pending operations.
|
|
376
|
+
* @param {boolean} [allowReconnect] - Whether this close may schedule reconnect.
|
|
377
|
+
* @returns {void}
|
|
378
|
+
*/
|
|
379
|
+
_handleSocketClose(socket: object, error?: unknown, allowReconnect?: boolean): void;
|
|
380
|
+
onClose: (event: any) => void;
|
|
337
381
|
/**
|
|
338
382
|
* @param {Record<string, any>} payload - Payload data.
|
|
339
383
|
* @returns {void}
|
|
@@ -373,12 +417,7 @@ export default class SnapReqWebSocketClient {
|
|
|
373
417
|
_resetSessionReadyState(error?: unknown): void;
|
|
374
418
|
}
|
|
375
419
|
/** A response to a request made over the WebSocket transport. */
|
|
376
|
-
export class SnapReqWebSocketResponse {
|
|
377
|
-
/**
|
|
378
|
-
* @param {object} message - The response message.
|
|
379
|
-
* @param {(value: any) => any} [deserialize] - Transform applied to the parsed body in `json()`. Defaults to identity.
|
|
380
|
-
*/
|
|
381
|
-
constructor(message: object, deserialize?: (value: any) => any);
|
|
420
|
+
export declare class SnapReqWebSocketResponse {
|
|
382
421
|
body: any;
|
|
383
422
|
headers: Record<string, any>;
|
|
384
423
|
id: string | number;
|
|
@@ -386,9 +425,12 @@ export class SnapReqWebSocketResponse {
|
|
|
386
425
|
statusMessage: string;
|
|
387
426
|
type: string;
|
|
388
427
|
_deserialize: (value: any) => any;
|
|
428
|
+
/**
|
|
429
|
+
* @param {object} message - The response message.
|
|
430
|
+
* @param {(value: any) => any} [deserialize] - Transform applied to the parsed body in `json()`. Defaults to identity.
|
|
431
|
+
*/
|
|
432
|
+
constructor(message: object, deserialize?: (value: any) => any);
|
|
389
433
|
/** @returns {any} - The parsed (and optionally deserialized) JSON body. */
|
|
390
434
|
json(): any;
|
|
391
435
|
}
|
|
392
|
-
import SnapReqWebSocketConnection from "./websocket-connection.js";
|
|
393
|
-
import SnapReqWebSocketChannel from "./websocket-channel.js";
|
|
394
436
|
//# sourceMappingURL=websocket-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-client.d.ts","sourceRoot":"","sources":["../../src/websocket/websocket-client.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"websocket-client.d.ts","sourceRoot":"","sources":["../../src/websocket/websocket-client.js"],"names":[],"mappings":"AAEA,OAAO,0BAA0B,MAAM,2BAA2B,CAAA;AAClE,OAAO,uBAAuB,MAAM,wBAAwB,CAAA;AAK5D;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,OAAO,sBAAsB;IA4BvC,kCAAkC;IAC7B,YAAY,EADN,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG;IAE9B,sBAAsB;IACjB,aAAa,EADP,OAAO;IAEb,KAAK;IACV,0CAA0C;IACrC,UAAU,EADJ,OAAO,UAAU,CAAC,SAAS;IAEtC,sBAAsB;IACjB,MAAM,EADA,OAAO;IAElB,4EAA4E;IACvE,oBAAoB,EADd,MAAM;IAEjB,oDAAoD;IAC/C,eAAe,EADT,UAAU,CAAC,OAAO,WAAW,CAAC,GAAG,IAAI;IAEhD,4BAA4B;IACvB,iBAAiB,EADX,MAAM,GAAG,IAAI;IAIxB,qBAAqB;IAChB,gBAAgB,EADV,MAAM;IAEjB,qBAAqB;IAChB,kBAAkB,EADZ,MAAM;IAEjB,uBAAuB;IAClB,eAAe,EADT,MAAM,EAAE;IAEnB,mDAAmD;IAC9C,cAAc,EADR,UAAU,CAAC,OAAO,UAAU,CAAC,GAAG,IAAI;IAE1C,GAAG;IAEH,MAAM;IACX,kDAAkD;IAC7C,WAAW,EADL,CAAC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,IAAI;IAG9C,kCAAkC;IAC7B,SAAS,EADH,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAG9B,sDAAsD;IACjD,YAAY,EADN,GAAG,CAAC,MAAM,EAAE,0BAA0B,CAAC;IAGlD,mDAAmD;IAC9C,qBAAqB,EADf,GAAG,CAAC,MAAM,EAAE,uBAAuB,CA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