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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { f as finalAssertExports, l as logger, S as SerwistError } from './chunks/timeout.js';
|
|
2
|
+
import { S as Strategy, m as messages, c as cacheOkAndOpaquePlugin } from './chunks/NetworkOnly.js';
|
|
3
|
+
export { a as NetworkFirst, N as NetworkOnly, b as StrategyHandler } from './chunks/NetworkOnly.js';
|
|
4
|
+
|
|
5
|
+
class CacheFirst extends Strategy {
|
|
6
|
+
async _handle(request, handler) {
|
|
7
|
+
const logs = [];
|
|
8
|
+
if (process.env.NODE_ENV !== "production") {
|
|
9
|
+
finalAssertExports.isInstance(request, Request, {
|
|
10
|
+
moduleName: "serwist/strategies",
|
|
11
|
+
className: this.constructor.name,
|
|
12
|
+
funcName: "makeRequest",
|
|
13
|
+
paramName: "request"
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
let response = await handler.cacheMatch(request);
|
|
17
|
+
let error = undefined;
|
|
18
|
+
if (!response) {
|
|
19
|
+
if (process.env.NODE_ENV !== "production") {
|
|
20
|
+
logs.push(`No response found in the '${this.cacheName}' cache. Will respond with a network request.`);
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
response = await handler.fetchAndCachePut(request);
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (err instanceof Error) {
|
|
26
|
+
error = err;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (process.env.NODE_ENV !== "production") {
|
|
30
|
+
if (response) {
|
|
31
|
+
logs.push("Got response from network.");
|
|
32
|
+
} else {
|
|
33
|
+
logs.push("Unable to get a response from the network.");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
if (process.env.NODE_ENV !== "production") {
|
|
38
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (process.env.NODE_ENV !== "production") {
|
|
42
|
+
logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
43
|
+
for (const log of logs){
|
|
44
|
+
logger.log(log);
|
|
45
|
+
}
|
|
46
|
+
messages.printFinalResponse(response);
|
|
47
|
+
logger.groupEnd();
|
|
48
|
+
}
|
|
49
|
+
if (!response) {
|
|
50
|
+
throw new SerwistError("no-response", {
|
|
51
|
+
url: request.url,
|
|
52
|
+
error
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
return response;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class CacheOnly extends Strategy {
|
|
60
|
+
async _handle(request, handler) {
|
|
61
|
+
if (process.env.NODE_ENV !== "production") {
|
|
62
|
+
finalAssertExports.isInstance(request, Request, {
|
|
63
|
+
moduleName: "serwist/strategies",
|
|
64
|
+
className: this.constructor.name,
|
|
65
|
+
funcName: "makeRequest",
|
|
66
|
+
paramName: "request"
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const response = await handler.cacheMatch(request);
|
|
70
|
+
if (process.env.NODE_ENV !== "production") {
|
|
71
|
+
logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
72
|
+
if (response) {
|
|
73
|
+
logger.log(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
74
|
+
messages.printFinalResponse(response);
|
|
75
|
+
} else {
|
|
76
|
+
logger.log(`No response found in the '${this.cacheName}' cache.`);
|
|
77
|
+
}
|
|
78
|
+
logger.groupEnd();
|
|
79
|
+
}
|
|
80
|
+
if (!response) {
|
|
81
|
+
throw new SerwistError("no-response", {
|
|
82
|
+
url: request.url
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return response;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
class StaleWhileRevalidate extends Strategy {
|
|
90
|
+
constructor(options = {}){
|
|
91
|
+
super(options);
|
|
92
|
+
if (!this.plugins.some((p)=>"cacheWillUpdate" in p)) {
|
|
93
|
+
this.plugins.unshift(cacheOkAndOpaquePlugin);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async _handle(request, handler) {
|
|
97
|
+
const logs = [];
|
|
98
|
+
if (process.env.NODE_ENV !== "production") {
|
|
99
|
+
finalAssertExports.isInstance(request, Request, {
|
|
100
|
+
moduleName: "serwist/strategies",
|
|
101
|
+
className: this.constructor.name,
|
|
102
|
+
funcName: "handle",
|
|
103
|
+
paramName: "request"
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
const fetchAndCachePromise = handler.fetchAndCachePut(request).catch(()=>{});
|
|
107
|
+
void handler.waitUntil(fetchAndCachePromise);
|
|
108
|
+
let response = await handler.cacheMatch(request);
|
|
109
|
+
let error = undefined;
|
|
110
|
+
if (response) {
|
|
111
|
+
if (process.env.NODE_ENV !== "production") {
|
|
112
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache. Will update with the network response in the background.`);
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
if (process.env.NODE_ENV !== "production") {
|
|
116
|
+
logs.push(`No response found in the '${this.cacheName}' cache. Will wait for the network response.`);
|
|
117
|
+
}
|
|
118
|
+
try {
|
|
119
|
+
response = await fetchAndCachePromise;
|
|
120
|
+
} catch (err) {
|
|
121
|
+
if (err instanceof Error) {
|
|
122
|
+
error = err;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (process.env.NODE_ENV !== "production") {
|
|
127
|
+
logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
128
|
+
for (const log of logs){
|
|
129
|
+
logger.log(log);
|
|
130
|
+
}
|
|
131
|
+
messages.printFinalResponse(response);
|
|
132
|
+
logger.groupEnd();
|
|
133
|
+
}
|
|
134
|
+
if (!response) {
|
|
135
|
+
throw new SerwistError("no-response", {
|
|
136
|
+
url: request.url,
|
|
137
|
+
error
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return response;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { CacheFirst, CacheOnly, StaleWhileRevalidate, Strategy };
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import type { RouteHandlerCallback, SerwistPlugin } from "../types.js";
|
|
2
|
+
import type { Strategy } from "../strategies/Strategy.js";
|
|
3
|
+
import type { CleanupResult, InstallResult, PrecacheEntry } from "../types.js";
|
|
4
|
+
interface PrecacheControllerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* The cache to use for precaching.
|
|
7
|
+
*/
|
|
8
|
+
cacheName?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Plugins to use when precaching as well as responding to fetch
|
|
11
|
+
* events for precached assets.
|
|
12
|
+
*/
|
|
13
|
+
plugins?: SerwistPlugin[];
|
|
14
|
+
/**
|
|
15
|
+
* Whether to attempt to get the response from the network if there's
|
|
16
|
+
* a precache miss.
|
|
17
|
+
*/
|
|
18
|
+
fallbackToNetwork?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* The number of precache requests that should be made concurrently.
|
|
21
|
+
*
|
|
22
|
+
* @default 1
|
|
23
|
+
*/
|
|
24
|
+
concurrentPrecaching?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Performs efficient precaching of assets.
|
|
28
|
+
* @deprecated
|
|
29
|
+
*/
|
|
30
|
+
export declare class PrecacheController {
|
|
31
|
+
private _installAndActiveListenersAdded?;
|
|
32
|
+
private _concurrentPrecaching;
|
|
33
|
+
private readonly _strategy;
|
|
34
|
+
private readonly _urlsToCacheKeys;
|
|
35
|
+
private readonly _urlsToCacheModes;
|
|
36
|
+
private readonly _cacheKeysToIntegrities;
|
|
37
|
+
/**
|
|
38
|
+
* Create a new PrecacheController.
|
|
39
|
+
*
|
|
40
|
+
* @param options
|
|
41
|
+
*/
|
|
42
|
+
constructor({ cacheName, plugins, fallbackToNetwork, concurrentPrecaching }?: PrecacheControllerOptions);
|
|
43
|
+
/**
|
|
44
|
+
* The strategy created by this controller and
|
|
45
|
+
* used to cache assets and respond to fetch events.
|
|
46
|
+
*/
|
|
47
|
+
get strategy(): Strategy;
|
|
48
|
+
/**
|
|
49
|
+
* Adds items to the precache list, removing any duplicates and
|
|
50
|
+
* stores the files in the precache cache when the service
|
|
51
|
+
* worker installs.
|
|
52
|
+
*
|
|
53
|
+
* This method can be called multiple times.
|
|
54
|
+
*
|
|
55
|
+
* @param entries Array of entries to precache.
|
|
56
|
+
*/
|
|
57
|
+
precache(entries: (PrecacheEntry | string)[]): void;
|
|
58
|
+
/**
|
|
59
|
+
* This method will add items to the precache list, removing duplicates
|
|
60
|
+
* and ensuring the information is valid.
|
|
61
|
+
*
|
|
62
|
+
* @param entries Array of entries to precache.
|
|
63
|
+
*/
|
|
64
|
+
addToCacheList(entries: (PrecacheEntry | string)[]): void;
|
|
65
|
+
/**
|
|
66
|
+
* Precaches new and updated assets. Call this method from the service worker
|
|
67
|
+
* install event.
|
|
68
|
+
*
|
|
69
|
+
* Note: this method calls `event.waitUntil()` for you, so you do not need
|
|
70
|
+
* to call it yourself in your event handlers.
|
|
71
|
+
*
|
|
72
|
+
* @param event
|
|
73
|
+
* @returns
|
|
74
|
+
*/
|
|
75
|
+
install(event: ExtendableEvent): Promise<InstallResult>;
|
|
76
|
+
/**
|
|
77
|
+
* Deletes assets that are no longer present in the current precache manifest.
|
|
78
|
+
* Call this method from the service worker activate event.
|
|
79
|
+
*
|
|
80
|
+
* Note: this method calls `event.waitUntil()` for you, so you do not need
|
|
81
|
+
* to call it yourself in your event handlers.
|
|
82
|
+
*
|
|
83
|
+
* @param event
|
|
84
|
+
* @returns
|
|
85
|
+
*/
|
|
86
|
+
activate(event: ExtendableEvent): Promise<CleanupResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Returns a mapping of a precached URL to the corresponding cache key, taking
|
|
89
|
+
* into account the revision information for the URL.
|
|
90
|
+
*
|
|
91
|
+
* @returns A URL to cache key mapping.
|
|
92
|
+
*/
|
|
93
|
+
getURLsToCacheKeys(): Map<string, string>;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a list of all the URLs that have been precached by the current
|
|
96
|
+
* service worker.
|
|
97
|
+
*
|
|
98
|
+
* @returns The precached URLs.
|
|
99
|
+
*/
|
|
100
|
+
getCachedURLs(): string[];
|
|
101
|
+
/**
|
|
102
|
+
* Returns the cache key used for storing a given URL. If that URL is
|
|
103
|
+
* unversioned, like `/index.html', then the cache key will be the original
|
|
104
|
+
* URL with a search parameter appended to it.
|
|
105
|
+
*
|
|
106
|
+
* @param url A URL whose cache key you want to look up.
|
|
107
|
+
* @returns The versioned URL that corresponds to a cache key
|
|
108
|
+
* for the original URL, or undefined if that URL isn't precached.
|
|
109
|
+
*/
|
|
110
|
+
getCacheKeyForURL(url: string): string | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* @param url A cache key whose SRI you want to look up.
|
|
113
|
+
* @returns The subresource integrity associated with the cache key,
|
|
114
|
+
* or undefined if it's not set.
|
|
115
|
+
*/
|
|
116
|
+
getIntegrityForCacheKey(cacheKey: string): string | undefined;
|
|
117
|
+
/**
|
|
118
|
+
* This acts as a drop-in replacement for
|
|
119
|
+
* [`cache.match()`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match)
|
|
120
|
+
* with the following differences:
|
|
121
|
+
*
|
|
122
|
+
* - It knows what the name of the precache is, and only checks in that cache.
|
|
123
|
+
* - It allows you to pass in an "original" URL without versioning parameters,
|
|
124
|
+
* and it will automatically look up the correct cache key for the currently
|
|
125
|
+
* active revision of that URL.
|
|
126
|
+
*
|
|
127
|
+
* E.g., `matchPrecache('index.html')` will find the correct precached
|
|
128
|
+
* response for the currently active service worker, even if the actual cache
|
|
129
|
+
* key is `'/index.html?__WB_REVISION__=1234abcd'`.
|
|
130
|
+
*
|
|
131
|
+
* @param request The key (without revisioning parameters)
|
|
132
|
+
* to look up in the precache.
|
|
133
|
+
* @returns
|
|
134
|
+
*/
|
|
135
|
+
matchPrecache(request: string | Request): Promise<Response | undefined>;
|
|
136
|
+
/**
|
|
137
|
+
* Returns a function that looks up `url` in the precache (taking into
|
|
138
|
+
* account revision information), and returns the corresponding `Response`.
|
|
139
|
+
*
|
|
140
|
+
* @param url The precached URL which will be used to lookup the response.
|
|
141
|
+
* @return
|
|
142
|
+
*/
|
|
143
|
+
createHandlerBoundToURL(url: string): RouteHandlerCallback;
|
|
144
|
+
}
|
|
145
|
+
export {};
|
|
146
|
+
//# sourceMappingURL=PrecacheController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrecacheController.d.ts","sourceRoot":"","sources":["../../src/legacy/PrecacheController.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAU/E,UAAU,yBAAyB;IACjC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,+BAA+B,CAAC,CAAU;IAClD,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkC;IACnE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6G;IAC/I,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAkC;IAE1E;;;;OAIG;gBACS,EAAE,SAAS,EAAE,OAAY,EAAE,iBAAwB,EAAE,oBAAwB,EAAE,GAAE,yBAA8B;IAY3H;;;OAGG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAEvB;IAED;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI;IAUnD;;;;;OAKG;IACH,cAAc,CAAC,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI;IAwDzD;;;;;;;;;OASG;IACH,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAmCvD;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAuBxD;;;;;OAKG;IACH,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIzC;;;;;OAKG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAKlD;;;;OAIG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI7D;;;;;;;;;;;;;;;;;OAiBG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAU7E;;;;;;OAMG;IACH,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB;CAY3D"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { HandlerDidErrorCallbackParam, SerwistPlugin } from "../types.js";
|
|
2
|
+
import type { PrecacheController } from "./PrecacheController.js";
|
|
3
|
+
/**
|
|
4
|
+
* @deprecated
|
|
5
|
+
*/
|
|
6
|
+
export interface PrecacheFallbackEntry {
|
|
7
|
+
/**
|
|
8
|
+
* A function that checks whether the fallback entry can be used
|
|
9
|
+
* for a request.
|
|
10
|
+
*/
|
|
11
|
+
matcher: (param: HandlerDidErrorCallbackParam) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* A precached URL to be used as a fallback.
|
|
14
|
+
*/
|
|
15
|
+
url: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* @deprecated
|
|
19
|
+
*/
|
|
20
|
+
export interface PrecacheFallbackPluginOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Precached URLs to be used as the fallback
|
|
23
|
+
* if the associated strategy can't generate a response.
|
|
24
|
+
*/
|
|
25
|
+
fallbackUrls: (string | PrecacheFallbackEntry)[];
|
|
26
|
+
/**
|
|
27
|
+
* An optional `PrecacheController` instance. If not provided, the default
|
|
28
|
+
* `PrecacheController` will be used.
|
|
29
|
+
*/
|
|
30
|
+
precacheController?: PrecacheController;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* `PrecacheFallbackPlugin` allows you to specify offline fallbacks
|
|
34
|
+
* to be used when a given strategy is unable to generate a response.
|
|
35
|
+
*
|
|
36
|
+
* It does this by intercepting the `handlerDidError` plugin callback
|
|
37
|
+
* and returning a precached response, taking the expected revision parameter
|
|
38
|
+
* into account automatically.
|
|
39
|
+
*
|
|
40
|
+
* Unless you explicitly pass in a `PrecacheController` instance to the
|
|
41
|
+
* constructor, the default instance will be used. Generally speaking, most
|
|
42
|
+
* developers will end up using the default.
|
|
43
|
+
*
|
|
44
|
+
* @deprecated
|
|
45
|
+
*/
|
|
46
|
+
export declare class PrecacheFallbackPlugin implements SerwistPlugin {
|
|
47
|
+
private readonly _fallbackUrls;
|
|
48
|
+
private readonly _precacheController;
|
|
49
|
+
/**
|
|
50
|
+
* Constructs a new `PrecacheFallbackPlugin` with the associated `fallbackUrls`.
|
|
51
|
+
*
|
|
52
|
+
* @param config
|
|
53
|
+
*/
|
|
54
|
+
constructor({ fallbackUrls, precacheController }: PrecacheFallbackPluginOptions);
|
|
55
|
+
/**
|
|
56
|
+
* @returns The precache response for one of the fallback URLs, or `undefined` if
|
|
57
|
+
* nothing satisfies the conditions.
|
|
58
|
+
* @private
|
|
59
|
+
*/
|
|
60
|
+
handlerDidError(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=PrecacheFallbackPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrecacheFallbackPlugin.d.ts","sourceRoot":"","sources":["../../src/legacy/PrecacheFallbackPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,4BAA4B,KAAK,OAAO,CAAC;IAC1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,YAAY,EAAE,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,CAAC;IACjD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqC;IACnE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;IAEzD;;;;OAIG;gBACS,EAAE,YAAY,EAAE,kBAAkB,EAAE,EAAE,6BAA6B;IAK/E;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,4BAA4B;CAgB1D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Route } from "../Route.js";
|
|
2
|
+
import type { PrecacheRouteOptions } from "../types.js";
|
|
3
|
+
import type { PrecacheController } from "./PrecacheController.js";
|
|
4
|
+
/**
|
|
5
|
+
* A subclass of `serwist.Route` that takes a `serwist/legacy.PrecacheController`
|
|
6
|
+
* instance and uses it to match incoming requests and handle fetching
|
|
7
|
+
* responses from the precache.
|
|
8
|
+
* @deprecated
|
|
9
|
+
*/
|
|
10
|
+
export declare class PrecacheRoute extends Route {
|
|
11
|
+
/**
|
|
12
|
+
* @param precacheController A `PrecacheController`
|
|
13
|
+
* instance used to both match requests and respond to fetch events.
|
|
14
|
+
* @param options Options to control how requests are matched
|
|
15
|
+
* against the list of precached URLs.
|
|
16
|
+
*/
|
|
17
|
+
constructor(precacheController: PrecacheController, options?: PrecacheRouteOptions);
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=PrecacheRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrecacheRoute.d.ts","sourceRoot":"","sources":["../../src/legacy/PrecacheRoute.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC;;;;;OAKG;gBACS,kBAAkB,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,oBAAoB;CAkBnF"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { RouteHandler, RouteHandlerCallbackOptions, RouteMatchCallback, RouteMatchCallbackOptions } from "../types.js";
|
|
2
|
+
import type { Route } from "../Route.js";
|
|
3
|
+
import type { HTTPMethod } from "../constants.js";
|
|
4
|
+
/**
|
|
5
|
+
* `Router` can be used to process a `FetchEvent` using one or more `Route`(s), responding with a `Response`
|
|
6
|
+
* if a matching route exists.
|
|
7
|
+
*
|
|
8
|
+
* If no `Route` matches given a `Request`, the `Router` will use the default handler if one is defined.
|
|
9
|
+
*
|
|
10
|
+
* Should the matching Route throw an error, the Router will use the catch handler if one is defined to
|
|
11
|
+
* gracefully deal with issues and respond with a `Request`.
|
|
12
|
+
*
|
|
13
|
+
* If a `Request` matches multiple routes, the earliest registered route will be used to respond to the `Request`.
|
|
14
|
+
* @deprecated
|
|
15
|
+
*/
|
|
16
|
+
export declare class Router {
|
|
17
|
+
private readonly _routes;
|
|
18
|
+
private readonly _defaultHandlerMap;
|
|
19
|
+
private _fetchListenerHandler;
|
|
20
|
+
private _cacheListenerHandler;
|
|
21
|
+
private _catchHandler?;
|
|
22
|
+
/**
|
|
23
|
+
* Initializes a new Router.
|
|
24
|
+
*/
|
|
25
|
+
constructor();
|
|
26
|
+
/**
|
|
27
|
+
* @returns routes A `Map` of HTTP method name (`'GET'`, etc.) to an array of all the corresponding `Route`
|
|
28
|
+
* instances that are registered.
|
|
29
|
+
*/
|
|
30
|
+
get routes(): Map<HTTPMethod, Route[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Adds a `fetch` event listener to respond to events when a `Route` matches
|
|
33
|
+
* the event's request. Effectively no-op if `addFEtchListener` has been
|
|
34
|
+
* called, but `removeFetchListener` has not.
|
|
35
|
+
*/
|
|
36
|
+
addFetchListener(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Removes `fetch` event listener added by `addFetchListener`.
|
|
39
|
+
* Effectively no-op if either `addFetchListener` has not been called or,
|
|
40
|
+
* if it has, so has `removeFetchListener`.
|
|
41
|
+
*/
|
|
42
|
+
removeFetchListener(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Adds a `message` event listener for URLs to cache from the window.
|
|
45
|
+
* This is useful to cache resources loaded on the page prior to when the
|
|
46
|
+
* service worker started controlling it. Effectively no-op if `addCacheListener`
|
|
47
|
+
* has been called, but `removeCacheListener` hasn't.
|
|
48
|
+
*
|
|
49
|
+
* The format of the message data sent from the window should be as follows.
|
|
50
|
+
* Where the `urlsToCache` array may consist of URL strings or an array of
|
|
51
|
+
* URL string + `requestInit` object (the same as you'd pass to `fetch()`).
|
|
52
|
+
*
|
|
53
|
+
* ```
|
|
54
|
+
* {
|
|
55
|
+
* type: 'CACHE_URLS',
|
|
56
|
+
* payload: {
|
|
57
|
+
* urlsToCache: [
|
|
58
|
+
* './script1.js',
|
|
59
|
+
* './script2.js',
|
|
60
|
+
* ['./script3.js', {mode: 'no-cors'}],
|
|
61
|
+
* ],
|
|
62
|
+
* },
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
addCacheListener(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Removes the `message` event listener added by `addCacheListener`.
|
|
69
|
+
* Effectively no-op if either `addCacheListener` has not been called or,
|
|
70
|
+
* if it has, so has `removeCacheListener`.
|
|
71
|
+
*/
|
|
72
|
+
removeCacheListener(): void;
|
|
73
|
+
/**
|
|
74
|
+
* Apply the routing rules to a `FetchEvent` object to get a `Response` from an
|
|
75
|
+
* appropriate `Route`'s handler.
|
|
76
|
+
*
|
|
77
|
+
* @param options
|
|
78
|
+
* @returns A promise is returned if a registered route can handle the request.
|
|
79
|
+
* If there is no matching route and there's no `defaultHandler`, `undefined`
|
|
80
|
+
* is returned.
|
|
81
|
+
*/
|
|
82
|
+
handleRequest({ request, event, }: {
|
|
83
|
+
/**
|
|
84
|
+
* The request to handle.
|
|
85
|
+
*/
|
|
86
|
+
request: Request;
|
|
87
|
+
/**
|
|
88
|
+
* The event that triggered the request.
|
|
89
|
+
*/
|
|
90
|
+
event: ExtendableEvent;
|
|
91
|
+
}): Promise<Response> | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Checks a request and URL (and optionally an event) against the list of
|
|
94
|
+
* registered routes, and if there's a match, returns the corresponding
|
|
95
|
+
* route along with any params generated by the match.
|
|
96
|
+
*
|
|
97
|
+
* @param options
|
|
98
|
+
* @returns An object with `route` and `params` properties. They are populated
|
|
99
|
+
* if a matching route was found or `undefined` otherwise.
|
|
100
|
+
*/
|
|
101
|
+
findMatchingRoute({ url, sameOrigin, request, event }: RouteMatchCallbackOptions): {
|
|
102
|
+
route?: Route;
|
|
103
|
+
params?: RouteHandlerCallbackOptions["params"];
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Define a default `handler` that's called when no routes explicitly
|
|
107
|
+
* match the incoming request.
|
|
108
|
+
*
|
|
109
|
+
* Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
|
|
110
|
+
*
|
|
111
|
+
* Without a default handler, unmatched requests will go against the
|
|
112
|
+
* network as if there were no service worker present.
|
|
113
|
+
*
|
|
114
|
+
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
115
|
+
* @param method The HTTP method to associate with this default handler. Each method
|
|
116
|
+
* has its own default. Defaults to `'GET'`.
|
|
117
|
+
*/
|
|
118
|
+
setDefaultHandler(handler: RouteHandler, method?: HTTPMethod): void;
|
|
119
|
+
/**
|
|
120
|
+
* If a `Route` throws an error while handling a request, this `handler`
|
|
121
|
+
* will be called and given a chance to provide a response.
|
|
122
|
+
*
|
|
123
|
+
* @param handler A callback function that returns a Promise resulting
|
|
124
|
+
* in a Response.
|
|
125
|
+
*/
|
|
126
|
+
setCatchHandler(handler: RouteHandler): void;
|
|
127
|
+
/**
|
|
128
|
+
* Registers a `RegExp`, string, or function with a caching
|
|
129
|
+
* strategy to the `Router`.
|
|
130
|
+
*
|
|
131
|
+
* @param capture If the capture param is a `Route`, all other arguments will be ignored.
|
|
132
|
+
* @param handler A callback function that returns a `Promise` resulting in a `Response`.
|
|
133
|
+
* This parameter is required if `capture` is not a `Route` object.
|
|
134
|
+
* @param method The HTTP method to match the Route against. Defaults to `'GET'`.
|
|
135
|
+
* @returns The generated `Route`.
|
|
136
|
+
*/
|
|
137
|
+
registerCapture(capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod): Route;
|
|
138
|
+
/**
|
|
139
|
+
* Registers a `Route` with the router.
|
|
140
|
+
*
|
|
141
|
+
* @param route The `Route` to register.
|
|
142
|
+
*/
|
|
143
|
+
registerRoute(route: Route): void;
|
|
144
|
+
/**
|
|
145
|
+
* Unregisters a `Route` with the `Router`.
|
|
146
|
+
*
|
|
147
|
+
* @param route The `Route` to unregister.
|
|
148
|
+
*/
|
|
149
|
+
unregisterRoute(route: Route): void;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=Router.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/legacy/Router.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAsB,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAKhJ,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAgBlD;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsC;IACzE,OAAO,CAAC,qBAAqB,CAA2C;IACxE,OAAO,CAAC,qBAAqB,CAAuD;IACpF,OAAO,CAAC,aAAa,CAAC,CAAqB;IAE3C;;OAEG;;IAMH;;;OAGG;IACH,IAAI,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAErC;IAED;;;;OAIG;IACH,gBAAgB,IAAI,IAAI;IAaxB;;;;OAIG;IACH,mBAAmB,IAAI,IAAI;IAO3B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,gBAAgB,IAAI,IAAI;IAiCxB;;;;OAIG;IACH,mBAAmB,IAAI,IAAI;IAM3B;;;;;;;;OAQG;IACH,aAAa,CAAC,EACZ,OAAO,EACP,KAAK,GACN,EAAE;QACD;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;WAEG;QACH,KAAK,EAAE,eAAe,CAAC;KACxB,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS;IA8HjC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,yBAAyB,GAAG;QACjF,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,CAAC,EAAE,2BAA2B,CAAC,QAAQ,CAAC,CAAC;KAChD;IA+CD;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAE,UAA0B,GAAG,IAAI;IAIlF;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAI5C;;;;;;;;;OASG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,KAAK;IAM1H;;;;OAIG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IA+CjC;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAcpC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addPlugins.d.ts","sourceRoot":"","sources":["../../src/legacy/addPlugins.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,YAAa,aAAa,EAAE,KAAG,IAGrD,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PrecacheRouteOptions } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Add a `fetch` listener to the service worker that will
|
|
4
|
+
* respond to
|
|
5
|
+
* [network requests](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests)
|
|
6
|
+
* with precached assets.
|
|
7
|
+
*
|
|
8
|
+
* Requests for assets that aren't precached, the `FetchEvent` will not be
|
|
9
|
+
* responded to, allowing the event to fall through to other `fetch` event
|
|
10
|
+
* listeners.
|
|
11
|
+
*
|
|
12
|
+
* @param options See `serwist.PrecacheRouteOptions`.
|
|
13
|
+
* @deprecated
|
|
14
|
+
*/
|
|
15
|
+
export declare const addRoute: (options?: PrecacheRouteOptions) => void;
|
|
16
|
+
//# sourceMappingURL=addRoute.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addRoute.d.ts","sourceRoot":"","sources":["../../src/legacy/addRoute.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAKxD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,aAAc,oBAAoB,KAAG,IAGzD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { RouteHandlerCallback } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Helper function that calls `PrecacheController#createHandlerBoundToURL`
|
|
4
|
+
* on the default `PrecacheController` instance.
|
|
5
|
+
*
|
|
6
|
+
* If you are creating your own `PrecacheController`, then call the
|
|
7
|
+
* `PrecacheController#createHandlerBoundToURL` on that instance,
|
|
8
|
+
* instead of using this function.
|
|
9
|
+
*
|
|
10
|
+
* @param url The precached URL which will be used to lookup the
|
|
11
|
+
* `Response`.
|
|
12
|
+
* @param fallbackToNetwork Whether to attempt to get the
|
|
13
|
+
* response from the network if there's a precache miss.
|
|
14
|
+
* @return
|
|
15
|
+
* @deprecated
|
|
16
|
+
*/
|
|
17
|
+
export declare const createHandlerBoundToURL: (url: string) => RouteHandlerCallback;
|
|
18
|
+
//# sourceMappingURL=createHandlerBoundToURL.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createHandlerBoundToURL.d.ts","sourceRoot":"","sources":["../../src/legacy/createHandlerBoundToURL.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB,QAAS,MAAM,KAAG,oBAGrD,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { PrecacheRouteOptions, RuntimeCaching } from "../types.js";
|
|
2
|
+
import type { PrecacheController } from "./PrecacheController.js";
|
|
3
|
+
import type { Router } from "./Router.js";
|
|
4
|
+
import type { PrecacheFallbackEntry } from "./PrecacheFallbackPlugin.js";
|
|
5
|
+
export interface FallbackEntry extends PrecacheFallbackEntry {
|
|
6
|
+
/**
|
|
7
|
+
* The revision used for precaching.
|
|
8
|
+
*/
|
|
9
|
+
revision: string;
|
|
10
|
+
}
|
|
11
|
+
export interface FallbacksOptions {
|
|
12
|
+
/**
|
|
13
|
+
* A list of fallback entries.
|
|
14
|
+
*/
|
|
15
|
+
entries: FallbackEntry[];
|
|
16
|
+
/**
|
|
17
|
+
* Precache options that will be used for your
|
|
18
|
+
* fallback entries.
|
|
19
|
+
*/
|
|
20
|
+
precacheOptions?: PrecacheRouteOptions;
|
|
21
|
+
}
|
|
22
|
+
export interface FallbacksOptions {
|
|
23
|
+
/**
|
|
24
|
+
* An optional `PrecacheController` instance. If not provided, the singleton
|
|
25
|
+
* `PrecacheController` will be used.
|
|
26
|
+
*/
|
|
27
|
+
precacheController?: PrecacheController;
|
|
28
|
+
/**
|
|
29
|
+
* An optional `Router` instance. If not provided, the singleton `Router`
|
|
30
|
+
* will be used.
|
|
31
|
+
*/
|
|
32
|
+
router?: Router;
|
|
33
|
+
/**
|
|
34
|
+
* Your previous list of caching strategies.
|
|
35
|
+
*/
|
|
36
|
+
runtimeCaching: RuntimeCaching[];
|
|
37
|
+
/**
|
|
38
|
+
* A list of fallback entries.
|
|
39
|
+
*/
|
|
40
|
+
entries: FallbackEntry[];
|
|
41
|
+
/**
|
|
42
|
+
* Precache options that will be used for your
|
|
43
|
+
* fallback entries.
|
|
44
|
+
*/
|
|
45
|
+
precacheOptions?: PrecacheRouteOptions;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Precaches routes so that they can be used as a fallback when
|
|
49
|
+
* a Strategy fails to generate a response.
|
|
50
|
+
*
|
|
51
|
+
* Note: This function mutates `runtimeCaching`. It also precaches the URLs
|
|
52
|
+
* defined in `entries`, so you must NOT precache any of them beforehand.
|
|
53
|
+
*
|
|
54
|
+
* @param options
|
|
55
|
+
* @returns The modified `runtimeCaching` array.
|
|
56
|
+
* @deprecated
|
|
57
|
+
*/
|
|
58
|
+
export declare const fallbacks: ({ precacheController, router, runtimeCaching, entries, precacheOptions, }: FallbacksOptions) => RuntimeCaching[];
|
|
59
|
+
//# sourceMappingURL=fallbacks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallbacks.d.ts","sourceRoot":"","sources":["../../src/legacy/fallbacks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC;;OAEG;IACH,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,8EAMnB,gBAAgB,KAAG,cAAc,EAqBnC,CAAC"}
|