{"version":3,"file":"wretch.all.min.js","sources":["../../src/constants.ts","../../src/utils.ts","../../src/config.ts","../../src/resolver.ts","../../src/middleware.ts","../../src/core.ts","../../src/addons/abort.ts","../../src/addons/formData.ts","../../src/addons/formUrl.ts","../../src/addons/perfs.ts","../../src/addons/queryString.ts","../../src/addons/progress.ts","../../src/index.all.ts"],"sourcesContent":["export const JSON_MIME = \"application/json\"\nexport const CONTENT_TYPE_HEADER = \"Content-Type\"\nexport const FETCH_ERROR = Symbol()\nexport const CATCHER_FALLBACK = Symbol()\n","import { CONTENT_TYPE_HEADER } from \"./constants.js\"\n\nexport function extractContentType(headers: Record = {}): string | undefined {\n return Object.entries(headers).find(([k]) =>\n k.toLowerCase() === CONTENT_TYPE_HEADER.toLowerCase()\n )?.[1]\n}\n\nexport function isLikelyJsonMime(value: string): boolean {\n return /^application\\/.*json.*/.test(value)\n}\n\nexport const mix = function (one: object, two: object, mergeArrays: boolean = false) {\n return Object.entries(two).reduce((acc, [key, newValue]) => {\n const value = one[key]\n if (Array.isArray(value) && Array.isArray(newValue)) {\n acc[key] = mergeArrays ? [...value, ...newValue] : newValue\n } else if (typeof value === \"object\" && typeof newValue === \"object\") {\n acc[key] = mix(value, newValue, mergeArrays)\n } else {\n acc[key] = newValue\n }\n\n return acc\n }, { ...one })\n}\n","import { mix } from \"./utils.js\"\nimport type { Config } from \"./types.js\"\n\ndeclare const global\n\nconst config: Config = {\n // Default options\n options: {},\n // Error type\n errorType: \"text\",\n // Polyfills\n polyfills: {\n // fetch: null,\n // FormData: null,\n // URLSearchParams: null,\n // performance: null,\n // PerformanceObserver: null,\n // AbortController: null\n },\n polyfill(p: string, doThrow: boolean = true, instance: boolean = false, ...args: any[]) {\n const res = this.polyfills[p] ||\n (typeof self !== \"undefined\" ? self[p] : null) ||\n (typeof global !== \"undefined\" ? global[p] : null)\n if (doThrow && !res) throw new Error(p + \" is not defined\")\n return instance && res ? new res(...args) : res\n }\n}\n\n/**\n * Sets the default fetch options that will be stored internally when instantiating wretch objects.\n *\n * ```js\n * import wretch from \"wretch\"\n *\n * wretch.options({ headers: { \"Accept\": \"application/json\" } });\n *\n * // The fetch request is sent with both headers.\n * wretch(\"...\", { headers: { \"X-Custom\": \"Header\" } }).get().res();\n * ```\n *\n * @param options Default options\n * @param replace If true, completely replaces the existing options instead of mixing in\n */\nexport function setOptions(options: object, replace = false) {\n config.options = replace ? options : mix(config.options, options)\n}\n\n/**\n * Sets the default polyfills that will be stored internally when instantiating wretch objects.\n * Useful for browserless environments like `node.js`.\n *\n * Needed for libraries like [fetch-ponyfill](https://github.com/qubyte/fetch-ponyfill).\n *\n * ```js\n * import wretch from \"wretch\"\n *\n * wretch.polyfills({\n * fetch: require(\"node-fetch\"),\n * FormData: require(\"form-data\"),\n * URLSearchParams: require(\"url\").URLSearchParams,\n * });\n *\n * // Uses the above polyfills.\n * wretch(\"...\").get().res();\n * ```\n *\n * @param polyfills An object containing the polyfills\n * @param replace If true, replaces the current polyfills instead of mixing in\n */\nexport function setPolyfills(polyfills: object, replace = false) {\n config.polyfills = replace ? polyfills : mix(config.polyfills, polyfills)\n}\n\n/**\n * Sets the default method (text, json, …) used to parse the data contained in the response body in case of an HTTP error.\n * As with other static methods, it will affect wretch instances created after calling this function.\n *\n * _Note: if the response Content-Type header is set to \"application/json\", the body will be parsed as json regardless of the errorType._\n *\n * ```js\n * import wretch from \"wretch\"\n *\n * wretch.errorType(\"json\")\n *\n * wretch(\"http://server/which/returns/an/error/with/a/json/body\")\n * .get()\n * .res()\n * .catch(error => {\n * // error[errorType] (here, json) contains the parsed body\n * console.log(error.json)\n * })\n * ```\n *\n * If null, defaults to \"text\".\n */\nexport function setErrorType(errorType: string) {\n config.errorType = errorType\n}\n\nexport default config\n","import { middlewareHelper } from \"./middleware.js\"\nimport { mix } from \"./utils.js\"\nimport type { Wretch, WretchResponse, WretchResponseChain, WretchError as WretchErrorType } from \"./types.js\"\nimport { FETCH_ERROR, CATCHER_FALLBACK } from \"./constants.js\"\n\n/**\n * This class inheriting from Error is thrown when the fetch response is not \"ok\".\n * It extends Error and adds status, text and body fields.\n */\nexport class WretchError extends Error implements WretchErrorType {\n status: number\n response: WretchResponse\n url: string\n text?: string\n json?: any\n}\n\nexport const resolver = (wretch: T & Wretch) => {\n const sharedState = Object.create(null)\n\n wretch = wretch._addons.reduce((w, addon) =>\n addon.beforeRequest &&\n addon.beforeRequest(w, wretch._options, sharedState)\n || w,\n wretch)\n\n const {\n _url: url,\n _options: opts,\n _config: config,\n _catchers: _catchers,\n _resolvers: resolvers,\n _middlewares: middlewares,\n _addons: addons\n } = wretch\n\n const catchers = new Map(_catchers)\n const finalOptions = mix(config.options, opts)\n\n // The generated fetch request\n let finalUrl = url\n const _fetchReq = middlewareHelper(middlewares)((url, options) => {\n finalUrl = url\n return config.polyfill(\"fetch\")(url, options)\n })(url, finalOptions)\n // Throws on an http error\n const referenceError = new Error()\n const throwingPromise: Promise = _fetchReq\n .catch(error => {\n throw { [FETCH_ERROR]: error }\n })\n .then(response => {\n if (!response.ok) {\n const err = new WretchError()\n // Enhance the error object\n err[\"cause\"] = referenceError\n err.stack = err.stack + \"\\nCAUSE: \" + referenceError.stack\n err.response = response\n err.url = finalUrl\n if (response.type === \"opaque\") {\n throw err\n }\n return response.text().then((body: string) => {\n err.message = body\n if (config.errorType === \"json\" || response.headers.get(\"Content-Type\")?.split(\";\")[0] === \"application/json\") {\n try { err.json = JSON.parse(body) } catch (e) { /* ignore */ }\n }\n err.text = body\n err[\"status\"] = response.status\n throw err\n })\n }\n return response\n })\n // Wraps the Promise in order to dispatch the error to a matching catcher\n const catchersWrapper = (promise: Promise): Promise => {\n return promise.catch(err => {\n const fetchErrorFlag = err.hasOwnProperty(FETCH_ERROR)\n const error = fetchErrorFlag ? err[FETCH_ERROR] : err\n\n const catcher =\n (error?.status && catchers.get(error.status)) ||\n catchers.get(error?.name) || (\n fetchErrorFlag && catchers.has(FETCH_ERROR) && catchers.get(FETCH_ERROR)\n )\n\n if (catcher)\n return catcher(error, wretch)\n\n const catcherFallback = catchers.get(CATCHER_FALLBACK)\n if (catcherFallback)\n return catcherFallback(error, wretch)\n\n throw error\n })\n }\n // Enforces the proper promise type when a body parsing method is called.\n type BodyParser = (funName: \"json\" | \"blob\" | \"formData\" | \"arrayBuffer\" | \"text\" | null) => (cb?: (type: Type) => Result) => Promise>\n const bodyParser: BodyParser = funName => cb => funName ?\n // If a callback is provided, then callback with the body result otherwise return the parsed body itself.\n catchersWrapper(throwingPromise.then(_ => _ && _[funName]()).then(_ => cb ? cb(_) : _)) :\n // No body parsing method - return the response\n catchersWrapper(throwingPromise.then(_ => cb ? cb(_ as any) : _))\n\n const responseChain: WretchResponseChain = {\n _wretchReq: wretch,\n _fetchReq,\n _sharedState: sharedState,\n res: bodyParser(null),\n json: bodyParser(\"json\"),\n blob: bodyParser(\"blob\"),\n formData: bodyParser(\"formData\"),\n arrayBuffer: bodyParser(\"arrayBuffer\"),\n text: bodyParser(\"text\"),\n error(errorId, cb) {\n catchers.set(errorId, cb)\n return this\n },\n badRequest(cb) { return this.error(400, cb) },\n unauthorized(cb) { return this.error(401, cb) },\n forbidden(cb) { return this.error(403, cb) },\n notFound(cb) { return this.error(404, cb) },\n timeout(cb) { return this.error(408, cb) },\n internalError(cb) { return this.error(500, cb) },\n fetchError(cb) { return this.error(FETCH_ERROR, cb) },\n }\n\n const enhancedResponseChain: R extends undefined ? Chain & WretchResponseChain : R = addons.reduce((chain, addon) => ({\n ...chain,\n ...(typeof addon.resolver === \"function\" ? (addon.resolver as (_: WretchResponseChain) => any)(chain) : addon.resolver)\n }), responseChain)\n\n return resolvers.reduce((chain, r) => r(chain, wretch), enhancedResponseChain)\n}\n","import type { ConfiguredMiddleware, FetchLike } from \"./types.js\"\n\n/**\n * @private @internal\n */\nexport const middlewareHelper = (middlewares: ConfiguredMiddleware[]) => (fetchFunction: FetchLike): FetchLike => {\n return middlewares.reduceRight((acc, curr) => curr(acc), fetchFunction) || fetchFunction\n}\n","import { mix, extractContentType, isLikelyJsonMime } from \"./utils.js\"\nimport { JSON_MIME, CONTENT_TYPE_HEADER, CATCHER_FALLBACK } from \"./constants.js\"\nimport { resolver } from \"./resolver.js\"\nimport config from \"./config.js\"\nimport type { Wretch } from \"./types.js\"\n\nexport const core: Wretch = {\n _url: \"\",\n _options: {},\n _config: config,\n _catchers: new Map(),\n _resolvers: [],\n _deferred: [],\n _middlewares: [],\n _addons: [],\n addon(addon) {\n return { ...this, _addons: [...this._addons, addon], ...addon.wretch }\n },\n errorType(errorType: string) {\n return {\n ...this,\n _config: {\n ...this._config,\n errorType\n }\n }\n },\n polyfills(polyfills, replace = false) {\n return {\n ...this,\n _config: {\n ...this._config,\n polyfills: replace ? polyfills : mix(this._config.polyfills, polyfills)\n }\n }\n },\n url(_url, replace = false) {\n if (replace)\n return { ...this, _url }\n const split = this._url.split(\"?\")\n return {\n ...this,\n _url: split.length > 1 ?\n split[0] + _url + \"?\" + split[1] :\n this._url + _url\n }\n },\n options(options, replace = false) {\n return { ...this, _options: replace ? options : mix(this._options, options) }\n },\n headers(headerValues) {\n const headers =\n !headerValues ? {} :\n Array.isArray(headerValues) ? Object.fromEntries(headerValues) :\n \"entries\" in headerValues ? Object.fromEntries((headerValues as Headers).entries()) :\n headerValues\n return { ...this, _options: mix(this._options, { headers }) }\n },\n accept(headerValue) {\n return this.headers({ Accept: headerValue })\n },\n content(headerValue) {\n return this.headers({ [CONTENT_TYPE_HEADER]: headerValue })\n },\n auth(headerValue) {\n return this.headers({ Authorization: headerValue })\n },\n catcher(errorId, catcher) {\n const newMap = new Map(this._catchers)\n newMap.set(errorId, catcher)\n return { ...this, _catchers: newMap }\n },\n catcherFallback(catcher) {\n return this.catcher(CATCHER_FALLBACK, catcher)\n },\n resolve(resolver, clear: boolean = false) {\n return { ...this, _resolvers: clear ? [resolver] : [...this._resolvers, resolver] }\n },\n defer(callback, clear: boolean = false) {\n return {\n ...this,\n _deferred: clear ? [callback] : [...this._deferred, callback]\n }\n },\n middlewares(middlewares, clear = false) {\n return {\n ...this,\n _middlewares: clear ? middlewares : [...this._middlewares, ...middlewares]\n }\n },\n fetch(method: string = this._options.method, url = \"\", body = null) {\n let base = this.url(url).options({ method })\n // \"Jsonify\" the body if it is an object and if it is likely that the content type targets json.\n const contentType = extractContentType(base._options.headers)\n const jsonify = typeof body === \"object\" && (!base._options.headers || !contentType || isLikelyJsonMime(contentType))\n base =\n !body ? base :\n jsonify ? base.json(body, contentType) :\n base.body(body)\n return resolver(\n base\n ._deferred\n .reduce((acc: Wretch, curr) => curr(acc, acc._url, acc._options), base)\n )\n },\n get(url = \"\") {\n return this.fetch(\"GET\", url)\n },\n delete(url = \"\") {\n return this.fetch(\"DELETE\", url)\n },\n put(body, url = \"\") {\n return this.fetch(\"PUT\", url, body)\n },\n post(body, url = \"\") {\n return this.fetch(\"POST\", url, body)\n },\n patch(body, url = \"\") {\n return this.fetch(\"PATCH\", url, body)\n },\n head(url = \"\") {\n return this.fetch(\"HEAD\", url)\n },\n opts(url = \"\") {\n return this.fetch(\"OPTIONS\", url)\n },\n body(contents) {\n return { ...this, _options: { ...this._options, body: contents } }\n },\n json(jsObject, contentType) {\n const currentContentType = extractContentType(this._options.headers)\n return this.content(\n contentType ||\n isLikelyJsonMime(currentContentType) && currentContentType ||\n JSON_MIME\n ).body(JSON.stringify(jsObject))\n }\n}\n","import type { Wretch, WretchAddon, WretchErrorCallback, WretchResponseChain } from \"../types.js\"\n\nexport interface AbortWretch {\n /**\n * Associates a custom controller with the request.\n *\n * Useful when you need to use\n * your own AbortController, otherwise wretch will create a new controller itself.\n *\n * ```js\n * const controller = new AbortController()\n *\n * // Associates the same controller with multiple requests\n * wretch(\"url1\")\n * .addon(AbortAddon())\n * .signal(controller)\n * .get()\n * .json()\n * wretch(\"url2\")\n * .addon(AbortAddon())\n * .signal(controller)\n * .get()\n * .json()\n *\n * // Aborts both requests\n * controller.abort()\n * ```\n *\n * @param controller - An instance of AbortController\n */\n signal: (this: T & Wretch, controller: AbortController) => this\n}\n\nexport interface AbortResolver {\n /**\n * Aborts the request after a fixed time.\n *\n * If you use a custom AbortController associated with the request, pass it as the second argument.\n *\n * ```js\n * // 1 second timeout\n * wretch(\"...\").addon(AbortAddon()).get().setTimeout(1000).json(_ =>\n * // will not be called if the request timeouts\n * )\n * ```\n *\n * @param time - Time in milliseconds\n * @param controller - An instance of AbortController\n */\n setTimeout: (this: C & WretchResponseChain, time: number, controller?: AbortController) => this\n /**\n * Returns the provided or generated AbortController plus the wretch response chain as a pair.\n *\n * ```js\n * // We need the controller outside the chain\n * const [c, w] = wretch(\"url\")\n * .addon(AbortAddon())\n * .get()\n * .controller()\n *\n * // Resume with the chain\n * w.onAbort(_ => console.log(\"ouch\")).json()\n *\n * // Later on…\n * c.abort()\n * ```\n */\n controller: (this: C & WretchResponseChain) => [any, this]\n /**\n * Catches an AbortError and performs a callback.\n */\n onAbort: (this: C & WretchResponseChain, cb: WretchErrorCallback) => this\n}\n\n/**\n * Adds the ability to abort requests using AbortController and signals under the hood.\n *\n *\n * _Only compatible with browsers that support\n * [AbortControllers](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).\n * Otherwise, you could use a (partial)\n * [polyfill](https://www.npmjs.com/package/abortcontroller-polyfill)._\n *\n * ```js\n * import AbortAddon from \"wretch/addons/abort\"\n *\n * const [c, w] = wretch(\"...\")\n * .addon(AbortAddon())\n * .get()\n * .onAbort((_) => console.log(\"Aborted !\"))\n * .controller();\n *\n * w.text((_) => console.log(\"should never be called\"));\n * c.abort();\n *\n * // Or :\n *\n * const controller = new AbortController();\n *\n * wretch(\"...\")\n * .addon(AbortAddon())\n * .signal(controller)\n * .get()\n * .onAbort((_) => console.log(\"Aborted !\"))\n * .text((_) => console.log(\"should never be called\"));\n *\n * controller.abort();\n * ```\n */\nconst abort: () => WretchAddon = () => {\n return {\n beforeRequest(wretch, options, state) {\n const fetchController = wretch._config.polyfill(\"AbortController\", false, true)\n if (!options[\"signal\"] && fetchController) {\n options[\"signal\"] = fetchController.signal\n }\n const timeout = {\n ref: null,\n clear() {\n if (timeout.ref) {\n clearTimeout(timeout.ref)\n timeout.ref = null\n }\n }\n }\n state.abort = {\n timeout,\n fetchController\n }\n return wretch\n },\n wretch: {\n signal(controller) {\n return { ...this, _options: { ...this._options, signal: controller.signal } }\n },\n },\n resolver: {\n setTimeout(time, controller = this._sharedState.abort.fetchController) {\n const { timeout } = this._sharedState.abort\n timeout.clear()\n timeout.ref = setTimeout(() => controller.abort(), time)\n return this\n },\n controller() { return [this._sharedState.abort.fetchController, this] },\n onAbort(cb) { return this.error(\"AbortError\", cb) }\n },\n }\n}\n\nexport default abort\n","import type { Wretch, Config, WretchAddon } from \"../types.js\"\n\nfunction convertFormData(\n formObject: object,\n recursive: string[] | boolean = false,\n config: Config,\n formData = config.polyfill(\"FormData\", true, true),\n ancestors = [],\n) {\n Object.entries(formObject).forEach(([key, value]) => {\n let formKey = ancestors.reduce((acc, ancestor) => (\n acc ? `${acc}[${ancestor}]` : ancestor\n ), null)\n formKey = formKey ? `${formKey}[${key}]` : key\n if (value instanceof Array || (globalThis.FileList && value instanceof FileList)) {\n for (const item of value as File[])\n formData.append(formKey, item)\n } else if (\n recursive &&\n typeof value === \"object\" &&\n (\n !(recursive instanceof Array) ||\n !recursive.includes(key)\n )\n ) {\n if (value !== null) {\n convertFormData(value, recursive, config, formData, [...ancestors, key])\n }\n } else {\n formData.append(formKey, value)\n }\n })\n\n return formData\n}\n\nexport interface FormDataAddon {\n /**\n * Converts the javascript object to a FormData and sets the request body.\n *\n * ```js\n * const form = {\n * hello: \"world\",\n * duck: \"Muscovy\",\n * };\n *\n * wretch(\"...\").addons(FormDataAddon).formData(form).post();\n * ```\n *\n * The `recursive` argument when set to `true` will enable recursion through all\n * nested objects and produce `object[key]` keys. It can be set to an array of\n * string to exclude specific keys.\n *\n * > Warning: Be careful to exclude `Blob` instances in the Browser, and\n * > `ReadableStream` and `Buffer` instances when using the node.js compatible\n * > `form-data` package.\n *\n * ```js\n * const form = {\n * duck: \"Muscovy\",\n * duckProperties: {\n * beak: {\n * color: \"yellow\",\n * },\n * legs: 2,\n * },\n * ignored: {\n * key: 0,\n * },\n * };\n *\n * // Will append the following keys to the FormData payload:\n * // \"duck\", \"duckProperties[beak][color]\", \"duckProperties[legs]\"\n * wretch(\"...\").addons(FormDataAddon).formData(form, [\"ignored\"]).post();\n * ```\n *\n * > Note: This addon does not support specifying a custom `filename`.\n * > If you need to do so, you can use the `body` method directly:\n * > ```js\n * > const form = new FormData();\n * > form.append(\"hello\", \"world\", \"hello.txt\");\n * > wretch(\"...\").body(form).post();\n * > ```\n * > See: https://developer.mozilla.org/en-US/docs/Web/API/FormData/append#example\n *\n * @param formObject - An object which will be converted to a FormData\n * @param recursive - If `true`, will recurse through all nested objects. Can be set as an array of string to exclude specific keys.\n */\n formData(this: T & Wretch, formObject: object, recursive?: string[] | boolean): this\n}\n\n/**\n * Adds the ability to convert a an object to a FormData and use it as a request body.\n *\n * ```js\n * import FormDataAddon from \"wretch/addons/formData\"\n *\n * wretch().addon(FormDataAddon)\n * ```\n */\nconst formData: WretchAddon = {\n wretch: {\n formData(formObject, recursive = false) {\n return this.body(convertFormData(formObject, recursive, this._config))\n }\n }\n}\n\nexport default formData\n","import type { Wretch, WretchAddon } from \"../types.js\"\n\nfunction encodeQueryValue(key: string, value: unknown) {\n return encodeURIComponent(key) +\n \"=\" +\n encodeURIComponent(\n typeof value === \"object\" ?\n JSON.stringify(value) :\n \"\" + value\n )\n}\nfunction convertFormUrl(formObject: object) {\n return Object.keys(formObject)\n .map(key => {\n const value = formObject[key]\n if (value instanceof Array) {\n return value.map(v => encodeQueryValue(key, v)).join(\"&\")\n }\n return encodeQueryValue(key, value)\n })\n .join(\"&\")\n}\n\nexport interface FormUrlAddon {\n /**\n * Converts the input parameter to an url encoded string and sets the content-type\n * header and body. If the input argument is already a string, skips the conversion\n * part.\n *\n * ```js\n * const form = { a: 1, b: { c: 2 } };\n * const alreadyEncodedForm = \"a=1&b=%7B%22c%22%3A2%7D\";\n *\n * // Automatically sets the content-type header to \"application/x-www-form-urlencoded\"\n * wretch(\"...\").addon(FormUrlAddon).formUrl(form).post();\n * wretch(\"...\").addon(FormUrlAddon).formUrl(alreadyEncodedForm).post();\n * ```\n *\n * @param input - An object to convert into an url encoded string or an already encoded string\n */\n formUrl(this: T & Wretch, input: (object | string)): this\n}\n\n/**\n * Adds the ability to convert a an object to a FormUrl and use it as a request body.\n *\n * ```js\n * import FormUrlAddon from \"wretch/addons/formUrl\"\n *\n * wretch().addon(FormUrlAddon)\n * ```\n */\nconst formUrl: WretchAddon = {\n wretch: {\n formUrl(input) {\n return this\n .body(typeof input === \"string\" ? input : convertFormUrl(input))\n .content(\"application/x-www-form-urlencoded\")\n }\n }\n}\n\nexport default formUrl\n","import type { WretchResponseChain, WretchAddon } from \"../types.js\"\n\nexport interface PerfsAddon {\n /**\n * Performs a callback on the API performance timings of the request.\n *\n * Warning: Still experimental on browsers and node.js\n */\n perfs: (this: C & WretchResponseChain, cb?: (timing: any) => void) => this,\n}\n\n/**\n * Adds the ability to measure requests using the Performance Timings API.\n *\n * Uses the Performance API\n * ([browsers](https://developer.mozilla.org/en-US/docs/Web/API/Performance_API) &\n * [node.js](https://nodejs.org/api/perf_hooks.html)) to expose timings related to\n * the underlying request.\n *\n * Browser timings are very accurate, node.js only contains raw measures.\n *\n * ```js\n * import PerfsAddon from \"wretch/addons/perfs\"\n *\n * // Use perfs() before the response types (text, json, ...)\n * wretch(\"...\")\n * .addon(PerfsAddon())\n * .get()\n * .perfs((timings) => {\n * // Will be called when the timings are ready.\n * console.log(timings.startTime);\n * })\n * .res();\n *\n * ```\n *\n * For node.js, there is a little extra work to do :\n *\n * ```js\n * // Node.js only\n * const { performance, PerformanceObserver } = require(\"perf_hooks\");\n *\n * wretch.polyfills({\n * fetch: function (url, opts) {\n * performance.mark(url + \" - begin\");\n * return fetch(url, opts).then(res => {\n * performance.mark(url + \" - end\");\n * setTimeout(() => performance.measure(res.url, url + \" - begin\", url + \" - end\"), 0);\n * return res;\n * });\n * },\n * // other polyfills…\n * performance: performance,\n * PerformanceObserver: PerformanceObserver,\n * });\n * ```\n */\nconst perfs: () => WretchAddon = () => {\n const callbacks = new Map()\n let observer = null\n\n const onMatch = (entries, name, callback, performance) => {\n if (!entries.getEntriesByName)\n return false\n const matches = entries.getEntriesByName(name)\n if (matches && matches.length > 0) {\n callback(matches.reverse()[0])\n if (performance.clearMeasures)\n performance.clearMeasures(name)\n callbacks.delete(name)\n\n if (callbacks.size < 1) {\n observer.disconnect()\n if (performance.clearResourceTimings) {\n performance.clearResourceTimings()\n }\n }\n return true\n }\n return false\n }\n\n const initObserver = (performance, performanceObserver) => {\n if (!observer && performance && performanceObserver) {\n observer = new performanceObserver(entries => {\n callbacks.forEach((callback, name) => {\n onMatch(entries, name, callback, performance)\n })\n })\n if (performance.clearResourceTimings) {\n performance.clearResourceTimings()\n }\n }\n\n return observer\n }\n\n const monitor = (name, callback, config) => {\n if (!name || !callback)\n return\n\n const performance = config.polyfill(\"performance\", false)\n const performanceObserver = config.polyfill(\"PerformanceObserver\", false)\n\n if (!initObserver(performance, performanceObserver))\n return\n\n if (!onMatch(performance, name, callback, performance)) {\n if (callbacks.size < 1)\n observer.observe({ entryTypes: [\"resource\", \"measure\"] })\n callbacks.set(name, callback)\n }\n }\n\n return {\n resolver: {\n perfs(cb) {\n this._fetchReq\n .then(res =>\n monitor(this._wretchReq._url, cb, this._wretchReq._config)\n )\n .catch(() => {/* swallow */ })\n return this\n },\n }\n }\n}\n\nexport default perfs\n","import type { Wretch, Config, WretchAddon } from \"../types.js\"\n\nfunction stringify(value?: string | null): string | null {\n return typeof value !== \"undefined\" ? value : \"\"\n}\n\nconst appendQueryParams = (url: string, qp: object | string, replace: boolean, config: Config) => {\n let queryString: string\n\n if (typeof qp === \"string\") {\n queryString = qp\n } else {\n const usp = config.polyfill(\"URLSearchParams\", true, true)\n for (const key in qp) {\n const value = qp[key]\n if (qp[key] instanceof Array) {\n for (const val of value)\n usp.append(key, stringify(val))\n } else {\n usp.append(key, stringify(value))\n }\n }\n queryString = usp.toString()\n }\n\n const split = url.split(\"?\")\n\n if (!queryString)\n return replace ? split[0] : url\n\n if (replace || split.length < 2)\n return split[0] + \"?\" + queryString\n\n return url + \"&\" + queryString\n}\n\nexport interface QueryStringAddon {\n /**\n * Converts a javascript object to query parameters, then appends this query string\n * to the current url. String values are used as the query string verbatim.\n *\n * Pass `true` as the second argument to replace existing query parameters.\n *\n * ```\n * import QueryAddon from \"wretch/addons/queryString\"\n *\n * let w = wretch(\"http://example.com\").addon(QueryStringAddon);\n * // url is http://example.com\n * w = w.query({ a: 1, b: 2 });\n * // url is now http://example.com?a=1&b=2\n * w = w.query({ c: 3, d: [4, 5] });\n * // url is now http://example.com?a=1&b=2c=3&d=4&d=5\n * w = w.query(\"five&six&seven=eight\");\n * // url is now http://example.com?a=1&b=2c=3&d=4&d=5&five&six&seven=eight\n * w = w.query({ reset: true }, true);\n * // url is now http://example.com?reset=true\n * ```\n *\n * ##### **Note that .query is not meant to handle complex cases with nested objects.**\n *\n * For this kind of usage, you can use `wretch` in conjunction with other libraries\n * (like [`qs`](https://github.com/ljharb/qs)).\n *\n * ```js\n * // Using wretch with qs\n *\n * const queryObject = { some: { nested: \"objects\" } };\n * const w = wretch(\"https://example.com/\").addon(QueryStringAddon)\n *\n * // Use .qs inside .query :\n *\n * w.query(qs.stringify(queryObject));\n *\n * // Use .defer :\n *\n * const qsWretch = w.defer((w, url, { qsQuery, qsOptions }) => (\n * qsQuery ? w.query(qs.stringify(qsQuery, qsOptions)) : w\n * ));\n *\n * qsWretch\n * .url(\"https://example.com/\")\n * .options({ qs: { query: queryObject } });\n * ```\n *\n * @param qp - An object which will be converted, or a string which will be used verbatim.\n */\n query(this: T & Wretch, qp: object | string, replace?: boolean): this\n}\n\n/**\n * Adds the ability to append query parameters from a javascript object.\n *\n * ```js\n * import QueryAddon from \"wretch/addons/queryString\"\n *\n * wretch().addon(QueryAddon)\n * ```\n */\nconst queryString: WretchAddon = {\n wretch: {\n query(qp, replace = false) {\n return { ...this, _url: appendQueryParams(this._url, qp, replace, this._config) }\n }\n }\n}\n\nexport default queryString\n","import type { ConfiguredMiddleware, WretchAddon, WretchResponseChain } from \"../types.js\"\n\nexport interface ProgressResolver {\n /**\n * Provides a way to register a callback to be invoked one or multiple times during the download.\n * The callback receives the current progress as two arguments, the number of bytes loaded and the total number of bytes to load.\n *\n * _Under the hood: this method adds a middleware to the chain that will intercept the response and replace the body with a new one that will emit the progress event._\n *\n * ```js\n * import ProgressAddon from \"wretch/addons/progress\"\n *\n * wretch(\"some_url\")\n * // Register the addon\n * .addon(ProgressAddon())\n * .get()\n * // Log the progress as a percentage of completion\n * .progress((loaded, total) => console.log(`${(loaded / total * 100).toFixed(0)}%`))\n * ```\n *\n * @param onProgress - A callback that will be called one or multiple times with the number of bytes loaded and the total number of bytes to load.\n */\n progress: (\n this: C & WretchResponseChain,\n onProgress: (loaded: number, total: number) => void\n ) => this\n}\n\n/**\n * Adds the ability to monitor progress when downloading a response.\n *\n * _Compatible with all platforms implementing the [TransformStream WebAPI](https://developer.mozilla.org/en-US/docs/Web/API/TransformStream#browser_compatibility)._\n *\n * ```js\n * import ProgressAddon from \"wretch/addons/progress\"\n *\n * wretch(\"some_url\")\n * // Register the addon\n * .addon(ProgressAddon())\n * .get()\n * // Log the progress as a percentage of completion\n * .progress((loaded, total) => console.log(`${(loaded / total * 100).toFixed(0)}%`))\n * ```\n */\nconst progress: () => WretchAddon = () => {\n function transformMiddleware(state: Record) : ConfiguredMiddleware {\n return next => (url, opts) => {\n let loaded = 0\n let total = 0\n return next(url, opts).then(response => {\n try {\n const contentLength = response.headers.get(\"content-length\")\n total = contentLength ? +contentLength : null\n const transform = new TransformStream({\n transform(chunk, controller) {\n loaded += chunk.length\n if (total < loaded) {\n total = loaded\n }\n if (state.progress) {\n state.progress(loaded, total)\n }\n controller.enqueue(chunk)\n }\n })\n return new Response(response.body.pipeThrough(transform), response)\n } catch (e) {\n return response\n }\n })\n }\n }\n\n return {\n beforeRequest(wretch, _, state) {\n return wretch.middlewares([transformMiddleware(state)])\n },\n resolver: {\n progress(onProgress: (loaded: number, total: number) => void) {\n this._sharedState.progress = onProgress\n return this\n }\n },\n }\n}\n\nexport default progress\n","import { setOptions, setErrorType, setPolyfills } from \"./config.js\"\nimport { core } from \"./core.js\"\nimport * as Addons from \"./addons/index.js\"\nimport { WretchError } from \"./resolver.js\"\n\nfunction factory(_url = \"\", _options = {}) {\n return { ...core, _url, _options }\n .addon(Addons.abortAddon())\n .addon(Addons.formDataAddon)\n .addon(Addons.formUrlAddon)\n .addon(Addons.perfsAddon())\n .addon(Addons.queryStringAddon)\n .addon(Addons.progressAddon())\n}\n\nfactory[\"default\"] = factory\nfactory.options = setOptions\nfactory.errorType = setErrorType\nfactory.polyfills = setPolyfills\nfactory.WretchError = WretchError\n\nexport default factory\n"],"names":["CONTENT_TYPE_HEADER","FETCH_ERROR","Symbol","CATCHER_FALLBACK","extractContentType","headers","_a","Object","entries","find","k","toLowerCase","isLikelyJsonMime","value","test","mix","one","two","mergeArrays","reduce","acc","key","newValue","Array","isArray","config","options","errorType","polyfills","polyfill","p","doThrow","instance","args","res","this","self","global","Error","WretchError","resolver","wretch","sharedState","create","_addons","w","addon","beforeRequest","_options","_url","url","opts","_config","_catchers","_resolvers","resolvers","_middlewares","middlewares","addons","catchers","Map","finalOptions","finalUrl","_fetchReq","fetchFunction","reduceRight","curr","middlewareHelper","referenceError","throwingPromise","catch","error","then","response","ok","err","stack","type","text","body","message","get","split","json","JSON","parse","e","status","bodyParser","funName","cb","_","fetchErrorFlag","hasOwnProperty","catcher","name","has","catcherFallback","responseChain","_wretchReq","_sharedState","blob","formData","arrayBuffer","errorId","set","badRequest","unauthorized","forbidden","notFound","timeout","internalError","fetchError","enhancedResponseChain","chain","r","core","_deferred","replace","length","headerValues","fromEntries","accept","headerValue","Accept","content","auth","Authorization","newMap","resolve","clear","defer","callback","fetch","method","base","contentType","jsonify","delete","put","post","patch","head","contents","jsObject","currentContentType","stringify","abort","state","fetchController","signal","ref","clearTimeout","controller","setTimeout","time","onAbort","convertFormData","formObject","recursive","ancestors","forEach","formKey","ancestor","globalThis","FileList","item","append","includes","encodeQueryValue","encodeURIComponent","formUrl","input","keys","map","v","join","perfs","callbacks","observer","onMatch","performance","getEntriesByName","matches","reverse","clearMeasures","size","disconnect","clearResourceTimings","performanceObserver","initObserver","observe","entryTypes","monitor","appendQueryParams","qp","queryString","usp","val","toString","query","progress","transformMiddleware","next","loaded","total","contentLength","transform","TransformStream","chunk","enqueue","Response","pipeThrough","onProgress","factory","Addons.abortAddon","Addons.formDataAddon","Addons.formUrlAddon","Addons.perfsAddon","Addons.queryStringAddon","Addons.progressAddon"],"mappings":"uOAAO,MACMA,EAAsB,eACtBC,EAAcC,SACdC,EAAmBD,SCDhB,SAAAE,EAAmBC,EAAkC,UACnE,OAEI,QAFGC,EAAAC,OAAOC,QAAQH,GAASI,MAAK,EAAEC,KACpCA,EAAEC,gBAAkBX,EAAoBW,uBACtC,IAAAL,OAAA,EAAAA,EAAA,EACN,CAEM,SAAUM,EAAiBC,GAC/B,MAAO,yBAAyBC,KAAKD,EACvC,CAEO,MAAME,EAAM,SAAUC,EAAaC,EAAaC,EAAuB,GAC5E,OAAOX,OAAOC,QAAQS,GAAKE,QAAO,CAACC,GAAMC,EAAKC,MAC5C,MAAMT,EAAQG,EAAIK,GASlB,OARIE,MAAMC,QAAQX,IAAUU,MAAMC,QAAQF,GACxCF,EAAIC,GAAOH,EAAc,IAAIL,KAAUS,GAAYA,EAEnDF,EAAIC,GADsB,iBAAVR,GAA0C,iBAAbS,EAClCP,EAAIF,EAAOS,EAAUJ,GAErBI,EAGNF,CAAG,GACT,IAAKJ,GACV,ECpBMS,EAAiB,CAErBC,QAAS,CAAE,EAEXC,UAAW,OAEXC,UAAW,CAOV,EACDC,SAASC,EAAWC,EAAmB,EAAMC,EAAoB,KAAUC,GACzE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