declare const HTTP_CONTEXT_TOKEN: unique symbol; export type HttpContextToken = (() => T) & { readonly [HTTP_CONTEXT_TOKEN]: () => T; }; export declare function makeHttpContextToken(defaultValue: () => T): HttpContextToken; export declare function isHttpContextToken(value: unknown): value is HttpContextToken; declare const HTTP_CONTEXT: unique symbol; export type HttpContext = { set(token: HttpContextToken, value: T): HttpContext; get(token: HttpContextToken): T; del(token: HttpContextToken): HttpContext; has(token: HttpContextToken): boolean; keys(): IterableIterator>; get length(): number; readonly [HTTP_CONTEXT]: Map, unknown>; }; export declare function makeHttpContext(): HttpContext; export declare function makeHttpContext(entries?: readonly (readonly [ HttpContextToken, unknown ])[]): HttpContext; export declare function makeHttpContext(context?: HttpContext): HttpContext; export type ValidatorFn = (value: T) => void; export type AsyncValidatorFn = (value: T) => Promise; export declare const required: ValidatorFn; export declare const requiredTrue: ValidatorFn; export declare const minLength: (min: number) => ValidatorFn; export declare const maxLength: (max: number) => ValidatorFn; export declare const min: (min: number) => ValidatorFn; export declare const max: (max: number) => ValidatorFn; export declare const pattern: (pattern: RegExp) => ValidatorFn; declare const FIELD: unique symbol; declare enum FieldType { Json = 0, Query = 1, Param = 2, Header = 3, Form = 4, Body = 5, UrlForm = 6 } export interface FieldMetadata { required: boolean; alias: Map; validators: ValidatorFn[]; asyncValidator: AsyncValidatorFn[]; } export type Field = (() => T) & { withJson(alias?: string): Field; withForm(alias?: string): Field; withQuery(alias?: string): Field; withParam(alias?: string): Field; withHeader(alias?: string): Field; withUrlForm(alias?: string): Field; withBody(): Field; withValidators(...fn: ValidatorFn[]): Field; withAsyncValidators(...fn: AsyncValidatorFn[]): Field; readonly [FIELD]: FieldMetadata; }; export declare function field(): Field; export declare function field(): Field; export declare function field(defaultValue: T): Field; export declare function doValid(validators: (ValidatorFn | AsyncValidatorFn)[], value: T): Promise; export declare function isField(value: unknown): value is Field; export declare function isFieldGroup(value: unknown): value is Record; export declare const ERR_ABORTED: Error; export declare const ERR_TIMEOUT: Error; export declare const ERR_NETWORK: Error; export declare const ERR_NOT_FOUND_HANDLER: Error; export declare const ERR_OBSERVE: Error; export declare const ERR_NOT_SET_ALIAS: Error; export declare const ERR_UNSUPPORTED_FIELD_TYPE: Error; export declare const ERR_INVALID_CLIENT: Error; export declare const ERR_NOT_FOUND_GLOBAL_CLIENT: Error; export declare const ERR_INVALID_HTTP_CONTEXT_TOKEN: Error; export declare const ERR_UNKNOWN: Error; export type HttpResponseBody = string | ArrayBuffer | Blob | object | null; export type HttpResponse = { readonly url: string; readonly status: number; readonly statusText: string; readonly headers: Headers; readonly body: R | null; readonly error?: Error | string | unknown; }; export type MakeResponseOptions = { status?: number; statusText?: string; url?: string; headers?: Headers; body?: R | null; error?: Error | string | unknown; }; export type InterceptorFn = (req: HttpRequest, next: HttpHandler) => Promise>; export type BasicCredential = { username: string; password: string; }; export type BasicAuthInterceptorOptions = { encode?: (credential: BasicCredential) => string; }; export declare function basicAuthInterceptor(fn: () => BasicCredential, options?: BasicAuthInterceptorOptions): InterceptorFn; export type HttpResponseType = "arraybuffer" | "blob" | "json" | "text"; export interface HttpProgressEvent { /** * Indicates whether the resources associated with Progress have a computable length. * Otherwise, the Progress.total attribute will be a meaningless value. */ readonly lengthComputable: boolean; /** Indicates the workload of the underlying process. */ readonly loaded: number; /** * The total size of the data being processed or transmitted. * If the Progress.lengthComputable attribute is false, this value is meaningless and should be ignored. */ readonly total: number; } export type HttpProgressFn = (event: HttpProgressEvent) => void; export type TransformResponseFn = (response: HttpResponse) => Output; export interface HttpRequest { host?: string; method: string; endpoint: string; body?: Blob | ArrayBuffer | FormData | URLSearchParams | object | string | number | boolean | null; headers?: Headers; queryParams?: URLSearchParams; /** default:json */ responseType?: HttpResponseType; context?: HttpContext; timeout?: number; withCredentials?: boolean; /** when use fetch handler, no upload progress */ uploadProgress?: HttpProgressFn; downloadProgress?: HttpProgressFn; abort?: AbortSignal; } export type RequestInputValue = T extends { [K in keyof T]: Field; } ? { [K in keyof T]: T[K] extends Field ? V : never; } : never; export type UseRequestOptions = { abort?: AbortSignal; handler?: HttpHandler; client?: Client; timeout?: number; }; export type UseRequestFn = { doRequest: undefined extends RequestInputValue ? (input?: RequestInputValue) => Promise> : (input: RequestInputValue) => Promise>; cancel: () => void; getInitValue: () => RequestInputValue; setUploadProgress: (fn: HttpProgressFn) => void; setDownloadProgress: (fn: HttpProgressFn) => void; }; export interface DefineRequest> | undefined = undefined, Output = unknown> { (options?: UseRequestOptions): UseRequestFn; withField>>(value: I): DefineRequest; withInterceptors(value: InterceptorFn[]): DefineRequest; withContext(value: HttpContext): DefineRequest; withCredentials(value: boolean): DefineRequest; withValidators(...fn: (ValidatorFn> | AsyncValidatorFn>)[]): DefineRequest; withTransformResponse(fn: TransformResponseFn): DefineRequest; withResponseType(value: "json"): DefineRequest; withResponseType(value: "text"): DefineRequest; withResponseType(value: "blob"): DefineRequest; withResponseType(value: "arraybuffer"): DefineRequest; } export declare function defineRequest(endpoint: string): DefineRequest; export declare function defineRequest(method: string, endpoint: string): DefineRequest; export type HttpHandler = (req: HttpRequest) => Promise>; export declare function fetchHandler(httpRequest: HttpRequest): Promise>; export interface ClientOptions { host: string; interceptors?: InterceptorFn[]; handler?: HttpHandler; } export type ClientConfig = { host: string; handler: HttpHandler; interceptors: InterceptorFn[]; }; declare const CLIENT: unique symbol; export type Client = { readonly [CLIENT]: ClientConfig; }; export declare function isClient(value: unknown): value is Client; export declare function createClient(options: ClientOptions): Client; export declare function cloneClient(client: Client, options: Partial): Client; export declare function getGlobalClient(): Client; export declare function setGlobalClient(client: Client): void; export declare function restGlobalClient(): void; export declare function createGlobalClient(options: ClientOptions): void; export {};