serwist 10.0.0-preview.1 → 10.0.0-preview.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/{resultingClientExists.js → waitUntil.js} +144 -144
- package/dist/index.d.ts +22 -50
- 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 +3 -3
- package/dist/index.js +1925 -1803
- package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.d.ts +1 -1
- package/dist/lib/background-sync/BackgroundSyncPlugin.d.ts.map +1 -0
- package/dist/lib/background-sync/BackgroundSyncQueue.d.ts.map +1 -0
- package/dist/lib/background-sync/BackgroundSyncQueueDb.d.ts.map +1 -0
- package/dist/lib/background-sync/BackgroundSyncQueueStore.d.ts.map +1 -0
- package/dist/lib/{backgroundSync → background-sync}/StorableRequest.d.ts +1 -1
- package/dist/lib/background-sync/StorableRequest.d.ts.map +1 -0
- package/dist/lib/background-sync/index.d.ts +6 -0
- package/dist/lib/background-sync/index.d.ts.map +1 -0
- package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.d.ts +1 -1
- package/dist/lib/broadcast-update/BroadcastCacheUpdate.d.ts.map +1 -0
- package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.d.ts +1 -1
- package/dist/lib/broadcast-update/BroadcastUpdatePlugin.d.ts.map +1 -0
- package/dist/lib/broadcast-update/constants.d.ts.map +1 -0
- package/dist/lib/broadcast-update/index.d.ts +6 -0
- package/dist/lib/broadcast-update/index.d.ts.map +1 -0
- package/dist/lib/broadcast-update/responsesAreSame.d.ts.map +1 -0
- package/dist/lib/{broadcastUpdate → broadcast-update}/types.d.ts +1 -1
- package/dist/lib/broadcast-update/types.d.ts.map +1 -0
- package/dist/{cacheNames.d.ts → lib/cache-name.d.ts} +1 -1
- package/dist/lib/cache-name.d.ts.map +1 -0
- package/dist/lib/cacheable-response/CacheableResponse.d.ts.map +1 -0
- package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.d.ts +1 -1
- package/dist/lib/cacheable-response/CacheableResponsePlugin.d.ts.map +1 -0
- package/dist/lib/cacheable-response/index.d.ts +4 -0
- package/dist/lib/cacheable-response/index.d.ts.map +1 -0
- package/dist/{constants.d.ts → lib/constants.d.ts} +1 -1
- package/dist/lib/constants.d.ts.map +1 -0
- package/dist/lib/core.d.ts +62 -0
- package/dist/lib/core.d.ts.map +1 -0
- package/dist/lib/expiration/ExpirationPlugin.d.ts +1 -1
- package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -1
- package/dist/lib/expiration/index.d.ts +4 -0
- package/dist/lib/expiration/index.d.ts.map +1 -0
- package/dist/lib/extension.d.ts +30 -0
- package/dist/lib/extension.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/constants.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/extension.d.ts +79 -0
- package/dist/lib/extensions/google-analytics/extension.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/index.d.ts +2 -0
- package/dist/lib/extensions/google-analytics/index.d.ts.map +1 -0
- package/dist/lib/extensions/google-analytics/initialize.d.ts +12 -0
- package/dist/lib/extensions/google-analytics/initialize.d.ts.map +1 -0
- package/dist/lib/extensions/index.d.ts +14 -0
- package/dist/lib/extensions/index.d.ts.map +1 -0
- package/dist/{controllers/PrecacheController/PrecacheController.d.ts → lib/extensions/precache/extension.d.ts} +19 -38
- package/dist/lib/extensions/precache/extension.d.ts.map +1 -0
- package/dist/{controllers/PrecacheController/parsePrecacheOptions.d.ts → lib/extensions/precache/options.d.ts} +6 -5
- package/dist/lib/extensions/precache/options.d.ts.map +1 -0
- package/dist/{controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts → lib/extensions/precache/plugin-cache-key.d.ts} +4 -4
- package/dist/lib/extensions/precache/plugin-cache-key.d.ts.map +1 -0
- package/dist/lib/{precaching/PrecacheFallbackPlugin.d.ts → extensions/precache/plugin-fallback.d.ts} +11 -11
- package/dist/lib/extensions/precache/plugin-fallback.d.ts.map +1 -0
- package/dist/{controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts → lib/extensions/precache/plugin-install-report.d.ts} +2 -2
- package/dist/lib/extensions/precache/plugin-install-report.d.ts.map +1 -0
- package/dist/lib/extensions/precache/route.d.ts +42 -0
- package/dist/lib/extensions/precache/route.d.ts.map +1 -0
- package/dist/{controllers/PrecacheController/PrecacheStrategy.d.ts → lib/extensions/precache/strategy.d.ts} +5 -5
- package/dist/lib/extensions/precache/strategy.d.ts.map +1 -0
- package/dist/{controllers/RuntimeCacheController.d.ts → lib/extensions/runtime-cache.d.ts} +16 -10
- package/dist/lib/extensions/runtime-cache.d.ts.map +1 -0
- package/dist/lib/functions/handlers.d.ts +60 -0
- package/dist/lib/functions/handlers.d.ts.map +1 -0
- package/dist/lib/functions/router.d.ts +60 -0
- package/dist/lib/functions/router.d.ts.map +1 -0
- package/dist/{navigationPreload.d.ts → lib/navigation-preload.d.ts} +1 -1
- package/dist/lib/navigation-preload.d.ts.map +1 -0
- package/dist/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.d.ts +1 -1
- package/dist/lib/range-requests/RangeRequestsPlugin.d.ts.map +1 -0
- package/dist/lib/range-requests/createPartialResponse.d.ts.map +1 -0
- package/dist/lib/range-requests/index.d.ts +3 -0
- package/dist/lib/range-requests/index.d.ts.map +1 -0
- package/dist/lib/range-requests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
- package/dist/lib/range-requests/utils/parseRangeHeader.d.ts.map +1 -0
- package/dist/lib/route.d.ts +106 -0
- package/dist/lib/route.d.ts.map +1 -0
- package/dist/{Serwist.d.ts → lib/serwist.d.ts} +28 -41
- package/dist/lib/serwist.d.ts.map +1 -0
- package/dist/lib/strategies/NetworkFirst.d.ts.map +1 -1
- package/dist/lib/strategies/StaleWhileRevalidate.d.ts.map +1 -1
- package/dist/lib/strategies/Strategy.d.ts +1 -1
- package/dist/lib/strategies/Strategy.d.ts.map +1 -1
- package/dist/lib/strategies/StrategyHandler.d.ts +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/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +1 -1
- package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -1
- package/dist/{types.d.ts → lib/types.d.ts} +15 -24
- package/dist/lib/types.d.ts.map +1 -0
- package/dist/{copyResponse.d.ts → lib/utils.d.ts} +22 -1
- package/dist/lib/utils.d.ts.map +1 -0
- package/dist/models/messages/messageGenerator.d.ts +1 -1
- package/dist/models/messages/messageGenerator.d.ts.map +1 -1
- package/dist/utils/SerwistError.d.ts +2 -2
- package/dist/utils/SerwistError.d.ts.map +1 -1
- package/dist/utils/assert.d.ts +1 -1
- package/dist/utils/assert.d.ts.map +1 -1
- package/dist/utils/cacheNames.d.ts.map +1 -1
- package/dist/utils/cleanupOutdatedCaches.d.ts.map +1 -1
- package/dist/utils/createCacheKey.d.ts +1 -1
- package/dist/utils/createCacheKey.d.ts.map +1 -1
- package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -1
- package/dist/utils/generateURLVariations.d.ts +1 -1
- package/dist/utils/generateURLVariations.d.ts.map +1 -1
- package/dist/utils/getFriendlyURL.d.ts.map +1 -1
- package/dist/utils/logger.d.ts +1 -1
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/normalizeHandler.d.ts +1 -1
- package/dist/utils/normalizeHandler.d.ts.map +1 -1
- package/dist/utils/parseRoute.d.ts +3 -3
- package/dist/utils/parseRoute.d.ts.map +1 -1
- package/dist/utils/pluginUtils.d.ts +1 -1
- 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 +30 -6
- package/src/index.internal.ts +16 -16
- package/src/index.ts +100 -110
- package/src/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.ts +1 -1
- package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.ts +7 -7
- package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.ts +1 -1
- package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.ts +1 -3
- package/src/lib/{backgroundSync → background-sync}/StorableRequest.ts +2 -2
- package/src/lib/background-sync/index.ts +5 -0
- package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.ts +5 -5
- package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.ts +1 -1
- package/src/lib/broadcast-update/index.ts +5 -0
- package/src/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.ts +2 -2
- package/src/lib/{broadcastUpdate → broadcast-update}/types.ts +1 -1
- package/src/{cacheNames.ts → lib/cache-name.ts} +1 -1
- package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponse.ts +4 -4
- package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.ts +1 -1
- package/src/lib/cacheable-response/index.ts +3 -0
- package/src/lib/core.ts +128 -0
- package/src/lib/expiration/CacheExpiration.ts +3 -3
- package/src/lib/expiration/ExpirationPlugin.ts +9 -10
- package/src/lib/expiration/index.ts +3 -0
- package/src/lib/extension.ts +37 -0
- package/src/lib/{googleAnalytics/initializeGoogleAnalytics.ts → extensions/google-analytics/extension.ts} +43 -49
- package/src/lib/extensions/google-analytics/index.ts +0 -0
- package/src/lib/extensions/google-analytics/initialize.ts +48 -0
- package/src/lib/extensions/index.ts +13 -0
- package/src/{controllers/PrecacheController/PrecacheController.ts → lib/extensions/precache/extension.ts} +37 -56
- package/src/{controllers/PrecacheController/parsePrecacheOptions.ts → lib/extensions/precache/options.ts} +11 -8
- package/src/{controllers/PrecacheController/PrecacheCacheKeyPlugin.ts → lib/extensions/precache/plugin-cache-key.ts} +4 -4
- package/src/lib/{precaching/PrecacheFallbackPlugin.ts → extensions/precache/plugin-fallback.ts} +26 -16
- package/src/{controllers/PrecacheController/PrecacheInstallReportPlugin.ts → lib/extensions/precache/plugin-install-report.ts} +1 -1
- package/src/lib/extensions/precache/route.ts +72 -0
- package/src/{controllers/PrecacheController/PrecacheStrategy.ts → lib/extensions/precache/strategy.ts} +11 -11
- package/src/{controllers/RuntimeCacheController.ts → lib/extensions/runtime-cache.ts} +24 -17
- package/src/lib/functions/handlers.ts +149 -0
- package/src/lib/functions/router.ts +314 -0
- package/src/{navigationPreload.ts → lib/navigation-preload.ts} +1 -1
- package/src/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.ts +1 -1
- package/src/lib/{rangeRequests → range-requests}/createPartialResponse.ts +3 -3
- package/src/lib/range-requests/index.ts +2 -0
- package/src/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.ts +2 -2
- package/src/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.ts +2 -2
- package/src/lib/route.ts +234 -0
- package/src/lib/serwist.ts +443 -0
- package/src/lib/strategies/CacheFirst.ts +4 -4
- package/src/lib/strategies/CacheOnly.ts +3 -3
- package/src/lib/strategies/NetworkFirst.ts +6 -6
- package/src/lib/strategies/NetworkOnly.ts +5 -5
- package/src/lib/strategies/StaleWhileRevalidate.ts +5 -5
- package/src/lib/strategies/Strategy.ts +9 -9
- package/src/lib/strategies/StrategyHandler.ts +11 -11
- package/src/lib/strategies/index.ts +10 -0
- package/src/lib/strategies/plugins/cacheOkAndOpaquePlugin.ts +1 -1
- package/src/lib/strategies/utils/messages.ts +2 -2
- package/src/{types.ts → lib/types.ts} +17 -26
- package/src/lib/utils.ts +137 -0
- package/src/models/messages/messageGenerator.ts +1 -1
- package/src/models/messages/messages.ts +3 -3
- package/src/utils/SerwistError.ts +3 -3
- package/src/utils/assert.ts +1 -2
- package/src/utils/cacheNames.ts +0 -2
- package/src/utils/canConstructReadableStream.ts +1 -1
- package/src/utils/canConstructResponseFromBodyStream.ts +1 -1
- package/src/utils/createCacheKey.ts +1 -2
- package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
- package/src/utils/generateURLVariations.ts +1 -1
- package/src/utils/logger.ts +1 -1
- package/src/utils/normalizeHandler.ts +1 -1
- package/src/utils/parseRoute.ts +4 -5
- package/src/utils/pluginUtils.ts +1 -1
- package/src/utils/resultingClientExists.ts +1 -1
- package/dist/NavigationRoute.d.ts +0 -56
- package/dist/NavigationRoute.d.ts.map +0 -1
- package/dist/RegExpRoute.d.ts +0 -24
- package/dist/RegExpRoute.d.ts.map +0 -1
- package/dist/Route.d.ts +0 -33
- package/dist/Route.d.ts.map +0 -1
- package/dist/Serwist.d.ts.map +0 -1
- package/dist/cacheNames.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -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 +0 -15
- 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
- package/dist/copyResponse.d.ts.map +0 -1
- package/dist/disableDevLogs.d.ts +0 -7
- package/dist/disableDevLogs.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncQueueDb.d.ts.map +0 -1
- package/dist/lib/backgroundSync/BackgroundSyncQueueStore.d.ts.map +0 -1
- package/dist/lib/backgroundSync/StorableRequest.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/constants.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
- package/dist/lib/broadcastUpdate/types.d.ts.map +0 -1
- package/dist/lib/cacheableResponse/CacheableResponse.d.ts.map +0 -1
- package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
- package/dist/lib/googleAnalytics/constants.d.ts.map +0 -1
- package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts +0 -30
- package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +0 -1
- package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
- package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
- package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +0 -1
- package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
- package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
- package/dist/navigationPreload.d.ts.map +0 -1
- package/dist/registerQuotaErrorCallback.d.ts +0 -8
- package/dist/registerQuotaErrorCallback.d.ts.map +0 -1
- package/dist/setCacheNameDetails.d.ts +0 -9
- package/dist/setCacheNameDetails.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/src/NavigationRoute.ts +0 -118
- package/src/RegExpRoute.ts +0 -74
- package/src/Route.ts +0 -67
- package/src/Serwist.ts +0 -762
- package/src/controllers/PrecacheController/PrecacheRoute.ts +0 -44
- package/src/copyResponse.ts +0 -58
- package/src/disableDevLogs.ts +0 -10
- package/src/registerQuotaErrorCallback.ts +0 -34
- package/src/setCacheNameDetails.ts +0 -53
- /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.d.ts +0 -0
- /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.d.ts +0 -0
- /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.d.ts +0 -0
- /package/dist/lib/{broadcastUpdate → broadcast-update}/constants.d.ts +0 -0
- /package/dist/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.d.ts +0 -0
- /package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponse.d.ts +0 -0
- /package/dist/lib/{googleAnalytics → extensions/google-analytics}/constants.d.ts +0 -0
- /package/dist/lib/{rangeRequests → range-requests}/createPartialResponse.d.ts +0 -0
- /package/dist/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.d.ts +0 -0
- /package/dist/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.d.ts +0 -0
- /package/src/lib/{broadcastUpdate → broadcast-update}/constants.ts +0 -0
- /package/src/{constants.ts → lib/constants.ts} +0 -0
- /package/src/lib/{googleAnalytics → extensions/google-analytics}/constants.ts +0 -0
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2020 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { Route } from "../../Route.js";
|
|
10
|
-
import type { RouteMatchCallback, RouteMatchCallbackOptions } from "../../types.js";
|
|
11
|
-
import { generateURLVariations } from "../../utils/generateURLVariations.js";
|
|
12
|
-
import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
|
|
13
|
-
import { logger } from "../../utils/logger.js";
|
|
14
|
-
import type { PrecacheController, PrecacheRouteOptions } from "./PrecacheController.js";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* A subclass of {@linkcode Route} that takes a {@linkcode Serwist} instance and uses it to match
|
|
18
|
-
* incoming requests and handle fetching responses from the precache.
|
|
19
|
-
*/
|
|
20
|
-
export class PrecacheRoute extends Route {
|
|
21
|
-
/**
|
|
22
|
-
* @param controller A {@linkcode PrecacheController} instance.
|
|
23
|
-
* @param options Options to control how requests are matched
|
|
24
|
-
* against the list of precached URLs.
|
|
25
|
-
*/
|
|
26
|
-
constructor(controller: PrecacheController, options?: PrecacheRouteOptions) {
|
|
27
|
-
const match: RouteMatchCallback = ({ request }: RouteMatchCallbackOptions) => {
|
|
28
|
-
const urlsToCacheKeys = controller.getUrlsToPrecacheKeys();
|
|
29
|
-
for (const possibleURL of generateURLVariations(request.url, options)) {
|
|
30
|
-
const cacheKey = urlsToCacheKeys.get(possibleURL);
|
|
31
|
-
if (cacheKey) {
|
|
32
|
-
const integrity = controller.getIntegrityForPrecacheKey(cacheKey);
|
|
33
|
-
return { cacheKey, integrity };
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
if (process.env.NODE_ENV !== "production") {
|
|
37
|
-
logger.debug(`Precaching did not find a match for ${getFriendlyURL(request.url)}.`);
|
|
38
|
-
}
|
|
39
|
-
return;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
super(match, controller.strategy);
|
|
43
|
-
}
|
|
44
|
-
}
|
package/src/copyResponse.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { SerwistError } from "./utils/SerwistError.js";
|
|
10
|
-
import { canConstructResponseFromBodyStream } from "./utils/canConstructResponseFromBodyStream.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Allows developers to copy a response and modify its `headers`, `status`,
|
|
14
|
-
* or `statusText` values (the [valid options](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#options)
|
|
15
|
-
* when constructing a `Response` object).
|
|
16
|
-
* To modify these values, pass a function as the second argument. That
|
|
17
|
-
* function will be invoked with the options of the initial `Response` object.
|
|
18
|
-
* The return value of this function will be used as the options for the new `Response` object.
|
|
19
|
-
* To change the values either modify the passed parameter(s) and return it or return a totally
|
|
20
|
-
* new object.
|
|
21
|
-
*
|
|
22
|
-
* This method is intentionally limited to same-origin responses, regardless of
|
|
23
|
-
* whether CORS was used or not.
|
|
24
|
-
*
|
|
25
|
-
* @param response The initial response.
|
|
26
|
-
* @param modifier The function used to modify the options of the `Response` object.
|
|
27
|
-
*/
|
|
28
|
-
export const copyResponse = async (response: Response, modifier?: (responseInit: ResponseInit) => ResponseInit): Promise<Response> => {
|
|
29
|
-
let origin = null;
|
|
30
|
-
// If response.url isn't set, assume it's cross-origin and keep origin null.
|
|
31
|
-
if (response.url) {
|
|
32
|
-
const responseURL = new URL(response.url);
|
|
33
|
-
origin = responseURL.origin;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (origin !== self.location.origin) {
|
|
37
|
-
throw new SerwistError("cross-origin-copy-response", { origin });
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const clonedResponse = response.clone();
|
|
41
|
-
|
|
42
|
-
// Create a fresh `ResponseInit` object by cloning the headers.
|
|
43
|
-
const responseInit: ResponseInit = {
|
|
44
|
-
headers: new Headers(clonedResponse.headers),
|
|
45
|
-
status: clonedResponse.status,
|
|
46
|
-
statusText: clonedResponse.statusText,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
// Apply any user modifications.
|
|
50
|
-
const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
|
|
51
|
-
|
|
52
|
-
// Create the new response from the body stream and `ResponseInit`
|
|
53
|
-
// modifications. Note: not all browsers support the Response.body stream,
|
|
54
|
-
// so fall back to reading the entire body into memory as a blob.
|
|
55
|
-
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
|
56
|
-
|
|
57
|
-
return new Response(body, modifiedResponseInit);
|
|
58
|
-
};
|
package/src/disableDevLogs.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare const self: ServiceWorkerGlobalScope;
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Disables Serwist's logging in development mode.
|
|
5
|
-
*
|
|
6
|
-
* @see https://serwist.pages.dev/docs/serwist/core/disable-dev-logs
|
|
7
|
-
*/
|
|
8
|
-
export const disableDevLogs = (): void => {
|
|
9
|
-
self.__WB_DISABLE_DEV_LOGS = true;
|
|
10
|
-
};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
|
|
10
|
-
import { assert } from "./utils/assert.js";
|
|
11
|
-
import { logger } from "./utils/logger.js";
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Adds a function to the set of quotaErrorCallbacks that will be executed if
|
|
15
|
-
* there's a quota error.
|
|
16
|
-
*
|
|
17
|
-
* @param callback
|
|
18
|
-
*/
|
|
19
|
-
// biome-ignore lint/complexity/noBannedTypes: Can't change Function type
|
|
20
|
-
export const registerQuotaErrorCallback = (callback: Function): void => {
|
|
21
|
-
if (process.env.NODE_ENV !== "production") {
|
|
22
|
-
assert!.isType(callback, "function", {
|
|
23
|
-
moduleName: "@serwist/core",
|
|
24
|
-
funcName: "register",
|
|
25
|
-
paramName: "callback",
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
quotaErrorCallbacks.add(callback);
|
|
30
|
-
|
|
31
|
-
if (process.env.NODE_ENV !== "production") {
|
|
32
|
-
logger.log("Registered a callback to respond to quota errors.", callback);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2019 Google LLC
|
|
3
|
-
|
|
4
|
-
Use of this source code is governed by an MIT-style
|
|
5
|
-
license that can be found in the LICENSE file or at
|
|
6
|
-
https://opensource.org/licenses/MIT.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { SerwistError } from "./utils/SerwistError.js";
|
|
10
|
-
import { assert } from "./utils/assert.js";
|
|
11
|
-
import type { PartialCacheNameDetails } from "./utils/cacheNames.js";
|
|
12
|
-
import { cacheNames } from "./utils/cacheNames.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Modifies the default cache names used by Serwist packages.
|
|
16
|
-
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
|
17
|
-
*
|
|
18
|
-
* @param details
|
|
19
|
-
*/
|
|
20
|
-
export const setCacheNameDetails = (details: PartialCacheNameDetails): void => {
|
|
21
|
-
if (process.env.NODE_ENV !== "production") {
|
|
22
|
-
for (const key of Object.keys(details)) {
|
|
23
|
-
assert!.isType(details[key], "string", {
|
|
24
|
-
moduleName: "@serwist/core",
|
|
25
|
-
funcName: "setCacheNameDetails",
|
|
26
|
-
paramName: `details.${key}`,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (details.precache?.length === 0) {
|
|
31
|
-
throw new SerwistError("invalid-cache-name", {
|
|
32
|
-
cacheNameId: "precache",
|
|
33
|
-
value: details.precache,
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (details.runtime?.length === 0) {
|
|
38
|
-
throw new SerwistError("invalid-cache-name", {
|
|
39
|
-
cacheNameId: "runtime",
|
|
40
|
-
value: details.runtime,
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (details.googleAnalytics?.length === 0) {
|
|
45
|
-
throw new SerwistError("invalid-cache-name", {
|
|
46
|
-
cacheNameId: "googleAnalytics",
|
|
47
|
-
value: details.googleAnalytics,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
cacheNames.updateDetails(details);
|
|
53
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|