{"version":3,"file":"index.cjs","sources":["../src/error.ts","../src/response.ts","../src/utils.ts","../src/index.ts"],"sourcesContent":["import type { FexiosResponse } from './response';\nimport type { FexiosContext } from './types';\n\nexport enum FexiosErrorCodes {\n\tBODY_USED = 'BODY_USED',\n\tNO_BODY_READER = 'NO_BODY_READER',\n\tTIMEOUT = 'TIMEOUT',\n\tNETWORK_ERROR = 'NETWORK_ERROR',\n\tBODY_NOT_ALLOWED = 'BODY_NOT_ALLOWED',\n\tHOOK_CONTEXT_CHANGED = 'HOOK_CONTEXT_CHANGED',\n\tABORTED_BY_HOOK = 'ABORTED_BY_HOOK',\n\tINVALID_HOOK_CALLBACK = 'INVALID_HOOK_CALLBACK',\n\tUNEXPECTED_HOOK_RETURN = 'UNEXPECTED_HOOK_RETURN',\n}\nexport class FexiosError extends Error {\n\tname = 'FexiosError';\n\tconstructor(\n\t\treadonly code: FexiosErrorCodes | string,\n\t\tmessage?: string,\n\t\treadonly context?: FexiosContext,\n\t\toptions?: ErrorOptions,\n\t) {\n\t\tsuper(message, options);\n\t}\n}\nexport class FexiosResponseError<T> extends FexiosError {\n\tname = 'FexiosResponseError';\n\tconstructor(\n\t\tmessage: string,\n\t\treadonly response: FexiosResponse<T>,\n\t\toptions?: ErrorOptions,\n\t) {\n\t\tsuper(response.statusText, message, undefined, options);\n\t}\n}\n/**\n * Check if the error is a FexiosError that not caused by Response error\n */\nexport const isFexiosError = (e: any): boolean => {\n\treturn !(e instanceof FexiosResponseError) && e instanceof FexiosError;\n};\n","export class FexiosResponse<T = any> {\n\tpublic ok: boolean;\n\tpublic status: number;\n\tpublic statusText: string;\n\tpublic headers: Headers;\n\tconstructor(\n\t\tpublic rawResponse: Response,\n\t\tpublic data: T,\n\t\toverrides?: Partial<Omit<FexiosResponse<T>, 'rawResponse' | 'data'>>,\n\t) {\n\t\tthis.ok = rawResponse.ok;\n\t\tthis.status = rawResponse.status;\n\t\tthis.statusText = rawResponse.statusText;\n\t\tthis.headers = rawResponse.headers;\n\t\tfor (const [key, value] of Object.entries(overrides || {})) {\n\t\t\t(this as any)[key] = value;\n\t\t}\n\t}\n}\n","import type { FexiosResponse } from '.';\nimport { FexiosResponseError } from './error';\n\nconst withResolvers =\n\ttypeof Promise.withResolvers === 'undefined'\n\t\t? function withResolvers<T>() {\n\t\t\t\t/* v8 ignore next 10 */\n\t\t\t\t// withResolvers polyfill\n\t\t\t\tlet resolve: (value: T) => void;\n\t\t\t\tlet reject: (reason?: unknown) => void;\n\t\t\t\tconst promise = new Promise<T>((res, rej) => {\n\t\t\t\t\tresolve = res;\n\t\t\t\t\treject = rej;\n\t\t\t\t});\n\t\t\t\treturn { promise, resolve: resolve!, reject: reject! };\n\t\t\t}\n\t\t: <T>() => Promise.withResolvers<T>();\n\nexport function checkThrow<T>(res: FexiosResponse<T>) {\n\tif (!res.ok)\n\t\tthrow new FexiosResponseError(\n\t\t\t`Request failed with status code ${res.status}`,\n\t\t\tres as any,\n\t\t);\n\treturn res;\n}\n\nexport function concat(buffers: Uint8Array[]): Uint8Array {\n\tlet length = 0;\n\tfor (const buffer of buffers) {\n\t\tlength += buffer.length;\n\t}\n\tconst output = new Uint8Array(length);\n\tlet offset = 0;\n\tfor (const buffer of buffers) {\n\t\toutput.set(buffer, offset);\n\t\toffset += buffer.length;\n\t}\n\n\treturn output;\n}\n\nexport async function readToUint8ArrayUnsized(\n\tstream: ReadableStream<Uint8Array>,\n\tprogressHook?: (progress: number, chunk?: Uint8Array) => void,\n): Promise<Uint8Array> {\n\tlet progress = 0;\n\tconst buffers: Uint8Array[] = [];\n\tfor await (const chunk of stream) {\n\t\tbuffers.push(chunk);\n\t\tprogress += chunk.length;\n\t\tprogressHook?.(chunk.length, chunk);\n\t}\n\n\treturn concat(buffers);\n}\n\nexport async function readToUint8Array(\n\tstream: ReadableStream<Uint8Array>,\n\tsize?: number,\n\tprogressHook?: (\n\t\tprogress: number,\n\t\tchunk?: Uint8Array,\n\t\tbuffer?: Uint8Array,\n\t) => void,\n): Promise<Uint8Array> {\n\tif (!size) return readToUint8ArrayUnsized(stream, progressHook);\n\tconst buffer = new Uint8Array(size || 0);\n\tlet offset = 0;\n\n\tlet overflower:\n\t\t| Promise<[Promise<Uint8Array>, ReadableStreamDefaultController]>\n\t\t| undefined;\n\tfor await (const chunk of stream) {\n\t\tif (overflower) {\n\t\t\tconst [_, controller] = await overflower;\n\t\t\tcontroller.enqueue(chunk);\n\t\t\toffset += chunk.length;\n\t\t\tprogressHook?.(offset, chunk);\n\t\t\tcontinue;\n\t\t}\n\t\tif (offset + chunk.length > buffer.length) {\n\t\t\t// overflow fallback\n\t\t\tconsole.warn(\n\t\t\t\t`readToUint8Array overflowed (${buffer.length}++${offset + chunk.length - buffer.length}), fallback to concat`,\n\t\t\t);\n\t\t\tconst { promise, resolve } =\n\t\t\t\twithResolvers<[Promise<Uint8Array>, ReadableStreamDefaultController]>();\n\t\t\toverflower = promise;\n\t\t\tconst {\n\t\t\t\tpromise: bufferPromise,\n\t\t\t\tresolve: bufferResolve,\n\t\t\t\treject: bufferReject,\n\t\t\t} = withResolvers<Uint8Array>();\n\t\t\treadToUint8ArrayUnsized(\n\t\t\t\tnew ReadableStream({\n\t\t\t\t\tstart(controller) {\n\t\t\t\t\t\tcontroller.enqueue(buffer.subarray(0, offset));\n\t\t\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t\t\t\toffset += chunk.length;\n\t\t\t\t\t\tresolve([bufferPromise, controller]);\n\t\t\t\t\t},\n\t\t\t\t}),\n\t\t\t)\n\t\t\t\t.then(bufferResolve)\n\t\t\t\t.catch(bufferReject);\n\t\t\tcontinue;\n\t\t}\n\t\tbuffer.set(chunk, offset);\n\t\tprogressHook?.(offset, chunk, buffer);\n\t\toffset += chunk.length;\n\t}\n\tif (overflower) {\n\t\tconst [bufferPromise, controller] = await overflower;\n\t\tcontroller.close();\n\t\tconst buffer = await bufferPromise;\n\t\tprogressHook?.(offset, void 0, buffer);\n\t\treturn buffer;\n\t}\n\n\treturn buffer;\n}\n\nconst textTypes = new Set([\n\t'image/svg',\n\t'application/xml',\n\t'application/xhtml',\n\t'application/html',\n]);\n\nconst JSON_RE = /^application\\/(?:[\\w!#$%&*.^`~-]*\\+)?json(;.+)?$/i;\n\n// https://github.com/unjs/ofetch/blob/c817be86e8758ed7e6a05d2589f4b318f1f0b38e/src/utils.ts#L50\n// This provides reasonable defaults for the correct parser based on Content-Type header.\nexport function detectResponseType(\n\t_contentType = '',\n): 'json' | 'text' | 'blob' | 'stream' {\n\tif (!_contentType) {\n\t\treturn 'json';\n\t}\n\n\t// Value might look like: `application/json; charset=utf-8`\n\tconst contentType = _contentType.split(';').shift() || '';\n\n\tif (JSON_RE.test(contentType)) {\n\t\treturn 'json';\n\t}\n\n\tif (contentType === 'application/octet-stream') {\n\t\treturn 'stream';\n\t}\n\n\tif (textTypes.has(contentType) || contentType.startsWith('text/')) {\n\t\treturn 'text';\n\t}\n\n\treturn 'blob';\n}\n","import CallableInstance from 'callable-instance';\nimport { type Awaitable, Time } from 'cosmokit';\nimport { safeDestr } from 'destr';\nimport { type FetchResponse, type MappedResponseType, ofetch } from 'ofetch';\nimport { TransformStream } from '#ofexios/stream-polyfill';\nimport { FexiosError, FexiosErrorCodes, FexiosResponseError } from './error';\nimport { FexiosResponse } from './response';\nimport type {\n\tFexiosConfigs,\n\tFexiosContext,\n\tFexiosFinalContext,\n\tFexiosHook,\n\tFexiosHookStore,\n\tFexiosInterceptor,\n\tFexiosInterceptors,\n\tFexiosLifecycleEvents,\n\tFexiosMethods,\n\tFexiosRequestOptions,\n\tFexiosRequestShortcut,\n} from './types';\nimport { checkThrow, detectResponseType, readToUint8Array } from './utils';\n\nexport { fetch } from 'ofetch';\n\nexport * from './response';\nexport * from './types';\nexport * from './error';\n\n/**\n * Fexios\n * @desc Fetch based HTTP client with similar API to axios for browser and Node.js\n *\n * @license MIT\n * @author dragon-fish <dragon-fish@qq.com>\n */\n\nexport class Fexios extends CallableInstance<\n\t[\n\t\tstring | URL | Partial<FexiosRequestOptions>,\n\t\tPartial<FexiosRequestOptions>?,\n\t],\n\tPromise<FexiosFinalContext>\n> {\n\tprotected hooks: FexiosHookStore[] = [];\n\treadonly DEFAULT_CONFIGS: FexiosConfigs = {\n\t\tbaseURL: '',\n\t\ttimeout: Time.minute,\n\t\tcredentials: 'same-origin',\n\t\theaders: {},\n\t\tquery: {},\n\t\tresponseType: undefined,\n\t};\n\tprivate readonly ALL_METHODS: FexiosMethods[] = [\n\t\t'get',\n\t\t'post',\n\t\t'put',\n\t\t'patch',\n\t\t'delete',\n\t\t'head',\n\t\t'options',\n\t\t'trace',\n\t];\n\tprivate readonly METHODS_WITHOUT_BODY: FexiosMethods[] = [\n\t\t'get',\n\t\t'head',\n\t\t'options',\n\t\t'trace',\n\t];\n\tprivate static readonly BLOB_MIME_TYPE: string[] = [\n\t\t'image/',\n\t\t'video/',\n\t\t'audio/',\n\t];\n\n\tconstructor(public baseConfigs: Partial<FexiosConfigs> = {}) {\n\t\tsuper('request');\n\t\tthis.ALL_METHODS.forEach(this.createMethodShortcut.bind(this));\n\t}\n\n\tasync request<T = any>(\n\t\turl: string | URL,\n\t\toptions?: Partial<FexiosRequestOptions>,\n\t): Promise<FexiosFinalContext<T>>;\n\tasync request<T = any>(\n\t\toptions: Partial<FexiosRequestOptions> & { url: string | URL },\n\t): Promise<FexiosFinalContext<T>>;\n\tasync request<T = any>(\n\t\turlOrOptions:\n\t\t\t| string\n\t\t\t| URL\n\t\t\t| (Partial<FexiosRequestOptions> & { url: string | URL }),\n\t\toptions?: Partial<FexiosRequestOptions>,\n\t): Promise<FexiosFinalContext<T>> {\n\t\tlet ctx: FexiosContext = (options = options || {}) as any;\n\t\tif (typeof urlOrOptions === 'string' || urlOrOptions instanceof URL) {\n\t\t\tctx.url = urlOrOptions.toString();\n\t\t} else if (typeof urlOrOptions === 'object') {\n\t\t\tctx = { ...urlOrOptions, ...ctx };\n\t\t}\n\t\tctx = await this.emit('beforeInit', ctx);\n\n\t\tconst baseUrlString =\n\t\t\toptions.baseURL || this.baseConfigs.baseURL || globalThis.location?.href;\n\t\tconst baseURL = baseUrlString\n\t\t\t? new URL(baseUrlString, globalThis.location?.href)\n\t\t\t: undefined;\n\t\tconst reqURL = new URL(ctx.url.toString(), baseURL);\n\t\tctx.url = reqURL.href;\n\t\tctx.baseURL = baseURL ? baseURL.href : reqURL.origin;\n\n\t\tctx.headers = this.mergeHeaders(\n\t\t\tthis.baseConfigs.headers,\n\t\t\toptions.headers,\n\t\t) as any;\n\t\tctx.query = this.mergeQuery(\n\t\t\tthis.baseConfigs.query,\n\t\t\treqURL.searchParams,\n\t\t\toptions.query,\n\t\t);\n\n\t\treqURL.search = new URLSearchParams(ctx.query as any).toString();\n\t\tctx.url = reqURL.toString();\n\n\t\tif (\n\t\t\tthis.METHODS_WITHOUT_BODY.includes(\n\t\t\t\tctx.method?.toLocaleLowerCase() as FexiosMethods,\n\t\t\t) &&\n\t\t\tctx.body\n\t\t) {\n\t\t\tthrow new FexiosError(\n\t\t\t\tFexiosErrorCodes.BODY_NOT_ALLOWED,\n\t\t\t\t`Request method \"${ctx.method}\" does not allow body`,\n\t\t\t);\n\t\t}\n\n\t\tctx = await this.emit('beforeRequest', ctx);\n\n\t\tlet body: string | FormData | URLSearchParams | Blob | undefined;\n\t\tif (typeof ctx.body !== 'undefined' && ctx.body !== null) {\n\t\t\t// Automatically transform JSON object to JSON string\n\t\t\tif (\n\t\t\t\tctx.body instanceof Blob ||\n\t\t\t\tctx.body instanceof FormData ||\n\t\t\t\tctx.body instanceof URLSearchParams\n\t\t\t) {\n\t\t\t\tbody = ctx.body;\n\t\t\t} else if (typeof ctx.body === 'object') {\n\t\t\t\tbody = JSON.stringify(ctx.body);\n\t\t\t\t(ctx.headers as any)['content-type'] =\n\t\t\t\t\t'application/json; charset=UTF-8';\n\t\t\t} else {\n\t\t\t\tbody = ctx.body;\n\t\t\t}\n\t\t}\n\n\t\t// Adjust content-type header\n\t\tif (!(options.headers as any)?.['content-type'] && body) {\n\t\t\t// If body is FormData or URLSearchParams, simply delete content-type header to let Request constructor handle it\n\t\t\tif (!(body instanceof FormData || body instanceof URLSearchParams)) {\n\t\t\t\tdelete (ctx.headers as any)['content-type'];\n\t\t\t}\n\t\t\t// If body is a string and ctx.body is an object, it means ctx.body is a JSON string\n\t\t\telse if (typeof body === 'string' && typeof ctx.body === 'object') {\n\t\t\t\t/* v8 ignore next 3 */\n\t\t\t\t(ctx.headers as any)['content-type'] =\n\t\t\t\t\t'application/json; charset=UTF-8';\n\t\t\t}\n\t\t\t// If body is a Blob, set content-type header to the Blob's type\n\t\t\telse if (body instanceof Blob) {\n\t\t\t\t(ctx.headers as any)['content-type'] = body.type;\n\t\t\t}\n\t\t}\n\n\t\tctx.body = body;\n\t\tctx = await this.emit('afterBodyTransformed', ctx);\n\n\t\tconst abortController =\n\t\t\tctx.abortController || globalThis.AbortController\n\t\t\t\t? new AbortController()\n\t\t\t\t: /* v8 ignore next */ undefined;\n\t\tconst rawRequest = new Request(ctx.url, {\n\t\t\tmethod: ctx.method || 'GET',\n\t\t\tcredentials: ctx.credentials,\n\t\t\tcache: ctx.cache,\n\t\t\tmode: ctx.mode,\n\t\t\theaders: ctx.headers,\n\t\t\tbody: ctx.body as any,\n\t\t\tsignal: abortController?.signal,\n\t\t});\n\t\tctx.rawRequest = rawRequest;\n\n\t\tctx = await this.emit('beforeActualFetch', ctx);\n\n\t\tif (ctx.url.startsWith('ws')) {\n\t\t\tconsole.info('WebSocket:', ctx.url);\n\t\t\tconst ws = new WebSocket(ctx.url);\n\t\t\tctx.rawResponse = new Response();\n\t\t\tctx.response = new FexiosResponse(ctx.rawResponse, ws as any, {\n\t\t\t\tok: true,\n\t\t\t\tstatus: 101,\n\t\t\t\tstatusText: 'Switching Protocols',\n\t\t\t});\n\t\t\tctx.data = ws;\n\t\t\tctx.headers = new Headers();\n\t\t\treturn this.emit('afterResponse', ctx) as any;\n\t\t}\n\n\t\tconst timeout = ctx.timeout || this.baseConfigs.timeout || Time.minute;\n\t\tconst timer = setTimeout(() => {\n\t\t\tabortController?.abort();\n\t\t\tif (!abortController) {\n\t\t\t\tthrow new FexiosError(\n\t\t\t\t\tFexiosErrorCodes.TIMEOUT,\n\t\t\t\t\t`Request timed out after ${timeout}ms`,\n\t\t\t\t\tctx,\n\t\t\t\t);\n\t\t\t}\n\t\t}, timeout);\n\t\tconst rawResponse = await fetch(ctx.rawRequest!).catch((err: any) =>\n\t\t\tPromise.reject(\n\t\t\t\tnew FexiosError(FexiosErrorCodes.NETWORK_ERROR, err.error.message, ctx),\n\t\t\t),\n\t\t);\n\n\t\tctx.rawResponse = rawResponse;\n\t\tctx.response = await Fexios.resolveResponseBody(\n\t\t\trawResponse,\n\t\t\tctx.responseType,\n\t\t\t(progress, buffer) => {\n\t\t\t\tconsole.info('Download progress:', progress);\n\t\t\t\toptions?.onProgress?.(progress, buffer);\n\t\t\t},\n\t\t).finally(() => {\n\t\t\tclearTimeout(timer);\n\t\t});\n\t\tctx.data = ctx.response.data;\n\t\tctx.headers = ctx.response.headers;\n\n\t\treturn this.emit('afterResponse', ctx) as any;\n\t}\n\n\tmergeQuery(\n\t\tbase: Record<string, any> | string | URLSearchParams | undefined,\n\t\t...income: (Record<string, any> | string | URLSearchParams | undefined)[]\n\t): Record<string, any> {\n\t\tconst baseQuery = new URLSearchParams(base);\n\t\tfor (const incomeQuery of income) {\n\t\t\tconst params = new URLSearchParams(incomeQuery);\n\t\t\tparams.forEach((value, key) => {\n\t\t\t\tbaseQuery.set(key, value);\n\t\t\t});\n\t\t}\n\t\treturn Object.fromEntries(baseQuery.entries());\n\t}\n\tmergeHeaders(\n\t\tbase: Record<string, any> | Headers | undefined,\n\t\t...income: (Record<string, any> | Headers | undefined)[]\n\t): Record<string, any> {\n\t\tconst headersObject: any = {};\n\t\tconst baseHeaders = new Headers(base);\n\t\tfor (const incomeHeaders of income) {\n\t\t\tconst header = new Headers(incomeHeaders);\n\t\t\theader.forEach((value, key) => {\n\t\t\t\tbaseHeaders.set(key, value);\n\t\t\t});\n\t\t}\n\t\tbaseHeaders.forEach((value, key) => {\n\t\t\theadersObject[key] = value;\n\t\t});\n\t\treturn headersObject;\n\t}\n\n\tasync emit<C = FexiosContext>(event: FexiosLifecycleEvents, ctx: C) {\n\t\tconst hooks = this.hooks.filter((hook) => hook.event === event);\n\t\ttry {\n\t\t\tlet index = 0;\n\t\t\tfor (const hook of hooks) {\n\t\t\t\tconst hookName = `${event}#${hook.action.name || `anonymous#${index}`}`;\n\n\t\t\t\t// Set a symbol to check if the hook overrides the original context\n\t\t\t\tconst symbol = Symbol('FexiosHookContext');\n\t\t\t\t(ctx as any)[symbol] = symbol;\n\n\t\t\t\tconst newCtx = (await hook.action.call(this, ctx)) as Awaited<\n\t\t\t\t\tC | false\n\t\t\t\t>;\n\n\t\t\t\t// Excepted abort signal\n\t\t\t\tif (newCtx === false) {\n\t\t\t\t\tthrow new FexiosError(\n\t\t\t\t\t\tFexiosErrorCodes.ABORTED_BY_HOOK,\n\t\t\t\t\t\t`Request aborted by hook \"${hookName}\"`,\n\t\t\t\t\t\tctx as FexiosContext,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\t// Good\n\t\t\t\tif (typeof newCtx === 'object' && (newCtx as any)[symbol] === symbol) {\n\t\t\t\t\tctx = newCtx as C;\n\t\t\t\t}\n\t\t\t\t// Unexpected return value\n\t\t\t\telse {\n\t\t\t\t\t// @ts-ignore prevent esbuild optimize\n\t\t\t\t\tconst console = globalThis[''.concat('console')];\n\t\t\t\t\ttry {\n\t\t\t\t\t\tthrow new FexiosError(\n\t\t\t\t\t\t\tFexiosErrorCodes.HOOK_CONTEXT_CHANGED,\n\t\t\t\t\t\t\t`Hook \"${hookName}\" should return the original FexiosContext or return false to abort the request, but got \"${newCtx}\".`,\n\t\t\t\t\t\t);\n\t\t\t\t\t} catch (e: any) {\n\t\t\t\t\t\tconsole.warn(e.stack || e);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// Clean up\n\t\t\t\tdelete (ctx as any)[symbol];\n\n\t\t\t\tindex++;\n\t\t\t}\n\t\t} catch (e) {\n\t\t\treturn Promise.reject(e);\n\t\t}\n\t\treturn ctx;\n\t}\n\ton<C = FexiosContext>(\n\t\tevent: FexiosLifecycleEvents,\n\t\taction: FexiosHook<C>,\n\t\tprepend = false,\n\t) {\n\t\tif (typeof action !== 'function') {\n\t\t\tthrow new FexiosError(\n\t\t\t\tFexiosErrorCodes.INVALID_HOOK_CALLBACK,\n\t\t\t\t`Hook should be a function, but got \"${typeof action}\"`,\n\t\t\t);\n\t\t}\n\t\tthis.hooks[prepend ? 'unshift' : 'push']({\n\t\t\tevent,\n\t\t\taction: action as FexiosHook,\n\t\t});\n\t\treturn this;\n\t}\n\toff(event: FexiosLifecycleEvents, action: FexiosHook<any>) {\n\t\tthis.hooks = this.hooks.filter(\n\t\t\t(hook) => hook.event !== event || hook.action !== action,\n\t\t);\n\t\treturn this;\n\t}\n\n\tprivate createInterceptor<T extends FexiosLifecycleEvents>(\n\t\tevent: T,\n\t): FexiosInterceptor {\n\t\treturn {\n\t\t\thandlers: () =>\n\t\t\t\tthis.hooks\n\t\t\t\t\t.filter((hook) => hook.event === event)\n\t\t\t\t\t.map((hook) => hook.action),\n\t\t\tuse: <C = FexiosContext>(hook: FexiosHook<C>, prepend = false) => {\n\t\t\t\treturn this.on(event, hook, prepend);\n\t\t\t},\n\t\t\tclear: () => {\n\t\t\t\tthis.hooks = this.hooks.filter((hook) => hook.event !== event);\n\t\t\t},\n\t\t};\n\t}\n\treadonly interceptors: FexiosInterceptors = {\n\t\trequest: this.createInterceptor('beforeRequest'),\n\t\tresponse: this.createInterceptor('afterResponse'),\n\t};\n\n\tprivate createMethodShortcut(method: FexiosMethods) {\n\t\tObject.defineProperty(this, method, {\n\t\t\tvalue: (\n\t\t\t\turl: string | URL,\n\t\t\t\tbodyOrQuery?: Record<string, any> | string | URLSearchParams,\n\t\t\t\toptions?: Partial<FexiosRequestOptions>,\n\t\t\t) => {\n\t\t\t\tif (\n\t\t\t\t\tthis.METHODS_WITHOUT_BODY.includes(\n\t\t\t\t\t\tmethod.toLocaleLowerCase() as FexiosMethods,\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\toptions = bodyOrQuery as any;\n\t\t\t\t} else {\n\t\t\t\t\toptions = options || {};\n\t\t\t\t\toptions.body = bodyOrQuery;\n\t\t\t\t}\n\t\t\t\treturn this.request(url, {\n\t\t\t\t\t...options,\n\t\t\t\t\tmethod: method as FexiosMethods,\n\t\t\t\t});\n\t\t\t},\n\t\t});\n\t\treturn this;\n\t}\n\n\tstatic async resolveResponseBody<T = any>(\n\t\trawResponse: Response,\n\t\texpectType?: FexiosConfigs['responseType'],\n\t\tonProgress?: (\n\t\t\tprogress: number,\n\t\t\tchunk?: Uint8Array,\n\t\t\tbuffer?: Uint8Array,\n\t\t) => void,\n\t): Promise<FexiosResponse<T>> {\n\t\tif (rawResponse.bodyUsed) {\n\t\t\tthrow new FexiosError(\n\t\t\t\t'BODY_USED',\n\t\t\t\t'Response body has already been used or locked',\n\t\t\t);\n\t\t}\n\n\t\tconst contentType = rawResponse.headers.get('content-type') || '';\n\t\tconst contentLength =\n\t\t\tNumber(rawResponse.headers.get('content-length')) || 0;\n\n\t\t// Check if the response is a WebSocket\n\t\tif (\n\t\t\t(rawResponse.status === 101 ||\n\t\t\t\trawResponse.status === 426 ||\n\t\t\t\trawResponse.headers.get('upgrade')) &&\n\t\t\ttypeof globalThis.WebSocket !== 'undefined'\n\t\t) {\n\t\t\tconst ws = new WebSocket(rawResponse.url);\n\t\t\tawait new Promise((resolve, reject) => {\n\t\t\t\tws.onopen = resolve;\n\t\t\t\tws.onerror = reject;\n\t\t\t});\n\t\t\treturn new FexiosResponse(rawResponse, ws as T, {\n\t\t\t\tok: true,\n\t\t\t\tstatus: 101,\n\t\t\t\tstatusText: 'Switching Protocols',\n\t\t\t});\n\t\t}\n\t\t// Check if the response is a EventSource\n\t\t// But only if the content-type is not 'text' or 'json'\n\t\tif (\n\t\t\tcontentType.startsWith('text/event-stream') &&\n\t\t\t!['text', 'json'].includes(expectType || '') &&\n\t\t\ttypeof globalThis.EventSource !== 'undefined'\n\t\t) {\n\t\t\tconst es = new EventSource(rawResponse.url);\n\t\t\tawait new Promise<any>((resolve, reject) => {\n\t\t\t\tes.onopen = resolve;\n\t\t\t\tes.onerror = reject;\n\t\t\t});\n\t\t\treturn new FexiosResponse(rawResponse, es as T);\n\t\t}\n\t\t// Check if expectType is 'stream'\n\t\tif (expectType === 'stream') {\n\t\t\treturn new FexiosResponse(\n\t\t\t\trawResponse,\n\t\t\t\tsafeDestr<T>(await rawResponse.text()),\n\t\t\t);\n\t\t}\n\n\t\tconst preferType =\n\t\t\texpectType ||\n\t\t\tdetectResponseType(rawResponse.headers.get('content-type') || '');\n\n\t\tif (!expectType && preferType === 'stream') {\n\t\t\tlet count = 0;\n\t\t\tconst transformer = new TransformStream({\n\t\t\t\ttransform(chunk, controller) {\n\t\t\t\t\tcontroller.enqueue(chunk);\n\t\t\t\t\tcount += chunk.length;\n\t\t\t\t\tonProgress?.(count, chunk);\n\t\t\t\t},\n\t\t\t\tflush(controller) {\n\t\t\t\t\tcontroller.terminate();\n\t\t\t\t},\n\t\t\t});\n\t\t\treturn new FexiosResponse(\n\t\t\t\trawResponse,\n\t\t\t\trawResponse.body?.pipeThrough(transformer) as ReadableStream as T,\n\t\t\t);\n\t\t}\n\n\t\tif (\n\t\t\texpectType === 'blob' ||\n\t\t\tcontentType.startsWith('image/') ||\n\t\t\tcontentType.startsWith('video/') ||\n\t\t\tcontentType.startsWith('audio/')\n\t\t) {\n\t\t\treturn new FexiosResponse(rawResponse, <any>await rawResponse.blob());\n\t\t}\n\n\t\t// Check if the response is a ReadableStream\n\t\tconst stream = rawResponse.body;\n\t\tif (!stream) {\n\t\t\tthrow new FexiosError(\n\t\t\t\tFexiosErrorCodes.NO_BODY_READER,\n\t\t\t\t'Failed to get ReadableStream from response body',\n\t\t\t);\n\t\t}\n\t\tconst buffer = await readToUint8Array(\n\t\t\tstream, // allowing preallocating buffer\n\t\t\t+(rawResponse.headers.get('content-length') || 0),\n\t\t\tonProgress,\n\t\t);\n\n\t\tconst res = new FexiosResponse(rawResponse, undefined as any);\n\n\t\t// Guess the response type, maybe a Blob?\n\t\tif (!this.isText(buffer)) {\n\t\t\tres.data = new Blob([buffer], {\n\t\t\t\ttype: rawResponse.headers.get('content-type') || undefined,\n\t\t\t}) as Blob as T;\n\t\t}\n\t\t// Otherwise, try to decode the buffer as text\n\t\telse {\n\t\t\tres.data = new TextDecoder().decode(buffer) as T;\n\t\t}\n\n\t\t// If the data resolved as a string above, try to parse it as JSON\n\t\tif (\n\t\t\ttypeof res.data === 'string' &&\n\t\t\texpectType !== 'text' &&\n\t\t\t(expectType === 'json' || contentType.startsWith('application/json'))\n\t\t) {\n\t\t\ttry {\n\t\t\t\tres.data = safeDestr<T>(res.data);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.warn('Failed to parse response data as JSON:', e);\n\t\t\t}\n\t\t}\n\n\t\t// Fall back to the buffer if the data is still not resolved\n\t\tif (typeof res.data === 'undefined') {\n\t\t\tres.data = buffer.length > 0 ? (buffer as any) : undefined;\n\t\t}\n\n\t\treturn checkThrow(res);\n\t}\n\n\tstatic isText(uint8Array: Uint8Array, maxBytesToCheck = 1024) {\n\t\t// 确保输入是一个 Uint8Array\n\t\tif (!(uint8Array instanceof Uint8Array)) {\n\t\t\tthrow new TypeError('Input must be a Uint8Array');\n\t\t}\n\n\t\t// 截取前 maxBytesToCheck 字节进行检查\n\t\tconst dataToCheck = uint8Array.slice(0, maxBytesToCheck);\n\n\t\t// 使用 TextDecoder 尝试解码为 UTF-8 字符串\n\t\tconst decoder = new TextDecoder('utf-8', { fatal: true });\n\t\ttry {\n\t\t\tconst decodedString = decoder.decode(dataToCheck);\n\n\t\t\t// 检查解码后的字符串是否包含大量不可打印字符\n\t\t\tconst nonPrintableRegex = /[\\x00-\\x08\\x0E-\\x1F\\x7F]/g; // 匹配控制字符\n\t\t\tconst nonPrintableMatches = decodedString.match(nonPrintableRegex);\n\n\t\t\t// 如果不可打印字符占比过高，则认为是二进制数据\n\t\t\tconst threshold = 0.1; // 允许最多 10% 的不可打印字符\n\t\t\tif (\n\t\t\t\tnonPrintableMatches &&\n\t\t\t\tnonPrintableMatches.length / decodedString.length > threshold\n\t\t\t) {\n\t\t\t\treturn false; // 是二进制数据\n\t\t\t}\n\n\t\t\t// 否则认为是文本数据\n\t\t\treturn true;\n\t\t} catch (error) {\n\t\t\t// 如果解码失败（例如包含无效的 UTF-8 序列），认为是二进制数据\n\t\t\treturn false;\n\t\t}\n\t}\n\n\textends(configs: Partial<FexiosConfigs>) {\n\t\tconst fexios = new Fexios({ ...this.baseConfigs, ...configs });\n\t\tfexios.hooks = [...this.hooks];\n\t\treturn fexios;\n\t}\n\n\treadonly create = Fexios.create;\n\tstatic create(configs?: Partial<FexiosConfigs>) {\n\t\treturn new Fexios(configs);\n\t}\n}\n\n// declare method shortcuts\nexport interface Fexios {\n\tget: FexiosRequestShortcut<'get'>;\n\tpost: FexiosRequestShortcut<'post'>;\n\tput: FexiosRequestShortcut<'put'>;\n\tpatch: FexiosRequestShortcut<'patch'>;\n\tdelete: FexiosRequestShortcut<'delete'>;\n\thead: FexiosRequestShortcut<'head'>;\n\toptions: FexiosRequestShortcut<'options'>;\n\ttrace: FexiosRequestShortcut<'trace'>;\n}\n\n// Support for direct import\nexport const createFexios = Fexios.create;\nexport const fexios = createFexios();\nexport default fexios;\n"],"names":["FexiosErrorCodes","BODY_USED","NO_BODY_READER","TIMEOUT","NETWORK_ERROR","BODY_NOT_ALLOWED","HOOK_CONTEXT_CHANGED","ABORTED_BY_HOOK","INVALID_HOOK_CALLBACK","UNEXPECTED_HOOK_RETURN","FexiosError","Error","constructor","code","message","context","options","name","FexiosResponseError","response","statusText","isFexiosError","e","FexiosResponse","rawResponse","data","overrides","ok","status","headers","key","value","Object","entries","withResolvers","Promise","resolve","reject","promise","res","rej","checkThrow","concat","buffers","length","buffer","output","Uint8Array","offset","set","readToUint8ArrayUnsized","stream","progressHook","progress","chunk","push","readToUint8Array","size","overflower","_","controller","enqueue","console","warn","bufferPromise","bufferResolve","bufferReject","ReadableStream","start","subarray","then","catch","close","textTypes","Set","JSON_RE","detectResponseType","_contentType","contentType","split","shift","test","has","startsWith","Fexios","CallableInstance","request","urlOrOptions","ctx","URL","url","toString","emit","baseUrlString","baseURL","baseConfigs","globalThis","location","href","reqURL","origin","mergeHeaders","query","mergeQuery","searchParams","search","URLSearchParams","METHODS_WITHOUT_BODY","includes","method","toLocaleLowerCase","body","Blob","FormData","JSON","stringify","type","abortController","AbortController","rawRequest","Request","credentials","cache","mode","signal","info","ws","WebSocket","Response","Headers","timeout","Time","minute","timer","setTimeout","abort","fetch","err","error","resolveResponseBody","responseType","onProgress","finally","clearTimeout","base","income","baseQuery","incomeQuery","forEach","fromEntries","headersObject","baseHeaders","incomeHeaders","event","hooks","filter","hook","index","hookName","action","symbol","Symbol","newCtx","call","stack","on","prepend","off","createInterceptor","handlers","map","use","clear","createMethodShortcut","defineProperty","bodyOrQuery","expectType","bodyUsed","get","Number","onopen","onerror","EventSource","es","safeDestr","text","preferType","count","transformer","TransformStream","transform","flush","terminate","pipeThrough","blob","isText","TextDecoder","decode","uint8Array","maxBytesToCheck","TypeError","dataToCheck","slice","decoder","fatal","decodedString","nonPrintableRegex","nonPrintableMatches","match","extends","configs","fexios","create","DEFAULT_CONFIGS","ALL_METHODS","interceptors","bind","BLOB_MIME_TYPE","createFexios"],"mappings":"guBAGO,IAAKA,kBAAAA,IACXA,EAAAC,UAAY,YACZD,EAAAE,eAAiB,iBACjBF,EAAAG,QAAU,UACVH,EAAAI,cAAgB,gBAChBJ,EAAAK,iBAAmB,mBACnBL,EAAAM,qBAAuB,uBACvBN,EAAAO,gBAAkB,kBAClBP,EAAAQ,sBAAwB,wBACxBR,EAAAS,uBAAyB,yBATdT,IAAAA,kBAA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