import type { Alova, AlovaDefaultCacheAdapter, AlovaGenerics, AlovaGlobalCacheAdapter, AlovaMethodCommonConfig, AlovaMethodCreateConfig, AlovaOptions, AlovaRequestAdapter, Method, RequestBody, RespondedAlovaGenerics, RespondedHandler, RespondedHandlerRecord, ResponseCompleteHandler, ResponseErrorHandler, StatesExport, StatesHook, } from 'alova'; import type { TokenAuthenticationResult } from 'alova/client'; import type { FetchRequestInit } from 'alova/fetch'; import type { VueHookExportType } from 'alova/vue'; export type AlovaFetchRequestGenerics< Responded = unknown, Transformed = unknown, > = AlovaGenerics< Responded, Transformed, FetchRequestInit, Response, Headers, AlovaDefaultCacheAdapter, AlovaDefaultCacheAdapter, VueHookExportType >; export type RequestedHandler = ( method: Method, ) => Promise | void; /* eslint-disable perfectionist/sort-interfaces */ export interface AlovaClient extends Alova { request( config: AlovaMethodCommonConfig, ): Method>; get( url: string, config?: AlovaMethodCreateConfig, ): Method>; post( url: string, data?: RequestBody, config?: AlovaMethodCreateConfig, ): Method>; put( url: string, data?: RequestBody, config?: AlovaMethodCreateConfig, ): Method>; delete( url: string, data?: RequestBody, config?: AlovaMethodCreateConfig, ): Method>; head( url: string, config?: AlovaMethodCreateConfig, ): Method>; _options( url: string, config?: AlovaMethodCreateConfig, ): Method>; patch( url: string, data?: RequestBody, config?: AlovaMethodCreateConfig, ): Method>; interceptor(type: 'request', fn: RequestedHandler): () => void; interceptor(type: 'success', fn: RespondedHandler): () => void; interceptor(type: 'error', fn: ResponseErrorHandler): () => void; interceptor(type: 'complete', fn: ResponseCompleteHandler): () => void; } export interface ResponseBodyData { code: number; data?: D; message?: string; } export type SimpleAlovaOptions< AG extends AlovaGenerics = AlovaFetchRequestGenerics, > = Pick, 'baseURL' | 'id'> & { interceptor?: RespondedHandlerRecord; tokenStore?: { accessToken?: null | string; loginExpired?: boolean; refreshToken?: null | string; }; transform?: ( data: Record, method: Method>, ) => ResponseBodyData; }; export interface CreateAlovaClient { < RequestConfig, Response, ResponseHeader, L1Cache extends AlovaGlobalCacheAdapter = AlovaDefaultCacheAdapter, L2Cache extends AlovaGlobalCacheAdapter = AlovaDefaultCacheAdapter, SE extends StatesExport = StatesExport, >( options: Partial< Omit< AlovaOptions< AlovaGenerics< any, any, RequestConfig, Response, ResponseHeader, L1Cache, L2Cache, SE > >, 'beforeRequest' | 'responded' > & { tokenAuthentication: TokenAuthenticationResult< StatesHook, AlovaRequestAdapter >; } >, ): AlovaClient< AlovaGenerics< any, any, RequestConfig, Response, ResponseHeader, L1Cache, L2Cache, SE > >; }