@serwist/sw 9.0.0-preview.2 → 9.0.0-preview.20
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/abstractions/Serwist.d.ts +82 -0
- package/dist/abstractions/Serwist.d.ts.map +1 -0
- package/dist/{disableDevLogs.d.ts → abstractions/disableDevLogs.d.ts} +2 -0
- package/dist/abstractions/disableDevLogs.d.ts.map +1 -0
- package/dist/{fallbacks.d.ts → abstractions/fallbacks.d.ts} +9 -20
- package/dist/abstractions/fallbacks.d.ts.map +1 -0
- package/dist/{handlePrecaching.d.ts → abstractions/handlePrecaching.d.ts} +8 -10
- package/dist/abstractions/handlePrecaching.d.ts.map +1 -0
- package/dist/abstractions/installSerwist.d.ts +15 -0
- package/dist/abstractions/installSerwist.d.ts.map +1 -0
- package/dist/abstractions/navigationPreload.d.ts +20 -0
- package/dist/abstractions/navigationPreload.d.ts.map +1 -0
- package/dist/{registerRuntimeCaching.d.ts → abstractions/registerRuntimeCaching.d.ts} +2 -0
- package/dist/abstractions/registerRuntimeCaching.d.ts.map +1 -0
- package/dist/abstractions/types.d.ts +29 -0
- package/dist/abstractions/types.d.ts.map +1 -0
- package/dist/chunks/NavigationRoute.js +54 -0
- package/dist/chunks/NetworkOnly.js +193 -0
- package/dist/chunks/PrecacheFallbackPlugin.js +573 -0
- package/dist/chunks/Strategy.js +410 -0
- package/dist/chunks/precacheAndRoute.js +113 -0
- package/dist/chunks/registerRoute.js +7 -0
- package/dist/chunks/singletonPrecacheController.js +433 -0
- package/dist/chunks/singletonRouter.js +435 -0
- package/dist/index.d.ts +11 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +121 -124
- package/dist/index.plugins.d.ts +41 -0
- package/dist/index.plugins.d.ts.map +1 -0
- package/dist/index.plugins.js +671 -0
- package/dist/index.precaching.d.ts +25 -0
- package/dist/index.precaching.d.ts.map +1 -0
- package/dist/index.precaching.js +24 -0
- package/dist/index.routing.d.ts +15 -0
- package/dist/index.routing.d.ts.map +1 -0
- package/dist/index.routing.js +19 -0
- package/dist/index.strategies.d.ts +22 -0
- package/dist/index.strategies.d.ts.map +1 -0
- package/dist/index.strategies.js +146 -0
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +23 -0
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/Queue.d.ts +166 -0
- package/dist/plugins/backgroundSync/Queue.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/QueueDb.d.ts +90 -0
- package/dist/plugins/backgroundSync/QueueDb.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/QueueStore.d.ts +75 -0
- package/dist/plugins/backgroundSync/QueueStore.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/StorableRequest.d.ts +51 -0
- package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +45 -0
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +27 -0
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/constants.d.ts +5 -0
- package/dist/plugins/broadcastUpdate/constants.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +11 -0
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/types.d.ts +34 -0
- package/dist/plugins/broadcastUpdate/types.d.ts.map +1 -0
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +40 -0
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +1 -0
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +27 -0
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
- package/dist/plugins/expiration/CacheExpiration.d.ts +66 -0
- package/dist/plugins/expiration/CacheExpiration.d.ts.map +1 -0
- package/dist/plugins/expiration/ExpirationPlugin.d.ts +116 -0
- package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +1 -0
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +73 -0
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
- package/dist/plugins/googleAnalytics/constants.d.ts +10 -0
- package/dist/plugins/googleAnalytics/constants.d.ts.map +1 -0
- package/dist/plugins/googleAnalytics/initialize.d.ts +34 -0
- package/dist/plugins/googleAnalytics/initialize.d.ts.map +1 -0
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +54 -0
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +19 -0
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts +18 -0
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +14 -0
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +12 -0
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
- package/dist/precaching/PrecacheController.d.ts +145 -0
- package/dist/precaching/PrecacheController.d.ts.map +1 -0
- package/dist/precaching/PrecacheRoute.d.ts +20 -0
- package/dist/precaching/PrecacheRoute.d.ts.map +1 -0
- package/dist/precaching/PrecacheStrategy.d.ts +68 -0
- package/dist/precaching/PrecacheStrategy.d.ts.map +1 -0
- package/dist/precaching/addPlugins.d.ts +8 -0
- package/dist/precaching/addPlugins.d.ts.map +1 -0
- package/dist/precaching/addRoute.d.ts +15 -0
- package/dist/precaching/addRoute.d.ts.map +1 -0
- package/dist/precaching/cleanupOutdatedCaches.d.ts +6 -0
- package/dist/precaching/cleanupOutdatedCaches.d.ts.map +1 -0
- package/dist/precaching/createHandlerBoundToURL.d.ts +17 -0
- package/dist/precaching/createHandlerBoundToURL.d.ts.map +1 -0
- package/dist/precaching/getCacheKeyForURL.d.ts +20 -0
- package/dist/precaching/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/precaching/matchPrecache.d.ts +14 -0
- package/dist/precaching/matchPrecache.d.ts.map +1 -0
- package/dist/precaching/precache.d.ts +19 -0
- package/dist/precaching/precache.d.ts.map +1 -0
- package/dist/precaching/precacheAndRoute.d.ts +14 -0
- package/dist/precaching/precacheAndRoute.d.ts.map +1 -0
- package/dist/precaching/singletonPrecacheController.d.ts +38 -0
- package/dist/precaching/singletonPrecacheController.d.ts.map +1 -0
- package/dist/precaching/types.d.ts +37 -0
- package/dist/precaching/types.d.ts.map +1 -0
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts +17 -0
- package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts +15 -0
- package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
- package/dist/precaching/utils/createCacheKey.d.ts +16 -0
- package/dist/precaching/utils/createCacheKey.d.ts.map +1 -0
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts +18 -0
- package/dist/precaching/utils/deleteOutdatedCaches.d.ts.map +1 -0
- package/dist/precaching/utils/generateURLVariations.d.ts +12 -0
- package/dist/precaching/utils/generateURLVariations.d.ts.map +1 -0
- package/dist/precaching/utils/getCacheKeyForURL.d.ts +14 -0
- package/dist/precaching/utils/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/precaching/utils/printCleanupDetails.d.ts +6 -0
- package/dist/precaching/utils/printCleanupDetails.d.ts.map +1 -0
- package/dist/precaching/utils/printInstallDetails.d.ts +7 -0
- package/dist/precaching/utils/printInstallDetails.d.ts.map +1 -0
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts +12 -0
- package/dist/precaching/utils/removeIgnoredSearchParams.d.ts.map +1 -0
- package/dist/routing/NavigationRoute.d.ts +57 -0
- package/dist/routing/NavigationRoute.d.ts.map +1 -0
- package/dist/routing/RegExpRoute.d.ts +24 -0
- package/dist/routing/RegExpRoute.d.ts.map +1 -0
- package/dist/routing/Route.d.ts +33 -0
- package/dist/routing/Route.d.ts.map +1 -0
- package/dist/routing/Router.d.ts +150 -0
- package/dist/routing/Router.d.ts.map +1 -0
- package/dist/routing/parseRoute.d.ts +16 -0
- package/dist/routing/parseRoute.d.ts.map +1 -0
- package/dist/routing/registerRoute.d.ts +15 -0
- package/dist/routing/registerRoute.d.ts.map +1 -0
- package/dist/routing/setCatchHandler.d.ts +9 -0
- package/dist/routing/setCatchHandler.d.ts.map +1 -0
- package/dist/routing/setDefaultHandler.d.ts +12 -0
- package/dist/routing/setDefaultHandler.d.ts.map +1 -0
- package/dist/routing/singletonRouter.d.ts +47 -0
- package/dist/routing/singletonRouter.d.ts.map +1 -0
- package/dist/routing/unregisterRoute.d.ts +8 -0
- package/dist/routing/unregisterRoute.d.ts.map +1 -0
- package/dist/routing/utils/constants.d.ts +15 -0
- package/dist/routing/utils/constants.d.ts.map +1 -0
- package/dist/routing/utils/normalizeHandler.d.ts +10 -0
- package/dist/routing/utils/normalizeHandler.d.ts.map +1 -0
- package/dist/strategies/CacheFirst.d.ts +23 -0
- package/dist/strategies/CacheFirst.d.ts.map +1 -0
- package/dist/strategies/CacheOnly.d.ts +20 -0
- package/dist/strategies/CacheOnly.d.ts.map +1 -0
- package/dist/strategies/NetworkFirst.d.ts +61 -0
- package/dist/strategies/NetworkFirst.d.ts.map +1 -0
- package/dist/strategies/NetworkOnly.d.ts +32 -0
- package/dist/strategies/NetworkOnly.d.ts.map +1 -0
- package/dist/strategies/StaleWhileRevalidate.d.ts +35 -0
- package/dist/strategies/StaleWhileRevalidate.d.ts.map +1 -0
- package/dist/strategies/Strategy.d.ts +83 -0
- package/dist/strategies/Strategy.d.ts.map +1 -0
- package/dist/strategies/StrategyHandler.d.ts +189 -0
- package/dist/strategies/StrategyHandler.d.ts.map +1 -0
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
- package/dist/strategies/utils/messages.d.ts +5 -0
- package/dist/strategies/utils/messages.d.ts.map +1 -0
- package/package.json +42 -19
- package/src/abstractions/Serwist.ts +177 -0
- package/src/abstractions/disableDevLogs.ts +10 -0
- package/src/abstractions/fallbacks.ts +65 -0
- package/src/abstractions/handlePrecaching.ts +65 -0
- package/src/abstractions/installSerwist.ts +28 -0
- package/src/abstractions/navigationPreload.ts +64 -0
- package/src/abstractions/registerRuntimeCaching.ts +17 -0
- package/src/abstractions/types.ts +29 -0
- package/src/index.plugins.ts +95 -0
- package/src/index.precaching.ts +41 -0
- package/src/index.routing.ts +28 -0
- package/src/index.strategies.ts +26 -0
- package/src/index.ts +31 -9
- package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +39 -0
- package/src/plugins/backgroundSync/Queue.ts +438 -0
- package/src/plugins/backgroundSync/QueueDb.ts +176 -0
- package/src/plugins/backgroundSync/QueueStore.ts +161 -0
- package/src/plugins/backgroundSync/StorableRequest.ts +142 -0
- package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +159 -0
- package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +43 -0
- package/src/plugins/broadcastUpdate/constants.ts +12 -0
- package/src/plugins/broadcastUpdate/responsesAreSame.ts +48 -0
- package/src/plugins/broadcastUpdate/types.ts +37 -0
- package/src/plugins/cacheableResponse/CacheableResponse.ts +141 -0
- package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +46 -0
- package/src/plugins/expiration/CacheExpiration.ts +192 -0
- package/src/plugins/expiration/ExpirationPlugin.ts +297 -0
- package/src/plugins/expiration/models/CacheTimestampsModel.ts +184 -0
- package/src/plugins/googleAnalytics/constants.ts +22 -0
- package/src/plugins/googleAnalytics/initialize.ts +213 -0
- package/src/plugins/precaching/PrecacheFallbackPlugin.ts +86 -0
- package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +39 -0
- package/src/plugins/rangeRequests/createPartialResponse.ts +92 -0
- package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +58 -0
- package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +54 -0
- package/src/precaching/PrecacheController.ts +332 -0
- package/src/precaching/PrecacheRoute.ts +50 -0
- package/src/precaching/PrecacheStrategy.ts +238 -0
- package/src/precaching/addPlugins.ts +21 -0
- package/src/precaching/addRoute.ts +30 -0
- package/src/precaching/cleanupOutdatedCaches.ts +33 -0
- package/src/precaching/createHandlerBoundToURL.ts +30 -0
- package/src/precaching/getCacheKeyForURL.ts +33 -0
- package/src/precaching/matchPrecache.ts +25 -0
- package/src/precaching/precache.ts +31 -0
- package/src/precaching/precacheAndRoute.ts +27 -0
- package/src/precaching/singletonPrecacheController.ts +57 -0
- package/src/precaching/types.ts +46 -0
- package/src/precaching/utils/PrecacheCacheKeyPlugin.ts +36 -0
- package/src/precaching/utils/PrecacheInstallReportPlugin.ts +49 -0
- package/src/precaching/utils/createCacheKey.ts +68 -0
- package/src/precaching/utils/deleteOutdatedCaches.ts +40 -0
- package/src/precaching/utils/generateURLVariations.ts +55 -0
- package/src/precaching/utils/getCacheKeyForURL.ts +36 -0
- package/src/precaching/utils/printCleanupDetails.ts +38 -0
- package/src/precaching/utils/printInstallDetails.ts +53 -0
- package/src/precaching/utils/removeIgnoredSearchParams.ts +29 -0
- package/src/routing/NavigationRoute.ts +119 -0
- package/src/routing/RegExpRoute.ts +74 -0
- package/src/routing/Route.ts +68 -0
- package/src/routing/Router.ts +481 -0
- package/src/routing/parseRoute.ts +78 -0
- package/src/routing/registerRoute.ts +27 -0
- package/src/routing/setCatchHandler.ts +21 -0
- package/src/routing/setDefaultHandler.ts +24 -0
- package/src/routing/singletonRouter.ts +76 -0
- package/src/routing/unregisterRoute.ts +11 -0
- package/src/routing/utils/constants.ts +24 -0
- package/src/routing/utils/normalizeHandler.ts +40 -0
- package/src/strategies/CacheFirst.ts +87 -0
- package/src/strategies/CacheOnly.ts +58 -0
- package/src/strategies/NetworkFirst.ts +228 -0
- package/src/strategies/NetworkOnly.ts +96 -0
- package/src/strategies/StaleWhileRevalidate.ts +109 -0
- package/src/strategies/Strategy.ts +202 -0
- package/src/strategies/StrategyHandler.ts +557 -0
- package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +26 -0
- package/src/strategies/utils/messages.ts +20 -0
- package/dist/disableDevLogs.d.ts.map +0 -1
- package/dist/fallbacks.d.ts.map +0 -1
- package/dist/handlePrecaching.d.ts.map +0 -1
- package/dist/installSerwist.d.ts +0 -21
- package/dist/installSerwist.d.ts.map +0 -1
- package/dist/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/types.d.ts +0 -110
- package/dist/types.d.ts.map +0 -1
- package/src/disableDevLogs.ts +0 -10
- package/src/fallbacks.ts +0 -83
- package/src/handlePrecaching.ts +0 -65
- package/src/installSerwist.ts +0 -106
- package/src/registerRuntimeCaching.ts +0 -84
- package/src/types.ts +0 -113
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorableRequest.d.ts","sourceRoot":"","sources":["../../../src/plugins/backgroundSync/StorableRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAiBnD,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;GAMG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAE3C;;;;;;OAMG;WACU,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC;IA6BpE;;;;;;OAMG;gBACS,WAAW,EAAE,WAAW;IAyBpC;;;;OAIG;IACH,QAAQ,IAAI,WAAW;IAUvB;;;;OAIG;IACH,SAAS,IAAI,OAAO;IAIpB;;;;OAIG;IACH,KAAK,IAAI,eAAe;CAGzB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CacheDidUpdateCallbackParam } from "@serwist/core";
|
|
2
|
+
import type { BroadcastCacheUpdateOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A class that uses the `postMessage()` API to inform any open windows/tabs when
|
|
5
|
+
* a cached response has been updated.
|
|
6
|
+
*
|
|
7
|
+
* For efficiency's sake, the underlying response bodies are not compared;
|
|
8
|
+
* only specific response headers are checked.
|
|
9
|
+
*/
|
|
10
|
+
export declare class BroadcastCacheUpdate {
|
|
11
|
+
private readonly _headersToCheck;
|
|
12
|
+
private readonly _generatePayload;
|
|
13
|
+
private readonly _notifyAllClients;
|
|
14
|
+
/**
|
|
15
|
+
* Construct a BroadcastCacheUpdate instance with a specific `channelName` to
|
|
16
|
+
* broadcast messages on
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
*/
|
|
20
|
+
constructor({ generatePayload, headersToCheck, notifyAllClients }?: BroadcastCacheUpdateOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Compares two responses and sends a message (via `postMessage()`) to all window clients if the
|
|
23
|
+
* responses differ. Neither of the Responses can be opaque.
|
|
24
|
+
*
|
|
25
|
+
* The message that's posted has the following format (where `payload` can
|
|
26
|
+
* be customized via the `generatePayload` option the instance is created
|
|
27
|
+
* with):
|
|
28
|
+
*
|
|
29
|
+
* ```
|
|
30
|
+
* {
|
|
31
|
+
* type: 'CACHE_UPDATED',
|
|
32
|
+
* meta: 'workbox-broadcast-update',
|
|
33
|
+
* payload: {
|
|
34
|
+
* cacheName: 'the-cache-name',
|
|
35
|
+
* updatedURL: 'https://example.com/'
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param options
|
|
41
|
+
* @returns Resolves once the update is sent.
|
|
42
|
+
*/
|
|
43
|
+
notifyIfUpdated(options: CacheDidUpdateCallbackParam): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=BroadcastCacheUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BroadcastCacheUpdate.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AAKjE,OAAO,KAAK,EAAE,2BAA2B,EAAiE,MAAM,YAAY,CAAC;AAuB7H;;;;;;GAMG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA4B;IAC7D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAU;IAE5C;;;;;OAKG;gBACS,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAE,2BAAgC;IAMnG;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,eAAe,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;CA4E3E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CacheDidUpdateCallbackParam, SerwistPlugin } from "@serwist/core";
|
|
2
|
+
import type { BroadcastCacheUpdateOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A class implementing the `cacheDidUpdate` lifecycle callback. It will automatically
|
|
5
|
+
* broadcast a message whenever a cached response is updated.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BroadcastUpdatePlugin implements SerwistPlugin {
|
|
8
|
+
private readonly _broadcastUpdate;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a `@serwist/broadcast-update.BroadcastCacheUpdate` instance with
|
|
11
|
+
* the passed options and calls its `notifyIfUpdated` method whenever the
|
|
12
|
+
* plugin's `cacheDidUpdate` callback is invoked.
|
|
13
|
+
*
|
|
14
|
+
* @param options
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: BroadcastCacheUpdateOptions);
|
|
17
|
+
/**
|
|
18
|
+
* A "lifecycle" callback that will be triggered automatically by
|
|
19
|
+
* `@serwist/build.RuntimeCaching` handlers when an entry is
|
|
20
|
+
* added to a cache.
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
* @param options The input object to this function.
|
|
24
|
+
*/
|
|
25
|
+
cacheDidUpdate(options: CacheDidUpdateCallbackParam): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=BroadcastUpdatePlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BroadcastUpdatePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAGhF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAE9D;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,aAAa;IACzD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAuB;IAExD;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,2BAA2B;IAIjD;;;;;;;OAOG;IACH,cAAc,CAAC,OAAO,EAAE,2BAA2B;CAGpD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const CACHE_UPDATED_MESSAGE_TYPE = "CACHE_UPDATED";
|
|
2
|
+
export declare const CACHE_UPDATED_MESSAGE_META = "serwist-broadcast-update";
|
|
3
|
+
export declare const defaultNotifyAllClients = true;
|
|
4
|
+
export declare const defaultHeadersToCheck: string[];
|
|
5
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/constants.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,0BAA0B,kBAAkB,CAAC;AAC1D,eAAO,MAAM,0BAA0B,6BAA6B,CAAC;AACrE,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,qBAAqB,UAA8C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given two responses, compares several header values to see if they are
|
|
3
|
+
* the same or not.
|
|
4
|
+
*
|
|
5
|
+
* @param firstResponse The first response.
|
|
6
|
+
* @param secondResponse The second response.
|
|
7
|
+
* @param headersToCheck A list of headers to check.
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const responsesAreSame: (firstResponse: Response, secondResponse: Response, headersToCheck: string[]) => boolean;
|
|
11
|
+
//# sourceMappingURL=responsesAreSame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsesAreSame.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/responsesAreSame.ts"],"names":[],"mappings":"AAUA;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,kBAAmB,QAAQ,kBAAkB,QAAQ,kBAAkB,MAAM,EAAE,KAAG,OA4B9G,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CacheDidUpdateCallbackParam } from "@serwist/core";
|
|
2
|
+
import type { CACHE_UPDATED_MESSAGE_META, CACHE_UPDATED_MESSAGE_TYPE } from "./constants.js";
|
|
3
|
+
export interface BroadcastCacheUpdateOptions {
|
|
4
|
+
/**
|
|
5
|
+
* A list of headers that will be used to determine whether the responses
|
|
6
|
+
* differ.
|
|
7
|
+
*
|
|
8
|
+
* @default ['content-length', 'etag', 'last-modified']
|
|
9
|
+
*/
|
|
10
|
+
headersToCheck?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* A function whose return value
|
|
13
|
+
* will be used as the `payload` field in any cache update messages sent
|
|
14
|
+
* to the window clients.
|
|
15
|
+
* @param options
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
generatePayload?: (options: CacheDidUpdateCallbackParam) => Record<string, any>;
|
|
19
|
+
/**
|
|
20
|
+
* If `true` (the default) then all open clients will receive a message. If `false`,
|
|
21
|
+
* then only the client that make the original request will be notified of the update.
|
|
22
|
+
*
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
notifyAllClients?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type BroadcastPayload = Record<string, any>;
|
|
28
|
+
export type BroadcastPayloadGenerator = (options: CacheDidUpdateCallbackParam) => BroadcastPayload;
|
|
29
|
+
export interface BroadcastMessage {
|
|
30
|
+
type: typeof CACHE_UPDATED_MESSAGE_TYPE;
|
|
31
|
+
meta: typeof CACHE_UPDATED_MESSAGE_META;
|
|
32
|
+
payload: BroadcastPayload;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,KAAK,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE7F,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChF;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEnD,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,2BAA2B,KAAK,gBAAgB,CAAC;AAEnG,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,0BAA0B,CAAC;IACxC,IAAI,EAAE,OAAO,0BAA0B,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC;CAC3B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface CacheableResponseOptions {
|
|
2
|
+
/**
|
|
3
|
+
* One or more status codes that a `Response` can have to be considered cacheable.
|
|
4
|
+
*/
|
|
5
|
+
statuses?: number[];
|
|
6
|
+
/**
|
|
7
|
+
* A mapping of header names and expected values that a `Response` can have and be
|
|
8
|
+
* considered cacheable. If multiple headers are provided, only one needs to be present.
|
|
9
|
+
*/
|
|
10
|
+
headers?: HeadersInit;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Allows you to set up rules determining what status codes and/or headers need
|
|
14
|
+
* to be present in order for a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
15
|
+
* to be considered cacheable.
|
|
16
|
+
*/
|
|
17
|
+
export declare class CacheableResponse {
|
|
18
|
+
private readonly _statuses?;
|
|
19
|
+
private readonly _headers?;
|
|
20
|
+
/**
|
|
21
|
+
* To construct a new CacheableResponse instance you must provide at least
|
|
22
|
+
* one of the `config` properties.
|
|
23
|
+
*
|
|
24
|
+
* If both `statuses` and `headers` are specified, then both conditions must
|
|
25
|
+
* be met for the `Response` to be considered cacheable.
|
|
26
|
+
*
|
|
27
|
+
* @param config
|
|
28
|
+
*/
|
|
29
|
+
constructor(config?: CacheableResponseOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Checks a response to see whether it's cacheable or not.
|
|
32
|
+
*
|
|
33
|
+
* @param response The response whose cacheability is being
|
|
34
|
+
* checked.
|
|
35
|
+
* @returns `true` if the `Response` is cacheable, and `false`
|
|
36
|
+
* otherwise.
|
|
37
|
+
*/
|
|
38
|
+
isResponseCacheable(response: Response): boolean;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=CacheableResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheableResponse.d.ts","sourceRoot":"","sources":["../../../src/plugins/cacheableResponse/CacheableResponse.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;GAIG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAuC;IAClE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAU;IAEpC;;;;;;;;OAQG;gBACS,MAAM,GAAE,wBAA6B;IAmCjD;;;;;;;OAOG;IACH,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;CAyDjD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SerwistPlugin } from "@serwist/core";
|
|
2
|
+
import type { CacheableResponseOptions } from "./CacheableResponse.js";
|
|
3
|
+
/**
|
|
4
|
+
* A class implementing the `cacheWillUpdate` lifecycle callback. This makes it
|
|
5
|
+
* easier to add in cacheability checks to requests made via Serwist's built-in
|
|
6
|
+
* strategies.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CacheableResponsePlugin implements SerwistPlugin {
|
|
9
|
+
private readonly _cacheableResponse;
|
|
10
|
+
/**
|
|
11
|
+
* To construct a new CacheableResponsePlugin instance you must provide at
|
|
12
|
+
* least one of the `config` properties.
|
|
13
|
+
*
|
|
14
|
+
* If both `statuses` and `headers` are specified, then both conditions must
|
|
15
|
+
* be met for the `Response` to be considered cacheable.
|
|
16
|
+
*
|
|
17
|
+
* @param config
|
|
18
|
+
*/
|
|
19
|
+
constructor(config: CacheableResponseOptions);
|
|
20
|
+
/**
|
|
21
|
+
* @param options
|
|
22
|
+
* @returns
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
cacheWillUpdate: SerwistPlugin["cacheWillUpdate"];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=CacheableResponsePlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheableResponsePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/cacheableResponse/CacheableResponsePlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGvE;;;;GAIG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IAEvD;;;;;;;;OAQG;gBACS,MAAM,EAAE,wBAAwB;IAI5C;;;;OAIG;IACH,eAAe,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAK/C;CACH"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
interface CacheExpirationConfig {
|
|
2
|
+
/**
|
|
3
|
+
* The maximum number of entries to cache. Entries used the least will
|
|
4
|
+
* be removed as the maximum is reached.
|
|
5
|
+
*/
|
|
6
|
+
maxEntries?: number;
|
|
7
|
+
/**
|
|
8
|
+
* The maximum age of an entry before it's treated as stale and removed.
|
|
9
|
+
*/
|
|
10
|
+
maxAgeSeconds?: number;
|
|
11
|
+
/**
|
|
12
|
+
* The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters)
|
|
13
|
+
* that will be used when calling `delete()` on the cache.
|
|
14
|
+
*/
|
|
15
|
+
matchOptions?: CacheQueryOptions;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Allows you to expires cached responses based on age or maximum number of entries.
|
|
19
|
+
* @see https://serwist.pages.dev/docs/expiration/cache-expiration
|
|
20
|
+
*/
|
|
21
|
+
export declare class CacheExpiration {
|
|
22
|
+
private _isRunning;
|
|
23
|
+
private _rerunRequested;
|
|
24
|
+
private readonly _maxEntries?;
|
|
25
|
+
private readonly _maxAgeSeconds?;
|
|
26
|
+
private readonly _matchOptions?;
|
|
27
|
+
private readonly _cacheName;
|
|
28
|
+
private readonly _timestampModel;
|
|
29
|
+
/**
|
|
30
|
+
* To construct a new CacheExpiration instance you must provide at least
|
|
31
|
+
* one of the `config` properties.
|
|
32
|
+
*
|
|
33
|
+
* @param cacheName Name of the cache to apply restrictions to.
|
|
34
|
+
* @param config
|
|
35
|
+
*/
|
|
36
|
+
constructor(cacheName: string, config?: CacheExpirationConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Expires entries for the given cache and given criteria.
|
|
39
|
+
*/
|
|
40
|
+
expireEntries(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Updates the timestamp for the given URL, allowing it to be correctly
|
|
43
|
+
* tracked by the class.
|
|
44
|
+
*
|
|
45
|
+
* @param url
|
|
46
|
+
*/
|
|
47
|
+
updateTimestamp(url: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Checks if a URL has expired or not before it's used.
|
|
50
|
+
*
|
|
51
|
+
* This looks the timestamp up in IndexedDB and can be slow.
|
|
52
|
+
*
|
|
53
|
+
* Note: This method does not remove an expired entry, call
|
|
54
|
+
* `expireEntries()` to remove such entries instead.
|
|
55
|
+
*
|
|
56
|
+
* @param url
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
isURLExpired(url: string): Promise<boolean>;
|
|
60
|
+
/**
|
|
61
|
+
* Removes the IndexedDB used to keep track of cache expiration metadata.
|
|
62
|
+
*/
|
|
63
|
+
delete(): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=CacheExpiration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheExpiration.d.ts","sourceRoot":"","sources":["../../../src/plugins/expiration/CacheExpiration.ts"],"names":[],"mappings":"AAYA,UAAU,qBAAqB;IAC7B;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAS;IACzC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAoB;IACnD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAuB;IAEvD;;;;;;OAMG;gBACS,SAAS,EAAE,MAAM,EAAE,MAAM,GAAE,qBAA0B;IA2CjE;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC;IA0CpC;;;;;OAKG;IACG,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAajD;;;;;;;;;;OAUG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAejD;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAM9B"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, SerwistPlugin } from "@serwist/core";
|
|
2
|
+
export interface ExpirationPluginOptions {
|
|
3
|
+
/**
|
|
4
|
+
* The maximum number of entries to cache. Entries used the least will be removed
|
|
5
|
+
* as the maximum is reached.
|
|
6
|
+
*/
|
|
7
|
+
maxEntries?: number;
|
|
8
|
+
/**
|
|
9
|
+
* The maximum number of seconds before an entry is treated as stale and removed.
|
|
10
|
+
*/
|
|
11
|
+
maxAgeSeconds?: number;
|
|
12
|
+
/**
|
|
13
|
+
* Determines whether `maxAgeSeconds` should be calculated from when an
|
|
14
|
+
* entry was last fetched or when it was last used.
|
|
15
|
+
*
|
|
16
|
+
* @default "last-fetched"
|
|
17
|
+
*/
|
|
18
|
+
maxAgeFrom?: "last-fetched" | "last-used";
|
|
19
|
+
/**
|
|
20
|
+
* The [`CacheQueryOptions`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/delete#Parameters)
|
|
21
|
+
* that will be used when calling `delete()` on the cache.
|
|
22
|
+
*/
|
|
23
|
+
matchOptions?: CacheQueryOptions;
|
|
24
|
+
/**
|
|
25
|
+
* Whether to opt this cache into automatic deletion if the available storage quota has been exceeded.
|
|
26
|
+
*/
|
|
27
|
+
purgeOnQuotaError?: boolean;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* This plugin can be used in a `@serwist/strategies` Strategy to regularly enforce a
|
|
31
|
+
* limit on the age and/or the number of cached requests.
|
|
32
|
+
*
|
|
33
|
+
* It can only be used with Strategy instances that have a custom `cacheName` property set.
|
|
34
|
+
* In other words, it can't be used to expire entries in strategies that use the default runtime
|
|
35
|
+
* cache name.
|
|
36
|
+
*
|
|
37
|
+
* Whenever a cached response is used or updated, this plugin will look
|
|
38
|
+
* at the associated cache and remove any old or extra responses.
|
|
39
|
+
*
|
|
40
|
+
* When using `maxAgeSeconds`, responses may be used *once* after expiring
|
|
41
|
+
* because the expiration clean up will not have occurred until *after* the
|
|
42
|
+
* cached response has been used. If the response has a "Date" header, then a lightweight expiration
|
|
43
|
+
* check is performed, and the response will not be used immediately.
|
|
44
|
+
*
|
|
45
|
+
* When using `maxEntries`, the least recently requested entry will be removed
|
|
46
|
+
* from the cache.
|
|
47
|
+
*
|
|
48
|
+
* @see https://serwist.pages.dev/docs/expiration/expiration-plugin
|
|
49
|
+
*/
|
|
50
|
+
export declare class ExpirationPlugin implements SerwistPlugin {
|
|
51
|
+
private readonly _config;
|
|
52
|
+
private _cacheExpirations;
|
|
53
|
+
/**
|
|
54
|
+
* @param config
|
|
55
|
+
*/
|
|
56
|
+
constructor(config?: ExpirationPluginOptions);
|
|
57
|
+
/**
|
|
58
|
+
* A simple helper method to return a CacheExpiration instance for a given
|
|
59
|
+
* cache name.
|
|
60
|
+
*
|
|
61
|
+
* @param cacheName
|
|
62
|
+
* @returns
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
private _getCacheExpiration;
|
|
66
|
+
/**
|
|
67
|
+
* A "lifecycle" callback that will be triggered automatically by the
|
|
68
|
+
* `@serwist/strategies` handlers when a `Response` is about to be returned
|
|
69
|
+
* from a [Cache](https://developer.mozilla.org/en-US/docs/Web/API/Cache) to
|
|
70
|
+
* the handler. It allows the `Response` to be inspected for freshness and
|
|
71
|
+
* prevents it from being used if the `Response`'s `Date` header value is
|
|
72
|
+
* older than the configured `maxAgeSeconds`.
|
|
73
|
+
*
|
|
74
|
+
* @param options
|
|
75
|
+
* @returns `cachedResponse` if it is fresh and `null` if it is stale or
|
|
76
|
+
* not available.
|
|
77
|
+
* @private
|
|
78
|
+
*/
|
|
79
|
+
cachedResponseWillBeUsed({ event, cacheName, request, cachedResponse }: CachedResponseWillBeUsedCallbackParam): Response | null;
|
|
80
|
+
/**
|
|
81
|
+
* @param cachedResponse
|
|
82
|
+
* @returns
|
|
83
|
+
* @private
|
|
84
|
+
*/
|
|
85
|
+
private _isResponseDateFresh;
|
|
86
|
+
/**
|
|
87
|
+
* Extracts the `Date` header and parse it into an useful value.
|
|
88
|
+
*
|
|
89
|
+
* @param cachedResponse
|
|
90
|
+
* @returns
|
|
91
|
+
* @private
|
|
92
|
+
*/
|
|
93
|
+
private _getDateHeaderTimestamp;
|
|
94
|
+
/**
|
|
95
|
+
* A "lifecycle" callback that will be triggered automatically by the
|
|
96
|
+
* `@serwist/strategies` handlers when an entry is added to a cache.
|
|
97
|
+
*
|
|
98
|
+
* @param options
|
|
99
|
+
* @private
|
|
100
|
+
*/
|
|
101
|
+
cacheDidUpdate({ cacheName, request }: CacheDidUpdateCallbackParam): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Deletes the underlying `Cache` instance associated with this instance and the metadata
|
|
104
|
+
* from IndexedDB used to keep track of expiration details for each `Cache` instance.
|
|
105
|
+
*
|
|
106
|
+
* When using cache expiration, calling this method is preferable to calling
|
|
107
|
+
* `caches.delete()` directly, since this will ensure that the IndexedDB
|
|
108
|
+
* metadata is also cleanly removed and that open IndexedDB instances are deleted.
|
|
109
|
+
*
|
|
110
|
+
* Note that if you're *not* using cache expiration for a given cache, calling
|
|
111
|
+
* `caches.delete()` and passing in the cache's name should be sufficient.
|
|
112
|
+
* There is no Serwist-specific method needed for cleanup in that case.
|
|
113
|
+
*/
|
|
114
|
+
deleteCacheAndMetadata(): Promise<void>;
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=ExpirationPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExpirationPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/expiration/ExpirationPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,qCAAqC,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAMvH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,cAAc,GAAG,WAAW,CAAC;IAC1C;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;IACjC;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,gBAAiB,YAAW,aAAa;IACpD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA0B;IAClD,OAAO,CAAC,iBAAiB,CAA+B;IAExD;;OAEG;gBACS,MAAM,GAAE,uBAA4B;IAkDhD;;;;;;;OAOG;IACH,OAAO,CAAC,mBAAmB;IAa3B;;;;;;;;;;;;OAYG;IACH,wBAAwB,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE,qCAAqC;IAqC7G;;;;OAIG;IACH,OAAO,CAAC,oBAAoB;IAwB5B;;;;;;OAMG;IACH,OAAO,CAAC,uBAAuB;IAkB/B;;;;;;OAMG;IACG,cAAc,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,2BAA2B;IAqBxE;;;;;;;;;;;OAWG;IACG,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC;CAW9C"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns the timestamp model.
|
|
3
|
+
*
|
|
4
|
+
* @private
|
|
5
|
+
*/
|
|
6
|
+
export declare class CacheTimestampsModel {
|
|
7
|
+
private readonly _cacheName;
|
|
8
|
+
private _db;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param cacheName
|
|
12
|
+
*
|
|
13
|
+
* @private
|
|
14
|
+
*/
|
|
15
|
+
constructor(cacheName: string);
|
|
16
|
+
/**
|
|
17
|
+
* Takes a URL and returns an ID that will be unique in the object store.
|
|
18
|
+
*
|
|
19
|
+
* @param url
|
|
20
|
+
* @returns
|
|
21
|
+
* @private
|
|
22
|
+
*/
|
|
23
|
+
private _getId;
|
|
24
|
+
/**
|
|
25
|
+
* Performs an upgrade of indexedDB.
|
|
26
|
+
*
|
|
27
|
+
* @param db
|
|
28
|
+
*
|
|
29
|
+
* @private
|
|
30
|
+
*/
|
|
31
|
+
private _upgradeDb;
|
|
32
|
+
/**
|
|
33
|
+
* Performs an upgrade of indexedDB and deletes deprecated DBs.
|
|
34
|
+
*
|
|
35
|
+
* @param db
|
|
36
|
+
*
|
|
37
|
+
* @private
|
|
38
|
+
*/
|
|
39
|
+
private _upgradeDbAndDeleteOldDbs;
|
|
40
|
+
/**
|
|
41
|
+
* @param url
|
|
42
|
+
* @param timestamp
|
|
43
|
+
*
|
|
44
|
+
* @private
|
|
45
|
+
*/
|
|
46
|
+
setTimestamp(url: string, timestamp: number): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Returns the timestamp stored for a given URL.
|
|
49
|
+
*
|
|
50
|
+
* @param url
|
|
51
|
+
* @returns
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
getTimestamp(url: string): Promise<number | undefined>;
|
|
55
|
+
/**
|
|
56
|
+
* Iterates through all the entries in the object store (from newest to
|
|
57
|
+
* oldest) and removes entries once either `maxCount` is reached or the
|
|
58
|
+
* entry's timestamp is less than `minTimestamp`.
|
|
59
|
+
*
|
|
60
|
+
* @param minTimestamp
|
|
61
|
+
* @param maxCount
|
|
62
|
+
* @returns
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
expireEntries(minTimestamp: number, maxCount?: number): Promise<string[]>;
|
|
66
|
+
/**
|
|
67
|
+
* Returns an open connection to the database.
|
|
68
|
+
*
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
private getDb;
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=CacheTimestampsModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheTimestampsModel.d.ts","sourceRoot":"","sources":["../../../../src/plugins/expiration/models/CacheTimestampsModel.ts"],"names":[],"mappings":"AAoCA;;;;GAIG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,GAAG,CAA4C;IAEvD;;;;;OAKG;gBACS,SAAS,EAAE,MAAM;IAI7B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM;IAId;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAYlB;;;;;;OAMG;IACH,OAAO,CAAC,yBAAyB;IAOjC;;;;;OAKG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBjE;;;;;;OAMG;IACG,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAM5D;;;;;;;;;OASG;IACG,aAAa,CAAC,YAAY,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAyB/E;;;;OAIG;YACW,KAAK;CAQpB"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const QUEUE_NAME = "serwist-google-analytics";
|
|
2
|
+
export declare const MAX_RETENTION_TIME: number;
|
|
3
|
+
export declare const GOOGLE_ANALYTICS_HOST = "www.google-analytics.com";
|
|
4
|
+
export declare const GTM_HOST = "www.googletagmanager.com";
|
|
5
|
+
export declare const ANALYTICS_JS_PATH = "/analytics.js";
|
|
6
|
+
export declare const GTAG_JS_PATH = "/gtag/js";
|
|
7
|
+
export declare const GTM_JS_PATH = "/gtm.js";
|
|
8
|
+
export declare const COLLECT_DEFAULT_PATH = "/collect";
|
|
9
|
+
export declare const COLLECT_PATHS_REGEX: RegExp;
|
|
10
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/plugins/googleAnalytics/constants.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,UAAU,6BAA6B,CAAC;AACrD,eAAO,MAAM,kBAAkB,QAAU,CAAC;AAC1C,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAChE,eAAO,MAAM,QAAQ,6BAA6B,CAAC;AACnD,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AACjD,eAAO,MAAM,YAAY,aAAa,CAAC;AACvC,eAAO,MAAM,WAAW,YAAY,CAAC;AACrC,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAM/C,eAAO,MAAM,mBAAmB,QAAuB,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Router } from "../../routing/Router.js";
|
|
2
|
+
export interface GoogleAnalyticsInitializeOptions {
|
|
3
|
+
/**
|
|
4
|
+
* An optional `Router` instance. If not provided, the singleton `Router`
|
|
5
|
+
* will be used.
|
|
6
|
+
*/
|
|
7
|
+
router?: Router;
|
|
8
|
+
/**
|
|
9
|
+
* The cache name to store and retrieve analytics.js. Defaults to the cache names provided by `@serwist/core`.
|
|
10
|
+
*/
|
|
11
|
+
cacheName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* [Measurement Protocol parameters](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters),
|
|
14
|
+
* expressed as key/value pairs, to be added to replayed Google Analytics
|
|
15
|
+
* requests. This can be used to, e.g., set a custom dimension indicating
|
|
16
|
+
* that the request was replayed.
|
|
17
|
+
*/
|
|
18
|
+
parameterOverrides?: {
|
|
19
|
+
[paramName: string]: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* A function that allows you to modify the hit parameters prior to replaying
|
|
23
|
+
* the hit. The function is invoked with the original hit's URLSearchParams
|
|
24
|
+
* object as its only argument.
|
|
25
|
+
*/
|
|
26
|
+
hitFilter?: (params: URLSearchParams) => void;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Initialize Serwist's offline Google Analytics v3 support.
|
|
30
|
+
*
|
|
31
|
+
* @param options
|
|
32
|
+
*/
|
|
33
|
+
export declare const initialize: ({ cacheName, router, ...options }?: GoogleAnalyticsInitializeOptions) => void;
|
|
34
|
+
//# sourceMappingURL=initialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../../src/plugins/googleAnalytics/initialize.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAC;AAatD,MAAM,WAAW,gCAAgC;IAC/C;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;;OAKG;IACH,kBAAkB,CAAC,EAAE;QAAE,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;IACrD;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,eAAe,KAAK,IAAI,CAAC;CAC/C;AAyID;;;;GAIG;AACH,eAAO,MAAM,UAAU,uCAA8D,gCAAgC,KAAQ,IAkB5H,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { HandlerDidErrorCallbackParam, SerwistPlugin } from "@serwist/core";
|
|
2
|
+
import type { PrecacheController } from "../../precaching/PrecacheController.js";
|
|
3
|
+
export interface PrecacheFallbackEntry {
|
|
4
|
+
/**
|
|
5
|
+
* A function that checks whether the fallback entry can be used
|
|
6
|
+
* for a request.
|
|
7
|
+
*/
|
|
8
|
+
matcher: (param: HandlerDidErrorCallbackParam) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* A precached URL to be used as a fallback.
|
|
11
|
+
*/
|
|
12
|
+
url: string;
|
|
13
|
+
}
|
|
14
|
+
export interface PrecacheFallbackPluginOptions {
|
|
15
|
+
/**
|
|
16
|
+
* Precached URLs to be used as the fallback
|
|
17
|
+
* if the associated strategy can't generate a response.
|
|
18
|
+
*/
|
|
19
|
+
fallbackUrls: (string | PrecacheFallbackEntry)[];
|
|
20
|
+
/**
|
|
21
|
+
* An optional `PrecacheController` instance. If not provided, the default
|
|
22
|
+
* `PrecacheController` will be used.
|
|
23
|
+
*/
|
|
24
|
+
precacheController?: PrecacheController;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* `PrecacheFallbackPlugin` allows you to specify offline fallbacks
|
|
28
|
+
* to be used when a given strategy is unable to generate a response.
|
|
29
|
+
*
|
|
30
|
+
* It does this by intercepting the `handlerDidError` plugin callback
|
|
31
|
+
* and returning a precached response, taking the expected revision parameter
|
|
32
|
+
* into account automatically.
|
|
33
|
+
*
|
|
34
|
+
* Unless you explicitly pass in a `PrecacheController` instance to the
|
|
35
|
+
* constructor, the default instance will be used. Generally speaking, most
|
|
36
|
+
* developers will end up using the default.
|
|
37
|
+
*/
|
|
38
|
+
export declare class PrecacheFallbackPlugin implements SerwistPlugin {
|
|
39
|
+
private readonly _fallbackUrls;
|
|
40
|
+
private readonly _precacheController;
|
|
41
|
+
/**
|
|
42
|
+
* Constructs a new `PrecacheFallbackPlugin` with the associated `fallbackUrls`.
|
|
43
|
+
*
|
|
44
|
+
* @param config
|
|
45
|
+
*/
|
|
46
|
+
constructor({ fallbackUrls, precacheController }: PrecacheFallbackPluginOptions);
|
|
47
|
+
/**
|
|
48
|
+
* @returns The precache response for one of the fallback URLs, or `undefined` if
|
|
49
|
+
* nothing satisfies the conditions.
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
handlerDidError(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=PrecacheFallbackPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PrecacheFallbackPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/precaching/PrecacheFallbackPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEjF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAGjF,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,4BAA4B,KAAK,OAAO,CAAC;IAC1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,YAAY,EAAE,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,CAAC;IACjD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqC;IACnE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;IAEzD;;;;OAIG;gBACS,EAAE,YAAY,EAAE,kBAAkB,EAAE,EAAE,6BAA6B;IAK/E;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,4BAA4B;CAgB1D"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { SerwistPlugin } from "@serwist/core";
|
|
2
|
+
/**
|
|
3
|
+
* The range request plugin makes it easy for a request with a 'Range' header to
|
|
4
|
+
* be fulfilled by a cached response.
|
|
5
|
+
*
|
|
6
|
+
* It does this by intercepting the `cachedResponseWillBeUsed` plugin callback
|
|
7
|
+
* and returning the appropriate subset of the cached response body.
|
|
8
|
+
*/
|
|
9
|
+
export declare class RangeRequestsPlugin implements SerwistPlugin {
|
|
10
|
+
/**
|
|
11
|
+
* @param options
|
|
12
|
+
* @returns If request contains a 'Range' header, then a
|
|
13
|
+
* new response with status 206 whose body is a subset of `cachedResponse` is
|
|
14
|
+
* returned. Otherwise, `cachedResponse` is returned as-is.
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
cachedResponseWillBeUsed: SerwistPlugin["cachedResponseWillBeUsed"];
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=RangeRequestsPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RangeRequestsPlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/rangeRequests/RangeRequestsPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD;;;;;;GAMG;AACH,qBAAa,mBAAoB,YAAW,aAAa;IACvD;;;;;;OAMG;IACH,wBAAwB,EAAE,aAAa,CAAC,0BAA0B,CAAC,CAUjE;CACH"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a `Request` and `Response` objects as input, this will return a
|
|
3
|
+
* promise for a new `Response`.
|
|
4
|
+
*
|
|
5
|
+
* If the original `Response` already contains partial content (i.e. it has
|
|
6
|
+
* a status of 206), then this assumes it already fulfills the `Range:`
|
|
7
|
+
* requirements, and will return it as-is.
|
|
8
|
+
*
|
|
9
|
+
* @param request A request, which should contain a Range:
|
|
10
|
+
* header.
|
|
11
|
+
* @param originalResponse A response.
|
|
12
|
+
* @returns Either a `206 Partial Content` response, with
|
|
13
|
+
* the response body set to the slice of content specified by the request's
|
|
14
|
+
* `Range:` header, or a `416 Range Not Satisfiable` response if the
|
|
15
|
+
* conditions of the `Range:` header can't be met.
|
|
16
|
+
*/
|
|
17
|
+
export declare const createPartialResponse: (request: Request, originalResponse: Response) => Promise<Response>;
|
|
18
|
+
//# sourceMappingURL=createPartialResponse.d.ts.map
|