|
1 |
| -import { buildThunks } from './buildThunks'; |
2 |
| -import type { AnyAction, Reducer, ThunkAction } from '@reduxjs/toolkit'; |
3 |
| -import { buildSlice, SliceActions } from './buildSlice'; |
| 1 | +import type { AnyAction, Reducer } from '@reduxjs/toolkit'; |
| 2 | +import type { CombinedState, QueryStatePhantomType } from './apiState'; |
| 3 | +import { Api, BaseQueryArg, BaseQueryFn } from './apiTypes'; |
4 | 4 | import { buildActionMaps } from './buildActionMaps';
|
5 |
| -import { buildSelectors } from './buildSelectors'; |
6 |
| -import { buildHooks, PrefetchOptions } from './buildHooks'; |
| 5 | +import { buildHooks } from './buildHooks'; |
7 | 6 | import { buildMiddleware } from './buildMiddleware';
|
| 7 | +import { buildSelectors } from './buildSelectors'; |
| 8 | +import { buildSlice } from './buildSlice'; |
| 9 | +import { buildThunks } from './buildThunks'; |
| 10 | +import { defaultSerializeQueryArgs, InternalSerializeQueryArgs, SerializeQueryArgs } from './defaultSerializeQueryArgs'; |
8 | 11 | import {
|
9 |
| - EndpointDefinitions, |
10 |
| - EndpointBuilder, |
| 12 | + AssertEntityTypes, |
11 | 13 | DefinitionType,
|
12 |
| - isQueryDefinition, |
| 14 | + EndpointBuilder, |
| 15 | + EndpointDefinitions, |
13 | 16 | isMutationDefinition,
|
14 |
| - AssertEntityTypes, |
| 17 | + isQueryDefinition, |
15 | 18 | } from './endpointDefinitions';
|
16 |
| -import type { CombinedState, QueryCacheKey, QueryStatePhantomType } from './apiState'; |
17 | 19 | import { assertCast } from './tsHelpers';
|
18 |
| -import { Api, BaseQueryArg, BaseQueryFn } from './apiTypes'; |
19 |
| -export { Api, ApiWithInjectedEndpoints, BaseQueryFn, BaseQueryEnhancer } from './apiTypes'; |
20 |
| -export { fetchBaseQuery, FetchBaseQueryError } from './fetchBaseQuery'; |
| 20 | +import { capitalize, IS_DEV } from './utils'; |
| 21 | +export { ApiProvider } from './ApiProvider'; |
21 | 22 | export { QueryStatus } from './apiState';
|
| 23 | +export type { Api, ApiWithInjectedEndpoints, BaseQueryEnhancer, BaseQueryFn } from './apiTypes'; |
| 24 | +export { fetchBaseQuery } from './fetchBaseQuery'; |
| 25 | +export type { FetchBaseQueryError } from './fetchBaseQuery'; |
22 | 26 | export { retry } from './retry';
|
23 | 27 |
|
24 |
| -export { ApiProvider } from './ApiProvider'; |
25 |
| - |
26 |
| -export type SerializeQueryArgs<InternalQueryArgs> = (_: { |
27 |
| - queryArgs: any; |
28 |
| - internalQueryArgs: InternalQueryArgs; |
29 |
| - endpoint: string; |
30 |
| -}) => string; |
31 |
| - |
32 |
| -export type InternalSerializeQueryArgs<InternalQueryArgs> = (_: { |
33 |
| - queryArgs: any; |
34 |
| - internalQueryArgs: InternalQueryArgs; |
35 |
| - endpoint: string; |
36 |
| -}) => QueryCacheKey; |
37 |
| - |
38 |
| -const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({ endpoint, queryArgs }) => { |
39 |
| - // Sort the object keys before stringifying, to prevent useQuery({ a: 1, b: 2 }) having a different cache key than useQuery({ b: 2, a: 1 }) |
40 |
| - return `${endpoint}(${JSON.stringify(queryArgs, Object.keys(queryArgs || {}).sort())})`; |
41 |
| -}; |
42 |
| - |
43 |
| -const IS_DEV = () => typeof process !== 'undefined' && process.env.NODE_ENV === 'development'; |
44 |
| - |
45 | 28 | export function createApi<
|
46 | 29 | BaseQuery extends BaseQueryFn,
|
47 | 30 | Definitions extends EndpointDefinitions,
|
@@ -205,11 +188,3 @@ export function createApi<
|
205 | 188 |
|
206 | 189 | return api.injectEndpoints({ endpoints });
|
207 | 190 | }
|
208 |
| - |
209 |
| -export type InternalActions = SliceActions & { |
210 |
| - prefetchThunk: (endpointName: any, arg: any, options: PrefetchOptions) => ThunkAction<void, any, any, AnyAction>; |
211 |
| -}; |
212 |
| - |
213 |
| -function capitalize(str: string) { |
214 |
| - return str.replace(str[0], str[0].toUpperCase()); |
215 |
| -} |
0 commit comments