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,126 @@
1
+ import { parallel } from "@serwist/utils";
2
+ import type { Serwist } from "#lib/core.js";
3
+ import type { Extension } from "#lib/extension.js";
4
+ import { handleRequest, registerCapture } from "#lib/functions/router.js";
5
+ import { Strategy } from "../strategies/Strategy.js";
6
+ import type { RuntimeCaching } from "../types.js";
7
+ import { type PrecacheFallbackEntry, PrecacheFallbackPlugin } from "./precache/plugin-fallback.js";
8
+
9
+ export interface WarmRuntimeCacheEntry {
10
+ integrity?: string;
11
+ url: string;
12
+ }
13
+
14
+ export interface WarmRuntimeCacheOptions {
15
+ concurrency?: number;
16
+ }
17
+
18
+ export interface FallbackEntry extends PrecacheFallbackEntry {}
19
+
20
+ export interface FallbacksOptions {
21
+ /**
22
+ * A list of fallback entries.
23
+ */
24
+ entries: FallbackEntry[];
25
+ }
26
+
27
+ export interface RuntimeCacheOptions {
28
+ /**
29
+ * URLs that should be cached as the service worker is installed.
30
+ */
31
+ warmEntries?: (WarmRuntimeCacheEntry | string | Request)[];
32
+ /**
33
+ * Options for `warmEntries`.
34
+ */
35
+ warmOptions?: WarmRuntimeCacheOptions;
36
+ /**
37
+ * Precaches routes so that they can be used as a fallback when
38
+ * a {@linkcode Strategy} fails to generate a response.
39
+ *
40
+ * Note: This option mutates `runtimeCaching`. It also expects the URLs
41
+ * defined in `entries` to have been precached beforehand.
42
+ */
43
+ fallbacks?: FallbacksOptions;
44
+ }
45
+
46
+ export class RuntimeCache implements Extension {
47
+ _entries: RuntimeCaching[];
48
+ _options: RuntimeCacheOptions;
49
+ constructor(entries: RuntimeCaching[], options: RuntimeCacheOptions = {}) {
50
+ this._entries = entries;
51
+ this._options = options;
52
+ this.init = this.init.bind(this);
53
+ this.install = this.install.bind(this);
54
+ }
55
+
56
+ init({ serwist }: { serwist: Serwist }): void {
57
+ if (this._options.fallbacks !== undefined) {
58
+ const fallbackPlugin = new PrecacheFallbackPlugin({
59
+ fallbackUrls: this._options.fallbacks.entries,
60
+ serwist,
61
+ });
62
+
63
+ this._entries.forEach((cacheEntry) => {
64
+ if (
65
+ cacheEntry.handler instanceof Strategy &&
66
+ // This also filters entries with `PrecacheFallbackPlugin` as it also has `handlerDidError`.
67
+ !cacheEntry.handler.plugins.some((plugin) => "handlerDidError" in plugin)
68
+ ) {
69
+ cacheEntry.handler.plugins.push(fallbackPlugin);
70
+ }
71
+ });
72
+ }
73
+ for (const entry of this._entries) {
74
+ registerCapture(serwist, entry.matcher, entry.handler, entry.method);
75
+ }
76
+ }
77
+
78
+ async install({ event, serwist }: { event: ExtendableEvent; serwist: Serwist }) {
79
+ const concurrency = this._options.warmOptions?.concurrency ?? 10;
80
+ if (this._options.warmEntries) {
81
+ await parallel(concurrency, this._options.warmEntries, async (entry) => {
82
+ const request =
83
+ entry instanceof Request
84
+ ? entry
85
+ : typeof entry === "string"
86
+ ? new Request(entry, {
87
+ credentials: "same-origin",
88
+ })
89
+ : new Request(entry.url, {
90
+ integrity: entry.integrity,
91
+ credentials: "same-origin",
92
+ });
93
+
94
+ await handleRequest(serwist, {
95
+ request,
96
+ event,
97
+ });
98
+ });
99
+ }
100
+ }
101
+
102
+ /**
103
+ * Any assets you wish to cache ahead of time which can't be revisioned
104
+ * should be cached with this method. All assets are cached on install
105
+ * regardless of whether an older version of the request is in the cache.
106
+ *
107
+ * The input can be a string or a [Request](https://developer.mozilla.org/en-US/docs/Web/API/Request).
108
+ *
109
+ * @example
110
+ * ```js
111
+ * // For unrevisioned assets that should always be downloaded
112
+ * // with every service worker update, use this method.
113
+ * serwist.warmRuntimeCache([
114
+ * "/scripts/main.js',
115
+ * "/images/default-avater.png",
116
+ * new Request("/images/logo.png"),
117
+ * new Request("/api/data.json"),
118
+ * ]);
119
+ * ```
120
+ * @param entries A set of urls to cache when the service worker is installed.
121
+ */
122
+ warmRuntimeCache(entries: (WarmRuntimeCacheEntry | string | Request)[]): void {
123
+ if (!this._options.warmEntries) this._options.warmEntries = [];
124
+ this._options.warmEntries.push(...entries);
125
+ }
126
+ }
@@ -0,0 +1,149 @@
1
+ import { defaultMethod, type HTTPMethod } from "#lib/constants.js";
2
+ import type { Extension, ExtensionParam } from "#lib/extension.js";
3
+ import type { Route } from "#lib/route.js";
4
+ import type { RouteHandler } from "#lib/types.js";
5
+ import { logger } from "#utils/logger.js";
6
+ import { normalizeHandler } from "#utils/normalizeHandler.js";
7
+ import { waitUntil } from "#utils/waitUntil.js";
8
+ import type { Serwist } from "../core.js";
9
+ import { handleRequest } from "./router.js";
10
+
11
+ declare const self: ServiceWorkerGlobalScope;
12
+
13
+ export type RequestArgs = string | [string, RequestInit?];
14
+
15
+ export interface CacheURLsMessageData {
16
+ type: string;
17
+ payload: {
18
+ urlsToCache: RequestArgs[];
19
+ };
20
+ }
21
+
22
+ /**
23
+ * Adds Serwist's event listeners. Before calling it, add your own listeners should you need to.
24
+ */
25
+ export const addEventListeners = (state: Serwist) => {
26
+ self.addEventListener("install", createInstallHandler(state));
27
+ self.addEventListener("activate", createActivateHandler(state));
28
+ self.addEventListener("fetch", createFetchHandler(state));
29
+ self.addEventListener("message", createCacheHandler(state));
30
+ };
31
+
32
+ export const createInstallHandler = (state: Serwist) => {
33
+ return (event: ExtendableEvent): Promise<void> => {
34
+ return waitUntil(event, async () => {
35
+ for (const callback of iterateExtensions(state, "install")) {
36
+ await callback({ event, serwist: state });
37
+ }
38
+ });
39
+ };
40
+ };
41
+
42
+ export const createActivateHandler = (state: Serwist) => {
43
+ return (event: ExtendableEvent): Promise<void> => {
44
+ return waitUntil(event, async () => {
45
+ for (const callback of iterateExtensions(state, "activate")) {
46
+ await callback({ event, serwist: state });
47
+ }
48
+ });
49
+ };
50
+ };
51
+
52
+ /**
53
+ * Gets a `Response` from an appropriate `Route`'s handler. Call this method
54
+ * from the service worker's `fetch` event.
55
+ * @param event
56
+ */
57
+ export const createFetchHandler = (state: Serwist) => {
58
+ return (event: FetchEvent) => {
59
+ const { request } = event;
60
+ const responsePromise = handleRequest(state, { request, event });
61
+ if (responsePromise) {
62
+ event.respondWith(responsePromise);
63
+ }
64
+ };
65
+ };
66
+
67
+ /**
68
+ * Caches new URLs on demand. Call this method from the service worker's
69
+ * `message` event. To trigger the handler, send a message of type `"CACHE_URLS"`
70
+ * alongside a list of URLs that should be cached as `urlsToCache`.
71
+ * @param event
72
+ */
73
+ export const createCacheHandler = (state: Serwist) => {
74
+ return (event: ExtendableMessageEvent) => {
75
+ if (event.data && event.data.type === "CACHE_URLS") {
76
+ const { payload }: CacheURLsMessageData = event.data;
77
+
78
+ if (process.env.NODE_ENV !== "production") {
79
+ logger.debug("Caching URLs from the window", payload.urlsToCache);
80
+ }
81
+
82
+ const requestPromises = Promise.all(
83
+ payload.urlsToCache.map((entry: string | [string, RequestInit?]) => {
84
+ let request: Request;
85
+ if (typeof entry === "string") {
86
+ request = new Request(entry);
87
+ } else {
88
+ request = new Request(...entry);
89
+ }
90
+ return handleRequest(state, { request, event });
91
+ }),
92
+ );
93
+
94
+ event.waitUntil(requestPromises);
95
+
96
+ // If a MessageChannel was used, reply to the message on success.
97
+ if (event.ports?.[0]) {
98
+ void requestPromises.then(() => event.ports[0].postMessage(true));
99
+ }
100
+ }
101
+ };
102
+ };
103
+
104
+ /**
105
+ * Define a default handler that's called when no routes explicitly
106
+ * match the incoming request.
107
+ *
108
+ * Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
109
+ *
110
+ * Without a default handler, unmatched requests will go against the
111
+ * network as if there were no service worker present.
112
+ *
113
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
114
+ * @param method The HTTP method to associate with this default handler. Each method
115
+ * has its own default. Defaults to `'GET'`.
116
+ */
117
+ export const setDefaultHandler = (state: Serwist, handler: RouteHandler, method: HTTPMethod = defaultMethod): void => {
118
+ state.defaultHandlerMap.set(method, normalizeHandler(handler));
119
+ };
120
+
121
+ /**
122
+ * If a {@linkcode Route} throws an error while handling a request, this handler
123
+ * will be called and given a chance to provide a response.
124
+ *
125
+ * @param handler A callback function that returns a `Promise` resulting
126
+ * in a `Response`.
127
+ */
128
+ export const setCatchHandler = (state: Serwist, handler: RouteHandler): void => {
129
+ state.catchHandler = normalizeHandler(handler);
130
+ };
131
+
132
+ /**
133
+ * Accepts a callback name and returns an iterable of matching plugin callbacks.
134
+ *
135
+ * @param name The name fo the callback to run
136
+ * @returns
137
+ */
138
+ export function* iterateExtensions<C extends keyof Extension>(state: Serwist, name: C): Generator<NonNullable<Extension[C]>> {
139
+ if (!state.extensions) return;
140
+
141
+ for (const controller of state.extensions) {
142
+ if (typeof controller[name] === "function") {
143
+ const callback = (param: ExtensionParam[C]) => {
144
+ controller[name]!(param as any);
145
+ };
146
+ yield callback as NonNullable<Extension[C]>;
147
+ }
148
+ }
149
+ }
@@ -0,0 +1,314 @@
1
+ import { assert } from "#utils/assert.js";
2
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
3
+ import { logger } from "#utils/logger.js";
4
+ import { parseRoute } from "#utils/parseRoute.js";
5
+ import { SerwistError } from "#utils/SerwistError.js";
6
+ import type { HTTPMethod } from "../constants.js";
7
+ import type { Serwist } from "../core.js";
8
+ import type { Route } from "../route.js";
9
+ import type { RouteHandler, RouteHandlerCallbackOptions, RouteMatchCallback, RouteMatchCallbackOptions } from "../types.js";
10
+
11
+ /**
12
+ * Registers a `RegExp`, string, or function with a caching
13
+ * strategy to the router.
14
+ *
15
+ * @param capture If the capture param is a {@linkcode Route} object, all other arguments will be ignored.
16
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
17
+ * This parameter is required if `capture` is not a {@linkcode Route} object.
18
+ * @param method The HTTP method to match the route against. Defaults to `'GET'`.
19
+ * @returns The generated {@linkcode Route} object.
20
+ */
21
+ export const registerCapture = <T extends RegExp | string | RouteMatchCallback | Route>(
22
+ state: Serwist,
23
+ capture: T,
24
+ handler?: T extends Route ? never : RouteHandler,
25
+ method?: T extends Route ? never : HTTPMethod,
26
+ ): Route => {
27
+ const route = parseRoute(capture, handler, method);
28
+ registerRoute(state, route);
29
+ return route;
30
+ };
31
+
32
+ /**
33
+ * Registers a {@linkcode Route} with the router.
34
+ *
35
+ * @param route The {@linkcode Route} to register.
36
+ */
37
+ export const registerRoute = (state: Serwist, route: Route): void => {
38
+ if (process.env.NODE_ENV !== "production") {
39
+ assert!.isType(route, "object", {
40
+ moduleName: "serwist",
41
+ className: "Serwist",
42
+ funcName: "registerRoute",
43
+ paramName: "route",
44
+ });
45
+
46
+ assert!.hasMethod(route, "match", {
47
+ moduleName: "serwist",
48
+ className: "Serwist",
49
+ funcName: "registerRoute",
50
+ paramName: "route",
51
+ });
52
+
53
+ assert!.isType(route.handler, "object", {
54
+ moduleName: "serwist",
55
+ className: "Serwist",
56
+ funcName: "registerRoute",
57
+ paramName: "route",
58
+ });
59
+
60
+ assert!.hasMethod(route.handler, "handle", {
61
+ moduleName: "serwist",
62
+ className: "Serwist",
63
+ funcName: "registerRoute",
64
+ paramName: "route.handler",
65
+ });
66
+
67
+ assert!.isType(route.method, "string", {
68
+ moduleName: "serwist",
69
+ className: "Serwist",
70
+ funcName: "registerRoute",
71
+ paramName: "route.method",
72
+ });
73
+ }
74
+
75
+ if (!state.routes.has(route.method)) {
76
+ state.routes.set(route.method, []);
77
+ }
78
+
79
+ // Give precedence to all of the earlier routes by adding this additional
80
+ // route to the end of the array.
81
+ state.routes.get(route.method)!.push(route);
82
+ };
83
+
84
+ /**
85
+ * Unregisters a route from the router.
86
+ *
87
+ * @param route The {@linkcode Route} object to unregister.
88
+ */
89
+ export const unregisterRoute = (state: Serwist, route: Route): void => {
90
+ if (!state.routes.has(route.method)) {
91
+ throw new SerwistError("unregister-route-but-not-found-with-method", {
92
+ method: route.method,
93
+ });
94
+ }
95
+
96
+ const routeIndex = state.routes.get(route.method)!.indexOf(route);
97
+ if (routeIndex > -1) {
98
+ state.routes.get(route.method)!.splice(routeIndex, 1);
99
+ } else {
100
+ throw new SerwistError("unregister-route-route-not-registered");
101
+ }
102
+ };
103
+
104
+ /**
105
+ * Applies the routing rules to a `FetchEvent` object to get a response from an
106
+ * appropriate route.
107
+ *
108
+ * @param options
109
+ * @returns A promise is returned if a registered route can handle the request.
110
+ * If there is no matching route and there's no default handler, `undefined`
111
+ * is returned.
112
+ */
113
+ export const handleRequest = (
114
+ state: Serwist,
115
+ {
116
+ request,
117
+ event,
118
+ }: {
119
+ /**
120
+ * The request to handle.
121
+ */
122
+ request: Request;
123
+ /**
124
+ * The event that triggered the request.
125
+ */
126
+ event: ExtendableEvent;
127
+ },
128
+ ): Promise<Response> | undefined => {
129
+ if (process.env.NODE_ENV !== "production") {
130
+ assert!.isInstance(request, Request, {
131
+ moduleName: "serwist",
132
+ className: "Serwist",
133
+ funcName: "handleRequest",
134
+ paramName: "options.request",
135
+ });
136
+ }
137
+
138
+ const url = new URL(request.url, location.href);
139
+ if (!url.protocol.startsWith("http")) {
140
+ if (process.env.NODE_ENV !== "production") {
141
+ logger.debug("Router only supports URLs that start with 'http'.");
142
+ }
143
+ return;
144
+ }
145
+
146
+ const sameOrigin = url.origin === location.origin;
147
+ const { params, route } = findMatchingRoute(state, {
148
+ event,
149
+ request,
150
+ sameOrigin,
151
+ url,
152
+ });
153
+ let handler = route?.handler;
154
+
155
+ const debugMessages = [];
156
+ if (process.env.NODE_ENV !== "production") {
157
+ if (handler) {
158
+ debugMessages.push(["Found a route to handle this request:", route]);
159
+
160
+ if (params) {
161
+ debugMessages.push([`Passing the following params to the route's handler:`, params]);
162
+ }
163
+ }
164
+ }
165
+
166
+ // If we don't have a handler because there was no matching route, then
167
+ // fall back to defaultHandler if that's defined.
168
+ const method = request.method as HTTPMethod;
169
+ if (!handler && state.defaultHandlerMap.has(method)) {
170
+ if (process.env.NODE_ENV !== "production") {
171
+ debugMessages.push(`Failed to find a matching route. Falling back to the default handler for ${method}.`);
172
+ }
173
+ handler = state.defaultHandlerMap.get(method);
174
+ }
175
+
176
+ if (!handler) {
177
+ if (process.env.NODE_ENV !== "production") {
178
+ // No handler so Serwist will do nothing. If logs is set of debug
179
+ // i.e. verbose, we should print out this information.
180
+ logger.debug(`No route found for: ${getFriendlyURL(url)}`);
181
+ }
182
+ return;
183
+ }
184
+
185
+ if (process.env.NODE_ENV !== "production") {
186
+ // We have a handler, meaning Serwist is going to handle the route.
187
+ // print the routing details to the console.
188
+ logger.groupCollapsed(`Router is responding to: ${getFriendlyURL(url)}`);
189
+
190
+ for (const msg of debugMessages) {
191
+ if (Array.isArray(msg)) {
192
+ logger.log(...msg);
193
+ } else {
194
+ logger.log(msg);
195
+ }
196
+ }
197
+
198
+ logger.groupEnd();
199
+ }
200
+
201
+ // Wrap in try and catch in case the handle method throws a synchronous
202
+ // error. It should still callback to the catch handler.
203
+ let responsePromise: Promise<Response>;
204
+ try {
205
+ responsePromise = handler.handle({ url, request, event, params });
206
+ } catch (err) {
207
+ responsePromise = Promise.reject(err);
208
+ }
209
+
210
+ // Get route's catch handler, if it exists
211
+ const catchHandler = route?.catchHandler;
212
+
213
+ if (responsePromise instanceof Promise && (state.catchHandler || catchHandler)) {
214
+ responsePromise = responsePromise.catch(async (err) => {
215
+ // If there's a route catch handler, process that first
216
+ if (catchHandler) {
217
+ if (process.env.NODE_ENV !== "production") {
218
+ // Still include URL here as it will be async from the console group
219
+ // and may not make sense without the URL
220
+ logger.groupCollapsed(`Error thrown when responding to: ${getFriendlyURL(url)}. Falling back to route's Catch Handler.`);
221
+ logger.error("Error thrown by:", route);
222
+ logger.error(err);
223
+ logger.groupEnd();
224
+ }
225
+
226
+ try {
227
+ return await catchHandler.handle({ url, request, event, params });
228
+ } catch (catchErr) {
229
+ if (catchErr instanceof Error) {
230
+ err = catchErr;
231
+ }
232
+ }
233
+ }
234
+
235
+ if (state.catchHandler) {
236
+ if (process.env.NODE_ENV !== "production") {
237
+ // Still include URL here as it will be async from the console group
238
+ // and may not make sense without the URL
239
+ logger.groupCollapsed(`Error thrown when responding to: ${getFriendlyURL(url)}. Falling back to global Catch Handler.`);
240
+ logger.error("Error thrown by:", route);
241
+ logger.error(err);
242
+ logger.groupEnd();
243
+ }
244
+ return state.catchHandler.handle({ url, request, event });
245
+ }
246
+
247
+ throw err;
248
+ });
249
+ }
250
+
251
+ return responsePromise;
252
+ };
253
+
254
+ /**
255
+ * Checks a request and URL (and optionally an event) against the list of
256
+ * registered routes, and if there's a match, returns the corresponding
257
+ * route along with any params generated by the match.
258
+ *
259
+ * @param options
260
+ * @returns An object with `route` and `params` properties. They are populated
261
+ * if a matching route was found or `undefined` otherwise.
262
+ */
263
+ export const findMatchingRoute = (
264
+ state: Serwist,
265
+ { url, sameOrigin, request, event }: RouteMatchCallbackOptions,
266
+ ): {
267
+ route?: Route;
268
+ params?: RouteHandlerCallbackOptions["params"];
269
+ } => {
270
+ const routes = state.routes.get(request.method as HTTPMethod) || [];
271
+ for (const route of routes) {
272
+ let params: Promise<any> | undefined;
273
+ // route.match returns type any, not possible to change right now.
274
+ const matchResult = route.match({ url, sameOrigin, request, event });
275
+ if (matchResult) {
276
+ if (process.env.NODE_ENV !== "production") {
277
+ // Warn developers that using an async matchCallback is almost always
278
+ // not the right thing to do.
279
+ if (matchResult instanceof Promise) {
280
+ logger.warn(
281
+ `While routing ${getFriendlyURL(
282
+ url,
283
+ )}, an async matchCallback function was used. Please convert the following route to use a synchronous matchCallback function:`,
284
+ route,
285
+ );
286
+ }
287
+ }
288
+
289
+ // See https://github.com/GoogleChrome/workbox/issues/2079
290
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
291
+ params = matchResult;
292
+ if (Array.isArray(params) && params.length === 0) {
293
+ // Instead of passing an empty array in as params, use undefined.
294
+ params = undefined;
295
+ } else if (
296
+ matchResult.constructor === Object && // eslint-disable-line
297
+ Object.keys(matchResult).length === 0
298
+ ) {
299
+ // Instead of passing an empty object in as params, use undefined.
300
+ params = undefined;
301
+ } else if (typeof matchResult === "boolean") {
302
+ // For the boolean value true (rather than just something truth-y),
303
+ // don't set params.
304
+ // See https://github.com/GoogleChrome/workbox/pull/2134#issuecomment-513924353
305
+ params = undefined;
306
+ }
307
+
308
+ // Return early if have a match.
309
+ return { route, params };
310
+ }
311
+ }
312
+ // If no match was found above, return and empty object.
313
+ return {};
314
+ };
@@ -1,4 +1,4 @@
1
- import { logger } from "./utils/logger.js";
1
+ import { logger } from "#utils/logger.js";
2
2
 
3
3
  declare const self: ServiceWorkerGlobalScope;
4
4
 
@@ -6,7 +6,7 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { SerwistPlugin } from "../../types.js";
9
+ import type { StrategyPlugin } from "#lib/types.js";
10
10
  import { createPartialResponse } from "./createPartialResponse.js";
11
11
 
12
12
  /**
@@ -15,7 +15,7 @@ import { createPartialResponse } from "./createPartialResponse.js";
15
15
  * It does this by intercepting the `cachedResponseWillBeUsed` plugin callback
16
16
  * and returning the appropriate subset of the cached response body.
17
17
  */
18
- export class RangeRequestsPlugin implements SerwistPlugin {
18
+ export class RangeRequestsPlugin implements StrategyPlugin {
19
19
  /**
20
20
  * @param options
21
21
  * @returns If request contains a `Range` header, then a
@@ -23,7 +23,7 @@ export class RangeRequestsPlugin implements SerwistPlugin {
23
23
  * returned. Otherwise, `cachedResponse` is returned as-is.
24
24
  * @private
25
25
  */
26
- cachedResponseWillBeUsed: SerwistPlugin["cachedResponseWillBeUsed"] = async ({ request, cachedResponse }) => {
26
+ cachedResponseWillBeUsed: StrategyPlugin["cachedResponseWillBeUsed"] = async ({ request, cachedResponse }) => {
27
27
  // Only return a sliced response if there's something valid in the cache,
28
28
  // and there's a Range: header in the request.
29
29
  if (cachedResponse && request.headers.has("range")) {
@@ -6,9 +6,9 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
9
+ import { assert } from "#utils/assert.js";
10
+ import { logger } from "#utils/logger.js";
11
+ import { SerwistError } from "#utils/SerwistError.js";
12
12
  import { calculateEffectiveBoundaries } from "./utils/calculateEffectiveBoundaries.js";
13
13
  import { parseRangeHeader } from "./utils/parseRangeHeader.js";
14
14
 
@@ -0,0 +1,2 @@
1
+ export { createPartialResponse } from "./createPartialResponse.js";
2
+ export { RangeRequestsPlugin } from "./RangeRequestsPlugin.js";
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../../utils/SerwistError.js";
10
- import { assert } from "../../../utils/assert.js";
9
+ import { assert } from "#utils/assert.js";
10
+ import { SerwistError } from "#utils/SerwistError.js";
11
11
 
12
12
  /**
13
13
  * @param blob A source blob.
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../../utils/SerwistError.js";
10
- import { assert } from "../../../utils/assert.js";
9
+ import { assert } from "#utils/assert.js";
10
+ import { SerwistError } from "#utils/SerwistError.js";
11
11
 
12
12
  /**
13
13
  * @param rangeHeader A `Range` header value.