@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,29 +1,43 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
AnyMutationProcedure,
|
|
3
|
-
AnyProcedure,
|
|
4
3
|
AnyQueryProcedure,
|
|
5
|
-
|
|
4
|
+
AnyRootTypes,
|
|
6
5
|
AnyRouter,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
6
|
+
RouterRecord,
|
|
7
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
8
|
+
import type { MutationLike } from './mutationLike';
|
|
9
|
+
import type { QueryLike } from './queryLike';
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Use to describe a route path which matches a given route's interface
|
|
13
13
|
*/
|
|
14
14
|
export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
|
|
15
|
-
TRouter['_def']['_config'],
|
|
15
|
+
TRouter['_def']['_config']['$types'],
|
|
16
16
|
TRouter['_def']['procedures']
|
|
17
17
|
>;
|
|
18
18
|
export type RouterLikeInner<
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
TRoot extends AnyRootTypes,
|
|
20
|
+
TRecord extends RouterRecord,
|
|
21
21
|
> = {
|
|
22
|
-
[TKey in keyof
|
|
23
|
-
?
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
23
|
+
? $Value extends RouterRecord
|
|
24
|
+
? RouterLikeInner<TRoot, $Value>
|
|
25
|
+
: $Value extends AnyQueryProcedure
|
|
26
|
+
? QueryLike<TRoot, $Value>
|
|
27
|
+
: $Value extends AnyMutationProcedure
|
|
28
|
+
? MutationLike<TRoot, $Value>
|
|
29
|
+
: never
|
|
28
30
|
: never;
|
|
29
31
|
};
|
|
32
|
+
|
|
33
|
+
// /**
|
|
34
|
+
// * Use to describe a route path which matches a given route's interface
|
|
35
|
+
// */
|
|
36
|
+
// export type RouterLike<TRouter extends AnyRouter> = RouterLikeInner<
|
|
37
|
+
// TRouter['_def']['_config']['$types'],
|
|
38
|
+
// TRouter['_def']['procedures']
|
|
39
|
+
// >;
|
|
40
|
+
// export type RouterLikeInner<
|
|
41
|
+
// TRoot extends AnyRootTypes,
|
|
42
|
+
// TRecord extends RouterRecord,
|
|
43
|
+
// > = DecorateRouterRecord<TRoot, TRecord>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { DecoratedProcedureUtilsRecord } from '../proxy/utilsProxy';
|
|
1
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
+
import type { DecoratedProcedureUtilsRecord } from '../proxy/utilsProxy';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Use to describe a Utils/Context path which matches the given route's interface
|
|
6
6
|
*/
|
|
7
7
|
export type UtilsLike<TRouter extends AnyRouter> =
|
|
8
|
-
DecoratedProcedureUtilsRecord<
|
|
8
|
+
DecoratedProcedureUtilsRecord<
|
|
9
|
+
TRouter['_def']['_config']['$types'],
|
|
10
|
+
TRouter['_def']['record']
|
|
11
|
+
>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AnyRouter } from '@trpc/server';
|
|
2
|
-
import { createRecursiveProxy } from '@trpc/server/
|
|
3
|
-
import { CreateReactQueryHooks } from '../hooks/createHooksInternal';
|
|
1
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
2
|
+
import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
+
import type { CreateReactQueryHooks } from '../hooks/createHooksInternal';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Create proxy for decorating procedures
|
|
@@ -1,50 +1,84 @@
|
|
|
1
|
-
import { QueryOptions } from '@tanstack/react-query';
|
|
2
|
-
import { TRPCClientError, TRPCUntypedClient } from '@trpc/client';
|
|
3
|
-
import {
|
|
1
|
+
import type { QueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { TRPCClientError, TRPCUntypedClient } from '@trpc/client';
|
|
3
|
+
import type {
|
|
4
4
|
AnyProcedure,
|
|
5
5
|
AnyQueryProcedure,
|
|
6
|
-
|
|
6
|
+
AnyRootTypes,
|
|
7
7
|
AnyRouter,
|
|
8
|
-
Filter,
|
|
9
8
|
inferProcedureInput,
|
|
10
|
-
} from '@trpc/server';
|
|
11
|
-
import {
|
|
12
|
-
createRecursiveProxy,
|
|
13
9
|
inferTransformedProcedureOutput,
|
|
14
|
-
|
|
10
|
+
RouterRecord,
|
|
11
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
12
|
+
import { createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
15
13
|
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
|
16
|
-
import {
|
|
17
|
-
|
|
14
|
+
import type {
|
|
15
|
+
TrpcQueryOptionsForUseQueries,
|
|
16
|
+
TrpcQueryOptionsForUseSuspenseQueries,
|
|
17
|
+
} from '../../internals/useQueries';
|
|
18
|
+
import type { TRPCUseQueryBaseOptions } from '../hooks/types';
|
|
18
19
|
|
|
19
20
|
type GetQueryOptions<
|
|
20
|
-
|
|
21
|
+
TRoot extends AnyRootTypes,
|
|
21
22
|
TProcedure extends AnyProcedure,
|
|
22
|
-
> = <TData = inferTransformedProcedureOutput<
|
|
23
|
+
> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(
|
|
23
24
|
input: inferProcedureInput<TProcedure>,
|
|
24
25
|
opts?: TrpcQueryOptionsForUseQueries<
|
|
25
|
-
inferTransformedProcedureOutput<
|
|
26
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
26
27
|
TData,
|
|
27
|
-
TRPCClientError<
|
|
28
|
+
TRPCClientError<TRoot>
|
|
28
29
|
>,
|
|
29
30
|
) => TrpcQueryOptionsForUseQueries<
|
|
30
|
-
inferTransformedProcedureOutput<
|
|
31
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
31
32
|
TData,
|
|
32
|
-
TRPCClientError<
|
|
33
|
+
TRPCClientError<TRoot>
|
|
33
34
|
>;
|
|
34
35
|
|
|
35
36
|
/**
|
|
36
37
|
* @internal
|
|
37
38
|
*/
|
|
38
|
-
export type UseQueriesProcedureRecord<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
?
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
39
|
+
export type UseQueriesProcedureRecord<
|
|
40
|
+
TRoot extends AnyRootTypes,
|
|
41
|
+
TRecord extends RouterRecord,
|
|
42
|
+
> = {
|
|
43
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
44
|
+
? $Value extends RouterRecord
|
|
45
|
+
? UseQueriesProcedureRecord<TRoot, $Value>
|
|
46
|
+
: $Value extends AnyQueryProcedure
|
|
47
|
+
? GetQueryOptions<TRoot, $Value>
|
|
48
|
+
: never
|
|
49
|
+
: never;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
type GetSuspenseQueryOptions<
|
|
53
|
+
TRoot extends AnyRootTypes,
|
|
54
|
+
TProcedure extends AnyQueryProcedure,
|
|
55
|
+
> = <TData = inferTransformedProcedureOutput<TRoot, TProcedure>>(
|
|
56
|
+
input: inferProcedureInput<TProcedure>,
|
|
57
|
+
opts?: TrpcQueryOptionsForUseSuspenseQueries<
|
|
58
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
59
|
+
TData,
|
|
60
|
+
TRPCClientError<TRoot>
|
|
61
|
+
>,
|
|
62
|
+
) => TrpcQueryOptionsForUseSuspenseQueries<
|
|
63
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
64
|
+
TData,
|
|
65
|
+
TRPCClientError<TRoot>
|
|
66
|
+
>;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @internal
|
|
70
|
+
*/
|
|
71
|
+
export type UseSuspenseQueriesProcedureRecord<
|
|
72
|
+
TRoot extends AnyRootTypes,
|
|
73
|
+
TRecord extends RouterRecord,
|
|
74
|
+
> = {
|
|
75
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
76
|
+
? $Value extends RouterRecord
|
|
77
|
+
? UseSuspenseQueriesProcedureRecord<TRoot, $Value>
|
|
78
|
+
: $Value extends AnyQueryProcedure
|
|
79
|
+
? GetSuspenseQueryOptions<TRoot, $Value>
|
|
80
|
+
: never
|
|
81
|
+
: never;
|
|
48
82
|
};
|
|
49
83
|
|
|
50
84
|
/**
|
|
@@ -71,5 +105,8 @@ export function createUseQueries<TRouter extends AnyRouter>(
|
|
|
71
105
|
};
|
|
72
106
|
|
|
73
107
|
return options;
|
|
74
|
-
}) as UseQueriesProcedureRecord<
|
|
108
|
+
}) as UseQueriesProcedureRecord<
|
|
109
|
+
TRouter['_def']['_config']['$types'],
|
|
110
|
+
TRouter['_def']['record']
|
|
111
|
+
>;
|
|
75
112
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type {
|
|
2
2
|
CancelOptions,
|
|
3
3
|
InfiniteData,
|
|
4
4
|
InvalidateOptions,
|
|
@@ -10,37 +10,36 @@ import {
|
|
|
10
10
|
SetDataOptions,
|
|
11
11
|
Updater,
|
|
12
12
|
} from '@tanstack/react-query';
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
13
|
+
import type { TRPCClientError } from '@trpc/client';
|
|
14
|
+
import { createTRPCClientProxy } from '@trpc/client';
|
|
15
|
+
import type {
|
|
15
16
|
AnyQueryProcedure,
|
|
16
|
-
|
|
17
|
+
AnyRootTypes,
|
|
17
18
|
AnyRouter,
|
|
18
19
|
DeepPartial,
|
|
19
|
-
Filter,
|
|
20
20
|
inferProcedureInput,
|
|
21
|
+
inferTransformedProcedureOutput,
|
|
21
22
|
ProtectedIntersection,
|
|
22
|
-
|
|
23
|
+
RouterRecord,
|
|
24
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
23
25
|
import {
|
|
24
26
|
createFlatProxy,
|
|
25
27
|
createRecursiveProxy,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
import {
|
|
29
|
-
contextProps,
|
|
28
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
29
|
+
import type {
|
|
30
30
|
DecoratedTRPCContextProps,
|
|
31
31
|
TRPCContextState,
|
|
32
32
|
TRPCFetchInfiniteQueryOptions,
|
|
33
33
|
TRPCFetchQueryOptions,
|
|
34
|
+
TRPCQueryUtils,
|
|
34
35
|
} from '../../internals/context';
|
|
35
|
-
import {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
} from '../../internals/getQueryKey';
|
|
40
|
-
import { ExtractCursorType } from '../hooks/types';
|
|
36
|
+
import { contextProps } from '../../internals/context';
|
|
37
|
+
import type { QueryKeyKnown, QueryType } from '../../internals/getQueryKey';
|
|
38
|
+
import { getQueryKeyInternal } from '../../internals/getQueryKey';
|
|
39
|
+
import type { ExtractCursorType } from '../hooks/types';
|
|
41
40
|
|
|
42
41
|
type DecorateProcedure<
|
|
43
|
-
|
|
42
|
+
TRoot extends AnyRootTypes,
|
|
44
43
|
TProcedure extends AnyQueryProcedure,
|
|
45
44
|
> = {
|
|
46
45
|
/**
|
|
@@ -49,10 +48,10 @@ type DecorateProcedure<
|
|
|
49
48
|
fetch(
|
|
50
49
|
input: inferProcedureInput<TProcedure>,
|
|
51
50
|
opts?: TRPCFetchQueryOptions<
|
|
52
|
-
inferTransformedProcedureOutput<
|
|
53
|
-
TRPCClientError<
|
|
51
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
52
|
+
TRPCClientError<TRoot>
|
|
54
53
|
>,
|
|
55
|
-
): Promise<inferTransformedProcedureOutput<
|
|
54
|
+
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
57
|
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchinfinitequery
|
|
@@ -61,12 +60,12 @@ type DecorateProcedure<
|
|
|
61
60
|
input: inferProcedureInput<TProcedure>,
|
|
62
61
|
opts?: TRPCFetchInfiniteQueryOptions<
|
|
63
62
|
inferProcedureInput<TProcedure>,
|
|
64
|
-
inferTransformedProcedureOutput<
|
|
65
|
-
TRPCClientError<
|
|
63
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
64
|
+
TRPCClientError<TRoot>
|
|
66
65
|
>,
|
|
67
66
|
): Promise<
|
|
68
67
|
InfiniteData<
|
|
69
|
-
inferTransformedProcedureOutput<
|
|
68
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
70
69
|
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
71
70
|
>
|
|
72
71
|
>;
|
|
@@ -77,8 +76,8 @@ type DecorateProcedure<
|
|
|
77
76
|
prefetch(
|
|
78
77
|
input: inferProcedureInput<TProcedure>,
|
|
79
78
|
opts?: TRPCFetchQueryOptions<
|
|
80
|
-
inferTransformedProcedureOutput<
|
|
81
|
-
TRPCClientError<
|
|
79
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
80
|
+
TRPCClientError<TRoot>
|
|
82
81
|
>,
|
|
83
82
|
): Promise<void>;
|
|
84
83
|
|
|
@@ -89,21 +88,21 @@ type DecorateProcedure<
|
|
|
89
88
|
input: inferProcedureInput<TProcedure>,
|
|
90
89
|
opts?: TRPCFetchInfiniteQueryOptions<
|
|
91
90
|
inferProcedureInput<TProcedure>,
|
|
92
|
-
inferTransformedProcedureOutput<
|
|
93
|
-
TRPCClientError<
|
|
91
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
92
|
+
TRPCClientError<TRoot>
|
|
94
93
|
>,
|
|
95
94
|
): Promise<void>;
|
|
96
95
|
|
|
97
96
|
/**
|
|
98
|
-
* @link https://tanstack.com/query/v5/docs/
|
|
97
|
+
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientensurequerydata
|
|
99
98
|
*/
|
|
100
99
|
ensureData(
|
|
101
100
|
input: inferProcedureInput<TProcedure>,
|
|
102
101
|
opts?: TRPCFetchQueryOptions<
|
|
103
|
-
inferTransformedProcedureOutput<
|
|
104
|
-
TRPCClientError<
|
|
102
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
103
|
+
TRPCClientError<TRoot>
|
|
105
104
|
>,
|
|
106
|
-
): Promise<inferTransformedProcedureOutput<
|
|
105
|
+
): Promise<inferTransformedProcedureOutput<TRoot, TProcedure>>;
|
|
107
106
|
|
|
108
107
|
/**
|
|
109
108
|
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientinvalidatequeries
|
|
@@ -114,7 +113,7 @@ type DecorateProcedure<
|
|
|
114
113
|
predicate?: (
|
|
115
114
|
query: Query<
|
|
116
115
|
inferProcedureInput<TProcedure>,
|
|
117
|
-
TRPCClientError<
|
|
116
|
+
TRPCClientError<TRoot>,
|
|
118
117
|
inferProcedureInput<TProcedure>,
|
|
119
118
|
QueryKeyKnown<
|
|
120
119
|
inferProcedureInput<TProcedure>,
|
|
@@ -162,8 +161,8 @@ type DecorateProcedure<
|
|
|
162
161
|
*/
|
|
163
162
|
input: inferProcedureInput<TProcedure>,
|
|
164
163
|
updater: Updater<
|
|
165
|
-
inferTransformedProcedureOutput<
|
|
166
|
-
inferTransformedProcedureOutput<
|
|
164
|
+
inferTransformedProcedureOutput<TRoot, TProcedure> | undefined,
|
|
165
|
+
inferTransformedProcedureOutput<TRoot, TProcedure> | undefined
|
|
167
166
|
>,
|
|
168
167
|
options?: SetDataOptions,
|
|
169
168
|
): void;
|
|
@@ -175,12 +174,12 @@ type DecorateProcedure<
|
|
|
175
174
|
input: inferProcedureInput<TProcedure>,
|
|
176
175
|
updater: Updater<
|
|
177
176
|
| InfiniteData<
|
|
178
|
-
inferTransformedProcedureOutput<
|
|
177
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
179
178
|
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
180
179
|
>
|
|
181
180
|
| undefined,
|
|
182
181
|
| InfiniteData<
|
|
183
|
-
inferTransformedProcedureOutput<
|
|
182
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
184
183
|
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
185
184
|
>
|
|
186
185
|
| undefined
|
|
@@ -193,7 +192,7 @@ type DecorateProcedure<
|
|
|
193
192
|
*/
|
|
194
193
|
getData(
|
|
195
194
|
input?: inferProcedureInput<TProcedure>,
|
|
196
|
-
): inferTransformedProcedureOutput<
|
|
195
|
+
): inferTransformedProcedureOutput<TRoot, TProcedure> | undefined;
|
|
197
196
|
|
|
198
197
|
/**
|
|
199
198
|
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
@@ -202,7 +201,7 @@ type DecorateProcedure<
|
|
|
202
201
|
input?: inferProcedureInput<TProcedure>,
|
|
203
202
|
):
|
|
204
203
|
| InfiniteData<
|
|
205
|
-
inferTransformedProcedureOutput<
|
|
204
|
+
inferTransformedProcedureOutput<TRoot, TProcedure>,
|
|
206
205
|
NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null
|
|
207
206
|
>
|
|
208
207
|
| undefined;
|
|
@@ -216,7 +215,7 @@ type DecorateRouter = {
|
|
|
216
215
|
/**
|
|
217
216
|
* Invalidate the full router
|
|
218
217
|
* @link https://trpc.io/docs/v10/useContext#query-invalidation
|
|
219
|
-
* @link https://tanstack.com/query/v5/docs/react/guides/query-invalidation
|
|
218
|
+
* @link https://tanstack.com/query/v5/docs/framework/react/guides/query-invalidation
|
|
220
219
|
*/
|
|
221
220
|
invalidate(
|
|
222
221
|
input?: undefined,
|
|
@@ -228,20 +227,19 @@ type DecorateRouter = {
|
|
|
228
227
|
/**
|
|
229
228
|
* @internal
|
|
230
229
|
*/
|
|
231
|
-
export type DecoratedProcedureUtilsRecord<
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
? DecoratedProcedureUtilsRecord<
|
|
238
|
-
DecorateRouter
|
|
230
|
+
export type DecoratedProcedureUtilsRecord<
|
|
231
|
+
TRoot extends AnyRootTypes,
|
|
232
|
+
TRecord extends RouterRecord,
|
|
233
|
+
> = DecorateRouter & {
|
|
234
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
235
|
+
? $Value extends RouterRecord
|
|
236
|
+
? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter
|
|
239
237
|
: // utils only apply to queries
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
238
|
+
$Value extends AnyQueryProcedure
|
|
239
|
+
? DecorateProcedure<TRoot, $Value>
|
|
240
|
+
: never
|
|
241
|
+
: never;
|
|
242
|
+
}; // Add functions that should be available at utils root
|
|
245
243
|
|
|
246
244
|
type AnyDecoratedProcedure = DecorateProcedure<any, any>;
|
|
247
245
|
|
|
@@ -250,9 +248,18 @@ export type CreateReactUtils<
|
|
|
250
248
|
TSSRContext,
|
|
251
249
|
> = ProtectedIntersection<
|
|
252
250
|
DecoratedTRPCContextProps<TRouter, TSSRContext>,
|
|
253
|
-
DecoratedProcedureUtilsRecord<
|
|
251
|
+
DecoratedProcedureUtilsRecord<
|
|
252
|
+
TRouter['_def']['_config']['$types'],
|
|
253
|
+
TRouter['_def']['record']
|
|
254
|
+
>
|
|
254
255
|
>;
|
|
255
256
|
|
|
257
|
+
export type CreateQueryUtils<TRouter extends AnyRouter> =
|
|
258
|
+
DecoratedProcedureUtilsRecord<
|
|
259
|
+
TRouter['_def']['_config']['$types'],
|
|
260
|
+
TRouter['_def']['record']
|
|
261
|
+
>;
|
|
262
|
+
|
|
256
263
|
export const getQueryType = (
|
|
257
264
|
utilName: keyof AnyDecoratedProcedure,
|
|
258
265
|
): QueryType => {
|
|
@@ -278,11 +285,52 @@ export const getQueryType = (
|
|
|
278
285
|
}
|
|
279
286
|
};
|
|
280
287
|
|
|
288
|
+
/**
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
|
|
292
|
+
context: TRPCQueryUtils<TRouter>,
|
|
293
|
+
key: string,
|
|
294
|
+
) {
|
|
295
|
+
return createRecursiveProxy((opts) => {
|
|
296
|
+
const path = [key, ...opts.path];
|
|
297
|
+
const utilName = path.pop() as keyof AnyDecoratedProcedure;
|
|
298
|
+
const args = [...opts.args] as Parameters<
|
|
299
|
+
AnyDecoratedProcedure[typeof utilName]
|
|
300
|
+
>;
|
|
301
|
+
const input = args.shift(); // args can now be spread when input removed
|
|
302
|
+
const queryType = getQueryType(utilName);
|
|
303
|
+
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
304
|
+
|
|
305
|
+
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
|
306
|
+
fetch: () => context.fetchQuery(queryKey, ...args),
|
|
307
|
+
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
|
308
|
+
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
|
309
|
+
prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
|
|
310
|
+
ensureData: () => context.ensureQueryData(queryKey, ...args),
|
|
311
|
+
invalidate: () => context.invalidateQueries(queryKey, ...args),
|
|
312
|
+
reset: () => context.resetQueries(queryKey, ...args),
|
|
313
|
+
refetch: () => context.refetchQueries(queryKey, ...args),
|
|
314
|
+
cancel: () => context.cancelQuery(queryKey, ...args),
|
|
315
|
+
setData: () => {
|
|
316
|
+
context.setQueryData(queryKey, args[0], args[1]);
|
|
317
|
+
},
|
|
318
|
+
setInfiniteData: () => {
|
|
319
|
+
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
|
320
|
+
},
|
|
321
|
+
getData: () => context.getQueryData(queryKey),
|
|
322
|
+
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
return contextMap[utilName]();
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
|
|
281
329
|
/**
|
|
282
330
|
* @internal
|
|
283
331
|
*/
|
|
284
332
|
export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
|
|
285
|
-
context: TRPCContextState<AnyRouter,
|
|
333
|
+
context: TRPCContextState<AnyRouter, TSSRContext>,
|
|
286
334
|
) {
|
|
287
335
|
type CreateReactUtilsReturnType = CreateReactUtils<TRouter, TSSRContext>;
|
|
288
336
|
|
|
@@ -295,38 +343,17 @@ export function createReactQueryUtils<TRouter extends AnyRouter, TSSRContext>(
|
|
|
295
343
|
return context[contextName];
|
|
296
344
|
}
|
|
297
345
|
|
|
298
|
-
return
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const args = [...opts.args] as Parameters<
|
|
302
|
-
AnyDecoratedProcedure[typeof utilName]
|
|
303
|
-
>;
|
|
304
|
-
const input = args.shift(); // args can now be spread when input removed
|
|
305
|
-
const queryType = getQueryType(utilName);
|
|
306
|
-
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
307
|
-
|
|
308
|
-
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
|
309
|
-
fetch: () => context.fetchQuery(queryKey, ...args),
|
|
310
|
-
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
|
311
|
-
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
|
312
|
-
prefetchInfinite: () =>
|
|
313
|
-
context.prefetchInfiniteQuery(queryKey, args[0]),
|
|
314
|
-
ensureData: () => context.ensureQueryData(queryKey, ...args),
|
|
315
|
-
invalidate: () => context.invalidateQueries(queryKey, ...args),
|
|
316
|
-
reset: () => context.resetQueries(queryKey, ...args),
|
|
317
|
-
refetch: () => context.refetchQueries(queryKey, ...args),
|
|
318
|
-
cancel: () => context.cancelQuery(queryKey, ...args),
|
|
319
|
-
setData: () => {
|
|
320
|
-
context.setQueryData(queryKey, args[0], args[1]);
|
|
321
|
-
},
|
|
322
|
-
setInfiniteData: () => {
|
|
323
|
-
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
|
324
|
-
},
|
|
325
|
-
getData: () => context.getQueryData(queryKey),
|
|
326
|
-
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
|
327
|
-
};
|
|
346
|
+
return createRecursiveUtilsProxy(context, key);
|
|
347
|
+
});
|
|
348
|
+
}
|
|
328
349
|
|
|
329
|
-
|
|
330
|
-
|
|
350
|
+
/**
|
|
351
|
+
* @internal
|
|
352
|
+
*/
|
|
353
|
+
export function createQueryUtilsProxy<TRouter extends AnyRouter>(
|
|
354
|
+
context: TRPCQueryUtils<TRouter>,
|
|
355
|
+
): CreateQueryUtils<TRouter> {
|
|
356
|
+
return createFlatProxy((key) => {
|
|
357
|
+
return createRecursiveUtilsProxy(context, key);
|
|
331
358
|
});
|
|
332
359
|
}
|
package/src/shared/types.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
1
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type {
|
|
3
|
+
AnyRouter,
|
|
4
|
+
MaybePromise,
|
|
5
|
+
} from '@trpc/server/unstable-core-do-not-import';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* @internal
|