serwist 9.1.0-preview.0 → 10.0.0-preview.2

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.
Files changed (239) hide show
  1. package/dist/NavigationRoute.d.ts.map +1 -1
  2. package/dist/RegExpRoute.d.ts.map +1 -1
  3. package/dist/Route.d.ts.map +1 -1
  4. package/dist/Serwist.d.ts +75 -53
  5. package/dist/Serwist.d.ts.map +1 -1
  6. package/dist/cacheNames.d.ts.map +1 -1
  7. package/dist/chunks/waitUntil.js +49 -42
  8. package/dist/copyResponse.d.ts.map +1 -1
  9. package/dist/index.d.ts +11 -36
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.internal.d.ts +16 -16
  12. package/dist/index.internal.d.ts.map +1 -1
  13. package/dist/index.internal.js +25 -3
  14. package/dist/index.js +1918 -248
  15. package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts +2 -2
  16. package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -1
  17. package/dist/lib/backgroundSync/StorableRequest.d.ts.map +1 -1
  18. package/dist/lib/backgroundSync/index.d.ts +6 -0
  19. package/dist/lib/backgroundSync/index.d.ts.map +1 -0
  20. package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -1
  21. package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts +2 -2
  22. package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -1
  23. package/dist/lib/broadcastUpdate/index.d.ts +6 -0
  24. package/dist/lib/broadcastUpdate/index.d.ts.map +1 -0
  25. package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +1 -1
  26. package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts +3 -3
  27. package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -1
  28. package/dist/lib/cacheableResponse/index.d.ts +4 -0
  29. package/dist/lib/cacheableResponse/index.d.ts.map +1 -0
  30. package/dist/{legacy/utils → lib/controllers/PrecacheController}/PrecacheCacheKeyPlugin.d.ts +4 -4
  31. package/dist/lib/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +1 -0
  32. package/dist/{legacy → lib/controllers/PrecacheController}/PrecacheController.d.ts +77 -64
  33. package/dist/lib/controllers/PrecacheController/PrecacheController.d.ts.map +1 -0
  34. package/dist/lib/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts +14 -0
  35. package/dist/lib/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +1 -0
  36. package/dist/{PrecacheRoute.d.ts → lib/controllers/PrecacheController/PrecacheRoute.d.ts} +4 -5
  37. package/dist/lib/controllers/PrecacheController/PrecacheRoute.d.ts.map +1 -0
  38. package/dist/lib/{strategies → controllers/PrecacheController}/PrecacheStrategy.d.ts +6 -6
  39. package/dist/lib/controllers/PrecacheController/PrecacheStrategy.d.ts.map +1 -0
  40. package/dist/lib/controllers/PrecacheController/parsePrecacheOptions.d.ts +25 -0
  41. package/dist/lib/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +1 -0
  42. package/dist/lib/controllers/RuntimeCacheController.d.ts +70 -0
  43. package/dist/lib/controllers/RuntimeCacheController.d.ts.map +1 -0
  44. package/dist/lib/controllers/index.d.ts +4 -0
  45. package/dist/lib/controllers/index.d.ts.map +1 -0
  46. package/dist/lib/expiration/ExpirationPlugin.d.ts +2 -2
  47. package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -1
  48. package/dist/lib/expiration/index.d.ts +4 -0
  49. package/dist/lib/expiration/index.d.ts.map +1 -0
  50. package/dist/lib/googleAnalytics/index.d.ts +3 -0
  51. package/dist/lib/googleAnalytics/index.d.ts.map +1 -0
  52. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +1 -1
  53. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts +15 -9
  54. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -1
  55. package/dist/lib/precaching/index.d.ts +3 -0
  56. package/dist/lib/precaching/index.d.ts.map +1 -0
  57. package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts +3 -3
  58. package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -1
  59. package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +1 -1
  60. package/dist/lib/rangeRequests/index.d.ts +3 -0
  61. package/dist/lib/rangeRequests/index.d.ts.map +1 -0
  62. package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -1
  63. package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -1
  64. package/dist/lib/strategies/Strategy.d.ts +3 -3
  65. package/dist/lib/strategies/Strategy.d.ts.map +1 -1
  66. package/dist/lib/strategies/StrategyHandler.d.ts +4 -4
  67. package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
  68. package/dist/lib/strategies/index.d.ts +11 -0
  69. package/dist/lib/strategies/index.d.ts.map +1 -0
  70. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +2 -2
  71. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -1
  72. package/dist/navigationPreload.d.ts.map +1 -1
  73. package/dist/registerQuotaErrorCallback.d.ts.map +1 -1
  74. package/dist/setCacheNameDetails.d.ts +1 -1
  75. package/dist/setCacheNameDetails.d.ts.map +1 -1
  76. package/dist/types.d.ts +35 -64
  77. package/dist/types.d.ts.map +1 -1
  78. package/dist/utils/SerwistError.d.ts +1 -1
  79. package/dist/utils/SerwistError.d.ts.map +1 -1
  80. package/dist/utils/cleanupOutdatedCaches.d.ts.map +1 -1
  81. package/dist/utils/createCacheKey.d.ts.map +1 -1
  82. package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -1
  83. package/dist/utils/getFriendlyURL.d.ts.map +1 -1
  84. package/dist/utils/normalizeHandler.d.ts.map +1 -1
  85. package/dist/utils/parseRoute.d.ts.map +1 -1
  86. package/dist/utils/pluginUtils.d.ts +2 -2
  87. package/dist/utils/pluginUtils.d.ts.map +1 -1
  88. package/dist/utils/printCleanupDetails.d.ts.map +1 -1
  89. package/dist/utils/printInstallDetails.d.ts.map +1 -1
  90. package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -1
  91. package/dist/utils/waitUntil.d.ts.map +1 -1
  92. package/package.json +29 -13
  93. package/src/NavigationRoute.ts +2 -2
  94. package/src/RegExpRoute.ts +2 -2
  95. package/src/Route.ts +2 -2
  96. package/src/Serwist.ts +170 -271
  97. package/src/cacheNames.ts +1 -1
  98. package/src/copyResponse.ts +2 -2
  99. package/src/index.internal.ts +16 -16
  100. package/src/index.ts +68 -93
  101. package/src/lib/backgroundSync/BackgroundSyncPlugin.ts +2 -2
  102. package/src/lib/backgroundSync/BackgroundSyncQueue.ts +4 -4
  103. package/src/lib/backgroundSync/BackgroundSyncQueueStore.ts +1 -1
  104. package/src/lib/backgroundSync/StorableRequest.ts +1 -1
  105. package/src/lib/backgroundSync/index.ts +5 -0
  106. package/src/lib/broadcastUpdate/BroadcastCacheUpdate.ts +4 -4
  107. package/src/lib/broadcastUpdate/BroadcastUpdatePlugin.ts +2 -2
  108. package/src/lib/broadcastUpdate/index.ts +5 -0
  109. package/src/lib/broadcastUpdate/responsesAreSame.ts +2 -2
  110. package/src/lib/cacheableResponse/CacheableResponse.ts +4 -4
  111. package/src/lib/cacheableResponse/CacheableResponsePlugin.ts +3 -3
  112. package/src/lib/cacheableResponse/index.ts +3 -0
  113. package/src/{legacy/utils → lib/controllers/PrecacheController}/PrecacheCacheKeyPlugin.ts +5 -6
  114. package/src/lib/controllers/PrecacheController/PrecacheController.ts +328 -0
  115. package/src/{utils → lib/controllers/PrecacheController}/PrecacheInstallReportPlugin.ts +5 -5
  116. package/src/{PrecacheRoute.ts → lib/controllers/PrecacheController/PrecacheRoute.ts} +11 -12
  117. package/src/lib/{strategies → controllers/PrecacheController}/PrecacheStrategy.ts +13 -13
  118. package/src/lib/controllers/PrecacheController/parsePrecacheOptions.ts +46 -0
  119. package/src/lib/controllers/RuntimeCacheController.ts +119 -0
  120. package/src/lib/controllers/index.ts +3 -0
  121. package/src/lib/expiration/CacheExpiration.ts +3 -3
  122. package/src/lib/expiration/ExpirationPlugin.ts +8 -8
  123. package/src/lib/expiration/index.ts +3 -0
  124. package/src/lib/googleAnalytics/index.ts +2 -0
  125. package/src/lib/googleAnalytics/initializeGoogleAnalytics.ts +5 -5
  126. package/src/lib/precaching/PrecacheFallbackPlugin.ts +23 -12
  127. package/src/lib/precaching/index.ts +2 -0
  128. package/src/lib/rangeRequests/RangeRequestsPlugin.ts +3 -3
  129. package/src/lib/rangeRequests/createPartialResponse.ts +3 -3
  130. package/src/lib/rangeRequests/index.ts +2 -0
  131. package/src/lib/rangeRequests/utils/calculateEffectiveBoundaries.ts +2 -2
  132. package/src/lib/rangeRequests/utils/parseRangeHeader.ts +2 -2
  133. package/src/lib/strategies/CacheFirst.ts +3 -3
  134. package/src/lib/strategies/CacheOnly.ts +3 -3
  135. package/src/lib/strategies/NetworkFirst.ts +3 -3
  136. package/src/lib/strategies/NetworkOnly.ts +4 -4
  137. package/src/lib/strategies/StaleWhileRevalidate.ts +3 -3
  138. package/src/lib/strategies/Strategy.ts +7 -7
  139. package/src/lib/strategies/StrategyHandler.ts +18 -18
  140. package/src/lib/strategies/index.ts +10 -0
  141. package/src/lib/strategies/plugins/cacheOkAndOpaquePlugin.ts +2 -2
  142. package/src/lib/strategies/utils/messages.ts +2 -2
  143. package/src/models/messages/messages.ts +3 -3
  144. package/src/navigationPreload.ts +1 -1
  145. package/src/registerQuotaErrorCallback.ts +2 -2
  146. package/src/setCacheNameDetails.ts +4 -4
  147. package/src/types.ts +56 -68
  148. package/src/utils/SerwistError.ts +2 -2
  149. package/src/utils/cacheNames.ts +1 -1
  150. package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
  151. package/src/utils/pluginUtils.ts +2 -2
  152. package/dist/PrecacheRoute.d.ts.map +0 -1
  153. package/dist/chunks/printInstallDetails.js +0 -1601
  154. package/dist/chunks/resultingClientExists.js +0 -32
  155. package/dist/index.legacy.d.ts +0 -28
  156. package/dist/index.legacy.d.ts.map +0 -1
  157. package/dist/index.legacy.js +0 -790
  158. package/dist/legacy/PrecacheController.d.ts.map +0 -1
  159. package/dist/legacy/PrecacheFallbackPlugin.d.ts +0 -61
  160. package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +0 -1
  161. package/dist/legacy/PrecacheRoute.d.ts +0 -19
  162. package/dist/legacy/PrecacheRoute.d.ts.map +0 -1
  163. package/dist/legacy/Router.d.ts +0 -151
  164. package/dist/legacy/Router.d.ts.map +0 -1
  165. package/dist/legacy/addPlugins.d.ts +0 -9
  166. package/dist/legacy/addPlugins.d.ts.map +0 -1
  167. package/dist/legacy/addRoute.d.ts +0 -14
  168. package/dist/legacy/addRoute.d.ts.map +0 -1
  169. package/dist/legacy/constants.d.ts +0 -10
  170. package/dist/legacy/constants.d.ts.map +0 -1
  171. package/dist/legacy/createHandlerBoundToURL.d.ts +0 -17
  172. package/dist/legacy/createHandlerBoundToURL.d.ts.map +0 -1
  173. package/dist/legacy/fallbacks.d.ts +0 -59
  174. package/dist/legacy/fallbacks.d.ts.map +0 -1
  175. package/dist/legacy/getCacheKeyForURL.d.ts +0 -20
  176. package/dist/legacy/getCacheKeyForURL.d.ts.map +0 -1
  177. package/dist/legacy/handlePrecaching.d.ts +0 -54
  178. package/dist/legacy/handlePrecaching.d.ts.map +0 -1
  179. package/dist/legacy/initializeGoogleAnalytics.d.ts +0 -38
  180. package/dist/legacy/initializeGoogleAnalytics.d.ts.map +0 -1
  181. package/dist/legacy/installSerwist.d.ts +0 -81
  182. package/dist/legacy/installSerwist.d.ts.map +0 -1
  183. package/dist/legacy/matchPrecache.d.ts +0 -15
  184. package/dist/legacy/matchPrecache.d.ts.map +0 -1
  185. package/dist/legacy/precache.d.ts +0 -20
  186. package/dist/legacy/precache.d.ts.map +0 -1
  187. package/dist/legacy/precacheAndRoute.d.ts +0 -14
  188. package/dist/legacy/precacheAndRoute.d.ts.map +0 -1
  189. package/dist/legacy/registerRoute.d.ts +0 -16
  190. package/dist/legacy/registerRoute.d.ts.map +0 -1
  191. package/dist/legacy/registerRuntimeCaching.d.ts +0 -11
  192. package/dist/legacy/registerRuntimeCaching.d.ts.map +0 -1
  193. package/dist/legacy/setCatchHandler.d.ts +0 -10
  194. package/dist/legacy/setCatchHandler.d.ts.map +0 -1
  195. package/dist/legacy/setDefaultHandler.d.ts +0 -13
  196. package/dist/legacy/setDefaultHandler.d.ts.map +0 -1
  197. package/dist/legacy/singletonPrecacheController.d.ts +0 -34
  198. package/dist/legacy/singletonPrecacheController.d.ts.map +0 -1
  199. package/dist/legacy/singletonRouter.d.ts +0 -41
  200. package/dist/legacy/singletonRouter.d.ts.map +0 -1
  201. package/dist/legacy/unregisterRoute.d.ts +0 -9
  202. package/dist/legacy/unregisterRoute.d.ts.map +0 -1
  203. package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
  204. package/dist/legacy/utils/getCacheKeyForURL.d.ts +0 -14
  205. package/dist/legacy/utils/getCacheKeyForURL.d.ts.map +0 -1
  206. package/dist/lib/strategies/PrecacheStrategy.d.ts.map +0 -1
  207. package/dist/utils/PrecacheCacheKeyPlugin.d.ts +0 -16
  208. package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
  209. package/dist/utils/PrecacheInstallReportPlugin.d.ts +0 -14
  210. package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
  211. package/dist/utils/parsePrecacheOptions.d.ts +0 -26
  212. package/dist/utils/parsePrecacheOptions.d.ts.map +0 -1
  213. package/src/index.legacy.ts +0 -62
  214. package/src/legacy/PrecacheController.ts +0 -337
  215. package/src/legacy/PrecacheFallbackPlugin.ts +0 -92
  216. package/src/legacy/PrecacheRoute.ts +0 -48
  217. package/src/legacy/Router.ts +0 -484
  218. package/src/legacy/addPlugins.ts +0 -21
  219. package/src/legacy/addRoute.ts +0 -27
  220. package/src/legacy/constants.ts +0 -22
  221. package/src/legacy/createHandlerBoundToURL.ts +0 -30
  222. package/src/legacy/fallbacks.ts +0 -94
  223. package/src/legacy/getCacheKeyForURL.ts +0 -32
  224. package/src/legacy/handlePrecaching.ts +0 -86
  225. package/src/legacy/initializeGoogleAnalytics.ts +0 -218
  226. package/src/legacy/installSerwist.ts +0 -170
  227. package/src/legacy/matchPrecache.ts +0 -27
  228. package/src/legacy/precache.ts +0 -33
  229. package/src/legacy/precacheAndRoute.ts +0 -27
  230. package/src/legacy/registerRoute.ts +0 -28
  231. package/src/legacy/registerRuntimeCaching.ts +0 -17
  232. package/src/legacy/setCatchHandler.ts +0 -21
  233. package/src/legacy/setDefaultHandler.ts +0 -24
  234. package/src/legacy/singletonPrecacheController.ts +0 -53
  235. package/src/legacy/singletonRouter.ts +0 -70
  236. package/src/legacy/unregisterRoute.ts +0 -13
  237. package/src/legacy/utils/getCacheKeyForURL.ts +0 -36
  238. package/src/utils/PrecacheCacheKeyPlugin.ts +0 -33
  239. package/src/utils/parsePrecacheOptions.ts +0 -47
@@ -6,15 +6,15 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
12
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
13
+ import { logger } from "#utils/logger.js";
9
14
  import { registerQuotaErrorCallback } from "../../registerQuotaErrorCallback.js";
10
- import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, SerwistPlugin } from "../../types.js";
11
- import { SerwistError } from "../../utils/SerwistError.js";
12
- import { assert } from "../../utils/assert.js";
13
- import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
14
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
15
- import { logger } from "../../utils/logger.js";
16
- import { CacheExpiration } from "./CacheExpiration.js";
15
+ import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, StrategyPlugin } from "../../types.js";
17
16
  import type { Strategy } from "../strategies/Strategy.js";
17
+ import { CacheExpiration } from "./CacheExpiration.js";
18
18
 
19
19
  export interface ExpirationPluginOptions {
20
20
  /**
@@ -66,7 +66,7 @@ export interface ExpirationPluginOptions {
66
66
  *
67
67
  * @see https://serwist.pages.dev/docs/serwist/runtime-caching/plugins/expiration-plugin
68
68
  */
69
- export class ExpirationPlugin implements SerwistPlugin {
69
+ export class ExpirationPlugin implements StrategyPlugin {
70
70
  private readonly _config: ExpirationPluginOptions;
71
71
  private _cacheExpirations: Map<string, CacheExpiration>;
72
72
 
@@ -0,0 +1,3 @@
1
+ export { CacheExpiration } from "./CacheExpiration.js";
2
+ export type { ExpirationPluginOptions } from "./ExpirationPlugin.js";
3
+ export { ExpirationPlugin } from "./ExpirationPlugin.js";
@@ -0,0 +1,2 @@
1
+ export { initializeGoogleAnalytics } from "./initializeGoogleAnalytics.js";
2
+ export type { GoogleAnalyticsInitializeOptions } from "./initializeGoogleAnalytics.js";
@@ -6,16 +6,16 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
+ import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
10
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
11
+ import { logger } from "#utils/logger.js";
9
12
  import { Route } from "../../Route.js";
10
13
  import type { Serwist } from "../../Serwist.js";
11
- import { NetworkFirst } from "../../lib/strategies/NetworkFirst.js";
12
- import { NetworkOnly } from "../../lib/strategies/NetworkOnly.js";
13
14
  import type { RouteMatchCallbackOptions } from "../../types.js";
14
- import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
15
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
16
- import { logger } from "../../utils/logger.js";
17
15
  import { BackgroundSyncPlugin } from "../backgroundSync/BackgroundSyncPlugin.js";
18
16
  import type { BackgroundSyncQueue, BackgroundSyncQueueEntry } from "../backgroundSync/BackgroundSyncQueue.js";
17
+ import { NetworkFirst } from "../strategies/NetworkFirst.js";
18
+ import { NetworkOnly } from "../strategies/NetworkOnly.js";
19
19
  import {
20
20
  ANALYTICS_JS_PATH,
21
21
  COLLECT_PATHS_REGEX,
@@ -6,19 +6,20 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
+ import type { PrecacheController } from "#lib/controllers/PrecacheController/PrecacheController.js";
9
10
  import type { Serwist } from "../../Serwist.js";
10
- import type { HandlerDidErrorCallbackParam, SerwistPlugin } from "../../types.js";
11
+ import type { HandlerDidErrorCallbackParam, StrategyPlugin } from "../../types.js";
11
12
 
12
13
  export interface PrecacheFallbackEntry {
14
+ /**
15
+ * A precached URL to be used as a fallback.
16
+ */
17
+ url: string;
13
18
  /**
14
19
  * A function that checks whether the fallback entry can be used
15
20
  * for a request.
16
21
  */
17
22
  matcher: (param: HandlerDidErrorCallbackParam) => boolean;
18
- /**
19
- * A precached URL to be used as a fallback.
20
- */
21
- url: string;
22
23
  }
23
24
 
24
25
  export interface PrecacheFallbackPluginOptions {
@@ -27,10 +28,15 @@ export interface PrecacheFallbackPluginOptions {
27
28
  * if the associated strategy can't generate a response.
28
29
  */
29
30
  fallbackUrls: (string | PrecacheFallbackEntry)[];
31
+ /**
32
+ * A {@linkcode PrecacheController} instance.
33
+ */
34
+ precacheController: PrecacheController;
30
35
  /**
31
36
  * A {@linkcode Serwist} instance.
37
+ * @deprecated Use `precacheController` instead.
32
38
  */
33
- serwist: Serwist;
39
+ serwist?: Serwist;
34
40
  }
35
41
 
36
42
  /**
@@ -41,18 +47,23 @@ export interface PrecacheFallbackPluginOptions {
41
47
  * and returning a precached response, taking the expected revision parameter
42
48
  * into account automatically.
43
49
  */
44
- export class PrecacheFallbackPlugin implements SerwistPlugin {
50
+ export class PrecacheFallbackPlugin implements StrategyPlugin {
45
51
  private readonly _fallbackUrls: (string | PrecacheFallbackEntry)[];
46
- private readonly _serwist: Serwist;
52
+ private readonly _precacheController: PrecacheController;
47
53
 
48
54
  /**
49
55
  * Constructs a new instance with the associated `fallbackUrls`.
50
56
  *
51
57
  * @param config
52
58
  */
53
- constructor({ fallbackUrls, serwist }: PrecacheFallbackPluginOptions) {
59
+ constructor({ fallbackUrls, precacheController, serwist }: PrecacheFallbackPluginOptions) {
54
60
  this._fallbackUrls = fallbackUrls;
55
- this._serwist = serwist;
61
+ // TODO(ducanhgh): remove in v11.
62
+ if (!serwist) {
63
+ this._precacheController = precacheController;
64
+ } else {
65
+ this._precacheController = serwist.precache;
66
+ }
56
67
  }
57
68
 
58
69
  /**
@@ -63,12 +74,12 @@ export class PrecacheFallbackPlugin implements SerwistPlugin {
63
74
  async handlerDidError(param: HandlerDidErrorCallbackParam) {
64
75
  for (const fallback of this._fallbackUrls) {
65
76
  if (typeof fallback === "string") {
66
- const fallbackResponse = await this._serwist.matchPrecache(fallback);
77
+ const fallbackResponse = await this._precacheController.matchPrecache(fallback);
67
78
  if (fallbackResponse !== undefined) {
68
79
  return fallbackResponse;
69
80
  }
70
81
  } else if (fallback.matcher(param)) {
71
- const fallbackResponse = await this._serwist.matchPrecache(fallback.url);
82
+ const fallbackResponse = await this._precacheController.matchPrecache(fallback.url);
72
83
  if (fallbackResponse !== undefined) {
73
84
  return fallbackResponse;
74
85
  }
@@ -0,0 +1,2 @@
1
+ export type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "./PrecacheFallbackPlugin.js";
2
+ export { PrecacheFallbackPlugin } from "./PrecacheFallbackPlugin.js";
@@ -6,7 +6,7 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { SerwistPlugin } from "../../types.js";
9
+ import type { StrategyPlugin } from "../../types.js";
10
10
  import { createPartialResponse } from "./createPartialResponse.js";
11
11
 
12
12
  /**
@@ -15,7 +15,7 @@ import { createPartialResponse } from "./createPartialResponse.js";
15
15
  * It does this by intercepting the `cachedResponseWillBeUsed` plugin callback
16
16
  * and returning the appropriate subset of the cached response body.
17
17
  */
18
- export class RangeRequestsPlugin implements SerwistPlugin {
18
+ export class RangeRequestsPlugin implements StrategyPlugin {
19
19
  /**
20
20
  * @param options
21
21
  * @returns If request contains a `Range` header, then a
@@ -23,7 +23,7 @@ export class RangeRequestsPlugin implements SerwistPlugin {
23
23
  * returned. Otherwise, `cachedResponse` is returned as-is.
24
24
  * @private
25
25
  */
26
- cachedResponseWillBeUsed: SerwistPlugin["cachedResponseWillBeUsed"] = async ({ request, cachedResponse }) => {
26
+ cachedResponseWillBeUsed: StrategyPlugin["cachedResponseWillBeUsed"] = async ({ request, cachedResponse }) => {
27
27
  // Only return a sliced response if there's something valid in the cache,
28
28
  // and there's a Range: header in the request.
29
29
  if (cachedResponse && request.headers.has("range")) {
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { logger } from "#utils/logger.js";
12
12
  import { calculateEffectiveBoundaries } from "./utils/calculateEffectiveBoundaries.js";
13
13
  import { parseRangeHeader } from "./utils/parseRangeHeader.js";
14
14
 
@@ -0,0 +1,2 @@
1
+ export { RangeRequestsPlugin } from "./RangeRequestsPlugin.js";
2
+ export { createPartialResponse } from "./createPartialResponse.js";
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../../utils/SerwistError.js";
10
- import { assert } from "../../../utils/assert.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
11
 
12
12
  /**
13
13
  * @param blob A source blob.
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../../utils/SerwistError.js";
10
- import { assert } from "../../../utils/assert.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
11
 
12
12
  /**
13
13
  * @param rangeHeader A `Range` header value.
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { logger } from "#utils/logger.js";
12
12
  import { Strategy } from "./Strategy.js";
13
13
  import type { StrategyHandler } from "./StrategyHandler.js";
14
14
  import { messages } from "./utils/messages.js";
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { logger } from "#utils/logger.js";
12
12
  import { Strategy } from "./Strategy.js";
13
13
  import type { StrategyHandler } from "./StrategyHandler.js";
14
14
  import { messages } from "./utils/messages.js";
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { logger } from "#utils/logger.js";
12
12
  import type { StrategyOptions } from "./Strategy.js";
13
13
  import { Strategy } from "./Strategy.js";
14
14
  import type { StrategyHandler } from "./StrategyHandler.js";
@@ -6,10 +6,10 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
12
- import { timeout } from "../../utils/timeout.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { logger } from "#utils/logger.js";
12
+ import { timeout } from "#utils/timeout.js";
13
13
  import type { StrategyOptions } from "./Strategy.js";
14
14
  import { Strategy } from "./Strategy.js";
15
15
  import type { StrategyHandler } from "./StrategyHandler.js";
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { logger } from "#utils/logger.js";
12
12
  import type { StrategyOptions } from "./Strategy.js";
13
13
  import { Strategy } from "./Strategy.js";
14
14
  import type { StrategyHandler } from "./StrategyHandler.js";
@@ -6,11 +6,11 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { HandlerCallbackOptions, RouteHandlerObject, SerwistPlugin } from "../../types.js";
10
- import { SerwistError } from "../../utils/SerwistError.js";
11
- import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
12
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
13
- import { logger } from "../../utils/logger.js";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
11
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
12
+ import { logger } from "#utils/logger.js";
13
+ import type { HandlerCallbackOptions, RouteHandlerObject, StrategyPlugin } from "../../types.js";
14
14
  import { StrategyHandler } from "./StrategyHandler.js";
15
15
 
16
16
  export interface StrategyOptions {
@@ -21,7 +21,7 @@ export interface StrategyOptions {
21
21
  /**
22
22
  * [Plugins](https://serwist.pages.dev/docs/serwist/runtime-caching/plugins) to use in conjunction with this caching strategy.
23
23
  */
24
- plugins?: SerwistPlugin[];
24
+ plugins?: StrategyPlugin[];
25
25
  /**
26
26
  * Options passed to [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796) `fetch()` calls made by
27
27
  * this strategy.
@@ -42,7 +42,7 @@ export interface StrategyOptions {
42
42
  */
43
43
  export abstract class Strategy implements RouteHandlerObject {
44
44
  cacheName: string;
45
- plugins: SerwistPlugin[];
45
+ plugins: StrategyPlugin[];
46
46
  fetchOptions?: RequestInit;
47
47
  matchOptions?: CacheQueryOptions;
48
48
 
@@ -6,17 +6,17 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } from "../../types.js";
10
- import { Deferred } from "../../utils/Deferred.js";
11
- import { SerwistError } from "../../utils/SerwistError.js";
12
- import { assert } from "../../utils/assert.js";
13
- import { cacheMatchIgnoreParams } from "../../utils/cacheMatchIgnoreParams.js";
14
- import { executeQuotaErrorCallbacks } from "../../utils/executeQuotaErrorCallbacks.js";
15
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
16
- import { logger } from "../../utils/logger.js";
17
- import { timeout } from "../../utils/timeout.js";
18
- import type { Strategy } from "./Strategy.js";
9
+ import { Deferred } from "#utils/Deferred.js";
10
+ import { SerwistError } from "#utils/SerwistError.js";
11
+ import { assert } from "#utils/assert.js";
12
+ import { cacheMatchIgnoreParams } from "#utils/cacheMatchIgnoreParams.js";
13
+ import { executeQuotaErrorCallbacks } from "#utils/executeQuotaErrorCallbacks.js";
14
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
15
+ import { logger } from "#utils/logger.js";
16
+ import { timeout } from "#utils/timeout.js";
19
17
  import type { Route } from "../../Route.js";
18
+ import type { HandlerCallbackOptions, MapLikeObject, StrategyPlugin, StrategyPluginCallbackParam } from "../../types.js";
19
+ import type { Strategy } from "./Strategy.js";
20
20
 
21
21
  function toRequest(input: RequestInfo) {
22
22
  return typeof input === "string" ? new Request(input) : input;
@@ -59,8 +59,8 @@ export class StrategyHandler {
59
59
  private readonly _strategy: Strategy;
60
60
  private readonly _handlerDeferred: Deferred<any>;
61
61
  private readonly _extendLifetimePromises: Promise<any>[];
62
- private readonly _plugins: SerwistPlugin[];
63
- private readonly _pluginStateMap: Map<SerwistPlugin, MapLikeObject>;
62
+ private readonly _plugins: StrategyPlugin[];
63
+ private readonly _pluginStateMap: Map<StrategyPlugin, MapLikeObject>;
64
64
 
65
65
  /**
66
66
  * Creates a new instance associated with the passed strategy and event
@@ -405,7 +405,7 @@ export class StrategyHandler {
405
405
  * @param name The name of the callback to check for.
406
406
  * @returns
407
407
  */
408
- hasCallback<C extends keyof SerwistPlugin>(name: C): boolean {
408
+ hasCallback<C extends keyof StrategyPlugin>(name: C): boolean {
409
409
  for (const plugin of this._strategy.plugins) {
410
410
  if (name in plugin) {
411
411
  return true;
@@ -426,10 +426,10 @@ export class StrategyHandler {
426
426
  * @param param The object to pass as the first (and only) param when executing each callback. This object will be merged with the
427
427
  * current plugin state prior to callback execution.
428
428
  */
429
- async runCallbacks<C extends keyof NonNullable<SerwistPlugin>>(name: C, param: Omit<SerwistPluginCallbackParam[C], "state">): Promise<void> {
429
+ async runCallbacks<C extends keyof NonNullable<StrategyPlugin>>(name: C, param: Omit<StrategyPluginCallbackParam[C], "state">): Promise<void> {
430
430
  for (const callback of this.iterateCallbacks(name)) {
431
431
  // TODO(philipwalton): not sure why `any` is needed. It seems like
432
- // this should work with `as SerwistPluginCallbackParam[C]`.
432
+ // this should work with `as StrategyPluginCallbackParam[C]`.
433
433
  await callback(param as any);
434
434
  }
435
435
  }
@@ -440,18 +440,18 @@ export class StrategyHandler {
440
440
  * @param name The name fo the callback to run
441
441
  * @returns
442
442
  */
443
- *iterateCallbacks<C extends keyof SerwistPlugin>(name: C): Generator<NonNullable<SerwistPlugin[C]>> {
443
+ *iterateCallbacks<C extends keyof StrategyPlugin>(name: C): Generator<NonNullable<StrategyPlugin[C]>> {
444
444
  for (const plugin of this._strategy.plugins) {
445
445
  if (typeof plugin[name] === "function") {
446
446
  const state = this._pluginStateMap.get(plugin);
447
- const statefulCallback = (param: Omit<SerwistPluginCallbackParam[C], "state">) => {
447
+ const statefulCallback = (param: Omit<StrategyPluginCallbackParam[C], "state">) => {
448
448
  const statefulParam = { ...param, state };
449
449
 
450
450
  // TODO(philipwalton): not sure why `any` is needed. It seems like
451
451
  // this should work with `as WorkboxPluginCallbackParam[C]`.
452
452
  return plugin[name]!(statefulParam as any);
453
453
  };
454
- yield statefulCallback as NonNullable<SerwistPlugin[C]>;
454
+ yield statefulCallback as NonNullable<StrategyPlugin[C]>;
455
455
  }
456
456
  }
457
457
  }
@@ -0,0 +1,10 @@
1
+ export { CacheFirst } from "./CacheFirst.js";
2
+ export { CacheOnly } from "./CacheOnly.js";
3
+ export type { NetworkFirstOptions } from "./NetworkFirst.js";
4
+ export { NetworkFirst } from "./NetworkFirst.js";
5
+ export type { NetworkOnlyOptions } from "./NetworkOnly.js";
6
+ export { NetworkOnly } from "./NetworkOnly.js";
7
+ export { StaleWhileRevalidate } from "./StaleWhileRevalidate.js";
8
+ export type { StrategyOptions } from "./Strategy.js";
9
+ export { Strategy } from "./Strategy.js";
10
+ export { StrategyHandler } from "./StrategyHandler.js";
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { SerwistPlugin } from "../../../types.js";
9
+ import type { StrategyPlugin } from "../../../types.js";
10
10
 
11
- export const cacheOkAndOpaquePlugin: SerwistPlugin = {
11
+ export const cacheOkAndOpaquePlugin: StrategyPlugin = {
12
12
  /**
13
13
  * Returns a valid response (to allow caching) if the status is 200 (OK) or
14
14
  * 0 (opaque).
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { getFriendlyURL } from "../../../utils/getFriendlyURL.js";
10
- import { logger } from "../../../utils/logger.js";
9
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
10
+ import { logger } from "#utils/logger.js";
11
11
 
12
12
  export const messages = {
13
13
  strategyStart: (strategyName: string, request: Request): string => `Using ${strategyName} to respond to '${getFriendlyURL(request.url)}'`,
@@ -64,7 +64,7 @@ export const messages = {
64
64
  },
65
65
 
66
66
  "add-to-cache-list-unexpected-type": ({ entry }) => {
67
- return `An unexpected entry was passed to 'serwist.Serwist.addToPrecacheList()' The entry '${JSON.stringify(
67
+ return `An unexpected entry was passed to 'serwist.Serwist.precache.addToCacheList()' The entry '${JSON.stringify(
68
68
  entry,
69
69
  )}' isn't supported. You must supply an array of strings with one or more characters, objects with a url property or Request objects.`;
70
70
  },
@@ -74,7 +74,7 @@ export const messages = {
74
74
  throw new Error("Unexpected input to " + `'add-to-cache-list-duplicate-entries' error.`);
75
75
  }
76
76
 
77
- return `Two of the entries passed to 'serwist.Serwist.addToPrecacheList()' had the URL ${firstEntry} but different revision details. Serwist is unable to cache and version the asset correctly. Please remove one of the entries.`;
77
+ return `Two of the entries passed to 'serwist.Serwist.precache.addToCacheList()' had the URL ${firstEntry} but different revision details. Serwist is unable to cache and version the asset correctly. Please remove one of the entries.`;
78
78
  },
79
79
 
80
80
  "plugin-error-request-will-fetch": ({ thrownErrorMessage }) => {
@@ -210,7 +210,7 @@ export const messages = {
210
210
  },
211
211
 
212
212
  "add-to-cache-list-conflicting-integrities": ({ url }) => {
213
- return `Two of the entries passed to 'serwist.Serwist.addToPrecacheList()' had the URL ${url} with different integrity values. Please remove one of them.`;
213
+ return `Two of the entries passed to 'serwist.Serwist.precache.addToCacheList()' had the URL ${url} with different integrity values. Please remove one of them.`;
214
214
  },
215
215
 
216
216
  "missing-precache-entry": ({ cacheName, url }) => {
@@ -1,4 +1,4 @@
1
- import { logger } from "./utils/logger.js";
1
+ import { logger } from "#utils/logger.js";
2
2
 
3
3
  declare const self: ServiceWorkerGlobalScope;
4
4
 
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
+ import { assert } from "#utils/assert.js";
10
+ import { logger } from "#utils/logger.js";
9
11
  import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
10
- import { assert } from "./utils/assert.js";
11
- import { logger } from "./utils/logger.js";
12
12
 
13
13
  /**
14
14
  * Adds a function to the set of quotaErrorCallbacks that will be executed if
@@ -6,10 +6,10 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "./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";
9
+ import { SerwistError } from "#utils/SerwistError.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import type { PartialCacheNameDetails } from "#utils/cacheNames.js";
12
+ import { cacheNames } from "#utils/cacheNames.js";
13
13
 
14
14
  /**
15
15
  * Modifies the default cache names used by Serwist packages.