@orpc/tanstack-query 1.14.10 → 1.14.11
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 +52 -48
- package/dist/index.d.mts +312 -152
- package/dist/index.d.ts +312 -152
- package/dist/index.mjs +484 -165
- package/package.json +17 -15
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { ClientContext, Client,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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';
|
|
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,11 @@ 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
|
-
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>];
|
|
40
36
|
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
41
37
|
interface OperationContext {
|
|
42
38
|
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
@@ -48,229 +44,393 @@ type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
|
48
44
|
input?: TInput | SkipToken;
|
|
49
45
|
} : {
|
|
50
46
|
input: TInput | SkipToken;
|
|
51
|
-
})
|
|
52
|
-
queryKey
|
|
47
|
+
}) | {
|
|
48
|
+
queryKey: QueryKey;
|
|
53
49
|
};
|
|
54
|
-
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData> =
|
|
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 ? {
|
|
55
55
|
context?: TClientContext;
|
|
56
56
|
} : {
|
|
57
57
|
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;
|
|
58
|
+
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey' | '_defaulted' | '_optimisticResults'> & {
|
|
59
|
+
queryKey?: QueryKey;
|
|
60
|
+
initialData?: TInitialData;
|
|
68
61
|
};
|
|
69
|
-
type
|
|
70
|
-
|
|
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>>;
|
|
71
66
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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;
|
|
78
|
+
};
|
|
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;
|
|
82
|
+
};
|
|
83
|
+
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam, TInitialData> = {
|
|
75
84
|
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
76
|
-
|
|
85
|
+
initialData?: TInitialData;
|
|
86
|
+
queryKey?: QueryKey;
|
|
87
|
+
} & (object extends TClientContext ? {
|
|
77
88
|
context?: TClientContext;
|
|
78
89
|
} : {
|
|
79
90
|
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 ? {
|
|
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 ? {
|
|
90
99
|
context?: TClientContext;
|
|
91
100
|
} : {
|
|
92
101
|
context: TClientContext;
|
|
93
|
-
}) &
|
|
94
|
-
type
|
|
102
|
+
}) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
|
|
103
|
+
type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
|
|
95
104
|
|
|
96
|
-
|
|
97
|
-
* Utils at any level (procedure or router)
|
|
98
|
-
*/
|
|
99
|
-
interface GeneralUtils<TInput> {
|
|
105
|
+
interface OperationKeyPrefixOptions {
|
|
100
106
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
103
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
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.
|
|
104
109
|
*/
|
|
105
|
-
|
|
110
|
+
prefix?: string;
|
|
106
111
|
}
|
|
107
|
-
|
|
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>;
|
|
108
119
|
|
|
109
|
-
declare
|
|
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
|
+
}
|
|
110
129
|
|
|
111
|
-
interface
|
|
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
|
+
/**
|
|
153
|
+
* Can be partial options for spread-merged options,
|
|
154
|
+
* or a function that receives per-call options and returns overridden this.options.
|
|
155
|
+
*/
|
|
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>>;
|
|
200
|
+
/**
|
|
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.
|
|
226
|
+
*/
|
|
227
|
+
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
228
|
+
}
|
|
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>;
|
|
112
240
|
/**
|
|
113
241
|
* Calling corresponding procedure client
|
|
114
|
-
*
|
|
115
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#calling-clients Tanstack Calling Procedure Client Docs}
|
|
116
242
|
*/
|
|
117
243
|
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
244
|
+
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>);
|
|
118
245
|
/**
|
|
119
246
|
* 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
247
|
*/
|
|
123
248
|
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, TOutput, TError>;
|
|
124
249
|
/**
|
|
125
250
|
* 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
251
|
*/
|
|
129
|
-
queryOptions<
|
|
252
|
+
queryOptions<USelectData = TOutput, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<TOutput, TError, USelectData, UInitialData>>;
|
|
130
253
|
/**
|
|
131
254
|
* 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
255
|
*/
|
|
135
|
-
|
|
256
|
+
streamedKey(...rest: MaybeOptionalOptions<StreamedKeyOptions<TInput>>): DataTag<QueryKey, InferStreamedQueryOutput<TOutput>, TError>;
|
|
136
257
|
/**
|
|
137
|
-
* Configure queries for [
|
|
258
|
+
* Configure queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
|
|
138
259
|
* This is built on [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
139
260
|
* 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
261
|
*/
|
|
143
|
-
|
|
262
|
+
streamedOptions<USelectData = InferStreamedQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<StreamedOptionsOut<InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
144
263
|
/**
|
|
145
264
|
* 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
265
|
*/
|
|
149
|
-
|
|
266
|
+
liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, InferLiveQueryOutput<TOutput>, TError>;
|
|
150
267
|
/**
|
|
151
|
-
* Configure live queries for [
|
|
268
|
+
* Configure live queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
|
|
152
269
|
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
153
270
|
* 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
271
|
*/
|
|
157
|
-
|
|
272
|
+
liveOptions<USelectData = InferLiveQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
158
273
|
/**
|
|
159
274
|
* 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
275
|
*/
|
|
163
|
-
infiniteKey<UPageParam>(
|
|
276
|
+
infiniteKey<UPageParam>(optionsIn: InfiniteKeyOptions<TInput, UPageParam>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
|
|
164
277
|
/**
|
|
165
278
|
* 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
279
|
*/
|
|
169
|
-
infiniteOptions<
|
|
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>>;
|
|
170
281
|
/**
|
|
171
282
|
* 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
283
|
*/
|
|
175
|
-
mutationKey(
|
|
284
|
+
mutationKey(optionsIn?: MutationKeyOptions): DataTag<QueryKey, TOutput, TError>;
|
|
176
285
|
/**
|
|
177
286
|
* Generate options used for useMutation/...
|
|
178
|
-
*
|
|
179
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
180
287
|
*/
|
|
181
|
-
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<
|
|
288
|
+
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptionsOut<TInput, TOutput, TError, UMutationContext>>;
|
|
182
289
|
}
|
|
183
|
-
|
|
290
|
+
|
|
291
|
+
interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
184
292
|
/**
|
|
185
|
-
*
|
|
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
|
|
186
301
|
*
|
|
187
|
-
* @
|
|
302
|
+
* @example
|
|
303
|
+
* ```ts
|
|
304
|
+
* init(options) {
|
|
305
|
+
* return {
|
|
306
|
+
* ...options,
|
|
307
|
+
* mutationInterceptors: [...(options.mutationInterceptors ?? []), myInterceptor]
|
|
308
|
+
* }
|
|
309
|
+
* }
|
|
310
|
+
* ```
|
|
188
311
|
*/
|
|
189
|
-
|
|
312
|
+
init?(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
190
313
|
/**
|
|
191
|
-
*
|
|
314
|
+
* Initializes per-procedure router utils options and returns updated options.
|
|
315
|
+
* Called once per procedure utils instance during composition.
|
|
192
316
|
*
|
|
193
|
-
*
|
|
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
|
|
194
323
|
*/
|
|
195
|
-
|
|
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 {
|
|
196
341
|
/**
|
|
197
|
-
*
|
|
342
|
+
* Base path for all query keys.
|
|
198
343
|
*
|
|
199
|
-
* @
|
|
344
|
+
* @internal
|
|
200
345
|
*/
|
|
201
|
-
|
|
346
|
+
path?: string[] | undefined;
|
|
202
347
|
/**
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
348
|
+
* Interceptors that intercept queryFn inside .queryOptions
|
|
206
349
|
*/
|
|
207
|
-
|
|
350
|
+
queryInterceptors?: ProcedureUtilsQueryInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
208
351
|
/**
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
352
|
+
* Interceptors that intercept queryFn inside .streamedOptions
|
|
212
353
|
*/
|
|
213
|
-
|
|
354
|
+
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
214
355
|
/**
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
356
|
+
* Interceptors that intercept queryFn inside .liveOptions
|
|
218
357
|
*/
|
|
219
|
-
|
|
358
|
+
liveInterceptors?: ProcedureUtilsLiveInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
220
359
|
/**
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
360
|
+
* Interceptors that intercept queryFn inside .infiniteOptions
|
|
224
361
|
*/
|
|
225
|
-
|
|
362
|
+
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
226
363
|
/**
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
364
|
+
* Interceptors that intercept mutationFn inside .mutationOptions
|
|
230
365
|
*/
|
|
231
|
-
|
|
366
|
+
mutationInterceptors?: ProcedureUtilsMutationInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
232
367
|
/**
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
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.
|
|
236
371
|
*/
|
|
237
|
-
|
|
372
|
+
scoped?: RouterUtilsScoped<T> | undefined;
|
|
238
373
|
/**
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
374
|
+
* Plugins to extend router utils behavior.
|
|
242
375
|
*/
|
|
243
|
-
|
|
376
|
+
plugins?: RouterUtilsPlugin<T>[] | undefined;
|
|
244
377
|
}
|
|
245
378
|
/**
|
|
246
|
-
*
|
|
379
|
+
* Create a router utils from a client.
|
|
380
|
+
*
|
|
381
|
+
* @info Both client-side and server-side clients are supported.
|
|
247
382
|
*/
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
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'> {
|
|
251
395
|
}
|
|
252
|
-
declare function
|
|
396
|
+
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
253
397
|
|
|
254
|
-
type
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
[K in keyof T]?: T[K] extends NestedClient<any> ? experimental_RouterUtilsDefaults<T[K]> : never;
|
|
259
|
-
};
|
|
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
|
+
}
|
|
260
402
|
/**
|
|
261
|
-
*
|
|
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}
|
|
262
411
|
*/
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
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;
|
|
267
418
|
/**
|
|
268
|
-
*
|
|
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.
|
|
269
422
|
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
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.
|
|
425
|
+
*
|
|
426
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin TanStack Query Contract Options Plugin Docs}
|
|
272
427
|
*/
|
|
273
|
-
declare
|
|
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
|
+
}
|
|
274
434
|
|
|
275
|
-
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL,
|
|
276
|
-
export type {
|
|
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 };
|