@trpc/client 11.1.3-alpha-tmp-issues-6785.34 → 11.1.3-alpha-tmp-tsdown.24

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 (244) hide show
  1. package/dist/TRPCClientError.d.mts +32 -0
  2. package/dist/TRPCClientError.d.mts.map +1 -0
  3. package/dist/TRPCClientError.d.ts +28 -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 +69 -0
  11. package/dist/createTRPCClient.d.mts.map +1 -0
  12. package/dist/createTRPCClient.d.ts +34 -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 +8 -0
  18. package/dist/createTRPCUntypedClient.d.mts.map +1 -0
  19. package/dist/createTRPCUntypedClient.d.ts +7 -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 +9 -0
  25. package/dist/getFetch.d.mts.map +1 -0
  26. package/dist/getFetch.d.ts +8 -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 +42 -42
  34. package/dist/index.mjs +19 -15
  35. package/dist/internals/TRPCUntypedClient.d.mts +45 -0
  36. package/dist/internals/TRPCUntypedClient.d.mts.map +1 -0
  37. package/dist/internals/TRPCUntypedClient.d.ts +39 -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 -112
  43. package/dist/internals/dataLoader.mjs +101 -110
  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 +46 -0
  52. package/dist/internals/transformer.d.mts.map +1 -0
  53. package/dist/internals/transformer.d.ts +26 -22
  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 +84 -0
  59. package/dist/internals/types.d.mts.map +1 -0
  60. package/dist/internals/types.d.ts +44 -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 +15 -0
  67. package/dist/links/httpBatchLink.d.mts.map +1 -0
  68. package/dist/links/httpBatchLink.d.ts +11 -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 +19 -0
  74. package/dist/links/httpBatchStreamLink.d.mts.map +1 -0
  75. package/dist/links/httpBatchStreamLink.d.ts +12 -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 +23 -0
  81. package/dist/links/httpLink.d.mts.map +1 -0
  82. package/dist/links/httpLink.d.ts +18 -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 +29 -0
  88. package/dist/links/httpSubscriptionLink.d.mts.map +1 -0
  89. package/dist/links/httpSubscriptionLink.d.ts +20 -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 +9 -0
  95. package/dist/links/internals/contentTypes.d.mts.map +1 -0
  96. package/dist/links/internals/contentTypes.d.ts +8 -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 +25 -0
  105. package/dist/links/internals/httpUtils.d.mts.map +1 -0
  106. package/dist/links/internals/httpUtils.d.ts +20 -63
  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 +19 -0
  112. package/dist/links/internals/subscriptions.d.mts.map +1 -0
  113. package/dist/links/internals/subscriptions.d.ts +10 -8
  114. package/dist/links/internals/subscriptions.d.ts.map +1 -1
  115. package/dist/links/internals/urlWithConnectionParams.d.mts +24 -0
  116. package/dist/links/internals/urlWithConnectionParams.d.mts.map +1 -0
  117. package/dist/links/internals/urlWithConnectionParams.d.ts +19 -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 +21 -0
  123. package/dist/links/localLink.d.mts.map +1 -0
  124. package/dist/links/localLink.d.ts +21 -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 +55 -0
  130. package/dist/links/loggerLink.d.mts.map +1 -0
  131. package/dist/links/loggerLink.d.ts +39 -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 +36 -0
  137. package/dist/links/retryLink.d.mts.map +1 -0
  138. package/dist/links/retryLink.d.ts +28 -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 +20 -0
  144. package/dist/links/splitLink.d.mts.map +1 -0
  145. package/dist/links/splitLink.d.ts +18 -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 +68 -0
  151. package/dist/links/types.d.mts.map +1 -0
  152. package/dist/links/types.d.ts +34 -29
  153. package/dist/links/types.d.ts.map +1 -1
  154. package/dist/links/wsLink/createWsClient.d.mts +9 -0
  155. package/dist/links/wsLink/createWsClient.d.mts.map +1 -0
  156. package/dist/links/wsLink/createWsClient.d.ts +8 -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 +53 -63
  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 -140
  169. package/dist/links/wsLink/wsClient/requestManager.mjs +133 -137
  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 +101 -0
  175. package/dist/links/wsLink/wsClient/wsClient.d.mts.map +1 -0
  176. package/dist/links/wsLink/wsClient/wsClient.d.ts +95 -78
  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 +14 -0
  185. package/dist/links/wsLink/wsLink.d.mts.map +1 -0
  186. package/dist/links/wsLink/wsLink.d.ts +12 -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.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +68 -0
  194. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +66 -0
  195. package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/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 +63 -30
  206. package/src/TRPCClientError.ts +4 -9
  207. package/src/internals/signals.ts +16 -0
  208. package/src/links/httpSubscriptionLink.ts +3 -18
  209. package/src/links/localLink.ts +277 -0
  210. package/src/links.ts +1 -0
  211. package/unstable-internals/package.json +1 -0
  212. package/dist/bundle-analysis.json +0 -433
  213. package/dist/index.d.ts.map +0 -1
  214. package/dist/internals/dataLoader.d.ts +0 -13
  215. package/dist/internals/dataLoader.d.ts.map +0 -1
  216. package/dist/internals/inputWithTrackedEventId.d.ts +0 -2
  217. package/dist/internals/inputWithTrackedEventId.d.ts.map +0 -1
  218. package/dist/internals/signals.d.ts +0 -15
  219. package/dist/internals/signals.d.ts.map +0 -1
  220. package/dist/links/internals/createChain.d.ts +0 -8
  221. package/dist/links/internals/createChain.d.ts.map +0 -1
  222. package/dist/links/internals/dedupeLink.d.ts +0 -7
  223. package/dist/links/internals/dedupeLink.d.ts.map +0 -1
  224. package/dist/links/wsLink/wsClient/requestManager.d.ts +0 -106
  225. package/dist/links/wsLink/wsClient/requestManager.d.ts.map +0 -1
  226. package/dist/links/wsLink/wsClient/utils.d.ts +0 -38
  227. package/dist/links/wsLink/wsClient/utils.d.ts.map +0 -1
  228. package/dist/links/wsLink/wsClient/wsConnection.d.ts +0 -79
  229. package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +0 -1
  230. package/dist/links.d.ts +0 -11
  231. package/dist/links.d.ts.map +0 -1
  232. package/dist/unstable-internals.d.ts.map +0 -1
  233. package/links/httpBatchLink/index.d.ts +0 -1
  234. package/links/httpBatchLink/index.js +0 -1
  235. package/links/httpLink/index.d.ts +0 -1
  236. package/links/httpLink/index.js +0 -1
  237. package/links/loggerLink/index.d.ts +0 -1
  238. package/links/loggerLink/index.js +0 -1
  239. package/links/splitLink/index.d.ts +0 -1
  240. package/links/splitLink/index.js +0 -1
  241. package/links/wsLink/wsLink/index.d.ts +0 -1
  242. package/links/wsLink/wsLink/index.js +0 -1
  243. package/unstable-internals/index.d.ts +0 -1
  244. package/unstable-internals/index.js +0 -1
@@ -1,143 +1,136 @@
1
- 'use strict';
1
+ const require_utils = require('./utils.js');
2
2
 
3
- var utils = require('./utils.js');
4
-
5
- function _define_property(obj, key, value) {
6
- if (key in obj) {
7
- Object.defineProperty(obj, key, {
8
- value: value,
9
- enumerable: true,
10
- configurable: true,
11
- writable: true
12
- });
13
- } else {
14
- obj[key] = value;
15
- }
16
- return obj;
17
- }
3
+ //#region src/links/wsLink/wsClient/requestManager.ts
18
4
  /**
19
- * Manages WebSocket requests, tracking their lifecycle and providing utility methods
20
- * for handling outgoing and pending requests.
21
- *
22
- * - **Outgoing requests**: Requests that are queued and waiting to be sent.
23
- * - **Pending requests**: Requests that have been sent and are in flight awaiting a response.
24
- * For subscriptions, multiple responses may be received until the subscription is closed.
25
- */ class RequestManager {
26
- /**
27
- * Registers a new request by adding it to the outgoing queue and setting up
28
- * callbacks for lifecycle events such as completion or error.
29
- *
30
- * @param message - The outgoing message to be sent.
31
- * @param callbacks - Callback functions to observe the request's state.
32
- * @returns A cleanup function to manually remove the request.
33
- */ register(message, callbacks) {
34
- const { promise: end, resolve } = utils.withResolvers();
35
- this.outgoingRequests.push({
36
- id: String(message.id),
37
- message,
38
- end,
39
- callbacks: {
40
- next: callbacks.next,
41
- complete: ()=>{
42
- callbacks.complete();
43
- resolve();
44
- },
45
- error: (e)=>{
46
- callbacks.error(e);
47
- resolve();
48
- }
49
- }
50
- });
51
- return ()=>{
52
- this.delete(message.id);
53
- callbacks.complete();
54
- resolve();
55
- };
56
- }
57
- /**
58
- * Deletes a request from both the outgoing and pending collections, if it exists.
59
- */ delete(messageId) {
60
- if (messageId === null) return;
61
- this.outgoingRequests = this.outgoingRequests.filter(({ id })=>id !== String(messageId));
62
- delete this.pendingRequests[String(messageId)];
63
- }
64
- /**
65
- * Moves all outgoing requests to the pending state and clears the outgoing queue.
66
- *
67
- * The caller is expected to handle the actual sending of the requests
68
- * (e.g., sending them over the network) after this method is called.
69
- *
70
- * @returns The list of requests that were transitioned to the pending state.
71
- */ flush() {
72
- const requests = this.outgoingRequests;
73
- this.outgoingRequests = [];
74
- for (const request of requests){
75
- this.pendingRequests[request.id] = request;
76
- }
77
- return requests;
78
- }
79
- /**
80
- * Retrieves all currently pending requests, which are in flight awaiting responses
81
- * or handling ongoing subscriptions.
82
- */ getPendingRequests() {
83
- return Object.values(this.pendingRequests);
84
- }
85
- /**
86
- * Retrieves a specific pending request by its message ID.
87
- */ getPendingRequest(messageId) {
88
- if (messageId === null) return null;
89
- return this.pendingRequests[String(messageId)];
90
- }
91
- /**
92
- * Retrieves all outgoing requests, which are waiting to be sent.
93
- */ getOutgoingRequests() {
94
- return this.outgoingRequests;
95
- }
96
- /**
97
- * Retrieves all requests, both outgoing and pending, with their respective states.
98
- *
99
- * @returns An array of all requests with their state ("outgoing" or "pending").
100
- */ getRequests() {
101
- return [
102
- ...this.getOutgoingRequests().map((request)=>({
103
- state: 'outgoing',
104
- message: request.message,
105
- end: request.end,
106
- callbacks: request.callbacks
107
- })),
108
- ...this.getPendingRequests().map((request)=>({
109
- state: 'pending',
110
- message: request.message,
111
- end: request.end,
112
- callbacks: request.callbacks
113
- }))
114
- ];
115
- }
116
- /**
117
- * Checks if there are any pending requests, including ongoing subscriptions.
118
- */ hasPendingRequests() {
119
- return this.getPendingRequests().length > 0;
120
- }
121
- /**
122
- * Checks if there are any pending subscriptions
123
- */ hasPendingSubscriptions() {
124
- return this.getPendingRequests().some((request)=>request.message.method === 'subscription');
125
- }
126
- /**
127
- * Checks if there are any outgoing requests waiting to be sent.
128
- */ hasOutgoingRequests() {
129
- return this.outgoingRequests.length > 0;
130
- }
131
- constructor(){
132
- /**
133
- * Stores requests that are outgoing, meaning they are registered but not yet sent over the WebSocket.
134
- */ _define_property(this, "outgoingRequests", new Array());
135
- /**
136
- * Stores requests that are pending (in flight), meaning they have been sent over the WebSocket
137
- * and are awaiting responses. For subscriptions, this includes requests
138
- * that may receive multiple responses.
139
- */ _define_property(this, "pendingRequests", {});
140
- }
141
- }
5
+ * Manages WebSocket requests, tracking their lifecycle and providing utility methods
6
+ * for handling outgoing and pending requests.
7
+ *
8
+ * - **Outgoing requests**: Requests that are queued and waiting to be sent.
9
+ * - **Pending requests**: Requests that have been sent and are in flight awaiting a response.
10
+ * For subscriptions, multiple responses may be received until the subscription is closed.
11
+ */
12
+ var RequestManager = class {
13
+ /**
14
+ * Stores requests that are outgoing, meaning they are registered but not yet sent over the WebSocket.
15
+ */
16
+ outgoingRequests = new Array();
17
+ /**
18
+ * Stores requests that are pending (in flight), meaning they have been sent over the WebSocket
19
+ * and are awaiting responses. For subscriptions, this includes requests
20
+ * that may receive multiple responses.
21
+ */
22
+ pendingRequests = {};
23
+ /**
24
+ * Registers a new request by adding it to the outgoing queue and setting up
25
+ * callbacks for lifecycle events such as completion or error.
26
+ *
27
+ * @param message - The outgoing message to be sent.
28
+ * @param callbacks - Callback functions to observe the request's state.
29
+ * @returns A cleanup function to manually remove the request.
30
+ */
31
+ register(message, callbacks) {
32
+ const { promise: end, resolve } = require_utils.withResolvers();
33
+ this.outgoingRequests.push({
34
+ id: String(message.id),
35
+ message,
36
+ end,
37
+ callbacks: {
38
+ next: callbacks.next,
39
+ complete: () => {
40
+ callbacks.complete();
41
+ resolve();
42
+ },
43
+ error: (e) => {
44
+ callbacks.error(e);
45
+ resolve();
46
+ }
47
+ }
48
+ });
49
+ return () => {
50
+ this.delete(message.id);
51
+ callbacks.complete();
52
+ resolve();
53
+ };
54
+ }
55
+ /**
56
+ * Deletes a request from both the outgoing and pending collections, if it exists.
57
+ */
58
+ delete(messageId) {
59
+ if (messageId === null) return;
60
+ this.outgoingRequests = this.outgoingRequests.filter(({ id }) => id !== String(messageId));
61
+ delete this.pendingRequests[String(messageId)];
62
+ }
63
+ /**
64
+ * Moves all outgoing requests to the pending state and clears the outgoing queue.
65
+ *
66
+ * The caller is expected to handle the actual sending of the requests
67
+ * (e.g., sending them over the network) after this method is called.
68
+ *
69
+ * @returns The list of requests that were transitioned to the pending state.
70
+ */
71
+ flush() {
72
+ const requests = this.outgoingRequests;
73
+ this.outgoingRequests = [];
74
+ for (const request of requests) this.pendingRequests[request.id] = request;
75
+ return requests;
76
+ }
77
+ /**
78
+ * Retrieves all currently pending requests, which are in flight awaiting responses
79
+ * or handling ongoing subscriptions.
80
+ */
81
+ getPendingRequests() {
82
+ return Object.values(this.pendingRequests);
83
+ }
84
+ /**
85
+ * Retrieves a specific pending request by its message ID.
86
+ */
87
+ getPendingRequest(messageId) {
88
+ if (messageId === null) return null;
89
+ return this.pendingRequests[String(messageId)];
90
+ }
91
+ /**
92
+ * Retrieves all outgoing requests, which are waiting to be sent.
93
+ */
94
+ getOutgoingRequests() {
95
+ return this.outgoingRequests;
96
+ }
97
+ /**
98
+ * Retrieves all requests, both outgoing and pending, with their respective states.
99
+ *
100
+ * @returns An array of all requests with their state ("outgoing" or "pending").
101
+ */
102
+ getRequests() {
103
+ return [...this.getOutgoingRequests().map((request) => ({
104
+ state: "outgoing",
105
+ message: request.message,
106
+ end: request.end,
107
+ callbacks: request.callbacks
108
+ })), ...this.getPendingRequests().map((request) => ({
109
+ state: "pending",
110
+ message: request.message,
111
+ end: request.end,
112
+ callbacks: request.callbacks
113
+ }))];
114
+ }
115
+ /**
116
+ * Checks if there are any pending requests, including ongoing subscriptions.
117
+ */
118
+ hasPendingRequests() {
119
+ return this.getPendingRequests().length > 0;
120
+ }
121
+ /**
122
+ * Checks if there are any pending subscriptions
123
+ */
124
+ hasPendingSubscriptions() {
125
+ return this.getPendingRequests().some((request) => request.message.method === "subscription");
126
+ }
127
+ /**
128
+ * Checks if there are any outgoing requests waiting to be sent.
129
+ */
130
+ hasOutgoingRequests() {
131
+ return this.outgoingRequests.length > 0;
132
+ }
133
+ };
142
134
 
143
- exports.RequestManager = RequestManager;
135
+ //#endregion
136
+ exports.RequestManager = RequestManager;
@@ -1,141 +1,137 @@
1
- import { withResolvers } from './utils.mjs';
1
+ import { withResolvers } from "./utils.mjs";
2
2
 
3
- function _define_property(obj, key, value) {
4
- if (key in obj) {
5
- Object.defineProperty(obj, key, {
6
- value: value,
7
- enumerable: true,
8
- configurable: true,
9
- writable: true
10
- });
11
- } else {
12
- obj[key] = value;
13
- }
14
- return obj;
15
- }
3
+ //#region src/links/wsLink/wsClient/requestManager.ts
16
4
  /**
17
- * Manages WebSocket requests, tracking their lifecycle and providing utility methods
18
- * for handling outgoing and pending requests.
19
- *
20
- * - **Outgoing requests**: Requests that are queued and waiting to be sent.
21
- * - **Pending requests**: Requests that have been sent and are in flight awaiting a response.
22
- * For subscriptions, multiple responses may be received until the subscription is closed.
23
- */ class RequestManager {
24
- /**
25
- * Registers a new request by adding it to the outgoing queue and setting up
26
- * callbacks for lifecycle events such as completion or error.
27
- *
28
- * @param message - The outgoing message to be sent.
29
- * @param callbacks - Callback functions to observe the request's state.
30
- * @returns A cleanup function to manually remove the request.
31
- */ register(message, callbacks) {
32
- const { promise: end, resolve } = withResolvers();
33
- this.outgoingRequests.push({
34
- id: String(message.id),
35
- message,
36
- end,
37
- callbacks: {
38
- next: callbacks.next,
39
- complete: ()=>{
40
- callbacks.complete();
41
- resolve();
42
- },
43
- error: (e)=>{
44
- callbacks.error(e);
45
- resolve();
46
- }
47
- }
48
- });
49
- return ()=>{
50
- this.delete(message.id);
51
- callbacks.complete();
52
- resolve();
53
- };
54
- }
55
- /**
56
- * Deletes a request from both the outgoing and pending collections, if it exists.
57
- */ delete(messageId) {
58
- if (messageId === null) return;
59
- this.outgoingRequests = this.outgoingRequests.filter(({ id })=>id !== String(messageId));
60
- delete this.pendingRequests[String(messageId)];
61
- }
62
- /**
63
- * Moves all outgoing requests to the pending state and clears the outgoing queue.
64
- *
65
- * The caller is expected to handle the actual sending of the requests
66
- * (e.g., sending them over the network) after this method is called.
67
- *
68
- * @returns The list of requests that were transitioned to the pending state.
69
- */ flush() {
70
- const requests = this.outgoingRequests;
71
- this.outgoingRequests = [];
72
- for (const request of requests){
73
- this.pendingRequests[request.id] = request;
74
- }
75
- return requests;
76
- }
77
- /**
78
- * Retrieves all currently pending requests, which are in flight awaiting responses
79
- * or handling ongoing subscriptions.
80
- */ getPendingRequests() {
81
- return Object.values(this.pendingRequests);
82
- }
83
- /**
84
- * Retrieves a specific pending request by its message ID.
85
- */ getPendingRequest(messageId) {
86
- if (messageId === null) return null;
87
- return this.pendingRequests[String(messageId)];
88
- }
89
- /**
90
- * Retrieves all outgoing requests, which are waiting to be sent.
91
- */ getOutgoingRequests() {
92
- return this.outgoingRequests;
93
- }
94
- /**
95
- * Retrieves all requests, both outgoing and pending, with their respective states.
96
- *
97
- * @returns An array of all requests with their state ("outgoing" or "pending").
98
- */ getRequests() {
99
- return [
100
- ...this.getOutgoingRequests().map((request)=>({
101
- state: 'outgoing',
102
- message: request.message,
103
- end: request.end,
104
- callbacks: request.callbacks
105
- })),
106
- ...this.getPendingRequests().map((request)=>({
107
- state: 'pending',
108
- message: request.message,
109
- end: request.end,
110
- callbacks: request.callbacks
111
- }))
112
- ];
113
- }
114
- /**
115
- * Checks if there are any pending requests, including ongoing subscriptions.
116
- */ hasPendingRequests() {
117
- return this.getPendingRequests().length > 0;
118
- }
119
- /**
120
- * Checks if there are any pending subscriptions
121
- */ hasPendingSubscriptions() {
122
- return this.getPendingRequests().some((request)=>request.message.method === 'subscription');
123
- }
124
- /**
125
- * Checks if there are any outgoing requests waiting to be sent.
126
- */ hasOutgoingRequests() {
127
- return this.outgoingRequests.length > 0;
128
- }
129
- constructor(){
130
- /**
131
- * Stores requests that are outgoing, meaning they are registered but not yet sent over the WebSocket.
132
- */ _define_property(this, "outgoingRequests", new Array());
133
- /**
134
- * Stores requests that are pending (in flight), meaning they have been sent over the WebSocket
135
- * and are awaiting responses. For subscriptions, this includes requests
136
- * that may receive multiple responses.
137
- */ _define_property(this, "pendingRequests", {});
138
- }
139
- }
5
+ * Manages WebSocket requests, tracking their lifecycle and providing utility methods
6
+ * for handling outgoing and pending requests.
7
+ *
8
+ * - **Outgoing requests**: Requests that are queued and waiting to be sent.
9
+ * - **Pending requests**: Requests that have been sent and are in flight awaiting a response.
10
+ * For subscriptions, multiple responses may be received until the subscription is closed.
11
+ */
12
+ var RequestManager = class {
13
+ /**
14
+ * Stores requests that are outgoing, meaning they are registered but not yet sent over the WebSocket.
15
+ */
16
+ outgoingRequests = new Array();
17
+ /**
18
+ * Stores requests that are pending (in flight), meaning they have been sent over the WebSocket
19
+ * and are awaiting responses. For subscriptions, this includes requests
20
+ * that may receive multiple responses.
21
+ */
22
+ pendingRequests = {};
23
+ /**
24
+ * Registers a new request by adding it to the outgoing queue and setting up
25
+ * callbacks for lifecycle events such as completion or error.
26
+ *
27
+ * @param message - The outgoing message to be sent.
28
+ * @param callbacks - Callback functions to observe the request's state.
29
+ * @returns A cleanup function to manually remove the request.
30
+ */
31
+ register(message, callbacks) {
32
+ const { promise: end, resolve } = withResolvers();
33
+ this.outgoingRequests.push({
34
+ id: String(message.id),
35
+ message,
36
+ end,
37
+ callbacks: {
38
+ next: callbacks.next,
39
+ complete: () => {
40
+ callbacks.complete();
41
+ resolve();
42
+ },
43
+ error: (e) => {
44
+ callbacks.error(e);
45
+ resolve();
46
+ }
47
+ }
48
+ });
49
+ return () => {
50
+ this.delete(message.id);
51
+ callbacks.complete();
52
+ resolve();
53
+ };
54
+ }
55
+ /**
56
+ * Deletes a request from both the outgoing and pending collections, if it exists.
57
+ */
58
+ delete(messageId) {
59
+ if (messageId === null) return;
60
+ this.outgoingRequests = this.outgoingRequests.filter(({ id }) => id !== String(messageId));
61
+ delete this.pendingRequests[String(messageId)];
62
+ }
63
+ /**
64
+ * Moves all outgoing requests to the pending state and clears the outgoing queue.
65
+ *
66
+ * The caller is expected to handle the actual sending of the requests
67
+ * (e.g., sending them over the network) after this method is called.
68
+ *
69
+ * @returns The list of requests that were transitioned to the pending state.
70
+ */
71
+ flush() {
72
+ const requests = this.outgoingRequests;
73
+ this.outgoingRequests = [];
74
+ for (const request of requests) this.pendingRequests[request.id] = request;
75
+ return requests;
76
+ }
77
+ /**
78
+ * Retrieves all currently pending requests, which are in flight awaiting responses
79
+ * or handling ongoing subscriptions.
80
+ */
81
+ getPendingRequests() {
82
+ return Object.values(this.pendingRequests);
83
+ }
84
+ /**
85
+ * Retrieves a specific pending request by its message ID.
86
+ */
87
+ getPendingRequest(messageId) {
88
+ if (messageId === null) return null;
89
+ return this.pendingRequests[String(messageId)];
90
+ }
91
+ /**
92
+ * Retrieves all outgoing requests, which are waiting to be sent.
93
+ */
94
+ getOutgoingRequests() {
95
+ return this.outgoingRequests;
96
+ }
97
+ /**
98
+ * Retrieves all requests, both outgoing and pending, with their respective states.
99
+ *
100
+ * @returns An array of all requests with their state ("outgoing" or "pending").
101
+ */
102
+ getRequests() {
103
+ return [...this.getOutgoingRequests().map((request) => ({
104
+ state: "outgoing",
105
+ message: request.message,
106
+ end: request.end,
107
+ callbacks: request.callbacks
108
+ })), ...this.getPendingRequests().map((request) => ({
109
+ state: "pending",
110
+ message: request.message,
111
+ end: request.end,
112
+ callbacks: request.callbacks
113
+ }))];
114
+ }
115
+ /**
116
+ * Checks if there are any pending requests, including ongoing subscriptions.
117
+ */
118
+ hasPendingRequests() {
119
+ return this.getPendingRequests().length > 0;
120
+ }
121
+ /**
122
+ * Checks if there are any pending subscriptions
123
+ */
124
+ hasPendingSubscriptions() {
125
+ return this.getPendingRequests().some((request) => request.message.method === "subscription");
126
+ }
127
+ /**
128
+ * Checks if there are any outgoing requests waiting to be sent.
129
+ */
130
+ hasOutgoingRequests() {
131
+ return this.outgoingRequests.length > 0;
132
+ }
133
+ };
140
134
 
135
+ //#endregion
141
136
  export { RequestManager };
137
+ //# sourceMappingURL=requestManager.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"requestManager.mjs","names":["message: TRPCClientOutgoingMessage","callbacks: TCallbacks","messageId: MessageIdLike"],"sources":["../../../../src/links/wsLink/wsClient/requestManager.ts"],"sourcesContent":["import type { AnyTRPCRouter, inferRouterError } from '@trpc/server';\nimport type { Observer } from '@trpc/server/observable';\nimport type {\n TRPCClientOutgoingMessage,\n TRPCResponseMessage,\n} from '@trpc/server/unstable-core-do-not-import';\nimport type { TRPCClientError } from '../../../TRPCClientError';\nimport { withResolvers } from './utils';\n\nexport type TCallbacks = Observer<\n TRPCResponseMessage<unknown, inferRouterError<AnyTRPCRouter>>,\n TRPCClientError<AnyTRPCRouter>\n>;\n\ntype MessageId = string;\ntype MessageIdLike = string | number | null;\n\n/**\n * Represents a WebSocket request managed by the RequestManager.\n * Combines the network message, a utility promise (`end`) that mirrors the lifecycle\n * handled by `callbacks`, and a set of state monitoring callbacks.\n */\ninterface Request {\n message: TRPCClientOutgoingMessage;\n end: Promise<void>;\n callbacks: TCallbacks;\n}\n\n/**\n * Manages WebSocket requests, tracking their lifecycle and providing utility methods\n * for handling outgoing and pending requests.\n *\n * - **Outgoing requests**: Requests that are queued and waiting to be sent.\n * - **Pending requests**: Requests that have been sent and are in flight awaiting a response.\n * For subscriptions, multiple responses may be received until the subscription is closed.\n */\nexport class RequestManager {\n /**\n * Stores requests that are outgoing, meaning they are registered but not yet sent over the WebSocket.\n */\n private outgoingRequests = new Array<Request & { id: MessageId }>();\n\n /**\n * Stores requests that are pending (in flight), meaning they have been sent over the WebSocket\n * and are awaiting responses. For subscriptions, this includes requests\n * that may receive multiple responses.\n */\n private pendingRequests: Record<MessageId, Request> = {};\n\n /**\n * Registers a new request by adding it to the outgoing queue and setting up\n * callbacks for lifecycle events such as completion or error.\n *\n * @param message - The outgoing message to be sent.\n * @param callbacks - Callback functions to observe the request's state.\n * @returns A cleanup function to manually remove the request.\n */\n public register(message: TRPCClientOutgoingMessage, callbacks: TCallbacks) {\n const { promise: end, resolve } = withResolvers<void>();\n\n this.outgoingRequests.push({\n id: String(message.id),\n message,\n end,\n callbacks: {\n next: callbacks.next,\n complete: () => {\n callbacks.complete();\n resolve();\n },\n error: (e) => {\n callbacks.error(e);\n resolve();\n },\n },\n });\n\n return () => {\n this.delete(message.id);\n callbacks.complete();\n resolve();\n };\n }\n\n /**\n * Deletes a request from both the outgoing and pending collections, if it exists.\n */\n public delete(messageId: MessageIdLike) {\n if (messageId === null) return;\n\n this.outgoingRequests = this.outgoingRequests.filter(\n ({ id }) => id !== String(messageId),\n );\n delete this.pendingRequests[String(messageId)];\n }\n\n /**\n * Moves all outgoing requests to the pending state and clears the outgoing queue.\n *\n * The caller is expected to handle the actual sending of the requests\n * (e.g., sending them over the network) after this method is called.\n *\n * @returns The list of requests that were transitioned to the pending state.\n */\n public flush() {\n const requests = this.outgoingRequests;\n this.outgoingRequests = [];\n\n for (const request of requests) {\n this.pendingRequests[request.id] = request;\n }\n return requests;\n }\n\n /**\n * Retrieves all currently pending requests, which are in flight awaiting responses\n * or handling ongoing subscriptions.\n */\n public getPendingRequests() {\n return Object.values(this.pendingRequests);\n }\n\n /**\n * Retrieves a specific pending request by its message ID.\n */\n public getPendingRequest(messageId: MessageIdLike) {\n if (messageId === null) return null;\n\n return this.pendingRequests[String(messageId)];\n }\n\n /**\n * Retrieves all outgoing requests, which are waiting to be sent.\n */\n public getOutgoingRequests() {\n return this.outgoingRequests;\n }\n\n /**\n * Retrieves all requests, both outgoing and pending, with their respective states.\n *\n * @returns An array of all requests with their state (\"outgoing\" or \"pending\").\n */\n public getRequests() {\n return [\n ...this.getOutgoingRequests().map((request) => ({\n state: 'outgoing' as const,\n message: request.message,\n end: request.end,\n callbacks: request.callbacks,\n })),\n ...this.getPendingRequests().map((request) => ({\n state: 'pending' as const,\n message: request.message,\n end: request.end,\n callbacks: request.callbacks,\n })),\n ];\n }\n\n /**\n * Checks if there are any pending requests, including ongoing subscriptions.\n */\n public hasPendingRequests() {\n return this.getPendingRequests().length > 0;\n }\n\n /**\n * Checks if there are any pending subscriptions\n */\n public hasPendingSubscriptions() {\n return this.getPendingRequests().some(\n (request) => request.message.method === 'subscription',\n );\n }\n\n /**\n * Checks if there are any outgoing requests waiting to be sent.\n */\n public hasOutgoingRequests() {\n return this.outgoingRequests.length > 0;\n }\n}\n"],"mappings":";;;;;;;;;;;AAoCA,IAAa,iBAAb,MAA4B;;;;CAI1B,AAAQ,mBAAmB,IAAI;;;;;;CAO/B,AAAQ,kBAA8C,CAAE;;;;;;;;;CAUxD,AAAO,SAASA,SAAoCC,WAAuB;EACzE,MAAM,EAAE,SAAS,KAAK,SAAS,GAAG,eAAqB;AAEvD,OAAK,iBAAiB,KAAK;GACzB,IAAI,OAAO,QAAQ,GAAG;GACtB;GACA;GACA,WAAW;IACT,MAAM,UAAU;IAChB,UAAU,MAAM;AACd,eAAU,UAAU;AACpB,cAAS;IACV;IACD,OAAO,CAAC,MAAM;AACZ,eAAU,MAAM,EAAE;AAClB,cAAS;IACV;GACF;EACF,EAAC;AAEF,SAAO,MAAM;AACX,QAAK,OAAO,QAAQ,GAAG;AACvB,aAAU,UAAU;AACpB,YAAS;EACV;CACF;;;;CAKD,AAAO,OAAOC,WAA0B;AACtC,MAAI,cAAc,KAAM;AAExB,OAAK,mBAAmB,KAAK,iBAAiB,OAC5C,CAAC,EAAE,IAAI,KAAK,OAAO,OAAO,UAAU,CACrC;AACD,SAAO,KAAK,gBAAgB,OAAO,UAAU;CAC9C;;;;;;;;;CAUD,AAAO,QAAQ;EACb,MAAM,WAAW,KAAK;AACtB,OAAK,mBAAmB,CAAE;AAE1B,OAAK,MAAM,WAAW,SACpB,MAAK,gBAAgB,QAAQ,MAAM;AAErC,SAAO;CACR;;;;;CAMD,AAAO,qBAAqB;AAC1B,SAAO,OAAO,OAAO,KAAK,gBAAgB;CAC3C;;;;CAKD,AAAO,kBAAkBA,WAA0B;AACjD,MAAI,cAAc,KAAM,QAAO;AAE/B,SAAO,KAAK,gBAAgB,OAAO,UAAU;CAC9C;;;;CAKD,AAAO,sBAAsB;AAC3B,SAAO,KAAK;CACb;;;;;;CAOD,AAAO,cAAc;AACnB,SAAO,CACL,GAAG,KAAK,qBAAqB,CAAC,IAAI,CAAC,aAAa;GAC9C,OAAO;GACP,SAAS,QAAQ;GACjB,KAAK,QAAQ;GACb,WAAW,QAAQ;EACpB,GAAE,EACH,GAAG,KAAK,oBAAoB,CAAC,IAAI,CAAC,aAAa;GAC7C,OAAO;GACP,SAAS,QAAQ;GACjB,KAAK,QAAQ;GACb,WAAW,QAAQ;EACpB,GAAE,AACJ;CACF;;;;CAKD,AAAO,qBAAqB;AAC1B,SAAO,KAAK,oBAAoB,CAAC,SAAS;CAC3C;;;;CAKD,AAAO,0BAA0B;AAC/B,SAAO,KAAK,oBAAoB,CAAC,KAC/B,CAAC,YAAY,QAAQ,QAAQ,WAAW,eACzC;CACF;;;;CAKD,AAAO,sBAAsB;AAC3B,SAAO,KAAK,iBAAiB,SAAS;CACvC;AACF"}