@trpc/react-query 11.0.0-rc.458 → 11.0.0-rc.459
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 +46 -44
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -1
- package/dist/internals/context.d.ts +18 -2
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts +8 -0
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/getQueryKey.js +15 -0
- package/dist/internals/getQueryKey.mjs +14 -1
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createHooksInternal.js +1 -3
- package/dist/shared/hooks/createHooksInternal.mjs +2 -4
- package/dist/shared/proxy/utilsProxy.d.ts +12 -4
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +14 -2
- package/dist/shared/proxy/utilsProxy.mjs +15 -3
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.js +23 -0
- package/dist/utils/createUtilityFunctions.mjs +23 -0
- package/package.json +6 -6
- package/src/index.ts +1 -1
- package/src/internals/context.tsx +26 -1
- package/src/internals/getQueryKey.ts +21 -0
- package/src/shared/hooks/createHooksInternal.tsx +5 -2
- package/src/shared/proxy/utilsProxy.ts +47 -6
- package/src/utils/createUtilityFunctions.ts +26 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"bundleSize":
|
|
3
|
-
"bundleOrigSize":
|
|
4
|
-
"bundleReduction": 52.
|
|
2
|
+
"bundleSize": 34573,
|
|
3
|
+
"bundleOrigSize": 72829,
|
|
4
|
+
"bundleReduction": 52.53,
|
|
5
5
|
"modules": [
|
|
6
6
|
{
|
|
7
7
|
"id": "/src/shared/hooks/createHooksInternal.tsx",
|
|
8
|
-
"size":
|
|
9
|
-
"origSize":
|
|
8
|
+
"size": 13979,
|
|
9
|
+
"origSize": 15929,
|
|
10
10
|
"renderedExports": [
|
|
11
11
|
"createRootHooks"
|
|
12
12
|
],
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
"dependents": [
|
|
15
15
|
"/src/createTRPCReact.tsx"
|
|
16
16
|
],
|
|
17
|
-
"percent":
|
|
18
|
-
"reduction": 12.
|
|
17
|
+
"percent": 40.43,
|
|
18
|
+
"reduction": 12.24
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
21
|
"id": "/src/utils/createUtilityFunctions.ts",
|
|
22
|
-
"size":
|
|
23
|
-
"origSize":
|
|
22
|
+
"size": 4612,
|
|
23
|
+
"origSize": 4721,
|
|
24
24
|
"renderedExports": [
|
|
25
25
|
"createUtilityFunctions"
|
|
26
26
|
],
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"/src/createTRPCQueryUtils.tsx",
|
|
30
30
|
"/src/shared/hooks/createHooksInternal.tsx"
|
|
31
31
|
],
|
|
32
|
-
"percent":
|
|
33
|
-
"reduction":
|
|
32
|
+
"percent": 13.34,
|
|
33
|
+
"reduction": 2.31
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
36
|
"id": "/src/server/ssgProxy.ts",
|
|
@@ -43,25 +43,13 @@
|
|
|
43
43
|
"dependents": [
|
|
44
44
|
"/src/server/index.ts"
|
|
45
45
|
],
|
|
46
|
-
"percent": 10.
|
|
46
|
+
"percent": 10.08,
|
|
47
47
|
"reduction": 52.58
|
|
48
48
|
},
|
|
49
|
-
{
|
|
50
|
-
"id": "/src/rsc.tsx",
|
|
51
|
-
"size": 3232,
|
|
52
|
-
"origSize": 5356,
|
|
53
|
-
"renderedExports": [
|
|
54
|
-
"createHydrationHelpers"
|
|
55
|
-
],
|
|
56
|
-
"removedExports": [],
|
|
57
|
-
"dependents": [],
|
|
58
|
-
"percent": 9.89,
|
|
59
|
-
"reduction": 39.66
|
|
60
|
-
},
|
|
61
49
|
{
|
|
62
50
|
"id": "/src/shared/proxy/utilsProxy.ts",
|
|
63
|
-
"size":
|
|
64
|
-
"origSize":
|
|
51
|
+
"size": 3392,
|
|
52
|
+
"origSize": 12511,
|
|
65
53
|
"renderedExports": [
|
|
66
54
|
"getQueryType",
|
|
67
55
|
"createReactQueryUtils",
|
|
@@ -71,16 +59,30 @@
|
|
|
71
59
|
"dependents": [
|
|
72
60
|
"/src/shared/index.ts"
|
|
73
61
|
],
|
|
74
|
-
"percent":
|
|
75
|
-
"reduction":
|
|
62
|
+
"percent": 9.81,
|
|
63
|
+
"reduction": 72.89
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
"id": "/src/rsc.tsx",
|
|
67
|
+
"size": 3232,
|
|
68
|
+
"origSize": 5356,
|
|
69
|
+
"renderedExports": [
|
|
70
|
+
"createHydrationHelpers"
|
|
71
|
+
],
|
|
72
|
+
"removedExports": [],
|
|
73
|
+
"dependents": [],
|
|
74
|
+
"percent": 9.35,
|
|
75
|
+
"reduction": 39.66
|
|
76
76
|
},
|
|
77
77
|
{
|
|
78
78
|
"id": "/src/internals/getQueryKey.ts",
|
|
79
|
-
"size":
|
|
80
|
-
"origSize":
|
|
79
|
+
"size": 2506,
|
|
80
|
+
"origSize": 4191,
|
|
81
81
|
"renderedExports": [
|
|
82
82
|
"getQueryKeyInternal",
|
|
83
|
-
"
|
|
83
|
+
"getMutationKeyInternal",
|
|
84
|
+
"getQueryKey",
|
|
85
|
+
"getMutationKey"
|
|
84
86
|
],
|
|
85
87
|
"removedExports": [],
|
|
86
88
|
"dependents": [
|
|
@@ -91,8 +93,8 @@
|
|
|
91
93
|
"/src/shared/proxy/useQueriesProxy.ts",
|
|
92
94
|
"/src/shared/hooks/createHooksInternal.tsx"
|
|
93
95
|
],
|
|
94
|
-
"percent":
|
|
95
|
-
"reduction":
|
|
96
|
+
"percent": 7.25,
|
|
97
|
+
"reduction": 40.21
|
|
96
98
|
},
|
|
97
99
|
{
|
|
98
100
|
"id": "/src/createTRPCReact.tsx",
|
|
@@ -106,7 +108,7 @@
|
|
|
106
108
|
"dependents": [
|
|
107
109
|
"/src/index.ts"
|
|
108
110
|
],
|
|
109
|
-
"percent": 2.
|
|
111
|
+
"percent": 2.53,
|
|
110
112
|
"reduction": 89.53
|
|
111
113
|
},
|
|
112
114
|
{
|
|
@@ -120,7 +122,7 @@
|
|
|
120
122
|
"dependents": [
|
|
121
123
|
"/src/shared/index.ts"
|
|
122
124
|
],
|
|
123
|
-
"percent": 2.
|
|
125
|
+
"percent": 2.26,
|
|
124
126
|
"reduction": 24
|
|
125
127
|
},
|
|
126
128
|
{
|
|
@@ -135,7 +137,7 @@
|
|
|
135
137
|
"/src/shared/index.ts",
|
|
136
138
|
"/src/shared/hooks/createHooksInternal.tsx"
|
|
137
139
|
],
|
|
138
|
-
"percent": 1.
|
|
140
|
+
"percent": 1.65,
|
|
139
141
|
"reduction": 82.1
|
|
140
142
|
},
|
|
141
143
|
{
|
|
@@ -151,7 +153,7 @@
|
|
|
151
153
|
"/src/shared/hooks/createHooksInternal.tsx",
|
|
152
154
|
"/src/utils/createUtilityFunctions.ts"
|
|
153
155
|
],
|
|
154
|
-
"percent": 1.
|
|
156
|
+
"percent": 1.37,
|
|
155
157
|
"reduction": 17.31
|
|
156
158
|
},
|
|
157
159
|
{
|
|
@@ -165,7 +167,7 @@
|
|
|
165
167
|
"dependents": [
|
|
166
168
|
"/src/shared/hooks/createHooksInternal.tsx"
|
|
167
169
|
],
|
|
168
|
-
"percent": 0.
|
|
170
|
+
"percent": 0.64,
|
|
169
171
|
"reduction": 37.82
|
|
170
172
|
},
|
|
171
173
|
{
|
|
@@ -179,13 +181,13 @@
|
|
|
179
181
|
"dependents": [
|
|
180
182
|
"/src/index.ts"
|
|
181
183
|
],
|
|
182
|
-
"percent": 0.
|
|
184
|
+
"percent": 0.47,
|
|
183
185
|
"reduction": 66.6
|
|
184
186
|
},
|
|
185
187
|
{
|
|
186
188
|
"id": "/src/internals/context.tsx",
|
|
187
189
|
"size": 154,
|
|
188
|
-
"origSize":
|
|
190
|
+
"origSize": 7157,
|
|
189
191
|
"renderedExports": [
|
|
190
192
|
"contextProps",
|
|
191
193
|
"TRPCContext"
|
|
@@ -197,8 +199,8 @@
|
|
|
197
199
|
"/src/shared/proxy/utilsProxy.ts",
|
|
198
200
|
"/src/shared/hooks/createHooksInternal.tsx"
|
|
199
201
|
],
|
|
200
|
-
"percent": 0.
|
|
201
|
-
"reduction": 97.
|
|
202
|
+
"percent": 0.45,
|
|
203
|
+
"reduction": 97.85
|
|
202
204
|
},
|
|
203
205
|
{
|
|
204
206
|
"id": "/src/shared/queryClient.ts",
|
|
@@ -211,13 +213,13 @@
|
|
|
211
213
|
"dependents": [
|
|
212
214
|
"/src/shared/index.ts"
|
|
213
215
|
],
|
|
214
|
-
"percent": 0.
|
|
216
|
+
"percent": 0.37,
|
|
215
217
|
"reduction": 74.9
|
|
216
218
|
},
|
|
217
219
|
{
|
|
218
220
|
"id": "/src/index.ts",
|
|
219
221
|
"size": 0,
|
|
220
|
-
"origSize":
|
|
222
|
+
"origSize": 362,
|
|
221
223
|
"renderedExports": [],
|
|
222
224
|
"removedExports": [],
|
|
223
225
|
"dependents": [],
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from '@trpc/client';
|
|
2
|
-
export { getQueryKey } from './internals/getQueryKey';
|
|
2
|
+
export { getQueryKey, getMutationKey } from './internals/getQueryKey';
|
|
3
3
|
export { createTRPCReact, type CreateTRPCReact, type CreateTRPCReactBase, } from './createTRPCReact';
|
|
4
4
|
export type { inferReactQueryProcedureOptions } from './utils/inferReactQueryProcedure';
|
|
5
5
|
export { createTRPCQueryUtils } from './createTRPCQueryUtils';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACtE,OAAO,EACL,eAAe,EACf,KAAK,eAAe,EACpB,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,YAAY,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACxF,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,7 @@ var createTRPCQueryUtils = require('./createTRPCQueryUtils.js');
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
|
+
exports.getMutationKey = getQueryKey.getMutationKey;
|
|
10
11
|
exports.getQueryKey = getQueryKey.getQueryKey;
|
|
11
12
|
exports.createTRPCReact = createTRPCReact.createTRPCReact;
|
|
12
13
|
exports.createTRPCQueryUtils = createTRPCQueryUtils.createTRPCQueryUtils;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from '@trpc/client';
|
|
2
|
-
export { getQueryKey } from './internals/getQueryKey.mjs';
|
|
2
|
+
export { getMutationKey, getQueryKey } from './internals/getQueryKey.mjs';
|
|
3
3
|
export { createTRPCReact } from './createTRPCReact.mjs';
|
|
4
4
|
export { createTRPCQueryUtils } from './createTRPCQueryUtils.mjs';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { CancelOptions, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, QueryClient, QueryFilters, QueryKey, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
|
|
1
|
+
import type { CancelOptions, FetchInfiniteQueryOptions, FetchQueryOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, MutationOptions, QueryClient, QueryFilters, QueryKey, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
|
|
2
2
|
import type { CreateTRPCClient, TRPCClientError, TRPCRequestOptions, TRPCUntypedClient } from '@trpc/client';
|
|
3
3
|
import type { AnyRouter, DistributiveOmit } from '@trpc/server/unstable-core-do-not-import';
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import type { ExtractCursorType } from '../shared';
|
|
6
|
-
import type { TRPCQueryKey } from './getQueryKey';
|
|
6
|
+
import type { TRPCMutationKey, TRPCQueryKey } from './getQueryKey';
|
|
7
7
|
export type TRPCFetchQueryOptions<TOutput, TError> = DistributiveOmit<FetchQueryOptions<TOutput, TError>, 'queryKey'> & TRPCRequestOptions;
|
|
8
8
|
export type TRPCFetchInfiniteQueryOptions<TInput, TOutput, TError> = DistributiveOmit<FetchInfiniteQueryOptions<TOutput, TError, TOutput, TRPCQueryKey, ExtractCursorType<TInput>>, 'queryKey' | 'initialPageParam'> & TRPCRequestOptions & {
|
|
9
9
|
initialCursor?: ExtractCursorType<TInput>;
|
|
@@ -114,6 +114,22 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
|
|
114
114
|
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientgetquerydata
|
|
115
115
|
*/
|
|
116
116
|
getInfiniteQueryData: (queryKey: TRPCQueryKey) => InfiniteData<unknown> | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* @link https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
|
|
119
|
+
*/
|
|
120
|
+
setMutationDefaults: (mutationKey: TRPCMutationKey, options: MutationOptions | ((args: {
|
|
121
|
+
canonicalMutationFn: (input: unknown) => Promise<unknown>;
|
|
122
|
+
}) => MutationOptions)) => void;
|
|
123
|
+
/**
|
|
124
|
+
* @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
|
|
125
|
+
*/
|
|
126
|
+
getMutationDefaults: (mutationKey: TRPCMutationKey) => MutationOptions | undefined;
|
|
127
|
+
/**
|
|
128
|
+
* @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
|
|
129
|
+
*/
|
|
130
|
+
isMutating: (filters: {
|
|
131
|
+
mutationKey: TRPCMutationKey;
|
|
132
|
+
}) => number;
|
|
117
133
|
}
|
|
118
134
|
export declare const TRPCContext: React.Context<any>;
|
|
119
135
|
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/internals/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,OAAO,EACR,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EACjB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/internals/context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,yBAAyB,EACzB,iBAAiB,EACjB,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,YAAY,EAC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O,EAAE,OAAO,CAAC,EAClC,OAAO,CAAC,EAAE,cAAc,KACrB,CAAC,QAAQ,EAAE,OAAO,CAAC,EAAE,CAAC;IAE3B;;OAEG;IACH,YAAY,EAAE,CAAC,QAAQ,EAAE,YAAY,KAAK,OAAO,CAAC;IAElD;;OAEG;IACH,oBAAoB,EAAE,CACpB,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,OAAO,CACd,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,EACjC,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAClC,EACD,OAAO,CAAC,EAAE,cAAc,KACrB,IAAI,CAAC;IAEV;;OAEG;IACH,oBAAoB,EAAE,CACpB,QAAQ,EAAE,YAAY,KACnB,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAEvC;;OAEG;IACH,mBAAmB,EAAE,CACnB,WAAW,EAAE,eAAe,EAC5B,OAAO,EACH,eAAe,GACf,CAAC,CAAC,IAAI,EAAE;QACN,mBAAmB,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;KAC3D,KAAK,eAAe,CAAC,KACvB,IAAI,CAAC;IAEV;;OAEG;IACH,mBAAmB,EAAE,CACnB,WAAW,EAAE,eAAe,KACzB,eAAe,GAAG,SAAS,CAAC;IAEjC;;OAEG;IACH,UAAU,EAAE,CAAC,OAAO,EAAE;QAAE,WAAW,EAAE,eAAe,CAAA;KAAE,KAAK,MAAM,CAAC;CACnE;AACD,eAAO,MAAM,WAAW,oBAAqC,CAAC"}
|
|
@@ -9,6 +9,7 @@ export type TRPCQueryKey = [
|
|
|
9
9
|
type?: Exclude<QueryType, 'any'>;
|
|
10
10
|
}?
|
|
11
11
|
];
|
|
12
|
+
export type TRPCMutationKey = [readonly string[]];
|
|
12
13
|
type ProcedureOrRouter = DecoratedMutation<any> | DecoratedQuery<any> | DecorateRouterRecord<any, any>;
|
|
13
14
|
/**
|
|
14
15
|
* To allow easy interactions with groups of related queries, such as
|
|
@@ -16,6 +17,7 @@ type ProcedureOrRouter = DecoratedMutation<any> | DecoratedQuery<any> | Decorate
|
|
|
16
17
|
* storing in tanstack query.
|
|
17
18
|
**/
|
|
18
19
|
export declare function getQueryKeyInternal(path: readonly string[], input: unknown, type: QueryType): TRPCQueryKey;
|
|
20
|
+
export declare function getMutationKeyInternal(path: readonly string[]): TRPCMutationKey;
|
|
19
21
|
type GetInfiniteQueryInput<TProcedureInput, TInputWithoutCursorAndDirection = Omit<TProcedureInput, 'cursor' | 'direction'>> = keyof TInputWithoutCursorAndDirection extends never ? undefined : DeepPartial<TInputWithoutCursorAndDirection> | undefined;
|
|
20
22
|
/** @internal */
|
|
21
23
|
export type GetQueryProcedureInput<TProcedureInput> = TProcedureInput extends {
|
|
@@ -37,5 +39,11 @@ export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
|
|
|
37
39
|
type: TType;
|
|
38
40
|
}?
|
|
39
41
|
];
|
|
42
|
+
/**
|
|
43
|
+
* Method to extract the mutation key for a procedure
|
|
44
|
+
* @param procedure - procedure
|
|
45
|
+
* @link https://trpc.io/docs/v11/getQueryKey#mutations
|
|
46
|
+
*/
|
|
47
|
+
export declare function getMutationKey<TProcedure extends DecoratedMutation<any>>(procedure: TProcedure): TRPCMutationKey;
|
|
40
48
|
export {};
|
|
41
49
|
//# sourceMappingURL=getQueryKey.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQueryKey.d.ts","sourceRoot":"","sources":["../../src/internals/getQueryKey.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EACjB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAEtD,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC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AG,CAAC,EACtE,SAAS,EAAE,UAAU,mBAKtB"}
|
|
@@ -14,6 +14,7 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
|
|
|
14
14
|
// some parts of the path may be dot-separated, split them up
|
|
15
15
|
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
16
16
|
if (!input && (!type || type === 'any')) {
|
|
17
|
+
// this matches also all mutations (see `getMutationKeyInternal`)
|
|
17
18
|
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
18
19
|
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
19
20
|
return splitPath.length ? [
|
|
@@ -42,6 +43,9 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
|
|
|
42
43
|
}
|
|
43
44
|
];
|
|
44
45
|
}
|
|
46
|
+
function getMutationKeyInternal(path) {
|
|
47
|
+
return getQueryKeyInternal(path, undefined, 'any');
|
|
48
|
+
}
|
|
45
49
|
/**
|
|
46
50
|
* Method to extract the query key for a procedure
|
|
47
51
|
* @param procedureOrRouter - procedure or AnyRouter
|
|
@@ -55,6 +59,17 @@ var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import'
|
|
|
55
59
|
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
|
56
60
|
return queryKey;
|
|
57
61
|
}
|
|
62
|
+
/**
|
|
63
|
+
* Method to extract the mutation key for a procedure
|
|
64
|
+
* @param procedure - procedure
|
|
65
|
+
* @link https://trpc.io/docs/v11/getQueryKey#mutations
|
|
66
|
+
*/ function getMutationKey(procedure) {
|
|
67
|
+
// @ts-expect-error - we don't expose _def on the type layer
|
|
68
|
+
const path = procedure._def().path;
|
|
69
|
+
return getMutationKeyInternal(path);
|
|
70
|
+
}
|
|
58
71
|
|
|
72
|
+
exports.getMutationKey = getMutationKey;
|
|
73
|
+
exports.getMutationKeyInternal = getMutationKeyInternal;
|
|
59
74
|
exports.getQueryKey = getQueryKey;
|
|
60
75
|
exports.getQueryKeyInternal = getQueryKeyInternal;
|
|
@@ -12,6 +12,7 @@ import { isObject } from '@trpc/server/unstable-core-do-not-import';
|
|
|
12
12
|
// some parts of the path may be dot-separated, split them up
|
|
13
13
|
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
14
14
|
if (!input && (!type || type === 'any')) {
|
|
15
|
+
// this matches also all mutations (see `getMutationKeyInternal`)
|
|
15
16
|
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
16
17
|
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
17
18
|
return splitPath.length ? [
|
|
@@ -40,6 +41,9 @@ import { isObject } from '@trpc/server/unstable-core-do-not-import';
|
|
|
40
41
|
}
|
|
41
42
|
];
|
|
42
43
|
}
|
|
44
|
+
function getMutationKeyInternal(path) {
|
|
45
|
+
return getQueryKeyInternal(path, undefined, 'any');
|
|
46
|
+
}
|
|
43
47
|
/**
|
|
44
48
|
* Method to extract the query key for a procedure
|
|
45
49
|
* @param procedureOrRouter - procedure or AnyRouter
|
|
@@ -53,5 +57,14 @@ import { isObject } from '@trpc/server/unstable-core-do-not-import';
|
|
|
53
57
|
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
|
54
58
|
return queryKey;
|
|
55
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Method to extract the mutation key for a procedure
|
|
62
|
+
* @param procedure - procedure
|
|
63
|
+
* @link https://trpc.io/docs/v11/getQueryKey#mutations
|
|
64
|
+
*/ function getMutationKey(procedure) {
|
|
65
|
+
// @ts-expect-error - we don't expose _def on the type layer
|
|
66
|
+
const path = procedure._def().path;
|
|
67
|
+
return getMutationKeyInternal(path);
|
|
68
|
+
}
|
|
56
69
|
|
|
57
|
-
export { getQueryKey, getQueryKeyInternal };
|
|
70
|
+
export { getMutationKey, getMutationKeyInternal, getQueryKey, getQueryKeyInternal };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAG1E,OAAO,KAAK,EAAY,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAG1E,OAAO,KAAK,EAAY,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAS1E,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,sBAAsB,EAAuB,MAAM,UAAU,CAAC;AAC5E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EAEZ,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC1B,mCAAmC,EACnC,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,MAAM,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC;;;;;qBAmFhC,SAAS,MAAM,EAAE,SAChB,OAAO,SACP,mBAAmB,CAAC,OAAO,EAAE,OAAO,+BAAS,KACnD,kBAAkB,CAAC,OAAO,+BAAS;6BAqF9B,SAAS,MAAM,EAAE,SAChB,OAAO,SACP,2BAA2B,CAAC,OAAO,EAAE,OAAO,+BAAS,KAC3D,0BAA0B,CAAC,OAAO,+BAAS;;;wBAoCtC,SAAS,MAAM,EAAE,SAChB,sBAAsB,CAAC,OAAO,gCAAU,OAAO,EAAE,OAAO,CAAC,KAC/D,qBAAqB,CAAC,OAAO,gCAAU,OAAO,EAAE,OAAO,CAAC;4BAwCnD,SAAS,MAAM,EAAE,SAChB,OAAO,QACR,0BAA0B,CAAC,OAAO,+BAAS;6BA4C3C,SAAS,MAAM,EAAE,SAChB,OAAO,QACR,2BAA2B,CAAC,OAAO,EAAE,OAAO,+BAAS,KAC1D,0BAA0B,CAAC,OAAO,gCAAU,OAAO,CAAC;qCAuE/C,SAAS,MAAM,EAAE,SAChB,OAAO,QACR,mCAAmC,CAAC,OAAO,EAAE,OAAO,+BAAS,KAClE,kCAAkC,CAAC,OAAO,gCAAU,OAAO,CAAC;EAoHhE;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,IACnB,UAAU,CAAC,OAAO,eAAe,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC"}
|
|
@@ -182,9 +182,7 @@ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
|
182
182
|
function useMutation(path, opts) {
|
|
183
183
|
const { client } = useContext();
|
|
184
184
|
const queryClient = reactQuery.useQueryClient();
|
|
185
|
-
const mutationKey =
|
|
186
|
-
path
|
|
187
|
-
];
|
|
185
|
+
const mutationKey = getQueryKey.getMutationKeyInternal(path);
|
|
188
186
|
const defaultOpts = queryClient.defaultMutationOptions(queryClient.getMutationDefaults(mutationKey));
|
|
189
187
|
const hook = reactQuery.useMutation({
|
|
190
188
|
...opts,
|
|
@@ -4,7 +4,7 @@ import { isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { TRPCContext } from '../../internals/context.mjs';
|
|
6
6
|
import { getClientArgs } from '../../internals/getClientArgs.mjs';
|
|
7
|
-
import { getQueryKeyInternal } from '../../internals/getQueryKey.mjs';
|
|
7
|
+
import { getQueryKeyInternal, getMutationKeyInternal } from '../../internals/getQueryKey.mjs';
|
|
8
8
|
import { useHookResult } from '../../internals/useHookResult.mjs';
|
|
9
9
|
import { createUtilityFunctions } from '../../utils/createUtilityFunctions.mjs';
|
|
10
10
|
import { createUseQueries } from '../proxy/useQueriesProxy.mjs';
|
|
@@ -161,9 +161,7 @@ import { createUseQueries } from '../proxy/useQueriesProxy.mjs';
|
|
|
161
161
|
function useMutation$1(path, opts) {
|
|
162
162
|
const { client } = useContext();
|
|
163
163
|
const queryClient = useQueryClient();
|
|
164
|
-
const mutationKey =
|
|
165
|
-
path
|
|
166
|
-
];
|
|
164
|
+
const mutationKey = getMutationKeyInternal(path);
|
|
167
165
|
const defaultOpts = queryClient.defaultMutationOptions(queryClient.getMutationDefaults(mutationKey));
|
|
168
166
|
const hook = useMutation({
|
|
169
167
|
...opts,
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { CancelOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, Query, QueryFilters, QueryKey, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
|
|
2
2
|
import type { TRPCClientError } from '@trpc/client';
|
|
3
|
-
import type { AnyQueryProcedure, AnyRootTypes, AnyRouter, DeepPartial, inferProcedureInput, inferTransformedProcedureOutput, ProtectedIntersection, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
|
|
3
|
+
import type { AnyMutationProcedure, AnyQueryProcedure, AnyRootTypes, AnyRouter, DeepPartial, inferProcedureInput, inferTransformedProcedureOutput, ProtectedIntersection, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
|
|
4
4
|
import type { DecoratedTRPCContextProps, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCQueryUtils } from '../../internals/context';
|
|
5
5
|
import type { QueryKeyKnown, QueryType } from '../../internals/getQueryKey';
|
|
6
|
+
import type { InferMutationOptions } from '../../utils/inferReactQueryProcedure';
|
|
6
7
|
import type { ExtractCursorType } from '../hooks/types';
|
|
7
|
-
type
|
|
8
|
+
type DecorateQueryProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyQueryProcedure> = {
|
|
8
9
|
/**
|
|
9
10
|
* @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
|
|
10
11
|
*/
|
|
@@ -74,6 +75,13 @@ type DecorateProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyQueryPr
|
|
|
74
75
|
*/
|
|
75
76
|
getInfiniteData(input?: inferProcedureInput<TProcedure>): InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined;
|
|
76
77
|
};
|
|
78
|
+
type DecorateMutationProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyMutationProcedure> = {
|
|
79
|
+
setMutationDefaults(options: InferMutationOptions<TRoot, TProcedure> | ((args: {
|
|
80
|
+
canonicalMutationFn: NonNullable<InferMutationOptions<TRoot, TProcedure>['mutationFn']>;
|
|
81
|
+
}) => InferMutationOptions<TRoot, TProcedure>)): void;
|
|
82
|
+
getMutationDefaults(): InferMutationOptions<TRoot, TProcedure> | undefined;
|
|
83
|
+
isMutating(): number;
|
|
84
|
+
};
|
|
77
85
|
/**
|
|
78
86
|
* this is the type that is used to add in procedures that can be used on
|
|
79
87
|
* an entire router
|
|
@@ -90,9 +98,9 @@ type DecorateRouter = {
|
|
|
90
98
|
* @internal
|
|
91
99
|
*/
|
|
92
100
|
export type DecoratedProcedureUtilsRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = DecorateRouter & {
|
|
93
|
-
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends RouterRecord ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter : $Value extends AnyQueryProcedure ?
|
|
101
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends RouterRecord ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter : $Value extends AnyQueryProcedure ? DecorateQueryProcedure<TRoot, $Value> : $Value extends AnyMutationProcedure ? DecorateMutationProcedure<TRoot, $Value> : never : never;
|
|
94
102
|
};
|
|
95
|
-
type AnyDecoratedProcedure =
|
|
103
|
+
type AnyDecoratedProcedure = DecorateQueryProcedure<any, any> & DecorateMutationProcedure<any, any>;
|
|
96
104
|
export type CreateReactUtils<TRouter extends AnyRouter, TSSRContext> = ProtectedIntersection<DecoratedTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
|
|
97
105
|
export type CreateQueryUtils<TRouter extends AnyRouter> = DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
|
|
98
106
|
export declare const getQueryType: (utilName: keyof AnyDecoratedProcedure) => QueryType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilsProxy.d.ts","sourceRoot":"","sources":["../../../src/shared/proxy/utilsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,OAAO,EACR,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,+BAA+B,EAC/B,qBAAqB,EACrB,YAAY,EACb,MAAM,0CAA0C,CAAC;AAKlD,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,6BAA6B,EAC7B,qBAAqB,EACrB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,6BAA6B,C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AAC,EACpC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAC1B,CACF,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,OAAO,SAAS,SAAS,IACpD,6BAA6B,CAC3B,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EACpC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAC1B,CAAC;AAEJ,eAAO,MAAM,YAAY,aACb,MAAM,qBAAqB,KACpC,SAyBF,CAAC;AAwDF;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAAE,WAAW,EAC1E,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAE,WAAW,CAAC,0KAqBlD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC,GAC/B,gBAAgB,CAAC,OAAO,CAAC,CAE3B"}
|
|
@@ -19,6 +19,9 @@ const getQueryType = (utilName)=>{
|
|
|
19
19
|
case 'getInfiniteData':
|
|
20
20
|
case 'setInfiniteData':
|
|
21
21
|
return 'infinite';
|
|
22
|
+
case 'setMutationDefaults':
|
|
23
|
+
case 'getMutationDefaults':
|
|
24
|
+
case 'isMutating':
|
|
22
25
|
case 'cancel':
|
|
23
26
|
case 'invalidate':
|
|
24
27
|
case 'refetch':
|
|
@@ -41,7 +44,9 @@ const getQueryType = (utilName)=>{
|
|
|
41
44
|
const queryType = getQueryType(utilName);
|
|
42
45
|
const queryKey = getQueryKey.getQueryKeyInternal(path, input, queryType);
|
|
43
46
|
const contextMap = {
|
|
44
|
-
|
|
47
|
+
/**
|
|
48
|
+
* DecorateQueryProcedure
|
|
49
|
+
*/ fetch: ()=>context.fetchQuery(queryKey, ...args),
|
|
45
50
|
fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
|
|
46
51
|
prefetch: ()=>context.prefetchQuery(queryKey, ...args),
|
|
47
52
|
prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
|
|
@@ -58,7 +63,14 @@ const getQueryType = (utilName)=>{
|
|
|
58
63
|
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
|
59
64
|
},
|
|
60
65
|
getData: ()=>context.getQueryData(queryKey),
|
|
61
|
-
getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
|
|
66
|
+
getInfiniteData: ()=>context.getInfiniteQueryData(queryKey),
|
|
67
|
+
/**
|
|
68
|
+
* DecorateMutationProcedure
|
|
69
|
+
*/ setMutationDefaults: ()=>context.setMutationDefaults(getQueryKey.getMutationKeyInternal(path), input),
|
|
70
|
+
getMutationDefaults: ()=>context.getMutationDefaults(getQueryKey.getMutationKeyInternal(path)),
|
|
71
|
+
isMutating: ()=>context.isMutating({
|
|
72
|
+
mutationKey: getQueryKey.getMutationKeyInternal(path)
|
|
73
|
+
})
|
|
62
74
|
};
|
|
63
75
|
return contextMap[utilName]();
|
|
64
76
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createTRPCClientProxy } from '@trpc/client';
|
|
2
2
|
import { createFlatProxy, createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
3
3
|
import { contextProps } from '../../internals/context.mjs';
|
|
4
|
-
import { getQueryKeyInternal } from '../../internals/getQueryKey.mjs';
|
|
4
|
+
import { getQueryKeyInternal, getMutationKeyInternal } from '../../internals/getQueryKey.mjs';
|
|
5
5
|
|
|
6
6
|
const getQueryType = (utilName)=>{
|
|
7
7
|
switch(utilName){
|
|
@@ -17,6 +17,9 @@ const getQueryType = (utilName)=>{
|
|
|
17
17
|
case 'getInfiniteData':
|
|
18
18
|
case 'setInfiniteData':
|
|
19
19
|
return 'infinite';
|
|
20
|
+
case 'setMutationDefaults':
|
|
21
|
+
case 'getMutationDefaults':
|
|
22
|
+
case 'isMutating':
|
|
20
23
|
case 'cancel':
|
|
21
24
|
case 'invalidate':
|
|
22
25
|
case 'refetch':
|
|
@@ -39,7 +42,9 @@ const getQueryType = (utilName)=>{
|
|
|
39
42
|
const queryType = getQueryType(utilName);
|
|
40
43
|
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
41
44
|
const contextMap = {
|
|
42
|
-
|
|
45
|
+
/**
|
|
46
|
+
* DecorateQueryProcedure
|
|
47
|
+
*/ fetch: ()=>context.fetchQuery(queryKey, ...args),
|
|
43
48
|
fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
|
|
44
49
|
prefetch: ()=>context.prefetchQuery(queryKey, ...args),
|
|
45
50
|
prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
|
|
@@ -56,7 +61,14 @@ const getQueryType = (utilName)=>{
|
|
|
56
61
|
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
|
57
62
|
},
|
|
58
63
|
getData: ()=>context.getQueryData(queryKey),
|
|
59
|
-
getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
|
|
64
|
+
getInfiniteData: ()=>context.getInfiniteQueryData(queryKey),
|
|
65
|
+
/**
|
|
66
|
+
* DecorateMutationProcedure
|
|
67
|
+
*/ setMutationDefaults: ()=>context.setMutationDefaults(getMutationKeyInternal(path), input),
|
|
68
|
+
getMutationDefaults: ()=>context.getMutationDefaults(getMutationKeyInternal(path)),
|
|
69
|
+
isMutating: ()=>context.isMutating({
|
|
70
|
+
mutationKey: getMutationKeyInternal(path)
|
|
71
|
+
})
|
|
60
72
|
};
|
|
61
73
|
return contextMap[utilName]();
|
|
62
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createUtilityFunctions.d.ts","sourceRoot":"","sources":["../../src/utils/createUtilityFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,WAAW,uBAAuB,CAAC,OAAO,SAAS,SAAS;IAChE;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC/D;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAC9D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,GACrC,cAAc,CAAC,OAAO,CAAC,
|
|
1
|
+
{"version":3,"file":"createUtilityFunctions.d.ts","sourceRoot":"","sources":["../../src/utils/createUtilityFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAoB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0CAA0C,CAAC;AAE1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,MAAM,WAAW,uBAAuB,CAAC,OAAO,SAAS,SAAS;IAChE;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC/D;;OAEG;IACH,WAAW,EAAE,WAAW,CAAC;CAC1B;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,SAAS,EAC9D,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,GACrC,cAAc,CAAC,OAAO,CAAC,CAoJzB"}
|
|
@@ -100,6 +100,29 @@ var getClientArgs = require('../internals/getClientArgs.js');
|
|
|
100
100
|
},
|
|
101
101
|
getInfiniteQueryData: (queryKey)=>{
|
|
102
102
|
return queryClient.getQueryData(queryKey);
|
|
103
|
+
},
|
|
104
|
+
setMutationDefaults: (mutationKey, options)=>{
|
|
105
|
+
const path = mutationKey[0];
|
|
106
|
+
const canonicalMutationFn = (input)=>{
|
|
107
|
+
return untypedClient.mutation(...getClientArgs.getClientArgs([
|
|
108
|
+
path,
|
|
109
|
+
{
|
|
110
|
+
input
|
|
111
|
+
}
|
|
112
|
+
], opts));
|
|
113
|
+
};
|
|
114
|
+
return queryClient.setMutationDefaults(mutationKey, typeof options === 'function' ? options({
|
|
115
|
+
canonicalMutationFn
|
|
116
|
+
}) : options);
|
|
117
|
+
},
|
|
118
|
+
getMutationDefaults: (mutationKey)=>{
|
|
119
|
+
return queryClient.getMutationDefaults(mutationKey);
|
|
120
|
+
},
|
|
121
|
+
isMutating: (filters)=>{
|
|
122
|
+
return queryClient.isMutating({
|
|
123
|
+
...filters,
|
|
124
|
+
exact: true
|
|
125
|
+
});
|
|
103
126
|
}
|
|
104
127
|
};
|
|
105
128
|
}
|
|
@@ -98,6 +98,29 @@ import { getClientArgs } from '../internals/getClientArgs.mjs';
|
|
|
98
98
|
},
|
|
99
99
|
getInfiniteQueryData: (queryKey)=>{
|
|
100
100
|
return queryClient.getQueryData(queryKey);
|
|
101
|
+
},
|
|
102
|
+
setMutationDefaults: (mutationKey, options)=>{
|
|
103
|
+
const path = mutationKey[0];
|
|
104
|
+
const canonicalMutationFn = (input)=>{
|
|
105
|
+
return untypedClient.mutation(...getClientArgs([
|
|
106
|
+
path,
|
|
107
|
+
{
|
|
108
|
+
input
|
|
109
|
+
}
|
|
110
|
+
], opts));
|
|
111
|
+
};
|
|
112
|
+
return queryClient.setMutationDefaults(mutationKey, typeof options === 'function' ? options({
|
|
113
|
+
canonicalMutationFn
|
|
114
|
+
}) : options);
|
|
115
|
+
},
|
|
116
|
+
getMutationDefaults: (mutationKey)=>{
|
|
117
|
+
return queryClient.getMutationDefaults(mutationKey);
|
|
118
|
+
},
|
|
119
|
+
isMutating: (filters)=>{
|
|
120
|
+
return queryClient.isMutating({
|
|
121
|
+
...filters,
|
|
122
|
+
exact: true
|
|
123
|
+
});
|
|
101
124
|
}
|
|
102
125
|
};
|
|
103
126
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/react-query",
|
|
3
|
-
"version": "11.0.0-rc.
|
|
3
|
+
"version": "11.0.0-rc.459+e14ad2175",
|
|
4
4
|
"description": "The tRPC React library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"@tanstack/react-query": "^5.49.2",
|
|
67
|
-
"@trpc/client": "11.0.0-rc.
|
|
68
|
-
"@trpc/server": "11.0.0-rc.
|
|
67
|
+
"@trpc/client": "11.0.0-rc.459+e14ad2175",
|
|
68
|
+
"@trpc/server": "11.0.0-rc.459+e14ad2175",
|
|
69
69
|
"react": ">=18.2.0",
|
|
70
70
|
"react-dom": ">=18.2.0"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@tanstack/react-query": "^5.49.2",
|
|
74
|
-
"@trpc/client": "11.0.0-rc.
|
|
75
|
-
"@trpc/server": "11.0.0-rc.
|
|
74
|
+
"@trpc/client": "11.0.0-rc.459+e14ad2175",
|
|
75
|
+
"@trpc/server": "11.0.0-rc.459+e14ad2175",
|
|
76
76
|
"@types/express": "^4.17.17",
|
|
77
77
|
"@types/node": "^20.10.0",
|
|
78
78
|
"@types/react": "^18.3.1",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
"funding": [
|
|
93
93
|
"https://trpc.io/sponsor"
|
|
94
94
|
],
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "e14ad2175af4647060a7dd679d293b090636beda"
|
|
96
96
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import type {
|
|
|
5
5
|
InfiniteData,
|
|
6
6
|
InvalidateOptions,
|
|
7
7
|
InvalidateQueryFilters,
|
|
8
|
+
MutationOptions,
|
|
8
9
|
QueryClient,
|
|
9
10
|
QueryFilters,
|
|
10
11
|
QueryKey,
|
|
@@ -26,7 +27,7 @@ import type {
|
|
|
26
27
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
27
28
|
import * as React from 'react';
|
|
28
29
|
import type { ExtractCursorType } from '../shared';
|
|
29
|
-
import type { TRPCQueryKey } from './getQueryKey';
|
|
30
|
+
import type { TRPCMutationKey, TRPCQueryKey } from './getQueryKey';
|
|
30
31
|
|
|
31
32
|
export type TRPCFetchQueryOptions<TOutput, TError> = DistributiveOmit<
|
|
32
33
|
FetchQueryOptions<TOutput, TError>,
|
|
@@ -240,5 +241,29 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
|
|
|
240
241
|
getInfiniteQueryData: (
|
|
241
242
|
queryKey: TRPCQueryKey,
|
|
242
243
|
) => InfiniteData<unknown> | undefined;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @link https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
|
|
247
|
+
*/
|
|
248
|
+
setMutationDefaults: (
|
|
249
|
+
mutationKey: TRPCMutationKey,
|
|
250
|
+
options:
|
|
251
|
+
| MutationOptions
|
|
252
|
+
| ((args: {
|
|
253
|
+
canonicalMutationFn: (input: unknown) => Promise<unknown>;
|
|
254
|
+
}) => MutationOptions),
|
|
255
|
+
) => void;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
|
|
259
|
+
*/
|
|
260
|
+
getMutationDefaults: (
|
|
261
|
+
mutationKey: TRPCMutationKey,
|
|
262
|
+
) => MutationOptions | undefined;
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
|
|
266
|
+
*/
|
|
267
|
+
isMutating: (filters: { mutationKey: TRPCMutationKey }) => number;
|
|
243
268
|
}
|
|
244
269
|
export const TRPCContext = React.createContext?.(null as any);
|
|
@@ -13,6 +13,8 @@ export type TRPCQueryKey = [
|
|
|
13
13
|
{ input?: unknown; type?: Exclude<QueryType, 'any'> }?,
|
|
14
14
|
];
|
|
15
15
|
|
|
16
|
+
export type TRPCMutationKey = [readonly string[]]; // = [TRPCQueryKey[0]]
|
|
17
|
+
|
|
16
18
|
type ProcedureOrRouter =
|
|
17
19
|
| DecoratedMutation<any>
|
|
18
20
|
| DecoratedQuery<any>
|
|
@@ -36,6 +38,8 @@ export function getQueryKeyInternal(
|
|
|
36
38
|
const splitPath = path.flatMap((part) => part.split('.'));
|
|
37
39
|
|
|
38
40
|
if (!input && (!type || type === 'any')) {
|
|
41
|
+
// this matches also all mutations (see `getMutationKeyInternal`)
|
|
42
|
+
|
|
39
43
|
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
40
44
|
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
41
45
|
return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);
|
|
@@ -69,6 +73,10 @@ export function getQueryKeyInternal(
|
|
|
69
73
|
];
|
|
70
74
|
}
|
|
71
75
|
|
|
76
|
+
export function getMutationKeyInternal(path: readonly string[]) {
|
|
77
|
+
return getQueryKeyInternal(path, undefined, 'any') as TRPCMutationKey;
|
|
78
|
+
}
|
|
79
|
+
|
|
72
80
|
type GetInfiniteQueryInput<
|
|
73
81
|
TProcedureInput,
|
|
74
82
|
TInputWithoutCursorAndDirection = Omit<
|
|
@@ -115,3 +123,16 @@ export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
|
|
|
115
123
|
string[],
|
|
116
124
|
{ input?: GetQueryProcedureInput<TInput>; type: TType }?,
|
|
117
125
|
];
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Method to extract the mutation key for a procedure
|
|
129
|
+
* @param procedure - procedure
|
|
130
|
+
* @link https://trpc.io/docs/v11/getQueryKey#mutations
|
|
131
|
+
*/
|
|
132
|
+
export function getMutationKey<TProcedure extends DecoratedMutation<any>>(
|
|
133
|
+
procedure: TProcedure,
|
|
134
|
+
) {
|
|
135
|
+
// @ts-expect-error - we don't expose _def on the type layer
|
|
136
|
+
const path = procedure._def().path as string[];
|
|
137
|
+
return getMutationKeyInternal(path);
|
|
138
|
+
}
|
|
@@ -19,7 +19,10 @@ import type { SSRState, TRPCContextState } from '../../internals/context';
|
|
|
19
19
|
import { TRPCContext } from '../../internals/context';
|
|
20
20
|
import { getClientArgs } from '../../internals/getClientArgs';
|
|
21
21
|
import type { TRPCQueryKey } from '../../internals/getQueryKey';
|
|
22
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
getMutationKeyInternal,
|
|
24
|
+
getQueryKeyInternal,
|
|
25
|
+
} from '../../internals/getQueryKey';
|
|
23
26
|
import { useHookResult } from '../../internals/useHookResult';
|
|
24
27
|
import type {
|
|
25
28
|
TRPCUseQueries,
|
|
@@ -267,7 +270,7 @@ export function createRootHooks<
|
|
|
267
270
|
const { client } = useContext();
|
|
268
271
|
const queryClient = useQueryClient();
|
|
269
272
|
|
|
270
|
-
const mutationKey =
|
|
273
|
+
const mutationKey = getMutationKeyInternal(path);
|
|
271
274
|
|
|
272
275
|
const defaultOpts = queryClient.defaultMutationOptions(
|
|
273
276
|
queryClient.getMutationDefaults(mutationKey),
|
|
@@ -15,6 +15,7 @@ import type {
|
|
|
15
15
|
import type { TRPCClientError } from '@trpc/client';
|
|
16
16
|
import { createTRPCClientProxy } from '@trpc/client';
|
|
17
17
|
import type {
|
|
18
|
+
AnyMutationProcedure,
|
|
18
19
|
AnyQueryProcedure,
|
|
19
20
|
AnyRootTypes,
|
|
20
21
|
AnyRouter,
|
|
@@ -37,10 +38,14 @@ import type {
|
|
|
37
38
|
} from '../../internals/context';
|
|
38
39
|
import { contextProps } from '../../internals/context';
|
|
39
40
|
import type { QueryKeyKnown, QueryType } from '../../internals/getQueryKey';
|
|
40
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
getMutationKeyInternal,
|
|
43
|
+
getQueryKeyInternal,
|
|
44
|
+
} from '../../internals/getQueryKey';
|
|
45
|
+
import type { InferMutationOptions } from '../../utils/inferReactQueryProcedure';
|
|
41
46
|
import type { ExtractCursorType } from '../hooks/types';
|
|
42
47
|
|
|
43
|
-
type
|
|
48
|
+
type DecorateQueryProcedure<
|
|
44
49
|
TRoot extends AnyRootTypes,
|
|
45
50
|
TProcedure extends AnyQueryProcedure,
|
|
46
51
|
> = {
|
|
@@ -225,6 +230,25 @@ type DecorateProcedure<
|
|
|
225
230
|
| undefined;
|
|
226
231
|
};
|
|
227
232
|
|
|
233
|
+
type DecorateMutationProcedure<
|
|
234
|
+
TRoot extends AnyRootTypes,
|
|
235
|
+
TProcedure extends AnyMutationProcedure,
|
|
236
|
+
> = {
|
|
237
|
+
setMutationDefaults(
|
|
238
|
+
options:
|
|
239
|
+
| InferMutationOptions<TRoot, TProcedure>
|
|
240
|
+
| ((args: {
|
|
241
|
+
canonicalMutationFn: NonNullable<
|
|
242
|
+
InferMutationOptions<TRoot, TProcedure>['mutationFn']
|
|
243
|
+
>;
|
|
244
|
+
}) => InferMutationOptions<TRoot, TProcedure>),
|
|
245
|
+
): void;
|
|
246
|
+
|
|
247
|
+
getMutationDefaults(): InferMutationOptions<TRoot, TProcedure> | undefined;
|
|
248
|
+
|
|
249
|
+
isMutating(): number;
|
|
250
|
+
};
|
|
251
|
+
|
|
228
252
|
/**
|
|
229
253
|
* this is the type that is used to add in procedures that can be used on
|
|
230
254
|
* an entire router
|
|
@@ -252,14 +276,16 @@ export type DecoratedProcedureUtilsRecord<
|
|
|
252
276
|
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value
|
|
253
277
|
? $Value extends RouterRecord
|
|
254
278
|
? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter
|
|
255
|
-
:
|
|
256
|
-
$Value
|
|
257
|
-
|
|
279
|
+
: $Value extends AnyQueryProcedure
|
|
280
|
+
? DecorateQueryProcedure<TRoot, $Value>
|
|
281
|
+
: $Value extends AnyMutationProcedure
|
|
282
|
+
? DecorateMutationProcedure<TRoot, $Value>
|
|
258
283
|
: never
|
|
259
284
|
: never;
|
|
260
285
|
}; // Add functions that should be available at utils root
|
|
261
286
|
|
|
262
|
-
type AnyDecoratedProcedure =
|
|
287
|
+
type AnyDecoratedProcedure = DecorateQueryProcedure<any, any> &
|
|
288
|
+
DecorateMutationProcedure<any, any>;
|
|
263
289
|
|
|
264
290
|
export type CreateReactUtils<
|
|
265
291
|
TRouter extends AnyRouter,
|
|
@@ -296,6 +322,9 @@ export const getQueryType = (
|
|
|
296
322
|
case 'setInfiniteData':
|
|
297
323
|
return 'infinite';
|
|
298
324
|
|
|
325
|
+
case 'setMutationDefaults':
|
|
326
|
+
case 'getMutationDefaults':
|
|
327
|
+
case 'isMutating':
|
|
299
328
|
case 'cancel':
|
|
300
329
|
case 'invalidate':
|
|
301
330
|
case 'refetch':
|
|
@@ -321,6 +350,9 @@ function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
|
|
|
321
350
|
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
322
351
|
|
|
323
352
|
const contextMap: Record<keyof AnyDecoratedProcedure, () => unknown> = {
|
|
353
|
+
/**
|
|
354
|
+
* DecorateQueryProcedure
|
|
355
|
+
*/
|
|
324
356
|
fetch: () => context.fetchQuery(queryKey, ...args),
|
|
325
357
|
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
|
326
358
|
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
|
@@ -340,6 +372,15 @@ function createRecursiveUtilsProxy<TRouter extends AnyRouter>(
|
|
|
340
372
|
},
|
|
341
373
|
getData: () => context.getQueryData(queryKey),
|
|
342
374
|
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
|
375
|
+
/**
|
|
376
|
+
* DecorateMutationProcedure
|
|
377
|
+
*/
|
|
378
|
+
setMutationDefaults: () =>
|
|
379
|
+
context.setMutationDefaults(getMutationKeyInternal(path), input),
|
|
380
|
+
getMutationDefaults: () =>
|
|
381
|
+
context.getMutationDefaults(getMutationKeyInternal(path)),
|
|
382
|
+
isMutating: () =>
|
|
383
|
+
context.isMutating({ mutationKey: getMutationKeyInternal(path) }),
|
|
343
384
|
};
|
|
344
385
|
|
|
345
386
|
return contextMap[utilName]();
|
|
@@ -145,5 +145,31 @@ export function createUtilityFunctions<TRouter extends AnyRouter>(
|
|
|
145
145
|
getInfiniteQueryData: (queryKey) => {
|
|
146
146
|
return queryClient.getQueryData(queryKey);
|
|
147
147
|
},
|
|
148
|
+
|
|
149
|
+
setMutationDefaults: (mutationKey, options) => {
|
|
150
|
+
const path = mutationKey[0];
|
|
151
|
+
const canonicalMutationFn = (input: unknown) => {
|
|
152
|
+
return untypedClient.mutation(
|
|
153
|
+
...getClientArgs([path, { input }], opts),
|
|
154
|
+
);
|
|
155
|
+
};
|
|
156
|
+
return queryClient.setMutationDefaults(
|
|
157
|
+
mutationKey,
|
|
158
|
+
typeof options === 'function'
|
|
159
|
+
? options({ canonicalMutationFn })
|
|
160
|
+
: options,
|
|
161
|
+
);
|
|
162
|
+
},
|
|
163
|
+
|
|
164
|
+
getMutationDefaults: (mutationKey) => {
|
|
165
|
+
return queryClient.getMutationDefaults(mutationKey);
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
isMutating: (filters) => {
|
|
169
|
+
return queryClient.isMutating({
|
|
170
|
+
...filters,
|
|
171
|
+
exact: true,
|
|
172
|
+
});
|
|
173
|
+
},
|
|
148
174
|
};
|
|
149
175
|
}
|