serwist 9.1.1 → 10.0.0-preview.10
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/chunks/waitUntil.js +141 -134
- package/dist/index.d.ts +22 -49
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.d.ts +16 -16
- package/dist/index.internal.d.ts.map +1 -1
- package/dist/index.internal.js +25 -3
- package/dist/index.js +2231 -452
- package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.d.ts +2 -2
- package/dist/lib/background-sync/BackgroundSyncPlugin.d.ts.map +1 -0
- package/dist/lib/background-sync/BackgroundSyncQueue.d.ts.map +1 -0
- package/dist/lib/background-sync/BackgroundSyncQueueDb.d.ts.map +1 -0
- package/dist/lib/background-sync/BackgroundSyncQueueStore.d.ts.map +1 -0
- package/dist/lib/{backgroundSync → background-sync}/StorableRequest.d.ts +1 -1
- package/dist/lib/background-sync/StorableRequest.d.ts.map +1 -0
- package/dist/lib/background-sync/index.d.ts +6 -0
- package/dist/lib/background-sync/index.d.ts.map +1 -0
- package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.d.ts +1 -1
- package/dist/lib/broadcast-update/BroadcastCacheUpdate.d.ts.map +1 -0
- package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.d.ts +2 -2
- package/dist/lib/broadcast-update/BroadcastUpdatePlugin.d.ts.map +1 -0
- package/dist/lib/broadcast-update/constants.d.ts.map +1 -0
- package/dist/lib/broadcast-update/index.d.ts +6 -0
- package/dist/lib/broadcast-update/index.d.ts.map +1 -0
- package/dist/lib/broadcast-update/responsesAreSame.d.ts.map +1 -0
- package/dist/lib/{broadcastUpdate → broadcast-update}/types.d.ts +1 -1
- package/dist/lib/broadcast-update/types.d.ts.map +1 -0
- package/dist/{cacheNames.d.ts → lib/cache-name.d.ts} +1 -1
- package/dist/lib/cache-name.d.ts.map +1 -0
- package/dist/lib/cacheable-response/CacheableResponse.d.ts.map +1 -0
- package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.d.ts +3 -3
- package/dist/lib/cacheable-response/CacheableResponsePlugin.d.ts.map +1 -0
- package/dist/lib/cacheable-response/index.d.ts +4 -0
- package/dist/lib/cacheable-response/index.d.ts.map +1 -0
- package/dist/{constants.d.ts → lib/constants.d.ts} +1 -1
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/core.d.ts +62 -0
- package/dist/lib/core.d.ts.map +1 -0
- package/dist/lib/expiration/ExpirationPlugin.d.ts +2 -2
- package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -1
- package/dist/lib/expiration/index.d.ts +4 -0
- package/dist/lib/expiration/index.d.ts.map +1 -0
- package/dist/lib/extension.d.ts +30 -0
- package/dist/lib/extension.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/constants.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/extension.d.ts +79 -0
- package/dist/lib/extensions/google-analytics/extension.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/index.d.ts +2 -0
- package/dist/lib/extensions/google-analytics/index.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/initialize.d.ts +12 -0
- package/dist/lib/extensions/google-analytics/initialize.d.ts.map +1 -0
- package/dist/lib/extensions/index.d.ts +14 -0
- package/dist/lib/extensions/index.d.ts.map +1 -0
- package/dist/{legacy/PrecacheController.d.ts → lib/extensions/precache/extension.d.ts} +56 -66
- package/dist/lib/extensions/precache/extension.d.ts.map +1 -0
- package/dist/lib/extensions/precache/options.d.ts +26 -0
- package/dist/lib/extensions/precache/options.d.ts.map +1 -0
- package/dist/lib/extensions/precache/plugin-cache-key.d.ts +16 -0
- package/dist/lib/extensions/precache/plugin-cache-key.d.ts.map +1 -0
- package/dist/lib/{precaching/PrecacheFallbackPlugin.d.ts → extensions/precache/plugin-fallback.d.ts} +4 -4
- package/dist/lib/extensions/precache/plugin-fallback.d.ts.map +1 -0
- package/dist/lib/extensions/precache/plugin-install-report.d.ts +14 -0
- package/dist/lib/extensions/precache/plugin-install-report.d.ts.map +1 -0
- package/dist/lib/extensions/precache/route.d.ts +42 -0
- package/dist/lib/extensions/precache/route.d.ts.map +1 -0
- package/dist/lib/{strategies/PrecacheStrategy.d.ts → extensions/precache/strategy.d.ts} +7 -7
- package/dist/lib/extensions/precache/strategy.d.ts.map +1 -0
- package/dist/lib/extensions/runtime-cache.d.ts +71 -0
- package/dist/lib/extensions/runtime-cache.d.ts.map +1 -0
- package/dist/lib/functions/handlers.d.ts +60 -0
- package/dist/lib/functions/handlers.d.ts.map +1 -0
- package/dist/lib/functions/router.d.ts +60 -0
- package/dist/lib/functions/router.d.ts.map +1 -0
- package/dist/{navigationPreload.d.ts → lib/navigation-preload.d.ts} +1 -1
- package/dist/lib/navigation-preload.d.ts.map +1 -0
- package/dist/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.d.ts +3 -3
- package/dist/lib/range-requests/RangeRequestsPlugin.d.ts.map +1 -0
- package/dist/lib/range-requests/createPartialResponse.d.ts.map +1 -0
- package/dist/lib/range-requests/index.d.ts +3 -0
- package/dist/lib/range-requests/index.d.ts.map +1 -0
- package/dist/lib/range-requests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
- package/dist/lib/range-requests/utils/parseRangeHeader.d.ts.map +1 -0
- package/dist/lib/route.d.ts +106 -0
- package/dist/lib/route.d.ts.map +1 -0
- package/dist/{Serwist.d.ts → lib/serwist.d.ts} +71 -62
- package/dist/lib/serwist.d.ts.map +1 -0
- package/dist/lib/strategies/NetworkFirst.d.ts.map +1 -1
- package/dist/lib/strategies/StaleWhileRevalidate.d.ts.map +1 -1
- package/dist/lib/strategies/Strategy.d.ts +3 -3
- package/dist/lib/strategies/Strategy.d.ts.map +1 -1
- package/dist/lib/strategies/StrategyHandler.d.ts +4 -4
- package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
- package/dist/lib/strategies/index.d.ts +11 -0
- package/dist/lib/strategies/index.d.ts.map +1 -0
- package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +2 -2
- package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -1
- package/dist/{types.d.ts → lib/types.d.ts} +7 -65
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/{copyResponse.d.ts → lib/utils.d.ts} +22 -1
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/models/messages/messageGenerator.d.ts +1 -1
- package/dist/models/messages/messageGenerator.d.ts.map +1 -1
- package/dist/utils/SerwistError.d.ts +2 -2
- package/dist/utils/SerwistError.d.ts.map +1 -1
- package/dist/utils/assert.d.ts +1 -1
- package/dist/utils/assert.d.ts.map +1 -1
- package/dist/utils/createCacheKey.d.ts +1 -1
- package/dist/utils/createCacheKey.d.ts.map +1 -1
- package/dist/utils/generateURLVariations.d.ts +1 -1
- package/dist/utils/generateURLVariations.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/normalizeHandler.d.ts +1 -1
- package/dist/utils/normalizeHandler.d.ts.map +1 -1
- package/dist/utils/parseRoute.d.ts +3 -3
- package/dist/utils/parseRoute.d.ts.map +1 -1
- package/dist/utils/pluginUtils.d.ts +2 -2
- package/dist/utils/pluginUtils.d.ts.map +1 -1
- package/package.json +28 -11
- package/src/index.internal.ts +16 -16
- package/src/index.ts +100 -107
- package/src/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.ts +2 -2
- package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.ts +4 -4
- package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.ts +1 -1
- package/src/lib/{backgroundSync → background-sync}/StorableRequest.ts +2 -2
- package/src/lib/background-sync/index.ts +5 -0
- package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.ts +5 -5
- package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.ts +2 -2
- package/src/lib/broadcast-update/index.ts +5 -0
- package/src/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.ts +2 -2
- package/src/lib/{broadcastUpdate → broadcast-update}/types.ts +1 -1
- package/src/{cacheNames.ts → lib/cache-name.ts} +1 -1
- package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponse.ts +4 -4
- package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.ts +3 -3
- package/src/lib/cacheable-response/index.ts +3 -0
- package/src/lib/core.ts +128 -0
- package/src/lib/expiration/CacheExpiration.ts +3 -3
- package/src/lib/expiration/ExpirationPlugin.ts +9 -10
- package/src/lib/expiration/index.ts +3 -0
- package/src/lib/extension.ts +37 -0
- package/src/lib/{googleAnalytics/initializeGoogleAnalytics.ts → extensions/google-analytics/extension.ts} +42 -48
- package/src/lib/extensions/google-analytics/index.ts +0 -0
- package/src/lib/extensions/google-analytics/initialize.ts +48 -0
- package/src/lib/extensions/index.ts +13 -0
- package/src/lib/extensions/precache/extension.ts +306 -0
- package/src/lib/extensions/precache/options.ts +49 -0
- package/src/{legacy/utils/PrecacheCacheKeyPlugin.ts → lib/extensions/precache/plugin-cache-key.ts} +7 -8
- package/src/lib/{precaching/PrecacheFallbackPlugin.ts → extensions/precache/plugin-fallback.ts} +19 -8
- package/src/{utils/PrecacheInstallReportPlugin.ts → lib/extensions/precache/plugin-install-report.ts} +5 -5
- package/src/lib/extensions/precache/route.ts +72 -0
- package/src/lib/{strategies/PrecacheStrategy.ts → extensions/precache/strategy.ts} +12 -12
- package/src/lib/extensions/runtime-cache.ts +126 -0
- package/src/lib/functions/handlers.ts +149 -0
- package/src/lib/functions/router.ts +314 -0
- package/src/{navigationPreload.ts → lib/navigation-preload.ts} +1 -1
- package/src/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.ts +3 -3
- package/src/lib/{rangeRequests → range-requests}/createPartialResponse.ts +3 -3
- package/src/lib/range-requests/index.ts +2 -0
- package/src/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.ts +2 -2
- package/src/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.ts +2 -2
- package/src/lib/route.ts +234 -0
- package/src/lib/serwist.ts +443 -0
- package/src/lib/strategies/CacheFirst.ts +3 -3
- package/src/lib/strategies/CacheOnly.ts +3 -3
- package/src/lib/strategies/NetworkFirst.ts +4 -4
- package/src/lib/strategies/NetworkOnly.ts +4 -4
- package/src/lib/strategies/StaleWhileRevalidate.ts +4 -4
- package/src/lib/strategies/Strategy.ts +7 -7
- package/src/lib/strategies/StrategyHandler.ts +18 -18
- package/src/lib/strategies/index.ts +10 -0
- package/src/lib/strategies/plugins/cacheOkAndOpaquePlugin.ts +2 -2
- package/src/lib/strategies/utils/messages.ts +2 -2
- package/src/{types.ts → lib/types.ts} +17 -70
- package/src/lib/utils.ts +137 -0
- package/src/models/messages/messageGenerator.ts +1 -1
- package/src/models/messages/messages.ts +3 -3
- package/src/utils/SerwistError.ts +3 -3
- package/src/utils/assert.ts +1 -1
- package/src/utils/createCacheKey.ts +1 -2
- package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
- package/src/utils/generateURLVariations.ts +1 -1
- package/src/utils/logger.ts +1 -1
- package/src/utils/normalizeHandler.ts +1 -1
- package/src/utils/parseRoute.ts +4 -5
- package/src/utils/pluginUtils.ts +2 -2
- package/dist/NavigationRoute.d.ts +0 -56
- package/dist/NavigationRoute.d.ts.map +0 -1
- package/dist/PrecacheRoute.d.ts +0 -16
- package/dist/PrecacheRoute.d.ts.map +0 -1
- package/dist/RegExpRoute.d.ts +0 -24
- package/dist/RegExpRoute.d.ts.map +0 -1
- package/dist/Route.d.ts +0 -33
- package/dist/Route.d.ts.map +0 -1
- package/dist/Serwist.d.ts.map +0 -1
- package/dist/cacheNames.d.ts.map +0 -1
- package/dist/chunks/printInstallDetails.js +0 -1601
- package/dist/chunks/resultingClientExists.js +0 -32
- package/dist/constants.d.ts.map +0 -1
- package/dist/copyResponse.d.ts.map +0 -1
- package/dist/disableDevLogs.d.ts +0 -7
- package/dist/disableDevLogs.d.ts.map +0 -1
- package/dist/index.legacy.d.ts +0 -28
- package/dist/index.legacy.d.ts.map +0 -1
- package/dist/index.legacy.js +0 -790
- package/dist/legacy/PrecacheController.d.ts.map +0 -1
- package/dist/legacy/PrecacheFallbackPlugin.d.ts +0 -61
- package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/legacy/PrecacheRoute.d.ts +0 -19
- package/dist/legacy/PrecacheRoute.d.ts.map +0 -1
- package/dist/legacy/Router.d.ts +0 -151
- package/dist/legacy/Router.d.ts.map +0 -1
- package/dist/legacy/addPlugins.d.ts +0 -9
- package/dist/legacy/addPlugins.d.ts.map +0 -1
- package/dist/legacy/addRoute.d.ts +0 -14
- package/dist/legacy/addRoute.d.ts.map +0 -1
- package/dist/legacy/constants.d.ts.map +0 -1
- package/dist/legacy/createHandlerBoundToURL.d.ts +0 -17
- package/dist/legacy/createHandlerBoundToURL.d.ts.map +0 -1
- package/dist/legacy/fallbacks.d.ts +0 -59
- package/dist/legacy/fallbacks.d.ts.map +0 -1
- package/dist/legacy/getCacheKeyForURL.d.ts +0 -20
- package/dist/legacy/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/legacy/handlePrecaching.d.ts +0 -54
- package/dist/legacy/handlePrecaching.d.ts.map +0 -1
- package/dist/legacy/initializeGoogleAnalytics.d.ts +0 -38
- package/dist/legacy/initializeGoogleAnalytics.d.ts.map +0 -1
- package/dist/legacy/installSerwist.d.ts +0 -81
- package/dist/legacy/installSerwist.d.ts.map +0 -1
- package/dist/legacy/matchPrecache.d.ts +0 -15
- package/dist/legacy/matchPrecache.d.ts.map +0 -1
- package/dist/legacy/precache.d.ts +0 -20
- package/dist/legacy/precache.d.ts.map +0 -1
- package/dist/legacy/precacheAndRoute.d.ts +0 -14
- package/dist/legacy/precacheAndRoute.d.ts.map +0 -1
- package/dist/legacy/registerRoute.d.ts +0 -16
- package/dist/legacy/registerRoute.d.ts.map +0 -1
- package/dist/legacy/registerRuntimeCaching.d.ts +0 -11
- package/dist/legacy/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/legacy/setCatchHandler.d.ts +0 -10
- package/dist/legacy/setCatchHandler.d.ts.map +0 -1
- package/dist/legacy/setDefaultHandler.d.ts +0 -13
- package/dist/legacy/setDefaultHandler.d.ts.map +0 -1
- package/dist/legacy/singletonPrecacheController.d.ts +0 -34
- package/dist/legacy/singletonPrecacheController.d.ts.map +0 -1
- package/dist/legacy/singletonRouter.d.ts +0 -41
- package/dist/legacy/singletonRouter.d.ts.map +0 -1
- package/dist/legacy/unregisterRoute.d.ts +0 -9
- package/dist/legacy/unregisterRoute.d.ts.map +0 -1
- package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts +0 -16
- package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/legacy/utils/getCacheKeyForURL.d.ts +0 -14
- package/dist/legacy/utils/getCacheKeyForURL.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncQueueDb.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncQueueStore.d.ts.map +0 -1
- package/dist/lib/backgroundSync/StorableRequest.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/constants.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/types.d.ts.map +0 -1
- package/dist/lib/cacheableResponse/CacheableResponse.d.ts.map +0 -1
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
- package/dist/lib/googleAnalytics/constants.d.ts +0 -10
- package/dist/lib/googleAnalytics/constants.d.ts.map +0 -1
- package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts +0 -30
- package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +0 -1
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
- package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +0 -1
- package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
- package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
- package/dist/lib/strategies/PrecacheStrategy.d.ts.map +0 -1
- package/dist/navigationPreload.d.ts.map +0 -1
- package/dist/registerQuotaErrorCallback.d.ts +0 -8
- package/dist/registerQuotaErrorCallback.d.ts.map +0 -1
- package/dist/setCacheNameDetails.d.ts +0 -9
- package/dist/setCacheNameDetails.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts +0 -16
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/utils/PrecacheInstallReportPlugin.d.ts +0 -14
- package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
- package/dist/utils/parsePrecacheOptions.d.ts +0 -26
- package/dist/utils/parsePrecacheOptions.d.ts.map +0 -1
- package/src/NavigationRoute.ts +0 -118
- package/src/PrecacheRoute.ts +0 -45
- package/src/RegExpRoute.ts +0 -74
- package/src/Route.ts +0 -67
- package/src/Serwist.ts +0 -867
- package/src/copyResponse.ts +0 -58
- package/src/disableDevLogs.ts +0 -10
- package/src/index.legacy.ts +0 -62
- package/src/legacy/PrecacheController.ts +0 -337
- package/src/legacy/PrecacheFallbackPlugin.ts +0 -92
- package/src/legacy/PrecacheRoute.ts +0 -48
- package/src/legacy/Router.ts +0 -484
- package/src/legacy/addPlugins.ts +0 -21
- package/src/legacy/addRoute.ts +0 -27
- package/src/legacy/createHandlerBoundToURL.ts +0 -30
- package/src/legacy/fallbacks.ts +0 -94
- package/src/legacy/getCacheKeyForURL.ts +0 -32
- package/src/legacy/handlePrecaching.ts +0 -86
- package/src/legacy/initializeGoogleAnalytics.ts +0 -218
- package/src/legacy/installSerwist.ts +0 -170
- package/src/legacy/matchPrecache.ts +0 -27
- package/src/legacy/precache.ts +0 -33
- package/src/legacy/precacheAndRoute.ts +0 -27
- package/src/legacy/registerRoute.ts +0 -28
- package/src/legacy/registerRuntimeCaching.ts +0 -17
- package/src/legacy/setCatchHandler.ts +0 -21
- package/src/legacy/setDefaultHandler.ts +0 -24
- package/src/legacy/singletonPrecacheController.ts +0 -53
- package/src/legacy/singletonRouter.ts +0 -70
- package/src/legacy/unregisterRoute.ts +0 -13
- package/src/legacy/utils/getCacheKeyForURL.ts +0 -36
- package/src/lib/googleAnalytics/constants.ts +0 -22
- package/src/registerQuotaErrorCallback.ts +0 -34
- package/src/setCacheNameDetails.ts +0 -53
- package/src/utils/PrecacheCacheKeyPlugin.ts +0 -33
- package/src/utils/parsePrecacheOptions.ts +0 -47
- /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.d.ts +0 -0
- /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.d.ts +0 -0
- /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.d.ts +0 -0
- /package/dist/lib/{broadcastUpdate → broadcast-update}/constants.d.ts +0 -0
- /package/dist/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.d.ts +0 -0
- /package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponse.d.ts +0 -0
- /package/dist/{legacy → lib/extensions/google-analytics}/constants.d.ts +0 -0
- /package/dist/lib/{rangeRequests → range-requests}/createPartialResponse.d.ts +0 -0
- /package/dist/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.d.ts +0 -0
- /package/dist/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.d.ts +0 -0
- /package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.ts +0 -0
- /package/src/lib/{broadcastUpdate → broadcast-update}/constants.ts +0 -0
- /package/src/{constants.ts → lib/constants.ts} +0 -0
- /package/src/{legacy → lib/extensions/google-analytics}/constants.ts +0 -0
package/src/copyResponse.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { SerwistError } from "./utils/SerwistError.js";
|
|
10
|
-
import { canConstructResponseFromBodyStream } from "./utils/canConstructResponseFromBodyStream.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Allows developers to copy a response and modify its `headers`, `status`,
|
|
14
|
-
* or `statusText` values (the [valid options](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#options)
|
|
15
|
-
* when constructing a `Response` object).
|
|
16
|
-
* To modify these values, pass a function as the second argument. That
|
|
17
|
-
* function will be invoked with the options of the initial `Response` object.
|
|
18
|
-
* The return value of this function will be used as the options for the new `Response` object.
|
|
19
|
-
* To change the values either modify the passed parameter(s) and return it or return a totally
|
|
20
|
-
* new object.
|
|
21
|
-
*
|
|
22
|
-
* This method is intentionally limited to same-origin responses, regardless of
|
|
23
|
-
* whether CORS was used or not.
|
|
24
|
-
*
|
|
25
|
-
* @param response The initial response.
|
|
26
|
-
* @param modifier The function used to modify the options of the `Response` object.
|
|
27
|
-
*/
|
|
28
|
-
export const copyResponse = async (response: Response, modifier?: (responseInit: ResponseInit) => ResponseInit): Promise<Response> => {
|
|
29
|
-
let origin = null;
|
|
30
|
-
// If response.url isn't set, assume it's cross-origin and keep origin null.
|
|
31
|
-
if (response.url) {
|
|
32
|
-
const responseURL = new URL(response.url);
|
|
33
|
-
origin = responseURL.origin;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (origin !== self.location.origin) {
|
|
37
|
-
throw new SerwistError("cross-origin-copy-response", { origin });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const clonedResponse = response.clone();
|
|
41
|
-
|
|
42
|
-
// Create a fresh `ResponseInit` object by cloning the headers.
|
|
43
|
-
const responseInit: ResponseInit = {
|
|
44
|
-
headers: new Headers(clonedResponse.headers),
|
|
45
|
-
status: clonedResponse.status,
|
|
46
|
-
statusText: clonedResponse.statusText,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Apply any user modifications.
|
|
50
|
-
const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
|
|
51
|
-
|
|
52
|
-
// Create the new response from the body stream and `ResponseInit`
|
|
53
|
-
// modifications. Note: not all browsers support the Response.body stream,
|
|
54
|
-
// so fall back to reading the entire body into memory as a blob.
|
|
55
|
-
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
|
56
|
-
|
|
57
|
-
return new Response(body, modifiedResponseInit);
|
|
58
|
-
};
|
package/src/disableDevLogs.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare const self: ServiceWorkerGlobalScope;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Disables Serwist's logging in development mode.
|
|
5
|
-
*
|
|
6
|
-
* @see https://serwist.pages.dev/docs/serwist/core/disable-dev-logs
|
|
7
|
-
*/
|
|
8
|
-
export const disableDevLogs = (): void => {
|
|
9
|
-
self.__WB_DISABLE_DEV_LOGS = true;
|
|
10
|
-
};
|
package/src/index.legacy.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { PrecacheController } from "./legacy/PrecacheController.js";
|
|
2
|
-
import { PrecacheFallbackPlugin } from "./legacy/PrecacheFallbackPlugin.js";
|
|
3
|
-
import type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "./legacy/PrecacheFallbackPlugin.js";
|
|
4
|
-
import { PrecacheRoute } from "./legacy/PrecacheRoute.js";
|
|
5
|
-
import { Router } from "./legacy/Router.js";
|
|
6
|
-
import { addPlugins } from "./legacy/addPlugins.js";
|
|
7
|
-
import { addRoute } from "./legacy/addRoute.js";
|
|
8
|
-
import { createHandlerBoundToURL } from "./legacy/createHandlerBoundToURL.js";
|
|
9
|
-
import type { FallbackEntry, FallbacksOptions } from "./legacy/fallbacks.js";
|
|
10
|
-
import { fallbacks } from "./legacy/fallbacks.js";
|
|
11
|
-
import { getCacheKeyForURL } from "./legacy/getCacheKeyForURL.js";
|
|
12
|
-
import { type HandlePrecachingOptions, handlePrecaching } from "./legacy/handlePrecaching.js";
|
|
13
|
-
import type { GoogleAnalyticsInitializeOptions } from "./legacy/initializeGoogleAnalytics.js";
|
|
14
|
-
import { initializeGoogleAnalytics } from "./legacy/initializeGoogleAnalytics.js";
|
|
15
|
-
import { type InstallSerwistOptions, installSerwist } from "./legacy/installSerwist.js";
|
|
16
|
-
import { matchPrecache } from "./legacy/matchPrecache.js";
|
|
17
|
-
import { precache } from "./legacy/precache.js";
|
|
18
|
-
import { precacheAndRoute } from "./legacy/precacheAndRoute.js";
|
|
19
|
-
import { registerRoute } from "./legacy/registerRoute.js";
|
|
20
|
-
import { registerRuntimeCaching } from "./legacy/registerRuntimeCaching.js";
|
|
21
|
-
import { setCatchHandler } from "./legacy/setCatchHandler.js";
|
|
22
|
-
import { setDefaultHandler } from "./legacy/setDefaultHandler.js";
|
|
23
|
-
import { getSingletonPrecacheController, setSingletonPrecacheController } from "./legacy/singletonPrecacheController.js";
|
|
24
|
-
import { getSingletonRouter, setSingletonRouter } from "./legacy/singletonRouter.js";
|
|
25
|
-
import { unregisterRoute } from "./legacy/unregisterRoute.js";
|
|
26
|
-
|
|
27
|
-
export {
|
|
28
|
-
// Actual deprecated modules start here
|
|
29
|
-
addPlugins,
|
|
30
|
-
addRoute,
|
|
31
|
-
createHandlerBoundToURL,
|
|
32
|
-
fallbacks,
|
|
33
|
-
getCacheKeyForURL,
|
|
34
|
-
initializeGoogleAnalytics,
|
|
35
|
-
installSerwist,
|
|
36
|
-
matchPrecache,
|
|
37
|
-
precache,
|
|
38
|
-
precacheAndRoute,
|
|
39
|
-
PrecacheController,
|
|
40
|
-
PrecacheFallbackPlugin,
|
|
41
|
-
PrecacheRoute,
|
|
42
|
-
getSingletonPrecacheController,
|
|
43
|
-
setSingletonPrecacheController,
|
|
44
|
-
handlePrecaching,
|
|
45
|
-
registerRuntimeCaching,
|
|
46
|
-
registerRoute,
|
|
47
|
-
Router,
|
|
48
|
-
setCatchHandler,
|
|
49
|
-
setDefaultHandler,
|
|
50
|
-
getSingletonRouter,
|
|
51
|
-
setSingletonRouter,
|
|
52
|
-
unregisterRoute,
|
|
53
|
-
};
|
|
54
|
-
export type {
|
|
55
|
-
HandlePrecachingOptions,
|
|
56
|
-
GoogleAnalyticsInitializeOptions,
|
|
57
|
-
InstallSerwistOptions,
|
|
58
|
-
FallbackEntry,
|
|
59
|
-
FallbacksOptions,
|
|
60
|
-
PrecacheFallbackEntry,
|
|
61
|
-
PrecacheFallbackPluginOptions,
|
|
62
|
-
};
|
|
@@ -1,337 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { parallel } from "@serwist/utils";
|
|
10
|
-
import { PrecacheStrategy } from "../lib/strategies/PrecacheStrategy.js";
|
|
11
|
-
import type { Strategy } from "../lib/strategies/Strategy.js";
|
|
12
|
-
import type { RouteHandlerCallback, SerwistPlugin } from "../types.js";
|
|
13
|
-
import type { CleanupResult, InstallResult, PrecacheEntry } from "../types.js";
|
|
14
|
-
import { PrecacheInstallReportPlugin } from "../utils/PrecacheInstallReportPlugin.js";
|
|
15
|
-
import { SerwistError } from "../utils/SerwistError.js";
|
|
16
|
-
import { assert } from "../utils/assert.js";
|
|
17
|
-
import { cacheNames as privateCacheNames } from "../utils/cacheNames.js";
|
|
18
|
-
import { createCacheKey } from "../utils/createCacheKey.js";
|
|
19
|
-
import { logger } from "../utils/logger.js";
|
|
20
|
-
import { printCleanupDetails } from "../utils/printCleanupDetails.js";
|
|
21
|
-
import { printInstallDetails } from "../utils/printInstallDetails.js";
|
|
22
|
-
import { waitUntil } from "../utils/waitUntil.js";
|
|
23
|
-
import { PrecacheCacheKeyPlugin } from "./utils/PrecacheCacheKeyPlugin.js";
|
|
24
|
-
|
|
25
|
-
// Give TypeScript the correct global.
|
|
26
|
-
declare const self: ServiceWorkerGlobalScope;
|
|
27
|
-
|
|
28
|
-
interface PrecacheControllerOptions {
|
|
29
|
-
/**
|
|
30
|
-
* The cache to use for precaching.
|
|
31
|
-
*/
|
|
32
|
-
cacheName?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Plugins to use when precaching as well as responding to fetch
|
|
35
|
-
* events for precached assets.
|
|
36
|
-
*/
|
|
37
|
-
plugins?: SerwistPlugin[];
|
|
38
|
-
/**
|
|
39
|
-
* Whether to attempt to get the response from the network if there's
|
|
40
|
-
* a precache miss.
|
|
41
|
-
*/
|
|
42
|
-
fallbackToNetwork?: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* The number of precache requests that should be made concurrently.
|
|
45
|
-
*
|
|
46
|
-
* @default 1
|
|
47
|
-
*/
|
|
48
|
-
concurrentPrecaching?: number;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Performs efficient precaching of assets.
|
|
53
|
-
* @deprecated
|
|
54
|
-
*/
|
|
55
|
-
export class PrecacheController {
|
|
56
|
-
private _installAndActiveListenersAdded?: boolean;
|
|
57
|
-
private _concurrentPrecaching: number;
|
|
58
|
-
private readonly _strategy: Strategy;
|
|
59
|
-
private readonly _urlsToCacheKeys: Map<string, string> = new Map();
|
|
60
|
-
private readonly _urlsToCacheModes: Map<string, "reload" | "default" | "no-store" | "no-cache" | "force-cache" | "only-if-cached"> = new Map();
|
|
61
|
-
private readonly _cacheKeysToIntegrities: Map<string, string> = new Map();
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Create a new PrecacheController.
|
|
65
|
-
*
|
|
66
|
-
* @param options
|
|
67
|
-
*/
|
|
68
|
-
constructor({ cacheName, plugins = [], fallbackToNetwork = true, concurrentPrecaching = 1 }: PrecacheControllerOptions = {}) {
|
|
69
|
-
this._concurrentPrecaching = concurrentPrecaching;
|
|
70
|
-
this._strategy = new PrecacheStrategy({
|
|
71
|
-
cacheName: privateCacheNames.getPrecacheName(cacheName),
|
|
72
|
-
plugins: [...plugins, new PrecacheCacheKeyPlugin({ precacheController: this })],
|
|
73
|
-
fallbackToNetwork,
|
|
74
|
-
});
|
|
75
|
-
// Bind the install and activate methods to the instance.
|
|
76
|
-
this.install = this.install.bind(this);
|
|
77
|
-
this.activate = this.activate.bind(this);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* The strategy created by this controller and
|
|
82
|
-
* used to cache assets and respond to `fetch` events.
|
|
83
|
-
*/
|
|
84
|
-
get strategy(): Strategy {
|
|
85
|
-
return this._strategy;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Adds items to the precache list, removing any duplicates and
|
|
90
|
-
* stores the files in the precache cache when the service
|
|
91
|
-
* worker installs.
|
|
92
|
-
*
|
|
93
|
-
* This method can be called multiple times.
|
|
94
|
-
*
|
|
95
|
-
* @param entries Array of entries to precache.
|
|
96
|
-
*/
|
|
97
|
-
precache(entries: (PrecacheEntry | string)[]): void {
|
|
98
|
-
this.addToCacheList(entries);
|
|
99
|
-
|
|
100
|
-
if (!this._installAndActiveListenersAdded) {
|
|
101
|
-
self.addEventListener("install", this.install);
|
|
102
|
-
self.addEventListener("activate", this.activate);
|
|
103
|
-
this._installAndActiveListenersAdded = true;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* This method will add items to the precache list, removing duplicates
|
|
109
|
-
* and ensuring the information is valid.
|
|
110
|
-
*
|
|
111
|
-
* @param entries Array of entries to precache.
|
|
112
|
-
*/
|
|
113
|
-
addToCacheList(entries: (PrecacheEntry | string)[]): void {
|
|
114
|
-
if (process.env.NODE_ENV !== "production") {
|
|
115
|
-
assert!.isArray(entries, {
|
|
116
|
-
moduleName: "serwist/legacy",
|
|
117
|
-
className: "PrecacheController",
|
|
118
|
-
funcName: "addToCacheList",
|
|
119
|
-
paramName: "entries",
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
const urlsToWarnAbout: string[] = [];
|
|
124
|
-
for (const entry of entries) {
|
|
125
|
-
// See https://github.com/GoogleChrome/workbox/issues/2259
|
|
126
|
-
if (typeof entry === "string") {
|
|
127
|
-
urlsToWarnAbout.push(entry);
|
|
128
|
-
} else if (entry && !entry.integrity && entry.revision === undefined) {
|
|
129
|
-
urlsToWarnAbout.push(entry.url);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
const { cacheKey, url } = createCacheKey(entry);
|
|
133
|
-
const cacheMode = typeof entry !== "string" && entry.revision ? "reload" : "default";
|
|
134
|
-
|
|
135
|
-
if (this._urlsToCacheKeys.has(url) && this._urlsToCacheKeys.get(url) !== cacheKey) {
|
|
136
|
-
throw new SerwistError("add-to-cache-list-conflicting-entries", {
|
|
137
|
-
firstEntry: this._urlsToCacheKeys.get(url),
|
|
138
|
-
secondEntry: cacheKey,
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (typeof entry !== "string" && entry.integrity) {
|
|
143
|
-
if (this._cacheKeysToIntegrities.has(cacheKey) && this._cacheKeysToIntegrities.get(cacheKey) !== entry.integrity) {
|
|
144
|
-
throw new SerwistError("add-to-cache-list-conflicting-integrities", {
|
|
145
|
-
url,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
this._cacheKeysToIntegrities.set(cacheKey, entry.integrity);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
this._urlsToCacheKeys.set(url, cacheKey);
|
|
152
|
-
this._urlsToCacheModes.set(url, cacheMode);
|
|
153
|
-
|
|
154
|
-
if (urlsToWarnAbout.length > 0) {
|
|
155
|
-
const warningMessage = `Serwist is precaching URLs without revision info: ${urlsToWarnAbout.join(
|
|
156
|
-
", ",
|
|
157
|
-
)}\nThis is generally NOT safe. Learn more at https://bit.ly/wb-precache`;
|
|
158
|
-
if (process.env.NODE_ENV === "production") {
|
|
159
|
-
// Use console directly to display this warning without bloating
|
|
160
|
-
// bundle sizes by pulling in all of the logger codebase in prod.
|
|
161
|
-
console.warn(warningMessage);
|
|
162
|
-
} else {
|
|
163
|
-
logger.warn(warningMessage);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Precaches new and updated assets. Call this method from the service worker
|
|
171
|
-
* install event.
|
|
172
|
-
*
|
|
173
|
-
* Note: this method calls `event.waitUntil()` for you, so you do not need
|
|
174
|
-
* to call it yourself in your event handlers.
|
|
175
|
-
*
|
|
176
|
-
* @param event
|
|
177
|
-
* @returns
|
|
178
|
-
*/
|
|
179
|
-
install(event: ExtendableEvent): Promise<InstallResult> {
|
|
180
|
-
return waitUntil<InstallResult>(event, async () => {
|
|
181
|
-
const installReportPlugin = new PrecacheInstallReportPlugin();
|
|
182
|
-
this.strategy.plugins.push(installReportPlugin);
|
|
183
|
-
|
|
184
|
-
await parallel(this._concurrentPrecaching, Array.from(this._urlsToCacheKeys.entries()), async ([url, cacheKey]): Promise<void> => {
|
|
185
|
-
const integrity = this._cacheKeysToIntegrities.get(cacheKey);
|
|
186
|
-
const cacheMode = this._urlsToCacheModes.get(url);
|
|
187
|
-
|
|
188
|
-
const request = new Request(url, {
|
|
189
|
-
integrity,
|
|
190
|
-
cache: cacheMode,
|
|
191
|
-
credentials: "same-origin",
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
await Promise.all(
|
|
195
|
-
this.strategy.handleAll({
|
|
196
|
-
event,
|
|
197
|
-
request,
|
|
198
|
-
url: new URL(request.url),
|
|
199
|
-
params: { cacheKey },
|
|
200
|
-
}),
|
|
201
|
-
);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
const { updatedURLs, notUpdatedURLs } = installReportPlugin;
|
|
205
|
-
|
|
206
|
-
if (process.env.NODE_ENV !== "production") {
|
|
207
|
-
printInstallDetails(updatedURLs, notUpdatedURLs);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return { updatedURLs, notUpdatedURLs };
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Deletes assets that are no longer present in the current precache manifest.
|
|
216
|
-
* Call this method from the service worker activate event.
|
|
217
|
-
*
|
|
218
|
-
* Note: this method calls `event.waitUntil()` for you, so you do not need
|
|
219
|
-
* to call it yourself in your event handlers.
|
|
220
|
-
*
|
|
221
|
-
* @param event
|
|
222
|
-
* @returns
|
|
223
|
-
*/
|
|
224
|
-
activate(event: ExtendableEvent): Promise<CleanupResult> {
|
|
225
|
-
return waitUntil<CleanupResult>(event, async () => {
|
|
226
|
-
const cache = await self.caches.open(this.strategy.cacheName);
|
|
227
|
-
const currentlyCachedRequests = await cache.keys();
|
|
228
|
-
const expectedCacheKeys = new Set(this._urlsToCacheKeys.values());
|
|
229
|
-
|
|
230
|
-
const deletedCacheRequests: string[] = [];
|
|
231
|
-
|
|
232
|
-
for (const request of currentlyCachedRequests) {
|
|
233
|
-
if (!expectedCacheKeys.has(request.url)) {
|
|
234
|
-
await cache.delete(request);
|
|
235
|
-
deletedCacheRequests.push(request.url);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
if (process.env.NODE_ENV !== "production") {
|
|
240
|
-
printCleanupDetails(deletedCacheRequests);
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return { deletedCacheRequests };
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Returns a mapping of a precached URL to the corresponding cache key, taking
|
|
249
|
-
* into account the revision information for the URL.
|
|
250
|
-
*
|
|
251
|
-
* @returns A URL to cache key mapping.
|
|
252
|
-
*/
|
|
253
|
-
getURLsToCacheKeys(): Map<string, string> {
|
|
254
|
-
return this._urlsToCacheKeys;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
/**
|
|
258
|
-
* Returns a list of all the URLs that have been precached by the current
|
|
259
|
-
* service worker.
|
|
260
|
-
*
|
|
261
|
-
* @returns The precached URLs.
|
|
262
|
-
*/
|
|
263
|
-
getCachedURLs(): string[] {
|
|
264
|
-
return [...this._urlsToCacheKeys.keys()];
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Returns the cache key used for storing a given URL. If that URL is
|
|
269
|
-
* unversioned, like `/index.html', then the cache key will be the original
|
|
270
|
-
* URL with a search parameter appended to it.
|
|
271
|
-
*
|
|
272
|
-
* @param url A URL whose cache key you want to look up.
|
|
273
|
-
* @returns The versioned URL that corresponds to a cache key
|
|
274
|
-
* for the original URL, or undefined if that URL isn't precached.
|
|
275
|
-
*/
|
|
276
|
-
getCacheKeyForURL(url: string): string | undefined {
|
|
277
|
-
const urlObject = new URL(url, location.href);
|
|
278
|
-
return this._urlsToCacheKeys.get(urlObject.href);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* @param url A cache key whose SRI you want to look up.
|
|
283
|
-
* @returns The subresource integrity associated with the cache key,
|
|
284
|
-
* or undefined if it's not set.
|
|
285
|
-
*/
|
|
286
|
-
getIntegrityForCacheKey(cacheKey: string): string | undefined {
|
|
287
|
-
return this._cacheKeysToIntegrities.get(cacheKey);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* This acts as a drop-in replacement for
|
|
292
|
-
* [`cache.match()`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match)
|
|
293
|
-
* with the following differences:
|
|
294
|
-
*
|
|
295
|
-
* - It knows what the name of the precache is, and only checks in that cache.
|
|
296
|
-
* - It allows you to pass in an "original" URL without versioning parameters,
|
|
297
|
-
* and it will automatically look up the correct cache key for the currently
|
|
298
|
-
* active revision of that URL.
|
|
299
|
-
*
|
|
300
|
-
* E.g., `matchPrecache('index.html')` will find the correct precached
|
|
301
|
-
* response for the currently active service worker, even if the actual cache
|
|
302
|
-
* key is `'/index.html?__WB_REVISION__=1234abcd'`.
|
|
303
|
-
*
|
|
304
|
-
* @param request The key (without revisioning parameters)
|
|
305
|
-
* to look up in the precache.
|
|
306
|
-
* @returns
|
|
307
|
-
*/
|
|
308
|
-
async matchPrecache(request: string | Request): Promise<Response | undefined> {
|
|
309
|
-
const url = request instanceof Request ? request.url : request;
|
|
310
|
-
const cacheKey = this.getCacheKeyForURL(url);
|
|
311
|
-
if (cacheKey) {
|
|
312
|
-
const cache = await self.caches.open(this.strategy.cacheName);
|
|
313
|
-
return cache.match(cacheKey);
|
|
314
|
-
}
|
|
315
|
-
return undefined;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
/**
|
|
319
|
-
* Returns a function that looks up `url` in the precache (taking into
|
|
320
|
-
* account revision information), and returns the corresponding `Response`.
|
|
321
|
-
*
|
|
322
|
-
* @param url The precached URL which will be used to lookup the response.
|
|
323
|
-
* @return
|
|
324
|
-
*/
|
|
325
|
-
createHandlerBoundToURL(url: string): RouteHandlerCallback {
|
|
326
|
-
const cacheKey = this.getCacheKeyForURL(url);
|
|
327
|
-
if (!cacheKey) {
|
|
328
|
-
throw new SerwistError("non-precached-url", { url });
|
|
329
|
-
}
|
|
330
|
-
return (options) => {
|
|
331
|
-
options.request = new Request(url);
|
|
332
|
-
options.params = { cacheKey, ...options.params };
|
|
333
|
-
|
|
334
|
-
return this.strategy.handle(options);
|
|
335
|
-
};
|
|
336
|
-
}
|
|
337
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import type { HandlerDidErrorCallbackParam, SerwistPlugin } from "../types.js";
|
|
10
|
-
import type { PrecacheController } from "./PrecacheController.js";
|
|
11
|
-
import { getSingletonPrecacheController } from "./singletonPrecacheController.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @deprecated
|
|
15
|
-
*/
|
|
16
|
-
export interface PrecacheFallbackEntry {
|
|
17
|
-
/**
|
|
18
|
-
* A function that checks whether the fallback entry can be used
|
|
19
|
-
* for a request.
|
|
20
|
-
*/
|
|
21
|
-
matcher: (param: HandlerDidErrorCallbackParam) => boolean;
|
|
22
|
-
/**
|
|
23
|
-
* A precached URL to be used as a fallback.
|
|
24
|
-
*/
|
|
25
|
-
url: string;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @deprecated
|
|
30
|
-
*/
|
|
31
|
-
export interface PrecacheFallbackPluginOptions {
|
|
32
|
-
/**
|
|
33
|
-
* Precached URLs to be used as the fallback
|
|
34
|
-
* if the associated strategy can't generate a response.
|
|
35
|
-
*/
|
|
36
|
-
fallbackUrls: (string | PrecacheFallbackEntry)[];
|
|
37
|
-
/**
|
|
38
|
-
* An optional {@linkcode PrecacheController} instance. If not provided,
|
|
39
|
-
* the default {@linkcode PrecacheController} will be used.
|
|
40
|
-
*/
|
|
41
|
-
precacheController?: PrecacheController;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* A class that allows you to specify offline fallbacks
|
|
46
|
-
* to be used when a given strategy is unable to generate a response.
|
|
47
|
-
*
|
|
48
|
-
* It does this by intercepting the `handlerDidError` plugin callback
|
|
49
|
-
* and returning a precached response, taking the expected revision parameter
|
|
50
|
-
* into account automatically.
|
|
51
|
-
*
|
|
52
|
-
* Unless you explicitly pass in a {@linkcode PrecacheController} instance to the
|
|
53
|
-
* constructor, the default instance will be used.
|
|
54
|
-
*
|
|
55
|
-
* @deprecated
|
|
56
|
-
*/
|
|
57
|
-
export class PrecacheFallbackPlugin implements SerwistPlugin {
|
|
58
|
-
private readonly _fallbackUrls: (string | PrecacheFallbackEntry)[];
|
|
59
|
-
private readonly _precacheController: PrecacheController;
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Constructs a new instance with the associated `fallbackUrls`.
|
|
63
|
-
*
|
|
64
|
-
* @param config
|
|
65
|
-
*/
|
|
66
|
-
constructor({ fallbackUrls, precacheController }: PrecacheFallbackPluginOptions) {
|
|
67
|
-
this._fallbackUrls = fallbackUrls;
|
|
68
|
-
this._precacheController = precacheController || getSingletonPrecacheController();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @returns The precache response for one of the fallback URLs, or `undefined` if
|
|
73
|
-
* nothing satisfies the conditions.
|
|
74
|
-
* @private
|
|
75
|
-
*/
|
|
76
|
-
async handlerDidError(param: HandlerDidErrorCallbackParam) {
|
|
77
|
-
for (const fallback of this._fallbackUrls) {
|
|
78
|
-
if (typeof fallback === "string") {
|
|
79
|
-
const fallbackResponse = await this._precacheController.matchPrecache(fallback);
|
|
80
|
-
if (fallbackResponse !== undefined) {
|
|
81
|
-
return fallbackResponse;
|
|
82
|
-
}
|
|
83
|
-
} else if (fallback.matcher(param)) {
|
|
84
|
-
const fallbackResponse = await this._precacheController.matchPrecache(fallback.url);
|
|
85
|
-
if (fallbackResponse !== undefined) {
|
|
86
|
-
return fallbackResponse;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
return undefined;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { Route } from "../Route.js";
|
|
10
|
-
import type { RouteMatchCallback, RouteMatchCallbackOptions } from "../types.js";
|
|
11
|
-
import type { PrecacheRouteOptions } from "../types.js";
|
|
12
|
-
import { generateURLVariations } from "../utils/generateURLVariations.js";
|
|
13
|
-
import { getFriendlyURL } from "../utils/getFriendlyURL.js";
|
|
14
|
-
import { logger } from "../utils/logger.js";
|
|
15
|
-
import type { PrecacheController } from "./PrecacheController.js";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A subclass of {@linkcode Route} that takes a {@linkcode PrecacheController}
|
|
19
|
-
* instance and uses it to match incoming requests and handle fetching
|
|
20
|
-
* responses from the precache.
|
|
21
|
-
* @deprecated
|
|
22
|
-
*/
|
|
23
|
-
export class PrecacheRoute extends Route {
|
|
24
|
-
/**
|
|
25
|
-
* @param precacheController A {@linkcode PrecacheController}
|
|
26
|
-
* instance used to both match requests and respond to `fetch` events.
|
|
27
|
-
* @param options Options to control how requests are matched
|
|
28
|
-
* against the list of precached URLs.
|
|
29
|
-
*/
|
|
30
|
-
constructor(precacheController: PrecacheController, options?: PrecacheRouteOptions) {
|
|
31
|
-
const match: RouteMatchCallback = ({ request }: RouteMatchCallbackOptions) => {
|
|
32
|
-
const urlsToCacheKeys = precacheController.getURLsToCacheKeys();
|
|
33
|
-
for (const possibleURL of generateURLVariations(request.url, options)) {
|
|
34
|
-
const cacheKey = urlsToCacheKeys.get(possibleURL);
|
|
35
|
-
if (cacheKey) {
|
|
36
|
-
const integrity = precacheController.getIntegrityForCacheKey(cacheKey);
|
|
37
|
-
return { cacheKey, integrity };
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
if (process.env.NODE_ENV !== "production") {
|
|
41
|
-
logger.debug(`Precaching did not find a match for ${getFriendlyURL(request.url)}`);
|
|
42
|
-
}
|
|
43
|
-
return;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
super(match, precacheController.strategy);
|
|
47
|
-
}
|
|
48
|
-
}
|