@trpc/react-query 11.0.0-rc.577 → 11.0.0-rc.584
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 +50 -47
- package/dist/internals/context.d.ts +16 -2
- package/dist/internals/context.d.ts.map +1 -1
- 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/rsc.d.ts +1 -1
- package/dist/rsc.js +1 -1
- package/dist/rsc.mjs +1 -1
- package/dist/server/ssgProxy.d.ts +6 -23
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +16 -0
- package/dist/server/ssgProxy.mjs +16 -0
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createHooksInternal.js +7 -24
- package/dist/shared/hooks/createHooksInternal.mjs +2 -19
- package/dist/shared/hooks/types.d.ts +1 -1
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +23 -2
- 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 +55 -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 +66 -0
- package/dist/utils/createUtilityFunctions.mjs +66 -0
- package/package.json +7 -7
- package/src/internals/context.tsx +76 -1
- package/src/internals/trpcResult.ts +55 -0
- package/src/rsc.tsx +1 -1
- package/src/server/ssgProxy.ts +19 -63
- package/src/shared/hooks/createHooksInternal.tsx +8 -20
- package/src/shared/hooks/types.ts +1 -1
- package/src/shared/proxy/utilsProxy.ts +110 -2
- package/src/shared/types.ts +202 -1
- package/src/utils/createUtilityFunctions.ts +90 -2
- 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/src/internals/useHookResult.ts +0 -17
package/src/rsc.tsx
CHANGED
|
@@ -73,7 +73,7 @@ type Caller<TRouter extends AnyRouter> = ReturnType<
|
|
|
73
73
|
// ts-prune-ignore-next
|
|
74
74
|
/**
|
|
75
75
|
* @note This requires `@tanstack/react-query@^5.49.0`
|
|
76
|
-
* @note Make sure to have `
|
|
76
|
+
* @note Make sure to have `dehydrate.serializeData` and `hydrate.deserializeData`
|
|
77
77
|
* set to your data transformer in your `QueryClient` factory.
|
|
78
78
|
* @example
|
|
79
79
|
* ```ts
|
package/src/server/ssgProxy.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
DehydratedState,
|
|
3
3
|
DehydrateOptions,
|
|
4
|
-
InfiniteData,
|
|
5
4
|
QueryClient,
|
|
6
5
|
} from '@tanstack/react-query';
|
|
7
6
|
import { dehydrate } from '@tanstack/react-query';
|
|
8
|
-
import type { inferRouterClient
|
|
7
|
+
import type { inferRouterClient } from '@trpc/client';
|
|
9
8
|
import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
|
|
10
9
|
import type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';
|
|
11
10
|
import {
|
|
@@ -13,14 +12,11 @@ import {
|
|
|
13
12
|
type TransformerOptions,
|
|
14
13
|
} from '@trpc/client/unstable-internals';
|
|
15
14
|
import type {
|
|
16
|
-
AnyProcedure,
|
|
17
15
|
AnyQueryProcedure,
|
|
18
16
|
AnyRootTypes,
|
|
19
17
|
AnyRouter,
|
|
20
18
|
inferClientTypes,
|
|
21
|
-
inferProcedureInput,
|
|
22
19
|
inferRouterContext,
|
|
23
|
-
inferTransformedProcedureOutput,
|
|
24
20
|
Maybe,
|
|
25
21
|
ProtectedIntersection,
|
|
26
22
|
RouterRecord,
|
|
@@ -33,7 +29,7 @@ import {
|
|
|
33
29
|
import { getQueryKeyInternal } from '../internals/getQueryKey';
|
|
34
30
|
import type {
|
|
35
31
|
CreateTRPCReactQueryClientConfig,
|
|
36
|
-
|
|
32
|
+
DecorateQueryProcedure,
|
|
37
33
|
TRPCFetchInfiniteQueryOptions,
|
|
38
34
|
TRPCFetchQueryOptions,
|
|
39
35
|
} from '../shared';
|
|
@@ -52,61 +48,13 @@ type CreateServerSideHelpersOptions<TRouter extends AnyRouter> =
|
|
|
52
48
|
CreateTRPCReactQueryClientConfig &
|
|
53
49
|
(CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>);
|
|
54
50
|
|
|
55
|
-
type
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
fetch(
|
|
63
|
-
input: inferProcedureInput<TProcedure>,
|
|
64
|
-
opts?: TRPCFetchQueryOptions<
|
|
65
|
-
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
66
|
-
TRPCClientError<TRoot>
|
|
67
|
-
>,
|
|
68
|
-
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @see https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
72
|
-
*/
|
|
73
|
-
fetchInfinite(
|
|
74
|
-
input: inferProcedureInput<TProcedure>,
|
|
75
|
-
opts?: TRPCFetchInfiniteQueryOptions<
|
|
76
|
-
inferProcedureInput<TProcedure>,
|
|
77
|
-
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
78
|
-
TRPCClientError<TRoot>
|
|
79
|
-
>,
|
|
80
|
-
): Promise<
|
|
81
|
-
InfiniteData<
|
|
82
|
-
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
83
|
-
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
84
|
-
>
|
|
85
|
-
>;
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* @see https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
89
|
-
*/
|
|
90
|
-
prefetch(
|
|
91
|
-
input: inferProcedureInput<TProcedure>,
|
|
92
|
-
opts?: TRPCFetchQueryOptions<
|
|
93
|
-
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
94
|
-
TRPCClientError<TRoot>
|
|
95
|
-
>,
|
|
96
|
-
): Promise<void>;
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* @see https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
100
|
-
*/
|
|
101
|
-
prefetchInfinite(
|
|
102
|
-
input: inferProcedureInput<TProcedure>,
|
|
103
|
-
opts?: TRPCFetchInfiniteQueryOptions<
|
|
104
|
-
inferProcedureInput<TProcedure>,
|
|
105
|
-
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
106
|
-
TRPCClientError<TRoot>
|
|
107
|
-
>,
|
|
108
|
-
): Promise<void>;
|
|
109
|
-
};
|
|
51
|
+
type SSGFns =
|
|
52
|
+
| 'queryOptions'
|
|
53
|
+
| 'infiniteQueryOptions'
|
|
54
|
+
| 'fetch'
|
|
55
|
+
| 'fetchInfinite'
|
|
56
|
+
| 'prefetch'
|
|
57
|
+
| 'prefetchInfinite';
|
|
110
58
|
|
|
111
59
|
/**
|
|
112
60
|
* @internal
|
|
@@ -120,12 +68,12 @@ type DecoratedProcedureSSGRecord<
|
|
|
120
68
|
? DecoratedProcedureSSGRecord<TRoot, $Value>
|
|
121
69
|
: // utils only apply to queries
|
|
122
70
|
$Value extends AnyQueryProcedure
|
|
123
|
-
?
|
|
71
|
+
? Pick<DecorateQueryProcedure<TRoot, $Value>, SSGFns>
|
|
124
72
|
: never
|
|
125
73
|
: never;
|
|
126
74
|
};
|
|
127
75
|
|
|
128
|
-
type AnyDecoratedProcedure =
|
|
76
|
+
type AnyDecoratedProcedure = Pick<DecorateQueryProcedure<any, any>, SSGFns>;
|
|
129
77
|
|
|
130
78
|
/**
|
|
131
79
|
* Create functions you can use for server-side rendering / static generation
|
|
@@ -210,6 +158,14 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
|
210
158
|
);
|
|
211
159
|
|
|
212
160
|
const helperMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
|
161
|
+
queryOptions: () => {
|
|
162
|
+
const args1 = args[1] as Maybe<any>;
|
|
163
|
+
return { ...args1, queryKey, queryFn };
|
|
164
|
+
},
|
|
165
|
+
infiniteQueryOptions: () => {
|
|
166
|
+
const args1 = args[1] as Maybe<any>;
|
|
167
|
+
return { ...args1, queryKey, queryFn };
|
|
168
|
+
},
|
|
213
169
|
fetch: () => {
|
|
214
170
|
const args1 = args[1] as Maybe<TRPCFetchQueryOptions<any, any>>;
|
|
215
171
|
return queryClient.fetchQuery({ ...args1, queryKey, queryFn });
|
|
@@ -24,7 +24,10 @@ import {
|
|
|
24
24
|
getMutationKeyInternal,
|
|
25
25
|
getQueryKeyInternal,
|
|
26
26
|
} from '../../internals/getQueryKey';
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
buildQueryFromAsyncIterable,
|
|
29
|
+
useHookResult,
|
|
30
|
+
} from '../../internals/trpcResult';
|
|
28
31
|
import type {
|
|
29
32
|
TRPCUseQueries,
|
|
30
33
|
TRPCUseSuspenseQueries,
|
|
@@ -193,26 +196,11 @@ export function createRootHooks<
|
|
|
193
196
|
);
|
|
194
197
|
|
|
195
198
|
if (isAsyncIterable(result)) {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
+
return buildQueryFromAsyncIterable(
|
|
200
|
+
result,
|
|
201
|
+
queryClient,
|
|
199
202
|
queryKey,
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
query.setState({
|
|
203
|
-
data: [],
|
|
204
|
-
status: 'success',
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
const aggregate: unknown[] = [];
|
|
208
|
-
for await (const value of result) {
|
|
209
|
-
aggregate.push(value);
|
|
210
|
-
|
|
211
|
-
query.setState({
|
|
212
|
-
data: [...aggregate],
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
return aggregate;
|
|
203
|
+
);
|
|
216
204
|
}
|
|
217
205
|
return result;
|
|
218
206
|
},
|
|
@@ -185,7 +185,7 @@ export type CreateClient<TRouter extends AnyRouter> = (
|
|
|
185
185
|
opts: CreateTRPCClientOptions<TRouter>,
|
|
186
186
|
) => TRPCUntypedClient<TRouter>;
|
|
187
187
|
|
|
188
|
-
type coerceAsyncIterableToArray<TValue> = TValue extends AsyncIterable<
|
|
188
|
+
export type coerceAsyncIterableToArray<TValue> = TValue extends AsyncIterable<
|
|
189
189
|
infer $Inferred
|
|
190
190
|
>
|
|
191
191
|
? $Inferred[]
|
|
@@ -10,6 +10,7 @@ import type {
|
|
|
10
10
|
RefetchQueryFilters,
|
|
11
11
|
ResetOptions,
|
|
12
12
|
SetDataOptions,
|
|
13
|
+
SkipToken,
|
|
13
14
|
Updater,
|
|
14
15
|
} from '@tanstack/react-query';
|
|
15
16
|
import type { TRPCClientError } from '@trpc/client';
|
|
@@ -44,11 +45,113 @@ import {
|
|
|
44
45
|
} from '../../internals/getQueryKey';
|
|
45
46
|
import type { InferMutationOptions } from '../../utils/inferReactQueryProcedure';
|
|
46
47
|
import type { ExtractCursorType } from '../hooks/types';
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
import type {
|
|
49
|
+
DefinedTRPCInfiniteQueryOptionsIn,
|
|
50
|
+
DefinedTRPCInfiniteQueryOptionsOut,
|
|
51
|
+
DefinedTRPCQueryOptionsIn,
|
|
52
|
+
DefinedTRPCQueryOptionsOut,
|
|
53
|
+
UndefinedTRPCInfiniteQueryOptionsIn,
|
|
54
|
+
UndefinedTRPCInfiniteQueryOptionsOut,
|
|
55
|
+
UndefinedTRPCQueryOptionsIn,
|
|
56
|
+
UndefinedTRPCQueryOptionsOut,
|
|
57
|
+
UnusedSkipTokenTRPCInfiniteQueryOptionsIn,
|
|
58
|
+
UnusedSkipTokenTRPCInfiniteQueryOptionsOut,
|
|
59
|
+
} from '../types';
|
|
60
|
+
|
|
61
|
+
export type DecorateQueryProcedure<
|
|
49
62
|
TRoot extends AnyRootTypes,
|
|
50
63
|
TProcedure extends AnyQueryProcedure,
|
|
51
64
|
> = {
|
|
65
|
+
/**
|
|
66
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
|
67
|
+
*/
|
|
68
|
+
queryOptions<
|
|
69
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
70
|
+
TData = TQueryFnData,
|
|
71
|
+
>(
|
|
72
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
73
|
+
opts: DefinedTRPCQueryOptionsIn<
|
|
74
|
+
TQueryFnData,
|
|
75
|
+
TData,
|
|
76
|
+
TRPCClientError<TRoot>
|
|
77
|
+
>,
|
|
78
|
+
): DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
|
79
|
+
/**
|
|
80
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
|
81
|
+
*/
|
|
82
|
+
queryOptions<
|
|
83
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
84
|
+
TData = TQueryFnData,
|
|
85
|
+
>(
|
|
86
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
87
|
+
opts?: UndefinedTRPCQueryOptionsIn<
|
|
88
|
+
TQueryFnData,
|
|
89
|
+
TData,
|
|
90
|
+
TRPCClientError<TRoot>
|
|
91
|
+
>,
|
|
92
|
+
): UndefinedTRPCQueryOptionsOut<TQueryFnData, TData, TRPCClientError<TRoot>>;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
|
96
|
+
*/
|
|
97
|
+
infiniteQueryOptions<
|
|
98
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
99
|
+
TData = TQueryFnData,
|
|
100
|
+
>(
|
|
101
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
102
|
+
opts: DefinedTRPCInfiniteQueryOptionsIn<
|
|
103
|
+
inferProcedureInput<TProcedure>,
|
|
104
|
+
TQueryFnData,
|
|
105
|
+
TData,
|
|
106
|
+
TRPCClientError<TRoot>
|
|
107
|
+
>,
|
|
108
|
+
): DefinedTRPCInfiniteQueryOptionsOut<
|
|
109
|
+
inferProcedureInput<TProcedure>,
|
|
110
|
+
TQueryFnData,
|
|
111
|
+
TData,
|
|
112
|
+
TRPCClientError<TRoot>
|
|
113
|
+
>;
|
|
114
|
+
/**
|
|
115
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
|
116
|
+
*/
|
|
117
|
+
infiniteQueryOptions<
|
|
118
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
119
|
+
TData = TQueryFnData,
|
|
120
|
+
>(
|
|
121
|
+
input: inferProcedureInput<TProcedure>,
|
|
122
|
+
opts: UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
|
|
123
|
+
inferProcedureInput<TProcedure>,
|
|
124
|
+
TQueryFnData,
|
|
125
|
+
TData,
|
|
126
|
+
TRPCClientError<TRoot>
|
|
127
|
+
>,
|
|
128
|
+
): UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
|
|
129
|
+
inferProcedureInput<TProcedure>,
|
|
130
|
+
TQueryFnData,
|
|
131
|
+
TData,
|
|
132
|
+
TRPCClientError<TRoot>
|
|
133
|
+
>;
|
|
134
|
+
/**
|
|
135
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
|
136
|
+
*/
|
|
137
|
+
infiniteQueryOptions<
|
|
138
|
+
TQueryFnData extends inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
139
|
+
TData = TQueryFnData,
|
|
140
|
+
>(
|
|
141
|
+
input: inferProcedureInput<TProcedure> | SkipToken,
|
|
142
|
+
opts?: UndefinedTRPCInfiniteQueryOptionsIn<
|
|
143
|
+
inferProcedureInput<TProcedure>,
|
|
144
|
+
TQueryFnData,
|
|
145
|
+
TData,
|
|
146
|
+
TRPCClientError<TRoot>
|
|
147
|
+
>,
|
|
148
|
+
): UndefinedTRPCInfiniteQueryOptionsOut<
|
|
149
|
+
inferProcedureInput<TProcedure>,
|
|
150
|
+
TQueryFnData,
|
|
151
|
+
TData,
|
|
152
|
+
TRPCClientError<TRoot>
|
|
153
|
+
>;
|
|
154
|
+
|
|
52
155
|
/**
|
|
53
156
|
* @see https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
|
54
157
|
*/
|
|
@@ -308,6 +411,7 @@ export const getQueryType = (
|
|
|
308
411
|
utilName: keyof AnyDecoratedProcedure,
|
|
309
412
|
): QueryType => {
|
|
310
413
|
switch (utilName) {
|
|
414
|
+
case 'queryOptions':
|
|
311
415
|
case 'fetch':
|
|
312
416
|
case 'ensureData':
|
|
313
417
|
case 'prefetch':
|
|
@@ -316,6 +420,7 @@ export const getQueryType = (
|
|
|
316
420
|
case 'setQueriesData':
|
|
317
421
|
return 'query';
|
|
318
422
|
|
|
423
|
+
case 'infiniteQueryOptions':
|
|
319
424
|
case 'fetchInfinite':
|
|
320
425
|
case 'prefetchInfinite':
|
|
321
426
|
case 'getInfiniteData':
|
|
@@ -350,6 +455,9 @@ function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
|
|
|
350
455
|
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
351
456
|
|
|
352
457
|
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
|
458
|
+
infiniteQueryOptions: () =>
|
|
459
|
+
context.infiniteQueryOptions(path, queryKey, args[0]),
|
|
460
|
+
queryOptions: () => context.queryOptions(path, queryKey, ...args),
|
|
353
461
|
/**
|
|
354
462
|
* DecorateQueryProcedure
|
|
355
463
|
*/
|
package/src/shared/types.ts
CHANGED
|
@@ -1,8 +1,209 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
DataTag,
|
|
3
|
+
DefinedInitialDataInfiniteOptions,
|
|
4
|
+
DefinedInitialDataOptions,
|
|
5
|
+
InfiniteData,
|
|
6
|
+
QueryClient,
|
|
7
|
+
UndefinedInitialDataInfiniteOptions,
|
|
8
|
+
UndefinedInitialDataOptions,
|
|
9
|
+
UnusedSkipTokenInfiniteOptions,
|
|
10
|
+
} from '@tanstack/react-query';
|
|
2
11
|
import type {
|
|
3
12
|
AnyRouter,
|
|
13
|
+
DistributiveOmit,
|
|
4
14
|
MaybePromise,
|
|
5
15
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
16
|
+
import type { TRPCQueryKey } from '../internals/getQueryKey';
|
|
17
|
+
import type {
|
|
18
|
+
coerceAsyncIterableToArray,
|
|
19
|
+
ExtractCursorType,
|
|
20
|
+
TRPCReactRequestOptions,
|
|
21
|
+
} from './hooks/types';
|
|
22
|
+
|
|
23
|
+
export interface TRPCQueryBaseOptions {
|
|
24
|
+
/**
|
|
25
|
+
* tRPC-related options
|
|
26
|
+
*/
|
|
27
|
+
trpc?: TRPCReactRequestOptions;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface TRPCQueryOptionsResult {
|
|
31
|
+
trpc: {
|
|
32
|
+
path: string;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type TRPCOptionOverrides = 'queryKey' | 'queryFn' | 'queryHashFn' | 'queryHash';
|
|
37
|
+
type TRPCInfiniteOptionOverrides = TRPCOptionOverrides | 'initialPageParam';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* QueryOptions API helpers
|
|
41
|
+
*/
|
|
42
|
+
export interface UndefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
|
43
|
+
extends DistributiveOmit<
|
|
44
|
+
UndefinedInitialDataOptions<
|
|
45
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
46
|
+
TError,
|
|
47
|
+
coerceAsyncIterableToArray<TData>,
|
|
48
|
+
TRPCQueryKey
|
|
49
|
+
>,
|
|
50
|
+
TRPCOptionOverrides
|
|
51
|
+
>,
|
|
52
|
+
TRPCQueryBaseOptions {}
|
|
53
|
+
|
|
54
|
+
export interface UndefinedTRPCQueryOptionsOut<TQueryFnData, TOutput, TError>
|
|
55
|
+
extends UndefinedInitialDataOptions<
|
|
56
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
57
|
+
TError,
|
|
58
|
+
coerceAsyncIterableToArray<TOutput>,
|
|
59
|
+
TRPCQueryKey
|
|
60
|
+
>,
|
|
61
|
+
TRPCQueryOptionsResult {
|
|
62
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TOutput>>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface DefinedTRPCQueryOptionsIn<TQueryFnData, TData, TError>
|
|
66
|
+
extends DistributiveOmit<
|
|
67
|
+
DefinedInitialDataOptions<
|
|
68
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
69
|
+
TError,
|
|
70
|
+
coerceAsyncIterableToArray<TData>,
|
|
71
|
+
TRPCQueryKey
|
|
72
|
+
>,
|
|
73
|
+
TRPCOptionOverrides
|
|
74
|
+
>,
|
|
75
|
+
TRPCQueryBaseOptions {}
|
|
76
|
+
|
|
77
|
+
export interface DefinedTRPCQueryOptionsOut<TQueryFnData, TData, TError>
|
|
78
|
+
extends DefinedInitialDataOptions<
|
|
79
|
+
coerceAsyncIterableToArray<TQueryFnData>,
|
|
80
|
+
TError,
|
|
81
|
+
coerceAsyncIterableToArray<TData>,
|
|
82
|
+
TRPCQueryKey
|
|
83
|
+
>,
|
|
84
|
+
TRPCQueryOptionsResult {
|
|
85
|
+
queryKey: DataTag<TRPCQueryKey, coerceAsyncIterableToArray<TData>>;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* InifiniteQueryOptions helpers
|
|
90
|
+
*/
|
|
91
|
+
export interface UndefinedTRPCInfiniteQueryOptionsIn<
|
|
92
|
+
TInput,
|
|
93
|
+
TQueryFnData,
|
|
94
|
+
TData,
|
|
95
|
+
TError,
|
|
96
|
+
> extends DistributiveOmit<
|
|
97
|
+
UndefinedInitialDataInfiniteOptions<
|
|
98
|
+
TQueryFnData,
|
|
99
|
+
TError,
|
|
100
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
101
|
+
TRPCQueryKey,
|
|
102
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
103
|
+
>,
|
|
104
|
+
TRPCInfiniteOptionOverrides
|
|
105
|
+
>,
|
|
106
|
+
TRPCQueryBaseOptions {
|
|
107
|
+
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export interface UndefinedTRPCInfiniteQueryOptionsOut<
|
|
111
|
+
TInput,
|
|
112
|
+
TQueryFnData,
|
|
113
|
+
TData,
|
|
114
|
+
TError,
|
|
115
|
+
> extends DistributiveOmit<
|
|
116
|
+
UndefinedInitialDataInfiniteOptions<
|
|
117
|
+
TQueryFnData,
|
|
118
|
+
TError,
|
|
119
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
120
|
+
TRPCQueryKey,
|
|
121
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
122
|
+
>,
|
|
123
|
+
'initialPageParam'
|
|
124
|
+
>,
|
|
125
|
+
TRPCQueryOptionsResult {
|
|
126
|
+
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
127
|
+
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export interface DefinedTRPCInfiniteQueryOptionsIn<
|
|
131
|
+
TInput,
|
|
132
|
+
TQueryFnData,
|
|
133
|
+
TData,
|
|
134
|
+
TError,
|
|
135
|
+
> extends DistributiveOmit<
|
|
136
|
+
DefinedInitialDataInfiniteOptions<
|
|
137
|
+
TQueryFnData,
|
|
138
|
+
TError,
|
|
139
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
140
|
+
TRPCQueryKey,
|
|
141
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
142
|
+
>,
|
|
143
|
+
TRPCInfiniteOptionOverrides
|
|
144
|
+
>,
|
|
145
|
+
TRPCQueryBaseOptions {
|
|
146
|
+
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export interface DefinedTRPCInfiniteQueryOptionsOut<
|
|
150
|
+
TInput,
|
|
151
|
+
TQueryFnData,
|
|
152
|
+
TData,
|
|
153
|
+
TError,
|
|
154
|
+
> extends DistributiveOmit<
|
|
155
|
+
DefinedInitialDataInfiniteOptions<
|
|
156
|
+
TQueryFnData,
|
|
157
|
+
TError,
|
|
158
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
159
|
+
TRPCQueryKey,
|
|
160
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
161
|
+
>,
|
|
162
|
+
'initialPageParam'
|
|
163
|
+
>,
|
|
164
|
+
TRPCQueryOptionsResult {
|
|
165
|
+
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
166
|
+
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export interface UnusedSkipTokenTRPCInfiniteQueryOptionsIn<
|
|
170
|
+
TInput,
|
|
171
|
+
TQueryFnData,
|
|
172
|
+
TData,
|
|
173
|
+
TError,
|
|
174
|
+
> extends DistributiveOmit<
|
|
175
|
+
UnusedSkipTokenInfiniteOptions<
|
|
176
|
+
TQueryFnData,
|
|
177
|
+
TError,
|
|
178
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
179
|
+
TRPCQueryKey,
|
|
180
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
181
|
+
>,
|
|
182
|
+
TRPCInfiniteOptionOverrides
|
|
183
|
+
>,
|
|
184
|
+
TRPCQueryBaseOptions {
|
|
185
|
+
initialCursor?: NonNullable<ExtractCursorType<TInput>> | null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
export interface UnusedSkipTokenTRPCInfiniteQueryOptionsOut<
|
|
189
|
+
TInput,
|
|
190
|
+
TQueryFnData,
|
|
191
|
+
TData,
|
|
192
|
+
TError,
|
|
193
|
+
> extends DistributiveOmit<
|
|
194
|
+
UnusedSkipTokenInfiniteOptions<
|
|
195
|
+
TQueryFnData,
|
|
196
|
+
TError,
|
|
197
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
198
|
+
TRPCQueryKey,
|
|
199
|
+
NonNullable<ExtractCursorType<TInput>> | null
|
|
200
|
+
>,
|
|
201
|
+
'initialPageParam'
|
|
202
|
+
>,
|
|
203
|
+
TRPCQueryOptionsResult {
|
|
204
|
+
queryKey: DataTag<TRPCQueryKey, TData>;
|
|
205
|
+
initialPageParam: NonNullable<ExtractCursorType<TInput>> | null;
|
|
206
|
+
}
|
|
6
207
|
|
|
7
208
|
/**
|
|
8
209
|
* @internal
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { QueryFunctionContext } from '@tanstack/react-query';
|
|
2
|
+
import {
|
|
3
|
+
infiniteQueryOptions,
|
|
4
|
+
queryOptions,
|
|
5
|
+
skipToken,
|
|
6
|
+
type QueryClient,
|
|
7
|
+
} from '@tanstack/react-query';
|
|
2
8
|
import type { CreateTRPCClient } from '@trpc/client';
|
|
3
9
|
import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
|
|
4
10
|
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
11
|
+
import { isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
|
5
12
|
import { getClientArgs } from '../internals/getClientArgs';
|
|
6
|
-
import type {
|
|
13
|
+
import type { TRPCQueryKey } from '../internals/getQueryKey';
|
|
14
|
+
import {
|
|
15
|
+
buildQueryFromAsyncIterable,
|
|
16
|
+
createTRPCOptionsResult,
|
|
17
|
+
} from '../internals/trpcResult';
|
|
18
|
+
import { type TRPCQueryUtils } from '../shared';
|
|
7
19
|
|
|
8
20
|
export interface CreateQueryUtilsOptions<TRouter extends AnyRouter> {
|
|
9
21
|
/**
|
|
@@ -30,6 +42,82 @@ export function createUtilityFunctions<TRouter extends AnyRouter>(
|
|
|
30
42
|
client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
|
31
43
|
|
|
32
44
|
return {
|
|
45
|
+
infiniteQueryOptions: (path, queryKey, opts) => {
|
|
46
|
+
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
|
47
|
+
|
|
48
|
+
const queryFn = async (
|
|
49
|
+
queryFnContext: QueryFunctionContext<TRPCQueryKey, unknown>,
|
|
50
|
+
): Promise<unknown> => {
|
|
51
|
+
const actualOpts = {
|
|
52
|
+
...opts,
|
|
53
|
+
trpc: {
|
|
54
|
+
...opts?.trpc,
|
|
55
|
+
...(opts?.trpc?.abortOnUnmount
|
|
56
|
+
? { signal: queryFnContext.signal }
|
|
57
|
+
: { signal: null }),
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const result = await untypedClient.query(
|
|
62
|
+
...getClientArgs(queryKey, actualOpts, {
|
|
63
|
+
direction: queryFnContext.direction,
|
|
64
|
+
pageParam: queryFnContext.pageParam,
|
|
65
|
+
}),
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
return Object.assign(
|
|
72
|
+
infiniteQueryOptions({
|
|
73
|
+
...opts,
|
|
74
|
+
initialData: opts?.initialData as any,
|
|
75
|
+
queryKey,
|
|
76
|
+
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
|
77
|
+
initialPageParam: (opts?.initialCursor as any) ?? null,
|
|
78
|
+
}),
|
|
79
|
+
{ trpc: createTRPCOptionsResult({ path }) },
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
queryOptions: (path, queryKey, opts) => {
|
|
84
|
+
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
|
85
|
+
|
|
86
|
+
const queryFn = async (
|
|
87
|
+
queryFnContext: QueryFunctionContext<TRPCQueryKey>,
|
|
88
|
+
): Promise<unknown> => {
|
|
89
|
+
const actualOpts = {
|
|
90
|
+
...opts,
|
|
91
|
+
trpc: {
|
|
92
|
+
...opts?.trpc,
|
|
93
|
+
...(opts?.trpc?.abortOnUnmount
|
|
94
|
+
? { signal: queryFnContext.signal }
|
|
95
|
+
: { signal: null }),
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const result = await untypedClient.query(
|
|
100
|
+
...getClientArgs(queryKey, actualOpts),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
if (isAsyncIterable(result)) {
|
|
104
|
+
return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return result;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
return Object.assign(
|
|
111
|
+
queryOptions({
|
|
112
|
+
...opts,
|
|
113
|
+
initialData: opts?.initialData as any,
|
|
114
|
+
queryKey,
|
|
115
|
+
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
|
116
|
+
}),
|
|
117
|
+
{ trpc: createTRPCOptionsResult({ path }) },
|
|
118
|
+
);
|
|
119
|
+
},
|
|
120
|
+
|
|
33
121
|
fetchQuery: (queryKey, opts) => {
|
|
34
122
|
return queryClient.fetchQuery({
|
|
35
123
|
...opts,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { TRPCHookResult } from '../shared/hooks/types';
|
|
2
|
-
/**
|
|
3
|
-
* Makes a stable reference of the `trpc` prop
|
|
4
|
-
*/
|
|
5
|
-
export declare function useHookResult(value: {
|
|
6
|
-
path: readonly string[];
|
|
7
|
-
}): TRPCHookResult['trpc'];
|
|
8
|
-
//# sourceMappingURL=useHookResult.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHookResult.d.ts","sourceRoot":"","sources":["../../src/internals/useHookResult.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAE5D;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE;IACnC,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;CACzB,GAAG,cAAc,CAAC,MAAM,CAAC,CAQzB"}
|