serwist 9.1.0-preview.0 → 10.0.0-preview.2
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/NavigationRoute.d.ts.map +1 -1
- package/dist/RegExpRoute.d.ts.map +1 -1
- package/dist/Route.d.ts.map +1 -1
- package/dist/Serwist.d.ts +75 -53
- package/dist/Serwist.d.ts.map +1 -1
- package/dist/cacheNames.d.ts.map +1 -1
- package/dist/chunks/waitUntil.js +49 -42
- package/dist/copyResponse.d.ts.map +1 -1
- package/dist/index.d.ts +11 -36
- 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 +1918 -248
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts +2 -2
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -1
- package/dist/lib/backgroundSync/StorableRequest.d.ts.map +1 -1
- package/dist/lib/backgroundSync/index.d.ts +6 -0
- package/dist/lib/backgroundSync/index.d.ts.map +1 -0
- package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -1
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts +2 -2
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -1
- package/dist/lib/broadcastUpdate/index.d.ts +6 -0
- package/dist/lib/broadcastUpdate/index.d.ts.map +1 -0
- package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +1 -1
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts +3 -3
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -1
- package/dist/lib/cacheableResponse/index.d.ts +4 -0
- package/dist/lib/cacheableResponse/index.d.ts.map +1 -0
- package/dist/{legacy/utils → lib/controllers/PrecacheController}/PrecacheCacheKeyPlugin.d.ts +4 -4
- package/dist/lib/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/{legacy → lib/controllers/PrecacheController}/PrecacheController.d.ts +77 -64
- package/dist/lib/controllers/PrecacheController/PrecacheController.d.ts.map +1 -0
- package/dist/lib/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts +14 -0
- package/dist/lib/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +1 -0
- package/dist/{PrecacheRoute.d.ts → lib/controllers/PrecacheController/PrecacheRoute.d.ts} +4 -5
- package/dist/lib/controllers/PrecacheController/PrecacheRoute.d.ts.map +1 -0
- package/dist/lib/{strategies → controllers/PrecacheController}/PrecacheStrategy.d.ts +6 -6
- package/dist/lib/controllers/PrecacheController/PrecacheStrategy.d.ts.map +1 -0
- package/dist/lib/controllers/PrecacheController/parsePrecacheOptions.d.ts +25 -0
- package/dist/lib/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +1 -0
- package/dist/lib/controllers/RuntimeCacheController.d.ts +70 -0
- package/dist/lib/controllers/RuntimeCacheController.d.ts.map +1 -0
- package/dist/lib/controllers/index.d.ts +4 -0
- package/dist/lib/controllers/index.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/googleAnalytics/index.d.ts +3 -0
- package/dist/lib/googleAnalytics/index.d.ts.map +1 -0
- package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +1 -1
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts +15 -9
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -1
- package/dist/lib/precaching/index.d.ts +3 -0
- package/dist/lib/precaching/index.d.ts.map +1 -0
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts +3 -3
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -1
- package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +1 -1
- package/dist/lib/rangeRequests/index.d.ts +3 -0
- package/dist/lib/rangeRequests/index.d.ts.map +1 -0
- package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -1
- package/dist/lib/rangeRequests/utils/parseRangeHeader.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/navigationPreload.d.ts.map +1 -1
- package/dist/registerQuotaErrorCallback.d.ts.map +1 -1
- package/dist/setCacheNameDetails.d.ts +1 -1
- package/dist/setCacheNameDetails.d.ts.map +1 -1
- package/dist/types.d.ts +35 -64
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/SerwistError.d.ts +1 -1
- package/dist/utils/SerwistError.d.ts.map +1 -1
- package/dist/utils/cleanupOutdatedCaches.d.ts.map +1 -1
- package/dist/utils/createCacheKey.d.ts.map +1 -1
- package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -1
- package/dist/utils/getFriendlyURL.d.ts.map +1 -1
- package/dist/utils/normalizeHandler.d.ts.map +1 -1
- 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/dist/utils/printCleanupDetails.d.ts.map +1 -1
- package/dist/utils/printInstallDetails.d.ts.map +1 -1
- package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -1
- package/dist/utils/waitUntil.d.ts.map +1 -1
- package/package.json +29 -13
- package/src/NavigationRoute.ts +2 -2
- package/src/RegExpRoute.ts +2 -2
- package/src/Route.ts +2 -2
- package/src/Serwist.ts +170 -271
- package/src/cacheNames.ts +1 -1
- package/src/copyResponse.ts +2 -2
- package/src/index.internal.ts +16 -16
- package/src/index.ts +68 -93
- package/src/lib/backgroundSync/BackgroundSyncPlugin.ts +2 -2
- package/src/lib/backgroundSync/BackgroundSyncQueue.ts +4 -4
- package/src/lib/backgroundSync/BackgroundSyncQueueStore.ts +1 -1
- package/src/lib/backgroundSync/StorableRequest.ts +1 -1
- package/src/lib/backgroundSync/index.ts +5 -0
- package/src/lib/broadcastUpdate/BroadcastCacheUpdate.ts +4 -4
- package/src/lib/broadcastUpdate/BroadcastUpdatePlugin.ts +2 -2
- package/src/lib/broadcastUpdate/index.ts +5 -0
- package/src/lib/broadcastUpdate/responsesAreSame.ts +2 -2
- package/src/lib/cacheableResponse/CacheableResponse.ts +4 -4
- package/src/lib/cacheableResponse/CacheableResponsePlugin.ts +3 -3
- package/src/lib/cacheableResponse/index.ts +3 -0
- package/src/{legacy/utils → lib/controllers/PrecacheController}/PrecacheCacheKeyPlugin.ts +5 -6
- package/src/lib/controllers/PrecacheController/PrecacheController.ts +328 -0
- package/src/{utils → lib/controllers/PrecacheController}/PrecacheInstallReportPlugin.ts +5 -5
- package/src/{PrecacheRoute.ts → lib/controllers/PrecacheController/PrecacheRoute.ts} +11 -12
- package/src/lib/{strategies → controllers/PrecacheController}/PrecacheStrategy.ts +13 -13
- package/src/lib/controllers/PrecacheController/parsePrecacheOptions.ts +46 -0
- package/src/lib/controllers/RuntimeCacheController.ts +119 -0
- package/src/lib/controllers/index.ts +3 -0
- package/src/lib/expiration/CacheExpiration.ts +3 -3
- package/src/lib/expiration/ExpirationPlugin.ts +8 -8
- package/src/lib/expiration/index.ts +3 -0
- package/src/lib/googleAnalytics/index.ts +2 -0
- package/src/lib/googleAnalytics/initializeGoogleAnalytics.ts +5 -5
- package/src/lib/precaching/PrecacheFallbackPlugin.ts +23 -12
- package/src/lib/precaching/index.ts +2 -0
- package/src/lib/rangeRequests/RangeRequestsPlugin.ts +3 -3
- package/src/lib/rangeRequests/createPartialResponse.ts +3 -3
- package/src/lib/rangeRequests/index.ts +2 -0
- package/src/lib/rangeRequests/utils/calculateEffectiveBoundaries.ts +2 -2
- package/src/lib/rangeRequests/utils/parseRangeHeader.ts +2 -2
- package/src/lib/strategies/CacheFirst.ts +3 -3
- package/src/lib/strategies/CacheOnly.ts +3 -3
- package/src/lib/strategies/NetworkFirst.ts +3 -3
- package/src/lib/strategies/NetworkOnly.ts +4 -4
- package/src/lib/strategies/StaleWhileRevalidate.ts +3 -3
- 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/models/messages/messages.ts +3 -3
- package/src/navigationPreload.ts +1 -1
- package/src/registerQuotaErrorCallback.ts +2 -2
- package/src/setCacheNameDetails.ts +4 -4
- package/src/types.ts +56 -68
- package/src/utils/SerwistError.ts +2 -2
- package/src/utils/cacheNames.ts +1 -1
- package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
- package/src/utils/pluginUtils.ts +2 -2
- package/dist/PrecacheRoute.d.ts.map +0 -1
- package/dist/chunks/printInstallDetails.js +0 -1601
- package/dist/chunks/resultingClientExists.js +0 -32
- 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 +0 -10
- 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.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/strategies/PrecacheStrategy.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/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/constants.ts +0 -22
- 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/utils/PrecacheCacheKeyPlugin.ts +0 -33
- package/src/utils/parsePrecacheOptions.ts +0 -47
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
|
|
12
|
+
import { getFriendlyURL } from "#utils/getFriendlyURL.js";
|
|
13
|
+
import { logger } from "#utils/logger.js";
|
|
9
14
|
import { registerQuotaErrorCallback } from "../../registerQuotaErrorCallback.js";
|
|
10
|
-
import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam,
|
|
11
|
-
import { SerwistError } from "../../utils/SerwistError.js";
|
|
12
|
-
import { assert } from "../../utils/assert.js";
|
|
13
|
-
import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
|
|
14
|
-
import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
|
|
15
|
-
import { logger } from "../../utils/logger.js";
|
|
16
|
-
import { CacheExpiration } from "./CacheExpiration.js";
|
|
15
|
+
import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, StrategyPlugin } from "../../types.js";
|
|
17
16
|
import type { Strategy } from "../strategies/Strategy.js";
|
|
17
|
+
import { CacheExpiration } from "./CacheExpiration.js";
|
|
18
18
|
|
|
19
19
|
export interface ExpirationPluginOptions {
|
|
20
20
|
/**
|
|
@@ -66,7 +66,7 @@ export interface ExpirationPluginOptions {
|
|
|
66
66
|
*
|
|
67
67
|
* @see https://serwist.pages.dev/docs/serwist/runtime-caching/plugins/expiration-plugin
|
|
68
68
|
*/
|
|
69
|
-
export class ExpirationPlugin implements
|
|
69
|
+
export class ExpirationPlugin implements StrategyPlugin {
|
|
70
70
|
private readonly _config: ExpirationPluginOptions;
|
|
71
71
|
private _cacheExpirations: Map<string, CacheExpiration>;
|
|
72
72
|
|
|
@@ -6,16 +6,16 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
|
|
10
|
+
import { getFriendlyURL } from "#utils/getFriendlyURL.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
9
12
|
import { Route } from "../../Route.js";
|
|
10
13
|
import type { Serwist } from "../../Serwist.js";
|
|
11
|
-
import { NetworkFirst } from "../../lib/strategies/NetworkFirst.js";
|
|
12
|
-
import { NetworkOnly } from "../../lib/strategies/NetworkOnly.js";
|
|
13
14
|
import type { RouteMatchCallbackOptions } from "../../types.js";
|
|
14
|
-
import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
|
|
15
|
-
import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
|
|
16
|
-
import { logger } from "../../utils/logger.js";
|
|
17
15
|
import { BackgroundSyncPlugin } from "../backgroundSync/BackgroundSyncPlugin.js";
|
|
18
16
|
import type { BackgroundSyncQueue, BackgroundSyncQueueEntry } from "../backgroundSync/BackgroundSyncQueue.js";
|
|
17
|
+
import { NetworkFirst } from "../strategies/NetworkFirst.js";
|
|
18
|
+
import { NetworkOnly } from "../strategies/NetworkOnly.js";
|
|
19
19
|
import {
|
|
20
20
|
ANALYTICS_JS_PATH,
|
|
21
21
|
COLLECT_PATHS_REGEX,
|
|
@@ -6,19 +6,20 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import type { PrecacheController } from "#lib/controllers/PrecacheController/PrecacheController.js";
|
|
9
10
|
import type { Serwist } from "../../Serwist.js";
|
|
10
|
-
import type { HandlerDidErrorCallbackParam,
|
|
11
|
+
import type { HandlerDidErrorCallbackParam, StrategyPlugin } from "../../types.js";
|
|
11
12
|
|
|
12
13
|
export interface PrecacheFallbackEntry {
|
|
14
|
+
/**
|
|
15
|
+
* A precached URL to be used as a fallback.
|
|
16
|
+
*/
|
|
17
|
+
url: string;
|
|
13
18
|
/**
|
|
14
19
|
* A function that checks whether the fallback entry can be used
|
|
15
20
|
* for a request.
|
|
16
21
|
*/
|
|
17
22
|
matcher: (param: HandlerDidErrorCallbackParam) => boolean;
|
|
18
|
-
/**
|
|
19
|
-
* A precached URL to be used as a fallback.
|
|
20
|
-
*/
|
|
21
|
-
url: string;
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export interface PrecacheFallbackPluginOptions {
|
|
@@ -27,10 +28,15 @@ export interface PrecacheFallbackPluginOptions {
|
|
|
27
28
|
* if the associated strategy can't generate a response.
|
|
28
29
|
*/
|
|
29
30
|
fallbackUrls: (string | PrecacheFallbackEntry)[];
|
|
31
|
+
/**
|
|
32
|
+
* A {@linkcode PrecacheController} instance.
|
|
33
|
+
*/
|
|
34
|
+
precacheController: PrecacheController;
|
|
30
35
|
/**
|
|
31
36
|
* A {@linkcode Serwist} instance.
|
|
37
|
+
* @deprecated Use `precacheController` instead.
|
|
32
38
|
*/
|
|
33
|
-
serwist
|
|
39
|
+
serwist?: Serwist;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
@@ -41,18 +47,23 @@ export interface PrecacheFallbackPluginOptions {
|
|
|
41
47
|
* and returning a precached response, taking the expected revision parameter
|
|
42
48
|
* into account automatically.
|
|
43
49
|
*/
|
|
44
|
-
export class PrecacheFallbackPlugin implements
|
|
50
|
+
export class PrecacheFallbackPlugin implements StrategyPlugin {
|
|
45
51
|
private readonly _fallbackUrls: (string | PrecacheFallbackEntry)[];
|
|
46
|
-
private readonly
|
|
52
|
+
private readonly _precacheController: PrecacheController;
|
|
47
53
|
|
|
48
54
|
/**
|
|
49
55
|
* Constructs a new instance with the associated `fallbackUrls`.
|
|
50
56
|
*
|
|
51
57
|
* @param config
|
|
52
58
|
*/
|
|
53
|
-
constructor({ fallbackUrls, serwist }: PrecacheFallbackPluginOptions) {
|
|
59
|
+
constructor({ fallbackUrls, precacheController, serwist }: PrecacheFallbackPluginOptions) {
|
|
54
60
|
this._fallbackUrls = fallbackUrls;
|
|
55
|
-
|
|
61
|
+
// TODO(ducanhgh): remove in v11.
|
|
62
|
+
if (!serwist) {
|
|
63
|
+
this._precacheController = precacheController;
|
|
64
|
+
} else {
|
|
65
|
+
this._precacheController = serwist.precache;
|
|
66
|
+
}
|
|
56
67
|
}
|
|
57
68
|
|
|
58
69
|
/**
|
|
@@ -63,12 +74,12 @@ export class PrecacheFallbackPlugin implements SerwistPlugin {
|
|
|
63
74
|
async handlerDidError(param: HandlerDidErrorCallbackParam) {
|
|
64
75
|
for (const fallback of this._fallbackUrls) {
|
|
65
76
|
if (typeof fallback === "string") {
|
|
66
|
-
const fallbackResponse = await this.
|
|
77
|
+
const fallbackResponse = await this._precacheController.matchPrecache(fallback);
|
|
67
78
|
if (fallbackResponse !== undefined) {
|
|
68
79
|
return fallbackResponse;
|
|
69
80
|
}
|
|
70
81
|
} else if (fallback.matcher(param)) {
|
|
71
|
-
const fallbackResponse = await this.
|
|
82
|
+
const fallbackResponse = await this._precacheController.matchPrecache(fallback.url);
|
|
72
83
|
if (fallbackResponse !== undefined) {
|
|
73
84
|
return fallbackResponse;
|
|
74
85
|
}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { StrategyPlugin } from "../../types.js";
|
|
10
10
|
import { createPartialResponse } from "./createPartialResponse.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -15,7 +15,7 @@ import { createPartialResponse } from "./createPartialResponse.js";
|
|
|
15
15
|
* It does this by intercepting the `cachedResponseWillBeUsed` plugin callback
|
|
16
16
|
* and returning the appropriate subset of the cached response body.
|
|
17
17
|
*/
|
|
18
|
-
export class RangeRequestsPlugin implements
|
|
18
|
+
export class RangeRequestsPlugin implements StrategyPlugin {
|
|
19
19
|
/**
|
|
20
20
|
* @param options
|
|
21
21
|
* @returns If request contains a `Range` header, then a
|
|
@@ -23,7 +23,7 @@ export class RangeRequestsPlugin implements SerwistPlugin {
|
|
|
23
23
|
* returned. Otherwise, `cachedResponse` is returned as-is.
|
|
24
24
|
* @private
|
|
25
25
|
*/
|
|
26
|
-
cachedResponseWillBeUsed:
|
|
26
|
+
cachedResponseWillBeUsed: StrategyPlugin["cachedResponseWillBeUsed"] = async ({ request, cachedResponse }) => {
|
|
27
27
|
// Only return a sliced response if there's something valid in the cache,
|
|
28
28
|
// and there's a Range: header in the request.
|
|
29
29
|
if (cachedResponse && request.headers.has("range")) {
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
11
|
-
import { logger } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
12
12
|
import { calculateEffectiveBoundaries } from "./utils/calculateEffectiveBoundaries.js";
|
|
13
13
|
import { parseRangeHeader } from "./utils/parseRangeHeader.js";
|
|
14
14
|
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @param blob A source blob.
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* @param rangeHeader A `Range` header value.
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
11
|
-
import { logger } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
12
12
|
import { Strategy } from "./Strategy.js";
|
|
13
13
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
14
14
|
import { messages } from "./utils/messages.js";
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
11
|
-
import { logger } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
12
12
|
import { Strategy } from "./Strategy.js";
|
|
13
13
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
14
14
|
import { messages } from "./utils/messages.js";
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
11
|
-
import { logger } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
12
12
|
import type { StrategyOptions } from "./Strategy.js";
|
|
13
13
|
import { Strategy } from "./Strategy.js";
|
|
14
14
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
11
|
-
import { logger } from "
|
|
12
|
-
import { timeout } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
12
|
+
import { timeout } from "#utils/timeout.js";
|
|
13
13
|
import type { StrategyOptions } from "./Strategy.js";
|
|
14
14
|
import { Strategy } from "./Strategy.js";
|
|
15
15
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
11
|
-
import { logger } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
12
12
|
import type { StrategyOptions } from "./Strategy.js";
|
|
13
13
|
import { Strategy } from "./Strategy.js";
|
|
14
14
|
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
|
|
11
|
+
import { getFriendlyURL } from "#utils/getFriendlyURL.js";
|
|
12
|
+
import { logger } from "#utils/logger.js";
|
|
13
|
+
import type { HandlerCallbackOptions, RouteHandlerObject, StrategyPlugin } from "../../types.js";
|
|
14
14
|
import { StrategyHandler } from "./StrategyHandler.js";
|
|
15
15
|
|
|
16
16
|
export interface StrategyOptions {
|
|
@@ -21,7 +21,7 @@ export interface StrategyOptions {
|
|
|
21
21
|
/**
|
|
22
22
|
* [Plugins](https://serwist.pages.dev/docs/serwist/runtime-caching/plugins) to use in conjunction with this caching strategy.
|
|
23
23
|
*/
|
|
24
|
-
plugins?:
|
|
24
|
+
plugins?: StrategyPlugin[];
|
|
25
25
|
/**
|
|
26
26
|
* Options passed to [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796) `fetch()` calls made by
|
|
27
27
|
* this strategy.
|
|
@@ -42,7 +42,7 @@ export interface StrategyOptions {
|
|
|
42
42
|
*/
|
|
43
43
|
export abstract class Strategy implements RouteHandlerObject {
|
|
44
44
|
cacheName: string;
|
|
45
|
-
plugins:
|
|
45
|
+
plugins: StrategyPlugin[];
|
|
46
46
|
fetchOptions?: RequestInit;
|
|
47
47
|
matchOptions?: CacheQueryOptions;
|
|
48
48
|
|
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { timeout } from "../../utils/timeout.js";
|
|
18
|
-
import type { Strategy } from "./Strategy.js";
|
|
9
|
+
import { Deferred } from "#utils/Deferred.js";
|
|
10
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
11
|
+
import { assert } from "#utils/assert.js";
|
|
12
|
+
import { cacheMatchIgnoreParams } from "#utils/cacheMatchIgnoreParams.js";
|
|
13
|
+
import { executeQuotaErrorCallbacks } from "#utils/executeQuotaErrorCallbacks.js";
|
|
14
|
+
import { getFriendlyURL } from "#utils/getFriendlyURL.js";
|
|
15
|
+
import { logger } from "#utils/logger.js";
|
|
16
|
+
import { timeout } from "#utils/timeout.js";
|
|
19
17
|
import type { Route } from "../../Route.js";
|
|
18
|
+
import type { HandlerCallbackOptions, MapLikeObject, StrategyPlugin, StrategyPluginCallbackParam } from "../../types.js";
|
|
19
|
+
import type { Strategy } from "./Strategy.js";
|
|
20
20
|
|
|
21
21
|
function toRequest(input: RequestInfo) {
|
|
22
22
|
return typeof input === "string" ? new Request(input) : input;
|
|
@@ -59,8 +59,8 @@ export class StrategyHandler {
|
|
|
59
59
|
private readonly _strategy: Strategy;
|
|
60
60
|
private readonly _handlerDeferred: Deferred<any>;
|
|
61
61
|
private readonly _extendLifetimePromises: Promise<any>[];
|
|
62
|
-
private readonly _plugins:
|
|
63
|
-
private readonly _pluginStateMap: Map<
|
|
62
|
+
private readonly _plugins: StrategyPlugin[];
|
|
63
|
+
private readonly _pluginStateMap: Map<StrategyPlugin, MapLikeObject>;
|
|
64
64
|
|
|
65
65
|
/**
|
|
66
66
|
* Creates a new instance associated with the passed strategy and event
|
|
@@ -405,7 +405,7 @@ export class StrategyHandler {
|
|
|
405
405
|
* @param name The name of the callback to check for.
|
|
406
406
|
* @returns
|
|
407
407
|
*/
|
|
408
|
-
hasCallback<C extends keyof
|
|
408
|
+
hasCallback<C extends keyof StrategyPlugin>(name: C): boolean {
|
|
409
409
|
for (const plugin of this._strategy.plugins) {
|
|
410
410
|
if (name in plugin) {
|
|
411
411
|
return true;
|
|
@@ -426,10 +426,10 @@ export class StrategyHandler {
|
|
|
426
426
|
* @param param The object to pass as the first (and only) param when executing each callback. This object will be merged with the
|
|
427
427
|
* current plugin state prior to callback execution.
|
|
428
428
|
*/
|
|
429
|
-
async runCallbacks<C extends keyof NonNullable<
|
|
429
|
+
async runCallbacks<C extends keyof NonNullable<StrategyPlugin>>(name: C, param: Omit<StrategyPluginCallbackParam[C], "state">): Promise<void> {
|
|
430
430
|
for (const callback of this.iterateCallbacks(name)) {
|
|
431
431
|
// TODO(philipwalton): not sure why `any` is needed. It seems like
|
|
432
|
-
// this should work with `as
|
|
432
|
+
// this should work with `as StrategyPluginCallbackParam[C]`.
|
|
433
433
|
await callback(param as any);
|
|
434
434
|
}
|
|
435
435
|
}
|
|
@@ -440,18 +440,18 @@ export class StrategyHandler {
|
|
|
440
440
|
* @param name The name fo the callback to run
|
|
441
441
|
* @returns
|
|
442
442
|
*/
|
|
443
|
-
*iterateCallbacks<C extends keyof
|
|
443
|
+
*iterateCallbacks<C extends keyof StrategyPlugin>(name: C): Generator<NonNullable<StrategyPlugin[C]>> {
|
|
444
444
|
for (const plugin of this._strategy.plugins) {
|
|
445
445
|
if (typeof plugin[name] === "function") {
|
|
446
446
|
const state = this._pluginStateMap.get(plugin);
|
|
447
|
-
const statefulCallback = (param: Omit<
|
|
447
|
+
const statefulCallback = (param: Omit<StrategyPluginCallbackParam[C], "state">) => {
|
|
448
448
|
const statefulParam = { ...param, state };
|
|
449
449
|
|
|
450
450
|
// TODO(philipwalton): not sure why `any` is needed. It seems like
|
|
451
451
|
// this should work with `as WorkboxPluginCallbackParam[C]`.
|
|
452
452
|
return plugin[name]!(statefulParam as any);
|
|
453
453
|
};
|
|
454
|
-
yield statefulCallback as NonNullable<
|
|
454
|
+
yield statefulCallback as NonNullable<StrategyPlugin[C]>;
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { CacheFirst } from "./CacheFirst.js";
|
|
2
|
+
export { CacheOnly } from "./CacheOnly.js";
|
|
3
|
+
export type { NetworkFirstOptions } from "./NetworkFirst.js";
|
|
4
|
+
export { NetworkFirst } from "./NetworkFirst.js";
|
|
5
|
+
export type { NetworkOnlyOptions } from "./NetworkOnly.js";
|
|
6
|
+
export { NetworkOnly } from "./NetworkOnly.js";
|
|
7
|
+
export { StaleWhileRevalidate } from "./StaleWhileRevalidate.js";
|
|
8
|
+
export type { StrategyOptions } from "./Strategy.js";
|
|
9
|
+
export { Strategy } from "./Strategy.js";
|
|
10
|
+
export { StrategyHandler } from "./StrategyHandler.js";
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type {
|
|
9
|
+
import type { StrategyPlugin } from "../../../types.js";
|
|
10
10
|
|
|
11
|
-
export const cacheOkAndOpaquePlugin:
|
|
11
|
+
export const cacheOkAndOpaquePlugin: StrategyPlugin = {
|
|
12
12
|
/**
|
|
13
13
|
* Returns a valid response (to allow caching) if the status is 200 (OK) or
|
|
14
14
|
* 0 (opaque).
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { getFriendlyURL } from "
|
|
10
|
-
import { logger } from "
|
|
9
|
+
import { getFriendlyURL } from "#utils/getFriendlyURL.js";
|
|
10
|
+
import { logger } from "#utils/logger.js";
|
|
11
11
|
|
|
12
12
|
export const messages = {
|
|
13
13
|
strategyStart: (strategyName: string, request: Request): string => `Using ${strategyName} to respond to '${getFriendlyURL(request.url)}'`,
|
|
@@ -64,7 +64,7 @@ export const messages = {
|
|
|
64
64
|
},
|
|
65
65
|
|
|
66
66
|
"add-to-cache-list-unexpected-type": ({ entry }) => {
|
|
67
|
-
return `An unexpected entry was passed to 'serwist.Serwist.
|
|
67
|
+
return `An unexpected entry was passed to 'serwist.Serwist.precache.addToCacheList()' The entry '${JSON.stringify(
|
|
68
68
|
entry,
|
|
69
69
|
)}' isn't supported. You must supply an array of strings with one or more characters, objects with a url property or Request objects.`;
|
|
70
70
|
},
|
|
@@ -74,7 +74,7 @@ export const messages = {
|
|
|
74
74
|
throw new Error("Unexpected input to " + `'add-to-cache-list-duplicate-entries' error.`);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
return `Two of the entries passed to 'serwist.Serwist.
|
|
77
|
+
return `Two of the entries passed to 'serwist.Serwist.precache.addToCacheList()' had the URL ${firstEntry} but different revision details. Serwist is unable to cache and version the asset correctly. Please remove one of the entries.`;
|
|
78
78
|
},
|
|
79
79
|
|
|
80
80
|
"plugin-error-request-will-fetch": ({ thrownErrorMessage }) => {
|
|
@@ -210,7 +210,7 @@ export const messages = {
|
|
|
210
210
|
},
|
|
211
211
|
|
|
212
212
|
"add-to-cache-list-conflicting-integrities": ({ url }) => {
|
|
213
|
-
return `Two of the entries passed to 'serwist.Serwist.
|
|
213
|
+
return `Two of the entries passed to 'serwist.Serwist.precache.addToCacheList()' had the URL ${url} with different integrity values. Please remove one of them.`;
|
|
214
214
|
},
|
|
215
215
|
|
|
216
216
|
"missing-precache-entry": ({ cacheName, url }) => {
|
package/src/navigationPreload.ts
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { assert } from "#utils/assert.js";
|
|
10
|
+
import { logger } from "#utils/logger.js";
|
|
9
11
|
import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
|
|
10
|
-
import { assert } from "./utils/assert.js";
|
|
11
|
-
import { logger } from "./utils/logger.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Adds a function to the set of quotaErrorCallbacks that will be executed if
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "
|
|
10
|
-
import { assert } from "
|
|
11
|
-
import type { PartialCacheNameDetails } from "
|
|
12
|
-
import { cacheNames } from "
|
|
9
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
10
|
+
import { assert } from "#utils/assert.js";
|
|
11
|
+
import type { PartialCacheNameDetails } from "#utils/cacheNames.js";
|
|
12
|
+
import { cacheNames } from "#utils/cacheNames.js";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Modifies the default cache names used by Serwist packages.
|