serwist 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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/NavigationRoute.d.ts +57 -0
- package/dist/NavigationRoute.d.ts.map +1 -0
- package/dist/PrecacheRoute.d.ts +17 -0
- package/dist/PrecacheRoute.d.ts.map +1 -0
- package/dist/PrecacheStrategy.d.ts +66 -0
- package/dist/PrecacheStrategy.d.ts.map +1 -0
- package/dist/RegExpRoute.d.ts +24 -0
- package/dist/RegExpRoute.d.ts.map +1 -0
- package/dist/Route.d.ts +33 -0
- package/dist/Route.d.ts.map +1 -0
- package/dist/Serwist.d.ts +331 -0
- package/dist/Serwist.d.ts.map +1 -0
- package/dist/cacheNames.d.ts +20 -0
- package/dist/cacheNames.d.ts.map +1 -0
- package/dist/chunks/NetworkOnly.js +599 -0
- package/dist/chunks/PrecacheFallbackPlugin.js +634 -0
- package/dist/chunks/Serwist.js +1034 -0
- package/dist/chunks/registerQuotaErrorCallback.js +17 -0
- package/dist/chunks/resultingClientExists.js +32 -0
- package/dist/chunks/timeout.js +400 -0
- package/dist/chunks/waitUntil.js +24 -0
- package/dist/cleanupOutdatedCaches.d.ts +6 -0
- package/dist/cleanupOutdatedCaches.d.ts.map +1 -0
- package/dist/clientsClaim.d.ts +6 -0
- package/dist/clientsClaim.d.ts.map +1 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/copyResponse.d.ts +20 -0
- package/dist/copyResponse.d.ts.map +1 -0
- package/dist/disableDevLogs.d.ts +7 -0
- package/dist/disableDevLogs.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.internal.d.ts +16 -0
- package/dist/index.internal.d.ts.map +1 -0
- package/dist/index.internal.js +24 -0
- package/dist/index.js +27 -0
- package/dist/index.legacy.d.ts +32 -0
- package/dist/index.legacy.d.ts.map +1 -0
- package/dist/index.legacy.js +640 -0
- package/dist/index.plugins.d.ts +41 -0
- package/dist/index.plugins.d.ts.map +1 -0
- package/dist/index.plugins.js +669 -0
- package/dist/index.strategies.d.ts +22 -0
- package/dist/index.strategies.d.ts.map +1 -0
- package/dist/index.strategies.js +144 -0
- package/dist/legacy/PrecacheController.d.ts +146 -0
- package/dist/legacy/PrecacheController.d.ts.map +1 -0
- package/dist/legacy/PrecacheFallbackPlugin.d.ts +62 -0
- package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +1 -0
- package/dist/legacy/PrecacheRoute.d.ts +19 -0
- package/dist/legacy/PrecacheRoute.d.ts.map +1 -0
- package/dist/legacy/Router.d.ts +151 -0
- package/dist/legacy/Router.d.ts.map +1 -0
- package/dist/legacy/addPlugins.d.ts +9 -0
- package/dist/legacy/addPlugins.d.ts.map +1 -0
- package/dist/legacy/addRoute.d.ts +16 -0
- package/dist/legacy/addRoute.d.ts.map +1 -0
- package/dist/legacy/createHandlerBoundToURL.d.ts +18 -0
- package/dist/legacy/createHandlerBoundToURL.d.ts.map +1 -0
- package/dist/legacy/fallbacks.d.ts +59 -0
- package/dist/legacy/fallbacks.d.ts.map +1 -0
- package/dist/legacy/getCacheKeyForURL.d.ts +20 -0
- package/dist/legacy/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/legacy/handlePrecaching.d.ts +54 -0
- package/dist/legacy/handlePrecaching.d.ts.map +1 -0
- package/dist/legacy/installSerwist.d.ts +15 -0
- package/dist/legacy/installSerwist.d.ts.map +1 -0
- package/dist/legacy/matchPrecache.d.ts +15 -0
- package/dist/legacy/matchPrecache.d.ts.map +1 -0
- package/dist/legacy/precache.d.ts +20 -0
- package/dist/legacy/precache.d.ts.map +1 -0
- package/dist/legacy/precacheAndRoute.d.ts +15 -0
- package/dist/legacy/precacheAndRoute.d.ts.map +1 -0
- package/dist/legacy/registerRoute.d.ts +16 -0
- package/dist/legacy/registerRoute.d.ts.map +1 -0
- package/dist/legacy/registerRuntimeCaching.d.ts +11 -0
- package/dist/legacy/registerRuntimeCaching.d.ts.map +1 -0
- package/dist/legacy/setCatchHandler.d.ts +10 -0
- package/dist/legacy/setCatchHandler.d.ts.map +1 -0
- package/dist/legacy/setDefaultHandler.d.ts +13 -0
- package/dist/legacy/setDefaultHandler.d.ts.map +1 -0
- package/dist/legacy/singletonPrecacheController.d.ts +34 -0
- package/dist/legacy/singletonPrecacheController.d.ts.map +1 -0
- package/dist/legacy/singletonRouter.d.ts +41 -0
- package/dist/legacy/singletonRouter.d.ts.map +1 -0
- package/dist/legacy/unregisterRoute.d.ts +9 -0
- package/dist/legacy/unregisterRoute.d.ts.map +1 -0
- package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts +16 -0
- package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/legacy/utils/getCacheKeyForURL.d.ts +14 -0
- package/dist/legacy/utils/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/models/messages/messageGenerator.d.ts +4 -0
- package/dist/models/messages/messageGenerator.d.ts.map +1 -0
- package/dist/models/messages/messages.d.ts +44 -0
- package/dist/models/messages/messages.d.ts.map +1 -0
- package/dist/models/pluginEvents.d.ts +10 -0
- package/dist/models/pluginEvents.d.ts.map +1 -0
- package/dist/models/quotaErrorCallbacks.d.ts +3 -0
- package/dist/models/quotaErrorCallbacks.d.ts.map +1 -0
- package/dist/navigationPreload.d.ts +24 -0
- package/dist/navigationPreload.d.ts.map +1 -0
- package/dist/parseRoute.d.ts +16 -0
- package/dist/parseRoute.d.ts.map +1 -0
- 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 +30 -0
- package/dist/plugins/googleAnalytics/initialize.d.ts.map +1 -0
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +53 -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/registerQuotaErrorCallback.d.ts +8 -0
- package/dist/registerQuotaErrorCallback.d.ts.map +1 -0
- package/dist/setCacheNameDetails.d.ts +9 -0
- package/dist/setCacheNameDetails.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/dist/types.d.ts +317 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/Deferred.d.ts +19 -0
- package/dist/utils/Deferred.d.ts.map +1 -0
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts +16 -0
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/utils/PrecacheInstallReportPlugin.d.ts +14 -0
- package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
- package/dist/utils/SerwistError.d.ts +24 -0
- package/dist/utils/SerwistError.d.ts.map +1 -0
- package/dist/utils/assert.d.ts +11 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/cacheMatchIgnoreParams.d.ts +15 -0
- package/dist/utils/cacheMatchIgnoreParams.d.ts.map +1 -0
- package/dist/utils/cacheNames.d.ts +40 -0
- package/dist/utils/cacheNames.d.ts.map +1 -0
- package/dist/utils/canConstructReadableStream.d.ts +12 -0
- package/dist/utils/canConstructReadableStream.d.ts.map +1 -0
- package/dist/utils/canConstructResponseFromBodyStream.d.ts +11 -0
- package/dist/utils/canConstructResponseFromBodyStream.d.ts.map +1 -0
- package/dist/utils/createCacheKey.d.ts +16 -0
- package/dist/utils/createCacheKey.d.ts.map +1 -0
- package/dist/utils/deleteOutdatedCaches.d.ts +18 -0
- package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -0
- package/dist/utils/dontWaitFor.d.ts +7 -0
- package/dist/utils/dontWaitFor.d.ts.map +1 -0
- package/dist/utils/executeQuotaErrorCallbacks.d.ts +8 -0
- package/dist/utils/executeQuotaErrorCallbacks.d.ts.map +1 -0
- package/dist/utils/generateURLVariations.d.ts +12 -0
- package/dist/utils/generateURLVariations.d.ts.map +1 -0
- package/dist/utils/getFriendlyURL.d.ts +3 -0
- package/dist/utils/getFriendlyURL.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/normalizeHandler.d.ts +10 -0
- package/dist/utils/normalizeHandler.d.ts.map +1 -0
- package/dist/utils/pluginUtils.d.ts +5 -0
- package/dist/utils/pluginUtils.d.ts.map +1 -0
- package/dist/utils/printCleanupDetails.d.ts +6 -0
- package/dist/utils/printCleanupDetails.d.ts.map +1 -0
- package/dist/utils/printInstallDetails.d.ts +7 -0
- package/dist/utils/printInstallDetails.d.ts.map +1 -0
- package/dist/utils/removeIgnoredSearchParams.d.ts +12 -0
- package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -0
- package/dist/utils/resultingClientExists.d.ts +12 -0
- package/dist/utils/resultingClientExists.d.ts.map +1 -0
- package/dist/utils/timeout.d.ts +10 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/waitUntil.d.ts +11 -0
- package/dist/utils/waitUntil.d.ts.map +1 -0
- package/dist/utils/welcome.d.ts +2 -0
- package/dist/utils/welcome.d.ts.map +1 -0
- package/package.json +85 -0
- package/src/NavigationRoute.ts +119 -0
- package/src/PrecacheRoute.ts +46 -0
- package/src/PrecacheStrategy.ts +239 -0
- package/src/RegExpRoute.ts +74 -0
- package/src/Route.ts +67 -0
- package/src/Serwist.ts +920 -0
- package/src/cacheNames.ts +39 -0
- package/src/cleanupOutdatedCaches.ts +32 -0
- package/src/clientsClaim.ts +18 -0
- package/src/constants.ts +24 -0
- package/src/copyResponse.ts +60 -0
- package/src/disableDevLogs.ts +10 -0
- package/src/index.internal.ts +33 -0
- package/src/index.legacy.ts +66 -0
- package/src/index.plugins.ts +95 -0
- package/src/index.strategies.ts +26 -0
- package/src/index.ts +39 -0
- package/src/legacy/PrecacheController.ts +337 -0
- package/src/legacy/PrecacheFallbackPlugin.ts +93 -0
- package/src/legacy/PrecacheRoute.ts +48 -0
- package/src/legacy/Router.ts +484 -0
- package/src/legacy/addPlugins.ts +21 -0
- package/src/legacy/addRoute.ts +29 -0
- package/src/legacy/createHandlerBoundToURL.ts +30 -0
- package/src/legacy/fallbacks.ts +94 -0
- package/src/legacy/getCacheKeyForURL.ts +32 -0
- package/src/legacy/handlePrecaching.ts +86 -0
- package/src/legacy/installSerwist.ts +19 -0
- package/src/legacy/matchPrecache.ts +26 -0
- package/src/legacy/precache.ts +31 -0
- package/src/legacy/precacheAndRoute.ts +28 -0
- package/src/legacy/registerRoute.ts +27 -0
- package/src/legacy/registerRuntimeCaching.ts +17 -0
- package/src/legacy/setCatchHandler.ts +21 -0
- package/src/legacy/setDefaultHandler.ts +24 -0
- package/src/legacy/singletonPrecacheController.ts +53 -0
- package/src/legacy/singletonRouter.ts +70 -0
- package/src/legacy/unregisterRoute.ts +12 -0
- package/src/legacy/utils/PrecacheCacheKeyPlugin.ts +33 -0
- package/src/legacy/utils/getCacheKeyForURL.ts +36 -0
- package/src/models/messages/messageGenerator.ts +29 -0
- package/src/models/messages/messages.ts +233 -0
- package/src/models/pluginEvents.ts +17 -0
- package/src/models/quotaErrorCallbacks.ts +13 -0
- package/src/navigationPreload.ts +68 -0
- package/src/parseRoute.ts +78 -0
- package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +38 -0
- package/src/plugins/backgroundSync/Queue.ts +440 -0
- package/src/plugins/backgroundSync/QueueDb.ts +176 -0
- package/src/plugins/backgroundSync/QueueStore.ts +160 -0
- package/src/plugins/backgroundSync/StorableRequest.ts +142 -0
- package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +161 -0
- package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +42 -0
- package/src/plugins/broadcastUpdate/constants.ts +12 -0
- package/src/plugins/broadcastUpdate/responsesAreSame.ts +49 -0
- package/src/plugins/broadcastUpdate/types.ts +37 -0
- package/src/plugins/cacheableResponse/CacheableResponse.ts +144 -0
- package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +45 -0
- package/src/plugins/expiration/CacheExpiration.ts +193 -0
- package/src/plugins/expiration/ExpirationPlugin.ts +300 -0
- package/src/plugins/expiration/models/CacheTimestampsModel.ts +184 -0
- package/src/plugins/googleAnalytics/constants.ts +22 -0
- package/src/plugins/googleAnalytics/initialize.ts +209 -0
- package/src/plugins/precaching/PrecacheFallbackPlugin.ts +83 -0
- package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +38 -0
- package/src/plugins/rangeRequests/createPartialResponse.ts +93 -0
- package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +59 -0
- package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +55 -0
- package/src/registerQuotaErrorCallback.ts +34 -0
- package/src/setCacheNameDetails.ts +53 -0
- package/src/strategies/CacheFirst.ts +88 -0
- package/src/strategies/CacheOnly.ts +59 -0
- package/src/strategies/NetworkFirst.ts +229 -0
- package/src/strategies/NetworkOnly.ts +98 -0
- package/src/strategies/StaleWhileRevalidate.ts +110 -0
- package/src/strategies/Strategy.ts +204 -0
- package/src/strategies/StrategyHandler.ts +554 -0
- package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +26 -0
- package/src/strategies/utils/messages.ts +21 -0
- package/src/types.ts +358 -0
- package/src/utils/Deferred.ts +33 -0
- package/src/utils/PrecacheCacheKeyPlugin.ts +33 -0
- package/src/utils/PrecacheInstallReportPlugin.ts +47 -0
- package/src/utils/SerwistError.ts +41 -0
- package/src/utils/assert.ts +89 -0
- package/src/utils/cacheMatchIgnoreParams.ts +54 -0
- package/src/utils/cacheNames.ts +87 -0
- package/src/utils/canConstructReadableStream.ts +34 -0
- package/src/utils/canConstructResponseFromBodyStream.ts +37 -0
- package/src/utils/createCacheKey.ts +68 -0
- package/src/utils/deleteOutdatedCaches.ts +40 -0
- package/src/utils/dontWaitFor.ts +16 -0
- package/src/utils/executeQuotaErrorCallbacks.ts +33 -0
- package/src/utils/generateURLVariations.ts +55 -0
- package/src/utils/getFriendlyURL.ts +16 -0
- package/src/utils/logger.ts +95 -0
- package/src/utils/normalizeHandler.ts +40 -0
- package/src/utils/pluginUtils.ts +15 -0
- package/src/utils/printCleanupDetails.ts +38 -0
- package/src/utils/printInstallDetails.ts +53 -0
- package/src/utils/removeIgnoredSearchParams.ts +29 -0
- package/src/utils/resultingClientExists.ts +58 -0
- package/src/utils/timeout.ts +19 -0
- package/src/utils/waitUntil.ts +21 -0
- package/src/utils/welcome.ts +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 Google LLC, 2019 ShadowWalker w@weiw.io https://weiw.io, 2023 Serwist
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This module's documentation can be found at https://serwist.pages.dev/docs/serwist
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { RouteHandler } from "./types.js";
|
|
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 `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/NavigationRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAA6B,MAAM,YAAY,CAAC;AAG1E,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,17 @@
|
|
|
1
|
+
import { Route } from "./Route.js";
|
|
2
|
+
import type { Serwist } from "./Serwist.js";
|
|
3
|
+
import type { PrecacheRouteOptions } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* A subclass of `Route` that takes a `serwist.Serwist` instance and uses it to match
|
|
6
|
+
* incoming requests and handle fetching responses from the precache.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PrecacheRoute extends Route {
|
|
9
|
+
/**
|
|
10
|
+
* @param serwist A `PrecacheController`
|
|
11
|
+
* instance used to both match requests and respond to fetch events.
|
|
12
|
+
* @param options Options to control how requests are matched
|
|
13
|
+
* against the list of precached URLs.
|
|
14
|
+
*/
|
|
15
|
+
constructor(serwist: Serwist, options?: PrecacheRouteOptions);
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=PrecacheRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrecacheRoute.d.ts","sourceRoot":"","sources":["../src/PrecacheRoute.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGvD;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC;;;;;OAKG;gBACS,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,oBAAoB;CAkB7D"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SerwistPlugin } from "./types.js";
|
|
2
|
+
import type { StrategyOptions } from "./strategies/Strategy.js";
|
|
3
|
+
import { Strategy } from "./strategies/Strategy.js";
|
|
4
|
+
import type { StrategyHandler } from "./strategies/StrategyHandler.js";
|
|
5
|
+
interface PrecacheStrategyOptions extends StrategyOptions {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to attempt to get the response from the network
|
|
8
|
+
* if there's a precache miss.
|
|
9
|
+
*/
|
|
10
|
+
fallbackToNetwork?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A `serwist/strategies.Strategy` implementation
|
|
14
|
+
* specifically designed to both cache and fetch precached assets.
|
|
15
|
+
*
|
|
16
|
+
* Note: an instance of this class is created automatically when creating a
|
|
17
|
+
* `PrecacheController`; it's generally not necessary to create this yourself.
|
|
18
|
+
*/
|
|
19
|
+
export declare class PrecacheStrategy extends Strategy {
|
|
20
|
+
private readonly _fallbackToNetwork;
|
|
21
|
+
static readonly defaultPrecacheCacheabilityPlugin: SerwistPlugin;
|
|
22
|
+
static readonly copyRedirectedCacheableResponsesPlugin: SerwistPlugin;
|
|
23
|
+
/**
|
|
24
|
+
* @param options
|
|
25
|
+
*/
|
|
26
|
+
constructor(options?: PrecacheStrategyOptions);
|
|
27
|
+
/**
|
|
28
|
+
* @private
|
|
29
|
+
* @param request A request to run this strategy for.
|
|
30
|
+
* @param handler The event that triggered the request.
|
|
31
|
+
* @returns
|
|
32
|
+
*/
|
|
33
|
+
_handle(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
34
|
+
_handleFetch(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
35
|
+
_handleInstall(request: Request, handler: StrategyHandler): Promise<Response>;
|
|
36
|
+
/**
|
|
37
|
+
* This method is complex, as there a number of things to account for:
|
|
38
|
+
*
|
|
39
|
+
* The `plugins` array can be set at construction, and/or it might be added to
|
|
40
|
+
* to at any time before the strategy is used.
|
|
41
|
+
*
|
|
42
|
+
* At the time the strategy is used (i.e. during an `install` event), there
|
|
43
|
+
* needs to be at least one plugin that implements `cacheWillUpdate` in the
|
|
44
|
+
* array, other than `copyRedirectedCacheableResponsesPlugin`.
|
|
45
|
+
*
|
|
46
|
+
* - If this method is called and there are no suitable `cacheWillUpdate`
|
|
47
|
+
* plugins, we need to add `defaultPrecacheCacheabilityPlugin`.
|
|
48
|
+
*
|
|
49
|
+
* - If this method is called and there is exactly one `cacheWillUpdate`, then
|
|
50
|
+
* we don't have to do anything (this might be a previously added
|
|
51
|
+
* `defaultPrecacheCacheabilityPlugin`, or it might be a custom plugin).
|
|
52
|
+
*
|
|
53
|
+
* - If this method is called and there is more than one `cacheWillUpdate`,
|
|
54
|
+
* then we need to check if one is `defaultPrecacheCacheabilityPlugin`. If so,
|
|
55
|
+
* we need to remove it. (This situation is unlikely, but it could happen if
|
|
56
|
+
* the strategy is used multiple times, the first without a `cacheWillUpdate`,
|
|
57
|
+
* and then later on after manually adding a custom `cacheWillUpdate`.)
|
|
58
|
+
*
|
|
59
|
+
* See https://github.com/GoogleChrome/workbox/issues/2737 for more context.
|
|
60
|
+
*
|
|
61
|
+
* @private
|
|
62
|
+
*/
|
|
63
|
+
_useDefaultCacheabilityPluginIfNeeded(): void;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=PrecacheStrategy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrecacheStrategy.d.ts","sourceRoot":"","sources":["../src/PrecacheStrategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,UAAU,uBAAwB,SAAQ,eAAe;IACvD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAU;IAE7C,MAAM,CAAC,QAAQ,CAAC,iCAAiC,EAAE,aAAa,CAQ9D;IAEF,MAAM,CAAC,QAAQ,CAAC,sCAAsC,EAAE,aAAa,CAInE;IAEF;;OAEG;gBACS,OAAO,GAAE,uBAA4B;IAajD;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiBtE,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAwE3E,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAoBnF;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,qCAAqC,IAAI,IAAI;CA4B9C"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RouteHandler } from "./types.js";
|
|
2
|
+
import { Route } from "./Route.js";
|
|
3
|
+
import type { HTTPMethod } from "./constants.js";
|
|
4
|
+
/**
|
|
5
|
+
* `RegExpRoute` makes it easy to create a regular expression based on a `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/RegExpRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAiD,MAAM,YAAY,CAAC;AAG9F,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;;;;;;;OASG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,UAAU;CAyCvE"}
|
package/dist/Route.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { RouteHandler, RouteHandlerObject, RouteMatchCallback } from "./types.js";
|
|
2
|
+
import type { HTTPMethod } from "./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/Route.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEvF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAIjD;;;;;;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,331 @@
|
|
|
1
|
+
import type { RouteHandler, RouteHandlerCallback, RouteHandlerCallbackOptions, RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "./types.js";
|
|
2
|
+
import type { Route } from "./Route.js";
|
|
3
|
+
import { type HTTPMethod } from "./constants.js";
|
|
4
|
+
import { type GoogleAnalyticsInitializeOptions } from "./plugins/googleAnalytics/initialize.js";
|
|
5
|
+
import { type PrecacheFallbackEntry } from "./plugins/precaching/PrecacheFallbackPlugin.js";
|
|
6
|
+
import { Strategy } from "./strategies/Strategy.js";
|
|
7
|
+
import type { PrecacheRouteOptions, RuntimeCaching } from "./types.js";
|
|
8
|
+
import type { CleanupResult, InstallResult, PrecacheEntry } from "./types.js";
|
|
9
|
+
export interface FallbackEntry extends PrecacheFallbackEntry {
|
|
10
|
+
}
|
|
11
|
+
export interface FallbacksOptions {
|
|
12
|
+
/**
|
|
13
|
+
* A list of fallback entries.
|
|
14
|
+
*/
|
|
15
|
+
entries: FallbackEntry[];
|
|
16
|
+
}
|
|
17
|
+
export interface PrecacheOptions extends PrecacheRouteOptions {
|
|
18
|
+
/**
|
|
19
|
+
* The cache to use for precaching.
|
|
20
|
+
*/
|
|
21
|
+
cacheName?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface SerwistOptions {
|
|
24
|
+
/**
|
|
25
|
+
* A list of URLs that should be cached.
|
|
26
|
+
*/
|
|
27
|
+
precacheEntries?: (PrecacheEntry | string)[];
|
|
28
|
+
/**
|
|
29
|
+
* Options to customize how Serwist precaches the URLs in the precache list.
|
|
30
|
+
*/
|
|
31
|
+
precacheOptions?: PrecacheOptions;
|
|
32
|
+
/**
|
|
33
|
+
* Whether outdated caches should be removed.
|
|
34
|
+
*
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
cleanupOutdatedCaches?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* An URL that should point to a HTML file with which navigation requests for URLs that aren't
|
|
40
|
+
* precached will be fulfilled.
|
|
41
|
+
*/
|
|
42
|
+
navigateFallback?: string;
|
|
43
|
+
/**
|
|
44
|
+
* URLs that should be allowed to use the `navigateFallback` handler.
|
|
45
|
+
*/
|
|
46
|
+
navigateFallbackAllowlist?: RegExp[];
|
|
47
|
+
/**
|
|
48
|
+
* URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
|
|
49
|
+
* over `navigateFallbackAllowlist`.
|
|
50
|
+
*/
|
|
51
|
+
navigateFallbackDenylist?: RegExp[];
|
|
52
|
+
/**
|
|
53
|
+
* Plugins to use when precaching as well as responding to fetch
|
|
54
|
+
* events for precached assets.
|
|
55
|
+
*/
|
|
56
|
+
plugins?: SerwistPlugin[];
|
|
57
|
+
/**
|
|
58
|
+
* Whether to attempt to get the response from the network if there's
|
|
59
|
+
* a precache miss.
|
|
60
|
+
*/
|
|
61
|
+
fallbackToNetwork?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* The number of precache requests that should be made concurrently.
|
|
64
|
+
*
|
|
65
|
+
* @default 1
|
|
66
|
+
*/
|
|
67
|
+
concurrentPrecaching?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Forces the waiting service worker to become the active one.
|
|
70
|
+
*
|
|
71
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
|
|
72
|
+
*/
|
|
73
|
+
skipWaiting?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Imports external scripts. They are executed in the order they
|
|
76
|
+
* are passed.
|
|
77
|
+
*
|
|
78
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
|
|
79
|
+
*/
|
|
80
|
+
importScripts?: string[];
|
|
81
|
+
/**
|
|
82
|
+
* Enables navigation preloading if it is supported.
|
|
83
|
+
*
|
|
84
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/navigationPreload
|
|
85
|
+
*/
|
|
86
|
+
navigationPreload?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Modifies the prefix of the default cache names used by Serwist packages.
|
|
89
|
+
*/
|
|
90
|
+
cacheId?: string | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Claims any currently available clients once the service worker
|
|
93
|
+
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
94
|
+
*
|
|
95
|
+
* @default false
|
|
96
|
+
*/
|
|
97
|
+
clientsClaim?: boolean;
|
|
98
|
+
/**
|
|
99
|
+
* A list of caching strategies.
|
|
100
|
+
*
|
|
101
|
+
* @see https://serwist.pages.dev/docs/sw/runtime-caching
|
|
102
|
+
*/
|
|
103
|
+
runtimeCaching?: RuntimeCaching[];
|
|
104
|
+
/**
|
|
105
|
+
* Your configuration for `@serwist/google-analytics`. This plugin is
|
|
106
|
+
* only initialized when this option is not `undefined` or `false`.
|
|
107
|
+
*/
|
|
108
|
+
offlineAnalyticsConfig?: Omit<GoogleAnalyticsInitializeOptions, "serwist"> | boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Disables Serwist's logging in development mode.
|
|
111
|
+
*
|
|
112
|
+
* @default false
|
|
113
|
+
*/
|
|
114
|
+
disableDevLogs?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Precaches routes so that they can be used as a fallback when
|
|
117
|
+
* a Strategy fails to generate a response.
|
|
118
|
+
*
|
|
119
|
+
* Note: This option mutates `runtimeCaching`. It also precaches the URLs
|
|
120
|
+
* defined in `entries`, so you must NOT precache any of them beforehand.
|
|
121
|
+
*
|
|
122
|
+
* @see https://serwist.pages.dev/docs/sw/abstractions/fallbacks
|
|
123
|
+
*/
|
|
124
|
+
fallbacks?: FallbacksOptions;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* A class that helps bootstrap the service worker.
|
|
128
|
+
*/
|
|
129
|
+
export declare class Serwist {
|
|
130
|
+
private readonly _urlsToCacheKeys;
|
|
131
|
+
private readonly _urlsToCacheModes;
|
|
132
|
+
private readonly _cacheKeysToIntegrities;
|
|
133
|
+
private _concurrentPrecaching;
|
|
134
|
+
private readonly _precacheStrategy;
|
|
135
|
+
private readonly _routes;
|
|
136
|
+
private readonly _defaultHandlerMap;
|
|
137
|
+
private _catchHandler?;
|
|
138
|
+
constructor({ precacheEntries, precacheOptions, cleanupOutdatedCaches, navigateFallback, navigateFallbackAllowlist, navigateFallbackDenylist, plugins, fallbackToNetwork, concurrentPrecaching, skipWaiting, importScripts, navigationPreload, cacheId, clientsClaim, runtimeCaching, offlineAnalyticsConfig, disableDevLogs, fallbacks, }?: SerwistOptions);
|
|
139
|
+
/**
|
|
140
|
+
* The strategy created by this controller and
|
|
141
|
+
* used to cache assets and respond to fetch events.
|
|
142
|
+
*/
|
|
143
|
+
get precacheStrategy(): Strategy;
|
|
144
|
+
/**
|
|
145
|
+
* A `Map` of HTTP method name (`'GET'`, etc.) to an array of all the corresponding `Route`
|
|
146
|
+
* instances that are registered.
|
|
147
|
+
*/
|
|
148
|
+
get routes(): Map<HTTPMethod, Route[]>;
|
|
149
|
+
/**
|
|
150
|
+
* This function adds Serwist's event listeners for you. Before calling it, add your own listeners
|
|
151
|
+
* should you need to.
|
|
152
|
+
*/
|
|
153
|
+
addEventListeners(): void;
|
|
154
|
+
/**
|
|
155
|
+
* This method will add items to the precache list, removing duplicates
|
|
156
|
+
* and ensuring the information is valid.
|
|
157
|
+
*
|
|
158
|
+
* @param entries Array of entries to precache.
|
|
159
|
+
*/
|
|
160
|
+
addToPrecacheList(entries: (PrecacheEntry | string)[]): void;
|
|
161
|
+
/**
|
|
162
|
+
* Precaches new and updated assets. Call this method from the service worker's
|
|
163
|
+
* `install` event.
|
|
164
|
+
*
|
|
165
|
+
* Note: this method calls `event.waitUntil()` for you, so you do not need
|
|
166
|
+
* to call it yourself in your event handlers.
|
|
167
|
+
*
|
|
168
|
+
* @param event
|
|
169
|
+
* @returns
|
|
170
|
+
*/
|
|
171
|
+
handleInstall(event: ExtendableEvent): Promise<InstallResult>;
|
|
172
|
+
/**
|
|
173
|
+
* Deletes assets that are no longer present in the current precache manifest.
|
|
174
|
+
* Call this method from the service worker's `activate` event.
|
|
175
|
+
*
|
|
176
|
+
* Note: this method calls `event.waitUntil()` for you, so you do not need
|
|
177
|
+
* to call it yourself in your event handlers.
|
|
178
|
+
*
|
|
179
|
+
* @param event
|
|
180
|
+
* @returns
|
|
181
|
+
*/
|
|
182
|
+
handleActivate(event: ExtendableEvent): Promise<CleanupResult>;
|
|
183
|
+
/**
|
|
184
|
+
* Gets a `Response` from an appropriate `Route`'s handler. Call this method
|
|
185
|
+
* from the service worker's `fetch` event.
|
|
186
|
+
* @param event
|
|
187
|
+
*/
|
|
188
|
+
handleFetch(event: FetchEvent): void;
|
|
189
|
+
/**
|
|
190
|
+
* Caches new URLs on demand. Call this method from the service worker's
|
|
191
|
+
* `message` event. To trigger the handler, send a message of type `"CACHE_URLS"`
|
|
192
|
+
* alongside a list of URLs that should be cached as `urlsToCache`.
|
|
193
|
+
* @param event
|
|
194
|
+
*/
|
|
195
|
+
handleCache(event: ExtendableMessageEvent): void;
|
|
196
|
+
/**
|
|
197
|
+
* Define a default `handler` that's called when no routes explicitly
|
|
198
|
+
* match the incoming request.
|
|
199
|
+
*
|
|
200
|
+
* Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
|
|
201
|
+
*
|
|
202
|
+
* Without a default handler, unmatched requests will go against the
|
|
203
|
+
* network as if there were no service worker present.
|
|
204
|
+
*
|
|
205
|
+
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
206
|
+
* @param method The HTTP method to associate with this default handler. Each method
|
|
207
|
+
* has its own default. Defaults to `'GET'`.
|
|
208
|
+
*/
|
|
209
|
+
setDefaultHandler(handler: RouteHandler, method?: HTTPMethod): void;
|
|
210
|
+
/**
|
|
211
|
+
* If a `Route` throws an error while handling a request, this `handler`
|
|
212
|
+
* will be called and given a chance to provide a response.
|
|
213
|
+
*
|
|
214
|
+
* @param handler A callback function that returns a Promise resulting
|
|
215
|
+
* in a Response.
|
|
216
|
+
*/
|
|
217
|
+
setCatchHandler(handler: RouteHandler): void;
|
|
218
|
+
/**
|
|
219
|
+
* Registers a `RegExp`, string, or function with a caching
|
|
220
|
+
* strategy to the `Router`.
|
|
221
|
+
*
|
|
222
|
+
* @param capture If the capture param is a `Route`, all other arguments will be ignored.
|
|
223
|
+
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
224
|
+
* This parameter is required if `capture` is not a `Route` object.
|
|
225
|
+
* @param method The HTTP method to match the Route against. Defaults to `'GET'`.
|
|
226
|
+
* @returns The generated `Route`.
|
|
227
|
+
*/
|
|
228
|
+
registerCapture(capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod): Route;
|
|
229
|
+
/**
|
|
230
|
+
* Registers a `Route` with the router.
|
|
231
|
+
*
|
|
232
|
+
* @param route The `Route` to register.
|
|
233
|
+
*/
|
|
234
|
+
registerRoute(route: Route): void;
|
|
235
|
+
/**
|
|
236
|
+
* Unregisters a `Route` with the `Router`.
|
|
237
|
+
*
|
|
238
|
+
* @param route The `Route` to unregister.
|
|
239
|
+
*/
|
|
240
|
+
unregisterRoute(route: Route): void;
|
|
241
|
+
/**
|
|
242
|
+
* Returns a mapping of a precached URL to the corresponding cache key, taking
|
|
243
|
+
* into account the revision information for the URL.
|
|
244
|
+
*
|
|
245
|
+
* @returns A URL to cache key mapping.
|
|
246
|
+
*/
|
|
247
|
+
getUrlsToPrecacheKeys(): Map<string, string>;
|
|
248
|
+
/**
|
|
249
|
+
* Returns a list of all the URLs that have been precached by the current
|
|
250
|
+
* service worker.
|
|
251
|
+
*
|
|
252
|
+
* @returns The precached URLs.
|
|
253
|
+
*/
|
|
254
|
+
getPrecachedUrls(): string[];
|
|
255
|
+
/**
|
|
256
|
+
* Returns the cache key used for storing a given URL. If that URL is
|
|
257
|
+
* unversioned, like `/index.html', then the cache key will be the original
|
|
258
|
+
* URL with a search parameter appended to it.
|
|
259
|
+
*
|
|
260
|
+
* @param url A URL whose cache key you want to look up.
|
|
261
|
+
* @returns The versioned URL that corresponds to a cache key
|
|
262
|
+
* for the original URL, or undefined if that URL isn't precached.
|
|
263
|
+
*/
|
|
264
|
+
getPrecacheKeyForUrl(url: string): string | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* @param url A cache key whose SRI you want to look up.
|
|
267
|
+
* @returns The subresource integrity associated with the cache key,
|
|
268
|
+
* or undefined if it's not set.
|
|
269
|
+
*/
|
|
270
|
+
getIntegrityForPrecacheKey(cacheKey: string): string | undefined;
|
|
271
|
+
/**
|
|
272
|
+
* This acts as a drop-in replacement for
|
|
273
|
+
* [`cache.match()`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match)
|
|
274
|
+
* with the following differences:
|
|
275
|
+
*
|
|
276
|
+
* - It knows what the name of the precache is, and only checks in that cache.
|
|
277
|
+
* - It allows you to pass in an "original" URL without versioning parameters,
|
|
278
|
+
* and it will automatically look up the correct cache key for the currently
|
|
279
|
+
* active revision of that URL.
|
|
280
|
+
*
|
|
281
|
+
* E.g., `matchPrecache('index.html')` will find the correct precached
|
|
282
|
+
* response for the currently active service worker, even if the actual cache
|
|
283
|
+
* key is `'/index.html?__WB_REVISION__=1234abcd'`.
|
|
284
|
+
*
|
|
285
|
+
* @param request The key (without revisioning parameters)
|
|
286
|
+
* to look up in the precache.
|
|
287
|
+
* @returns
|
|
288
|
+
*/
|
|
289
|
+
matchPrecache(request: string | Request): Promise<Response | undefined>;
|
|
290
|
+
/**
|
|
291
|
+
* Returns a function that looks up `url` in the precache (taking into
|
|
292
|
+
* account revision information), and returns the corresponding `Response`.
|
|
293
|
+
*
|
|
294
|
+
* @param url The precached URL which will be used to lookup the response.
|
|
295
|
+
* @return
|
|
296
|
+
*/
|
|
297
|
+
createHandlerBoundToUrl(url: string): RouteHandlerCallback;
|
|
298
|
+
/**
|
|
299
|
+
* Apply the routing rules to a `FetchEvent` object to get a `Response` from an
|
|
300
|
+
* appropriate `Route`'s handler.
|
|
301
|
+
*
|
|
302
|
+
* @param options
|
|
303
|
+
* @returns A promise is returned if a registered route can handle the request.
|
|
304
|
+
* If there is no matching route and there's no `defaultHandler`, `undefined`
|
|
305
|
+
* is returned.
|
|
306
|
+
*/
|
|
307
|
+
handleRequest({ request, event, }: {
|
|
308
|
+
/**
|
|
309
|
+
* The request to handle.
|
|
310
|
+
*/
|
|
311
|
+
request: Request;
|
|
312
|
+
/**
|
|
313
|
+
* The event that triggered the request.
|
|
314
|
+
*/
|
|
315
|
+
event: ExtendableEvent;
|
|
316
|
+
}): Promise<Response> | undefined;
|
|
317
|
+
/**
|
|
318
|
+
* Checks a request and URL (and optionally an event) against the list of
|
|
319
|
+
* registered routes, and if there's a match, returns the corresponding
|
|
320
|
+
* route along with any params generated by the match.
|
|
321
|
+
*
|
|
322
|
+
* @param options
|
|
323
|
+
* @returns An object with `route` and `params` properties. They are populated
|
|
324
|
+
* if a matching route was found or `undefined` otherwise.
|
|
325
|
+
*/
|
|
326
|
+
findMatchingRoute({ url, sameOrigin, request, event }: RouteMatchCallbackOptions): {
|
|
327
|
+
route?: Route;
|
|
328
|
+
params?: RouteHandlerCallbackOptions["params"];
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
//# sourceMappingURL=Serwist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Serwist.d.ts","sourceRoot":"","sources":["../src/Serwist.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get the current cache names and prefix/suffix used by Serwist.
|
|
3
|
+
*
|
|
4
|
+
* `cacheNames.precache` is used for precached assets,
|
|
5
|
+
* `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
|
|
6
|
+
* store `analytics.js`, and `cacheNames.runtime` is used for everything else.
|
|
7
|
+
*
|
|
8
|
+
* `cacheNames.prefix` can be used to retrieve just the current prefix value.
|
|
9
|
+
* `cacheNames.suffix` can be used to retrieve just the current suffix value.
|
|
10
|
+
*
|
|
11
|
+
* @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
|
|
12
|
+
*/
|
|
13
|
+
export declare const cacheNames: {
|
|
14
|
+
readonly googleAnalytics: string;
|
|
15
|
+
readonly precache: string;
|
|
16
|
+
readonly prefix: string;
|
|
17
|
+
readonly runtime: string;
|
|
18
|
+
readonly suffix: string;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=cacheNames.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cacheNames.d.ts","sourceRoot":"","sources":["../src/cacheNames.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU;;;;;;CAgBtB,CAAC"}
|