Debian Codegraph @

install/freeipa-webui/node_modules/@reduxjs/toolkit/dist/query/react/rtk-query-react.modern.mjs

raw
1 // src/query/react/index.ts
2 import { buildCreateApi, coreModule } from "@reduxjs/toolkit/query";
3
4 // src/query/react/module.ts
5 import { formatProdErrorMessage as _formatProdErrorMessage3 } from "@reduxjs/toolkit";
6 import { batch as rrBatch, useDispatch as rrUseDispatch, useSelector as rrUseSelector, useStore as rrUseStore } from "react-redux";
7 import { createSelector as _createSelector } from "reselect";
8
9 // src/query/utils/capitalize.ts
10 function capitalize(str) {
11 return str.replace(str[0], str[0].toUpperCase());
12 }
13
14 // src/query/utils/countObjectKeys.ts
15 function countObjectKeys(obj) {
16 let count = 0;
17 for (const _key in obj) {
18 count++;
19 }
20 return count;
21 }
22
23 // src/query/endpointDefinitions.ts
24 function isQueryDefinition(e) {
25 return e.type === "query" /* query */;
26 }
27 function isMutationDefinition(e) {
28 return e.type === "mutation" /* mutation */;
29 }
30 function isInfiniteQueryDefinition(e) {
31 return e.type === "infinitequery" /* infinitequery */;
32 }
33
34 // src/query/tsHelpers.ts
35 function safeAssign(target, ...args) {
36 return Object.assign(target, ...args);
37 }
38
39 // src/query/react/buildHooks.ts
40 import { formatProdErrorMessage as _formatProdErrorMessage, formatProdErrorMessage as _formatProdErrorMessage2 } from "@reduxjs/toolkit";
41 import { defaultSerializeQueryArgs, QueryStatus, skipToken } from "@reduxjs/toolkit/query";
42 import { useCallback, useDebugValue, useEffect as useEffect3, useLayoutEffect, useMemo as useMemo2, useRef as useRef3, useState } from "react";
43 import { shallowEqual as shallowEqual2 } from "react-redux";
44
45 // src/query/react/constants.ts
46 var UNINITIALIZED_VALUE = Symbol();
47
48 // src/query/react/useSerializedStableValue.ts
49 import { useEffect, useRef, useMemo } from "react";
50 function useStableQueryArgs(queryArgs, serialize, endpointDefinition, endpointName) {
51 const incoming = useMemo(() => ({
52 queryArgs,
53 serialized: typeof queryArgs == "object" ? serialize({
54 queryArgs,
55 endpointDefinition,
56 endpointName
57 }) : queryArgs
58 }), [queryArgs, serialize, endpointDefinition, endpointName]);
59 const cache = useRef(incoming);
60 useEffect(() => {
61 if (cache.current.serialized !== incoming.serialized) {
62 cache.current = incoming;
63 }
64 }, [incoming]);
65 return cache.current.serialized === incoming.serialized ? cache.current.queryArgs : queryArgs;
66 }
67
68 // src/query/react/useShallowStableValue.ts
69 import { useEffect as useEffect2, useRef as useRef2 } from "react";
70 import { shallowEqual } from "react-redux";
71 function useShallowStableValue(value) {
72 const cache = useRef2(value);
73 useEffect2(() => {
74 if (!shallowEqual(cache.current, value)) {
75 cache.current = value;
76 }
77 }, [value]);
78 return shallowEqual(cache.current, value) ? cache.current : value;
79 }
80
81 // src/query/react/buildHooks.ts
82 var canUseDOM = () => !!(typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined");
83 var isDOM = /* @__PURE__ */ canUseDOM();
84 var isRunningInReactNative = () => typeof navigator !== "undefined" && navigator.product === "ReactNative";
85 var isReactNative = /* @__PURE__ */ isRunningInReactNative();
86 var getUseIsomorphicLayoutEffect = () => isDOM || isReactNative ? useLayoutEffect : useEffect3;
87 var useIsomorphicLayoutEffect = /* @__PURE__ */ getUseIsomorphicLayoutEffect();
88 var noPendingQueryStateSelector = (selected) => {
89 if (selected.isUninitialized) {
90 return {
91 ...selected,
92 isUninitialized: false,
93 isFetching: true,
94 isLoading: selected.data !== void 0 ? false : true,
95 status: QueryStatus.pending
96 };
97 }
98 return selected;
99 };
100 function pick(obj, ...keys) {
101 const ret = {};
102 keys.forEach((key) => {
103 ret[key] = obj[key];
104 });
105 return ret;
106 }
107 var COMMON_HOOK_DEBUG_FIELDS = ["data", "status", "isLoading", "isSuccess", "isError", "error"];
108 function buildHooks({
109 api,
110 moduleOptions: {
111 batch,
112 hooks: {
113 useDispatch,
114 useSelector,
115 useStore
116 },
117 unstable__sideEffectsInRender,
118 createSelector
119 },
120 serializeQueryArgs,
121 context
122 }) {
123 const usePossiblyImmediateEffect = unstable__sideEffectsInRender ? (cb) => cb() : useEffect3;
124 return {
125 buildQueryHooks,
126 buildInfiniteQueryHooks,
127 buildMutationHook,
128 usePrefetch
129 };
130 function queryStatePreSelector(currentState, lastResult, queryArgs) {
131 if (lastResult?.endpointName && currentState.isUninitialized) {
132 const {
133 endpointName
134 } = lastResult;
135 const endpointDefinition = context.endpointDefinitions[endpointName];
136 if (queryArgs !== skipToken && serializeQueryArgs({
137 queryArgs: lastResult.originalArgs,
138 endpointDefinition,
139 endpointName
140 }) === serializeQueryArgs({
141 queryArgs,
142 endpointDefinition,
143 endpointName
144 })) lastResult = void 0;
145 }
146 let data = currentState.isSuccess ? currentState.data : lastResult?.data;
147 if (data === void 0) data = currentState.data;
148 const hasData = data !== void 0;
149 const isFetching = currentState.isLoading;
150 const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
151 const isSuccess = currentState.isSuccess || hasData && (isFetching && !lastResult?.isError || currentState.isUninitialized);
152 return {
153 ...currentState,
154 data,
155 currentData: currentState.data,
156 isFetching,
157 isLoading,
158 isSuccess
159 };
160 }
161 function infiniteQueryStatePreSelector(currentState, lastResult, queryArgs) {
162 if (lastResult?.endpointName && currentState.isUninitialized) {
163 const {
164 endpointName
165 } = lastResult;
166 const endpointDefinition = context.endpointDefinitions[endpointName];
167 if (serializeQueryArgs({
168 queryArgs: lastResult.originalArgs,
169 endpointDefinition,
170 endpointName
171 }) === serializeQueryArgs({
172 queryArgs,
173 endpointDefinition,
174 endpointName
175 })) lastResult = void 0;
176 }
177 let data = currentState.isSuccess ? currentState.data : lastResult?.data;
178 if (data === void 0) data = currentState.data;
179 const hasData = data !== void 0;
180 const isFetching = currentState.isLoading;
181 const isLoading = (!lastResult || lastResult.isLoading || lastResult.isUninitialized) && !hasData && isFetching;
182 const isSuccess = currentState.isSuccess || isFetching && hasData;
183 return {
184 ...currentState,
185 data,
186 currentData: currentState.data,
187 isFetching,
188 isLoading,
189 isSuccess
190 };
191 }
192 function usePrefetch(endpointName, defaultOptions) {
193 const dispatch = useDispatch();
194 const stableDefaultOptions = useShallowStableValue(defaultOptions);
195 return useCallback((arg, options) => dispatch(api.util.prefetch(endpointName, arg, {
196 ...stableDefaultOptions,
197 ...options
198 })), [endpointName, dispatch, stableDefaultOptions]);
199 }
200 function useQuerySubscriptionCommonImpl(endpointName, arg, {
201 refetchOnReconnect,
202 refetchOnFocus,
203 refetchOnMountOrArgChange,
204 skip = false,
205 pollingInterval = 0,
206 skipPollingIfUnfocused = false,
207 ...rest
208 } = {}) {
209 const {
210 initiate
211 } = api.endpoints[endpointName];
212 const dispatch = useDispatch();
213 const subscriptionSelectorsRef = useRef3(void 0);
214 if (!subscriptionSelectorsRef.current) {
215 const returnedValue = dispatch(api.internalActions.internal_getRTKQSubscriptions());
216 if (process.env.NODE_ENV !== "production") {
217 if (typeof returnedValue !== "object" || typeof returnedValue?.type === "string") {
218 throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage(37) : `Warning: Middleware for RTK-Query API at reducerPath "${api.reducerPath}" has not been added to the store.
219 You must add the middleware for RTK-Query to function correctly!`);
220 }
221 }
222 subscriptionSelectorsRef.current = returnedValue;
223 }
224 const stableArg = useStableQueryArgs(
225 skip ? skipToken : arg,
226 // Even if the user provided a per-endpoint `serializeQueryArgs` with
227 // a consistent return value, _here_ we want to use the default behavior
228 // so we can tell if _anything_ actually changed. Otherwise, we can end up
229 // with a case where the query args did change but the serialization doesn't,
230 // and then we never try to initiate a refetch.
231 defaultSerializeQueryArgs,
232 context.endpointDefinitions[endpointName],
233 endpointName
234 );
235 const stableSubscriptionOptions = useShallowStableValue({
236 refetchOnReconnect,
237 refetchOnFocus,
238 pollingInterval,
239 skipPollingIfUnfocused
240 });
241 const lastRenderHadSubscription = useRef3(false);
242 const initialPageParam = rest.initialPageParam;
243 const stableInitialPageParam = useShallowStableValue(initialPageParam);
244 const promiseRef = useRef3(void 0);
245 let {
246 queryCacheKey,
247 requestId
248 } = promiseRef.current || {};
249 let currentRenderHasSubscription = false;
250 if (queryCacheKey && requestId) {
251 currentRenderHasSubscription = subscriptionSelectorsRef.current.isRequestSubscribed(queryCacheKey, requestId);
252 }
253 const subscriptionRemoved = !currentRenderHasSubscription && lastRenderHadSubscription.current;
254 usePossiblyImmediateEffect(() => {
255 lastRenderHadSubscription.current = currentRenderHasSubscription;
256 });
257 usePossiblyImmediateEffect(() => {
258 if (subscriptionRemoved) {
259 promiseRef.current = void 0;
260 }
261 }, [subscriptionRemoved]);
262 usePossiblyImmediateEffect(() => {
263 const lastPromise = promiseRef.current;
264 if (typeof process !== "undefined" && process.env.NODE_ENV === "removeMeOnCompilation") {
265 console.log(subscriptionRemoved);
266 }
267 if (stableArg === skipToken) {
268 lastPromise?.unsubscribe();
269 promiseRef.current = void 0;
270 return;
271 }
272 const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
273 if (!lastPromise || lastPromise.arg !== stableArg) {
274 lastPromise?.unsubscribe();
275 const promise = dispatch(initiate(stableArg, {
276 subscriptionOptions: stableSubscriptionOptions,
277 forceRefetch: refetchOnMountOrArgChange,
278 ...isInfiniteQueryDefinition(context.endpointDefinitions[endpointName]) ? {
279 initialPageParam: stableInitialPageParam
280 } : {}
281 }));
282 promiseRef.current = promise;
283 } else if (stableSubscriptionOptions !== lastSubscriptionOptions) {
284 lastPromise.updateSubscriptionOptions(stableSubscriptionOptions);
285 }
286 }, [dispatch, initiate, refetchOnMountOrArgChange, stableArg, stableSubscriptionOptions, subscriptionRemoved, stableInitialPageParam, endpointName]);
287 return [promiseRef, dispatch, initiate, stableSubscriptionOptions];
288 }
289 function buildUseQueryState(endpointName, preSelector) {
290 const useQueryState = (arg, {
291 skip = false,
292 selectFromResult
293 } = {}) => {
294 const {
295 select
296 } = api.endpoints[endpointName];
297 const stableArg = useStableQueryArgs(skip ? skipToken : arg, serializeQueryArgs, context.endpointDefinitions[endpointName], endpointName);
298 const lastValue = useRef3(void 0);
299 const selectDefaultResult = useMemo2(() => (
300 // Normally ts-ignores are bad and should be avoided, but we're
301 // already casting this selector to be `Selector<any>` anyway,
302 // so the inconsistencies don't matter here
303 // @ts-ignore
304 createSelector([
305 // @ts-ignore
306 select(stableArg),
307 (_, lastResult) => lastResult,
308 (_) => stableArg
309 ], preSelector, {
310 memoizeOptions: {
311 resultEqualityCheck: shallowEqual2
312 }
313 })
314 ), [select, stableArg]);
315 const querySelector = useMemo2(() => selectFromResult ? createSelector([selectDefaultResult], selectFromResult, {
316 devModeChecks: {
317 identityFunctionCheck: "never"
318 }
319 }) : selectDefaultResult, [selectDefaultResult, selectFromResult]);
320 const currentState = useSelector((state) => querySelector(state, lastValue.current), shallowEqual2);
321 const store = useStore();
322 const newLastValue = selectDefaultResult(store.getState(), lastValue.current);
323 useIsomorphicLayoutEffect(() => {
324 lastValue.current = newLastValue;
325 }, [newLastValue]);
326 return currentState;
327 };
328 return useQueryState;
329 }
330 function usePromiseRefUnsubscribeOnUnmount(promiseRef) {
331 useEffect3(() => {
332 return () => {
333 promiseRef.current?.unsubscribe?.();
334 promiseRef.current = void 0;
335 };
336 }, [promiseRef]);
337 }
338 function refetchOrErrorIfUnmounted(promiseRef) {
339 if (!promiseRef.current) throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage2(38) : "Cannot refetch a query that has not been started yet.");
340 return promiseRef.current.refetch();
341 }
342 function buildQueryHooks(endpointName) {
343 const useQuerySubscription = (arg, options = {}) => {
344 const [promiseRef] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
345 usePromiseRefUnsubscribeOnUnmount(promiseRef);
346 return useMemo2(() => ({
347 /**
348 * A method to manually refetch data for the query
349 */
350 refetch: () => refetchOrErrorIfUnmounted(promiseRef)
351 }), [promiseRef]);
352 };
353 const useLazyQuerySubscription = ({
354 refetchOnReconnect,
355 refetchOnFocus,
356 pollingInterval = 0,
357 skipPollingIfUnfocused = false
358 } = {}) => {
359 const {
360 initiate
361 } = api.endpoints[endpointName];
362 const dispatch = useDispatch();
363 const [arg, setArg] = useState(UNINITIALIZED_VALUE);
364 const promiseRef = useRef3(void 0);
365 const stableSubscriptionOptions = useShallowStableValue({
366 refetchOnReconnect,
367 refetchOnFocus,
368 pollingInterval,
369 skipPollingIfUnfocused
370 });
371 usePossiblyImmediateEffect(() => {
372 const lastSubscriptionOptions = promiseRef.current?.subscriptionOptions;
373 if (stableSubscriptionOptions !== lastSubscriptionOptions) {
374 promiseRef.current?.updateSubscriptionOptions(stableSubscriptionOptions);
375 }
376 }, [stableSubscriptionOptions]);
377 const subscriptionOptionsRef = useRef3(stableSubscriptionOptions);
378 usePossiblyImmediateEffect(() => {
379 subscriptionOptionsRef.current = stableSubscriptionOptions;
380 }, [stableSubscriptionOptions]);
381 const trigger = useCallback(function(arg2, preferCacheValue = false) {
382 let promise;
383 batch(() => {
384 promiseRef.current?.unsubscribe();
385 promiseRef.current = promise = dispatch(initiate(arg2, {
386 subscriptionOptions: subscriptionOptionsRef.current,
387 forceRefetch: !preferCacheValue
388 }));
389 setArg(arg2);
390 });
391 return promise;
392 }, [dispatch, initiate]);
393 const reset = useCallback(() => {
394 if (promiseRef.current?.queryCacheKey) {
395 dispatch(api.internalActions.removeQueryResult({
396 queryCacheKey: promiseRef.current?.queryCacheKey
397 }));
398 }
399 }, [dispatch]);
400 useEffect3(() => {
401 return () => {
402 promiseRef?.current?.unsubscribe();
403 };
404 }, []);
405 useEffect3(() => {
406 if (arg !== UNINITIALIZED_VALUE && !promiseRef.current) {
407 trigger(arg, true);
408 }
409 }, [arg, trigger]);
410 return useMemo2(() => [trigger, arg, {
411 reset
412 }], [trigger, arg, reset]);
413 };
414 const useQueryState = buildUseQueryState(endpointName, queryStatePreSelector);
415 return {
416 useQueryState,
417 useQuerySubscription,
418 useLazyQuerySubscription,
419 useLazyQuery(options) {
420 const [trigger, arg, {
421 reset
422 }] = useLazyQuerySubscription(options);
423 const queryStateResults = useQueryState(arg, {
424 ...options,
425 skip: arg === UNINITIALIZED_VALUE
426 });
427 const info = useMemo2(() => ({
428 lastArg: arg
429 }), [arg]);
430 return useMemo2(() => [trigger, {
431 ...queryStateResults,
432 reset
433 }, info], [trigger, queryStateResults, reset, info]);
434 },
435 useQuery(arg, options) {
436 const querySubscriptionResults = useQuerySubscription(arg, options);
437 const queryStateResults = useQueryState(arg, {
438 selectFromResult: arg === skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
439 ...options
440 });
441 const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS);
442 useDebugValue(debugValue);
443 return useMemo2(() => ({
444 ...queryStateResults,
445 ...querySubscriptionResults
446 }), [queryStateResults, querySubscriptionResults]);
447 }
448 };
449 }
450 function buildInfiniteQueryHooks(endpointName) {
451 const useInfiniteQuerySubscription = (arg, options = {}) => {
452 const [promiseRef, dispatch, initiate, stableSubscriptionOptions] = useQuerySubscriptionCommonImpl(endpointName, arg, options);
453 const subscriptionOptionsRef = useRef3(stableSubscriptionOptions);
454 usePossiblyImmediateEffect(() => {
455 subscriptionOptionsRef.current = stableSubscriptionOptions;
456 }, [stableSubscriptionOptions]);
457 const trigger = useCallback(function(arg2, direction) {
458 let promise;
459 batch(() => {
460 promiseRef.current?.unsubscribe();
461 promiseRef.current = promise = dispatch(initiate(arg2, {
462 subscriptionOptions: subscriptionOptionsRef.current,
463 direction
464 }));
465 });
466 return promise;
467 }, [promiseRef, dispatch, initiate]);
468 usePromiseRefUnsubscribeOnUnmount(promiseRef);
469 return useMemo2(() => {
470 const fetchNextPage = () => {
471 return trigger(arg, "forward");
472 };
473 const fetchPreviousPage = () => {
474 return trigger(arg, "backward");
475 };
476 return {
477 trigger,
478 /**
479 * A method to manually refetch data for the query
480 */
481 refetch: () => refetchOrErrorIfUnmounted(promiseRef),
482 fetchNextPage,
483 fetchPreviousPage
484 };
485 }, [promiseRef, trigger, arg]);
486 };
487 const useInfiniteQueryState = buildUseQueryState(endpointName, infiniteQueryStatePreSelector);
488 return {
489 useInfiniteQueryState,
490 useInfiniteQuerySubscription,
491 useInfiniteQuery(arg, options) {
492 const {
493 refetch,
494 fetchNextPage,
495 fetchPreviousPage
496 } = useInfiniteQuerySubscription(arg, options);
497 const queryStateResults = useInfiniteQueryState(arg, {
498 selectFromResult: arg === skipToken || options?.skip ? void 0 : noPendingQueryStateSelector,
499 ...options
500 });
501 const debugValue = pick(queryStateResults, ...COMMON_HOOK_DEBUG_FIELDS, "hasNextPage", "hasPreviousPage");
502 useDebugValue(debugValue);
503 return useMemo2(() => ({
504 ...queryStateResults,
505 fetchNextPage,
506 fetchPreviousPage,
507 refetch
508 }), [queryStateResults, fetchNextPage, fetchPreviousPage, refetch]);
509 }
510 };
511 }
512 function buildMutationHook(name) {
513 return ({
514 selectFromResult,
515 fixedCacheKey
516 } = {}) => {
517 const {
518 select,
519 initiate
520 } = api.endpoints[name];
521 const dispatch = useDispatch();
522 const [promise, setPromise] = useState();
523 useEffect3(() => () => {
524 if (!promise?.arg.fixedCacheKey) {
525 promise?.reset();
526 }
527 }, [promise]);
528 const triggerMutation = useCallback(function(arg) {
529 const promise2 = dispatch(initiate(arg, {
530 fixedCacheKey
531 }));
532 setPromise(promise2);
533 return promise2;
534 }, [dispatch, initiate, fixedCacheKey]);
535 const {
536 requestId
537 } = promise || {};
538 const selectDefaultResult = useMemo2(() => select({
539 fixedCacheKey,
540 requestId: promise?.requestId
541 }), [fixedCacheKey, promise, select]);
542 const mutationSelector = useMemo2(() => selectFromResult ? createSelector([selectDefaultResult], selectFromResult) : selectDefaultResult, [selectFromResult, selectDefaultResult]);
543 const currentState = useSelector(mutationSelector, shallowEqual2);
544 const originalArgs = fixedCacheKey == null ? promise?.arg.originalArgs : void 0;
545 const reset = useCallback(() => {
546 batch(() => {
547 if (promise) {
548 setPromise(void 0);
549 }
550 if (fixedCacheKey) {
551 dispatch(api.internalActions.removeMutationResult({
552 requestId,
553 fixedCacheKey
554 }));
555 }
556 });
557 }, [dispatch, fixedCacheKey, promise, requestId]);
558 const debugValue = pick(currentState, ...COMMON_HOOK_DEBUG_FIELDS, "endpointName");
559 useDebugValue(debugValue);
560 const finalState = useMemo2(() => ({
561 ...currentState,
562 originalArgs,
563 reset
564 }), [currentState, originalArgs, reset]);
565 return useMemo2(() => [triggerMutation, finalState], [triggerMutation, finalState]);
566 };
567 }
568 }
569
570 // src/query/react/module.ts
571 var reactHooksModuleName = /* @__PURE__ */ Symbol();
572 var reactHooksModule = ({
573 batch = rrBatch,
574 hooks = {
575 useDispatch: rrUseDispatch,
576 useSelector: rrUseSelector,
577 useStore: rrUseStore
578 },
579 createSelector = _createSelector,
580 unstable__sideEffectsInRender = false,
581 ...rest
582 } = {}) => {
583 if (process.env.NODE_ENV !== "production") {
584 const hookNames = ["useDispatch", "useSelector", "useStore"];
585 let warned = false;
586 for (const hookName of hookNames) {
587 if (countObjectKeys(rest) > 0) {
588 if (rest[hookName]) {
589 if (!warned) {
590 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 } })`");
591 warned = true;
592 }
593 }
594 hooks[hookName] = rest[hookName];
595 }
596 if (typeof hooks[hookName] !== "function") {
597 throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage3(36) : `When using custom hooks for context, all ${hookNames.length} hooks need to be provided: ${hookNames.join(", ")}.
598 Hook ${hookName} was either not provided or not a function.`);
599 }
600 }
601 }
602 return {
603 name: reactHooksModuleName,
604 init(api, {
605 serializeQueryArgs
606 }, context) {
607 const anyApi = api;
608 const {
609 buildQueryHooks,
610 buildInfiniteQueryHooks,
611 buildMutationHook,
612 usePrefetch
613 } = buildHooks({
614 api,
615 moduleOptions: {
616 batch,
617 hooks,
618 unstable__sideEffectsInRender,
619 createSelector
620 },
621 serializeQueryArgs,
622 context
623 });
624 safeAssign(anyApi, {
625 usePrefetch
626 });
627 safeAssign(context, {
628 batch
629 });
630 return {
631 injectEndpoint(endpointName, definition) {
632 if (isQueryDefinition(definition)) {
633 const {
634 useQuery,
635 useLazyQuery,
636 useLazyQuerySubscription,
637 useQueryState,
638 useQuerySubscription
639 } = buildQueryHooks(endpointName);
640 safeAssign(anyApi.endpoints[endpointName], {
641 useQuery,
642 useLazyQuery,
643 useLazyQuerySubscription,
644 useQueryState,
645 useQuerySubscription
646 });
647 api[`use${capitalize(endpointName)}Query`] = useQuery;
648 api[`useLazy${capitalize(endpointName)}Query`] = useLazyQuery;
649 }
650 if (isMutationDefinition(definition)) {
651 const useMutation = buildMutationHook(endpointName);
652 safeAssign(anyApi.endpoints[endpointName], {
653 useMutation
654 });
655 api[`use${capitalize(endpointName)}Mutation`] = useMutation;
656 } else if (isInfiniteQueryDefinition(definition)) {
657 const {
658 useInfiniteQuery,
659 useInfiniteQuerySubscription,
660 useInfiniteQueryState
661 } = buildInfiniteQueryHooks(endpointName);
662 safeAssign(anyApi.endpoints[endpointName], {
663 useInfiniteQuery,
664 useInfiniteQuerySubscription,
665 useInfiniteQueryState
666 });
667 api[`use${capitalize(endpointName)}InfiniteQuery`] = useInfiniteQuery;
668 }
669 }
670 };
671 }
672 };
673 };
674
675 // src/query/react/index.ts
676 export * from "@reduxjs/toolkit/query";
677
678 // src/query/react/ApiProvider.tsx
679 import { configureStore, formatProdErrorMessage as _formatProdErrorMessage4 } from "@reduxjs/toolkit";
680 import { useContext } from "react";
681 import { useEffect as useEffect4 } from "react";
682 import * as React from "react";
683 import { Provider, ReactReduxContext } from "react-redux";
684 import { setupListeners } from "@reduxjs/toolkit/query";
685 function ApiProvider(props) {
686 const context = props.context || ReactReduxContext;
687 const existingContext = useContext(context);
688 if (existingContext) {
689 throw new Error(process.env.NODE_ENV === "production" ? _formatProdErrorMessage4(35) : "Existing Redux context detected. If you already have a store set up, please use the traditional Redux setup.");
690 }
691 const [store] = React.useState(() => configureStore({
692 reducer: {
693 [props.api.reducerPath]: props.api.reducer
694 },
695 middleware: (gDM) => gDM().concat(props.api.middleware)
696 }));
697 useEffect4(() => props.setupListeners === false ? void 0 : setupListeners(store.dispatch, props.setupListeners), [props.setupListeners, store.dispatch]);
698 return /* @__PURE__ */ React.createElement(Provider, { store, context }, props.children);
699 }
700
701 // src/query/react/index.ts
702 var createApi = /* @__PURE__ */ buildCreateApi(coreModule(), reactHooksModule());
703 export {
704 ApiProvider,
705 UNINITIALIZED_VALUE,
706 createApi,
707 reactHooksModule,
708 reactHooksModuleName
709 };
710 //# sourceMappingURL=rtk-query-react.modern.mjs.map