@trpc/react-query 10.43.0 → 11.0.0-next.92
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 +208 -0
- package/dist/createHooksInternal-3d8ebfcf.mjs +481 -0
- package/dist/createHooksInternal-dce6e141.js +435 -0
- package/dist/createHooksInternal-e2034194.js +490 -0
- package/dist/createTRPCReact.d.ts +46 -45
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -21
- package/dist/index.mjs +9 -21
- package/dist/internals/context.d.ts +42 -54
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getClientArgs.d.ts +2 -1
- package/dist/internals/getClientArgs.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts +28 -13
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/useQueries.d.ts +4 -4
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/server/index.d.ts +0 -6
- package/dist/server/index.d.ts.map +1 -1
- package/dist/server/index.js +52 -69
- package/dist/server/index.mjs +52 -69
- package/dist/server/ssgProxy.d.ts +23 -13
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/shared/hooks/createHooksInternal.d.ts +35 -12
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createRootHooks.d.ts +0 -5
- package/dist/shared/hooks/createRootHooks.d.ts.map +1 -1
- package/dist/shared/hooks/types.d.ts +33 -18
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.js +9 -9
- package/dist/shared/index.mjs +3 -3
- package/dist/shared/polymorphism/mutationLike.d.ts +5 -5
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts +5 -5
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts +4 -3
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.d.ts +2 -2
- package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
- package/dist/shared/proxy/useQueriesProxy.d.ts +6 -6
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +34 -31
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/types.d.ts +0 -12
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts +7 -7
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/dist/utilsProxy-00894da2.mjs +121 -0
- package/dist/utilsProxy-27bd93c1.js +128 -0
- package/dist/utilsProxy-7e396600.js +114 -0
- package/package.json +8 -14
- package/src/createTRPCReact.tsx +156 -135
- package/src/index.ts +0 -1
- package/src/internals/context.tsx +93 -164
- package/src/internals/getClientArgs.ts +9 -4
- package/src/internals/getQueryKey.ts +53 -24
- package/src/internals/useQueries.ts +7 -10
- package/src/server/index.ts +0 -8
- package/src/server/ssgProxy.ts +179 -34
- package/src/shared/hooks/createHooksInternal.tsx +298 -207
- package/src/shared/hooks/createRootHooks.tsx +0 -6
- package/src/shared/hooks/types.ts +87 -36
- package/src/shared/polymorphism/mutationLike.ts +11 -8
- package/src/shared/polymorphism/queryLike.ts +17 -12
- package/src/shared/polymorphism/routerLike.ts +15 -9
- package/src/shared/proxy/decorationProxy.ts +9 -31
- package/src/shared/proxy/useQueriesProxy.ts +23 -37
- package/src/shared/proxy/utilsProxy.ts +121 -95
- package/src/shared/types.ts +0 -12
- package/src/utils/inferReactQueryProcedure.ts +28 -30
- package/dist/context-4557b3d3.js +0 -38
- package/dist/createHooksInternal-2e69c447.js +0 -582
- package/dist/createHooksInternal-37b068e0.js +0 -510
- package/dist/createHooksInternal-bdff7171.mjs +0 -568
- package/dist/getArrayQueryKey-4bdb5cc2.js +0 -36
- package/dist/getArrayQueryKey-86134f8b.mjs +0 -34
- package/dist/internals/getArrayQueryKey.d.ts +0 -25
- package/dist/internals/getArrayQueryKey.d.ts.map +0 -1
- package/dist/interop.d.ts +0 -11
- package/dist/interop.d.ts.map +0 -1
- package/dist/server/types.d.ts +0 -14
- package/dist/server/types.d.ts.map +0 -1
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts +0 -63
- package/dist/shared/hooks/deprecated/createHooksInternal.d.ts.map +0 -1
- package/dist/ssg/index.d.ts +0 -15
- package/dist/ssg/index.d.ts.map +0 -1
- package/dist/ssg/ssg.d.ts +0 -16
- package/dist/ssg/ssg.d.ts.map +0 -1
- package/src/internals/getArrayQueryKey.ts +0 -46
- package/src/interop.ts +0 -29
- package/src/server/types.ts +0 -29
- package/src/shared/hooks/deprecated/createHooksInternal.tsx +0 -641
- package/src/ssg/index.tsx +0 -16
- package/src/ssg/ssg.ts +0 -139
- package/ssg/index.d.ts +0 -1
- package/ssg/index.js +0 -1
|
@@ -2,9 +2,3 @@
|
|
|
2
2
|
// After removal of `hooks/deprecated/createHooksInternal` file,
|
|
3
3
|
// `hooks/createHooksInternal` can be swapped for all `createRootHooks` imports.
|
|
4
4
|
export { createRootHooks } from './createHooksInternal';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @deprecated
|
|
8
|
-
* DELETE ME
|
|
9
|
-
*/
|
|
10
|
-
export * from './deprecated/createHooksInternal';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DefinedUseQueryResult,
|
|
3
3
|
DehydratedState,
|
|
4
|
+
InfiniteData,
|
|
4
5
|
InfiniteQueryObserverSuccessResult,
|
|
5
6
|
InitialDataFunction,
|
|
6
7
|
QueryObserverSuccessResult,
|
|
@@ -11,15 +12,20 @@ import {
|
|
|
11
12
|
UseMutationOptions,
|
|
12
13
|
UseMutationResult,
|
|
13
14
|
UseQueryResult,
|
|
15
|
+
UseSuspenseInfiniteQueryOptions,
|
|
16
|
+
UseSuspenseInfiniteQueryResult,
|
|
17
|
+
UseSuspenseQueryOptions,
|
|
18
|
+
UseSuspenseQueryResult,
|
|
14
19
|
} from '@tanstack/react-query';
|
|
15
20
|
import {
|
|
16
21
|
CreateTRPCClientOptions,
|
|
17
|
-
TRPCClient,
|
|
18
22
|
TRPCRequestOptions,
|
|
23
|
+
TRPCUntypedClient,
|
|
19
24
|
} from '@trpc/client';
|
|
20
|
-
import { AnyRouter } from '@trpc/server';
|
|
25
|
+
import { AnyRouter, DistributiveOmit } from '@trpc/server';
|
|
21
26
|
import { ReactNode } from 'react';
|
|
22
27
|
import { TRPCContextProps } from '../../internals/context';
|
|
28
|
+
import { TRPCQueryKey } from '../../internals/getQueryKey';
|
|
23
29
|
import { TRPCHookResult } from '../../internals/useHookResult';
|
|
24
30
|
|
|
25
31
|
export type OutputWithCursor<TData, TCursor = any> = {
|
|
@@ -48,55 +54,73 @@ export interface TRPCUseQueryBaseOptions {
|
|
|
48
54
|
}
|
|
49
55
|
|
|
50
56
|
export interface UseTRPCQueryOptions<
|
|
51
|
-
TPath,
|
|
52
|
-
TInput,
|
|
53
57
|
TOutput,
|
|
54
58
|
TData,
|
|
55
59
|
TError,
|
|
56
60
|
TQueryOptsData = TOutput,
|
|
57
|
-
> extends
|
|
58
|
-
TOutput,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
> extends DistributiveOmit<
|
|
62
|
+
UseBaseQueryOptions<TOutput, TError, TData, TQueryOptsData, any>,
|
|
63
|
+
'queryKey'
|
|
64
|
+
>,
|
|
65
|
+
TRPCUseQueryBaseOptions {}
|
|
66
|
+
|
|
67
|
+
export interface UseTRPCSuspenseQueryOptions<TOutput, TData, TError>
|
|
68
|
+
extends DistributiveOmit<
|
|
69
|
+
UseSuspenseQueryOptions<TOutput, TError, TData, any>,
|
|
70
|
+
'queryKey'
|
|
63
71
|
>,
|
|
64
72
|
TRPCUseQueryBaseOptions {}
|
|
65
73
|
|
|
66
74
|
/** @internal **/
|
|
67
75
|
export interface DefinedUseTRPCQueryOptions<
|
|
68
|
-
TPath,
|
|
69
|
-
TInput,
|
|
70
76
|
TOutput,
|
|
71
77
|
TData,
|
|
72
78
|
TError,
|
|
73
79
|
TQueryOptsData = TOutput,
|
|
74
|
-
> extends
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
TOutput,
|
|
78
|
-
TData,
|
|
79
|
-
TError,
|
|
80
|
-
TQueryOptsData
|
|
80
|
+
> extends DistributiveOmit<
|
|
81
|
+
UseTRPCQueryOptions<TOutput, TData, TError, TQueryOptsData>,
|
|
82
|
+
'queryKey'
|
|
81
83
|
> {
|
|
82
84
|
initialData: InitialDataFunction<TQueryOptsData> | TQueryOptsData;
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
export interface TRPCQueryOptions<
|
|
86
|
-
extends QueryOptions<TData, TError, TData,
|
|
87
|
-
TRPCUseQueryBaseOptions {
|
|
87
|
+
export interface TRPCQueryOptions<TData, TError>
|
|
88
|
+
extends DistributiveOmit<QueryOptions<TData, TError, TData, any>, 'queryKey'>,
|
|
89
|
+
TRPCUseQueryBaseOptions {
|
|
90
|
+
queryKey: TRPCQueryKey;
|
|
91
|
+
}
|
|
88
92
|
|
|
89
|
-
export type ExtractCursorType<TInput> = TInput extends { cursor
|
|
93
|
+
export type ExtractCursorType<TInput> = TInput extends { cursor?: any }
|
|
90
94
|
? TInput['cursor']
|
|
91
95
|
: unknown;
|
|
92
96
|
|
|
93
|
-
export interface UseTRPCInfiniteQueryOptions<
|
|
94
|
-
extends
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
export interface UseTRPCInfiniteQueryOptions<TInput, TOutput, TError>
|
|
98
|
+
extends DistributiveOmit<
|
|
99
|
+
UseInfiniteQueryOptions<
|
|
100
|
+
TOutput,
|
|
101
|
+
TError,
|
|
102
|
+
TOutput,
|
|
103
|
+
TOutput,
|
|
104
|
+
any,
|
|
105
|
+
ExtractCursorType<TInput>
|
|
106
|
+
>,
|
|
107
|
+
'queryKey' | 'initialPageParam'
|
|
108
|
+
>,
|
|
109
|
+
TRPCUseQueryBaseOptions {
|
|
110
|
+
initialCursor?: ExtractCursorType<TInput>;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export interface UseTRPCSuspenseInfiniteQueryOptions<TInput, TOutput, TError>
|
|
114
|
+
extends DistributiveOmit<
|
|
115
|
+
UseSuspenseInfiniteQueryOptions<
|
|
116
|
+
TOutput,
|
|
117
|
+
TError,
|
|
118
|
+
TOutput,
|
|
119
|
+
TOutput,
|
|
120
|
+
any,
|
|
121
|
+
ExtractCursorType<TInput>
|
|
122
|
+
>,
|
|
123
|
+
'queryKey' | 'initialPageParam'
|
|
100
124
|
>,
|
|
101
125
|
TRPCUseQueryBaseOptions {
|
|
102
126
|
initialCursor?: ExtractCursorType<TInput>;
|
|
@@ -126,13 +150,13 @@ export type TRPCProvider<TRouter extends AnyRouter, TSSRContext> = (
|
|
|
126
150
|
) => JSX.Element;
|
|
127
151
|
|
|
128
152
|
export type UseDehydratedState<TRouter extends AnyRouter> = (
|
|
129
|
-
client:
|
|
153
|
+
client: TRPCUntypedClient<TRouter>,
|
|
130
154
|
trpcState: DehydratedState | undefined,
|
|
131
155
|
) => DehydratedState | undefined;
|
|
132
156
|
|
|
133
157
|
export type CreateClient<TRouter extends AnyRouter> = (
|
|
134
158
|
opts: CreateTRPCClientOptions<TRouter>,
|
|
135
|
-
) =>
|
|
159
|
+
) => TRPCUntypedClient<TRouter>;
|
|
136
160
|
|
|
137
161
|
/**
|
|
138
162
|
* @internal
|
|
@@ -158,14 +182,41 @@ export type UseTRPCQuerySuccessResult<TData, TError> =
|
|
|
158
182
|
/**
|
|
159
183
|
* @internal
|
|
160
184
|
*/
|
|
161
|
-
export type
|
|
162
|
-
|
|
185
|
+
export type UseTRPCSuspenseQueryResult<TData, TError> = [
|
|
186
|
+
TData,
|
|
187
|
+
UseSuspenseQueryResult<TData, TError> & TRPCHookResult,
|
|
188
|
+
];
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @internal
|
|
192
|
+
*/
|
|
193
|
+
export type UseTRPCInfiniteQueryResult<TData, TError, TInput> = TRPCHookResult &
|
|
194
|
+
UseInfiniteQueryResult<
|
|
195
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
196
|
+
TError
|
|
197
|
+
>;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* @internal
|
|
201
|
+
*/
|
|
202
|
+
export type UseTRPCInfiniteQuerySuccessResult<TData, TError, TInput> =
|
|
203
|
+
InfiniteQueryObserverSuccessResult<
|
|
204
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
205
|
+
TError
|
|
206
|
+
> &
|
|
207
|
+
TRPCHookResult;
|
|
163
208
|
|
|
164
209
|
/**
|
|
165
210
|
* @internal
|
|
166
211
|
*/
|
|
167
|
-
export type
|
|
168
|
-
|
|
212
|
+
export type UseTRPCSuspenseInfiniteQueryResult<TData, TError, TInput> = [
|
|
213
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
214
|
+
UseSuspenseInfiniteQueryResult<
|
|
215
|
+
InfiniteData<TData, NonNullable<ExtractCursorType<TInput>> | null>,
|
|
216
|
+
TError
|
|
217
|
+
> &
|
|
218
|
+
TRPCHookResult,
|
|
219
|
+
];
|
|
169
220
|
|
|
170
221
|
/**
|
|
171
222
|
* @internal
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyProcedure, inferProcedureInput } from '@trpc/server';
|
|
1
|
+
import { AnyProcedure, AnyRootConfig, inferProcedureInput } from '@trpc/server';
|
|
2
2
|
import { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
3
3
|
import {
|
|
4
4
|
InferMutationOptions,
|
|
@@ -8,24 +8,27 @@ import {
|
|
|
8
8
|
/**
|
|
9
9
|
* Use to describe a mutation route which matches a given mutation procedure's interface
|
|
10
10
|
*/
|
|
11
|
-
export type MutationLike<
|
|
11
|
+
export type MutationLike<
|
|
12
|
+
TConfig extends AnyRootConfig = AnyRootConfig,
|
|
13
|
+
TProcedure extends AnyProcedure = AnyProcedure,
|
|
14
|
+
> = {
|
|
12
15
|
useMutation: (
|
|
13
|
-
opts?: InferMutationOptions<TProcedure>,
|
|
14
|
-
) => InferMutationResult<TProcedure>;
|
|
16
|
+
opts?: InferMutationOptions<TConfig, TProcedure>,
|
|
17
|
+
) => InferMutationResult<TConfig, TProcedure>;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* Use to unwrap a MutationLike's input
|
|
19
22
|
*/
|
|
20
23
|
export type InferMutationLikeInput<TMutationLike extends MutationLike> =
|
|
21
|
-
TMutationLike extends MutationLike<infer
|
|
22
|
-
? inferProcedureInput
|
|
24
|
+
TMutationLike extends MutationLike<any, infer $Procedure>
|
|
25
|
+
? inferProcedureInput<$Procedure>
|
|
23
26
|
: never;
|
|
24
27
|
|
|
25
28
|
/**
|
|
26
29
|
* Use to unwrap a MutationLike's data output
|
|
27
30
|
*/
|
|
28
31
|
export type InferMutationLikeData<TMutationLike extends MutationLike> =
|
|
29
|
-
TMutationLike extends MutationLike<infer TProcedure>
|
|
30
|
-
? inferTransformedProcedureOutput<TProcedure>
|
|
32
|
+
TMutationLike extends MutationLike<infer TConfig, infer TProcedure>
|
|
33
|
+
? inferTransformedProcedureOutput<TConfig, TProcedure>
|
|
31
34
|
: never;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AnyProcedure, inferProcedureInput } from '@trpc/server';
|
|
1
|
+
import { AnyProcedure, AnyRootConfig, inferProcedureInput } from '@trpc/server';
|
|
2
2
|
import { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
3
3
|
import {
|
|
4
4
|
InferQueryOptions,
|
|
@@ -8,25 +8,30 @@ import {
|
|
|
8
8
|
/**
|
|
9
9
|
* Use to request a query route which matches a given query procedure's interface
|
|
10
10
|
*/
|
|
11
|
-
export type QueryLike<
|
|
11
|
+
export type QueryLike<
|
|
12
|
+
TConfig extends AnyRootConfig = AnyRootConfig,
|
|
13
|
+
TProcedure extends AnyProcedure = AnyProcedure,
|
|
14
|
+
> = {
|
|
12
15
|
useQuery: (
|
|
13
16
|
variables: inferProcedureInput<TProcedure>,
|
|
14
|
-
opts?: InferQueryOptions<
|
|
15
|
-
) => InferQueryResult<TProcedure>;
|
|
17
|
+
opts?: InferQueryOptions<TConfig, TProcedure, any>,
|
|
18
|
+
) => InferQueryResult<TConfig, TProcedure>;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
/**
|
|
19
22
|
* Use to unwrap a QueryLike's input
|
|
20
23
|
*/
|
|
21
|
-
export type InferQueryLikeInput<
|
|
22
|
-
TQueryLike extends QueryLike<
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
export type InferQueryLikeInput<
|
|
25
|
+
TQueryLike extends QueryLike<AnyRootConfig, AnyProcedure>,
|
|
26
|
+
> = TQueryLike extends QueryLike<any, infer TProcedure>
|
|
27
|
+
? inferProcedureInput<TProcedure>
|
|
28
|
+
: never;
|
|
25
29
|
|
|
26
30
|
/**
|
|
27
31
|
* Use to unwrap a QueryLike's data output
|
|
28
32
|
*/
|
|
29
|
-
export type InferQueryLikeData<
|
|
30
|
-
TQueryLike extends QueryLike<
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
export type InferQueryLikeData<
|
|
34
|
+
TQueryLike extends QueryLike<AnyRootConfig, AnyProcedure>,
|
|
35
|
+
> = TQueryLike extends QueryLike<infer TConfig, infer TProcedure>
|
|
36
|
+
? inferTransformedProcedureOutput<TConfig, TProcedure>
|
|
37
|
+
: never;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AnyMutationProcedure,
|
|
3
|
+
AnyProcedure,
|
|
3
4
|
AnyQueryProcedure,
|
|
5
|
+
AnyRootConfig,
|
|
4
6
|
AnyRouter,
|
|
5
7
|
} from '@trpc/server';
|
|
6
8
|
import { MutationLike } from './mutationLike';
|
|
@@ -9,15 +11,19 @@ import { QueryLike } from './queryLike';
|
|
|
9
11
|
/**
|
|
10
12
|
* Use to describe a route path which matches a given route's interface
|
|
11
13
|
*/
|
|
12
|
-
export type RouterLike<
|
|
13
|
-
TRouter
|
|
14
|
-
|
|
14
|
+
export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
|
|
15
|
+
TRouter['_def']['_config'],
|
|
16
|
+
TRouter['_def']['procedures']
|
|
17
|
+
>;
|
|
18
|
+
export type RouterLikeInner<
|
|
19
|
+
TConfig extends AnyRootConfig,
|
|
20
|
+
TProcedures extends AnyProcedure,
|
|
15
21
|
> = {
|
|
16
|
-
[
|
|
17
|
-
?
|
|
18
|
-
:
|
|
19
|
-
? QueryLike<
|
|
20
|
-
:
|
|
21
|
-
? MutationLike<
|
|
22
|
+
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
23
|
+
? RouterLikeInner<TConfig, TProcedures[TKey]['_def']['record']>
|
|
24
|
+
: TProcedures[TKey] extends AnyQueryProcedure
|
|
25
|
+
? QueryLike<TConfig, TProcedures[TKey]>
|
|
26
|
+
: TProcedures[TKey] extends AnyMutationProcedure
|
|
27
|
+
? MutationLike<TConfig, TProcedures[TKey]>
|
|
22
28
|
: never;
|
|
23
29
|
};
|
|
@@ -1,38 +1,24 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { createRecursiveProxy } from '@trpc/server/shared';
|
|
3
|
-
import {
|
|
4
|
-
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
|
5
|
-
import { CreateReactQueryHooks } from '../hooks/createRootHooks';
|
|
3
|
+
import { CreateReactQueryHooks } from '../hooks/createHooksInternal';
|
|
6
4
|
|
|
7
5
|
/**
|
|
8
6
|
* Create proxy for decorating procedures
|
|
9
7
|
* @internal
|
|
10
8
|
*/
|
|
11
|
-
export function
|
|
9
|
+
export function createReactDecoration<
|
|
12
10
|
TRouter extends AnyRouter,
|
|
13
11
|
TSSRContext = unknown,
|
|
14
12
|
>(name: string, hooks: CreateReactQueryHooks<TRouter, TSSRContext>) {
|
|
15
|
-
return createRecursiveProxy((
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
const pathCopy = [name, ...opts.path];
|
|
13
|
+
return createRecursiveProxy(({ path, args }) => {
|
|
14
|
+
const pathCopy = [name, ...path];
|
|
19
15
|
|
|
20
16
|
// The last arg is for instance `.useMutation` or `.useQuery()`
|
|
21
17
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22
18
|
const lastArg = pathCopy.pop()!;
|
|
23
19
|
|
|
24
|
-
// The `path` ends up being something like `post.byId`
|
|
25
|
-
const path = pathCopy.join('.');
|
|
26
20
|
if (lastArg === 'useMutation') {
|
|
27
|
-
return (hooks as any)[lastArg](
|
|
28
|
-
}
|
|
29
|
-
const [input, ...rest] = args;
|
|
30
|
-
|
|
31
|
-
const queryKey = getQueryKeyInternal(path, input);
|
|
32
|
-
|
|
33
|
-
// Expose queryKey helper
|
|
34
|
-
if (lastArg === 'getQueryKey') {
|
|
35
|
-
return getArrayQueryKey(queryKey, (rest[0] as any) ?? 'any');
|
|
21
|
+
return (hooks as any)[lastArg](pathCopy, ...args);
|
|
36
22
|
}
|
|
37
23
|
|
|
38
24
|
if (lastArg === '_def') {
|
|
@@ -41,17 +27,9 @@ export function createReactProxyDecoration<
|
|
|
41
27
|
};
|
|
42
28
|
}
|
|
43
29
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const result = (hooks as any)[fn](queryKey, {
|
|
49
|
-
...opts,
|
|
50
|
-
suspense: true,
|
|
51
|
-
enabled: true,
|
|
52
|
-
});
|
|
53
|
-
return [result.data, result];
|
|
54
|
-
}
|
|
55
|
-
return (hooks as any)[lastArg](queryKey, ...rest);
|
|
30
|
+
const [input, ...rest] = args;
|
|
31
|
+
const opts = rest[0] || {};
|
|
32
|
+
|
|
33
|
+
return (hooks as any)[lastArg](pathCopy, input, opts);
|
|
56
34
|
});
|
|
57
35
|
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { QueryOptions } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
2
|
+
import { TRPCClientError, TRPCUntypedClient } from '@trpc/client';
|
|
3
3
|
import {
|
|
4
4
|
AnyProcedure,
|
|
5
5
|
AnyQueryProcedure,
|
|
6
|
+
AnyRootConfig,
|
|
6
7
|
AnyRouter,
|
|
7
8
|
Filter,
|
|
8
9
|
inferProcedureInput,
|
|
@@ -13,45 +14,36 @@ import {
|
|
|
13
14
|
} from '@trpc/server/shared';
|
|
14
15
|
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
|
15
16
|
import { TrpcQueryOptionsForUseQueries } from '../../internals/useQueries';
|
|
16
|
-
import {
|
|
17
|
+
import { TRPCUseQueryBaseOptions } from '../hooks/types';
|
|
17
18
|
|
|
18
|
-
type GetQueryOptions<
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
type GetQueryOptions<
|
|
20
|
+
TConfig extends AnyRootConfig,
|
|
21
|
+
TProcedure extends AnyProcedure,
|
|
22
|
+
> = <TData = inferTransformedProcedureOutput<TConfig, TProcedure>>(
|
|
21
23
|
input: inferProcedureInput<TProcedure>,
|
|
22
24
|
opts?: TrpcQueryOptionsForUseQueries<
|
|
23
|
-
|
|
24
|
-
inferProcedureInput<TProcedure>,
|
|
25
|
-
inferTransformedProcedureOutput<TProcedure>,
|
|
25
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
26
26
|
TData,
|
|
27
|
-
TRPCClientError<
|
|
27
|
+
TRPCClientError<TConfig>
|
|
28
28
|
>,
|
|
29
29
|
) => TrpcQueryOptionsForUseQueries<
|
|
30
|
-
|
|
31
|
-
inferProcedureInput<TProcedure>,
|
|
32
|
-
inferTransformedProcedureOutput<TProcedure>,
|
|
30
|
+
inferTransformedProcedureOutput<TConfig, TProcedure>,
|
|
33
31
|
TData,
|
|
34
|
-
TRPCClientError<
|
|
32
|
+
TRPCClientError<TConfig>
|
|
35
33
|
>;
|
|
36
34
|
|
|
37
35
|
/**
|
|
38
36
|
* @internal
|
|
39
37
|
*/
|
|
40
|
-
export type UseQueriesProcedureRecord<
|
|
41
|
-
TRouter extends AnyRouter,
|
|
42
|
-
TPath extends string = '',
|
|
43
|
-
> = {
|
|
38
|
+
export type UseQueriesProcedureRecord<TRouter extends AnyRouter> = {
|
|
44
39
|
[TKey in keyof Filter<
|
|
45
40
|
TRouter['_def']['record'],
|
|
46
41
|
AnyQueryProcedure | AnyRouter
|
|
47
42
|
>]: TRouter['_def']['record'][TKey] extends AnyRouter
|
|
48
|
-
? UseQueriesProcedureRecord<
|
|
49
|
-
TRouter['_def']['record'][TKey],
|
|
50
|
-
`${TPath}${TKey & string}.`
|
|
51
|
-
>
|
|
43
|
+
? UseQueriesProcedureRecord<TRouter['_def']['record'][TKey]>
|
|
52
44
|
: GetQueryOptions<
|
|
53
|
-
TRouter['_def']['
|
|
54
|
-
|
|
45
|
+
TRouter['_def']['_config'],
|
|
46
|
+
TRouter['_def']['record'][TKey]
|
|
55
47
|
>;
|
|
56
48
|
};
|
|
57
49
|
|
|
@@ -59,29 +51,23 @@ export type UseQueriesProcedureRecord<
|
|
|
59
51
|
* Create proxy for `useQueries` options
|
|
60
52
|
* @internal
|
|
61
53
|
*/
|
|
62
|
-
export function
|
|
63
|
-
client:
|
|
54
|
+
export function createUseQueries<TRouter extends AnyRouter>(
|
|
55
|
+
client: TRPCUntypedClient<TRouter>,
|
|
64
56
|
) {
|
|
65
57
|
return createRecursiveProxy((opts) => {
|
|
66
|
-
const
|
|
58
|
+
const arrayPath = opts.path;
|
|
59
|
+
const dotPath = arrayPath.join('.');
|
|
67
60
|
const [input, _opts] = opts.args as [
|
|
68
61
|
unknown,
|
|
69
|
-
|
|
70
|
-
| undefined
|
|
71
|
-
| {
|
|
72
|
-
trpc?: TRPCReactRequestOptions;
|
|
73
|
-
}
|
|
74
|
-
),
|
|
62
|
+
Partial<QueryOptions> & TRPCUseQueryBaseOptions,
|
|
75
63
|
];
|
|
76
64
|
|
|
77
|
-
const queryKey = getQueryKeyInternal(path, input);
|
|
78
|
-
|
|
79
65
|
const options: QueryOptions = {
|
|
80
|
-
queryKey,
|
|
66
|
+
queryKey: getQueryKeyInternal(arrayPath, input, 'query'),
|
|
81
67
|
queryFn: () => {
|
|
82
|
-
return client.query(
|
|
68
|
+
return client.query(dotPath, input, _opts?.trpc);
|
|
83
69
|
},
|
|
84
|
-
...
|
|
70
|
+
..._opts,
|
|
85
71
|
};
|
|
86
72
|
|
|
87
73
|
return options;
|