workbox-strategies
Advanced tools
Comparing version 6.1.1 to 6.1.2
"use strict"; | ||
// @ts-ignore | ||
try { | ||
self['workbox:strategies:6.1.1'] && _(); | ||
self['workbox:strategies:6.1.2'] && _(); | ||
} | ||
catch (e) { } |
@@ -24,3 +24,3 @@ this.workbox = this.workbox || {}; | ||
try { | ||
self['workbox:strategies:6.1.1'] && _(); | ||
self['workbox:strategies:6.1.2'] && _(); | ||
} catch (e) {} | ||
@@ -143,81 +143,79 @@ | ||
fetch(input) { | ||
return this.waitUntil((async () => { | ||
const { | ||
event | ||
} = this; | ||
let request = toRequest(input); | ||
async fetch(input) { | ||
const { | ||
event | ||
} = this; | ||
let request = toRequest(input); | ||
if (request.mode === 'navigate' && event instanceof FetchEvent && event.preloadResponse) { | ||
const possiblePreloadResponse = await event.preloadResponse; | ||
if (request.mode === 'navigate' && event instanceof FetchEvent && event.preloadResponse) { | ||
const possiblePreloadResponse = await event.preloadResponse; | ||
if (possiblePreloadResponse) { | ||
{ | ||
logger_js.logger.log(`Using a preloaded navigation response for ` + `'${getFriendlyURL_js.getFriendlyURL(request.url)}'`); | ||
} | ||
return possiblePreloadResponse; | ||
if (possiblePreloadResponse) { | ||
{ | ||
logger_js.logger.log(`Using a preloaded navigation response for ` + `'${getFriendlyURL_js.getFriendlyURL(request.url)}'`); | ||
} | ||
} // If there is a fetchDidFail plugin, we need to save a clone of the | ||
// original request before it's either modified by a requestWillFetch | ||
// plugin or before the original request's body is consumed via fetch(). | ||
return possiblePreloadResponse; | ||
} | ||
} // If there is a fetchDidFail plugin, we need to save a clone of the | ||
// original request before it's either modified by a requestWillFetch | ||
// plugin or before the original request's body is consumed via fetch(). | ||
const originalRequest = this.hasCallback('fetchDidFail') ? request.clone() : null; | ||
try { | ||
for (const cb of this.iterateCallbacks('requestWillFetch')) { | ||
request = await cb({ | ||
request: request.clone(), | ||
event | ||
}); | ||
} | ||
} catch (err) { | ||
throw new WorkboxError_js.WorkboxError('plugin-error-request-will-fetch', { | ||
thrownError: err | ||
const originalRequest = this.hasCallback('fetchDidFail') ? request.clone() : null; | ||
try { | ||
for (const cb of this.iterateCallbacks('requestWillFetch')) { | ||
request = await cb({ | ||
request: request.clone(), | ||
event | ||
}); | ||
} // The request can be altered by plugins with `requestWillFetch` making | ||
// the original request (most likely from a `fetch` event) different | ||
// from the Request we make. Pass both to `fetchDidFail` to aid debugging. | ||
} | ||
} catch (err) { | ||
throw new WorkboxError_js.WorkboxError('plugin-error-request-will-fetch', { | ||
thrownError: err | ||
}); | ||
} // The request can be altered by plugins with `requestWillFetch` making | ||
// the original request (most likely from a `fetch` event) different | ||
// from the Request we make. Pass both to `fetchDidFail` to aid debugging. | ||
const pluginFilteredRequest = request.clone(); | ||
const pluginFilteredRequest = request.clone(); | ||
try { | ||
let fetchResponse; // See https://github.com/GoogleChrome/workbox/issues/1796 | ||
try { | ||
let fetchResponse; // See https://github.com/GoogleChrome/workbox/issues/1796 | ||
fetchResponse = await fetch(request, request.mode === 'navigate' ? undefined : this._strategy.fetchOptions); | ||
fetchResponse = await fetch(request, request.mode === 'navigate' ? undefined : this._strategy.fetchOptions); | ||
if ("dev" !== 'production') { | ||
logger_js.logger.debug(`Network request for ` + `'${getFriendlyURL_js.getFriendlyURL(request.url)}' returned a response with ` + `status '${fetchResponse.status}'.`); | ||
} | ||
if ("dev" !== 'production') { | ||
logger_js.logger.debug(`Network request for ` + `'${getFriendlyURL_js.getFriendlyURL(request.url)}' returned a response with ` + `status '${fetchResponse.status}'.`); | ||
} | ||
for (const callback of this.iterateCallbacks('fetchDidSucceed')) { | ||
fetchResponse = await callback({ | ||
event, | ||
request: pluginFilteredRequest, | ||
response: fetchResponse | ||
}); | ||
} | ||
for (const callback of this.iterateCallbacks('fetchDidSucceed')) { | ||
fetchResponse = await callback({ | ||
event, | ||
request: pluginFilteredRequest, | ||
response: fetchResponse | ||
}); | ||
} | ||
return fetchResponse; | ||
} catch (error) { | ||
{ | ||
logger_js.logger.error(`Network request for ` + `'${getFriendlyURL_js.getFriendlyURL(request.url)}' threw an error.`, error); | ||
} // `originalRequest` will only exist if a `fetchDidFail` callback | ||
// is being used (see above). | ||
return fetchResponse; | ||
} catch (error) { | ||
{ | ||
logger_js.logger.log(`Network request for ` + `'${getFriendlyURL_js.getFriendlyURL(request.url)}' threw an error.`, error); | ||
} // `originalRequest` will only exist if a `fetchDidFail` callback | ||
// is being used (see above). | ||
if (originalRequest) { | ||
await this.runCallbacks('fetchDidFail', { | ||
error, | ||
event, | ||
originalRequest: originalRequest.clone(), | ||
request: pluginFilteredRequest.clone() | ||
}); | ||
} | ||
if (originalRequest) { | ||
await this.runCallbacks('fetchDidFail', { | ||
error, | ||
event, | ||
originalRequest: originalRequest.clone(), | ||
request: pluginFilteredRequest.clone() | ||
}); | ||
} | ||
throw error; | ||
} | ||
})()); | ||
throw error; | ||
} | ||
} | ||
@@ -256,38 +254,36 @@ /** | ||
cacheMatch(key) { | ||
return this.waitUntil((async () => { | ||
const request = toRequest(key); | ||
let cachedResponse; | ||
const { | ||
cacheName, | ||
matchOptions | ||
} = this._strategy; | ||
const effectiveRequest = await this.getCacheKey(request, 'read'); | ||
async cacheMatch(key) { | ||
const request = toRequest(key); | ||
let cachedResponse; | ||
const { | ||
cacheName, | ||
matchOptions | ||
} = this._strategy; | ||
const effectiveRequest = await this.getCacheKey(request, 'read'); | ||
const multiMatchOptions = _extends({}, matchOptions, { | ||
cacheName | ||
}); | ||
const multiMatchOptions = _extends({}, matchOptions, { | ||
cacheName | ||
}); | ||
cachedResponse = await caches.match(effectiveRequest, multiMatchOptions); | ||
cachedResponse = await caches.match(effectiveRequest, multiMatchOptions); | ||
{ | ||
if (cachedResponse) { | ||
logger_js.logger.debug(`Found a cached response in '${cacheName}'.`); | ||
} else { | ||
logger_js.logger.debug(`No cached response found in '${cacheName}'.`); | ||
} | ||
{ | ||
if (cachedResponse) { | ||
logger_js.logger.debug(`Found a cached response in '${cacheName}'.`); | ||
} else { | ||
logger_js.logger.debug(`No cached response found in '${cacheName}'.`); | ||
} | ||
} | ||
for (const callback of this.iterateCallbacks('cachedResponseWillBeUsed')) { | ||
cachedResponse = (await callback({ | ||
cacheName, | ||
matchOptions, | ||
cachedResponse, | ||
request: effectiveRequest, | ||
event: this.event | ||
})) || undefined; | ||
} | ||
for (const callback of this.iterateCallbacks('cachedResponseWillBeUsed')) { | ||
cachedResponse = (await callback({ | ||
cacheName, | ||
matchOptions, | ||
cachedResponse, | ||
request: effectiveRequest, | ||
event: this.event | ||
})) || undefined; | ||
} | ||
return cachedResponse; | ||
})()); | ||
return cachedResponse; | ||
} | ||
@@ -294,0 +290,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,r,i,a,n,o,c){"use strict";function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t}).apply(this,arguments)}try{self["workbox:strategies:6.1.1"]&&_()}catch(t){}function l(t){return"string"==typeof t?new Request(t):t}class u{constructor(t,e){this.vt={},Object.assign(this,e),this.event=e.event,this.ht=t,this.bt=new n.Deferred,this._t=[],this.kt=[...t.plugins],this.xt=new Map;for(const t of this.kt)this.xt.set(t,{});this.event.waitUntil(this.bt.promise)}fetch(t){return this.waitUntil((async()=>{const{event:e}=this;let r=l(t);if("navigate"===r.mode&&e instanceof FetchEvent&&e.preloadResponse){const t=await e.preloadResponse;if(t)return t}const i=this.hasCallback("fetchDidFail")?r.clone():null;try{for(const t of this.iterateCallbacks("requestWillFetch"))r=await t({request:r.clone(),event:e})}catch(t){throw new s.WorkboxError("plugin-error-request-will-fetch",{thrownError:t})}const a=r.clone();try{let t;t=await fetch(r,"navigate"===r.mode?void 0:this.ht.fetchOptions);for(const s of this.iterateCallbacks("fetchDidSucceed"))t=await s({event:e,request:a,response:t});return t}catch(t){throw i&&await this.runCallbacks("fetchDidFail",{error:t,event:e,originalRequest:i.clone(),request:a.clone()}),t}})())}async fetchAndCachePut(t){const e=await this.fetch(t),s=e.clone();return this.waitUntil(this.cachePut(t,s)),e}cacheMatch(t){return this.waitUntil((async()=>{const e=l(t);let s;const{cacheName:r,matchOptions:i}=this.ht,a=await this.getCacheKey(e,"read"),n=h({},i,{cacheName:r});s=await caches.match(a,n);for(const t of this.iterateCallbacks("cachedResponseWillBeUsed"))s=await t({cacheName:r,matchOptions:i,cachedResponse:s,request:a,event:this.event})||void 0;return s})())}async cachePut(t,e){const r=l(t);await c.timeout(0);const n=await this.getCacheKey(r,"write");if(!e)throw new s.WorkboxError("cache-put-with-no-response",{url:i.getFriendlyURL(n.url)});const h=await this.Rt(e);if(!h)return!1;const{cacheName:u,matchOptions:w}=this.ht,f=await self.caches.open(u),d=this.hasCallback("cacheDidUpdate"),p=d?await a.cacheMatchIgnoreParams(f,n.clone(),["__WB_REVISION__"],w):null;try{await f.put(n,d?h.clone():h)}catch(t){throw"QuotaExceededError"===t.name&&await o.executeQuotaErrorCallbacks(),t}for(const t of this.iterateCallbacks("cacheDidUpdate"))await t({cacheName:u,oldResponse:p,newResponse:h.clone(),request:n,event:this.event});return!0}async getCacheKey(t,e){if(!this.vt[e]){let s=t;for(const t of this.iterateCallbacks("cacheKeyWillBeUsed"))s=l(await t({mode:e,request:s,event:this.event,params:this.params}));this.vt[e]=s}return this.vt[e]}hasCallback(t){for(const e of this.ht.plugins)if(t in e)return!0;return!1}async runCallbacks(t,e){for(const s of this.iterateCallbacks(t))await s(e)}*iterateCallbacks(t){for(const e of this.ht.plugins)if("function"==typeof e[t]){const s=this.xt.get(e),r=r=>{const i=h({},r,{state:s});return e[t](i)};yield r}}waitUntil(t){return this._t.push(t),t}async doneWaiting(){let t;for(;t=this._t.shift();)await t}destroy(){this.bt.resolve()}async Rt(t){let e=t,s=!1;for(const t of this.iterateCallbacks("cacheWillUpdate"))if(e=await t({request:this.request,response:e,event:this.event})||void 0,s=!0,!e)break;return s||e&&200!==e.status&&(e=void 0),e}}class w{constructor(t={}){this.cacheName=r.cacheNames.getRuntimeName(t.cacheName),this.plugins=t.plugins||[],this.fetchOptions=t.fetchOptions,this.matchOptions=t.matchOptions}handle(t){const[e]=this.handleAll(t);return e}handleAll(t){t instanceof FetchEvent&&(t={event:t,request:t.request});const e=t.event,s="string"==typeof t.request?new Request(t.request):t.request,r="params"in t?t.params:void 0,i=new u(this,{event:e,request:s,params:r}),a=this.Wt(i,s,e);return[a,this.Ut(a,i,s,e)]}async Wt(t,e,r){await t.runCallbacks("handlerWillStart",{event:r,request:e});let i=void 0;try{if(i=await this._handle(e,t),!i||"error"===i.type)throw new s.WorkboxError("no-response",{url:e.url})}catch(s){for(const a of t.iterateCallbacks("handlerDidError"))if(i=await a({error:s,event:r,request:e}),i)break;if(!i)throw s}for(const s of t.iterateCallbacks("handlerWillRespond"))i=await s({event:r,request:e,response:i});return i}async Ut(t,e,s,r){let i,a;try{i=await t}catch(a){}try{await e.runCallbacks("handlerDidRespond",{event:r,request:s,response:i}),await e.doneWaiting()}catch(t){a=t}if(await e.runCallbacks("handlerDidComplete",{event:r,request:s,response:i,error:a}),e.destroy(),a)throw a}}const f={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};return t.CacheFirst=class extends w{async _handle(t,e){let r,i=await e.cacheMatch(t);if(!i)try{i=await e.fetchAndCachePut(t)}catch(t){r=t}if(!i)throw new s.WorkboxError("no-response",{url:t.url,error:r});return i}},t.CacheOnly=class extends w{async _handle(t,e){const r=await e.cacheMatch(t);if(!r)throw new s.WorkboxError("no-response",{url:t.url});return r}},t.NetworkFirst=class extends w{constructor(t={}){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){const r=[],i=[];let a;if(this.Ct){const{id:s,promise:n}=this.Dt({request:t,logs:r,handler:e});a=s,i.push(n)}const n=this.Et({timeoutId:a,request:t,logs:r,handler:e});i.push(n);const o=await e.waitUntil((async()=>await e.waitUntil(Promise.race(i))||await n)());if(!o)throw new s.WorkboxError("no-response",{url:t.url});return o}Dt({request:t,logs:e,handler:s}){let r;return{promise:new Promise((e=>{r=setTimeout((async()=>{e(await s.cacheMatch(t))}),1e3*this.Ct)})),id:r}}async Et({timeoutId:t,request:e,logs:s,handler:r}){let i,a;try{a=await r.fetchAndCachePut(e)}catch(t){i=t}return t&&clearTimeout(t),!i&&a||(a=await r.cacheMatch(e)),a}},t.NetworkOnly=class extends w{constructor(t={}){super(t),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){let r,i=void 0;try{const s=[e.fetch(t)];if(this.Ct){const t=c.timeout(1e3*this.Ct);s.push(t)}if(r=await Promise.race(s),!r)throw new Error("Timed out the network response after "+this.Ct+" seconds.")}catch(t){i=t}if(!r)throw new s.WorkboxError("no-response",{url:t.url,error:i});return r}},t.StaleWhileRevalidate=class extends w{constructor(t){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f)}async _handle(t,e){const r=e.fetchAndCachePut(t).catch((()=>{}));let i,a=await e.cacheMatch(t);if(a);else try{a=await r}catch(t){i=t}if(!a)throw new s.WorkboxError("no-response",{url:t.url,error:i});return a}},t.Strategy=w,t.StrategyHandler=u,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.strategies=function(t,e,s,r,a,i,n,o,c){"use strict";function h(){return(h=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var s=arguments[e];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(t[r]=s[r])}return t}).apply(this,arguments)}try{self["workbox:strategies:6.1.2"]&&_()}catch(t){}function l(t){return"string"==typeof t?new Request(t):t}class u{constructor(t,e){this.vt={},Object.assign(this,e),this.event=e.event,this.ht=t,this.bt=new n.Deferred,this._t=[],this.kt=[...t.plugins],this.xt=new Map;for(const t of this.kt)this.xt.set(t,{});this.event.waitUntil(this.bt.promise)}async fetch(t){const{event:e}=this;let r=l(t);if("navigate"===r.mode&&e instanceof FetchEvent&&e.preloadResponse){const t=await e.preloadResponse;if(t)return t}const a=this.hasCallback("fetchDidFail")?r.clone():null;try{for(const t of this.iterateCallbacks("requestWillFetch"))r=await t({request:r.clone(),event:e})}catch(t){throw new s.WorkboxError("plugin-error-request-will-fetch",{thrownError:t})}const i=r.clone();try{let t;t=await fetch(r,"navigate"===r.mode?void 0:this.ht.fetchOptions);for(const s of this.iterateCallbacks("fetchDidSucceed"))t=await s({event:e,request:i,response:t});return t}catch(t){throw a&&await this.runCallbacks("fetchDidFail",{error:t,event:e,originalRequest:a.clone(),request:i.clone()}),t}}async fetchAndCachePut(t){const e=await this.fetch(t),s=e.clone();return this.waitUntil(this.cachePut(t,s)),e}async cacheMatch(t){const e=l(t);let s;const{cacheName:r,matchOptions:a}=this.ht,i=await this.getCacheKey(e,"read"),n=h({},a,{cacheName:r});s=await caches.match(i,n);for(const t of this.iterateCallbacks("cachedResponseWillBeUsed"))s=await t({cacheName:r,matchOptions:a,cachedResponse:s,request:i,event:this.event})||void 0;return s}async cachePut(t,e){const r=l(t);await c.timeout(0);const n=await this.getCacheKey(r,"write");if(!e)throw new s.WorkboxError("cache-put-with-no-response",{url:a.getFriendlyURL(n.url)});const h=await this.Rt(e);if(!h)return!1;const{cacheName:u,matchOptions:w}=this.ht,f=await self.caches.open(u),d=this.hasCallback("cacheDidUpdate"),p=d?await i.cacheMatchIgnoreParams(f,n.clone(),["__WB_REVISION__"],w):null;try{await f.put(n,d?h.clone():h)}catch(t){throw"QuotaExceededError"===t.name&&await o.executeQuotaErrorCallbacks(),t}for(const t of this.iterateCallbacks("cacheDidUpdate"))await t({cacheName:u,oldResponse:p,newResponse:h.clone(),request:n,event:this.event});return!0}async getCacheKey(t,e){if(!this.vt[e]){let s=t;for(const t of this.iterateCallbacks("cacheKeyWillBeUsed"))s=l(await t({mode:e,request:s,event:this.event,params:this.params}));this.vt[e]=s}return this.vt[e]}hasCallback(t){for(const e of this.ht.plugins)if(t in e)return!0;return!1}async runCallbacks(t,e){for(const s of this.iterateCallbacks(t))await s(e)}*iterateCallbacks(t){for(const e of this.ht.plugins)if("function"==typeof e[t]){const s=this.xt.get(e),r=r=>{const a=h({},r,{state:s});return e[t](a)};yield r}}waitUntil(t){return this._t.push(t),t}async doneWaiting(){let t;for(;t=this._t.shift();)await t}destroy(){this.bt.resolve()}async Rt(t){let e=t,s=!1;for(const t of this.iterateCallbacks("cacheWillUpdate"))if(e=await t({request:this.request,response:e,event:this.event})||void 0,s=!0,!e)break;return s||e&&200!==e.status&&(e=void 0),e}}class w{constructor(t={}){this.cacheName=r.cacheNames.getRuntimeName(t.cacheName),this.plugins=t.plugins||[],this.fetchOptions=t.fetchOptions,this.matchOptions=t.matchOptions}handle(t){const[e]=this.handleAll(t);return e}handleAll(t){t instanceof FetchEvent&&(t={event:t,request:t.request});const e=t.event,s="string"==typeof t.request?new Request(t.request):t.request,r="params"in t?t.params:void 0,a=new u(this,{event:e,request:s,params:r}),i=this.Wt(a,s,e);return[i,this.Ut(i,a,s,e)]}async Wt(t,e,r){await t.runCallbacks("handlerWillStart",{event:r,request:e});let a=void 0;try{if(a=await this._handle(e,t),!a||"error"===a.type)throw new s.WorkboxError("no-response",{url:e.url})}catch(s){for(const i of t.iterateCallbacks("handlerDidError"))if(a=await i({error:s,event:r,request:e}),a)break;if(!a)throw s}for(const s of t.iterateCallbacks("handlerWillRespond"))a=await s({event:r,request:e,response:a});return a}async Ut(t,e,s,r){let a,i;try{a=await t}catch(i){}try{await e.runCallbacks("handlerDidRespond",{event:r,request:s,response:a}),await e.doneWaiting()}catch(t){i=t}if(await e.runCallbacks("handlerDidComplete",{event:r,request:s,response:a,error:i}),e.destroy(),i)throw i}}const f={cacheWillUpdate:async({response:t})=>200===t.status||0===t.status?t:null};return t.CacheFirst=class extends w{async _handle(t,e){let r,a=await e.cacheMatch(t);if(!a)try{a=await e.fetchAndCachePut(t)}catch(t){r=t}if(!a)throw new s.WorkboxError("no-response",{url:t.url,error:r});return a}},t.CacheOnly=class extends w{async _handle(t,e){const r=await e.cacheMatch(t);if(!r)throw new s.WorkboxError("no-response",{url:t.url});return r}},t.NetworkFirst=class extends w{constructor(t={}){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){const r=[],a=[];let i;if(this.Ct){const{id:s,promise:n}=this.Dt({request:t,logs:r,handler:e});i=s,a.push(n)}const n=this.Et({timeoutId:i,request:t,logs:r,handler:e});a.push(n);const o=await e.waitUntil((async()=>await e.waitUntil(Promise.race(a))||await n)());if(!o)throw new s.WorkboxError("no-response",{url:t.url});return o}Dt({request:t,logs:e,handler:s}){let r;return{promise:new Promise((e=>{r=setTimeout((async()=>{e(await s.cacheMatch(t))}),1e3*this.Ct)})),id:r}}async Et({timeoutId:t,request:e,logs:s,handler:r}){let a,i;try{i=await r.fetchAndCachePut(e)}catch(t){a=t}return t&&clearTimeout(t),!a&&i||(i=await r.cacheMatch(e)),i}},t.NetworkOnly=class extends w{constructor(t={}){super(t),this.Ct=t.networkTimeoutSeconds||0}async _handle(t,e){let r,a=void 0;try{const s=[e.fetch(t)];if(this.Ct){const t=c.timeout(1e3*this.Ct);s.push(t)}if(r=await Promise.race(s),!r)throw new Error("Timed out the network response after "+this.Ct+" seconds.")}catch(t){a=t}if(!r)throw new s.WorkboxError("no-response",{url:t.url,error:a});return r}},t.StaleWhileRevalidate=class extends w{constructor(t){super(t),this.plugins.some((t=>"cacheWillUpdate"in t))||this.plugins.unshift(f)}async _handle(t,e){const r=e.fetchAndCachePut(t).catch((()=>{}));let a,i=await e.cacheMatch(t);if(i);else try{i=await r}catch(t){a=t}if(!i)throw new s.WorkboxError("no-response",{url:t.url,error:a});return i}},t.Strategy=w,t.StrategyHandler=u,t}({},workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
//# sourceMappingURL=workbox-strategies.prod.js.map |
{ | ||
"name": "workbox-strategies", | ||
"version": "6.1.1", | ||
"version": "6.1.2", | ||
"license": "MIT", | ||
@@ -26,5 +26,5 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "^6.1.1" | ||
"workbox-core": "^6.1.2" | ||
}, | ||
"gitHead": "e103c29615990b6bfb28cd0b81f80412aaaa7aab" | ||
"gitHead": "d39796c135ab149d544fcfa20685608dfeb05026" | ||
} |
// @ts-ignore | ||
try{self['workbox:strategies:6.1.1']&&_()}catch(e){} | ||
try{self['workbox:strategies:6.1.2']&&_()}catch(e){} |
@@ -150,81 +150,79 @@ /* | ||
*/ | ||
fetch(input: RequestInfo): Promise<Response> { | ||
return this.waitUntil((async () => { | ||
const {event} = this; | ||
let request: Request = toRequest(input); | ||
async fetch(input: RequestInfo): Promise<Response> { | ||
const {event} = this; | ||
let request: Request = toRequest(input); | ||
if (request.mode === 'navigate' && | ||
event instanceof FetchEvent && | ||
event.preloadResponse) { | ||
const possiblePreloadResponse = await event.preloadResponse; | ||
if (possiblePreloadResponse) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log(`Using a preloaded navigation response for ` + | ||
`'${getFriendlyURL(request.url)}'`); | ||
} | ||
return possiblePreloadResponse; | ||
if (request.mode === 'navigate' && | ||
event instanceof FetchEvent && | ||
event.preloadResponse) { | ||
const possiblePreloadResponse = await event.preloadResponse; | ||
if (possiblePreloadResponse) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log(`Using a preloaded navigation response for ` + | ||
`'${getFriendlyURL(request.url)}'`); | ||
} | ||
return possiblePreloadResponse; | ||
} | ||
} | ||
// If there is a fetchDidFail plugin, we need to save a clone of the | ||
// original request before it's either modified by a requestWillFetch | ||
// plugin or before the original request's body is consumed via fetch(). | ||
const originalRequest = this.hasCallback('fetchDidFail') ? | ||
request.clone() : null; | ||
// If there is a fetchDidFail plugin, we need to save a clone of the | ||
// original request before it's either modified by a requestWillFetch | ||
// plugin or before the original request's body is consumed via fetch(). | ||
const originalRequest = this.hasCallback('fetchDidFail') ? | ||
request.clone() : null; | ||
try { | ||
for (const cb of this.iterateCallbacks('requestWillFetch')) { | ||
request = await cb({request: request.clone(), event}); | ||
} | ||
} catch (err) { | ||
throw new WorkboxError('plugin-error-request-will-fetch', { | ||
thrownError: err, | ||
}); | ||
try { | ||
for (const cb of this.iterateCallbacks('requestWillFetch')) { | ||
request = await cb({request: request.clone(), event}); | ||
} | ||
} catch (err) { | ||
throw new WorkboxError('plugin-error-request-will-fetch', { | ||
thrownError: err, | ||
}); | ||
} | ||
// The request can be altered by plugins with `requestWillFetch` making | ||
// the original request (most likely from a `fetch` event) different | ||
// from the Request we make. Pass both to `fetchDidFail` to aid debugging. | ||
const pluginFilteredRequest: Request = request.clone(); | ||
// The request can be altered by plugins with `requestWillFetch` making | ||
// the original request (most likely from a `fetch` event) different | ||
// from the Request we make. Pass both to `fetchDidFail` to aid debugging. | ||
const pluginFilteredRequest: Request = request.clone(); | ||
try { | ||
let fetchResponse: Response; | ||
try { | ||
let fetchResponse: Response; | ||
// See https://github.com/GoogleChrome/workbox/issues/1796 | ||
fetchResponse = await fetch(request, request.mode === 'navigate' ? | ||
undefined : this._strategy.fetchOptions); | ||
// See https://github.com/GoogleChrome/workbox/issues/1796 | ||
fetchResponse = await fetch(request, request.mode === 'navigate' ? | ||
undefined : this._strategy.fetchOptions); | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.debug(`Network request for ` + | ||
`'${getFriendlyURL(request.url)}' returned a response with ` + | ||
`status '${fetchResponse.status}'.`); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.debug(`Network request for ` + | ||
`'${getFriendlyURL(request.url)}' returned a response with ` + | ||
`status '${fetchResponse.status}'.`); | ||
} | ||
for (const callback of this.iterateCallbacks('fetchDidSucceed')) { | ||
fetchResponse = await callback({ | ||
event, | ||
request: pluginFilteredRequest, | ||
response: fetchResponse, | ||
}); | ||
} | ||
return fetchResponse; | ||
} catch (error) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.error(`Network request for `+ | ||
`'${getFriendlyURL(request.url)}' threw an error.`, error); | ||
} | ||
for (const callback of this.iterateCallbacks('fetchDidSucceed')) { | ||
fetchResponse = await callback({ | ||
event, | ||
request: pluginFilteredRequest, | ||
response: fetchResponse, | ||
}); | ||
} | ||
return fetchResponse; | ||
} catch (error) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log(`Network request for `+ | ||
`'${getFriendlyURL(request.url)}' threw an error.`, error); | ||
} | ||
// `originalRequest` will only exist if a `fetchDidFail` callback | ||
// is being used (see above). | ||
if (originalRequest) { | ||
await this.runCallbacks('fetchDidFail', { | ||
error, | ||
event, | ||
originalRequest: originalRequest.clone(), | ||
request: pluginFilteredRequest.clone(), | ||
}); | ||
} | ||
throw error; | ||
// `originalRequest` will only exist if a `fetchDidFail` callback | ||
// is being used (see above). | ||
if (originalRequest) { | ||
await this.runCallbacks('fetchDidFail', { | ||
error, | ||
event, | ||
originalRequest: originalRequest.clone(), | ||
request: pluginFilteredRequest.clone(), | ||
}); | ||
} | ||
})()); | ||
throw error; | ||
} | ||
} | ||
@@ -263,32 +261,30 @@ | ||
*/ | ||
cacheMatch(key: RequestInfo): Promise<Response | undefined> { | ||
return this.waitUntil((async () => { | ||
const request: Request = toRequest(key); | ||
let cachedResponse: Response | undefined; | ||
const {cacheName, matchOptions} = this._strategy; | ||
async cacheMatch(key: RequestInfo): Promise<Response | undefined> { | ||
const request: Request = toRequest(key); | ||
let cachedResponse: Response | undefined; | ||
const {cacheName, matchOptions} = this._strategy; | ||
const effectiveRequest = await this.getCacheKey(request, 'read'); | ||
const multiMatchOptions = {...matchOptions, ...{cacheName}}; | ||
const effectiveRequest = await this.getCacheKey(request, 'read'); | ||
const multiMatchOptions = {...matchOptions, ...{cacheName}}; | ||
cachedResponse = await caches.match(effectiveRequest, multiMatchOptions); | ||
cachedResponse = await caches.match(effectiveRequest, multiMatchOptions); | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (cachedResponse) { | ||
logger.debug(`Found a cached response in '${cacheName}'.`); | ||
} else { | ||
logger.debug(`No cached response found in '${cacheName}'.`); | ||
} | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (cachedResponse) { | ||
logger.debug(`Found a cached response in '${cacheName}'.`); | ||
} else { | ||
logger.debug(`No cached response found in '${cacheName}'.`); | ||
} | ||
} | ||
for (const callback of this.iterateCallbacks('cachedResponseWillBeUsed')) { | ||
cachedResponse = (await callback({ | ||
cacheName, | ||
matchOptions, | ||
cachedResponse, | ||
request: effectiveRequest, | ||
event: this.event, | ||
})) || undefined; | ||
} | ||
return cachedResponse; | ||
})()); | ||
for (const callback of this.iterateCallbacks('cachedResponseWillBeUsed')) { | ||
cachedResponse = (await callback({ | ||
cacheName, | ||
matchOptions, | ||
cachedResponse, | ||
request: effectiveRequest, | ||
event: this.event, | ||
})) || undefined; | ||
} | ||
return cachedResponse; | ||
} | ||
@@ -295,0 +291,0 @@ |
@@ -121,74 +121,72 @@ /* | ||
*/ | ||
fetch(input) { | ||
return this.waitUntil((async () => { | ||
const { event } = this; | ||
let request = toRequest(input); | ||
if (request.mode === 'navigate' && | ||
event instanceof FetchEvent && | ||
event.preloadResponse) { | ||
const possiblePreloadResponse = await event.preloadResponse; | ||
if (possiblePreloadResponse) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log(`Using a preloaded navigation response for ` + | ||
`'${getFriendlyURL(request.url)}'`); | ||
} | ||
return possiblePreloadResponse; | ||
async fetch(input) { | ||
const { event } = this; | ||
let request = toRequest(input); | ||
if (request.mode === 'navigate' && | ||
event instanceof FetchEvent && | ||
event.preloadResponse) { | ||
const possiblePreloadResponse = await event.preloadResponse; | ||
if (possiblePreloadResponse) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log(`Using a preloaded navigation response for ` + | ||
`'${getFriendlyURL(request.url)}'`); | ||
} | ||
return possiblePreloadResponse; | ||
} | ||
// If there is a fetchDidFail plugin, we need to save a clone of the | ||
// original request before it's either modified by a requestWillFetch | ||
// plugin or before the original request's body is consumed via fetch(). | ||
const originalRequest = this.hasCallback('fetchDidFail') ? | ||
request.clone() : null; | ||
try { | ||
for (const cb of this.iterateCallbacks('requestWillFetch')) { | ||
request = await cb({ request: request.clone(), event }); | ||
} | ||
} | ||
// If there is a fetchDidFail plugin, we need to save a clone of the | ||
// original request before it's either modified by a requestWillFetch | ||
// plugin or before the original request's body is consumed via fetch(). | ||
const originalRequest = this.hasCallback('fetchDidFail') ? | ||
request.clone() : null; | ||
try { | ||
for (const cb of this.iterateCallbacks('requestWillFetch')) { | ||
request = await cb({ request: request.clone(), event }); | ||
} | ||
catch (err) { | ||
throw new WorkboxError('plugin-error-request-will-fetch', { | ||
thrownError: err, | ||
} | ||
catch (err) { | ||
throw new WorkboxError('plugin-error-request-will-fetch', { | ||
thrownError: err, | ||
}); | ||
} | ||
// The request can be altered by plugins with `requestWillFetch` making | ||
// the original request (most likely from a `fetch` event) different | ||
// from the Request we make. Pass both to `fetchDidFail` to aid debugging. | ||
const pluginFilteredRequest = request.clone(); | ||
try { | ||
let fetchResponse; | ||
// See https://github.com/GoogleChrome/workbox/issues/1796 | ||
fetchResponse = await fetch(request, request.mode === 'navigate' ? | ||
undefined : this._strategy.fetchOptions); | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.debug(`Network request for ` + | ||
`'${getFriendlyURL(request.url)}' returned a response with ` + | ||
`status '${fetchResponse.status}'.`); | ||
} | ||
for (const callback of this.iterateCallbacks('fetchDidSucceed')) { | ||
fetchResponse = await callback({ | ||
event, | ||
request: pluginFilteredRequest, | ||
response: fetchResponse, | ||
}); | ||
} | ||
// The request can be altered by plugins with `requestWillFetch` making | ||
// the original request (most likely from a `fetch` event) different | ||
// from the Request we make. Pass both to `fetchDidFail` to aid debugging. | ||
const pluginFilteredRequest = request.clone(); | ||
try { | ||
let fetchResponse; | ||
// See https://github.com/GoogleChrome/workbox/issues/1796 | ||
fetchResponse = await fetch(request, request.mode === 'navigate' ? | ||
undefined : this._strategy.fetchOptions); | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.debug(`Network request for ` + | ||
`'${getFriendlyURL(request.url)}' returned a response with ` + | ||
`status '${fetchResponse.status}'.`); | ||
} | ||
for (const callback of this.iterateCallbacks('fetchDidSucceed')) { | ||
fetchResponse = await callback({ | ||
event, | ||
request: pluginFilteredRequest, | ||
response: fetchResponse, | ||
}); | ||
} | ||
return fetchResponse; | ||
return fetchResponse; | ||
} | ||
catch (error) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.log(`Network request for ` + | ||
`'${getFriendlyURL(request.url)}' threw an error.`, error); | ||
} | ||
catch (error) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
logger.error(`Network request for ` + | ||
`'${getFriendlyURL(request.url)}' threw an error.`, error); | ||
} | ||
// `originalRequest` will only exist if a `fetchDidFail` callback | ||
// is being used (see above). | ||
if (originalRequest) { | ||
await this.runCallbacks('fetchDidFail', { | ||
error, | ||
event, | ||
originalRequest: originalRequest.clone(), | ||
request: pluginFilteredRequest.clone(), | ||
}); | ||
} | ||
throw error; | ||
// `originalRequest` will only exist if a `fetchDidFail` callback | ||
// is being used (see above). | ||
if (originalRequest) { | ||
await this.runCallbacks('fetchDidFail', { | ||
error, | ||
event, | ||
originalRequest: originalRequest.clone(), | ||
request: pluginFilteredRequest.clone(), | ||
}); | ||
} | ||
})()); | ||
throw error; | ||
} | ||
} | ||
@@ -223,29 +221,27 @@ /** | ||
*/ | ||
cacheMatch(key) { | ||
return this.waitUntil((async () => { | ||
const request = toRequest(key); | ||
let cachedResponse; | ||
const { cacheName, matchOptions } = this._strategy; | ||
const effectiveRequest = await this.getCacheKey(request, 'read'); | ||
const multiMatchOptions = { ...matchOptions, ...{ cacheName } }; | ||
cachedResponse = await caches.match(effectiveRequest, multiMatchOptions); | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (cachedResponse) { | ||
logger.debug(`Found a cached response in '${cacheName}'.`); | ||
} | ||
else { | ||
logger.debug(`No cached response found in '${cacheName}'.`); | ||
} | ||
async cacheMatch(key) { | ||
const request = toRequest(key); | ||
let cachedResponse; | ||
const { cacheName, matchOptions } = this._strategy; | ||
const effectiveRequest = await this.getCacheKey(request, 'read'); | ||
const multiMatchOptions = { ...matchOptions, ...{ cacheName } }; | ||
cachedResponse = await caches.match(effectiveRequest, multiMatchOptions); | ||
if (process.env.NODE_ENV !== 'production') { | ||
if (cachedResponse) { | ||
logger.debug(`Found a cached response in '${cacheName}'.`); | ||
} | ||
for (const callback of this.iterateCallbacks('cachedResponseWillBeUsed')) { | ||
cachedResponse = (await callback({ | ||
cacheName, | ||
matchOptions, | ||
cachedResponse, | ||
request: effectiveRequest, | ||
event: this.event, | ||
})) || undefined; | ||
else { | ||
logger.debug(`No cached response found in '${cacheName}'.`); | ||
} | ||
return cachedResponse; | ||
})()); | ||
} | ||
for (const callback of this.iterateCallbacks('cachedResponseWillBeUsed')) { | ||
cachedResponse = (await callback({ | ||
cacheName, | ||
matchOptions, | ||
cachedResponse, | ||
request: effectiveRequest, | ||
event: this.event, | ||
})) || undefined; | ||
} | ||
return cachedResponse; | ||
} | ||
@@ -252,0 +248,0 @@ /** |
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
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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances 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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 2 instances in 1 package
413211
4607
Updatedworkbox-core@^6.1.2