@trpc/client 11.1.2 → 11.1.3-alpha-tmp-tsdown.23

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 (234) hide show
  1. package/dist/TRPCClientError.d.mts +33 -0
  2. package/dist/TRPCClientError.d.mts.map +1 -0
  3. package/dist/TRPCClientError.d.ts +29 -25
  4. package/dist/TRPCClientError.d.ts.map +1 -1
  5. package/dist/TRPCClientError.js +48 -72
  6. package/dist/TRPCClientError.mjs +48 -71
  7. package/dist/TRPCClientError.mjs.map +1 -0
  8. package/dist/_virtual/rolldown_runtime.js +39 -0
  9. package/dist/_virtual/rolldown_runtime.mjs +27 -0
  10. package/dist/createTRPCClient.d.mts +73 -0
  11. package/dist/createTRPCClient.d.mts.map +1 -0
  12. package/dist/createTRPCClient.d.ts +38 -34
  13. package/dist/createTRPCClient.d.ts.map +1 -1
  14. package/dist/createTRPCClient.js +34 -34
  15. package/dist/createTRPCClient.mjs +33 -31
  16. package/dist/createTRPCClient.mjs.map +1 -0
  17. package/dist/createTRPCUntypedClient.d.mts +9 -0
  18. package/dist/createTRPCUntypedClient.d.mts.map +1 -0
  19. package/dist/createTRPCUntypedClient.d.ts +8 -6
  20. package/dist/createTRPCUntypedClient.d.ts.map +1 -1
  21. package/dist/createTRPCUntypedClient.js +5 -6
  22. package/dist/createTRPCUntypedClient.mjs +6 -3
  23. package/dist/createTRPCUntypedClient.mjs.map +1 -0
  24. package/dist/getFetch.d.mts +10 -0
  25. package/dist/getFetch.d.mts.map +1 -0
  26. package/dist/getFetch.d.ts +9 -2
  27. package/dist/getFetch.d.ts.map +1 -1
  28. package/dist/getFetch.js +8 -13
  29. package/dist/getFetch.mjs +8 -11
  30. package/dist/getFetch.mjs.map +1 -0
  31. package/dist/index.d.mts +21 -0
  32. package/dist/index.d.ts +21 -16
  33. package/dist/index.js +41 -42
  34. package/dist/index.mjs +18 -15
  35. package/dist/internals/TRPCUntypedClient.d.mts +46 -0
  36. package/dist/internals/TRPCUntypedClient.d.mts.map +1 -0
  37. package/dist/internals/TRPCUntypedClient.d.ts +40 -33
  38. package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
  39. package/dist/internals/TRPCUntypedClient.js +94 -113
  40. package/dist/internals/TRPCUntypedClient.mjs +93 -110
  41. package/dist/internals/TRPCUntypedClient.mjs.map +1 -0
  42. package/dist/internals/dataLoader.js +101 -116
  43. package/dist/internals/dataLoader.mjs +101 -114
  44. package/dist/internals/dataLoader.mjs.map +1 -0
  45. package/dist/internals/inputWithTrackedEventId.js +9 -12
  46. package/dist/internals/inputWithTrackedEventId.mjs +9 -10
  47. package/dist/internals/inputWithTrackedEventId.mjs.map +1 -0
  48. package/dist/internals/signals.js +39 -40
  49. package/dist/internals/signals.mjs +39 -39
  50. package/dist/internals/signals.mjs.map +1 -0
  51. package/dist/internals/transformer.d.mts +47 -0
  52. package/dist/internals/transformer.d.mts.map +1 -0
  53. package/dist/internals/transformer.d.ts +28 -23
  54. package/dist/internals/transformer.d.ts.map +1 -1
  55. package/dist/internals/transformer.js +25 -26
  56. package/dist/internals/transformer.mjs +25 -24
  57. package/dist/internals/transformer.mjs.map +1 -0
  58. package/dist/internals/types.d.mts +85 -0
  59. package/dist/internals/types.d.mts.map +1 -0
  60. package/dist/internals/types.d.ts +45 -42
  61. package/dist/internals/types.d.ts.map +1 -1
  62. package/dist/links/HTTPBatchLinkOptions.d.mts +25 -0
  63. package/dist/links/HTTPBatchLinkOptions.d.mts.map +1 -0
  64. package/dist/links/HTTPBatchLinkOptions.d.ts +23 -18
  65. package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
  66. package/dist/links/httpBatchLink.d.mts +18 -0
  67. package/dist/links/httpBatchLink.d.mts.map +1 -0
  68. package/dist/links/httpBatchLink.d.ts +14 -4
  69. package/dist/links/httpBatchLink.d.ts.map +1 -1
  70. package/dist/links/httpBatchLink.js +90 -106
  71. package/dist/links/httpBatchLink.mjs +89 -103
  72. package/dist/links/httpBatchLink.mjs.map +1 -0
  73. package/dist/links/httpBatchStreamLink.d.mts +22 -0
  74. package/dist/links/httpBatchStreamLink.d.mts.map +1 -0
  75. package/dist/links/httpBatchStreamLink.d.ts +15 -5
  76. package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
  77. package/dist/links/httpBatchStreamLink.js +120 -144
  78. package/dist/links/httpBatchStreamLink.mjs +119 -141
  79. package/dist/links/httpBatchStreamLink.mjs.map +1 -0
  80. package/dist/links/httpLink.d.mts +24 -0
  81. package/dist/links/httpLink.d.mts.map +1 -0
  82. package/dist/links/httpLink.d.ts +19 -12
  83. package/dist/links/httpLink.d.ts.map +1 -1
  84. package/dist/links/httpLink.js +74 -90
  85. package/dist/links/httpLink.mjs +73 -87
  86. package/dist/links/httpLink.mjs.map +1 -0
  87. package/dist/links/httpSubscriptionLink.d.mts +30 -0
  88. package/dist/links/httpSubscriptionLink.d.mts.map +1 -0
  89. package/dist/links/httpSubscriptionLink.d.ts +21 -17
  90. package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
  91. package/dist/links/httpSubscriptionLink.js +134 -179
  92. package/dist/links/httpSubscriptionLink.mjs +133 -176
  93. package/dist/links/httpSubscriptionLink.mjs.map +1 -0
  94. package/dist/links/internals/contentTypes.d.mts +10 -0
  95. package/dist/links/internals/contentTypes.d.mts.map +1 -0
  96. package/dist/links/internals/contentTypes.d.ts +9 -3
  97. package/dist/links/internals/contentTypes.d.ts.map +1 -1
  98. package/dist/links/internals/contentTypes.js +6 -6
  99. package/dist/links/internals/contentTypes.mjs +6 -4
  100. package/dist/links/internals/contentTypes.mjs.map +1 -0
  101. package/dist/links/internals/createChain.js +23 -23
  102. package/dist/links/internals/createChain.mjs +22 -20
  103. package/dist/links/internals/createChain.mjs.map +1 -0
  104. package/dist/links/internals/httpUtils.d.mts +26 -0
  105. package/dist/links/internals/httpUtils.d.mts.map +1 -0
  106. package/dist/links/internals/httpUtils.d.ts +22 -64
  107. package/dist/links/internals/httpUtils.d.ts.map +1 -1
  108. package/dist/links/internals/httpUtils.js +93 -116
  109. package/dist/links/internals/httpUtils.mjs +94 -113
  110. package/dist/links/internals/httpUtils.mjs.map +1 -0
  111. package/dist/links/internals/subscriptions.d.mts +20 -0
  112. package/dist/links/internals/subscriptions.d.mts.map +1 -0
  113. package/dist/links/internals/subscriptions.d.ts +11 -8
  114. package/dist/links/internals/subscriptions.d.ts.map +1 -1
  115. package/dist/links/internals/urlWithConnectionParams.d.mts +27 -0
  116. package/dist/links/internals/urlWithConnectionParams.d.mts.map +1 -0
  117. package/dist/links/internals/urlWithConnectionParams.d.ts +22 -18
  118. package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
  119. package/dist/links/internals/urlWithConnectionParams.js +8 -6
  120. package/dist/links/internals/urlWithConnectionParams.mjs +8 -4
  121. package/dist/links/internals/urlWithConnectionParams.mjs.map +1 -0
  122. package/dist/links/localLink.d.mts +22 -0
  123. package/dist/links/localLink.d.mts.map +1 -0
  124. package/dist/links/localLink.d.ts +22 -0
  125. package/dist/links/localLink.d.ts.map +1 -0
  126. package/dist/links/localLink.js +192 -0
  127. package/dist/links/localLink.mjs +193 -0
  128. package/dist/links/localLink.mjs.map +1 -0
  129. package/dist/links/loggerLink.d.mts +56 -0
  130. package/dist/links/loggerLink.d.mts.map +1 -0
  131. package/dist/links/loggerLink.d.ts +40 -36
  132. package/dist/links/loggerLink.d.ts.map +1 -1
  133. package/dist/links/loggerLink.js +113 -166
  134. package/dist/links/loggerLink.mjs +112 -163
  135. package/dist/links/loggerLink.mjs.map +1 -0
  136. package/dist/links/retryLink.d.mts +35 -0
  137. package/dist/links/retryLink.d.mts.map +1 -0
  138. package/dist/links/retryLink.d.ts +27 -25
  139. package/dist/links/retryLink.d.ts.map +1 -1
  140. package/dist/links/retryLink.js +60 -68
  141. package/dist/links/retryLink.mjs +59 -65
  142. package/dist/links/retryLink.mjs.map +1 -0
  143. package/dist/links/splitLink.d.mts +21 -0
  144. package/dist/links/splitLink.d.mts.map +1 -0
  145. package/dist/links/splitLink.d.ts +19 -12
  146. package/dist/links/splitLink.d.ts.map +1 -1
  147. package/dist/links/splitLink.js +20 -21
  148. package/dist/links/splitLink.mjs +19 -18
  149. package/dist/links/splitLink.mjs.map +1 -0
  150. package/dist/links/types.d.mts +71 -0
  151. package/dist/links/types.d.mts.map +1 -0
  152. package/dist/links/types.d.ts +37 -29
  153. package/dist/links/types.d.ts.map +1 -1
  154. package/dist/links/wsLink/createWsClient.d.mts +10 -0
  155. package/dist/links/wsLink/createWsClient.d.mts.map +1 -0
  156. package/dist/links/wsLink/createWsClient.d.ts +9 -5
  157. package/dist/links/wsLink/createWsClient.d.ts.map +1 -1
  158. package/dist/links/wsLink/createWsClient.js +5 -5
  159. package/dist/links/wsLink/createWsClient.mjs +5 -2
  160. package/dist/links/wsLink/createWsClient.mjs.map +1 -0
  161. package/dist/links/wsLink/wsClient/options.d.mts +69 -0
  162. package/dist/links/wsLink/wsClient/options.d.mts.map +1 -0
  163. package/dist/links/wsLink/wsClient/options.d.ts +54 -64
  164. package/dist/links/wsLink/wsClient/options.d.ts.map +1 -1
  165. package/dist/links/wsLink/wsClient/options.js +14 -12
  166. package/dist/links/wsLink/wsClient/options.mjs +14 -10
  167. package/dist/links/wsLink/wsClient/options.mjs.map +1 -0
  168. package/dist/links/wsLink/wsClient/requestManager.js +133 -135
  169. package/dist/links/wsLink/wsClient/requestManager.mjs +133 -132
  170. package/dist/links/wsLink/wsClient/requestManager.mjs.map +1 -0
  171. package/dist/links/wsLink/wsClient/utils.js +64 -81
  172. package/dist/links/wsLink/wsClient/utils.mjs +64 -78
  173. package/dist/links/wsLink/wsClient/utils.mjs.map +1 -0
  174. package/dist/links/wsLink/wsClient/wsClient.d.mts +104 -0
  175. package/dist/links/wsLink/wsClient/wsClient.d.mts.map +1 -0
  176. package/dist/links/wsLink/wsClient/wsClient.d.ts +99 -79
  177. package/dist/links/wsLink/wsClient/wsClient.d.ts.map +1 -1
  178. package/dist/links/wsLink/wsClient/wsClient.js +273 -322
  179. package/dist/links/wsLink/wsClient/wsClient.mjs +272 -319
  180. package/dist/links/wsLink/wsClient/wsClient.mjs.map +1 -0
  181. package/dist/links/wsLink/wsClient/wsConnection.js +155 -178
  182. package/dist/links/wsLink/wsClient/wsConnection.mjs +154 -175
  183. package/dist/links/wsLink/wsClient/wsConnection.mjs.map +1 -0
  184. package/dist/links/wsLink/wsLink.d.mts +15 -0
  185. package/dist/links/wsLink/wsLink.d.mts.map +1 -0
  186. package/dist/links/wsLink/wsLink.d.ts +13 -9
  187. package/dist/links/wsLink/wsLink.d.ts.map +1 -1
  188. package/dist/links/wsLink/wsLink.js +30 -31
  189. package/dist/links/wsLink/wsLink.mjs +29 -28
  190. package/dist/links/wsLink/wsLink.mjs.map +1 -0
  191. package/dist/links.js +11 -0
  192. package/dist/links.mjs +11 -0
  193. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +68 -0
  194. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +66 -0
  195. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs.map +1 -0
  196. package/dist/unstable-internals.d.mts +3 -0
  197. package/dist/unstable-internals.d.ts +3 -3
  198. package/dist/unstable-internals.js +2 -6
  199. package/dist/unstable-internals.mjs +3 -1
  200. package/links/httpBatchLink/package.json +1 -0
  201. package/links/httpLink/package.json +1 -0
  202. package/links/loggerLink/package.json +1 -0
  203. package/links/splitLink/package.json +1 -0
  204. package/links/wsLink/wsLink/package.json +1 -0
  205. package/package.json +64 -29
  206. package/src/TRPCClientError.ts +4 -9
  207. package/src/internals/dataLoader.ts +2 -6
  208. package/src/internals/signals.ts +16 -0
  209. package/src/links/httpSubscriptionLink.ts +3 -18
  210. package/src/links/localLink.ts +277 -0
  211. package/src/links/wsLink/wsClient/requestManager.ts +9 -0
  212. package/src/links/wsLink/wsClient/wsClient.ts +1 -1
  213. package/src/links.ts +1 -0
  214. package/unstable-internals/package.json +1 -0
  215. package/dist/index.d.ts.map +0 -1
  216. package/dist/internals/dataLoader.d.ts +0 -13
  217. package/dist/internals/dataLoader.d.ts.map +0 -1
  218. package/dist/internals/inputWithTrackedEventId.d.ts +0 -2
  219. package/dist/internals/inputWithTrackedEventId.d.ts.map +0 -1
  220. package/dist/internals/signals.d.ts +0 -15
  221. package/dist/internals/signals.d.ts.map +0 -1
  222. package/dist/links/internals/createChain.d.ts +0 -8
  223. package/dist/links/internals/createChain.d.ts.map +0 -1
  224. package/dist/links/internals/dedupeLink.d.ts +0 -7
  225. package/dist/links/internals/dedupeLink.d.ts.map +0 -1
  226. package/dist/links/wsLink/wsClient/requestManager.d.ts +0 -102
  227. package/dist/links/wsLink/wsClient/requestManager.d.ts.map +0 -1
  228. package/dist/links/wsLink/wsClient/utils.d.ts +0 -38
  229. package/dist/links/wsLink/wsClient/utils.d.ts.map +0 -1
  230. package/dist/links/wsLink/wsClient/wsConnection.d.ts +0 -79
  231. package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +0 -1
  232. package/dist/links.d.ts +0 -11
  233. package/dist/links.d.ts.map +0 -1
  234. package/dist/unstable-internals.d.ts.map +0 -1
@@ -1,185 +1,164 @@
1
- import { behaviorSubject } from '@trpc/server/observable';
2
- import { prepareUrl, buildConnectionMessage, withResolvers } from './utils.mjs';
1
+ import { buildConnectionMessage, prepareUrl, withResolvers } from "./utils.mjs";
2
+ import { behaviorSubject } from "@trpc/server/observable";
3
3
 
4
- function _define_property(obj, key, value) {
5
- if (key in obj) {
6
- Object.defineProperty(obj, key, {
7
- value: value,
8
- enumerable: true,
9
- configurable: true,
10
- writable: true
11
- });
12
- } else {
13
- obj[key] = value;
14
- }
15
- return obj;
16
- }
4
+ //#region src/links/wsLink/wsClient/wsConnection.ts
17
5
  /**
18
- * Opens a WebSocket connection asynchronously and returns a promise
19
- * that resolves when the connection is successfully established.
20
- * The promise rejects if an error occurs during the connection attempt.
21
- */ function asyncWsOpen(ws) {
22
- const { promise, resolve, reject } = withResolvers();
23
- ws.addEventListener('open', ()=>{
24
- ws.removeEventListener('error', reject);
25
- resolve();
26
- });
27
- ws.addEventListener('error', reject);
28
- return promise;
6
+ * Opens a WebSocket connection asynchronously and returns a promise
7
+ * that resolves when the connection is successfully established.
8
+ * The promise rejects if an error occurs during the connection attempt.
9
+ */
10
+ function asyncWsOpen(ws) {
11
+ const { promise, resolve, reject } = withResolvers();
12
+ ws.addEventListener("open", () => {
13
+ ws.removeEventListener("error", reject);
14
+ resolve();
15
+ });
16
+ ws.addEventListener("error", reject);
17
+ return promise;
29
18
  }
30
19
  /**
31
- * Sets up a periodic ping-pong mechanism to keep the WebSocket connection alive.
32
- *
33
- * - Sends "PING" messages at regular intervals defined by `intervalMs`.
34
- * - If a "PONG" response is not received within the `pongTimeoutMs`, the WebSocket is closed.
35
- * - The ping timer resets upon receiving any message to maintain activity.
36
- * - Automatically starts the ping process when the WebSocket connection is opened.
37
- * - Cleans up timers when the WebSocket is closed.
38
- *
39
- * @param ws - The WebSocket instance to manage.
40
- * @param options - Configuration options for ping-pong intervals and timeouts.
41
- */ function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
42
- let pingTimeout;
43
- let pongTimeout;
44
- function start() {
45
- pingTimeout = setTimeout(()=>{
46
- ws.send('PING');
47
- pongTimeout = setTimeout(()=>{
48
- ws.close();
49
- }, pongTimeoutMs);
50
- }, intervalMs);
51
- }
52
- function reset() {
53
- clearTimeout(pingTimeout);
54
- start();
55
- }
56
- function pong() {
57
- clearTimeout(pongTimeout);
58
- reset();
59
- }
60
- ws.addEventListener('open', start);
61
- ws.addEventListener('message', ({ data })=>{
62
- clearTimeout(pingTimeout);
63
- start();
64
- if (data === 'PONG') {
65
- pong();
66
- }
67
- });
68
- ws.addEventListener('close', ()=>{
69
- clearTimeout(pingTimeout);
70
- clearTimeout(pongTimeout);
71
- });
20
+ * Sets up a periodic ping-pong mechanism to keep the WebSocket connection alive.
21
+ *
22
+ * - Sends "PING" messages at regular intervals defined by `intervalMs`.
23
+ * - If a "PONG" response is not received within the `pongTimeoutMs`, the WebSocket is closed.
24
+ * - The ping timer resets upon receiving any message to maintain activity.
25
+ * - Automatically starts the ping process when the WebSocket connection is opened.
26
+ * - Cleans up timers when the WebSocket is closed.
27
+ *
28
+ * @param ws - The WebSocket instance to manage.
29
+ * @param options - Configuration options for ping-pong intervals and timeouts.
30
+ */
31
+ function setupPingInterval(ws, { intervalMs, pongTimeoutMs }) {
32
+ let pingTimeout;
33
+ let pongTimeout;
34
+ function start() {
35
+ pingTimeout = setTimeout(() => {
36
+ ws.send("PING");
37
+ pongTimeout = setTimeout(() => {
38
+ ws.close();
39
+ }, pongTimeoutMs);
40
+ }, intervalMs);
41
+ }
42
+ function reset() {
43
+ clearTimeout(pingTimeout);
44
+ start();
45
+ }
46
+ function pong() {
47
+ clearTimeout(pongTimeout);
48
+ reset();
49
+ }
50
+ ws.addEventListener("open", start);
51
+ ws.addEventListener("message", ({ data }) => {
52
+ clearTimeout(pingTimeout);
53
+ start();
54
+ if (data === "PONG") pong();
55
+ });
56
+ ws.addEventListener("close", () => {
57
+ clearTimeout(pingTimeout);
58
+ clearTimeout(pongTimeout);
59
+ });
72
60
  }
73
61
  /**
74
- * Manages a WebSocket connection with support for reconnection, keep-alive mechanisms,
75
- * and observable state tracking.
76
- */ class WsConnection {
77
- get ws() {
78
- return this.wsObservable.get();
79
- }
80
- set ws(ws) {
81
- this.wsObservable.next(ws);
82
- }
83
- /**
84
- * Checks if the WebSocket connection is open and ready to communicate.
85
- */ isOpen() {
86
- return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise;
87
- }
88
- /**
89
- * Checks if the WebSocket connection is closed or in the process of closing.
90
- */ isClosed() {
91
- return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
92
- }
93
- async open() {
94
- if (this.openPromise) return this.openPromise;
95
- this.id = ++WsConnection.connectCount;
96
- const wsPromise = prepareUrl(this.urlOptions).then((url)=>new this.WebSocketPonyfill(url));
97
- this.openPromise = wsPromise.then(async (ws)=>{
98
- this.ws = ws;
99
- // Setup ping listener
100
- ws.addEventListener('message', function({ data }) {
101
- if (data === 'PING') {
102
- this.send('PONG');
103
- }
104
- });
105
- if (this.keepAliveOpts.enabled) {
106
- setupPingInterval(ws, this.keepAliveOpts);
107
- }
108
- ws.addEventListener('close', ()=>{
109
- if (this.ws === ws) {
110
- this.ws = null;
111
- }
112
- });
113
- await asyncWsOpen(ws);
114
- if (this.urlOptions.connectionParams) {
115
- ws.send(await buildConnectionMessage(this.urlOptions.connectionParams));
116
- }
117
- });
118
- try {
119
- await this.openPromise;
120
- } finally{
121
- this.openPromise = null;
122
- }
123
- }
124
- /**
125
- * Closes the WebSocket connection gracefully.
126
- * Waits for any ongoing open operation to complete before closing.
127
- */ async close() {
128
- try {
129
- await this.openPromise;
130
- } finally{
131
- this.ws?.close();
132
- }
133
- }
134
- constructor(opts){
135
- _define_property(this, "id", ++WsConnection.connectCount);
136
- _define_property(this, "WebSocketPonyfill", void 0);
137
- _define_property(this, "urlOptions", void 0);
138
- _define_property(this, "keepAliveOpts", void 0);
139
- _define_property(this, "wsObservable", behaviorSubject(null));
140
- /**
141
- * Manages the WebSocket opening process, ensuring that only one open operation
142
- * occurs at a time. Tracks the ongoing operation with `openPromise` to avoid
143
- * redundant calls and ensure proper synchronization.
144
- *
145
- * Sets up the keep-alive mechanism and necessary event listeners for the connection.
146
- *
147
- * @returns A promise that resolves once the WebSocket connection is successfully opened.
148
- */ _define_property(this, "openPromise", null);
149
- this.WebSocketPonyfill = opts.WebSocketPonyfill ?? WebSocket;
150
- if (!this.WebSocketPonyfill) {
151
- 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");
152
- }
153
- this.urlOptions = opts.urlOptions;
154
- this.keepAliveOpts = opts.keepAlive;
155
- }
156
- }
157
- _define_property(WsConnection, "connectCount", 0);
62
+ * Manages a WebSocket connection with support for reconnection, keep-alive mechanisms,
63
+ * and observable state tracking.
64
+ */
65
+ var WsConnection = class WsConnection {
66
+ static connectCount = 0;
67
+ id = ++WsConnection.connectCount;
68
+ WebSocketPonyfill;
69
+ urlOptions;
70
+ keepAliveOpts;
71
+ wsObservable = behaviorSubject(null);
72
+ constructor(opts) {
73
+ this.WebSocketPonyfill = opts.WebSocketPonyfill ?? WebSocket;
74
+ 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");
75
+ this.urlOptions = opts.urlOptions;
76
+ this.keepAliveOpts = opts.keepAlive;
77
+ }
78
+ get ws() {
79
+ return this.wsObservable.get();
80
+ }
81
+ set ws(ws) {
82
+ this.wsObservable.next(ws);
83
+ }
84
+ /**
85
+ * Checks if the WebSocket connection is open and ready to communicate.
86
+ */
87
+ isOpen() {
88
+ return !!this.ws && this.ws.readyState === this.WebSocketPonyfill.OPEN && !this.openPromise;
89
+ }
90
+ /**
91
+ * Checks if the WebSocket connection is closed or in the process of closing.
92
+ */
93
+ isClosed() {
94
+ return !!this.ws && (this.ws.readyState === this.WebSocketPonyfill.CLOSING || this.ws.readyState === this.WebSocketPonyfill.CLOSED);
95
+ }
96
+ /**
97
+ * Manages the WebSocket opening process, ensuring that only one open operation
98
+ * occurs at a time. Tracks the ongoing operation with `openPromise` to avoid
99
+ * redundant calls and ensure proper synchronization.
100
+ *
101
+ * Sets up the keep-alive mechanism and necessary event listeners for the connection.
102
+ *
103
+ * @returns A promise that resolves once the WebSocket connection is successfully opened.
104
+ */
105
+ openPromise = null;
106
+ async open() {
107
+ if (this.openPromise) return this.openPromise;
108
+ this.id = ++WsConnection.connectCount;
109
+ const wsPromise = prepareUrl(this.urlOptions).then((url) => new this.WebSocketPonyfill(url));
110
+ this.openPromise = wsPromise.then(async (ws) => {
111
+ this.ws = ws;
112
+ ws.addEventListener("message", function({ data }) {
113
+ if (data === "PING") this.send("PONG");
114
+ });
115
+ if (this.keepAliveOpts.enabled) setupPingInterval(ws, this.keepAliveOpts);
116
+ ws.addEventListener("close", () => {
117
+ if (this.ws === ws) this.ws = null;
118
+ });
119
+ await asyncWsOpen(ws);
120
+ if (this.urlOptions.connectionParams) ws.send(await buildConnectionMessage(this.urlOptions.connectionParams));
121
+ });
122
+ try {
123
+ await this.openPromise;
124
+ } finally {
125
+ this.openPromise = null;
126
+ }
127
+ }
128
+ /**
129
+ * Closes the WebSocket connection gracefully.
130
+ * Waits for any ongoing open operation to complete before closing.
131
+ */
132
+ async close() {
133
+ try {
134
+ await this.openPromise;
135
+ } finally {
136
+ this.ws?.close();
137
+ }
138
+ }
139
+ };
158
140
  /**
159
- * Provides a backward-compatible representation of the connection state.
160
- */ function backwardCompatibility(connection) {
161
- if (connection.isOpen()) {
162
- return {
163
- id: connection.id,
164
- state: 'open',
165
- ws: connection.ws
166
- };
167
- }
168
- if (connection.isClosed()) {
169
- return {
170
- id: connection.id,
171
- state: 'closed',
172
- ws: connection.ws
173
- };
174
- }
175
- if (!connection.ws) {
176
- return null;
177
- }
178
- return {
179
- id: connection.id,
180
- state: 'connecting',
181
- ws: connection.ws
182
- };
141
+ * Provides a backward-compatible representation of the connection state.
142
+ */
143
+ function backwardCompatibility(connection) {
144
+ if (connection.isOpen()) return {
145
+ id: connection.id,
146
+ state: "open",
147
+ ws: connection.ws
148
+ };
149
+ if (connection.isClosed()) return {
150
+ id: connection.id,
151
+ state: "closed",
152
+ ws: connection.ws
153
+ };
154
+ if (!connection.ws) return null;
155
+ return {
156
+ id: connection.id,
157
+ state: "connecting",
158
+ ws: connection.ws
159
+ };
183
160
  }
184
161
 
162
+ //#endregion
185
163
  export { WsConnection, backwardCompatibility };
164
+ //# sourceMappingURL=wsConnection.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsConnection.mjs","names":["ws: WebSocket","pingTimeout: ReturnType<typeof setTimeout> | undefined","pongTimeout: ReturnType<typeof setTimeout> | undefined","opts: WebSocketConnectionOptions","connection: WsConnection"],"sources":["../../../../src/links/wsLink/wsClient/wsConnection.ts"],"sourcesContent":["import { behaviorSubject } from '@trpc/server/observable';\nimport type { UrlOptionsWithConnectionParams } from '../../internals/urlWithConnectionParams';\nimport { buildConnectionMessage, prepareUrl, withResolvers } from './utils';\n\n/**\n * Opens a WebSocket connection asynchronously and returns a promise\n * that resolves when the connection is successfully established.\n * The promise rejects if an error occurs during the connection attempt.\n */\nfunction asyncWsOpen(ws: WebSocket) {\n const { promise, resolve, reject } = withResolvers<void>();\n\n ws.addEventListener('open', () => {\n ws.removeEventListener('error', reject);\n resolve();\n });\n ws.addEventListener('error', reject);\n\n return promise;\n}\n\ninterface PingPongOptions {\n /**\n * The interval (in milliseconds) between \"PING\" messages.\n */\n intervalMs: number;\n\n /**\n * The timeout (in milliseconds) to wait for a \"PONG\" response before closing the connection.\n */\n pongTimeoutMs: number;\n}\n\n/**\n * Sets up a periodic ping-pong mechanism to keep the WebSocket connection alive.\n *\n * - Sends \"PING\" messages at regular intervals defined by `intervalMs`.\n * - If a \"PONG\" response is not received within the `pongTimeoutMs`, the WebSocket is closed.\n * - The ping timer resets upon receiving any message to maintain activity.\n * - Automatically starts the ping process when the WebSocket connection is opened.\n * - Cleans up timers when the WebSocket is closed.\n *\n * @param ws - The WebSocket instance to manage.\n * @param options - Configuration options for ping-pong intervals and timeouts.\n */\nfunction setupPingInterval(\n ws: WebSocket,\n { intervalMs, pongTimeoutMs }: PingPongOptions,\n) {\n let pingTimeout: ReturnType<typeof setTimeout> | undefined;\n let pongTimeout: ReturnType<typeof setTimeout> | undefined;\n\n function start() {\n pingTimeout = setTimeout(() => {\n ws.send('PING');\n pongTimeout = setTimeout(() => {\n ws.close();\n }, pongTimeoutMs);\n }, intervalMs);\n }\n\n function reset() {\n clearTimeout(pingTimeout);\n start();\n }\n\n function pong() {\n clearTimeout(pongTimeout);\n reset();\n }\n\n ws.addEventListener('open', start);\n ws.addEventListener('message', ({ data }) => {\n clearTimeout(pingTimeout);\n start();\n\n if (data === 'PONG') {\n pong();\n }\n });\n ws.addEventListener('close', () => {\n clearTimeout(pingTimeout);\n clearTimeout(pongTimeout);\n });\n}\n\nexport interface WebSocketConnectionOptions {\n WebSocketPonyfill?: typeof WebSocket;\n urlOptions: UrlOptionsWithConnectionParams;\n keepAlive: PingPongOptions & {\n enabled: boolean;\n };\n}\n\n/**\n * Manages a WebSocket connection with support for reconnection, keep-alive mechanisms,\n * and observable state tracking.\n */\nexport class WsConnection {\n static connectCount = 0;\n public id = ++WsConnection.connectCount;\n\n private readonly WebSocketPonyfill: typeof WebSocket;\n private readonly urlOptions: UrlOptionsWithConnectionParams;\n private readonly keepAliveOpts: WebSocketConnectionOptions['keepAlive'];\n public readonly wsObservable = behaviorSubject<WebSocket | null>(null);\n\n constructor(opts: WebSocketConnectionOptions) {\n this.WebSocketPonyfill = opts.WebSocketPonyfill ?? WebSocket;\n if (!this.WebSocketPonyfill) {\n throw new Error(\n \"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\",\n );\n }\n\n this.urlOptions = opts.urlOptions;\n this.keepAliveOpts = opts.keepAlive;\n }\n\n public get ws() {\n return this.wsObservable.get();\n }\n\n private set ws(ws) {\n this.wsObservable.next(ws);\n }\n\n /**\n * Checks if the WebSocket connection is open and ready to communicate.\n */\n public isOpen(): this is { ws: WebSocket } {\n return (\n !!this.ws &&\n this.ws.readyState === this.WebSocketPonyfill.OPEN &&\n !this.openPromise\n );\n }\n\n /**\n * Checks if the WebSocket connection is closed or in the process of closing.\n */\n public isClosed(): this is { ws: WebSocket } {\n return (\n !!this.ws &&\n (this.ws.readyState === this.WebSocketPonyfill.CLOSING ||\n this.ws.readyState === this.WebSocketPonyfill.CLOSED)\n );\n }\n\n /**\n * Manages the WebSocket opening process, ensuring that only one open operation\n * occurs at a time. Tracks the ongoing operation with `openPromise` to avoid\n * redundant calls and ensure proper synchronization.\n *\n * Sets up the keep-alive mechanism and necessary event listeners for the connection.\n *\n * @returns A promise that resolves once the WebSocket connection is successfully opened.\n */\n private openPromise: Promise<void> | null = null;\n public async open() {\n if (this.openPromise) return this.openPromise;\n\n this.id = ++WsConnection.connectCount;\n const wsPromise = prepareUrl(this.urlOptions).then(\n (url) => new this.WebSocketPonyfill(url),\n );\n this.openPromise = wsPromise.then(async (ws) => {\n this.ws = ws;\n\n // Setup ping listener\n ws.addEventListener('message', function ({ data }) {\n if (data === 'PING') {\n this.send('PONG');\n }\n });\n\n if (this.keepAliveOpts.enabled) {\n setupPingInterval(ws, this.keepAliveOpts);\n }\n\n ws.addEventListener('close', () => {\n if (this.ws === ws) {\n this.ws = null;\n }\n });\n\n await asyncWsOpen(ws);\n\n if (this.urlOptions.connectionParams) {\n ws.send(await buildConnectionMessage(this.urlOptions.connectionParams));\n }\n });\n\n try {\n await this.openPromise;\n } finally {\n this.openPromise = null;\n }\n }\n\n /**\n * Closes the WebSocket connection gracefully.\n * Waits for any ongoing open operation to complete before closing.\n */\n public async close() {\n try {\n await this.openPromise;\n } finally {\n this.ws?.close();\n }\n }\n}\n\n/**\n * Provides a backward-compatible representation of the connection state.\n */\nexport function backwardCompatibility(connection: WsConnection) {\n if (connection.isOpen()) {\n return {\n id: connection.id,\n state: 'open',\n ws: connection.ws,\n } as const;\n }\n\n if (connection.isClosed()) {\n return {\n id: connection.id,\n state: 'closed',\n ws: connection.ws,\n } as const;\n }\n\n if (!connection.ws) {\n return null;\n }\n\n return {\n id: connection.id,\n state: 'connecting',\n ws: connection.ws,\n } as const;\n}\n"],"mappings":"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"}
@@ -0,0 +1,15 @@
1
+ import { TRPCLink } from "../types.mjs";
2
+ import { TransformerOptions } from "../../internals/transformer.mjs";
3
+ import { WebSocketClientOptions } from "./wsClient/options.mjs";
4
+ import { TRPCWebSocketClient, createWSClient$1 as createWSClient } from "./createWsClient.mjs";
5
+ import { AnyRouter, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
6
+
7
+ //#region src/links/wsLink/wsLink.d.ts
8
+ type WebSocketLinkOptions<TRouter extends AnyRouter> = {
9
+ client: TRPCWebSocketClient;
10
+ } & TransformerOptions<inferClientTypes<TRouter>>;
11
+ declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>;
12
+
13
+ //#endregion
14
+ export { TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink };
15
+ //# sourceMappingURL=wsLink.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsLink.d.mts","names":[],"sources":["../../../src/links/wsLink/wsLink.ts"],"sourcesContent":[],"mappings":";;;;;;;KAcY,qCAAqC;UACvC;AADV,CAAA,GAEI,kBAFQ,CAEW,gBAFS,CAEQ,OAFR,CAAA,CAAA;AAAA,iBAIhB,MAJgB,CAAA,gBAIO,SAJP,CAAA,CAAA,IAAA,EAKxB,oBALwB,CAKH,OALG,CAAA,CAAA,EAM7B,QAN6B,CAMpB,OANoB,CAAA"}
@@ -1,11 +1,15 @@
1
- import type { AnyRouter, inferClientTypes } from '@trpc/server/unstable-core-do-not-import';
2
- import type { TransformerOptions } from '../../unstable-internals';
3
- import type { TRPCLink } from '../types';
4
- import type { TRPCWebSocketClient, WebSocketClientOptions } from './createWsClient';
5
- import { createWSClient } from './createWsClient';
6
- export type WebSocketLinkOptions<TRouter extends AnyRouter> = {
7
- client: TRPCWebSocketClient;
1
+ import { TRPCLink } from "../types.js";
2
+ import { TransformerOptions } from "../../internals/transformer.js";
3
+ import { WebSocketClientOptions } from "./wsClient/options.js";
4
+ import { TRPCWebSocketClient, createWSClient } from "./createWsClient.js";
5
+ import { AnyRouter, inferClientTypes } from "@trpc/server/unstable-core-do-not-import";
6
+
7
+ //#region src/links/wsLink/wsLink.d.ts
8
+ type WebSocketLinkOptions<TRouter extends AnyRouter> = {
9
+ client: TRPCWebSocketClient;
8
10
  } & TransformerOptions<inferClientTypes<TRouter>>;
9
- export declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>;
10
- export { TRPCWebSocketClient, WebSocketClientOptions, createWSClient };
11
+ declare function wsLink<TRouter extends AnyRouter>(opts: WebSocketLinkOptions<TRouter>): TRPCLink<TRouter>;
12
+
13
+ //#endregion
14
+ export { TRPCWebSocketClient, WebSocketClientOptions, WebSocketLinkOptions, createWSClient, wsLink };
11
15
  //# sourceMappingURL=wsLink.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wsLink.d.ts","sourceRoot":"","sources":["../../../src/links/wsLink/wsLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EACjB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,MAAM,oBAAoB,CAAC,OAAO,SAAS,SAAS,IAAI;IAC5D,MAAM,EAAE,mBAAmB,CAAC;CAC7B,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAElD,wBAAgB,MAAM,CAAC,OAAO,SAAS,SAAS,EAC9C,IAAI,EAAE,oBAAoB,CAAC,OAAO,CAAC,GAClC,QAAQ,CAAC,OAAO,CAAC,CAgCnB;AAED,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,cAAc,EAAE,CAAC"}
1
+ {"version":3,"file":"wsLink.d.ts","names":[],"sources":["../../../src/links/wsLink/wsLink.ts"],"sourcesContent":[],"mappings":";;;;;;;KAcY,qCAAqC;UACvC;AADV,CAAA,GAEI,kBAFQ,CAEW,gBAFS,CAEQ,OAFR,CAAA,CAAA;AAAA,iBAIhB,MAJgB,CAAA,gBAIO,SAJP,CAAA,CAAA,IAAA,EAKxB,oBALwB,CAKH,OALG,CAAA,CAAA,EAM7B,QAN6B,CAMpB,OANoB,CAAA"}
@@ -1,35 +1,34 @@
1
- 'use strict';
2
-
3
- var observable = require('@trpc/server/observable');
4
- var transformer = require('../../internals/transformer.js');
5
- var createWsClient = require('./createWsClient.js');
1
+ const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.js');
2
+ const require__Users_julius_dev_trpc_packages_client_src_internals_transformer = require('../../internals/transformer.js');
3
+ const require__Users_julius_dev_trpc_packages_client_src_links_wsLink_createWsClient = require('./createWsClient.js');
4
+ const __trpc_server_observable = require_rolldown_runtime.__toESM(require("@trpc/server/observable"));
6
5
 
6
+ //#region src/links/wsLink/wsLink.ts
7
7
  function wsLink(opts) {
8
- const { client } = opts;
9
- const transformer$1 = transformer.getTransformer(opts.transformer);
10
- return ()=>{
11
- return ({ op })=>{
12
- return observable.observable((observer)=>{
13
- const connStateSubscription = op.type === 'subscription' ? client.connectionState.subscribe({
14
- next (result) {
15
- observer.next({
16
- result,
17
- context: op.context
18
- });
19
- }
20
- }) : null;
21
- const requestSubscription = client.request({
22
- op,
23
- transformer: transformer$1
24
- }).subscribe(observer);
25
- return ()=>{
26
- requestSubscription.unsubscribe();
27
- connStateSubscription?.unsubscribe();
28
- };
29
- });
30
- };
31
- };
8
+ const { client } = opts;
9
+ const transformer = require__Users_julius_dev_trpc_packages_client_src_internals_transformer.getTransformer(opts.transformer);
10
+ return () => {
11
+ return ({ op }) => {
12
+ return (0, __trpc_server_observable.observable)((observer) => {
13
+ const connStateSubscription = op.type === "subscription" ? client.connectionState.subscribe({ next(result) {
14
+ observer.next({
15
+ result,
16
+ context: op.context
17
+ });
18
+ } }) : null;
19
+ const requestSubscription = client.request({
20
+ op,
21
+ transformer
22
+ }).subscribe(observer);
23
+ return () => {
24
+ requestSubscription.unsubscribe();
25
+ connStateSubscription?.unsubscribe();
26
+ };
27
+ });
28
+ };
29
+ };
32
30
  }
33
31
 
34
- exports.createWSClient = createWsClient.createWSClient;
35
- exports.wsLink = wsLink;
32
+ //#endregion
33
+ exports.createWSClient = require__Users_julius_dev_trpc_packages_client_src_links_wsLink_createWsClient.createWSClient;
34
+ exports.wsLink = wsLink;
@@ -1,32 +1,33 @@
1
- import { observable } from '@trpc/server/observable';
2
- import { getTransformer } from '../../internals/transformer.mjs';
3
- export { createWSClient } from './createWsClient.mjs';
1
+ import { getTransformer } from "../../internals/transformer.mjs";
2
+ import { createWSClient } from "./createWsClient.mjs";
3
+ import { observable } from "@trpc/server/observable";
4
4
 
5
+ //#region src/links/wsLink/wsLink.ts
5
6
  function wsLink(opts) {
6
- const { client } = opts;
7
- const transformer = getTransformer(opts.transformer);
8
- return ()=>{
9
- return ({ op })=>{
10
- return observable((observer)=>{
11
- const connStateSubscription = op.type === 'subscription' ? client.connectionState.subscribe({
12
- next (result) {
13
- observer.next({
14
- result,
15
- context: op.context
16
- });
17
- }
18
- }) : null;
19
- const requestSubscription = client.request({
20
- op,
21
- transformer
22
- }).subscribe(observer);
23
- return ()=>{
24
- requestSubscription.unsubscribe();
25
- connStateSubscription?.unsubscribe();
26
- };
27
- });
28
- };
29
- };
7
+ const { client } = opts;
8
+ const transformer = getTransformer(opts.transformer);
9
+ return () => {
10
+ return ({ op }) => {
11
+ return observable((observer) => {
12
+ const connStateSubscription = op.type === "subscription" ? client.connectionState.subscribe({ next(result) {
13
+ observer.next({
14
+ result,
15
+ context: op.context
16
+ });
17
+ } }) : null;
18
+ const requestSubscription = client.request({
19
+ op,
20
+ transformer
21
+ }).subscribe(observer);
22
+ return () => {
23
+ requestSubscription.unsubscribe();
24
+ connStateSubscription?.unsubscribe();
25
+ };
26
+ });
27
+ };
28
+ };
30
29
  }
31
30
 
32
- export { wsLink };
31
+ //#endregion
32
+ export { createWSClient, wsLink };
33
+ //# sourceMappingURL=wsLink.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wsLink.mjs","names":["opts: WebSocketLinkOptions<TRouter>"],"sources":["../../../src/links/wsLink/wsLink.ts"],"sourcesContent":["import { observable } from '@trpc/server/observable';\nimport type {\n AnyRouter,\n inferClientTypes,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type { TransformerOptions } from '../../unstable-internals';\nimport { getTransformer } from '../../unstable-internals';\nimport type { TRPCLink } from '../types';\nimport type {\n TRPCWebSocketClient,\n WebSocketClientOptions,\n} from './createWsClient';\nimport { createWSClient } from './createWsClient';\n\nexport type WebSocketLinkOptions<TRouter extends AnyRouter> = {\n client: TRPCWebSocketClient;\n} & TransformerOptions<inferClientTypes<TRouter>>;\n\nexport function wsLink<TRouter extends AnyRouter>(\n opts: WebSocketLinkOptions<TRouter>,\n): TRPCLink<TRouter> {\n const { client } = opts;\n const transformer = getTransformer(opts.transformer);\n return () => {\n return ({ op }) => {\n return observable((observer) => {\n const connStateSubscription =\n op.type === 'subscription'\n ? client.connectionState.subscribe({\n next(result) {\n observer.next({\n result,\n context: op.context,\n });\n },\n })\n : null;\n\n const requestSubscription = client\n .request({\n op,\n transformer,\n })\n .subscribe(observer);\n\n return () => {\n requestSubscription.unsubscribe();\n connStateSubscription?.unsubscribe();\n };\n });\n };\n };\n}\n\nexport { TRPCWebSocketClient, WebSocketClientOptions, createWSClient };\n"],"mappings":";;;;;AAkBA,SAAgB,OACdA,MACmB;CACnB,MAAM,EAAE,QAAQ,GAAG;CACnB,MAAM,cAAc,eAAe,KAAK,YAAY;AACpD,QAAO,MAAM;AACX,SAAO,CAAC,EAAE,IAAI,KAAK;AACjB,UAAO,WAAW,CAAC,aAAa;IAC9B,MAAM,wBACJ,GAAG,SAAS,iBACR,OAAO,gBAAgB,UAAU,EAC/B,KAAK,QAAQ;AACX,cAAS,KAAK;MACZ;MACA,SAAS,GAAG;KACb,EAAC;IACH,EACF,EAAC,GACF;IAEN,MAAM,sBAAsB,OACzB,QAAQ;KACP;KACA;IACD,EAAC,CACD,UAAU,SAAS;AAEtB,WAAO,MAAM;AACX,yBAAoB,aAAa;AACjC,4BAAuB,aAAa;IACrC;GACF,EAAC;EACH;CACF;AACF"}
package/dist/links.js ADDED
@@ -0,0 +1,11 @@
1
+ const require__Users_julius_dev_trpc_packages_client_src_links_internals_contentTypes = require('./links/internals/contentTypes.js');
2
+ const require__Users_julius_dev_trpc_packages_client_src_links_httpBatchLink = require('./links/httpBatchLink.js');
3
+ const require__Users_julius_dev_trpc_packages_client_src_links_httpBatchStreamLink = require('./links/httpBatchStreamLink.js');
4
+ const require__Users_julius_dev_trpc_packages_client_src_links_httpLink = require('./links/httpLink.js');
5
+ const require__Users_julius_dev_trpc_packages_client_src_links_loggerLink = require('./links/loggerLink.js');
6
+ const require__Users_julius_dev_trpc_packages_client_src_links_splitLink = require('./links/splitLink.js');
7
+ const require__Users_julius_dev_trpc_packages_client_src_links_wsLink_createWsClient = require('./links/wsLink/createWsClient.js');
8
+ const require__Users_julius_dev_trpc_packages_client_src_links_wsLink_wsLink = require('./links/wsLink/wsLink.js');
9
+ const require__Users_julius_dev_trpc_packages_client_src_links_httpSubscriptionLink = require('./links/httpSubscriptionLink.js');
10
+ const require__Users_julius_dev_trpc_packages_client_src_links_retryLink = require('./links/retryLink.js');
11
+ const require__Users_julius_dev_trpc_packages_client_src_links_localLink = require('./links/localLink.js');
package/dist/links.mjs ADDED
@@ -0,0 +1,11 @@
1
+ import { isFormData, isNonJsonSerializable, isOctetType } from "./links/internals/contentTypes.mjs";
2
+ import { httpBatchLink } from "./links/httpBatchLink.mjs";
3
+ import { httpBatchStreamLink, unstable_httpBatchStreamLink } from "./links/httpBatchStreamLink.mjs";
4
+ import { httpLink } from "./links/httpLink.mjs";
5
+ import { loggerLink } from "./links/loggerLink.mjs";
6
+ import { splitLink } from "./links/splitLink.mjs";
7
+ import { createWSClient } from "./links/wsLink/createWsClient.mjs";
8
+ import { wsLink } from "./links/wsLink/wsLink.mjs";
9
+ import { httpSubscriptionLink, unstable_httpSubscriptionLink } from "./links/httpSubscriptionLink.mjs";
10
+ import { retryLink } from "./links/retryLink.mjs";
11
+ import { experimental_localLink } from "./links/localLink.mjs";