@tanstack/vue-query 5.0.0-alpha.2 → 5.0.0-alpha.21

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.
Files changed (62) hide show
  1. package/build/lib/__mocks__/useBaseQuery.d.ts +1 -2
  2. package/build/lib/__mocks__/useQueryClient.d.ts +1 -2
  3. package/build/lib/devtools/devtools.esm.js +50 -9
  4. package/build/lib/devtools/devtools.esm.js.map +1 -1
  5. package/build/lib/devtools/devtools.js +50 -9
  6. package/build/lib/devtools/devtools.js.map +1 -1
  7. package/build/lib/devtools/devtools.mjs +46 -7
  8. package/build/lib/devtools/devtools.mjs.map +1 -1
  9. package/build/lib/devtools/utils.esm.js +0 -1
  10. package/build/lib/devtools/utils.esm.js.map +1 -1
  11. package/build/lib/devtools/utils.js +0 -1
  12. package/build/lib/devtools/utils.js.map +1 -1
  13. package/build/lib/devtools/utils.mjs +0 -1
  14. package/build/lib/devtools/utils.mjs.map +1 -1
  15. package/build/lib/index.d.ts +2 -2
  16. package/build/lib/index.esm.js +1 -1
  17. package/build/lib/index.js +3 -2
  18. package/build/lib/index.js.map +1 -1
  19. package/build/lib/index.mjs +1 -1
  20. package/build/lib/queryClient.esm.js +1 -1
  21. package/build/lib/queryClient.esm.js.map +1 -1
  22. package/build/lib/queryClient.js +1 -1
  23. package/build/lib/queryClient.js.map +1 -1
  24. package/build/lib/useBaseQuery.esm.js.map +1 -1
  25. package/build/lib/useBaseQuery.js.map +1 -1
  26. package/build/lib/useBaseQuery.mjs.map +1 -1
  27. package/build/lib/useMutationState.d.ts +12 -0
  28. package/build/lib/useMutationState.esm.js +33 -0
  29. package/build/lib/useMutationState.esm.js.map +1 -0
  30. package/build/lib/useMutationState.js +36 -0
  31. package/build/lib/useMutationState.js.map +1 -0
  32. package/build/lib/useMutationState.mjs +33 -0
  33. package/build/lib/useMutationState.mjs.map +1 -0
  34. package/build/lib/useQueries.d.ts +2 -3
  35. package/build/lib/useQueries.esm.js +4 -5
  36. package/build/lib/useQueries.esm.js.map +1 -1
  37. package/build/lib/useQueries.js +4 -5
  38. package/build/lib/useQueries.js.map +1 -1
  39. package/build/lib/useQueries.mjs +4 -5
  40. package/build/lib/useQueries.mjs.map +1 -1
  41. package/build/lib/useQueryClient.esm.js +2 -1
  42. package/build/lib/useQueryClient.esm.js.map +1 -1
  43. package/build/lib/useQueryClient.js +2 -1
  44. package/build/lib/useQueryClient.js.map +1 -1
  45. package/build/lib/vueQueryPlugin.esm.js +0 -2
  46. package/build/lib/vueQueryPlugin.esm.js.map +1 -1
  47. package/build/lib/vueQueryPlugin.js +0 -2
  48. package/build/lib/vueQueryPlugin.js.map +1 -1
  49. package/build/lib/vueQueryPlugin.mjs +0 -2
  50. package/build/lib/vueQueryPlugin.mjs.map +1 -1
  51. package/build/umd/index.development.js +167 -135
  52. package/build/umd/index.development.js.map +1 -1
  53. package/build/umd/index.production.js +1 -1
  54. package/build/umd/index.production.js.map +1 -1
  55. package/package.json +6 -6
  56. package/build/lib/useIsMutating.d.ts +0 -6
  57. package/build/lib/useIsMutating.esm.js +0 -24
  58. package/build/lib/useIsMutating.esm.js.map +0 -1
  59. package/build/lib/useIsMutating.js +0 -26
  60. package/build/lib/useIsMutating.js.map +0 -1
  61. package/build/lib/useIsMutating.mjs +0 -24
  62. package/build/lib/useIsMutating.mjs.map +0 -1
@@ -1024,7 +1024,7 @@
1024
1024
  this.state = reducer(this.state);
1025
1025
  notifyManager.batch(() => {
1026
1026
  this.#observers.forEach(observer => {
1027
- observer.onQueryUpdate(action);
1027
+ observer.onQueryUpdate();
1028
1028
  });
1029
1029
  this.#cache.notify({
1030
1030
  query: this,
@@ -1116,10 +1116,11 @@
1116
1116
  return [...this.#queries.values()];
1117
1117
  }
1118
1118
  find(filters) {
1119
- if (typeof filters.exact === 'undefined') {
1120
- filters.exact = true;
1121
- }
1122
- return this.getAll().find(query => matchQuery(filters, query));
1119
+ const defaultedFilters = {
1120
+ exact: true,
1121
+ ...filters
1122
+ };
1123
+ return this.getAll().find(query => matchQuery(defaultedFilters, query));
1123
1124
  }
1124
1125
  findAll(filters = {}) {
1125
1126
  const queries = this.getAll();
@@ -1154,18 +1155,26 @@
1154
1155
 
1155
1156
  class Mutation extends Removable {
1156
1157
  #observers;
1158
+ #defaultOptions;
1157
1159
  #mutationCache;
1158
1160
  #retryer;
1159
1161
  constructor(config) {
1160
1162
  super();
1161
- this.options = config.options;
1162
1163
  this.mutationId = config.mutationId;
1164
+ this.#defaultOptions = config.defaultOptions;
1163
1165
  this.#mutationCache = config.mutationCache;
1164
1166
  this.#observers = [];
1165
1167
  this.state = config.state || getDefaultState();
1166
- this.updateGcTime(this.options.gcTime);
1168
+ this.setOptions(config.options);
1167
1169
  this.scheduleGc();
1168
1170
  }
1171
+ setOptions(options) {
1172
+ this.options = {
1173
+ ...this.#defaultOptions,
1174
+ ...options
1175
+ };
1176
+ this.updateGcTime(this.options.gcTime);
1177
+ }
1169
1178
  get meta() {
1170
1179
  return this.options.meta;
1171
1180
  }
@@ -1417,10 +1426,11 @@
1417
1426
  return this.#mutations;
1418
1427
  }
1419
1428
  find(filters) {
1420
- if (typeof filters.exact === 'undefined') {
1421
- filters.exact = true;
1422
- }
1423
- return this.#mutations.find(mutation => matchMutation(filters, mutation));
1429
+ const defaultedFilters = {
1430
+ exact: true,
1431
+ ...filters
1432
+ };
1433
+ return this.#mutations.find(mutation => matchMutation(defaultedFilters, mutation));
1424
1434
  }
1425
1435
  findAll(filters = {}) {
1426
1436
  return this.#mutations.filter(mutation => matchMutation(filters, mutation));
@@ -1446,12 +1456,15 @@
1446
1456
  function infiniteQueryBehavior() {
1447
1457
  return {
1448
1458
  onFetch: context => {
1449
- context.fetchFn = () => {
1459
+ context.fetchFn = async () => {
1450
1460
  const options = context.options;
1451
1461
  const direction = context.fetchOptions?.meta?.fetchMore?.direction;
1452
1462
  const oldPages = context.state.data?.pages || [];
1453
1463
  const oldPageParams = context.state.data?.pageParams || [];
1454
- let newPageParams = oldPageParams;
1464
+ const empty = {
1465
+ pages: [],
1466
+ pageParams: []
1467
+ };
1455
1468
  let cancelled = false;
1456
1469
  const addSignalProperty = object => {
1457
1470
  Object.defineProperty(object, 'signal', {
@@ -1471,95 +1484,95 @@
1471
1484
 
1472
1485
  // Get query function
1473
1486
  const queryFn = context.options.queryFn || (() => Promise.reject(new Error('Missing queryFn')));
1474
- const buildNewPages = (pages, param, page, previous) => {
1475
- const {
1476
- maxPages
1477
- } = context.options;
1478
- if (previous) {
1479
- newPageParams = addToStart(newPageParams, param, maxPages);
1480
- return addToStart(pages, page, maxPages);
1481
- }
1482
- newPageParams = addToEnd(newPageParams, param, maxPages);
1483
- return addToEnd(pages, page, maxPages);
1484
- };
1485
1487
 
1486
1488
  // Create function to fetch a page
1487
- const fetchPage = (pages, param, previous) => {
1489
+ const fetchPage = async (data, param, previous) => {
1488
1490
  if (cancelled) {
1489
1491
  return Promise.reject();
1490
1492
  }
1491
- if (typeof param === 'undefined' && pages.length) {
1492
- return Promise.resolve(pages);
1493
+ if (typeof param === 'undefined' && data.pages.length) {
1494
+ return Promise.resolve(data);
1493
1495
  }
1494
1496
  const queryFnContext = {
1495
1497
  queryKey: context.queryKey,
1496
1498
  pageParam: param,
1499
+ direction: previous ? 'backward' : 'forward',
1497
1500
  meta: context.options.meta
1498
1501
  };
1499
1502
  addSignalProperty(queryFnContext);
1500
- const queryFnResult = queryFn(queryFnContext);
1501
- const promise = Promise.resolve(queryFnResult).then(page => buildNewPages(pages, param, page, previous));
1502
- return promise;
1503
+ const page = await queryFn(queryFnContext);
1504
+ const {
1505
+ maxPages
1506
+ } = context.options;
1507
+ const addTo = previous ? addToStart : addToEnd;
1508
+ return {
1509
+ pages: addTo(data.pages, page, maxPages),
1510
+ pageParams: addTo(data.pageParams, param, maxPages)
1511
+ };
1503
1512
  };
1504
- let promise;
1513
+ let result;
1505
1514
 
1506
1515
  // Fetch first page?
1507
1516
  if (!oldPages.length) {
1508
- promise = fetchPage([], options.defaultPageParam);
1517
+ result = await fetchPage(empty, options.defaultPageParam);
1509
1518
  }
1510
1519
 
1511
1520
  // fetch next / previous page?
1512
1521
  else if (direction) {
1513
1522
  const previous = direction === 'backward';
1514
- const param = previous ? getPreviousPageParam(options, oldPages) : getNextPageParam(options, oldPages);
1515
- promise = fetchPage(oldPages, param, previous);
1523
+ const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
1524
+ const oldData = {
1525
+ pages: oldPages,
1526
+ pageParams: oldPageParams
1527
+ };
1528
+ const param = pageParamFn(options, oldData);
1529
+ result = await fetchPage(oldData, param, previous);
1516
1530
  }
1517
1531
 
1518
1532
  // Refetch pages
1519
1533
  else {
1520
- newPageParams = [];
1521
-
1522
1534
  // Fetch first page
1523
- promise = fetchPage([], oldPageParams[0]);
1535
+ result = await fetchPage(empty, oldPageParams[0]);
1524
1536
 
1525
1537
  // Fetch remaining pages
1526
1538
  for (let i = 1; i < oldPages.length; i++) {
1527
- promise = promise.then(pages => {
1528
- const param = getNextPageParam(options, pages);
1529
- return fetchPage(pages, param);
1530
- });
1539
+ const param = getNextPageParam(options, result);
1540
+ result = await fetchPage(result, param);
1531
1541
  }
1532
1542
  }
1533
- const finalPromise = promise.then(pages => ({
1534
- pages,
1535
- pageParams: newPageParams
1536
- }));
1537
- return finalPromise;
1543
+ return result;
1538
1544
  };
1539
1545
  }
1540
1546
  };
1541
1547
  }
1542
- function getNextPageParam(options, pages) {
1543
- return options.getNextPageParam(pages[pages.length - 1], pages);
1548
+ function getNextPageParam(options, {
1549
+ pages,
1550
+ pageParams
1551
+ }) {
1552
+ const lastIndex = pages.length - 1;
1553
+ return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams);
1544
1554
  }
1545
- function getPreviousPageParam(options, pages) {
1546
- return options.getPreviousPageParam?.(pages[0], pages);
1555
+ function getPreviousPageParam(options, {
1556
+ pages,
1557
+ pageParams
1558
+ }) {
1559
+ return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
1547
1560
  }
1548
1561
 
1549
1562
  /**
1550
1563
  * Checks if there is a next page.
1551
1564
  */
1552
- function hasNextPage(options, pages) {
1553
- if (!pages) return false;
1554
- return typeof getNextPageParam(options, pages) !== 'undefined';
1565
+ function hasNextPage(options, data) {
1566
+ if (!data) return false;
1567
+ return typeof getNextPageParam(options, data) !== 'undefined';
1555
1568
  }
1556
1569
 
1557
1570
  /**
1558
1571
  * Checks if there is a previous page.
1559
1572
  */
1560
- function hasPreviousPage(options, pages) {
1561
- if (!pages || !options.getPreviousPageParam) return false;
1562
- return typeof getPreviousPageParam(options, pages) !== 'undefined';
1573
+ function hasPreviousPage(options, data) {
1574
+ if (!data || !options.getPreviousPageParam) return false;
1575
+ return typeof getPreviousPageParam(options, data) !== 'undefined';
1563
1576
  }
1564
1577
 
1565
1578
  // CLASS
@@ -1684,10 +1697,11 @@
1684
1697
  });
1685
1698
  }
1686
1699
  cancelQueries(filters = {}, cancelOptions = {}) {
1687
- if (typeof cancelOptions.revert === 'undefined') {
1688
- cancelOptions.revert = true;
1689
- }
1690
- const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
1700
+ const defaultedCancelOptions = {
1701
+ revert: true,
1702
+ ...cancelOptions
1703
+ };
1704
+ const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(defaultedCancelOptions)));
1691
1705
  return Promise.all(promises).then(noop).catch(noop);
1692
1706
  }
1693
1707
  invalidateQueries(filters = {}, options = {}) {
@@ -1836,10 +1850,12 @@
1836
1850
  #currentResult = undefined;
1837
1851
  #currentResultState;
1838
1852
  #currentResultOptions;
1839
- #previousQueryResult;
1840
1853
  #selectError;
1841
1854
  #selectFn;
1842
1855
  #selectResult;
1856
+ // This property keeps track of the last defined query data.
1857
+ // It will be used to pass the previous data to the placeholder function between renders.
1858
+ #lastDefinedQueryData;
1843
1859
  #staleTimeoutId;
1844
1860
  #refetchIntervalId;
1845
1861
  #currentRefetchInterval;
@@ -2034,7 +2050,6 @@
2034
2050
  const prevResultOptions = this.#currentResultOptions;
2035
2051
  const queryChange = query !== prevQuery;
2036
2052
  const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
2037
- const prevQueryResult = queryChange ? this.#currentResult : this.#previousQueryResult;
2038
2053
  const {
2039
2054
  state
2040
2055
  } = query;
@@ -2093,7 +2108,7 @@
2093
2108
  if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
2094
2109
  placeholderData = prevResult.data;
2095
2110
  } else {
2096
- placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(prevQueryResult?.data) : options.placeholderData;
2111
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastDefinedQueryData) : options.placeholderData;
2097
2112
  if (options.select && typeof placeholderData !== 'undefined') {
2098
2113
  try {
2099
2114
  placeholderData = options.select(placeholderData);
@@ -2157,6 +2172,9 @@
2157
2172
  if (shallowEqualObjects(nextResult, prevResult)) {
2158
2173
  return;
2159
2174
  }
2175
+ if (this.#currentResultState.data !== undefined) {
2176
+ this.#lastDefinedQueryData = this.#currentResultState.data;
2177
+ }
2160
2178
  this.#currentResult = nextResult;
2161
2179
 
2162
2180
  // Determine which callbacks to trigger
@@ -2197,36 +2215,20 @@
2197
2215
  const prevQuery = this.#currentQuery;
2198
2216
  this.#currentQuery = query;
2199
2217
  this.#currentQueryInitialState = query.state;
2200
- this.#previousQueryResult = this.#currentResult;
2201
2218
  if (this.hasListeners()) {
2202
2219
  prevQuery?.removeObserver(this);
2203
2220
  query.addObserver(this);
2204
2221
  }
2205
2222
  }
2206
- onQueryUpdate(action) {
2207
- const notifyOptions = {};
2208
- if (action.type === 'success') {
2209
- notifyOptions.onSuccess = !action.manual;
2210
- } else if (action.type === 'error' && !isCancelledError(action.error)) {
2211
- notifyOptions.onError = true;
2212
- }
2213
- this.#updateResult(notifyOptions);
2223
+ onQueryUpdate() {
2224
+ this.#updateResult();
2214
2225
  if (this.hasListeners()) {
2215
2226
  this.#updateTimers();
2216
2227
  }
2217
2228
  }
2218
2229
  #notify(notifyOptions) {
2219
2230
  notifyManager.batch(() => {
2220
- // First trigger the configuration callbacks
2221
- if (notifyOptions.onSuccess) {
2222
- this.options.onSuccess?.(this.#currentResult.data);
2223
- this.options.onSettled?.(this.#currentResult.data, null);
2224
- } else if (notifyOptions.onError) {
2225
- this.options.onError?.(this.#currentResult.error);
2226
- this.options.onSettled?.(undefined, this.#currentResult.error);
2227
- }
2228
-
2229
- // Then trigger the listeners
2231
+ // First, trigger the listeners
2230
2232
  if (notifyOptions.listeners) {
2231
2233
  this.listeners.forEach(listener => {
2232
2234
  listener(this.#currentResult);
@@ -2348,9 +2350,10 @@
2348
2350
  }
2349
2351
  #findMatchingObservers(queries) {
2350
2352
  const prevObservers = this.#observers;
2353
+ const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
2351
2354
  const defaultedQueryOptions = queries.map(options => this.#client.defaultQueryOptions(options));
2352
2355
  const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
2353
- const match = prevObservers.find(observer => observer.options.queryHash === defaultedOptions.queryHash);
2356
+ const match = prevObserversMap.get(defaultedOptions.queryHash);
2354
2357
  if (match != null) {
2355
2358
  return [{
2356
2359
  defaultedQueryOptions: defaultedOptions,
@@ -2359,8 +2362,8 @@
2359
2362
  }
2360
2363
  return [];
2361
2364
  });
2362
- const matchedQueryHashes = matchingObservers.map(match => match.defaultedQueryOptions.queryHash);
2363
- const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
2365
+ const matchedQueryHashes = new Set(matchingObservers.map(match => match.defaultedQueryOptions.queryHash));
2366
+ const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.has(defaultedOptions.queryHash));
2364
2367
  const getObserver = options => {
2365
2368
  const defaultedOptions = this.#client.defaultQueryOptions(options);
2366
2369
  const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
@@ -2417,7 +2420,7 @@
2417
2420
  options.behavior = infiniteQueryBehavior();
2418
2421
  return super.getOptimisticResult(options);
2419
2422
  }
2420
- fetchNextPage(options = {}) {
2423
+ fetchNextPage(options) {
2421
2424
  return this.fetch({
2422
2425
  ...options,
2423
2426
  meta: {
@@ -2427,9 +2430,7 @@
2427
2430
  }
2428
2431
  });
2429
2432
  }
2430
- fetchPreviousPage({
2431
- ...options
2432
- } = {}) {
2433
+ fetchPreviousPage(options) {
2433
2434
  return this.fetch({
2434
2435
  ...options,
2435
2436
  meta: {
@@ -2454,8 +2455,8 @@
2454
2455
  ...result,
2455
2456
  fetchNextPage: this.fetchNextPage,
2456
2457
  fetchPreviousPage: this.fetchPreviousPage,
2457
- hasNextPage: hasNextPage(options, state.data?.pages),
2458
- hasPreviousPage: hasPreviousPage(options, state.data?.pages),
2458
+ hasNextPage: hasNextPage(options, state.data),
2459
+ hasPreviousPage: hasPreviousPage(options, state.data),
2459
2460
  isFetchingNextPage,
2460
2461
  isFetchingPreviousPage,
2461
2462
  isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
@@ -2493,6 +2494,7 @@
2493
2494
  observer: this
2494
2495
  });
2495
2496
  }
2497
+ this.#currentMutation?.setOptions(this.options);
2496
2498
  }
2497
2499
  onUnsubscribe() {
2498
2500
  if (!this.listeners.length) {
@@ -2580,24 +2582,10 @@
2580
2582
  return query.state.status === 'success';
2581
2583
  }
2582
2584
  function dehydrate(client, options = {}) {
2583
- const mutations = [];
2584
- const queries = [];
2585
- if (options.dehydrateMutations !== false) {
2586
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
2587
- client.getMutationCache().getAll().forEach(mutation => {
2588
- if (shouldDehydrateMutation(mutation)) {
2589
- mutations.push(dehydrateMutation(mutation));
2590
- }
2591
- });
2592
- }
2593
- if (options.dehydrateQueries !== false) {
2594
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
2595
- client.getQueryCache().getAll().forEach(query => {
2596
- if (shouldDehydrateQuery(query)) {
2597
- queries.push(dehydrateQuery(query));
2598
- }
2599
- });
2600
- }
2585
+ const filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
2586
+ const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);
2587
+ const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
2588
+ const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);
2601
2589
  return {
2602
2590
  mutations,
2603
2591
  queries
@@ -3665,7 +3653,6 @@
3665
3653
  };
3666
3654
  }
3667
3655
 
3668
- /* istanbul ignore file */
3669
3656
  // eslint-disable-next-line no-shadow
3670
3657
  var QueryState;
3671
3658
  (function (QueryState) {
@@ -3743,7 +3730,6 @@
3743
3730
  'Last Updated': dateSort
3744
3731
  };
3745
3732
 
3746
- /* istanbul ignore file */
3747
3733
  const pluginId = 'vue-query';
3748
3734
  const pluginName = 'Vue Query';
3749
3735
  function setupDevtools(app, queryClient) {
@@ -3751,8 +3737,8 @@
3751
3737
  id: pluginId,
3752
3738
  label: pluginName,
3753
3739
  packageName: 'vue-query',
3754
- homepage: 'https://tanstack.com/query/v4',
3755
- logo: 'https://vue-query.vercel.app/vue-query.svg',
3740
+ homepage: 'https://tanstack.com/query/latest',
3741
+ logo: 'https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.svg',
3756
3742
  app,
3757
3743
  settings: {
3758
3744
  baseSort: {
@@ -3776,16 +3762,31 @@
3776
3762
  value: key
3777
3763
  })),
3778
3764
  defaultValue: Object.keys(sortFns)[0]
3765
+ },
3766
+ onlineMode: {
3767
+ type: 'choice',
3768
+ component: 'button-group',
3769
+ label: 'Online mode',
3770
+ options: [{
3771
+ label: 'Online',
3772
+ value: 1
3773
+ }, {
3774
+ label: 'Offline',
3775
+ value: 0
3776
+ }],
3777
+ defaultValue: 1
3779
3778
  }
3780
3779
  }
3781
3780
  }, api => {
3781
+ const initialSettings = api.getSettings();
3782
+ onlineManager.setOnline(Boolean(initialSettings.onlineMode.valueOf()));
3782
3783
  const queryCache = queryClient.getQueryCache();
3783
3784
  api.addInspector({
3784
3785
  id: pluginId,
3785
3786
  label: pluginName,
3786
3787
  icon: 'api',
3787
3788
  nodeActions: [{
3788
- icon: 'cloud_download',
3789
+ icon: 'file_download',
3789
3790
  tooltip: 'Refetch',
3790
3791
  action: queryHash => {
3791
3792
  queryCache.get(queryHash)?.fetch();
@@ -3810,6 +3811,27 @@
3810
3811
  const query = queryCache.get(queryHash);
3811
3812
  queryCache.remove(query);
3812
3813
  }
3814
+ }, {
3815
+ icon: 'hourglass_empty',
3816
+ tooltip: 'Force loading',
3817
+ action: queryHash => {
3818
+ const query = queryCache.get(queryHash);
3819
+ query.setState({
3820
+ data: undefined,
3821
+ status: 'pending'
3822
+ });
3823
+ }
3824
+ }, {
3825
+ icon: 'error_outline',
3826
+ tooltip: 'Force error',
3827
+ action: queryHash => {
3828
+ const query = queryCache.get(queryHash);
3829
+ query.setState({
3830
+ data: undefined,
3831
+ status: 'error',
3832
+ error: new Error('Unknown error from devtools')
3833
+ });
3834
+ }
3813
3835
  }]
3814
3836
  });
3815
3837
  api.addTimelineLayer({
@@ -3820,9 +3842,7 @@
3820
3842
  queryCache.subscribe(event => {
3821
3843
  api.sendInspectorTree(pluginId);
3822
3844
  api.sendInspectorState(pluginId);
3823
- if (
3824
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
3825
- event && ['queryAdded', 'queryRemoved', 'queryUpdated'].includes(event.type)) {
3845
+ if (['added', 'removed', 'updated'].includes(event.type)) {
3826
3846
  api.addTimelineEvent({
3827
3847
  layerId: pluginId,
3828
3848
  event: {
@@ -3837,6 +3857,11 @@
3837
3857
  });
3838
3858
  }
3839
3859
  });
3860
+ api.on.setPluginSettings(payload => {
3861
+ if (payload.key === 'onlineMode') {
3862
+ onlineManager.setOnline(Boolean(payload.newValue));
3863
+ }
3864
+ });
3840
3865
  api.on.getInspectorTree(payload => {
3841
3866
  if (payload.inspectorId === pluginId) {
3842
3867
  const queries = queryCache.getAll();
@@ -3929,8 +3954,6 @@
3929
3954
  originalUnmount();
3930
3955
  };
3931
3956
  }
3932
-
3933
- /* istanbul ignore next */
3934
3957
  if (vueDemi.isVue2) {
3935
3958
  app.mixin({
3936
3959
  beforeCreate() {
@@ -4030,9 +4053,8 @@
4030
4053
 
4031
4054
  /* eslint-disable @typescript-eslint/no-explicit-any */
4032
4055
  function useQueries({
4033
- queries,
4034
- queryClient
4035
- }) {
4056
+ queries
4057
+ }, queryClient) {
4036
4058
  const client = queryClient || useQueryClient();
4037
4059
  const defaultedQueries = vueDemi.computed(() => cloneDeepUnref(queries).map(options => {
4038
4060
  const defaulted = client.defaultQueryOptions(options);
@@ -4051,14 +4073,14 @@
4051
4073
  state.value.splice(0, result.length, ...result);
4052
4074
  });
4053
4075
  // Subscription would not fire for persisted results
4054
- state.value.splice(0, state.value.length, ...observer.getOptimisticResult(defaultedQueries.value));
4076
+ state.value = observer.getOptimisticResult(defaultedQueries.value);
4055
4077
  }
4056
4078
  }, {
4057
4079
  immediate: true
4058
4080
  });
4059
4081
  vueDemi.watch(defaultedQueries, () => {
4060
4082
  observer.setQueries(defaultedQueries.value);
4061
- state.value.splice(0, state.value.length, ...observer.getCurrentResult());
4083
+ state.value = observer.getCurrentResult();
4062
4084
  }, {
4063
4085
  deep: true
4064
4086
  });
@@ -4131,22 +4153,31 @@
4131
4153
  return isFetching;
4132
4154
  }
4133
4155
 
4134
- function useIsMutating(mutationFilters = {}, queryClient) {
4135
- const filters = vueDemi.computed(() => cloneDeepUnref(mutationFilters));
4156
+ function useIsMutating(filters = {}, queryClient) {
4136
4157
  const client = queryClient || useQueryClient();
4137
- const isMutating = vueDemi.ref(client.isMutating(filters));
4138
- const unsubscribe = client.getMutationCache().subscribe(() => {
4139
- isMutating.value = client.isMutating(filters);
4140
- });
4141
- vueDemi.watch(filters, () => {
4142
- isMutating.value = client.isMutating(filters);
4143
- }, {
4144
- deep: true
4158
+ const unreffedFilters = vueDemi.computed(() => ({
4159
+ ...cloneDeepUnref(filters),
4160
+ status: 'pending'
4161
+ }));
4162
+ const length = vueDemi.computed(() => useMutationState({
4163
+ filters: unreffedFilters
4164
+ }, client).value.length);
4165
+ return length;
4166
+ }
4167
+ function getResult(mutationCache, options) {
4168
+ return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);
4169
+ }
4170
+ function useMutationState(options = {}, queryClient) {
4171
+ const mutationCache = (queryClient || useQueryClient()).getMutationCache();
4172
+ const state = vueDemi.ref(getResult(mutationCache, options));
4173
+ const unsubscribe = mutationCache.subscribe(() => {
4174
+ const result = getResult(mutationCache, options);
4175
+ state.value = result;
4145
4176
  });
4146
4177
  vueDemi.onScopeDispose(() => {
4147
4178
  unsubscribe();
4148
4179
  });
4149
- return isMutating;
4180
+ return vueDemi.readonly(state);
4150
4181
  }
4151
4182
 
4152
4183
  exports.CancelledError = CancelledError;
@@ -4176,6 +4207,7 @@
4176
4207
  exports.useIsFetching = useIsFetching;
4177
4208
  exports.useIsMutating = useIsMutating;
4178
4209
  exports.useMutation = useMutation;
4210
+ exports.useMutationState = useMutationState;
4179
4211
  exports.useQueries = useQueries;
4180
4212
  exports.useQuery = useQuery;
4181
4213
  exports.useQueryClient = useQueryClient;