@serwist/routing 9.0.0-preview.2 → 9.0.0-preview.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/index.d.ts +2 -12
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +1 -468
  4. package/package.json +7 -8
  5. package/src/index.ts +2 -22
  6. package/dist/NavigationRoute.d.ts +0 -57
  7. package/dist/NavigationRoute.d.ts.map +0 -1
  8. package/dist/RegExpRoute.d.ts +0 -24
  9. package/dist/RegExpRoute.d.ts.map +0 -1
  10. package/dist/Route.d.ts +0 -33
  11. package/dist/Route.d.ts.map +0 -1
  12. package/dist/Router.d.ts +0 -124
  13. package/dist/Router.d.ts.map +0 -1
  14. package/dist/_types.d.ts +0 -48
  15. package/dist/_types.d.ts.map +0 -1
  16. package/dist/registerRoute.d.ts +0 -15
  17. package/dist/registerRoute.d.ts.map +0 -1
  18. package/dist/setCatchHandler.d.ts +0 -9
  19. package/dist/setCatchHandler.d.ts.map +0 -1
  20. package/dist/setDefaultHandler.d.ts +0 -12
  21. package/dist/setDefaultHandler.d.ts.map +0 -1
  22. package/dist/unregisterRoute.d.ts +0 -8
  23. package/dist/unregisterRoute.d.ts.map +0 -1
  24. package/dist/utils/constants.d.ts +0 -15
  25. package/dist/utils/constants.d.ts.map +0 -1
  26. package/dist/utils/getOrCreateDefaultRouter.d.ts +0 -10
  27. package/dist/utils/getOrCreateDefaultRouter.d.ts.map +0 -1
  28. package/dist/utils/normalizeHandler.d.ts +0 -10
  29. package/dist/utils/normalizeHandler.d.ts.map +0 -1
  30. package/src/NavigationRoute.ts +0 -119
  31. package/src/RegExpRoute.ts +0 -74
  32. package/src/Route.ts +0 -68
  33. package/src/Router.ts +0 -436
  34. package/src/_types.ts +0 -62
  35. package/src/registerRoute.ts +0 -89
  36. package/src/setCatchHandler.ts +0 -22
  37. package/src/setDefaultHandler.ts +0 -25
  38. package/src/unregisterRoute.ts +0 -12
  39. package/src/utils/constants.ts +0 -24
  40. package/src/utils/getOrCreateDefaultRouter.ts +0 -29
  41. package/src/utils/normalizeHandler.ts +0 -40
package/dist/index.d.ts CHANGED
@@ -1,13 +1,3 @@
1
- import type { NavigationRouteMatchOptions } from "./NavigationRoute.js";
2
- import { NavigationRoute } from "./NavigationRoute.js";
3
- import { RegExpRoute } from "./RegExpRoute.js";
4
- import { Route } from "./Route.js";
5
- import { Router } from "./Router.js";
6
- import { registerRoute } from "./registerRoute.js";
7
- import { setCatchHandler } from "./setCatchHandler.js";
8
- import { setDefaultHandler } from "./setDefaultHandler.js";
9
- import { unregisterRoute } from "./unregisterRoute.js";
10
- import type { HTTPMethod } from "./utils/constants.js";
11
- export { NavigationRoute, RegExpRoute, registerRoute, Route, Router, setCatchHandler, setDefaultHandler, unregisterRoute };
12
- export type { HTTPMethod, NavigationRouteMatchOptions };
1
+ export { NavigationRoute, RegExpRoute, registerRoute, Route, Router, setCatchHandler, setDefaultHandler, unregisterRoute } from "@serwist/sw/routing";
2
+ export type { HTTPMethod, NavigationRouteMatchOptions } from "@serwist/sw/routing";
13
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,CAAC;AAE3H,YAAY,EAAE,UAAU,EAAE,2BAA2B,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtJ,YAAY,EAAE,UAAU,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,468 +1 @@
1
- import { assert, logger, getFriendlyURL, SerwistError } from '@serwist/core/internal';
2
-
3
- const defaultMethod = "GET";
4
- const validMethods = [
5
- "DELETE",
6
- "GET",
7
- "HEAD",
8
- "PATCH",
9
- "POST",
10
- "PUT"
11
- ];
12
-
13
- const normalizeHandler = (handler)=>{
14
- if (handler && typeof handler === "object") {
15
- if (process.env.NODE_ENV !== "production") {
16
- assert.hasMethod(handler, "handle", {
17
- moduleName: "@serwist/routing",
18
- className: "Route",
19
- funcName: "constructor",
20
- paramName: "handler"
21
- });
22
- }
23
- return handler;
24
- }
25
- if (process.env.NODE_ENV !== "production") {
26
- assert.isType(handler, "function", {
27
- moduleName: "@serwist/routing",
28
- className: "Route",
29
- funcName: "constructor",
30
- paramName: "handler"
31
- });
32
- }
33
- return {
34
- handle: handler
35
- };
36
- };
37
-
38
- class Route {
39
- handler;
40
- match;
41
- method;
42
- catchHandler;
43
- constructor(match, handler, method = defaultMethod){
44
- if (process.env.NODE_ENV !== "production") {
45
- assert.isType(match, "function", {
46
- moduleName: "@serwist/routing",
47
- className: "Route",
48
- funcName: "constructor",
49
- paramName: "match"
50
- });
51
- if (method) {
52
- assert.isOneOf(method, validMethods, {
53
- paramName: "method"
54
- });
55
- }
56
- }
57
- this.handler = normalizeHandler(handler);
58
- this.match = match;
59
- this.method = method;
60
- }
61
- setCatchHandler(handler) {
62
- this.catchHandler = normalizeHandler(handler);
63
- }
64
- }
65
-
66
- class NavigationRoute extends Route {
67
- _allowlist;
68
- _denylist;
69
- constructor(handler, { allowlist = [
70
- /./
71
- ], denylist = [] } = {}){
72
- if (process.env.NODE_ENV !== "production") {
73
- assert.isArrayOfClass(allowlist, RegExp, {
74
- moduleName: "@serwist/routing",
75
- className: "NavigationRoute",
76
- funcName: "constructor",
77
- paramName: "options.allowlist"
78
- });
79
- assert.isArrayOfClass(denylist, RegExp, {
80
- moduleName: "@serwist/routing",
81
- className: "NavigationRoute",
82
- funcName: "constructor",
83
- paramName: "options.denylist"
84
- });
85
- }
86
- super((options)=>this._match(options), handler);
87
- this._allowlist = allowlist;
88
- this._denylist = denylist;
89
- }
90
- _match({ url, request }) {
91
- if (request && request.mode !== "navigate") {
92
- return false;
93
- }
94
- const pathnameAndSearch = url.pathname + url.search;
95
- for (const regExp of this._denylist){
96
- if (regExp.test(pathnameAndSearch)) {
97
- if (process.env.NODE_ENV !== "production") {
98
- logger.log(`The navigation route ${pathnameAndSearch} is not being used, since the URL matches this denylist pattern: ${regExp.toString()}`);
99
- }
100
- return false;
101
- }
102
- }
103
- if (this._allowlist.some((regExp)=>regExp.test(pathnameAndSearch))) {
104
- if (process.env.NODE_ENV !== "production") {
105
- logger.debug(`The navigation route ${pathnameAndSearch} is being used.`);
106
- }
107
- return true;
108
- }
109
- if (process.env.NODE_ENV !== "production") {
110
- logger.log(`The navigation route ${pathnameAndSearch} is not being used, since the URL being navigated to doesn't match the allowlist.`);
111
- }
112
- return false;
113
- }
114
- }
115
-
116
- class RegExpRoute extends Route {
117
- constructor(regExp, handler, method){
118
- if (process.env.NODE_ENV !== "production") {
119
- assert.isInstance(regExp, RegExp, {
120
- moduleName: "@serwist/routing",
121
- className: "RegExpRoute",
122
- funcName: "constructor",
123
- paramName: "pattern"
124
- });
125
- }
126
- const match = ({ url })=>{
127
- const result = regExp.exec(url.href);
128
- if (!result) {
129
- return;
130
- }
131
- if (url.origin !== location.origin && result.index !== 0) {
132
- if (process.env.NODE_ENV !== "production") {
133
- 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.`);
134
- }
135
- return;
136
- }
137
- return result.slice(1);
138
- };
139
- super(match, handler, method);
140
- }
141
- }
142
-
143
- class Router {
144
- _routes;
145
- _defaultHandlerMap;
146
- _catchHandler;
147
- constructor(){
148
- this._routes = new Map();
149
- this._defaultHandlerMap = new Map();
150
- }
151
- get routes() {
152
- return this._routes;
153
- }
154
- addFetchListener() {
155
- self.addEventListener("fetch", (event)=>{
156
- const { request } = event;
157
- const responsePromise = this.handleRequest({
158
- request,
159
- event
160
- });
161
- if (responsePromise) {
162
- event.respondWith(responsePromise);
163
- }
164
- });
165
- }
166
- addCacheListener() {
167
- self.addEventListener("message", (event)=>{
168
- if (event.data && event.data.type === "CACHE_URLS") {
169
- const { payload } = event.data;
170
- if (process.env.NODE_ENV !== "production") {
171
- logger.debug("Caching URLs from the window", payload.urlsToCache);
172
- }
173
- const requestPromises = Promise.all(payload.urlsToCache.map((entry)=>{
174
- if (typeof entry === "string") {
175
- entry = [
176
- entry
177
- ];
178
- }
179
- const request = new Request(...entry);
180
- return this.handleRequest({
181
- request,
182
- event
183
- });
184
- }));
185
- event.waitUntil(requestPromises);
186
- if (event.ports?.[0]) {
187
- void requestPromises.then(()=>event.ports[0].postMessage(true));
188
- }
189
- }
190
- });
191
- }
192
- handleRequest({ request, event }) {
193
- if (process.env.NODE_ENV !== "production") {
194
- assert.isInstance(request, Request, {
195
- moduleName: "@serwist/routing",
196
- className: "Router",
197
- funcName: "handleRequest",
198
- paramName: "options.request"
199
- });
200
- }
201
- const url = new URL(request.url, location.href);
202
- if (!url.protocol.startsWith("http")) {
203
- if (process.env.NODE_ENV !== "production") {
204
- logger.debug(`Serwist Router only supports URLs that start with 'http'.`);
205
- }
206
- return;
207
- }
208
- const sameOrigin = url.origin === location.origin;
209
- const { params, route } = this.findMatchingRoute({
210
- event,
211
- request,
212
- sameOrigin,
213
- url
214
- });
215
- let handler = route?.handler;
216
- const debugMessages = [];
217
- if (process.env.NODE_ENV !== "production") {
218
- if (handler) {
219
- debugMessages.push([
220
- "Found a route to handle this request:",
221
- route
222
- ]);
223
- if (params) {
224
- debugMessages.push([
225
- `Passing the following params to the route's handler:`,
226
- params
227
- ]);
228
- }
229
- }
230
- }
231
- const method = request.method;
232
- if (!handler && this._defaultHandlerMap.has(method)) {
233
- if (process.env.NODE_ENV !== "production") {
234
- debugMessages.push(`Failed to find a matching route. Falling back to the default handler for ${method}.`);
235
- }
236
- handler = this._defaultHandlerMap.get(method);
237
- }
238
- if (!handler) {
239
- if (process.env.NODE_ENV !== "production") {
240
- logger.debug(`No route found for: ${getFriendlyURL(url)}`);
241
- }
242
- return;
243
- }
244
- if (process.env.NODE_ENV !== "production") {
245
- logger.groupCollapsed(`Router is responding to: ${getFriendlyURL(url)}`);
246
- for (const msg of debugMessages){
247
- if (Array.isArray(msg)) {
248
- logger.log(...msg);
249
- } else {
250
- logger.log(msg);
251
- }
252
- }
253
- logger.groupEnd();
254
- }
255
- let responsePromise;
256
- try {
257
- responsePromise = handler.handle({
258
- url,
259
- request,
260
- event,
261
- params
262
- });
263
- } catch (err) {
264
- responsePromise = Promise.reject(err);
265
- }
266
- const catchHandler = route?.catchHandler;
267
- if (responsePromise instanceof Promise && (this._catchHandler || catchHandler)) {
268
- responsePromise = responsePromise.catch(async (err)=>{
269
- if (catchHandler) {
270
- if (process.env.NODE_ENV !== "production") {
271
- logger.groupCollapsed(`Error thrown when responding to: ${getFriendlyURL(url)}. Falling back to route's Catch Handler.`);
272
- logger.error("Error thrown by:", route);
273
- logger.error(err);
274
- logger.groupEnd();
275
- }
276
- try {
277
- return await catchHandler.handle({
278
- url,
279
- request,
280
- event,
281
- params
282
- });
283
- } catch (catchErr) {
284
- if (catchErr instanceof Error) {
285
- err = catchErr;
286
- }
287
- }
288
- }
289
- if (this._catchHandler) {
290
- if (process.env.NODE_ENV !== "production") {
291
- logger.groupCollapsed(`Error thrown when responding to: ${getFriendlyURL(url)}. Falling back to global Catch Handler.`);
292
- logger.error("Error thrown by:", route);
293
- logger.error(err);
294
- logger.groupEnd();
295
- }
296
- return this._catchHandler.handle({
297
- url,
298
- request,
299
- event
300
- });
301
- }
302
- throw err;
303
- });
304
- }
305
- return responsePromise;
306
- }
307
- findMatchingRoute({ url, sameOrigin, request, event }) {
308
- const routes = this._routes.get(request.method) || [];
309
- for (const route of routes){
310
- let params;
311
- const matchResult = route.match({
312
- url,
313
- sameOrigin,
314
- request,
315
- event
316
- });
317
- if (matchResult) {
318
- if (process.env.NODE_ENV !== "production") {
319
- if (matchResult instanceof Promise) {
320
- logger.warn(`While routing ${getFriendlyURL(url)}, an async matchCallback function was used. Please convert the following route to use a synchronous matchCallback function:`, route);
321
- }
322
- }
323
- params = matchResult;
324
- if (Array.isArray(params) && params.length === 0) {
325
- params = undefined;
326
- } else if (matchResult.constructor === Object && Object.keys(matchResult).length === 0) {
327
- params = undefined;
328
- } else if (typeof matchResult === "boolean") {
329
- params = undefined;
330
- }
331
- return {
332
- route,
333
- params
334
- };
335
- }
336
- }
337
- return {};
338
- }
339
- setDefaultHandler(handler, method = defaultMethod) {
340
- this._defaultHandlerMap.set(method, normalizeHandler(handler));
341
- }
342
- setCatchHandler(handler) {
343
- this._catchHandler = normalizeHandler(handler);
344
- }
345
- registerRoute(route) {
346
- if (process.env.NODE_ENV !== "production") {
347
- assert.isType(route, "object", {
348
- moduleName: "@serwist/routing",
349
- className: "Router",
350
- funcName: "registerRoute",
351
- paramName: "route"
352
- });
353
- assert.hasMethod(route, "match", {
354
- moduleName: "@serwist/routing",
355
- className: "Router",
356
- funcName: "registerRoute",
357
- paramName: "route"
358
- });
359
- assert.isType(route.handler, "object", {
360
- moduleName: "@serwist/routing",
361
- className: "Router",
362
- funcName: "registerRoute",
363
- paramName: "route"
364
- });
365
- assert.hasMethod(route.handler, "handle", {
366
- moduleName: "@serwist/routing",
367
- className: "Router",
368
- funcName: "registerRoute",
369
- paramName: "route.handler"
370
- });
371
- assert.isType(route.method, "string", {
372
- moduleName: "@serwist/routing",
373
- className: "Router",
374
- funcName: "registerRoute",
375
- paramName: "route.method"
376
- });
377
- }
378
- if (!this._routes.has(route.method)) {
379
- this._routes.set(route.method, []);
380
- }
381
- this._routes.get(route.method).push(route);
382
- }
383
- unregisterRoute(route) {
384
- if (!this._routes.has(route.method)) {
385
- throw new SerwistError("unregister-route-but-not-found-with-method", {
386
- method: route.method
387
- });
388
- }
389
- const routeIndex = this._routes.get(route.method).indexOf(route);
390
- if (routeIndex > -1) {
391
- this._routes.get(route.method).splice(routeIndex, 1);
392
- } else {
393
- throw new SerwistError("unregister-route-route-not-registered");
394
- }
395
- }
396
- }
397
-
398
- let defaultRouter;
399
- const getOrCreateDefaultRouter = ()=>{
400
- if (!defaultRouter) {
401
- defaultRouter = new Router();
402
- defaultRouter.addFetchListener();
403
- defaultRouter.addCacheListener();
404
- }
405
- return defaultRouter;
406
- };
407
-
408
- const registerRoute = (capture, handler, method)=>{
409
- let route;
410
- if (typeof capture === "string") {
411
- const captureUrl = new URL(capture, location.href);
412
- if (process.env.NODE_ENV !== "production") {
413
- if (!(capture.startsWith("/") || capture.startsWith("http"))) {
414
- throw new SerwistError("invalid-string", {
415
- moduleName: "@serwist/routing",
416
- funcName: "registerRoute",
417
- paramName: "capture"
418
- });
419
- }
420
- const valueToCheck = capture.startsWith("http") ? captureUrl.pathname : capture;
421
- const wildcards = "[*:?+]";
422
- if (new RegExp(`${wildcards}`).exec(valueToCheck)) {
423
- 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.`);
424
- }
425
- }
426
- const matchCallback = ({ url })=>{
427
- if (process.env.NODE_ENV !== "production") {
428
- if (url.pathname === captureUrl.pathname && url.origin !== captureUrl.origin) {
429
- 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.`);
430
- }
431
- }
432
- return url.href === captureUrl.href;
433
- };
434
- route = new Route(matchCallback, handler, method);
435
- } else if (capture instanceof RegExp) {
436
- route = new RegExpRoute(capture, handler, method);
437
- } else if (typeof capture === "function") {
438
- route = new Route(capture, handler, method);
439
- } else if (capture instanceof Route) {
440
- route = capture;
441
- } else {
442
- throw new SerwistError("unsupported-route-type", {
443
- moduleName: "@serwist/routing",
444
- funcName: "registerRoute",
445
- paramName: "capture"
446
- });
447
- }
448
- const defaultRouter = getOrCreateDefaultRouter();
449
- defaultRouter.registerRoute(route);
450
- return route;
451
- };
452
-
453
- const setCatchHandler = (handler)=>{
454
- const defaultRouter = getOrCreateDefaultRouter();
455
- defaultRouter.setCatchHandler(handler);
456
- };
457
-
458
- const setDefaultHandler = (handler)=>{
459
- const defaultRouter = getOrCreateDefaultRouter();
460
- defaultRouter.setDefaultHandler(handler);
461
- };
462
-
463
- const unregisterRoute = (route)=>{
464
- const defaultRouter = getOrCreateDefaultRouter();
465
- defaultRouter.unregisterRoute(route);
466
- };
467
-
468
- export { NavigationRoute, RegExpRoute, Route, Router, registerRoute, setCatchHandler, setDefaultHandler, unregisterRoute };
1
+ export { NavigationRoute, RegExpRoute, Route, Router, registerRoute, setCatchHandler, setDefaultHandler, unregisterRoute } from '@serwist/sw/routing';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/routing",
3
- "version": "9.0.0-preview.2",
3
+ "version": "9.0.0-preview.20",
4
4
  "type": "module",
5
5
  "description": "A service worker helper library to route request URLs to handlers.",
6
6
  "files": [
@@ -17,8 +17,8 @@
17
17
  ],
18
18
  "author": "Google's Web DevRel Team, Serwist's Team",
19
19
  "license": "MIT",
20
- "repository": "serwist/serwist",
21
- "bugs": "https://github.com/serwist/serwist/issues",
20
+ "repository": "https://gitlab.com/serwist/serwist",
21
+ "bugs": "https://gitlab.com/serwist/serwist/issues",
22
22
  "homepage": "https://serwist.pages.dev",
23
23
  "main": "./dist/index.js",
24
24
  "types": "./dist/index.d.ts",
@@ -30,12 +30,12 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "dependencies": {
33
- "@serwist/core": "9.0.0-preview.2"
33
+ "@serwist/sw": "9.0.0-preview.20"
34
34
  },
35
35
  "devDependencies": {
36
- "rollup": "4.9.6",
37
- "typescript": "5.4.0-dev.20240206",
38
- "@serwist/constants": "9.0.0-preview.2"
36
+ "rollup": "4.13.0",
37
+ "typescript": "5.5.0-dev.20240323",
38
+ "@serwist/constants": "9.0.0-preview.20"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "typescript": ">=5.0.0"
@@ -47,7 +47,6 @@
47
47
  },
48
48
  "scripts": {
49
49
  "build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
50
- "dev": "rollup --config rollup.config.js --watch",
51
50
  "lint": "biome lint ./src",
52
51
  "typecheck": "tsc"
53
52
  }
package/src/index.ts CHANGED
@@ -1,22 +1,2 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import type { NavigationRouteMatchOptions } from "./NavigationRoute.js";
10
- import { NavigationRoute } from "./NavigationRoute.js";
11
- import { RegExpRoute } from "./RegExpRoute.js";
12
- import { Route } from "./Route.js";
13
- import { Router } from "./Router.js";
14
- import { registerRoute } from "./registerRoute.js";
15
- import { setCatchHandler } from "./setCatchHandler.js";
16
- import { setDefaultHandler } from "./setDefaultHandler.js";
17
- import { unregisterRoute } from "./unregisterRoute.js";
18
- import type { HTTPMethod } from "./utils/constants.js";
19
-
20
- export { NavigationRoute, RegExpRoute, registerRoute, Route, Router, setCatchHandler, setDefaultHandler, unregisterRoute };
21
-
22
- export type { HTTPMethod, NavigationRouteMatchOptions };
1
+ export { NavigationRoute, RegExpRoute, registerRoute, Route, Router, setCatchHandler, setDefaultHandler, unregisterRoute } from "@serwist/sw/routing";
2
+ export type { HTTPMethod, NavigationRouteMatchOptions } from "@serwist/sw/routing";
@@ -1,57 +0,0 @@
1
- import type { RouteHandler } from "@serwist/core";
2
- import { Route } from "./Route.js";
3
- export interface NavigationRouteMatchOptions {
4
- /**
5
- * If any of these patterns
6
- * match the URL's pathname and search parameter, the route will handle the
7
- * request (assuming the denylist doesn't match).
8
- *
9
- * @default [/./]
10
- */
11
- allowlist?: RegExp[];
12
- /**
13
- * If any of these patterns match, the route will not handle the request (even if a allowlist RegExp matches).
14
- */
15
- denylist?: RegExp[];
16
- }
17
- /**
18
- * NavigationRoute makes it easy to create a `@serwist/routing` Route that matches for browser
19
- * [navigation requests](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests).
20
- *
21
- * It will only match incoming Requests whose [mode](https://fetch.spec.whatwg.org/#concept-request-mode) is set to `navigate`.
22
- *
23
- * You can optionally only apply this route to a subset of navigation requests
24
- * by using one or both of the `denylist` and `allowlist` parameters.
25
- */
26
- export declare class NavigationRoute extends Route {
27
- private readonly _allowlist;
28
- private readonly _denylist;
29
- /**
30
- * If both `denylist` and `allowlist` are provided, the `denylist` will
31
- * take precedence and the request will not match this route.
32
- *
33
- * The regular expressions in `allowlist` and `denylist`
34
- * are matched against the concatenated
35
- * [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname)
36
- * and [`search`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search)
37
- * portions of the requested URL.
38
- *
39
- * *Note*: These RegExps may be evaluated against every destination URL during
40
- * a navigation. Avoid using
41
- * [complex RegExps](https://github.com/GoogleChrome/workbox/issues/3077),
42
- * or else your users may see delays when navigating your site.
43
- *
44
- * @param handler A callback function that returns a Promise resulting in a Response.
45
- * @param options
46
- */
47
- constructor(handler: RouteHandler, { allowlist, denylist }?: NavigationRouteMatchOptions);
48
- /**
49
- * Routes match handler.
50
- *
51
- * @param options
52
- * @returns
53
- * @private
54
- */
55
- private _match;
56
- }
57
- //# sourceMappingURL=NavigationRoute.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NavigationRoute.d.ts","sourceRoot":"","sources":["../src/NavigationRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAA6B,MAAM,eAAe,CAAC;AAG7E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,WAAW,2BAA2B;IAC1C;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IAErC;;;;;;;;;;;;;;;;;OAiBG;gBACS,OAAO,EAAE,YAAY,EAAE,EAAE,SAAiB,EAAE,QAAa,EAAE,GAAE,2BAAgC;IAsBzG;;;;;;OAMG;IACH,OAAO,CAAC,MAAM;CA8Bf"}
@@ -1,24 +0,0 @@
1
- import type { RouteHandler } from "@serwist/core";
2
- import { Route } from "./Route.js";
3
- import type { HTTPMethod } from "./utils/constants.js";
4
- /**
5
- * RegExpRoute makes it easy to create a regular expression based on a `@serwist/routing` Route.
6
- *
7
- * For same-origin requests the RegExp only needs to match part of the URL. For
8
- * requests against third-party servers, you must define a RegExp that matches
9
- * the start of the URL.
10
- */
11
- export declare class RegExpRoute extends Route {
12
- /**
13
- * If the regular expression contains
14
- * [capture groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references),
15
- * the captured values will be passed to the `params` argument.
16
- *
17
- * @param regExp The regular expression to match against URLs.
18
- * @param handler A callback function that returns a Promise resulting in a Response.
19
- * @param method The HTTP method to match the Route, defaults to GET.
20
- * against.
21
- */
22
- constructor(regExp: RegExp, handler: RouteHandler, method?: HTTPMethod);
23
- }
24
- //# sourceMappingURL=RegExpRoute.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RegExpRoute.d.ts","sourceRoot":"","sources":["../src/RegExpRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAiD,MAAM,eAAe,CAAC;AAGjG,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;;;;;;;OASG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,UAAU;CAyCvE"}