import { Options as NoCaseOptions } from 'camel-case' ; import { AxiosInstance , AxiosRequestConfig , AxiosRequestTransformer , AxiosResponseTransformer , } from 'axios' ; /** string transformers (change-case functions) */ export interface CaseFunction { ( input , options ? ) : string ; } export type CaseFunctionTypes = 'snake' | 'camel' | 'header' ; export type CaseFunctions = { [ K in CaseFunctionTypes ] : CaseFunction ; } ; /** decorators for string transformers */ export interface ApplyCaseOptions { ( fn , options ? ) : CaseFunction ; } export interface PreserveSpecificKeys { ( fn , keys ) : CaseFunction ; } /** objects which can be handled in object transformers */ export interface TransformableObject { [ key ] : unknown ; } export type Transformable = ( unknown [ ] | Record < string | number , unknown > | FormData | URLSearchParams ) & TransformableObject ; /** object transformers and their factories */ export interface PreservedKeysCondition { ( input , options ? ) : boolean ; } export type ObjectTransformerOptions = { overwrite ? : boolean ; preservedKeys ? : string [ ] | PreservedKeysCondition ; caseOptions ? : NoCaseOptions ; } ; export interface ObjectTransformer { ( data , options ? ) : unknown ; } export type ObjectTransformers = { [ K in CaseFunctionTypes ] : ObjectTransformer ; } ; export interface CreateObjectTransformer { ( fn ) : ObjectTransformer ; } export interface CreateObjectTransformerOf { ( type , options ? ) : ObjectTransformer ; } export interface CreateObjectTransformers { ( options ? ) : ObjectTransformers ; } /** converters for axios and their factories */ export type AxiosCaseMiddlewareOptions = Omit < ObjectTransformerOptions , 'overwrite' > & { caseFunctions ? : Partial < CaseFunctions > ; ignoreHeaders ? : boolean ; } ; export interface AxiosInterceptor { ( config ) : AxiosRequestConfig ; } export interface CreateAxiosInterceptor { ( options ? ) : AxiosInterceptor ; } export interface CreateAxiosRequestTransformer { ( options ? ) : AxiosResponseTransformer ; } export interface CreateAxiosResponseTransformer { ( options ? ) : AxiosResponseTransformer ; } /** converter applier */ export type ApplyCaseMiddlewareOptions = AxiosCaseMiddlewareOptions & { caseMiddleware ? : { requestTransformer ? : AxiosRequestTransformer ; responseTransformer ? : AxiosResponseTransformer ; requestInterceptor ? : AxiosInterceptor ; } ; } ; export interface ApplyCaseMiddleware { ( axios , options ? ) : AxiosInstance ; }