@enegalan/request-manager 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"request-manager.umd.js","sources":["../main.js"],"sourcesContent":["/**\n * RequestManager - A library for managing and regulating HTTP requests efficiently.\n * @license MIT\n * @author Eneko Galan <enekogalanelorza@gmail.com>\n * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)\n * by accepting Promises as parameters. When a request is repeated with the same identifier,\n * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.\n */\nclass RequestManager {\n constructor(options = {}) {\n /**\n * @type {Map<string, import('./index.d.ts').ActiveRequest>}\n */\n this.activeRequests = new Map();\n /**\n * @type {import('./index.d.ts').Options}\n */\n this.options = options;\n /**\n * One-shot AbortController for getSignal()/getAbortController() handoff.\n * Consumed by the next request that does not pass options.abortController.\n * @type {AbortController|null}\n */\n this.abortController = null;\n }\n\n /**\n * Gets the manager options\n * @returns {import('./index.d.ts').Options} Manager options\n */\n getOptions() {\n return this.options;\n }\n\n /**\n * Sets the manager options\n * @param {import('./index.d.ts').Options} options - The options to set\n */\n setOptions(options) {\n this.options = options;\n }\n\n /**\n * Creates a new AbortController and returns its signal for the next request()\n * (one getSignal → one request). Do not use for parallel requests; use fetch(),\n * axios(), or request(url, ({ options }) => ...) instead — they create their own signal.\n * @returns {AbortSignal} The signal from a new AbortController\n * @example\n * const signal = requestManager.getSignal();\n * requestManager.request('/api/users', fetch('/api/users', { signal }));\n */\n getSignal() {\n return this.getAbortController().signal;\n }\n\n /**\n * Creates a new AbortController for the next request handoff.\n * Always returns a fresh controller (never reuses one from another in-flight request).\n * @returns {AbortController} A new AbortController instance\n */\n getAbortController() {\n this.abortController = new AbortController();\n return this.abortController;\n }\n\n /**\n * Checks if a request with the given identifier is currently active.\n * @param {string} requestId - The unique identifier to check\n * @returns {boolean} True if the request is active, false otherwise\n */\n isActive(requestId) {\n return this.activeRequests.has(requestId);\n }\n\n /**\n * Gets the number of active requests.\n * @returns {number} The number of currently active requests\n */\n getActiveCount() {\n return this.activeRequests.size;\n }\n\n /**\n * Clears all active requests without cancelling them.\n * Use with caution - this will not cancel the underlying HTTP requests.\n */\n clear() {\n this.activeRequests.clear();\n }\n\n /**\n * Executes an HTTP request, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise or function that returns a promise\n * @param {import('./index.d.ts').RequestOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Request with Promise\n * requestManager.request('/api/users', axios.get('/api/users'));\n * @example\n * // Request with Function\n * requestManager.request('/api/users', ({ options }) => fetch('/api/users', { signal: options.signal, ...options }));\n * @example\n * // Request with Promise and custom cancellation grouping with requestKey\n * const options = {\n * requestKey: 'get-users'\n * }\n * requestManager.request('/api/users', axios.get('/api/users', options), options);\n */\n request(url, requestPromise, options = {}) {\n return this.#_request(this.getRequestId(url, options), requestPromise, options);\n }\n\n /**\n * Executes an HTTP request using fetch, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to fetch\n * @param {import('./index.d.ts').FetchOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.fetch('/api/users');\n * @example\n * // POST request with options\n * requestManager.fetch('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.fetch('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n fetch(url, options = {}) {\n return this.#_request(this.getRequestId(url, options), url, options);\n }\n\n /**\n * Executes an HTTP request using axios, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').AxiosRequestOptions} options - Optional configuration\n * @param {import('./index.d.ts').AxiosInstance|import('./index.d.ts').AxiosStatic|null} axiosInstance - Optional axios instance to use. If not provided, uses global axios.\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request (uses global axios)\n * requestManager.axios('/api/users');\n * @example\n * // With custom axios instance\n * const myAxios = axios.create({ baseURL: 'https://api.example.com' });\n * requestManager.axios('/users', {}, myAxios);\n * @example\n * // POST request with options\n * requestManager.axios('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.axios('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n axios(url, options = {}, axiosInstance = null) {\n const axiosLib = axiosInstance || axios;\n this.#_checkAxiosVersion(axiosLib);\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => axiosLib({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using jQuery.ajax, cancelling any previous request with the same identifier.\n * @param {import('./index.d.ts').AjaxFunction} ajaxFunction - A function that receives { url, ...options } and returns a Promise\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').BaseRequestOptions & Record<string, any>} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.ajax(ajaxFunction, '/api/users');\n * @example\n * // POST request with options\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * requestKey: 'get-users'\n * });\n */\n ajax(ajaxFunction, url, options = {}) {\n if (typeof ajaxFunction !== 'function') throw new Error('ajaxFunction parameter must be a function');\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => ajaxFunction({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using XMLHttpRequest, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').XhrOptions} options - Optional configuration\n * @returns {Promise<import('./index.d.ts').XhrResponse>} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.xhr('/api/users');\n * @example\n * // POST request with options\n * requestManager.xhr('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping\n * requestManager.xhr('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n xhr(url, options = {}) {\n const requestId = this.getRequestId(url, options);\n /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */\n const xhrFunction = ({ options: fetchOptions }) => {\n // Create XMLHttpRequest\n const xhr = new XMLHttpRequest();\n const method = (options.method || 'GET').toUpperCase();\n // Create a promise that wraps the XHR request\n const xhrPromise = new Promise((resolve, reject) => {\n xhr.onload = function () {\n if (xhr.status >= 200 && xhr.status < 300) {\n let response = xhr.response;\n if (\n options.responseType === 'json' ||\n ((!options.responseType || options.responseType === 'text') &&\n xhr.getResponseHeader('Content-Type')?.includes('application/json') &&\n typeof response === 'string')\n ) {\n try {\n response = JSON.parse(response);\n } catch {}\n }\n resolve({\n data: response,\n status: xhr.status,\n statusText: xhr.statusText,\n headers: xhr.getAllResponseHeaders(),\n xhr: xhr,\n });\n } else {\n reject({\n message: `Request failed with status ${xhr.status}`,\n status: xhr.status,\n statusText: xhr.statusText,\n xhr: xhr,\n });\n }\n };\n xhr.onerror = function () {\n reject({\n message: 'Network error',\n xhr: xhr,\n });\n };\n xhr.ontimeout = function () {\n reject({\n message: 'Request timeout',\n xhr: xhr,\n });\n };\n\n // Open the request\n xhr.open(method, url, true);\n\n // Set response type\n if (options.responseType) xhr.responseType = options.responseType;\n // Set withCredentials\n if (options.withCredentials !== undefined) xhr.withCredentials = options.withCredentials;\n // Set timeout\n if (options.timeout !== undefined) xhr.timeout = options.timeout;\n // Set headers\n if (options.headers)\n Object.keys(options.headers).forEach((key) => {\n xhr.setRequestHeader(key, options.headers[key]);\n });\n\n // Connect abort signal to xhr.abort()\n if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', () => xhr.abort());\n\n // Send the request\n xhr.send(options.body || null);\n });\n return xhrPromise;\n };\n return this.#_request(requestId, xhrFunction, options);\n }\n\n /**\n * Returns the request identifier for a URL and options.\n * @param {string} url - The URL used when starting the request\n * @param {import('./index.d.ts').BaseRequestOptions} options - Same options used for the request\n * @returns {string} The request identifier\n * @example\n * requestManager.fetch('/api/users');\n * const id = requestManager.getRequestId('/api/users');\n * requestManager.cancel(id);\n */\n getRequestId(url, options = {}) {\n let requestKey = options.requestKey;\n\n const prefix = 'request_';\n\n // Generate a unique identifier to prevent cancellation for non cancelable requests\n if (options.noCancel) {\n return `${prefix}${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n // Handle function requestKey\n if (typeof requestKey === 'function') {\n try {\n requestKey = requestKey();\n } catch {\n requestKey = null;\n }\n }\n if (requestKey !== null && requestKey !== undefined) return `${prefix}${String(requestKey)}`;\n\n // Use cleaned URL as key as fallback\n let cleanedUrl = url || '';\n if (cleanedUrl.includes('://')) cleanedUrl = cleanedUrl.split('://')[1];\n if (cleanedUrl.includes('#')) cleanedUrl = cleanedUrl.split('#')[0];\n if (!options.includeQuery && cleanedUrl.includes('?')) cleanedUrl = cleanedUrl.split('?')[0];\n\n const methodPrefix =\n options.includeMethod === false ? '' : `${(options.method || options.type || 'GET').toUpperCase()}_`;\n\n return `${prefix}${methodPrefix}${cleanedUrl}`;\n }\n\n /**\n * Cancels a specific request by its identifier.\n * @param {string} requestId - The unique identifier of the request to cancel\n * @returns {boolean} True if the request was found and cancelled, false otherwise\n */\n cancel(requestId) {\n /** @type {import('./index.d.ts').ActiveRequest|undefined} */\n const requestInfo = this.activeRequests.get(requestId);\n if (!requestInfo) return false;\n\n requestInfo.isCancelled = true; // Mark as cancelled\n\n // Try to abort using AbortController (for fetch)\n if (requestInfo.abortController && !requestInfo.abortController.signal.aborted) {\n try {\n requestInfo.abortController.abort('Request was cancelled');\n } catch (error) {}\n }\n\n // Try to cancel using cancel token/function (for axios and others)\n if (requestInfo.cancelToken) {\n try {\n if (typeof requestInfo.cancelToken === 'function') requestInfo.cancelToken();\n else if (requestInfo.cancelToken.cancel) requestInfo.cancelToken.cancel();\n } catch (error) {}\n }\n\n // Reject the wrapper promise\n this.#_deleteRequest(\n requestId,\n requestInfo.rejectWrapper,\n this.getOptions().verbose ? new Error(`Request ${requestId} was cancelled`) : null\n );\n return true;\n }\n\n /**\n * Link abort signal with HTTP client abort method.\n * Useful for custom HTTP clients that only support the abort method to cancel requests.\n * @param {Function} abortMethod - The abort method to call when the signal is aborted\n * @param {AbortSignal} signal - The signal to listen to\n */\n addAbortListener(abortMethod, signal) {\n if (!abortMethod || !signal) return;\n signal.addEventListener('abort', () => {\n if (typeof abortMethod === 'function') {\n try {\n abortMethod();\n } catch (error) {}\n }\n });\n }\n\n /**\n * Cancels all active requests.\n * @returns {number} The number of requests that were cancelled\n */\n cancelAll() {\n const requestIds = Array.from(this.activeRequests.keys());\n let cancelledCount = 0;\n requestIds.forEach((requestId) => {\n if (this.cancel(requestId)) cancelledCount++;\n });\n return cancelledCount;\n }\n\n /**\n * Resolves the AbortController for a request: explicit option, pending handoff, or new.\n * Clears the pending handoff so concurrent requests do not share it.\n * @param {AbortController|undefined} provided - Optional AbortController from options\n * @returns {AbortController}\n * @private\n */\n #_resolveAbortController(provided) {\n const abortController = provided || this.abortController || new AbortController();\n this.abortController = null;\n return abortController;\n }\n\n /**\n * Picks the best abort callback for a client request object.\n * @param {Object} req - The request object\n * @returns {Function|null}\n * @private\n */\n #_resolveAbortMethod(req) {\n if (!req) return null;\n if (typeof req.abort === 'function') return () => req.abort();\n const ExtAjax =\n typeof globalThis !== 'undefined' && globalThis.Ext && globalThis.Ext.Ajax ? globalThis.Ext.Ajax : null;\n if (req.xhr && ExtAjax && typeof ExtAjax.abort === 'function') {\n return () => ExtAjax.abort(req);\n }\n if (req.xhr && typeof req.xhr.abort === 'function') return () => req.xhr.abort();\n return null;\n }\n\n /**\n * Prepares request options by merging options and removing custom properties\n * @param {import('./index.d.ts').RequestOptions} options - Configuration options\n * @param {AbortSignal} signal - Abort signal to add to request options\n * @returns {Object} Prepared request options\n * @private\n */\n #_prepareRequestOptions(options, signal) {\n const requestOptions = {};\n const customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery'];\n Object.keys(options).forEach((key) => {\n if (customOptions.includes(key)) return;\n requestOptions[key] = options[key];\n });\n requestOptions.signal = signal;\n return requestOptions;\n }\n\n /**\n * Warns when the provided axios instance predates 0.22.0, the first version\n * supporting AbortSignal cancellation. Older instances silently ignore\n * options.signal, so duplicate requests would not be cancelled.\n * @param {object} axiosLib - The axios instance about to be used\n * @private\n */\n #_checkAxiosVersion(axiosLib) {\n const version = typeof axiosLib?.VERSION === 'string' ? axiosLib.VERSION : null;\n if (!version) return;\n const [major, minor] = version.split('.').map(Number);\n if (major === 0 && minor < 22) {\n console.warn(\n `[request-manager] axios >= 0.22.0 is required: axios ${version} ignores the AbortSignal used for automatic cancellation. Please upgrade axios.`\n );\n }\n }\n\n /**\n * Deletes a request from the active requests map and rejects the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} rejectWrapper - The function to reject the wrapper promise\n * @param {*} error - The error to reject the wrapper promise with; the wrapper is not rejected if null/undefined\n * @private\n */\n #_deleteRequest(requestId, rejectWrapper, error) {\n this.activeRequests.delete(requestId);\n if (error !== null && error !== undefined) {\n rejectWrapper(error);\n }\n }\n\n /**\n * Completes a request by deleting it from the active requests map and resolving the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} resolveWrapper - The function to resolve the wrapper promise\n * @param {Promise} requestPromise - The request promise\n * @param {boolean} isCancelled - Whether the request was cancelled\n * @private\n */\n #_completeRequest(requestId, resolveWrapper, requestPromise, isCancelled) {\n this.activeRequests.delete(requestId);\n if (!isCancelled) {\n resolveWrapper(requestPromise);\n }\n }\n\n /**\n * Internal method that handles the core request logic.\n * @param {string} requestId - Unique identifier for the request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise, function, or URL string\n * @param {import('./index.d.ts').BaseRequestOptions} options - Configuration options\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @private\n */\n #_request(requestId, requestPromise, options = {}) {\n const abortController = this.#_resolveAbortController(options.abortController);\n\n // Handle different types of requestPromise inputs\n // Priority: Function (Custom logic) > String (URL) > Promise (axios, fetch, etc.)\n if (typeof requestPromise === 'function') {\n // Function: custom logic for any library (axios, ajax, etc.)\n try {\n requestPromise = requestPromise({\n options: this.#_prepareRequestOptions(options, abortController.signal),\n });\n } catch (error) {\n return Promise.reject(error);\n }\n } else if (typeof requestPromise === 'string') {\n // String (URL): make fetch internally\n try {\n requestPromise = fetch(requestPromise, this.#_prepareRequestOptions(options, abortController.signal));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n // Link the request object's abort method (Ext.Ajax, XHR, etc.) to the cancellation signal\n this.addAbortListener(this.#_resolveAbortMethod(requestPromise), abortController.signal);\n\n // Cancel previous request with the same identifier if it exists\n if (!options.noCancel) this.cancel(requestId);\n\n // Create a wrapper promise that will be resolved/rejected based on the request\n let resolveWrapper, rejectWrapper;\n const wrapperPromise = new Promise((resolve, reject) => {\n resolveWrapper = resolve;\n rejectWrapper = reject;\n });\n\n /**\n * @type {import('./index.d.ts').ActiveRequest}\n */\n const requestInfo = {\n promise: requestPromise,\n abortController: abortController,\n cancelToken: options.cancelToken || null,\n resolveWrapper: resolveWrapper,\n rejectWrapper: rejectWrapper,\n isCancelled: false,\n };\n\n this.activeRequests.set(requestId, requestInfo);\n\n // Handle request promise completion\n if (requestPromise && typeof requestPromise.then === 'function') {\n try {\n let req = requestPromise.then((result) => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, result, requestInfo.isCancelled);\n });\n if (req.catch)\n req.catch((error) => {\n onError(this, error);\n });\n } catch (error) {\n onError(this, error);\n }\n function onError(scope, error) {\n // Check if this requestInfo is still the active one, or if it was cancelled\n if (scope.activeRequests.get(requestId) !== requestInfo) return;\n if (requestInfo.isCancelled) {\n // Already cancelled: let cancel() handle cleanup and reject the wrapper promise\n scope.cancel(requestId);\n return;\n }\n // Only delete if this is still the active request\n scope.#_deleteRequest(requestId, rejectWrapper, error);\n }\n } else {\n // Non-promise (Ext.Ajax request object, raw XHR, etc.). Keep tracked until the\n // underlying XHR finishes so a later duplicate can still cancel it.\n const xhr =\n requestPromise &&\n (requestPromise.xhr ||\n (typeof XMLHttpRequest !== 'undefined' && requestPromise instanceof XMLHttpRequest\n ? requestPromise\n : null));\n const finish = () => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, requestPromise, requestInfo.isCancelled);\n };\n if (xhr && typeof xhr.addEventListener === 'function') {\n xhr.addEventListener('loadend', finish);\n } else {\n setTimeout(finish, 0);\n }\n }\n return wrapperPromise;\n }\n}\n\nexport default RequestManager;\n\nexport { RequestManager };\n"],"names":["RequestManager","constructor","options","arguments","length","undefined","_classPrivateMethodInitSpec","_RequestManager_brand","activeRequests","Map","abortController","getOptions","setOptions","getSignal","getAbortController","signal","AbortController","isActive","requestId","has","getActiveCount","size","clear","request","url","requestPromise","_assertClassBrand","_request","call","getRequestId","fetch","axios","axiosInstance","axiosLib","_checkAxiosVersion","_ref","requestOptions","_objectSpread","ajax","ajaxFunction","Error","_ref2","xhr","xhrFunction","_ref3","fetchOptions","XMLHttpRequest","method","toUpperCase","xhrPromise","Promise","resolve","reject","onload","status","_xhr$getResponseHeade","response","responseType","getResponseHeader","includes","JSON","parse","_unused","data","statusText","headers","getAllResponseHeaders","message","concat","onerror","ontimeout","open","withCredentials","timeout","Object","keys","forEach","key","setRequestHeader","addEventListener","abort","send","body","requestKey","prefix","noCancel","Date","now","Math","random","toString","slice","_unused2","String","cleanedUrl","split","includeQuery","methodPrefix","includeMethod","type","cancel","requestInfo","get","isCancelled","aborted","error","cancelToken","_deleteRequest","rejectWrapper","verbose","addAbortListener","abortMethod","cancelAll","requestIds","Array","from","cancelledCount","_resolveAbortController","provided","_resolveAbortMethod","req","ExtAjax","globalThis","Ext","Ajax","_prepareRequestOptions","customOptions","version","VERSION","_version$split$map","map","Number","_version$split$map2","_slicedToArray","major","minor","console","warn","delete","_completeRequest","resolveWrapper","wrapperPromise","promise","set","then","result","catch","onError","scope","finish","setTimeout"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMA,cAAc,CAAC;EACjBC,EAAAA,WAAWA,GAAe;EAAA,IAAA,IAAdC,QAAO,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE;EAkZxB;EACJ;EACA;EACA;EACA;EACA;EACA;EANIG,IAAAA,2BAAA,OAAAC,qBAAA,CAAA;EAjZI;EACR;EACA;EACQ,IAAA,IAAI,CAACC,cAAc,GAAG,IAAIC,GAAG,EAAE;EAC/B;EACR;EACA;MACQ,IAAI,CAACP,OAAO,GAAGA,QAAO;EACtB;EACR;EACA;EACA;EACA;MACQ,IAAI,CAACQ,eAAe,GAAG,IAAI;EAC/B,EAAA;;EAEA;EACJ;EACA;EACA;EACIC,EAAAA,UAAUA,GAAG;MACT,OAAO,IAAI,CAACT,OAAO;EACvB,EAAA;;EAEA;EACJ;EACA;EACA;IACIU,UAAUA,CAACV,OAAO,EAAE;MAChB,IAAI,CAACA,OAAO,GAAGA,OAAO;EAC1B,EAAA;;EAEA;EACJ;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S,CAAC,KAAKmF,WAAW,EAAE;QACzD,IAAIA,WAAW,CAACE,WAAW,EAAE;EACzB;EACA6C,QAAAA,KAAK,CAAChD,MAAM,CAAClF,SAAS,CAAC;EACvB,QAAA;EACJ,MAAA;EACA;EACAQ,MAAAA,iBAAA,CAAAnB,qBAAA,EAAA6I,KAAK,EAACzC,cAAc,CAAC,CAAA/E,IAAA,CAArBwH,KAAK,EAAiBlI,SAAS,EAAE0F,aAAa,EAAEH,KAAK,CAAA;EACzD,IAAA;EACJ,EAAA,CAAC,MAAM;EACH;EACA;MACA,IAAM/D,GAAG,GACLjB,cAAc,KACbA,cAAc,CAACiB,GAAG,KACd,OAAOI,cAAc,KAAK,WAAW,IAAIrB,cAAc,YAAYqB,cAAc,GAC5ErB,cAAc,GACd,IAAI,CAAC,CAAC;MACpB,IAAM4H,MAAM,GAAGA,MAAM;QACjB,IAAI,IAAI,CAAC7I,cAAc,CAAC8F,GAAG,CAACpF,SAAS,CAAC,KAAKmF,WAAW,EAAE;EACxD3E,MAAAA,iBAAA,CAAAnB,qBAAA,EAAA,IAAI,EAACoI,gBAAgB,CAAC,CAAA/G,IAAA,CAAtB,IAAI,EAAmBV,SAAS,EAAE0H,cAAc,EAAEnH,cAAc,EAAE4E,WAAW,CAACE,WAAW,CAAA;MAC7F,CAAC;MACD,IAAI7D,GAAG,IAAI,OAAOA,GAAG,CAACqC,gBAAgB,KAAK,UAAU,EAAE;EACnDrC,MAAAA,GAAG,CAACqC,gBAAgB,CAAC,SAAS,EAAEsE,MAAM,CAAC;EAC3C,IAAA,CAAC,MAAM;EACHC,MAAAA,UAAU,CAACD,MAAM,EAAE,CAAC,CAAC;EACzB,IAAA;EACJ,EAAA;EACA,EAAA,OAAOR,cAAc;EACzB;;;;;;;;"}
1
+ {"version":3,"file":"request-manager.umd.js","sources":["../main.js"],"sourcesContent":["/**\n * RequestManager - A library for managing and regulating HTTP requests efficiently.\n * @license MIT\n * @author Eneko Galan <enekogalanelorza@gmail.com>\n * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)\n * by accepting Promises as parameters. When a request is repeated with the same identifier,\n * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.\n */\nclass RequestManager {\n constructor(options = {}) {\n /**\n * @type {Map<string, import('./index.d.ts').ActiveRequest>}\n */\n this.activeRequests = new Map();\n /**\n * @type {import('./index.d.ts').Options}\n */\n this.options = options;\n /**\n * One-shot AbortController for getSignal()/getAbortController() handoff.\n * Consumed by the next request that does not pass options.abortController.\n * @type {AbortController|null}\n */\n this.abortController = null;\n }\n\n /**\n * Gets the manager options\n * @returns {import('./index.d.ts').Options} Manager options\n */\n getOptions() {\n return this.options;\n }\n\n /**\n * Sets the manager options\n * @param {import('./index.d.ts').Options} options - The options to set\n */\n setOptions(options) {\n this.options = options;\n }\n\n /**\n * Creates a new AbortController and returns its signal for the next request()\n * (one getSignal → one request). Do not use for parallel requests; use fetch(),\n * axios(), or request(url, ({ options }) => ...) instead — they create their own signal.\n * @returns {AbortSignal} The signal from a new AbortController\n * @example\n * const signal = requestManager.getSignal();\n * requestManager.request('/api/users', fetch('/api/users', { signal }));\n */\n getSignal() {\n return this.getAbortController().signal;\n }\n\n /**\n * Creates a new AbortController for the next request handoff.\n * Always returns a fresh controller (never reuses one from another in-flight request).\n * @returns {AbortController} A new AbortController instance\n */\n getAbortController() {\n this.abortController = new AbortController();\n return this.abortController;\n }\n\n /**\n * Checks if a request with the given identifier is currently active.\n * @param {string} requestId - The unique identifier to check\n * @returns {boolean} True if the request is active, false otherwise\n */\n isActive(requestId) {\n return this.activeRequests.has(requestId);\n }\n\n /**\n * Gets the number of active requests.\n * @returns {number} The number of currently active requests\n */\n getActiveCount() {\n return this.activeRequests.size;\n }\n\n /**\n * Clears all active requests without cancelling them.\n * Use with caution - this will not cancel the underlying HTTP requests.\n */\n clear() {\n this.activeRequests.clear();\n }\n\n /**\n * Executes an HTTP request, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise or function that returns a promise\n * @param {import('./index.d.ts').RequestOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Request with Promise\n * requestManager.request('/api/users', axios.get('/api/users'));\n * @example\n * // Request with Function\n * requestManager.request('/api/users', ({ options }) => fetch('/api/users', { signal: options.signal, ...options }));\n * @example\n * // Request with Promise and custom cancellation grouping with requestKey\n * const options = {\n * requestKey: 'get-users'\n * }\n * requestManager.request('/api/users', axios.get('/api/users', options), options);\n */\n request(url, requestPromise, options = {}) {\n return this.#_request(this.getRequestId(url, options), requestPromise, options);\n }\n\n /**\n * Executes an HTTP request using fetch, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to fetch\n * @param {import('./index.d.ts').FetchOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.fetch('/api/users');\n * @example\n * // POST request with options\n * requestManager.fetch('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.fetch('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n fetch(url, options = {}) {\n return this.#_request(this.getRequestId(url, options), url, options);\n }\n\n /**\n * Executes an HTTP request using axios, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').AxiosRequestOptions} options - Optional configuration\n * @param {import('./index.d.ts').AxiosInstance|import('./index.d.ts').AxiosStatic|null} axiosInstance - Optional axios instance to use. If not provided, uses global axios.\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request (uses global axios)\n * requestManager.axios('/api/users');\n * @example\n * // With custom axios instance\n * const myAxios = axios.create({ baseURL: 'https://api.example.com' });\n * requestManager.axios('/users', {}, myAxios);\n * @example\n * // POST request with options\n * requestManager.axios('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.axios('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n axios(url, options = {}, axiosInstance = null) {\n const axiosLib = axiosInstance || (typeof axios !== 'undefined' ? axios : null);\n if (!axiosLib) {\n throw new Error(\n 'axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally'\n );\n }\n this.#_checkAxiosVersion(axiosLib);\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => axiosLib({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using jQuery.ajax, cancelling any previous request with the same identifier.\n * @param {import('./index.d.ts').AjaxFunction} ajaxFunction - A function that receives { url, ...options } and returns a Promise\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').BaseRequestOptions & Record<string, any>} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.ajax(ajaxFunction, '/api/users');\n * @example\n * // POST request with options\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * requestKey: 'get-users'\n * });\n */\n ajax(ajaxFunction, url, options = {}) {\n if (typeof ajaxFunction !== 'function') throw new Error('ajaxFunction parameter must be a function');\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => ajaxFunction({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using XMLHttpRequest, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').XhrOptions} options - Optional configuration\n * @returns {Promise<import('./index.d.ts').XhrResponse>} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.xhr('/api/users');\n * @example\n * // POST request with options\n * requestManager.xhr('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping\n * requestManager.xhr('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n xhr(url, options = {}) {\n /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */\n const xhrFunction = ({ options: fetchOptions }) => {\n // Create XMLHttpRequest\n const xhr = new XMLHttpRequest();\n const method = (options.method || 'GET').toUpperCase();\n // Create a promise that wraps the XHR request\n const xhrPromise = new Promise((resolve, reject) => {\n xhr.onload = function () {\n detachAbortListener();\n if (xhr.status >= 200 && xhr.status < 300) {\n let response = xhr.response;\n if (\n options.responseType === 'json' ||\n ((!options.responseType || options.responseType === 'text') &&\n xhr.getResponseHeader('Content-Type')?.includes('application/json') &&\n typeof response === 'string')\n ) {\n try {\n response = JSON.parse(response);\n } catch {}\n }\n resolve({\n data: response,\n status: xhr.status,\n statusText: xhr.statusText,\n headers: xhr.getAllResponseHeaders(),\n xhr: xhr,\n });\n } else {\n reject({\n message: `Request failed with status ${xhr.status}`,\n status: xhr.status,\n statusText: xhr.statusText,\n xhr: xhr,\n });\n }\n };\n xhr.onerror = function () {\n detachAbortListener();\n reject({\n message: 'Network error',\n xhr: xhr,\n });\n };\n xhr.ontimeout = function () {\n detachAbortListener();\n reject({\n message: 'Request timeout',\n xhr: xhr,\n });\n };\n\n // Open the request\n xhr.open(method, url, true);\n\n // Set response type\n if (options.responseType) xhr.responseType = options.responseType;\n // Set withCredentials\n if (options.withCredentials !== undefined) xhr.withCredentials = options.withCredentials;\n // Set timeout\n if (options.timeout !== undefined) xhr.timeout = options.timeout;\n // Set headers\n if (options.headers)\n Object.keys(options.headers).forEach((key) => {\n xhr.setRequestHeader(key, options.headers[key]);\n });\n\n // Connect abort signal to xhr.abort()\n const abortListener = () => xhr.abort();\n if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', abortListener);\n // Detach the listener once the request settles so completed requests do not keep it alive\n const detachAbortListener = () => {\n if (fetchOptions.signal) fetchOptions.signal.removeEventListener('abort', abortListener);\n };\n\n xhr.onabort = function () {\n reject({\n message: 'Request was cancelled',\n xhr: xhr,\n });\n };\n\n // Send the request\n xhr.send(options.body || null);\n });\n return xhrPromise;\n };\n return this.#_request(this.getRequestId(url, options), xhrFunction, options);\n }\n\n /**\n * Returns the request identifier for a URL and options.\n * @param {string} url - The URL used when starting the request\n * @param {import('./index.d.ts').BaseRequestOptions} options - Same options used for the request\n * @returns {string} The request identifier\n * @example\n * requestManager.fetch('/api/users');\n * const id = requestManager.getRequestId('/api/users');\n * requestManager.cancel(id);\n */\n getRequestId(url, options = {}) {\n let requestKey = options.requestKey;\n\n const prefix = 'request_';\n\n // Generate a unique identifier to prevent cancellation for non cancelable requests\n if (options.noCancel) {\n return `${prefix}${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n // Handle function requestKey\n if (typeof requestKey === 'function') {\n try {\n requestKey = requestKey();\n } catch {\n requestKey = null;\n }\n }\n if (requestKey !== null && requestKey !== undefined) return `${prefix}${String(requestKey)}`;\n\n // Use cleaned URL as key as fallback\n let cleanedUrl = url || '';\n if (cleanedUrl.includes('://')) cleanedUrl = cleanedUrl.split('://')[1];\n if (cleanedUrl.includes('#')) cleanedUrl = cleanedUrl.split('#')[0];\n if (!options.includeQuery && cleanedUrl.includes('?')) cleanedUrl = cleanedUrl.split('?')[0];\n\n const methodPrefix =\n options.includeMethod === false ? '' : `${(options.method || options.type || 'GET').toUpperCase()}_`;\n\n return `${prefix}${methodPrefix}${cleanedUrl}`;\n }\n\n /**\n * Cancels a specific request by its identifier.\n * @param {string} requestId - The unique identifier of the request to cancel\n * @returns {boolean} True if the request was found and cancelled, false otherwise\n */\n cancel(requestId) {\n /** @type {import('./index.d.ts').ActiveRequest|undefined} */\n const requestInfo = this.activeRequests.get(requestId);\n if (!requestInfo) return false;\n\n requestInfo.isCancelled = true; // Mark as cancelled\n\n // Try to abort using AbortController (for fetch)\n if (requestInfo.abortController && !requestInfo.abortController.signal.aborted) {\n try {\n requestInfo.abortController.abort('Request was cancelled');\n } catch (error) {}\n }\n\n // Try to cancel using cancel token/function (for axios and others)\n if (requestInfo.cancelToken) {\n try {\n if (typeof requestInfo.cancelToken === 'function') requestInfo.cancelToken();\n else if (requestInfo.cancelToken.cancel) requestInfo.cancelToken.cancel();\n } catch (error) {}\n }\n\n // Reject the wrapper promise\n this.#_deleteRequest(\n requestId,\n requestInfo.rejectWrapper,\n this.getOptions().verbose ? new Error(`Request ${requestId} was cancelled`) : null\n );\n return true;\n }\n\n /**\n * Link abort signal with HTTP client abort method.\n * Useful for custom HTTP clients that only support the abort method to cancel requests.\n * @param {Function} abortMethod - The abort method to call when the signal is aborted\n * @param {AbortSignal} signal - The signal to listen to\n */\n addAbortListener(abortMethod, signal) {\n if (!abortMethod || !signal) return;\n signal.addEventListener('abort', () => {\n if (typeof abortMethod === 'function') {\n try {\n abortMethod();\n } catch (error) {}\n }\n });\n }\n\n /**\n * Cancels all active requests.\n * @returns {number} The number of requests that were cancelled\n */\n cancelAll() {\n const requestIds = Array.from(this.activeRequests.keys());\n let cancelledCount = 0;\n requestIds.forEach((requestId) => {\n if (this.cancel(requestId)) cancelledCount++;\n });\n return cancelledCount;\n }\n\n /**\n * Resolves the AbortController for a request: explicit option, pending handoff, or new.\n * Clears the pending handoff so concurrent requests do not share it.\n * @param {AbortController|undefined} provided - Optional AbortController from options\n * @returns {AbortController}\n * @private\n */\n #_resolveAbortController(provided) {\n const abortController = provided || this.abortController || new AbortController();\n this.abortController = null;\n return abortController;\n }\n\n /**\n * Picks the best abort callback for a client request object.\n * @param {Object} req - The request object\n * @returns {Function|null}\n * @private\n */\n #_resolveAbortMethod(req) {\n if (!req) return null;\n if (typeof req.abort === 'function') return () => req.abort();\n const ExtAjax =\n typeof globalThis !== 'undefined' && globalThis.Ext && globalThis.Ext.Ajax ? globalThis.Ext.Ajax : null;\n if (req.xhr && ExtAjax && typeof ExtAjax.abort === 'function') {\n return () => ExtAjax.abort(req);\n }\n if (req.xhr && typeof req.xhr.abort === 'function') return () => req.xhr.abort();\n return null;\n }\n\n /**\n * Prepares request options by merging options and removing custom properties\n * @param {import('./index.d.ts').RequestOptions} options - Configuration options\n * @param {AbortSignal} signal - Abort signal to add to request options\n * @returns {Object} Prepared request options\n * @private\n */\n #_prepareRequestOptions(options, signal) {\n const requestOptions = {};\n const customOptions = [\n 'abortController',\n 'cancelToken',\n 'requestKey',\n 'noCancel',\n 'includeQuery',\n 'includeMethod',\n 'verbose',\n ];\n Object.keys(options).forEach((key) => {\n if (customOptions.includes(key)) return;\n requestOptions[key] = options[key];\n });\n requestOptions.signal = signal;\n return requestOptions;\n }\n\n /**\n * Warns when the provided axios instance predates 0.22.0, the first version\n * supporting AbortSignal cancellation. Older instances silently ignore\n * options.signal, so duplicate requests would not be cancelled.\n * @param {object} axiosLib - The axios instance about to be used\n * @private\n */\n #_checkAxiosVersion(axiosLib) {\n const version = typeof axiosLib?.VERSION === 'string' ? axiosLib.VERSION : null;\n if (!version) return;\n const [major, minor] = version.split('.').map(Number);\n if (major === 0 && minor < 22) {\n console.warn(\n `[request-manager] axios >= 0.22.0 is required: axios ${version} ignores the AbortSignal used for automatic cancellation. Please upgrade axios.`\n );\n }\n }\n\n /**\n * Deletes a request from the active requests map and rejects the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} rejectWrapper - The function to reject the wrapper promise\n * @param {*} error - The error to reject the wrapper promise with; the wrapper is not rejected if null/undefined\n * @private\n */\n #_deleteRequest(requestId, rejectWrapper, error) {\n this.activeRequests.delete(requestId);\n if (error !== null && error !== undefined) {\n rejectWrapper(error);\n }\n }\n\n /**\n * Completes a request by deleting it from the active requests map and resolving the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} resolveWrapper - The function to resolve the wrapper promise\n * @param {Promise} requestPromise - The request promise\n * @param {boolean} isCancelled - Whether the request was cancelled\n * @private\n */\n #_completeRequest(requestId, resolveWrapper, requestPromise, isCancelled) {\n this.activeRequests.delete(requestId);\n if (!isCancelled) {\n resolveWrapper(requestPromise);\n }\n }\n\n /**\n * Internal method that handles the core request logic.\n * @param {string} requestId - Unique identifier for the request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise, function, or URL string\n * @param {import('./index.d.ts').BaseRequestOptions} options - Configuration options\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @private\n */\n #_request(requestId, requestPromise, options = {}) {\n const abortController = this.#_resolveAbortController(options.abortController);\n\n // Handle different types of requestPromise inputs\n // Priority: Function (Custom logic) > String (URL) > Promise (axios, fetch, etc.)\n if (typeof requestPromise === 'function') {\n // Function: custom logic for any library (axios, ajax, etc.)\n try {\n requestPromise = requestPromise({\n options: this.#_prepareRequestOptions(options, abortController.signal),\n });\n } catch (error) {\n return Promise.reject(error);\n }\n } else if (typeof requestPromise === 'string') {\n // String (URL): make fetch internally\n try {\n requestPromise = fetch(requestPromise, this.#_prepareRequestOptions(options, abortController.signal));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n // Link the request object's abort method (Ext.Ajax, XHR, etc.) to the cancellation signal\n this.addAbortListener(this.#_resolveAbortMethod(requestPromise), abortController.signal);\n\n // Cancel previous request with the same identifier if it exists\n if (!options.noCancel) this.cancel(requestId);\n\n // Create a wrapper promise that will be resolved/rejected based on the request\n let resolveWrapper, rejectWrapper;\n const wrapperPromise = new Promise((resolve, reject) => {\n resolveWrapper = resolve;\n rejectWrapper = reject;\n });\n\n /**\n * @type {import('./index.d.ts').ActiveRequest}\n */\n const requestInfo = {\n promise: requestPromise,\n abortController: abortController,\n cancelToken: options.cancelToken || null,\n resolveWrapper: resolveWrapper,\n rejectWrapper: rejectWrapper,\n isCancelled: false,\n };\n\n this.activeRequests.set(requestId, requestInfo);\n\n // Handle request promise completion\n if (requestPromise && typeof requestPromise.then === 'function') {\n try {\n let req = requestPromise.then((result) => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, result, requestInfo.isCancelled);\n });\n if (req.catch)\n req.catch((error) => {\n onError(this, error);\n });\n } catch (error) {\n onError(this, error);\n }\n function onError(scope, error) {\n // Check if this requestInfo is still the active one, or if it was cancelled\n if (scope.activeRequests.get(requestId) !== requestInfo) return;\n if (requestInfo.isCancelled) {\n // Already cancelled: let cancel() handle cleanup and reject the wrapper promise\n scope.cancel(requestId);\n return;\n }\n // Only delete if this is still the active request\n scope.#_deleteRequest(requestId, rejectWrapper, error);\n }\n } else {\n // Non-promise (Ext.Ajax request object, raw XHR, etc.). Keep tracked until the\n // underlying XHR finishes so a later duplicate can still cancel it.\n const xhr =\n requestPromise &&\n (requestPromise.xhr ||\n (typeof XMLHttpRequest !== 'undefined' && requestPromise instanceof XMLHttpRequest\n ? requestPromise\n : null));\n const finish = () => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, requestPromise, requestInfo.isCancelled);\n };\n if (xhr && typeof xhr.addEventListener === 'function') {\n xhr.addEventListener('loadend', finish);\n } else {\n setTimeout(finish, 0);\n }\n }\n return wrapperPromise;\n }\n}\n\nexport default RequestManager;\n\nexport { RequestManager };\n"],"names":["RequestManager","constructor","options","arguments","length","undefined","_classPrivateMethodInitSpec","_RequestManager_brand","activeRequests","Map","abortController","getOptions","setOptions","getSignal","getAbortController","signal","AbortController","isActive","requestId","has","getActiveCount","size","clear","request","url","requestPromise","_assertClassBrand","_request","call","getRequestId","fetch","axios","axiosInstance","axiosLib","Error","_checkAxiosVersion","_ref","requestOptions","_objectSpread","ajax","ajaxFunction","_ref2","xhr","xhrFunction","_ref3","fetchOptions","XMLHttpRequest","method","toUpperCase","xhrPromise","Promise","resolve","reject","onload","detachAbortListener","status","_xhr$getResponseHeade","response","responseType","getResponseHeader","includes","JSON","parse","_unused","data","statusText","headers","getAllResponseHeaders","message","concat","onerror","ontimeout","open","withCredentials","timeout","Object","keys","forEach","key","setRequestHeader","abortListener","abort","addEventListener","removeEventListener","onabort","send","body","requestKey","prefix","noCancel","Date","now","Math","random","toString","slice","_unused2","String","cleanedUrl","split","includeQuery","methodPrefix","includeMethod","type","cancel","requestInfo","get","isCancelled","aborted","error","cancelToken","_deleteRequest","rejectWrapper","verbose","addAbortListener","abortMethod","cancelAll","requestIds","Array","from","cancelledCount","_resolveAbortController","provided","_resolveAbortMethod","req","ExtAjax","globalThis","Ext","Ajax","_prepareRequestOptions","customOptions","version","VERSION","_version$split$map","map","Number","_version$split$map2","_slicedToArray","major","minor","console","warn","delete","_completeRequest","resolveWrapper","wrapperPromise","promise","set","then","result","catch","onError","scope","finish","setTimeout"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMA,cAAc,CAAC;EACjBC,EAAAA,WAAWA,GAAe;EAAA,IAAA,IAAdC,QAAO,GAAAC,SAAA,CAAAC,MAAA,GAAA,CAAA,IAAAD,SAAA,CAAA,CAAA,CAAA,KAAAE,SAAA,GAAAF,SAAA,CAAA,CAAA,CAAA,GAAG,EAAE;EAqaxB;EACJ;EACA;EACA;EACA;EACA;EACA;EANIG,IAAAA,2BAAA,OAAAC,qBAAA,CAAA;EApaI;EACR;EACA;EACQ,IAAA,IAAI,CAACC,cAAc,GAAG,IAAIC,GAAG,EAAE;EAC/B;EACR;EACA;MACQ,IAAI,CAACP,OAAO,GAAGA,QAAO;EACtB;EACR;EACA;EACA;EACA;MACQ,IAAI,CAACQ,eAAe,GAAG,IAAI;EAC/B,EAAA;;EAEA;EACJ;EACA;EACA;EACIC,EAAAA,UAAUA,GAAG;MACT,OAAO,IAAI,CAACT,OAAO;EACvB,EAAA;;EAEA;EACJ;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AI,CAACjJ,cAAc,CAACkG,GAAG,CAACxF,SAAS,CAAC,KAAKuF,WAAW,EAAE;EACxD/E,MAAAA,iBAAA,CAAAnB,qBAAA,EAAA,IAAI,EAACwI,gBAAgB,CAAC,CAAAnH,IAAA,CAAtB,IAAI,EAAmBV,SAAS,EAAE8H,cAAc,EAAEvH,cAAc,EAAEgF,WAAW,CAACE,WAAW,CAAA;MAC7F,CAAC;MACD,IAAIjE,GAAG,IAAI,OAAOA,GAAG,CAACwC,gBAAgB,KAAK,UAAU,EAAE;EACnDxC,MAAAA,GAAG,CAACwC,gBAAgB,CAAC,SAAS,EAAEuE,MAAM,CAAC;EAC3C,IAAA,CAAC,MAAM;EACHC,MAAAA,UAAU,CAACD,MAAM,EAAE,CAAC,CAAC;EACzB,IAAA;EACJ,EAAA;EACA,EAAA,OAAOR,cAAc;EACzB;;;;;;;;"}
@@ -1,4 +1,4 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).RequestManager=e()}(this,function(){"use strict";function t(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function e(t,e,r){if("function"==typeof t?t===e:t.has(e))return arguments.length<3?e:r;throw new TypeError("Private element is not present on this object")}function r(t,e){(function(t,e){if(e.has(t))throw new TypeError("Cannot initialize the same private elements twice on an object")})(t,e),e.add(t)}function n(t,e,r){return(e=function(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var r=t[Symbol.toPrimitive];if(void 0!==r){var n=r.call(t,e);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===e?String:Number)(t)}(t,"string");return"symbol"==typeof e?e:e+""}(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function i(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach(function(e){n(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}function s(e,r){return function(t){if(Array.isArray(t))return t}(e)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,i,s,a=[],l=!0,c=!1;try{if(i=(r=r.call(t)).next,0===e);else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==e);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw o}}return a}}(e,r)||function(e,r){if(e){if("string"==typeof e)return t(e,r);var n={}.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?t(e,r):void 0}}(e,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var a=new WeakSet;
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).RequestManager=t()}(this,function(){"use strict";function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function t(e,t,r){if("function"==typeof e?e===t:e.has(t))return arguments.length<3?t:r;throw new TypeError("Private element is not present on this object")}function r(e,t){(function(e,t){if(t.has(e))throw new TypeError("Cannot initialize the same private elements twice on an object")})(e,t),t.add(e)}function n(e,t,r){return(t=function(e){var t=function(e,t){if("object"!=typeof e||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t);if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:t+""}(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function o(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function i(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?o(Object(r),!0).forEach(function(t){n(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function s(t,r){return function(e){if(Array.isArray(e))return e}(t)||function(e,t){var r=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=r){var n,o,i,s,a=[],l=!0,c=!1;try{if(i=(r=r.call(e)).next,0===t);else for(;!(l=(n=i.call(r)).done)&&(a.push(n.value),a.length!==t);l=!0);}catch(e){c=!0,o=e}finally{try{if(!l&&null!=r.return&&(s=r.return(),Object(s)!==s))return}finally{if(c)throw o}}return a}}(t,r)||function(t,r){if(t){if("string"==typeof t)return e(t,r);var n={}.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t,r)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var a=new WeakSet;
2
2
  /**
3
3
  * RequestManager - A library for managing and regulating HTTP requests efficiently.
4
4
  * @license MIT
@@ -6,5 +6,5 @@
6
6
  * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)
7
7
  * by accepting Promises as parameters. When a request is repeated with the same identifier,
8
8
  * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.
9
- */function l(t){var e=t||this.abortController||new AbortController;return this.abortController=null,e}function c(t){if(!t)return null;if("function"==typeof t.abort)return()=>t.abort();var e="undefined"!=typeof globalThis&&globalThis.Ext&&globalThis.Ext.Ajax?globalThis.Ext.Ajax:null;return t.xhr&&e&&"function"==typeof e.abort?()=>e.abort(t):t.xhr&&"function"==typeof t.xhr.abort?()=>t.xhr.abort():null}function u(t,e){var r={},n=["abortController","cancelToken","requestKey","noCancel","includeQuery"];return Object.keys(t).forEach(e=>{n.includes(e)||(r[e]=t[e])}),r.signal=e,r}function h(t){var e="string"==typeof(null==t?void 0:t.VERSION)?t.VERSION:null;if(e){var r=s(e.split(".").map(Number),2),n=r[0],o=r[1];0===n&&o<22&&console.warn("[request-manager] axios >= 0.22.0 is required: axios ".concat(e," ignores the AbortSignal used for automatic cancellation. Please upgrade axios."))}}function f(t,e,r){this.activeRequests.delete(t),null!=r&&e(r)}function p(t,e,r,n){this.activeRequests.delete(t),n||e(r)}function d(t,r){var n,o,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=e(a,this,l).call(this,i.abortController);if("function"==typeof r)try{r=r({options:e(a,this,u).call(this,i,s.signal)})}catch(g){return Promise.reject(g)}else if("string"==typeof r)try{r=fetch(r,e(a,this,u).call(this,i,s.signal))}catch(m){return Promise.reject(m)}this.addAbortListener(e(a,this,c).call(this,r),s.signal),i.noCancel||this.cancel(t);var h=new Promise((t,e)=>{n=t,o=e}),d={promise:r,abortController:s,cancelToken:i.cancelToken||null,resolveWrapper:n,rejectWrapper:o,isCancelled:!1};if(this.activeRequests.set(t,d),r&&"function"==typeof r.then){try{var v=r.then(r=>{this.activeRequests.get(t)===d&&e(a,this,p).call(this,t,n,r,d.isCancelled)});v.catch&&v.catch(t=>{w(this,t)})}catch(q){w(this,q)}function w(r,n){r.activeRequests.get(t)===d&&(d.isCancelled?r.cancel(t):e(a,r,f).call(r,t,o,n))}}else{var y=r&&(r.xhr||("undefined"!=typeof XMLHttpRequest&&r instanceof XMLHttpRequest?r:null)),b=()=>{this.activeRequests.get(t)===d&&e(a,this,p).call(this,t,n,r,d.isCancelled)};y&&"function"==typeof y.addEventListener?y.addEventListener("loadend",b):setTimeout(b,0)}return h}return class{constructor(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,a),this.activeRequests=new Map,this.options=t,this.abortController=null}getOptions(){return this.options}setOptions(t){this.options=t}getSignal(){return this.getAbortController().signal}getAbortController(){return this.abortController=new AbortController,this.abortController}isActive(t){return this.activeRequests.has(t)}getActiveCount(){return this.activeRequests.size}clear(){this.activeRequests.clear()}request(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return e(a,this,d).call(this,this.getRequestId(t,n),r,n)}fetch(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return e(a,this,d).call(this,this.getRequestId(t,r),t,r)}axios(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:null)||axios;return e(a,this,h).call(this,n),e(a,this,d).call(this,this.getRequestId(t,r),e=>{var r=e.options;return n(i({url:t},r))},r)}ajax(t,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("function"!=typeof t)throw new Error("ajaxFunction parameter must be a function");return e(a,this,d).call(this,this.getRequestId(r,n),e=>{var n=e.options;return t(i({url:r},n))},n)}xhr(t){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=this.getRequestId(t,r);return e(a,this,d).call(this,n,e=>{var n=e.options,o=new XMLHttpRequest,i=(r.method||"GET").toUpperCase();return new Promise((e,s)=>{o.onload=function(){if(o.status>=200&&o.status<300){var t,n=o.response;if("json"===r.responseType||(!r.responseType||"text"===r.responseType)&&null!==(t=o.getResponseHeader("Content-Type"))&&void 0!==t&&t.includes("application/json")&&"string"==typeof n)try{n=JSON.parse(n)}catch(t){}e({data:n,status:o.status,statusText:o.statusText,headers:o.getAllResponseHeaders(),xhr:o})}else s({message:"Request failed with status ".concat(o.status),status:o.status,statusText:o.statusText,xhr:o})},o.onerror=function(){s({message:"Network error",xhr:o})},o.ontimeout=function(){s({message:"Request timeout",xhr:o})},o.open(i,t,!0),r.responseType&&(o.responseType=r.responseType),void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),void 0!==r.timeout&&(o.timeout=r.timeout),r.headers&&Object.keys(r.headers).forEach(t=>{o.setRequestHeader(t,r.headers[t])}),n.signal&&n.signal.addEventListener("abort",()=>o.abort()),o.send(r.body||null)})},r)}getRequestId(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.requestKey,n="request_";if(e.noCancel)return"".concat(n).concat(Date.now(),"_").concat(Math.random().toString(36).slice(2,11));if("function"==typeof r)try{r=r()}catch(t){r=null}if(null!=r)return"".concat(n).concat(String(r));var o=t||"";o.includes("://")&&(o=o.split("://")[1]),o.includes("#")&&(o=o.split("#")[0]),!e.includeQuery&&o.includes("?")&&(o=o.split("?")[0]);var i=!1===e.includeMethod?"":"".concat((e.method||e.type||"GET").toUpperCase(),"_");return"".concat(n).concat(i).concat(o)}cancel(t){var r=this.activeRequests.get(t);if(!r)return!1;if(r.isCancelled=!0,r.abortController&&!r.abortController.signal.aborted)try{r.abortController.abort("Request was cancelled")}catch(t){}if(r.cancelToken)try{"function"==typeof r.cancelToken?r.cancelToken():r.cancelToken.cancel&&r.cancelToken.cancel()}catch(t){}return e(a,this,f).call(this,t,r.rejectWrapper,this.getOptions().verbose?new Error("Request ".concat(t," was cancelled")):null),!0}addAbortListener(t,e){t&&e&&e.addEventListener("abort",()=>{if("function"==typeof t)try{t()}catch(t){}})}cancelAll(){var t=Array.from(this.activeRequests.keys()),e=0;return t.forEach(t=>{this.cancel(t)&&e++}),e}}});
9
+ */function l(e){var t=e||this.abortController||new AbortController;return this.abortController=null,t}function c(e){if(!e)return null;if("function"==typeof e.abort)return()=>e.abort();var t="undefined"!=typeof globalThis&&globalThis.Ext&&globalThis.Ext.Ajax?globalThis.Ext.Ajax:null;return e.xhr&&t&&"function"==typeof t.abort?()=>t.abort(e):e.xhr&&"function"==typeof e.xhr.abort?()=>e.xhr.abort():null}function u(e,t){var r={},n=["abortController","cancelToken","requestKey","noCancel","includeQuery","includeMethod","verbose"];return Object.keys(e).forEach(t=>{n.includes(t)||(r[t]=e[t])}),r.signal=t,r}function h(e){var t="string"==typeof(null==e?void 0:e.VERSION)?e.VERSION:null;if(t){var r=s(t.split(".").map(Number),2),n=r[0],o=r[1];0===n&&o<22&&console.warn("[request-manager] axios >= 0.22.0 is required: axios ".concat(t," ignores the AbortSignal used for automatic cancellation. Please upgrade axios."))}}function f(e,t,r){this.activeRequests.delete(e),null!=r&&t(r)}function d(e,t,r,n){this.activeRequests.delete(e),n||t(r)}function p(e,r){var n,o,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=t(a,this,l).call(this,i.abortController);if("function"==typeof r)try{r=r({options:t(a,this,u).call(this,i,s.signal)})}catch(g){return Promise.reject(g)}else if("string"==typeof r)try{r=fetch(r,t(a,this,u).call(this,i,s.signal))}catch(m){return Promise.reject(m)}this.addAbortListener(t(a,this,c).call(this,r),s.signal),i.noCancel||this.cancel(e);var h=new Promise((e,t)=>{n=e,o=t}),p={promise:r,abortController:s,cancelToken:i.cancelToken||null,resolveWrapper:n,rejectWrapper:o,isCancelled:!1};if(this.activeRequests.set(e,p),r&&"function"==typeof r.then){try{var v=r.then(r=>{this.activeRequests.get(e)===p&&t(a,this,d).call(this,e,n,r,p.isCancelled)});v.catch&&v.catch(e=>{w(this,e)})}catch(x){w(this,x)}function w(r,n){r.activeRequests.get(e)===p&&(p.isCancelled?r.cancel(e):t(a,r,f).call(r,e,o,n))}}else{var y=r&&(r.xhr||("undefined"!=typeof XMLHttpRequest&&r instanceof XMLHttpRequest?r:null)),b=()=>{this.activeRequests.get(e)===p&&t(a,this,d).call(this,e,n,r,p.isCancelled)};y&&"function"==typeof y.addEventListener?y.addEventListener("loadend",b):setTimeout(b,0)}return h}return class{constructor(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};r(this,a),this.activeRequests=new Map,this.options=e,this.abortController=null}getOptions(){return this.options}setOptions(e){this.options=e}getSignal(){return this.getAbortController().signal}getAbortController(){return this.abortController=new AbortController,this.abortController}isActive(e){return this.activeRequests.has(e)}getActiveCount(){return this.activeRequests.size}clear(){this.activeRequests.clear()}request(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return t(a,this,p).call(this,this.getRequestId(e,n),r,n)}fetch(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t(a,this,p).call(this,this.getRequestId(e,r),e,r)}axios(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=(arguments.length>2&&void 0!==arguments[2]?arguments[2]:null)||("undefined"!=typeof axios?axios:null);if(!n)throw new Error("axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally");return t(a,this,h).call(this,n),t(a,this,p).call(this,this.getRequestId(e,r),t=>{var r=t.options;return n(i({url:e},r))},r)}ajax(e,r){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};if("function"!=typeof e)throw new Error("ajaxFunction parameter must be a function");return t(a,this,p).call(this,this.getRequestId(r,n),t=>{var n=t.options;return e(i({url:r},n))},n)}xhr(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return t(a,this,p).call(this,this.getRequestId(e,r),t=>{var n=t.options,o=new XMLHttpRequest,i=(r.method||"GET").toUpperCase();return new Promise((t,s)=>{o.onload=function(){if(l(),o.status>=200&&o.status<300){var e,n=o.response;if("json"===r.responseType||(!r.responseType||"text"===r.responseType)&&null!==(e=o.getResponseHeader("Content-Type"))&&void 0!==e&&e.includes("application/json")&&"string"==typeof n)try{n=JSON.parse(n)}catch(e){}t({data:n,status:o.status,statusText:o.statusText,headers:o.getAllResponseHeaders(),xhr:o})}else s({message:"Request failed with status ".concat(o.status),status:o.status,statusText:o.statusText,xhr:o})},o.onerror=function(){l(),s({message:"Network error",xhr:o})},o.ontimeout=function(){l(),s({message:"Request timeout",xhr:o})},o.open(i,e,!0),r.responseType&&(o.responseType=r.responseType),void 0!==r.withCredentials&&(o.withCredentials=r.withCredentials),void 0!==r.timeout&&(o.timeout=r.timeout),r.headers&&Object.keys(r.headers).forEach(e=>{o.setRequestHeader(e,r.headers[e])});var a=()=>o.abort();n.signal&&n.signal.addEventListener("abort",a);var l=()=>{n.signal&&n.signal.removeEventListener("abort",a)};o.onabort=function(){s({message:"Request was cancelled",xhr:o})},o.send(r.body||null)})},r)}getRequestId(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=t.requestKey,n="request_";if(t.noCancel)return"".concat(n).concat(Date.now(),"_").concat(Math.random().toString(36).slice(2,11));if("function"==typeof r)try{r=r()}catch(e){r=null}if(null!=r)return"".concat(n).concat(String(r));var o=e||"";o.includes("://")&&(o=o.split("://")[1]),o.includes("#")&&(o=o.split("#")[0]),!t.includeQuery&&o.includes("?")&&(o=o.split("?")[0]);var i=!1===t.includeMethod?"":"".concat((t.method||t.type||"GET").toUpperCase(),"_");return"".concat(n).concat(i).concat(o)}cancel(e){var r=this.activeRequests.get(e);if(!r)return!1;if(r.isCancelled=!0,r.abortController&&!r.abortController.signal.aborted)try{r.abortController.abort("Request was cancelled")}catch(e){}if(r.cancelToken)try{"function"==typeof r.cancelToken?r.cancelToken():r.cancelToken.cancel&&r.cancelToken.cancel()}catch(e){}return t(a,this,f).call(this,e,r.rejectWrapper,this.getOptions().verbose?new Error("Request ".concat(e," was cancelled")):null),!0}addAbortListener(e,t){e&&t&&t.addEventListener("abort",()=>{if("function"==typeof e)try{e()}catch(e){}})}cancelAll(){var e=Array.from(this.activeRequests.keys()),t=0;return e.forEach(e=>{this.cancel(e)&&t++}),t}}});
10
10
  //# sourceMappingURL=request-manager.umd.min.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"request-manager.umd.min.js","sources":["../main.js"],"sourcesContent":["/**\n * RequestManager - A library for managing and regulating HTTP requests efficiently.\n * @license MIT\n * @author Eneko Galan <enekogalanelorza@gmail.com>\n * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)\n * by accepting Promises as parameters. When a request is repeated with the same identifier,\n * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.\n */\nclass RequestManager {\n constructor(options = {}) {\n /**\n * @type {Map<string, import('./index.d.ts').ActiveRequest>}\n */\n this.activeRequests = new Map();\n /**\n * @type {import('./index.d.ts').Options}\n */\n this.options = options;\n /**\n * One-shot AbortController for getSignal()/getAbortController() handoff.\n * Consumed by the next request that does not pass options.abortController.\n * @type {AbortController|null}\n */\n this.abortController = null;\n }\n\n /**\n * Gets the manager options\n * @returns {import('./index.d.ts').Options} Manager options\n */\n getOptions() {\n return this.options;\n }\n\n /**\n * Sets the manager options\n * @param {import('./index.d.ts').Options} options - The options to set\n */\n setOptions(options) {\n this.options = options;\n }\n\n /**\n * Creates a new AbortController and returns its signal for the next request()\n * (one getSignal → one request). Do not use for parallel requests; use fetch(),\n * axios(), or request(url, ({ options }) => ...) instead — they create their own signal.\n * @returns {AbortSignal} The signal from a new AbortController\n * @example\n * const signal = requestManager.getSignal();\n * requestManager.request('/api/users', fetch('/api/users', { signal }));\n */\n getSignal() {\n return this.getAbortController().signal;\n }\n\n /**\n * Creates a new AbortController for the next request handoff.\n * Always returns a fresh controller (never reuses one from another in-flight request).\n * @returns {AbortController} A new AbortController instance\n */\n getAbortController() {\n this.abortController = new AbortController();\n return this.abortController;\n }\n\n /**\n * Checks if a request with the given identifier is currently active.\n * @param {string} requestId - The unique identifier to check\n * @returns {boolean} True if the request is active, false otherwise\n */\n isActive(requestId) {\n return this.activeRequests.has(requestId);\n }\n\n /**\n * Gets the number of active requests.\n * @returns {number} The number of currently active requests\n */\n getActiveCount() {\n return this.activeRequests.size;\n }\n\n /**\n * Clears all active requests without cancelling them.\n * Use with caution - this will not cancel the underlying HTTP requests.\n */\n clear() {\n this.activeRequests.clear();\n }\n\n /**\n * Executes an HTTP request, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise or function that returns a promise\n * @param {import('./index.d.ts').RequestOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Request with Promise\n * requestManager.request('/api/users', axios.get('/api/users'));\n * @example\n * // Request with Function\n * requestManager.request('/api/users', ({ options }) => fetch('/api/users', { signal: options.signal, ...options }));\n * @example\n * // Request with Promise and custom cancellation grouping with requestKey\n * const options = {\n * requestKey: 'get-users'\n * }\n * requestManager.request('/api/users', axios.get('/api/users', options), options);\n */\n request(url, requestPromise, options = {}) {\n return this.#_request(this.getRequestId(url, options), requestPromise, options);\n }\n\n /**\n * Executes an HTTP request using fetch, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to fetch\n * @param {import('./index.d.ts').FetchOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.fetch('/api/users');\n * @example\n * // POST request with options\n * requestManager.fetch('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.fetch('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n fetch(url, options = {}) {\n return this.#_request(this.getRequestId(url, options), url, options);\n }\n\n /**\n * Executes an HTTP request using axios, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').AxiosRequestOptions} options - Optional configuration\n * @param {import('./index.d.ts').AxiosInstance|import('./index.d.ts').AxiosStatic|null} axiosInstance - Optional axios instance to use. If not provided, uses global axios.\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request (uses global axios)\n * requestManager.axios('/api/users');\n * @example\n * // With custom axios instance\n * const myAxios = axios.create({ baseURL: 'https://api.example.com' });\n * requestManager.axios('/users', {}, myAxios);\n * @example\n * // POST request with options\n * requestManager.axios('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.axios('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n axios(url, options = {}, axiosInstance = null) {\n const axiosLib = axiosInstance || axios;\n this.#_checkAxiosVersion(axiosLib);\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => axiosLib({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using jQuery.ajax, cancelling any previous request with the same identifier.\n * @param {import('./index.d.ts').AjaxFunction} ajaxFunction - A function that receives { url, ...options } and returns a Promise\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').BaseRequestOptions & Record<string, any>} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.ajax(ajaxFunction, '/api/users');\n * @example\n * // POST request with options\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * requestKey: 'get-users'\n * });\n */\n ajax(ajaxFunction, url, options = {}) {\n if (typeof ajaxFunction !== 'function') throw new Error('ajaxFunction parameter must be a function');\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => ajaxFunction({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using XMLHttpRequest, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').XhrOptions} options - Optional configuration\n * @returns {Promise<import('./index.d.ts').XhrResponse>} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.xhr('/api/users');\n * @example\n * // POST request with options\n * requestManager.xhr('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping\n * requestManager.xhr('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n xhr(url, options = {}) {\n const requestId = this.getRequestId(url, options);\n /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */\n const xhrFunction = ({ options: fetchOptions }) => {\n // Create XMLHttpRequest\n const xhr = new XMLHttpRequest();\n const method = (options.method || 'GET').toUpperCase();\n // Create a promise that wraps the XHR request\n const xhrPromise = new Promise((resolve, reject) => {\n xhr.onload = function () {\n if (xhr.status >= 200 && xhr.status < 300) {\n let response = xhr.response;\n if (\n options.responseType === 'json' ||\n ((!options.responseType || options.responseType === 'text') &&\n xhr.getResponseHeader('Content-Type')?.includes('application/json') &&\n typeof response === 'string')\n ) {\n try {\n response = JSON.parse(response);\n } catch {}\n }\n resolve({\n data: response,\n status: xhr.status,\n statusText: xhr.statusText,\n headers: xhr.getAllResponseHeaders(),\n xhr: xhr,\n });\n } else {\n reject({\n message: `Request failed with status ${xhr.status}`,\n status: xhr.status,\n statusText: xhr.statusText,\n xhr: xhr,\n });\n }\n };\n xhr.onerror = function () {\n reject({\n message: 'Network error',\n xhr: xhr,\n });\n };\n xhr.ontimeout = function () {\n reject({\n message: 'Request timeout',\n xhr: xhr,\n });\n };\n\n // Open the request\n xhr.open(method, url, true);\n\n // Set response type\n if (options.responseType) xhr.responseType = options.responseType;\n // Set withCredentials\n if (options.withCredentials !== undefined) xhr.withCredentials = options.withCredentials;\n // Set timeout\n if (options.timeout !== undefined) xhr.timeout = options.timeout;\n // Set headers\n if (options.headers)\n Object.keys(options.headers).forEach((key) => {\n xhr.setRequestHeader(key, options.headers[key]);\n });\n\n // Connect abort signal to xhr.abort()\n if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', () => xhr.abort());\n\n // Send the request\n xhr.send(options.body || null);\n });\n return xhrPromise;\n };\n return this.#_request(requestId, xhrFunction, options);\n }\n\n /**\n * Returns the request identifier for a URL and options.\n * @param {string} url - The URL used when starting the request\n * @param {import('./index.d.ts').BaseRequestOptions} options - Same options used for the request\n * @returns {string} The request identifier\n * @example\n * requestManager.fetch('/api/users');\n * const id = requestManager.getRequestId('/api/users');\n * requestManager.cancel(id);\n */\n getRequestId(url, options = {}) {\n let requestKey = options.requestKey;\n\n const prefix = 'request_';\n\n // Generate a unique identifier to prevent cancellation for non cancelable requests\n if (options.noCancel) {\n return `${prefix}${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n // Handle function requestKey\n if (typeof requestKey === 'function') {\n try {\n requestKey = requestKey();\n } catch {\n requestKey = null;\n }\n }\n if (requestKey !== null && requestKey !== undefined) return `${prefix}${String(requestKey)}`;\n\n // Use cleaned URL as key as fallback\n let cleanedUrl = url || '';\n if (cleanedUrl.includes('://')) cleanedUrl = cleanedUrl.split('://')[1];\n if (cleanedUrl.includes('#')) cleanedUrl = cleanedUrl.split('#')[0];\n if (!options.includeQuery && cleanedUrl.includes('?')) cleanedUrl = cleanedUrl.split('?')[0];\n\n const methodPrefix =\n options.includeMethod === false ? '' : `${(options.method || options.type || 'GET').toUpperCase()}_`;\n\n return `${prefix}${methodPrefix}${cleanedUrl}`;\n }\n\n /**\n * Cancels a specific request by its identifier.\n * @param {string} requestId - The unique identifier of the request to cancel\n * @returns {boolean} True if the request was found and cancelled, false otherwise\n */\n cancel(requestId) {\n /** @type {import('./index.d.ts').ActiveRequest|undefined} */\n const requestInfo = this.activeRequests.get(requestId);\n if (!requestInfo) return false;\n\n requestInfo.isCancelled = true; // Mark as cancelled\n\n // Try to abort using AbortController (for fetch)\n if (requestInfo.abortController && !requestInfo.abortController.signal.aborted) {\n try {\n requestInfo.abortController.abort('Request was cancelled');\n } catch (error) {}\n }\n\n // Try to cancel using cancel token/function (for axios and others)\n if (requestInfo.cancelToken) {\n try {\n if (typeof requestInfo.cancelToken === 'function') requestInfo.cancelToken();\n else if (requestInfo.cancelToken.cancel) requestInfo.cancelToken.cancel();\n } catch (error) {}\n }\n\n // Reject the wrapper promise\n this.#_deleteRequest(\n requestId,\n requestInfo.rejectWrapper,\n this.getOptions().verbose ? new Error(`Request ${requestId} was cancelled`) : null\n );\n return true;\n }\n\n /**\n * Link abort signal with HTTP client abort method.\n * Useful for custom HTTP clients that only support the abort method to cancel requests.\n * @param {Function} abortMethod - The abort method to call when the signal is aborted\n * @param {AbortSignal} signal - The signal to listen to\n */\n addAbortListener(abortMethod, signal) {\n if (!abortMethod || !signal) return;\n signal.addEventListener('abort', () => {\n if (typeof abortMethod === 'function') {\n try {\n abortMethod();\n } catch (error) {}\n }\n });\n }\n\n /**\n * Cancels all active requests.\n * @returns {number} The number of requests that were cancelled\n */\n cancelAll() {\n const requestIds = Array.from(this.activeRequests.keys());\n let cancelledCount = 0;\n requestIds.forEach((requestId) => {\n if (this.cancel(requestId)) cancelledCount++;\n });\n return cancelledCount;\n }\n\n /**\n * Resolves the AbortController for a request: explicit option, pending handoff, or new.\n * Clears the pending handoff so concurrent requests do not share it.\n * @param {AbortController|undefined} provided - Optional AbortController from options\n * @returns {AbortController}\n * @private\n */\n #_resolveAbortController(provided) {\n const abortController = provided || this.abortController || new AbortController();\n this.abortController = null;\n return abortController;\n }\n\n /**\n * Picks the best abort callback for a client request object.\n * @param {Object} req - The request object\n * @returns {Function|null}\n * @private\n */\n #_resolveAbortMethod(req) {\n if (!req) return null;\n if (typeof req.abort === 'function') return () => req.abort();\n const ExtAjax =\n typeof globalThis !== 'undefined' && globalThis.Ext && globalThis.Ext.Ajax ? globalThis.Ext.Ajax : null;\n if (req.xhr && ExtAjax && typeof ExtAjax.abort === 'function') {\n return () => ExtAjax.abort(req);\n }\n if (req.xhr && typeof req.xhr.abort === 'function') return () => req.xhr.abort();\n return null;\n }\n\n /**\n * Prepares request options by merging options and removing custom properties\n * @param {import('./index.d.ts').RequestOptions} options - Configuration options\n * @param {AbortSignal} signal - Abort signal to add to request options\n * @returns {Object} Prepared request options\n * @private\n */\n #_prepareRequestOptions(options, signal) {\n const requestOptions = {};\n const customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery'];\n Object.keys(options).forEach((key) => {\n if (customOptions.includes(key)) return;\n requestOptions[key] = options[key];\n });\n requestOptions.signal = signal;\n return requestOptions;\n }\n\n /**\n * Warns when the provided axios instance predates 0.22.0, the first version\n * supporting AbortSignal cancellation. Older instances silently ignore\n * options.signal, so duplicate requests would not be cancelled.\n * @param {object} axiosLib - The axios instance about to be used\n * @private\n */\n #_checkAxiosVersion(axiosLib) {\n const version = typeof axiosLib?.VERSION === 'string' ? axiosLib.VERSION : null;\n if (!version) return;\n const [major, minor] = version.split('.').map(Number);\n if (major === 0 && minor < 22) {\n console.warn(\n `[request-manager] axios >= 0.22.0 is required: axios ${version} ignores the AbortSignal used for automatic cancellation. Please upgrade axios.`\n );\n }\n }\n\n /**\n * Deletes a request from the active requests map and rejects the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} rejectWrapper - The function to reject the wrapper promise\n * @param {*} error - The error to reject the wrapper promise with; the wrapper is not rejected if null/undefined\n * @private\n */\n #_deleteRequest(requestId, rejectWrapper, error) {\n this.activeRequests.delete(requestId);\n if (error !== null && error !== undefined) {\n rejectWrapper(error);\n }\n }\n\n /**\n * Completes a request by deleting it from the active requests map and resolving the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} resolveWrapper - The function to resolve the wrapper promise\n * @param {Promise} requestPromise - The request promise\n * @param {boolean} isCancelled - Whether the request was cancelled\n * @private\n */\n #_completeRequest(requestId, resolveWrapper, requestPromise, isCancelled) {\n this.activeRequests.delete(requestId);\n if (!isCancelled) {\n resolveWrapper(requestPromise);\n }\n }\n\n /**\n * Internal method that handles the core request logic.\n * @param {string} requestId - Unique identifier for the request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise, function, or URL string\n * @param {import('./index.d.ts').BaseRequestOptions} options - Configuration options\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @private\n */\n #_request(requestId, requestPromise, options = {}) {\n const abortController = this.#_resolveAbortController(options.abortController);\n\n // Handle different types of requestPromise inputs\n // Priority: Function (Custom logic) > String (URL) > Promise (axios, fetch, etc.)\n if (typeof requestPromise === 'function') {\n // Function: custom logic for any library (axios, ajax, etc.)\n try {\n requestPromise = requestPromise({\n options: this.#_prepareRequestOptions(options, abortController.signal),\n });\n } catch (error) {\n return Promise.reject(error);\n }\n } else if (typeof requestPromise === 'string') {\n // String (URL): make fetch internally\n try {\n requestPromise = fetch(requestPromise, this.#_prepareRequestOptions(options, abortController.signal));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n // Link the request object's abort method (Ext.Ajax, XHR, etc.) to the cancellation signal\n this.addAbortListener(this.#_resolveAbortMethod(requestPromise), abortController.signal);\n\n // Cancel previous request with the same identifier if it exists\n if (!options.noCancel) this.cancel(requestId);\n\n // Create a wrapper promise that will be resolved/rejected based on the request\n let resolveWrapper, rejectWrapper;\n const wrapperPromise = new Promise((resolve, reject) => {\n resolveWrapper = resolve;\n rejectWrapper = reject;\n });\n\n /**\n * @type {import('./index.d.ts').ActiveRequest}\n */\n const requestInfo = {\n promise: requestPromise,\n abortController: abortController,\n cancelToken: options.cancelToken || null,\n resolveWrapper: resolveWrapper,\n rejectWrapper: rejectWrapper,\n isCancelled: false,\n };\n\n this.activeRequests.set(requestId, requestInfo);\n\n // Handle request promise completion\n if (requestPromise && typeof requestPromise.then === 'function') {\n try {\n let req = requestPromise.then((result) => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, result, requestInfo.isCancelled);\n });\n if (req.catch)\n req.catch((error) => {\n onError(this, error);\n });\n } catch (error) {\n onError(this, error);\n }\n function onError(scope, error) {\n // Check if this requestInfo is still the active one, or if it was cancelled\n if (scope.activeRequests.get(requestId) !== requestInfo) return;\n if (requestInfo.isCancelled) {\n // Already cancelled: let cancel() handle cleanup and reject the wrapper promise\n scope.cancel(requestId);\n return;\n }\n // Only delete if this is still the active request\n scope.#_deleteRequest(requestId, rejectWrapper, error);\n }\n } else {\n // Non-promise (Ext.Ajax request object, raw XHR, etc.). Keep tracked until the\n // underlying XHR finishes so a later duplicate can still cancel it.\n const xhr =\n requestPromise &&\n (requestPromise.xhr ||\n (typeof XMLHttpRequest !== 'undefined' && requestPromise instanceof XMLHttpRequest\n ? requestPromise\n : null));\n const finish = () => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, requestPromise, requestInfo.isCancelled);\n };\n if (xhr && typeof xhr.addEventListener === 'function') {\n xhr.addEventListener('loadend', finish);\n } else {\n setTimeout(finish, 0);\n }\n }\n return wrapperPromise;\n }\n}\n\nexport default RequestManager;\n\nexport { RequestManager };\n"],"names":["_resolveAbortController","provided","abortController","this","AbortController","_resolveAbortMethod","req","abort","ExtAjax","globalThis","Ext","Ajax","xhr","_prepareRequestOptions","options","signal","requestOptions","customOptions","Object","keys","forEach","key","includes","_checkAxiosVersion","axiosLib","version","VERSION","_version$split$map2","_slicedToArray","split","map","Number","major","minor","console","warn","concat","_deleteRequest","requestId","rejectWrapper","error","activeRequests","delete","_completeRequest","resolveWrapper","requestPromise","isCancelled","_request","arguments","length","undefined","_assertClassBrand","_RequestManager_brand","call","Promise","reject","fetch","addAbortListener","noCancel","cancel","wrapperPromise","resolve","requestInfo","promise","cancelToken","set","then","result","get","catch","onError","scope","XMLHttpRequest","finish","addEventListener","setTimeout","constructor","_classPrivateMethodInitSpec","Map","getOptions","setOptions","getSignal","getAbortController","isActive","has","getActiveCount","size","clear","request","url","getRequestId","axios","_ref","_objectSpread","ajax","ajaxFunction","Error","_ref2","_ref3","fetchOptions","method","toUpperCase","onload","status","_xhr$getResponseHeade","response","responseType","getResponseHeader","JSON","parse","_unused","data","statusText","headers","getAllResponseHeaders","message","onerror","ontimeout","open","withCredentials","timeout","setRequestHeader","send","body","requestKey","prefix","Date","now","Math","random","toString","slice","_unused2","String","cleanedUrl","includeQuery","methodPrefix","includeMethod","type","aborted","verbose","abortMethod","cancelAll","requestIds","Array","from","cancelledCount"],"mappings":";;;;;;;;KAmmBC,SAAAA,EAjM4BC,GACrB,IAAMC,EAAkBD,GAAYE,KAAKD,iBAAmB,IAAIE,gBAEhE,OADAD,KAAKD,gBAAkB,KAChBA,CACX,CAEA,SAAAG,EAMqBC,GACjB,IAAKA,EAAK,OAAO,KACjB,GAAyB,mBAAdA,EAAIC,MAAsB,MAAO,IAAMD,EAAIC,QACtD,IAAMC,EACoB,oBAAfC,YAA8BA,WAAWC,KAAOD,WAAWC,IAAIC,KAAOF,WAAWC,IAAIC,KAAO,KACvG,OAAIL,EAAIM,KAAOJ,GAAoC,mBAAlBA,EAAQD,MAC9B,IAAMC,EAAQD,MAAMD,GAE3BA,EAAIM,KAAgC,mBAAlBN,EAAIM,IAAIL,MAA6B,IAAMD,EAAIM,IAAIL,QAClE,IACX,CAEA,SAAAM,EAOwBC,EAASC,GAC7B,IAAMC,EAAiB,CAAA,EACjBC,EAAgB,CAAC,kBAAmB,cAAe,aAAc,WAAY,gBAMnF,OALAC,OAAOC,KAAKL,GAASM,QAASC,IACtBJ,EAAcK,SAASD,KAC3BL,EAAeK,GAAOP,EAAQO,MAElCL,EAAeD,OAASA,EACjBC,CACX,CAEA,SAAAO,EAOoBC,GAChB,IAAMC,EAAuC,iBAAtBD,eAAAA,EAAUE,SAAuBF,EAASE,QAAU,KAC3E,GAAKD,EAAL,CACA,IAAqDE,EAAAC,EAA9BH,EAAQI,MAAM,KAAKC,IAAIC,QAAO,GAA9CC,EAAKL,EAAA,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G,GACwB,IAA1B1H,EAAQ2H,cAA0B,GAAE,GAAArG,QAAOtB,EAAQsF,QAAUtF,EAAQ4H,MAAQ,OAAOrC,cAAa,KAErG,MAAA,GAAAjE,OAAUyF,GAAMzF,OAAGoG,GAAYpG,OAAGkG,EACtC,CAOA3E,MAAAA,CAAOrB,GAEH,IAAMwB,EAAc3D,KAAKsC,eAAe2B,IAAI9B,GAC5C,IAAKwB,EAAa,OAAO,EAKzB,GAHAA,EAAYhB,aAAc,EAGtBgB,EAAY5D,kBAAoB4D,EAAY5D,gBAAgBa,OAAO4H,QACnE,IACI7E,EAAY5D,gBAAgBK,MAAM,wBACtC,CAAE,MAAOiC,GAAQ,CAIrB,GAAIsB,EAAYE,YACZ,IAC2C,mBAA5BF,EAAYE,YAA4BF,EAAYE,cACtDF,EAAYE,YAAYL,QAAQG,EAAYE,YAAYL,QACrE,CAAE,MAAOnB,GAAQ,CASrB,OALAW,EAAAC,EAAAjD,KAAKkC,GAAegB,KAApBlD,KACImC,EACAwB,EAAYvB,cACZpC,KAAK4E,aAAa6D,QAAU,IAAI5C,MAAK,WAAA5D,OAAYE,EAAS,mBAAoB,OAE3E,CACX,CAQAmB,gBAAAA,CAAiBoF,EAAa9H,GACrB8H,GAAgB9H,GACrBA,EAAO2D,iBAAiB,QAAS,KAC7B,GAA2B,mBAAhBmE,EACP,IACIA,GACJ,CAAE,MAAOrG,GAAQ,GAG7B,CAMAsG,SAAAA,GACI,IAAMC,EAAaC,MAAMC,KAAK9I,KAAKsC,eAAetB,QAC9C+H,EAAiB,EAIrB,OAHAH,EAAW3H,QAASkB,IACZnC,KAAKwD,OAAOrB,IAAY4G,MAEzBA,CACX"}
1
+ {"version":3,"file":"request-manager.umd.min.js","sources":["../main.js"],"sourcesContent":["/**\n * RequestManager - A library for managing and regulating HTTP requests efficiently.\n * @license MIT\n * @author Eneko Galan <enekogalanelorza@gmail.com>\n * This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)\n * by accepting Promises as parameters. When a request is repeated with the same identifier,\n * the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.\n */\nclass RequestManager {\n constructor(options = {}) {\n /**\n * @type {Map<string, import('./index.d.ts').ActiveRequest>}\n */\n this.activeRequests = new Map();\n /**\n * @type {import('./index.d.ts').Options}\n */\n this.options = options;\n /**\n * One-shot AbortController for getSignal()/getAbortController() handoff.\n * Consumed by the next request that does not pass options.abortController.\n * @type {AbortController|null}\n */\n this.abortController = null;\n }\n\n /**\n * Gets the manager options\n * @returns {import('./index.d.ts').Options} Manager options\n */\n getOptions() {\n return this.options;\n }\n\n /**\n * Sets the manager options\n * @param {import('./index.d.ts').Options} options - The options to set\n */\n setOptions(options) {\n this.options = options;\n }\n\n /**\n * Creates a new AbortController and returns its signal for the next request()\n * (one getSignal → one request). Do not use for parallel requests; use fetch(),\n * axios(), or request(url, ({ options }) => ...) instead — they create their own signal.\n * @returns {AbortSignal} The signal from a new AbortController\n * @example\n * const signal = requestManager.getSignal();\n * requestManager.request('/api/users', fetch('/api/users', { signal }));\n */\n getSignal() {\n return this.getAbortController().signal;\n }\n\n /**\n * Creates a new AbortController for the next request handoff.\n * Always returns a fresh controller (never reuses one from another in-flight request).\n * @returns {AbortController} A new AbortController instance\n */\n getAbortController() {\n this.abortController = new AbortController();\n return this.abortController;\n }\n\n /**\n * Checks if a request with the given identifier is currently active.\n * @param {string} requestId - The unique identifier to check\n * @returns {boolean} True if the request is active, false otherwise\n */\n isActive(requestId) {\n return this.activeRequests.has(requestId);\n }\n\n /**\n * Gets the number of active requests.\n * @returns {number} The number of currently active requests\n */\n getActiveCount() {\n return this.activeRequests.size;\n }\n\n /**\n * Clears all active requests without cancelling them.\n * Use with caution - this will not cancel the underlying HTTP requests.\n */\n clear() {\n this.activeRequests.clear();\n }\n\n /**\n * Executes an HTTP request, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise or function that returns a promise\n * @param {import('./index.d.ts').RequestOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Request with Promise\n * requestManager.request('/api/users', axios.get('/api/users'));\n * @example\n * // Request with Function\n * requestManager.request('/api/users', ({ options }) => fetch('/api/users', { signal: options.signal, ...options }));\n * @example\n * // Request with Promise and custom cancellation grouping with requestKey\n * const options = {\n * requestKey: 'get-users'\n * }\n * requestManager.request('/api/users', axios.get('/api/users', options), options);\n */\n request(url, requestPromise, options = {}) {\n return this.#_request(this.getRequestId(url, options), requestPromise, options);\n }\n\n /**\n * Executes an HTTP request using fetch, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to fetch\n * @param {import('./index.d.ts').FetchOptions} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.fetch('/api/users');\n * @example\n * // POST request with options\n * requestManager.fetch('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.fetch('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n fetch(url, options = {}) {\n return this.#_request(this.getRequestId(url, options), url, options);\n }\n\n /**\n * Executes an HTTP request using axios, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').AxiosRequestOptions} options - Optional configuration\n * @param {import('./index.d.ts').AxiosInstance|import('./index.d.ts').AxiosStatic|null} axiosInstance - Optional axios instance to use. If not provided, uses global axios.\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request (uses global axios)\n * requestManager.axios('/api/users');\n * @example\n * // With custom axios instance\n * const myAxios = axios.create({ baseURL: 'https://api.example.com' });\n * requestManager.axios('/users', {}, myAxios);\n * @example\n * // POST request with options\n * requestManager.axios('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.axios('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n axios(url, options = {}, axiosInstance = null) {\n const axiosLib = axiosInstance || (typeof axios !== 'undefined' ? axios : null);\n if (!axiosLib) {\n throw new Error(\n 'axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally'\n );\n }\n this.#_checkAxiosVersion(axiosLib);\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => axiosLib({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using jQuery.ajax, cancelling any previous request with the same identifier.\n * @param {import('./index.d.ts').AjaxFunction} ajaxFunction - A function that receives { url, ...options } and returns a Promise\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').BaseRequestOptions & Record<string, any>} options - Optional configuration\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.ajax(ajaxFunction, '/api/users');\n * @example\n * // POST request with options\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping with requestKey\n * requestManager.ajax(ajaxFunction, '/api/users', {\n * requestKey: 'get-users'\n * });\n */\n ajax(ajaxFunction, url, options = {}) {\n if (typeof ajaxFunction !== 'function') throw new Error('ajaxFunction parameter must be a function');\n return this.#_request(\n this.getRequestId(url, options),\n ({ options: requestOptions }) => ajaxFunction({ url, ...requestOptions }),\n options\n );\n }\n\n /**\n * Executes an HTTP request using XMLHttpRequest, cancelling any previous request with the same identifier.\n * @param {string} url - The URL to request\n * @param {import('./index.d.ts').XhrOptions} options - Optional configuration\n * @returns {Promise<import('./index.d.ts').XhrResponse>} A Promise that resolves/rejects based on the most recent request\n * @example\n * // Simple GET request\n * requestManager.xhr('/api/users');\n * @example\n * // POST request with options\n * requestManager.xhr('/api/users', {\n * method: 'POST',\n * headers: { 'Content-Type': 'application/json' },\n * body: JSON.stringify({ name: 'John' })\n * });\n * @example\n * // Request with requestKey for custom cancellation grouping\n * requestManager.xhr('/api/users', {\n * requestKey: 'get-users'\n * });\n */\n xhr(url, options = {}) {\n /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */\n const xhrFunction = ({ options: fetchOptions }) => {\n // Create XMLHttpRequest\n const xhr = new XMLHttpRequest();\n const method = (options.method || 'GET').toUpperCase();\n // Create a promise that wraps the XHR request\n const xhrPromise = new Promise((resolve, reject) => {\n xhr.onload = function () {\n detachAbortListener();\n if (xhr.status >= 200 && xhr.status < 300) {\n let response = xhr.response;\n if (\n options.responseType === 'json' ||\n ((!options.responseType || options.responseType === 'text') &&\n xhr.getResponseHeader('Content-Type')?.includes('application/json') &&\n typeof response === 'string')\n ) {\n try {\n response = JSON.parse(response);\n } catch {}\n }\n resolve({\n data: response,\n status: xhr.status,\n statusText: xhr.statusText,\n headers: xhr.getAllResponseHeaders(),\n xhr: xhr,\n });\n } else {\n reject({\n message: `Request failed with status ${xhr.status}`,\n status: xhr.status,\n statusText: xhr.statusText,\n xhr: xhr,\n });\n }\n };\n xhr.onerror = function () {\n detachAbortListener();\n reject({\n message: 'Network error',\n xhr: xhr,\n });\n };\n xhr.ontimeout = function () {\n detachAbortListener();\n reject({\n message: 'Request timeout',\n xhr: xhr,\n });\n };\n\n // Open the request\n xhr.open(method, url, true);\n\n // Set response type\n if (options.responseType) xhr.responseType = options.responseType;\n // Set withCredentials\n if (options.withCredentials !== undefined) xhr.withCredentials = options.withCredentials;\n // Set timeout\n if (options.timeout !== undefined) xhr.timeout = options.timeout;\n // Set headers\n if (options.headers)\n Object.keys(options.headers).forEach((key) => {\n xhr.setRequestHeader(key, options.headers[key]);\n });\n\n // Connect abort signal to xhr.abort()\n const abortListener = () => xhr.abort();\n if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', abortListener);\n // Detach the listener once the request settles so completed requests do not keep it alive\n const detachAbortListener = () => {\n if (fetchOptions.signal) fetchOptions.signal.removeEventListener('abort', abortListener);\n };\n\n xhr.onabort = function () {\n reject({\n message: 'Request was cancelled',\n xhr: xhr,\n });\n };\n\n // Send the request\n xhr.send(options.body || null);\n });\n return xhrPromise;\n };\n return this.#_request(this.getRequestId(url, options), xhrFunction, options);\n }\n\n /**\n * Returns the request identifier for a URL and options.\n * @param {string} url - The URL used when starting the request\n * @param {import('./index.d.ts').BaseRequestOptions} options - Same options used for the request\n * @returns {string} The request identifier\n * @example\n * requestManager.fetch('/api/users');\n * const id = requestManager.getRequestId('/api/users');\n * requestManager.cancel(id);\n */\n getRequestId(url, options = {}) {\n let requestKey = options.requestKey;\n\n const prefix = 'request_';\n\n // Generate a unique identifier to prevent cancellation for non cancelable requests\n if (options.noCancel) {\n return `${prefix}${Date.now()}_${Math.random().toString(36).slice(2, 11)}`;\n }\n\n // Handle function requestKey\n if (typeof requestKey === 'function') {\n try {\n requestKey = requestKey();\n } catch {\n requestKey = null;\n }\n }\n if (requestKey !== null && requestKey !== undefined) return `${prefix}${String(requestKey)}`;\n\n // Use cleaned URL as key as fallback\n let cleanedUrl = url || '';\n if (cleanedUrl.includes('://')) cleanedUrl = cleanedUrl.split('://')[1];\n if (cleanedUrl.includes('#')) cleanedUrl = cleanedUrl.split('#')[0];\n if (!options.includeQuery && cleanedUrl.includes('?')) cleanedUrl = cleanedUrl.split('?')[0];\n\n const methodPrefix =\n options.includeMethod === false ? '' : `${(options.method || options.type || 'GET').toUpperCase()}_`;\n\n return `${prefix}${methodPrefix}${cleanedUrl}`;\n }\n\n /**\n * Cancels a specific request by its identifier.\n * @param {string} requestId - The unique identifier of the request to cancel\n * @returns {boolean} True if the request was found and cancelled, false otherwise\n */\n cancel(requestId) {\n /** @type {import('./index.d.ts').ActiveRequest|undefined} */\n const requestInfo = this.activeRequests.get(requestId);\n if (!requestInfo) return false;\n\n requestInfo.isCancelled = true; // Mark as cancelled\n\n // Try to abort using AbortController (for fetch)\n if (requestInfo.abortController && !requestInfo.abortController.signal.aborted) {\n try {\n requestInfo.abortController.abort('Request was cancelled');\n } catch (error) {}\n }\n\n // Try to cancel using cancel token/function (for axios and others)\n if (requestInfo.cancelToken) {\n try {\n if (typeof requestInfo.cancelToken === 'function') requestInfo.cancelToken();\n else if (requestInfo.cancelToken.cancel) requestInfo.cancelToken.cancel();\n } catch (error) {}\n }\n\n // Reject the wrapper promise\n this.#_deleteRequest(\n requestId,\n requestInfo.rejectWrapper,\n this.getOptions().verbose ? new Error(`Request ${requestId} was cancelled`) : null\n );\n return true;\n }\n\n /**\n * Link abort signal with HTTP client abort method.\n * Useful for custom HTTP clients that only support the abort method to cancel requests.\n * @param {Function} abortMethod - The abort method to call when the signal is aborted\n * @param {AbortSignal} signal - The signal to listen to\n */\n addAbortListener(abortMethod, signal) {\n if (!abortMethod || !signal) return;\n signal.addEventListener('abort', () => {\n if (typeof abortMethod === 'function') {\n try {\n abortMethod();\n } catch (error) {}\n }\n });\n }\n\n /**\n * Cancels all active requests.\n * @returns {number} The number of requests that were cancelled\n */\n cancelAll() {\n const requestIds = Array.from(this.activeRequests.keys());\n let cancelledCount = 0;\n requestIds.forEach((requestId) => {\n if (this.cancel(requestId)) cancelledCount++;\n });\n return cancelledCount;\n }\n\n /**\n * Resolves the AbortController for a request: explicit option, pending handoff, or new.\n * Clears the pending handoff so concurrent requests do not share it.\n * @param {AbortController|undefined} provided - Optional AbortController from options\n * @returns {AbortController}\n * @private\n */\n #_resolveAbortController(provided) {\n const abortController = provided || this.abortController || new AbortController();\n this.abortController = null;\n return abortController;\n }\n\n /**\n * Picks the best abort callback for a client request object.\n * @param {Object} req - The request object\n * @returns {Function|null}\n * @private\n */\n #_resolveAbortMethod(req) {\n if (!req) return null;\n if (typeof req.abort === 'function') return () => req.abort();\n const ExtAjax =\n typeof globalThis !== 'undefined' && globalThis.Ext && globalThis.Ext.Ajax ? globalThis.Ext.Ajax : null;\n if (req.xhr && ExtAjax && typeof ExtAjax.abort === 'function') {\n return () => ExtAjax.abort(req);\n }\n if (req.xhr && typeof req.xhr.abort === 'function') return () => req.xhr.abort();\n return null;\n }\n\n /**\n * Prepares request options by merging options and removing custom properties\n * @param {import('./index.d.ts').RequestOptions} options - Configuration options\n * @param {AbortSignal} signal - Abort signal to add to request options\n * @returns {Object} Prepared request options\n * @private\n */\n #_prepareRequestOptions(options, signal) {\n const requestOptions = {};\n const customOptions = [\n 'abortController',\n 'cancelToken',\n 'requestKey',\n 'noCancel',\n 'includeQuery',\n 'includeMethod',\n 'verbose',\n ];\n Object.keys(options).forEach((key) => {\n if (customOptions.includes(key)) return;\n requestOptions[key] = options[key];\n });\n requestOptions.signal = signal;\n return requestOptions;\n }\n\n /**\n * Warns when the provided axios instance predates 0.22.0, the first version\n * supporting AbortSignal cancellation. Older instances silently ignore\n * options.signal, so duplicate requests would not be cancelled.\n * @param {object} axiosLib - The axios instance about to be used\n * @private\n */\n #_checkAxiosVersion(axiosLib) {\n const version = typeof axiosLib?.VERSION === 'string' ? axiosLib.VERSION : null;\n if (!version) return;\n const [major, minor] = version.split('.').map(Number);\n if (major === 0 && minor < 22) {\n console.warn(\n `[request-manager] axios >= 0.22.0 is required: axios ${version} ignores the AbortSignal used for automatic cancellation. Please upgrade axios.`\n );\n }\n }\n\n /**\n * Deletes a request from the active requests map and rejects the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} rejectWrapper - The function to reject the wrapper promise\n * @param {*} error - The error to reject the wrapper promise with; the wrapper is not rejected if null/undefined\n * @private\n */\n #_deleteRequest(requestId, rejectWrapper, error) {\n this.activeRequests.delete(requestId);\n if (error !== null && error !== undefined) {\n rejectWrapper(error);\n }\n }\n\n /**\n * Completes a request by deleting it from the active requests map and resolving the wrapper promise\n * @param {string} requestId - The unique identifier of the request\n * @param {Function} resolveWrapper - The function to resolve the wrapper promise\n * @param {Promise} requestPromise - The request promise\n * @param {boolean} isCancelled - Whether the request was cancelled\n * @private\n */\n #_completeRequest(requestId, resolveWrapper, requestPromise, isCancelled) {\n this.activeRequests.delete(requestId);\n if (!isCancelled) {\n resolveWrapper(requestPromise);\n }\n }\n\n /**\n * Internal method that handles the core request logic.\n * @param {string} requestId - Unique identifier for the request\n * @param {Promise|import('./index.d.ts').RequestFunction|string} requestPromise - The request promise, function, or URL string\n * @param {import('./index.d.ts').BaseRequestOptions} options - Configuration options\n * @returns {Promise} A Promise that resolves/rejects based on the most recent request\n * @private\n */\n #_request(requestId, requestPromise, options = {}) {\n const abortController = this.#_resolveAbortController(options.abortController);\n\n // Handle different types of requestPromise inputs\n // Priority: Function (Custom logic) > String (URL) > Promise (axios, fetch, etc.)\n if (typeof requestPromise === 'function') {\n // Function: custom logic for any library (axios, ajax, etc.)\n try {\n requestPromise = requestPromise({\n options: this.#_prepareRequestOptions(options, abortController.signal),\n });\n } catch (error) {\n return Promise.reject(error);\n }\n } else if (typeof requestPromise === 'string') {\n // String (URL): make fetch internally\n try {\n requestPromise = fetch(requestPromise, this.#_prepareRequestOptions(options, abortController.signal));\n } catch (error) {\n return Promise.reject(error);\n }\n }\n\n // Link the request object's abort method (Ext.Ajax, XHR, etc.) to the cancellation signal\n this.addAbortListener(this.#_resolveAbortMethod(requestPromise), abortController.signal);\n\n // Cancel previous request with the same identifier if it exists\n if (!options.noCancel) this.cancel(requestId);\n\n // Create a wrapper promise that will be resolved/rejected based on the request\n let resolveWrapper, rejectWrapper;\n const wrapperPromise = new Promise((resolve, reject) => {\n resolveWrapper = resolve;\n rejectWrapper = reject;\n });\n\n /**\n * @type {import('./index.d.ts').ActiveRequest}\n */\n const requestInfo = {\n promise: requestPromise,\n abortController: abortController,\n cancelToken: options.cancelToken || null,\n resolveWrapper: resolveWrapper,\n rejectWrapper: rejectWrapper,\n isCancelled: false,\n };\n\n this.activeRequests.set(requestId, requestInfo);\n\n // Handle request promise completion\n if (requestPromise && typeof requestPromise.then === 'function') {\n try {\n let req = requestPromise.then((result) => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, result, requestInfo.isCancelled);\n });\n if (req.catch)\n req.catch((error) => {\n onError(this, error);\n });\n } catch (error) {\n onError(this, error);\n }\n function onError(scope, error) {\n // Check if this requestInfo is still the active one, or if it was cancelled\n if (scope.activeRequests.get(requestId) !== requestInfo) return;\n if (requestInfo.isCancelled) {\n // Already cancelled: let cancel() handle cleanup and reject the wrapper promise\n scope.cancel(requestId);\n return;\n }\n // Only delete if this is still the active request\n scope.#_deleteRequest(requestId, rejectWrapper, error);\n }\n } else {\n // Non-promise (Ext.Ajax request object, raw XHR, etc.). Keep tracked until the\n // underlying XHR finishes so a later duplicate can still cancel it.\n const xhr =\n requestPromise &&\n (requestPromise.xhr ||\n (typeof XMLHttpRequest !== 'undefined' && requestPromise instanceof XMLHttpRequest\n ? requestPromise\n : null));\n const finish = () => {\n if (this.activeRequests.get(requestId) !== requestInfo) return;\n this.#_completeRequest(requestId, resolveWrapper, requestPromise, requestInfo.isCancelled);\n };\n if (xhr && typeof xhr.addEventListener === 'function') {\n xhr.addEventListener('loadend', finish);\n } else {\n setTimeout(finish, 0);\n }\n }\n return wrapperPromise;\n }\n}\n\nexport default RequestManager;\n\nexport { RequestManager };\n"],"names":["_resolveAbortController","provided","abortController","this","AbortController","_resolveAbortMethod","req","abort","ExtAjax","globalThis","Ext","Ajax","xhr","_prepareRequestOptions","options","signal","requestOptions","customOptions","Object","keys","forEach","key","includes","_checkAxiosVersion","axiosLib","version","VERSION","_version$split$map2","_slicedToArray","split","map","Number","major","minor","console","warn","concat","_deleteRequest","requestId","rejectWrapper","error","activeRequests","delete","_completeRequest","resolveWrapper","requestPromise","isCancelled","_request","arguments","length","undefined","_assertClassBrand","_RequestManager_brand","call","Promise","reject","fetch","addAbortListener","noCancel","cancel","wrapperPromise","resolve","requestInfo","promise","cancelToken","set","then","result","get","catch","onError","scope","XMLHttpRequest","finish","addEventListener","setTimeout","constructor","_classPrivateMethodInitSpec","Map","getOptions","setOptions","getSignal","getAbortController","isActive","has","getActiveCount","size","clear","request","url","getRequestId","axios","Error","_ref","_objectSpread","ajax","ajaxFunction","_ref2","_ref3","fetchOptions","method","toUpperCase","onload","detachAbortListener","status","_xhr$getResponseHeade","response","responseType","getResponseHeader","JSON","parse","_unused","data","statusText","headers","getAllResponseHeaders","message","onerror","ontimeout","open","withCredentials","timeout","setRequestHeader","abortListener","removeEventListener","onabort","send","body","requestKey","prefix","Date","now","Math","random","toString","slice","_unused2","String","cleanedUrl","includeQuery","methodPrefix","includeMethod","type","aborted","verbose","abortMethod","cancelAll","requestIds","Array","from","cancelledCount"],"mappings":";;;;;;;;KA8nBC,SAAAA,EAzM4BC,GACrB,IAAMC,EAAkBD,GAAYE,KAAKD,iBAAmB,IAAIE,gBAEhE,OADAD,KAAKD,gBAAkB,KAChBA,CACX,CAEA,SAAAG,EAMqBC,GACjB,IAAKA,EAAK,OAAO,KACjB,GAAyB,mBAAdA,EAAIC,MAAsB,MAAO,IAAMD,EAAIC,QACtD,IAAMC,EACoB,oBAAfC,YAA8BA,WAAWC,KAAOD,WAAWC,IAAIC,KAAOF,WAAWC,IAAIC,KAAO,KACvG,OAAIL,EAAIM,KAAOJ,GAAoC,mBAAlBA,EAAQD,MAC9B,IAAMC,EAAQD,MAAMD,GAE3BA,EAAIM,KAAgC,mBAAlBN,EAAIM,IAAIL,MAA6B,IAAMD,EAAIM,IAAIL,QAClE,IACX,CAEA,SAAAM,EAOwBC,EAASC,GAC7B,IAAMC,EAAiB,CAAA,EACjBC,EAAgB,CAClB,kBACA,cACA,aACA,WACA,eACA,gBACA,WAOJ,OALAC,OAAOC,KAAKL,GAASM,QAASC,IACtBJ,EAAcK,SAASD,KAC3BL,EAAeK,GAAOP,EAAQO,MAElCL,EAAeD,OAASA,EACjBC,CACX,CAEA,SAAAO,EAOoBC,GAChB,IAAMC,EAAuC,iBAAtBD,eAAAA,EAAUE,SAAuBF,EAASE,QAAU,KAC3E,GAAKD,EAAL,CACA,IAAqDE,EAA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C,eAAetB,QAC9CmI,EAAiB,EAIrB,OAHAH,EAAW/H,QAASkB,IACZnC,KAAKwD,OAAOrB,IAAYgH,MAEzBA,CACX"}
package/index.d.ts CHANGED
@@ -247,12 +247,19 @@ export interface RequestFunctionOptions {
247
247
  */
248
248
  export type RequestFunction<T = any> = (params: RequestFunctionOptions) => Promise<T>;
249
249
 
250
+ /**
251
+ * Result returned by an ajax function: either a Promise (e.g. jQuery jqXHR)
252
+ * or a request object (e.g. Ext.Ajax.request result) exposing `abort` and/or `xhr`.
253
+ */
254
+ export type AjaxResult<T = any> =
255
+ (Promise<T> & { abort?: () => void }) | ({ abort?: () => void; xhr?: XMLHttpRequest } & Record<string, any>);
256
+
250
257
  /**
251
258
  * Ajax function type
252
259
  */
253
260
  export type AjaxFunction<T = any> = (
254
261
  params: { url: string; signal?: AbortSignal } & Record<string, any>
255
- ) => Promise<T> & { abort?: () => void };
262
+ ) => AjaxResult<T>;
256
263
 
257
264
  /**
258
265
  * Axios instance interface
package/main.js CHANGED
@@ -163,7 +163,12 @@ class RequestManager {
163
163
  * });
164
164
  */
165
165
  axios(url, options = {}, axiosInstance = null) {
166
- const axiosLib = axiosInstance || axios;
166
+ const axiosLib = axiosInstance || (typeof axios !== 'undefined' ? axios : null);
167
+ if (!axiosLib) {
168
+ throw new Error(
169
+ 'axios was not found: pass an axios instance as the third argument of requestManager.axios() or make sure axios is available globally'
170
+ );
171
+ }
167
172
  this.#_checkAxiosVersion(axiosLib);
168
173
  return this.#_request(
169
174
  this.getRequestId(url, options),
@@ -225,7 +230,6 @@ class RequestManager {
225
230
  * });
226
231
  */
227
232
  xhr(url, options = {}) {
228
- const requestId = this.getRequestId(url, options);
229
233
  /** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */
230
234
  const xhrFunction = ({ options: fetchOptions }) => {
231
235
  // Create XMLHttpRequest
@@ -234,6 +238,7 @@ class RequestManager {
234
238
  // Create a promise that wraps the XHR request
235
239
  const xhrPromise = new Promise((resolve, reject) => {
236
240
  xhr.onload = function () {
241
+ detachAbortListener();
237
242
  if (xhr.status >= 200 && xhr.status < 300) {
238
243
  let response = xhr.response;
239
244
  if (
@@ -263,12 +268,14 @@ class RequestManager {
263
268
  }
264
269
  };
265
270
  xhr.onerror = function () {
271
+ detachAbortListener();
266
272
  reject({
267
273
  message: 'Network error',
268
274
  xhr: xhr,
269
275
  });
270
276
  };
271
277
  xhr.ontimeout = function () {
278
+ detachAbortListener();
272
279
  reject({
273
280
  message: 'Request timeout',
274
281
  xhr: xhr,
@@ -291,14 +298,26 @@ class RequestManager {
291
298
  });
292
299
 
293
300
  // Connect abort signal to xhr.abort()
294
- if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', () => xhr.abort());
301
+ const abortListener = () => xhr.abort();
302
+ if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', abortListener);
303
+ // Detach the listener once the request settles so completed requests do not keep it alive
304
+ const detachAbortListener = () => {
305
+ if (fetchOptions.signal) fetchOptions.signal.removeEventListener('abort', abortListener);
306
+ };
307
+
308
+ xhr.onabort = function () {
309
+ reject({
310
+ message: 'Request was cancelled',
311
+ xhr: xhr,
312
+ });
313
+ };
295
314
 
296
315
  // Send the request
297
316
  xhr.send(options.body || null);
298
317
  });
299
318
  return xhrPromise;
300
319
  };
301
- return this.#_request(requestId, xhrFunction, options);
320
+ return this.#_request(this.getRequestId(url, options), xhrFunction, options);
302
321
  }
303
322
 
304
323
  /**
@@ -449,7 +468,15 @@ class RequestManager {
449
468
  */
450
469
  #_prepareRequestOptions(options, signal) {
451
470
  const requestOptions = {};
452
- const customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery'];
471
+ const customOptions = [
472
+ 'abortController',
473
+ 'cancelToken',
474
+ 'requestKey',
475
+ 'noCancel',
476
+ 'includeQuery',
477
+ 'includeMethod',
478
+ 'verbose',
479
+ ];
453
480
  Object.keys(options).forEach((key) => {
454
481
  if (customOptions.includes(key)) return;
455
482
  requestOptions[key] = options[key];