@trpc/react-query 11.0.0-alpha-tmp-react-sideeffects-import.202 → 11.0.0-alpha-tmp-ahmed-rollup-v4.203
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/createTRPCQueryUtils.js +15 -0
- package/dist/createTRPCQueryUtils.mjs +13 -0
- package/dist/createTRPCReact.js +38 -0
- package/dist/createTRPCReact.mjs +35 -0
- package/dist/index.js +10 -64
- package/dist/index.mjs +3 -40
- package/dist/internals/context.d.ts +2 -2
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/context.js +14 -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.js +45 -0
- package/dist/internals/getQueryKey.mjs +42 -0
- package/dist/internals/useHookResult.js +13 -0
- package/dist/internals/useHookResult.mjs +11 -0
- package/dist/server/index.js +2 -102
- package/dist/server/index.mjs +1 -103
- package/dist/server/ssgProxy.js +106 -0
- package/dist/server/ssgProxy.mjs +104 -0
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/{createHooksInternal-5d2fa367.js → shared/hooks/createHooksInternal.js} +33 -207
- package/dist/{createHooksInternal-e0b0564e.mjs → shared/hooks/createHooksInternal.mjs} +16 -166
- package/dist/shared/index.js +13 -15
- package/dist/shared/index.mjs +7 -7
- package/dist/shared/proxy/decorationProxy.js +31 -0
- package/dist/shared/proxy/decorationProxy.mjs +29 -0
- package/dist/shared/proxy/useQueriesProxy.js +25 -0
- package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
- package/dist/shared/proxy/utilsProxy.js +89 -0
- package/dist/{utilsProxy-61a4601f.mjs → shared/proxy/utilsProxy.mjs} +3 -51
- package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
- package/dist/utils/createUtilityFunctions.js +94 -0
- package/dist/utils/createUtilityFunctions.mjs +92 -0
- package/package.json +6 -6
- package/src/createTRPCReact.tsx +2 -2
- package/src/internals/context.tsx +2 -2
- package/src/internals/useHookResult.ts +2 -2
- package/src/shared/hooks/createHooksInternal.tsx +8 -10
- 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
|
@@ -0,0 +1,106 @@
|
|
|
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
|
+
var queryClient = require('../shared/queryClient.js');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Create functions you can use for server-side rendering / static generation
|
|
13
|
+
* @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
|
14
|
+
*/ function createServerSideHelpers(opts) {
|
|
15
|
+
const queryClient$1 = queryClient.getQueryClient(opts);
|
|
16
|
+
const resolvedOpts = (()=>{
|
|
17
|
+
if ('router' in opts) {
|
|
18
|
+
const { transformer , ctx , router } = opts;
|
|
19
|
+
return {
|
|
20
|
+
serialize: transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj,
|
|
21
|
+
query: (queryOpts)=>{
|
|
22
|
+
return core.callProcedure({
|
|
23
|
+
procedures: router._def.procedures,
|
|
24
|
+
path: queryOpts.path,
|
|
25
|
+
getRawInput: async ()=>queryOpts.input,
|
|
26
|
+
ctx,
|
|
27
|
+
type: 'query'
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
const { client: client$1 } = opts;
|
|
33
|
+
const untypedClient = client$1 instanceof client.TRPCUntypedClient ? client$1 : client.getUntypedClient(client$1);
|
|
34
|
+
return {
|
|
35
|
+
query: (queryOpts)=>untypedClient.query(queryOpts.path, queryOpts.input),
|
|
36
|
+
serialize: (obj)=>untypedClient.runtime.transformer.serialize(obj)
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
function _dehydrate(opts = {
|
|
40
|
+
shouldDehydrateQuery () {
|
|
41
|
+
// makes sure to serialize errors
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}) {
|
|
45
|
+
const before = reactQuery.dehydrate(queryClient$1, opts);
|
|
46
|
+
const after = resolvedOpts.serialize(before);
|
|
47
|
+
return after;
|
|
48
|
+
}
|
|
49
|
+
return core.createFlatProxy((key)=>{
|
|
50
|
+
if (key === 'queryClient') return queryClient$1;
|
|
51
|
+
if (key === 'dehydrate') return _dehydrate;
|
|
52
|
+
return core.createRecursiveProxy((opts)=>{
|
|
53
|
+
const args = opts.args;
|
|
54
|
+
const input = args[0];
|
|
55
|
+
const arrayPath = [
|
|
56
|
+
key,
|
|
57
|
+
...opts.path
|
|
58
|
+
];
|
|
59
|
+
const utilName = arrayPath.pop();
|
|
60
|
+
const queryFn = ()=>resolvedOpts.query({
|
|
61
|
+
path: arrayPath.join('.'),
|
|
62
|
+
input
|
|
63
|
+
});
|
|
64
|
+
const queryKey = getQueryKey.getQueryKeyInternal(arrayPath, input, utilsProxy.getQueryType(utilName));
|
|
65
|
+
const helperMap = {
|
|
66
|
+
fetch: ()=>{
|
|
67
|
+
const args1 = args[1];
|
|
68
|
+
return queryClient$1.fetchQuery({
|
|
69
|
+
...args1,
|
|
70
|
+
queryKey,
|
|
71
|
+
queryFn
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
fetchInfinite: ()=>{
|
|
75
|
+
const args1 = args[1];
|
|
76
|
+
return queryClient$1.fetchInfiniteQuery({
|
|
77
|
+
...args1,
|
|
78
|
+
queryKey,
|
|
79
|
+
queryFn,
|
|
80
|
+
initialPageParam: args1?.initialCursor ?? null
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
prefetch: ()=>{
|
|
84
|
+
const args1 = args[1];
|
|
85
|
+
return queryClient$1.prefetchQuery({
|
|
86
|
+
...args1,
|
|
87
|
+
queryKey,
|
|
88
|
+
queryFn
|
|
89
|
+
});
|
|
90
|
+
},
|
|
91
|
+
prefetchInfinite: ()=>{
|
|
92
|
+
const args1 = args[1];
|
|
93
|
+
return queryClient$1.prefetchInfiniteQuery({
|
|
94
|
+
...args1,
|
|
95
|
+
queryKey,
|
|
96
|
+
queryFn,
|
|
97
|
+
initialPageParam: args1?.initialCursor ?? null
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
return helperMap[utilName]();
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
exports.createServerSideHelpers = createServerSideHelpers;
|
|
@@ -0,0 +1,104 @@
|
|
|
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 { getQueryClient } from '../shared/queryClient.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Create functions you can use for server-side rendering / static generation
|
|
11
|
+
* @link https://trpc.io/docs/v11/client/nextjs/server-side-helpers
|
|
12
|
+
*/ function createServerSideHelpers(opts) {
|
|
13
|
+
const queryClient = getQueryClient(opts);
|
|
14
|
+
const resolvedOpts = (()=>{
|
|
15
|
+
if ('router' in opts) {
|
|
16
|
+
const { transformer , ctx , router } = opts;
|
|
17
|
+
return {
|
|
18
|
+
serialize: transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj,
|
|
19
|
+
query: (queryOpts)=>{
|
|
20
|
+
return callProcedure({
|
|
21
|
+
procedures: router._def.procedures,
|
|
22
|
+
path: queryOpts.path,
|
|
23
|
+
getRawInput: async ()=>queryOpts.input,
|
|
24
|
+
ctx,
|
|
25
|
+
type: 'query'
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const { client } = opts;
|
|
31
|
+
const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
|
32
|
+
return {
|
|
33
|
+
query: (queryOpts)=>untypedClient.query(queryOpts.path, queryOpts.input),
|
|
34
|
+
serialize: (obj)=>untypedClient.runtime.transformer.serialize(obj)
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
function _dehydrate(opts = {
|
|
38
|
+
shouldDehydrateQuery () {
|
|
39
|
+
// makes sure to serialize errors
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
}) {
|
|
43
|
+
const before = dehydrate(queryClient, opts);
|
|
44
|
+
const after = resolvedOpts.serialize(before);
|
|
45
|
+
return after;
|
|
46
|
+
}
|
|
47
|
+
return createFlatProxy((key)=>{
|
|
48
|
+
if (key === 'queryClient') return queryClient;
|
|
49
|
+
if (key === 'dehydrate') return _dehydrate;
|
|
50
|
+
return createRecursiveProxy((opts)=>{
|
|
51
|
+
const args = opts.args;
|
|
52
|
+
const input = args[0];
|
|
53
|
+
const arrayPath = [
|
|
54
|
+
key,
|
|
55
|
+
...opts.path
|
|
56
|
+
];
|
|
57
|
+
const utilName = arrayPath.pop();
|
|
58
|
+
const queryFn = ()=>resolvedOpts.query({
|
|
59
|
+
path: arrayPath.join('.'),
|
|
60
|
+
input
|
|
61
|
+
});
|
|
62
|
+
const queryKey = getQueryKeyInternal(arrayPath, input, getQueryType(utilName));
|
|
63
|
+
const helperMap = {
|
|
64
|
+
fetch: ()=>{
|
|
65
|
+
const args1 = args[1];
|
|
66
|
+
return queryClient.fetchQuery({
|
|
67
|
+
...args1,
|
|
68
|
+
queryKey,
|
|
69
|
+
queryFn
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
fetchInfinite: ()=>{
|
|
73
|
+
const args1 = args[1];
|
|
74
|
+
return queryClient.fetchInfiniteQuery({
|
|
75
|
+
...args1,
|
|
76
|
+
queryKey,
|
|
77
|
+
queryFn,
|
|
78
|
+
initialPageParam: args1?.initialCursor ?? null
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
prefetch: ()=>{
|
|
82
|
+
const args1 = args[1];
|
|
83
|
+
return queryClient.prefetchQuery({
|
|
84
|
+
...args1,
|
|
85
|
+
queryKey,
|
|
86
|
+
queryFn
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
prefetchInfinite: ()=>{
|
|
90
|
+
const args1 = args[1];
|
|
91
|
+
return queryClient.prefetchInfiniteQuery({
|
|
92
|
+
...args1,
|
|
93
|
+
queryKey,
|
|
94
|
+
queryFn,
|
|
95
|
+
initialPageParam: args1?.initialCursor ?? null
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return helperMap[utilName]();
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { createServerSideHelpers };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAY,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAM1E,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,sBAAsB,EAAuB,MAAM,UAAU,CAAC;AAC5E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EAEZ,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC1B,mCAAmC,EACnC,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,MAAM,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC;;;;;
|
|
1
|
+
{"version":3,"file":"createHooksInternal.d.ts","sourceRoot":"","sources":["../../../src/shared/hooks/createHooksInternal.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAExD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,KAAK,EAAY,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAM1E,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACvB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,KAAK,EAAE,sBAAsB,EAAuB,MAAM,UAAU,CAAC;AAC5E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EAEZ,kBAAkB,EAClB,2BAA2B,EAC3B,0BAA0B,EAC1B,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EAClB,0BAA0B,EAC1B,mCAAmC,EACnC,kCAAkC,EAClC,2BAA2B,EAC3B,0BAA0B,EAC3B,MAAM,SAAS,CAAC;AAEjB;;GAEG;AACH,wBAAgB,eAAe,CAC7B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,EACrB,MAAM,CAAC,EAAE,sBAAsB,CAAC,OAAO,CAAC;;;;;qBAiFhC,MAAM,EAAE,SACP,OAAO;6BAwDR,MAAM,EAAE,SACP,OAAO;;;wBAsCR,MAAM,EAAE;4BAuCR,MAAM,EAAE,SACP,OAAO;;6BA6CR,MAAM,EAAE,SACP,OAAO;qCAoER,MAAM,EAAE,SACP,OAAO;EAsIjB;AAED;;;GAGG;AACH,cAAM,OAAO,CAAC,OAAO,SAAS,SAAS,EAAE,WAAW,GAAG,OAAO;IAC5D,EAAE;;;;;;;;;;;;;;;CAGH;AAED,KAAK,iBAAiB,CAAC,KAAK,IAAI,KAAK,SAAS,CAC5C,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACtB,MAAM,CAAC,GACR,CAAC,GACD,KAAK,CAAC;AACV,KAAK,OAAO,CAAC,OAAO,SAAS,SAAS,EAAE,WAAW,GAAG,OAAO,IAAI,OAAO,CACtE,OAAO,EACP,WAAW,CACZ,CAAC,IAAI,CAAC,CAAC;AAER;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,WAAW,GAAG,OAAO,IACnB,iBAAiB,CAAC,OAAO,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC,CAAC"}
|
|
@@ -1,204 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var core = require('@trpc/core');
|
|
4
3
|
var reactQuery = require('@tanstack/react-query');
|
|
5
4
|
var client = require('@trpc/client');
|
|
6
5
|
var React = require('react');
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Object.keys(e).forEach(function (k) {
|
|
14
|
-
if (k !== 'default') {
|
|
15
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
16
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function () { return e[k]; }
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
n["default"] = e;
|
|
24
|
-
return Object.freeze(n);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Create proxy for decorating procedures
|
|
31
|
-
* @internal
|
|
32
|
-
*/ function createReactDecoration(name, hooks) {
|
|
33
|
-
return core.createRecursiveProxy(({ path , args })=>{
|
|
34
|
-
const pathCopy = [
|
|
35
|
-
name,
|
|
36
|
-
...path
|
|
37
|
-
];
|
|
38
|
-
// The last arg is for instance `.useMutation` or `.useQuery()`
|
|
39
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
40
|
-
const lastArg = pathCopy.pop();
|
|
41
|
-
if (lastArg === 'useMutation') {
|
|
42
|
-
return hooks[lastArg](pathCopy, ...args);
|
|
43
|
-
}
|
|
44
|
-
if (lastArg === '_def') {
|
|
45
|
-
return {
|
|
46
|
-
path: pathCopy
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
const [input, ...rest] = args;
|
|
50
|
-
const opts = rest[0] || {};
|
|
51
|
-
return hooks[lastArg](pathCopy, input, opts);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Create proxy for `useQueries` options
|
|
57
|
-
* @internal
|
|
58
|
-
*/ function createUseQueries(client) {
|
|
59
|
-
return core.createRecursiveProxy((opts)=>{
|
|
60
|
-
const arrayPath = opts.path;
|
|
61
|
-
const dotPath = arrayPath.join('.');
|
|
62
|
-
const [input, _opts] = opts.args;
|
|
63
|
-
const options = {
|
|
64
|
-
queryKey: utilsProxy.getQueryKeyInternal(arrayPath, input, 'query'),
|
|
65
|
-
queryFn: ()=>{
|
|
66
|
-
return client.query(dotPath, input, _opts?.trpc);
|
|
67
|
-
},
|
|
68
|
-
..._opts
|
|
69
|
-
};
|
|
70
|
-
return options;
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* @internal
|
|
76
|
-
*/ function getClientArgs(queryKey, opts, pageParam) {
|
|
77
|
-
const path = queryKey[0];
|
|
78
|
-
const input = queryKey[1]?.input;
|
|
79
|
-
if (pageParam) input.cursor = pageParam;
|
|
80
|
-
return [
|
|
81
|
-
path.join('.'),
|
|
82
|
-
input,
|
|
83
|
-
opts?.trpc
|
|
84
|
-
];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Makes a stable reference of the `trpc` prop
|
|
89
|
-
*/ function useHookResult(value) {
|
|
90
|
-
const ref = React__namespace.useRef(value);
|
|
91
|
-
ref.current.path = value.path;
|
|
92
|
-
return ref.current;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Creates a set of utility functions that can be used to interact with `react-query`
|
|
97
|
-
* @param opts the `TRPCClient` and `QueryClient` to use
|
|
98
|
-
* @returns a set of utility functions that can be used to interact with `react-query`
|
|
99
|
-
* @internal
|
|
100
|
-
*/ function createUtilityFunctions(opts) {
|
|
101
|
-
const { client: client$1 , queryClient } = opts;
|
|
102
|
-
const untypedClient = client$1 instanceof client.TRPCUntypedClient ? client$1 : client.getUntypedClient(client$1);
|
|
103
|
-
return {
|
|
104
|
-
fetchQuery: (queryKey, opts)=>{
|
|
105
|
-
return queryClient.fetchQuery({
|
|
106
|
-
...opts,
|
|
107
|
-
queryKey,
|
|
108
|
-
queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
|
|
109
|
-
});
|
|
110
|
-
},
|
|
111
|
-
fetchInfiniteQuery: (queryKey, opts)=>{
|
|
112
|
-
return queryClient.fetchInfiniteQuery({
|
|
113
|
-
...opts,
|
|
114
|
-
queryKey,
|
|
115
|
-
queryFn: ({ pageParam })=>{
|
|
116
|
-
return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
|
|
117
|
-
},
|
|
118
|
-
initialPageParam: opts?.initialCursor ?? null
|
|
119
|
-
});
|
|
120
|
-
},
|
|
121
|
-
prefetchQuery: (queryKey, opts)=>{
|
|
122
|
-
return queryClient.prefetchQuery({
|
|
123
|
-
...opts,
|
|
124
|
-
queryKey,
|
|
125
|
-
queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
|
|
126
|
-
});
|
|
127
|
-
},
|
|
128
|
-
prefetchInfiniteQuery: (queryKey, opts)=>{
|
|
129
|
-
return queryClient.prefetchInfiniteQuery({
|
|
130
|
-
...opts,
|
|
131
|
-
queryKey,
|
|
132
|
-
queryFn: ({ pageParam })=>{
|
|
133
|
-
return untypedClient.query(...getClientArgs(queryKey, opts, pageParam));
|
|
134
|
-
},
|
|
135
|
-
initialPageParam: opts?.initialCursor ?? null
|
|
136
|
-
});
|
|
137
|
-
},
|
|
138
|
-
ensureQueryData: (queryKey, opts)=>{
|
|
139
|
-
return queryClient.ensureQueryData({
|
|
140
|
-
...opts,
|
|
141
|
-
queryKey,
|
|
142
|
-
queryFn: ()=>untypedClient.query(...getClientArgs(queryKey, opts))
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
invalidateQueries: (queryKey, filters, options)=>{
|
|
146
|
-
return queryClient.invalidateQueries({
|
|
147
|
-
...filters,
|
|
148
|
-
queryKey
|
|
149
|
-
}, options);
|
|
150
|
-
},
|
|
151
|
-
resetQueries: (queryKey, filters, options)=>{
|
|
152
|
-
return queryClient.resetQueries({
|
|
153
|
-
...filters,
|
|
154
|
-
queryKey
|
|
155
|
-
}, options);
|
|
156
|
-
},
|
|
157
|
-
refetchQueries: (queryKey, filters, options)=>{
|
|
158
|
-
return queryClient.refetchQueries({
|
|
159
|
-
...filters,
|
|
160
|
-
queryKey
|
|
161
|
-
}, options);
|
|
162
|
-
},
|
|
163
|
-
cancelQuery: (queryKey, options)=>{
|
|
164
|
-
return queryClient.cancelQueries({
|
|
165
|
-
queryKey
|
|
166
|
-
}, options);
|
|
167
|
-
},
|
|
168
|
-
setQueryData: (queryKey, updater, options)=>{
|
|
169
|
-
return queryClient.setQueryData(queryKey, updater, options);
|
|
170
|
-
},
|
|
171
|
-
getQueryData: (queryKey)=>{
|
|
172
|
-
return queryClient.getQueryData(queryKey);
|
|
173
|
-
},
|
|
174
|
-
setInfiniteQueryData: (queryKey, updater, options)=>{
|
|
175
|
-
return queryClient.setQueryData(queryKey, updater, options);
|
|
176
|
-
},
|
|
177
|
-
getInfiniteQueryData: (queryKey)=>{
|
|
178
|
-
return queryClient.getQueryData(queryKey);
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
}
|
|
6
|
+
var context = require('../../internals/context.js');
|
|
7
|
+
var getClientArgs = require('../../internals/getClientArgs.js');
|
|
8
|
+
var getQueryKey = require('../../internals/getQueryKey.js');
|
|
9
|
+
var useHookResult = require('../../internals/useHookResult.js');
|
|
10
|
+
var createUtilityFunctions = require('../../utils/createUtilityFunctions.js');
|
|
11
|
+
var useQueriesProxy = require('../proxy/useQueriesProxy.js');
|
|
182
12
|
|
|
183
13
|
/**
|
|
184
14
|
* @internal
|
|
185
15
|
*/ function createRootHooks(config) {
|
|
186
16
|
const mutationSuccessOverride = config?.overrides?.useMutation?.onSuccess ?? ((options)=>options.originalFn());
|
|
187
|
-
const Context = config?.context ??
|
|
17
|
+
const Context = config?.context ?? context.TRPCContext;
|
|
188
18
|
const createClient = (opts)=>{
|
|
189
19
|
return client.createTRPCUntypedClient(opts);
|
|
190
20
|
};
|
|
191
21
|
const TRPCProvider = (props)=>{
|
|
192
22
|
const { abortOnUnmount =false , client , queryClient , ssrContext } = props;
|
|
193
|
-
const [ssrState, setSSRState] =
|
|
194
|
-
const fns =
|
|
23
|
+
const [ssrState, setSSRState] = React.useState(props.ssrState ?? false);
|
|
24
|
+
const fns = React.useMemo(()=>createUtilityFunctions.createUtilityFunctions({
|
|
195
25
|
client,
|
|
196
26
|
queryClient
|
|
197
27
|
}), [
|
|
198
28
|
client,
|
|
199
29
|
queryClient
|
|
200
30
|
]);
|
|
201
|
-
const contextValue =
|
|
31
|
+
const contextValue = React.useMemo(()=>({
|
|
202
32
|
abortOnUnmount,
|
|
203
33
|
queryClient,
|
|
204
34
|
client,
|
|
@@ -213,17 +43,17 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
213
43
|
ssrContext,
|
|
214
44
|
ssrState
|
|
215
45
|
]);
|
|
216
|
-
|
|
46
|
+
React.useEffect(()=>{
|
|
217
47
|
// Only updating state to `mounted` if we are using SSR.
|
|
218
48
|
// This makes it so we don't have an unnecessary re-render when opting out of SSR.
|
|
219
49
|
setSSRState((state)=>state ? 'mounted' : false);
|
|
220
50
|
}, []);
|
|
221
|
-
return /*#__PURE__*/
|
|
51
|
+
return /*#__PURE__*/ React.createElement(Context.Provider, {
|
|
222
52
|
value: contextValue
|
|
223
53
|
}, props.children);
|
|
224
54
|
};
|
|
225
55
|
function useContext() {
|
|
226
|
-
const context =
|
|
56
|
+
const context = React.useContext(Context);
|
|
227
57
|
if (!context) {
|
|
228
58
|
throw new Error('Unable to find tRPC Context. Did you forget to wrap your App inside `withTRPC` HoC?');
|
|
229
59
|
}
|
|
@@ -244,7 +74,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
244
74
|
function useQuery(path, input, opts) {
|
|
245
75
|
const context = useContext();
|
|
246
76
|
const { abortOnUnmount , client , ssrState , queryClient , prefetchQuery } = context;
|
|
247
|
-
const queryKey =
|
|
77
|
+
const queryKey = getQueryKey.getQueryKeyInternal(path, input, 'query');
|
|
248
78
|
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
|
249
79
|
if (typeof window === 'undefined' && ssrState === 'prepass' && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !queryClient.getQueryCache().find({
|
|
250
80
|
queryKey
|
|
@@ -269,17 +99,17 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
269
99
|
} : {}
|
|
270
100
|
}
|
|
271
101
|
};
|
|
272
|
-
return client.query(...getClientArgs(queryKey, actualOpts));
|
|
102
|
+
return client.query(...getClientArgs.getClientArgs(queryKey, actualOpts));
|
|
273
103
|
}
|
|
274
104
|
}, queryClient);
|
|
275
|
-
hook.trpc = useHookResult({
|
|
105
|
+
hook.trpc = useHookResult.useHookResult({
|
|
276
106
|
path: path.join('.')
|
|
277
107
|
});
|
|
278
108
|
return hook;
|
|
279
109
|
}
|
|
280
110
|
function useSuspenseQuery(path, input, opts) {
|
|
281
111
|
const context = useContext();
|
|
282
|
-
const queryKey =
|
|
112
|
+
const queryKey = getQueryKey.getQueryKeyInternal(path, input, 'query');
|
|
283
113
|
const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? config?.abortOnUnmount ?? context.abortOnUnmount;
|
|
284
114
|
const hook = reactQuery.useSuspenseQuery({
|
|
285
115
|
...opts,
|
|
@@ -292,10 +122,10 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
292
122
|
} : {}
|
|
293
123
|
}
|
|
294
124
|
};
|
|
295
|
-
return context.client.query(...getClientArgs(queryKey, actualOpts));
|
|
125
|
+
return context.client.query(...getClientArgs.getClientArgs(queryKey, actualOpts));
|
|
296
126
|
}
|
|
297
127
|
}, context.queryClient);
|
|
298
|
-
hook.trpc = useHookResult({
|
|
128
|
+
hook.trpc = useHookResult.useHookResult({
|
|
299
129
|
path: path.join('.')
|
|
300
130
|
});
|
|
301
131
|
return [
|
|
@@ -314,7 +144,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
314
144
|
...opts,
|
|
315
145
|
mutationKey: mutationKey,
|
|
316
146
|
mutationFn: (input)=>{
|
|
317
|
-
return client.mutation(...getClientArgs([
|
|
147
|
+
return client.mutation(...getClientArgs.getClientArgs([
|
|
318
148
|
path,
|
|
319
149
|
{
|
|
320
150
|
input
|
|
@@ -330,18 +160,18 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
330
160
|
});
|
|
331
161
|
}
|
|
332
162
|
}, queryClient);
|
|
333
|
-
hook.trpc = useHookResult({
|
|
163
|
+
hook.trpc = useHookResult.useHookResult({
|
|
334
164
|
path: path.join('.')
|
|
335
165
|
});
|
|
336
166
|
return hook;
|
|
337
167
|
}
|
|
338
168
|
/* istanbul ignore next -- @preserve */ function useSubscription(path, input, opts) {
|
|
339
169
|
const enabled = opts?.enabled ?? true;
|
|
340
|
-
const queryKey = reactQuery.hashKey(
|
|
170
|
+
const queryKey = reactQuery.hashKey(getQueryKey.getQueryKeyInternal(path, input, 'any'));
|
|
341
171
|
const { client } = useContext();
|
|
342
|
-
const optsRef =
|
|
172
|
+
const optsRef = React.useRef(opts);
|
|
343
173
|
optsRef.current = opts;
|
|
344
|
-
|
|
174
|
+
React.useEffect(()=>{
|
|
345
175
|
if (!enabled) {
|
|
346
176
|
return;
|
|
347
177
|
}
|
|
@@ -375,7 +205,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
375
205
|
}
|
|
376
206
|
function useInfiniteQuery(path, input, opts) {
|
|
377
207
|
const { client , ssrState , prefetchInfiniteQuery , queryClient , abortOnUnmount , } = useContext();
|
|
378
|
-
const queryKey =
|
|
208
|
+
const queryKey = getQueryKey.getQueryKeyInternal(path, input, 'infinite');
|
|
379
209
|
const defaultOpts = queryClient.getQueryDefaults(queryKey);
|
|
380
210
|
if (typeof window === 'undefined' && ssrState === 'prepass' && opts?.trpc?.ssr !== false && (opts?.enabled ?? defaultOpts?.enabled) !== false && !queryClient.getQueryCache().find({
|
|
381
211
|
queryKey
|
|
@@ -406,17 +236,17 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
406
236
|
} : {}
|
|
407
237
|
}
|
|
408
238
|
};
|
|
409
|
-
return client.query(...getClientArgs(queryKey, actualOpts, queryFunctionContext.pageParam ?? opts.initialCursor));
|
|
239
|
+
return client.query(...getClientArgs.getClientArgs(queryKey, actualOpts, queryFunctionContext.pageParam ?? opts.initialCursor));
|
|
410
240
|
}
|
|
411
241
|
}, queryClient);
|
|
412
|
-
hook.trpc = useHookResult({
|
|
242
|
+
hook.trpc = useHookResult.useHookResult({
|
|
413
243
|
path: path.join('.')
|
|
414
244
|
});
|
|
415
245
|
return hook;
|
|
416
246
|
}
|
|
417
247
|
function useSuspenseInfiniteQuery(path, input, opts) {
|
|
418
248
|
const context = useContext();
|
|
419
|
-
const queryKey =
|
|
249
|
+
const queryKey = getQueryKey.getQueryKeyInternal(path, input, 'infinite');
|
|
420
250
|
const defaultOpts = context.queryClient.getQueryDefaults(queryKey);
|
|
421
251
|
const ssrOpts = useSSRQueryOptionsIfNeeded(queryKey, {
|
|
422
252
|
...defaultOpts,
|
|
@@ -438,10 +268,10 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
438
268
|
} : {}
|
|
439
269
|
}
|
|
440
270
|
};
|
|
441
|
-
return context.client.query(...getClientArgs(queryKey, actualOpts, queryFunctionContext.pageParam ?? opts.initialCursor));
|
|
271
|
+
return context.client.query(...getClientArgs.getClientArgs(queryKey, actualOpts, queryFunctionContext.pageParam ?? opts.initialCursor));
|
|
442
272
|
}
|
|
443
273
|
}, context.queryClient);
|
|
444
|
-
hook.trpc = useHookResult({
|
|
274
|
+
hook.trpc = useHookResult.useHookResult({
|
|
445
275
|
path: path.join('.')
|
|
446
276
|
});
|
|
447
277
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
@@ -452,7 +282,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
452
282
|
}
|
|
453
283
|
const useQueries = (queriesCallback)=>{
|
|
454
284
|
const { ssrState , queryClient , prefetchQuery , client } = useContext();
|
|
455
|
-
const proxy = createUseQueries(client);
|
|
285
|
+
const proxy = useQueriesProxy.createUseQueries(client);
|
|
456
286
|
const queries = queriesCallback(proxy);
|
|
457
287
|
if (typeof window === 'undefined' && ssrState === 'prepass') {
|
|
458
288
|
for (const query of queries){
|
|
@@ -473,7 +303,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
473
303
|
};
|
|
474
304
|
const useSuspenseQueries = (queriesCallback)=>{
|
|
475
305
|
const { queryClient , client } = useContext();
|
|
476
|
-
const proxy = createUseQueries(client);
|
|
306
|
+
const proxy = useQueriesProxy.createUseQueries(client);
|
|
477
307
|
const queries = queriesCallback(proxy);
|
|
478
308
|
const hook = reactQuery.useSuspenseQueries({
|
|
479
309
|
queries: queries.map((query)=>({
|
|
@@ -487,7 +317,7 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
487
317
|
];
|
|
488
318
|
};
|
|
489
319
|
const useDehydratedState = (client, trpcState)=>{
|
|
490
|
-
const transformed =
|
|
320
|
+
const transformed = React.useMemo(()=>{
|
|
491
321
|
if (!trpcState) {
|
|
492
322
|
return trpcState;
|
|
493
323
|
}
|
|
@@ -515,8 +345,4 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
|
515
345
|
};
|
|
516
346
|
}
|
|
517
347
|
|
|
518
|
-
exports.createReactDecoration = createReactDecoration;
|
|
519
348
|
exports.createRootHooks = createRootHooks;
|
|
520
|
-
exports.createUseQueries = createUseQueries;
|
|
521
|
-
exports.createUtilityFunctions = createUtilityFunctions;
|
|
522
|
-
exports.getClientArgs = getClientArgs;
|