@tanstack/query-core 5.0.0-alpha.1 → 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.
Files changed (143) hide show
  1. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js +13 -0
  2. package/build/lib/_virtual/_rollupPluginBabelHelpers.esm.js.map +1 -0
  3. package/build/lib/_virtual/_rollupPluginBabelHelpers.js +16 -0
  4. package/build/lib/_virtual/_rollupPluginBabelHelpers.js.map +1 -0
  5. package/build/lib/focusManager.esm.js +31 -15
  6. package/build/lib/focusManager.esm.js.map +1 -1
  7. package/build/lib/focusManager.js +31 -15
  8. package/build/lib/focusManager.js.map +1 -1
  9. package/build/lib/hydration.d.ts +2 -6
  10. package/build/lib/hydration.esm.js +9 -20
  11. package/build/lib/hydration.esm.js.map +1 -1
  12. package/build/lib/hydration.js +9 -20
  13. package/build/lib/hydration.js.map +1 -1
  14. package/build/lib/hydration.mjs +4 -18
  15. package/build/lib/hydration.mjs.map +1 -1
  16. package/build/lib/index.d.ts +4 -4
  17. package/build/lib/index.esm.js +1 -1
  18. package/build/lib/index.js +1 -0
  19. package/build/lib/index.js.map +1 -1
  20. package/build/lib/index.mjs +1 -1
  21. package/build/lib/infiniteQueryBehavior.d.ts +2 -2
  22. package/build/lib/infiniteQueryBehavior.esm.js +52 -48
  23. package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
  24. package/build/lib/infiniteQueryBehavior.js +52 -48
  25. package/build/lib/infiniteQueryBehavior.js.map +1 -1
  26. package/build/lib/infiniteQueryBehavior.mjs +48 -45
  27. package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
  28. package/build/lib/infiniteQueryObserver.d.ts +7 -7
  29. package/build/lib/infiniteQueryObserver.esm.js +7 -8
  30. package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
  31. package/build/lib/infiniteQueryObserver.js +7 -8
  32. package/build/lib/infiniteQueryObserver.js.map +1 -1
  33. package/build/lib/infiniteQueryObserver.mjs +4 -6
  34. package/build/lib/infiniteQueryObserver.mjs.map +1 -1
  35. package/build/lib/mutation.d.ts +5 -4
  36. package/build/lib/mutation.esm.js +138 -99
  37. package/build/lib/mutation.esm.js.map +1 -1
  38. package/build/lib/mutation.js +138 -99
  39. package/build/lib/mutation.js.map +1 -1
  40. package/build/lib/mutation.mjs +16 -2
  41. package/build/lib/mutation.mjs.map +1 -1
  42. package/build/lib/mutationCache.d.ts +5 -4
  43. package/build/lib/mutationCache.esm.js +34 -20
  44. package/build/lib/mutationCache.esm.js.map +1 -1
  45. package/build/lib/mutationCache.js +34 -20
  46. package/build/lib/mutationCache.js.map +1 -1
  47. package/build/lib/mutationCache.mjs +5 -4
  48. package/build/lib/mutationCache.mjs.map +1 -1
  49. package/build/lib/mutationObserver.d.ts +2 -2
  50. package/build/lib/mutationObserver.esm.js +81 -50
  51. package/build/lib/mutationObserver.esm.js.map +1 -1
  52. package/build/lib/mutationObserver.js +81 -50
  53. package/build/lib/mutationObserver.js.map +1 -1
  54. package/build/lib/mutationObserver.mjs +1 -0
  55. package/build/lib/mutationObserver.mjs.map +1 -1
  56. package/build/lib/onlineManager.esm.js +29 -14
  57. package/build/lib/onlineManager.esm.js.map +1 -1
  58. package/build/lib/onlineManager.js +29 -14
  59. package/build/lib/onlineManager.js.map +1 -1
  60. package/build/lib/queriesObserver.esm.js +94 -69
  61. package/build/lib/queriesObserver.esm.js.map +1 -1
  62. package/build/lib/queriesObserver.js +94 -69
  63. package/build/lib/queriesObserver.js.map +1 -1
  64. package/build/lib/queriesObserver.mjs +1 -5
  65. package/build/lib/queriesObserver.mjs.map +1 -1
  66. package/build/lib/query.d.ts +8 -7
  67. package/build/lib/query.esm.js +210 -159
  68. package/build/lib/query.esm.js.map +1 -1
  69. package/build/lib/query.js +210 -159
  70. package/build/lib/query.js.map +1 -1
  71. package/build/lib/query.mjs +2 -0
  72. package/build/lib/query.mjs.map +1 -1
  73. package/build/lib/queryCache.d.ts +5 -4
  74. package/build/lib/queryCache.esm.js +21 -13
  75. package/build/lib/queryCache.esm.js.map +1 -1
  76. package/build/lib/queryCache.js +21 -13
  77. package/build/lib/queryCache.js.map +1 -1
  78. package/build/lib/queryCache.mjs +5 -4
  79. package/build/lib/queryCache.mjs.map +1 -1
  80. package/build/lib/queryClient.d.ts +7 -7
  81. package/build/lib/queryClient.esm.js +107 -66
  82. package/build/lib/queryClient.esm.js.map +1 -1
  83. package/build/lib/queryClient.js +107 -66
  84. package/build/lib/queryClient.js.map +1 -1
  85. package/build/lib/queryClient.mjs +5 -4
  86. package/build/lib/queryClient.mjs.map +1 -1
  87. package/build/lib/queryObserver.d.ts +2 -2
  88. package/build/lib/queryObserver.esm.js +308 -207
  89. package/build/lib/queryObserver.esm.js.map +1 -1
  90. package/build/lib/queryObserver.js +307 -206
  91. package/build/lib/queryObserver.js.map +1 -1
  92. package/build/lib/queryObserver.mjs.map +1 -1
  93. package/build/lib/removable.esm.js +13 -6
  94. package/build/lib/removable.esm.js.map +1 -1
  95. package/build/lib/removable.js +13 -6
  96. package/build/lib/removable.js.map +1 -1
  97. package/build/lib/retryer.d.ts +5 -5
  98. package/build/lib/retryer.esm.js +15 -14
  99. package/build/lib/retryer.esm.js.map +1 -1
  100. package/build/lib/retryer.js +15 -14
  101. package/build/lib/retryer.js.map +1 -1
  102. package/build/lib/retryer.mjs.map +1 -1
  103. package/build/lib/tests/utils.d.ts +4 -5
  104. package/build/lib/types.d.ts +42 -40
  105. package/build/lib/utils.esm.js +1 -1
  106. package/build/lib/utils.esm.js.map +1 -1
  107. package/build/lib/utils.js +1 -1
  108. package/build/lib/utils.js.map +1 -1
  109. package/build/umd/index.development.js +92 -88
  110. package/build/umd/index.development.js.map +1 -1
  111. package/build/umd/index.production.js +1 -1
  112. package/build/umd/index.production.js.map +1 -1
  113. package/package.json +2 -2
  114. package/src/hydration.ts +18 -37
  115. package/src/index.ts +9 -5
  116. package/src/infiniteQueryBehavior.ts +52 -60
  117. package/src/infiniteQueryObserver.ts +17 -12
  118. package/src/mutation.ts +34 -7
  119. package/src/mutationCache.ts +15 -8
  120. package/src/mutationObserver.ts +3 -2
  121. package/src/queriesObserver.ts +3 -7
  122. package/src/query.ts +24 -9
  123. package/src/queryCache.ts +16 -10
  124. package/src/queryClient.ts +9 -11
  125. package/src/queryObserver.ts +2 -2
  126. package/src/retryer.ts +5 -5
  127. package/src/tests/focusManager.test.tsx +12 -14
  128. package/src/tests/hydration.test.tsx +22 -17
  129. package/src/tests/infiniteQueryBehavior.test.tsx +16 -9
  130. package/src/tests/infiniteQueryObserver.test.tsx +62 -1
  131. package/src/tests/mutationCache.test.tsx +61 -16
  132. package/src/tests/mutationObserver.test.tsx +3 -2
  133. package/src/tests/mutations.test.tsx +41 -9
  134. package/src/tests/notifyManager.test.tsx +7 -6
  135. package/src/tests/onlineManager.test.tsx +12 -17
  136. package/src/tests/queriesObserver.test.tsx +18 -17
  137. package/src/tests/query.test.tsx +18 -17
  138. package/src/tests/queryCache.test.tsx +28 -15
  139. package/src/tests/queryClient.test.tsx +49 -48
  140. package/src/tests/queryObserver.test.tsx +10 -9
  141. package/src/tests/utils.test.tsx +2 -1
  142. package/src/tests/utils.ts +5 -4
  143. package/src/types.ts +53 -37
@@ -889,6 +889,7 @@
889
889
  if (!isCancelledError(error)) {
890
890
  // Notify cache callback
891
891
  this.#cache.config.onError?.(error, this);
892
+ this.#cache.config.onSettled?.(this.state.data, error, this);
892
893
  }
893
894
  if (!this.isFetchingOptimistic) {
894
895
  // Schedule query gc after fetching
@@ -913,6 +914,7 @@
913
914
 
914
915
  // Notify cache callback
915
916
  this.#cache.config.onSuccess?.(data, this);
917
+ this.#cache.config.onSettled?.(data, this.state.error, this);
916
918
  if (!this.isFetchingOptimistic) {
917
919
  // Schedule query gc after fetching
918
920
  this.scheduleGc();
@@ -1114,10 +1116,11 @@
1114
1116
  return [...this.#queries.values()];
1115
1117
  }
1116
1118
  find(filters) {
1117
- if (typeof filters.exact === 'undefined') {
1118
- filters.exact = true;
1119
- }
1120
- 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));
1121
1124
  }
1122
1125
  findAll(filters = {}) {
1123
1126
  const queries = this.getAll();
@@ -1152,18 +1155,26 @@
1152
1155
 
1153
1156
  class Mutation extends Removable {
1154
1157
  #observers;
1158
+ #defaultOptions;
1155
1159
  #mutationCache;
1156
1160
  #retryer;
1157
1161
  constructor(config) {
1158
1162
  super();
1159
- this.options = config.options;
1160
1163
  this.mutationId = config.mutationId;
1164
+ this.#defaultOptions = config.defaultOptions;
1161
1165
  this.#mutationCache = config.mutationCache;
1162
1166
  this.#observers = [];
1163
1167
  this.state = config.state || getDefaultState();
1164
- this.updateGcTime(this.options.gcTime);
1168
+ this.setOptions(config.options);
1165
1169
  this.scheduleGc();
1166
1170
  }
1171
+ setOptions(options) {
1172
+ this.options = {
1173
+ ...this.#defaultOptions,
1174
+ ...options
1175
+ };
1176
+ this.updateGcTime(this.options.gcTime);
1177
+ }
1167
1178
  get meta() {
1168
1179
  return this.options.meta;
1169
1180
  }
@@ -1258,6 +1269,9 @@
1258
1269
  // Notify cache callback
1259
1270
  await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this);
1260
1271
  await this.options.onSuccess?.(data, variables, this.state.context);
1272
+
1273
+ // Notify cache callback
1274
+ await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this);
1261
1275
  await this.options.onSettled?.(data, null, variables, this.state.context);
1262
1276
  this.#dispatch({
1263
1277
  type: 'success',
@@ -1269,6 +1283,9 @@
1269
1283
  // Notify cache callback
1270
1284
  await this.#mutationCache.config.onError?.(error, variables, this.state.context, this);
1271
1285
  await this.options.onError?.(error, variables, this.state.context);
1286
+
1287
+ // Notify cache callback
1288
+ await this.#mutationCache.config.onSettled?.(undefined, error, this.state.variables, this.state.context, this);
1272
1289
  await this.options.onSettled?.(undefined, error, variables, this.state.context);
1273
1290
  throw error;
1274
1291
  } finally {
@@ -1409,10 +1426,11 @@
1409
1426
  return this.#mutations;
1410
1427
  }
1411
1428
  find(filters) {
1412
- if (typeof filters.exact === 'undefined') {
1413
- filters.exact = true;
1414
- }
1415
- 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));
1416
1434
  }
1417
1435
  findAll(filters = {}) {
1418
1436
  return this.#mutations.filter(mutation => matchMutation(filters, mutation));
@@ -1438,12 +1456,15 @@
1438
1456
  function infiniteQueryBehavior() {
1439
1457
  return {
1440
1458
  onFetch: context => {
1441
- context.fetchFn = () => {
1459
+ context.fetchFn = async () => {
1442
1460
  const options = context.options;
1443
1461
  const direction = context.fetchOptions?.meta?.fetchMore?.direction;
1444
1462
  const oldPages = context.state.data?.pages || [];
1445
1463
  const oldPageParams = context.state.data?.pageParams || [];
1446
- let newPageParams = oldPageParams;
1464
+ const empty = {
1465
+ pages: [],
1466
+ pageParams: []
1467
+ };
1447
1468
  let cancelled = false;
1448
1469
  const addSignalProperty = object => {
1449
1470
  Object.defineProperty(object, 'signal', {
@@ -1463,95 +1484,95 @@
1463
1484
 
1464
1485
  // Get query function
1465
1486
  const queryFn = context.options.queryFn || (() => Promise.reject(new Error('Missing queryFn')));
1466
- const buildNewPages = (pages, param, page, previous) => {
1467
- const {
1468
- maxPages
1469
- } = context.options;
1470
- if (previous) {
1471
- newPageParams = addToStart(newPageParams, param, maxPages);
1472
- return addToStart(pages, page, maxPages);
1473
- }
1474
- newPageParams = addToEnd(newPageParams, param, maxPages);
1475
- return addToEnd(pages, page, maxPages);
1476
- };
1477
1487
 
1478
1488
  // Create function to fetch a page
1479
- const fetchPage = (pages, param, previous) => {
1489
+ const fetchPage = async (data, param, previous) => {
1480
1490
  if (cancelled) {
1481
1491
  return Promise.reject();
1482
1492
  }
1483
- if (typeof param === 'undefined' && pages.length) {
1484
- return Promise.resolve(pages);
1493
+ if (typeof param === 'undefined' && data.pages.length) {
1494
+ return Promise.resolve(data);
1485
1495
  }
1486
1496
  const queryFnContext = {
1487
1497
  queryKey: context.queryKey,
1488
1498
  pageParam: param,
1499
+ direction: previous ? 'backward' : 'forward',
1489
1500
  meta: context.options.meta
1490
1501
  };
1491
1502
  addSignalProperty(queryFnContext);
1492
- const queryFnResult = queryFn(queryFnContext);
1493
- const promise = Promise.resolve(queryFnResult).then(page => buildNewPages(pages, param, page, previous));
1494
- 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
+ };
1495
1512
  };
1496
- let promise;
1513
+ let result;
1497
1514
 
1498
1515
  // Fetch first page?
1499
1516
  if (!oldPages.length) {
1500
- promise = fetchPage([], options.defaultPageParam);
1517
+ result = await fetchPage(empty, options.defaultPageParam);
1501
1518
  }
1502
1519
 
1503
1520
  // fetch next / previous page?
1504
1521
  else if (direction) {
1505
1522
  const previous = direction === 'backward';
1506
- const param = previous ? getPreviousPageParam(options, oldPages) : getNextPageParam(options, oldPages);
1507
- 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);
1508
1530
  }
1509
1531
 
1510
1532
  // Refetch pages
1511
1533
  else {
1512
- newPageParams = [];
1513
-
1514
1534
  // Fetch first page
1515
- promise = fetchPage([], oldPageParams[0]);
1535
+ result = await fetchPage(empty, oldPageParams[0]);
1516
1536
 
1517
1537
  // Fetch remaining pages
1518
1538
  for (let i = 1; i < oldPages.length; i++) {
1519
- promise = promise.then(pages => {
1520
- const param = getNextPageParam(options, pages);
1521
- return fetchPage(pages, param);
1522
- });
1539
+ const param = getNextPageParam(options, result);
1540
+ result = await fetchPage(result, param);
1523
1541
  }
1524
1542
  }
1525
- const finalPromise = promise.then(pages => ({
1526
- pages,
1527
- pageParams: newPageParams
1528
- }));
1529
- return finalPromise;
1543
+ return result;
1530
1544
  };
1531
1545
  }
1532
1546
  };
1533
1547
  }
1534
- function getNextPageParam(options, pages) {
1535
- 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);
1536
1554
  }
1537
- function getPreviousPageParam(options, pages) {
1538
- 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);
1539
1560
  }
1540
1561
 
1541
1562
  /**
1542
1563
  * Checks if there is a next page.
1543
1564
  */
1544
- function hasNextPage(options, pages) {
1545
- if (!pages) return false;
1546
- return typeof getNextPageParam(options, pages) !== 'undefined';
1565
+ function hasNextPage(options, data) {
1566
+ if (!data) return false;
1567
+ return typeof getNextPageParam(options, data) !== 'undefined';
1547
1568
  }
1548
1569
 
1549
1570
  /**
1550
1571
  * Checks if there is a previous page.
1551
1572
  */
1552
- function hasPreviousPage(options, pages) {
1553
- if (!pages || !options.getPreviousPageParam) return false;
1554
- 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';
1555
1576
  }
1556
1577
 
1557
1578
  // CLASS
@@ -1676,10 +1697,11 @@
1676
1697
  });
1677
1698
  }
1678
1699
  cancelQueries(filters = {}, cancelOptions = {}) {
1679
- if (typeof cancelOptions.revert === 'undefined') {
1680
- cancelOptions.revert = true;
1681
- }
1682
- 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)));
1683
1705
  return Promise.all(promises).then(noop).catch(noop);
1684
1706
  }
1685
1707
  invalidateQueries(filters = {}, options = {}) {
@@ -2266,14 +2288,12 @@
2266
2288
  #result;
2267
2289
  #queries;
2268
2290
  #observers;
2269
- #observersMap;
2270
2291
  constructor(client, queries) {
2271
2292
  super();
2272
2293
  this.#client = client;
2273
2294
  this.#queries = [];
2274
2295
  this.#result = [];
2275
2296
  this.#observers = [];
2276
- this.#observersMap = {};
2277
2297
  if (queries) {
2278
2298
  this.setQueries(queries);
2279
2299
  }
@@ -2307,14 +2327,12 @@
2307
2327
  // set options for the new observers to notify of changes
2308
2328
  newObserverMatches.forEach(match => match.observer.setOptions(match.defaultedQueryOptions, notifyOptions));
2309
2329
  const newObservers = newObserverMatches.map(match => match.observer);
2310
- const newObserversMap = Object.fromEntries(newObservers.map(observer => [observer.options.queryHash, observer]));
2311
2330
  const newResult = newObservers.map(observer => observer.getCurrentResult());
2312
2331
  const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
2313
2332
  if (prevObservers.length === newObservers.length && !hasIndexChange) {
2314
2333
  return;
2315
2334
  }
2316
2335
  this.#observers = newObservers;
2317
- this.#observersMap = newObserversMap;
2318
2336
  this.#result = newResult;
2319
2337
  if (!this.hasListeners()) {
2320
2338
  return;
@@ -2359,7 +2377,7 @@
2359
2377
  const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
2360
2378
  const getObserver = options => {
2361
2379
  const defaultedOptions = this.#client.defaultQueryOptions(options);
2362
- const currentObserver = this.#observersMap[defaultedOptions.queryHash];
2380
+ const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
2363
2381
  return currentObserver ?? new QueryObserver(this.#client, defaultedOptions);
2364
2382
  };
2365
2383
  const newOrReusedObservers = unmatchedQueries.map(options => {
@@ -2413,7 +2431,7 @@
2413
2431
  options.behavior = infiniteQueryBehavior();
2414
2432
  return super.getOptimisticResult(options);
2415
2433
  }
2416
- fetchNextPage(options = {}) {
2434
+ fetchNextPage(options) {
2417
2435
  return this.fetch({
2418
2436
  ...options,
2419
2437
  meta: {
@@ -2423,9 +2441,7 @@
2423
2441
  }
2424
2442
  });
2425
2443
  }
2426
- fetchPreviousPage({
2427
- ...options
2428
- } = {}) {
2444
+ fetchPreviousPage(options) {
2429
2445
  return this.fetch({
2430
2446
  ...options,
2431
2447
  meta: {
@@ -2450,8 +2466,8 @@
2450
2466
  ...result,
2451
2467
  fetchNextPage: this.fetchNextPage,
2452
2468
  fetchPreviousPage: this.fetchPreviousPage,
2453
- hasNextPage: hasNextPage(options, state.data?.pages),
2454
- hasPreviousPage: hasPreviousPage(options, state.data?.pages),
2469
+ hasNextPage: hasNextPage(options, state.data),
2470
+ hasPreviousPage: hasPreviousPage(options, state.data),
2455
2471
  isFetchingNextPage,
2456
2472
  isFetchingPreviousPage,
2457
2473
  isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
@@ -2489,6 +2505,7 @@
2489
2505
  observer: this
2490
2506
  });
2491
2507
  }
2508
+ this.#currentMutation?.setOptions(this.options);
2492
2509
  }
2493
2510
  onUnsubscribe() {
2494
2511
  if (!this.listeners.length) {
@@ -2576,24 +2593,10 @@
2576
2593
  return query.state.status === 'success';
2577
2594
  }
2578
2595
  function dehydrate(client, options = {}) {
2579
- const mutations = [];
2580
- const queries = [];
2581
- if (options.dehydrateMutations !== false) {
2582
- const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
2583
- client.getMutationCache().getAll().forEach(mutation => {
2584
- if (shouldDehydrateMutation(mutation)) {
2585
- mutations.push(dehydrateMutation(mutation));
2586
- }
2587
- });
2588
- }
2589
- if (options.dehydrateQueries !== false) {
2590
- const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
2591
- client.getQueryCache().getAll().forEach(query => {
2592
- if (shouldDehydrateQuery(query)) {
2593
- queries.push(dehydrateQuery(query));
2594
- }
2595
- });
2596
- }
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)] : []);
2597
2600
  return {
2598
2601
  mutations,
2599
2602
  queries
@@ -2660,6 +2663,7 @@
2660
2663
  exports.isCancelledError = isCancelledError;
2661
2664
  exports.isServer = isServer;
2662
2665
  exports.keepPreviousData = keepPreviousData;
2666
+ exports.matchQuery = matchQuery;
2663
2667
  exports.notifyManager = notifyManager;
2664
2668
  exports.onlineManager = onlineManager;
2665
2669
  exports.replaceEqualDeep = replaceEqualDeep;