@orpc/tanstack-query 1.14.6 → 2.0.0-beta.10
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 +78 -87
- package/dist/index.d.mts +249 -151
- package/dist/index.d.ts +249 -151
- package/dist/index.mjs +398 -156
- package/package.json +17 -15
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { ClientContext, Client,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { ClientContext, Client, AnyNestedClient, InferClientContext, InferClientError, ThrowableError } from '@orpc/client';
|
|
2
|
+
import { AnySchema, ErrorMap, ProcedureContract, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap, RouterContractClient, RouterContract, ContractCaller } from '@orpc/contract';
|
|
3
|
+
import { JsonifiedValue, JsonifiedClientError, JsonifiedClient } from '@orpc/openapi';
|
|
4
|
+
import { Promisable, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, Public } from '@orpc/shared';
|
|
5
|
+
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData, MutationFunctionContext } from '@tanstack/query-core';
|
|
4
6
|
|
|
5
|
-
interface
|
|
7
|
+
interface SerializableStreamedQueryOptions {
|
|
6
8
|
/**
|
|
7
|
-
* Determines how data is handled when the query is
|
|
9
|
+
* Determines how data is handled when the query is fetched again
|
|
8
10
|
*
|
|
9
|
-
* - `'reset'`: Clears existing data and
|
|
10
|
-
* - `'append'`:
|
|
11
|
-
* - `'replace'`:
|
|
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.
|
|
12
14
|
*
|
|
13
15
|
* @default 'reset'
|
|
14
16
|
*/
|
|
@@ -26,17 +28,17 @@ interface experimental_SerializableStreamedQueryOptions {
|
|
|
26
28
|
* - Options are serializable
|
|
27
29
|
* - The output is predictable
|
|
28
30
|
*/
|
|
29
|
-
declare function
|
|
31
|
+
declare function serializableStreamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => Promisable<AsyncIterable<TQueryFnData>>, { refetchMode, maxChunks }?: SerializableStreamedQueryOptions): QueryFunction<TQueryFnData[], TQueryKey>;
|
|
30
32
|
|
|
31
|
-
type
|
|
32
|
-
type
|
|
33
|
+
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
34
|
+
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
33
35
|
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
34
36
|
type OperationKeyOptions<TType extends OperationType, TInput> = {
|
|
35
37
|
type?: TType;
|
|
36
38
|
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
37
|
-
fnOptions?: TType extends 'streamed' ?
|
|
39
|
+
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
38
40
|
};
|
|
39
|
-
type OperationKey<TType extends OperationType, TInput> = [path:
|
|
41
|
+
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: OperationKeyOptions<TType, TInput>];
|
|
40
42
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
41
43
|
interface OperationContext {
|
|
42
44
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
@@ -48,229 +50,325 @@ type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
|
48
50
|
input?: TInput | SkipToken;
|
|
49
51
|
} : {
|
|
50
52
|
input: TInput | SkipToken;
|
|
51
|
-
})
|
|
52
|
-
queryKey
|
|
53
|
+
}) | {
|
|
54
|
+
queryKey: QueryKey;
|
|
53
55
|
};
|
|
54
|
-
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> =
|
|
56
|
+
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = (undefined extends TInput ? {
|
|
57
|
+
input?: TInput | SkipToken;
|
|
58
|
+
} : {
|
|
59
|
+
input: TInput | SkipToken;
|
|
60
|
+
}) & (object extends TClientContext ? {
|
|
55
61
|
context?: TClientContext;
|
|
56
62
|
} : {
|
|
57
63
|
context: TClientContext;
|
|
58
|
-
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey'
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
|
64
|
+
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey' | '_defaulted' | '_optimisticResults'> & {
|
|
65
|
+
queryKey?: QueryKey;
|
|
66
|
+
initialData?: TInitialData;
|
|
68
67
|
};
|
|
69
|
-
type
|
|
70
|
-
|
|
68
|
+
type QueryOptionsOut<TOutput, TError, TSelectData, TInitialData> = Pick<QueryObserverOptions<TOutput, TError, TSelectData, TOutput, DataTag<QueryKey, TOutput, TError>>, 'queryKey' | 'throwOnError' | 'select' | 'retryDelay'> & (undefined extends TInitialData ? object : {
|
|
69
|
+
initialData: TInitialData;
|
|
70
|
+
}) & {
|
|
71
|
+
queryFn: QueryFunction<TOutput, DataTag<QueryKey, TOutput, TError>>;
|
|
71
72
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
|
|
74
|
+
input?: TInput | SkipToken;
|
|
75
|
+
} : {
|
|
76
|
+
input: TInput | SkipToken;
|
|
77
|
+
}) & {
|
|
78
|
+
queryFnOptions?: SerializableStreamedQueryOptions;
|
|
79
|
+
}) | {
|
|
80
|
+
queryKey: QueryKey;
|
|
81
|
+
};
|
|
82
|
+
type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData> & {
|
|
83
|
+
queryFnOptions?: SerializableStreamedQueryOptions;
|
|
84
|
+
};
|
|
85
|
+
type StreamedOptionsOut<TOutput, TError, TSelectData, TInitialData> = QueryOptionsOut<TOutput, TError, TSelectData, TInitialData>;
|
|
86
|
+
type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, any, TPageParam, any>, 'input' | 'initialPageParam'> | {
|
|
87
|
+
queryKey: QueryKey;
|
|
88
|
+
};
|
|
89
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam, TInitialData> = {
|
|
75
90
|
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
76
|
-
|
|
91
|
+
initialData?: TInitialData;
|
|
92
|
+
queryKey?: QueryKey;
|
|
93
|
+
} & (object extends TClientContext ? {
|
|
77
94
|
context?: TClientContext;
|
|
78
95
|
} : {
|
|
79
96
|
context: TClientContext;
|
|
80
|
-
}) &
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (Record<never, never> extends TClientContext ? {
|
|
97
|
+
}) & Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | '_defaulted' | '_optimisticResults'>;
|
|
98
|
+
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 : {
|
|
99
|
+
initialData: TInitialData;
|
|
100
|
+
}) & {
|
|
101
|
+
queryFn: QueryFunction<TOutput, DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>, TPageParam>;
|
|
102
|
+
};
|
|
103
|
+
type MutationKeyOptions = Pick<MutationOptionsIn<any, any, any, any, any>, 'mutationKey'>;
|
|
104
|
+
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (object extends TClientContext ? {
|
|
90
105
|
context?: TClientContext;
|
|
91
106
|
} : {
|
|
92
107
|
context: TClientContext;
|
|
93
|
-
}) &
|
|
94
|
-
type
|
|
108
|
+
}) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
|
|
109
|
+
type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
|
|
95
110
|
|
|
111
|
+
interface ProcedureUtilsQueryInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
112
|
+
path: string[];
|
|
113
|
+
context: TClientContext & OperationContext;
|
|
114
|
+
input: TInput | SkipToken;
|
|
115
|
+
fnContext: QueryFunctionContext;
|
|
116
|
+
}
|
|
117
|
+
type ProcedureUtilsQueryInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
118
|
+
interface ProcedureUtilsStreamedInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
119
|
+
}
|
|
120
|
+
type ProcedureUtilsStreamedInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsStreamedInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferStreamedQueryOutput<TOutput>, TError>>;
|
|
121
|
+
interface ProcedureUtilsLiveInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
122
|
+
}
|
|
123
|
+
type ProcedureUtilsLiveInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsLiveInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferLiveQueryOutput<TOutput>, TError>>;
|
|
124
|
+
interface ProcedureUtilsInfiniteInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
125
|
+
fnContext: QueryFunctionContext<QueryKey, any>;
|
|
126
|
+
}
|
|
127
|
+
type ProcedureUtilsInfiniteInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsInfiniteInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
128
|
+
interface ProcedureUtilsMutationInterceptorOptions<TClientContext extends ClientContext, TInput> extends Omit<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, 'input' | 'fnContext'> {
|
|
129
|
+
input: TInput;
|
|
130
|
+
fnContext: MutationFunctionContext;
|
|
131
|
+
}
|
|
132
|
+
type ProcedureUtilsMutationInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsMutationInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
96
133
|
/**
|
|
97
|
-
*
|
|
134
|
+
* Can be partial options for spread-merged options,
|
|
135
|
+
* or a function that receives per-call options and returns overridden this.options.
|
|
98
136
|
*/
|
|
99
|
-
|
|
137
|
+
type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
|
|
138
|
+
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
100
139
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
140
|
+
* Key options modifier for .queryKey and .queryOptions
|
|
141
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
104
142
|
*/
|
|
105
|
-
|
|
143
|
+
queryKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>>;
|
|
144
|
+
/**
|
|
145
|
+
* Interceptors that intercept queryFn inside .queryOptions, guaranteed to be executed.
|
|
146
|
+
*/
|
|
147
|
+
queryInterceptors?: ProcedureUtilsQueryInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
148
|
+
/**
|
|
149
|
+
* Options modifier for .queryOptions
|
|
150
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
151
|
+
*/
|
|
152
|
+
queryOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown>>;
|
|
153
|
+
/**
|
|
154
|
+
* Key options modifier for .streamedKey and .streamedOptions
|
|
155
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
156
|
+
*/
|
|
157
|
+
streamedKey?: ProcedureUtilsModifier<StreamedKeyOptions<TInput>>;
|
|
158
|
+
/**
|
|
159
|
+
* Interceptors that intercept queryFn inside .streamedOptions, guaranteed to be executed.
|
|
160
|
+
*/
|
|
161
|
+
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
162
|
+
/**
|
|
163
|
+
* Options modifier for .streamedOptions
|
|
164
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
165
|
+
*/
|
|
166
|
+
streamedOptions?: ProcedureUtilsModifier<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, unknown, unknown>>;
|
|
167
|
+
/**
|
|
168
|
+
* Key options modifier for .liveKey and .liveOptions
|
|
169
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
170
|
+
*/
|
|
171
|
+
liveKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>>;
|
|
172
|
+
/**
|
|
173
|
+
* Interceptors that intercept queryFn inside .liveOptions, guaranteed to be executed.
|
|
174
|
+
*/
|
|
175
|
+
liveInterceptors?: ProcedureUtilsLiveInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
176
|
+
/**
|
|
177
|
+
* Options modifier for .liveOptions
|
|
178
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
179
|
+
*/
|
|
180
|
+
liveOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, unknown, unknown>>;
|
|
181
|
+
/**
|
|
182
|
+
* Key options modifier for .infiniteKey and .infiniteOptions
|
|
183
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
184
|
+
*/
|
|
185
|
+
infiniteKey?: ProcedureUtilsModifier<InfiniteKeyOptions<TInput, unknown>>;
|
|
186
|
+
/**
|
|
187
|
+
* Interceptors that intercept queryFn inside .infiniteOptions, guaranteed to be executed.
|
|
188
|
+
*/
|
|
189
|
+
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
190
|
+
/**
|
|
191
|
+
* Options modifier for .infiniteOptions
|
|
192
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
193
|
+
*/
|
|
194
|
+
infiniteOptions?: ProcedureUtilsModifier<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown, unknown>>;
|
|
195
|
+
/**
|
|
196
|
+
* Key options modifier for .mutationKey and .mutationOptions
|
|
197
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
198
|
+
*/
|
|
199
|
+
mutationKey?: ProcedureUtilsModifier<MutationKeyOptions>;
|
|
200
|
+
/**
|
|
201
|
+
* Interceptors that intercept mutationFn inside .mutationOptions, guaranteed to be executed.
|
|
202
|
+
*/
|
|
203
|
+
mutationInterceptors?: ProcedureUtilsMutationInterceptor<TClientContext, TInput, TOutput, TError>[];
|
|
204
|
+
/**
|
|
205
|
+
* Options modifier for .mutationOptions
|
|
206
|
+
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
207
|
+
*/
|
|
208
|
+
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
106
209
|
}
|
|
107
|
-
declare
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
210
|
+
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
211
|
+
private readonly path;
|
|
212
|
+
private readonly options;
|
|
112
213
|
/**
|
|
113
214
|
* Calling corresponding procedure client
|
|
114
|
-
*
|
|
115
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#calling-clients Tanstack Calling Procedure Client Docs}
|
|
116
215
|
*/
|
|
117
216
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
217
|
+
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>);
|
|
118
218
|
/**
|
|
119
219
|
* 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}
|
|
122
220
|
*/
|
|
123
221
|
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, TOutput, TError>;
|
|
124
222
|
/**
|
|
125
223
|
* 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}
|
|
128
224
|
*/
|
|
129
|
-
queryOptions<
|
|
225
|
+
queryOptions<USelectData = TOutput, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<TOutput, TError, USelectData, UInitialData>>;
|
|
130
226
|
/**
|
|
131
227
|
* 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}
|
|
134
228
|
*/
|
|
135
|
-
|
|
229
|
+
streamedKey(...rest: MaybeOptionalOptions<StreamedKeyOptions<TInput>>): DataTag<QueryKey, InferStreamedQueryOutput<TOutput>, TError>;
|
|
136
230
|
/**
|
|
137
231
|
* Configure queries for [Event Iterator](https://orpc.dev/docs/event-iterator).
|
|
138
232
|
* This is built on [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
139
233
|
* 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}
|
|
142
234
|
*/
|
|
143
|
-
|
|
235
|
+
streamedOptions<USelectData = InferStreamedQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<StreamedOptionsOut<InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
144
236
|
/**
|
|
145
237
|
* 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}
|
|
148
238
|
*/
|
|
149
|
-
|
|
239
|
+
liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, InferLiveQueryOutput<TOutput>, TError>;
|
|
150
240
|
/**
|
|
151
241
|
* Configure live queries for [Event Iterator](https://orpc.dev/docs/event-iterator).
|
|
152
242
|
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
153
243
|
* 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}
|
|
156
244
|
*/
|
|
157
|
-
|
|
245
|
+
liveOptions<USelectData = InferLiveQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
158
246
|
/**
|
|
159
247
|
* 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}
|
|
162
248
|
*/
|
|
163
|
-
infiniteKey<UPageParam>(
|
|
249
|
+
infiniteKey<UPageParam>(optionsIn: InfiniteKeyOptions<TInput, UPageParam>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
|
|
164
250
|
/**
|
|
165
251
|
* 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}
|
|
168
252
|
*/
|
|
169
|
-
infiniteOptions<
|
|
253
|
+
infiniteOptions<UPageParam, USelectData = InfiniteData<TOutput, UPageParam>, UInitialData = undefined>(optionsIn: InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam, UInitialData>): NoInfer<InfiniteOptionsOut<TOutput, TError, USelectData, UPageParam, UInitialData>>;
|
|
170
254
|
/**
|
|
171
255
|
* 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}
|
|
174
256
|
*/
|
|
175
|
-
mutationKey(
|
|
257
|
+
mutationKey(optionsIn?: MutationKeyOptions): DataTag<QueryKey, TOutput, TError>;
|
|
176
258
|
/**
|
|
177
259
|
* Generate options used for useMutation/...
|
|
178
|
-
*
|
|
179
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
180
260
|
*/
|
|
181
|
-
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<
|
|
261
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptionsOut<TInput, TOutput, TError, UMutationContext>>;
|
|
182
262
|
}
|
|
183
|
-
|
|
263
|
+
|
|
264
|
+
interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
184
265
|
/**
|
|
185
|
-
*
|
|
266
|
+
* Initializes the router utils plugin and returns updated router utils options.
|
|
267
|
+
* Called once per plugin instance during composition.
|
|
268
|
+
*
|
|
269
|
+
* This method allows plugins to wrap, extend, or transform router utils options,
|
|
270
|
+
* such as interceptors or configuration.
|
|
186
271
|
*
|
|
187
|
-
* @
|
|
272
|
+
* @param options - The current router utils options from previous plugins or base configuration
|
|
273
|
+
* @returns Transformed router utils options with this plugin's modifications applied
|
|
274
|
+
*
|
|
275
|
+
* @example
|
|
276
|
+
* ```ts
|
|
277
|
+
* init(options) {
|
|
278
|
+
* return {
|
|
279
|
+
* ...options,
|
|
280
|
+
* mutationInterceptors: [...(options.mutationInterceptors ?? []), myInterceptor]
|
|
281
|
+
* }
|
|
282
|
+
* }
|
|
283
|
+
* ```
|
|
188
284
|
*/
|
|
189
|
-
|
|
285
|
+
init?(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
190
286
|
/**
|
|
191
|
-
*
|
|
287
|
+
* Initializes per-procedure router utils options and returns updated options.
|
|
288
|
+
* Called once per procedure utils instance during composition.
|
|
289
|
+
*
|
|
290
|
+
* This method allows plugins to customize merged procedure-specific defaults,
|
|
291
|
+
* such as query or mutation options, for the current path.
|
|
192
292
|
*
|
|
193
|
-
* @
|
|
293
|
+
* @param path - The current procedure path
|
|
294
|
+
* @param options - The merged procedure utils options for the current procedure
|
|
295
|
+
* @returns Transformed procedure utils options with this plugin's modifications applied
|
|
194
296
|
*/
|
|
195
|
-
|
|
297
|
+
initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
declare class SharedRouterUtils<TInput> {
|
|
301
|
+
private readonly path;
|
|
302
|
+
constructor(path: string[]);
|
|
196
303
|
/**
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
304
|
+
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
200
305
|
*/
|
|
201
|
-
|
|
306
|
+
key<TType extends OperationType>(options?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
307
|
+
}
|
|
308
|
+
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> & Public<SharedRouterUtils<UInput>> : {
|
|
309
|
+
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
310
|
+
} & Public<SharedRouterUtils<unknown>>;
|
|
311
|
+
type RouterUtilsScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtilsOptions<UClientContext, UInput, UOutput, UError> : {
|
|
312
|
+
[K in keyof T]?: T[K] extends AnyNestedClient ? RouterUtilsScoped<T[K]> : never;
|
|
313
|
+
};
|
|
314
|
+
interface RouterUtilsOptions<T extends AnyNestedClient> {
|
|
202
315
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
316
|
+
* Base path for all query keys. Use this to avoid conflicts when mounting
|
|
317
|
+
* multiple router utils instances.
|
|
206
318
|
*/
|
|
207
|
-
|
|
319
|
+
path?: string[] | undefined;
|
|
208
320
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
321
|
+
* Interceptors that intercept queryFn inside .queryOptions
|
|
212
322
|
*/
|
|
213
|
-
|
|
323
|
+
queryInterceptors?: ProcedureUtilsQueryInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
214
324
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
325
|
+
* Interceptors that intercept queryFn inside .streamedOptions
|
|
218
326
|
*/
|
|
219
|
-
|
|
327
|
+
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
220
328
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
329
|
+
* Interceptors that intercept queryFn inside .liveOptions
|
|
224
330
|
*/
|
|
225
|
-
|
|
331
|
+
liveInterceptors?: ProcedureUtilsLiveInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
226
332
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
333
|
+
* Interceptors that intercept queryFn inside .infiniteOptions
|
|
230
334
|
*/
|
|
231
|
-
|
|
335
|
+
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
232
336
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
337
|
+
* Interceptors that intercept mutationFn inside .mutationOptions
|
|
236
338
|
*/
|
|
237
|
-
|
|
339
|
+
mutationInterceptors?: ProcedureUtilsMutationInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
238
340
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
341
|
+
* Per-procedure options following the shape of the router.
|
|
342
|
+
* Allows fine-grained configuration of individual procedure utils
|
|
343
|
+
* without affecting the rest of the router.
|
|
242
344
|
*/
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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>;
|
|
251
|
-
}
|
|
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>;
|
|
253
|
-
|
|
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
|
-
};
|
|
260
|
-
/**
|
|
261
|
-
* @todo remove default generic types on v2
|
|
262
|
-
*/
|
|
263
|
-
interface CreateRouterUtilsOptions<T extends NestedClient<any> = NestedClient<any>> {
|
|
264
|
-
path?: readonly string[];
|
|
265
|
-
experimental_defaults?: experimental_RouterUtilsDefaults<T>;
|
|
345
|
+
scoped?: RouterUtilsScoped<T> | undefined;
|
|
346
|
+
/**
|
|
347
|
+
* Plugins to extend router utils behavior.
|
|
348
|
+
*/
|
|
349
|
+
plugins?: RouterUtilsPlugin<T>[] | undefined;
|
|
266
350
|
}
|
|
267
351
|
/**
|
|
268
352
|
* Create a router utils from a client.
|
|
269
353
|
*
|
|
270
354
|
* @info Both client-side and server-side clients are supported.
|
|
271
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query Tanstack Query Integration}
|
|
272
355
|
*/
|
|
273
|
-
declare function createRouterUtils<T extends
|
|
356
|
+
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
|
|
357
|
+
|
|
358
|
+
interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
359
|
+
<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(procedure: ProcedureContract<TInputSchema, TOutputSchema, TErrorMap>): Public<SharedRouterUtils<InferSchemaInput<TInputSchema>>> & Public<ProcedureUtils<TClientContext, InferSchemaInput<TInputSchema>, InferSchemaOutput<TOutputSchema>, ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
|
|
360
|
+
}
|
|
361
|
+
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>> {
|
|
362
|
+
}
|
|
363
|
+
declare function createContractUtilsFactory<TClientContext extends ClientContext>(caller: ContractCaller<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
364
|
+
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
365
|
+
<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap>(procedure: ProcedureContract<TInputSchema, TOutputSchema, TErrorMap>): SharedRouterUtils<InferSchemaInput<TInputSchema>> & ProcedureUtils<TClientContext, InferSchemaInput<TInputSchema>, JsonifiedValue<InferSchemaOutput<TOutputSchema>>, JsonifiedClientError<ORPCErrorFromErrorMap<TErrorMap> | ThrowableError>>;
|
|
366
|
+
}
|
|
367
|
+
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>> {
|
|
368
|
+
}
|
|
369
|
+
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(caller: ContractCaller<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
370
|
+
|
|
371
|
+
declare function generateOperationKey<TType extends OperationType, TInput>(path: string[], state?: OperationKeyOptions<TType, TInput>): OperationKey<TType, TInput>;
|
|
274
372
|
|
|
275
|
-
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL,
|
|
276
|
-
export type {
|
|
373
|
+
export { OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedRouterUtils, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createRouterUtils, createRouterUtils as createTanstackQueryUtils, generateOperationKey, serializableStreamedQuery };
|
|
374
|
+
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, OperationContext as TanstackQueryOperationContext };
|