@trpc/react-query 10.42.0 → 11.0.0-next.91

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 (97) hide show
  1. package/dist/bundle-analysis.json +208 -0
  2. package/dist/createHooksInternal-3d8ebfcf.mjs +481 -0
  3. package/dist/createHooksInternal-dce6e141.js +435 -0
  4. package/dist/createHooksInternal-e2034194.js +490 -0
  5. package/dist/createTRPCReact.d.ts +46 -45
  6. package/dist/createTRPCReact.d.ts.map +1 -1
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +8 -21
  10. package/dist/index.mjs +9 -21
  11. package/dist/internals/context.d.ts +42 -54
  12. package/dist/internals/context.d.ts.map +1 -1
  13. package/dist/internals/getClientArgs.d.ts +2 -1
  14. package/dist/internals/getClientArgs.d.ts.map +1 -1
  15. package/dist/internals/getQueryKey.d.ts +28 -13
  16. package/dist/internals/getQueryKey.d.ts.map +1 -1
  17. package/dist/internals/useQueries.d.ts +4 -4
  18. package/dist/internals/useQueries.d.ts.map +1 -1
  19. package/dist/server/index.d.ts +0 -6
  20. package/dist/server/index.d.ts.map +1 -1
  21. package/dist/server/index.js +52 -69
  22. package/dist/server/index.mjs +52 -69
  23. package/dist/server/ssgProxy.d.ts +23 -13
  24. package/dist/server/ssgProxy.d.ts.map +1 -1
  25. package/dist/shared/hooks/createHooksInternal.d.ts +35 -12
  26. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  27. package/dist/shared/hooks/createRootHooks.d.ts +0 -5
  28. package/dist/shared/hooks/createRootHooks.d.ts.map +1 -1
  29. package/dist/shared/hooks/types.d.ts +33 -18
  30. package/dist/shared/hooks/types.d.ts.map +1 -1
  31. package/dist/shared/index.js +9 -9
  32. package/dist/shared/index.mjs +3 -3
  33. package/dist/shared/polymorphism/mutationLike.d.ts +5 -5
  34. package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
  35. package/dist/shared/polymorphism/queryLike.d.ts +5 -5
  36. package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
  37. package/dist/shared/polymorphism/routerLike.d.ts +4 -3
  38. package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
  39. package/dist/shared/proxy/decorationProxy.d.ts +2 -2
  40. package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
  41. package/dist/shared/proxy/useQueriesProxy.d.ts +6 -6
  42. package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
  43. package/dist/shared/proxy/utilsProxy.d.ts +34 -31
  44. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  45. package/dist/shared/types.d.ts +0 -12
  46. package/dist/shared/types.d.ts.map +1 -1
  47. package/dist/utils/inferReactQueryProcedure.d.ts +7 -7
  48. package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
  49. package/dist/utilsProxy-00894da2.mjs +121 -0
  50. package/dist/utilsProxy-27bd93c1.js +128 -0
  51. package/dist/utilsProxy-7e396600.js +114 -0
  52. package/package.json +8 -14
  53. package/src/createTRPCReact.tsx +156 -135
  54. package/src/index.ts +0 -1
  55. package/src/internals/context.tsx +93 -164
  56. package/src/internals/getClientArgs.ts +9 -4
  57. package/src/internals/getQueryKey.ts +53 -24
  58. package/src/internals/useQueries.ts +7 -10
  59. package/src/server/index.ts +0 -8
  60. package/src/server/ssgProxy.ts +179 -34
  61. package/src/shared/hooks/createHooksInternal.tsx +298 -207
  62. package/src/shared/hooks/createRootHooks.tsx +0 -6
  63. package/src/shared/hooks/types.ts +87 -36
  64. package/src/shared/polymorphism/mutationLike.ts +11 -8
  65. package/src/shared/polymorphism/queryLike.ts +17 -12
  66. package/src/shared/polymorphism/routerLike.ts +15 -9
  67. package/src/shared/proxy/decorationProxy.ts +9 -31
  68. package/src/shared/proxy/useQueriesProxy.ts +23 -37
  69. package/src/shared/proxy/utilsProxy.ts +121 -95
  70. package/src/shared/types.ts +0 -12
  71. package/src/utils/inferReactQueryProcedure.ts +28 -30
  72. package/dist/context-4557b3d3.js +0 -38
  73. package/dist/createHooksInternal-2e69c447.js +0 -582
  74. package/dist/createHooksInternal-37b068e0.js +0 -510
  75. package/dist/createHooksInternal-bdff7171.mjs +0 -568
  76. package/dist/getArrayQueryKey-4bdb5cc2.js +0 -36
  77. package/dist/getArrayQueryKey-86134f8b.mjs +0 -34
  78. package/dist/internals/getArrayQueryKey.d.ts +0 -25
  79. package/dist/internals/getArrayQueryKey.d.ts.map +0 -1
  80. package/dist/interop.d.ts +0 -11
  81. package/dist/interop.d.ts.map +0 -1
  82. package/dist/server/types.d.ts +0 -14
  83. package/dist/server/types.d.ts.map +0 -1
  84. package/dist/shared/hooks/deprecated/createHooksInternal.d.ts +0 -63
  85. package/dist/shared/hooks/deprecated/createHooksInternal.d.ts.map +0 -1
  86. package/dist/ssg/index.d.ts +0 -15
  87. package/dist/ssg/index.d.ts.map +0 -1
  88. package/dist/ssg/ssg.d.ts +0 -16
  89. package/dist/ssg/ssg.d.ts.map +0 -1
  90. package/src/internals/getArrayQueryKey.ts +0 -46
  91. package/src/interop.ts +0 -29
  92. package/src/server/types.ts +0 -29
  93. package/src/shared/hooks/deprecated/createHooksInternal.tsx +0 -641
  94. package/src/ssg/index.tsx +0 -16
  95. package/src/ssg/ssg.ts +0 -139
  96. package/ssg/index.d.ts +0 -1
  97. package/ssg/index.js +0 -1
@@ -0,0 +1,128 @@
1
+ 'use strict';
2
+
3
+ var client = require('@trpc/client');
4
+ var shared = require('@trpc/server/shared');
5
+ var React = require('react');
6
+
7
+ /**
8
+ * To allow easy interactions with groups of related queries, such as
9
+ * invalidating all queries of a router, we use an array as the path when
10
+ * storing in tanstack query.
11
+ **/ function getQueryKeyInternal(path, input, type) {
12
+ // Construct a query key that is easy to destructure and flexible for
13
+ // partial selecting etc.
14
+ // https://github.com/trpc/trpc/issues/3128
15
+ // some parts of the path may be dot-separated, split them up
16
+ const splitPath = path.flatMap((part)=>part.split('.'));
17
+ if (!input && (!type || type === 'any')) // 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 ? [
20
+ splitPath
21
+ ] : [];
22
+ return [
23
+ splitPath,
24
+ {
25
+ ...typeof input !== 'undefined' && {
26
+ input: input
27
+ },
28
+ ...type && type !== 'any' && {
29
+ type: type
30
+ }
31
+ }
32
+ ];
33
+ }
34
+ /**
35
+ * Method to extract the query key for a procedure
36
+ * @param procedureOrRouter - procedure or AnyRouter
37
+ * @param input - input to procedureOrRouter
38
+ * @param type - defaults to `any`
39
+ * @link https://trpc.io/docs/getQueryKey
40
+ */ function getQueryKey(..._params) {
41
+ const [procedureOrRouter, input, type] = _params;
42
+ // @ts-expect-error - we don't expose _def on the type layer
43
+ const path = procedureOrRouter._def().path;
44
+ const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
45
+ return queryKey;
46
+ }
47
+
48
+ const contextProps = [
49
+ 'client',
50
+ 'ssrContext',
51
+ 'ssrState',
52
+ 'abortOnUnmount'
53
+ ];
54
+ const TRPCContext = /*#__PURE__*/ React.createContext(null);
55
+
56
+ const getQueryType = (utilName)=>{
57
+ switch(utilName){
58
+ case 'fetch':
59
+ case 'ensureData':
60
+ case 'prefetch':
61
+ case 'getData':
62
+ case 'setData':
63
+ return 'query';
64
+ case 'fetchInfinite':
65
+ case 'prefetchInfinite':
66
+ case 'getInfiniteData':
67
+ case 'setInfiniteData':
68
+ return 'infinite';
69
+ case 'cancel':
70
+ case 'invalidate':
71
+ case 'refetch':
72
+ case 'reset':
73
+ return 'any';
74
+ }
75
+ };
76
+ /**
77
+ * @internal
78
+ */ function createReactQueryUtils(context) {
79
+ return shared.createFlatProxy((key)=>{
80
+ const contextName = key;
81
+ if (contextName === 'client') {
82
+ return client.createTRPCClientProxy(context.client);
83
+ }
84
+ if (contextProps.includes(contextName)) {
85
+ return context[contextName];
86
+ }
87
+ return shared.createRecursiveProxy((opts)=>{
88
+ const path = [
89
+ key,
90
+ ...opts.path
91
+ ];
92
+ const utilName = path.pop();
93
+ const args = [
94
+ ...opts.args
95
+ ];
96
+ const input = args.shift(); // args can now be spread when input removed
97
+ const queryType = getQueryType(utilName);
98
+ const queryKey = getQueryKeyInternal(path, input, queryType);
99
+ const contextMap = {
100
+ fetch: ()=>context.fetchQuery(queryKey, ...args),
101
+ fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
102
+ prefetch: ()=>context.prefetchQuery(queryKey, ...args),
103
+ prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
104
+ ensureData: ()=>context.ensureQueryData(queryKey, ...args),
105
+ invalidate: ()=>context.invalidateQueries(queryKey, ...args),
106
+ reset: ()=>context.resetQueries(queryKey, ...args),
107
+ refetch: ()=>context.refetchQueries(queryKey, ...args),
108
+ cancel: ()=>context.cancelQuery(queryKey, ...args),
109
+ setData: ()=>{
110
+ context.setQueryData(queryKey, args[0], args[1]);
111
+ },
112
+ setInfiniteData: ()=>{
113
+ context.setInfiniteQueryData(queryKey, args[0], args[1]);
114
+ },
115
+ getData: ()=>context.getQueryData(queryKey),
116
+ getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
117
+ };
118
+ return contextMap[utilName]();
119
+ });
120
+ });
121
+ }
122
+
123
+ exports.TRPCContext = TRPCContext;
124
+ exports.contextProps = contextProps;
125
+ exports.createReactQueryUtils = createReactQueryUtils;
126
+ exports.getQueryKey = getQueryKey;
127
+ exports.getQueryKeyInternal = getQueryKeyInternal;
128
+ exports.getQueryType = getQueryType;
@@ -0,0 +1,114 @@
1
+ import { createTRPCClientProxy } from '@trpc/client';
2
+ import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
3
+ import { createContext } 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/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 = 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 createReactQueryUtils(context) {
75
+ return createFlatProxy((key) => {
76
+ const contextName = key;
77
+ if (contextName === 'client') {
78
+ return createTRPCClientProxy(context.client);
79
+ }
80
+ if (contextProps.includes(contextName)) {
81
+ return context[contextName];
82
+ }
83
+ return createRecursiveProxy((opts) => {
84
+ const path = [key, ...opts.path];
85
+ const utilName = path.pop();
86
+ const args = [...opts.args];
87
+ const input = args.shift(); // args can now be spread when input removed
88
+ const queryType = getQueryType(utilName);
89
+ const queryKey = getQueryKeyInternal(path, input, queryType);
90
+ const contextMap = {
91
+ fetch: () => context.fetchQuery(queryKey, ...args),
92
+ fetchInfinite: () => context.fetchInfiniteQuery(queryKey, args[0]),
93
+ prefetch: () => context.prefetchQuery(queryKey, ...args),
94
+ prefetchInfinite: () => context.prefetchInfiniteQuery(queryKey, args[0]),
95
+ ensureData: () => context.ensureQueryData(queryKey, ...args),
96
+ invalidate: () => context.invalidateQueries(queryKey, ...args),
97
+ reset: () => context.resetQueries(queryKey, ...args),
98
+ refetch: () => context.refetchQueries(queryKey, ...args),
99
+ cancel: () => context.cancelQuery(queryKey, ...args),
100
+ setData: () => {
101
+ context.setQueryData(queryKey, args[0], args[1]);
102
+ },
103
+ setInfiniteData: () => {
104
+ context.setInfiniteQueryData(queryKey, args[0], args[1]);
105
+ },
106
+ getData: () => context.getQueryData(queryKey),
107
+ getInfiniteData: () => context.getInfiniteQueryData(queryKey),
108
+ };
109
+ return contextMap[utilName]();
110
+ });
111
+ });
112
+ }
113
+
114
+ export { TRPCContext as T, getQueryKeyInternal as a, getQueryType as b, createReactQueryUtils as c, contextProps as d, getQueryKey as g };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/react-query",
3
- "version": "10.42.0",
3
+ "version": "11.0.0-next.91+ca021e61",
4
4
  "description": "The tRPC React library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -36,11 +36,6 @@
36
36
  "import": "./dist/shared/index.mjs",
37
37
  "require": "./dist/shared/index.js",
38
38
  "default": "./dist/shared/index.js"
39
- },
40
- "./ssg": {
41
- "import": "./dist/ssg/index.mjs",
42
- "require": "./dist/ssg/index.js",
43
- "default": "./dist/ssg/index.js"
44
39
  }
45
40
  },
46
41
  "files": [
@@ -50,7 +45,6 @@
50
45
  "package.json",
51
46
  "server",
52
47
  "shared",
53
- "ssg",
54
48
  "!**/*.test.*"
55
49
  ],
56
50
  "eslintConfig": {
@@ -63,16 +57,16 @@
63
57
  }
64
58
  },
65
59
  "peerDependencies": {
66
- "@tanstack/react-query": "^4.18.0",
67
- "@trpc/client": "10.42.0",
68
- "@trpc/server": "10.42.0",
60
+ "@tanstack/react-query": "^5.0.0",
61
+ "@trpc/client": "11.0.0-next.91+ca021e61",
62
+ "@trpc/server": "11.0.0-next.91+ca021e61",
69
63
  "react": ">=16.8.0",
70
64
  "react-dom": ">=16.8.0"
71
65
  },
72
66
  "devDependencies": {
73
- "@tanstack/react-query": "^4.18.0",
74
- "@trpc/client": "10.42.0",
75
- "@trpc/server": "10.42.0",
67
+ "@tanstack/react-query": "^5.0.0",
68
+ "@trpc/client": "11.0.0-next.91+ca021e61",
69
+ "@trpc/server": "11.0.0-next.91+ca021e61",
76
70
  "@types/express": "^4.17.17",
77
71
  "@types/node": "^18.16.16",
78
72
  "@types/react": "^18.2.8",
@@ -91,5 +85,5 @@
91
85
  "funding": [
92
86
  "https://trpc.io/sponsor"
93
87
  ],
94
- "gitHead": "b6853a63b41c979ec0e4f1a318eec2887b7c58bf"
88
+ "gitHead": "ca021e61ba8e6eb6e1715f124489cda75a00b5aa"
95
89
  }