@trpc/client 11.0.0-rc.772 → 11.0.0-rc.781

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.
Files changed (51) hide show
  1. package/dist/bundle-analysis.json +132 -39
  2. package/dist/index.js +3 -2
  3. package/dist/index.mjs +2 -1
  4. package/dist/links/wsLink/createWsClient.d.ts +6 -0
  5. package/dist/links/wsLink/createWsClient.d.ts.map +1 -0
  6. package/dist/links/wsLink/createWsClient.js +9 -0
  7. package/dist/links/wsLink/createWsClient.mjs +7 -0
  8. package/dist/links/wsLink/wsClient/options.d.ts +79 -0
  9. package/dist/links/wsLink/wsClient/options.d.ts.map +1 -0
  10. package/dist/links/wsLink/wsClient/options.js +22 -0
  11. package/dist/links/wsLink/wsClient/options.mjs +18 -0
  12. package/dist/links/wsLink/wsClient/requestManager.d.ts +102 -0
  13. package/dist/links/wsLink/wsClient/requestManager.d.ts.map +1 -0
  14. package/dist/links/wsLink/wsClient/requestManager.js +138 -0
  15. package/dist/links/wsLink/wsClient/requestManager.mjs +136 -0
  16. package/dist/links/wsLink/wsClient/utils.d.ts +38 -0
  17. package/dist/links/wsLink/wsClient/utils.d.ts.map +1 -0
  18. package/dist/links/wsLink/wsClient/utils.js +94 -0
  19. package/dist/links/wsLink/wsClient/utils.mjs +88 -0
  20. package/dist/links/wsLink/wsClient/wsClient.d.ts +85 -0
  21. package/dist/links/wsLink/wsClient/wsClient.d.ts.map +1 -0
  22. package/dist/links/wsLink/wsClient/wsClient.js +331 -0
  23. package/dist/links/wsLink/wsClient/wsClient.mjs +329 -0
  24. package/dist/links/wsLink/wsClient/wsConnection.d.ts +79 -0
  25. package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +1 -0
  26. package/dist/links/wsLink/wsClient/wsConnection.js +181 -0
  27. package/dist/links/wsLink/wsClient/wsConnection.mjs +178 -0
  28. package/dist/links/wsLink/wsLink.d.ts +11 -0
  29. package/dist/links/wsLink/wsLink.d.ts.map +1 -0
  30. package/dist/links/wsLink/wsLink.js +35 -0
  31. package/dist/links/wsLink/wsLink.mjs +32 -0
  32. package/dist/links.d.ts +1 -1
  33. package/dist/links.d.ts.map +1 -1
  34. package/links/wsLink/wsLink/index.d.ts +1 -0
  35. package/links/wsLink/wsLink/index.js +1 -0
  36. package/package.json +8 -8
  37. package/src/links/wsLink/createWsClient.ts +10 -0
  38. package/src/links/wsLink/wsClient/options.ts +91 -0
  39. package/src/links/wsLink/wsClient/requestManager.ts +174 -0
  40. package/src/links/wsLink/wsClient/utils.ts +94 -0
  41. package/src/links/wsLink/wsClient/wsClient.ts +441 -0
  42. package/src/links/wsLink/wsClient/wsConnection.ts +230 -0
  43. package/src/links/wsLink/wsLink.ts +55 -0
  44. package/src/links.ts +1 -1
  45. package/dist/links/wsLink.d.ts +0 -125
  46. package/dist/links/wsLink.d.ts.map +0 -1
  47. package/dist/links/wsLink.js +0 -498
  48. package/dist/links/wsLink.mjs +0 -495
  49. package/links/wsLink/index.d.ts +0 -1
  50. package/links/wsLink/index.js +0 -1
  51. package/src/links/wsLink.ts +0 -737
@@ -1,20 +1,21 @@
1
1
  {
2
- "bundleSize": 66332,
3
- "bundleOrigSize": 83397,
4
- "bundleReduction": 20.46,
2
+ "bundleSize": 75600,
3
+ "bundleOrigSize": 94551,
4
+ "bundleReduction": 20.04,
5
5
  "modules": [
6
6
  {
7
- "id": "/src/links/wsLink.ts",
8
- "size": 18016,
9
- "origSize": 20084,
7
+ "id": "/src/links/wsLink/wsClient/wsClient.ts",
8
+ "size": 12353,
9
+ "origSize": 12459,
10
10
  "renderedExports": [
11
- "createWSClient",
12
- "wsLink"
11
+ "WsClient"
13
12
  ],
14
13
  "removedExports": [],
15
- "dependents": [],
16
- "percent": 27.16,
17
- "reduction": 10.3
14
+ "dependents": [
15
+ "/src/links/wsLink/createWsClient.ts"
16
+ ],
17
+ "percent": 16.34,
18
+ "reduction": 0.85
18
19
  },
19
20
  {
20
21
  "id": "/src/links/httpSubscriptionLink.ts",
@@ -25,7 +26,7 @@
25
26
  ],
26
27
  "removedExports": [],
27
28
  "dependents": [],
28
- "percent": 12.01,
29
+ "percent": 10.54,
29
30
  "reduction": 0
30
31
  },
31
32
  {
@@ -37,9 +38,24 @@
37
38
  ],
38
39
  "removedExports": [],
39
40
  "dependents": [],
40
- "percent": 9.07,
41
+ "percent": 7.96,
41
42
  "reduction": 4.42
42
43
  },
44
+ {
45
+ "id": "/src/links/wsLink/wsClient/wsConnection.ts",
46
+ "size": 5861,
47
+ "origSize": 6218,
48
+ "renderedExports": [
49
+ "WsConnection",
50
+ "backwardCompatibility"
51
+ ],
52
+ "removedExports": [],
53
+ "dependents": [
54
+ "/src/links/wsLink/wsClient/wsClient.ts"
55
+ ],
56
+ "percent": 7.75,
57
+ "reduction": 5.74
58
+ },
43
59
  {
44
60
  "id": "/src/links/loggerLink.ts",
45
61
  "size": 5596,
@@ -49,9 +65,23 @@
49
65
  ],
50
66
  "removedExports": [],
51
67
  "dependents": [],
52
- "percent": 8.44,
68
+ "percent": 7.4,
53
69
  "reduction": 19.44
54
70
  },
71
+ {
72
+ "id": "/src/links/wsLink/wsClient/requestManager.ts",
73
+ "size": 4792,
74
+ "origSize": 5216,
75
+ "renderedExports": [
76
+ "RequestManager"
77
+ ],
78
+ "removedExports": [],
79
+ "dependents": [
80
+ "/src/links/wsLink/wsClient/wsClient.ts"
81
+ ],
82
+ "percent": 6.34,
83
+ "reduction": 8.13
84
+ },
55
85
  {
56
86
  "id": "/src/internals/dataLoader.ts",
57
87
  "size": 4084,
@@ -64,7 +94,7 @@
64
94
  "/src/links/httpBatchLink.ts",
65
95
  "/src/links/httpBatchStreamLink.ts"
66
96
  ],
67
- "percent": 6.16,
97
+ "percent": 5.4,
68
98
  "reduction": 5.64
69
99
  },
70
100
  {
@@ -76,7 +106,7 @@
76
106
  ],
77
107
  "removedExports": [],
78
108
  "dependents": [],
79
- "percent": 5.94,
109
+ "percent": 5.21,
80
110
  "reduction": 5.59
81
111
  },
82
112
  {
@@ -94,12 +124,12 @@
94
124
  ],
95
125
  "removedExports": [],
96
126
  "dependents": [
97
- "/src/links/httpLink.ts",
98
127
  "/src/links/httpBatchLink.ts",
128
+ "/src/links/httpLink.ts",
99
129
  "/src/links/httpBatchStreamLink.ts",
100
130
  "/src/links/httpSubscriptionLink.ts"
101
131
  ],
102
- "percent": 5.57,
132
+ "percent": 4.88,
103
133
  "reduction": 37.14
104
134
  },
105
135
  {
@@ -111,7 +141,7 @@
111
141
  ],
112
142
  "removedExports": [],
113
143
  "dependents": [],
114
- "percent": 4.96,
144
+ "percent": 4.35,
115
145
  "reduction": 12.56
116
146
  },
117
147
  {
@@ -126,7 +156,7 @@
126
156
  "/src/createTRPCUntypedClient.ts",
127
157
  "/src/createTRPCClient.ts"
128
158
  ],
129
- "percent": 4.76,
159
+ "percent": 4.18,
130
160
  "reduction": 31.02
131
161
  },
132
162
  {
@@ -139,16 +169,36 @@
139
169
  "removedExports": [],
140
170
  "dependents": [
141
171
  "/src/index.ts",
142
- "/src/links/httpLink.ts",
143
172
  "/src/links/httpBatchLink.ts",
144
- "/src/links/wsLink.ts",
173
+ "/src/links/httpLink.ts",
145
174
  "/src/links/httpBatchStreamLink.ts",
146
175
  "/src/links/httpSubscriptionLink.ts",
147
- "/src/internals/TRPCUntypedClient.ts"
176
+ "/src/internals/TRPCUntypedClient.ts",
177
+ "/src/links/wsLink/wsClient/wsClient.ts"
148
178
  ],
149
- "percent": 4.2,
179
+ "percent": 3.69,
150
180
  "reduction": 21.8
151
181
  },
182
+ {
183
+ "id": "/src/links/wsLink/wsClient/utils.ts",
184
+ "size": 2781,
185
+ "origSize": 2794,
186
+ "renderedExports": [
187
+ "TRPCWebSocketClosedError",
188
+ "ResettableTimeout",
189
+ "withResolvers",
190
+ "prepareUrl",
191
+ "buildConnectionMessage"
192
+ ],
193
+ "removedExports": [],
194
+ "dependents": [
195
+ "/src/links/wsLink/wsClient/wsClient.ts",
196
+ "/src/links/wsLink/wsClient/requestManager.ts",
197
+ "/src/links/wsLink/wsClient/wsConnection.ts"
198
+ ],
199
+ "percent": 3.68,
200
+ "reduction": 0.47
201
+ },
152
202
  {
153
203
  "id": "/src/links/retryLink.ts",
154
204
  "size": 2194,
@@ -158,7 +208,7 @@
158
208
  ],
159
209
  "removedExports": [],
160
210
  "dependents": [],
161
- "percent": 3.31,
211
+ "percent": 2.9,
162
212
  "reduction": 18.8
163
213
  },
164
214
  {
@@ -175,7 +225,7 @@
175
225
  "/src/links/httpBatchStreamLink.ts",
176
226
  "/src/links/httpSubscriptionLink.ts"
177
227
  ],
178
- "percent": 1.79,
228
+ "percent": 1.57,
179
229
  "reduction": 3.88
180
230
  },
181
231
  {
@@ -192,9 +242,22 @@
192
242
  "dependents": [
193
243
  "/src/index.ts"
194
244
  ],
195
- "percent": 1.79,
245
+ "percent": 1.57,
196
246
  "reduction": 74.76
197
247
  },
248
+ {
249
+ "id": "/src/links/wsLink/wsLink.ts",
250
+ "size": 939,
251
+ "origSize": 1600,
252
+ "renderedExports": [
253
+ "wsLink",
254
+ "createWSClient"
255
+ ],
256
+ "removedExports": [],
257
+ "dependents": [],
258
+ "percent": 1.24,
259
+ "reduction": 41.31
260
+ },
198
261
  {
199
262
  "id": "/src/links/internals/createChain.ts",
200
263
  "size": 690,
@@ -207,7 +270,7 @@
207
270
  "/src/links/splitLink.ts",
208
271
  "/src/internals/TRPCUntypedClient.ts"
209
272
  ],
210
- "percent": 1.04,
273
+ "percent": 0.91,
211
274
  "reduction": 32.75
212
275
  },
213
276
  {
@@ -219,7 +282,7 @@
219
282
  ],
220
283
  "removedExports": [],
221
284
  "dependents": [],
222
- "percent": 0.92,
285
+ "percent": 0.81,
223
286
  "reduction": 44.95
224
287
  },
225
288
  {
@@ -233,9 +296,25 @@
233
296
  "dependents": [
234
297
  "/src/unstable-internals.ts"
235
298
  ],
236
- "percent": 0.85,
299
+ "percent": 0.75,
237
300
  "reduction": 66.71
238
301
  },
302
+ {
303
+ "id": "/src/links/wsLink/wsClient/options.ts",
304
+ "size": 485,
305
+ "origSize": 2636,
306
+ "renderedExports": [
307
+ "lazyDefaults",
308
+ "keepAliveDefaults",
309
+ "exponentialBackoff"
310
+ ],
311
+ "removedExports": [],
312
+ "dependents": [
313
+ "/src/links/wsLink/wsClient/wsClient.ts"
314
+ ],
315
+ "percent": 0.64,
316
+ "reduction": 81.6
317
+ },
239
318
  {
240
319
  "id": "/src/getFetch.ts",
241
320
  "size": 428,
@@ -248,7 +327,7 @@
248
327
  "/src/index.ts",
249
328
  "/src/links/internals/httpUtils.ts"
250
329
  ],
251
- "percent": 0.65,
330
+ "percent": 0.57,
252
331
  "reduction": 33.54
253
332
  },
254
333
  {
@@ -262,7 +341,7 @@
262
341
  ],
263
342
  "removedExports": [],
264
343
  "dependents": [],
265
- "percent": 0.5,
344
+ "percent": 0.44,
266
345
  "reduction": 15.17
267
346
  },
268
347
  {
@@ -277,7 +356,7 @@
277
356
  "/src/links/httpSubscriptionLink.ts",
278
357
  "/src/links/retryLink.ts"
279
358
  ],
280
- "percent": 0.38,
359
+ "percent": 0.34,
281
360
  "reduction": 6.96
282
361
  },
283
362
  {
@@ -289,10 +368,10 @@
289
368
  ],
290
369
  "removedExports": [],
291
370
  "dependents": [
292
- "/src/links/wsLink.ts",
293
- "/src/links/httpSubscriptionLink.ts"
371
+ "/src/links/httpSubscriptionLink.ts",
372
+ "/src/links/wsLink/wsClient/utils.ts"
294
373
  ],
295
- "percent": 0.36,
374
+ "percent": 0.32,
296
375
  "reduction": 76.38
297
376
  },
298
377
  {
@@ -306,9 +385,23 @@
306
385
  "dependents": [
307
386
  "/src/index.ts"
308
387
  ],
309
- "percent": 0.15,
388
+ "percent": 0.13,
310
389
  "reduction": 82.58
311
390
  },
391
+ {
392
+ "id": "/src/links/wsLink/createWsClient.ts",
393
+ "size": 73,
394
+ "origSize": 315,
395
+ "renderedExports": [
396
+ "createWSClient"
397
+ ],
398
+ "removedExports": [],
399
+ "dependents": [
400
+ "/src/links/wsLink/wsLink.ts"
401
+ ],
402
+ "percent": 0.1,
403
+ "reduction": 76.83
404
+ },
312
405
  {
313
406
  "id": "/src/index.ts",
314
407
  "size": 0,
@@ -326,7 +419,7 @@
326
419
  "renderedExports": [],
327
420
  "removedExports": [],
328
421
  "dependents": [
329
- "/src/links/wsLink.ts",
422
+ "/src/links/wsLink/wsLink.ts",
330
423
  "/src/links/httpSubscriptionLink.ts",
331
424
  "/src/links/internals/httpUtils.ts"
332
425
  ],
@@ -334,5 +427,5 @@
334
427
  "reduction": 100
335
428
  }
336
429
  ],
337
- "moduleCount": 23
430
+ "moduleCount": 29
338
431
  }
package/dist/index.js CHANGED
@@ -10,10 +10,11 @@ var httpBatchStreamLink = require('./links/httpBatchStreamLink.js');
10
10
  var httpLink = require('./links/httpLink.js');
11
11
  var loggerLink = require('./links/loggerLink.js');
12
12
  var splitLink = require('./links/splitLink.js');
13
- var wsLink = require('./links/wsLink.js');
13
+ var wsLink = require('./links/wsLink/wsLink.js');
14
14
  var httpSubscriptionLink = require('./links/httpSubscriptionLink.js');
15
15
  var retryLink = require('./links/retryLink.js');
16
16
  var TRPCUntypedClient = require('./internals/TRPCUntypedClient.js');
17
+ var createWsClient = require('./links/wsLink/createWsClient.js');
17
18
 
18
19
 
19
20
 
@@ -33,8 +34,8 @@ exports.unstable_httpBatchStreamLink = httpBatchStreamLink.unstable_httpBatchStr
33
34
  exports.httpLink = httpLink.httpLink;
34
35
  exports.loggerLink = loggerLink.loggerLink;
35
36
  exports.splitLink = splitLink.splitLink;
36
- exports.createWSClient = wsLink.createWSClient;
37
37
  exports.wsLink = wsLink.wsLink;
38
38
  exports.unstable_httpSubscriptionLink = httpSubscriptionLink.unstable_httpSubscriptionLink;
39
39
  exports.retryLink = retryLink.retryLink;
40
40
  exports.TRPCUntypedClient = TRPCUntypedClient.TRPCUntypedClient;
41
+ exports.createWSClient = createWsClient.createWSClient;
package/dist/index.mjs CHANGED
@@ -8,7 +8,8 @@ export { unstable_httpBatchStreamLink } from './links/httpBatchStreamLink.mjs';
8
8
  export { httpLink } from './links/httpLink.mjs';
9
9
  export { loggerLink } from './links/loggerLink.mjs';
10
10
  export { splitLink } from './links/splitLink.mjs';
11
- export { createWSClient, wsLink } from './links/wsLink.mjs';
11
+ export { wsLink } from './links/wsLink/wsLink.mjs';
12
12
  export { unstable_httpSubscriptionLink } from './links/httpSubscriptionLink.mjs';
13
13
  export { retryLink } from './links/retryLink.mjs';
14
14
  export { TRPCUntypedClient } from './internals/TRPCUntypedClient.mjs';
15
+ export { createWSClient } from './links/wsLink/createWsClient.mjs';
@@ -0,0 +1,6 @@
1
+ import type { WebSocketClientOptions } from './wsClient/options';
2
+ import { WsClient } from './wsClient/wsClient';
3
+ export declare function createWSClient(opts: WebSocketClientOptions): WsClient;
4
+ export type TRPCWebSocketClient = ReturnType<typeof createWSClient>;
5
+ export { WebSocketClientOptions };
6
+ //# sourceMappingURL=createWsClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createWsClient.d.ts","sourceRoot":"","sources":["../../../src/links/wsLink/createWsClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,wBAAgB,cAAc,CAAC,IAAI,EAAE,sBAAsB,YAE1D;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAEpE,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ var wsClient = require('./wsClient/wsClient.js');
4
+
5
+ function createWSClient(opts) {
6
+ return new wsClient.WsClient(opts);
7
+ }
8
+
9
+ exports.createWSClient = createWSClient;
@@ -0,0 +1,7 @@
1
+ import { WsClient } from './wsClient/wsClient.mjs';
2
+
3
+ function createWSClient(opts) {
4
+ return new WsClient(opts);
5
+ }
6
+
7
+ export { createWSClient };
@@ -0,0 +1,79 @@
1
+ import type { UrlOptionsWithConnectionParams } from '../../internals/urlWithConnectionParams';
2
+ export interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
3
+ /**
4
+ * Ponyfill which WebSocket implementation to use
5
+ */
6
+ WebSocket?: typeof WebSocket;
7
+ /**
8
+ * The number of milliseconds before a reconnect is attempted.
9
+ * @default {@link exponentialBackoff}
10
+ */
11
+ retryDelayMs?: (attemptIndex: number) => number;
12
+ /**
13
+ * Triggered when a WebSocket connection is established
14
+ */
15
+ onOpen?: () => void;
16
+ /**
17
+ * Triggered when a WebSocket connection encounters an error
18
+ */
19
+ onError?: (evt?: Event) => void;
20
+ /**
21
+ * Triggered when a WebSocket connection is closed
22
+ */
23
+ onClose?: (cause?: {
24
+ code?: number;
25
+ }) => void;
26
+ /**
27
+ * Lazy mode will close the WebSocket automatically after a period of inactivity (no messages sent or received and no pending requests)
28
+ */
29
+ lazy?: {
30
+ /**
31
+ * Enable lazy mode
32
+ * @default false
33
+ */
34
+ enabled: boolean;
35
+ /**
36
+ * Close the WebSocket after this many milliseconds
37
+ * @default 0
38
+ */
39
+ closeMs: number;
40
+ };
41
+ /**
42
+ * Send ping messages to the server and kill the connection if no pong message is returned
43
+ */
44
+ keepAlive?: {
45
+ /**
46
+ * @default false
47
+ */
48
+ enabled: boolean;
49
+ /**
50
+ * Send a ping message every this many milliseconds
51
+ * @default 5_000
52
+ */
53
+ intervalMs?: number;
54
+ /**
55
+ * Close the WebSocket after this many milliseconds if the server does not respond
56
+ * @default 1_000
57
+ */
58
+ pongTimeoutMs?: number;
59
+ };
60
+ }
61
+ /**
62
+ * Default options for lazy WebSocket connections.
63
+ * Determines whether the connection should be established lazily and defines the delay before closure.
64
+ */
65
+ export type LazyOptions = Required<NonNullable<WebSocketClientOptions['lazy']>>;
66
+ export declare const lazyDefaults: LazyOptions;
67
+ /**
68
+ * Default options for the WebSocket keep-alive mechanism.
69
+ * Configures whether keep-alive is enabled and specifies the timeout and interval for ping-pong messages.
70
+ */
71
+ export type KeepAliveOptions = Required<NonNullable<WebSocketClientOptions['keepAlive']>>;
72
+ export declare const keepAliveDefaults: KeepAliveOptions;
73
+ /**
74
+ * Calculates a delay for exponential backoff based on the retry attempt index.
75
+ * The delay starts at 0 for the first attempt and doubles for each subsequent attempt,
76
+ * capped at 30 seconds.
77
+ */
78
+ export declare const exponentialBackoff: (attemptIndex: number) => number;
79
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../src/links/wsLink/wsClient/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAE9F,MAAM,WAAW,sBAAuB,SAAQ,8BAA8B;IAC5E;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;IAC7B;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IAChD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,IAAI,CAAC,EAAE;QACL;;;WAGG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF;;OAEG;IACH,SAAS,CAAC,EAAE;QACV;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB;;;WAGG;QACH,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAChF,eAAO,MAAM,YAAY,EAAE,WAG1B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,WAAW,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC,CACjD,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,gBAI/B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,iBAAkB,MAAM,WAEtD,CAAC"}
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const lazyDefaults = {
4
+ enabled: false,
5
+ closeMs: 0
6
+ };
7
+ const keepAliveDefaults = {
8
+ enabled: false,
9
+ pongTimeoutMs: 1000,
10
+ intervalMs: 5000
11
+ };
12
+ /**
13
+ * Calculates a delay for exponential backoff based on the retry attempt index.
14
+ * The delay starts at 0 for the first attempt and doubles for each subsequent attempt,
15
+ * capped at 30 seconds.
16
+ */ const exponentialBackoff = (attemptIndex)=>{
17
+ return attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
18
+ };
19
+
20
+ exports.exponentialBackoff = exponentialBackoff;
21
+ exports.keepAliveDefaults = keepAliveDefaults;
22
+ exports.lazyDefaults = lazyDefaults;
@@ -0,0 +1,18 @@
1
+ const lazyDefaults = {
2
+ enabled: false,
3
+ closeMs: 0
4
+ };
5
+ const keepAliveDefaults = {
6
+ enabled: false,
7
+ pongTimeoutMs: 1000,
8
+ intervalMs: 5000
9
+ };
10
+ /**
11
+ * Calculates a delay for exponential backoff based on the retry attempt index.
12
+ * The delay starts at 0 for the first attempt and doubles for each subsequent attempt,
13
+ * capped at 30 seconds.
14
+ */ const exponentialBackoff = (attemptIndex)=>{
15
+ return attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
16
+ };
17
+
18
+ export { exponentialBackoff, keepAliveDefaults, lazyDefaults };
@@ -0,0 +1,102 @@
1
+ import type { AnyTRPCRouter, inferRouterError } from '@trpc/server';
2
+ import type { Observer } from '@trpc/server/observable';
3
+ import type { TRPCClientOutgoingMessage, TRPCResponseMessage } from '@trpc/server/unstable-core-do-not-import';
4
+ import type { TRPCClientError } from '../../../TRPCClientError';
5
+ export type TCallbacks = Observer<TRPCResponseMessage<unknown, inferRouterError<AnyTRPCRouter>>, TRPCClientError<AnyTRPCRouter>>;
6
+ type MessageId = string;
7
+ type MessageIdLike = string | number | null;
8
+ /**
9
+ * Represents a WebSocket request managed by the RequestManager.
10
+ * Combines the network message, a utility promise (`end`) that mirrors the lifecycle
11
+ * handled by `callbacks`, and a set of state monitoring callbacks.
12
+ */
13
+ interface Request {
14
+ message: TRPCClientOutgoingMessage;
15
+ end: Promise<void>;
16
+ callbacks: TCallbacks;
17
+ }
18
+ /**
19
+ * Manages WebSocket requests, tracking their lifecycle and providing utility methods
20
+ * for handling outgoing and pending requests.
21
+ *
22
+ * - **Outgoing requests**: Requests that are queued and waiting to be sent.
23
+ * - **Pending requests**: Requests that have been sent and are in flight awaiting a response.
24
+ * For subscriptions, multiple responses may be received until the subscription is closed.
25
+ */
26
+ export declare class RequestManager {
27
+ /**
28
+ * Stores requests that are outgoing, meaning they are registered but not yet sent over the WebSocket.
29
+ */
30
+ private outgoingRequests;
31
+ /**
32
+ * Stores requests that are pending (in flight), meaning they have been sent over the WebSocket
33
+ * and are awaiting responses. For subscriptions, this includes requests
34
+ * that may receive multiple responses.
35
+ */
36
+ private pendingRequests;
37
+ /**
38
+ * Registers a new request by adding it to the outgoing queue and setting up
39
+ * callbacks for lifecycle events such as completion or error.
40
+ *
41
+ * @param message - The outgoing message to be sent.
42
+ * @param callbacks - Callback functions to observe the request's state.
43
+ * @returns A cleanup function to manually remove the request.
44
+ */
45
+ register(message: TRPCClientOutgoingMessage, callbacks: TCallbacks): () => void;
46
+ /**
47
+ * Deletes a request from both the outgoing and pending collections, if it exists.
48
+ */
49
+ delete(messageId: MessageIdLike): void;
50
+ /**
51
+ * Moves all outgoing requests to the pending state and clears the outgoing queue.
52
+ *
53
+ * The caller is expected to handle the actual sending of the requests
54
+ * (e.g., sending them over the network) after this method is called.
55
+ *
56
+ * @returns The list of requests that were transitioned to the pending state.
57
+ */
58
+ flush(): (Request & {
59
+ id: MessageId;
60
+ })[];
61
+ /**
62
+ * Retrieves all currently pending requests, which are in flight awaiting responses
63
+ * or handling ongoing subscriptions.
64
+ */
65
+ getPendingRequests(): Request[];
66
+ /**
67
+ * Retrieves a specific pending request by its message ID.
68
+ */
69
+ getPendingRequest(messageId: MessageIdLike): Request | null | undefined;
70
+ /**
71
+ * Retrieves all outgoing requests, which are waiting to be sent.
72
+ */
73
+ getOutgoingRequests(): (Request & {
74
+ id: MessageId;
75
+ })[];
76
+ /**
77
+ * Retrieves all requests, both outgoing and pending, with their respective states.
78
+ *
79
+ * @returns An array of all requests with their state ("outgoing" or "pending").
80
+ */
81
+ getRequests(): ({
82
+ state: "outgoing";
83
+ message: TRPCClientOutgoingMessage;
84
+ end: Promise<void>;
85
+ callbacks: TCallbacks;
86
+ } | {
87
+ state: "pending";
88
+ message: TRPCClientOutgoingMessage;
89
+ end: Promise<void>;
90
+ callbacks: TCallbacks;
91
+ })[];
92
+ /**
93
+ * Checks if there are any pending requests, including ongoing subscriptions.
94
+ */
95
+ hasPendingRequests(): boolean;
96
+ /**
97
+ * Checks if there are any outgoing requests waiting to be sent.
98
+ */
99
+ hasOutgoingRequests(): boolean;
100
+ }
101
+ export {};
102
+ //# sourceMappingURL=requestManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestManager.d.ts","sourceRoot":"","sources":["../../../../src/links/wsLink/wsClient/requestManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE,MAAM,MAAM,UAAU,GAAG,QAAQ,CAC/B,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC,EAC7D,eAAe,CAAC,aAAa,CAAC,CAC/B,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,CAAC;AACxB,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE5C;;;;GAIG;AACH,UAAU,OAAO;IACf,OAAO,EAAE,yBAAyB,CAAC;IACnC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAA4C;IAEpE;;;;OAIG;IACH,OAAO,CAAC,eAAe,CAAkC;IAEzD;;;;;;;OAOG;IACI,QAAQ,CAAC,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,UAAU;IA2BzE;;OAEG;IACI,MAAM,CAAC,SAAS,EAAE,aAAa;IAStC;;;;;;;OAOG;IACI,KAAK;YAhEyC,SAAS;;IA0E9D;;;OAGG;IACI,kBAAkB;IAIzB;;OAEG;IACI,iBAAiB,CAAC,SAAS,EAAE,aAAa;IAMjD;;OAEG;IACI,mBAAmB;YA9F2B,SAAS;;IAkG9D;;;;OAIG;IACI,WAAW;;;;;;;;;;;IAiBlB;;OAEG;IACI,kBAAkB;IAIzB;;OAEG;IACI,mBAAmB;CAG3B"}