serwist 9.0.0-preview.24 → 9.0.0-preview.25
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 +1 -1
- package/dist/NavigationRoute.d.ts.map +1 -1
- package/dist/PrecacheRoute.d.ts.map +1 -1
- package/dist/RegExpRoute.d.ts +1 -1
- package/dist/RegExpRoute.d.ts.map +1 -1
- package/dist/Route.d.ts +1 -1
- package/dist/Route.d.ts.map +1 -1
- package/dist/Serwist.d.ts +38 -43
- package/dist/Serwist.d.ts.map +1 -1
- package/dist/chunks/printInstallDetails.js +1613 -0
- package/dist/chunks/resultingClientExists.js +1 -1
- package/dist/chunks/waitUntil.js +400 -1
- package/dist/copyResponse.d.ts +1 -1
- package/dist/copyResponse.d.ts.map +1 -1
- package/dist/disableDevLogs.d.ts +1 -1
- package/dist/index.d.ts +42 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.js +1 -2
- package/dist/index.js +1464 -8
- package/dist/index.legacy.d.ts +5 -3
- package/dist/index.legacy.d.ts.map +1 -1
- package/dist/index.legacy.js +168 -17
- package/dist/legacy/PrecacheController.d.ts +1 -1
- package/dist/legacy/PrecacheController.d.ts.map +1 -1
- package/dist/legacy/PrecacheRoute.d.ts.map +1 -1
- package/dist/legacy/Router.d.ts +1 -1
- package/dist/legacy/Router.d.ts.map +1 -1
- package/dist/legacy/constants.d.ts.map +1 -0
- package/dist/legacy/fallbacks.d.ts +1 -1
- package/dist/legacy/fallbacks.d.ts.map +1 -1
- package/dist/legacy/initializeGoogleAnalytics.d.ts +38 -0
- package/dist/legacy/initializeGoogleAnalytics.d.ts.map +1 -0
- package/dist/legacy/installSerwist.d.ts +69 -3
- package/dist/legacy/installSerwist.d.ts.map +1 -1
- package/dist/legacy/registerRoute.d.ts +1 -1
- package/dist/legacy/registerRoute.d.ts.map +1 -1
- package/dist/{plugins → lib}/backgroundSync/BackgroundSyncPlugin.d.ts +3 -3
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
- package/dist/{plugins/backgroundSync/Queue.d.ts → lib/backgroundSync/BackgroundSyncQueue.d.ts} +29 -13
- package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts.map +1 -0
- package/dist/{plugins/backgroundSync/QueueDb.d.ts → lib/backgroundSync/BackgroundSyncQueueDb.d.ts} +7 -7
- package/dist/lib/backgroundSync/BackgroundSyncQueueDb.d.ts.map +1 -0
- package/dist/{plugins/backgroundSync/QueueStore.d.ts → lib/backgroundSync/BackgroundSyncQueueStore.d.ts} +7 -7
- package/dist/lib/backgroundSync/BackgroundSyncQueueStore.d.ts.map +1 -0
- package/dist/lib/backgroundSync/StorableRequest.d.ts.map +1 -0
- package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
- package/dist/{plugins → lib}/broadcastUpdate/BroadcastUpdatePlugin.d.ts +1 -1
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
- package/dist/lib/broadcastUpdate/constants.d.ts +5 -0
- package/dist/lib/broadcastUpdate/constants.d.ts.map +1 -0
- package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
- package/dist/{plugins → lib}/broadcastUpdate/types.d.ts +3 -3
- package/dist/lib/broadcastUpdate/types.d.ts.map +1 -0
- package/dist/lib/cacheableResponse/CacheableResponse.d.ts.map +1 -0
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
- package/dist/{plugins → lib}/expiration/CacheExpiration.d.ts +1 -1
- package/dist/lib/expiration/CacheExpiration.d.ts.map +1 -0
- package/dist/{plugins → lib}/expiration/ExpirationPlugin.d.ts +1 -1
- package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -0
- package/dist/lib/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
- package/dist/lib/googleAnalytics/constants.d.ts +10 -0
- package/dist/lib/googleAnalytics/constants.d.ts.map +1 -0
- package/dist/{plugins/googleAnalytics/initialize.d.ts → lib/googleAnalytics/initializeGoogleAnalytics.d.ts} +2 -2
- package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +1 -0
- package/dist/{plugins → lib}/precaching/PrecacheFallbackPlugin.d.ts +1 -1
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
- package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +1 -0
- package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
- package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
- package/dist/lib/strategies/CacheFirst.d.ts.map +1 -0
- package/dist/lib/strategies/CacheOnly.d.ts.map +1 -0
- package/dist/lib/strategies/NetworkFirst.d.ts.map +1 -0
- package/dist/lib/strategies/NetworkOnly.d.ts.map +1 -0
- package/dist/{PrecacheStrategy.d.ts → lib/strategies/PrecacheOnly.d.ts} +7 -7
- package/dist/lib/strategies/PrecacheOnly.d.ts.map +1 -0
- package/dist/lib/strategies/StaleWhileRevalidate.d.ts.map +1 -0
- package/dist/{strategies → lib/strategies}/Strategy.d.ts +1 -1
- package/dist/lib/strategies/Strategy.d.ts.map +1 -0
- package/dist/{strategies → lib/strategies}/StrategyHandler.d.ts +1 -1
- package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -0
- package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
- package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
- package/dist/lib/strategies/utils/messages.d.ts.map +1 -0
- package/dist/navigationPreload.d.ts +3 -3
- package/dist/parseRoute.d.ts +1 -1
- package/dist/parseRoute.d.ts.map +1 -1
- package/dist/types.d.ts +12 -7
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts +1 -1
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -1
- package/dist/utils/assert.d.ts.map +1 -1
- package/package.json +7 -21
- package/src/NavigationRoute.ts +1 -1
- package/src/PrecacheRoute.ts +3 -3
- package/src/RegExpRoute.ts +2 -2
- package/src/Route.ts +2 -2
- package/src/Serwist.ts +69 -80
- package/src/cleanupOutdatedCaches.ts +1 -1
- package/src/disableDevLogs.ts +1 -1
- package/src/index.legacy.ts +16 -5
- package/src/index.ts +107 -14
- package/src/legacy/PrecacheController.ts +9 -9
- package/src/legacy/PrecacheFallbackPlugin.ts +1 -1
- package/src/legacy/PrecacheRoute.ts +3 -3
- package/src/legacy/Router.ts +5 -5
- package/src/legacy/fallbacks.ts +3 -3
- package/src/legacy/initializeGoogleAnalytics.ts +218 -0
- package/src/legacy/installSerwist.ts +156 -5
- package/src/legacy/registerRoute.ts +1 -1
- package/src/{plugins → lib}/backgroundSync/BackgroundSyncPlugin.ts +6 -6
- package/src/{plugins/backgroundSync/Queue.ts → lib/backgroundSync/BackgroundSyncQueue.ts} +47 -26
- package/src/{plugins/backgroundSync/QueueDb.ts → lib/backgroundSync/BackgroundSyncQueueDb.ts} +16 -16
- package/src/{plugins/backgroundSync/QueueStore.ts → lib/backgroundSync/BackgroundSyncQueueStore.ts} +13 -13
- package/src/{plugins → lib}/backgroundSync/StorableRequest.ts +2 -2
- package/src/{plugins → lib}/broadcastUpdate/BroadcastCacheUpdate.ts +14 -9
- package/src/{plugins → lib}/broadcastUpdate/BroadcastUpdatePlugin.ts +1 -1
- package/src/lib/broadcastUpdate/constants.ts +12 -0
- package/src/{plugins → lib}/broadcastUpdate/types.ts +3 -3
- package/src/{plugins → lib}/cacheableResponse/CacheableResponse.ts +5 -5
- package/src/{plugins → lib}/expiration/CacheExpiration.ts +7 -7
- package/src/{plugins → lib}/expiration/ExpirationPlugin.ts +10 -10
- package/src/lib/googleAnalytics/constants.ts +22 -0
- package/src/{plugins/googleAnalytics/initialize.ts → lib/googleAnalytics/initializeGoogleAnalytics.ts} +9 -9
- package/src/{strategies → lib/strategies}/CacheFirst.ts +4 -4
- package/src/{strategies → lib/strategies}/CacheOnly.ts +4 -4
- package/src/{strategies → lib/strategies}/NetworkFirst.ts +5 -5
- package/src/{strategies → lib/strategies}/NetworkOnly.ts +5 -5
- package/src/{PrecacheStrategy.ts → lib/strategies/PrecacheOnly.ts} +19 -15
- package/src/{strategies → lib/strategies}/StaleWhileRevalidate.ts +4 -4
- package/src/{strategies → lib/strategies}/Strategy.ts +5 -5
- package/src/{strategies → lib/strategies}/StrategyHandler.ts +11 -11
- package/src/{strategies → lib/strategies}/plugins/cacheOkAndOpaquePlugin.ts +1 -1
- package/src/{strategies → lib/strategies}/utils/messages.ts +2 -2
- package/src/models/messages/messages.ts +1 -1
- package/src/navigationPreload.ts +3 -3
- package/src/parseRoute.ts +3 -3
- package/src/registerQuotaErrorCallback.ts +1 -1
- package/src/types.ts +12 -7
- package/src/utils/PrecacheCacheKeyPlugin.ts +1 -1
- package/src/utils/assert.ts +1 -1
- package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
- package/src/utils/welcome.ts +1 -1
- package/dist/PrecacheStrategy.d.ts.map +0 -1
- package/dist/chunks/NetworkOnly.js +0 -599
- package/dist/chunks/PrecacheFallbackPlugin.js +0 -634
- package/dist/chunks/Serwist.js +0 -1034
- package/dist/chunks/registerQuotaErrorCallback.js +0 -17
- package/dist/chunks/timeout.js +0 -400
- package/dist/index.plugins.d.ts +0 -41
- package/dist/index.plugins.d.ts.map +0 -1
- package/dist/index.plugins.js +0 -669
- package/dist/index.strategies.d.ts +0 -22
- package/dist/index.strategies.d.ts.map +0 -1
- package/dist/index.strategies.js +0 -144
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/Queue.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/QueueDb.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/QueueStore.d.ts.map +0 -1
- package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/constants.d.ts +0 -5
- package/dist/plugins/broadcastUpdate/constants.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
- package/dist/plugins/broadcastUpdate/types.d.ts.map +0 -1
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +0 -1
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
- package/dist/plugins/expiration/CacheExpiration.d.ts.map +0 -1
- package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +0 -1
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +0 -1
- package/dist/plugins/googleAnalytics/constants.d.ts.map +0 -1
- package/dist/plugins/googleAnalytics/initialize.d.ts.map +0 -1
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
- package/dist/strategies/CacheFirst.d.ts.map +0 -1
- package/dist/strategies/CacheOnly.d.ts.map +0 -1
- package/dist/strategies/NetworkFirst.d.ts.map +0 -1
- package/dist/strategies/NetworkOnly.d.ts.map +0 -1
- package/dist/strategies/StaleWhileRevalidate.d.ts.map +0 -1
- package/dist/strategies/Strategy.d.ts.map +0 -1
- package/dist/strategies/StrategyHandler.d.ts.map +0 -1
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +0 -3
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +0 -1
- package/dist/strategies/utils/messages.d.ts.map +0 -1
- package/src/index.plugins.ts +0 -95
- package/src/index.strategies.ts +0 -26
- package/src/plugins/broadcastUpdate/constants.ts +0 -12
- package/dist/{plugins/googleAnalytics → legacy}/constants.d.ts +0 -0
- package/dist/{plugins → lib}/backgroundSync/StorableRequest.d.ts +0 -0
- package/dist/{plugins → lib}/broadcastUpdate/BroadcastCacheUpdate.d.ts +0 -0
- package/dist/{plugins → lib}/broadcastUpdate/responsesAreSame.d.ts +0 -0
- package/dist/{plugins → lib}/cacheableResponse/CacheableResponse.d.ts +0 -0
- package/dist/{plugins → lib}/cacheableResponse/CacheableResponsePlugin.d.ts +0 -0
- package/dist/{plugins → lib}/expiration/models/CacheTimestampsModel.d.ts +0 -0
- package/dist/{plugins → lib}/rangeRequests/RangeRequestsPlugin.d.ts +0 -0
- package/dist/{plugins → lib}/rangeRequests/createPartialResponse.d.ts +0 -0
- package/dist/{plugins → lib}/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +0 -0
- package/dist/{plugins → lib}/rangeRequests/utils/parseRangeHeader.d.ts +0 -0
- package/dist/{strategies → lib/strategies}/CacheFirst.d.ts +0 -0
- package/dist/{strategies → lib/strategies}/CacheOnly.d.ts +0 -0
- package/dist/{strategies → lib/strategies}/NetworkFirst.d.ts +0 -0
- package/dist/{strategies → lib/strategies}/NetworkOnly.d.ts +0 -0
- package/dist/{strategies → lib/strategies}/StaleWhileRevalidate.d.ts +0 -0
- package/dist/{strategies → lib/strategies}/utils/messages.d.ts +0 -0
- package/src/{plugins/googleAnalytics → legacy}/constants.ts +0 -0
- package/src/{plugins → lib}/broadcastUpdate/responsesAreSame.ts +0 -0
- package/src/{plugins → lib}/cacheableResponse/CacheableResponsePlugin.ts +0 -0
- package/src/{plugins → lib}/expiration/models/CacheTimestampsModel.ts +0 -0
- package/src/{plugins → lib}/precaching/PrecacheFallbackPlugin.ts +1 -1
- package/src/{plugins → lib}/rangeRequests/RangeRequestsPlugin.ts +0 -0
- package/src/{plugins → lib}/rangeRequests/createPartialResponse.ts +1 -1
- package/src/{plugins → lib}/rangeRequests/utils/calculateEffectiveBoundaries.ts +1 -1
- package/src/{plugins → lib}/rangeRequests/utils/parseRangeHeader.ts +1 -1
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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";
|
|
@@ -55,7 +55,7 @@ export class NetworkFirst extends Strategy {
|
|
|
55
55
|
if (process.env.NODE_ENV !== "production") {
|
|
56
56
|
if (this._networkTimeoutSeconds) {
|
|
57
57
|
assert!.isType(this._networkTimeoutSeconds, "number", {
|
|
58
|
-
moduleName: "serwist
|
|
58
|
+
moduleName: "serwist",
|
|
59
59
|
className: this.constructor.name,
|
|
60
60
|
funcName: "constructor",
|
|
61
61
|
paramName: "networkTimeoutSeconds",
|
|
@@ -75,7 +75,7 @@ export class NetworkFirst extends Strategy {
|
|
|
75
75
|
|
|
76
76
|
if (process.env.NODE_ENV !== "production") {
|
|
77
77
|
assert!.isInstance(request, Request, {
|
|
78
|
-
moduleName: "serwist
|
|
78
|
+
moduleName: "serwist",
|
|
79
79
|
className: this.constructor.name,
|
|
80
80
|
funcName: "handle",
|
|
81
81
|
paramName: "makeRequest",
|
|
@@ -6,10 +6,10 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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";
|
|
@@ -51,7 +51,7 @@ export class NetworkOnly extends Strategy {
|
|
|
51
51
|
async _handle(request: Request, handler: StrategyHandler): Promise<Response> {
|
|
52
52
|
if (process.env.NODE_ENV !== "production") {
|
|
53
53
|
assert!.isInstance(request, Request, {
|
|
54
|
-
moduleName: "serwist
|
|
54
|
+
moduleName: "serwist",
|
|
55
55
|
className: this.constructor.name,
|
|
56
56
|
funcName: "_handle",
|
|
57
57
|
paramName: "request",
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
10
|
-
import {
|
|
11
|
-
import { SerwistError } from "
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import type { StrategyOptions } from "./
|
|
16
|
-
import { Strategy } from "./
|
|
17
|
-
import type { StrategyHandler } from "./
|
|
9
|
+
import { copyResponse } from "../../copyResponse.js";
|
|
10
|
+
import type { SerwistPlugin } from "../../types.js";
|
|
11
|
+
import { SerwistError } from "../../utils/SerwistError.js";
|
|
12
|
+
import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
|
|
13
|
+
import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
|
|
14
|
+
import { logger } from "../../utils/logger.js";
|
|
15
|
+
import type { StrategyOptions } from "./Strategy.js";
|
|
16
|
+
import { Strategy } from "./Strategy.js";
|
|
17
|
+
import type { StrategyHandler } from "./StrategyHandler.js";
|
|
18
18
|
|
|
19
19
|
interface PrecacheStrategyOptions extends StrategyOptions {
|
|
20
20
|
/**
|
|
@@ -29,9 +29,9 @@ interface PrecacheStrategyOptions extends StrategyOptions {
|
|
|
29
29
|
* specifically designed to both cache and fetch precached assets.
|
|
30
30
|
*
|
|
31
31
|
* Note: an instance of this class is created automatically when creating a
|
|
32
|
-
* `
|
|
32
|
+
* `Serwist` instance; it's generally not necessary to create this yourself.
|
|
33
33
|
*/
|
|
34
|
-
export class
|
|
34
|
+
export class PrecacheOnly extends Strategy {
|
|
35
35
|
private readonly _fallbackToNetwork: boolean;
|
|
36
36
|
|
|
37
37
|
static readonly defaultPrecacheCacheabilityPlugin: SerwistPlugin = {
|
|
@@ -55,6 +55,7 @@ export class PrecacheStrategy extends Strategy {
|
|
|
55
55
|
*/
|
|
56
56
|
constructor(options: PrecacheStrategyOptions = {}) {
|
|
57
57
|
options.cacheName = privateCacheNames.getPrecacheName(options.cacheName);
|
|
58
|
+
|
|
58
59
|
super(options);
|
|
59
60
|
|
|
60
61
|
this._fallbackToNetwork = options.fallbackToNetwork === false ? false : true;
|
|
@@ -63,7 +64,7 @@ export class PrecacheStrategy extends Strategy {
|
|
|
63
64
|
// any redirected response must be "copied" rather than cloned, so the new
|
|
64
65
|
// response doesn't contain the `redirected` flag. See:
|
|
65
66
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=669363&desc=2#c1
|
|
66
|
-
this.plugins.push(
|
|
67
|
+
this.plugins.push(PrecacheOnly.copyRedirectedCacheableResponsesPlugin);
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
/**
|
|
@@ -74,6 +75,7 @@ export class PrecacheStrategy extends Strategy {
|
|
|
74
75
|
*/
|
|
75
76
|
async _handle(request: Request, handler: StrategyHandler): Promise<Response> {
|
|
76
77
|
const response = await handler.cacheMatch(request);
|
|
78
|
+
|
|
77
79
|
if (response) {
|
|
78
80
|
return response;
|
|
79
81
|
}
|
|
@@ -91,6 +93,7 @@ export class PrecacheStrategy extends Strategy {
|
|
|
91
93
|
|
|
92
94
|
async _handleFetch(request: Request, handler: StrategyHandler): Promise<Response> {
|
|
93
95
|
let response: Response | undefined = undefined;
|
|
96
|
+
|
|
94
97
|
const params = (handler.params || {}) as {
|
|
95
98
|
cacheKey?: string;
|
|
96
99
|
integrity?: string;
|
|
@@ -169,6 +172,7 @@ export class PrecacheStrategy extends Strategy {
|
|
|
169
172
|
// Make sure we defer cachePut() until after we know the response
|
|
170
173
|
// should be cached; see https://github.com/GoogleChrome/workbox/issues/2737
|
|
171
174
|
const wasCached = await handler.cachePut(request, response.clone());
|
|
175
|
+
|
|
172
176
|
if (!wasCached) {
|
|
173
177
|
// Throwing here will lead to the `install` handler failing, which
|
|
174
178
|
// we want to do if *any* of the responses aren't safe to cache.
|
|
@@ -214,12 +218,12 @@ export class PrecacheStrategy extends Strategy {
|
|
|
214
218
|
|
|
215
219
|
for (const [index, plugin] of this.plugins.entries()) {
|
|
216
220
|
// Ignore the copy redirected plugin when determining what to do.
|
|
217
|
-
if (plugin ===
|
|
221
|
+
if (plugin === PrecacheOnly.copyRedirectedCacheableResponsesPlugin) {
|
|
218
222
|
continue;
|
|
219
223
|
}
|
|
220
224
|
|
|
221
225
|
// Save the default plugin's index, in case it needs to be removed.
|
|
222
|
-
if (plugin ===
|
|
226
|
+
if (plugin === PrecacheOnly.defaultPrecacheCacheabilityPlugin) {
|
|
223
227
|
defaultPluginIndex = index;
|
|
224
228
|
}
|
|
225
229
|
|
|
@@ -229,7 +233,7 @@ export class PrecacheStrategy extends Strategy {
|
|
|
229
233
|
}
|
|
230
234
|
|
|
231
235
|
if (cacheWillUpdatePluginCount === 0) {
|
|
232
|
-
this.plugins.push(
|
|
236
|
+
this.plugins.push(PrecacheOnly.defaultPrecacheCacheabilityPlugin);
|
|
233
237
|
} else if (cacheWillUpdatePluginCount > 1 && defaultPluginIndex !== null) {
|
|
234
238
|
// Only remove the default plugin; multiple custom plugins are allowed.
|
|
235
239
|
this.plugins.splice(defaultPluginIndex, 1);
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
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";
|
|
@@ -58,7 +58,7 @@ export class StaleWhileRevalidate extends Strategy {
|
|
|
58
58
|
|
|
59
59
|
if (process.env.NODE_ENV !== "production") {
|
|
60
60
|
assert!.isInstance(request, Request, {
|
|
61
|
-
moduleName: "serwist
|
|
61
|
+
moduleName: "serwist",
|
|
62
62
|
className: this.constructor.name,
|
|
63
63
|
funcName: "handle",
|
|
64
64
|
paramName: "request",
|
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { HandlerCallbackOptions, RouteHandlerObject, SerwistPlugin } from "
|
|
10
|
-
import { SerwistError } from "
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
9
|
+
import type { HandlerCallbackOptions, RouteHandlerObject, SerwistPlugin } 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,15 +6,15 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } from "
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { cacheMatchIgnoreParams } from "
|
|
14
|
-
import { executeQuotaErrorCallbacks } from "
|
|
15
|
-
import { getFriendlyURL } from "
|
|
16
|
-
import { logger } from "
|
|
17
|
-
import { timeout } from "
|
|
9
|
+
import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } 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
18
|
import type { Strategy } from "./Strategy.js";
|
|
19
19
|
|
|
20
20
|
function toRequest(input: RequestInfo) {
|
|
@@ -78,13 +78,13 @@ export class StrategyHandler {
|
|
|
78
78
|
) {
|
|
79
79
|
if (process.env.NODE_ENV !== "production") {
|
|
80
80
|
assert!.isInstance(options.event, ExtendableEvent, {
|
|
81
|
-
moduleName: "serwist
|
|
81
|
+
moduleName: "serwist",
|
|
82
82
|
className: "StrategyHandler",
|
|
83
83
|
funcName: "constructor",
|
|
84
84
|
paramName: "options.event",
|
|
85
85
|
});
|
|
86
86
|
assert!.isInstance(options.request, Request, {
|
|
87
|
-
moduleName: "serwist
|
|
87
|
+
moduleName: "serwist",
|
|
88
88
|
className: "StrategyHandler",
|
|
89
89
|
funcName: "constructor",
|
|
90
90
|
paramName: "options.request",
|
|
@@ -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)}'`,
|
|
@@ -112,7 +112,7 @@ export const messages = {
|
|
|
112
112
|
},
|
|
113
113
|
|
|
114
114
|
"duplicate-queue-name": ({ name }) => {
|
|
115
|
-
return `The
|
|
115
|
+
return `The queue name '${name}' is already being used. All instances of 'serwist.BackgroundSyncQueue' must be given unique names.`;
|
|
116
116
|
},
|
|
117
117
|
|
|
118
118
|
"expired-test-without-max-age": ({ methodName, paramName }) => {
|
package/src/navigationPreload.ts
CHANGED
|
@@ -7,7 +7,7 @@ declare const self: ServiceWorkerGlobalScope;
|
|
|
7
7
|
* navigation preloading.
|
|
8
8
|
*
|
|
9
9
|
* @returns
|
|
10
|
-
* @see https://serwist.pages.dev/docs/
|
|
10
|
+
* @see https://serwist.pages.dev/docs/serwist/core/is-navigation-preload-supported
|
|
11
11
|
*/
|
|
12
12
|
export const isNavigationPreloadSupported = (): boolean => {
|
|
13
13
|
return Boolean(self.registration?.navigationPreload);
|
|
@@ -19,7 +19,7 @@ export const isNavigationPreloadSupported = (): boolean => {
|
|
|
19
19
|
* @param headerValue Optional. Allows developers to override the value of
|
|
20
20
|
* the `Service-Worker-Navigation-Preload` header which will be sent to the
|
|
21
21
|
* server when making the navigation request.
|
|
22
|
-
* @see https://serwist.pages.dev/docs/
|
|
22
|
+
* @see https://serwist.pages.dev/docs/serwist/core/enable-navigation-preload
|
|
23
23
|
*/
|
|
24
24
|
export const enableNavigationPreload = (headerValue?: string): void => {
|
|
25
25
|
if (isNavigationPreloadSupported()) {
|
|
@@ -47,7 +47,7 @@ export const enableNavigationPreload = (headerValue?: string): void => {
|
|
|
47
47
|
/**
|
|
48
48
|
* If the browser supports navigation preloading, then this will disable it.
|
|
49
49
|
*
|
|
50
|
-
* @see https://serwist.pages.dev/docs/
|
|
50
|
+
* @see https://serwist.pages.dev/docs/serwist/core/disable-navigation-preload
|
|
51
51
|
*/
|
|
52
52
|
export const disableNavigationPreload = (): void => {
|
|
53
53
|
if (isNavigationPreloadSupported()) {
|
package/src/parseRoute.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { RouteHandler, RouteMatchCallback } from "./types.js";
|
|
2
|
-
import { SerwistError } from "./utils/SerwistError.js";
|
|
3
|
-
import { logger } from "./utils/logger.js";
|
|
4
1
|
import { RegExpRoute } from "./RegExpRoute.js";
|
|
5
2
|
import { Route } from "./Route.js";
|
|
6
3
|
import type { HTTPMethod } from "./constants.js";
|
|
4
|
+
import type { RouteHandler, RouteMatchCallback } from "./types.js";
|
|
5
|
+
import { SerwistError } from "./utils/SerwistError.js";
|
|
6
|
+
import { logger } from "./utils/logger.js";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Parses a `RegExp`, string, or function with a caching strategy into a `Route`. This is for
|
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
+
import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
|
|
9
10
|
import { assert } from "./utils/assert.js";
|
|
10
11
|
import { logger } from "./utils/logger.js";
|
|
11
|
-
import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Adds a function to the set of quotaErrorCallbacks that will be executed if
|
package/src/types.ts
CHANGED
|
@@ -335,22 +335,27 @@ export declare interface PrecacheEntry {
|
|
|
335
335
|
|
|
336
336
|
export interface PrecacheRouteOptions {
|
|
337
337
|
/**
|
|
338
|
-
*
|
|
339
|
-
*
|
|
338
|
+
* Tells Serwist to check the precache for an entry whose URL is the request URL appended
|
|
339
|
+
* with the specified value. Only applies if the request URL ends with "/".
|
|
340
|
+
*
|
|
341
|
+
* @default "index.html"
|
|
340
342
|
*/
|
|
341
343
|
directoryIndex?: string | null;
|
|
342
344
|
/**
|
|
343
|
-
* An array of RegExp
|
|
345
|
+
* An array of `RegExp` objects matching search params that should be removed when looking
|
|
346
|
+
* for a precache match.
|
|
344
347
|
*/
|
|
345
348
|
ignoreURLParametersMatching?: RegExp[];
|
|
346
349
|
/**
|
|
347
|
-
*
|
|
348
|
-
*
|
|
350
|
+
* Tells Serwist to check the precache for an entry whose URL is the request URL appended
|
|
351
|
+
* with ".html".
|
|
352
|
+
*
|
|
353
|
+
* @default true
|
|
349
354
|
*/
|
|
350
355
|
cleanURLs?: boolean;
|
|
351
356
|
/**
|
|
352
|
-
*
|
|
353
|
-
*
|
|
357
|
+
* A function that should take a URL and return an array of alternative URLs that should
|
|
358
|
+
* be checked for precache matches.
|
|
354
359
|
*/
|
|
355
360
|
urlManipulation?: UrlManipulation;
|
|
356
361
|
}
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { SerwistPlugin, SerwistPluginCallbackParam } from "../types.js";
|
|
10
9
|
import type { Serwist } from "../Serwist.js";
|
|
10
|
+
import type { SerwistPlugin, SerwistPluginCallbackParam } from "../types.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* A plugin, designed to be used with PrecacheController, to translate URLs into
|
package/src/utils/assert.ts
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { SerwistError } from "./SerwistError.js";
|
|
10
9
|
import type { MapLikeObject } from "../types.js";
|
|
10
|
+
import { SerwistError } from "./SerwistError.js";
|
|
11
11
|
|
|
12
12
|
/*
|
|
13
13
|
* This method throws if the supplied value is not an array.
|
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import { logger } from "./logger.js";
|
|
10
9
|
import { quotaErrorCallbacks } from "../models/quotaErrorCallbacks.js";
|
|
10
|
+
import { logger } from "./logger.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Runs all of the callback functions, one at a time sequentially, in the order
|
package/src/utils/welcome.ts
CHANGED
|
@@ -14,6 +14,6 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
14
14
|
const padding = " ";
|
|
15
15
|
logger.groupCollapsed("Welcome to Serwist!");
|
|
16
16
|
logger.log(`📖 Read the guides and documentation\n${padding}https://serwist.pages.dev/`);
|
|
17
|
-
logger.log(`🐛 Found a bug or want to ask a question? Open a new issue on
|
|
17
|
+
logger.log(`🐛 Found a bug or want to ask a question? Open a new issue on GitHub\n${padding}https://github.com/serwist/serwist/issues/new/choose`);
|
|
18
18
|
logger.groupEnd();
|
|
19
19
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"PrecacheStrategy.d.ts","sourceRoot":"","sources":["../src/PrecacheStrategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,UAAU,uBAAwB,SAAQ,eAAe;IACvD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAU;IAE7C,MAAM,CAAC,QAAQ,CAAC,iCAAiC,EAAE,aAAa,CAQ9D;IAEF,MAAM,CAAC,QAAQ,CAAC,sCAAsC,EAAE,aAAa,CAInE;IAEF;;OAEG;gBACS,OAAO,GAAE,uBAA4B;IAajD;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiBtE,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAwE3E,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAoBnF;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,qCAAqC,IAAI,IAAI;CA4B9C"}
|