Socket
Socket
Sign inDemoInstall

workbox-routing

Package Overview
Dependencies
1
Maintainers
4
Versions
95
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 5.0.0-alpha.2 to 5.0.0-beta.0

4

_types.d.ts

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

import { RouteHandler, RouteHandlerCallback, RouteHandlerCallbackOptions, RouteMatchCallback, RouteMatchCallbackOptions } from 'workbox-core/types.js';
import { RouteHandler, RouteHandlerObject, RouteHandlerCallback, RouteHandlerCallbackOptions, RouteMatchCallback, RouteMatchCallbackOptions } from 'workbox-core/types.js';
import './_version.js';

@@ -50,2 +50,2 @@ /**

*/
export { RouteHandler as Handler, RouteHandlerCallback as HandlerCallback, RouteHandlerCallbackOptions as HandlerCallbackOptions, RouteMatchCallback as MatchCallback, RouteMatchCallbackOptions as MatchCallbackOptions, };
export { RouteHandler as Handler, RouteHandlerObject as HandlerObject, RouteHandlerCallback as HandlerCallback, RouteHandlerCallbackOptions as HandlerCallbackOptions, RouteMatchCallback as MatchCallback, RouteMatchCallbackOptions as MatchCallbackOptions, };
// @ts-ignore
try {
self['workbox:routing:5.0.0-alpha.2'] && _();
self['workbox:routing:5.0.0-beta.0'] && _();
}
catch (e) { }

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

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

@@ -10,0 +10,0 @@

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

this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self["workbox:routing:5.0.0-alpha.2"]&&_()}catch(t){}const s="GET",r=t=>t&&"object"==typeof t?t:{handle:t};class n{constructor(t,e,n=s){this.handler=r(e),this.match=t,this.method=n}}class o extends n{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.t=new Map}get routes(){return this.t}addFetchListener(){self.addEventListener("fetch",t=>{const{request:e}=t,s=this.handleRequest({request:e,event:t});s&&t.respondWith(s)})}addCacheListener(){self.addEventListener("message",async t=>{if(t.data&&"CACHE_URLS"===t.data.type){const{payload:e}=t.data,s=Promise.all(e.urlsToCache.map(t=>{"string"==typeof t&&(t=[t]);const e=new Request(...t);return this.handleRequest({request:e})}));t.waitUntil(s),t.ports&&t.ports[0]&&(await s,t.ports[0].postMessage(!0))}})}handleRequest({request:t,event:e}){const s=new URL(t.url,location.href);if(!s.protocol.startsWith("http"))return;let r,{params:n,route:o}=this.findMatchingRoute({url:s,request:t,event:e}),i=o&&o.handler;if(!i&&this.s&&(i=this.s),i){try{r=i.handle({url:s,request:t,event:e,params:n})}catch(t){r=Promise.reject(t)}return r&&this.o&&(r=r.catch(r=>this.o.handle({url:s,request:t,event:e}))),r}}findMatchingRoute({url:t,request:e,event:s}){const r=this.t.get(e.method)||[];for(const n of r){let r,o=n.match({url:t,request:e,event:s});if(o)return r=o,Array.isArray(o)&&0===o.length?r=void 0:o.constructor===Object&&0===Object.keys(o).length?r=void 0:"boolean"==typeof o&&(r=void 0),{route:n,params:r}}return{}}setDefaultHandler(t){this.s=r(t)}setCatchHandler(t){this.o=r(t)}registerRoute(t){this.t.has(t.method)||this.t.set(t.method,[]),this.t.get(t.method).push(t)}unregisterRoute(t){if(!this.t.has(t.method))throw new e.WorkboxError("unregister-route-but-not-found-with-method",{method:t.method});const s=this.t.get(t.method).indexOf(t);if(!(s>-1))throw new e.WorkboxError("unregister-route-route-not-registered");this.t.get(t.method).splice(s,1)}}let u;const c=()=>(u||((u=new i).addFetchListener(),u.addCacheListener()),u);return t.NavigationRoute=class extends n{constructor(t,{whitelist:e=[/./],blacklist:s=[]}={}){super(t=>this.i(t),t),this.u=e,this.h=s}i({url:t,request:e}){if(e&&"navigate"!==e.mode)return!1;const s=t.pathname+t.search;for(const t of this.h)if(t.test(s))return!1;return!!this.u.some(t=>t.test(s))}},t.RegExpRoute=o,t.Route=n,t.Router=i,t.registerRoute=((t,s,r)=>{let i;if("string"==typeof t){const e=new URL(t,location.href);i=new n(({url:t})=>t.href===e.href,s,r)}else if(t instanceof RegExp)i=new o(t,s,r);else if("function"==typeof t)i=new n(t,s,r);else{if(!(t instanceof n))throw new e.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});i=t}return c().registerRoute(i),i}),t.setCatchHandler=(t=>{c().setCatchHandler(t)}),t.setDefaultHandler=(t=>{c().setDefaultHandler(t)}),t}({},workbox.core._private);
this.workbox=this.workbox||{},this.workbox.routing=function(t,e){"use strict";try{self["workbox:routing:5.0.0-beta.0"]&&_()}catch(t){}const s="GET",r=t=>t&&"object"==typeof t?t:{handle:t};class n{constructor(t,e,n=s){this.handler=r(e),this.match=t,this.method=n}}class o extends n{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.t=new Map}get routes(){return this.t}addFetchListener(){self.addEventListener("fetch",t=>{const{request:e}=t,s=this.handleRequest({request:e,event:t});s&&t.respondWith(s)})}addCacheListener(){self.addEventListener("message",async t=>{if(t.data&&"CACHE_URLS"===t.data.type){const{payload:e}=t.data,s=Promise.all(e.urlsToCache.map(t=>{"string"==typeof t&&(t=[t]);const e=new Request(...t);return this.handleRequest({request:e})}));t.waitUntil(s),t.ports&&t.ports[0]&&(await s,t.ports[0].postMessage(!0))}})}handleRequest({request:t,event:e}){const s=new URL(t.url,location.href);if(!s.protocol.startsWith("http"))return;let r,{params:n,route:o}=this.findMatchingRoute({url:s,request:t,event:e}),i=o&&o.handler;if(!i&&this.s&&(i=this.s),i){try{r=i.handle({url:s,request:t,event:e,params:n})}catch(t){r=Promise.reject(t)}return r&&this.o&&(r=r.catch(r=>this.o.handle({url:s,request:t,event:e}))),r}}findMatchingRoute({url:t,request:e,event:s}){const r=this.t.get(e.method)||[];for(const n of r){let r,o=n.match({url:t,request:e,event:s});if(o)return r=o,Array.isArray(o)&&0===o.length?r=void 0:o.constructor===Object&&0===Object.keys(o).length?r=void 0:"boolean"==typeof o&&(r=void 0),{route:n,params:r}}return{}}setDefaultHandler(t){this.s=r(t)}setCatchHandler(t){this.o=r(t)}registerRoute(t){this.t.has(t.method)||this.t.set(t.method,[]),this.t.get(t.method).push(t)}unregisterRoute(t){if(!this.t.has(t.method))throw new e.WorkboxError("unregister-route-but-not-found-with-method",{method:t.method});const s=this.t.get(t.method).indexOf(t);if(!(s>-1))throw new e.WorkboxError("unregister-route-route-not-registered");this.t.get(t.method).splice(s,1)}}let u;const c=()=>(u||((u=new i).addFetchListener(),u.addCacheListener()),u);return t.NavigationRoute=class extends n{constructor(t,{whitelist:e=[/./],blacklist:s=[]}={}){super(t=>this.i(t),t),this.u=e,this.h=s}i({url:t,request:e}){if(e&&"navigate"!==e.mode)return!1;const s=t.pathname+t.search;for(const t of this.h)if(t.test(s))return!1;return!!this.u.some(t=>t.test(s))}},t.RegExpRoute=o,t.Route=n,t.Router=i,t.registerRoute=((t,s,r)=>{let i;if("string"==typeof t){const e=new URL(t,location.href);i=new n(({url:t})=>t.href===e.href,s,r)}else if(t instanceof RegExp)i=new o(t,s,r);else if("function"==typeof t)i=new n(t,s,r);else{if(!(t instanceof n))throw new e.WorkboxError("unsupported-route-type",{moduleName:"workbox-routing",funcName:"registerRoute",paramName:"capture"});i=t}return c().registerRoute(i),i}),t.setCatchHandler=(t=>{c().setCatchHandler(t)}),t.setDefaultHandler=(t=>{c().setDefaultHandler(t)}),t}({},workbox.core._private);
//# sourceMappingURL=workbox-routing.prod.js.map
import { Route } from './Route.js';
import { HandlerCallback } from './_types.js';
import { Handler } from './_types.js';
import './_version.js';

@@ -45,3 +45,3 @@ export interface NavigationRouteMatchOptions {

*/
constructor(handler: HandlerCallback, { whitelist, blacklist }?: NavigationRouteMatchOptions);
constructor(handler: Handler, { whitelist, blacklist }?: NavigationRouteMatchOptions);
/**

@@ -48,0 +48,0 @@ * Routes match handler.

{
"name": "workbox-routing",
"version": "5.0.0-alpha.2",
"version": "5.0.0-beta.0",
"license": "MIT",

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

"dependencies": {
"workbox-core": "^5.0.0-alpha.2"
"workbox-core": "^5.0.0-beta.0"
},
"gitHead": "0cb0029b692c3802545238fe59b6d6179ca32f6c"
"gitHead": "136b38f2c701bd7c04e808d19961310a9ede524b"
}
import { HTTPMethod } from './utils/constants.js';
import { Route } from './Route.js';
import { HandlerCallback } from './_types.js';
import { Handler } from './_types.js';
import './_version.js';

@@ -32,4 +32,4 @@ /**

*/
constructor(regExp: RegExp, handler: HandlerCallback, method?: HTTPMethod);
constructor(regExp: RegExp, handler: Handler, method?: HTTPMethod);
}
export { RegExpRoute };
import { Route } from './Route.js';
import { MatchCallback, HandlerCallback } from './_types.js';
import { MatchCallback } from './_types.js';
import './_version.js';

@@ -29,2 +29,2 @@ /**

*/
export declare const registerRoute: (capture: string | RegExp | MatchCallback | Route, handler?: HandlerCallback | undefined, method?: "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | undefined) => Route;
export declare const registerRoute: (capture: string | RegExp | MatchCallback | Route, handler?: import("workbox-core/types").RouteHandlerCallback | import("workbox-core/types").RouteHandlerObject | undefined, method?: "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT" | undefined) => Route;
import { HTTPMethod } from './utils/constants.js';
import { Handler, HandlerCallback, MatchCallback } from './_types.js';
import { Handler, HandlerObject, MatchCallback } from './_types.js';
import './_version.js';

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

declare class Route {
handler: Handler;
handler: HandlerObject;
match: MatchCallback;

@@ -29,4 +29,4 @@ method: HTTPMethod;

*/
constructor(match: MatchCallback, handler: HandlerCallback | Handler, method?: HTTPMethod);
constructor(match: MatchCallback, handler: Handler, method?: HTTPMethod);
}
export { Route };
import { Route } from './Route.js';
import { HTTPMethod } from './utils/constants.js';
import { HandlerCallback, HandlerCallbackOptions } from './_types.js';
import { Handler, HandlerCallbackOptions } from './_types.js';
import './_version.js';

@@ -112,3 +112,3 @@ /**

*/
setDefaultHandler(handler: HandlerCallback): void;
setDefaultHandler(handler: Handler): void;
/**

@@ -121,3 +121,3 @@ * If a Route throws an error while handling a request, this `handler`

*/
setCatchHandler(handler: HandlerCallback): void;
setCatchHandler(handler: Handler): void;
/**

@@ -124,0 +124,0 @@ * Registers a route with the router.

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

import { HandlerCallback } from './_types.js';
import { Handler } from './_types.js';
import './_version.js';

@@ -12,2 +12,2 @@ /**

*/
export declare const setCatchHandler: (handler: HandlerCallback) => void;
export declare const setCatchHandler: (handler: Handler) => void;

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

import { HandlerCallback } from './_types.js';
import { Handler } from './_types.js';
import './_version.js';

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

*/
export declare const setDefaultHandler: (handler: HandlerCallback) => void;
export declare const setDefaultHandler: (handler: Handler) => void;

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

RouteHandler,
RouteHandlerObject,
RouteHandlerCallback,

@@ -70,2 +71,3 @@ RouteHandlerCallbackOptions,

RouteHandler as Handler,
RouteHandlerObject as HandlerObject,
RouteHandlerCallback as HandlerCallback,

@@ -72,0 +74,0 @@ RouteHandlerCallbackOptions as HandlerCallbackOptions,

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

@@ -12,3 +12,3 @@ /*

import {Route} from './Route.js';
import {HandlerCallback, MatchCallbackOptions} from './_types.js';
import {Handler, MatchCallbackOptions} from './_types.js';
import './_version.js';

@@ -59,3 +59,3 @@

*/
constructor(handler: HandlerCallback,
constructor(handler: Handler,
{whitelist = [/./], blacklist = []}: NavigationRouteMatchOptions = {}) {

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

@@ -13,3 +13,3 @@ /*

import {Route} from './Route.js';
import {MatchCallbackOptions, HandlerCallback, MatchCallback} from './_types.js';
import {Handler, MatchCallbackOptions, MatchCallback} from './_types.js';
import './_version.js';

@@ -45,3 +45,3 @@

*/
constructor(regExp: RegExp, handler: HandlerCallback, method?: HTTPMethod) {
constructor(regExp: RegExp, handler: Handler, method?: HTTPMethod) {
if (process.env.NODE_ENV !== 'production') {

@@ -48,0 +48,0 @@ assert!.isInstance(regExp, RegExp, {

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

import {getOrCreateDefaultRouter} from './utils/getOrCreateDefaultRouter.js';
import {MatchCallback, HandlerCallback} from './_types.js';
import {Handler, MatchCallback} from './_types.js';
import './_version.js';

@@ -47,3 +47,3 @@

capture: RegExp | string | MatchCallback | Route,
handler?: HandlerCallback,
handler?: Handler,
method?: HTTPMethod): Route => {

@@ -50,0 +50,0 @@ let route;

@@ -12,3 +12,3 @@ /*

import {normalizeHandler} from './utils/normalizeHandler.js';
import {Handler, HandlerCallback, MatchCallback} from './_types.js';
import {Handler, HandlerObject, MatchCallback} from './_types.js';
import './_version.js';

@@ -27,3 +27,3 @@

class Route {
handler: Handler;
handler: HandlerObject;
match: MatchCallback;

@@ -45,3 +45,3 @@ method: HTTPMethod;

match: MatchCallback,
handler: HandlerCallback | Handler,
handler: Handler,
method: HTTPMethod = defaultMethod) {

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

@@ -16,3 +16,3 @@ /*

import {normalizeHandler} from './utils/normalizeHandler.js';
import {Handler, HandlerCallback, HandlerCallbackOptions} from './_types.js';
import {Handler, HandlerObject, HandlerCallbackOptions} from './_types.js';
import './_version.js';

@@ -50,4 +50,4 @@

private _routes: Map<HTTPMethod, Route[]>;
private _defaultHandler: Handler;
private _catchHandler: Handler;
private _defaultHandler: HandlerObject;
private _catchHandler: HandlerObject;

@@ -332,3 +332,3 @@ /**

*/
setDefaultHandler(handler: HandlerCallback) {
setDefaultHandler(handler: Handler) {
this._defaultHandler = normalizeHandler(handler);

@@ -344,3 +344,3 @@ }

*/
setCatchHandler(handler: HandlerCallback) {
setCatchHandler(handler: Handler) {
this._catchHandler = normalizeHandler(handler);

@@ -347,0 +347,0 @@ }

@@ -10,3 +10,3 @@ /*

import {getOrCreateDefaultRouter} from './utils/getOrCreateDefaultRouter.js';
import {HandlerCallback} from './_types.js';
import {Handler} from './_types.js';
import './_version.js';

@@ -24,5 +24,5 @@

*/
export const setCatchHandler = (handler: HandlerCallback) => {
export const setCatchHandler = (handler: Handler) => {
const defaultRouter = getOrCreateDefaultRouter();
defaultRouter.setCatchHandler(handler);
};

@@ -10,3 +10,3 @@ /*

import {getOrCreateDefaultRouter} from './utils/getOrCreateDefaultRouter.js';
import {HandlerCallback} from './_types.js';
import {Handler} from './_types.js';
import './_version.js';

@@ -27,5 +27,5 @@

*/
export const setDefaultHandler = (handler: HandlerCallback) => {
export const setDefaultHandler = (handler: Handler) => {
const defaultRouter = getOrCreateDefaultRouter();
defaultRouter.setDefaultHandler(handler);
};

@@ -10,3 +10,3 @@ /*

import {assert} from 'workbox-core/_private/assert.js';
import {Handler, HandlerCallback} from '../_types.js';
import {Handler, HandlerObject} from '../_types.js';
import '../_version.js';

@@ -23,4 +23,4 @@

export const normalizeHandler = (
handler: Handler | HandlerCallback
): Handler => {
handler: Handler
): HandlerObject => {
if (handler && typeof handler === 'object') {

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

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

import { Handler, HandlerCallback } from '../_types.js';
import { Handler, HandlerObject } from '../_types.js';
import '../_version.js';

@@ -10,2 +10,2 @@ /**

*/
export declare const normalizeHandler: (handler: HandlerCallback | Handler) => Handler;
export declare const normalizeHandler: (handler: Handler) => HandlerObject;

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc