@trpc/react-query 11.0.0-next.92 → 11.0.0-rc.330
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/README.md +4 -4
- package/dist/bundle-analysis.json +83 -51
- package/dist/createTRPCQueryUtils.d.ts +4 -0
- package/dist/createTRPCQueryUtils.d.ts.map +1 -0
- package/dist/createTRPCQueryUtils.js +16 -0
- package/dist/createTRPCQueryUtils.mjs +14 -0
- package/dist/createTRPCReact.d.ts +55 -40
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/createTRPCReact.js +58 -0
- package/dist/createTRPCReact.mjs +36 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -36
- package/dist/index.mjs +3 -35
- package/dist/internals/context.d.ts +23 -18
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/context.js +33 -0
- package/dist/internals/context.mjs +11 -0
- package/dist/internals/getClientArgs.d.ts +8 -2
- package/dist/internals/getClientArgs.d.ts.map +1 -1
- package/dist/internals/getClientArgs.js +24 -0
- package/dist/internals/getClientArgs.mjs +22 -0
- package/dist/internals/getQueryKey.d.ts +8 -13
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/getQueryKey.js +60 -0
- package/dist/internals/getQueryKey.mjs +57 -0
- package/dist/internals/useHookResult.d.ts +4 -6
- package/dist/internals/useHookResult.d.ts.map +1 -1
- package/dist/internals/useHookResult.js +35 -0
- package/dist/internals/useHookResult.mjs +14 -0
- package/dist/internals/useQueries.d.ts +32 -4
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/server/index.js +2 -103
- package/dist/server/index.mjs +1 -104
- package/dist/server/ssgProxy.d.ts +21 -21
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +109 -0
- package/dist/server/ssgProxy.mjs +107 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +8 -31
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/{createHooksInternal-e2034194.js → shared/hooks/createHooksInternal.js} +98 -226
- package/dist/{createHooksInternal-3d8ebfcf.mjs → shared/hooks/createHooksInternal.mjs} +70 -210
- package/dist/shared/hooks/types.d.ts +11 -7
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.d.ts +2 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +14 -15
- package/dist/shared/index.mjs +7 -7
- package/dist/shared/polymorphism/mutationLike.d.ts +6 -7
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts +10 -7
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts +6 -6
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/utilsLike.d.ts +3 -3
- package/dist/shared/polymorphism/utilsLike.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/decorationProxy.js +31 -0
- package/dist/shared/proxy/decorationProxy.mjs +29 -0
- package/dist/shared/proxy/useQueriesProxy.d.ts +14 -8
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/useQueriesProxy.js +25 -0
- package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
- package/dist/shared/proxy/utilsProxy.d.ts +28 -24
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +89 -0
- package/dist/shared/proxy/utilsProxy.mjs +85 -0
- package/dist/shared/queryClient.d.ts +2 -1
- package/dist/shared/queryClient.d.ts.map +1 -1
- package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
- package/dist/shared/types.d.ts +2 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.d.ts +23 -0
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -0
- package/dist/utils/createUtilityFunctions.js +100 -0
- package/dist/utils/createUtilityFunctions.mjs +98 -0
- package/dist/utils/inferReactQueryProcedure.d.ts +11 -10
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/createTRPCQueryUtils.tsx +11 -0
- package/src/createTRPCReact.tsx +139 -163
- package/src/index.ts +6 -1
- package/src/internals/context.tsx +27 -18
- package/src/internals/getClientArgs.ts +16 -4
- package/src/internals/getQueryKey.ts +51 -62
- package/src/internals/useHookResult.ts +12 -13
- package/src/internals/useQueries.ts +129 -4
- package/src/server/ssgProxy.ts +59 -57
- package/src/shared/hooks/createHooksInternal.tsx +115 -246
- package/src/shared/hooks/types.ts +15 -7
- package/src/shared/index.ts +5 -2
- package/src/shared/polymorphism/mutationLike.ts +21 -15
- package/src/shared/polymorphism/queryLike.ts +34 -14
- package/src/shared/polymorphism/routerLike.ts +29 -15
- package/src/shared/polymorphism/utilsLike.ts +6 -3
- package/src/shared/proxy/decorationProxy.ts +3 -3
- package/src/shared/proxy/useQueriesProxy.ts +65 -28
- package/src/shared/proxy/utilsProxy.ts +113 -86
- package/src/shared/queryClient.ts +2 -1
- package/src/shared/types.ts +5 -2
- package/src/utils/createUtilityFunctions.ts +137 -0
- package/src/utils/inferReactQueryProcedure.ts +38 -28
- package/dist/createHooksInternal-dce6e141.js +0 -435
- package/dist/queryClient-1c8d7d8a.js +0 -8
- package/dist/utilsProxy-00894da2.mjs +0 -121
- package/dist/utilsProxy-27bd93c1.js +0 -128
- package/dist/utilsProxy-7e396600.js +0 -114
- /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
|
@@ -1,12 +1,10 @@
|
|
|
1
|
+
import { skipToken } from '@tanstack/react-query';
|
|
1
2
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
inferProcedureInput,
|
|
8
|
-
} from '@trpc/server';
|
|
9
|
-
import { DecoratedProcedureRecord, DecorateProcedure } from '../shared';
|
|
3
|
+
isObject,
|
|
4
|
+
type DeepPartial,
|
|
5
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
6
|
+
import type { DecoratedMutation, DecoratedQuery } from '../createTRPCReact';
|
|
7
|
+
import type { DecorateRouterRecord } from '../shared';
|
|
10
8
|
|
|
11
9
|
export type QueryType = 'any' | 'infinite' | 'query';
|
|
12
10
|
|
|
@@ -15,6 +13,11 @@ export type TRPCQueryKey = [
|
|
|
15
13
|
{ input?: unknown; type?: Exclude<QueryType, 'any'> }?,
|
|
16
14
|
];
|
|
17
15
|
|
|
16
|
+
type ProcedureOrRouter =
|
|
17
|
+
| DecoratedMutation<any>
|
|
18
|
+
| DecoratedQuery<any>
|
|
19
|
+
| DecorateRouterRecord<any, any>;
|
|
20
|
+
|
|
18
21
|
/**
|
|
19
22
|
* To allow easy interactions with groups of related queries, such as
|
|
20
23
|
* invalidating all queries of a router, we use an array as the path when
|
|
@@ -32,14 +35,35 @@ export function getQueryKeyInternal(
|
|
|
32
35
|
// some parts of the path may be dot-separated, split them up
|
|
33
36
|
const splitPath = path.flatMap((part) => part.split('.'));
|
|
34
37
|
|
|
35
|
-
if (!input && (!type || type === 'any'))
|
|
38
|
+
if (!input && (!type || type === 'any')) {
|
|
36
39
|
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
37
40
|
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
38
41
|
return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (
|
|
45
|
+
type === 'infinite' &&
|
|
46
|
+
isObject(input) &&
|
|
47
|
+
('direction' in input || 'cursor' in input)
|
|
48
|
+
) {
|
|
49
|
+
const {
|
|
50
|
+
cursor: _,
|
|
51
|
+
direction: __,
|
|
52
|
+
...inputWithoutCursorAndDirection
|
|
53
|
+
} = input;
|
|
54
|
+
return [
|
|
55
|
+
splitPath,
|
|
56
|
+
{
|
|
57
|
+
input: inputWithoutCursorAndDirection,
|
|
58
|
+
type: 'infinite',
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
}
|
|
39
62
|
return [
|
|
40
63
|
splitPath,
|
|
41
64
|
{
|
|
42
|
-
...(typeof input !== 'undefined' &&
|
|
65
|
+
...(typeof input !== 'undefined' &&
|
|
66
|
+
input !== skipToken && { input: input }),
|
|
43
67
|
...(type && type !== 'any' && { type: type }),
|
|
44
68
|
},
|
|
45
69
|
];
|
|
@@ -47,10 +71,13 @@ export function getQueryKeyInternal(
|
|
|
47
71
|
|
|
48
72
|
type GetInfiniteQueryInput<
|
|
49
73
|
TProcedureInput,
|
|
50
|
-
|
|
51
|
-
|
|
74
|
+
TInputWithoutCursorAndDirection = Omit<
|
|
75
|
+
TProcedureInput,
|
|
76
|
+
'cursor' | 'direction'
|
|
77
|
+
>,
|
|
78
|
+
> = keyof TInputWithoutCursorAndDirection extends never
|
|
52
79
|
? undefined
|
|
53
|
-
: DeepPartial<
|
|
80
|
+
: DeepPartial<TInputWithoutCursorAndDirection> | undefined;
|
|
54
81
|
|
|
55
82
|
/** @internal */
|
|
56
83
|
export type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
|
@@ -59,62 +86,24 @@ export type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
|
|
59
86
|
? GetInfiniteQueryInput<TProcedureInput>
|
|
60
87
|
: DeepPartial<TProcedureInput> | undefined;
|
|
61
88
|
|
|
62
|
-
type
|
|
63
|
-
TProcedureOrRouter extends
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
? []
|
|
67
|
-
: [input?: GetQueryProcedureInput<TProcedureInput>, type?: QueryType];
|
|
68
|
-
|
|
69
|
-
type GetParams<
|
|
70
|
-
TConfig extends AnyRootConfig,
|
|
71
|
-
TProcedureOrRouter extends
|
|
72
|
-
| AnyMutationProcedure
|
|
73
|
-
| AnyQueryProcedure
|
|
74
|
-
| AnyRouter,
|
|
75
|
-
TFlags,
|
|
76
|
-
> = TProcedureOrRouter extends AnyQueryProcedure
|
|
77
|
-
? [
|
|
78
|
-
procedureOrRouter: DecorateProcedure<TConfig, TProcedureOrRouter, TFlags>,
|
|
79
|
-
..._params: GetQueryParams<TProcedureOrRouter>,
|
|
80
|
-
]
|
|
81
|
-
: TProcedureOrRouter extends AnyMutationProcedure
|
|
82
|
-
? [procedureOrRouter: DecorateProcedure<TConfig, TProcedureOrRouter, TFlags>]
|
|
83
|
-
: TProcedureOrRouter extends AnyRouter
|
|
84
|
-
? [
|
|
85
|
-
procedureOrRouter: DecoratedProcedureRecord<
|
|
86
|
-
TConfig,
|
|
87
|
-
TProcedureOrRouter['_def']['record'],
|
|
88
|
-
TFlags
|
|
89
|
-
>,
|
|
90
|
-
]
|
|
91
|
-
: never;
|
|
92
|
-
|
|
93
|
-
type GetQueryKeyParams<
|
|
94
|
-
TConfig extends AnyRootConfig,
|
|
95
|
-
TProcedureOrRouter extends
|
|
96
|
-
| AnyMutationProcedure
|
|
97
|
-
| AnyQueryProcedure
|
|
98
|
-
| AnyRouter,
|
|
99
|
-
TFlags,
|
|
100
|
-
> = GetParams<TConfig, TProcedureOrRouter, TFlags>;
|
|
89
|
+
type GetParams<TProcedureOrRouter extends ProcedureOrRouter> =
|
|
90
|
+
TProcedureOrRouter extends DecoratedQuery<infer $Def>
|
|
91
|
+
? [input?: GetQueryProcedureInput<$Def['input']>, type?: QueryType]
|
|
92
|
+
: [];
|
|
101
93
|
|
|
102
94
|
/**
|
|
103
95
|
* Method to extract the query key for a procedure
|
|
104
96
|
* @param procedureOrRouter - procedure or AnyRouter
|
|
105
97
|
* @param input - input to procedureOrRouter
|
|
106
98
|
* @param type - defaults to `any`
|
|
107
|
-
* @link https://trpc.io/docs/getQueryKey
|
|
99
|
+
* @link https://trpc.io/docs/v11/getQueryKey
|
|
108
100
|
*/
|
|
109
|
-
export function getQueryKey<
|
|
110
|
-
|
|
111
|
-
TProcedureOrRouter
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
TFlags,
|
|
116
|
-
>(..._params: GetQueryKeyParams<TConfig, TProcedureOrRouter, TFlags>) {
|
|
117
|
-
const [procedureOrRouter, input, type] = _params;
|
|
101
|
+
export function getQueryKey<TProcedureOrRouter extends ProcedureOrRouter>(
|
|
102
|
+
procedureOrRouter: TProcedureOrRouter,
|
|
103
|
+
..._params: GetParams<TProcedureOrRouter>
|
|
104
|
+
) {
|
|
105
|
+
const [input, type] = _params;
|
|
106
|
+
|
|
118
107
|
// @ts-expect-error - we don't expose _def on the type layer
|
|
119
108
|
const path = procedureOrRouter._def().path as string[];
|
|
120
109
|
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export interface TRPCHookResult {
|
|
4
|
-
trpc: {
|
|
5
|
-
path: string;
|
|
6
|
-
};
|
|
7
|
-
}
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import type { TRPCHookResult } from '../shared/hooks/types';
|
|
8
3
|
|
|
9
4
|
/**
|
|
10
5
|
* Makes a stable reference of the `trpc` prop
|
|
11
6
|
*/
|
|
12
|
-
export function useHookResult(
|
|
13
|
-
|
|
14
|
-
): TRPCHookResult['trpc'] {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
export function useHookResult(value: {
|
|
8
|
+
path: string[];
|
|
9
|
+
}): TRPCHookResult['trpc'] {
|
|
10
|
+
const path = value.path.join('.');
|
|
11
|
+
return React.useMemo(
|
|
12
|
+
() => ({
|
|
13
|
+
path,
|
|
14
|
+
}),
|
|
15
|
+
[path],
|
|
16
|
+
);
|
|
18
17
|
}
|
|
@@ -1,9 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type {
|
|
2
|
+
QueryKey,
|
|
3
|
+
UseQueryOptions,
|
|
4
|
+
UseSuspenseQueryOptions,
|
|
5
|
+
UseSuspenseQueryResult,
|
|
6
|
+
} from '@tanstack/react-query';
|
|
7
|
+
import type {
|
|
8
|
+
AnyRouter,
|
|
9
|
+
DistributiveOmit,
|
|
10
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
11
|
+
import type {
|
|
4
12
|
UseQueriesProcedureRecord,
|
|
13
|
+
UseSuspenseQueriesProcedureRecord,
|
|
5
14
|
UseTRPCQueryOptions,
|
|
6
15
|
UseTRPCQueryResult,
|
|
16
|
+
UseTRPCSuspenseQueryOptions,
|
|
7
17
|
} from '../shared';
|
|
8
18
|
|
|
9
19
|
/**
|
|
@@ -19,12 +29,34 @@ export type UseQueryOptionsForUseQueries<
|
|
|
19
29
|
'queryKey'
|
|
20
30
|
>;
|
|
21
31
|
|
|
32
|
+
/**
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
export type UseQueryOptionsForUseSuspenseQueries<
|
|
36
|
+
TQueryFnData = unknown,
|
|
37
|
+
TError = unknown,
|
|
38
|
+
TData = TQueryFnData,
|
|
39
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
40
|
+
> = DistributiveOmit<
|
|
41
|
+
UseSuspenseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
|
42
|
+
'queryKey'
|
|
43
|
+
>;
|
|
44
|
+
|
|
22
45
|
/**
|
|
23
46
|
* @internal
|
|
24
47
|
*/
|
|
25
48
|
export type TrpcQueryOptionsForUseQueries<TOutput, TData, TError> =
|
|
26
49
|
DistributiveOmit<UseTRPCQueryOptions<TOutput, TData, TError>, 'queryKey'>;
|
|
27
50
|
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export type TrpcQueryOptionsForUseSuspenseQueries<TOutput, TData, TError> =
|
|
55
|
+
DistributiveOmit<
|
|
56
|
+
UseTRPCSuspenseQueryOptions<TOutput, TData, TError>,
|
|
57
|
+
'queryKey'
|
|
58
|
+
>;
|
|
59
|
+
|
|
28
60
|
/**
|
|
29
61
|
* @internal
|
|
30
62
|
*/
|
|
@@ -41,6 +73,44 @@ export declare type QueriesResults<
|
|
|
41
73
|
: never;
|
|
42
74
|
};
|
|
43
75
|
|
|
76
|
+
/**
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
export declare type SuspenseQueriesResults<
|
|
80
|
+
TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<
|
|
81
|
+
any,
|
|
82
|
+
any,
|
|
83
|
+
any,
|
|
84
|
+
any
|
|
85
|
+
>[],
|
|
86
|
+
> = [
|
|
87
|
+
{
|
|
88
|
+
[TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<
|
|
89
|
+
infer TQueryFnData,
|
|
90
|
+
any,
|
|
91
|
+
infer TData,
|
|
92
|
+
any
|
|
93
|
+
>
|
|
94
|
+
? unknown extends TData
|
|
95
|
+
? TQueryFnData
|
|
96
|
+
: TData
|
|
97
|
+
: never;
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
[TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseSuspenseQueries<
|
|
101
|
+
infer TQueryFnData,
|
|
102
|
+
infer TError,
|
|
103
|
+
infer TData,
|
|
104
|
+
any
|
|
105
|
+
>
|
|
106
|
+
? UseSuspenseQueryResult<
|
|
107
|
+
unknown extends TData ? TQueryFnData : TData,
|
|
108
|
+
TError
|
|
109
|
+
>
|
|
110
|
+
: never;
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
44
114
|
type GetOptions<TQueryOptions> =
|
|
45
115
|
TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>
|
|
46
116
|
? TQueryOptions
|
|
@@ -69,6 +139,39 @@ export type QueriesOptions<
|
|
|
69
139
|
? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[]
|
|
70
140
|
: UseQueryOptionsForUseQueries[];
|
|
71
141
|
|
|
142
|
+
type GetSuspenseOptions<TQueryOptions> =
|
|
143
|
+
TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<any, any, any, any>
|
|
144
|
+
? TQueryOptions
|
|
145
|
+
: never;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @internal
|
|
149
|
+
*/
|
|
150
|
+
export type SuspenseQueriesOptions<
|
|
151
|
+
TQueriesOptions extends any[],
|
|
152
|
+
TResult extends any[] = [],
|
|
153
|
+
> = TQueriesOptions extends []
|
|
154
|
+
? []
|
|
155
|
+
: TQueriesOptions extends [infer Head]
|
|
156
|
+
? [...TResult, GetSuspenseOptions<Head>]
|
|
157
|
+
: TQueriesOptions extends [infer Head, ...infer Tail]
|
|
158
|
+
? QueriesOptions<Tail, [...TResult, GetSuspenseOptions<Head>]>
|
|
159
|
+
: unknown[] extends TQueriesOptions
|
|
160
|
+
? TQueriesOptions
|
|
161
|
+
: TQueriesOptions extends UseQueryOptionsForUseSuspenseQueries<
|
|
162
|
+
infer TQueryFnData,
|
|
163
|
+
infer TError,
|
|
164
|
+
infer TData,
|
|
165
|
+
infer TQueryKey
|
|
166
|
+
>[]
|
|
167
|
+
? UseQueryOptionsForUseSuspenseQueries<
|
|
168
|
+
TQueryFnData,
|
|
169
|
+
TError,
|
|
170
|
+
TData,
|
|
171
|
+
TQueryKey
|
|
172
|
+
>[]
|
|
173
|
+
: UseQueryOptionsForUseSuspenseQueries[];
|
|
174
|
+
|
|
72
175
|
/**
|
|
73
176
|
* @internal
|
|
74
177
|
*/
|
|
@@ -76,6 +179,28 @@ export type TRPCUseQueries<TRouter extends AnyRouter> = <
|
|
|
76
179
|
TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[],
|
|
77
180
|
>(
|
|
78
181
|
queriesCallback: (
|
|
79
|
-
t: UseQueriesProcedureRecord<
|
|
182
|
+
t: UseQueriesProcedureRecord<
|
|
183
|
+
TRouter['_def']['_config']['$types'],
|
|
184
|
+
TRouter['_def']['record']
|
|
185
|
+
>,
|
|
80
186
|
) => readonly [...QueriesOptions<TQueryOptions>],
|
|
81
187
|
) => QueriesResults<TQueryOptions>;
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
export type TRPCUseSuspenseQueries<TRouter extends AnyRouter> = <
|
|
193
|
+
TQueryOptions extends UseQueryOptionsForUseSuspenseQueries<
|
|
194
|
+
any,
|
|
195
|
+
any,
|
|
196
|
+
any,
|
|
197
|
+
any
|
|
198
|
+
>[],
|
|
199
|
+
>(
|
|
200
|
+
queriesCallback: (
|
|
201
|
+
t: UseSuspenseQueriesProcedureRecord<
|
|
202
|
+
TRouter['_def']['_config']['$types'],
|
|
203
|
+
TRouter['_def']['record']
|
|
204
|
+
>,
|
|
205
|
+
) => readonly [...SuspenseQueriesOptions<TQueryOptions>],
|
|
206
|
+
) => SuspenseQueriesResults<TQueryOptions>;
|
package/src/server/ssgProxy.ts
CHANGED
|
@@ -1,49 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
dehydrate,
|
|
1
|
+
import type {
|
|
3
2
|
DehydratedState,
|
|
4
3
|
DehydrateOptions,
|
|
5
4
|
InfiniteData,
|
|
6
5
|
QueryClient,
|
|
7
6
|
} from '@tanstack/react-query';
|
|
7
|
+
import { dehydrate } from '@tanstack/react-query';
|
|
8
|
+
import type { inferRouterClient, TRPCClientError } from '@trpc/client';
|
|
9
|
+
import { getUntypedClient, TRPCUntypedClient } from '@trpc/client';
|
|
10
|
+
import type { CoercedTransformerParameters } from '@trpc/client/unstable-internals';
|
|
8
11
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
} from '@trpc/client';
|
|
14
|
-
import {
|
|
12
|
+
getTransformer,
|
|
13
|
+
type TransformerOptions,
|
|
14
|
+
} from '@trpc/client/unstable-internals';
|
|
15
|
+
import type {
|
|
15
16
|
AnyProcedure,
|
|
16
17
|
AnyQueryProcedure,
|
|
17
|
-
|
|
18
|
+
AnyRootTypes,
|
|
18
19
|
AnyRouter,
|
|
19
|
-
|
|
20
|
-
ClientDataTransformerOptions,
|
|
21
|
-
Filter,
|
|
20
|
+
inferClientTypes,
|
|
22
21
|
inferProcedureInput,
|
|
23
22
|
inferRouterContext,
|
|
23
|
+
inferTransformedProcedureOutput,
|
|
24
24
|
Maybe,
|
|
25
25
|
ProtectedIntersection,
|
|
26
|
-
|
|
26
|
+
RouterRecord,
|
|
27
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
27
28
|
import {
|
|
29
|
+
callProcedure,
|
|
28
30
|
createFlatProxy,
|
|
29
31
|
createRecursiveProxy,
|
|
30
|
-
|
|
31
|
-
} from '@trpc/server/shared';
|
|
32
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
32
33
|
import { getQueryKeyInternal } from '../internals/getQueryKey';
|
|
33
|
-
import {
|
|
34
|
+
import type {
|
|
34
35
|
CreateTRPCReactQueryClientConfig,
|
|
35
36
|
ExtractCursorType,
|
|
36
|
-
getQueryClient,
|
|
37
|
-
getQueryType,
|
|
38
37
|
TRPCFetchInfiniteQueryOptions,
|
|
39
38
|
TRPCFetchQueryOptions,
|
|
40
39
|
} from '../shared';
|
|
40
|
+
import { getQueryClient, getQueryType } from '../shared';
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
type CreateSSGHelpersInternal<TRouter extends AnyRouter> = {
|
|
43
43
|
router: TRouter;
|
|
44
44
|
ctx: inferRouterContext<TRouter>;
|
|
45
|
-
|
|
46
|
-
}
|
|
45
|
+
} & TransformerOptions<inferClientTypes<TRouter>>;
|
|
47
46
|
|
|
48
47
|
interface CreateSSGHelpersExternal<TRouter extends AnyRouter> {
|
|
49
48
|
client: inferRouterClient<TRouter> | TRPCUntypedClient<TRouter>;
|
|
@@ -54,57 +53,57 @@ type CreateServerSideHelpersOptions<TRouter extends AnyRouter> =
|
|
|
54
53
|
(CreateSSGHelpersExternal<TRouter> | CreateSSGHelpersInternal<TRouter>);
|
|
55
54
|
|
|
56
55
|
type DecorateProcedure<
|
|
57
|
-
|
|
56
|
+
TRoot extends AnyRootTypes,
|
|
58
57
|
TProcedure extends AnyProcedure,
|
|
59
58
|
> = {
|
|
60
59
|
/**
|
|
61
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching
|
|
60
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
62
61
|
*/
|
|
63
62
|
fetch(
|
|
64
63
|
input: inferProcedureInput<TProcedure>,
|
|
65
64
|
opts?: TRPCFetchQueryOptions<
|
|
66
|
-
inferTransformedProcedureOutput<
|
|
67
|
-
TRPCClientError<
|
|
65
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
66
|
+
TRPCClientError<TRoot>
|
|
68
67
|
>,
|
|
69
|
-
): Promise<inferTransformedProcedureOutput<
|
|
68
|
+
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
|
70
69
|
|
|
71
70
|
/**
|
|
72
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching
|
|
71
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
73
72
|
*/
|
|
74
73
|
fetchInfinite(
|
|
75
74
|
input: inferProcedureInput<TProcedure>,
|
|
76
75
|
opts?: TRPCFetchInfiniteQueryOptions<
|
|
77
76
|
inferProcedureInput<TProcedure>,
|
|
78
|
-
inferTransformedProcedureOutput<
|
|
79
|
-
TRPCClientError<
|
|
77
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
78
|
+
TRPCClientError<TRoot>
|
|
80
79
|
>,
|
|
81
80
|
): Promise<
|
|
82
81
|
InfiniteData<
|
|
83
|
-
inferTransformedProcedureOutput<
|
|
82
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
84
83
|
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
85
84
|
>
|
|
86
85
|
>;
|
|
87
86
|
|
|
88
87
|
/**
|
|
89
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching
|
|
88
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
90
89
|
*/
|
|
91
90
|
prefetch(
|
|
92
91
|
input: inferProcedureInput<TProcedure>,
|
|
93
92
|
opts?: TRPCFetchQueryOptions<
|
|
94
|
-
inferTransformedProcedureOutput<
|
|
95
|
-
TRPCClientError<
|
|
93
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
94
|
+
TRPCClientError<TRoot>
|
|
96
95
|
>,
|
|
97
96
|
): Promise<void>;
|
|
98
97
|
|
|
99
98
|
/**
|
|
100
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/prefetching
|
|
99
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/prefetching
|
|
101
100
|
*/
|
|
102
101
|
prefetchInfinite(
|
|
103
102
|
input: inferProcedureInput<TProcedure>,
|
|
104
103
|
opts?: TRPCFetchInfiniteQueryOptions<
|
|
105
104
|
inferProcedureInput<TProcedure>,
|
|
106
|
-
inferTransformedProcedureOutput<
|
|
107
|
-
TRPCClientError<
|
|
105
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
106
|
+
TRPCClientError<TRoot>
|
|
108
107
|
>,
|
|
109
108
|
): Promise<void>;
|
|
110
109
|
};
|
|
@@ -112,40 +111,42 @@ type DecorateProcedure<
|
|
|
112
111
|
/**
|
|
113
112
|
* @internal
|
|
114
113
|
*/
|
|
115
|
-
type DecoratedProcedureSSGRecord<
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
?
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
114
|
+
type DecoratedProcedureSSGRecord<
|
|
115
|
+
TRoot extends AnyRootTypes,
|
|
116
|
+
TRecord extends RouterRecord,
|
|
117
|
+
> = {
|
|
118
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
119
|
+
? $Value extends RouterRecord
|
|
120
|
+
? DecoratedProcedureSSGRecord<TRoot, $Value>
|
|
121
|
+
: // utils only apply to queries
|
|
122
|
+
$Value extends AnyQueryProcedure
|
|
123
|
+
? DecorateProcedure<TRoot, $Value>
|
|
124
|
+
: never
|
|
125
|
+
: never;
|
|
126
126
|
};
|
|
127
127
|
|
|
128
128
|
type AnyDecoratedProcedure = DecorateProcedure<any, any>;
|
|
129
129
|
|
|
130
130
|
/**
|
|
131
131
|
* Create functions you can use for server-side rendering / static generation
|
|
132
|
-
* @
|
|
132
|
+
* @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
|
133
133
|
*/
|
|
134
134
|
export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
135
135
|
opts: CreateServerSideHelpersOptions<TRouter>,
|
|
136
136
|
) {
|
|
137
137
|
const queryClient = getQueryClient(opts);
|
|
138
|
+
const transformer = getTransformer(
|
|
139
|
+
(opts as CoercedTransformerParameters).transformer,
|
|
140
|
+
);
|
|
138
141
|
|
|
139
142
|
const resolvedOpts: {
|
|
140
143
|
serialize: (obj: unknown) => any;
|
|
141
144
|
query: (queryOpts: { path: string; input: unknown }) => Promise<unknown>;
|
|
142
145
|
} = (() => {
|
|
143
146
|
if ('router' in opts) {
|
|
144
|
-
const {
|
|
147
|
+
const { ctx, router } = opts;
|
|
145
148
|
return {
|
|
146
|
-
serialize: transformer
|
|
147
|
-
? ('input' in transformer ? transformer.input : transformer).serialize
|
|
148
|
-
: (obj) => obj,
|
|
149
|
+
serialize: transformer.output.serialize,
|
|
149
150
|
query: (queryOpts) => {
|
|
150
151
|
return callProcedure({
|
|
151
152
|
procedures: router._def.procedures,
|
|
@@ -160,14 +161,12 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
|
160
161
|
|
|
161
162
|
const { client } = opts;
|
|
162
163
|
const untypedClient =
|
|
163
|
-
client instanceof TRPCUntypedClient
|
|
164
|
-
? client
|
|
165
|
-
: getUntypedClient(client as any);
|
|
164
|
+
client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
|
166
165
|
|
|
167
166
|
return {
|
|
168
167
|
query: (queryOpts) =>
|
|
169
168
|
untypedClient.query(queryOpts.path, queryOpts.input),
|
|
170
|
-
serialize: (obj) =>
|
|
169
|
+
serialize: (obj) => transformer.output.serialize(obj),
|
|
171
170
|
};
|
|
172
171
|
})();
|
|
173
172
|
|
|
@@ -189,7 +188,10 @@ export function createServerSideHelpers<TRouter extends AnyRouter>(
|
|
|
189
188
|
queryClient: QueryClient;
|
|
190
189
|
dehydrate: (opts?: DehydrateOptions) => DehydratedState;
|
|
191
190
|
},
|
|
192
|
-
DecoratedProcedureSSGRecord<
|
|
191
|
+
DecoratedProcedureSSGRecord<
|
|
192
|
+
TRouter['_def']['_config']['$types'],
|
|
193
|
+
TRouter['_def']['record']
|
|
194
|
+
>
|
|
193
195
|
>;
|
|
194
196
|
|
|
195
197
|
return createFlatProxy<CreateSSGHelpers>((key) => {
|