@trpc/react-query 11.0.0-alpha-tmp-subscription-connection-state.488 → 11.0.0-alpha-tmp-12-06-react.665
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 +59 -76
- package/dist/createTRPCReact.d.ts +47 -17
- package/dist/createTRPCReact.d.ts.map +1 -1
- package/dist/internals/context.d.ts +43 -21
- package/dist/internals/context.d.ts.map +1 -1
- package/dist/internals/getQueryKey.d.ts +2 -2
- package/dist/internals/getQueryKey.js +3 -3
- package/dist/internals/getQueryKey.mjs +3 -3
- package/dist/internals/trpcResult.d.ts +18 -0
- package/dist/internals/trpcResult.d.ts.map +1 -0
- package/dist/internals/trpcResult.js +63 -0
- package/dist/internals/trpcResult.mjs +40 -0
- package/dist/internals/useQueries.d.ts +1 -1
- package/dist/internals/useQueries.d.ts.map +1 -1
- package/dist/rsc.d.ts +1 -1
- package/dist/rsc.d.ts.map +1 -1
- package/dist/rsc.js +4 -4
- package/dist/rsc.mjs +4 -4
- package/dist/server/ssgProxy.d.ts +7 -24
- package/dist/server/ssgProxy.d.ts.map +1 -1
- package/dist/server/ssgProxy.js +21 -4
- package/dist/server/ssgProxy.mjs +21 -4
- package/dist/shared/hooks/createHooksInternal.d.ts +4 -2
- package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
- package/dist/shared/hooks/createHooksInternal.js +160 -93
- package/dist/shared/hooks/createHooksInternal.mjs +156 -89
- package/dist/shared/hooks/types.d.ts +38 -159
- package/dist/shared/hooks/types.d.ts.map +1 -1
- package/dist/shared/index.js +0 -7
- package/dist/shared/index.mjs +0 -1
- package/dist/shared/polymorphism/mutationLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/queryLike.d.ts.map +1 -1
- package/dist/shared/polymorphism/routerLike.d.ts.map +1 -1
- package/dist/shared/proxy/decorationProxy.js +1 -1
- package/dist/shared/proxy/decorationProxy.mjs +1 -1
- package/dist/shared/proxy/useQueriesProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.d.ts +45 -20
- package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
- package/dist/shared/proxy/utilsProxy.js +4 -0
- package/dist/shared/proxy/utilsProxy.mjs +4 -0
- package/dist/shared/types.d.ts +60 -2
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.d.ts +2 -2
- package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
- package/dist/utils/createUtilityFunctions.js +69 -3
- package/dist/utils/createUtilityFunctions.mjs +69 -3
- package/dist/utils/inferReactQueryProcedure.d.ts +2 -2
- package/dist/utils/inferReactQueryProcedure.d.ts.map +1 -1
- package/package.json +22 -19
- package/src/createTRPCReact.tsx +276 -65
- package/src/internals/context.tsx +105 -24
- package/src/internals/getQueryKey.ts +2 -2
- package/src/internals/trpcResult.ts +55 -0
- package/src/internals/useQueries.ts +36 -31
- package/src/rsc.tsx +6 -6
- package/src/server/ssgProxy.ts +23 -66
- package/src/shared/hooks/createHooksInternal.tsx +222 -151
- package/src/shared/hooks/types.ts +64 -348
- package/src/shared/polymorphism/mutationLike.ts +8 -6
- package/src/shared/polymorphism/queryLike.ts +12 -14
- package/src/shared/polymorphism/routerLike.ts +4 -4
- package/src/shared/proxy/useQueriesProxy.ts +4 -4
- package/src/shared/proxy/utilsProxy.ts +153 -25
- package/src/shared/types.ts +229 -1
- package/src/utils/createUtilityFunctions.ts +90 -2
- package/src/utils/inferReactQueryProcedure.ts +8 -6
- package/dist/internals/useHookResult.d.ts +0 -8
- package/dist/internals/useHookResult.d.ts.map +0 -1
- package/dist/internals/useHookResult.js +0 -35
- package/dist/internals/useHookResult.mjs +0 -14
- package/dist/shared/hooks/types.js +0 -133
- package/dist/shared/hooks/types.mjs +0 -126
- package/src/internals/useHookResult.ts +0 -17
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { skipToken, infiniteQueryOptions, queryOptions } from '@tanstack/react-query';
|
|
1
2
|
import { TRPCUntypedClient, getUntypedClient } from '@trpc/client';
|
|
3
|
+
import { isAsyncIterable } from '@trpc/server/unstable-core-do-not-import';
|
|
2
4
|
import { getClientArgs } from '../internals/getClientArgs.mjs';
|
|
5
|
+
import { createTRPCOptionsResult, buildQueryFromAsyncIterable } from '../internals/trpcResult.mjs';
|
|
3
6
|
|
|
4
7
|
/**
|
|
5
8
|
* Creates a set of utility functions that can be used to interact with `react-query`
|
|
@@ -7,9 +10,72 @@ import { getClientArgs } from '../internals/getClientArgs.mjs';
|
|
|
7
10
|
* @returns a set of utility functions that can be used to interact with `react-query`
|
|
8
11
|
* @internal
|
|
9
12
|
*/ function createUtilityFunctions(opts) {
|
|
10
|
-
const { client
|
|
13
|
+
const { client, queryClient } = opts;
|
|
11
14
|
const untypedClient = client instanceof TRPCUntypedClient ? client : getUntypedClient(client);
|
|
12
15
|
return {
|
|
16
|
+
infiniteQueryOptions: (path, queryKey, opts)=>{
|
|
17
|
+
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
|
18
|
+
const queryFn = async (queryFnContext)=>{
|
|
19
|
+
const actualOpts = {
|
|
20
|
+
...opts,
|
|
21
|
+
trpc: {
|
|
22
|
+
...opts?.trpc,
|
|
23
|
+
...opts?.trpc?.abortOnUnmount ? {
|
|
24
|
+
signal: queryFnContext.signal
|
|
25
|
+
} : {
|
|
26
|
+
signal: null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts, {
|
|
31
|
+
direction: queryFnContext.direction,
|
|
32
|
+
pageParam: queryFnContext.pageParam
|
|
33
|
+
}));
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
return Object.assign(infiniteQueryOptions({
|
|
37
|
+
...opts,
|
|
38
|
+
initialData: opts?.initialData,
|
|
39
|
+
queryKey,
|
|
40
|
+
queryFn: inputIsSkipToken ? skipToken : queryFn,
|
|
41
|
+
initialPageParam: opts?.initialCursor ?? null
|
|
42
|
+
}), {
|
|
43
|
+
trpc: createTRPCOptionsResult({
|
|
44
|
+
path
|
|
45
|
+
})
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
queryOptions: (path, queryKey, opts)=>{
|
|
49
|
+
const inputIsSkipToken = queryKey[1]?.input === skipToken;
|
|
50
|
+
const queryFn = async (queryFnContext)=>{
|
|
51
|
+
const actualOpts = {
|
|
52
|
+
...opts,
|
|
53
|
+
trpc: {
|
|
54
|
+
...opts?.trpc,
|
|
55
|
+
...opts?.trpc?.abortOnUnmount ? {
|
|
56
|
+
signal: queryFnContext.signal
|
|
57
|
+
} : {
|
|
58
|
+
signal: null
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
const result = await untypedClient.query(...getClientArgs(queryKey, actualOpts));
|
|
63
|
+
if (isAsyncIterable(result)) {
|
|
64
|
+
return buildQueryFromAsyncIterable(result, queryClient, queryKey);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
};
|
|
68
|
+
return Object.assign(queryOptions({
|
|
69
|
+
...opts,
|
|
70
|
+
initialData: opts?.initialData,
|
|
71
|
+
queryKey,
|
|
72
|
+
queryFn: inputIsSkipToken ? skipToken : queryFn
|
|
73
|
+
}), {
|
|
74
|
+
trpc: createTRPCOptionsResult({
|
|
75
|
+
path
|
|
76
|
+
})
|
|
77
|
+
});
|
|
78
|
+
},
|
|
13
79
|
fetchQuery: (queryKey, opts)=>{
|
|
14
80
|
return queryClient.fetchQuery({
|
|
15
81
|
...opts,
|
|
@@ -21,7 +87,7 @@ import { getClientArgs } from '../internals/getClientArgs.mjs';
|
|
|
21
87
|
return queryClient.fetchInfiniteQuery({
|
|
22
88
|
...opts,
|
|
23
89
|
queryKey,
|
|
24
|
-
queryFn: ({ pageParam
|
|
90
|
+
queryFn: ({ pageParam, direction })=>{
|
|
25
91
|
return untypedClient.query(...getClientArgs(queryKey, opts, {
|
|
26
92
|
pageParam,
|
|
27
93
|
direction
|
|
@@ -41,7 +107,7 @@ import { getClientArgs } from '../internals/getClientArgs.mjs';
|
|
|
41
107
|
return queryClient.prefetchInfiniteQuery({
|
|
42
108
|
...opts,
|
|
43
109
|
queryKey,
|
|
44
|
-
queryFn: ({ pageParam
|
|
110
|
+
queryFn: ({ pageParam, direction })=>{
|
|
45
111
|
return untypedClient.query(...getClientArgs(queryKey, opts, {
|
|
46
112
|
pageParam,
|
|
47
113
|
direction
|
|
@@ -4,11 +4,11 @@ import type { UseTRPCMutationOptions, UseTRPCMutationResult, UseTRPCQueryOptions
|
|
|
4
4
|
/**
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
export type InferQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TData = inferTransformedProcedureOutput<TRoot, TProcedure>> = Omit<UseTRPCQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>, TData>, 'select'>;
|
|
7
|
+
export type InferQueryOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TData = inferTransformedProcedureOutput<TRoot, TProcedure>> = Omit<UseTRPCQueryOptions<inferTransformedProcedureOutput<TRoot, TProcedure>, inferTransformedProcedureOutput<TRoot, TProcedure>, TRPCClientErrorLike<TRoot>, TData>, 'select' | 'queryFn'>;
|
|
8
8
|
/**
|
|
9
9
|
* @internal
|
|
10
10
|
*/
|
|
11
|
-
export type InferMutationOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure> = UseTRPCMutationOptions<inferProcedureInput<TProcedure>, TRPCClientErrorLike<TRoot>, inferTransformedProcedureOutput<TRoot, TProcedure
|
|
11
|
+
export type InferMutationOptions<TRoot extends AnyRootTypes, TProcedure extends AnyProcedure, TMeta = unknown> = UseTRPCMutationOptions<inferProcedureInput<TProcedure>, TRPCClientErrorLike<TRoot>, inferTransformedProcedureOutput<TRoot, TProcedure>, TMeta>;
|
|
12
12
|
/**
|
|
13
13
|
* @internal
|
|
14
14
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inferReactQueryProcedure.d.ts","sourceRoot":"","sources":["../../src/utils/inferReactQueryProcedure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,+BAA+B,EAC/B,YAAY,EACb,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,WAAW,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAC3B,KAAK,SAAS,YAAY,EAC1B,UAAU,SAAS,YAAY,EAC/B,KAAK,GAAG,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,IACxD,IAAI,CACN,mBAAmB,CACjB,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,EAClD,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,EAClD,mBAAmB,CAAC,KAAK,CAAC,EAC1B,KAAK,CACN,EACD,QAAQ,
|
|
1
|
+
{"version":3,"file":"inferReactQueryProcedure.d.ts","sourceRoot":"","sources":["../../src/utils/inferReactQueryProcedure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,KAAK,EACV,oBAAoB,EACpB,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,mBAAmB,EACnB,+BAA+B,EAC/B,YAAY,EACb,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,mBAAmB,EACnB,kBAAkB,EACnB,MAAM,WAAW,CAAC;AAEnB;;GAEG;AACH,MAAM,MAAM,iBAAiB,CAC3B,KAAK,SAAS,YAAY,EAC1B,UAAU,SAAS,YAAY,EAC/B,KAAK,GAAG,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,IACxD,IAAI,CACN,mBAAmB,CACjB,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,EAClD,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,EAClD,mBAAmB,CAAC,KAAK,CAAC,EAC1B,KAAK,CACN,EACD,QAAQ,GAAG,SAAS,CACrB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAC9B,KAAK,SAAS,YAAY,EAC1B,UAAU,SAAS,YAAY,EAC/B,KAAK,GAAG,OAAO,IACb,sBAAsB,CACxB,mBAAmB,CAAC,UAAU,CAAC,EAC/B,mBAAmB,CAAC,KAAK,CAAC,EAC1B,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,EAClD,KAAK,CACN,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAC1B,KAAK,SAAS,YAAY,EAC1B,UAAU,SAAS,YAAY,IAC7B,kBAAkB,CACpB,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,EAClD,mBAAmB,CAAC,KAAK,CAAC,CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,mBAAmB,CAC7B,KAAK,SAAS,YAAY,EAC1B,UAAU,SAAS,YAAY,EAC/B,QAAQ,GAAG,OAAO,IAChB,qBAAqB,CACvB,+BAA+B,CAAC,KAAK,EAAE,UAAU,CAAC,EAClD,mBAAmB,CAAC,KAAK,CAAC,EAC1B,mBAAmB,CAAC,UAAU,CAAC,EAC/B,QAAQ,CACT,CAAC;AAEF,KAAK,oCAAoC,CACvC,KAAK,SAAS,YAAY,EAC1B,OAAO,SAAS,YAAY,IAC1B;KACD,IAAI,IAAI,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,MAAM,MAAM,GACvD,MAAM,SAAS,YAAY,GACzB,oCAAoC,CAAC,KAAK,EAAE,MAAM,CAAC,GACnD,MAAM,SAAS,oBAAoB,GACjC,oBAAoB,CAAC,KAAK,EAAE,MAAM,CAAC,GACnC,MAAM,SAAS,iBAAiB,GAC9B,iBAAiB,CAAC,KAAK,EAAE,MAAM,CAAC,GAChC,KAAK,GACX,KAAK;CACV,CAAC;AAEF,MAAM,MAAM,+BAA+B,CAAC,OAAO,SAAS,SAAS,IACnE,oCAAoC,CAClC,OAAO,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,EACpC,OAAO,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAC1B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trpc/react-query",
|
|
3
|
-
"version": "11.0.0-alpha-tmp-
|
|
3
|
+
"version": "11.0.0-alpha-tmp-12-06-react.665+f3677f632",
|
|
4
4
|
"description": "The tRPC React library",
|
|
5
5
|
"author": "KATT",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build": "rollup --config rollup.config.ts --configPlugin rollup-plugin-swc3",
|
|
18
18
|
"dev": "pnpm build --watch",
|
|
19
19
|
"codegen-entrypoints": "tsx entrypoints.script.ts",
|
|
20
|
-
"lint": "eslint --cache
|
|
20
|
+
"lint": "eslint --cache src",
|
|
21
21
|
"ts-watch": "tsc --watch"
|
|
22
22
|
},
|
|
23
23
|
"exports": {
|
|
@@ -51,7 +51,8 @@
|
|
|
51
51
|
"rsc",
|
|
52
52
|
"server",
|
|
53
53
|
"shared",
|
|
54
|
-
"!**/*.test.*"
|
|
54
|
+
"!**/*.test.*",
|
|
55
|
+
"!**/__tests__"
|
|
55
56
|
],
|
|
56
57
|
"eslintConfig": {
|
|
57
58
|
"rules": {
|
|
@@ -63,27 +64,29 @@
|
|
|
63
64
|
}
|
|
64
65
|
},
|
|
65
66
|
"peerDependencies": {
|
|
66
|
-
"@tanstack/react-query": "^5.
|
|
67
|
-
"@trpc/client": "11.0.0-alpha-tmp-
|
|
68
|
-
"@trpc/server": "11.0.0-alpha-tmp-
|
|
67
|
+
"@tanstack/react-query": "^5.59.15",
|
|
68
|
+
"@trpc/client": "11.0.0-alpha-tmp-12-06-react.665+f3677f632",
|
|
69
|
+
"@trpc/server": "11.0.0-alpha-tmp-12-06-react.665+f3677f632",
|
|
69
70
|
"react": ">=18.2.0",
|
|
70
|
-
"react-dom": ">=18.2.0"
|
|
71
|
+
"react-dom": ">=18.2.0",
|
|
72
|
+
"typescript": ">=5.6.2"
|
|
71
73
|
},
|
|
72
74
|
"devDependencies": {
|
|
73
|
-
"@tanstack/react-query": "^5.
|
|
74
|
-
"@trpc/client": "11.0.0-alpha-tmp-
|
|
75
|
-
"@trpc/server": "11.0.0-alpha-tmp-
|
|
75
|
+
"@tanstack/react-query": "^5.59.15",
|
|
76
|
+
"@trpc/client": "11.0.0-alpha-tmp-12-06-react.665+f3677f632",
|
|
77
|
+
"@trpc/server": "11.0.0-alpha-tmp-12-06-react.665+f3677f632",
|
|
76
78
|
"@types/express": "^4.17.17",
|
|
77
|
-
"@types/node": "^
|
|
78
|
-
"@types/react": "^
|
|
79
|
-
"eslint": "^
|
|
79
|
+
"@types/node": "^22.9.0",
|
|
80
|
+
"@types/react": "^19.0.0",
|
|
81
|
+
"eslint": "^9.13.0",
|
|
80
82
|
"express": "^4.17.1",
|
|
81
|
-
"next": "^
|
|
82
|
-
"react": "^
|
|
83
|
-
"react-dom": "^
|
|
84
|
-
"rollup": "^4.
|
|
85
|
-
"tslib": "^2.
|
|
83
|
+
"next": "^15.0.4",
|
|
84
|
+
"react": "^19.0.0",
|
|
85
|
+
"react-dom": "^19.0.0",
|
|
86
|
+
"rollup": "^4.24.4",
|
|
87
|
+
"tslib": "^2.8.1",
|
|
86
88
|
"tsx": "^4.0.0",
|
|
89
|
+
"typescript": "^5.7.0",
|
|
87
90
|
"zod": "^3.0.0"
|
|
88
91
|
},
|
|
89
92
|
"publishConfig": {
|
|
@@ -92,5 +95,5 @@
|
|
|
92
95
|
"funding": [
|
|
93
96
|
"https://trpc.io/sponsor"
|
|
94
97
|
],
|
|
95
|
-
"gitHead": "
|
|
98
|
+
"gitHead": "f3677f6326d62400c29d1c358db9f3a68a0dd27d"
|
|
96
99
|
}
|
package/src/createTRPCReact.tsx
CHANGED
|
@@ -1,14 +1,27 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
DefinedInitialDataInfiniteOptions,
|
|
3
|
+
DefinedUseInfiniteQueryResult,
|
|
4
|
+
InfiniteData,
|
|
5
|
+
SkipToken,
|
|
6
|
+
UndefinedInitialDataInfiniteOptions,
|
|
7
|
+
UseInfiniteQueryOptions,
|
|
8
|
+
UseInfiniteQueryResult,
|
|
9
|
+
UseSuspenseInfiniteQueryOptions,
|
|
10
|
+
UseSuspenseInfiniteQueryResult,
|
|
11
|
+
UseSuspenseQueryResult,
|
|
12
|
+
} from '@tanstack/react-query';
|
|
2
13
|
import type { TRPCClientErrorLike } from '@trpc/client';
|
|
3
14
|
import type {
|
|
4
15
|
AnyProcedure,
|
|
5
16
|
AnyRootTypes,
|
|
6
17
|
AnyRouter,
|
|
18
|
+
inferAsyncIterableYield,
|
|
7
19
|
inferProcedureInput,
|
|
8
20
|
inferTransformedProcedureOutput,
|
|
9
21
|
ProcedureType,
|
|
10
22
|
ProtectedIntersection,
|
|
11
23
|
RouterRecord,
|
|
24
|
+
Simplify,
|
|
12
25
|
} from '@trpc/server/unstable-core-do-not-import';
|
|
13
26
|
import { createFlatProxy } from '@trpc/server/unstable-core-do-not-import';
|
|
14
27
|
import * as React from 'react';
|
|
@@ -16,7 +29,11 @@ import type {
|
|
|
16
29
|
TRPCUseQueries,
|
|
17
30
|
TRPCUseSuspenseQueries,
|
|
18
31
|
} from './internals/useQueries';
|
|
19
|
-
import type {
|
|
32
|
+
import type {
|
|
33
|
+
CreateReactUtils,
|
|
34
|
+
TRPCFetchInfiniteQueryOptions,
|
|
35
|
+
TRPCFetchQueryOptions,
|
|
36
|
+
} from './shared';
|
|
20
37
|
import { createReactDecoration, createReactQueryUtils } from './shared';
|
|
21
38
|
import type { CreateReactQueryHooks } from './shared/hooks/createHooksInternal';
|
|
22
39
|
import { createRootHooks } from './shared/hooks/createHooksInternal';
|
|
@@ -24,19 +41,16 @@ import type {
|
|
|
24
41
|
CreateClient,
|
|
25
42
|
DefinedUseTRPCQueryOptions,
|
|
26
43
|
DefinedUseTRPCQueryResult,
|
|
44
|
+
TRPCHookResult,
|
|
27
45
|
TRPCProvider,
|
|
28
|
-
|
|
29
|
-
|
|
46
|
+
TRPCSubscriptionResult,
|
|
47
|
+
TRPCUseQueryBaseOptions,
|
|
30
48
|
UseTRPCMutationOptions,
|
|
31
49
|
UseTRPCMutationResult,
|
|
32
50
|
UseTRPCQueryOptions,
|
|
33
51
|
UseTRPCQueryResult,
|
|
34
52
|
UseTRPCSubscriptionOptions,
|
|
35
|
-
UseTRPCSubscriptionResult,
|
|
36
|
-
UseTRPCSuspenseInfiniteQueryOptions,
|
|
37
|
-
UseTRPCSuspenseInfiniteQueryResult,
|
|
38
53
|
UseTRPCSuspenseQueryOptions,
|
|
39
|
-
UseTRPCSuspenseQueryResult,
|
|
40
54
|
} from './shared/hooks/types';
|
|
41
55
|
import type { CreateTRPCReactOptions } from './shared/types';
|
|
42
56
|
|
|
@@ -80,6 +94,14 @@ export interface ProcedureUseQuery<TDef extends ResolverDef> {
|
|
|
80
94
|
): UseTRPCQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
|
81
95
|
}
|
|
82
96
|
|
|
97
|
+
/**
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
export type ProcedureUsePrefetchQuery<TDef extends ResolverDef> = (
|
|
101
|
+
input: TDef['input'] | SkipToken,
|
|
102
|
+
opts?: TRPCFetchQueryOptions<TDef['output'], TRPCClientErrorLike<TDef>>,
|
|
103
|
+
) => void;
|
|
104
|
+
|
|
83
105
|
/**
|
|
84
106
|
* @remark `void` is here due to https://github.com/trpc/trpc/pull/4374
|
|
85
107
|
*/
|
|
@@ -88,6 +110,191 @@ type CursorInput = {
|
|
|
88
110
|
} | void;
|
|
89
111
|
|
|
90
112
|
type ReservedInfiniteQueryKeys = 'cursor' | 'direction';
|
|
113
|
+
type InfiniteInput<TInput> =
|
|
114
|
+
| Omit<TInput, ReservedInfiniteQueryKeys>
|
|
115
|
+
| SkipToken;
|
|
116
|
+
|
|
117
|
+
type inferCursorType<TInput> = TInput extends { cursor?: any }
|
|
118
|
+
? TInput['cursor']
|
|
119
|
+
: unknown;
|
|
120
|
+
|
|
121
|
+
type makeInfiniteQueryOptions<TCursor, TOptions> = Omit<
|
|
122
|
+
TOptions,
|
|
123
|
+
'queryKey' | 'initialPageParam' | 'queryFn' | 'queryHash' | 'queryHashFn'
|
|
124
|
+
> &
|
|
125
|
+
TRPCUseQueryBaseOptions & {
|
|
126
|
+
initialCursor?: TCursor;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
type trpcInfiniteData<TDef extends ResolverDef> = Simplify<
|
|
130
|
+
InfiniteData<TDef['output'], inferCursorType<TDef['input']>>
|
|
131
|
+
>;
|
|
132
|
+
// references from react-query
|
|
133
|
+
// 1st
|
|
134
|
+
// declare function useInfiniteQuery<
|
|
135
|
+
// TQueryFnData,
|
|
136
|
+
// TError = DefaultError,
|
|
137
|
+
// TData = InfiniteData<TQueryFnData>,
|
|
138
|
+
// TQueryKey extends QueryKey = QueryKey,
|
|
139
|
+
// TPageParam = unknown,
|
|
140
|
+
// >(
|
|
141
|
+
// options: DefinedInitialDataInfiniteOptions<
|
|
142
|
+
// TQueryFnData,
|
|
143
|
+
// TError,
|
|
144
|
+
// TData,
|
|
145
|
+
// TQueryKey,
|
|
146
|
+
// TPageParam
|
|
147
|
+
// >,
|
|
148
|
+
// queryClient?: QueryClient,
|
|
149
|
+
// ): DefinedUseInfiniteQueryResult<TData, TError>;
|
|
150
|
+
// 2nd
|
|
151
|
+
// declare function useInfiniteQuery<
|
|
152
|
+
// TQueryFnData,
|
|
153
|
+
// TError = DefaultError,
|
|
154
|
+
// TData = InfiniteData<TQueryFnData>,
|
|
155
|
+
// TQueryKey extends QueryKey = QueryKey,
|
|
156
|
+
// TPageParam = unknown,
|
|
157
|
+
// >(
|
|
158
|
+
// options: UndefinedInitialDataInfiniteOptions<
|
|
159
|
+
// TQueryFnData,
|
|
160
|
+
// TError,
|
|
161
|
+
// TData,
|
|
162
|
+
// TQueryKey,
|
|
163
|
+
// TPageParam
|
|
164
|
+
// >,
|
|
165
|
+
// queryClient?: QueryClient,
|
|
166
|
+
// ): UseInfiniteQueryResult<TData, TError>;
|
|
167
|
+
// 3rd
|
|
168
|
+
// declare function useInfiniteQuery<
|
|
169
|
+
// TQueryFnData,
|
|
170
|
+
// TError = DefaultError,
|
|
171
|
+
// TData = InfiniteData<TQueryFnData>,
|
|
172
|
+
// TQueryKey extends QueryKey = QueryKey,
|
|
173
|
+
// TPageParam = unknown,
|
|
174
|
+
// >(
|
|
175
|
+
// options: UseInfiniteQueryOptions<
|
|
176
|
+
// TQueryFnData,
|
|
177
|
+
// TError,
|
|
178
|
+
// TData,
|
|
179
|
+
// TQueryFnData,
|
|
180
|
+
// TQueryKey,
|
|
181
|
+
// TPageParam
|
|
182
|
+
// >,
|
|
183
|
+
// queryClient?: QueryClient,
|
|
184
|
+
// ): UseInfiniteQueryResult<TData, TError>;
|
|
185
|
+
|
|
186
|
+
export interface useTRPCInfiniteQuery<TDef extends ResolverDef> {
|
|
187
|
+
// 1st
|
|
188
|
+
<TData = trpcInfiniteData<TDef>>(
|
|
189
|
+
input: InfiniteInput<TDef['input']>,
|
|
190
|
+
opts: makeInfiniteQueryOptions<
|
|
191
|
+
inferCursorType<TDef['input']>,
|
|
192
|
+
DefinedInitialDataInfiniteOptions<
|
|
193
|
+
// TQueryFnData,
|
|
194
|
+
TDef['output'],
|
|
195
|
+
// TError,
|
|
196
|
+
TRPCClientErrorLike<TDef>,
|
|
197
|
+
// TData,
|
|
198
|
+
TData,
|
|
199
|
+
// TQueryKey,
|
|
200
|
+
any,
|
|
201
|
+
// TPageParam
|
|
202
|
+
inferCursorType<TDef['input']>
|
|
203
|
+
>
|
|
204
|
+
>,
|
|
205
|
+
): TRPCHookResult &
|
|
206
|
+
DefinedUseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
|
207
|
+
|
|
208
|
+
// 2nd
|
|
209
|
+
<TData = trpcInfiniteData<TDef>>(
|
|
210
|
+
input: InfiniteInput<TDef['input']>,
|
|
211
|
+
opts?: makeInfiniteQueryOptions<
|
|
212
|
+
inferCursorType<TDef['input']>,
|
|
213
|
+
UndefinedInitialDataInfiniteOptions<
|
|
214
|
+
// TQueryFnData,
|
|
215
|
+
TDef['output'],
|
|
216
|
+
// TError,
|
|
217
|
+
TRPCClientErrorLike<TDef>,
|
|
218
|
+
// TData,
|
|
219
|
+
TData,
|
|
220
|
+
// TQueryKey,
|
|
221
|
+
any,
|
|
222
|
+
// TPageParam
|
|
223
|
+
inferCursorType<TDef['input']>
|
|
224
|
+
>
|
|
225
|
+
>,
|
|
226
|
+
): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
|
227
|
+
|
|
228
|
+
// 3rd:
|
|
229
|
+
<TData = trpcInfiniteData<TDef>>(
|
|
230
|
+
input: InfiniteInput<TDef['input']>,
|
|
231
|
+
opts?: makeInfiniteQueryOptions<
|
|
232
|
+
inferCursorType<TDef['input']>,
|
|
233
|
+
UseInfiniteQueryOptions<
|
|
234
|
+
// TQueryFnData,
|
|
235
|
+
TDef['output'],
|
|
236
|
+
// TError,
|
|
237
|
+
TRPCClientErrorLike<TDef>,
|
|
238
|
+
// TData,
|
|
239
|
+
TData,
|
|
240
|
+
// TQueryFnData,
|
|
241
|
+
TDef['output'],
|
|
242
|
+
// TQueryKey,
|
|
243
|
+
any,
|
|
244
|
+
// TPageParam
|
|
245
|
+
inferCursorType<TDef['input']>
|
|
246
|
+
>
|
|
247
|
+
>,
|
|
248
|
+
): TRPCHookResult & UseInfiniteQueryResult<TData, TRPCClientErrorLike<TDef>>;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// references from react-query
|
|
252
|
+
// declare function useSuspenseInfiniteQuery<
|
|
253
|
+
// TQueryFnData,
|
|
254
|
+
// TError = DefaultError,
|
|
255
|
+
// TData = InfiniteData<TQueryFnData>,
|
|
256
|
+
// TQueryKey extends QueryKey = QueryKey,
|
|
257
|
+
// TPageParam = unknown,
|
|
258
|
+
// >(
|
|
259
|
+
// options: UseSuspenseInfiniteQueryOptions<
|
|
260
|
+
// TQueryFnData,
|
|
261
|
+
// TError,
|
|
262
|
+
// TData,
|
|
263
|
+
// TQueryFnData,
|
|
264
|
+
// TQueryKey,
|
|
265
|
+
// TPageParam
|
|
266
|
+
// >,
|
|
267
|
+
// queryClient?: QueryClient,
|
|
268
|
+
// ): UseSuspenseInfiniteQueryResult<TData, TError>;
|
|
269
|
+
|
|
270
|
+
export type useTRPCSuspenseInfiniteQuery<TDef extends ResolverDef> = (
|
|
271
|
+
input: InfiniteInput<TDef['input']>,
|
|
272
|
+
opts: makeInfiniteQueryOptions<
|
|
273
|
+
inferCursorType<TDef['input']>,
|
|
274
|
+
UseSuspenseInfiniteQueryOptions<
|
|
275
|
+
// TQueryFnData,
|
|
276
|
+
TDef['output'],
|
|
277
|
+
// TError,
|
|
278
|
+
TRPCClientErrorLike<TDef>,
|
|
279
|
+
// TData,
|
|
280
|
+
trpcInfiniteData<TDef>,
|
|
281
|
+
// TQueryFnData,
|
|
282
|
+
TDef['output'],
|
|
283
|
+
// TQueryKey,
|
|
284
|
+
any,
|
|
285
|
+
// TPageParam
|
|
286
|
+
inferCursorType<TDef['input']>
|
|
287
|
+
>
|
|
288
|
+
>,
|
|
289
|
+
) => [
|
|
290
|
+
trpcInfiniteData<TDef>,
|
|
291
|
+
TRPCHookResult &
|
|
292
|
+
UseSuspenseInfiniteQueryResult<
|
|
293
|
+
trpcInfiniteData<TDef>,
|
|
294
|
+
TRPCClientErrorLike<TDef>
|
|
295
|
+
>,
|
|
296
|
+
];
|
|
297
|
+
|
|
91
298
|
/**
|
|
92
299
|
* @internal
|
|
93
300
|
*/
|
|
@@ -95,35 +302,22 @@ export type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =
|
|
|
95
302
|
TDef['input'] extends CursorInput
|
|
96
303
|
? {
|
|
97
304
|
/**
|
|
98
|
-
* @
|
|
305
|
+
* @see https://trpc.io/docs/v11/client/react/useInfiniteQuery
|
|
99
306
|
*/
|
|
100
|
-
useInfiniteQuery:
|
|
101
|
-
input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken,
|
|
102
|
-
opts: UseTRPCInfiniteQueryOptions<
|
|
103
|
-
TDef['input'],
|
|
104
|
-
TDef['output'],
|
|
105
|
-
TRPCClientErrorLike<TDef>
|
|
106
|
-
>,
|
|
107
|
-
) => UseTRPCInfiniteQueryResult<
|
|
108
|
-
TDef['output'],
|
|
109
|
-
TRPCClientErrorLike<TDef>,
|
|
110
|
-
TDef['input']
|
|
111
|
-
>;
|
|
307
|
+
useInfiniteQuery: useTRPCInfiniteQuery<TDef>;
|
|
112
308
|
/**
|
|
113
|
-
* @
|
|
309
|
+
* @see https://trpc.io/docs/client/react/suspense#usesuspenseinfinitequery
|
|
114
310
|
*/
|
|
115
|
-
useSuspenseInfiniteQuery:
|
|
116
|
-
|
|
117
|
-
|
|
311
|
+
useSuspenseInfiniteQuery: useTRPCSuspenseInfiniteQuery<TDef>;
|
|
312
|
+
|
|
313
|
+
usePrefetchInfiniteQuery: (
|
|
314
|
+
input: Omit<TDef['input'], ReservedInfiniteQueryKeys> | SkipToken,
|
|
315
|
+
opts: TRPCFetchInfiniteQueryOptions<
|
|
118
316
|
TDef['input'],
|
|
119
317
|
TDef['output'],
|
|
120
318
|
TRPCClientErrorLike<TDef>
|
|
121
319
|
>,
|
|
122
|
-
) =>
|
|
123
|
-
TDef['output'],
|
|
124
|
-
TRPCClientErrorLike<TDef>,
|
|
125
|
-
TDef['input']
|
|
126
|
-
>;
|
|
320
|
+
) => void;
|
|
127
321
|
}
|
|
128
322
|
: object;
|
|
129
323
|
|
|
@@ -132,11 +326,12 @@ export type MaybeDecoratedInfiniteQuery<TDef extends ResolverDef> =
|
|
|
132
326
|
*/
|
|
133
327
|
export type DecoratedQueryMethods<TDef extends ResolverDef> = {
|
|
134
328
|
/**
|
|
135
|
-
* @
|
|
329
|
+
* @see https://trpc.io/docs/v11/client/react/useQuery
|
|
136
330
|
*/
|
|
137
331
|
useQuery: ProcedureUseQuery<TDef>;
|
|
332
|
+
usePrefetchQuery: ProcedureUsePrefetchQuery<TDef>;
|
|
138
333
|
/**
|
|
139
|
-
* @
|
|
334
|
+
* @see https://trpc.io/docs/v11/client/react/suspense#usesuspensequery
|
|
140
335
|
*/
|
|
141
336
|
useSuspenseQuery: <
|
|
142
337
|
TQueryFnData extends TDef['output'] = TDef['output'],
|
|
@@ -148,7 +343,10 @@ export type DecoratedQueryMethods<TDef extends ResolverDef> = {
|
|
|
148
343
|
TData,
|
|
149
344
|
TRPCClientErrorLike<TDef>
|
|
150
345
|
>,
|
|
151
|
-
) =>
|
|
346
|
+
) => [
|
|
347
|
+
TData,
|
|
348
|
+
UseSuspenseQueryResult<TData, TRPCClientErrorLike<TDef>> & TRPCHookResult,
|
|
349
|
+
];
|
|
152
350
|
};
|
|
153
351
|
|
|
154
352
|
/**
|
|
@@ -159,7 +357,7 @@ export type DecoratedQuery<TDef extends ResolverDef> =
|
|
|
159
357
|
|
|
160
358
|
export type DecoratedMutation<TDef extends ResolverDef> = {
|
|
161
359
|
/**
|
|
162
|
-
* @
|
|
360
|
+
* @see https://trpc.io/docs/v11/client/react/useMutation
|
|
163
361
|
*/
|
|
164
362
|
useMutation: <TContext = unknown>(
|
|
165
363
|
opts?: UseTRPCMutationOptions<
|
|
@@ -180,23 +378,36 @@ interface ProcedureUseSubscription<TDef extends ResolverDef> {
|
|
|
180
378
|
// Without skip token
|
|
181
379
|
(
|
|
182
380
|
input: TDef['input'],
|
|
183
|
-
opts
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
381
|
+
opts?: UseTRPCSubscriptionOptions<
|
|
382
|
+
inferAsyncIterableYield<TDef['output']>,
|
|
383
|
+
TRPCClientErrorLike<TDef>
|
|
384
|
+
>,
|
|
385
|
+
): Exclude<
|
|
386
|
+
TRPCSubscriptionResult<
|
|
387
|
+
inferAsyncIterableYield<TDef['output']>,
|
|
388
|
+
TRPCClientErrorLike<TDef>
|
|
389
|
+
>,
|
|
390
|
+
// The idle state is
|
|
391
|
+
| {
|
|
392
|
+
status: 'idle';
|
|
393
|
+
}
|
|
394
|
+
| {
|
|
395
|
+
connectionState: 'idle';
|
|
396
|
+
}
|
|
188
397
|
>;
|
|
189
398
|
|
|
190
399
|
// With skip token
|
|
191
400
|
(
|
|
192
401
|
input: TDef['input'] | SkipToken,
|
|
193
|
-
opts
|
|
194
|
-
UseTRPCSubscriptionOptions<
|
|
402
|
+
opts?: Omit<
|
|
403
|
+
UseTRPCSubscriptionOptions<
|
|
404
|
+
inferAsyncIterableYield<TDef['output']>,
|
|
405
|
+
TRPCClientErrorLike<TDef>
|
|
406
|
+
>,
|
|
195
407
|
'enabled'
|
|
196
408
|
>,
|
|
197
|
-
):
|
|
198
|
-
TDef['
|
|
199
|
-
TDef['output'],
|
|
409
|
+
): TRPCSubscriptionResult<
|
|
410
|
+
inferAsyncIterableYield<TDef['output']>,
|
|
200
411
|
TRPCClientErrorLike<TDef>
|
|
201
412
|
>;
|
|
202
413
|
}
|
|
@@ -209,15 +420,15 @@ export type DecorateProcedure<
|
|
|
209
420
|
> = TType extends 'query'
|
|
210
421
|
? DecoratedQuery<TDef>
|
|
211
422
|
: TType extends 'mutation'
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
423
|
+
? DecoratedMutation<TDef>
|
|
424
|
+
: TType extends 'subscription'
|
|
425
|
+
? {
|
|
426
|
+
/**
|
|
427
|
+
* @see https://trpc.io/docs/v11/subscriptions
|
|
428
|
+
*/
|
|
429
|
+
useSubscription: ProcedureUseSubscription<TDef>;
|
|
430
|
+
}
|
|
431
|
+
: never;
|
|
221
432
|
|
|
222
433
|
/**
|
|
223
434
|
* @internal
|
|
@@ -230,16 +441,16 @@ export type DecorateRouterRecord<
|
|
|
230
441
|
? $Value extends RouterRecord
|
|
231
442
|
? DecorateRouterRecord<TRoot, $Value>
|
|
232
443
|
: $Value extends AnyProcedure
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
444
|
+
? DecorateProcedure<
|
|
445
|
+
$Value['_def']['type'],
|
|
446
|
+
{
|
|
447
|
+
input: inferProcedureInput<$Value>;
|
|
448
|
+
output: inferTransformedProcedureOutput<TRoot, $Value>;
|
|
449
|
+
transformer: TRoot['transformer'];
|
|
450
|
+
errorShape: TRoot['errorShape'];
|
|
451
|
+
}
|
|
452
|
+
>
|
|
453
|
+
: never
|
|
243
454
|
: never;
|
|
244
455
|
};
|
|
245
456
|
|
|
@@ -250,11 +461,11 @@ export type CreateTRPCReactBase<TRouter extends AnyRouter, TSSRContext> = {
|
|
|
250
461
|
/**
|
|
251
462
|
* @deprecated renamed to `useUtils` and will be removed in a future tRPC version
|
|
252
463
|
*
|
|
253
|
-
* @
|
|
464
|
+
* @see https://trpc.io/docs/v11/client/react/useUtils
|
|
254
465
|
*/
|
|
255
466
|
useContext(): CreateReactUtils<TRouter, TSSRContext>;
|
|
256
467
|
/**
|
|
257
|
-
* @
|
|
468
|
+
* @see https://trpc.io/docs/v11/client/react/useUtils
|
|
258
469
|
*/
|
|
259
470
|
useUtils(): CreateReactUtils<TRouter, TSSRContext>;
|
|
260
471
|
Provider: TRPCProvider<TRouter, TSSRContext>;
|