import * as _vobs_vobs from '@vobs/vobs'; import { VobsPlugin } from '@vobs/vobs'; import { RuntimeDebugContext } from '@vobs/runtime'; export { SSEClient, SSEConstructor, SSEOptions, WebSocketClient, WebSocketConstructor, WebSocketEventListener, WebSocketEventName, WebSocketOptions, WebSocketState, createSSE, createWebSocket } from './stream.js'; type HTTPMethod = 'DELETE' | 'GET' | 'HEAD' | 'OPTIONS' | 'PATCH' | 'POST' | 'PUT'; type HTTPResponseType = 'arrayBuffer' | 'blob' | 'json' | 'response' | 'text'; type HTTPHeaders = Record; type RetryDelay = number | ((attempt: number, error: Error) => number); interface HTTPProgress { readonly loaded: number; readonly total: number | undefined; readonly percent: number | undefined; } type HTTPProgressHandler = (progress: HTTPProgress) => void; interface RequestOptions { url: string; method?: HTTPMethod; baseURL?: string; headers?: HeadersInit; params?: Record | URLSearchParams; body?: unknown; signal?: AbortSignal; /** @deprecated Use signal. */ state?: AbortSignal; timeout?: number; retry?: number; retryDelay?: RetryDelay; shouldRetry?: (error: Error, attempt: number) => boolean | PromiseLike; cache?: RequestCache; credentials?: RequestCredentials; mode?: RequestMode; responseType?: HTTPResponseType; onUploadProgress?: HTTPProgressHandler; onDownloadProgress?: HTTPProgressHandler; /** Share an in-flight request with the same dedupe key. */ dedupe?: boolean; dedupeKey?: string; /** Optional context copied into DevTools request traces. */ debugContext?: HTTPDebugContext; } interface RequestConfig extends Omit { readonly method: HTTPMethod; headers: HTTPHeaders; readonly url: string; } interface HTTPResponse { readonly data: T; readonly status: number; readonly statusText: string; readonly headers: Headers; readonly config: RequestConfig; readonly raw: Response | null; } /** Adapt an HTTP request to the fetcher contract used by Resource. */ type HTTPResourceRequest = (signal: AbortSignal) => HTTPResponse | PromiseLike>; declare function toResourceFetcher(request: HTTPResourceRequest): (signal: AbortSignal) => Promise; type HTTPAdapter = (config: RequestConfig) => Response | HTTPResponse | PromiseLike>; interface AxiosResponseLike { readonly data: T; readonly status: number; readonly statusText?: string; readonly headers?: HeadersInit; readonly raw?: Response | null; } type AxiosRequestConfigLike = RequestConfig & { readonly data?: unknown; }; type AxiosRequest = (config: AxiosRequestConfigLike) => PromiseLike>; /** Bridges an Axios request function while preserving HTTPResponse.data typing. */ declare function createAxiosAdapter(request?: AxiosRequest): HTTPAdapter; /** * Creates an adapter for deterministic local handlers and test transports. * Returning a Response or HTTPResponse keeps full control over status and * headers; any other value becomes a successful 200 payload. */ declare function createMockAdapter(handler: (config: RequestConfig) => unknown | PromiseLike): HTTPAdapter; /** XMLHttpRequest adapter for upload and download progress events. */ declare function createXHRAdapter(): HTTPAdapter; /** Explicit fetch transport for applications that do not want the built-in Axios transport. */ declare function createFetchAdapter(): HTTPAdapter; interface HTTPClientOptions { baseURL?: string; headers?: HeadersInit; timeout?: number; adapter?: HTTPAdapter; retry?: number; retryDelay?: RetryDelay; shouldRetry?: (error: Error, attempt: number) => boolean | PromiseLike; concurrency?: number; dedupe?: boolean; } interface InterceptorManager { use(onFulfilled?: (value: T) => TResult | PromiseLike, onRejected?: (error: unknown) => TResult | PromiseLike): number; eject(id: number): void; clear(): void; } interface HTTPInterceptors { readonly request: InterceptorManager; readonly response: InterceptorManager>; } interface HTTPClient { readonly interceptors: HTTPInterceptors; request(options: RequestOptions): Promise>; get(url: string, options?: Omit): Promise>; delete(url: string, options?: Omit): Promise>; head(url: string, options?: Omit): Promise>; post(url: string, body?: unknown, options?: Omit): Promise>; put(url: string, body?: unknown, options?: Omit): Promise>; patch(url: string, body?: unknown, options?: Omit): Promise>; } interface ConcurrencyLimiter { (task: () => T | PromiseLike): Promise; } declare class HTTPError extends Error { readonly status: number; readonly statusText: string; readonly data: unknown; readonly config: RequestConfig; readonly response: HTTPResponse; constructor(response: HTTPResponse); } declare class TimeoutError extends Error { readonly code = "ETIMEDOUT"; /** * 超时时手上那个错误。 * * 整链预算到点会把当前错误换成 TimeoutError —— 原来原错误就此丢掉(报告 P12:真实的 * ECONNREFUSED 变成了无 cause 的超时)。挂在这里,排查时还有线索。 */ readonly cause?: unknown; constructor(timeout: number, cause?: unknown); } declare const HTTP_KEY: _vobs_vobs.InjectionKey; interface HTTPPluginOptions extends HTTPClientOptions { client?: HTTPClient; } declare function createHTTPClient(options?: HTTPClientOptions): HTTPClient; declare function httpPlugin(options?: HTTPPluginOptions): VobsPlugin; declare function createConcurrencyLimiter(limit: number): ConcurrencyLimiter; type HTTPDebugStatus = 'loading' | 'retrying' | 'success' | 'error' | 'cancelled'; type HTTPDebugCacheStatus = 'hit' | 'miss' | 'revalidated'; interface HTTPDebugContext extends RuntimeDebugContext { readonly cacheStatus?: HTTPDebugCacheStatus; /** Marks a request created from the DevTools request tester. */ readonly test?: boolean; } interface HTTPDebugRequest { readonly id: number; readonly phase: 'start' | 'retry' | 'end'; readonly status: HTTPDebugStatus; readonly url: string; readonly method: HTTPMethod; readonly headers: HTTPHeaders; readonly requestBody?: unknown; readonly startedAt: number; readonly endedAt?: number; readonly duration?: number; readonly attempt: number; readonly retries: number; readonly responseStatus?: number; readonly responseBody?: unknown; readonly error?: { readonly name: string; readonly message: string; }; readonly context?: HTTPDebugContext; } interface HTTPDebugHooks { request?(event: HTTPDebugRequest): void; } declare function setHTTPDebugHooks(hooks: HTTPDebugHooks | null): HTTPDebugHooks | null; declare function getHTTPDebugHooks(): HTTPDebugHooks | null; declare function subscribeHTTPDebug(listener: NonNullable): () => void; declare function emitHTTPDebug(event: HTTPDebugRequest): void; export { type AxiosRequest, type AxiosRequestConfigLike, type AxiosResponseLike, type ConcurrencyLimiter, type HTTPAdapter, type HTTPClient, type HTTPClientOptions, type HTTPDebugCacheStatus, type HTTPDebugContext, type HTTPDebugHooks, type HTTPDebugRequest, type HTTPDebugStatus, HTTPError, type HTTPHeaders, type HTTPInterceptors, type HTTPMethod, type HTTPPluginOptions, type HTTPProgress, type HTTPProgressHandler, type HTTPResourceRequest, type HTTPResponse, type HTTPResponseType, HTTP_KEY, type InterceptorManager, type RequestConfig, type RequestOptions, type RetryDelay, TimeoutError, createAxiosAdapter, createConcurrencyLimiter, createFetchAdapter, createHTTPClient, createMockAdapter, createXHRAdapter, emitHTTPDebug, getHTTPDebugHooks, httpPlugin, setHTTPDebugHooks, subscribeHTTPDebug, toResourceFetcher };