@trpc/react-query 11.0.0-next-beta.206 → 11.0.0-next-beta.208
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 +40 -40
- package/dist/createTRPCQueryUtils.js +16 -0
- package/dist/createTRPCQueryUtils.mjs +14 -0
- package/dist/createTRPCReact.js +58 -0
- package/dist/createTRPCReact.mjs +36 -0
- package/dist/index.js +10 -64
- package/dist/index.mjs +3 -40
- package/dist/internals/context.js +33 -0
- package/dist/internals/context.mjs +11 -0
- package/dist/internals/getClientArgs.js +16 -0
- package/dist/internals/getClientArgs.mjs +14 -0
- package/dist/internals/getQueryKey.js +57 -0
- package/dist/internals/getQueryKey.mjs +54 -0
- package/dist/internals/useHookResult.js +32 -0
- package/dist/internals/useHookResult.mjs +11 -0
- package/dist/server/index.js +2 -102
- package/dist/server/index.mjs +1 -103
- package/dist/server/ssgProxy.js +107 -0
- package/dist/server/ssgProxy.mjs +105 -0
- package/dist/{createHooksInternal-f77072af.js → shared/hooks/createHooksInternal.js} +28 -183
- package/dist/{createHooksInternal-0df35117.mjs → shared/hooks/createHooksInternal.mjs} +8 -158
- package/dist/shared/index.js +13 -15
- package/dist/shared/index.mjs +7 -7
- package/dist/shared/proxy/decorationProxy.js +31 -0
- package/dist/shared/proxy/decorationProxy.mjs +29 -0
- package/dist/shared/proxy/useQueriesProxy.js +25 -0
- package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
- package/dist/shared/proxy/utilsProxy.js +89 -0
- package/dist/{utilsProxy-12979321.mjs → shared/proxy/utilsProxy.mjs} +3 -63
- package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
- package/dist/utils/createUtilityFunctions.js +94 -0
- package/dist/utils/createUtilityFunctions.mjs +92 -0
- package/package.json +6 -6
- package/dist/createHooksInternal-3074c6c4.js +0 -470
- package/dist/queryClient-1c8d7d8a.js +0 -8
- package/dist/utilsProxy-13814792.js +0 -142
- package/dist/utilsProxy-4f6da312.js +0 -173
- /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@trpc/client');
|
|
4
|
+
var core = require('@trpc/core');
|
|
5
|
+
var context = require('../../internals/context.js');
|
|
6
|
+
var getQueryKey = require('../../internals/getQueryKey.js');
|
|
7
|
+
|
|
8
|
+
const getQueryType = (utilName)=>{
|
|
9
|
+
switch(utilName){
|
|
10
|
+
case 'fetch':
|
|
11
|
+
case 'ensureData':
|
|
12
|
+
case 'prefetch':
|
|
13
|
+
case 'getData':
|
|
14
|
+
case 'setData':
|
|
15
|
+
return 'query';
|
|
16
|
+
case 'fetchInfinite':
|
|
17
|
+
case 'prefetchInfinite':
|
|
18
|
+
case 'getInfiniteData':
|
|
19
|
+
case 'setInfiniteData':
|
|
20
|
+
return 'infinite';
|
|
21
|
+
case 'cancel':
|
|
22
|
+
case 'invalidate':
|
|
23
|
+
case 'refetch':
|
|
24
|
+
case 'reset':
|
|
25
|
+
return 'any';
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* @internal
|
|
30
|
+
*/ function createRecursiveUtilsProxy(context, key) {
|
|
31
|
+
return core.createRecursiveProxy((opts)=>{
|
|
32
|
+
const path = [
|
|
33
|
+
key,
|
|
34
|
+
...opts.path
|
|
35
|
+
];
|
|
36
|
+
const utilName = path.pop();
|
|
37
|
+
const args = [
|
|
38
|
+
...opts.args
|
|
39
|
+
];
|
|
40
|
+
const input = args.shift(); // args can now be spread when input removed
|
|
41
|
+
const queryType = getQueryType(utilName);
|
|
42
|
+
const queryKey = getQueryKey.getQueryKeyInternal(path, input, queryType);
|
|
43
|
+
const contextMap = {
|
|
44
|
+
fetch: ()=>context.fetchQuery(queryKey, ...args),
|
|
45
|
+
fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
|
|
46
|
+
prefetch: ()=>context.prefetchQuery(queryKey, ...args),
|
|
47
|
+
prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
|
|
48
|
+
ensureData: ()=>context.ensureQueryData(queryKey, ...args),
|
|
49
|
+
invalidate: ()=>context.invalidateQueries(queryKey, ...args),
|
|
50
|
+
reset: ()=>context.resetQueries(queryKey, ...args),
|
|
51
|
+
refetch: ()=>context.refetchQueries(queryKey, ...args),
|
|
52
|
+
cancel: ()=>context.cancelQuery(queryKey, ...args),
|
|
53
|
+
setData: ()=>{
|
|
54
|
+
context.setQueryData(queryKey, args[0], args[1]);
|
|
55
|
+
},
|
|
56
|
+
setInfiniteData: ()=>{
|
|
57
|
+
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
|
58
|
+
},
|
|
59
|
+
getData: ()=>context.getQueryData(queryKey),
|
|
60
|
+
getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
|
|
61
|
+
};
|
|
62
|
+
return contextMap[utilName]();
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @internal
|
|
67
|
+
*/ function createReactQueryUtils(context$1) {
|
|
68
|
+
return core.createFlatProxy((key)=>{
|
|
69
|
+
const contextName = key;
|
|
70
|
+
if (contextName === 'client') {
|
|
71
|
+
return client.createTRPCClientProxy(context$1.client);
|
|
72
|
+
}
|
|
73
|
+
if (context.contextProps.includes(contextName)) {
|
|
74
|
+
return context$1[contextName];
|
|
75
|
+
}
|
|
76
|
+
return createRecursiveUtilsProxy(context$1, key);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @internal
|
|
81
|
+
*/ function createQueryUtilsProxy(context) {
|
|
82
|
+
return core.createFlatProxy((key)=>{
|
|
83
|
+
return createRecursiveUtilsProxy(context, key);
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
exports.createQueryUtilsProxy = createQueryUtilsProxy;
|
|
88
|
+
exports.createReactQueryUtils = createReactQueryUtils;
|
|
89
|
+
exports.getQueryType = getQueryType;
|
|
@@ -1,67 +1,7 @@
|
|
|
1
1
|
import { createTRPCClientProxy } from '@trpc/client';
|
|
2
2
|
import { createFlatProxy, createRecursiveProxy } from '@trpc/core';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* To allow easy interactions with groups of related queries, such as
|
|
7
|
-
* invalidating all queries of a router, we use an array as the path when
|
|
8
|
-
* storing in tanstack query.
|
|
9
|
-
**/ function getQueryKeyInternal(path, input, type) {
|
|
10
|
-
// Construct a query key that is easy to destructure and flexible for
|
|
11
|
-
// partial selecting etc.
|
|
12
|
-
// https://github.com/trpc/trpc/issues/3128
|
|
13
|
-
// some parts of the path may be dot-separated, split them up
|
|
14
|
-
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
15
|
-
if (!input && (!type || type === 'any')) {
|
|
16
|
-
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
17
|
-
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
18
|
-
return splitPath.length ? [
|
|
19
|
-
splitPath
|
|
20
|
-
] : [];
|
|
21
|
-
}
|
|
22
|
-
if (type === 'infinite' && input && typeof input === 'object' && 'cursor' in input) {
|
|
23
|
-
const { cursor: _ , ...inputWithoutCursor } = input;
|
|
24
|
-
return [
|
|
25
|
-
splitPath,
|
|
26
|
-
{
|
|
27
|
-
input: inputWithoutCursor,
|
|
28
|
-
type: 'infinite'
|
|
29
|
-
}
|
|
30
|
-
];
|
|
31
|
-
}
|
|
32
|
-
return [
|
|
33
|
-
splitPath,
|
|
34
|
-
{
|
|
35
|
-
...typeof input !== 'undefined' && {
|
|
36
|
-
input: input
|
|
37
|
-
},
|
|
38
|
-
...type && type !== 'any' && {
|
|
39
|
-
type: type
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Method to extract the query key for a procedure
|
|
46
|
-
* @param procedureOrRouter - procedure or AnyRouter
|
|
47
|
-
* @param input - input to procedureOrRouter
|
|
48
|
-
* @param type - defaults to `any`
|
|
49
|
-
* @link https://trpc.io/docs/v11/getQueryKey
|
|
50
|
-
*/ function getQueryKey(..._params) {
|
|
51
|
-
const [procedureOrRouter, input, type] = _params;
|
|
52
|
-
// @ts-expect-error - we don't expose _def on the type layer
|
|
53
|
-
const path = procedureOrRouter._def().path;
|
|
54
|
-
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
|
55
|
-
return queryKey;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const contextProps = [
|
|
59
|
-
'client',
|
|
60
|
-
'ssrContext',
|
|
61
|
-
'ssrState',
|
|
62
|
-
'abortOnUnmount'
|
|
63
|
-
];
|
|
64
|
-
const TRPCContext = React.createContext?.(null);
|
|
3
|
+
import { contextProps } from '../../internals/context.mjs';
|
|
4
|
+
import { getQueryKeyInternal } from '../../internals/getQueryKey.mjs';
|
|
65
5
|
|
|
66
6
|
const getQueryType = (utilName)=>{
|
|
67
7
|
switch(utilName){
|
|
@@ -142,4 +82,4 @@ const getQueryType = (utilName)=>{
|
|
|
142
82
|
});
|
|
143
83
|
}
|
|
144
84
|
|
|
145
|
-
export {
|
|
85
|
+
export { createQueryUtilsProxy, createReactQueryUtils, getQueryType };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@trpc/client');
|
|
4
|
+
var getClientArgs = require('../internals/getClientArgs.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a set of utility functions that can be used to interact with `react-query`
|
|
8
|
+
* @param opts the `TRPCClient` and `QueryClient` to use
|
|
9
|
+
* @returns a set of utility functions that can be used to interact with `react-query`
|
|
10
|
+
* @internal
|
|
11
|
+
*/ function createUtilityFunctions(opts) {
|
|
12
|
+
const { client: client$1 , queryClient } = opts;
|
|
13
|
+
const untypedClient = client$1 instanceof client.TRPCUntypedClient ? client$1 : client.getUntypedClient(client$1);
|
|
14
|
+
return {
|
|
15
|
+
fetchQuery: (queryKey, opts)=>{
|
|
16
|
+
return queryClient.fetchQuery({
|
|
17
|
+
...opts,
|
|
18
|
+
queryKey,
|
|
19
|
+
queryFn: ()=>untypedClient.query(...getClientArgs.getClientArgs(queryKey, opts))
|
|
20
|
+
});
|
|
21
|
+
},
|
|
22
|
+
fetchInfiniteQuery: (queryKey, opts)=>{
|
|
23
|
+
return queryClient.fetchInfiniteQuery({
|
|
24
|
+
...opts,
|
|
25
|
+
queryKey,
|
|
26
|
+
queryFn: ({ pageParam })=>{
|
|
27
|
+
return untypedClient.query(...getClientArgs.getClientArgs(queryKey, opts, pageParam));
|
|
28
|
+
},
|
|
29
|
+
initialPageParam: opts?.initialCursor ?? null
|
|
30
|
+
});
|
|
31
|
+
},
|
|
32
|
+
prefetchQuery: (queryKey, opts)=>{
|
|
33
|
+
return queryClient.prefetchQuery({
|
|
34
|
+
...opts,
|
|
35
|
+
queryKey,
|
|
36
|
+
queryFn: ()=>untypedClient.query(...getClientArgs.getClientArgs(queryKey, opts))
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
prefetchInfiniteQuery: (queryKey, opts)=>{
|
|
40
|
+
return queryClient.prefetchInfiniteQuery({
|
|
41
|
+
...opts,
|
|
42
|
+
queryKey,
|
|
43
|
+
queryFn: ({ pageParam })=>{
|
|
44
|
+
return untypedClient.query(...getClientArgs.getClientArgs(queryKey, opts, pageParam));
|
|
45
|
+
},
|
|
46
|
+
initialPageParam: opts?.initialCursor ?? null
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
ensureQueryData: (queryKey, opts)=>{
|
|
50
|
+
return queryClient.ensureQueryData({
|
|
51
|
+
...opts,
|
|
52
|
+
queryKey,
|
|
53
|
+
queryFn: ()=>untypedClient.query(...getClientArgs.getClientArgs(queryKey, opts))
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
invalidateQueries: (queryKey, filters, options)=>{
|
|
57
|
+
return queryClient.invalidateQueries({
|
|
58
|
+
...filters,
|
|
59
|
+
queryKey
|
|
60
|
+
}, options);
|
|
61
|
+
},
|
|
62
|
+
resetQueries: (queryKey, filters, options)=>{
|
|
63
|
+
return queryClient.resetQueries({
|
|
64
|
+
...filters,
|
|
65
|
+
queryKey
|
|
66
|
+
}, options);
|
|
67
|
+
},
|
|
68
|
+
refetchQueries: (queryKey, filters, options)=>{
|
|
69
|
+
return queryClient.refetchQueries({
|
|
70
|
+
...filters,
|
|
71
|
+
queryKey
|
|
72
|
+
}, options);
|
|
73
|
+
},
|
|
74
|
+
cancelQuery: (queryKey, options)=>{
|
|
75
|
+
return queryClient.cancelQueries({
|
|
76
|
+
queryKey
|
|
77
|
+
}, options);
|
|
78
|
+
},
|
|
79
|
+
setQueryData: (queryKey, updater, options)=>{
|
|
80
|
+
return queryClient.setQueryData(queryKey, updater, options);
|
|
81
|
+
},
|
|
82
|
+
getQueryData: (queryKey)=>{
|
|
83
|
+
return queryClient.getQueryData(queryKey);
|
|
84
|
+
},
|
|
85
|
+
setInfiniteQueryData: (queryKey, updater, options)=>{
|
|
86
|
+
return queryClient.setQueryData(queryKey, updater, options);
|
|
87
|
+
},
|
|
88
|
+
getInfiniteQueryData: (queryKey)=>{
|
|
89
|
+
return queryClient.getQueryData(queryKey);
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
exports.createUtilityFunctions = createUtilityFunctions;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { TRPCUntypedClient, getUntypedClient } from '@trpc/client';
|
|
2
|
+
import { getClientArgs } from '../internals/getClientArgs.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates a set of utility functions that can be used to interact with `react-query`
|
|
6
|
+
* @param opts the `TRPCClient` and `QueryClient` to use
|
|
7
|
+
* @returns a set of utility functions that can be used to interact with `react-query`
|
|
8
|
+
* @internal
|
|
9
|
+
*/ function createUtilityFunctions(opts) {
|
|
10
|
+
const { client , queryClient } = opts;
|
|
11
|
+
const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
|
12
|
+
return {
|
|
13
|
+
fetchQuery: (queryKey, opts)=>{
|
|
14
|
+
return queryClient.fetchQuery({
|
|
15
|
+
...opts,
|
|
16
|
+
queryKey,
|
|
17
|
+
queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
|
|
18
|
+
});
|
|
19
|
+
},
|
|
20
|
+
fetchInfiniteQuery: (queryKey, opts)=>{
|
|
21
|
+
return queryClient.fetchInfiniteQuery({
|
|
22
|
+
...opts,
|
|
23
|
+
queryKey,
|
|
24
|
+
queryFn: ({ pageParam })=>{
|
|
25
|
+
return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
|
|
26
|
+
},
|
|
27
|
+
initialPageParam: opts?.initialCursor ?? null
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
prefetchQuery: (queryKey, opts)=>{
|
|
31
|
+
return queryClient.prefetchQuery({
|
|
32
|
+
...opts,
|
|
33
|
+
queryKey,
|
|
34
|
+
queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
|
|
35
|
+
});
|
|
36
|
+
},
|
|
37
|
+
prefetchInfiniteQuery: (queryKey, opts)=>{
|
|
38
|
+
return queryClient.prefetchInfiniteQuery({
|
|
39
|
+
...opts,
|
|
40
|
+
queryKey,
|
|
41
|
+
queryFn: ({ pageParam })=>{
|
|
42
|
+
return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
|
|
43
|
+
},
|
|
44
|
+
initialPageParam: opts?.initialCursor ?? null
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
ensureQueryData: (queryKey, opts)=>{
|
|
48
|
+
return queryClient.ensureQueryData({
|
|
49
|
+
...opts,
|
|
50
|
+
queryKey,
|
|
51
|
+
queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
invalidateQueries: (queryKey, filters, options)=>{
|
|
55
|
+
return queryClient.invalidateQueries({
|
|
56
|
+
...filters,
|
|
57
|
+
queryKey
|
|
58
|
+
}, options);
|
|
59
|
+
},
|
|
60
|
+
resetQueries: (queryKey, filters, options)=>{
|
|
61
|
+
return queryClient.resetQueries({
|
|
62
|
+
...filters,
|
|
63
|
+
queryKey
|
|
64
|
+
}, options);
|
|
65
|
+
},
|
|
66
|
+
refetchQueries: (queryKey, filters, options)=>{
|
|
67
|
+
return queryClient.refetchQueries({
|
|
68
|
+
...filters,
|
|
69
|
+
queryKey
|
|
70
|
+
}, options);
|
|
71
|
+
},
|
|
72
|
+
cancelQuery: (queryKey, options)=>{
|
|
73
|
+
return queryClient.cancelQueries({
|
|
74
|
+
queryKey
|
|
75
|
+
}, options);
|
|
76
|
+
},
|
|
77
|
+
setQueryData: (queryKey, updater, options)=>{
|
|
78
|
+
return queryClient.setQueryData(queryKey, updater, options);
|
|
79
|
+
},
|
|
80
|
+
getQueryData: (queryKey)=>{
|
|
81
|
+
return queryClient.getQueryData(queryKey);
|
|
82
|
+
},
|
|
83
|
+
setInfiniteQueryData: (queryKey, updater, options)=>{
|
|
84
|
+
return queryClient.setQueryData(queryKey, updater, options);
|
|
85
|
+
},
|
|
86
|
+
getInfiniteQueryData: (queryKey)=>{
|
|
87
|
+
return queryClient.getQueryData(queryKey);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export { createUtilityFunctions };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/react-query",
|
|
3
|
-
"version": "11.0.0-next-beta.
|
|
3
|
+
"version": "11.0.0-next-beta.208+ce423b8ae",
|
|
4
4
|
"description": "The tRPC React library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -57,17 +57,17 @@
|
|
|
57
57
|
}
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@trpc/core": "11.0.0-next-beta.
|
|
60
|
+
"@trpc/core": "11.0.0-next-beta.208+ce423b8ae"
|
|
61
61
|
},
|
|
62
62
|
"peerDependencies": {
|
|
63
63
|
"@tanstack/react-query": "^5.0.0",
|
|
64
|
-
"@trpc/client": "11.0.0-next-beta.
|
|
64
|
+
"@trpc/client": "11.0.0-next-beta.208+ce423b8ae",
|
|
65
65
|
"react": ">=18.2.0",
|
|
66
66
|
"react-dom": ">=18.2.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@tanstack/react-query": "^5.0.0",
|
|
70
|
-
"@trpc/client": "11.0.0-next-beta.
|
|
70
|
+
"@trpc/client": "11.0.0-next-beta.208+ce423b8ae",
|
|
71
71
|
"@types/express": "^4.17.17",
|
|
72
72
|
"@types/node": "^20.10.0",
|
|
73
73
|
"@types/react": "^18.2.33",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"next": "^14.0.1",
|
|
77
77
|
"react": "^18.2.0",
|
|
78
78
|
"react-dom": "^18.2.0",
|
|
79
|
-
"rollup": "^
|
|
79
|
+
"rollup": "^4.9.5",
|
|
80
80
|
"tsx": "^4.0.0",
|
|
81
81
|
"zod": "^3.0.0"
|
|
82
82
|
},
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"funding": [
|
|
87
87
|
"https://trpc.io/sponsor"
|
|
88
88
|
],
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "ce423b8ae58efdb512748acd8e63d54bcbfd6eec"
|
|
90
90
|
}
|