\r\n\r\ninterface UseQuerySubscriptionOptions extends SubscriptionOptions {\r\n /**\r\n * Prevents a query from automatically running.\r\n *\r\n * @remarks\r\n * When `skip` is true (or `skipToken` is passed in as `arg`):\r\n *\r\n * - **If the query has cached data:**\r\n * * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed\r\n * * The query will have a status of `uninitialized`\r\n * * If `skip: false` is set after the initial load, the cached result will be used\r\n * - **If the query does not have cached data:**\r\n * * The query will have a status of `uninitialized`\r\n * * The query will not exist in the state when viewed with the dev tools\r\n * * The query will not automatically fetch on mount\r\n * * The query will not automatically run when additional components with the same query are added that do run\r\n *\r\n * @example\r\n * ```tsx\r\n * // codeblock-meta no-transpile title=\"Skip example\"\r\n * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {\r\n * const { data, error, status } = useGetPokemonByNameQuery(name, {\r\n * skip,\r\n * });\r\n *\r\n * return (\r\n * \r\n * {name} - {status}\r\n *
\r\n * );\r\n * };\r\n * ```\r\n */\r\n skip?: boolean\r\n /**\r\n * Defaults to `false`. This setting allows you to control whether if a cached result is already available, RTK Query will only serve a cached result, or if it should `refetch` when set to `true` or if an adequate amount of time has passed since the last successful query result.\r\n * - `false` - Will not cause a query to be performed _unless_ it does not exist yet.\r\n * - `true` - Will always refetch when a new subscriber to a query is added. Behaves the same as calling the `refetch` callback or passing `forceRefetch: true` in the action creator.\r\n * - `number` - **Value is in seconds**. If a number is provided and there is an existing query in the cache, it will compare the current time vs the last fulfilled timestamp, and only refetch if enough time has elapsed.\r\n *\r\n * If you specify this option alongside `skip: true`, this **will not be evaluated** until `skip` is false.\r\n */\r\n refetchOnMountOrArgChange?: boolean | number\r\n}\r\n\r\n/**\r\n * A React hook that automatically triggers fetches of data from an endpoint, and 'subscribes' the component to the cached data.\r\n *\r\n * The query arg is used as a cache key. Changing the query arg will tell the hook to re-fetch the data if it does not exist in the cache already.\r\n *\r\n * Note that this hook does not return a request status or cached data. For that use-case, see [`useQuery`](#usequery) or [`useQueryState`](#usequerystate).\r\n *\r\n * #### Features\r\n *\r\n * - Automatically triggers requests to retrieve data based on the hook argument and whether cached data exists by default\r\n * - 'Subscribes' the component to keep cached data in the store, and 'unsubscribes' when the component unmounts\r\n * - Accepts polling/re-fetching options to trigger automatic re-fetches when the corresponding criteria is met\r\n */\r\nexport type UseQuerySubscription<\r\n D extends QueryDefinition\r\n> = (\r\n arg: QueryArgFrom | SkipToken,\r\n options?: UseQuerySubscriptionOptions\r\n) => UseQuerySubscriptionResult\r\n\r\nexport type UseQuerySubscriptionResult<\r\n D extends QueryDefinition\r\n> = Pick, 'refetch'>\r\n\r\n/**\r\n * Helper type to manually type the result\r\n * of the `useQuerySubscription` hook in userland code.\r\n */\r\nexport type TypedUseQuerySubscriptionResult<\r\n ResultType,\r\n QueryArg,\r\n BaseQuery extends BaseQueryFn\r\n> = UseQuerySubscriptionResult<\r\n QueryDefinition\r\n>\r\n\r\nexport type UseLazyQueryLastPromiseInfo<\r\n D extends QueryDefinition\r\n> = {\r\n lastArg: QueryArgFrom\r\n}\r\n\r\n/**\r\n * A React hook similar to [`useQuery`](#usequery), but with manual control over when the data fetching occurs.\r\n *\r\n * This hook includes the functionality of [`useLazyQuerySubscription`](#uselazyquerysubscription).\r\n *\r\n * #### Features\r\n *\r\n * - Manual control over firing a request to retrieve data\r\n * - 'Subscribes' the component to keep cached data in the store, and 'unsubscribes' when the component unmounts\r\n * - Returns the latest request status and cached data from the Redux store\r\n * - Re-renders as the request status changes and data becomes available\r\n * - Accepts polling/re-fetching options to trigger automatic re-fetches when the corresponding criteria is met and the fetch has been manually called at least once\r\n *\r\n * #### Note\r\n *\r\n * When the trigger function returned from a LazyQuery is called, it always initiates a new request to the server even if there is cached data. Set `preferCacheValue`(the second argument to the function) as `true` if you want it to immediately return a cached value if one exists.\r\n */\r\nexport type UseLazyQuery> = <\r\n R extends Record = UseQueryStateDefaultResult\r\n>(\r\n options?: SubscriptionOptions & Omit, 'skip'>\r\n) => [\r\n LazyQueryTrigger,\r\n UseQueryStateResult,\r\n UseLazyQueryLastPromiseInfo\r\n]\r\n\r\nexport type LazyQueryTrigger> = {\r\n /**\r\n * Triggers a lazy query.\r\n *\r\n * By default, this will start a new request even if there is already a value in the cache.\r\n * If you want to use the cache value and only start a request if there is no cache value, set the second argument to `true`.\r\n *\r\n * @remarks\r\n * If you need to access the error or success payload immediately after a lazy query, you can chain .unwrap().\r\n *\r\n * @example\r\n * ```ts\r\n * // codeblock-meta title=\"Using .unwrap with async await\"\r\n * try {\r\n * const payload = await getUserById(1).unwrap();\r\n * console.log('fulfilled', payload)\r\n * } catch (error) {\r\n * console.error('rejected', error);\r\n * }\r\n * ```\r\n */\r\n (\r\n arg: QueryArgFrom,\r\n preferCacheValue?: boolean\r\n ): QueryActionCreatorResult\r\n}\r\n\r\n/**\r\n * A React hook similar to [`useQuerySubscription`](#usequerysubscription), but with manual control over when the data fetching occurs.\r\n *\r\n * Note that this hook does not return a request status or cached data. For that use-case, see [`useLazyQuery`](#uselazyquery).\r\n *\r\n * #### Features\r\n *\r\n * - Manual control over firing a request to retrieve data\r\n * - 'Subscribes' the component to keep cached data in the store, and 'unsubscribes' when the component unmounts\r\n * - Accepts polling/re-fetching options to trigger automatic re-fetches when the corresponding criteria is met and the fetch has been manually called at least once\r\n */\r\nexport type UseLazyQuerySubscription<\r\n D extends QueryDefinition\r\n> = (\r\n options?: SubscriptionOptions\r\n) => readonly [LazyQueryTrigger, QueryArgFrom | UninitializedValue]\r\n\r\nexport type QueryStateSelector<\r\n R extends Record,\r\n D extends QueryDefinition\r\n> = (state: UseQueryStateDefaultResult) => R\r\n\r\n/**\r\n * A React hook that reads the request status and cached data from the Redux store. The component will re-render as the loading status changes and the data becomes available.\r\n *\r\n * Note that this hook does not trigger fetching new data. For that use-case, see [`useQuery`](#usequery) or [`useQuerySubscription`](#usequerysubscription).\r\n *\r\n * #### Features\r\n *\r\n * - Returns the latest request status and cached data from the Redux store\r\n * - Re-renders as the request status changes and data becomes available\r\n */\r\nexport type UseQueryState> = <\r\n R extends Record = UseQueryStateDefaultResult\r\n>(\r\n arg: QueryArgFrom | SkipToken,\r\n options?: UseQueryStateOptions\r\n) => UseQueryStateResult\r\n\r\nexport type UseQueryStateOptions<\r\n D extends QueryDefinition,\r\n R extends Record\r\n> = {\r\n /**\r\n * Prevents a query from automatically running.\r\n *\r\n * @remarks\r\n * When skip is true:\r\n *\r\n * - **If the query has cached data:**\r\n * * The cached data **will not be used** on the initial load, and will ignore updates from any identical query until the `skip` condition is removed\r\n * * The query will have a status of `uninitialized`\r\n * * If `skip: false` is set after skipping the initial load, the cached result will be used\r\n * - **If the query does not have cached data:**\r\n * * The query will have a status of `uninitialized`\r\n * * The query will not exist in the state when viewed with the dev tools\r\n * * The query will not automatically fetch on mount\r\n * * The query will not automatically run when additional components with the same query are added that do run\r\n *\r\n * @example\r\n * ```ts\r\n * // codeblock-meta title=\"Skip example\"\r\n * const Pokemon = ({ name, skip }: { name: string; skip: boolean }) => {\r\n * const { data, error, status } = useGetPokemonByNameQuery(name, {\r\n * skip,\r\n * });\r\n *\r\n * return (\r\n * \r\n * {name} - {status}\r\n *
\r\n * );\r\n * };\r\n * ```\r\n */\r\n skip?: boolean\r\n /**\r\n * `selectFromResult` allows you to get a specific segment from a query result in a performant manner.\r\n * When using this feature, the component will not rerender unless the underlying data of the selected item has changed.\r\n * If the selected item is one element in a larger collection, it will disregard changes to elements in the same collection.\r\n *\r\n * @example\r\n * ```ts\r\n * // codeblock-meta title=\"Using selectFromResult to extract a single result\"\r\n * function PostsList() {\r\n * const { data: posts } = api.useGetPostsQuery();\r\n *\r\n * return (\r\n * \r\n * {posts?.data?.map((post) => (\r\n * \r\n * ))}\r\n *
\r\n * );\r\n * }\r\n *\r\n * function PostById({ id }: { id: number }) {\r\n * // Will select the post with the given id, and will only rerender if the given posts data changes\r\n * const { post } = api.useGetPostsQuery(undefined, {\r\n * selectFromResult: ({ data }) => ({ post: data?.find((post) => post.id === id) }),\r\n * });\r\n *\r\n * return {post?.name};\r\n * }\r\n * ```\r\n */\r\n selectFromResult?: QueryStateSelector\r\n}\r\n\r\nexport type UseQueryStateResult<\r\n _ extends QueryDefinition,\r\n R\r\n> = TSHelpersNoInfer\r\n\r\n/**\r\n * Helper type to manually type the result\r\n * of the `useQueryState` hook in userland code.\r\n */\r\nexport type TypedUseQueryStateResult<\r\n ResultType,\r\n QueryArg,\r\n BaseQuery extends BaseQueryFn,\r\n R = UseQueryStateDefaultResult<\r\n QueryDefinition\r\n >\r\n> = TSHelpersNoInfer\r\n\r\ntype UseQueryStateBaseResult> =\r\n QuerySubState & {\r\n /**\r\n * Where `data` tries to hold data as much as possible, also re-using\r\n * data from the last arguments passed into the hook, this property\r\n * will always contain the received data from the query, for the current query arguments.\r\n */\r\n currentData?: ResultTypeFrom\r\n /**\r\n * Query has not started yet.\r\n */\r\n isUninitialized: false\r\n /**\r\n * Query is currently loading for the first time. No data yet.\r\n */\r\n isLoading: false\r\n /**\r\n * Query is currently fetching, but might have data from an earlier request.\r\n */\r\n isFetching: false\r\n /**\r\n * Query has data from a successful load.\r\n */\r\n isSuccess: false\r\n /**\r\n * Query is currently in \"error\" state.\r\n */\r\n isError: false\r\n }\r\n\r\ntype UseQueryStateDefaultResult> =\r\n TSHelpersId<\r\n | TSHelpersOverride<\r\n Extract<\r\n UseQueryStateBaseResult,\r\n { status: QueryStatus.uninitialized }\r\n >,\r\n { isUninitialized: true }\r\n >\r\n | TSHelpersOverride<\r\n UseQueryStateBaseResult,\r\n | { isLoading: true; isFetching: boolean; data: undefined }\r\n | ({\r\n isSuccess: true\r\n isFetching: true\r\n error: undefined\r\n } & Required<\r\n Pick, 'data' | 'fulfilledTimeStamp'>\r\n >)\r\n | ({\r\n isSuccess: true\r\n isFetching: false\r\n error: undefined\r\n } & Required<\r\n Pick<\r\n UseQueryStateBaseResult,\r\n 'data' | 'fulfilledTimeStamp' | 'currentData'\r\n >\r\n >)\r\n | ({ isError: true } & Required<\r\n Pick, 'error'>\r\n >)\r\n >\r\n > & {\r\n /**\r\n * @deprecated will be removed in the next version\r\n * please use the `isLoading`, `isFetching`, `isSuccess`, `isError`\r\n * and `isUninitialized` flags instead\r\n */\r\n status: QueryStatus\r\n }\r\n\r\nexport type MutationStateSelector<\r\n R extends Record,\r\n D extends MutationDefinition\r\n> = (state: MutationResultSelectorResult) => R\r\n\r\nexport type UseMutationStateOptions<\r\n D extends MutationDefinition,\r\n R extends Record\r\n> = {\r\n selectFromResult?: MutationStateSelector\r\n fixedCacheKey?: string\r\n}\r\n\r\nexport type UseMutationStateResult<\r\n D extends MutationDefinition,\r\n R\r\n> = TSHelpersNoInfer & {\r\n originalArgs?: QueryArgFrom\r\n /**\r\n * Resets the hook state to it's initial `uninitialized` state.\r\n * This will also remove the last result from the cache.\r\n */\r\n reset: () => void\r\n}\r\n\r\n/**\r\n * Helper type to manually type the result\r\n * of the `useMutation` hook in userland code.\r\n */\r\nexport type TypedUseMutationResult<\r\n ResultType,\r\n QueryArg,\r\n BaseQuery extends BaseQueryFn,\r\n R = MutationResultSelectorResult<\r\n MutationDefinition\r\n >\r\n> = UseMutationStateResult<\r\n MutationDefinition,\r\n R\r\n>\r\n\r\n/**\r\n * A React hook that lets you trigger an update request for a given endpoint, and subscribes the component to read the request status from the Redux store. The component will re-render as the loading status changes.\r\n *\r\n * #### Features\r\n *\r\n * - Manual control over firing a request to alter data on the server or possibly invalidate the cache\r\n * - 'Subscribes' the component to keep cached data in the store, and 'unsubscribes' when the component unmounts\r\n * - Returns the latest request status and cached data from the Redux store\r\n * - Re-renders as the request status changes and data becomes available\r\n */\r\nexport type UseMutation> = <\r\n R extends Record = MutationResultSelectorResult\r\n>(\r\n options?: UseMutationStateOptions\r\n) => readonly [MutationTrigger, UseMutationStateResult]\r\n\r\nexport type MutationTrigger> =\r\n {\r\n /**\r\n * Triggers the mutation and returns a Promise.\r\n * @remarks\r\n * If you need to access the error or success payload immediately after a mutation, you can chain .unwrap().\r\n *\r\n * @example\r\n * ```ts\r\n * // codeblock-meta title=\"Using .unwrap with async await\"\r\n * try {\r\n * const payload = await addPost({ id: 1, name: 'Example' }).unwrap();\r\n * console.log('fulfilled', payload)\r\n * } catch (error) {\r\n * console.error('rejected', error);\r\n * }\r\n * ```\r\n */\r\n (arg: QueryArgFrom): MutationActionCreatorResult\r\n }\r\n\r\nconst defaultQueryStateSelector: QueryStateSelector = (x) => x\r\nconst defaultMutationStateSelector: MutationStateSelector = (x) => x\r\n\r\n/**\r\n * Wrapper around `defaultQueryStateSelector` to be used in `useQuery`.\r\n * We want the initial render to already come back with\r\n * `{ isUninitialized: false, isFetching: true, isLoading: true }`\r\n * to prevent that the library user has to do an additional check for `isUninitialized`/\r\n */\r\nconst noPendingQueryStateSelector: QueryStateSelector