Socket
Socket
Sign inDemoInstall

workbox-routing

Package Overview
Dependencies
Maintainers
6
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 6.1.5 to 6.2.0-alpha.0

2

_version.js
"use strict";
// @ts-ignore
try {
self['workbox:routing:6.1.5'] && _();
self['workbox:routing:6.2.0-alpha.0'] && _();
}
catch (e) { }

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

try {
self['workbox:routing:6.1.5'] && _();
self['workbox:routing:6.2.0-alpha.0'] && _();
} catch (e) {}

@@ -235,3 +235,3 @@

{
logger_js.logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL matches this denylist pattern: ` + `${regExp}`);
logger_js.logger.log(`The navigation route ${pathnameAndSearch} is not ` + `being used, since the URL matches this denylist pattern: ` + `${regExp.toString()}`);
}

@@ -320,3 +320,3 @@

{
logger_js.logger.debug(`The regular expression '${regExp}' only partially matched ` + `against the cross-origin URL '${url}'. RegExpRoute's will only ` + `handle cross-origin requests if they match the entire URL.`);
logger_js.logger.debug(`The regular expression '${regExp.toString()}' only partially matched ` + `against the cross-origin URL '${url.toString()}'. RegExpRoute's will only ` + `handle cross-origin requests if they match the entire URL.`);
}

@@ -431,6 +431,8 @@

self.addEventListener('message', event => {
// event.data is type 'any'
if (event.data && event.data.type === 'CACHE_URLS') {
// eslint-disable-line
const {
payload
} = event.data;
} = event.data; // eslint-disable-line

@@ -458,3 +460,3 @@ {

if (event.ports && event.ports[0]) {
requestPromises.then(() => event.ports[0].postMessage(true));
void requestPromises.then(() => event.ports[0].postMessage(true));
}

@@ -599,3 +601,5 @@ }

} catch (catchErr) {
err = catchErr;
if (catchErr instanceof Error) {
err = catchErr;
}
}

@@ -653,3 +657,5 @@ }

for (const route of routes) {
let params;
let params; // route.match returns type any, not possible to change right now.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const matchResult = route.match({

@@ -665,3 +671,3 @@ url,

// Warn developers that using an async matchCallback is almost always
// not the right thing to do.
// not the right thing to do.
if (matchResult instanceof Promise) {

@@ -671,2 +677,3 @@ logger_js.logger.warn(`While routing ${getFriendlyURL_js.getFriendlyURL(url)}, an async ` + `matchCallback function was used. Please convert the ` + `following route to use a synchronous matchCallback function:`, route);

} // See https://github.com/GoogleChrome/workbox/issues/2079
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment

@@ -676,6 +683,7 @@

if (Array.isArray(matchResult) && matchResult.length === 0) {
if (Array.isArray(params) && params.length === 0) {
// Instead of passing an empty array in as params, use undefined.
params = undefined;
} else if (matchResult.constructor === Object && Object.keys(matchResult).length === 0) {
} else if (matchResult.constructor === Object && // eslint-disable-line
Object.keys(matchResult).length === 0) {
// Instead of passing an empty object in as params, use undefined.

@@ -891,3 +899,3 @@ params = undefined;

if (url.pathname === captureUrl.pathname && url.origin !== captureUrl.origin) {
logger_js.logger.debug(`${capture} only partially matches the cross-origin URL ` + `${url}. This route will only handle cross-origin requests ` + `if they match the entire URL.`);
logger_js.logger.debug(`${capture} only partially matches the cross-origin URL ` + `${url.toString()}. This route will only handle cross-origin requests ` + `if they match the entire URL.`);
}

@@ -894,0 +902,0 @@ }

@@ -1,2 +0,2 @@

this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self["workbox:routing:6.1.5"]&&_()}catch(t){}const s=t=>t&&"object"==typeof t?t:{handle:t};class r{constructor(t,e,r="GET"){this.handler=s(e),this.match=t,this.method=r}setCatchHandler(t){this.catchHandler=s(t)}}class n extends r{constructor(t,e,s){super((({url:e})=>{const s=t.exec(e.href);if(s&&(e.origin===location.origin||0===s.index))return s.slice(1)}),e,s)}}class i{constructor(){this.ft=new Map,this.dt=new Map}get routes(){return this.ft}addFetchListener(){self.addEventListener("fetch",(t=>{const{request:e}=t,s=this.handleRequest({request:e,event:t});s&&t.respondWith(s)}))}addCacheListener(){self.addEventListener("message",(t=>{if(t.data&&"CACHE_URLS"===t.data.type){const{payload:e}=t.data,s=Promise.all(e.urlsToCache.map((e=>{"string"==typeof e&&(e=[e]);const s=new Request(...e);return this.handleRequest({request:s,event:t})})));t.waitUntil(s),t.ports&&t.ports[0]&&s.then((()=>t.ports[0].postMessage(!0)))}}))}handleRequest({request:t,event:e}){const s=new URL(t.url,location.href);if(!s.protocol.startsWith("http"))return;const r=s.origin===location.origin,{params:n,route:i}=this.findMatchingRoute({event:e,request:t,sameOrigin:r,url:s});let o=i&&i.handler;const u=t.method;if(!o&&this.dt.has(u)&&(o=this.dt.get(u)),!o)return;let c;try{c=o.handle({url:s,request:t,event:e,params:n})}catch(t){c=Promise.reject(t)}const a=i&&i.catchHandler;return c instanceof Promise&&(this.wt||a)&&(c=c.catch((async r=>{if(a)try{return await a.handle({url:s,request:t,event:e,params:n})}catch(t){r=t}if(this.wt)return this.wt.handle({url:s,request:t,event:e});throw r}))),c}findMatchingRoute({url:t,sameOrigin:e,request:s,event:r}){const n=this.ft.get(s.method)||[];for(const i of n){let n;const o=i.match({url:t,sameOrigin:e,request:s,event:r});if(o)return n=o,(Array.isArray(o)&&0===o.length||o.constructor===Object&&0===Object.keys(o).length||"boolean"==typeof o)&&(n=void 0),{route:i,params:n}}return{}}setDefaultHandler(t,e="GET"){this.dt.set(e,s(t))}setCatchHandler(t){this.wt=s(t)}registerRoute(t){this.ft.has(t.method)||this.ft.set(t.method,[]),this.ft.get(t.method).push(t)}unregisterRoute(t){if(!this.ft.has(t.method))throw new e.WorkboxError("unregister-route-but-not-found-with-method",{method:t.method});const s=this.ft.get(t.method).indexOf(t);if(!(s>-1))throw new e.WorkboxError("unregister-route-route-not-registered");this.ft.get(t.method).splice(s,1)}}let o;const u=()=>(o||(o=new i,o.addFetchListener(),o.addCacheListener()),o);return t.NavigationRoute=class extends r{constructor(t,{allowlist:e=[/./],denylist:s=[]}={}){super((t=>this.gt(t)),t),this.qt=e,this.yt=s}gt({url:t,request:e}){if(e&&"navigate"!==e.mode)return!1;const s=t.pathname+t.search;for(const t of this.yt)if(t.test(s))return!1;return!!this.qt.some((t=>t.test(s)))}},t.RegExpRoute=n,t.Route=r,t.Router=i,t.registerRoute=function(t,s,i){let o;if("string"==typeof t){const e=new URL(t,location.href);o=new r((({url:t})=>t.href===e.href),s,i)}else if(t instanceof RegExp)o=new n(t,s,i);else if("function"==typeof t)o=new r(t,s,i);else{if(!(t instanceof r))throw new e.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});o=t}return u().registerRoute(o),o},t.setCatchHandler=function(t){u().setCatchHandler(t)},t.setDefaultHandler=function(t){u().setDefaultHandler(t)},t}({},workbox.core._private);
this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self["workbox:routing:6.2.0-alpha.0"]&&_()}catch(t){}const s=t=>t&&"object"==typeof t?t:{handle:t};class r{constructor(t,e,r="GET"){this.handler=s(e),this.match=t,this.method=r}setCatchHandler(t){this.catchHandler=s(t)}}class n extends r{constructor(t,e,s){super((({url:e})=>{const s=t.exec(e.href);if(s&&(e.origin===location.origin||0===s.index))return s.slice(1)}),e,s)}}class i{constructor(){this.ut=new Map,this.ht=new Map}get routes(){return this.ut}addFetchListener(){self.addEventListener("fetch",(t=>{const{request:e}=t,s=this.handleRequest({request:e,event:t});s&&t.respondWith(s)}))}addCacheListener(){self.addEventListener("message",(t=>{if(t.data&&"CACHE_URLS"===t.data.type){const{payload:e}=t.data,s=Promise.all(e.urlsToCache.map((e=>{"string"==typeof e&&(e=[e]);const s=new Request(...e);return this.handleRequest({request:s,event:t})})));t.waitUntil(s),t.ports&&t.ports[0]&&s.then((()=>t.ports[0].postMessage(!0)))}}))}handleRequest({request:t,event:e}){const s=new URL(t.url,location.href);if(!s.protocol.startsWith("http"))return;const r=s.origin===location.origin,{params:n,route:i}=this.findMatchingRoute({event:e,request:t,sameOrigin:r,url:s});let o=i&&i.handler;const u=t.method;if(!o&&this.ht.has(u)&&(o=this.ht.get(u)),!o)return;let c;try{c=o.handle({url:s,request:t,event:e,params:n})}catch(t){c=Promise.reject(t)}const a=i&&i.catchHandler;return c instanceof Promise&&(this.ft||a)&&(c=c.catch((async r=>{if(a)try{return await a.handle({url:s,request:t,event:e,params:n})}catch(t){t instanceof Error&&(r=t)}if(this.ft)return this.ft.handle({url:s,request:t,event:e});throw r}))),c}findMatchingRoute({url:t,sameOrigin:e,request:s,event:r}){const n=this.ut.get(s.method)||[];for(const i of n){let n;const o=i.match({url:t,sameOrigin:e,request:s,event:r});if(o)return n=o,(Array.isArray(n)&&0===n.length||o.constructor===Object&&0===Object.keys(o).length||"boolean"==typeof o)&&(n=void 0),{route:i,params:n}}return{}}setDefaultHandler(t,e="GET"){this.ht.set(e,s(t))}setCatchHandler(t){this.ft=s(t)}registerRoute(t){this.ut.has(t.method)||this.ut.set(t.method,[]),this.ut.get(t.method).push(t)}unregisterRoute(t){if(!this.ut.has(t.method))throw new e.WorkboxError("unregister-route-but-not-found-with-method",{method:t.method});const s=this.ut.get(t.method).indexOf(t);if(!(s>-1))throw new e.WorkboxError("unregister-route-route-not-registered");this.ut.get(t.method).splice(s,1)}}let o;const u=()=>(o||(o=new i,o.addFetchListener(),o.addCacheListener()),o);return t.NavigationRoute=class extends r{constructor(t,{allowlist:e=[/./],denylist:s=[]}={}){super((t=>this.lt(t)),t),this.dt=e,this.wt=s}lt({url:t,request:e}){if(e&&"navigate"!==e.mode)return!1;const s=t.pathname+t.search;for(const t of this.wt)if(t.test(s))return!1;return!!this.dt.some((t=>t.test(s)))}},t.RegExpRoute=n,t.Route=r,t.Router=i,t.registerRoute=function(t,s,i){let o;if("string"==typeof t){const e=new URL(t,location.href);o=new r((({url:t})=>t.href===e.href),s,i)}else if(t instanceof RegExp)o=new n(t,s,i);else if("function"==typeof t)o=new r(t,s,i);else{if(!(t instanceof r))throw new e.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});o=t}return u().registerRoute(o),o},t.setCatchHandler=function(t){u().setCatchHandler(t)},t.setDefaultHandler=function(t){u().setDefaultHandler(t)},t}({},workbox.core._private);
//# sourceMappingURL=workbox-routing.prod.js.map

@@ -86,3 +86,3 @@ /*

`being used, since the URL matches this denylist pattern: ` +
`${regExp}`);
`${regExp.toString()}`);
}

@@ -89,0 +89,0 @@ return false;

{
"name": "workbox-routing",
"version": "6.1.5",
"version": "6.2.0-alpha.0",
"license": "MIT",

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

"dependencies": {
"workbox-core": "^6.1.5"
"workbox-core": "^6.2.0-alpha.0"
},
"gitHead": "d559fc8b3240f723fd9721f3976797dcedf7112b"
"gitHead": "46af63c1780955345c117c63c8c8dd54f3d40220"
}

@@ -60,4 +60,4 @@ /*

if (process.env.NODE_ENV !== 'production') {
logger.debug(`The regular expression '${regExp}' only partially matched ` +
`against the cross-origin URL '${url}'. RegExpRoute's will only ` +
logger.debug(`The regular expression '${regExp.toString()}' only partially matched ` +
`against the cross-origin URL '${url.toString()}'. RegExpRoute's will only ` +
`handle cross-origin requests if they match the entire URL.`);

@@ -64,0 +64,0 @@ }

@@ -62,3 +62,3 @@ /*

logger.debug(`${capture} only partially matches the cross-origin URL ` +
`${url}. This route will only handle cross-origin requests ` +
`${url.toString()}. This route will only handle cross-origin requests ` +
`if they match the entire URL.`);

@@ -65,0 +65,0 @@ }

@@ -87,4 +87,5 @@ /*

self.addEventListener('message', ((event) => {
if (event.data && event.data.type === 'CACHE_URLS') {
const { payload } = event.data;
// event.data is type 'any'
if (event.data && event.data.type === 'CACHE_URLS') { // eslint-disable-line
const { payload } = event.data; // eslint-disable-line
if (process.env.NODE_ENV !== 'production') {

@@ -106,3 +107,3 @@ logger.debug(`Caching URLs from the window`, payload.urlsToCache);

if (event.ports && event.ports[0]) {
requestPromises.then(() => event.ports[0].postMessage(true));
void requestPromises.then(() => event.ports[0].postMessage(true));
}

@@ -221,3 +222,5 @@ }

catch (catchErr) {
err = catchErr;
if (catchErr instanceof Error) {
err = catchErr;
}
}

@@ -261,2 +264,4 @@ }

let params;
// route.match returns type any, not possible to change right now.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const matchResult = route.match({ url, sameOrigin, request, event });

@@ -266,3 +271,3 @@ if (matchResult) {

// Warn developers that using an async matchCallback is almost always
// not the right thing to do.
// not the right thing to do.
if (matchResult instanceof Promise) {

@@ -275,8 +280,9 @@ logger.warn(`While routing ${getFriendlyURL(url)}, an async ` +

// See https://github.com/GoogleChrome/workbox/issues/2079
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
params = matchResult;
if (Array.isArray(matchResult) && matchResult.length === 0) {
if (Array.isArray(params) && params.length === 0) {
// Instead of passing an empty array in as params, use undefined.
params = undefined;
}
else if ((matchResult.constructor === Object &&
else if ((matchResult.constructor === Object && // eslint-disable-line
Object.keys(matchResult).length === 0)) {

@@ -283,0 +289,0 @@ // Instead of passing an empty object in as params, use undefined.

// @ts-ignore
try{self['workbox:routing:6.1.5']&&_()}catch(e){}
try{self['workbox:routing:6.2.0-alpha.0']&&_()}catch(e){}

@@ -105,3 +105,3 @@ /*

`being used, since the URL matches this denylist pattern: ` +
`${regExp}`);
`${regExp.toString()}`);
}

@@ -108,0 +108,0 @@ return false;

@@ -72,4 +72,4 @@ /*

logger.debug(
`The regular expression '${regExp}' only partially matched ` +
`against the cross-origin URL '${url}'. RegExpRoute's will only ` +
`The regular expression '${regExp.toString()}' only partially matched ` +
`against the cross-origin URL '${url.toString()}'. RegExpRoute's will only ` +
`handle cross-origin requests if they match the entire URL.`

@@ -76,0 +76,0 @@ );

@@ -80,3 +80,3 @@ /*

`${capture} only partially matches the cross-origin URL ` +
`${url}. This route will only handle cross-origin requests ` +
`${url.toString()}. This route will only handle cross-origin requests ` +
`if they match the entire URL.`);

@@ -83,0 +83,0 @@ }

@@ -68,7 +68,7 @@ /*

/**
*
*
* @param {module:workbox-routing-handlerCallback} handler A callback
* function that returns a Promise resolving to a Response
*/
setCatchHandler(handler: RouteHandler) {
setCatchHandler(handler: RouteHandler): void {
this.catchHandler = normalizeHandler(handler)

@@ -75,0 +75,0 @@ }

@@ -69,3 +69,3 @@ /*

*/
get routes() {
get routes(): Map<HTTPMethod, Route[]> {
return this._routes;

@@ -78,3 +78,3 @@ }

*/
addFetchListener() {
addFetchListener(): void {
// See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705

@@ -112,7 +112,8 @@ self.addEventListener('fetch', ((event: FetchEvent) => {

*/
addCacheListener() {
addCacheListener(): void {
// See https://github.com/Microsoft/TypeScript/issues/28357#issuecomment-436484705
self.addEventListener('message', ((event: ExtendableMessageEvent) => {
if (event.data && event.data.type === 'CACHE_URLS') {
const {payload}: CacheURLsMessageData = event.data;
// event.data is type 'any'
if (event.data && event.data.type === 'CACHE_URLS') { // eslint-disable-line
const {payload}: CacheURLsMessageData = event.data; // eslint-disable-line

@@ -141,3 +142,3 @@ if (process.env.NODE_ENV !== 'production') {

if (event.ports && event.ports[0]) {
requestPromises.then(() => event.ports[0].postMessage(true));
void requestPromises.then(() => event.ports[0].postMessage(true));
}

@@ -271,3 +272,5 @@ }

} catch (catchErr) {
err = catchErr;
if (catchErr instanceof Error) {
err = catchErr;
}
}

@@ -286,3 +289,2 @@ }

}
return this._catchHandler.handle({url, request, event});

@@ -318,3 +320,5 @@ }

for (const route of routes) {
let params;
let params: Promise<any> | undefined;
// route.match returns type any, not possible to change right now.
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const matchResult = route.match({url, sameOrigin, request, event});

@@ -324,3 +328,3 @@ if (matchResult) {

// Warn developers that using an async matchCallback is almost always
// not the right thing to do.
// not the right thing to do.
if (matchResult instanceof Promise) {

@@ -335,7 +339,8 @@ logger.warn(`While routing ${getFriendlyURL(url)}, an async ` +

// See https://github.com/GoogleChrome/workbox/issues/2079
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
params = matchResult;
if (Array.isArray(matchResult) && matchResult.length === 0) {
if (Array.isArray(params) && params.length === 0) {
// Instead of passing an empty array in as params, use undefined.
params = undefined;
} else if ((matchResult.constructor === Object &&
} else if ((matchResult.constructor === Object && // eslint-disable-line
Object.keys(matchResult).length === 0)) {

@@ -373,3 +378,3 @@ // Instead of passing an empty object in as params, use undefined.

*/
setDefaultHandler(handler: RouteHandler, method: HTTPMethod = defaultMethod) {
setDefaultHandler(handler: RouteHandler, method: HTTPMethod = defaultMethod): void {
this._defaultHandlerMap.set(method, normalizeHandler(handler));

@@ -385,3 +390,3 @@ }

*/
setCatchHandler(handler: RouteHandler) {
setCatchHandler(handler: RouteHandler): void {
this._catchHandler = normalizeHandler(handler);

@@ -395,3 +400,3 @@ }

*/
registerRoute(route: Route) {
registerRoute(route: Route): void {
if (process.env.NODE_ENV !== 'production') {

@@ -448,3 +453,3 @@ assert!.isType(route, 'object', {

*/
unregisterRoute(route: Route) {
unregisterRoute(route: Route): void {
if (!this._routes.has(route.method)) {

@@ -451,0 +456,0 @@ throw new WorkboxError(

@@ -24,3 +24,3 @@ /*

*/
function setCatchHandler(handler: RouteHandler) {
function setCatchHandler(handler: RouteHandler): void {
const defaultRouter = getOrCreateDefaultRouter();

@@ -27,0 +27,0 @@ defaultRouter.setCatchHandler(handler);

@@ -28,3 +28,3 @@ /*

*/
function setDefaultHandler(handler: RouteHandler) {
function setDefaultHandler(handler: RouteHandler): void {
const defaultRouter = getOrCreateDefaultRouter();

@@ -31,0 +31,0 @@ defaultRouter.setDefaultHandler(handler);

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