workbox-precaching
Advanced tools
Comparing version 3.0.0-beta.1 to 3.0.0-beta.2
this.workbox = this.workbox || {}; | ||
this.workbox.precaching = (function (DBWrapper_mjs,cacheNames_mjs,logger_mjs,WorkboxError_mjs,fetchWrapper_mjs,cacheWrapper_mjs,assert_mjs,getFriendlyURL_mjs) { | ||
this.workbox.precaching = (function (DBWrapper_mjs,logger_mjs,cacheNames_mjs,WorkboxError_mjs,fetchWrapper_mjs,cacheWrapper_mjs,assert_mjs,getFriendlyURL_mjs) { | ||
'use strict'; | ||
try { | ||
self.workbox.v['workbox:precaching:3.0.0-beta.1'] = 1; | ||
self.workbox.v['workbox:precaching:3.0.0-beta.2'] = 1; | ||
} catch (e) {} // eslint-disable-line | ||
@@ -113,9 +113,9 @@ | ||
* | ||
* @param {string} cacheName | ||
* | ||
* @param {string} dbName | ||
* @private | ||
*/ | ||
constructor(cacheName) { | ||
this._cacheName = cacheNames_mjs.cacheNames.getPrecacheName(cacheName); | ||
this._db = new DBWrapper_mjs.DBWrapper(`workbox-precaching`, 2, { | ||
constructor(dbName) { | ||
// This ensures the db name contains only letters, numbers, '-', '_' and '$' | ||
const filteredDBName = dbName.replace(/[^\w-]/g, '_'); | ||
this._db = new DBWrapper_mjs.DBWrapper(filteredDBName, 2, { | ||
onupgradeneeded: this._handleUpgrade | ||
@@ -152,2 +152,3 @@ }); | ||
* | ||
* @param {string} cacheName | ||
* @param {PrecacheEntry} precacheEntry | ||
@@ -158,3 +159,3 @@ * @return {boolean} | ||
*/ | ||
_isEntryCached(precacheEntry) { | ||
_isEntryCached(cacheName, precacheEntry) { | ||
var _this = this; | ||
@@ -168,3 +169,3 @@ | ||
const openCache = yield caches.open(_this._cacheName); | ||
const openCache = yield caches.open(cacheName); | ||
const cachedResponse = yield openCache.match(precacheEntry._cacheRequest); | ||
@@ -583,3 +584,3 @@ return !!cachedResponse; | ||
* @return { | ||
* Promise<module:workbox-precaching.PrecacheController.InstallResult>} | ||
* Promise<workbox.precaching.InstallResult>} | ||
*/ | ||
@@ -605,2 +606,5 @@ install(options = {}) { | ||
// Clear any existing temp cache | ||
yield caches.delete(_this._getTempCacheName()); | ||
const entriesToPrecache = []; | ||
@@ -610,3 +614,3 @@ const entriesAlreadyPrecached = []; | ||
for (const precacheEntry of _this._entriesToCacheMap.values()) { | ||
if (yield _this._precacheDetailsModel._isEntryCached(precacheEntry)) { | ||
if (yield _this._precacheDetailsModel._isEntryCached(_this._cacheName, precacheEntry)) { | ||
entriesAlreadyPrecached.push(precacheEntry); | ||
@@ -620,3 +624,3 @@ } else { | ||
yield Promise.all(entriesToPrecache.map(function (precacheEntry) { | ||
return _this._cacheEntry(precacheEntry, options.plugins); | ||
return _this._cacheEntryInTemp(precacheEntry, options.plugins); | ||
})); | ||
@@ -636,2 +640,47 @@ | ||
/** | ||
* Takes the current set of temporary files and moves them to the final | ||
* cache, deleting the temporary cache once copying is complete. | ||
* | ||
* @return { | ||
* Promise<workbox.precaching.CleanupResult>} | ||
* Resolves with an object containing details of the deleted cache requests | ||
* and precache revision details. | ||
*/ | ||
activate() { | ||
var _this2 = this; | ||
return babelHelpers.asyncToGenerator(function* () { | ||
const tempCache = yield caches.open(_this2._getTempCacheName()); | ||
const requests = yield tempCache.keys(); | ||
yield Promise.all(requests.map((() => { | ||
var _ref = babelHelpers.asyncToGenerator(function* (request) { | ||
const response = yield tempCache.match(request); | ||
yield cacheWrapper_mjs.cacheWrapper.put(_this2._cacheName, request, response); | ||
yield tempCache.delete(request); | ||
}); | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
})())); | ||
yield caches.delete(_this2._getTempCacheName()); | ||
return _this2._cleanup(); | ||
})(); | ||
} | ||
/** | ||
* Returns the name of the temporary cache. | ||
* | ||
* @return {string} | ||
* | ||
* @private | ||
*/ | ||
_getTempCacheName() { | ||
return `${this._cacheName}-temp`; | ||
} | ||
/** | ||
* Requests the entry and saves it to the cache if the response | ||
@@ -649,4 +698,4 @@ * is valid. | ||
*/ | ||
_cacheEntry(precacheEntry, plugins) { | ||
var _this2 = this; | ||
_cacheEntryInTemp(precacheEntry, plugins) { | ||
var _this3 = this; | ||
@@ -660,5 +709,5 @@ return babelHelpers.asyncToGenerator(function* () { | ||
yield cacheWrapper_mjs.cacheWrapper.put(_this2._cacheName, precacheEntry._cacheRequest, response, plugins); | ||
yield cacheWrapper_mjs.cacheWrapper.put(_this3._getTempCacheName(), precacheEntry._cacheRequest, response, plugins); | ||
yield _this2._precacheDetailsModel._addEntry(precacheEntry); | ||
yield _this3._precacheDetailsModel._addEntry(precacheEntry); | ||
@@ -676,12 +725,14 @@ return true; | ||
* @return { | ||
* Promise<module:workbox-precaching.PrecacheController.CleanupResult>} | ||
* Promise<workbox.precaching.CleanupResult>} | ||
* Resolves with an object containing details of the deleted cache requests | ||
* and precache revision details. | ||
* | ||
* @private | ||
*/ | ||
cleanup() { | ||
var _this3 = this; | ||
_cleanup() { | ||
var _this4 = this; | ||
return babelHelpers.asyncToGenerator(function* () { | ||
const expectedCacheUrls = []; | ||
_this3._entriesToCacheMap.forEach(function (entry) { | ||
_this4._entriesToCacheMap.forEach(function (entry) { | ||
const fullUrl = new URL(entry._cacheRequest.url, location).toString(); | ||
@@ -691,3 +742,3 @@ expectedCacheUrls.push(fullUrl); | ||
const [deletedCacheRequests, deletedRevisionDetails] = yield Promise.all([_this3._cleanupCache(expectedCacheUrls), _this3._cleanupDetailsModel(expectedCacheUrls)]); | ||
const [deletedCacheRequests, deletedRevisionDetails] = yield Promise.all([_this4._cleanupCache(expectedCacheUrls), _this4._cleanupDetailsModel(expectedCacheUrls)]); | ||
@@ -716,6 +767,6 @@ { | ||
_cleanupCache(expectedCacheUrls) { | ||
var _this4 = this; | ||
var _this5 = this; | ||
return babelHelpers.asyncToGenerator(function* () { | ||
if (!(yield caches.has(_this4._cacheName))) { | ||
if (!(yield caches.has(_this5._cacheName))) { | ||
// Cache doesn't exist, so nothing to delete | ||
@@ -725,3 +776,3 @@ return []; | ||
const cache = yield caches.open(_this4._cacheName); | ||
const cache = yield caches.open(_this5._cacheName); | ||
const cachedRequests = yield cache.keys(); | ||
@@ -752,6 +803,6 @@ const cachedRequestsToDelete = cachedRequests.filter(function (cachedRequest) { | ||
_cleanupDetailsModel(expectedCacheUrls) { | ||
var _this5 = this; | ||
var _this6 = this; | ||
return babelHelpers.asyncToGenerator(function* () { | ||
const revisionedEntries = yield _this5._precacheDetailsModel._getAllEntries(); | ||
const revisionedEntries = yield _this6._precacheDetailsModel._getAllEntries(); | ||
const detailsToDelete = revisionedEntries.filter(function (entry) { | ||
@@ -763,3 +814,3 @@ const fullUrl = new URL(entry.value.url, location).toString(); | ||
yield Promise.all(detailsToDelete.map(function (entry) { | ||
return _this5._precacheDetailsModel._deleteEntry(entry.primaryKey); | ||
return _this6._precacheDetailsModel._deleteEntry(entry.primaryKey); | ||
})); | ||
@@ -958,3 +1009,3 @@ return detailsToDelete.map(function (entry) { | ||
self.addEventListener('activate', event => { | ||
event.waitUntil(precacheController.cleanup()); | ||
event.waitUntil(precacheController.activate()); | ||
}); | ||
@@ -961,0 +1012,0 @@ }; |
@@ -1,3 +0,3 @@ | ||
this.workbox=this.workbox||{},this.workbox.precaching=function(e,t,n,r,s){"use strict";try{self.workbox.v["workbox:precaching:3.0.0-beta.1"]=1}catch(e){}class i{constructor(e,t,n,r){this.e=e,this.t=t,this.n=n;const s=new Request(t,{credentials:"same-origin"});this.r=s,this.s=r?this.i(s):s}i(e){let t=e.url;const n={credentials:"same-origin"};if("cache"in Request.prototype)n.cache="reload";else{const e=new URL(t,location),n=encodeURIComponent;e.search+=(e.search?"&":"")+n("_workbox-cache-bust")+"="+n(this.n),t=e.toString()}return new Request(t,n)}}const c="revision",o="url",l="precached-details-models";class a{constructor(n){this.c=t.cacheNames.getPrecacheName(n),this.o=new e.DBWrapper("workbox-precaching",2,{onupgradeneeded:this.l})}l(e){const t=e.target.result;e.oldVersion<2&&(t.objectStoreNames.contains("workbox-precaching")&&t.deleteObjectStore("workbox-precaching"),t.objectStoreNames.contains(l)&&t.deleteObjectStore(l)),t.createObjectStore(l)}a(e){var t=this;return babelHelpers.asyncToGenerator(function*(){if((yield t.u(e.t))!==e.n)return!1;return!!(yield(yield caches.open(t.c)).match(e.r))})()}h(){var e=this;return babelHelpers.asyncToGenerator(function*(){return yield e.o.getAllMatching(l,{includeKeys:!0})})()}u(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=yield t.o.get(l,e);return n?n[c]:null})()}d(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.o.put(l,{[c]:e.n,[o]:e.r.url},e.t)})()}f(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.o.delete(l,e)})()}}const u=(()=>{var e=babelHelpers.asyncToGenerator(function*(e){const t=e.clone(),n=yield"body"in t?Promise.resolve(t.body):t.blob();return new Response(n,["headers","status","statusText"].map(function(e){return t[e]}))});return function(t){return e.apply(this,arguments)}})();class h{constructor(e){this.c=t.cacheNames.getPrecacheName(e),this.y=new Map,this.b=new a(this.c)}addToCacheList(e){e.map(e=>{this.p(this.w(e))})}w(e){switch(typeof e){case"string":return new i(e,e,e);case"object":return new i(e,e.url,e.revision||e.url,!!e.revision);default:throw new n.WorkboxError("add-to-cache-list-unexpected-type",{entry:e})}}p(e){const t=this.y.get(e.t);if(t){if(t.n!==e.n)throw new n.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:t.e,secondEntry:e.e})}else this.y.set(e.t,e)}install(e={}){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=[],r=[];for(const e of t.y.values())(yield t.b.a(e))?r.push(e):n.push(e);return yield Promise.all(n.map(function(n){return t.R(n,e.plugins)})),{updatedEntries:n,notUpdatedEntries:r}})()}R(e,t){var n=this;return babelHelpers.asyncToGenerator(function*(){let i=yield r.fetchWrapper.fetch(e.s,null,t);return i.redirected&&(i=yield u(i)),yield s.cacheWrapper.put(n.c,e.r,i,t),yield n.b.d(e),!0})()}cleanup(){var e=this;return babelHelpers.asyncToGenerator(function*(){const t=[];e.y.forEach(function(e){const n=new URL(e.r.url,location).toString();t.push(n)});const[n,r]=yield Promise.all([e.g(t),e.U(t)]);return{deletedCacheRequests:n,deletedRevisionDetails:r}})()}g(e){var t=this;return babelHelpers.asyncToGenerator(function*(){if(!(yield caches.has(t.c)))return[];const n=yield caches.open(t.c),r=(yield n.keys()).filter(function(t){return!e.includes(new URL(t.url,location).toString())});return yield Promise.all(r.map(function(e){return n.delete(e)})),r.map(function(e){return e.url})})()}U(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=(yield t.b.h()).filter(function(t){const n=new URL(t.value.url,location).toString();return!e.includes(n)});return yield Promise.all(n.map(function(e){return t.b.f(e.primaryKey)})),n.map(function(e){return e.value.url})})()}getCachedUrls(){return Array.from(this.y.keys()).map(e=>new URL(e,location).href)}}var d=Object.freeze({PrecacheController:h});let f=!1,y=!1,b=!1,p=[];const w=t.cacheNames.getPrecacheName(),R=new h(w),g=(e,{ignoreUrlParametersMatching:t=[/^utm_/],directoryIndex:n="index.html",cleanUrls:r=!0,urlManipulation:s=null}={})=>{const i=new URL(e,location);i.hash="";const c=((e,t)=>{const n=e.search.slice(1).split("&").map(e=>e.split("=")).filter(e=>t.every(t=>!t.test(e[0]))).map(e=>e.join("=")),r=new URL(e);return r.search=n.join("&"),r})(i,t);let o=[i,c];if(n&&c.pathname.endsWith("/")){const e=new URL(c);e.pathname+=n,o.push(e)}if(r){const e=new URL(c);e.pathname+=".html",o.push(e)}if(s){const e=s({url:i});o=o.concat(e)}const l=R.getCachedUrls();for(const e of o)if(-1!==l.indexOf(e.href))return e.href;return null},v={};v.precache=(e=>{R.addToCacheList(e),f||e.length<=0||(f=!0,self.addEventListener("install",e=>{e.waitUntil(R.install({suppressWarnings:b,plugins:p}))}),self.addEventListener("activate",e=>{e.waitUntil(R.cleanup())}))}),v.addRoute=(e=>{y||(y=!0,self.addEventListener("fetch",t=>{const n=g(t.request.url,e);if(!n)return;let r=caches.open(w).then(e=>e.match(n)).then(e=>e||fetch(n));t.respondWith(r)}))}),v.precacheAndRoute=((e,t)=>{v.precache(e),v.addRoute(t)}),v.suppressWarnings=(e=>{b=e}),v.addPlugins=(e=>{p=p.concat(e)});return Object.assign(v,d)}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.precaching=function(e,t,n,r,s){"use strict";try{self.workbox.v["workbox:precaching:3.0.0-beta.2"]=1}catch(e){}class i{constructor(e,t,n,r){this.e=e,this.t=t,this.n=n;const s=new Request(t,{credentials:"same-origin"});this.r=s,this.s=r?this.i(s):s}i(e){let t=e.url;const n={credentials:"same-origin"};if("cache"in Request.prototype)n.cache="reload";else{const e=new URL(t,location),n=encodeURIComponent;e.search+=(e.search?"&":"")+n("_workbox-cache-bust")+"="+n(this.n),t=e.toString()}return new Request(t,n)}}const c="revision",o="url",l="precached-details-models";class a{constructor(t){const n=t.replace(/[^\w-]/g,"_");this.c=new e.DBWrapper(n,2,{onupgradeneeded:this.o})}o(e){const t=e.target.result;e.oldVersion<2&&(t.objectStoreNames.contains("workbox-precaching")&&t.deleteObjectStore("workbox-precaching"),t.objectStoreNames.contains(l)&&t.deleteObjectStore(l)),t.createObjectStore(l)}l(e,t){var n=this;return babelHelpers.asyncToGenerator(function*(){if((yield n.a(t.t))!==t.n)return!1;return!!(yield(yield caches.open(e)).match(t.r))})()}u(){var e=this;return babelHelpers.asyncToGenerator(function*(){return yield e.c.getAllMatching(l,{includeKeys:!0})})()}a(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=yield t.c.get(l,e);return n?n[c]:null})()}d(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.c.put(l,{[c]:e.n,[o]:e.r.url},e.t)})()}h(e){var t=this;return babelHelpers.asyncToGenerator(function*(){yield t.c.delete(l,e)})()}}const u=(()=>{var e=babelHelpers.asyncToGenerator(function*(e){const t=e.clone(),n=yield"body"in t?Promise.resolve(t.body):t.blob();return new Response(n,["headers","status","statusText"].map(function(e){return t[e]}))});return function(t){return e.apply(this,arguments)}})();class d{constructor(e){this.f=t.cacheNames.getPrecacheName(e),this.y=new Map,this.b=new a(this.f)}addToCacheList(e){e.map(e=>{this.p(this.w(e))})}w(e){switch(typeof e){case"string":return new i(e,e,e);case"object":return new i(e,e.url,e.revision||e.url,!!e.revision);default:throw new n.WorkboxError("add-to-cache-list-unexpected-type",{entry:e})}}p(e){const t=this.y.get(e.t);if(t){if(t.n!==e.n)throw new n.WorkboxError("add-to-cache-list-conflicting-entries",{firstEntry:t.e,secondEntry:e.e})}else this.y.set(e.t,e)}install(e={}){var t=this;return babelHelpers.asyncToGenerator(function*(){yield caches.delete(t.m());const n=[],r=[];for(const e of t.y.values())(yield t.b.l(t.f,e))?r.push(e):n.push(e);return yield Promise.all(n.map(function(n){return t.R(n,e.plugins)})),{updatedEntries:n,notUpdatedEntries:r}})()}activate(){var e=this;return babelHelpers.asyncToGenerator(function*(){const t=yield caches.open(e.m()),n=yield t.keys();return yield Promise.all(n.map((()=>{var n=babelHelpers.asyncToGenerator(function*(n){const r=yield t.match(n);yield s.cacheWrapper.put(e.f,n,r),yield t.delete(n)});return function(e){return n.apply(this,arguments)}})())),yield caches.delete(e.m()),e.g()})()}m(){return`${this.f}-temp`}R(e,t){var n=this;return babelHelpers.asyncToGenerator(function*(){let i=yield r.fetchWrapper.fetch(e.s,null,t);return i.redirected&&(i=yield u(i)),yield s.cacheWrapper.put(n.m(),e.r,i,t),yield n.b.d(e),!0})()}g(){var e=this;return babelHelpers.asyncToGenerator(function*(){const t=[];e.y.forEach(function(e){const n=new URL(e.r.url,location).toString();t.push(n)});const[n,r]=yield Promise.all([e._(t),e.U(t)]);return{deletedCacheRequests:n,deletedRevisionDetails:r}})()}_(e){var t=this;return babelHelpers.asyncToGenerator(function*(){if(!(yield caches.has(t.f)))return[];const n=yield caches.open(t.f),r=(yield n.keys()).filter(function(t){return!e.includes(new URL(t.url,location).toString())});return yield Promise.all(r.map(function(e){return n.delete(e)})),r.map(function(e){return e.url})})()}U(e){var t=this;return babelHelpers.asyncToGenerator(function*(){const n=(yield t.b.u()).filter(function(t){const n=new URL(t.value.url,location).toString();return!e.includes(n)});return yield Promise.all(n.map(function(e){return t.b.h(e.primaryKey)})),n.map(function(e){return e.value.url})})()}getCachedUrls(){return Array.from(this.y.keys()).map(e=>new URL(e,location).href)}}var h=Object.freeze({PrecacheController:d});let f=!1,y=!1,b=!1,p=[];const w=t.cacheNames.getPrecacheName(),v=new d(w),m=(e,{ignoreUrlParametersMatching:t=[/^utm_/],directoryIndex:n="index.html",cleanUrls:r=!0,urlManipulation:s=null}={})=>{const i=new URL(e,location);i.hash="";const c=((e,t)=>{const n=e.search.slice(1).split("&").map(e=>e.split("=")).filter(e=>t.every(t=>!t.test(e[0]))).map(e=>e.join("=")),r=new URL(e);return r.search=n.join("&"),r})(i,t);let o=[i,c];if(n&&c.pathname.endsWith("/")){const e=new URL(c);e.pathname+=n,o.push(e)}if(r){const e=new URL(c);e.pathname+=".html",o.push(e)}if(s){const e=s({url:i});o=o.concat(e)}const l=v.getCachedUrls();for(const e of o)if(-1!==l.indexOf(e.href))return e.href;return null},R={};R.precache=(e=>{v.addToCacheList(e),f||e.length<=0||(f=!0,self.addEventListener("install",e=>{e.waitUntil(v.install({suppressWarnings:b,plugins:p}))}),self.addEventListener("activate",e=>{e.waitUntil(v.activate())}))}),R.addRoute=(e=>{y||(y=!0,self.addEventListener("fetch",t=>{const n=m(t.request.url,e);if(!n)return;let r=caches.open(w).then(e=>e.match(n)).then(e=>e||fetch(n));t.respondWith(r)}))}),R.precacheAndRoute=((e,t)=>{R.precache(e),R.addRoute(t)}),R.suppressWarnings=(e=>{b=e}),R.addPlugins=(e=>{p=p.concat(e)});return Object.assign(R,h)}(workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private,workbox.core._private); | ||
//# sourceMappingURL=workbox-precaching.prod.js.map |
{ | ||
"name": "workbox-precaching", | ||
"version": "3.0.0-beta.1", | ||
"version": "3.0.0-beta.2", | ||
"license": "Apache-2.0", | ||
@@ -28,4 +28,4 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "^3.0.0-beta.1" | ||
"workbox-core": "^3.0.0-beta.2" | ||
} | ||
} |
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
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
123647
2099
Updatedworkbox-core@^3.0.0-beta.2