@trpc/client 11.4.0 → 11.4.2-canary.1
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/dist/TRPCClientError-CjKyS10w.mjs +47 -0
- package/dist/{TRPCClientError-COkhCKf3.mjs.map → TRPCClientError-CjKyS10w.mjs.map} +1 -1
- package/dist/{TRPCClientError-CGgRtttT.cjs → TRPCClientError-Dey88Uiy.cjs} +15 -24
- package/dist/{httpBatchLink-DIfnmmcu.mjs → httpBatchLink-BfUVex5U.mjs} +33 -24
- package/dist/{httpBatchLink-DIfnmmcu.mjs.map → httpBatchLink-BfUVex5U.mjs.map} +1 -1
- package/dist/{httpBatchLink-CIC9PZ_Z.cjs → httpBatchLink-JKXaA6dG.cjs} +32 -23
- package/dist/{httpBatchLink.d-BN2Iw_cK.d.mts → httpBatchLink.d-CAaMQOtX.d.mts} +3 -3
- package/dist/{httpBatchLink.d-BN2Iw_cK.d.mts.map → httpBatchLink.d-CAaMQOtX.d.mts.map} +1 -1
- package/dist/{httpLink-BbVj_TgM.cjs → httpLink-CbZZVG--.cjs} +10 -11
- package/dist/{httpLink-9bpwQ15c.mjs → httpLink-Dptv1zSJ.mjs} +11 -12
- package/dist/{httpLink-9bpwQ15c.mjs.map → httpLink-Dptv1zSJ.mjs.map} +1 -1
- package/dist/{httpLink.d-CTSOARfE.d.mts → httpLink.d-B0nHKy2W.d.mts} +3 -3
- package/dist/{httpLink.d-CTSOARfE.d.mts.map → httpLink.d-B0nHKy2W.d.mts.map} +1 -1
- package/dist/{httpUtils-3pbQzhUL.mjs → httpUtils-ZiawzpnD.mjs} +12 -13
- package/dist/{httpUtils-3pbQzhUL.mjs.map → httpUtils-ZiawzpnD.mjs.map} +1 -1
- package/dist/{httpUtils-Buf6jCgh.cjs → httpUtils-rn2lxsJO.cjs} +12 -12
- package/dist/{httpUtils.d-C8wPxU79.d.mts → httpUtils.d-cQRQZrfo.d.mts} +3 -3
- package/dist/{httpUtils.d-C8wPxU79.d.mts.map → httpUtils.d-cQRQZrfo.d.mts.map} +1 -1
- package/dist/index.cjs +268 -104
- package/dist/index.d.mts +9 -9
- package/dist/index.mjs +269 -131
- package/dist/index.mjs.map +1 -1
- package/dist/links/httpBatchLink.cjs +5 -4
- package/dist/links/httpBatchLink.d.mts +5 -5
- package/dist/links/httpBatchLink.mjs +5 -4
- package/dist/links/httpLink.cjs +5 -4
- package/dist/links/httpLink.d.mts +5 -5
- package/dist/links/httpLink.mjs +5 -4
- package/dist/links/loggerLink.cjs +2 -1
- package/dist/links/loggerLink.d.mts +3 -3
- package/dist/links/loggerLink.mjs +2 -1
- package/dist/links/splitLink.d.mts +3 -3
- package/dist/links/splitLink.mjs +1 -1
- package/dist/links/wsLink/wsLink.cjs +4 -3
- package/dist/links/wsLink/wsLink.d.mts +4 -4
- package/dist/links/wsLink/wsLink.mjs +4 -3
- package/dist/{loggerLink-CsDfg5Bb.cjs → loggerLink-CuYvRzyH.cjs} +14 -21
- package/dist/{loggerLink-PGBSQFcR.mjs → loggerLink-ineCN1PO.mjs} +15 -22
- package/dist/{loggerLink-PGBSQFcR.mjs.map → loggerLink-ineCN1PO.mjs.map} +1 -1
- package/dist/{loggerLink.d-CZjK1CXm.d.mts → loggerLink.d-g_uYSbus.d.mts} +2 -2
- package/dist/{loggerLink.d-CZjK1CXm.d.mts.map → loggerLink.d-g_uYSbus.d.mts.map} +1 -1
- package/dist/objectSpread2-Bsvh_OqM.cjs +100 -0
- package/dist/objectSpread2-BvkFp-_Y.mjs +114 -0
- package/dist/objectSpread2-BvkFp-_Y.mjs.map +1 -0
- package/dist/{splitLink-BVblHq4n.mjs → splitLink-B7Cuf2c_.mjs} +1 -1
- package/dist/{splitLink-BVblHq4n.mjs.map → splitLink-B7Cuf2c_.mjs.map} +1 -1
- package/dist/{splitLink.d-BAqgq0NG.d.mts → splitLink.d-od8YIcex.d.mts} +2 -2
- package/dist/{splitLink.d-BAqgq0NG.d.mts.map → splitLink.d-od8YIcex.d.mts.map} +1 -1
- package/dist/{subscriptions.d-U92STdZl.d.mts → subscriptions.d-Dlr1nWGD.d.mts} +1 -1
- package/dist/{subscriptions.d-U92STdZl.d.mts.map → subscriptions.d-Dlr1nWGD.d.mts.map} +1 -1
- package/dist/{types.d-DXbqQLCC.d.mts → types.d-POgEdUB1.d.mts} +2 -2
- package/dist/{types.d-DXbqQLCC.d.mts.map → types.d-POgEdUB1.d.mts.map} +1 -1
- package/dist/{unstable-internals-DU4WecoG.mjs → unstable-internals-Bg7n9BBj.mjs} +1 -1
- package/dist/{unstable-internals-DU4WecoG.mjs.map → unstable-internals-Bg7n9BBj.mjs.map} +1 -1
- package/dist/unstable-internals.cjs +1 -1
- package/dist/{unstable-internals.d-DyLd-B0J.d.mts → unstable-internals.d-BOmV7EK1.d.mts} +1 -1
- package/dist/{unstable-internals.d-DyLd-B0J.d.mts.map → unstable-internals.d-BOmV7EK1.d.mts.map} +1 -1
- package/dist/unstable-internals.d.mts +2 -2
- package/dist/unstable-internals.mjs +1 -1
- package/dist/{wsLink-DhJ50EC5.cjs → wsLink-BcTLPVgc.cjs} +93 -106
- package/dist/{wsLink-DbSHOzlB.mjs → wsLink-H5IjZfJW.mjs} +94 -107
- package/dist/wsLink-H5IjZfJW.mjs.map +1 -0
- package/dist/{wsLink.d-BqO7ltN_.d.mts → wsLink.d-BZxAJRBO.d.mts} +4 -4
- package/dist/{wsLink.d-BqO7ltN_.d.mts.map → wsLink.d-BZxAJRBO.d.mts.map} +1 -1
- package/package.json +32 -32
- package/dist/TRPCClientError-COkhCKf3.mjs +0 -56
- package/dist/wsLink-DbSHOzlB.mjs.map +0 -1
- /package/dist/{unstable-internals-CYBH4jbF.cjs → unstable-internals-M84gUQCV.cjs} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_chunk = require('./chunk-DWy1uDak.cjs');
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_objectSpread2$1 = require('./objectSpread2-Bsvh_OqM.cjs');
|
|
3
|
+
const require_TRPCClientError = require('./TRPCClientError-Dey88Uiy.cjs');
|
|
4
|
+
const require_unstable_internals = require('./unstable-internals-M84gUQCV.cjs');
|
|
4
5
|
const __trpc_server_observable = require_chunk.__toESM(require("@trpc/server/observable"));
|
|
5
6
|
const __trpc_server_unstable_core_do_not_import = require_chunk.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
6
7
|
|
|
@@ -35,6 +36,7 @@ const resultOf = (value, ...args) => {
|
|
|
35
36
|
|
|
36
37
|
//#endregion
|
|
37
38
|
//#region src/links/wsLink/wsClient/utils.ts
|
|
39
|
+
var import_defineProperty$3 = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
38
40
|
var TRPCWebSocketClosedError = class TRPCWebSocketClosedError extends Error {
|
|
39
41
|
constructor(opts) {
|
|
40
42
|
super(opts.message, { cause: opts.cause });
|
|
@@ -47,10 +49,10 @@ var TRPCWebSocketClosedError = class TRPCWebSocketClosedError extends Error {
|
|
|
47
49
|
* Useful for scenarios where the timeout duration is reset dynamically based on events.
|
|
48
50
|
*/
|
|
49
51
|
var ResettableTimeout = class {
|
|
50
|
-
timeout;
|
|
51
52
|
constructor(onTimeout, timeoutMs) {
|
|
52
53
|
this.onTimeout = onTimeout;
|
|
53
54
|
this.timeoutMs = timeoutMs;
|
|
55
|
+
(0, import_defineProperty$3.default)(this, "timeout", void 0);
|
|
54
56
|
}
|
|
55
57
|
/**
|
|
56
58
|
* Resets the current timeout, restarting it with the same duration.
|
|
@@ -105,6 +107,7 @@ async function buildConnectionMessage(connectionParams) {
|
|
|
105
107
|
|
|
106
108
|
//#endregion
|
|
107
109
|
//#region src/links/wsLink/wsClient/requestManager.ts
|
|
110
|
+
var import_defineProperty$2 = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
108
111
|
/**
|
|
109
112
|
* Manages WebSocket requests, tracking their lifecycle and providing utility methods
|
|
110
113
|
* for handling outgoing and pending requests.
|
|
@@ -114,16 +117,10 @@ async function buildConnectionMessage(connectionParams) {
|
|
|
114
117
|
* For subscriptions, multiple responses may be received until the subscription is closed.
|
|
115
118
|
*/
|
|
116
119
|
var RequestManager = class {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Stores requests that are pending (in flight), meaning they have been sent over the WebSocket
|
|
123
|
-
* and are awaiting responses. For subscriptions, this includes requests
|
|
124
|
-
* that may receive multiple responses.
|
|
125
|
-
*/
|
|
126
|
-
pendingRequests = {};
|
|
120
|
+
constructor() {
|
|
121
|
+
(0, import_defineProperty$2.default)(this, "outgoingRequests", new Array());
|
|
122
|
+
(0, import_defineProperty$2.default)(this, "pendingRequests", {});
|
|
123
|
+
}
|
|
127
124
|
/**
|
|
128
125
|
* Registers a new request by adding it to the outgoing queue and setting up
|
|
129
126
|
* callbacks for lifecycle events such as completion or error.
|
|
@@ -238,6 +235,7 @@ var RequestManager = class {
|
|
|
238
235
|
|
|
239
236
|
//#endregion
|
|
240
237
|
//#region src/links/wsLink/wsClient/wsConnection.ts
|
|
238
|
+
var import_defineProperty$1 = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
241
239
|
/**
|
|
242
240
|
* Opens a WebSocket connection asynchronously and returns a promise
|
|
243
241
|
* that resolves when the connection is successfully established.
|
|
@@ -299,14 +297,15 @@ function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
|
|
|
299
297
|
* and observable state tracking.
|
|
300
298
|
*/
|
|
301
299
|
var WsConnection = class WsConnection {
|
|
302
|
-
static connectCount = 0;
|
|
303
|
-
id = ++WsConnection.connectCount;
|
|
304
|
-
WebSocketPonyfill;
|
|
305
|
-
urlOptions;
|
|
306
|
-
keepAliveOpts;
|
|
307
|
-
wsObservable = (0, __trpc_server_observable.behaviorSubject)(null);
|
|
308
300
|
constructor(opts) {
|
|
309
|
-
|
|
301
|
+
var _opts$WebSocketPonyfi;
|
|
302
|
+
(0, import_defineProperty$1.default)(this, "id", ++WsConnection.connectCount);
|
|
303
|
+
(0, import_defineProperty$1.default)(this, "WebSocketPonyfill", void 0);
|
|
304
|
+
(0, import_defineProperty$1.default)(this, "urlOptions", void 0);
|
|
305
|
+
(0, import_defineProperty$1.default)(this, "keepAliveOpts", void 0);
|
|
306
|
+
(0, import_defineProperty$1.default)(this, "wsObservable", (0, __trpc_server_observable.behaviorSubject)(null));
|
|
307
|
+
(0, import_defineProperty$1.default)(this, "openPromise", null);
|
|
308
|
+
this.WebSocketPonyfill = (_opts$WebSocketPonyfi = opts.WebSocketPonyfill) !== null && _opts$WebSocketPonyfi !== void 0 ? _opts$WebSocketPonyfi : WebSocket;
|
|
310
309
|
if (!this.WebSocketPonyfill) throw new Error("No WebSocket implementation found - you probably don't want to use this on the server, but if you do you need to pass a `WebSocket`-ponyfill");
|
|
311
310
|
this.urlOptions = opts.urlOptions;
|
|
312
311
|
this.keepAliveOpts = opts.keepAlive;
|
|
@@ -329,36 +328,27 @@ var WsConnection = class WsConnection {
|
|
|
329
328
|
isClosed() {
|
|
330
329
|
return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
|
|
331
330
|
}
|
|
332
|
-
/**
|
|
333
|
-
* Manages the WebSocket opening process, ensuring that only one open operation
|
|
334
|
-
* occurs at a time. Tracks the ongoing operation with `openPromise` to avoid
|
|
335
|
-
* redundant calls and ensure proper synchronization.
|
|
336
|
-
*
|
|
337
|
-
* Sets up the keep-alive mechanism and necessary event listeners for the connection.
|
|
338
|
-
*
|
|
339
|
-
* @returns A promise that resolves once the WebSocket connection is successfully opened.
|
|
340
|
-
*/
|
|
341
|
-
openPromise = null;
|
|
342
331
|
async open() {
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
332
|
+
var _this = this;
|
|
333
|
+
if (_this.openPromise) return _this.openPromise;
|
|
334
|
+
_this.id = ++WsConnection.connectCount;
|
|
335
|
+
const wsPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url));
|
|
336
|
+
_this.openPromise = wsPromise.then(async (ws) => {
|
|
337
|
+
_this.ws = ws;
|
|
348
338
|
ws.addEventListener("message", function({ data }) {
|
|
349
339
|
if (data === "PING") this.send("PONG");
|
|
350
340
|
});
|
|
351
|
-
if (
|
|
341
|
+
if (_this.keepAliveOpts.enabled) setupPingInterval(ws, _this.keepAliveOpts);
|
|
352
342
|
ws.addEventListener("close", () => {
|
|
353
|
-
if (
|
|
343
|
+
if (_this.ws === ws) _this.ws = null;
|
|
354
344
|
});
|
|
355
345
|
await asyncWsOpen(ws);
|
|
356
|
-
if (
|
|
346
|
+
if (_this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(_this.urlOptions.connectionParams));
|
|
357
347
|
});
|
|
358
348
|
try {
|
|
359
|
-
await
|
|
349
|
+
await _this.openPromise;
|
|
360
350
|
} finally {
|
|
361
|
-
|
|
351
|
+
_this.openPromise = null;
|
|
362
352
|
}
|
|
363
353
|
}
|
|
364
354
|
/**
|
|
@@ -366,13 +356,16 @@ var WsConnection = class WsConnection {
|
|
|
366
356
|
* Waits for any ongoing open operation to complete before closing.
|
|
367
357
|
*/
|
|
368
358
|
async close() {
|
|
359
|
+
var _this2 = this;
|
|
369
360
|
try {
|
|
370
|
-
await
|
|
361
|
+
await _this2.openPromise;
|
|
371
362
|
} finally {
|
|
372
|
-
|
|
363
|
+
var _this$ws;
|
|
364
|
+
(_this$ws = _this2.ws) === null || _this$ws === void 0 || _this$ws.close();
|
|
373
365
|
}
|
|
374
366
|
}
|
|
375
367
|
};
|
|
368
|
+
(0, import_defineProperty$1.default)(WsConnection, "connectCount", 0);
|
|
376
369
|
/**
|
|
377
370
|
* Provides a backward-compatible representation of the connection state.
|
|
378
371
|
*/
|
|
@@ -397,32 +390,30 @@ function backwardCompatibility(connection) {
|
|
|
397
390
|
|
|
398
391
|
//#endregion
|
|
399
392
|
//#region src/links/wsLink/wsClient/wsClient.ts
|
|
393
|
+
var import_defineProperty = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
394
|
+
var import_objectSpread2 = require_chunk.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
|
|
400
395
|
/**
|
|
401
396
|
* A WebSocket client for managing TRPC operations, supporting lazy initialization,
|
|
402
397
|
* reconnection, keep-alive, and request management.
|
|
403
398
|
*/
|
|
404
399
|
var WsClient = class {
|
|
405
|
-
/**
|
|
406
|
-
* Observable tracking the current connection state, including errors.
|
|
407
|
-
*/
|
|
408
|
-
connectionState;
|
|
409
|
-
allowReconnect = false;
|
|
410
|
-
requestManager = new RequestManager();
|
|
411
|
-
activeConnection;
|
|
412
|
-
reconnectRetryDelay;
|
|
413
|
-
inactivityTimeout;
|
|
414
|
-
callbacks;
|
|
415
|
-
lazyMode;
|
|
416
400
|
constructor(opts) {
|
|
401
|
+
var _opts$retryDelayMs;
|
|
402
|
+
(0, import_defineProperty.default)(this, "connectionState", void 0);
|
|
403
|
+
(0, import_defineProperty.default)(this, "allowReconnect", false);
|
|
404
|
+
(0, import_defineProperty.default)(this, "requestManager", new RequestManager());
|
|
405
|
+
(0, import_defineProperty.default)(this, "activeConnection", void 0);
|
|
406
|
+
(0, import_defineProperty.default)(this, "reconnectRetryDelay", void 0);
|
|
407
|
+
(0, import_defineProperty.default)(this, "inactivityTimeout", void 0);
|
|
408
|
+
(0, import_defineProperty.default)(this, "callbacks", void 0);
|
|
409
|
+
(0, import_defineProperty.default)(this, "lazyMode", void 0);
|
|
410
|
+
(0, import_defineProperty.default)(this, "reconnecting", null);
|
|
417
411
|
this.callbacks = {
|
|
418
412
|
onOpen: opts.onOpen,
|
|
419
413
|
onClose: opts.onClose,
|
|
420
414
|
onError: opts.onError
|
|
421
415
|
};
|
|
422
|
-
const lazyOptions = {
|
|
423
|
-
...lazyDefaults,
|
|
424
|
-
...opts.lazy
|
|
425
|
-
};
|
|
416
|
+
const lazyOptions = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, lazyDefaults), opts.lazy);
|
|
426
417
|
this.inactivityTimeout = new ResettableTimeout(() => {
|
|
427
418
|
if (this.requestManager.hasOutgoingRequests() || this.requestManager.hasPendingRequests()) {
|
|
428
419
|
this.inactivityTimeout.reset();
|
|
@@ -433,16 +424,13 @@ var WsClient = class {
|
|
|
433
424
|
this.activeConnection = new WsConnection({
|
|
434
425
|
WebSocketPonyfill: opts.WebSocket,
|
|
435
426
|
urlOptions: opts,
|
|
436
|
-
keepAlive: {
|
|
437
|
-
...keepAliveDefaults,
|
|
438
|
-
...opts.keepAlive
|
|
439
|
-
}
|
|
427
|
+
keepAlive: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, keepAliveDefaults), opts.keepAlive)
|
|
440
428
|
});
|
|
441
429
|
this.activeConnection.wsObservable.subscribe({ next: (ws) => {
|
|
442
430
|
if (!ws) return;
|
|
443
431
|
this.setupWebSocketListeners(ws);
|
|
444
432
|
} });
|
|
445
|
-
this.reconnectRetryDelay = opts.retryDelayMs
|
|
433
|
+
this.reconnectRetryDelay = (_opts$retryDelayMs = opts.retryDelayMs) !== null && _opts$retryDelayMs !== void 0 ? _opts$retryDelayMs : exponentialBackoff;
|
|
446
434
|
this.lazyMode = lazyOptions.enabled;
|
|
447
435
|
this.connectionState = (0, __trpc_server_observable.behaviorSubject)({
|
|
448
436
|
type: "state",
|
|
@@ -456,20 +444,21 @@ var WsClient = class {
|
|
|
456
444
|
* the connection state accordingly.
|
|
457
445
|
*/
|
|
458
446
|
async open() {
|
|
459
|
-
|
|
460
|
-
|
|
447
|
+
var _this = this;
|
|
448
|
+
_this.allowReconnect = true;
|
|
449
|
+
if (_this.connectionState.get().state !== "connecting") _this.connectionState.next({
|
|
461
450
|
type: "state",
|
|
462
451
|
state: "connecting",
|
|
463
452
|
error: null
|
|
464
453
|
});
|
|
465
454
|
try {
|
|
466
|
-
await
|
|
455
|
+
await _this.activeConnection.open();
|
|
467
456
|
} catch (error) {
|
|
468
|
-
|
|
457
|
+
_this.reconnect(new TRPCWebSocketClosedError({
|
|
469
458
|
message: "Initialization error",
|
|
470
459
|
cause: error
|
|
471
460
|
}));
|
|
472
|
-
return
|
|
461
|
+
return _this.reconnecting;
|
|
473
462
|
}
|
|
474
463
|
}
|
|
475
464
|
/**
|
|
@@ -477,15 +466,16 @@ var WsClient = class {
|
|
|
477
466
|
* Ensures all outgoing and pending requests are properly finalized.
|
|
478
467
|
*/
|
|
479
468
|
async close() {
|
|
480
|
-
|
|
481
|
-
|
|
469
|
+
var _this2 = this;
|
|
470
|
+
_this2.allowReconnect = false;
|
|
471
|
+
_this2.inactivityTimeout.stop();
|
|
482
472
|
const requestsToAwait = [];
|
|
483
|
-
for (const request of
|
|
473
|
+
for (const request of _this2.requestManager.getRequests()) if (request.message.method === "subscription") request.callbacks.complete();
|
|
484
474
|
else if (request.state === "outgoing") request.callbacks.error(require_TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError({ message: "Closed before connection was established" })));
|
|
485
475
|
else requestsToAwait.push(request.end);
|
|
486
476
|
await Promise.all(requestsToAwait).catch(() => null);
|
|
487
|
-
await
|
|
488
|
-
|
|
477
|
+
await _this2.activeConnection.close().catch(() => null);
|
|
478
|
+
_this2.connectionState.next({
|
|
489
479
|
type: "state",
|
|
490
480
|
state: "idle",
|
|
491
481
|
error: null
|
|
@@ -511,37 +501,29 @@ var WsClient = class {
|
|
|
511
501
|
path,
|
|
512
502
|
lastEventId
|
|
513
503
|
}
|
|
514
|
-
}, {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
observer.error(require_TRPCClientError.TRPCClientError.from(transformed.error));
|
|
520
|
-
return;
|
|
521
|
-
}
|
|
522
|
-
observer.next({ result: transformed.result });
|
|
504
|
+
}, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, observer), {}, { next(event) {
|
|
505
|
+
const transformed = (0, __trpc_server_unstable_core_do_not_import.transformResult)(event, transformer.output);
|
|
506
|
+
if (!transformed.ok) {
|
|
507
|
+
observer.error(require_TRPCClientError.TRPCClientError.from(transformed.error));
|
|
508
|
+
return;
|
|
523
509
|
}
|
|
524
|
-
|
|
510
|
+
observer.next({ result: transformed.result });
|
|
511
|
+
} }));
|
|
525
512
|
return () => {
|
|
526
513
|
abort();
|
|
527
514
|
if (type === "subscription" && this.activeConnection.isOpen()) this.send({
|
|
528
515
|
id,
|
|
529
516
|
method: "subscription.stop"
|
|
530
517
|
});
|
|
531
|
-
signal
|
|
518
|
+
signal === null || signal === void 0 || signal.removeEventListener("abort", abort);
|
|
532
519
|
};
|
|
533
520
|
});
|
|
534
521
|
}
|
|
535
522
|
get connection() {
|
|
536
523
|
return backwardCompatibility(this.activeConnection);
|
|
537
524
|
}
|
|
538
|
-
/**
|
|
539
|
-
* Manages the reconnection process for the WebSocket using retry logic.
|
|
540
|
-
* Ensures that only one reconnection attempt is active at a time by tracking the current
|
|
541
|
-
* reconnection state in the `reconnecting` promise.
|
|
542
|
-
*/
|
|
543
|
-
reconnecting = null;
|
|
544
525
|
reconnect(closedError) {
|
|
526
|
+
var _this3 = this;
|
|
545
527
|
this.connectionState.next({
|
|
546
528
|
type: "state",
|
|
547
529
|
state: "connecting",
|
|
@@ -550,25 +532,26 @@ var WsClient = class {
|
|
|
550
532
|
if (this.reconnecting) return;
|
|
551
533
|
const tryReconnect = async (attemptIndex) => {
|
|
552
534
|
try {
|
|
553
|
-
await (0, __trpc_server_unstable_core_do_not_import.sleep)(
|
|
554
|
-
if (
|
|
555
|
-
await
|
|
556
|
-
await
|
|
557
|
-
if (
|
|
535
|
+
await (0, __trpc_server_unstable_core_do_not_import.sleep)(_this3.reconnectRetryDelay(attemptIndex));
|
|
536
|
+
if (_this3.allowReconnect) {
|
|
537
|
+
await _this3.activeConnection.close();
|
|
538
|
+
await _this3.activeConnection.open();
|
|
539
|
+
if (_this3.requestManager.hasPendingRequests()) _this3.send(_this3.requestManager.getPendingRequests().map(({ message }) => message));
|
|
558
540
|
}
|
|
559
|
-
|
|
560
|
-
} catch {
|
|
541
|
+
_this3.reconnecting = null;
|
|
542
|
+
} catch (_unused) {
|
|
561
543
|
await tryReconnect(attemptIndex + 1);
|
|
562
544
|
}
|
|
563
545
|
};
|
|
564
546
|
this.reconnecting = tryReconnect(0);
|
|
565
547
|
}
|
|
566
548
|
setupWebSocketListeners(ws) {
|
|
549
|
+
var _this4 = this;
|
|
567
550
|
const handleCloseOrError = (cause) => {
|
|
568
551
|
const reqs = this.requestManager.getPendingRequests();
|
|
569
552
|
for (const { message, callbacks } of reqs) {
|
|
570
553
|
if (message.method === "subscription") continue;
|
|
571
|
-
callbacks.error(require_TRPCClientError.TRPCClientError.from(cause
|
|
554
|
+
callbacks.error(require_TRPCClientError.TRPCClientError.from(cause !== null && cause !== void 0 ? cause : new TRPCWebSocketClosedError({
|
|
572
555
|
message: "WebSocket closed",
|
|
573
556
|
cause
|
|
574
557
|
})));
|
|
@@ -577,9 +560,10 @@ var WsClient = class {
|
|
|
577
560
|
};
|
|
578
561
|
ws.addEventListener("open", () => {
|
|
579
562
|
(0, __trpc_server_unstable_core_do_not_import.run)(async () => {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
563
|
+
var _this$callbacks$onOpe, _this$callbacks;
|
|
564
|
+
if (_this4.lazyMode) _this4.inactivityTimeout.start();
|
|
565
|
+
(_this$callbacks$onOpe = (_this$callbacks = _this4.callbacks).onOpen) === null || _this$callbacks$onOpe === void 0 || _this$callbacks$onOpe.call(_this$callbacks);
|
|
566
|
+
_this4.connectionState.next({
|
|
583
567
|
type: "state",
|
|
584
568
|
state: "pending",
|
|
585
569
|
error: null
|
|
@@ -600,16 +584,18 @@ var WsClient = class {
|
|
|
600
584
|
this.handleResponseMessage(incomingMessage);
|
|
601
585
|
});
|
|
602
586
|
ws.addEventListener("close", (event) => {
|
|
587
|
+
var _this$callbacks$onClo, _this$callbacks2;
|
|
603
588
|
handleCloseOrError(event);
|
|
604
|
-
this.callbacks.onClose
|
|
589
|
+
(_this$callbacks$onClo = (_this$callbacks2 = this.callbacks).onClose) === null || _this$callbacks$onClo === void 0 || _this$callbacks$onClo.call(_this$callbacks2, event);
|
|
605
590
|
if (!this.lazyMode || this.requestManager.hasPendingSubscriptions()) this.reconnect(new TRPCWebSocketClosedError({
|
|
606
591
|
message: "WebSocket closed",
|
|
607
592
|
cause: event
|
|
608
593
|
}));
|
|
609
594
|
});
|
|
610
595
|
ws.addEventListener("error", (event) => {
|
|
596
|
+
var _this$callbacks$onErr, _this$callbacks3;
|
|
611
597
|
handleCloseOrError(event);
|
|
612
|
-
this.callbacks.onError
|
|
598
|
+
(_this$callbacks$onErr = (_this$callbacks3 = this.callbacks).onError) === null || _this$callbacks$onErr === void 0 || _this$callbacks$onErr.call(_this$callbacks3, event);
|
|
613
599
|
this.reconnect(new TRPCWebSocketClosedError({
|
|
614
600
|
message: "WebSocket closed",
|
|
615
601
|
cause: event
|
|
@@ -647,12 +633,13 @@ var WsClient = class {
|
|
|
647
633
|
* @returns A function to abort the batched request.
|
|
648
634
|
*/
|
|
649
635
|
batchSend(message, callbacks) {
|
|
636
|
+
var _this5 = this;
|
|
650
637
|
this.inactivityTimeout.reset();
|
|
651
638
|
(0, __trpc_server_unstable_core_do_not_import.run)(async () => {
|
|
652
|
-
if (!
|
|
639
|
+
if (!_this5.activeConnection.isOpen()) await _this5.open();
|
|
653
640
|
await (0, __trpc_server_unstable_core_do_not_import.sleep)(0);
|
|
654
|
-
if (!
|
|
655
|
-
|
|
641
|
+
if (!_this5.requestManager.hasOutgoingRequests()) return;
|
|
642
|
+
_this5.send(_this5.requestManager.flush().map(({ message: message$1 }) => message$1));
|
|
656
643
|
}).catch((err) => {
|
|
657
644
|
this.requestManager.delete(message.id);
|
|
658
645
|
callbacks.error(require_TRPCClientError.TRPCClientError.from(err));
|
|
@@ -687,7 +674,7 @@ function wsLink(opts) {
|
|
|
687
674
|
}).subscribe(observer);
|
|
688
675
|
return () => {
|
|
689
676
|
requestSubscription.unsubscribe();
|
|
690
|
-
connStateSubscription
|
|
677
|
+
connStateSubscription === null || connStateSubscription === void 0 || connStateSubscription.unsubscribe();
|
|
691
678
|
};
|
|
692
679
|
});
|
|
693
680
|
};
|