@orpc/tanstack-query 0.0.0-next.56271c2 → 0.0.0-next.56695f3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +79 -6
- package/dist/index.d.ts +79 -6
- package/dist/index.mjs +54 -24
- package/package.json +12 -12
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
2
|
import { Promisable, SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions,
|
|
3
|
+
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData } from '@tanstack/query-core';
|
|
4
4
|
|
|
5
5
|
interface experimental_SerializableStreamedQueryOptions {
|
|
6
6
|
/**
|
|
@@ -180,16 +180,89 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
180
180
|
*/
|
|
181
181
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
|
|
182
182
|
}
|
|
183
|
-
interface
|
|
183
|
+
interface experimental_ProcedureUtilsDefaults<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
184
|
+
/**
|
|
185
|
+
* Default options for queryKey utility
|
|
186
|
+
*
|
|
187
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
188
|
+
*/
|
|
189
|
+
queryKey?: Partial<QueryKeyOptions<TInput>>;
|
|
190
|
+
/**
|
|
191
|
+
* Default options for queryOptions utility
|
|
192
|
+
*
|
|
193
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
|
|
194
|
+
*/
|
|
195
|
+
queryOptions?: Partial<QueryOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
196
|
+
/**
|
|
197
|
+
* Default options for experimental_streamedKey utility
|
|
198
|
+
*
|
|
199
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
200
|
+
*/
|
|
201
|
+
experimental_streamedKey?: Partial<experimental_StreamedKeyOptions<TInput>>;
|
|
202
|
+
/**
|
|
203
|
+
* Default options for experimental_streamedOptions utility
|
|
204
|
+
*
|
|
205
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
206
|
+
*/
|
|
207
|
+
experimental_streamedOptions?: Partial<experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, unknown>>;
|
|
208
|
+
/**
|
|
209
|
+
* Default options for experimental_liveKey utility
|
|
210
|
+
*
|
|
211
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
212
|
+
*/
|
|
213
|
+
experimental_liveKey?: Partial<QueryKeyOptions<TInput>>;
|
|
214
|
+
/**
|
|
215
|
+
* Default options for experimental_liveOptions utility
|
|
216
|
+
*
|
|
217
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
218
|
+
*/
|
|
219
|
+
experimental_liveOptions?: Partial<experimental_StreamedOptionsIn<TClientContext, TInput, experimental_LiveQueryOutput<TOutput>, TError, unknown>>;
|
|
220
|
+
/**
|
|
221
|
+
* Default options for infiniteKey utility
|
|
222
|
+
*
|
|
223
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
224
|
+
*/
|
|
225
|
+
infiniteKey?: Partial<Pick<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, InfiniteData<TOutput, unknown>, unknown>, 'input' | 'initialPageParam' | 'queryKey'>>;
|
|
226
|
+
/**
|
|
227
|
+
* Default options for infiniteOptions utility
|
|
228
|
+
*
|
|
229
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
230
|
+
*/
|
|
231
|
+
infiniteOptions?: Partial<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown>>;
|
|
232
|
+
/**
|
|
233
|
+
* Default options for mutationKey utility
|
|
234
|
+
*
|
|
235
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
236
|
+
*/
|
|
237
|
+
mutationKey?: Partial<Pick<MutationOptionsIn<TClientContext, TInput, TOutput, TError, any>, 'mutationKey'>>;
|
|
238
|
+
/**
|
|
239
|
+
* Default options for mutationOptions utility
|
|
240
|
+
*
|
|
241
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
242
|
+
*/
|
|
243
|
+
mutationOptions?: Partial<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @todo remove default generic types on v2
|
|
247
|
+
*/
|
|
248
|
+
interface CreateProcedureUtilsOptions<TClientContext extends ClientContext = ClientContext, TInput = unknown, TOutput = unknown, TError = unknown> {
|
|
184
249
|
path: readonly string[];
|
|
250
|
+
experimental_defaults?: experimental_ProcedureUtilsDefaults<TClientContext, TInput, TOutput, TError>;
|
|
185
251
|
}
|
|
186
|
-
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
252
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
187
253
|
|
|
188
254
|
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
|
189
255
|
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
190
256
|
} & GeneralUtils<unknown>;
|
|
191
|
-
|
|
257
|
+
type experimental_RouterUtilsDefaults<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? experimental_ProcedureUtilsDefaults<UClientContext, UInput, UOutput, UError> : {
|
|
258
|
+
[K in keyof T]?: T[K] extends NestedClient<any> ? experimental_RouterUtilsDefaults<T[K]> : never;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* @todo remove default generic types on v2
|
|
262
|
+
*/
|
|
263
|
+
interface CreateRouterUtilsOptions<T extends NestedClient<any> = NestedClient<any>> {
|
|
192
264
|
path?: readonly string[];
|
|
265
|
+
experimental_defaults?: experimental_RouterUtilsDefaults<T>;
|
|
193
266
|
}
|
|
194
267
|
/**
|
|
195
268
|
* Create a router utils from a client.
|
|
@@ -197,7 +270,7 @@ interface CreateRouterUtilsOptions {
|
|
|
197
270
|
* @info Both client-side and server-side clients are supported.
|
|
198
271
|
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query Tanstack Query Integration}
|
|
199
272
|
*/
|
|
200
|
-
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
273
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions<T>): RouterUtils<T>;
|
|
201
274
|
|
|
202
275
|
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, experimental_serializableStreamedQuery, generateOperationKey };
|
|
203
|
-
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_LiveQueryOutput, experimental_SerializableStreamedQueryOptions, experimental_StreamedKeyOptions, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
|
276
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_LiveQueryOutput, experimental_ProcedureUtilsDefaults, experimental_RouterUtilsDefaults, experimental_SerializableStreamedQueryOptions, experimental_StreamedKeyOptions, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ClientContext, Client, NestedClient } from '@orpc/client';
|
|
2
2
|
import { Promisable, SetOptional, PartialDeep, MaybeOptionalOptions } from '@orpc/shared';
|
|
3
|
-
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions,
|
|
3
|
+
import { QueryKey, QueryFunctionContext, QueryFunction, SkipToken, QueryObserverOptions, InfiniteQueryObserverOptions, MutationObserverOptions, DataTag, InfiniteData } from '@tanstack/query-core';
|
|
4
4
|
|
|
5
5
|
interface experimental_SerializableStreamedQueryOptions {
|
|
6
6
|
/**
|
|
@@ -180,16 +180,89 @@ interface ProcedureUtils<TClientContext extends ClientContext, TInput, TOutput,
|
|
|
180
180
|
*/
|
|
181
181
|
mutationOptions<UMutationContext>(...rest: MaybeOptionalOptions<MutationOptionsIn<TClientContext, TInput, TOutput, TError, UMutationContext>>): NoInfer<MutationOptions<TInput, TOutput, TError, UMutationContext>>;
|
|
182
182
|
}
|
|
183
|
-
interface
|
|
183
|
+
interface experimental_ProcedureUtilsDefaults<TClientContext extends ClientContext, TInput, TOutput, TError> {
|
|
184
|
+
/**
|
|
185
|
+
* Default options for queryKey utility
|
|
186
|
+
*
|
|
187
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
188
|
+
*/
|
|
189
|
+
queryKey?: Partial<QueryKeyOptions<TInput>>;
|
|
190
|
+
/**
|
|
191
|
+
* Default options for queryOptions utility
|
|
192
|
+
*
|
|
193
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-options Tanstack Query Options Utility Docs}
|
|
194
|
+
*/
|
|
195
|
+
queryOptions?: Partial<QueryOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
196
|
+
/**
|
|
197
|
+
* Default options for experimental_streamedKey utility
|
|
198
|
+
*
|
|
199
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
200
|
+
*/
|
|
201
|
+
experimental_streamedKey?: Partial<experimental_StreamedKeyOptions<TInput>>;
|
|
202
|
+
/**
|
|
203
|
+
* Default options for experimental_streamedOptions utility
|
|
204
|
+
*
|
|
205
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#streamed-query-options Tanstack Streamed Query Options Utility Docs}
|
|
206
|
+
*/
|
|
207
|
+
experimental_streamedOptions?: Partial<experimental_StreamedOptionsIn<TClientContext, TInput, experimental_StreamedQueryOutput<TOutput>, TError, unknown>>;
|
|
208
|
+
/**
|
|
209
|
+
* Default options for experimental_liveKey utility
|
|
210
|
+
*
|
|
211
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
212
|
+
*/
|
|
213
|
+
experimental_liveKey?: Partial<QueryKeyOptions<TInput>>;
|
|
214
|
+
/**
|
|
215
|
+
* Default options for experimental_liveOptions utility
|
|
216
|
+
*
|
|
217
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#live-query-options Tanstack Live Query Options Utility Docs}
|
|
218
|
+
*/
|
|
219
|
+
experimental_liveOptions?: Partial<experimental_StreamedOptionsIn<TClientContext, TInput, experimental_LiveQueryOutput<TOutput>, TError, unknown>>;
|
|
220
|
+
/**
|
|
221
|
+
* Default options for infiniteKey utility
|
|
222
|
+
*
|
|
223
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
224
|
+
*/
|
|
225
|
+
infiniteKey?: Partial<Pick<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, InfiniteData<TOutput, unknown>, unknown>, 'input' | 'initialPageParam' | 'queryKey'>>;
|
|
226
|
+
/**
|
|
227
|
+
* Default options for infiniteOptions utility
|
|
228
|
+
*
|
|
229
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#infinite-query-options Tanstack Infinite Query Options Utility Docs}
|
|
230
|
+
*/
|
|
231
|
+
infiniteOptions?: Partial<InfiniteOptionsIn<TClientContext, TInput, TOutput, TError, unknown, unknown>>;
|
|
232
|
+
/**
|
|
233
|
+
* Default options for mutationKey utility
|
|
234
|
+
*
|
|
235
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#query-mutation-key Tanstack Query/Mutation Key Docs}
|
|
236
|
+
*/
|
|
237
|
+
mutationKey?: Partial<Pick<MutationOptionsIn<TClientContext, TInput, TOutput, TError, any>, 'mutationKey'>>;
|
|
238
|
+
/**
|
|
239
|
+
* Default options for mutationOptions utility
|
|
240
|
+
*
|
|
241
|
+
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query#mutation-options Tanstack Mutation Options Docs}
|
|
242
|
+
*/
|
|
243
|
+
mutationOptions?: Partial<MutationOptionsIn<TClientContext, TInput, TOutput, TError, unknown>>;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* @todo remove default generic types on v2
|
|
247
|
+
*/
|
|
248
|
+
interface CreateProcedureUtilsOptions<TClientContext extends ClientContext = ClientContext, TInput = unknown, TOutput = unknown, TError = unknown> {
|
|
184
249
|
path: readonly string[];
|
|
250
|
+
experimental_defaults?: experimental_ProcedureUtilsDefaults<TClientContext, TInput, TOutput, TError>;
|
|
185
251
|
}
|
|
186
|
-
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
252
|
+
declare function createProcedureUtils<TClientContext extends ClientContext, TInput, TOutput, TError>(client: Client<TClientContext, TInput, TOutput, TError>, options: CreateProcedureUtilsOptions<TClientContext, TInput, TOutput, TError>): ProcedureUtils<TClientContext, TInput, TOutput, TError>;
|
|
187
253
|
|
|
188
254
|
type RouterUtils<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? ProcedureUtils<UClientContext, UInput, UOutput, UError> & GeneralUtils<UInput> : {
|
|
189
255
|
[K in keyof T]: T[K] extends NestedClient<any> ? RouterUtils<T[K]> : never;
|
|
190
256
|
} & GeneralUtils<unknown>;
|
|
191
|
-
|
|
257
|
+
type experimental_RouterUtilsDefaults<T extends NestedClient<any>> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? experimental_ProcedureUtilsDefaults<UClientContext, UInput, UOutput, UError> : {
|
|
258
|
+
[K in keyof T]?: T[K] extends NestedClient<any> ? experimental_RouterUtilsDefaults<T[K]> : never;
|
|
259
|
+
};
|
|
260
|
+
/**
|
|
261
|
+
* @todo remove default generic types on v2
|
|
262
|
+
*/
|
|
263
|
+
interface CreateRouterUtilsOptions<T extends NestedClient<any> = NestedClient<any>> {
|
|
192
264
|
path?: readonly string[];
|
|
265
|
+
experimental_defaults?: experimental_RouterUtilsDefaults<T>;
|
|
193
266
|
}
|
|
194
267
|
/**
|
|
195
268
|
* Create a router utils from a client.
|
|
@@ -197,7 +270,7 @@ interface CreateRouterUtilsOptions {
|
|
|
197
270
|
* @info Both client-side and server-side clients are supported.
|
|
198
271
|
* @see {@link https://orpc.unnoq.com/docs/integrations/tanstack-query Tanstack Query Integration}
|
|
199
272
|
*/
|
|
200
|
-
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions): RouterUtils<T>;
|
|
273
|
+
declare function createRouterUtils<T extends NestedClient<any>>(client: T, options?: CreateRouterUtilsOptions<T>): RouterUtils<T>;
|
|
201
274
|
|
|
202
275
|
export { OPERATION_CONTEXT_SYMBOL, OPERATION_CONTEXT_SYMBOL as TANSTACK_QUERY_OPERATION_CONTEXT_SYMBOL, createGeneralUtils, createProcedureUtils, createRouterUtils, createRouterUtils as createTanstackQueryUtils, experimental_serializableStreamedQuery, generateOperationKey };
|
|
203
|
-
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_LiveQueryOutput, experimental_SerializableStreamedQueryOptions, experimental_StreamedKeyOptions, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
|
276
|
+
export type { CreateProcedureUtilsOptions, CreateRouterUtilsOptions, GeneralUtils, InfiniteOptionsBase, InfiniteOptionsIn, MutationOptions, MutationOptionsIn, OperationContext, OperationKey, OperationKeyOptions, OperationType, ProcedureUtils, QueryKeyOptions, QueryOptionsBase, QueryOptionsIn, RouterUtils, OperationContext as TanstackQueryOperationContext, experimental_LiveQueryOutput, experimental_ProcedureUtilsDefaults, experimental_RouterUtilsDefaults, experimental_SerializableStreamedQueryOptions, experimental_StreamedKeyOptions, experimental_StreamedOptionsBase, experimental_StreamedOptionsIn, experimental_StreamedQueryOutput };
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { stringifyJSON, isAsyncIteratorObject, toArray } from '@orpc/shared';
|
|
1
|
+
import { stringifyJSON, isAsyncIteratorObject, toArray, get } from '@orpc/shared';
|
|
2
2
|
import { skipToken } from '@tanstack/query-core';
|
|
3
3
|
|
|
4
4
|
function generateOperationKey(path, state = {}) {
|
|
@@ -40,44 +40,57 @@ function experimental_liveQuery(queryFn) {
|
|
|
40
40
|
function experimental_serializableStreamedQuery(queryFn, { refetchMode = "reset", maxChunks = Number.POSITIVE_INFINITY } = {}) {
|
|
41
41
|
return async (context) => {
|
|
42
42
|
const query = context.client.getQueryCache().find({ queryKey: context.queryKey, exact: true });
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const hasPreviousData = !!query && query.state.data !== void 0;
|
|
44
|
+
if (hasPreviousData) {
|
|
45
|
+
if (refetchMode === "reset") {
|
|
46
|
+
query.setState({
|
|
47
|
+
status: "pending",
|
|
48
|
+
data: void 0,
|
|
49
|
+
error: null,
|
|
50
|
+
fetchStatus: "fetching"
|
|
51
|
+
});
|
|
52
|
+
} else {
|
|
53
|
+
context.client.setQueryData(
|
|
54
|
+
context.queryKey,
|
|
55
|
+
(prev = []) => limitArraySize(prev, maxChunks)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
51
58
|
}
|
|
52
59
|
let result = [];
|
|
53
60
|
const stream = await queryFn(context);
|
|
61
|
+
const shouldUpdateCacheDuringStream = !hasPreviousData || refetchMode !== "replace";
|
|
62
|
+
context.client.setQueryData(
|
|
63
|
+
context.queryKey,
|
|
64
|
+
(prev = []) => limitArraySize(prev, maxChunks)
|
|
65
|
+
);
|
|
54
66
|
for await (const chunk of stream) {
|
|
55
67
|
if (context.signal.aborted) {
|
|
56
68
|
throw context.signal.reason;
|
|
57
69
|
}
|
|
58
|
-
|
|
70
|
+
result.push(chunk);
|
|
71
|
+
result = limitArraySize(result, maxChunks);
|
|
72
|
+
if (shouldUpdateCacheDuringStream) {
|
|
59
73
|
context.client.setQueryData(
|
|
60
74
|
context.queryKey,
|
|
61
|
-
(prev = []) =>
|
|
62
|
-
return addToEnd(prev, chunk, maxChunks);
|
|
63
|
-
}
|
|
75
|
+
(prev = []) => limitArraySize([...prev, chunk], maxChunks)
|
|
64
76
|
);
|
|
65
77
|
}
|
|
66
|
-
result = addToEnd(result, chunk, maxChunks);
|
|
67
78
|
}
|
|
68
|
-
if (
|
|
79
|
+
if (!shouldUpdateCacheDuringStream) {
|
|
69
80
|
context.client.setQueryData(context.queryKey, result);
|
|
70
81
|
}
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
82
|
+
const cachedData = context.client.getQueryData(context.queryKey);
|
|
83
|
+
if (cachedData) {
|
|
84
|
+
return limitArraySize(cachedData, maxChunks);
|
|
74
85
|
}
|
|
75
|
-
return
|
|
86
|
+
return result;
|
|
76
87
|
};
|
|
77
88
|
}
|
|
78
|
-
function
|
|
79
|
-
|
|
80
|
-
|
|
89
|
+
function limitArraySize(items, maxSize) {
|
|
90
|
+
if (items.length <= maxSize) {
|
|
91
|
+
return items;
|
|
92
|
+
}
|
|
93
|
+
return items.slice(items.length - maxSize);
|
|
81
94
|
}
|
|
82
95
|
|
|
83
96
|
const OPERATION_CONTEXT_SYMBOL = Symbol("ORPC_OPERATION_CONTEXT");
|
|
@@ -86,10 +99,12 @@ function createProcedureUtils(client, options) {
|
|
|
86
99
|
const utils = {
|
|
87
100
|
call: client,
|
|
88
101
|
queryKey(...[optionsIn = {}]) {
|
|
102
|
+
optionsIn = { ...options.experimental_defaults?.queryKey, ...optionsIn };
|
|
89
103
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "query", input: optionsIn.input });
|
|
90
104
|
return queryKey;
|
|
91
105
|
},
|
|
92
106
|
queryOptions(...[optionsIn = {}]) {
|
|
107
|
+
optionsIn = { ...options.experimental_defaults?.queryOptions, ...optionsIn };
|
|
93
108
|
const queryKey = utils.queryKey(optionsIn);
|
|
94
109
|
return {
|
|
95
110
|
queryFn: ({ signal }) => {
|
|
@@ -113,10 +128,12 @@ function createProcedureUtils(client, options) {
|
|
|
113
128
|
};
|
|
114
129
|
},
|
|
115
130
|
experimental_streamedKey(...[optionsIn = {}]) {
|
|
131
|
+
optionsIn = { ...options.experimental_defaults?.experimental_streamedKey, ...optionsIn };
|
|
116
132
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "streamed", input: optionsIn.input, fnOptions: optionsIn.queryFnOptions });
|
|
117
133
|
return queryKey;
|
|
118
134
|
},
|
|
119
135
|
experimental_streamedOptions(...[optionsIn = {}]) {
|
|
136
|
+
optionsIn = { ...options.experimental_defaults?.experimental_streamedOptions, ...optionsIn };
|
|
120
137
|
const queryKey = utils.experimental_streamedKey(optionsIn);
|
|
121
138
|
return {
|
|
122
139
|
queryFn: experimental_serializableStreamedQuery(
|
|
@@ -147,10 +164,12 @@ function createProcedureUtils(client, options) {
|
|
|
147
164
|
};
|
|
148
165
|
},
|
|
149
166
|
experimental_liveKey(...[optionsIn = {}]) {
|
|
167
|
+
optionsIn = { ...options.experimental_defaults?.experimental_liveKey, ...optionsIn };
|
|
150
168
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, { type: "live", input: optionsIn.input });
|
|
151
169
|
return queryKey;
|
|
152
170
|
},
|
|
153
171
|
experimental_liveOptions(...[optionsIn = {}]) {
|
|
172
|
+
optionsIn = { ...options.experimental_defaults?.experimental_liveOptions, ...optionsIn };
|
|
154
173
|
const queryKey = utils.experimental_liveKey(optionsIn);
|
|
155
174
|
return {
|
|
156
175
|
queryFn: experimental_liveQuery(async ({ signal }) => {
|
|
@@ -178,6 +197,7 @@ function createProcedureUtils(client, options) {
|
|
|
178
197
|
};
|
|
179
198
|
},
|
|
180
199
|
infiniteKey(optionsIn) {
|
|
200
|
+
optionsIn = { ...options.experimental_defaults?.infiniteKey, ...optionsIn };
|
|
181
201
|
const queryKey = optionsIn.queryKey ?? generateOperationKey(options.path, {
|
|
182
202
|
type: "infinite",
|
|
183
203
|
input: optionsIn.input === skipToken ? skipToken : optionsIn.input(optionsIn.initialPageParam)
|
|
@@ -185,6 +205,7 @@ function createProcedureUtils(client, options) {
|
|
|
185
205
|
return queryKey;
|
|
186
206
|
},
|
|
187
207
|
infiniteOptions(optionsIn) {
|
|
208
|
+
optionsIn = { ...options.experimental_defaults?.infiniteOptions, ...optionsIn };
|
|
188
209
|
const queryKey = utils.infiniteKey(optionsIn);
|
|
189
210
|
return {
|
|
190
211
|
queryFn: ({ pageParam, signal }) => {
|
|
@@ -208,10 +229,12 @@ function createProcedureUtils(client, options) {
|
|
|
208
229
|
};
|
|
209
230
|
},
|
|
210
231
|
mutationKey(...[optionsIn = {}]) {
|
|
232
|
+
optionsIn = { ...options.experimental_defaults?.mutationKey, ...optionsIn };
|
|
211
233
|
const mutationKey = optionsIn.mutationKey ?? generateOperationKey(options.path, { type: "mutation" });
|
|
212
234
|
return mutationKey;
|
|
213
235
|
},
|
|
214
236
|
mutationOptions(...[optionsIn = {}]) {
|
|
237
|
+
optionsIn = { ...options.experimental_defaults?.mutationOptions, ...optionsIn };
|
|
215
238
|
const mutationKey = utils.mutationKey(optionsIn);
|
|
216
239
|
return {
|
|
217
240
|
mutationFn: (input) => client(input, {
|
|
@@ -234,7 +257,10 @@ function createProcedureUtils(client, options) {
|
|
|
234
257
|
function createRouterUtils(client, options = {}) {
|
|
235
258
|
const path = toArray(options.path);
|
|
236
259
|
const generalUtils = createGeneralUtils(path);
|
|
237
|
-
const procedureUtils = createProcedureUtils(client, {
|
|
260
|
+
const procedureUtils = createProcedureUtils(client, {
|
|
261
|
+
path,
|
|
262
|
+
experimental_defaults: options.experimental_defaults
|
|
263
|
+
});
|
|
238
264
|
const recursive = new Proxy({
|
|
239
265
|
...generalUtils,
|
|
240
266
|
...procedureUtils
|
|
@@ -244,7 +270,11 @@ function createRouterUtils(client, options = {}) {
|
|
|
244
270
|
if (typeof prop !== "string") {
|
|
245
271
|
return value;
|
|
246
272
|
}
|
|
247
|
-
const nextUtils = createRouterUtils(client[prop], {
|
|
273
|
+
const nextUtils = createRouterUtils(client[prop], {
|
|
274
|
+
...options,
|
|
275
|
+
path: [...path, prop],
|
|
276
|
+
experimental_defaults: get(options.experimental_defaults, [prop])
|
|
277
|
+
});
|
|
248
278
|
if (typeof value !== "function") {
|
|
249
279
|
return nextUtils;
|
|
250
280
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/tanstack-query",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.0-next.
|
|
4
|
+
"version": "0.0.0-next.56695f3",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -25,21 +25,21 @@
|
|
|
25
25
|
],
|
|
26
26
|
"peerDependencies": {
|
|
27
27
|
"@tanstack/query-core": ">=5.80.2",
|
|
28
|
-
"@orpc/client": "0.0.0-next.
|
|
28
|
+
"@orpc/client": "0.0.0-next.56695f3"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@orpc/shared": "0.0.0-next.
|
|
31
|
+
"@orpc/shared": "0.0.0-next.56695f3"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@angular/core": "^20.3.
|
|
35
|
-
"@tanstack/angular-query-experimental": "^5.90.
|
|
36
|
-
"@tanstack/query-core": "^5.90.
|
|
37
|
-
"@tanstack/react-query": "^5.90.
|
|
38
|
-
"@tanstack/solid-query": "^5.90.
|
|
39
|
-
"@tanstack/svelte-query": "^6.0.
|
|
40
|
-
"@tanstack/vue-query": "^5.
|
|
41
|
-
"svelte": "^5.
|
|
42
|
-
"vue": "^3.5.
|
|
34
|
+
"@angular/core": "^20.3.12",
|
|
35
|
+
"@tanstack/angular-query-experimental": "^5.90.12",
|
|
36
|
+
"@tanstack/query-core": "^5.90.10",
|
|
37
|
+
"@tanstack/react-query": "^5.90.10",
|
|
38
|
+
"@tanstack/solid-query": "^5.90.13",
|
|
39
|
+
"@tanstack/svelte-query": "^6.0.8",
|
|
40
|
+
"@tanstack/vue-query": "^5.91.2",
|
|
41
|
+
"svelte": "^5.43.14",
|
|
42
|
+
"vue": "^3.5.24",
|
|
43
43
|
"zod": "^4.1.12"
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|