@orpc/tanstack-query 2.0.0-beta.46 → 2.0.0-beta.48
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 +6 -4
- package/dist/contract-utils.d.mts +35 -0
- package/dist/contract-utils.mjs +23 -0
- package/dist/index.d.mts +16 -541
- package/dist/index.mjs +10 -821
- package/dist/key.d.mts +62 -0
- package/dist/key.mjs +30 -0
- package/dist/live-query.d.mts +6 -0
- package/dist/live-query.mjs +16 -0
- package/dist/meta.d.mts +55 -0
- package/dist/meta.mjs +37 -0
- package/dist/plugin.d.mts +51 -0
- package/dist/plugin.mjs +25 -0
- package/dist/procedure-utils.d.mts +232 -0
- package/dist/procedure-utils.mjs +406 -0
- package/dist/router-utils.d.mts +57 -0
- package/dist/router-utils.mjs +51 -0
- package/dist/shared-utils.d.mts +11 -0
- package/dist/shared-utils.mjs +17 -0
- package/dist/ssr.d.mts +38 -0
- package/dist/ssr.mjs +57 -0
- package/dist/stream-query.d.mts +30 -0
- package/dist/stream-query.mjs +58 -0
- package/dist/structural-sharing.d.mts +14 -0
- package/dist/structural-sharing.mjs +140 -0
- package/dist/types.d.mts +138 -0
- package/dist/types.mjs +2 -0
- package/package.json +13 -13
- package/dist/index.d.ts +0 -541
package/dist/index.d.ts
DELETED
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
import { ClientContext, RPCJsonSerializer, Client, AnyNestedClient, InferClientContext, InferClientError, RPCJsonSerialization } from '@orpc/client';
|
|
2
|
-
export { AnyNestedClient } from '@orpc/client';
|
|
3
|
-
import { RouterContract, RouterContractClient, ContractClientFactory, AnySchema, ErrorMap, MetaPlugin, Meta, InferSchemaInput, InferSchemaOutput, ORPCErrorFromErrorMap } from '@orpc/contract';
|
|
4
|
-
import { JsonifiedClient, ContractJsonifiedClientFactory } from '@orpc/openapi';
|
|
5
|
-
import { Public, PartialDeep, Interceptor, PromiseWithError, MaybeOptionalOptions, OrderablePlugin, ThrowableError } from '@orpc/shared';
|
|
6
|
-
export { Public } from '@orpc/shared';
|
|
7
|
-
import { SkipToken, QueryKey, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, QueryFunction, InfiniteData, QueryFunctionContext, MutationFunctionContext } from '@tanstack/query-core';
|
|
8
|
-
|
|
9
|
-
interface SerializableStreamedQueryOptions {
|
|
10
|
-
/**
|
|
11
|
-
* Determines how data is handled when the query is fetched again
|
|
12
|
-
*
|
|
13
|
-
* - `'reset'`: Clears existing data and returns the query to a pending state.
|
|
14
|
-
* - `'append'`: Adds new streamed chunks to the existing data.
|
|
15
|
-
* - `'replace'`: Buffers streamed data and replaces the cache after the stream completes.
|
|
16
|
-
*
|
|
17
|
-
* @default 'reset'
|
|
18
|
-
*/
|
|
19
|
-
refetchMode?: 'append' | 'reset' | 'replace' | undefined;
|
|
20
|
-
/**
|
|
21
|
-
* Limits the number of data chunks stored in the query result.
|
|
22
|
-
* Older chunks are removed when the limit is reached.
|
|
23
|
-
*
|
|
24
|
-
* @default Number.POSITIVE_INFINITY (unlimited)
|
|
25
|
-
*/
|
|
26
|
-
maxChunks?: number | undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
30
|
-
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
31
|
-
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
32
|
-
/**
|
|
33
|
-
* The symbol under which TanStack Query utils attach operation details
|
|
34
|
-
* (key and operation type) to the client context.
|
|
35
|
-
*
|
|
36
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
|
|
37
|
-
*/
|
|
38
|
-
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
39
|
-
/**
|
|
40
|
-
* A client context automatically populated by TanStack Query utils,
|
|
41
|
-
* exposing the operation key and type of the calling operation.
|
|
42
|
-
*
|
|
43
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#client-context | TanStack Query Integration - Client Context}
|
|
44
|
-
*/
|
|
45
|
-
interface OperationContext {
|
|
46
|
-
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
47
|
-
key: QueryKey;
|
|
48
|
-
type: OperationType;
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
52
|
-
input?: TInput | SkipToken;
|
|
53
|
-
} : {
|
|
54
|
-
input: TInput | SkipToken;
|
|
55
|
-
}) | {
|
|
56
|
-
queryKey: QueryKey;
|
|
57
|
-
};
|
|
58
|
-
type QueryOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = (undefined extends TInput ? {
|
|
59
|
-
input?: TInput | SkipToken;
|
|
60
|
-
} : {
|
|
61
|
-
input: TInput | SkipToken;
|
|
62
|
-
}) & (object extends TClientContext ? {
|
|
63
|
-
context?: TClientContext | undefined;
|
|
64
|
-
} : {
|
|
65
|
-
context: TClientContext;
|
|
66
|
-
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey' | '_defaulted' | '_optimisticResults'> & {
|
|
67
|
-
queryKey?: QueryKey | undefined;
|
|
68
|
-
initialData?: TInitialData;
|
|
69
|
-
};
|
|
70
|
-
type QueryOptionsOut<TOutput, TError, TSelectData, TInitialData> = Pick<QueryObserverOptions<TOutput, TError, TSelectData, TOutput, DataTag<QueryKey, TOutput, TError>>, 'queryKey' | 'throwOnError' | 'select' | 'retryDelay'> & (undefined extends TInitialData ? object : {
|
|
71
|
-
initialData: TInitialData;
|
|
72
|
-
}) & {
|
|
73
|
-
queryFn: QueryFunction<TOutput, DataTag<QueryKey, TOutput, TError>>;
|
|
74
|
-
};
|
|
75
|
-
type StreamedKeyOptions<TInput> = ((undefined extends TInput ? {
|
|
76
|
-
input?: TInput | SkipToken;
|
|
77
|
-
} : {
|
|
78
|
-
input: TInput | SkipToken;
|
|
79
|
-
}) & {
|
|
80
|
-
queryFnOptions?: SerializableStreamedQueryOptions | undefined;
|
|
81
|
-
}) | {
|
|
82
|
-
queryKey: QueryKey;
|
|
83
|
-
};
|
|
84
|
-
type StreamedOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TInitialData> = QueryOptionsIn<TClientContext, TInput, TOutput, TError, TSelectData, TInitialData> & {
|
|
85
|
-
queryFnOptions?: SerializableStreamedQueryOptions | undefined;
|
|
86
|
-
};
|
|
87
|
-
type StreamedOptionsOut<TOutput, TError, TSelectData, TInitialData> = QueryOptionsOut<TOutput, TError, TSelectData, TInitialData>;
|
|
88
|
-
type InfiniteKeyOptions<TInput, TPageParam> = Pick<InfiniteOptionsIn<any, TInput, any, any, any, TPageParam, any>, 'input' | 'initialPageParam'> | {
|
|
89
|
-
queryKey: QueryKey;
|
|
90
|
-
};
|
|
91
|
-
type InfiniteOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TSelectData, TPageParam, TInitialData> = {
|
|
92
|
-
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
93
|
-
initialData?: TInitialData;
|
|
94
|
-
queryKey?: QueryKey | undefined;
|
|
95
|
-
} & (object extends TClientContext ? {
|
|
96
|
-
context?: TClientContext | undefined;
|
|
97
|
-
} : {
|
|
98
|
-
context: TClientContext;
|
|
99
|
-
}) & Omit<InfiniteQueryObserverOptions<TOutput, TError, TSelectData, QueryKey, TPageParam>, 'queryKey' | '_defaulted' | '_optimisticResults'>;
|
|
100
|
-
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 : {
|
|
101
|
-
initialData: TInitialData;
|
|
102
|
-
}) & {
|
|
103
|
-
queryFn: QueryFunction<TOutput, DataTag<QueryKey, InfiniteData<TOutput, TPageParam>, TError>, TPageParam>;
|
|
104
|
-
};
|
|
105
|
-
type MutationKeyOptions = Pick<MutationOptionsIn<any, any, any, any, any>, 'mutationKey'>;
|
|
106
|
-
type MutationOptionsIn<TClientContext extends ClientContext, TInput, TOutput, TError, TMutationContext> = (object extends TClientContext ? {
|
|
107
|
-
context?: TClientContext | undefined;
|
|
108
|
-
} : {
|
|
109
|
-
context: TClientContext;
|
|
110
|
-
}) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
|
|
111
|
-
type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
|
|
112
|
-
|
|
113
|
-
interface OperationKeyPrefixOptions {
|
|
114
|
-
/**
|
|
115
|
-
* Prepended as the first element of the key when present.
|
|
116
|
-
* Use this to avoid key conflicts when multiple router utils share the same client.
|
|
117
|
-
*/
|
|
118
|
-
prefix?: string | undefined;
|
|
119
|
-
}
|
|
120
|
-
interface OperationKeyBaseOptions extends OperationKeyPrefixOptions {
|
|
121
|
-
/**
|
|
122
|
-
* Serializes inputs into JSON-compatible values when building keys,
|
|
123
|
-
* and compares custom types in structural sharing.
|
|
124
|
-
* Pass the serializer your link uses so custom types are supported.
|
|
125
|
-
*
|
|
126
|
-
* @default new RPCJsonSerializer()
|
|
127
|
-
*/
|
|
128
|
-
serializer?: Public<RPCJsonSerializer> | undefined;
|
|
129
|
-
}
|
|
130
|
-
type OperationKeyOptions<TType extends OperationType, TInput> = OperationKeyBaseOptions & {
|
|
131
|
-
type?: TType | undefined;
|
|
132
|
-
input?: (TType extends 'mutation' ? never : PartialDeep<TInput>) | undefined;
|
|
133
|
-
fnOptions?: (TType extends 'streamed' ? SerializableStreamedQueryOptions : never) | undefined;
|
|
134
|
-
};
|
|
135
|
-
type OperationKeyContent<TType extends OperationType, TInput> = Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions> & {
|
|
136
|
-
/**
|
|
137
|
-
* Set in place of `input` when the operation is disabled with `skipToken`,
|
|
138
|
-
* because query key hashers drop symbols.
|
|
139
|
-
*/
|
|
140
|
-
skipToken?: TType extends 'mutation' ? never : true;
|
|
141
|
-
/**
|
|
142
|
-
* Serializer types of non-JSON values in `input`, keyed by their JSON-encoded path,
|
|
143
|
-
* so inputs with the same JSON form (like a `Date` and its ISO string) produce different keys.
|
|
144
|
-
* Keyed by path (not a list) so partial keys still match.
|
|
145
|
-
*/
|
|
146
|
-
inputMeta?: Record<string, string[]> | undefined;
|
|
147
|
-
};
|
|
148
|
-
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: OperationKeyContent<TType, TInput>] | [prefix: string, path: string[], options: OperationKeyContent<TType, TInput>];
|
|
149
|
-
|
|
150
|
-
declare class SharedUtils<TInput> {
|
|
151
|
-
protected readonly path: string[];
|
|
152
|
-
protected readonly options: OperationKeyBaseOptions;
|
|
153
|
-
constructor(path: string[], options: OperationKeyBaseOptions);
|
|
154
|
-
/**
|
|
155
|
-
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
156
|
-
*/
|
|
157
|
-
key<TType extends OperationType>(options?: Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions>): OperationKey<TType, TInput>;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
interface ProcedureUtilsQueryInterceptorOptions<TClientContext extends ClientContext, TInput> {
|
|
161
|
-
path: string[];
|
|
162
|
-
context: TClientContext & OperationContext;
|
|
163
|
-
input: TInput | SkipToken;
|
|
164
|
-
fnContext: QueryFunctionContext;
|
|
165
|
-
}
|
|
166
|
-
type ProcedureUtilsQueryInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
167
|
-
interface ProcedureUtilsStreamedInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
168
|
-
}
|
|
169
|
-
type ProcedureUtilsStreamedInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsStreamedInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferStreamedQueryOutput<TOutput>, TError>>;
|
|
170
|
-
interface ProcedureUtilsLiveInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
171
|
-
}
|
|
172
|
-
type ProcedureUtilsLiveInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsLiveInterceptorOptions<TClientContext, TInput>, PromiseWithError<InferLiveQueryOutput<TOutput>, TError>>;
|
|
173
|
-
interface ProcedureUtilsInfiniteInterceptorOptions<TClientContext extends ClientContext, TInput> extends ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput> {
|
|
174
|
-
fnContext: QueryFunctionContext<QueryKey, any>;
|
|
175
|
-
}
|
|
176
|
-
type ProcedureUtilsInfiniteInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsInfiniteInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
177
|
-
interface ProcedureUtilsMutationInterceptorOptions<TClientContext extends ClientContext, TInput> extends Omit<ProcedureUtilsQueryInterceptorOptions<TClientContext, TInput>, 'input' | 'fnContext'> {
|
|
178
|
-
input: TInput;
|
|
179
|
-
fnContext: MutationFunctionContext;
|
|
180
|
-
}
|
|
181
|
-
type ProcedureUtilsMutationInterceptor<TClientContext extends ClientContext, TInput, TOutput, TError> = Interceptor<ProcedureUtilsMutationInterceptorOptions<TClientContext, TInput>, PromiseWithError<TOutput, TError>>;
|
|
182
|
-
/**
|
|
183
|
-
* Can be partial options for spread-merged options,
|
|
184
|
-
* or a function that receives per-call options and returns overridden this.options.
|
|
185
|
-
*/
|
|
186
|
-
type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
|
|
187
|
-
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> extends OperationKeyBaseOptions {
|
|
188
|
-
/**
|
|
189
|
-
* Key options modifier for .queryKey and .queryOptions
|
|
190
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
191
|
-
*/
|
|
192
|
-
queryKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>> | undefined;
|
|
193
|
-
/**
|
|
194
|
-
* Interceptors that intercept queryFn inside .queryOptions, guaranteed to be executed.
|
|
195
|
-
*/
|
|
196
|
-
queryInterceptors?: ProcedureUtilsQueryInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
|
|
197
|
-
/**
|
|
198
|
-
* Options modifier for .queryOptions
|
|
199
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
200
|
-
*/
|
|
201
|
-
queryOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown>> | undefined;
|
|
202
|
-
/**
|
|
203
|
-
* Key options modifier for .streamedKey and .streamedOptions
|
|
204
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
205
|
-
*/
|
|
206
|
-
streamedKey?: ProcedureUtilsModifier<StreamedKeyOptions<TInput>> | undefined;
|
|
207
|
-
/**
|
|
208
|
-
* Interceptors that intercept queryFn inside .streamedOptions, guaranteed to be executed.
|
|
209
|
-
*/
|
|
210
|
-
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
|
|
211
|
-
/**
|
|
212
|
-
* Options modifier for .streamedOptions
|
|
213
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
214
|
-
*/
|
|
215
|
-
streamedOptions?: ProcedureUtilsModifier<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, unknown, unknown>> | undefined;
|
|
216
|
-
/**
|
|
217
|
-
* Key options modifier for .liveKey and .liveOptions
|
|
218
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
219
|
-
*/
|
|
220
|
-
liveKey?: ProcedureUtilsModifier<QueryKeyOptions<TInput>> | undefined;
|
|
221
|
-
/**
|
|
222
|
-
* Interceptors that intercept queryFn inside .liveOptions, guaranteed to be executed.
|
|
223
|
-
*/
|
|
224
|
-
liveInterceptors?: ProcedureUtilsLiveInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
|
|
225
|
-
/**
|
|
226
|
-
* Options modifier for .liveOptions
|
|
227
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
228
|
-
*/
|
|
229
|
-
liveOptions?: ProcedureUtilsModifier<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, unknown, unknown>> | undefined;
|
|
230
|
-
/**
|
|
231
|
-
* Key options modifier for .infiniteKey and .infiniteOptions
|
|
232
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
233
|
-
*/
|
|
234
|
-
infiniteKey?: ProcedureUtilsModifier<InfiniteKeyOptions<TInput, unknown>> | undefined;
|
|
235
|
-
/**
|
|
236
|
-
* Interceptors that intercept queryFn inside .infiniteOptions, guaranteed to be executed.
|
|
237
|
-
*/
|
|
238
|
-
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
|
|
239
|
-
/**
|
|
240
|
-
* Options modifier for .infiniteOptions
|
|
241
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
242
|
-
*/
|
|
243
|
-
infiniteOptions?: ProcedureUtilsModifier<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown, unknown>> | undefined;
|
|
244
|
-
/**
|
|
245
|
-
* Key options modifier for .mutationKey and .mutationOptions
|
|
246
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
247
|
-
*/
|
|
248
|
-
mutationKey?: ProcedureUtilsModifier<MutationKeyOptions> | undefined;
|
|
249
|
-
/**
|
|
250
|
-
* Interceptors that intercept mutationFn inside .mutationOptions, guaranteed to be executed.
|
|
251
|
-
*/
|
|
252
|
-
mutationInterceptors?: ProcedureUtilsMutationInterceptor<TClientContext, TInput, TOutput, TError>[] | undefined;
|
|
253
|
-
/**
|
|
254
|
-
* Options modifier for .mutationOptions
|
|
255
|
-
* Can be partial options or a function that receives per-call options and returns override this.options.
|
|
256
|
-
*/
|
|
257
|
-
mutationOptions?: ProcedureUtilsModifier<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>> | undefined;
|
|
258
|
-
}
|
|
259
|
-
/**
|
|
260
|
-
* Merge two procedure utils options where `override` takes priority.
|
|
261
|
-
* A key explicitly set to `undefined` in `override` resets the base value.
|
|
262
|
-
* When both sides define a key, interceptors are concatenated (base ones run first) and
|
|
263
|
-
* modifiers are combined so that, for object values, per-call options beat `override`,
|
|
264
|
-
* which beats `base`. A function modifier receives the merged options and its result wins.
|
|
265
|
-
*/
|
|
266
|
-
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>;
|
|
267
|
-
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> extends SharedUtils<TInput> {
|
|
268
|
-
protected readonly options: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>;
|
|
269
|
-
/**
|
|
270
|
-
* Calling corresponding procedure client
|
|
271
|
-
*/
|
|
272
|
-
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
273
|
-
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>);
|
|
274
|
-
/**
|
|
275
|
-
* Generate a **full matching** key for [Query Options](https://orpc.dev/docs/integrations/tanstack-query#query-options).
|
|
276
|
-
*/
|
|
277
|
-
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, TOutput, TError>;
|
|
278
|
-
/**
|
|
279
|
-
* Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
280
|
-
*/
|
|
281
|
-
queryOptions<USelectData = TOutput, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<TOutput, TError, USelectData, UInitialData>>;
|
|
282
|
-
/**
|
|
283
|
-
* Generate a **full matching** key for [Streamed Query Options](https://orpc.dev/docs/integrations/tanstack-query#streamed-query-options).
|
|
284
|
-
*/
|
|
285
|
-
streamedKey(...rest: MaybeOptionalOptions<StreamedKeyOptions<TInput>>): DataTag<QueryKey, InferStreamedQueryOutput<TOutput>, TError>;
|
|
286
|
-
/**
|
|
287
|
-
* Configure queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
|
|
288
|
-
* This is built on [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
289
|
-
* and works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
290
|
-
*/
|
|
291
|
-
streamedOptions<USelectData = InferStreamedQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<StreamedOptionsOut<InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
292
|
-
/**
|
|
293
|
-
* Generate a **full matching** key for [Live Query Options](https://orpc.dev/docs/integrations/tanstack-query#live-query-options).
|
|
294
|
-
*/
|
|
295
|
-
liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, InferLiveQueryOutput<TOutput>, TError>;
|
|
296
|
-
/**
|
|
297
|
-
* Configure live queries for [AsyncIteratorObject](https://orpc.dev/docs/async-iterator-object).
|
|
298
|
-
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
299
|
-
* Works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
300
|
-
*/
|
|
301
|
-
liveOptions<USelectData = InferLiveQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
302
|
-
/**
|
|
303
|
-
* Generate a **full matching** key for [Infinite Query Options](https://orpc.dev/docs/integrations/tanstack-query#infinite-query-options).
|
|
304
|
-
*/
|
|
305
|
-
infiniteKey<UPageParam>(optionsIn: InfiniteKeyOptions<TInput, UPageParam>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
|
|
306
|
-
/**
|
|
307
|
-
* Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
|
|
308
|
-
*/
|
|
309
|
-
infiniteOptions<UPageParam, USelectData = InfiniteData<TOutput, UPageParam>, UInitialData = undefined>(optionsIn: InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UPageParam, UInitialData>): NoInfer<InfiniteOptionsOut<TOutput, TError, USelectData, UPageParam, UInitialData>>;
|
|
310
|
-
/**
|
|
311
|
-
* Generate a **full matching** key for [Mutation Options](https://orpc.dev/docs/integrations/tanstack-query#mutation-options).
|
|
312
|
-
*/
|
|
313
|
-
mutationKey(optionsIn?: MutationKeyOptions): DataTag<QueryKey, TOutput, TError>;
|
|
314
|
-
/**
|
|
315
|
-
* Generate options used for useMutation/...
|
|
316
|
-
*/
|
|
317
|
-
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptionsOut<TInput, TOutput, TError, UMutationContext>>;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
/**
|
|
321
|
-
* Plugin that packages reusable defaults and interceptors for router utils.
|
|
322
|
-
*
|
|
323
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#plugins | TanStack Query Integration - Plugins}
|
|
324
|
-
*/
|
|
325
|
-
interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
326
|
-
/**
|
|
327
|
-
* Initializes the router utils plugin and returns updated router utils options.
|
|
328
|
-
* Called once per plugin instance during composition.
|
|
329
|
-
*
|
|
330
|
-
* This method allows plugins to wrap, extend, or transform router utils options,
|
|
331
|
-
* such as interceptors or configuration.
|
|
332
|
-
*
|
|
333
|
-
* @param options - The current router utils options from previous plugins or base configuration
|
|
334
|
-
* @returns Transformed router utils options with this plugin's modifications applied
|
|
335
|
-
*
|
|
336
|
-
* @example
|
|
337
|
-
* ```ts
|
|
338
|
-
* init(options) {
|
|
339
|
-
* return {
|
|
340
|
-
* ...options,
|
|
341
|
-
* mutationInterceptors: [...(options.mutationInterceptors ?? []), myInterceptor]
|
|
342
|
-
* }
|
|
343
|
-
* }
|
|
344
|
-
* ```
|
|
345
|
-
*/
|
|
346
|
-
init?(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
347
|
-
/**
|
|
348
|
-
* Initializes per-procedure router utils options and returns updated options.
|
|
349
|
-
* Called once per procedure utils instance during composition.
|
|
350
|
-
*
|
|
351
|
-
* This method allows plugins to customize merged procedure-specific defaults,
|
|
352
|
-
* such as query or mutation options, for the current path.
|
|
353
|
-
*
|
|
354
|
-
* @param path - The current procedure path
|
|
355
|
-
* @param options - The merged procedure utils options for the current procedure
|
|
356
|
-
* @returns Transformed procedure utils options with this plugin's modifications applied
|
|
357
|
-
*/
|
|
358
|
-
initProcedureOptions?(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* The utils shape derived from a client: procedure clients map to procedure
|
|
363
|
-
* utils, and routers map recursively to nested utils.
|
|
364
|
-
*
|
|
365
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query | TanStack Query Integration}
|
|
366
|
-
*/
|
|
367
|
-
type RouterUtils<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Public<ProcedureUtils<UClientContext, UInput, UOutput, UError>> : {
|
|
368
|
-
[K in keyof T]: T[K] extends AnyNestedClient ? RouterUtils<T[K]> : never;
|
|
369
|
-
} & Public<SharedUtils<unknown>>;
|
|
370
|
-
type RouterUtilsScoped<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtilsOptions<UClientContext, UInput, UOutput, UError> : {
|
|
371
|
-
[K in keyof T]?: (T[K] extends AnyNestedClient ? RouterUtilsScoped<T[K]> : never) | undefined;
|
|
372
|
-
};
|
|
373
|
-
interface RouterUtilsOptions<T extends AnyNestedClient> extends OperationKeyBaseOptions {
|
|
374
|
-
/**
|
|
375
|
-
* Base path for all query keys.
|
|
376
|
-
*
|
|
377
|
-
* @internal
|
|
378
|
-
*/
|
|
379
|
-
path?: string[] | undefined;
|
|
380
|
-
/**
|
|
381
|
-
* Interceptors that intercept queryFn inside .queryOptions
|
|
382
|
-
*/
|
|
383
|
-
queryInterceptors?: ProcedureUtilsQueryInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
|
|
384
|
-
/**
|
|
385
|
-
* Interceptors that intercept queryFn inside .streamedOptions
|
|
386
|
-
*/
|
|
387
|
-
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
|
|
388
|
-
/**
|
|
389
|
-
* Interceptors that intercept queryFn inside .liveOptions
|
|
390
|
-
*/
|
|
391
|
-
liveInterceptors?: ProcedureUtilsLiveInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
|
|
392
|
-
/**
|
|
393
|
-
* Interceptors that intercept queryFn inside .infiniteOptions
|
|
394
|
-
*/
|
|
395
|
-
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
|
|
396
|
-
/**
|
|
397
|
-
* Interceptors that intercept mutationFn inside .mutationOptions
|
|
398
|
-
*/
|
|
399
|
-
mutationInterceptors?: ProcedureUtilsMutationInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[] | undefined;
|
|
400
|
-
/**
|
|
401
|
-
* Per-procedure options following the shape of the router.
|
|
402
|
-
* Allows fine-grained configuration of individual procedure utils
|
|
403
|
-
* without affecting the rest of the router.
|
|
404
|
-
*/
|
|
405
|
-
scoped?: RouterUtilsScoped<T> | undefined;
|
|
406
|
-
/**
|
|
407
|
-
* Plugins to extend router utils behavior.
|
|
408
|
-
*/
|
|
409
|
-
plugins?: RouterUtilsPlugin<T>[] | undefined;
|
|
410
|
-
}
|
|
411
|
-
/**
|
|
412
|
-
* Creates TanStack Query utils from a client, exposing query/mutation
|
|
413
|
-
* option builders for every procedure in the router.
|
|
414
|
-
*
|
|
415
|
-
* @remarks
|
|
416
|
-
* **Note**: Both client-side and server-side clients are supported.
|
|
417
|
-
*
|
|
418
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query | TanStack Query Integration}
|
|
419
|
-
*/
|
|
420
|
-
declare function createRouterUtils<T extends AnyNestedClient>(client: T, options?: NoInfer<RouterUtilsOptions<T>>): RouterUtils<T>;
|
|
421
|
-
|
|
422
|
-
interface ContractUtilsFactory<TClientContext extends ClientContext> {
|
|
423
|
-
<T extends RouterContract>(contract: T): RouterUtils<RouterContractClient<T, TClientContext>>;
|
|
424
|
-
}
|
|
425
|
-
interface ContractUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<RouterContractClient<RouterContract, TClientContext>>, 'path'> {
|
|
426
|
-
}
|
|
427
|
-
/**
|
|
428
|
-
* Creates a factory that builds TanStack Query utils directly from a contract,
|
|
429
|
-
* using the given contract client factory. Useful for scaling large projects
|
|
430
|
-
* where each part only needs a slice of the router.
|
|
431
|
-
*
|
|
432
|
-
* @remarks
|
|
433
|
-
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
434
|
-
*
|
|
435
|
-
* @see {@link https://orpc.dev/docs/contract/client-factory#tanstack-query-integration | Contract Client Factory - TanStack Query Integration}
|
|
436
|
-
*/
|
|
437
|
-
declare function createContractUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractClientFactory<TClientContext>, options: ContractUtilsFactoryOptions<TClientContext>): ContractUtilsFactory<TClientContext>;
|
|
438
|
-
interface ContractJsonifiedUtilsFactory<TClientContext extends ClientContext> {
|
|
439
|
-
<T extends RouterContract>(contract: T): RouterUtils<JsonifiedClient<RouterContractClient<T, TClientContext>>>;
|
|
440
|
-
}
|
|
441
|
-
interface ContractJsonifiedUtilsFactoryOptions<TClientContext extends ClientContext> extends Omit<RouterUtilsOptions<JsonifiedClient<RouterContractClient<RouterContract, TClientContext>>>, 'path'> {
|
|
442
|
-
}
|
|
443
|
-
/**
|
|
444
|
-
* Like `createContractUtilsFactory`, but for clients whose types are wrapped in `JsonifiedClient`,
|
|
445
|
-
* such as clients using OpenAPI Link.
|
|
446
|
-
*
|
|
447
|
-
* @remarks
|
|
448
|
-
* Takes a client factory created by `createContractJsonifiedClientFactory` from `@orpc/openapi`.
|
|
449
|
-
*
|
|
450
|
-
* **Note**: The contract must define a `path` meta matching its position in the root router contract.
|
|
451
|
-
*
|
|
452
|
-
* @see {@link https://orpc.dev/docs/contract/client-factory#tanstack-query-integration | Contract Client Factory - TanStack Query Integration}
|
|
453
|
-
*/
|
|
454
|
-
declare function createContractJsonifiedUtilsFactory<TClientContext extends ClientContext>(clientFactory: ContractJsonifiedClientFactory<TClientContext>, options: ContractJsonifiedUtilsFactoryOptions<TClientContext>): ContractJsonifiedUtilsFactory<TClientContext>;
|
|
455
|
-
|
|
456
|
-
type TanstackQueryMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, keyof OperationKeyBaseOptions>;
|
|
457
|
-
interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
458
|
-
name: '~tanstack-query';
|
|
459
|
-
}
|
|
460
|
-
/**
|
|
461
|
-
* Define base TanStack Query options and interceptors on a procedure contract.
|
|
462
|
-
* Applied multiple times, later options are spread-merged with higher priority
|
|
463
|
-
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
464
|
-
* resets the value from earlier applications instead of merging.
|
|
465
|
-
*
|
|
466
|
-
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
467
|
-
*
|
|
468
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
469
|
-
*/
|
|
470
|
-
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>;
|
|
471
|
-
declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
472
|
-
'~orpc': {
|
|
473
|
-
meta: Meta;
|
|
474
|
-
};
|
|
475
|
-
}): TanstackQueryMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
476
|
-
/**
|
|
477
|
-
* Router utils plugin that applies base options defined via {@link tanstackQuery}
|
|
478
|
-
* on the given router contract. Meta options act as the base layer: options defined
|
|
479
|
-
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
480
|
-
*
|
|
481
|
-
* The contract shape must match the client the utils are created from,
|
|
482
|
-
* so pass the root router contract when utils paths start from the root.
|
|
483
|
-
*
|
|
484
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
485
|
-
*/
|
|
486
|
-
declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
487
|
-
private readonly contract;
|
|
488
|
-
readonly name = "~contract-options";
|
|
489
|
-
constructor(contract: RouterContract);
|
|
490
|
-
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* Creates `dehydrate` and `hydrate` query client defaults that preserve oRPC types.
|
|
495
|
-
*
|
|
496
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#custom-serializers | TanStack Query Integration - Custom Serializers}
|
|
497
|
-
*/
|
|
498
|
-
declare function createHydrationOptions(serializer?: Public<RPCJsonSerializer>): {
|
|
499
|
-
dehydrate: {
|
|
500
|
-
serializeData: (data: unknown) => RPCJsonSerialization;
|
|
501
|
-
};
|
|
502
|
-
hydrate: {
|
|
503
|
-
deserializeData: (data: RPCJsonSerialization) => unknown;
|
|
504
|
-
};
|
|
505
|
-
};
|
|
506
|
-
interface StreamQuerySSRUtilsPluginOptions {
|
|
507
|
-
/**
|
|
508
|
-
* Whether utils run on the server, where streamed and live queries are cancelled once they have data.
|
|
509
|
-
* Defaults to `true` when there is no global `window`.
|
|
510
|
-
*/
|
|
511
|
-
isServer?: boolean | undefined;
|
|
512
|
-
}
|
|
513
|
-
/**
|
|
514
|
-
* Router utils plugin for SSR of streamed and live queries. On the server, streamed queries are
|
|
515
|
-
* cancelled once they connect and live queries on their first event, keeping the data received so far;
|
|
516
|
-
* in the browser, they refetch on mount so streams reopen after hydration.
|
|
517
|
-
*
|
|
518
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#streamed-and-live-queries | TanStack Query Integration - Streamed and Live Queries}
|
|
519
|
-
*/
|
|
520
|
-
declare class StreamQuerySSRUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
521
|
-
readonly name = "~stream-query-ssr";
|
|
522
|
-
private readonly isServer;
|
|
523
|
-
constructor(options?: StreamQuerySSRUtilsPluginOptions);
|
|
524
|
-
initProcedureOptions(_path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
type StructuralSharing = <T>(oldData: unknown, newData: T) => T;
|
|
528
|
-
/**
|
|
529
|
-
* Creates a `structuralSharing` function that works like TanStack Query's default, but also keeps
|
|
530
|
-
* the previous reference for equal `Date`, `URL`, `Map` and `Set` values, which oRPC's serializer
|
|
531
|
-
* recreates on every response, and for custom types that serialize the same with a type-aware
|
|
532
|
-
* serializer like `RPCJsonSerializer`.
|
|
533
|
-
*
|
|
534
|
-
* Used by default in `.queryOptions`, `.liveOptions` and `.infiniteOptions`, pass `structuralSharing: false` to opt out.
|
|
535
|
-
*
|
|
536
|
-
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#structural-sharing | TanStack Query Integration - Structural Sharing}
|
|
537
|
-
*/
|
|
538
|
-
declare function createStructuralSharing(serializer?: Public<RPCJsonSerializer>): StructuralSharing;
|
|
539
|
-
|
|
540
|
-
export { ContractOptionsUtilsPlugin, OPERATION_CONTEXT_SYMBOL, ProcedureUtils, SharedUtils, StreamQuerySSRUtilsPlugin, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createHydrationOptions, createRouterUtils, createStructuralSharing, createRouterUtils as createTanstackQueryUtils, getTanstackQueryMeta, mergeProcedureUtilsOptions, tanstackQuery };
|
|
541
|
-
export type { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OperationContext, OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions, OperationType, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, RouterUtilsPlugin, RouterUtilsScoped, SerializableStreamedQueryOptions, StreamQuerySSRUtilsPluginOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, StructuralSharing, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, OperationContext as TanstackQueryOperationContext };
|