import { Event } from '../../../util/vs/base/common/event'; export declare const IFetcherService: import("../../../util/common/services").ServiceIdentifier; /** Use as the callSite value to suppress fetch telemetry for a request (e.g. from the telemetry service itself). */ export declare const NO_FETCH_TELEMETRY = "NO_FETCH_TELEMETRY"; export interface IFetcherService { readonly _serviceBrand: undefined; readonly onDidFetch: Event; readonly onDidCompleteFetch: Event; getUserAgentLibrary(): string; fetch(url: string, options: FetchOptions): Promise; createWebSocket(url: string, options?: WebSocketConnectOptions): WebSocketConnection; disconnectAll(): Promise; makeAbortController(): IAbortController; isAbortError(e: any): boolean; isInternetDisconnectedError(e: any): boolean; isFetcherError(e: any): boolean; isNetworkProcessCrashedError(e: any): boolean; getUserMessageForFetcherError(err: any): string; fetchWithPagination(baseUrl: string, options: PaginationOptions): Promise; } export type FetchEvent = { internalId: string; timestamp: number; outcome: 'success'; phase: 'requestResponse'; fetcher: FetcherId; hostname: string; statusCode: number; } | { internalId: string; timestamp: number; outcome: 'success'; phase: 'responseStreaming'; fetcher: FetcherId; hostname: string; bytesReceived: number; } | { internalId: string; timestamp: number; outcome: 'error' | 'cancel'; phase: 'requestResponse'; fetcher: FetcherId; hostname: string; reason: any; } | { internalId: string; timestamp: number; outcome: 'error' | 'cancel'; phase: 'responseStreaming'; fetcher: FetcherId; hostname: string; reason: any; bytesReceived: number; }; export type ReportFetchEvent = (outcome: FetchEvent) => void; export interface FetchTelemetryEvent { callSite: string; hostname: string; latencyMs: number; statusCode: number | undefined; success: boolean; /** * Cache outcome when the caller opted in via {@link FetchOptions.cache}. * `undefined` when the caller did not opt in or the selected fetcher does * not implement caching. */ cacheStatus?: CacheStatus; } export type CacheStatus = 'hit' | 'stale-hit' | 'revalidated' | 'miss' | 'bypass'; /** A basic version of http://developer.mozilla.org/en-US/docs/Web/API/Response */ export declare class Response { readonly status: number; readonly statusText: string; readonly headers: IHeaders; readonly fetcher: FetcherId; private readonly _reportEvent; private readonly _internalId; private readonly _hostname; readonly cacheStatus?: CacheStatus | undefined; ok: boolean; readonly body: DestroyableStream; private _bytesReceived; get bytesReceived(): number; constructor(status: number, statusText: string, headers: IHeaders, body: ReadableStream | null, fetcher: FetcherId, _reportEvent: ReportFetchEvent, _internalId: string, _hostname: string, cacheStatus?: CacheStatus | undefined); static fromText(status: number, statusText: string, headers: IHeaders, body: string, fetcher: FetcherId): Response; text(): Promise; json(): Promise; } export type FetcherId = 'electron-fetch' | 'node-fetch' | 'node-http' | 'test-stub' | 'helix-fetch'; /** These are the options we currently use, for ease of reference. */ export interface FetchOptions { /** Identifies the call site for telemetry tracking. Use {@link NO_FETCH_TELEMETRY} to suppress. */ callSite: string; headers?: { [name: string]: string; }; body?: string; timeout?: number; /** * If `json` is provided, it will be stringified using `JSON.stringify` and sent as the body with * the `Content-Type` header set to `application/json`. */ json?: unknown; method?: 'GET' | 'POST' | 'PUT'; signal?: IAbortSignal; retryFallbacks?: boolean; expectJSON?: boolean; useFetcher?: FetcherId; suppressIntegrationId?: boolean; /** * Opportunistic cache hint. When set to `true`, fetchers that implement * caching (today only the Node fetch fetcher) will route the request * through an RFC 9111 cache. Fetchers without cache support ignore this * flag, and fallback to other fetchers continues to work normally. */ cache?: boolean; } export interface PaginationOptions extends FetchOptions { pageSize?: number; startPage?: number; getItemsFromResponse: (data: any) => T[]; buildUrl: (baseUrl: string, pageSize: number, page: number) => string; } export interface WebSocketConnectOptions { headers?: { [name: string]: string; }; } export interface WebSocketConnection { readonly webSocket: WebSocket; readonly responseHeaders: IHeaders; readonly responseStatusCode: number | undefined; readonly responseStatusText: string | undefined; readonly networkError: Error | undefined; } export interface IAbortSignal { readonly aborted: boolean; addEventListener(type: 'abort', listener: (this: AbortSignal) => void): void; removeEventListener(type: 'abort', listener: (this: AbortSignal) => void): void; } export interface IAbortController { readonly signal: IAbortSignal; abort(): void; } export interface IHeaders extends Iterable<[string, string]> { get(name: string): string | null; } export declare class HeadersImpl implements IHeaders { private readonly _record; constructor(_record: Readonly>); static fromMap(map: ReadonlyMap): HeadersImpl; get(name: string): string | null; [Symbol.iterator](): Iterator<[string, string]>; } /** * Wraps a ReadableStream to allow cancellation even while a `for await` loop * holds the stream locked. Use `destroy()` to safely cancel from an external * callback (e.g., `onReturn`) - it cancels through the reader if locked. * * When `pipeThrough()` is called, destroy() will forward to the piped stream. */ export declare class DestroyableStream implements AsyncIterable { private readonly stream; private reader; private pipedHead; constructor(stream: ReadableStream); /** * Returns the underlying ReadableStream for APIs that require it * (e.g., Readable.fromWeb). Use with caution as operations on the * returned stream bypass the DestroyableStream's reader tracking. */ toReadableStream(): ReadableStream; /** * Pipes this stream through a transform stream. * Returns a new DestroyableStream wrapping the transformed stream. * Calling destroy() on this stream will forward to the piped stream. */ pipeThrough(transform: { readable: ReadableStream; writable: WritableStream; }): DestroyableStream; [Symbol.asyncIterator](): AsyncGenerator; destroy(): Promise; } export declare function jsonVerboseError(resp: Response): Promise; export declare function isAbortError(e: any): boolean; export declare function safeGetHostname(url: string): string; //# sourceMappingURL=fetcherService.d.ts.map