serwist 9.0.0-preview.24 → 9.0.0-preview.25

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 (217) hide show
  1. package/dist/NavigationRoute.d.ts +1 -1
  2. package/dist/NavigationRoute.d.ts.map +1 -1
  3. package/dist/PrecacheRoute.d.ts.map +1 -1
  4. package/dist/RegExpRoute.d.ts +1 -1
  5. package/dist/RegExpRoute.d.ts.map +1 -1
  6. package/dist/Route.d.ts +1 -1
  7. package/dist/Route.d.ts.map +1 -1
  8. package/dist/Serwist.d.ts +38 -43
  9. package/dist/Serwist.d.ts.map +1 -1
  10. package/dist/chunks/printInstallDetails.js +1613 -0
  11. package/dist/chunks/resultingClientExists.js +1 -1
  12. package/dist/chunks/waitUntil.js +400 -1
  13. package/dist/copyResponse.d.ts +1 -1
  14. package/dist/copyResponse.d.ts.map +1 -1
  15. package/dist/disableDevLogs.d.ts +1 -1
  16. package/dist/index.d.ts +42 -10
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.internal.js +1 -2
  19. package/dist/index.js +1464 -8
  20. package/dist/index.legacy.d.ts +5 -3
  21. package/dist/index.legacy.d.ts.map +1 -1
  22. package/dist/index.legacy.js +168 -17
  23. package/dist/legacy/PrecacheController.d.ts +1 -1
  24. package/dist/legacy/PrecacheController.d.ts.map +1 -1
  25. package/dist/legacy/PrecacheRoute.d.ts.map +1 -1
  26. package/dist/legacy/Router.d.ts +1 -1
  27. package/dist/legacy/Router.d.ts.map +1 -1
  28. package/dist/legacy/constants.d.ts.map +1 -0
  29. package/dist/legacy/fallbacks.d.ts +1 -1
  30. package/dist/legacy/fallbacks.d.ts.map +1 -1
  31. package/dist/legacy/initializeGoogleAnalytics.d.ts +38 -0
  32. package/dist/legacy/initializeGoogleAnalytics.d.ts.map +1 -0
  33. package/dist/legacy/installSerwist.d.ts +69 -3
  34. package/dist/legacy/installSerwist.d.ts.map +1 -1
  35. package/dist/legacy/registerRoute.d.ts +1 -1
  36. package/dist/legacy/registerRoute.d.ts.map +1 -1
  37. package/dist/{plugins → lib}/backgroundSync/BackgroundSyncPlugin.d.ts +3 -3
  38. package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
  39. package/dist/{plugins/backgroundSync/Queue.d.ts → lib/backgroundSync/BackgroundSyncQueue.d.ts} +29 -13
  40. package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts.map +1 -0
  41. package/dist/{plugins/backgroundSync/QueueDb.d.ts → lib/backgroundSync/BackgroundSyncQueueDb.d.ts} +7 -7
  42. package/dist/lib/backgroundSync/BackgroundSyncQueueDb.d.ts.map +1 -0
  43. package/dist/{plugins/backgroundSync/QueueStore.d.ts → lib/backgroundSync/BackgroundSyncQueueStore.d.ts} +7 -7
  44. package/dist/lib/backgroundSync/BackgroundSyncQueueStore.d.ts.map +1 -0
  45. package/dist/lib/backgroundSync/StorableRequest.d.ts.map +1 -0
  46. package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
  47. package/dist/{plugins → lib}/broadcastUpdate/BroadcastUpdatePlugin.d.ts +1 -1
  48. package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
  49. package/dist/lib/broadcastUpdate/constants.d.ts +5 -0
  50. package/dist/lib/broadcastUpdate/constants.d.ts.map +1 -0
  51. package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
  52. package/dist/{plugins → lib}/broadcastUpdate/types.d.ts +3 -3
  53. package/dist/lib/broadcastUpdate/types.d.ts.map +1 -0
  54. package/dist/lib/cacheableResponse/CacheableResponse.d.ts.map +1 -0
  55. package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
  56. package/dist/{plugins → lib}/expiration/CacheExpiration.d.ts +1 -1
  57. package/dist/lib/expiration/CacheExpiration.d.ts.map +1 -0
  58. package/dist/{plugins → lib}/expiration/ExpirationPlugin.d.ts +1 -1
  59. package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -0
  60. package/dist/lib/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
  61. package/dist/lib/googleAnalytics/constants.d.ts +10 -0
  62. package/dist/lib/googleAnalytics/constants.d.ts.map +1 -0
  63. package/dist/{plugins/googleAnalytics/initialize.d.ts → lib/googleAnalytics/initializeGoogleAnalytics.d.ts} +2 -2
  64. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +1 -0
  65. package/dist/{plugins → lib}/precaching/PrecacheFallbackPlugin.d.ts +1 -1
  66. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
  67. package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
  68. package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +1 -0
  69. package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
  70. package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
  71. package/dist/lib/strategies/CacheFirst.d.ts.map +1 -0
  72. package/dist/lib/strategies/CacheOnly.d.ts.map +1 -0
  73. package/dist/lib/strategies/NetworkFirst.d.ts.map +1 -0
  74. package/dist/lib/strategies/NetworkOnly.d.ts.map +1 -0
  75. package/dist/{PrecacheStrategy.d.ts → lib/strategies/PrecacheOnly.d.ts} +7 -7
  76. package/dist/lib/strategies/PrecacheOnly.d.ts.map +1 -0
  77. package/dist/lib/strategies/StaleWhileRevalidate.d.ts.map +1 -0
  78. package/dist/{strategies → lib/strategies}/Strategy.d.ts +1 -1
  79. package/dist/lib/strategies/Strategy.d.ts.map +1 -0
  80. package/dist/{strategies → lib/strategies}/StrategyHandler.d.ts +1 -1
  81. package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -0
  82. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
  83. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
  84. package/dist/lib/strategies/utils/messages.d.ts.map +1 -0
  85. package/dist/navigationPreload.d.ts +3 -3
  86. package/dist/parseRoute.d.ts +1 -1
  87. package/dist/parseRoute.d.ts.map +1 -1
  88. package/dist/types.d.ts +12 -7
  89. package/dist/types.d.ts.map +1 -1
  90. package/dist/utils/PrecacheCacheKeyPlugin.d.ts +1 -1
  91. package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -1
  92. package/dist/utils/assert.d.ts.map +1 -1
  93. package/package.json +7 -21
  94. package/src/NavigationRoute.ts +1 -1
  95. package/src/PrecacheRoute.ts +3 -3
  96. package/src/RegExpRoute.ts +2 -2
  97. package/src/Route.ts +2 -2
  98. package/src/Serwist.ts +69 -80
  99. package/src/cleanupOutdatedCaches.ts +1 -1
  100. package/src/disableDevLogs.ts +1 -1
  101. package/src/index.legacy.ts +16 -5
  102. package/src/index.ts +107 -14
  103. package/src/legacy/PrecacheController.ts +9 -9
  104. package/src/legacy/PrecacheFallbackPlugin.ts +1 -1
  105. package/src/legacy/PrecacheRoute.ts +3 -3
  106. package/src/legacy/Router.ts +5 -5
  107. package/src/legacy/fallbacks.ts +3 -3
  108. package/src/legacy/initializeGoogleAnalytics.ts +218 -0
  109. package/src/legacy/installSerwist.ts +156 -5
  110. package/src/legacy/registerRoute.ts +1 -1
  111. package/src/{plugins → lib}/backgroundSync/BackgroundSyncPlugin.ts +6 -6
  112. package/src/{plugins/backgroundSync/Queue.ts → lib/backgroundSync/BackgroundSyncQueue.ts} +47 -26
  113. package/src/{plugins/backgroundSync/QueueDb.ts → lib/backgroundSync/BackgroundSyncQueueDb.ts} +16 -16
  114. package/src/{plugins/backgroundSync/QueueStore.ts → lib/backgroundSync/BackgroundSyncQueueStore.ts} +13 -13
  115. package/src/{plugins → lib}/backgroundSync/StorableRequest.ts +2 -2
  116. package/src/{plugins → lib}/broadcastUpdate/BroadcastCacheUpdate.ts +14 -9
  117. package/src/{plugins → lib}/broadcastUpdate/BroadcastUpdatePlugin.ts +1 -1
  118. package/src/lib/broadcastUpdate/constants.ts +12 -0
  119. package/src/{plugins → lib}/broadcastUpdate/types.ts +3 -3
  120. package/src/{plugins → lib}/cacheableResponse/CacheableResponse.ts +5 -5
  121. package/src/{plugins → lib}/expiration/CacheExpiration.ts +7 -7
  122. package/src/{plugins → lib}/expiration/ExpirationPlugin.ts +10 -10
  123. package/src/lib/googleAnalytics/constants.ts +22 -0
  124. package/src/{plugins/googleAnalytics/initialize.ts → lib/googleAnalytics/initializeGoogleAnalytics.ts} +9 -9
  125. package/src/{strategies → lib/strategies}/CacheFirst.ts +4 -4
  126. package/src/{strategies → lib/strategies}/CacheOnly.ts +4 -4
  127. package/src/{strategies → lib/strategies}/NetworkFirst.ts +5 -5
  128. package/src/{strategies → lib/strategies}/NetworkOnly.ts +5 -5
  129. package/src/{PrecacheStrategy.ts → lib/strategies/PrecacheOnly.ts} +19 -15
  130. package/src/{strategies → lib/strategies}/StaleWhileRevalidate.ts +4 -4
  131. package/src/{strategies → lib/strategies}/Strategy.ts +5 -5
  132. package/src/{strategies → lib/strategies}/StrategyHandler.ts +11 -11
  133. package/src/{strategies → lib/strategies}/plugins/cacheOkAndOpaquePlugin.ts +1 -1
  134. package/src/{strategies → lib/strategies}/utils/messages.ts +2 -2
  135. package/src/models/messages/messages.ts +1 -1
  136. package/src/navigationPreload.ts +3 -3
  137. package/src/parseRoute.ts +3 -3
  138. package/src/registerQuotaErrorCallback.ts +1 -1
  139. package/src/types.ts +12 -7
  140. package/src/utils/PrecacheCacheKeyPlugin.ts +1 -1
  141. package/src/utils/assert.ts +1 -1
  142. package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
  143. package/src/utils/welcome.ts +1 -1
  144. package/dist/PrecacheStrategy.d.ts.map +0 -1
  145. package/dist/chunks/NetworkOnly.js +0 -599
  146. package/dist/chunks/PrecacheFallbackPlugin.js +0 -634
  147. package/dist/chunks/Serwist.js +0 -1034
  148. package/dist/chunks/registerQuotaErrorCallback.js +0 -17
  149. package/dist/chunks/timeout.js +0 -400
  150. package/dist/index.plugins.d.ts +0 -41
  151. package/dist/index.plugins.d.ts.map +0 -1
  152. package/dist/index.plugins.js +0 -669
  153. package/dist/index.strategies.d.ts +0 -22
  154. package/dist/index.strategies.d.ts.map +0 -1
  155. package/dist/index.strategies.js +0 -144
  156. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
  157. package/dist/plugins/backgroundSync/Queue.d.ts.map +0 -1
  158. package/dist/plugins/backgroundSync/QueueDb.d.ts.map +0 -1
  159. package/dist/plugins/backgroundSync/QueueStore.d.ts.map +0 -1
  160. package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +0 -1
  161. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
  162. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
  163. package/dist/plugins/broadcastUpdate/constants.d.ts +0 -5
  164. package/dist/plugins/broadcastUpdate/constants.d.ts.map +0 -1
  165. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
  166. package/dist/plugins/broadcastUpdate/types.d.ts.map +0 -1
  167. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +0 -1
  168. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
  169. package/dist/plugins/expiration/CacheExpiration.d.ts.map +0 -1
  170. package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +0 -1
  171. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +0 -1
  172. package/dist/plugins/googleAnalytics/constants.d.ts.map +0 -1
  173. package/dist/plugins/googleAnalytics/initialize.d.ts.map +0 -1
  174. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
  175. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
  176. package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +0 -1
  177. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
  178. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
  179. package/dist/strategies/CacheFirst.d.ts.map +0 -1
  180. package/dist/strategies/CacheOnly.d.ts.map +0 -1
  181. package/dist/strategies/NetworkFirst.d.ts.map +0 -1
  182. package/dist/strategies/NetworkOnly.d.ts.map +0 -1
  183. package/dist/strategies/StaleWhileRevalidate.d.ts.map +0 -1
  184. package/dist/strategies/Strategy.d.ts.map +0 -1
  185. package/dist/strategies/StrategyHandler.d.ts.map +0 -1
  186. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +0 -3
  187. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +0 -1
  188. package/dist/strategies/utils/messages.d.ts.map +0 -1
  189. package/src/index.plugins.ts +0 -95
  190. package/src/index.strategies.ts +0 -26
  191. package/src/plugins/broadcastUpdate/constants.ts +0 -12
  192. package/dist/{plugins/googleAnalytics → legacy}/constants.d.ts +0 -0
  193. package/dist/{plugins → lib}/backgroundSync/StorableRequest.d.ts +0 -0
  194. package/dist/{plugins → lib}/broadcastUpdate/BroadcastCacheUpdate.d.ts +0 -0
  195. package/dist/{plugins → lib}/broadcastUpdate/responsesAreSame.d.ts +0 -0
  196. package/dist/{plugins → lib}/cacheableResponse/CacheableResponse.d.ts +0 -0
  197. package/dist/{plugins → lib}/cacheableResponse/CacheableResponsePlugin.d.ts +0 -0
  198. package/dist/{plugins → lib}/expiration/models/CacheTimestampsModel.d.ts +0 -0
  199. package/dist/{plugins → lib}/rangeRequests/RangeRequestsPlugin.d.ts +0 -0
  200. package/dist/{plugins → lib}/rangeRequests/createPartialResponse.d.ts +0 -0
  201. package/dist/{plugins → lib}/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +0 -0
  202. package/dist/{plugins → lib}/rangeRequests/utils/parseRangeHeader.d.ts +0 -0
  203. package/dist/{strategies → lib/strategies}/CacheFirst.d.ts +0 -0
  204. package/dist/{strategies → lib/strategies}/CacheOnly.d.ts +0 -0
  205. package/dist/{strategies → lib/strategies}/NetworkFirst.d.ts +0 -0
  206. package/dist/{strategies → lib/strategies}/NetworkOnly.d.ts +0 -0
  207. package/dist/{strategies → lib/strategies}/StaleWhileRevalidate.d.ts +0 -0
  208. package/dist/{strategies → lib/strategies}/utils/messages.d.ts +0 -0
  209. package/src/{plugins/googleAnalytics → legacy}/constants.ts +0 -0
  210. package/src/{plugins → lib}/broadcastUpdate/responsesAreSame.ts +0 -0
  211. package/src/{plugins → lib}/cacheableResponse/CacheableResponsePlugin.ts +0 -0
  212. package/src/{plugins → lib}/expiration/models/CacheTimestampsModel.ts +0 -0
  213. package/src/{plugins → lib}/precaching/PrecacheFallbackPlugin.ts +1 -1
  214. package/src/{plugins → lib}/rangeRequests/RangeRequestsPlugin.ts +0 -0
  215. package/src/{plugins → lib}/rangeRequests/createPartialResponse.ts +1 -1
  216. package/src/{plugins → lib}/rangeRequests/utils/calculateEffectiveBoundaries.ts +1 -1
  217. package/src/{plugins → lib}/rangeRequests/utils/parseRangeHeader.ts +1 -1
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { assert } from "../utils/assert.js";
10
- import { SerwistError } from "../utils/SerwistError.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";
@@ -55,7 +55,7 @@ export class NetworkFirst extends Strategy {
55
55
  if (process.env.NODE_ENV !== "production") {
56
56
  if (this._networkTimeoutSeconds) {
57
57
  assert!.isType(this._networkTimeoutSeconds, "number", {
58
- moduleName: "serwist/strategies",
58
+ moduleName: "serwist",
59
59
  className: this.constructor.name,
60
60
  funcName: "constructor",
61
61
  paramName: "networkTimeoutSeconds",
@@ -75,7 +75,7 @@ export class NetworkFirst extends Strategy {
75
75
 
76
76
  if (process.env.NODE_ENV !== "production") {
77
77
  assert!.isInstance(request, Request, {
78
- moduleName: "serwist/strategies",
78
+ moduleName: "serwist",
79
79
  className: this.constructor.name,
80
80
  funcName: "handle",
81
81
  paramName: "makeRequest",
@@ -6,10 +6,10 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { assert } from "../utils/assert.js";
10
- import { SerwistError } from "../utils/SerwistError.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";
@@ -51,7 +51,7 @@ export class NetworkOnly extends Strategy {
51
51
  async _handle(request: Request, handler: StrategyHandler): Promise<Response> {
52
52
  if (process.env.NODE_ENV !== "production") {
53
53
  assert!.isInstance(request, Request, {
54
- moduleName: "serwist/strategies",
54
+ moduleName: "serwist",
55
55
  className: this.constructor.name,
56
56
  funcName: "_handle",
57
57
  paramName: "request",
@@ -6,15 +6,15 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { SerwistPlugin } from "./types.js";
10
- import { copyResponse } from "./copyResponse.js";
11
- import { SerwistError } from "./utils/SerwistError.js";
12
- import { getFriendlyURL } from "./utils/getFriendlyURL.js";
13
- import { logger } from "./utils/logger.js";
14
- import { cacheNames as privateCacheNames } from "./utils/cacheNames.js";
15
- import type { StrategyOptions } from "./strategies/Strategy.js";
16
- import { Strategy } from "./strategies/Strategy.js";
17
- import type { StrategyHandler } from "./strategies/StrategyHandler.js";
9
+ import { copyResponse } from "../../copyResponse.js";
10
+ import type { SerwistPlugin } 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 { StrategyOptions } from "./Strategy.js";
16
+ import { Strategy } from "./Strategy.js";
17
+ import type { StrategyHandler } from "./StrategyHandler.js";
18
18
 
19
19
  interface PrecacheStrategyOptions extends StrategyOptions {
20
20
  /**
@@ -29,9 +29,9 @@ interface PrecacheStrategyOptions extends StrategyOptions {
29
29
  * specifically designed to both cache and fetch precached assets.
30
30
  *
31
31
  * Note: an instance of this class is created automatically when creating a
32
- * `PrecacheController`; it's generally not necessary to create this yourself.
32
+ * `Serwist` instance; it's generally not necessary to create this yourself.
33
33
  */
34
- export class PrecacheStrategy extends Strategy {
34
+ export class PrecacheOnly extends Strategy {
35
35
  private readonly _fallbackToNetwork: boolean;
36
36
 
37
37
  static readonly defaultPrecacheCacheabilityPlugin: SerwistPlugin = {
@@ -55,6 +55,7 @@ export class PrecacheStrategy extends Strategy {
55
55
  */
56
56
  constructor(options: PrecacheStrategyOptions = {}) {
57
57
  options.cacheName = privateCacheNames.getPrecacheName(options.cacheName);
58
+
58
59
  super(options);
59
60
 
60
61
  this._fallbackToNetwork = options.fallbackToNetwork === false ? false : true;
@@ -63,7 +64,7 @@ export class PrecacheStrategy extends Strategy {
63
64
  // any redirected response must be "copied" rather than cloned, so the new
64
65
  // response doesn't contain the `redirected` flag. See:
65
66
  // https://bugs.chromium.org/p/chromium/issues/detail?id=669363&desc=2#c1
66
- this.plugins.push(PrecacheStrategy.copyRedirectedCacheableResponsesPlugin);
67
+ this.plugins.push(PrecacheOnly.copyRedirectedCacheableResponsesPlugin);
67
68
  }
68
69
 
69
70
  /**
@@ -74,6 +75,7 @@ export class PrecacheStrategy extends Strategy {
74
75
  */
75
76
  async _handle(request: Request, handler: StrategyHandler): Promise<Response> {
76
77
  const response = await handler.cacheMatch(request);
78
+
77
79
  if (response) {
78
80
  return response;
79
81
  }
@@ -91,6 +93,7 @@ export class PrecacheStrategy extends Strategy {
91
93
 
92
94
  async _handleFetch(request: Request, handler: StrategyHandler): Promise<Response> {
93
95
  let response: Response | undefined = undefined;
96
+
94
97
  const params = (handler.params || {}) as {
95
98
  cacheKey?: string;
96
99
  integrity?: string;
@@ -169,6 +172,7 @@ export class PrecacheStrategy extends Strategy {
169
172
  // Make sure we defer cachePut() until after we know the response
170
173
  // should be cached; see https://github.com/GoogleChrome/workbox/issues/2737
171
174
  const wasCached = await handler.cachePut(request, response.clone());
175
+
172
176
  if (!wasCached) {
173
177
  // Throwing here will lead to the `install` handler failing, which
174
178
  // we want to do if *any* of the responses aren't safe to cache.
@@ -214,12 +218,12 @@ export class PrecacheStrategy extends Strategy {
214
218
 
215
219
  for (const [index, plugin] of this.plugins.entries()) {
216
220
  // Ignore the copy redirected plugin when determining what to do.
217
- if (plugin === PrecacheStrategy.copyRedirectedCacheableResponsesPlugin) {
221
+ if (plugin === PrecacheOnly.copyRedirectedCacheableResponsesPlugin) {
218
222
  continue;
219
223
  }
220
224
 
221
225
  // Save the default plugin's index, in case it needs to be removed.
222
- if (plugin === PrecacheStrategy.defaultPrecacheCacheabilityPlugin) {
226
+ if (plugin === PrecacheOnly.defaultPrecacheCacheabilityPlugin) {
223
227
  defaultPluginIndex = index;
224
228
  }
225
229
 
@@ -229,7 +233,7 @@ export class PrecacheStrategy extends Strategy {
229
233
  }
230
234
 
231
235
  if (cacheWillUpdatePluginCount === 0) {
232
- this.plugins.push(PrecacheStrategy.defaultPrecacheCacheabilityPlugin);
236
+ this.plugins.push(PrecacheOnly.defaultPrecacheCacheabilityPlugin);
233
237
  } else if (cacheWillUpdatePluginCount > 1 && defaultPluginIndex !== null) {
234
238
  // Only remove the default plugin; multiple custom plugins are allowed.
235
239
  this.plugins.splice(defaultPluginIndex, 1);
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { assert } from "../utils/assert.js";
10
- import { SerwistError } from "../utils/SerwistError.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";
@@ -58,7 +58,7 @@ export class StaleWhileRevalidate extends Strategy {
58
58
 
59
59
  if (process.env.NODE_ENV !== "production") {
60
60
  assert!.isInstance(request, Request, {
61
- moduleName: "serwist/strategies",
61
+ moduleName: "serwist",
62
62
  className: this.constructor.name,
63
63
  funcName: "handle",
64
64
  paramName: "request",
@@ -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 { getFriendlyURL } from "../utils/getFriendlyURL.js";
12
- import { logger } from "../utils/logger.js";
13
- import { cacheNames as privateCacheNames } from "../utils/cacheNames.js";
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";
14
14
  import { StrategyHandler } from "./StrategyHandler.js";
15
15
 
16
16
  export interface StrategyOptions {
@@ -6,15 +6,15 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } from "../types.js";
10
- import { assert } from "../utils/assert.js";
11
- import { Deferred } from "../utils/Deferred.js";
12
- import { SerwistError } from "../utils/SerwistError.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";
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
18
  import type { Strategy } from "./Strategy.js";
19
19
 
20
20
  function toRequest(input: RequestInfo) {
@@ -78,13 +78,13 @@ export class StrategyHandler {
78
78
  ) {
79
79
  if (process.env.NODE_ENV !== "production") {
80
80
  assert!.isInstance(options.event, ExtendableEvent, {
81
- moduleName: "serwist/strategies",
81
+ moduleName: "serwist",
82
82
  className: "StrategyHandler",
83
83
  funcName: "constructor",
84
84
  paramName: "options.event",
85
85
  });
86
86
  assert!.isInstance(options.request, Request, {
87
- moduleName: "serwist/strategies",
87
+ moduleName: "serwist",
88
88
  className: "StrategyHandler",
89
89
  funcName: "constructor",
90
90
  paramName: "options.request",
@@ -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 { SerwistPlugin } from "../../../types.js";
10
10
 
11
11
  export const cacheOkAndOpaquePlugin: SerwistPlugin = {
12
12
  /**
@@ -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)}'`,
@@ -112,7 +112,7 @@ export const messages = {
112
112
  },
113
113
 
114
114
  "duplicate-queue-name": ({ name }) => {
115
- return `The Queue name '${name}' is already being used. All instances of backgroundSync.Queue must be given unique names.`;
115
+ return `The queue name '${name}' is already being used. All instances of 'serwist.BackgroundSyncQueue' must be given unique names.`;
116
116
  },
117
117
 
118
118
  "expired-test-without-max-age": ({ methodName, paramName }) => {
@@ -7,7 +7,7 @@ declare const self: ServiceWorkerGlobalScope;
7
7
  * navigation preloading.
8
8
  *
9
9
  * @returns
10
- * @see https://serwist.pages.dev/docs/sw/navigation-preloading/is-navigation-preload-supported
10
+ * @see https://serwist.pages.dev/docs/serwist/core/is-navigation-preload-supported
11
11
  */
12
12
  export const isNavigationPreloadSupported = (): boolean => {
13
13
  return Boolean(self.registration?.navigationPreload);
@@ -19,7 +19,7 @@ export const isNavigationPreloadSupported = (): boolean => {
19
19
  * @param headerValue Optional. Allows developers to override the value of
20
20
  * the `Service-Worker-Navigation-Preload` header which will be sent to the
21
21
  * server when making the navigation request.
22
- * @see https://serwist.pages.dev/docs/sw/navigation-preloading/enable-navigation-preload
22
+ * @see https://serwist.pages.dev/docs/serwist/core/enable-navigation-preload
23
23
  */
24
24
  export const enableNavigationPreload = (headerValue?: string): void => {
25
25
  if (isNavigationPreloadSupported()) {
@@ -47,7 +47,7 @@ export const enableNavigationPreload = (headerValue?: string): void => {
47
47
  /**
48
48
  * If the browser supports navigation preloading, then this will disable it.
49
49
  *
50
- * @see https://serwist.pages.dev/docs/sw/navigation-preloading/disable-navigation-preload
50
+ * @see https://serwist.pages.dev/docs/serwist/core/disable-navigation-preload
51
51
  */
52
52
  export const disableNavigationPreload = (): void => {
53
53
  if (isNavigationPreloadSupported()) {
package/src/parseRoute.ts CHANGED
@@ -1,9 +1,9 @@
1
- import type { RouteHandler, RouteMatchCallback } from "./types.js";
2
- import { SerwistError } from "./utils/SerwistError.js";
3
- import { logger } from "./utils/logger.js";
4
1
  import { RegExpRoute } from "./RegExpRoute.js";
5
2
  import { Route } from "./Route.js";
6
3
  import type { HTTPMethod } from "./constants.js";
4
+ import type { RouteHandler, RouteMatchCallback } from "./types.js";
5
+ import { SerwistError } from "./utils/SerwistError.js";
6
+ import { logger } from "./utils/logger.js";
7
7
 
8
8
  /**
9
9
  * Parses a `RegExp`, string, or function with a caching strategy into a `Route`. This is for
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
+ import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
9
10
  import { assert } from "./utils/assert.js";
10
11
  import { logger } from "./utils/logger.js";
11
- import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
12
12
 
13
13
  /**
14
14
  * Adds a function to the set of quotaErrorCallbacks that will be executed if
package/src/types.ts CHANGED
@@ -335,22 +335,27 @@ export declare interface PrecacheEntry {
335
335
 
336
336
  export interface PrecacheRouteOptions {
337
337
  /**
338
- * The `directoryIndex` will check cache entries for a URL ending with '/'
339
- * to see if there is a hit when appending the `directoryIndex` value.
338
+ * Tells Serwist to check the precache for an entry whose URL is the request URL appended
339
+ * with the specified value. Only applies if the request URL ends with "/".
340
+ *
341
+ * @default "index.html"
340
342
  */
341
343
  directoryIndex?: string | null;
342
344
  /**
343
- * An array of RegExp's to remove search params when looking for a cache match.
345
+ * An array of `RegExp` objects matching search params that should be removed when looking
346
+ * for a precache match.
344
347
  */
345
348
  ignoreURLParametersMatching?: RegExp[];
346
349
  /**
347
- * The `cleanURLs` option will check the cache for the URL with a `.html` added
348
- * to the end of the end.
350
+ * Tells Serwist to check the precache for an entry whose URL is the request URL appended
351
+ * with ".html".
352
+ *
353
+ * @default true
349
354
  */
350
355
  cleanURLs?: boolean;
351
356
  /**
352
- * This is a function that should take a URL and return an array of
353
- * alternative URLs that should be checked for precache matches.
357
+ * A function that should take a URL and return an array of alternative URLs that should
358
+ * be checked for precache matches.
354
359
  */
355
360
  urlManipulation?: UrlManipulation;
356
361
  }
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { SerwistPlugin, SerwistPluginCallbackParam } from "../types.js";
10
9
  import type { Serwist } from "../Serwist.js";
10
+ import type { SerwistPlugin, SerwistPluginCallbackParam } from "../types.js";
11
11
 
12
12
  /**
13
13
  * A plugin, designed to be used with PrecacheController, to translate URLs into
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "./SerwistError.js";
10
9
  import type { MapLikeObject } from "../types.js";
10
+ import { SerwistError } from "./SerwistError.js";
11
11
 
12
12
  /*
13
13
  * This method throws if the supplied value is not an array.
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { logger } from "./logger.js";
10
9
  import { quotaErrorCallbacks } from "../models/quotaErrorCallbacks.js";
10
+ import { logger } from "./logger.js";
11
11
 
12
12
  /**
13
13
  * Runs all of the callback functions, one at a time sequentially, in the order
@@ -14,6 +14,6 @@ if (process.env.NODE_ENV !== "production") {
14
14
  const padding = " ";
15
15
  logger.groupCollapsed("Welcome to Serwist!");
16
16
  logger.log(`📖 Read the guides and documentation\n${padding}https://serwist.pages.dev/`);
17
- logger.log(`🐛 Found a bug or want to ask a question? Open a new issue on GitLab\n${padding}https://gitlab.com/serwist/serwist/issues/new`);
17
+ logger.log(`🐛 Found a bug or want to ask a question? Open a new issue on GitHub\n${padding}https://github.com/serwist/serwist/issues/new/choose`);
18
18
  logger.groupEnd();
19
19
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"PrecacheStrategy.d.ts","sourceRoot":"","sources":["../src/PrecacheStrategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAMhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,UAAU,uBAAwB,SAAQ,eAAe;IACvD;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAU;IAE7C,MAAM,CAAC,QAAQ,CAAC,iCAAiC,EAAE,aAAa,CAQ9D;IAEF,MAAM,CAAC,QAAQ,CAAC,sCAAsC,EAAE,aAAa,CAInE;IAEF;;OAEG;gBACS,OAAO,GAAE,uBAA4B;IAajD;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiBtE,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAwE3E,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAoBnF;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,qCAAqC,IAAI,IAAI;CA4B9C"}