@serwist/sw 9.0.0-preview.17 → 9.0.0-preview.18
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/{Serwist.d.ts → abstractions/Serwist.d.ts} +6 -15
- package/dist/abstractions/Serwist.d.ts.map +1 -0
- package/dist/abstractions/disableDevLogs.d.ts.map +1 -0
- package/dist/{fallbacks.d.ts → abstractions/fallbacks.d.ts} +2 -2
- package/dist/abstractions/fallbacks.d.ts.map +1 -0
- package/dist/{handlePrecaching.d.ts → abstractions/handlePrecaching.d.ts} +1 -1
- package/dist/abstractions/handlePrecaching.d.ts.map +1 -0
- package/dist/abstractions/installSerwist.d.ts.map +1 -0
- package/dist/abstractions/registerRuntimeCaching.d.ts.map +1 -0
- package/dist/{types.d.ts → abstractions/types.d.ts} +1 -1
- package/dist/abstractions/types.d.ts.map +1 -0
- package/dist/chunks/NavigationRoute.js +54 -0
- package/dist/chunks/NetworkOnly.js +193 -0
- package/dist/chunks/PrecacheFallbackPlugin.js +573 -0
- package/dist/chunks/Strategy.js +410 -0
- package/dist/chunks/getOrCreatePrecacheController.js +429 -0
- package/dist/chunks/precacheAndRoute.js +112 -0
- package/dist/chunks/registerRoute.js +408 -0
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -9
- package/dist/index.plugins.d.ts +40 -11
- package/dist/index.plugins.d.ts.map +1 -1
- package/dist/index.plugins.js +671 -5
- package/dist/index.precaching.d.ts +24 -0
- package/dist/index.precaching.d.ts.map +1 -0
- package/dist/index.precaching.js +24 -0
- package/dist/index.routing.d.ts +13 -0
- package/dist/index.routing.d.ts.map +1 -0
- package/dist/index.routing.js +21 -0
- package/dist/index.strategies.d.ts +19 -2
- package/dist/index.strategies.d.ts.map +1 -1
- package/dist/index.strategies.js +146 -1
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +23 -0
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/Queue.d.ts +166 -0
- package/dist/plugins/backgroundSync/Queue.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/QueueDb.d.ts +90 -0
- package/dist/plugins/backgroundSync/QueueDb.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/QueueStore.d.ts +75 -0
- package/dist/plugins/backgroundSync/QueueStore.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/StorableRequest.d.ts +51 -0
- package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +45 -0
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +27 -0
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/constants.d.ts +5 -0
- package/dist/plugins/broadcastUpdate/constants.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +11 -0
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/types.d.ts +34 -0
- package/dist/plugins/broadcastUpdate/types.d.ts.map +1 -0
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +40 -0
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +1 -0
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +27 -0
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
- package/dist/plugins/expiration/CacheExpiration.d.ts +66 -0
- package/dist/plugins/expiration/CacheExpiration.d.ts.map +1 -0
- package/dist/plugins/expiration/ExpirationPlugin.d.ts +116 -0
- package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +1 -0
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +73 -0
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
- package/dist/plugins/googleAnalytics/constants.d.ts +10 -0
- package/dist/plugins/googleAnalytics/constants.d.ts.map +1 -0
- package/dist/plugins/googleAnalytics/initialize.d.ts +26 -0
- package/dist/plugins/googleAnalytics/initialize.d.ts.map +1 -0
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +54 -0
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +19 -0
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts +18 -0
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +14 -0
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +12 -0
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
- package/dist/precaching/PrecacheController.d.ts +145 -0
- package/dist/precaching/PrecacheController.d.ts.map +1 -0
- package/dist/precaching/PrecacheRoute.d.ts +20 -0
- package/dist/precaching/PrecacheRoute.d.ts.map +1 -0
- package/dist/precaching/PrecacheStrategy.d.ts +68 -0
- package/dist/precaching/PrecacheStrategy.d.ts.map +1 -0
- package/dist/precaching/addPlugins.d.ts +8 -0
- package/dist/precaching/addPlugins.d.ts.map +1 -0
- package/dist/precaching/addRoute.d.ts +15 -0
- package/dist/precaching/addRoute.d.ts.map +1 -0
- package/dist/precaching/cleanupOutdatedCaches.d.ts +6 -0
- package/dist/precaching/cleanupOutdatedCaches.d.ts.map +1 -0
- package/dist/precaching/createHandlerBoundToURL.d.ts +17 -0
- package/dist/precaching/createHandlerBoundToURL.d.ts.map +1 -0
- package/dist/precaching/getCacheKeyForURL.d.ts +20 -0
- package/dist/precaching/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/precaching/matchPrecache.d.ts +14 -0
- package/dist/precaching/matchPrecache.d.ts.map +1 -0
- package/dist/precaching/precache.d.ts +19 -0
- package/dist/precaching/precache.d.ts.map +1 -0
- package/dist/precaching/precacheAndRoute.d.ts +14 -0
- package/dist/precaching/precacheAndRoute.d.ts.map +1 -0
- package/dist/precaching/types.d.ts +37 -0
- package/dist/precaching/types.d.ts.map +1 -0
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts +17 -0
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts +15 -0
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
- package/dist/precaching/utils/createCacheKey.d.ts +16 -0
- package/dist/precaching/utils/createCacheKey.d.ts.map +1 -0
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts +18 -0
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts.map +1 -0
- package/dist/precaching/utils/generateURLVariations.d.ts +12 -0
- package/dist/precaching/utils/generateURLVariations.d.ts.map +1 -0
- package/dist/precaching/utils/getCacheKeyForURL.d.ts +14 -0
- package/dist/precaching/utils/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/precaching/utils/getOrCreatePrecacheController.d.ts +7 -0
- package/dist/precaching/utils/getOrCreatePrecacheController.d.ts.map +1 -0
- package/dist/precaching/utils/printCleanupDetails.d.ts +6 -0
- package/dist/precaching/utils/printCleanupDetails.d.ts.map +1 -0
- package/dist/precaching/utils/printInstallDetails.d.ts +7 -0
- package/dist/precaching/utils/printInstallDetails.d.ts.map +1 -0
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts +12 -0
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts.map +1 -0
- package/dist/routing/NavigationRoute.d.ts +57 -0
- package/dist/routing/NavigationRoute.d.ts.map +1 -0
- package/dist/routing/RegExpRoute.d.ts +24 -0
- package/dist/routing/RegExpRoute.d.ts.map +1 -0
- package/dist/routing/Route.d.ts +33 -0
- package/dist/routing/Route.d.ts.map +1 -0
- package/dist/routing/Router.d.ts +124 -0
- package/dist/routing/Router.d.ts.map +1 -0
- package/dist/routing/registerRoute.d.ts +15 -0
- package/dist/routing/registerRoute.d.ts.map +1 -0
- package/dist/routing/setCatchHandler.d.ts +9 -0
- package/dist/routing/setCatchHandler.d.ts.map +1 -0
- package/dist/routing/setDefaultHandler.d.ts +12 -0
- package/dist/routing/setDefaultHandler.d.ts.map +1 -0
- package/dist/routing/unregisterRoute.d.ts +8 -0
- package/dist/routing/unregisterRoute.d.ts.map +1 -0
- package/dist/routing/utils/constants.d.ts +15 -0
- package/dist/routing/utils/constants.d.ts.map +1 -0
- package/dist/routing/utils/getOrCreateDefaultRouter.d.ts +10 -0
- package/dist/routing/utils/getOrCreateDefaultRouter.d.ts.map +1 -0
- package/dist/routing/utils/normalizeHandler.d.ts +10 -0
- package/dist/routing/utils/normalizeHandler.d.ts.map +1 -0
- package/dist/routing/utils/parseRoute.d.ts +5 -0
- package/dist/routing/utils/parseRoute.d.ts.map +1 -0
- package/dist/strategies/CacheFirst.d.ts +23 -0
- package/dist/strategies/CacheFirst.d.ts.map +1 -0
- package/dist/strategies/CacheOnly.d.ts +20 -0
- package/dist/strategies/CacheOnly.d.ts.map +1 -0
- package/dist/strategies/NetworkFirst.d.ts +61 -0
- package/dist/strategies/NetworkFirst.d.ts.map +1 -0
- package/dist/strategies/NetworkOnly.d.ts +32 -0
- package/dist/strategies/NetworkOnly.d.ts.map +1 -0
- package/dist/strategies/StaleWhileRevalidate.d.ts +35 -0
- package/dist/strategies/StaleWhileRevalidate.d.ts.map +1 -0
- package/dist/strategies/Strategy.d.ts +83 -0
- package/dist/strategies/Strategy.d.ts.map +1 -0
- package/dist/strategies/StrategyHandler.d.ts +189 -0
- package/dist/strategies/StrategyHandler.d.ts.map +1 -0
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
- package/dist/strategies/utils/messages.d.ts +5 -0
- package/dist/strategies/utils/messages.d.ts.map +1 -0
- package/package.json +20 -14
- package/src/{Serwist.ts → abstractions/Serwist.ts} +16 -19
- package/src/{fallbacks.ts → abstractions/fallbacks.ts} +5 -5
- package/src/{handlePrecaching.ts → abstractions/handlePrecaching.ts} +6 -3
- package/src/{installSerwist.ts → abstractions/installSerwist.ts} +2 -2
- package/src/{registerRuntimeCaching.ts → abstractions/registerRuntimeCaching.ts} +1 -1
- package/src/{types.ts → abstractions/types.ts} +1 -1
- package/src/index.plugins.ts +65 -16
- package/src/index.precaching.ts +38 -0
- package/src/index.routing.ts +14 -0
- package/src/index.strategies.ts +22 -2
- package/src/index.ts +8 -8
- package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +39 -0
- package/src/plugins/backgroundSync/Queue.ts +438 -0
- package/src/plugins/backgroundSync/QueueDb.ts +176 -0
- package/src/plugins/backgroundSync/QueueStore.ts +161 -0
- package/src/plugins/backgroundSync/StorableRequest.ts +142 -0
- package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +159 -0
- package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +43 -0
- package/src/plugins/broadcastUpdate/constants.ts +12 -0
- package/src/plugins/broadcastUpdate/responsesAreSame.ts +48 -0
- package/src/plugins/broadcastUpdate/types.ts +37 -0
- package/src/plugins/cacheableResponse/CacheableResponse.ts +141 -0
- package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +46 -0
- package/src/plugins/expiration/CacheExpiration.ts +192 -0
- package/src/plugins/expiration/ExpirationPlugin.ts +297 -0
- package/src/plugins/expiration/models/CacheTimestampsModel.ts +184 -0
- package/src/plugins/googleAnalytics/constants.ts +22 -0
- package/src/plugins/googleAnalytics/initialize.ts +200 -0
- package/src/plugins/precaching/PrecacheFallbackPlugin.ts +86 -0
- package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +39 -0
- package/src/plugins/rangeRequests/createPartialResponse.ts +92 -0
- package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +58 -0
- package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +54 -0
- package/src/precaching/PrecacheController.ts +332 -0
- package/src/precaching/PrecacheRoute.ts +50 -0
- package/src/precaching/PrecacheStrategy.ts +238 -0
- package/src/precaching/addPlugins.ts +21 -0
- package/src/precaching/addRoute.ts +30 -0
- package/src/precaching/cleanupOutdatedCaches.ts +33 -0
- package/src/precaching/createHandlerBoundToURL.ts +30 -0
- package/src/precaching/getCacheKeyForURL.ts +33 -0
- package/src/precaching/matchPrecache.ts +26 -0
- package/src/precaching/precache.ts +31 -0
- package/src/precaching/precacheAndRoute.ts +27 -0
- package/src/precaching/types.ts +46 -0
- package/src/precaching/utils/PrecacheCacheKeyPlugin.ts +36 -0
- package/src/precaching/utils/PrecacheInstallReportPlugin.ts +49 -0
- package/src/precaching/utils/createCacheKey.ts +68 -0
- package/src/precaching/utils/deleteOutdatedCaches.ts +40 -0
- package/src/precaching/utils/generateURLVariations.ts +55 -0
- package/src/precaching/utils/getCacheKeyForURL.ts +36 -0
- package/src/precaching/utils/getOrCreatePrecacheController.ts +22 -0
- package/src/precaching/utils/printCleanupDetails.ts +38 -0
- package/src/precaching/utils/printInstallDetails.ts +53 -0
- package/src/precaching/utils/removeIgnoredSearchParams.ts +29 -0
- package/src/routing/NavigationRoute.ts +119 -0
- package/src/routing/RegExpRoute.ts +74 -0
- package/src/routing/Route.ts +68 -0
- package/src/routing/Router.ts +432 -0
- package/src/routing/registerRoute.ts +33 -0
- package/src/routing/setCatchHandler.ts +22 -0
- package/src/routing/setDefaultHandler.ts +25 -0
- package/src/routing/unregisterRoute.ts +12 -0
- package/src/routing/utils/constants.ts +24 -0
- package/src/routing/utils/getOrCreateDefaultRouter.ts +29 -0
- package/src/routing/utils/normalizeHandler.ts +40 -0
- package/src/routing/utils/parseRoute.ts +67 -0
- package/src/strategies/CacheFirst.ts +87 -0
- package/src/strategies/CacheOnly.ts +58 -0
- package/src/strategies/NetworkFirst.ts +228 -0
- package/src/strategies/NetworkOnly.ts +96 -0
- package/src/strategies/StaleWhileRevalidate.ts +109 -0
- package/src/strategies/Strategy.ts +202 -0
- package/src/strategies/StrategyHandler.ts +557 -0
- package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +26 -0
- package/src/strategies/utils/messages.ts +20 -0
- package/dist/Serwist.d.ts.map +0 -1
- package/dist/disableDevLogs.d.ts.map +0 -1
- package/dist/fallbacks.d.ts.map +0 -1
- package/dist/handlePrecaching.d.ts.map +0 -1
- package/dist/installSerwist.d.ts.map +0 -1
- package/dist/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- /package/dist/{disableDevLogs.d.ts → abstractions/disableDevLogs.d.ts} +0 -0
- /package/dist/{installSerwist.d.ts → abstractions/installSerwist.d.ts} +0 -0
- /package/dist/{registerRuntimeCaching.d.ts → abstractions/registerRuntimeCaching.d.ts} +0 -0
- /package/src/{disableDevLogs.ts → abstractions/disableDevLogs.ts} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PrecacheRouteOptions } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* This function will take the request URL and manipulate it based on the
|
|
4
|
+
* configuration options.
|
|
5
|
+
*
|
|
6
|
+
* @param url
|
|
7
|
+
* @param options
|
|
8
|
+
* @returns Returns the URL in the cache that matches the request,
|
|
9
|
+
* if possible.
|
|
10
|
+
*
|
|
11
|
+
* @private
|
|
12
|
+
*/
|
|
13
|
+
export declare const getCacheKeyForURL: (url: string, options: PrecacheRouteOptions) => string | undefined;
|
|
14
|
+
//# sourceMappingURL=getCacheKeyForURL.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCacheKeyForURL.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/getCacheKeyForURL.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAIxD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,QAAS,MAAM,WAAW,oBAAoB,KAAG,MAAM,GAAG,SAYvF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrCreatePrecacheController.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/getOrCreatePrecacheController.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI9D;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAO,kBAKhD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printCleanupDetails.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/printCleanupDetails.ts"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAO/D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printInstallDetails.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/printInstallDetails.ts"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,GAAG,IAAI,CAiBlG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes any URL search parameters that should be ignored.
|
|
3
|
+
*
|
|
4
|
+
* @param urlObject The original URL.
|
|
5
|
+
* @param ignoreURLParametersMatching RegExps to test against
|
|
6
|
+
* each search parameter name. Matches mean that the search parameter should be
|
|
7
|
+
* ignored.
|
|
8
|
+
* @returns The URL with any ignored search parameters removed.
|
|
9
|
+
* @private
|
|
10
|
+
*/
|
|
11
|
+
export declare function removeIgnoredSearchParams(urlObject: URL, ignoreURLParametersMatching?: RegExp[]): URL;
|
|
12
|
+
//# sourceMappingURL=removeIgnoredSearchParams.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeIgnoredSearchParams.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/removeIgnoredSearchParams.ts"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,GAAG,EAAE,2BAA2B,GAAE,MAAM,EAAO,GAAG,GAAG,CAUzG"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NavigationRoute.d.ts","sourceRoot":"","sources":["../../src/routing/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"}
|
|
@@ -0,0 +1,24 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RegExpRoute.d.ts","sourceRoot":"","sources":["../../src/routing/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"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RouteHandler, RouteHandlerObject, RouteMatchCallback } from "@serwist/core";
|
|
2
|
+
import type { HTTPMethod } from "./utils/constants.js";
|
|
3
|
+
/**
|
|
4
|
+
* A `Route` consists of a pair of callback functions, "match" and "handler".
|
|
5
|
+
* The "match" callback determine if a route should be used to "handle" a
|
|
6
|
+
* request by returning a non-falsy value if it can. The "handler" callback
|
|
7
|
+
* is called when there is a match and should return a Promise that resolves
|
|
8
|
+
* to a `Response`.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Route {
|
|
11
|
+
handler: RouteHandlerObject;
|
|
12
|
+
match: RouteMatchCallback;
|
|
13
|
+
method: HTTPMethod;
|
|
14
|
+
catchHandler?: RouteHandlerObject;
|
|
15
|
+
/**
|
|
16
|
+
* Constructor for Route class.
|
|
17
|
+
*
|
|
18
|
+
* @param match A callback function that determines whether the
|
|
19
|
+
* route matches a given `fetch` event by returning a non-falsy value.
|
|
20
|
+
* @param handler A callback function that returns a Promise resolving
|
|
21
|
+
* to a Response.
|
|
22
|
+
* @param method The HTTP method to match the Route against. Defaults
|
|
23
|
+
* to GET.
|
|
24
|
+
*/
|
|
25
|
+
constructor(match: RouteMatchCallback, handler: RouteHandler, method?: HTTPMethod);
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param handler A callback function that returns a Promise resolving
|
|
29
|
+
* to a Response.
|
|
30
|
+
*/
|
|
31
|
+
setCatchHandler(handler: RouteHandler): void;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=Route.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../src/routing/Route.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAG1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD;;;;;;GAMG;AACH,qBAAa,KAAK;IAChB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAElC;;;;;;;;;OASG;gBACS,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAE,UAA0B;IAqBhG;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;CAG7C"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import type { RouteHandler, RouteHandlerCallbackOptions, RouteMatchCallbackOptions } from "@serwist/core";
|
|
2
|
+
import type { Route } from "./Route.js";
|
|
3
|
+
import type { HTTPMethod } from "./utils/constants.js";
|
|
4
|
+
/**
|
|
5
|
+
* The Router can be used to process a `FetchEvent` using one or more `@serwist/routing` Route(s),
|
|
6
|
+
* responding with a `Response` if a matching route exists.
|
|
7
|
+
*
|
|
8
|
+
* If no route matches a given a request, the Router will use a "default" handler if one is defined.
|
|
9
|
+
*
|
|
10
|
+
* Should the matching Route throw an error, the Router will use a "catch" handler if one is defined to
|
|
11
|
+
* gracefully deal with issues and respond with a Request.
|
|
12
|
+
*
|
|
13
|
+
* If a request matches multiple routes, the **earliest** registered route will
|
|
14
|
+
* be used to respond to the request.
|
|
15
|
+
*/
|
|
16
|
+
export declare class Router {
|
|
17
|
+
private readonly _routes;
|
|
18
|
+
private readonly _defaultHandlerMap;
|
|
19
|
+
private _catchHandler?;
|
|
20
|
+
/**
|
|
21
|
+
* Initializes a new Router.
|
|
22
|
+
*/
|
|
23
|
+
constructor();
|
|
24
|
+
/**
|
|
25
|
+
* @returns routes A `Map` of HTTP method name ('GET', etc.) to an array of all the corresponding `Route`
|
|
26
|
+
* instances that are registered.
|
|
27
|
+
*/
|
|
28
|
+
get routes(): Map<HTTPMethod, Route[]>;
|
|
29
|
+
/**
|
|
30
|
+
* Adds a fetch event listener to respond to events when a route matches
|
|
31
|
+
* the event's request.
|
|
32
|
+
*/
|
|
33
|
+
addFetchListener(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Adds a message event listener for URLs to cache from the window.
|
|
36
|
+
* This is useful to cache resources loaded on the page prior to when the
|
|
37
|
+
* service worker started controlling it.
|
|
38
|
+
*
|
|
39
|
+
* The format of the message data sent from the window should be as follows.
|
|
40
|
+
* Where the `urlsToCache` array may consist of URL strings or an array of
|
|
41
|
+
* URL string + `requestInit` object (the same as you'd pass to `fetch()`).
|
|
42
|
+
*
|
|
43
|
+
* ```
|
|
44
|
+
* {
|
|
45
|
+
* type: 'CACHE_URLS',
|
|
46
|
+
* payload: {
|
|
47
|
+
* urlsToCache: [
|
|
48
|
+
* './script1.js',
|
|
49
|
+
* './script2.js',
|
|
50
|
+
* ['./script3.js', {mode: 'no-cors'}],
|
|
51
|
+
* ],
|
|
52
|
+
* },
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
addCacheListener(): void;
|
|
57
|
+
/**
|
|
58
|
+
* Apply the routing rules to a FetchEvent object to get a Response from an
|
|
59
|
+
* appropriate Route's handler.
|
|
60
|
+
*
|
|
61
|
+
* @param options
|
|
62
|
+
* @returns A promise is returned if a registered route can handle the request.
|
|
63
|
+
* If there is no matching route and there's no `defaultHandler`, `undefined`
|
|
64
|
+
* is returned.
|
|
65
|
+
*/
|
|
66
|
+
handleRequest({ request, event, }: {
|
|
67
|
+
/**
|
|
68
|
+
* The request to handle.
|
|
69
|
+
*/
|
|
70
|
+
request: Request;
|
|
71
|
+
/**
|
|
72
|
+
* The event that triggered the request.
|
|
73
|
+
*/
|
|
74
|
+
event: ExtendableEvent;
|
|
75
|
+
}): Promise<Response> | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Checks a request and URL (and optionally an event) against the list of
|
|
78
|
+
* registered routes, and if there's a match, returns the corresponding
|
|
79
|
+
* route along with any params generated by the match.
|
|
80
|
+
*
|
|
81
|
+
* @param options
|
|
82
|
+
* @returns An object with `route` and `params` properties. They are populated
|
|
83
|
+
* if a matching route was found or `undefined` otherwise.
|
|
84
|
+
*/
|
|
85
|
+
findMatchingRoute({ url, sameOrigin, request, event }: RouteMatchCallbackOptions): {
|
|
86
|
+
route?: Route;
|
|
87
|
+
params?: RouteHandlerCallbackOptions["params"];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Define a default `handler` that's called when no routes explicitly
|
|
91
|
+
* match the incoming request.
|
|
92
|
+
*
|
|
93
|
+
* Each HTTP method ('GET', 'POST', etc.) gets its own default handler.
|
|
94
|
+
*
|
|
95
|
+
* Without a default handler, unmatched requests will go against the
|
|
96
|
+
* network as if there were no service worker present.
|
|
97
|
+
*
|
|
98
|
+
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
99
|
+
* @param method The HTTP method to associate with this default handler. Each method
|
|
100
|
+
* has its own default. Defaults to GET.
|
|
101
|
+
*/
|
|
102
|
+
setDefaultHandler(handler: RouteHandler, method?: HTTPMethod): void;
|
|
103
|
+
/**
|
|
104
|
+
* If a Route throws an error while handling a request, this `handler`
|
|
105
|
+
* will be called and given a chance to provide a response.
|
|
106
|
+
*
|
|
107
|
+
* @param handler A callback function that returns a Promise resulting
|
|
108
|
+
* in a Response.
|
|
109
|
+
*/
|
|
110
|
+
setCatchHandler(handler: RouteHandler): void;
|
|
111
|
+
/**
|
|
112
|
+
* Registers a route with the router.
|
|
113
|
+
*
|
|
114
|
+
* @param route The route to register.
|
|
115
|
+
*/
|
|
116
|
+
registerRoute(route: Route): void;
|
|
117
|
+
/**
|
|
118
|
+
* Unregisters a route with the router.
|
|
119
|
+
*
|
|
120
|
+
* @param route The route to unregister.
|
|
121
|
+
*/
|
|
122
|
+
unregisterRoute(route: Route): void;
|
|
123
|
+
}
|
|
124
|
+
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/routing/Router.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAsB,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAG9H,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACxC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAevD;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsC;IACzE,OAAO,CAAC,aAAa,CAAC,CAAqB;IAE3C;;OAEG;;IAMH;;;OAGG;IACH,IAAI,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAErC;IAED;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAUxB;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,gBAAgB,IAAI,IAAI;IA8BxB;;;;;;;;OAQG;IACH,aAAa,CAAC,EACZ,OAAO,EACP,KAAK,GACN,EAAE;QACD;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;WAEG;QACH,KAAK,EAAE,eAAe,CAAC;KACxB,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS;IA8HjC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,yBAAyB,GAAG;QACjF,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,CAAC,EAAE,2BAA2B,CAAC,QAAQ,CAAC,CAAC;KAChD;IA+CD;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAE,UAA0B,GAAG,IAAI;IAIlF;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAI5C;;;;OAIG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IA+CjC;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAcpC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
|
|
2
|
+
import { Route } from "./Route.js";
|
|
3
|
+
import type { HTTPMethod } from "./utils/constants.js";
|
|
4
|
+
/**
|
|
5
|
+
* Registers a RegExp, string, or function with a caching
|
|
6
|
+
* strategy to a singleton Router instance.
|
|
7
|
+
*
|
|
8
|
+
* @param capture If the capture param is a `Route`, all other arguments will be ignored.
|
|
9
|
+
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
10
|
+
* This parameter is required if `capture` is not a `Route` object.
|
|
11
|
+
* @param method The HTTP method to match the Route against. Defaults to GET.
|
|
12
|
+
* @returns The generated `Route`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const registerRoute: (capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod) => Route;
|
|
15
|
+
//# sourceMappingURL=registerRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerRoute.d.ts","sourceRoot":"","sources":["../../src/routing/registerRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,YAAY,YAAY,WAAW,UAAU,KAAG,KAOlI,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { RouteHandler } from "@serwist/core";
|
|
2
|
+
/**
|
|
3
|
+
* If a Route throws an error while handling a request, this `handler`
|
|
4
|
+
* will be called and given a chance to provide a response.
|
|
5
|
+
*
|
|
6
|
+
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
7
|
+
*/
|
|
8
|
+
export declare const setCatchHandler: (handler: RouteHandler) => void;
|
|
9
|
+
//# sourceMappingURL=setCatchHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setCatchHandler.d.ts","sourceRoot":"","sources":["../../src/routing/setCatchHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,YAAa,YAAY,KAAG,IAGvD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { RouteHandler } from "@serwist/core";
|
|
2
|
+
/**
|
|
3
|
+
* Defines a default `handler` that's called when no routes explicitly
|
|
4
|
+
* match the incoming request.
|
|
5
|
+
*
|
|
6
|
+
* Without a default handler, unmatched requests will go against the
|
|
7
|
+
* network as if there were no service worker present.
|
|
8
|
+
*
|
|
9
|
+
* @param handler A callback function that returns a Promise resulting in a Response.
|
|
10
|
+
*/
|
|
11
|
+
export declare const setDefaultHandler: (handler: RouteHandler) => void;
|
|
12
|
+
//# sourceMappingURL=setDefaultHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setDefaultHandler.d.ts","sourceRoot":"","sources":["../../src/routing/setDefaultHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,YAAa,YAAY,KAAG,IAGzD,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Route } from "./Route.js";
|
|
2
|
+
/**
|
|
3
|
+
* Unregisters a route from the singleton Router instance.
|
|
4
|
+
*
|
|
5
|
+
* @param route The route to unregister.
|
|
6
|
+
*/
|
|
7
|
+
export declare const unregisterRoute: (route: Route) => void;
|
|
8
|
+
//# sourceMappingURL=unregisterRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unregisterRoute.d.ts","sourceRoot":"","sources":["../../src/routing/unregisterRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;GAIG;AACH,eAAO,MAAM,eAAe,UAAW,KAAK,KAAG,IAG9C,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type HTTPMethod = "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT";
|
|
2
|
+
/**
|
|
3
|
+
* The default HTTP method, 'GET', used when there's no specific method
|
|
4
|
+
* configured for a route.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
export declare const defaultMethod = "GET";
|
|
9
|
+
/**
|
|
10
|
+
* The list of valid HTTP methods associated with requests that could be routed.
|
|
11
|
+
*
|
|
12
|
+
* @private
|
|
13
|
+
*/
|
|
14
|
+
export declare const validMethods: ("GET" | "DELETE" | "HEAD" | "PATCH" | "POST" | "PUT")[];
|
|
15
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/routing/utils/constants.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAE9E;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAA6B,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,YAAY,0DAA2E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Router } from "../Router.js";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new, singleton Router instance if one does not exist. If one
|
|
4
|
+
* does already exist, that instance is returned.
|
|
5
|
+
*
|
|
6
|
+
* @private
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const getOrCreateDefaultRouter: () => Router;
|
|
10
|
+
//# sourceMappingURL=getOrCreateDefaultRouter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getOrCreateDefaultRouter.d.ts","sourceRoot":"","sources":["../../../src/routing/utils/getOrCreateDefaultRouter.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAItC;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,QAAO,MAS3C,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { RouteHandler, RouteHandlerObject } from "@serwist/core";
|
|
2
|
+
/**
|
|
3
|
+
* @param handler Either a function, or an object with a
|
|
4
|
+
* 'handle' method.
|
|
5
|
+
* @returns An object with a handle method.
|
|
6
|
+
*
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
export declare const normalizeHandler: (handler: RouteHandler) => RouteHandlerObject;
|
|
10
|
+
//# sourceMappingURL=normalizeHandler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeHandler.d.ts","sourceRoot":"","sources":["../../../src/routing/utils/normalizeHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGtE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,YAAa,YAAY,KAAG,kBAqBxD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
|
|
2
|
+
import { Route } from "../Route.js";
|
|
3
|
+
import type { HTTPMethod } from "./constants.js";
|
|
4
|
+
export declare const parseRoute: (capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod) => Route;
|
|
5
|
+
//# sourceMappingURL=parseRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseRoute.d.ts","sourceRoot":"","sources":["../../../src/routing/utils/parseRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAItE,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,UAAU,YAAa,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,YAAY,YAAY,WAAW,UAAU,KAAG,KA2D/H,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Strategy } from "./Strategy.js";
|
|
2
|
+
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
3
|
+
/**
|
|
4
|
+
* An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache_first_falling_back_to_network)
|
|
5
|
+
* request strategy.
|
|
6
|
+
*
|
|
7
|
+
* A cache first strategy is useful for assets that have been revisioned,
|
|
8
|
+
* such as URLs like `/styles/example.a8f5f1.css`, since they
|
|
9
|
+
* can be cached for long periods of time.
|
|
10
|
+
*
|
|
11
|
+
* If the network request fails, and there is no cache match, this will throw
|
|
12
|
+
* a `SerwistError` exception.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CacheFirst extends Strategy {
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
* @param request A request to run this strategy for.
|
|
18
|
+
* @param handler The event that triggered the request.
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
21
|
+
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=CacheFirst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheFirst.d.ts","sourceRoot":"","sources":["../../src/strategies/CacheFirst.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,QAAQ;IACtC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Strategy } from "./Strategy.js";
|
|
2
|
+
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
3
|
+
/**
|
|
4
|
+
* An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-only)
|
|
5
|
+
* request strategy.
|
|
6
|
+
*
|
|
7
|
+
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
8
|
+
*
|
|
9
|
+
* If there is no cache match, this will throw a `SerwistError` exception.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CacheOnly extends Strategy {
|
|
12
|
+
/**
|
|
13
|
+
* @private
|
|
14
|
+
* @param request A request to run this strategy for.
|
|
15
|
+
* @param handler The event that triggered the request.
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=CacheOnly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheOnly.d.ts","sourceRoot":"","sources":["../../src/strategies/CacheOnly.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,QAAQ;IACrC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA4B7E"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { StrategyOptions } from "./Strategy.js";
|
|
2
|
+
import { Strategy } from "./Strategy.js";
|
|
3
|
+
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
4
|
+
export interface NetworkFirstOptions extends StrategyOptions {
|
|
5
|
+
/**
|
|
6
|
+
* If set, any network requests that fail to respond within the timeout will fallback to the cache.
|
|
7
|
+
*/
|
|
8
|
+
networkTimeoutSeconds?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
|
|
12
|
+
* request strategy.
|
|
13
|
+
*
|
|
14
|
+
* By default, this strategy will cache responses with a 200 status code as
|
|
15
|
+
* well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
|
|
16
|
+
* Opaque responses are are cross-origin requests where the response doesn't
|
|
17
|
+
* support [CORS](https://enable-cors.org/).
|
|
18
|
+
*
|
|
19
|
+
* If the network request fails, and there is no cache match, this will throw
|
|
20
|
+
* a `SerwistError` exception.
|
|
21
|
+
*/
|
|
22
|
+
export declare class NetworkFirst extends Strategy {
|
|
23
|
+
private readonly _networkTimeoutSeconds;
|
|
24
|
+
/**
|
|
25
|
+
* @param options
|
|
26
|
+
* This option can be used to combat
|
|
27
|
+
* "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
|
|
28
|
+
* scenarios.
|
|
29
|
+
*/
|
|
30
|
+
constructor(options?: NetworkFirstOptions);
|
|
31
|
+
/**
|
|
32
|
+
* @private
|
|
33
|
+
* @param request A request to run this strategy for.
|
|
34
|
+
* @param handler The event that triggered the request.
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
38
|
+
/**
|
|
39
|
+
* @param options
|
|
40
|
+
* @returns
|
|
41
|
+
* @private
|
|
42
|
+
*/
|
|
43
|
+
private _getTimeoutPromise;
|
|
44
|
+
/**
|
|
45
|
+
* @param options
|
|
46
|
+
* @param options.timeoutId
|
|
47
|
+
* @param options.request
|
|
48
|
+
* @param options.logs A reference to the logs Array.
|
|
49
|
+
* @param options.event
|
|
50
|
+
* @returns
|
|
51
|
+
*
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
_getNetworkPromise({ timeoutId, request, logs, handler, }: {
|
|
55
|
+
request: Request;
|
|
56
|
+
logs: any[];
|
|
57
|
+
timeoutId?: number;
|
|
58
|
+
handler: StrategyHandler;
|
|
59
|
+
}): Promise<Response | undefined>;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=NetworkFirst.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkFirst.d.ts","sourceRoot":"","sources":["../../src/strategies/NetworkFirst.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAChD;;;;;OAKG;gBACS,OAAO,GAAE,mBAAwB;IAsB7C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgE5E;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;;;;;;;;OASG;IACG,kBAAkB,CAAC,EACvB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAqClC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { StrategyOptions } from "./Strategy.js";
|
|
2
|
+
import { Strategy } from "./Strategy.js";
|
|
3
|
+
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
4
|
+
export interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" | "matchOptions"> {
|
|
5
|
+
/**
|
|
6
|
+
* If set, any network requests that fail to respond within the timeout will result in a network error.
|
|
7
|
+
*/
|
|
8
|
+
networkTimeoutSeconds?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
|
|
12
|
+
* request strategy.
|
|
13
|
+
*
|
|
14
|
+
* This class is useful if you want to take advantage of any Serwist plugin.
|
|
15
|
+
*
|
|
16
|
+
* If the network request fails, this will throw a `SerwistError` exception.
|
|
17
|
+
*/
|
|
18
|
+
export declare class NetworkOnly extends Strategy {
|
|
19
|
+
private readonly _networkTimeoutSeconds;
|
|
20
|
+
/**
|
|
21
|
+
* @param options
|
|
22
|
+
*/
|
|
23
|
+
constructor(options?: NetworkOnlyOptions);
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
* @param request A request to run this strategy for.
|
|
27
|
+
* @param handler The event that triggered the request.
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=NetworkOnly.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NetworkOnly.d.ts","sourceRoot":"","sources":["../../src/strategies/NetworkOnly.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,cAAc,CAAC;IAC7F;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,QAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;OAEG;gBACS,OAAO,GAAE,kBAAuB;IAM5C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA+C7E"}
|