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

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 (262) hide show
  1. package/dist/abstractions/Serwist.d.ts +82 -0
  2. package/dist/abstractions/Serwist.d.ts.map +1 -0
  3. package/dist/{disableDevLogs.d.ts → abstractions/disableDevLogs.d.ts} +2 -0
  4. package/dist/abstractions/disableDevLogs.d.ts.map +1 -0
  5. package/dist/{fallbacks.d.ts → abstractions/fallbacks.d.ts} +9 -20
  6. package/dist/abstractions/fallbacks.d.ts.map +1 -0
  7. package/dist/{handlePrecaching.d.ts → abstractions/handlePrecaching.d.ts} +8 -10
  8. package/dist/abstractions/handlePrecaching.d.ts.map +1 -0
  9. package/dist/abstractions/installSerwist.d.ts +15 -0
  10. package/dist/abstractions/installSerwist.d.ts.map +1 -0
  11. package/dist/abstractions/navigationPreload.d.ts +20 -0
  12. package/dist/abstractions/navigationPreload.d.ts.map +1 -0
  13. package/dist/{registerRuntimeCaching.d.ts → abstractions/registerRuntimeCaching.d.ts} +2 -0
  14. package/dist/abstractions/registerRuntimeCaching.d.ts.map +1 -0
  15. package/dist/abstractions/types.d.ts +29 -0
  16. package/dist/abstractions/types.d.ts.map +1 -0
  17. package/dist/chunks/NavigationRoute.js +54 -0
  18. package/dist/chunks/NetworkOnly.js +193 -0
  19. package/dist/chunks/PrecacheFallbackPlugin.js +573 -0
  20. package/dist/chunks/Strategy.js +410 -0
  21. package/dist/chunks/precacheAndRoute.js +113 -0
  22. package/dist/chunks/registerRoute.js +7 -0
  23. package/dist/chunks/singletonPrecacheController.js +433 -0
  24. package/dist/chunks/singletonRouter.js +435 -0
  25. package/dist/index.d.ts +11 -9
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +121 -124
  28. package/dist/index.plugins.d.ts +41 -0
  29. package/dist/index.plugins.d.ts.map +1 -0
  30. package/dist/index.plugins.js +671 -0
  31. package/dist/index.precaching.d.ts +25 -0
  32. package/dist/index.precaching.d.ts.map +1 -0
  33. package/dist/index.precaching.js +24 -0
  34. package/dist/index.routing.d.ts +15 -0
  35. package/dist/index.routing.d.ts.map +1 -0
  36. package/dist/index.routing.js +19 -0
  37. package/dist/index.strategies.d.ts +22 -0
  38. package/dist/index.strategies.d.ts.map +1 -0
  39. package/dist/index.strategies.js +146 -0
  40. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +23 -0
  41. package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
  42. package/dist/plugins/backgroundSync/Queue.d.ts +166 -0
  43. package/dist/plugins/backgroundSync/Queue.d.ts.map +1 -0
  44. package/dist/plugins/backgroundSync/QueueDb.d.ts +90 -0
  45. package/dist/plugins/backgroundSync/QueueDb.d.ts.map +1 -0
  46. package/dist/plugins/backgroundSync/QueueStore.d.ts +75 -0
  47. package/dist/plugins/backgroundSync/QueueStore.d.ts.map +1 -0
  48. package/dist/plugins/backgroundSync/StorableRequest.d.ts +51 -0
  49. package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +1 -0
  50. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +45 -0
  51. package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
  52. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +27 -0
  53. package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
  54. package/dist/plugins/broadcastUpdate/constants.d.ts +5 -0
  55. package/dist/plugins/broadcastUpdate/constants.d.ts.map +1 -0
  56. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +11 -0
  57. package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
  58. package/dist/plugins/broadcastUpdate/types.d.ts +34 -0
  59. package/dist/plugins/broadcastUpdate/types.d.ts.map +1 -0
  60. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +40 -0
  61. package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +1 -0
  62. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +27 -0
  63. package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
  64. package/dist/plugins/expiration/CacheExpiration.d.ts +66 -0
  65. package/dist/plugins/expiration/CacheExpiration.d.ts.map +1 -0
  66. package/dist/plugins/expiration/ExpirationPlugin.d.ts +116 -0
  67. package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +1 -0
  68. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +73 -0
  69. package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
  70. package/dist/plugins/googleAnalytics/constants.d.ts +10 -0
  71. package/dist/plugins/googleAnalytics/constants.d.ts.map +1 -0
  72. package/dist/plugins/googleAnalytics/initialize.d.ts +34 -0
  73. package/dist/plugins/googleAnalytics/initialize.d.ts.map +1 -0
  74. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +54 -0
  75. package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
  76. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +19 -0
  77. package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
  78. package/dist/plugins/rangeRequests/createPartialResponse.d.ts +18 -0
  79. package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +1 -0
  80. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +14 -0
  81. package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
  82. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +12 -0
  83. package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
  84. package/dist/precaching/PrecacheController.d.ts +145 -0
  85. package/dist/precaching/PrecacheController.d.ts.map +1 -0
  86. package/dist/precaching/PrecacheRoute.d.ts +20 -0
  87. package/dist/precaching/PrecacheRoute.d.ts.map +1 -0
  88. package/dist/precaching/PrecacheStrategy.d.ts +68 -0
  89. package/dist/precaching/PrecacheStrategy.d.ts.map +1 -0
  90. package/dist/precaching/addPlugins.d.ts +8 -0
  91. package/dist/precaching/addPlugins.d.ts.map +1 -0
  92. package/dist/precaching/addRoute.d.ts +15 -0
  93. package/dist/precaching/addRoute.d.ts.map +1 -0
  94. package/dist/precaching/cleanupOutdatedCaches.d.ts +6 -0
  95. package/dist/precaching/cleanupOutdatedCaches.d.ts.map +1 -0
  96. package/dist/precaching/createHandlerBoundToURL.d.ts +17 -0
  97. package/dist/precaching/createHandlerBoundToURL.d.ts.map +1 -0
  98. package/dist/precaching/getCacheKeyForURL.d.ts +20 -0
  99. package/dist/precaching/getCacheKeyForURL.d.ts.map +1 -0
  100. package/dist/precaching/matchPrecache.d.ts +14 -0
  101. package/dist/precaching/matchPrecache.d.ts.map +1 -0
  102. package/dist/precaching/precache.d.ts +19 -0
  103. package/dist/precaching/precache.d.ts.map +1 -0
  104. package/dist/precaching/precacheAndRoute.d.ts +14 -0
  105. package/dist/precaching/precacheAndRoute.d.ts.map +1 -0
  106. package/dist/precaching/singletonPrecacheController.d.ts +38 -0
  107. package/dist/precaching/singletonPrecacheController.d.ts.map +1 -0
  108. package/dist/precaching/types.d.ts +37 -0
  109. package/dist/precaching/types.d.ts.map +1 -0
  110. package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts +17 -0
  111. package/dist/precaching/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
  112. package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts +15 -0
  113. package/dist/precaching/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
  114. package/dist/precaching/utils/createCacheKey.d.ts +16 -0
  115. package/dist/precaching/utils/createCacheKey.d.ts.map +1 -0
  116. package/dist/precaching/utils/deleteOutdatedCaches.d.ts +18 -0
  117. package/dist/precaching/utils/deleteOutdatedCaches.d.ts.map +1 -0
  118. package/dist/precaching/utils/generateURLVariations.d.ts +12 -0
  119. package/dist/precaching/utils/generateURLVariations.d.ts.map +1 -0
  120. package/dist/precaching/utils/getCacheKeyForURL.d.ts +14 -0
  121. package/dist/precaching/utils/getCacheKeyForURL.d.ts.map +1 -0
  122. package/dist/precaching/utils/printCleanupDetails.d.ts +6 -0
  123. package/dist/precaching/utils/printCleanupDetails.d.ts.map +1 -0
  124. package/dist/precaching/utils/printInstallDetails.d.ts +7 -0
  125. package/dist/precaching/utils/printInstallDetails.d.ts.map +1 -0
  126. package/dist/precaching/utils/removeIgnoredSearchParams.d.ts +12 -0
  127. package/dist/precaching/utils/removeIgnoredSearchParams.d.ts.map +1 -0
  128. package/dist/routing/NavigationRoute.d.ts +57 -0
  129. package/dist/routing/NavigationRoute.d.ts.map +1 -0
  130. package/dist/routing/RegExpRoute.d.ts +24 -0
  131. package/dist/routing/RegExpRoute.d.ts.map +1 -0
  132. package/dist/routing/Route.d.ts +33 -0
  133. package/dist/routing/Route.d.ts.map +1 -0
  134. package/dist/routing/Router.d.ts +150 -0
  135. package/dist/routing/Router.d.ts.map +1 -0
  136. package/dist/routing/parseRoute.d.ts +16 -0
  137. package/dist/routing/parseRoute.d.ts.map +1 -0
  138. package/dist/routing/registerRoute.d.ts +15 -0
  139. package/dist/routing/registerRoute.d.ts.map +1 -0
  140. package/dist/routing/setCatchHandler.d.ts +9 -0
  141. package/dist/routing/setCatchHandler.d.ts.map +1 -0
  142. package/dist/routing/setDefaultHandler.d.ts +12 -0
  143. package/dist/routing/setDefaultHandler.d.ts.map +1 -0
  144. package/dist/routing/singletonRouter.d.ts +47 -0
  145. package/dist/routing/singletonRouter.d.ts.map +1 -0
  146. package/dist/routing/unregisterRoute.d.ts +8 -0
  147. package/dist/routing/unregisterRoute.d.ts.map +1 -0
  148. package/dist/routing/utils/constants.d.ts +15 -0
  149. package/dist/routing/utils/constants.d.ts.map +1 -0
  150. package/dist/routing/utils/normalizeHandler.d.ts +10 -0
  151. package/dist/routing/utils/normalizeHandler.d.ts.map +1 -0
  152. package/dist/strategies/CacheFirst.d.ts +23 -0
  153. package/dist/strategies/CacheFirst.d.ts.map +1 -0
  154. package/dist/strategies/CacheOnly.d.ts +20 -0
  155. package/dist/strategies/CacheOnly.d.ts.map +1 -0
  156. package/dist/strategies/NetworkFirst.d.ts +61 -0
  157. package/dist/strategies/NetworkFirst.d.ts.map +1 -0
  158. package/dist/strategies/NetworkOnly.d.ts +32 -0
  159. package/dist/strategies/NetworkOnly.d.ts.map +1 -0
  160. package/dist/strategies/StaleWhileRevalidate.d.ts +35 -0
  161. package/dist/strategies/StaleWhileRevalidate.d.ts.map +1 -0
  162. package/dist/strategies/Strategy.d.ts +83 -0
  163. package/dist/strategies/Strategy.d.ts.map +1 -0
  164. package/dist/strategies/StrategyHandler.d.ts +189 -0
  165. package/dist/strategies/StrategyHandler.d.ts.map +1 -0
  166. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
  167. package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
  168. package/dist/strategies/utils/messages.d.ts +5 -0
  169. package/dist/strategies/utils/messages.d.ts.map +1 -0
  170. package/package.json +42 -19
  171. package/src/abstractions/Serwist.ts +177 -0
  172. package/src/abstractions/disableDevLogs.ts +10 -0
  173. package/src/abstractions/fallbacks.ts +65 -0
  174. package/src/abstractions/handlePrecaching.ts +65 -0
  175. package/src/abstractions/installSerwist.ts +28 -0
  176. package/src/abstractions/navigationPreload.ts +64 -0
  177. package/src/abstractions/registerRuntimeCaching.ts +17 -0
  178. package/src/abstractions/types.ts +29 -0
  179. package/src/index.plugins.ts +95 -0
  180. package/src/index.precaching.ts +41 -0
  181. package/src/index.routing.ts +28 -0
  182. package/src/index.strategies.ts +26 -0
  183. package/src/index.ts +31 -9
  184. package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +39 -0
  185. package/src/plugins/backgroundSync/Queue.ts +438 -0
  186. package/src/plugins/backgroundSync/QueueDb.ts +176 -0
  187. package/src/plugins/backgroundSync/QueueStore.ts +161 -0
  188. package/src/plugins/backgroundSync/StorableRequest.ts +142 -0
  189. package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +159 -0
  190. package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +43 -0
  191. package/src/plugins/broadcastUpdate/constants.ts +12 -0
  192. package/src/plugins/broadcastUpdate/responsesAreSame.ts +48 -0
  193. package/src/plugins/broadcastUpdate/types.ts +37 -0
  194. package/src/plugins/cacheableResponse/CacheableResponse.ts +141 -0
  195. package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +46 -0
  196. package/src/plugins/expiration/CacheExpiration.ts +192 -0
  197. package/src/plugins/expiration/ExpirationPlugin.ts +297 -0
  198. package/src/plugins/expiration/models/CacheTimestampsModel.ts +184 -0
  199. package/src/plugins/googleAnalytics/constants.ts +22 -0
  200. package/src/plugins/googleAnalytics/initialize.ts +213 -0
  201. package/src/plugins/precaching/PrecacheFallbackPlugin.ts +86 -0
  202. package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +39 -0
  203. package/src/plugins/rangeRequests/createPartialResponse.ts +92 -0
  204. package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +58 -0
  205. package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +54 -0
  206. package/src/precaching/PrecacheController.ts +332 -0
  207. package/src/precaching/PrecacheRoute.ts +50 -0
  208. package/src/precaching/PrecacheStrategy.ts +238 -0
  209. package/src/precaching/addPlugins.ts +21 -0
  210. package/src/precaching/addRoute.ts +30 -0
  211. package/src/precaching/cleanupOutdatedCaches.ts +33 -0
  212. package/src/precaching/createHandlerBoundToURL.ts +30 -0
  213. package/src/precaching/getCacheKeyForURL.ts +33 -0
  214. package/src/precaching/matchPrecache.ts +25 -0
  215. package/src/precaching/precache.ts +31 -0
  216. package/src/precaching/precacheAndRoute.ts +27 -0
  217. package/src/precaching/singletonPrecacheController.ts +57 -0
  218. package/src/precaching/types.ts +46 -0
  219. package/src/precaching/utils/PrecacheCacheKeyPlugin.ts +36 -0
  220. package/src/precaching/utils/PrecacheInstallReportPlugin.ts +49 -0
  221. package/src/precaching/utils/createCacheKey.ts +68 -0
  222. package/src/precaching/utils/deleteOutdatedCaches.ts +40 -0
  223. package/src/precaching/utils/generateURLVariations.ts +55 -0
  224. package/src/precaching/utils/getCacheKeyForURL.ts +36 -0
  225. package/src/precaching/utils/printCleanupDetails.ts +38 -0
  226. package/src/precaching/utils/printInstallDetails.ts +53 -0
  227. package/src/precaching/utils/removeIgnoredSearchParams.ts +29 -0
  228. package/src/routing/NavigationRoute.ts +119 -0
  229. package/src/routing/RegExpRoute.ts +74 -0
  230. package/src/routing/Route.ts +68 -0
  231. package/src/routing/Router.ts +481 -0
  232. package/src/routing/parseRoute.ts +78 -0
  233. package/src/routing/registerRoute.ts +27 -0
  234. package/src/routing/setCatchHandler.ts +21 -0
  235. package/src/routing/setDefaultHandler.ts +24 -0
  236. package/src/routing/singletonRouter.ts +76 -0
  237. package/src/routing/unregisterRoute.ts +11 -0
  238. package/src/routing/utils/constants.ts +24 -0
  239. package/src/routing/utils/normalizeHandler.ts +40 -0
  240. package/src/strategies/CacheFirst.ts +87 -0
  241. package/src/strategies/CacheOnly.ts +58 -0
  242. package/src/strategies/NetworkFirst.ts +228 -0
  243. package/src/strategies/NetworkOnly.ts +96 -0
  244. package/src/strategies/StaleWhileRevalidate.ts +109 -0
  245. package/src/strategies/Strategy.ts +202 -0
  246. package/src/strategies/StrategyHandler.ts +557 -0
  247. package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +26 -0
  248. package/src/strategies/utils/messages.ts +20 -0
  249. package/dist/disableDevLogs.d.ts.map +0 -1
  250. package/dist/fallbacks.d.ts.map +0 -1
  251. package/dist/handlePrecaching.d.ts.map +0 -1
  252. package/dist/installSerwist.d.ts +0 -21
  253. package/dist/installSerwist.d.ts.map +0 -1
  254. package/dist/registerRuntimeCaching.d.ts.map +0 -1
  255. package/dist/types.d.ts +0 -110
  256. package/dist/types.d.ts.map +0 -1
  257. package/src/disableDevLogs.ts +0 -10
  258. package/src/fallbacks.ts +0 -83
  259. package/src/handlePrecaching.ts +0 -65
  260. package/src/installSerwist.ts +0 -106
  261. package/src/registerRuntimeCaching.ts +0 -84
  262. package/src/types.ts +0 -113
@@ -0,0 +1,14 @@
1
+ import type { PrecacheRouteOptions } from "../types.js";
2
+ /**
3
+ * This function will take the request URL and manipulate it based on the
4
+ * configuration options.
5
+ *
6
+ * @param url
7
+ * @param options
8
+ * @returns Returns the URL in the cache that matches the request,
9
+ * if possible.
10
+ *
11
+ * @private
12
+ */
13
+ export declare const getCacheKeyForURL: (url: string, options: PrecacheRouteOptions) => string | undefined;
14
+ //# sourceMappingURL=getCacheKeyForURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCacheKeyForURL.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/getCacheKeyForURL.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAGxD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,QAAS,MAAM,WAAW,oBAAoB,KAAG,MAAM,GAAG,SAYvF,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param deletedURLs
3
+ * @private
4
+ */
5
+ export declare function printCleanupDetails(deletedURLs: string[]): void;
6
+ //# sourceMappingURL=printCleanupDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printCleanupDetails.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/printCleanupDetails.ts"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAO/D"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param urlsToPrecache
3
+ * @param urlsAlreadyPrecached
4
+ * @private
5
+ */
6
+ export declare function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]): void;
7
+ //# sourceMappingURL=printInstallDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printInstallDetails.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/printInstallDetails.ts"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,GAAG,IAAI,CAiBlG"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Removes any URL search parameters that should be ignored.
3
+ *
4
+ * @param urlObject The original URL.
5
+ * @param ignoreURLParametersMatching RegExps to test against
6
+ * each search parameter name. Matches mean that the search parameter should be
7
+ * ignored.
8
+ * @returns The URL with any ignored search parameters removed.
9
+ * @private
10
+ */
11
+ export declare function removeIgnoredSearchParams(urlObject: URL, ignoreURLParametersMatching?: RegExp[]): URL;
12
+ //# sourceMappingURL=removeIgnoredSearchParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeIgnoredSearchParams.d.ts","sourceRoot":"","sources":["../../../src/precaching/utils/removeIgnoredSearchParams.ts"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,GAAG,EAAE,2BAA2B,GAAE,MAAM,EAAO,GAAG,GAAG,CAUzG"}
@@ -0,0 +1,57 @@
1
+ import type { RouteHandler } from "@serwist/core";
2
+ import { Route } from "./Route.js";
3
+ export interface NavigationRouteMatchOptions {
4
+ /**
5
+ * If any of these patterns
6
+ * match the URL's pathname and search parameter, the route will handle the
7
+ * request (assuming the denylist doesn't match).
8
+ *
9
+ * @default [/./]
10
+ */
11
+ allowlist?: RegExp[];
12
+ /**
13
+ * If any of these patterns match, the route will not handle the request (even if a allowlist RegExp matches).
14
+ */
15
+ denylist?: RegExp[];
16
+ }
17
+ /**
18
+ * NavigationRoute makes it easy to create a `@serwist/routing` Route that matches for browser
19
+ * [navigation requests](https://developers.google.com/web/fundamentals/primers/service-workers/high-performance-loading#first_what_are_navigation_requests).
20
+ *
21
+ * It will only match incoming Requests whose [mode](https://fetch.spec.whatwg.org/#concept-request-mode) is set to `navigate`.
22
+ *
23
+ * You can optionally only apply this route to a subset of navigation requests
24
+ * by using one or both of the `denylist` and `allowlist` parameters.
25
+ */
26
+ export declare class NavigationRoute extends Route {
27
+ private readonly _allowlist;
28
+ private readonly _denylist;
29
+ /**
30
+ * If both `denylist` and `allowlist` are provided, the `denylist` will
31
+ * take precedence and the request will not match this route.
32
+ *
33
+ * The regular expressions in `allowlist` and `denylist`
34
+ * are matched against the concatenated
35
+ * [`pathname`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/pathname)
36
+ * and [`search`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLHyperlinkElementUtils/search)
37
+ * portions of the requested URL.
38
+ *
39
+ * *Note*: These RegExps may be evaluated against every destination URL during
40
+ * a navigation. Avoid using
41
+ * [complex RegExps](https://github.com/GoogleChrome/workbox/issues/3077),
42
+ * or else your users may see delays when navigating your site.
43
+ *
44
+ * @param handler A callback function that returns a Promise resulting in a Response.
45
+ * @param options
46
+ */
47
+ constructor(handler: RouteHandler, { allowlist, denylist }?: NavigationRouteMatchOptions);
48
+ /**
49
+ * Routes match handler.
50
+ *
51
+ * @param options
52
+ * @returns
53
+ * @private
54
+ */
55
+ private _match;
56
+ }
57
+ //# sourceMappingURL=NavigationRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NavigationRoute.d.ts","sourceRoot":"","sources":["../../src/routing/NavigationRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAA6B,MAAM,eAAe,CAAC;AAG7E,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,MAAM,WAAW,2BAA2B;IAC1C;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB;AAED;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;IACtC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAW;IAErC;;;;;;;;;;;;;;;;;OAiBG;gBACS,OAAO,EAAE,YAAY,EAAE,EAAE,SAAiB,EAAE,QAAa,EAAE,GAAE,2BAAgC;IAsBzG;;;;;;OAMG;IACH,OAAO,CAAC,MAAM;CA8Bf"}
@@ -0,0 +1,24 @@
1
+ import type { RouteHandler } from "@serwist/core";
2
+ import { Route } from "./Route.js";
3
+ import type { HTTPMethod } from "./utils/constants.js";
4
+ /**
5
+ * `RegExpRoute` makes it easy to create a regular expression based on a `@serwist/routing` Route.
6
+ *
7
+ * For same-origin requests the `RegExp` only needs to match part of the URL. For
8
+ * requests against third-party servers, you must define a `RegExp` that matches
9
+ * the start of the URL.
10
+ */
11
+ export declare class RegExpRoute extends Route {
12
+ /**
13
+ * If the regular expression contains
14
+ * [capture groups](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#grouping-back-references),
15
+ * the captured values will be passed to the `params` argument.
16
+ *
17
+ * @param regExp The regular expression to match against URLs.
18
+ * @param handler A callback function that returns a Promise resulting in a Response.
19
+ * @param method The HTTP method to match the Route, defaults to GET.
20
+ * against.
21
+ */
22
+ constructor(regExp: RegExp, handler: RouteHandler, method?: HTTPMethod);
23
+ }
24
+ //# sourceMappingURL=RegExpRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RegExpRoute.d.ts","sourceRoot":"","sources":["../../src/routing/RegExpRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAiD,MAAM,eAAe,CAAC;AAGjG,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;GAMG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;;;;;;;OASG;gBACS,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,CAAC,EAAE,UAAU;CAyCvE"}
@@ -0,0 +1,33 @@
1
+ import type { RouteHandler, RouteHandlerObject, RouteMatchCallback } from "@serwist/core";
2
+ import type { HTTPMethod } from "./utils/constants.js";
3
+ /**
4
+ * A `Route` consists of a pair of callback functions, "match" and "handler".
5
+ * The "match" callback determine if a route should be used to "handle" a
6
+ * request by returning a non-falsy value if it can. The "handler" callback
7
+ * is called when there is a match and should return a Promise that resolves
8
+ * to a `Response`.
9
+ */
10
+ export declare class Route {
11
+ handler: RouteHandlerObject;
12
+ match: RouteMatchCallback;
13
+ method: HTTPMethod;
14
+ catchHandler?: RouteHandlerObject;
15
+ /**
16
+ * Constructor for Route class.
17
+ *
18
+ * @param match A callback function that determines whether the
19
+ * route matches a given `fetch` event by returning a non-falsy value.
20
+ * @param handler A callback function that returns a Promise resolving
21
+ * to a Response.
22
+ * @param method The HTTP method to match the Route against. Defaults
23
+ * to GET.
24
+ */
25
+ constructor(match: RouteMatchCallback, handler: RouteHandler, method?: HTTPMethod);
26
+ /**
27
+ *
28
+ * @param handler A callback function that returns a Promise resolving
29
+ * to a Response.
30
+ */
31
+ setCatchHandler(handler: RouteHandler): void;
32
+ }
33
+ //# sourceMappingURL=Route.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Route.d.ts","sourceRoot":"","sources":["../../src/routing/Route.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAG1F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAIvD;;;;;;GAMG;AACH,qBAAa,KAAK;IAChB,OAAO,EAAE,kBAAkB,CAAC;IAC5B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,MAAM,EAAE,UAAU,CAAC;IACnB,YAAY,CAAC,EAAE,kBAAkB,CAAC;IAElC;;;;;;;;;OASG;gBACS,KAAK,EAAE,kBAAkB,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAE,UAA0B;IAqBhG;;;;OAIG;IACH,eAAe,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI;CAG7C"}
@@ -0,0 +1,150 @@
1
+ import type { RouteHandler, RouteHandlerCallbackOptions, RouteMatchCallback, RouteMatchCallbackOptions } from "@serwist/core";
2
+ import type { Route } from "./Route.js";
3
+ import type { HTTPMethod } from "./utils/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
+ */
15
+ export declare class Router {
16
+ private readonly _routes;
17
+ private readonly _defaultHandlerMap;
18
+ private _fetchListenerHandler;
19
+ private _cacheListenerHandler;
20
+ private _catchHandler?;
21
+ /**
22
+ * Initializes a new Router.
23
+ */
24
+ constructor();
25
+ /**
26
+ * @returns routes A `Map` of HTTP method name (`'GET'`, etc.) to an array of all the corresponding `Route`
27
+ * instances that are registered.
28
+ */
29
+ get routes(): Map<HTTPMethod, Route[]>;
30
+ /**
31
+ * Adds a `fetch` event listener to respond to events when a `Route` matches
32
+ * the event's request. Effectively no-op if `addFEtchListener` has been
33
+ * called, but `removeFetchListener` has not.
34
+ */
35
+ addFetchListener(): void;
36
+ /**
37
+ * Removes `fetch` event listener added by `addFetchListener`.
38
+ * Effectively no-op if either `addFetchListener` has not been called or,
39
+ * if it has, so has `removeFetchListener`.
40
+ */
41
+ removeFetchListener(): void;
42
+ /**
43
+ * Adds a `message` event listener for URLs to cache from the window.
44
+ * This is useful to cache resources loaded on the page prior to when the
45
+ * service worker started controlling it. Effectively no-op if `addCacheListener`
46
+ * has been called, but `removeCacheListener` hasn't.
47
+ *
48
+ * The format of the message data sent from the window should be as follows.
49
+ * Where the `urlsToCache` array may consist of URL strings or an array of
50
+ * URL string + `requestInit` object (the same as you'd pass to `fetch()`).
51
+ *
52
+ * ```
53
+ * {
54
+ * type: 'CACHE_URLS',
55
+ * payload: {
56
+ * urlsToCache: [
57
+ * './script1.js',
58
+ * './script2.js',
59
+ * ['./script3.js', {mode: 'no-cors'}],
60
+ * ],
61
+ * },
62
+ * }
63
+ * ```
64
+ */
65
+ addCacheListener(): void;
66
+ /**
67
+ * Removes the `message` event listener added by `addCacheListener`.
68
+ * Effectively no-op if either `addCacheListener` has not been called or,
69
+ * if it has, so has `removeCacheListener`.
70
+ */
71
+ removeCacheListener(): void;
72
+ /**
73
+ * Apply the routing rules to a `FetchEvent` object to get a `Response` from an
74
+ * appropriate `Route`'s handler.
75
+ *
76
+ * @param options
77
+ * @returns A promise is returned if a registered route can handle the request.
78
+ * If there is no matching route and there's no `defaultHandler`, `undefined`
79
+ * is returned.
80
+ */
81
+ handleRequest({ request, event, }: {
82
+ /**
83
+ * The request to handle.
84
+ */
85
+ request: Request;
86
+ /**
87
+ * The event that triggered the request.
88
+ */
89
+ event: ExtendableEvent;
90
+ }): Promise<Response> | undefined;
91
+ /**
92
+ * Checks a request and URL (and optionally an event) against the list of
93
+ * registered routes, and if there's a match, returns the corresponding
94
+ * route along with any params generated by the match.
95
+ *
96
+ * @param options
97
+ * @returns An object with `route` and `params` properties. They are populated
98
+ * if a matching route was found or `undefined` otherwise.
99
+ */
100
+ findMatchingRoute({ url, sameOrigin, request, event }: RouteMatchCallbackOptions): {
101
+ route?: Route;
102
+ params?: RouteHandlerCallbackOptions["params"];
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
+ setDefaultHandler(handler: RouteHandler, method?: HTTPMethod): void;
118
+ /**
119
+ * If a `Route` throws an error while handling a request, this `handler`
120
+ * will be called and given a chance to provide a response.
121
+ *
122
+ * @param handler A callback function that returns a Promise resulting
123
+ * in a Response.
124
+ */
125
+ setCatchHandler(handler: RouteHandler): void;
126
+ /**
127
+ * Registers a `RegExp`, string, or function with a caching
128
+ * strategy to the `Router`.
129
+ *
130
+ * @param capture If the capture param is a `Route`, all other arguments will be ignored.
131
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
132
+ * This parameter is required if `capture` is not a `Route` object.
133
+ * @param method The HTTP method to match the Route against. Defaults to `'GET'`.
134
+ * @returns The generated `Route`.
135
+ */
136
+ registerCapture(capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod): Route;
137
+ /**
138
+ * Registers a `Route` with the router.
139
+ *
140
+ * @param route The `Route` to register.
141
+ */
142
+ registerRoute(route: Route): void;
143
+ /**
144
+ * Unregisters a `Route` with the `Router`.
145
+ *
146
+ * @param route The `Route` to unregister.
147
+ */
148
+ unregisterRoute(route: Route): void;
149
+ }
150
+ //# sourceMappingURL=Router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/routing/Router.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,2BAA2B,EAAsB,kBAAkB,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAGlJ,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAevD;;;;;;;;;;GAUG;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,16 @@
1
+ import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
2
+ import { Route } from "./Route.js";
3
+ import type { HTTPMethod } from "./utils/constants.js";
4
+ /**
5
+ * Parses a `RegExp`, string, or function with a caching strategy into a `Route`. This is for
6
+ * when you want to create a `Route`, but you don't want to register it just yet: sometimes
7
+ * you want to call `setCatchHandler` first, for example.
8
+ *
9
+ * @param capture If the capture param is a `Route`, all other arguments will be ignored.
10
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
11
+ * This parameter is required if `capture` is not a `Route` object.
12
+ * @param method The HTTP method to match the `Route` against. Defaults to `'GET'`.
13
+ * @returns The generated `Route`.
14
+ */
15
+ export declare const parseRoute: (capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod) => Route;
16
+ //# sourceMappingURL=parseRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parseRoute.d.ts","sourceRoot":"","sources":["../../src/routing/parseRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAItE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,YAAa,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,YAAY,YAAY,WAAW,UAAU,KAAG,KA2D/H,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { RouteHandler, RouteMatchCallback } from "@serwist/core";
2
+ import { Route } from "./Route.js";
3
+ import type { HTTPMethod } from "./utils/constants.js";
4
+ /**
5
+ * Registers a `RegExp`, string, or function with a caching
6
+ * strategy to a singleton `Router` instance.
7
+ *
8
+ * @param capture If the capture param is a `Route`, all other arguments will be ignored.
9
+ * @param handler A callback function that returns a `Promise` resulting in a `Response`.
10
+ * This parameter is required if `capture` is not a `Route` object.
11
+ * @param method The HTTP method to match the `Route` against. Defaults to `'GET'`.
12
+ * @returns The generated `Route`, which can then be provided to `unregisterRoute` if needed.
13
+ */
14
+ export declare const registerRoute: (capture: RegExp | string | RouteMatchCallback | Route, handler?: RouteHandler, method?: HTTPMethod) => Route;
15
+ //# sourceMappingURL=registerRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registerRoute.d.ts","sourceRoot":"","sources":["../../src/routing/registerRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEtE,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEnC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,YAAa,MAAM,GAAG,MAAM,GAAG,kBAAkB,GAAG,KAAK,YAAY,YAAY,WAAW,UAAU,KAAG,KAElI,CAAC"}
@@ -0,0 +1,9 @@
1
+ import type { RouteHandler } from "@serwist/core";
2
+ /**
3
+ * If a `Route` throws an error while handling a request, this `handler`
4
+ * will be called and given a chance to provide a response.
5
+ *
6
+ * @param handler A callback function that returns a Promise resulting in a Response.
7
+ */
8
+ export declare const setCatchHandler: (handler: RouteHandler) => void;
9
+ //# sourceMappingURL=setCatchHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setCatchHandler.d.ts","sourceRoot":"","sources":["../../src/routing/setCatchHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,YAAa,YAAY,KAAG,IAEvD,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { RouteHandler } from "@serwist/core";
2
+ /**
3
+ * Defines a default `handler` that's called when no routes explicitly
4
+ * match the incoming request.
5
+ *
6
+ * Without a default `handler`, unmatched requests will go against the
7
+ * network as if there were no service worker present.
8
+ *
9
+ * @param handler A callback function that returns a Promise resulting in a Response.
10
+ */
11
+ export declare const setDefaultHandler: (handler: RouteHandler) => void;
12
+ //# sourceMappingURL=setDefaultHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setDefaultHandler.d.ts","sourceRoot":"","sources":["../../src/routing/setDefaultHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAIlD;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,YAAa,YAAY,KAAG,IAEzD,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { Router } from "./Router.js";
2
+ /**
3
+ * Creates a new, singleton `Router` if one does not exist. If one does
4
+ * already exist, that instance is returned. This instance is used by
5
+ * Serwist's `Router`-dependent functions and classes unless you provide
6
+ * a different `Router` to them.
7
+ *
8
+ * @returns The singleton `Router`.
9
+ */
10
+ export declare const getSingletonRouter: () => Router;
11
+ /**
12
+ * Changes the singleton `Router` to a different instance. This is meant for when you do not
13
+ * want to pass your own `Router` to every one of Serwist's `Router`-dependent functions and classes.
14
+ * If this or `getSingletonRouter` has been called before, it removes the listeners of the
15
+ * previous singleton `Router`. It also adds those of the new one, so you need not do that yourself.
16
+ *
17
+ * It is highly recommended that you call this before anything else, if you plan on doing so.
18
+ *
19
+ * @example
20
+ * ```js
21
+ * import { Router, setSingletonRouter } from "@serwist/sw/routing";
22
+ *
23
+ * const router = new Router();
24
+ *
25
+ * setSingletonRouter(router);
26
+ *
27
+ * router.registerRoute(
28
+ * new Route(
29
+ * /\/api\/.*\/*.json/,
30
+ * new NetworkOnly({
31
+ * plugins: [backgroundSync],
32
+ * }),
33
+ * "POST",
34
+ * ),
35
+ * );
36
+ *
37
+ * // This class now automatically picks up your `Router`! Without `setSingletonRouter`, you'd need to
38
+ * // write this instead: `new Serwist({ router })`
39
+ * const serwist = new Serwist();
40
+ *
41
+ * serwist.install();
42
+ * ```
43
+ * @param router
44
+ * @returns The new singleton `Router`.
45
+ */
46
+ export declare const setSingletonRouter: (router: Router) => Router;
47
+ //# sourceMappingURL=singletonRouter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"singletonRouter.d.ts","sourceRoot":"","sources":["../../src/routing/singletonRouter.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAIrC;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,QAAO,MASrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,kBAAkB,WAAY,MAAM,KAAG,MASnD,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { Route } from "./Route.js";
2
+ /**
3
+ * Unregisters a route from the singleton `Router` instance.
4
+ *
5
+ * @param route The route to unregister.
6
+ */
7
+ export declare const unregisterRoute: (route: Route) => void;
8
+ //# sourceMappingURL=unregisterRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unregisterRoute.d.ts","sourceRoot":"","sources":["../../src/routing/unregisterRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAGxC;;;;GAIG;AACH,eAAO,MAAM,eAAe,UAAW,KAAK,KAAG,IAE9C,CAAC"}
@@ -0,0 +1,15 @@
1
+ export type HTTPMethod = "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT";
2
+ /**
3
+ * The default HTTP method, 'GET', used when there's no specific method
4
+ * configured for a route.
5
+ *
6
+ * @private
7
+ */
8
+ export declare const defaultMethod = "GET";
9
+ /**
10
+ * The list of valid HTTP methods associated with requests that could be routed.
11
+ *
12
+ * @private
13
+ */
14
+ export declare const validMethods: ("GET" | "DELETE" | "HEAD" | "PATCH" | "POST" | "PUT")[];
15
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/routing/utils/constants.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,KAAK,CAAC;AAE9E;;;;;GAKG;AACH,eAAO,MAAM,aAAa,QAA6B,CAAC;AAExD;;;;GAIG;AACH,eAAO,MAAM,YAAY,0DAA2E,CAAC"}
@@ -0,0 +1,10 @@
1
+ import type { RouteHandler, RouteHandlerObject } from "@serwist/core";
2
+ /**
3
+ * @param handler Either a function, or an object with a
4
+ * 'handle' method.
5
+ * @returns An object with a handle method.
6
+ *
7
+ * @private
8
+ */
9
+ export declare const normalizeHandler: (handler: RouteHandler) => RouteHandlerObject;
10
+ //# sourceMappingURL=normalizeHandler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeHandler.d.ts","sourceRoot":"","sources":["../../../src/routing/utils/normalizeHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGtE;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,YAAa,YAAY,KAAG,kBAqBxD,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { Strategy } from "./Strategy.js";
2
+ import type { StrategyHandler } from "./StrategyHandler.js";
3
+ /**
4
+ * An implementation of the [cache first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache_first_falling_back_to_network)
5
+ * request strategy.
6
+ *
7
+ * A cache first strategy is useful for assets that have been revisioned,
8
+ * such as URLs like `/styles/example.a8f5f1.css`, since they
9
+ * can be cached for long periods of time.
10
+ *
11
+ * If the network request fails, and there is no cache match, this will throw
12
+ * a `SerwistError` exception.
13
+ */
14
+ export declare class CacheFirst extends Strategy {
15
+ /**
16
+ * @private
17
+ * @param request A request to run this strategy for.
18
+ * @param handler The event that triggered the request.
19
+ * @returns
20
+ */
21
+ _handle(request: Request, handler: StrategyHandler): Promise<Response>;
22
+ }
23
+ //# sourceMappingURL=CacheFirst.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheFirst.d.ts","sourceRoot":"","sources":["../../src/strategies/CacheFirst.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;;;;GAUG;AACH,qBAAa,UAAW,SAAQ,QAAQ;IACtC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CAsD7E"}
@@ -0,0 +1,20 @@
1
+ import { Strategy } from "./Strategy.js";
2
+ import type { StrategyHandler } from "./StrategyHandler.js";
3
+ /**
4
+ * An implementation of the [cache only](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#cache-only)
5
+ * request strategy.
6
+ *
7
+ * This class is useful if you want to take advantage of any Serwist plugin.
8
+ *
9
+ * If there is no cache match, this will throw a `SerwistError` exception.
10
+ */
11
+ export declare class CacheOnly extends Strategy {
12
+ /**
13
+ * @private
14
+ * @param request A request to run this strategy for.
15
+ * @param handler The event that triggered the request.
16
+ * @returns
17
+ */
18
+ _handle(request: Request, handler: StrategyHandler): Promise<Response>;
19
+ }
20
+ //# sourceMappingURL=CacheOnly.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CacheOnly.d.ts","sourceRoot":"","sources":["../../src/strategies/CacheOnly.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAG5D;;;;;;;GAOG;AACH,qBAAa,SAAU,SAAQ,QAAQ;IACrC;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;CA4B7E"}
@@ -0,0 +1,61 @@
1
+ import type { StrategyOptions } from "./Strategy.js";
2
+ import { Strategy } from "./Strategy.js";
3
+ import type { StrategyHandler } from "./StrategyHandler.js";
4
+ export interface NetworkFirstOptions extends StrategyOptions {
5
+ /**
6
+ * If set, any network requests that fail to respond within the timeout will fallback to the cache.
7
+ */
8
+ networkTimeoutSeconds?: number;
9
+ }
10
+ /**
11
+ * An implementation of the [network first](https://developer.chrome.com/docs/workbox/caching-strategies-overview/#network-first-falling-back-to-cache)
12
+ * request strategy.
13
+ *
14
+ * By default, this strategy will cache responses with a 200 status code as
15
+ * well as [opaque responses](https://developer.chrome.com/docs/workbox/caching-resources-during-runtime/#opaque-responses).
16
+ * Opaque responses are are cross-origin requests where the response doesn't
17
+ * support [CORS](https://enable-cors.org/).
18
+ *
19
+ * If the network request fails, and there is no cache match, this will throw
20
+ * a `SerwistError` exception.
21
+ */
22
+ export declare class NetworkFirst extends Strategy {
23
+ private readonly _networkTimeoutSeconds;
24
+ /**
25
+ * @param options
26
+ * This option can be used to combat
27
+ * "[lie-fi](https://developers.google.com/web/fundamentals/performance/poor-connectivity/#lie-fi)"
28
+ * scenarios.
29
+ */
30
+ constructor(options?: NetworkFirstOptions);
31
+ /**
32
+ * @private
33
+ * @param request A request to run this strategy for.
34
+ * @param handler The event that triggered the request.
35
+ * @returns
36
+ */
37
+ _handle(request: Request, handler: StrategyHandler): Promise<Response>;
38
+ /**
39
+ * @param options
40
+ * @returns
41
+ * @private
42
+ */
43
+ private _getTimeoutPromise;
44
+ /**
45
+ * @param options
46
+ * @param options.timeoutId
47
+ * @param options.request
48
+ * @param options.logs A reference to the logs Array.
49
+ * @param options.event
50
+ * @returns
51
+ *
52
+ * @private
53
+ */
54
+ _getNetworkPromise({ timeoutId, request, logs, handler, }: {
55
+ request: Request;
56
+ logs: any[];
57
+ timeoutId?: number;
58
+ handler: StrategyHandler;
59
+ }): Promise<Response | undefined>;
60
+ }
61
+ //# sourceMappingURL=NetworkFirst.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NetworkFirst.d.ts","sourceRoot":"","sources":["../../src/strategies/NetworkFirst.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAI5D,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D;;OAEG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,SAAQ,QAAQ;IACxC,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAS;IAChD;;;;;OAKG;gBACS,OAAO,GAAE,mBAAwB;IAsB7C;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,QAAQ,CAAC;IAgE5E;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;;;;;;;;OASG;IACG,kBAAkB,CAAC,EACvB,SAAS,EACT,OAAO,EACP,IAAI,EACJ,OAAO,GACR,EAAE;QACD,OAAO,EAAE,OAAO,CAAC;QACjB,IAAI,EAAE,GAAG,EAAE,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,eAAe,CAAC;KAC1B,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAqClC"}