@trpc/react-query 10.5.0 → 10.7.0
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/README.md +1 -1
- package/dist/{createHooksInternal-d9b9c414.js → createHooksInternal-9b01c277.js} +49 -2
- package/dist/{createHooksInternal-808efaa7.mjs → createHooksInternal-de11647d.mjs} +49 -4
- package/dist/createTRPCReact.d.ts +14 -3
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/{getArrayQueryKey-24927615.js → getArrayQueryKey-4bdb5cc2.js} +7 -2
- package/dist/{getArrayQueryKey-c6f6badf.mjs → getArrayQueryKey-86134f8b.mjs} +7 -2
- package/dist/index.js +2 -2
- package/dist/index.mjs +2 -2
- package/dist/internals/context.d.ts +0 -4
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getArrayQueryKey.d.ts +9 -5
- package/dist/internals/getArrayQueryKey.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts.map +1 -1
- package/dist/internals/useQueries.d.ts +28 -0
- package/dist/internals/useQueries.d.ts.map +1 -0
- package/dist/shared/hooks/createHooksInternal.d.ts +7 -1
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/index.d.ts +2 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +4 -2
- package/dist/shared/index.mjs +2 -2
- package/dist/shared/proxy/decorationProxy.d.ts.map +1 -1
- package/dist/shared/proxy/useQueriesProxy.d.ts +18 -0
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -0
- package/dist/shared/proxy/utilsProxy.d.ts +13 -13
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/ssg/index.js +1 -1
- package/dist/ssg/index.mjs +1 -1
- package/package.json +6 -6
- package/src/createTRPCReact.tsx +19 -5
- package/src/internals/context.tsx +0 -7
- package/src/internals/getArrayQueryKey.test.ts +11 -0
- package/src/internals/getArrayQueryKey.ts +12 -3
- package/src/internals/getQueryKey.ts +2 -1
- package/src/internals/useQueries.ts +84 -0
- package/src/shared/hooks/createHooksInternal.tsx +41 -1
- package/src/shared/index.ts +2 -0
- package/src/shared/proxy/decorationProxy.ts +7 -0
- package/src/shared/proxy/useQueriesProxy.ts +83 -0
- package/src/shared/proxy/utilsProxy.ts +13 -12
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TRPCClient, TRPCClientError } from '@trpc/client';
|
|
2
|
+
import { AnyProcedure, AnyQueryProcedure, AnyRouter, Filter, inferProcedureInput } from '@trpc/server';
|
|
3
|
+
import { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
4
|
+
import { TrpcQueryOptionsForUseQueries } from '../../internals/useQueries';
|
|
5
|
+
declare type GetQueryOptions<TRouter extends AnyRouter, TProcedure extends AnyProcedure, TPath extends string> = <TData = inferTransformedProcedureOutput<TProcedure>>(input: inferProcedureInput<TProcedure>, opts?: TrpcQueryOptionsForUseQueries<TPath, inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TData, TRPCClientError<TRouter>>) => TrpcQueryOptionsForUseQueries<TPath, inferProcedureInput<TProcedure>, inferTransformedProcedureOutput<TProcedure>, TData, TRPCClientError<TRouter>>;
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare type UseQueriesProcedureRecord<TRouter extends AnyRouter, TPath extends string = ''> = {
|
|
10
|
+
[TKey in keyof Filter<TRouter['_def']['record'], AnyRouter | AnyQueryProcedure>]: TRouter['_def']['record'][TKey] extends AnyRouter ? UseQueriesProcedureRecord<TRouter['_def']['record'][TKey], `${TPath}${TKey & string}.`> : GetQueryOptions<TRouter, TRouter['_def']['record'][TKey], `${TPath}${TKey & string}`>;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Create proxy for `useQueries` options
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
export declare function createUseQueriesProxy<TRouter extends AnyRouter>(client: TRPCClient<TRouter>): UseQueriesProcedureRecord<TRouter, "">;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=useQueriesProxy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueriesProxy.d.ts","sourceRoot":"","sources":["../../../src/shared/proxy/useQueriesProxy.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,MAAM,EACN,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAEL,+BAA+B,EAChC,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,4BAA4B,CAAC;AAE3E,aAAK,eAAe,CAClB,OAAO,SAAS,SAAS,EACzB,UAAU,SAAS,YAAY,EAC/B,KAAK,SAAS,MAAM,IAClB,CAAC,KAAK,GAAG,+BAA+B,CAAC,UAAU,CAAC,EACtD,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACtC,IAAI,CAAC,EAAE,6BAA6B,CAClC,KAAK,EACL,mBAAmB,CAAC,UAAU,CAAC,EAC/B,+BAA+B,CAAC,UAAU,CAAC,EAC3C,KAAK,EACL,eAAe,CAAC,OAAO,CAAC,CACzB,KACE,6BAA6B,CAChC,KAAK,EACL,mBAAmB,CAAC,UAAU,CAAC,EAC/B,+BAA+B,CAAC,UAAU,CAAC,EAC3C,KAAK,EACL,eAAe,CAAC,OAAO,CAAC,CACzB,CAAC;AAEF;;GAEG;AACH,oBAAY,yBAAyB,CACnC,OAAO,SAAS,SAAS,EACzB,KAAK,SAAS,MAAM,GAAG,EAAE,IACvB;KACD,IAAI,IAAI,MAAM,MAAM,CACnB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACzB,SAAS,GAAG,iBAAiB,CAC9B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GACjD,yBAAyB,CACvB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAC/B,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,GAAG,CAC5B,GACD,eAAe,CACb,OAAO,EACP,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAC/B,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,EAAE,CAC3B;CACN,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,SAAS,EAC7D,MAAM,EAAE,UAAU,CAAC,OAAO,CAAC,0CAkB5B"}
|
|
@@ -5,39 +5,39 @@ import { inferTransformedProcedureOutput } from '@trpc/server/shared';
|
|
|
5
5
|
import { DecoratedProxyTRPCContextProps, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions } from '../../internals/context';
|
|
6
6
|
declare type DecorateProcedure<TRouter extends AnyRouter, TProcedure extends AnyQueryProcedure> = {
|
|
7
7
|
/**
|
|
8
|
-
* @link https://
|
|
8
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchquery
|
|
9
9
|
*/
|
|
10
10
|
fetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TRouter>, inferTransformedProcedureOutput<TProcedure>>): Promise<inferTransformedProcedureOutput<TProcedure>>;
|
|
11
11
|
/**
|
|
12
|
-
* @link https://
|
|
12
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientfetchinfinitequery
|
|
13
13
|
*/
|
|
14
14
|
fetchInfinite(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TRouter>, inferTransformedProcedureOutput<TProcedure>>): Promise<InfiniteData<inferTransformedProcedureOutput<TProcedure>>>;
|
|
15
15
|
/**
|
|
16
|
-
* @link https://
|
|
16
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchquery
|
|
17
17
|
*/
|
|
18
18
|
prefetch(input: inferProcedureInput<TProcedure>, opts?: TRPCFetchQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TRouter>, inferTransformedProcedureOutput<TProcedure>>): Promise<void>;
|
|
19
19
|
/**
|
|
20
|
-
* @link https://
|
|
20
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientprefetchinfinitequery
|
|
21
21
|
*/
|
|
22
22
|
prefetchInfinite(input: inferProcedureInput<TProcedure>, procedureOpts?: ProcedureOptions, opts?: TRPCFetchInfiniteQueryOptions<inferProcedureInput<TProcedure>, TRPCClientError<TRouter>, inferTransformedProcedureOutput<TProcedure>>): Promise<void>;
|
|
23
23
|
/**
|
|
24
|
-
* @link https://
|
|
24
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientinvalidatequeries
|
|
25
25
|
*/
|
|
26
26
|
invalidate(input?: inferProcedureInput<TProcedure>, filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise<void>;
|
|
27
27
|
/**
|
|
28
|
-
* @link https://
|
|
28
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientrefetchqueries
|
|
29
29
|
*/
|
|
30
30
|
refetch(input?: inferProcedureInput<TProcedure>, filters?: RefetchQueryFilters, options?: RefetchOptions): Promise<void>;
|
|
31
31
|
/**
|
|
32
|
-
* @link https://
|
|
32
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientcancelqueries
|
|
33
33
|
*/
|
|
34
34
|
cancel(input?: inferProcedureInput<TProcedure>, options?: CancelOptions): Promise<void>;
|
|
35
35
|
/**
|
|
36
|
-
* @link https://
|
|
36
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientresetqueries
|
|
37
37
|
*/
|
|
38
38
|
reset(input?: inferProcedureInput<TProcedure>, options?: ResetOptions): Promise<void>;
|
|
39
39
|
/**
|
|
40
|
-
* @link https://
|
|
40
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientsetquerydata
|
|
41
41
|
*/
|
|
42
42
|
setData(
|
|
43
43
|
/**
|
|
@@ -45,15 +45,15 @@ declare type DecorateProcedure<TRouter extends AnyRouter, TProcedure extends Any
|
|
|
45
45
|
*/
|
|
46
46
|
input: inferProcedureInput<TProcedure>, updater: Updater<inferTransformedProcedureOutput<TProcedure> | undefined, inferTransformedProcedureOutput<TProcedure> | undefined>, options?: SetDataOptions): void;
|
|
47
47
|
/**
|
|
48
|
-
* @link https://
|
|
48
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientsetquerydata
|
|
49
49
|
*/
|
|
50
50
|
setInfiniteData(input: inferProcedureInput<TProcedure>, updater: Updater<InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined, InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined>, options?: SetDataOptions): void;
|
|
51
51
|
/**
|
|
52
|
-
* @link https://
|
|
52
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientgetquerydata
|
|
53
53
|
*/
|
|
54
54
|
getData(input?: inferProcedureInput<TProcedure>): inferTransformedProcedureOutput<TProcedure> | undefined;
|
|
55
55
|
/**
|
|
56
|
-
* @link https://
|
|
56
|
+
* @link https://tanstack.com/query/v4/docs/reference/QueryClient#queryclientgetquerydata
|
|
57
57
|
*/
|
|
58
58
|
getInfiniteData(input?: inferProcedureInput<TProcedure>): InfiniteData<inferTransformedProcedureOutput<TProcedure>> | undefined;
|
|
59
59
|
};
|
|
@@ -67,7 +67,7 @@ declare type DecorateRouter = {
|
|
|
67
67
|
* @link https://trpc.io/docs/v10/useContext#query-invalidation
|
|
68
68
|
* @link https://react-query.tanstack.com/guides/query-invalidation
|
|
69
69
|
*/
|
|
70
|
-
invalidate(filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise<void>;
|
|
70
|
+
invalidate(input?: undefined, filters?: InvalidateQueryFilters, options?: InvalidateOptions): Promise<void>;
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
73
73
|
* @internal
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utilsProxy.d.ts","sourceRoot":"","sources":["../../../src/shared/proxy/utilsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,OAAO,EACR,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAyB,MAAM,cAAc,CAAC;AACtE,OAAO,EACL,iBAAiB,EACjB,SAAS,EACT,MAAM,EACN,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,+BAA+B,EAChC,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,8BAA8B,EAC9B,gBAAgB,EAChB,6BAA6B,EAC7B,qBAAqB,EAEtB,MAAM,yBAAyB,CAAC;AAGjC,aAAK,iBAAiB,CACpB,OAAO,SAAS,SAAS,EACzB,UAAU,SAAS,iBAAiB,IAClC;IACF;;OAEG;IACH,KAAK,CACH,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACtC,IAAI,CAAC,EAAE,qBAAqB,CAC1B,mBAAmB,CAAC,UAAU,CAAC,EAC/B,eAAe,CAAC,OAAO,CAAC,EACxB,+BAA+B,CAAC,UAAU,CAAC,CAC5C,GACA,OAAO,CAAC,+BAA+B,CAAC,UAAU,CAAC,CAAC,CAAC;IAExD;;OAEG;IACH,aAAa,CACX,KAAK,EAAE,mBAAmB,CAAC,UAAU,CAAC,EACtC,IAAI,CAAC,EAAE,6BAA6B,CAClC,mBAAmB,CAAC,UAAU,CAAC,EAC/B,eAAe,CAAC,OAAO,CAAC,EACxB,+BAA+B,CAAC,UAAU,CAAC,CAC5C,GACA,OAAO,CAA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BAAsB,EAChC,OAAO,CAAC,EAAE,iBAAiB,GAC1B,OAAO,CAAC,IAAI,CAAC,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,oBAAY,6BAA6B,CAAC,OAAO,SAAS,SAAS,IAAI;KACpE,IAAI,IAAI,MAAM,MAAM,CACnB,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,EACzB,SAAS,GAAG,iBAAiB,CAC9B,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,GACjD,6BAA6B,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,GAC5D,cAAc,GAEhB,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;CAChE,GAAG,cAAc,CAAC;AAInB,oBAAY,qBAAqB,CAC/B,OAAO,SAAS,SAAS,EACzB,WAAW,IACT,6BAA6B,CAAC,OAAO,CAAC,GACxC,8BAA8B,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;AAEvD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,OAAO,SAAS,SAAS,EACzB,WAAW,EACX,OAAO,EAAE,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,+CAkE9C"}
|
package/dist/ssg/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var reactQuery = require('@tanstack/react-query');
|
|
6
6
|
var server = require('@trpc/server');
|
|
7
|
-
var getArrayQueryKey = require('../getArrayQueryKey-
|
|
7
|
+
var getArrayQueryKey = require('../getArrayQueryKey-4bdb5cc2.js');
|
|
8
8
|
var shared = require('@trpc/server/shared');
|
|
9
9
|
require('@trpc/client');
|
|
10
10
|
require('react');
|
package/dist/ssg/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { dehydrate } from '@tanstack/react-query';
|
|
2
2
|
import { callProcedure } from '@trpc/server';
|
|
3
|
-
import { g as getArrayQueryKey } from '../getArrayQueryKey-
|
|
3
|
+
import { g as getArrayQueryKey } from '../getArrayQueryKey-86134f8b.mjs';
|
|
4
4
|
import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
|
|
5
5
|
import '@trpc/client';
|
|
6
6
|
import 'react';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/react-query",
|
|
3
|
-
"version": "10.
|
|
3
|
+
"version": "10.7.0",
|
|
4
4
|
"description": "tRPC React lib",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
56
|
"@tanstack/react-query": "^4.3.8",
|
|
57
|
-
"@trpc/client": "10.
|
|
58
|
-
"@trpc/server": "10.
|
|
57
|
+
"@trpc/client": "10.7.0",
|
|
58
|
+
"@trpc/server": "10.7.0",
|
|
59
59
|
"react": ">=16.8.0",
|
|
60
60
|
"react-dom": ">=16.8.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"@tanstack/react-query": "^4.3.8",
|
|
64
|
-
"@trpc/client": "10.
|
|
65
|
-
"@trpc/server": "10.
|
|
64
|
+
"@trpc/client": "10.7.0",
|
|
65
|
+
"@trpc/server": "10.7.0",
|
|
66
66
|
"@types/express": "^4.17.12",
|
|
67
67
|
"@types/node": "^18.7.20",
|
|
68
68
|
"express": "^4.17.1",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "dd8e424c0f0d3a43b6c6cb0356c4ac1b8199c4d0"
|
|
80
80
|
}
|
package/src/createTRPCReact.tsx
CHANGED
|
@@ -15,6 +15,8 @@ import {
|
|
|
15
15
|
inferTransformedSubscriptionOutput,
|
|
16
16
|
} from '@trpc/server/shared';
|
|
17
17
|
import { useMemo } from 'react';
|
|
18
|
+
import { QueryKey, QueryType } from './internals/getArrayQueryKey';
|
|
19
|
+
import { TRPCUseQueries } from './internals/useQueries';
|
|
18
20
|
import {
|
|
19
21
|
CreateReactUtilsProxy,
|
|
20
22
|
createReactProxyDecoration,
|
|
@@ -47,6 +49,15 @@ export type DecorateProcedure<
|
|
|
47
49
|
TPath extends string,
|
|
48
50
|
> = TProcedure extends AnyQueryProcedure
|
|
49
51
|
? {
|
|
52
|
+
/**
|
|
53
|
+
* Method to extract the query key for a procedure
|
|
54
|
+
* @param type - defaults to `any`
|
|
55
|
+
* @link https://trpc.io/docs/useContext#-the-function-i-want-isnt-here
|
|
56
|
+
*/
|
|
57
|
+
getQueryKey: (
|
|
58
|
+
input: inferProcedureInput<TProcedure>,
|
|
59
|
+
type?: QueryType,
|
|
60
|
+
) => QueryKey;
|
|
50
61
|
useQuery: <
|
|
51
62
|
TQueryFnData = inferTransformedProcedureOutput<TProcedure>,
|
|
52
63
|
TData = inferTransformedProcedureOutput<TProcedure>,
|
|
@@ -101,8 +112,8 @@ export type DecorateProcedure<
|
|
|
101
112
|
>,
|
|
102
113
|
];
|
|
103
114
|
}
|
|
104
|
-
:
|
|
105
|
-
:
|
|
115
|
+
: object)
|
|
116
|
+
: object) &
|
|
106
117
|
(TFlags extends 'ExperimentalSuspense'
|
|
107
118
|
? {
|
|
108
119
|
useSuspenseQuery: <
|
|
@@ -125,7 +136,7 @@ export type DecorateProcedure<
|
|
|
125
136
|
UseTRPCQuerySuccessResult<TData, TRPCClientErrorLike<TProcedure>>,
|
|
126
137
|
];
|
|
127
138
|
}
|
|
128
|
-
:
|
|
139
|
+
: object)
|
|
129
140
|
: TProcedure extends AnyMutationProcedure
|
|
130
141
|
? {
|
|
131
142
|
useMutation: <TContext = unknown>(
|
|
@@ -163,7 +174,9 @@ export type DecoratedProcedureRecord<
|
|
|
163
174
|
TPath extends string = '',
|
|
164
175
|
> = {
|
|
165
176
|
[TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
|
|
166
|
-
?
|
|
177
|
+
? {
|
|
178
|
+
getQueryKey: () => QueryKey;
|
|
179
|
+
} & DecoratedProcedureRecord<
|
|
167
180
|
TProcedures[TKey]['_def']['record'],
|
|
168
181
|
TFlags,
|
|
169
182
|
`${TPath}${TKey & string}.`
|
|
@@ -177,6 +190,7 @@ export type CreateTRPCReact<TRouter extends AnyRouter, TSSRContext, TFlags> = {
|
|
|
177
190
|
useContext(): CreateReactUtilsProxy<TRouter, TSSRContext>;
|
|
178
191
|
Provider: TRPCProvider<TRouter, TSSRContext>;
|
|
179
192
|
createClient: CreateClient<TRouter>;
|
|
193
|
+
useQueries: TRPCUseQueries<TRouter>;
|
|
180
194
|
useDehydratedState: UseDehydratedState<TRouter>;
|
|
181
195
|
} & DecoratedProcedureRecord<TRouter['_def']['record'], TFlags>;
|
|
182
196
|
|
|
@@ -196,7 +210,7 @@ export function createHooksInternalProxy<
|
|
|
196
210
|
const context = trpc.useContext();
|
|
197
211
|
// create a stable reference of the utils context
|
|
198
212
|
return useMemo(() => {
|
|
199
|
-
return (createReactQueryUtilsProxy as any)(context
|
|
213
|
+
return (createReactQueryUtilsProxy as any)(context);
|
|
200
214
|
}, [context]);
|
|
201
215
|
};
|
|
202
216
|
}
|
|
@@ -160,13 +160,6 @@ export interface TRPCContextState<
|
|
|
160
160
|
filters?: InvalidateQueryFilters,
|
|
161
161
|
options?: InvalidateOptions,
|
|
162
162
|
): Promise<void>;
|
|
163
|
-
/**
|
|
164
|
-
* @link https://react-query.tanstack.com/guides/query-invalidation
|
|
165
|
-
*/
|
|
166
|
-
invalidateQueries(
|
|
167
|
-
filters?: InvalidateQueryFilters,
|
|
168
|
-
options?: InvalidateOptions,
|
|
169
|
-
): Promise<void>;
|
|
170
163
|
|
|
171
164
|
/**
|
|
172
165
|
* @link https://react-query.tanstack.com/reference/QueryClient#queryclientresetqueries
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { getArrayQueryKey } from './getArrayQueryKey';
|
|
2
2
|
|
|
3
3
|
test('getArrayQueryKey', () => {
|
|
4
|
+
// empty path should not nest an extra array
|
|
5
|
+
expect(getArrayQueryKey('', 'any')).toMatchInlineSnapshot(`Array []`);
|
|
6
|
+
|
|
7
|
+
// should not nest an empty object
|
|
8
|
+
expect(getArrayQueryKey('foo', 'any')).toMatchInlineSnapshot(`
|
|
9
|
+
Array [
|
|
10
|
+
Array [
|
|
11
|
+
"foo",
|
|
12
|
+
],
|
|
13
|
+
]
|
|
14
|
+
`);
|
|
4
15
|
expect(getArrayQueryKey('foo', 'query')).toMatchInlineSnapshot(`
|
|
5
16
|
Array [
|
|
6
17
|
Array [
|
|
@@ -1,16 +1,21 @@
|
|
|
1
1
|
export type QueryType = 'query' | 'infinite' | 'any';
|
|
2
2
|
|
|
3
|
+
export type QueryKey = [
|
|
4
|
+
string[],
|
|
5
|
+
{ input?: unknown; type?: Exclude<QueryType, 'any'> }?,
|
|
6
|
+
];
|
|
7
|
+
|
|
3
8
|
/**
|
|
4
9
|
* To allow easy interactions with groups of related queries, such as
|
|
5
10
|
* invalidating all queries of a router, we use an array as the path when
|
|
6
11
|
* storing in tanstack query. This function converts from the `.` separated
|
|
7
12
|
* path passed around internally by both the legacy and proxy implementation.
|
|
8
13
|
* https://github.com/trpc/trpc/issues/2611
|
|
9
|
-
|
|
14
|
+
**/
|
|
10
15
|
export function getArrayQueryKey(
|
|
11
16
|
queryKey: string | [string] | [string, ...unknown[]] | unknown[],
|
|
12
17
|
type: QueryType,
|
|
13
|
-
):
|
|
18
|
+
): QueryKey {
|
|
14
19
|
const queryKeyArrayed = Array.isArray(queryKey) ? queryKey : [queryKey];
|
|
15
20
|
const [path, input] = queryKeyArrayed;
|
|
16
21
|
|
|
@@ -20,10 +25,14 @@ export function getArrayQueryKey(
|
|
|
20
25
|
// Construct a query key that is easy to destructure and flexible for
|
|
21
26
|
// partial selecting etc.
|
|
22
27
|
// https://github.com/trpc/trpc/issues/3128
|
|
28
|
+
if (!input && (!type || type === 'any'))
|
|
29
|
+
// for `utils.invalidate()` to match all queries (including vanilla react-query)
|
|
30
|
+
// we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
|
|
31
|
+
return arrayPath.length ? [arrayPath] : ([] as unknown as QueryKey);
|
|
23
32
|
return [
|
|
24
33
|
arrayPath,
|
|
25
34
|
{
|
|
26
|
-
...(input && { input: input }),
|
|
35
|
+
...(typeof input !== 'undefined' && { input: input }),
|
|
27
36
|
...(type && type !== 'any' && { type: type }),
|
|
28
37
|
},
|
|
29
38
|
];
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { QueryKey, UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { AnyRouter } from '@trpc/server';
|
|
3
|
+
import {
|
|
4
|
+
UseQueriesProcedureRecord,
|
|
5
|
+
UseTRPCQueryOptions,
|
|
6
|
+
UseTRPCQueryResult,
|
|
7
|
+
} from '../shared';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export type UseQueryOptionsForUseQueries<
|
|
13
|
+
TQueryFnData = unknown,
|
|
14
|
+
TError = unknown,
|
|
15
|
+
TData = TQueryFnData,
|
|
16
|
+
TQueryKey extends QueryKey = QueryKey,
|
|
17
|
+
> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'context'>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export type TrpcQueryOptionsForUseQueries<
|
|
23
|
+
TPath,
|
|
24
|
+
TInput,
|
|
25
|
+
TOutput,
|
|
26
|
+
TData,
|
|
27
|
+
TError,
|
|
28
|
+
> = Omit<UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError>, 'context'>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @internal
|
|
32
|
+
*/
|
|
33
|
+
export declare type QueriesResults<
|
|
34
|
+
TQueriesOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[],
|
|
35
|
+
> = {
|
|
36
|
+
[TKey in keyof TQueriesOptions]: TQueriesOptions[TKey] extends UseQueryOptionsForUseQueries<
|
|
37
|
+
infer TQueryFnData,
|
|
38
|
+
infer TError,
|
|
39
|
+
infer TData,
|
|
40
|
+
any
|
|
41
|
+
>
|
|
42
|
+
? UseTRPCQueryResult<unknown extends TData ? TQueryFnData : TData, TError>
|
|
43
|
+
: never;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type GetOptions<TQueryOptions> =
|
|
47
|
+
TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>
|
|
48
|
+
? TQueryOptions
|
|
49
|
+
: never;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export type QueriesOptions<
|
|
55
|
+
TQueriesOptions extends any[],
|
|
56
|
+
TResult extends any[] = [],
|
|
57
|
+
> = TQueriesOptions extends []
|
|
58
|
+
? []
|
|
59
|
+
: TQueriesOptions extends [infer Head]
|
|
60
|
+
? [...TResult, GetOptions<Head>]
|
|
61
|
+
: TQueriesOptions extends [infer Head, ...infer Tail]
|
|
62
|
+
? QueriesOptions<Tail, [...TResult, GetOptions<Head>]>
|
|
63
|
+
: unknown[] extends TQueriesOptions
|
|
64
|
+
? TQueriesOptions
|
|
65
|
+
: TQueriesOptions extends UseQueryOptionsForUseQueries<
|
|
66
|
+
infer TQueryFnData,
|
|
67
|
+
infer TError,
|
|
68
|
+
infer TData,
|
|
69
|
+
infer TQueryKey
|
|
70
|
+
>[]
|
|
71
|
+
? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[]
|
|
72
|
+
: UseQueryOptionsForUseQueries[];
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
export type TRPCUseQueries<TRouter extends AnyRouter> = <
|
|
78
|
+
TQueryOptions extends UseQueryOptionsForUseQueries<any, any, any, any>[],
|
|
79
|
+
>(
|
|
80
|
+
queriesCallback: (
|
|
81
|
+
t: UseQueriesProcedureRecord<TRouter>,
|
|
82
|
+
) => readonly [...QueriesOptions<TQueryOptions>],
|
|
83
|
+
context?: UseQueryOptions['context'],
|
|
84
|
+
) => QueriesResults<TQueryOptions>;
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
InfiniteQueryObserverSuccessResult,
|
|
5
5
|
QueryClient,
|
|
6
6
|
QueryObserverSuccessResult,
|
|
7
|
+
QueryOptions,
|
|
7
8
|
UseInfiniteQueryOptions,
|
|
8
9
|
UseInfiniteQueryResult,
|
|
9
10
|
UseMutationOptions,
|
|
@@ -12,6 +13,7 @@ import {
|
|
|
12
13
|
UseQueryResult,
|
|
13
14
|
useInfiniteQuery as __useInfiniteQuery,
|
|
14
15
|
useMutation as __useMutation,
|
|
16
|
+
useQueries as __useQueries,
|
|
15
17
|
useQuery as __useQuery,
|
|
16
18
|
hashQueryKey,
|
|
17
19
|
useQueryClient,
|
|
@@ -49,6 +51,8 @@ import {
|
|
|
49
51
|
TRPCContextState,
|
|
50
52
|
} from '../../internals/context';
|
|
51
53
|
import { QueryType, getArrayQueryKey } from '../../internals/getArrayQueryKey';
|
|
54
|
+
import { TRPCUseQueries } from '../../internals/useQueries';
|
|
55
|
+
import { createUseQueriesProxy } from '../proxy/useQueriesProxy';
|
|
52
56
|
import { CreateTRPCReactOptions, UseMutationOverride } from '../types';
|
|
53
57
|
|
|
54
58
|
export type OutputWithCursor<TData, TCursor = any> = {
|
|
@@ -82,6 +86,10 @@ export interface UseTRPCQueryOptions<TPath, TInput, TOutput, TData, TError>
|
|
|
82
86
|
extends UseQueryOptions<TOutput, TError, TData, [TPath, TInput]>,
|
|
83
87
|
TRPCUseQueryBaseOptions {}
|
|
84
88
|
|
|
89
|
+
export interface TRPCQueryOptions<TPath, TInput, TData, TError>
|
|
90
|
+
extends QueryOptions<TData, TError, TData, [TPath, TInput]>,
|
|
91
|
+
TRPCUseQueryBaseOptions {}
|
|
92
|
+
|
|
85
93
|
export interface UseTRPCInfiniteQueryOptions<TPath, TInput, TOutput, TError>
|
|
86
94
|
extends UseInfiniteQueryOptions<
|
|
87
95
|
TOutput,
|
|
@@ -107,7 +115,7 @@ export interface UseTRPCSubscriptionOptions<TOutput, TError> {
|
|
|
107
115
|
onError?: (err: TError) => void;
|
|
108
116
|
}
|
|
109
117
|
|
|
110
|
-
function getClientArgs<TPathAndInput extends unknown[], TOptions>(
|
|
118
|
+
export function getClientArgs<TPathAndInput extends unknown[], TOptions>(
|
|
111
119
|
pathAndInput: TPathAndInput,
|
|
112
120
|
opts: TOptions,
|
|
113
121
|
) {
|
|
@@ -654,6 +662,37 @@ export function createHooksInternal<
|
|
|
654
662
|
});
|
|
655
663
|
return hook;
|
|
656
664
|
}
|
|
665
|
+
|
|
666
|
+
const useQueries: TRPCUseQueries<TRouter> = (queriesCallback, context) => {
|
|
667
|
+
const { ssrState, queryClient, prefetchQuery, client } = useContext();
|
|
668
|
+
|
|
669
|
+
const proxy = createUseQueriesProxy(client);
|
|
670
|
+
|
|
671
|
+
const queries = queriesCallback(proxy);
|
|
672
|
+
|
|
673
|
+
if (typeof window === 'undefined' && ssrState === 'prepass') {
|
|
674
|
+
for (const query of queries) {
|
|
675
|
+
const queryOption = query as TRPCQueryOptions<any, any, any, any>;
|
|
676
|
+
if (
|
|
677
|
+
queryOption.trpc?.ssr !== false &&
|
|
678
|
+
!queryClient
|
|
679
|
+
.getQueryCache()
|
|
680
|
+
.find(getArrayQueryKey(queryOption.queryKey!, 'query'))
|
|
681
|
+
) {
|
|
682
|
+
void prefetchQuery(queryOption.queryKey as any, queryOption as any);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
return __useQueries({
|
|
688
|
+
queries: queries.map((query) => ({
|
|
689
|
+
...query,
|
|
690
|
+
queryKey: getArrayQueryKey(query.queryKey, 'query'),
|
|
691
|
+
})),
|
|
692
|
+
context,
|
|
693
|
+
}) as any;
|
|
694
|
+
};
|
|
695
|
+
|
|
657
696
|
const useDehydratedState: UseDehydratedState<TRouter> = (
|
|
658
697
|
client,
|
|
659
698
|
trpcState,
|
|
@@ -673,6 +712,7 @@ export function createHooksInternal<
|
|
|
673
712
|
createClient,
|
|
674
713
|
useContext,
|
|
675
714
|
useQuery,
|
|
715
|
+
useQueries,
|
|
676
716
|
useMutation,
|
|
677
717
|
useSubscription,
|
|
678
718
|
useDehydratedState,
|
package/src/shared/index.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from './proxy/decorationProxy';
|
|
2
2
|
export * from './proxy/utilsProxy';
|
|
3
|
+
export * from './proxy/useQueriesProxy';
|
|
3
4
|
export type {
|
|
4
5
|
DecoratedProcedureRecord,
|
|
5
6
|
DecorateProcedure,
|
|
6
7
|
} from '../createTRPCReact';
|
|
8
|
+
export type { TRPCUseQueries } from '../internals/useQueries';
|
|
7
9
|
export * from './hooks/createHooksInternal';
|
|
8
10
|
export * from './queryClient';
|
|
9
11
|
export * from './types';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AnyRouter } from '@trpc/server';
|
|
2
2
|
import { createRecursiveProxy } from '@trpc/server/shared';
|
|
3
|
+
import { getArrayQueryKey } from '../../internals/getArrayQueryKey';
|
|
3
4
|
import { getQueryKey } from '../../internals/getQueryKey';
|
|
4
5
|
import { CreateReactQueryHooks } from '../hooks/createHooksInternal';
|
|
5
6
|
|
|
@@ -28,6 +29,12 @@ export function createReactProxyDecoration<
|
|
|
28
29
|
const [input, ...rest] = args;
|
|
29
30
|
|
|
30
31
|
const queryKey = getQueryKey(path, input);
|
|
32
|
+
|
|
33
|
+
// Expose queryKey helper
|
|
34
|
+
if (lastArg === 'getQueryKey') {
|
|
35
|
+
return getArrayQueryKey(queryKey, (rest[0] as any) ?? 'any');
|
|
36
|
+
}
|
|
37
|
+
|
|
31
38
|
if (lastArg.startsWith('useSuspense')) {
|
|
32
39
|
const opts = rest[0] || {};
|
|
33
40
|
const fn =
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { QueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import { TRPCClient, TRPCClientError } from '@trpc/client';
|
|
3
|
+
import {
|
|
4
|
+
AnyProcedure,
|
|
5
|
+
AnyQueryProcedure,
|
|
6
|
+
AnyRouter,
|
|
7
|
+
Filter,
|
|
8
|
+
inferProcedureInput,
|
|
9
|
+
} from '@trpc/server';
|
|
10
|
+
import {
|
|
11
|
+
createRecursiveProxy,
|
|
12
|
+
inferTransformedProcedureOutput,
|
|
13
|
+
} from '@trpc/server/shared';
|
|
14
|
+
import { getQueryKey } from '../../internals/getQueryKey';
|
|
15
|
+
import { TrpcQueryOptionsForUseQueries } from '../../internals/useQueries';
|
|
16
|
+
|
|
17
|
+
type GetQueryOptions<
|
|
18
|
+
TRouter extends AnyRouter,
|
|
19
|
+
TProcedure extends AnyProcedure,
|
|
20
|
+
TPath extends string,
|
|
21
|
+
> = <TData = inferTransformedProcedureOutput<TProcedure>>(
|
|
22
|
+
input: inferProcedureInput<TProcedure>,
|
|
23
|
+
opts?: TrpcQueryOptionsForUseQueries<
|
|
24
|
+
TPath,
|
|
25
|
+
inferProcedureInput<TProcedure>,
|
|
26
|
+
inferTransformedProcedureOutput<TProcedure>,
|
|
27
|
+
TData,
|
|
28
|
+
TRPCClientError<TRouter>
|
|
29
|
+
>,
|
|
30
|
+
) => TrpcQueryOptionsForUseQueries<
|
|
31
|
+
TPath,
|
|
32
|
+
inferProcedureInput<TProcedure>,
|
|
33
|
+
inferTransformedProcedureOutput<TProcedure>,
|
|
34
|
+
TData,
|
|
35
|
+
TRPCClientError<TRouter>
|
|
36
|
+
>;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export type UseQueriesProcedureRecord<
|
|
42
|
+
TRouter extends AnyRouter,
|
|
43
|
+
TPath extends string = '',
|
|
44
|
+
> = {
|
|
45
|
+
[TKey in keyof Filter<
|
|
46
|
+
TRouter['_def']['record'],
|
|
47
|
+
AnyRouter | AnyQueryProcedure
|
|
48
|
+
>]: TRouter['_def']['record'][TKey] extends AnyRouter
|
|
49
|
+
? UseQueriesProcedureRecord<
|
|
50
|
+
TRouter['_def']['record'][TKey],
|
|
51
|
+
`${TPath}${TKey & string}.`
|
|
52
|
+
>
|
|
53
|
+
: GetQueryOptions<
|
|
54
|
+
TRouter,
|
|
55
|
+
TRouter['_def']['record'][TKey],
|
|
56
|
+
`${TPath}${TKey & string}`
|
|
57
|
+
>;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Create proxy for `useQueries` options
|
|
62
|
+
* @internal
|
|
63
|
+
*/
|
|
64
|
+
export function createUseQueriesProxy<TRouter extends AnyRouter>(
|
|
65
|
+
client: TRPCClient<TRouter>,
|
|
66
|
+
) {
|
|
67
|
+
return createRecursiveProxy((opts) => {
|
|
68
|
+
const path = opts.path.join('.');
|
|
69
|
+
const [input, ...rest] = opts.args;
|
|
70
|
+
|
|
71
|
+
const queryKey = getQueryKey(path, input);
|
|
72
|
+
|
|
73
|
+
const options: QueryOptions = {
|
|
74
|
+
queryKey,
|
|
75
|
+
queryFn: () => {
|
|
76
|
+
return client.query(path, input);
|
|
77
|
+
},
|
|
78
|
+
...(rest[1] as any),
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
return options;
|
|
82
|
+
}) as UseQueriesProcedureRecord<TRouter>;
|
|
83
|
+
}
|