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.3.0 to 6.4.0

2

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

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

try {
self['workbox:routing:6.2.4'] && _();
self['workbox:routing:6.3.0'] && _();
} catch (e) {}

@@ -430,7 +430,8 @@

// event.data is type 'any'
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (event.data && event.data.type === 'CACHE_URLS') {
// eslint-disable-line
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const {
payload
} = event.data; // eslint-disable-line
} = event.data;

@@ -437,0 +438,0 @@ {

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

this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self["workbox:routing:6.2.4"]&&_()}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.ft=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.ft.has(u)&&(o=this.ft.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.lt||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.lt)return this.lt.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.ft.set(e,s(t))}setCatchHandler(t){this.lt=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.dt(t)),t),this.wt=e,this.gt=s}dt({url:t,request:e}){if(e&&"navigate"!==e.mode)return!1;const s=t.pathname+t.search;for(const t of this.gt)if(t.test(s))return!1;return!!this.wt.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.3.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.ft=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.ft.has(u)&&(o=this.ft.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.lt||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.lt)return this.lt.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.ft.set(e,s(t))}setCatchHandler(t){this.lt=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.dt(t)),t),this.wt=e,this.gt=s}dt({url:t,request:e}){if(e&&"navigate"!==e.mode)return!1;const s=t.pathname+t.search;for(const t of this.gt)if(t.test(s))return!1;return!!this.wt.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

@@ -93,4 +93,3 @@ /*

if (process.env.NODE_ENV !== 'production') {
logger.debug(`The navigation route ${pathnameAndSearch} ` +
`is being used.`);
logger.debug(`The navigation route ${pathnameAndSearch} ` + `is being used.`);
}

@@ -97,0 +96,0 @@ return true;

{
"name": "workbox-routing",
"version": "6.3.0",
"version": "6.4.0",
"license": "MIT",

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

"dependencies": {
"workbox-core": "6.3.0"
"workbox-core": "6.4.0"
},
"gitHead": "03055e64014a46f6cc977a3a50ad814c6409d36a"
"gitHead": "cdad230c678a3626c217615d5792eb0f1c77194c"
}

@@ -58,3 +58,3 @@ /*

// behind this behavior.
if ((url.origin !== location.origin) && (result.index !== 0)) {
if (url.origin !== location.origin && result.index !== 0) {
if (process.env.NODE_ENV !== 'production') {

@@ -61,0 +61,0 @@ logger.debug(`The regular expression '${regExp.toString()}' only partially matched ` +

@@ -47,7 +47,8 @@ /*

// TODO: Remove this log message in v4.
const valueToCheck = capture.startsWith('http') ?
captureUrl.pathname : capture;
const valueToCheck = capture.startsWith('http')
? captureUrl.pathname
: capture;
// See https://github.com/pillarjs/path-to-regexp#parameters
const wildcards = '[*:?+]';
if ((new RegExp(`${wildcards}`)).exec(valueToCheck)) {
if (new RegExp(`${wildcards}`).exec(valueToCheck)) {
logger.debug(`The '$capture' parameter contains an Express-style wildcard ` +

@@ -60,4 +61,4 @@ `character (${wildcards}). Strings are now always interpreted as ` +

if (process.env.NODE_ENV !== 'production') {
if ((url.pathname === captureUrl.pathname) &&
(url.origin !== captureUrl.origin)) {
if (url.pathname === captureUrl.pathname &&
url.origin !== captureUrl.origin) {
logger.debug(`${capture} only partially matches the cross-origin URL ` +

@@ -64,0 +65,0 @@ `${url.toString()}. This route will only handle cross-origin requests ` +

@@ -76,3 +76,3 @@ import { RouteHandler, RouteHandlerCallbackOptions, RouteMatchCallbackOptions } from 'workbox-core/types.js';

*/
handleRequest({ request, event }: {
handleRequest({ request, event, }: {
request: Request;

@@ -96,3 +96,3 @@ event: ExtendableEvent;

*/
findMatchingRoute({ url, sameOrigin, request, event }: RouteMatchCallbackOptions): {
findMatchingRoute({ url, sameOrigin, request, event, }: RouteMatchCallbackOptions): {
route?: Route;

@@ -99,0 +99,0 @@ params?: RouteHandlerCallbackOptions['params'];

@@ -88,4 +88,6 @@ /*

// event.data is type 'any'
if (event.data && event.data.type === 'CACHE_URLS') { // eslint-disable-line
const { payload } = event.data; // eslint-disable-line
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (event.data && event.data.type === 'CACHE_URLS') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { payload } = event.data;
if (process.env.NODE_ENV !== 'production') {

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

*/
handleRequest({ request, event }) {
handleRequest({ request, event, }) {
if (process.env.NODE_ENV !== 'production') {

@@ -152,8 +154,7 @@ assert.isInstance(request, Request, {

if (handler) {
debugMessages.push([
`Found a route to handle this request:`, route,
]);
debugMessages.push([`Found a route to handle this request:`, route]);
if (params) {
debugMessages.push([
`Passing the following params to the route's handler:`, params,
`Passing the following params to the route's handler:`,
params,
]);

@@ -206,3 +207,4 @@ }

const catchHandler = route && route.catchHandler;
if (responsePromise instanceof Promise && (this._catchHandler || catchHandler)) {
if (responsePromise instanceof Promise &&
(this._catchHandler || catchHandler)) {
responsePromise = responsePromise.catch(async (err) => {

@@ -261,3 +263,3 @@ // If there's a route catch handler, process that first

*/
findMatchingRoute({ url, sameOrigin, request, event }) {
findMatchingRoute({ url, sameOrigin, request, event, }) {
const routes = this._routes.get(request.method) || [];

@@ -286,4 +288,4 @@ for (const route of routes) {

}
else if ((matchResult.constructor === Object && // eslint-disable-line
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.

@@ -290,0 +292,0 @@ params = undefined;

// @ts-ignore
try{self['workbox:routing:6.3.0']&&_()}catch(e){}
try{self['workbox:routing:6.4.0']&&_()}catch(e){}

@@ -19,3 +19,2 @@ /*

/**

@@ -22,0 +21,0 @@ * @module workbox-routing

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

*/
constructor(handler: RouteHandler,
{allowlist = [/./], denylist = []}: NavigationRouteMatchOptions = {}) {
constructor(
handler: RouteHandler,
{allowlist = [/./], denylist = []}: NavigationRouteMatchOptions = {},
) {
if (process.env.NODE_ENV !== 'production') {

@@ -78,3 +80,6 @@ assert!.isArrayOfClass(allowlist, RegExp, {

super((options: RouteMatchCallbackOptions) => this._match(options), handler);
super(
(options: RouteMatchCallbackOptions) => this._match(options),
handler,
);

@@ -105,5 +110,7 @@ this._allowlist = allowlist;

if (process.env.NODE_ENV !== 'production') {
logger.log(`The navigation route ${pathnameAndSearch} is not ` +
logger.log(
`The navigation route ${pathnameAndSearch} is not ` +
`being used, since the URL matches this denylist pattern: ` +
`${regExp.toString()}`);
`${regExp.toString()}`,
);
}

@@ -116,4 +123,5 @@ return false;

if (process.env.NODE_ENV !== 'production') {
logger.debug(`The navigation route ${pathnameAndSearch} ` +
`is being used.`);
logger.debug(
`The navigation route ${pathnameAndSearch} ` + `is being used.`,
);
}

@@ -124,5 +132,7 @@ return true;

if (process.env.NODE_ENV !== 'production') {
logger.log(`The navigation route ${pathnameAndSearch} is not ` +
logger.log(
`The navigation route ${pathnameAndSearch} is not ` +
`being used, since the URL being navigated to doesn't ` +
`match the allowlist.`);
`match the allowlist.`,
);
}

@@ -129,0 +139,0 @@ return false;

@@ -11,4 +11,7 @@ /*

import {logger} from 'workbox-core/_private/logger.js';
import {RouteHandler, RouteMatchCallback, RouteMatchCallbackOptions}
from 'workbox-core/types.js';
import {
RouteHandler,
RouteMatchCallback,
RouteMatchCallbackOptions,
} from 'workbox-core/types.js';

@@ -20,3 +23,2 @@ import {HTTPMethod} from './utils/constants.js';

/**

@@ -71,8 +73,8 @@ * RegExpRoute makes it easy to create a regular expression based

// behind this behavior.
if ((url.origin !== location.origin) && (result.index !== 0)) {
if (url.origin !== location.origin && result.index !== 0) {
if (process.env.NODE_ENV !== 'production') {
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.`
`against the cross-origin URL '${url.toString()}'. RegExpRoute's will only ` +
`handle cross-origin requests if they match the entire URL.`,
);

@@ -79,0 +81,0 @@ }

@@ -20,3 +20,2 @@ /*

/**

@@ -42,5 +41,6 @@ * Easily register a RegExp, string, or function with a caching

function registerRoute(
capture: RegExp | string | RouteMatchCallback | Route,
handler?: RouteHandler,
method?: HTTPMethod): Route {
capture: RegExp | string | RouteMatchCallback | Route,
handler?: RouteHandler,
method?: HTTPMethod,
): Route {
let route;

@@ -62,12 +62,13 @@

// TODO: Remove this log message in v4.
const valueToCheck = capture.startsWith('http') ?
captureUrl.pathname : capture;
const valueToCheck = capture.startsWith('http')
? captureUrl.pathname
: capture;
// See https://github.com/pillarjs/path-to-regexp#parameters
const wildcards = '[*:?+]';
if ((new RegExp(`${wildcards}`)).exec(valueToCheck)) {
if (new RegExp(`${wildcards}`).exec(valueToCheck)) {
logger.debug(
`The '$capture' parameter contains an Express-style wildcard ` +
`character (${wildcards}). Strings are now always interpreted as ` +
`exact matches; use a RegExp for partial or wildcard matches.`
`The '$capture' parameter contains an Express-style wildcard ` +
`character (${wildcards}). Strings are now always interpreted as ` +
`exact matches; use a RegExp for partial or wildcard matches.`,
);

@@ -79,8 +80,11 @@ }

if (process.env.NODE_ENV !== 'production') {
if ((url.pathname === captureUrl.pathname) &&
(url.origin !== captureUrl.origin)) {
if (
url.pathname === captureUrl.pathname &&
url.origin !== captureUrl.origin
) {
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.`);
`${capture} only partially matches the cross-origin URL ` +
`${url.toString()}. This route will only handle cross-origin requests ` +
`if they match the entire URL.`,
);
}

@@ -87,0 +91,0 @@ }

@@ -12,7 +12,9 @@ /*

import {normalizeHandler} from './utils/normalizeHandler.js';
import {RouteHandler, RouteHandlerObject, RouteMatchCallback}
from 'workbox-core/types.js';
import {
RouteHandler,
RouteHandlerObject,
RouteMatchCallback,
} from 'workbox-core/types.js';
import './_version.js';
/**

@@ -45,5 +47,6 @@ * A `Route` consists of a pair of callback functions, "match" and "handler".

constructor(
match: RouteMatchCallback,
handler: RouteHandler,
method: HTTPMethod = defaultMethod) {
match: RouteMatchCallback,
handler: RouteHandler,
method: HTTPMethod = defaultMethod,
) {
if (process.env.NODE_ENV !== 'production') {

@@ -75,3 +78,3 @@ assert!.isType(match, 'function', {

setCatchHandler(handler: RouteHandler): void {
this.catchHandler = normalizeHandler(handler)
this.catchHandler = normalizeHandler(handler);
}

@@ -78,0 +81,0 @@ }

@@ -114,4 +114,6 @@ /*

// event.data is type 'any'
if (event.data && event.data.type === 'CACHE_URLS') { // eslint-disable-line
const {payload}: CacheURLsMessageData = event.data; // eslint-disable-line
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (event.data && event.data.type === 'CACHE_URLS') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const {payload}: CacheURLsMessageData = event.data;

@@ -122,15 +124,16 @@ if (process.env.NODE_ENV !== 'production') {

const requestPromises = Promise.all(payload.urlsToCache.map(
(entry: string | [string, RequestInit?]) => {
if (typeof entry === 'string') {
entry = [entry];
}
const requestPromises = Promise.all(
payload.urlsToCache.map((entry: string | [string, RequestInit?]) => {
if (typeof entry === 'string') {
entry = [entry];
}
const request = new Request(...entry);
return this.handleRequest({request, event});
const request = new Request(...entry);
return this.handleRequest({request, event});
// TODO(philipwalton): TypeScript errors without this typecast for
// some reason (probably a bug). The real type here should work but
// doesn't: `Array<Promise<Response> | undefined>`.
}) as any[]); // TypeScript
// TODO(philipwalton): TypeScript errors without this typecast for
// some reason (probably a bug). The real type here should work but
// doesn't: `Array<Promise<Response> | undefined>`.
}) as any[],
); // TypeScript

@@ -159,3 +162,6 @@ event.waitUntil(requestPromises);

*/
handleRequest({request, event}: {
handleRequest({
request,
event,
}: {
request: Request;

@@ -177,3 +183,4 @@ event: ExtendableEvent;

logger.debug(
`Workbox Router only supports URLs that start with 'http'.`);
`Workbox Router only supports URLs that start with 'http'.`,
);
}

@@ -195,9 +202,8 @@ return;

if (handler) {
debugMessages.push([
`Found a route to handle this request:`, route,
]);
debugMessages.push([`Found a route to handle this request:`, route]);
if (params) {
debugMessages.push([
`Passing the following params to the route's handler:`, params,
`Passing the following params to the route's handler:`,
params,
]);

@@ -213,4 +219,6 @@ }

if (process.env.NODE_ENV !== 'production') {
debugMessages.push(`Failed to find a matching route. Falling ` +
`back to the default handler for ${method}.`);
debugMessages.push(
`Failed to find a matching route. Falling ` +
`back to the default handler for ${method}.`,
);
}

@@ -257,3 +265,6 @@ handler = this._defaultHandlerMap.get(method);

if (responsePromise instanceof Promise && (this._catchHandler || catchHandler)) {
if (
responsePromise instanceof Promise &&
(this._catchHandler || catchHandler)
) {
responsePromise = responsePromise.catch(async (err) => {

@@ -265,4 +276,8 @@ // If there's a route catch handler, process that first

// and may not make sense without the URL
logger.groupCollapsed(`Error thrown when responding to: ` +
` ${getFriendlyURL(url)}. Falling back to route's Catch Handler.`);
logger.groupCollapsed(
`Error thrown when responding to: ` +
` ${getFriendlyURL(
url,
)}. Falling back to route's Catch Handler.`,
);
logger.error(`Error thrown by:`, route);

@@ -286,4 +301,8 @@ logger.error(err);

// and may not make sense without the URL
logger.groupCollapsed(`Error thrown when responding to: ` +
` ${getFriendlyURL(url)}. Falling back to global Catch Handler.`);
logger.groupCollapsed(
`Error thrown when responding to: ` +
` ${getFriendlyURL(
url,
)}. Falling back to global Catch Handler.`,
);
logger.error(`Error thrown by:`, route);

@@ -318,5 +337,11 @@ logger.error(err);

*/
findMatchingRoute(
{url, sameOrigin, request, event}: RouteMatchCallbackOptions):
{route?: Route; params?: RouteHandlerCallbackOptions['params']} {
findMatchingRoute({
url,
sameOrigin,
request,
event,
}: RouteMatchCallbackOptions): {
route?: Route;
params?: RouteHandlerCallbackOptions['params'];
} {
const routes = this._routes.get(request.method as HTTPMethod) || [];

@@ -333,6 +358,8 @@ for (const route of routes) {

if (matchResult instanceof Promise) {
logger.warn(`While routing ${getFriendlyURL(url)}, an async ` +
logger.warn(
`While routing ${getFriendlyURL(url)}, an async ` +
`matchCallback function was used. Please convert the ` +
`following route to use a synchronous matchCallback function:`,
route);
route,
);
}

@@ -347,4 +374,6 @@ }

params = undefined;
} else if ((matchResult.constructor === Object && // eslint-disable-line
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.

@@ -381,3 +410,6 @@ params = undefined;

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

@@ -456,7 +488,5 @@ }

if (!this._routes.has(route.method)) {
throw new WorkboxError(
'unregister-route-but-not-found-with-method', {
method: route.method,
}
);
throw new WorkboxError('unregister-route-but-not-found-with-method', {
method: route.method,
});
}

@@ -463,0 +493,0 @@

@@ -15,3 +15,2 @@ /*

/**

@@ -18,0 +17,0 @@ * Define a default `handler` that's called when no routes explicitly

@@ -11,3 +11,2 @@ /*

export type HTTPMethod = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT';

@@ -14,0 +13,0 @@

@@ -14,3 +14,2 @@ /*

/**

@@ -23,5 +22,3 @@ * @param {function()|Object} handler Either a function, or an object with a

*/
export const normalizeHandler = (
handler: RouteHandler
): RouteHandlerObject => {
export const normalizeHandler = (handler: RouteHandler): RouteHandlerObject => {
if (handler && typeof handler === 'object') {

@@ -28,0 +25,0 @@ if (process.env.NODE_ENV !== 'production') {

@@ -8,8 +8,4 @@ {

},
"include": [
"src/**/*.ts"
],
"references": [
{ "path": "../workbox-core/" }
]
"include": ["src/**/*.ts"],
"references": [{"path": "../workbox-core/"}]
}

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