@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/dist/index.d.ts CHANGED
@@ -1,16 +1,14 @@
1
- import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError } from '@orpc/client';
2
- import { RouterContract, RouterContractClient, ContractClientFactory, AnySchema, ErrorMap, MetaPlugin, Meta, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
3
- import { JsonifiedClient } from '@orpc/openapi';
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 SerializableStreamedQueryOptions {
5
+ interface experimental_SerializableStreamedQueryOptions {
8
6
  /**
9
- * Determines how data is handled when the query is fetched again
7
+ * Determines how data is handled when the query is refetched.
10
8
  *
11
- * - `'reset'`: Clears existing data and returns the query to a pending state.
12
- * - `'append'`: Adds new streamed chunks to the existing data.
13
- * - `'replace'`: Buffers streamed data and replaces the cache after the stream completes.
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 serializableStreamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => Promisable<AsyncIterable<TQueryFnData>>, { refetchMode, maxChunks }?: SerializableStreamedQueryOptions): QueryFunction<TQueryFnData[], TQueryKey>;
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 InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
34
- type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
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: QueryKey;
51
+ }) & {
52
+ queryKey?: QueryKey;
49
53
  };
50
- type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = (undefined extends TInput ? {
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' | '_defaulted' | '_optimisticResults'> & {
59
- queryKey?: QueryKey;
60
- initialData?: TInitialData;
61
- };
62
- type QueryOptionsOut<TOutput, TError, TSelectData, TInitialData> = Pick<QueryObserverOptions<TOutput, TError, TSelectData, TOutput, DataTag<QueryKey, TOutput, TError>>, 'queryKey' | 'throwOnError' | 'select' | 'retryDelay'> & (undefined extends TInitialData ? object : {
63
- initialData: TInitialData;
64
- }) & {
65
- queryFn: QueryFunction<TOutput, DataTag<QueryKey, TOutput, TError>>;
66
- };
67
- type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
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 StreamedOptionsOut<TOutput, TError, TSelectData, TInitialData> = QueryOptionsOut<TOutput, TError, TSelectData, TInitialData>;
80
- type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, any, TPageParam, any>, 'input' | 'initialPageParam'> | {
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
- type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam, TInitialData> = {
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
- initialData?: TInitialData;
86
- queryKey?: QueryKey;
87
- } & (object extends TClientContext ? {
76
+ } & (Record<never, never> extends TClientContext ? {
88
77
  context?: TClientContext;
89
78
  } : {
90
79
  context: TClientContext;
91
- }) & Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | '_defaulted' | '_optimisticResults'>;
92
- type InfiniteOptionsOut<TOutput, TError, TSelectData, TPageParam, TInitialData> = Pick<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>, TPageParam>, 'queryKey' | 'select' | 'throwOnError' | 'retryDelay' | 'initialPageParam' | 'getNextPageParam' | 'getPreviousPageParam'> & (undefined extends TInitialData ? object : {
93
- initialData: TInitialData;
94
- }) & {
95
- queryFn: QueryFunction<TOutput, DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>, TPageParam>;
96
- };
97
- type MutationKeyOptions = Pick<MutationOptionsIn<any, any, any, any, any>, 'mutationKey'>;
98
- type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (object extends TClientContext ? {
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
- }) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
103
- type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
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
- * Can be partial options for spread-merged options,
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
- type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
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
- * Key options modifier for .infiniteKey and .infiniteOptions
202
- * Can be partial options or a function that receives per-call options and returns override this.options.
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
- mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
105
+ key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
228
106
  }
229
- declare function isProcedureUtilsOptions(value: unknown): value is ProcedureUtilsOptions<any, any, any, any>;
230
- /**
231
- * Merge two procedure utils options where `override` takes priority.
232
- * A key explicitly set to `undefined` in `override` resets the base value.
233
- * When both sides define a key: interceptors are concatenated (base ones run first),
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, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<TOutput, TError, USelectData, UInitialData>>;
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
- streamedKey(...rest: MaybeOptionalOptions<StreamedKeyOptions<TInput>>): DataTag<QueryKey, InferStreamedQueryOutput<TOutput>, TError>;
135
+ experimental_streamedKey(...rest: MaybeOptionalOptions<experimental_StreamedKeyOptions<TInput>>): DataTag<QueryKey, experimental_StreamedQueryOutput<TOutput>, TError>;
257
136
  /**
258
- * Configure queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
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
- streamedOptions<USelectData = InferStreamedQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<StreamedOptionsOut<InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
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
- liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, InferLiveQueryOutput<TOutput>, TError>;
149
+ experimental_liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, experimental_LiveQueryOutput<TOutput>, TError>;
267
150
  /**
268
- * Configure live queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
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
- liveOptions<USelectData = InferLiveQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
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>(optionsIn: InfiniteKeyOptions<TInput, UPageParam>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
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>, UInitialData = undefined>(optionsIn: InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam, UInitialData>): NoInfer<InfiniteOptionsOut<TOutput, TError, USelectData, UPageParam, UInitialData>>;
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(optionsIn?: MutationKeyOptions): DataTag<QueryKey, TOutput, TError>;
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<MutationOptionsOut<TInput, TOutput, TError, UMutationContext>>;
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
- * Initializes the router utils plugin and returns updated router utils options.
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
- * @example
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
- init?(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
189
+ queryKey?: Partial<QueryKeyOptions<TInput>>;
313
190
  /**
314
- * Initializes per-procedure router utils options and returns updated options.
315
- * Called once per procedure utils instance during composition.
191
+ * Default options for queryOptions utility
316
192
  *
317
- * This method allows plugins to customize merged procedure-specific defaults,
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
- initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
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
- * Base path for all query keys.
197
+ * Default options for experimental_streamedKey utility
343
198
  *
344
- * @internal
199
+ * @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
345
200
  */
346
- path?: string[] | undefined;
201
+ experimental_streamedKey?: Partial<experimental_StreamedKeyOptions<TInput>>;
347
202
  /**
348
- * Interceptors that intercept queryFn inside .queryOptions
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
- queryInterceptors?: ProcedureUtilsQueryInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
207
+ experimental_streamedOptions?: Partial<experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, unknown>>;
351
208
  /**
352
- * Interceptors that intercept queryFn inside .streamedOptions
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
- streamedInterceptors?: ProcedureUtilsStreamedInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
213
+ experimental_liveKey?: Partial<QueryKeyOptions<TInput>>;
355
214
  /**
356
- * Interceptors that intercept queryFn inside .liveOptions
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
- liveInterceptors?: ProcedureUtilsLiveInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
219
+ experimental_liveOptions?: Partial<QueryOptionsIn<TClientContext, TInput, experimental_LiveQueryOutput<TOutput>, TError, unknown>>;
359
220
  /**
360
- * Interceptors that intercept queryFn inside .infiniteOptions
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
- infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
225
+ infiniteKey?: Partial<Pick<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, InfiniteData<TOutput, unknown>, unknown>, 'input' | 'initialPageParam' | 'queryKey'>>;
363
226
  /**
364
- * Interceptors that intercept mutationFn inside .mutationOptions
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
- mutationInterceptors?: ProcedureUtilsMutationInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
231
+ infiniteOptions?: Partial<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown>>;
367
232
  /**
368
- * Per-procedure options following the shape of the router.
369
- * Allows fine-grained configuration of individual procedure utils
370
- * without affecting the rest of the router.
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
- scoped?: RouterUtilsScoped<T> | undefined;
237
+ mutationKey?: Partial<Pick<MutationOptionsIn<TClientContext, TInput, TOutput, TError, any>, 'mutationKey'>>;
373
238
  /**
374
- * Plugins to extend router utils behavior.
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
- plugins?: RouterUtilsPlugin<T>[] | undefined;
243
+ mutationOptions?: Partial<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
377
244
  }
378
245
  /**
379
- * Create a router utils from a client.
380
- *
381
- * @info Both client-side and server-side clients are supported.
246
+ * @todo remove default generic types on v2
382
247
  */
383
- declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
384
-
385
- interface ContractUtilsFactory<TClientContext extends ClientContext> {
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 createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
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 TanstackQueryMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, 'prefix'>;
399
- interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
400
- name: '~tanstack-query';
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
- * Define base TanStack Query options and interceptors on a procedure contract.
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
- declare function tanstackQuery<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(options: TanstackQueryMetaOptions<ClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>): TanstackQueryMetaPlugin<TInputSchema, TOutputSchema, TErrorMap>;
413
- declare function getTanstackQueryMeta(procedureOrLazy: {
414
- '~orpc': {
415
- meta: Meta;
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
- * Router utils plugin that applies base options defined via {@link tanstackQuery}
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
- * @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin Docs}
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 class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
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 { CompositeRouterUtilsPlugin, ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, getTanstackQueryMeta, isProcedureUtilsOptions, mergeProcedureUtilsOptions, serializableStreamedQuery, tanstackQuery };
436
- export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, OperationContext as TanstackQueryOperationContext };
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 };