@depup/reduxjs__toolkit 2.12.0-depup.28
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/LICENSE +21 -0
- package/README.md +33 -0
- package/changes.json +18 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/redux-toolkit.development.cjs +2406 -0
- package/dist/cjs/redux-toolkit.development.cjs.map +1 -0
- package/dist/cjs/redux-toolkit.production.min.cjs +3 -0
- package/dist/cjs/redux-toolkit.production.min.cjs.map +1 -0
- package/dist/index.d.mts +2665 -0
- package/dist/index.d.ts +2665 -0
- package/dist/query/cjs/index.js +6 -0
- package/dist/query/cjs/rtk-query.development.cjs +3092 -0
- package/dist/query/cjs/rtk-query.development.cjs.map +1 -0
- package/dist/query/cjs/rtk-query.production.min.cjs +2 -0
- package/dist/query/cjs/rtk-query.production.min.cjs.map +1 -0
- package/dist/query/index.d.mts +3066 -0
- package/dist/query/index.d.ts +3066 -0
- package/dist/query/react/cjs/index.js +6 -0
- package/dist/query/react/cjs/rtk-query-react.development.cjs +748 -0
- package/dist/query/react/cjs/rtk-query-react.development.cjs.map +1 -0
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs +2 -0
- package/dist/query/react/cjs/rtk-query-react.production.min.cjs.map +1 -0
- package/dist/query/react/index.d.mts +1009 -0
- package/dist/query/react/index.d.ts +1009 -0
- package/dist/query/react/rtk-query-react.browser.mjs +2 -0
- package/dist/query/react/rtk-query-react.browser.mjs.map +1 -0
- package/dist/query/react/rtk-query-react.legacy-esm.js +740 -0
- package/dist/query/react/rtk-query-react.legacy-esm.js.map +1 -0
- package/dist/query/react/rtk-query-react.modern.mjs +705 -0
- package/dist/query/react/rtk-query-react.modern.mjs.map +1 -0
- package/dist/query/rtk-query.browser.mjs +2 -0
- package/dist/query/rtk-query.browser.mjs.map +1 -0
- package/dist/query/rtk-query.legacy-esm.js +3117 -0
- package/dist/query/rtk-query.legacy-esm.js.map +1 -0
- package/dist/query/rtk-query.modern.mjs +3052 -0
- package/dist/query/rtk-query.modern.mjs.map +1 -0
- package/dist/react/cjs/index.js +6 -0
- package/dist/react/cjs/redux-toolkit-react.development.cjs +55 -0
- package/dist/react/cjs/redux-toolkit-react.development.cjs.map +1 -0
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs +2 -0
- package/dist/react/cjs/redux-toolkit-react.production.min.cjs.map +1 -0
- package/dist/react/index.d.mts +22 -0
- package/dist/react/index.d.ts +22 -0
- package/dist/react/redux-toolkit-react.browser.mjs +2 -0
- package/dist/react/redux-toolkit-react.browser.mjs.map +1 -0
- package/dist/react/redux-toolkit-react.legacy-esm.js +47 -0
- package/dist/react/redux-toolkit-react.legacy-esm.js.map +1 -0
- package/dist/react/redux-toolkit-react.modern.mjs +28 -0
- package/dist/react/redux-toolkit-react.modern.mjs.map +1 -0
- package/dist/redux-toolkit.browser.mjs +3 -0
- package/dist/redux-toolkit.browser.mjs.map +1 -0
- package/dist/redux-toolkit.legacy-esm.js +2351 -0
- package/dist/redux-toolkit.legacy-esm.js.map +1 -0
- package/dist/redux-toolkit.modern.mjs +2330 -0
- package/dist/redux-toolkit.modern.mjs.map +1 -0
- package/dist/uncheckedindexed.ts +16 -0
- package/package.json +310 -0
- package/query/package.json +13 -0
- package/query/react/package.json +13 -0
- package/react/package.json +13 -0
- package/skills/build-modern-redux-apps/modern-redux/SKILL.md +304 -0
- package/skills/build-modern-redux-apps/modern-redux/references/store-lifetime.md +53 -0
- package/skills/build-modern-redux-apps/redux-dataflow/SKILL.md +264 -0
- package/skills/evolve-and-diagnose-redux-apps/debug-redux-toolkit-apps/SKILL.md +269 -0
- package/skills/evolve-and-diagnose-redux-apps/migrate-to-modern-redux/SKILL.md +226 -0
- package/skills/manage-server-data/adopt-rtk-query/SKILL.md +385 -0
- package/skills/manage-server-data/adopt-rtk-query/references/endpoint-lifecycle.md +36 -0
- package/skills/model-redux-state/build-slices-and-selectors/SKILL.md +364 -0
- package/skills/model-redux-state/build-slices-and-selectors/references/slice-patterns.md +59 -0
- package/skills/model-redux-state/design-state-ownership/SKILL.md +322 -0
- package/skills/model-redux-state/design-state-ownership/references/state-ownership.md +28 -0
- package/skills/orchestrate-side-effects/handle-side-effects/SKILL.md +271 -0
- package/skills/orchestrate-side-effects/handle-side-effects/references/listener-workflows.md +34 -0
- package/src/actionCreatorInvariantMiddleware.ts +34 -0
- package/src/autoBatchEnhancer.ts +146 -0
- package/src/combineSlices.ts +487 -0
- package/src/configureStore.ts +248 -0
- package/src/createAction.ts +324 -0
- package/src/createAsyncThunk.ts +791 -0
- package/src/createDraftSafeSelector.ts +30 -0
- package/src/createReducer.ts +217 -0
- package/src/createSlice.ts +1079 -0
- package/src/devtoolsExtension.ts +241 -0
- package/src/dynamicMiddleware/index.ts +93 -0
- package/src/dynamicMiddleware/react/index.ts +101 -0
- package/src/dynamicMiddleware/types.ts +82 -0
- package/src/entities/create_adapter.ts +47 -0
- package/src/entities/entity_state.ts +38 -0
- package/src/entities/index.ts +8 -0
- package/src/entities/models.ts +198 -0
- package/src/entities/sorted_state_adapter.ts +266 -0
- package/src/entities/state_adapter.ts +58 -0
- package/src/entities/state_selectors.ts +73 -0
- package/src/entities/unsorted_state_adapter.ts +204 -0
- package/src/entities/utils.ts +68 -0
- package/src/formatProdErrorMessage.ts +13 -0
- package/src/getDefaultEnhancers.ts +31 -0
- package/src/getDefaultMiddleware.ts +113 -0
- package/src/immerImports.ts +7 -0
- package/src/immutableStateInvariantMiddleware.ts +274 -0
- package/src/index.ts +213 -0
- package/src/listenerMiddleware/exceptions.ts +20 -0
- package/src/listenerMiddleware/index.ts +562 -0
- package/src/listenerMiddleware/task.ts +100 -0
- package/src/listenerMiddleware/types.ts +886 -0
- package/src/listenerMiddleware/utils.ts +30 -0
- package/src/mapBuilders.ts +298 -0
- package/src/matchers.ts +365 -0
- package/src/nanoid.ts +20 -0
- package/src/query/HandledError.ts +6 -0
- package/src/query/apiTypes.ts +120 -0
- package/src/query/baseQueryTypes.ts +101 -0
- package/src/query/core/apiState.ts +377 -0
- package/src/query/core/buildInitiate.ts +596 -0
- package/src/query/core/buildMiddleware/batchActions.ts +207 -0
- package/src/query/core/buildMiddleware/cacheCollection.ts +204 -0
- package/src/query/core/buildMiddleware/cacheLifecycle.ts +379 -0
- package/src/query/core/buildMiddleware/devMiddleware.ts +34 -0
- package/src/query/core/buildMiddleware/index.ts +162 -0
- package/src/query/core/buildMiddleware/invalidationByTags.ts +139 -0
- package/src/query/core/buildMiddleware/polling.ts +187 -0
- package/src/query/core/buildMiddleware/queryLifecycle.ts +508 -0
- package/src/query/core/buildMiddleware/types.ts +173 -0
- package/src/query/core/buildMiddleware/windowEventHandling.ts +64 -0
- package/src/query/core/buildSelectors.ts +413 -0
- package/src/query/core/buildSlice.ts +735 -0
- package/src/query/core/buildThunks.ts +1124 -0
- package/src/query/core/index.ts +58 -0
- package/src/query/core/module.ts +727 -0
- package/src/query/core/rtkImports.ts +24 -0
- package/src/query/core/setupListeners.ts +118 -0
- package/src/query/createApi.ts +506 -0
- package/src/query/defaultSerializeQueryArgs.ts +52 -0
- package/src/query/endpointDefinitions.ts +1717 -0
- package/src/query/fakeBaseQuery.ts +21 -0
- package/src/query/fetchBaseQuery.ts +385 -0
- package/src/query/index.ts +105 -0
- package/src/query/react/ApiProvider.tsx +69 -0
- package/src/query/react/buildHooks.ts +2297 -0
- package/src/query/react/constants.ts +2 -0
- package/src/query/react/index.ts +45 -0
- package/src/query/react/module.ts +275 -0
- package/src/query/react/namedHooks.ts +59 -0
- package/src/query/react/reactImports.ts +10 -0
- package/src/query/react/reactReduxImports.ts +1 -0
- package/src/query/react/rtkqImports.ts +8 -0
- package/src/query/react/useSerializedStableValue.ts +17 -0
- package/src/query/react/useShallowStableValue.ts +13 -0
- package/src/query/retry.ts +233 -0
- package/src/query/standardSchema.ts +35 -0
- package/src/query/tsHelpers.ts +48 -0
- package/src/query/utils/capitalize.ts +3 -0
- package/src/query/utils/copyWithStructuralSharing.ts +27 -0
- package/src/query/utils/countObjectKeys.ts +14 -0
- package/src/query/utils/filterMap.ts +27 -0
- package/src/query/utils/getCurrent.ts +6 -0
- package/src/query/utils/getOrInsert.ts +41 -0
- package/src/query/utils/immerImports.ts +9 -0
- package/src/query/utils/index.ts +11 -0
- package/src/query/utils/isAbsoluteUrl.ts +9 -0
- package/src/query/utils/isDocumentVisible.ts +12 -0
- package/src/query/utils/isNotNullish.ts +7 -0
- package/src/query/utils/isOnline.ts +12 -0
- package/src/query/utils/isValidUrl.ts +9 -0
- package/src/query/utils/joinUrls.ts +26 -0
- package/src/query/utils/signals.ts +33 -0
- package/src/react/index.ts +7 -0
- package/src/reduxImports.ts +8 -0
- package/src/reselectImports.ts +1 -0
- package/src/serializableStateInvariantMiddleware.ts +285 -0
- package/src/tsHelpers.ts +214 -0
- package/src/uncheckedindexed.ts +16 -0
- package/src/utils.ts +125 -0
|
@@ -0,0 +1,3117 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
34
|
+
|
|
35
|
+
// src/query/core/apiState.ts
|
|
36
|
+
var QueryStatus = /* @__PURE__ */ ((QueryStatus7) => {
|
|
37
|
+
QueryStatus7["uninitialized"] = "uninitialized";
|
|
38
|
+
QueryStatus7["pending"] = "pending";
|
|
39
|
+
QueryStatus7["fulfilled"] = "fulfilled";
|
|
40
|
+
QueryStatus7["rejected"] = "rejected";
|
|
41
|
+
return QueryStatus7;
|
|
42
|
+
})(QueryStatus || {});
|
|
43
|
+
var STATUS_UNINITIALIZED = "uninitialized" /* uninitialized */;
|
|
44
|
+
var STATUS_PENDING = "pending" /* pending */;
|
|
45
|
+
var STATUS_FULFILLED = "fulfilled" /* fulfilled */;
|
|
46
|
+
var STATUS_REJECTED = "rejected" /* rejected */;
|
|
47
|
+
function getRequestStatusFlags(status) {
|
|
48
|
+
return {
|
|
49
|
+
status,
|
|
50
|
+
isUninitialized: status === STATUS_UNINITIALIZED,
|
|
51
|
+
isLoading: status === STATUS_PENDING,
|
|
52
|
+
isSuccess: status === STATUS_FULFILLED,
|
|
53
|
+
isError: status === STATUS_REJECTED
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/query/core/rtkImports.ts
|
|
58
|
+
import { createAction, createSlice, createSelector, createAsyncThunk, combineReducers, createNextState, isAnyOf, isAllOf, isAction, isPending, isRejected, isFulfilled, isRejectedWithValue, isAsyncThunkAction, prepareAutoBatched, SHOULD_AUTOBATCH, isPlainObject, nanoid } from "@reduxjs/toolkit";
|
|
59
|
+
|
|
60
|
+
// src/query/utils/copyWithStructuralSharing.ts
|
|
61
|
+
var isPlainObject2 = isPlainObject;
|
|
62
|
+
function copyWithStructuralSharing(oldObj, newObj) {
|
|
63
|
+
if (oldObj === newObj || !(isPlainObject2(oldObj) && isPlainObject2(newObj) || Array.isArray(oldObj) && Array.isArray(newObj))) {
|
|
64
|
+
return newObj;
|
|
65
|
+
}
|
|
66
|
+
const newKeys = Object.keys(newObj);
|
|
67
|
+
const oldKeys = Object.keys(oldObj);
|
|
68
|
+
let isSameObject = newKeys.length === oldKeys.length;
|
|
69
|
+
const mergeObj = Array.isArray(newObj) ? [] : {};
|
|
70
|
+
for (const key of newKeys) {
|
|
71
|
+
mergeObj[key] = copyWithStructuralSharing(oldObj[key], newObj[key]);
|
|
72
|
+
if (isSameObject) isSameObject = oldObj[key] === mergeObj[key];
|
|
73
|
+
}
|
|
74
|
+
return isSameObject ? oldObj : mergeObj;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/query/utils/filterMap.ts
|
|
78
|
+
function filterMap(array, predicate, mapper) {
|
|
79
|
+
return array.reduce((acc, item, i) => {
|
|
80
|
+
if (predicate(item, i)) {
|
|
81
|
+
acc.push(mapper(item, i));
|
|
82
|
+
}
|
|
83
|
+
return acc;
|
|
84
|
+
}, []).flat();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// src/query/utils/isAbsoluteUrl.ts
|
|
88
|
+
function isAbsoluteUrl(url) {
|
|
89
|
+
return new RegExp(`(^|:)//`).test(url);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// src/query/utils/isDocumentVisible.ts
|
|
93
|
+
function isDocumentVisible() {
|
|
94
|
+
if (typeof document === "undefined") {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return document.visibilityState !== "hidden";
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// src/query/utils/isNotNullish.ts
|
|
101
|
+
function isNotNullish(v) {
|
|
102
|
+
return v != null;
|
|
103
|
+
}
|
|
104
|
+
function filterNullishValues(map) {
|
|
105
|
+
var _a;
|
|
106
|
+
return [...(_a = map == null ? void 0 : map.values()) != null ? _a : []].filter(isNotNullish);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// src/query/utils/isOnline.ts
|
|
110
|
+
function isOnline() {
|
|
111
|
+
return typeof navigator === "undefined" ? true : navigator.onLine === void 0 ? true : navigator.onLine;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// src/query/utils/joinUrls.ts
|
|
115
|
+
var withoutTrailingSlash = (url) => url.replace(/\/$/, "");
|
|
116
|
+
var withoutLeadingSlash = (url) => url.replace(/^\//, "");
|
|
117
|
+
function joinUrls(base, url) {
|
|
118
|
+
if (!base) {
|
|
119
|
+
return url;
|
|
120
|
+
}
|
|
121
|
+
if (!url) {
|
|
122
|
+
return base;
|
|
123
|
+
}
|
|
124
|
+
if (isAbsoluteUrl(url)) {
|
|
125
|
+
return url;
|
|
126
|
+
}
|
|
127
|
+
const delimiter = base.endsWith("/") || !url.startsWith("?") ? "/" : "";
|
|
128
|
+
base = withoutTrailingSlash(base);
|
|
129
|
+
url = withoutLeadingSlash(url);
|
|
130
|
+
return `${base}${delimiter}${url}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// src/query/utils/getOrInsert.ts
|
|
134
|
+
function getOrInsertComputed(map, key, compute) {
|
|
135
|
+
if (map.has(key)) return map.get(key);
|
|
136
|
+
return map.set(key, compute(key)).get(key);
|
|
137
|
+
}
|
|
138
|
+
var createNewMap = () => /* @__PURE__ */ new Map();
|
|
139
|
+
|
|
140
|
+
// src/query/utils/signals.ts
|
|
141
|
+
var timeoutSignal = (milliseconds) => {
|
|
142
|
+
const abortController = new AbortController();
|
|
143
|
+
setTimeout(() => {
|
|
144
|
+
const message = "signal timed out";
|
|
145
|
+
const name = "TimeoutError";
|
|
146
|
+
abortController.abort(
|
|
147
|
+
// some environments (React Native, Node) don't have DOMException
|
|
148
|
+
typeof DOMException !== "undefined" ? new DOMException(message, name) : Object.assign(new Error(message), {
|
|
149
|
+
name
|
|
150
|
+
})
|
|
151
|
+
);
|
|
152
|
+
}, milliseconds);
|
|
153
|
+
return abortController.signal;
|
|
154
|
+
};
|
|
155
|
+
var anySignal = (...signals) => {
|
|
156
|
+
for (const signal of signals) if (signal.aborted) return AbortSignal.abort(signal.reason);
|
|
157
|
+
const abortController = new AbortController();
|
|
158
|
+
for (const signal of signals) {
|
|
159
|
+
signal.addEventListener("abort", () => abortController.abort(signal.reason), {
|
|
160
|
+
signal: abortController.signal,
|
|
161
|
+
once: true
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
return abortController.signal;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// src/query/fetchBaseQuery.ts
|
|
168
|
+
var defaultFetchFn = (...args) => fetch(...args);
|
|
169
|
+
var defaultValidateStatus = (response) => response.status >= 200 && response.status <= 299;
|
|
170
|
+
var defaultIsJsonContentType = (headers) => (
|
|
171
|
+
/*applicat*/
|
|
172
|
+
/ion\/(vnd\.api\+)?json/.test(headers.get("content-type") || "")
|
|
173
|
+
);
|
|
174
|
+
function stripUndefined(obj) {
|
|
175
|
+
if (!isPlainObject(obj)) {
|
|
176
|
+
return obj;
|
|
177
|
+
}
|
|
178
|
+
const copy = __spreadValues({}, obj);
|
|
179
|
+
for (const [k, v] of Object.entries(copy)) {
|
|
180
|
+
if (v === void 0) delete copy[k];
|
|
181
|
+
}
|
|
182
|
+
return copy;
|
|
183
|
+
}
|
|
184
|
+
var isJsonifiable = (body) => typeof body === "object" && (isPlainObject(body) || Array.isArray(body) || typeof body.toJSON === "function");
|
|
185
|
+
function fetchBaseQuery(_a = {}) {
|
|
186
|
+
var _b = _a, {
|
|
187
|
+
baseUrl,
|
|
188
|
+
prepareHeaders = (x) => x,
|
|
189
|
+
fetchFn = defaultFetchFn,
|
|
190
|
+
paramsSerializer,
|
|
191
|
+
isJsonContentType = defaultIsJsonContentType,
|
|
192
|
+
jsonContentType = "application/json",
|
|
193
|
+
jsonReplacer,
|
|
194
|
+
timeout: defaultTimeout,
|
|
195
|
+
responseHandler: globalResponseHandler,
|
|
196
|
+
validateStatus: globalValidateStatus
|
|
197
|
+
} = _b, baseFetchOptions = __objRest(_b, [
|
|
198
|
+
"baseUrl",
|
|
199
|
+
"prepareHeaders",
|
|
200
|
+
"fetchFn",
|
|
201
|
+
"paramsSerializer",
|
|
202
|
+
"isJsonContentType",
|
|
203
|
+
"jsonContentType",
|
|
204
|
+
"jsonReplacer",
|
|
205
|
+
"timeout",
|
|
206
|
+
"responseHandler",
|
|
207
|
+
"validateStatus"
|
|
208
|
+
]);
|
|
209
|
+
if (typeof fetch === "undefined" && fetchFn === defaultFetchFn) {
|
|
210
|
+
console.warn("Warning: `fetch` is not available. Please supply a custom `fetchFn` property to use `fetchBaseQuery` on SSR environments.");
|
|
211
|
+
}
|
|
212
|
+
return async (arg, api, extraOptions) => {
|
|
213
|
+
const {
|
|
214
|
+
getState,
|
|
215
|
+
extra,
|
|
216
|
+
endpoint,
|
|
217
|
+
forced,
|
|
218
|
+
type
|
|
219
|
+
} = api;
|
|
220
|
+
let meta;
|
|
221
|
+
let _a2 = typeof arg == "string" ? {
|
|
222
|
+
url: arg
|
|
223
|
+
} : arg, {
|
|
224
|
+
url,
|
|
225
|
+
headers = new Headers(baseFetchOptions.headers),
|
|
226
|
+
params = void 0,
|
|
227
|
+
responseHandler = globalResponseHandler != null ? globalResponseHandler : "json",
|
|
228
|
+
validateStatus = globalValidateStatus != null ? globalValidateStatus : defaultValidateStatus,
|
|
229
|
+
timeout = defaultTimeout
|
|
230
|
+
} = _a2, rest = __objRest(_a2, [
|
|
231
|
+
"url",
|
|
232
|
+
"headers",
|
|
233
|
+
"params",
|
|
234
|
+
"responseHandler",
|
|
235
|
+
"validateStatus",
|
|
236
|
+
"timeout"
|
|
237
|
+
]);
|
|
238
|
+
let config = __spreadValues(__spreadProps(__spreadValues({}, baseFetchOptions), {
|
|
239
|
+
signal: timeout ? anySignal(api.signal, timeoutSignal(timeout)) : api.signal
|
|
240
|
+
}), rest);
|
|
241
|
+
headers = new Headers(stripUndefined(headers));
|
|
242
|
+
config.headers = await prepareHeaders(headers, {
|
|
243
|
+
getState,
|
|
244
|
+
arg,
|
|
245
|
+
extra,
|
|
246
|
+
endpoint,
|
|
247
|
+
forced,
|
|
248
|
+
type,
|
|
249
|
+
extraOptions
|
|
250
|
+
}) || headers;
|
|
251
|
+
const bodyIsJsonifiable = isJsonifiable(config.body);
|
|
252
|
+
if (config.body != null && !bodyIsJsonifiable && typeof config.body !== "string") {
|
|
253
|
+
config.headers.delete("content-type");
|
|
254
|
+
}
|
|
255
|
+
if (!config.headers.has("content-type") && bodyIsJsonifiable) {
|
|
256
|
+
config.headers.set("content-type", jsonContentType);
|
|
257
|
+
}
|
|
258
|
+
if (bodyIsJsonifiable && isJsonContentType(config.headers)) {
|
|
259
|
+
config.body = JSON.stringify(config.body, jsonReplacer);
|
|
260
|
+
}
|
|
261
|
+
if (!config.headers.has("accept")) {
|
|
262
|
+
if (responseHandler === "json") {
|
|
263
|
+
config.headers.set("accept", "application/json");
|
|
264
|
+
} else if (responseHandler === "text") {
|
|
265
|
+
config.headers.set("accept", "text/plain, text/html, */*");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (params) {
|
|
269
|
+
const divider = ~url.indexOf("?") ? "&" : "?";
|
|
270
|
+
const query = paramsSerializer ? paramsSerializer(params) : new URLSearchParams(stripUndefined(params));
|
|
271
|
+
url += divider + query;
|
|
272
|
+
}
|
|
273
|
+
url = joinUrls(baseUrl, url);
|
|
274
|
+
const request = new Request(url, config);
|
|
275
|
+
const requestClone = new Request(url, config);
|
|
276
|
+
meta = {
|
|
277
|
+
request: requestClone
|
|
278
|
+
};
|
|
279
|
+
let response;
|
|
280
|
+
try {
|
|
281
|
+
response = await fetchFn(request);
|
|
282
|
+
} catch (e) {
|
|
283
|
+
return {
|
|
284
|
+
error: {
|
|
285
|
+
status: (e instanceof Error || typeof DOMException !== "undefined" && e instanceof DOMException) && e.name === "TimeoutError" ? "TIMEOUT_ERROR" : "FETCH_ERROR",
|
|
286
|
+
error: String(e)
|
|
287
|
+
},
|
|
288
|
+
meta
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const responseClone = response.clone();
|
|
292
|
+
meta.response = responseClone;
|
|
293
|
+
let resultData;
|
|
294
|
+
let responseText = "";
|
|
295
|
+
try {
|
|
296
|
+
let handleResponseError;
|
|
297
|
+
await Promise.all([
|
|
298
|
+
handleResponse(response, responseHandler).then((r) => resultData = r, (e) => handleResponseError = e),
|
|
299
|
+
// see https://github.com/node-fetch/node-fetch/issues/665#issuecomment-538995182
|
|
300
|
+
// we *have* to "use up" both streams at the same time or they will stop running in node-fetch scenarios
|
|
301
|
+
responseClone.text().then((r) => responseText = r, () => {
|
|
302
|
+
})
|
|
303
|
+
]);
|
|
304
|
+
if (handleResponseError) throw handleResponseError;
|
|
305
|
+
} catch (e) {
|
|
306
|
+
return {
|
|
307
|
+
error: {
|
|
308
|
+
status: "PARSING_ERROR",
|
|
309
|
+
originalStatus: response.status,
|
|
310
|
+
data: responseText,
|
|
311
|
+
error: String(e)
|
|
312
|
+
},
|
|
313
|
+
meta
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
return validateStatus(response, resultData) ? {
|
|
317
|
+
data: resultData,
|
|
318
|
+
meta
|
|
319
|
+
} : {
|
|
320
|
+
error: {
|
|
321
|
+
status: response.status,
|
|
322
|
+
data: resultData
|
|
323
|
+
},
|
|
324
|
+
meta
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
async function handleResponse(response, responseHandler) {
|
|
328
|
+
if (typeof responseHandler === "function") {
|
|
329
|
+
return responseHandler(response);
|
|
330
|
+
}
|
|
331
|
+
if (responseHandler === "content-type") {
|
|
332
|
+
responseHandler = isJsonContentType(response.headers) ? "json" : "text";
|
|
333
|
+
}
|
|
334
|
+
if (responseHandler === "json") {
|
|
335
|
+
const text = await response.text();
|
|
336
|
+
return text.length ? JSON.parse(text) : null;
|
|
337
|
+
}
|
|
338
|
+
return response.text();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// src/query/HandledError.ts
|
|
343
|
+
var HandledError = class {
|
|
344
|
+
constructor(value, meta = void 0) {
|
|
345
|
+
__publicField(this, "value", value);
|
|
346
|
+
__publicField(this, "meta", meta);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
// src/query/retry.ts
|
|
351
|
+
async function defaultBackoff(attempt = 0, maxRetries = 5, signal) {
|
|
352
|
+
const attempts = Math.min(attempt, maxRetries);
|
|
353
|
+
const timeout = ~~((Math.random() + 0.4) * (300 << attempts));
|
|
354
|
+
await new Promise((resolve, reject) => {
|
|
355
|
+
const timeoutId = setTimeout(() => resolve(), timeout);
|
|
356
|
+
if (signal) {
|
|
357
|
+
const abortHandler = () => {
|
|
358
|
+
clearTimeout(timeoutId);
|
|
359
|
+
reject(new Error("Aborted"));
|
|
360
|
+
};
|
|
361
|
+
if (signal.aborted) {
|
|
362
|
+
clearTimeout(timeoutId);
|
|
363
|
+
reject(new Error("Aborted"));
|
|
364
|
+
} else {
|
|
365
|
+
signal.addEventListener("abort", abortHandler, {
|
|
366
|
+
once: true
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
}
|
|
372
|
+
function fail(error, meta) {
|
|
373
|
+
throw Object.assign(new HandledError({
|
|
374
|
+
error,
|
|
375
|
+
meta
|
|
376
|
+
}), {
|
|
377
|
+
throwImmediately: true
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
function failIfAborted(signal) {
|
|
381
|
+
if (signal.aborted) {
|
|
382
|
+
fail({
|
|
383
|
+
status: "CUSTOM_ERROR",
|
|
384
|
+
error: "Aborted"
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
var EMPTY_OPTIONS = {};
|
|
389
|
+
var retryWithBackoff = (baseQuery, defaultOptions) => async (args, api, extraOptions) => {
|
|
390
|
+
const possibleMaxRetries = [5, (defaultOptions || EMPTY_OPTIONS).maxRetries, (extraOptions || EMPTY_OPTIONS).maxRetries].filter((x) => x !== void 0);
|
|
391
|
+
const [maxRetries] = possibleMaxRetries.slice(-1);
|
|
392
|
+
const defaultRetryCondition = (_, __, {
|
|
393
|
+
attempt
|
|
394
|
+
}) => attempt <= maxRetries;
|
|
395
|
+
const options = __spreadValues(__spreadValues({
|
|
396
|
+
maxRetries,
|
|
397
|
+
backoff: defaultBackoff,
|
|
398
|
+
retryCondition: defaultRetryCondition
|
|
399
|
+
}, defaultOptions), extraOptions);
|
|
400
|
+
let retry2 = 0;
|
|
401
|
+
while (true) {
|
|
402
|
+
failIfAborted(api.signal);
|
|
403
|
+
try {
|
|
404
|
+
const result = await baseQuery(args, api, extraOptions);
|
|
405
|
+
if (result.error) {
|
|
406
|
+
throw new HandledError(result);
|
|
407
|
+
}
|
|
408
|
+
return result;
|
|
409
|
+
} catch (e) {
|
|
410
|
+
retry2++;
|
|
411
|
+
if (e.throwImmediately) {
|
|
412
|
+
if (e instanceof HandledError) {
|
|
413
|
+
return e.value;
|
|
414
|
+
}
|
|
415
|
+
throw e;
|
|
416
|
+
}
|
|
417
|
+
if (e instanceof HandledError) {
|
|
418
|
+
if (!options.retryCondition(e.value.error, args, {
|
|
419
|
+
attempt: retry2,
|
|
420
|
+
baseQueryApi: api,
|
|
421
|
+
extraOptions
|
|
422
|
+
})) {
|
|
423
|
+
return e.value;
|
|
424
|
+
}
|
|
425
|
+
} else {
|
|
426
|
+
if (retry2 > options.maxRetries) {
|
|
427
|
+
return {
|
|
428
|
+
error: e
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
failIfAborted(api.signal);
|
|
433
|
+
try {
|
|
434
|
+
await options.backoff(retry2, options.maxRetries, api.signal);
|
|
435
|
+
} catch (backoffError) {
|
|
436
|
+
failIfAborted(api.signal);
|
|
437
|
+
throw backoffError;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
};
|
|
442
|
+
var retry = /* @__PURE__ */ Object.assign(retryWithBackoff, {
|
|
443
|
+
fail
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
// src/query/core/setupListeners.ts
|
|
447
|
+
var INTERNAL_PREFIX = "__rtkq/";
|
|
448
|
+
var ONLINE = "online";
|
|
449
|
+
var OFFLINE = "offline";
|
|
450
|
+
var FOCUS = "focus";
|
|
451
|
+
var FOCUSED = "focused";
|
|
452
|
+
var VISIBILITYCHANGE = "visibilitychange";
|
|
453
|
+
var onFocus = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}${FOCUSED}`);
|
|
454
|
+
var onFocusLost = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}un${FOCUSED}`);
|
|
455
|
+
var onOnline = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}${ONLINE}`);
|
|
456
|
+
var onOffline = /* @__PURE__ */ createAction(`${INTERNAL_PREFIX}${OFFLINE}`);
|
|
457
|
+
var actions = {
|
|
458
|
+
onFocus,
|
|
459
|
+
onFocusLost,
|
|
460
|
+
onOnline,
|
|
461
|
+
onOffline
|
|
462
|
+
};
|
|
463
|
+
var initialized = false;
|
|
464
|
+
function setupListeners(dispatch, customHandler) {
|
|
465
|
+
function defaultHandler() {
|
|
466
|
+
const [handleFocus, handleFocusLost, handleOnline, handleOffline] = [onFocus, onFocusLost, onOnline, onOffline].map((action) => () => dispatch(action()));
|
|
467
|
+
const handleVisibilityChange = () => {
|
|
468
|
+
if (window.document.visibilityState === "visible") {
|
|
469
|
+
handleFocus();
|
|
470
|
+
} else {
|
|
471
|
+
handleFocusLost();
|
|
472
|
+
}
|
|
473
|
+
};
|
|
474
|
+
let unsubscribe = () => {
|
|
475
|
+
initialized = false;
|
|
476
|
+
};
|
|
477
|
+
if (!initialized) {
|
|
478
|
+
if (typeof window !== "undefined" && window.addEventListener) {
|
|
479
|
+
let updateListeners2 = function(add) {
|
|
480
|
+
Object.entries(handlers).forEach(([event, handler]) => {
|
|
481
|
+
if (add) {
|
|
482
|
+
window.addEventListener(event, handler, false);
|
|
483
|
+
} else {
|
|
484
|
+
window.removeEventListener(event, handler);
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
};
|
|
488
|
+
var updateListeners = updateListeners2;
|
|
489
|
+
const handlers = {
|
|
490
|
+
[FOCUS]: handleFocus,
|
|
491
|
+
[VISIBILITYCHANGE]: handleVisibilityChange,
|
|
492
|
+
[ONLINE]: handleOnline,
|
|
493
|
+
[OFFLINE]: handleOffline
|
|
494
|
+
};
|
|
495
|
+
updateListeners2(true);
|
|
496
|
+
initialized = true;
|
|
497
|
+
unsubscribe = () => {
|
|
498
|
+
updateListeners2(false);
|
|
499
|
+
initialized = false;
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
return unsubscribe;
|
|
504
|
+
}
|
|
505
|
+
return customHandler ? customHandler(dispatch, actions) : defaultHandler();
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// src/query/endpointDefinitions.ts
|
|
509
|
+
var ENDPOINT_QUERY = "query" /* query */;
|
|
510
|
+
var ENDPOINT_MUTATION = "mutation" /* mutation */;
|
|
511
|
+
var ENDPOINT_INFINITEQUERY = "infinitequery" /* infinitequery */;
|
|
512
|
+
function isQueryDefinition(e) {
|
|
513
|
+
return e.type === ENDPOINT_QUERY;
|
|
514
|
+
}
|
|
515
|
+
function isMutationDefinition(e) {
|
|
516
|
+
return e.type === ENDPOINT_MUTATION;
|
|
517
|
+
}
|
|
518
|
+
function isInfiniteQueryDefinition(e) {
|
|
519
|
+
return e.type === ENDPOINT_INFINITEQUERY;
|
|
520
|
+
}
|
|
521
|
+
function isAnyQueryDefinition(e) {
|
|
522
|
+
return isQueryDefinition(e) || isInfiniteQueryDefinition(e);
|
|
523
|
+
}
|
|
524
|
+
function calculateProvidedBy(description, result, error, queryArg, meta, assertTagTypes) {
|
|
525
|
+
const finalDescription = isFunction(description) ? description(result, error, queryArg, meta) : description;
|
|
526
|
+
if (finalDescription) {
|
|
527
|
+
return filterMap(finalDescription, isNotNullish, (tag) => assertTagTypes(expandTagDescription(tag)));
|
|
528
|
+
}
|
|
529
|
+
return [];
|
|
530
|
+
}
|
|
531
|
+
function isFunction(t) {
|
|
532
|
+
return typeof t === "function";
|
|
533
|
+
}
|
|
534
|
+
function expandTagDescription(description) {
|
|
535
|
+
return typeof description === "string" ? {
|
|
536
|
+
type: description
|
|
537
|
+
} : description;
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
// src/query/utils/immerImports.ts
|
|
541
|
+
import { current, isDraft, applyPatches, original, isDraftable, produceWithPatches, enablePatches } from "immer";
|
|
542
|
+
|
|
543
|
+
// src/query/core/buildInitiate.ts
|
|
544
|
+
import { formatProdErrorMessage as _formatProdErrorMessage } from "@reduxjs/toolkit";
|
|
545
|
+
|
|
546
|
+
// src/tsHelpers.ts
|
|
547
|
+
function asSafePromise(promise, fallback) {
|
|
548
|
+
return promise.catch(fallback);
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// src/query/apiTypes.ts
|
|
552
|
+
var getEndpointDefinition = (context, endpointName) => context.endpointDefinitions[endpointName];
|
|
553
|
+
|
|
554
|
+
// src/query/core/buildInitiate.ts
|
|
555
|
+
var forceQueryFnSymbol = /* @__PURE__ */ Symbol("forceQueryFn");
|
|
556
|
+
var isUpsertQuery = (arg) => typeof arg[forceQueryFnSymbol] === "function";
|
|
557
|
+
function buildInitiate({
|
|
558
|
+
serializeQueryArgs,
|
|
559
|
+
queryThunk,
|
|
560
|
+
infiniteQueryThunk,
|
|
561
|
+
mutationThunk,
|
|
562
|
+
api,
|
|
563
|
+
context,
|
|
564
|
+
getInternalState
|
|
565
|
+
}) {
|
|
566
|
+
const getRunningQueries = (dispatch) => {
|
|
567
|
+
var _a;
|
|
568
|
+
return (_a = getInternalState(dispatch)) == null ? void 0 : _a.runningQueries;
|
|
569
|
+
};
|
|
570
|
+
const getRunningMutations = (dispatch) => {
|
|
571
|
+
var _a;
|
|
572
|
+
return (_a = getInternalState(dispatch)) == null ? void 0 : _a.runningMutations;
|
|
573
|
+
};
|
|
574
|
+
const {
|
|
575
|
+
unsubscribeQueryResult,
|
|
576
|
+
removeMutationResult,
|
|
577
|
+
updateSubscriptionOptions
|
|
578
|
+
} = api.internalActions;
|
|
579
|
+
return {
|
|
580
|
+
buildInitiateQuery,
|
|
581
|
+
buildInitiateInfiniteQuery,
|
|
582
|
+
buildInitiateMutation,
|
|
583
|
+
getRunningQueryThunk,
|
|
584
|
+
getRunningMutationThunk,
|
|
585
|
+
getRunningQueriesThunk,
|
|
586
|
+
getRunningMutationsThunk
|
|
587
|
+
};
|
|
588
|
+
function getRunningQueryThunk(endpointName, queryArgs) {
|
|
589
|
+
return (dispatch) => {
|
|
590
|
+
var _a;
|
|
591
|
+
const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|
592
|
+
const queryCacheKey = serializeQueryArgs({
|
|
593
|
+
queryArgs,
|
|
594
|
+
endpointDefinition,
|
|
595
|
+
endpointName
|
|
596
|
+
});
|
|
597
|
+
return (_a = getRunningQueries(dispatch)) == null ? void 0 : _a.get(queryCacheKey);
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function getRunningMutationThunk(_endpointName, fixedCacheKeyOrRequestId) {
|
|
601
|
+
return (dispatch) => {
|
|
602
|
+
var _a;
|
|
603
|
+
return (_a = getRunningMutations(dispatch)) == null ? void 0 : _a.get(fixedCacheKeyOrRequestId);
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
function getRunningQueriesThunk() {
|
|
607
|
+
return (dispatch) => filterNullishValues(getRunningQueries(dispatch));
|
|
608
|
+
}
|
|
609
|
+
function getRunningMutationsThunk() {
|
|
610
|
+
return (dispatch) => filterNullishValues(getRunningMutations(dispatch));
|
|
611
|
+
}
|
|
612
|
+
function middlewareWarning(dispatch) {
|
|
613
|
+
if (process.env.NODE_ENV !== "production") {
|
|
614
|
+
if (middlewareWarning.triggered) return;
|
|
615
|
+
const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
|
|
616
|
+
middlewareWarning.triggered = true;
|
|
617
|
+
if (typeof returnedValue !== "object" || typeof (returnedValue == null ? void 0 : returnedValue.type) === "string") {
|
|
618
|
+
throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage(34) : `Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
|
|
619
|
+
You must add the middleware for RTK-Query to function correctly!`);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
function buildInitiateAnyQuery(endpointName, endpointDefinition) {
|
|
624
|
+
const queryAction = (arg, _a = {}) => {
|
|
625
|
+
var _b = _a, {
|
|
626
|
+
subscribe = true,
|
|
627
|
+
forceRefetch,
|
|
628
|
+
subscriptionOptions,
|
|
629
|
+
[forceQueryFnSymbol]: forceQueryFn
|
|
630
|
+
} = _b, rest = __objRest(_b, [
|
|
631
|
+
"subscribe",
|
|
632
|
+
"forceRefetch",
|
|
633
|
+
"subscriptionOptions",
|
|
634
|
+
__restKey(forceQueryFnSymbol)
|
|
635
|
+
]);
|
|
636
|
+
return (dispatch, getState) => {
|
|
637
|
+
var _a2;
|
|
638
|
+
const queryCacheKey = serializeQueryArgs({
|
|
639
|
+
queryArgs: arg,
|
|
640
|
+
endpointDefinition,
|
|
641
|
+
endpointName
|
|
642
|
+
});
|
|
643
|
+
let thunk;
|
|
644
|
+
const commonThunkArgs = __spreadProps(__spreadValues({}, rest), {
|
|
645
|
+
type: ENDPOINT_QUERY,
|
|
646
|
+
subscribe,
|
|
647
|
+
forceRefetch,
|
|
648
|
+
subscriptionOptions,
|
|
649
|
+
endpointName,
|
|
650
|
+
originalArgs: arg,
|
|
651
|
+
queryCacheKey,
|
|
652
|
+
[forceQueryFnSymbol]: forceQueryFn
|
|
653
|
+
});
|
|
654
|
+
if (isQueryDefinition(endpointDefinition)) {
|
|
655
|
+
thunk = queryThunk(commonThunkArgs);
|
|
656
|
+
} else {
|
|
657
|
+
const {
|
|
658
|
+
direction,
|
|
659
|
+
initialPageParam,
|
|
660
|
+
refetchCachedPages
|
|
661
|
+
} = rest;
|
|
662
|
+
thunk = infiniteQueryThunk(__spreadProps(__spreadValues({}, commonThunkArgs), {
|
|
663
|
+
// Supply these even if undefined. This helps with a field existence
|
|
664
|
+
// check over in `buildSlice.ts`
|
|
665
|
+
direction,
|
|
666
|
+
initialPageParam,
|
|
667
|
+
refetchCachedPages
|
|
668
|
+
}));
|
|
669
|
+
}
|
|
670
|
+
const selector = api.endpoints[endpointName].select(arg);
|
|
671
|
+
const thunkResult = dispatch(thunk);
|
|
672
|
+
const stateAfter = selector(getState());
|
|
673
|
+
middlewareWarning(dispatch);
|
|
674
|
+
const {
|
|
675
|
+
requestId,
|
|
676
|
+
abort
|
|
677
|
+
} = thunkResult;
|
|
678
|
+
const skippedSynchronously = stateAfter.requestId !== requestId;
|
|
679
|
+
const runningQuery = (_a2 = getRunningQueries(dispatch)) == null ? void 0 : _a2.get(queryCacheKey);
|
|
680
|
+
const selectFromState = () => selector(getState());
|
|
681
|
+
const statePromise = Object.assign(forceQueryFn ? (
|
|
682
|
+
// a query has been forced (upsertQueryData)
|
|
683
|
+
// -> we want to resolve it once data has been written with the data that will be written
|
|
684
|
+
thunkResult.then(selectFromState)
|
|
685
|
+
) : skippedSynchronously && !runningQuery ? (
|
|
686
|
+
// a query has been skipped due to a condition and we do not have any currently running query
|
|
687
|
+
// -> we want to resolve it immediately with the current data
|
|
688
|
+
Promise.resolve(stateAfter)
|
|
689
|
+
) : (
|
|
690
|
+
// query just started or one is already in flight
|
|
691
|
+
// -> wait for the running query, then resolve with data from after that
|
|
692
|
+
Promise.all([runningQuery, thunkResult]).then(selectFromState)
|
|
693
|
+
), {
|
|
694
|
+
arg,
|
|
695
|
+
requestId,
|
|
696
|
+
subscriptionOptions,
|
|
697
|
+
queryCacheKey,
|
|
698
|
+
abort,
|
|
699
|
+
async unwrap() {
|
|
700
|
+
const result = await statePromise;
|
|
701
|
+
if (result.isError) {
|
|
702
|
+
throw result.error;
|
|
703
|
+
}
|
|
704
|
+
return result.data;
|
|
705
|
+
},
|
|
706
|
+
refetch: (options) => dispatch(queryAction(arg, __spreadValues({
|
|
707
|
+
subscribe: false,
|
|
708
|
+
forceRefetch: true
|
|
709
|
+
}, options))),
|
|
710
|
+
unsubscribe() {
|
|
711
|
+
if (subscribe) dispatch(unsubscribeQueryResult({
|
|
712
|
+
queryCacheKey,
|
|
713
|
+
requestId
|
|
714
|
+
}));
|
|
715
|
+
},
|
|
716
|
+
updateSubscriptionOptions(options) {
|
|
717
|
+
statePromise.subscriptionOptions = options;
|
|
718
|
+
dispatch(updateSubscriptionOptions({
|
|
719
|
+
endpointName,
|
|
720
|
+
requestId,
|
|
721
|
+
queryCacheKey,
|
|
722
|
+
options
|
|
723
|
+
}));
|
|
724
|
+
}
|
|
725
|
+
});
|
|
726
|
+
if (!runningQuery && !skippedSynchronously && !forceQueryFn) {
|
|
727
|
+
const runningQueries = getRunningQueries(dispatch);
|
|
728
|
+
runningQueries.set(queryCacheKey, statePromise);
|
|
729
|
+
statePromise.then(() => {
|
|
730
|
+
runningQueries.delete(queryCacheKey);
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
return statePromise;
|
|
734
|
+
};
|
|
735
|
+
};
|
|
736
|
+
return queryAction;
|
|
737
|
+
}
|
|
738
|
+
function buildInitiateQuery(endpointName, endpointDefinition) {
|
|
739
|
+
const queryAction = buildInitiateAnyQuery(endpointName, endpointDefinition);
|
|
740
|
+
return queryAction;
|
|
741
|
+
}
|
|
742
|
+
function buildInitiateInfiniteQuery(endpointName, endpointDefinition) {
|
|
743
|
+
const infiniteQueryAction = buildInitiateAnyQuery(endpointName, endpointDefinition);
|
|
744
|
+
return infiniteQueryAction;
|
|
745
|
+
}
|
|
746
|
+
function buildInitiateMutation(endpointName) {
|
|
747
|
+
return (arg, {
|
|
748
|
+
track = true,
|
|
749
|
+
fixedCacheKey
|
|
750
|
+
} = {}) => (dispatch, getState) => {
|
|
751
|
+
const thunk = mutationThunk({
|
|
752
|
+
type: "mutation",
|
|
753
|
+
endpointName,
|
|
754
|
+
originalArgs: arg,
|
|
755
|
+
track,
|
|
756
|
+
fixedCacheKey
|
|
757
|
+
});
|
|
758
|
+
const thunkResult = dispatch(thunk);
|
|
759
|
+
middlewareWarning(dispatch);
|
|
760
|
+
const {
|
|
761
|
+
requestId,
|
|
762
|
+
abort,
|
|
763
|
+
unwrap
|
|
764
|
+
} = thunkResult;
|
|
765
|
+
const returnValuePromise = asSafePromise(thunkResult.unwrap().then((data) => ({
|
|
766
|
+
data
|
|
767
|
+
})), (error) => ({
|
|
768
|
+
error
|
|
769
|
+
}));
|
|
770
|
+
const reset = () => {
|
|
771
|
+
dispatch(removeMutationResult({
|
|
772
|
+
requestId,
|
|
773
|
+
fixedCacheKey
|
|
774
|
+
}));
|
|
775
|
+
};
|
|
776
|
+
const ret = Object.assign(returnValuePromise, {
|
|
777
|
+
arg: thunkResult.arg,
|
|
778
|
+
requestId,
|
|
779
|
+
abort,
|
|
780
|
+
unwrap,
|
|
781
|
+
reset
|
|
782
|
+
});
|
|
783
|
+
const runningMutations = getRunningMutations(dispatch);
|
|
784
|
+
runningMutations.set(requestId, ret);
|
|
785
|
+
ret.then(() => {
|
|
786
|
+
runningMutations.delete(requestId);
|
|
787
|
+
});
|
|
788
|
+
if (fixedCacheKey) {
|
|
789
|
+
runningMutations.set(fixedCacheKey, ret);
|
|
790
|
+
ret.then(() => {
|
|
791
|
+
if (runningMutations.get(fixedCacheKey) === ret) {
|
|
792
|
+
runningMutations.delete(fixedCacheKey);
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
}
|
|
796
|
+
return ret;
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
// src/query/standardSchema.ts
|
|
802
|
+
import { SchemaError } from "@standard-schema/utils";
|
|
803
|
+
var NamedSchemaError = class extends SchemaError {
|
|
804
|
+
constructor(issues, value, schemaName, _bqMeta) {
|
|
805
|
+
super(issues);
|
|
806
|
+
__publicField(this, "value", value);
|
|
807
|
+
__publicField(this, "schemaName", schemaName);
|
|
808
|
+
__publicField(this, "_bqMeta", _bqMeta);
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
var shouldSkip = (skipSchemaValidation, schemaName) => Array.isArray(skipSchemaValidation) ? skipSchemaValidation.includes(schemaName) : !!skipSchemaValidation;
|
|
812
|
+
async function parseWithSchema(schema, data, schemaName, bqMeta) {
|
|
813
|
+
const result = await schema["~standard"].validate(data);
|
|
814
|
+
if (result.issues) {
|
|
815
|
+
throw new NamedSchemaError(result.issues, data, schemaName, bqMeta);
|
|
816
|
+
}
|
|
817
|
+
return result.value;
|
|
818
|
+
}
|
|
819
|
+
|
|
820
|
+
// src/query/core/buildThunks.ts
|
|
821
|
+
function defaultTransformResponse(baseQueryReturnValue) {
|
|
822
|
+
return baseQueryReturnValue;
|
|
823
|
+
}
|
|
824
|
+
var addShouldAutoBatch = (arg = {}) => {
|
|
825
|
+
return __spreadProps(__spreadValues({}, arg), {
|
|
826
|
+
[SHOULD_AUTOBATCH]: true
|
|
827
|
+
});
|
|
828
|
+
};
|
|
829
|
+
function buildThunks({
|
|
830
|
+
reducerPath,
|
|
831
|
+
baseQuery,
|
|
832
|
+
context: {
|
|
833
|
+
endpointDefinitions
|
|
834
|
+
},
|
|
835
|
+
serializeQueryArgs,
|
|
836
|
+
api,
|
|
837
|
+
assertTagType,
|
|
838
|
+
selectors,
|
|
839
|
+
onSchemaFailure,
|
|
840
|
+
catchSchemaFailure: globalCatchSchemaFailure,
|
|
841
|
+
skipSchemaValidation: globalSkipSchemaValidation
|
|
842
|
+
}) {
|
|
843
|
+
const patchQueryData = (endpointName, arg, patches, updateProvided) => (dispatch, getState) => {
|
|
844
|
+
const endpointDefinition = endpointDefinitions[endpointName];
|
|
845
|
+
const queryCacheKey = serializeQueryArgs({
|
|
846
|
+
queryArgs: arg,
|
|
847
|
+
endpointDefinition,
|
|
848
|
+
endpointName
|
|
849
|
+
});
|
|
850
|
+
dispatch(api.internalActions.queryResultPatched({
|
|
851
|
+
queryCacheKey,
|
|
852
|
+
patches
|
|
853
|
+
}));
|
|
854
|
+
if (!updateProvided) {
|
|
855
|
+
return;
|
|
856
|
+
}
|
|
857
|
+
const newValue = api.endpoints[endpointName].select(arg)(
|
|
858
|
+
// Work around TS 4.1 mismatch
|
|
859
|
+
getState()
|
|
860
|
+
);
|
|
861
|
+
const providedTags = calculateProvidedBy(endpointDefinition.providesTags, newValue.data, void 0, arg, {}, assertTagType);
|
|
862
|
+
dispatch(api.internalActions.updateProvidedBy([{
|
|
863
|
+
queryCacheKey,
|
|
864
|
+
providedTags
|
|
865
|
+
}]));
|
|
866
|
+
};
|
|
867
|
+
function addToStart(items, item, max = 0) {
|
|
868
|
+
const newItems = [item, ...items];
|
|
869
|
+
return max && newItems.length > max ? newItems.slice(0, -1) : newItems;
|
|
870
|
+
}
|
|
871
|
+
function addToEnd(items, item, max = 0) {
|
|
872
|
+
const newItems = [...items, item];
|
|
873
|
+
return max && newItems.length > max ? newItems.slice(1) : newItems;
|
|
874
|
+
}
|
|
875
|
+
const updateQueryData = (endpointName, arg, updateRecipe, updateProvided = true) => (dispatch, getState) => {
|
|
876
|
+
const endpointDefinition = api.endpoints[endpointName];
|
|
877
|
+
const currentState = endpointDefinition.select(arg)(
|
|
878
|
+
// Work around TS 4.1 mismatch
|
|
879
|
+
getState()
|
|
880
|
+
);
|
|
881
|
+
const ret = {
|
|
882
|
+
patches: [],
|
|
883
|
+
inversePatches: [],
|
|
884
|
+
undo: () => dispatch(api.util.patchQueryData(endpointName, arg, ret.inversePatches, updateProvided))
|
|
885
|
+
};
|
|
886
|
+
if (currentState.status === STATUS_UNINITIALIZED) {
|
|
887
|
+
return ret;
|
|
888
|
+
}
|
|
889
|
+
let newValue;
|
|
890
|
+
if ("data" in currentState) {
|
|
891
|
+
if (isDraftable(currentState.data)) {
|
|
892
|
+
const [value, patches, inversePatches] = produceWithPatches(currentState.data, updateRecipe);
|
|
893
|
+
ret.patches.push(...patches);
|
|
894
|
+
ret.inversePatches.push(...inversePatches);
|
|
895
|
+
newValue = value;
|
|
896
|
+
} else {
|
|
897
|
+
newValue = updateRecipe(currentState.data);
|
|
898
|
+
ret.patches.push({
|
|
899
|
+
op: "replace",
|
|
900
|
+
path: [],
|
|
901
|
+
value: newValue
|
|
902
|
+
});
|
|
903
|
+
ret.inversePatches.push({
|
|
904
|
+
op: "replace",
|
|
905
|
+
path: [],
|
|
906
|
+
value: currentState.data
|
|
907
|
+
});
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
if (ret.patches.length === 0) {
|
|
911
|
+
return ret;
|
|
912
|
+
}
|
|
913
|
+
dispatch(api.util.patchQueryData(endpointName, arg, ret.patches, updateProvided));
|
|
914
|
+
return ret;
|
|
915
|
+
};
|
|
916
|
+
const upsertQueryData = (endpointName, arg, value) => (dispatch) => {
|
|
917
|
+
const res = dispatch(api.endpoints[endpointName].initiate(arg, {
|
|
918
|
+
subscribe: false,
|
|
919
|
+
forceRefetch: true,
|
|
920
|
+
[forceQueryFnSymbol]: () => ({
|
|
921
|
+
data: value
|
|
922
|
+
})
|
|
923
|
+
}));
|
|
924
|
+
return res;
|
|
925
|
+
};
|
|
926
|
+
const getTransformCallbackForEndpoint = (endpointDefinition, transformFieldName) => {
|
|
927
|
+
return endpointDefinition.query && endpointDefinition[transformFieldName] ? endpointDefinition[transformFieldName] : defaultTransformResponse;
|
|
928
|
+
};
|
|
929
|
+
const executeEndpoint = async (arg, {
|
|
930
|
+
signal,
|
|
931
|
+
abort,
|
|
932
|
+
rejectWithValue,
|
|
933
|
+
fulfillWithValue,
|
|
934
|
+
dispatch,
|
|
935
|
+
getState,
|
|
936
|
+
extra
|
|
937
|
+
}) => {
|
|
938
|
+
var _a, _b, _c, _d, _e, _f;
|
|
939
|
+
const endpointDefinition = endpointDefinitions[arg.endpointName];
|
|
940
|
+
const {
|
|
941
|
+
metaSchema,
|
|
942
|
+
skipSchemaValidation = globalSkipSchemaValidation
|
|
943
|
+
} = endpointDefinition;
|
|
944
|
+
const isQuery = arg.type === ENDPOINT_QUERY;
|
|
945
|
+
try {
|
|
946
|
+
let transformResponse = defaultTransformResponse;
|
|
947
|
+
const baseQueryApi = {
|
|
948
|
+
signal,
|
|
949
|
+
abort,
|
|
950
|
+
dispatch,
|
|
951
|
+
getState,
|
|
952
|
+
extra,
|
|
953
|
+
endpoint: arg.endpointName,
|
|
954
|
+
type: arg.type,
|
|
955
|
+
forced: isQuery ? isForcedQuery(arg, getState()) : void 0,
|
|
956
|
+
queryCacheKey: isQuery ? arg.queryCacheKey : void 0
|
|
957
|
+
};
|
|
958
|
+
const forceQueryFn = isQuery ? arg[forceQueryFnSymbol] : void 0;
|
|
959
|
+
let finalQueryReturnValue;
|
|
960
|
+
const fetchPage = async (data, param, maxPages, previous) => {
|
|
961
|
+
if (param == null && data.pages.length) {
|
|
962
|
+
return Promise.resolve({
|
|
963
|
+
data
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
const finalQueryArg = {
|
|
967
|
+
queryArg: arg.originalArgs,
|
|
968
|
+
pageParam: param
|
|
969
|
+
};
|
|
970
|
+
const pageResponse = await executeRequest(finalQueryArg);
|
|
971
|
+
const addTo = previous ? addToStart : addToEnd;
|
|
972
|
+
return {
|
|
973
|
+
data: {
|
|
974
|
+
pages: addTo(data.pages, pageResponse.data, maxPages),
|
|
975
|
+
pageParams: addTo(data.pageParams, param, maxPages)
|
|
976
|
+
},
|
|
977
|
+
meta: pageResponse.meta
|
|
978
|
+
};
|
|
979
|
+
};
|
|
980
|
+
async function executeRequest(finalQueryArg) {
|
|
981
|
+
let result;
|
|
982
|
+
const {
|
|
983
|
+
extraOptions,
|
|
984
|
+
argSchema,
|
|
985
|
+
rawResponseSchema,
|
|
986
|
+
responseSchema
|
|
987
|
+
} = endpointDefinition;
|
|
988
|
+
if (argSchema && !shouldSkip(skipSchemaValidation, "arg")) {
|
|
989
|
+
finalQueryArg = await parseWithSchema(
|
|
990
|
+
argSchema,
|
|
991
|
+
finalQueryArg,
|
|
992
|
+
"argSchema",
|
|
993
|
+
{}
|
|
994
|
+
// we don't have a meta yet, so we can't pass it
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
if (forceQueryFn) {
|
|
998
|
+
result = forceQueryFn();
|
|
999
|
+
} else if (endpointDefinition.query) {
|
|
1000
|
+
transformResponse = getTransformCallbackForEndpoint(endpointDefinition, "transformResponse");
|
|
1001
|
+
result = await baseQuery(endpointDefinition.query(finalQueryArg), baseQueryApi, extraOptions);
|
|
1002
|
+
} else {
|
|
1003
|
+
result = await endpointDefinition.queryFn(finalQueryArg, baseQueryApi, extraOptions, (arg2) => baseQuery(arg2, baseQueryApi, extraOptions));
|
|
1004
|
+
}
|
|
1005
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
1006
|
+
const what = endpointDefinition.query ? "`baseQuery`" : "`queryFn`";
|
|
1007
|
+
let err;
|
|
1008
|
+
if (!result) {
|
|
1009
|
+
err = `${what} did not return anything.`;
|
|
1010
|
+
} else if (typeof result !== "object") {
|
|
1011
|
+
err = `${what} did not return an object.`;
|
|
1012
|
+
} else if (result.error && result.data) {
|
|
1013
|
+
err = `${what} returned an object containing both \`error\` and \`result\`.`;
|
|
1014
|
+
} else if (result.error === void 0 && result.data === void 0) {
|
|
1015
|
+
err = `${what} returned an object containing neither a valid \`error\` and \`result\`. At least one of them should not be \`undefined\``;
|
|
1016
|
+
} else {
|
|
1017
|
+
for (const key of Object.keys(result)) {
|
|
1018
|
+
if (key !== "error" && key !== "data" && key !== "meta") {
|
|
1019
|
+
err = `The object returned by ${what} has the unknown property ${key}.`;
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
if (err) {
|
|
1025
|
+
console.error(`Error encountered handling the endpoint ${arg.endpointName}.
|
|
1026
|
+
${err}
|
|
1027
|
+
It needs to return an object with either the shape \`{ data: <value> }\` or \`{ error: <value> }\` that may contain an optional \`meta\` property.
|
|
1028
|
+
Object returned was:`, result);
|
|
1029
|
+
}
|
|
1030
|
+
}
|
|
1031
|
+
if (result.error) throw new HandledError(result.error, result.meta);
|
|
1032
|
+
let {
|
|
1033
|
+
data
|
|
1034
|
+
} = result;
|
|
1035
|
+
if (rawResponseSchema && !shouldSkip(skipSchemaValidation, "rawResponse")) {
|
|
1036
|
+
data = await parseWithSchema(rawResponseSchema, result.data, "rawResponseSchema", result.meta);
|
|
1037
|
+
}
|
|
1038
|
+
let transformedResponse = await transformResponse(data, result.meta, finalQueryArg);
|
|
1039
|
+
if (responseSchema && !shouldSkip(skipSchemaValidation, "response")) {
|
|
1040
|
+
transformedResponse = await parseWithSchema(responseSchema, transformedResponse, "responseSchema", result.meta);
|
|
1041
|
+
}
|
|
1042
|
+
return __spreadProps(__spreadValues({}, result), {
|
|
1043
|
+
data: transformedResponse
|
|
1044
|
+
});
|
|
1045
|
+
}
|
|
1046
|
+
if (isQuery && "infiniteQueryOptions" in endpointDefinition) {
|
|
1047
|
+
const {
|
|
1048
|
+
infiniteQueryOptions
|
|
1049
|
+
} = endpointDefinition;
|
|
1050
|
+
const {
|
|
1051
|
+
maxPages = Infinity
|
|
1052
|
+
} = infiniteQueryOptions;
|
|
1053
|
+
const refetchCachedPages = (_b = (_a = arg.refetchCachedPages) != null ? _a : infiniteQueryOptions.refetchCachedPages) != null ? _b : true;
|
|
1054
|
+
let result;
|
|
1055
|
+
const blankData = {
|
|
1056
|
+
pages: [],
|
|
1057
|
+
pageParams: []
|
|
1058
|
+
};
|
|
1059
|
+
const cachedData = (_c = selectors.selectQueryEntry(getState(), arg.queryCacheKey)) == null ? void 0 : _c.data;
|
|
1060
|
+
const isForcedQueryNeedingRefetch = (
|
|
1061
|
+
// arg.forceRefetch
|
|
1062
|
+
isForcedQuery(arg, getState()) && !arg.direction
|
|
1063
|
+
);
|
|
1064
|
+
const existingData = isForcedQueryNeedingRefetch || !cachedData ? blankData : cachedData;
|
|
1065
|
+
if ("direction" in arg && arg.direction && existingData.pages.length) {
|
|
1066
|
+
const previous = arg.direction === "backward";
|
|
1067
|
+
const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
|
|
1068
|
+
const param = pageParamFn(infiniteQueryOptions, existingData, arg.originalArgs);
|
|
1069
|
+
result = await fetchPage(existingData, param, maxPages, previous);
|
|
1070
|
+
} else {
|
|
1071
|
+
const {
|
|
1072
|
+
initialPageParam = infiniteQueryOptions.initialPageParam
|
|
1073
|
+
} = arg;
|
|
1074
|
+
const cachedPageParams = (_d = cachedData == null ? void 0 : cachedData.pageParams) != null ? _d : [];
|
|
1075
|
+
const firstPageParam = (_e = cachedPageParams[0]) != null ? _e : initialPageParam;
|
|
1076
|
+
const totalPages = cachedPageParams.length;
|
|
1077
|
+
result = await fetchPage(existingData, firstPageParam, maxPages);
|
|
1078
|
+
if (forceQueryFn) {
|
|
1079
|
+
result = {
|
|
1080
|
+
data: result.data.pages[0]
|
|
1081
|
+
};
|
|
1082
|
+
}
|
|
1083
|
+
if (refetchCachedPages) {
|
|
1084
|
+
for (let i = 1; i < totalPages; i++) {
|
|
1085
|
+
const param = getNextPageParam(infiniteQueryOptions, result.data, arg.originalArgs);
|
|
1086
|
+
result = await fetchPage(result.data, param, maxPages);
|
|
1087
|
+
}
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
finalQueryReturnValue = result;
|
|
1091
|
+
} else {
|
|
1092
|
+
finalQueryReturnValue = await executeRequest(arg.originalArgs);
|
|
1093
|
+
}
|
|
1094
|
+
if (metaSchema && !shouldSkip(skipSchemaValidation, "meta") && finalQueryReturnValue.meta) {
|
|
1095
|
+
finalQueryReturnValue.meta = await parseWithSchema(metaSchema, finalQueryReturnValue.meta, "metaSchema", finalQueryReturnValue.meta);
|
|
1096
|
+
}
|
|
1097
|
+
return fulfillWithValue(finalQueryReturnValue.data, addShouldAutoBatch({
|
|
1098
|
+
fulfilledTimeStamp: Date.now(),
|
|
1099
|
+
baseQueryMeta: finalQueryReturnValue.meta
|
|
1100
|
+
}));
|
|
1101
|
+
} catch (error) {
|
|
1102
|
+
let caughtError = error;
|
|
1103
|
+
if (caughtError instanceof HandledError) {
|
|
1104
|
+
let transformErrorResponse = getTransformCallbackForEndpoint(endpointDefinition, "transformErrorResponse");
|
|
1105
|
+
const {
|
|
1106
|
+
rawErrorResponseSchema,
|
|
1107
|
+
errorResponseSchema
|
|
1108
|
+
} = endpointDefinition;
|
|
1109
|
+
let {
|
|
1110
|
+
value,
|
|
1111
|
+
meta
|
|
1112
|
+
} = caughtError;
|
|
1113
|
+
try {
|
|
1114
|
+
if (rawErrorResponseSchema && !shouldSkip(skipSchemaValidation, "rawErrorResponse")) {
|
|
1115
|
+
value = await parseWithSchema(rawErrorResponseSchema, value, "rawErrorResponseSchema", meta);
|
|
1116
|
+
}
|
|
1117
|
+
if (metaSchema && !shouldSkip(skipSchemaValidation, "meta")) {
|
|
1118
|
+
meta = await parseWithSchema(metaSchema, meta, "metaSchema", meta);
|
|
1119
|
+
}
|
|
1120
|
+
let transformedErrorResponse = await transformErrorResponse(value, meta, arg.originalArgs);
|
|
1121
|
+
if (errorResponseSchema && !shouldSkip(skipSchemaValidation, "errorResponse")) {
|
|
1122
|
+
transformedErrorResponse = await parseWithSchema(errorResponseSchema, transformedErrorResponse, "errorResponseSchema", meta);
|
|
1123
|
+
}
|
|
1124
|
+
return rejectWithValue(transformedErrorResponse, addShouldAutoBatch({
|
|
1125
|
+
baseQueryMeta: meta
|
|
1126
|
+
}));
|
|
1127
|
+
} catch (e) {
|
|
1128
|
+
caughtError = e;
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
try {
|
|
1132
|
+
if (caughtError instanceof NamedSchemaError) {
|
|
1133
|
+
const info = {
|
|
1134
|
+
endpoint: arg.endpointName,
|
|
1135
|
+
arg: arg.originalArgs,
|
|
1136
|
+
type: arg.type,
|
|
1137
|
+
queryCacheKey: isQuery ? arg.queryCacheKey : void 0
|
|
1138
|
+
};
|
|
1139
|
+
(_f = endpointDefinition.onSchemaFailure) == null ? void 0 : _f.call(endpointDefinition, caughtError, info);
|
|
1140
|
+
onSchemaFailure == null ? void 0 : onSchemaFailure(caughtError, info);
|
|
1141
|
+
const {
|
|
1142
|
+
catchSchemaFailure = globalCatchSchemaFailure
|
|
1143
|
+
} = endpointDefinition;
|
|
1144
|
+
if (catchSchemaFailure) {
|
|
1145
|
+
return rejectWithValue(catchSchemaFailure(caughtError, info), addShouldAutoBatch({
|
|
1146
|
+
baseQueryMeta: caughtError._bqMeta
|
|
1147
|
+
}));
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
} catch (e) {
|
|
1151
|
+
caughtError = e;
|
|
1152
|
+
}
|
|
1153
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV !== "production") {
|
|
1154
|
+
console.error(`An unhandled error occurred processing a request for the endpoint "${arg.endpointName}".
|
|
1155
|
+
In the case of an unhandled error, no tags will be "provided" or "invalidated".`, caughtError);
|
|
1156
|
+
} else {
|
|
1157
|
+
console.error(caughtError);
|
|
1158
|
+
}
|
|
1159
|
+
throw caughtError;
|
|
1160
|
+
}
|
|
1161
|
+
};
|
|
1162
|
+
function isForcedQuery(arg, state) {
|
|
1163
|
+
var _a;
|
|
1164
|
+
const requestState = selectors.selectQueryEntry(state, arg.queryCacheKey);
|
|
1165
|
+
const baseFetchOnMountOrArgChange = selectors.selectConfig(state).refetchOnMountOrArgChange;
|
|
1166
|
+
const fulfilledVal = requestState == null ? void 0 : requestState.fulfilledTimeStamp;
|
|
1167
|
+
const refetchVal = (_a = arg.forceRefetch) != null ? _a : arg.subscribe && baseFetchOnMountOrArgChange;
|
|
1168
|
+
if (refetchVal) {
|
|
1169
|
+
return refetchVal === true || (Number(/* @__PURE__ */ new Date()) - Number(fulfilledVal)) / 1e3 >= refetchVal;
|
|
1170
|
+
}
|
|
1171
|
+
return false;
|
|
1172
|
+
}
|
|
1173
|
+
const createQueryThunk = () => {
|
|
1174
|
+
const generatedQueryThunk = createAsyncThunk(`${reducerPath}/executeQuery`, executeEndpoint, {
|
|
1175
|
+
getPendingMeta({
|
|
1176
|
+
arg
|
|
1177
|
+
}) {
|
|
1178
|
+
const endpointDefinition = endpointDefinitions[arg.endpointName];
|
|
1179
|
+
return addShouldAutoBatch(__spreadValues({
|
|
1180
|
+
startedTimeStamp: Date.now()
|
|
1181
|
+
}, isInfiniteQueryDefinition(endpointDefinition) ? {
|
|
1182
|
+
direction: arg.direction
|
|
1183
|
+
} : {}));
|
|
1184
|
+
},
|
|
1185
|
+
condition(queryThunkArg, {
|
|
1186
|
+
getState
|
|
1187
|
+
}) {
|
|
1188
|
+
var _a;
|
|
1189
|
+
const state = getState();
|
|
1190
|
+
const requestState = selectors.selectQueryEntry(state, queryThunkArg.queryCacheKey);
|
|
1191
|
+
const fulfilledVal = requestState == null ? void 0 : requestState.fulfilledTimeStamp;
|
|
1192
|
+
const currentArg = queryThunkArg.originalArgs;
|
|
1193
|
+
const previousArg = requestState == null ? void 0 : requestState.originalArgs;
|
|
1194
|
+
const endpointDefinition = endpointDefinitions[queryThunkArg.endpointName];
|
|
1195
|
+
const direction = queryThunkArg.direction;
|
|
1196
|
+
if (isUpsertQuery(queryThunkArg)) {
|
|
1197
|
+
return true;
|
|
1198
|
+
}
|
|
1199
|
+
if ((requestState == null ? void 0 : requestState.status) === "pending") {
|
|
1200
|
+
return false;
|
|
1201
|
+
}
|
|
1202
|
+
if (isForcedQuery(queryThunkArg, state)) {
|
|
1203
|
+
return true;
|
|
1204
|
+
}
|
|
1205
|
+
if (isQueryDefinition(endpointDefinition) && ((_a = endpointDefinition == null ? void 0 : endpointDefinition.forceRefetch) == null ? void 0 : _a.call(endpointDefinition, {
|
|
1206
|
+
currentArg,
|
|
1207
|
+
previousArg,
|
|
1208
|
+
endpointState: requestState,
|
|
1209
|
+
state
|
|
1210
|
+
}))) {
|
|
1211
|
+
return true;
|
|
1212
|
+
}
|
|
1213
|
+
if (fulfilledVal && !direction) {
|
|
1214
|
+
return false;
|
|
1215
|
+
}
|
|
1216
|
+
return true;
|
|
1217
|
+
},
|
|
1218
|
+
dispatchConditionRejection: true
|
|
1219
|
+
});
|
|
1220
|
+
return generatedQueryThunk;
|
|
1221
|
+
};
|
|
1222
|
+
const queryThunk = createQueryThunk();
|
|
1223
|
+
const infiniteQueryThunk = createQueryThunk();
|
|
1224
|
+
const mutationThunk = createAsyncThunk(`${reducerPath}/executeMutation`, executeEndpoint, {
|
|
1225
|
+
getPendingMeta() {
|
|
1226
|
+
return addShouldAutoBatch({
|
|
1227
|
+
startedTimeStamp: Date.now()
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
});
|
|
1231
|
+
const hasTheForce = (options) => "force" in options;
|
|
1232
|
+
const hasMaxAge = (options) => "ifOlderThan" in options;
|
|
1233
|
+
const prefetch = (endpointName, arg, options = {}) => (dispatch, getState) => {
|
|
1234
|
+
const force = hasTheForce(options) && options.force;
|
|
1235
|
+
const maxAge = hasMaxAge(options) && options.ifOlderThan;
|
|
1236
|
+
const queryAction = (force2 = true) => {
|
|
1237
|
+
const options2 = {
|
|
1238
|
+
forceRefetch: force2,
|
|
1239
|
+
subscribe: false
|
|
1240
|
+
};
|
|
1241
|
+
return api.endpoints[endpointName].initiate(arg, options2);
|
|
1242
|
+
};
|
|
1243
|
+
const latestStateValue = api.endpoints[endpointName].select(arg)(getState());
|
|
1244
|
+
if (force) {
|
|
1245
|
+
dispatch(queryAction());
|
|
1246
|
+
} else if (maxAge) {
|
|
1247
|
+
const lastFulfilledTs = latestStateValue == null ? void 0 : latestStateValue.fulfilledTimeStamp;
|
|
1248
|
+
if (!lastFulfilledTs) {
|
|
1249
|
+
dispatch(queryAction());
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
const shouldRetrigger = (Number(/* @__PURE__ */ new Date()) - Number(new Date(lastFulfilledTs))) / 1e3 >= maxAge;
|
|
1253
|
+
if (shouldRetrigger) {
|
|
1254
|
+
dispatch(queryAction());
|
|
1255
|
+
}
|
|
1256
|
+
} else {
|
|
1257
|
+
dispatch(queryAction(false));
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
function matchesEndpoint(endpointName) {
|
|
1261
|
+
return (action) => {
|
|
1262
|
+
var _a, _b;
|
|
1263
|
+
return ((_b = (_a = action == null ? void 0 : action.meta) == null ? void 0 : _a.arg) == null ? void 0 : _b.endpointName) === endpointName;
|
|
1264
|
+
};
|
|
1265
|
+
}
|
|
1266
|
+
function buildMatchThunkActions(thunk, endpointName) {
|
|
1267
|
+
return {
|
|
1268
|
+
matchPending: isAllOf(isPending(thunk), matchesEndpoint(endpointName)),
|
|
1269
|
+
matchFulfilled: isAllOf(isFulfilled(thunk), matchesEndpoint(endpointName)),
|
|
1270
|
+
matchRejected: isAllOf(isRejected(thunk), matchesEndpoint(endpointName))
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
return {
|
|
1274
|
+
queryThunk,
|
|
1275
|
+
mutationThunk,
|
|
1276
|
+
infiniteQueryThunk,
|
|
1277
|
+
prefetch,
|
|
1278
|
+
updateQueryData,
|
|
1279
|
+
upsertQueryData,
|
|
1280
|
+
patchQueryData,
|
|
1281
|
+
buildMatchThunkActions
|
|
1282
|
+
};
|
|
1283
|
+
}
|
|
1284
|
+
function getNextPageParam(options, {
|
|
1285
|
+
pages,
|
|
1286
|
+
pageParams
|
|
1287
|
+
}, queryArg) {
|
|
1288
|
+
const lastIndex = pages.length - 1;
|
|
1289
|
+
return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams, queryArg);
|
|
1290
|
+
}
|
|
1291
|
+
function getPreviousPageParam(options, {
|
|
1292
|
+
pages,
|
|
1293
|
+
pageParams
|
|
1294
|
+
}, queryArg) {
|
|
1295
|
+
var _a;
|
|
1296
|
+
return (_a = options.getPreviousPageParam) == null ? void 0 : _a.call(options, pages[0], pages, pageParams[0], pageParams, queryArg);
|
|
1297
|
+
}
|
|
1298
|
+
function calculateProvidedByThunk(action, type, endpointDefinitions, assertTagType) {
|
|
1299
|
+
return calculateProvidedBy(endpointDefinitions[action.meta.arg.endpointName][type], isFulfilled(action) ? action.payload : void 0, isRejectedWithValue(action) ? action.payload : void 0, action.meta.arg.originalArgs, "baseQueryMeta" in action.meta ? action.meta.baseQueryMeta : void 0, assertTagType);
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
// src/query/utils/getCurrent.ts
|
|
1303
|
+
function getCurrent(value) {
|
|
1304
|
+
return isDraft(value) ? current(value) : value;
|
|
1305
|
+
}
|
|
1306
|
+
|
|
1307
|
+
// src/query/core/buildSlice.ts
|
|
1308
|
+
function updateQuerySubstateIfExists(state, queryCacheKey, update) {
|
|
1309
|
+
const substate = state[queryCacheKey];
|
|
1310
|
+
if (substate) {
|
|
1311
|
+
update(substate);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function getMutationCacheKey(id) {
|
|
1315
|
+
var _a;
|
|
1316
|
+
return (_a = "arg" in id ? id.arg.fixedCacheKey : id.fixedCacheKey) != null ? _a : id.requestId;
|
|
1317
|
+
}
|
|
1318
|
+
function updateMutationSubstateIfExists(state, id, update) {
|
|
1319
|
+
const substate = state[getMutationCacheKey(id)];
|
|
1320
|
+
if (substate) {
|
|
1321
|
+
update(substate);
|
|
1322
|
+
}
|
|
1323
|
+
}
|
|
1324
|
+
var initialState = {};
|
|
1325
|
+
function buildSlice({
|
|
1326
|
+
reducerPath,
|
|
1327
|
+
queryThunk,
|
|
1328
|
+
mutationThunk,
|
|
1329
|
+
serializeQueryArgs,
|
|
1330
|
+
context: {
|
|
1331
|
+
endpointDefinitions: definitions,
|
|
1332
|
+
apiUid,
|
|
1333
|
+
extractRehydrationInfo,
|
|
1334
|
+
hasRehydrationInfo
|
|
1335
|
+
},
|
|
1336
|
+
assertTagType,
|
|
1337
|
+
config
|
|
1338
|
+
}) {
|
|
1339
|
+
const resetApiState = createAction(`${reducerPath}/resetApiState`);
|
|
1340
|
+
function writePendingCacheEntry(draft, arg, upserting, meta) {
|
|
1341
|
+
var _a, _b;
|
|
1342
|
+
(_b = draft[_a = arg.queryCacheKey]) != null ? _b : draft[_a] = {
|
|
1343
|
+
status: STATUS_UNINITIALIZED,
|
|
1344
|
+
endpointName: arg.endpointName
|
|
1345
|
+
};
|
|
1346
|
+
updateQuerySubstateIfExists(draft, arg.queryCacheKey, (substate) => {
|
|
1347
|
+
substate.status = STATUS_PENDING;
|
|
1348
|
+
substate.requestId = upserting && substate.requestId ? (
|
|
1349
|
+
// for `upsertQuery` **updates**, keep the current `requestId`
|
|
1350
|
+
substate.requestId
|
|
1351
|
+
) : (
|
|
1352
|
+
// for normal queries or `upsertQuery` **inserts** always update the `requestId`
|
|
1353
|
+
meta.requestId
|
|
1354
|
+
);
|
|
1355
|
+
if (arg.originalArgs !== void 0) {
|
|
1356
|
+
substate.originalArgs = arg.originalArgs;
|
|
1357
|
+
}
|
|
1358
|
+
substate.startedTimeStamp = meta.startedTimeStamp;
|
|
1359
|
+
const endpointDefinition = definitions[meta.arg.endpointName];
|
|
1360
|
+
if (isInfiniteQueryDefinition(endpointDefinition) && "direction" in arg) {
|
|
1361
|
+
;
|
|
1362
|
+
substate.direction = arg.direction;
|
|
1363
|
+
}
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
function writeFulfilledCacheEntry(draft, meta, payload, upserting) {
|
|
1367
|
+
updateQuerySubstateIfExists(draft, meta.arg.queryCacheKey, (substate) => {
|
|
1368
|
+
var _a;
|
|
1369
|
+
if (substate.requestId !== meta.requestId && !upserting) return;
|
|
1370
|
+
const {
|
|
1371
|
+
merge
|
|
1372
|
+
} = definitions[meta.arg.endpointName];
|
|
1373
|
+
substate.status = STATUS_FULFILLED;
|
|
1374
|
+
if (merge) {
|
|
1375
|
+
if (substate.data !== void 0) {
|
|
1376
|
+
const {
|
|
1377
|
+
fulfilledTimeStamp,
|
|
1378
|
+
arg,
|
|
1379
|
+
baseQueryMeta,
|
|
1380
|
+
requestId
|
|
1381
|
+
} = meta;
|
|
1382
|
+
let newData = createNextState(substate.data, (draftSubstateData) => {
|
|
1383
|
+
return merge(draftSubstateData, payload, {
|
|
1384
|
+
arg: arg.originalArgs,
|
|
1385
|
+
baseQueryMeta,
|
|
1386
|
+
fulfilledTimeStamp,
|
|
1387
|
+
requestId
|
|
1388
|
+
});
|
|
1389
|
+
});
|
|
1390
|
+
substate.data = newData;
|
|
1391
|
+
} else {
|
|
1392
|
+
substate.data = payload;
|
|
1393
|
+
}
|
|
1394
|
+
} else {
|
|
1395
|
+
substate.data = ((_a = definitions[meta.arg.endpointName].structuralSharing) != null ? _a : true) ? copyWithStructuralSharing(isDraft(substate.data) ? original(substate.data) : substate.data, payload) : payload;
|
|
1396
|
+
}
|
|
1397
|
+
delete substate.error;
|
|
1398
|
+
substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
const querySlice = createSlice({
|
|
1402
|
+
name: `${reducerPath}/queries`,
|
|
1403
|
+
initialState,
|
|
1404
|
+
reducers: {
|
|
1405
|
+
removeQueryResult: {
|
|
1406
|
+
reducer(draft, {
|
|
1407
|
+
payload: {
|
|
1408
|
+
queryCacheKey
|
|
1409
|
+
}
|
|
1410
|
+
}) {
|
|
1411
|
+
delete draft[queryCacheKey];
|
|
1412
|
+
},
|
|
1413
|
+
prepare: prepareAutoBatched()
|
|
1414
|
+
},
|
|
1415
|
+
cacheEntriesUpserted: {
|
|
1416
|
+
reducer(draft, action) {
|
|
1417
|
+
for (const entry of action.payload) {
|
|
1418
|
+
const {
|
|
1419
|
+
queryDescription: arg,
|
|
1420
|
+
value
|
|
1421
|
+
} = entry;
|
|
1422
|
+
writePendingCacheEntry(draft, arg, true, {
|
|
1423
|
+
arg,
|
|
1424
|
+
requestId: action.meta.requestId,
|
|
1425
|
+
startedTimeStamp: action.meta.timestamp
|
|
1426
|
+
});
|
|
1427
|
+
writeFulfilledCacheEntry(
|
|
1428
|
+
draft,
|
|
1429
|
+
{
|
|
1430
|
+
arg,
|
|
1431
|
+
requestId: action.meta.requestId,
|
|
1432
|
+
fulfilledTimeStamp: action.meta.timestamp,
|
|
1433
|
+
baseQueryMeta: {}
|
|
1434
|
+
},
|
|
1435
|
+
value,
|
|
1436
|
+
// We know we're upserting here
|
|
1437
|
+
true
|
|
1438
|
+
);
|
|
1439
|
+
}
|
|
1440
|
+
},
|
|
1441
|
+
prepare: (payload) => {
|
|
1442
|
+
const queryDescriptions = payload.map((entry) => {
|
|
1443
|
+
const {
|
|
1444
|
+
endpointName,
|
|
1445
|
+
arg,
|
|
1446
|
+
value
|
|
1447
|
+
} = entry;
|
|
1448
|
+
const endpointDefinition = definitions[endpointName];
|
|
1449
|
+
const queryDescription = {
|
|
1450
|
+
type: ENDPOINT_QUERY,
|
|
1451
|
+
endpointName,
|
|
1452
|
+
originalArgs: entry.arg,
|
|
1453
|
+
queryCacheKey: serializeQueryArgs({
|
|
1454
|
+
queryArgs: arg,
|
|
1455
|
+
endpointDefinition,
|
|
1456
|
+
endpointName
|
|
1457
|
+
})
|
|
1458
|
+
};
|
|
1459
|
+
return {
|
|
1460
|
+
queryDescription,
|
|
1461
|
+
value
|
|
1462
|
+
};
|
|
1463
|
+
});
|
|
1464
|
+
const result = {
|
|
1465
|
+
payload: queryDescriptions,
|
|
1466
|
+
meta: {
|
|
1467
|
+
[SHOULD_AUTOBATCH]: true,
|
|
1468
|
+
requestId: nanoid(),
|
|
1469
|
+
timestamp: Date.now()
|
|
1470
|
+
}
|
|
1471
|
+
};
|
|
1472
|
+
return result;
|
|
1473
|
+
}
|
|
1474
|
+
},
|
|
1475
|
+
queryResultPatched: {
|
|
1476
|
+
reducer(draft, {
|
|
1477
|
+
payload: {
|
|
1478
|
+
queryCacheKey,
|
|
1479
|
+
patches
|
|
1480
|
+
}
|
|
1481
|
+
}) {
|
|
1482
|
+
updateQuerySubstateIfExists(draft, queryCacheKey, (substate) => {
|
|
1483
|
+
substate.data = applyPatches(substate.data, patches.concat());
|
|
1484
|
+
});
|
|
1485
|
+
},
|
|
1486
|
+
prepare: prepareAutoBatched()
|
|
1487
|
+
}
|
|
1488
|
+
},
|
|
1489
|
+
extraReducers(builder) {
|
|
1490
|
+
builder.addCase(queryThunk.pending, (draft, {
|
|
1491
|
+
meta,
|
|
1492
|
+
meta: {
|
|
1493
|
+
arg
|
|
1494
|
+
}
|
|
1495
|
+
}) => {
|
|
1496
|
+
const upserting = isUpsertQuery(arg);
|
|
1497
|
+
writePendingCacheEntry(draft, arg, upserting, meta);
|
|
1498
|
+
}).addCase(queryThunk.fulfilled, (draft, {
|
|
1499
|
+
meta,
|
|
1500
|
+
payload
|
|
1501
|
+
}) => {
|
|
1502
|
+
const upserting = isUpsertQuery(meta.arg);
|
|
1503
|
+
writeFulfilledCacheEntry(draft, meta, payload, upserting);
|
|
1504
|
+
}).addCase(queryThunk.rejected, (draft, {
|
|
1505
|
+
meta: {
|
|
1506
|
+
condition,
|
|
1507
|
+
arg,
|
|
1508
|
+
requestId
|
|
1509
|
+
},
|
|
1510
|
+
error,
|
|
1511
|
+
payload
|
|
1512
|
+
}) => {
|
|
1513
|
+
updateQuerySubstateIfExists(draft, arg.queryCacheKey, (substate) => {
|
|
1514
|
+
if (condition) {
|
|
1515
|
+
} else {
|
|
1516
|
+
if (substate.requestId !== requestId) return;
|
|
1517
|
+
substate.status = STATUS_REJECTED;
|
|
1518
|
+
substate.error = payload != null ? payload : error;
|
|
1519
|
+
}
|
|
1520
|
+
});
|
|
1521
|
+
}).addMatcher(hasRehydrationInfo, (draft, action) => {
|
|
1522
|
+
const {
|
|
1523
|
+
queries
|
|
1524
|
+
} = extractRehydrationInfo(action);
|
|
1525
|
+
for (const [key, entry] of Object.entries(queries)) {
|
|
1526
|
+
if (
|
|
1527
|
+
// do not rehydrate entries that were currently in flight.
|
|
1528
|
+
(entry == null ? void 0 : entry.status) === STATUS_FULFILLED || (entry == null ? void 0 : entry.status) === STATUS_REJECTED
|
|
1529
|
+
) {
|
|
1530
|
+
draft[key] = entry;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
});
|
|
1534
|
+
}
|
|
1535
|
+
});
|
|
1536
|
+
const mutationSlice = createSlice({
|
|
1537
|
+
name: `${reducerPath}/mutations`,
|
|
1538
|
+
initialState,
|
|
1539
|
+
reducers: {
|
|
1540
|
+
removeMutationResult: {
|
|
1541
|
+
reducer(draft, {
|
|
1542
|
+
payload
|
|
1543
|
+
}) {
|
|
1544
|
+
const cacheKey = getMutationCacheKey(payload);
|
|
1545
|
+
if (cacheKey in draft) {
|
|
1546
|
+
delete draft[cacheKey];
|
|
1547
|
+
}
|
|
1548
|
+
},
|
|
1549
|
+
prepare: prepareAutoBatched()
|
|
1550
|
+
}
|
|
1551
|
+
},
|
|
1552
|
+
extraReducers(builder) {
|
|
1553
|
+
builder.addCase(mutationThunk.pending, (draft, {
|
|
1554
|
+
meta,
|
|
1555
|
+
meta: {
|
|
1556
|
+
requestId,
|
|
1557
|
+
arg,
|
|
1558
|
+
startedTimeStamp
|
|
1559
|
+
}
|
|
1560
|
+
}) => {
|
|
1561
|
+
if (!arg.track) return;
|
|
1562
|
+
draft[getMutationCacheKey(meta)] = {
|
|
1563
|
+
requestId,
|
|
1564
|
+
status: STATUS_PENDING,
|
|
1565
|
+
endpointName: arg.endpointName,
|
|
1566
|
+
startedTimeStamp
|
|
1567
|
+
};
|
|
1568
|
+
}).addCase(mutationThunk.fulfilled, (draft, {
|
|
1569
|
+
payload,
|
|
1570
|
+
meta
|
|
1571
|
+
}) => {
|
|
1572
|
+
if (!meta.arg.track) return;
|
|
1573
|
+
updateMutationSubstateIfExists(draft, meta, (substate) => {
|
|
1574
|
+
if (substate.requestId !== meta.requestId) return;
|
|
1575
|
+
substate.status = STATUS_FULFILLED;
|
|
1576
|
+
substate.data = payload;
|
|
1577
|
+
substate.fulfilledTimeStamp = meta.fulfilledTimeStamp;
|
|
1578
|
+
});
|
|
1579
|
+
}).addCase(mutationThunk.rejected, (draft, {
|
|
1580
|
+
payload,
|
|
1581
|
+
error,
|
|
1582
|
+
meta
|
|
1583
|
+
}) => {
|
|
1584
|
+
if (!meta.arg.track) return;
|
|
1585
|
+
updateMutationSubstateIfExists(draft, meta, (substate) => {
|
|
1586
|
+
if (substate.requestId !== meta.requestId) return;
|
|
1587
|
+
substate.status = STATUS_REJECTED;
|
|
1588
|
+
substate.error = payload != null ? payload : error;
|
|
1589
|
+
});
|
|
1590
|
+
}).addMatcher(hasRehydrationInfo, (draft, action) => {
|
|
1591
|
+
const {
|
|
1592
|
+
mutations
|
|
1593
|
+
} = extractRehydrationInfo(action);
|
|
1594
|
+
for (const [key, entry] of Object.entries(mutations)) {
|
|
1595
|
+
if (
|
|
1596
|
+
// do not rehydrate entries that were currently in flight.
|
|
1597
|
+
((entry == null ? void 0 : entry.status) === STATUS_FULFILLED || (entry == null ? void 0 : entry.status) === STATUS_REJECTED) && // only rehydrate endpoints that were persisted using a `fixedCacheKey`
|
|
1598
|
+
key !== (entry == null ? void 0 : entry.requestId)
|
|
1599
|
+
) {
|
|
1600
|
+
draft[key] = entry;
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
});
|
|
1606
|
+
const initialInvalidationState = {
|
|
1607
|
+
tags: {},
|
|
1608
|
+
keys: {}
|
|
1609
|
+
};
|
|
1610
|
+
const invalidationSlice = createSlice({
|
|
1611
|
+
name: `${reducerPath}/invalidation`,
|
|
1612
|
+
initialState: initialInvalidationState,
|
|
1613
|
+
reducers: {
|
|
1614
|
+
updateProvidedBy: {
|
|
1615
|
+
reducer(draft, action) {
|
|
1616
|
+
var _a, _b, _c, _d, _e;
|
|
1617
|
+
for (const {
|
|
1618
|
+
queryCacheKey,
|
|
1619
|
+
providedTags
|
|
1620
|
+
} of action.payload) {
|
|
1621
|
+
removeCacheKeyFromTags(draft, queryCacheKey);
|
|
1622
|
+
for (const {
|
|
1623
|
+
type,
|
|
1624
|
+
id
|
|
1625
|
+
} of providedTags) {
|
|
1626
|
+
const subscribedQueries = (_e = (_c = (_b = (_a = draft.tags)[type]) != null ? _b : _a[type] = {})[_d = id || "__internal_without_id"]) != null ? _e : _c[_d] = [];
|
|
1627
|
+
const alreadySubscribed = subscribedQueries.includes(queryCacheKey);
|
|
1628
|
+
if (!alreadySubscribed) {
|
|
1629
|
+
subscribedQueries.push(queryCacheKey);
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
draft.keys[queryCacheKey] = providedTags;
|
|
1633
|
+
}
|
|
1634
|
+
},
|
|
1635
|
+
prepare: prepareAutoBatched()
|
|
1636
|
+
}
|
|
1637
|
+
},
|
|
1638
|
+
extraReducers(builder) {
|
|
1639
|
+
builder.addCase(querySlice.actions.removeQueryResult, (draft, {
|
|
1640
|
+
payload: {
|
|
1641
|
+
queryCacheKey
|
|
1642
|
+
}
|
|
1643
|
+
}) => {
|
|
1644
|
+
removeCacheKeyFromTags(draft, queryCacheKey);
|
|
1645
|
+
}).addMatcher(hasRehydrationInfo, (draft, action) => {
|
|
1646
|
+
var _a, _b, _c, _d, _e, _f;
|
|
1647
|
+
const {
|
|
1648
|
+
provided
|
|
1649
|
+
} = extractRehydrationInfo(action);
|
|
1650
|
+
for (const [type, incomingTags] of Object.entries((_a = provided.tags) != null ? _a : {})) {
|
|
1651
|
+
for (const [id, cacheKeys] of Object.entries(incomingTags)) {
|
|
1652
|
+
const subscribedQueries = (_f = (_d = (_c = (_b = draft.tags)[type]) != null ? _c : _b[type] = {})[_e = id || "__internal_without_id"]) != null ? _f : _d[_e] = [];
|
|
1653
|
+
for (const queryCacheKey of cacheKeys) {
|
|
1654
|
+
const alreadySubscribed = subscribedQueries.includes(queryCacheKey);
|
|
1655
|
+
if (!alreadySubscribed) {
|
|
1656
|
+
subscribedQueries.push(queryCacheKey);
|
|
1657
|
+
}
|
|
1658
|
+
draft.keys[queryCacheKey] = provided.keys[queryCacheKey];
|
|
1659
|
+
}
|
|
1660
|
+
}
|
|
1661
|
+
}
|
|
1662
|
+
}).addMatcher(isAnyOf(isFulfilled(queryThunk), isRejectedWithValue(queryThunk)), (draft, action) => {
|
|
1663
|
+
writeProvidedTagsForQueries(draft, [action]);
|
|
1664
|
+
}).addMatcher(querySlice.actions.cacheEntriesUpserted.match, (draft, action) => {
|
|
1665
|
+
const mockActions = action.payload.map(({
|
|
1666
|
+
queryDescription,
|
|
1667
|
+
value
|
|
1668
|
+
}) => {
|
|
1669
|
+
return {
|
|
1670
|
+
type: "UNKNOWN",
|
|
1671
|
+
payload: value,
|
|
1672
|
+
meta: {
|
|
1673
|
+
requestStatus: "fulfilled",
|
|
1674
|
+
requestId: "UNKNOWN",
|
|
1675
|
+
arg: queryDescription
|
|
1676
|
+
}
|
|
1677
|
+
};
|
|
1678
|
+
});
|
|
1679
|
+
writeProvidedTagsForQueries(draft, mockActions);
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
});
|
|
1683
|
+
function removeCacheKeyFromTags(draft, queryCacheKey) {
|
|
1684
|
+
var _a, _b, _c;
|
|
1685
|
+
const existingTags = getCurrent((_a = draft.keys[queryCacheKey]) != null ? _a : []);
|
|
1686
|
+
for (const tag of existingTags) {
|
|
1687
|
+
const tagType = tag.type;
|
|
1688
|
+
const tagId = (_b = tag.id) != null ? _b : "__internal_without_id";
|
|
1689
|
+
const tagSubscriptions = (_c = draft.tags[tagType]) == null ? void 0 : _c[tagId];
|
|
1690
|
+
if (tagSubscriptions) {
|
|
1691
|
+
draft.tags[tagType][tagId] = getCurrent(tagSubscriptions).filter((qc) => qc !== queryCacheKey);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
delete draft.keys[queryCacheKey];
|
|
1695
|
+
}
|
|
1696
|
+
function writeProvidedTagsForQueries(draft, actions3) {
|
|
1697
|
+
const providedByEntries = actions3.map((action) => {
|
|
1698
|
+
const providedTags = calculateProvidedByThunk(action, "providesTags", definitions, assertTagType);
|
|
1699
|
+
const {
|
|
1700
|
+
queryCacheKey
|
|
1701
|
+
} = action.meta.arg;
|
|
1702
|
+
return {
|
|
1703
|
+
queryCacheKey,
|
|
1704
|
+
providedTags
|
|
1705
|
+
};
|
|
1706
|
+
});
|
|
1707
|
+
invalidationSlice.caseReducers.updateProvidedBy(draft, invalidationSlice.actions.updateProvidedBy(providedByEntries));
|
|
1708
|
+
}
|
|
1709
|
+
const subscriptionSlice = createSlice({
|
|
1710
|
+
name: `${reducerPath}/subscriptions`,
|
|
1711
|
+
initialState,
|
|
1712
|
+
reducers: {
|
|
1713
|
+
updateSubscriptionOptions(d, a) {
|
|
1714
|
+
},
|
|
1715
|
+
unsubscribeQueryResult(d, a) {
|
|
1716
|
+
},
|
|
1717
|
+
internal_getRTKQSubscriptions() {
|
|
1718
|
+
}
|
|
1719
|
+
}
|
|
1720
|
+
});
|
|
1721
|
+
const internalSubscriptionsSlice = createSlice({
|
|
1722
|
+
name: `${reducerPath}/internalSubscriptions`,
|
|
1723
|
+
initialState,
|
|
1724
|
+
reducers: {
|
|
1725
|
+
subscriptionsUpdated: {
|
|
1726
|
+
reducer(state, action) {
|
|
1727
|
+
return applyPatches(state, action.payload);
|
|
1728
|
+
},
|
|
1729
|
+
prepare: prepareAutoBatched()
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
});
|
|
1733
|
+
const configSlice = createSlice({
|
|
1734
|
+
name: `${reducerPath}/config`,
|
|
1735
|
+
initialState: __spreadValues({
|
|
1736
|
+
online: isOnline(),
|
|
1737
|
+
focused: isDocumentVisible(),
|
|
1738
|
+
middlewareRegistered: false
|
|
1739
|
+
}, config),
|
|
1740
|
+
reducers: {
|
|
1741
|
+
middlewareRegistered(state, {
|
|
1742
|
+
payload
|
|
1743
|
+
}) {
|
|
1744
|
+
state.middlewareRegistered = state.middlewareRegistered === "conflict" || apiUid !== payload ? "conflict" : true;
|
|
1745
|
+
}
|
|
1746
|
+
},
|
|
1747
|
+
extraReducers: (builder) => {
|
|
1748
|
+
builder.addCase(onOnline, (state) => {
|
|
1749
|
+
state.online = true;
|
|
1750
|
+
}).addCase(onOffline, (state) => {
|
|
1751
|
+
state.online = false;
|
|
1752
|
+
}).addCase(onFocus, (state) => {
|
|
1753
|
+
state.focused = true;
|
|
1754
|
+
}).addCase(onFocusLost, (state) => {
|
|
1755
|
+
state.focused = false;
|
|
1756
|
+
}).addMatcher(hasRehydrationInfo, (draft) => __spreadValues({}, draft));
|
|
1757
|
+
}
|
|
1758
|
+
});
|
|
1759
|
+
const combinedReducer = combineReducers({
|
|
1760
|
+
queries: querySlice.reducer,
|
|
1761
|
+
mutations: mutationSlice.reducer,
|
|
1762
|
+
provided: invalidationSlice.reducer,
|
|
1763
|
+
subscriptions: internalSubscriptionsSlice.reducer,
|
|
1764
|
+
config: configSlice.reducer
|
|
1765
|
+
});
|
|
1766
|
+
const reducer = (state, action) => combinedReducer(resetApiState.match(action) ? void 0 : state, action);
|
|
1767
|
+
const actions2 = __spreadProps(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, configSlice.actions), querySlice.actions), subscriptionSlice.actions), internalSubscriptionsSlice.actions), mutationSlice.actions), invalidationSlice.actions), {
|
|
1768
|
+
resetApiState
|
|
1769
|
+
});
|
|
1770
|
+
return {
|
|
1771
|
+
reducer,
|
|
1772
|
+
actions: actions2
|
|
1773
|
+
};
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
// src/query/core/buildSelectors.ts
|
|
1777
|
+
var skipToken = /* @__PURE__ */ Symbol.for("RTKQ/skipToken");
|
|
1778
|
+
var initialSubState = {
|
|
1779
|
+
status: STATUS_UNINITIALIZED
|
|
1780
|
+
};
|
|
1781
|
+
var defaultQuerySubState = /* @__PURE__ */ createNextState(initialSubState, () => {
|
|
1782
|
+
});
|
|
1783
|
+
var defaultMutationSubState = /* @__PURE__ */ createNextState(initialSubState, () => {
|
|
1784
|
+
});
|
|
1785
|
+
function buildSelectors({
|
|
1786
|
+
serializeQueryArgs,
|
|
1787
|
+
reducerPath,
|
|
1788
|
+
createSelector: createSelector2
|
|
1789
|
+
}) {
|
|
1790
|
+
const selectSkippedQuery = (state) => defaultQuerySubState;
|
|
1791
|
+
const selectSkippedMutation = (state) => defaultMutationSubState;
|
|
1792
|
+
return {
|
|
1793
|
+
buildQuerySelector,
|
|
1794
|
+
buildInfiniteQuerySelector,
|
|
1795
|
+
buildMutationSelector,
|
|
1796
|
+
selectInvalidatedBy,
|
|
1797
|
+
selectCachedArgsForQuery,
|
|
1798
|
+
selectApiState,
|
|
1799
|
+
selectQueries,
|
|
1800
|
+
selectMutations,
|
|
1801
|
+
selectQueryEntry,
|
|
1802
|
+
selectConfig
|
|
1803
|
+
};
|
|
1804
|
+
function withRequestFlags(substate) {
|
|
1805
|
+
return __spreadValues(__spreadValues({}, substate), getRequestStatusFlags(substate.status));
|
|
1806
|
+
}
|
|
1807
|
+
function selectApiState(rootState) {
|
|
1808
|
+
const state = rootState[reducerPath];
|
|
1809
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1810
|
+
if (!state) {
|
|
1811
|
+
if (selectApiState.triggered) return state;
|
|
1812
|
+
selectApiState.triggered = true;
|
|
1813
|
+
console.error(`Error: No data found at \`state.${reducerPath}\`. Did you forget to add the reducer to the store?`);
|
|
1814
|
+
}
|
|
1815
|
+
}
|
|
1816
|
+
return state;
|
|
1817
|
+
}
|
|
1818
|
+
function selectQueries(rootState) {
|
|
1819
|
+
var _a;
|
|
1820
|
+
return (_a = selectApiState(rootState)) == null ? void 0 : _a.queries;
|
|
1821
|
+
}
|
|
1822
|
+
function selectQueryEntry(rootState, cacheKey) {
|
|
1823
|
+
var _a;
|
|
1824
|
+
return (_a = selectQueries(rootState)) == null ? void 0 : _a[cacheKey];
|
|
1825
|
+
}
|
|
1826
|
+
function selectMutations(rootState) {
|
|
1827
|
+
var _a;
|
|
1828
|
+
return (_a = selectApiState(rootState)) == null ? void 0 : _a.mutations;
|
|
1829
|
+
}
|
|
1830
|
+
function selectConfig(rootState) {
|
|
1831
|
+
var _a;
|
|
1832
|
+
return (_a = selectApiState(rootState)) == null ? void 0 : _a.config;
|
|
1833
|
+
}
|
|
1834
|
+
function buildAnyQuerySelector(endpointName, endpointDefinition, combiner) {
|
|
1835
|
+
return (queryArgs) => {
|
|
1836
|
+
if (queryArgs === skipToken) {
|
|
1837
|
+
return createSelector2(selectSkippedQuery, combiner);
|
|
1838
|
+
}
|
|
1839
|
+
const serializedArgs = serializeQueryArgs({
|
|
1840
|
+
queryArgs,
|
|
1841
|
+
endpointDefinition,
|
|
1842
|
+
endpointName
|
|
1843
|
+
});
|
|
1844
|
+
const selectQuerySubstate = (state) => {
|
|
1845
|
+
var _a;
|
|
1846
|
+
return (_a = selectQueryEntry(state, serializedArgs)) != null ? _a : defaultQuerySubState;
|
|
1847
|
+
};
|
|
1848
|
+
return createSelector2(selectQuerySubstate, combiner);
|
|
1849
|
+
};
|
|
1850
|
+
}
|
|
1851
|
+
function buildQuerySelector(endpointName, endpointDefinition) {
|
|
1852
|
+
return buildAnyQuerySelector(endpointName, endpointDefinition, withRequestFlags);
|
|
1853
|
+
}
|
|
1854
|
+
function buildInfiniteQuerySelector(endpointName, endpointDefinition) {
|
|
1855
|
+
const {
|
|
1856
|
+
infiniteQueryOptions
|
|
1857
|
+
} = endpointDefinition;
|
|
1858
|
+
function withInfiniteQueryResultFlags(substate) {
|
|
1859
|
+
const stateWithRequestFlags = __spreadValues(__spreadValues({}, substate), getRequestStatusFlags(substate.status));
|
|
1860
|
+
const {
|
|
1861
|
+
isLoading,
|
|
1862
|
+
isError,
|
|
1863
|
+
direction
|
|
1864
|
+
} = stateWithRequestFlags;
|
|
1865
|
+
const isForward = direction === "forward";
|
|
1866
|
+
const isBackward = direction === "backward";
|
|
1867
|
+
return __spreadProps(__spreadValues({}, stateWithRequestFlags), {
|
|
1868
|
+
hasNextPage: getHasNextPage(infiniteQueryOptions, stateWithRequestFlags.data, stateWithRequestFlags.originalArgs),
|
|
1869
|
+
hasPreviousPage: getHasPreviousPage(infiniteQueryOptions, stateWithRequestFlags.data, stateWithRequestFlags.originalArgs),
|
|
1870
|
+
isFetchingNextPage: isLoading && isForward,
|
|
1871
|
+
isFetchingPreviousPage: isLoading && isBackward,
|
|
1872
|
+
isFetchNextPageError: isError && isForward,
|
|
1873
|
+
isFetchPreviousPageError: isError && isBackward
|
|
1874
|
+
});
|
|
1875
|
+
}
|
|
1876
|
+
return buildAnyQuerySelector(endpointName, endpointDefinition, withInfiniteQueryResultFlags);
|
|
1877
|
+
}
|
|
1878
|
+
function buildMutationSelector() {
|
|
1879
|
+
return ((id) => {
|
|
1880
|
+
var _a;
|
|
1881
|
+
let mutationId;
|
|
1882
|
+
if (typeof id === "object") {
|
|
1883
|
+
mutationId = (_a = getMutationCacheKey(id)) != null ? _a : skipToken;
|
|
1884
|
+
} else {
|
|
1885
|
+
mutationId = id;
|
|
1886
|
+
}
|
|
1887
|
+
const selectMutationSubstate = (state) => {
|
|
1888
|
+
var _a2, _b, _c;
|
|
1889
|
+
return (_c = (_b = (_a2 = selectApiState(state)) == null ? void 0 : _a2.mutations) == null ? void 0 : _b[mutationId]) != null ? _c : defaultMutationSubState;
|
|
1890
|
+
};
|
|
1891
|
+
const finalSelectMutationSubstate = mutationId === skipToken ? selectSkippedMutation : selectMutationSubstate;
|
|
1892
|
+
return createSelector2(finalSelectMutationSubstate, withRequestFlags);
|
|
1893
|
+
});
|
|
1894
|
+
}
|
|
1895
|
+
function selectInvalidatedBy(state, tags) {
|
|
1896
|
+
var _a;
|
|
1897
|
+
const apiState = state[reducerPath];
|
|
1898
|
+
const toInvalidate = /* @__PURE__ */ new Set();
|
|
1899
|
+
const finalTags = filterMap(tags, isNotNullish, expandTagDescription);
|
|
1900
|
+
for (const tag of finalTags) {
|
|
1901
|
+
const provided = apiState.provided.tags[tag.type];
|
|
1902
|
+
if (!provided) {
|
|
1903
|
+
continue;
|
|
1904
|
+
}
|
|
1905
|
+
let invalidateSubscriptions = (_a = tag.id !== void 0 ? (
|
|
1906
|
+
// id given: invalidate all queries that provide this type & id
|
|
1907
|
+
provided[tag.id]
|
|
1908
|
+
) : (
|
|
1909
|
+
// no id: invalidate all queries that provide this type
|
|
1910
|
+
Object.values(provided).flat()
|
|
1911
|
+
)) != null ? _a : [];
|
|
1912
|
+
for (const invalidate of invalidateSubscriptions) {
|
|
1913
|
+
toInvalidate.add(invalidate);
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
return Array.from(toInvalidate.values()).flatMap((queryCacheKey) => {
|
|
1917
|
+
const querySubState = apiState.queries[queryCacheKey];
|
|
1918
|
+
return querySubState ? {
|
|
1919
|
+
queryCacheKey,
|
|
1920
|
+
endpointName: querySubState.endpointName,
|
|
1921
|
+
originalArgs: querySubState.originalArgs
|
|
1922
|
+
} : [];
|
|
1923
|
+
});
|
|
1924
|
+
}
|
|
1925
|
+
function selectCachedArgsForQuery(state, queryName) {
|
|
1926
|
+
return filterMap(Object.values(selectQueries(state)), (entry) => (entry == null ? void 0 : entry.endpointName) === queryName && entry.status !== STATUS_UNINITIALIZED, (entry) => entry.originalArgs);
|
|
1927
|
+
}
|
|
1928
|
+
function getHasNextPage(options, data, queryArg) {
|
|
1929
|
+
if (!data) return false;
|
|
1930
|
+
return getNextPageParam(options, data, queryArg) != null;
|
|
1931
|
+
}
|
|
1932
|
+
function getHasPreviousPage(options, data, queryArg) {
|
|
1933
|
+
if (!data || !options.getPreviousPageParam) return false;
|
|
1934
|
+
return getPreviousPageParam(options, data, queryArg) != null;
|
|
1935
|
+
}
|
|
1936
|
+
}
|
|
1937
|
+
|
|
1938
|
+
// src/query/createApi.ts
|
|
1939
|
+
import { formatProdErrorMessage as _formatProdErrorMessage2, formatProdErrorMessage as _formatProdErrorMessage22, formatProdErrorMessage as _formatProdErrorMessage3 } from "@reduxjs/toolkit";
|
|
1940
|
+
import { weakMapMemoize } from "reselect";
|
|
1941
|
+
|
|
1942
|
+
// src/query/defaultSerializeQueryArgs.ts
|
|
1943
|
+
var cache = WeakMap ? /* @__PURE__ */ new WeakMap() : void 0;
|
|
1944
|
+
var defaultSerializeQueryArgs = ({
|
|
1945
|
+
endpointName,
|
|
1946
|
+
queryArgs
|
|
1947
|
+
}) => {
|
|
1948
|
+
let serialized = "";
|
|
1949
|
+
const cached = cache == null ? void 0 : cache.get(queryArgs);
|
|
1950
|
+
if (typeof cached === "string") {
|
|
1951
|
+
serialized = cached;
|
|
1952
|
+
} else {
|
|
1953
|
+
const stringified = JSON.stringify(queryArgs, (key, value) => {
|
|
1954
|
+
value = typeof value === "bigint" ? {
|
|
1955
|
+
$bigint: value.toString()
|
|
1956
|
+
} : value;
|
|
1957
|
+
value = isPlainObject(value) ? Object.keys(value).sort().reduce((acc, key2) => {
|
|
1958
|
+
acc[key2] = value[key2];
|
|
1959
|
+
return acc;
|
|
1960
|
+
}, {}) : value;
|
|
1961
|
+
return value;
|
|
1962
|
+
});
|
|
1963
|
+
if (isPlainObject(queryArgs)) {
|
|
1964
|
+
cache == null ? void 0 : cache.set(queryArgs, stringified);
|
|
1965
|
+
}
|
|
1966
|
+
serialized = stringified;
|
|
1967
|
+
}
|
|
1968
|
+
return `${endpointName}(${serialized})`;
|
|
1969
|
+
};
|
|
1970
|
+
|
|
1971
|
+
// src/query/createApi.ts
|
|
1972
|
+
function buildCreateApi(...modules) {
|
|
1973
|
+
return function baseCreateApi(options) {
|
|
1974
|
+
const extractRehydrationInfo = weakMapMemoize((action) => {
|
|
1975
|
+
var _a, _b;
|
|
1976
|
+
return (_b = options.extractRehydrationInfo) == null ? void 0 : _b.call(options, action, {
|
|
1977
|
+
reducerPath: (_a = options.reducerPath) != null ? _a : "api"
|
|
1978
|
+
});
|
|
1979
|
+
});
|
|
1980
|
+
const optionsWithDefaults = __spreadProps(__spreadValues({
|
|
1981
|
+
reducerPath: "api",
|
|
1982
|
+
keepUnusedDataFor: 60,
|
|
1983
|
+
refetchOnMountOrArgChange: false,
|
|
1984
|
+
refetchOnFocus: false,
|
|
1985
|
+
refetchOnReconnect: false,
|
|
1986
|
+
invalidationBehavior: "delayed"
|
|
1987
|
+
}, options), {
|
|
1988
|
+
extractRehydrationInfo,
|
|
1989
|
+
serializeQueryArgs(queryArgsApi) {
|
|
1990
|
+
let finalSerializeQueryArgs = defaultSerializeQueryArgs;
|
|
1991
|
+
if ("serializeQueryArgs" in queryArgsApi.endpointDefinition) {
|
|
1992
|
+
const endpointSQA = queryArgsApi.endpointDefinition.serializeQueryArgs;
|
|
1993
|
+
finalSerializeQueryArgs = (queryArgsApi2) => {
|
|
1994
|
+
const initialResult = endpointSQA(queryArgsApi2);
|
|
1995
|
+
if (typeof initialResult === "string") {
|
|
1996
|
+
return initialResult;
|
|
1997
|
+
} else {
|
|
1998
|
+
return defaultSerializeQueryArgs(__spreadProps(__spreadValues({}, queryArgsApi2), {
|
|
1999
|
+
queryArgs: initialResult
|
|
2000
|
+
}));
|
|
2001
|
+
}
|
|
2002
|
+
};
|
|
2003
|
+
} else if (options.serializeQueryArgs) {
|
|
2004
|
+
finalSerializeQueryArgs = options.serializeQueryArgs;
|
|
2005
|
+
}
|
|
2006
|
+
return finalSerializeQueryArgs(queryArgsApi);
|
|
2007
|
+
},
|
|
2008
|
+
tagTypes: [...options.tagTypes || []]
|
|
2009
|
+
});
|
|
2010
|
+
const context = {
|
|
2011
|
+
endpointDefinitions: {},
|
|
2012
|
+
batch(fn) {
|
|
2013
|
+
fn();
|
|
2014
|
+
},
|
|
2015
|
+
apiUid: nanoid(),
|
|
2016
|
+
extractRehydrationInfo,
|
|
2017
|
+
hasRehydrationInfo: weakMapMemoize((action) => extractRehydrationInfo(action) != null)
|
|
2018
|
+
};
|
|
2019
|
+
const api = {
|
|
2020
|
+
injectEndpoints,
|
|
2021
|
+
enhanceEndpoints({
|
|
2022
|
+
addTagTypes,
|
|
2023
|
+
endpoints
|
|
2024
|
+
}) {
|
|
2025
|
+
if (addTagTypes) {
|
|
2026
|
+
for (const eT of addTagTypes) {
|
|
2027
|
+
if (!optionsWithDefaults.tagTypes.includes(eT)) {
|
|
2028
|
+
;
|
|
2029
|
+
optionsWithDefaults.tagTypes.push(eT);
|
|
2030
|
+
}
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
if (endpoints) {
|
|
2034
|
+
for (const [endpointName, partialDefinition] of Object.entries(endpoints)) {
|
|
2035
|
+
if (typeof partialDefinition === "function") {
|
|
2036
|
+
partialDefinition(getEndpointDefinition(context, endpointName));
|
|
2037
|
+
} else {
|
|
2038
|
+
Object.assign(getEndpointDefinition(context, endpointName) || {}, partialDefinition);
|
|
2039
|
+
}
|
|
2040
|
+
}
|
|
2041
|
+
}
|
|
2042
|
+
return api;
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
const initializedModules = modules.map((m) => m.init(api, optionsWithDefaults, context));
|
|
2046
|
+
function injectEndpoints(inject) {
|
|
2047
|
+
const evaluatedEndpoints = inject.endpoints({
|
|
2048
|
+
query: (x) => __spreadProps(__spreadValues({}, x), {
|
|
2049
|
+
type: ENDPOINT_QUERY
|
|
2050
|
+
}),
|
|
2051
|
+
mutation: (x) => __spreadProps(__spreadValues({}, x), {
|
|
2052
|
+
type: ENDPOINT_MUTATION
|
|
2053
|
+
}),
|
|
2054
|
+
infiniteQuery: (x) => __spreadProps(__spreadValues({}, x), {
|
|
2055
|
+
type: ENDPOINT_INFINITEQUERY
|
|
2056
|
+
})
|
|
2057
|
+
});
|
|
2058
|
+
for (const [endpointName, definition] of Object.entries(evaluatedEndpoints)) {
|
|
2059
|
+
if (inject.overrideExisting !== true && endpointName in context.endpointDefinitions) {
|
|
2060
|
+
if (inject.overrideExisting === "throw") {
|
|
2061
|
+
throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage2(39) : `called \`injectEndpoints\` to override already-existing endpointName ${endpointName} without specifying \`overrideExisting: true\``);
|
|
2062
|
+
} else if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
2063
|
+
console.error(`called \`injectEndpoints\` to override already-existing endpointName ${endpointName} without specifying \`overrideExisting: true\``);
|
|
2064
|
+
}
|
|
2065
|
+
continue;
|
|
2066
|
+
}
|
|
2067
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
2068
|
+
if (isInfiniteQueryDefinition(definition)) {
|
|
2069
|
+
const {
|
|
2070
|
+
infiniteQueryOptions
|
|
2071
|
+
} = definition;
|
|
2072
|
+
const {
|
|
2073
|
+
maxPages,
|
|
2074
|
+
getPreviousPageParam: getPreviousPageParam2
|
|
2075
|
+
} = infiniteQueryOptions;
|
|
2076
|
+
if (typeof maxPages === "number") {
|
|
2077
|
+
if (maxPages < 1) {
|
|
2078
|
+
throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage22(40) : `maxPages for endpoint '${endpointName}' must be a number greater than 0`);
|
|
2079
|
+
}
|
|
2080
|
+
if (typeof getPreviousPageParam2 !== "function") {
|
|
2081
|
+
throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage3(41) : `getPreviousPageParam for endpoint '${endpointName}' must be a function if maxPages is used`);
|
|
2082
|
+
}
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
}
|
|
2086
|
+
context.endpointDefinitions[endpointName] = definition;
|
|
2087
|
+
for (const m of initializedModules) {
|
|
2088
|
+
m.injectEndpoint(endpointName, definition);
|
|
2089
|
+
}
|
|
2090
|
+
}
|
|
2091
|
+
return api;
|
|
2092
|
+
}
|
|
2093
|
+
return api.injectEndpoints({
|
|
2094
|
+
endpoints: options.endpoints
|
|
2095
|
+
});
|
|
2096
|
+
};
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
// src/query/fakeBaseQuery.ts
|
|
2100
|
+
import { formatProdErrorMessage as _formatProdErrorMessage4 } from "@reduxjs/toolkit";
|
|
2101
|
+
var _NEVER = /* @__PURE__ */ Symbol();
|
|
2102
|
+
function fakeBaseQuery() {
|
|
2103
|
+
return function() {
|
|
2104
|
+
throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage4(33) : "When using `fakeBaseQuery`, all queries & mutations must use the `queryFn` definition syntax.");
|
|
2105
|
+
};
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
// src/query/tsHelpers.ts
|
|
2109
|
+
function assertCast(v) {
|
|
2110
|
+
}
|
|
2111
|
+
function safeAssign(target, ...args) {
|
|
2112
|
+
return Object.assign(target, ...args);
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
// src/query/core/buildMiddleware/batchActions.ts
|
|
2116
|
+
var buildBatchedActionsHandler = ({
|
|
2117
|
+
api,
|
|
2118
|
+
queryThunk,
|
|
2119
|
+
internalState,
|
|
2120
|
+
mwApi
|
|
2121
|
+
}) => {
|
|
2122
|
+
const subscriptionsPrefix = `${api.reducerPath}/subscriptions`;
|
|
2123
|
+
let previousSubscriptions = null;
|
|
2124
|
+
let updateSyncTimer = null;
|
|
2125
|
+
const {
|
|
2126
|
+
updateSubscriptionOptions,
|
|
2127
|
+
unsubscribeQueryResult
|
|
2128
|
+
} = api.internalActions;
|
|
2129
|
+
const actuallyMutateSubscriptions = (currentSubscriptions, action) => {
|
|
2130
|
+
var _a, _b, _c, _d;
|
|
2131
|
+
if (updateSubscriptionOptions.match(action)) {
|
|
2132
|
+
const {
|
|
2133
|
+
queryCacheKey,
|
|
2134
|
+
requestId,
|
|
2135
|
+
options
|
|
2136
|
+
} = action.payload;
|
|
2137
|
+
const sub = currentSubscriptions.get(queryCacheKey);
|
|
2138
|
+
if (sub == null ? void 0 : sub.has(requestId)) {
|
|
2139
|
+
sub.set(requestId, options);
|
|
2140
|
+
}
|
|
2141
|
+
return true;
|
|
2142
|
+
}
|
|
2143
|
+
if (unsubscribeQueryResult.match(action)) {
|
|
2144
|
+
const {
|
|
2145
|
+
queryCacheKey,
|
|
2146
|
+
requestId
|
|
2147
|
+
} = action.payload;
|
|
2148
|
+
const sub = currentSubscriptions.get(queryCacheKey);
|
|
2149
|
+
if (sub) {
|
|
2150
|
+
sub.delete(requestId);
|
|
2151
|
+
}
|
|
2152
|
+
return true;
|
|
2153
|
+
}
|
|
2154
|
+
if (api.internalActions.removeQueryResult.match(action)) {
|
|
2155
|
+
currentSubscriptions.delete(action.payload.queryCacheKey);
|
|
2156
|
+
return true;
|
|
2157
|
+
}
|
|
2158
|
+
if (queryThunk.pending.match(action)) {
|
|
2159
|
+
const {
|
|
2160
|
+
meta: {
|
|
2161
|
+
arg,
|
|
2162
|
+
requestId
|
|
2163
|
+
}
|
|
2164
|
+
} = action;
|
|
2165
|
+
const substate = getOrInsertComputed(currentSubscriptions, arg.queryCacheKey, createNewMap);
|
|
2166
|
+
if (arg.subscribe) {
|
|
2167
|
+
substate.set(requestId, (_b = (_a = arg.subscriptionOptions) != null ? _a : substate.get(requestId)) != null ? _b : {});
|
|
2168
|
+
}
|
|
2169
|
+
return true;
|
|
2170
|
+
}
|
|
2171
|
+
let mutated = false;
|
|
2172
|
+
if (queryThunk.rejected.match(action)) {
|
|
2173
|
+
const {
|
|
2174
|
+
meta: {
|
|
2175
|
+
condition,
|
|
2176
|
+
arg,
|
|
2177
|
+
requestId
|
|
2178
|
+
}
|
|
2179
|
+
} = action;
|
|
2180
|
+
if (condition && arg.subscribe) {
|
|
2181
|
+
const substate = getOrInsertComputed(currentSubscriptions, arg.queryCacheKey, createNewMap);
|
|
2182
|
+
substate.set(requestId, (_d = (_c = arg.subscriptionOptions) != null ? _c : substate.get(requestId)) != null ? _d : {});
|
|
2183
|
+
mutated = true;
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
return mutated;
|
|
2187
|
+
};
|
|
2188
|
+
const getSubscriptions = () => internalState.currentSubscriptions;
|
|
2189
|
+
const getSubscriptionCount = (queryCacheKey) => {
|
|
2190
|
+
var _a;
|
|
2191
|
+
const subscriptions = getSubscriptions();
|
|
2192
|
+
const subscriptionsForQueryArg = subscriptions.get(queryCacheKey);
|
|
2193
|
+
return (_a = subscriptionsForQueryArg == null ? void 0 : subscriptionsForQueryArg.size) != null ? _a : 0;
|
|
2194
|
+
};
|
|
2195
|
+
const isRequestSubscribed = (queryCacheKey, requestId) => {
|
|
2196
|
+
var _a;
|
|
2197
|
+
const subscriptions = getSubscriptions();
|
|
2198
|
+
return !!((_a = subscriptions == null ? void 0 : subscriptions.get(queryCacheKey)) == null ? void 0 : _a.get(requestId));
|
|
2199
|
+
};
|
|
2200
|
+
const subscriptionSelectors = {
|
|
2201
|
+
getSubscriptions,
|
|
2202
|
+
getSubscriptionCount,
|
|
2203
|
+
isRequestSubscribed
|
|
2204
|
+
};
|
|
2205
|
+
function serializeSubscriptions(currentSubscriptions) {
|
|
2206
|
+
return JSON.parse(JSON.stringify(Object.fromEntries([...currentSubscriptions].map(([k, v]) => [k, Object.fromEntries(v)]))));
|
|
2207
|
+
}
|
|
2208
|
+
return (action, mwApi2) => {
|
|
2209
|
+
if (!previousSubscriptions) {
|
|
2210
|
+
previousSubscriptions = serializeSubscriptions(internalState.currentSubscriptions);
|
|
2211
|
+
}
|
|
2212
|
+
if (api.util.resetApiState.match(action)) {
|
|
2213
|
+
previousSubscriptions = {};
|
|
2214
|
+
internalState.currentSubscriptions.clear();
|
|
2215
|
+
updateSyncTimer = null;
|
|
2216
|
+
return [true, false];
|
|
2217
|
+
}
|
|
2218
|
+
if (api.internalActions.internal_getRTKQSubscriptions.match(action)) {
|
|
2219
|
+
return [false, subscriptionSelectors];
|
|
2220
|
+
}
|
|
2221
|
+
const didMutate = actuallyMutateSubscriptions(internalState.currentSubscriptions, action);
|
|
2222
|
+
let actionShouldContinue = true;
|
|
2223
|
+
if (process.env.NODE_ENV === "test" && typeof action.type === "string" && action.type === `${api.reducerPath}/getPolling`) {
|
|
2224
|
+
return [false, internalState.currentPolls];
|
|
2225
|
+
}
|
|
2226
|
+
if (didMutate) {
|
|
2227
|
+
if (!updateSyncTimer) {
|
|
2228
|
+
updateSyncTimer = setTimeout(() => {
|
|
2229
|
+
const newSubscriptions = serializeSubscriptions(internalState.currentSubscriptions);
|
|
2230
|
+
const [, patches] = produceWithPatches(previousSubscriptions, () => newSubscriptions);
|
|
2231
|
+
mwApi2.next(api.internalActions.subscriptionsUpdated(patches));
|
|
2232
|
+
previousSubscriptions = newSubscriptions;
|
|
2233
|
+
updateSyncTimer = null;
|
|
2234
|
+
}, 500);
|
|
2235
|
+
}
|
|
2236
|
+
const isSubscriptionSliceAction = typeof action.type == "string" && !!action.type.startsWith(subscriptionsPrefix);
|
|
2237
|
+
const isAdditionalSubscriptionAction = queryThunk.rejected.match(action) && action.meta.condition && !!action.meta.arg.subscribe;
|
|
2238
|
+
actionShouldContinue = !isSubscriptionSliceAction && !isAdditionalSubscriptionAction;
|
|
2239
|
+
}
|
|
2240
|
+
return [actionShouldContinue, false];
|
|
2241
|
+
};
|
|
2242
|
+
};
|
|
2243
|
+
|
|
2244
|
+
// src/query/core/buildMiddleware/cacheCollection.ts
|
|
2245
|
+
var THIRTY_TWO_BIT_MAX_TIMER_SECONDS = 2147483647 / 1e3 - 1;
|
|
2246
|
+
var buildCacheCollectionHandler = ({
|
|
2247
|
+
reducerPath,
|
|
2248
|
+
api,
|
|
2249
|
+
queryThunk,
|
|
2250
|
+
context,
|
|
2251
|
+
internalState,
|
|
2252
|
+
selectors: {
|
|
2253
|
+
selectQueryEntry,
|
|
2254
|
+
selectConfig
|
|
2255
|
+
},
|
|
2256
|
+
getRunningQueryThunk,
|
|
2257
|
+
mwApi
|
|
2258
|
+
}) => {
|
|
2259
|
+
const {
|
|
2260
|
+
removeQueryResult,
|
|
2261
|
+
unsubscribeQueryResult,
|
|
2262
|
+
cacheEntriesUpserted
|
|
2263
|
+
} = api.internalActions;
|
|
2264
|
+
const canTriggerUnsubscribe = isAnyOf(unsubscribeQueryResult.match, queryThunk.fulfilled, queryThunk.rejected, cacheEntriesUpserted.match);
|
|
2265
|
+
function anySubscriptionsRemainingForKey(queryCacheKey) {
|
|
2266
|
+
const subscriptions = internalState.currentSubscriptions.get(queryCacheKey);
|
|
2267
|
+
if (!subscriptions) {
|
|
2268
|
+
return false;
|
|
2269
|
+
}
|
|
2270
|
+
const hasSubscriptions = subscriptions.size > 0;
|
|
2271
|
+
return hasSubscriptions;
|
|
2272
|
+
}
|
|
2273
|
+
const currentRemovalTimeouts = {};
|
|
2274
|
+
function abortAllPromises(promiseMap) {
|
|
2275
|
+
var _a;
|
|
2276
|
+
for (const promise of promiseMap.values()) {
|
|
2277
|
+
(_a = promise == null ? void 0 : promise.abort) == null ? void 0 : _a.call(promise);
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
const handler = (action, mwApi2) => {
|
|
2281
|
+
const state = mwApi2.getState();
|
|
2282
|
+
const config = selectConfig(state);
|
|
2283
|
+
if (canTriggerUnsubscribe(action)) {
|
|
2284
|
+
let queryCacheKeys;
|
|
2285
|
+
if (cacheEntriesUpserted.match(action)) {
|
|
2286
|
+
queryCacheKeys = action.payload.map((entry) => entry.queryDescription.queryCacheKey);
|
|
2287
|
+
} else {
|
|
2288
|
+
const {
|
|
2289
|
+
queryCacheKey
|
|
2290
|
+
} = unsubscribeQueryResult.match(action) ? action.payload : action.meta.arg;
|
|
2291
|
+
queryCacheKeys = [queryCacheKey];
|
|
2292
|
+
}
|
|
2293
|
+
handleUnsubscribeMany(queryCacheKeys, mwApi2, config);
|
|
2294
|
+
}
|
|
2295
|
+
if (api.util.resetApiState.match(action)) {
|
|
2296
|
+
for (const [key, timeout] of Object.entries(currentRemovalTimeouts)) {
|
|
2297
|
+
if (timeout) clearTimeout(timeout);
|
|
2298
|
+
delete currentRemovalTimeouts[key];
|
|
2299
|
+
}
|
|
2300
|
+
abortAllPromises(internalState.runningQueries);
|
|
2301
|
+
abortAllPromises(internalState.runningMutations);
|
|
2302
|
+
}
|
|
2303
|
+
if (context.hasRehydrationInfo(action)) {
|
|
2304
|
+
const {
|
|
2305
|
+
queries
|
|
2306
|
+
} = context.extractRehydrationInfo(action);
|
|
2307
|
+
handleUnsubscribeMany(Object.keys(queries), mwApi2, config);
|
|
2308
|
+
}
|
|
2309
|
+
};
|
|
2310
|
+
function handleUnsubscribeMany(cacheKeys, api2, config) {
|
|
2311
|
+
const state = api2.getState();
|
|
2312
|
+
for (const queryCacheKey of cacheKeys) {
|
|
2313
|
+
const entry = selectQueryEntry(state, queryCacheKey);
|
|
2314
|
+
if (entry == null ? void 0 : entry.endpointName) {
|
|
2315
|
+
handleUnsubscribe(queryCacheKey, entry.endpointName, api2, config);
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
}
|
|
2319
|
+
function handleUnsubscribe(queryCacheKey, endpointName, api2, config) {
|
|
2320
|
+
var _a;
|
|
2321
|
+
const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|
2322
|
+
const keepUnusedDataFor = (_a = endpointDefinition == null ? void 0 : endpointDefinition.keepUnusedDataFor) != null ? _a : config.keepUnusedDataFor;
|
|
2323
|
+
if (keepUnusedDataFor === Infinity) {
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
const finalKeepUnusedDataFor = Math.max(0, Math.min(keepUnusedDataFor, THIRTY_TWO_BIT_MAX_TIMER_SECONDS));
|
|
2327
|
+
if (!anySubscriptionsRemainingForKey(queryCacheKey)) {
|
|
2328
|
+
const currentTimeout = currentRemovalTimeouts[queryCacheKey];
|
|
2329
|
+
if (currentTimeout) {
|
|
2330
|
+
clearTimeout(currentTimeout);
|
|
2331
|
+
}
|
|
2332
|
+
currentRemovalTimeouts[queryCacheKey] = setTimeout(() => {
|
|
2333
|
+
if (!anySubscriptionsRemainingForKey(queryCacheKey)) {
|
|
2334
|
+
const entry = selectQueryEntry(api2.getState(), queryCacheKey);
|
|
2335
|
+
if (entry == null ? void 0 : entry.endpointName) {
|
|
2336
|
+
const runningQuery = api2.dispatch(getRunningQueryThunk(entry.endpointName, entry.originalArgs));
|
|
2337
|
+
runningQuery == null ? void 0 : runningQuery.abort();
|
|
2338
|
+
}
|
|
2339
|
+
api2.dispatch(removeQueryResult({
|
|
2340
|
+
queryCacheKey
|
|
2341
|
+
}));
|
|
2342
|
+
}
|
|
2343
|
+
delete currentRemovalTimeouts[queryCacheKey];
|
|
2344
|
+
}, finalKeepUnusedDataFor * 1e3);
|
|
2345
|
+
}
|
|
2346
|
+
}
|
|
2347
|
+
return handler;
|
|
2348
|
+
};
|
|
2349
|
+
|
|
2350
|
+
// src/query/core/buildMiddleware/cacheLifecycle.ts
|
|
2351
|
+
var neverResolvedError = new Error("Promise never resolved before cacheEntryRemoved.");
|
|
2352
|
+
var buildCacheLifecycleHandler = ({
|
|
2353
|
+
api,
|
|
2354
|
+
reducerPath,
|
|
2355
|
+
context,
|
|
2356
|
+
queryThunk,
|
|
2357
|
+
mutationThunk,
|
|
2358
|
+
internalState,
|
|
2359
|
+
selectors: {
|
|
2360
|
+
selectQueryEntry,
|
|
2361
|
+
selectApiState
|
|
2362
|
+
}
|
|
2363
|
+
}) => {
|
|
2364
|
+
const isQueryThunk = isAsyncThunkAction(queryThunk);
|
|
2365
|
+
const isMutationThunk = isAsyncThunkAction(mutationThunk);
|
|
2366
|
+
const isFulfilledThunk = isFulfilled(queryThunk, mutationThunk);
|
|
2367
|
+
const lifecycleMap = {};
|
|
2368
|
+
const {
|
|
2369
|
+
removeQueryResult,
|
|
2370
|
+
removeMutationResult,
|
|
2371
|
+
cacheEntriesUpserted
|
|
2372
|
+
} = api.internalActions;
|
|
2373
|
+
function resolveLifecycleEntry(cacheKey, data, meta) {
|
|
2374
|
+
const lifecycle = lifecycleMap[cacheKey];
|
|
2375
|
+
if (lifecycle == null ? void 0 : lifecycle.valueResolved) {
|
|
2376
|
+
lifecycle.valueResolved({
|
|
2377
|
+
data,
|
|
2378
|
+
meta
|
|
2379
|
+
});
|
|
2380
|
+
delete lifecycle.valueResolved;
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
function removeLifecycleEntry(cacheKey) {
|
|
2384
|
+
const lifecycle = lifecycleMap[cacheKey];
|
|
2385
|
+
if (lifecycle) {
|
|
2386
|
+
delete lifecycleMap[cacheKey];
|
|
2387
|
+
lifecycle.cacheEntryRemoved();
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
function getActionMetaFields(action) {
|
|
2391
|
+
const {
|
|
2392
|
+
arg,
|
|
2393
|
+
requestId
|
|
2394
|
+
} = action.meta;
|
|
2395
|
+
const {
|
|
2396
|
+
endpointName,
|
|
2397
|
+
originalArgs
|
|
2398
|
+
} = arg;
|
|
2399
|
+
return [endpointName, originalArgs, requestId];
|
|
2400
|
+
}
|
|
2401
|
+
const handler = (action, mwApi, stateBefore) => {
|
|
2402
|
+
const cacheKey = getCacheKey(action);
|
|
2403
|
+
function checkForNewCacheKey(endpointName, cacheKey2, requestId, originalArgs) {
|
|
2404
|
+
const oldEntry = selectQueryEntry(stateBefore, cacheKey2);
|
|
2405
|
+
const newEntry = selectQueryEntry(mwApi.getState(), cacheKey2);
|
|
2406
|
+
if (!oldEntry && newEntry) {
|
|
2407
|
+
handleNewKey(endpointName, originalArgs, cacheKey2, mwApi, requestId);
|
|
2408
|
+
}
|
|
2409
|
+
}
|
|
2410
|
+
if (queryThunk.pending.match(action)) {
|
|
2411
|
+
const [endpointName, originalArgs, requestId] = getActionMetaFields(action);
|
|
2412
|
+
checkForNewCacheKey(endpointName, cacheKey, requestId, originalArgs);
|
|
2413
|
+
} else if (cacheEntriesUpserted.match(action)) {
|
|
2414
|
+
for (const {
|
|
2415
|
+
queryDescription,
|
|
2416
|
+
value
|
|
2417
|
+
} of action.payload) {
|
|
2418
|
+
const {
|
|
2419
|
+
endpointName,
|
|
2420
|
+
originalArgs,
|
|
2421
|
+
queryCacheKey
|
|
2422
|
+
} = queryDescription;
|
|
2423
|
+
checkForNewCacheKey(endpointName, queryCacheKey, action.meta.requestId, originalArgs);
|
|
2424
|
+
resolveLifecycleEntry(queryCacheKey, value, {});
|
|
2425
|
+
}
|
|
2426
|
+
} else if (mutationThunk.pending.match(action)) {
|
|
2427
|
+
const state = mwApi.getState()[reducerPath].mutations[cacheKey];
|
|
2428
|
+
if (state) {
|
|
2429
|
+
const [endpointName, originalArgs, requestId] = getActionMetaFields(action);
|
|
2430
|
+
handleNewKey(endpointName, originalArgs, cacheKey, mwApi, requestId);
|
|
2431
|
+
}
|
|
2432
|
+
} else if (isFulfilledThunk(action)) {
|
|
2433
|
+
resolveLifecycleEntry(cacheKey, action.payload, action.meta.baseQueryMeta);
|
|
2434
|
+
} else if (removeQueryResult.match(action) || removeMutationResult.match(action)) {
|
|
2435
|
+
removeLifecycleEntry(cacheKey);
|
|
2436
|
+
} else if (api.util.resetApiState.match(action)) {
|
|
2437
|
+
for (const cacheKey2 of Object.keys(lifecycleMap)) {
|
|
2438
|
+
removeLifecycleEntry(cacheKey2);
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
};
|
|
2442
|
+
function getCacheKey(action) {
|
|
2443
|
+
var _a;
|
|
2444
|
+
if (isQueryThunk(action)) return action.meta.arg.queryCacheKey;
|
|
2445
|
+
if (isMutationThunk(action)) {
|
|
2446
|
+
return (_a = action.meta.arg.fixedCacheKey) != null ? _a : action.meta.requestId;
|
|
2447
|
+
}
|
|
2448
|
+
if (removeQueryResult.match(action)) return action.payload.queryCacheKey;
|
|
2449
|
+
if (removeMutationResult.match(action)) return getMutationCacheKey(action.payload);
|
|
2450
|
+
return "";
|
|
2451
|
+
}
|
|
2452
|
+
function handleNewKey(endpointName, originalArgs, queryCacheKey, mwApi, requestId) {
|
|
2453
|
+
const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|
2454
|
+
const onCacheEntryAdded = endpointDefinition == null ? void 0 : endpointDefinition.onCacheEntryAdded;
|
|
2455
|
+
if (!onCacheEntryAdded) return;
|
|
2456
|
+
const lifecycle = {};
|
|
2457
|
+
const cacheEntryRemoved = new Promise((resolve) => {
|
|
2458
|
+
lifecycle.cacheEntryRemoved = resolve;
|
|
2459
|
+
});
|
|
2460
|
+
const cacheDataLoaded = Promise.race([new Promise((resolve) => {
|
|
2461
|
+
lifecycle.valueResolved = resolve;
|
|
2462
|
+
}), cacheEntryRemoved.then(() => {
|
|
2463
|
+
throw neverResolvedError;
|
|
2464
|
+
})]);
|
|
2465
|
+
cacheDataLoaded.catch(() => {
|
|
2466
|
+
});
|
|
2467
|
+
lifecycleMap[queryCacheKey] = lifecycle;
|
|
2468
|
+
const selector = api.endpoints[endpointName].select(isAnyQueryDefinition(endpointDefinition) ? originalArgs : queryCacheKey);
|
|
2469
|
+
const extra = mwApi.dispatch((_, __, extra2) => extra2);
|
|
2470
|
+
const lifecycleApi = __spreadProps(__spreadValues({}, mwApi), {
|
|
2471
|
+
getCacheEntry: () => selector(mwApi.getState()),
|
|
2472
|
+
requestId,
|
|
2473
|
+
extra,
|
|
2474
|
+
updateCachedData: isAnyQueryDefinition(endpointDefinition) ? (updateRecipe) => mwApi.dispatch(api.util.updateQueryData(endpointName, originalArgs, updateRecipe)) : void 0,
|
|
2475
|
+
cacheDataLoaded,
|
|
2476
|
+
cacheEntryRemoved
|
|
2477
|
+
});
|
|
2478
|
+
const runningHandler = onCacheEntryAdded(originalArgs, lifecycleApi);
|
|
2479
|
+
Promise.resolve(runningHandler).catch((e) => {
|
|
2480
|
+
if (e === neverResolvedError) return;
|
|
2481
|
+
throw e;
|
|
2482
|
+
});
|
|
2483
|
+
}
|
|
2484
|
+
return handler;
|
|
2485
|
+
};
|
|
2486
|
+
|
|
2487
|
+
// src/query/core/buildMiddleware/devMiddleware.ts
|
|
2488
|
+
var buildDevCheckHandler = ({
|
|
2489
|
+
api,
|
|
2490
|
+
context: {
|
|
2491
|
+
apiUid
|
|
2492
|
+
},
|
|
2493
|
+
reducerPath
|
|
2494
|
+
}) => {
|
|
2495
|
+
return (action, mwApi) => {
|
|
2496
|
+
var _a, _b;
|
|
2497
|
+
if (api.util.resetApiState.match(action)) {
|
|
2498
|
+
mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
|
2499
|
+
}
|
|
2500
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
2501
|
+
if (api.internalActions.middlewareRegistered.match(action) && action.payload === apiUid && ((_b = (_a = mwApi.getState()[reducerPath]) == null ? void 0 : _a.config) == null ? void 0 : _b.middlewareRegistered) === "conflict") {
|
|
2502
|
+
console.warn(`There is a mismatch between slice and middleware for the reducerPath "${reducerPath}".
|
|
2503
|
+
You can only have one api per reducer path, this will lead to crashes in various situations!${reducerPath === "api" ? `
|
|
2504
|
+
If you have multiple apis, you *have* to specify the reducerPath option when using createApi!` : ""}`);
|
|
2505
|
+
}
|
|
2506
|
+
}
|
|
2507
|
+
};
|
|
2508
|
+
};
|
|
2509
|
+
|
|
2510
|
+
// src/query/core/buildMiddleware/invalidationByTags.ts
|
|
2511
|
+
var buildInvalidationByTagsHandler = ({
|
|
2512
|
+
reducerPath,
|
|
2513
|
+
context,
|
|
2514
|
+
context: {
|
|
2515
|
+
endpointDefinitions
|
|
2516
|
+
},
|
|
2517
|
+
mutationThunk,
|
|
2518
|
+
queryThunk,
|
|
2519
|
+
api,
|
|
2520
|
+
assertTagType,
|
|
2521
|
+
refetchQuery,
|
|
2522
|
+
internalState
|
|
2523
|
+
}) => {
|
|
2524
|
+
const {
|
|
2525
|
+
removeQueryResult
|
|
2526
|
+
} = api.internalActions;
|
|
2527
|
+
const isThunkActionWithTags = isAnyOf(isFulfilled(mutationThunk), isRejectedWithValue(mutationThunk));
|
|
2528
|
+
const isQueryEnd = isAnyOf(isFulfilled(queryThunk, mutationThunk), isRejected(queryThunk, mutationThunk));
|
|
2529
|
+
let pendingTagInvalidations = [];
|
|
2530
|
+
let pendingRequestCount = 0;
|
|
2531
|
+
const handler = (action, mwApi) => {
|
|
2532
|
+
if (queryThunk.pending.match(action) || mutationThunk.pending.match(action)) {
|
|
2533
|
+
pendingRequestCount++;
|
|
2534
|
+
}
|
|
2535
|
+
if (isQueryEnd(action)) {
|
|
2536
|
+
pendingRequestCount = Math.max(0, pendingRequestCount - 1);
|
|
2537
|
+
}
|
|
2538
|
+
if (isThunkActionWithTags(action)) {
|
|
2539
|
+
invalidateTags(calculateProvidedByThunk(action, "invalidatesTags", endpointDefinitions, assertTagType), mwApi);
|
|
2540
|
+
} else if (isQueryEnd(action)) {
|
|
2541
|
+
invalidateTags([], mwApi);
|
|
2542
|
+
} else if (api.util.invalidateTags.match(action)) {
|
|
2543
|
+
invalidateTags(calculateProvidedBy(action.payload, void 0, void 0, void 0, void 0, assertTagType), mwApi);
|
|
2544
|
+
}
|
|
2545
|
+
};
|
|
2546
|
+
function hasPendingRequests() {
|
|
2547
|
+
return pendingRequestCount > 0;
|
|
2548
|
+
}
|
|
2549
|
+
function invalidateTags(newTags, mwApi) {
|
|
2550
|
+
const rootState = mwApi.getState();
|
|
2551
|
+
const state = rootState[reducerPath];
|
|
2552
|
+
pendingTagInvalidations.push(...newTags);
|
|
2553
|
+
if (state.config.invalidationBehavior === "delayed" && hasPendingRequests()) {
|
|
2554
|
+
return;
|
|
2555
|
+
}
|
|
2556
|
+
const tags = pendingTagInvalidations;
|
|
2557
|
+
pendingTagInvalidations = [];
|
|
2558
|
+
if (tags.length === 0) return;
|
|
2559
|
+
const toInvalidate = api.util.selectInvalidatedBy(rootState, tags);
|
|
2560
|
+
context.batch(() => {
|
|
2561
|
+
const valuesArray = Array.from(toInvalidate.values());
|
|
2562
|
+
for (const {
|
|
2563
|
+
queryCacheKey
|
|
2564
|
+
} of valuesArray) {
|
|
2565
|
+
const querySubState = state.queries[queryCacheKey];
|
|
2566
|
+
const subscriptionSubState = getOrInsertComputed(internalState.currentSubscriptions, queryCacheKey, createNewMap);
|
|
2567
|
+
if (querySubState) {
|
|
2568
|
+
if (subscriptionSubState.size === 0) {
|
|
2569
|
+
mwApi.dispatch(removeQueryResult({
|
|
2570
|
+
queryCacheKey
|
|
2571
|
+
}));
|
|
2572
|
+
} else if (querySubState.status !== STATUS_UNINITIALIZED) {
|
|
2573
|
+
mwApi.dispatch(refetchQuery(querySubState));
|
|
2574
|
+
}
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
return handler;
|
|
2580
|
+
};
|
|
2581
|
+
|
|
2582
|
+
// src/query/core/buildMiddleware/polling.ts
|
|
2583
|
+
var buildPollingHandler = ({
|
|
2584
|
+
reducerPath,
|
|
2585
|
+
queryThunk,
|
|
2586
|
+
api,
|
|
2587
|
+
refetchQuery,
|
|
2588
|
+
internalState
|
|
2589
|
+
}) => {
|
|
2590
|
+
const {
|
|
2591
|
+
currentPolls,
|
|
2592
|
+
currentSubscriptions
|
|
2593
|
+
} = internalState;
|
|
2594
|
+
const pendingPollingUpdates = /* @__PURE__ */ new Set();
|
|
2595
|
+
let pollingUpdateTimer = null;
|
|
2596
|
+
const handler = (action, mwApi) => {
|
|
2597
|
+
if (api.internalActions.updateSubscriptionOptions.match(action) || api.internalActions.unsubscribeQueryResult.match(action)) {
|
|
2598
|
+
schedulePollingUpdate(action.payload.queryCacheKey, mwApi);
|
|
2599
|
+
}
|
|
2600
|
+
if (queryThunk.pending.match(action) || queryThunk.rejected.match(action) && action.meta.condition) {
|
|
2601
|
+
schedulePollingUpdate(action.meta.arg.queryCacheKey, mwApi);
|
|
2602
|
+
}
|
|
2603
|
+
if (queryThunk.fulfilled.match(action) || queryThunk.rejected.match(action) && !action.meta.condition) {
|
|
2604
|
+
startNextPoll(action.meta.arg, mwApi);
|
|
2605
|
+
}
|
|
2606
|
+
if (api.util.resetApiState.match(action)) {
|
|
2607
|
+
clearPolls();
|
|
2608
|
+
if (pollingUpdateTimer) {
|
|
2609
|
+
clearTimeout(pollingUpdateTimer);
|
|
2610
|
+
pollingUpdateTimer = null;
|
|
2611
|
+
}
|
|
2612
|
+
pendingPollingUpdates.clear();
|
|
2613
|
+
}
|
|
2614
|
+
};
|
|
2615
|
+
function schedulePollingUpdate(queryCacheKey, api2) {
|
|
2616
|
+
pendingPollingUpdates.add(queryCacheKey);
|
|
2617
|
+
if (!pollingUpdateTimer) {
|
|
2618
|
+
pollingUpdateTimer = setTimeout(() => {
|
|
2619
|
+
for (const key of pendingPollingUpdates) {
|
|
2620
|
+
updatePollingInterval({
|
|
2621
|
+
queryCacheKey: key
|
|
2622
|
+
}, api2);
|
|
2623
|
+
}
|
|
2624
|
+
pendingPollingUpdates.clear();
|
|
2625
|
+
pollingUpdateTimer = null;
|
|
2626
|
+
}, 0);
|
|
2627
|
+
}
|
|
2628
|
+
}
|
|
2629
|
+
function startNextPoll({
|
|
2630
|
+
queryCacheKey
|
|
2631
|
+
}, api2) {
|
|
2632
|
+
const state = api2.getState()[reducerPath];
|
|
2633
|
+
const querySubState = state.queries[queryCacheKey];
|
|
2634
|
+
const subscriptions = currentSubscriptions.get(queryCacheKey);
|
|
2635
|
+
if (!querySubState || querySubState.status === STATUS_UNINITIALIZED) return;
|
|
2636
|
+
const {
|
|
2637
|
+
lowestPollingInterval,
|
|
2638
|
+
skipPollingIfUnfocused
|
|
2639
|
+
} = findLowestPollingInterval(subscriptions);
|
|
2640
|
+
if (!Number.isFinite(lowestPollingInterval)) return;
|
|
2641
|
+
const currentPoll = currentPolls.get(queryCacheKey);
|
|
2642
|
+
if (currentPoll == null ? void 0 : currentPoll.timeout) {
|
|
2643
|
+
clearTimeout(currentPoll.timeout);
|
|
2644
|
+
currentPoll.timeout = void 0;
|
|
2645
|
+
}
|
|
2646
|
+
const nextPollTimestamp = Date.now() + lowestPollingInterval;
|
|
2647
|
+
currentPolls.set(queryCacheKey, {
|
|
2648
|
+
nextPollTimestamp,
|
|
2649
|
+
pollingInterval: lowestPollingInterval,
|
|
2650
|
+
timeout: setTimeout(() => {
|
|
2651
|
+
if (state.config.focused || !skipPollingIfUnfocused) {
|
|
2652
|
+
api2.dispatch(refetchQuery(querySubState));
|
|
2653
|
+
}
|
|
2654
|
+
startNextPoll({
|
|
2655
|
+
queryCacheKey
|
|
2656
|
+
}, api2);
|
|
2657
|
+
}, lowestPollingInterval)
|
|
2658
|
+
});
|
|
2659
|
+
}
|
|
2660
|
+
function updatePollingInterval({
|
|
2661
|
+
queryCacheKey
|
|
2662
|
+
}, api2) {
|
|
2663
|
+
var _a, _b;
|
|
2664
|
+
const state = api2.getState()[reducerPath];
|
|
2665
|
+
const querySubState = state.queries[queryCacheKey];
|
|
2666
|
+
const subscriptions = currentSubscriptions.get(queryCacheKey);
|
|
2667
|
+
if (!querySubState || querySubState.status === STATUS_UNINITIALIZED) {
|
|
2668
|
+
return;
|
|
2669
|
+
}
|
|
2670
|
+
const {
|
|
2671
|
+
lowestPollingInterval
|
|
2672
|
+
} = findLowestPollingInterval(subscriptions);
|
|
2673
|
+
if (process.env.NODE_ENV === "test") {
|
|
2674
|
+
const updateCounters = (_a = currentPolls.pollUpdateCounters) != null ? _a : currentPolls.pollUpdateCounters = {};
|
|
2675
|
+
(_b = updateCounters[queryCacheKey]) != null ? _b : updateCounters[queryCacheKey] = 0;
|
|
2676
|
+
updateCounters[queryCacheKey]++;
|
|
2677
|
+
}
|
|
2678
|
+
if (!Number.isFinite(lowestPollingInterval)) {
|
|
2679
|
+
cleanupPollForKey(queryCacheKey);
|
|
2680
|
+
return;
|
|
2681
|
+
}
|
|
2682
|
+
const currentPoll = currentPolls.get(queryCacheKey);
|
|
2683
|
+
const nextPollTimestamp = Date.now() + lowestPollingInterval;
|
|
2684
|
+
if (!currentPoll || nextPollTimestamp < currentPoll.nextPollTimestamp) {
|
|
2685
|
+
startNextPoll({
|
|
2686
|
+
queryCacheKey
|
|
2687
|
+
}, api2);
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
function cleanupPollForKey(key) {
|
|
2691
|
+
const existingPoll = currentPolls.get(key);
|
|
2692
|
+
if (existingPoll == null ? void 0 : existingPoll.timeout) {
|
|
2693
|
+
clearTimeout(existingPoll.timeout);
|
|
2694
|
+
}
|
|
2695
|
+
currentPolls.delete(key);
|
|
2696
|
+
}
|
|
2697
|
+
function clearPolls() {
|
|
2698
|
+
for (const key of currentPolls.keys()) {
|
|
2699
|
+
cleanupPollForKey(key);
|
|
2700
|
+
}
|
|
2701
|
+
}
|
|
2702
|
+
function findLowestPollingInterval(subscribers = /* @__PURE__ */ new Map()) {
|
|
2703
|
+
let skipPollingIfUnfocused = false;
|
|
2704
|
+
let lowestPollingInterval = Number.POSITIVE_INFINITY;
|
|
2705
|
+
for (const entry of subscribers.values()) {
|
|
2706
|
+
if (!!entry.pollingInterval) {
|
|
2707
|
+
lowestPollingInterval = Math.min(entry.pollingInterval, lowestPollingInterval);
|
|
2708
|
+
skipPollingIfUnfocused = entry.skipPollingIfUnfocused || skipPollingIfUnfocused;
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
return {
|
|
2712
|
+
lowestPollingInterval,
|
|
2713
|
+
skipPollingIfUnfocused
|
|
2714
|
+
};
|
|
2715
|
+
}
|
|
2716
|
+
return handler;
|
|
2717
|
+
};
|
|
2718
|
+
|
|
2719
|
+
// src/query/core/buildMiddleware/queryLifecycle.ts
|
|
2720
|
+
var buildQueryLifecycleHandler = ({
|
|
2721
|
+
api,
|
|
2722
|
+
context,
|
|
2723
|
+
queryThunk,
|
|
2724
|
+
mutationThunk
|
|
2725
|
+
}) => {
|
|
2726
|
+
const isPendingThunk = isPending(queryThunk, mutationThunk);
|
|
2727
|
+
const isRejectedThunk = isRejected(queryThunk, mutationThunk);
|
|
2728
|
+
const isFulfilledThunk = isFulfilled(queryThunk, mutationThunk);
|
|
2729
|
+
const lifecycleMap = {};
|
|
2730
|
+
const handler = (action, mwApi) => {
|
|
2731
|
+
var _a, _b, _c;
|
|
2732
|
+
if (isPendingThunk(action)) {
|
|
2733
|
+
const {
|
|
2734
|
+
requestId,
|
|
2735
|
+
arg: {
|
|
2736
|
+
endpointName,
|
|
2737
|
+
originalArgs
|
|
2738
|
+
}
|
|
2739
|
+
} = action.meta;
|
|
2740
|
+
const endpointDefinition = getEndpointDefinition(context, endpointName);
|
|
2741
|
+
const onQueryStarted = endpointDefinition == null ? void 0 : endpointDefinition.onQueryStarted;
|
|
2742
|
+
if (onQueryStarted) {
|
|
2743
|
+
const lifecycle = {};
|
|
2744
|
+
const queryFulfilled = new Promise((resolve, reject) => {
|
|
2745
|
+
lifecycle.resolve = resolve;
|
|
2746
|
+
lifecycle.reject = reject;
|
|
2747
|
+
});
|
|
2748
|
+
queryFulfilled.catch(() => {
|
|
2749
|
+
});
|
|
2750
|
+
lifecycleMap[requestId] = lifecycle;
|
|
2751
|
+
const selector = api.endpoints[endpointName].select(isAnyQueryDefinition(endpointDefinition) ? originalArgs : requestId);
|
|
2752
|
+
const extra = mwApi.dispatch((_, __, extra2) => extra2);
|
|
2753
|
+
const lifecycleApi = __spreadProps(__spreadValues({}, mwApi), {
|
|
2754
|
+
getCacheEntry: () => selector(mwApi.getState()),
|
|
2755
|
+
requestId,
|
|
2756
|
+
extra,
|
|
2757
|
+
updateCachedData: isAnyQueryDefinition(endpointDefinition) ? (updateRecipe) => mwApi.dispatch(api.util.updateQueryData(endpointName, originalArgs, updateRecipe)) : void 0,
|
|
2758
|
+
queryFulfilled
|
|
2759
|
+
});
|
|
2760
|
+
onQueryStarted(originalArgs, lifecycleApi);
|
|
2761
|
+
}
|
|
2762
|
+
} else if (isFulfilledThunk(action)) {
|
|
2763
|
+
const {
|
|
2764
|
+
requestId,
|
|
2765
|
+
baseQueryMeta
|
|
2766
|
+
} = action.meta;
|
|
2767
|
+
(_a = lifecycleMap[requestId]) == null ? void 0 : _a.resolve({
|
|
2768
|
+
data: action.payload,
|
|
2769
|
+
meta: baseQueryMeta
|
|
2770
|
+
});
|
|
2771
|
+
delete lifecycleMap[requestId];
|
|
2772
|
+
} else if (isRejectedThunk(action)) {
|
|
2773
|
+
const {
|
|
2774
|
+
requestId,
|
|
2775
|
+
rejectedWithValue,
|
|
2776
|
+
baseQueryMeta
|
|
2777
|
+
} = action.meta;
|
|
2778
|
+
(_c = lifecycleMap[requestId]) == null ? void 0 : _c.reject({
|
|
2779
|
+
error: (_b = action.payload) != null ? _b : action.error,
|
|
2780
|
+
isUnhandledError: !rejectedWithValue,
|
|
2781
|
+
meta: baseQueryMeta
|
|
2782
|
+
});
|
|
2783
|
+
delete lifecycleMap[requestId];
|
|
2784
|
+
}
|
|
2785
|
+
};
|
|
2786
|
+
return handler;
|
|
2787
|
+
};
|
|
2788
|
+
|
|
2789
|
+
// src/query/core/buildMiddleware/windowEventHandling.ts
|
|
2790
|
+
var buildWindowEventHandler = ({
|
|
2791
|
+
reducerPath,
|
|
2792
|
+
context,
|
|
2793
|
+
api,
|
|
2794
|
+
refetchQuery,
|
|
2795
|
+
internalState
|
|
2796
|
+
}) => {
|
|
2797
|
+
const {
|
|
2798
|
+
removeQueryResult
|
|
2799
|
+
} = api.internalActions;
|
|
2800
|
+
const handler = (action, mwApi) => {
|
|
2801
|
+
if (onFocus.match(action)) {
|
|
2802
|
+
refetchValidQueries(mwApi, "refetchOnFocus");
|
|
2803
|
+
}
|
|
2804
|
+
if (onOnline.match(action)) {
|
|
2805
|
+
refetchValidQueries(mwApi, "refetchOnReconnect");
|
|
2806
|
+
}
|
|
2807
|
+
};
|
|
2808
|
+
function refetchValidQueries(api2, type) {
|
|
2809
|
+
const state = api2.getState()[reducerPath];
|
|
2810
|
+
const queries = state.queries;
|
|
2811
|
+
const subscriptions = internalState.currentSubscriptions;
|
|
2812
|
+
context.batch(() => {
|
|
2813
|
+
for (const queryCacheKey of subscriptions.keys()) {
|
|
2814
|
+
const querySubState = queries[queryCacheKey];
|
|
2815
|
+
const subscriptionSubState = subscriptions.get(queryCacheKey);
|
|
2816
|
+
if (!subscriptionSubState || !querySubState) continue;
|
|
2817
|
+
const values = [...subscriptionSubState.values()];
|
|
2818
|
+
const shouldRefetch = values.some((sub) => sub[type] === true) || values.every((sub) => sub[type] === void 0) && state.config[type];
|
|
2819
|
+
if (shouldRefetch) {
|
|
2820
|
+
if (subscriptionSubState.size === 0) {
|
|
2821
|
+
api2.dispatch(removeQueryResult({
|
|
2822
|
+
queryCacheKey
|
|
2823
|
+
}));
|
|
2824
|
+
} else if (querySubState.status !== STATUS_UNINITIALIZED) {
|
|
2825
|
+
api2.dispatch(refetchQuery(querySubState));
|
|
2826
|
+
}
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
});
|
|
2830
|
+
}
|
|
2831
|
+
return handler;
|
|
2832
|
+
};
|
|
2833
|
+
|
|
2834
|
+
// src/query/core/buildMiddleware/index.ts
|
|
2835
|
+
function buildMiddleware(input) {
|
|
2836
|
+
const {
|
|
2837
|
+
reducerPath,
|
|
2838
|
+
queryThunk,
|
|
2839
|
+
api,
|
|
2840
|
+
context,
|
|
2841
|
+
getInternalState
|
|
2842
|
+
} = input;
|
|
2843
|
+
const {
|
|
2844
|
+
apiUid
|
|
2845
|
+
} = context;
|
|
2846
|
+
const actions2 = {
|
|
2847
|
+
invalidateTags: createAction(`${reducerPath}/invalidateTags`)
|
|
2848
|
+
};
|
|
2849
|
+
const isThisApiSliceAction = (action) => action.type.startsWith(`${reducerPath}/`);
|
|
2850
|
+
const handlerBuilders = [buildDevCheckHandler, buildCacheCollectionHandler, buildInvalidationByTagsHandler, buildPollingHandler, buildCacheLifecycleHandler, buildQueryLifecycleHandler];
|
|
2851
|
+
const middleware = (mwApi) => {
|
|
2852
|
+
let initialized2 = false;
|
|
2853
|
+
const internalState = getInternalState(mwApi.dispatch);
|
|
2854
|
+
const builderArgs = __spreadProps(__spreadValues({}, input), {
|
|
2855
|
+
internalState,
|
|
2856
|
+
refetchQuery,
|
|
2857
|
+
isThisApiSliceAction,
|
|
2858
|
+
mwApi
|
|
2859
|
+
});
|
|
2860
|
+
const handlers = handlerBuilders.map((build) => build(builderArgs));
|
|
2861
|
+
const batchedActionsHandler = buildBatchedActionsHandler(builderArgs);
|
|
2862
|
+
const windowEventsHandler = buildWindowEventHandler(builderArgs);
|
|
2863
|
+
return (next) => {
|
|
2864
|
+
return (action) => {
|
|
2865
|
+
if (!isAction(action)) {
|
|
2866
|
+
return next(action);
|
|
2867
|
+
}
|
|
2868
|
+
if (!initialized2) {
|
|
2869
|
+
initialized2 = true;
|
|
2870
|
+
mwApi.dispatch(api.internalActions.middlewareRegistered(apiUid));
|
|
2871
|
+
}
|
|
2872
|
+
const mwApiWithNext = __spreadProps(__spreadValues({}, mwApi), {
|
|
2873
|
+
next
|
|
2874
|
+
});
|
|
2875
|
+
const stateBefore = mwApi.getState();
|
|
2876
|
+
const [actionShouldContinue, internalProbeResult] = batchedActionsHandler(action, mwApiWithNext, stateBefore);
|
|
2877
|
+
let res;
|
|
2878
|
+
if (actionShouldContinue) {
|
|
2879
|
+
res = next(action);
|
|
2880
|
+
} else {
|
|
2881
|
+
res = internalProbeResult;
|
|
2882
|
+
}
|
|
2883
|
+
if (!!mwApi.getState()[reducerPath]) {
|
|
2884
|
+
windowEventsHandler(action, mwApiWithNext, stateBefore);
|
|
2885
|
+
if (isThisApiSliceAction(action) || context.hasRehydrationInfo(action)) {
|
|
2886
|
+
for (const handler of handlers) {
|
|
2887
|
+
handler(action, mwApiWithNext, stateBefore);
|
|
2888
|
+
}
|
|
2889
|
+
}
|
|
2890
|
+
}
|
|
2891
|
+
return res;
|
|
2892
|
+
};
|
|
2893
|
+
};
|
|
2894
|
+
};
|
|
2895
|
+
return {
|
|
2896
|
+
middleware,
|
|
2897
|
+
actions: actions2
|
|
2898
|
+
};
|
|
2899
|
+
function refetchQuery(querySubState) {
|
|
2900
|
+
return input.api.endpoints[querySubState.endpointName].initiate(querySubState.originalArgs, {
|
|
2901
|
+
subscribe: false,
|
|
2902
|
+
forceRefetch: true
|
|
2903
|
+
});
|
|
2904
|
+
}
|
|
2905
|
+
}
|
|
2906
|
+
|
|
2907
|
+
// src/query/core/module.ts
|
|
2908
|
+
var coreModuleName = /* @__PURE__ */ Symbol();
|
|
2909
|
+
var coreModule = ({
|
|
2910
|
+
createSelector: createSelector2 = createSelector
|
|
2911
|
+
} = {}) => ({
|
|
2912
|
+
name: coreModuleName,
|
|
2913
|
+
init(api, {
|
|
2914
|
+
baseQuery,
|
|
2915
|
+
tagTypes,
|
|
2916
|
+
reducerPath,
|
|
2917
|
+
serializeQueryArgs,
|
|
2918
|
+
keepUnusedDataFor,
|
|
2919
|
+
refetchOnMountOrArgChange,
|
|
2920
|
+
refetchOnFocus,
|
|
2921
|
+
refetchOnReconnect,
|
|
2922
|
+
invalidationBehavior,
|
|
2923
|
+
onSchemaFailure,
|
|
2924
|
+
catchSchemaFailure,
|
|
2925
|
+
skipSchemaValidation
|
|
2926
|
+
}, context) {
|
|
2927
|
+
enablePatches();
|
|
2928
|
+
assertCast(serializeQueryArgs);
|
|
2929
|
+
const assertTagType = (tag) => {
|
|
2930
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
2931
|
+
if (!tagTypes.includes(tag.type)) {
|
|
2932
|
+
console.error(`Tag type '${tag.type}' was used, but not specified in \`tagTypes\`!`);
|
|
2933
|
+
}
|
|
2934
|
+
}
|
|
2935
|
+
return tag;
|
|
2936
|
+
};
|
|
2937
|
+
Object.assign(api, {
|
|
2938
|
+
reducerPath,
|
|
2939
|
+
endpoints: {},
|
|
2940
|
+
internalActions: {
|
|
2941
|
+
onOnline,
|
|
2942
|
+
onOffline,
|
|
2943
|
+
onFocus,
|
|
2944
|
+
onFocusLost
|
|
2945
|
+
},
|
|
2946
|
+
util: {}
|
|
2947
|
+
});
|
|
2948
|
+
const selectors = buildSelectors({
|
|
2949
|
+
serializeQueryArgs,
|
|
2950
|
+
reducerPath,
|
|
2951
|
+
createSelector: createSelector2
|
|
2952
|
+
});
|
|
2953
|
+
const {
|
|
2954
|
+
selectInvalidatedBy,
|
|
2955
|
+
selectCachedArgsForQuery,
|
|
2956
|
+
buildQuerySelector,
|
|
2957
|
+
buildInfiniteQuerySelector,
|
|
2958
|
+
buildMutationSelector
|
|
2959
|
+
} = selectors;
|
|
2960
|
+
safeAssign(api.util, {
|
|
2961
|
+
selectInvalidatedBy,
|
|
2962
|
+
selectCachedArgsForQuery
|
|
2963
|
+
});
|
|
2964
|
+
const {
|
|
2965
|
+
queryThunk,
|
|
2966
|
+
infiniteQueryThunk,
|
|
2967
|
+
mutationThunk,
|
|
2968
|
+
patchQueryData,
|
|
2969
|
+
updateQueryData,
|
|
2970
|
+
upsertQueryData,
|
|
2971
|
+
prefetch,
|
|
2972
|
+
buildMatchThunkActions
|
|
2973
|
+
} = buildThunks({
|
|
2974
|
+
baseQuery,
|
|
2975
|
+
reducerPath,
|
|
2976
|
+
context,
|
|
2977
|
+
api,
|
|
2978
|
+
serializeQueryArgs,
|
|
2979
|
+
assertTagType,
|
|
2980
|
+
selectors,
|
|
2981
|
+
onSchemaFailure,
|
|
2982
|
+
catchSchemaFailure,
|
|
2983
|
+
skipSchemaValidation
|
|
2984
|
+
});
|
|
2985
|
+
const {
|
|
2986
|
+
reducer,
|
|
2987
|
+
actions: sliceActions
|
|
2988
|
+
} = buildSlice({
|
|
2989
|
+
context,
|
|
2990
|
+
queryThunk,
|
|
2991
|
+
infiniteQueryThunk,
|
|
2992
|
+
mutationThunk,
|
|
2993
|
+
serializeQueryArgs,
|
|
2994
|
+
reducerPath,
|
|
2995
|
+
assertTagType,
|
|
2996
|
+
config: {
|
|
2997
|
+
refetchOnFocus,
|
|
2998
|
+
refetchOnReconnect,
|
|
2999
|
+
refetchOnMountOrArgChange,
|
|
3000
|
+
keepUnusedDataFor,
|
|
3001
|
+
reducerPath,
|
|
3002
|
+
invalidationBehavior
|
|
3003
|
+
}
|
|
3004
|
+
});
|
|
3005
|
+
safeAssign(api.util, {
|
|
3006
|
+
patchQueryData,
|
|
3007
|
+
updateQueryData,
|
|
3008
|
+
upsertQueryData,
|
|
3009
|
+
prefetch,
|
|
3010
|
+
resetApiState: sliceActions.resetApiState,
|
|
3011
|
+
upsertQueryEntries: sliceActions.cacheEntriesUpserted
|
|
3012
|
+
});
|
|
3013
|
+
safeAssign(api.internalActions, sliceActions);
|
|
3014
|
+
const internalStateMap = /* @__PURE__ */ new WeakMap();
|
|
3015
|
+
const getInternalState = (dispatch) => {
|
|
3016
|
+
const state = getOrInsertComputed(internalStateMap, dispatch, () => ({
|
|
3017
|
+
currentSubscriptions: /* @__PURE__ */ new Map(),
|
|
3018
|
+
currentPolls: /* @__PURE__ */ new Map(),
|
|
3019
|
+
runningQueries: /* @__PURE__ */ new Map(),
|
|
3020
|
+
runningMutations: /* @__PURE__ */ new Map()
|
|
3021
|
+
}));
|
|
3022
|
+
return state;
|
|
3023
|
+
};
|
|
3024
|
+
const {
|
|
3025
|
+
buildInitiateQuery,
|
|
3026
|
+
buildInitiateInfiniteQuery,
|
|
3027
|
+
buildInitiateMutation,
|
|
3028
|
+
getRunningMutationThunk,
|
|
3029
|
+
getRunningMutationsThunk,
|
|
3030
|
+
getRunningQueriesThunk,
|
|
3031
|
+
getRunningQueryThunk
|
|
3032
|
+
} = buildInitiate({
|
|
3033
|
+
queryThunk,
|
|
3034
|
+
mutationThunk,
|
|
3035
|
+
infiniteQueryThunk,
|
|
3036
|
+
api,
|
|
3037
|
+
serializeQueryArgs,
|
|
3038
|
+
context,
|
|
3039
|
+
getInternalState
|
|
3040
|
+
});
|
|
3041
|
+
safeAssign(api.util, {
|
|
3042
|
+
getRunningMutationThunk,
|
|
3043
|
+
getRunningMutationsThunk,
|
|
3044
|
+
getRunningQueryThunk,
|
|
3045
|
+
getRunningQueriesThunk
|
|
3046
|
+
});
|
|
3047
|
+
const {
|
|
3048
|
+
middleware,
|
|
3049
|
+
actions: middlewareActions
|
|
3050
|
+
} = buildMiddleware({
|
|
3051
|
+
reducerPath,
|
|
3052
|
+
context,
|
|
3053
|
+
queryThunk,
|
|
3054
|
+
mutationThunk,
|
|
3055
|
+
infiniteQueryThunk,
|
|
3056
|
+
api,
|
|
3057
|
+
assertTagType,
|
|
3058
|
+
selectors,
|
|
3059
|
+
getRunningQueryThunk,
|
|
3060
|
+
getInternalState
|
|
3061
|
+
});
|
|
3062
|
+
safeAssign(api.util, middlewareActions);
|
|
3063
|
+
safeAssign(api, {
|
|
3064
|
+
reducer,
|
|
3065
|
+
middleware
|
|
3066
|
+
});
|
|
3067
|
+
return {
|
|
3068
|
+
name: coreModuleName,
|
|
3069
|
+
injectEndpoint(endpointName, definition) {
|
|
3070
|
+
var _a, _b;
|
|
3071
|
+
const anyApi = api;
|
|
3072
|
+
const endpoint = (_b = (_a = anyApi.endpoints)[endpointName]) != null ? _b : _a[endpointName] = {};
|
|
3073
|
+
if (isQueryDefinition(definition)) {
|
|
3074
|
+
safeAssign(endpoint, {
|
|
3075
|
+
name: endpointName,
|
|
3076
|
+
select: buildQuerySelector(endpointName, definition),
|
|
3077
|
+
initiate: buildInitiateQuery(endpointName, definition)
|
|
3078
|
+
}, buildMatchThunkActions(queryThunk, endpointName));
|
|
3079
|
+
}
|
|
3080
|
+
if (isMutationDefinition(definition)) {
|
|
3081
|
+
safeAssign(endpoint, {
|
|
3082
|
+
name: endpointName,
|
|
3083
|
+
select: buildMutationSelector(),
|
|
3084
|
+
initiate: buildInitiateMutation(endpointName)
|
|
3085
|
+
}, buildMatchThunkActions(mutationThunk, endpointName));
|
|
3086
|
+
}
|
|
3087
|
+
if (isInfiniteQueryDefinition(definition)) {
|
|
3088
|
+
safeAssign(endpoint, {
|
|
3089
|
+
name: endpointName,
|
|
3090
|
+
select: buildInfiniteQuerySelector(endpointName, definition),
|
|
3091
|
+
initiate: buildInitiateInfiniteQuery(endpointName, definition)
|
|
3092
|
+
}, buildMatchThunkActions(queryThunk, endpointName));
|
|
3093
|
+
}
|
|
3094
|
+
}
|
|
3095
|
+
};
|
|
3096
|
+
}
|
|
3097
|
+
});
|
|
3098
|
+
|
|
3099
|
+
// src/query/core/index.ts
|
|
3100
|
+
var createApi = /* @__PURE__ */ buildCreateApi(coreModule());
|
|
3101
|
+
export {
|
|
3102
|
+
NamedSchemaError,
|
|
3103
|
+
QueryStatus,
|
|
3104
|
+
_NEVER,
|
|
3105
|
+
buildCreateApi,
|
|
3106
|
+
copyWithStructuralSharing,
|
|
3107
|
+
coreModule,
|
|
3108
|
+
coreModuleName,
|
|
3109
|
+
createApi,
|
|
3110
|
+
defaultSerializeQueryArgs,
|
|
3111
|
+
fakeBaseQuery,
|
|
3112
|
+
fetchBaseQuery,
|
|
3113
|
+
retry,
|
|
3114
|
+
setupListeners,
|
|
3115
|
+
skipToken
|
|
3116
|
+
};
|
|
3117
|
+
//# sourceMappingURL=rtk-query.legacy-esm.js.map
|