@tanstack/vue-query 4.12.0 → 4.13.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.
@@ -1112,9 +1112,11 @@
1112
1112
  this.isFetchingOptimistic = false;
1113
1113
  },
1114
1114
  onError,
1115
- onFail: () => {
1115
+ onFail: (failureCount, error) => {
1116
1116
  this.dispatch({
1117
- type: 'failed'
1117
+ type: 'failed',
1118
+ failureCount,
1119
+ error
1118
1120
  });
1119
1121
  },
1120
1122
  onPause: () => {
@@ -1142,7 +1144,8 @@
1142
1144
  switch (action.type) {
1143
1145
  case 'failed':
1144
1146
  return { ...state,
1145
- fetchFailureCount: state.fetchFailureCount + 1
1147
+ fetchFailureCount: action.failureCount,
1148
+ fetchFailureReason: action.error
1146
1149
  };
1147
1150
 
1148
1151
  case 'pause':
@@ -1158,6 +1161,7 @@
1158
1161
  case 'fetch':
1159
1162
  return { ...state,
1160
1163
  fetchFailureCount: 0,
1164
+ fetchFailureReason: null,
1161
1165
  fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
1162
1166
  fetchStatus: canFetch(this.options.networkMode) ? 'fetching' : 'paused',
1163
1167
  ...(!state.dataUpdatedAt && {
@@ -1176,7 +1180,8 @@
1176
1180
  status: 'success',
1177
1181
  ...(!action.manual && {
1178
1182
  fetchStatus: 'idle',
1179
- fetchFailureCount: 0
1183
+ fetchFailureCount: 0,
1184
+ fetchFailureReason: null
1180
1185
  })
1181
1186
  };
1182
1187
 
@@ -1193,6 +1198,7 @@
1193
1198
  errorUpdateCount: state.errorUpdateCount + 1,
1194
1199
  errorUpdatedAt: Date.now(),
1195
1200
  fetchFailureCount: state.fetchFailureCount + 1,
1201
+ fetchFailureReason: error,
1196
1202
  fetchStatus: 'idle',
1197
1203
  status: 'error'
1198
1204
  };
@@ -1237,6 +1243,7 @@
1237
1243
  errorUpdateCount: 0,
1238
1244
  errorUpdatedAt: 0,
1239
1245
  fetchFailureCount: 0,
1246
+ fetchFailureReason: null,
1240
1247
  fetchMeta: null,
1241
1248
  isInvalidated: false,
1242
1249
  status: hasData ? 'success' : 'loading',
@@ -1441,9 +1448,11 @@
1441
1448
 
1442
1449
  return this.options.mutationFn(this.state.variables);
1443
1450
  },
1444
- onFail: () => {
1451
+ onFail: (failureCount, error) => {
1445
1452
  this.dispatch({
1446
- type: 'failed'
1453
+ type: 'failed',
1454
+ failureCount,
1455
+ error
1447
1456
  });
1448
1457
  },
1449
1458
  onPause: () => {
@@ -1526,7 +1535,8 @@
1526
1535
  switch (action.type) {
1527
1536
  case 'failed':
1528
1537
  return { ...state,
1529
- failureCount: state.failureCount + 1
1538
+ failureCount: action.failureCount,
1539
+ failureReason: action.error
1530
1540
  };
1531
1541
 
1532
1542
  case 'pause':
@@ -1543,6 +1553,8 @@
1543
1553
  return { ...state,
1544
1554
  context: action.context,
1545
1555
  data: undefined,
1556
+ failureCount: 0,
1557
+ failureReason: null,
1546
1558
  error: null,
1547
1559
  isPaused: !canFetch(this.options.networkMode),
1548
1560
  status: 'loading',
@@ -1552,6 +1564,8 @@
1552
1564
  case 'success':
1553
1565
  return { ...state,
1554
1566
  data: action.data,
1567
+ failureCount: 0,
1568
+ failureReason: null,
1555
1569
  error: null,
1556
1570
  status: 'success',
1557
1571
  isPaused: false
@@ -1562,6 +1576,7 @@
1562
1576
  data: undefined,
1563
1577
  error: action.error,
1564
1578
  failureCount: state.failureCount + 1,
1579
+ failureReason: action.error,
1565
1580
  isPaused: false,
1566
1581
  status: 'error'
1567
1582
  };
@@ -1593,6 +1608,7 @@
1593
1608
  data: undefined,
1594
1609
  error: null,
1595
1610
  failureCount: 0,
1611
+ failureReason: null,
1596
1612
  isPaused: false,
1597
1613
  status: 'idle',
1598
1614
  variables: undefined
@@ -2494,6 +2510,7 @@
2494
2510
  error,
2495
2511
  errorUpdatedAt,
2496
2512
  failureCount: state.fetchFailureCount,
2513
+ failureReason: state.fetchFailureReason,
2497
2514
  errorUpdateCount: state.errorUpdateCount,
2498
2515
  isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
2499
2516
  isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
@@ -3104,6 +3121,9 @@
3104
3121
  function isQueryKey(value) {
3105
3122
  return Array.isArray(value);
3106
3123
  }
3124
+ function isMutationKey(value) {
3125
+ return Array.isArray(vueDemi.isRef(value) ? value.value : value);
3126
+ }
3107
3127
  function updateState(state, update) {
3108
3128
  Object.keys(state).forEach(key => {
3109
3129
  state[key] = update[key];
@@ -4710,12 +4730,13 @@
4710
4730
  }
4711
4731
 
4712
4732
  function useMutation(arg1, arg2, arg3) {
4713
- var _options$queryClient;
4733
+ var _options$value$queryC;
4714
4734
 
4715
- const options = parseMutationArgs(arg1, arg2, arg3);
4716
- const queryClient = (_options$queryClient = options.queryClient) != null ? _options$queryClient : useQueryClient(options.queryClientKey);
4717
- const defaultedOptions = queryClient.defaultMutationOptions(options);
4718
- const observer = new MutationObserver(queryClient, defaultedOptions);
4735
+ const options = vueDemi.computed(() => {
4736
+ return parseMutationArgs(arg1, arg2, arg3);
4737
+ });
4738
+ const queryClient = (_options$value$queryC = options.value.queryClient) != null ? _options$value$queryC : useQueryClient(options.value.queryClientKey);
4739
+ const observer = new MutationObserver(queryClient, queryClient.defaultMutationOptions(options.value));
4719
4740
  const state = vueDemi.reactive(observer.getCurrentResult());
4720
4741
  const unsubscribe = observer.subscribe(result => {
4721
4742
  updateState(state, result);
@@ -4726,8 +4747,8 @@
4726
4747
  });
4727
4748
  };
4728
4749
 
4729
- vueDemi.watch([() => arg1, () => arg2, () => arg3], () => {
4730
- observer.setOptions(queryClient.defaultMutationOptions(parseMutationArgs(arg1, arg2, arg3)));
4750
+ vueDemi.watch(options, () => {
4751
+ observer.setOptions(queryClient.defaultMutationOptions(options.value));
4731
4752
  }, {
4732
4753
  deep: true
4733
4754
  });
@@ -4744,11 +4765,14 @@
4744
4765
  function parseMutationArgs(arg1, arg2, arg3) {
4745
4766
  let options = arg1;
4746
4767
 
4747
- if (isQueryKey(arg1)) {
4748
- if (typeof arg2 === 'function') {
4749
- options = { ...arg3,
4768
+ if (isMutationKey(arg1)) {
4769
+ const plainFn = vueDemi.isRef(arg2) ? arg2.value : arg2;
4770
+ const plainOptions = vueDemi.isRef(arg3) ? arg3.value : arg3;
4771
+
4772
+ if (typeof plainFn === 'function') {
4773
+ options = { ...plainOptions,
4750
4774
  mutationKey: arg1,
4751
- mutationFn: arg2
4775
+ mutationFn: plainFn
4752
4776
  };
4753
4777
  } else {
4754
4778
  options = { ...arg2,
@@ -4757,9 +4781,12 @@
4757
4781
  }
4758
4782
  }
4759
4783
 
4760
- if (typeof arg1 === 'function') {
4761
- options = { ...arg2,
4762
- mutationFn: arg1
4784
+ const plainFn = vueDemi.isRef(arg1) ? arg1.value : arg1;
4785
+ const plainOptions = vueDemi.isRef(arg2) ? arg2.value : arg2;
4786
+
4787
+ if (typeof plainFn === 'function') {
4788
+ options = { ...plainOptions,
4789
+ mutationFn: plainFn
4763
4790
  };
4764
4791
  }
4765
4792