@trpc/react-query 11.0.0-alpha-tmp-export-from-main.213 → 11.0.0-alpha-tmp-export-from-main.217

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 (39) hide show
  1. package/dist/createTRPCQueryUtils.js +16 -0
  2. package/dist/createTRPCQueryUtils.mjs +14 -0
  3. package/dist/createTRPCReact.js +58 -0
  4. package/dist/createTRPCReact.mjs +36 -0
  5. package/dist/index.js +10 -64
  6. package/dist/index.mjs +3 -40
  7. package/dist/internals/context.js +33 -0
  8. package/dist/internals/context.mjs +11 -0
  9. package/dist/internals/getClientArgs.js +16 -0
  10. package/dist/internals/getClientArgs.mjs +14 -0
  11. package/dist/internals/getQueryKey.d.ts.map +1 -1
  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-5d2fa367.js → shared/hooks/createHooksInternal.js} +28 -183
  21. package/dist/{createHooksInternal-e0b0564e.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-61a4601f.mjs → shared/proxy/utilsProxy.mjs} +3 -51
  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/src/internals/getQueryKey.ts +19 -1
  35. package/dist/createHooksInternal-4285c71a.js +0 -470
  36. package/dist/queryClient-1c8d7d8a.js +0 -8
  37. package/dist/utilsProxy-0b88c1e3.js +0 -161
  38. package/dist/utilsProxy-ff357a62.js +0 -128
  39. /package/dist/{queryClient-358a9a75.js → shared/queryClient.js} +0 -0
@@ -1,161 +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')) // for `utils.invalidate()` to match all queries (including vanilla react-query)
38
- // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
39
- return splitPath.length ? [
40
- splitPath
41
- ] : [];
42
- return [
43
- splitPath,
44
- {
45
- ...typeof input !== 'undefined' && {
46
- input: input
47
- },
48
- ...type && type !== 'any' && {
49
- type: type
50
- }
51
- }
52
- ];
53
- }
54
- /**
55
- * Method to extract the query key for a procedure
56
- * @param procedureOrRouter - procedure or AnyRouter
57
- * @param input - input to procedureOrRouter
58
- * @param type - defaults to `any`
59
- * @link https://trpc.io/docs/v11/getQueryKey
60
- */ function getQueryKey(..._params) {
61
- const [procedureOrRouter, input, type] = _params;
62
- // @ts-expect-error - we don't expose _def on the type layer
63
- const path = procedureOrRouter._def().path;
64
- const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
65
- return queryKey;
66
- }
67
-
68
- const contextProps = [
69
- 'client',
70
- 'ssrContext',
71
- 'ssrState',
72
- 'abortOnUnmount'
73
- ];
74
- const TRPCContext = React__namespace.createContext?.(null);
75
-
76
- const getQueryType = (utilName)=>{
77
- switch(utilName){
78
- case 'fetch':
79
- case 'ensureData':
80
- case 'prefetch':
81
- case 'getData':
82
- case 'setData':
83
- return 'query';
84
- case 'fetchInfinite':
85
- case 'prefetchInfinite':
86
- case 'getInfiniteData':
87
- case 'setInfiniteData':
88
- return 'infinite';
89
- case 'cancel':
90
- case 'invalidate':
91
- case 'refetch':
92
- case 'reset':
93
- return 'any';
94
- }
95
- };
96
- /**
97
- * @internal
98
- */ function createRecursiveUtilsProxy(context, key) {
99
- return core.createRecursiveProxy((opts)=>{
100
- const path = [
101
- key,
102
- ...opts.path
103
- ];
104
- const utilName = path.pop();
105
- const args = [
106
- ...opts.args
107
- ];
108
- const input = args.shift(); // args can now be spread when input removed
109
- const queryType = getQueryType(utilName);
110
- const queryKey = getQueryKeyInternal(path, input, queryType);
111
- const contextMap = {
112
- fetch: ()=>context.fetchQuery(queryKey, ...args),
113
- fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
114
- prefetch: ()=>context.prefetchQuery(queryKey, ...args),
115
- prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
116
- ensureData: ()=>context.ensureQueryData(queryKey, ...args),
117
- invalidate: ()=>context.invalidateQueries(queryKey, ...args),
118
- reset: ()=>context.resetQueries(queryKey, ...args),
119
- refetch: ()=>context.refetchQueries(queryKey, ...args),
120
- cancel: ()=>context.cancelQuery(queryKey, ...args),
121
- setData: ()=>{
122
- context.setQueryData(queryKey, args[0], args[1]);
123
- },
124
- setInfiniteData: ()=>{
125
- context.setInfiniteQueryData(queryKey, args[0], args[1]);
126
- },
127
- getData: ()=>context.getQueryData(queryKey),
128
- getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
129
- };
130
- return contextMap[utilName]();
131
- });
132
- }
133
- /**
134
- * @internal
135
- */ function createReactQueryUtils(context) {
136
- return core.createFlatProxy((key)=>{
137
- const contextName = key;
138
- if (contextName === 'client') {
139
- return client.createTRPCClientProxy(context.client);
140
- }
141
- if (contextProps.includes(contextName)) {
142
- return context[contextName];
143
- }
144
- return createRecursiveUtilsProxy(context, key);
145
- });
146
- }
147
- /**
148
- * @internal
149
- */ function createQueryUtilsProxy(context) {
150
- return core.createFlatProxy((key)=>{
151
- return createRecursiveUtilsProxy(context, key);
152
- });
153
- }
154
-
155
- exports.TRPCContext = TRPCContext;
156
- exports.contextProps = contextProps;
157
- exports.createQueryUtilsProxy = createQueryUtilsProxy;
158
- exports.createReactQueryUtils = createReactQueryUtils;
159
- exports.getQueryKey = getQueryKey;
160
- exports.getQueryKeyInternal = getQueryKeyInternal;
161
- exports.getQueryType = getQueryType;
@@ -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 };