serwist 10.0.0-preview.1 → 10.0.0-preview.3
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 +5 -5
- package/dist/Serwist.d.ts.map +1 -1
- package/dist/chunks/{resultingClientExists.js → waitUntil.js} +117 -117
- package/dist/copyResponse.d.ts.map +1 -1
- package/dist/index.d.ts +11 -37
- 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 +2 -2
- package/dist/index.js +1400 -1387
- 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/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/index.d.ts +4 -0
- package/dist/lib/cacheableResponse/index.d.ts.map +1 -0
- package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheCacheKeyPlugin.d.ts +1 -1
- package/dist/lib/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheController.d.ts +9 -5
- package/dist/lib/controllers/PrecacheController/PrecacheController.d.ts.map +1 -0
- package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheInstallReportPlugin.d.ts +1 -1
- package/dist/lib/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +1 -0
- package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheRoute.d.ts +1 -1
- package/dist/lib/controllers/PrecacheController/PrecacheRoute.d.ts.map +1 -0
- package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheStrategy.d.ts +4 -4
- package/dist/lib/controllers/PrecacheController/PrecacheStrategy.d.ts.map +1 -0
- package/dist/{controllers → lib/controllers}/PrecacheController/parsePrecacheOptions.d.ts +3 -3
- package/dist/lib/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +1 -0
- package/dist/{controllers → lib/controllers}/RuntimeCacheController.d.ts +10 -5
- 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.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 +12 -6
- 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/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.map +1 -1
- 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/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 +24 -5
- 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/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 +28 -5
- package/src/NavigationRoute.ts +2 -2
- package/src/RegExpRoute.ts +2 -2
- package/src/Route.ts +2 -2
- package/src/Serwist.ts +23 -19
- package/src/cacheNames.ts +1 -1
- package/src/copyResponse.ts +2 -2
- package/src/index.internal.ts +16 -16
- package/src/index.ts +68 -96
- 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/index.ts +5 -0
- package/src/lib/broadcastUpdate/responsesAreSame.ts +2 -2
- package/src/lib/cacheableResponse/CacheableResponse.ts +4 -4
- package/src/lib/cacheableResponse/index.ts +3 -0
- package/src/{controllers → lib/controllers}/PrecacheController/PrecacheCacheKeyPlugin.ts +1 -1
- package/src/{controllers → lib/controllers}/PrecacheController/PrecacheController.ts +19 -16
- package/src/{controllers → lib/controllers}/PrecacheController/PrecacheInstallReportPlugin.ts +1 -1
- package/src/{controllers → lib/controllers}/PrecacheController/PrecacheRoute.ts +5 -5
- package/src/{controllers → lib/controllers}/PrecacheController/PrecacheStrategy.ts +10 -10
- package/src/{controllers → lib/controllers}/PrecacheController/parsePrecacheOptions.ts +3 -3
- package/src/{controllers → lib/controllers}/RuntimeCacheController.ts +6 -6
- package/src/lib/controllers/index.ts +3 -0
- package/src/lib/expiration/CacheExpiration.ts +3 -3
- package/src/lib/expiration/ExpirationPlugin.ts +6 -6
- 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 +18 -7
- package/src/lib/precaching/index.ts +2 -0
- 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 +4 -4
- package/src/lib/strategies/StrategyHandler.ts +9 -9
- package/src/lib/strategies/index.ts +10 -0
- 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 +36 -5
- package/src/utils/SerwistError.ts +2 -2
- package/src/utils/cacheNames.ts +1 -1
- package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
- package/dist/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +0 -1
- package/dist/controllers/PrecacheController/PrecacheController.d.ts.map +0 -1
- package/dist/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +0 -1
- package/dist/controllers/PrecacheController/PrecacheRoute.d.ts.map +0 -1
- package/dist/controllers/PrecacheController/PrecacheStrategy.d.ts.map +0 -1
- package/dist/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +0 -1
- package/dist/controllers/RuntimeCacheController.d.ts.map +0 -1
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { SerwistError } from "#utils/SerwistError.js";
|
|
2
|
+
import { assert } from "#utils/assert.js";
|
|
3
|
+
import { createCacheKey } from "#utils/createCacheKey.js";
|
|
4
|
+
import { logger } from "#utils/logger.js";
|
|
5
|
+
import { printCleanupDetails } from "#utils/printCleanupDetails.js";
|
|
6
|
+
import { printInstallDetails } from "#utils/printInstallDetails.js";
|
|
1
7
|
import { parallel } from "@serwist/utils";
|
|
2
|
-
import
|
|
3
|
-
import type {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { logger } from "../../utils/logger.js";
|
|
8
|
+
import { NavigationRoute } from "../../../NavigationRoute.js";
|
|
9
|
+
import type { Serwist } from "../../../Serwist.js";
|
|
10
|
+
import type { Controller, RouteHandlerCallback, UrlManipulation } from "../../../types.js";
|
|
11
|
+
import type { Strategy } from "../../strategies/Strategy.js";
|
|
7
12
|
import { PrecacheInstallReportPlugin } from "./PrecacheInstallReportPlugin.js";
|
|
8
|
-
import { SerwistError } from "../../utils/SerwistError.js";
|
|
9
|
-
import { printInstallDetails } from "../../utils/printInstallDetails.js";
|
|
10
|
-
import { printCleanupDetails } from "../../utils/printCleanupDetails.js";
|
|
11
|
-
import { PrecacheStrategy } from "./PrecacheStrategy.js";
|
|
12
13
|
import { PrecacheRoute } from "./PrecacheRoute.js";
|
|
13
|
-
import
|
|
14
|
-
import { NavigationRoute } from "../../NavigationRoute.js";
|
|
14
|
+
import { PrecacheStrategy } from "./PrecacheStrategy.js";
|
|
15
15
|
import type { PrecacheStrategyOptions } from "./PrecacheStrategy.js";
|
|
16
16
|
import { parsePrecacheOptions } from "./parsePrecacheOptions.js";
|
|
17
17
|
|
|
@@ -90,6 +90,7 @@ export class PrecacheController implements Controller {
|
|
|
90
90
|
private readonly _strategy: Strategy;
|
|
91
91
|
private _options: PrecacheControllerOptions;
|
|
92
92
|
private _routeOptions: PrecacheRouteOptions;
|
|
93
|
+
|
|
93
94
|
/**
|
|
94
95
|
* Create a new PrecacheController.
|
|
95
96
|
*
|
|
@@ -101,10 +102,8 @@ export class PrecacheController implements Controller {
|
|
|
101
102
|
this._strategy = new PrecacheStrategy(strategyOptions);
|
|
102
103
|
this._options = controllerOptions;
|
|
103
104
|
this._routeOptions = routeOptions;
|
|
104
|
-
// Bind the install and activate methods to the instance.
|
|
105
|
-
this.install = this.install.bind(this);
|
|
106
|
-
this.activate = this.activate.bind(this);
|
|
107
105
|
}
|
|
106
|
+
|
|
108
107
|
/**
|
|
109
108
|
* The strategy created by this controller and
|
|
110
109
|
* used to cache assets and respond to `fetch` events.
|
|
@@ -112,6 +111,7 @@ export class PrecacheController implements Controller {
|
|
|
112
111
|
get strategy(): Strategy {
|
|
113
112
|
return this._strategy;
|
|
114
113
|
}
|
|
114
|
+
|
|
115
115
|
/**
|
|
116
116
|
* Adds items to the cache list, removing duplicates and ensuring the information is valid.
|
|
117
117
|
*
|
|
@@ -172,7 +172,8 @@ export class PrecacheController implements Controller {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
}
|
|
175
|
-
|
|
175
|
+
|
|
176
|
+
init({ serwist }: { serwist: Serwist }): void {
|
|
176
177
|
serwist.registerRoute(new PrecacheRoute(this, this._routeOptions));
|
|
177
178
|
|
|
178
179
|
if (this._options.navigateFallback) {
|
|
@@ -184,7 +185,8 @@ export class PrecacheController implements Controller {
|
|
|
184
185
|
);
|
|
185
186
|
}
|
|
186
187
|
}
|
|
187
|
-
|
|
188
|
+
|
|
189
|
+
async install({ event }: { event: ExtendableEvent }): Promise<void> {
|
|
188
190
|
const installReportPlugin = new PrecacheInstallReportPlugin();
|
|
189
191
|
this._strategy.plugins.push(installReportPlugin);
|
|
190
192
|
await parallel(this._options.concurrency!, Array.from(this._urlsToCacheKeys.entries()), async ([url, cacheKey]): Promise<void> => {
|
|
@@ -213,6 +215,7 @@ export class PrecacheController implements Controller {
|
|
|
213
215
|
printInstallDetails(updatedURLs, notUpdatedURLs);
|
|
214
216
|
}
|
|
215
217
|
}
|
|
218
|
+
|
|
216
219
|
async activate(): Promise<void> {
|
|
217
220
|
const cache = await self.caches.open(this._strategy.cacheName);
|
|
218
221
|
const currentlyCachedRequests = await cache.keys();
|
package/src/{controllers → lib/controllers}/PrecacheController/PrecacheInstallReportPlugin.ts
RENAMED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { StrategyPlugin, StrategyPluginCallbackParam } from "
|
|
9
|
+
import type { StrategyPlugin, StrategyPluginCallbackParam } from "../../../types.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A plugin designed to determine the number of assets that were updated (or not updated)
|
|
@@ -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 { generateURLVariations } from "#utils/generateURLVariations.js";
|
|
10
|
+
import { getFriendlyURL } from "#utils/getFriendlyURL.js";
|
|
11
|
+
import { logger } from "#utils/logger.js";
|
|
12
|
+
import { Route } from "../../../Route.js";
|
|
13
|
+
import type { RouteMatchCallback, RouteMatchCallbackOptions } from "../../../types.js";
|
|
14
14
|
import type { PrecacheController, PrecacheRouteOptions } from "./PrecacheController.js";
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -6,16 +6,16 @@
|
|
|
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 type {
|
|
16
|
-
import type { StrategyOptions } from "../../
|
|
17
|
-
import { Strategy } from "../../
|
|
18
|
-
import type { StrategyHandler } from "../../
|
|
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 { Serwist } from "../../../Serwist.js";
|
|
14
|
+
import { copyResponse } from "../../../copyResponse.js";
|
|
15
|
+
import type { StrategyPlugin } from "../../../types.js";
|
|
16
|
+
import type { StrategyOptions } from "../../strategies/Strategy.js";
|
|
17
|
+
import { Strategy } from "../../strategies/Strategy.js";
|
|
18
|
+
import type { StrategyHandler } from "../../strategies/StrategyHandler.js";
|
|
19
19
|
|
|
20
20
|
export interface PrecacheStrategyOptions extends StrategyOptions {
|
|
21
21
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { PrecacheController, PrecacheControllerOptions, PrecacheOptions, PrecacheRouteOptions } from "./PrecacheController.js";
|
|
1
|
+
import { privateCacheNames } from "#index.internal";
|
|
3
2
|
import type { Require } from "@serwist/utils";
|
|
4
|
-
import { privateCacheNames } from "../../index.internal.js";
|
|
5
3
|
import { PrecacheCacheKeyPlugin } from "./PrecacheCacheKeyPlugin.js";
|
|
4
|
+
import type { PrecacheController, PrecacheControllerOptions, PrecacheOptions, PrecacheRouteOptions } from "./PrecacheController.js";
|
|
5
|
+
import type { PrecacheStrategyOptions } from "./PrecacheStrategy.js";
|
|
6
6
|
|
|
7
7
|
export const parsePrecacheOptions = (
|
|
8
8
|
controller: PrecacheController,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { parallel } from "@serwist/utils";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import type
|
|
5
|
-
import
|
|
2
|
+
import type { Serwist } from "../../Serwist.js";
|
|
3
|
+
import type { Controller, RuntimeCaching } from "../../types.js";
|
|
4
|
+
import { type PrecacheFallbackEntry, PrecacheFallbackPlugin } from "../precaching/PrecacheFallbackPlugin.js";
|
|
5
|
+
import { Strategy } from "../strategies/Strategy.js";
|
|
6
6
|
|
|
7
7
|
export interface WarmRuntimeCacheEntry {
|
|
8
8
|
integrity?: string;
|
|
@@ -51,7 +51,7 @@ export class RuntimeCacheController implements Controller {
|
|
|
51
51
|
this.install = this.install.bind(this);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
init(serwist: Serwist): void {
|
|
54
|
+
init({ serwist }: { serwist: Serwist }): void {
|
|
55
55
|
if (this._options.fallbacks !== undefined) {
|
|
56
56
|
const fallbackPlugin = new PrecacheFallbackPlugin({
|
|
57
57
|
fallbackUrls: this._options.fallbacks.entries,
|
|
@@ -73,7 +73,7 @@ export class RuntimeCacheController implements Controller {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
async install(event: ExtendableEvent
|
|
76
|
+
async install({ event, serwist }: { event: ExtendableEvent; serwist: Serwist }) {
|
|
77
77
|
const concurrency = this._options.warmOptions?.concurrency ?? 10;
|
|
78
78
|
if (this._options.warmEntries) {
|
|
79
79
|
await parallel(concurrency, this._options.warmEntries, async (entry) => {
|
|
@@ -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 { CacheTimestampsModel } from "./models/CacheTimestampsModel.js";
|
|
13
13
|
|
|
14
14
|
interface CacheExpirationConfig {
|
|
@@ -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
15
|
import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, StrategyPlugin } from "../../types.js";
|
|
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";
|
|
17
16
|
import type { Strategy } from "../strategies/Strategy.js";
|
|
17
|
+
import { CacheExpiration } from "./CacheExpiration.js";
|
|
18
18
|
|
|
19
19
|
export interface ExpirationPluginOptions {
|
|
20
20
|
/**
|
|
@@ -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 "
|
|
9
|
+
import type { PrecacheController } from "#lib/controllers/PrecacheController/PrecacheController.js";
|
|
10
|
+
import type { Serwist } from "../../Serwist.js";
|
|
10
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 {
|
|
@@ -31,6 +32,11 @@ export interface PrecacheFallbackPluginOptions {
|
|
|
31
32
|
* A {@linkcode PrecacheController} instance.
|
|
32
33
|
*/
|
|
33
34
|
precacheController: PrecacheController;
|
|
35
|
+
/**
|
|
36
|
+
* A {@linkcode Serwist} instance.
|
|
37
|
+
* @deprecated Use `precacheController` instead.
|
|
38
|
+
*/
|
|
39
|
+
serwist?: Serwist;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
/**
|
|
@@ -50,9 +56,14 @@ export class PrecacheFallbackPlugin implements StrategyPlugin {
|
|
|
50
56
|
*
|
|
51
57
|
* @param config
|
|
52
58
|
*/
|
|
53
|
-
constructor({ fallbackUrls, precacheController }: 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
|
/**
|
|
@@ -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 { 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";
|
|
9
13
|
import type { HandlerCallbackOptions, RouteHandlerObject, StrategyPlugin } from "../../types.js";
|
|
10
|
-
import { SerwistError } from "../../utils/SerwistError.js";
|
|
11
|
-
import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
|
|
12
|
-
import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
|
|
13
|
-
import { logger } from "../../utils/logger.js";
|
|
14
14
|
import { StrategyHandler } from "./StrategyHandler.js";
|
|
15
15
|
|
|
16
16
|
export interface StrategyOptions {
|
|
@@ -6,17 +6,17 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
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";
|
|
17
|
+
import type { Route } from "../../Route.js";
|
|
9
18
|
import type { HandlerCallbackOptions, MapLikeObject, StrategyPlugin, StrategyPluginCallbackParam } from "../../types.js";
|
|
10
|
-
import { Deferred } from "../../utils/Deferred.js";
|
|
11
|
-
import { SerwistError } from "../../utils/SerwistError.js";
|
|
12
|
-
import { assert } from "../../utils/assert.js";
|
|
13
|
-
import { cacheMatchIgnoreParams } from "../../utils/cacheMatchIgnoreParams.js";
|
|
14
|
-
import { executeQuotaErrorCallbacks } from "../../utils/executeQuotaErrorCallbacks.js";
|
|
15
|
-
import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
|
|
16
|
-
import { logger } from "../../utils/logger.js";
|
|
17
|
-
import { timeout } from "../../utils/timeout.js";
|
|
18
19
|
import type { Strategy } from "./Strategy.js";
|
|
19
|
-
import type { Route } from "../../Route.js";
|
|
20
20
|
|
|
21
21
|
function toRequest(input: RequestInfo) {
|
|
22
22
|
return typeof input === "string" ? new Request(input) : input;
|
|
@@ -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,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.
|
package/src/types.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
PrecacheControllerOptions,
|
|
3
|
+
PrecacheEntry,
|
|
4
|
+
PrecacheOptions,
|
|
5
|
+
PrecacheRouteOptions,
|
|
6
|
+
} from "#lib/controllers/PrecacheController/PrecacheController.js";
|
|
1
7
|
import type { Prettify } from "@serwist/utils";
|
|
2
|
-
import type { HTTPMethod } from "./constants.js";
|
|
3
8
|
import type { Route } from "./Route.js";
|
|
4
9
|
import type { Serwist } from "./Serwist.js";
|
|
5
|
-
import type {
|
|
10
|
+
import type { HTTPMethod } from "./constants.js";
|
|
6
11
|
|
|
7
12
|
export type PromiseOrNot<T> = T | Promise<T>;
|
|
8
13
|
|
|
@@ -16,13 +21,39 @@ export interface MapLikeObject {
|
|
|
16
21
|
*/
|
|
17
22
|
export type PluginState = MapLikeObject;
|
|
18
23
|
|
|
24
|
+
export interface InitCallbackParam {
|
|
25
|
+
serwist: Serwist;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type InitCallback = (param: InitCallbackParam) => PromiseOrNot<void>;
|
|
29
|
+
|
|
30
|
+
export interface InstallCallbackParam {
|
|
31
|
+
event: ExtendableEvent;
|
|
32
|
+
serwist: Serwist;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type InstallCallback = (param: InstallCallbackParam) => PromiseOrNot<void>;
|
|
36
|
+
|
|
37
|
+
export interface ActivateCallbackParam {
|
|
38
|
+
event: ExtendableEvent;
|
|
39
|
+
serwist: Serwist;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type ActivateCallback = (param: ActivateCallbackParam) => PromiseOrNot<void>;
|
|
43
|
+
|
|
19
44
|
/**
|
|
20
45
|
* An object with optional lifecycle callback properties for Serwist's operations.
|
|
21
46
|
*/
|
|
22
47
|
export interface Controller {
|
|
23
|
-
init
|
|
24
|
-
install
|
|
25
|
-
activate
|
|
48
|
+
init?: InitCallback;
|
|
49
|
+
install?: InstallCallback;
|
|
50
|
+
activate?: ActivateCallback;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface ControllerParam {
|
|
54
|
+
init: InitCallbackParam;
|
|
55
|
+
install: InstallCallbackParam;
|
|
56
|
+
activate: ActivateCallbackParam;
|
|
26
57
|
}
|
|
27
58
|
|
|
28
59
|
/**
|