axios-cache-interceptor
Advanced tools
Comparing version 0.7.7 to 0.7.8
@@ -1,3 +0,2 @@ | ||
/*! For license information please see index.min.js.LICENSE.txt */ | ||
!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()}(self,(function(){return(()=>{var e={86:(e,t)=>{!function(e){var t=Symbol("cache-parser"),r=Number;function a(e){return("string"==typeof e||"number"==typeof e)&&(e=r(e))>=0&&e<1/0}function n(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}e.__internal={isDuration:a,toBoolean:n},e.isCacheControl=function(e){return!!e&&!!e[t]},e.tokenize=function(e){if(!e||"object"!=typeof e)return[];var t=[];return n(e.immutable)&&t.push("immutable"),a(e.maxAge)&&t.push("max-age="+r(e.maxAge)),a(e.maxStale)&&t.push("max-stale="+r(e.maxStale)),a(e.minFresh)&&t.push("min-fresh="+r(e.minFresh)),n(e.mustRevalidate)&&t.push("must-revalidate"),n(e.mustUnderstand)&&t.push("must-understand"),n(e.noCache)&&t.push("no-cache"),n(e.noStore)&&t.push("no-store"),n(e.noTransform)&&t.push("no-transform"),n(e.onlyIfCached)&&t.push("only-if-cached"),n(e.private)&&t.push("private"),n(e.proxyRevalidate)&&t.push("proxy-revalidate"),n(e.public)&&t.push("public"),a(e.sMaxAge)&&t.push("s-maxage="+r(e.sMaxAge)),a(e.staleIfError)&&t.push("stale-if-error="+r(e.staleIfError)),a(e.staleWhileRevalidate)&&t.push("stale-while-revalidate="+r(e.staleWhileRevalidate)),t},e.parse=function(e){var o=Object.defineProperty({},t,{enumerable:!1,value:1});if(!e||"string"!=typeof e)return o;var i={},s=e.toLowerCase().replace(/\s+/g,"").split(",");for(var c in s){var u=s[c].split("=",2);i[u[0]]=1===u.length||u[1]}return n(i.immutable)&&(o.immutable=!0),a(i["max-age"])&&(o.maxAge=r(i["max-age"])),a(i["max-stale"])&&(o.maxStale=r(i["max-stale"])),a(i["min-fresh"])&&(o.minFresh=r(i["min-fresh"])),n(i["must-revalidate"])&&(o.mustRevalidate=!0),n(i["must-understand"])&&(o.mustUnderstand=!0),n(i["no-cache"])&&(o.noCache=!0),n(i["no-store"])&&(o.noStore=!0),n(i["no-transform"])&&(o.noTransform=!0),n(i["only-if-cached"])&&(o.onlyIfCached=!0),n(i.private)&&(o.private=!0),n(i["proxy-revalidate"])&&(o.proxyRevalidate=!0),n(i.public)&&(o.public=!0),a(i["s-maxage"])&&(o.sMaxAge=r(i["s-maxage"])),a(i["stale-if-error"])&&(o.staleIfError=r(i["stale-if-error"])),a(i["stale-while-revalidate"])&&(o.staleWhileRevalidate=r(i["stale-while-revalidate"])),o}}(t)},549:(e,t)=>{var r,a;r=t,a=Symbol("fast-defer"),r.deferred=function(){var e,t,r=new Promise(((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]}},441:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.useCache=t.createCache=void 0;var a=r(655),n=r(772),o=r(975),i=r(731),s=r(145),c=r(481);function u(e,t){void 0===t&&(t={});var r=t.storage,u=t.generateKey,d=t.waiting,l=t.headerInterpreter,f=t.requestInterceptor,h=t.responseInterceptor,p=(0,a.__rest)(t,["storage","generateKey","waiting","headerInterpreter","requestInterceptor","responseInterceptor"]),v=e;return v.storage=r||new s.MemoryAxiosStorage,v.generateKey=u||c.defaultKeyGenerator,v.waiting=d||{},v.headerInterpreter=l||n.defaultHeaderInterpreter,v.requestInterceptor=f||new o.CacheRequestInterceptor(v),v.responseInterceptor=h||new i.CacheResponseInterceptor(v),v.defaults=(0,a.__assign)((0,a.__assign)({},e.defaults),{cache:(0,a.__assign)({ttl:3e5,interpretHeader:!1,methods:["get"],cachePredicate:{statusCheck:[200,399]},etag:!1,modifiedSince:!1,update:{}},p)}),v.requestInterceptor.use(),v.responseInterceptor.use(),v}t.createCache=u,t.useCache=u},772:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.defaultHeaderInterpreter=void 0;var a=r(86),n=r(750);t.defaultHeaderInterpreter=function(e){return void 0===e&&(e={}),n.Header.CacheControl in e?i(e[n.Header.CacheControl],e):n.Header.Expires in e?o(e[n.Header.Expires],e):void 0};var o=function(e){var t=Date.parse(e)-Date.now();return t>=0&&t},i=function(e,t){var r=(0,a.parse)(e),o=r.noCache,i=r.noStore,s=r.mustRevalidate,c=r.maxAge,u=r.immutable;if(o||i)return!1;if(u)return 31536e6;if(s)return 0;if(c){var d=t[n.Header.Age];return d?1e3*(c-Number(d)):1e3*c}}},54:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});var a=r(655);(0,a.__exportStar)(r(441),t),(0,a.__exportStar)(r(931),t),(0,a.__exportStar)(r(145),t),(0,a.__exportStar)(r(499),t)},975:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CacheRequestInterceptor=void 0;var a=r(655),n=r(549),o=r(750),i=function(){function e(t){var r=this;this.axios=t,this.use=function(){r.axios.interceptors.request.use(r.onFulfilled)},this.onFulfilled=function(t){return(0,a.__awaiter)(r,void 0,void 0,(function(){var r,o,i,s,c;return(0,a.__generator)(this,(function(u){switch(u.label){case 0:return!1===t.cache?[2,t]:(t.cache=(0,a.__assign)((0,a.__assign)({},this.axios.defaults.cache),t.cache),e.isMethodAllowed(t.method,t.cache)?(r=this.axios.generateKey(t),[4,this.axios.storage.get(r)]):[2,t]);case 1:return"empty"!=(o=u.sent()).state&&"stale"!==o.state?[3,5]:this.axios.waiting[r]?[4,this.axios.storage.get(r)]:[3,3];case 2:return o=u.sent(),[3,5];case 3:return this.axios.waiting[r]=(0,n.deferred)(),null===(c=this.axios.waiting[r])||void 0===c||c.catch((function(){})),[4,this.axios.storage.set(r,{state:"loading",data:o.data})];case 4:return u.sent(),"stale"===o.state&&e.setRevalidationHeaders(o,t),t.validateStatus=e.createValidateStatus(t.validateStatus),[2,t];case 5:return"loading"!==o.state?[3,11]:(s=this.axios.waiting[r])?[3,7]:[4,this.axios.storage.remove(r)];case 6:return u.sent(),[2,t];case 7:return u.trys.push([7,9,,10]),[4,s];case 8:return i=u.sent(),[3,10];case 9:return u.sent(),[2,t];case 10:return[3,12];case 11:i=o.data,u.label=12;case 12:return t.adapter=function(){return Promise.resolve({config:t,data:i.data,headers:i.headers,status:i.status,statusText:i.statusText,cached:!0,id:r})},[2,t]}}))}))}}return e.isMethodAllowed=function(e,t){var r,n,o=e.toLowerCase();try{for(var i=(0,a.__values)(t.methods||[]),s=i.next();!s.done;s=i.next()){if(s.value.toLowerCase()===o)return!0}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}return!1},e.setRevalidationHeaders=function(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.Header.ETag]:n;s&&(t.headers[o.Header.IfNoneMatch]=s)}i&&(t.headers[o.Header.IfModifiedSince]=!0===i?e.data.headers[o.Header.LastModified]||new Date(e.createdAt).toUTCString():i.toUTCString())},e.createValidateStatus=function(e){return function(t){return e?e(t)||304===t:t>=200&&t<300||304===t}},e}();t.CacheRequestInterceptor=i},731:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.CacheResponseInterceptor=void 0;var a=r(655),n=r(916),o=r(750),i=r(786),s=function(){function e(t){var r=this;this.axios=t,this.use=function(){r.axios.interceptors.response.use(r.onFulfilled)},this.onFulfilled=function(t){return(0,a.__awaiter)(r,void 0,void 0,(function(){var r,s,c,u,d,l,f,h;return(0,a.__generator)(this,(function(p){switch(p.label){case 0:return(r=this.cachedResponse(t)).cached?[2,r]:r.config.cache?(s=r.config.cache,[4,this.axios.storage.get(r.id)]):[2,(0,a.__assign)((0,a.__assign)({},r),{cached:!1})];case 1:return"stale"===(c=p.sent()).state||"empty"===c.state||"cached"===c.state?[2,r]:c.data||(0,n.shouldCacheResponse)(r,s)?[3,3]:[4,this.rejectResponse(r.id)];case 2:return p.sent(),[2,r];case 3:return delete r.headers[o.Header.XAxiosCacheEtag],delete r.headers[o.Header.XAxiosCacheLastModified],s.etag&&!0!==s.etag&&(r.headers[o.Header.XAxiosCacheEtag]=s.etag),s.modifiedSince&&(r.headers[o.Header.XAxiosCacheLastModified]=!0===s.modifiedSince?"use-cache-timestamp":s.modifiedSince.toUTCString()),u=s.ttl||-1,(null==s?void 0:s.interpretHeader)?!1!==(d=this.axios.headerInterpreter(r.headers))?[3,5]:[4,this.rejectResponse(r.id)]:[3,6];case 4:return p.sent(),[2,r];case 5:u=d||0===d?d:u,p.label=6;case 6:return l=e.createCacheData(r,c.data),f={state:"cached",ttl:u,createdAt:Date.now(),data:l},(null==s?void 0:s.update)&&(0,i.updateCache)(this.axios.storage,r.data,s.update),[4,null==(h=this.axios.waiting[r.id])?void 0:h.resolve(f.data)];case 7:return p.sent(),delete this.axios.waiting[r.id],[4,this.axios.storage.set(r.id,f)];case 8:return p.sent(),[2,r]}}))}))},this.rejectResponse=function(e){return(0,a.__awaiter)(r,void 0,void 0,(function(){var t;return(0,a.__generator)(this,(function(r){switch(r.label){case 0:return[4,this.axios.storage.remove(e)];case 1:return r.sent(),null===(t=this.axios.waiting[e])||void 0===t||t.reject(null),delete this.axios.waiting[e],[2]}}))}))},this.cachedResponse=function(e){return(0,a.__assign)({id:r.axios.generateKey(e.config),cached:e.cached||!1},e)}}return e.createCacheData=function(e,t){return 304===e.status&&t?(e.cached=!0,e.data=t.data,e.status=t.status,e.statusText=t.statusText,e.headers=(0,a.__assign)((0,a.__assign)({},t.headers),e.headers),t):{data:e.data,status:e.status,statusText:e.statusText,headers:e.headers}},e}();t.CacheResponseInterceptor=s},931:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.BrowserAxiosStorage=void 0;var a=r(655),n=function(e){function t(r,n){void 0===n&&(n=t.DEFAULT_KEY_PREFIX);var o=e.call(this)||this;return o.storage=r,o.prefix=n,o.find=function(e){return(0,a.__awaiter)(o,void 0,void 0,(function(){var t;return(0,a.__generator)(this,(function(r){return[2,(t=this.storage.getItem("".concat(this.prefix,":").concat(e)))?JSON.parse(t):{state:"empty"}]}))}))},o.set=function(e,t){return(0,a.__awaiter)(o,void 0,void 0,(function(){return(0,a.__generator)(this,(function(r){return[2,this.storage.setItem("".concat(this.prefix,":").concat(e),JSON.stringify(t))]}))}))},o.remove=function(e){return(0,a.__awaiter)(o,void 0,void 0,(function(){return(0,a.__generator)(this,(function(t){return[2,this.storage.removeItem("".concat(this.prefix,":").concat(e))]}))}))},o}return(0,a.__extends)(t,e),t.DEFAULT_KEY_PREFIX="a-c-i",t}(r(499).AxiosStorage);t.BrowserAxiosStorage=n},145:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.MemoryAxiosStorage=void 0;var a=r(655),n=function(e){function t(t){void 0===t&&(t={});var r=e.call(this)||this;return r.storage=t,r.find=function(e){return(0,a.__awaiter)(r,void 0,void 0,(function(){return(0,a.__generator)(this,(function(t){return[2,this.storage[e]||{state:"empty"}]}))}))},r.set=function(e,t){return(0,a.__awaiter)(r,void 0,void 0,(function(){return(0,a.__generator)(this,(function(r){return this.storage[e]=t,[2]}))}))},r.remove=function(e){return(0,a.__awaiter)(r,void 0,void 0,(function(){return(0,a.__generator)(this,(function(t){return delete this.storage[e],[2]}))}))},r}return(0,a.__extends)(t,e),t}(r(499).AxiosStorage);t.MemoryAxiosStorage=n},499:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.AxiosStorage=void 0;var a=r(655),n=r(750),o=function(){function e(){var t=this;this.get=function(r){return(0,a.__awaiter)(t,void 0,void 0,(function(){var t,n;return(0,a.__generator)(this,(function(a){switch(a.label){case 0:return[4,this.find(r)];case 1:return"cached"!==(t=a.sent()).state||t.createdAt+t.ttl>Date.now()?[2,t]:e.keepIfStale(t)?(n={data:t.data,state:"stale",createdAt:t.createdAt},[4,this.set(r,n)]):[3,3];case 2:return a.sent(),[2,n];case 3:return[4,this.remove(r)];case 4:return a.sent(),[2,{state:"empty"}]}}))}))}}return e.keepIfStale=function(e){var t=e.data;return!!(null==t?void 0:t.headers)&&(n.Header.ETag in t.headers||n.Header.LastModified in t.headers||n.Header.XAxiosCacheEtag in t.headers||n.Header.XAxiosCacheLastModified in t.headers)},e}();t.AxiosStorage=o},916:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.isCachePredicateValid=t.shouldCacheResponse=void 0;var a=r(655);function n(e,t){var r=t.statusCheck,n=t.containsHeaders,o=t.responseMatch;if(r)if("function"==typeof r){if(!r(e.status))return!1}else{var i=(0,a.__read)(r,2),s=i[0],c=i[1];if(e.status<s||e.status>c)return!1}if(n)for(var u in n){var d=n[u],l=e.headers[u];if(!l)return!1;switch(typeof d){case"string":if(l!=d)return!1;break;case"function":if(!d(l))return!1}}return!(o&&!o(e.data))}t.shouldCacheResponse=function(e,t){var r=t.cachePredicate;return"function"==typeof r?r(e):n(e,r)},t.isCachePredicateValid=n},750:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Header=void 0,function(e){e.IfModifiedSince="if-modified-since",e.LastModified="last-modified",e.IfNoneMatch="if-none-match",e.CacheControl="cache-control",e.ETag="etag",e.Expires="expires",e.Age="age",e.ContentType="content-type",e.XAxiosCacheEtag="x-axios-cache-etag",e.XAxiosCacheLastModified="x-axios-cache-last-modified"}(t.Header||(t.Header={}))},481:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.defaultKeyGenerator=void 0;var r=/^\/|\/+$/g;t.defaultKeyGenerator=function(e){var t=e.baseURL,a=void 0===t?"":t,n=e.url,o=void 0===n?"":n,i=e.method,s=e.params,c=e.id;if(c)return String(c);a=a.replace(r,""),o=o.replace(r,"");var u=(null==i?void 0:i.toLowerCase())||"get",d=s?JSON.stringify(s,Object.keys(s).sort()):"{}";return"".concat(u,"::").concat(a+(o&&a?"/":"")+o,"::").concat(d)}},786:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.updateCache=void 0;var a=r(655);t.updateCache=function(e,t,r){return(0,a.__awaiter)(this,void 0,void 0,(function(){var n,o,i,s,c,u,d;return(0,a.__generator)(this,(function(a){switch(a.label){case 0:for(o in n=[],r)n.push(o);i=0,a.label=1;case 1:return i<n.length?(s=n[i],"delete"!==(c=r[s])?[3,3]:[4,e.remove(s)]):[3,9];case 2:return a.sent(),[3,8];case 3:return[4,e.get(s)];case 4:if("loading"===(u=a.sent()).state)throw new Error("cannot update the cache while loading");return void 0!==(d=c(u,t))?[3,6]:[4,e.remove(s)];case 5:return a.sent(),[3,8];case 6:return[4,e.set(s,d)];case 7:a.sent(),a.label=8;case 8:return i++,[3,1];case 9:return[2]}}))}))}},655:(e,t,r)=>{"use strict";r.r(t),r.d(t,{__extends:()=>n,__assign:()=>o,__rest:()=>i,__decorate:()=>s,__param:()=>c,__metadata:()=>u,__awaiter:()=>d,__generator:()=>l,__createBinding:()=>f,__exportStar:()=>h,__values:()=>p,__read:()=>v,__spread:()=>_,__spreadArrays:()=>y,__spreadArray:()=>g,__await:()=>m,__asyncGenerator:()=>x,__asyncDelegator:()=>b,__asyncValues:()=>w,__makeTemplateObject:()=>S,__importStar:()=>O,__importDefault:()=>j,__classPrivateFieldGet:()=>P,__classPrivateFieldSet:()=>I});var a=function(e,t){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},a(e,t)};function n(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}a(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}var o=function(){return o=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},o.apply(this,arguments)};function i(e,t){var r={};for(var a in e)Object.prototype.hasOwnProperty.call(e,a)&&t.indexOf(a)<0&&(r[a]=e[a]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(a=Object.getOwnPropertySymbols(e);n<a.length;n++)t.indexOf(a[n])<0&&Object.prototype.propertyIsEnumerable.call(e,a[n])&&(r[a[n]]=e[a[n]])}return r}function s(e,t,r,a){var n,o=arguments.length,i=o<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,r):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,a);else for(var s=e.length-1;s>=0;s--)(n=e[s])&&(i=(o<3?n(i):o>3?n(t,r,i):n(t,r))||i);return o>3&&i&&Object.defineProperty(t,r,i),i}function c(e,t){return function(r,a){t(r,a,e)}}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function d(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 l(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])}}}var f=Object.create?function(e,t,r,a){void 0===a&&(a=r),Object.defineProperty(e,a,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,a){void 0===a&&(a=r),e[a]=t[r]};function h(e,t){for(var r in e)"default"===r||Object.prototype.hasOwnProperty.call(t,r)||f(t,e,r)}function p(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],a=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&a>=e.length&&(e=void 0),{value:e&&e[a++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function v(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var a,n,o=r.call(e),i=[];try{for(;(void 0===t||t-- >0)&&!(a=o.next()).done;)i.push(a.value)}catch(e){n={error:e}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}return i}function _(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(v(arguments[t]));return e}function y(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var a=Array(e),n=0;for(t=0;t<r;t++)for(var o=arguments[t],i=0,s=o.length;i<s;i++,n++)a[n]=o[i];return a}function g(e,t,r){if(r||2===arguments.length)for(var a,n=0,o=t.length;n<o;n++)!a&&n in t||(a||(a=Array.prototype.slice.call(t,0,n)),a[n]=t[n]);return e.concat(a||Array.prototype.slice.call(t))}function m(e){return this instanceof m?(this.v=e,this):new m(e)}function x(e,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var a,n=r.apply(e,t||[]),o=[];return a={},i("next"),i("throw"),i("return"),a[Symbol.asyncIterator]=function(){return this},a;function i(e){n[e]&&(a[e]=function(t){return new Promise((function(r,a){o.push([e,t,r,a])>1||s(e,t)}))})}function s(e,t){try{(r=n[e](t)).value instanceof m?Promise.resolve(r.value.v).then(c,u):d(o[0][2],r)}catch(e){d(o[0][3],e)}var r}function c(e){s("next",e)}function u(e){s("throw",e)}function d(e,t){e(t),o.shift(),o.length&&s(o[0][0],o[0][1])}}function b(e){var t,r;return t={},a("next"),a("throw",(function(e){throw e})),a("return"),t[Symbol.iterator]=function(){return this},t;function a(a,n){t[a]=e[a]?function(t){return(r=!r)?{value:m(e[a](t)),done:"return"===a}:n?n(t):t}:n}}function w(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t,r=e[Symbol.asyncIterator];return r?r.call(e):(e=p(e),t={},a("next"),a("throw"),a("return"),t[Symbol.asyncIterator]=function(){return this},t);function a(r){t[r]=e[r]&&function(t){return new Promise((function(a,n){(function(e,t,r,a){Promise.resolve(a).then((function(t){e({value:t,done:r})}),t)})(a,n,(t=e[r](t)).done,t.value)}))}}}function S(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}var C=Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t};function O(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)"default"!==r&&Object.prototype.hasOwnProperty.call(e,r)&&f(t,e,r);return C(t,e),t}function j(e){return e&&e.__esModule?e:{default:e}}function P(e,t,r,a){if("a"===r&&!a)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof t?e!==t||!a:!t.has(e))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===r?a:"a"===r?a.call(e):a?a.value:t.get(e)}function I(e,t,r,a,n){if("m"===a)throw new TypeError("Private method is not writable");if("a"===a&&!n)throw new TypeError("Private accessor was defined without a setter");if("function"==typeof t?e!==t||!n:!t.has(e))throw new TypeError("Cannot write private member to an object whose class did not declare it");return"a"===a?n.call(e,r):n?n.value=r:t.set(e,r),r}}},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}return 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})},r(54)})()})); | ||
!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?this:self,(function(){return(()=>{var e={86:(e,t)=>{!function(e){var t=Symbol("cache-parser"),a=Number;function i(e){return("string"==typeof e||"number"==typeof e)&&(e=a(e))>=0&&e<1/0}function r(e){return"number"==typeof e||!0===e||"string"==typeof e&&"false"!==e}e.__internal={isDuration:i,toBoolean:r},e.isCacheControl=function(e){return!!e&&!!e[t]},e.tokenize=function(e){if(!e||"object"!=typeof e)return[];var t=[];return r(e.immutable)&&t.push("immutable"),i(e.maxAge)&&t.push("max-age="+a(e.maxAge)),i(e.maxStale)&&t.push("max-stale="+a(e.maxStale)),i(e.minFresh)&&t.push("min-fresh="+a(e.minFresh)),r(e.mustRevalidate)&&t.push("must-revalidate"),r(e.mustUnderstand)&&t.push("must-understand"),r(e.noCache)&&t.push("no-cache"),r(e.noStore)&&t.push("no-store"),r(e.noTransform)&&t.push("no-transform"),r(e.onlyIfCached)&&t.push("only-if-cached"),r(e.private)&&t.push("private"),r(e.proxyRevalidate)&&t.push("proxy-revalidate"),r(e.public)&&t.push("public"),i(e.sMaxAge)&&t.push("s-maxage="+a(e.sMaxAge)),i(e.staleIfError)&&t.push("stale-if-error="+a(e.staleIfError)),i(e.staleWhileRevalidate)&&t.push("stale-while-revalidate="+a(e.staleWhileRevalidate)),t},e.parse=function(e){var n=Object.defineProperty({},t,{enumerable:!1,value:1});if(!e||"string"!=typeof e)return n;var s={},o=e.toLowerCase().replace(/\s+/g,"").split(",");for(var c in o){var d=o[c].split("=",2);s[d[0]]=1===d.length||d[1]}return r(s.immutable)&&(n.immutable=!0),i(s["max-age"])&&(n.maxAge=a(s["max-age"])),i(s["max-stale"])&&(n.maxStale=a(s["max-stale"])),i(s["min-fresh"])&&(n.minFresh=a(s["min-fresh"])),r(s["must-revalidate"])&&(n.mustRevalidate=!0),r(s["must-understand"])&&(n.mustUnderstand=!0),r(s["no-cache"])&&(n.noCache=!0),r(s["no-store"])&&(n.noStore=!0),r(s["no-transform"])&&(n.noTransform=!0),r(s["only-if-cached"])&&(n.onlyIfCached=!0),r(s.private)&&(n.private=!0),r(s["proxy-revalidate"])&&(n.proxyRevalidate=!0),r(s.public)&&(n.public=!0),i(s["s-maxage"])&&(n.sMaxAge=a(s["s-maxage"])),i(s["stale-if-error"])&&(n.staleIfError=a(s["stale-if-error"])),i(s["stale-while-revalidate"])&&(n.staleWhileRevalidate=a(s["stale-while-revalidate"])),n}}(t)},549:(e,t)=>{var a,i;a=t,i=Symbol("fast-defer"),a.deferred=function(){var e,t,a=new Promise(((a,i)=>{e=a,t=i}));return a.resolve=e,a.reject=t,a[i]=1,a},a.isDeferred=function(e){return!!e&&!!e[i]}}},t={};function a(i){var r=t[i];if(void 0!==r)return r.exports;var n=t[i]={exports:{}};return e[i](n,n.exports,a),n.exports}a.d=(e,t)=>{for(var i in t)a.o(t,i)&&!a.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},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 i={};return(()=>{"use strict";a.r(i),a.d(i,{AxiosStorage:()=>p,BrowserAxiosStorage:()=>C,MemoryAxiosStorage:()=>g,createCache:()=>w,useCache:()=>b});var e,t=a(86);!function(e){e.IfModifiedSince="if-modified-since",e.LastModified="last-modified",e.IfNoneMatch="if-none-match",e.CacheControl="cache-control",e.ETag="etag",e.Expires="expires",e.Age="age",e.ContentType="content-type",e.XAxiosCacheEtag="x-axios-cache-etag",e.XAxiosCacheLastModified="x-axios-cache-last-modified"}(e||(e={}));const r=(t={})=>e.CacheControl in t?s(t[e.CacheControl],t):e.Expires in t?n(t[e.Expires],t):void 0,n=e=>{const t=Date.parse(e)-Date.now();return t>=0&&t},s=(a,i)=>{const{noCache:r,noStore:n,mustRevalidate:s,maxAge:o,immutable:c}=(0,t.parse)(a);if(r||n)return!1;if(c)return 31536e6;if(s)return 0;if(o){const t=i[e.Age];return t?1e3*(o-Number(t)):1e3*o}};var o=a(549),c=function(e,t,a,i){return new(a||(a=Promise))((function(r,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function o(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(s,o)}c((i=i.apply(e,t||[])).next())}))};class d{constructor(e){this.axios=e,this.use=()=>{this.axios.interceptors.request.use(this.onFulfilled)},this.onFulfilled=e=>c(this,void 0,void 0,(function*(){var t;if(!1===e.cache)return e;if(e.cache=Object.assign(Object.assign({},this.axios.defaults.cache),e.cache),!d.isMethodAllowed(e.method,e.cache))return e;const a=this.axios.generateKey(e);let i,r=yield this.axios.storage.get(a);e:if("empty"==r.state||"stale"===r.state){if(this.axios.waiting[a]){r=yield this.axios.storage.get(a);break e}return this.axios.waiting[a]=(0,o.deferred)(),null===(t=this.axios.waiting[a])||void 0===t||t.catch((()=>{})),yield this.axios.storage.set(a,{state:"loading",data:r.data}),"stale"===r.state&&d.setRevalidationHeaders(r,e),e.validateStatus=d.createValidateStatus(e.validateStatus),e}if("loading"===r.state){const t=this.axios.waiting[a];if(!t)return yield this.axios.storage.remove(a),e;try{i=yield t}catch(t){return e}}else i=r.data;return e.adapter=()=>Promise.resolve({config:e,data:i.data,headers:i.headers,status:i.status,statusText:i.statusText,cached:!0,id:a}),e}))}}d.isMethodAllowed=(e,t)=>{const a=e.toLowerCase();for(const e of t.methods||[])if(e.toLowerCase()===a)return!0;return!1},d.setRevalidationHeaders=(t,a)=>{var i;a.headers||(a.headers={});const{etag:r,modifiedSince:n}=a.cache;if(r){const n=!0===r?null===(i=t.data)||void 0===i?void 0:i.headers[e.ETag]:r;n&&(a.headers[e.IfNoneMatch]=n)}n&&(a.headers[e.IfModifiedSince]=!0===n?t.data.headers[e.LastModified]||new Date(t.createdAt).toUTCString():n.toUTCString())},d.createValidateStatus=e=>t=>e?e(t)||304===t:t>=200&&t<300||304===t;var u=function(e,t,a,i){return new(a||(a=Promise))((function(r,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function o(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(s,o)}c((i=i.apply(e,t||[])).next())}))};var h=function(e,t,a,i){return new(a||(a=Promise))((function(r,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function o(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(s,o)}c((i=i.apply(e,t||[])).next())}))};class f{constructor(t){this.axios=t,this.use=()=>{this.axios.interceptors.response.use(this.onFulfilled)},this.onFulfilled=t=>h(this,void 0,void 0,(function*(){const a=this.cachedResponse(t);if(a.cached)return a;if(!a.config.cache)return Object.assign(Object.assign({},a),{cached:!1});const i=a.config.cache,r=yield this.axios.storage.get(a.id);if("stale"===r.state||"empty"===r.state||"cached"===r.state)return a;if(!r.data&&!function(e,{cachePredicate:t}){return"function"==typeof t?t(e):function(e,{statusCheck:t,containsHeaders:a,responseMatch:i}){if(t)if("function"==typeof t){if(!t(e.status))return!1}else{const[a,i]=t;if(e.status<a||e.status>i)return!1}if(a)for(const t in a){const i=a[t],r=e.headers[t];if(!r)return!1;switch(typeof i){case"string":if(r!=i)return!1;break;case"function":if(!i(r))return!1}}return!(i&&!i(e.data))}(e,t)}(a,i))return yield this.rejectResponse(a.id),a;delete a.headers[e.XAxiosCacheEtag],delete a.headers[e.XAxiosCacheLastModified],i.etag&&!0!==i.etag&&(a.headers[e.XAxiosCacheEtag]=i.etag),i.modifiedSince&&(a.headers[e.XAxiosCacheLastModified]=!0===i.modifiedSince?"use-cache-timestamp":i.modifiedSince.toUTCString());let n=i.ttl||-1;if(null==i?void 0:i.interpretHeader){const e=this.axios.headerInterpreter(a.headers);if(!1===e)return yield this.rejectResponse(a.id),a;n=e||0===e?e:n}const s=f.createCacheData(a,r.data),o={state:"cached",ttl:n,createdAt:Date.now(),data:s};(null==i?void 0:i.update)&&function(e,t,a){u(this,void 0,void 0,(function*(){for(const i in a){const r=a[i];if("delete"===r){yield e.remove(i);continue}const n=yield e.get(i);if("loading"===n.state)throw new Error("cannot update the cache while loading");const s=r(n,t);void 0!==s?yield e.set(i,s):yield e.remove(i)}}))}(this.axios.storage,a.data,i.update);const c=this.axios.waiting[a.id];return yield null==c?void 0:c.resolve(o.data),delete this.axios.waiting[a.id],yield this.axios.storage.set(a.id,o),a})),this.rejectResponse=e=>h(this,void 0,void 0,(function*(){var t;yield this.axios.storage.remove(e),null===(t=this.axios.waiting[e])||void 0===t||t.reject(null),delete this.axios.waiting[e]})),this.cachedResponse=e=>Object.assign({id:this.axios.generateKey(e.config),cached:e.cached||!1},e)}}f.createCacheData=(e,t)=>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};var l=function(e,t,a,i){return new(a||(a=Promise))((function(r,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function o(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(s,o)}c((i=i.apply(e,t||[])).next())}))};class p{constructor(){this.get=e=>l(this,void 0,void 0,(function*(){const t=yield this.find(e);if("cached"!==t.state||t.createdAt+t.ttl>Date.now())return t;if(p.keepIfStale(t)){const a={data:t.data,state:"stale",createdAt:t.createdAt};return yield this.set(e,a),a}return yield this.remove(e),{state:"empty"}}))}}p.keepIfStale=({data:t})=>!!(null==t?void 0:t.headers)&&(e.ETag in t.headers||e.LastModified in t.headers||e.XAxiosCacheEtag in t.headers||e.XAxiosCacheLastModified in t.headers);var v=function(e,t,a,i){return new(a||(a=Promise))((function(r,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function o(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(s,o)}c((i=i.apply(e,t||[])).next())}))};class g extends p{constructor(e={}){super(),this.storage=e,this.find=e=>v(this,void 0,void 0,(function*(){return this.storage[e]||{state:"empty"}})),this.set=(e,t)=>v(this,void 0,void 0,(function*(){this.storage[e]=t})),this.remove=e=>v(this,void 0,void 0,(function*(){delete this.storage[e]}))}}const m=/^\/|\/+$/g,x=({baseURL:e="",url:t="",method:a,params:i,id:r})=>{if(r)return String(r);e=e.replace(m,""),t=t.replace(m,"");return`${(null==a?void 0:a.toLowerCase())||"get"}::${e+(t&&e?"/":"")+t}::${i?JSON.stringify(i,Object.keys(i).sort()):"{}"}`};var y=function(e,t){var a={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(a[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(i=Object.getOwnPropertySymbols(e);r<i.length;r++)t.indexOf(i[r])<0&&Object.prototype.propertyIsEnumerable.call(e,i[r])&&(a[i[r]]=e[i[r]])}return a};function w(e,t={}){var{storage:a,generateKey:i,waiting:n,headerInterpreter:s,requestInterceptor:o,responseInterceptor:c}=t,u=y(t,["storage","generateKey","waiting","headerInterpreter","requestInterceptor","responseInterceptor"]);const h=e;return h.storage=a||new g,h.generateKey=i||x,h.waiting=n||{},h.headerInterpreter=s||r,h.requestInterceptor=o||new d(h),h.responseInterceptor=c||new f(h),h.defaults=Object.assign(Object.assign({},e.defaults),{cache:Object.assign({ttl:3e5,interpretHeader:!1,methods:["get"],cachePredicate:{statusCheck:[200,399]},etag:!1,modifiedSince:!1,update:{}},u)}),h.requestInterceptor.use(),h.responseInterceptor.use(),h}const b=w;var S=function(e,t,a,i){return new(a||(a=Promise))((function(r,n){function s(e){try{c(i.next(e))}catch(e){n(e)}}function o(e){try{c(i.throw(e))}catch(e){n(e)}}function c(e){var t;e.done?r(e.value):(t=e.value,t instanceof a?t:new a((function(e){e(t)}))).then(s,o)}c((i=i.apply(e,t||[])).next())}))};class C extends p{constructor(e,t=C.DEFAULT_KEY_PREFIX){super(),this.storage=e,this.prefix=t,this.find=e=>S(this,void 0,void 0,(function*(){const t=this.storage.getItem(`${this.prefix}:${e}`);return t?JSON.parse(t):{state:"empty"}})),this.set=(e,t)=>S(this,void 0,void 0,(function*(){return this.storage.setItem(`${this.prefix}:${e}`,JSON.stringify(t))})),this.remove=e=>S(this,void 0,void 0,(function*(){return this.storage.removeItem(`${this.prefix}:${e}`)}))}}C.DEFAULT_KEY_PREFIX="a-c-i"})(),i})()})); | ||
//# sourceMappingURL=index.min.js.map |
@@ -20,3 +20,2 @@ /* eslint-disable @typescript-eslint/no-var-requires */ | ||
*/ | ||
const axiosWithCache = createCache(axios, { | ||
@@ -23,0 +22,0 @@ ttl: 99999, |
{ | ||
"name": "axios-cache-interceptor", | ||
"version": "0.7.7", | ||
"version": "0.7.8", | ||
"description": "Cache interceptor for axios", | ||
@@ -55,3 +55,3 @@ "main": "./dist/index.js", | ||
"@typescript-eslint/eslint-plugin": "^5.7.0", | ||
"@typescript-eslint/parser": "^5.7.0", | ||
"@typescript-eslint/parser": "^5.8.1", | ||
"auto-changelog": "^2.3.0", | ||
@@ -69,5 +69,3 @@ "axios": "~0.24.0", | ||
"ts-loader": "^9.2.6", | ||
"tslib": "^2.3.1", | ||
"typescript": "^4.5.4", | ||
"weak-napi": "^2.0.2", | ||
"webpack": "^5.65.0", | ||
@@ -74,0 +72,0 @@ "webpack-cli": "^4.9.1" |
<br /> | ||
<div align="center"> | ||
<pre> | ||
<br /> | ||
<h1>🗄️🔥💨 | ||
Axios Cache Interceptor</h1> | ||
<br /> | ||
</pre> | ||
<br /> | ||
<br /> | ||
<code | ||
@@ -39,2 +31,3 @@ ><a href="https://github.com/ArthurFiorette/axios-cache-interceptor/issues" | ||
></code> | ||
<br /> | ||
<code | ||
@@ -52,5 +45,12 @@ ><a href="https://www.npmjs.com/package/axios-cache-interceptor" | ||
target="_blank" | ||
alt="Size" /></a | ||
alt="Minified Size" /></a | ||
></code> | ||
<code | ||
><a href="https://bundlephobia.com/package/axios-cache-interceptor" | ||
><img | ||
src="https://packagephobia.com/badge?p=axios-cache-interceptor@latest" | ||
target="_blank" | ||
alt="Install Size" /></a | ||
></code> | ||
<code | ||
><a href="https://npm.runkit.com/axios-cache-interceptor" | ||
@@ -62,2 +62,12 @@ ><img | ||
></code> | ||
<br /> | ||
<br /> | ||
<br /> | ||
<pre> | ||
<br /> | ||
<h1>🗄️🔥💨 | ||
Axios Cache Interceptor</h1> | ||
<br /> | ||
</pre> | ||
<br /> | ||
</div> | ||
@@ -223,10 +233,13 @@ | ||
The compiled code is built in two different ways, one as CommonsJS Module | ||
`(ES6 Compatible)` and one as a browser minified code `(ES5 Compatible)`. | ||
As axios itself requires [ES6 Promises](https://axios-http.com/docs/notes#promises), the | ||
CommonsJS module and the Browser minified version are also `>= ES6` compatibles. | ||
You can see more here about compiling options: | ||
- [Browser config](/tsconfig.browser.json) - [Webpack config](/webpack.config.js) | ||
- [Browser config](/tsconfig.browser.json) & [Webpack config](/webpack.config.js) | ||
- [NodeJS Config](/tsconfig.build.json) | ||
Don't forget, you can always rebuilt this library by up from it's source code or recompile | ||
the dist with lower ecma script versions. | ||
<br /> | ||
@@ -233,0 +246,0 @@ |
@@ -67,8 +67,7 @@ import type { AxiosInstance } from 'axios'; | ||
* | ||
* @deprecated Prefer {@link createCache} | ||
* @param axios The already created axios instance | ||
* @param config The config for the caching interceptors | ||
* @returns The same instance but with caching enabled | ||
* | ||
* @deprecated Prefer {@link createCache} | ||
*/ | ||
export const useCache = createCache; |
/** Index file for webpack and cdn usage */ | ||
export * from './cache/create'; | ||
export * from './storage/browser'; | ||
export * from './storage/memory'; | ||
export * from './storage/storage'; | ||
export { createCache, useCache } from './cache/create'; | ||
export { BrowserAxiosStorage } from './storage/browser'; | ||
export { MemoryAxiosStorage } from './storage/memory'; | ||
export { AxiosStorage } from './storage/storage'; |
@@ -5,9 +5,8 @@ { | ||
"noEmit": false, | ||
"target": "ES5", | ||
"sourceMap": false, | ||
"target": "ES6", | ||
"declaration": false, | ||
"declarationMap": false, | ||
"importHelpers": true | ||
"module": "ESNext" | ||
}, | ||
"include": ["src/index.browser.ts"] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
21
0
476
196278
83
2038