@trpc/react-query 11.0.0-next-beta.206 → 11.0.0-next-beta.216

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.
Files changed (38) hide show
  1. package/dist/bundle-analysis.json +28 -28
  2. package/dist/createTRPCQueryUtils.js +16 -0
  3. package/dist/createTRPCQueryUtils.mjs +14 -0
  4. package/dist/createTRPCReact.js +58 -0
  5. package/dist/createTRPCReact.mjs +36 -0
  6. package/dist/index.js +10 -64
  7. package/dist/index.mjs +3 -40
  8. package/dist/internals/context.js +33 -0
  9. package/dist/internals/context.mjs +11 -0
  10. package/dist/internals/getClientArgs.js +16 -0
  11. package/dist/internals/getClientArgs.mjs +14 -0
  12. package/dist/internals/getQueryKey.js +57 -0
  13. package/dist/internals/getQueryKey.mjs +54 -0
  14. package/dist/internals/useHookResult.js +32 -0
  15. package/dist/internals/useHookResult.mjs +11 -0
  16. package/dist/server/index.js +2 -102
  17. package/dist/server/index.mjs +1 -103
  18. package/dist/server/ssgProxy.js +107 -0
  19. package/dist/server/ssgProxy.mjs +105 -0
  20. package/dist/{createHooksInternal-f77072af.js → shared/hooks/createHooksInternal.js} +28 -183
  21. package/dist/{createHooksInternal-0df35117.mjs → shared/hooks/createHooksInternal.mjs} +8 -158
  22. package/dist/shared/index.js +13 -15
  23. package/dist/shared/index.mjs +7 -7
  24. package/dist/shared/proxy/decorationProxy.js +31 -0
  25. package/dist/shared/proxy/decorationProxy.mjs +29 -0
  26. package/dist/shared/proxy/useQueriesProxy.js +25 -0
  27. package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
  28. package/dist/shared/proxy/utilsProxy.js +89 -0
  29. package/dist/{utilsProxy-12979321.mjs → shared/proxy/utilsProxy.mjs} +3 -63
  30. package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
  31. package/dist/utils/createUtilityFunctions.js +94 -0
  32. package/dist/utils/createUtilityFunctions.mjs +92 -0
  33. package/package.json +6 -6
  34. package/dist/createHooksInternal-3074c6c4.js +0 -470
  35. package/dist/queryClient-1c8d7d8a.js +0 -8
  36. package/dist/utilsProxy-13814792.js +0 -142
  37. package/dist/utilsProxy-4f6da312.js +0 -173
  38. /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
@@ -1,173 +0,0 @@
1
- 'use strict';
2
-
3
- var client = require('@trpc/client');
4
- var core = require('@trpc/core');
5
- var React = require('react');
6
-
7
- function _interopNamespace(e) {
8
- if (e && e.__esModule) return e;
9
- var n = Object.create(null);
10
- if (e) {
11
- Object.keys(e).forEach(function (k) {
12
- if (k !== 'default') {
13
- var d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: function () { return e[k]; }
17
- });
18
- }
19
- });
20
- }
21
- n["default"] = e;
22
- return Object.freeze(n);
23
- }
24
-
25
- var React__namespace = /*#__PURE__*/_interopNamespace(React);
26
-
27
- /**
28
- * To allow easy interactions with groups of related queries, such as
29
- * invalidating all queries of a router, we use an array as the path when
30
- * storing in tanstack query.
31
- **/ function getQueryKeyInternal(path, input, type) {
32
- // Construct a query key that is easy to destructure and flexible for
33
- // partial selecting etc.
34
- // https://github.com/trpc/trpc/issues/3128
35
- // some parts of the path may be dot-separated, split them up
36
- const splitPath = path.flatMap((part)=>part.split('.'));
37
- if (!input && (!type || type === 'any')) {
38
- // for `utils.invalidate()` to match all queries (including vanilla react-query)
39
- // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
40
- return splitPath.length ? [
41
- splitPath
42
- ] : [];
43
- }
44
- if (type === 'infinite' && input && typeof input === 'object' && 'cursor' in input) {
45
- const { cursor: _ , ...inputWithoutCursor } = input;
46
- return [
47
- splitPath,
48
- {
49
- input: inputWithoutCursor,
50
- type: 'infinite'
51
- }
52
- ];
53
- }
54
- return [
55
- splitPath,
56
- {
57
- ...typeof input !== 'undefined' && {
58
- input: input
59
- },
60
- ...type && type !== 'any' && {
61
- type: type
62
- }
63
- }
64
- ];
65
- }
66
- /**
67
- * Method to extract the query key for a procedure
68
- * @param procedureOrRouter - procedure or AnyRouter
69
- * @param input - input to procedureOrRouter
70
- * @param type - defaults to `any`
71
- * @link https://trpc.io/docs/v11/getQueryKey
72
- */ function getQueryKey(..._params) {
73
- const [procedureOrRouter, input, type] = _params;
74
- // @ts-expect-error - we don't expose _def on the type layer
75
- const path = procedureOrRouter._def().path;
76
- const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
77
- return queryKey;
78
- }
79
-
80
- const contextProps = [
81
- 'client',
82
- 'ssrContext',
83
- 'ssrState',
84
- 'abortOnUnmount'
85
- ];
86
- const TRPCContext = React__namespace.createContext?.(null);
87
-
88
- const getQueryType = (utilName)=>{
89
- switch(utilName){
90
- case 'fetch':
91
- case 'ensureData':
92
- case 'prefetch':
93
- case 'getData':
94
- case 'setData':
95
- return 'query';
96
- case 'fetchInfinite':
97
- case 'prefetchInfinite':
98
- case 'getInfiniteData':
99
- case 'setInfiniteData':
100
- return 'infinite';
101
- case 'cancel':
102
- case 'invalidate':
103
- case 'refetch':
104
- case 'reset':
105
- return 'any';
106
- }
107
- };
108
- /**
109
- * @internal
110
- */ function createRecursiveUtilsProxy(context, key) {
111
- return core.createRecursiveProxy((opts)=>{
112
- const path = [
113
- key,
114
- ...opts.path
115
- ];
116
- const utilName = path.pop();
117
- const args = [
118
- ...opts.args
119
- ];
120
- const input = args.shift(); // args can now be spread when input removed
121
- const queryType = getQueryType(utilName);
122
- const queryKey = getQueryKeyInternal(path, input, queryType);
123
- const contextMap = {
124
- fetch: ()=>context.fetchQuery(queryKey, ...args),
125
- fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
126
- prefetch: ()=>context.prefetchQuery(queryKey, ...args),
127
- prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
128
- ensureData: ()=>context.ensureQueryData(queryKey, ...args),
129
- invalidate: ()=>context.invalidateQueries(queryKey, ...args),
130
- reset: ()=>context.resetQueries(queryKey, ...args),
131
- refetch: ()=>context.refetchQueries(queryKey, ...args),
132
- cancel: ()=>context.cancelQuery(queryKey, ...args),
133
- setData: ()=>{
134
- context.setQueryData(queryKey, args[0], args[1]);
135
- },
136
- setInfiniteData: ()=>{
137
- context.setInfiniteQueryData(queryKey, args[0], args[1]);
138
- },
139
- getData: ()=>context.getQueryData(queryKey),
140
- getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
141
- };
142
- return contextMap[utilName]();
143
- });
144
- }
145
- /**
146
- * @internal
147
- */ function createReactQueryUtils(context) {
148
- return core.createFlatProxy((key)=>{
149
- const contextName = key;
150
- if (contextName === 'client') {
151
- return client.createTRPCClientProxy(context.client);
152
- }
153
- if (contextProps.includes(contextName)) {
154
- return context[contextName];
155
- }
156
- return createRecursiveUtilsProxy(context, key);
157
- });
158
- }
159
- /**
160
- * @internal
161
- */ function createQueryUtilsProxy(context) {
162
- return core.createFlatProxy((key)=>{
163
- return createRecursiveUtilsProxy(context, key);
164
- });
165
- }
166
-
167
- exports.TRPCContext = TRPCContext;
168
- exports.contextProps = contextProps;
169
- exports.createQueryUtilsProxy = createQueryUtilsProxy;
170
- exports.createReactQueryUtils = createReactQueryUtils;
171
- exports.getQueryKey = getQueryKey;
172
- exports.getQueryKeyInternal = getQueryKeyInternal;
173
- exports.getQueryType = getQueryType;