diff --git a/packages/toolkit/src/query/core/apiState.ts b/packages/toolkit/src/query/core/apiState.ts index ca9d2c1833..81f7a78e7f 100644 --- a/packages/toolkit/src/query/core/apiState.ts +++ b/packages/toolkit/src/query/core/apiState.ts @@ -1,14 +1,14 @@ import type { SerializedError } from '@reduxjs/toolkit' import type { BaseQueryError } from '../baseQueryTypes' import type { - QueryDefinition, - MutationDefinition, - EndpointDefinitions, BaseEndpointDefinition, - ResultTypeFrom, - QueryArgFrom, + EndpointDefinitions, InfiniteQueryDefinition, + MutationDefinition, PageParamFrom, + QueryArgFrom, + QueryDefinition, + ResultTypeFrom, } from '../endpointDefinitions' import type { Id, WithRequiredProp } from '../tsHelpers' diff --git a/packages/toolkit/src/query/core/buildInitiate.ts b/packages/toolkit/src/query/core/buildInitiate.ts index 925b902228..33f6adde3f 100644 --- a/packages/toolkit/src/query/core/buildInitiate.ts +++ b/packages/toolkit/src/query/core/buildInitiate.ts @@ -1,11 +1,11 @@ import type { + SafePromise, SerializedError, ThunkAction, ThunkDispatch, UnknownAction, } from '@reduxjs/toolkit' import type { Dispatch } from 'redux' -import type { SafePromise } from '../../tsHelpers' import { asSafePromise } from '../../tsHelpers' import type { Api, ApiContext } from '../apiTypes' import type { BaseQueryError, QueryReturnValue } from '../baseQueryTypes' diff --git a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts index f683dd4f69..c13a89957d 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/cacheLifecycle.ts @@ -148,12 +148,12 @@ export type CacheLifecycleInfiniteQueryExtraOptions< QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string, -> = { - onCacheEntryAdded?( - arg: QueryArg, - api: QueryCacheLifecycleApi, - ): Promise | void -} +> = CacheLifecycleQueryExtraOptions< + ResultType, + QueryArg, + BaseQuery, + ReducerPath +> export type CacheLifecycleMutationExtraOptions< ResultType, diff --git a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts index df2e72a023..4cd4456794 100644 --- a/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts +++ b/packages/toolkit/src/query/core/buildMiddleware/queryLifecycle.ts @@ -122,12 +122,12 @@ export type QueryLifecycleInfiniteQueryExtraOptions< QueryArg, BaseQuery extends BaseQueryFn, ReducerPath extends string = string, -> = { - onQueryStarted?( - arg: QueryArg, - api: QueryLifecycleApi, - ): Promise | void -} +> = QueryLifecycleQueryExtraOptions< + ResultType, + QueryArg, + BaseQuery, + ReducerPath +> export type QueryLifecycleMutationExtraOptions< ResultType, diff --git a/packages/toolkit/src/query/core/buildSlice.ts b/packages/toolkit/src/query/core/buildSlice.ts index a84a3b0e76..93d9759981 100644 --- a/packages/toolkit/src/query/core/buildSlice.ts +++ b/packages/toolkit/src/query/core/buildSlice.ts @@ -202,14 +202,17 @@ export function buildSlice({ substate.startedTimeStamp = meta.startedTimeStamp // TODO: Awful - fix this most likely by just moving it to its own slice that only works on InfQuery's - if ('param' in substate && 'direction' in substate) { - if ('param' in arg && 'direction' in arg) { - substate.param = arg.param - substate.direction = arg.direction as - | 'forward' - | 'backwards' - | undefined - } + if ( + 'param' in substate && + 'direction' in substate && + 'param' in arg && + 'direction' in arg + ) { + substate.param = arg.param + substate.direction = arg.direction as + | 'forward' + | 'backwards' + | undefined } }) } diff --git a/packages/toolkit/src/query/core/index.ts b/packages/toolkit/src/query/core/index.ts index 4fd35c7719..c5c0e32439 100644 --- a/packages/toolkit/src/query/core/index.ts +++ b/packages/toolkit/src/query/core/index.ts @@ -6,6 +6,9 @@ export const createApi = /* @__PURE__ */ buildCreateApi(coreModule()) export { QueryStatus } from './apiState' export type { CombinedState, + InfiniteData, + InfiniteQueryConfigOptions, + InfiniteQuerySubState, MutationKeys, QueryCacheKey, QueryKeys, @@ -14,6 +17,7 @@ export type { SubscriptionOptions, } from './apiState' export type { + InfiniteQueryActionCreatorResult, MutationActionCreatorResult, QueryActionCreatorResult, StartQueryActionCreatorOptions, @@ -24,7 +28,7 @@ export type { QueryCacheLifecycleApi, QueryLifecycleApi, SubscriptionSelectors, -} from './buildMiddleware' +} from './buildMiddleware/index' export { skipToken } from './buildSelectors' export type { InfiniteQueryResultSelectorResult, @@ -40,6 +44,7 @@ export type { } from './buildThunks' export { coreModuleName } from './module' export type { + ApiEndpointInfiniteQuery, ApiEndpointMutation, ApiEndpointQuery, CoreModule, diff --git a/packages/toolkit/src/query/endpointDefinitions.ts b/packages/toolkit/src/query/endpointDefinitions.ts index 8c9dfdf662..f520869535 100644 --- a/packages/toolkit/src/query/endpointDefinitions.ts +++ b/packages/toolkit/src/query/endpointDefinitions.ts @@ -1,9 +1,4 @@ import type { Api } from '@reduxjs/toolkit/query' -import type { - InfiniteQueryConfigOptions, - QuerySubState, - RootState, -} from './core/apiState' import type { BaseQueryApi, BaseQueryArg, @@ -25,6 +20,11 @@ import type { QueryLifecycleMutationExtraOptions, QueryLifecycleQueryExtraOptions, } from './core/buildMiddleware/queryLifecycle' +import type { + InfiniteQueryConfigOptions, + QuerySubState, + RootState, +} from './core/index' import type { SerializeQueryArgs } from './defaultSerializeQueryArgs' import type { NEVER } from './fakeBaseQuery' import type { @@ -43,7 +43,6 @@ type EndpointDefinitionWithQuery< QueryArg, BaseQuery extends BaseQueryFn, ResultType, - PageParam = never, > = { /** * `query` can be a function that returns either a `string` or an `object` which is passed to your `baseQuery`. If you are using [fetchBaseQuery](./fetchBaseQuery), this can return either a `string` or an `object` of properties in `FetchArgs`. If you use your own custom [`baseQuery`](../../rtk-query/usage/customizing-queries), you can customize this behavior to your liking. diff --git a/packages/toolkit/src/query/index.ts b/packages/toolkit/src/query/index.ts index f96d0b259c..669ea16318 100644 --- a/packages/toolkit/src/query/index.ts +++ b/packages/toolkit/src/query/index.ts @@ -1,20 +1,7 @@ // This must remain here so that the `mangleErrors.cjs` build script // does not have to import this into each source file it rewrites. -import { formatProdErrorMessage } from '@reduxjs/toolkit' -export type { - CombinedState, - InfiniteData, - InfiniteQueryConfigOptions, - QueryCacheKey, - QueryKeys, - QuerySubState, - RootState, - SubscriptionOptions, -} from './core/apiState' -export { QueryStatus } from './core/apiState' export type { Api, ApiContext, Module } from './apiTypes' - export type { BaseQueryApi, BaseQueryArg, @@ -26,67 +13,78 @@ export type { BaseQueryResult, QueryReturnValue, } from './baseQueryTypes' +export { + QueryStatus, + coreModule, + coreModuleName, + createApi, + setupListeners, + skipToken, +} from './core/index' +export type { + ApiEndpointInfiniteQuery, + ApiEndpointMutation, + ApiEndpointQuery, + CombinedState, + CoreModule, + InfiniteData, + InfiniteQueryActionCreatorResult, + InfiniteQueryConfigOptions, + InfiniteQueryResultSelectorResult, + MutationActionCreatorResult, + MutationResultSelectorResult, + PrefetchOptions, + QueryActionCreatorResult, + QueryCacheKey, + QueryKeys, + QueryResultSelectorResult, + QuerySubState, + RootState, + SkipToken, + StartQueryActionCreatorOptions, + SubscriptionOptions, +} from './core/index' +export type { ApiModules } from './core/module' +export { buildCreateApi } from './createApi' +export type { CreateApi, CreateApiOptions } from './createApi' +export { defaultSerializeQueryArgs } from './defaultSerializeQueryArgs' +export type { SerializeQueryArgs } from './defaultSerializeQueryArgs' export type { BaseEndpointDefinition, - EndpointDefinitions, - EndpointDefinition, + DefinitionType, + DefinitionsFromApi, EndpointBuilder, - QueryDefinition, + EndpointDefinition, + EndpointDefinitions, + InfiniteQueryArgFrom, InfiniteQueryDefinition, InfiniteQueryExtraOptions, MutationDefinition, MutationExtraOptions, - TagDescription, + OverrideResultType, + PageParamFrom, QueryArgFrom, + QueryDefinition, QueryExtraOptions, - ResultTypeFrom, - DefinitionType, - DefinitionsFromApi, - OverrideResultType, ResultDescription, + ResultTypeFrom, + TagDescription, TagTypesFromApi, UpdateDefinitions, } from './endpointDefinitions' +export { _NEVER, fakeBaseQuery } from './fakeBaseQuery' export { fetchBaseQuery } from './fetchBaseQuery' export type { + FetchArgs, FetchBaseQueryArgs, FetchBaseQueryError, FetchBaseQueryMeta, - FetchArgs, } from './fetchBaseQuery' export { retry } from './retry' export type { RetryOptions } from './retry' -export { setupListeners } from './core/setupListeners' -export { skipToken } from './core/buildSelectors' -export type { - QueryResultSelectorResult, - MutationResultSelectorResult, - SkipToken, -} from './core/buildSelectors' -export type { - InfiniteQueryActionCreatorResult, - QueryActionCreatorResult, - MutationActionCreatorResult, - StartQueryActionCreatorOptions, -} from './core/buildInitiate' -export type { CreateApi, CreateApiOptions } from './createApi' -export { buildCreateApi } from './createApi' -export { _NEVER, fakeBaseQuery } from './fakeBaseQuery' -export { copyWithStructuralSharing } from './utils/copyWithStructuralSharing' -export { createApi, coreModule, coreModuleName } from './core' -export type { - ApiEndpointMutation, - ApiEndpointQuery, - ApiEndpointInfiniteQuery, - ApiModules, - CoreModule, - PrefetchOptions, -} from './core/module' -export { defaultSerializeQueryArgs } from './defaultSerializeQueryArgs' -export type { SerializeQueryArgs } from './defaultSerializeQueryArgs' - export type { Id as TSHelpersId, NoInfer as TSHelpersNoInfer, Override as TSHelpersOverride, } from './tsHelpers' +export { copyWithStructuralSharing } from './utils/copyWithStructuralSharing' diff --git a/packages/toolkit/src/query/react/buildHooks.ts b/packages/toolkit/src/query/react/buildHooks.ts index 118f4ad797..95c6ef777a 100644 --- a/packages/toolkit/src/query/react/buildHooks.ts +++ b/packages/toolkit/src/query/react/buildHooks.ts @@ -13,13 +13,14 @@ import type { BaseQueryFn, CoreModule, EndpointDefinitions, - InfiniteData, InfiniteQueryActionCreatorResult, - InfiniteQueryConfigOptions, + InfiniteQueryArgFrom, InfiniteQueryDefinition, + InfiniteQueryResultSelectorResult, MutationActionCreatorResult, MutationDefinition, MutationResultSelectorResult, + PageParamFrom, PrefetchOptions, QueryActionCreatorResult, QueryArgFrom, @@ -36,7 +37,11 @@ import type { TSHelpersNoInfer, TSHelpersOverride, } from '@reduxjs/toolkit/query' -import { QueryStatus, skipToken } from '@reduxjs/toolkit/query' +import { + defaultSerializeQueryArgs, + QueryStatus, + skipToken, +} from '@reduxjs/toolkit/query' import type { DependencyList } from 'react' import { useCallback, @@ -48,13 +53,9 @@ import { useState, } from 'react' import { shallowEqual } from 'react-redux' -import type { InfiniteQueryResultSelectorResult } from '../core/buildSelectors' -import type { SubscriptionSelectors } from '../core/index' -import { defaultSerializeQueryArgs } from '../defaultSerializeQueryArgs' -import type { - InfiniteQueryArgFrom, - PageParamFrom, -} from '../endpointDefinitions' + +import type { SubscriptionSelectors } from '../core/buildMiddleware/index' +import type { InfiniteData, InfiniteQueryConfigOptions } from '../core/index' import type { UninitializedValue } from './constants' import { UNINITIALIZED_VALUE } from './constants' import type { ReactHooksModuleOptions } from './module' diff --git a/packages/toolkit/src/query/react/namedHooks.ts b/packages/toolkit/src/query/react/namedHooks.ts index 7a21b993f4..07b7ac7417 100644 --- a/packages/toolkit/src/query/react/namedHooks.ts +++ b/packages/toolkit/src/query/react/namedHooks.ts @@ -1,10 +1,10 @@ -import type { UseMutation, UseLazyQuery, UseQuery } from './buildHooks' import type { DefinitionType, EndpointDefinitions, MutationDefinition, QueryDefinition, } from '@reduxjs/toolkit/query' +import type { UseLazyQuery, UseMutation, UseQuery } from './buildHooks' type QueryHookNames = { [K in keyof Definitions as Definitions[K] extends {