@tanstack/query-core 4.0.8 → 4.0.11-beta.1
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/build/{types/packages/query-core/src → lib}/focusManager.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/hydration.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/index.d.ts +2 -2
- package/build/lib/index.js +3115 -0
- package/build/lib/index.js.map +1 -0
- package/build/{esm/index.js → lib/index.mjs} +22 -7
- package/build/lib/index.mjs.map +1 -0
- package/build/{types/packages/query-core/src → lib}/infiniteQueryBehavior.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/infiniteQueryObserver.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/logger.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/logger.native.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/mutation.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/mutationCache.d.ts +6 -1
- package/build/{types/packages/query-core/src → lib}/mutationObserver.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/notifyManager.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/onlineManager.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/queriesObserver.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/query.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/queryCache.d.ts +6 -1
- package/build/{types/packages/query-core/src → lib}/queryClient.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/queryObserver.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/removable.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/retryer.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/subscribable.d.ts +0 -0
- package/build/{types/packages/query-core/src → lib}/types.d.ts +10 -8
- package/build/{types/packages/query-core/src → lib}/utils.d.ts +0 -0
- package/build/umd/index.development.js +21 -6
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +16 -7
- package/src/index.ts +2 -2
- package/src/mutationCache.ts +7 -0
- package/src/mutationObserver.ts +9 -0
- package/src/queryCache.ts +7 -0
- package/src/queryClient.ts +10 -14
- package/src/queryObserver.ts +8 -0
- package/src/tests/queryClient.test.tsx +33 -0
- package/src/tests/queryObserver.test.tsx +19 -0
- package/src/types.ts +15 -9
- package/src/utils.ts +2 -0
- package/build/cjs/focusManager.js +0 -101
- package/build/cjs/focusManager.js.map +0 -1
- package/build/cjs/hydration.js +0 -112
- package/build/cjs/hydration.js.map +0 -1
- package/build/cjs/index.js +0 -51
- package/build/cjs/index.js.map +0 -1
- package/build/cjs/infiniteQueryBehavior.js +0 -160
- package/build/cjs/infiniteQueryBehavior.js.map +0 -1
- package/build/cjs/infiniteQueryObserver.js +0 -92
- package/build/cjs/infiniteQueryObserver.js.map +0 -1
- package/build/cjs/logger.js +0 -18
- package/build/cjs/logger.js.map +0 -1
- package/build/cjs/mutation.js +0 -258
- package/build/cjs/mutation.js.map +0 -1
- package/build/cjs/mutationCache.js +0 -99
- package/build/cjs/mutationCache.js.map +0 -1
- package/build/cjs/mutationObserver.js +0 -130
- package/build/cjs/mutationObserver.js.map +0 -1
- package/build/cjs/notifyManager.js +0 -114
- package/build/cjs/notifyManager.js.map +0 -1
- package/build/cjs/onlineManager.js +0 -100
- package/build/cjs/onlineManager.js.map +0 -1
- package/build/cjs/queriesObserver.js +0 -170
- package/build/cjs/queriesObserver.js.map +0 -1
- package/build/cjs/query.js +0 -474
- package/build/cjs/query.js.map +0 -1
- package/build/cjs/queryCache.js +0 -140
- package/build/cjs/queryCache.js.map +0 -1
- package/build/cjs/queryClient.js +0 -357
- package/build/cjs/queryClient.js.map +0 -1
- package/build/cjs/queryObserver.js +0 -521
- package/build/cjs/queryObserver.js.map +0 -1
- package/build/cjs/removable.js +0 -47
- package/build/cjs/removable.js.map +0 -1
- package/build/cjs/retryer.js +0 -177
- package/build/cjs/retryer.js.map +0 -1
- package/build/cjs/subscribable.js +0 -43
- package/build/cjs/subscribable.js.map +0 -1
- package/build/cjs/utils.js +0 -356
- package/build/cjs/utils.js.map +0 -1
- package/build/esm/index.js.map +0 -1
- package/build/stats-html.html +0 -2689
- package/build/stats.json +0 -805
- package/build/types/packages/query-core/src/tests/focusManager.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/hydration.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/infiniteQueryBehavior.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/infiniteQueryObserver.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/mutationCache.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/mutationObserver.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/mutations.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/notifyManager.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/onlineManager.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/queriesObserver.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/query.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/queryCache.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/queryClient.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/queryObserver.test.d.ts +0 -1
- package/build/types/packages/query-core/src/tests/utils.test.d.ts +0 -1
- package/build/types/tests/utils.d.ts +0 -24
|
@@ -27,12 +27,17 @@ interface NotifyEventMutationObserverRemoved {
|
|
|
27
27
|
mutation: Mutation<any, any, any, any>;
|
|
28
28
|
observer: MutationObserver<any, any, any>;
|
|
29
29
|
}
|
|
30
|
+
interface NotifyEventMutationObserverOptionsUpdated {
|
|
31
|
+
type: 'observerOptionsUpdated';
|
|
32
|
+
mutation?: Mutation<any, any, any, any>;
|
|
33
|
+
observer: MutationObserver<any, any, any, any>;
|
|
34
|
+
}
|
|
30
35
|
interface NotifyEventMutationUpdated {
|
|
31
36
|
type: 'updated';
|
|
32
37
|
mutation: Mutation<any, any, any, any>;
|
|
33
38
|
action: Action<any, any, any, any>;
|
|
34
39
|
}
|
|
35
|
-
declare type MutationCacheNotifyEvent = NotifyEventMutationAdded | NotifyEventMutationRemoved | NotifyEventMutationObserverAdded | NotifyEventMutationObserverRemoved | NotifyEventMutationUpdated;
|
|
40
|
+
declare type MutationCacheNotifyEvent = NotifyEventMutationAdded | NotifyEventMutationRemoved | NotifyEventMutationObserverAdded | NotifyEventMutationObserverRemoved | NotifyEventMutationObserverOptionsUpdated | NotifyEventMutationUpdated;
|
|
36
41
|
declare type MutationCacheListener = (event: MutationCacheNotifyEvent) => void;
|
|
37
42
|
export declare class MutationCache extends Subscribable<MutationCacheListener> {
|
|
38
43
|
config: MutationCacheConfig;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -35,7 +35,12 @@ interface NotifyEventQueryObserverResultsUpdated {
|
|
|
35
35
|
type: 'observerResultsUpdated';
|
|
36
36
|
query: Query<any, any, any, any>;
|
|
37
37
|
}
|
|
38
|
-
|
|
38
|
+
interface NotifyEventQueryObserverOptionsUpdated {
|
|
39
|
+
type: 'observerOptionsUpdated';
|
|
40
|
+
query: Query<any, any, any, any>;
|
|
41
|
+
observer: QueryObserver<any, any, any, any, any>;
|
|
42
|
+
}
|
|
43
|
+
declare type QueryCacheNotifyEvent = NotifyEventQueryAdded | NotifyEventQueryRemoved | NotifyEventQueryUpdated | NotifyEventQueryObserverAdded | NotifyEventQueryObserverRemoved | NotifyEventQueryObserverResultsUpdated | NotifyEventQueryObserverOptionsUpdated;
|
|
39
44
|
declare type QueryCacheListener = (event: QueryCacheNotifyEvent) => void;
|
|
40
45
|
export declare class QueryCache extends Subscribable<QueryCacheListener> {
|
|
41
46
|
config: QueryCacheConfig;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -45,9 +45,10 @@ export interface QueryOptions<TQueryFnData = unknown, TError = unknown, TData =
|
|
|
45
45
|
behavior?: QueryBehavior<TQueryFnData, TError, TData>;
|
|
46
46
|
/**
|
|
47
47
|
* Set this to `false` to disable structural sharing between query results.
|
|
48
|
+
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic.
|
|
48
49
|
* Defaults to `true`.
|
|
49
50
|
*/
|
|
50
|
-
structuralSharing?: boolean;
|
|
51
|
+
structuralSharing?: boolean | ((oldData: TData | undefined, newData: TData) => TData);
|
|
51
52
|
/**
|
|
52
53
|
* This function can be set to automatically get the previous cursor for infinite queries.
|
|
53
54
|
* The result will also be used to determine the value of `hasPreviousPage`.
|
|
@@ -274,7 +275,8 @@ export interface QueryObserverSuccessResult<TData = unknown, TError = unknown> e
|
|
|
274
275
|
isSuccess: true;
|
|
275
276
|
status: 'success';
|
|
276
277
|
}
|
|
277
|
-
export declare type
|
|
278
|
+
export declare type DefinedQueryObserverResult<TData = unknown, TError = unknown> = QueryObserverRefetchErrorResult<TData, TError> | QueryObserverSuccessResult<TData, TError>;
|
|
279
|
+
export declare type QueryObserverResult<TData = unknown, TError = unknown> = DefinedQueryObserverResult<TData, TError> | QueryObserverLoadingErrorResult<TData, TError> | QueryObserverLoadingResult<TData, TError>;
|
|
278
280
|
export interface InfiniteQueryObserverBaseResult<TData = unknown, TError = unknown> extends QueryObserverBaseResult<InfiniteData<TData>, TError> {
|
|
279
281
|
fetchNextPage: (options?: FetchNextPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
280
282
|
fetchPreviousPage: (options?: FetchPreviousPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
@@ -333,9 +335,9 @@ export interface MutationOptions<TData = unknown, TError = unknown, TVariables =
|
|
|
333
335
|
mutationKey?: MutationKey;
|
|
334
336
|
variables?: TVariables;
|
|
335
337
|
onMutate?: (variables: TVariables) => Promise<TContext | undefined> | TContext | undefined;
|
|
336
|
-
onSuccess?: (data: TData, variables: TVariables, context: TContext | undefined) => Promise<unknown> |
|
|
337
|
-
onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> |
|
|
338
|
-
onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> |
|
|
338
|
+
onSuccess?: (data: TData, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
339
|
+
onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
340
|
+
onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
339
341
|
retry?: RetryValue<TError>;
|
|
340
342
|
retryDelay?: RetryDelayValue<TError>;
|
|
341
343
|
networkMode?: NetworkMode;
|
|
@@ -347,9 +349,9 @@ export interface MutationObserverOptions<TData = unknown, TError = unknown, TVar
|
|
|
347
349
|
useErrorBoundary?: boolean | ((error: TError) => boolean);
|
|
348
350
|
}
|
|
349
351
|
export interface MutateOptions<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> {
|
|
350
|
-
onSuccess?: (data: TData, variables: TVariables, context: TContext) => Promise<unknown> |
|
|
351
|
-
onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> |
|
|
352
|
-
onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> |
|
|
352
|
+
onSuccess?: (data: TData, variables: TVariables, context: TContext) => Promise<unknown> | unknown;
|
|
353
|
+
onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
354
|
+
onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
353
355
|
}
|
|
354
356
|
export declare type MutateFunction<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> = (variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TContext>) => Promise<TData>;
|
|
355
357
|
export interface MutationObserverBaseResult<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> extends MutationState<TData, TError, TVariables, TContext> {
|
|
File without changes
|
|
@@ -347,6 +347,8 @@
|
|
|
347
347
|
// Use prev data if an isDataEqual function is defined and returns `true`
|
|
348
348
|
if (options.isDataEqual != null && options.isDataEqual(prevData, data)) {
|
|
349
349
|
return prevData;
|
|
350
|
+
} else if (typeof options.structuralSharing === 'function') {
|
|
351
|
+
return options.structuralSharing(prevData, data);
|
|
350
352
|
} else if (options.structuralSharing !== false) {
|
|
351
353
|
// Structurally share data between prev and new data if needed
|
|
352
354
|
return replaceEqualDeep(prevData, data);
|
|
@@ -2063,9 +2065,7 @@
|
|
|
2063
2065
|
const matchingDefaults = this.queryDefaults.filter(x => partialMatchKey(queryKey, x.queryKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
|
|
2064
2066
|
|
|
2065
2067
|
if (matchingDefaults.length > 1) {
|
|
2066
|
-
|
|
2067
|
-
this.logger.error("[QueryClient] Several query defaults match with key '" + JSON.stringify(queryKey) + "'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults.");
|
|
2068
|
-
}
|
|
2068
|
+
this.logger.error("[QueryClient] Several query defaults match with key '" + JSON.stringify(queryKey) + "'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults.");
|
|
2069
2069
|
}
|
|
2070
2070
|
}
|
|
2071
2071
|
|
|
@@ -2098,9 +2098,7 @@
|
|
|
2098
2098
|
const matchingDefaults = this.mutationDefaults.filter(x => partialMatchKey(mutationKey, x.mutationKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
|
|
2099
2099
|
|
|
2100
2100
|
if (matchingDefaults.length > 1) {
|
|
2101
|
-
|
|
2102
|
-
this.logger.error("[QueryClient] Several mutation defaults match with key '" + JSON.stringify(mutationKey) + "'. The first matching mutation defaults are used. Please check how mutation defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetmutationdefaults.");
|
|
2103
|
-
}
|
|
2101
|
+
this.logger.error("[QueryClient] Several mutation defaults match with key '" + JSON.stringify(mutationKey) + "'. The first matching mutation defaults are used. Please check how mutation defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetmutationdefaults.");
|
|
2104
2102
|
}
|
|
2105
2103
|
}
|
|
2106
2104
|
|
|
@@ -2207,6 +2205,14 @@
|
|
|
2207
2205
|
const prevQuery = this.currentQuery;
|
|
2208
2206
|
this.options = this.client.defaultQueryOptions(options);
|
|
2209
2207
|
|
|
2208
|
+
if (!shallowEqualObjects(prevOptions, this.options)) {
|
|
2209
|
+
this.client.getQueryCache().notify({
|
|
2210
|
+
type: 'observerOptionsUpdated',
|
|
2211
|
+
query: this.currentQuery,
|
|
2212
|
+
observer: this
|
|
2213
|
+
});
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2210
2216
|
if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
|
|
2211
2217
|
throw new Error('Expected enabled to be a boolean');
|
|
2212
2218
|
} // Keep previous query key if the user does not supply one
|
|
@@ -2890,7 +2896,16 @@
|
|
|
2890
2896
|
}
|
|
2891
2897
|
|
|
2892
2898
|
setOptions(options) {
|
|
2899
|
+
const prevOptions = this.options;
|
|
2893
2900
|
this.options = this.client.defaultMutationOptions(options);
|
|
2901
|
+
|
|
2902
|
+
if (!shallowEqualObjects(prevOptions, this.options)) {
|
|
2903
|
+
this.client.getMutationCache().notify({
|
|
2904
|
+
type: 'observerOptionsUpdated',
|
|
2905
|
+
mutation: this.currentMutation,
|
|
2906
|
+
observer: this
|
|
2907
|
+
});
|
|
2908
|
+
}
|
|
2894
2909
|
}
|
|
2895
2910
|
|
|
2896
2911
|
onUnsubscribe() {
|