@serwist/sw 9.0.0-preview.20 → 9.0.0-preview.24

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 (249) hide show
  1. package/dist/index.d.ts +4 -11
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +2 -156
  4. package/package.json +5 -40
  5. package/src/index.ts +5 -22
  6. package/README.md +0 -1
  7. package/dist/abstractions/Serwist.d.ts +0 -82
  8. package/dist/abstractions/Serwist.d.ts.map +0 -1
  9. package/dist/abstractions/disableDevLogs.d.ts +0 -7
  10. package/dist/abstractions/disableDevLogs.d.ts.map +0 -1
  11. package/dist/abstractions/fallbacks.d.ts +0 -39
  12. package/dist/abstractions/fallbacks.d.ts.map +0 -1
  13. package/dist/abstractions/handlePrecaching.d.ts +0 -39
  14. package/dist/abstractions/handlePrecaching.d.ts.map +0 -1
  15. package/dist/abstractions/installSerwist.d.ts +0 -15
  16. package/dist/abstractions/installSerwist.d.ts.map +0 -1
  17. package/dist/abstractions/navigationPreload.d.ts +0 -20
  18. package/dist/abstractions/navigationPreload.d.ts.map +0 -1
  19. package/dist/abstractions/registerRuntimeCaching.d.ts +0 -11
  20. package/dist/abstractions/registerRuntimeCaching.d.ts.map +0 -1
  21. package/dist/abstractions/types.d.ts +0 -29
  22. package/dist/abstractions/types.d.ts.map +0 -1
  23. package/dist/chunks/NavigationRoute.js +0 -54
  24. package/dist/chunks/NetworkOnly.js +0 -193
  25. package/dist/chunks/PrecacheFallbackPlugin.js +0 -573
  26. package/dist/chunks/Strategy.js +0 -410
  27. package/dist/chunks/precacheAndRoute.js +0 -113
  28. package/dist/chunks/registerRoute.js +0 -7
  29. package/dist/chunks/singletonPrecacheController.js +0 -433
  30. package/dist/chunks/singletonRouter.js +0 -435
  31. package/dist/index.plugins.d.ts +0 -41
  32. package/dist/index.plugins.d.ts.map +0 -1
  33. package/dist/index.plugins.js +0 -671
  34. package/dist/index.precaching.d.ts +0 -25
  35. package/dist/index.precaching.d.ts.map +0 -1
  36. package/dist/index.precaching.js +0 -24
  37. package/dist/index.routing.d.ts +0 -15
  38. package/dist/index.routing.d.ts.map +0 -1
  39. package/dist/index.routing.js +0 -19
  40. package/dist/index.strategies.d.ts +0 -22
  41. package/dist/index.strategies.d.ts.map +0 -1
  42. package/dist/index.strategies.js +0 -146
  43. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +0 -23
  44. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
  45. package/dist/plugins/backgroundSync/Queue.d.ts +0 -166
  46. package/dist/plugins/backgroundSync/Queue.d.ts.map +0 -1
  47. package/dist/plugins/backgroundSync/QueueDb.d.ts +0 -90
  48. package/dist/plugins/backgroundSync/QueueDb.d.ts.map +0 -1
  49. package/dist/plugins/backgroundSync/QueueStore.d.ts +0 -75
  50. package/dist/plugins/backgroundSync/QueueStore.d.ts.map +0 -1
  51. package/dist/plugins/backgroundSync/StorableRequest.d.ts +0 -51
  52. package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +0 -1
  53. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +0 -45
  54. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
  55. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +0 -27
  56. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
  57. package/dist/plugins/broadcastUpdate/constants.d.ts +0 -5
  58. package/dist/plugins/broadcastUpdate/constants.d.ts.map +0 -1
  59. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +0 -11
  60. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
  61. package/dist/plugins/broadcastUpdate/types.d.ts +0 -34
  62. package/dist/plugins/broadcastUpdate/types.d.ts.map +0 -1
  63. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +0 -40
  64. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +0 -1
  65. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +0 -27
  66. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
  67. package/dist/plugins/expiration/CacheExpiration.d.ts +0 -66
  68. package/dist/plugins/expiration/CacheExpiration.d.ts.map +0 -1
  69. package/dist/plugins/expiration/ExpirationPlugin.d.ts +0 -116
  70. package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +0 -1
  71. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +0 -73
  72. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +0 -1
  73. package/dist/plugins/googleAnalytics/constants.d.ts +0 -10
  74. package/dist/plugins/googleAnalytics/constants.d.ts.map +0 -1
  75. package/dist/plugins/googleAnalytics/initialize.d.ts +0 -34
  76. package/dist/plugins/googleAnalytics/initialize.d.ts.map +0 -1
  77. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +0 -54
  78. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
  79. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +0 -19
  80. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
  81. package/dist/plugins/rangeRequests/createPartialResponse.d.ts +0 -18
  82. package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +0 -1
  83. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +0 -14
  84. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
  85. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +0 -12
  86. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
  87. package/dist/precaching/PrecacheController.d.ts +0 -145
  88. package/dist/precaching/PrecacheController.d.ts.map +0 -1
  89. package/dist/precaching/PrecacheRoute.d.ts +0 -20
  90. package/dist/precaching/PrecacheRoute.d.ts.map +0 -1
  91. package/dist/precaching/PrecacheStrategy.d.ts +0 -68
  92. package/dist/precaching/PrecacheStrategy.d.ts.map +0 -1
  93. package/dist/precaching/addPlugins.d.ts +0 -8
  94. package/dist/precaching/addPlugins.d.ts.map +0 -1
  95. package/dist/precaching/addRoute.d.ts +0 -15
  96. package/dist/precaching/addRoute.d.ts.map +0 -1
  97. package/dist/precaching/cleanupOutdatedCaches.d.ts +0 -6
  98. package/dist/precaching/cleanupOutdatedCaches.d.ts.map +0 -1
  99. package/dist/precaching/createHandlerBoundToURL.d.ts +0 -17
  100. package/dist/precaching/createHandlerBoundToURL.d.ts.map +0 -1
  101. package/dist/precaching/getCacheKeyForURL.d.ts +0 -20
  102. package/dist/precaching/getCacheKeyForURL.d.ts.map +0 -1
  103. package/dist/precaching/matchPrecache.d.ts +0 -14
  104. package/dist/precaching/matchPrecache.d.ts.map +0 -1
  105. package/dist/precaching/precache.d.ts +0 -19
  106. package/dist/precaching/precache.d.ts.map +0 -1
  107. package/dist/precaching/precacheAndRoute.d.ts +0 -14
  108. package/dist/precaching/precacheAndRoute.d.ts.map +0 -1
  109. package/dist/precaching/singletonPrecacheController.d.ts +0 -38
  110. package/dist/precaching/singletonPrecacheController.d.ts.map +0 -1
  111. package/dist/precaching/types.d.ts +0 -37
  112. package/dist/precaching/types.d.ts.map +0 -1
  113. package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts +0 -17
  114. package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
  115. package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts +0 -15
  116. package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
  117. package/dist/precaching/utils/createCacheKey.d.ts +0 -16
  118. package/dist/precaching/utils/createCacheKey.d.ts.map +0 -1
  119. package/dist/precaching/utils/deleteOutdatedCaches.d.ts +0 -18
  120. package/dist/precaching/utils/deleteOutdatedCaches.d.ts.map +0 -1
  121. package/dist/precaching/utils/generateURLVariations.d.ts +0 -12
  122. package/dist/precaching/utils/generateURLVariations.d.ts.map +0 -1
  123. package/dist/precaching/utils/getCacheKeyForURL.d.ts +0 -14
  124. package/dist/precaching/utils/getCacheKeyForURL.d.ts.map +0 -1
  125. package/dist/precaching/utils/printCleanupDetails.d.ts +0 -6
  126. package/dist/precaching/utils/printCleanupDetails.d.ts.map +0 -1
  127. package/dist/precaching/utils/printInstallDetails.d.ts +0 -7
  128. package/dist/precaching/utils/printInstallDetails.d.ts.map +0 -1
  129. package/dist/precaching/utils/removeIgnoredSearchParams.d.ts +0 -12
  130. package/dist/precaching/utils/removeIgnoredSearchParams.d.ts.map +0 -1
  131. package/dist/routing/NavigationRoute.d.ts +0 -57
  132. package/dist/routing/NavigationRoute.d.ts.map +0 -1
  133. package/dist/routing/RegExpRoute.d.ts +0 -24
  134. package/dist/routing/RegExpRoute.d.ts.map +0 -1
  135. package/dist/routing/Route.d.ts +0 -33
  136. package/dist/routing/Route.d.ts.map +0 -1
  137. package/dist/routing/Router.d.ts +0 -150
  138. package/dist/routing/Router.d.ts.map +0 -1
  139. package/dist/routing/parseRoute.d.ts +0 -16
  140. package/dist/routing/parseRoute.d.ts.map +0 -1
  141. package/dist/routing/registerRoute.d.ts +0 -15
  142. package/dist/routing/registerRoute.d.ts.map +0 -1
  143. package/dist/routing/setCatchHandler.d.ts +0 -9
  144. package/dist/routing/setCatchHandler.d.ts.map +0 -1
  145. package/dist/routing/setDefaultHandler.d.ts +0 -12
  146. package/dist/routing/setDefaultHandler.d.ts.map +0 -1
  147. package/dist/routing/singletonRouter.d.ts +0 -47
  148. package/dist/routing/singletonRouter.d.ts.map +0 -1
  149. package/dist/routing/unregisterRoute.d.ts +0 -8
  150. package/dist/routing/unregisterRoute.d.ts.map +0 -1
  151. package/dist/routing/utils/constants.d.ts +0 -15
  152. package/dist/routing/utils/constants.d.ts.map +0 -1
  153. package/dist/routing/utils/normalizeHandler.d.ts +0 -10
  154. package/dist/routing/utils/normalizeHandler.d.ts.map +0 -1
  155. package/dist/strategies/CacheFirst.d.ts +0 -23
  156. package/dist/strategies/CacheFirst.d.ts.map +0 -1
  157. package/dist/strategies/CacheOnly.d.ts +0 -20
  158. package/dist/strategies/CacheOnly.d.ts.map +0 -1
  159. package/dist/strategies/NetworkFirst.d.ts +0 -61
  160. package/dist/strategies/NetworkFirst.d.ts.map +0 -1
  161. package/dist/strategies/NetworkOnly.d.ts +0 -32
  162. package/dist/strategies/NetworkOnly.d.ts.map +0 -1
  163. package/dist/strategies/StaleWhileRevalidate.d.ts +0 -35
  164. package/dist/strategies/StaleWhileRevalidate.d.ts.map +0 -1
  165. package/dist/strategies/Strategy.d.ts +0 -83
  166. package/dist/strategies/Strategy.d.ts.map +0 -1
  167. package/dist/strategies/StrategyHandler.d.ts +0 -189
  168. package/dist/strategies/StrategyHandler.d.ts.map +0 -1
  169. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +0 -3
  170. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +0 -1
  171. package/dist/strategies/utils/messages.d.ts +0 -5
  172. package/dist/strategies/utils/messages.d.ts.map +0 -1
  173. package/src/abstractions/Serwist.ts +0 -177
  174. package/src/abstractions/disableDevLogs.ts +0 -10
  175. package/src/abstractions/fallbacks.ts +0 -65
  176. package/src/abstractions/handlePrecaching.ts +0 -65
  177. package/src/abstractions/installSerwist.ts +0 -28
  178. package/src/abstractions/navigationPreload.ts +0 -64
  179. package/src/abstractions/registerRuntimeCaching.ts +0 -17
  180. package/src/abstractions/types.ts +0 -29
  181. package/src/index.plugins.ts +0 -95
  182. package/src/index.precaching.ts +0 -41
  183. package/src/index.routing.ts +0 -28
  184. package/src/index.strategies.ts +0 -26
  185. package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +0 -39
  186. package/src/plugins/backgroundSync/Queue.ts +0 -438
  187. package/src/plugins/backgroundSync/QueueDb.ts +0 -176
  188. package/src/plugins/backgroundSync/QueueStore.ts +0 -161
  189. package/src/plugins/backgroundSync/StorableRequest.ts +0 -142
  190. package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +0 -159
  191. package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +0 -43
  192. package/src/plugins/broadcastUpdate/constants.ts +0 -12
  193. package/src/plugins/broadcastUpdate/responsesAreSame.ts +0 -48
  194. package/src/plugins/broadcastUpdate/types.ts +0 -37
  195. package/src/plugins/cacheableResponse/CacheableResponse.ts +0 -141
  196. package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +0 -46
  197. package/src/plugins/expiration/CacheExpiration.ts +0 -192
  198. package/src/plugins/expiration/ExpirationPlugin.ts +0 -297
  199. package/src/plugins/expiration/models/CacheTimestampsModel.ts +0 -184
  200. package/src/plugins/googleAnalytics/constants.ts +0 -22
  201. package/src/plugins/googleAnalytics/initialize.ts +0 -213
  202. package/src/plugins/precaching/PrecacheFallbackPlugin.ts +0 -86
  203. package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +0 -39
  204. package/src/plugins/rangeRequests/createPartialResponse.ts +0 -92
  205. package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +0 -58
  206. package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +0 -54
  207. package/src/precaching/PrecacheController.ts +0 -332
  208. package/src/precaching/PrecacheRoute.ts +0 -50
  209. package/src/precaching/PrecacheStrategy.ts +0 -238
  210. package/src/precaching/addPlugins.ts +0 -21
  211. package/src/precaching/addRoute.ts +0 -30
  212. package/src/precaching/cleanupOutdatedCaches.ts +0 -33
  213. package/src/precaching/createHandlerBoundToURL.ts +0 -30
  214. package/src/precaching/getCacheKeyForURL.ts +0 -33
  215. package/src/precaching/matchPrecache.ts +0 -25
  216. package/src/precaching/precache.ts +0 -31
  217. package/src/precaching/precacheAndRoute.ts +0 -27
  218. package/src/precaching/singletonPrecacheController.ts +0 -57
  219. package/src/precaching/types.ts +0 -46
  220. package/src/precaching/utils/PrecacheCacheKeyPlugin.ts +0 -36
  221. package/src/precaching/utils/PrecacheInstallReportPlugin.ts +0 -49
  222. package/src/precaching/utils/createCacheKey.ts +0 -68
  223. package/src/precaching/utils/deleteOutdatedCaches.ts +0 -40
  224. package/src/precaching/utils/generateURLVariations.ts +0 -55
  225. package/src/precaching/utils/getCacheKeyForURL.ts +0 -36
  226. package/src/precaching/utils/printCleanupDetails.ts +0 -38
  227. package/src/precaching/utils/printInstallDetails.ts +0 -53
  228. package/src/precaching/utils/removeIgnoredSearchParams.ts +0 -29
  229. package/src/routing/NavigationRoute.ts +0 -119
  230. package/src/routing/RegExpRoute.ts +0 -74
  231. package/src/routing/Route.ts +0 -68
  232. package/src/routing/Router.ts +0 -481
  233. package/src/routing/parseRoute.ts +0 -78
  234. package/src/routing/registerRoute.ts +0 -27
  235. package/src/routing/setCatchHandler.ts +0 -21
  236. package/src/routing/setDefaultHandler.ts +0 -24
  237. package/src/routing/singletonRouter.ts +0 -76
  238. package/src/routing/unregisterRoute.ts +0 -11
  239. package/src/routing/utils/constants.ts +0 -24
  240. package/src/routing/utils/normalizeHandler.ts +0 -40
  241. package/src/strategies/CacheFirst.ts +0 -87
  242. package/src/strategies/CacheOnly.ts +0 -58
  243. package/src/strategies/NetworkFirst.ts +0 -228
  244. package/src/strategies/NetworkOnly.ts +0 -96
  245. package/src/strategies/StaleWhileRevalidate.ts +0 -109
  246. package/src/strategies/Strategy.ts +0 -202
  247. package/src/strategies/StrategyHandler.ts +0 -557
  248. package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +0 -26
  249. package/src/strategies/utils/messages.ts +0 -20
@@ -1,61 +0,0 @@
1
- import type { StrategyOptions } from "./Strategy.js";
2
- import { Strategy } from "./Strategy.js";
3
- import type { StrategyHandler } from "./StrategyHandler.js";
4
- export interface NetworkFirstOptions extends StrategyOptions {
5
- /**
6
- * If set, any network requests that fail to respond within the timeout will fallback to the cache.
7
- */
8
- networkTimeoutSeconds?: number;
9
- }
10
- /**
11
- * An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
12
- * request strategy.
13
- *
14
- * By default, this strategy will cache responses with a 200 status code as
15
- * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
16
- * Opaque responses are are cross-origin requests where the response doesn't
17
- * support [CORS](https://enable-cors.org/).
18
- *
19
- * If the network request fails, and there is no cache match, this will throw
20
- * a `SerwistError` exception.
21
- */
22
- export declare class NetworkFirst extends Strategy {
23
- private readonly _networkTimeoutSeconds;
24
- /**
25
- * @param options
26
- * This option can be used to combat
27
- * "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
28
- * scenarios.
29
- */
30
- constructor(options?: NetworkFirstOptions);
31
- /**
32
- * @private
33
- * @param request A request to run this strategy for.
34
- * @param handler The event that triggered the request.
35
- * @returns
36
- */
37
- _handle(request: Request, handler: StrategyHandler): Promise<Response>;
38
- /**
39
- * @param options
40
- * @returns
41
- * @private
42
- */
43
- private _getTimeoutPromise;
44
- /**
45
- * @param options
46
- * @param options.timeoutId
47
- * @param options.request
48
- * @param options.logs A reference to the logs Array.
49
- * @param options.event
50
- * @returns
51
- *
52
- * @private
53
- */
54
- _getNetworkPromise({ timeoutId, request, logs, handler, }: {
55
- request: Request;
56
- logs: any[];
57
- timeoutId?: number;
58
- handler: StrategyHandler;
59
- }): Promise<Response | undefined>;
60
- }
61
- //# sourceMappingURL=NetworkFirst.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NetworkFirst.d.ts","sourceRoot":"","sources":["../../src/strategies/NetworkFirst.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAChD;;;;;OAKG;gBACS,OAAO,GAAE,mBAAwB;IAsB7C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgE5E;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;;;;;;;;OASG;IACG,kBAAkB,CAAC,EACvB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAqClC"}
@@ -1,32 +0,0 @@
1
- import type { StrategyOptions } from "./Strategy.js";
2
- import { Strategy } from "./Strategy.js";
3
- import type { StrategyHandler } from "./StrategyHandler.js";
4
- export interface NetworkOnlyOptions extends Omit<StrategyOptions, "cacheName" | "matchOptions"> {
5
- /**
6
- * If set, any network requests that fail to respond within the timeout will result in a network error.
7
- */
8
- networkTimeoutSeconds?: number;
9
- }
10
- /**
11
- * An implementation of the [network only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-only)
12
- * request strategy.
13
- *
14
- * This class is useful if you want to take advantage of any Serwist plugin.
15
- *
16
- * If the network request fails, this will throw a `SerwistError` exception.
17
- */
18
- export declare class NetworkOnly extends Strategy {
19
- private readonly _networkTimeoutSeconds;
20
- /**
21
- * @param options
22
- */
23
- constructor(options?: NetworkOnlyOptions);
24
- /**
25
- * @private
26
- * @param request A request to run this strategy for.
27
- * @param handler The event that triggered the request.
28
- * @returns
29
- */
30
- _handle(request: Request, handler: StrategyHandler): Promise<Response>;
31
- }
32
- //# sourceMappingURL=NetworkOnly.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"NetworkOnly.d.ts","sourceRoot":"","sources":["../../src/strategies/NetworkOnly.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D,MAAM,WAAW,kBAAmB,SAAQ,IAAI,CAAC,eAAe,EAAE,WAAW,GAAG,cAAc,CAAC;IAC7F;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;GAOG;AACH,qBAAa,WAAY,SAAQ,QAAQ;IACvC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAEhD;;OAEG;gBACS,OAAO,GAAE,kBAAuB;IAM5C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA+C7E"}
@@ -1,35 +0,0 @@
1
- import type { StrategyOptions } from "./Strategy.js";
2
- import { Strategy } from "./Strategy.js";
3
- import type { StrategyHandler } from "./StrategyHandler.js";
4
- /**
5
- * An implementation of the
6
- * [stale-while-revalidate](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#stale-while-revalidate)
7
- * request strategy.
8
- *
9
- * Resources are requested from both the cache and the network in parallel.
10
- * The strategy will respond with the cached version if available, otherwise
11
- * wait for the network response. The cache is updated with the network response
12
- * with each successful request.
13
- *
14
- * By default, this strategy will cache responses with a 200 status code as
15
- * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
16
- * Opaque responses are cross-origin requests where the response doesn't
17
- * support [CORS](https://enable-cors.org/).
18
- *
19
- * If the network request fails, and there is no cache match, this will throw
20
- * a `SerwistError` exception.
21
- */
22
- export declare class StaleWhileRevalidate extends Strategy {
23
- /**
24
- * @param options
25
- */
26
- constructor(options?: StrategyOptions);
27
- /**
28
- * @private
29
- * @param request A request to run this strategy for.
30
- * @param handler The event that triggered the request.
31
- * @returns
32
- */
33
- _handle(request: Request, handler: StrategyHandler): Promise<Response>;
34
- }
35
- //# sourceMappingURL=StaleWhileRevalidate.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StaleWhileRevalidate.d.ts","sourceRoot":"","sources":["../../src/strategies/StaleWhileRevalidate.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,oBAAqB,SAAQ,QAAQ;IAChD;;OAEG;gBACS,OAAO,GAAE,eAAoB;IAUzC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E"}
@@ -1,83 +0,0 @@
1
- import type { HandlerCallbackOptions, RouteHandlerObject, SerwistPlugin } from "@serwist/core";
2
- import { StrategyHandler } from "./StrategyHandler.js";
3
- export interface StrategyOptions {
4
- /**
5
- * Cache name to store and retrieve requests. Defaults to cache names provided by `@serwist/core`.
6
- */
7
- cacheName?: string;
8
- /**
9
- * [Plugins](https://developer.chrome.com/docs/workbox/using-plugins)
10
- * to use in conjunction with this caching strategy.
11
- */
12
- plugins?: SerwistPlugin[];
13
- /**
14
- * Values passed along to the [`init`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch#Parameters)
15
- * of [non-navigation](https://github.com/GoogleChrome/workbox/issues/1796) `fetch()` requests made by this strategy.
16
- */
17
- fetchOptions?: RequestInit;
18
- /**
19
- * The [`CacheQueryOptions`](https://w3c.github.io/ServiceWorker/#dictdef-cachequeryoptions)
20
- * for any `cache.match()` or `cache.put()` calls made by this strategy.
21
- */
22
- matchOptions?: CacheQueryOptions;
23
- }
24
- /**
25
- * Classes extending the `Strategy` based class should implement this method,
26
- * and leverage `@serwist/strategies`'s `StrategyHandler` arg to perform all
27
- * fetching and cache logic, which will ensure all relevant cache, cache options,
28
- * fetch options and plugins are used (per the current strategy instance).
29
- */
30
- export declare abstract class Strategy implements RouteHandlerObject {
31
- cacheName: string;
32
- plugins: SerwistPlugin[];
33
- fetchOptions?: RequestInit;
34
- matchOptions?: CacheQueryOptions;
35
- protected abstract _handle(request: Request, handler: StrategyHandler): Promise<Response | undefined>;
36
- /**
37
- * Creates a new instance of the strategy and sets all documented option
38
- * properties as public instance properties.
39
- *
40
- * Note: if a custom strategy class extends the base Strategy class and does
41
- * not need more than these properties, it does not need to define its own
42
- * constructor.
43
- *
44
- * @param options
45
- */
46
- constructor(options?: StrategyOptions);
47
- /**
48
- * Perform a request strategy and returns a `Promise` that will resolve with
49
- * a `Response`, invoking all relevant plugin callbacks.
50
- *
51
- * When a strategy instance is registered with a `@serwist/routing` Route, this method is automatically
52
- * called when the route matches.
53
- *
54
- * Alternatively, this method can be used in a standalone `FetchEvent`
55
- * listener by passing it to `event.respondWith()`.
56
- *
57
- * @param options A `FetchEvent` or an object with the properties listed below.
58
- * @param options.request A request to run this strategy for.
59
- * @param options.event The event associated with the request.
60
- * @param options.url
61
- * @param options.params
62
- */
63
- handle(options: FetchEvent | HandlerCallbackOptions): Promise<Response>;
64
- /**
65
- * Similar to `@serwist/strategies`'s `Strategy.handle`, but
66
- * instead of just returning a `Promise` that resolves to a `Response` it
67
- * it will return an tuple of `[response, done]` promises, where the former
68
- * (`response`) is equivalent to what `handle()` returns, and the latter is a
69
- * Promise that will resolve once any promises that were added to
70
- * `event.waitUntil()` as part of performing the strategy have completed.
71
- *
72
- * You can await the `done` promise to ensure any extra work performed by
73
- * the strategy (usually caching responses) completes successfully.
74
- *
75
- * @param options A `FetchEvent` or `HandlerCallbackOptions` object.
76
- * @returns A tuple of [response, done] promises that can be used to determine when the response resolves as
77
- * well as when the handler has completed all its work.
78
- */
79
- handleAll(options: FetchEvent | HandlerCallbackOptions): [Promise<Response>, Promise<void>];
80
- _getResponse(handler: StrategyHandler, request: Request, event: ExtendableEvent): Promise<Response>;
81
- _awaitComplete(responseDone: Promise<Response>, handler: StrategyHandler, request: Request, event: ExtendableEvent): Promise<void>;
82
- }
83
- //# sourceMappingURL=Strategy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Strategy.d.ts","sourceRoot":"","sources":["../../src/strategies/Strategy.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG/F,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEvD,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B;;;OAGG;IACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;CAClC;AAED;;;;;GAKG;AACH,8BAAsB,QAAS,YAAW,kBAAkB;IAC1D,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,YAAY,CAAC,EAAE,WAAW,CAAC;IAC3B,YAAY,CAAC,EAAE,iBAAiB,CAAC;IAEjC,SAAS,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAErG;;;;;;;;;OASG;gBACS,OAAO,GAAE,eAAoB;IAOzC;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAC,OAAO,EAAE,UAAU,GAAG,sBAAsB,GAAG,OAAO,CAAC,QAAQ,CAAC;IAKvE;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,OAAO,EAAE,UAAU,GAAG,sBAAsB,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAqBrF,YAAY,CAAC,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyCnG,cAAc,CAAC,YAAY,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;CAqCzI"}
@@ -1,189 +0,0 @@
1
- import type { HandlerCallbackOptions, MapLikeObject, SerwistPlugin, SerwistPluginCallbackParam } from "@serwist/core";
2
- import type { Strategy } from "./Strategy.js";
3
- /**
4
- * A class created every time a Strategy instance instance calls `Strategy.handle` or
5
- * `Strategy.handleAll` that wraps all fetch and cache actions around plugin callbacks
6
- * and keeps track of when the strategy is "done" (i.e. all added `event.waitUntil()` promises
7
- * have resolved).
8
- */
9
- export declare class StrategyHandler {
10
- /**
11
- * The event associated with this request.
12
- */
13
- event: ExtendableEvent;
14
- /**
15
- * The request the strategy is performing (passed to the strategy's
16
- * `handle()` or `handleAll()` method).
17
- */
18
- request: Request;
19
- /**
20
- * A `URL` instance of `request.url` (if passed to the strategy's
21
- * `handle()` or `handleAll()` method).
22
- * Note: the `url` param will be present if the strategy was invoked
23
- * from a `@serwist/routing.Route` object.
24
- */
25
- url?: URL;
26
- /**
27
- * A `param` value (if passed to the strategy's
28
- * `handle()` or `handleAll()` method).
29
- * Note: the `param` param will be present if the strategy was invoked
30
- * from a `@serwist/routing.Route` object and the `@serwist/strategies.matchCallback`
31
- * returned a truthy value (it will be that value).
32
- */
33
- params?: string[] | MapLikeObject;
34
- private _cacheKeys;
35
- private readonly _strategy;
36
- private readonly _handlerDeferred;
37
- private readonly _extendLifetimePromises;
38
- private readonly _plugins;
39
- private readonly _pluginStateMap;
40
- /**
41
- * Creates a new instance associated with the passed strategy and event
42
- * that's handling the request.
43
- *
44
- * The constructor also initializes the state that will be passed to each of
45
- * the plugins handling this request.
46
- *
47
- * @param strategy
48
- * @param options
49
- */
50
- constructor(strategy: Strategy, options: HandlerCallbackOptions & {
51
- request: HandlerCallbackOptions["request"] & Request;
52
- });
53
- /**
54
- * Fetches a given request (and invokes any applicable plugin callback
55
- * methods) using the `fetchOptions` (for non-navigation requests) and
56
- * `plugins` defined on the `Strategy` object.
57
- *
58
- * The following plugin lifecycle methods are invoked when using this method:
59
- * - `requestWillFetch()`
60
- * - `fetchDidSucceed()`
61
- * - `fetchDidFail()`
62
- *
63
- * @param input The URL or request to fetch.
64
- * @returns
65
- */
66
- fetch(input: RequestInfo): Promise<Response>;
67
- /**
68
- * Calls `this.fetch()` and (in the background) runs `this.cachePut()` on
69
- * the response generated by `this.fetch()`.
70
- *
71
- * The call to `this.cachePut()` automatically invokes `this.waitUntil()`,
72
- * so you do not have to manually call `waitUntil()` on the event.
73
- *
74
- * @param input The request or URL to fetch and cache.
75
- * @returns
76
- */
77
- fetchAndCachePut(input: RequestInfo): Promise<Response>;
78
- /**
79
- * Matches a request from the cache (and invokes any applicable plugin
80
- * callback methods) using the `cacheName`, `matchOptions`, and `plugins`
81
- * defined on the strategy object.
82
- *
83
- * The following plugin lifecycle methods are invoked when using this method:
84
- * - cacheKeyWillByUsed()
85
- * - cachedResponseWillByUsed()
86
- *
87
- * @param key The Request or URL to use as the cache key.
88
- * @returns A matching response, if found.
89
- */
90
- cacheMatch(key: RequestInfo): Promise<Response | undefined>;
91
- /**
92
- * Puts a request/response pair in the cache (and invokes any applicable
93
- * plugin callback methods) using the `cacheName` and `plugins` defined on
94
- * the strategy object.
95
- *
96
- * The following plugin lifecycle methods are invoked when using this method:
97
- * - cacheKeyWillByUsed()
98
- * - cacheWillUpdate()
99
- * - cacheDidUpdate()
100
- *
101
- * @param key The request or URL to use as the cache key.
102
- * @param response The response to cache.
103
- * @returns `false` if a cacheWillUpdate caused the response
104
- * not be cached, and `true` otherwise.
105
- */
106
- cachePut(key: RequestInfo, response: Response): Promise<boolean>;
107
- /**
108
- * Checks the list of plugins for the `cacheKeyWillBeUsed` callback, and
109
- * executes any of those callbacks found in sequence. The final `Request`
110
- * object returned by the last plugin is treated as the cache key for cache
111
- * reads and/or writes. If no `cacheKeyWillBeUsed` plugin callbacks have
112
- * been registered, the passed request is returned unmodified
113
- *
114
- * @param request
115
- * @param mode
116
- * @returns
117
- */
118
- getCacheKey(request: Request, mode: "read" | "write"): Promise<Request>;
119
- /**
120
- * Returns true if the strategy has at least one plugin with the given
121
- * callback.
122
- *
123
- * @param name The name of the callback to check for.
124
- * @returns
125
- */
126
- hasCallback<C extends keyof SerwistPlugin>(name: C): boolean;
127
- /**
128
- * Runs all plugin callbacks matching the given name, in order, passing the
129
- * given param object (merged ith the current plugin state) as the only
130
- * argument.
131
- *
132
- * Note: since this method runs all plugins, it's not suitable for cases
133
- * where the return value of a callback needs to be applied prior to calling
134
- * the next callback. See `@serwist/strategies.iterateCallbacks` for how to handle that case.
135
- *
136
- * @param name The name of the callback to run within each plugin.
137
- * @param param The object to pass as the first (and only) param when executing each callback. This object will be merged with the
138
- * current plugin state prior to callback execution.
139
- */
140
- runCallbacks<C extends keyof NonNullable<SerwistPlugin>>(name: C, param: Omit<SerwistPluginCallbackParam[C], "state">): Promise<void>;
141
- /**
142
- * Accepts a callback and returns an iterable of matching plugin callbacks,
143
- * where each callback is wrapped with the current handler state (i.e. when
144
- * you call each callback, whatever object parameter you pass it will
145
- * be merged with the plugin's current state).
146
- *
147
- * @param name The name fo the callback to run
148
- * @returns
149
- */
150
- iterateCallbacks<C extends keyof SerwistPlugin>(name: C): Generator<NonNullable<SerwistPlugin[C]>>;
151
- /**
152
- * Adds a promise to the
153
- * [extend lifetime promises](https://w3c.github.io/ServiceWorker/#extendableevent-extend-lifetime-promises)
154
- * of the event event associated with the request being handled (usually a `FetchEvent`).
155
- *
156
- * Note: you can await
157
- * `@serwist/strategies.StrategyHandler.doneWaiting`
158
- * to know when all added promises have settled.
159
- *
160
- * @param promise A promise to add to the extend lifetime promises of
161
- * the event that triggered the request.
162
- */
163
- waitUntil<T>(promise: Promise<T>): Promise<T>;
164
- /**
165
- * Returns a promise that resolves once all promises passed to
166
- * `@serwist/strategies.StrategyHandler.waitUntil` have settled.
167
- *
168
- * Note: any work done after `doneWaiting()` settles should be manually
169
- * passed to an event's `waitUntil()` method (not this handler's
170
- * `waitUntil()` method), otherwise the service worker thread my be killed
171
- * prior to your work completing.
172
- */
173
- doneWaiting(): Promise<void>;
174
- /**
175
- * Stops running the strategy and immediately resolves any pending
176
- * `waitUntil()` promises.
177
- */
178
- destroy(): void;
179
- /**
180
- * This method will call `cacheWillUpdate` on the available plugins (or use
181
- * status === 200) to determine if the response is safe and valid to cache.
182
- *
183
- * @param response
184
- * @returns
185
- * @private
186
- */
187
- _ensureResponseSafeToCache(response: Response): Promise<Response | undefined>;
188
- }
189
- //# sourceMappingURL=StrategyHandler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../../src/strategies/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAE,aAAa,EAAE,aAAa,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAYtH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C;;;;;GAKG;AACH,qBAAa,eAAe;IAC1B;;OAEG;IACI,KAAK,EAAE,eAAe,CAAC;IAC9B;;;OAGG;IACI,OAAO,EAAE,OAAO,CAAC;IACxB;;;;;OAKG;IACI,GAAG,CAAC,EAAE,GAAG,CAAC;IACjB;;;;;;OAMG;IACI,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,aAAa,CAAC;IAEzC,OAAO,CAAC,UAAU,CAA+B;IACjD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAgB;IACjD,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAiB;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkB;IAC3C,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAoC;IAEpE;;;;;;;;;OASG;gBAED,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,sBAAsB,GAAG;QAChC,OAAO,EAAE,sBAAsB,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC;KACtD;IAsCH;;;;;;;;;;;;OAYG;IACG,KAAK,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAyElD;;;;;;;;;OASG;IACG,gBAAgB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAS7D;;;;;;;;;;;OAWG;IACG,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IA+BjE;;;;;;;;;;;;;;OAcG;IACG,QAAQ,CAAC,GAAG,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IA8FtE;;;;;;;;;;OAUG;IACG,WAAW,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IAqB7E;;;;;;OAMG;IACH,WAAW,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,OAAO;IAS5D;;;;;;;;;;;;OAYG;IACG,YAAY,CAAC,CAAC,SAAS,MAAM,WAAW,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3I;;;;;;;;OAQG;IACF,gBAAgB,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAgBnG;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAK7C;;;;;;;;OAQG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC;;;OAGG;IACH,OAAO,IAAI,IAAI;IAIf;;;;;;;OAOG;IACG,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAuCpF"}
@@ -1,3 +0,0 @@
1
- import type { SerwistPlugin } from "@serwist/core";
2
- export declare const cacheOkAndOpaquePlugin: SerwistPlugin;
3
- //# sourceMappingURL=cacheOkAndOpaquePlugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cacheOkAndOpaquePlugin.d.ts","sourceRoot":"","sources":["../../../src/strategies/plugins/cacheOkAndOpaquePlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,eAAO,MAAM,sBAAsB,EAAE,aAepC,CAAC"}
@@ -1,5 +0,0 @@
1
- export declare const messages: {
2
- strategyStart: (strategyName: string, request: Request) => string;
3
- printFinalResponse: (response?: Response) => void;
4
- };
5
- //# sourceMappingURL=messages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/strategies/utils/messages.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,QAAQ;kCACW,MAAM,WAAW,OAAO,KAAG,MAAM;oCAC/B,QAAQ,KAAG,IAAI;CAOhD,CAAC"}
@@ -1,177 +0,0 @@
1
- import { clientsClaim as clientsClaimImpl, setCacheNameDetails } from "@serwist/core";
2
- import { type GoogleAnalyticsInitializeOptions, initialize } from "../plugins/googleAnalytics/initialize.js";
3
- import { PrecacheController } from "../precaching/PrecacheController.js";
4
- import { PrecacheRoute } from "../precaching/PrecacheRoute.js";
5
- import { cleanupOutdatedCaches as cleanupOutdatedCachesImpl } from "../precaching/cleanupOutdatedCaches.js";
6
- import { createHandlerBoundToURL } from "../precaching/createHandlerBoundToURL.js";
7
- import { getSingletonPrecacheController } from "../precaching/singletonPrecacheController.js";
8
- import { NavigationRoute } from "../routing/NavigationRoute.js";
9
- import { Router } from "../routing/Router.js";
10
- import { parseRoute } from "../routing/parseRoute.js";
11
- import { getSingletonRouter } from "../routing/singletonRouter.js";
12
- import { disableDevLogs as disableDevLogsImpl } from "./disableDevLogs.js";
13
- import { fallbacks as fallbacksImpl } from "./fallbacks.js";
14
- import type { FallbacksOptions } from "./fallbacks.js";
15
- import { type HandlePrecachingOptions } from "./handlePrecaching.js";
16
- import { enableNavigationPreload } from "./navigationPreload.js";
17
- import type { RuntimeCaching } from "./types.js";
18
-
19
- declare const self: ServiceWorkerGlobalScope;
20
-
21
- export interface SerwistOptions {
22
- /**
23
- * An optional `PrecacheController` instance. If not provided, the singleton
24
- * `PrecacheController` will be used.
25
- */
26
- precacheController?: PrecacheController;
27
- /**
28
- * An optional `Router` instance. If not provided, the singleton `Router`
29
- * will be used.
30
- */
31
- router?: Router;
32
- }
33
-
34
- export interface SerwistInstallOptions extends HandlePrecachingOptions {
35
- /**
36
- * Forces the waiting service worker to become the active one.
37
- *
38
- * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
39
- */
40
- skipWaiting?: boolean;
41
- /**
42
- * Imports external scripts. They are executed in the order they
43
- * are passed.
44
- *
45
- * @see https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
46
- */
47
- importScripts?: string[];
48
- /**
49
- * Enables navigation preloading if it is supported.
50
- *
51
- * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/navigationPreload
52
- */
53
- navigationPreload?: boolean;
54
- /**
55
- * Modifies the prefix of the default cache names used by Serwist packages.
56
- */
57
- cacheId?: string | undefined;
58
- /**
59
- * Claims any currently available clients once the service worker
60
- * becomes active. This is normally used in conjunction with `skipWaiting()`.
61
- *
62
- * @default false
63
- */
64
- clientsClaim?: boolean;
65
- /**
66
- * A list of caching strategies.
67
- *
68
- * @see https://serwist.pages.dev/docs/sw/runtime-caching
69
- */
70
- runtimeCaching?: RuntimeCaching[];
71
- /**
72
- * Your configuration for `@serwist/google-analytics`. This plugin is
73
- * only initialized when this option is not `undefined` or `false`.
74
- */
75
- offlineAnalyticsConfig?: GoogleAnalyticsInitializeOptions | boolean;
76
- /**
77
- * Disables Serwist's logging in development mode.
78
- *
79
- * @default false
80
- */
81
- disableDevLogs?: boolean;
82
- /**
83
- * Precaches routes so that they can be used as a fallback when
84
- * a Strategy fails to generate a response.
85
- * Note: This option mutates `runtimeCaching`!
86
- *
87
- * @see https://serwist.pages.dev/docs/sw/fallbacks
88
- */
89
- fallbacks?: Omit<FallbacksOptions, "runtimeCaching">;
90
- }
91
-
92
- export class Serwist {
93
- private _precacheController: PrecacheController;
94
- private _router: Router;
95
- constructor({ precacheController, router }: SerwistOptions = {}) {
96
- this._precacheController = precacheController || getSingletonPrecacheController();
97
- this._router = router || getSingletonRouter();
98
- }
99
- install({
100
- precacheEntries,
101
- precacheOptions,
102
- cleanupOutdatedCaches,
103
- navigateFallback,
104
- navigateFallbackAllowlist,
105
- navigateFallbackDenylist,
106
- skipWaiting = false,
107
- importScripts,
108
- navigationPreload = false,
109
- cacheId,
110
- clientsClaim = false,
111
- runtimeCaching,
112
- offlineAnalyticsConfig,
113
- disableDevLogs = false,
114
- fallbacks,
115
- }: SerwistInstallOptions = {}) {
116
- if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
117
-
118
- if (navigationPreload) enableNavigationPreload();
119
-
120
- if (cacheId !== undefined) {
121
- setCacheNameDetails({
122
- prefix: cacheId,
123
- });
124
- }
125
-
126
- if (skipWaiting) {
127
- self.skipWaiting();
128
- } else {
129
- self.addEventListener("message", (event) => {
130
- if (event.data && event.data.type === "SKIP_WAITING") {
131
- self.skipWaiting();
132
- }
133
- });
134
- }
135
-
136
- if (clientsClaim) clientsClaimImpl();
137
-
138
- if (!!precacheEntries && precacheEntries.length > 0) {
139
- /**
140
- * The precacheAndRoute() method efficiently caches and responds to
141
- * requests for URLs in the manifest.
142
- * See https://goo.gl/S9QRab
143
- */
144
- this._precacheController.precache(precacheEntries);
145
- this._router.registerRoute(new PrecacheRoute(this._precacheController, precacheOptions));
146
-
147
- if (cleanupOutdatedCaches) cleanupOutdatedCachesImpl();
148
-
149
- if (navigateFallback) {
150
- this._router.registerRoute(
151
- new NavigationRoute(createHandlerBoundToURL(navigateFallback), {
152
- allowlist: navigateFallbackAllowlist,
153
- denylist: navigateFallbackDenylist,
154
- }),
155
- );
156
- }
157
- }
158
-
159
- if (offlineAnalyticsConfig !== undefined) {
160
- if (typeof offlineAnalyticsConfig === "boolean") {
161
- offlineAnalyticsConfig && initialize();
162
- } else {
163
- initialize(offlineAnalyticsConfig);
164
- }
165
- }
166
- if (runtimeCaching !== undefined) {
167
- if (fallbacks !== undefined) {
168
- fallbacksImpl({ ...fallbacks, runtimeCaching });
169
- }
170
- for (const entry of runtimeCaching) {
171
- this._router.registerRoute(parseRoute(entry.matcher, entry.handler, entry.method));
172
- }
173
- }
174
-
175
- if (disableDevLogs) disableDevLogsImpl();
176
- }
177
- }
@@ -1,10 +0,0 @@
1
- declare const self: ServiceWorkerGlobalScope;
2
-
3
- /**
4
- * Disables Serwist's logging in development mode.
5
- *
6
- * @see https://serwist.pages.dev/docs/sw/disable-dev-logs
7
- */
8
- export const disableDevLogs = (): void => {
9
- self.__WB_DISABLE_DEV_LOGS = true;
10
- };