@serwist/recipes 9.0.0-preview.21 → 9.0.0-preview.24
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.
- package/dist/googleFontsCache.d.ts +4 -5
- package/dist/googleFontsCache.d.ts.map +1 -1
- package/dist/imageCache.d.ts +5 -6
- package/dist/imageCache.d.ts.map +1 -1
- package/dist/index.js +16 -18
- package/dist/offlineFallback.d.ts +4 -5
- package/dist/offlineFallback.d.ts.map +1 -1
- package/dist/pageCache.d.ts +5 -6
- package/dist/pageCache.d.ts.map +1 -1
- package/dist/staticResourceCache.d.ts +5 -6
- package/dist/staticResourceCache.d.ts.map +1 -1
- package/dist/warmStrategyCache.d.ts +1 -1
- package/dist/warmStrategyCache.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/googleFontsCache.ts +9 -11
- package/src/imageCache.ts +9 -10
- package/src/offlineFallback.ts +9 -12
- package/src/pageCache.ts +9 -10
- package/src/staticResourceCache.ts +9 -10
- package/src/warmStrategyCache.ts +1 -1
| @@ -1,10 +1,9 @@ | |
| 1 | 
            -
            import {  | 
| 1 | 
            +
            import { Serwist } from "serwist";
         | 
| 2 2 | 
             
            export interface GoogleFontCacheOptions {
         | 
| 3 3 | 
             
                /**
         | 
| 4 | 
            -
                 *  | 
| 5 | 
            -
                 * will be used.
         | 
| 4 | 
            +
                 * Your `Serwist` instance.
         | 
| 6 5 | 
             
                 */
         | 
| 7 | 
            -
                 | 
| 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: ({  | 
| 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":" | 
| 1 | 
            +
            {"version":3,"file":"googleFontsCache.d.ts","sourceRoot":"","sources":["../src/googleFontsCache.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAIlC,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"}
         | 
    
        package/dist/imageCache.d.ts
    CHANGED
    
    | @@ -1,11 +1,10 @@ | |
| 1 | 
            -
            import type { RouteMatchCallback, SerwistPlugin } from " | 
| 2 | 
            -
            import {  | 
| 1 | 
            +
            import type { RouteMatchCallback, SerwistPlugin } from "serwist";
         | 
| 2 | 
            +
            import { Serwist } from "serwist";
         | 
| 3 3 | 
             
            export interface ImageCacheOptions {
         | 
| 4 4 | 
             
                /**
         | 
| 5 | 
            -
                 *  | 
| 6 | 
            -
                 * will be used.
         | 
| 5 | 
            +
                 * Your `Serwist` instance.
         | 
| 7 6 | 
             
                 */
         | 
| 8 | 
            -
                 | 
| 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: ({  | 
| 38 | 
            +
            export declare const imageCache: ({ serwist, cacheName, matchCallback, maxAgeSeconds, maxEntries, plugins, warmCache, }: ImageCacheOptions) => void;
         | 
| 40 39 | 
             
            //# sourceMappingURL=imageCache.d.ts.map
         | 
    
        package/dist/imageCache.d.ts.map
    CHANGED
    
    | @@ -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, | 
| 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,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKlC,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,11 @@ | |
| 1 | 
            -
            import { CacheableResponsePlugin, ExpirationPlugin } from ' | 
| 2 | 
            -
            import {  | 
| 3 | 
            -
            import { StaleWhileRevalidate, CacheFirst, NetworkFirst } from '@serwist/sw/strategies';
         | 
| 4 | 
            -
            import { getSingletonPrecacheController } from '@serwist/sw/precaching';
         | 
| 1 | 
            +
            import { CacheableResponsePlugin, ExpirationPlugin } from 'serwist/plugins';
         | 
| 2 | 
            +
            import { StaleWhileRevalidate, CacheFirst, NetworkFirst } from 'serwist/strategies';
         | 
| 5 3 |  | 
| 6 | 
            -
            const googleFontsCache = ({  | 
| 7 | 
            -
                 | 
| 4 | 
            +
            const googleFontsCache = ({ serwist, cachePrefix = "google-fonts", maxAgeSeconds = 60 * 60 * 24 * 365, maxEntries = 30 })=>{
         | 
| 5 | 
            +
                serwist.registerCapture(({ url })=>url.origin === "https://fonts.googleapis.com", new StaleWhileRevalidate({
         | 
| 8 6 | 
             
                    cacheName: `${cachePrefix}-stylesheets`
         | 
| 9 7 | 
             
                }));
         | 
| 10 | 
            -
                 | 
| 8 | 
            +
                serwist.registerCapture(({ url })=>url.origin === "https://fonts.gstatic.com", new CacheFirst({
         | 
| 11 9 | 
             
                    cacheName: `${cachePrefix}-webfonts`,
         | 
| 12 10 | 
             
                    plugins: [
         | 
| 13 11 | 
             
                        new CacheableResponsePlugin({
         | 
| @@ -34,7 +32,7 @@ const warmStrategyCache = (options)=>{ | |
| 34 32 | 
             
                });
         | 
| 35 33 | 
             
            };
         | 
| 36 34 |  | 
| 37 | 
            -
            const imageCache = ({  | 
| 35 | 
            +
            const imageCache = ({ serwist, cacheName = "images", matchCallback = ({ request })=>request.destination === "image", maxAgeSeconds = 30 * 24 * 60 * 60, maxEntries = 60, plugins = [], warmCache })=>{
         | 
| 38 36 | 
             
                plugins.push(new CacheableResponsePlugin({
         | 
| 39 37 | 
             
                    statuses: [
         | 
| 40 38 | 
             
                        0,
         | 
| @@ -49,7 +47,7 @@ const imageCache = ({ router = getSingletonRouter(), cacheName = "images", match | |
| 49 47 | 
             
                    cacheName,
         | 
| 50 48 | 
             
                    plugins
         | 
| 51 49 | 
             
                });
         | 
| 52 | 
            -
                 | 
| 50 | 
            +
                serwist.registerCapture(matchCallback, strategy);
         | 
| 53 51 | 
             
                if (warmCache) {
         | 
| 54 52 | 
             
                    warmStrategyCache({
         | 
| 55 53 | 
             
                        urls: warmCache,
         | 
| @@ -58,7 +56,7 @@ const imageCache = ({ router = getSingletonRouter(), cacheName = "images", match | |
| 58 56 | 
             
                }
         | 
| 59 57 | 
             
            };
         | 
| 60 58 |  | 
| 61 | 
            -
            const offlineFallback = ({  | 
| 59 | 
            +
            const offlineFallback = ({ serwist, pageFallback = "offline.html", imageFallback, fontFallback })=>{
         | 
| 62 60 | 
             
                self.addEventListener("install", (event)=>{
         | 
| 63 61 | 
             
                    const files = [
         | 
| 64 62 | 
             
                        pageFallback
         | 
| @@ -75,23 +73,23 @@ const offlineFallback = ({ precacheController = getSingletonPrecacheController() | |
| 75 73 | 
             
                    const dest = options.request.destination;
         | 
| 76 74 | 
             
                    const cache = await self.caches.open("serwist-offline-fallbacks");
         | 
| 77 75 | 
             
                    if (dest === "document") {
         | 
| 78 | 
            -
                        const match = await  | 
| 76 | 
            +
                        const match = await serwist.matchPrecache(pageFallback) || await cache.match(pageFallback);
         | 
| 79 77 | 
             
                        return match || Response.error();
         | 
| 80 78 | 
             
                    }
         | 
| 81 79 | 
             
                    if (dest === "image" && imageFallback !== undefined) {
         | 
| 82 | 
            -
                        const match = await  | 
| 80 | 
            +
                        const match = await serwist.matchPrecache(imageFallback) || await cache.match(imageFallback);
         | 
| 83 81 | 
             
                        return match || Response.error();
         | 
| 84 82 | 
             
                    }
         | 
| 85 83 | 
             
                    if (dest === "font" && fontFallback !== undefined) {
         | 
| 86 | 
            -
                        const match = await  | 
| 84 | 
            +
                        const match = await serwist.matchPrecache(fontFallback) || await cache.match(fontFallback);
         | 
| 87 85 | 
             
                        return match || Response.error();
         | 
| 88 86 | 
             
                    }
         | 
| 89 87 | 
             
                    return Response.error();
         | 
| 90 88 | 
             
                };
         | 
| 91 | 
            -
                setCatchHandler(handler);
         | 
| 89 | 
            +
                serwist.setCatchHandler(handler);
         | 
| 92 90 | 
             
            };
         | 
| 93 91 |  | 
| 94 | 
            -
            const pageCache = ({  | 
| 92 | 
            +
            const pageCache = ({ serwist, cacheName = "pages", matchCallback = ({ request })=>request.mode === "navigate", networkTimeoutSeconds = 3, plugins = [], warmCache })=>{
         | 
| 95 93 | 
             
                plugins.push(new CacheableResponsePlugin({
         | 
| 96 94 | 
             
                    statuses: [
         | 
| 97 95 | 
             
                        0,
         | 
| @@ -103,7 +101,7 @@ const pageCache = ({ router = getSingletonRouter(), cacheName = "pages", matchCa | |
| 103 101 | 
             
                    cacheName,
         | 
| 104 102 | 
             
                    plugins
         | 
| 105 103 | 
             
                });
         | 
| 106 | 
            -
                 | 
| 104 | 
            +
                serwist.registerCapture(matchCallback, strategy);
         | 
| 107 105 | 
             
                if (warmCache) {
         | 
| 108 106 | 
             
                    warmStrategyCache({
         | 
| 109 107 | 
             
                        urls: warmCache,
         | 
| @@ -112,7 +110,7 @@ const pageCache = ({ router = getSingletonRouter(), cacheName = "pages", matchCa | |
| 112 110 | 
             
                }
         | 
| 113 111 | 
             
            };
         | 
| 114 112 |  | 
| 115 | 
            -
            const staticResourceCache = ({  | 
| 113 | 
            +
            const staticResourceCache = ({ serwist, cacheName = "static-resources", matchCallback = ({ request })=>request.destination === "style" || request.destination === "script" || request.destination === "worker", plugins = [], warmCache })=>{
         | 
| 116 114 | 
             
                plugins.push(new CacheableResponsePlugin({
         | 
| 117 115 | 
             
                    statuses: [
         | 
| 118 116 | 
             
                        0,
         | 
| @@ -123,7 +121,7 @@ const staticResourceCache = ({ router = getSingletonRouter(), cacheName = "stati | |
| 123 121 | 
             
                    cacheName,
         | 
| 124 122 | 
             
                    plugins
         | 
| 125 123 | 
             
                });
         | 
| 126 | 
            -
                 | 
| 124 | 
            +
                serwist.registerCapture(matchCallback, strategy);
         | 
| 127 125 | 
             
                if (warmCache) {
         | 
| 128 126 | 
             
                    warmStrategyCache({
         | 
| 129 127 | 
             
                        urls: warmCache,
         | 
| @@ -1,10 +1,9 @@ | |
| 1 | 
            -
            import {  | 
| 1 | 
            +
            import type { Serwist } from "serwist";
         | 
| 2 2 | 
             
            export interface OfflineFallbackOptions {
         | 
| 3 3 | 
             
                /**
         | 
| 4 | 
            -
                 *  | 
| 5 | 
            -
                 * `PrecacheController` will be used.
         | 
| 4 | 
            +
                 * Your `Serwist` instance.
         | 
| 6 5 | 
             
                 */
         | 
| 7 | 
            -
                 | 
| 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: ({  | 
| 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":" | 
| 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,4DAKzB,sBAAsB,KAAG,IAoC3B,CAAC"}
         | 
    
        package/dist/pageCache.d.ts
    CHANGED
    
    | @@ -1,11 +1,10 @@ | |
| 1 | 
            -
            import type { RouteMatchCallback, SerwistPlugin } from " | 
| 2 | 
            -
            import {  | 
| 1 | 
            +
            import type { RouteMatchCallback, SerwistPlugin } from "serwist";
         | 
| 2 | 
            +
            import { Serwist } from "serwist";
         | 
| 3 3 | 
             
            export interface PageCacheOptions {
         | 
| 4 4 | 
             
                /**
         | 
| 5 | 
            -
                 *  | 
| 6 | 
            -
                 * will be used.
         | 
| 5 | 
            +
                 * Your `Serwist` instance.
         | 
| 7 6 | 
             
                 */
         | 
| 8 | 
            -
                 | 
| 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: ({  | 
| 36 | 
            +
            export declare const pageCache: ({ serwist, cacheName, matchCallback, networkTimeoutSeconds, plugins, warmCache, }: PageCacheOptions) => void;
         | 
| 38 37 | 
             
            //# sourceMappingURL=pageCache.d.ts.map
         | 
    
        package/dist/pageCache.d.ts.map
    CHANGED
    
    | @@ -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, | 
| 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,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKlC,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 " | 
| 2 | 
            -
            import {  | 
| 1 | 
            +
            import type { RouteMatchCallback, SerwistPlugin } from "serwist";
         | 
| 2 | 
            +
            import { Serwist } from "serwist";
         | 
| 3 3 | 
             
            export interface StaticResourceOptions {
         | 
| 4 4 | 
             
                /**
         | 
| 5 | 
            -
                 *  | 
| 6 | 
            -
                 * will be used.
         | 
| 5 | 
            +
                 * Your `Serwist` instance.
         | 
| 7 6 | 
             
                 */
         | 
| 8 | 
            -
                 | 
| 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: ({  | 
| 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, | 
| 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,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAKlC,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 +1 @@ | |
| 1 | 
            -
            {"version":3,"file":"warmStrategyCache.d.ts","sourceRoot":"","sources":["../src/warmStrategyCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM, | 
| 1 | 
            +
            {"version":3,"file":"warmStrategyCache.d.ts","sourceRoot":"","sources":["../src/warmStrategyCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,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. | 
| 3 | 
            +
              "version": "9.0.0-preview.24",
         | 
| 4 4 | 
             
              "type": "module",
         | 
| 5 5 | 
             
              "description": "A service worker helper library to manage common request and caching patterns",
         | 
| 6 6 | 
             
              "files": [
         | 
| @@ -30,13 +30,12 @@ | |
| 30 30 | 
             
                "./package.json": "./package.json"
         | 
| 31 31 | 
             
              },
         | 
| 32 32 | 
             
              "dependencies": {
         | 
| 33 | 
            -
                " | 
| 34 | 
            -
                "@serwist/sw": "9.0.0-preview.21"
         | 
| 33 | 
            +
                "serwist": "9.0.0-preview.24"
         | 
| 35 34 | 
             
              },
         | 
| 36 35 | 
             
              "devDependencies": {
         | 
| 37 | 
            -
                "rollup": "4. | 
| 38 | 
            -
                "typescript": "5.5.0-dev. | 
| 39 | 
            -
                "@serwist/constants": "9.0.0-preview. | 
| 36 | 
            +
                "rollup": "4.14.0",
         | 
| 37 | 
            +
                "typescript": "5.5.0-dev.20240404",
         | 
| 38 | 
            +
                "@serwist/constants": "9.0.0-preview.24"
         | 
| 40 39 | 
             
              },
         | 
| 41 40 | 
             
              "peerDependencies": {
         | 
| 42 41 | 
             
                "typescript": ">=5.0.0"
         | 
    
        package/src/googleFontsCache.ts
    CHANGED
    
    | @@ -5,17 +5,15 @@ | |
| 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 " | 
| 10 | 
            -
            import {  | 
| 11 | 
            -
            import { CacheFirst, StaleWhileRevalidate } from "@serwist/sw/strategies";
         | 
| 8 | 
            +
            import { Serwist } from "serwist";
         | 
| 9 | 
            +
            import { CacheableResponsePlugin, ExpirationPlugin } from "serwist/plugins";
         | 
| 10 | 
            +
            import { CacheFirst, StaleWhileRevalidate } from "serwist/strategies";
         | 
| 12 11 |  | 
| 13 12 | 
             
            export interface GoogleFontCacheOptions {
         | 
| 14 13 | 
             
              /**
         | 
| 15 | 
            -
               *  | 
| 16 | 
            -
               * will be used.
         | 
| 14 | 
            +
               * Your `Serwist` instance.
         | 
| 17 15 | 
             
               */
         | 
| 18 | 
            -
               | 
| 16 | 
            +
              serwist: Serwist;
         | 
| 19 17 | 
             
              /**
         | 
| 20 18 | 
             
               * Cache prefix for caching stylesheets and webfonts. Defaults to google-fonts.
         | 
| 21 19 | 
             
               */
         | 
| @@ -36,13 +34,13 @@ export interface GoogleFontCacheOptions { | |
| 36 34 | 
             
             * @param options
         | 
| 37 35 | 
             
             */
         | 
| 38 36 | 
             
            export const googleFontsCache = ({
         | 
| 39 | 
            -
               | 
| 37 | 
            +
              serwist,
         | 
| 40 38 | 
             
              cachePrefix = "google-fonts",
         | 
| 41 39 | 
             
              maxAgeSeconds = 60 * 60 * 24 * 365,
         | 
| 42 40 | 
             
              maxEntries = 30,
         | 
| 43 | 
            -
            }: GoogleFontCacheOptions | 
| 41 | 
            +
            }: GoogleFontCacheOptions): void => {
         | 
| 44 42 | 
             
              // Cache the Google Fonts stylesheets with a stale-while-revalidate strategy.
         | 
| 45 | 
            -
               | 
| 43 | 
            +
              serwist.registerCapture(
         | 
| 46 44 | 
             
                ({ url }) => url.origin === "https://fonts.googleapis.com",
         | 
| 47 45 | 
             
                new StaleWhileRevalidate({
         | 
| 48 46 | 
             
                  cacheName: `${cachePrefix}-stylesheets`,
         | 
| @@ -50,7 +48,7 @@ export const googleFontsCache = ({ | |
| 50 48 | 
             
              );
         | 
| 51 49 |  | 
| 52 50 | 
             
              // Cache the underlying font files with a cache-first strategy for 1 year.
         | 
| 53 | 
            -
               | 
| 51 | 
            +
              serwist.registerCapture(
         | 
| 54 52 | 
             
                ({ url }) => url.origin === "https://fonts.gstatic.com",
         | 
| 55 53 | 
             
                new CacheFirst({
         | 
| 56 54 | 
             
                  cacheName: `${cachePrefix}-webfonts`,
         | 
    
        package/src/imageCache.ts
    CHANGED
    
    | @@ -6,18 +6,17 @@ | |
| 6 6 | 
             
              https://opensource.org/licenses/MIT.
         | 
| 7 7 | 
             
            */
         | 
| 8 8 |  | 
| 9 | 
            -
            import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from " | 
| 10 | 
            -
            import {  | 
| 11 | 
            -
            import {  | 
| 12 | 
            -
            import { CacheFirst } from " | 
| 9 | 
            +
            import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "serwist";
         | 
| 10 | 
            +
            import { Serwist } from "serwist";
         | 
| 11 | 
            +
            import { CacheableResponsePlugin, ExpirationPlugin } from "serwist/plugins";
         | 
| 12 | 
            +
            import { CacheFirst } from "serwist/strategies";
         | 
| 13 13 | 
             
            import { warmStrategyCache } from "./warmStrategyCache.js";
         | 
| 14 14 |  | 
| 15 15 | 
             
            export interface ImageCacheOptions {
         | 
| 16 16 | 
             
              /**
         | 
| 17 | 
            -
               *  | 
| 18 | 
            -
               * will be used.
         | 
| 17 | 
            +
               * Your `Serwist` instance.
         | 
| 19 18 | 
             
               */
         | 
| 20 | 
            -
               | 
| 19 | 
            +
              serwist: Serwist;
         | 
| 21 20 | 
             
              /**
         | 
| 22 21 | 
             
               * Name for cache. Defaults to images.
         | 
| 23 22 | 
             
               */
         | 
| @@ -50,14 +49,14 @@ export interface ImageCacheOptions { | |
| 50 49 | 
             
             * @param options
         | 
| 51 50 | 
             
             */
         | 
| 52 51 | 
             
            export const imageCache = ({
         | 
| 53 | 
            -
               | 
| 52 | 
            +
              serwist,
         | 
| 54 53 | 
             
              cacheName = "images",
         | 
| 55 54 | 
             
              matchCallback = ({ request }: RouteMatchCallbackOptions) => request.destination === "image",
         | 
| 56 55 | 
             
              maxAgeSeconds = 30 * 24 * 60 * 60,
         | 
| 57 56 | 
             
              maxEntries = 60,
         | 
| 58 57 | 
             
              plugins = [],
         | 
| 59 58 | 
             
              warmCache,
         | 
| 60 | 
            -
            }: ImageCacheOptions | 
| 59 | 
            +
            }: ImageCacheOptions): void => {
         | 
| 61 60 | 
             
              plugins.push(
         | 
| 62 61 | 
             
                new CacheableResponsePlugin({
         | 
| 63 62 | 
             
                  statuses: [0, 200],
         | 
| @@ -75,7 +74,7 @@ export const imageCache = ({ | |
| 75 74 | 
             
                plugins,
         | 
| 76 75 | 
             
              });
         | 
| 77 76 |  | 
| 78 | 
            -
               | 
| 77 | 
            +
              serwist.registerCapture(matchCallback, strategy);
         | 
| 79 78 |  | 
| 80 79 | 
             
              // Warms the cache
         | 
| 81 80 | 
             
              if (warmCache) {
         | 
    
        package/src/offlineFallback.ts
    CHANGED
    
    | @@ -6,16 +6,13 @@ | |
| 6 6 | 
             
              https://opensource.org/licenses/MIT.
         | 
| 7 7 | 
             
            */
         | 
| 8 8 |  | 
| 9 | 
            -
            import type { RouteHandler, RouteHandlerCallbackOptions } from " | 
| 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 | 
            -
               *  | 
| 16 | 
            -
               * `PrecacheController` will be used.
         | 
| 13 | 
            +
               * Your `Serwist` instance.
         | 
| 17 14 | 
             
               */
         | 
| 18 | 
            -
               | 
| 15 | 
            +
              serwist: Serwist;
         | 
| 19 16 | 
             
              /**
         | 
| 20 17 | 
             
               * Precache name to match for page fallbacks. Defaults to offline.html.
         | 
| 21 18 | 
             
               */
         | 
| @@ -40,11 +37,11 @@ declare let self: ServiceWorkerGlobalScope; | |
| 40 37 | 
             
             * @param options
         | 
| 41 38 | 
             
             */
         | 
| 42 39 | 
             
            export const offlineFallback = ({
         | 
| 43 | 
            -
               | 
| 40 | 
            +
              serwist,
         | 
| 44 41 | 
             
              pageFallback = "offline.html",
         | 
| 45 42 | 
             
              imageFallback,
         | 
| 46 43 | 
             
              fontFallback,
         | 
| 47 | 
            -
            }: OfflineFallbackOptions | 
| 44 | 
            +
            }: OfflineFallbackOptions): void => {
         | 
| 48 45 | 
             
              self.addEventListener("install", (event) => {
         | 
| 49 46 | 
             
                const files = [pageFallback];
         | 
| 50 47 | 
             
                if (imageFallback) {
         | 
| @@ -62,22 +59,22 @@ export const offlineFallback = ({ | |
| 62 59 | 
             
                const cache = await self.caches.open("serwist-offline-fallbacks");
         | 
| 63 60 |  | 
| 64 61 | 
             
                if (dest === "document") {
         | 
| 65 | 
            -
                  const match = (await  | 
| 62 | 
            +
                  const match = (await serwist.matchPrecache(pageFallback)) || (await cache.match(pageFallback));
         | 
| 66 63 | 
             
                  return match || Response.error();
         | 
| 67 64 | 
             
                }
         | 
| 68 65 |  | 
| 69 66 | 
             
                if (dest === "image" && imageFallback !== undefined) {
         | 
| 70 | 
            -
                  const match = (await  | 
| 67 | 
            +
                  const match = (await serwist.matchPrecache(imageFallback)) || (await cache.match(imageFallback));
         | 
| 71 68 | 
             
                  return match || Response.error();
         | 
| 72 69 | 
             
                }
         | 
| 73 70 |  | 
| 74 71 | 
             
                if (dest === "font" && fontFallback !== undefined) {
         | 
| 75 | 
            -
                  const match = (await  | 
| 72 | 
            +
                  const match = (await serwist.matchPrecache(fontFallback)) || (await cache.match(fontFallback));
         | 
| 76 73 | 
             
                  return match || Response.error();
         | 
| 77 74 | 
             
                }
         | 
| 78 75 |  | 
| 79 76 | 
             
                return Response.error();
         | 
| 80 77 | 
             
              };
         | 
| 81 78 |  | 
| 82 | 
            -
              setCatchHandler(handler);
         | 
| 79 | 
            +
              serwist.setCatchHandler(handler);
         | 
| 83 80 | 
             
            };
         | 
    
        package/src/pageCache.ts
    CHANGED
    
    | @@ -6,18 +6,17 @@ | |
| 6 6 | 
             
              https://opensource.org/licenses/MIT.
         | 
| 7 7 | 
             
            */
         | 
| 8 8 |  | 
| 9 | 
            -
            import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from " | 
| 10 | 
            -
            import {  | 
| 11 | 
            -
            import {  | 
| 12 | 
            -
            import { NetworkFirst } from " | 
| 9 | 
            +
            import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "serwist";
         | 
| 10 | 
            +
            import { Serwist } from "serwist";
         | 
| 11 | 
            +
            import { CacheableResponsePlugin } from "serwist/plugins";
         | 
| 12 | 
            +
            import { NetworkFirst } from "serwist/strategies";
         | 
| 13 13 | 
             
            import { warmStrategyCache } from "./warmStrategyCache.js";
         | 
| 14 14 |  | 
| 15 15 | 
             
            export interface PageCacheOptions {
         | 
| 16 16 | 
             
              /**
         | 
| 17 | 
            -
               *  | 
| 18 | 
            -
               * will be used.
         | 
| 17 | 
            +
               * Your `Serwist` instance.
         | 
| 19 18 | 
             
               */
         | 
| 20 | 
            -
               | 
| 19 | 
            +
              serwist: Serwist;
         | 
| 21 20 | 
             
              /**
         | 
| 22 21 | 
             
               * Name for cache. Defaults to pages.
         | 
| 23 22 | 
             
               */
         | 
| @@ -48,13 +47,13 @@ export interface PageCacheOptions { | |
| 48 47 | 
             
             * @param options
         | 
| 49 48 | 
             
             */
         | 
| 50 49 | 
             
            export const pageCache = ({
         | 
| 51 | 
            -
               | 
| 50 | 
            +
              serwist,
         | 
| 52 51 | 
             
              cacheName = "pages",
         | 
| 53 52 | 
             
              matchCallback = ({ request }: RouteMatchCallbackOptions) => request.mode === "navigate",
         | 
| 54 53 | 
             
              networkTimeoutSeconds = 3,
         | 
| 55 54 | 
             
              plugins = [],
         | 
| 56 55 | 
             
              warmCache,
         | 
| 57 | 
            -
            }: PageCacheOptions | 
| 56 | 
            +
            }: PageCacheOptions): void => {
         | 
| 58 57 | 
             
              plugins.push(
         | 
| 59 58 | 
             
                new CacheableResponsePlugin({
         | 
| 60 59 | 
             
                  statuses: [0, 200],
         | 
| @@ -68,7 +67,7 @@ export const pageCache = ({ | |
| 68 67 | 
             
              });
         | 
| 69 68 |  | 
| 70 69 | 
             
              // Registers the route
         | 
| 71 | 
            -
               | 
| 70 | 
            +
              serwist.registerCapture(matchCallback, strategy);
         | 
| 72 71 |  | 
| 73 72 | 
             
              // Warms the cache
         | 
| 74 73 | 
             
              if (warmCache) {
         | 
| @@ -6,18 +6,17 @@ | |
| 6 6 | 
             
              https://opensource.org/licenses/MIT.
         | 
| 7 7 | 
             
            */
         | 
| 8 8 |  | 
| 9 | 
            -
            import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from " | 
| 10 | 
            -
            import {  | 
| 11 | 
            -
            import {  | 
| 12 | 
            -
            import { StaleWhileRevalidate } from " | 
| 9 | 
            +
            import type { RouteMatchCallback, RouteMatchCallbackOptions, SerwistPlugin } from "serwist";
         | 
| 10 | 
            +
            import { Serwist } from "serwist";
         | 
| 11 | 
            +
            import { CacheableResponsePlugin } from "serwist/plugins";
         | 
| 12 | 
            +
            import { StaleWhileRevalidate } from "serwist/strategies";
         | 
| 13 13 | 
             
            import { warmStrategyCache } from "./warmStrategyCache.js";
         | 
| 14 14 |  | 
| 15 15 | 
             
            export interface StaticResourceOptions {
         | 
| 16 16 | 
             
              /**
         | 
| 17 | 
            -
               *  | 
| 18 | 
            -
               * will be used.
         | 
| 17 | 
            +
               * Your `Serwist` instance.
         | 
| 19 18 | 
             
               */
         | 
| 20 | 
            -
               | 
| 19 | 
            +
              serwist: Serwist;
         | 
| 21 20 | 
             
              /**
         | 
| 22 21 | 
             
               * Name for cache.
         | 
| 23 22 | 
             
               *
         | 
| @@ -46,13 +45,13 @@ export interface StaticResourceOptions { | |
| 46 45 | 
             
             * @param options
         | 
| 47 46 | 
             
             */
         | 
| 48 47 | 
             
            export const staticResourceCache = ({
         | 
| 49 | 
            -
               | 
| 48 | 
            +
              serwist,
         | 
| 50 49 | 
             
              cacheName = "static-resources",
         | 
| 51 50 | 
             
              matchCallback = ({ request }: RouteMatchCallbackOptions) =>
         | 
| 52 51 | 
             
                request.destination === "style" || request.destination === "script" || request.destination === "worker",
         | 
| 53 52 | 
             
              plugins = [],
         | 
| 54 53 | 
             
              warmCache,
         | 
| 55 | 
            -
            }: StaticResourceOptions | 
| 54 | 
            +
            }: StaticResourceOptions): void => {
         | 
| 56 55 | 
             
              plugins.push(
         | 
| 57 56 | 
             
                new CacheableResponsePlugin({
         | 
| 58 57 | 
             
                  statuses: [0, 200],
         | 
| @@ -64,7 +63,7 @@ export const staticResourceCache = ({ | |
| 64 63 | 
             
                plugins,
         | 
| 65 64 | 
             
              });
         | 
| 66 65 |  | 
| 67 | 
            -
               | 
| 66 | 
            +
              serwist.registerCapture(matchCallback, strategy);
         | 
| 68 67 |  | 
| 69 68 | 
             
              // Warms the cache
         | 
| 70 69 | 
             
              if (warmCache) {
         | 
    
        package/src/warmStrategyCache.ts
    CHANGED