serwist 10.0.0-preview.1 → 10.0.0-preview.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/dist/chunks/{resultingClientExists.js → waitUntil.js} +144 -144
  2. package/dist/index.d.ts +22 -50
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.internal.d.ts +16 -16
  5. package/dist/index.internal.d.ts.map +1 -1
  6. package/dist/index.internal.js +3 -3
  7. package/dist/index.js +1925 -1803
  8. package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.d.ts +1 -1
  9. package/dist/lib/background-sync/BackgroundSyncPlugin.d.ts.map +1 -0
  10. package/dist/lib/background-sync/BackgroundSyncQueue.d.ts.map +1 -0
  11. package/dist/lib/background-sync/BackgroundSyncQueueDb.d.ts.map +1 -0
  12. package/dist/lib/background-sync/BackgroundSyncQueueStore.d.ts.map +1 -0
  13. package/dist/lib/{backgroundSync → background-sync}/StorableRequest.d.ts +1 -1
  14. package/dist/lib/background-sync/StorableRequest.d.ts.map +1 -0
  15. package/dist/lib/background-sync/index.d.ts +6 -0
  16. package/dist/lib/background-sync/index.d.ts.map +1 -0
  17. package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.d.ts +1 -1
  18. package/dist/lib/broadcast-update/BroadcastCacheUpdate.d.ts.map +1 -0
  19. package/dist/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.d.ts +1 -1
  20. package/dist/lib/broadcast-update/BroadcastUpdatePlugin.d.ts.map +1 -0
  21. package/dist/lib/broadcast-update/constants.d.ts.map +1 -0
  22. package/dist/lib/broadcast-update/index.d.ts +6 -0
  23. package/dist/lib/broadcast-update/index.d.ts.map +1 -0
  24. package/dist/lib/broadcast-update/responsesAreSame.d.ts.map +1 -0
  25. package/dist/lib/{broadcastUpdate → broadcast-update}/types.d.ts +1 -1
  26. package/dist/lib/broadcast-update/types.d.ts.map +1 -0
  27. package/dist/{cacheNames.d.ts → lib/cache-name.d.ts} +1 -1
  28. package/dist/lib/cache-name.d.ts.map +1 -0
  29. package/dist/lib/cacheable-response/CacheableResponse.d.ts.map +1 -0
  30. package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.d.ts +1 -1
  31. package/dist/lib/cacheable-response/CacheableResponsePlugin.d.ts.map +1 -0
  32. package/dist/lib/cacheable-response/index.d.ts +4 -0
  33. package/dist/lib/cacheable-response/index.d.ts.map +1 -0
  34. package/dist/{constants.d.ts → lib/constants.d.ts} +1 -1
  35. package/dist/lib/constants.d.ts.map +1 -0
  36. package/dist/lib/core.d.ts +62 -0
  37. package/dist/lib/core.d.ts.map +1 -0
  38. package/dist/lib/expiration/ExpirationPlugin.d.ts +1 -1
  39. package/dist/lib/expiration/ExpirationPlugin.d.ts.map +1 -1
  40. package/dist/lib/expiration/index.d.ts +4 -0
  41. package/dist/lib/expiration/index.d.ts.map +1 -0
  42. package/dist/lib/extension.d.ts +30 -0
  43. package/dist/lib/extension.d.ts.map +1 -0
  44. package/dist/lib/extensions/google-analytics/constants.d.ts.map +1 -0
  45. package/dist/lib/extensions/google-analytics/extension.d.ts +79 -0
  46. package/dist/lib/extensions/google-analytics/extension.d.ts.map +1 -0
  47. package/dist/lib/extensions/google-analytics/index.d.ts +2 -0
  48. package/dist/lib/extensions/google-analytics/index.d.ts.map +1 -0
  49. package/dist/lib/extensions/google-analytics/initialize.d.ts +12 -0
  50. package/dist/lib/extensions/google-analytics/initialize.d.ts.map +1 -0
  51. package/dist/lib/extensions/index.d.ts +14 -0
  52. package/dist/lib/extensions/index.d.ts.map +1 -0
  53. package/dist/{controllers/PrecacheController/PrecacheController.d.ts → lib/extensions/precache/extension.d.ts} +19 -38
  54. package/dist/lib/extensions/precache/extension.d.ts.map +1 -0
  55. package/dist/{controllers/PrecacheController/parsePrecacheOptions.d.ts → lib/extensions/precache/options.d.ts} +6 -5
  56. package/dist/lib/extensions/precache/options.d.ts.map +1 -0
  57. package/dist/{controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts → lib/extensions/precache/plugin-cache-key.d.ts} +4 -4
  58. package/dist/lib/extensions/precache/plugin-cache-key.d.ts.map +1 -0
  59. package/dist/lib/{precaching/PrecacheFallbackPlugin.d.ts → extensions/precache/plugin-fallback.d.ts} +11 -11
  60. package/dist/lib/extensions/precache/plugin-fallback.d.ts.map +1 -0
  61. package/dist/{controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts → lib/extensions/precache/plugin-install-report.d.ts} +2 -2
  62. package/dist/lib/extensions/precache/plugin-install-report.d.ts.map +1 -0
  63. package/dist/lib/extensions/precache/route.d.ts +42 -0
  64. package/dist/lib/extensions/precache/route.d.ts.map +1 -0
  65. package/dist/{controllers/PrecacheController/PrecacheStrategy.d.ts → lib/extensions/precache/strategy.d.ts} +5 -5
  66. package/dist/lib/extensions/precache/strategy.d.ts.map +1 -0
  67. package/dist/{controllers/RuntimeCacheController.d.ts → lib/extensions/runtime-cache.d.ts} +16 -10
  68. package/dist/lib/extensions/runtime-cache.d.ts.map +1 -0
  69. package/dist/lib/functions/handlers.d.ts +60 -0
  70. package/dist/lib/functions/handlers.d.ts.map +1 -0
  71. package/dist/lib/functions/router.d.ts +60 -0
  72. package/dist/lib/functions/router.d.ts.map +1 -0
  73. package/dist/{navigationPreload.d.ts → lib/navigation-preload.d.ts} +1 -1
  74. package/dist/lib/navigation-preload.d.ts.map +1 -0
  75. package/dist/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.d.ts +1 -1
  76. package/dist/lib/range-requests/RangeRequestsPlugin.d.ts.map +1 -0
  77. package/dist/lib/range-requests/createPartialResponse.d.ts.map +1 -0
  78. package/dist/lib/range-requests/index.d.ts +3 -0
  79. package/dist/lib/range-requests/index.d.ts.map +1 -0
  80. package/dist/lib/range-requests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
  81. package/dist/lib/range-requests/utils/parseRangeHeader.d.ts.map +1 -0
  82. package/dist/lib/route.d.ts +106 -0
  83. package/dist/lib/route.d.ts.map +1 -0
  84. package/dist/{Serwist.d.ts → lib/serwist.d.ts} +28 -41
  85. package/dist/lib/serwist.d.ts.map +1 -0
  86. package/dist/lib/strategies/NetworkFirst.d.ts.map +1 -1
  87. package/dist/lib/strategies/StaleWhileRevalidate.d.ts.map +1 -1
  88. package/dist/lib/strategies/Strategy.d.ts +1 -1
  89. package/dist/lib/strategies/Strategy.d.ts.map +1 -1
  90. package/dist/lib/strategies/StrategyHandler.d.ts +1 -1
  91. package/dist/lib/strategies/StrategyHandler.d.ts.map +1 -1
  92. package/dist/lib/strategies/index.d.ts +11 -0
  93. package/dist/lib/strategies/index.d.ts.map +1 -0
  94. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +1 -1
  95. package/dist/lib/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -1
  96. package/dist/{types.d.ts → lib/types.d.ts} +15 -24
  97. package/dist/lib/types.d.ts.map +1 -0
  98. package/dist/{copyResponse.d.ts → lib/utils.d.ts} +22 -1
  99. package/dist/lib/utils.d.ts.map +1 -0
  100. package/dist/models/messages/messageGenerator.d.ts +1 -1
  101. package/dist/models/messages/messageGenerator.d.ts.map +1 -1
  102. package/dist/utils/SerwistError.d.ts +2 -2
  103. package/dist/utils/SerwistError.d.ts.map +1 -1
  104. package/dist/utils/assert.d.ts +1 -1
  105. package/dist/utils/assert.d.ts.map +1 -1
  106. package/dist/utils/cacheNames.d.ts.map +1 -1
  107. package/dist/utils/cleanupOutdatedCaches.d.ts.map +1 -1
  108. package/dist/utils/createCacheKey.d.ts +1 -1
  109. package/dist/utils/createCacheKey.d.ts.map +1 -1
  110. package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -1
  111. package/dist/utils/generateURLVariations.d.ts +1 -1
  112. package/dist/utils/generateURLVariations.d.ts.map +1 -1
  113. package/dist/utils/getFriendlyURL.d.ts.map +1 -1
  114. package/dist/utils/logger.d.ts +1 -1
  115. package/dist/utils/logger.d.ts.map +1 -1
  116. package/dist/utils/normalizeHandler.d.ts +1 -1
  117. package/dist/utils/normalizeHandler.d.ts.map +1 -1
  118. package/dist/utils/parseRoute.d.ts +3 -3
  119. package/dist/utils/parseRoute.d.ts.map +1 -1
  120. package/dist/utils/pluginUtils.d.ts +1 -1
  121. package/dist/utils/pluginUtils.d.ts.map +1 -1
  122. package/dist/utils/printCleanupDetails.d.ts.map +1 -1
  123. package/dist/utils/printInstallDetails.d.ts.map +1 -1
  124. package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -1
  125. package/dist/utils/waitUntil.d.ts.map +1 -1
  126. package/package.json +30 -6
  127. package/src/index.internal.ts +16 -16
  128. package/src/index.ts +100 -110
  129. package/src/lib/{backgroundSync → background-sync}/BackgroundSyncPlugin.ts +1 -1
  130. package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.ts +7 -7
  131. package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.ts +1 -1
  132. package/src/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.ts +1 -3
  133. package/src/lib/{backgroundSync → background-sync}/StorableRequest.ts +2 -2
  134. package/src/lib/background-sync/index.ts +5 -0
  135. package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastCacheUpdate.ts +5 -5
  136. package/src/lib/{broadcastUpdate → broadcast-update}/BroadcastUpdatePlugin.ts +1 -1
  137. package/src/lib/broadcast-update/index.ts +5 -0
  138. package/src/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.ts +2 -2
  139. package/src/lib/{broadcastUpdate → broadcast-update}/types.ts +1 -1
  140. package/src/{cacheNames.ts → lib/cache-name.ts} +1 -1
  141. package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponse.ts +4 -4
  142. package/src/lib/{cacheableResponse → cacheable-response}/CacheableResponsePlugin.ts +1 -1
  143. package/src/lib/cacheable-response/index.ts +3 -0
  144. package/src/lib/core.ts +128 -0
  145. package/src/lib/expiration/CacheExpiration.ts +3 -3
  146. package/src/lib/expiration/ExpirationPlugin.ts +9 -10
  147. package/src/lib/expiration/index.ts +3 -0
  148. package/src/lib/extension.ts +37 -0
  149. package/src/lib/{googleAnalytics/initializeGoogleAnalytics.ts → extensions/google-analytics/extension.ts} +43 -49
  150. package/src/lib/extensions/google-analytics/index.ts +0 -0
  151. package/src/lib/extensions/google-analytics/initialize.ts +48 -0
  152. package/src/lib/extensions/index.ts +13 -0
  153. package/src/{controllers/PrecacheController/PrecacheController.ts → lib/extensions/precache/extension.ts} +37 -56
  154. package/src/{controllers/PrecacheController/parsePrecacheOptions.ts → lib/extensions/precache/options.ts} +11 -8
  155. package/src/{controllers/PrecacheController/PrecacheCacheKeyPlugin.ts → lib/extensions/precache/plugin-cache-key.ts} +4 -4
  156. package/src/lib/{precaching/PrecacheFallbackPlugin.ts → extensions/precache/plugin-fallback.ts} +27 -16
  157. package/src/{controllers/PrecacheController/PrecacheInstallReportPlugin.ts → lib/extensions/precache/plugin-install-report.ts} +1 -1
  158. package/src/lib/extensions/precache/route.ts +72 -0
  159. package/src/{controllers/PrecacheController/PrecacheStrategy.ts → lib/extensions/precache/strategy.ts} +11 -11
  160. package/src/{controllers/RuntimeCacheController.ts → lib/extensions/runtime-cache.ts} +24 -17
  161. package/src/lib/functions/handlers.ts +149 -0
  162. package/src/lib/functions/router.ts +314 -0
  163. package/src/{navigationPreload.ts → lib/navigation-preload.ts} +1 -1
  164. package/src/lib/{rangeRequests → range-requests}/RangeRequestsPlugin.ts +1 -1
  165. package/src/lib/{rangeRequests → range-requests}/createPartialResponse.ts +3 -3
  166. package/src/lib/range-requests/index.ts +2 -0
  167. package/src/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.ts +2 -2
  168. package/src/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.ts +2 -2
  169. package/src/lib/route.ts +234 -0
  170. package/src/lib/serwist.ts +443 -0
  171. package/src/lib/strategies/CacheFirst.ts +4 -4
  172. package/src/lib/strategies/CacheOnly.ts +3 -3
  173. package/src/lib/strategies/NetworkFirst.ts +6 -6
  174. package/src/lib/strategies/NetworkOnly.ts +5 -5
  175. package/src/lib/strategies/StaleWhileRevalidate.ts +5 -5
  176. package/src/lib/strategies/Strategy.ts +9 -9
  177. package/src/lib/strategies/StrategyHandler.ts +11 -11
  178. package/src/lib/strategies/index.ts +10 -0
  179. package/src/lib/strategies/plugins/cacheOkAndOpaquePlugin.ts +1 -1
  180. package/src/lib/strategies/utils/messages.ts +2 -2
  181. package/src/{types.ts → lib/types.ts} +17 -26
  182. package/src/lib/utils.ts +137 -0
  183. package/src/models/messages/messageGenerator.ts +1 -1
  184. package/src/models/messages/messages.ts +3 -3
  185. package/src/utils/SerwistError.ts +3 -3
  186. package/src/utils/assert.ts +1 -2
  187. package/src/utils/cacheNames.ts +0 -2
  188. package/src/utils/canConstructReadableStream.ts +1 -1
  189. package/src/utils/canConstructResponseFromBodyStream.ts +1 -1
  190. package/src/utils/createCacheKey.ts +1 -2
  191. package/src/utils/executeQuotaErrorCallbacks.ts +1 -1
  192. package/src/utils/generateURLVariations.ts +1 -1
  193. package/src/utils/logger.ts +1 -1
  194. package/src/utils/normalizeHandler.ts +1 -1
  195. package/src/utils/parseRoute.ts +4 -5
  196. package/src/utils/pluginUtils.ts +1 -1
  197. package/src/utils/resultingClientExists.ts +1 -1
  198. package/dist/NavigationRoute.d.ts +0 -56
  199. package/dist/NavigationRoute.d.ts.map +0 -1
  200. package/dist/RegExpRoute.d.ts +0 -24
  201. package/dist/RegExpRoute.d.ts.map +0 -1
  202. package/dist/Route.d.ts +0 -33
  203. package/dist/Route.d.ts.map +0 -1
  204. package/dist/Serwist.d.ts.map +0 -1
  205. package/dist/cacheNames.d.ts.map +0 -1
  206. package/dist/constants.d.ts.map +0 -1
  207. package/dist/controllers/PrecacheController/PrecacheCacheKeyPlugin.d.ts.map +0 -1
  208. package/dist/controllers/PrecacheController/PrecacheController.d.ts.map +0 -1
  209. package/dist/controllers/PrecacheController/PrecacheInstallReportPlugin.d.ts.map +0 -1
  210. package/dist/controllers/PrecacheController/PrecacheRoute.d.ts +0 -15
  211. package/dist/controllers/PrecacheController/PrecacheRoute.d.ts.map +0 -1
  212. package/dist/controllers/PrecacheController/PrecacheStrategy.d.ts.map +0 -1
  213. package/dist/controllers/PrecacheController/parsePrecacheOptions.d.ts.map +0 -1
  214. package/dist/controllers/RuntimeCacheController.d.ts.map +0 -1
  215. package/dist/copyResponse.d.ts.map +0 -1
  216. package/dist/disableDevLogs.d.ts +0 -7
  217. package/dist/disableDevLogs.d.ts.map +0 -1
  218. package/dist/lib/backgroundSync/BackgroundSyncPlugin.d.ts.map +0 -1
  219. package/dist/lib/backgroundSync/BackgroundSyncQueue.d.ts.map +0 -1
  220. package/dist/lib/backgroundSync/BackgroundSyncQueueDb.d.ts.map +0 -1
  221. package/dist/lib/backgroundSync/BackgroundSyncQueueStore.d.ts.map +0 -1
  222. package/dist/lib/backgroundSync/StorableRequest.d.ts.map +0 -1
  223. package/dist/lib/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +0 -1
  224. package/dist/lib/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +0 -1
  225. package/dist/lib/broadcastUpdate/constants.d.ts.map +0 -1
  226. package/dist/lib/broadcastUpdate/responsesAreSame.d.ts.map +0 -1
  227. package/dist/lib/broadcastUpdate/types.d.ts.map +0 -1
  228. package/dist/lib/cacheableResponse/CacheableResponse.d.ts.map +0 -1
  229. package/dist/lib/cacheableResponse/CacheableResponsePlugin.d.ts.map +0 -1
  230. package/dist/lib/googleAnalytics/constants.d.ts.map +0 -1
  231. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts +0 -30
  232. package/dist/lib/googleAnalytics/initializeGoogleAnalytics.d.ts.map +0 -1
  233. package/dist/lib/precaching/PrecacheFallbackPlugin.d.ts.map +0 -1
  234. package/dist/lib/rangeRequests/RangeRequestsPlugin.d.ts.map +0 -1
  235. package/dist/lib/rangeRequests/createPartialResponse.d.ts.map +0 -1
  236. package/dist/lib/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +0 -1
  237. package/dist/lib/rangeRequests/utils/parseRangeHeader.d.ts.map +0 -1
  238. package/dist/navigationPreload.d.ts.map +0 -1
  239. package/dist/registerQuotaErrorCallback.d.ts +0 -8
  240. package/dist/registerQuotaErrorCallback.d.ts.map +0 -1
  241. package/dist/setCacheNameDetails.d.ts +0 -9
  242. package/dist/setCacheNameDetails.d.ts.map +0 -1
  243. package/dist/types.d.ts.map +0 -1
  244. package/src/NavigationRoute.ts +0 -118
  245. package/src/RegExpRoute.ts +0 -74
  246. package/src/Route.ts +0 -67
  247. package/src/Serwist.ts +0 -762
  248. package/src/controllers/PrecacheController/PrecacheRoute.ts +0 -44
  249. package/src/copyResponse.ts +0 -58
  250. package/src/disableDevLogs.ts +0 -10
  251. package/src/registerQuotaErrorCallback.ts +0 -34
  252. package/src/setCacheNameDetails.ts +0 -53
  253. /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueue.d.ts +0 -0
  254. /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueDb.d.ts +0 -0
  255. /package/dist/lib/{backgroundSync → background-sync}/BackgroundSyncQueueStore.d.ts +0 -0
  256. /package/dist/lib/{broadcastUpdate → broadcast-update}/constants.d.ts +0 -0
  257. /package/dist/lib/{broadcastUpdate → broadcast-update}/responsesAreSame.d.ts +0 -0
  258. /package/dist/lib/{cacheableResponse → cacheable-response}/CacheableResponse.d.ts +0 -0
  259. /package/dist/lib/{googleAnalytics → extensions/google-analytics}/constants.d.ts +0 -0
  260. /package/dist/lib/{rangeRequests → range-requests}/createPartialResponse.d.ts +0 -0
  261. /package/dist/lib/{rangeRequests → range-requests}/utils/calculateEffectiveBoundaries.d.ts +0 -0
  262. /package/dist/lib/{rangeRequests → range-requests}/utils/parseRangeHeader.d.ts +0 -0
  263. /package/src/lib/{broadcastUpdate → broadcast-update}/constants.ts +0 -0
  264. /package/src/{constants.ts → lib/constants.ts} +0 -0
  265. /package/src/lib/{googleAnalytics → extensions/google-analytics}/constants.ts +0 -0
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "serwist",
3
- "version": "10.0.0-preview.1",
3
+ "version": "10.0.0-preview.10",
4
4
  "type": "module",
5
+ "sideEffects": false,
5
6
  "description": "A Swiss Army knife for service workers.",
6
7
  "files": [
7
8
  "src",
@@ -30,6 +31,28 @@
30
31
  ]
31
32
  }
32
33
  },
34
+ "imports": {
35
+ "#lib/*.js": {
36
+ "local": "./src/lib/*.ts",
37
+ "types": "./dist/lib/*.d.ts"
38
+ },
39
+ "#index": {
40
+ "local": "./src/index.ts",
41
+ "types": "./dist/index.d.ts"
42
+ },
43
+ "#index.internal": {
44
+ "local": "./src/index.internal.ts",
45
+ "types": "./dist/index.internal.d.ts"
46
+ },
47
+ "#models/*.js": {
48
+ "local": "./src/models/*.ts",
49
+ "types": "./dist/models/*.d.ts"
50
+ },
51
+ "#utils/*.js": {
52
+ "local": "./src/utils/*.ts",
53
+ "types": "./dist/utils/*.d.ts"
54
+ }
55
+ },
33
56
  "exports": {
34
57
  ".": {
35
58
  "types": "./dist/index.d.ts",
@@ -42,13 +65,13 @@
42
65
  "./package.json": "./package.json"
43
66
  },
44
67
  "dependencies": {
45
- "idb": "8.0.2",
46
- "@serwist/utils": "10.0.0-preview.1"
68
+ "idb": "8.0.3",
69
+ "@serwist/utils": "10.0.0-preview.10"
47
70
  },
48
71
  "devDependencies": {
49
- "rollup": "4.34.8",
50
- "typescript": "5.7.3",
51
- "@serwist/configs": "10.0.0-preview.1"
72
+ "rollup": "4.45.1",
73
+ "typescript": "5.8.3",
74
+ "@serwist/configs": "10.0.0-preview.10"
52
75
  },
53
76
  "peerDependencies": {
54
77
  "typescript": ">=5.0.0"
@@ -62,6 +85,7 @@
62
85
  "build": "rimraf dist && NODE_ENV=production rollup --config rollup.config.js",
63
86
  "dev": "rollup --config rollup.config.js --watch",
64
87
  "lint": "biome lint ./src",
88
+ "qcheck": "biome check ./src",
65
89
  "typecheck": "tsc"
66
90
  }
67
91
  }
@@ -1,19 +1,19 @@
1
- import { Deferred } from "./utils/Deferred.js";
2
- import { SerwistError } from "./utils/SerwistError.js";
3
- import { assert } from "./utils/assert.js";
4
- import { cacheMatchIgnoreParams } from "./utils/cacheMatchIgnoreParams.js";
5
- import { cacheNames as privateCacheNames } from "./utils/cacheNames.js";
6
- import { canConstructReadableStream } from "./utils/canConstructReadableStream.js";
7
- import { canConstructResponseFromBodyStream } from "./utils/canConstructResponseFromBodyStream.js";
8
- import { cleanupOutdatedCaches } from "./utils/cleanupOutdatedCaches.js";
9
- import { clientsClaim } from "./utils/clientsClaim.js";
10
- import { dontWaitFor } from "./utils/dontWaitFor.js";
11
- import { executeQuotaErrorCallbacks } from "./utils/executeQuotaErrorCallbacks.js";
12
- import { getFriendlyURL } from "./utils/getFriendlyURL.js";
13
- import { logger } from "./utils/logger.js";
14
- import { resultingClientExists } from "./utils/resultingClientExists.js";
15
- import { timeout } from "./utils/timeout.js";
16
- import { waitUntil } from "./utils/waitUntil.js";
1
+ import { assert } from "#utils/assert.js";
2
+ import { cacheMatchIgnoreParams } from "#utils/cacheMatchIgnoreParams.js";
3
+ import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
4
+ import { canConstructReadableStream } from "#utils/canConstructReadableStream.js";
5
+ import { canConstructResponseFromBodyStream } from "#utils/canConstructResponseFromBodyStream.js";
6
+ import { cleanupOutdatedCaches } from "#utils/cleanupOutdatedCaches.js";
7
+ import { clientsClaim } from "#utils/clientsClaim.js";
8
+ import { Deferred } from "#utils/Deferred.js";
9
+ import { dontWaitFor } from "#utils/dontWaitFor.js";
10
+ import { executeQuotaErrorCallbacks } from "#utils/executeQuotaErrorCallbacks.js";
11
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
12
+ import { logger } from "#utils/logger.js";
13
+ import { resultingClientExists } from "#utils/resultingClientExists.js";
14
+ import { SerwistError } from "#utils/SerwistError.js";
15
+ import { timeout } from "#utils/timeout.js";
16
+ import { waitUntil } from "#utils/waitUntil.js";
17
17
 
18
18
  // Serwist's internal functions, classes, variables, and more. Feel free to use them,
19
19
  // but they are not documented. Note: they do follow semver.
package/src/index.ts CHANGED
@@ -1,128 +1,118 @@
1
- import { PrecacheStrategy } from "./controllers/PrecacheController/PrecacheStrategy.js";
2
- import { PrecacheRoute } from "./controllers/PrecacheController/PrecacheRoute.js";
3
- import { RuntimeCacheController } from "./controllers/RuntimeCacheController.js";
4
- import type { NavigationRouteMatchOptions } from "./NavigationRoute.js";
5
- import { NavigationRoute } from "./NavigationRoute.js";
6
- import { RegExpRoute } from "./RegExpRoute.js";
7
- import { Route } from "./Route.js";
8
- import { Serwist, type SerwistOptions } from "./Serwist.js";
9
- import { cacheNames } from "./cacheNames.js";
10
- import type { HTTPMethod } from "./constants.js";
11
- import { copyResponse } from "./copyResponse.js";
12
- import { disableDevLogs } from "./disableDevLogs.js";
13
- import { BackgroundSyncPlugin } from "./lib/backgroundSync/BackgroundSyncPlugin.js";
14
- import type { BackgroundSyncQueueEntry, BackgroundSyncQueueOptions } from "./lib/backgroundSync/BackgroundSyncQueue.js";
15
- import { BackgroundSyncQueue } from "./lib/backgroundSync/BackgroundSyncQueue.js";
16
- import { BackgroundSyncQueueStore } from "./lib/backgroundSync/BackgroundSyncQueueStore.js";
17
- import { StorableRequest } from "./lib/backgroundSync/StorableRequest.js";
18
- import { BroadcastCacheUpdate } from "./lib/broadcastUpdate/BroadcastCacheUpdate.js";
19
- import { BroadcastUpdatePlugin } from "./lib/broadcastUpdate/BroadcastUpdatePlugin.js";
20
- import { BROADCAST_UPDATE_DEFAULT_HEADERS } from "./lib/broadcastUpdate/constants.js";
21
- import { responsesAreSame } from "./lib/broadcastUpdate/responsesAreSame.js";
22
- import type { BroadcastCacheUpdateOptions, BroadcastMessage, BroadcastPayload, BroadcastPayloadGenerator } from "./lib/broadcastUpdate/types.js";
23
- import { CacheableResponse } from "./lib/cacheableResponse/CacheableResponse.js";
24
- import type { CacheableResponseOptions } from "./lib/cacheableResponse/CacheableResponse.js";
25
- import { CacheableResponsePlugin } from "./lib/cacheableResponse/CacheableResponsePlugin.js";
26
- import { CacheExpiration } from "./lib/expiration/CacheExpiration.js";
27
- import type { ExpirationPluginOptions } from "./lib/expiration/ExpirationPlugin.js";
28
- import { ExpirationPlugin } from "./lib/expiration/ExpirationPlugin.js";
29
- import { initializeGoogleAnalytics } from "./lib/googleAnalytics/initializeGoogleAnalytics.js";
30
- import type { GoogleAnalyticsInitializeOptions } from "./lib/googleAnalytics/initializeGoogleAnalytics.js";
31
- import type { PrecacheFallbackEntry, PrecacheFallbackPluginOptions } from "./lib/precaching/PrecacheFallbackPlugin.js";
32
- import { PrecacheFallbackPlugin } from "./lib/precaching/PrecacheFallbackPlugin.js";
33
- import { RangeRequestsPlugin } from "./lib/rangeRequests/RangeRequestsPlugin.js";
34
- import { createPartialResponse } from "./lib/rangeRequests/createPartialResponse.js";
35
- import { CacheFirst } from "./lib/strategies/CacheFirst.js";
36
- import { CacheOnly } from "./lib/strategies/CacheOnly.js";
37
- import type { NetworkFirstOptions } from "./lib/strategies/NetworkFirst.js";
38
- import { NetworkFirst } from "./lib/strategies/NetworkFirst.js";
39
- import type { NetworkOnlyOptions } from "./lib/strategies/NetworkOnly.js";
40
- import { NetworkOnly } from "./lib/strategies/NetworkOnly.js";
41
- import { StaleWhileRevalidate } from "./lib/strategies/StaleWhileRevalidate.js";
42
- import type { StrategyOptions } from "./lib/strategies/Strategy.js";
43
- import { Strategy } from "./lib/strategies/Strategy.js";
44
- import { StrategyHandler } from "./lib/strategies/StrategyHandler.js";
45
- import { disableNavigationPreload, enableNavigationPreload, isNavigationPreloadSupported } from "./navigationPreload.js";
46
- import { registerQuotaErrorCallback } from "./registerQuotaErrorCallback.js";
47
- import { setCacheNameDetails } from "./setCacheNameDetails.js";
1
+ import { cacheNames } from "#lib/cache-name.js";
2
+ import type { HTTPMethod } from "#lib/constants.js";
3
+ import { disableNavigationPreload, enableNavigationPreload, isNavigationPreloadSupported } from "#lib/navigation-preload.js";
4
+ import type { NavigationRouteMatchOptions } from "#lib/route.js";
5
+ import { NavigationRoute, RegExpRoute, Route } from "#lib/route.js";
6
+ import { Serwist, type SerwistOptions } from "#lib/serwist.js";
7
+ import { copyResponse, disableDevLogs, registerQuotaErrorCallback, setCacheNameDetails } from "#lib/utils.js";
48
8
 
9
+ // Background synchronizing
49
10
  export {
50
- // Core
51
- Serwist,
52
- cacheNames,
53
- copyResponse,
54
- disableDevLogs,
55
- disableNavigationPreload,
56
- enableNavigationPreload,
57
- isNavigationPreloadSupported,
58
- registerQuotaErrorCallback,
59
- setCacheNameDetails,
60
- // Controllers
61
- RuntimeCacheController,
62
- // Caching strategies
63
- CacheFirst,
64
- CacheOnly,
65
- NetworkFirst,
66
- NetworkOnly,
67
- PrecacheStrategy,
68
- StaleWhileRevalidate,
69
- Strategy,
70
- StrategyHandler,
71
- // Routing
72
- NavigationRoute,
73
- PrecacheRoute,
74
- RegExpRoute,
75
- Route,
76
- // Background synchronizing
77
11
  BackgroundSyncPlugin,
78
12
  BackgroundSyncQueue,
13
+ type BackgroundSyncQueueEntry,
14
+ type BackgroundSyncQueueOptions,
79
15
  BackgroundSyncQueueStore,
80
16
  StorableRequest,
81
- // Broadcasting updates
17
+ } from "#lib/background-sync/index.js";
18
+
19
+ // Broadcasting updates
20
+ export {
21
+ BROADCAST_UPDATE_DEFAULT_HEADERS,
82
22
  BroadcastCacheUpdate,
23
+ type BroadcastCacheUpdateOptions,
24
+ type BroadcastMessage,
25
+ type BroadcastPayload,
26
+ type BroadcastPayloadGenerator,
83
27
  BroadcastUpdatePlugin,
84
- BROADCAST_UPDATE_DEFAULT_HEADERS,
85
28
  responsesAreSame,
86
- // Setting cacheability criteria
29
+ } from "#lib/broadcast-update/index.js";
30
+
31
+ // Setting cacheability criteria
32
+ export {
87
33
  CacheableResponse,
34
+ type CacheableResponseOptions,
88
35
  CacheableResponsePlugin,
89
- // Expiring outdated responses
36
+ } from "#lib/cacheable-response/index.js";
37
+
38
+ // Controllers
39
+
40
+ // Expiring outdated responses
41
+ export {
90
42
  CacheExpiration,
91
43
  ExpirationPlugin,
92
- // Precaching
93
- PrecacheFallbackPlugin,
94
- // Google Analytics
44
+ type ExpirationPluginOptions,
45
+ } from "#lib/expiration/index.js";
46
+
47
+ // Extensions
48
+ export {
49
+ GoogleAnalytics,
50
+ type GoogleAnalyticsInitializeOptions,
51
+ type GoogleAnalyticsOptions,
95
52
  initializeGoogleAnalytics,
96
- // Handling range requests
53
+ type PrecacheFallbackEntry,
54
+ PrecacheFallbackPlugin,
55
+ type PrecacheFallbackPluginOptions,
56
+ PrecacheRoute,
57
+ PrecacheStrategy,
58
+ RuntimeCache,
59
+ type RuntimeCacheOptions,
60
+ } from "#lib/extensions/index.js";
61
+
62
+ // Handling range requests
63
+ export {
97
64
  createPartialResponse,
98
65
  RangeRequestsPlugin,
99
- };
100
- export type {
101
- // Core
102
- HTTPMethod,
103
- SerwistOptions,
104
- // Caching strategies
105
- NetworkFirstOptions,
106
- NetworkOnlyOptions,
107
- StrategyOptions,
66
+ } from "#lib/range-requests/index.js";
67
+
68
+ // Built-in caching strategies
69
+ export {
70
+ CacheFirst,
71
+ CacheOnly,
72
+ NetworkFirst,
73
+ type NetworkFirstOptions,
74
+ NetworkOnly,
75
+ type NetworkOnlyOptions,
76
+ StaleWhileRevalidate,
77
+ Strategy,
78
+ StrategyHandler,
79
+ type StrategyOptions,
80
+ } from "#lib/strategies/index.js";
81
+
82
+ // Core
83
+ export {
84
+ Serwist,
85
+ cacheNames,
86
+ copyResponse,
87
+ disableDevLogs,
88
+ disableNavigationPreload,
89
+ enableNavigationPreload,
90
+ isNavigationPreloadSupported,
91
+ registerQuotaErrorCallback,
92
+ setCacheNameDetails,
108
93
  // Routing
109
- NavigationRouteMatchOptions,
110
- // Background synchronizing
111
- BackgroundSyncQueueOptions,
112
- BackgroundSyncQueueEntry,
113
- // Broadcasting updates
114
- BroadcastCacheUpdateOptions,
115
- BroadcastPayload,
116
- BroadcastPayloadGenerator,
117
- BroadcastMessage,
118
- // Setting cacheability criteria
119
- CacheableResponseOptions,
120
- // Expiring outdated responses
121
- ExpirationPluginOptions,
122
- // Precaching
123
- PrecacheFallbackEntry,
124
- PrecacheFallbackPluginOptions,
125
- // Google Analytics
126
- GoogleAnalyticsInitializeOptions,
94
+ NavigationRoute,
95
+ RegExpRoute,
96
+ Route,
127
97
  };
128
- export type * from "./types.js";
98
+
99
+ // Core (modern)
100
+ // TODO(v11): rename once we remove legacy `Serwist` and `SerwistOptions`
101
+ export type { Serwist as SerwistState, SerwistOptions as CreateSerwistOptions } from "#lib/core.js";
102
+ export { createSerwist } from "#lib/core.js";
103
+ // Extension
104
+ export type * from "#lib/extension.js";
105
+ export {
106
+ addEventListeners,
107
+ createActivateHandler,
108
+ createCacheHandler,
109
+ createFetchHandler,
110
+ createInstallHandler,
111
+ iterateExtensions,
112
+ setCatchHandler,
113
+ setDefaultHandler,
114
+ } from "#lib/functions/handlers.js";
115
+ export { findMatchingRoute, handleRequest, registerCapture, registerRoute, unregisterRoute } from "#lib/functions/router.js";
116
+
117
+ export type { HTTPMethod, SerwistOptions, NavigationRouteMatchOptions };
118
+ export type * from "#lib/types.js";
@@ -6,7 +6,7 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { FetchDidFailCallbackParam, StrategyPlugin } from "../../types.js";
9
+ import type { FetchDidFailCallbackParam, StrategyPlugin } from "#lib/types.js";
10
10
  import type { BackgroundSyncQueueOptions } from "./BackgroundSyncQueue.js";
11
11
  import { BackgroundSyncQueue } from "./BackgroundSyncQueue.js";
12
12
 
@@ -1,4 +1,3 @@
1
- import { SerwistError } from "../../utils/SerwistError.js";
2
1
  /*
3
2
  Copyright 2018 Google LLC
4
3
 
@@ -6,9 +5,10 @@ import { SerwistError } from "../../utils/SerwistError.js";
6
5
  license that can be found in the LICENSE file or at
7
6
  https://opensource.org/licenses/MIT.
8
7
  */
9
- import { assert } from "../../utils/assert.js";
10
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
11
- import { logger } from "../../utils/logger.js";
8
+ import { assert } from "#utils/assert.js";
9
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
10
+ import { logger } from "#utils/logger.js";
11
+ import { SerwistError } from "#utils/SerwistError.js";
12
12
  import type { BackgroundSyncQueueStoreEntry, UnidentifiedQueueStoreEntry } from "./BackgroundSyncQueueDb.js";
13
13
  import { BackgroundSyncQueueStore } from "./BackgroundSyncQueueStore.js";
14
14
  import { StorableRequest } from "./StorableRequest.js";
@@ -350,7 +350,7 @@ export class BackgroundSyncQueue {
350
350
  * the queue (which registers a retry for the next sync event).
351
351
  */
352
352
  async replayRequests(): Promise<void> {
353
- let entry: BackgroundSyncQueueEntry | undefined = undefined;
353
+ let entry: BackgroundSyncQueueEntry | undefined;
354
354
  while ((entry = await this.shiftRequest())) {
355
355
  try {
356
356
  await fetch(entry.request.clone());
@@ -358,7 +358,7 @@ export class BackgroundSyncQueue {
358
358
  if (process.env.NODE_ENV !== "production") {
359
359
  logger.log(`Request for '${getFriendlyURL(entry.request.url)}' ` + `has been replayed in queue '${this._name}'`);
360
360
  }
361
- } catch (error) {
361
+ } catch {
362
362
  await this.unshiftRequest(entry);
363
363
 
364
364
  if (process.env.NODE_ENV !== "production") {
@@ -409,7 +409,7 @@ export class BackgroundSyncQueue {
409
409
  const syncComplete = async () => {
410
410
  this._syncInProgress = true;
411
411
 
412
- let syncError: Error | undefined = undefined;
412
+ let syncError: Error | undefined;
413
413
  try {
414
414
  await this._onSync({ queue: this });
415
415
  } catch (error) {
@@ -81,7 +81,7 @@ export class BackgroundSyncQueueDb {
81
81
  async getAllEntriesByQueueName(queueName: string): Promise<BackgroundSyncQueueStoreEntry[]> {
82
82
  const db = await this.getDb();
83
83
  const results = await db.getAllFromIndex(REQUEST_OBJECT_STORE_NAME, QUEUE_NAME_INDEX, IDBKeyRange.only(queueName));
84
- return results ? results : new Array<BackgroundSyncQueueStoreEntry>();
84
+ return results ? results : ([] as BackgroundSyncQueueStoreEntry[]);
85
85
  }
86
86
 
87
87
  /**
@@ -5,7 +5,7 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
- import { assert } from "../../utils/assert.js";
8
+ import { assert } from "#utils/assert.js";
9
9
  import type { BackgroundSyncQueueStoreEntry, UnidentifiedQueueStoreEntry } from "./BackgroundSyncQueueDb.js";
10
10
  import { BackgroundSyncQueueDb } from "./BackgroundSyncQueueDb.js";
11
11
 
@@ -52,7 +52,6 @@ export class BackgroundSyncQueueStore {
52
52
  });
53
53
  }
54
54
 
55
- // biome-ignore lint/performance/noDelete: Don't specify an ID since one is automatically generated.
56
55
  delete entry.id;
57
56
  entry.queueName = this._queueName;
58
57
 
@@ -86,7 +85,6 @@ export class BackgroundSyncQueueStore {
86
85
  // Pick an ID one less than the lowest ID in the object store.
87
86
  entry.id = firstId - 1;
88
87
  } else {
89
- // biome-ignore lint/performance/noDelete: Let the auto-incrementor assign the ID.
90
88
  delete entry.id;
91
89
  }
92
90
  entry.queueName = this._queueName;
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { MapLikeObject } from "../../types.js";
10
- import { assert } from "../../utils/assert.js";
9
+ import type { MapLikeObject } from "#lib/types.js";
10
+ import { assert } from "#utils/assert.js";
11
11
 
12
12
  type SerializableProperties = "method" | "referrer" | "referrerPolicy" | "mode" | "credentials" | "cache" | "redirect" | "integrity" | "keepalive";
13
13
 
@@ -0,0 +1,5 @@
1
+ export { BackgroundSyncPlugin } from "./BackgroundSyncPlugin.js";
2
+ export type { BackgroundSyncQueueEntry, BackgroundSyncQueueOptions } from "./BackgroundSyncQueue.js";
3
+ export { BackgroundSyncQueue } from "./BackgroundSyncQueue.js";
4
+ export { BackgroundSyncQueueStore } from "./BackgroundSyncQueueStore.js";
5
+ export { StorableRequest } from "./StorableRequest.js";
@@ -6,11 +6,11 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { CacheDidUpdateCallbackParam } from "../../types.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { logger } from "../../utils/logger.js";
12
- import { resultingClientExists } from "../../utils/resultingClientExists.js";
13
- import { timeout } from "../../utils/timeout.js";
9
+ import type { CacheDidUpdateCallbackParam } from "#lib/types.js";
10
+ import { assert } from "#utils/assert.js";
11
+ import { logger } from "#utils/logger.js";
12
+ import { resultingClientExists } from "#utils/resultingClientExists.js";
13
+ import { timeout } from "#utils/timeout.js";
14
14
  import {
15
15
  BROADCAST_UPDATE_DEFAULT_HEADERS,
16
16
  BROADCAST_UPDATE_DEFAULT_NOTIFY,
@@ -6,7 +6,7 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { CacheDidUpdateCallbackParam, StrategyPlugin } from "../../types.js";
9
+ import type { CacheDidUpdateCallbackParam, StrategyPlugin } from "#lib/types.js";
10
10
  import { BroadcastCacheUpdate } from "./BroadcastCacheUpdate.js";
11
11
  import type { BroadcastCacheUpdateOptions } from "./types.js";
12
12
 
@@ -0,0 +1,5 @@
1
+ export { BroadcastCacheUpdate } from "./BroadcastCacheUpdate.js";
2
+ export { BroadcastUpdatePlugin } from "./BroadcastUpdatePlugin.js";
3
+ export { BROADCAST_UPDATE_DEFAULT_HEADERS } from "./constants.js";
4
+ export { responsesAreSame } from "./responsesAreSame.js";
5
+ export type { BroadcastCacheUpdateOptions, BroadcastMessage, BroadcastPayload, BroadcastPayloadGenerator } from "./types.js";
@@ -6,8 +6,8 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { logger } from "../../utils/logger.js";
9
+ import { logger } from "#utils/logger.js";
10
+ import { SerwistError } from "#utils/SerwistError.js";
11
11
 
12
12
  /**
13
13
  * Given two responses, compares several header values to see if they are
@@ -1,4 +1,4 @@
1
- import type { CacheDidUpdateCallbackParam } from "../../types.js";
1
+ import type { CacheDidUpdateCallbackParam } from "#lib/types.js";
2
2
  import type { BROADCAST_UPDATE_MESSAGE_META, BROADCAST_UPDATE_MESSAGE_TYPE } from "./constants.js";
3
3
 
4
4
  export interface BroadcastCacheUpdateOptions {
@@ -6,7 +6,7 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { cacheNames as privateCacheNames } from "./utils/cacheNames.js";
9
+ import { cacheNames as privateCacheNames } from "#utils/cacheNames.js";
10
10
 
11
11
  /**
12
12
  * Get the current cache names and prefix/suffix used by Serwist.
@@ -6,10 +6,10 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import { SerwistError } from "../../utils/SerwistError.js";
10
- import { assert } from "../../utils/assert.js";
11
- import { getFriendlyURL } from "../../utils/getFriendlyURL.js";
12
- import { logger } from "../../utils/logger.js";
9
+ import { assert } from "#utils/assert.js";
10
+ import { getFriendlyURL } from "#utils/getFriendlyURL.js";
11
+ import { logger } from "#utils/logger.js";
12
+ import { SerwistError } from "#utils/SerwistError.js";
13
13
 
14
14
  export interface CacheableResponseOptions {
15
15
  /**
@@ -6,7 +6,7 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { StrategyPlugin } from "../../types.js";
9
+ import type { StrategyPlugin } from "#lib/types.js";
10
10
  import type { CacheableResponseOptions } from "./CacheableResponse.js";
11
11
  import { CacheableResponse } from "./CacheableResponse.js";
12
12
 
@@ -0,0 +1,3 @@
1
+ export type { CacheableResponseOptions } from "./CacheableResponse.js";
2
+ export { CacheableResponse } from "./CacheableResponse.js";
3
+ export { CacheableResponsePlugin } from "./CacheableResponsePlugin.js";