@trpc/client 11.18.1-canary.6 → 11.19.0
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/bin/intent.js +0 -0
- package/dist/TRPCClientError-CmHlBkPF.cjs +56 -0
- package/dist/{TRPCClientError-apv8gw59.mjs → TRPCClientError-CxFRO7Js.mjs} +11 -14
- package/dist/TRPCClientError-CxFRO7Js.mjs.map +1 -0
- package/dist/{httpBatchLink-LhidKAPw.mjs → httpBatchLink-BMtWxLJV.mjs} +25 -72
- package/dist/httpBatchLink-BMtWxLJV.mjs.map +1 -0
- package/dist/{httpBatchLink.d-7jyWtY5H.d.cts → httpBatchLink-Br-pzPXf.d.cts} +4 -8
- package/dist/httpBatchLink-Br-pzPXf.d.cts.map +1 -0
- package/dist/{httpBatchLink-BGZRsGNf.cjs → httpBatchLink-DO3WQoxu.cjs} +37 -104
- package/dist/{httpBatchLink.d-p8Y9QM8p.d.mts → httpBatchLink-nvc48L_N.d.mts} +4 -8
- package/dist/httpBatchLink-nvc48L_N.d.mts.map +1 -0
- package/dist/{httpLink.d-CjpPCq4q.d.mts → httpLink-D5FQijY2.d.cts} +4 -7
- package/dist/httpLink-D5FQijY2.d.cts.map +1 -0
- package/dist/{httpLink-B8Iv31Ee.cjs → httpLink-MDJTSlpi.cjs} +39 -38
- package/dist/{httpLink-lG_6juPY.mjs → httpLink-Tm93WWFA.mjs} +17 -14
- package/dist/httpLink-Tm93WWFA.mjs.map +1 -0
- package/dist/{httpLink.d-D5qR9haY.d.cts → httpLink-eSAq8J9S.d.mts} +4 -7
- package/dist/httpLink-eSAq8J9S.d.mts.map +1 -0
- package/dist/{httpUtils.d-BqmeKEGo.d.cts → httpUtils-C37jRVnj.d.mts} +4 -6
- package/dist/httpUtils-C37jRVnj.d.mts.map +1 -0
- package/dist/{httpUtils-pyf5RF99.mjs → httpUtils-CB_100ND.mjs} +51 -14
- package/dist/httpUtils-CB_100ND.mjs.map +1 -0
- package/dist/{httpUtils.d-C5t5to0D.d.mts → httpUtils-CUqAubVD.d.cts} +4 -6
- package/dist/httpUtils-CUqAubVD.d.cts.map +1 -0
- package/dist/{httpUtils-wv2o-njD.cjs → httpUtils-cggqcHz0.cjs} +102 -49
- package/dist/index.cjs +248 -309
- package/dist/index.d.cts +38 -41
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +38 -41
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +212 -272
- package/dist/index.mjs.map +1 -1
- package/dist/links/httpBatchLink.cjs +3 -7
- package/dist/links/httpBatchLink.d.cts +1 -5
- package/dist/links/httpBatchLink.d.mts +1 -5
- package/dist/links/httpBatchLink.mjs +2 -7
- package/dist/links/httpLink.cjs +3 -7
- package/dist/links/httpLink.d.cts +1 -5
- package/dist/links/httpLink.d.mts +1 -5
- package/dist/links/httpLink.mjs +2 -7
- package/dist/links/loggerLink.cjs +113 -4
- package/dist/links/loggerLink.d.cts +1 -3
- package/dist/links/loggerLink.d.mts +1 -3
- package/dist/links/loggerLink.mjs +113 -3
- package/dist/links/loggerLink.mjs.map +1 -0
- package/dist/links/splitLink.cjs +3 -3
- package/dist/links/splitLink.d.cts +1 -3
- package/dist/links/splitLink.d.mts +1 -3
- package/dist/links/splitLink.mjs +2 -3
- package/dist/links/wsLink/wsLink.cjs +3 -6
- package/dist/links/wsLink/wsLink.d.cts +2 -5
- package/dist/links/wsLink/wsLink.d.mts +2 -5
- package/dist/links/wsLink/wsLink.mjs +2 -6
- package/dist/{loggerLink.d-0ABgt7oh.d.mts → loggerLink-2o-uZ3r1.d.cts} +3 -4
- package/dist/loggerLink-2o-uZ3r1.d.cts.map +1 -0
- package/dist/{loggerLink.d-BxSIj5kx.d.cts → loggerLink-CFercTVc.d.mts} +3 -4
- package/dist/loggerLink-CFercTVc.d.mts.map +1 -0
- package/dist/objectSpread2-D-dJi1gK.cjs +73 -0
- package/dist/objectSpread2-weooBxVk.mjs +62 -0
- package/dist/{splitLink-B7Cuf2c_.mjs → splitLink-BZPioDdG.mjs} +6 -11
- package/dist/splitLink-BZPioDdG.mjs.map +1 -0
- package/dist/{splitLink.d-BBFK_mCw.d.cts → splitLink-CJdcmEmS.d.cts} +3 -6
- package/dist/splitLink-CJdcmEmS.d.cts.map +1 -0
- package/dist/{splitLink.d-CkHNg1Se.d.mts → splitLink-CixmF14P.d.mts} +3 -6
- package/dist/splitLink-CixmF14P.d.mts.map +1 -0
- package/dist/{splitLink-BMgxggng.cjs → splitLink-MXnaFlEb.cjs} +17 -24
- package/dist/{subscriptions.d-Ciljg_dH.d.cts → subscriptions-DcqRZc4h.d.cts} +2 -2
- package/dist/subscriptions-DcqRZc4h.d.cts.map +1 -0
- package/dist/{subscriptions.d-Dlr1nWGD.d.mts → subscriptions-DcqRZc4h.d.mts} +2 -2
- package/dist/subscriptions-DcqRZc4h.d.mts.map +1 -0
- package/dist/{types.d-CAr6snH0.d.mts → types-BxbMkv6C.d.cts} +4 -15
- package/dist/types-BxbMkv6C.d.cts.map +1 -0
- package/dist/{types.d-Dmmedc5G.d.cts → types-CAPs7vhA.d.mts} +4 -15
- package/dist/types-CAPs7vhA.d.mts.map +1 -0
- package/dist/{unstable-internals.d-BOmV7EK1.d.mts → unstable-internals-CE8gFBQ9.d.cts} +2 -4
- package/dist/unstable-internals-CE8gFBQ9.d.cts.map +1 -0
- package/dist/{unstable-internals.d-kWsZTlQq.d.cts → unstable-internals-CE8gFBQ9.d.mts} +2 -4
- package/dist/unstable-internals-CE8gFBQ9.d.mts.map +1 -0
- package/dist/unstable-internals.cjs +28 -3
- package/dist/unstable-internals.d.cts +2 -2
- package/dist/unstable-internals.d.mts +2 -2
- package/dist/unstable-internals.mjs +28 -2
- package/dist/unstable-internals.mjs.map +1 -0
- package/dist/{wsLink-DSf4KOdW.mjs → wsLink-Bm5LKL6z.mjs} +73 -94
- package/dist/wsLink-Bm5LKL6z.mjs.map +1 -0
- package/dist/{wsLink-CobRSm6C.cjs → wsLink-CKAsNP9P.cjs} +100 -123
- package/dist/{wsLink.d-pFN64NkG.d.mts → wsLink-DoiyfDgJ.d.cts} +11 -31
- package/dist/wsLink-DoiyfDgJ.d.cts.map +1 -0
- package/dist/{wsLink.d-DzZZZGZQ.d.cts → wsLink-U8pJ7LD2.d.mts} +11 -31
- package/dist/wsLink-U8pJ7LD2.d.mts.map +1 -0
- package/package.json +10 -10
- package/src/getFetch.ts +3 -2
- package/src/links/httpBatchLink.ts +12 -3
- package/src/links/httpBatchStreamLink.ts +7 -8
- package/src/links/httpLink.ts +9 -2
- package/src/links/httpSubscriptionLink.ts +1 -3
- package/src/links/internals/subscriptions.ts +3 -2
- package/src/links/types.ts +1 -2
- package/src/links/wsLink/wsClient/wsClient.ts +8 -1
- package/dist/TRPCClientError-CQrTQLrk.cjs +0 -61
- package/dist/TRPCClientError-apv8gw59.mjs.map +0 -1
- package/dist/chunk-DWy1uDak.cjs +0 -39
- package/dist/httpBatchLink-LhidKAPw.mjs.map +0 -1
- package/dist/httpBatchLink.d-7jyWtY5H.d.cts.map +0 -1
- package/dist/httpBatchLink.d-p8Y9QM8p.d.mts.map +0 -1
- package/dist/httpLink-lG_6juPY.mjs.map +0 -1
- package/dist/httpLink.d-CjpPCq4q.d.mts.map +0 -1
- package/dist/httpLink.d-D5qR9haY.d.cts.map +0 -1
- package/dist/httpUtils-pyf5RF99.mjs.map +0 -1
- package/dist/httpUtils.d-BqmeKEGo.d.cts.map +0 -1
- package/dist/httpUtils.d-C5t5to0D.d.mts.map +0 -1
- package/dist/loggerLink-CuYvRzyH.cjs +0 -123
- package/dist/loggerLink-ineCN1PO.mjs +0 -118
- package/dist/loggerLink-ineCN1PO.mjs.map +0 -1
- package/dist/loggerLink.d-0ABgt7oh.d.mts.map +0 -1
- package/dist/loggerLink.d-BxSIj5kx.d.cts.map +0 -1
- package/dist/objectSpread2-Bsvh_OqM.cjs +0 -100
- package/dist/objectSpread2-BvkFp-_Y.mjs +0 -114
- package/dist/objectSpread2-BvkFp-_Y.mjs.map +0 -1
- package/dist/splitLink-B7Cuf2c_.mjs.map +0 -1
- package/dist/splitLink.d-BBFK_mCw.d.cts.map +0 -1
- package/dist/splitLink.d-CkHNg1Se.d.mts.map +0 -1
- package/dist/subscriptions.d-Ciljg_dH.d.cts.map +0 -1
- package/dist/subscriptions.d-Dlr1nWGD.d.mts.map +0 -1
- package/dist/types.d-CAr6snH0.d.mts.map +0 -1
- package/dist/types.d-Dmmedc5G.d.cts.map +0 -1
- package/dist/unstable-internals-Bg7n9BBj.mjs +0 -29
- package/dist/unstable-internals-Bg7n9BBj.mjs.map +0 -1
- package/dist/unstable-internals-M84gUQCV.cjs +0 -34
- package/dist/unstable-internals.d-BOmV7EK1.d.mts.map +0 -1
- package/dist/unstable-internals.d-kWsZTlQq.d.cts.map +0 -1
- package/dist/wsLink-DSf4KOdW.mjs.map +0 -1
- package/dist/wsLink.d-DzZZZGZQ.d.cts.map +0 -1
- package/dist/wsLink.d-pFN64NkG.d.mts.map +0 -1
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const __trpc_server_unstable_core_do_not_import = require_chunk.__toESM(require("@trpc/server/unstable-core-do-not-import"));
|
|
7
|
-
|
|
1
|
+
const require_objectSpread2 = require("./objectSpread2-D-dJi1gK.cjs");
|
|
2
|
+
const require_TRPCClientError = require("./TRPCClientError-CmHlBkPF.cjs");
|
|
3
|
+
const require_unstable_internals = require("./unstable-internals.cjs");
|
|
4
|
+
let _trpc_server_observable = require("@trpc/server/observable");
|
|
5
|
+
let _trpc_server_unstable_core_do_not_import = require("@trpc/server/unstable-core-do-not-import");
|
|
8
6
|
//#region src/links/wsLink/wsClient/encoder.ts
|
|
9
7
|
const jsonEncoder = {
|
|
10
8
|
encode: (data) => JSON.stringify(data),
|
|
@@ -13,7 +11,6 @@ const jsonEncoder = {
|
|
|
13
11
|
return JSON.parse(data);
|
|
14
12
|
}
|
|
15
13
|
};
|
|
16
|
-
|
|
17
14
|
//#endregion
|
|
18
15
|
//#region src/links/wsLink/wsClient/options.ts
|
|
19
16
|
const lazyDefaults = {
|
|
@@ -33,7 +30,6 @@ const keepAliveDefaults = {
|
|
|
33
30
|
const exponentialBackoff = (attemptIndex) => {
|
|
34
31
|
return attemptIndex === 0 ? 0 : Math.min(1e3 * 2 ** attemptIndex, 3e4);
|
|
35
32
|
};
|
|
36
|
-
|
|
37
33
|
//#endregion
|
|
38
34
|
//#region src/links/internals/urlWithConnectionParams.ts
|
|
39
35
|
/**
|
|
@@ -43,10 +39,8 @@ const exponentialBackoff = (attemptIndex) => {
|
|
|
43
39
|
const resultOf = (value, ...args) => {
|
|
44
40
|
return typeof value === "function" ? value(...args) : value;
|
|
45
41
|
};
|
|
46
|
-
|
|
47
42
|
//#endregion
|
|
48
43
|
//#region src/links/wsLink/wsClient/utils.ts
|
|
49
|
-
var import_defineProperty$3 = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
50
44
|
var TRPCWebSocketClosedError = class TRPCWebSocketClosedError extends Error {
|
|
51
45
|
constructor(opts) {
|
|
52
46
|
super(opts.message, { cause: opts.cause });
|
|
@@ -62,7 +56,7 @@ var ResettableTimeout = class {
|
|
|
62
56
|
constructor(onTimeout, timeoutMs) {
|
|
63
57
|
this.onTimeout = onTimeout;
|
|
64
58
|
this.timeoutMs = timeoutMs;
|
|
65
|
-
|
|
59
|
+
require_objectSpread2._defineProperty(this, "timeout", void 0);
|
|
66
60
|
}
|
|
67
61
|
/**
|
|
68
62
|
* Resets the current timeout, restarting it with the same duration.
|
|
@@ -85,12 +79,11 @@ var ResettableTimeout = class {
|
|
|
85
79
|
function withResolvers() {
|
|
86
80
|
let resolve;
|
|
87
81
|
let reject;
|
|
88
|
-
const promise = new Promise((res, rej) => {
|
|
89
|
-
resolve = res;
|
|
90
|
-
reject = rej;
|
|
91
|
-
});
|
|
92
82
|
return {
|
|
93
|
-
promise,
|
|
83
|
+
promise: new Promise((res, rej) => {
|
|
84
|
+
resolve = res;
|
|
85
|
+
reject = rej;
|
|
86
|
+
}),
|
|
94
87
|
resolve,
|
|
95
88
|
reject
|
|
96
89
|
};
|
|
@@ -103,9 +96,7 @@ function withResolvers() {
|
|
|
103
96
|
async function prepareUrl(urlOptions) {
|
|
104
97
|
const url = await resultOf(urlOptions.url);
|
|
105
98
|
if (!urlOptions.connectionParams) return url;
|
|
106
|
-
|
|
107
|
-
const connectionParams = `${prefix}connectionParams=1`;
|
|
108
|
-
return url + connectionParams;
|
|
99
|
+
return url + `${url.includes("?") ? "&" : "?"}connectionParams=1`;
|
|
109
100
|
}
|
|
110
101
|
async function buildConnectionMessage(connectionParams, encoder) {
|
|
111
102
|
const message = {
|
|
@@ -114,10 +105,8 @@ async function buildConnectionMessage(connectionParams, encoder) {
|
|
|
114
105
|
};
|
|
115
106
|
return encoder.encode(message);
|
|
116
107
|
}
|
|
117
|
-
|
|
118
108
|
//#endregion
|
|
119
109
|
//#region src/links/wsLink/wsClient/requestManager.ts
|
|
120
|
-
var import_defineProperty$2 = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
121
110
|
/**
|
|
122
111
|
* Manages WebSocket requests, tracking their lifecycle and providing utility methods
|
|
123
112
|
* for handling outgoing and pending requests.
|
|
@@ -128,8 +117,8 @@ var import_defineProperty$2 = require_chunk.__toESM(require_objectSpread2$1.requ
|
|
|
128
117
|
*/
|
|
129
118
|
var RequestManager = class {
|
|
130
119
|
constructor() {
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
require_objectSpread2._defineProperty(this, "outgoingRequests", new Array());
|
|
121
|
+
require_objectSpread2._defineProperty(this, "pendingRequests", {});
|
|
133
122
|
}
|
|
134
123
|
/**
|
|
135
124
|
* Registers a new request by adding it to the outgoing queue and setting up
|
|
@@ -242,10 +231,8 @@ var RequestManager = class {
|
|
|
242
231
|
return this.outgoingRequests.length > 0;
|
|
243
232
|
}
|
|
244
233
|
};
|
|
245
|
-
|
|
246
234
|
//#endregion
|
|
247
235
|
//#region src/links/wsLink/wsClient/wsConnection.ts
|
|
248
|
-
var import_defineProperty$1 = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
249
236
|
/**
|
|
250
237
|
* Opens a WebSocket connection asynchronously and returns a promise
|
|
251
238
|
* that resolves when the connection is successfully established.
|
|
@@ -309,13 +296,13 @@ function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
|
|
|
309
296
|
var WsConnection = class WsConnection {
|
|
310
297
|
constructor(opts) {
|
|
311
298
|
var _opts$WebSocketPonyfi;
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
299
|
+
require_objectSpread2._defineProperty(this, "id", ++WsConnection.connectCount);
|
|
300
|
+
require_objectSpread2._defineProperty(this, "WebSocketPonyfill", void 0);
|
|
301
|
+
require_objectSpread2._defineProperty(this, "urlOptions", void 0);
|
|
302
|
+
require_objectSpread2._defineProperty(this, "keepAliveOpts", void 0);
|
|
303
|
+
require_objectSpread2._defineProperty(this, "encoder", void 0);
|
|
304
|
+
require_objectSpread2._defineProperty(this, "wsObservable", (0, _trpc_server_observable.behaviorSubject)(null));
|
|
305
|
+
require_objectSpread2._defineProperty(this, "openPromise", null);
|
|
319
306
|
this.WebSocketPonyfill = (_opts$WebSocketPonyfi = opts.WebSocketPonyfill) !== null && _opts$WebSocketPonyfi !== void 0 ? _opts$WebSocketPonyfi : WebSocket;
|
|
320
307
|
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");
|
|
321
308
|
this.urlOptions = opts.urlOptions;
|
|
@@ -341,27 +328,26 @@ var WsConnection = class WsConnection {
|
|
|
341
328
|
return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
|
|
342
329
|
}
|
|
343
330
|
async open() {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
_this.ws = ws;
|
|
331
|
+
if (this.openPromise) return this.openPromise;
|
|
332
|
+
this.id = ++WsConnection.connectCount;
|
|
333
|
+
const wsPromise = prepareUrl(this.urlOptions).then((url) => new this.WebSocketPonyfill(url));
|
|
334
|
+
this.openPromise = wsPromise.then(async (ws) => {
|
|
335
|
+
this.ws = ws;
|
|
350
336
|
ws.binaryType = "arraybuffer";
|
|
351
337
|
ws.addEventListener("message", function({ data }) {
|
|
352
338
|
if (data === "PING") this.send("PONG");
|
|
353
339
|
});
|
|
354
|
-
if (
|
|
340
|
+
if (this.keepAliveOpts.enabled) setupPingInterval(ws, this.keepAliveOpts);
|
|
355
341
|
ws.addEventListener("close", () => {
|
|
356
|
-
if (
|
|
342
|
+
if (this.ws === ws) this.ws = null;
|
|
357
343
|
});
|
|
358
344
|
await asyncWsOpen(ws);
|
|
359
|
-
if (
|
|
345
|
+
if (this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(this.urlOptions.connectionParams, this.encoder));
|
|
360
346
|
});
|
|
361
347
|
try {
|
|
362
|
-
await
|
|
348
|
+
await this.openPromise;
|
|
363
349
|
} finally {
|
|
364
|
-
|
|
350
|
+
this.openPromise = null;
|
|
365
351
|
}
|
|
366
352
|
}
|
|
367
353
|
/**
|
|
@@ -369,16 +355,15 @@ var WsConnection = class WsConnection {
|
|
|
369
355
|
* Waits for any ongoing open operation to complete before closing.
|
|
370
356
|
*/
|
|
371
357
|
async close() {
|
|
372
|
-
var _this2 = this;
|
|
373
358
|
try {
|
|
374
|
-
await
|
|
359
|
+
await this.openPromise;
|
|
375
360
|
} finally {
|
|
376
361
|
var _this$ws;
|
|
377
|
-
(_this$ws =
|
|
362
|
+
(_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.close();
|
|
378
363
|
}
|
|
379
364
|
}
|
|
380
365
|
};
|
|
381
|
-
|
|
366
|
+
require_objectSpread2._defineProperty(WsConnection, "connectCount", 0);
|
|
382
367
|
/**
|
|
383
368
|
* Provides a backward-compatible representation of the connection state.
|
|
384
369
|
*/
|
|
@@ -400,11 +385,8 @@ function backwardCompatibility(connection) {
|
|
|
400
385
|
ws: connection.ws
|
|
401
386
|
};
|
|
402
387
|
}
|
|
403
|
-
|
|
404
388
|
//#endregion
|
|
405
389
|
//#region src/links/wsLink/wsClient/wsClient.ts
|
|
406
|
-
var import_defineProperty = require_chunk.__toESM(require_objectSpread2$1.require_defineProperty(), 1);
|
|
407
|
-
var import_objectSpread2 = require_chunk.__toESM(require_objectSpread2$1.require_objectSpread2(), 1);
|
|
408
390
|
/**
|
|
409
391
|
* A WebSocket client for managing TRPC operations, supporting lazy initialization,
|
|
410
392
|
* reconnection, keep-alive, and request management.
|
|
@@ -412,23 +394,23 @@ var import_objectSpread2 = require_chunk.__toESM(require_objectSpread2$1.require
|
|
|
412
394
|
var WsClient = class {
|
|
413
395
|
constructor(opts) {
|
|
414
396
|
var _opts$experimental_en, _opts$retryDelayMs;
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
397
|
+
require_objectSpread2._defineProperty(this, "connectionState", void 0);
|
|
398
|
+
require_objectSpread2._defineProperty(this, "allowReconnect", false);
|
|
399
|
+
require_objectSpread2._defineProperty(this, "requestManager", new RequestManager());
|
|
400
|
+
require_objectSpread2._defineProperty(this, "activeConnection", void 0);
|
|
401
|
+
require_objectSpread2._defineProperty(this, "reconnectRetryDelay", void 0);
|
|
402
|
+
require_objectSpread2._defineProperty(this, "inactivityTimeout", void 0);
|
|
403
|
+
require_objectSpread2._defineProperty(this, "callbacks", void 0);
|
|
404
|
+
require_objectSpread2._defineProperty(this, "lazyMode", void 0);
|
|
405
|
+
require_objectSpread2._defineProperty(this, "encoder", void 0);
|
|
406
|
+
require_objectSpread2._defineProperty(this, "reconnecting", null);
|
|
425
407
|
this.encoder = (_opts$experimental_en = opts.experimental_encoder) !== null && _opts$experimental_en !== void 0 ? _opts$experimental_en : jsonEncoder;
|
|
426
408
|
this.callbacks = {
|
|
427
409
|
onOpen: opts.onOpen,
|
|
428
410
|
onClose: opts.onClose,
|
|
429
411
|
onError: opts.onError
|
|
430
412
|
};
|
|
431
|
-
const lazyOptions =
|
|
413
|
+
const lazyOptions = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, lazyDefaults), opts.lazy);
|
|
432
414
|
this.inactivityTimeout = new ResettableTimeout(() => {
|
|
433
415
|
if (this.requestManager.hasOutgoingRequests() || this.requestManager.hasPendingRequests()) {
|
|
434
416
|
this.inactivityTimeout.reset();
|
|
@@ -439,7 +421,7 @@ var WsClient = class {
|
|
|
439
421
|
this.activeConnection = new WsConnection({
|
|
440
422
|
WebSocketPonyfill: opts.WebSocket,
|
|
441
423
|
urlOptions: opts,
|
|
442
|
-
keepAlive:
|
|
424
|
+
keepAlive: require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, keepAliveDefaults), opts.keepAlive),
|
|
443
425
|
encoder: this.encoder
|
|
444
426
|
});
|
|
445
427
|
this.activeConnection.wsObservable.subscribe({ next: (ws) => {
|
|
@@ -448,7 +430,7 @@ var WsClient = class {
|
|
|
448
430
|
} });
|
|
449
431
|
this.reconnectRetryDelay = (_opts$retryDelayMs = opts.retryDelayMs) !== null && _opts$retryDelayMs !== void 0 ? _opts$retryDelayMs : exponentialBackoff;
|
|
450
432
|
this.lazyMode = lazyOptions.enabled;
|
|
451
|
-
this.connectionState = (0,
|
|
433
|
+
this.connectionState = (0, _trpc_server_observable.behaviorSubject)({
|
|
452
434
|
type: "state",
|
|
453
435
|
state: lazyOptions.enabled ? "idle" : "connecting",
|
|
454
436
|
error: null
|
|
@@ -460,21 +442,20 @@ var WsClient = class {
|
|
|
460
442
|
* the connection state accordingly.
|
|
461
443
|
*/
|
|
462
444
|
async open() {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
if (_this.connectionState.get().state === "idle") _this.connectionState.next({
|
|
445
|
+
this.allowReconnect = true;
|
|
446
|
+
if (this.connectionState.get().state === "idle") this.connectionState.next({
|
|
466
447
|
type: "state",
|
|
467
448
|
state: "connecting",
|
|
468
449
|
error: null
|
|
469
450
|
});
|
|
470
451
|
try {
|
|
471
|
-
await
|
|
452
|
+
await this.activeConnection.open();
|
|
472
453
|
} catch (error) {
|
|
473
|
-
|
|
454
|
+
this.reconnect(new TRPCWebSocketClosedError({
|
|
474
455
|
message: "Initialization error",
|
|
475
456
|
cause: error
|
|
476
457
|
}));
|
|
477
|
-
return
|
|
458
|
+
return this.reconnecting;
|
|
478
459
|
}
|
|
479
460
|
}
|
|
480
461
|
/**
|
|
@@ -482,16 +463,15 @@ var WsClient = class {
|
|
|
482
463
|
* Ensures all outgoing and pending requests are properly finalized.
|
|
483
464
|
*/
|
|
484
465
|
async close() {
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
_this2.inactivityTimeout.stop();
|
|
466
|
+
this.allowReconnect = false;
|
|
467
|
+
this.inactivityTimeout.stop();
|
|
488
468
|
const requestsToAwait = [];
|
|
489
|
-
for (const request of
|
|
469
|
+
for (const request of this.requestManager.getRequests()) if (request.message.method === "subscription") request.callbacks.complete();
|
|
490
470
|
else if (request.state === "outgoing") request.callbacks.error(require_TRPCClientError.TRPCClientError.from(new TRPCWebSocketClosedError({ message: "Closed before connection was established" })));
|
|
491
471
|
else requestsToAwait.push(request.end);
|
|
492
472
|
await Promise.all(requestsToAwait).catch(() => null);
|
|
493
|
-
await
|
|
494
|
-
|
|
473
|
+
await this.activeConnection.close().catch(() => null);
|
|
474
|
+
this.connectionState.next({
|
|
495
475
|
type: "state",
|
|
496
476
|
state: "idle",
|
|
497
477
|
error: null
|
|
@@ -508,7 +488,7 @@ var WsClient = class {
|
|
|
508
488
|
* @returns An observable that emits operation results and handles cleanup
|
|
509
489
|
*/
|
|
510
490
|
request({ op: { id, type, path, input, signal }, transformer, lastEventId }) {
|
|
511
|
-
return (0,
|
|
491
|
+
return (0, _trpc_server_observable.observable)((observer) => {
|
|
512
492
|
const abort = this.batchSend({
|
|
513
493
|
id,
|
|
514
494
|
method: type,
|
|
@@ -517,21 +497,24 @@ var WsClient = class {
|
|
|
517
497
|
path,
|
|
518
498
|
lastEventId
|
|
519
499
|
}
|
|
520
|
-
},
|
|
521
|
-
const transformed = (0,
|
|
500
|
+
}, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, observer), {}, { next(event) {
|
|
501
|
+
const transformed = (0, _trpc_server_unstable_core_do_not_import.transformResult)(event, transformer.output);
|
|
522
502
|
if (!transformed.ok) {
|
|
523
503
|
observer.error(require_TRPCClientError.TRPCClientError.from(transformed.error));
|
|
524
504
|
return;
|
|
525
505
|
}
|
|
526
506
|
observer.next({ result: transformed.result });
|
|
527
507
|
} }));
|
|
508
|
+
const onAbort = () => observer.complete();
|
|
509
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) onAbort();
|
|
510
|
+
else signal === null || signal === void 0 || signal.addEventListener("abort", onAbort, { once: true });
|
|
528
511
|
return () => {
|
|
529
512
|
abort();
|
|
530
513
|
if (type === "subscription" && this.activeConnection.isOpen()) this.send({
|
|
531
514
|
id,
|
|
532
515
|
method: "subscription.stop"
|
|
533
516
|
});
|
|
534
|
-
signal === null || signal === void 0 || signal.removeEventListener("abort",
|
|
517
|
+
signal === null || signal === void 0 || signal.removeEventListener("abort", onAbort);
|
|
535
518
|
};
|
|
536
519
|
});
|
|
537
520
|
}
|
|
@@ -539,7 +522,6 @@ var WsClient = class {
|
|
|
539
522
|
return backwardCompatibility(this.activeConnection);
|
|
540
523
|
}
|
|
541
524
|
reconnect(closedError) {
|
|
542
|
-
var _this3 = this;
|
|
543
525
|
this.connectionState.next({
|
|
544
526
|
type: "state",
|
|
545
527
|
state: "connecting",
|
|
@@ -548,13 +530,13 @@ var WsClient = class {
|
|
|
548
530
|
if (this.reconnecting) return;
|
|
549
531
|
const tryReconnect = async (attemptIndex) => {
|
|
550
532
|
try {
|
|
551
|
-
await (0,
|
|
552
|
-
if (
|
|
553
|
-
await
|
|
554
|
-
await
|
|
555
|
-
if (
|
|
533
|
+
await (0, _trpc_server_unstable_core_do_not_import.sleep)(this.reconnectRetryDelay(attemptIndex));
|
|
534
|
+
if (this.allowReconnect) {
|
|
535
|
+
await this.activeConnection.close();
|
|
536
|
+
await this.activeConnection.open();
|
|
537
|
+
if (this.requestManager.hasPendingRequests()) this.send(this.requestManager.getPendingRequests().map(({ message }) => message));
|
|
556
538
|
}
|
|
557
|
-
|
|
539
|
+
this.reconnecting = null;
|
|
558
540
|
} catch (_unused) {
|
|
559
541
|
await tryReconnect(attemptIndex + 1);
|
|
560
542
|
}
|
|
@@ -562,7 +544,6 @@ var WsClient = class {
|
|
|
562
544
|
this.reconnecting = tryReconnect(0);
|
|
563
545
|
}
|
|
564
546
|
setupWebSocketListeners(ws) {
|
|
565
|
-
var _this4 = this;
|
|
566
547
|
const handleCloseOrError = (cause) => {
|
|
567
548
|
const reqs = this.requestManager.getPendingRequests();
|
|
568
549
|
for (const { message, callbacks } of reqs) {
|
|
@@ -575,11 +556,11 @@ var WsClient = class {
|
|
|
575
556
|
}
|
|
576
557
|
};
|
|
577
558
|
ws.addEventListener("open", () => {
|
|
578
|
-
(0,
|
|
559
|
+
(0, _trpc_server_unstable_core_do_not_import.run)(async () => {
|
|
579
560
|
var _this$callbacks$onOpe, _this$callbacks;
|
|
580
|
-
if (
|
|
581
|
-
(_this$callbacks$onOpe = (_this$callbacks =
|
|
582
|
-
|
|
561
|
+
if (this.lazyMode) this.inactivityTimeout.start();
|
|
562
|
+
(_this$callbacks$onOpe = (_this$callbacks = this.callbacks).onOpen) === null || _this$callbacks$onOpe === void 0 || _this$callbacks$onOpe.call(_this$callbacks);
|
|
563
|
+
this.connectionState.next({
|
|
583
564
|
type: "state",
|
|
584
565
|
state: "pending",
|
|
585
566
|
error: null
|
|
@@ -649,13 +630,12 @@ var WsClient = class {
|
|
|
649
630
|
* @returns A function to abort the batched request.
|
|
650
631
|
*/
|
|
651
632
|
batchSend(message, callbacks) {
|
|
652
|
-
var _this5 = this;
|
|
653
633
|
this.inactivityTimeout.reset();
|
|
654
|
-
(0,
|
|
655
|
-
if (!
|
|
656
|
-
await (0,
|
|
657
|
-
if (!
|
|
658
|
-
|
|
634
|
+
(0, _trpc_server_unstable_core_do_not_import.run)(async () => {
|
|
635
|
+
if (!this.activeConnection.isOpen()) await this.open();
|
|
636
|
+
await (0, _trpc_server_unstable_core_do_not_import.sleep)(0);
|
|
637
|
+
if (!this.requestManager.hasOutgoingRequests()) return;
|
|
638
|
+
this.send(this.requestManager.flush().map(({ message }) => message));
|
|
659
639
|
}).catch((err) => {
|
|
660
640
|
this.requestManager.delete(message.id);
|
|
661
641
|
callbacks.error(require_TRPCClientError.TRPCClientError.from(err));
|
|
@@ -663,13 +643,11 @@ var WsClient = class {
|
|
|
663
643
|
return this.requestManager.register(message, callbacks);
|
|
664
644
|
}
|
|
665
645
|
};
|
|
666
|
-
|
|
667
646
|
//#endregion
|
|
668
647
|
//#region src/links/wsLink/createWsClient.ts
|
|
669
648
|
function createWSClient(opts) {
|
|
670
649
|
return new WsClient(opts);
|
|
671
650
|
}
|
|
672
|
-
|
|
673
651
|
//#endregion
|
|
674
652
|
//#region src/links/wsLink/wsLink.ts
|
|
675
653
|
function wsLink(opts) {
|
|
@@ -677,7 +655,7 @@ function wsLink(opts) {
|
|
|
677
655
|
const transformer = require_unstable_internals.getTransformer(opts.transformer);
|
|
678
656
|
return () => {
|
|
679
657
|
return ({ op }) => {
|
|
680
|
-
return (0,
|
|
658
|
+
return (0, _trpc_server_observable.observable)((observer) => {
|
|
681
659
|
const connStateSubscription = op.type === "subscription" ? client.connectionState.subscribe({ next(result) {
|
|
682
660
|
observer.next({
|
|
683
661
|
result,
|
|
@@ -696,29 +674,28 @@ function wsLink(opts) {
|
|
|
696
674
|
};
|
|
697
675
|
};
|
|
698
676
|
}
|
|
699
|
-
|
|
700
677
|
//#endregion
|
|
701
|
-
Object.defineProperty(exports,
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
678
|
+
Object.defineProperty(exports, "createWSClient", {
|
|
679
|
+
enumerable: true,
|
|
680
|
+
get: function() {
|
|
681
|
+
return createWSClient;
|
|
682
|
+
}
|
|
706
683
|
});
|
|
707
|
-
Object.defineProperty(exports,
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
684
|
+
Object.defineProperty(exports, "jsonEncoder", {
|
|
685
|
+
enumerable: true,
|
|
686
|
+
get: function() {
|
|
687
|
+
return jsonEncoder;
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
Object.defineProperty(exports, "resultOf", {
|
|
691
|
+
enumerable: true,
|
|
692
|
+
get: function() {
|
|
693
|
+
return resultOf;
|
|
694
|
+
}
|
|
712
695
|
});
|
|
713
|
-
Object.defineProperty(exports,
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
696
|
+
Object.defineProperty(exports, "wsLink", {
|
|
697
|
+
enumerable: true,
|
|
698
|
+
get: function() {
|
|
699
|
+
return wsLink;
|
|
700
|
+
}
|
|
718
701
|
});
|
|
719
|
-
Object.defineProperty(exports, 'wsLink', {
|
|
720
|
-
enumerable: true,
|
|
721
|
-
get: function () {
|
|
722
|
-
return wsLink;
|
|
723
|
-
}
|
|
724
|
-
});
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
import { TRPCConnectionState } from "./subscriptions
|
|
2
|
-
import {
|
|
3
|
-
import { TransformerOptions } from "./unstable-internals
|
|
4
|
-
import * as _trpc_server_observable0 from "@trpc/server/observable";
|
|
5
|
-
import { BehaviorSubject } from "@trpc/server/observable";
|
|
1
|
+
import { t as TRPCConnectionState } from "./subscriptions-DcqRZc4h.cjs";
|
|
2
|
+
import { a as OperationResultEnvelope, d as TRPCClientError, n as Operation, u as TRPCLink } from "./types-BxbMkv6C.cjs";
|
|
3
|
+
import { n as TransformerOptions } from "./unstable-internals-CE8gFBQ9.cjs";
|
|
6
4
|
import { AnyRouter, CombinedDataTransformer, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
|
|
5
|
+
import { BehaviorSubject } from "@trpc/server/observable";
|
|
7
6
|
import { AnyTRPCRouter } from "@trpc/server";
|
|
8
7
|
import { Encoder } from "@trpc/server/adapters/ws";
|
|
9
8
|
import { TRPCRequestInfo } from "@trpc/server/http";
|
|
10
|
-
|
|
11
9
|
//#region src/links/wsLink/wsClient/encoder.d.ts
|
|
12
10
|
declare const jsonEncoder: Encoder;
|
|
13
|
-
//# sourceMappingURL=encoder.d.ts.map
|
|
14
|
-
|
|
15
11
|
//#endregion
|
|
16
12
|
//#region src/links/internals/urlWithConnectionParams.d.ts
|
|
17
13
|
/**
|
|
@@ -30,7 +26,6 @@ interface UrlOptionsWithConnectionParams {
|
|
|
30
26
|
*/
|
|
31
27
|
connectionParams?: CallbackOrValue<TRPCRequestInfo['connectionParams']>;
|
|
32
28
|
}
|
|
33
|
-
//# sourceMappingURL=urlWithConnectionParams.d.ts.map
|
|
34
29
|
//#endregion
|
|
35
30
|
//#region src/links/wsLink/wsClient/options.d.ts
|
|
36
31
|
interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
|
|
@@ -97,10 +92,6 @@ interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
|
|
|
97
92
|
*/
|
|
98
93
|
experimental_encoder?: Encoder;
|
|
99
94
|
}
|
|
100
|
-
/**
|
|
101
|
-
* Default options for lazy WebSocket connections.
|
|
102
|
-
* Determines whether the connection should be established lazily and defines the delay before closure.
|
|
103
|
-
*/
|
|
104
95
|
//#endregion
|
|
105
96
|
//#region src/links/wsLink/wsClient/wsClient.d.ts
|
|
106
97
|
/**
|
|
@@ -141,32 +132,22 @@ declare class WsClient {
|
|
|
141
132
|
*
|
|
142
133
|
* @returns An observable that emits operation results and handles cleanup
|
|
143
134
|
*/
|
|
144
|
-
request({
|
|
145
|
-
op: {
|
|
146
|
-
id,
|
|
147
|
-
type,
|
|
148
|
-
path,
|
|
149
|
-
input,
|
|
150
|
-
signal
|
|
151
|
-
},
|
|
152
|
-
transformer,
|
|
153
|
-
lastEventId
|
|
154
|
-
}: {
|
|
135
|
+
request({ op: { id, type, path, input, signal }, transformer, lastEventId }: {
|
|
155
136
|
op: Pick<Operation, 'id' | 'type' | 'path' | 'input' | 'signal'>;
|
|
156
137
|
transformer: CombinedDataTransformer;
|
|
157
138
|
lastEventId?: string;
|
|
158
|
-
}):
|
|
139
|
+
}): import("@trpc/server/observable").Observable<OperationResultEnvelope<unknown, TRPCClientError<AnyTRPCRouter>>, TRPCClientError<AnyTRPCRouter>>;
|
|
159
140
|
get connection(): {
|
|
160
141
|
readonly id: number;
|
|
161
|
-
readonly state:
|
|
142
|
+
readonly state: 'open';
|
|
162
143
|
readonly ws: WebSocket;
|
|
163
144
|
} | {
|
|
164
145
|
readonly id: number;
|
|
165
|
-
readonly state:
|
|
146
|
+
readonly state: 'closed';
|
|
166
147
|
readonly ws: WebSocket;
|
|
167
148
|
} | {
|
|
168
149
|
readonly id: number;
|
|
169
|
-
readonly state:
|
|
150
|
+
readonly state: 'connecting';
|
|
170
151
|
readonly ws: WebSocket;
|
|
171
152
|
} | null;
|
|
172
153
|
/**
|
|
@@ -190,7 +171,6 @@ declare class WsClient {
|
|
|
190
171
|
*/
|
|
191
172
|
private batchSend;
|
|
192
173
|
}
|
|
193
|
-
//# sourceMappingURL=wsClient.d.ts.map
|
|
194
174
|
//#endregion
|
|
195
175
|
//#region src/links/wsLink/createWsClient.d.ts
|
|
196
176
|
declare function createWSClient(opts: WebSocketClientOptions): WsClient;
|
|
@@ -202,5 +182,5 @@ type WebSocketLinkOptions<TRouter extends AnyRouter> = {
|
|
|
202
182
|
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
203
183
|
declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>;
|
|
204
184
|
//#endregion
|
|
205
|
-
export {
|
|
206
|
-
//# sourceMappingURL=wsLink
|
|
185
|
+
export { WebSocketClientOptions as a, jsonEncoder as c, createWSClient as i, wsLink as n, UrlOptionsWithConnectionParams as o, TRPCWebSocketClient as r, Encoder as s, WebSocketLinkOptions as t };
|
|
186
|
+
//# sourceMappingURL=wsLink-DoiyfDgJ.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wsLink-DoiyfDgJ.d.cts","names":[],"sources":["../src/links/wsLink/wsClient/encoder.ts","../src/links/internals/urlWithConnectionParams.ts","../src/links/wsLink/wsClient/options.ts","../src/links/wsLink/wsClient/wsClient.ts","../src/links/wsLink/createWsClient.ts","../src/links/wsLink/wsLink.ts"],"mappings":";;;;;;;;;cAIa,aAAa;;;;;;KCcd,gBAAgB,KAAK,WAAW,IAAI,QAAQ;UAEvC;;;;EAIf,KAAK;;;;;;EAOL,mBAAmB,gBAAgB;;;;UC5BpB,+BAA+B;;;;EAI9C,mBAAmB;;;;;EAKnB,gBAAgB;;;;EAIhB;;;;EAIA,WAAW,MAAM;;;;EAIjB,WAAW;IAAU;;;;;EAIrB;;;;;IAKE;;;;;IAKA;;;;;EAKF;;;;IAIE;;;;;IAKA;;;;;IAKA;;;;;;EAMF,uBAAuB;;;;;;;;cChCZ;;;;WAIK,iBAAiB,gBAC/B,oBAAoB,gBAAgB;UAG9B;UACA;mBACS;mBACA;UACT;mBACS;mBAIA;mBACA;EAEjB,YAAY,MAAM;;;;;UAiEJ;;;;;EA2BD,SAAK;;;;;;;;;;;EAyCX,UACL,MAAM,IAAI,MAAM,MAAM,OAAO,UAC7B,aACA;IAEA,IAAI,KAAK;IACT,aAAa;IACb;wCACD,WAAA,iCAAA,gBAAA,iBAAA,gBAAA;MAsDU;;;;;;;;;;;;;;;;;;UASH;UACA;UAgCA;UAkFA;UAuBA;;;;UAaA;;;;;;UAqBA;;;;iBCtaM,eAAe,MAAM,yBAAsB;KAI/C,sBAAsB,kBAAkB;;;KCMxC,qBAAqB,gBAAgB;EAC/C,QAAQ;IACN,mBAAmB,iBAAiB;iBAExB,OAAO,gBAAgB,WACrC,MAAM,qBAAqB,WAC1B,SAAS"}
|