axios-cache-interceptor
Advanced tools
Comparing version 0.8.4 to 0.8.5
@@ -1,19 +0,1 @@ | ||
export * from './cache/axios'; | ||
export * from './cache/cache'; | ||
export * from './cache/create'; | ||
export * from './header/interpreter'; | ||
export * from './header/types'; | ||
export * from './interceptors/build'; | ||
export * from './interceptors/request'; | ||
export * from './interceptors/response'; | ||
export * from './interceptors/util'; | ||
export * from './storage/build'; | ||
export * from './storage/memory'; | ||
export * from './storage/types'; | ||
export * from './storage/web-api'; | ||
export * from './util/cache-predicate'; | ||
export * from './util/headers'; | ||
export * from './util/key-generator'; | ||
export * from './util/types'; | ||
export * from './util/update-cache'; | ||
//# sourceMappingURL=index.d.ts.map | ||
export * from '../types'; |
@@ -1,30 +0,1 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./cache/axios"), exports); | ||
__exportStar(require("./cache/cache"), exports); | ||
__exportStar(require("./cache/create"), exports); | ||
__exportStar(require("./header/interpreter"), exports); | ||
__exportStar(require("./header/types"), exports); | ||
__exportStar(require("./interceptors/build"), exports); | ||
__exportStar(require("./interceptors/request"), exports); | ||
__exportStar(require("./interceptors/response"), exports); | ||
__exportStar(require("./interceptors/util"), exports); | ||
__exportStar(require("./storage/build"), exports); | ||
__exportStar(require("./storage/memory"), exports); | ||
__exportStar(require("./storage/types"), exports); | ||
__exportStar(require("./storage/web-api"), exports); | ||
__exportStar(require("./util/cache-predicate"), exports); | ||
__exportStar(require("./util/headers"), exports); | ||
__exportStar(require("./util/key-generator"), exports); | ||
__exportStar(require("./util/types"), exports); | ||
__exportStar(require("./util/update-cache"), exports); | ||
(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{Header:()=>r,buildKeyGenerator:()=>w,buildMemoryStorage:()=>m,buildStorage:()=>y,buildWebStorage:()=>C,createCacheResponse:()=>u,createValidateStatus:()=>d,defaultHeaderInterpreter:()=>i,defaultKeyGenerator:()=>x,defaultRequestInterceptor:()=>l,defaultResponseInterceptor:()=>g,isMethodIn:()=>s,isStorage:()=>v,setupCache:()=>I,testCachePredicate:()=>f,updateCache:()=>h,updateStaleRequest:()=>c});const a=require("cache-parser"),r=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),i=e=>{if(!e)return"not enough headers";const t=e[r.CacheControl];if(t){const{noCache:i,noStore:n,mustRevalidate:o,maxAge:d,immutable:s}=(0,a.parse)(String(t));if(i||n)return"dont cache";if(s)return 31536e6;if(o)return 0;if(d){const t=e[r.Age];return t?1e3*(d-Number(t)):1e3*d}}const i=e[r.Expires];if(i){const e=Date.parse(String(i))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};function n(e,t,a,r){return new(a||(a=Promise))((function(i,n){function o(e){try{s(r.next(e))}catch(e){n(e)}}function d(e){try{s(r.throw(e))}catch(e){n(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(o,d)}s((r=r.apply(e,t||[])).next())}))}Object.create;Object.create;const o=require("fast-defer");function d(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function s(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function c(e,t){var a;t.headers||(t.headers={});const{etag:i,modifiedSince:n}=t.cache;if(i){const n=!0===i?null===(a=e.data)||void 0===a?void 0:a.headers[r.ETag]:i;n&&(t.headers[r.IfNoneMatch]=n)}n&&(t.headers[r.IfModifiedSince]=!0===n?e.data.headers[r.LastModified]||new Date(e.createdAt).toUTCString():n.toUTCString())}function u(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function l(e){const t=t=>n(this,void 0,void 0,(function*(){var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!s(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let i,n=yield e.storage.get(r);e:if("empty"===n.state||"stale"===n.state){if(e.waiting[r]){n=yield e.storage.get(r);break e}return e.waiting[r]=(0,o.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),yield e.storage.set(r,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt}),"stale"===n.state&&c(n,t),t.validateStatus=d(t.validateStatus),t}if("loading"===n.state){const a=e.waiting[r];if(!a)return yield e.storage.remove(r),t;0;try{i=yield a}catch(e){return t}}else i=n.data;return t.adapter=()=>Promise.resolve({config:t,data:i.data,headers:i.headers,status:i.status,statusText:i.statusText,cached:!0,id:r}),t}));return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}function f(e,t){var a;return n(this,void 0,void 0,(function*(){if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:i,containsHeaders:n}=t;if(r&&!(yield r(e.status))||i&&!(yield i(e)))return!1;if(n)for(const t in n){const r=n[t];if(r&&!(yield r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t])))return!1}return!0}))}function h(e,t,a){return n(this,void 0,void 0,(function*(){for(const r in a){const i=a[r];if("delete"===i){yield e.remove(r);continue}const n=yield e.get(r);if("loading"===n.state)continue;const o=yield i(n,t);"delete"!==o?"ignore"!==o&&(yield e.set(r,o)):yield e.remove(r)}}))}function g(e){const t=t=>n(this,void 0,void 0,(function*(){var a;yield e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]})),a=a=>n(this,void 0,void 0,(function*(){var i,n,o;if(a.id=null!==(i=(o=a.config).id)&&void 0!==i?i:o.id=e.generateKey(a.config),null!==(n=a.cached)&&void 0!==n||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const d=a.config.cache,s=yield e.storage.get(a.id);if("stale"===s.state||"empty"===s.state||"cached"===s.state)return a;if(!s.data&&!(yield f(a,d.cachePredicate)))return yield t(a.id),a;for(const e in r)e.startsWith("XAxiosCache")&&delete a.headers[e];d.etag&&!0!==d.etag&&(a.headers[r.XAxiosCacheEtag]=d.etag),d.modifiedSince&&(a.headers[r.XAxiosCacheLastModified]=!0===d.modifiedSince?"use-cache-timestamp":d.modifiedSince.toUTCString());let c=d.ttl||-1;if(null==d?void 0:d.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return yield t(a.id),a;c="not enough headers"===r?c:r}const l=u(a,s.data);"function"==typeof c&&(c=yield c(a)),d.staleIfError&&(a.headers[r.XAxiosCacheStaleIfError]=String(c)),(null==d?void 0:d.update)&&(yield h(e.storage,a,d.update));const g={state:"cached",ttl:c,createdAt:Date.now(),data:l},p=e.waiting[a.id];return p&&(p.resolve(g.data),delete e.waiting[a.id]),yield e.storage.set(a.id,g),a})),i=a=>n(this,void 0,void 0,(function*(){var r;const i=a.config;if(!i||!1===i.cache||!i.id)throw a;const n=yield e.storage.get(i.id),o=i.cache;if("loading"!==n.state||"stale"!==n.previous)throw yield t(i.id),a;if(null==o?void 0:o.staleIfError){const t="function"==typeof o.staleIfError?yield o.staleIfError(a.response,n,a):o.staleIfError;if(!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return null===(r=e.waiting[i.id])||void 0===r||r.resolve(n.data),delete e.waiting[i.id],yield e.storage.set(i.id,{state:"stale",createdAt:Date.now(),data:n.data}),{cached:!0,config:i,id:i.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw a}));return{onFulfilled:a,onRejected:i,apply:()=>e.interceptors.response.use(a,i)}}const p=Symbol(),v=e=>!!e&&!!e[p];function y({set:e,find:t,remove:a}){return{[p]:1,set:e,remove:a,get:i=>n(this,void 0,void 0,(function*(){const n=yield t(i);if(!n)return{state:"empty"};if("cached"!==n.state||n.createdAt+n.ttl>Date.now())return n;if(n.data.headers&&(r.ETag in n.data.headers||r.LastModified in n.data.headers||r.XAxiosCacheEtag in n.data.headers||r.XAxiosCacheStaleIfError in n.data.headers||r.XAxiosCacheLastModified in n.data.headers)){const t={state:"stale",createdAt:n.createdAt,data:n.data};return yield e(i,t),t}return yield a(i),{state:"empty"}}))}}function m(){const e=y({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const b=require("object-code"),S=/^\/|\/$/g;function w(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(S,"")),a.url&&(a.url=a.url.replace(S,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?(0,b.code)(r).toString():r}}const x=w(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:i})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:i})));function I(e,t={}){var a,r,n,o,d;const s=e;if(s.storage=t.storage||m(),!v(s.storage))throw new Error("Use buildStorage() function");return s.generateKey=t.generateKey||x,s.waiting=t.waiting||{},s.headerInterpreter=t.headerInterpreter||i,s.requestInterceptor=t.requestInterceptor||l(s),s.responseInterceptor=t.responseInterceptor||g(s),s.debug=t.debug,s.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(o=t.modifiedSince)&&void 0!==o&&o,staleIfError:null!==(d=t.staleIfError)&&void 0!==d&&d,update:t.update||{}},s.requestInterceptor.apply(),s.responseInterceptor.apply(),s}function C(e,t=""){return y({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},set:(a,r)=>{e.setItem(t+a,JSON.stringify(r))},remove:a=>{e.removeItem(t+a)}})}module.exports=t})(); |
@@ -1,19 +0,1 @@ | ||
export * from './cache/axios'; | ||
export * from './cache/cache'; | ||
export * from './cache/create'; | ||
export * from './header/interpreter'; | ||
export * from './header/types'; | ||
export * from './interceptors/build'; | ||
export * from './interceptors/request'; | ||
export * from './interceptors/response'; | ||
export * from './interceptors/util'; | ||
export * from './storage/build'; | ||
export * from './storage/memory'; | ||
export * from './storage/types'; | ||
export * from './storage/web-api'; | ||
export * from './util/cache-predicate'; | ||
export * from './util/headers'; | ||
export * from './util/key-generator'; | ||
export * from './util/types'; | ||
export * from './util/update-cache'; | ||
//# sourceMappingURL=index.d.ts.map | ||
export * from '../types'; |
@@ -1,18 +0,1 @@ | ||
export * from './cache/axios'; | ||
export * from './cache/cache'; | ||
export * from './cache/create'; | ||
export * from './header/interpreter'; | ||
export * from './header/types'; | ||
export * from './interceptors/build'; | ||
export * from './interceptors/request'; | ||
export * from './interceptors/response'; | ||
export * from './interceptors/util'; | ||
export * from './storage/build'; | ||
export * from './storage/memory'; | ||
export * from './storage/types'; | ||
export * from './storage/web-api'; | ||
export * from './util/cache-predicate'; | ||
export * from './util/headers'; | ||
export * from './util/key-generator'; | ||
export * from './util/types'; | ||
export * from './util/update-cache'; | ||
import*as e from"cache-parser";import*as t from"fast-defer";import*as a from"object-code";var r={d:(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},i={};r.d(i,{h4:()=>s,UN:()=>C,uu:()=>I,Kd:()=>S,ZF:()=>L,p:()=>h,E7:()=>u,NQ:()=>o,xK:()=>A,G6:()=>g,LN:()=>m,Ad:()=>l,$k:()=>x,v8:()=>E,Jk:()=>p,tI:()=>v,iS:()=>f});const n=(e=>{var t={};return r.d(t,e),t})({parse:()=>e.parse}),s=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),o=e=>{if(!e)return"not enough headers";const t=e[s.CacheControl];if(t){const{noCache:a,noStore:r,mustRevalidate:i,maxAge:o,immutable:d}=(0,n.parse)(String(t));if(a||r)return"dont cache";if(d)return 31536e6;if(i)return 0;if(o){const t=e[s.Age];return t?1e3*(o-Number(t)):1e3*o}}const a=e[s.Expires];if(a){const e=Date.parse(String(a))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};function d(e,t,a,r){return new(a||(a=Promise))((function(i,n){function s(e){try{d(r.next(e))}catch(e){n(e)}}function o(e){try{d(r.throw(e))}catch(e){n(e)}}function d(e){var t;e.done?i(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(s,o)}d((r=r.apply(e,t||[])).next())}))}Object.create;Object.create;const c=(e=>{var t={};return r.d(t,e),t})({deferred:()=>t.deferred});function u(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function l(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function f(e,t){var a;t.headers||(t.headers={});const{etag:r,modifiedSince:i}=t.cache;if(r){const i=!0===r?null===(a=e.data)||void 0===a?void 0:a.headers[s.ETag]:r;i&&(t.headers[s.IfNoneMatch]=i)}i&&(t.headers[s.IfModifiedSince]=!0===i?e.data.headers[s.LastModified]||new Date(e.createdAt).toUTCString():i.toUTCString())}function h(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function g(e){const t=t=>d(this,void 0,void 0,(function*(){var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!l(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let i,n=yield e.storage.get(r);e:if("empty"===n.state||"stale"===n.state){if(e.waiting[r]){n=yield e.storage.get(r);break e}return e.waiting[r]=(0,c.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),yield e.storage.set(r,{state:"loading",previous:n.state,data:n.data,createdAt:n.createdAt}),"stale"===n.state&&f(n,t),t.validateStatus=u(t.validateStatus),t}if("loading"===n.state){const a=e.waiting[r];if(!a)return yield e.storage.remove(r),t;0;try{i=yield a}catch(e){return t}}else i=n.data;return t.adapter=()=>Promise.resolve({config:t,data:i.data,headers:i.headers,status:i.status,statusText:i.statusText,cached:!0,id:r}),t}));return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}function p(e,t){var a;return d(this,void 0,void 0,(function*(){if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:i,containsHeaders:n}=t;if(r&&!(yield r(e.status))||i&&!(yield i(e)))return!1;if(n)for(const t in n){const r=n[t];if(r&&!(yield r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t])))return!1}return!0}))}function v(e,t,a){return d(this,void 0,void 0,(function*(){for(const r in a){const i=a[r];if("delete"===i){yield e.remove(r);continue}const n=yield e.get(r);if("loading"===n.state)continue;const s=yield i(n,t);"delete"!==s?"ignore"!==s&&(yield e.set(r,s)):yield e.remove(r)}}))}function m(e){const t=t=>d(this,void 0,void 0,(function*(){var a;yield e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]})),a=a=>d(this,void 0,void 0,(function*(){var r,i,n;if(a.id=null!==(r=(n=a.config).id)&&void 0!==r?r:n.id=e.generateKey(a.config),null!==(i=a.cached)&&void 0!==i||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const o=a.config.cache,d=yield e.storage.get(a.id);if("stale"===d.state||"empty"===d.state||"cached"===d.state)return a;if(!d.data&&!(yield p(a,o.cachePredicate)))return yield t(a.id),a;for(const e in s)e.startsWith("XAxiosCache")&&delete a.headers[e];o.etag&&!0!==o.etag&&(a.headers[s.XAxiosCacheEtag]=o.etag),o.modifiedSince&&(a.headers[s.XAxiosCacheLastModified]=!0===o.modifiedSince?"use-cache-timestamp":o.modifiedSince.toUTCString());let c=o.ttl||-1;if(null==o?void 0:o.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return yield t(a.id),a;c="not enough headers"===r?c:r}const u=h(a,d.data);"function"==typeof c&&(c=yield c(a)),o.staleIfError&&(a.headers[s.XAxiosCacheStaleIfError]=String(c)),(null==o?void 0:o.update)&&(yield v(e.storage,a,o.update));const l={state:"cached",ttl:c,createdAt:Date.now(),data:u},f=e.waiting[a.id];return f&&(f.resolve(l.data),delete e.waiting[a.id]),yield e.storage.set(a.id,l),a})),r=a=>d(this,void 0,void 0,(function*(){var r;const i=a.config;if(!i||!1===i.cache||!i.id)throw a;const n=yield e.storage.get(i.id),s=i.cache;if("loading"!==n.state||"stale"!==n.previous)throw yield t(i.id),a;if(null==s?void 0:s.staleIfError){const t="function"==typeof s.staleIfError?yield s.staleIfError(a.response,n,a):s.staleIfError;if(!0===t||"number"==typeof t&&n.createdAt+t>Date.now())return null===(r=e.waiting[i.id])||void 0===r||r.resolve(n.data),delete e.waiting[i.id],yield e.storage.set(i.id,{state:"stale",createdAt:Date.now(),data:n.data}),{cached:!0,config:i,id:i.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}}throw a}));return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const y=Symbol(),x=e=>!!e&&!!e[y];function S({set:e,find:t,remove:a}){return{[y]:1,set:e,remove:a,get:r=>d(this,void 0,void 0,(function*(){const i=yield t(r);if(!i)return{state:"empty"};if("cached"!==i.state||i.createdAt+i.ttl>Date.now())return i;if(i.data.headers&&(s.ETag in i.data.headers||s.LastModified in i.data.headers||s.XAxiosCacheEtag in i.data.headers||s.XAxiosCacheStaleIfError in i.data.headers||s.XAxiosCacheLastModified in i.data.headers)){const t={state:"stale",createdAt:i.createdAt,data:i.data};return yield e(r,t),t}return yield a(r),{state:"empty"}}))}}function I(){const e=S({find:t=>e.data[t],set:(t,a)=>{e.data[t]=a},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}const b=(e=>{var t={};return r.d(t,e),t})({code:()=>a.code}),w=/^\/|\/$/g;function C(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(w,"")),a.url&&(a.url=a.url.replace(w,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?(0,b.code)(r).toString():r}}const A=C(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:i})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:i})));function E(e,t={}){var a,r,i,n,s;const d=e;if(d.storage=t.storage||I(),!x(d.storage))throw new Error("Use buildStorage() function");return d.generateKey=t.generateKey||A,d.waiting=t.waiting||{},d.headerInterpreter=t.headerInterpreter||o,d.requestInterceptor=t.requestInterceptor||g(d),d.responseInterceptor=t.responseInterceptor||m(d),d.debug=t.debug,d.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(i=t.etag)&&void 0!==i&&i,modifiedSince:null!==(n=t.modifiedSince)&&void 0!==n&&n,staleIfError:null!==(s=t.staleIfError)&&void 0!==s&&s,update:t.update||{}},d.requestInterceptor.apply(),d.responseInterceptor.apply(),d}function L(e,t=""){return S({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},set:(a,r)=>{e.setItem(t+a,JSON.stringify(r))},remove:a=>{e.removeItem(t+a)}})}var j=i.h4,O=i.UN,T=i.uu,M=i.Kd,N=i.ZF,K=i.p,R=i.E7,U=i.NQ,X=i.xK,P=i.G6,k=i.LN,D=i.Ad,q=i.$k,H=i.v8,F=i.Jk,G=i.tI,J=i.iS;export{j as Header,O as buildKeyGenerator,T as buildMemoryStorage,M as buildStorage,N as buildWebStorage,K as createCacheResponse,R as createValidateStatus,U as defaultHeaderInterpreter,X as defaultKeyGenerator,P as defaultRequestInterceptor,k as defaultResponseInterceptor,D as isMethodIn,q as isStorage,H as setupCache,F as testCachePredicate,G as updateCache,J as updateStaleRequest}; |
{ | ||
"name": "axios-cache-interceptor", | ||
"version": "0.8.4", | ||
"version": "0.8.5", | ||
"description": "Cache interceptor for axios", | ||
@@ -11,7 +11,7 @@ "main": "./cjs/index.js", | ||
"require": "./cjs/index.js", | ||
"default": "./umd/es6.js" | ||
"default": "./umd/index.js" | ||
}, | ||
"browser": "./umd/es6.js", | ||
"jsdelivr": "./umd/es6.js", | ||
"unpkg": "./umd/es6.js", | ||
"browser": "./umd/index.js", | ||
"jsdelivr": "./umd/index.js", | ||
"unpkg": "./umd/index.js", | ||
"sideEffects": false, | ||
@@ -25,3 +25,3 @@ "runkitExampleFilename": "./examples/runkit.js", | ||
"lint": "eslint . --ext .ts", | ||
"changelog": "auto-changelog -p" | ||
"version": "auto-changelog -p && git add CHANGELOG.md" | ||
}, | ||
@@ -49,2 +49,3 @@ "repository": { | ||
"src/", | ||
"types/", | ||
"examples/" | ||
@@ -95,3 +96,4 @@ ], | ||
"axios": "~0.25.0" | ||
} | ||
}, | ||
"packageManager": "yarn@1.22.17" | ||
} |
@@ -9,2 +9,3 @@ [![Issues](https://img.shields.io/github/issues/arthurfiorette/axios-cache-interceptor?logo=github&label=Issues)](https://github.com/arthurfiorette/axios-cache-interceptor/issues) | ||
[![Packagephobia](https://packagephobia.com/badge?p=axios-cache-interceptor@latest)](https://packagephobia.com/result?p=axios-cache-interceptor@latest) | ||
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Farthurfiorette%2Faxios-cache-interceptor.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Farthurfiorette%2Faxios-cache-interceptor?ref=badge_shield) | ||
@@ -22,3 +23,3 @@ <br /> | ||
<h3 align="center"> | ||
<code>axios-cache-interceptor</code> is a small and efficient cache interceptor for axios. | ||
<code>Axios Cache Interceptor</code> is a small and efficient cache interceptor for axios. | ||
<br /> | ||
@@ -60,2 +61,4 @@ <br /> | ||
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Farthurfiorette%2Faxios-cache-interceptor.svg?type=small)](https://app.fossa.com/projects/git%2Bgithub.com%2Farthurfiorette%2Faxios-cache-interceptor?ref=badge_small) | ||
## Contact | ||
@@ -62,0 +65,0 @@ |
@@ -139,10 +139,36 @@ import type { Method } from 'axios'; | ||
* cache.interpretHeader is true. | ||
* | ||
* @default defaultHeaderInterpreter() | ||
*/ | ||
headerInterpreter: HeadersInterpreter; | ||
/** The request interceptor that will be used to handle the cache. */ | ||
/** | ||
* The request interceptor that will be used to handle the cache. | ||
* | ||
* @default defaultRequestInterceptor() | ||
*/ | ||
requestInterceptor: AxiosInterceptor<CacheRequestConfig>; | ||
/** The response interceptor that will be used to handle the cache. */ | ||
/** | ||
* The response interceptor that will be used to handle the cache. | ||
* | ||
* @default defaultResponseInterceptor() | ||
*/ | ||
responseInterceptor: AxiosInterceptor<CacheAxiosResponse>; | ||
/** | ||
* Logs useful information in the console | ||
* | ||
* **Note**: This is only available with development mode enabled | ||
* | ||
* @default console.log | ||
* @see https://axios-cache-interceptor.js.org/#/pages/development-mode | ||
*/ | ||
debug: undefined | ((msg: DebugObject) => void); | ||
} | ||
/** | ||
* An object with any possible type that can be used to log and debug information in | ||
* `development` mode (a.k.a `__ACI_DEV__ === true`) | ||
*/ | ||
export type DebugObject = Partial<{ id: string; msg: string; data: unknown }>; |
@@ -68,2 +68,3 @@ import type { AxiosInstance } from 'axios'; | ||
options.responseInterceptor || defaultResponseInterceptor(axiosCache); | ||
axiosCache.debug = options.debug; | ||
@@ -70,0 +71,0 @@ // CacheRequestConfig values |
import { parse } from 'cache-parser'; | ||
import { Header } from '../util/headers'; | ||
import { Header } from './headers'; | ||
import type { HeadersInterpreter } from './types'; | ||
@@ -4,0 +4,0 @@ |
export * from './cache/axios'; | ||
export * from './cache/cache'; | ||
export * from './cache/create'; | ||
export * from './header/headers'; | ||
export * from './header/interpreter'; | ||
@@ -15,5 +16,22 @@ export * from './header/types'; | ||
export * from './util/cache-predicate'; | ||
export * from './util/headers'; | ||
export * from './util/key-generator'; | ||
export * from './util/types'; | ||
export * from './util/update-cache'; | ||
/** @internal */ | ||
declare global { | ||
/** | ||
* Global variable defined at compile time. Use to write code that will only be executed | ||
* at development time. | ||
* | ||
* @internal | ||
*/ | ||
const __ACI_DEV__: boolean; | ||
} | ||
if (__ACI_DEV__) { | ||
console.error( | ||
'You are using a development build. Make sure to use the correct build in production' | ||
); | ||
console.error('https://axios-cache-interceptor.js.org/#/pages/installing'); | ||
} |
@@ -19,2 +19,9 @@ import { deferred } from 'fast-defer'; | ||
if (config.cache === false) { | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
msg: 'Ignoring cache because config.cache is false', | ||
data: config | ||
}); | ||
} | ||
return config; | ||
@@ -27,2 +34,7 @@ } | ||
if (!isMethodIn(config.method, config.cache.methods)) { | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
msg: `Ignored because method (${config.method}) is not in cache.methods (${config.cache.methods})` | ||
}); | ||
} | ||
return config; | ||
@@ -47,2 +59,10 @@ } | ||
| LoadingStorageValue; | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: key, | ||
msg: 'Waiting list had an deferred for this key, waiting for it to finish' | ||
}); | ||
} | ||
break emptyOrStale; | ||
@@ -73,2 +93,9 @@ } | ||
updateStaleRequest(cache, config as ConfigWithCache<unknown>); | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: key, | ||
msg: 'Updated stale request' | ||
}); | ||
} | ||
} | ||
@@ -78,2 +105,9 @@ | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: key, | ||
msg: 'Sending request, waiting for response' | ||
}); | ||
} | ||
return config; | ||
@@ -94,5 +128,20 @@ } | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: key, | ||
msg: 'Detected concurrent request, waiting for it to finish' | ||
}); | ||
} | ||
try { | ||
cachedResponse = await deferred; | ||
} catch { | ||
} catch (err) { | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: key, | ||
msg: 'Deferred rejected, requesting again', | ||
data: err | ||
}); | ||
} | ||
// The deferred is rejected when the request that we are waiting rejected cache. | ||
@@ -118,2 +167,9 @@ return config; | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: key, | ||
msg: 'Returning cached response' | ||
}); | ||
} | ||
return config; | ||
@@ -120,0 +176,0 @@ }; |
@@ -7,5 +7,5 @@ import type { CacheProperties } from '..'; | ||
} from '../cache/axios'; | ||
import { Header } from '../header/headers'; | ||
import type { CachedStorageValue } from '../storage/types'; | ||
import { testCachePredicate } from '../util/cache-predicate'; | ||
import { Header } from '../util/headers'; | ||
import { updateCache } from '../util/update-cache'; | ||
@@ -37,2 +37,9 @@ import type { ResponseInterceptor } from './build'; | ||
if (response.cached) { | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: 'Returned cached response' | ||
}); | ||
} | ||
return response; | ||
@@ -44,2 +51,10 @@ } | ||
if (!response.config.cache) { | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: 'Response with config.cache === false', | ||
data: response | ||
}); | ||
} | ||
return { ...response, cached: false }; | ||
@@ -60,2 +75,10 @@ } | ||
) { | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: 'Response not cached but storage is not loading', | ||
data: { cache, response } | ||
}); | ||
} | ||
return response; | ||
@@ -71,2 +94,9 @@ } | ||
await rejectResponse(response.id); | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: 'Cache predicate rejected this response' | ||
}); | ||
} | ||
return response; | ||
@@ -103,2 +133,15 @@ } | ||
await rejectResponse(response.id); | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: `Cache header interpreted as 'dont cache'`, | ||
data: { | ||
cache, | ||
response, | ||
expirationTime | ||
} | ||
}); | ||
} | ||
return response; | ||
@@ -120,2 +163,10 @@ } | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: 'Useful response configuration found', | ||
data: { cacheConfig, ttl, cacheResponse: data } | ||
}); | ||
} | ||
// Update other entries before updating himself | ||
@@ -134,8 +185,27 @@ if (cacheConfig?.update) { | ||
// Resolve all other requests waiting for this response | ||
axios.waiting[response.id]?.resolve(newCache.data); | ||
delete axios.waiting[response.id]; | ||
const waiting = axios.waiting[response.id]; | ||
if (waiting) { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
waiting.resolve(newCache.data); | ||
delete axios.waiting[response.id]; | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: 'Found waiting deferred(s) and resolved them' | ||
}); | ||
} | ||
} | ||
// Define this key as cache on the storage | ||
await axios.storage.set(response.id, newCache); | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
id: response.id, | ||
msg: 'Response cached', | ||
data: { cache: newCache, response } | ||
}); | ||
} | ||
// Return the response with cached as false, because it was not cached at all | ||
@@ -149,2 +219,9 @@ return response; | ||
if (!config || config.cache === false || !config.id) { | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
msg: 'Web request returned an error but cache handling is not enabled', | ||
data: { error, config } | ||
}); | ||
} | ||
throw error; | ||
@@ -162,2 +239,10 @@ } | ||
await rejectResponse(config.id); | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
msg: 'Caught an error in the request interceptor', | ||
data: { error, config } | ||
}); | ||
} | ||
throw error; | ||
@@ -176,2 +261,9 @@ } | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
msg: 'Found cache if stale config for rejected response', | ||
data: { error, config, staleIfError } | ||
}); | ||
} | ||
if ( | ||
@@ -193,2 +285,9 @@ staleIfError === true || | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
msg: 'staleIfError resolved this response with cached data', | ||
data: { error, config, cache } | ||
}); | ||
} | ||
return { | ||
@@ -206,2 +305,9 @@ cached: true, | ||
if (__ACI_DEV__) { | ||
axios.debug?.({ | ||
msg: 'Received an unknown error that could not be handled', | ||
data: { error, config } | ||
}); | ||
} | ||
throw error; | ||
@@ -208,0 +314,0 @@ }; |
import type { Method } from 'axios'; | ||
import type { CacheAxiosResponse, CacheRequestConfig } from '../cache/axios'; | ||
import type { CacheProperties } from '../cache/cache'; | ||
import { Header } from '../header/headers'; | ||
import type { CachedResponse, StaleStorageValue } from '../storage/types'; | ||
import { Header } from '../util/headers'; | ||
@@ -7,0 +7,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
import { Header } from '../util/headers'; | ||
import { Header } from '../header/headers'; | ||
import type { MaybePromise } from '../util/types'; | ||
@@ -3,0 +3,0 @@ import type { AxiosStorage, StaleStorageValue, StorageValue } from './types'; |
@@ -0,1 +1,2 @@ | ||
import type { AxiosStorage } from '..'; | ||
import { buildStorage } from './build'; | ||
@@ -27,13 +28,19 @@ import type { StorageValue } from './types'; | ||
export function buildMemoryStorage() { | ||
const data: Record<string, StorageValue> = {}; | ||
const storage = buildStorage({ | ||
find: (key) => data[key], | ||
find: (key) => storage.data[key], | ||
set: (key, value) => { | ||
data[key] = value; | ||
storage.data[key] = value; | ||
}, | ||
remove: (key) => { | ||
delete data[key]; | ||
delete storage.data[key]; | ||
} | ||
}); | ||
return { ...storage, data }; | ||
}) as MemoryStorage; | ||
storage.data = Object.create(null) as Record<string, StorageValue>; | ||
return storage; | ||
} | ||
export type MemoryStorage = AxiosStorage & { | ||
data: Record<string, StorageValue>; | ||
}; |
@@ -0,1 +1,2 @@ | ||
import type { AxiosResponseHeaders } from 'axios'; | ||
import type { MaybePromise } from '../util/types'; | ||
@@ -5,3 +6,3 @@ | ||
data?: unknown; | ||
headers: Record<string, string>; | ||
headers: AxiosResponseHeaders; | ||
status: number; | ||
@@ -20,8 +21,2 @@ statusText: string; | ||
export type StorageMetadata = { | ||
/** If the request can be stale */ | ||
shouldStale?: boolean; | ||
[key: string]: unknown; | ||
}; | ||
export type StaleStorageValue = { | ||
@@ -28,0 +23,0 @@ data: CachedResponse; |
@@ -62,3 +62,3 @@ { | ||
"newLine": "lf" /* Set the newline character for emitting files. */, | ||
// "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ | ||
"stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */ | ||
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */ | ||
@@ -65,0 +65,0 @@ // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ |
@@ -1,2 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return function(){var e={549:function(e,t){var r,a;r=t,a=Symbol("fast-defer"),r.deferred=function(){var e,t,r=new Promise((function(r,a){e=r,t=a}));return r.resolve=e,r.reject=t,r[a]=1,r},r.isDeferred=function(e){return!!e&&!!e[a]}},246:function(e,t){var r;(r=t).transform=function(e){var t=typeof e;if("object"===t&&e){if(e instanceof Date)return"#"+e.getTime();if(e instanceof RegExp)return"#"+e.toString();var a=Array.isArray(e)?[]:{};for(var n in e)a[n]=r.transform(e[n]);return"#"+String(e.constructor)+JSON.stringify(a,Object.keys(a).sort())}return t+String(e)+("symbol"===t?Math.random():"")},r.code=function(e){e=r.transform(e);for(var t=7,a=0;a<e.length;)t=31*t+e.charCodeAt(a++)&9007199254740991;return t}}},t={};function r(a){var n=t[a];if(void 0!==n)return n.exports;var o=t[a]={exports:{}};return e[a](o,o.exports,r),o.exports}r.d=function(e,t){for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return function(){"use strict";r.r(a),r.d(a,{Header:function(){return o},buildKeyGenerator:function(){return A},buildMemoryStorage:function(){return S},buildStorage:function(){return w},buildWebStorage:function(){return j},createCacheResponse:function(){return v},createValidateStatus:function(){return f},defaultHeaderInterpreter:function(){return i},defaultKeyGenerator:function(){return E},defaultRequestInterceptor:function(){return p},defaultResponseInterceptor:function(){return b},isMethodIn:function(){return l},isStorage:function(){return x},setupCache:function(){return T},testCachePredicate:function(){return g},updateCache:function(){return m},updateStaleRequest:function(){return h}});var e=Symbol("cache-parser");function t(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}var o=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",ContentType:"content-type",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),i=function(r){if(!r)return"not enough headers";var a=r[o.CacheControl];if(a){var i=function(r){var a=Object.defineProperty({},e,{enumerable:!1,value:1});if(!r||"string"!=typeof r)return a;var o=function(e){var t=e.toLowerCase().replace(/\s+/g,"").split(","),r={};for(var a in t){var n=t[a].split("=",2);r[n[0]]=1===n.length||n[1]}return r}(r);return n(o.immutable)&&(a.immutable=!0),t(o["max-age"])&&(a.maxAge=Number(o["max-age"])),t(o["max-stale"])&&(a.maxStale=Number(o["max-stale"])),t(o["min-fresh"])&&(a.minFresh=Number(o["min-fresh"])),n(o["must-revalidate"])&&(a.mustRevalidate=!0),n(o["must-understand"])&&(a.mustUnderstand=!0),n(o["no-cache"])&&(a.noCache=!0),n(o["no-store"])&&(a.noStore=!0),n(o["no-transform"])&&(a.noTransform=!0),n(o["only-if-cached"])&&(a.onlyIfCached=!0),n(o.private)&&(a.private=!0),n(o["proxy-revalidate"])&&(a.proxyRevalidate=!0),n(o.public)&&(a.public=!0),t(o["s-maxage"])&&(a.sMaxAge=Number(o["s-maxage"])),t(o["stale-if-error"])&&(a.staleIfError=Number(o["stale-if-error"])),t(o["stale-while-revalidate"])&&(a.staleWhileRevalidate=Number(o["stale-while-revalidate"])),a}(String(a)),s=i.noCache,c=i.noStore,u=i.mustRevalidate,d=i.maxAge,f=i.immutable;if(s||c)return"dont cache";if(f)return 31536e6;if(u)return 0;if(d){var l=r[o.Age];return l?1e3*(d-Number(l)):1e3*d}}var h=r[o.Expires];if(h){var v=Date.parse(String(h))-Date.now();return v>=0?v:"dont cache"}return"not enough headers"};var s=function(){return s=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},s.apply(this,arguments)};function c(e,t,r,a){return new(r||(r=Promise))((function(n,o){function i(e){try{c(a.next(e))}catch(e){o(e)}}function s(e){try{c(a.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((a=a.apply(e,t||[])).next())}))}function u(e,t){var r,a,n,o,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,a&&(n=2&o[0]?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,a=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){i.label=o[1];break}if(6===o[0]&&i.label<n[1]){i.label=n[1],n=o;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(o);break}n[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],a=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}Object.create;Object.create;var d=r(549);function f(e){return e?function(t){return e(t)||304===t}:function(e){return e>=200&&e<300||304===e}}function l(e,t){void 0===e&&(e="get"),void 0===t&&(t=[]),e=e.toLowerCase();for(var r=0,a=t;r<a.length;r++){if(a[r].toLowerCase()===e)return!0}return!1}function h(e,t){var r;t.headers||(t.headers={});var a=t.cache,n=a.etag,i=a.modifiedSince;if(n){var s=!0===n?null===(r=e.data)||void 0===r?void 0:r.headers[o.ETag]:n;s&&(t.headers[o.IfNoneMatch]=s)}i&&(t.headers[o.IfModifiedSince]=!0===i?e.data.headers[o.LastModified]||new Date(e.createdAt).toUTCString():i.toUTCString())}function v(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=s(s({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function p(e){var t=this,r=function(r){return c(t,void 0,void 0,(function(){var t,a,n,o,i;return u(this,(function(c){switch(c.label){case 0:return!1===r.cache?[2,r]:(r.cache=s(s({},e.defaults.cache),r.cache),l(r.method,r.cache.methods)?(t=r.id=e.generateKey(r),[4,e.storage.get(t)]):[2,r]);case 1:return"empty"!==(a=c.sent()).state&&"stale"!==a.state?[3,5]:e.waiting[t]?[4,e.storage.get(t)]:[3,3];case 2:return a=c.sent(),[3,5];case 3:return e.waiting[t]=(0,d.deferred)(),null===(i=e.waiting[t])||void 0===i||i.catch((function(){})),[4,e.storage.set(t,{state:"loading",previous:a.state,data:a.data,createdAt:a.createdAt})];case 4:return c.sent(),"stale"===a.state&&h(a,r),r.validateStatus=f(r.validateStatus),[2,r];case 5:return"loading"!==a.state?[3,11]:(o=e.waiting[t])?[3,7]:[4,e.storage.remove(t)];case 6:return c.sent(),[2,r];case 7:return c.trys.push([7,9,,10]),[4,o];case 8:return n=c.sent(),[3,10];case 9:return c.sent(),[2,r];case 10:return[3,12];case 11:n=a.data,c.label=12;case 12:return r.adapter=function(){return Promise.resolve({config:r,data:n.data,headers:n.headers,status:n.status,statusText:n.statusText,cached:!0,id:t})},[2,r]}}))}))};return{onFulfilled:r,apply:function(){return e.interceptors.request.use(r)}}}function g(e,t){var r;return c(this,void 0,void 0,(function(){var a,n,o,i,s,c,d,f,l,h,v,p;return u(this,(function(u){switch(u.label){case 0:return"function"==typeof t?[2,t(e)]:(a=t.statusCheck,n=t.responseMatch,o=t.containsHeaders,(s=a)?[4,a(e.status)]:[3,2]);case 1:s=!u.sent(),u.label=2;case 2:return(i=s)?[3,5]:(c=n)?[4,n(e)]:[3,4];case 3:c=!u.sent(),u.label=4;case 4:i=c,u.label=5;case 5:if(i)return[2,!1];if(!o)return[3,10];for(f in d=[],o)d.push(f);l=0,u.label=6;case 6:return l<d.length?(h=d[l],v=o[h],(p=v)?[4,v(null!==(r=e.headers[h.toLowerCase()])&&void 0!==r?r:e.headers[h])]:[3,8]):[3,10];case 7:p=!u.sent(),u.label=8;case 8:if(p)return[2,!1];u.label=9;case 9:return l++,[3,6];case 10:return[2,!0]}}))}))}function m(e,t,r){return c(this,void 0,void 0,(function(){var a,n,o,i,s,c,d;return u(this,(function(u){switch(u.label){case 0:for(n in a=[],r)a.push(n);o=0,u.label=1;case 1:return o<a.length?(i=a[o],"delete"!==(s=r[i])?[3,3]:[4,e.remove(i)]):[3,10];case 2:return u.sent(),[3,9];case 3:return[4,e.get(i)];case 4:return"loading"===(c=u.sent()).state?[3,9]:[4,s(c,t)];case 5:return"delete"!==(d=u.sent())?[3,7]:[4,e.remove(i)];case 6:return u.sent(),[3,9];case 7:return"ignore"===d?[3,9]:[4,e.set(i,d)];case 8:u.sent(),u.label=9;case 9:return o++,[3,1];case 10:return[2]}}))}))}function b(e){var t=this,r=function(r){return c(t,void 0,void 0,(function(){var t;return u(this,(function(a){switch(a.label){case 0:return[4,e.storage.remove(r)];case 1:return a.sent(),null===(t=e.waiting[r])||void 0===t||t.reject(null),delete e.waiting[r],[2]}}))}))},a=function(a){return c(t,void 0,void 0,(function(){var t,n,i,c,d,f,l,h,p,b,y,x;return u(this,(function(u){switch(u.label){case 0:return a.id=null!==(p=(x=a.config).id)&&void 0!==p?p:x.id=e.generateKey(a.config),null!==(b=a.cached)&&void 0!==b||(a.cached=!1),a.cached?[2,a]:a.config.cache?(t=a.config.cache,[4,e.storage.get(a.id)]):[2,s(s({},a),{cached:!1})];case 1:return"stale"===(n=u.sent()).state||"empty"===n.state||"cached"===n.state?[2,a]:(i=!n.data)?[4,g(a,t.cachePredicate)]:[3,3];case 2:i=!u.sent(),u.label=3;case 3:return i?[4,r(a.id)]:[3,5];case 4:return u.sent(),[2,a];case 5:for(c in o)c.startsWith("XAxiosCache")&&delete a.headers[c];return t.etag&&!0!==t.etag&&(a.headers[o.XAxiosCacheEtag]=t.etag),t.modifiedSince&&(a.headers[o.XAxiosCacheLastModified]=!0===t.modifiedSince?"use-cache-timestamp":t.modifiedSince.toUTCString()),d=t.ttl||-1,(null==t?void 0:t.interpretHeader)?"dont cache"!==(f=e.headerInterpreter(a.headers))?[3,7]:[4,r(a.id)]:[3,8];case 6:return u.sent(),[2,a];case 7:d="not enough headers"===f?d:f,u.label=8;case 8:return l=v(a,n.data),"function"!=typeof d?[3,10]:[4,d(a)];case 9:d=u.sent(),u.label=10;case 10:return t.staleIfError&&(a.headers[o.XAxiosCacheStaleIfError]=String(d)),(null==t?void 0:t.update)?[4,m(e.storage,a,t.update)]:[3,12];case 11:u.sent(),u.label=12;case 12:return h={state:"cached",ttl:d,createdAt:Date.now(),data:l},null===(y=e.waiting[a.id])||void 0===y||y.resolve(h.data),delete e.waiting[a.id],[4,e.storage.set(a.id,h)];case 13:return u.sent(),[2,a]}}))}))},n=function(a){return c(t,void 0,void 0,(function(){var t,n,o,i,s,c;return u(this,(function(u){switch(u.label){case 0:if(!(t=a.config)||!1===t.cache||!t.id)throw a;return[4,e.storage.get(t.id)];case 1:return n=u.sent(),o=t.cache,"loading"===n.state&&"stale"===n.previous?[3,3]:[4,r(t.id)];case 2:throw u.sent(),a;case 3:return(null==o?void 0:o.staleIfError)?"function"!=typeof o.staleIfError?[3,5]:[4,o.staleIfError(a.response,n,a)]:[3,8];case 4:return s=u.sent(),[3,6];case 5:s=o.staleIfError,u.label=6;case 6:return!0===(i=s)||"number"==typeof i&&n.createdAt+i>Date.now()?(null===(c=e.waiting[t.id])||void 0===c||c.resolve(n.data),delete e.waiting[t.id],[4,e.storage.set(t.id,{state:"stale",createdAt:Date.now(),data:n.data})]):[3,8];case 7:return u.sent(),[2,{cached:!0,config:t,id:t.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}];case 8:throw a}}))}))};return{onFulfilled:a,onRejected:n,apply:function(){return e.interceptors.response.use(a,n)}}}var y=Symbol(),x=function(e){return!!e&&!!e[y]};function w(e){var t,r=this,a=e.set,n=e.find,i=e.remove;return(t={})[y]=1,t.set=a,t.remove=i,t.get=function(e){return c(r,void 0,void 0,(function(){var t,r;return u(this,(function(s){switch(s.label){case 0:return[4,n(e)];case 1:return(t=s.sent())?"cached"!==t.state||t.createdAt+t.ttl>Date.now()?[2,t]:t.data.headers&&(o.ETag in t.data.headers||o.LastModified in t.data.headers||o.XAxiosCacheEtag in t.data.headers||o.XAxiosCacheStaleIfError in t.data.headers||o.XAxiosCacheLastModified in t.data.headers)?(r={state:"stale",createdAt:t.createdAt,data:t.data},[4,a(e,r)]):[3,3]:[2,{state:"empty"}];case 2:return s.sent(),[2,r];case 3:return[4,i(e)];case 4:return s.sent(),[2,{state:"empty"}]}}))}))},t}function S(){var e={},t=w({find:function(t){return e[t]},set:function(t,r){e[t]=r},remove:function(t){delete e[t]}});return s(s({},t),{data:e})}var C=r(246),I=/^\/|\/$/g;function A(e,t){return function(r){if(r.id)return r.id;r.baseURL&&(r.baseURL=r.baseURL.replace(I,"")),r.url&&(r.url=r.url.replace(I,"")),r.method&&(r.method=r.method.toLowerCase());var a=t(r);return e?(0,C.code)(a).toString():a}}var E=A(!0,(function(e){var t=e.baseURL,r=void 0===t?"":t,a=e.url,n=void 0===a?"":a,o=e.method;return{url:r+(r&&n?"/":"")+n,method:void 0===o?"get":o,params:e.params,data:e.data}}));function T(e,t){var r,a,n,o,s;void 0===t&&(t={});var c=e;if(c.storage=t.storage||S(),!x(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||E,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||i,c.requestInterceptor=t.requestInterceptor||p(c),c.responseInterceptor=t.responseInterceptor||b(c),c.defaults.cache={ttl:null!==(r=t.ttl)&&void 0!==r?r:3e5,interpretHeader:null!==(a=t.interpretHeader)&&void 0!==a&&a,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:function(e){return e>=200&&e<400}},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(o=t.modifiedSince)&&void 0!==o&&o,staleIfError:null!==(s=t.staleIfError)&&void 0!==s&&s,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function j(e,t){return void 0===t&&(t=""),w({find:function(r){var a=e.getItem(t+r);return a?JSON.parse(a):void 0},set:function(r,a){e.setItem(t+r,JSON.stringify(a))},remove:function(r){e.removeItem(t+r)}})}}(),a}()})); | ||
//# sourceMappingURL=es5.map | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return function(){var e={549:function(e,t){var r,a;r=t,a=Symbol("fast-defer"),r.deferred=function(){var e,t,r=new Promise((function(r,a){e=r,t=a}));return r.resolve=e,r.reject=t,r[a]=1,r},r.isDeferred=function(e){return!!e&&!!e[a]}},246:function(e,t){var r;(r=t).transform=function(e){var t=typeof e;if("object"===t&&e){if(e instanceof Date)return"#"+e.getTime();if(e instanceof RegExp)return"#"+e.toString();var a=Array.isArray(e)?[]:{};for(var n in e)a[n]=r.transform(e[n]);return"#"+String(e.constructor)+JSON.stringify(a,Object.keys(a).sort())}return t+String(e)+("symbol"===t?Math.random():"")},r.code=function(e){e=r.transform(e);for(var t=7,a=0;a<e.length;)t=31*t+e.charCodeAt(a++)&9007199254740991;return t}}},t={};function r(a){var n=t[a];if(void 0!==n)return n.exports;var o=t[a]={exports:{}};return e[a](o,o.exports,r),o.exports}r.d=function(e,t){for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return function(){"use strict";r.r(a),r.d(a,{Header:function(){return o},buildKeyGenerator:function(){return A},buildMemoryStorage:function(){return S},buildStorage:function(){return w},buildWebStorage:function(){return T},createCacheResponse:function(){return v},createValidateStatus:function(){return f},defaultHeaderInterpreter:function(){return i},defaultKeyGenerator:function(){return E},defaultRequestInterceptor:function(){return p},defaultResponseInterceptor:function(){return b},isMethodIn:function(){return l},isStorage:function(){return x},setupCache:function(){return j},testCachePredicate:function(){return g},updateCache:function(){return m},updateStaleRequest:function(){return h}});var e=Symbol("cache-parser");function t(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}var o=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),i=function(r){if(!r)return"not enough headers";var a=r[o.CacheControl];if(a){var i=function(r){var a=Object.defineProperty({},e,{enumerable:!1,value:1});if(!r||"string"!=typeof r)return a;var o=function(e){var t=e.toLowerCase().replace(/\s+/g,"").split(","),r={};for(var a in t){var n=t[a].split("=",2);r[n[0]]=1===n.length||n[1]}return r}(r);return n(o.immutable)&&(a.immutable=!0),t(o["max-age"])&&(a.maxAge=Number(o["max-age"])),t(o["max-stale"])&&(a.maxStale=Number(o["max-stale"])),t(o["min-fresh"])&&(a.minFresh=Number(o["min-fresh"])),n(o["must-revalidate"])&&(a.mustRevalidate=!0),n(o["must-understand"])&&(a.mustUnderstand=!0),n(o["no-cache"])&&(a.noCache=!0),n(o["no-store"])&&(a.noStore=!0),n(o["no-transform"])&&(a.noTransform=!0),n(o["only-if-cached"])&&(a.onlyIfCached=!0),n(o.private)&&(a.private=!0),n(o["proxy-revalidate"])&&(a.proxyRevalidate=!0),n(o.public)&&(a.public=!0),t(o["s-maxage"])&&(a.sMaxAge=Number(o["s-maxage"])),t(o["stale-if-error"])&&(a.staleIfError=Number(o["stale-if-error"])),t(o["stale-while-revalidate"])&&(a.staleWhileRevalidate=Number(o["stale-while-revalidate"])),a}(String(a)),s=i.noCache,c=i.noStore,u=i.mustRevalidate,d=i.maxAge,f=i.immutable;if(s||c)return"dont cache";if(f)return 31536e6;if(u)return 0;if(d){var l=r[o.Age];return l?1e3*(d-Number(l)):1e3*d}}var h=r[o.Expires];if(h){var v=Date.parse(String(h))-Date.now();return v>=0?v:"dont cache"}return"not enough headers"};var s=function(){return s=Object.assign||function(e){for(var t,r=1,a=arguments.length;r<a;r++)for(var n in t=arguments[r])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e},s.apply(this,arguments)};function c(e,t,r,a){return new(r||(r=Promise))((function(n,o){function i(e){try{c(a.next(e))}catch(e){o(e)}}function s(e){try{c(a.throw(e))}catch(e){o(e)}}function c(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(i,s)}c((a=a.apply(e,t||[])).next())}))}function u(e,t){var r,a,n,o,i={label:0,sent:function(){if(1&n[0])throw n[1];return n[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;i;)try{if(r=1,a&&(n=2&o[0]?a.return:o[0]?a.throw||((n=a.return)&&n.call(a),0):a.next)&&!(n=n.call(a,o[1])).done)return n;switch(a=0,n&&(o=[2&o[0],n.value]),o[0]){case 0:case 1:n=o;break;case 4:return i.label++,{value:o[1],done:!1};case 5:i.label++,a=o[1],o=[0];continue;case 7:o=i.ops.pop(),i.trys.pop();continue;default:if(!(n=i.trys,(n=n.length>0&&n[n.length-1])||6!==o[0]&&2!==o[0])){i=0;continue}if(3===o[0]&&(!n||o[1]>n[0]&&o[1]<n[3])){i.label=o[1];break}if(6===o[0]&&i.label<n[1]){i.label=n[1],n=o;break}if(n&&i.label<n[2]){i.label=n[2],i.ops.push(o);break}n[2]&&i.ops.pop(),i.trys.pop();continue}o=t.call(e,i)}catch(e){o=[6,e],a=0}finally{r=n=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}}Object.create;Object.create;var d=r(549);function f(e){return e?function(t){return e(t)||304===t}:function(e){return e>=200&&e<300||304===e}}function l(e,t){void 0===e&&(e="get"),void 0===t&&(t=[]),e=e.toLowerCase();for(var r=0,a=t;r<a.length;r++){if(a[r].toLowerCase()===e)return!0}return!1}function h(e,t){var r;t.headers||(t.headers={});var a=t.cache,n=a.etag,i=a.modifiedSince;if(n){var s=!0===n?null===(r=e.data)||void 0===r?void 0:r.headers[o.ETag]:n;s&&(t.headers[o.IfNoneMatch]=s)}i&&(t.headers[o.IfModifiedSince]=!0===i?e.data.headers[o.LastModified]||new Date(e.createdAt).toUTCString():i.toUTCString())}function v(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=s(s({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function p(e){var t=this,r=function(r){return c(t,void 0,void 0,(function(){var t,a,n,o,i;return u(this,(function(c){switch(c.label){case 0:return!1===r.cache?[2,r]:(r.cache=s(s({},e.defaults.cache),r.cache),l(r.method,r.cache.methods)?(t=r.id=e.generateKey(r),[4,e.storage.get(t)]):[2,r]);case 1:return"empty"!==(a=c.sent()).state&&"stale"!==a.state?[3,5]:e.waiting[t]?[4,e.storage.get(t)]:[3,3];case 2:return a=c.sent(),[3,5];case 3:return e.waiting[t]=(0,d.deferred)(),null===(i=e.waiting[t])||void 0===i||i.catch((function(){})),[4,e.storage.set(t,{state:"loading",previous:a.state,data:a.data,createdAt:a.createdAt})];case 4:return c.sent(),"stale"===a.state&&h(a,r),r.validateStatus=f(r.validateStatus),[2,r];case 5:return"loading"!==a.state?[3,12]:(o=e.waiting[t])?[3,7]:[4,e.storage.remove(t)];case 6:return c.sent(),[2,r];case 7:0,c.label=8;case 8:return c.trys.push([8,10,,11]),[4,o];case 9:return n=c.sent(),[3,11];case 10:return c.sent(),[2,r];case 11:return[3,13];case 12:n=a.data,c.label=13;case 13:return r.adapter=function(){return Promise.resolve({config:r,data:n.data,headers:n.headers,status:n.status,statusText:n.statusText,cached:!0,id:t})},[2,r]}}))}))};return{onFulfilled:r,apply:function(){return e.interceptors.request.use(r)}}}function g(e,t){var r;return c(this,void 0,void 0,(function(){var a,n,o,i,s,c,d,f,l,h,v,p;return u(this,(function(u){switch(u.label){case 0:return"function"==typeof t?[2,t(e)]:(a=t.statusCheck,n=t.responseMatch,o=t.containsHeaders,(s=a)?[4,a(e.status)]:[3,2]);case 1:s=!u.sent(),u.label=2;case 2:return(i=s)?[3,5]:(c=n)?[4,n(e)]:[3,4];case 3:c=!u.sent(),u.label=4;case 4:i=c,u.label=5;case 5:if(i)return[2,!1];if(!o)return[3,10];for(f in d=[],o)d.push(f);l=0,u.label=6;case 6:return l<d.length?(h=d[l],v=o[h],(p=v)?[4,v(null!==(r=e.headers[h.toLowerCase()])&&void 0!==r?r:e.headers[h])]:[3,8]):[3,10];case 7:p=!u.sent(),u.label=8;case 8:if(p)return[2,!1];u.label=9;case 9:return l++,[3,6];case 10:return[2,!0]}}))}))}function m(e,t,r){return c(this,void 0,void 0,(function(){var a,n,o,i,s,c,d;return u(this,(function(u){switch(u.label){case 0:for(n in a=[],r)a.push(n);o=0,u.label=1;case 1:return o<a.length?(i=a[o],"delete"!==(s=r[i])?[3,3]:[4,e.remove(i)]):[3,10];case 2:return u.sent(),[3,9];case 3:return[4,e.get(i)];case 4:return"loading"===(c=u.sent()).state?[3,9]:[4,s(c,t)];case 5:return"delete"!==(d=u.sent())?[3,7]:[4,e.remove(i)];case 6:return u.sent(),[3,9];case 7:return"ignore"===d?[3,9]:[4,e.set(i,d)];case 8:u.sent(),u.label=9;case 9:return o++,[3,1];case 10:return[2]}}))}))}function b(e){var t=this,r=function(r){return c(t,void 0,void 0,(function(){var t;return u(this,(function(a){switch(a.label){case 0:return[4,e.storage.remove(r)];case 1:return a.sent(),null===(t=e.waiting[r])||void 0===t||t.reject(null),delete e.waiting[r],[2]}}))}))},a=function(a){return c(t,void 0,void 0,(function(){var t,n,i,c,d,f,l,h,p,b,y,x;return u(this,(function(u){switch(u.label){case 0:return a.id=null!==(b=(x=a.config).id)&&void 0!==b?b:x.id=e.generateKey(a.config),null!==(y=a.cached)&&void 0!==y||(a.cached=!1),a.cached?[2,a]:a.config.cache?(t=a.config.cache,[4,e.storage.get(a.id)]):[2,s(s({},a),{cached:!1})];case 1:return"stale"===(n=u.sent()).state||"empty"===n.state||"cached"===n.state?[2,a]:(i=!n.data)?[4,g(a,t.cachePredicate)]:[3,3];case 2:i=!u.sent(),u.label=3;case 3:return i?[4,r(a.id)]:[3,5];case 4:return u.sent(),[2,a];case 5:for(c in o)c.startsWith("XAxiosCache")&&delete a.headers[c];return t.etag&&!0!==t.etag&&(a.headers[o.XAxiosCacheEtag]=t.etag),t.modifiedSince&&(a.headers[o.XAxiosCacheLastModified]=!0===t.modifiedSince?"use-cache-timestamp":t.modifiedSince.toUTCString()),d=t.ttl||-1,(null==t?void 0:t.interpretHeader)?"dont cache"!==(f=e.headerInterpreter(a.headers))?[3,7]:[4,r(a.id)]:[3,8];case 6:return u.sent(),[2,a];case 7:d="not enough headers"===f?d:f,u.label=8;case 8:return l=v(a,n.data),"function"!=typeof d?[3,10]:[4,d(a)];case 9:d=u.sent(),u.label=10;case 10:return t.staleIfError&&(a.headers[o.XAxiosCacheStaleIfError]=String(d)),(null==t?void 0:t.update)?[4,m(e.storage,a,t.update)]:[3,12];case 11:u.sent(),u.label=12;case 12:return h={state:"cached",ttl:d,createdAt:Date.now(),data:l},(p=e.waiting[a.id])&&(p.resolve(h.data),delete e.waiting[a.id]),[4,e.storage.set(a.id,h)];case 13:return u.sent(),[2,a]}}))}))},n=function(a){return c(t,void 0,void 0,(function(){var t,n,o,i,s,c;return u(this,(function(u){switch(u.label){case 0:if(!(t=a.config)||!1===t.cache||!t.id)throw a;return[4,e.storage.get(t.id)];case 1:return n=u.sent(),o=t.cache,"loading"===n.state&&"stale"===n.previous?[3,3]:[4,r(t.id)];case 2:throw u.sent(),a;case 3:return(null==o?void 0:o.staleIfError)?"function"!=typeof o.staleIfError?[3,5]:[4,o.staleIfError(a.response,n,a)]:[3,8];case 4:return s=u.sent(),[3,6];case 5:s=o.staleIfError,u.label=6;case 6:return!0===(i=s)||"number"==typeof i&&n.createdAt+i>Date.now()?(null===(c=e.waiting[t.id])||void 0===c||c.resolve(n.data),delete e.waiting[t.id],[4,e.storage.set(t.id,{state:"stale",createdAt:Date.now(),data:n.data})]):[3,8];case 7:return u.sent(),[2,{cached:!0,config:t,id:t.id,data:n.data.data,headers:n.data.headers,status:n.data.status,statusText:n.data.statusText}];case 8:throw a}}))}))};return{onFulfilled:a,onRejected:n,apply:function(){return e.interceptors.response.use(a,n)}}}var y=Symbol(),x=function(e){return!!e&&!!e[y]};function w(e){var t,r=this,a=e.set,n=e.find,i=e.remove;return(t={})[y]=1,t.set=a,t.remove=i,t.get=function(e){return c(r,void 0,void 0,(function(){var t,r;return u(this,(function(s){switch(s.label){case 0:return[4,n(e)];case 1:return(t=s.sent())?"cached"!==t.state||t.createdAt+t.ttl>Date.now()?[2,t]:t.data.headers&&(o.ETag in t.data.headers||o.LastModified in t.data.headers||o.XAxiosCacheEtag in t.data.headers||o.XAxiosCacheStaleIfError in t.data.headers||o.XAxiosCacheLastModified in t.data.headers)?(r={state:"stale",createdAt:t.createdAt,data:t.data},[4,a(e,r)]):[3,3]:[2,{state:"empty"}];case 2:return s.sent(),[2,r];case 3:return[4,i(e)];case 4:return s.sent(),[2,{state:"empty"}]}}))}))},t}function S(){var e=w({find:function(t){return e.data[t]},set:function(t,r){e.data[t]=r},remove:function(t){delete e.data[t]}});return e.data=Object.create(null),e}var C=r(246),I=/^\/|\/$/g;function A(e,t){return function(r){if(r.id)return r.id;r.baseURL&&(r.baseURL=r.baseURL.replace(I,"")),r.url&&(r.url=r.url.replace(I,"")),r.method&&(r.method=r.method.toLowerCase());var a=t(r);return e?(0,C.code)(a).toString():a}}var E=A(!0,(function(e){var t=e.baseURL,r=void 0===t?"":t,a=e.url,n=void 0===a?"":a,o=e.method;return{url:r+(r&&n?"/":"")+n,method:void 0===o?"get":o,params:e.params,data:e.data}}));function j(e,t){var r,a,n,o,s;void 0===t&&(t={});var c=e;if(c.storage=t.storage||S(),!x(c.storage))throw new Error("Use buildStorage() function");return c.generateKey=t.generateKey||E,c.waiting=t.waiting||{},c.headerInterpreter=t.headerInterpreter||i,c.requestInterceptor=t.requestInterceptor||p(c),c.responseInterceptor=t.responseInterceptor||b(c),c.debug=t.debug,c.defaults.cache={ttl:null!==(r=t.ttl)&&void 0!==r?r:3e5,interpretHeader:null!==(a=t.interpretHeader)&&void 0!==a&&a,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:function(e){return e>=200&&e<400}},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(o=t.modifiedSince)&&void 0!==o&&o,staleIfError:null!==(s=t.staleIfError)&&void 0!==s&&s,update:t.update||{}},c.requestInterceptor.apply(),c.responseInterceptor.apply(),c}function T(e,t){return void 0===t&&(t=""),w({find:function(r){var a=e.getItem(t+r);return a?JSON.parse(a):void 0},set:function(r,a){e.setItem(t+r,JSON.stringify(a))},remove:function(r){e.removeItem(t+r)}})}}(),a}()})); |
@@ -1,2 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{var e={549:(e,t)=>{var a,r;a=t,r=Symbol("fast-defer"),a.deferred=function(){var e,t,a=new Promise((function(a,r){e=a,t=r}));return a.resolve=e,a.reject=t,a[r]=1,a},a.isDeferred=function(e){return!!e&&!!e[r]}},246:(e,t)=>{var a;(a=t).transform=function(e){var t=typeof e;if("object"===t&&e){if(e instanceof Date)return"#"+e.getTime();if(e instanceof RegExp)return"#"+e.toString();var r=Array.isArray(e)?[]:{};for(var n in e)r[n]=a.transform(e[n]);return"#"+String(e.constructor)+JSON.stringify(r,Object.keys(r).sort())}return t+String(e)+("symbol"===t?Math.random():"")},a.code=function(e){e=a.transform(e);for(var t=7,r=0;r<e.length;)t=31*t+e.charCodeAt(r++)&9007199254740991;return t}}},t={};function a(r){var n=t[r];if(void 0!==n)return n.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,a),i.exports}a.d=(e,t)=>{for(var r in t)a.o(t,r)&&!a.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},a.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),a.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return(()=>{"use strict";a.r(r),a.d(r,{Header:()=>i,buildKeyGenerator:()=>S,buildMemoryStorage:()=>w,buildStorage:()=>y,buildWebStorage:()=>A,createCacheResponse:()=>f,createValidateStatus:()=>d,defaultHeaderInterpreter:()=>o,defaultKeyGenerator:()=>C,defaultRequestInterceptor:()=>l,defaultResponseInterceptor:()=>p,isMethodIn:()=>c,isStorage:()=>v,setupCache:()=>I,testCachePredicate:()=>h,updateCache:()=>g,updateStaleRequest:()=>u});var e=Symbol("cache-parser");function t(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}const i=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",ContentType:"content-type",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),o=a=>{if(!a)return"not enough headers";const r=a[i.CacheControl];if(r){const{noCache:o,noStore:s,mustRevalidate:d,maxAge:c,immutable:u}=function(a){var r=Object.defineProperty({},e,{enumerable:!1,value:1});if(!a||"string"!=typeof a)return r;var i=function(e){var t=e.toLowerCase().replace(/\s+/g,"").split(","),a={};for(var r in t){var n=t[r].split("=",2);a[n[0]]=1===n.length||n[1]}return a}(a);return n(i.immutable)&&(r.immutable=!0),t(i["max-age"])&&(r.maxAge=Number(i["max-age"])),t(i["max-stale"])&&(r.maxStale=Number(i["max-stale"])),t(i["min-fresh"])&&(r.minFresh=Number(i["min-fresh"])),n(i["must-revalidate"])&&(r.mustRevalidate=!0),n(i["must-understand"])&&(r.mustUnderstand=!0),n(i["no-cache"])&&(r.noCache=!0),n(i["no-store"])&&(r.noStore=!0),n(i["no-transform"])&&(r.noTransform=!0),n(i["only-if-cached"])&&(r.onlyIfCached=!0),n(i.private)&&(r.private=!0),n(i["proxy-revalidate"])&&(r.proxyRevalidate=!0),n(i.public)&&(r.public=!0),t(i["s-maxage"])&&(r.sMaxAge=Number(i["s-maxage"])),t(i["stale-if-error"])&&(r.staleIfError=Number(i["stale-if-error"])),t(i["stale-while-revalidate"])&&(r.staleWhileRevalidate=Number(i["stale-while-revalidate"])),r}(String(r));if(o||s)return"dont cache";if(u)return 31536e6;if(d)return 0;if(c){const e=a[i.Age];return e?1e3*(c-Number(e)):1e3*c}}const o=a[i.Expires];if(o){const e=Date.parse(String(o))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};var s=a(549);function d(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function c(e="get",t=[]){e=e.toLowerCase();for(const a of t)if(a.toLowerCase()===e)return!0;return!1}function u(e,t){var a;t.headers||(t.headers={});const{etag:r,modifiedSince:n}=t.cache;if(r){const n=!0===r?null===(a=e.data)||void 0===a?void 0:a.headers[i.ETag]:r;n&&(t.headers[i.IfNoneMatch]=n)}n&&(t.headers[i.IfModifiedSince]=!0===n?e.data.headers[i.LastModified]||new Date(e.createdAt).toUTCString():n.toUTCString())}function f(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function l(e){const t=async t=>{var a;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!c(t.method,t.cache.methods))return t;const r=t.id=e.generateKey(t);let n,i=await e.storage.get(r);e:if("empty"===i.state||"stale"===i.state){if(e.waiting[r]){i=await e.storage.get(r);break e}return e.waiting[r]=(0,s.deferred)(),null===(a=e.waiting[r])||void 0===a||a.catch((()=>{})),await e.storage.set(r,{state:"loading",previous:i.state,data:i.data,createdAt:i.createdAt}),"stale"===i.state&&u(i,t),t.validateStatus=d(t.validateStatus),t}if("loading"===i.state){const a=e.waiting[r];if(!a)return await e.storage.remove(r),t;try{n=await a}catch(e){return t}}else n=i.data;return t.adapter=()=>Promise.resolve({config:t,data:n.data,headers:n.headers,status:n.status,statusText:n.statusText,cached:!0,id:r}),t};return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}async function h(e,t){var a;if("function"==typeof t)return t(e);const{statusCheck:r,responseMatch:n,containsHeaders:i}=t;if(r&&!await r(e.status)||n&&!await n(e))return!1;if(i)for(const t in i){const r=i[t];if(r&&!await r(null!==(a=e.headers[t.toLowerCase()])&&void 0!==a?a:e.headers[t]))return!1}return!0}async function g(e,t,a){for(const r in a){const n=a[r];if("delete"===n){await e.remove(r);continue}const i=await e.get(r);if("loading"===i.state)continue;const o=await n(i,t);"delete"!==o?"ignore"!==o&&await e.set(r,o):await e.remove(r)}}function p(e){const t=async t=>{var a;await e.storage.remove(t),null===(a=e.waiting[t])||void 0===a||a.reject(null),delete e.waiting[t]},a=async a=>{var r,n,o,s;if(a.id=null!==(r=(s=a.config).id)&&void 0!==r?r:s.id=e.generateKey(a.config),null!==(n=a.cached)&&void 0!==n||(a.cached=!1),a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const d=a.config.cache,c=await e.storage.get(a.id);if("stale"===c.state||"empty"===c.state||"cached"===c.state)return a;if(!c.data&&!await h(a,d.cachePredicate))return await t(a.id),a;for(const e in i)e.startsWith("XAxiosCache")&&delete a.headers[e];d.etag&&!0!==d.etag&&(a.headers[i.XAxiosCacheEtag]=d.etag),d.modifiedSince&&(a.headers[i.XAxiosCacheLastModified]=!0===d.modifiedSince?"use-cache-timestamp":d.modifiedSince.toUTCString());let u=d.ttl||-1;if(null==d?void 0:d.interpretHeader){const r=e.headerInterpreter(a.headers);if("dont cache"===r)return await t(a.id),a;u="not enough headers"===r?u:r}const l=f(a,c.data);"function"==typeof u&&(u=await u(a)),d.staleIfError&&(a.headers[i.XAxiosCacheStaleIfError]=String(u)),(null==d?void 0:d.update)&&await g(e.storage,a,d.update);const p={state:"cached",ttl:u,createdAt:Date.now(),data:l};return null===(o=e.waiting[a.id])||void 0===o||o.resolve(p.data),delete e.waiting[a.id],await e.storage.set(a.id,p),a},r=async a=>{var r;const n=a.config;if(!n||!1===n.cache||!n.id)throw a;const i=await e.storage.get(n.id),o=n.cache;if("loading"!==i.state||"stale"!==i.previous)throw await t(n.id),a;if(null==o?void 0:o.staleIfError){const t="function"==typeof o.staleIfError?await o.staleIfError(a.response,i,a):o.staleIfError;if(!0===t||"number"==typeof t&&i.createdAt+t>Date.now())return null===(r=e.waiting[n.id])||void 0===r||r.resolve(i.data),delete e.waiting[n.id],await e.storage.set(n.id,{state:"stale",createdAt:Date.now(),data:i.data}),{cached:!0,config:n,id:n.id,data:i.data.data,headers:i.data.headers,status:i.data.status,statusText:i.data.statusText}}throw a};return{onFulfilled:a,onRejected:r,apply:()=>e.interceptors.response.use(a,r)}}const m=Symbol(),v=e=>!!e&&!!e[m];function y({set:e,find:t,remove:a}){return{[m]:1,set:e,remove:a,get:async r=>{const n=await t(r);if(!n)return{state:"empty"};if("cached"!==n.state||n.createdAt+n.ttl>Date.now())return n;if(n.data.headers&&(i.ETag in n.data.headers||i.LastModified in n.data.headers||i.XAxiosCacheEtag in n.data.headers||i.XAxiosCacheStaleIfError in n.data.headers||i.XAxiosCacheLastModified in n.data.headers)){const t={state:"stale",createdAt:n.createdAt,data:n.data};return await e(r,t),t}return await a(r),{state:"empty"}}}}function w(){const e={},t=y({find:t=>e[t],set:(t,a)=>{e[t]=a},remove:t=>{delete e[t]}});return Object.assign(Object.assign({},t),{data:e})}var b=a(246);const x=/^\/|\/$/g;function S(e,t){return a=>{if(a.id)return a.id;a.baseURL&&(a.baseURL=a.baseURL.replace(x,"")),a.url&&(a.url=a.url.replace(x,"")),a.method&&(a.method=a.method.toLowerCase());const r=t(a);return e?(0,b.code)(r).toString():r}}const C=S(!0,(({baseURL:e="",url:t="",method:a="get",params:r,data:n})=>({url:e+(e&&t?"/":"")+t,method:a,params:r,data:n})));function I(e,t={}){var a,r,n,i,s;const d=e;if(d.storage=t.storage||w(),!v(d.storage))throw new Error("Use buildStorage() function");return d.generateKey=t.generateKey||C,d.waiting=t.waiting||{},d.headerInterpreter=t.headerInterpreter||o,d.requestInterceptor=t.requestInterceptor||l(d),d.responseInterceptor=t.responseInterceptor||p(d),d.defaults.cache={ttl:null!==(a=t.ttl)&&void 0!==a?a:3e5,interpretHeader:null!==(r=t.interpretHeader)&&void 0!==r&&r,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(i=t.modifiedSince)&&void 0!==i&&i,staleIfError:null!==(s=t.staleIfError)&&void 0!==s&&s,update:t.update||{}},d.requestInterceptor.apply(),d.responseInterceptor.apply(),d}function A(e,t=""){return y({find:a=>{const r=e.getItem(t+a);return r?JSON.parse(r):void 0},set:(a,r)=>{e.setItem(t+a,JSON.stringify(r))},remove:a=>{e.removeItem(t+a)}})}})(),r})()})); | ||
//# sourceMappingURL=index.map | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.AxiosCacheInterceptor=t():e.AxiosCacheInterceptor=t()}("undefined"!=typeof self?self:this,(function(){return(()=>{var e={549:(e,t)=>{var r,a;r=t,a=Symbol("fast-defer"),r.deferred=function(){var e,t,r=new Promise((function(r,a){e=r,t=a}));return r.resolve=e,r.reject=t,r[a]=1,r},r.isDeferred=function(e){return!!e&&!!e[a]}},246:(e,t)=>{var r;(r=t).transform=function(e){var t=typeof e;if("object"===t&&e){if(e instanceof Date)return"#"+e.getTime();if(e instanceof RegExp)return"#"+e.toString();var a=Array.isArray(e)?[]:{};for(var n in e)a[n]=r.transform(e[n]);return"#"+String(e.constructor)+JSON.stringify(a,Object.keys(a).sort())}return t+String(e)+("symbol"===t?Math.random():"")},r.code=function(e){e=r.transform(e);for(var t=7,a=0;a<e.length;)t=31*t+e.charCodeAt(a++)&9007199254740991;return t}}},t={};function r(a){var n=t[a];if(void 0!==n)return n.exports;var i=t[a]={exports:{}};return e[a](i,i.exports,r),i.exports}r.d=(e,t)=>{for(var a in t)r.o(t,a)&&!r.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var a={};return(()=>{"use strict";r.r(a),r.d(a,{Header:()=>i,buildKeyGenerator:()=>C,buildMemoryStorage:()=>x,buildStorage:()=>b,buildWebStorage:()=>j,createCacheResponse:()=>l,createValidateStatus:()=>c,defaultHeaderInterpreter:()=>o,defaultKeyGenerator:()=>I,defaultRequestInterceptor:()=>h,defaultResponseInterceptor:()=>m,isMethodIn:()=>u,isStorage:()=>y,setupCache:()=>A,testCachePredicate:()=>g,updateCache:()=>p,updateStaleRequest:()=>f});var e=Symbol("cache-parser");function t(e){return("string"==typeof e||"number"==typeof e)&&(e=Number(e))>=0&&e<1/0}function n(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}const i=Object.freeze({IfModifiedSince:"if-modified-since",LastModified:"last-modified",IfNoneMatch:"if-none-match",CacheControl:"cache-control",ETag:"etag",Expires:"expires",Age:"age",XAxiosCacheEtag:"x-axios-cache-etag",XAxiosCacheLastModified:"x-axios-cache-last-modified",XAxiosCacheStaleIfError:"x-axios-cache-stale-if-error"}),o=r=>{if(!r)return"not enough headers";const a=r[i.CacheControl];if(a){const{noCache:o,noStore:s,mustRevalidate:d,maxAge:c,immutable:u}=function(r){var a=Object.defineProperty({},e,{enumerable:!1,value:1});if(!r||"string"!=typeof r)return a;var i=function(e){var t=e.toLowerCase().replace(/\s+/g,"").split(","),r={};for(var a in t){var n=t[a].split("=",2);r[n[0]]=1===n.length||n[1]}return r}(r);return n(i.immutable)&&(a.immutable=!0),t(i["max-age"])&&(a.maxAge=Number(i["max-age"])),t(i["max-stale"])&&(a.maxStale=Number(i["max-stale"])),t(i["min-fresh"])&&(a.minFresh=Number(i["min-fresh"])),n(i["must-revalidate"])&&(a.mustRevalidate=!0),n(i["must-understand"])&&(a.mustUnderstand=!0),n(i["no-cache"])&&(a.noCache=!0),n(i["no-store"])&&(a.noStore=!0),n(i["no-transform"])&&(a.noTransform=!0),n(i["only-if-cached"])&&(a.onlyIfCached=!0),n(i.private)&&(a.private=!0),n(i["proxy-revalidate"])&&(a.proxyRevalidate=!0),n(i.public)&&(a.public=!0),t(i["s-maxage"])&&(a.sMaxAge=Number(i["s-maxage"])),t(i["stale-if-error"])&&(a.staleIfError=Number(i["stale-if-error"])),t(i["stale-while-revalidate"])&&(a.staleWhileRevalidate=Number(i["stale-while-revalidate"])),a}(String(a));if(o||s)return"dont cache";if(u)return 31536e6;if(d)return 0;if(c){const e=r[i.Age];return e?1e3*(c-Number(e)):1e3*c}}const o=r[i.Expires];if(o){const e=Date.parse(String(o))-Date.now();return e>=0?e:"dont cache"}return"not enough headers"};function s(e,t,r,a){return new(r||(r=Promise))((function(n,i){function o(e){try{d(a.next(e))}catch(e){i(e)}}function s(e){try{d(a.throw(e))}catch(e){i(e)}}function d(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(o,s)}d((a=a.apply(e,t||[])).next())}))}Object.create;Object.create;var d=r(549);function c(e){return e?t=>e(t)||304===t:e=>e>=200&&e<300||304===e}function u(e="get",t=[]){e=e.toLowerCase();for(const r of t)if(r.toLowerCase()===e)return!0;return!1}function f(e,t){var r;t.headers||(t.headers={});const{etag:a,modifiedSince:n}=t.cache;if(a){const n=!0===a?null===(r=e.data)||void 0===r?void 0:r.headers[i.ETag]:a;n&&(t.headers[i.IfNoneMatch]=n)}n&&(t.headers[i.IfModifiedSince]=!0===n?e.data.headers[i.LastModified]||new Date(e.createdAt).toUTCString():n.toUTCString())}function l(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=Object.assign(Object.assign({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}}function h(e){const t=t=>s(this,void 0,void 0,(function*(){var r;if(!1===t.cache)return t;if(t.cache=Object.assign(Object.assign({},e.defaults.cache),t.cache),!u(t.method,t.cache.methods))return t;const a=t.id=e.generateKey(t);let n,i=yield e.storage.get(a);e:if("empty"===i.state||"stale"===i.state){if(e.waiting[a]){i=yield e.storage.get(a);break e}return e.waiting[a]=(0,d.deferred)(),null===(r=e.waiting[a])||void 0===r||r.catch((()=>{})),yield e.storage.set(a,{state:"loading",previous:i.state,data:i.data,createdAt:i.createdAt}),"stale"===i.state&&f(i,t),t.validateStatus=c(t.validateStatus),t}if("loading"===i.state){const r=e.waiting[a];if(!r)return yield e.storage.remove(a),t;0;try{n=yield r}catch(e){return t}}else n=i.data;return t.adapter=()=>Promise.resolve({config:t,data:n.data,headers:n.headers,status:n.status,statusText:n.statusText,cached:!0,id:a}),t}));return{onFulfilled:t,apply:()=>e.interceptors.request.use(t)}}function g(e,t){var r;return s(this,void 0,void 0,(function*(){if("function"==typeof t)return t(e);const{statusCheck:a,responseMatch:n,containsHeaders:i}=t;if(a&&!(yield a(e.status))||n&&!(yield n(e)))return!1;if(i)for(const t in i){const a=i[t];if(a&&!(yield a(null!==(r=e.headers[t.toLowerCase()])&&void 0!==r?r:e.headers[t])))return!1}return!0}))}function p(e,t,r){return s(this,void 0,void 0,(function*(){for(const a in r){const n=r[a];if("delete"===n){yield e.remove(a);continue}const i=yield e.get(a);if("loading"===i.state)continue;const o=yield n(i,t);"delete"!==o?"ignore"!==o&&(yield e.set(a,o)):yield e.remove(a)}}))}function m(e){const t=t=>s(this,void 0,void 0,(function*(){var r;yield e.storage.remove(t),null===(r=e.waiting[t])||void 0===r||r.reject(null),delete e.waiting[t]})),r=r=>s(this,void 0,void 0,(function*(){var a,n,o;if(r.id=null!==(a=(o=r.config).id)&&void 0!==a?a:o.id=e.generateKey(r.config),null!==(n=r.cached)&&void 0!==n||(r.cached=!1),r.cached)return r;if(!r.config.cache)return Object.assign(Object.assign({},r),{cached:!1});const s=r.config.cache,d=yield e.storage.get(r.id);if("stale"===d.state||"empty"===d.state||"cached"===d.state)return r;if(!d.data&&!(yield g(r,s.cachePredicate)))return yield t(r.id),r;for(const e in i)e.startsWith("XAxiosCache")&&delete r.headers[e];s.etag&&!0!==s.etag&&(r.headers[i.XAxiosCacheEtag]=s.etag),s.modifiedSince&&(r.headers[i.XAxiosCacheLastModified]=!0===s.modifiedSince?"use-cache-timestamp":s.modifiedSince.toUTCString());let c=s.ttl||-1;if(null==s?void 0:s.interpretHeader){const a=e.headerInterpreter(r.headers);if("dont cache"===a)return yield t(r.id),r;c="not enough headers"===a?c:a}const u=l(r,d.data);"function"==typeof c&&(c=yield c(r)),s.staleIfError&&(r.headers[i.XAxiosCacheStaleIfError]=String(c)),(null==s?void 0:s.update)&&(yield p(e.storage,r,s.update));const f={state:"cached",ttl:c,createdAt:Date.now(),data:u},h=e.waiting[r.id];return h&&(h.resolve(f.data),delete e.waiting[r.id]),yield e.storage.set(r.id,f),r})),a=r=>s(this,void 0,void 0,(function*(){var a;const n=r.config;if(!n||!1===n.cache||!n.id)throw r;const i=yield e.storage.get(n.id),o=n.cache;if("loading"!==i.state||"stale"!==i.previous)throw yield t(n.id),r;if(null==o?void 0:o.staleIfError){const t="function"==typeof o.staleIfError?yield o.staleIfError(r.response,i,r):o.staleIfError;if(!0===t||"number"==typeof t&&i.createdAt+t>Date.now())return null===(a=e.waiting[n.id])||void 0===a||a.resolve(i.data),delete e.waiting[n.id],yield e.storage.set(n.id,{state:"stale",createdAt:Date.now(),data:i.data}),{cached:!0,config:n,id:n.id,data:i.data.data,headers:i.data.headers,status:i.data.status,statusText:i.data.statusText}}throw r}));return{onFulfilled:r,onRejected:a,apply:()=>e.interceptors.response.use(r,a)}}const v=Symbol(),y=e=>!!e&&!!e[v];function b({set:e,find:t,remove:r}){return{[v]:1,set:e,remove:r,get:a=>s(this,void 0,void 0,(function*(){const n=yield t(a);if(!n)return{state:"empty"};if("cached"!==n.state||n.createdAt+n.ttl>Date.now())return n;if(n.data.headers&&(i.ETag in n.data.headers||i.LastModified in n.data.headers||i.XAxiosCacheEtag in n.data.headers||i.XAxiosCacheStaleIfError in n.data.headers||i.XAxiosCacheLastModified in n.data.headers)){const t={state:"stale",createdAt:n.createdAt,data:n.data};return yield e(a,t),t}return yield r(a),{state:"empty"}}))}}function x(){const e=b({find:t=>e.data[t],set:(t,r)=>{e.data[t]=r},remove:t=>{delete e.data[t]}});return e.data=Object.create(null),e}var S=r(246);const w=/^\/|\/$/g;function C(e,t){return r=>{if(r.id)return r.id;r.baseURL&&(r.baseURL=r.baseURL.replace(w,"")),r.url&&(r.url=r.url.replace(w,"")),r.method&&(r.method=r.method.toLowerCase());const a=t(r);return e?(0,S.code)(a).toString():a}}const I=C(!0,(({baseURL:e="",url:t="",method:r="get",params:a,data:n})=>({url:e+(e&&t?"/":"")+t,method:r,params:a,data:n})));function A(e,t={}){var r,a,n,i,s;const d=e;if(d.storage=t.storage||x(),!y(d.storage))throw new Error("Use buildStorage() function");return d.generateKey=t.generateKey||I,d.waiting=t.waiting||{},d.headerInterpreter=t.headerInterpreter||o,d.requestInterceptor=t.requestInterceptor||h(d),d.responseInterceptor=t.responseInterceptor||m(d),d.debug=t.debug,d.defaults.cache={ttl:null!==(r=t.ttl)&&void 0!==r?r:3e5,interpretHeader:null!==(a=t.interpretHeader)&&void 0!==a&&a,methods:t.methods||["get"],cachePredicate:t.cachePredicate||{statusCheck:e=>e>=200&&e<400},etag:null!==(n=t.etag)&&void 0!==n&&n,modifiedSince:null!==(i=t.modifiedSince)&&void 0!==i&&i,staleIfError:null!==(s=t.staleIfError)&&void 0!==s&&s,update:t.update||{}},d.requestInterceptor.apply(),d.responseInterceptor.apply(),d}function j(e,t=""){return b({find:r=>{const a=e.getItem(t+r);return a?JSON.parse(a):void 0},set:(r,a)=>{e.setItem(t+r,JSON.stringify(a))},remove:r=>{e.removeItem(t+r)}})}})(),a})()})); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67
374749
80
2468
3
1