@tanstack/vue-query 5.0.0-alpha.4 → 5.0.0-alpha.42
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.
- package/README.md +18 -14
- package/build/lib/__mocks__/useBaseQuery.d.ts +2 -2
- package/build/lib/__mocks__/useBaseQuery.d.ts.map +1 -0
- package/build/lib/__mocks__/useQueryClient.d.ts +2 -2
- package/build/lib/__mocks__/useQueryClient.d.ts.map +1 -0
- package/build/lib/__tests__/mutationCache.test.d.ts +1 -0
- package/build/lib/__tests__/mutationCache.test.d.ts.map +1 -0
- package/build/lib/__tests__/queryCache.test.d.ts +1 -0
- package/build/lib/__tests__/queryCache.test.d.ts.map +1 -0
- package/build/lib/__tests__/queryClient.test.d.ts +1 -0
- package/build/lib/__tests__/queryClient.test.d.ts.map +1 -0
- package/build/lib/__tests__/test-utils.d.ts +3 -2
- package/build/lib/__tests__/test-utils.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.types.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
- package/build/lib/__tests__/useIsMutating.test.d.ts +1 -0
- package/build/lib/__tests__/useIsMutating.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutation.types.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQueryClient.test.d.ts +1 -0
- package/build/lib/__tests__/useQueryClient.test.d.ts.map +1 -0
- package/build/lib/__tests__/utils.test.d.ts +1 -0
- package/build/lib/__tests__/utils.test.d.ts.map +1 -0
- package/build/lib/__tests__/vueQueryPlugin.test.d.ts +1 -0
- package/build/lib/__tests__/vueQueryPlugin.test.d.ts.map +1 -0
- package/build/lib/devtools/devtools.d.ts +1 -0
- package/build/lib/devtools/devtools.d.ts.map +1 -0
- package/build/lib/devtools/devtools.esm.js +50 -9
- package/build/lib/devtools/devtools.esm.js.map +1 -1
- package/build/lib/devtools/devtools.js +50 -9
- package/build/lib/devtools/devtools.js.map +1 -1
- package/build/lib/devtools/devtools.mjs +46 -7
- package/build/lib/devtools/devtools.mjs.map +1 -1
- package/build/lib/devtools/utils.d.ts +2 -1
- package/build/lib/devtools/utils.d.ts.map +1 -0
- package/build/lib/devtools/utils.esm.js +3 -4
- package/build/lib/devtools/utils.esm.js.map +1 -1
- package/build/lib/devtools/utils.js +3 -4
- package/build/lib/devtools/utils.js.map +1 -1
- package/build/lib/devtools/utils.mjs +3 -4
- package/build/lib/devtools/utils.mjs.map +1 -1
- package/build/lib/index.d.ts +3 -2
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +3 -2
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/mutationCache.d.ts +1 -0
- package/build/lib/mutationCache.d.ts.map +1 -0
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +1 -0
- package/build/lib/queryCache.d.ts.map +1 -0
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +1 -0
- package/build/lib/queryClient.d.ts.map +1 -0
- package/build/lib/queryClient.esm.js +1 -1
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +1 -1
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/types.d.ts +4 -3
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.d.ts +3 -2
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +4 -3
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.d.ts +2 -1
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useMutation.d.ts +5 -4
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useMutationState.d.ts +12 -0
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.esm.js +33 -0
- package/build/lib/useMutationState.esm.js.map +1 -0
- package/build/lib/useMutationState.js +36 -0
- package/build/lib/useMutationState.js.map +1 -0
- package/build/lib/useMutationState.mjs +33 -0
- package/build/lib/useMutationState.mjs.map +1 -0
- package/build/lib/useQueries.d.ts +12 -11
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.esm.js +25 -11
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +25 -11
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +25 -11
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +4 -3
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/lib/useQueryClient.d.ts +1 -0
- package/build/lib/useQueryClient.d.ts.map +1 -0
- package/build/lib/useQueryClient.esm.js +2 -1
- package/build/lib/useQueryClient.esm.js.map +1 -1
- package/build/lib/useQueryClient.js +2 -1
- package/build/lib/useQueryClient.js.map +1 -1
- package/build/lib/useQueryClient.mjs.map +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs.map +1 -1
- package/build/lib/vueQueryPlugin.d.ts +3 -2
- package/build/lib/vueQueryPlugin.d.ts.map +1 -0
- package/build/lib/vueQueryPlugin.esm.js +0 -2
- package/build/lib/vueQueryPlugin.esm.js.map +1 -1
- package/build/lib/vueQueryPlugin.js +0 -2
- package/build/lib/vueQueryPlugin.js.map +1 -1
- package/build/lib/vueQueryPlugin.mjs +0 -2
- package/build/lib/vueQueryPlugin.mjs.map +1 -1
- package/build/umd/index.development.js +244 -176
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +13 -11
- package/build/lib/useIsMutating.d.ts +0 -6
- package/build/lib/useIsMutating.esm.js +0 -24
- package/build/lib/useIsMutating.esm.js.map +0 -1
- package/build/lib/useIsMutating.js +0 -26
- package/build/lib/useIsMutating.js.map +0 -1
- package/build/lib/useIsMutating.mjs +0 -24
- package/build/lib/useIsMutating.mjs.map +0 -1
|
@@ -6,19 +6,19 @@
|
|
|
6
6
|
|
|
7
7
|
class Subscribable {
|
|
8
8
|
constructor() {
|
|
9
|
-
this.listeners =
|
|
9
|
+
this.listeners = new Set();
|
|
10
10
|
this.subscribe = this.subscribe.bind(this);
|
|
11
11
|
}
|
|
12
12
|
subscribe(listener) {
|
|
13
|
-
this.listeners.
|
|
13
|
+
this.listeners.add(listener);
|
|
14
14
|
this.onSubscribe();
|
|
15
15
|
return () => {
|
|
16
|
-
this.listeners
|
|
16
|
+
this.listeners.delete(listener);
|
|
17
17
|
this.onUnsubscribe();
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
hasListeners() {
|
|
21
|
-
return this.listeners.
|
|
21
|
+
return this.listeners.size > 0;
|
|
22
22
|
}
|
|
23
23
|
onSubscribe() {
|
|
24
24
|
// Do nothing
|
|
@@ -387,6 +387,8 @@
|
|
|
387
387
|
}
|
|
388
388
|
const onlineManager = new OnlineManager();
|
|
389
389
|
|
|
390
|
+
// TYPES
|
|
391
|
+
|
|
390
392
|
function defaultRetryDelay(failureCount) {
|
|
391
393
|
return Math.min(1000 * 2 ** failureCount, 30000);
|
|
392
394
|
}
|
|
@@ -907,7 +909,7 @@
|
|
|
907
909
|
{
|
|
908
910
|
console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
|
|
909
911
|
}
|
|
910
|
-
onError(new Error(
|
|
912
|
+
onError(new Error(`${this.queryHash} data is undefined`));
|
|
911
913
|
return;
|
|
912
914
|
}
|
|
913
915
|
this.setData(data);
|
|
@@ -1024,7 +1026,7 @@
|
|
|
1024
1026
|
this.state = reducer(this.state);
|
|
1025
1027
|
notifyManager.batch(() => {
|
|
1026
1028
|
this.#observers.forEach(observer => {
|
|
1027
|
-
observer.onQueryUpdate(
|
|
1029
|
+
observer.onQueryUpdate();
|
|
1028
1030
|
});
|
|
1029
1031
|
this.#cache.notify({
|
|
1030
1032
|
query: this,
|
|
@@ -1054,6 +1056,8 @@
|
|
|
1054
1056
|
};
|
|
1055
1057
|
}
|
|
1056
1058
|
|
|
1059
|
+
// TYPES
|
|
1060
|
+
|
|
1057
1061
|
// CLASS
|
|
1058
1062
|
|
|
1059
1063
|
let QueryCache$1 = class QueryCache extends Subscribable {
|
|
@@ -1061,7 +1065,7 @@
|
|
|
1061
1065
|
constructor(config = {}) {
|
|
1062
1066
|
super();
|
|
1063
1067
|
this.config = config;
|
|
1064
|
-
this.#queries =
|
|
1068
|
+
this.#queries = new Map();
|
|
1065
1069
|
}
|
|
1066
1070
|
build(client, options, state) {
|
|
1067
1071
|
const queryKey = options.queryKey;
|
|
@@ -1116,10 +1120,11 @@
|
|
|
1116
1120
|
return [...this.#queries.values()];
|
|
1117
1121
|
}
|
|
1118
1122
|
find(filters) {
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
+
const defaultedFilters = {
|
|
1124
|
+
exact: true,
|
|
1125
|
+
...filters
|
|
1126
|
+
};
|
|
1127
|
+
return this.getAll().find(query => matchQuery(defaultedFilters, query));
|
|
1123
1128
|
}
|
|
1124
1129
|
findAll(filters = {}) {
|
|
1125
1130
|
const queries = this.getAll();
|
|
@@ -1425,10 +1430,11 @@
|
|
|
1425
1430
|
return this.#mutations;
|
|
1426
1431
|
}
|
|
1427
1432
|
find(filters) {
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1433
|
+
const defaultedFilters = {
|
|
1434
|
+
exact: true,
|
|
1435
|
+
...filters
|
|
1436
|
+
};
|
|
1437
|
+
return this.#mutations.find(mutation => matchMutation(defaultedFilters, mutation));
|
|
1432
1438
|
}
|
|
1433
1439
|
findAll(filters = {}) {
|
|
1434
1440
|
return this.#mutations.filter(mutation => matchMutation(filters, mutation));
|
|
@@ -1454,12 +1460,15 @@
|
|
|
1454
1460
|
function infiniteQueryBehavior() {
|
|
1455
1461
|
return {
|
|
1456
1462
|
onFetch: context => {
|
|
1457
|
-
context.fetchFn = () => {
|
|
1463
|
+
context.fetchFn = async () => {
|
|
1458
1464
|
const options = context.options;
|
|
1459
1465
|
const direction = context.fetchOptions?.meta?.fetchMore?.direction;
|
|
1460
1466
|
const oldPages = context.state.data?.pages || [];
|
|
1461
1467
|
const oldPageParams = context.state.data?.pageParams || [];
|
|
1462
|
-
|
|
1468
|
+
const empty = {
|
|
1469
|
+
pages: [],
|
|
1470
|
+
pageParams: []
|
|
1471
|
+
};
|
|
1463
1472
|
let cancelled = false;
|
|
1464
1473
|
const addSignalProperty = object => {
|
|
1465
1474
|
Object.defineProperty(object, 'signal', {
|
|
@@ -1479,97 +1488,99 @@
|
|
|
1479
1488
|
|
|
1480
1489
|
// Get query function
|
|
1481
1490
|
const queryFn = context.options.queryFn || (() => Promise.reject(new Error('Missing queryFn')));
|
|
1482
|
-
const buildNewPages = (pages, param, page, previous) => {
|
|
1483
|
-
const {
|
|
1484
|
-
maxPages
|
|
1485
|
-
} = context.options;
|
|
1486
|
-
if (previous) {
|
|
1487
|
-
newPageParams = addToStart(newPageParams, param, maxPages);
|
|
1488
|
-
return addToStart(pages, page, maxPages);
|
|
1489
|
-
}
|
|
1490
|
-
newPageParams = addToEnd(newPageParams, param, maxPages);
|
|
1491
|
-
return addToEnd(pages, page, maxPages);
|
|
1492
|
-
};
|
|
1493
1491
|
|
|
1494
1492
|
// Create function to fetch a page
|
|
1495
|
-
const fetchPage = (
|
|
1493
|
+
const fetchPage = async (data, param, previous) => {
|
|
1496
1494
|
if (cancelled) {
|
|
1497
1495
|
return Promise.reject();
|
|
1498
1496
|
}
|
|
1499
|
-
if (typeof param === 'undefined' && pages.length) {
|
|
1500
|
-
return Promise.resolve(
|
|
1497
|
+
if (typeof param === 'undefined' && data.pages.length) {
|
|
1498
|
+
return Promise.resolve(data);
|
|
1501
1499
|
}
|
|
1502
1500
|
const queryFnContext = {
|
|
1503
1501
|
queryKey: context.queryKey,
|
|
1504
1502
|
pageParam: param,
|
|
1503
|
+
direction: previous ? 'backward' : 'forward',
|
|
1505
1504
|
meta: context.options.meta
|
|
1506
1505
|
};
|
|
1507
1506
|
addSignalProperty(queryFnContext);
|
|
1508
|
-
const
|
|
1509
|
-
const
|
|
1510
|
-
|
|
1507
|
+
const page = await queryFn(queryFnContext);
|
|
1508
|
+
const {
|
|
1509
|
+
maxPages
|
|
1510
|
+
} = context.options;
|
|
1511
|
+
const addTo = previous ? addToStart : addToEnd;
|
|
1512
|
+
return {
|
|
1513
|
+
pages: addTo(data.pages, page, maxPages),
|
|
1514
|
+
pageParams: addTo(data.pageParams, param, maxPages)
|
|
1515
|
+
};
|
|
1511
1516
|
};
|
|
1512
|
-
let
|
|
1517
|
+
let result;
|
|
1513
1518
|
|
|
1514
1519
|
// Fetch first page?
|
|
1515
1520
|
if (!oldPages.length) {
|
|
1516
|
-
|
|
1521
|
+
result = await fetchPage(empty, options.defaultPageParam);
|
|
1517
1522
|
}
|
|
1518
1523
|
|
|
1519
1524
|
// fetch next / previous page?
|
|
1520
1525
|
else if (direction) {
|
|
1521
1526
|
const previous = direction === 'backward';
|
|
1522
|
-
const
|
|
1523
|
-
|
|
1527
|
+
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|
1528
|
+
const oldData = {
|
|
1529
|
+
pages: oldPages,
|
|
1530
|
+
pageParams: oldPageParams
|
|
1531
|
+
};
|
|
1532
|
+
const param = pageParamFn(options, oldData);
|
|
1533
|
+
result = await fetchPage(oldData, param, previous);
|
|
1524
1534
|
}
|
|
1525
1535
|
|
|
1526
1536
|
// Refetch pages
|
|
1527
1537
|
else {
|
|
1528
|
-
newPageParams = [];
|
|
1529
|
-
|
|
1530
1538
|
// Fetch first page
|
|
1531
|
-
|
|
1539
|
+
result = await fetchPage(empty, oldPageParams[0]);
|
|
1532
1540
|
|
|
1533
1541
|
// Fetch remaining pages
|
|
1534
1542
|
for (let i = 1; i < oldPages.length; i++) {
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
return fetchPage(pages, param);
|
|
1538
|
-
});
|
|
1543
|
+
const param = getNextPageParam(options, result);
|
|
1544
|
+
result = await fetchPage(result, param);
|
|
1539
1545
|
}
|
|
1540
1546
|
}
|
|
1541
|
-
|
|
1542
|
-
pages,
|
|
1543
|
-
pageParams: newPageParams
|
|
1544
|
-
}));
|
|
1545
|
-
return finalPromise;
|
|
1547
|
+
return result;
|
|
1546
1548
|
};
|
|
1547
1549
|
}
|
|
1548
1550
|
};
|
|
1549
1551
|
}
|
|
1550
|
-
function getNextPageParam(options,
|
|
1551
|
-
|
|
1552
|
+
function getNextPageParam(options, {
|
|
1553
|
+
pages,
|
|
1554
|
+
pageParams
|
|
1555
|
+
}) {
|
|
1556
|
+
const lastIndex = pages.length - 1;
|
|
1557
|
+
return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams);
|
|
1552
1558
|
}
|
|
1553
|
-
function getPreviousPageParam(options,
|
|
1554
|
-
|
|
1559
|
+
function getPreviousPageParam(options, {
|
|
1560
|
+
pages,
|
|
1561
|
+
pageParams
|
|
1562
|
+
}) {
|
|
1563
|
+
return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
|
|
1555
1564
|
}
|
|
1556
1565
|
|
|
1557
1566
|
/**
|
|
1558
1567
|
* Checks if there is a next page.
|
|
1559
1568
|
*/
|
|
1560
|
-
function hasNextPage(options,
|
|
1561
|
-
if (!
|
|
1562
|
-
return typeof getNextPageParam(options,
|
|
1569
|
+
function hasNextPage(options, data) {
|
|
1570
|
+
if (!data) return false;
|
|
1571
|
+
return typeof getNextPageParam(options, data) !== 'undefined';
|
|
1563
1572
|
}
|
|
1564
1573
|
|
|
1565
1574
|
/**
|
|
1566
1575
|
* Checks if there is a previous page.
|
|
1567
1576
|
*/
|
|
1568
|
-
function hasPreviousPage(options,
|
|
1569
|
-
if (!
|
|
1570
|
-
return typeof getPreviousPageParam(options,
|
|
1577
|
+
function hasPreviousPage(options, data) {
|
|
1578
|
+
if (!data || !options.getPreviousPageParam) return false;
|
|
1579
|
+
return typeof getPreviousPageParam(options, data) !== 'undefined';
|
|
1571
1580
|
}
|
|
1572
1581
|
|
|
1582
|
+
// TYPES
|
|
1583
|
+
|
|
1573
1584
|
// CLASS
|
|
1574
1585
|
|
|
1575
1586
|
let QueryClient$1 = class QueryClient {
|
|
@@ -1692,10 +1703,11 @@
|
|
|
1692
1703
|
});
|
|
1693
1704
|
}
|
|
1694
1705
|
cancelQueries(filters = {}, cancelOptions = {}) {
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1706
|
+
const defaultedCancelOptions = {
|
|
1707
|
+
revert: true,
|
|
1708
|
+
...cancelOptions
|
|
1709
|
+
};
|
|
1710
|
+
const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map(query => query.cancel(defaultedCancelOptions)));
|
|
1699
1711
|
return Promise.all(promises).then(noop).catch(noop);
|
|
1700
1712
|
}
|
|
1701
1713
|
invalidateQueries(filters = {}, options = {}) {
|
|
@@ -1714,15 +1726,18 @@
|
|
|
1714
1726
|
});
|
|
1715
1727
|
}
|
|
1716
1728
|
refetchQueries(filters = {}, options) {
|
|
1717
|
-
const
|
|
1729
|
+
const fetchOptions = {
|
|
1718
1730
|
...options,
|
|
1719
1731
|
cancelRefetch: options?.cancelRefetch ?? true
|
|
1720
|
-
}
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1732
|
+
};
|
|
1733
|
+
const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => {
|
|
1734
|
+
let promise = query.fetch(undefined, fetchOptions);
|
|
1735
|
+
if (!fetchOptions.throwOnError) {
|
|
1736
|
+
promise = promise.catch(noop);
|
|
1737
|
+
}
|
|
1738
|
+
return query.state.fetchStatus === 'paused' ? Promise.resolve() : promise;
|
|
1739
|
+
}));
|
|
1740
|
+
return Promise.all(promises).then(noop);
|
|
1726
1741
|
}
|
|
1727
1742
|
fetchQuery(options) {
|
|
1728
1743
|
const defaultedOptions = this.defaultQueryOptions(options);
|
|
@@ -1815,8 +1830,8 @@
|
|
|
1815
1830
|
if (typeof defaultedOptions.refetchOnReconnect === 'undefined') {
|
|
1816
1831
|
defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== 'always';
|
|
1817
1832
|
}
|
|
1818
|
-
if (typeof defaultedOptions.
|
|
1819
|
-
defaultedOptions.
|
|
1833
|
+
if (typeof defaultedOptions.throwOnError === 'undefined') {
|
|
1834
|
+
defaultedOptions.throwOnError = !!defaultedOptions.suspense;
|
|
1820
1835
|
}
|
|
1821
1836
|
return defaultedOptions;
|
|
1822
1837
|
}
|
|
@@ -1844,10 +1859,12 @@
|
|
|
1844
1859
|
#currentResult = undefined;
|
|
1845
1860
|
#currentResultState;
|
|
1846
1861
|
#currentResultOptions;
|
|
1847
|
-
#previousQueryResult;
|
|
1848
1862
|
#selectError;
|
|
1849
1863
|
#selectFn;
|
|
1850
1864
|
#selectResult;
|
|
1865
|
+
// This property keeps track of the last query with defined data.
|
|
1866
|
+
// It will be used to pass the previous data and query to the placeholder function between renders.
|
|
1867
|
+
#lastQueryWithDefinedData;
|
|
1851
1868
|
#staleTimeoutId;
|
|
1852
1869
|
#refetchIntervalId;
|
|
1853
1870
|
#currentRefetchInterval;
|
|
@@ -1864,7 +1881,7 @@
|
|
|
1864
1881
|
this.refetch = this.refetch.bind(this);
|
|
1865
1882
|
}
|
|
1866
1883
|
onSubscribe() {
|
|
1867
|
-
if (this.listeners.
|
|
1884
|
+
if (this.listeners.size === 1) {
|
|
1868
1885
|
this.#currentQuery.addObserver(this);
|
|
1869
1886
|
if (shouldFetchOnMount(this.#currentQuery, this.options)) {
|
|
1870
1887
|
this.#executeFetch();
|
|
@@ -1873,7 +1890,7 @@
|
|
|
1873
1890
|
}
|
|
1874
1891
|
}
|
|
1875
1892
|
onUnsubscribe() {
|
|
1876
|
-
if (!this.
|
|
1893
|
+
if (!this.hasListeners()) {
|
|
1877
1894
|
this.destroy();
|
|
1878
1895
|
}
|
|
1879
1896
|
}
|
|
@@ -1884,7 +1901,7 @@
|
|
|
1884
1901
|
return shouldFetchOn(this.#currentQuery, this.options, this.options.refetchOnWindowFocus);
|
|
1885
1902
|
}
|
|
1886
1903
|
destroy() {
|
|
1887
|
-
this.listeners =
|
|
1904
|
+
this.listeners = new Set();
|
|
1888
1905
|
this.#clearStaleTimeout();
|
|
1889
1906
|
this.#clearRefetchInterval();
|
|
1890
1907
|
this.#currentQuery.removeObserver(this);
|
|
@@ -2004,7 +2021,7 @@
|
|
|
2004
2021
|
}, timeout);
|
|
2005
2022
|
}
|
|
2006
2023
|
#computeRefetchInterval() {
|
|
2007
|
-
return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval ?? false;
|
|
2024
|
+
return (typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.#currentResult.data, this.#currentQuery) : this.options.refetchInterval) ?? false;
|
|
2008
2025
|
}
|
|
2009
2026
|
#updateRefetchInterval(nextInterval) {
|
|
2010
2027
|
this.#clearRefetchInterval();
|
|
@@ -2042,7 +2059,6 @@
|
|
|
2042
2059
|
const prevResultOptions = this.#currentResultOptions;
|
|
2043
2060
|
const queryChange = query !== prevQuery;
|
|
2044
2061
|
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
|
|
2045
|
-
const prevQueryResult = queryChange ? this.#currentResult : this.#previousQueryResult;
|
|
2046
2062
|
const {
|
|
2047
2063
|
state
|
|
2048
2064
|
} = query;
|
|
@@ -2101,7 +2117,7 @@
|
|
|
2101
2117
|
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
2102
2118
|
placeholderData = prevResult.data;
|
|
2103
2119
|
} else {
|
|
2104
|
-
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(
|
|
2120
|
+
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData(this.#lastQueryWithDefinedData?.state.data, this.#lastQueryWithDefinedData) : options.placeholderData;
|
|
2105
2121
|
if (options.select && typeof placeholderData !== 'undefined') {
|
|
2106
2122
|
try {
|
|
2107
2123
|
placeholderData = options.select(placeholderData);
|
|
@@ -2165,6 +2181,9 @@
|
|
|
2165
2181
|
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
2166
2182
|
return;
|
|
2167
2183
|
}
|
|
2184
|
+
if (this.#currentResultState.data !== undefined) {
|
|
2185
|
+
this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
2186
|
+
}
|
|
2168
2187
|
this.#currentResult = nextResult;
|
|
2169
2188
|
|
|
2170
2189
|
// Determine which callbacks to trigger
|
|
@@ -2180,7 +2199,7 @@
|
|
|
2180
2199
|
return true;
|
|
2181
2200
|
}
|
|
2182
2201
|
const includedProps = new Set(notifyOnChangeProps ?? this.#trackedProps);
|
|
2183
|
-
if (this.options.
|
|
2202
|
+
if (this.options.throwOnError) {
|
|
2184
2203
|
includedProps.add('error');
|
|
2185
2204
|
}
|
|
2186
2205
|
return Object.keys(this.#currentResult).some(key => {
|
|
@@ -2205,36 +2224,20 @@
|
|
|
2205
2224
|
const prevQuery = this.#currentQuery;
|
|
2206
2225
|
this.#currentQuery = query;
|
|
2207
2226
|
this.#currentQueryInitialState = query.state;
|
|
2208
|
-
this.#previousQueryResult = this.#currentResult;
|
|
2209
2227
|
if (this.hasListeners()) {
|
|
2210
2228
|
prevQuery?.removeObserver(this);
|
|
2211
2229
|
query.addObserver(this);
|
|
2212
2230
|
}
|
|
2213
2231
|
}
|
|
2214
|
-
onQueryUpdate(
|
|
2215
|
-
|
|
2216
|
-
if (action.type === 'success') {
|
|
2217
|
-
notifyOptions.onSuccess = !action.manual;
|
|
2218
|
-
} else if (action.type === 'error' && !isCancelledError(action.error)) {
|
|
2219
|
-
notifyOptions.onError = true;
|
|
2220
|
-
}
|
|
2221
|
-
this.#updateResult(notifyOptions);
|
|
2232
|
+
onQueryUpdate() {
|
|
2233
|
+
this.#updateResult();
|
|
2222
2234
|
if (this.hasListeners()) {
|
|
2223
2235
|
this.#updateTimers();
|
|
2224
2236
|
}
|
|
2225
2237
|
}
|
|
2226
2238
|
#notify(notifyOptions) {
|
|
2227
2239
|
notifyManager.batch(() => {
|
|
2228
|
-
// First trigger the
|
|
2229
|
-
if (notifyOptions.onSuccess) {
|
|
2230
|
-
this.options.onSuccess?.(this.#currentResult.data);
|
|
2231
|
-
this.options.onSettled?.(this.#currentResult.data, null);
|
|
2232
|
-
} else if (notifyOptions.onError) {
|
|
2233
|
-
this.options.onError?.(this.#currentResult.error);
|
|
2234
|
-
this.options.onSettled?.(undefined, this.#currentResult.error);
|
|
2235
|
-
}
|
|
2236
|
-
|
|
2237
|
-
// Then trigger the listeners
|
|
2240
|
+
// First, trigger the listeners
|
|
2238
2241
|
if (notifyOptions.listeners) {
|
|
2239
2242
|
this.listeners.forEach(listener => {
|
|
2240
2243
|
listener(this.#currentResult);
|
|
@@ -2282,18 +2285,22 @@
|
|
|
2282
2285
|
#result;
|
|
2283
2286
|
#queries;
|
|
2284
2287
|
#observers;
|
|
2285
|
-
|
|
2288
|
+
#options;
|
|
2289
|
+
#combinedResult;
|
|
2290
|
+
constructor(client, queries, options) {
|
|
2286
2291
|
super();
|
|
2287
2292
|
this.#client = client;
|
|
2288
2293
|
this.#queries = [];
|
|
2289
|
-
this.#result = [];
|
|
2290
2294
|
this.#observers = [];
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2295
|
+
this.#setResult([]);
|
|
2296
|
+
this.setQueries(queries, options);
|
|
2297
|
+
}
|
|
2298
|
+
#setResult(value) {
|
|
2299
|
+
this.#result = value;
|
|
2300
|
+
this.#combinedResult = this.#combineResult(value);
|
|
2294
2301
|
}
|
|
2295
2302
|
onSubscribe() {
|
|
2296
|
-
if (this.listeners.
|
|
2303
|
+
if (this.listeners.size === 1) {
|
|
2297
2304
|
this.#observers.forEach(observer => {
|
|
2298
2305
|
observer.subscribe(result => {
|
|
2299
2306
|
this.#onUpdate(observer, result);
|
|
@@ -2302,18 +2309,19 @@
|
|
|
2302
2309
|
}
|
|
2303
2310
|
}
|
|
2304
2311
|
onUnsubscribe() {
|
|
2305
|
-
if (!this.listeners.
|
|
2312
|
+
if (!this.listeners.size) {
|
|
2306
2313
|
this.destroy();
|
|
2307
2314
|
}
|
|
2308
2315
|
}
|
|
2309
2316
|
destroy() {
|
|
2310
|
-
this.listeners =
|
|
2317
|
+
this.listeners = new Set();
|
|
2311
2318
|
this.#observers.forEach(observer => {
|
|
2312
2319
|
observer.destroy();
|
|
2313
2320
|
});
|
|
2314
2321
|
}
|
|
2315
|
-
setQueries(queries, notifyOptions) {
|
|
2322
|
+
setQueries(queries, options, notifyOptions) {
|
|
2316
2323
|
this.#queries = queries;
|
|
2324
|
+
this.#options = options;
|
|
2317
2325
|
notifyManager.batch(() => {
|
|
2318
2326
|
const prevObservers = this.#observers;
|
|
2319
2327
|
const newObserverMatches = this.#findMatchingObservers(this.#queries);
|
|
@@ -2327,7 +2335,7 @@
|
|
|
2327
2335
|
return;
|
|
2328
2336
|
}
|
|
2329
2337
|
this.#observers = newObservers;
|
|
2330
|
-
this.#
|
|
2338
|
+
this.#setResult(newResult);
|
|
2331
2339
|
if (!this.hasListeners()) {
|
|
2332
2340
|
return;
|
|
2333
2341
|
}
|
|
@@ -2343,7 +2351,7 @@
|
|
|
2343
2351
|
});
|
|
2344
2352
|
}
|
|
2345
2353
|
getCurrentResult() {
|
|
2346
|
-
return this.#
|
|
2354
|
+
return this.#combinedResult;
|
|
2347
2355
|
}
|
|
2348
2356
|
getQueries() {
|
|
2349
2357
|
return this.#observers.map(observer => observer.getCurrentQuery());
|
|
@@ -2352,13 +2360,30 @@
|
|
|
2352
2360
|
return this.#observers;
|
|
2353
2361
|
}
|
|
2354
2362
|
getOptimisticResult(queries) {
|
|
2355
|
-
|
|
2363
|
+
const matches = this.#findMatchingObservers(queries);
|
|
2364
|
+
const result = matches.map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions));
|
|
2365
|
+
return [result, r => {
|
|
2366
|
+
return this.#combineResult(r ?? result);
|
|
2367
|
+
}, () => {
|
|
2368
|
+
return matches.map((match, index) => {
|
|
2369
|
+
const observerResult = result[index];
|
|
2370
|
+
return !match.defaultedQueryOptions.notifyOnChangeProps ? match.observer.trackResult(observerResult) : observerResult;
|
|
2371
|
+
});
|
|
2372
|
+
}];
|
|
2373
|
+
}
|
|
2374
|
+
#combineResult(input) {
|
|
2375
|
+
const combine = this.#options?.combine;
|
|
2376
|
+
if (combine) {
|
|
2377
|
+
return replaceEqualDeep(this.#combinedResult, combine(input));
|
|
2378
|
+
}
|
|
2379
|
+
return input;
|
|
2356
2380
|
}
|
|
2357
2381
|
#findMatchingObservers(queries) {
|
|
2358
2382
|
const prevObservers = this.#observers;
|
|
2383
|
+
const prevObserversMap = new Map(prevObservers.map(observer => [observer.options.queryHash, observer]));
|
|
2359
2384
|
const defaultedQueryOptions = queries.map(options => this.#client.defaultQueryOptions(options));
|
|
2360
2385
|
const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
|
|
2361
|
-
const match =
|
|
2386
|
+
const match = prevObserversMap.get(defaultedOptions.queryHash);
|
|
2362
2387
|
if (match != null) {
|
|
2363
2388
|
return [{
|
|
2364
2389
|
defaultedQueryOptions: defaultedOptions,
|
|
@@ -2367,8 +2392,8 @@
|
|
|
2367
2392
|
}
|
|
2368
2393
|
return [];
|
|
2369
2394
|
});
|
|
2370
|
-
const matchedQueryHashes = matchingObservers.map(match => match.defaultedQueryOptions.queryHash);
|
|
2371
|
-
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.
|
|
2395
|
+
const matchedQueryHashes = new Set(matchingObservers.map(match => match.defaultedQueryOptions.queryHash));
|
|
2396
|
+
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.has(defaultedOptions.queryHash));
|
|
2372
2397
|
const getObserver = options => {
|
|
2373
2398
|
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2374
2399
|
const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
|
|
@@ -2386,7 +2411,7 @@
|
|
|
2386
2411
|
#onUpdate(observer, result) {
|
|
2387
2412
|
const index = this.#observers.indexOf(observer);
|
|
2388
2413
|
if (index !== -1) {
|
|
2389
|
-
this.#
|
|
2414
|
+
this.#setResult(replaceAt(this.#result, index, result));
|
|
2390
2415
|
this.#notify();
|
|
2391
2416
|
}
|
|
2392
2417
|
}
|
|
@@ -2425,7 +2450,7 @@
|
|
|
2425
2450
|
options.behavior = infiniteQueryBehavior();
|
|
2426
2451
|
return super.getOptimisticResult(options);
|
|
2427
2452
|
}
|
|
2428
|
-
fetchNextPage(options
|
|
2453
|
+
fetchNextPage(options) {
|
|
2429
2454
|
return this.fetch({
|
|
2430
2455
|
...options,
|
|
2431
2456
|
meta: {
|
|
@@ -2435,9 +2460,7 @@
|
|
|
2435
2460
|
}
|
|
2436
2461
|
});
|
|
2437
2462
|
}
|
|
2438
|
-
fetchPreviousPage({
|
|
2439
|
-
...options
|
|
2440
|
-
} = {}) {
|
|
2463
|
+
fetchPreviousPage(options) {
|
|
2441
2464
|
return this.fetch({
|
|
2442
2465
|
...options,
|
|
2443
2466
|
meta: {
|
|
@@ -2462,8 +2485,8 @@
|
|
|
2462
2485
|
...result,
|
|
2463
2486
|
fetchNextPage: this.fetchNextPage,
|
|
2464
2487
|
fetchPreviousPage: this.fetchPreviousPage,
|
|
2465
|
-
hasNextPage: hasNextPage(options, state.data
|
|
2466
|
-
hasPreviousPage: hasPreviousPage(options, state.data
|
|
2488
|
+
hasNextPage: hasNextPage(options, state.data),
|
|
2489
|
+
hasPreviousPage: hasPreviousPage(options, state.data),
|
|
2467
2490
|
isFetchingNextPage,
|
|
2468
2491
|
isFetchingPreviousPage,
|
|
2469
2492
|
isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
|
|
@@ -2504,7 +2527,7 @@
|
|
|
2504
2527
|
this.#currentMutation?.setOptions(this.options);
|
|
2505
2528
|
}
|
|
2506
2529
|
onUnsubscribe() {
|
|
2507
|
-
if (!this.
|
|
2530
|
+
if (!this.hasListeners()) {
|
|
2508
2531
|
this.#currentMutation?.removeObserver(this);
|
|
2509
2532
|
}
|
|
2510
2533
|
}
|
|
@@ -2589,24 +2612,10 @@
|
|
|
2589
2612
|
return query.state.status === 'success';
|
|
2590
2613
|
}
|
|
2591
2614
|
function dehydrate(client, options = {}) {
|
|
2592
|
-
const
|
|
2593
|
-
const
|
|
2594
|
-
|
|
2595
|
-
|
|
2596
|
-
client.getMutationCache().getAll().forEach(mutation => {
|
|
2597
|
-
if (shouldDehydrateMutation(mutation)) {
|
|
2598
|
-
mutations.push(dehydrateMutation(mutation));
|
|
2599
|
-
}
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
if (options.dehydrateQueries !== false) {
|
|
2603
|
-
const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
|
|
2604
|
-
client.getQueryCache().getAll().forEach(query => {
|
|
2605
|
-
if (shouldDehydrateQuery(query)) {
|
|
2606
|
-
queries.push(dehydrateQuery(query));
|
|
2607
|
-
}
|
|
2608
|
-
});
|
|
2609
|
-
}
|
|
2615
|
+
const filterMutation = options.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
|
|
2616
|
+
const mutations = client.getMutationCache().getAll().flatMap(mutation => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []);
|
|
2617
|
+
const filterQuery = options.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
|
|
2618
|
+
const queries = client.getQueryCache().getAll().flatMap(query => filterQuery(query) ? [dehydrateQuery(query)] : []);
|
|
2610
2619
|
return {
|
|
2611
2620
|
mutations,
|
|
2612
2621
|
queries
|
|
@@ -3674,16 +3683,15 @@
|
|
|
3674
3683
|
};
|
|
3675
3684
|
}
|
|
3676
3685
|
|
|
3677
|
-
/* istanbul ignore file */
|
|
3678
3686
|
// eslint-disable-next-line no-shadow
|
|
3679
|
-
var QueryState
|
|
3680
|
-
(function (QueryState) {
|
|
3687
|
+
var QueryState = /*#__PURE__*/function (QueryState) {
|
|
3681
3688
|
QueryState[QueryState["Fetching"] = 0] = "Fetching";
|
|
3682
3689
|
QueryState[QueryState["Fresh"] = 1] = "Fresh";
|
|
3683
3690
|
QueryState[QueryState["Stale"] = 2] = "Stale";
|
|
3684
3691
|
QueryState[QueryState["Inactive"] = 3] = "Inactive";
|
|
3685
3692
|
QueryState[QueryState["Paused"] = 4] = "Paused";
|
|
3686
|
-
|
|
3693
|
+
return QueryState;
|
|
3694
|
+
}(QueryState || {});
|
|
3687
3695
|
function getQueryState(query) {
|
|
3688
3696
|
if (query.state.fetchStatus === 'fetching') {
|
|
3689
3697
|
return QueryState.Fetching;
|
|
@@ -3752,7 +3760,6 @@
|
|
|
3752
3760
|
'Last Updated': dateSort
|
|
3753
3761
|
};
|
|
3754
3762
|
|
|
3755
|
-
/* istanbul ignore file */
|
|
3756
3763
|
const pluginId = 'vue-query';
|
|
3757
3764
|
const pluginName = 'Vue Query';
|
|
3758
3765
|
function setupDevtools(app, queryClient) {
|
|
@@ -3760,8 +3767,8 @@
|
|
|
3760
3767
|
id: pluginId,
|
|
3761
3768
|
label: pluginName,
|
|
3762
3769
|
packageName: 'vue-query',
|
|
3763
|
-
homepage: 'https://tanstack.com/query/
|
|
3764
|
-
logo: 'https://vue-query
|
|
3770
|
+
homepage: 'https://tanstack.com/query/latest',
|
|
3771
|
+
logo: 'https://raw.githubusercontent.com/TanStack/query/main/packages/vue-query/media/vue-query.svg',
|
|
3765
3772
|
app,
|
|
3766
3773
|
settings: {
|
|
3767
3774
|
baseSort: {
|
|
@@ -3785,16 +3792,31 @@
|
|
|
3785
3792
|
value: key
|
|
3786
3793
|
})),
|
|
3787
3794
|
defaultValue: Object.keys(sortFns)[0]
|
|
3795
|
+
},
|
|
3796
|
+
onlineMode: {
|
|
3797
|
+
type: 'choice',
|
|
3798
|
+
component: 'button-group',
|
|
3799
|
+
label: 'Online mode',
|
|
3800
|
+
options: [{
|
|
3801
|
+
label: 'Online',
|
|
3802
|
+
value: 1
|
|
3803
|
+
}, {
|
|
3804
|
+
label: 'Offline',
|
|
3805
|
+
value: 0
|
|
3806
|
+
}],
|
|
3807
|
+
defaultValue: 1
|
|
3788
3808
|
}
|
|
3789
3809
|
}
|
|
3790
3810
|
}, api => {
|
|
3811
|
+
const initialSettings = api.getSettings();
|
|
3812
|
+
onlineManager.setOnline(Boolean(initialSettings.onlineMode.valueOf()));
|
|
3791
3813
|
const queryCache = queryClient.getQueryCache();
|
|
3792
3814
|
api.addInspector({
|
|
3793
3815
|
id: pluginId,
|
|
3794
3816
|
label: pluginName,
|
|
3795
3817
|
icon: 'api',
|
|
3796
3818
|
nodeActions: [{
|
|
3797
|
-
icon: '
|
|
3819
|
+
icon: 'file_download',
|
|
3798
3820
|
tooltip: 'Refetch',
|
|
3799
3821
|
action: queryHash => {
|
|
3800
3822
|
queryCache.get(queryHash)?.fetch();
|
|
@@ -3819,6 +3841,27 @@
|
|
|
3819
3841
|
const query = queryCache.get(queryHash);
|
|
3820
3842
|
queryCache.remove(query);
|
|
3821
3843
|
}
|
|
3844
|
+
}, {
|
|
3845
|
+
icon: 'hourglass_empty',
|
|
3846
|
+
tooltip: 'Force loading',
|
|
3847
|
+
action: queryHash => {
|
|
3848
|
+
const query = queryCache.get(queryHash);
|
|
3849
|
+
query.setState({
|
|
3850
|
+
data: undefined,
|
|
3851
|
+
status: 'pending'
|
|
3852
|
+
});
|
|
3853
|
+
}
|
|
3854
|
+
}, {
|
|
3855
|
+
icon: 'error_outline',
|
|
3856
|
+
tooltip: 'Force error',
|
|
3857
|
+
action: queryHash => {
|
|
3858
|
+
const query = queryCache.get(queryHash);
|
|
3859
|
+
query.setState({
|
|
3860
|
+
data: undefined,
|
|
3861
|
+
status: 'error',
|
|
3862
|
+
error: new Error('Unknown error from devtools')
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3822
3865
|
}]
|
|
3823
3866
|
});
|
|
3824
3867
|
api.addTimelineLayer({
|
|
@@ -3829,9 +3872,7 @@
|
|
|
3829
3872
|
queryCache.subscribe(event => {
|
|
3830
3873
|
api.sendInspectorTree(pluginId);
|
|
3831
3874
|
api.sendInspectorState(pluginId);
|
|
3832
|
-
if (
|
|
3833
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
3834
|
-
event && ['queryAdded', 'queryRemoved', 'queryUpdated'].includes(event.type)) {
|
|
3875
|
+
if (['added', 'removed', 'updated'].includes(event.type)) {
|
|
3835
3876
|
api.addTimelineEvent({
|
|
3836
3877
|
layerId: pluginId,
|
|
3837
3878
|
event: {
|
|
@@ -3846,6 +3887,11 @@
|
|
|
3846
3887
|
});
|
|
3847
3888
|
}
|
|
3848
3889
|
});
|
|
3890
|
+
api.on.setPluginSettings(payload => {
|
|
3891
|
+
if (payload.key === 'onlineMode') {
|
|
3892
|
+
onlineManager.setOnline(Boolean(payload.newValue));
|
|
3893
|
+
}
|
|
3894
|
+
});
|
|
3849
3895
|
api.on.getInspectorTree(payload => {
|
|
3850
3896
|
if (payload.inspectorId === pluginId) {
|
|
3851
3897
|
const queries = queryCache.getAll();
|
|
@@ -3938,8 +3984,6 @@
|
|
|
3938
3984
|
originalUnmount();
|
|
3939
3985
|
};
|
|
3940
3986
|
}
|
|
3941
|
-
|
|
3942
|
-
/* istanbul ignore next */
|
|
3943
3987
|
if (vueDemi.isVue2) {
|
|
3944
3988
|
app.mixin({
|
|
3945
3989
|
beforeCreate() {
|
|
@@ -4038,35 +4082,49 @@
|
|
|
4038
4082
|
}
|
|
4039
4083
|
|
|
4040
4084
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4085
|
+
|
|
4086
|
+
// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
|
|
4087
|
+
// `placeholderData` function does not have a parameter
|
|
4088
|
+
// Avoid TS depth-limit error in case of large array literal
|
|
4089
|
+
/**
|
|
4090
|
+
* UseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
4091
|
+
*/
|
|
4092
|
+
/**
|
|
4093
|
+
* UseQueriesResults reducer recursively maps type param to results
|
|
4094
|
+
*/
|
|
4041
4095
|
function useQueries({
|
|
4042
|
-
queries
|
|
4096
|
+
queries,
|
|
4097
|
+
...options
|
|
4043
4098
|
}, queryClient) {
|
|
4044
4099
|
const client = queryClient || useQueryClient();
|
|
4045
|
-
const defaultedQueries = vueDemi.computed(() => cloneDeepUnref(queries).map(
|
|
4046
|
-
const defaulted = client.defaultQueryOptions(
|
|
4100
|
+
const defaultedQueries = vueDemi.computed(() => cloneDeepUnref(queries).map(queryOptions => {
|
|
4101
|
+
const defaulted = client.defaultQueryOptions(queryOptions);
|
|
4047
4102
|
defaulted._optimisticResults = client.isRestoring.value ? 'isRestoring' : 'optimistic';
|
|
4048
4103
|
return defaulted;
|
|
4049
4104
|
}));
|
|
4050
|
-
const observer = new QueriesObserver(client, defaultedQueries.value);
|
|
4051
|
-
const
|
|
4105
|
+
const observer = new QueriesObserver(client, defaultedQueries.value, options);
|
|
4106
|
+
const [, getCombinedResult] = observer.getOptimisticResult(defaultedQueries.value);
|
|
4107
|
+
const state = vueDemi.ref(getCombinedResult());
|
|
4052
4108
|
const unsubscribe = vueDemi.ref(() => {
|
|
4053
4109
|
// noop
|
|
4054
4110
|
});
|
|
4055
4111
|
vueDemi.watch(client.isRestoring, isRestoring => {
|
|
4056
4112
|
if (!isRestoring) {
|
|
4057
4113
|
unsubscribe.value();
|
|
4058
|
-
unsubscribe.value = observer.subscribe(
|
|
4059
|
-
|
|
4114
|
+
unsubscribe.value = observer.subscribe(() => {
|
|
4115
|
+
const [, getCombinedResultRestoring] = observer.getOptimisticResult(defaultedQueries.value);
|
|
4116
|
+
state.value = getCombinedResultRestoring();
|
|
4060
4117
|
});
|
|
4061
4118
|
// Subscription would not fire for persisted results
|
|
4062
|
-
|
|
4119
|
+
const [, getCombinedResultPersisted] = observer.getOptimisticResult(defaultedQueries.value);
|
|
4120
|
+
state.value = getCombinedResultPersisted();
|
|
4063
4121
|
}
|
|
4064
4122
|
}, {
|
|
4065
4123
|
immediate: true
|
|
4066
4124
|
});
|
|
4067
|
-
vueDemi.watch(defaultedQueries, () => {
|
|
4068
|
-
observer.setQueries(defaultedQueries.value);
|
|
4069
|
-
state.value
|
|
4125
|
+
vueDemi.watch([defaultedQueries], () => {
|
|
4126
|
+
observer.setQueries(defaultedQueries.value, options);
|
|
4127
|
+
state.value = observer.getCurrentResult();
|
|
4070
4128
|
}, {
|
|
4071
4129
|
deep: true
|
|
4072
4130
|
});
|
|
@@ -4139,22 +4197,31 @@
|
|
|
4139
4197
|
return isFetching;
|
|
4140
4198
|
}
|
|
4141
4199
|
|
|
4142
|
-
function useIsMutating(
|
|
4143
|
-
const filters = vueDemi.computed(() => cloneDeepUnref(mutationFilters));
|
|
4200
|
+
function useIsMutating(filters = {}, queryClient) {
|
|
4144
4201
|
const client = queryClient || useQueryClient();
|
|
4145
|
-
const
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
});
|
|
4149
|
-
vueDemi.
|
|
4150
|
-
|
|
4151
|
-
},
|
|
4152
|
-
|
|
4202
|
+
const unreffedFilters = vueDemi.computed(() => ({
|
|
4203
|
+
...cloneDeepUnref(filters),
|
|
4204
|
+
status: 'pending'
|
|
4205
|
+
}));
|
|
4206
|
+
const length = vueDemi.computed(() => useMutationState({
|
|
4207
|
+
filters: unreffedFilters
|
|
4208
|
+
}, client).value.length);
|
|
4209
|
+
return length;
|
|
4210
|
+
}
|
|
4211
|
+
function getResult(mutationCache, options) {
|
|
4212
|
+
return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);
|
|
4213
|
+
}
|
|
4214
|
+
function useMutationState(options = {}, queryClient) {
|
|
4215
|
+
const mutationCache = (queryClient || useQueryClient()).getMutationCache();
|
|
4216
|
+
const state = vueDemi.ref(getResult(mutationCache, options));
|
|
4217
|
+
const unsubscribe = mutationCache.subscribe(() => {
|
|
4218
|
+
const result = getResult(mutationCache, options);
|
|
4219
|
+
state.value = result;
|
|
4153
4220
|
});
|
|
4154
4221
|
vueDemi.onScopeDispose(() => {
|
|
4155
4222
|
unsubscribe();
|
|
4156
4223
|
});
|
|
4157
|
-
return
|
|
4224
|
+
return vueDemi.readonly(state);
|
|
4158
4225
|
}
|
|
4159
4226
|
|
|
4160
4227
|
exports.CancelledError = CancelledError;
|
|
@@ -4184,6 +4251,7 @@
|
|
|
4184
4251
|
exports.useIsFetching = useIsFetching;
|
|
4185
4252
|
exports.useIsMutating = useIsMutating;
|
|
4186
4253
|
exports.useMutation = useMutation;
|
|
4254
|
+
exports.useMutationState = useMutationState;
|
|
4187
4255
|
exports.useQueries = useQueries;
|
|
4188
4256
|
exports.useQuery = useQuery;
|
|
4189
4257
|
exports.useQueryClient = useQueryClient;
|