serwist 10.0.0-preview.1 → 10.0.0-preview.3

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 (136) 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 +5 -5
  5. package/dist/Serwist.d.ts.map +1 -1
  6. package/dist/chunks/{resultingClientExists.js → waitUntil.js} +117 -117
  7. package/dist/copyResponse.d.ts.map +1 -1
  8. package/dist/index.d.ts +11 -37
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.internal.d.ts +16 -16
  11. package/dist/index.internal.d.ts.map +1 -1
  12. package/dist/index.internal.js +2 -2
  13. package/dist/index.js +1400 -1387
  14. package/dist/lib/backgroundSync/StorableRequest.d.ts.map +1 -1
  15. package/dist/lib/backgroundSync/index.d.ts +6 -0
  16. package/dist/lib/backgroundSync/index.d.ts.map +1 -0
  17. package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -1
  18. package/dist/lib/broadcastUpdate/index.d.ts +6 -0
  19. package/dist/lib/broadcastUpdate/index.d.ts.map +1 -0
  20. package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +1 -1
  21. package/dist/lib/cacheableResponse/index.d.ts +4 -0
  22. package/dist/lib/cacheableResponse/index.d.ts.map +1 -0
  23. package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheCacheKeyPlugin.d.ts +1 -1
  24. package/dist/lib/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +1 -0
  25. package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheController.d.ts +9 -5
  26. package/dist/lib/controllers/PrecacheController/PrecacheController.d.ts.map +1 -0
  27. package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheInstallReportPlugin.d.ts +1 -1
  28. package/dist/lib/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +1 -0
  29. package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheRoute.d.ts +1 -1
  30. package/dist/lib/controllers/PrecacheController/PrecacheRoute.d.ts.map +1 -0
  31. package/dist/{controllers → lib/controllers}/PrecacheController/PrecacheStrategy.d.ts +4 -4
  32. package/dist/lib/controllers/PrecacheController/PrecacheStrategy.d.ts.map +1 -0
  33. package/dist/{controllers → lib/controllers}/PrecacheController/parsePrecacheOptions.d.ts +3 -3
  34. package/dist/lib/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +1 -0
  35. package/dist/{controllers → lib/controllers}/RuntimeCacheController.d.ts +10 -5
  36. package/dist/lib/controllers/RuntimeCacheController.d.ts.map +1 -0
  37. package/dist/lib/controllers/index.d.ts +4 -0
  38. package/dist/lib/controllers/index.d.ts.map +1 -0
  39. package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -1
  40. package/dist/lib/expiration/index.d.ts +4 -0
  41. package/dist/lib/expiration/index.d.ts.map +1 -0
  42. package/dist/lib/googleAnalytics/index.d.ts +3 -0
  43. package/dist/lib/googleAnalytics/index.d.ts.map +1 -0
  44. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +1 -1
  45. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts +12 -6
  46. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -1
  47. package/dist/lib/precaching/index.d.ts +3 -0
  48. package/dist/lib/precaching/index.d.ts.map +1 -0
  49. package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +1 -1
  50. package/dist/lib/rangeRequests/index.d.ts +3 -0
  51. package/dist/lib/rangeRequests/index.d.ts.map +1 -0
  52. package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -1
  53. package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -1
  54. package/dist/lib/strategies/Strategy.d.ts.map +1 -1
  55. package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
  56. package/dist/lib/strategies/index.d.ts +11 -0
  57. package/dist/lib/strategies/index.d.ts.map +1 -0
  58. package/dist/navigationPreload.d.ts.map +1 -1
  59. package/dist/registerQuotaErrorCallback.d.ts.map +1 -1
  60. package/dist/setCacheNameDetails.d.ts +1 -1
  61. package/dist/setCacheNameDetails.d.ts.map +1 -1
  62. package/dist/types.d.ts +24 -5
  63. package/dist/types.d.ts.map +1 -1
  64. package/dist/utils/SerwistError.d.ts +1 -1
  65. package/dist/utils/SerwistError.d.ts.map +1 -1
  66. package/dist/utils/cleanupOutdatedCaches.d.ts.map +1 -1
  67. package/dist/utils/createCacheKey.d.ts.map +1 -1
  68. package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -1
  69. package/dist/utils/getFriendlyURL.d.ts.map +1 -1
  70. package/dist/utils/normalizeHandler.d.ts.map +1 -1
  71. package/dist/utils/parseRoute.d.ts.map +1 -1
  72. package/dist/utils/printCleanupDetails.d.ts.map +1 -1
  73. package/dist/utils/printInstallDetails.d.ts.map +1 -1
  74. package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -1
  75. package/dist/utils/waitUntil.d.ts.map +1 -1
  76. package/package.json +28 -5
  77. package/src/NavigationRoute.ts +2 -2
  78. package/src/RegExpRoute.ts +2 -2
  79. package/src/Route.ts +2 -2
  80. package/src/Serwist.ts +23 -19
  81. package/src/cacheNames.ts +1 -1
  82. package/src/copyResponse.ts +2 -2
  83. package/src/index.internal.ts +16 -16
  84. package/src/index.ts +68 -96
  85. package/src/lib/backgroundSync/BackgroundSyncQueue.ts +4 -4
  86. package/src/lib/backgroundSync/BackgroundSyncQueueStore.ts +1 -1
  87. package/src/lib/backgroundSync/StorableRequest.ts +1 -1
  88. package/src/lib/backgroundSync/index.ts +5 -0
  89. package/src/lib/broadcastUpdate/BroadcastCacheUpdate.ts +4 -4
  90. package/src/lib/broadcastUpdate/index.ts +5 -0
  91. package/src/lib/broadcastUpdate/responsesAreSame.ts +2 -2
  92. package/src/lib/cacheableResponse/CacheableResponse.ts +4 -4
  93. package/src/lib/cacheableResponse/index.ts +3 -0
  94. package/src/{controllers → lib/controllers}/PrecacheController/PrecacheCacheKeyPlugin.ts +1 -1
  95. package/src/{controllers → lib/controllers}/PrecacheController/PrecacheController.ts +19 -16
  96. package/src/{controllers → lib/controllers}/PrecacheController/PrecacheInstallReportPlugin.ts +1 -1
  97. package/src/{controllers → lib/controllers}/PrecacheController/PrecacheRoute.ts +5 -5
  98. package/src/{controllers → lib/controllers}/PrecacheController/PrecacheStrategy.ts +10 -10
  99. package/src/{controllers → lib/controllers}/PrecacheController/parsePrecacheOptions.ts +3 -3
  100. package/src/{controllers → lib/controllers}/RuntimeCacheController.ts +6 -6
  101. package/src/lib/controllers/index.ts +3 -0
  102. package/src/lib/expiration/CacheExpiration.ts +3 -3
  103. package/src/lib/expiration/ExpirationPlugin.ts +6 -6
  104. package/src/lib/expiration/index.ts +3 -0
  105. package/src/lib/googleAnalytics/index.ts +2 -0
  106. package/src/lib/googleAnalytics/initializeGoogleAnalytics.ts +5 -5
  107. package/src/lib/precaching/PrecacheFallbackPlugin.ts +18 -7
  108. package/src/lib/precaching/index.ts +2 -0
  109. package/src/lib/rangeRequests/createPartialResponse.ts +3 -3
  110. package/src/lib/rangeRequests/index.ts +2 -0
  111. package/src/lib/rangeRequests/utils/calculateEffectiveBoundaries.ts +2 -2
  112. package/src/lib/rangeRequests/utils/parseRangeHeader.ts +2 -2
  113. package/src/lib/strategies/CacheFirst.ts +3 -3
  114. package/src/lib/strategies/CacheOnly.ts +3 -3
  115. package/src/lib/strategies/NetworkFirst.ts +3 -3
  116. package/src/lib/strategies/NetworkOnly.ts +4 -4
  117. package/src/lib/strategies/StaleWhileRevalidate.ts +3 -3
  118. package/src/lib/strategies/Strategy.ts +4 -4
  119. package/src/lib/strategies/StrategyHandler.ts +9 -9
  120. package/src/lib/strategies/index.ts +10 -0
  121. package/src/lib/strategies/utils/messages.ts +2 -2
  122. package/src/models/messages/messages.ts +3 -3
  123. package/src/navigationPreload.ts +1 -1
  124. package/src/registerQuotaErrorCallback.ts +2 -2
  125. package/src/setCacheNameDetails.ts +4 -4
  126. package/src/types.ts +36 -5
  127. package/src/utils/SerwistError.ts +2 -2
  128. package/src/utils/cacheNames.ts +1 -1
  129. package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
  130. package/dist/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +0 -1
  131. package/dist/controllers/PrecacheController/PrecacheController.d.ts.map +0 -1
  132. package/dist/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +0 -1
  133. package/dist/controllers/PrecacheController/PrecacheRoute.d.ts.map +0 -1
  134. package/dist/controllers/PrecacheController/PrecacheStrategy.d.ts.map +0 -1
  135. package/dist/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +0 -1
  136. package/dist/controllers/RuntimeCacheController.d.ts.map +0 -1
@@ -1,17 +1,17 @@
1
+ import { SerwistError } from "#utils/SerwistError.js";
2
+ import { assert } from "#utils/assert.js";
3
+ import { createCacheKey } from "#utils/createCacheKey.js";
4
+ import { logger } from "#utils/logger.js";
5
+ import { printCleanupDetails } from "#utils/printCleanupDetails.js";
6
+ import { printInstallDetails } from "#utils/printInstallDetails.js";
1
7
  import { parallel } from "@serwist/utils";
2
- import type { Strategy } from "../../lib/strategies/Strategy.js";
3
- import type { Controller, RouteHandlerCallback, UrlManipulation } from "../../types.js";
4
- import { assert } from "../../utils/assert.js";
5
- import { createCacheKey } from "../../utils/createCacheKey.js";
6
- import { logger } from "../../utils/logger.js";
8
+ import { NavigationRoute } from "../../../NavigationRoute.js";
9
+ import type { Serwist } from "../../../Serwist.js";
10
+ import type { Controller, RouteHandlerCallback, UrlManipulation } from "../../../types.js";
11
+ import type { Strategy } from "../../strategies/Strategy.js";
7
12
  import { PrecacheInstallReportPlugin } from "./PrecacheInstallReportPlugin.js";
8
- import { SerwistError } from "../../utils/SerwistError.js";
9
- import { printInstallDetails } from "../../utils/printInstallDetails.js";
10
- import { printCleanupDetails } from "../../utils/printCleanupDetails.js";
11
- import { PrecacheStrategy } from "./PrecacheStrategy.js";
12
13
  import { PrecacheRoute } from "./PrecacheRoute.js";
13
- import type { Serwist } from "../../Serwist.js";
14
- import { NavigationRoute } from "../../NavigationRoute.js";
14
+ import { PrecacheStrategy } from "./PrecacheStrategy.js";
15
15
  import type { PrecacheStrategyOptions } from "./PrecacheStrategy.js";
16
16
  import { parsePrecacheOptions } from "./parsePrecacheOptions.js";
17
17
 
@@ -90,6 +90,7 @@ export class PrecacheController implements Controller {
90
90
  private readonly _strategy: Strategy;
91
91
  private _options: PrecacheControllerOptions;
92
92
  private _routeOptions: PrecacheRouteOptions;
93
+
93
94
  /**
94
95
  * Create a new PrecacheController.
95
96
  *
@@ -101,10 +102,8 @@ export class PrecacheController implements Controller {
101
102
  this._strategy = new PrecacheStrategy(strategyOptions);
102
103
  this._options = controllerOptions;
103
104
  this._routeOptions = routeOptions;
104
- // Bind the install and activate methods to the instance.
105
- this.install = this.install.bind(this);
106
- this.activate = this.activate.bind(this);
107
105
  }
106
+
108
107
  /**
109
108
  * The strategy created by this controller and
110
109
  * used to cache assets and respond to `fetch` events.
@@ -112,6 +111,7 @@ export class PrecacheController implements Controller {
112
111
  get strategy(): Strategy {
113
112
  return this._strategy;
114
113
  }
114
+
115
115
  /**
116
116
  * Adds items to the cache list, removing duplicates and ensuring the information is valid.
117
117
  *
@@ -172,7 +172,8 @@ export class PrecacheController implements Controller {
172
172
  }
173
173
  }
174
174
  }
175
- init(serwist: Serwist) {
175
+
176
+ init({ serwist }: { serwist: Serwist }): void {
176
177
  serwist.registerRoute(new PrecacheRoute(this, this._routeOptions));
177
178
 
178
179
  if (this._options.navigateFallback) {
@@ -184,7 +185,8 @@ export class PrecacheController implements Controller {
184
185
  );
185
186
  }
186
187
  }
187
- async install(event: ExtendableEvent): Promise<void> {
188
+
189
+ async install({ event }: { event: ExtendableEvent }): Promise<void> {
188
190
  const installReportPlugin = new PrecacheInstallReportPlugin();
189
191
  this._strategy.plugins.push(installReportPlugin);
190
192
  await parallel(this._options.concurrency!, Array.from(this._urlsToCacheKeys.entries()), async ([url, cacheKey]): Promise<void> => {
@@ -213,6 +215,7 @@ export class PrecacheController implements Controller {
213
215
  printInstallDetails(updatedURLs, notUpdatedURLs);
214
216
  }
215
217
  }
218
+
216
219
  async activate(): Promise<void> {
217
220
  const cache = await self.caches.open(this._strategy.cacheName);
218
221
  const currentlyCachedRequests = await cache.keys();
@@ -6,7 +6,7 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { StrategyPlugin, StrategyPluginCallbackParam } from "../../types.js";
9
+ import type { StrategyPlugin, StrategyPluginCallbackParam } from "../../../types.js";
10
10
 
11
11
  /**
12
12
  * A plugin designed to determine the number of assets that were updated (or not updated)
@@ -6,11 +6,11 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { Route } from "../../Route.js";
10
- import type { RouteMatchCallback, RouteMatchCallbackOptions } from "../../types.js";
11
- import { generateURLVariations } from "../../utils/generateURLVariations.js";
12
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
13
- import { logger } from "../../utils/logger.js";
9
+ import { generateURLVariations } from "#utils/generateURLVariations.js";
10
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
11
+ import { logger } from "#utils/logger.js";
12
+ import { Route } from "../../../Route.js";
13
+ import type { RouteMatchCallback, RouteMatchCallbackOptions } from "../../../types.js";
14
14
  import type { PrecacheController, PrecacheRouteOptions } from "./PrecacheController.js";
15
15
 
16
16
  /**
@@ -6,16 +6,16 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { copyResponse } from "../../copyResponse.js";
10
- import type { StrategyPlugin } from "../../types.js";
11
- import { SerwistError } from "../../utils/SerwistError.js";
12
- import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
13
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
14
- import { logger } from "../../utils/logger.js";
15
- import type { Serwist } from "../../Serwist.js";
16
- import type { StrategyOptions } from "../../lib/strategies/Strategy.js";
17
- import { Strategy } from "../../lib/strategies/Strategy.js";
18
- import type { StrategyHandler } from "../../lib/strategies/StrategyHandler.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 { Serwist } from "../../../Serwist.js";
14
+ import { copyResponse } from "../../../copyResponse.js";
15
+ import type { StrategyPlugin } from "../../../types.js";
16
+ import type { StrategyOptions } from "../../strategies/Strategy.js";
17
+ import { Strategy } from "../../strategies/Strategy.js";
18
+ import type { StrategyHandler } from "../../strategies/StrategyHandler.js";
19
19
 
20
20
  export interface PrecacheStrategyOptions extends StrategyOptions {
21
21
  /**
@@ -1,8 +1,8 @@
1
- import type { PrecacheStrategyOptions } from "./PrecacheStrategy.js";
2
- import type { PrecacheController, PrecacheControllerOptions, PrecacheOptions, PrecacheRouteOptions } from "./PrecacheController.js";
1
+ import { privateCacheNames } from "#index.internal";
3
2
  import type { Require } from "@serwist/utils";
4
- import { privateCacheNames } from "../../index.internal.js";
5
3
  import { PrecacheCacheKeyPlugin } from "./PrecacheCacheKeyPlugin.js";
4
+ import type { PrecacheController, PrecacheControllerOptions, PrecacheOptions, PrecacheRouteOptions } from "./PrecacheController.js";
5
+ import type { PrecacheStrategyOptions } from "./PrecacheStrategy.js";
6
6
 
7
7
  export const parsePrecacheOptions = (
8
8
  controller: PrecacheController,
@@ -1,8 +1,8 @@
1
1
  import { parallel } from "@serwist/utils";
2
- import { PrecacheFallbackPlugin, type PrecacheFallbackEntry } from "../lib/precaching/PrecacheFallbackPlugin.js";
3
- import { Strategy } from "../lib/strategies/Strategy.js";
4
- import type { Serwist } from "../Serwist.js";
5
- import type { Controller, RuntimeCaching } from "../types.js";
2
+ import type { Serwist } from "../../Serwist.js";
3
+ import type { Controller, RuntimeCaching } from "../../types.js";
4
+ import { type PrecacheFallbackEntry, PrecacheFallbackPlugin } from "../precaching/PrecacheFallbackPlugin.js";
5
+ import { Strategy } from "../strategies/Strategy.js";
6
6
 
7
7
  export interface WarmRuntimeCacheEntry {
8
8
  integrity?: string;
@@ -51,7 +51,7 @@ export class RuntimeCacheController implements Controller {
51
51
  this.install = this.install.bind(this);
52
52
  }
53
53
 
54
- init(serwist: Serwist): void {
54
+ init({ serwist }: { serwist: Serwist }): void {
55
55
  if (this._options.fallbacks !== undefined) {
56
56
  const fallbackPlugin = new PrecacheFallbackPlugin({
57
57
  fallbackUrls: this._options.fallbacks.entries,
@@ -73,7 +73,7 @@ export class RuntimeCacheController implements Controller {
73
73
  }
74
74
  }
75
75
 
76
- async install(event: ExtendableEvent, serwist: Serwist) {
76
+ async install({ event, serwist }: { event: ExtendableEvent; serwist: Serwist }) {
77
77
  const concurrency = this._options.warmOptions?.concurrency ?? 10;
78
78
  if (this._options.warmEntries) {
79
79
  await parallel(concurrency, this._options.warmEntries, async (entry) => {
@@ -0,0 +1,3 @@
1
+ export { PrecacheStrategy } from "./PrecacheController/PrecacheStrategy.js";
2
+ export { PrecacheRoute } from "./PrecacheController/PrecacheRoute.js";
3
+ export { RuntimeCacheController } from "./RuntimeCacheController.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 { CacheTimestampsModel } from "./models/CacheTimestampsModel.js";
13
13
 
14
14
  interface CacheExpirationConfig {
@@ -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
15
  import type { CacheDidUpdateCallbackParam, CachedResponseWillBeUsedCallbackParam, StrategyPlugin } 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";
17
16
  import type { Strategy } from "../strategies/Strategy.js";
17
+ import { CacheExpiration } from "./CacheExpiration.js";
18
18
 
19
19
  export interface ExpirationPluginOptions {
20
20
  /**
@@ -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 "../../controllers/PrecacheController/PrecacheController.js";
9
+ import type { PrecacheController } from "#lib/controllers/PrecacheController/PrecacheController.js";
10
+ import type { Serwist } from "../../Serwist.js";
10
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 {
@@ -31,6 +32,11 @@ export interface PrecacheFallbackPluginOptions {
31
32
  * A {@linkcode PrecacheController} instance.
32
33
  */
33
34
  precacheController: PrecacheController;
35
+ /**
36
+ * A {@linkcode Serwist} instance.
37
+ * @deprecated Use `precacheController` instead.
38
+ */
39
+ serwist?: Serwist;
34
40
  }
35
41
 
36
42
  /**
@@ -50,9 +56,14 @@ export class PrecacheFallbackPlugin implements StrategyPlugin {
50
56
  *
51
57
  * @param config
52
58
  */
53
- constructor({ fallbackUrls, precacheController }: PrecacheFallbackPluginOptions) {
59
+ constructor({ fallbackUrls, precacheController, serwist }: PrecacheFallbackPluginOptions) {
54
60
  this._fallbackUrls = fallbackUrls;
55
- this._precacheController = precacheController;
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
  /**
@@ -0,0 +1,2 @@
1
+ export type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "./PrecacheFallbackPlugin.js";
2
+ export { PrecacheFallbackPlugin } from "./PrecacheFallbackPlugin.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 { 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 { 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";
9
13
  import type { HandlerCallbackOptions, RouteHandlerObject, StrategyPlugin } from "../../types.js";
10
- import { SerwistError } from "../../utils/SerwistError.js";
11
- import { cacheNames as privateCacheNames } from "../../utils/cacheNames.js";
12
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
13
- import { logger } from "../../utils/logger.js";
14
14
  import { StrategyHandler } from "./StrategyHandler.js";
15
15
 
16
16
  export interface StrategyOptions {
@@ -6,17 +6,17 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
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";
17
+ import type { Route } from "../../Route.js";
9
18
  import type { HandlerCallbackOptions, MapLikeObject, StrategyPlugin, StrategyPluginCallbackParam } 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
19
  import type { Strategy } from "./Strategy.js";
19
- import type { Route } from "../../Route.js";
20
20
 
21
21
  function toRequest(input: RequestInfo) {
22
22
  return typeof input === "string" ? new Request(input) : input;
@@ -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,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.
package/src/types.ts CHANGED
@@ -1,8 +1,13 @@
1
+ import type {
2
+ PrecacheControllerOptions,
3
+ PrecacheEntry,
4
+ PrecacheOptions,
5
+ PrecacheRouteOptions,
6
+ } from "#lib/controllers/PrecacheController/PrecacheController.js";
1
7
  import type { Prettify } from "@serwist/utils";
2
- import type { HTTPMethod } from "./constants.js";
3
8
  import type { Route } from "./Route.js";
4
9
  import type { Serwist } from "./Serwist.js";
5
- import type { PrecacheControllerOptions, PrecacheEntry, PrecacheOptions, PrecacheRouteOptions } from "./controllers/PrecacheController/PrecacheController.js";
10
+ import type { HTTPMethod } from "./constants.js";
6
11
 
7
12
  export type PromiseOrNot<T> = T | Promise<T>;
8
13
 
@@ -16,13 +21,39 @@ export interface MapLikeObject {
16
21
  */
17
22
  export type PluginState = MapLikeObject;
18
23
 
24
+ export interface InitCallbackParam {
25
+ serwist: Serwist;
26
+ }
27
+
28
+ export type InitCallback = (param: InitCallbackParam) => PromiseOrNot<void>;
29
+
30
+ export interface InstallCallbackParam {
31
+ event: ExtendableEvent;
32
+ serwist: Serwist;
33
+ }
34
+
35
+ export type InstallCallback = (param: InstallCallbackParam) => PromiseOrNot<void>;
36
+
37
+ export interface ActivateCallbackParam {
38
+ event: ExtendableEvent;
39
+ serwist: Serwist;
40
+ }
41
+
42
+ export type ActivateCallback = (param: ActivateCallbackParam) => PromiseOrNot<void>;
43
+
19
44
  /**
20
45
  * An object with optional lifecycle callback properties for Serwist's operations.
21
46
  */
22
47
  export interface Controller {
23
- init?(serwist: Serwist): void;
24
- install?(event: ExtendableEvent, serwist: Serwist): Promise<void>;
25
- activate?(event: ExtendableEvent, serwist: Serwist): Promise<void>;
48
+ init?: InitCallback;
49
+ install?: InstallCallback;
50
+ activate?: ActivateCallback;
51
+ }
52
+
53
+ export interface ControllerParam {
54
+ init: InitCallbackParam;
55
+ install: InstallCallbackParam;
56
+ activate: ActivateCallbackParam;
26
57
  }
27
58
 
28
59
  /**