@trpc/react-query 11.0.0-alpha-tmp-issues-5851-take-two.499 → 11.0.0-alpha-tmp-subscription-connection-state.485

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.
Files changed (39) hide show
  1. package/dist/bundle-analysis.json +76 -54
  2. package/dist/createTRPCReact.d.ts +3 -3
  3. package/dist/createTRPCReact.d.ts.map +1 -1
  4. package/dist/index.d.ts +1 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +1 -0
  7. package/dist/index.mjs +1 -1
  8. package/dist/internals/context.d.ts +18 -2
  9. package/dist/internals/context.d.ts.map +1 -1
  10. package/dist/internals/getQueryKey.d.ts +8 -0
  11. package/dist/internals/getQueryKey.d.ts.map +1 -1
  12. package/dist/internals/getQueryKey.js +15 -0
  13. package/dist/internals/getQueryKey.mjs +14 -1
  14. package/dist/shared/hooks/createHooksInternal.d.ts +2 -2
  15. package/dist/shared/hooks/createHooksInternal.d.ts.map +1 -1
  16. package/dist/shared/hooks/createHooksInternal.js +67 -3
  17. package/dist/shared/hooks/createHooksInternal.mjs +68 -4
  18. package/dist/shared/hooks/types.d.ts +171 -2
  19. package/dist/shared/hooks/types.d.ts.map +1 -1
  20. package/dist/shared/hooks/types.js +133 -0
  21. package/dist/shared/hooks/types.mjs +126 -0
  22. package/dist/shared/index.js +7 -0
  23. package/dist/shared/index.mjs +1 -0
  24. package/dist/shared/proxy/utilsProxy.d.ts +12 -4
  25. package/dist/shared/proxy/utilsProxy.d.ts.map +1 -1
  26. package/dist/shared/proxy/utilsProxy.js +14 -2
  27. package/dist/shared/proxy/utilsProxy.mjs +15 -3
  28. package/dist/utils/createUtilityFunctions.d.ts.map +1 -1
  29. package/dist/utils/createUtilityFunctions.js +23 -0
  30. package/dist/utils/createUtilityFunctions.mjs +23 -0
  31. package/package.json +6 -6
  32. package/src/createTRPCReact.tsx +11 -2
  33. package/src/index.ts +1 -1
  34. package/src/internals/context.tsx +26 -1
  35. package/src/internals/getQueryKey.ts +21 -0
  36. package/src/shared/hooks/createHooksInternal.tsx +146 -18
  37. package/src/shared/hooks/types.ts +365 -1
  38. package/src/shared/proxy/utilsProxy.ts +47 -6
  39. package/src/utils/createUtilityFunctions.ts +26 -0
@@ -0,0 +1,126 @@
1
+ const defaultIdleResult = {
2
+ data: null,
3
+ connectionStartedAt: 0,
4
+ initialConnectionStartedAt: 0,
5
+ error: null,
6
+ errorUpdatedAt: 0,
7
+ connectionError: null,
8
+ connectionAttemptCount: 0,
9
+ isStarting: false,
10
+ isStarted: false,
11
+ isConnecting: false,
12
+ isPending: false,
13
+ isReconnecting: false,
14
+ isError: false,
15
+ connectionErrorUpdatedAt: 0,
16
+ status: 'idle'
17
+ };
18
+ const getIdleResult = ()=>{
19
+ return {
20
+ ...defaultIdleResult,
21
+ data: null
22
+ };
23
+ };
24
+ const getStartingResult = (// restart: restartSubscriptionFn<TInput>,
25
+ previous, error)=>{
26
+ const now = Date.now();
27
+ if (previous) {
28
+ return {
29
+ ...defaultIdleResult,
30
+ ...previous,
31
+ data: null,
32
+ connectionError: error ?? null,
33
+ isStarting: true,
34
+ isConnecting: true,
35
+ errorUpdatedAt: 0,
36
+ connectionAttemptCount: previous.connectionAttemptCount + 1,
37
+ connectionErrorUpdatedAt: error ? now : 0,
38
+ connectionStartedAt: 0,
39
+ initialConnectionStartedAt: 0,
40
+ error: null,
41
+ isStarted: false,
42
+ isError: false,
43
+ status: 'connecting'
44
+ };
45
+ }
46
+ return {
47
+ ...getIdleResult(),
48
+ connectionError: error ?? null,
49
+ isStarting: true,
50
+ isConnecting: true,
51
+ errorUpdatedAt: 0,
52
+ connectionAttemptCount: 0,
53
+ connectionErrorUpdatedAt: error ? now : 0,
54
+ status: 'connecting'
55
+ };
56
+ };
57
+ const getPendingResult = (previous, data)=>{
58
+ const time = Date.now();
59
+ if (previous.isStarting) {
60
+ return {
61
+ ...previous,
62
+ error: null,
63
+ isStarting: false,
64
+ isStarted: true,
65
+ isConnecting: false,
66
+ isReconnecting: false,
67
+ isPending: true,
68
+ status: 'pending',
69
+ connectionStartedAt: time,
70
+ connectionAttemptCount: 0,
71
+ connectionError: null,
72
+ initialConnectionStartedAt: time
73
+ };
74
+ }
75
+ return {
76
+ ...previous,
77
+ data: data ?? previous.data,
78
+ error: null,
79
+ isError: false,
80
+ isStarting: false,
81
+ isStarted: true,
82
+ isConnecting: false,
83
+ isReconnecting: false,
84
+ isPending: true,
85
+ status: 'pending',
86
+ connectionStartedAt: time,
87
+ connectionAttemptCount: 0,
88
+ connectionError: null
89
+ };
90
+ };
91
+ const getReconnectingResult = (previous, error)=>{
92
+ return {
93
+ ...previous,
94
+ isStarting: false,
95
+ isStarted: true,
96
+ isConnecting: true,
97
+ isReconnecting: true,
98
+ isPending: false,
99
+ status: 'connecting',
100
+ connectionError: error,
101
+ connectionAttemptCount: previous.connectionAttemptCount + 1
102
+ };
103
+ };
104
+ const getConnectingResult = (previous, error)=>{
105
+ if (previous.isReconnecting || previous.isPending) {
106
+ if (!error) throw new Error('Reconnecting without error?');
107
+ return getReconnectingResult(previous, error);
108
+ }
109
+ return getStartingResult(/*previous.restart, */ previous, error);
110
+ };
111
+ const getErrorResult = (previous, error)=>{
112
+ return {
113
+ ...previous,
114
+ isStarting: false,
115
+ isStarted: true,
116
+ isConnecting: false,
117
+ isReconnecting: false,
118
+ isPending: false,
119
+ isError: true,
120
+ status: 'error',
121
+ error,
122
+ errorUpdatedAt: Date.now()
123
+ };
124
+ };
125
+
126
+ export { getConnectingResult, getErrorResult, getIdleResult, getPendingResult, getReconnectingResult, getStartingResult };
@@ -5,6 +5,7 @@ var utilsProxy = require('./proxy/utilsProxy.js');
5
5
  var useQueriesProxy = require('./proxy/useQueriesProxy.js');
6
6
  var createHooksInternal = require('./hooks/createHooksInternal.js');
7
7
  var queryClient = require('./queryClient.js');
8
+ var types = require('./hooks/types.js');
8
9
  var getClientArgs = require('../internals/getClientArgs.js');
9
10
  var context = require('../internals/context.js');
10
11
 
@@ -17,6 +18,12 @@ exports.getQueryType = utilsProxy.getQueryType;
17
18
  exports.createUseQueries = useQueriesProxy.createUseQueries;
18
19
  exports.createRootHooks = createHooksInternal.createRootHooks;
19
20
  exports.getQueryClient = queryClient.getQueryClient;
21
+ exports.getConnectingResult = types.getConnectingResult;
22
+ exports.getErrorResult = types.getErrorResult;
23
+ exports.getIdleResult = types.getIdleResult;
24
+ exports.getPendingResult = types.getPendingResult;
25
+ exports.getReconnectingResult = types.getReconnectingResult;
26
+ exports.getStartingResult = types.getStartingResult;
20
27
  exports.getClientArgs = getClientArgs.getClientArgs;
21
28
  exports.TRPCContext = context.TRPCContext;
22
29
  exports.contextProps = context.contextProps;
@@ -3,5 +3,6 @@ export { createQueryUtilsProxy, createReactQueryUtils, getQueryType } from './pr
3
3
  export { createUseQueries } from './proxy/useQueriesProxy.mjs';
4
4
  export { createRootHooks } from './hooks/createHooksInternal.mjs';
5
5
  export { getQueryClient } from './queryClient.mjs';
6
+ export { getConnectingResult, getErrorResult, getIdleResult, getPendingResult, getReconnectingResult, getStartingResult } from './hooks/types.mjs';
6
7
  export { getClientArgs } from '../internals/getClientArgs.mjs';
7
8
  export { TRPCContext, contextProps } from '../internals/context.mjs';
@@ -1,10 +1,11 @@
1
1
  import type { CancelOptions, InfiniteData, InvalidateOptions, InvalidateQueryFilters, Query, QueryFilters, QueryKey, RefetchOptions, RefetchQueryFilters, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
2
2
  import type { TRPCClientError } from '@trpc/client';
3
- import type { AnyQueryProcedure, AnyRootTypes, AnyRouter, DeepPartial, inferProcedureInput, inferTransformedProcedureOutput, ProtectedIntersection, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
3
+ import type { AnyMutationProcedure, AnyQueryProcedure, AnyRootTypes, AnyRouter, DeepPartial, inferProcedureInput, inferTransformedProcedureOutput, ProtectedIntersection, RouterRecord } from '@trpc/server/unstable-core-do-not-import';
4
4
  import type { DecoratedTRPCContextProps, TRPCContextState, TRPCFetchInfiniteQueryOptions, TRPCFetchQueryOptions, TRPCQueryUtils } from '../../internals/context';
5
5
  import type { QueryKeyKnown, QueryType } from '../../internals/getQueryKey';
6
+ import type { InferMutationOptions } from '../../utils/inferReactQueryProcedure';
6
7
  import type { ExtractCursorType } from '../hooks/types';
7
- type DecorateProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyQueryProcedure> = {
8
+ type DecorateQueryProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyQueryProcedure> = {
8
9
  /**
9
10
  * @link https://tanstack.com/query/v5/docs/reference/QueryClient#queryclientfetchquery
10
11
  */
@@ -74,6 +75,13 @@ type DecorateProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyQueryPr
74
75
  */
75
76
  getInfiniteData(input?: inferProcedureInput<TProcedure>): InfiniteData<inferTransformedProcedureOutput<TRoot, TProcedure>, NonNullable<ExtractCursorType<inferProcedureInput<TProcedure>>> | null> | undefined;
76
77
  };
78
+ type DecorateMutationProcedure<TRoot extends AnyRootTypes, TProcedure extends AnyMutationProcedure> = {
79
+ setMutationDefaults(options: InferMutationOptions<TRoot, TProcedure> | ((args: {
80
+ canonicalMutationFn: NonNullable<InferMutationOptions<TRoot, TProcedure>['mutationFn']>;
81
+ }) => InferMutationOptions<TRoot, TProcedure>)): void;
82
+ getMutationDefaults(): InferMutationOptions<TRoot, TProcedure> | undefined;
83
+ isMutating(): number;
84
+ };
77
85
  /**
78
86
  * this is the type that is used to add in procedures that can be used on
79
87
  * an entire router
@@ -90,9 +98,9 @@ type DecorateRouter = {
90
98
  * @internal
91
99
  */
92
100
  export type DecoratedProcedureUtilsRecord<TRoot extends AnyRootTypes, TRecord extends RouterRecord> = DecorateRouter & {
93
- [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends RouterRecord ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter : $Value extends AnyQueryProcedure ? DecorateProcedure<TRoot, $Value> : never : never;
101
+ [TKey in keyof TRecord]: TRecord[TKey] extends infer $Value ? $Value extends RouterRecord ? DecoratedProcedureUtilsRecord<TRoot, $Value> & DecorateRouter : $Value extends AnyQueryProcedure ? DecorateQueryProcedure<TRoot, $Value> : $Value extends AnyMutationProcedure ? DecorateMutationProcedure<TRoot, $Value> : never : never;
94
102
  };
95
- type AnyDecoratedProcedure = DecorateProcedure<any, any>;
103
+ type AnyDecoratedProcedure = DecorateQueryProcedure<any, any> & DecorateMutationProcedure<any, any>;
96
104
  export type CreateReactUtils<TRouter extends AnyRouter, TSSRContext> = ProtectedIntersection<DecoratedTRPCContextProps<TRouter, TSSRContext>, DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>>;
97
105
  export type CreateQueryUtils<TRouter extends AnyRouter> = DecoratedProcedureUtilsRecord<TRouter['_def']['_config']['$types'], TRouter['_def']['record']>;
98
106
  export declare const getQueryType: (utilName: keyof AnyDecoratedProcedure) => QueryType;
@@ -1 +1 @@
1
- {"version":3,"file":"utilsProxy.d.ts","sourceRoot":"","sources":["../../../src/shared/proxy/utilsProxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,iBAAiB,EACjB,sBAAsB,EACtB,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,cAAc,EACd,mBAAmB,EACnB,YAAY,EACZ,cAAc,EACd,OAAO,EACR,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,+BAA+B,EAC/B,qBAAqB,EACrB,YAAY,EACb,MAAM,0CAA0C,CAAC;AAKlD,OAAO,KAAK,EACV,yBAAyB,EACzB,gBAAgB,EAChB,6BAA6B,EAC7B,qBAAqB,EACrB,cAAc,EACf,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,aAAa,E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21
  return 'infinite';
22
+ case 'setMutationDefaults':
23
+ case 'getMutationDefaults':
24
+ case 'isMutating':
22
25
  case 'cancel':
23
26
  case 'invalidate':
24
27
  case 'refetch':
@@ -41,7 +44,9 @@ const getQueryType = (utilName)=>{
41
44
  const queryType = getQueryType(utilName);
42
45
  const queryKey = getQueryKey.getQueryKeyInternal(path, input, queryType);
43
46
  const contextMap = {
44
- fetch: ()=>context.fetchQuery(queryKey, ...args),
47
+ /**
48
+ * DecorateQueryProcedure
49
+ */ fetch: ()=>context.fetchQuery(queryKey, ...args),
45
50
  fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
46
51
  prefetch: ()=>context.prefetchQuery(queryKey, ...args),
47
52
  prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
@@ -58,7 +63,14 @@ const getQueryType = (utilName)=>{
58
63
  context.setInfiniteQueryData(queryKey, args[0], args[1]);
59
64
  },
60
65
  getData: ()=>context.getQueryData(queryKey),
61
- getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
66
+ getInfiniteData: ()=>context.getInfiniteQueryData(queryKey),
67
+ /**
68
+ * DecorateMutationProcedure
69
+ */ setMutationDefaults: ()=>context.setMutationDefaults(getQueryKey.getMutationKeyInternal(path), input),
70
+ getMutationDefaults: ()=>context.getMutationDefaults(getQueryKey.getMutationKeyInternal(path)),
71
+ isMutating: ()=>context.isMutating({
72
+ mutationKey: getQueryKey.getMutationKeyInternal(path)
73
+ })
62
74
  };
63
75
  return contextMap[utilName]();
64
76
  });
@@ -1,7 +1,7 @@
1
1
  import { createTRPCClientProxy } from '@trpc/client';
2
2
  import { createFlatProxy, createRecursiveProxy } from '@trpc/server/unstable-core-do-not-import';
3
3
  import { contextProps } from '../../internals/context.mjs';
4
- import { getQueryKeyInternal } from '../../internals/getQueryKey.mjs';
4
+ import { getQueryKeyInternal, getMutationKeyInternal } from '../../internals/getQueryKey.mjs';
5
5
 
6
6
  const getQueryType = (utilName)=>{
7
7
  switch(utilName){
@@ -17,6 +17,9 @@ const getQueryType = (utilName)=>{
17
17
  case 'getInfiniteData':
18
18
  case 'setInfiniteData':
19
19
  return 'infinite';
20
+ case 'setMutationDefaults':
21
+ case 'getMutationDefaults':
22
+ case 'isMutating':
20
23
  case 'cancel':
21
24
  case 'invalidate':
22
25
  case 'refetch':
@@ -39,7 +42,9 @@ const getQueryType = (utilName)=>{
39
42
  const queryType = getQueryType(utilName);
40
43
  const queryKey = getQueryKeyInternal(path, input, queryType);
41
44
  const contextMap = {
42
- fetch: ()=>context.fetchQuery(queryKey, ...args),
45
+ /**
46
+ * DecorateQueryProcedure
47
+ */ fetch: ()=>context.fetchQuery(queryKey, ...args),
43
48
  fetchInfinite: ()=>context.fetchInfiniteQuery(queryKey, args[0]),
44
49
  prefetch: ()=>context.prefetchQuery(queryKey, ...args),
45
50
  prefetchInfinite: ()=>context.prefetchInfiniteQuery(queryKey, args[0]),
@@ -56,7 +61,14 @@ const getQueryType = (utilName)=>{
56
61
  context.setInfiniteQueryData(queryKey, args[0], args[1]);
57
62
  },
58
63
  getData: ()=>context.getQueryData(queryKey),
59
- getInfiniteData: ()=>context.getInfiniteQueryData(queryKey)
64
+ getInfiniteData: ()=>context.getInfiniteQueryData(queryKey),
65
+ /**
66
+ * DecorateMutationProcedure
67
+ */ setMutationDefaults: ()=>context.setMutationDefaults(getMutationKeyInternal(path), input),
68
+ getMutationDefaults: ()=>context.getMutationDefaults(getMutationKeyInternal(path)),
69
+ isMutating: ()=>context.isMutating({
70
+ mutationKey: getMutationKeyInternal(path)
71
+ })
60
72
  };
61
73
  return contextMap[utilName]();
62
74
  });
@@ -1 +1 @@
1
- {"version":3,"file":"createUtilityFunctions.d.ts","sourceRoot":"","sources":["../../src/utils/createUtilityFunctions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,O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var getClientArgs = require('../internals/getClientArgs.js');
100
100
  },
101
101
  getInfiniteQueryData: (queryKey)=>{
102
102
  return queryClient.getQueryData(queryKey);
103
+ },
104
+ setMutationDefaults: (mutationKey, options)=>{
105
+ const path = mutationKey[0];
106
+ const canonicalMutationFn = (input)=>{
107
+ return untypedClient.mutation(...getClientArgs.getClientArgs([
108
+ path,
109
+ {
110
+ input
111
+ }
112
+ ], opts));
113
+ };
114
+ return queryClient.setMutationDefaults(mutationKey, typeof options === 'function' ? options({
115
+ canonicalMutationFn
116
+ }) : options);
117
+ },
118
+ getMutationDefaults: (mutationKey)=>{
119
+ return queryClient.getMutationDefaults(mutationKey);
120
+ },
121
+ isMutating: (filters)=>{
122
+ return queryClient.isMutating({
123
+ ...filters,
124
+ exact: true
125
+ });
103
126
  }
104
127
  };
105
128
  }
@@ -98,6 +98,29 @@ import { getClientArgs } from '../internals/getClientArgs.mjs';
98
98
  },
99
99
  getInfiniteQueryData: (queryKey)=>{
100
100
  return queryClient.getQueryData(queryKey);
101
+ },
102
+ setMutationDefaults: (mutationKey, options)=>{
103
+ const path = mutationKey[0];
104
+ const canonicalMutationFn = (input)=>{
105
+ return untypedClient.mutation(...getClientArgs([
106
+ path,
107
+ {
108
+ input
109
+ }
110
+ ], opts));
111
+ };
112
+ return queryClient.setMutationDefaults(mutationKey, typeof options === 'function' ? options({
113
+ canonicalMutationFn
114
+ }) : options);
115
+ },
116
+ getMutationDefaults: (mutationKey)=>{
117
+ return queryClient.getMutationDefaults(mutationKey);
118
+ },
119
+ isMutating: (filters)=>{
120
+ return queryClient.isMutating({
121
+ ...filters,
122
+ exact: true
123
+ });
101
124
  }
102
125
  };
103
126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/react-query",
3
- "version": "11.0.0-alpha-tmp-issues-5851-take-two.499+02e677611",
3
+ "version": "11.0.0-alpha-tmp-subscription-connection-state.485+386eae02c",
4
4
  "description": "The tRPC React library",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -64,15 +64,15 @@
64
64
  },
65
65
  "peerDependencies": {
66
66
  "@tanstack/react-query": "^5.49.2",
67
- "@trpc/client": "11.0.0-alpha-tmp-issues-5851-take-two.499+02e677611",
68
- "@trpc/server": "11.0.0-alpha-tmp-issues-5851-take-two.499+02e677611",
67
+ "@trpc/client": "11.0.0-alpha-tmp-subscription-connection-state.485+386eae02c",
68
+ "@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.485+386eae02c",
69
69
  "react": ">=18.2.0",
70
70
  "react-dom": ">=18.2.0"
71
71
  },
72
72
  "devDependencies": {
73
73
  "@tanstack/react-query": "^5.49.2",
74
- "@trpc/client": "11.0.0-alpha-tmp-issues-5851-take-two.499+02e677611",
75
- "@trpc/server": "11.0.0-alpha-tmp-issues-5851-take-two.499+02e677611",
74
+ "@trpc/client": "11.0.0-alpha-tmp-subscription-connection-state.485+386eae02c",
75
+ "@trpc/server": "11.0.0-alpha-tmp-subscription-connection-state.485+386eae02c",
76
76
  "@types/express": "^4.17.17",
77
77
  "@types/node": "^20.10.0",
78
78
  "@types/react": "^18.3.1",
@@ -92,5 +92,5 @@
92
92
  "funding": [
93
93
  "https://trpc.io/sponsor"
94
94
  ],
95
- "gitHead": "02e67761124670c5ff27d174bfec6cfa5410a5ac"
95
+ "gitHead": "386eae02c675ba0fe0feda78188b6975e56d0e49"
96
96
  }
@@ -32,6 +32,7 @@ import type {
32
32
  UseTRPCQueryOptions,
33
33
  UseTRPCQueryResult,
34
34
  UseTRPCSubscriptionOptions,
35
+ UseTRPCSubscriptionResult,
35
36
  UseTRPCSuspenseInfiniteQueryOptions,
36
37
  UseTRPCSuspenseInfiniteQueryResult,
37
38
  UseTRPCSuspenseQueryOptions,
@@ -180,7 +181,11 @@ interface ProcedureUseSubscription<TDef extends ResolverDef> {
180
181
  (
181
182
  input: TDef['input'],
182
183
  opts: UseTRPCSubscriptionOptions<TDef['output'], TRPCClientErrorLike<TDef>>,
183
- ): void;
184
+ ): UseTRPCSubscriptionResult<
185
+ TDef['input'],
186
+ TDef['output'],
187
+ TRPCClientErrorLike<TDef>
188
+ >;
184
189
 
185
190
  // With skip token
186
191
  (
@@ -189,7 +194,11 @@ interface ProcedureUseSubscription<TDef extends ResolverDef> {
189
194
  UseTRPCSubscriptionOptions<TDef['output'], TRPCClientErrorLike<TDef>>,
190
195
  'enabled'
191
196
  >,
192
- ): void;
197
+ ): UseTRPCSubscriptionResult<
198
+ TDef['input'],
199
+ TDef['output'],
200
+ TRPCClientErrorLike<TDef>
201
+ >;
193
202
  }
194
203
  /**
195
204
  * @internal
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from '@trpc/client';
2
2
 
3
- export { getQueryKey } from './internals/getQueryKey';
3
+ export { getQueryKey, getMutationKey } from './internals/getQueryKey';
4
4
  export {
5
5
  createTRPCReact,
6
6
  type CreateTRPCReact,
@@ -5,6 +5,7 @@ import type {
5
5
  InfiniteData,
6
6
  InvalidateOptions,
7
7
  InvalidateQueryFilters,
8
+ MutationOptions,
8
9
  QueryClient,
9
10
  QueryFilters,
10
11
  QueryKey,
@@ -26,7 +27,7 @@ import type {
26
27
  } from '@trpc/server/unstable-core-do-not-import';
27
28
  import * as React from 'react';
28
29
  import type { ExtractCursorType } from '../shared';
29
- import type { TRPCQueryKey } from './getQueryKey';
30
+ import type { TRPCMutationKey, TRPCQueryKey } from './getQueryKey';
30
31
 
31
32
  export type TRPCFetchQueryOptions<TOutput, TError> = DistributiveOmit<
32
33
  FetchQueryOptions<TOutput, TError>,
@@ -240,5 +241,29 @@ export interface TRPCQueryUtils<TRouter extends AnyRouter> {
240
241
  getInfiniteQueryData: (
241
242
  queryKey: TRPCQueryKey,
242
243
  ) => InfiniteData<unknown> | undefined;
244
+
245
+ /**
246
+ * @link https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetmutationdefaults
247
+ */
248
+ setMutationDefaults: (
249
+ mutationKey: TRPCMutationKey,
250
+ options:
251
+ | MutationOptions
252
+ | ((args: {
253
+ canonicalMutationFn: (input: unknown) => Promise<unknown>;
254
+ }) => MutationOptions),
255
+ ) => void;
256
+
257
+ /**
258
+ * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientgetmutationdefaults
259
+ */
260
+ getMutationDefaults: (
261
+ mutationKey: TRPCMutationKey,
262
+ ) => MutationOptions | undefined;
263
+
264
+ /**
265
+ * @link https://tanstack.com/query/latest/docs/reference/QueryClient#queryclientismutating
266
+ */
267
+ isMutating: (filters: { mutationKey: TRPCMutationKey }) => number;
243
268
  }
244
269
  export const TRPCContext = React.createContext?.(null as any);
@@ -13,6 +13,8 @@ export type TRPCQueryKey = [
13
13
  { input?: unknown; type?: Exclude<QueryType, 'any'> }?,
14
14
  ];
15
15
 
16
+ export type TRPCMutationKey = [readonly string[]]; // = [TRPCQueryKey[0]]
17
+
16
18
  type ProcedureOrRouter =
17
19
  | DecoratedMutation<any>
18
20
  | DecoratedQuery<any>
@@ -36,6 +38,8 @@ export function getQueryKeyInternal(
36
38
  const splitPath = path.flatMap((part) => part.split('.'));
37
39
 
38
40
  if (!input && (!type || type === 'any')) {
41
+ // this matches also all mutations (see `getMutationKeyInternal`)
42
+
39
43
  // for `utils.invalidate()` to match all queries (including vanilla react-query)
40
44
  // we don't want nested array if path is empty, i.e. `[]` instead of `[[]]`
41
45
  return splitPath.length ? [splitPath] : ([] as unknown as TRPCQueryKey);
@@ -69,6 +73,10 @@ export function getQueryKeyInternal(
69
73
  ];
70
74
  }
71
75
 
76
+ export function getMutationKeyInternal(path: readonly string[]) {
77
+ return getQueryKeyInternal(path, undefined, 'any') as TRPCMutationKey;
78
+ }
79
+
72
80
  type GetInfiniteQueryInput<
73
81
  TProcedureInput,
74
82
  TInputWithoutCursorAndDirection = Omit<
@@ -115,3 +123,16 @@ export type QueryKeyKnown<TInput, TType extends Exclude<QueryType, 'any'>> = [
115
123
  string[],
116
124
  { input?: GetQueryProcedureInput<TInput>; type: TType }?,
117
125
  ];
126
+
127
+ /**
128
+ * Method to extract the mutation key for a procedure
129
+ * @param procedure - procedure
130
+ * @link https://trpc.io/docs/v11/getQueryKey#mutations
131
+ */
132
+ export function getMutationKey<TProcedure extends DecoratedMutation<any>>(
133
+ procedure: TProcedure,
134
+ ) {
135
+ // @ts-expect-error - we don't expose _def on the type layer
136
+ const path = procedure._def().path as string[];
137
+ return getMutationKeyInternal(path);
138
+ }