workbox-routing
Advanced tools
Comparing version 4.0.0-rc.0 to 4.0.0-rc.1
this.workbox = this.workbox || {}; | ||
this.workbox.routing = (function (exports,assert_mjs,logger_mjs,WorkboxError_mjs,getFriendlyURL_mjs,cacheNames_mjs) { | ||
this.workbox.routing = (function (exports, assert_mjs, logger_mjs, cacheNames_mjs, WorkboxError_mjs, getFriendlyURL_mjs) { | ||
'use strict'; | ||
try { | ||
self['workbox:routing:4.0.0-rc.0'] && _(); | ||
self['workbox:routing:4.0.0-rc.1'] && _(); | ||
} catch (e) {} // eslint-disable-line | ||
@@ -948,2 +948,49 @@ | ||
/* | ||
Copyright 2019 Google LLC | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
/** | ||
* If a Route throws an error while handling a request, this `handler` | ||
* will be called and given a chance to provide a response. | ||
* | ||
* @param {workbox.routing.Route~handlerCallback} handler A callback | ||
* function that returns a Promise resulting in a Response. | ||
* | ||
* @alias workbox.routing.setCatchHandler | ||
*/ | ||
const setCatchHandler = handler => { | ||
const defaultRouter = getOrCreateDefaultRouter(); | ||
defaultRouter.setCatchHandler(handler); | ||
}; | ||
/* | ||
Copyright 2019 Google LLC | ||
Use of this source code is governed by an MIT-style | ||
license that can be found in the LICENSE file or at | ||
https://opensource.org/licenses/MIT. | ||
*/ | ||
/** | ||
* Define a default `handler` that's called when no routes explicitly | ||
* match the incoming request. | ||
* | ||
* Without a default handler, unmatched requests will go against the | ||
* network as if there were no service worker present. | ||
* | ||
* @param {workbox.routing.Route~handlerCallback} handler A callback | ||
* function that returns a Promise resulting in a Response. | ||
* | ||
* @alias workbox.routing.setDefaultHandler | ||
*/ | ||
const setDefaultHandler = handler => { | ||
const defaultRouter = getOrCreateDefaultRouter(); | ||
defaultRouter.setDefaultHandler(handler); | ||
}; | ||
/* | ||
Copyright 2018 Google LLC | ||
@@ -966,7 +1013,8 @@ | ||
exports.Router = Router; | ||
exports.setCatchHandler = setCatchHandler; | ||
exports.setDefaultHandler = setDefaultHandler; | ||
return exports; | ||
}({},workbox.core._private,workbox.core._private,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-routing.dev.js.map |
@@ -1,3 +0,2 @@ | ||
this.workbox=this.workbox||{},this.workbox.routing=function(t,e,r){"use strict";try{self["workbox:routing:4.0.0-rc.0"]&&_()}catch(t){}const s="GET",n=t=>t&&"object"==typeof t?t:{handle:t};class o{constructor(t,e,r){this.handler=n(e),this.match=t,this.method=r||s}}class i extends o{constructor(t,{whitelist:e=[/./],blacklist:r=[]}={}){super(t=>this.t(t),t),this.e=e,this.r=r}t({url:t,request:e}){if("navigate"!==e.mode)return!1;const r=t.pathname+t.search;for(const t of this.r)if(t.test(r))return!1;return!!this.e.some(t=>t.test(r))}}class u extends o{constructor(t,e,r){super(({url:e})=>{const r=t.exec(e.href);return r?e.origin!==location.origin&&0!==r.index?null:r.slice(1):null},e,r)}}class c{constructor(){this.s=new Map}get routes(){return this.s}addFetchListener(){self.addEventListener("fetch",t=>{const{request:e}=t,r=this.handleRequest({request:e,event:t});r&&t.respondWith(r)})}addCacheListener(){self.addEventListener("message",t=>{const{type:e,meta:r,payload:s}=t.data;if("CACHE_URLS"===e&&"workbox-window"===r)for(let e of s.urlsToCache){"string"==typeof e&&(e=[e]);const r=new Request(...e);this.handleRequest({request:r,event:t})}})}handleRequest({request:t,event:e}){const r=new URL(t.url,location);if(!r.protocol.startsWith("http"))return;let s,{params:n,route:o}=this.findMatchingRoute({url:r,request:t,event:e}),i=o&&o.handler;if(!i&&this.n&&(i=this.n),i){try{s=i.handle({url:r,request:t,event:e,params:n})}catch(t){s=Promise.reject(t)}return s&&this.o&&(s=s.catch(t=>this.o.handle({url:r,event:e,err:t}))),s}}findMatchingRoute({url:t,request:e,event:r}){const s=this.s.get(e.method)||[];for(const n of s){let s,o=n.match({url:t,request:e,event:r});if(o)return Array.isArray(o)&&o.length>0?s=o:o.constructor===Object&&Object.keys(o).length>0&&(s=o),{route:n,params:s}}return{}}setDefaultHandler(t){this.n=n(t)}setCatchHandler(t){this.o=n(t)}registerRoute(t){this.s.has(t.method)||this.s.set(t.method,[]),this.s.get(t.method).push(t)}unregisterRoute(t){if(!this.s.has(t.method))throw new e.WorkboxError("unregister-route-but-not-found-with-method",{method:t.method});const r=this.s.get(t.method).indexOf(t);if(!(r>-1))throw new e.WorkboxError("unregister-route-route-not-registered");this.s.get(t.method).splice(r,1)}}let h;const a=()=>(h||((h=new c).addFetchListener(),h.addCacheListener()),h);return t.NavigationRoute=i,t.RegExpRoute=u,t.registerNavigationRoute=((t,e={})=>{const s=r.cacheNames.getPrecacheName(e.cacheName),n=new i(async()=>{try{const e=await caches.match(t,{cacheName:s});if(e)return e;throw new Error(`The cache ${s} did not have an entry for `+`${t}.`)}catch(e){return fetch(t)}},{whitelist:e.whitelist,blacklist:e.blacklist});return a().registerRoute(n),n}),t.registerRoute=((t,r,s="GET")=>{let n;if("string"==typeof t){const e=new URL(t,location);n=new o(({url:t})=>t.href===e.href,r,s)}else if(t instanceof RegExp)n=new u(t,r,s);else if("function"==typeof t)n=new o(t,r,s);else{if(!(t instanceof o))throw new e.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});n=t}return a().registerRoute(n),n}),t.Route=o,t.Router=c,t}({},workbox.core._private,workbox.core._private); | ||
this.workbox=this.workbox||{},this.workbox.routing=function(t,e,r){"use strict";try{self["workbox:routing:4.0.0-rc.1"]&&_()}catch(t){}const s="GET",n=t=>t&&"object"==typeof t?t:{handle:t};class o{constructor(t,e,r){this.handler=n(e),this.match=t,this.method=r||s}}class i extends o{constructor(t,{whitelist:e=[/./],blacklist:r=[]}={}){super(t=>this.t(t),t),this.s=e,this.o=r}t({url:t,request:e}){if("navigate"!==e.mode)return!1;const r=t.pathname+t.search;for(const t of this.o)if(t.test(r))return!1;return!!this.s.some(t=>t.test(r))}}class u extends o{constructor(t,e,r){super(({url:e})=>{const r=t.exec(e.href);return r?e.origin!==location.origin&&0!==r.index?null:r.slice(1):null},e,r)}}class c{constructor(){this.i=new Map}get routes(){return this.i}addFetchListener(){self.addEventListener("fetch",t=>{const{request:e}=t,r=this.handleRequest({request:e,event:t});r&&t.respondWith(r)})}addCacheListener(){self.addEventListener("message",t=>{const{type:e,meta:r,payload:s}=t.data;if("CACHE_URLS"===e&&"workbox-window"===r)for(let e of s.urlsToCache){"string"==typeof e&&(e=[e]);const r=new Request(...e);this.handleRequest({request:r,event:t})}})}handleRequest({request:t,event:e}){const r=new URL(t.url,location);if(!r.protocol.startsWith("http"))return;let s,{params:n,route:o}=this.findMatchingRoute({url:r,request:t,event:e}),i=o&&o.handler;if(!i&&this.u&&(i=this.u),i){try{s=i.handle({url:r,request:t,event:e,params:n})}catch(t){s=Promise.reject(t)}return s&&this.h&&(s=s.catch(t=>this.h.handle({url:r,event:e,err:t}))),s}}findMatchingRoute({url:t,request:e,event:r}){const s=this.i.get(e.method)||[];for(const n of s){let s,o=n.match({url:t,request:e,event:r});if(o)return Array.isArray(o)&&o.length>0?s=o:o.constructor===Object&&Object.keys(o).length>0&&(s=o),{route:n,params:s}}return{}}setDefaultHandler(t){this.u=n(t)}setCatchHandler(t){this.h=n(t)}registerRoute(t){this.i.has(t.method)||this.i.set(t.method,[]),this.i.get(t.method).push(t)}unregisterRoute(t){if(!this.i.has(t.method))throw new r.WorkboxError("unregister-route-but-not-found-with-method",{method:t.method});const e=this.i.get(t.method).indexOf(t);if(!(e>-1))throw new r.WorkboxError("unregister-route-route-not-registered");this.i.get(t.method).splice(e,1)}}let h;const a=()=>(h||((h=new c).addFetchListener(),h.addCacheListener()),h);return t.NavigationRoute=i,t.RegExpRoute=u,t.registerNavigationRoute=((t,r={})=>{const s=e.cacheNames.getPrecacheName(r.cacheName),n=new i(async()=>{try{const e=await caches.match(t,{cacheName:s});if(e)return e;throw new Error(`The cache ${s} did not have an entry for `+`${t}.`)}catch(e){return fetch(t)}},{whitelist:r.whitelist,blacklist:r.blacklist});return a().registerRoute(n),n}),t.registerRoute=((t,e,s="GET")=>{let n;if("string"==typeof t){const r=new URL(t,location);n=new o(({url:t})=>t.href===r.href,e,s)}else if(t instanceof RegExp)n=new u(t,e,s);else if("function"==typeof t)n=new o(t,e,s);else{if(!(t instanceof o))throw new r.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});n=t}return a().registerRoute(n),n}),t.Route=o,t.Router=c,t.setCatchHandler=(t=>{a().setCatchHandler(t)}),t.setDefaultHandler=(t=>{a().setDefaultHandler(t)}),t}({},workbox.core._private,workbox.core._private); | ||
//# sourceMappingURL=workbox-routing.prod.js.map |
{ | ||
"name": "workbox-routing", | ||
"version": "4.0.0-rc.0", | ||
"version": "4.0.0-rc.1", | ||
"license": "MIT", | ||
@@ -30,5 +30,5 @@ "author": "Google's Web DevRel Team", | ||
"dependencies": { | ||
"workbox-core": "^4.0.0-rc.0" | ||
"workbox-core": "^4.0.0-rc.1" | ||
}, | ||
"gitHead": "895940b985bea024e086713c319af216f7c5ee95" | ||
"gitHead": "5e19e1c192d867f0db97e23f1262c3cab19bf6c6" | ||
} |
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 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
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
160563
21
1858
Updatedworkbox-core@^4.0.0-rc.1