@depup/reduxjs__toolkit 2.12.0-depup.28 → 2.13.0-depup.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/README.md +4 -4
  2. package/changes.json +3 -3
  3. package/dist/cjs/redux-toolkit.development.cjs +1755 -2247
  4. package/dist/cjs/redux-toolkit.development.cjs.map +1 -1
  5. package/dist/cjs/redux-toolkit.production.min.cjs +1 -2
  6. package/dist/cjs/redux-toolkit.production.min.cjs.map +1 -1
  7. package/dist/index.d.mts +1496 -1525
  8. package/dist/index.d.ts +1496 -1525
  9. package/dist/query/cjs/rtk-query.development.cjs +2059 -2990
  10. package/dist/query/cjs/rtk-query.development.cjs.map +1 -1
  11. package/dist/query/cjs/rtk-query.production.min.cjs +1 -1
  12. package/dist/query/cjs/rtk-query.production.min.cjs.map +1 -1
  13. package/dist/query/index.d.mts +2300 -2308
  14. package/dist/query/index.d.ts +2300 -2308
  15. package/dist/query/react/cjs/rtk-query-react.development.cjs +609 -714
  16. package/dist/query/react/cjs/rtk-query-react.development.cjs.map +1 -1
  17. package/dist/query/react/cjs/rtk-query-react.production.min.cjs +1 -1
  18. package/dist/query/react/cjs/rtk-query-react.production.min.cjs.map +1 -1
  19. package/dist/query/react/index.d.mts +516 -523
  20. package/dist/query/react/index.d.ts +516 -523
  21. package/dist/query/react/rtk-query-react.browser.mjs +1 -1
  22. package/dist/query/react/rtk-query-react.browser.mjs.map +1 -1
  23. package/dist/query/react/rtk-query-react.legacy-esm.js +672 -714
  24. package/dist/query/react/rtk-query-react.legacy-esm.js.map +1 -1
  25. package/dist/query/react/rtk-query-react.modern.mjs +586 -679
  26. package/dist/query/react/rtk-query-react.modern.mjs.map +1 -1
  27. package/dist/query/rtk-query.browser.mjs +1 -1
  28. package/dist/query/rtk-query.browser.mjs.map +1 -1
  29. package/dist/query/rtk-query.legacy-esm.js +2175 -3014
  30. package/dist/query/rtk-query.legacy-esm.js.map +1 -1
  31. package/dist/query/rtk-query.modern.mjs +2052 -2949
  32. package/dist/query/rtk-query.modern.mjs.map +1 -1
  33. package/dist/react/cjs/redux-toolkit-react.development.cjs +30 -51
  34. package/dist/react/cjs/redux-toolkit-react.development.cjs.map +1 -1
  35. package/dist/react/cjs/redux-toolkit-react.production.min.cjs +1 -1
  36. package/dist/react/cjs/redux-toolkit-react.production.min.cjs.map +1 -1
  37. package/dist/react/index.d.mts +12 -15
  38. package/dist/react/index.d.ts +12 -15
  39. package/dist/react/redux-toolkit-react.browser.mjs +1 -1
  40. package/dist/react/redux-toolkit-react.browser.mjs.map +1 -1
  41. package/dist/react/redux-toolkit-react.legacy-esm.js +83 -44
  42. package/dist/react/redux-toolkit-react.legacy-esm.js.map +1 -1
  43. package/dist/react/redux-toolkit-react.modern.mjs +23 -25
  44. package/dist/react/redux-toolkit-react.modern.mjs.map +1 -1
  45. package/dist/redux-toolkit.browser.mjs +1 -2
  46. package/dist/redux-toolkit.browser.mjs.map +1 -1
  47. package/dist/redux-toolkit.legacy-esm.js +1748 -2201
  48. package/dist/redux-toolkit.legacy-esm.js.map +1 -1
  49. package/dist/redux-toolkit.modern.mjs +1670 -2171
  50. package/dist/redux-toolkit.modern.mjs.map +1 -1
  51. package/package.json +17 -33
  52. package/skills/build-modern-redux-apps/modern-redux/SKILL.md +23 -14
  53. package/skills/build-modern-redux-apps/modern-redux/references/store-lifetime.md +6 -6
  54. package/skills/build-modern-redux-apps/redux-dataflow/SKILL.md +13 -10
  55. package/skills/evolve-and-diagnose-redux-apps/debug-redux-toolkit-apps/SKILL.md +6 -6
  56. package/skills/evolve-and-diagnose-redux-apps/migrate-to-modern-redux/SKILL.md +7 -8
  57. package/skills/manage-server-data/adopt-rtk-query/SKILL.md +13 -11
  58. package/skills/model-redux-state/build-slices-and-selectors/SKILL.md +26 -14
  59. package/skills/model-redux-state/design-state-ownership/SKILL.md +11 -12
  60. package/skills/model-redux-state/design-state-ownership/references/state-ownership.md +6 -6
  61. package/skills/orchestrate-side-effects/handle-side-effects/SKILL.md +27 -23
  62. package/skills/orchestrate-side-effects/handle-side-effects/references/listener-workflows.md +4 -4
  63. package/src/autoBatchEnhancer.ts +5 -3
  64. package/src/combineSlices.ts +5 -5
  65. package/src/createAction.ts +11 -6
  66. package/src/createAsyncThunk.ts +14 -2
  67. package/src/createReducer.ts +1 -1
  68. package/src/createSlice.ts +9 -4
  69. package/src/dynamicMiddleware/index.ts +21 -5
  70. package/src/entities/models.ts +2 -1
  71. package/src/entities/sorted_state_adapter.ts +35 -24
  72. package/src/entities/unsorted_state_adapter.ts +1 -1
  73. package/src/immutableStateInvariantMiddleware.ts +34 -5
  74. package/src/listenerMiddleware/types.ts +10 -10
  75. package/src/mapBuilders.ts +2 -5
  76. package/src/matchers.ts +7 -1
  77. package/src/query/core/apiState.ts +1 -1
  78. package/src/query/core/buildInitiate.ts +19 -15
  79. package/src/query/core/buildMiddleware/cacheLifecycle.ts +3 -1
  80. package/src/query/core/buildMiddleware/index.ts +1 -1
  81. package/src/query/core/buildMiddleware/invalidationByTags.ts +4 -1
  82. package/src/query/core/buildMiddleware/polling.ts +12 -3
  83. package/src/query/core/buildMiddleware/types.ts +5 -2
  84. package/src/query/core/buildSlice.ts +2 -2
  85. package/src/query/core/buildThunks.ts +19 -0
  86. package/src/query/core/module.ts +9 -3
  87. package/src/query/createApi.ts +4 -1
  88. package/src/query/endpointDefinitions.ts +15 -9
  89. package/src/query/fetchBaseQuery.ts +1 -1
  90. package/src/query/react/buildHooks.ts +54 -51
  91. package/src/query/react/namedHooks.ts +28 -24
  92. package/src/query/utils/isAbsoluteUrl.ts +8 -3
  93. package/src/serializableStateInvariantMiddleware.ts +1 -1
@@ -1,748 +1,643 @@
1
- "use strict";
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#region \0rolldown/runtime.js
2
3
  var __create = Object.create;
3
4
  var __defProp = Object.defineProperty;
4
5
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getProtoOf = Object.getPrototypeOf;
7
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
9
  var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
10
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
+ get: ((k) => from[k]).bind(null, key),
14
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
+ });
16
+ }
17
+ return to;
19
18
  };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
-
31
- // src/query/react/index.ts
32
- var react_exports = {};
33
- __export(react_exports, {
34
- ApiProvider: () => ApiProvider,
35
- UNINITIALIZED_VALUE: () => UNINITIALIZED_VALUE,
36
- createApi: () => createApi,
37
- reactHooksModule: () => reactHooksModule,
38
- reactHooksModuleName: () => reactHooksModuleName
39
- });
40
- module.exports = __toCommonJS(react_exports);
41
-
42
- // src/query/react/rtkqImports.ts
43
- var import_query = require("@reduxjs/toolkit/query");
44
-
45
- // src/query/react/module.ts
46
- var import_toolkit2 = require("@reduxjs/toolkit");
47
- var import_react_redux2 = require("react-redux");
48
- var import_reselect = require("reselect");
49
-
50
- // src/query/utils/capitalize.ts
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+ //#endregion
24
+ let _reduxjs_toolkit = require("@reduxjs/toolkit");
25
+ let react_redux = require("react-redux");
26
+ let reselect = require("reselect");
27
+ let react = require("react");
28
+ react = __toESM(react);
29
+ let _reduxjs_toolkit_query = require("@reduxjs/toolkit/query");
30
+ //#region src/query/utils/capitalize.ts
51
31
  function capitalize(str) {
52
- return str.replace(str[0], str[0].toUpperCase());
32
+ return str.replace(str[0], str[0].toUpperCase());
53
33
  }
54
-
55
- // src/query/utils/countObjectKeys.ts
34
+ //#endregion
35
+ //#region src/query/utils/countObjectKeys.ts
56
36
  function countObjectKeys(obj) {
57
- let count = 0;
58
- for (const _key in obj) {
59
- count++;
60
- }
61
- return count;
37
+ let count = 0;
38
+ for (const _key in obj) count++;
39
+ return count;
62
40
  }
63
-
64
- // src/query/endpointDefinitions.ts
65
- var ENDPOINT_QUERY = "query" /* query */;
66
- var ENDPOINT_MUTATION = "mutation" /* mutation */;
67
- var ENDPOINT_INFINITEQUERY = "infinitequery" /* infinitequery */;
41
+ //#endregion
42
+ //#region src/query/endpointDefinitions.ts
43
+ const ENDPOINT_QUERY = "query";
44
+ const ENDPOINT_MUTATION = "mutation";
45
+ const ENDPOINT_INFINITEQUERY = "infinitequery";
68
46
  function isQueryDefinition(e) {
69
- return e.type === ENDPOINT_QUERY;
47
+ return e.type === ENDPOINT_QUERY;
70
48
  }
71
49
  function isMutationDefinition(e) {
72
- return e.type === ENDPOINT_MUTATION;
50
+ return e.type === ENDPOINT_MUTATION;
73
51
  }
74
52
  function isInfiniteQueryDefinition(e) {
75
- return e.type === ENDPOINT_INFINITEQUERY;
53
+ return e.type === ENDPOINT_INFINITEQUERY;
76
54
  }
77
-
78
- // src/query/tsHelpers.ts
55
+ //#endregion
56
+ //#region src/query/tsHelpers.ts
79
57
  function safeAssign(target, ...args) {
80
- return Object.assign(target, ...args);
58
+ return Object.assign(target, ...args);
81
59
  }
82
-
83
- // src/query/react/buildHooks.ts
84
- var import_toolkit = require("@reduxjs/toolkit");
85
-
86
- // src/query/react/constants.ts
87
- var UNINITIALIZED_VALUE = /* @__PURE__ */ Symbol();
88
-
89
- // src/query/react/reactImports.ts
90
- var import_react = require("react");
91
-
92
- // src/query/react/reactReduxImports.ts
93
- var import_react_redux = require("react-redux");
94
-
95
- // src/query/react/useSerializedStableValue.ts
60
+ //#endregion
61
+ //#region src/query/react/constants.ts
62
+ const UNINITIALIZED_VALUE = Symbol();
63
+ //#endregion
64
+ //#region src/query/react/useSerializedStableValue.ts
96
65
  function useStableQueryArgs(queryArgs) {
97
- const cache = (0, import_react.useRef)(queryArgs);
98
- const copy = (0, import_react.useMemo)(() => (0, import_query.copyWithStructuralSharing)(cache.current, queryArgs), [queryArgs]);
99
- (0, import_react.useEffect)(() => {
100
- if (cache.current !== copy) {
101
- cache.current = copy;
102
- }
103
- }, [copy]);
104
- return copy;
66
+ const cache = (0, react.useRef)(queryArgs);
67
+ const copy = (0, react.useMemo)(() => (0, _reduxjs_toolkit_query.copyWithStructuralSharing)(cache.current, queryArgs), [queryArgs]);
68
+ (0, react.useEffect)(() => {
69
+ if (cache.current !== copy) cache.current = copy;
70
+ }, [copy]);
71
+ return copy;
105
72
  }
106
-
107
- // src/query/react/useShallowStableValue.ts
73
+ //#endregion
74
+ //#region src/query/react/useShallowStableValue.ts
108
75
  function useShallowStableValue(value) {
109
- const cache = (0, import_react.useRef)(value);
110
- (0, import_react.useEffect)(() => {
111
- if (!(0, import_react_redux.shallowEqual)(cache.current, value)) {
112
- cache.current = value;
113
- }
114
- }, [value]);
115
- return (0, import_react_redux.shallowEqual)(cache.current, value) ? cache.current : value;
76
+ const cache = (0, react.useRef)(value);
77
+ (0, react.useEffect)(() => {
78
+ if (!(0, react_redux.shallowEqual)(cache.current, value)) cache.current = value;
79
+ }, [value]);
80
+ return (0, react_redux.shallowEqual)(cache.current, value) ? cache.current : value;
116
81
  }
117
-
118
- // src/query/react/buildHooks.ts
119
- var canUseDOM = () => !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
120
- var isDOM = /* @__PURE__ */ canUseDOM();
121
- var isRunningInReactNative = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
122
- var isReactNative = /* @__PURE__ */ isRunningInReactNative();
123
- var getUseIsomorphicLayoutEffect = () => isDOM || isReactNative ? import_react.useLayoutEffect : import_react.useEffect;
124
- var useIsomorphicLayoutEffect = /* @__PURE__ */ getUseIsomorphicLayoutEffect();
125
- var noPendingQueryStateSelector = (selected) => {
126
- if (selected.isUninitialized) {
127
- return {
128
- ...selected,
129
- isUninitialized: false,
130
- isFetching: true,
131
- isLoading: selected.data !== void 0 ? false : true,
132
- // This is the one place where we still have to use `QueryStatus` as an enum,
133
- // since it's the only reference in the React package and not in the core.
134
- status: import_query.QueryStatus.pending
135
- };
136
- }
137
- return selected;
82
+ //#endregion
83
+ //#region src/query/react/buildHooks.ts
84
+ const canUseDOM = () => !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
85
+ const isDOM = /* @__PURE__ */ canUseDOM();
86
+ const isRunningInReactNative = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
87
+ const isReactNative = /* @__PURE__ */ isRunningInReactNative();
88
+ const getUseIsomorphicLayoutEffect = () => isDOM || isReactNative ? react.useLayoutEffect : react.useEffect;
89
+ const useIsomorphicLayoutEffect = /* @__PURE__ */ getUseIsomorphicLayoutEffect();
90
+ const noPendingQueryStateSelector = (selected) => {
91
+ if (selected.isUninitialized) return {
92
+ ...selected,
93
+ isUninitialized: false,
94
+ isFetching: true,
95
+ isLoading: selected.data !== void 0 ? false : true,
96
+ status: _reduxjs_toolkit_query.QueryStatus.pending
97
+ };
98
+ return selected;
138
99
  };
139
100
  function pick(obj, ...keys) {
140
- const ret = {};
141
- keys.forEach((key) => {
142
- ret[key] = obj[key];
143
- });
144
- return ret;
101
+ const ret = {};
102
+ keys.forEach((key) => {
103
+ ret[key] = obj[key];
104
+ });
105
+ return ret;
145
106
  }
146
- var COMMON_HOOK_DEBUG_FIELDS = ["data", "status", "isLoading", "isSuccess", "isError", "error"];
147
- function buildHooks({
148
- api,
149
- moduleOptions: {
150
- batch,
151
- hooks: {
152
- useDispatch,
153
- useSelector,
154
- useStore
155
- },
156
- unstable__sideEffectsInRender,
157
- createSelector
158
- },
159
- serializeQueryArgs,
160
- context
161
- }) {
162
- const usePossiblyImmediateEffect = unstable__sideEffectsInRender ? (cb) => cb() : import_react.useEffect;
163
- const unsubscribePromiseRef = (ref) => ref.current?.unsubscribe?.();
164
- const endpointDefinitions = context.endpointDefinitions;
165
- return {
166
- buildQueryHooks,
167
- buildInfiniteQueryHooks,
168
- buildMutationHook,
169
- usePrefetch
170
- };
171
- function queryStatePreSelector(currentState, lastResult, queryArgs) {
172
- if (lastResult?.endpointName && currentState.isUninitialized) {
173
- const {
174
- endpointName
175
- } = lastResult;
176
- const endpointDefinition = endpointDefinitions[endpointName];
177
- if (queryArgs !== import_query.skipToken && serializeQueryArgs({
178
- queryArgs: lastResult.originalArgs,
179
- endpointDefinition,
180
- endpointName
181
- }) === serializeQueryArgs({
182
- queryArgs,
183
- endpointDefinition,
184
- endpointName
185
- })) lastResult = void 0;
186
- }
187
- let data = currentState.isSuccess ? currentState.data : lastResult?.data;
188
- if (data === void 0) data = currentState.data;
189
- const hasData = data !== void 0;
190
- const isFetching = currentState.isLoading;
191
- const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
192
- const isSuccess = currentState.isSuccess || hasData && (isFetching && !lastResult?.isError || currentState.isUninitialized);
193
- return {
194
- ...currentState,
195
- data,
196
- currentData: currentState.data,
197
- isFetching,
198
- isLoading,
199
- isSuccess
200
- };
201
- }
202
- function infiniteQueryStatePreSelector(currentState, lastResult, queryArgs) {
203
- if (lastResult?.endpointName && currentState.isUninitialized) {
204
- const {
205
- endpointName
206
- } = lastResult;
207
- const endpointDefinition = endpointDefinitions[endpointName];
208
- if (queryArgs !== import_query.skipToken && serializeQueryArgs({
209
- queryArgs: lastResult.originalArgs,
210
- endpointDefinition,
211
- endpointName
212
- }) === serializeQueryArgs({
213
- queryArgs,
214
- endpointDefinition,
215
- endpointName
216
- })) lastResult = void 0;
217
- }
218
- let data = currentState.isSuccess ? currentState.data : lastResult?.data;
219
- if (data === void 0) data = currentState.data;
220
- const hasData = data !== void 0;
221
- const isFetching = currentState.isLoading;
222
- const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
223
- const isSuccess = currentState.isSuccess || hasData && (isFetching && !lastResult?.isError || currentState.isUninitialized);
224
- return {
225
- ...currentState,
226
- data,
227
- currentData: currentState.data,
228
- isFetching,
229
- isLoading,
230
- isSuccess
231
- };
232
- }
233
- function usePrefetch(endpointName, defaultOptions) {
234
- const dispatch = useDispatch();
235
- const stableDefaultOptions = useShallowStableValue(defaultOptions);
236
- return (0, import_react.useCallback)((arg, options) => dispatch(api.util.prefetch(endpointName, arg, {
237
- ...stableDefaultOptions,
238
- ...options
239
- })), [endpointName, dispatch, stableDefaultOptions]);
240
- }
241
- function useQuerySubscriptionCommonImpl(endpointName, arg, {
242
- refetchOnReconnect,
243
- refetchOnFocus,
244
- refetchOnMountOrArgChange,
245
- skip = false,
246
- pollingInterval = 0,
247
- skipPollingIfUnfocused = false,
248
- ...rest
249
- } = {}) {
250
- const {
251
- initiate
252
- } = api.endpoints[endpointName];
253
- const dispatch = useDispatch();
254
- const subscriptionSelectorsRef = (0, import_react.useRef)(void 0);
255
- if (!subscriptionSelectorsRef.current) {
256
- const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
257
- if (true) {
258
- if (typeof returnedValue !== "object" || typeof returnedValue?.type === "string") {
259
- throw new Error(false ? _formatProdErrorMessage(37) : `Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
107
+ const COMMON_HOOK_DEBUG_FIELDS = [
108
+ "data",
109
+ "status",
110
+ "isLoading",
111
+ "isSuccess",
112
+ "isError",
113
+ "error"
114
+ ];
115
+ function buildHooks({ api, moduleOptions: { batch, hooks: { useDispatch, useSelector }, unstable__sideEffectsInRender, createSelector }, serializeQueryArgs, context }) {
116
+ const usePossiblyImmediateEffect = unstable__sideEffectsInRender ? (cb) => cb() : react.useEffect;
117
+ const unsubscribePromiseRef = (ref) => {
118
+ ref.current?.unsubscribe?.();
119
+ ref.current = void 0;
120
+ };
121
+ const endpointDefinitions = context.endpointDefinitions;
122
+ return {
123
+ buildQueryHooks,
124
+ buildInfiniteQueryHooks,
125
+ buildMutationHook,
126
+ usePrefetch
127
+ };
128
+ function queryStatePreSelector(currentState, lastResult, queryArgs) {
129
+ if (lastResult?.endpointName && currentState.isUninitialized) {
130
+ const { endpointName } = lastResult;
131
+ const endpointDefinition = endpointDefinitions[endpointName];
132
+ if (queryArgs !== _reduxjs_toolkit_query.skipToken && serializeQueryArgs({
133
+ queryArgs: lastResult.originalArgs,
134
+ endpointDefinition,
135
+ endpointName
136
+ }) === serializeQueryArgs({
137
+ queryArgs,
138
+ endpointDefinition,
139
+ endpointName
140
+ })) lastResult = void 0;
141
+ }
142
+ let data = currentState.data;
143
+ if (data === void 0) data = lastResult?.data;
144
+ const hasData = data !== void 0;
145
+ const isFetching = currentState.isLoading;
146
+ const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
147
+ const isSuccess = currentState.isSuccess || hasData && (isFetching && currentState.error === void 0 || currentState.isUninitialized);
148
+ return {
149
+ ...currentState,
150
+ data,
151
+ currentData: currentState.data,
152
+ isFetching,
153
+ isLoading,
154
+ isSuccess
155
+ };
156
+ }
157
+ function infiniteQueryStatePreSelector(currentState, lastResult, queryArgs) {
158
+ if (lastResult?.endpointName && currentState.isUninitialized) {
159
+ const { endpointName } = lastResult;
160
+ const endpointDefinition = endpointDefinitions[endpointName];
161
+ if (queryArgs !== _reduxjs_toolkit_query.skipToken && serializeQueryArgs({
162
+ queryArgs: lastResult.originalArgs,
163
+ endpointDefinition,
164
+ endpointName
165
+ }) === serializeQueryArgs({
166
+ queryArgs,
167
+ endpointDefinition,
168
+ endpointName
169
+ })) lastResult = void 0;
170
+ }
171
+ let data = currentState.data;
172
+ if (data === void 0) data = lastResult?.data;
173
+ const hasData = data !== void 0;
174
+ const isFetching = currentState.isLoading;
175
+ const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
176
+ const isSuccess = currentState.isSuccess || hasData && (isFetching && currentState.error === void 0 || currentState.isUninitialized);
177
+ return {
178
+ ...currentState,
179
+ data,
180
+ currentData: currentState.data,
181
+ isFetching,
182
+ isLoading,
183
+ isSuccess
184
+ };
185
+ }
186
+ function usePrefetch(endpointName, defaultOptions) {
187
+ const dispatch = useDispatch();
188
+ const stableDefaultOptions = useShallowStableValue(defaultOptions);
189
+ return (0, react.useCallback)((arg, options) => dispatch(api.util.prefetch(endpointName, arg, {
190
+ ...stableDefaultOptions,
191
+ ...options
192
+ })), [
193
+ endpointName,
194
+ dispatch,
195
+ stableDefaultOptions
196
+ ]);
197
+ }
198
+ function useQuerySubscriptionCommonImpl(endpointName, arg, { refetchOnReconnect, refetchOnFocus, refetchOnMountOrArgChange, skip = false, pollingInterval = 0, skipPollingIfUnfocused = false, ...rest } = {}) {
199
+ const { initiate } = api.endpoints[endpointName];
200
+ const dispatch = useDispatch();
201
+ const subscriptionSelectorsRef = (0, react.useRef)(void 0);
202
+ if (!subscriptionSelectorsRef.current) {
203
+ const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
204
+ if (typeof returnedValue !== "object" || typeof returnedValue?.type === "string") throw new Error(`Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
260
205
  You must add the middleware for RTK-Query to function correctly!`);
261
- }
262
- }
263
- subscriptionSelectorsRef.current = returnedValue;
264
- }
265
- const stableArg = useStableQueryArgs(skip ? import_query.skipToken : arg);
266
- const stableSubscriptionOptions = useShallowStableValue({
267
- refetchOnReconnect,
268
- refetchOnFocus,
269
- pollingInterval,
270
- skipPollingIfUnfocused
271
- });
272
- const initialPageParam = rest.initialPageParam;
273
- const stableInitialPageParam = useShallowStableValue(initialPageParam);
274
- const refetchCachedPages = rest.refetchCachedPages;
275
- const stableRefetchCachedPages = useShallowStableValue(refetchCachedPages);
276
- const promiseRef = (0, import_react.useRef)(void 0);
277
- let {
278
- queryCacheKey,
279
- requestId
280
- } = promiseRef.current || {};
281
- let currentRenderHasSubscription = false;
282
- if (queryCacheKey && requestId) {
283
- currentRenderHasSubscription = subscriptionSelectorsRef.current.isRequestSubscribed(queryCacheKey, requestId);
284
- }
285
- const subscriptionRemoved = !currentRenderHasSubscription && promiseRef.current !== void 0;
286
- usePossiblyImmediateEffect(() => {
287
- if (subscriptionRemoved) {
288
- promiseRef.current = void 0;
289
- }
290
- }, [subscriptionRemoved]);
291
- usePossiblyImmediateEffect(() => {
292
- const lastPromise = promiseRef.current;
293
- if (typeof process !== "undefined" && false) {
294
- console.log(subscriptionRemoved);
295
- }
296
- if (stableArg === import_query.skipToken) {
297
- lastPromise?.unsubscribe();
298
- promiseRef.current = void 0;
299
- return;
300
- }
301
- const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
302
- if (!lastPromise || lastPromise.arg !== stableArg) {
303
- lastPromise?.unsubscribe();
304
- const promise = dispatch(initiate(stableArg, {
305
- subscriptionOptions: stableSubscriptionOptions,
306
- forceRefetch: refetchOnMountOrArgChange,
307
- ...isInfiniteQueryDefinition(endpointDefinitions[endpointName]) ? {
308
- initialPageParam: stableInitialPageParam,
309
- refetchCachedPages: stableRefetchCachedPages
310
- } : {}
311
- }));
312
- promiseRef.current = promise;
313
- } else if (stableSubscriptionOptions !== lastSubscriptionOptions) {
314
- lastPromise.updateSubscriptionOptions(stableSubscriptionOptions);
315
- }
316
- }, [dispatch, initiate, refetchOnMountOrArgChange, stableArg, stableSubscriptionOptions, subscriptionRemoved, stableInitialPageParam, stableRefetchCachedPages, endpointName]);
317
- return [promiseRef, dispatch, initiate, stableSubscriptionOptions];
318
- }
319
- function buildUseQueryState(endpointName, preSelector) {
320
- const useQueryState = (arg, {
321
- skip = false,
322
- selectFromResult
323
- } = {}) => {
324
- const {
325
- select
326
- } = api.endpoints[endpointName];
327
- const stableArg = useStableQueryArgs(skip ? import_query.skipToken : arg);
328
- const lastValue = (0, import_react.useRef)(void 0);
329
- const selectDefaultResult = (0, import_react.useMemo)(() => (
330
- // Normally ts-ignores are bad and should be avoided, but we're
331
- // already casting this selector to be `Selector<any>` anyway,
332
- // so the inconsistencies don't matter here
333
- // @ts-ignore
334
- createSelector([
335
- // @ts-ignore
336
- select(stableArg),
337
- (_, lastResult) => lastResult,
338
- (_) => stableArg
339
- ], preSelector, {
340
- memoizeOptions: {
341
- resultEqualityCheck: import_react_redux.shallowEqual
342
- }
343
- })
344
- ), [select, stableArg]);
345
- const querySelector = (0, import_react.useMemo)(() => selectFromResult ? createSelector([selectDefaultResult], selectFromResult, {
346
- devModeChecks: {
347
- identityFunctionCheck: "never"
348
- }
349
- }) : selectDefaultResult, [selectDefaultResult, selectFromResult]);
350
- const currentState = useSelector((state) => querySelector(state, lastValue.current), import_react_redux.shallowEqual);
351
- const store = useStore();
352
- const newLastValue = selectDefaultResult(store.getState(), lastValue.current);
353
- useIsomorphicLayoutEffect(() => {
354
- lastValue.current = newLastValue;
355
- }, [newLastValue]);
356
- return currentState;
357
- };
358
- return useQueryState;
359
- }
360
- function usePromiseRefUnsubscribeOnUnmount(promiseRef) {
361
- (0, import_react.useEffect)(() => {
362
- return () => {
363
- unsubscribePromiseRef(promiseRef);
364
- promiseRef.current = void 0;
365
- };
366
- }, [promiseRef]);
367
- }
368
- function refetchOrErrorIfUnmounted(promiseRef) {
369
- if (!promiseRef.current) throw new Error(false ? _formatProdErrorMessage2(38) : "Cannot refetch a query that has not been started yet.");
370
- return promiseRef.current.refetch();
371
- }
372
- function buildQueryHooks(endpointName) {
373
- const useQuerySubscription = (arg, options = {}) => {
374
- const [promiseRef] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
375
- usePromiseRefUnsubscribeOnUnmount(promiseRef);
376
- return (0, import_react.useMemo)(() => ({
377
- /**
378
- * A method to manually refetch data for the query
379
- */
380
- refetch: () => refetchOrErrorIfUnmounted(promiseRef)
381
- }), [promiseRef]);
382
- };
383
- const useLazyQuerySubscription = ({
384
- refetchOnReconnect,
385
- refetchOnFocus,
386
- pollingInterval = 0,
387
- skipPollingIfUnfocused = false
388
- } = {}) => {
389
- const {
390
- initiate
391
- } = api.endpoints[endpointName];
392
- const dispatch = useDispatch();
393
- const [arg, setArg] = (0, import_react.useState)(UNINITIALIZED_VALUE);
394
- const promiseRef = (0, import_react.useRef)(void 0);
395
- const stableSubscriptionOptions = useShallowStableValue({
396
- refetchOnReconnect,
397
- refetchOnFocus,
398
- pollingInterval,
399
- skipPollingIfUnfocused
400
- });
401
- usePossiblyImmediateEffect(() => {
402
- const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
403
- if (stableSubscriptionOptions !== lastSubscriptionOptions) {
404
- promiseRef.current?.updateSubscriptionOptions(stableSubscriptionOptions);
405
- }
406
- }, [stableSubscriptionOptions]);
407
- const subscriptionOptionsRef = (0, import_react.useRef)(stableSubscriptionOptions);
408
- usePossiblyImmediateEffect(() => {
409
- subscriptionOptionsRef.current = stableSubscriptionOptions;
410
- }, [stableSubscriptionOptions]);
411
- const trigger = (0, import_react.useCallback)(function(arg2, preferCacheValue = false) {
412
- let promise;
413
- batch(() => {
414
- unsubscribePromiseRef(promiseRef);
415
- promiseRef.current = promise = dispatch(initiate(arg2, {
416
- subscriptionOptions: subscriptionOptionsRef.current,
417
- forceRefetch: !preferCacheValue
418
- }));
419
- setArg(arg2);
420
- });
421
- return promise;
422
- }, [dispatch, initiate]);
423
- const reset = (0, import_react.useCallback)(() => {
424
- if (promiseRef.current?.queryCacheKey) {
425
- dispatch(api.internalActions.removeQueryResult({
426
- queryCacheKey: promiseRef.current?.queryCacheKey
427
- }));
428
- }
429
- }, [dispatch]);
430
- (0, import_react.useEffect)(() => {
431
- return () => {
432
- unsubscribePromiseRef(promiseRef);
433
- };
434
- }, []);
435
- (0, import_react.useEffect)(() => {
436
- if (arg !== UNINITIALIZED_VALUE && !promiseRef.current) {
437
- trigger(arg, true);
438
- }
439
- }, [arg, trigger]);
440
- return (0, import_react.useMemo)(() => [trigger, arg, {
441
- reset
442
- }], [trigger, arg, reset]);
443
- };
444
- const useQueryState = buildUseQueryState(endpointName, queryStatePreSelector);
445
- return {
446
- useQueryState,
447
- useQuerySubscription,
448
- useLazyQuerySubscription,
449
- useLazyQuery(options) {
450
- const [trigger, arg, {
451
- reset
452
- }] = useLazyQuerySubscription(options);
453
- const queryStateResults = useQueryState(arg, {
454
- ...options,
455
- skip: arg === UNINITIALIZED_VALUE
456
- });
457
- const info = (0, import_react.useMemo)(() => ({
458
- lastArg: arg
459
- }), [arg]);
460
- return (0, import_react.useMemo)(() => [trigger, {
461
- ...queryStateResults,
462
- reset
463
- }, info], [trigger, queryStateResults, reset, info]);
464
- },
465
- useQuery(arg, options) {
466
- const querySubscriptionResults = useQuerySubscription(arg, options);
467
- const queryStateResults = useQueryState(arg, {
468
- selectFromResult: arg === import_query.skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
469
- ...options
470
- });
471
- const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS);
472
- (0, import_react.useDebugValue)(debugValue);
473
- return (0, import_react.useMemo)(() => ({
474
- ...queryStateResults,
475
- ...querySubscriptionResults
476
- }), [queryStateResults, querySubscriptionResults]);
477
- }
478
- };
479
- }
480
- function buildInfiniteQueryHooks(endpointName) {
481
- const useInfiniteQuerySubscription = (arg, options = {}) => {
482
- const [promiseRef, dispatch, initiate, stableSubscriptionOptions] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
483
- const subscriptionOptionsRef = (0, import_react.useRef)(stableSubscriptionOptions);
484
- usePossiblyImmediateEffect(() => {
485
- subscriptionOptionsRef.current = stableSubscriptionOptions;
486
- }, [stableSubscriptionOptions]);
487
- const hookRefetchCachedPages = options.refetchCachedPages;
488
- const stableHookRefetchCachedPages = useShallowStableValue(hookRefetchCachedPages);
489
- const trigger = (0, import_react.useCallback)(function(arg2, direction) {
490
- let promise;
491
- batch(() => {
492
- unsubscribePromiseRef(promiseRef);
493
- promiseRef.current = promise = dispatch(initiate(arg2, {
494
- subscriptionOptions: subscriptionOptionsRef.current,
495
- direction
496
- }));
497
- });
498
- return promise;
499
- }, [promiseRef, dispatch, initiate]);
500
- usePromiseRefUnsubscribeOnUnmount(promiseRef);
501
- const stableArg = useStableQueryArgs(options.skip ? import_query.skipToken : arg);
502
- const refetch = (0, import_react.useCallback)((options2) => {
503
- if (!promiseRef.current) throw new Error(false ? _formatProdErrorMessage3(38) : "Cannot refetch a query that has not been started yet.");
504
- const mergedOptions = {
505
- refetchCachedPages: options2?.refetchCachedPages ?? stableHookRefetchCachedPages
506
- };
507
- return promiseRef.current.refetch(mergedOptions);
508
- }, [promiseRef, stableHookRefetchCachedPages]);
509
- return (0, import_react.useMemo)(() => {
510
- const fetchNextPage = () => {
511
- return trigger(stableArg, "forward");
512
- };
513
- const fetchPreviousPage = () => {
514
- return trigger(stableArg, "backward");
515
- };
516
- return {
517
- trigger,
518
- /**
519
- * A method to manually refetch data for the query
520
- */
521
- refetch,
522
- fetchNextPage,
523
- fetchPreviousPage
524
- };
525
- }, [refetch, trigger, stableArg]);
526
- };
527
- const useInfiniteQueryState = buildUseQueryState(endpointName, infiniteQueryStatePreSelector);
528
- return {
529
- useInfiniteQueryState,
530
- useInfiniteQuerySubscription,
531
- useInfiniteQuery(arg, options) {
532
- const {
533
- refetch,
534
- fetchNextPage,
535
- fetchPreviousPage
536
- } = useInfiniteQuerySubscription(arg, options);
537
- const queryStateResults = useInfiniteQueryState(arg, {
538
- selectFromResult: arg === import_query.skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
539
- ...options
540
- });
541
- const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS, "hasNextPage", "hasPreviousPage");
542
- (0, import_react.useDebugValue)(debugValue);
543
- return (0, import_react.useMemo)(() => ({
544
- ...queryStateResults,
545
- fetchNextPage,
546
- fetchPreviousPage,
547
- refetch
548
- }), [queryStateResults, fetchNextPage, fetchPreviousPage, refetch]);
549
- }
550
- };
551
- }
552
- function buildMutationHook(name) {
553
- return ({
554
- selectFromResult,
555
- fixedCacheKey
556
- } = {}) => {
557
- const {
558
- select,
559
- initiate
560
- } = api.endpoints[name];
561
- const dispatch = useDispatch();
562
- const [promise, setPromise] = (0, import_react.useState)();
563
- (0, import_react.useEffect)(() => () => {
564
- if (!promise?.arg.fixedCacheKey) {
565
- promise?.reset();
566
- }
567
- }, [promise]);
568
- const triggerMutation = (0, import_react.useCallback)(function(arg) {
569
- const promise2 = dispatch(initiate(arg, {
570
- fixedCacheKey
571
- }));
572
- setPromise(promise2);
573
- return promise2;
574
- }, [dispatch, initiate, fixedCacheKey]);
575
- const {
576
- requestId
577
- } = promise || {};
578
- const selectDefaultResult = (0, import_react.useMemo)(() => select({
579
- fixedCacheKey,
580
- requestId: promise?.requestId
581
- }), [fixedCacheKey, promise, select]);
582
- const mutationSelector = (0, import_react.useMemo)(() => selectFromResult ? createSelector([selectDefaultResult], selectFromResult) : selectDefaultResult, [selectFromResult, selectDefaultResult]);
583
- const currentState = useSelector(mutationSelector, import_react_redux.shallowEqual);
584
- const originalArgs = fixedCacheKey == null ? promise?.arg.originalArgs : void 0;
585
- const reset = (0, import_react.useCallback)(() => {
586
- batch(() => {
587
- if (promise) {
588
- setPromise(void 0);
589
- }
590
- if (fixedCacheKey) {
591
- dispatch(api.internalActions.removeMutationResult({
592
- requestId,
593
- fixedCacheKey
594
- }));
595
- }
596
- });
597
- }, [dispatch, fixedCacheKey, promise, requestId]);
598
- const debugValue = pick(currentState, ...COMMON_HOOK_DEBUG_FIELDS, "endpointName");
599
- (0, import_react.useDebugValue)(debugValue);
600
- const finalState = (0, import_react.useMemo)(() => ({
601
- ...currentState,
602
- originalArgs,
603
- reset
604
- }), [currentState, originalArgs, reset]);
605
- return (0, import_react.useMemo)(() => [triggerMutation, finalState], [triggerMutation, finalState]);
606
- };
607
- }
206
+ subscriptionSelectorsRef.current = returnedValue;
207
+ }
208
+ const stableArg = useStableQueryArgs(skip ? _reduxjs_toolkit_query.skipToken : arg);
209
+ const stableSubscriptionOptions = useShallowStableValue({
210
+ refetchOnReconnect,
211
+ refetchOnFocus,
212
+ pollingInterval,
213
+ skipPollingIfUnfocused
214
+ });
215
+ const initialPageParam = rest.initialPageParam;
216
+ const stableInitialPageParam = useShallowStableValue(initialPageParam);
217
+ const refetchCachedPages = rest.refetchCachedPages;
218
+ const stableRefetchCachedPages = useShallowStableValue(refetchCachedPages);
219
+ const promiseRef = (0, react.useRef)(void 0);
220
+ let { queryCacheKey, requestId } = promiseRef.current || {};
221
+ let currentRenderHasSubscription = false;
222
+ if (queryCacheKey && requestId) currentRenderHasSubscription = subscriptionSelectorsRef.current.isRequestSubscribed(queryCacheKey, requestId);
223
+ const subscriptionRemoved = !currentRenderHasSubscription && promiseRef.current !== void 0;
224
+ usePossiblyImmediateEffect(() => {
225
+ if (subscriptionRemoved) promiseRef.current = void 0;
226
+ }, [subscriptionRemoved]);
227
+ usePossiblyImmediateEffect(() => {
228
+ const lastPromise = promiseRef.current;
229
+ if (stableArg === _reduxjs_toolkit_query.skipToken) {
230
+ lastPromise?.unsubscribe();
231
+ promiseRef.current = void 0;
232
+ return;
233
+ }
234
+ const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
235
+ if (!lastPromise || lastPromise.arg !== stableArg) {
236
+ lastPromise?.unsubscribe();
237
+ const promise = dispatch(initiate(stableArg, {
238
+ subscriptionOptions: stableSubscriptionOptions,
239
+ forceRefetch: refetchOnMountOrArgChange,
240
+ ...isInfiniteQueryDefinition(endpointDefinitions[endpointName]) ? {
241
+ initialPageParam: stableInitialPageParam,
242
+ refetchCachedPages: stableRefetchCachedPages
243
+ } : {}
244
+ }));
245
+ promiseRef.current = promise;
246
+ } else if (stableSubscriptionOptions !== lastSubscriptionOptions) lastPromise.updateSubscriptionOptions(stableSubscriptionOptions);
247
+ }, [
248
+ dispatch,
249
+ initiate,
250
+ refetchOnMountOrArgChange,
251
+ stableArg,
252
+ stableSubscriptionOptions,
253
+ subscriptionRemoved,
254
+ stableInitialPageParam,
255
+ stableRefetchCachedPages,
256
+ endpointName
257
+ ]);
258
+ return [
259
+ promiseRef,
260
+ dispatch,
261
+ initiate,
262
+ stableSubscriptionOptions
263
+ ];
264
+ }
265
+ function buildUseQueryState(endpointName, preSelector) {
266
+ const useQueryState = (arg, { skip = false, selectFromResult } = {}) => {
267
+ const { select } = api.endpoints[endpointName];
268
+ const stableArg = useStableQueryArgs(skip ? _reduxjs_toolkit_query.skipToken : arg);
269
+ const lastValue = (0, react.useRef)(void 0);
270
+ const latestDefaultResult = (0, react.useRef)(void 0);
271
+ const selectDefaultResult = (0, react.useMemo)(() => createSelector([
272
+ select(stableArg),
273
+ (_, lastResult) => lastResult,
274
+ (_) => stableArg
275
+ ], preSelector, { memoizeOptions: { resultEqualityCheck: react_redux.shallowEqual } }), [select, stableArg]);
276
+ const currentState = useSelector((0, react.useMemo)(() => {
277
+ const selectResult = selectFromResult ? createSelector([selectDefaultResult], selectFromResult, { devModeChecks: { identityFunctionCheck: "never" } }) : selectDefaultResult;
278
+ return (state) => {
279
+ const lastResult = lastValue.current;
280
+ const result = selectResult(state, lastResult);
281
+ latestDefaultResult.current = selectDefaultResult(state, lastResult);
282
+ return result;
283
+ };
284
+ }, [selectDefaultResult, selectFromResult]), react_redux.shallowEqual);
285
+ useIsomorphicLayoutEffect(() => {
286
+ lastValue.current = latestDefaultResult.current;
287
+ });
288
+ return currentState;
289
+ };
290
+ return useQueryState;
291
+ }
292
+ function usePromiseRefUnsubscribeOnUnmount(promiseRef) {
293
+ (0, react.useEffect)(() => {
294
+ return () => {
295
+ unsubscribePromiseRef(promiseRef);
296
+ };
297
+ }, [promiseRef]);
298
+ }
299
+ function refetchOrErrorIfUnmounted(promiseRef) {
300
+ if (!promiseRef.current) throw new Error("Cannot refetch a query that has not been started yet.");
301
+ return promiseRef.current.refetch();
302
+ }
303
+ function buildQueryHooks(endpointName) {
304
+ const useQuerySubscription = (arg, options = {}) => {
305
+ const [promiseRef] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
306
+ usePromiseRefUnsubscribeOnUnmount(promiseRef);
307
+ return (0, react.useMemo)(() => ({ refetch: () => refetchOrErrorIfUnmounted(promiseRef) }), [promiseRef]);
308
+ };
309
+ const useLazyQuerySubscription = ({ refetchOnReconnect, refetchOnFocus, pollingInterval = 0, skipPollingIfUnfocused = false } = {}) => {
310
+ const { initiate } = api.endpoints[endpointName];
311
+ const dispatch = useDispatch();
312
+ const [arg, setArg] = (0, react.useState)(UNINITIALIZED_VALUE);
313
+ const promiseRef = (0, react.useRef)(void 0);
314
+ const stableSubscriptionOptions = useShallowStableValue({
315
+ refetchOnReconnect,
316
+ refetchOnFocus,
317
+ pollingInterval,
318
+ skipPollingIfUnfocused
319
+ });
320
+ usePossiblyImmediateEffect(() => {
321
+ const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
322
+ if (stableSubscriptionOptions !== lastSubscriptionOptions) promiseRef.current?.updateSubscriptionOptions(stableSubscriptionOptions);
323
+ }, [stableSubscriptionOptions]);
324
+ const subscriptionOptionsRef = (0, react.useRef)(stableSubscriptionOptions);
325
+ usePossiblyImmediateEffect(() => {
326
+ subscriptionOptionsRef.current = stableSubscriptionOptions;
327
+ }, [stableSubscriptionOptions]);
328
+ const trigger = (0, react.useCallback)(function(arg, preferCacheValue = false) {
329
+ let promise;
330
+ batch(() => {
331
+ unsubscribePromiseRef(promiseRef);
332
+ promiseRef.current = promise = dispatch(initiate(arg, {
333
+ subscriptionOptions: subscriptionOptionsRef.current,
334
+ forceRefetch: !preferCacheValue
335
+ }));
336
+ setArg(arg);
337
+ });
338
+ return promise;
339
+ }, [dispatch, initiate]);
340
+ const reset = (0, react.useCallback)(() => {
341
+ if (promiseRef.current?.queryCacheKey) dispatch(api.internalActions.removeQueryResult({ queryCacheKey: promiseRef.current?.queryCacheKey }));
342
+ }, [dispatch]);
343
+ (0, react.useEffect)(() => {
344
+ return () => {
345
+ unsubscribePromiseRef(promiseRef);
346
+ };
347
+ }, []);
348
+ (0, react.useEffect)(() => {
349
+ if (arg !== UNINITIALIZED_VALUE && !promiseRef.current) trigger(arg, true);
350
+ }, [arg, trigger]);
351
+ return (0, react.useMemo)(() => [
352
+ trigger,
353
+ arg,
354
+ { reset }
355
+ ], [
356
+ trigger,
357
+ arg,
358
+ reset
359
+ ]);
360
+ };
361
+ const useQueryState = buildUseQueryState(endpointName, queryStatePreSelector);
362
+ return {
363
+ useQueryState,
364
+ useQuerySubscription,
365
+ useLazyQuerySubscription,
366
+ useLazyQuery(options) {
367
+ const [trigger, arg, { reset }] = useLazyQuerySubscription(options);
368
+ const queryStateResults = useQueryState(arg, {
369
+ ...options,
370
+ skip: arg === UNINITIALIZED_VALUE
371
+ });
372
+ const info = (0, react.useMemo)(() => ({ lastArg: arg }), [arg]);
373
+ return (0, react.useMemo)(() => [
374
+ trigger,
375
+ {
376
+ ...queryStateResults,
377
+ reset
378
+ },
379
+ info
380
+ ], [
381
+ trigger,
382
+ queryStateResults,
383
+ reset,
384
+ info
385
+ ]);
386
+ },
387
+ useQuery(arg, options) {
388
+ const querySubscriptionResults = useQuerySubscription(arg, options);
389
+ const queryStateResults = useQueryState(arg, {
390
+ selectFromResult: arg === _reduxjs_toolkit_query.skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
391
+ ...options
392
+ });
393
+ const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS);
394
+ (0, react.useDebugValue)(debugValue);
395
+ return (0, react.useMemo)(() => ({
396
+ ...queryStateResults,
397
+ ...querySubscriptionResults
398
+ }), [queryStateResults, querySubscriptionResults]);
399
+ }
400
+ };
401
+ }
402
+ function buildInfiniteQueryHooks(endpointName) {
403
+ const useInfiniteQuerySubscription = (arg, options = {}) => {
404
+ const [promiseRef, dispatch, initiate, stableSubscriptionOptions] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
405
+ const subscriptionOptionsRef = (0, react.useRef)(stableSubscriptionOptions);
406
+ usePossiblyImmediateEffect(() => {
407
+ subscriptionOptionsRef.current = stableSubscriptionOptions;
408
+ }, [stableSubscriptionOptions]);
409
+ const hookRefetchCachedPages = options.refetchCachedPages;
410
+ const stableHookRefetchCachedPages = useShallowStableValue(hookRefetchCachedPages);
411
+ const trigger = (0, react.useCallback)(function(arg, direction) {
412
+ let promise;
413
+ batch(() => {
414
+ unsubscribePromiseRef(promiseRef);
415
+ promiseRef.current = promise = dispatch(initiate(arg, {
416
+ subscriptionOptions: subscriptionOptionsRef.current,
417
+ direction
418
+ }));
419
+ });
420
+ return promise;
421
+ }, [
422
+ promiseRef,
423
+ dispatch,
424
+ initiate
425
+ ]);
426
+ usePromiseRefUnsubscribeOnUnmount(promiseRef);
427
+ const stableArg = useStableQueryArgs(options.skip ? _reduxjs_toolkit_query.skipToken : arg);
428
+ const refetch = (0, react.useCallback)((options) => {
429
+ if (!promiseRef.current) throw new Error("Cannot refetch a query that has not been started yet.");
430
+ const mergedOptions = { refetchCachedPages: options?.refetchCachedPages ?? stableHookRefetchCachedPages };
431
+ return promiseRef.current.refetch(mergedOptions);
432
+ }, [promiseRef, stableHookRefetchCachedPages]);
433
+ return (0, react.useMemo)(() => {
434
+ const fetchNextPage = () => {
435
+ return trigger(stableArg, "forward");
436
+ };
437
+ const fetchPreviousPage = () => {
438
+ return trigger(stableArg, "backward");
439
+ };
440
+ return {
441
+ trigger,
442
+ refetch,
443
+ fetchNextPage,
444
+ fetchPreviousPage
445
+ };
446
+ }, [
447
+ refetch,
448
+ trigger,
449
+ stableArg
450
+ ]);
451
+ };
452
+ const useInfiniteQueryState = buildUseQueryState(endpointName, infiniteQueryStatePreSelector);
453
+ return {
454
+ useInfiniteQueryState,
455
+ useInfiniteQuerySubscription,
456
+ useInfiniteQuery(arg, options) {
457
+ const { refetch, fetchNextPage, fetchPreviousPage } = useInfiniteQuerySubscription(arg, options);
458
+ const queryStateResults = useInfiniteQueryState(arg, {
459
+ selectFromResult: arg === _reduxjs_toolkit_query.skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
460
+ ...options
461
+ });
462
+ const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS, "hasNextPage", "hasPreviousPage");
463
+ (0, react.useDebugValue)(debugValue);
464
+ return (0, react.useMemo)(() => ({
465
+ ...queryStateResults,
466
+ fetchNextPage,
467
+ fetchPreviousPage,
468
+ refetch
469
+ }), [
470
+ queryStateResults,
471
+ fetchNextPage,
472
+ fetchPreviousPage,
473
+ refetch
474
+ ]);
475
+ }
476
+ };
477
+ }
478
+ function buildMutationHook(name) {
479
+ return ({ selectFromResult, fixedCacheKey } = {}) => {
480
+ const { select, initiate } = api.endpoints[name];
481
+ const dispatch = useDispatch();
482
+ const [promise, setPromise] = (0, react.useState)();
483
+ (0, react.useEffect)(() => () => {
484
+ if (!promise?.arg.fixedCacheKey) promise?.reset();
485
+ }, [promise]);
486
+ const triggerMutation = (0, react.useCallback)(function(arg) {
487
+ const promise = dispatch(initiate(arg, { fixedCacheKey }));
488
+ setPromise(promise);
489
+ return promise;
490
+ }, [
491
+ dispatch,
492
+ initiate,
493
+ fixedCacheKey
494
+ ]);
495
+ const { requestId } = promise || {};
496
+ const selectDefaultResult = (0, react.useMemo)(() => select({
497
+ fixedCacheKey,
498
+ requestId: promise?.requestId
499
+ }), [
500
+ fixedCacheKey,
501
+ promise,
502
+ select
503
+ ]);
504
+ const currentState = useSelector((0, react.useMemo)(() => selectFromResult ? createSelector([selectDefaultResult], selectFromResult) : selectDefaultResult, [selectFromResult, selectDefaultResult]), react_redux.shallowEqual);
505
+ const originalArgs = fixedCacheKey == null ? promise?.arg.originalArgs : void 0;
506
+ const reset = (0, react.useCallback)(() => {
507
+ batch(() => {
508
+ if (promise) setPromise(void 0);
509
+ if (fixedCacheKey) dispatch(api.internalActions.removeMutationResult({
510
+ requestId,
511
+ fixedCacheKey
512
+ }));
513
+ });
514
+ }, [
515
+ dispatch,
516
+ fixedCacheKey,
517
+ promise,
518
+ requestId
519
+ ]);
520
+ const debugValue = pick(currentState, ...COMMON_HOOK_DEBUG_FIELDS, "endpointName");
521
+ (0, react.useDebugValue)(debugValue);
522
+ const finalState = (0, react.useMemo)(() => ({
523
+ ...currentState,
524
+ originalArgs,
525
+ reset
526
+ }), [
527
+ currentState,
528
+ originalArgs,
529
+ reset
530
+ ]);
531
+ return (0, react.useMemo)(() => [triggerMutation, finalState], [triggerMutation, finalState]);
532
+ };
533
+ }
608
534
  }
609
-
610
- // src/query/react/module.ts
611
- var reactHooksModuleName = /* @__PURE__ */ Symbol();
612
- var reactHooksModule = ({
613
- batch = import_react_redux2.batch,
614
- hooks = {
615
- useDispatch: import_react_redux2.useDispatch,
616
- useSelector: import_react_redux2.useSelector,
617
- useStore: import_react_redux2.useStore
618
- },
619
- createSelector = import_reselect.createSelector,
620
- unstable__sideEffectsInRender = false,
621
- ...rest
622
- } = {}) => {
623
- if (true) {
624
- const hookNames = ["useDispatch", "useSelector", "useStore"];
625
- let warned = false;
626
- for (const hookName of hookNames) {
627
- if (countObjectKeys(rest) > 0) {
628
- if (rest[hookName]) {
629
- if (!warned) {
630
- console.warn("As of RTK 2.0, the hooks now need to be specified as one object, provided under a `hooks` key:\n`reactHooksModule({ hooks: { useDispatch, useSelector, useStore } })`");
631
- warned = true;
632
- }
633
- }
634
- hooks[hookName] = rest[hookName];
635
- }
636
- if (typeof hooks[hookName] !== "function") {
637
- throw new Error(false ? _formatProdErrorMessage4(36) : `When using custom hooks for context, all ${hookNames.length} hooks need to be provided: ${hookNames.join(", ")}.
638
- Hook ${hookName} was either not provided or not a function.`);
639
- }
640
- }
641
- }
642
- return {
643
- name: reactHooksModuleName,
644
- init(api, {
645
- serializeQueryArgs
646
- }, context) {
647
- const anyApi = api;
648
- const {
649
- buildQueryHooks,
650
- buildInfiniteQueryHooks,
651
- buildMutationHook,
652
- usePrefetch
653
- } = buildHooks({
654
- api,
655
- moduleOptions: {
656
- batch,
657
- hooks,
658
- unstable__sideEffectsInRender,
659
- createSelector
660
- },
661
- serializeQueryArgs,
662
- context
663
- });
664
- safeAssign(anyApi, {
665
- usePrefetch
666
- });
667
- safeAssign(context, {
668
- batch
669
- });
670
- return {
671
- injectEndpoint(endpointName, definition) {
672
- if (isQueryDefinition(definition)) {
673
- const {
674
- useQuery,
675
- useLazyQuery,
676
- useLazyQuerySubscription,
677
- useQueryState,
678
- useQuerySubscription
679
- } = buildQueryHooks(endpointName);
680
- safeAssign(anyApi.endpoints[endpointName], {
681
- useQuery,
682
- useLazyQuery,
683
- useLazyQuerySubscription,
684
- useQueryState,
685
- useQuerySubscription
686
- });
687
- api[`use${capitalize(endpointName)}Query`] = useQuery;
688
- api[`useLazy${capitalize(endpointName)}Query`] = useLazyQuery;
689
- }
690
- if (isMutationDefinition(definition)) {
691
- const useMutation = buildMutationHook(endpointName);
692
- safeAssign(anyApi.endpoints[endpointName], {
693
- useMutation
694
- });
695
- api[`use${capitalize(endpointName)}Mutation`] = useMutation;
696
- } else if (isInfiniteQueryDefinition(definition)) {
697
- const {
698
- useInfiniteQuery,
699
- useInfiniteQuerySubscription,
700
- useInfiniteQueryState
701
- } = buildInfiniteQueryHooks(endpointName);
702
- safeAssign(anyApi.endpoints[endpointName], {
703
- useInfiniteQuery,
704
- useInfiniteQuerySubscription,
705
- useInfiniteQueryState
706
- });
707
- api[`use${capitalize(endpointName)}InfiniteQuery`] = useInfiniteQuery;
708
- }
709
- }
710
- };
711
- }
712
- };
535
+ //#endregion
536
+ //#region src/query/react/module.ts
537
+ const reactHooksModuleName = /* @__PURE__ */ Symbol();
538
+ const reactHooksModule = ({ batch = react_redux.batch, hooks = {
539
+ useDispatch: react_redux.useDispatch,
540
+ useSelector: react_redux.useSelector,
541
+ useStore: react_redux.useStore
542
+ }, createSelector = reselect.createSelector, unstable__sideEffectsInRender = false, ...rest } = {}) => {
543
+ {
544
+ const hookNames = [
545
+ "useDispatch",
546
+ "useSelector",
547
+ "useStore"
548
+ ];
549
+ let warned = false;
550
+ for (const hookName of hookNames) {
551
+ if (countObjectKeys(rest) > 0) {
552
+ if (rest[hookName]) {
553
+ if (!warned) {
554
+ console.warn("As of RTK 2.0, the hooks now need to be specified as one object, provided under a `hooks` key:\n`reactHooksModule({ hooks: { useDispatch, useSelector, useStore } })`");
555
+ warned = true;
556
+ }
557
+ }
558
+ hooks[hookName] = rest[hookName];
559
+ }
560
+ if (typeof hooks[hookName] !== "function") throw new Error(`When using custom hooks for context, all ${hookNames.length} hooks need to be provided: ${hookNames.join(", ")}.\nHook ${hookName} was either not provided or not a function.`);
561
+ }
562
+ }
563
+ return {
564
+ name: reactHooksModuleName,
565
+ init(api, { serializeQueryArgs }, context) {
566
+ const anyApi = api;
567
+ const { buildQueryHooks, buildInfiniteQueryHooks, buildMutationHook, usePrefetch } = buildHooks({
568
+ api,
569
+ moduleOptions: {
570
+ batch,
571
+ hooks,
572
+ unstable__sideEffectsInRender,
573
+ createSelector
574
+ },
575
+ serializeQueryArgs,
576
+ context
577
+ });
578
+ safeAssign(anyApi, { usePrefetch });
579
+ safeAssign(context, { batch });
580
+ return { injectEndpoint(endpointName, definition) {
581
+ if (isQueryDefinition(definition)) {
582
+ const { useQuery, useLazyQuery, useLazyQuerySubscription, useQueryState, useQuerySubscription } = buildQueryHooks(endpointName);
583
+ safeAssign(anyApi.endpoints[endpointName], {
584
+ useQuery,
585
+ useLazyQuery,
586
+ useLazyQuerySubscription,
587
+ useQueryState,
588
+ useQuerySubscription
589
+ });
590
+ api[`use${capitalize(endpointName)}Query`] = useQuery;
591
+ api[`useLazy${capitalize(endpointName)}Query`] = useLazyQuery;
592
+ }
593
+ if (isMutationDefinition(definition)) {
594
+ const useMutation = buildMutationHook(endpointName);
595
+ safeAssign(anyApi.endpoints[endpointName], { useMutation });
596
+ api[`use${capitalize(endpointName)}Mutation`] = useMutation;
597
+ } else if (isInfiniteQueryDefinition(definition)) {
598
+ const { useInfiniteQuery, useInfiniteQuerySubscription, useInfiniteQueryState } = buildInfiniteQueryHooks(endpointName);
599
+ safeAssign(anyApi.endpoints[endpointName], {
600
+ useInfiniteQuery,
601
+ useInfiniteQuerySubscription,
602
+ useInfiniteQueryState
603
+ });
604
+ api[`use${capitalize(endpointName)}InfiniteQuery`] = useInfiniteQuery;
605
+ }
606
+ } };
607
+ }
608
+ };
713
609
  };
714
-
715
- // src/query/react/index.ts
716
- __reExport(react_exports, require("@reduxjs/toolkit/query"), module.exports);
717
-
718
- // src/query/react/ApiProvider.tsx
719
- var import_toolkit3 = require("@reduxjs/toolkit");
720
- var React = __toESM(require("react"));
610
+ //#endregion
611
+ //#region src/query/react/ApiProvider.tsx
721
612
  function ApiProvider(props) {
722
- const context = props.context || import_react_redux.ReactReduxContext;
723
- const existingContext = (0, import_react.useContext)(context);
724
- if (existingContext) {
725
- throw new Error(false ? _formatProdErrorMessage5(35) : "Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.");
726
- }
727
- const [store] = React.useState(() => (0, import_toolkit3.configureStore)({
728
- reducer: {
729
- [props.api.reducerPath]: props.api.reducer
730
- },
731
- middleware: (gDM) => gDM().concat(props.api.middleware)
732
- }));
733
- (0, import_react.useEffect)(() => props.setupListeners === false ? void 0 : (0, import_query.setupListeners)(store.dispatch, props.setupListeners), [props.setupListeners, store.dispatch]);
734
- return /* @__PURE__ */ React.createElement(import_react_redux.Provider, { store, context }, props.children);
613
+ const context = props.context || react_redux.ReactReduxContext;
614
+ if ((0, react.useContext)(context)) throw new Error("Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.");
615
+ const [store] = react.useState(() => (0, _reduxjs_toolkit.configureStore)({
616
+ reducer: { [props.api.reducerPath]: props.api.reducer },
617
+ middleware: (gDM) => gDM().concat(props.api.middleware)
618
+ }));
619
+ (0, react.useEffect)(() => props.setupListeners === false ? void 0 : (0, _reduxjs_toolkit_query.setupListeners)(store.dispatch, props.setupListeners), [props.setupListeners, store.dispatch]);
620
+ return /* @__PURE__ */ react.createElement(react_redux.Provider, {
621
+ store,
622
+ context
623
+ }, props.children);
735
624
  }
736
-
737
- // src/query/react/index.ts
738
- var createApi = /* @__PURE__ */ (0, import_query.buildCreateApi)((0, import_query.coreModule)(), reactHooksModule());
739
- // Annotate the CommonJS export names for ESM import in node:
740
- 0 && (module.exports = {
741
- ApiProvider,
742
- UNINITIALIZED_VALUE,
743
- createApi,
744
- reactHooksModule,
745
- reactHooksModuleName,
746
- ...require("@reduxjs/toolkit/query")
625
+ //#endregion
626
+ //#region src/query/react/index.ts
627
+ const createApi = /* @__PURE__ */ (0, _reduxjs_toolkit_query.buildCreateApi)((0, _reduxjs_toolkit_query.coreModule)(), reactHooksModule());
628
+ //#endregion
629
+ exports.ApiProvider = ApiProvider;
630
+ exports.UNINITIALIZED_VALUE = UNINITIALIZED_VALUE;
631
+ exports.createApi = createApi;
632
+ exports.reactHooksModule = reactHooksModule;
633
+ exports.reactHooksModuleName = reactHooksModuleName;
634
+ Object.keys(_reduxjs_toolkit_query).forEach(function(k) {
635
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
636
+ enumerable: true,
637
+ get: function() {
638
+ return _reduxjs_toolkit_query[k];
639
+ }
640
+ });
747
641
  });
642
+
748
643
  //# sourceMappingURL=rtk-query-react.development.cjs.map