import RestError from "./rest-error"; export interface IKeyValue { [key: string]: any; } export interface IRestOptionsQuery { query: IKeyValue; queryParamsTransformer: IQueryParamTransformer; queryParamsIncludeEmpty: boolean; } type Mutable = { -readonly [Key in keyof Type]: Type[Key]; }; export type AllowedNativeOptions = Omit, "clone" | "signal" | "url" | keyof Body>; export interface IRestOptionsNative extends AllowedNativeOptions { } export interface IRestOptionsProtected { overrideStrategy: LocalOverrideStrategy; } export interface IRestOptions extends IRestOptionsQuery, IRestOptionsNative { host: string; basePath: string; responseType: HttpResponseFormat; body: ArrayBuffer | ArrayBufferView | Blob | File | string | URLSearchParams | FormData | IKeyValue; timeout: number; cacheInMemory: boolean; cacheKey: string; cacheExpireIn: number; throw: boolean; throwExcluding: IResponseFilter[]; abortController: AbortController; onRequest(request: IRequest): void | Promise; onResponse(response: IResponse): void; onError(error: RestError, response: TResponse): void; } export interface IRestOptionsGlobals extends IRestOptions, IRestOptionsProtected { } export type LocalOverrideStrategy = "merge" | "assign"; export interface IRequest { options: Partial>; url: URL; method: HttpMethod; body: any; } export interface IResponse { fetchResponse: Response | null; request: IRequest; error?: RestError; status: HTTPStatusCode; headers?: Headers; data: TResponse | null; throwFilter?: IResponseFilter; repeat: IRepeat; } export interface IRepeat { (method: HttpMethod, requestOptions?: Partial>): Promise>; } export interface IRepeat { (requestOptions?: Partial>): Promise>; } interface IResponseFilterObject { path?: string; method?: HttpMethod; statusCode?: HTTPStatusCode; errorCode?: InternalErrorCode; } interface IResponseFilterHook { (restError: RestError): boolean; } interface IResponseFilterHookAsync { (restError: RestError): Promise; } export type IResponseFilter = IResponseFilterHook | IResponseFilterHookAsync | IResponseFilterObject; export type InternalErrorCode = "Timeout" | "BodyParse" | "UrlParameter"; export interface IQueryParamTransformer { (key: string, value: any, query: any): string; } export interface IResponseAny { (prom: Promise): Promise<[TData | null, TError | null]>; } export interface IResponseAny { (prom: Promise): Promise<[TResponse | null, Error | RestError | null]>; } export type HttpMethod = 'GET' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'POST' | 'PUT' | 'PATCH' | 'LINK'; export type HttpResponseFormatType = "json" | "text" | "blob" | "arrayBuffer" | "formData" | undefined | null; export type HttpResponseFormat = HttpResponseFormatType | { (request: IRequest, fetchResponse: Response | null): HttpResponseFormatType; } | { (request: IRequest, fetchResponse: Response | null): Promise; }; export declare const enum HTTPStatusCode { Continue = 100, SwitchingProtocols = 101, Processing = 102, EarlyHints = 103, InformationalResponses = 103, OK = 200, Created = 201, Accepted = 202, NonAuthoritativeInformation = 203, NoContent = 204, ResetContent = 205, PartialContent = 206, MultiStatus = 207, AlreadyReported = 208, IMUsed = 226, Success = 255, MultipleChoices = 300, MovedPermanently = 301, Found = 302, SeeOther = 303, NotModified = 304, UseProxy = 305, SwitchProxy = 306, TemporaryRedirect = 307, PermanentRedirect = 308, Redirection = 319, BadRequest = 400, Unauthorized = 401, PaymentRequired = 402, Forbidden = 403, NotFound = 404, MethodNotAllowed = 405, NotAcceptable = 406, ProxyAuthenticationRequired = 407, RequestTimeout = 408, Conflict = 409, Gone = 410, LengthRequired = 411, PreconditionFailed = 412, PayloadTooLarge = 413, URITooLong = 414, UnsupportedMediaType = 415, RangeNotSatisfiable = 416, ExpectationFailed = 417, ImATeapot = 418, MisdirectedRequest = 421, UnprocessableEntity = 422, Locked = 423, FailedDependency = 424, UpgradeRequired = 426, PreconditionRequired = 428, TooManyRequests = 429, RequestHeaderFieldsTooLarge = 431, UnavailableForLegalReasons = 451, ClientErrors = 511, InternalServerError = 500, NotImplemented = 501, BadGateway = 502, ServiceUnavailable = 503, GatewayTimeout = 504, HTTPVersionNotSupported = 505, VariantAlsoNegotiates = 506, InsufficientStorage = 507, LoopDetected = 508, NotExtended = 510, NetworkAuthenticationRequired = 511, ServerErrors = 511 } export interface HttpResponseFormatResult { success: boolean; result: any; resultType: HttpResponseFormatType; } export {};