@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.
- package/dist/createTRPCQueryUtils.js +16 -0
- package/dist/createTRPCQueryUtils.mjs +14 -0
- 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.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.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/server/index.js +2 -102
- package/dist/server/index.mjs +1 -103
- package/dist/server/ssgProxy.js +107 -0
- package/dist/server/ssgProxy.mjs +105 -0
- 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/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/internals/getQueryKey.ts +19 -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
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('@trpc/core');
|
|
4
|
+
var utilsProxy = require('./shared/proxy/utilsProxy.js');
|
|
5
|
+
require('@tanstack/react-query');
|
|
6
|
+
require('@trpc/client');
|
|
7
|
+
require('react');
|
|
8
|
+
require('./internals/context.js');
|
|
9
|
+
var createUtilityFunctions = require('./utils/createUtilityFunctions.js');
|
|
10
|
+
|
|
11
|
+
function createTRPCQueryUtils(opts) {
|
|
12
|
+
const utils = createUtilityFunctions.createUtilityFunctions(opts);
|
|
13
|
+
return utilsProxy.createQueryUtilsProxy(utils);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.createTRPCQueryUtils = createTRPCQueryUtils;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import '@trpc/core';
|
|
2
|
+
import { createQueryUtilsProxy } from './shared/proxy/utilsProxy.mjs';
|
|
3
|
+
import '@tanstack/react-query';
|
|
4
|
+
import '@trpc/client';
|
|
5
|
+
import 'react';
|
|
6
|
+
import './internals/context.mjs';
|
|
7
|
+
import { createUtilityFunctions } from './utils/createUtilityFunctions.mjs';
|
|
8
|
+
|
|
9
|
+
function createTRPCQueryUtils(opts) {
|
|
10
|
+
const utils = createUtilityFunctions(opts);
|
|
11
|
+
return createQueryUtilsProxy(utils);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { createTRPCQueryUtils };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@trpc/core');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var decorationProxy = require('./shared/proxy/decorationProxy.js');
|
|
6
|
+
var utilsProxy = require('./shared/proxy/utilsProxy.js');
|
|
7
|
+
var createHooksInternal$1 = require('./shared/hooks/createHooksInternal.js');
|
|
8
|
+
require('@tanstack/react-query');
|
|
9
|
+
require('./internals/context.js');
|
|
10
|
+
|
|
11
|
+
function _interopNamespaceDefault(e) {
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n.default = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/ function createHooksInternal(trpc) {
|
|
33
|
+
return core.createFlatProxy((key)=>{
|
|
34
|
+
if (key === 'useContext' || key === 'useUtils') {
|
|
35
|
+
return ()=>{
|
|
36
|
+
const context = trpc.useUtils();
|
|
37
|
+
// create a stable reference of the utils context
|
|
38
|
+
return React__namespace.useMemo(()=>{
|
|
39
|
+
return utilsProxy.createReactQueryUtils(context);
|
|
40
|
+
}, [
|
|
41
|
+
context
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
if (trpc.hasOwnProperty(key)) {
|
|
46
|
+
return trpc[key];
|
|
47
|
+
}
|
|
48
|
+
return decorationProxy.createReactDecoration(key, trpc);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function createTRPCReact(opts) {
|
|
52
|
+
const hooks = createHooksInternal$1.createRootHooks(opts);
|
|
53
|
+
const proxy = createHooksInternal(hooks);
|
|
54
|
+
return proxy;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
exports.createHooksInternal = createHooksInternal;
|
|
58
|
+
exports.createTRPCReact = createTRPCReact;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { createFlatProxy } from '@trpc/core';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { createReactDecoration } from './shared/proxy/decorationProxy.mjs';
|
|
4
|
+
import { createReactQueryUtils } from './shared/proxy/utilsProxy.mjs';
|
|
5
|
+
import { createRootHooks } from './shared/hooks/createHooksInternal.mjs';
|
|
6
|
+
import '@tanstack/react-query';
|
|
7
|
+
import './internals/context.mjs';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/ function createHooksInternal(trpc) {
|
|
12
|
+
return createFlatProxy((key)=>{
|
|
13
|
+
if (key === 'useContext' || key === 'useUtils') {
|
|
14
|
+
return ()=>{
|
|
15
|
+
const context = trpc.useUtils();
|
|
16
|
+
// create a stable reference of the utils context
|
|
17
|
+
return React.useMemo(()=>{
|
|
18
|
+
return createReactQueryUtils(context);
|
|
19
|
+
}, [
|
|
20
|
+
context
|
|
21
|
+
]);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
if (trpc.hasOwnProperty(key)) {
|
|
25
|
+
return trpc[key];
|
|
26
|
+
}
|
|
27
|
+
return createReactDecoration(key, trpc);
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
function createTRPCReact(opts) {
|
|
31
|
+
const hooks = createRootHooks(opts);
|
|
32
|
+
const proxy = createHooksInternal(hooks);
|
|
33
|
+
return proxy;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { createHooksInternal, createTRPCReact };
|
package/dist/index.js
CHANGED
|
@@ -1,72 +1,18 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
3
|
var client = require('@trpc/client');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var createHooksInternal$1 = require('./createHooksInternal-5d2fa367.js');
|
|
10
|
-
require('@tanstack/react-query');
|
|
11
|
-
|
|
12
|
-
function _interopNamespace(e) {
|
|
13
|
-
if (e && e.__esModule) return e;
|
|
14
|
-
var n = Object.create(null);
|
|
15
|
-
if (e) {
|
|
16
|
-
Object.keys(e).forEach(function (k) {
|
|
17
|
-
if (k !== 'default') {
|
|
18
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
19
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () { return e[k]; }
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
n["default"] = e;
|
|
27
|
-
return Object.freeze(n);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
4
|
+
var getQueryKey = require('./internals/getQueryKey.js');
|
|
5
|
+
var createTRPCReact = require('./createTRPCReact.js');
|
|
6
|
+
var createTRPCQueryUtils = require('./createTRPCQueryUtils.js');
|
|
31
7
|
|
|
32
|
-
/**
|
|
33
|
-
* @internal
|
|
34
|
-
*/ function createHooksInternal(trpc) {
|
|
35
|
-
return core.createFlatProxy((key)=>{
|
|
36
|
-
if (key === 'useContext' || key === 'useUtils') {
|
|
37
|
-
return ()=>{
|
|
38
|
-
const context = trpc.useUtils();
|
|
39
|
-
// create a stable reference of the utils context
|
|
40
|
-
return React__namespace.useMemo(()=>{
|
|
41
|
-
return utilsProxy.createReactQueryUtils(context);
|
|
42
|
-
}, [
|
|
43
|
-
context
|
|
44
|
-
]);
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
if (trpc.hasOwnProperty(key)) {
|
|
48
|
-
return trpc[key];
|
|
49
|
-
}
|
|
50
|
-
return createHooksInternal$1.createReactDecoration(key, trpc);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
function createTRPCReact(opts) {
|
|
54
|
-
const hooks = createHooksInternal$1.createRootHooks(opts);
|
|
55
|
-
const proxy = createHooksInternal(hooks);
|
|
56
|
-
return proxy;
|
|
57
|
-
}
|
|
58
8
|
|
|
59
|
-
function createTRPCQueryUtils(opts) {
|
|
60
|
-
const utils = createHooksInternal$1.createUtilityFunctions(opts);
|
|
61
|
-
return utilsProxy.createQueryUtilsProxy(utils);
|
|
62
|
-
}
|
|
63
9
|
|
|
64
|
-
exports.getQueryKey =
|
|
65
|
-
exports.
|
|
66
|
-
exports.
|
|
10
|
+
exports.getQueryKey = getQueryKey.getQueryKey;
|
|
11
|
+
exports.createTRPCReact = createTRPCReact.createTRPCReact;
|
|
12
|
+
exports.createTRPCQueryUtils = createTRPCQueryUtils.createTRPCQueryUtils;
|
|
67
13
|
Object.keys(client).forEach(function (k) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
14
|
+
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function () { return client[k]; }
|
|
17
|
+
});
|
|
72
18
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,41 +1,4 @@
|
|
|
1
1
|
export * from '@trpc/client';
|
|
2
|
-
|
|
3
|
-
export {
|
|
4
|
-
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
import { c as createRootHooks, a as createReactDecoration, b as createUtilityFunctions } from './createHooksInternal-e0b0564e.mjs';
|
|
7
|
-
import '@tanstack/react-query';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @internal
|
|
11
|
-
*/ function createHooksInternal(trpc) {
|
|
12
|
-
return createFlatProxy((key)=>{
|
|
13
|
-
if (key === 'useContext' || key === 'useUtils') {
|
|
14
|
-
return ()=>{
|
|
15
|
-
const context = trpc.useUtils();
|
|
16
|
-
// create a stable reference of the utils context
|
|
17
|
-
return React.useMemo(()=>{
|
|
18
|
-
return createReactQueryUtils(context);
|
|
19
|
-
}, [
|
|
20
|
-
context
|
|
21
|
-
]);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
if (trpc.hasOwnProperty(key)) {
|
|
25
|
-
return trpc[key];
|
|
26
|
-
}
|
|
27
|
-
return createReactDecoration(key, trpc);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
function createTRPCReact(opts) {
|
|
31
|
-
const hooks = createRootHooks(opts);
|
|
32
|
-
const proxy = createHooksInternal(hooks);
|
|
33
|
-
return proxy;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function createTRPCQueryUtils(opts) {
|
|
37
|
-
const utils = createUtilityFunctions(opts);
|
|
38
|
-
return createQueryUtilsProxy(utils);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export { createTRPCQueryUtils, createTRPCReact };
|
|
2
|
+
export { getQueryKey } from './internals/getQueryKey.mjs';
|
|
3
|
+
export { createTRPCReact } from './createTRPCReact.mjs';
|
|
4
|
+
export { createTRPCQueryUtils } from './createTRPCQueryUtils.mjs';
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
const contextProps = [
|
|
25
|
+
'client',
|
|
26
|
+
'ssrContext',
|
|
27
|
+
'ssrState',
|
|
28
|
+
'abortOnUnmount'
|
|
29
|
+
];
|
|
30
|
+
const TRPCContext = React__namespace.createContext?.(null);
|
|
31
|
+
|
|
32
|
+
exports.TRPCContext = TRPCContext;
|
|
33
|
+
exports.contextProps = contextProps;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/ function getClientArgs(queryKey, opts, pageParam) {
|
|
6
|
+
const path = queryKey[0];
|
|
7
|
+
const input = queryKey[1]?.input;
|
|
8
|
+
if (pageParam) input.cursor = pageParam;
|
|
9
|
+
return [
|
|
10
|
+
path.join('.'),
|
|
11
|
+
input,
|
|
12
|
+
opts?.trpc
|
|
13
|
+
];
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.getClientArgs = getClientArgs;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @internal
|
|
3
|
+
*/ function getClientArgs(queryKey, opts, pageParam) {
|
|
4
|
+
const path = queryKey[0];
|
|
5
|
+
const input = queryKey[1]?.input;
|
|
6
|
+
if (pageParam) input.cursor = pageParam;
|
|
7
|
+
return [
|
|
8
|
+
path.join('.'),
|
|
9
|
+
input,
|
|
10
|
+
opts?.trpc
|
|
11
|
+
];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { getClientArgs };
|
|
@@ -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,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,wBAAwB,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAE7E,MAAM,MAAM,SAAS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,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;
|
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;
|