@trpc/react-query 11.0.0-alpha-tmp-export-from-main.212 → 11.0.0-alpha-tmp-export-from-main-nuke-core.236
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/bundle-analysis.json +240 -0
- package/dist/createTRPCQueryUtils.d.ts +1 -1
- package/dist/createTRPCQueryUtils.d.ts.map +1 -1
- package/dist/createTRPCQueryUtils.js +16 -0
- package/dist/createTRPCQueryUtils.mjs +14 -0
- package/dist/createTRPCReact.d.ts +1 -1
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/createTRPCReact.js +58 -0
- package/dist/createTRPCReact.mjs +36 -0
- package/dist/index.js +10 -64
- package/dist/index.mjs +3 -40
- package/dist/internals/context.d.ts +1 -1
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/context.js +33 -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.d.ts +1 -1
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/getQueryKey.js +57 -0
- package/dist/internals/getQueryKey.mjs +54 -0
- package/dist/internals/useHookResult.js +32 -0
- package/dist/internals/useHookResult.mjs +11 -0
- package/dist/internals/useQueries.d.ts +1 -1
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/server/index.js +2 -102
- package/dist/server/index.mjs +1 -103
- package/dist/server/ssgProxy.d.ts +1 -1
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +107 -0
- package/dist/server/ssgProxy.mjs +105 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +1 -1
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/{createHooksInternal-5d2fa367.js → shared/hooks/createHooksInternal.js} +28 -183
- package/dist/{createHooksInternal-e0b0564e.mjs → shared/hooks/createHooksInternal.mjs} +8 -158
- package/dist/shared/hooks/types.d.ts +1 -1
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.js +13 -15
- package/dist/shared/index.mjs +7 -7
- package/dist/shared/polymorphism/mutationLike.d.ts +1 -1
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/utilsLike.d.ts +1 -1
- package/dist/shared/polymorphism/utilsLike.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.d.ts +1 -1
- package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.js +31 -0
- package/dist/shared/proxy/decorationProxy.mjs +29 -0
- package/dist/shared/proxy/useQueriesProxy.d.ts +1 -1
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/useQueriesProxy.js +25 -0
- package/dist/shared/proxy/useQueriesProxy.mjs +23 -0
- package/dist/shared/proxy/utilsProxy.d.ts +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +89 -0
- package/dist/{utilsProxy-61a4601f.mjs → shared/proxy/utilsProxy.mjs} +4 -52
- package/dist/{queryClient-4d766c0c.mjs → shared/queryClient.mjs} +1 -1
- package/dist/shared/types.d.ts +1 -1
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.d.ts +1 -1
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.js +94 -0
- package/dist/utils/createUtilityFunctions.mjs +92 -0
- package/dist/utils/inferReactQueryProcedure.d.ts +1 -1
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +16 -32
- package/src/createTRPCQueryUtils.tsx +1 -1
- package/src/createTRPCReact.tsx +2 -2
- package/src/internals/context.tsx +4 -1
- package/src/internals/getQueryKey.ts +20 -2
- package/src/internals/useQueries.ts +4 -1
- package/src/server/ssgProxy.ts +2 -2
- package/src/shared/hooks/createHooksInternal.tsx +1 -1
- package/src/shared/hooks/types.ts +4 -1
- package/src/shared/polymorphism/mutationLike.ts +1 -1
- package/src/shared/polymorphism/queryLike.ts +1 -1
- package/src/shared/polymorphism/routerLike.ts +1 -1
- package/src/shared/polymorphism/utilsLike.ts +1 -1
- package/src/shared/proxy/decorationProxy.ts +2 -2
- package/src/shared/proxy/useQueriesProxy.ts +2 -2
- package/src/shared/proxy/utilsProxy.ts +5 -2
- package/src/shared/types.ts +4 -1
- package/src/utils/createUtilityFunctions.ts +1 -1
- package/src/utils/inferReactQueryProcedure.ts +1 -1
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getQueryKey.d.ts","sourceRoot":"","sources":["../../src/internals/getQueryKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,WAAW,EACX,mBAAmB,EACpB,MAAM,
|
|
1
|
+
{"version":3,"file":"getQueryKey.d.ts","sourceRoot":"","sources":["../../src/internals/getQueryKey.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EACjB,aAAa,EACb,SAAS,EACT,WAAW,EACX,mBAAmB,EACpB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE7E,MAAM,MAAM,SAAS,GAAG,KAAK,GAAG,UAAU,GAAG,OAAO,CAAC;AAEr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iB,EAAE,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC,GAC3E,kBAAkB,SAAS,SAAS,GACpC;IACE,iBAAiB,EAAE,wBAAwB,CACzC,OAAO,EACP,kBAAkB,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACpC,MAAM,CACP;CACF,GACD,KAAK,CAAC;AAEV,KAAK,iBAAiB,CACpB,OAAO,SAAS,aAAa,EAC7B,kBAAkB,SACd,oBAAoB,GACpB,iBAAiB,GACjB,SAAS,EACb,MAAM,IACJ,SAAS,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,CAAC;AAEnD;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,OAAO,SAAS,aAAa,EAC7B,kBAAkB,SACd,oBAAoB,GACpB,iBAAiB,GACjB,SAAS,EACb,MAAM,EACN,GAAG,OAAO,EAAE,iBAAiB,CAAC,OAAO,EAAE,kBAAkB,EAAE,MAAM,CAAC,gBAMnE;AAGD,MAAM,MAAM,aAAa,CAAC,MAAM,EAAE,KAAK,SAAS,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,IAAI;IAC3E,MAAM,EAAE;IACR;QAAE,KAAK,CAAC,EAAE,sBAAsB,CAAC,MAAM,CAAC,CAAC;QAAC,IAAI,EAAE,KAAK,CAAA;KAAE,CAAC;CACzD,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* To allow easy interactions with groups of related queries, such as
|
|
5
|
+
* invalidating all queries of a router, we use an array as the path when
|
|
6
|
+
* storing in tanstack query.
|
|
7
|
+
**/ function getQueryKeyInternal(path, input, type) {
|
|
8
|
+
// Construct a query key that is easy to destructure and flexible for
|
|
9
|
+
// partial selecting etc.
|
|
10
|
+
// https://github.com/trpc/trpc/issues/3128
|
|
11
|
+
// some parts of the path may be dot-separated, split them up
|
|
12
|
+
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
13
|
+
if (!input && (!type || type === 'any')) {
|
|
14
|
+
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
15
|
+
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
16
|
+
return splitPath.length ? [
|
|
17
|
+
splitPath
|
|
18
|
+
] : [];
|
|
19
|
+
}
|
|
20
|
+
if (type === 'infinite' && input && typeof input === 'object' && 'cursor' in input) {
|
|
21
|
+
const { cursor: _ , ...inputWithoutCursor } = input;
|
|
22
|
+
return [
|
|
23
|
+
splitPath,
|
|
24
|
+
{
|
|
25
|
+
input: inputWithoutCursor,
|
|
26
|
+
type: 'infinite'
|
|
27
|
+
}
|
|
28
|
+
];
|
|
29
|
+
}
|
|
30
|
+
return [
|
|
31
|
+
splitPath,
|
|
32
|
+
{
|
|
33
|
+
...typeof input !== 'undefined' && {
|
|
34
|
+
input: input
|
|
35
|
+
},
|
|
36
|
+
...type && type !== 'any' && {
|
|
37
|
+
type: type
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Method to extract the query key for a procedure
|
|
44
|
+
* @param procedureOrRouter - procedure or AnyRouter
|
|
45
|
+
* @param input - input to procedureOrRouter
|
|
46
|
+
* @param type - defaults to `any`
|
|
47
|
+
* @link https://trpc.io/docs/v11/getQueryKey
|
|
48
|
+
*/ function getQueryKey(..._params) {
|
|
49
|
+
const [procedureOrRouter, input, type] = _params;
|
|
50
|
+
// @ts-expect-error - we don't expose _def on the type layer
|
|
51
|
+
const path = procedureOrRouter._def().path;
|
|
52
|
+
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
|
53
|
+
return queryKey;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
exports.getQueryKey = getQueryKey;
|
|
57
|
+
exports.getQueryKeyInternal = getQueryKeyInternal;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* To allow easy interactions with groups of related queries, such as
|
|
3
|
+
* invalidating all queries of a router, we use an array as the path when
|
|
4
|
+
* storing in tanstack query.
|
|
5
|
+
**/ function getQueryKeyInternal(path, input, type) {
|
|
6
|
+
// Construct a query key that is easy to destructure and flexible for
|
|
7
|
+
// partial selecting etc.
|
|
8
|
+
// https://github.com/trpc/trpc/issues/3128
|
|
9
|
+
// some parts of the path may be dot-separated, split them up
|
|
10
|
+
const splitPath = path.flatMap((part)=>part.split('.'));
|
|
11
|
+
if (!input && (!type || type === 'any')) {
|
|
12
|
+
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
13
|
+
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
14
|
+
return splitPath.length ? [
|
|
15
|
+
splitPath
|
|
16
|
+
] : [];
|
|
17
|
+
}
|
|
18
|
+
if (type === 'infinite' && input && typeof input === 'object' && 'cursor' in input) {
|
|
19
|
+
const { cursor: _ , ...inputWithoutCursor } = input;
|
|
20
|
+
return [
|
|
21
|
+
splitPath,
|
|
22
|
+
{
|
|
23
|
+
input: inputWithoutCursor,
|
|
24
|
+
type: 'infinite'
|
|
25
|
+
}
|
|
26
|
+
];
|
|
27
|
+
}
|
|
28
|
+
return [
|
|
29
|
+
splitPath,
|
|
30
|
+
{
|
|
31
|
+
...typeof input !== 'undefined' && {
|
|
32
|
+
input: input
|
|
33
|
+
},
|
|
34
|
+
...type && type !== 'any' && {
|
|
35
|
+
type: type
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Method to extract the query key for a procedure
|
|
42
|
+
* @param procedureOrRouter - procedure or AnyRouter
|
|
43
|
+
* @param input - input to procedureOrRouter
|
|
44
|
+
* @param type - defaults to `any`
|
|
45
|
+
* @link https://trpc.io/docs/v11/getQueryKey
|
|
46
|
+
*/ function getQueryKey(..._params) {
|
|
47
|
+
const [procedureOrRouter, input, type] = _params;
|
|
48
|
+
// @ts-expect-error - we don't expose _def on the type layer
|
|
49
|
+
const path = procedureOrRouter._def().path;
|
|
50
|
+
const queryKey = getQueryKeyInternal(path, input, type ?? 'any');
|
|
51
|
+
return queryKey;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { getQueryKey, getQueryKeyInternal };
|
|
@@ -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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { QueryKey, UseQueryOptions, UseSuspenseQueryOptions, UseSuspenseQueryResult } from '@tanstack/react-query';
|
|
2
|
-
import type { AnyRouter, DistributiveOmit } from '@trpc/core';
|
|
2
|
+
import type { AnyRouter, DistributiveOmit } from '@trpc/server/unstable-core-do-not-import';
|
|
3
3
|
import type { UseQueriesProcedureRecord, UseSuspenseQueriesProcedureRecord, UseTRPCQueryOptions, UseTRPCQueryResult, UseTRPCSuspenseQueryOptions } from '../shared';
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueries.d.ts","sourceRoot":"","sources":["../../src/internals/useQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useQueries.d.ts","sourceRoot":"","sources":["../../src/internals/useQueries.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EACjB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,yBAAyB,EACzB,iCAAiC,EACjC,mBAAmB,EACnB,kBAAkB,EAClB,2BAA2B,EAC5B,MAAM,WAAW,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,4BAA4B,CACtC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,OAAO,EAChB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,gBAAgB,CAClB,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EACvD,UAAU,CACX,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oCAAoC,CAC9C,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,OAAO,EAChB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,IACnC,gBAAgB,CAClB,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,EAC/D,UAAU,CACX,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,6BAA6B,CAAC,OAAO,EAAE,KAAK,EA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eAAe,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,GACnD,cAAc,CAAC,IAAI,EAAE,CAAC,GAAG,OAAO,EAAE,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,GAC5D,OAAO,EAAE,SAAS,eAAe,GACjC,eAAe,GACf,eAAe,SAAS,oCAAoC,CAC1D,MAAM,YAAY,EAClB,MAAM,MAAM,EACZ,MAAM,KAAK,EACX,MAAM,SAAS,CAChB,EAAE,GACH,oCAAoC,CAClC,YAAY,EACZ,MAAM,EACN,KAAK,EACL,SAAS,CACV,EAAE,GACH,oCAAoC,EAAE,CAAC;AAE3C;;GAEG;AACH,MAAM,MAAM,cAAc,CAAC,OAAO,SAAS,SAAS,IAAI,CACtD,aAAa,SAAS,4BAA4B,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAE,EAExE,eAAe,EAAE,CACf,CAAC,EAAE,yBAAyB,CAAC,OAAO,CAAC,KAClC,SAAS,CAAC,GAAG,cAAc,CAAC,aAAa,CAAC,CAAC,KAC7C,cAAc,CAAC,aAAa,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,sBAAsB,CAAC,OAAO,SAAS,SAAS,IAAI,CAC9D,aAAa,SAAS,oCAAoC,CACxD,GAAG,EACH,GAAG,EACH,GAAG,EACH,GAAG,CACJ,EAAE,EAEH,eAAe,EAAE,CACf,CAAC,EAAE,iCAAiC,CAAC,OAAO,CAAC,KAC1C,SAAS,CAAC,GAAG,sBAAsB,CAAC,aAAa,CAAC,CAAC,KACrD,sBAAsB,CAAC,aAAa,CAAC,CAAC"}
|
package/dist/server/index.js
CHANGED
|
@@ -1,107 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
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-0b88c1e3.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;
|
package/dist/server/index.mjs
CHANGED
|
@@ -1,103 +1 @@
|
|
|
1
|
-
|
|
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-61a4601f.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';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DehydratedState, DehydrateOptions, InfiniteData, QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import type { inferRouterClient, TRPCClientError } from '@trpc/client';
|
|
3
3
|
import { TRPCUntypedClient } from '@trpc/client';
|
|
4
|
-
import type { AnyProcedure, AnyQueryProcedure, AnyRootConfig, AnyRouter, DataTransformerOptions, Filter, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput, ProtectedIntersection } from '@trpc/core';
|
|
4
|
+
import type { AnyProcedure, AnyQueryProcedure, AnyRootConfig, AnyRouter, DataTransformerOptions, Filter, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput, ProtectedIntersection } from '@trpc/server/unstable-core-do-not-import';
|
|
5
5
|
import type { CreateTRPCReactQueryClientConfig, ExtractCursorType, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions } from '../shared';
|
|
6
6
|
interface CreateSSGHelpersInternal<TRouter extends AnyRouter> {
|
|
7
7
|
router: TRouter;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssgProxy.d.ts","sourceRoot":"","sources":["../../src/server/ssgProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACZ,M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C,CACzB,GACA,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,KAAK,2BAA2B,CAAC,OAAO,SAAS,SAAS,IAAI;KAC3D,IAAI,IAAI,MAAM,MAAM,CACnB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACzB,iBAAiB,GAAG,SAAS,CAC9B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GACjD,2BAA2B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAE5D,iBAAiB,CACf,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,EAC1B,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAChC;CACN,CAAC;AAIF;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,SAAS,SAAS,EAC/D,IAAI,EAAE,8BAA8B,CAAC,OAAO,CAAC;iBAoD5B,WAAW;uBACL,gBAAgB,KAAK,eAAe;yCA4D5D"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactQuery = require('@tanstack/react-query');
|
|
4
|
+
var client = require('@trpc/client');
|
|
5
|
+
var unstableCoreDoNotImport = require('@trpc/server/unstable-core-do-not-import');
|
|
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 unstableCoreDoNotImport.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 unstableCoreDoNotImport.createFlatProxy((key)=>{
|
|
51
|
+
if (key === 'queryClient') return queryClient$1;
|
|
52
|
+
if (key === 'dehydrate') return _dehydrate;
|
|
53
|
+
return unstableCoreDoNotImport.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/server/unstable-core-do-not-import';
|
|
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 };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TRPCClientErrorLike } from '@trpc/client';
|
|
2
|
-
import type { AnyRouter } from '@trpc/core';
|
|
2
|
+
import type { AnyRouter } from '@trpc/server/unstable-core-do-not-import';
|
|
3
3
|
import type { TRPCContextState } from '../../internals/context';
|
|
4
4
|
import type { TRPCUseQueries, TRPCUseSuspenseQueries } from '../../internals/useQueries';
|
|
5
5
|
import type { CreateTRPCReactOptions } from '../types';
|