1 | import type { QueryCacheKey } from './core/apiState'
|
2 | import type { EndpointDefinition } from './endpointDefinitions'
|
3 | import { isPlainObject } from '@reduxjs/toolkit'
|
4 |
|
5 | export const defaultSerializeQueryArgs: SerializeQueryArgs<any> = ({
|
6 | endpointName,
|
7 | queryArgs,
|
8 | }) => {
|
9 |
|
10 | return `${endpointName}(${JSON.stringify(queryArgs, (key, value) =>
|
11 | isPlainObject(value)
|
12 | ? Object.keys(value)
|
13 | .sort()
|
14 | .reduce<any>((acc, key) => {
|
15 | acc[key] = (value as any)[key]
|
16 | return acc
|
17 | }, {})
|
18 | : value
|
19 | )})`
|
20 | }
|
21 |
|
22 | export type SerializeQueryArgs<QueryArgs> = (_: {
|
23 | queryArgs: QueryArgs
|
24 | endpointDefinition: EndpointDefinition<any, any, any, any>
|
25 | endpointName: string
|
26 | }) => string
|
27 |
|
28 | export type InternalSerializeQueryArgs = (_: {
|
29 | queryArgs: any
|
30 | endpointDefinition: EndpointDefinition<any, any, any, any>
|
31 | endpointName: string
|
32 | }) => QueryCacheKey
|