@tanstack/vue-query 4.25.0 → 4.26.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.
@@ -1081,10 +1081,11 @@
1081
1081
  }
1082
1082
 
1083
1083
  if (!isCancelledError(error)) {
1084
- var _this$cache$config$on, _this$cache$config;
1084
+ var _this$cache$config$on, _this$cache$config, _this$cache$config$on2, _this$cache$config2;
1085
1085
 
1086
1086
  // Notify cache callback
1087
1087
  (_this$cache$config$on = (_this$cache$config = this.cache.config).onError) == null ? void 0 : _this$cache$config$on.call(_this$cache$config, error, this);
1088
+ (_this$cache$config$on2 = (_this$cache$config2 = this.cache.config).onSettled) == null ? void 0 : _this$cache$config$on2.call(_this$cache$config2, this.state.data, error, this);
1088
1089
 
1089
1090
  {
1090
1091
  this.logger.error(error);
@@ -1104,7 +1105,7 @@
1104
1105
  fn: context.fetchFn,
1105
1106
  abort: abortController == null ? void 0 : abortController.abort.bind(abortController),
1106
1107
  onSuccess: data => {
1107
- var _this$cache$config$on2, _this$cache$config2;
1108
+ var _this$cache$config$on3, _this$cache$config3, _this$cache$config$on4, _this$cache$config4;
1108
1109
 
1109
1110
  if (typeof data === 'undefined') {
1110
1111
  {
@@ -1117,7 +1118,8 @@
1117
1118
 
1118
1119
  this.setData(data); // Notify cache callback
1119
1120
 
1120
- (_this$cache$config$on2 = (_this$cache$config2 = this.cache.config).onSuccess) == null ? void 0 : _this$cache$config$on2.call(_this$cache$config2, data, this);
1121
+ (_this$cache$config$on3 = (_this$cache$config3 = this.cache.config).onSuccess) == null ? void 0 : _this$cache$config$on3.call(_this$cache$config3, data, this);
1122
+ (_this$cache$config$on4 = (_this$cache$config4 = this.cache.config).onSettled) == null ? void 0 : _this$cache$config$on4.call(_this$cache$config4, data, this.state.error, this);
1121
1123
 
1122
1124
  if (!this.isFetchingOptimistic) {
1123
1125
  // Schedule query gc after fetching
@@ -1387,18 +1389,23 @@
1387
1389
  class Mutation extends Removable {
1388
1390
  constructor(config) {
1389
1391
  super();
1390
- this.options = { ...config.defaultOptions,
1391
- ...config.options
1392
- };
1392
+ this.defaultOptions = config.defaultOptions;
1393
1393
  this.mutationId = config.mutationId;
1394
1394
  this.mutationCache = config.mutationCache;
1395
1395
  this.logger = config.logger || defaultLogger;
1396
1396
  this.observers = [];
1397
1397
  this.state = config.state || getDefaultState();
1398
- this.updateCacheTime(this.options.cacheTime);
1398
+ this.setOptions(config.options);
1399
1399
  this.scheduleGc();
1400
1400
  }
1401
1401
 
1402
+ setOptions(options) {
1403
+ this.options = { ...this.defaultOptions,
1404
+ ...options
1405
+ };
1406
+ this.updateCacheTime(this.options.cacheTime);
1407
+ }
1408
+
1402
1409
  get meta() {
1403
1410
  return this.options.meta;
1404
1411
  }
@@ -1488,7 +1495,7 @@
1488
1495
  const restored = this.state.status === 'loading';
1489
1496
 
1490
1497
  try {
1491
- var _this$mutationCache$c3, _this$mutationCache$c4, _this$options$onSucce, _this$options2, _this$options$onSettl, _this$options3;
1498
+ var _this$mutationCache$c3, _this$mutationCache$c4, _this$options$onSucce, _this$options2, _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onSettl, _this$options3;
1492
1499
 
1493
1500
  if (!restored) {
1494
1501
  var _this$mutationCache$c, _this$mutationCache$c2, _this$options$onMutat, _this$options;
@@ -1513,7 +1520,9 @@
1513
1520
  const data = await executeMutation(); // Notify cache callback
1514
1521
 
1515
1522
  await ((_this$mutationCache$c3 = (_this$mutationCache$c4 = this.mutationCache.config).onSuccess) == null ? void 0 : _this$mutationCache$c3.call(_this$mutationCache$c4, data, this.state.variables, this.state.context, this));
1516
- await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, this.state.variables, this.state.context));
1523
+ await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, this.state.variables, this.state.context)); // Notify cache callback
1524
+
1525
+ await ((_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onSettled) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, data, null, this.state.variables, this.state.context, this));
1517
1526
  await ((_this$options$onSettl = (_this$options3 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options3, data, null, this.state.variables, this.state.context));
1518
1527
  this.dispatch({
1519
1528
  type: 'success',
@@ -1522,16 +1531,18 @@
1522
1531
  return data;
1523
1532
  } catch (error) {
1524
1533
  try {
1525
- var _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onError, _this$options4, _this$options$onSettl2, _this$options5;
1534
+ var _this$mutationCache$c7, _this$mutationCache$c8, _this$options$onError, _this$options4, _this$mutationCache$c9, _this$mutationCache$c10, _this$options$onSettl2, _this$options5;
1526
1535
 
1527
1536
  // Notify cache callback
1528
- await ((_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, error, this.state.variables, this.state.context, this));
1537
+ await ((_this$mutationCache$c7 = (_this$mutationCache$c8 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c7.call(_this$mutationCache$c8, error, this.state.variables, this.state.context, this));
1529
1538
 
1530
1539
  if ("development" !== 'production') {
1531
1540
  this.logger.error(error);
1532
1541
  }
1533
1542
 
1534
- await ((_this$options$onError = (_this$options4 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options4, error, this.state.variables, this.state.context));
1543
+ await ((_this$options$onError = (_this$options4 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options4, error, this.state.variables, this.state.context)); // Notify cache callback
1544
+
1545
+ await ((_this$mutationCache$c9 = (_this$mutationCache$c10 = this.mutationCache.config).onSettled) == null ? void 0 : _this$mutationCache$c9.call(_this$mutationCache$c10, undefined, error, this.state.variables, this.state.context, this));
1535
1546
  await ((_this$options$onSettl2 = (_this$options5 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options5, undefined, error, this.state.variables, this.state.context));
1536
1547
  throw error;
1537
1548
  } finally {
@@ -2968,6 +2979,8 @@
2968
2979
  }
2969
2980
 
2970
2981
  setOptions(options) {
2982
+ var _this$currentMutation;
2983
+
2971
2984
  const prevOptions = this.options;
2972
2985
  this.options = this.client.defaultMutationOptions(options);
2973
2986
 
@@ -2978,13 +2991,15 @@
2978
2991
  observer: this
2979
2992
  });
2980
2993
  }
2994
+
2995
+ (_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.setOptions(this.options);
2981
2996
  }
2982
2997
 
2983
2998
  onUnsubscribe() {
2984
2999
  if (!this.listeners.length) {
2985
- var _this$currentMutation;
3000
+ var _this$currentMutation2;
2986
3001
 
2987
- (_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.removeObserver(this);
3002
+ (_this$currentMutation2 = this.currentMutation) == null ? void 0 : _this$currentMutation2.removeObserver(this);
2988
3003
  }
2989
3004
  }
2990
3005