UNPKG

evil-vue

Version:

Evil vue3 writing, similar to angular writing Dependency injection

55 lines (54 loc) 2.65 kB
import { InjectionToken } from 'injection-js'; import { AxiosClient, HttpResponse } from './types'; import { AxiosRequestConfig } from 'axios'; export interface HttpResponseInterceptor { interceptResponse(response: HttpResponse): HttpResponse | Promise<HttpResponse>; interceptResponseError?(error: any): Promise<any> | any; } export interface HttpRequestInterceptor { interceptRequest(request: AxiosRequestConfig): AxiosRequestConfig | Promise<AxiosRequestConfig>; interceptRequestError?(error: any): Promise<any> | any; } export interface HttpInterceptor { /** * Intercept an outgoing `HttpRequest` and optionally transform it or the * response. * * Typically an interceptor will transform the outgoing request before returning * `next.handle(transformedReq)`. An interceptor may choose to transform the * response event stream as well, by applying additional Rx operators on the stream * returned by `next.handle()`. * * More rarely, an interceptor may choose to completely handle the request itself, * and compose a new event stream instead of invoking `next.handle()`. This is * acceptable behavior, but keep in mind further interceptors will be skipped entirely. * * It is also rare but valid for an interceptor to return multiple responses on the * event stream for a single request.q */ interceptRequest?(request: AxiosRequestConfig): AxiosRequestConfig | Promise<AxiosRequestConfig>; interceptRequestError?(error: any): Promise<any> | any; interceptResponse?(response: HttpResponse): HttpResponse | Promise<HttpResponse>; interceptResponseError?(error: any): Promise<any> | any; } /** * A multi-provider token which represents the array of `HttpInterceptor`s that * are registered. */ export declare const HTTP_INTERCEPTORS: InjectionToken<HttpInterceptor[]>; export declare const HTTP_INTERCEPTORS_LOGGER: InjectionToken<HttpInterceptor[]>; /** * `HttpInterceptorHandler` which registers an `HttpInterceptor[]` to `HttpClient` instance. * @private */ export declare class HttpInterceptorHandler { private _interceptors; private _registeredInterceptors; get registeredInterceptors(): number[]; constructor(_interceptors: HttpResponseInterceptor[] | HttpRequestInterceptor[] | HttpResponseInterceptor | HttpRequestInterceptor); register(httpClientInterceptors: AxiosClient['interceptors']): void; } export declare class NoopInterceptor implements HttpResponseInterceptor, HttpRequestInterceptor { interceptRequest(request: any): any; interceptResponse(response: HttpResponse): HttpResponse<any>; }