libmodpm
Version:
Modrinth package manager library
77 lines (76 loc) • 2.8 kB
TypeScript
/**
* Represents an HTTP client for sending HTTP requests.
*
* @template T Error type.
*/
export declare abstract class HTTPClient<T extends Error> {
/**
* User agent string.
*/
private readonly userAgent;
/**
* Authorisation credentials.
*/
private readonly credentials;
/**
* Creates a new HTTP client.
*
* @param userAgent User agent string.
* @param [credentials] Authorisation credentials.
*/
protected constructor(userAgent: string, credentials?: string);
/**
* Returns a promise which is resolved after the specified number of milliseconds.
*
* @param delay Number of milliseconds to wait.
*/
private static wait;
/**
* Parses a string representing either a decimal integer or an HTTP date.
*
* @param value String to parse.
* @returns Returns the number of seconds representing the difference relative to the current time, as represented
* by the input.
*/
private static parseRelativeTime;
/**
* Determines whether the specified response represents a transient error, and if so, how long to wait before
* retrying the request.
*
* @param res Response to check.
* @returns
* - a non-negative number specifying the delay in seconds before retrying,
* - `-1` to indicate the delay is unknown and that exponential backoff should be used,
* - or `null` if the response is not a transient error and should not be retried.
*/
private static getTransientErrorRetryDelay;
/**
* Prepares request init options before sending.
*
* @param url Absolute URL.
* @param [options] Request options.
* @param [query] Query parameters.
*/
protected prepareRequest(url: URL | string, options?: RequestInit, query?: URLSearchParams): Request;
/**
* Creates an error instance to throw when fetching fails.
*
* @param res HTTP error response.
* @returns Error instance to throw in {@link fetch}.
*/
protected abstract createError(res: Response): Promise<T>;
/**
* Sends an HTTP request.
*
* @param url Absolute URL.
* @param [options] Request options.
* @param [query] Query parameters.
* @param [retries=3] Maximum number of retry attempts performed if the request fails.
* @throws {@link T} If the request fails with a permanent error, allowed retries
* already exceeded, or delay is more than 30 seconds.
* @throws {@link !TypeError} If the request fails due to a native fetch error, like a network error, DNS error,
* timeout, etc.
* @final
*/
protected fetch(url: URL | string, options?: RequestInit, query?: URLSearchParams, retries?: number): Promise<Response>;
}