@serwist/recipes 9.0.0-preview.0 → 9.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.
@@ -30,6 +30,5 @@ export interface ImageCacheOptions {
30
30
  *
31
31
  * @param options
32
32
  */
33
- declare function imageCache(options?: ImageCacheOptions): void;
34
- export { imageCache };
33
+ export declare const imageCache: (options?: ImageCacheOptions) => void;
35
34
  //# sourceMappingURL=imageCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageCache.d.ts","sourceRoot":"","sources":["../src/imageCache.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,eAAe,CAAC;AAOlG,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,iBAAS,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI,CA+BzD;AAED,OAAO,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"imageCache.d.ts","sourceRoot":"","sources":["../src/imageCache.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,eAAe,CAAC;AAOlG,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,UAAU,aAAa,iBAAiB,KAAQ,IA+B5D,CAAC"}
package/dist/index.js CHANGED
@@ -4,20 +4,14 @@ import { registerRoute, setCatchHandler } from '@serwist/routing';
4
4
  import { StaleWhileRevalidate, CacheFirst, NetworkFirst } from '@serwist/strategies';
5
5
  import { matchPrecache } from '@serwist/precaching';
6
6
 
7
- /**
8
- * An implementation of the [Google fonts](https://developers.google.com/web/tools/workbox/guides/common-recipes#google_fonts) caching recipe.
9
- *
10
- * @param options
11
- */ function googleFontsCache(options = {}) {
7
+ function googleFontsCache(options = {}) {
12
8
  const sheetCacheName = `${options.cachePrefix || "google-fonts"}-stylesheets`;
13
9
  const fontCacheName = `${options.cachePrefix || "google-fonts"}-webfonts`;
14
10
  const maxAgeSeconds = options.maxAgeSeconds || 60 * 60 * 24 * 365;
15
11
  const maxEntries = options.maxEntries || 30;
16
- // Cache the Google Fonts stylesheets with a stale-while-revalidate strategy.
17
12
  registerRoute(({ url })=>url.origin === "https://fonts.googleapis.com", new StaleWhileRevalidate({
18
13
  cacheName: sheetCacheName
19
14
  }));
20
- // Cache the underlying font files with a cache-first strategy for 1 year.
21
15
  registerRoute(({ url })=>url.origin === "https://fonts.gstatic.com", new CacheFirst({
22
16
  cacheName: fontCacheName,
23
17
  plugins: [
@@ -35,9 +29,7 @@ import { matchPrecache } from '@serwist/precaching';
35
29
  }));
36
30
  }
37
31
 
38
- /**
39
- * @param options
40
- */ function warmStrategyCache(options) {
32
+ function warmStrategyCache(options) {
41
33
  self.addEventListener("install", (event)=>{
42
34
  const done = options.urls.map((path)=>options.strategy.handleAll({
43
35
  event,
@@ -47,11 +39,7 @@ import { matchPrecache } from '@serwist/precaching';
47
39
  });
48
40
  }
49
41
 
50
- /**
51
- * An implementation of the [image caching recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#caching_images).
52
- *
53
- * @param options
54
- */ function imageCache(options = {}) {
42
+ const imageCache = (options = {})=>{
55
43
  const defaultMatchCallback = ({ request })=>request.destination === "image";
56
44
  const cacheName = options.cacheName || "images";
57
45
  const matchCallback = options.matchCallback || defaultMatchCallback;
@@ -73,21 +61,15 @@ import { matchPrecache } from '@serwist/precaching';
73
61
  plugins
74
62
  });
75
63
  registerRoute(matchCallback, strategy);
76
- // Warms the cache
77
64
  if (options.warmCache) {
78
65
  warmStrategyCache({
79
66
  urls: options.warmCache,
80
67
  strategy
81
68
  });
82
69
  }
83
- }
84
-
85
- /**
86
- * An implementation of the [comprehensive fallbacks recipe](https://developers.google.com/web/tools/workbox/guides/advanced-recipes#comprehensive_fallbacks).
87
- * Be sure to include the fallbacks in your precache injection.
70
+ };
88
71
 
89
- * @param options
90
- */ function offlineFallback(options = {}) {
72
+ const offlineFallback = (options = {})=>{
91
73
  const pageFallback = options.pageFallback || "offline.html";
92
74
  const imageFallback = options.imageFallback || false;
93
75
  const fontFallback = options.fontFallback || false;
@@ -121,13 +103,9 @@ import { matchPrecache } from '@serwist/precaching';
121
103
  return Response.error();
122
104
  };
123
105
  setCatchHandler(handler);
124
- }
106
+ };
125
107
 
126
- /**
127
- * An implementation of a page caching recipe with a network timeout.
128
- *
129
- * @param options
130
- */ function pageCache(options = {}) {
108
+ function pageCache(options = {}) {
131
109
  const defaultMatchCallback = ({ request })=>request.mode === "navigate";
132
110
  const cacheName = options.cacheName || "pages";
133
111
  const matchCallback = options.matchCallback || defaultMatchCallback;
@@ -144,9 +122,7 @@ import { matchPrecache } from '@serwist/precaching';
144
122
  cacheName,
145
123
  plugins
146
124
  });
147
- // Registers the route
148
125
  registerRoute(matchCallback, strategy);
149
- // Warms the cache
150
126
  if (options.warmCache) {
151
127
  warmStrategyCache({
152
128
  urls: options.warmCache,
@@ -155,11 +131,7 @@ import { matchPrecache } from '@serwist/precaching';
155
131
  }
156
132
  }
157
133
 
158
- /**
159
- * An implementation of the [CSS and JavaScript files recipe](https://developers.google.com/web/tools/workbox/guides/common-recipes#cache_css_and_javascript_files).
160
- *
161
- * @param options
162
- */ function staticResourceCache(options = {}) {
134
+ function staticResourceCache(options = {}) {
163
135
  const defaultMatchCallback = ({ request })=>request.destination === "style" || request.destination === "script" || request.destination === "worker";
164
136
  const cacheName = options.cacheName || "static-resources";
165
137
  const matchCallback = options.matchCallback || defaultMatchCallback;
@@ -175,7 +147,6 @@ import { matchPrecache } from '@serwist/precaching';
175
147
  plugins
176
148
  });
177
149
  registerRoute(matchCallback, strategy);
178
- // Warms the cache
179
150
  if (options.warmCache) {
180
151
  warmStrategyCache({
181
152
  urls: options.warmCache,
@@ -18,6 +18,5 @@ export interface OfflineFallbackOptions {
18
18
 
19
19
  * @param options
20
20
  */
21
- declare function offlineFallback(options?: OfflineFallbackOptions): void;
22
- export { offlineFallback };
21
+ export declare const offlineFallback: (options?: OfflineFallbackOptions) => void;
23
22
  //# sourceMappingURL=offlineFallback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"offlineFallback.d.ts","sourceRoot":"","sources":["../src/offlineFallback.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAKD;;;;;GAKG;AACH,iBAAS,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,IAAI,CAwCnE;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"offlineFallback.d.ts","sourceRoot":"","sources":["../src/offlineFallback.ts"],"names":[],"mappings":"AAYA,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAKD;;;;;GAKG;AACH,eAAO,MAAM,eAAe,aAAa,sBAAsB,KAAQ,IAwCtE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/recipes",
3
- "version": "9.0.0-preview.0",
3
+ "version": "9.0.0-preview.10",
4
4
  "type": "module",
5
5
  "description": "A service worker helper library to manage common request and caching patterns",
6
6
  "files": [
@@ -30,17 +30,17 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "dependencies": {
33
- "@serwist/cacheable-response": "9.0.0-preview.0",
34
- "@serwist/core": "9.0.0-preview.0",
35
- "@serwist/expiration": "9.0.0-preview.0",
36
- "@serwist/precaching": "9.0.0-preview.0",
37
- "@serwist/routing": "9.0.0-preview.0",
38
- "@serwist/strategies": "9.0.0-preview.0"
33
+ "@serwist/cacheable-response": "9.0.0-preview.10",
34
+ "@serwist/core": "9.0.0-preview.10",
35
+ "@serwist/expiration": "9.0.0-preview.10",
36
+ "@serwist/precaching": "9.0.0-preview.10",
37
+ "@serwist/routing": "9.0.0-preview.10",
38
+ "@serwist/strategies": "9.0.0-preview.10"
39
39
  },
40
40
  "devDependencies": {
41
41
  "rollup": "4.9.6",
42
- "typescript": "5.4.0-dev.20240203",
43
- "@serwist/constants": "9.0.0-preview.0"
42
+ "typescript": "5.4.0-dev.20240206",
43
+ "@serwist/constants": "9.0.0-preview.10"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "typescript": ">=5.0.0"
package/src/imageCache.ts CHANGED
@@ -46,7 +46,7 @@ export interface ImageCacheOptions {
46
46
  *
47
47
  * @param options
48
48
  */
49
- function imageCache(options: ImageCacheOptions = {}): void {
49
+ export const imageCache = (options: ImageCacheOptions = {}): void => {
50
50
  const defaultMatchCallback = ({ request }: RouteMatchCallbackOptions) => request.destination === "image";
51
51
 
52
52
  const cacheName = options.cacheName || "images";
@@ -77,6 +77,4 @@ function imageCache(options: ImageCacheOptions = {}): void {
77
77
  if (options.warmCache) {
78
78
  warmStrategyCache({ urls: options.warmCache, strategy });
79
79
  }
80
- }
81
-
82
- export { imageCache };
80
+ };
@@ -34,7 +34,7 @@ declare let self: ServiceWorkerGlobalScope;
34
34
 
35
35
  * @param options
36
36
  */
37
- function offlineFallback(options: OfflineFallbackOptions = {}): void {
37
+ export const offlineFallback = (options: OfflineFallbackOptions = {}): void => {
38
38
  const pageFallback = options.pageFallback || "offline.html";
39
39
  const imageFallback = options.imageFallback || false;
40
40
  const fontFallback = options.fontFallback || false;
@@ -74,6 +74,4 @@ function offlineFallback(options: OfflineFallbackOptions = {}): void {
74
74
  };
75
75
 
76
76
  setCatchHandler(handler);
77
- }
78
-
79
- export { offlineFallback };
77
+ };