@westacks/vortex
Version:
Server-based routing for SPAs
60 lines (59 loc) • 3.32 kB
TypeScript
import { AxiosRequestConfig, AxiosResponse, AxiosInstance, AxiosInterceptorManager, HeadersDefaults, AxiosHeaderValue, InternalAxiosRequestConfig } from 'axios';
export interface Router extends AxiosInstance {
new (config?: RouterRequestConfig): any;
interceptors: {
request: AxiosInterceptorManager<InternalRouterRequestConfig>;
response: AxiosInterceptorManager<RouterResponse>;
};
getUri(config?: RouterRequestConfig): string;
request<T = any, R = RouterResponse<T>, D = any>(config: RouterRequestConfig<D>): Promise<R>;
get<T = any, R = RouterResponse<T>, D = any>(url: string, config?: RouterRequestConfig<D>): Promise<R>;
delete<T = any, R = RouterResponse<T>, D = any>(url: string, config?: RouterRequestConfig<D>): Promise<R>;
head<T = any, R = RouterResponse<T>, D = any>(url: string, config?: RouterRequestConfig<D>): Promise<R>;
options<T = any, R = RouterResponse<T>, D = any>(url: string, config?: RouterRequestConfig<D>): Promise<R>;
post<T = any, R = RouterResponse<T>, D = any>(url: string, data?: D, config?: RouterRequestConfig<D>): Promise<R>;
put<T = any, R = RouterResponse<T>, D = any>(url: string, data?: D, config?: RouterRequestConfig<D>): Promise<R>;
patch<T = any, R = RouterResponse<T>, D = any>(url: string, data?: D, config?: RouterRequestConfig<D>): Promise<R>;
postForm<T = any, R = RouterResponse<T>, D = any>(url: string, data?: D, config?: RouterRequestConfig<D>): Promise<R>;
putForm<T = any, R = RouterResponse<T>, D = any>(url: string, data?: D, config?: RouterRequestConfig<D>): Promise<R>;
patchForm<T = any, R = RouterResponse<T>, D = any>(url: string, data?: D, config?: RouterRequestConfig<D>): Promise<R>;
reload<T = any, R = AxiosResponse<T>, D = any>(config?: RouterRequestConfig<D>): Promise<R>;
<T = any, R = RouterResponse<T>, D = any>(config: RouterRequestConfig<D>): Promise<R>;
<T = any, R = RouterResponse<T>, D = any>(url: string, config?: RouterRequestConfig<D>): Promise<R>;
defaults: Omit<RouterDefaults, 'headers'> & {
headers: HeadersDefaults & {
[key: string]: AxiosHeaderValue;
};
};
}
interface RouterDefaults<D = any> extends Omit<RouterRequestConfig<D>, 'headers'> {
headers: HeadersDefaults;
}
export interface VortexConfig {
[key: string]: unknown;
}
export type PrefetchConfig = number | string | (string | number)[] | boolean;
export interface RouterRequestConfig<D = any> extends AxiosRequestConfig<D> {
vortex?: VortexConfig | boolean;
prefetch?: PrefetchConfig;
[key: string]: unknown;
}
export interface InternalRouterRequestConfig<D = any> extends InternalAxiosRequestConfig<D> {
vortex?: VortexConfig | boolean;
prefetch?: PrefetchConfig;
}
export interface RouterResponse<T = any, D = any> extends AxiosResponse<T, D> {
config: InternalRouterRequestConfig<D>;
}
export type VortexExtension = (interceptors: Router["interceptors"]) => () => void | (() => void);
export declare let axios: Router;
/**
* Register Vortex extensions
*
* @param extensions Vortex extensions
* @returns Uninstall function
*/
export declare function install(...extensions: VortexExtension[]): () => void;
export declare function createRouter(): void;
export declare function destroyRouter(): void;
export {};