import { ErrorWithCode } from "./error"; import { Predicate } from "./misc"; export declare class HTTPError extends ErrorWithCode { constructor(code?: number, message?: string); } export declare class ResourceNotFoundException extends HTTPError { constructor(code?: number, message?: string); } export interface XHRNetworkOptions { /** * Execute after opening but before sending the XHR {@param xhr} */ prerequest: (xhr: XMLHttpRequest) => void; /** * The HTTP method by which to make the request */ method: "GET" | "HEAD" | "POST" | "PUT" | "DELETE" | "CONNECT" | "OPTIONS" | "TRACE" | "PATCH"; body?: Document | BodyInit | null; /** * Determines when to resolve the Promise instead of rejecting * * Defaults to ensuring the status is in [200, 300) */ resolveCondition: Predicate; } export declare class Network { /** * Fetch a network resource as JSON and return the parsed object * * Use instead of `window.fetch` because it * rejects failed transactions * and provides a legacy XHR interface. * If the legacy interface is not a concern, use [[`Network.loadJSON`]]. * * @param filePath The network URL of file to be fetched * @return The resource as parsed JSON object * @throws {ResourceNotFoundException} if the request fails, * defined by the status not being in [200, 300) * @warn Doesn't implement timeout logic * @deprecated */ static loadJSONXHR(filePath: string): Promise; /** * `Promise` wrapper for `XMLHttpRequest` * * Use instead of `window.fetch` because it * rejects failed transactions * and provides a legacy XHR interface. * If the legacy interface is not a concern, use [[`Network.fetch`]]. * * @return * The XHR as a Promise, * with a [[`ResourceNotFoundException`]] in case of rejection * @throws {ResourceNotFoundException} if the request fails, * as defined by the negation of {@param resolveCondition} * @warn Doesn't implement timeout logic * @deprecated */ static fetchXHR(url: string, { prerequest, method, body, resolveCondition, }?: Partial): Promise; /** * Makes a network request to a resource and returns its data parsed as JSON * * Use instead of `window.fetch` because it rejects failed transactions. * * @return The result of the request to the resource, parsed as JSON, if it is `ok` * @throws {ResourceNotFoundException} if not `ok` */ static loadJSON(input: RequestInfo, init?: RequestInit): Promise; /** * Makes a network request * * Use instead of `window.fetch` because it rejects failed transactions. * * @return The result of `window.fetch`, if it is `ok` * @throws {ResourceNotFoundException} if not `ok` */ static fetch(input: RequestInfo, init?: RequestInit): Promise; }