/** The Standard Schema interface. */ interface StandardSchemaV1 { /** The Standard Schema properties. */ readonly "~standard": StandardSchemaV1.Props; } declare namespace StandardSchemaV1 { /** The Standard Schema properties interface. */ export interface Props { /** The version number of the standard. */ readonly version: 1; /** The vendor name of the schema library. */ readonly vendor: string; /** Validates unknown input values. */ readonly validate: (value: unknown) => Result | Promise>; /** Inferred types associated with the schema. */ readonly types?: Types | undefined; } /** The result interface of the validate function. */ export type Result = SuccessResult | FailureResult; /** The result interface if validation succeeds. */ export interface SuccessResult { /** The typed output value. */ readonly value: Output; /** The non-existent issues. */ readonly issues?: undefined; } /** The result interface if validation fails. */ export interface FailureResult { /** The issues of failed validation. */ readonly issues: ReadonlyArray; } /** The issue interface of the failure output. */ export interface Issue { /** The error message of the issue. */ readonly message: string; /** The path of the issue, if any. */ readonly path?: ReadonlyArray | undefined; } /** The path segment interface of the issue. */ export interface PathSegment { /** The key representing a path segment. */ readonly key: PropertyKey; } /** The Standard Schema types interface. */ export interface Types { /** The input type of the schema. */ readonly input: Input; /** The output type of the schema. */ readonly output: Output; } /** Infers the input type of a Standard Schema. */ export type InferInput = NonNullable["input"]; /** Infers the output type of a Standard Schema. */ export type InferOutput = NonNullable["output"]; export { }; } declare class ResponseError extends Error { data: TData; status: number; kind: 'response'; constructor(props: { message: string; status: number; data: TData; }); } declare const isResponseError: (error: unknown) => error is ResponseError; type KeyOf = O extends unknown ? keyof O : never; type DistributiveOmit | (string & {})> = TObject extends unknown ? Omit : never; type IsNull = [T] extends [null] ? true : false; type IsUnknown = unknown extends T ? IsNull extends false ? true : false : false; type MaybePromise = T | Promise; type JsonPrimitive = string | number | boolean | null | undefined; type JsonifiableObject = Record; type JsonifiableArray = Array | ReadonlyArray> | ReadonlyArray; type MinFetchFn = (input: Request, options?: any, ctx?: any) => Promise; type ParseResponse = (response: Response, request: Request) => MaybePromise; type ParseRejected = (response: Response, request: Request) => any; type SerializeBody = (body: TRawBody) => BodyInit | null | undefined; type SerializeParams = (params: Params) => string; type Params = Record; type HeadersObject = Record; type Method = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'HEAD' | (string & {}); type BaseOptions = DistributiveOmit[1]>, 'body' | 'headers' | 'method'> & {}; type OnRetry = (context: { response: Response | undefined; error: unknown; request: Request; attempt: number; }) => MaybePromise; type RetryWhen = (context: { response: Response | undefined; error: unknown; request: Request; }) => MaybePromise; type RetryAttempts = number | ((context: { request: Request; }) => MaybePromise); type RetryDelay = number | ((context: { response: Response | undefined; error: unknown; request: Request; attempt: number; }) => MaybePromise); type RetryOptions = { /** * The number of attempts to make before giving up */ attempts?: RetryAttempts; /** * The delay before retrying */ delay?: RetryDelay; /** * Function to determine if a retry attempt should be made */ when?: RetryWhen; }; type ResponseStreamingEvent = { /** The last streamed chunk */ chunk: Uint8Array; /** Total bytes, read from the Response "Content-Length" header */ totalBytes: number | undefined; /** Transferred bytes */ transferredBytes: number; }; type RequestStreamingEvent = { /** The last streamed chunk */ chunk: Uint8Array; /** Total bytes, read from the Request "Content-Length" header or from the Request body */ totalBytes: number; /** Transferred bytes */ transferredBytes: number; }; type DefaultRawBody = BodyInit | JsonifiableObject | JsonifiableArray; type GetDefaultParsedData = TDefaultOptions extends DefaultOptions ? U : never; type GetDefaultRawBody = TDefaultOptions extends DefaultOptions ? IsUnknown extends true ? DefaultRawBody : U : never; /** * Default configuration options for the fetch client */ type DefaultOptions = BaseOptions & { /** Base URL to prepend to all request URLs */ baseUrl?: string; /** Request headers to be sent with each request */ headers?: HeadersInit | HeadersObject; /** HTTP method to use for the request */ method?: Method; /** Executed when the request fails */ onError?: (error: unknown, request: Request) => MaybePromise; /** Executed before the request is made */ onRequest?: (request: Request) => MaybePromise; /** Executed when a response is received, once all retries are completed. Not executed when the fetch itself fails (e.g. network error) */ onResponse?: (response: Response, request: Request) => MaybePromise; /** Executed before each retry */ onRetry?: OnRetry; /** Executed when the request succeeds */ onSuccess?: (data: any, request: Request) => MaybePromise; /** URL parameters to be serialized and appended to the URL */ params?: Params; /** Function to parse response errors */ parseRejected?: ParseRejected; /** Function to parse the response data */ parseResponse?: ParseResponse; /** Function to determine if a response should throw an error */ reject?: (response: Response) => MaybePromise; /** The default retry options. Will be merged with the fetcher options */ retry?: RetryOptions; /** Function to serialize request body. Restrict the valid `body` type by typing its first argument. */ serializeBody?: SerializeBody; /** Function to serialize URL parameters */ serializeParams?: SerializeParams; /** AbortSignal to cancel the request */ signal?: AbortSignal; /** Request timeout in milliseconds */ timeout?: number; }; /** * Options for individual fetch requests */ type FetcherOptions = BaseOptions & { /** Base URL to prepend to the request URL */ baseUrl?: string; /** Request body data */ body?: NoInfer | null | undefined; /** Request headers */ headers?: HeadersInit | HeadersObject; /** HTTP method */ method?: Method; /** Executed when the request fails */ onError?: (error: unknown, request: Request) => MaybePromise; /** Executed before the request is made */ onRequest?: (request: Request) => MaybePromise; /** Executed each time a chunk of the request stream is sent */ onRequestStreaming?: (event: RequestStreamingEvent, request: Request) => MaybePromise; /** Executed each time a chunk of the response stream is received */ onResponseStreaming?: (event: ResponseStreamingEvent, response: Response) => MaybePromise; /** Executed when a response is received, once all retries are completed. Not executed when the fetch itself fails (e.g. network error) */ onResponse?: (response: Response, request: Request) => MaybePromise; /** Executed before each retry */ onRetry?: OnRetry; /** Executed when the request succeeds */ onSuccess?: (data: NoInfer, request: Request) => MaybePromise; /** URL parameters */ params?: Params; /** Function to parse response errors */ parseRejected?: ParseRejected; /** Function to parse the response data */ parseResponse?: ParseResponse; /** Function to determine if a response should throw an error */ reject?: (response: Response) => MaybePromise; /** The fetch retry options. Merged with the default retry options */ retry?: RetryOptions; /** JSON Schema for request/response validation */ schema?: TSchema; /** Function to serialize request body. Restrict the valid `body` type by typing its first argument. */ serializeBody?: SerializeBody; /** Function to serialize URL parameters */ serializeParams?: SerializeParams; /** AbortSignal to cancel the request */ signal?: AbortSignal; /** Request timeout in milliseconds */ timeout?: number; }; type UpFetch = DefaultOptions> = , TSchema extends StandardSchemaV1 = StandardSchemaV1, TRawBody = GetDefaultRawBody>(input: Parameters[0], options?: FetcherOptions, ctx?: Parameters[2]) => Promise>; declare const up: = DefaultOptions>(fetchFn: TFetchFn, getDefaultOptions?: (input: Parameters[0], fetcherOpts: FetcherOptions, ctx?: Parameters[2]) => MaybePromise) => UpFetch; declare const isJsonifiable: (value: any) => value is JsonifiableObject | JsonifiableArray; declare class ResponseValidationError extends Error { issues: readonly StandardSchemaV1.Issue[]; kind: 'validation'; data: TData; constructor(result: StandardSchemaV1.FailureResult, data: TData); } declare const isResponseValidationError: (error: unknown) => error is ResponseValidationError; /** * @deprecated Use `ResponseValidationError` instead. */ declare const ValidationError: typeof ResponseValidationError; /** * @deprecated Use `isResponseValidationError` instead. */ declare const isValidationError: (error: unknown) => error is ResponseValidationError; export { type DefaultOptions, type FetcherOptions, type GetDefaultParsedData, type GetDefaultRawBody, ResponseError, ResponseValidationError, type RetryOptions, StandardSchemaV1, type UpFetch, ValidationError, isJsonifiable, isResponseError, isResponseValidationError, isValidationError, up };