@trpc/react-query 11.0.0-alpha-tmp-subscription-connection-state.488 → 11.0.0-alpha-tmp-12-06-react.665
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/bundle-analysis.json +59 -76
- package/dist/createTRPCReact.d.ts +47 -17
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/internals/context.d.ts +43 -21
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts +2 -2
- package/dist/internals/getQueryKey.js +3 -3
- package/dist/internals/getQueryKey.mjs +3 -3
- package/dist/internals/trpcResult.d.ts +18 -0
- package/dist/internals/trpcResult.d.ts.map +1 -0
- package/dist/internals/trpcResult.js +63 -0
- package/dist/internals/trpcResult.mjs +40 -0
- package/dist/internals/useQueries.d.ts +1 -1
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/rsc.d.ts +1 -1
- package/dist/rsc.d.ts.map +1 -1
- package/dist/rsc.js +4 -4
- package/dist/rsc.mjs +4 -4
- package/dist/server/ssgProxy.d.ts +7 -24
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +21 -4
- package/dist/server/ssgProxy.mjs +21 -4
- package/dist/shared/hooks/createHooksInternal.d.ts +4 -2
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createHooksInternal.js +160 -93
- package/dist/shared/hooks/createHooksInternal.mjs +156 -89
- package/dist/shared/hooks/types.d.ts +38 -159
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.js +0 -7
- package/dist/shared/index.mjs +0 -1
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.js +1 -1
- package/dist/shared/proxy/decorationProxy.mjs +1 -1
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +45 -20
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +4 -0
- package/dist/shared/proxy/utilsProxy.mjs +4 -0
- package/dist/shared/types.d.ts +60 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.d.ts +2 -2
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.js +69 -3
- package/dist/utils/createUtilityFunctions.mjs +69 -3
- package/dist/utils/inferReactQueryProcedure.d.ts +2 -2
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +22 -19
- package/src/createTRPCReact.tsx +276 -65
- package/src/internals/context.tsx +105 -24
- package/src/internals/getQueryKey.ts +2 -2
- package/src/internals/trpcResult.ts +55 -0
- package/src/internals/useQueries.ts +36 -31
- package/src/rsc.tsx +6 -6
- package/src/server/ssgProxy.ts +23 -66
- package/src/shared/hooks/createHooksInternal.tsx +222 -151
- package/src/shared/hooks/types.ts +64 -348
- package/src/shared/polymorphism/mutationLike.ts +8 -6
- package/src/shared/polymorphism/queryLike.ts +12 -14
- package/src/shared/polymorphism/routerLike.ts +4 -4
- package/src/shared/proxy/useQueriesProxy.ts +4 -4
- package/src/shared/proxy/utilsProxy.ts +153 -25
- package/src/shared/types.ts +229 -1
- package/src/utils/createUtilityFunctions.ts +90 -2
- package/src/utils/inferReactQueryProcedure.ts +8 -6
- package/dist/internals/useHookResult.d.ts +0 -8
- package/dist/internals/useHookResult.d.ts.map +0 -1
- package/dist/internals/useHookResult.js +0 -35
- package/dist/internals/useHookResult.mjs +0 -14
- package/dist/shared/hooks/types.js +0 -133
- package/dist/shared/hooks/types.mjs +0 -126
- package/src/internals/useHookResult.ts +0 -17
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DefinedUseQueryResult,
|
|
3
3
|
DehydratedState,
|
|
4
|
+
FetchInfiniteQueryOptions,
|
|
5
|
+
FetchQueryOptions,
|
|
4
6
|
InfiniteData,
|
|
5
7
|
InfiniteQueryObserverSuccessResult,
|
|
6
8
|
InitialDataFunction,
|
|
@@ -18,9 +20,7 @@ import type {
|
|
|
18
20
|
UseSuspenseQueryResult,
|
|
19
21
|
} from '@tanstack/react-query';
|
|
20
22
|
import type {
|
|
21
|
-
ConnectionState,
|
|
22
23
|
CreateTRPCClientOptions,
|
|
23
|
-
TRPCConnectionStateMessage,
|
|
24
24
|
TRPCRequestOptions,
|
|
25
25
|
TRPCUntypedClient,
|
|
26
26
|
} from '@trpc/client';
|
|
@@ -28,7 +28,7 @@ import type {
|
|
|
28
28
|
AnyRouter,
|
|
29
29
|
DistributiveOmit,
|
|
30
30
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
31
|
-
import type { ReactNode } from 'react';
|
|
31
|
+
import type { JSX, ReactNode } from 'react';
|
|
32
32
|
import type { TRPCContextProps } from '../../internals/context';
|
|
33
33
|
import type { TRPCQueryKey } from '../../internals/getQueryKey';
|
|
34
34
|
|
|
@@ -75,6 +75,13 @@ export interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError>
|
|
|
75
75
|
>,
|
|
76
76
|
TRPCUseQueryBaseOptions {}
|
|
77
77
|
|
|
78
|
+
export interface UseTRPCPrefetchQueryOptions<TOutput, TData, TError>
|
|
79
|
+
extends DistributiveOmit<
|
|
80
|
+
FetchQueryOptions<TOutput, TError, TData, any>,
|
|
81
|
+
'queryKey'
|
|
82
|
+
>,
|
|
83
|
+
TRPCUseQueryBaseOptions {}
|
|
84
|
+
|
|
78
85
|
/** @internal **/
|
|
79
86
|
export interface DefinedUseTRPCQueryOptions<
|
|
80
87
|
TOutput,
|
|
@@ -114,6 +121,21 @@ export interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError>
|
|
|
114
121
|
initialCursor?: ExtractCursorType<TInput>;
|
|
115
122
|
}
|
|
116
123
|
|
|
124
|
+
export type UseTRPCPrefetchInfiniteQueryOptions<TInput, TOutput, TError> =
|
|
125
|
+
DistributiveOmit<
|
|
126
|
+
FetchInfiniteQueryOptions<
|
|
127
|
+
TOutput,
|
|
128
|
+
TError,
|
|
129
|
+
TOutput,
|
|
130
|
+
any,
|
|
131
|
+
ExtractCursorType<TInput>
|
|
132
|
+
>,
|
|
133
|
+
'queryKey' | 'initialPageParam'
|
|
134
|
+
> &
|
|
135
|
+
TRPCUseQueryBaseOptions & {
|
|
136
|
+
initialCursor?: ExtractCursorType<TInput>;
|
|
137
|
+
};
|
|
138
|
+
|
|
117
139
|
export interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError>
|
|
118
140
|
extends DistributiveOmit<
|
|
119
141
|
UseSuspenseInfiniteQueryOptions<
|
|
@@ -139,372 +161,69 @@ export interface UseTRPCMutationOptions<
|
|
|
139
161
|
TRPCUseQueryBaseOptions {}
|
|
140
162
|
|
|
141
163
|
export interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
|
164
|
+
/**
|
|
165
|
+
* @deprecated
|
|
166
|
+
* use a `skipToken` from `@tanstack/react-query` instead
|
|
167
|
+
* this will be removed in v12
|
|
168
|
+
*/
|
|
142
169
|
enabled?: boolean;
|
|
143
|
-
onStarted?: () => void;
|
|
144
170
|
/**
|
|
145
|
-
*
|
|
171
|
+
* Called when the subscription is started
|
|
146
172
|
*/
|
|
147
|
-
|
|
148
|
-
onData: (data: TOutput) => void;
|
|
149
|
-
onStateChange?: (state: TRPCConnectionStateMessage<TError>) => void;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface restartSubscriptionOptionsBase {
|
|
173
|
+
onStarted?: () => void;
|
|
153
174
|
/**
|
|
154
|
-
*
|
|
155
|
-
* - Defaults to `true`
|
|
156
|
-
* - Set to `false` no new subscription will be established if there is already an active subscription
|
|
175
|
+
* Called when new data is received
|
|
157
176
|
*/
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
export interface restartSubscriptionOptionsWithLastEventId
|
|
162
|
-
extends restartSubscriptionOptionsBase {
|
|
177
|
+
onData?: (data: TOutput) => void;
|
|
163
178
|
/**
|
|
164
|
-
*
|
|
165
|
-
* - When the susbscription has successfully completed, it will be set to `false`
|
|
179
|
+
* Called when an **unrecoverable error** occurs and the subscription is closed
|
|
166
180
|
*/
|
|
167
|
-
|
|
181
|
+
onError?: (err: TError) => void;
|
|
168
182
|
}
|
|
169
183
|
|
|
170
|
-
export
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
: restartSubscriptionOptionsBase;
|
|
175
|
-
|
|
176
|
-
export type restartSubscriptionFn<TInput> = (
|
|
177
|
-
options?: restartSubscriptionOptions<TInput>,
|
|
178
|
-
) => void;
|
|
179
|
-
|
|
180
|
-
export interface TRPCSubscriptionBaseResult<_TInput, TOutput, TError> {
|
|
181
|
-
/**
|
|
182
|
-
* The last data received from the subscription
|
|
183
|
-
*/
|
|
184
|
-
data: TOutput | null;
|
|
184
|
+
export interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
185
|
+
status: 'idle' | 'connecting' | 'pending' | 'error';
|
|
186
|
+
data: undefined | TOutput;
|
|
187
|
+
error: null | TError;
|
|
185
188
|
/**
|
|
186
|
-
*
|
|
189
|
+
* Reset the subscription
|
|
187
190
|
*/
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* The timestamp for when the connection was initially established
|
|
191
|
-
*/
|
|
192
|
-
initialConnectionStartedAt: number;
|
|
193
|
-
/**
|
|
194
|
-
* The error that caused the subscription to stop
|
|
195
|
-
* - Defaults to `null`
|
|
196
|
-
* - Resets to `null` after the subscription is restarted and the connection is re-established
|
|
197
|
-
*/
|
|
198
|
-
error: TError | null;
|
|
199
|
-
/**
|
|
200
|
-
* The timestamp for when the last error was captured
|
|
201
|
-
*/
|
|
202
|
-
errorUpdatedAt: number;
|
|
203
|
-
/**
|
|
204
|
-
* The reason for the reconnection
|
|
205
|
-
* - Resets to `null` after the subscription is restarted and the connection is re-established
|
|
206
|
-
*/
|
|
207
|
-
connectionError: TError | null;
|
|
208
|
-
/**
|
|
209
|
-
* Reconnection attempts since last successful connection
|
|
210
|
-
*/
|
|
211
|
-
connectionAttemptCount: number;
|
|
212
|
-
/**
|
|
213
|
-
* The timestamp for when the last reconnection error was captured
|
|
214
|
-
*/
|
|
215
|
-
connectionErrorUpdatedAt: number;
|
|
216
|
-
/**
|
|
217
|
-
* Is `true` when the subscription is establishing the initial connection
|
|
218
|
-
*/
|
|
219
|
-
isStarting: boolean;
|
|
220
|
-
/**
|
|
221
|
-
* Is `true` when the subscription has successfully connected at least once
|
|
222
|
-
*/
|
|
223
|
-
isStarted: boolean;
|
|
224
|
-
/**
|
|
225
|
-
* Is `true` if the subscription is (re-)establishing a connection
|
|
226
|
-
* - Alias for `status === 'connecting'`
|
|
227
|
-
*/
|
|
228
|
-
isConnecting: boolean;
|
|
229
|
-
/**
|
|
230
|
-
* Is `true` when the subscription is connected and listening for data
|
|
231
|
-
* - Alias for `status === 'pending'`
|
|
232
|
-
*/
|
|
233
|
-
isPending: boolean;
|
|
234
|
-
/**
|
|
235
|
-
* Is `true` if the subscription is re-establishing a connection
|
|
236
|
-
* - Alias for `status === 'connecting' && isStarted === true`
|
|
237
|
-
*/
|
|
238
|
-
isReconnecting: boolean;
|
|
239
|
-
/**
|
|
240
|
-
* Is `true` if the subscription ended in an error state
|
|
241
|
-
* - Alias for `status === 'error'`
|
|
242
|
-
*/
|
|
243
|
-
isError: boolean;
|
|
244
|
-
/**
|
|
245
|
-
* The current state of the subscription
|
|
246
|
-
* - Will be:
|
|
247
|
-
* - `'idle'` when the subscription is not enabled
|
|
248
|
-
* - `'connecting'` when the subscription is (re-)establishing the connection
|
|
249
|
-
* - `'pending'` when the subscription is connected and receiving data
|
|
250
|
-
* - `'error'` when the subscription has stopped due to an error
|
|
251
|
-
*/
|
|
252
|
-
status: ConnectionState;
|
|
253
|
-
/**
|
|
254
|
-
* Restart the subscription
|
|
255
|
-
*/
|
|
256
|
-
// restart: restartSubscriptionFn<TInput>;
|
|
191
|
+
reset: () => void;
|
|
257
192
|
}
|
|
258
193
|
|
|
259
|
-
export interface TRPCSubscriptionIdleResult<
|
|
260
|
-
extends TRPCSubscriptionBaseResult<
|
|
261
|
-
data: null;
|
|
262
|
-
error: null;
|
|
263
|
-
errorUpdatedAt: 0;
|
|
264
|
-
connectionError: null;
|
|
265
|
-
isStarting: false;
|
|
266
|
-
isStarted: false;
|
|
267
|
-
isConnecting: false;
|
|
268
|
-
isPending: false;
|
|
269
|
-
isReconnecting: false;
|
|
270
|
-
isError: false;
|
|
271
|
-
connectionAttemptCount: 0;
|
|
272
|
-
connectionErrorUpdatedAt: 0;
|
|
273
|
-
connectionStartedAt: 0;
|
|
274
|
-
initialConnectionStartedAt: 0;
|
|
194
|
+
export interface TRPCSubscriptionIdleResult<TOutput>
|
|
195
|
+
extends TRPCSubscriptionBaseResult<TOutput, null> {
|
|
275
196
|
status: 'idle';
|
|
197
|
+
data: undefined;
|
|
198
|
+
error: null;
|
|
276
199
|
}
|
|
277
200
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
'restart'
|
|
281
|
-
> = {
|
|
282
|
-
data: null,
|
|
283
|
-
connectionStartedAt: 0,
|
|
284
|
-
initialConnectionStartedAt: 0,
|
|
285
|
-
error: null,
|
|
286
|
-
errorUpdatedAt: 0,
|
|
287
|
-
connectionError: null,
|
|
288
|
-
connectionAttemptCount: 0,
|
|
289
|
-
isStarting: false,
|
|
290
|
-
isStarted: false,
|
|
291
|
-
isConnecting: false,
|
|
292
|
-
isPending: false,
|
|
293
|
-
isReconnecting: false,
|
|
294
|
-
isError: false,
|
|
295
|
-
connectionErrorUpdatedAt: 0,
|
|
296
|
-
status: 'idle',
|
|
297
|
-
};
|
|
298
|
-
|
|
299
|
-
export const getIdleResult = <
|
|
300
|
-
TInput,
|
|
301
|
-
TOutput,
|
|
302
|
-
TError,
|
|
303
|
-
>(): // restart: restartSubscriptionFn<TInput>,
|
|
304
|
-
TRPCSubscriptionIdleResult<TInput, TOutput, TError> => {
|
|
305
|
-
return {
|
|
306
|
-
...defaultIdleResult,
|
|
307
|
-
data: null,
|
|
308
|
-
// restart,
|
|
309
|
-
};
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
export interface TRPCSubscriptionStartingResult<TInput, TOutput, TError>
|
|
313
|
-
extends TRPCSubscriptionBaseResult<TInput, TOutput, TError> {
|
|
314
|
-
connectionStartedAt: 0;
|
|
315
|
-
initialConnectionStartedAt: 0;
|
|
316
|
-
error: null;
|
|
317
|
-
data: null;
|
|
318
|
-
connectionError: TError | null;
|
|
319
|
-
isStarting: true;
|
|
320
|
-
isStarted: false;
|
|
321
|
-
isConnecting: true;
|
|
322
|
-
isPending: false;
|
|
323
|
-
isReconnecting: false;
|
|
324
|
-
isError: false;
|
|
201
|
+
export interface TRPCSubscriptionConnectingResult<TOutput, TError>
|
|
202
|
+
extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
325
203
|
status: 'connecting';
|
|
204
|
+
data: undefined | TOutput;
|
|
205
|
+
error: TError | null;
|
|
326
206
|
}
|
|
327
207
|
|
|
328
|
-
export
|
|
329
|
-
|
|
330
|
-
previous?:
|
|
331
|
-
| TRPCSubscriptionIdleResult<TInput, TOutput, TError>
|
|
332
|
-
| TRPCSubscriptionErrorResult<TInput, TOutput, TError>
|
|
333
|
-
| TRPCSubscriptionStartingResult<TInput, TOutput, TError>,
|
|
334
|
-
error?: TError | null,
|
|
335
|
-
): TRPCSubscriptionStartingResult<TInput, TOutput, TError> => {
|
|
336
|
-
const now = Date.now();
|
|
337
|
-
|
|
338
|
-
if (previous) {
|
|
339
|
-
return {
|
|
340
|
-
...defaultIdleResult,
|
|
341
|
-
...previous,
|
|
342
|
-
data: null,
|
|
343
|
-
connectionError: error ?? null,
|
|
344
|
-
isStarting: true,
|
|
345
|
-
isConnecting: true,
|
|
346
|
-
errorUpdatedAt: 0,
|
|
347
|
-
connectionAttemptCount: previous.connectionAttemptCount + 1,
|
|
348
|
-
connectionErrorUpdatedAt: error ? now : 0,
|
|
349
|
-
connectionStartedAt: 0,
|
|
350
|
-
initialConnectionStartedAt: 0,
|
|
351
|
-
error: null,
|
|
352
|
-
isStarted: false,
|
|
353
|
-
isError: false,
|
|
354
|
-
status: 'connecting',
|
|
355
|
-
};
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
return {
|
|
359
|
-
...getIdleResult(/*restart*/),
|
|
360
|
-
connectionError: error ?? null,
|
|
361
|
-
isStarting: true,
|
|
362
|
-
isConnecting: true,
|
|
363
|
-
errorUpdatedAt: 0,
|
|
364
|
-
connectionAttemptCount: 0,
|
|
365
|
-
connectionErrorUpdatedAt: error ? now : 0,
|
|
366
|
-
status: 'connecting',
|
|
367
|
-
};
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
export interface TRPCSubscriptionPendingResult<TInput, TOutput, TError>
|
|
371
|
-
extends TRPCSubscriptionBaseResult<TInput, TOutput, TError> {
|
|
372
|
-
error: null;
|
|
373
|
-
connectionError: null;
|
|
374
|
-
connectionAttemptCount: 0;
|
|
375
|
-
isStarting: false;
|
|
376
|
-
isStarted: true;
|
|
377
|
-
isConnecting: false;
|
|
378
|
-
isPending: true;
|
|
379
|
-
isReconnecting: false;
|
|
380
|
-
isError: false;
|
|
208
|
+
export interface TRPCSubscriptionPendingResult<TOutput>
|
|
209
|
+
extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
|
381
210
|
status: 'pending';
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
export const getPendingResult = <TInput, TOutput, TError>(
|
|
385
|
-
previous: UseTRPCSubscriptionResult<TInput, TOutput, TError>,
|
|
386
|
-
data?: TOutput,
|
|
387
|
-
): TRPCSubscriptionPendingResult<TInput, TOutput, TError> => {
|
|
388
|
-
const time = Date.now();
|
|
389
|
-
|
|
390
|
-
if (previous.isStarting) {
|
|
391
|
-
return {
|
|
392
|
-
...previous,
|
|
393
|
-
error: null,
|
|
394
|
-
isStarting: false,
|
|
395
|
-
isStarted: true,
|
|
396
|
-
isConnecting: false,
|
|
397
|
-
isReconnecting: false,
|
|
398
|
-
isPending: true,
|
|
399
|
-
status: 'pending',
|
|
400
|
-
connectionStartedAt: time,
|
|
401
|
-
connectionAttemptCount: 0,
|
|
402
|
-
connectionError: null,
|
|
403
|
-
initialConnectionStartedAt: time,
|
|
404
|
-
};
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
return {
|
|
408
|
-
...previous,
|
|
409
|
-
data: data ?? previous.data,
|
|
410
|
-
error: null,
|
|
411
|
-
isError: false,
|
|
412
|
-
isStarting: false,
|
|
413
|
-
isStarted: true,
|
|
414
|
-
isConnecting: false,
|
|
415
|
-
isReconnecting: false,
|
|
416
|
-
isPending: true,
|
|
417
|
-
status: 'pending',
|
|
418
|
-
connectionStartedAt: time,
|
|
419
|
-
connectionAttemptCount: 0,
|
|
420
|
-
connectionError: null,
|
|
421
|
-
};
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
export interface TRPCSubscriptionReconnectingResult<TInput, TOutput, TError>
|
|
425
|
-
extends TRPCSubscriptionBaseResult<TInput, TOutput, TError> {
|
|
211
|
+
data: TOutput;
|
|
426
212
|
error: null;
|
|
427
|
-
connectionError: TError;
|
|
428
|
-
isStarting: false;
|
|
429
|
-
isStarted: true;
|
|
430
|
-
isConnecting: true;
|
|
431
|
-
isPending: false;
|
|
432
|
-
isReconnecting: true;
|
|
433
|
-
isError: false;
|
|
434
|
-
status: 'connecting';
|
|
435
213
|
}
|
|
436
214
|
|
|
437
|
-
export
|
|
438
|
-
|
|
439
|
-
| TRPCSubscriptionPendingResult<TInput, TOutput, TError>
|
|
440
|
-
| TRPCSubscriptionReconnectingResult<TInput, TOutput, TError>,
|
|
441
|
-
error: TError,
|
|
442
|
-
): TRPCSubscriptionReconnectingResult<TInput, TOutput, TError> => {
|
|
443
|
-
return {
|
|
444
|
-
...previous,
|
|
445
|
-
isStarting: false,
|
|
446
|
-
isStarted: true,
|
|
447
|
-
isConnecting: true,
|
|
448
|
-
isReconnecting: true,
|
|
449
|
-
isPending: false,
|
|
450
|
-
status: 'connecting',
|
|
451
|
-
connectionError: error,
|
|
452
|
-
connectionAttemptCount: previous.connectionAttemptCount + 1,
|
|
453
|
-
};
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
export const getConnectingResult = <TInput, TOutput, TError>(
|
|
457
|
-
previous: UseTRPCSubscriptionResult<TInput, TOutput, TError>,
|
|
458
|
-
error: TError | null,
|
|
459
|
-
): TRPCSubscriptionConnectingResult<TInput, TOutput, TError> => {
|
|
460
|
-
if (previous.isReconnecting || previous.isPending) {
|
|
461
|
-
if (!error) throw new Error('Reconnecting without error?');
|
|
462
|
-
|
|
463
|
-
return getReconnectingResult(previous, error);
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
return getStartingResult(/*previous.restart, */ previous, error);
|
|
467
|
-
};
|
|
468
|
-
|
|
469
|
-
export interface TRPCSubscriptionErrorResult<TInput, TOutput, TError>
|
|
470
|
-
extends TRPCSubscriptionBaseResult<TInput, TOutput, TError> {
|
|
471
|
-
error: TError;
|
|
472
|
-
isStarting: false;
|
|
473
|
-
isStarted: true; // Not sure about this one
|
|
474
|
-
isConnecting: false;
|
|
475
|
-
isPending: false;
|
|
476
|
-
isReconnecting: false;
|
|
477
|
-
isError: true;
|
|
215
|
+
export interface TRPCSubscriptionErrorResult<TOutput, TError>
|
|
216
|
+
extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
478
217
|
status: 'error';
|
|
218
|
+
data: TOutput | undefined;
|
|
219
|
+
error: TError;
|
|
479
220
|
}
|
|
480
221
|
|
|
481
|
-
export
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
...previous,
|
|
487
|
-
isStarting: false,
|
|
488
|
-
isStarted: true,
|
|
489
|
-
isConnecting: false,
|
|
490
|
-
isReconnecting: false,
|
|
491
|
-
isPending: false,
|
|
492
|
-
isError: true,
|
|
493
|
-
status: 'error',
|
|
494
|
-
error,
|
|
495
|
-
errorUpdatedAt: Date.now(),
|
|
496
|
-
};
|
|
497
|
-
};
|
|
498
|
-
|
|
499
|
-
export type TRPCSubscriptionConnectingResult<TInput, TOutput, TError> =
|
|
500
|
-
| TRPCSubscriptionStartingResult<TInput, TOutput, TError>
|
|
501
|
-
| TRPCSubscriptionReconnectingResult<TInput, TOutput, TError>;
|
|
502
|
-
|
|
503
|
-
export type UseTRPCSubscriptionResult<TInput, TOutput, TError> =
|
|
504
|
-
| TRPCSubscriptionIdleResult<TInput, TOutput, TError>
|
|
505
|
-
| TRPCSubscriptionPendingResult<TInput, TOutput, TError>
|
|
506
|
-
| TRPCSubscriptionConnectingResult<TInput, TOutput, TError>
|
|
507
|
-
| TRPCSubscriptionErrorResult<TInput, TOutput, TError>;
|
|
222
|
+
export type TRPCSubscriptionResult<TOutput, TError> =
|
|
223
|
+
| TRPCSubscriptionIdleResult<TOutput>
|
|
224
|
+
| TRPCSubscriptionConnectingResult<TOutput, TError>
|
|
225
|
+
| TRPCSubscriptionErrorResult<TOutput, TError>
|
|
226
|
+
| TRPCSubscriptionPendingResult<TOutput>;
|
|
508
227
|
|
|
509
228
|
export interface TRPCProviderProps<TRouter extends AnyRouter, TSSRContext>
|
|
510
229
|
extends TRPCContextProps<TRouter, TSSRContext> {
|
|
@@ -524,11 +243,8 @@ export type CreateClient<TRouter extends AnyRouter> = (
|
|
|
524
243
|
opts: CreateTRPCClientOptions<TRouter>,
|
|
525
244
|
) => TRPCUntypedClient<TRouter>;
|
|
526
245
|
|
|
527
|
-
type coerceAsyncIterableToArray<TValue> =
|
|
528
|
-
infer $Inferred
|
|
529
|
-
>
|
|
530
|
-
? $Inferred[]
|
|
531
|
-
: TValue;
|
|
246
|
+
export type coerceAsyncIterableToArray<TValue> =
|
|
247
|
+
TValue extends AsyncIterable<infer $Inferred> ? $Inferred[] : TValue;
|
|
532
248
|
|
|
533
249
|
/**
|
|
534
250
|
* @internal
|
|
@@ -26,15 +26,17 @@ export type MutationLike<
|
|
|
26
26
|
*/
|
|
27
27
|
export type InferMutationLikeInput<
|
|
28
28
|
TMutationLike extends MutationLike<any, any>,
|
|
29
|
-
> =
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
> =
|
|
30
|
+
TMutationLike extends MutationLike<any, infer $Procedure>
|
|
31
|
+
? inferProcedureInput<$Procedure>
|
|
32
|
+
: never;
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* Use to unwrap a MutationLike's data output
|
|
35
36
|
*/
|
|
36
37
|
export type InferMutationLikeData<
|
|
37
38
|
TMutationLike extends MutationLike<any, any>,
|
|
38
|
-
> =
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
> =
|
|
40
|
+
TMutationLike extends MutationLike<infer TRoot, infer TProcedure>
|
|
41
|
+
? inferTransformedProcedureOutput<TRoot, TProcedure>
|
|
42
|
+
: never;
|
|
@@ -37,21 +37,19 @@ export type QueryLike<
|
|
|
37
37
|
/**
|
|
38
38
|
* Use to unwrap a QueryLike's input
|
|
39
39
|
*/
|
|
40
|
-
export type InferQueryLikeInput<TQueryLike> =
|
|
41
|
-
infer $Def
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
: never;
|
|
40
|
+
export type InferQueryLikeInput<TQueryLike> =
|
|
41
|
+
TQueryLike extends DecoratedQuery<infer $Def>
|
|
42
|
+
? $Def['input']
|
|
43
|
+
: TQueryLike extends QueryLike<any, infer TProcedure>
|
|
44
|
+
? inferProcedureInput<TProcedure>
|
|
45
|
+
: never;
|
|
47
46
|
|
|
48
47
|
/**
|
|
49
48
|
* Use to unwrap a QueryLike's data output
|
|
50
49
|
*/
|
|
51
|
-
export type InferQueryLikeData<TQueryLike> =
|
|
52
|
-
infer $Def
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
: never;
|
|
50
|
+
export type InferQueryLikeData<TQueryLike> =
|
|
51
|
+
TQueryLike extends DecoratedQuery<infer $Def>
|
|
52
|
+
? $Def['output']
|
|
53
|
+
: TQueryLike extends QueryLike<infer TRoot, infer TProcedure>
|
|
54
|
+
? inferTransformedProcedureOutput<TRoot, TProcedure>
|
|
55
|
+
: never;
|
|
@@ -23,10 +23,10 @@ export type RouterLikeInner<
|
|
|
23
23
|
? $Value extends RouterRecord
|
|
24
24
|
? RouterLikeInner<TRoot, $Value>
|
|
25
25
|
: $Value extends AnyQueryProcedure
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
? QueryLike<TRoot, $Value>
|
|
27
|
+
: $Value extends AnyMutationProcedure
|
|
28
|
+
? MutationLike<TRoot, $Value>
|
|
29
|
+
: never
|
|
30
30
|
: never;
|
|
31
31
|
};
|
|
32
32
|
|
|
@@ -44,8 +44,8 @@ export type UseQueriesProcedureRecord<
|
|
|
44
44
|
? $Value extends RouterRecord
|
|
45
45
|
? UseQueriesProcedureRecord<TRoot, $Value>
|
|
46
46
|
: $Value extends AnyQueryProcedure
|
|
47
|
-
|
|
48
|
-
|
|
47
|
+
? GetQueryOptions<TRoot, $Value>
|
|
48
|
+
: never
|
|
49
49
|
: never;
|
|
50
50
|
};
|
|
51
51
|
|
|
@@ -76,8 +76,8 @@ export type UseSuspenseQueriesProcedureRecord<
|
|
|
76
76
|
? $Value extends RouterRecord
|
|
77
77
|
? UseSuspenseQueriesProcedureRecord<TRoot, $Value>
|
|
78
78
|
: $Value extends AnyQueryProcedure
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
? GetSuspenseQueryOptions<TRoot, $Value>
|
|
80
|
+
: never
|
|
81
81
|
: never;
|
|
82
82
|
};
|
|
83
83
|
|