@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.
- package/README.md +2 -2
- package/dist/{request-manager.cjs.js → request-manager.cjs} +22 -6
- package/dist/request-manager.cjs.map +1 -0
- package/dist/request-manager.esm.js +21 -5
- package/dist/request-manager.esm.js.map +1 -1
- package/dist/request-manager.esm.min.js +2 -2
- package/dist/request-manager.esm.min.js.map +1 -1
- package/dist/request-manager.js +21 -5
- package/dist/request-manager.js.map +1 -1
- package/dist/request-manager.min.cjs +10 -0
- package/dist/request-manager.min.cjs.map +1 -0
- package/dist/request-manager.min.js +2 -2
- package/dist/request-manager.min.js.map +1 -1
- package/dist/request-manager.umd.js +21 -5
- package/dist/request-manager.umd.js.map +1 -1
- package/dist/request-manager.umd.min.js +2 -2
- package/dist/request-manager.umd.min.js.map +1 -1
- package/index.d.ts +8 -1
- package/main.js +32 -5
- package/package.json +3 -3
- package/dist/request-manager.cjs.js.map +0 -1
- package/dist/request-manager.cjs.min.js +0 -10
- package/dist/request-manager.cjs.min.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-manager.esm.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":["RequestManager","constructor","options","arguments","length","undefined","_classPrivateMethodInitSpec","_RequestManager_brand","this","activeRequests","Map","abortController","getOptions","setOptions","getSignal","getAbortController","signal","AbortController","isActive","requestId","has","getActiveCount","size","clear","request","url","requestPromise","_assertClassBrand","_request","call","getRequestId","fetch","axios","axiosLib","_checkAxiosVersion","_ref","requestOptions","_objectSpread","ajax","ajaxFunction","Error","_ref2","xhr","_ref3","fetchOptions","XMLHttpRequest","method","toUpperCase","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$map2","_slicedToArray","map","Number","major","minor","console","warn","delete","_completeRequest","resolveWrapper","wrapperPromise","promise","set","then","result","catch","onError","scope","finish","setTimeout"],"mappings":";;;;;;;;GAQA,MAAMA,EACFC,WAAAA,GAA0B,IAAdC,EAAOC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAA,EAkZtBG,OAAAC,GA9YIC,KAAKC,eAAiB,IAAIC,IAI1BF,KAAKN,QAAUA,EAMfM,KAAKG,gBAAkB,IAC3B,CAMAC,UAAAA,GACI,OAAOJ,KAAKN,OAChB,CAMAW,UAAAA,CAAWX,GACPM,K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,EAAeH,GACpD,CACJ,KAAO,CAGH,IAAM7D,EACFhB,IACCA,EAAegB,MACe,oBAAnBG,gBAAkCnB,aAA0BmB,eAC9DnB,EACA,OACRwH,EAASA,KACP1I,KAAKC,eAAe2F,IAAIjF,KAAegF,GAC3CxE,EAAApB,EAAAC,KAAKgI,GAAiB3G,KAAtBrB,KAAuBW,EAAWsH,EAAgB/G,EAAgByE,EAAYE,cAE9E3D,GAAuC,mBAAzBA,EAAImC,iBAClBnC,EAAImC,iBAAiB,UAAWqE,GAEhCC,WAAWD,EAAQ,EAE3B,CACA,OAAOR,CACX"}
|
|
1
|
+
{"version":3,"file":"request-manager.esm.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":["RequestManager","constructor","options","arguments","length","undefined","_classPrivateMethodInitSpec","_RequestManager_brand","this","activeRequests","Map","abortController","getOptions","setOptions","getSignal","getAbortController","signal","AbortController","isActive","requestId","has","getActiveCount","size","clear","request","url","requestPromise","_assertClassBrand","_request","call","getRequestId","fetch","axios","axiosLib","Error","_checkAxiosVersion","_ref","requestOptions","_objectSpread","ajax","ajaxFunction","_ref2","xhr","_ref3","fetchOptions","XMLHttpRequest","method","toUpperCase","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$map2","_slicedToArray","map","Number","major","minor","console","warn","delete","_completeRequest","resolveWrapper","wrapperPromise","promise","set","then","result","catch","onError","scope","finish","setTimeout"],"mappings":";;;;;;;;GAQA,MAAMA,EACFC,WAAAA,GAA0B,IAAdC,EAAOC,UAAAC,OAAA,QAAAC,IAAAF,UAAA,GAAAA,UAAA,GAAG,CAAA,EAqatBG,OAAAC,GAjaIC,KAAKC,eAAiB,IAAIC,IAI1BF,KAAKN,QAAUA,EAMfM,KAAKG,gBAAkB,IAC3B,CAMAC,UAAAA,GACI,OAAOJ,KAAKN,OAChB,CAMAW,UAA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xC,IACPyC,EAAQ5I,KAAMmG,IAE1B,CAAE,MAAOA,GACLyC,EAAQ5I,KAAMmG,EAClB,CACA,SAASyC,EAAQC,EAAO1C,GAEhB0C,EAAM5I,eAAe+F,IAAIrF,KAAeoF,IACxCA,EAAYE,YAEZ4C,EAAM/C,OAAOnF,GAIjBQ,EAAApB,EAAA8I,EAAMxC,GAAehF,KAArBwH,EAAsBlI,EAAW2F,EAAeH,GACpD,CACJ,KAAO,CAGH,IAAMjE,EACFhB,IACCA,EAAegB,MACe,oBAAnBG,gBAAkCnB,aAA0BmB,eAC9DnB,EACA,OACR4H,EAASA,KACP9I,KAAKC,eAAe+F,IAAIrF,KAAeoF,GAC3C5E,EAAApB,EAAAC,KAAKoI,GAAiB/G,KAAtBrB,KAAuBW,EAAW0H,EAAgBnH,EAAgB6E,EAAYE,cAE9E/D,GAAuC,mBAAzBA,EAAIsC,iBAClBtC,EAAIsC,iBAAiB,UAAWsE,GAEhCC,WAAWD,EAAQ,EAE3B,CACA,OAAOR,CACX"}
|
package/dist/request-manager.js
CHANGED
|
@@ -279,7 +279,10 @@ var RequestManager = (function () {
|
|
|
279
279
|
axios(url) {
|
|
280
280
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
281
281
|
var axiosInstance = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
282
|
-
var axiosLib = axiosInstance || axios;
|
|
282
|
+
var axiosLib = axiosInstance || (typeof axios !== 'undefined' ? axios : null);
|
|
283
|
+
if (!axiosLib) {
|
|
284
|
+
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');
|
|
285
|
+
}
|
|
283
286
|
_assertClassBrand(_RequestManager_brand, this, _checkAxiosVersion).call(this, axiosLib);
|
|
284
287
|
return _assertClassBrand(_RequestManager_brand, this, _request).call(this, this.getRequestId(url, options), _ref => {
|
|
285
288
|
var requestOptions = _ref.options;
|
|
@@ -345,7 +348,6 @@ var RequestManager = (function () {
|
|
|
345
348
|
*/
|
|
346
349
|
xhr(url) {
|
|
347
350
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
348
|
-
var requestId = this.getRequestId(url, options);
|
|
349
351
|
/** @type {import('./index.d.ts').RequestFunction<import('./index.d.ts').XhrResponse>} */
|
|
350
352
|
var xhrFunction = _ref3 => {
|
|
351
353
|
var fetchOptions = _ref3.options;
|
|
@@ -355,6 +357,7 @@ var RequestManager = (function () {
|
|
|
355
357
|
// Create a promise that wraps the XHR request
|
|
356
358
|
var xhrPromise = new Promise((resolve, reject) => {
|
|
357
359
|
xhr.onload = function () {
|
|
360
|
+
detachAbortListener();
|
|
358
361
|
if (xhr.status >= 200 && xhr.status < 300) {
|
|
359
362
|
var _xhr$getResponseHeade;
|
|
360
363
|
var response = xhr.response;
|
|
@@ -380,12 +383,14 @@ var RequestManager = (function () {
|
|
|
380
383
|
}
|
|
381
384
|
};
|
|
382
385
|
xhr.onerror = function () {
|
|
386
|
+
detachAbortListener();
|
|
383
387
|
reject({
|
|
384
388
|
message: 'Network error',
|
|
385
389
|
xhr: xhr
|
|
386
390
|
});
|
|
387
391
|
};
|
|
388
392
|
xhr.ontimeout = function () {
|
|
393
|
+
detachAbortListener();
|
|
389
394
|
reject({
|
|
390
395
|
message: 'Request timeout',
|
|
391
396
|
xhr: xhr
|
|
@@ -407,14 +412,25 @@ var RequestManager = (function () {
|
|
|
407
412
|
});
|
|
408
413
|
|
|
409
414
|
// Connect abort signal to xhr.abort()
|
|
410
|
-
|
|
415
|
+
var abortListener = () => xhr.abort();
|
|
416
|
+
if (fetchOptions.signal) fetchOptions.signal.addEventListener('abort', abortListener);
|
|
417
|
+
// Detach the listener once the request settles so completed requests do not keep it alive
|
|
418
|
+
var detachAbortListener = () => {
|
|
419
|
+
if (fetchOptions.signal) fetchOptions.signal.removeEventListener('abort', abortListener);
|
|
420
|
+
};
|
|
421
|
+
xhr.onabort = function () {
|
|
422
|
+
reject({
|
|
423
|
+
message: 'Request was cancelled',
|
|
424
|
+
xhr: xhr
|
|
425
|
+
});
|
|
426
|
+
};
|
|
411
427
|
|
|
412
428
|
// Send the request
|
|
413
429
|
xhr.send(options.body || null);
|
|
414
430
|
});
|
|
415
431
|
return xhrPromise;
|
|
416
432
|
};
|
|
417
|
-
return _assertClassBrand(_RequestManager_brand, this, _request).call(this,
|
|
433
|
+
return _assertClassBrand(_RequestManager_brand, this, _request).call(this, this.getRequestId(url, options), xhrFunction, options);
|
|
418
434
|
}
|
|
419
435
|
|
|
420
436
|
/**
|
|
@@ -546,7 +562,7 @@ var RequestManager = (function () {
|
|
|
546
562
|
*/
|
|
547
563
|
function _prepareRequestOptions(options, signal) {
|
|
548
564
|
var requestOptions = {};
|
|
549
|
-
var customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery'];
|
|
565
|
+
var customOptions = ['abortController', 'cancelToken', 'requestKey', 'noCancel', 'includeQuery', 'includeMethod', 'verbose'];
|
|
550
566
|
Object.keys(options).forEach(key => {
|
|
551
567
|
if (customOptions.includes(key)) return;
|
|
552
568
|
requestOptions[key] = options[key];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-manager.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,GA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A,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.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;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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.")}()}Object.defineProperty(exports,"__esModule",{value:!0});var a=new WeakSet;
|
|
2
|
+
/**
|
|
3
|
+
* RequestManager - A library for managing and regulating HTTP requests efficiently.
|
|
4
|
+
* @license MIT
|
|
5
|
+
* @author Eneko Galan <enekogalanelorza@gmail.com>
|
|
6
|
+
* This library allows you to manage HTTP requests from any library (ajax, Ext.Ajax, axios, fetch, etc.)
|
|
7
|
+
* by accepting Promises as parameters. When a request is repeated with the same identifier,
|
|
8
|
+
* the previous request is automatically cancelled and the new one is executed, giving priority to the most recent requests.
|
|
9
|
+
*/class l{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,v).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,v).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,f).call(this,n),t(a,this,v).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,v).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,v).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,p).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}}function c(e){var t=e||this.abortController||new AbortController;return this.abortController=null,t}function u(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 h(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 f(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 p(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 v(e,r){var n,o,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},s=t(a,this,c).call(this,i.abortController);if("function"==typeof r)try{r=r({options:t(a,this,h).call(this,i,s.signal)})}catch(g){return Promise.reject(g)}else if("string"==typeof r)try{r=fetch(r,t(a,this,h).call(this,i,s.signal))}catch(m){return Promise.reject(m)}this.addAbortListener(t(a,this,u).call(this,r),s.signal),i.noCancel||this.cancel(e);var l=new Promise((e,t)=>{n=e,o=t}),f={promise:r,abortController:s,cancelToken:i.cancelToken||null,resolveWrapper:n,rejectWrapper:o,isCancelled:!1};if(this.activeRequests.set(e,f),r&&"function"==typeof r.then){try{var v=r.then(r=>{this.activeRequests.get(e)===f&&t(a,this,d).call(this,e,n,r,f.isCancelled)});v.catch&&v.catch(e=>{w(this,e)})}catch(x){w(this,x)}function w(r,n){r.activeRequests.get(e)===f&&(f.isCancelled?r.cancel(e):t(a,r,p).call(r,e,o,n))}}else{var y=r&&(r.xhr||("undefined"!=typeof XMLHttpRequest&&r instanceof XMLHttpRequest?r:null)),b=()=>{this.activeRequests.get(e)===f&&t(a,this,d).call(this,e,n,r,f.isCancelled)};y&&"function"==typeof y.addEventListener?y.addEventListener("loadend",b):setTimeout(b,0)}return l}exports.RequestManager=l,exports.default=l;
|
|
10
|
+
//# sourceMappingURL=request-manager.min.cjs.map
|