@trpc/tanstack-react-query 11.18.1-canary.6 → 11.19.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/dist/index.cjs +172 -245
- package/dist/index.d.cts +7 -8
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +7 -8
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +161 -258
- package/dist/index.mjs.map +1 -1
- package/package.json +12 -12
- package/src/internals/Context.tsx +1 -4
- package/src/internals/createOptionsProxy.ts +11 -8
- package/src/internals/infiniteQueryOptions.ts +19 -11
- package/src/internals/mutationOptions.ts +3 -1
- package/src/internals/queryOptions.ts +18 -6
- package/src/internals/subscriptionOptions.ts +30 -18
- package/src/internals/types.ts +2 -4
|
@@ -12,7 +12,7 @@ import type {
|
|
|
12
12
|
TRPCQueryKey,
|
|
13
13
|
TRPCQueryOptionsResult,
|
|
14
14
|
} from './types';
|
|
15
|
-
import { createTRPCOptionsResult
|
|
15
|
+
import { createTRPCOptionsResult } from './utils';
|
|
16
16
|
|
|
17
17
|
interface BaseTRPCSubscriptionOptionsIn<TOutput, TError> {
|
|
18
18
|
enabled?: boolean;
|
|
@@ -33,7 +33,9 @@ interface TRPCSubscriptionOptionsOut<
|
|
|
33
33
|
TOutput,
|
|
34
34
|
TError,
|
|
35
35
|
TFeatureFlags extends FeatureFlags,
|
|
36
|
-
>
|
|
36
|
+
>
|
|
37
|
+
extends
|
|
38
|
+
UnusedSkipTokenTRPCSubscriptionOptionsIn<TOutput, TError>,
|
|
37
39
|
TRPCQueryOptionsResult {
|
|
38
40
|
enabled: boolean;
|
|
39
41
|
queryKey: TRPCQueryKey<TFeatureFlags['keyPrefix']>;
|
|
@@ -70,10 +72,7 @@ export interface TRPCSubscriptionOptions<
|
|
|
70
72
|
>;
|
|
71
73
|
}
|
|
72
74
|
export type TRPCSubscriptionStatus =
|
|
73
|
-
| '
|
|
74
|
-
| 'connecting'
|
|
75
|
-
| 'pending'
|
|
76
|
-
| 'error';
|
|
75
|
+
'idle' | 'connecting' | 'pending' | 'error';
|
|
77
76
|
|
|
78
77
|
export interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
79
78
|
status: TRPCSubscriptionStatus;
|
|
@@ -85,29 +84,35 @@ export interface TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
|
85
84
|
reset: () => void;
|
|
86
85
|
}
|
|
87
86
|
|
|
88
|
-
export interface TRPCSubscriptionIdleResult<
|
|
89
|
-
|
|
87
|
+
export interface TRPCSubscriptionIdleResult<
|
|
88
|
+
TOutput,
|
|
89
|
+
> extends TRPCSubscriptionBaseResult<TOutput, null> {
|
|
90
90
|
status: 'idle';
|
|
91
91
|
data: undefined;
|
|
92
92
|
error: null;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
export interface TRPCSubscriptionConnectingResult<
|
|
96
|
-
|
|
95
|
+
export interface TRPCSubscriptionConnectingResult<
|
|
96
|
+
TOutput,
|
|
97
|
+
TError,
|
|
98
|
+
> extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
97
99
|
status: 'connecting';
|
|
98
100
|
data: undefined | TOutput;
|
|
99
101
|
error: TError | null;
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
export interface TRPCSubscriptionPendingResult<
|
|
103
|
-
|
|
104
|
+
export interface TRPCSubscriptionPendingResult<
|
|
105
|
+
TOutput,
|
|
106
|
+
> extends TRPCSubscriptionBaseResult<TOutput, undefined> {
|
|
104
107
|
status: 'pending';
|
|
105
108
|
data: TOutput | undefined;
|
|
106
109
|
error: null;
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
export interface TRPCSubscriptionErrorResult<
|
|
110
|
-
|
|
112
|
+
export interface TRPCSubscriptionErrorResult<
|
|
113
|
+
TOutput,
|
|
114
|
+
TError,
|
|
115
|
+
> extends TRPCSubscriptionBaseResult<TOutput, TError> {
|
|
111
116
|
status: 'error';
|
|
112
117
|
data: TOutput | undefined;
|
|
113
118
|
error: TError;
|
|
@@ -135,16 +140,24 @@ export const trpcSubscriptionOptions = <
|
|
|
135
140
|
subscribe: typeof TRPCUntypedClient.prototype.subscription;
|
|
136
141
|
path: string[];
|
|
137
142
|
queryKey: TRPCQueryKey<TFeatureFlags['keyPrefix']>;
|
|
143
|
+
/**
|
|
144
|
+
* The raw input before queryKey serialization. Required to correctly detect
|
|
145
|
+
* `skipToken` because `getQueryKeyInternal` strips it from the queryKey args.
|
|
146
|
+
*/
|
|
147
|
+
input: unknown;
|
|
138
148
|
opts?: AnyTRPCSubscriptionOptionsIn;
|
|
139
149
|
}): AnyTRPCSubscriptionOptionsOut<TFeatureFlags> => {
|
|
140
|
-
const { subscribe, path, queryKey, opts = {} } = args;
|
|
141
|
-
const input = readQueryKey(queryKey)?.args?.input;
|
|
150
|
+
const { subscribe, path, queryKey, input, opts = {} } = args;
|
|
142
151
|
const enabled = 'enabled' in opts ? !!opts.enabled : input !== skipToken;
|
|
143
152
|
|
|
144
153
|
const _subscribe: ReturnType<
|
|
145
154
|
TRPCSubscriptionOptions<any, TFeatureFlags>
|
|
146
155
|
>['subscribe'] = (innerOpts) => {
|
|
147
|
-
return subscribe(
|
|
156
|
+
return subscribe(
|
|
157
|
+
path.join('.'),
|
|
158
|
+
input === skipToken ? undefined : input,
|
|
159
|
+
innerOpts,
|
|
160
|
+
);
|
|
148
161
|
};
|
|
149
162
|
|
|
150
163
|
return {
|
|
@@ -237,7 +250,6 @@ export function useSubscription<TOutput, TError>(
|
|
|
237
250
|
currentSubscriptionRef.current = () => {
|
|
238
251
|
subscription.unsubscribe();
|
|
239
252
|
};
|
|
240
|
-
// eslint-disable-next-line react-hooks/react-compiler
|
|
241
253
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
242
254
|
}, [hashKey(opts.queryKey), opts.enabled]);
|
|
243
255
|
|
package/src/internals/types.ts
CHANGED
|
@@ -103,8 +103,7 @@ export type TRPCQueryKey<TPrefixEnabled extends boolean = false> =
|
|
|
103
103
|
: TRPCQueryKeyWithoutPrefix;
|
|
104
104
|
|
|
105
105
|
export type AnyTRPCQueryKey =
|
|
106
|
-
|
|
|
107
|
-
| TRPCQueryKeyWithPrefix;
|
|
106
|
+
TRPCQueryKeyWithoutPrefix | TRPCQueryKeyWithPrefix;
|
|
108
107
|
|
|
109
108
|
/**
|
|
110
109
|
* @public
|
|
@@ -120,8 +119,7 @@ export type TRPCMutationKeyWithPrefix = [
|
|
|
120
119
|
export type TRPCMutationKeyWithoutPrefix = [path: string[]];
|
|
121
120
|
|
|
122
121
|
export type AnyTRPCMutationKey =
|
|
123
|
-
|
|
|
124
|
-
| TRPCMutationKeyWithPrefix;
|
|
122
|
+
TRPCMutationKeyWithoutPrefix | TRPCMutationKeyWithPrefix;
|
|
125
123
|
|
|
126
124
|
/**
|
|
127
125
|
* @public
|