@@ -159,6 +159,8 @@ const defaultMutationSubState = /* @__PURE__ */ createNextState(
159159 ( ) => { } ,
160160)
161161
162+ export type AllSelectors = ReturnType < typeof buildSelectors >
163+
162164export function buildSelectors <
163165 Definitions extends EndpointDefinitions ,
164166 ReducerPath extends string ,
@@ -182,6 +184,11 @@ export function buildSelectors<
182184 buildMutationSelector,
183185 selectInvalidatedBy,
184186 selectCachedArgsForQuery,
187+ selectApiState,
188+ selectQueries,
189+ selectMutations,
190+ selectQueryEntry,
191+ selectConfig,
185192 }
186193
187194 function withRequestFlags < T extends { status : QueryStatus } > (
@@ -193,12 +200,12 @@ export function buildSelectors<
193200 }
194201 }
195202
196- function selectInternalState ( rootState : RootState ) {
203+ function selectApiState ( rootState : RootState ) {
197204 const state = rootState [ reducerPath ]
198205 if ( process . env . NODE_ENV !== 'production' ) {
199206 if ( ! state ) {
200- if ( ( selectInternalState as any ) . triggered ) return state
201- ; ( selectInternalState as any ) . triggered = true
207+ if ( ( selectApiState as any ) . triggered ) return state
208+ ; ( selectApiState as any ) . triggered = true
202209 console . error (
203210 `Error: No data found at \`state.${ reducerPath } \`. Did you forget to add the reducer to the store?` ,
204211 )
@@ -207,6 +214,22 @@ export function buildSelectors<
207214 return state
208215 }
209216
217+ function selectQueries ( rootState : RootState ) {
218+ return selectApiState ( rootState ) ?. queries
219+ }
220+
221+ function selectQueryEntry ( rootState : RootState , cacheKey : QueryCacheKey ) {
222+ return selectQueries ( rootState ) ?. [ cacheKey ]
223+ }
224+
225+ function selectMutations ( rootState : RootState ) {
226+ return selectApiState ( rootState ) ?. mutations
227+ }
228+
229+ function selectConfig ( rootState : RootState ) {
230+ return selectApiState ( rootState ) ?. config
231+ }
232+
210233 function buildAnyQuerySelector (
211234 endpointName : string ,
212235 endpointDefinition : EndpointDefinition < any , any , any , any > ,
@@ -221,8 +244,7 @@ export function buildSelectors<
221244 endpointName,
222245 } )
223246 const selectQuerySubstate = ( state : RootState ) =>
224- selectInternalState ( state ) ?. queries ?. [ serializedArgs ] ??
225- defaultQuerySubState
247+ selectQueryEntry ( state , serializedArgs ) ?? defaultQuerySubState
226248 const finalSelectQuerySubState =
227249 queryArgs === skipToken ? selectSkippedQuery : selectQuerySubstate
228250
@@ -292,7 +314,7 @@ export function buildSelectors<
292314 mutationId = id
293315 }
294316 const selectMutationSubstate = ( state : RootState ) =>
295- selectInternalState ( state ) ?. mutations ?. [ mutationId as string ] ??
317+ selectApiState ( state ) ?. mutations ?. [ mutationId as string ] ??
296318 defaultMutationSubState
297319 const finalSelectMutationSubstate =
298320 mutationId === skipToken
@@ -351,7 +373,7 @@ export function buildSelectors<
351373 state : RootState ,
352374 queryName : QueryName ,
353375 ) : Array < QueryArgFrom < Definitions [ QueryName ] > > {
354- return Object . values ( state [ reducerPath ] . queries as QueryState < any > )
376+ return Object . values ( selectQueries ( state ) as QueryState < any > )
355377 . filter (
356378 (
357379 entry ,
0 commit comments