@trpc/client 11.18.1-canary.9 → 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.
Files changed (134) hide show
  1. package/bin/intent.js +0 -0
  2. package/dist/TRPCClientError-CmHlBkPF.cjs +56 -0
  3. package/dist/{TRPCClientError-apv8gw59.mjs → TRPCClientError-CxFRO7Js.mjs} +11 -14
  4. package/dist/TRPCClientError-CxFRO7Js.mjs.map +1 -0
  5. package/dist/{httpBatchLink-LhidKAPw.mjs → httpBatchLink-BMtWxLJV.mjs} +25 -72
  6. package/dist/httpBatchLink-BMtWxLJV.mjs.map +1 -0
  7. package/dist/{httpBatchLink.d-7jyWtY5H.d.cts → httpBatchLink-Br-pzPXf.d.cts} +4 -8
  8. package/dist/httpBatchLink-Br-pzPXf.d.cts.map +1 -0
  9. package/dist/{httpBatchLink-BGZRsGNf.cjs → httpBatchLink-DO3WQoxu.cjs} +37 -104
  10. package/dist/{httpBatchLink.d-p8Y9QM8p.d.mts → httpBatchLink-nvc48L_N.d.mts} +4 -8
  11. package/dist/httpBatchLink-nvc48L_N.d.mts.map +1 -0
  12. package/dist/{httpLink.d-CjpPCq4q.d.mts → httpLink-D5FQijY2.d.cts} +4 -7
  13. package/dist/httpLink-D5FQijY2.d.cts.map +1 -0
  14. package/dist/{httpLink-B8Iv31Ee.cjs → httpLink-MDJTSlpi.cjs} +39 -38
  15. package/dist/{httpLink-lG_6juPY.mjs → httpLink-Tm93WWFA.mjs} +17 -14
  16. package/dist/httpLink-Tm93WWFA.mjs.map +1 -0
  17. package/dist/{httpLink.d-D5qR9haY.d.cts → httpLink-eSAq8J9S.d.mts} +4 -7
  18. package/dist/httpLink-eSAq8J9S.d.mts.map +1 -0
  19. package/dist/{httpUtils.d-BqmeKEGo.d.cts → httpUtils-C37jRVnj.d.mts} +4 -6
  20. package/dist/httpUtils-C37jRVnj.d.mts.map +1 -0
  21. package/dist/{httpUtils-pyf5RF99.mjs → httpUtils-CB_100ND.mjs} +51 -14
  22. package/dist/httpUtils-CB_100ND.mjs.map +1 -0
  23. package/dist/{httpUtils.d-C5t5to0D.d.mts → httpUtils-CUqAubVD.d.cts} +4 -6
  24. package/dist/httpUtils-CUqAubVD.d.cts.map +1 -0
  25. package/dist/{httpUtils-wv2o-njD.cjs → httpUtils-cggqcHz0.cjs} +102 -49
  26. package/dist/index.cjs +248 -309
  27. package/dist/index.d.cts +38 -41
  28. package/dist/index.d.cts.map +1 -1
  29. package/dist/index.d.mts +38 -41
  30. package/dist/index.d.mts.map +1 -1
  31. package/dist/index.mjs +212 -272
  32. package/dist/index.mjs.map +1 -1
  33. package/dist/links/httpBatchLink.cjs +3 -7
  34. package/dist/links/httpBatchLink.d.cts +1 -5
  35. package/dist/links/httpBatchLink.d.mts +1 -5
  36. package/dist/links/httpBatchLink.mjs +2 -7
  37. package/dist/links/httpLink.cjs +3 -7
  38. package/dist/links/httpLink.d.cts +1 -5
  39. package/dist/links/httpLink.d.mts +1 -5
  40. package/dist/links/httpLink.mjs +2 -7
  41. package/dist/links/loggerLink.cjs +113 -4
  42. package/dist/links/loggerLink.d.cts +1 -3
  43. package/dist/links/loggerLink.d.mts +1 -3
  44. package/dist/links/loggerLink.mjs +113 -3
  45. package/dist/links/loggerLink.mjs.map +1 -0
  46. package/dist/links/splitLink.cjs +3 -3
  47. package/dist/links/splitLink.d.cts +1 -3
  48. package/dist/links/splitLink.d.mts +1 -3
  49. package/dist/links/splitLink.mjs +2 -3
  50. package/dist/links/wsLink/wsLink.cjs +3 -6
  51. package/dist/links/wsLink/wsLink.d.cts +2 -5
  52. package/dist/links/wsLink/wsLink.d.mts +2 -5
  53. package/dist/links/wsLink/wsLink.mjs +2 -6
  54. package/dist/{loggerLink.d-0ABgt7oh.d.mts → loggerLink-2o-uZ3r1.d.cts} +3 -4
  55. package/dist/loggerLink-2o-uZ3r1.d.cts.map +1 -0
  56. package/dist/{loggerLink.d-BxSIj5kx.d.cts → loggerLink-CFercTVc.d.mts} +3 -4
  57. package/dist/loggerLink-CFercTVc.d.mts.map +1 -0
  58. package/dist/objectSpread2-D-dJi1gK.cjs +73 -0
  59. package/dist/objectSpread2-weooBxVk.mjs +62 -0
  60. package/dist/{splitLink-B7Cuf2c_.mjs → splitLink-BZPioDdG.mjs} +6 -11
  61. package/dist/splitLink-BZPioDdG.mjs.map +1 -0
  62. package/dist/{splitLink.d-BBFK_mCw.d.cts → splitLink-CJdcmEmS.d.cts} +3 -6
  63. package/dist/splitLink-CJdcmEmS.d.cts.map +1 -0
  64. package/dist/{splitLink.d-CkHNg1Se.d.mts → splitLink-CixmF14P.d.mts} +3 -6
  65. package/dist/splitLink-CixmF14P.d.mts.map +1 -0
  66. package/dist/{splitLink-BMgxggng.cjs → splitLink-MXnaFlEb.cjs} +17 -24
  67. package/dist/{subscriptions.d-Ciljg_dH.d.cts → subscriptions-DcqRZc4h.d.cts} +2 -2
  68. package/dist/subscriptions-DcqRZc4h.d.cts.map +1 -0
  69. package/dist/{subscriptions.d-Dlr1nWGD.d.mts → subscriptions-DcqRZc4h.d.mts} +2 -2
  70. package/dist/subscriptions-DcqRZc4h.d.mts.map +1 -0
  71. package/dist/{types.d-CAr6snH0.d.mts → types-BxbMkv6C.d.cts} +4 -15
  72. package/dist/types-BxbMkv6C.d.cts.map +1 -0
  73. package/dist/{types.d-Dmmedc5G.d.cts → types-CAPs7vhA.d.mts} +4 -15
  74. package/dist/types-CAPs7vhA.d.mts.map +1 -0
  75. package/dist/{unstable-internals.d-BOmV7EK1.d.mts → unstable-internals-CE8gFBQ9.d.cts} +2 -4
  76. package/dist/unstable-internals-CE8gFBQ9.d.cts.map +1 -0
  77. package/dist/{unstable-internals.d-kWsZTlQq.d.cts → unstable-internals-CE8gFBQ9.d.mts} +2 -4
  78. package/dist/unstable-internals-CE8gFBQ9.d.mts.map +1 -0
  79. package/dist/unstable-internals.cjs +28 -3
  80. package/dist/unstable-internals.d.cts +2 -2
  81. package/dist/unstable-internals.d.mts +2 -2
  82. package/dist/unstable-internals.mjs +28 -2
  83. package/dist/unstable-internals.mjs.map +1 -0
  84. package/dist/{wsLink-DSf4KOdW.mjs → wsLink-Bm5LKL6z.mjs} +73 -94
  85. package/dist/wsLink-Bm5LKL6z.mjs.map +1 -0
  86. package/dist/{wsLink-CobRSm6C.cjs → wsLink-CKAsNP9P.cjs} +100 -123
  87. package/dist/{wsLink.d-pFN64NkG.d.mts → wsLink-DoiyfDgJ.d.cts} +11 -31
  88. package/dist/wsLink-DoiyfDgJ.d.cts.map +1 -0
  89. package/dist/{wsLink.d-DzZZZGZQ.d.cts → wsLink-U8pJ7LD2.d.mts} +11 -31
  90. package/dist/wsLink-U8pJ7LD2.d.mts.map +1 -0
  91. package/package.json +10 -10
  92. package/src/getFetch.ts +3 -2
  93. package/src/links/httpBatchLink.ts +12 -3
  94. package/src/links/httpBatchStreamLink.ts +7 -8
  95. package/src/links/httpLink.ts +9 -2
  96. package/src/links/httpSubscriptionLink.ts +1 -3
  97. package/src/links/internals/subscriptions.ts +3 -2
  98. package/src/links/types.ts +1 -2
  99. package/src/links/wsLink/wsClient/wsClient.ts +8 -1
  100. package/dist/TRPCClientError-CQrTQLrk.cjs +0 -61
  101. package/dist/TRPCClientError-apv8gw59.mjs.map +0 -1
  102. package/dist/chunk-DWy1uDak.cjs +0 -39
  103. package/dist/httpBatchLink-LhidKAPw.mjs.map +0 -1
  104. package/dist/httpBatchLink.d-7jyWtY5H.d.cts.map +0 -1
  105. package/dist/httpBatchLink.d-p8Y9QM8p.d.mts.map +0 -1
  106. package/dist/httpLink-lG_6juPY.mjs.map +0 -1
  107. package/dist/httpLink.d-CjpPCq4q.d.mts.map +0 -1
  108. package/dist/httpLink.d-D5qR9haY.d.cts.map +0 -1
  109. package/dist/httpUtils-pyf5RF99.mjs.map +0 -1
  110. package/dist/httpUtils.d-BqmeKEGo.d.cts.map +0 -1
  111. package/dist/httpUtils.d-C5t5to0D.d.mts.map +0 -1
  112. package/dist/loggerLink-CuYvRzyH.cjs +0 -123
  113. package/dist/loggerLink-ineCN1PO.mjs +0 -118
  114. package/dist/loggerLink-ineCN1PO.mjs.map +0 -1
  115. package/dist/loggerLink.d-0ABgt7oh.d.mts.map +0 -1
  116. package/dist/loggerLink.d-BxSIj5kx.d.cts.map +0 -1
  117. package/dist/objectSpread2-Bsvh_OqM.cjs +0 -100
  118. package/dist/objectSpread2-BvkFp-_Y.mjs +0 -114
  119. package/dist/objectSpread2-BvkFp-_Y.mjs.map +0 -1
  120. package/dist/splitLink-B7Cuf2c_.mjs.map +0 -1
  121. package/dist/splitLink.d-BBFK_mCw.d.cts.map +0 -1
  122. package/dist/splitLink.d-CkHNg1Se.d.mts.map +0 -1
  123. package/dist/subscriptions.d-Ciljg_dH.d.cts.map +0 -1
  124. package/dist/subscriptions.d-Dlr1nWGD.d.mts.map +0 -1
  125. package/dist/types.d-CAr6snH0.d.mts.map +0 -1
  126. package/dist/types.d-Dmmedc5G.d.cts.map +0 -1
  127. package/dist/unstable-internals-Bg7n9BBj.mjs +0 -29
  128. package/dist/unstable-internals-Bg7n9BBj.mjs.map +0 -1
  129. package/dist/unstable-internals-M84gUQCV.cjs +0 -34
  130. package/dist/unstable-internals.d-BOmV7EK1.d.mts.map +0 -1
  131. package/dist/unstable-internals.d-kWsZTlQq.d.cts.map +0 -1
  132. package/dist/wsLink-DSf4KOdW.mjs.map +0 -1
  133. package/dist/wsLink.d-DzZZZGZQ.d.cts.map +0 -1
  134. package/dist/wsLink.d-pFN64NkG.d.mts.map +0 -1
@@ -1,10 +1,8 @@
1
- const require_chunk = require('./chunk-DWy1uDak.cjs');
2
- const require_objectSpread2$1 = require('./objectSpread2-Bsvh_OqM.cjs');
3
- const require_TRPCClientError = require('./TRPCClientError-CQrTQLrk.cjs');
4
- const require_unstable_internals = require('./unstable-internals-M84gUQCV.cjs');
5
- const __trpc_server_observable = require_chunk.__toESM(require("@trpc/server/observable"));
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
- (0, import_defineProperty$3.default)(this, "timeout", void 0);
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
- const prefix = url.includes("?") ? "&" : "?";
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
- (0, import_defineProperty$2.default)(this, "outgoingRequests", new Array());
132
- (0, import_defineProperty$2.default)(this, "pendingRequests", {});
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
- (0, import_defineProperty$1.default)(this, "id", ++WsConnection.connectCount);
313
- (0, import_defineProperty$1.default)(this, "WebSocketPonyfill", void 0);
314
- (0, import_defineProperty$1.default)(this, "urlOptions", void 0);
315
- (0, import_defineProperty$1.default)(this, "keepAliveOpts", void 0);
316
- (0, import_defineProperty$1.default)(this, "encoder", void 0);
317
- (0, import_defineProperty$1.default)(this, "wsObservable", (0, __trpc_server_observable.behaviorSubject)(null));
318
- (0, import_defineProperty$1.default)(this, "openPromise", null);
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
- var _this = this;
345
- if (_this.openPromise) return _this.openPromise;
346
- _this.id = ++WsConnection.connectCount;
347
- const wsPromise = prepareUrl(_this.urlOptions).then((url) => new _this.WebSocketPonyfill(url));
348
- _this.openPromise = wsPromise.then(async (ws) => {
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 (_this.keepAliveOpts.enabled) setupPingInterval(ws, _this.keepAliveOpts);
340
+ if (this.keepAliveOpts.enabled) setupPingInterval(ws, this.keepAliveOpts);
355
341
  ws.addEventListener("close", () => {
356
- if (_this.ws === ws) _this.ws = null;
342
+ if (this.ws === ws) this.ws = null;
357
343
  });
358
344
  await asyncWsOpen(ws);
359
- if (_this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(_this.urlOptions.connectionParams, _this.encoder));
345
+ if (this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(this.urlOptions.connectionParams, this.encoder));
360
346
  });
361
347
  try {
362
- await _this.openPromise;
348
+ await this.openPromise;
363
349
  } finally {
364
- _this.openPromise = null;
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 _this2.openPromise;
359
+ await this.openPromise;
375
360
  } finally {
376
361
  var _this$ws;
377
- (_this$ws = _this2.ws) === null || _this$ws === void 0 || _this$ws.close();
362
+ (_this$ws = this.ws) === null || _this$ws === void 0 || _this$ws.close();
378
363
  }
379
364
  }
380
365
  };
381
- (0, import_defineProperty$1.default)(WsConnection, "connectCount", 0);
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
- (0, import_defineProperty.default)(this, "connectionState", void 0);
416
- (0, import_defineProperty.default)(this, "allowReconnect", false);
417
- (0, import_defineProperty.default)(this, "requestManager", new RequestManager());
418
- (0, import_defineProperty.default)(this, "activeConnection", void 0);
419
- (0, import_defineProperty.default)(this, "reconnectRetryDelay", void 0);
420
- (0, import_defineProperty.default)(this, "inactivityTimeout", void 0);
421
- (0, import_defineProperty.default)(this, "callbacks", void 0);
422
- (0, import_defineProperty.default)(this, "lazyMode", void 0);
423
- (0, import_defineProperty.default)(this, "encoder", void 0);
424
- (0, import_defineProperty.default)(this, "reconnecting", null);
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 = (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, lazyDefaults), opts.lazy);
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: (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, keepAliveDefaults), opts.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, __trpc_server_observable.behaviorSubject)({
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
- var _this = this;
464
- _this.allowReconnect = true;
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 _this.activeConnection.open();
452
+ await this.activeConnection.open();
472
453
  } catch (error) {
473
- _this.reconnect(new TRPCWebSocketClosedError({
454
+ this.reconnect(new TRPCWebSocketClosedError({
474
455
  message: "Initialization error",
475
456
  cause: error
476
457
  }));
477
- return _this.reconnecting;
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
- var _this2 = this;
486
- _this2.allowReconnect = false;
487
- _this2.inactivityTimeout.stop();
466
+ this.allowReconnect = false;
467
+ this.inactivityTimeout.stop();
488
468
  const requestsToAwait = [];
489
- for (const request of _this2.requestManager.getRequests()) if (request.message.method === "subscription") request.callbacks.complete();
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 _this2.activeConnection.close().catch(() => null);
494
- _this2.connectionState.next({
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, __trpc_server_observable.observable)((observer) => {
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
- }, (0, import_objectSpread2.default)((0, import_objectSpread2.default)({}, observer), {}, { next(event) {
521
- const transformed = (0, __trpc_server_unstable_core_do_not_import.transformResult)(event, transformer.output);
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", 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, __trpc_server_unstable_core_do_not_import.sleep)(_this3.reconnectRetryDelay(attemptIndex));
552
- if (_this3.allowReconnect) {
553
- await _this3.activeConnection.close();
554
- await _this3.activeConnection.open();
555
- if (_this3.requestManager.hasPendingRequests()) _this3.send(_this3.requestManager.getPendingRequests().map(({ message }) => message));
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
- _this3.reconnecting = null;
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, __trpc_server_unstable_core_do_not_import.run)(async () => {
559
+ (0, _trpc_server_unstable_core_do_not_import.run)(async () => {
579
560
  var _this$callbacks$onOpe, _this$callbacks;
580
- if (_this4.lazyMode) _this4.inactivityTimeout.start();
581
- (_this$callbacks$onOpe = (_this$callbacks = _this4.callbacks).onOpen) === null || _this$callbacks$onOpe === void 0 || _this$callbacks$onOpe.call(_this$callbacks);
582
- _this4.connectionState.next({
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, __trpc_server_unstable_core_do_not_import.run)(async () => {
655
- if (!_this5.activeConnection.isOpen()) await _this5.open();
656
- await (0, __trpc_server_unstable_core_do_not_import.sleep)(0);
657
- if (!_this5.requestManager.hasOutgoingRequests()) return;
658
- _this5.send(_this5.requestManager.flush().map(({ message: message$1 }) => message$1));
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, __trpc_server_observable.observable)((observer) => {
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, 'createWSClient', {
702
- enumerable: true,
703
- get: function () {
704
- return createWSClient;
705
- }
678
+ Object.defineProperty(exports, "createWSClient", {
679
+ enumerable: true,
680
+ get: function() {
681
+ return createWSClient;
682
+ }
706
683
  });
707
- Object.defineProperty(exports, 'jsonEncoder', {
708
- enumerable: true,
709
- get: function () {
710
- return jsonEncoder;
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, 'resultOf', {
714
- enumerable: true,
715
- get: function () {
716
- return resultOf;
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.d-Dlr1nWGD.mjs";
2
- import { Operation, OperationResultEnvelope, TRPCClientError, TRPCLink } from "./types.d-CAr6snH0.mjs";
3
- import { TransformerOptions } from "./unstable-internals.d-BOmV7EK1.mjs";
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
- }): _trpc_server_observable0.Observable<OperationResultEnvelope<unknown, TRPCClientError<AnyTRPCRouter>>, TRPCClientError<AnyTRPCRouter>>;
139
+ }): import("@trpc/server/observable").Observable<OperationResultEnvelope<unknown, TRPCClientError<AnyTRPCRouter>>, TRPCClientError<AnyTRPCRouter>>;
159
140
  get connection(): {
160
141
  readonly id: number;
161
- readonly state: "open";
142
+ readonly state: 'open';
162
143
  readonly ws: WebSocket;
163
144
  } | {
164
145
  readonly id: number;
165
- readonly state: "closed";
146
+ readonly state: 'closed';
166
147
  readonly ws: WebSocket;
167
148
  } | {
168
149
  readonly id: number;
169
- readonly state: "connecting";
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 { Encoder, TRPCWebSocketClient, UrlOptionsWithConnectionParams, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, jsonEncoder, wsLink };
206
- //# sourceMappingURL=wsLink.d-pFN64NkG.d.mts.map
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"}