@trpc/react-query 11.0.0-next-beta.205 → 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.
Files changed (38) hide show
  1. package/dist/bundle-analysis.json +40 -40
  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
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ var React = require('react');
4
+
5
+ function _interopNamespaceDefault(e) {
6
+ var n = Object.create(null);
7
+ if (e) {
8
+ Object.keys(e).forEach(function (k) {
9
+ if (k !== 'default') {
10
+ var d = Object.getOwnPropertyDescriptor(e, k);
11
+ Object.defineProperty(n, k, d.get ? d : {
12
+ enumerable: true,
13
+ get: function () { return e[k]; }
14
+ });
15
+ }
16
+ });
17
+ }
18
+ n.default = e;
19
+ return Object.freeze(n);
20
+ }
21
+
22
+ var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
23
+
24
+ /**
25
+ * Makes a stable reference of the `trpc` prop
26
+ */ function useHookResult(value) {
27
+ const ref = React__namespace.useRef(value);
28
+ ref.current.path = value.path;
29
+ return ref.current;
30
+ }
31
+
32
+ exports.useHookResult = useHookResult;
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * Makes a stable reference of the `trpc` prop
5
+ */ function useHookResult(value) {
6
+ const ref = React.useRef(value);
7
+ ref.current.path = value.path;
8
+ return ref.current;
9
+ }
10
+
11
+ export { useHookResult };
@@ -1,107 +1,7 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
3
+ var ssgProxy = require('./ssgProxy.js');
4
4
 
5
- var reactQuery = require('@tanstack/react-query');
6
- var client = require('@trpc/client');
7
- var core = require('@trpc/core');
8
- var utilsProxy = require('../utilsProxy-4f6da312.js');
9
- require('react');
10
- var queryClient = require('../queryClient-358a9a75.js');
11
5
 
12
- /**
13
- * Create functions you can use for server-side rendering / static generation
14
- * @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
15
- */ function createServerSideHelpers(opts) {
16
- const queryClient$1 = queryClient.getQueryClient(opts);
17
- const resolvedOpts = (()=>{
18
- if ('router' in opts) {
19
- const { transformer , ctx , router } = opts;
20
- return {
21
- serialize: transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj,
22
- query: (queryOpts)=>{
23
- return core.callProcedure({
24
- procedures: router._def.procedures,
25
- path: queryOpts.path,
26
- getRawInput: async ()=>queryOpts.input,
27
- ctx,
28
- type: 'query'
29
- });
30
- }
31
- };
32
- }
33
- const { client: client$1 } = opts;
34
- const untypedClient = client$1 instanceof client.TRPCUntypedClient ? client$1 : client.getUntypedClient(client$1);
35
- return {
36
- query: (queryOpts)=>untypedClient.query(queryOpts.path, queryOpts.input),
37
- serialize: (obj)=>untypedClient.runtime.transformer.serialize(obj)
38
- };
39
- })();
40
- function _dehydrate(opts = {
41
- shouldDehydrateQuery () {
42
- // makes sure to serialize errors
43
- return true;
44
- }
45
- }) {
46
- const before = reactQuery.dehydrate(queryClient$1, opts);
47
- const after = resolvedOpts.serialize(before);
48
- return after;
49
- }
50
- return core.createFlatProxy((key)=>{
51
- if (key === 'queryClient') return queryClient$1;
52
- if (key === 'dehydrate') return _dehydrate;
53
- return core.createRecursiveProxy((opts)=>{
54
- const args = opts.args;
55
- const input = args[0];
56
- const arrayPath = [
57
- key,
58
- ...opts.path
59
- ];
60
- const utilName = arrayPath.pop();
61
- const queryFn = ()=>resolvedOpts.query({
62
- path: arrayPath.join('.'),
63
- input
64
- });
65
- const queryKey = utilsProxy.getQueryKeyInternal(arrayPath, input, utilsProxy.getQueryType(utilName));
66
- const helperMap = {
67
- fetch: ()=>{
68
- const args1 = args[1];
69
- return queryClient$1.fetchQuery({
70
- ...args1,
71
- queryKey,
72
- queryFn
73
- });
74
- },
75
- fetchInfinite: ()=>{
76
- const args1 = args[1];
77
- return queryClient$1.fetchInfiniteQuery({
78
- ...args1,
79
- queryKey,
80
- queryFn,
81
- initialPageParam: args1?.initialCursor ?? null
82
- });
83
- },
84
- prefetch: ()=>{
85
- const args1 = args[1];
86
- return queryClient$1.prefetchQuery({
87
- ...args1,
88
- queryKey,
89
- queryFn
90
- });
91
- },
92
- prefetchInfinite: ()=>{
93
- const args1 = args[1];
94
- return queryClient$1.prefetchInfiniteQuery({
95
- ...args1,
96
- queryKey,
97
- queryFn,
98
- initialPageParam: args1?.initialCursor ?? null
99
- });
100
- }
101
- };
102
- return helperMap[utilName]();
103
- });
104
- });
105
- }
106
6
 
107
- exports.createServerSideHelpers = createServerSideHelpers;
7
+ exports.createServerSideHelpers = ssgProxy.createServerSideHelpers;
@@ -1,103 +1 @@
1
- import { dehydrate } from '@tanstack/react-query';
2
- import { TRPCUntypedClient, getUntypedClient } from '@trpc/client';
3
- import { callProcedure, createFlatProxy, createRecursiveProxy } from '@trpc/core';
4
- import { b as getQueryKeyInternal, d as getQueryType } from '../utilsProxy-12979321.mjs';
5
- import 'react';
6
- import { g as getQueryClient } from '../queryClient-4d766c0c.mjs';
7
-
8
- /**
9
- * Create functions you can use for server-side rendering / static generation
10
- * @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
11
- */ function createServerSideHelpers(opts) {
12
- const queryClient = getQueryClient(opts);
13
- const resolvedOpts = (()=>{
14
- if ('router' in opts) {
15
- const { transformer , ctx , router } = opts;
16
- return {
17
- serialize: transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj,
18
- query: (queryOpts)=>{
19
- return callProcedure({
20
- procedures: router._def.procedures,
21
- path: queryOpts.path,
22
- getRawInput: async ()=>queryOpts.input,
23
- ctx,
24
- type: 'query'
25
- });
26
- }
27
- };
28
- }
29
- const { client } = opts;
30
- const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
31
- return {
32
- query: (queryOpts)=>untypedClient.query(queryOpts.path, queryOpts.input),
33
- serialize: (obj)=>untypedClient.runtime.transformer.serialize(obj)
34
- };
35
- })();
36
- function _dehydrate(opts = {
37
- shouldDehydrateQuery () {
38
- // makes sure to serialize errors
39
- return true;
40
- }
41
- }) {
42
- const before = dehydrate(queryClient, opts);
43
- const after = resolvedOpts.serialize(before);
44
- return after;
45
- }
46
- return createFlatProxy((key)=>{
47
- if (key === 'queryClient') return queryClient;
48
- if (key === 'dehydrate') return _dehydrate;
49
- return createRecursiveProxy((opts)=>{
50
- const args = opts.args;
51
- const input = args[0];
52
- const arrayPath = [
53
- key,
54
- ...opts.path
55
- ];
56
- const utilName = arrayPath.pop();
57
- const queryFn = ()=>resolvedOpts.query({
58
- path: arrayPath.join('.'),
59
- input
60
- });
61
- const queryKey = getQueryKeyInternal(arrayPath, input, getQueryType(utilName));
62
- const helperMap = {
63
- fetch: ()=>{
64
- const args1 = args[1];
65
- return queryClient.fetchQuery({
66
- ...args1,
67
- queryKey,
68
- queryFn
69
- });
70
- },
71
- fetchInfinite: ()=>{
72
- const args1 = args[1];
73
- return queryClient.fetchInfiniteQuery({
74
- ...args1,
75
- queryKey,
76
- queryFn,
77
- initialPageParam: args1?.initialCursor ?? null
78
- });
79
- },
80
- prefetch: ()=>{
81
- const args1 = args[1];
82
- return queryClient.prefetchQuery({
83
- ...args1,
84
- queryKey,
85
- queryFn
86
- });
87
- },
88
- prefetchInfinite: ()=>{
89
- const args1 = args[1];
90
- return queryClient.prefetchInfiniteQuery({
91
- ...args1,
92
- queryKey,
93
- queryFn,
94
- initialPageParam: args1?.initialCursor ?? null
95
- });
96
- }
97
- };
98
- return helperMap[utilName]();
99
- });
100
- });
101
- }
102
-
103
- export { createServerSideHelpers };
1
+ export { createServerSideHelpers } from './ssgProxy.mjs';
@@ -0,0 +1,107 @@
1
+ 'use strict';
2
+
3
+ var reactQuery = require('@tanstack/react-query');
4
+ var client = require('@trpc/client');
5
+ var core = require('@trpc/core');
6
+ var getQueryKey = require('../internals/getQueryKey.js');
7
+ var utilsProxy = require('../shared/proxy/utilsProxy.js');
8
+ require('react');
9
+ require('../internals/context.js');
10
+ var queryClient = require('../shared/queryClient.js');
11
+
12
+ /**
13
+ * Create functions you can use for server-side rendering / static generation
14
+ * @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
15
+ */ function createServerSideHelpers(opts) {
16
+ const queryClient$1 = queryClient.getQueryClient(opts);
17
+ const resolvedOpts = (()=>{
18
+ if ('router' in opts) {
19
+ const { transformer , ctx , router } = opts;
20
+ return {
21
+ serialize: transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj,
22
+ query: (queryOpts)=>{
23
+ return core.callProcedure({
24
+ procedures: router._def.procedures,
25
+ path: queryOpts.path,
26
+ getRawInput: async ()=>queryOpts.input,
27
+ ctx,
28
+ type: 'query'
29
+ });
30
+ }
31
+ };
32
+ }
33
+ const { client: client$1 } = opts;
34
+ const untypedClient = client$1 instanceof client.TRPCUntypedClient ? client$1 : client.getUntypedClient(client$1);
35
+ return {
36
+ query: (queryOpts)=>untypedClient.query(queryOpts.path, queryOpts.input),
37
+ serialize: (obj)=>untypedClient.runtime.transformer.serialize(obj)
38
+ };
39
+ })();
40
+ function _dehydrate(opts = {
41
+ shouldDehydrateQuery () {
42
+ // makes sure to serialize errors
43
+ return true;
44
+ }
45
+ }) {
46
+ const before = reactQuery.dehydrate(queryClient$1, opts);
47
+ const after = resolvedOpts.serialize(before);
48
+ return after;
49
+ }
50
+ return core.createFlatProxy((key)=>{
51
+ if (key === 'queryClient') return queryClient$1;
52
+ if (key === 'dehydrate') return _dehydrate;
53
+ return core.createRecursiveProxy((opts)=>{
54
+ const args = opts.args;
55
+ const input = args[0];
56
+ const arrayPath = [
57
+ key,
58
+ ...opts.path
59
+ ];
60
+ const utilName = arrayPath.pop();
61
+ const queryFn = ()=>resolvedOpts.query({
62
+ path: arrayPath.join('.'),
63
+ input
64
+ });
65
+ const queryKey = getQueryKey.getQueryKeyInternal(arrayPath, input, utilsProxy.getQueryType(utilName));
66
+ const helperMap = {
67
+ fetch: ()=>{
68
+ const args1 = args[1];
69
+ return queryClient$1.fetchQuery({
70
+ ...args1,
71
+ queryKey,
72
+ queryFn
73
+ });
74
+ },
75
+ fetchInfinite: ()=>{
76
+ const args1 = args[1];
77
+ return queryClient$1.fetchInfiniteQuery({
78
+ ...args1,
79
+ queryKey,
80
+ queryFn,
81
+ initialPageParam: args1?.initialCursor ?? null
82
+ });
83
+ },
84
+ prefetch: ()=>{
85
+ const args1 = args[1];
86
+ return queryClient$1.prefetchQuery({
87
+ ...args1,
88
+ queryKey,
89
+ queryFn
90
+ });
91
+ },
92
+ prefetchInfinite: ()=>{
93
+ const args1 = args[1];
94
+ return queryClient$1.prefetchInfiniteQuery({
95
+ ...args1,
96
+ queryKey,
97
+ queryFn,
98
+ initialPageParam: args1?.initialCursor ?? null
99
+ });
100
+ }
101
+ };
102
+ return helperMap[utilName]();
103
+ });
104
+ });
105
+ }
106
+
107
+ exports.createServerSideHelpers = createServerSideHelpers;
@@ -0,0 +1,105 @@
1
+ import { dehydrate } from '@tanstack/react-query';
2
+ import { TRPCUntypedClient, getUntypedClient } from '@trpc/client';
3
+ import { callProcedure, createFlatProxy, createRecursiveProxy } from '@trpc/core';
4
+ import { getQueryKeyInternal } from '../internals/getQueryKey.mjs';
5
+ import { getQueryType } from '../shared/proxy/utilsProxy.mjs';
6
+ import 'react';
7
+ import '../internals/context.mjs';
8
+ import { getQueryClient } from '../shared/queryClient.mjs';
9
+
10
+ /**
11
+ * Create functions you can use for server-side rendering / static generation
12
+ * @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
13
+ */ function createServerSideHelpers(opts) {
14
+ const queryClient = getQueryClient(opts);
15
+ const resolvedOpts = (()=>{
16
+ if ('router' in opts) {
17
+ const { transformer , ctx , router } = opts;
18
+ return {
19
+ serialize: transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj,
20
+ query: (queryOpts)=>{
21
+ return callProcedure({
22
+ procedures: router._def.procedures,
23
+ path: queryOpts.path,
24
+ getRawInput: async ()=>queryOpts.input,
25
+ ctx,
26
+ type: 'query'
27
+ });
28
+ }
29
+ };
30
+ }
31
+ const { client } = opts;
32
+ const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
33
+ return {
34
+ query: (queryOpts)=>untypedClient.query(queryOpts.path, queryOpts.input),
35
+ serialize: (obj)=>untypedClient.runtime.transformer.serialize(obj)
36
+ };
37
+ })();
38
+ function _dehydrate(opts = {
39
+ shouldDehydrateQuery () {
40
+ // makes sure to serialize errors
41
+ return true;
42
+ }
43
+ }) {
44
+ const before = dehydrate(queryClient, opts);
45
+ const after = resolvedOpts.serialize(before);
46
+ return after;
47
+ }
48
+ return createFlatProxy((key)=>{
49
+ if (key === 'queryClient') return queryClient;
50
+ if (key === 'dehydrate') return _dehydrate;
51
+ return createRecursiveProxy((opts)=>{
52
+ const args = opts.args;
53
+ const input = args[0];
54
+ const arrayPath = [
55
+ key,
56
+ ...opts.path
57
+ ];
58
+ const utilName = arrayPath.pop();
59
+ const queryFn = ()=>resolvedOpts.query({
60
+ path: arrayPath.join('.'),
61
+ input
62
+ });
63
+ const queryKey = getQueryKeyInternal(arrayPath, input, getQueryType(utilName));
64
+ const helperMap = {
65
+ fetch: ()=>{
66
+ const args1 = args[1];
67
+ return queryClient.fetchQuery({
68
+ ...args1,
69
+ queryKey,
70
+ queryFn
71
+ });
72
+ },
73
+ fetchInfinite: ()=>{
74
+ const args1 = args[1];
75
+ return queryClient.fetchInfiniteQuery({
76
+ ...args1,
77
+ queryKey,
78
+ queryFn,
79
+ initialPageParam: args1?.initialCursor ?? null
80
+ });
81
+ },
82
+ prefetch: ()=>{
83
+ const args1 = args[1];
84
+ return queryClient.prefetchQuery({
85
+ ...args1,
86
+ queryKey,
87
+ queryFn
88
+ });
89
+ },
90
+ prefetchInfinite: ()=>{
91
+ const args1 = args[1];
92
+ return queryClient.prefetchInfiniteQuery({
93
+ ...args1,
94
+ queryKey,
95
+ queryFn,
96
+ initialPageParam: args1?.initialCursor ?? null
97
+ });
98
+ }
99
+ };
100
+ return helperMap[utilName]();
101
+ });
102
+ });
103
+ }
104
+
105
+ export { createServerSideHelpers };