@trpc/client 11.3.1 → 11.3.2-canary.2
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-CGgRtttT.cjs +67 -0
- package/dist/TRPCClientError-COkhCKf3.mjs +56 -0
- package/dist/TRPCClientError-COkhCKf3.mjs.map +1 -0
- package/dist/chunk-DWy1uDak.cjs +39 -0
- package/dist/httpBatchLink-CIC9PZ_Z.cjs +267 -0
- package/dist/httpBatchLink-DIfnmmcu.mjs +238 -0
- package/dist/httpBatchLink-DIfnmmcu.mjs.map +1 -0
- package/dist/httpBatchLink.d-BN2Iw_cK.d.mts +33 -0
- package/dist/httpBatchLink.d-BN2Iw_cK.d.mts.map +1 -0
- package/dist/httpBatchLink.d-CLAuJKNV.d.cts +33 -0
- package/dist/httpBatchLink.d-CLAuJKNV.d.cts.map +1 -0
- package/dist/httpLink-9bpwQ15c.mjs +90 -0
- package/dist/httpLink-9bpwQ15c.mjs.map +1 -0
- package/dist/httpLink-BbVj_TgM.cjs +113 -0
- package/dist/httpLink.d-CTSOARfE.d.mts +23 -0
- package/dist/httpLink.d-CTSOARfE.d.mts.map +1 -0
- package/dist/httpLink.d-yMKfOlTU.d.cts +23 -0
- package/dist/httpLink.d-yMKfOlTU.d.cts.map +1 -0
- package/dist/httpUtils-3pbQzhUL.mjs +123 -0
- package/dist/httpUtils-3pbQzhUL.mjs.map +1 -0
- package/dist/httpUtils-Buf6jCgh.cjs +163 -0
- package/dist/httpUtils.d-C8wPxU79.d.mts +25 -0
- package/dist/httpUtils.d-C8wPxU79.d.mts.map +1 -0
- package/dist/httpUtils.d-DNRVGNHs.d.cts +25 -0
- package/dist/httpUtils.d-DNRVGNHs.d.cts.map +1 -0
- package/dist/index.cjs +731 -0
- package/dist/index.d.cts +197 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +197 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +733 -16
- package/dist/index.mjs.map +1 -0
- package/dist/links/httpBatchLink.cjs +6 -0
- package/dist/links/httpBatchLink.d.cts +6 -0
- package/dist/links/httpBatchLink.d.mts +6 -0
- package/dist/links/httpBatchLink.mjs +5 -107
- package/dist/links/httpLink.cjs +6 -0
- package/dist/links/httpLink.d.cts +6 -0
- package/dist/links/httpLink.d.mts +6 -0
- package/dist/links/httpLink.mjs +5 -92
- package/dist/links/loggerLink.cjs +3 -0
- package/dist/links/loggerLink.d.cts +4 -0
- package/dist/links/loggerLink.d.mts +4 -0
- package/dist/links/loggerLink.mjs +2 -175
- package/dist/links/splitLink.cjs +3 -0
- package/dist/links/splitLink.d.cts +4 -0
- package/dist/links/splitLink.d.mts +4 -0
- package/dist/links/splitLink.mjs +2 -24
- package/dist/links/wsLink/wsLink.cjs +6 -0
- package/dist/links/wsLink/wsLink.d.cts +5 -0
- package/dist/links/wsLink/wsLink.d.mts +5 -0
- package/dist/links/wsLink/wsLink.mjs +4 -31
- package/dist/loggerLink-CsDfg5Bb.cjs +130 -0
- package/dist/loggerLink-PGBSQFcR.mjs +125 -0
- package/dist/loggerLink-PGBSQFcR.mjs.map +1 -0
- package/dist/loggerLink.d-CZjK1CXm.d.mts +54 -0
- package/dist/loggerLink.d-CZjK1CXm.d.mts.map +1 -0
- package/dist/loggerLink.d-DU855urG.d.cts +54 -0
- package/dist/loggerLink.d-DU855urG.d.cts.map +1 -0
- package/dist/splitLink-BMgxggng.cjs +58 -0
- package/dist/splitLink-BVblHq4n.mjs +47 -0
- package/dist/splitLink-BVblHq4n.mjs.map +1 -0
- package/dist/splitLink.d-BAqgq0NG.d.mts +20 -0
- package/dist/splitLink.d-BAqgq0NG.d.mts.map +1 -0
- package/dist/splitLink.d-GdevSkGW.d.cts +20 -0
- package/dist/splitLink.d-GdevSkGW.d.cts.map +1 -0
- package/dist/subscriptions.d-Ciljg_dH.d.cts +19 -0
- package/dist/subscriptions.d-Ciljg_dH.d.cts.map +1 -0
- package/dist/subscriptions.d-U92STdZl.d.mts +19 -0
- package/dist/subscriptions.d-U92STdZl.d.mts.map +1 -0
- package/dist/types.d-DXbqQLCC.d.mts +182 -0
- package/dist/types.d-DXbqQLCC.d.mts.map +1 -0
- package/dist/types.d-DqGYG6S_.d.cts +182 -0
- package/dist/types.d-DqGYG6S_.d.cts.map +1 -0
- package/dist/unstable-internals-CYBH4jbF.cjs +34 -0
- package/dist/unstable-internals-DU4WecoG.mjs +29 -0
- package/dist/unstable-internals-DU4WecoG.mjs.map +1 -0
- package/dist/unstable-internals.cjs +3 -0
- package/dist/unstable-internals.d-DyLd-B0J.d.mts +46 -0
- package/dist/unstable-internals.d-DyLd-B0J.d.mts.map +1 -0
- package/dist/unstable-internals.d-kWsZTlQq.d.cts +46 -0
- package/dist/unstable-internals.d-kWsZTlQq.d.cts.map +1 -0
- package/dist/unstable-internals.d.cts +3 -0
- package/dist/unstable-internals.d.mts +3 -0
- package/dist/unstable-internals.mjs +3 -1
- package/dist/wsLink-DbSHOzlB.mjs +698 -0
- package/dist/wsLink-DbSHOzlB.mjs.map +1 -0
- package/dist/wsLink-DhJ50EC5.cjs +715 -0
- package/dist/wsLink.d-BqO7ltN_.d.mts +194 -0
- package/dist/wsLink.d-BqO7ltN_.d.mts.map +1 -0
- package/dist/wsLink.d-DtZjg09g.d.cts +194 -0
- package/dist/wsLink.d-DtZjg09g.d.cts.map +1 -0
- 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 +67 -33
- package/unstable-internals/package.json +1 -0
- package/dist/TRPCClientError.d.ts +0 -30
- package/dist/TRPCClientError.d.ts.map +0 -1
- package/dist/TRPCClientError.js +0 -79
- package/dist/TRPCClientError.mjs +0 -76
- package/dist/createTRPCClient.d.ts +0 -69
- package/dist/createTRPCClient.d.ts.map +0 -1
- package/dist/createTRPCClient.js +0 -48
- package/dist/createTRPCClient.mjs +0 -43
- package/dist/createTRPCUntypedClient.d.ts +0 -7
- package/dist/createTRPCUntypedClient.d.ts.map +0 -1
- package/dist/createTRPCUntypedClient.js +0 -10
- package/dist/createTRPCUntypedClient.mjs +0 -7
- package/dist/getFetch.d.ts +0 -3
- package/dist/getFetch.d.ts.map +0 -1
- package/dist/getFetch.js +0 -17
- package/dist/getFetch.mjs +0 -15
- package/dist/index.d.ts +0 -16
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -46
- package/dist/internals/TRPCUntypedClient.d.ts +0 -39
- package/dist/internals/TRPCUntypedClient.d.ts.map +0 -1
- package/dist/internals/TRPCUntypedClient.js +0 -115
- package/dist/internals/TRPCUntypedClient.mjs +0 -113
- package/dist/internals/dataLoader.d.ts +0 -13
- package/dist/internals/dataLoader.d.ts.map +0 -1
- package/dist/internals/dataLoader.js +0 -117
- package/dist/internals/dataLoader.mjs +0 -115
- package/dist/internals/inputWithTrackedEventId.d.ts +0 -2
- package/dist/internals/inputWithTrackedEventId.d.ts.map +0 -1
- package/dist/internals/inputWithTrackedEventId.js +0 -16
- package/dist/internals/inputWithTrackedEventId.mjs +0 -14
- package/dist/internals/signals.d.ts +0 -16
- package/dist/internals/signals.d.ts.map +0 -1
- package/dist/internals/signals.js +0 -61
- package/dist/internals/signals.mjs +0 -57
- package/dist/internals/transformer.d.ts +0 -42
- package/dist/internals/transformer.d.ts.map +0 -1
- package/dist/internals/transformer.js +0 -30
- package/dist/internals/transformer.mjs +0 -28
- package/dist/internals/types.d.ts +0 -82
- package/dist/internals/types.d.ts.map +0 -1
- package/dist/links/HTTPBatchLinkOptions.d.ts +0 -20
- package/dist/links/HTTPBatchLinkOptions.d.ts.map +0 -1
- package/dist/links/httpBatchLink.d.ts +0 -8
- package/dist/links/httpBatchLink.d.ts.map +0 -1
- package/dist/links/httpBatchLink.js +0 -110
- package/dist/links/httpBatchStreamLink.d.ts +0 -12
- package/dist/links/httpBatchStreamLink.d.ts.map +0 -1
- package/dist/links/httpBatchStreamLink.js +0 -150
- package/dist/links/httpBatchStreamLink.mjs +0 -147
- package/dist/links/httpLink.d.ts +0 -17
- package/dist/links/httpLink.d.ts.map +0 -1
- package/dist/links/httpLink.js +0 -95
- package/dist/links/httpSubscriptionLink.d.ts +0 -26
- package/dist/links/httpSubscriptionLink.d.ts.map +0 -1
- package/dist/links/httpSubscriptionLink.js +0 -177
- package/dist/links/httpSubscriptionLink.mjs +0 -174
- package/dist/links/internals/contentTypes.d.ts +0 -4
- package/dist/links/internals/contentTypes.d.ts.map +0 -1
- package/dist/links/internals/contentTypes.js +0 -16
- package/dist/links/internals/contentTypes.mjs +0 -12
- package/dist/links/internals/createChain.d.ts +0 -8
- package/dist/links/internals/createChain.d.ts.map +0 -1
- package/dist/links/internals/createChain.js +0 -26
- package/dist/links/internals/createChain.mjs +0 -24
- package/dist/links/internals/dedupeLink.d.ts +0 -7
- package/dist/links/internals/dedupeLink.d.ts.map +0 -1
- package/dist/links/internals/httpUtils.d.ts +0 -68
- package/dist/links/internals/httpUtils.d.ts.map +0 -1
- package/dist/links/internals/httpUtils.js +0 -141
- package/dist/links/internals/httpUtils.mjs +0 -133
- package/dist/links/internals/subscriptions.d.ts +0 -17
- package/dist/links/internals/subscriptions.d.ts.map +0 -1
- package/dist/links/internals/urlWithConnectionParams.d.ts +0 -23
- package/dist/links/internals/urlWithConnectionParams.d.ts.map +0 -1
- package/dist/links/internals/urlWithConnectionParams.js +0 -10
- package/dist/links/internals/urlWithConnectionParams.mjs +0 -8
- package/dist/links/localLink.d.ts +0 -15
- package/dist/links/localLink.d.ts.map +0 -1
- package/dist/links/localLink.js +0 -333
- package/dist/links/localLink.mjs +0 -331
- package/dist/links/loggerLink.d.ts +0 -52
- package/dist/links/loggerLink.d.ts.map +0 -1
- package/dist/links/loggerLink.js +0 -178
- package/dist/links/retryLink.d.ts +0 -33
- package/dist/links/retryLink.d.ts.map +0 -1
- package/dist/links/retryLink.js +0 -72
- package/dist/links/retryLink.mjs +0 -70
- package/dist/links/splitLink.d.ts +0 -14
- package/dist/links/splitLink.d.ts.map +0 -1
- package/dist/links/splitLink.js +0 -27
- package/dist/links/types.d.ts +0 -63
- package/dist/links/types.d.ts.map +0 -1
- package/dist/links/wsLink/createWsClient.d.ts +0 -6
- package/dist/links/wsLink/createWsClient.d.ts.map +0 -1
- package/dist/links/wsLink/createWsClient.js +0 -9
- package/dist/links/wsLink/createWsClient.mjs +0 -7
- package/dist/links/wsLink/wsClient/options.d.ts +0 -79
- package/dist/links/wsLink/wsClient/options.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/options.js +0 -22
- package/dist/links/wsLink/wsClient/options.mjs +0 -18
- 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/requestManager.js +0 -143
- package/dist/links/wsLink/wsClient/requestManager.mjs +0 -141
- 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/utils.js +0 -94
- package/dist/links/wsLink/wsClient/utils.mjs +0 -88
- package/dist/links/wsLink/wsClient/wsClient.d.ts +0 -84
- package/dist/links/wsLink/wsClient/wsClient.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/wsClient.js +0 -325
- package/dist/links/wsLink/wsClient/wsClient.mjs +0 -323
- package/dist/links/wsLink/wsClient/wsConnection.d.ts +0 -79
- package/dist/links/wsLink/wsClient/wsConnection.d.ts.map +0 -1
- package/dist/links/wsLink/wsClient/wsConnection.js +0 -188
- package/dist/links/wsLink/wsClient/wsConnection.mjs +0 -185
- package/dist/links/wsLink/wsLink.d.ts +0 -11
- package/dist/links/wsLink/wsLink.d.ts.map +0 -1
- package/dist/links/wsLink/wsLink.js +0 -35
- package/dist/links.d.ts +0 -12
- package/dist/links.d.ts.map +0 -1
- package/dist/unstable-internals.d.ts +0 -3
- package/dist/unstable-internals.d.ts.map +0 -1
- package/dist/unstable-internals.js +0 -7
- 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/index.d.ts +0 -1
- package/links/wsLink/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,22 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const lazyDefaults = {
|
|
4
|
-
enabled: false,
|
|
5
|
-
closeMs: 0
|
|
6
|
-
};
|
|
7
|
-
const keepAliveDefaults = {
|
|
8
|
-
enabled: false,
|
|
9
|
-
pongTimeoutMs: 1000,
|
|
10
|
-
intervalMs: 5000
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Calculates a delay for exponential backoff based on the retry attempt index.
|
|
14
|
-
* The delay starts at 0 for the first attempt and doubles for each subsequent attempt,
|
|
15
|
-
* capped at 30 seconds.
|
|
16
|
-
*/ const exponentialBackoff = (attemptIndex)=>{
|
|
17
|
-
return attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
exports.exponentialBackoff = exponentialBackoff;
|
|
21
|
-
exports.keepAliveDefaults = keepAliveDefaults;
|
|
22
|
-
exports.lazyDefaults = lazyDefaults;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const lazyDefaults = {
|
|
2
|
-
enabled: false,
|
|
3
|
-
closeMs: 0
|
|
4
|
-
};
|
|
5
|
-
const keepAliveDefaults = {
|
|
6
|
-
enabled: false,
|
|
7
|
-
pongTimeoutMs: 1000,
|
|
8
|
-
intervalMs: 5000
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Calculates a delay for exponential backoff based on the retry attempt index.
|
|
12
|
-
* The delay starts at 0 for the first attempt and doubles for each subsequent attempt,
|
|
13
|
-
* capped at 30 seconds.
|
|
14
|
-
*/ const exponentialBackoff = (attemptIndex)=>{
|
|
15
|
-
return attemptIndex === 0 ? 0 : Math.min(1000 * 2 ** attemptIndex, 30000);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { exponentialBackoff, keepAliveDefaults, lazyDefaults };
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { AnyTRPCRouter, inferRouterError } from '@trpc/server';
|
|
2
|
-
import type { Observer } from '@trpc/server/observable';
|
|
3
|
-
import type { TRPCClientOutgoingMessage, TRPCResponseMessage } from '@trpc/server/unstable-core-do-not-import';
|
|
4
|
-
import type { TRPCClientError } from '../../../TRPCClientError';
|
|
5
|
-
export type TCallbacks = Observer<TRPCResponseMessage<unknown, inferRouterError<AnyTRPCRouter>>, TRPCClientError<AnyTRPCRouter>>;
|
|
6
|
-
type MessageId = string;
|
|
7
|
-
type MessageIdLike = string | number | null;
|
|
8
|
-
/**
|
|
9
|
-
* Represents a WebSocket request managed by the RequestManager.
|
|
10
|
-
* Combines the network message, a utility promise (`end`) that mirrors the lifecycle
|
|
11
|
-
* handled by `callbacks`, and a set of state monitoring callbacks.
|
|
12
|
-
*/
|
|
13
|
-
interface Request {
|
|
14
|
-
message: TRPCClientOutgoingMessage;
|
|
15
|
-
end: Promise<void>;
|
|
16
|
-
callbacks: TCallbacks;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
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
|
-
*/
|
|
26
|
-
export declare class RequestManager {
|
|
27
|
-
/**
|
|
28
|
-
* Stores requests that are outgoing, meaning they are registered but not yet sent over the WebSocket.
|
|
29
|
-
*/
|
|
30
|
-
private outgoingRequests;
|
|
31
|
-
/**
|
|
32
|
-
* Stores requests that are pending (in flight), meaning they have been sent over the WebSocket
|
|
33
|
-
* and are awaiting responses. For subscriptions, this includes requests
|
|
34
|
-
* that may receive multiple responses.
|
|
35
|
-
*/
|
|
36
|
-
private pendingRequests;
|
|
37
|
-
/**
|
|
38
|
-
* Registers a new request by adding it to the outgoing queue and setting up
|
|
39
|
-
* callbacks for lifecycle events such as completion or error.
|
|
40
|
-
*
|
|
41
|
-
* @param message - The outgoing message to be sent.
|
|
42
|
-
* @param callbacks - Callback functions to observe the request's state.
|
|
43
|
-
* @returns A cleanup function to manually remove the request.
|
|
44
|
-
*/
|
|
45
|
-
register(message: TRPCClientOutgoingMessage, callbacks: TCallbacks): () => void;
|
|
46
|
-
/**
|
|
47
|
-
* Deletes a request from both the outgoing and pending collections, if it exists.
|
|
48
|
-
*/
|
|
49
|
-
delete(messageId: MessageIdLike): void;
|
|
50
|
-
/**
|
|
51
|
-
* Moves all outgoing requests to the pending state and clears the outgoing queue.
|
|
52
|
-
*
|
|
53
|
-
* The caller is expected to handle the actual sending of the requests
|
|
54
|
-
* (e.g., sending them over the network) after this method is called.
|
|
55
|
-
*
|
|
56
|
-
* @returns The list of requests that were transitioned to the pending state.
|
|
57
|
-
*/
|
|
58
|
-
flush(): (Request & {
|
|
59
|
-
id: MessageId;
|
|
60
|
-
})[];
|
|
61
|
-
/**
|
|
62
|
-
* Retrieves all currently pending requests, which are in flight awaiting responses
|
|
63
|
-
* or handling ongoing subscriptions.
|
|
64
|
-
*/
|
|
65
|
-
getPendingRequests(): Request[];
|
|
66
|
-
/**
|
|
67
|
-
* Retrieves a specific pending request by its message ID.
|
|
68
|
-
*/
|
|
69
|
-
getPendingRequest(messageId: MessageIdLike): Request | null | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Retrieves all outgoing requests, which are waiting to be sent.
|
|
72
|
-
*/
|
|
73
|
-
getOutgoingRequests(): (Request & {
|
|
74
|
-
id: MessageId;
|
|
75
|
-
})[];
|
|
76
|
-
/**
|
|
77
|
-
* Retrieves all requests, both outgoing and pending, with their respective states.
|
|
78
|
-
*
|
|
79
|
-
* @returns An array of all requests with their state ("outgoing" or "pending").
|
|
80
|
-
*/
|
|
81
|
-
getRequests(): ({
|
|
82
|
-
state: "outgoing";
|
|
83
|
-
message: TRPCClientOutgoingMessage;
|
|
84
|
-
end: Promise<void>;
|
|
85
|
-
callbacks: TCallbacks;
|
|
86
|
-
} | {
|
|
87
|
-
state: "pending";
|
|
88
|
-
message: TRPCClientOutgoingMessage;
|
|
89
|
-
end: Promise<void>;
|
|
90
|
-
callbacks: TCallbacks;
|
|
91
|
-
})[];
|
|
92
|
-
/**
|
|
93
|
-
* Checks if there are any pending requests, including ongoing subscriptions.
|
|
94
|
-
*/
|
|
95
|
-
hasPendingRequests(): boolean;
|
|
96
|
-
/**
|
|
97
|
-
* Checks if there are any pending subscriptions
|
|
98
|
-
*/
|
|
99
|
-
hasPendingSubscriptions(): boolean;
|
|
100
|
-
/**
|
|
101
|
-
* Checks if there are any outgoing requests waiting to be sent.
|
|
102
|
-
*/
|
|
103
|
-
hasOutgoingRequests(): boolean;
|
|
104
|
-
}
|
|
105
|
-
export {};
|
|
106
|
-
//# sourceMappingURL=requestManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"requestManager.d.ts","sourceRoot":"","sources":["../../../../src/links/wsLink/wsClient/requestManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EACV,yBAAyB,EACzB,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAGhE,MAAM,MAAM,UAAU,GAAG,QAAQ,CAC/B,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAC,EAC7D,eAAe,CAAC,aAAa,CAAC,CAC/B,CAAC;AAEF,KAAK,SAAS,GAAG,MAAM,CAAC;AACxB,KAAK,aAAa,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE5C;;;;GAIG;AACH,UAAU,OAAO;IACf,OAAO,EAAE,yBAAyB,CAAC;IACnC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,SAAS,EAAE,UAAU,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,qBAAa,cAAc;IACzB;;OAEG;IACH,OAAO,CAAC,gBAAgB,CAA4C;IAEpE;;;;OAIG;IACH,OAAO,CAAC,eAAe,CAAkC;IAEzD;;;;;;;OAOG;IACI,QAAQ,CAAC,OAAO,EAAE,yBAAyB,EAAE,SAAS,EAAE,UAAU;IA2BzE;;OAEG;IACI,MAAM,CAAC,SAAS,EAAE,aAAa;IAStC;;;;;;;OAOG;IACI,KAAK;YAhEyC,SAAS;;IA0E9D;;;OAGG;IACI,kBAAkB;IAIzB;;OAEG;IACI,iBAAiB,CAAC,SAAS,EAAE,aAAa;IAMjD;;OAEG;IACI,mBAAmB;YA9F2B,SAAS;;IAkG9D;;;;OAIG;IACI,WAAW;;;;;;;;;;;IAiBlB;;OAEG;IACI,kBAAkB;IAIzB;;OAEG;IACI,uBAAuB;IAM9B;;OAEG;IACI,mBAAmB;CAG3B"}
|
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
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
|
-
}
|
|
18
|
-
/**
|
|
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
|
-
}
|
|
142
|
-
|
|
143
|
-
exports.RequestManager = RequestManager;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { withResolvers } from './utils.mjs';
|
|
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
|
-
}
|
|
16
|
-
/**
|
|
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
|
-
}
|
|
140
|
-
|
|
141
|
-
export { RequestManager };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { TRPCRequestInfo } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
-
import type { CallbackOrValue, UrlOptionsWithConnectionParams } from '../../internals/urlWithConnectionParams';
|
|
3
|
-
export declare class TRPCWebSocketClosedError extends Error {
|
|
4
|
-
constructor(opts: {
|
|
5
|
-
message: string;
|
|
6
|
-
cause?: unknown;
|
|
7
|
-
});
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Utility class for managing a timeout that can be started, stopped, and reset.
|
|
11
|
-
* Useful for scenarios where the timeout duration is reset dynamically based on events.
|
|
12
|
-
*/
|
|
13
|
-
export declare class ResettableTimeout {
|
|
14
|
-
private readonly onTimeout;
|
|
15
|
-
private readonly timeoutMs;
|
|
16
|
-
private timeout;
|
|
17
|
-
constructor(onTimeout: () => void, timeoutMs: number);
|
|
18
|
-
/**
|
|
19
|
-
* Resets the current timeout, restarting it with the same duration.
|
|
20
|
-
* Does nothing if no timeout is active.
|
|
21
|
-
*/
|
|
22
|
-
reset(): void;
|
|
23
|
-
start(): void;
|
|
24
|
-
stop(): void;
|
|
25
|
-
}
|
|
26
|
-
export declare function withResolvers<T>(): {
|
|
27
|
-
promise: Promise<T>;
|
|
28
|
-
resolve: (value: T | PromiseLike<T>) => void;
|
|
29
|
-
reject: (reason?: any) => void;
|
|
30
|
-
};
|
|
31
|
-
/**
|
|
32
|
-
* Resolves a WebSocket URL and optionally appends connection parameters.
|
|
33
|
-
*
|
|
34
|
-
* If connectionParams are provided, appends 'connectionParams=1' query parameter.
|
|
35
|
-
*/
|
|
36
|
-
export declare function prepareUrl(urlOptions: UrlOptionsWithConnectionParams): Promise<string>;
|
|
37
|
-
export declare function buildConnectionMessage(connectionParams: CallbackOrValue<TRPCRequestInfo['connectionParams']>): Promise<string>;
|
|
38
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/links/wsLink/wsClient/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAChB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,eAAe,EACf,8BAA8B,EAC/B,MAAM,yCAAyC,CAAC;AAGjD,qBAAa,wBAAyB,SAAQ,KAAK;gBACrC,IAAI,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAOvD;AAED;;;GAGG;AACH,qBAAa,iBAAiB;IAI1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAJ5B,OAAO,CAAC,OAAO,CAA4C;gBAGxC,SAAS,EAAE,MAAM,IAAI,EACrB,SAAS,EAAE,MAAM;IAGpC;;;OAGG;IACI,KAAK;IAOL,KAAK;IAKL,IAAI;CAIZ;AAGD,wBAAgB,aAAa,CAAC,CAAC;;qBACR,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI;sBAC1B,GAAG,KAAK,IAAI;EAQnC;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAAC,UAAU,EAAE,8BAA8B,mBAU1E;AAED,wBAAsB,sBAAsB,CAC1C,gBAAgB,EAAE,eAAe,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,mBAQvE"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var urlWithConnectionParams = require('../../internals/urlWithConnectionParams.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
|
-
}
|
|
18
|
-
class TRPCWebSocketClosedError extends Error {
|
|
19
|
-
constructor(opts){
|
|
20
|
-
super(opts.message, {
|
|
21
|
-
cause: opts.cause
|
|
22
|
-
});
|
|
23
|
-
this.name = 'TRPCWebSocketClosedError';
|
|
24
|
-
Object.setPrototypeOf(this, TRPCWebSocketClosedError.prototype);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Utility class for managing a timeout that can be started, stopped, and reset.
|
|
29
|
-
* Useful for scenarios where the timeout duration is reset dynamically based on events.
|
|
30
|
-
*/ class ResettableTimeout {
|
|
31
|
-
/**
|
|
32
|
-
* Resets the current timeout, restarting it with the same duration.
|
|
33
|
-
* Does nothing if no timeout is active.
|
|
34
|
-
*/ reset() {
|
|
35
|
-
if (!this.timeout) return;
|
|
36
|
-
clearTimeout(this.timeout);
|
|
37
|
-
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
38
|
-
}
|
|
39
|
-
start() {
|
|
40
|
-
clearTimeout(this.timeout);
|
|
41
|
-
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
42
|
-
}
|
|
43
|
-
stop() {
|
|
44
|
-
clearTimeout(this.timeout);
|
|
45
|
-
this.timeout = undefined;
|
|
46
|
-
}
|
|
47
|
-
constructor(onTimeout, timeoutMs){
|
|
48
|
-
_define_property(this, "onTimeout", void 0);
|
|
49
|
-
_define_property(this, "timeoutMs", void 0);
|
|
50
|
-
_define_property(this, "timeout", void 0);
|
|
51
|
-
this.onTimeout = onTimeout;
|
|
52
|
-
this.timeoutMs = timeoutMs;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
// Ponyfill for Promise.withResolvers https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
|
|
56
|
-
function withResolvers() {
|
|
57
|
-
let resolve;
|
|
58
|
-
let reject;
|
|
59
|
-
const promise = new Promise((res, rej)=>{
|
|
60
|
-
resolve = res;
|
|
61
|
-
reject = rej;
|
|
62
|
-
});
|
|
63
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
64
|
-
return {
|
|
65
|
-
promise,
|
|
66
|
-
resolve: resolve,
|
|
67
|
-
reject: reject
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Resolves a WebSocket URL and optionally appends connection parameters.
|
|
72
|
-
*
|
|
73
|
-
* If connectionParams are provided, appends 'connectionParams=1' query parameter.
|
|
74
|
-
*/ async function prepareUrl(urlOptions) {
|
|
75
|
-
const url = await urlWithConnectionParams.resultOf(urlOptions.url);
|
|
76
|
-
if (!urlOptions.connectionParams) return url;
|
|
77
|
-
// append `?connectionParams=1` when connection params are used
|
|
78
|
-
const prefix = url.includes('?') ? '&' : '?';
|
|
79
|
-
const connectionParams = `${prefix}connectionParams=1`;
|
|
80
|
-
return url + connectionParams;
|
|
81
|
-
}
|
|
82
|
-
async function buildConnectionMessage(connectionParams) {
|
|
83
|
-
const message = {
|
|
84
|
-
method: 'connectionParams',
|
|
85
|
-
data: await urlWithConnectionParams.resultOf(connectionParams)
|
|
86
|
-
};
|
|
87
|
-
return JSON.stringify(message);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
exports.ResettableTimeout = ResettableTimeout;
|
|
91
|
-
exports.TRPCWebSocketClosedError = TRPCWebSocketClosedError;
|
|
92
|
-
exports.buildConnectionMessage = buildConnectionMessage;
|
|
93
|
-
exports.prepareUrl = prepareUrl;
|
|
94
|
-
exports.withResolvers = withResolvers;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import { resultOf } from '../../internals/urlWithConnectionParams.mjs';
|
|
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
|
-
}
|
|
16
|
-
class TRPCWebSocketClosedError extends Error {
|
|
17
|
-
constructor(opts){
|
|
18
|
-
super(opts.message, {
|
|
19
|
-
cause: opts.cause
|
|
20
|
-
});
|
|
21
|
-
this.name = 'TRPCWebSocketClosedError';
|
|
22
|
-
Object.setPrototypeOf(this, TRPCWebSocketClosedError.prototype);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Utility class for managing a timeout that can be started, stopped, and reset.
|
|
27
|
-
* Useful for scenarios where the timeout duration is reset dynamically based on events.
|
|
28
|
-
*/ class ResettableTimeout {
|
|
29
|
-
/**
|
|
30
|
-
* Resets the current timeout, restarting it with the same duration.
|
|
31
|
-
* Does nothing if no timeout is active.
|
|
32
|
-
*/ reset() {
|
|
33
|
-
if (!this.timeout) return;
|
|
34
|
-
clearTimeout(this.timeout);
|
|
35
|
-
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
36
|
-
}
|
|
37
|
-
start() {
|
|
38
|
-
clearTimeout(this.timeout);
|
|
39
|
-
this.timeout = setTimeout(this.onTimeout, this.timeoutMs);
|
|
40
|
-
}
|
|
41
|
-
stop() {
|
|
42
|
-
clearTimeout(this.timeout);
|
|
43
|
-
this.timeout = undefined;
|
|
44
|
-
}
|
|
45
|
-
constructor(onTimeout, timeoutMs){
|
|
46
|
-
_define_property(this, "onTimeout", void 0);
|
|
47
|
-
_define_property(this, "timeoutMs", void 0);
|
|
48
|
-
_define_property(this, "timeout", void 0);
|
|
49
|
-
this.onTimeout = onTimeout;
|
|
50
|
-
this.timeoutMs = timeoutMs;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
// Ponyfill for Promise.withResolvers https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
|
|
54
|
-
function withResolvers() {
|
|
55
|
-
let resolve;
|
|
56
|
-
let reject;
|
|
57
|
-
const promise = new Promise((res, rej)=>{
|
|
58
|
-
resolve = res;
|
|
59
|
-
reject = rej;
|
|
60
|
-
});
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
62
|
-
return {
|
|
63
|
-
promise,
|
|
64
|
-
resolve: resolve,
|
|
65
|
-
reject: reject
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Resolves a WebSocket URL and optionally appends connection parameters.
|
|
70
|
-
*
|
|
71
|
-
* If connectionParams are provided, appends 'connectionParams=1' query parameter.
|
|
72
|
-
*/ async function prepareUrl(urlOptions) {
|
|
73
|
-
const url = await resultOf(urlOptions.url);
|
|
74
|
-
if (!urlOptions.connectionParams) return url;
|
|
75
|
-
// append `?connectionParams=1` when connection params are used
|
|
76
|
-
const prefix = url.includes('?') ? '&' : '?';
|
|
77
|
-
const connectionParams = `${prefix}connectionParams=1`;
|
|
78
|
-
return url + connectionParams;
|
|
79
|
-
}
|
|
80
|
-
async function buildConnectionMessage(connectionParams) {
|
|
81
|
-
const message = {
|
|
82
|
-
method: 'connectionParams',
|
|
83
|
-
data: await resultOf(connectionParams)
|
|
84
|
-
};
|
|
85
|
-
return JSON.stringify(message);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export { ResettableTimeout, TRPCWebSocketClosedError, buildConnectionMessage, prepareUrl, withResolvers };
|