/** A service result. */ export interface IServiceResultBase { /** The error. */ error?: IServiceError; } /** A service result. */ export interface IServiceResult extends IServiceResultBase { /** The value. */ value?: T; } /** An error. */ export interface IServiceError { /** The error code. */ code?: string; /** The error message. (For developers, not end users.) */ message?: string; /** Advanced error details. */ details?: Record; /** The inner error. */ innerError?: IServiceError; } /** Options for an HTTP client. */ export interface IHttpClientOptions { /** The fetch object. */ fetch: HttpClientUtility.IFetch; /** The base URI of the service. */ baseUri?: string; } /** Helpers for HTTP clients. */ export declare namespace HttpClientUtility { /** The fetch function. */ interface IFetch { (uri: string, request: IFetchRequest, context?: unknown): Promise; } /** The minimal fetch request. */ interface IFetchRequest { method?: string; headers?: Record; body?: string; } /** The minimal fetch response. */ interface IFetchResponse { status: number; ok?: boolean; headers: { get(name: string): string | null; }; body?: IWebReadableStream | INodeReadableStream | null; json(): Promise; } /** A fetch response with any fetched content. */ interface IFetchedResponseWithContent { /** The fetch response. */ response: IFetchResponse; /** The fetched JSON, if any. */ json?: unknown; } /** Web Streams API ReadableStream (browser). */ interface IWebReadableStream { getReader(): { read(): Promise<{ done: boolean; value?: Uint8Array; }>; cancel(): Promise; }; } /** Node.js ReadableStream. */ interface INodeReadableStream { on(event: 'data', listener: (chunk: Uint8Array | ArrayBuffer) => void): void; on(event: 'end', listener: () => void): void; on(event: 'error', listener: (err: Error) => void): void; off?(event: string, listener: (...args: unknown[]) => void): void; removeAllListeners?(): void; } /** Fetch JSON using the specified fetch, URI, and request. */ function fetchResponse(fetch: IFetch, uri: string, request: IFetchRequest, context?: unknown): Promise; /** Creates an error result for the specified response. */ function createResponseError(status: number, json?: unknown): IServiceResultBase; /** Creates an error result for a required request field. */ function createRequiredRequestFieldError(name: string): IServiceResultBase; /** Creates an async iterable stream from a fetch SSE response. */ function createFetchEventStream(fetchFunc: IFetch, url: string, fetchRequest: IFetchRequest, context?: unknown): Promise>>>; }