@serwist/sw 9.0.0-preview.20 → 9.0.0-preview.24
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.
- package/dist/index.d.ts +4 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -156
- package/package.json +5 -40
- package/src/index.ts +5 -22
- package/README.md +0 -1
- package/dist/abstractions/Serwist.d.ts +0 -82
- package/dist/abstractions/Serwist.d.ts.map +0 -1
- package/dist/abstractions/disableDevLogs.d.ts +0 -7
- package/dist/abstractions/disableDevLogs.d.ts.map +0 -1
- package/dist/abstractions/fallbacks.d.ts +0 -39
- package/dist/abstractions/fallbacks.d.ts.map +0 -1
- package/dist/abstractions/handlePrecaching.d.ts +0 -39
- package/dist/abstractions/handlePrecaching.d.ts.map +0 -1
- package/dist/abstractions/installSerwist.d.ts +0 -15
- package/dist/abstractions/installSerwist.d.ts.map +0 -1
- package/dist/abstractions/navigationPreload.d.ts +0 -20
- package/dist/abstractions/navigationPreload.d.ts.map +0 -1
- package/dist/abstractions/registerRuntimeCaching.d.ts +0 -11
- package/dist/abstractions/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/abstractions/types.d.ts +0 -29
- package/dist/abstractions/types.d.ts.map +0 -1
- package/dist/chunks/NavigationRoute.js +0 -54
- package/dist/chunks/NetworkOnly.js +0 -193
- package/dist/chunks/PrecacheFallbackPlugin.js +0 -573
- package/dist/chunks/Strategy.js +0 -410
- package/dist/chunks/precacheAndRoute.js +0 -113
- package/dist/chunks/registerRoute.js +0 -7
- package/dist/chunks/singletonPrecacheController.js +0 -433
- package/dist/chunks/singletonRouter.js +0 -435
- package/dist/index.plugins.d.ts +0 -41
- package/dist/index.plugins.d.ts.map +0 -1
- package/dist/index.plugins.js +0 -671
- package/dist/index.precaching.d.ts +0 -25
- package/dist/index.precaching.d.ts.map +0 -1
- package/dist/index.precaching.js +0 -24
- package/dist/index.routing.d.ts +0 -15
- package/dist/index.routing.d.ts.map +0 -1
- package/dist/index.routing.js +0 -19
- package/dist/index.strategies.d.ts +0 -22
- package/dist/index.strategies.d.ts.map +0 -1
- package/dist/index.strategies.js +0 -146
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +0 -23
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/Queue.d.ts +0 -166
- package/dist/plugins/backgroundSync/Queue.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/QueueDb.d.ts +0 -90
- package/dist/plugins/backgroundSync/QueueDb.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/QueueStore.d.ts +0 -75
- package/dist/plugins/backgroundSync/QueueStore.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/StorableRequest.d.ts +0 -51
- package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +0 -45
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +0 -27
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/constants.d.ts +0 -5
- package/dist/plugins/broadcastUpdate/constants.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +0 -11
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/types.d.ts +0 -34
- package/dist/plugins/broadcastUpdate/types.d.ts.map +0 -1
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +0 -40
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +0 -1
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +0 -27
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
- package/dist/plugins/expiration/CacheExpiration.d.ts +0 -66
- package/dist/plugins/expiration/CacheExpiration.d.ts.map +0 -1
- package/dist/plugins/expiration/ExpirationPlugin.d.ts +0 -116
- package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +0 -1
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +0 -73
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +0 -1
- package/dist/plugins/googleAnalytics/constants.d.ts +0 -10
- package/dist/plugins/googleAnalytics/constants.d.ts.map +0 -1
- package/dist/plugins/googleAnalytics/initialize.d.ts +0 -34
- package/dist/plugins/googleAnalytics/initialize.d.ts.map +0 -1
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +0 -54
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +0 -19
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts +0 -18
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +0 -14
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +0 -12
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
- package/dist/precaching/PrecacheController.d.ts +0 -145
- package/dist/precaching/PrecacheController.d.ts.map +0 -1
- package/dist/precaching/PrecacheRoute.d.ts +0 -20
- package/dist/precaching/PrecacheRoute.d.ts.map +0 -1
- package/dist/precaching/PrecacheStrategy.d.ts +0 -68
- package/dist/precaching/PrecacheStrategy.d.ts.map +0 -1
- package/dist/precaching/addPlugins.d.ts +0 -8
- package/dist/precaching/addPlugins.d.ts.map +0 -1
- package/dist/precaching/addRoute.d.ts +0 -15
- package/dist/precaching/addRoute.d.ts.map +0 -1
- package/dist/precaching/cleanupOutdatedCaches.d.ts +0 -6
- package/dist/precaching/cleanupOutdatedCaches.d.ts.map +0 -1
- package/dist/precaching/createHandlerBoundToURL.d.ts +0 -17
- package/dist/precaching/createHandlerBoundToURL.d.ts.map +0 -1
- package/dist/precaching/getCacheKeyForURL.d.ts +0 -20
- package/dist/precaching/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/precaching/matchPrecache.d.ts +0 -14
- package/dist/precaching/matchPrecache.d.ts.map +0 -1
- package/dist/precaching/precache.d.ts +0 -19
- package/dist/precaching/precache.d.ts.map +0 -1
- package/dist/precaching/precacheAndRoute.d.ts +0 -14
- package/dist/precaching/precacheAndRoute.d.ts.map +0 -1
- package/dist/precaching/singletonPrecacheController.d.ts +0 -38
- package/dist/precaching/singletonPrecacheController.d.ts.map +0 -1
- package/dist/precaching/types.d.ts +0 -37
- package/dist/precaching/types.d.ts.map +0 -1
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts +0 -17
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts +0 -15
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
- package/dist/precaching/utils/createCacheKey.d.ts +0 -16
- package/dist/precaching/utils/createCacheKey.d.ts.map +0 -1
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts +0 -18
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts.map +0 -1
- package/dist/precaching/utils/generateURLVariations.d.ts +0 -12
- package/dist/precaching/utils/generateURLVariations.d.ts.map +0 -1
- package/dist/precaching/utils/getCacheKeyForURL.d.ts +0 -14
- package/dist/precaching/utils/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/precaching/utils/printCleanupDetails.d.ts +0 -6
- package/dist/precaching/utils/printCleanupDetails.d.ts.map +0 -1
- package/dist/precaching/utils/printInstallDetails.d.ts +0 -7
- package/dist/precaching/utils/printInstallDetails.d.ts.map +0 -1
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts +0 -12
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts.map +0 -1
- package/dist/routing/NavigationRoute.d.ts +0 -57
- package/dist/routing/NavigationRoute.d.ts.map +0 -1
- package/dist/routing/RegExpRoute.d.ts +0 -24
- package/dist/routing/RegExpRoute.d.ts.map +0 -1
- package/dist/routing/Route.d.ts +0 -33
- package/dist/routing/Route.d.ts.map +0 -1
- package/dist/routing/Router.d.ts +0 -150
- package/dist/routing/Router.d.ts.map +0 -1
- package/dist/routing/parseRoute.d.ts +0 -16
- package/dist/routing/parseRoute.d.ts.map +0 -1
- package/dist/routing/registerRoute.d.ts +0 -15
- package/dist/routing/registerRoute.d.ts.map +0 -1
- package/dist/routing/setCatchHandler.d.ts +0 -9
- package/dist/routing/setCatchHandler.d.ts.map +0 -1
- package/dist/routing/setDefaultHandler.d.ts +0 -12
- package/dist/routing/setDefaultHandler.d.ts.map +0 -1
- package/dist/routing/singletonRouter.d.ts +0 -47
- package/dist/routing/singletonRouter.d.ts.map +0 -1
- package/dist/routing/unregisterRoute.d.ts +0 -8
- package/dist/routing/unregisterRoute.d.ts.map +0 -1
- package/dist/routing/utils/constants.d.ts +0 -15
- package/dist/routing/utils/constants.d.ts.map +0 -1
- package/dist/routing/utils/normalizeHandler.d.ts +0 -10
- package/dist/routing/utils/normalizeHandler.d.ts.map +0 -1
- package/dist/strategies/CacheFirst.d.ts +0 -23
- package/dist/strategies/CacheFirst.d.ts.map +0 -1
- package/dist/strategies/CacheOnly.d.ts +0 -20
- package/dist/strategies/CacheOnly.d.ts.map +0 -1
- package/dist/strategies/NetworkFirst.d.ts +0 -61
- package/dist/strategies/NetworkFirst.d.ts.map +0 -1
- package/dist/strategies/NetworkOnly.d.ts +0 -32
- package/dist/strategies/NetworkOnly.d.ts.map +0 -1
- package/dist/strategies/StaleWhileRevalidate.d.ts +0 -35
- package/dist/strategies/StaleWhileRevalidate.d.ts.map +0 -1
- package/dist/strategies/Strategy.d.ts +0 -83
- package/dist/strategies/Strategy.d.ts.map +0 -1
- package/dist/strategies/StrategyHandler.d.ts +0 -189
- package/dist/strategies/StrategyHandler.d.ts.map +0 -1
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +0 -3
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +0 -1
- package/dist/strategies/utils/messages.d.ts +0 -5
- package/dist/strategies/utils/messages.d.ts.map +0 -1
- package/src/abstractions/Serwist.ts +0 -177
- package/src/abstractions/disableDevLogs.ts +0 -10
- package/src/abstractions/fallbacks.ts +0 -65
- package/src/abstractions/handlePrecaching.ts +0 -65
- package/src/abstractions/installSerwist.ts +0 -28
- package/src/abstractions/navigationPreload.ts +0 -64
- package/src/abstractions/registerRuntimeCaching.ts +0 -17
- package/src/abstractions/types.ts +0 -29
- package/src/index.plugins.ts +0 -95
- package/src/index.precaching.ts +0 -41
- package/src/index.routing.ts +0 -28
- package/src/index.strategies.ts +0 -26
- package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +0 -39
- package/src/plugins/backgroundSync/Queue.ts +0 -438
- package/src/plugins/backgroundSync/QueueDb.ts +0 -176
- package/src/plugins/backgroundSync/QueueStore.ts +0 -161
- package/src/plugins/backgroundSync/StorableRequest.ts +0 -142
- package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +0 -159
- package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +0 -43
- package/src/plugins/broadcastUpdate/constants.ts +0 -12
- package/src/plugins/broadcastUpdate/responsesAreSame.ts +0 -48
- package/src/plugins/broadcastUpdate/types.ts +0 -37
- package/src/plugins/cacheableResponse/CacheableResponse.ts +0 -141
- package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +0 -46
- package/src/plugins/expiration/CacheExpiration.ts +0 -192
- package/src/plugins/expiration/ExpirationPlugin.ts +0 -297
- package/src/plugins/expiration/models/CacheTimestampsModel.ts +0 -184
- package/src/plugins/googleAnalytics/constants.ts +0 -22
- package/src/plugins/googleAnalytics/initialize.ts +0 -213
- package/src/plugins/precaching/PrecacheFallbackPlugin.ts +0 -86
- package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +0 -39
- package/src/plugins/rangeRequests/createPartialResponse.ts +0 -92
- package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +0 -58
- package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +0 -54
- package/src/precaching/PrecacheController.ts +0 -332
- package/src/precaching/PrecacheRoute.ts +0 -50
- package/src/precaching/PrecacheStrategy.ts +0 -238
- package/src/precaching/addPlugins.ts +0 -21
- package/src/precaching/addRoute.ts +0 -30
- package/src/precaching/cleanupOutdatedCaches.ts +0 -33
- package/src/precaching/createHandlerBoundToURL.ts +0 -30
- package/src/precaching/getCacheKeyForURL.ts +0 -33
- package/src/precaching/matchPrecache.ts +0 -25
- package/src/precaching/precache.ts +0 -31
- package/src/precaching/precacheAndRoute.ts +0 -27
- package/src/precaching/singletonPrecacheController.ts +0 -57
- package/src/precaching/types.ts +0 -46
- package/src/precaching/utils/PrecacheCacheKeyPlugin.ts +0 -36
- package/src/precaching/utils/PrecacheInstallReportPlugin.ts +0 -49
- package/src/precaching/utils/createCacheKey.ts +0 -68
- package/src/precaching/utils/deleteOutdatedCaches.ts +0 -40
- package/src/precaching/utils/generateURLVariations.ts +0 -55
- package/src/precaching/utils/getCacheKeyForURL.ts +0 -36
- package/src/precaching/utils/printCleanupDetails.ts +0 -38
- package/src/precaching/utils/printInstallDetails.ts +0 -53
- package/src/precaching/utils/removeIgnoredSearchParams.ts +0 -29
- package/src/routing/NavigationRoute.ts +0 -119
- package/src/routing/RegExpRoute.ts +0 -74
- package/src/routing/Route.ts +0 -68
- package/src/routing/Router.ts +0 -481
- package/src/routing/parseRoute.ts +0 -78
- package/src/routing/registerRoute.ts +0 -27
- package/src/routing/setCatchHandler.ts +0 -21
- package/src/routing/setDefaultHandler.ts +0 -24
- package/src/routing/singletonRouter.ts +0 -76
- package/src/routing/unregisterRoute.ts +0 -11
- package/src/routing/utils/constants.ts +0 -24
- package/src/routing/utils/normalizeHandler.ts +0 -40
- package/src/strategies/CacheFirst.ts +0 -87
- package/src/strategies/CacheOnly.ts +0 -58
- package/src/strategies/NetworkFirst.ts +0 -228
- package/src/strategies/NetworkOnly.ts +0 -96
- package/src/strategies/StaleWhileRevalidate.ts +0 -109
- package/src/strategies/Strategy.ts +0 -202
- package/src/strategies/StrategyHandler.ts +0 -557
- package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +0 -26
- package/src/strategies/utils/messages.ts +0 -20
|
@@ -1,53 +0,0 @@
|
|
|
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 { logger } from "@serwist/core/internal";
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @param groupTitle
|
|
13
|
-
* @param urls
|
|
14
|
-
*
|
|
15
|
-
* @private
|
|
16
|
-
*/
|
|
17
|
-
function _nestedGroup(groupTitle: string, urls: string[]): void {
|
|
18
|
-
if (urls.length === 0) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
logger.groupCollapsed(groupTitle);
|
|
23
|
-
|
|
24
|
-
for (const url of urls) {
|
|
25
|
-
logger.log(url);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
logger.groupEnd();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @param urlsToPrecache
|
|
33
|
-
* @param urlsAlreadyPrecached
|
|
34
|
-
* @private
|
|
35
|
-
*/
|
|
36
|
-
export function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]): void {
|
|
37
|
-
const precachedCount = urlsToPrecache.length;
|
|
38
|
-
const alreadyPrecachedCount = urlsAlreadyPrecached.length;
|
|
39
|
-
|
|
40
|
-
if (precachedCount || alreadyPrecachedCount) {
|
|
41
|
-
let message = `Precaching ${precachedCount} file${precachedCount === 1 ? "" : "s"}.`;
|
|
42
|
-
|
|
43
|
-
if (alreadyPrecachedCount > 0) {
|
|
44
|
-
message += ` ${alreadyPrecachedCount} ` + `file${alreadyPrecachedCount === 1 ? " is" : "s are"} already cached.`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
logger.groupCollapsed(message);
|
|
48
|
-
|
|
49
|
-
_nestedGroup("View newly precached URLs.", urlsToPrecache);
|
|
50
|
-
_nestedGroup("View previously precached URLs.", urlsAlreadyPrecached);
|
|
51
|
-
logger.groupEnd();
|
|
52
|
-
}
|
|
53
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
/**
|
|
10
|
-
* Removes any URL search parameters that should be ignored.
|
|
11
|
-
*
|
|
12
|
-
* @param urlObject The original URL.
|
|
13
|
-
* @param ignoreURLParametersMatching RegExps to test against
|
|
14
|
-
* each search parameter name. Matches mean that the search parameter should be
|
|
15
|
-
* ignored.
|
|
16
|
-
* @returns The URL with any ignored search parameters removed.
|
|
17
|
-
* @private
|
|
18
|
-
*/
|
|
19
|
-
export function removeIgnoredSearchParams(urlObject: URL, ignoreURLParametersMatching: RegExp[] = []): URL {
|
|
20
|
-
// Convert the iterable into an array at the start of the loop to make sure
|
|
21
|
-
// deletion doesn't mess up iteration.
|
|
22
|
-
for (const paramName of [...urlObject.searchParams.keys()]) {
|
|
23
|
-
if (ignoreURLParametersMatching.some((regExp) => regExp.test(paramName))) {
|
|
24
|
-
urlObject.searchParams.delete(paramName);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return urlObject;
|
|
29
|
-
}
|
|
@@ -1,119 +0,0 @@
|
|
|
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 { RouteHandler, RouteMatchCallbackOptions } from "@serwist/core";
|
|
10
|
-
import { assert, logger } from "@serwist/core/internal";
|
|
11
|
-
|
|
12
|
-
import { Route } from "./Route.js";
|
|
13
|
-
|
|
14
|
-
export interface NavigationRouteMatchOptions {
|
|
15
|
-
/**
|
|
16
|
-
* If any of these patterns
|
|
17
|
-
* match the URL's pathname and search parameter, the route will handle the
|
|
18
|
-
* request (assuming the denylist doesn't match).
|
|
19
|
-
*
|
|
20
|
-
* @default [/./]
|
|
21
|
-
*/
|
|
22
|
-
allowlist?: RegExp[];
|
|
23
|
-
/**
|
|
24
|
-
* If any of these patterns match, the route will not handle the request (even if a allowlist RegExp matches).
|
|
25
|
-
*/
|
|
26
|
-
denylist?: RegExp[];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* NavigationRoute makes it easy to create a `@serwist/routing` Route that matches for browser
|
|
31
|
-
* [navigation requests](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests).
|
|
32
|
-
*
|
|
33
|
-
* It will only match incoming Requests whose [mode](https://fetch.spec.whatwg.org/#concept-request-mode) is set to `navigate`.
|
|
34
|
-
*
|
|
35
|
-
* You can optionally only apply this route to a subset of navigation requests
|
|
36
|
-
* by using one or both of the `denylist` and `allowlist` parameters.
|
|
37
|
-
*/
|
|
38
|
-
export class NavigationRoute extends Route {
|
|
39
|
-
private readonly _allowlist: RegExp[];
|
|
40
|
-
private readonly _denylist: RegExp[];
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* If both `denylist` and `allowlist` are provided, the `denylist` will
|
|
44
|
-
* take precedence and the request will not match this route.
|
|
45
|
-
*
|
|
46
|
-
* The regular expressions in `allowlist` and `denylist`
|
|
47
|
-
* are matched against the concatenated
|
|
48
|
-
* [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname)
|
|
49
|
-
* and [`search`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search)
|
|
50
|
-
* portions of the requested URL.
|
|
51
|
-
*
|
|
52
|
-
* *Note*: These RegExps may be evaluated against every destination URL during
|
|
53
|
-
* a navigation. Avoid using
|
|
54
|
-
* [complex RegExps](https://github.com/GoogleChrome/workbox/issues/3077),
|
|
55
|
-
* or else your users may see delays when navigating your site.
|
|
56
|
-
*
|
|
57
|
-
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
58
|
-
* @param options
|
|
59
|
-
*/
|
|
60
|
-
constructor(handler: RouteHandler, { allowlist = [/./], denylist = [] }: NavigationRouteMatchOptions = {}) {
|
|
61
|
-
if (process.env.NODE_ENV !== "production") {
|
|
62
|
-
assert!.isArrayOfClass(allowlist, RegExp, {
|
|
63
|
-
moduleName: "@serwist/routing",
|
|
64
|
-
className: "NavigationRoute",
|
|
65
|
-
funcName: "constructor",
|
|
66
|
-
paramName: "options.allowlist",
|
|
67
|
-
});
|
|
68
|
-
assert!.isArrayOfClass(denylist, RegExp, {
|
|
69
|
-
moduleName: "@serwist/routing",
|
|
70
|
-
className: "NavigationRoute",
|
|
71
|
-
funcName: "constructor",
|
|
72
|
-
paramName: "options.denylist",
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
super((options: RouteMatchCallbackOptions) => this._match(options), handler);
|
|
77
|
-
|
|
78
|
-
this._allowlist = allowlist;
|
|
79
|
-
this._denylist = denylist;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Routes match handler.
|
|
84
|
-
*
|
|
85
|
-
* @param options
|
|
86
|
-
* @returns
|
|
87
|
-
* @private
|
|
88
|
-
*/
|
|
89
|
-
private _match({ url, request }: RouteMatchCallbackOptions): boolean {
|
|
90
|
-
if (request && request.mode !== "navigate") {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const pathnameAndSearch = url.pathname + url.search;
|
|
95
|
-
|
|
96
|
-
for (const regExp of this._denylist) {
|
|
97
|
-
if (regExp.test(pathnameAndSearch)) {
|
|
98
|
-
if (process.env.NODE_ENV !== "production") {
|
|
99
|
-
logger.log(
|
|
100
|
-
`The navigation route ${pathnameAndSearch} is not being used, since the URL matches this denylist pattern: ${regExp.toString()}`,
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
return false;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (this._allowlist.some((regExp) => regExp.test(pathnameAndSearch))) {
|
|
108
|
-
if (process.env.NODE_ENV !== "production") {
|
|
109
|
-
logger.debug(`The navigation route ${pathnameAndSearch} is being used.`);
|
|
110
|
-
}
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
if (process.env.NODE_ENV !== "production") {
|
|
115
|
-
logger.log(`The navigation route ${pathnameAndSearch} is not being used, since the URL being navigated to doesn't match the allowlist.`);
|
|
116
|
-
}
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
@@ -1,74 +0,0 @@
|
|
|
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 { RouteHandler, RouteMatchCallback, RouteMatchCallbackOptions } from "@serwist/core";
|
|
10
|
-
import { assert, logger } from "@serwist/core/internal";
|
|
11
|
-
|
|
12
|
-
import { Route } from "./Route.js";
|
|
13
|
-
import type { HTTPMethod } from "./utils/constants.js";
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* `RegExpRoute` makes it easy to create a regular expression based on a `@serwist/routing` Route.
|
|
17
|
-
*
|
|
18
|
-
* For same-origin requests the `RegExp` only needs to match part of the URL. For
|
|
19
|
-
* requests against third-party servers, you must define a `RegExp` that matches
|
|
20
|
-
* the start of the URL.
|
|
21
|
-
*/
|
|
22
|
-
export class RegExpRoute extends Route {
|
|
23
|
-
/**
|
|
24
|
-
* If the regular expression contains
|
|
25
|
-
* [capture groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references),
|
|
26
|
-
* the captured values will be passed to the `params` argument.
|
|
27
|
-
*
|
|
28
|
-
* @param regExp The regular expression to match against URLs.
|
|
29
|
-
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
30
|
-
* @param method The HTTP method to match the Route, defaults to GET.
|
|
31
|
-
* against.
|
|
32
|
-
*/
|
|
33
|
-
constructor(regExp: RegExp, handler: RouteHandler, method?: HTTPMethod) {
|
|
34
|
-
if (process.env.NODE_ENV !== "production") {
|
|
35
|
-
assert!.isInstance(regExp, RegExp, {
|
|
36
|
-
moduleName: "@serwist/routing",
|
|
37
|
-
className: "RegExpRoute",
|
|
38
|
-
funcName: "constructor",
|
|
39
|
-
paramName: "pattern",
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const match: RouteMatchCallback = ({ url }: RouteMatchCallbackOptions) => {
|
|
44
|
-
const result = regExp.exec(url.href);
|
|
45
|
-
|
|
46
|
-
// Return immediately if there's no match.
|
|
47
|
-
if (!result) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Require that the match start at the first character in the URL string
|
|
52
|
-
// if it's a cross-origin request.
|
|
53
|
-
// See https://github.com/GoogleChrome/workbox/issues/281 for the context
|
|
54
|
-
// behind this behavior.
|
|
55
|
-
if (url.origin !== location.origin && result.index !== 0) {
|
|
56
|
-
if (process.env.NODE_ENV !== "production") {
|
|
57
|
-
logger.debug(
|
|
58
|
-
`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.`,
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// If the route matches, but there aren't any capture groups defined, then
|
|
66
|
-
// this will return [], which is truthy and therefore sufficient to
|
|
67
|
-
// indicate a match.
|
|
68
|
-
// If there are capture groups, then it will return their values.
|
|
69
|
-
return result.slice(1);
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
super(match, handler, method);
|
|
73
|
-
}
|
|
74
|
-
}
|
package/src/routing/Route.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
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 { RouteHandler, RouteHandlerObject, RouteMatchCallback } from "@serwist/core";
|
|
10
|
-
import { assert } from "@serwist/core/internal";
|
|
11
|
-
|
|
12
|
-
import type { HTTPMethod } from "./utils/constants.js";
|
|
13
|
-
import { defaultMethod, validMethods } from "./utils/constants.js";
|
|
14
|
-
import { normalizeHandler } from "./utils/normalizeHandler.js";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A `Route` consists of a pair of callback functions, "match" and "handler".
|
|
18
|
-
* The "match" callback determine if a route should be used to "handle" a
|
|
19
|
-
* request by returning a non-falsy value if it can. The "handler" callback
|
|
20
|
-
* is called when there is a match and should return a Promise that resolves
|
|
21
|
-
* to a `Response`.
|
|
22
|
-
*/
|
|
23
|
-
export class Route {
|
|
24
|
-
handler: RouteHandlerObject;
|
|
25
|
-
match: RouteMatchCallback;
|
|
26
|
-
method: HTTPMethod;
|
|
27
|
-
catchHandler?: RouteHandlerObject;
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Constructor for Route class.
|
|
31
|
-
*
|
|
32
|
-
* @param match A callback function that determines whether the
|
|
33
|
-
* route matches a given `fetch` event by returning a non-falsy value.
|
|
34
|
-
* @param handler A callback function that returns a Promise resolving
|
|
35
|
-
* to a Response.
|
|
36
|
-
* @param method The HTTP method to match the Route against. Defaults
|
|
37
|
-
* to GET.
|
|
38
|
-
*/
|
|
39
|
-
constructor(match: RouteMatchCallback, handler: RouteHandler, method: HTTPMethod = defaultMethod) {
|
|
40
|
-
if (process.env.NODE_ENV !== "production") {
|
|
41
|
-
assert!.isType(match, "function", {
|
|
42
|
-
moduleName: "@serwist/routing",
|
|
43
|
-
className: "Route",
|
|
44
|
-
funcName: "constructor",
|
|
45
|
-
paramName: "match",
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
if (method) {
|
|
49
|
-
assert!.isOneOf(method, validMethods, { paramName: "method" });
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// These values are referenced directly by Router so cannot be
|
|
54
|
-
// altered by minificaton.
|
|
55
|
-
this.handler = normalizeHandler(handler);
|
|
56
|
-
this.match = match;
|
|
57
|
-
this.method = method;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
*
|
|
62
|
-
* @param handler A callback function that returns a Promise resolving
|
|
63
|
-
* to a Response.
|
|
64
|
-
*/
|
|
65
|
-
setCatchHandler(handler: RouteHandler): void {
|
|
66
|
-
this.catchHandler = normalizeHandler(handler);
|
|
67
|
-
}
|
|
68
|
-
}
|