serwist 9.1.1 → 10.0.0-preview.10

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 (335) hide show
  1. package/dist/chunks/waitUntil.js +141 -134
  2. package/dist/index.d.ts +22 -49
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.internal.d.ts +16 -16
  5. package/dist/index.internal.d.ts.map +1 -1
  6. package/dist/index.internal.js +25 -3
  7. package/dist/index.js +2231 -452
  8. package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.d.ts +2 -2
  9. package/dist/lib/background-sync/BackgroundSyncPlugin.d.ts.map +1 -0
  10. package/dist/lib/background-sync/BackgroundSyncQueue.d.ts.map +1 -0
  11. package/dist/lib/background-sync/BackgroundSyncQueueDb.d.ts.map +1 -0
  12. package/dist/lib/background-sync/BackgroundSyncQueueStore.d.ts.map +1 -0
  13. package/dist/lib/{backgroundSync → background-sync}/StorableRequest.d.ts +1 -1
  14. package/dist/lib/background-sync/StorableRequest.d.ts.map +1 -0
  15. package/dist/lib/background-sync/index.d.ts +6 -0
  16. package/dist/lib/background-sync/index.d.ts.map +1 -0
  17. package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.d.ts +1 -1
  18. package/dist/lib/broadcast-update/BroadcastCacheUpdate.d.ts.map +1 -0
  19. package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.d.ts +2 -2
  20. package/dist/lib/broadcast-update/BroadcastUpdatePlugin.d.ts.map +1 -0
  21. package/dist/lib/broadcast-update/constants.d.ts.map +1 -0
  22. package/dist/lib/broadcast-update/index.d.ts +6 -0
  23. package/dist/lib/broadcast-update/index.d.ts.map +1 -0
  24. package/dist/lib/broadcast-update/responsesAreSame.d.ts.map +1 -0
  25. package/dist/lib/{broadcastUpdate → broadcast-update}/types.d.ts +1 -1
  26. package/dist/lib/broadcast-update/types.d.ts.map +1 -0
  27. package/dist/{cacheNames.d.ts → lib/cache-name.d.ts} +1 -1
  28. package/dist/lib/cache-name.d.ts.map +1 -0
  29. package/dist/lib/cacheable-response/CacheableResponse.d.ts.map +1 -0
  30. package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.d.ts +3 -3
  31. package/dist/lib/cacheable-response/CacheableResponsePlugin.d.ts.map +1 -0
  32. package/dist/lib/cacheable-response/index.d.ts +4 -0
  33. package/dist/lib/cacheable-response/index.d.ts.map +1 -0
  34. package/dist/{constants.d.ts → lib/constants.d.ts} +1 -1
  35. package/dist/lib/constants.d.ts.map +1 -0
  36. package/dist/lib/core.d.ts +62 -0
  37. package/dist/lib/core.d.ts.map +1 -0
  38. package/dist/lib/expiration/ExpirationPlugin.d.ts +2 -2
  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/extension.d.ts +30 -0
  43. package/dist/lib/extension.d.ts.map +1 -0
  44. package/dist/lib/extensions/google-analytics/constants.d.ts.map +1 -0
  45. package/dist/lib/extensions/google-analytics/extension.d.ts +79 -0
  46. package/dist/lib/extensions/google-analytics/extension.d.ts.map +1 -0
  47. package/dist/lib/extensions/google-analytics/index.d.ts +2 -0
  48. package/dist/lib/extensions/google-analytics/index.d.ts.map +1 -0
  49. package/dist/lib/extensions/google-analytics/initialize.d.ts +12 -0
  50. package/dist/lib/extensions/google-analytics/initialize.d.ts.map +1 -0
  51. package/dist/lib/extensions/index.d.ts +14 -0
  52. package/dist/lib/extensions/index.d.ts.map +1 -0
  53. package/dist/{legacy/PrecacheController.d.ts → lib/extensions/precache/extension.d.ts} +56 -66
  54. package/dist/lib/extensions/precache/extension.d.ts.map +1 -0
  55. package/dist/lib/extensions/precache/options.d.ts +26 -0
  56. package/dist/lib/extensions/precache/options.d.ts.map +1 -0
  57. package/dist/lib/extensions/precache/plugin-cache-key.d.ts +16 -0
  58. package/dist/lib/extensions/precache/plugin-cache-key.d.ts.map +1 -0
  59. package/dist/lib/{precaching/PrecacheFallbackPlugin.d.ts → extensions/precache/plugin-fallback.d.ts} +4 -4
  60. package/dist/lib/extensions/precache/plugin-fallback.d.ts.map +1 -0
  61. package/dist/lib/extensions/precache/plugin-install-report.d.ts +14 -0
  62. package/dist/lib/extensions/precache/plugin-install-report.d.ts.map +1 -0
  63. package/dist/lib/extensions/precache/route.d.ts +42 -0
  64. package/dist/lib/extensions/precache/route.d.ts.map +1 -0
  65. package/dist/lib/{strategies/PrecacheStrategy.d.ts → extensions/precache/strategy.d.ts} +7 -7
  66. package/dist/lib/extensions/precache/strategy.d.ts.map +1 -0
  67. package/dist/lib/extensions/runtime-cache.d.ts +71 -0
  68. package/dist/lib/extensions/runtime-cache.d.ts.map +1 -0
  69. package/dist/lib/functions/handlers.d.ts +60 -0
  70. package/dist/lib/functions/handlers.d.ts.map +1 -0
  71. package/dist/lib/functions/router.d.ts +60 -0
  72. package/dist/lib/functions/router.d.ts.map +1 -0
  73. package/dist/{navigationPreload.d.ts → lib/navigation-preload.d.ts} +1 -1
  74. package/dist/lib/navigation-preload.d.ts.map +1 -0
  75. package/dist/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.d.ts +3 -3
  76. package/dist/lib/range-requests/RangeRequestsPlugin.d.ts.map +1 -0
  77. package/dist/lib/range-requests/createPartialResponse.d.ts.map +1 -0
  78. package/dist/lib/range-requests/index.d.ts +3 -0
  79. package/dist/lib/range-requests/index.d.ts.map +1 -0
  80. package/dist/lib/range-requests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
  81. package/dist/lib/range-requests/utils/parseRangeHeader.d.ts.map +1 -0
  82. package/dist/lib/route.d.ts +106 -0
  83. package/dist/lib/route.d.ts.map +1 -0
  84. package/dist/{Serwist.d.ts → lib/serwist.d.ts} +71 -62
  85. package/dist/lib/serwist.d.ts.map +1 -0
  86. package/dist/lib/strategies/NetworkFirst.d.ts.map +1 -1
  87. package/dist/lib/strategies/StaleWhileRevalidate.d.ts.map +1 -1
  88. package/dist/lib/strategies/Strategy.d.ts +3 -3
  89. package/dist/lib/strategies/Strategy.d.ts.map +1 -1
  90. package/dist/lib/strategies/StrategyHandler.d.ts +4 -4
  91. package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
  92. package/dist/lib/strategies/index.d.ts +11 -0
  93. package/dist/lib/strategies/index.d.ts.map +1 -0
  94. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +2 -2
  95. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -1
  96. package/dist/{types.d.ts → lib/types.d.ts} +7 -65
  97. package/dist/lib/types.d.ts.map +1 -0
  98. package/dist/{copyResponse.d.ts → lib/utils.d.ts} +22 -1
  99. package/dist/lib/utils.d.ts.map +1 -0
  100. package/dist/models/messages/messageGenerator.d.ts +1 -1
  101. package/dist/models/messages/messageGenerator.d.ts.map +1 -1
  102. package/dist/utils/SerwistError.d.ts +2 -2
  103. package/dist/utils/SerwistError.d.ts.map +1 -1
  104. package/dist/utils/assert.d.ts +1 -1
  105. package/dist/utils/assert.d.ts.map +1 -1
  106. package/dist/utils/createCacheKey.d.ts +1 -1
  107. package/dist/utils/createCacheKey.d.ts.map +1 -1
  108. package/dist/utils/generateURLVariations.d.ts +1 -1
  109. package/dist/utils/generateURLVariations.d.ts.map +1 -1
  110. package/dist/utils/logger.d.ts +1 -1
  111. package/dist/utils/logger.d.ts.map +1 -1
  112. package/dist/utils/normalizeHandler.d.ts +1 -1
  113. package/dist/utils/normalizeHandler.d.ts.map +1 -1
  114. package/dist/utils/parseRoute.d.ts +3 -3
  115. package/dist/utils/parseRoute.d.ts.map +1 -1
  116. package/dist/utils/pluginUtils.d.ts +2 -2
  117. package/dist/utils/pluginUtils.d.ts.map +1 -1
  118. package/package.json +28 -11
  119. package/src/index.internal.ts +16 -16
  120. package/src/index.ts +100 -107
  121. package/src/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.ts +2 -2
  122. package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.ts +4 -4
  123. package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.ts +1 -1
  124. package/src/lib/{backgroundSync → background-sync}/StorableRequest.ts +2 -2
  125. package/src/lib/background-sync/index.ts +5 -0
  126. package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.ts +5 -5
  127. package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.ts +2 -2
  128. package/src/lib/broadcast-update/index.ts +5 -0
  129. package/src/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.ts +2 -2
  130. package/src/lib/{broadcastUpdate → broadcast-update}/types.ts +1 -1
  131. package/src/{cacheNames.ts → lib/cache-name.ts} +1 -1
  132. package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponse.ts +4 -4
  133. package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.ts +3 -3
  134. package/src/lib/cacheable-response/index.ts +3 -0
  135. package/src/lib/core.ts +128 -0
  136. package/src/lib/expiration/CacheExpiration.ts +3 -3
  137. package/src/lib/expiration/ExpirationPlugin.ts +9 -10
  138. package/src/lib/expiration/index.ts +3 -0
  139. package/src/lib/extension.ts +37 -0
  140. package/src/lib/{googleAnalytics/initializeGoogleAnalytics.ts → extensions/google-analytics/extension.ts} +42 -48
  141. package/src/lib/extensions/google-analytics/index.ts +0 -0
  142. package/src/lib/extensions/google-analytics/initialize.ts +48 -0
  143. package/src/lib/extensions/index.ts +13 -0
  144. package/src/lib/extensions/precache/extension.ts +306 -0
  145. package/src/lib/extensions/precache/options.ts +49 -0
  146. package/src/{legacy/utils/PrecacheCacheKeyPlugin.ts → lib/extensions/precache/plugin-cache-key.ts} +7 -8
  147. package/src/lib/{precaching/PrecacheFallbackPlugin.ts → extensions/precache/plugin-fallback.ts} +19 -8
  148. package/src/{utils/PrecacheInstallReportPlugin.ts → lib/extensions/precache/plugin-install-report.ts} +5 -5
  149. package/src/lib/extensions/precache/route.ts +72 -0
  150. package/src/lib/{strategies/PrecacheStrategy.ts → extensions/precache/strategy.ts} +12 -12
  151. package/src/lib/extensions/runtime-cache.ts +126 -0
  152. package/src/lib/functions/handlers.ts +149 -0
  153. package/src/lib/functions/router.ts +314 -0
  154. package/src/{navigationPreload.ts → lib/navigation-preload.ts} +1 -1
  155. package/src/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.ts +3 -3
  156. package/src/lib/{rangeRequests → range-requests}/createPartialResponse.ts +3 -3
  157. package/src/lib/range-requests/index.ts +2 -0
  158. package/src/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.ts +2 -2
  159. package/src/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.ts +2 -2
  160. package/src/lib/route.ts +234 -0
  161. package/src/lib/serwist.ts +443 -0
  162. package/src/lib/strategies/CacheFirst.ts +3 -3
  163. package/src/lib/strategies/CacheOnly.ts +3 -3
  164. package/src/lib/strategies/NetworkFirst.ts +4 -4
  165. package/src/lib/strategies/NetworkOnly.ts +4 -4
  166. package/src/lib/strategies/StaleWhileRevalidate.ts +4 -4
  167. package/src/lib/strategies/Strategy.ts +7 -7
  168. package/src/lib/strategies/StrategyHandler.ts +18 -18
  169. package/src/lib/strategies/index.ts +10 -0
  170. package/src/lib/strategies/plugins/cacheOkAndOpaquePlugin.ts +2 -2
  171. package/src/lib/strategies/utils/messages.ts +2 -2
  172. package/src/{types.ts → lib/types.ts} +17 -70
  173. package/src/lib/utils.ts +137 -0
  174. package/src/models/messages/messageGenerator.ts +1 -1
  175. package/src/models/messages/messages.ts +3 -3
  176. package/src/utils/SerwistError.ts +3 -3
  177. package/src/utils/assert.ts +1 -1
  178. package/src/utils/createCacheKey.ts +1 -2
  179. package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
  180. package/src/utils/generateURLVariations.ts +1 -1
  181. package/src/utils/logger.ts +1 -1
  182. package/src/utils/normalizeHandler.ts +1 -1
  183. package/src/utils/parseRoute.ts +4 -5
  184. package/src/utils/pluginUtils.ts +2 -2
  185. package/dist/NavigationRoute.d.ts +0 -56
  186. package/dist/NavigationRoute.d.ts.map +0 -1
  187. package/dist/PrecacheRoute.d.ts +0 -16
  188. package/dist/PrecacheRoute.d.ts.map +0 -1
  189. package/dist/RegExpRoute.d.ts +0 -24
  190. package/dist/RegExpRoute.d.ts.map +0 -1
  191. package/dist/Route.d.ts +0 -33
  192. package/dist/Route.d.ts.map +0 -1
  193. package/dist/Serwist.d.ts.map +0 -1
  194. package/dist/cacheNames.d.ts.map +0 -1
  195. package/dist/chunks/printInstallDetails.js +0 -1601
  196. package/dist/chunks/resultingClientExists.js +0 -32
  197. package/dist/constants.d.ts.map +0 -1
  198. package/dist/copyResponse.d.ts.map +0 -1
  199. package/dist/disableDevLogs.d.ts +0 -7
  200. package/dist/disableDevLogs.d.ts.map +0 -1
  201. package/dist/index.legacy.d.ts +0 -28
  202. package/dist/index.legacy.d.ts.map +0 -1
  203. package/dist/index.legacy.js +0 -790
  204. package/dist/legacy/PrecacheController.d.ts.map +0 -1
  205. package/dist/legacy/PrecacheFallbackPlugin.d.ts +0 -61
  206. package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +0 -1
  207. package/dist/legacy/PrecacheRoute.d.ts +0 -19
  208. package/dist/legacy/PrecacheRoute.d.ts.map +0 -1
  209. package/dist/legacy/Router.d.ts +0 -151
  210. package/dist/legacy/Router.d.ts.map +0 -1
  211. package/dist/legacy/addPlugins.d.ts +0 -9
  212. package/dist/legacy/addPlugins.d.ts.map +0 -1
  213. package/dist/legacy/addRoute.d.ts +0 -14
  214. package/dist/legacy/addRoute.d.ts.map +0 -1
  215. package/dist/legacy/constants.d.ts.map +0 -1
  216. package/dist/legacy/createHandlerBoundToURL.d.ts +0 -17
  217. package/dist/legacy/createHandlerBoundToURL.d.ts.map +0 -1
  218. package/dist/legacy/fallbacks.d.ts +0 -59
  219. package/dist/legacy/fallbacks.d.ts.map +0 -1
  220. package/dist/legacy/getCacheKeyForURL.d.ts +0 -20
  221. package/dist/legacy/getCacheKeyForURL.d.ts.map +0 -1
  222. package/dist/legacy/handlePrecaching.d.ts +0 -54
  223. package/dist/legacy/handlePrecaching.d.ts.map +0 -1
  224. package/dist/legacy/initializeGoogleAnalytics.d.ts +0 -38
  225. package/dist/legacy/initializeGoogleAnalytics.d.ts.map +0 -1
  226. package/dist/legacy/installSerwist.d.ts +0 -81
  227. package/dist/legacy/installSerwist.d.ts.map +0 -1
  228. package/dist/legacy/matchPrecache.d.ts +0 -15
  229. package/dist/legacy/matchPrecache.d.ts.map +0 -1
  230. package/dist/legacy/precache.d.ts +0 -20
  231. package/dist/legacy/precache.d.ts.map +0 -1
  232. package/dist/legacy/precacheAndRoute.d.ts +0 -14
  233. package/dist/legacy/precacheAndRoute.d.ts.map +0 -1
  234. package/dist/legacy/registerRoute.d.ts +0 -16
  235. package/dist/legacy/registerRoute.d.ts.map +0 -1
  236. package/dist/legacy/registerRuntimeCaching.d.ts +0 -11
  237. package/dist/legacy/registerRuntimeCaching.d.ts.map +0 -1
  238. package/dist/legacy/setCatchHandler.d.ts +0 -10
  239. package/dist/legacy/setCatchHandler.d.ts.map +0 -1
  240. package/dist/legacy/setDefaultHandler.d.ts +0 -13
  241. package/dist/legacy/setDefaultHandler.d.ts.map +0 -1
  242. package/dist/legacy/singletonPrecacheController.d.ts +0 -34
  243. package/dist/legacy/singletonPrecacheController.d.ts.map +0 -1
  244. package/dist/legacy/singletonRouter.d.ts +0 -41
  245. package/dist/legacy/singletonRouter.d.ts.map +0 -1
  246. package/dist/legacy/unregisterRoute.d.ts +0 -9
  247. package/dist/legacy/unregisterRoute.d.ts.map +0 -1
  248. package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts +0 -16
  249. package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
  250. package/dist/legacy/utils/getCacheKeyForURL.d.ts +0 -14
  251. package/dist/legacy/utils/getCacheKeyForURL.d.ts.map +0 -1
  252. package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
  253. package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts.map +0 -1
  254. package/dist/lib/backgroundSync/BackgroundSyncQueueDb.d.ts.map +0 -1
  255. package/dist/lib/backgroundSync/BackgroundSyncQueueStore.d.ts.map +0 -1
  256. package/dist/lib/backgroundSync/StorableRequest.d.ts.map +0 -1
  257. package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
  258. package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
  259. package/dist/lib/broadcastUpdate/constants.d.ts.map +0 -1
  260. package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
  261. package/dist/lib/broadcastUpdate/types.d.ts.map +0 -1
  262. package/dist/lib/cacheableResponse/CacheableResponse.d.ts.map +0 -1
  263. package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
  264. package/dist/lib/googleAnalytics/constants.d.ts +0 -10
  265. package/dist/lib/googleAnalytics/constants.d.ts.map +0 -1
  266. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts +0 -30
  267. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +0 -1
  268. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
  269. package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
  270. package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +0 -1
  271. package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
  272. package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
  273. package/dist/lib/strategies/PrecacheStrategy.d.ts.map +0 -1
  274. package/dist/navigationPreload.d.ts.map +0 -1
  275. package/dist/registerQuotaErrorCallback.d.ts +0 -8
  276. package/dist/registerQuotaErrorCallback.d.ts.map +0 -1
  277. package/dist/setCacheNameDetails.d.ts +0 -9
  278. package/dist/setCacheNameDetails.d.ts.map +0 -1
  279. package/dist/types.d.ts.map +0 -1
  280. package/dist/utils/PrecacheCacheKeyPlugin.d.ts +0 -16
  281. package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +0 -1
  282. package/dist/utils/PrecacheInstallReportPlugin.d.ts +0 -14
  283. package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +0 -1
  284. package/dist/utils/parsePrecacheOptions.d.ts +0 -26
  285. package/dist/utils/parsePrecacheOptions.d.ts.map +0 -1
  286. package/src/NavigationRoute.ts +0 -118
  287. package/src/PrecacheRoute.ts +0 -45
  288. package/src/RegExpRoute.ts +0 -74
  289. package/src/Route.ts +0 -67
  290. package/src/Serwist.ts +0 -867
  291. package/src/copyResponse.ts +0 -58
  292. package/src/disableDevLogs.ts +0 -10
  293. package/src/index.legacy.ts +0 -62
  294. package/src/legacy/PrecacheController.ts +0 -337
  295. package/src/legacy/PrecacheFallbackPlugin.ts +0 -92
  296. package/src/legacy/PrecacheRoute.ts +0 -48
  297. package/src/legacy/Router.ts +0 -484
  298. package/src/legacy/addPlugins.ts +0 -21
  299. package/src/legacy/addRoute.ts +0 -27
  300. package/src/legacy/createHandlerBoundToURL.ts +0 -30
  301. package/src/legacy/fallbacks.ts +0 -94
  302. package/src/legacy/getCacheKeyForURL.ts +0 -32
  303. package/src/legacy/handlePrecaching.ts +0 -86
  304. package/src/legacy/initializeGoogleAnalytics.ts +0 -218
  305. package/src/legacy/installSerwist.ts +0 -170
  306. package/src/legacy/matchPrecache.ts +0 -27
  307. package/src/legacy/precache.ts +0 -33
  308. package/src/legacy/precacheAndRoute.ts +0 -27
  309. package/src/legacy/registerRoute.ts +0 -28
  310. package/src/legacy/registerRuntimeCaching.ts +0 -17
  311. package/src/legacy/setCatchHandler.ts +0 -21
  312. package/src/legacy/setDefaultHandler.ts +0 -24
  313. package/src/legacy/singletonPrecacheController.ts +0 -53
  314. package/src/legacy/singletonRouter.ts +0 -70
  315. package/src/legacy/unregisterRoute.ts +0 -13
  316. package/src/legacy/utils/getCacheKeyForURL.ts +0 -36
  317. package/src/lib/googleAnalytics/constants.ts +0 -22
  318. package/src/registerQuotaErrorCallback.ts +0 -34
  319. package/src/setCacheNameDetails.ts +0 -53
  320. package/src/utils/PrecacheCacheKeyPlugin.ts +0 -33
  321. package/src/utils/parsePrecacheOptions.ts +0 -47
  322. /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.d.ts +0 -0
  323. /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.d.ts +0 -0
  324. /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.d.ts +0 -0
  325. /package/dist/lib/{broadcastUpdate → broadcast-update}/constants.d.ts +0 -0
  326. /package/dist/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.d.ts +0 -0
  327. /package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponse.d.ts +0 -0
  328. /package/dist/{legacy → lib/extensions/google-analytics}/constants.d.ts +0 -0
  329. /package/dist/lib/{rangeRequests → range-requests}/createPartialResponse.d.ts +0 -0
  330. /package/dist/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.d.ts +0 -0
  331. /package/dist/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.d.ts +0 -0
  332. /package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.ts +0 -0
  333. /package/src/lib/{broadcastUpdate → broadcast-update}/constants.ts +0 -0
  334. /package/src/{constants.ts → lib/constants.ts} +0 -0
  335. /package/src/{legacy → lib/extensions/google-analytics}/constants.ts +0 -0
@@ -0,0 +1,234 @@
1
+ /*
2
+ Copyright 2018 Google LLC
3
+
4
+ Use of this source code is governed by an MIT-style
5
+ license that can be found in the LICENSE file or at
6
+ https://opensource.org/licenses/MIT.
7
+ */
8
+ import { assert } from "#utils/assert.js";
9
+ import { logger } from "#utils/logger.js";
10
+ import { normalizeHandler } from "#utils/normalizeHandler.js";
11
+ import type { HTTPMethod } from "./constants.js";
12
+ import { defaultMethod, validMethods } from "./constants.js";
13
+ import type { RouteHandler, RouteHandlerObject, RouteMatchCallback, RouteMatchCallbackOptions } from "./types.js";
14
+
15
+ /**
16
+ * A `Route` consists of a pair of callback functions, `match` and `handler`.
17
+ * The `match` callback determines if a route should be used to handle a
18
+ * request by returning a truthy value if it can. The `handler` callback
19
+ * is called when the route matches and should return a promise that resolves
20
+ * to a response.
21
+ */
22
+ export class Route {
23
+ handler: RouteHandlerObject;
24
+ match: RouteMatchCallback;
25
+ method: HTTPMethod;
26
+ catchHandler?: RouteHandlerObject;
27
+
28
+ /**
29
+ * Constructor for Route class.
30
+ *
31
+ * @param match A callback function that determines whether the
32
+ * route matches a given `fetch` event by returning a truthy value.
33
+ * @param handler A callback function that returns a `Promise` resolving
34
+ * to a `Response`.
35
+ * @param method The HTTP method to match the route against. Defaults
36
+ * to `GET`.
37
+ */
38
+ constructor(match: RouteMatchCallback, handler: RouteHandler, method: HTTPMethod = defaultMethod) {
39
+ if (process.env.NODE_ENV !== "production") {
40
+ assert!.isType(match, "function", {
41
+ moduleName: "serwist",
42
+ className: "Route",
43
+ funcName: "constructor",
44
+ paramName: "match",
45
+ });
46
+
47
+ if (method) {
48
+ assert!.isOneOf(method, validMethods, { paramName: "method" });
49
+ }
50
+ }
51
+
52
+ // These values are referenced directly by Router so cannot be
53
+ // altered by minificaton.
54
+ this.handler = normalizeHandler(handler);
55
+ this.match = match;
56
+ this.method = method;
57
+ }
58
+
59
+ /**
60
+ *
61
+ * @param handler A callback function that returns a Promise resolving
62
+ * to a Response.
63
+ */
64
+ setCatchHandler(handler: RouteHandler): void {
65
+ this.catchHandler = normalizeHandler(handler);
66
+ }
67
+ }
68
+
69
+ /**
70
+ * A class that makes it easy to create a {@linkcode Route} object with a regular expression.
71
+ *
72
+ * For same-origin requests the `RegExp` only needs to match part of the URL. For
73
+ * requests against third-party servers, you must define a `RegExp` that matches
74
+ * the start of the URL.
75
+ */
76
+ export class RegExpRoute extends Route {
77
+ /**
78
+ * If the regular expression contains
79
+ * [capture groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references),
80
+ * the captured values will be passed to the `params` argument.
81
+ *
82
+ * @param regExp The regular expression to match against URLs.
83
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
84
+ * @param method The HTTP method to match the {@linkcode Route} against. Defaults to `GET`.
85
+ * against.
86
+ */
87
+ constructor(regExp: RegExp, handler: RouteHandler, method?: HTTPMethod) {
88
+ if (process.env.NODE_ENV !== "production") {
89
+ assert!.isInstance(regExp, RegExp, {
90
+ moduleName: "serwist",
91
+ className: "RegExpRoute",
92
+ funcName: "constructor",
93
+ paramName: "pattern",
94
+ });
95
+ }
96
+
97
+ const match: RouteMatchCallback = ({ url }: RouteMatchCallbackOptions) => {
98
+ const result = regExp.exec(url.href);
99
+
100
+ // Return immediately if there's no match.
101
+ if (!result) {
102
+ return;
103
+ }
104
+
105
+ // Require that the match start at the first character in the URL string
106
+ // if it's a cross-origin request.
107
+ // See https://github.com/GoogleChrome/workbox/issues/281 for the context
108
+ // behind this behavior.
109
+ if (url.origin !== location.origin && result.index !== 0) {
110
+ if (process.env.NODE_ENV !== "production") {
111
+ logger.debug(
112
+ `The regular expression '${regExp.toString()}' only partially matched against the cross-origin URL '${url.toString()}'. RegExpRoute's will only handle cross-origin requests if they match the entire URL.`,
113
+ );
114
+ }
115
+
116
+ return;
117
+ }
118
+
119
+ // If the route matches, but there aren't any capture groups defined, then
120
+ // this will return [], which is truthy and therefore sufficient to
121
+ // indicate a match.
122
+ // If there are capture groups, then it will return their values.
123
+ return result.slice(1);
124
+ };
125
+
126
+ super(match, handler, method);
127
+ }
128
+ }
129
+
130
+ export interface NavigationRouteMatchOptions {
131
+ /**
132
+ * If any of these patterns
133
+ * match the URL's pathname and search parameter, the route will handle the
134
+ * request (assuming the denylist doesn't match).
135
+ *
136
+ * @default [/./]
137
+ */
138
+ allowlist?: RegExp[];
139
+ /**
140
+ * If any of these patterns match, the route will not handle the request (even if a allowlist RegExp matches).
141
+ */
142
+ denylist?: RegExp[];
143
+ }
144
+
145
+ /**
146
+ * A class that makes it easy to create a {@linkcode Route} object that matches navigation requests.
147
+ *
148
+ * It will only match incoming requests whose [`mode`](https://fetch.spec.whatwg.org/#concept-request-mode) is set to `"navigate"`.
149
+ *
150
+ * You can optionally only apply this route to a subset of navigation requests
151
+ * by using one or both of the `denylist` and `allowlist` parameters.
152
+ */
153
+ export class NavigationRoute extends Route {
154
+ private readonly _allowlist: RegExp[];
155
+ private readonly _denylist: RegExp[];
156
+
157
+ /**
158
+ * If both `denylist` and `allowlist` are provided, `denylist` will
159
+ * take precedence.
160
+ *
161
+ * The regular expressions in `allowlist` and `denylist`
162
+ * are matched against the concatenated
163
+ * [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname)
164
+ * and [`search`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search)
165
+ * portions of the requested URL.
166
+ *
167
+ * *Note*: These RegExps may be evaluated against every destination URL during
168
+ * a navigation. Avoid using
169
+ * [complex RegExps](https://github.com/GoogleChrome/workbox/issues/3077),
170
+ * or else your users may see delays when navigating your site.
171
+ *
172
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
173
+ * @param options
174
+ */
175
+ constructor(handler: RouteHandler, { allowlist = [/./], denylist = [] }: NavigationRouteMatchOptions = {}) {
176
+ if (process.env.NODE_ENV !== "production") {
177
+ assert!.isArrayOfClass(allowlist, RegExp, {
178
+ moduleName: "serwist",
179
+ className: "NavigationRoute",
180
+ funcName: "constructor",
181
+ paramName: "options.allowlist",
182
+ });
183
+ assert!.isArrayOfClass(denylist, RegExp, {
184
+ moduleName: "serwist",
185
+ className: "NavigationRoute",
186
+ funcName: "constructor",
187
+ paramName: "options.denylist",
188
+ });
189
+ }
190
+
191
+ super((options: RouteMatchCallbackOptions) => this._match(options), handler);
192
+
193
+ this._allowlist = allowlist;
194
+ this._denylist = denylist;
195
+ }
196
+
197
+ /**
198
+ * Routes match handler.
199
+ *
200
+ * @param options
201
+ * @returns
202
+ * @private
203
+ */
204
+ private _match({ url, request }: RouteMatchCallbackOptions): boolean {
205
+ if (request && request.mode !== "navigate") {
206
+ return false;
207
+ }
208
+
209
+ const pathnameAndSearch = url.pathname + url.search;
210
+
211
+ for (const regExp of this._denylist) {
212
+ if (regExp.test(pathnameAndSearch)) {
213
+ if (process.env.NODE_ENV !== "production") {
214
+ logger.log(
215
+ `The navigation route ${pathnameAndSearch} is not being used, since the URL matches this denylist pattern: ${regExp.toString()}`,
216
+ );
217
+ }
218
+ return false;
219
+ }
220
+ }
221
+
222
+ if (this._allowlist.some((regExp) => regExp.test(pathnameAndSearch))) {
223
+ if (process.env.NODE_ENV !== "production") {
224
+ logger.debug(`The navigation route ${pathnameAndSearch} is being used.`);
225
+ }
226
+ return true;
227
+ }
228
+
229
+ if (process.env.NODE_ENV !== "production") {
230
+ logger.log(`The navigation route ${pathnameAndSearch} is not being used, since the URL being navigated to doesn't match the allowlist.`);
231
+ }
232
+ return false;
233
+ }
234
+ }
@@ -0,0 +1,443 @@
1
+ import { createSerwist, type Serwist as SerwistState } from "#lib/core.js";
2
+ import type { GoogleAnalyticsOptions, Precache, PrecacheFallbackEntry, PrecacheOptions } from "#lib/extensions/index.js";
3
+ import { GoogleAnalytics, RuntimeCache } from "#lib/extensions/index.js";
4
+ import {
5
+ createActivateHandler,
6
+ createCacheHandler,
7
+ createFetchHandler,
8
+ createInstallHandler,
9
+ setCatchHandler,
10
+ setDefaultHandler,
11
+ } from "#lib/functions/handlers.js";
12
+ import { findMatchingRoute, handleRequest, registerCapture, registerRoute, unregisterRoute } from "#lib/functions/router.js";
13
+ import type { Strategy } from "#lib/strategies/Strategy.js";
14
+ import type { HTTPMethod } from "./constants.js";
15
+ import type { Extension } from "./extension.js";
16
+ import type { Route } from "./route.js";
17
+ import type {
18
+ PrecacheEntry,
19
+ RouteHandler,
20
+ RouteHandlerCallback,
21
+ RouteHandlerCallbackOptions,
22
+ RouteMatchCallback,
23
+ RouteMatchCallbackOptions,
24
+ RuntimeCaching,
25
+ } from "./types.js";
26
+
27
+ declare const self: ServiceWorkerGlobalScope;
28
+
29
+ export interface FallbackEntry extends PrecacheFallbackEntry {}
30
+
31
+ export interface FallbacksOptions {
32
+ /**
33
+ * A list of fallback entries.
34
+ */
35
+ entries: FallbackEntry[];
36
+ }
37
+
38
+ /**
39
+ * @deprecated Legacy `Serwist` class. Please migrate to `createSerwist`.
40
+ */
41
+ export interface SerwistOptions {
42
+ /**
43
+ * A list of URLs that should be cached.
44
+ */
45
+ precacheEntries?: (PrecacheEntry | string)[];
46
+ /**
47
+ * Options to customize how Serwist precaches the URLs in the precache list.
48
+ */
49
+ precacheOptions?: Omit<PrecacheOptions, "entries">;
50
+ /**
51
+ * Forces the waiting service worker to become the active one.
52
+ *
53
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerGlobalScope/skipWaiting
54
+ */
55
+ skipWaiting?: boolean;
56
+ /**
57
+ * Imports external scripts. They are executed in the order they
58
+ * are passed.
59
+ *
60
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
61
+ */
62
+ importScripts?: string[];
63
+ /**
64
+ * Enables navigation preloading if it is supported.
65
+ *
66
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/navigationPreload
67
+ */
68
+ navigationPreload?: boolean;
69
+ /**
70
+ * Modifies the prefix of the default cache names used by Serwist packages.
71
+ */
72
+ cacheId?: string | undefined;
73
+ /**
74
+ * Claims any currently available clients once the service worker
75
+ * becomes active. This is normally used in conjunction with `skipWaiting()`.
76
+ *
77
+ * @default false
78
+ */
79
+ clientsClaim?: boolean;
80
+ /**
81
+ * A list of caching strategies.
82
+ */
83
+ runtimeCaching?: RuntimeCaching[];
84
+ /**
85
+ * Your configuration for {@linkcode GoogleAnalytics}. This plugin is
86
+ * only initialized when this option is not `undefined` or `false`.
87
+ */
88
+ offlineAnalyticsConfig?: GoogleAnalyticsOptions | boolean;
89
+ /**
90
+ * Disables Serwist's logging in development mode.
91
+ *
92
+ * @default false
93
+ */
94
+ disableDevLogs?: boolean;
95
+ /**
96
+ * Precaches routes so that they can be used as a fallback when
97
+ * a {@linkcode Strategy} fails to generate a response.
98
+ *
99
+ * Note: This option mutates `runtimeCaching`. It also expects the URLs
100
+ * defined in `entries` to have been precached beforehand.
101
+ */
102
+ fallbacks?: FallbacksOptions;
103
+ /**
104
+ * A list of extensions.
105
+ */
106
+ extensions?: Extension[];
107
+ }
108
+
109
+ /**
110
+ * A class that helps bootstrap the service worker.
111
+ *
112
+ * @deprecated Legacy `Serwist` class. Please migrate to `createSerwist`.
113
+ * @see https://serwist.pages.dev/docs/serwist/core/serwist
114
+ */
115
+ export class Serwist {
116
+ private readonly _state: SerwistState;
117
+ private readonly _installHandler: (event: ExtendableEvent) => Promise<void>;
118
+ private readonly _activateHandler: (event: ExtendableEvent) => Promise<void>;
119
+ private readonly _fetchHandler: (event: FetchEvent) => void;
120
+ private readonly _cacheHandler: (event: ExtendableMessageEvent) => void;
121
+
122
+ constructor({
123
+ precacheEntries,
124
+ precacheOptions,
125
+ skipWaiting = false,
126
+ importScripts,
127
+ navigationPreload = false,
128
+ cacheId,
129
+ clientsClaim = false,
130
+ runtimeCaching,
131
+ offlineAnalyticsConfig,
132
+ disableDevLogs = false,
133
+ fallbacks,
134
+ extensions,
135
+ }: SerwistOptions = {}) {
136
+ this.handleInstall = this.handleInstall.bind(this);
137
+ this.handleActivate = this.handleActivate.bind(this);
138
+ this.handleFetch = this.handleFetch.bind(this);
139
+ this.handleCache = this.handleCache.bind(this);
140
+
141
+ this._state = createSerwist({
142
+ precache: { entries: precacheEntries ?? [], ...precacheOptions },
143
+ extensions: [
144
+ !extensions?.some((ext) => ext instanceof RuntimeCache) && runtimeCaching !== undefined
145
+ ? new RuntimeCache(runtimeCaching, { fallbacks })
146
+ : undefined,
147
+ !extensions?.some((ext) => ext instanceof GoogleAnalytics) && offlineAnalyticsConfig !== undefined
148
+ ? typeof offlineAnalyticsConfig === "boolean"
149
+ ? offlineAnalyticsConfig
150
+ ? new GoogleAnalytics()
151
+ : undefined
152
+ : new GoogleAnalytics(offlineAnalyticsConfig)
153
+ : undefined,
154
+ ...(extensions ?? []),
155
+ ].filter((extension) => extension !== undefined),
156
+ skipWaiting,
157
+ importScripts,
158
+ navigationPreload,
159
+ cacheId,
160
+ clientsClaim,
161
+ disableDevLogs,
162
+ });
163
+
164
+ this._installHandler = createInstallHandler(this._state);
165
+ this._activateHandler = createActivateHandler(this._state);
166
+ this._fetchHandler = createFetchHandler(this._state);
167
+ this._cacheHandler = createCacheHandler(this._state);
168
+ }
169
+
170
+ /**
171
+ * The {@linkcode Precache} used to handle precaching.
172
+ */
173
+ get precache(): Precache {
174
+ return this._state.precache;
175
+ }
176
+
177
+ /**
178
+ * The strategy used to precache assets and respond to `fetch` events.
179
+ */
180
+ get precacheStrategy(): Strategy {
181
+ return this._state.precache.strategy;
182
+ }
183
+
184
+ /**
185
+ * A `Map` of HTTP method name (`'GET'`, etc.) to an array of all corresponding registered {@linkcode Route}
186
+ * instances.
187
+ */
188
+ get routes(): Map<HTTPMethod, Route[]> {
189
+ return this._state.routes;
190
+ }
191
+
192
+ get state(): SerwistState {
193
+ return this._state;
194
+ }
195
+
196
+ /**
197
+ * Adds Serwist's event listeners. Before calling it, add your own listeners should you need to.
198
+ */
199
+ addEventListeners() {
200
+ self.addEventListener("install", this._installHandler);
201
+ self.addEventListener("activate", this._activateHandler);
202
+ self.addEventListener("fetch", this._fetchHandler);
203
+ self.addEventListener("message", this._cacheHandler);
204
+ }
205
+
206
+ /**
207
+ * Precaches new and updated assets. Call this method from the service worker's
208
+ * `install` event.
209
+ *
210
+ * Note: this method calls `event.waitUntil()` for you, so you do not need
211
+ * to call it yourself in your event handlers.
212
+ *
213
+ * @param event
214
+ * @returns
215
+ */
216
+ handleInstall(event: ExtendableEvent): Promise<void> {
217
+ return this._installHandler(event);
218
+ }
219
+
220
+ /**
221
+ * Deletes assets that are no longer present in the current precache manifest.
222
+ * Call this method from the service worker's `activate` event.
223
+ *
224
+ * Note: this method calls `event.waitUntil()` for you, so you do not need
225
+ * to call it yourself in your event handlers.
226
+ *
227
+ * @param event
228
+ * @returns
229
+ */
230
+ handleActivate(event: ExtendableEvent): Promise<void> {
231
+ return this._activateHandler(event);
232
+ }
233
+
234
+ /**
235
+ * Gets a `Response` from an appropriate `Route`'s handler. Call this method
236
+ * from the service worker's `fetch` event.
237
+ * @param event
238
+ */
239
+ handleFetch(event: FetchEvent) {
240
+ return this._fetchHandler(event);
241
+ }
242
+
243
+ /**
244
+ * Caches new URLs on demand. Call this method from the service worker's
245
+ * `message` event. To trigger the handler, send a message of type `"CACHE_URLS"`
246
+ * alongside a list of URLs that should be cached as `urlsToCache`.
247
+ * @param event
248
+ */
249
+ handleCache(event: ExtendableMessageEvent) {
250
+ return this._cacheHandler(event);
251
+ }
252
+
253
+ /**
254
+ * Define a default handler that's called when no routes explicitly
255
+ * match the incoming request.
256
+ *
257
+ * Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
258
+ *
259
+ * Without a default handler, unmatched requests will go against the
260
+ * network as if there were no service worker present.
261
+ *
262
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
263
+ * @param method The HTTP method to associate with this default handler. Each method
264
+ * has its own default. Defaults to `'GET'`.
265
+ */
266
+ setDefaultHandler(handler: RouteHandler, method?: HTTPMethod): void {
267
+ setDefaultHandler(this._state, handler, method);
268
+ }
269
+
270
+ /**
271
+ * If a {@linkcode Route} throws an error while handling a request, this handler
272
+ * will be called and given a chance to provide a response.
273
+ *
274
+ * @param handler A callback function that returns a `Promise` resulting
275
+ * in a `Response`.
276
+ */
277
+ setCatchHandler(handler: RouteHandler): void {
278
+ setCatchHandler(this._state, handler);
279
+ }
280
+
281
+ /**
282
+ * Registers a `RegExp`, string, or function with a caching
283
+ * strategy to the router.
284
+ *
285
+ * @param capture If the capture param is a {@linkcode Route} object, all other arguments will be ignored.
286
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
287
+ * This parameter is required if `capture` is not a {@linkcode Route} object.
288
+ * @param method The HTTP method to match the route against. Defaults to `'GET'`.
289
+ * @returns The generated {@linkcode Route} object.
290
+ */
291
+ registerCapture<T extends RegExp | string | RouteMatchCallback | Route>(
292
+ capture: T,
293
+ handler?: T extends Route ? never : RouteHandler,
294
+ method?: T extends Route ? never : HTTPMethod,
295
+ ): Route {
296
+ return registerCapture(this._state, capture, handler, method);
297
+ }
298
+
299
+ /**
300
+ * Registers a {@linkcode Route} with the router.
301
+ *
302
+ * @param route The {@linkcode Route} to register.
303
+ */
304
+ registerRoute(route: Route): void {
305
+ registerRoute(this._state, route);
306
+ }
307
+
308
+ /**
309
+ * Unregisters a route from the router.
310
+ *
311
+ * @param route The {@linkcode Route} object to unregister.
312
+ */
313
+ unregisterRoute(route: Route): void {
314
+ unregisterRoute(this._state, route);
315
+ }
316
+
317
+ /**
318
+ * Applies the routing rules to a `FetchEvent` object to get a response from an
319
+ * appropriate route.
320
+ *
321
+ * @param options
322
+ * @returns A promise is returned if a registered route can handle the request.
323
+ * If there is no matching route and there's no default handler, `undefined`
324
+ * is returned.
325
+ */
326
+ handleRequest({
327
+ request,
328
+ event,
329
+ }: {
330
+ /**
331
+ * The request to handle.
332
+ */
333
+ request: Request;
334
+ /**
335
+ * The event that triggered the request.
336
+ */
337
+ event: ExtendableEvent;
338
+ }): Promise<Response> | undefined {
339
+ return handleRequest(this._state, { request, event });
340
+ }
341
+
342
+ /**
343
+ * Checks a request and URL (and optionally an event) against the list of
344
+ * registered routes, and if there's a match, returns the corresponding
345
+ * route along with any params generated by the match.
346
+ *
347
+ * @param options
348
+ * @returns An object with `route` and `params` properties. They are populated
349
+ * if a matching route was found or `undefined` otherwise.
350
+ */
351
+ findMatchingRoute({ url, sameOrigin, request, event }: RouteMatchCallbackOptions): {
352
+ route?: Route;
353
+ params?: RouteHandlerCallbackOptions["params"];
354
+ } {
355
+ return findMatchingRoute(this._state, { url, sameOrigin, request, event });
356
+ }
357
+
358
+ // The following are deprecated methods:
359
+
360
+ /**
361
+ * Adds items to the precache list, removing duplicates and ensuring the information is valid.
362
+ *
363
+ * @param entries Array of entries to precache.
364
+ */
365
+ addToPrecacheList(entries: (PrecacheEntry | string)[]): void {
366
+ this.precache.addToCacheList(entries);
367
+ }
368
+
369
+ /**
370
+ * Returns a mapping of a precached URL to the corresponding cache key, taking
371
+ * into account the revision information for the URL.
372
+ *
373
+ * @returns A URL to cache key mapping.
374
+ */
375
+ getUrlsToPrecacheKeys(): Map<string, string> {
376
+ return this.precache.getUrlsToPrecacheKeys();
377
+ }
378
+
379
+ /**
380
+ * Returns a list of all the URLs that have been precached by the current
381
+ * service worker.
382
+ *
383
+ * @returns The precached URLs.
384
+ */
385
+ getPrecachedUrls(): string[] {
386
+ return this.precache.getPrecachedUrls();
387
+ }
388
+
389
+ /**
390
+ * Returns the cache key used for storing a given URL. If that URL is
391
+ * unversioned, like "/index.html", then the cache key will be the original
392
+ * URL with a search parameter appended to it.
393
+ *
394
+ * @param url A URL whose cache key you want to look up.
395
+ * @returns The versioned URL that corresponds to a cache key
396
+ * for the original URL, or undefined if that URL isn't precached.
397
+ */
398
+ getPrecacheKeyForUrl(url: string): string | undefined {
399
+ return this.precache.getPrecacheKeyForUrl(url);
400
+ }
401
+
402
+ /**
403
+ * @param url A cache key whose SRI you want to look up.
404
+ * @returns The subresource integrity associated with the cache key,
405
+ * or undefined if it's not set.
406
+ */
407
+ getIntegrityForPrecacheKey(cacheKey: string): string | undefined {
408
+ return this.precache.getIntegrityForPrecacheKey(cacheKey);
409
+ }
410
+
411
+ /**
412
+ * This acts as a drop-in replacement for
413
+ * [`cache.match()`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match)
414
+ * with the following differences:
415
+ *
416
+ * - It knows what the name of the precache is, and only checks in that cache.
417
+ * - It allows you to pass in an "original" URL without versioning parameters,
418
+ * and it will automatically look up the correct cache key for the currently
419
+ * active revision of that URL.
420
+ *
421
+ * E.g., `matchPrecache('index.html')` will find the correct precached
422
+ * response for the currently active service worker, even if the actual cache
423
+ * key is `'/index.html?__WB_REVISION__=1234abcd'`.
424
+ *
425
+ * @param request The key (without revisioning parameters)
426
+ * to look up in the precache.
427
+ * @returns
428
+ */
429
+ matchPrecache(request: string | Request): Promise<Response | undefined> {
430
+ return this.precache.matchPrecache(request);
431
+ }
432
+
433
+ /**
434
+ * Returns a function that looks up `url` in the precache (taking into
435
+ * account revision information), and returns the corresponding `Response`.
436
+ *
437
+ * @param url The precached URL which will be used to lookup the response.
438
+ * @return
439
+ */
440
+ createHandlerBoundToUrl(url: string): RouteHandlerCallback {
441
+ return this.precache.createHandlerBoundToUrl(url);
442
+ }
443
+ }
@@ -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 { assert } from "#utils/assert.js";
10
+ import { logger } from "#utils/logger.js";
11
+ import { SerwistError } from "#utils/SerwistError.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 { assert } from "#utils/assert.js";
10
+ import { logger } from "#utils/logger.js";
11
+ import { SerwistError } from "#utils/SerwistError.js";
12
12
  import { Strategy } from "./Strategy.js";
13
13
  import type { StrategyHandler } from "./StrategyHandler.js";
14
14
  import { messages } from "./utils/messages.js";