@trpc/client 11.3.1-canary.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/bundle-analysis.json +0 -451
- 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/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
package/dist/links/retryLink.mjs
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { observable } from '@trpc/server/observable';
|
|
2
|
-
import { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId.mjs';
|
|
3
|
-
|
|
4
|
-
/* istanbul ignore file -- @preserve */ // We're not actually exporting this link
|
|
5
|
-
/**
|
|
6
|
-
* @see https://trpc.io/docs/v11/client/links/retryLink
|
|
7
|
-
*/ function retryLink(opts) {
|
|
8
|
-
// initialized config
|
|
9
|
-
return ()=>{
|
|
10
|
-
// initialized in app
|
|
11
|
-
return (callOpts)=>{
|
|
12
|
-
// initialized for request
|
|
13
|
-
return observable((observer)=>{
|
|
14
|
-
let next$;
|
|
15
|
-
let callNextTimeout = undefined;
|
|
16
|
-
let lastEventId = undefined;
|
|
17
|
-
attempt(1);
|
|
18
|
-
function opWithLastEventId() {
|
|
19
|
-
const op = callOpts.op;
|
|
20
|
-
if (!lastEventId) {
|
|
21
|
-
return op;
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
...op,
|
|
25
|
-
input: inputWithTrackedEventId(op.input, lastEventId)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function attempt(attempts) {
|
|
29
|
-
const op = opWithLastEventId();
|
|
30
|
-
next$ = callOpts.next(op).subscribe({
|
|
31
|
-
error (error) {
|
|
32
|
-
const shouldRetry = opts.retry({
|
|
33
|
-
op,
|
|
34
|
-
attempts,
|
|
35
|
-
error
|
|
36
|
-
});
|
|
37
|
-
if (!shouldRetry) {
|
|
38
|
-
observer.error(error);
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const delayMs = opts.retryDelayMs?.(attempts) ?? 0;
|
|
42
|
-
if (delayMs <= 0) {
|
|
43
|
-
attempt(attempts + 1);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
callNextTimeout = setTimeout(()=>attempt(attempts + 1), delayMs);
|
|
47
|
-
},
|
|
48
|
-
next (envelope) {
|
|
49
|
-
//
|
|
50
|
-
if ((!envelope.result.type || envelope.result.type === 'data') && envelope.result.id) {
|
|
51
|
-
//
|
|
52
|
-
lastEventId = envelope.result.id;
|
|
53
|
-
}
|
|
54
|
-
observer.next(envelope);
|
|
55
|
-
},
|
|
56
|
-
complete () {
|
|
57
|
-
observer.complete();
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
return ()=>{
|
|
62
|
-
next$.unsubscribe();
|
|
63
|
-
clearTimeout(callNextTimeout);
|
|
64
|
-
};
|
|
65
|
-
});
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export { retryLink };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
-
import type { Operation, TRPCLink } from './types';
|
|
3
|
-
export declare function splitLink<TRouter extends AnyRouter = AnyRouter>(opts: {
|
|
4
|
-
condition: (op: Operation) => boolean;
|
|
5
|
-
/**
|
|
6
|
-
* The link to execute next if the test function returns `true`.
|
|
7
|
-
*/
|
|
8
|
-
true: TRPCLink<TRouter> | TRPCLink<TRouter>[];
|
|
9
|
-
/**
|
|
10
|
-
* The link to execute next if the test function returns `false`.
|
|
11
|
-
*/
|
|
12
|
-
false: TRPCLink<TRouter> | TRPCLink<TRouter>[];
|
|
13
|
-
}): TRPCLink<TRouter>;
|
|
14
|
-
//# sourceMappingURL=splitLink.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"splitLink.d.ts","sourceRoot":"","sources":["../../src/links/splitLink.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAE1E,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKnD,wBAAgB,SAAS,CAAC,OAAO,SAAS,SAAS,GAAG,SAAS,EAAE,IAAI,EAAE;IACrE,SAAS,EAAE,CAAC,EAAE,EAAE,SAAS,KAAK,OAAO,CAAC;IACtC;;OAEG;IACH,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;IAC9C;;OAEG;IACH,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;CAChD,GAAG,QAAQ,CAAC,OAAO,CAAC,CAWpB"}
|
package/dist/links/splitLink.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var observable = require('@trpc/server/observable');
|
|
4
|
-
var createChain = require('./internals/createChain.js');
|
|
5
|
-
|
|
6
|
-
function asArray(value) {
|
|
7
|
-
return Array.isArray(value) ? value : [
|
|
8
|
-
value
|
|
9
|
-
];
|
|
10
|
-
}
|
|
11
|
-
function splitLink(opts) {
|
|
12
|
-
return (runtime)=>{
|
|
13
|
-
const yes = asArray(opts.true).map((link)=>link(runtime));
|
|
14
|
-
const no = asArray(opts.false).map((link)=>link(runtime));
|
|
15
|
-
return (props)=>{
|
|
16
|
-
return observable.observable((observer)=>{
|
|
17
|
-
const links = opts.condition(props.op) ? yes : no;
|
|
18
|
-
return createChain.createChain({
|
|
19
|
-
op: props.op,
|
|
20
|
-
links
|
|
21
|
-
}).subscribe(observer);
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
exports.splitLink = splitLink;
|
package/dist/links/types.d.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { Observable, Observer } from '@trpc/server/observable';
|
|
2
|
-
import type { InferrableClientTypes, Maybe, TRPCResultMessage, TRPCSuccessResponse } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
-
import type { ResponseEsque } from '../internals/types';
|
|
4
|
-
import type { TRPCClientError } from '../TRPCClientError';
|
|
5
|
-
import type { TRPCConnectionState } from './internals/subscriptions';
|
|
6
|
-
export { isNonJsonSerializable, isFormData, isOctetType, } from './internals/contentTypes';
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export interface OperationContext extends Record<string, unknown> {
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* @internal
|
|
14
|
-
*/
|
|
15
|
-
export type Operation<TInput = unknown> = {
|
|
16
|
-
id: number;
|
|
17
|
-
type: 'mutation' | 'query' | 'subscription';
|
|
18
|
-
input: TInput;
|
|
19
|
-
path: string;
|
|
20
|
-
context: OperationContext;
|
|
21
|
-
signal: Maybe<AbortSignal>;
|
|
22
|
-
};
|
|
23
|
-
interface HeadersInitEsque {
|
|
24
|
-
[Symbol.iterator](): IterableIterator<[string, string]>;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* @internal
|
|
28
|
-
*/
|
|
29
|
-
export type HTTPHeaders = HeadersInitEsque | Record<string, string[] | string | undefined>;
|
|
30
|
-
/**
|
|
31
|
-
* The default `fetch` implementation has an overloaded signature. By convention this library
|
|
32
|
-
* only uses the overload taking a string and options object.
|
|
33
|
-
*/
|
|
34
|
-
export type TRPCFetch = (url: string, options?: RequestInit) => Promise<ResponseEsque>;
|
|
35
|
-
export interface TRPCClientRuntime {
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
export interface OperationResultEnvelope<TOutput, TError> {
|
|
41
|
-
result: TRPCResultMessage<TOutput>['result'] | TRPCSuccessResponse<TOutput>['result'] | TRPCConnectionState<TError>;
|
|
42
|
-
context?: OperationContext;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* @internal
|
|
46
|
-
*/
|
|
47
|
-
export type OperationResultObservable<TInferrable extends InferrableClientTypes, TOutput> = Observable<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>;
|
|
48
|
-
/**
|
|
49
|
-
* @internal
|
|
50
|
-
*/
|
|
51
|
-
export type OperationResultObserver<TInferrable extends InferrableClientTypes, TOutput> = Observer<OperationResultEnvelope<TOutput, TRPCClientError<TInferrable>>, TRPCClientError<TInferrable>>;
|
|
52
|
-
/**
|
|
53
|
-
* @internal
|
|
54
|
-
*/
|
|
55
|
-
export type OperationLink<TInferrable extends InferrableClientTypes, TInput = unknown, TOutput = unknown> = (opts: {
|
|
56
|
-
op: Operation<TInput>;
|
|
57
|
-
next: (op: Operation<TInput>) => OperationResultObservable<TInferrable, TOutput>;
|
|
58
|
-
}) => OperationResultObservable<TInferrable, TOutput>;
|
|
59
|
-
/**
|
|
60
|
-
* @public
|
|
61
|
-
*/
|
|
62
|
-
export type TRPCLink<TInferrable extends InferrableClientTypes> = (opts: TRPCClientRuntime) => OperationLink<TInferrable>;
|
|
63
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/links/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { WebSocketClientOptions } from './wsClient/options';
|
|
2
|
-
import { WsClient } from './wsClient/wsClient';
|
|
3
|
-
export declare function createWSClient(opts: WebSocketClientOptions): WsClient;
|
|
4
|
-
export type TRPCWebSocketClient = ReturnType<typeof createWSClient>;
|
|
5
|
-
export { WebSocketClientOptions };
|
|
6
|
-
//# sourceMappingURL=createWsClient.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createWsClient.d.ts","sourceRoot":"","sources":["../../../src/links/wsLink/createWsClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAE/C,wBAAgB,cAAc,CAAC,IAAI,EAAE,sBAAsB,YAE1D;AAED,MAAM,MAAM,mBAAmB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAEpE,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import type { UrlOptionsWithConnectionParams } from '../../internals/urlWithConnectionParams';
|
|
2
|
-
export interface WebSocketClientOptions extends UrlOptionsWithConnectionParams {
|
|
3
|
-
/**
|
|
4
|
-
* Ponyfill which WebSocket implementation to use
|
|
5
|
-
*/
|
|
6
|
-
WebSocket?: typeof WebSocket;
|
|
7
|
-
/**
|
|
8
|
-
* The number of milliseconds before a reconnect is attempted.
|
|
9
|
-
* @default {@link exponentialBackoff}
|
|
10
|
-
*/
|
|
11
|
-
retryDelayMs?: (attemptIndex: number) => number;
|
|
12
|
-
/**
|
|
13
|
-
* Triggered when a WebSocket connection is established
|
|
14
|
-
*/
|
|
15
|
-
onOpen?: () => void;
|
|
16
|
-
/**
|
|
17
|
-
* Triggered when a WebSocket connection encounters an error
|
|
18
|
-
*/
|
|
19
|
-
onError?: (evt?: Event) => void;
|
|
20
|
-
/**
|
|
21
|
-
* Triggered when a WebSocket connection is closed
|
|
22
|
-
*/
|
|
23
|
-
onClose?: (cause?: {
|
|
24
|
-
code?: number;
|
|
25
|
-
}) => void;
|
|
26
|
-
/**
|
|
27
|
-
* Lazy mode will close the WebSocket automatically after a period of inactivity (no messages sent or received and no pending requests)
|
|
28
|
-
*/
|
|
29
|
-
lazy?: {
|
|
30
|
-
/**
|
|
31
|
-
* Enable lazy mode
|
|
32
|
-
* @default false
|
|
33
|
-
*/
|
|
34
|
-
enabled: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* Close the WebSocket after this many milliseconds
|
|
37
|
-
* @default 0
|
|
38
|
-
*/
|
|
39
|
-
closeMs: number;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Send ping messages to the server and kill the connection if no pong message is returned
|
|
43
|
-
*/
|
|
44
|
-
keepAlive?: {
|
|
45
|
-
/**
|
|
46
|
-
* @default false
|
|
47
|
-
*/
|
|
48
|
-
enabled: boolean;
|
|
49
|
-
/**
|
|
50
|
-
* Send a ping message every this many milliseconds
|
|
51
|
-
* @default 5_000
|
|
52
|
-
*/
|
|
53
|
-
intervalMs?: number;
|
|
54
|
-
/**
|
|
55
|
-
* Close the WebSocket after this many milliseconds if the server does not respond
|
|
56
|
-
* @default 1_000
|
|
57
|
-
*/
|
|
58
|
-
pongTimeoutMs?: number;
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Default options for lazy WebSocket connections.
|
|
63
|
-
* Determines whether the connection should be established lazily and defines the delay before closure.
|
|
64
|
-
*/
|
|
65
|
-
export type LazyOptions = Required<NonNullable<WebSocketClientOptions['lazy']>>;
|
|
66
|
-
export declare const lazyDefaults: LazyOptions;
|
|
67
|
-
/**
|
|
68
|
-
* Default options for the WebSocket keep-alive mechanism.
|
|
69
|
-
* Configures whether keep-alive is enabled and specifies the timeout and interval for ping-pong messages.
|
|
70
|
-
*/
|
|
71
|
-
export type KeepAliveOptions = Required<NonNullable<WebSocketClientOptions['keepAlive']>>;
|
|
72
|
-
export declare const keepAliveDefaults: KeepAliveOptions;
|
|
73
|
-
/**
|
|
74
|
-
* Calculates a delay for exponential backoff based on the retry attempt index.
|
|
75
|
-
* The delay starts at 0 for the first attempt and doubles for each subsequent attempt,
|
|
76
|
-
* capped at 30 seconds.
|
|
77
|
-
*/
|
|
78
|
-
export declare const exponentialBackoff: (attemptIndex: number) => number;
|
|
79
|
-
//# sourceMappingURL=options.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../../../src/links/wsLink/wsClient/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAE9F,MAAM,WAAW,sBAAuB,SAAQ,8BAA8B;IAC5E;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,SAAS,CAAC;IAC7B;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,MAAM,CAAC;IAChD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,IAAI,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IAChC;;OAEG;IACH,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IAC9C;;OAEG;IACH,IAAI,CAAC,EAAE;QACL;;;WAGG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;IACF;;OAEG;IACH,SAAS,CAAC,EAAE;QACV;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;;WAGG;QACH,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB;;;WAGG;QACH,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,sBAAsB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AAChF,eAAO,MAAM,YAAY,EAAE,WAG1B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,GAAG,QAAQ,CACrC,WAAW,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC,CACjD,CAAC;AACF,eAAO,MAAM,iBAAiB,EAAE,gBAI/B,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,cAAc,MAAM,WAEtD,CAAC"}
|
|
@@ -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;
|