wretch
Version:
A tiny wrapper built around fetch with an intuitive syntax.
1 lines • 43 kB
Source Map (JSON)
{"version":3,"file":"wretch.all.min.cjs","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()","import { CONTENT_TYPE_HEADER } from \"./constants.js\"\n\nexport function extractContentType(headers: HeadersInit = {}): 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 * ```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 } 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 text?: string\n json?: any\n}\n\nexport const resolver = <T, Chain, R>(wretch: T & Wretch<T, Chain, R>) => {\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 addons.forEach(addon => addon.beforeRequest && addon.beforeRequest(wretch, finalOptions))\n // The generated fetch request\n const _fetchReq = middlewareHelper(middlewares)(config.polyfill(\"fetch\"))(url, finalOptions)\n // Throws on an http error\n const referenceError = new Error()\n const throwingPromise: Promise<void | WretchResponse> = _fetchReq\n .catch(error => {\n throw { __wrap: 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 if (response.type === \"opaque\") {\n throw err\n }\n return response[config.errorType]().then((body: string) => {\n err.message = body\n err[config.errorType] = 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 = <T>(promise: Promise<T>): Promise<void | T> => {\n return promise.catch(err => {\n const error = err.__wrap || err\n\n const catcher =\n err.__wrap && catchers.has(FETCH_ERROR) ? catchers.get(FETCH_ERROR) :\n (catchers.get(error.status) || catchers.get(error.name))\n\n if (catcher)\n return catcher(error, wretch)\n\n throw error\n })\n }\n // Enforces the proper promise type when a body parsing method is called.\n type BodyParser = <Type>(funName: string | null) => <Result = void>(cb?: (type: Type) => Result) => Promise<Awaited<Result>>\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<T, Chain, R> = {\n _wretchReq: wretch,\n _fetchReq,\n res: bodyParser<WretchResponse>(null),\n json: bodyParser<any>(\"json\"),\n blob: bodyParser<Blob>(\"blob\"),\n formData: bodyParser<FormData>(\"formData\"),\n arrayBuffer: bodyParser<ArrayBuffer>(\"arrayBuffer\"),\n text: bodyParser<string>(\"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<T, Chain, undefined> : R = addons.reduce((chain, addon) => ({\n ...chain,\n ...(addon.resolver as any)\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 } 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 return { ...this, _options: mix(this._options, { headers: headerValues || {} }) }\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 resolve<R = unknown>(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: <T extends AbortWretch, C, R>(this: T & Wretch<T, C, R>, 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: <T, C extends AbortResolver, R>(this: C & WretchResponseChain<T, C, R>, 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: <T, C extends AbortResolver, R>(this: C & WretchResponseChain<T, C, R>) => [any, this]\n /**\n * Catches an AbortError and performs a callback.\n */\n onAbort: <T, C extends AbortResolver, R>(this: C & WretchResponseChain<T, C, R>, cb: WretchErrorCallback<T, C, R>) => 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<AbortWretch, AbortResolver> = () => {\n let timeout = null\n let fetchController = null\n return {\n beforeRequest(wretch, options) {\n fetchController = wretch._config.polyfill(\"AbortController\", false, true)\n if (!options[\"signal\"] && fetchController) {\n options[\"signal\"] = fetchController.signal\n }\n timeout = {\n ref: null,\n clear() {\n if (timeout.ref) {\n clearTimeout(timeout.ref)\n timeout.ref = null\n }\n }\n }\n },\n wretch: {\n signal(controller) {\n return { ...this, _options: { ...this._options, signal: controller.signal } }\n },\n },\n resolver: {\n setTimeout(time, controller = fetchController) {\n timeout.clear()\n timeout.ref = setTimeout(() => controller.abort(), time)\n return this\n },\n controller() { return [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) {\n for (const item of value)\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 * @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<T extends FormDataAddon, C, R>(this: T & Wretch<T, C, R>, 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<FormDataAddon> = {\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<T extends FormUrlAddon, C, R>(this: T & Wretch<T, C, R>, 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<FormUrlAddon> = {\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\nconst 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 utils.callbacks.delete(name)\n\n if (utils.callbacks.size < 1) {\n utils.observer.disconnect()\n if (_performance.clearResourceTimings) {\n _performance.clearResourceTimings()\n }\n }\n return true\n }\n return false\n}\n\nconst lazyObserver = (_performance, _observer) => {\n if (!utils.observer && _performance && _observer) {\n utils.observer = new _observer(entries => {\n utils.callbacks.forEach((callback, name) => {\n onMatch(entries, name, callback, _performance)\n })\n })\n if (_performance.clearResourceTimings)\n _performance.clearResourceTimings()\n }\n return utils.observer\n}\n\nconst utils = {\n callbacks: new Map(),\n observer: null,\n observe: (name, callback, config) => {\n if (!name || !callback)\n return\n\n const _performance = config.polyfill(\"performance\", false)\n const _observer = config.polyfill(\"PerformanceObserver\", false)\n\n if (!lazyObserver(_performance, _observer))\n return\n\n if (!onMatch(_performance, name, callback, _performance)) {\n if (utils.callbacks.size < 1)\n utils.observer.observe({ entryTypes: [\"resource\", \"measure\"] })\n utils.callbacks.set(name, callback)\n }\n\n }\n}\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: <T, C extends PerfsAddon, R>(this: C & WretchResponseChain<T, C, R>, 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<unknown, PerfsAddon> = () => ({\n resolver: {\n perfs(cb) {\n this._fetchReq.then(res => utils.observe(res.url, cb, this._wretchReq._config)).catch(() => {/* swallow */ })\n return this\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<T extends QueryStringAddon, C, R>(this: T & Wretch<T, C, R>, 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<QueryStringAddon> = {\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: <T, C extends ProgressResolver, R>(\n this: C & WretchResponseChain<T, C, R>,\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<unknown, ProgressResolver> = () => {\n const cb = {\n ref: null\n }\n\n const transformMiddleware: ConfiguredMiddleware = 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 (cb.ref) {\n cb.ref(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 return {\n beforeRequest(wretch) {\n return wretch._middlewares.push(transformMiddleware)\n },\n resolver: {\n progress(onProgress: (loaded: number, total: number) => void) {\n cb.ref = 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":["FETCH_ERROR","Symbol","extractContentType","headers","_a","Object","entries","find","k","toLowerCase","test","value","one","two","mergeArrays","reduce","acc","key","newValue","Array","isArray","mix","config","options","errorType","polyfills","res","this","p","self","global","doThrow","Error","instance","args","resolver","wretch","_url","url","_options","opts","_config","_catchers","_resolvers","resolvers","_middlewares","middlewares","_addons","addons","catchers","Map","finalOptions","addon","beforeRequest","_fetchReq","reduceRight","curr","fetchFunction","middlewareHelper","referenceError","error","__wrap","response","ok","err","WretchError","type","then","body","message","status","bodyParser","funName","cb","_","throwingPromise","catcher","has","get","name","_wretchReq","json","blob","formData","arrayBuffer","text","errorId","set","badRequest","unauthorized","forbidden","notFound","timeout","internalError","fetchError","enhancedResponseChain","chain","responseChain","r","core","_deferred","replace","split","length","headerValues","accept","headerValue","Accept","content","auth","Authorization","newMap","resolve","clear","defer","callback","method","base","contentType","jsonify","fetch","delete","put","post","patch","head","contents","currentContentType","isLikelyJsonMime","JSON","stringify","jsObject","fetchController","polyfill","signal","ref","clearTimeout","controller","setTimeout","time","abort","onAbort","convertFormData","formObject","recursive","ancestors","formKey","ancestor","item","append","includes","encodeQueryValue","encodeURIComponent","input","keys","map","v","join","onMatch","_performance","matches","getEntriesByName","reverse","clearMeasures","utils","callbacks","size","observer","clearResourceTimings","observe","_observer","forEach","lazyObserver","entryTypes","perfs","catch","appendQueryParams","queryString","qp","usp","val","toString","transformMiddleware","next","loaded","contentLength","total","transform","TransformStream","chunk","enqueue","Response","pipeThrough","e","push","progress","onProgress","factory","Addons.abortAddon","Addons.formDataAddon","Addons.formUrlAddon","Addons.perfsAddon"],"mappings":"MAAaA,EAAYC,SAElB,SAAMC,EAAsBC,EAAA,CAAA,SCAnB,OAA4C,QAA1BC,EAAAC,OAAAC,QAACH,GAAyBI,MAAA,EAAAC,KAAAA,EAAAC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