zmdms-webui 1.5.3 → 1.5.5
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/dist/es/enhanceselect/enhance-select.js +1 -1
- package/dist/es/enhanceselect/list-query.js +1 -1
- package/dist/es/enhanceselect/page-query.js +1 -1
- package/package.json +4 -2
- package/dist/es/node_modules/@tanstack/query-core/build/modern/focusManager.js +0 -66
- package/dist/es/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js +0 -118
- package/dist/es/node_modules/@tanstack/query-core/build/modern/infiniteQueryObserver.js +0 -66
- package/dist/es/node_modules/@tanstack/query-core/build/modern/notifyManager.js +0 -81
- package/dist/es/node_modules/@tanstack/query-core/build/modern/onlineManager.js +0 -56
- package/dist/es/node_modules/@tanstack/query-core/build/modern/query.js +0 -16
- package/dist/es/node_modules/@tanstack/query-core/build/modern/queryObserver.js +0 -453
- package/dist/es/node_modules/@tanstack/query-core/build/modern/retryer.js +0 -8
- package/dist/es/node_modules/@tanstack/query-core/build/modern/subscribable.js +0 -24
- package/dist/es/node_modules/@tanstack/query-core/build/modern/thenable.js +0 -34
- package/dist/es/node_modules/@tanstack/query-core/build/modern/utils.js +0 -126
- package/dist/es/node_modules/@tanstack/react-query/build/modern/IsRestoringProvider.js +0 -7
- package/dist/es/node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js +0 -18
- package/dist/es/node_modules/@tanstack/react-query/build/modern/QueryErrorResetBoundary.js +0 -21
- package/dist/es/node_modules/@tanstack/react-query/build/modern/errorBoundaryUtils.js +0 -26
- package/dist/es/node_modules/@tanstack/react-query/build/modern/suspense.js +0 -17
- package/dist/es/node_modules/@tanstack/react-query/build/modern/useBaseQuery.js +0 -92
- package/dist/es/node_modules/@tanstack/react-query/build/modern/useInfiniteQuery.js +0 -12
- package/dist/es/node_modules/@tanstack/react-query/build/modern/useQuery.js +0 -8
- package/dist/es/node_modules/@tanstack/react-query/build/modern/utils.js +0 -11
|
@@ -12,7 +12,7 @@ import ButtonCom from '../button/button.js';
|
|
|
12
12
|
* 注意:如果你的下拉框数据,不需要通过接口来获取,可以使用普通的Select组件。
|
|
13
13
|
*/
|
|
14
14
|
var EnhanceSelect = function (props, ref) {
|
|
15
|
-
var isPage = props.isPage
|
|
15
|
+
var isPage = props.isPage; props.request; props.url; props.params; props.method; props.timeout; props.isCache; props.transformData; props.firstLoadDataKey; props.pageSize; props.remoteSearchKey; props.mustQueryKeys; var resetProps = __rest(props, ["isPage", "request", "url", "params", "method", "timeout", "isCache", "transformData", "firstLoadDataKey", "pageSize", "remoteSearchKey", "mustQueryKeys"]);
|
|
16
16
|
return !isPage ? (jsx(MemoListQuery, __assign({}, props, { customRender: function (_a) {
|
|
17
17
|
var list = _a.list, isLoading = _a.isLoading, refetch = _a.refetch, isEnabled = _a.isEnabled;
|
|
18
18
|
return (jsx(MemoSelect, __assign({ placeholder: "\u8BF7\u9009\u62E9", list: list, loading: isLoading, dropdownButton: jsx(ButtonCom, __assign({ onClick: function () {
|
|
@@ -3,7 +3,7 @@ import { jsx, Fragment } from 'react/jsx-runtime';
|
|
|
3
3
|
import { memo } from 'react';
|
|
4
4
|
import '../config/ZtxkContext.js';
|
|
5
5
|
import useBaseContext from '../config/useBaseContext.js';
|
|
6
|
-
import { useQuery } from '
|
|
6
|
+
import { useQuery } from '@tanstack/react-query';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 不分页的查询逻辑
|
|
@@ -3,7 +3,7 @@ import { jsx, Fragment } from 'react/jsx-runtime';
|
|
|
3
3
|
import { memo, useState, useRef } from 'react';
|
|
4
4
|
import '../config/ZtxkContext.js';
|
|
5
5
|
import useBaseContext from '../config/useBaseContext.js';
|
|
6
|
-
import { useInfiniteQuery } from '
|
|
6
|
+
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* 不分页的查询逻辑
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zmdms-webui",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/index.es.js",
|
|
6
6
|
"module": "dist/index.es.js",
|
|
@@ -20,7 +20,9 @@
|
|
|
20
20
|
"react-dom": ">=16.8.0",
|
|
21
21
|
"react-resizable": "^3.0.5",
|
|
22
22
|
"react-router-dom": ">=6",
|
|
23
|
-
"zmdms-utils": ">=0.0.1"
|
|
23
|
+
"zmdms-utils": ">=0.0.1",
|
|
24
|
+
"@tanstack/react-query": ">=5",
|
|
25
|
+
"@tanstack/react-query-devtools": ">=5"
|
|
24
26
|
},
|
|
25
27
|
"sideEffects": [
|
|
26
28
|
"dist/es/**/style/*",
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { Subscribable } from './subscribable.js';
|
|
2
|
-
import { isServer } from './utils.js';
|
|
3
|
-
|
|
4
|
-
// src/focusManager.ts
|
|
5
|
-
var FocusManager = class extends Subscribable {
|
|
6
|
-
#focused;
|
|
7
|
-
#cleanup;
|
|
8
|
-
#setup;
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
this.#setup = (onFocus) => {
|
|
12
|
-
if (!isServer && window.addEventListener) {
|
|
13
|
-
const listener = () => onFocus();
|
|
14
|
-
window.addEventListener("visibilitychange", listener, false);
|
|
15
|
-
return () => {
|
|
16
|
-
window.removeEventListener("visibilitychange", listener);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
return;
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
onSubscribe() {
|
|
23
|
-
if (!this.#cleanup) {
|
|
24
|
-
this.setEventListener(this.#setup);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
onUnsubscribe() {
|
|
28
|
-
if (!this.hasListeners()) {
|
|
29
|
-
this.#cleanup?.();
|
|
30
|
-
this.#cleanup = void 0;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
setEventListener(setup) {
|
|
34
|
-
this.#setup = setup;
|
|
35
|
-
this.#cleanup?.();
|
|
36
|
-
this.#cleanup = setup((focused) => {
|
|
37
|
-
if (typeof focused === "boolean") {
|
|
38
|
-
this.setFocused(focused);
|
|
39
|
-
} else {
|
|
40
|
-
this.onFocus();
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
setFocused(focused) {
|
|
45
|
-
const changed = this.#focused !== focused;
|
|
46
|
-
if (changed) {
|
|
47
|
-
this.#focused = focused;
|
|
48
|
-
this.onFocus();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
onFocus() {
|
|
52
|
-
const isFocused = this.isFocused();
|
|
53
|
-
this.listeners.forEach((listener) => {
|
|
54
|
-
listener(isFocused);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
isFocused() {
|
|
58
|
-
if (typeof this.#focused === "boolean") {
|
|
59
|
-
return this.#focused;
|
|
60
|
-
}
|
|
61
|
-
return globalThis.document?.visibilityState !== "hidden";
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
var focusManager = new FocusManager();
|
|
65
|
-
|
|
66
|
-
export { FocusManager, focusManager };
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { ensureQueryFn, addToStart, addToEnd } from './utils.js';
|
|
2
|
-
|
|
3
|
-
// src/infiniteQueryBehavior.ts
|
|
4
|
-
function infiniteQueryBehavior(pages) {
|
|
5
|
-
return {
|
|
6
|
-
onFetch: (context, query) => {
|
|
7
|
-
const options = context.options;
|
|
8
|
-
const direction = context.fetchOptions?.meta?.fetchMore?.direction;
|
|
9
|
-
const oldPages = context.state.data?.pages || [];
|
|
10
|
-
const oldPageParams = context.state.data?.pageParams || [];
|
|
11
|
-
let result = { pages: [], pageParams: [] };
|
|
12
|
-
let currentPage = 0;
|
|
13
|
-
const fetchFn = async () => {
|
|
14
|
-
let cancelled = false;
|
|
15
|
-
const addSignalProperty = (object) => {
|
|
16
|
-
Object.defineProperty(object, "signal", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: () => {
|
|
19
|
-
if (context.signal.aborted) {
|
|
20
|
-
cancelled = true;
|
|
21
|
-
} else {
|
|
22
|
-
context.signal.addEventListener("abort", () => {
|
|
23
|
-
cancelled = true;
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return context.signal;
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
};
|
|
30
|
-
const queryFn = ensureQueryFn(context.options, context.fetchOptions);
|
|
31
|
-
const fetchPage = async (data, param, previous) => {
|
|
32
|
-
if (cancelled) {
|
|
33
|
-
return Promise.reject();
|
|
34
|
-
}
|
|
35
|
-
if (param == null && data.pages.length) {
|
|
36
|
-
return Promise.resolve(data);
|
|
37
|
-
}
|
|
38
|
-
const queryFnContext = {
|
|
39
|
-
client: context.client,
|
|
40
|
-
queryKey: context.queryKey,
|
|
41
|
-
pageParam: param,
|
|
42
|
-
direction: previous ? "backward" : "forward",
|
|
43
|
-
meta: context.options.meta
|
|
44
|
-
};
|
|
45
|
-
addSignalProperty(queryFnContext);
|
|
46
|
-
const page = await queryFn(
|
|
47
|
-
queryFnContext
|
|
48
|
-
);
|
|
49
|
-
const { maxPages } = context.options;
|
|
50
|
-
const addTo = previous ? addToStart : addToEnd;
|
|
51
|
-
return {
|
|
52
|
-
pages: addTo(data.pages, page, maxPages),
|
|
53
|
-
pageParams: addTo(data.pageParams, param, maxPages)
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
if (direction && oldPages.length) {
|
|
57
|
-
const previous = direction === "backward";
|
|
58
|
-
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|
59
|
-
const oldData = {
|
|
60
|
-
pages: oldPages,
|
|
61
|
-
pageParams: oldPageParams
|
|
62
|
-
};
|
|
63
|
-
const param = pageParamFn(options, oldData);
|
|
64
|
-
result = await fetchPage(oldData, param, previous);
|
|
65
|
-
} else {
|
|
66
|
-
const remainingPages = pages ?? oldPages.length;
|
|
67
|
-
do {
|
|
68
|
-
const param = currentPage === 0 ? oldPageParams[0] ?? options.initialPageParam : getNextPageParam(options, result);
|
|
69
|
-
if (currentPage > 0 && param == null) {
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
result = await fetchPage(result, param);
|
|
73
|
-
currentPage++;
|
|
74
|
-
} while (currentPage < remainingPages);
|
|
75
|
-
}
|
|
76
|
-
return result;
|
|
77
|
-
};
|
|
78
|
-
if (context.options.persister) {
|
|
79
|
-
context.fetchFn = () => {
|
|
80
|
-
return context.options.persister?.(
|
|
81
|
-
fetchFn,
|
|
82
|
-
{
|
|
83
|
-
client: context.client,
|
|
84
|
-
queryKey: context.queryKey,
|
|
85
|
-
meta: context.options.meta,
|
|
86
|
-
signal: context.signal
|
|
87
|
-
},
|
|
88
|
-
query
|
|
89
|
-
);
|
|
90
|
-
};
|
|
91
|
-
} else {
|
|
92
|
-
context.fetchFn = fetchFn;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function getNextPageParam(options, { pages, pageParams }) {
|
|
98
|
-
const lastIndex = pages.length - 1;
|
|
99
|
-
return pages.length > 0 ? options.getNextPageParam(
|
|
100
|
-
pages[lastIndex],
|
|
101
|
-
pages,
|
|
102
|
-
pageParams[lastIndex],
|
|
103
|
-
pageParams
|
|
104
|
-
) : void 0;
|
|
105
|
-
}
|
|
106
|
-
function getPreviousPageParam(options, { pages, pageParams }) {
|
|
107
|
-
return pages.length > 0 ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams) : void 0;
|
|
108
|
-
}
|
|
109
|
-
function hasNextPage(options, data) {
|
|
110
|
-
if (!data) return false;
|
|
111
|
-
return getNextPageParam(options, data) != null;
|
|
112
|
-
}
|
|
113
|
-
function hasPreviousPage(options, data) {
|
|
114
|
-
if (!data || !options.getPreviousPageParam) return false;
|
|
115
|
-
return getPreviousPageParam(options, data) != null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
export { hasNextPage, hasPreviousPage, infiniteQueryBehavior };
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { QueryObserver } from './queryObserver.js';
|
|
2
|
-
import { infiniteQueryBehavior, hasNextPage, hasPreviousPage } from './infiniteQueryBehavior.js';
|
|
3
|
-
|
|
4
|
-
// src/infiniteQueryObserver.ts
|
|
5
|
-
var InfiniteQueryObserver = class extends QueryObserver {
|
|
6
|
-
constructor(client, options) {
|
|
7
|
-
super(client, options);
|
|
8
|
-
}
|
|
9
|
-
bindMethods() {
|
|
10
|
-
super.bindMethods();
|
|
11
|
-
this.fetchNextPage = this.fetchNextPage.bind(this);
|
|
12
|
-
this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
|
|
13
|
-
}
|
|
14
|
-
setOptions(options) {
|
|
15
|
-
super.setOptions({
|
|
16
|
-
...options,
|
|
17
|
-
behavior: infiniteQueryBehavior()
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
getOptimisticResult(options) {
|
|
21
|
-
options.behavior = infiniteQueryBehavior();
|
|
22
|
-
return super.getOptimisticResult(options);
|
|
23
|
-
}
|
|
24
|
-
fetchNextPage(options) {
|
|
25
|
-
return this.fetch({
|
|
26
|
-
...options,
|
|
27
|
-
meta: {
|
|
28
|
-
fetchMore: { direction: "forward" }
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
fetchPreviousPage(options) {
|
|
33
|
-
return this.fetch({
|
|
34
|
-
...options,
|
|
35
|
-
meta: {
|
|
36
|
-
fetchMore: { direction: "backward" }
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
createResult(query, options) {
|
|
41
|
-
const { state } = query;
|
|
42
|
-
const parentResult = super.createResult(query, options);
|
|
43
|
-
const { isFetching, isRefetching, isError, isRefetchError } = parentResult;
|
|
44
|
-
const fetchDirection = state.fetchMeta?.fetchMore?.direction;
|
|
45
|
-
const isFetchNextPageError = isError && fetchDirection === "forward";
|
|
46
|
-
const isFetchingNextPage = isFetching && fetchDirection === "forward";
|
|
47
|
-
const isFetchPreviousPageError = isError && fetchDirection === "backward";
|
|
48
|
-
const isFetchingPreviousPage = isFetching && fetchDirection === "backward";
|
|
49
|
-
const result = {
|
|
50
|
-
...parentResult,
|
|
51
|
-
fetchNextPage: this.fetchNextPage,
|
|
52
|
-
fetchPreviousPage: this.fetchPreviousPage,
|
|
53
|
-
hasNextPage: hasNextPage(options, state.data),
|
|
54
|
-
hasPreviousPage: hasPreviousPage(options, state.data),
|
|
55
|
-
isFetchNextPageError,
|
|
56
|
-
isFetchingNextPage,
|
|
57
|
-
isFetchPreviousPageError,
|
|
58
|
-
isFetchingPreviousPage,
|
|
59
|
-
isRefetchError: isRefetchError && !isFetchNextPageError && !isFetchPreviousPageError,
|
|
60
|
-
isRefetching: isRefetching && !isFetchingNextPage && !isFetchingPreviousPage
|
|
61
|
-
};
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
export { InfiniteQueryObserver };
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// src/notifyManager.ts
|
|
2
|
-
var defaultScheduler = (cb) => setTimeout(cb, 0);
|
|
3
|
-
function createNotifyManager() {
|
|
4
|
-
let queue = [];
|
|
5
|
-
let transactions = 0;
|
|
6
|
-
let notifyFn = (callback) => {
|
|
7
|
-
callback();
|
|
8
|
-
};
|
|
9
|
-
let batchNotifyFn = (callback) => {
|
|
10
|
-
callback();
|
|
11
|
-
};
|
|
12
|
-
let scheduleFn = defaultScheduler;
|
|
13
|
-
const schedule = (callback) => {
|
|
14
|
-
if (transactions) {
|
|
15
|
-
queue.push(callback);
|
|
16
|
-
} else {
|
|
17
|
-
scheduleFn(() => {
|
|
18
|
-
notifyFn(callback);
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
const flush = () => {
|
|
23
|
-
const originalQueue = queue;
|
|
24
|
-
queue = [];
|
|
25
|
-
if (originalQueue.length) {
|
|
26
|
-
scheduleFn(() => {
|
|
27
|
-
batchNotifyFn(() => {
|
|
28
|
-
originalQueue.forEach((callback) => {
|
|
29
|
-
notifyFn(callback);
|
|
30
|
-
});
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
return {
|
|
36
|
-
batch: (callback) => {
|
|
37
|
-
let result;
|
|
38
|
-
transactions++;
|
|
39
|
-
try {
|
|
40
|
-
result = callback();
|
|
41
|
-
} finally {
|
|
42
|
-
transactions--;
|
|
43
|
-
if (!transactions) {
|
|
44
|
-
flush();
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
},
|
|
49
|
-
/**
|
|
50
|
-
* All calls to the wrapped function will be batched.
|
|
51
|
-
*/
|
|
52
|
-
batchCalls: (callback) => {
|
|
53
|
-
return (...args) => {
|
|
54
|
-
schedule(() => {
|
|
55
|
-
callback(...args);
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
},
|
|
59
|
-
schedule,
|
|
60
|
-
/**
|
|
61
|
-
* Use this method to set a custom notify function.
|
|
62
|
-
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
63
|
-
*/
|
|
64
|
-
setNotifyFunction: (fn) => {
|
|
65
|
-
notifyFn = fn;
|
|
66
|
-
},
|
|
67
|
-
/**
|
|
68
|
-
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
69
|
-
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
70
|
-
*/
|
|
71
|
-
setBatchNotifyFunction: (fn) => {
|
|
72
|
-
batchNotifyFn = fn;
|
|
73
|
-
},
|
|
74
|
-
setScheduler: (fn) => {
|
|
75
|
-
scheduleFn = fn;
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
var notifyManager = createNotifyManager();
|
|
80
|
-
|
|
81
|
-
export { createNotifyManager, defaultScheduler, notifyManager };
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { Subscribable } from './subscribable.js';
|
|
2
|
-
import { isServer } from './utils.js';
|
|
3
|
-
|
|
4
|
-
// src/onlineManager.ts
|
|
5
|
-
var OnlineManager = class extends Subscribable {
|
|
6
|
-
#online = true;
|
|
7
|
-
#cleanup;
|
|
8
|
-
#setup;
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
this.#setup = (onOnline) => {
|
|
12
|
-
if (!isServer && window.addEventListener) {
|
|
13
|
-
const onlineListener = () => onOnline(true);
|
|
14
|
-
const offlineListener = () => onOnline(false);
|
|
15
|
-
window.addEventListener("online", onlineListener, false);
|
|
16
|
-
window.addEventListener("offline", offlineListener, false);
|
|
17
|
-
return () => {
|
|
18
|
-
window.removeEventListener("online", onlineListener);
|
|
19
|
-
window.removeEventListener("offline", offlineListener);
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
return;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
onSubscribe() {
|
|
26
|
-
if (!this.#cleanup) {
|
|
27
|
-
this.setEventListener(this.#setup);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
onUnsubscribe() {
|
|
31
|
-
if (!this.hasListeners()) {
|
|
32
|
-
this.#cleanup?.();
|
|
33
|
-
this.#cleanup = void 0;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
setEventListener(setup) {
|
|
37
|
-
this.#setup = setup;
|
|
38
|
-
this.#cleanup?.();
|
|
39
|
-
this.#cleanup = setup(this.setOnline.bind(this));
|
|
40
|
-
}
|
|
41
|
-
setOnline(online) {
|
|
42
|
-
const changed = this.#online !== online;
|
|
43
|
-
if (changed) {
|
|
44
|
-
this.#online = online;
|
|
45
|
-
this.listeners.forEach((listener) => {
|
|
46
|
-
listener(online);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
isOnline() {
|
|
51
|
-
return this.#online;
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
var onlineManager = new OnlineManager();
|
|
55
|
-
|
|
56
|
-
export { OnlineManager, onlineManager };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { canFetch } from './retryer.js';
|
|
2
|
-
|
|
3
|
-
// src/query.ts
|
|
4
|
-
function fetchState(data, options) {
|
|
5
|
-
return {
|
|
6
|
-
fetchFailureCount: 0,
|
|
7
|
-
fetchFailureReason: null,
|
|
8
|
-
fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
|
|
9
|
-
...data === void 0 && {
|
|
10
|
-
error: null,
|
|
11
|
-
status: "pending"
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export { fetchState };
|
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
import { focusManager } from './focusManager.js';
|
|
2
|
-
import { notifyManager } from './notifyManager.js';
|
|
3
|
-
import { fetchState } from './query.js';
|
|
4
|
-
import { Subscribable } from './subscribable.js';
|
|
5
|
-
import { pendingThenable } from './thenable.js';
|
|
6
|
-
import { resolveEnabled, shallowEqualObjects, resolveStaleTime, noop, isServer, isValidTimeout, timeUntilStale, replaceData } from './utils.js';
|
|
7
|
-
|
|
8
|
-
// src/queryObserver.ts
|
|
9
|
-
var QueryObserver = class extends Subscribable {
|
|
10
|
-
constructor(client, options) {
|
|
11
|
-
super();
|
|
12
|
-
this.options = options;
|
|
13
|
-
this.#client = client;
|
|
14
|
-
this.#selectError = null;
|
|
15
|
-
this.#currentThenable = pendingThenable();
|
|
16
|
-
if (!this.options.experimental_prefetchInRender) {
|
|
17
|
-
this.#currentThenable.reject(
|
|
18
|
-
new Error("experimental_prefetchInRender feature flag is not enabled")
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
this.bindMethods();
|
|
22
|
-
this.setOptions(options);
|
|
23
|
-
}
|
|
24
|
-
#client;
|
|
25
|
-
#currentQuery = void 0;
|
|
26
|
-
#currentQueryInitialState = void 0;
|
|
27
|
-
#currentResult = void 0;
|
|
28
|
-
#currentResultState;
|
|
29
|
-
#currentResultOptions;
|
|
30
|
-
#currentThenable;
|
|
31
|
-
#selectError;
|
|
32
|
-
#selectFn;
|
|
33
|
-
#selectResult;
|
|
34
|
-
// This property keeps track of the last query with defined data.
|
|
35
|
-
// It will be used to pass the previous data and query to the placeholder function between renders.
|
|
36
|
-
#lastQueryWithDefinedData;
|
|
37
|
-
#staleTimeoutId;
|
|
38
|
-
#refetchIntervalId;
|
|
39
|
-
#currentRefetchInterval;
|
|
40
|
-
#trackedProps = /* @__PURE__ */ new Set();
|
|
41
|
-
bindMethods() {
|
|
42
|
-
this.refetch = this.refetch.bind(this);
|
|
43
|
-
}
|
|
44
|
-
onSubscribe() {
|
|
45
|
-
if (this.listeners.size === 1) {
|
|
46
|
-
this.#currentQuery.addObserver(this);
|
|
47
|
-
if (shouldFetchOnMount(this.#currentQuery, this.options)) {
|
|
48
|
-
this.#executeFetch();
|
|
49
|
-
} else {
|
|
50
|
-
this.updateResult();
|
|
51
|
-
}
|
|
52
|
-
this.#updateTimers();
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
onUnsubscribe() {
|
|
56
|
-
if (!this.hasListeners()) {
|
|
57
|
-
this.destroy();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
shouldFetchOnReconnect() {
|
|
61
|
-
return shouldFetchOn(
|
|
62
|
-
this.#currentQuery,
|
|
63
|
-
this.options,
|
|
64
|
-
this.options.refetchOnReconnect
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
shouldFetchOnWindowFocus() {
|
|
68
|
-
return shouldFetchOn(
|
|
69
|
-
this.#currentQuery,
|
|
70
|
-
this.options,
|
|
71
|
-
this.options.refetchOnWindowFocus
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
destroy() {
|
|
75
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
76
|
-
this.#clearStaleTimeout();
|
|
77
|
-
this.#clearRefetchInterval();
|
|
78
|
-
this.#currentQuery.removeObserver(this);
|
|
79
|
-
}
|
|
80
|
-
setOptions(options) {
|
|
81
|
-
const prevOptions = this.options;
|
|
82
|
-
const prevQuery = this.#currentQuery;
|
|
83
|
-
this.options = this.#client.defaultQueryOptions(options);
|
|
84
|
-
if (this.options.enabled !== void 0 && typeof this.options.enabled !== "boolean" && typeof this.options.enabled !== "function" && typeof resolveEnabled(this.options.enabled, this.#currentQuery) !== "boolean") {
|
|
85
|
-
throw new Error(
|
|
86
|
-
"Expected enabled to be a boolean or a callback that returns a boolean"
|
|
87
|
-
);
|
|
88
|
-
}
|
|
89
|
-
this.#updateQuery();
|
|
90
|
-
this.#currentQuery.setOptions(this.options);
|
|
91
|
-
if (prevOptions._defaulted && !shallowEqualObjects(this.options, prevOptions)) {
|
|
92
|
-
this.#client.getQueryCache().notify({
|
|
93
|
-
type: "observerOptionsUpdated",
|
|
94
|
-
query: this.#currentQuery,
|
|
95
|
-
observer: this
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
const mounted = this.hasListeners();
|
|
99
|
-
if (mounted && shouldFetchOptionally(
|
|
100
|
-
this.#currentQuery,
|
|
101
|
-
prevQuery,
|
|
102
|
-
this.options,
|
|
103
|
-
prevOptions
|
|
104
|
-
)) {
|
|
105
|
-
this.#executeFetch();
|
|
106
|
-
}
|
|
107
|
-
this.updateResult();
|
|
108
|
-
if (mounted && (this.#currentQuery !== prevQuery || resolveEnabled(this.options.enabled, this.#currentQuery) !== resolveEnabled(prevOptions.enabled, this.#currentQuery) || resolveStaleTime(this.options.staleTime, this.#currentQuery) !== resolveStaleTime(prevOptions.staleTime, this.#currentQuery))) {
|
|
109
|
-
this.#updateStaleTimeout();
|
|
110
|
-
}
|
|
111
|
-
const nextRefetchInterval = this.#computeRefetchInterval();
|
|
112
|
-
if (mounted && (this.#currentQuery !== prevQuery || resolveEnabled(this.options.enabled, this.#currentQuery) !== resolveEnabled(prevOptions.enabled, this.#currentQuery) || nextRefetchInterval !== this.#currentRefetchInterval)) {
|
|
113
|
-
this.#updateRefetchInterval(nextRefetchInterval);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
getOptimisticResult(options) {
|
|
117
|
-
const query = this.#client.getQueryCache().build(this.#client, options);
|
|
118
|
-
const result = this.createResult(query, options);
|
|
119
|
-
if (shouldAssignObserverCurrentProperties(this, result)) {
|
|
120
|
-
this.#currentResult = result;
|
|
121
|
-
this.#currentResultOptions = this.options;
|
|
122
|
-
this.#currentResultState = this.#currentQuery.state;
|
|
123
|
-
}
|
|
124
|
-
return result;
|
|
125
|
-
}
|
|
126
|
-
getCurrentResult() {
|
|
127
|
-
return this.#currentResult;
|
|
128
|
-
}
|
|
129
|
-
trackResult(result, onPropTracked) {
|
|
130
|
-
return new Proxy(result, {
|
|
131
|
-
get: (target, key) => {
|
|
132
|
-
this.trackProp(key);
|
|
133
|
-
onPropTracked?.(key);
|
|
134
|
-
return Reflect.get(target, key);
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
trackProp(key) {
|
|
139
|
-
this.#trackedProps.add(key);
|
|
140
|
-
}
|
|
141
|
-
getCurrentQuery() {
|
|
142
|
-
return this.#currentQuery;
|
|
143
|
-
}
|
|
144
|
-
refetch({ ...options } = {}) {
|
|
145
|
-
return this.fetch({
|
|
146
|
-
...options
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
fetchOptimistic(options) {
|
|
150
|
-
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
151
|
-
const query = this.#client.getQueryCache().build(this.#client, defaultedOptions);
|
|
152
|
-
return query.fetch().then(() => this.createResult(query, defaultedOptions));
|
|
153
|
-
}
|
|
154
|
-
fetch(fetchOptions) {
|
|
155
|
-
return this.#executeFetch({
|
|
156
|
-
...fetchOptions,
|
|
157
|
-
cancelRefetch: fetchOptions.cancelRefetch ?? true
|
|
158
|
-
}).then(() => {
|
|
159
|
-
this.updateResult();
|
|
160
|
-
return this.#currentResult;
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
#executeFetch(fetchOptions) {
|
|
164
|
-
this.#updateQuery();
|
|
165
|
-
let promise = this.#currentQuery.fetch(
|
|
166
|
-
this.options,
|
|
167
|
-
fetchOptions
|
|
168
|
-
);
|
|
169
|
-
if (!fetchOptions?.throwOnError) {
|
|
170
|
-
promise = promise.catch(noop);
|
|
171
|
-
}
|
|
172
|
-
return promise;
|
|
173
|
-
}
|
|
174
|
-
#updateStaleTimeout() {
|
|
175
|
-
this.#clearStaleTimeout();
|
|
176
|
-
const staleTime = resolveStaleTime(
|
|
177
|
-
this.options.staleTime,
|
|
178
|
-
this.#currentQuery
|
|
179
|
-
);
|
|
180
|
-
if (isServer || this.#currentResult.isStale || !isValidTimeout(staleTime)) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
const time = timeUntilStale(this.#currentResult.dataUpdatedAt, staleTime);
|
|
184
|
-
const timeout = time + 1;
|
|
185
|
-
this.#staleTimeoutId = setTimeout(() => {
|
|
186
|
-
if (!this.#currentResult.isStale) {
|
|
187
|
-
this.updateResult();
|
|
188
|
-
}
|
|
189
|
-
}, timeout);
|
|
190
|
-
}
|
|
191
|
-
#computeRefetchInterval() {
|
|
192
|
-
return (typeof this.options.refetchInterval === "function" ? this.options.refetchInterval(this.#currentQuery) : this.options.refetchInterval) ?? false;
|
|
193
|
-
}
|
|
194
|
-
#updateRefetchInterval(nextInterval) {
|
|
195
|
-
this.#clearRefetchInterval();
|
|
196
|
-
this.#currentRefetchInterval = nextInterval;
|
|
197
|
-
if (isServer || resolveEnabled(this.options.enabled, this.#currentQuery) === false || !isValidTimeout(this.#currentRefetchInterval) || this.#currentRefetchInterval === 0) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
this.#refetchIntervalId = setInterval(() => {
|
|
201
|
-
if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
|
|
202
|
-
this.#executeFetch();
|
|
203
|
-
}
|
|
204
|
-
}, this.#currentRefetchInterval);
|
|
205
|
-
}
|
|
206
|
-
#updateTimers() {
|
|
207
|
-
this.#updateStaleTimeout();
|
|
208
|
-
this.#updateRefetchInterval(this.#computeRefetchInterval());
|
|
209
|
-
}
|
|
210
|
-
#clearStaleTimeout() {
|
|
211
|
-
if (this.#staleTimeoutId) {
|
|
212
|
-
clearTimeout(this.#staleTimeoutId);
|
|
213
|
-
this.#staleTimeoutId = void 0;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
#clearRefetchInterval() {
|
|
217
|
-
if (this.#refetchIntervalId) {
|
|
218
|
-
clearInterval(this.#refetchIntervalId);
|
|
219
|
-
this.#refetchIntervalId = void 0;
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
createResult(query, options) {
|
|
223
|
-
const prevQuery = this.#currentQuery;
|
|
224
|
-
const prevOptions = this.options;
|
|
225
|
-
const prevResult = this.#currentResult;
|
|
226
|
-
const prevResultState = this.#currentResultState;
|
|
227
|
-
const prevResultOptions = this.#currentResultOptions;
|
|
228
|
-
const queryChange = query !== prevQuery;
|
|
229
|
-
const queryInitialState = queryChange ? query.state : this.#currentQueryInitialState;
|
|
230
|
-
const { state } = query;
|
|
231
|
-
let newState = { ...state };
|
|
232
|
-
let isPlaceholderData = false;
|
|
233
|
-
let data;
|
|
234
|
-
if (options._optimisticResults) {
|
|
235
|
-
const mounted = this.hasListeners();
|
|
236
|
-
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
237
|
-
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
238
|
-
if (fetchOnMount || fetchOptionally) {
|
|
239
|
-
newState = {
|
|
240
|
-
...newState,
|
|
241
|
-
...fetchState(state.data, query.options)
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
if (options._optimisticResults === "isRestoring") {
|
|
245
|
-
newState.fetchStatus = "idle";
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
let { error, errorUpdatedAt, status } = newState;
|
|
249
|
-
data = newState.data;
|
|
250
|
-
let skipSelect = false;
|
|
251
|
-
if (options.placeholderData !== void 0 && data === void 0 && status === "pending") {
|
|
252
|
-
let placeholderData;
|
|
253
|
-
if (prevResult?.isPlaceholderData && options.placeholderData === prevResultOptions?.placeholderData) {
|
|
254
|
-
placeholderData = prevResult.data;
|
|
255
|
-
skipSelect = true;
|
|
256
|
-
} else {
|
|
257
|
-
placeholderData = typeof options.placeholderData === "function" ? options.placeholderData(
|
|
258
|
-
this.#lastQueryWithDefinedData?.state.data,
|
|
259
|
-
this.#lastQueryWithDefinedData
|
|
260
|
-
) : options.placeholderData;
|
|
261
|
-
}
|
|
262
|
-
if (placeholderData !== void 0) {
|
|
263
|
-
status = "success";
|
|
264
|
-
data = replaceData(
|
|
265
|
-
prevResult?.data,
|
|
266
|
-
placeholderData,
|
|
267
|
-
options
|
|
268
|
-
);
|
|
269
|
-
isPlaceholderData = true;
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
if (options.select && data !== void 0 && !skipSelect) {
|
|
273
|
-
if (prevResult && data === prevResultState?.data && options.select === this.#selectFn) {
|
|
274
|
-
data = this.#selectResult;
|
|
275
|
-
} else {
|
|
276
|
-
try {
|
|
277
|
-
this.#selectFn = options.select;
|
|
278
|
-
data = options.select(data);
|
|
279
|
-
data = replaceData(prevResult?.data, data, options);
|
|
280
|
-
this.#selectResult = data;
|
|
281
|
-
this.#selectError = null;
|
|
282
|
-
} catch (selectError) {
|
|
283
|
-
this.#selectError = selectError;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
if (this.#selectError) {
|
|
288
|
-
error = this.#selectError;
|
|
289
|
-
data = this.#selectResult;
|
|
290
|
-
errorUpdatedAt = Date.now();
|
|
291
|
-
status = "error";
|
|
292
|
-
}
|
|
293
|
-
const isFetching = newState.fetchStatus === "fetching";
|
|
294
|
-
const isPending = status === "pending";
|
|
295
|
-
const isError = status === "error";
|
|
296
|
-
const isLoading = isPending && isFetching;
|
|
297
|
-
const hasData = data !== void 0;
|
|
298
|
-
const result = {
|
|
299
|
-
status,
|
|
300
|
-
fetchStatus: newState.fetchStatus,
|
|
301
|
-
isPending,
|
|
302
|
-
isSuccess: status === "success",
|
|
303
|
-
isError,
|
|
304
|
-
isInitialLoading: isLoading,
|
|
305
|
-
isLoading,
|
|
306
|
-
data,
|
|
307
|
-
dataUpdatedAt: newState.dataUpdatedAt,
|
|
308
|
-
error,
|
|
309
|
-
errorUpdatedAt,
|
|
310
|
-
failureCount: newState.fetchFailureCount,
|
|
311
|
-
failureReason: newState.fetchFailureReason,
|
|
312
|
-
errorUpdateCount: newState.errorUpdateCount,
|
|
313
|
-
isFetched: newState.dataUpdateCount > 0 || newState.errorUpdateCount > 0,
|
|
314
|
-
isFetchedAfterMount: newState.dataUpdateCount > queryInitialState.dataUpdateCount || newState.errorUpdateCount > queryInitialState.errorUpdateCount,
|
|
315
|
-
isFetching,
|
|
316
|
-
isRefetching: isFetching && !isPending,
|
|
317
|
-
isLoadingError: isError && !hasData,
|
|
318
|
-
isPaused: newState.fetchStatus === "paused",
|
|
319
|
-
isPlaceholderData,
|
|
320
|
-
isRefetchError: isError && hasData,
|
|
321
|
-
isStale: isStale(query, options),
|
|
322
|
-
refetch: this.refetch,
|
|
323
|
-
promise: this.#currentThenable
|
|
324
|
-
};
|
|
325
|
-
const nextResult = result;
|
|
326
|
-
if (this.options.experimental_prefetchInRender) {
|
|
327
|
-
const finalizeThenableIfPossible = (thenable) => {
|
|
328
|
-
if (nextResult.status === "error") {
|
|
329
|
-
thenable.reject(nextResult.error);
|
|
330
|
-
} else if (nextResult.data !== void 0) {
|
|
331
|
-
thenable.resolve(nextResult.data);
|
|
332
|
-
}
|
|
333
|
-
};
|
|
334
|
-
const recreateThenable = () => {
|
|
335
|
-
const pending = this.#currentThenable = nextResult.promise = pendingThenable();
|
|
336
|
-
finalizeThenableIfPossible(pending);
|
|
337
|
-
};
|
|
338
|
-
const prevThenable = this.#currentThenable;
|
|
339
|
-
switch (prevThenable.status) {
|
|
340
|
-
case "pending":
|
|
341
|
-
if (query.queryHash === prevQuery.queryHash) {
|
|
342
|
-
finalizeThenableIfPossible(prevThenable);
|
|
343
|
-
}
|
|
344
|
-
break;
|
|
345
|
-
case "fulfilled":
|
|
346
|
-
if (nextResult.status === "error" || nextResult.data !== prevThenable.value) {
|
|
347
|
-
recreateThenable();
|
|
348
|
-
}
|
|
349
|
-
break;
|
|
350
|
-
case "rejected":
|
|
351
|
-
if (nextResult.status !== "error" || nextResult.error !== prevThenable.reason) {
|
|
352
|
-
recreateThenable();
|
|
353
|
-
}
|
|
354
|
-
break;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
|
-
return nextResult;
|
|
358
|
-
}
|
|
359
|
-
updateResult() {
|
|
360
|
-
const prevResult = this.#currentResult;
|
|
361
|
-
const nextResult = this.createResult(this.#currentQuery, this.options);
|
|
362
|
-
this.#currentResultState = this.#currentQuery.state;
|
|
363
|
-
this.#currentResultOptions = this.options;
|
|
364
|
-
if (this.#currentResultState.data !== void 0) {
|
|
365
|
-
this.#lastQueryWithDefinedData = this.#currentQuery;
|
|
366
|
-
}
|
|
367
|
-
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
this.#currentResult = nextResult;
|
|
371
|
-
const shouldNotifyListeners = () => {
|
|
372
|
-
if (!prevResult) {
|
|
373
|
-
return true;
|
|
374
|
-
}
|
|
375
|
-
const { notifyOnChangeProps } = this.options;
|
|
376
|
-
const notifyOnChangePropsValue = typeof notifyOnChangeProps === "function" ? notifyOnChangeProps() : notifyOnChangeProps;
|
|
377
|
-
if (notifyOnChangePropsValue === "all" || !notifyOnChangePropsValue && !this.#trackedProps.size) {
|
|
378
|
-
return true;
|
|
379
|
-
}
|
|
380
|
-
const includedProps = new Set(
|
|
381
|
-
notifyOnChangePropsValue ?? this.#trackedProps
|
|
382
|
-
);
|
|
383
|
-
if (this.options.throwOnError) {
|
|
384
|
-
includedProps.add("error");
|
|
385
|
-
}
|
|
386
|
-
return Object.keys(this.#currentResult).some((key) => {
|
|
387
|
-
const typedKey = key;
|
|
388
|
-
const changed = this.#currentResult[typedKey] !== prevResult[typedKey];
|
|
389
|
-
return changed && includedProps.has(typedKey);
|
|
390
|
-
});
|
|
391
|
-
};
|
|
392
|
-
this.#notify({ listeners: shouldNotifyListeners() });
|
|
393
|
-
}
|
|
394
|
-
#updateQuery() {
|
|
395
|
-
const query = this.#client.getQueryCache().build(this.#client, this.options);
|
|
396
|
-
if (query === this.#currentQuery) {
|
|
397
|
-
return;
|
|
398
|
-
}
|
|
399
|
-
const prevQuery = this.#currentQuery;
|
|
400
|
-
this.#currentQuery = query;
|
|
401
|
-
this.#currentQueryInitialState = query.state;
|
|
402
|
-
if (this.hasListeners()) {
|
|
403
|
-
prevQuery?.removeObserver(this);
|
|
404
|
-
query.addObserver(this);
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
onQueryUpdate() {
|
|
408
|
-
this.updateResult();
|
|
409
|
-
if (this.hasListeners()) {
|
|
410
|
-
this.#updateTimers();
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
#notify(notifyOptions) {
|
|
414
|
-
notifyManager.batch(() => {
|
|
415
|
-
if (notifyOptions.listeners) {
|
|
416
|
-
this.listeners.forEach((listener) => {
|
|
417
|
-
listener(this.#currentResult);
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
this.#client.getQueryCache().notify({
|
|
421
|
-
query: this.#currentQuery,
|
|
422
|
-
type: "observerResultsUpdated"
|
|
423
|
-
});
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
};
|
|
427
|
-
function shouldLoadOnMount(query, options) {
|
|
428
|
-
return resolveEnabled(options.enabled, query) !== false && query.state.data === void 0 && !(query.state.status === "error" && options.retryOnMount === false);
|
|
429
|
-
}
|
|
430
|
-
function shouldFetchOnMount(query, options) {
|
|
431
|
-
return shouldLoadOnMount(query, options) || query.state.data !== void 0 && shouldFetchOn(query, options, options.refetchOnMount);
|
|
432
|
-
}
|
|
433
|
-
function shouldFetchOn(query, options, field) {
|
|
434
|
-
if (resolveEnabled(options.enabled, query) !== false) {
|
|
435
|
-
const value = typeof field === "function" ? field(query) : field;
|
|
436
|
-
return value === "always" || value !== false && isStale(query, options);
|
|
437
|
-
}
|
|
438
|
-
return false;
|
|
439
|
-
}
|
|
440
|
-
function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
|
|
441
|
-
return (query !== prevQuery || resolveEnabled(prevOptions.enabled, query) === false) && (!options.suspense || query.state.status !== "error") && isStale(query, options);
|
|
442
|
-
}
|
|
443
|
-
function isStale(query, options) {
|
|
444
|
-
return resolveEnabled(options.enabled, query) !== false && query.isStaleByTime(resolveStaleTime(options.staleTime, query));
|
|
445
|
-
}
|
|
446
|
-
function shouldAssignObserverCurrentProperties(observer, optimisticResult) {
|
|
447
|
-
if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
|
|
448
|
-
return true;
|
|
449
|
-
}
|
|
450
|
-
return false;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
export { QueryObserver };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
// src/subscribable.ts
|
|
2
|
-
var Subscribable = class {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.listeners = /* @__PURE__ */ new Set();
|
|
5
|
-
this.subscribe = this.subscribe.bind(this);
|
|
6
|
-
}
|
|
7
|
-
subscribe(listener) {
|
|
8
|
-
this.listeners.add(listener);
|
|
9
|
-
this.onSubscribe();
|
|
10
|
-
return () => {
|
|
11
|
-
this.listeners.delete(listener);
|
|
12
|
-
this.onUnsubscribe();
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
hasListeners() {
|
|
16
|
-
return this.listeners.size > 0;
|
|
17
|
-
}
|
|
18
|
-
onSubscribe() {
|
|
19
|
-
}
|
|
20
|
-
onUnsubscribe() {
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export { Subscribable };
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
// src/thenable.ts
|
|
2
|
-
function pendingThenable() {
|
|
3
|
-
let resolve;
|
|
4
|
-
let reject;
|
|
5
|
-
const thenable = new Promise((_resolve, _reject) => {
|
|
6
|
-
resolve = _resolve;
|
|
7
|
-
reject = _reject;
|
|
8
|
-
});
|
|
9
|
-
thenable.status = "pending";
|
|
10
|
-
thenable.catch(() => {
|
|
11
|
-
});
|
|
12
|
-
function finalize(data) {
|
|
13
|
-
Object.assign(thenable, data);
|
|
14
|
-
delete thenable.resolve;
|
|
15
|
-
delete thenable.reject;
|
|
16
|
-
}
|
|
17
|
-
thenable.resolve = (value) => {
|
|
18
|
-
finalize({
|
|
19
|
-
status: "fulfilled",
|
|
20
|
-
value
|
|
21
|
-
});
|
|
22
|
-
resolve(value);
|
|
23
|
-
};
|
|
24
|
-
thenable.reject = (reason) => {
|
|
25
|
-
finalize({
|
|
26
|
-
status: "rejected",
|
|
27
|
-
reason
|
|
28
|
-
});
|
|
29
|
-
reject(reason);
|
|
30
|
-
};
|
|
31
|
-
return thenable;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export { pendingThenable };
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// src/utils.ts
|
|
2
|
-
var isServer = typeof window === "undefined" || "Deno" in globalThis;
|
|
3
|
-
function noop() {
|
|
4
|
-
}
|
|
5
|
-
function isValidTimeout(value) {
|
|
6
|
-
return typeof value === "number" && value >= 0 && value !== Infinity;
|
|
7
|
-
}
|
|
8
|
-
function timeUntilStale(updatedAt, staleTime) {
|
|
9
|
-
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
|
|
10
|
-
}
|
|
11
|
-
function resolveStaleTime(staleTime, query) {
|
|
12
|
-
return typeof staleTime === "function" ? staleTime(query) : staleTime;
|
|
13
|
-
}
|
|
14
|
-
function resolveEnabled(enabled, query) {
|
|
15
|
-
return typeof enabled === "function" ? enabled(query) : enabled;
|
|
16
|
-
}
|
|
17
|
-
function replaceEqualDeep(a, b) {
|
|
18
|
-
if (a === b) {
|
|
19
|
-
return a;
|
|
20
|
-
}
|
|
21
|
-
const array = isPlainArray(a) && isPlainArray(b);
|
|
22
|
-
if (array || isPlainObject(a) && isPlainObject(b)) {
|
|
23
|
-
const aItems = array ? a : Object.keys(a);
|
|
24
|
-
const aSize = aItems.length;
|
|
25
|
-
const bItems = array ? b : Object.keys(b);
|
|
26
|
-
const bSize = bItems.length;
|
|
27
|
-
const copy = array ? [] : {};
|
|
28
|
-
let equalItems = 0;
|
|
29
|
-
for (let i = 0; i < bSize; i++) {
|
|
30
|
-
const key = array ? i : bItems[i];
|
|
31
|
-
if ((!array && aItems.includes(key) || array) && a[key] === void 0 && b[key] === void 0) {
|
|
32
|
-
copy[key] = void 0;
|
|
33
|
-
equalItems++;
|
|
34
|
-
} else {
|
|
35
|
-
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
36
|
-
if (copy[key] === a[key] && a[key] !== void 0) {
|
|
37
|
-
equalItems++;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
42
|
-
}
|
|
43
|
-
return b;
|
|
44
|
-
}
|
|
45
|
-
function shallowEqualObjects(a, b) {
|
|
46
|
-
if (!b || Object.keys(a).length !== Object.keys(b).length) {
|
|
47
|
-
return false;
|
|
48
|
-
}
|
|
49
|
-
for (const key in a) {
|
|
50
|
-
if (a[key] !== b[key]) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
function isPlainArray(value) {
|
|
57
|
-
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
58
|
-
}
|
|
59
|
-
function isPlainObject(o) {
|
|
60
|
-
if (!hasObjectPrototype(o)) {
|
|
61
|
-
return false;
|
|
62
|
-
}
|
|
63
|
-
const ctor = o.constructor;
|
|
64
|
-
if (ctor === void 0) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
const prot = ctor.prototype;
|
|
68
|
-
if (!hasObjectPrototype(prot)) {
|
|
69
|
-
return false;
|
|
70
|
-
}
|
|
71
|
-
if (!prot.hasOwnProperty("isPrototypeOf")) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
if (Object.getPrototypeOf(o) !== Object.prototype) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
return true;
|
|
78
|
-
}
|
|
79
|
-
function hasObjectPrototype(o) {
|
|
80
|
-
return Object.prototype.toString.call(o) === "[object Object]";
|
|
81
|
-
}
|
|
82
|
-
function replaceData(prevData, data, options) {
|
|
83
|
-
if (typeof options.structuralSharing === "function") {
|
|
84
|
-
return options.structuralSharing(prevData, data);
|
|
85
|
-
} else if (options.structuralSharing !== false) {
|
|
86
|
-
if (process.env.NODE_ENV !== "production") {
|
|
87
|
-
try {
|
|
88
|
-
return replaceEqualDeep(prevData, data);
|
|
89
|
-
} catch (error) {
|
|
90
|
-
console.error(
|
|
91
|
-
`Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`
|
|
92
|
-
);
|
|
93
|
-
throw error;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return replaceEqualDeep(prevData, data);
|
|
97
|
-
}
|
|
98
|
-
return data;
|
|
99
|
-
}
|
|
100
|
-
function addToEnd(items, item, max = 0) {
|
|
101
|
-
const newItems = [...items, item];
|
|
102
|
-
return max && newItems.length > max ? newItems.slice(1) : newItems;
|
|
103
|
-
}
|
|
104
|
-
function addToStart(items, item, max = 0) {
|
|
105
|
-
const newItems = [item, ...items];
|
|
106
|
-
return max && newItems.length > max ? newItems.slice(0, -1) : newItems;
|
|
107
|
-
}
|
|
108
|
-
var skipToken = Symbol();
|
|
109
|
-
function ensureQueryFn(options, fetchOptions) {
|
|
110
|
-
if (process.env.NODE_ENV !== "production") {
|
|
111
|
-
if (options.queryFn === skipToken) {
|
|
112
|
-
console.error(
|
|
113
|
-
`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${options.queryHash}'`
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
if (!options.queryFn && fetchOptions?.initialPromise) {
|
|
118
|
-
return () => fetchOptions.initialPromise;
|
|
119
|
-
}
|
|
120
|
-
if (!options.queryFn || options.queryFn === skipToken) {
|
|
121
|
-
return () => Promise.reject(new Error(`Missing queryFn: '${options.queryHash}'`));
|
|
122
|
-
}
|
|
123
|
-
return options.queryFn;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export { addToEnd, addToStart, ensureQueryFn, isPlainArray, isPlainObject, isServer, isValidTimeout, noop, replaceData, replaceEqualDeep, resolveEnabled, resolveStaleTime, shallowEqualObjects, skipToken, timeUntilStale };
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
var QueryClientContext = React.createContext(
|
|
5
|
-
void 0
|
|
6
|
-
);
|
|
7
|
-
var useQueryClient = (queryClient) => {
|
|
8
|
-
const client = React.useContext(QueryClientContext);
|
|
9
|
-
if (queryClient) {
|
|
10
|
-
return queryClient;
|
|
11
|
-
}
|
|
12
|
-
if (!client) {
|
|
13
|
-
throw new Error("No QueryClient set, use QueryClientProvider to set one");
|
|
14
|
-
}
|
|
15
|
-
return client;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { QueryClientContext, useQueryClient };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
function createValue() {
|
|
5
|
-
let isReset = false;
|
|
6
|
-
return {
|
|
7
|
-
clearReset: () => {
|
|
8
|
-
isReset = false;
|
|
9
|
-
},
|
|
10
|
-
reset: () => {
|
|
11
|
-
isReset = true;
|
|
12
|
-
},
|
|
13
|
-
isReset: () => {
|
|
14
|
-
return isReset;
|
|
15
|
-
}
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
var QueryErrorResetBoundaryContext = React.createContext(createValue());
|
|
19
|
-
var useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext);
|
|
20
|
-
|
|
21
|
-
export { useQueryErrorResetBoundary };
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { shouldThrowError } from './utils.js';
|
|
3
|
-
|
|
4
|
-
var ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
5
|
-
if (options.suspense || options.throwOnError || options.experimental_prefetchInRender) {
|
|
6
|
-
if (!errorResetBoundary.isReset()) {
|
|
7
|
-
options.retryOnMount = false;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var useClearResetErrorBoundary = (errorResetBoundary) => {
|
|
12
|
-
React.useEffect(() => {
|
|
13
|
-
errorResetBoundary.clearReset();
|
|
14
|
-
}, [errorResetBoundary]);
|
|
15
|
-
};
|
|
16
|
-
var getHasError = ({
|
|
17
|
-
result,
|
|
18
|
-
errorResetBoundary,
|
|
19
|
-
throwOnError,
|
|
20
|
-
query,
|
|
21
|
-
suspense
|
|
22
|
-
}) => {
|
|
23
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && query && (suspense && result.data === void 0 || shouldThrowError(throwOnError, [result.error, query]));
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export { ensurePreventErrorBoundaryRetry, getHasError, useClearResetErrorBoundary };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/suspense.ts
|
|
2
|
-
var ensureSuspenseTimers = (defaultedOptions) => {
|
|
3
|
-
const originalStaleTime = defaultedOptions.staleTime;
|
|
4
|
-
if (defaultedOptions.suspense) {
|
|
5
|
-
defaultedOptions.staleTime = typeof originalStaleTime === "function" ? (...args) => Math.max(originalStaleTime(...args), 1e3) : Math.max(originalStaleTime ?? 1e3, 1e3);
|
|
6
|
-
if (typeof defaultedOptions.gcTime === "number") {
|
|
7
|
-
defaultedOptions.gcTime = Math.max(defaultedOptions.gcTime, 1e3);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
var willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
|
|
12
|
-
var shouldSuspend = (defaultedOptions, result) => defaultedOptions?.suspense && result.isPending;
|
|
13
|
-
var fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).catch(() => {
|
|
14
|
-
errorResetBoundary.clearReset();
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
export { ensureSuspenseTimers, fetchOptimistic, shouldSuspend, willFetch };
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { notifyManager } from '../../../query-core/build/modern/notifyManager.js';
|
|
3
|
-
import { isServer } from '../../../query-core/build/modern/utils.js';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.js';
|
|
5
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.js';
|
|
6
|
-
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.js';
|
|
7
|
-
import { useIsRestoring } from './IsRestoringProvider.js';
|
|
8
|
-
import { ensureSuspenseTimers, shouldSuspend, fetchOptimistic, willFetch } from './suspense.js';
|
|
9
|
-
import { noop } from './utils.js';
|
|
10
|
-
|
|
11
|
-
function useBaseQuery(options, Observer, queryClient) {
|
|
12
|
-
if (process.env.NODE_ENV !== "production") {
|
|
13
|
-
if (typeof options !== "object" || Array.isArray(options)) {
|
|
14
|
-
throw new Error(
|
|
15
|
-
'Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object'
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const client = useQueryClient(queryClient);
|
|
20
|
-
const isRestoring = useIsRestoring();
|
|
21
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
22
|
-
const defaultedOptions = client.defaultQueryOptions(options);
|
|
23
|
-
client.getDefaultOptions().queries?._experimental_beforeQuery?.(
|
|
24
|
-
defaultedOptions
|
|
25
|
-
);
|
|
26
|
-
if (process.env.NODE_ENV !== "production") {
|
|
27
|
-
if (!defaultedOptions.queryFn) {
|
|
28
|
-
console.error(
|
|
29
|
-
`[${defaultedOptions.queryHash}]: No queryFn was passed as an option, and no default queryFn was found. The queryFn parameter is only optional when using a default queryFn. More info here: https://tanstack.com/query/latest/docs/framework/react/guides/default-query-function`
|
|
30
|
-
);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
defaultedOptions._optimisticResults = isRestoring ? "isRestoring" : "optimistic";
|
|
34
|
-
ensureSuspenseTimers(defaultedOptions);
|
|
35
|
-
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
|
|
36
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
37
|
-
const isNewCacheEntry = !client.getQueryCache().get(defaultedOptions.queryHash);
|
|
38
|
-
const [observer] = React.useState(
|
|
39
|
-
() => new Observer(
|
|
40
|
-
client,
|
|
41
|
-
defaultedOptions
|
|
42
|
-
)
|
|
43
|
-
);
|
|
44
|
-
const result = observer.getOptimisticResult(defaultedOptions);
|
|
45
|
-
const shouldSubscribe = !isRestoring && options.subscribed !== false;
|
|
46
|
-
React.useSyncExternalStore(
|
|
47
|
-
React.useCallback(
|
|
48
|
-
(onStoreChange) => {
|
|
49
|
-
const unsubscribe = shouldSubscribe ? observer.subscribe(notifyManager.batchCalls(onStoreChange)) : noop;
|
|
50
|
-
observer.updateResult();
|
|
51
|
-
return unsubscribe;
|
|
52
|
-
},
|
|
53
|
-
[observer, shouldSubscribe]
|
|
54
|
-
),
|
|
55
|
-
() => observer.getCurrentResult(),
|
|
56
|
-
() => observer.getCurrentResult()
|
|
57
|
-
);
|
|
58
|
-
React.useEffect(() => {
|
|
59
|
-
observer.setOptions(defaultedOptions);
|
|
60
|
-
}, [defaultedOptions, observer]);
|
|
61
|
-
if (shouldSuspend(defaultedOptions, result)) {
|
|
62
|
-
throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
|
|
63
|
-
}
|
|
64
|
-
if (getHasError({
|
|
65
|
-
result,
|
|
66
|
-
errorResetBoundary,
|
|
67
|
-
throwOnError: defaultedOptions.throwOnError,
|
|
68
|
-
query: client.getQueryCache().get(defaultedOptions.queryHash),
|
|
69
|
-
suspense: defaultedOptions.suspense
|
|
70
|
-
})) {
|
|
71
|
-
throw result.error;
|
|
72
|
-
}
|
|
73
|
-
client.getDefaultOptions().queries?._experimental_afterQuery?.(
|
|
74
|
-
defaultedOptions,
|
|
75
|
-
result
|
|
76
|
-
);
|
|
77
|
-
if (defaultedOptions.experimental_prefetchInRender && !isServer && willFetch(result, isRestoring)) {
|
|
78
|
-
const promise = isNewCacheEntry ? (
|
|
79
|
-
// Fetch immediately on render in order to ensure `.promise` is resolved even if the component is unmounted
|
|
80
|
-
fetchOptimistic(defaultedOptions, observer, errorResetBoundary)
|
|
81
|
-
) : (
|
|
82
|
-
// subscribe to the "cache promise" so that we can finalize the currentThenable once data comes in
|
|
83
|
-
client.getQueryCache().get(defaultedOptions.queryHash)?.promise
|
|
84
|
-
);
|
|
85
|
-
promise?.catch(noop).finally(() => {
|
|
86
|
-
observer.updateResult();
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export { useBaseQuery };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from '../../../query-core/build/modern/infiniteQueryObserver.js';
|
|
2
|
-
import { useBaseQuery } from './useBaseQuery.js';
|
|
3
|
-
|
|
4
|
-
function useInfiniteQuery(options, queryClient) {
|
|
5
|
-
return useBaseQuery(
|
|
6
|
-
options,
|
|
7
|
-
InfiniteQueryObserver,
|
|
8
|
-
queryClient
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { useInfiniteQuery };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { QueryObserver } from '../../../query-core/build/modern/queryObserver.js';
|
|
2
|
-
import { useBaseQuery } from './useBaseQuery.js';
|
|
3
|
-
|
|
4
|
-
function useQuery(options, queryClient) {
|
|
5
|
-
return useBaseQuery(options, QueryObserver, queryClient);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export { useQuery };
|