Socket
Socket
Sign inDemoInstall

workbox-routing

Package Overview
Dependencies
Maintainers
4
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

workbox-routing - npm Package Compare versions

Comparing version 4.0.0-beta.1 to 4.0.0-beta.2

44

build/workbox-routing.dev.js

@@ -6,3 +6,3 @@ this.workbox = this.workbox || {};

try {
self.workbox.v['workbox:routing:4.0.0-beta.1'] = 1;
self['workbox:routing:4.0.0-beta.2'] && _();
} catch (e) {} // eslint-disable-line

@@ -392,4 +392,22 @@

* Adds a message event listener for URLs to cache from the window.
* This is useful to cache resources loaded prior to when the service worker
* started controlling the page.
* This is useful to cache resources loaded on the page prior to when the
* service worker started controlling it.
*
* The format of the message data sent from the window should be as follows.
* Where the `urlsToCache` array may consist of URL strings or an array of
* URL string + `requestInit` object (the same as you'd pass to `fetch()`).
*
* ```
* {
* type: 'CACHE_URLS',
* meta: 'workbox-window',
* payload: {
* urlsToCache: [
* './script1.js',
* './script2.js',
* ['./script3.js', {mode: 'no-cors'}],
* ],
* },
* }
* ```
*/

@@ -400,13 +418,19 @@

self.addEventListener('message', event => {
if (event.data.type === 'CACHE_URLS' && event.data.meta === 'workbox-window') {
const {
urlsToCache
} = event.data.payload;
const {
type,
meta,
payload
} = event.data;
if (type === 'CACHE_URLS' && meta === 'workbox-window') {
{
logger_mjs.logger.debug(`Caching URLs from the window`, urlsToCache);
logger_mjs.logger.debug(`Caching URLs from the window`, payload.urlsToCache);
}
for (const url of urlsToCache) {
const request = new Request(url);
for (let entry of payload.urlsToCache) {
if (typeof entry === 'string') {
entry = [entry];
}
const request = new Request(...entry);
this.handleRequest({

@@ -413,0 +437,0 @@ request,

@@ -1,3 +0,3 @@

this.workbox=this.workbox||{},this.workbox.routing=function(t,e,r){"use strict";try{self.workbox.v["workbox:routing:4.0.0-beta.1"]=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.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=>{if("CACHE_URLS"===t.data.type&&"workbox-window"===t.data.meta){const{urlsToCache:e}=t.data.payload;for(const r of e){const e=new Request(r);this.handleRequest({request:e,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-beta.2"]&&_()}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);
//# sourceMappingURL=workbox-routing.prod.js.map
{
"name": "workbox-routing",
"version": "4.0.0-beta.1",
"version": "4.0.0-beta.2",
"license": "MIT",

@@ -30,5 +30,5 @@ "author": "Google's Web DevRel Team",

"dependencies": {
"workbox-core": "^4.0.0-beta.1"
"workbox-core": "^4.0.0-beta.2"
},
"gitHead": "dda07c48e184f57ce5dfe3b3e93af316989a0877"
"gitHead": "a0baa6ac838e1bff9a140ccbe2e78551d9605466"
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc