import { Chain } from "../types/chain.js"; import { ErrorType } from "../errors/utils.js"; import { CreateTransportErrorType, Transport, TransportConfig } from "../types/transport.js"; //#region src/transports/fallback.d.ts type OnResponseFn = (args: { method: string; params: unknown[]; transport: ReturnType; } & ({ error?: undefined; response: unknown; status: "success"; } | { error: Error; response?: undefined; status: "error"; })) => void; type RankOptions = { /** * The polling interval (in ms) at which the ranker should ping the RPC URL. * @default client.pollingInterval */ interval?: number | undefined; /** * Ping method to determine latency. */ ping?: (parameters: { transport: ReturnType; }) => Promise | undefined; /** * The number of previous samples to perform ranking on. * @default 10 */ sampleCount?: number | undefined; /** * Timeout when sampling transports. * @default 1_000 */ timeout?: number | undefined; /** * Weights to apply to the scores. Weight values are proportional. */ weights?: { /** * The weight to apply to the latency score. * @default 0.3 */ latency?: number | undefined; /** * The weight to apply to the stability score. * @default 0.7 */ stability?: number | undefined; } | undefined; }; type FallbackTransportConfig = { /** The key of the Fallback transport. */key?: TransportConfig["key"] | undefined; /** The name of the Fallback transport. */ name?: TransportConfig["name"] | undefined; /** Toggle to enable ranking, or rank options. */ rank?: boolean | RankOptions | undefined; /** The max number of times to retry. */ retryCount?: TransportConfig["retryCount"] | undefined; /** The base delay (in ms) between retries. */ retryDelay?: TransportConfig["retryDelay"] | undefined; /** Callback on whether an error should throw or try the next transport in the fallback. */ shouldThrow?: (error: Error) => boolean | undefined; }; type FallbackTransport = Transport<"fallback", { onResponse: (fn: OnResponseFn) => void; transports: { [key in keyof transports]: ReturnType }; }>; type FallbackTransportErrorType = CreateTransportErrorType | ErrorType; declare function fallback(transports_: transports, config?: FallbackTransportConfig): FallbackTransport; declare function shouldThrow(error: Error): boolean; /** @internal */ declare function rankTransports({ chain, interval, onTransports, ping, sampleCount, timeout, transports, weights }: { chain?: Chain | undefined; interval: RankOptions["interval"]; onTransports: (transports: readonly Transport[]) => void; ping?: RankOptions["ping"] | undefined; sampleCount?: RankOptions["sampleCount"] | undefined; timeout?: RankOptions["timeout"] | undefined; transports: readonly Transport[]; weights?: RankOptions["weights"] | undefined; }): void; //#endregion export { FallbackTransport, FallbackTransportConfig, FallbackTransportErrorType, OnResponseFn, fallback, rankTransports, shouldThrow }; //# sourceMappingURL=fallback.d.ts.map