@orpc/tanstack-query 1.14.11 → 1.14.13
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 +48 -52
- package/dist/index.d.mts +152 -312
- package/dist/index.d.ts +152 -312
- package/dist/index.mjs +165 -484
- package/package.json +15 -17
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { ClientContext, Client,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public, ThrowableError } from '@orpc/shared';
|
|
5
|
-
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData, MutationFunctionContext } from '@tanstack/query-core';
|
|
1
|
+
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
|
+
import { Promisable, SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
+
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData } from '@tanstack/query-core';
|
|
6
4
|
|
|
7
|
-
interface
|
|
5
|
+
interface experimental_SerializableStreamedQueryOptions {
|
|
8
6
|
/**
|
|
9
|
-
* Determines how data is handled when the query is
|
|
7
|
+
* Determines how data is handled when the query is refetched.
|
|
10
8
|
*
|
|
11
|
-
* - `'reset'`: Clears existing data and
|
|
12
|
-
* - `'append'`:
|
|
13
|
-
* - `'replace'`:
|
|
9
|
+
* - `'reset'`: Clears existing data and sets the query back to a pending state.
|
|
10
|
+
* - `'append'`: Appends new data chunks to the existing data.
|
|
11
|
+
* - `'replace'`: Collects all streamed data and replaces the cache once the stream finishes.
|
|
14
12
|
*
|
|
15
13
|
* @default 'reset'
|
|
16
14
|
*/
|
|
@@ -28,11 +26,17 @@ interface SerializableStreamedQueryOptions {
|
|
|
28
26
|
* - Options are serializable
|
|
29
27
|
* - The output is predictable
|
|
30
28
|
*/
|
|
31
|
-
declare function
|
|
29
|
+
declare function experimental_serializableStreamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => Promisable<AsyncIterable<TQueryFnData>>, { refetchMode, maxChunks }?: experimental_SerializableStreamedQueryOptions): QueryFunction<Array<TQueryFnData>, TQueryKey>;
|
|
32
30
|
|
|
33
|
-
type
|
|
34
|
-
type
|
|
31
|
+
type experimental_StreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
32
|
+
type experimental_LiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
35
33
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
34
|
+
type OperationKeyOptions<TType extends OperationType, TInput> = {
|
|
35
|
+
type?: TType;
|
|
36
|
+
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
37
|
+
fnOptions?: TType extends 'streamed' ? experimental_SerializableStreamedQueryOptions : never;
|
|
38
|
+
};
|
|
39
|
+
type OperationKey<TType extends OperationType, TInput> = [path: readonly string[], options: OperationKeyOptions<TType, TInput>];
|
|
36
40
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
37
41
|
interface OperationContext {
|
|
38
42
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
@@ -44,393 +48,229 @@ type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
|
44
48
|
input?: TInput | SkipToken;
|
|
45
49
|
} : {
|
|
46
50
|
input: TInput | SkipToken;
|
|
47
|
-
})
|
|
48
|
-
queryKey
|
|
51
|
+
}) & {
|
|
52
|
+
queryKey?: QueryKey;
|
|
49
53
|
};
|
|
50
|
-
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData
|
|
51
|
-
input?: TInput | SkipToken;
|
|
52
|
-
} : {
|
|
53
|
-
input: TInput | SkipToken;
|
|
54
|
-
}) & (object extends TClientContext ? {
|
|
54
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryKeyOptions<TInput> & (Record<never, never> extends TClientContext ? {
|
|
55
55
|
context?: TClientContext;
|
|
56
56
|
} : {
|
|
57
57
|
context: TClientContext;
|
|
58
|
-
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
input?: TInput | SkipToken;
|
|
69
|
-
} : {
|
|
70
|
-
input: TInput | SkipToken;
|
|
71
|
-
}) & {
|
|
72
|
-
queryFnOptions?: SerializableStreamedQueryOptions;
|
|
73
|
-
}) | {
|
|
74
|
-
queryKey: QueryKey;
|
|
75
|
-
};
|
|
76
|
-
type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData> & {
|
|
77
|
-
queryFnOptions?: SerializableStreamedQueryOptions;
|
|
58
|
+
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'>;
|
|
59
|
+
interface QueryOptionsBase<TOutput, TError> {
|
|
60
|
+
queryKey: DataTag<QueryKey, TOutput, TError>;
|
|
61
|
+
queryFn: QueryFunction<TOutput>;
|
|
62
|
+
throwOnError?: (error: TError) => boolean;
|
|
63
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
64
|
+
enabled?: boolean;
|
|
65
|
+
}
|
|
66
|
+
type experimental_StreamedKeyOptions<TInput> = QueryKeyOptions<TInput> & {
|
|
67
|
+
queryFnOptions?: experimental_SerializableStreamedQueryOptions;
|
|
78
68
|
};
|
|
79
|
-
type
|
|
80
|
-
|
|
81
|
-
queryKey: QueryKey;
|
|
69
|
+
type experimental_StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData> & {
|
|
70
|
+
queryFnOptions?: experimental_SerializableStreamedQueryOptions;
|
|
82
71
|
};
|
|
83
|
-
|
|
72
|
+
interface experimental_StreamedOptionsBase<TOutput, TError> extends QueryOptionsBase<TOutput, TError> {
|
|
73
|
+
}
|
|
74
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam> = {
|
|
84
75
|
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
85
|
-
|
|
86
|
-
queryKey?: QueryKey;
|
|
87
|
-
} & (object extends TClientContext ? {
|
|
76
|
+
} & (Record<never, never> extends TClientContext ? {
|
|
88
77
|
context?: TClientContext;
|
|
89
78
|
} : {
|
|
90
79
|
context: TClientContext;
|
|
91
|
-
}) &
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
80
|
+
}) & SetOptional<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey'>;
|
|
81
|
+
interface InfiniteOptionsBase<TOutput, TError, TPageParam> {
|
|
82
|
+
queryKey: DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>;
|
|
83
|
+
queryFn: QueryFunction<TOutput, QueryKey, TPageParam>;
|
|
84
|
+
select?(): InfiniteData<TOutput, TPageParam>;
|
|
85
|
+
throwOnError?: (error: TError) => boolean;
|
|
86
|
+
retryDelay?: (count: number, error: TError) => number;
|
|
87
|
+
enabled?: boolean;
|
|
88
|
+
}
|
|
89
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
99
90
|
context?: TClientContext;
|
|
100
91
|
} : {
|
|
101
92
|
context: TClientContext;
|
|
102
|
-
}) &
|
|
103
|
-
type
|
|
104
|
-
|
|
105
|
-
interface OperationKeyPrefixOptions {
|
|
106
|
-
/**
|
|
107
|
-
* Prepended as the first element of the key when present.
|
|
108
|
-
* Use this to avoid key conflicts when multiple router utils share the same client.
|
|
109
|
-
*/
|
|
110
|
-
prefix?: string;
|
|
111
|
-
}
|
|
112
|
-
type OperationKeyOptions<TType extends OperationType, TInput> = OperationKeyPrefixOptions & {
|
|
113
|
-
type?: TType;
|
|
114
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
115
|
-
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
116
|
-
};
|
|
117
|
-
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>] | [prefix: string, path: string[], options: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>];
|
|
118
|
-
declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
93
|
+
}) & MutationOptions<TInput, TOutput, TError, TMutationContext>;
|
|
94
|
+
type MutationOptions<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
|
|
119
95
|
|
|
120
|
-
declare class SharedUtils<TInput> {
|
|
121
|
-
protected readonly path: string[];
|
|
122
|
-
protected readonly options: OperationKeyPrefixOptions;
|
|
123
|
-
constructor(path: string[], options: OperationKeyPrefixOptions);
|
|
124
|
-
/**
|
|
125
|
-
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
126
|
-
*/
|
|
127
|
-
key<TType extends OperationType>(options?: Omit<OperationKeyOptions<TType, TInput>, 'prefix'>): OperationKey<TType, TInput>;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
interface ProcedureUtilsQueryInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
131
|
-
path: string[];
|
|
132
|
-
context: TClientContext & OperationContext;
|
|
133
|
-
input: TInput | SkipToken;
|
|
134
|
-
fnContext: QueryFunctionContext;
|
|
135
|
-
}
|
|
136
|
-
type ProcedureUtilsQueryInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
137
|
-
interface ProcedureUtilsStreamedInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
138
|
-
}
|
|
139
|
-
type ProcedureUtilsStreamedInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsStreamedInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferStreamedQueryOutput<TOutput>, TError>>;
|
|
140
|
-
interface ProcedureUtilsLiveInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
141
|
-
}
|
|
142
|
-
type ProcedureUtilsLiveInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsLiveInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferLiveQueryOutput<TOutput>, TError>>;
|
|
143
|
-
interface ProcedureUtilsInfiniteInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
144
|
-
fnContext: QueryFunctionContext<QueryKey, any>;
|
|
145
|
-
}
|
|
146
|
-
type ProcedureUtilsInfiniteInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsInfiniteInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
147
|
-
interface ProcedureUtilsMutationInterceptorOptions<TClientContext extends ClientContext, TInput> extends Omit<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, 'input' | 'fnContext'> {
|
|
148
|
-
input: TInput;
|
|
149
|
-
fnContext: MutationFunctionContext;
|
|
150
|
-
}
|
|
151
|
-
type ProcedureUtilsMutationInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsMutationInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
152
96
|
/**
|
|
153
|
-
*
|
|
154
|
-
* or a function that receives per-call options and returns overridden this.options.
|
|
97
|
+
* Utils at any level (procedure or router)
|
|
155
98
|
*/
|
|
156
|
-
|
|
157
|
-
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> extends OperationKeyPrefixOptions {
|
|
158
|
-
/**
|
|
159
|
-
* Key options modifier for .queryKey and .queryOptions
|
|
160
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
161
|
-
*/
|
|
162
|
-
queryKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>>;
|
|
163
|
-
/**
|
|
164
|
-
* Interceptors that intercept queryFn inside .queryOptions, guaranteed to be executed.
|
|
165
|
-
*/
|
|
166
|
-
queryInterceptors?: ProcedureUtilsQueryInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
167
|
-
/**
|
|
168
|
-
* Options modifier for .queryOptions
|
|
169
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
170
|
-
*/
|
|
171
|
-
queryOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown>>;
|
|
172
|
-
/**
|
|
173
|
-
* Key options modifier for .streamedKey and .streamedOptions
|
|
174
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
175
|
-
*/
|
|
176
|
-
streamedKey?: ProcedureUtilsModifier<StreamedKeyOptions<TInput>>;
|
|
177
|
-
/**
|
|
178
|
-
* Interceptors that intercept queryFn inside .streamedOptions, guaranteed to be executed.
|
|
179
|
-
*/
|
|
180
|
-
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
181
|
-
/**
|
|
182
|
-
* Options modifier for .streamedOptions
|
|
183
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
184
|
-
*/
|
|
185
|
-
streamedOptions?: ProcedureUtilsModifier<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, unknown, unknown>>;
|
|
186
|
-
/**
|
|
187
|
-
* Key options modifier for .liveKey and .liveOptions
|
|
188
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
189
|
-
*/
|
|
190
|
-
liveKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>>;
|
|
191
|
-
/**
|
|
192
|
-
* Interceptors that intercept queryFn inside .liveOptions, guaranteed to be executed.
|
|
193
|
-
*/
|
|
194
|
-
liveInterceptors?: ProcedureUtilsLiveInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
195
|
-
/**
|
|
196
|
-
* Options modifier for .liveOptions
|
|
197
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
198
|
-
*/
|
|
199
|
-
liveOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, unknown, unknown>>;
|
|
99
|
+
interface GeneralUtils<TInput> {
|
|
200
100
|
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
|
|
204
|
-
infiniteKey?: ProcedureUtilsModifier<InfiniteKeyOptions<TInput, unknown>>;
|
|
205
|
-
/**
|
|
206
|
-
* Interceptors that intercept queryFn inside .infiniteOptions, guaranteed to be executed.
|
|
207
|
-
*/
|
|
208
|
-
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
209
|
-
/**
|
|
210
|
-
* Options modifier for .infiniteOptions
|
|
211
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
212
|
-
*/
|
|
213
|
-
infiniteOptions?: ProcedureUtilsModifier<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown, unknown>>;
|
|
214
|
-
/**
|
|
215
|
-
* Key options modifier for .mutationKey and .mutationOptions
|
|
216
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
217
|
-
*/
|
|
218
|
-
mutationKey?: ProcedureUtilsModifier<MutationKeyOptions>;
|
|
219
|
-
/**
|
|
220
|
-
* Interceptors that intercept mutationFn inside .mutationOptions, guaranteed to be executed.
|
|
221
|
-
*/
|
|
222
|
-
mutationInterceptors?: ProcedureUtilsMutationInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
223
|
-
/**
|
|
224
|
-
* Options modifier for .mutationOptions
|
|
225
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
101
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
102
|
+
*
|
|
103
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
226
104
|
*/
|
|
227
|
-
|
|
105
|
+
key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
228
106
|
}
|
|
229
|
-
declare function
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
* modifiers are spread-merged when both are plain objects and composed (base applied
|
|
235
|
-
* first) otherwise, with plain objects applied as regular spread merges.
|
|
236
|
-
*/
|
|
237
|
-
declare function mergeProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError>(base: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, override: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
238
|
-
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
239
|
-
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
107
|
+
declare function createGeneralUtils<TInput>(path: readonly string[]): GeneralUtils<TInput>;
|
|
108
|
+
|
|
109
|
+
declare function generateOperationKey<TType extends OperationType, TInput>(path: readonly string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
110
|
+
|
|
111
|
+
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
240
112
|
/**
|
|
241
113
|
* Calling corresponding procedure client
|
|
114
|
+
*
|
|
115
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#calling-clients Tanstack Calling Procedure Client Docs}
|
|
242
116
|
*/
|
|
243
117
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
244
|
-
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>);
|
|
245
118
|
/**
|
|
246
119
|
* Generate a **full matching** key for [Query Options](https://orpc.dev/docs/integrations/tanstack-query#query-options).
|
|
120
|
+
*
|
|
121
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
247
122
|
*/
|
|
248
123
|
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, TOutput, TError>;
|
|
249
124
|
/**
|
|
250
125
|
* Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
126
|
+
*
|
|
127
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
|
|
251
128
|
*/
|
|
252
|
-
queryOptions<USelectData = TOutput
|
|
129
|
+
queryOptions<U, USelectData = TOutput>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<TOutput, TError>, keyof U>>;
|
|
253
130
|
/**
|
|
254
131
|
* Generate a **full matching** key for [Streamed Query Options](https://orpc.dev/docs/integrations/tanstack-query#streamed-query-options).
|
|
132
|
+
*
|
|
133
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
255
134
|
*/
|
|
256
|
-
|
|
135
|
+
experimental_streamedKey(...rest: MaybeOptionalOptions<experimental_StreamedKeyOptions<TInput>>): DataTag<QueryKey, experimental_StreamedQueryOutput<TOutput>, TError>;
|
|
257
136
|
/**
|
|
258
|
-
* Configure queries for [
|
|
137
|
+
* Configure queries for [Event Iterator](https://orpc.dev/docs/event-iterator).
|
|
259
138
|
* This is built on [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
260
139
|
* and works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
140
|
+
*
|
|
141
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
261
142
|
*/
|
|
262
|
-
|
|
143
|
+
experimental_streamedOptions<U, USelectData = experimental_StreamedQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<experimental_StreamedOptionsBase<experimental_StreamedQueryOutput<TOutput>, TError>, keyof U>>;
|
|
263
144
|
/**
|
|
264
145
|
* Generate a **full matching** key for [Live Query Options](https://orpc.dev/docs/integrations/tanstack-query#live-query-options).
|
|
146
|
+
*
|
|
147
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
265
148
|
*/
|
|
266
|
-
|
|
149
|
+
experimental_liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, experimental_LiveQueryOutput<TOutput>, TError>;
|
|
267
150
|
/**
|
|
268
|
-
* Configure live queries for [
|
|
151
|
+
* Configure live queries for [Event Iterator](https://orpc.dev/docs/event-iterator).
|
|
269
152
|
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
270
153
|
* Works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
154
|
+
*
|
|
155
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
271
156
|
*/
|
|
272
|
-
|
|
157
|
+
experimental_liveOptions<U, USelectData = experimental_LiveQueryOutput<TOutput>>(...rest: MaybeOptionalOptions<U & QueryOptionsIn<TClientContext, TInput, experimental_LiveQueryOutput<TOutput>, TError, USelectData>>): NoInfer<U & Omit<QueryOptionsBase<experimental_LiveQueryOutput<TOutput>, TError>, keyof U>>;
|
|
273
158
|
/**
|
|
274
159
|
* Generate a **full matching** key for [Infinite Query Options](https://orpc.dev/docs/integrations/tanstack-query#infinite-query-options).
|
|
160
|
+
*
|
|
161
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
275
162
|
*/
|
|
276
|
-
infiniteKey<UPageParam>(
|
|
163
|
+
infiniteKey<UPageParam>(options: Pick<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, InfiniteData<TOutput, UPageParam>, UPageParam>, 'input' | 'initialPageParam' | 'queryKey'>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
|
|
277
164
|
/**
|
|
278
165
|
* Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
|
|
166
|
+
*
|
|
167
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
279
168
|
*/
|
|
280
|
-
infiniteOptions<UPageParam, USelectData = InfiniteData<TOutput, UPageParam
|
|
169
|
+
infiniteOptions<U, UPageParam, USelectData = InfiniteData<TOutput, UPageParam>>(options: U & InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam>): NoInfer<U & Omit<InfiniteOptionsBase<TOutput, TError, UPageParam>, keyof U>>;
|
|
281
170
|
/**
|
|
282
171
|
* Generate a **full matching** key for [Mutation Options](https://orpc.dev/docs/integrations/tanstack-query#mutation-options).
|
|
172
|
+
*
|
|
173
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
283
174
|
*/
|
|
284
|
-
mutationKey(
|
|
175
|
+
mutationKey(options?: Pick<MutationOptionsIn<TClientContext, TInput, TOutput, TError, any>, 'mutationKey'>): DataTag<QueryKey, TOutput, TError>;
|
|
285
176
|
/**
|
|
286
177
|
* Generate options used for useMutation/...
|
|
178
|
+
*
|
|
179
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
287
180
|
*/
|
|
288
|
-
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<
|
|
181
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
|
|
289
182
|
}
|
|
290
|
-
|
|
291
|
-
interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
183
|
+
interface experimental_ProcedureUtilsDefaults<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
292
184
|
/**
|
|
293
|
-
*
|
|
294
|
-
* Called once per plugin instance during composition.
|
|
295
|
-
*
|
|
296
|
-
* This method allows plugins to wrap, extend, or transform router utils options,
|
|
297
|
-
* such as interceptors or configuration.
|
|
298
|
-
*
|
|
299
|
-
* @param options - The current router utils options from previous plugins or base configuration
|
|
300
|
-
* @returns Transformed router utils options with this plugin's modifications applied
|
|
185
|
+
* Default options for queryKey utility
|
|
301
186
|
*
|
|
302
|
-
* @
|
|
303
|
-
* ```ts
|
|
304
|
-
* init(options) {
|
|
305
|
-
* return {
|
|
306
|
-
* ...options,
|
|
307
|
-
* mutationInterceptors: [...(options.mutationInterceptors ?? []), myInterceptor]
|
|
308
|
-
* }
|
|
309
|
-
* }
|
|
310
|
-
* ```
|
|
187
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
311
188
|
*/
|
|
312
|
-
|
|
189
|
+
queryKey?: Partial<QueryKeyOptions<TInput>>;
|
|
313
190
|
/**
|
|
314
|
-
*
|
|
315
|
-
* Called once per procedure utils instance during composition.
|
|
191
|
+
* Default options for queryOptions utility
|
|
316
192
|
*
|
|
317
|
-
*
|
|
318
|
-
* such as query or mutation options, for the current path.
|
|
319
|
-
*
|
|
320
|
-
* @param path - The current procedure path
|
|
321
|
-
* @param options - The merged procedure utils options for the current procedure
|
|
322
|
-
* @returns Transformed procedure utils options with this plugin's modifications applied
|
|
193
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
|
|
323
194
|
*/
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
declare class CompositeRouterUtilsPlugin<T extends AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
327
|
-
protected readonly plugins: RouterUtilsPlugin<T>[];
|
|
328
|
-
readonly name = "~composite";
|
|
329
|
-
constructor(plugins?: RouterUtilsPlugin<T>[]);
|
|
330
|
-
init(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
331
|
-
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
335
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
336
|
-
} & Public<SharedUtils<unknown>>;
|
|
337
|
-
type RouterUtilsScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtilsOptions<UClientContext, UInput, UOutput, UError> : {
|
|
338
|
-
[K in keyof T]?: T[K] extends AnyNestedClient ? RouterUtilsScoped<T[K]> : never;
|
|
339
|
-
};
|
|
340
|
-
interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyPrefixOptions {
|
|
195
|
+
queryOptions?: Partial<QueryOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
341
196
|
/**
|
|
342
|
-
*
|
|
197
|
+
* Default options for experimental_streamedKey utility
|
|
343
198
|
*
|
|
344
|
-
* @
|
|
199
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
345
200
|
*/
|
|
346
|
-
|
|
201
|
+
experimental_streamedKey?: Partial<experimental_StreamedKeyOptions<TInput>>;
|
|
347
202
|
/**
|
|
348
|
-
*
|
|
203
|
+
* Default options for experimental_streamedOptions utility
|
|
204
|
+
*
|
|
205
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
349
206
|
*/
|
|
350
|
-
|
|
207
|
+
experimental_streamedOptions?: Partial<experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, unknown>>;
|
|
351
208
|
/**
|
|
352
|
-
*
|
|
209
|
+
* Default options for experimental_liveKey utility
|
|
210
|
+
*
|
|
211
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
353
212
|
*/
|
|
354
|
-
|
|
213
|
+
experimental_liveKey?: Partial<QueryKeyOptions<TInput>>;
|
|
355
214
|
/**
|
|
356
|
-
*
|
|
215
|
+
* Default options for experimental_liveOptions utility
|
|
216
|
+
*
|
|
217
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
357
218
|
*/
|
|
358
|
-
|
|
219
|
+
experimental_liveOptions?: Partial<QueryOptionsIn<TClientContext, TInput, experimental_LiveQueryOutput<TOutput>, TError, unknown>>;
|
|
359
220
|
/**
|
|
360
|
-
*
|
|
221
|
+
* Default options for infiniteKey utility
|
|
222
|
+
*
|
|
223
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
361
224
|
*/
|
|
362
|
-
|
|
225
|
+
infiniteKey?: Partial<Pick<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, InfiniteData<TOutput, unknown>, unknown>, 'input' | 'initialPageParam' | 'queryKey'>>;
|
|
363
226
|
/**
|
|
364
|
-
*
|
|
227
|
+
* Default options for infiniteOptions utility
|
|
228
|
+
*
|
|
229
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
365
230
|
*/
|
|
366
|
-
|
|
231
|
+
infiniteOptions?: Partial<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown>>;
|
|
367
232
|
/**
|
|
368
|
-
*
|
|
369
|
-
*
|
|
370
|
-
*
|
|
233
|
+
* Default options for mutationKey utility
|
|
234
|
+
*
|
|
235
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
371
236
|
*/
|
|
372
|
-
|
|
237
|
+
mutationKey?: Partial<Pick<MutationOptionsIn<TClientContext, TInput, TOutput, TError, any>, 'mutationKey'>>;
|
|
373
238
|
/**
|
|
374
|
-
*
|
|
239
|
+
* Default options for mutationOptions utility
|
|
240
|
+
*
|
|
241
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
375
242
|
*/
|
|
376
|
-
|
|
243
|
+
mutationOptions?: Partial<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
377
244
|
}
|
|
378
245
|
/**
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
* @info Both client-side and server-side clients are supported.
|
|
246
|
+
* @todo remove default generic types on v2
|
|
382
247
|
*/
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
<T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
|
|
387
|
-
}
|
|
388
|
-
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
389
|
-
}
|
|
390
|
-
declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
391
|
-
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
392
|
-
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
393
|
-
}
|
|
394
|
-
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'path'> {
|
|
248
|
+
interface CreateProcedureUtilsOptions<TClientContext extends ClientContext = ClientContext, TInput = unknown, TOutput = unknown, TError = unknown> {
|
|
249
|
+
path: readonly string[];
|
|
250
|
+
experimental_defaults?: experimental_ProcedureUtilsDefaults<TClientContext, TInput, TOutput, TError>;
|
|
395
251
|
}
|
|
396
|
-
declare function
|
|
252
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
397
253
|
|
|
398
|
-
type
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
254
|
+
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
|
255
|
+
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
256
|
+
} & GeneralUtils<unknown>;
|
|
257
|
+
type experimental_RouterUtilsDefaults<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? experimental_ProcedureUtilsDefaults<UClientContext, UInput, UOutput, UError> : {
|
|
258
|
+
[K in keyof T]?: T[K] extends NestedClient<any> ? experimental_RouterUtilsDefaults<T[K]> : never;
|
|
259
|
+
};
|
|
402
260
|
/**
|
|
403
|
-
*
|
|
404
|
-
* Applied multiple times, later options are spread-merged with higher priority
|
|
405
|
-
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
406
|
-
* resets the value from earlier applications instead of merging.
|
|
407
|
-
*
|
|
408
|
-
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
409
|
-
*
|
|
410
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin Docs}
|
|
261
|
+
* @todo remove default generic types on v2
|
|
411
262
|
*/
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
};
|
|
417
|
-
}): TanstackQueryMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
263
|
+
interface CreateRouterUtilsOptions<T extends NestedClient<any> = NestedClient<any>> {
|
|
264
|
+
path?: readonly string[];
|
|
265
|
+
experimental_defaults?: experimental_RouterUtilsDefaults<T>;
|
|
266
|
+
}
|
|
418
267
|
/**
|
|
419
|
-
*
|
|
420
|
-
* on the given router contract. Meta options act as the base layer: options defined
|
|
421
|
-
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
422
|
-
*
|
|
423
|
-
* The contract shape must match the client the utils are created from,
|
|
424
|
-
* so pass the root router contract when utils paths start from the root.
|
|
268
|
+
* Create a router utils from a client.
|
|
425
269
|
*
|
|
426
|
-
* @
|
|
270
|
+
* @info Both client-side and server-side clients are supported.
|
|
271
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query Tanstack Query Integration}
|
|
427
272
|
*/
|
|
428
|
-
declare
|
|
429
|
-
private readonly contract;
|
|
430
|
-
readonly name = "~contract-options";
|
|
431
|
-
constructor(contract: RouterContract);
|
|
432
|
-
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
433
|
-
}
|
|
273
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions<T>): RouterUtils<T>;
|
|
434
274
|
|
|
435
|
-
export {
|
|
436
|
-
export type {
|
|
275
|
+
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, experimental_serializableStreamedQuery, generateOperationKey };
|
|
276
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_LiveQueryOutput, experimental_ProcedureUtilsDefaults, experimental_RouterUtilsDefaults, experimental_SerializableStreamedQueryOptions, experimental_StreamedKeyOptions, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|