@trpc/react-query 11.0.0-alpha-tmp-export-from-main.212 → 11.0.0-alpha-tmp-export-from-main-nuke-core.236
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 +240 -0
- package/dist/createTRPCQueryUtils.d.ts +1 -1
- package/dist/createTRPCQueryUtils.d.ts.map +1 -1
- package/dist/createTRPCQueryUtils.js +16 -0
- package/dist/createTRPCQueryUtils.mjs +14 -0
- package/dist/createTRPCReact.d.ts +1 -1
- package/dist/createTRPCReact.d.ts.map +1 -1
- 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.d.ts +1 -1
- 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.js +16 -0
- package/dist/internals/getClientArgs.mjs +14 -0
- package/dist/internals/getQueryKey.d.ts +1 -1
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- 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/internals/useQueries.d.ts +1 -1
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/server/index.js +2 -102
- package/dist/server/index.mjs +1 -103
- package/dist/server/ssgProxy.d.ts +1 -1
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +107 -0
- package/dist/server/ssgProxy.mjs +105 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +1 -1
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/{createHooksInternal-5d2fa367.js → shared/hooks/createHooksInternal.js} +28 -183
- package/dist/{createHooksInternal-e0b0564e.mjs → shared/hooks/createHooksInternal.mjs} +8 -158
- package/dist/shared/hooks/types.d.ts +1 -1
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.js +13 -15
- package/dist/shared/index.mjs +7 -7
- package/dist/shared/polymorphism/mutationLike.d.ts +1 -1
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/utilsLike.d.ts +1 -1
- package/dist/shared/polymorphism/utilsLike.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.d.ts +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +89 -0
- package/dist/{utilsProxy-61a4601f.mjs → shared/proxy/utilsProxy.mjs} +4 -52
- package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
- package/dist/shared/types.d.ts +1 -1
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.d.ts +1 -1
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.js +94 -0
- package/dist/utils/createUtilityFunctions.mjs +92 -0
- package/dist/utils/inferReactQueryProcedure.d.ts +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +16 -32
- package/src/createTRPCQueryUtils.tsx +1 -1
- package/src/createTRPCReact.tsx +2 -2
- package/src/internals/context.tsx +4 -1
- package/src/internals/getQueryKey.ts +20 -2
- package/src/internals/useQueries.ts +4 -1
- package/src/server/ssgProxy.ts +2 -2
- package/src/shared/hooks/createHooksInternal.tsx +1 -1
- package/src/shared/hooks/types.ts +4 -1
- package/src/shared/polymorphism/mutationLike.ts +1 -1
- package/src/shared/polymorphism/queryLike.ts +1 -1
- package/src/shared/polymorphism/routerLike.ts +1 -1
- package/src/shared/polymorphism/utilsLike.ts +1 -1
- package/src/shared/proxy/decorationProxy.ts +2 -2
- package/src/shared/proxy/useQueriesProxy.ts +2 -2
- package/src/shared/proxy/utilsProxy.ts +5 -2
- package/src/shared/types.ts +4 -1
- package/src/utils/createUtilityFunctions.ts +1 -1
- package/src/utils/inferReactQueryProcedure.ts +1 -1
- package/dist/createHooksInternal-4285c71a.js +0 -470
- package/dist/queryClient-1c8d7d8a.js +0 -8
- package/dist/utilsProxy-0b88c1e3.js +0 -161
- package/dist/utilsProxy-ff357a62.js +0 -128
- /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { createTRPCClientProxy } from '@trpc/client';
|
|
2
|
-
import { createFlatProxy, createRecursiveProxy } from '@trpc/core';
|
|
3
|
-
import * as React from 'react';
|
|
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
|
-
**/
|
|
10
|
-
function getQueryKeyInternal(path, input, type) {
|
|
11
|
-
// Construct a query key that is easy to destructure and flexible for
|
|
12
|
-
// partial selecting etc.
|
|
13
|
-
// https://github.com/trpc/trpc/issues/3128
|
|
14
|
-
// some parts of the path may be dot-separated, split them up
|
|
15
|
-
const splitPath = path.flatMap((part) => part.split('.'));
|
|
16
|
-
if (!input && (!type || type === 'any'))
|
|
17
|
-
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
18
|
-
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
19
|
-
return splitPath.length ? [splitPath] : [];
|
|
20
|
-
return [
|
|
21
|
-
splitPath,
|
|
22
|
-
{
|
|
23
|
-
...(typeof input !== 'undefined' && { input: input }),
|
|
24
|
-
...(type && type !== 'any' && { type: type }),
|
|
25
|
-
},
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Method to extract the query key for a procedure
|
|
30
|
-
* @param procedureOrRouter - procedure or AnyRouter
|
|
31
|
-
* @param input - input to procedureOrRouter
|
|
32
|
-
* @param type - defaults to `any`
|
|
33
|
-
* @link https://trpc.io/docs/v11/getQueryKey
|
|
34
|
-
*/
|
|
35
|
-
function getQueryKey(..._params) {
|
|
36
|
-
const [procedureOrRouter, input, type] = _params;
|
|
37
|
-
// @ts-expect-error - we don't expose _def on the type layer
|
|
38
|
-
const path = procedureOrRouter._def().path;
|
|
39
|
-
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
|
40
|
-
return queryKey;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const contextProps = [
|
|
44
|
-
'client',
|
|
45
|
-
'ssrContext',
|
|
46
|
-
'ssrState',
|
|
47
|
-
'abortOnUnmount',
|
|
48
|
-
];
|
|
49
|
-
const TRPCContext = React.createContext?.(null);
|
|
50
|
-
|
|
51
|
-
const getQueryType = (utilName) => {
|
|
52
|
-
switch (utilName) {
|
|
53
|
-
case 'fetch':
|
|
54
|
-
case 'ensureData':
|
|
55
|
-
case 'prefetch':
|
|
56
|
-
case 'getData':
|
|
57
|
-
case 'setData':
|
|
58
|
-
return 'query';
|
|
59
|
-
case 'fetchInfinite':
|
|
60
|
-
case 'prefetchInfinite':
|
|
61
|
-
case 'getInfiniteData':
|
|
62
|
-
case 'setInfiniteData':
|
|
63
|
-
return 'infinite';
|
|
64
|
-
case 'cancel':
|
|
65
|
-
case 'invalidate':
|
|
66
|
-
case 'refetch':
|
|
67
|
-
case 'reset':
|
|
68
|
-
return 'any';
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* @internal
|
|
73
|
-
*/
|
|
74
|
-
function createRecursiveUtilsProxy(context, key) {
|
|
75
|
-
return createRecursiveProxy((opts) => {
|
|
76
|
-
const path = [key, ...opts.path];
|
|
77
|
-
const utilName = path.pop();
|
|
78
|
-
const args = [...opts.args];
|
|
79
|
-
const input = args.shift(); // args can now be spread when input removed
|
|
80
|
-
const queryType = getQueryType(utilName);
|
|
81
|
-
const queryKey = getQueryKeyInternal(path, input, queryType);
|
|
82
|
-
const contextMap = {
|
|
83
|
-
fetch: () => context.fetchQuery(queryKey, ...args),
|
|
84
|
-
fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
|
|
85
|
-
prefetch: () => context.prefetchQuery(queryKey, ...args),
|
|
86
|
-
prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
|
|
87
|
-
ensureData: () => context.ensureQueryData(queryKey, ...args),
|
|
88
|
-
invalidate: () => context.invalidateQueries(queryKey, ...args),
|
|
89
|
-
reset: () => context.resetQueries(queryKey, ...args),
|
|
90
|
-
refetch: () => context.refetchQueries(queryKey, ...args),
|
|
91
|
-
cancel: () => context.cancelQuery(queryKey, ...args),
|
|
92
|
-
setData: () => {
|
|
93
|
-
context.setQueryData(queryKey, args[0], args[1]);
|
|
94
|
-
},
|
|
95
|
-
setInfiniteData: () => {
|
|
96
|
-
context.setInfiniteQueryData(queryKey, args[0], args[1]);
|
|
97
|
-
},
|
|
98
|
-
getData: () => context.getQueryData(queryKey),
|
|
99
|
-
getInfiniteData: () => context.getInfiniteQueryData(queryKey),
|
|
100
|
-
};
|
|
101
|
-
return contextMap[utilName]();
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* @internal
|
|
106
|
-
*/
|
|
107
|
-
function createReactQueryUtils(context) {
|
|
108
|
-
return createFlatProxy((key) => {
|
|
109
|
-
const contextName = key;
|
|
110
|
-
if (contextName === 'client') {
|
|
111
|
-
return createTRPCClientProxy(context.client);
|
|
112
|
-
}
|
|
113
|
-
if (contextProps.includes(contextName)) {
|
|
114
|
-
return context[contextName];
|
|
115
|
-
}
|
|
116
|
-
return createRecursiveUtilsProxy(context, key);
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* @internal
|
|
121
|
-
*/
|
|
122
|
-
function createQueryUtilsProxy(context) {
|
|
123
|
-
return createFlatProxy((key) => {
|
|
124
|
-
return createRecursiveUtilsProxy(context, key);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export { TRPCContext as T, createQueryUtilsProxy as a, getQueryKeyInternal as b, createReactQueryUtils as c, getQueryType as d, contextProps as e, getQueryKey as g };
|
|
File without changes
|