serwist 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 (330) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/NavigationRoute.d.ts +57 -0
  4. package/dist/NavigationRoute.d.ts.map +1 -0
  5. package/dist/PrecacheRoute.d.ts +17 -0
  6. package/dist/PrecacheRoute.d.ts.map +1 -0
  7. package/dist/PrecacheStrategy.d.ts +66 -0
  8. package/dist/PrecacheStrategy.d.ts.map +1 -0
  9. package/dist/RegExpRoute.d.ts +24 -0
  10. package/dist/RegExpRoute.d.ts.map +1 -0
  11. package/dist/Route.d.ts +33 -0
  12. package/dist/Route.d.ts.map +1 -0
  13. package/dist/Serwist.d.ts +331 -0
  14. package/dist/Serwist.d.ts.map +1 -0
  15. package/dist/cacheNames.d.ts +20 -0
  16. package/dist/cacheNames.d.ts.map +1 -0
  17. package/dist/chunks/NetworkOnly.js +599 -0
  18. package/dist/chunks/PrecacheFallbackPlugin.js +634 -0
  19. package/dist/chunks/Serwist.js +1034 -0
  20. package/dist/chunks/registerQuotaErrorCallback.js +17 -0
  21. package/dist/chunks/resultingClientExists.js +32 -0
  22. package/dist/chunks/timeout.js +400 -0
  23. package/dist/chunks/waitUntil.js +24 -0
  24. package/dist/cleanupOutdatedCaches.d.ts +6 -0
  25. package/dist/cleanupOutdatedCaches.d.ts.map +1 -0
  26. package/dist/clientsClaim.d.ts +6 -0
  27. package/dist/clientsClaim.d.ts.map +1 -0
  28. package/dist/constants.d.ts +15 -0
  29. package/dist/constants.d.ts.map +1 -0
  30. package/dist/copyResponse.d.ts +20 -0
  31. package/dist/copyResponse.d.ts.map +1 -0
  32. package/dist/disableDevLogs.d.ts +7 -0
  33. package/dist/disableDevLogs.d.ts.map +1 -0
  34. package/dist/index.d.ts +21 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.internal.d.ts +16 -0
  37. package/dist/index.internal.d.ts.map +1 -0
  38. package/dist/index.internal.js +24 -0
  39. package/dist/index.js +27 -0
  40. package/dist/index.legacy.d.ts +32 -0
  41. package/dist/index.legacy.d.ts.map +1 -0
  42. package/dist/index.legacy.js +640 -0
  43. package/dist/index.plugins.d.ts +41 -0
  44. package/dist/index.plugins.d.ts.map +1 -0
  45. package/dist/index.plugins.js +669 -0
  46. package/dist/index.strategies.d.ts +22 -0
  47. package/dist/index.strategies.d.ts.map +1 -0
  48. package/dist/index.strategies.js +144 -0
  49. package/dist/legacy/PrecacheController.d.ts +146 -0
  50. package/dist/legacy/PrecacheController.d.ts.map +1 -0
  51. package/dist/legacy/PrecacheFallbackPlugin.d.ts +62 -0
  52. package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +1 -0
  53. package/dist/legacy/PrecacheRoute.d.ts +19 -0
  54. package/dist/legacy/PrecacheRoute.d.ts.map +1 -0
  55. package/dist/legacy/Router.d.ts +151 -0
  56. package/dist/legacy/Router.d.ts.map +1 -0
  57. package/dist/legacy/addPlugins.d.ts +9 -0
  58. package/dist/legacy/addPlugins.d.ts.map +1 -0
  59. package/dist/legacy/addRoute.d.ts +16 -0
  60. package/dist/legacy/addRoute.d.ts.map +1 -0
  61. package/dist/legacy/createHandlerBoundToURL.d.ts +18 -0
  62. package/dist/legacy/createHandlerBoundToURL.d.ts.map +1 -0
  63. package/dist/legacy/fallbacks.d.ts +59 -0
  64. package/dist/legacy/fallbacks.d.ts.map +1 -0
  65. package/dist/legacy/getCacheKeyForURL.d.ts +20 -0
  66. package/dist/legacy/getCacheKeyForURL.d.ts.map +1 -0
  67. package/dist/legacy/handlePrecaching.d.ts +54 -0
  68. package/dist/legacy/handlePrecaching.d.ts.map +1 -0
  69. package/dist/legacy/installSerwist.d.ts +15 -0
  70. package/dist/legacy/installSerwist.d.ts.map +1 -0
  71. package/dist/legacy/matchPrecache.d.ts +15 -0
  72. package/dist/legacy/matchPrecache.d.ts.map +1 -0
  73. package/dist/legacy/precache.d.ts +20 -0
  74. package/dist/legacy/precache.d.ts.map +1 -0
  75. package/dist/legacy/precacheAndRoute.d.ts +15 -0
  76. package/dist/legacy/precacheAndRoute.d.ts.map +1 -0
  77. package/dist/legacy/registerRoute.d.ts +16 -0
  78. package/dist/legacy/registerRoute.d.ts.map +1 -0
  79. package/dist/legacy/registerRuntimeCaching.d.ts +11 -0
  80. package/dist/legacy/registerRuntimeCaching.d.ts.map +1 -0
  81. package/dist/legacy/setCatchHandler.d.ts +10 -0
  82. package/dist/legacy/setCatchHandler.d.ts.map +1 -0
  83. package/dist/legacy/setDefaultHandler.d.ts +13 -0
  84. package/dist/legacy/setDefaultHandler.d.ts.map +1 -0
  85. package/dist/legacy/singletonPrecacheController.d.ts +34 -0
  86. package/dist/legacy/singletonPrecacheController.d.ts.map +1 -0
  87. package/dist/legacy/singletonRouter.d.ts +41 -0
  88. package/dist/legacy/singletonRouter.d.ts.map +1 -0
  89. package/dist/legacy/unregisterRoute.d.ts +9 -0
  90. package/dist/legacy/unregisterRoute.d.ts.map +1 -0
  91. package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts +16 -0
  92. package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
  93. package/dist/legacy/utils/getCacheKeyForURL.d.ts +14 -0
  94. package/dist/legacy/utils/getCacheKeyForURL.d.ts.map +1 -0
  95. package/dist/models/messages/messageGenerator.d.ts +4 -0
  96. package/dist/models/messages/messageGenerator.d.ts.map +1 -0
  97. package/dist/models/messages/messages.d.ts +44 -0
  98. package/dist/models/messages/messages.d.ts.map +1 -0
  99. package/dist/models/pluginEvents.d.ts +10 -0
  100. package/dist/models/pluginEvents.d.ts.map +1 -0
  101. package/dist/models/quotaErrorCallbacks.d.ts +3 -0
  102. package/dist/models/quotaErrorCallbacks.d.ts.map +1 -0
  103. package/dist/navigationPreload.d.ts +24 -0
  104. package/dist/navigationPreload.d.ts.map +1 -0
  105. package/dist/parseRoute.d.ts +16 -0
  106. package/dist/parseRoute.d.ts.map +1 -0
  107. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +23 -0
  108. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
  109. package/dist/plugins/backgroundSync/Queue.d.ts +166 -0
  110. package/dist/plugins/backgroundSync/Queue.d.ts.map +1 -0
  111. package/dist/plugins/backgroundSync/QueueDb.d.ts +90 -0
  112. package/dist/plugins/backgroundSync/QueueDb.d.ts.map +1 -0
  113. package/dist/plugins/backgroundSync/QueueStore.d.ts +75 -0
  114. package/dist/plugins/backgroundSync/QueueStore.d.ts.map +1 -0
  115. package/dist/plugins/backgroundSync/StorableRequest.d.ts +51 -0
  116. package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +1 -0
  117. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +45 -0
  118. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
  119. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +27 -0
  120. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
  121. package/dist/plugins/broadcastUpdate/constants.d.ts +5 -0
  122. package/dist/plugins/broadcastUpdate/constants.d.ts.map +1 -0
  123. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +11 -0
  124. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
  125. package/dist/plugins/broadcastUpdate/types.d.ts +34 -0
  126. package/dist/plugins/broadcastUpdate/types.d.ts.map +1 -0
  127. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +40 -0
  128. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +1 -0
  129. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +27 -0
  130. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
  131. package/dist/plugins/expiration/CacheExpiration.d.ts +66 -0
  132. package/dist/plugins/expiration/CacheExpiration.d.ts.map +1 -0
  133. package/dist/plugins/expiration/ExpirationPlugin.d.ts +116 -0
  134. package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +1 -0
  135. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +73 -0
  136. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
  137. package/dist/plugins/googleAnalytics/constants.d.ts +10 -0
  138. package/dist/plugins/googleAnalytics/constants.d.ts.map +1 -0
  139. package/dist/plugins/googleAnalytics/initialize.d.ts +30 -0
  140. package/dist/plugins/googleAnalytics/initialize.d.ts.map +1 -0
  141. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +53 -0
  142. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
  143. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +19 -0
  144. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
  145. package/dist/plugins/rangeRequests/createPartialResponse.d.ts +18 -0
  146. package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +1 -0
  147. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +14 -0
  148. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
  149. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +12 -0
  150. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
  151. package/dist/registerQuotaErrorCallback.d.ts +8 -0
  152. package/dist/registerQuotaErrorCallback.d.ts.map +1 -0
  153. package/dist/setCacheNameDetails.d.ts +9 -0
  154. package/dist/setCacheNameDetails.d.ts.map +1 -0
  155. package/dist/strategies/CacheFirst.d.ts +23 -0
  156. package/dist/strategies/CacheFirst.d.ts.map +1 -0
  157. package/dist/strategies/CacheOnly.d.ts +20 -0
  158. package/dist/strategies/CacheOnly.d.ts.map +1 -0
  159. package/dist/strategies/NetworkFirst.d.ts +61 -0
  160. package/dist/strategies/NetworkFirst.d.ts.map +1 -0
  161. package/dist/strategies/NetworkOnly.d.ts +32 -0
  162. package/dist/strategies/NetworkOnly.d.ts.map +1 -0
  163. package/dist/strategies/StaleWhileRevalidate.d.ts +35 -0
  164. package/dist/strategies/StaleWhileRevalidate.d.ts.map +1 -0
  165. package/dist/strategies/Strategy.d.ts +83 -0
  166. package/dist/strategies/Strategy.d.ts.map +1 -0
  167. package/dist/strategies/StrategyHandler.d.ts +189 -0
  168. package/dist/strategies/StrategyHandler.d.ts.map +1 -0
  169. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
  170. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
  171. package/dist/strategies/utils/messages.d.ts +5 -0
  172. package/dist/strategies/utils/messages.d.ts.map +1 -0
  173. package/dist/types.d.ts +317 -0
  174. package/dist/types.d.ts.map +1 -0
  175. package/dist/utils/Deferred.d.ts +19 -0
  176. package/dist/utils/Deferred.d.ts.map +1 -0
  177. package/dist/utils/PrecacheCacheKeyPlugin.d.ts +16 -0
  178. package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
  179. package/dist/utils/PrecacheInstallReportPlugin.d.ts +14 -0
  180. package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
  181. package/dist/utils/SerwistError.d.ts +24 -0
  182. package/dist/utils/SerwistError.d.ts.map +1 -0
  183. package/dist/utils/assert.d.ts +11 -0
  184. package/dist/utils/assert.d.ts.map +1 -0
  185. package/dist/utils/cacheMatchIgnoreParams.d.ts +15 -0
  186. package/dist/utils/cacheMatchIgnoreParams.d.ts.map +1 -0
  187. package/dist/utils/cacheNames.d.ts +40 -0
  188. package/dist/utils/cacheNames.d.ts.map +1 -0
  189. package/dist/utils/canConstructReadableStream.d.ts +12 -0
  190. package/dist/utils/canConstructReadableStream.d.ts.map +1 -0
  191. package/dist/utils/canConstructResponseFromBodyStream.d.ts +11 -0
  192. package/dist/utils/canConstructResponseFromBodyStream.d.ts.map +1 -0
  193. package/dist/utils/createCacheKey.d.ts +16 -0
  194. package/dist/utils/createCacheKey.d.ts.map +1 -0
  195. package/dist/utils/deleteOutdatedCaches.d.ts +18 -0
  196. package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -0
  197. package/dist/utils/dontWaitFor.d.ts +7 -0
  198. package/dist/utils/dontWaitFor.d.ts.map +1 -0
  199. package/dist/utils/executeQuotaErrorCallbacks.d.ts +8 -0
  200. package/dist/utils/executeQuotaErrorCallbacks.d.ts.map +1 -0
  201. package/dist/utils/generateURLVariations.d.ts +12 -0
  202. package/dist/utils/generateURLVariations.d.ts.map +1 -0
  203. package/dist/utils/getFriendlyURL.d.ts +3 -0
  204. package/dist/utils/getFriendlyURL.d.ts.map +1 -0
  205. package/dist/utils/logger.d.ts +24 -0
  206. package/dist/utils/logger.d.ts.map +1 -0
  207. package/dist/utils/normalizeHandler.d.ts +10 -0
  208. package/dist/utils/normalizeHandler.d.ts.map +1 -0
  209. package/dist/utils/pluginUtils.d.ts +5 -0
  210. package/dist/utils/pluginUtils.d.ts.map +1 -0
  211. package/dist/utils/printCleanupDetails.d.ts +6 -0
  212. package/dist/utils/printCleanupDetails.d.ts.map +1 -0
  213. package/dist/utils/printInstallDetails.d.ts +7 -0
  214. package/dist/utils/printInstallDetails.d.ts.map +1 -0
  215. package/dist/utils/removeIgnoredSearchParams.d.ts +12 -0
  216. package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -0
  217. package/dist/utils/resultingClientExists.d.ts +12 -0
  218. package/dist/utils/resultingClientExists.d.ts.map +1 -0
  219. package/dist/utils/timeout.d.ts +10 -0
  220. package/dist/utils/timeout.d.ts.map +1 -0
  221. package/dist/utils/waitUntil.d.ts +11 -0
  222. package/dist/utils/waitUntil.d.ts.map +1 -0
  223. package/dist/utils/welcome.d.ts +2 -0
  224. package/dist/utils/welcome.d.ts.map +1 -0
  225. package/package.json +85 -0
  226. package/src/NavigationRoute.ts +119 -0
  227. package/src/PrecacheRoute.ts +46 -0
  228. package/src/PrecacheStrategy.ts +239 -0
  229. package/src/RegExpRoute.ts +74 -0
  230. package/src/Route.ts +67 -0
  231. package/src/Serwist.ts +920 -0
  232. package/src/cacheNames.ts +39 -0
  233. package/src/cleanupOutdatedCaches.ts +32 -0
  234. package/src/clientsClaim.ts +18 -0
  235. package/src/constants.ts +24 -0
  236. package/src/copyResponse.ts +60 -0
  237. package/src/disableDevLogs.ts +10 -0
  238. package/src/index.internal.ts +33 -0
  239. package/src/index.legacy.ts +66 -0
  240. package/src/index.plugins.ts +95 -0
  241. package/src/index.strategies.ts +26 -0
  242. package/src/index.ts +39 -0
  243. package/src/legacy/PrecacheController.ts +337 -0
  244. package/src/legacy/PrecacheFallbackPlugin.ts +93 -0
  245. package/src/legacy/PrecacheRoute.ts +48 -0
  246. package/src/legacy/Router.ts +484 -0
  247. package/src/legacy/addPlugins.ts +21 -0
  248. package/src/legacy/addRoute.ts +29 -0
  249. package/src/legacy/createHandlerBoundToURL.ts +30 -0
  250. package/src/legacy/fallbacks.ts +94 -0
  251. package/src/legacy/getCacheKeyForURL.ts +32 -0
  252. package/src/legacy/handlePrecaching.ts +86 -0
  253. package/src/legacy/installSerwist.ts +19 -0
  254. package/src/legacy/matchPrecache.ts +26 -0
  255. package/src/legacy/precache.ts +31 -0
  256. package/src/legacy/precacheAndRoute.ts +28 -0
  257. package/src/legacy/registerRoute.ts +27 -0
  258. package/src/legacy/registerRuntimeCaching.ts +17 -0
  259. package/src/legacy/setCatchHandler.ts +21 -0
  260. package/src/legacy/setDefaultHandler.ts +24 -0
  261. package/src/legacy/singletonPrecacheController.ts +53 -0
  262. package/src/legacy/singletonRouter.ts +70 -0
  263. package/src/legacy/unregisterRoute.ts +12 -0
  264. package/src/legacy/utils/PrecacheCacheKeyPlugin.ts +33 -0
  265. package/src/legacy/utils/getCacheKeyForURL.ts +36 -0
  266. package/src/models/messages/messageGenerator.ts +29 -0
  267. package/src/models/messages/messages.ts +233 -0
  268. package/src/models/pluginEvents.ts +17 -0
  269. package/src/models/quotaErrorCallbacks.ts +13 -0
  270. package/src/navigationPreload.ts +68 -0
  271. package/src/parseRoute.ts +78 -0
  272. package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +38 -0
  273. package/src/plugins/backgroundSync/Queue.ts +440 -0
  274. package/src/plugins/backgroundSync/QueueDb.ts +176 -0
  275. package/src/plugins/backgroundSync/QueueStore.ts +160 -0
  276. package/src/plugins/backgroundSync/StorableRequest.ts +142 -0
  277. package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +161 -0
  278. package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +42 -0
  279. package/src/plugins/broadcastUpdate/constants.ts +12 -0
  280. package/src/plugins/broadcastUpdate/responsesAreSame.ts +49 -0
  281. package/src/plugins/broadcastUpdate/types.ts +37 -0
  282. package/src/plugins/cacheableResponse/CacheableResponse.ts +144 -0
  283. package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +45 -0
  284. package/src/plugins/expiration/CacheExpiration.ts +193 -0
  285. package/src/plugins/expiration/ExpirationPlugin.ts +300 -0
  286. package/src/plugins/expiration/models/CacheTimestampsModel.ts +184 -0
  287. package/src/plugins/googleAnalytics/constants.ts +22 -0
  288. package/src/plugins/googleAnalytics/initialize.ts +209 -0
  289. package/src/plugins/precaching/PrecacheFallbackPlugin.ts +83 -0
  290. package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +38 -0
  291. package/src/plugins/rangeRequests/createPartialResponse.ts +93 -0
  292. package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +59 -0
  293. package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +55 -0
  294. package/src/registerQuotaErrorCallback.ts +34 -0
  295. package/src/setCacheNameDetails.ts +53 -0
  296. package/src/strategies/CacheFirst.ts +88 -0
  297. package/src/strategies/CacheOnly.ts +59 -0
  298. package/src/strategies/NetworkFirst.ts +229 -0
  299. package/src/strategies/NetworkOnly.ts +98 -0
  300. package/src/strategies/StaleWhileRevalidate.ts +110 -0
  301. package/src/strategies/Strategy.ts +204 -0
  302. package/src/strategies/StrategyHandler.ts +554 -0
  303. package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +26 -0
  304. package/src/strategies/utils/messages.ts +21 -0
  305. package/src/types.ts +358 -0
  306. package/src/utils/Deferred.ts +33 -0
  307. package/src/utils/PrecacheCacheKeyPlugin.ts +33 -0
  308. package/src/utils/PrecacheInstallReportPlugin.ts +47 -0
  309. package/src/utils/SerwistError.ts +41 -0
  310. package/src/utils/assert.ts +89 -0
  311. package/src/utils/cacheMatchIgnoreParams.ts +54 -0
  312. package/src/utils/cacheNames.ts +87 -0
  313. package/src/utils/canConstructReadableStream.ts +34 -0
  314. package/src/utils/canConstructResponseFromBodyStream.ts +37 -0
  315. package/src/utils/createCacheKey.ts +68 -0
  316. package/src/utils/deleteOutdatedCaches.ts +40 -0
  317. package/src/utils/dontWaitFor.ts +16 -0
  318. package/src/utils/executeQuotaErrorCallbacks.ts +33 -0
  319. package/src/utils/generateURLVariations.ts +55 -0
  320. package/src/utils/getFriendlyURL.ts +16 -0
  321. package/src/utils/logger.ts +95 -0
  322. package/src/utils/normalizeHandler.ts +40 -0
  323. package/src/utils/pluginUtils.ts +15 -0
  324. package/src/utils/printCleanupDetails.ts +38 -0
  325. package/src/utils/printInstallDetails.ts +53 -0
  326. package/src/utils/removeIgnoredSearchParams.ts +29 -0
  327. package/src/utils/resultingClientExists.ts +58 -0
  328. package/src/utils/timeout.ts +19 -0
  329. package/src/utils/waitUntil.ts +21 -0
  330. package/src/utils/welcome.ts +19 -0
@@ -0,0 +1,144 @@
1
+ import { f as finalAssertExports, l as logger, S as SerwistError } from './chunks/timeout.js';
2
+ import { S as Strategy, m as messages, c as cacheOkAndOpaquePlugin } from './chunks/NetworkOnly.js';
3
+ export { a as NetworkFirst, N as NetworkOnly, b as StrategyHandler } from './chunks/NetworkOnly.js';
4
+
5
+ class CacheFirst extends Strategy {
6
+ async _handle(request, handler) {
7
+ const logs = [];
8
+ if (process.env.NODE_ENV !== "production") {
9
+ finalAssertExports.isInstance(request, Request, {
10
+ moduleName: "serwist/strategies",
11
+ className: this.constructor.name,
12
+ funcName: "makeRequest",
13
+ paramName: "request"
14
+ });
15
+ }
16
+ let response = await handler.cacheMatch(request);
17
+ let error = undefined;
18
+ if (!response) {
19
+ if (process.env.NODE_ENV !== "production") {
20
+ logs.push(`No response found in the '${this.cacheName}' cache. Will respond with a network request.`);
21
+ }
22
+ try {
23
+ response = await handler.fetchAndCachePut(request);
24
+ } catch (err) {
25
+ if (err instanceof Error) {
26
+ error = err;
27
+ }
28
+ }
29
+ if (process.env.NODE_ENV !== "production") {
30
+ if (response) {
31
+ logs.push("Got response from network.");
32
+ } else {
33
+ logs.push("Unable to get a response from the network.");
34
+ }
35
+ }
36
+ } else {
37
+ if (process.env.NODE_ENV !== "production") {
38
+ logs.push(`Found a cached response in the '${this.cacheName}' cache.`);
39
+ }
40
+ }
41
+ if (process.env.NODE_ENV !== "production") {
42
+ logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
43
+ for (const log of logs){
44
+ logger.log(log);
45
+ }
46
+ messages.printFinalResponse(response);
47
+ logger.groupEnd();
48
+ }
49
+ if (!response) {
50
+ throw new SerwistError("no-response", {
51
+ url: request.url,
52
+ error
53
+ });
54
+ }
55
+ return response;
56
+ }
57
+ }
58
+
59
+ class CacheOnly extends Strategy {
60
+ async _handle(request, handler) {
61
+ if (process.env.NODE_ENV !== "production") {
62
+ finalAssertExports.isInstance(request, Request, {
63
+ moduleName: "serwist/strategies",
64
+ className: this.constructor.name,
65
+ funcName: "makeRequest",
66
+ paramName: "request"
67
+ });
68
+ }
69
+ const response = await handler.cacheMatch(request);
70
+ if (process.env.NODE_ENV !== "production") {
71
+ logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
72
+ if (response) {
73
+ logger.log(`Found a cached response in the '${this.cacheName}' cache.`);
74
+ messages.printFinalResponse(response);
75
+ } else {
76
+ logger.log(`No response found in the '${this.cacheName}' cache.`);
77
+ }
78
+ logger.groupEnd();
79
+ }
80
+ if (!response) {
81
+ throw new SerwistError("no-response", {
82
+ url: request.url
83
+ });
84
+ }
85
+ return response;
86
+ }
87
+ }
88
+
89
+ class StaleWhileRevalidate extends Strategy {
90
+ constructor(options = {}){
91
+ super(options);
92
+ if (!this.plugins.some((p)=>"cacheWillUpdate" in p)) {
93
+ this.plugins.unshift(cacheOkAndOpaquePlugin);
94
+ }
95
+ }
96
+ async _handle(request, handler) {
97
+ const logs = [];
98
+ if (process.env.NODE_ENV !== "production") {
99
+ finalAssertExports.isInstance(request, Request, {
100
+ moduleName: "serwist/strategies",
101
+ className: this.constructor.name,
102
+ funcName: "handle",
103
+ paramName: "request"
104
+ });
105
+ }
106
+ const fetchAndCachePromise = handler.fetchAndCachePut(request).catch(()=>{});
107
+ void handler.waitUntil(fetchAndCachePromise);
108
+ let response = await handler.cacheMatch(request);
109
+ let error = undefined;
110
+ if (response) {
111
+ if (process.env.NODE_ENV !== "production") {
112
+ logs.push(`Found a cached response in the '${this.cacheName}' cache. Will update with the network response in the background.`);
113
+ }
114
+ } else {
115
+ if (process.env.NODE_ENV !== "production") {
116
+ logs.push(`No response found in the '${this.cacheName}' cache. Will wait for the network response.`);
117
+ }
118
+ try {
119
+ response = await fetchAndCachePromise;
120
+ } catch (err) {
121
+ if (err instanceof Error) {
122
+ error = err;
123
+ }
124
+ }
125
+ }
126
+ if (process.env.NODE_ENV !== "production") {
127
+ logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
128
+ for (const log of logs){
129
+ logger.log(log);
130
+ }
131
+ messages.printFinalResponse(response);
132
+ logger.groupEnd();
133
+ }
134
+ if (!response) {
135
+ throw new SerwistError("no-response", {
136
+ url: request.url,
137
+ error
138
+ });
139
+ }
140
+ return response;
141
+ }
142
+ }
143
+
144
+ export { CacheFirst, CacheOnly, StaleWhileRevalidate, Strategy };
@@ -0,0 +1,146 @@
1
+ import type { RouteHandlerCallback, SerwistPlugin } from "../types.js";
2
+ import type { Strategy } from "../strategies/Strategy.js";
3
+ import type { CleanupResult, InstallResult, PrecacheEntry } from "../types.js";
4
+ interface PrecacheControllerOptions {
5
+ /**
6
+ * The cache to use for precaching.
7
+ */
8
+ cacheName?: string;
9
+ /**
10
+ * Plugins to use when precaching as well as responding to fetch
11
+ * events for precached assets.
12
+ */
13
+ plugins?: SerwistPlugin[];
14
+ /**
15
+ * Whether to attempt to get the response from the network if there's
16
+ * a precache miss.
17
+ */
18
+ fallbackToNetwork?: boolean;
19
+ /**
20
+ * The number of precache requests that should be made concurrently.
21
+ *
22
+ * @default 1
23
+ */
24
+ concurrentPrecaching?: number;
25
+ }
26
+ /**
27
+ * Performs efficient precaching of assets.
28
+ * @deprecated
29
+ */
30
+ export declare class PrecacheController {
31
+ private _installAndActiveListenersAdded?;
32
+ private _concurrentPrecaching;
33
+ private readonly _strategy;
34
+ private readonly _urlsToCacheKeys;
35
+ private readonly _urlsToCacheModes;
36
+ private readonly _cacheKeysToIntegrities;
37
+ /**
38
+ * Create a new PrecacheController.
39
+ *
40
+ * @param options
41
+ */
42
+ constructor({ cacheName, plugins, fallbackToNetwork, concurrentPrecaching }?: PrecacheControllerOptions);
43
+ /**
44
+ * The strategy created by this controller and
45
+ * used to cache assets and respond to fetch events.
46
+ */
47
+ get strategy(): Strategy;
48
+ /**
49
+ * Adds items to the precache list, removing any duplicates and
50
+ * stores the files in the precache cache when the service
51
+ * worker installs.
52
+ *
53
+ * This method can be called multiple times.
54
+ *
55
+ * @param entries Array of entries to precache.
56
+ */
57
+ precache(entries: (PrecacheEntry | string)[]): void;
58
+ /**
59
+ * This method will add items to the precache list, removing duplicates
60
+ * and ensuring the information is valid.
61
+ *
62
+ * @param entries Array of entries to precache.
63
+ */
64
+ addToCacheList(entries: (PrecacheEntry | string)[]): void;
65
+ /**
66
+ * Precaches new and updated assets. Call this method from the service worker
67
+ * install event.
68
+ *
69
+ * Note: this method calls `event.waitUntil()` for you, so you do not need
70
+ * to call it yourself in your event handlers.
71
+ *
72
+ * @param event
73
+ * @returns
74
+ */
75
+ install(event: ExtendableEvent): Promise<InstallResult>;
76
+ /**
77
+ * Deletes assets that are no longer present in the current precache manifest.
78
+ * Call this method from the service worker activate event.
79
+ *
80
+ * Note: this method calls `event.waitUntil()` for you, so you do not need
81
+ * to call it yourself in your event handlers.
82
+ *
83
+ * @param event
84
+ * @returns
85
+ */
86
+ activate(event: ExtendableEvent): Promise<CleanupResult>;
87
+ /**
88
+ * Returns a mapping of a precached URL to the corresponding cache key, taking
89
+ * into account the revision information for the URL.
90
+ *
91
+ * @returns A URL to cache key mapping.
92
+ */
93
+ getURLsToCacheKeys(): Map<string, string>;
94
+ /**
95
+ * Returns a list of all the URLs that have been precached by the current
96
+ * service worker.
97
+ *
98
+ * @returns The precached URLs.
99
+ */
100
+ getCachedURLs(): string[];
101
+ /**
102
+ * Returns the cache key used for storing a given URL. If that URL is
103
+ * unversioned, like `/index.html', then the cache key will be the original
104
+ * URL with a search parameter appended to it.
105
+ *
106
+ * @param url A URL whose cache key you want to look up.
107
+ * @returns The versioned URL that corresponds to a cache key
108
+ * for the original URL, or undefined if that URL isn't precached.
109
+ */
110
+ getCacheKeyForURL(url: string): string | undefined;
111
+ /**
112
+ * @param url A cache key whose SRI you want to look up.
113
+ * @returns The subresource integrity associated with the cache key,
114
+ * or undefined if it's not set.
115
+ */
116
+ getIntegrityForCacheKey(cacheKey: string): string | undefined;
117
+ /**
118
+ * This acts as a drop-in replacement for
119
+ * [`cache.match()`](https://developer.mozilla.org/en-US/docs/Web/API/Cache/match)
120
+ * with the following differences:
121
+ *
122
+ * - It knows what the name of the precache is, and only checks in that cache.
123
+ * - It allows you to pass in an "original" URL without versioning parameters,
124
+ * and it will automatically look up the correct cache key for the currently
125
+ * active revision of that URL.
126
+ *
127
+ * E.g., `matchPrecache('index.html')` will find the correct precached
128
+ * response for the currently active service worker, even if the actual cache
129
+ * key is `'/index.html?__WB_REVISION__=1234abcd'`.
130
+ *
131
+ * @param request The key (without revisioning parameters)
132
+ * to look up in the precache.
133
+ * @returns
134
+ */
135
+ matchPrecache(request: string | Request): Promise<Response | undefined>;
136
+ /**
137
+ * Returns a function that looks up `url` in the precache (taking into
138
+ * account revision information), and returns the corresponding `Response`.
139
+ *
140
+ * @param url The precached URL which will be used to lookup the response.
141
+ * @return
142
+ */
143
+ createHandlerBoundToURL(url: string): RouteHandlerCallback;
144
+ }
145
+ export {};
146
+ //# sourceMappingURL=PrecacheController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrecacheController.d.ts","sourceRoot":"","sources":["../../src/legacy/PrecacheController.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQvE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAU/E,UAAU,yBAAyB;IACjC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,+BAA+B,CAAC,CAAU;IAClD,OAAO,CAAC,qBAAqB,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IACrC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAkC;IACnE,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAA6G;IAC/I,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAkC;IAE1E;;;;OAIG;gBACS,EAAE,SAAS,EAAE,OAAY,EAAE,iBAAwB,EAAE,oBAAwB,EAAE,GAAE,yBAA8B;IAY3H;;;OAGG;IACH,IAAI,QAAQ,IAAI,QAAQ,CAEvB;IAED;;;;;;;;OAQG;IACH,QAAQ,CAAC,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI;IAUnD;;;;;OAKG;IACH,cAAc,CAAC,OAAO,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,GAAG,IAAI;IAwDzD;;;;;;;;;OASG;IACH,OAAO,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAmCvD;;;;;;;;;OASG;IACH,QAAQ,CAAC,KAAK,EAAE,eAAe,GAAG,OAAO,CAAC,aAAa,CAAC;IAuBxD;;;;;OAKG;IACH,kBAAkB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAIzC;;;;;OAKG;IACH,aAAa,IAAI,MAAM,EAAE;IAIzB;;;;;;;;OAQG;IACH,iBAAiB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAKlD;;;;OAIG;IACH,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI7D;;;;;;;;;;;;;;;;;OAiBG;IACG,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;IAU7E;;;;;;OAMG;IACH,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,oBAAoB;CAY3D"}
@@ -0,0 +1,62 @@
1
+ import type { HandlerDidErrorCallbackParam, SerwistPlugin } from "../types.js";
2
+ import type { PrecacheController } from "./PrecacheController.js";
3
+ /**
4
+ * @deprecated
5
+ */
6
+ export interface PrecacheFallbackEntry {
7
+ /**
8
+ * A function that checks whether the fallback entry can be used
9
+ * for a request.
10
+ */
11
+ matcher: (param: HandlerDidErrorCallbackParam) => boolean;
12
+ /**
13
+ * A precached URL to be used as a fallback.
14
+ */
15
+ url: string;
16
+ }
17
+ /**
18
+ * @deprecated
19
+ */
20
+ export interface PrecacheFallbackPluginOptions {
21
+ /**
22
+ * Precached URLs to be used as the fallback
23
+ * if the associated strategy can't generate a response.
24
+ */
25
+ fallbackUrls: (string | PrecacheFallbackEntry)[];
26
+ /**
27
+ * An optional `PrecacheController` instance. If not provided, the default
28
+ * `PrecacheController` will be used.
29
+ */
30
+ precacheController?: PrecacheController;
31
+ }
32
+ /**
33
+ * `PrecacheFallbackPlugin` allows you to specify offline fallbacks
34
+ * to be used when a given strategy is unable to generate a response.
35
+ *
36
+ * It does this by intercepting the `handlerDidError` plugin callback
37
+ * and returning a precached response, taking the expected revision parameter
38
+ * into account automatically.
39
+ *
40
+ * Unless you explicitly pass in a `PrecacheController` instance to the
41
+ * constructor, the default instance will be used. Generally speaking, most
42
+ * developers will end up using the default.
43
+ *
44
+ * @deprecated
45
+ */
46
+ export declare class PrecacheFallbackPlugin implements SerwistPlugin {
47
+ private readonly _fallbackUrls;
48
+ private readonly _precacheController;
49
+ /**
50
+ * Constructs a new `PrecacheFallbackPlugin` with the associated `fallbackUrls`.
51
+ *
52
+ * @param config
53
+ */
54
+ constructor({ fallbackUrls, precacheController }: PrecacheFallbackPluginOptions);
55
+ /**
56
+ * @returns The precache response for one of the fallback URLs, or `undefined` if
57
+ * nothing satisfies the conditions.
58
+ * @private
59
+ */
60
+ handlerDidError(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
61
+ }
62
+ //# sourceMappingURL=PrecacheFallbackPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrecacheFallbackPlugin.d.ts","sourceRoot":"","sources":["../../src/legacy/PrecacheFallbackPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,4BAA4B,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAGlE;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,4BAA4B,KAAK,OAAO,CAAC;IAC1D;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;CACb;AAED;;GAEG;AACH,MAAM,WAAW,6BAA6B;IAC5C;;;OAGG;IACH,YAAY,EAAE,CAAC,MAAM,GAAG,qBAAqB,CAAC,EAAE,CAAC;IACjD;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED;;;;;;;;;;;;;GAaG;AACH,qBAAa,sBAAuB,YAAW,aAAa;IAC1D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAqC;IACnE,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;IAEzD;;;;OAIG;gBACS,EAAE,YAAY,EAAE,kBAAkB,EAAE,EAAE,6BAA6B;IAK/E;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,4BAA4B;CAgB1D"}
@@ -0,0 +1,19 @@
1
+ import { Route } from "../Route.js";
2
+ import type { PrecacheRouteOptions } from "../types.js";
3
+ import type { PrecacheController } from "./PrecacheController.js";
4
+ /**
5
+ * A subclass of `serwist.Route` that takes a `serwist/legacy.PrecacheController`
6
+ * instance and uses it to match incoming requests and handle fetching
7
+ * responses from the precache.
8
+ * @deprecated
9
+ */
10
+ export declare class PrecacheRoute extends Route {
11
+ /**
12
+ * @param precacheController A `PrecacheController`
13
+ * instance used to both match requests and respond to fetch events.
14
+ * @param options Options to control how requests are matched
15
+ * against the list of precached URLs.
16
+ */
17
+ constructor(precacheController: PrecacheController, options?: PrecacheRouteOptions);
18
+ }
19
+ //# sourceMappingURL=PrecacheRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrecacheRoute.d.ts","sourceRoot":"","sources":["../../src/legacy/PrecacheRoute.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE;;;;;GAKG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC;;;;;OAKG;gBACS,kBAAkB,EAAE,kBAAkB,EAAE,OAAO,CAAC,EAAE,oBAAoB;CAkBnF"}
@@ -0,0 +1,151 @@
1
+ import type { RouteHandler, RouteHandlerCallbackOptions, RouteMatchCallback, RouteMatchCallbackOptions } from "../types.js";
2
+ import type { Route } from "../Route.js";
3
+ import type { HTTPMethod } from "../constants.js";
4
+ /**
5
+ * `Router` can be used to process a `FetchEvent` using one or more `Route`(s), responding with a `Response`
6
+ * if a matching route exists.
7
+ *
8
+ * If no `Route` matches given a `Request`, the `Router` will use the default handler if one is defined.
9
+ *
10
+ * Should the matching Route throw an error, the Router will use the catch handler if one is defined to
11
+ * gracefully deal with issues and respond with a `Request`.
12
+ *
13
+ * If a `Request` matches multiple routes, the earliest registered route will be used to respond to the `Request`.
14
+ * @deprecated
15
+ */
16
+ export declare class Router {
17
+ private readonly _routes;
18
+ private readonly _defaultHandlerMap;
19
+ private _fetchListenerHandler;
20
+ private _cacheListenerHandler;
21
+ private _catchHandler?;
22
+ /**
23
+ * Initializes a new Router.
24
+ */
25
+ constructor();
26
+ /**
27
+ * @returns routes A `Map` of HTTP method name (`'GET'`, etc.) to an array of all the corresponding `Route`
28
+ * instances that are registered.
29
+ */
30
+ get routes(): Map<HTTPMethod, Route[]>;
31
+ /**
32
+ * Adds a `fetch` event listener to respond to events when a `Route` matches
33
+ * the event's request. Effectively no-op if `addFEtchListener` has been
34
+ * called, but `removeFetchListener` has not.
35
+ */
36
+ addFetchListener(): void;
37
+ /**
38
+ * Removes `fetch` event listener added by `addFetchListener`.
39
+ * Effectively no-op if either `addFetchListener` has not been called or,
40
+ * if it has, so has `removeFetchListener`.
41
+ */
42
+ removeFetchListener(): void;
43
+ /**
44
+ * Adds a `message` event listener for URLs to cache from the window.
45
+ * This is useful to cache resources loaded on the page prior to when the
46
+ * service worker started controlling it. Effectively no-op if `addCacheListener`
47
+ * has been called, but `removeCacheListener` hasn't.
48
+ *
49
+ * The format of the message data sent from the window should be as follows.
50
+ * Where the `urlsToCache` array may consist of URL strings or an array of
51
+ * URL string + `requestInit` object (the same as you'd pass to `fetch()`).
52
+ *
53
+ * ```
54
+ * {
55
+ * type: 'CACHE_URLS',
56
+ * payload: {
57
+ * urlsToCache: [
58
+ * './script1.js',
59
+ * './script2.js',
60
+ * ['./script3.js', {mode: 'no-cors'}],
61
+ * ],
62
+ * },
63
+ * }
64
+ * ```
65
+ */
66
+ addCacheListener(): void;
67
+ /**
68
+ * Removes the `message` event listener added by `addCacheListener`.
69
+ * Effectively no-op if either `addCacheListener` has not been called or,
70
+ * if it has, so has `removeCacheListener`.
71
+ */
72
+ removeCacheListener(): void;
73
+ /**
74
+ * Apply the routing rules to a `FetchEvent` object to get a `Response` from an
75
+ * appropriate `Route`'s handler.
76
+ *
77
+ * @param options
78
+ * @returns A promise is returned if a registered route can handle the request.
79
+ * If there is no matching route and there's no `defaultHandler`, `undefined`
80
+ * is returned.
81
+ */
82
+ handleRequest({ request, event, }: {
83
+ /**
84
+ * The request to handle.
85
+ */
86
+ request: Request;
87
+ /**
88
+ * The event that triggered the request.
89
+ */
90
+ event: ExtendableEvent;
91
+ }): Promise<Response> | undefined;
92
+ /**
93
+ * Checks a request and URL (and optionally an event) against the list of
94
+ * registered routes, and if there's a match, returns the corresponding
95
+ * route along with any params generated by the match.
96
+ *
97
+ * @param options
98
+ * @returns An object with `route` and `params` properties. They are populated
99
+ * if a matching route was found or `undefined` otherwise.
100
+ */
101
+ findMatchingRoute({ url, sameOrigin, request, event }: RouteMatchCallbackOptions): {
102
+ route?: Route;
103
+ params?: RouteHandlerCallbackOptions["params"];
104
+ };
105
+ /**
106
+ * Define a default `handler` that's called when no routes explicitly
107
+ * match the incoming request.
108
+ *
109
+ * Each HTTP method (`'GET'`, `'POST'`, etc.) gets its own default handler.
110
+ *
111
+ * Without a default handler, unmatched requests will go against the
112
+ * network as if there were no service worker present.
113
+ *
114
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
115
+ * @param method The HTTP method to associate with this default handler. Each method
116
+ * has its own default. Defaults to `'GET'`.
117
+ */
118
+ setDefaultHandler(handler: RouteHandler, method?: HTTPMethod): void;
119
+ /**
120
+ * If a `Route` throws an error while handling a request, this `handler`
121
+ * will be called and given a chance to provide a response.
122
+ *
123
+ * @param handler A callback function that returns a Promise resulting
124
+ * in a Response.
125
+ */
126
+ setCatchHandler(handler: RouteHandler): void;
127
+ /**
128
+ * Registers a `RegExp`, string, or function with a caching
129
+ * strategy to the `Router`.
130
+ *
131
+ * @param capture If the capture param is a `Route`, all other arguments will be ignored.
132
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
133
+ * This parameter is required if `capture` is not a `Route` object.
134
+ * @param method The HTTP method to match the Route against. Defaults to `'GET'`.
135
+ * @returns The generated `Route`.
136
+ */
137
+ registerCapture(capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod): Route;
138
+ /**
139
+ * Registers a `Route` with the router.
140
+ *
141
+ * @param route The `Route` to register.
142
+ */
143
+ registerRoute(route: Route): void;
144
+ /**
145
+ * Unregisters a `Route` with the `Router`.
146
+ *
147
+ * @param route The `Route` to unregister.
148
+ */
149
+ unregisterRoute(route: Route): void;
150
+ }
151
+ //# sourceMappingURL=Router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/legacy/Router.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAsB,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAKhJ,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAgBlD;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA2B;IACnD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAsC;IACzE,OAAO,CAAC,qBAAqB,CAA2C;IACxE,OAAO,CAAC,qBAAqB,CAAuD;IACpF,OAAO,CAAC,aAAa,CAAC,CAAqB;IAE3C;;OAEG;;IAMH;;;OAGG;IACH,IAAI,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,KAAK,EAAE,CAAC,CAErC;IAED;;;;OAIG;IACH,gBAAgB,IAAI,IAAI;IAaxB;;;;OAIG;IACH,mBAAmB,IAAI,IAAI;IAO3B;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,gBAAgB,IAAI,IAAI;IAiCxB;;;;OAIG;IACH,mBAAmB,IAAI,IAAI;IAM3B;;;;;;;;OAQG;IACH,aAAa,CAAC,EACZ,OAAO,EACP,KAAK,GACN,EAAE;QACD;;WAEG;QACH,OAAO,EAAE,OAAO,CAAC;QACjB;;WAEG;QACH,KAAK,EAAE,eAAe,CAAC;KACxB,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,SAAS;IA8HjC;;;;;;;;OAQG;IACH,iBAAiB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,yBAAyB,GAAG;QACjF,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,CAAC,EAAE,2BAA2B,CAAC,QAAQ,CAAC,CAAC;KAChD;IA+CD;;;;;;;;;;;;OAYG;IACH,iBAAiB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,GAAE,UAA0B,GAAG,IAAI;IAIlF;;;;;;OAMG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;IAI5C;;;;;;;;;OASG;IACH,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,EAAE,OAAO,CAAC,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,UAAU,GAAG,KAAK;IAM1H;;;;OAIG;IACH,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IA+CjC;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;CAcpC"}
@@ -0,0 +1,9 @@
1
+ import type { SerwistPlugin } from "../types.js";
2
+ /**
3
+ * Adds plugins to the precaching strategy.
4
+ *
5
+ * @param plugins
6
+ * @deprecated
7
+ */
8
+ export declare const addPlugins: (plugins: SerwistPlugin[]) => void;
9
+ //# sourceMappingURL=addPlugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addPlugins.d.ts","sourceRoot":"","sources":["../../src/legacy/addPlugins.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,YAAa,aAAa,EAAE,KAAG,IAGrD,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { PrecacheRouteOptions } from "../types.js";
2
+ /**
3
+ * Add a `fetch` listener to the service worker that will
4
+ * respond to
5
+ * [network requests](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers#Custom_responses_to_requests)
6
+ * with precached assets.
7
+ *
8
+ * Requests for assets that aren't precached, the `FetchEvent` will not be
9
+ * responded to, allowing the event to fall through to other `fetch` event
10
+ * listeners.
11
+ *
12
+ * @param options See `serwist.PrecacheRouteOptions`.
13
+ * @deprecated
14
+ */
15
+ export declare const addRoute: (options?: PrecacheRouteOptions) => void;
16
+ //# sourceMappingURL=addRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addRoute.d.ts","sourceRoot":"","sources":["../../src/legacy/addRoute.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAKxD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,QAAQ,aAAc,oBAAoB,KAAG,IAGzD,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { RouteHandlerCallback } from "../types.js";
2
+ /**
3
+ * Helper function that calls `PrecacheController#createHandlerBoundToURL`
4
+ * on the default `PrecacheController` instance.
5
+ *
6
+ * If you are creating your own `PrecacheController`, then call the
7
+ * `PrecacheController#createHandlerBoundToURL` on that instance,
8
+ * instead of using this function.
9
+ *
10
+ * @param url The precached URL which will be used to lookup the
11
+ * `Response`.
12
+ * @param fallbackToNetwork Whether to attempt to get the
13
+ * response from the network if there's a precache miss.
14
+ * @return
15
+ * @deprecated
16
+ */
17
+ export declare const createHandlerBoundToURL: (url: string) => RouteHandlerCallback;
18
+ //# sourceMappingURL=createHandlerBoundToURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createHandlerBoundToURL.d.ts","sourceRoot":"","sources":["../../src/legacy/createHandlerBoundToURL.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,uBAAuB,QAAS,MAAM,KAAG,oBAGrD,CAAC"}
@@ -0,0 +1,59 @@
1
+ import type { PrecacheRouteOptions, RuntimeCaching } from "../types.js";
2
+ import type { PrecacheController } from "./PrecacheController.js";
3
+ import type { Router } from "./Router.js";
4
+ import type { PrecacheFallbackEntry } from "./PrecacheFallbackPlugin.js";
5
+ export interface FallbackEntry extends PrecacheFallbackEntry {
6
+ /**
7
+ * The revision used for precaching.
8
+ */
9
+ revision: string;
10
+ }
11
+ export interface FallbacksOptions {
12
+ /**
13
+ * A list of fallback entries.
14
+ */
15
+ entries: FallbackEntry[];
16
+ /**
17
+ * Precache options that will be used for your
18
+ * fallback entries.
19
+ */
20
+ precacheOptions?: PrecacheRouteOptions;
21
+ }
22
+ export interface FallbacksOptions {
23
+ /**
24
+ * An optional `PrecacheController` instance. If not provided, the singleton
25
+ * `PrecacheController` will be used.
26
+ */
27
+ precacheController?: PrecacheController;
28
+ /**
29
+ * An optional `Router` instance. If not provided, the singleton `Router`
30
+ * will be used.
31
+ */
32
+ router?: Router;
33
+ /**
34
+ * Your previous list of caching strategies.
35
+ */
36
+ runtimeCaching: RuntimeCaching[];
37
+ /**
38
+ * A list of fallback entries.
39
+ */
40
+ entries: FallbackEntry[];
41
+ /**
42
+ * Precache options that will be used for your
43
+ * fallback entries.
44
+ */
45
+ precacheOptions?: PrecacheRouteOptions;
46
+ }
47
+ /**
48
+ * Precaches routes so that they can be used as a fallback when
49
+ * a Strategy fails to generate a response.
50
+ *
51
+ * Note: This function mutates `runtimeCaching`. It also precaches the URLs
52
+ * defined in `entries`, so you must NOT precache any of them beforehand.
53
+ *
54
+ * @param options
55
+ * @returns The modified `runtimeCaching` array.
56
+ * @deprecated
57
+ */
58
+ export declare const fallbacks: ({ precacheController, router, runtimeCaching, entries, precacheOptions, }: FallbacksOptions) => RuntimeCaching[];
59
+ //# sourceMappingURL=fallbacks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fallbacks.d.ts","sourceRoot":"","sources":["../../src/legacy/fallbacks.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAElE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEzE,MAAM,WAAW,aAAc,SAAQ,qBAAqB;IAC1D;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,cAAc,EAAE,cAAc,EAAE,CAAC;IACjC;;OAEG;IACH,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,8EAMnB,gBAAgB,KAAG,cAAc,EAqBnC,CAAC"}