@orpc/tanstack-query 2.0.0-beta.5 → 2.0.0-beta.50
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 +137 -102
- package/dist/contract-utils.d.ts +35 -0
- package/dist/contract-utils.js +42 -0
- package/dist/index.d.ts +14 -374
- package/dist/index.js +8 -0
- package/dist/key.d.ts +41 -0
- package/dist/key.js +46 -0
- package/dist/live-query.js +30 -0
- package/dist/meta.d.ts +42 -0
- package/dist/meta.js +53 -0
- package/dist/plugin.d.ts +44 -0
- package/dist/plugin.js +19 -0
- package/dist/procedure-utils.d.ts +164 -0
- package/dist/procedure-utils.js +371 -0
- package/dist/router-utils.d.ts +62 -0
- package/dist/router-utils.js +54 -0
- package/dist/shared-utils.d.ts +11 -0
- package/dist/shared-utils.js +21 -0
- package/dist/ssr.d.ts +36 -0
- package/dist/ssr.js +47 -0
- package/dist/stream-query.d.ts +32 -0
- package/dist/stream-query.js +38 -0
- package/dist/structural-sharing.d.ts +14 -0
- package/dist/structural-sharing.js +105 -0
- package/dist/types.d.ts +87 -0
- package/dist/types.js +9 -0
- package/package.json +45 -33
- package/dist/index.d.mts +0 -374
- package/dist/index.mjs +0 -533
package/dist/index.d.ts
CHANGED
|
@@ -1,374 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
* @default 'reset'
|
|
16
|
-
*/
|
|
17
|
-
refetchMode?: 'append' | 'reset' | 'replace';
|
|
18
|
-
/**
|
|
19
|
-
* Limits the number of data chunks stored in the query result.
|
|
20
|
-
* Older chunks are removed when the limit is reached.
|
|
21
|
-
*
|
|
22
|
-
* @default Number.POSITIVE_INFINITY (unlimited)
|
|
23
|
-
*/
|
|
24
|
-
maxChunks?: number;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* A variant of `streamedQuery` where:
|
|
28
|
-
* - Options are serializable
|
|
29
|
-
* - The output is predictable
|
|
30
|
-
*/
|
|
31
|
-
declare function serializableStreamedQuery<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: (context: QueryFunctionContext<TQueryKey>) => Promisable<AsyncIterable<TQueryFnData>>, { refetchMode, maxChunks }?: SerializableStreamedQueryOptions): QueryFunction<TQueryFnData[], TQueryKey>;
|
|
32
|
-
|
|
33
|
-
type InferStreamedQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U[] : never;
|
|
34
|
-
type InferLiveQueryOutput<TOutput> = TOutput extends AsyncIterable<infer U> ? U : never;
|
|
35
|
-
type OperationType = 'query' | 'streamed' | 'live' | 'infinite' | 'mutation';
|
|
36
|
-
type OperationKeyOptions<TType extends OperationType, TInput> = {
|
|
37
|
-
type?: TType;
|
|
38
|
-
input?: TType extends 'mutation' ? never : PartialDeep<TInput>;
|
|
39
|
-
fnOptions?: TType extends 'streamed' ? SerializableStreamedQueryOptions : never;
|
|
40
|
-
};
|
|
41
|
-
type OperationKey<TType extends OperationType, TInput> = [path: string[], options: OperationKeyOptions<TType, TInput>];
|
|
42
|
-
declare const OPERATION_CONTEXT_SYMBOL: unique symbol;
|
|
43
|
-
interface OperationContext {
|
|
44
|
-
[OPERATION_CONTEXT_SYMBOL]?: {
|
|
45
|
-
key: QueryKey;
|
|
46
|
-
type: OperationType;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
type QueryKeyOptions<TInput> = (undefined extends TInput ? {
|
|
50
|
-
input?: TInput | SkipToken;
|
|
51
|
-
} : {
|
|
52
|
-
input: TInput | SkipToken;
|
|
53
|
-
}) | {
|
|
54
|
-
queryKey: QueryKey;
|
|
55
|
-
};
|
|
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 ? {
|
|
61
|
-
context?: TClientContext;
|
|
62
|
-
} : {
|
|
63
|
-
context: TClientContext;
|
|
64
|
-
}) & Omit<QueryObserverOptions<TOutput, TError, TSelectData>, 'queryKey' | '_defaulted' | '_optimisticResults'> & {
|
|
65
|
-
queryKey?: QueryKey;
|
|
66
|
-
initialData?: TInitialData;
|
|
67
|
-
};
|
|
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>>;
|
|
72
|
-
};
|
|
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> = {
|
|
90
|
-
input: ((pageParam: TPageParam) => TInput) | SkipToken;
|
|
91
|
-
initialData?: TInitialData;
|
|
92
|
-
queryKey?: QueryKey;
|
|
93
|
-
} & (object extends TClientContext ? {
|
|
94
|
-
context?: TClientContext;
|
|
95
|
-
} : {
|
|
96
|
-
context: 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 ? {
|
|
105
|
-
context?: TClientContext;
|
|
106
|
-
} : {
|
|
107
|
-
context: TClientContext;
|
|
108
|
-
}) & MutationOptionsOut<TInput, TOutput, TError, TMutationContext>;
|
|
109
|
-
type MutationOptionsOut<TInput, TOutput, TError, TMutationContext> = MutationObserverOptions<TOutput, TError, TInput, TMutationContext>;
|
|
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>>;
|
|
133
|
-
/**
|
|
134
|
-
* Can be partial options for spread-merged options,
|
|
135
|
-
* or a function that receives per-call options and returns overridden this.options.
|
|
136
|
-
*/
|
|
137
|
-
type ProcedureUtilsModifier<T extends object> = Partial<T> | ((options: T) => T);
|
|
138
|
-
interface ProcedureUtilsOptions<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
139
|
-
/**
|
|
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.
|
|
142
|
-
*/
|
|
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>>;
|
|
209
|
-
}
|
|
210
|
-
declare class ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
211
|
-
private readonly path;
|
|
212
|
-
private readonly options;
|
|
213
|
-
/**
|
|
214
|
-
* Calling corresponding procedure client
|
|
215
|
-
*/
|
|
216
|
-
call: Client<TClientContext, TInput, TOutput, TError>;
|
|
217
|
-
constructor(path: string[], client: Client<TClientContext, TInput, TOutput, TError>, options?: ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>);
|
|
218
|
-
/**
|
|
219
|
-
* Generate a **full matching** key for [Query Options](https://orpc.dev/docs/integrations/tanstack-query#query-options).
|
|
220
|
-
*/
|
|
221
|
-
queryKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, TOutput, TError>;
|
|
222
|
-
/**
|
|
223
|
-
* Generate options used for useQuery/useSuspenseQuery/prefetchQuery/...
|
|
224
|
-
*/
|
|
225
|
-
queryOptions<USelectData = TOutput, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, TOutput, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<TOutput, TError, USelectData, UInitialData>>;
|
|
226
|
-
/**
|
|
227
|
-
* Generate a **full matching** key for [Streamed Query Options](https://orpc.dev/docs/integrations/tanstack-query#streamed-query-options).
|
|
228
|
-
*/
|
|
229
|
-
streamedKey(...rest: MaybeOptionalOptions<StreamedKeyOptions<TInput>>): DataTag<QueryKey, InferStreamedQueryOutput<TOutput>, TError>;
|
|
230
|
-
/**
|
|
231
|
-
* Configure queries for [Event Iterator](https://orpc.dev/docs/event-iterator).
|
|
232
|
-
* This is built on [TanStack Query streamedQuery](https://tanstack.com/query/latest/docs/reference/streamedQuery)
|
|
233
|
-
* and works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
234
|
-
*/
|
|
235
|
-
streamedOptions<USelectData = InferStreamedQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<StreamedOptionsIn<TClientContext, TInput, InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<StreamedOptionsOut<InferStreamedQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
236
|
-
/**
|
|
237
|
-
* Generate a **full matching** key for [Live Query Options](https://orpc.dev/docs/integrations/tanstack-query#live-query-options).
|
|
238
|
-
*/
|
|
239
|
-
liveKey(...rest: MaybeOptionalOptions<QueryKeyOptions<TInput>>): DataTag<QueryKey, InferLiveQueryOutput<TOutput>, TError>;
|
|
240
|
-
/**
|
|
241
|
-
* Configure live queries for [Event Iterator](https://orpc.dev/docs/event-iterator).
|
|
242
|
-
* Unlike `.streamedOptions` which accumulates chunks, live queries replace the entire result with each new chunk received.
|
|
243
|
-
* Works with hooks like `useQuery`, `useSuspenseQuery`, or `prefetchQuery`.
|
|
244
|
-
*/
|
|
245
|
-
liveOptions<USelectData = InferLiveQueryOutput<TOutput>, UInitialData = undefined>(...rest: MaybeOptionalOptions<QueryOptionsIn<TClientContext, TInput, InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>): NoInfer<QueryOptionsOut<InferLiveQueryOutput<TOutput>, TError, USelectData, UInitialData>>;
|
|
246
|
-
/**
|
|
247
|
-
* Generate a **full matching** key for [Infinite Query Options](https://orpc.dev/docs/integrations/tanstack-query#infinite-query-options).
|
|
248
|
-
*/
|
|
249
|
-
infiniteKey<UPageParam>(optionsIn: InfiniteKeyOptions<TInput, UPageParam>): DataTag<QueryKey, InfiniteData<TOutput, UPageParam>, TError>;
|
|
250
|
-
/**
|
|
251
|
-
* Generate options used for useInfiniteQuery/useSuspenseInfiniteQuery/prefetchInfiniteQuery/...
|
|
252
|
-
*/
|
|
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>>;
|
|
254
|
-
/**
|
|
255
|
-
* Generate a **full matching** key for [Mutation Options](https://orpc.dev/docs/integrations/tanstack-query#mutation-options).
|
|
256
|
-
*/
|
|
257
|
-
mutationKey(optionsIn?: MutationKeyOptions): DataTag<QueryKey, TOutput, TError>;
|
|
258
|
-
/**
|
|
259
|
-
* Generate options used for useMutation/...
|
|
260
|
-
*/
|
|
261
|
-
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptionsOut<TInput, TOutput, TError, UMutationContext>>;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
interface RouterUtilsPlugin<T extends AnyNestedClient> extends OrderablePlugin {
|
|
265
|
-
/**
|
|
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.
|
|
271
|
-
*
|
|
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
|
-
* ```
|
|
284
|
-
*/
|
|
285
|
-
init?(options: RouterUtilsOptions<T>): RouterUtilsOptions<T>;
|
|
286
|
-
/**
|
|
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.
|
|
292
|
-
*
|
|
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
|
|
296
|
-
*/
|
|
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[]);
|
|
303
|
-
/**
|
|
304
|
-
* Generate a **partial matching** key for actions like revalidating queries, checking mutation status, etc.
|
|
305
|
-
*/
|
|
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> {
|
|
315
|
-
/**
|
|
316
|
-
* Base path for all query keys. Use this to avoid conflicts when mounting
|
|
317
|
-
* multiple router utils instances.
|
|
318
|
-
*/
|
|
319
|
-
path?: string[] | undefined;
|
|
320
|
-
/**
|
|
321
|
-
* Interceptors that intercept queryFn inside .queryOptions
|
|
322
|
-
*/
|
|
323
|
-
queryInterceptors?: ProcedureUtilsQueryInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
324
|
-
/**
|
|
325
|
-
* Interceptors that intercept queryFn inside .streamedOptions
|
|
326
|
-
*/
|
|
327
|
-
streamedInterceptors?: ProcedureUtilsStreamedInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
328
|
-
/**
|
|
329
|
-
* Interceptors that intercept queryFn inside .liveOptions
|
|
330
|
-
*/
|
|
331
|
-
liveInterceptors?: ProcedureUtilsLiveInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
332
|
-
/**
|
|
333
|
-
* Interceptors that intercept queryFn inside .infiniteOptions
|
|
334
|
-
*/
|
|
335
|
-
infiniteInterceptors?: ProcedureUtilsInfiniteInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
336
|
-
/**
|
|
337
|
-
* Interceptors that intercept mutationFn inside .mutationOptions
|
|
338
|
-
*/
|
|
339
|
-
mutationInterceptors?: ProcedureUtilsMutationInterceptor<InferClientContext<T>, unknown, unknown, InferClientError<T>>[];
|
|
340
|
-
/**
|
|
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.
|
|
344
|
-
*/
|
|
345
|
-
scoped?: RouterUtilsScoped<T> | undefined;
|
|
346
|
-
/**
|
|
347
|
-
* Plugins to extend router utils behavior.
|
|
348
|
-
*/
|
|
349
|
-
plugins?: RouterUtilsPlugin<T>[] | undefined;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* Create a router utils from a client.
|
|
353
|
-
*
|
|
354
|
-
* @info Both client-side and server-side clients are supported.
|
|
355
|
-
*/
|
|
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>;
|
|
372
|
-
|
|
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 };
|
|
1
|
+
import { ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractUtilsFactory, ContractUtilsFactoryOptions, createContractJsonifiedUtilsFactory, createContractUtilsFactory } from "./contract-utils.js";
|
|
2
|
+
import { OperationKey, OperationKeyBaseOptions, OperationKeyOptions, OperationKeyPrefixOptions } from "./key.js";
|
|
3
|
+
import { ContractOptionsUtilsPlugin, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, getTanstackQueryMeta, tanstackQuery } from "./meta.js";
|
|
4
|
+
import { RouterUtilsPlugin } from "./plugin.js";
|
|
5
|
+
import { ProcedureUtils, ProcedureUtilsInfiniteInterceptor, ProcedureUtilsInfiniteInterceptorOptions, ProcedureUtilsLiveInterceptor, ProcedureUtilsLiveInterceptorOptions, ProcedureUtilsModifier, ProcedureUtilsMutationInterceptor, ProcedureUtilsMutationInterceptorOptions, ProcedureUtilsOptions, ProcedureUtilsQueryInterceptor, ProcedureUtilsQueryInterceptorOptions, ProcedureUtilsStreamedInterceptor, ProcedureUtilsStreamedInterceptorOptions, mergeProcedureUtilsOptions } from "./procedure-utils.js";
|
|
6
|
+
import { RouterUtils, RouterUtilsOptions, RouterUtilsScoped, createRouterUtils } from "./router-utils.js";
|
|
7
|
+
import { SharedUtils } from "./shared-utils.js";
|
|
8
|
+
import { StreamQuerySSRUtilsPlugin, StreamQuerySSRUtilsPluginOptions, createHydrationOptions } from "./ssr.js";
|
|
9
|
+
import { SerializableStreamedQueryOptions, SettleOnFirstDataOptions } from "./stream-query.js";
|
|
10
|
+
import { StructuralSharing, createStructuralSharing } from "./structural-sharing.js";
|
|
11
|
+
import { InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, LiveOptionsIn, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OPERATION_CONTEXT_SYMBOL, OperationContext, OperationType, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut } from "./types.js";
|
|
12
|
+
import { Public } from "@orpc/shared";
|
|
13
|
+
import { AnyNestedClient } from "@orpc/client";
|
|
14
|
+
export { type AnyNestedClient, ContractJsonifiedUtilsFactory, ContractJsonifiedUtilsFactoryOptions, ContractOptionsUtilsPlugin, ContractUtilsFactory, ContractUtilsFactoryOptions, InferLiveQueryOutput, InferStreamedQueryOutput, InfiniteKeyOptions, InfiniteOptionsIn, InfiniteOptionsOut, LiveOptionsIn, MutationKeyOptions, MutationOptionsIn, MutationOptionsOut, OPERATION_CONTEXT_SYMBOL, OperationContext, type OperationKey, type OperationKeyBaseOptions, type OperationKeyOptions, type OperationKeyPrefixOptions, OperationType, ProcedureUtils, type ProcedureUtilsInfiniteInterceptor, type ProcedureUtilsInfiniteInterceptorOptions, type ProcedureUtilsLiveInterceptor, type ProcedureUtilsLiveInterceptorOptions, type ProcedureUtilsModifier, type ProcedureUtilsMutationInterceptor, type ProcedureUtilsMutationInterceptorOptions, type ProcedureUtilsOptions, type ProcedureUtilsQueryInterceptor, type ProcedureUtilsQueryInterceptorOptions, type ProcedureUtilsStreamedInterceptor, type ProcedureUtilsStreamedInterceptorOptions, type Public, QueryKeyOptions, QueryOptionsIn, QueryOptionsOut, RouterUtils, RouterUtilsOptions, type RouterUtilsPlugin, RouterUtilsScoped, type SerializableStreamedQueryOptions, type SettleOnFirstDataOptions, SharedUtils, StreamQuerySSRUtilsPlugin, StreamQuerySSRUtilsPluginOptions, StreamedKeyOptions, StreamedOptionsIn, StreamedOptionsOut, StructuralSharing, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, TanstackQueryMetaOptions, TanstackQueryMetaPlugin, type OperationContext as TanstackQueryOperationContext, createContractJsonifiedUtilsFactory, createContractUtilsFactory, createHydrationOptions, createRouterUtils, createStructuralSharing, createRouterUtils as createTanstackQueryUtils, getTanstackQueryMeta, mergeProcedureUtilsOptions, tanstackQuery };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { createContractJsonifiedUtilsFactory, createContractUtilsFactory } from "./contract-utils.js";
|
|
2
|
+
export { ContractOptionsUtilsPlugin, getTanstackQueryMeta, tanstackQuery } from "./meta.js";
|
|
3
|
+
export { ProcedureUtils, mergeProcedureUtilsOptions } from "./procedure-utils.js";
|
|
4
|
+
export { createRouterUtils, createRouterUtils as createTanstackQueryUtils } from "./router-utils.js";
|
|
5
|
+
export { SharedUtils } from "./shared-utils.js";
|
|
6
|
+
export { StreamQuerySSRUtilsPlugin, createHydrationOptions } from "./ssr.js";
|
|
7
|
+
export { createStructuralSharing } from "./structural-sharing.js";
|
|
8
|
+
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL } from "./types.js";
|
package/dist/key.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SerializableStreamedQueryOptions } from "./stream-query.js";
|
|
2
|
+
import { OperationType } from "./types.js";
|
|
3
|
+
import { PartialDeep, Public } from "@orpc/shared";
|
|
4
|
+
import { RPCJsonSerializer } from "@orpc/client";
|
|
5
|
+
export interface OperationKeyPrefixOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Prepended as the first element of the key when present.
|
|
8
|
+
* Use this to avoid key conflicts when multiple router utils share the same client.
|
|
9
|
+
*/
|
|
10
|
+
prefix?: string | undefined;
|
|
11
|
+
}
|
|
12
|
+
export interface OperationKeyBaseOptions extends OperationKeyPrefixOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Serializes inputs into JSON-compatible values when building keys,
|
|
15
|
+
* and compares custom types in structural sharing.
|
|
16
|
+
* Pass the serializer your link uses so custom types are supported.
|
|
17
|
+
*
|
|
18
|
+
* @default new RPCJsonSerializer()
|
|
19
|
+
*/
|
|
20
|
+
serializer?: Public<RPCJsonSerializer> | undefined;
|
|
21
|
+
}
|
|
22
|
+
export type OperationKeyOptions<TType extends OperationType, TInput> = OperationKeyBaseOptions & {
|
|
23
|
+
type?: TType | undefined;
|
|
24
|
+
input?: (TType extends "mutation" ? never : PartialDeep<TInput>) | undefined;
|
|
25
|
+
fnOptions?: (TType extends "streamed" ? SerializableStreamedQueryOptions : never) | undefined;
|
|
26
|
+
};
|
|
27
|
+
type OperationKeyContent<TType extends OperationType, TInput> = Omit<OperationKeyOptions<TType, TInput>, keyof OperationKeyBaseOptions> & {
|
|
28
|
+
/**
|
|
29
|
+
* Set in place of `input` when the operation is disabled with `skipToken`,
|
|
30
|
+
* because query key hashers drop symbols.
|
|
31
|
+
*/
|
|
32
|
+
skipToken?: TType extends "mutation" ? never : true;
|
|
33
|
+
/**
|
|
34
|
+
* Serializer types of non-JSON values in `input`, keyed by their JSON-encoded path,
|
|
35
|
+
* so inputs with the same JSON form (like a `Date` and its ISO string) produce different keys.
|
|
36
|
+
* Keyed by path (not a list) so partial keys still match.
|
|
37
|
+
*/
|
|
38
|
+
inputMeta?: Record<string, string[]> | undefined;
|
|
39
|
+
};
|
|
40
|
+
export type OperationKey<TType extends OperationType, TInput> = [path: string[], options: OperationKeyContent<TType, TInput>] | [prefix: string, path: string[], options: OperationKeyContent<TType, TInput>];
|
|
41
|
+
export {};
|
package/dist/key.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { stringifyJSON } from "@orpc/shared";
|
|
2
|
+
import { RPCJsonSerializer } from "@orpc/client";
|
|
3
|
+
import { skipToken } from "@tanstack/query-core";
|
|
4
|
+
// src/key.ts
|
|
5
|
+
const defaultSerializer = /* @__PURE__ */ new RPCJsonSerializer();
|
|
6
|
+
/**
|
|
7
|
+
* Generate a TanStack Query key for a procedure.
|
|
8
|
+
*
|
|
9
|
+
* The input is serialized to JSON-compatible values, so keys hash and partially match
|
|
10
|
+
* by value, including types like `Date`, `Set`, `Map` and custom serializer types.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#key-serializer | TanStack Query Integration - Key Serializer}
|
|
13
|
+
*/
|
|
14
|
+
function generateOperationKey(path, options = {}) {
|
|
15
|
+
return [
|
|
16
|
+
...options.prefix !== void 0 ? [options.prefix] : [],
|
|
17
|
+
path,
|
|
18
|
+
{
|
|
19
|
+
...options.input === skipToken ? { skipToken: true } : options.input !== void 0 ? serializeInput(options.serializer ?? defaultSerializer, options.input) : {},
|
|
20
|
+
...options.type !== void 0 ? { type: options.type } : {},
|
|
21
|
+
...streamedKeyOptions(options.fnOptions)
|
|
22
|
+
}
|
|
23
|
+
];
|
|
24
|
+
}
|
|
25
|
+
function serializeInput(serializer, input) {
|
|
26
|
+
const { json, meta } = serializer.serializeJson(input);
|
|
27
|
+
if (!meta?.length) return { input: json };
|
|
28
|
+
const inputMeta = {};
|
|
29
|
+
for (const [type, ...segments] of meta) (inputMeta[stringifyJSON(segments)] ??= []).push(type);
|
|
30
|
+
return {
|
|
31
|
+
input: json,
|
|
32
|
+
inputMeta
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Leaves out default streamed options, so passing a default gives the same key as omitting it.
|
|
37
|
+
*/
|
|
38
|
+
function streamedKeyOptions(options) {
|
|
39
|
+
const { refetchMode, maxChunks } = options ?? {};
|
|
40
|
+
const fnOptions = {
|
|
41
|
+
...refetchMode !== void 0 && refetchMode !== "reset" ? { refetchMode } : {},
|
|
42
|
+
...maxChunks !== void 0 && maxChunks !== Number.POSITIVE_INFINITY ? { maxChunks } : {}
|
|
43
|
+
};
|
|
44
|
+
return Object.keys(fnOptions).length > 0 ? { fnOptions } : {};
|
|
45
|
+
}
|
|
46
|
+
export { generateOperationKey };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { listenAbort, stringifyJSON, throwIfAborted } from "@orpc/shared";
|
|
2
|
+
// src/live-query.ts
|
|
3
|
+
function liveQuery(queryFn, { settleOnFirstData = false } = {}) {
|
|
4
|
+
return async (context) => {
|
|
5
|
+
const { client, queryKey, signal } = context;
|
|
6
|
+
const unlisten = listenAbort(signal, () => client.getQueryCache().find({
|
|
7
|
+
queryKey,
|
|
8
|
+
exact: true
|
|
9
|
+
})?.invalidate());
|
|
10
|
+
try {
|
|
11
|
+
const stream = await queryFn(context);
|
|
12
|
+
if (signal.aborted) {
|
|
13
|
+
await stream[Symbol.asyncIterator]().return?.();
|
|
14
|
+
throw signal.reason;
|
|
15
|
+
}
|
|
16
|
+
let last;
|
|
17
|
+
for await (const chunk of stream) {
|
|
18
|
+
throwIfAborted(signal);
|
|
19
|
+
last = { chunk };
|
|
20
|
+
client.setQueryData(queryKey, chunk);
|
|
21
|
+
if (settleOnFirstData) break;
|
|
22
|
+
}
|
|
23
|
+
if (!last) throw new TypeError(`Live query for ${stringifyJSON(queryKey)} did not yield any data. Ensure the query function returns an AsyncIterable with at least one chunk.`);
|
|
24
|
+
return last.chunk;
|
|
25
|
+
} finally {
|
|
26
|
+
unlisten();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export { liveQuery };
|
package/dist/meta.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { OperationKeyBaseOptions } from "./key.js";
|
|
2
|
+
import { RouterUtilsPlugin } from "./plugin.js";
|
|
3
|
+
import { ProcedureUtilsOptions } from "./procedure-utils.js";
|
|
4
|
+
import { AnySchema, ErrorMap, InferSchemaInput, InferSchemaOutput, Meta, MetaPlugin, ORPCErrorFromErrorMap, RouterContract } from "@orpc/contract";
|
|
5
|
+
import { ThrowableError } from "@orpc/shared";
|
|
6
|
+
import { AnyNestedClient, ClientContext, InferClientContext, InferClientError } from "@orpc/client";
|
|
7
|
+
export type TanstackQueryMetaOptions<TClientContext extends ClientContext, TInput, TOutput, TError> = Omit<ProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>, keyof OperationKeyBaseOptions>;
|
|
8
|
+
export interface TanstackQueryMetaPlugin<TInputSchema extends AnySchema, TOutputSchema extends AnySchema, TErrorMap extends ErrorMap> extends MetaPlugin<TInputSchema, TOutputSchema, TErrorMap> {
|
|
9
|
+
name: "~tanstack-query";
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Define base TanStack Query options and interceptors on a procedure contract.
|
|
13
|
+
* Applied multiple times, later options are spread-merged with higher priority
|
|
14
|
+
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
15
|
+
* resets the value from earlier applications instead of merging.
|
|
16
|
+
*
|
|
17
|
+
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
18
|
+
*
|
|
19
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
20
|
+
*/
|
|
21
|
+
export 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>;
|
|
22
|
+
export declare function getTanstackQueryMeta(procedureOrLazy: {
|
|
23
|
+
"~orpc": {
|
|
24
|
+
meta: Meta;
|
|
25
|
+
};
|
|
26
|
+
}): TanstackQueryMetaOptions<ClientContext, unknown, unknown, ThrowableError> | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* Router utils plugin that applies base options defined via {@link tanstackQuery}
|
|
29
|
+
* on the given router contract. Meta options act as the base layer: options defined
|
|
30
|
+
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
31
|
+
*
|
|
32
|
+
* The contract shape must match the client the utils are created from,
|
|
33
|
+
* so pass the root router contract when utils paths start from the root.
|
|
34
|
+
*
|
|
35
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
36
|
+
*/
|
|
37
|
+
export declare class ContractOptionsUtilsPlugin<T extends AnyNestedClient = AnyNestedClient> implements RouterUtilsPlugin<T> {
|
|
38
|
+
private readonly contract;
|
|
39
|
+
readonly name = "~contract-options";
|
|
40
|
+
constructor(contract: RouterContract);
|
|
41
|
+
initProcedureOptions(path: string[], options: ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>): ProcedureUtilsOptions<InferClientContext<T>, any, any, InferClientError<T>>;
|
|
42
|
+
}
|
package/dist/meta.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { mergeProcedureUtilsOptions } from "./procedure-utils.js";
|
|
2
|
+
import { ProcedureContract, getRouterContract } from "@orpc/contract";
|
|
3
|
+
// src/meta.ts
|
|
4
|
+
/**
|
|
5
|
+
* Define base TanStack Query options and interceptors on a procedure contract.
|
|
6
|
+
* Applied multiple times, later options are spread-merged with higher priority
|
|
7
|
+
* while interceptors are concatenated. A key explicitly set to `undefined`
|
|
8
|
+
* resets the value from earlier applications instead of merging.
|
|
9
|
+
*
|
|
10
|
+
* Apply them to router utils with {@link ContractOptionsUtilsPlugin}.
|
|
11
|
+
*
|
|
12
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
13
|
+
*/
|
|
14
|
+
function tanstackQuery(options) {
|
|
15
|
+
return {
|
|
16
|
+
name: "~tanstack-query",
|
|
17
|
+
init(meta) {
|
|
18
|
+
const current = meta["~tanstack-query"];
|
|
19
|
+
return {
|
|
20
|
+
...meta,
|
|
21
|
+
"~tanstack-query": current ? mergeProcedureUtilsOptions(current, options) : options
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function getTanstackQueryMeta(procedureOrLazy) {
|
|
27
|
+
return procedureOrLazy["~orpc"].meta["~tanstack-query"];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Router utils plugin that applies base options defined via {@link tanstackQuery}
|
|
31
|
+
* on the given router contract. Meta options act as the base layer: options defined
|
|
32
|
+
* on the utils override them, and utils interceptors run after meta interceptors.
|
|
33
|
+
*
|
|
34
|
+
* The contract shape must match the client the utils are created from,
|
|
35
|
+
* so pass the root router contract when utils paths start from the root.
|
|
36
|
+
*
|
|
37
|
+
* @see {@link https://orpc.dev/docs/integrations/tanstack-query#contract-options-plugin | TanStack Query Integration - Contract Options Plugin}
|
|
38
|
+
*/
|
|
39
|
+
var ContractOptionsUtilsPlugin = class {
|
|
40
|
+
contract;
|
|
41
|
+
name = "~contract-options";
|
|
42
|
+
constructor(contract) {
|
|
43
|
+
this.contract = contract;
|
|
44
|
+
}
|
|
45
|
+
initProcedureOptions(path, options) {
|
|
46
|
+
const procedure = getRouterContract(this.contract, path);
|
|
47
|
+
if (!(procedure instanceof ProcedureContract)) return options;
|
|
48
|
+
const base = getTanstackQueryMeta(procedure);
|
|
49
|
+
if (!base) return options;
|
|
50
|
+
return mergeProcedureUtilsOptions(base, options);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export { ContractOptionsUtilsPlugin, getTanstackQueryMeta, tanstackQuery };
|