@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
package/dist/types.d.ts DELETED
@@ -1,110 +0,0 @@
1
- import type { QueueOptions } from "@serwist/background-sync";
2
- import type { BroadcastCacheUpdateOptions } from "@serwist/broadcast-update";
3
- import type { CacheableResponseOptions } from "@serwist/cacheable-response";
4
- import type { RouteHandler, RouteMatchCallback, SerwistPlugin } from "@serwist/core";
5
- import type { ExpirationPluginOptions } from "@serwist/expiration";
6
- import type { HTTPMethod } from "@serwist/routing";
7
- export type StrategyName = "CacheFirst" | "CacheOnly" | "NetworkFirst" | "NetworkOnly" | "StaleWhileRevalidate";
8
- export interface RuntimeCaching {
9
- /**
10
- * This determines how the runtime route will generate a response.
11
- * To use one of the built-in `@serwist/strategies`, provide its name,
12
- * like `'NetworkFirst'`.
13
- * Alternatively, this can be a `@serwist/core.RouteHandler` callback
14
- * function with custom response logic.
15
- */
16
- handler: RouteHandler | StrategyName;
17
- /**
18
- * The HTTP method to match against. The default value of `'GET'` is normally
19
- * sufficient, unless you explicitly need to match `'POST'`, `'PUT'`, or
20
- * another type of request.
21
- * @default "GET"
22
- */
23
- method?: HTTPMethod;
24
- options?: {
25
- /**
26
- * Configuring this will add a
27
- * `@serwist/background-sync.BackgroundSyncPlugin` instance to the
28
- * `@serwist/strategies` configured in `handler`.
29
- */
30
- backgroundSync?: {
31
- name: string;
32
- options?: QueueOptions;
33
- };
34
- /**
35
- * Configuring this will add a
36
- * `@serwist/broadcast-update.BroadcastUpdatePlugin` instance to the
37
- * `@serwist/strategies` configured in `handler`.
38
- */
39
- broadcastUpdate?: {
40
- channelName?: string;
41
- options: BroadcastCacheUpdateOptions;
42
- };
43
- /**
44
- * Configuring this will add a
45
- * `@serwist/cacheable-response.CacheableResponsePlugin` instance to
46
- * the `@serwist/strategies` configured in `handler`.
47
- */
48
- cacheableResponse?: CacheableResponseOptions;
49
- /**
50
- * If provided, this will set the `cacheName` property of the
51
- * `@serwist/strategies` configured in `handler`.
52
- */
53
- cacheName?: string | null;
54
- /**
55
- * Configuring this will add a
56
- * `@serwist/expiration.ExpirationPlugin` instance to
57
- * the `@serwist/strategies` configured in `handler`.
58
- */
59
- expiration?: ExpirationPluginOptions;
60
- /**
61
- * If provided, this will set the `networkTimeoutSeconds` property of the
62
- * `@serwist/strategies` configured in `handler`. Note that only
63
- * `'NetworkFirst'` and `'NetworkOnly'` support `networkTimeoutSeconds`.
64
- */
65
- networkTimeoutSeconds?: number;
66
- /**
67
- * Configuring this allows the use of one or more Serwist plugins that
68
- * don't have "shortcut" options (like `expiration` for
69
- * `@serwist/expiration.ExpirationPlugin`). The plugins provided here
70
- * will be added to the `@serwist/strategies` configured in `handler`.
71
- */
72
- plugins?: SerwistPlugin[];
73
- /**
74
- * Configuring this will add a
75
- * `@serwist/precaching.PrecacheFallbackPlugin` instance to
76
- * the `@serwist/strategies` configured in `handler`.
77
- */
78
- precacheFallback?: {
79
- fallbackURL: string;
80
- };
81
- /**
82
- * Enabling this will add a
83
- * `@serwist/range-requests.RangeRequestsPlugin` instance to
84
- * the `@serwist/strategies` configured in `handler`.
85
- */
86
- rangeRequests?: boolean;
87
- /**
88
- * Configuring this will pass along the `fetchOptions` value to
89
- * the `@serwist/strategies` configured in `handler`.
90
- */
91
- fetchOptions?: RequestInit;
92
- /**
93
- * Configuring this will pass along the `matchOptions` value to
94
- * the `@serwist/strategies` configured in `handler`.
95
- */
96
- matchOptions?: CacheQueryOptions;
97
- };
98
- /**
99
- * This match criteria determines whether the configured handler will
100
- * generate a response for any requests that don't match one of the precached
101
- * URLs. If multiple `RuntimeCaching` routes are defined, then the first one
102
- * whose `urlPattern` matches will be the one that responds.
103
- *
104
- * This value directly maps to the first parameter passed to
105
- * `@serwist/routing.registerRoute`. It's recommended to use a
106
- * `@serwist/core.RouteMatchCallback` function for greatest flexibility.
107
- */
108
- urlPattern: RegExp | string | RouteMatchCallback;
109
- }
110
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,2BAA2B,CAAC;AAC7E,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,GAAG,aAAa,GAAG,sBAAsB,CAAC;AAEhH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,OAAO,EAAE,YAAY,GAAG,YAAY,CAAC;IACrC;;;;;OAKG;IACH,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,OAAO,CAAC,EAAE;QACR;;;;WAIG;QACH,cAAc,CAAC,EAAE;YACf,IAAI,EAAE,MAAM,CAAC;YACb,OAAO,CAAC,EAAE,YAAY,CAAC;SACxB,CAAC;QACF;;;;WAIG;QACH,eAAe,CAAC,EAAE;YAGhB,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,OAAO,EAAE,2BAA2B,CAAC;SACtC,CAAC;QACF;;;;WAIG;QACH,iBAAiB,CAAC,EAAE,wBAAwB,CAAC;QAC7C;;;WAGG;QACH,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC1B;;;;WAIG;QACH,UAAU,CAAC,EAAE,uBAAuB,CAAC;QACrC;;;;WAIG;QACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B;;;;;WAKG;QACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;QAC1B;;;;WAIG;QACH,gBAAgB,CAAC,EAAE;YACjB,WAAW,EAAE,MAAM,CAAC;SACrB,CAAC;QACF;;;;WAIG;QACH,aAAa,CAAC,EAAE,OAAO,CAAC;QACxB;;;WAGG;QACH,YAAY,CAAC,EAAE,WAAW,CAAC;QAC3B;;;WAGG;QACH,YAAY,CAAC,EAAE,iBAAiB,CAAC;KAClC,CAAC;IACF;;;;;;;;;OASG;IACH,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,kBAAkB,CAAC;CAClD"}
@@ -1,10 +0,0 @@
1
- declare const self: WorkerGlobalScope & {
2
- __WB_DISABLE_DEV_LOGS: boolean;
3
- };
4
-
5
- /**
6
- * Disables Serwist's logging in development mode.
7
- */
8
- export const disableDevLogs = () => {
9
- self.__WB_DISABLE_DEV_LOGS = true;
10
- };
package/src/fallbacks.ts DELETED
@@ -1,83 +0,0 @@
1
- import type { HandlerDidErrorCallbackParam } from "@serwist/core";
2
- import type { PrecacheRouteOptions } from "@serwist/precaching";
3
- import { precacheAndRoute } from "@serwist/precaching";
4
-
5
- import type { RuntimeCaching } from "./types.js";
6
-
7
- export type FallbackMatcher = (_: HandlerDidErrorCallbackParam) => boolean;
8
-
9
- export interface FallbackEntry {
10
- /**
11
- * The matcher, which checks whether the fallback entry can be used
12
- * for a Request.
13
- */
14
- matcher: FallbackMatcher;
15
- /**
16
- * The fallback URL.
17
- */
18
- url: URL | string;
19
- /**
20
- * The revision used for precaching.
21
- */
22
- revision: string;
23
- /**
24
- * How the Response in the cache should be matched.
25
- *
26
- * @default
27
- * { ignoreSearch: true }
28
- */
29
- cacheMatchOptions?: MultiCacheQueryOptions;
30
- }
31
-
32
- export interface FallbacksOptions {
33
- /**
34
- * Your previous `RuntimeCaching` array.
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
- /**
49
- * Precaches routes so that they can be used as a fallback when
50
- * a `RuntimeCaching` handler fails.
51
- * @param options
52
- * @returns The modified `RuntimeCaching` array. Using this value
53
- * is not needed, as it is simply the provided array.
54
- */
55
- export const fallbacks = ({ runtimeCaching, entries, precacheOptions }: FallbacksOptions): RuntimeCaching[] => {
56
- precacheAndRoute(
57
- entries.map(({ url, revision }) => ({ url: typeof url === "string" ? url : url.toString(), revision })),
58
- precacheOptions,
59
- );
60
- runtimeCaching = runtimeCaching.map((cacheEntry) => {
61
- if (!cacheEntry.options || cacheEntry.options.precacheFallback || cacheEntry.options.plugins?.some((plugin) => "handlerDidError" in plugin)) {
62
- return cacheEntry;
63
- }
64
-
65
- if (!cacheEntry.options.plugins) {
66
- cacheEntry.options.plugins = [];
67
- }
68
-
69
- cacheEntry.options.plugins.push({
70
- async handlerDidError(info) {
71
- for (const { matcher, url, cacheMatchOptions = { ignoreSearch: true } } of entries) {
72
- if (matcher(info)) {
73
- return caches.match(url, cacheMatchOptions);
74
- }
75
- }
76
- return Response.error();
77
- },
78
- });
79
-
80
- return cacheEntry;
81
- });
82
- return runtimeCaching;
83
- };
@@ -1,65 +0,0 @@
1
- import type { PrecacheEntry, PrecacheRouteOptions } from "@serwist/precaching";
2
- import { cleanupOutdatedCaches as cleanupOutdatedCachesImpl, createHandlerBoundToURL, precacheAndRoute } from "@serwist/precaching";
3
- import { NavigationRoute, registerRoute } from "@serwist/routing";
4
-
5
- export type HandlePrecachingOptions = {
6
- /**
7
- * A list of fallback entries.
8
- */
9
- precacheEntries?: (PrecacheEntry | string)[];
10
- /**
11
- * Precache options for the provided entries.
12
- */
13
- precacheOptions?: PrecacheRouteOptions;
14
- /**
15
- * Whether outdated caches should be removed.
16
- *
17
- * @default false
18
- */
19
- cleanupOutdatedCaches?: boolean;
20
- } & (
21
- | {
22
- /**
23
- * An URL that should point to a HTML
24
- * file with which navigation requests for URLs that aren't precached will be fulfilled.
25
- * For more complex cases, consider `@serwist/sw.fallbacks`instead.
26
- */
27
- navigateFallback: string;
28
- /**
29
- * URLs that should be allowed to use the `navigateFallback` handler.
30
- */
31
- navigateFallbackAllowlist?: RegExp[];
32
- /**
33
- * URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
34
- * over `navigateFallbackAllowlist`.
35
- */
36
- navigateFallbackDenylist?: RegExp[];
37
- }
38
- | { navigateFallback?: never }
39
- );
40
-
41
- /**
42
- * Handles a list of precache entries and cleans up outdated caches.
43
- * @param options
44
- */
45
- export const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches = false, ...options }: HandlePrecachingOptions) => {
46
- if (!!precacheEntries && precacheEntries.length > 0) {
47
- /**
48
- * The precacheAndRoute() method efficiently caches and responds to
49
- * requests for URLs in the manifest.
50
- * See https://goo.gl/S9QRab
51
- */
52
- precacheAndRoute(precacheEntries, precacheOptions);
53
- }
54
-
55
- if (cleanupOutdatedCaches) cleanupOutdatedCachesImpl();
56
-
57
- if (options.navigateFallback) {
58
- registerRoute(
59
- new NavigationRoute(createHandlerBoundToURL(options.navigateFallback), {
60
- allowlist: options.navigateFallbackAllowlist,
61
- denylist: options.navigateFallbackDenylist,
62
- }),
63
- );
64
- }
65
- };
@@ -1,106 +0,0 @@
1
- import { clientsClaim as clientsClaimImpl, setCacheNameDetails } from "@serwist/core";
2
- import { logger } from "@serwist/core/internal";
3
- import { type GoogleAnalyticsInitializeOptions, initialize } from "@serwist/google-analytics/initialize";
4
- import { enable } from "@serwist/navigation-preload";
5
-
6
- import { disableDevLogs as disableDevLogsImpl } from "./disableDevLogs.js";
7
- import type { FallbacksOptions } from "./fallbacks.js";
8
- import { fallbacks as fallbacksImpl } from "./fallbacks.js";
9
- import { type HandlePrecachingOptions, handlePrecaching } from "./handlePrecaching.js";
10
- import { registerRuntimeCaching } from "./registerRuntimeCaching.js";
11
- import type { RuntimeCaching } from "./types.js";
12
-
13
- declare const self: ServiceWorkerGlobalScope;
14
-
15
- export type InstallSerwistOptions = HandlePrecachingOptions & {
16
- skipWaiting?: boolean;
17
- importScripts?: string[];
18
- navigationPreload?: boolean;
19
- cacheId?: string | undefined;
20
- clientsClaim?: boolean;
21
- runtimeCaching?: RuntimeCaching[];
22
- offlineAnalyticsConfig?: GoogleAnalyticsInitializeOptions | boolean;
23
- disableDevLogs?: boolean;
24
- fallbacks?: Omit<FallbacksOptions, "runtimeCaching">;
25
- };
26
-
27
- /**
28
- * A function that abstracts away the core APIs of Serwist.
29
- * @param options - `installSerwist` options.
30
- */
31
- export const installSerwist = ({
32
- precacheEntries,
33
- precacheOptions,
34
- cleanupOutdatedCaches,
35
-
36
- skipWaiting = false,
37
- importScripts,
38
- navigationPreload = false,
39
- cacheId,
40
- clientsClaim = false,
41
- runtimeCaching,
42
- offlineAnalyticsConfig,
43
- disableDevLogs,
44
- fallbacks,
45
- ...options
46
- }: InstallSerwistOptions) => {
47
- if (!!importScripts && importScripts.length > 0) self.importScripts(...importScripts);
48
-
49
- if (navigationPreload) enable();
50
-
51
- if (cacheId !== undefined) {
52
- setCacheNameDetails({
53
- prefix: cacheId,
54
- });
55
- }
56
-
57
- if (skipWaiting) {
58
- self.skipWaiting();
59
- } else {
60
- self.addEventListener("message", (event) => {
61
- if (event.data && event.data.type === "SKIP_WAITING") {
62
- self.skipWaiting();
63
- }
64
- });
65
- }
66
-
67
- if (clientsClaim) clientsClaimImpl();
68
-
69
- handlePrecaching({
70
- precacheEntries,
71
- precacheOptions,
72
- cleanupOutdatedCaches,
73
- ...(options.navigateFallback && {
74
- navigateFallback: options.navigateFallback,
75
- navigateFallbackAllowlist: options.navigateFallbackAllowlist,
76
- navigateFallbackDenylist: options.navigateFallbackDenylist,
77
- }),
78
- });
79
-
80
- if (runtimeCaching !== undefined) {
81
- if (!("__WB_FORCE_RUNTIME_CACHING" in globalThis)) {
82
- self.__WB_FORCE_RUNTIME_CACHING = false;
83
- }
84
- if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
85
- logger.log("runtimeCaching and fallbacks are disabled in development mode.");
86
- } else {
87
- if (fallbacks !== undefined) {
88
- runtimeCaching = fallbacksImpl({
89
- ...fallbacks,
90
- runtimeCaching,
91
- });
92
- }
93
- registerRuntimeCaching(...runtimeCaching);
94
- }
95
- }
96
-
97
- if (offlineAnalyticsConfig !== undefined) {
98
- if (typeof offlineAnalyticsConfig === "boolean") {
99
- offlineAnalyticsConfig && initialize();
100
- } else {
101
- initialize(offlineAnalyticsConfig);
102
- }
103
- }
104
-
105
- if (disableDevLogs) disableDevLogsImpl();
106
- };
@@ -1,84 +0,0 @@
1
- import { BackgroundSyncPlugin } from "@serwist/background-sync";
2
- import { BroadcastUpdatePlugin } from "@serwist/broadcast-update";
3
- import { CacheableResponsePlugin } from "@serwist/cacheable-response";
4
- import { logger } from "@serwist/core/internal";
5
- import { ExpirationPlugin } from "@serwist/expiration";
6
- import { PrecacheFallbackPlugin } from "@serwist/precaching";
7
- import { RangeRequestsPlugin } from "@serwist/range-requests";
8
- import { registerRoute } from "@serwist/routing";
9
- import { CacheFirst, CacheOnly, NetworkFirst, NetworkOnly, StaleWhileRevalidate } from "@serwist/strategies";
10
- import { nonNullable } from "@serwist/utils";
11
-
12
- import type { RuntimeCaching, StrategyName } from "./types.js";
13
-
14
- declare const self: ServiceWorkerGlobalScope;
15
-
16
- const HANDLER_NAME_TO_METHOD = {
17
- CacheFirst,
18
- CacheOnly,
19
- NetworkFirst,
20
- NetworkOnly,
21
- StaleWhileRevalidate,
22
- } satisfies Record<StrategyName, unknown>;
23
-
24
- /**
25
- * Registers caching strategies to a singleton Router instance. It is a simple
26
- * syntatic sugar for `@serwist/routing.registerRoute`.
27
- * @param runtimeCachingList
28
- * @returns
29
- */
30
- export const registerRuntimeCaching = (...runtimeCachingList: RuntimeCaching[]) => {
31
- if (!("__WB_FORCE_RUNTIME_CACHING" in globalThis)) {
32
- self.__WB_FORCE_RUNTIME_CACHING = false;
33
- }
34
-
35
- if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
36
- logger.log("registerRuntimeCaching is disabled in development mode.");
37
- return;
38
- }
39
-
40
- for (const rcEntry of runtimeCachingList) {
41
- if (typeof rcEntry.handler === "string") {
42
- const {
43
- cacheName,
44
- networkTimeoutSeconds,
45
- fetchOptions,
46
- matchOptions,
47
- plugins,
48
- backgroundSync,
49
- broadcastUpdate,
50
- cacheableResponse,
51
- expiration,
52
- precacheFallback,
53
- rangeRequests,
54
- } = rcEntry.options!; // entry.options is always defined when entry.handler is of type 'string'.
55
- const Handler = HANDLER_NAME_TO_METHOD[rcEntry.handler];
56
- registerRoute(
57
- rcEntry.urlPattern,
58
- new Handler({
59
- cacheName: cacheName ?? undefined,
60
- networkTimeoutSeconds,
61
- fetchOptions,
62
- matchOptions,
63
- plugins: [
64
- ...(plugins ?? []),
65
- backgroundSync && new BackgroundSyncPlugin(backgroundSync.name, backgroundSync.options),
66
- broadcastUpdate &&
67
- new BroadcastUpdatePlugin({
68
- // @ts-expect-error weird...
69
- channelName: broadcastUpdate.channelName,
70
- ...broadcastUpdate.options,
71
- }),
72
- cacheableResponse && new CacheableResponsePlugin(cacheableResponse),
73
- expiration && new ExpirationPlugin(expiration),
74
- precacheFallback && new PrecacheFallbackPlugin(precacheFallback),
75
- rangeRequests ? new RangeRequestsPlugin() : undefined,
76
- ].filter(nonNullable),
77
- }),
78
- rcEntry.method,
79
- );
80
- } else {
81
- registerRoute(rcEntry.urlPattern, rcEntry.handler, rcEntry.method);
82
- }
83
- }
84
- };
package/src/types.ts DELETED
@@ -1,113 +0,0 @@
1
- import type { QueueOptions } from "@serwist/background-sync";
2
- import type { BroadcastCacheUpdateOptions } from "@serwist/broadcast-update";
3
- import type { CacheableResponseOptions } from "@serwist/cacheable-response";
4
- import type { RouteHandler, RouteMatchCallback, SerwistPlugin } from "@serwist/core";
5
- import type { ExpirationPluginOptions } from "@serwist/expiration";
6
- import type { HTTPMethod } from "@serwist/routing";
7
-
8
- export type StrategyName = "CacheFirst" | "CacheOnly" | "NetworkFirst" | "NetworkOnly" | "StaleWhileRevalidate";
9
-
10
- export interface RuntimeCaching {
11
- /**
12
- * This determines how the runtime route will generate a response.
13
- * To use one of the built-in `@serwist/strategies`, provide its name,
14
- * like `'NetworkFirst'`.
15
- * Alternatively, this can be a `@serwist/core.RouteHandler` callback
16
- * function with custom response logic.
17
- */
18
- handler: RouteHandler | StrategyName;
19
- /**
20
- * The HTTP method to match against. The default value of `'GET'` is normally
21
- * sufficient, unless you explicitly need to match `'POST'`, `'PUT'`, or
22
- * another type of request.
23
- * @default "GET"
24
- */
25
- method?: HTTPMethod;
26
- options?: {
27
- /**
28
- * Configuring this will add a
29
- * `@serwist/background-sync.BackgroundSyncPlugin` instance to the
30
- * `@serwist/strategies` configured in `handler`.
31
- */
32
- backgroundSync?: {
33
- name: string;
34
- options?: QueueOptions;
35
- };
36
- /**
37
- * Configuring this will add a
38
- * `@serwist/broadcast-update.BroadcastUpdatePlugin` instance to the
39
- * `@serwist/strategies` configured in `handler`.
40
- */
41
- broadcastUpdate?: {
42
- // TODO: This option is ignored since we switched to using postMessage().
43
- // Remove it in the next major release.
44
- channelName?: string;
45
- options: BroadcastCacheUpdateOptions;
46
- };
47
- /**
48
- * Configuring this will add a
49
- * `@serwist/cacheable-response.CacheableResponsePlugin` instance to
50
- * the `@serwist/strategies` configured in `handler`.
51
- */
52
- cacheableResponse?: CacheableResponseOptions;
53
- /**
54
- * If provided, this will set the `cacheName` property of the
55
- * `@serwist/strategies` configured in `handler`.
56
- */
57
- cacheName?: string | null;
58
- /**
59
- * Configuring this will add a
60
- * `@serwist/expiration.ExpirationPlugin` instance to
61
- * the `@serwist/strategies` configured in `handler`.
62
- */
63
- expiration?: ExpirationPluginOptions;
64
- /**
65
- * If provided, this will set the `networkTimeoutSeconds` property of the
66
- * `@serwist/strategies` configured in `handler`. Note that only
67
- * `'NetworkFirst'` and `'NetworkOnly'` support `networkTimeoutSeconds`.
68
- */
69
- networkTimeoutSeconds?: number;
70
- /**
71
- * Configuring this allows the use of one or more Serwist plugins that
72
- * don't have "shortcut" options (like `expiration` for
73
- * `@serwist/expiration.ExpirationPlugin`). The plugins provided here
74
- * will be added to the `@serwist/strategies` configured in `handler`.
75
- */
76
- plugins?: SerwistPlugin[];
77
- /**
78
- * Configuring this will add a
79
- * `@serwist/precaching.PrecacheFallbackPlugin` instance to
80
- * the `@serwist/strategies` configured in `handler`.
81
- */
82
- precacheFallback?: {
83
- fallbackURL: string;
84
- };
85
- /**
86
- * Enabling this will add a
87
- * `@serwist/range-requests.RangeRequestsPlugin` instance to
88
- * the `@serwist/strategies` configured in `handler`.
89
- */
90
- rangeRequests?: boolean;
91
- /**
92
- * Configuring this will pass along the `fetchOptions` value to
93
- * the `@serwist/strategies` configured in `handler`.
94
- */
95
- fetchOptions?: RequestInit;
96
- /**
97
- * Configuring this will pass along the `matchOptions` value to
98
- * the `@serwist/strategies` configured in `handler`.
99
- */
100
- matchOptions?: CacheQueryOptions;
101
- };
102
- /**
103
- * This match criteria determines whether the configured handler will
104
- * generate a response for any requests that don't match one of the precached
105
- * URLs. If multiple `RuntimeCaching` routes are defined, then the first one
106
- * whose `urlPattern` matches will be the one that responds.
107
- *
108
- * This value directly maps to the first parameter passed to
109
- * `@serwist/routing.registerRoute`. It's recommended to use a
110
- * `@serwist/core.RouteMatchCallback` function for greatest flexibility.
111
- */
112
- urlPattern: RegExp | string | RouteMatchCallback;
113
- }