@tanstack/query-core 4.0.10 → 4.1.2

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.
@@ -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;
@@ -35,7 +35,12 @@ interface NotifyEventQueryObserverResultsUpdated {
35
35
  type: 'observerResultsUpdated';
36
36
  query: Query<any, any, any, any>;
37
37
  }
38
- declare type QueryCacheNotifyEvent = NotifyEventQueryAdded | NotifyEventQueryRemoved | NotifyEventQueryUpdated | NotifyEventQueryObserverAdded | NotifyEventQueryObserverRemoved | NotifyEventQueryObserverResultsUpdated;
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;
@@ -333,9 +333,9 @@ export interface MutationOptions<TData = unknown, TError = unknown, TVariables =
333
333
  mutationKey?: MutationKey;
334
334
  variables?: TVariables;
335
335
  onMutate?: (variables: TVariables) => Promise<TContext | undefined> | TContext | undefined;
336
- onSuccess?: (data: TData, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void;
337
- onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void;
338
- onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void;
336
+ onSuccess?: (data: TData, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
337
+ onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
338
+ onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
339
339
  retry?: RetryValue<TError>;
340
340
  retryDelay?: RetryDelayValue<TError>;
341
341
  networkMode?: NetworkMode;
@@ -347,9 +347,9 @@ export interface MutationObserverOptions<TData = unknown, TError = unknown, TVar
347
347
  useErrorBoundary?: boolean | ((error: TError) => boolean);
348
348
  }
349
349
  export interface MutateOptions<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> {
350
- onSuccess?: (data: TData, variables: TVariables, context: TContext) => Promise<unknown> | void;
351
- onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void;
352
- onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | void;
350
+ onSuccess?: (data: TData, variables: TVariables, context: TContext) => Promise<unknown> | unknown;
351
+ onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
352
+ onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
353
353
  }
354
354
  export declare type MutateFunction<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> = (variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TContext>) => Promise<TData>;
355
355
  export interface MutationObserverBaseResult<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> extends MutationState<TData, TError, TVariables, TContext> {
@@ -2063,9 +2063,7 @@
2063
2063
  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
2064
 
2065
2065
  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
- }
2066
+ 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
2067
  }
2070
2068
  }
2071
2069
 
@@ -2098,9 +2096,7 @@
2098
2096
  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
2097
 
2100
2098
  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
- }
2099
+ 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
2100
  }
2105
2101
  }
2106
2102
 
@@ -2207,6 +2203,14 @@
2207
2203
  const prevQuery = this.currentQuery;
2208
2204
  this.options = this.client.defaultQueryOptions(options);
2209
2205
 
2206
+ if (!shallowEqualObjects(prevOptions, this.options)) {
2207
+ this.client.getQueryCache().notify({
2208
+ type: 'observerOptionsUpdated',
2209
+ query: this.currentQuery,
2210
+ observer: this
2211
+ });
2212
+ }
2213
+
2210
2214
  if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
2211
2215
  throw new Error('Expected enabled to be a boolean');
2212
2216
  } // Keep previous query key if the user does not supply one
@@ -2890,7 +2894,16 @@
2890
2894
  }
2891
2895
 
2892
2896
  setOptions(options) {
2897
+ const prevOptions = this.options;
2893
2898
  this.options = this.client.defaultMutationOptions(options);
2899
+
2900
+ if (!shallowEqualObjects(prevOptions, this.options)) {
2901
+ this.client.getMutationCache().notify({
2902
+ type: 'observerOptionsUpdated',
2903
+ mutation: this.currentMutation,
2904
+ observer: this
2905
+ });
2906
+ }
2894
2907
  }
2895
2908
 
2896
2909
  onUnsubscribe() {