@serwist/sw 9.0.0-preview.16 → 9.0.0-preview.18
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/{installSerwist.d.ts → abstractions/Serwist.d.ts} +27 -11
- package/dist/abstractions/Serwist.d.ts.map +1 -0
- package/dist/abstractions/disableDevLogs.d.ts.map +1 -0
- package/dist/{fallbacks.d.ts → abstractions/fallbacks.d.ts} +2 -2
- package/dist/abstractions/fallbacks.d.ts.map +1 -0
- package/dist/{handlePrecaching.d.ts → abstractions/handlePrecaching.d.ts} +5 -8
- 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/{registerRuntimeCaching.d.ts → abstractions/registerRuntimeCaching.d.ts} +1 -1
- package/dist/abstractions/registerRuntimeCaching.d.ts.map +1 -0
- package/dist/{types.d.ts → abstractions/types.d.ts} +1 -1
- 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/getOrCreatePrecacheController.js +429 -0
- package/dist/chunks/precacheAndRoute.js +112 -0
- package/dist/chunks/registerRoute.js +408 -0
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +79 -52
- package/dist/index.plugins.d.ts +40 -11
- package/dist/index.plugins.d.ts.map +1 -1
- package/dist/index.plugins.js +671 -5
- package/dist/index.precaching.d.ts +24 -0
- package/dist/index.precaching.d.ts.map +1 -0
- package/dist/index.precaching.js +24 -0
- package/dist/index.routing.d.ts +13 -0
- package/dist/index.routing.d.ts.map +1 -0
- package/dist/index.routing.js +21 -0
- package/dist/index.strategies.d.ts +19 -2
- package/dist/index.strategies.d.ts.map +1 -1
- package/dist/index.strategies.js +146 -1
- 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 +26 -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/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/getOrCreatePrecacheController.d.ts +7 -0
- package/dist/precaching/utils/getOrCreatePrecacheController.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 +124 -0
- package/dist/routing/Router.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/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/getOrCreateDefaultRouter.d.ts +10 -0
- package/dist/routing/utils/getOrCreateDefaultRouter.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/routing/utils/parseRoute.d.ts +5 -0
- package/dist/routing/utils/parseRoute.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 +20 -14
- package/src/abstractions/Serwist.ts +179 -0
- package/src/{fallbacks.ts → abstractions/fallbacks.ts} +5 -5
- package/src/{handlePrecaching.ts → abstractions/handlePrecaching.ts} +23 -24
- package/src/abstractions/installSerwist.ts +28 -0
- package/src/{registerRuntimeCaching.ts → abstractions/registerRuntimeCaching.ts} +2 -2
- package/src/{types.ts → abstractions/types.ts} +1 -1
- package/src/index.plugins.ts +65 -16
- package/src/index.precaching.ts +38 -0
- package/src/index.routing.ts +14 -0
- package/src/index.strategies.ts +22 -2
- package/src/index.ts +19 -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 +200 -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 +26 -0
- package/src/precaching/precache.ts +31 -0
- package/src/precaching/precacheAndRoute.ts +27 -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/getOrCreatePrecacheController.ts +22 -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 +432 -0
- package/src/routing/registerRoute.ts +33 -0
- package/src/routing/setCatchHandler.ts +22 -0
- package/src/routing/setDefaultHandler.ts +25 -0
- package/src/routing/unregisterRoute.ts +12 -0
- package/src/routing/utils/constants.ts +24 -0
- package/src/routing/utils/getOrCreateDefaultRouter.ts +29 -0
- package/src/routing/utils/normalizeHandler.ts +40 -0
- package/src/routing/utils/parseRoute.ts +67 -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.map +0 -1
- package/dist/registerRuntimeCaching.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/src/installSerwist.ts +0 -142
- /package/dist/{disableDevLogs.d.ts → abstractions/disableDevLogs.d.ts} +0 -0
- /package/src/{disableDevLogs.ts → abstractions/disableDevLogs.ts} +0 -0
|
@@ -1,8 +1,24 @@
|
|
|
1
|
-
import { type GoogleAnalyticsInitializeOptions } from "
|
|
1
|
+
import { type GoogleAnalyticsInitializeOptions } from "../plugins/googleAnalytics/initialize.js";
|
|
2
|
+
import { PrecacheController } from "../precaching/PrecacheController.js";
|
|
3
|
+
import { Router } from "../routing/Router.js";
|
|
2
4
|
import type { FallbacksOptions } from "./fallbacks.js";
|
|
3
5
|
import { type HandlePrecachingOptions } from "./handlePrecaching.js";
|
|
4
6
|
import type { RuntimeCaching } from "./types.js";
|
|
5
|
-
export
|
|
7
|
+
export interface SerwistOptions {
|
|
8
|
+
/**
|
|
9
|
+
* The precache controller that will be used to perform efficient
|
|
10
|
+
* precaching of assets.
|
|
11
|
+
* @see https://serwist.pages.dev/docs/sw/precaching
|
|
12
|
+
*/
|
|
13
|
+
precacheController?: PrecacheController;
|
|
14
|
+
/**
|
|
15
|
+
* The router that will be used to process a `FetchEvent`, responding
|
|
16
|
+
* with a `Response` if a matching route exists.
|
|
17
|
+
* @see https://serwist.pages.dev/docs/sw/routing
|
|
18
|
+
*/
|
|
19
|
+
router?: Router;
|
|
20
|
+
}
|
|
21
|
+
export interface SerwistInstallOptions extends HandlePrecachingOptions {
|
|
6
22
|
/**
|
|
7
23
|
* Forces the waiting service worker to become the active one.
|
|
8
24
|
*
|
|
@@ -36,7 +52,7 @@ export type InstallSerwistOptions = HandlePrecachingOptions & {
|
|
|
36
52
|
/**
|
|
37
53
|
* A list of caching strategies.
|
|
38
54
|
*
|
|
39
|
-
* @see https://serwist.pages.dev/docs/sw/
|
|
55
|
+
* @see https://serwist.pages.dev/docs/sw/runtime-caching
|
|
40
56
|
*/
|
|
41
57
|
runtimeCaching?: RuntimeCaching[];
|
|
42
58
|
/**
|
|
@@ -48,7 +64,6 @@ export type InstallSerwistOptions = HandlePrecachingOptions & {
|
|
|
48
64
|
* Disables Serwist's logging in development mode.
|
|
49
65
|
*
|
|
50
66
|
* @default false
|
|
51
|
-
* @see https://serwist.pages.dev/docs/sw/disable-dev-logs
|
|
52
67
|
*/
|
|
53
68
|
disableDevLogs?: boolean;
|
|
54
69
|
/**
|
|
@@ -59,10 +74,11 @@ export type InstallSerwistOptions = HandlePrecachingOptions & {
|
|
|
59
74
|
* @see https://serwist.pages.dev/docs/sw/fallbacks
|
|
60
75
|
*/
|
|
61
76
|
fallbacks?: Omit<FallbacksOptions, "runtimeCaching">;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
77
|
+
}
|
|
78
|
+
export declare class Serwist {
|
|
79
|
+
private _precacheController;
|
|
80
|
+
private _router;
|
|
81
|
+
constructor({ precacheController, router }?: SerwistOptions);
|
|
82
|
+
install({ precacheEntries, precacheOptions, cleanupOutdatedCaches, navigateFallback, navigateFallbackAllowlist, navigateFallbackDenylist, skipWaiting, importScripts, navigationPreload, cacheId, clientsClaim, runtimeCaching, offlineAnalyticsConfig, disableDevLogs, fallbacks, }: SerwistInstallOptions): void;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=Serwist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Serwist.d.ts","sourceRoot":"","sources":["../../src/abstractions/Serwist.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,gCAAgC,EAAc,MAAM,0CAA0C,CAAC;AAC7G,OAAO,EAAE,kBAAkB,EAAE,MAAM,qCAAqC,CAAC;AAMzE,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAK9C,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIjD,MAAM,WAAW,cAAc;IAC7B;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,qBAAsB,SAAQ,uBAAuB;IACpE;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;OAKG;IACH,aAAa,CAAC,EAAE,MAAM,EAAE,CAAC;IACzB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC7B;;;;;OAKG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;OAIG;IACH,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;IAClC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,gCAAgC,GAAG,OAAO,CAAC;IACpE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,gBAAgB,EAAE,gBAAgB,CAAC,CAAC;CACtD;AAED,qBAAa,OAAO;IAClB,OAAO,CAAC,mBAAmB,CAAqB;IAChD,OAAO,CAAC,OAAO,CAAS;gBACZ,EAAE,kBAAkB,EAAE,MAAM,EAAE,GAAE,cAAmB;IAI/D,OAAO,CAAC,EACN,eAAe,EACf,eAAe,EACf,qBAAqB,EACrB,gBAAgB,EAChB,yBAAyB,EACzB,wBAAwB,EACxB,WAAmB,EACnB,aAAa,EACb,iBAAyB,EACzB,OAAO,EACP,YAAoB,EACpB,cAAc,EACd,sBAAsB,EACtB,cAAsB,EACtB,SAAS,GACV,EAAE,qBAAqB;CA8DzB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"disableDevLogs.d.ts","sourceRoot":"","sources":["../../src/abstractions/disableDevLogs.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,cAAc,QAAO,IAEjC,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { HandlerDidErrorCallbackParam } from "@serwist/core";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { PrecacheFallbackEntry } from "../plugins/precaching/PrecacheFallbackPlugin.js";
|
|
3
|
+
import type { PrecacheRouteOptions } from "../precaching/types.js";
|
|
4
4
|
import type { RuntimeCaching } from "./types.js";
|
|
5
5
|
export type FallbackMatcher = (_: HandlerDidErrorCallbackParam) => boolean;
|
|
6
6
|
export interface FallbackEntry extends PrecacheFallbackEntry {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fallbacks.d.ts","sourceRoot":"","sources":["../../src/abstractions/fallbacks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAElE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAE7F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,4BAA4B,KAAK,OAAO,CAAC;AAE3E,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC;;OAEG;IACH,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,iDAAkD,gBAAgB,KAAG,cAAc,EAoBxG,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PrecacheEntry, PrecacheRouteOptions } from "
|
|
2
|
-
export
|
|
1
|
+
import type { PrecacheEntry, PrecacheRouteOptions } from "../precaching/types.js";
|
|
2
|
+
export interface HandlePrecachingOptions {
|
|
3
3
|
/**
|
|
4
4
|
* A list of fallback entries.
|
|
5
5
|
*/
|
|
@@ -14,12 +14,11 @@ export type HandlePrecachingOptions = {
|
|
|
14
14
|
* @default false
|
|
15
15
|
*/
|
|
16
16
|
cleanupOutdatedCaches?: boolean;
|
|
17
|
-
} & ({
|
|
18
17
|
/**
|
|
19
18
|
* An URL that should point to a HTML file with which navigation requests for URLs that aren't
|
|
20
19
|
* precached will be fulfilled.
|
|
21
20
|
*/
|
|
22
|
-
navigateFallback
|
|
21
|
+
navigateFallback?: string;
|
|
23
22
|
/**
|
|
24
23
|
* URLs that should be allowed to use the `navigateFallback` handler.
|
|
25
24
|
*/
|
|
@@ -29,13 +28,11 @@ export type HandlePrecachingOptions = {
|
|
|
29
28
|
* over `navigateFallbackAllowlist`.
|
|
30
29
|
*/
|
|
31
30
|
navigateFallbackDenylist?: RegExp[];
|
|
32
|
-
}
|
|
33
|
-
navigateFallback?: never;
|
|
34
|
-
});
|
|
31
|
+
}
|
|
35
32
|
/**
|
|
36
33
|
* Handles a list of precache entries and cleans up outdated caches.
|
|
37
34
|
*
|
|
38
|
-
* @see https://serwist.pages.dev/docs/sw/
|
|
35
|
+
* @see https://serwist.pages.dev/docs/sw/handle-precaching
|
|
39
36
|
* @param options
|
|
40
37
|
*/
|
|
41
38
|
export declare const handlePrecaching: ({ precacheEntries, precacheOptions, cleanupOutdatedCaches, ...options }: HandlePrecachingOptions) => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlePrecaching.d.ts","sourceRoot":"","sources":["../../src/abstractions/handlePrecaching.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAIlF,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IAC7C;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC;;;OAGG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;OAEG;IACH,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,4EAAqF,uBAAuB,KAAG,IAoB3I,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type SerwistInstallOptions } from "./Serwist.js";
|
|
2
|
+
/**
|
|
3
|
+
* Options for `installSerwist`.
|
|
4
|
+
*
|
|
5
|
+
* @deprecated
|
|
6
|
+
*/
|
|
7
|
+
export type InstallSerwistOptions = SerwistInstallOptions;
|
|
8
|
+
/**
|
|
9
|
+
* Abstracts away the core APIs of Serwist.
|
|
10
|
+
*
|
|
11
|
+
* @param options - `installSerwist` options.
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export declare const installSerwist: (options: InstallSerwistOptions) => void;
|
|
15
|
+
//# sourceMappingURL=installSerwist.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"installSerwist.d.ts","sourceRoot":"","sources":["../../src/abstractions/installSerwist.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAE1D;;;;;GAKG;AACH,eAAO,MAAM,cAAc,YAAa,qBAAqB,KAAG,IAS/D,CAAC"}
|
|
@@ -3,7 +3,7 @@ import type { RuntimeCaching } from "./types.js";
|
|
|
3
3
|
* Registers caching strategies to a singleton Router instance. It is a simple
|
|
4
4
|
* syntatic sugar for `@serwist/routing.registerRoute`.
|
|
5
5
|
*
|
|
6
|
-
* @see https://serwist.pages.dev/docs/sw/
|
|
6
|
+
* @see https://serwist.pages.dev/docs/sw/register-runtime-caching
|
|
7
7
|
* @param runtimeCachingList
|
|
8
8
|
* @returns
|
|
9
9
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerRuntimeCaching.d.ts","sourceRoot":"","sources":["../../src/abstractions/registerRuntimeCaching.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;;;GAOG;AACH,eAAO,MAAM,sBAAsB,0BAA2B,cAAc,EAAE,KAAG,IAIhF,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
|
|
2
|
-
import type { HTTPMethod } from "
|
|
2
|
+
import type { HTTPMethod } from "../routing/utils/constants.js";
|
|
3
3
|
export interface RuntimeCaching {
|
|
4
4
|
/**
|
|
5
5
|
* The HTTP method to match against. The default value of `'GET'` is normally
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/abstractions/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,MAAM,WAAW,cAAc;IAC7B;;;;;OAKG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB;;;;;;;;;OASG;IACH,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAAC;IAC9C;;;;OAIG;IACH,OAAO,EAAE,YAAY,CAAC;CACvB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { assert, logger } from '@serwist/core/internal';
|
|
2
|
+
import { R as Route } from './registerRoute.js';
|
|
3
|
+
|
|
4
|
+
class NavigationRoute extends Route {
|
|
5
|
+
_allowlist;
|
|
6
|
+
_denylist;
|
|
7
|
+
constructor(handler, { allowlist = [
|
|
8
|
+
/./
|
|
9
|
+
], denylist = [] } = {}){
|
|
10
|
+
if (process.env.NODE_ENV !== "production") {
|
|
11
|
+
assert.isArrayOfClass(allowlist, RegExp, {
|
|
12
|
+
moduleName: "@serwist/routing",
|
|
13
|
+
className: "NavigationRoute",
|
|
14
|
+
funcName: "constructor",
|
|
15
|
+
paramName: "options.allowlist"
|
|
16
|
+
});
|
|
17
|
+
assert.isArrayOfClass(denylist, RegExp, {
|
|
18
|
+
moduleName: "@serwist/routing",
|
|
19
|
+
className: "NavigationRoute",
|
|
20
|
+
funcName: "constructor",
|
|
21
|
+
paramName: "options.denylist"
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
super((options)=>this._match(options), handler);
|
|
25
|
+
this._allowlist = allowlist;
|
|
26
|
+
this._denylist = denylist;
|
|
27
|
+
}
|
|
28
|
+
_match({ url, request }) {
|
|
29
|
+
if (request && request.mode !== "navigate") {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
const pathnameAndSearch = url.pathname + url.search;
|
|
33
|
+
for (const regExp of this._denylist){
|
|
34
|
+
if (regExp.test(pathnameAndSearch)) {
|
|
35
|
+
if (process.env.NODE_ENV !== "production") {
|
|
36
|
+
logger.log(`The navigation route ${pathnameAndSearch} is not being used, since the URL matches this denylist pattern: ${regExp.toString()}`);
|
|
37
|
+
}
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (this._allowlist.some((regExp)=>regExp.test(pathnameAndSearch))) {
|
|
42
|
+
if (process.env.NODE_ENV !== "production") {
|
|
43
|
+
logger.debug(`The navigation route ${pathnameAndSearch} is being used.`);
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
if (process.env.NODE_ENV !== "production") {
|
|
48
|
+
logger.log(`The navigation route ${pathnameAndSearch} is not being used, since the URL being navigated to doesn't match the allowlist.`);
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { NavigationRoute as N };
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { getFriendlyURL, logger, assert, SerwistError, timeout } from '@serwist/core/internal';
|
|
2
|
+
import { S as Strategy } from './Strategy.js';
|
|
3
|
+
|
|
4
|
+
const cacheOkAndOpaquePlugin = {
|
|
5
|
+
cacheWillUpdate: async ({ response })=>{
|
|
6
|
+
if (response.status === 200 || response.status === 0) {
|
|
7
|
+
return response;
|
|
8
|
+
}
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const messages = {
|
|
14
|
+
strategyStart: (strategyName, request)=>`Using ${strategyName} to respond to '${getFriendlyURL(request.url)}'`,
|
|
15
|
+
printFinalResponse: (response)=>{
|
|
16
|
+
if (response) {
|
|
17
|
+
logger.groupCollapsed("View the final response here.");
|
|
18
|
+
logger.log(response || "[No response returned]");
|
|
19
|
+
logger.groupEnd();
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
class NetworkFirst extends Strategy {
|
|
25
|
+
_networkTimeoutSeconds;
|
|
26
|
+
constructor(options = {}){
|
|
27
|
+
super(options);
|
|
28
|
+
if (!this.plugins.some((p)=>"cacheWillUpdate" in p)) {
|
|
29
|
+
this.plugins.unshift(cacheOkAndOpaquePlugin);
|
|
30
|
+
}
|
|
31
|
+
this._networkTimeoutSeconds = options.networkTimeoutSeconds || 0;
|
|
32
|
+
if (process.env.NODE_ENV !== "production") {
|
|
33
|
+
if (this._networkTimeoutSeconds) {
|
|
34
|
+
assert.isType(this._networkTimeoutSeconds, "number", {
|
|
35
|
+
moduleName: "@serwist/strategies",
|
|
36
|
+
className: this.constructor.name,
|
|
37
|
+
funcName: "constructor",
|
|
38
|
+
paramName: "networkTimeoutSeconds"
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
async _handle(request, handler) {
|
|
44
|
+
const logs = [];
|
|
45
|
+
if (process.env.NODE_ENV !== "production") {
|
|
46
|
+
assert.isInstance(request, Request, {
|
|
47
|
+
moduleName: "@serwist/strategies",
|
|
48
|
+
className: this.constructor.name,
|
|
49
|
+
funcName: "handle",
|
|
50
|
+
paramName: "makeRequest"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
const promises = [];
|
|
54
|
+
let timeoutId;
|
|
55
|
+
if (this._networkTimeoutSeconds) {
|
|
56
|
+
const { id, promise } = this._getTimeoutPromise({
|
|
57
|
+
request,
|
|
58
|
+
logs,
|
|
59
|
+
handler
|
|
60
|
+
});
|
|
61
|
+
timeoutId = id;
|
|
62
|
+
promises.push(promise);
|
|
63
|
+
}
|
|
64
|
+
const networkPromise = this._getNetworkPromise({
|
|
65
|
+
timeoutId,
|
|
66
|
+
request,
|
|
67
|
+
logs,
|
|
68
|
+
handler
|
|
69
|
+
});
|
|
70
|
+
promises.push(networkPromise);
|
|
71
|
+
const response = await handler.waitUntil((async ()=>{
|
|
72
|
+
return await handler.waitUntil(Promise.race(promises)) || await networkPromise;
|
|
73
|
+
})());
|
|
74
|
+
if (process.env.NODE_ENV !== "production") {
|
|
75
|
+
logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
76
|
+
for (const log of logs){
|
|
77
|
+
logger.log(log);
|
|
78
|
+
}
|
|
79
|
+
messages.printFinalResponse(response);
|
|
80
|
+
logger.groupEnd();
|
|
81
|
+
}
|
|
82
|
+
if (!response) {
|
|
83
|
+
throw new SerwistError("no-response", {
|
|
84
|
+
url: request.url
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return response;
|
|
88
|
+
}
|
|
89
|
+
_getTimeoutPromise({ request, logs, handler }) {
|
|
90
|
+
let timeoutId;
|
|
91
|
+
const timeoutPromise = new Promise((resolve)=>{
|
|
92
|
+
const onNetworkTimeout = async ()=>{
|
|
93
|
+
if (process.env.NODE_ENV !== "production") {
|
|
94
|
+
logs.push(`Timing out the network response at ${this._networkTimeoutSeconds} seconds.`);
|
|
95
|
+
}
|
|
96
|
+
resolve(await handler.cacheMatch(request));
|
|
97
|
+
};
|
|
98
|
+
timeoutId = setTimeout(onNetworkTimeout, this._networkTimeoutSeconds * 1000);
|
|
99
|
+
});
|
|
100
|
+
return {
|
|
101
|
+
promise: timeoutPromise,
|
|
102
|
+
id: timeoutId
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
async _getNetworkPromise({ timeoutId, request, logs, handler }) {
|
|
106
|
+
let error = undefined;
|
|
107
|
+
let response = undefined;
|
|
108
|
+
try {
|
|
109
|
+
response = await handler.fetchAndCachePut(request);
|
|
110
|
+
} catch (fetchError) {
|
|
111
|
+
if (fetchError instanceof Error) {
|
|
112
|
+
error = fetchError;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (timeoutId) {
|
|
116
|
+
clearTimeout(timeoutId);
|
|
117
|
+
}
|
|
118
|
+
if (process.env.NODE_ENV !== "production") {
|
|
119
|
+
if (response) {
|
|
120
|
+
logs.push("Got response from network.");
|
|
121
|
+
} else {
|
|
122
|
+
logs.push("Unable to get a response from the network. Will respond " + "with a cached response.");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (error || !response) {
|
|
126
|
+
response = await handler.cacheMatch(request);
|
|
127
|
+
if (process.env.NODE_ENV !== "production") {
|
|
128
|
+
if (response) {
|
|
129
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
130
|
+
} else {
|
|
131
|
+
logs.push(`No response found in the '${this.cacheName}' cache.`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return response;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
class NetworkOnly extends Strategy {
|
|
140
|
+
_networkTimeoutSeconds;
|
|
141
|
+
constructor(options = {}){
|
|
142
|
+
super(options);
|
|
143
|
+
this._networkTimeoutSeconds = options.networkTimeoutSeconds || 0;
|
|
144
|
+
}
|
|
145
|
+
async _handle(request, handler) {
|
|
146
|
+
if (process.env.NODE_ENV !== "production") {
|
|
147
|
+
assert.isInstance(request, Request, {
|
|
148
|
+
moduleName: "@serwist/strategies",
|
|
149
|
+
className: this.constructor.name,
|
|
150
|
+
funcName: "_handle",
|
|
151
|
+
paramName: "request"
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
let error = undefined;
|
|
155
|
+
let response;
|
|
156
|
+
try {
|
|
157
|
+
const promises = [
|
|
158
|
+
handler.fetch(request)
|
|
159
|
+
];
|
|
160
|
+
if (this._networkTimeoutSeconds) {
|
|
161
|
+
const timeoutPromise = timeout(this._networkTimeoutSeconds * 1000);
|
|
162
|
+
promises.push(timeoutPromise);
|
|
163
|
+
}
|
|
164
|
+
response = await Promise.race(promises);
|
|
165
|
+
if (!response) {
|
|
166
|
+
throw new Error(`Timed out the network response after ${this._networkTimeoutSeconds} seconds.`);
|
|
167
|
+
}
|
|
168
|
+
} catch (err) {
|
|
169
|
+
if (err instanceof Error) {
|
|
170
|
+
error = err;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
if (process.env.NODE_ENV !== "production") {
|
|
174
|
+
logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
175
|
+
if (response) {
|
|
176
|
+
logger.log("Got response from network.");
|
|
177
|
+
} else {
|
|
178
|
+
logger.log("Unable to get a response from the network.");
|
|
179
|
+
}
|
|
180
|
+
messages.printFinalResponse(response);
|
|
181
|
+
logger.groupEnd();
|
|
182
|
+
}
|
|
183
|
+
if (!response) {
|
|
184
|
+
throw new SerwistError("no-response", {
|
|
185
|
+
url: request.url,
|
|
186
|
+
error
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
return response;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export { NetworkOnly as N, NetworkFirst as a, cacheOkAndOpaquePlugin as c, messages as m };
|