@trpc/tanstack-react-query 0.0.0-alpha.5 → 10.8.0-alpha-tmp-02-12-response-types-idea.853
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 +5 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/internals/Context.d.ts +16 -9
- package/dist/internals/Context.d.ts.map +1 -1
- package/dist/internals/Context.js +19 -4
- package/dist/internals/Context.mjs +19 -4
- package/dist/internals/createOptionsProxy.d.ts +104 -40
- package/dist/internals/createOptionsProxy.d.ts.map +1 -1
- package/dist/internals/createOptionsProxy.js +43 -31
- package/dist/internals/createOptionsProxy.mjs +44 -32
- package/dist/internals/infiniteQueryOptions.d.ts +37 -28
- package/dist/internals/infiniteQueryOptions.d.ts.map +1 -1
- package/dist/internals/infiniteQueryOptions.js +3 -3
- package/dist/internals/infiniteQueryOptions.mjs +4 -4
- package/dist/internals/mutationOptions.d.ts +9 -4
- package/dist/internals/mutationOptions.d.ts.map +1 -1
- package/dist/internals/mutationOptions.js +3 -1
- package/dist/internals/mutationOptions.mjs +3 -1
- package/dist/internals/queryOptions.d.ts +9 -15
- package/dist/internals/queryOptions.d.ts.map +1 -1
- package/dist/internals/queryOptions.js +5 -3
- package/dist/internals/queryOptions.mjs +6 -4
- package/dist/internals/subscriptionOptions.d.ts +14 -18
- package/dist/internals/subscriptionOptions.d.ts.map +1 -1
- package/dist/internals/subscriptionOptions.js +7 -3
- package/dist/internals/subscriptionOptions.mjs +7 -3
- package/dist/internals/types.d.ts +44 -2
- package/dist/internals/types.d.ts.map +1 -1
- package/dist/internals/utils.d.ts +10 -2
- package/dist/internals/utils.d.ts.map +1 -1
- package/dist/internals/utils.js +10 -4
- package/dist/internals/utils.mjs +10 -4
- package/package.json +27 -26
- package/src/index.ts +4 -3
- package/src/internals/Context.tsx +42 -13
- package/src/internals/createOptionsProxy.ts +246 -114
- package/src/internals/infiniteQueryOptions.ts +53 -27
- package/src/internals/mutationOptions.ts +24 -7
- package/src/internals/queryOptions.ts +20 -5
- package/src/internals/subscriptionOptions.ts +26 -10
- package/src/internals/types.ts +48 -1
- package/src/internals/utils.ts +15 -4
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
|
|
20
20
|
## Documentation
|
|
21
21
|
|
|
22
|
-
Full documentation can be found at https://trpc.io/docs/client/tanstack-react-query/
|
|
22
|
+
Full documentation can be found at https://trpc.io/docs/client/tanstack-react-query/setup.
|
|
23
23
|
|
|
24
24
|
## Installation
|
|
25
25
|
|
|
@@ -27,14 +27,14 @@ Full documentation can be found at https://trpc.io/docs/client/tanstack-react-qu
|
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
# npm
|
|
30
|
-
npm install @trpc/tanstack-react-query
|
|
30
|
+
npm install @trpc/tanstack-react-query @tanstack/react-query
|
|
31
31
|
|
|
32
32
|
# Yarn
|
|
33
|
-
yarn add @trpc/tanstack-react-query
|
|
33
|
+
yarn add @trpc/tanstack-react-query @tanstack/react-query
|
|
34
34
|
|
|
35
35
|
# pnpm
|
|
36
|
-
pnpm add @trpc/tanstack-react-query
|
|
36
|
+
pnpm add @trpc/tanstack-react-query @tanstack/react-query
|
|
37
37
|
|
|
38
38
|
# Bun
|
|
39
|
-
bun add @trpc/tanstack-react-query
|
|
39
|
+
bun add @trpc/tanstack-react-query @tanstack/react-query
|
|
40
40
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
export { createTRPCContext } from './internals/Context';
|
|
2
|
-
export type { TRPCOptionsProxy,
|
|
2
|
+
export type { TRPCOptionsProxy, inferInput, inferOutput, DecorateMutationProcedure, DecorateProcedure, DecorateRouterKeyable, DecorateQueryProcedure, DecorateSubscriptionProcedure, } from './internals/createOptionsProxy';
|
|
3
3
|
export type { TRPCQueryOptions } from './internals/queryOptions';
|
|
4
4
|
export type { TRPCInfiniteQueryOptions } from './internals/infiniteQueryOptions';
|
|
5
5
|
export type { TRPCMutationOptions } from './internals/mutationOptions';
|
|
6
6
|
export type { TRPCSubscriptionOptions, TRPCSubscriptionStatus, TRPCSubscriptionConnectingResult, TRPCSubscriptionErrorResult, TRPCSubscriptionIdleResult, TRPCSubscriptionPendingResult, TRPCSubscriptionResult, } from './internals/subscriptionOptions';
|
|
7
7
|
export { createTRPCOptionsProxy } from './internals/createOptionsProxy';
|
|
8
8
|
export { useSubscription } from './internals/subscriptionOptions';
|
|
9
|
+
export type * from './internals/types';
|
|
9
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,yBAAyB,EACzB,iBAAiB,EACjB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,YAAY,EACV,gBAAgB,EAChB,UAAU,EACV,WAAW,EACX,yBAAyB,EACzB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,EACtB,6BAA6B,GAC9B,MAAM,gCAAgC,CAAC;AACxC,YAAY,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACjE,YAAY,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AACjF,YAAY,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AACvE,YAAY,EACV,uBAAuB,EACvB,sBAAsB,EACtB,gCAAgC,EAChC,2BAA2B,EAC3B,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAClE,mBAAmB,mBAAmB,CAAC"}
|
|
@@ -1,14 +1,21 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
1
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type { TRPCClient } from '@trpc/client';
|
|
3
|
+
import type { AnyTRPCRouter } from '@trpc/server';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import {
|
|
6
|
-
export
|
|
7
|
-
TRPCProvider:
|
|
5
|
+
import type { TRPCOptionsProxy } from './createOptionsProxy';
|
|
6
|
+
export interface CreateTRPCContextResult<TRouter extends AnyTRPCRouter> {
|
|
7
|
+
TRPCProvider: React.FC<{
|
|
8
8
|
children: React.ReactNode;
|
|
9
9
|
queryClient: QueryClient;
|
|
10
|
-
trpcClient:
|
|
11
|
-
}
|
|
10
|
+
trpcClient: TRPCClient<TRouter>;
|
|
11
|
+
}>;
|
|
12
12
|
useTRPC: () => TRPCOptionsProxy<TRouter>;
|
|
13
|
-
|
|
13
|
+
useTRPCClient: () => TRPCClient<TRouter>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create a set of type-safe provider-consumers
|
|
17
|
+
*
|
|
18
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/setup#3a-setup-the-trpc-context-provider
|
|
19
|
+
*/
|
|
20
|
+
export declare function createTRPCContext<TRouter extends AnyTRPCRouter>(): CreateTRPCContextResult<TRouter>;
|
|
14
21
|
//# sourceMappingURL=Context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/internals/Context.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/internals/Context.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAG7D,MAAM,WAAW,uBAAuB,CAAC,OAAO,SAAS,aAAa;IACpE,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC;QACrB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;QAC1B,WAAW,EAAE,WAAW,CAAC;QACzB,UAAU,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;KACjC,CAAC,CAAC;IACH,OAAO,EAAE,MAAM,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACzC,aAAa,EAAE,MAAM,UAAU,CAAC,OAAO,CAAC,CAAC;CAC1C;AACD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,SAAS,aAAa,KAC1B,uBAAuB,CAAC,OAAO,CAAC,CAmDpC"}
|
|
@@ -22,7 +22,12 @@ function _interopNamespaceDefault(e) {
|
|
|
22
22
|
|
|
23
23
|
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Create a set of type-safe provider-consumers
|
|
27
|
+
*
|
|
28
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/setup#3a-setup-the-trpc-context-provider
|
|
29
|
+
*/ function createTRPCContext() {
|
|
30
|
+
const TRPCClientContext = /*#__PURE__*/ React__namespace.createContext(null);
|
|
26
31
|
const TRPCContext = /*#__PURE__*/ React__namespace.createContext(null);
|
|
27
32
|
function TRPCProvider(props) {
|
|
28
33
|
const value = React__namespace.useMemo(()=>createOptionsProxy.createTRPCOptionsProxy({
|
|
@@ -32,9 +37,11 @@ function createTRPCContext() {
|
|
|
32
37
|
props.trpcClient,
|
|
33
38
|
props.queryClient
|
|
34
39
|
]);
|
|
35
|
-
return /*#__PURE__*/ React__namespace.createElement(
|
|
40
|
+
return /*#__PURE__*/ React__namespace.createElement(TRPCClientContext.Provider, {
|
|
41
|
+
value: props.trpcClient
|
|
42
|
+
}, /*#__PURE__*/ React__namespace.createElement(TRPCContext.Provider, {
|
|
36
43
|
value: value
|
|
37
|
-
}, props.children);
|
|
44
|
+
}, props.children));
|
|
38
45
|
}
|
|
39
46
|
function useTRPC() {
|
|
40
47
|
const utils = React__namespace.useContext(TRPCContext);
|
|
@@ -43,9 +50,17 @@ function createTRPCContext() {
|
|
|
43
50
|
}
|
|
44
51
|
return utils;
|
|
45
52
|
}
|
|
53
|
+
function useTRPCClient() {
|
|
54
|
+
const client = React__namespace.useContext(TRPCClientContext);
|
|
55
|
+
if (!client) {
|
|
56
|
+
throw new Error('useTRPCClient() can only be used inside of a <TRPCProvider>');
|
|
57
|
+
}
|
|
58
|
+
return client;
|
|
59
|
+
}
|
|
46
60
|
return {
|
|
47
61
|
TRPCProvider,
|
|
48
|
-
useTRPC
|
|
62
|
+
useTRPC,
|
|
63
|
+
useTRPCClient
|
|
49
64
|
};
|
|
50
65
|
}
|
|
51
66
|
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { createTRPCOptionsProxy } from './createOptionsProxy.mjs';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Create a set of type-safe provider-consumers
|
|
6
|
+
*
|
|
7
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/setup#3a-setup-the-trpc-context-provider
|
|
8
|
+
*/ function createTRPCContext() {
|
|
9
|
+
const TRPCClientContext = /*#__PURE__*/ React.createContext(null);
|
|
5
10
|
const TRPCContext = /*#__PURE__*/ React.createContext(null);
|
|
6
11
|
function TRPCProvider(props) {
|
|
7
12
|
const value = React.useMemo(()=>createTRPCOptionsProxy({
|
|
@@ -11,9 +16,11 @@ function createTRPCContext() {
|
|
|
11
16
|
props.trpcClient,
|
|
12
17
|
props.queryClient
|
|
13
18
|
]);
|
|
14
|
-
return /*#__PURE__*/ React.createElement(
|
|
19
|
+
return /*#__PURE__*/ React.createElement(TRPCClientContext.Provider, {
|
|
20
|
+
value: props.trpcClient
|
|
21
|
+
}, /*#__PURE__*/ React.createElement(TRPCContext.Provider, {
|
|
15
22
|
value: value
|
|
16
|
-
}, props.children);
|
|
23
|
+
}, props.children));
|
|
17
24
|
}
|
|
18
25
|
function useTRPC() {
|
|
19
26
|
const utils = React.useContext(TRPCContext);
|
|
@@ -22,9 +29,17 @@ function createTRPCContext() {
|
|
|
22
29
|
}
|
|
23
30
|
return utils;
|
|
24
31
|
}
|
|
32
|
+
function useTRPCClient() {
|
|
33
|
+
const client = React.useContext(TRPCClientContext);
|
|
34
|
+
if (!client) {
|
|
35
|
+
throw new Error('useTRPCClient() can only be used inside of a <TRPCProvider>');
|
|
36
|
+
}
|
|
37
|
+
return client;
|
|
38
|
+
}
|
|
25
39
|
return {
|
|
26
40
|
TRPCProvider,
|
|
27
|
-
useTRPC
|
|
41
|
+
useTRPC,
|
|
42
|
+
useTRPCClient
|
|
28
43
|
};
|
|
29
44
|
}
|
|
30
45
|
|
|
@@ -1,109 +1,173 @@
|
|
|
1
|
-
import type { DataTag } from '@tanstack/react-query';
|
|
2
|
-
import {
|
|
3
|
-
import { TRPCUntypedClient
|
|
4
|
-
import {
|
|
5
|
-
import type {
|
|
1
|
+
import type { DataTag, QueryClient, QueryFilters } from '@tanstack/react-query';
|
|
2
|
+
import type { TRPCClient, TRPCClientErrorLike } from '@trpc/client';
|
|
3
|
+
import { TRPCUntypedClient } from '@trpc/client';
|
|
4
|
+
import type { AnyTRPCProcedure, AnyTRPCRootTypes, AnyTRPCRouter, inferProcedureInput, inferRouterContext, inferTransformedProcedureOutput, TRPCProcedureType, TRPCRouterRecord } from '@trpc/server';
|
|
5
|
+
import type { MaybePromise } from '@trpc/server/unstable-core-do-not-import';
|
|
6
6
|
import { type TRPCInfiniteQueryOptions } from './infiniteQueryOptions';
|
|
7
7
|
import type { MutationOptionsOverride } from './mutationOptions';
|
|
8
8
|
import { type TRPCMutationOptions } from './mutationOptions';
|
|
9
9
|
import { type TRPCQueryOptions } from './queryOptions';
|
|
10
10
|
import { type TRPCSubscriptionOptions } from './subscriptionOptions';
|
|
11
|
-
import type { ResolverDef, TRPCMutationKey, TRPCQueryKey } from './types';
|
|
12
|
-
export interface
|
|
11
|
+
import type { OptionalCursorInput, ResolverDef, TRPCInfiniteData, TRPCMutationKey, TRPCQueryKey, WithRequired } from './types';
|
|
12
|
+
export interface DecorateRouterKeyable {
|
|
13
13
|
/**
|
|
14
|
-
* Calculate the TanStack Query Key for
|
|
14
|
+
* Calculate the TanStack Query Key for any path, could be used to invalidate every procedure beneath this path
|
|
15
15
|
*
|
|
16
16
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
17
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
+
pathKey: () => TRPCQueryKey;
|
|
19
20
|
/**
|
|
20
|
-
* Calculate a TanStack Query Filter for
|
|
21
|
+
* Calculate a TanStack Query Filter for any path, could be used to manipulate every procedure beneath this path
|
|
21
22
|
*
|
|
22
23
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
24
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter
|
|
23
25
|
*/
|
|
24
|
-
|
|
26
|
+
pathFilter: (filters?: QueryFilters<unknown, unknown, unknown, TRPCQueryKey>) => WithRequired<QueryFilters<unknown, unknown, unknown, TRPCQueryKey>, 'queryKey'>;
|
|
25
27
|
}
|
|
26
|
-
|
|
27
|
-
export type InferOutput<TProcedure extends DecorateQueryProcedure<any> | DecorateMutationProcedure<any>> = TProcedure['~types']['output'];
|
|
28
|
-
export interface DecorateQueryProcedure<TDef extends ResolverDef> {
|
|
28
|
+
interface TypeHelper<TDef extends ResolverDef> {
|
|
29
29
|
/**
|
|
30
|
-
* @internal prefer using
|
|
30
|
+
* @internal prefer using inferInput and inferOutput to access types
|
|
31
31
|
*/
|
|
32
32
|
'~types': {
|
|
33
33
|
input: TDef['input'];
|
|
34
34
|
output: TDef['output'];
|
|
35
35
|
errorShape: TDef['errorShape'];
|
|
36
36
|
};
|
|
37
|
+
}
|
|
38
|
+
export type inferInput<TProcedure extends DecorateInfiniteQueryProcedure<any> | DecorateQueryProcedure<any> | DecorateMutationProcedure<any>> = TProcedure['~types']['input'];
|
|
39
|
+
export type inferOutput<TProcedure extends DecorateInfiniteQueryProcedure<any> | DecorateQueryProcedure<any> | DecorateMutationProcedure<any>> = TProcedure['~types']['output'];
|
|
40
|
+
export interface DecorateInfiniteQueryProcedure<TDef extends ResolverDef> extends TypeHelper<TDef> {
|
|
37
41
|
/**
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
queryOptions: TRPCQueryOptions<TDef>;
|
|
41
|
-
/**
|
|
42
|
+
* Create a set of type-safe infinite query options that can be passed to `useInfiniteQuery`, `prefetchInfiniteQuery` etc.
|
|
43
|
+
*
|
|
42
44
|
* @see https://tanstack.com/query/latest/docs/framework/react/reference/infiniteQueryOptions#infinitequeryoptions
|
|
45
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#infiniteQueryOptions
|
|
43
46
|
*/
|
|
44
47
|
infiniteQueryOptions: TRPCInfiniteQueryOptions<TDef>;
|
|
45
48
|
/**
|
|
46
|
-
* Calculate the TanStack Query Key for a Query Procedure
|
|
49
|
+
* Calculate the TanStack Query Key for a Infinite Query Procedure
|
|
47
50
|
*
|
|
48
51
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
52
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
|
|
49
53
|
*/
|
|
50
|
-
|
|
54
|
+
infiniteQueryKey: (input?: Partial<TDef['input']>) => DataTag<TRPCQueryKey, TRPCInfiniteData<TDef['input'], TDef['output']>, TRPCClientErrorLike<{
|
|
55
|
+
transformer: TDef['transformer'];
|
|
56
|
+
errorShape: TDef['errorShape'];
|
|
57
|
+
}>>;
|
|
51
58
|
/**
|
|
52
|
-
* Calculate a TanStack Query Filter for a Query Procedure
|
|
59
|
+
* Calculate a TanStack Query Filter for a Infinite Query Procedure
|
|
53
60
|
*
|
|
54
61
|
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
62
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter
|
|
55
63
|
*/
|
|
56
|
-
|
|
64
|
+
infiniteQueryFilter: (input?: Partial<TDef['input']>, filters?: QueryFilters<TRPCInfiniteData<TDef['input'], TDef['output']>, TRPCClientErrorLike<{
|
|
65
|
+
transformer: TDef['transformer'];
|
|
66
|
+
errorShape: TDef['errorShape'];
|
|
67
|
+
}>, TRPCInfiniteData<TDef['input'], TDef['output']>, DataTag<TRPCQueryKey, TRPCInfiniteData<TDef['input'], TDef['output']>, TRPCClientErrorLike<{
|
|
68
|
+
transformer: TDef['transformer'];
|
|
69
|
+
errorShape: TDef['errorShape'];
|
|
70
|
+
}>>>) => WithRequired<QueryFilters<TRPCInfiniteData<TDef['input'], TDef['output']>, TRPCClientErrorLike<{
|
|
71
|
+
transformer: TDef['transformer'];
|
|
72
|
+
errorShape: TDef['errorShape'];
|
|
73
|
+
}>, TRPCInfiniteData<TDef['input'], TDef['output']>, DataTag<TRPCQueryKey, TRPCInfiniteData<TDef['input'], TDef['output']>, TRPCClientErrorLike<{
|
|
74
|
+
transformer: TDef['transformer'];
|
|
75
|
+
errorShape: TDef['errorShape'];
|
|
76
|
+
}>>>, 'queryKey'>;
|
|
57
77
|
}
|
|
58
|
-
export interface
|
|
78
|
+
export interface DecorateQueryProcedure<TDef extends ResolverDef> extends TypeHelper<TDef>, DecorateRouterKeyable {
|
|
59
79
|
/**
|
|
60
|
-
*
|
|
80
|
+
* Create a set of type-safe query options that can be passed to `useQuery`, `prefetchQuery` etc.
|
|
81
|
+
*
|
|
82
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/reference/queryOptions#queryoptions
|
|
83
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryOptions
|
|
61
84
|
*/
|
|
62
|
-
|
|
63
|
-
input: TDef['input'];
|
|
64
|
-
output: TDef['output'];
|
|
65
|
-
};
|
|
85
|
+
queryOptions: TRPCQueryOptions<TDef>;
|
|
66
86
|
/**
|
|
67
|
-
*
|
|
87
|
+
* Calculate the TanStack Query Key for a Query Procedure
|
|
88
|
+
*
|
|
89
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/guides/query-keys
|
|
90
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryKey
|
|
91
|
+
*/
|
|
92
|
+
queryKey: (input?: Partial<TDef['input']>) => DataTag<TRPCQueryKey, TDef['output'], TRPCClientErrorLike<{
|
|
93
|
+
transformer: TDef['transformer'];
|
|
94
|
+
errorShape: TDef['errorShape'];
|
|
95
|
+
}>>;
|
|
96
|
+
/**
|
|
97
|
+
* Calculate a TanStack Query Filter for a Query Procedure
|
|
98
|
+
*
|
|
99
|
+
* @see https://tanstack.com/query/latest/docs/framework/react/guides/filters
|
|
100
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#queryFilter
|
|
101
|
+
*/
|
|
102
|
+
queryFilter: (input?: Partial<TDef['input']>, filters?: QueryFilters<TDef['output'], TRPCClientErrorLike<{
|
|
103
|
+
transformer: TDef['transformer'];
|
|
104
|
+
errorShape: TDef['errorShape'];
|
|
105
|
+
}>, TDef['output'], DataTag<TRPCQueryKey, TDef['output'], TRPCClientErrorLike<{
|
|
106
|
+
transformer: TDef['transformer'];
|
|
107
|
+
errorShape: TDef['errorShape'];
|
|
108
|
+
}>>>) => WithRequired<QueryFilters<TDef['output'], TRPCClientErrorLike<{
|
|
109
|
+
transformer: TDef['transformer'];
|
|
110
|
+
errorShape: TDef['errorShape'];
|
|
111
|
+
}>, TDef['output'], DataTag<TRPCQueryKey, TDef['output'], TRPCClientErrorLike<{
|
|
112
|
+
transformer: TDef['transformer'];
|
|
113
|
+
errorShape: TDef['errorShape'];
|
|
114
|
+
}>>>, 'queryKey'>;
|
|
115
|
+
}
|
|
116
|
+
export interface DecorateMutationProcedure<TDef extends ResolverDef> extends TypeHelper<TDef> {
|
|
117
|
+
/**
|
|
118
|
+
* Create a set of type-safe mutation options that can be passed to `useMutation`
|
|
119
|
+
*
|
|
120
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationOptions
|
|
68
121
|
*/
|
|
69
122
|
mutationOptions: TRPCMutationOptions<TDef>;
|
|
70
123
|
/**
|
|
71
124
|
* Calculate the TanStack Mutation Key for a Mutation Procedure
|
|
125
|
+
*
|
|
126
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#mutationKey
|
|
72
127
|
*/
|
|
73
128
|
mutationKey: () => TRPCMutationKey;
|
|
74
129
|
}
|
|
75
130
|
export interface DecorateSubscriptionProcedure<TDef extends ResolverDef> {
|
|
76
131
|
/**
|
|
77
|
-
*
|
|
132
|
+
* Create a set of type-safe subscription options that can be passed to `useSubscription`
|
|
133
|
+
*
|
|
134
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/usage#subscriptionOptions
|
|
78
135
|
*/
|
|
79
136
|
subscriptionOptions: TRPCSubscriptionOptions<TDef>;
|
|
80
137
|
}
|
|
81
|
-
export type DecorateProcedure<TType extends
|
|
138
|
+
export type DecorateProcedure<TType extends TRPCProcedureType, TDef extends ResolverDef> = TType extends 'query' ? DecorateQueryProcedure<TDef> & (TDef['input'] extends OptionalCursorInput ? DecorateInfiniteQueryProcedure<TDef> : Record<string, never>) : TType extends 'mutation' ? DecorateMutationProcedure<TDef> : TType extends 'subscription' ? DecorateSubscriptionProcedure<TDef> : never;
|
|
82
139
|
/**
|
|
83
140
|
* @internal
|
|
84
141
|
*/
|
|
85
|
-
export type
|
|
86
|
-
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends
|
|
142
|
+
export type DecoratedRouterRecord<TRoot extends AnyTRPCRootTypes, TRecord extends TRPCRouterRecord> = {
|
|
143
|
+
[TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends TRPCRouterRecord ? DecoratedRouterRecord<TRoot, $Value> & DecorateRouterKeyable : $Value extends AnyTRPCProcedure ? DecorateProcedure<$Value['_def']['type'], {
|
|
87
144
|
input: inferProcedureInput<$Value>;
|
|
88
145
|
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
|
89
146
|
transformer: TRoot['transformer'];
|
|
90
147
|
errorShape: TRoot['errorShape'];
|
|
91
148
|
}> : never : never;
|
|
92
149
|
};
|
|
93
|
-
export type TRPCOptionsProxy<TRouter extends
|
|
150
|
+
export type TRPCOptionsProxy<TRouter extends AnyTRPCRouter> = DecoratedRouterRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']> & DecorateRouterKeyable;
|
|
94
151
|
export interface TRPCOptionsProxyOptionsBase {
|
|
95
152
|
queryClient: QueryClient | (() => QueryClient);
|
|
96
153
|
overrides?: {
|
|
97
154
|
mutations?: MutationOptionsOverride;
|
|
98
155
|
};
|
|
99
156
|
}
|
|
100
|
-
export interface TRPCOptionsProxyOptionsInternal<TRouter extends
|
|
157
|
+
export interface TRPCOptionsProxyOptionsInternal<TRouter extends AnyTRPCRouter> {
|
|
101
158
|
router: TRouter;
|
|
102
159
|
ctx: inferRouterContext<TRouter> | (() => MaybePromise<inferRouterContext<TRouter>>);
|
|
103
160
|
}
|
|
104
|
-
export interface TRPCOptionsProxyOptionsExternal<TRouter extends
|
|
105
|
-
client: TRPCUntypedClient<TRouter> |
|
|
161
|
+
export interface TRPCOptionsProxyOptionsExternal<TRouter extends AnyTRPCRouter> {
|
|
162
|
+
client: TRPCUntypedClient<TRouter> | TRPCClient<TRouter>;
|
|
106
163
|
}
|
|
107
|
-
export type TRPCOptionsProxyOptions<TRouter extends
|
|
108
|
-
|
|
164
|
+
export type TRPCOptionsProxyOptions<TRouter extends AnyTRPCRouter> = TRPCOptionsProxyOptionsBase & (TRPCOptionsProxyOptionsInternal<TRouter> | TRPCOptionsProxyOptionsExternal<TRouter>);
|
|
165
|
+
/**
|
|
166
|
+
* Create a typed proxy from your router types. Can also be used on the server.
|
|
167
|
+
*
|
|
168
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/setup#3b-setup-without-react-context
|
|
169
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/server-components#5-create-a-trpc-caller-for-server-components
|
|
170
|
+
*/
|
|
171
|
+
export declare function createTRPCOptionsProxy<TRouter extends AnyTRPCRouter>(opts: TRPCOptionsProxyOptions<TRouter>): TRPCOptionsProxy<TRouter>;
|
|
172
|
+
export {};
|
|
109
173
|
//# sourceMappingURL=createOptionsProxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createOptionsProxy.d.ts","sourceRoot":"","sources":["../../src/internals/createOptionsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"createOptionsProxy.d.ts","sourceRoot":"","sources":["../../src/internals/createOptionsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EACV,UAAU,EACV,mBAAmB,EAEpB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAoB,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnE,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,+BAA+B,EAC/B,iBAAiB,EACjB,gBAAgB,EACjB,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,EAEL,KAAK,wBAAwB,EAC9B,MAAM,wBAAwB,CAA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ED,MAAM,WAAW,+BAA+B,CAC9C,OAAO,SAAS,aAAa;IAE7B,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EACC,kBAAkB,CAAC,OAAO,CAAC,GAC3B,CAAC,MAAM,YAAY,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,+BAA+B,CAC9C,OAAO,SAAS,aAAa;IAE7B,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;CAC1D;AAED,MAAM,MAAM,uBAAuB,CAAC,OAAO,SAAS,aAAa,IAC/D,2BAA2B,GACzB,CACI,+BAA+B,CAAC,OAAO,CAAC,GACxC,+BAA+B,CAAC,OAAO,CAAC,CAC3C,CAAC;AASN;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,SAAS,aAAa,EAClE,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC,GACrC,gBAAgB,CAAC,OAAO,CAAC,CA4G3B"}
|
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var client = require('@trpc/client');
|
|
4
|
-
var
|
|
4
|
+
var server = require('@trpc/server');
|
|
5
5
|
var infiniteQueryOptions = require('./infiniteQueryOptions.js');
|
|
6
6
|
var mutationOptions = require('./mutationOptions.js');
|
|
7
7
|
var queryOptions = require('./queryOptions.js');
|
|
8
8
|
var subscriptionOptions = require('./subscriptionOptions.js');
|
|
9
9
|
var utils = require('./utils.js');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
-
return map[method];
|
|
19
|
-
}
|
|
20
|
-
function createTRPCOptionsProxy(opts) {
|
|
11
|
+
/**
|
|
12
|
+
* Create a typed proxy from your router types. Can also be used on the server.
|
|
13
|
+
*
|
|
14
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/setup#3b-setup-without-react-context
|
|
15
|
+
* @see https://trpc.io/docs/client/tanstack-react-query/server-components#5-create-a-trpc-caller-for-server-components
|
|
16
|
+
*/ function createTRPCOptionsProxy(opts) {
|
|
21
17
|
const callIt = (type)=>{
|
|
22
18
|
return (path, input, trpcOpts)=>{
|
|
23
19
|
if ('router' in opts) {
|
|
24
|
-
return Promise.resolve(utils.unwrapLazyArg(opts.ctx)).then((ctx)=>
|
|
20
|
+
return Promise.resolve(utils.unwrapLazyArg(opts.ctx)).then((ctx)=>server.callTRPCProcedure({
|
|
25
21
|
router: opts.router,
|
|
26
22
|
path: path,
|
|
27
23
|
getRawInput: async ()=>input,
|
|
@@ -34,47 +30,60 @@ function createTRPCOptionsProxy(opts) {
|
|
|
34
30
|
return untypedClient[type](path, input, trpcOpts);
|
|
35
31
|
};
|
|
36
32
|
};
|
|
37
|
-
return
|
|
33
|
+
return server.createTRPCRecursiveProxy(({ args, path: _path })=>{
|
|
38
34
|
const path = [
|
|
39
35
|
..._path
|
|
40
36
|
];
|
|
41
37
|
const utilName = path.pop();
|
|
42
38
|
const [arg1, arg2] = args;
|
|
43
|
-
function getQueryKey() {
|
|
44
|
-
const queryType = getQueryType(utilName);
|
|
45
|
-
return utils.getQueryKeyInternal(path, arg1, queryType ?? 'any');
|
|
46
|
-
}
|
|
47
39
|
const contextMap = {
|
|
48
40
|
'~types': undefined,
|
|
49
|
-
|
|
50
|
-
return utils.
|
|
41
|
+
pathKey: ()=>{
|
|
42
|
+
return utils.getQueryKeyInternal(path);
|
|
43
|
+
},
|
|
44
|
+
pathFilter: ()=>{
|
|
45
|
+
return {
|
|
46
|
+
...arg1,
|
|
47
|
+
queryKey: utils.getQueryKeyInternal(path)
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
queryOptions: ()=>{
|
|
51
|
+
return queryOptions.trpcQueryOptions({
|
|
52
|
+
input: arg1,
|
|
53
|
+
opts: arg2,
|
|
54
|
+
path,
|
|
55
|
+
queryClient: opts.queryClient,
|
|
56
|
+
queryKey: utils.getQueryKeyInternal(path, arg1, 'query'),
|
|
57
|
+
query: callIt('query')
|
|
58
|
+
});
|
|
51
59
|
},
|
|
52
60
|
queryKey: ()=>{
|
|
53
|
-
return
|
|
61
|
+
return utils.getQueryKeyInternal(path, arg1, 'query');
|
|
54
62
|
},
|
|
55
63
|
queryFilter: ()=>{
|
|
56
64
|
return {
|
|
57
65
|
...arg2,
|
|
58
|
-
queryKey:
|
|
66
|
+
queryKey: utils.getQueryKeyInternal(path, arg1, 'query')
|
|
59
67
|
};
|
|
60
68
|
},
|
|
61
69
|
infiniteQueryOptions: ()=>{
|
|
62
70
|
return infiniteQueryOptions.trpcInfiniteQueryOptions({
|
|
71
|
+
input: arg1,
|
|
63
72
|
opts: arg2,
|
|
64
73
|
path,
|
|
65
74
|
queryClient: opts.queryClient,
|
|
66
|
-
queryKey:
|
|
75
|
+
queryKey: utils.getQueryKeyInternal(path, arg1, 'infinite'),
|
|
67
76
|
query: callIt('query')
|
|
68
77
|
});
|
|
69
78
|
},
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
}
|
|
79
|
+
infiniteQueryKey: ()=>{
|
|
80
|
+
return utils.getQueryKeyInternal(path, arg1, 'infinite');
|
|
81
|
+
},
|
|
82
|
+
infiniteQueryFilter: ()=>{
|
|
83
|
+
return {
|
|
84
|
+
...arg2,
|
|
85
|
+
queryKey: utils.getQueryKeyInternal(path, arg1, 'infinite')
|
|
86
|
+
};
|
|
78
87
|
},
|
|
79
88
|
mutationOptions: ()=>{
|
|
80
89
|
return mutationOptions.trpcMutationOptions({
|
|
@@ -85,11 +94,14 @@ function createTRPCOptionsProxy(opts) {
|
|
|
85
94
|
overrides: opts.overrides?.mutations
|
|
86
95
|
});
|
|
87
96
|
},
|
|
97
|
+
mutationKey: ()=>{
|
|
98
|
+
return utils.getMutationKeyInternal(path);
|
|
99
|
+
},
|
|
88
100
|
subscriptionOptions: ()=>{
|
|
89
101
|
return subscriptionOptions.trpcSubscriptionOptions({
|
|
90
102
|
opts: arg2,
|
|
91
103
|
path,
|
|
92
|
-
queryKey:
|
|
104
|
+
queryKey: utils.getQueryKeyInternal(path, arg1, 'any'),
|
|
93
105
|
subscribe: callIt('subscription')
|
|
94
106
|
});
|
|
95
107
|
}
|