@trpc/client 11.1.2 → 11.1.3-alpha-tmp-tsdown.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/TRPCClientError.d.mts +33 -0
- package/dist/TRPCClientError.d.mts.map +1 -0
- package/dist/TRPCClientError.d.ts +29 -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 +73 -0
- package/dist/createTRPCClient.d.mts.map +1 -0
- package/dist/createTRPCClient.d.ts +38 -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 +9 -0
- package/dist/createTRPCUntypedClient.d.mts.map +1 -0
- package/dist/createTRPCUntypedClient.d.ts +8 -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 +10 -0
- package/dist/getFetch.d.mts.map +1 -0
- package/dist/getFetch.d.ts +9 -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 +41 -42
- package/dist/index.mjs +18 -15
- package/dist/internals/TRPCUntypedClient.d.mts +46 -0
- package/dist/internals/TRPCUntypedClient.d.mts.map +1 -0
- package/dist/internals/TRPCUntypedClient.d.ts +40 -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 -116
- package/dist/internals/dataLoader.mjs +101 -114
- 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 +47 -0
- package/dist/internals/transformer.d.mts.map +1 -0
- package/dist/internals/transformer.d.ts +28 -23
- 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 +85 -0
- package/dist/internals/types.d.mts.map +1 -0
- package/dist/internals/types.d.ts +45 -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 +18 -0
- package/dist/links/httpBatchLink.d.mts.map +1 -0
- package/dist/links/httpBatchLink.d.ts +14 -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 +22 -0
- package/dist/links/httpBatchStreamLink.d.mts.map +1 -0
- package/dist/links/httpBatchStreamLink.d.ts +15 -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 +24 -0
- package/dist/links/httpLink.d.mts.map +1 -0
- package/dist/links/httpLink.d.ts +19 -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 +30 -0
- package/dist/links/httpSubscriptionLink.d.mts.map +1 -0
- package/dist/links/httpSubscriptionLink.d.ts +21 -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 +10 -0
- package/dist/links/internals/contentTypes.d.mts.map +1 -0
- package/dist/links/internals/contentTypes.d.ts +9 -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 +26 -0
- package/dist/links/internals/httpUtils.d.mts.map +1 -0
- package/dist/links/internals/httpUtils.d.ts +22 -64
- 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 +20 -0
- package/dist/links/internals/subscriptions.d.mts.map +1 -0
- package/dist/links/internals/subscriptions.d.ts +11 -8
- package/dist/links/internals/subscriptions.d.ts.map +1 -1
- package/dist/links/internals/urlWithConnectionParams.d.mts +27 -0
- package/dist/links/internals/urlWithConnectionParams.d.mts.map +1 -0
- package/dist/links/internals/urlWithConnectionParams.d.ts +22 -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 +22 -0
- package/dist/links/localLink.d.mts.map +1 -0
- package/dist/links/localLink.d.ts +22 -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 +56 -0
- package/dist/links/loggerLink.d.mts.map +1 -0
- package/dist/links/loggerLink.d.ts +40 -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 +35 -0
- package/dist/links/retryLink.d.mts.map +1 -0
- package/dist/links/retryLink.d.ts +27 -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 +21 -0
- package/dist/links/splitLink.d.mts.map +1 -0
- package/dist/links/splitLink.d.ts +19 -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 +71 -0
- package/dist/links/types.d.mts.map +1 -0
- package/dist/links/types.d.ts +37 -29
- package/dist/links/types.d.ts.map +1 -1
- package/dist/links/wsLink/createWsClient.d.mts +10 -0
- package/dist/links/wsLink/createWsClient.d.mts.map +1 -0
- package/dist/links/wsLink/createWsClient.d.ts +9 -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 +54 -64
- 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 -135
- package/dist/links/wsLink/wsClient/requestManager.mjs +133 -132
- 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 +104 -0
- package/dist/links/wsLink/wsClient/wsClient.d.mts.map +1 -0
- package/dist/links/wsLink/wsClient/wsClient.d.ts +99 -79
- 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 +15 -0
- package/dist/links/wsLink/wsLink.d.mts.map +1 -0
- package/dist/links/wsLink/wsLink.d.ts +13 -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.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.js +68 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/node_modules/@oxc-project/runtime/src/helpers/usingCtx.mjs +66 -0
- package/dist/node_modules/.pnpm/@oxc-project_runtime@0.71.0/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 +64 -29
- package/src/TRPCClientError.ts +4 -9
- package/src/internals/dataLoader.ts +2 -6
- package/src/internals/signals.ts +16 -0
- package/src/links/httpSubscriptionLink.ts +3 -18
- package/src/links/localLink.ts +277 -0
- package/src/links/wsLink/wsClient/requestManager.ts +9 -0
- package/src/links/wsLink/wsClient/wsClient.ts +1 -1
- package/src/links.ts +1 -0
- package/unstable-internals/package.json +1 -0
- 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 -102
- 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
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getTRPCErrorFromUnknown,
|
|
3
|
+
getTRPCErrorShape,
|
|
4
|
+
isTrackedEnvelope,
|
|
5
|
+
} from '@trpc/server';
|
|
6
|
+
import { behaviorSubject, observable } from '@trpc/server/observable';
|
|
7
|
+
import { TRPC_ERROR_CODES_BY_KEY, type TRPCResult } from '@trpc/server/rpc';
|
|
8
|
+
import {
|
|
9
|
+
callProcedure,
|
|
10
|
+
isAbortError,
|
|
11
|
+
isAsyncIterable,
|
|
12
|
+
iteratorResource,
|
|
13
|
+
makeResource,
|
|
14
|
+
retryableRpcCodes,
|
|
15
|
+
run,
|
|
16
|
+
type AnyRouter,
|
|
17
|
+
type ErrorHandlerOptions,
|
|
18
|
+
type inferClientTypes,
|
|
19
|
+
type inferRouterContext,
|
|
20
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
21
|
+
import { inputWithTrackedEventId } from '../internals/inputWithTrackedEventId';
|
|
22
|
+
import { abortSignalToPromise, raceAbortSignals } from '../internals/signals';
|
|
23
|
+
import { getTransformer } from '../internals/transformer';
|
|
24
|
+
import type { TransformerOptions } from '../internals/transformer';
|
|
25
|
+
import { isTRPCClientError, TRPCClientError } from '../TRPCClientError';
|
|
26
|
+
import type { TRPCConnectionState } from './internals/subscriptions';
|
|
27
|
+
import type { TRPCLink } from './types';
|
|
28
|
+
|
|
29
|
+
export type LocalLinkOptions<TRouter extends AnyRouter> = {
|
|
30
|
+
router: TRouter;
|
|
31
|
+
createContext: () => Promise<inferRouterContext<TRouter>>;
|
|
32
|
+
onError?: (opts: ErrorHandlerOptions<inferRouterContext<TRouter>>) => void;
|
|
33
|
+
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* localLink is a terminating link that allows you to make tRPC procedure calls directly in your application without going through HTTP.
|
|
37
|
+
*
|
|
38
|
+
* @see https://trpc.io/docs/links/localLink
|
|
39
|
+
*/
|
|
40
|
+
export function experimental_localLink<TRouter extends AnyRouter>(
|
|
41
|
+
opts: LocalLinkOptions<TRouter>,
|
|
42
|
+
): TRPCLink<TRouter> {
|
|
43
|
+
const transformer = getTransformer(opts.transformer);
|
|
44
|
+
|
|
45
|
+
const transformChunk = (chunk: unknown) => {
|
|
46
|
+
if (opts.transformer) {
|
|
47
|
+
// assume transformer will do the right thing
|
|
48
|
+
return chunk;
|
|
49
|
+
}
|
|
50
|
+
// Special case for undefined, because `JSON.stringify(undefined)` throws
|
|
51
|
+
if (chunk === undefined) {
|
|
52
|
+
return chunk;
|
|
53
|
+
}
|
|
54
|
+
const serialized = JSON.stringify(transformer.input.serialize(chunk));
|
|
55
|
+
const deserialized = JSON.parse(transformer.output.deserialize(serialized));
|
|
56
|
+
return deserialized;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return () =>
|
|
60
|
+
({ op }) =>
|
|
61
|
+
observable((observer) => {
|
|
62
|
+
let ctx: inferRouterContext<TRouter> | undefined = undefined;
|
|
63
|
+
const ac = new AbortController();
|
|
64
|
+
|
|
65
|
+
const signal = raceAbortSignals(op.signal, ac.signal);
|
|
66
|
+
const signalPromise = abortSignalToPromise(signal);
|
|
67
|
+
|
|
68
|
+
signalPromise.catch(() => {
|
|
69
|
+
// prevent unhandled rejection
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
let input = op.input;
|
|
73
|
+
async function runProcedure(newInput: unknown): Promise<unknown> {
|
|
74
|
+
input = newInput;
|
|
75
|
+
|
|
76
|
+
ctx = await opts.createContext();
|
|
77
|
+
|
|
78
|
+
return callProcedure({
|
|
79
|
+
router: opts.router,
|
|
80
|
+
path: op.path,
|
|
81
|
+
getRawInput: async () => newInput,
|
|
82
|
+
ctx,
|
|
83
|
+
type: op.type,
|
|
84
|
+
signal,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function onErrorCallback(cause: unknown) {
|
|
89
|
+
if (isAbortError(cause)) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
opts.onError?.({
|
|
93
|
+
error: getTRPCErrorFromUnknown(cause),
|
|
94
|
+
type: op.type,
|
|
95
|
+
path: op.path,
|
|
96
|
+
input,
|
|
97
|
+
ctx,
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function coerceToTRPCClientError(cause: unknown) {
|
|
102
|
+
if (isTRPCClientError<TRouter>(cause)) {
|
|
103
|
+
return cause;
|
|
104
|
+
}
|
|
105
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
106
|
+
|
|
107
|
+
const shape = getTRPCErrorShape({
|
|
108
|
+
config: opts.router._def._config,
|
|
109
|
+
ctx,
|
|
110
|
+
error,
|
|
111
|
+
input,
|
|
112
|
+
path: op.path,
|
|
113
|
+
type: op.type,
|
|
114
|
+
});
|
|
115
|
+
return TRPCClientError.from({
|
|
116
|
+
error: transformChunk(shape),
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
run(async () => {
|
|
121
|
+
switch (op.type) {
|
|
122
|
+
case 'query':
|
|
123
|
+
case 'mutation': {
|
|
124
|
+
const result = await runProcedure(op.input);
|
|
125
|
+
if (!isAsyncIterable(result)) {
|
|
126
|
+
observer.next({
|
|
127
|
+
result: { data: transformChunk(result) },
|
|
128
|
+
});
|
|
129
|
+
observer.complete();
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
observer.next({
|
|
134
|
+
result: {
|
|
135
|
+
data: (async function* () {
|
|
136
|
+
await using iterator = iteratorResource(result);
|
|
137
|
+
using _finally = makeResource({}, () => {
|
|
138
|
+
observer.complete();
|
|
139
|
+
});
|
|
140
|
+
try {
|
|
141
|
+
while (true) {
|
|
142
|
+
const res = await Promise.race([
|
|
143
|
+
iterator.next(),
|
|
144
|
+
signalPromise,
|
|
145
|
+
]);
|
|
146
|
+
if (res.done) {
|
|
147
|
+
return transformChunk(res.value);
|
|
148
|
+
}
|
|
149
|
+
yield transformChunk(res.value);
|
|
150
|
+
}
|
|
151
|
+
} catch (cause) {
|
|
152
|
+
onErrorCallback(cause);
|
|
153
|
+
throw coerceToTRPCClientError(cause);
|
|
154
|
+
}
|
|
155
|
+
})(),
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
case 'subscription': {
|
|
161
|
+
const connectionState = behaviorSubject<
|
|
162
|
+
TRPCConnectionState<TRPCClientError<any>>
|
|
163
|
+
>({
|
|
164
|
+
type: 'state',
|
|
165
|
+
state: 'connecting',
|
|
166
|
+
error: null,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
const connectionSub = connectionState.subscribe({
|
|
170
|
+
next(state) {
|
|
171
|
+
observer.next({
|
|
172
|
+
result: state,
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
});
|
|
176
|
+
let lastEventId: string | undefined = undefined;
|
|
177
|
+
|
|
178
|
+
using _finally = makeResource({}, async () => {
|
|
179
|
+
observer.complete();
|
|
180
|
+
|
|
181
|
+
connectionState.next({
|
|
182
|
+
type: 'state',
|
|
183
|
+
state: 'idle',
|
|
184
|
+
error: null,
|
|
185
|
+
});
|
|
186
|
+
connectionSub.unsubscribe();
|
|
187
|
+
});
|
|
188
|
+
while (true) {
|
|
189
|
+
const result = await runProcedure(
|
|
190
|
+
inputWithTrackedEventId(op.input, lastEventId),
|
|
191
|
+
);
|
|
192
|
+
if (!isAsyncIterable(result)) {
|
|
193
|
+
throw new Error('Expected an async iterable');
|
|
194
|
+
}
|
|
195
|
+
await using iterator = iteratorResource(result);
|
|
196
|
+
|
|
197
|
+
observer.next({
|
|
198
|
+
result: {
|
|
199
|
+
type: 'started',
|
|
200
|
+
},
|
|
201
|
+
});
|
|
202
|
+
connectionState.next({
|
|
203
|
+
type: 'state',
|
|
204
|
+
state: 'pending',
|
|
205
|
+
error: null,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Use a while loop to handle errors and reconnects
|
|
209
|
+
while (true) {
|
|
210
|
+
let res;
|
|
211
|
+
try {
|
|
212
|
+
res = await Promise.race([iterator.next(), signalPromise]);
|
|
213
|
+
} catch (cause) {
|
|
214
|
+
if (isAbortError(cause)) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
const error = getTRPCErrorFromUnknown(cause);
|
|
218
|
+
|
|
219
|
+
if (
|
|
220
|
+
!retryableRpcCodes.includes(
|
|
221
|
+
TRPC_ERROR_CODES_BY_KEY[error.code],
|
|
222
|
+
)
|
|
223
|
+
) {
|
|
224
|
+
throw coerceToTRPCClientError(error);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
onErrorCallback(error);
|
|
228
|
+
connectionState.next({
|
|
229
|
+
type: 'state',
|
|
230
|
+
state: 'connecting',
|
|
231
|
+
error: coerceToTRPCClientError(error),
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (res.done) {
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
let chunk: TRPCResult<unknown>;
|
|
241
|
+
if (isTrackedEnvelope(res.value)) {
|
|
242
|
+
lastEventId = res.value[0];
|
|
243
|
+
|
|
244
|
+
chunk = {
|
|
245
|
+
id: res.value[0],
|
|
246
|
+
data: {
|
|
247
|
+
id: res.value[0],
|
|
248
|
+
data: res.value[1],
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
} else {
|
|
252
|
+
chunk = {
|
|
253
|
+
data: res.value,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
observer.next({
|
|
258
|
+
result: {
|
|
259
|
+
...chunk,
|
|
260
|
+
data: transformChunk(chunk.data),
|
|
261
|
+
},
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}).catch((cause) => {
|
|
269
|
+
onErrorCallback(cause);
|
|
270
|
+
observer.error(coerceToTRPCClientError(cause));
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return () => {
|
|
274
|
+
ac.abort();
|
|
275
|
+
};
|
|
276
|
+
});
|
|
277
|
+
}
|
|
@@ -165,6 +165,15 @@ export class RequestManager {
|
|
|
165
165
|
return this.getPendingRequests().length > 0;
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
+
/**
|
|
169
|
+
* Checks if there are any pending subscriptions
|
|
170
|
+
*/
|
|
171
|
+
public hasPendingSubscriptions() {
|
|
172
|
+
return this.getPendingRequests().some(
|
|
173
|
+
(request) => request.message.method === 'subscription',
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
|
|
168
177
|
/**
|
|
169
178
|
* Checks if there are any outgoing requests waiting to be sent.
|
|
170
179
|
*/
|
|
@@ -330,7 +330,7 @@ export class WsClient {
|
|
|
330
330
|
handleCloseOrError(event);
|
|
331
331
|
this.callbacks.onClose?.(event);
|
|
332
332
|
|
|
333
|
-
if (!this.lazyMode) {
|
|
333
|
+
if (!this.lazyMode || this.requestManager.hasPendingSubscriptions()) {
|
|
334
334
|
this.reconnect(
|
|
335
335
|
new TRPCWebSocketClosedError({
|
|
336
336
|
message: 'WebSocket closed',
|
package/src/links.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from './links/splitLink';
|
|
|
9
9
|
export * from './links/wsLink/wsLink';
|
|
10
10
|
export * from './links/httpSubscriptionLink';
|
|
11
11
|
export * from './links/retryLink';
|
|
12
|
+
export * from './links/localLink';
|
|
12
13
|
|
|
13
14
|
// These are not public (yet) as we get this functionality from tanstack query
|
|
14
15
|
// export * from './links/internals/dedupeLink';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"main":"../dist/unstable-internals.js","module":"../dist/unstable-internals.mjs","types":"../dist/unstable-internals.d.ts"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,SAAS,CAAC;AAExB,OAAO;AACL;;GAEG;AACH,gBAAgB,IAAI,qBAAqB;AACzC;;GAEG;AACH,KAAK,iBAAiB,IAAI,sBAAsB,GACjD,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export type BatchLoader<TKey, TValue> = {
|
|
2
|
-
validate: (keys: TKey[]) => boolean;
|
|
3
|
-
fetch: (keys: TKey[]) => Promise<TValue[] | Promise<TValue>[]>;
|
|
4
|
-
};
|
|
5
|
-
/**
|
|
6
|
-
* Dataloader that's very inspired by https://github.com/graphql/dataloader
|
|
7
|
-
* Less configuration, no caching, and allows you to cancel requests
|
|
8
|
-
* When cancelling a single fetch the whole batch will be cancelled only when _all_ items are cancelled
|
|
9
|
-
*/
|
|
10
|
-
export declare function dataLoader<TKey, TValue>(batchLoader: BatchLoader<TKey, TValue>): {
|
|
11
|
-
load: (key: TKey) => Promise<TValue>;
|
|
12
|
-
};
|
|
13
|
-
//# sourceMappingURL=dataLoader.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dataLoader.d.ts","sourceRoot":"","sources":["../../src/internals/dataLoader.ts"],"names":[],"mappings":"AAYA,MAAM,MAAM,WAAW,CAAC,IAAI,EAAE,MAAM,IAAI;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC;IACpC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;CAChE,CAAC;AAWF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EACrC,WAAW,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC;gBAsGnB,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC;EA6B1C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inputWithTrackedEventId.d.ts","sourceRoot":"","sources":["../../src/internals/inputWithTrackedEventId.ts"],"names":[],"mappings":"AAAA,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,OAAO,EACd,WAAW,EAAE,MAAM,GAAG,SAAS,WAYhC"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Maybe } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
-
/**
|
|
3
|
-
* Like `Promise.all()` but for abort signals
|
|
4
|
-
* - When all signals have been aborted, the merged signal will be aborted
|
|
5
|
-
* - If one signal is `null`, no signal will be aborted
|
|
6
|
-
*/
|
|
7
|
-
export declare function allAbortSignals(...signals: Maybe<AbortSignal>[]): AbortSignal;
|
|
8
|
-
/**
|
|
9
|
-
* Like `Promise.race` but for abort signals
|
|
10
|
-
*
|
|
11
|
-
* Basically, a ponyfill for
|
|
12
|
-
* [`AbortSignal.any`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal/any_static).
|
|
13
|
-
*/
|
|
14
|
-
export declare function raceAbortSignals(...signals: Maybe<AbortSignal>[]): AbortSignal;
|
|
15
|
-
//# sourceMappingURL=signals.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signals.d.ts","sourceRoot":"","sources":["../../src/internals/signals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,0CAA0C,CAAC;AAEtE;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,GAAG,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,GAAG,WAAW,CAwB7E;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,EAAE,GAC/B,WAAW,CAYb"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
-
import type { Operation, OperationLink, OperationResultObservable } from '../types';
|
|
3
|
-
/** @internal */
|
|
4
|
-
export declare function createChain<TRouter extends AnyRouter, TInput = unknown, TOutput = unknown>(opts: {
|
|
5
|
-
links: OperationLink<TRouter, TInput, TOutput>[];
|
|
6
|
-
op: Operation<TInput>;
|
|
7
|
-
}): OperationResultObservable<TRouter, TOutput>;
|
|
8
|
-
//# sourceMappingURL=createChain.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createChain.d.ts","sourceRoot":"","sources":["../../../src/links/internals/createChain.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EACb,yBAAyB,EAC1B,MAAM,UAAU,CAAC;AAElB,gBAAgB;AAChB,wBAAgB,WAAW,CACzB,OAAO,SAAS,SAAS,EACzB,MAAM,GAAG,OAAO,EAChB,OAAO,GAAG,OAAO,EACjB,IAAI,EAAE;IACN,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;IACjD,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;CACvB,GAAG,yBAAyB,CAAC,OAAO,EAAE,OAAO,CAAC,CAuB9C"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
-
import type { TRPCLink } from '../types';
|
|
3
|
-
/**
|
|
4
|
-
* @internal used for testing
|
|
5
|
-
*/
|
|
6
|
-
export declare function dedupeLink<TRouter extends AnyRouter = AnyRouter>(): TRPCLink<TRouter>;
|
|
7
|
-
//# sourceMappingURL=dedupeLink.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dedupeLink.d.ts","sourceRoot":"","sources":["../../../src/links/internals/dedupeLink.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEzC;;GAEG;AACH,wBAAgB,UAAU,CACxB,OAAO,SAAS,SAAS,GAAG,SAAS,KAClC,QAAQ,CAAC,OAAO,CAAC,CA2CrB"}
|
|
@@ -1,102 +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 outgoing requests waiting to be sent.
|
|
98
|
-
*/
|
|
99
|
-
hasOutgoingRequests(): boolean;
|
|
100
|
-
}
|
|
101
|
-
export {};
|
|
102
|
-
//# 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,mBAAmB;CAG3B"}
|
|
@@ -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,79 +0,0 @@
|
|
|
1
|
-
import type { UrlOptionsWithConnectionParams } from '../../internals/urlWithConnectionParams';
|
|
2
|
-
interface PingPongOptions {
|
|
3
|
-
/**
|
|
4
|
-
* The interval (in milliseconds) between "PING" messages.
|
|
5
|
-
*/
|
|
6
|
-
intervalMs: number;
|
|
7
|
-
/**
|
|
8
|
-
* The timeout (in milliseconds) to wait for a "PONG" response before closing the connection.
|
|
9
|
-
*/
|
|
10
|
-
pongTimeoutMs: number;
|
|
11
|
-
}
|
|
12
|
-
export interface WebSocketConnectionOptions {
|
|
13
|
-
WebSocketPonyfill?: typeof WebSocket;
|
|
14
|
-
urlOptions: UrlOptionsWithConnectionParams;
|
|
15
|
-
keepAlive: PingPongOptions & {
|
|
16
|
-
enabled: boolean;
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Manages a WebSocket connection with support for reconnection, keep-alive mechanisms,
|
|
21
|
-
* and observable state tracking.
|
|
22
|
-
*/
|
|
23
|
-
export declare class WsConnection {
|
|
24
|
-
static connectCount: number;
|
|
25
|
-
id: number;
|
|
26
|
-
private readonly WebSocketPonyfill;
|
|
27
|
-
private readonly urlOptions;
|
|
28
|
-
private readonly keepAliveOpts;
|
|
29
|
-
readonly wsObservable: import("@trpc/server/observable").BehaviorSubject<WebSocket | null>;
|
|
30
|
-
constructor(opts: WebSocketConnectionOptions);
|
|
31
|
-
get ws(): WebSocket | null;
|
|
32
|
-
private set ws(value);
|
|
33
|
-
/**
|
|
34
|
-
* Checks if the WebSocket connection is open and ready to communicate.
|
|
35
|
-
*/
|
|
36
|
-
isOpen(): this is {
|
|
37
|
-
ws: WebSocket;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Checks if the WebSocket connection is closed or in the process of closing.
|
|
41
|
-
*/
|
|
42
|
-
isClosed(): this is {
|
|
43
|
-
ws: WebSocket;
|
|
44
|
-
};
|
|
45
|
-
/**
|
|
46
|
-
* Manages the WebSocket opening process, ensuring that only one open operation
|
|
47
|
-
* occurs at a time. Tracks the ongoing operation with `openPromise` to avoid
|
|
48
|
-
* redundant calls and ensure proper synchronization.
|
|
49
|
-
*
|
|
50
|
-
* Sets up the keep-alive mechanism and necessary event listeners for the connection.
|
|
51
|
-
*
|
|
52
|
-
* @returns A promise that resolves once the WebSocket connection is successfully opened.
|
|
53
|
-
*/
|
|
54
|
-
private openPromise;
|
|
55
|
-
open(): Promise<void>;
|
|
56
|
-
/**
|
|
57
|
-
* Closes the WebSocket connection gracefully.
|
|
58
|
-
* Waits for any ongoing open operation to complete before closing.
|
|
59
|
-
*/
|
|
60
|
-
close(): Promise<void>;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Provides a backward-compatible representation of the connection state.
|
|
64
|
-
*/
|
|
65
|
-
export declare function backwardCompatibility(connection: WsConnection): {
|
|
66
|
-
readonly id: number;
|
|
67
|
-
readonly state: "open";
|
|
68
|
-
readonly ws: WebSocket;
|
|
69
|
-
} | {
|
|
70
|
-
readonly id: number;
|
|
71
|
-
readonly state: "closed";
|
|
72
|
-
readonly ws: WebSocket;
|
|
73
|
-
} | {
|
|
74
|
-
readonly id: number;
|
|
75
|
-
readonly state: "connecting";
|
|
76
|
-
readonly ws: WebSocket;
|
|
77
|
-
} | null;
|
|
78
|
-
export {};
|
|
79
|
-
//# sourceMappingURL=wsConnection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wsConnection.d.ts","sourceRoot":"","sources":["../../../../src/links/wsLink/wsClient/wsConnection.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,yCAAyC,CAAC;AAoB9F,UAAU,eAAe;IACvB;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAuDD,MAAM,WAAW,0BAA0B;IACzC,iBAAiB,CAAC,EAAE,OAAO,SAAS,CAAC;IACrC,UAAU,EAAE,8BAA8B,CAAC;IAC3C,SAAS,EAAE,eAAe,GAAG;QAC3B,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;CACH;AAED;;;GAGG;AACH,qBAAa,YAAY;IACvB,MAAM,CAAC,YAAY,SAAK;IACjB,EAAE,SAA+B;IAExC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAmB;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAiC;IAC5D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA0C;IACxE,SAAgB,YAAY,sEAA2C;gBAE3D,IAAI,EAAE,0BAA0B;IAY5C,IAAW,EAAE,qBAEZ;IAED,OAAO,KAAK,EAAE,QAEb;IAED;;OAEG;IACI,MAAM,IAAI,IAAI,IAAI;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE;IAQ1C;;OAEG;IACI,QAAQ,IAAI,IAAI,IAAI;QAAE,EAAE,EAAE,SAAS,CAAA;KAAE;IAQ5C;;;;;;;;OAQG;IACH,OAAO,CAAC,WAAW,CAA8B;IACpC,IAAI;IAyCjB;;;OAGG;IACU,KAAK;CAOnB;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,YAAY;;;;;;;;;;;;SA0B7D"}
|
package/dist/links.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
export * from './links/types';
|
|
2
|
-
export * from './links/HTTPBatchLinkOptions';
|
|
3
|
-
export * from './links/httpBatchLink';
|
|
4
|
-
export * from './links/httpBatchStreamLink';
|
|
5
|
-
export * from './links/httpLink';
|
|
6
|
-
export * from './links/loggerLink';
|
|
7
|
-
export * from './links/splitLink';
|
|
8
|
-
export * from './links/wsLink/wsLink';
|
|
9
|
-
export * from './links/httpSubscriptionLink';
|
|
10
|
-
export * from './links/retryLink';
|
|
11
|
-
//# sourceMappingURL=links.d.ts.map
|
package/dist/links.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAE9B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,uBAAuB,CAAC;AACtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,uBAAuB,CAAC;AACtC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unstable-internals.d.ts","sourceRoot":"","sources":["../src/unstable-internals.ts"],"names":[],"mappings":"AAAA,cAAc,yBAAyB,CAAC;AACxC,cAAc,iCAAiC,CAAC"}
|