2023-03-23 12:14:53 -07:00
|
|
|
import type { EntitiesPath, EntityRequest, ExpandedEntitiesPath } from './types';
|
|
|
|
import type { AxiosRequestConfig } from 'axios';
|
2023-03-22 14:06:10 -07:00
|
|
|
|
2023-03-22 14:12:05 -07:00
|
|
|
function parseEntitiesPath(expandedPath: ExpandedEntitiesPath) {
|
2023-03-22 14:06:10 -07:00
|
|
|
const [entityType, ...listKeys] = expandedPath;
|
|
|
|
const listKey = (listKeys || []).join(':');
|
2023-03-22 14:12:05 -07:00
|
|
|
const path: EntitiesPath = [entityType, listKey];
|
|
|
|
|
|
|
|
return {
|
|
|
|
entityType,
|
|
|
|
listKey,
|
|
|
|
path,
|
|
|
|
};
|
2023-03-22 14:06:10 -07:00
|
|
|
}
|
|
|
|
|
2023-03-23 12:14:53 -07:00
|
|
|
function toAxiosRequest(req: EntityRequest): AxiosRequestConfig {
|
|
|
|
if (typeof req === 'string' || req instanceof URL) {
|
|
|
|
return {
|
|
|
|
method: 'get',
|
|
|
|
url: req.toString(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
|
|
|
|
export { parseEntitiesPath, toAxiosRequest };
|