@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.
- package/dist/TRPCClientError.d.mts +32 -0
- package/dist/TRPCClientError.d.mts.map +1 -0
- package/dist/TRPCClientError.d.ts +28 -25
- package/dist/TRPCClientError.d.ts.map +1 -1
- package/dist/TRPCClientError.js +48 -72
- package/dist/TRPCClientError.mjs +48 -71
- package/dist/TRPCClientError.mjs.map +1 -0
- package/dist/_virtual/rolldown_runtime.js +39 -0
- package/dist/_virtual/rolldown_runtime.mjs +27 -0
- package/dist/createTRPCClient.d.mts +69 -0
- package/dist/createTRPCClient.d.mts.map +1 -0
- package/dist/createTRPCClient.d.ts +34 -34
- package/dist/createTRPCClient.d.ts.map +1 -1
- package/dist/createTRPCClient.js +34 -34
- package/dist/createTRPCClient.mjs +33 -31
- package/dist/createTRPCClient.mjs.map +1 -0
- package/dist/createTRPCUntypedClient.d.mts +8 -0
- package/dist/createTRPCUntypedClient.d.mts.map +1 -0
- package/dist/createTRPCUntypedClient.d.ts +7 -6
- package/dist/createTRPCUntypedClient.d.ts.map +1 -1
- package/dist/createTRPCUntypedClient.js +5 -6
- package/dist/createTRPCUntypedClient.mjs +6 -3
- package/dist/createTRPCUntypedClient.mjs.map +1 -0
- package/dist/getFetch.d.mts +9 -0
- package/dist/getFetch.d.mts.map +1 -0
- package/dist/getFetch.d.ts +8 -2
- package/dist/getFetch.d.ts.map +1 -1
- package/dist/getFetch.js +8 -13
- package/dist/getFetch.mjs +8 -11
- package/dist/getFetch.mjs.map +1 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -16
- package/dist/index.js +42 -42
- package/dist/index.mjs +19 -15
- package/dist/internals/TRPCUntypedClient.d.mts +45 -0
- package/dist/internals/TRPCUntypedClient.d.mts.map +1 -0
- package/dist/internals/TRPCUntypedClient.d.ts +39 -33
- package/dist/internals/TRPCUntypedClient.d.ts.map +1 -1
- package/dist/internals/TRPCUntypedClient.js +94 -113
- package/dist/internals/TRPCUntypedClient.mjs +93 -110
- package/dist/internals/TRPCUntypedClient.mjs.map +1 -0
- package/dist/internals/dataLoader.js +101 -112
- package/dist/internals/dataLoader.mjs +101 -110
- package/dist/internals/dataLoader.mjs.map +1 -0
- package/dist/internals/inputWithTrackedEventId.js +9 -12
- package/dist/internals/inputWithTrackedEventId.mjs +9 -10
- package/dist/internals/inputWithTrackedEventId.mjs.map +1 -0
- package/dist/internals/signals.js +39 -40
- package/dist/internals/signals.mjs +39 -39
- package/dist/internals/signals.mjs.map +1 -0
- package/dist/internals/transformer.d.mts +46 -0
- package/dist/internals/transformer.d.mts.map +1 -0
- package/dist/internals/transformer.d.ts +26 -22
- package/dist/internals/transformer.d.ts.map +1 -1
- package/dist/internals/transformer.js +25 -26
- package/dist/internals/transformer.mjs +25 -24
- package/dist/internals/transformer.mjs.map +1 -0
- package/dist/internals/types.d.mts +84 -0
- package/dist/internals/types.d.mts.map +1 -0
- package/dist/internals/types.d.ts +44 -42
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/links/HTTPBatchLinkOptions.d.mts +25 -0
- package/dist/links/HTTPBatchLinkOptions.d.mts.map +1 -0
- package/dist/links/HTTPBatchLinkOptions.d.ts +23 -18
- package/dist/links/HTTPBatchLinkOptions.d.ts.map +1 -1
- package/dist/links/httpBatchLink.d.mts +15 -0
- package/dist/links/httpBatchLink.d.mts.map +1 -0
- package/dist/links/httpBatchLink.d.ts +11 -4
- package/dist/links/httpBatchLink.d.ts.map +1 -1
- package/dist/links/httpBatchLink.js +90 -106
- package/dist/links/httpBatchLink.mjs +89 -103
- package/dist/links/httpBatchLink.mjs.map +1 -0
- package/dist/links/httpBatchStreamLink.d.mts +19 -0
- package/dist/links/httpBatchStreamLink.d.mts.map +1 -0
- package/dist/links/httpBatchStreamLink.d.ts +12 -5
- package/dist/links/httpBatchStreamLink.d.ts.map +1 -1
- package/dist/links/httpBatchStreamLink.js +120 -144
- package/dist/links/httpBatchStreamLink.mjs +119 -141
- package/dist/links/httpBatchStreamLink.mjs.map +1 -0
- package/dist/links/httpLink.d.mts +23 -0
- package/dist/links/httpLink.d.mts.map +1 -0
- package/dist/links/httpLink.d.ts +18 -12
- package/dist/links/httpLink.d.ts.map +1 -1
- package/dist/links/httpLink.js +74 -90
- package/dist/links/httpLink.mjs +73 -87
- package/dist/links/httpLink.mjs.map +1 -0
- package/dist/links/httpSubscriptionLink.d.mts +29 -0
- package/dist/links/httpSubscriptionLink.d.mts.map +1 -0
- package/dist/links/httpSubscriptionLink.d.ts +20 -17
- package/dist/links/httpSubscriptionLink.d.ts.map +1 -1
- package/dist/links/httpSubscriptionLink.js +134 -179
- package/dist/links/httpSubscriptionLink.mjs +133 -176
- package/dist/links/httpSubscriptionLink.mjs.map +1 -0
- package/dist/links/internals/contentTypes.d.mts +9 -0
- package/dist/links/internals/contentTypes.d.mts.map +1 -0
- package/dist/links/internals/contentTypes.d.ts +8 -3
- package/dist/links/internals/contentTypes.d.ts.map +1 -1
- package/dist/links/internals/contentTypes.js +6 -6
- package/dist/links/internals/contentTypes.mjs +6 -4
- package/dist/links/internals/contentTypes.mjs.map +1 -0
- package/dist/links/internals/createChain.js +23 -23
- package/dist/links/internals/createChain.mjs +22 -20
- package/dist/links/internals/createChain.mjs.map +1 -0
- package/dist/links/internals/httpUtils.d.mts +25 -0
- package/dist/links/internals/httpUtils.d.mts.map +1 -0
- package/dist/links/internals/httpUtils.d.ts +20 -63
- package/dist/links/internals/httpUtils.d.ts.map +1 -1
- package/dist/links/internals/httpUtils.js +93 -116
- package/dist/links/internals/httpUtils.mjs +94 -113
- package/dist/links/internals/httpUtils.mjs.map +1 -0
- package/dist/links/internals/subscriptions.d.mts +19 -0
- package/dist/links/internals/subscriptions.d.mts.map +1 -0
- package/dist/links/internals/subscriptions.d.ts +10 -8
- package/dist/links/internals/subscriptions.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.d.mts +24 -0
- package/dist/links/internals/urlWithConnectionParams.d.mts.map +1 -0
- package/dist/links/internals/urlWithConnectionParams.d.ts +19 -18
- package/dist/links/internals/urlWithConnectionParams.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.js +8 -6
- package/dist/links/internals/urlWithConnectionParams.mjs +8 -4
- package/dist/links/internals/urlWithConnectionParams.mjs.map +1 -0
- package/dist/links/localLink.d.mts +21 -0
- package/dist/links/localLink.d.mts.map +1 -0
- package/dist/links/localLink.d.ts +21 -0
- package/dist/links/localLink.d.ts.map +1 -0
- package/dist/links/localLink.js +192 -0
- package/dist/links/localLink.mjs +193 -0
- package/dist/links/localLink.mjs.map +1 -0
- package/dist/links/loggerLink.d.mts +55 -0
- package/dist/links/loggerLink.d.mts.map +1 -0
- package/dist/links/loggerLink.d.ts +39 -36
- package/dist/links/loggerLink.d.ts.map +1 -1
- package/dist/links/loggerLink.js +113 -166
- package/dist/links/loggerLink.mjs +112 -163
- package/dist/links/loggerLink.mjs.map +1 -0
- package/dist/links/retryLink.d.mts +36 -0
- package/dist/links/retryLink.d.mts.map +1 -0
- package/dist/links/retryLink.d.ts +28 -25
- package/dist/links/retryLink.d.ts.map +1 -1
- package/dist/links/retryLink.js +60 -68
- package/dist/links/retryLink.mjs +59 -65
- package/dist/links/retryLink.mjs.map +1 -0
- package/dist/links/splitLink.d.mts +20 -0
- package/dist/links/splitLink.d.mts.map +1 -0
- package/dist/links/splitLink.d.ts +18 -12
- package/dist/links/splitLink.d.ts.map +1 -1
- package/dist/links/splitLink.js +20 -21
- package/dist/links/splitLink.mjs +19 -18
- package/dist/links/splitLink.mjs.map +1 -0
- package/dist/links/types.d.mts +68 -0
- package/dist/links/types.d.mts.map +1 -0
- package/dist/links/types.d.ts +34 -29
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink/createWsClient.d.mts +9 -0
- package/dist/links/wsLink/createWsClient.d.mts.map +1 -0
- package/dist/links/wsLink/createWsClient.d.ts +8 -5
- package/dist/links/wsLink/createWsClient.d.ts.map +1 -1
- package/dist/links/wsLink/createWsClient.js +5 -5
- package/dist/links/wsLink/createWsClient.mjs +5 -2
- package/dist/links/wsLink/createWsClient.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/options.d.mts +69 -0
- package/dist/links/wsLink/wsClient/options.d.mts.map +1 -0
- package/dist/links/wsLink/wsClient/options.d.ts +53 -63
- package/dist/links/wsLink/wsClient/options.d.ts.map +1 -1
- package/dist/links/wsLink/wsClient/options.js +14 -12
- package/dist/links/wsLink/wsClient/options.mjs +14 -10
- package/dist/links/wsLink/wsClient/options.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/requestManager.js +133 -140
- package/dist/links/wsLink/wsClient/requestManager.mjs +133 -137
- package/dist/links/wsLink/wsClient/requestManager.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/utils.js +64 -81
- package/dist/links/wsLink/wsClient/utils.mjs +64 -78
- package/dist/links/wsLink/wsClient/utils.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/wsClient.d.mts +101 -0
- package/dist/links/wsLink/wsClient/wsClient.d.mts.map +1 -0
- package/dist/links/wsLink/wsClient/wsClient.d.ts +95 -78
- package/dist/links/wsLink/wsClient/wsClient.d.ts.map +1 -1
- package/dist/links/wsLink/wsClient/wsClient.js +273 -322
- package/dist/links/wsLink/wsClient/wsClient.mjs +272 -319
- package/dist/links/wsLink/wsClient/wsClient.mjs.map +1 -0
- package/dist/links/wsLink/wsClient/wsConnection.js +155 -178
- package/dist/links/wsLink/wsClient/wsConnection.mjs +154 -175
- package/dist/links/wsLink/wsClient/wsConnection.mjs.map +1 -0
- package/dist/links/wsLink/wsLink.d.mts +14 -0
- package/dist/links/wsLink/wsLink.d.mts.map +1 -0
- package/dist/links/wsLink/wsLink.d.ts +12 -9
- package/dist/links/wsLink/wsLink.d.ts.map +1 -1
- package/dist/links/wsLink/wsLink.js +30 -31
- package/dist/links/wsLink/wsLink.mjs +29 -28
- package/dist/links/wsLink/wsLink.mjs.map +1 -0
- package/dist/links.js +11 -0
- package/dist/links.mjs +11 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +68 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +66 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.72.2/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs.map +1 -0
- package/dist/unstable-internals.d.mts +3 -0
- package/dist/unstable-internals.d.ts +3 -3
- package/dist/unstable-internals.js +2 -6
- package/dist/unstable-internals.mjs +3 -1
- package/links/httpBatchLink/package.json +1 -0
- package/links/httpLink/package.json +1 -0
- package/links/loggerLink/package.json +1 -0
- package/links/splitLink/package.json +1 -0
- package/links/wsLink/wsLink/package.json +1 -0
- package/package.json +63 -30
- package/src/TRPCClientError.ts +4 -9
- package/src/internals/signals.ts +16 -0
- package/src/links/httpSubscriptionLink.ts +3 -18
- package/src/links/localLink.ts +277 -0
- package/src/links.ts +1 -0
- package/unstable-internals/package.json +1 -0
- package/dist/bundle-analysis.json +0 -433
- package/dist/index.d.ts.map +0 -1
- package/dist/internals/dataLoader.d.ts +0 -13
- package/dist/internals/dataLoader.d.ts.map +0 -1
- package/dist/internals/inputWithTrackedEventId.d.ts +0 -2
- package/dist/internals/inputWithTrackedEventId.d.ts.map +0 -1
- package/dist/internals/signals.d.ts +0 -15
- package/dist/internals/signals.d.ts.map +0 -1
- package/dist/links/internals/createChain.d.ts +0 -8
- package/dist/links/internals/createChain.d.ts.map +0 -1
- package/dist/links/internals/dedupeLink.d.ts +0 -7
- package/dist/links/internals/dedupeLink.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/requestManager.d.ts +0 -106
- package/dist/links/wsLink/wsClient/requestManager.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/utils.d.ts +0 -38
- package/dist/links/wsLink/wsClient/utils.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/wsConnection.d.ts +0 -79
- package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +0 -1
- package/dist/links.d.ts +0 -11
- package/dist/links.d.ts.map +0 -1
- package/dist/unstable-internals.d.ts.map +0 -1
- package/links/httpBatchLink/index.d.ts +0 -1
- package/links/httpBatchLink/index.js +0 -1
- package/links/httpLink/index.d.ts +0 -1
- package/links/httpLink/index.js +0 -1
- package/links/loggerLink/index.d.ts +0 -1
- package/links/loggerLink/index.js +0 -1
- package/links/splitLink/index.d.ts +0 -1
- package/links/splitLink/index.js +0 -1
- package/links/wsLink/wsLink/index.d.ts +0 -1
- package/links/wsLink/wsLink/index.js +0 -1
- package/unstable-internals/index.d.ts +0 -1
- package/unstable-internals/index.js +0 -1
|
@@ -1,143 +1,136 @@
|
|
|
1
|
-
|
|
1
|
+
const require_utils = require('./utils.js');
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
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
|
-
|
|
135
|
+
//#endregion
|
|
136
|
+
exports.RequestManager = RequestManager;
|
|
@@ -1,141 +1,137 @@
|
|
|
1
|
-
import { withResolvers } from
|
|
1
|
+
import { withResolvers } from "./utils.mjs";
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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"}
|