@serwist/recipes 9.0.0-preview.21 → 9.0.0-preview.25

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.
@@ -1,10 +1,9 @@
1
- import { type Router } from "@serwist/sw/routing";
1
+ import { Serwist } from "serwist";
2
2
  export interface GoogleFontCacheOptions {
3
3
  /**
4
- * An optional `Router` instance. If not provided, the singleton `Router`
5
- * will be used.
4
+ * Your `Serwist` instance.
6
5
  */
7
- router?: Router;
6
+ serwist: Serwist;
8
7
  /**
9
8
  * Cache prefix for caching stylesheets and webfonts. Defaults to google-fonts.
10
9
  */
@@ -23,5 +22,5 @@ export interface GoogleFontCacheOptions {
23
22
  *
24
23
  * @param options
25
24
  */
26
- export declare const googleFontsCache: ({ router, cachePrefix, maxAgeSeconds, maxEntries, }?: GoogleFontCacheOptions) => void;
25
+ export declare const googleFontsCache: ({ serwist, cachePrefix, maxAgeSeconds, maxEntries, }: GoogleFontCacheOptions) => void;
27
26
  //# sourceMappingURL=googleFontsCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"googleFontsCache.d.ts","sourceRoot":"","sources":["../src/googleFontsCache.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,MAAM,EAAsB,MAAM,qBAAqB,CAAC;AAGtE,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,yDAK1B,sBAAsB,KAAQ,IAyBhC,CAAC"}
1
+ {"version":3,"file":"googleFontsCache.d.ts","sourceRoot":"","sources":["../src/googleFontsCache.ts"],"names":[],"mappings":"AAOA,OAAO,EAAyD,OAAO,EAAwB,MAAM,SAAS,CAAC;AAE/G,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,yDAK1B,sBAAsB,KAAG,IAyB3B,CAAC"}
@@ -1,11 +1,10 @@
1
- import type { RouteMatchCallback, SerwistPlugin } from "@serwist/core";
2
- import { type Router } from "@serwist/sw/routing";
1
+ import type { RouteMatchCallback, SerwistPlugin } from "serwist";
2
+ import { Serwist } from "serwist";
3
3
  export interface ImageCacheOptions {
4
4
  /**
5
- * An optional `Router` instance. If not provided, the singleton `Router`
6
- * will be used.
5
+ * Your `Serwist` instance.
7
6
  */
8
- router?: Router;
7
+ serwist: Serwist;
9
8
  /**
10
9
  * Name for cache. Defaults to images.
11
10
  */
@@ -36,5 +35,5 @@ export interface ImageCacheOptions {
36
35
  *
37
36
  * @param options
38
37
  */
39
- export declare const imageCache: ({ router, cacheName, matchCallback, maxAgeSeconds, maxEntries, plugins, warmCache, }?: ImageCacheOptions) => void;
38
+ export declare const imageCache: ({ serwist, cacheName, matchCallback, maxAgeSeconds, maxEntries, plugins, warmCache, }: ImageCacheOptions) => void;
40
39
  //# sourceMappingURL=imageCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"imageCache.d.ts","sourceRoot":"","sources":["../src/imageCache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,eAAe,CAAC;AAElG,OAAO,EAAE,KAAK,MAAM,EAAsB,MAAM,qBAAqB,CAAC;AAItE,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;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,0FAQpB,iBAAiB,KAAQ,IAwB3B,CAAC"}
1
+ {"version":3,"file":"imageCache.d.ts","sourceRoot":"","sources":["../src/imageCache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAyD,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzF,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;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,0FAQpB,iBAAiB,KAAG,IAwBtB,CAAC"}
package/dist/index.js CHANGED
@@ -1,13 +1,10 @@
1
- import { CacheableResponsePlugin, ExpirationPlugin } from '@serwist/sw/plugins';
2
- import { getSingletonRouter, setCatchHandler } from '@serwist/sw/routing';
3
- import { StaleWhileRevalidate, CacheFirst, NetworkFirst } from '@serwist/sw/strategies';
4
- import { getSingletonPrecacheController } from '@serwist/sw/precaching';
1
+ import { StaleWhileRevalidate, CacheFirst, CacheableResponsePlugin, ExpirationPlugin, NetworkFirst } from 'serwist';
5
2
 
6
- const googleFontsCache = ({ router = getSingletonRouter(), cachePrefix = "google-fonts", maxAgeSeconds = 60 * 60 * 24 * 365, maxEntries = 30 } = {})=>{
7
- router.registerCapture(({ url })=>url.origin === "https://fonts.googleapis.com", new StaleWhileRevalidate({
3
+ const googleFontsCache = ({ serwist, cachePrefix = "google-fonts", maxAgeSeconds = 60 * 60 * 24 * 365, maxEntries = 30 })=>{
4
+ serwist.registerCapture(({ url })=>url.origin === "https://fonts.googleapis.com", new StaleWhileRevalidate({
8
5
  cacheName: `${cachePrefix}-stylesheets`
9
6
  }));
10
- router.registerCapture(({ url })=>url.origin === "https://fonts.gstatic.com", new CacheFirst({
7
+ serwist.registerCapture(({ url })=>url.origin === "https://fonts.gstatic.com", new CacheFirst({
11
8
  cacheName: `${cachePrefix}-webfonts`,
12
9
  plugins: [
13
10
  new CacheableResponsePlugin({
@@ -34,7 +31,7 @@ const warmStrategyCache = (options)=>{
34
31
  });
35
32
  };
36
33
 
37
- const imageCache = ({ router = getSingletonRouter(), cacheName = "images", matchCallback = ({ request })=>request.destination === "image", maxAgeSeconds = 30 * 24 * 60 * 60, maxEntries = 60, plugins = [], warmCache } = {})=>{
34
+ const imageCache = ({ serwist, cacheName = "images", matchCallback = ({ request })=>request.destination === "image", maxAgeSeconds = 30 * 24 * 60 * 60, maxEntries = 60, plugins = [], warmCache })=>{
38
35
  plugins.push(new CacheableResponsePlugin({
39
36
  statuses: [
40
37
  0,
@@ -49,7 +46,7 @@ const imageCache = ({ router = getSingletonRouter(), cacheName = "images", match
49
46
  cacheName,
50
47
  plugins
51
48
  });
52
- router.registerCapture(matchCallback, strategy);
49
+ serwist.registerCapture(matchCallback, strategy);
53
50
  if (warmCache) {
54
51
  warmStrategyCache({
55
52
  urls: warmCache,
@@ -58,7 +55,7 @@ const imageCache = ({ router = getSingletonRouter(), cacheName = "images", match
58
55
  }
59
56
  };
60
57
 
61
- const offlineFallback = ({ precacheController = getSingletonPrecacheController(), pageFallback = "offline.html", imageFallback, fontFallback } = {})=>{
58
+ const offlineFallback = ({ serwist, pageFallback = "offline.html", imageFallback, fontFallback })=>{
62
59
  self.addEventListener("install", (event)=>{
63
60
  const files = [
64
61
  pageFallback
@@ -75,23 +72,23 @@ const offlineFallback = ({ precacheController = getSingletonPrecacheController()
75
72
  const dest = options.request.destination;
76
73
  const cache = await self.caches.open("serwist-offline-fallbacks");
77
74
  if (dest === "document") {
78
- const match = await precacheController.matchPrecache(pageFallback) || await cache.match(pageFallback);
75
+ const match = await serwist.matchPrecache(pageFallback) || await cache.match(pageFallback);
79
76
  return match || Response.error();
80
77
  }
81
78
  if (dest === "image" && imageFallback !== undefined) {
82
- const match = await precacheController.matchPrecache(imageFallback) || await cache.match(imageFallback);
79
+ const match = await serwist.matchPrecache(imageFallback) || await cache.match(imageFallback);
83
80
  return match || Response.error();
84
81
  }
85
82
  if (dest === "font" && fontFallback !== undefined) {
86
- const match = await precacheController.matchPrecache(fontFallback) || await cache.match(fontFallback);
83
+ const match = await serwist.matchPrecache(fontFallback) || await cache.match(fontFallback);
87
84
  return match || Response.error();
88
85
  }
89
86
  return Response.error();
90
87
  };
91
- setCatchHandler(handler);
88
+ serwist.setCatchHandler(handler);
92
89
  };
93
90
 
94
- const pageCache = ({ router = getSingletonRouter(), cacheName = "pages", matchCallback = ({ request })=>request.mode === "navigate", networkTimeoutSeconds = 3, plugins = [], warmCache } = {})=>{
91
+ const pageCache = ({ serwist, cacheName = "pages", matchCallback = ({ request })=>request.mode === "navigate", networkTimeoutSeconds = 3, plugins = [], warmCache })=>{
95
92
  plugins.push(new CacheableResponsePlugin({
96
93
  statuses: [
97
94
  0,
@@ -103,7 +100,7 @@ const pageCache = ({ router = getSingletonRouter(), cacheName = "pages", matchCa
103
100
  cacheName,
104
101
  plugins
105
102
  });
106
- router.registerCapture(matchCallback, strategy);
103
+ serwist.registerCapture(matchCallback, strategy);
107
104
  if (warmCache) {
108
105
  warmStrategyCache({
109
106
  urls: warmCache,
@@ -112,7 +109,7 @@ const pageCache = ({ router = getSingletonRouter(), cacheName = "pages", matchCa
112
109
  }
113
110
  };
114
111
 
115
- const staticResourceCache = ({ router = getSingletonRouter(), cacheName = "static-resources", matchCallback = ({ request })=>request.destination === "style" || request.destination === "script" || request.destination === "worker", plugins = [], warmCache } = {})=>{
112
+ const staticResourceCache = ({ serwist, cacheName = "static-resources", matchCallback = ({ request })=>request.destination === "style" || request.destination === "script" || request.destination === "worker", plugins = [], warmCache })=>{
116
113
  plugins.push(new CacheableResponsePlugin({
117
114
  statuses: [
118
115
  0,
@@ -123,7 +120,7 @@ const staticResourceCache = ({ router = getSingletonRouter(), cacheName = "stati
123
120
  cacheName,
124
121
  plugins
125
122
  });
126
- router.registerCapture(matchCallback, strategy);
123
+ serwist.registerCapture(matchCallback, strategy);
127
124
  if (warmCache) {
128
125
  warmStrategyCache({
129
126
  urls: warmCache,
@@ -1,10 +1,9 @@
1
- import { type PrecacheController } from "@serwist/sw/precaching";
1
+ import type { Serwist } from "serwist";
2
2
  export interface OfflineFallbackOptions {
3
3
  /**
4
- * An optional `PrecacheController` instance. If not provided, the singleton
5
- * `PrecacheController` will be used.
4
+ * Your `Serwist` instance.
6
5
  */
7
- precacheController?: PrecacheController;
6
+ serwist: Serwist;
8
7
  /**
9
8
  * Precache name to match for page fallbacks. Defaults to offline.html.
10
9
  */
@@ -24,5 +23,5 @@ export interface OfflineFallbackOptions {
24
23
 
25
24
  * @param options
26
25
  */
27
- export declare const offlineFallback: ({ precacheController, pageFallback, imageFallback, fontFallback, }?: OfflineFallbackOptions) => void;
26
+ export declare const offlineFallback: ({ serwist, pageFallback, imageFallback, fontFallback }: OfflineFallbackOptions) => void;
28
27
  //# sourceMappingURL=offlineFallback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"offlineFallback.d.ts","sourceRoot":"","sources":["../src/offlineFallback.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,kBAAkB,EAAkC,MAAM,wBAAwB,CAAC;AAGjG,MAAM,WAAW,sBAAsB;IACrC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC;;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,wEAKzB,sBAAsB,KAAQ,IAoChC,CAAC"}
1
+ {"version":3,"file":"offlineFallback.d.ts","sourceRoot":"","sources":["../src/offlineFallback.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAA6C,OAAO,EAAE,MAAM,SAAS,CAAC;AAElF,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;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,2DAA6E,sBAAsB,KAAG,IAoCjI,CAAC"}
@@ -1,11 +1,10 @@
1
- import type { RouteMatchCallback, SerwistPlugin } from "@serwist/core";
2
- import { type Router } from "@serwist/sw/routing";
1
+ import type { RouteMatchCallback, SerwistPlugin } from "serwist";
2
+ import { Serwist } from "serwist";
3
3
  export interface PageCacheOptions {
4
4
  /**
5
- * An optional `Router` instance. If not provided, the singleton `Router`
6
- * will be used.
5
+ * Your `Serwist` instance.
7
6
  */
8
- router?: Router;
7
+ serwist: Serwist;
9
8
  /**
10
9
  * Name for cache. Defaults to pages.
11
10
  */
@@ -34,5 +33,5 @@ export interface PageCacheOptions {
34
33
  *
35
34
  * @param options
36
35
  */
37
- export declare const pageCache: ({ router, cacheName, matchCallback, networkTimeoutSeconds, plugins, warmCache, }?: PageCacheOptions) => void;
36
+ export declare const pageCache: ({ serwist, cacheName, matchCallback, networkTimeoutSeconds, plugins, warmCache, }: PageCacheOptions) => void;
38
37
  //# sourceMappingURL=pageCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pageCache.d.ts","sourceRoot":"","sources":["../src/pageCache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,eAAe,CAAC;AAElG,OAAO,EAAE,KAAK,MAAM,EAAsB,MAAM,qBAAqB,CAAC;AAItE,MAAM,WAAW,gBAAgB;IAC/B;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,sFAOnB,gBAAgB,KAAQ,IAoB1B,CAAC"}
1
+ {"version":3,"file":"pageCache.d.ts","sourceRoot":"","sources":["../src/pageCache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAAyC,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzE,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,SAAS,sFAOnB,gBAAgB,KAAG,IAoBrB,CAAC"}
@@ -1,11 +1,10 @@
1
- import type { RouteMatchCallback, SerwistPlugin } from "@serwist/core";
2
- import { type Router } from "@serwist/sw/routing";
1
+ import type { RouteMatchCallback, SerwistPlugin } from "serwist";
2
+ import { Serwist } from "serwist";
3
3
  export interface StaticResourceOptions {
4
4
  /**
5
- * An optional `Router` instance. If not provided, the singleton `Router`
6
- * will be used.
5
+ * Your `Serwist` instance.
7
6
  */
8
- router?: Router;
7
+ serwist: Serwist;
9
8
  /**
10
9
  * Name for cache.
11
10
  *
@@ -32,5 +31,5 @@ export interface StaticResourceOptions {
32
31
  *
33
32
  * @param options
34
33
  */
35
- export declare const staticResourceCache: ({ router, cacheName, matchCallback, plugins, warmCache, }?: StaticResourceOptions) => void;
34
+ export declare const staticResourceCache: ({ serwist, cacheName, matchCallback, plugins, warmCache, }: StaticResourceOptions) => void;
36
35
  //# sourceMappingURL=staticResourceCache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"staticResourceCache.d.ts","sourceRoot":"","sources":["../src/staticResourceCache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,eAAe,CAAC;AAElG,OAAO,EAAE,KAAK,MAAM,EAAsB,MAAM,qBAAqB,CAAC;AAItE,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,+DAO7B,qBAAqB,KAAQ,IAkB/B,CAAC"}
1
+ {"version":3,"file":"staticResourceCache.d.ts","sourceRoot":"","sources":["../src/staticResourceCache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAA6B,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5F,OAAO,EAA2B,OAAO,EAAwB,MAAM,SAAS,CAAC;AAGjF,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC;IACnC;;OAEG;IACH,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,+DAO7B,qBAAqB,KAAG,IAkB1B,CAAC"}
@@ -1,4 +1,4 @@
1
- import type { Strategy } from "@serwist/sw/strategies";
1
+ import type { Strategy } from "serwist";
2
2
  export interface WarmStrategyCacheOptions {
3
3
  /**
4
4
  * Paths to warm the strategy's cache with.
@@ -1 +1 @@
1
- {"version":3,"file":"warmStrategyCache.d.ts","sourceRoot":"","sources":["../src/warmStrategyCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAEvD,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAKD;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAAa,wBAAwB,KAAG,IAYrE,CAAC"}
1
+ {"version":3,"file":"warmStrategyCache.d.ts","sourceRoot":"","sources":["../src/warmStrategyCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAExC,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,IAAI,EAAE,MAAM,EAAE,CAAC;IACf;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;CACpB;AAKD;;GAEG;AACH,eAAO,MAAM,iBAAiB,YAAa,wBAAwB,KAAG,IAYrE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/recipes",
3
- "version": "9.0.0-preview.21",
3
+ "version": "9.0.0-preview.25",
4
4
  "type": "module",
5
5
  "description": "A service worker helper library to manage common request and caching patterns",
6
6
  "files": [
@@ -17,8 +17,8 @@
17
17
  ],
18
18
  "author": "Google's Web DevRel Team, Serwist's Team",
19
19
  "license": "MIT",
20
- "repository": "https://gitlab.com/serwist/serwist",
21
- "bugs": "https://gitlab.com/serwist/serwist/issues",
20
+ "repository": "https://github.com/serwist/serwist",
21
+ "bugs": "https://github.com/serwist/serwist/issues",
22
22
  "homepage": "https://serwist.pages.dev",
23
23
  "main": "./dist/index.js",
24
24
  "types": "./dist/index.d.ts",
@@ -30,13 +30,12 @@
30
30
  "./package.json": "./package.json"
31
31
  },
32
32
  "dependencies": {
33
- "@serwist/core": "9.0.0-preview.21",
34
- "@serwist/sw": "9.0.0-preview.21"
33
+ "serwist": "9.0.0-preview.25"
35
34
  },
36
35
  "devDependencies": {
37
- "rollup": "4.13.0",
38
- "typescript": "5.5.0-dev.20240323",
39
- "@serwist/constants": "9.0.0-preview.21"
36
+ "rollup": "4.14.3",
37
+ "typescript": "5.5.0-dev.20240415",
38
+ "@serwist/configs": "9.0.0-preview.25"
40
39
  },
41
40
  "peerDependencies": {
42
41
  "typescript": ">=5.0.0"
@@ -5,17 +5,13 @@
5
5
  license that can be found in the LICENSE file or at
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
-
9
- import { CacheableResponsePlugin, ExpirationPlugin } from "@serwist/sw/plugins";
10
- import { type Router, getSingletonRouter } from "@serwist/sw/routing";
11
- import { CacheFirst, StaleWhileRevalidate } from "@serwist/sw/strategies";
8
+ import { CacheFirst, CacheableResponsePlugin, ExpirationPlugin, Serwist, StaleWhileRevalidate } from "serwist";
12
9
 
13
10
  export interface GoogleFontCacheOptions {
14
11
  /**
15
- * An optional `Router` instance. If not provided, the singleton `Router`
16
- * will be used.
12
+ * Your `Serwist` instance.
17
13
  */
18
- router?: Router;
14
+ serwist: Serwist;
19
15
  /**
20
16
  * Cache prefix for caching stylesheets and webfonts. Defaults to google-fonts.
21
17
  */
@@ -36,13 +32,13 @@ export interface GoogleFontCacheOptions {
36
32
  * @param options
37
33
  */
38
34
  export const googleFontsCache = ({
39
- router = getSingletonRouter(),
35
+ serwist,
40
36
  cachePrefix = "google-fonts",
41
37
  maxAgeSeconds = 60 * 60 * 24 * 365,
42
38
  maxEntries = 30,
43
- }: GoogleFontCacheOptions = {}): void => {
39
+ }: GoogleFontCacheOptions): void => {
44
40
  // Cache the Google Fonts stylesheets with a stale-while-revalidate strategy.
45
- router.registerCapture(
41
+ serwist.registerCapture(
46
42
  ({ url }) => url.origin === "https://fonts.googleapis.com",
47
43
  new StaleWhileRevalidate({
48
44
  cacheName: `${cachePrefix}-stylesheets`,
@@ -50,7 +46,7 @@ export const googleFontsCache = ({
50
46
  );
51
47
 
52
48
  // Cache the underlying font files with a cache-first strategy for 1 year.
53
- router.registerCapture(
49
+ serwist.registerCapture(
54
50
  ({ url }) => url.origin === "https://fonts.gstatic.com",
55
51
  new CacheFirst({
56
52
  cacheName: `${cachePrefix}-webfonts`,
package/src/imageCache.ts CHANGED
@@ -6,18 +6,15 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "@serwist/core";
10
- import { CacheableResponsePlugin, ExpirationPlugin } from "@serwist/sw/plugins";
11
- import { type Router, getSingletonRouter } from "@serwist/sw/routing";
12
- import { CacheFirst } from "@serwist/sw/strategies";
9
+ import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "serwist";
10
+ import { CacheFirst, CacheableResponsePlugin, ExpirationPlugin, Serwist } from "serwist";
13
11
  import { warmStrategyCache } from "./warmStrategyCache.js";
14
12
 
15
13
  export interface ImageCacheOptions {
16
14
  /**
17
- * An optional `Router` instance. If not provided, the singleton `Router`
18
- * will be used.
15
+ * Your `Serwist` instance.
19
16
  */
20
- router?: Router;
17
+ serwist: Serwist;
21
18
  /**
22
19
  * Name for cache. Defaults to images.
23
20
  */
@@ -50,14 +47,14 @@ export interface ImageCacheOptions {
50
47
  * @param options
51
48
  */
52
49
  export const imageCache = ({
53
- router = getSingletonRouter(),
50
+ serwist,
54
51
  cacheName = "images",
55
52
  matchCallback = ({ request }: RouteMatchCallbackOptions) => request.destination === "image",
56
53
  maxAgeSeconds = 30 * 24 * 60 * 60,
57
54
  maxEntries = 60,
58
55
  plugins = [],
59
56
  warmCache,
60
- }: ImageCacheOptions = {}): void => {
57
+ }: ImageCacheOptions): void => {
61
58
  plugins.push(
62
59
  new CacheableResponsePlugin({
63
60
  statuses: [0, 200],
@@ -75,7 +72,7 @@ export const imageCache = ({
75
72
  plugins,
76
73
  });
77
74
 
78
- router.registerCapture(matchCallback, strategy);
75
+ serwist.registerCapture(matchCallback, strategy);
79
76
 
80
77
  // Warms the cache
81
78
  if (warmCache) {
@@ -6,16 +6,13 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { RouteHandler, RouteHandlerCallbackOptions } from "@serwist/core";
10
- import { type PrecacheController, getSingletonPrecacheController } from "@serwist/sw/precaching";
11
- import { setCatchHandler } from "@serwist/sw/routing";
9
+ import type { RouteHandler, RouteHandlerCallbackOptions, Serwist } from "serwist";
12
10
 
13
11
  export interface OfflineFallbackOptions {
14
12
  /**
15
- * An optional `PrecacheController` instance. If not provided, the singleton
16
- * `PrecacheController` will be used.
13
+ * Your `Serwist` instance.
17
14
  */
18
- precacheController?: PrecacheController;
15
+ serwist: Serwist;
19
16
  /**
20
17
  * Precache name to match for page fallbacks. Defaults to offline.html.
21
18
  */
@@ -39,12 +36,7 @@ declare let self: ServiceWorkerGlobalScope;
39
36
 
40
37
  * @param options
41
38
  */
42
- export const offlineFallback = ({
43
- precacheController = getSingletonPrecacheController(),
44
- pageFallback = "offline.html",
45
- imageFallback,
46
- fontFallback,
47
- }: OfflineFallbackOptions = {}): void => {
39
+ export const offlineFallback = ({ serwist, pageFallback = "offline.html", imageFallback, fontFallback }: OfflineFallbackOptions): void => {
48
40
  self.addEventListener("install", (event) => {
49
41
  const files = [pageFallback];
50
42
  if (imageFallback) {
@@ -62,22 +54,22 @@ export const offlineFallback = ({
62
54
  const cache = await self.caches.open("serwist-offline-fallbacks");
63
55
 
64
56
  if (dest === "document") {
65
- const match = (await precacheController.matchPrecache(pageFallback)) || (await cache.match(pageFallback));
57
+ const match = (await serwist.matchPrecache(pageFallback)) || (await cache.match(pageFallback));
66
58
  return match || Response.error();
67
59
  }
68
60
 
69
61
  if (dest === "image" && imageFallback !== undefined) {
70
- const match = (await precacheController.matchPrecache(imageFallback)) || (await cache.match(imageFallback));
62
+ const match = (await serwist.matchPrecache(imageFallback)) || (await cache.match(imageFallback));
71
63
  return match || Response.error();
72
64
  }
73
65
 
74
66
  if (dest === "font" && fontFallback !== undefined) {
75
- const match = (await precacheController.matchPrecache(fontFallback)) || (await cache.match(fontFallback));
67
+ const match = (await serwist.matchPrecache(fontFallback)) || (await cache.match(fontFallback));
76
68
  return match || Response.error();
77
69
  }
78
70
 
79
71
  return Response.error();
80
72
  };
81
73
 
82
- setCatchHandler(handler);
74
+ serwist.setCatchHandler(handler);
83
75
  };
package/src/pageCache.ts CHANGED
@@ -6,18 +6,15 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "@serwist/core";
10
- import { CacheableResponsePlugin } from "@serwist/sw/plugins";
11
- import { type Router, getSingletonRouter } from "@serwist/sw/routing";
12
- import { NetworkFirst } from "@serwist/sw/strategies";
9
+ import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "serwist";
10
+ import { CacheableResponsePlugin, NetworkFirst, Serwist } from "serwist";
13
11
  import { warmStrategyCache } from "./warmStrategyCache.js";
14
12
 
15
13
  export interface PageCacheOptions {
16
14
  /**
17
- * An optional `Router` instance. If not provided, the singleton `Router`
18
- * will be used.
15
+ * Your `Serwist` instance.
19
16
  */
20
- router?: Router;
17
+ serwist: Serwist;
21
18
  /**
22
19
  * Name for cache. Defaults to pages.
23
20
  */
@@ -48,13 +45,13 @@ export interface PageCacheOptions {
48
45
  * @param options
49
46
  */
50
47
  export const pageCache = ({
51
- router = getSingletonRouter(),
48
+ serwist,
52
49
  cacheName = "pages",
53
50
  matchCallback = ({ request }: RouteMatchCallbackOptions) => request.mode === "navigate",
54
51
  networkTimeoutSeconds = 3,
55
52
  plugins = [],
56
53
  warmCache,
57
- }: PageCacheOptions = {}): void => {
54
+ }: PageCacheOptions): void => {
58
55
  plugins.push(
59
56
  new CacheableResponsePlugin({
60
57
  statuses: [0, 200],
@@ -68,7 +65,7 @@ export const pageCache = ({
68
65
  });
69
66
 
70
67
  // Registers the route
71
- router.registerCapture(matchCallback, strategy);
68
+ serwist.registerCapture(matchCallback, strategy);
72
69
 
73
70
  // Warms the cache
74
71
  if (warmCache) {
@@ -6,18 +6,15 @@
6
6
  https://opensource.org/licenses/MIT.
7
7
  */
8
8
 
9
- import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "@serwist/core";
10
- import { CacheableResponsePlugin } from "@serwist/sw/plugins";
11
- import { type Router, getSingletonRouter } from "@serwist/sw/routing";
12
- import { StaleWhileRevalidate } from "@serwist/sw/strategies";
9
+ import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "serwist";
10
+ import { CacheableResponsePlugin, Serwist, StaleWhileRevalidate } from "serwist";
13
11
  import { warmStrategyCache } from "./warmStrategyCache.js";
14
12
 
15
13
  export interface StaticResourceOptions {
16
14
  /**
17
- * An optional `Router` instance. If not provided, the singleton `Router`
18
- * will be used.
15
+ * Your `Serwist` instance.
19
16
  */
20
- router?: Router;
17
+ serwist: Serwist;
21
18
  /**
22
19
  * Name for cache.
23
20
  *
@@ -46,13 +43,13 @@ export interface StaticResourceOptions {
46
43
  * @param options
47
44
  */
48
45
  export const staticResourceCache = ({
49
- router = getSingletonRouter(),
46
+ serwist,
50
47
  cacheName = "static-resources",
51
48
  matchCallback = ({ request }: RouteMatchCallbackOptions) =>
52
49
  request.destination === "style" || request.destination === "script" || request.destination === "worker",
53
50
  plugins = [],
54
51
  warmCache,
55
- }: StaticResourceOptions = {}): void => {
52
+ }: StaticResourceOptions): void => {
56
53
  plugins.push(
57
54
  new CacheableResponsePlugin({
58
55
  statuses: [0, 200],
@@ -64,7 +61,7 @@ export const staticResourceCache = ({
64
61
  plugins,
65
62
  });
66
63
 
67
- router.registerCapture(matchCallback, strategy);
64
+ serwist.registerCapture(matchCallback, strategy);
68
65
 
69
66
  // Warms the cache
70
67
  if (warmCache) {
@@ -1,4 +1,4 @@
1
- import type { Strategy } from "@serwist/sw/strategies";
1
+ import type { Strategy } from "serwist";
2
2
 
3
3
  export interface WarmStrategyCacheOptions {
4
4
  /**