@tanstack/vue-query 5.0.0-alpha.10 → 5.0.0-alpha.18

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.
@@ -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();
@@ -1425,10 +1426,11 @@
1425
1426
  return this.#mutations;
1426
1427
  }
1427
1428
  find(filters) {
1428
- if (typeof filters.exact === 'undefined') {
1429
- filters.exact = true;
1430
- }
1431
- 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));
1432
1434
  }
1433
1435
  findAll(filters = {}) {
1434
1436
  return this.#mutations.filter(mutation => matchMutation(filters, mutation));
@@ -1695,10 +1697,11 @@
1695
1697
  });
1696
1698
  }
1697
1699
  cancelQueries(filters = {}, cancelOptions = {}) {
1698
- if (typeof cancelOptions.revert === 'undefined') {
1699
- cancelOptions.revert = true;
1700
- }
1701
- 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)));
1702
1705
  return Promise.all(promises).then(noop).catch(noop);
1703
1706
  }
1704
1707
  invalidateQueries(filters = {}, options = {}) {
@@ -2590,24 +2593,10 @@
2590
2593
  return query.state.status === 'success';
2591
2594
  }
2592
2595
  function dehydrate(client, options = {}) {
2593
- const mutations = [];
2594
- const queries = [];
2595
- if (options.dehydrateMutations !== false) {
2596
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
2597
- client.getMutationCache().getAll().forEach(mutation => {
2598
- if (shouldDehydrateMutation(mutation)) {
2599
- mutations.push(dehydrateMutation(mutation));
2600
- }
2601
- });
2602
- }
2603
- if (options.dehydrateQueries !== false) {
2604
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
2605
- client.getQueryCache().getAll().forEach(query => {
2606
- if (shouldDehydrateQuery(query)) {
2607
- queries.push(dehydrateQuery(query));
2608
- }
2609
- });
2610
- }
2596
+ const filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
2597
+ const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);
2598
+ const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
2599
+ const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);
2611
2600
  return {
2612
2601
  mutations,
2613
2602
  queries