/** * Confirm a data can be transform. * @param response * @returns */ declare function canActivate(data: unknown): data is Response; /** * Confirm an error whether is DOMException * @param error * @returns * * @deprecated use `@import('@fatcherjs/middleware-aborter').isAbortError` instead. */ declare function isAbortError(error: unknown): error is DOMException; declare type MaybePromise = T | Promise; /** * HTTP Request Methods */ declare type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS' | 'PATCH'; /** * Middleware Context */ interface Context extends Omit { body?: BodyInit | null; /** * A map of http request headers. * * @description Some headers name cannot be modified programmatically. * @see https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name */ requestHeaders: Headers; /** * Request Headers * * @deprecated use `requestHeaders` instead. */ headers?: RequestHeaders; } /** * Request Headers * * Will filter null value before fetch. */ declare type RequestHeaders = Record; /** * Response Result */ interface ResponseResult { data: T; headers: Headers; status: number; statusText: string; options: RequestOptions; url: string; } /** * Middlewares Response Result */ interface MiddlewareResult extends Omit { data?: any; } declare type PatchContext = Partial; /** * Middleware Next * * Should call by using middleware for get response. */ declare type MiddlewareNext = (patchContext?: PatchContext) => MaybePromise; /** * Middleware */ interface Middleware { name: `fatcher-middleware-${string}`; use(context: Readonly, next: MiddlewareNext): MaybePromise; /** * Current middleware needs some middlewares */ presets?: UnregisteredMiddlewares; } /** * A Middleware or a series of Middlewares * * Will flatten into a array of middlewares. */ declare type UnregisteredMiddlewares = ((() => Middleware) | Middleware | ((() => Middleware) | Middleware)[])[]; /** * Request Options for fetch */ interface RequestOptions extends Omit { /** * Base url to fetch. * * @default '/' */ baseUrl?: string; /** * Url to fetch */ url?: string; /** * HTTP Request Method for current request. * * @default 'GET' */ method?: RequestMethod; /** * Query string for request url */ params?: Record; /** * An array of function with `pre` or `post` request. * * Middlewares will compose into an async function. * * @default [] */ middlewares?: UnregisteredMiddlewares; /** * Request Payload */ payload?: Record | null; /** * Request Headers * * @default * { * 'Content-Type': 'application/x-www-form-urlencoded' * } */ headers?: RequestHeaders; } /** * Read a readable stream by chunk * @param readableStream * @param callback * @returns */ declare function readStreamByChunk(readableStream: ReadableStream, callback: (chunk: T) => MaybePromise): Promise; /** * Read a readable stream by chunk * @param readableStream * @param callback * @returns * * @deprecated Use `readStreamByChunk` instead. */ declare const chunkStreamReader: typeof readStreamByChunk; /** * Fatcher error */ declare class FatcherError extends Error { constructor(context: Context, response: Response); readonly name = "FatcherError"; readonly __isFatcherError__ = true; private readonly _response; private readonly _context; toJSON(): { status: number; statusText: string; context: Context; headers: Record; data: ReadableStream | null; }; } /** * Confirm an error whether is FatcherError * @param error * @returns */ declare function isFatcherError(error: Error): error is FatcherError; declare function mergeOptions(options: RequestOptions, ...patchOptions: Partial[]): RequestOptions; /** * Set Default Fatcher Request Options. * * Tips: * * If change default options, will `effect` any fatcher instances. * * If you want to have a scope options with fatcher. Use `createScopedRequest` instead. * * Inline Options `>` Scoped Options `>` Default Options */ declare function setDefaultOptions(patchRequestOptions: Partial): void; /** * Send HTTP request with custom options. */ declare function fatcher(inlineOptions?: RequestOptions): Promise>; /** * Create a scope fatcher request. * @param scopedOptions * @returns */ declare function createScopedRequest(scopedOptions?: RequestOptions): (url: string, payload?: any, inlineOptions?: RequestOptions) => Promise>; export { Context, FatcherError, MaybePromise, Middleware, MiddlewareNext, MiddlewareResult, PatchContext, RequestHeaders, RequestMethod, RequestOptions, ResponseResult, UnregisteredMiddlewares, canActivate, chunkStreamReader, createScopedRequest, fatcher, isAbortError, isFatcherError, mergeOptions, readStreamByChunk, setDefaultOptions };