@serwist/next 9.5.7 → 9.5.9
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/chunks/schema-BhRhcBIb.js +22 -0
- package/dist/chunks/schema-BhRhcBIb.js.map +1 -0
- package/dist/index.config.d.mts +50 -0
- package/dist/index.config.d.mts.map +1 -0
- package/dist/index.config.mjs +89 -0
- package/dist/index.config.mjs.map +1 -0
- package/dist/index.d.mts +111 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +242 -0
- package/dist/index.mjs.map +1 -0
- package/dist/index.react.d.mts +41 -0
- package/dist/index.react.d.mts.map +1 -0
- package/dist/index.react.mjs +138 -0
- package/dist/index.react.mjs.map +1 -0
- package/dist/index.schema.d.mts +94 -0
- package/dist/index.schema.d.mts.map +1 -0
- package/dist/index.schema.mjs +2 -0
- package/dist/index.worker.d.mts +18 -0
- package/dist/index.worker.d.mts.map +1 -0
- package/dist/index.worker.mjs +227 -0
- package/dist/index.worker.mjs.map +1 -0
- package/dist/sw-entry-worker.d.mts +11 -0
- package/dist/sw-entry-worker.d.mts.map +1 -0
- package/dist/sw-entry-worker.mjs +25 -0
- package/dist/sw-entry-worker.mjs.map +1 -0
- package/dist/sw-entry.d.mts +9 -0
- package/dist/sw-entry.d.mts.map +1 -0
- package/dist/sw-entry.mjs +37 -0
- package/dist/sw-entry.mjs.map +1 -0
- package/package.json +40 -38
- package/src/index.react.tsx +2 -2
- package/src/index.ts +2 -2
- package/src/lib/config/utils.ts +3 -2
- package/dist/chunks/schema.js +0 -24
- package/dist/index.config.d.ts +0 -36
- package/dist/index.config.d.ts.map +0 -1
- package/dist/index.config.js +0 -118
- package/dist/index.d.ts +0 -13
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -285
- package/dist/index.react.d.ts +0 -25
- package/dist/index.react.d.ts.map +0 -1
- package/dist/index.react.js +0 -88
- package/dist/index.schema.d.ts +0 -3
- package/dist/index.schema.d.ts.map +0 -1
- package/dist/index.schema.js +0 -4
- package/dist/index.worker.d.ts +0 -14
- package/dist/index.worker.d.ts.map +0 -1
- package/dist/index.worker.js +0 -261
- package/dist/internal-types.d.ts +0 -15
- package/dist/internal-types.d.ts.map +0 -1
- package/dist/lib/config/constants.d.ts +0 -2
- package/dist/lib/config/constants.d.ts.map +0 -1
- package/dist/lib/config/types.d.ts +0 -11
- package/dist/lib/config/types.d.ts.map +0 -1
- package/dist/lib/config/utils.d.ts +0 -3
- package/dist/lib/config/utils.d.ts.map +0 -1
- package/dist/lib/context.d.ts +0 -7
- package/dist/lib/context.d.ts.map +0 -1
- package/dist/lib/find-first-truthy.d.ts +0 -8
- package/dist/lib/find-first-truthy.d.ts.map +0 -1
- package/dist/lib/get-content-hash.d.ts +0 -3
- package/dist/lib/get-content-hash.d.ts.map +0 -1
- package/dist/lib/get-file-hash.d.ts +0 -3
- package/dist/lib/get-file-hash.d.ts.map +0 -1
- package/dist/lib/get-package-version.d.ts +0 -7
- package/dist/lib/get-package-version.d.ts.map +0 -1
- package/dist/lib/index.d.ts +0 -7
- package/dist/lib/index.d.ts.map +0 -1
- package/dist/lib/load-tsconfig.d.ts +0 -3
- package/dist/lib/load-tsconfig.d.ts.map +0 -1
- package/dist/lib/logger.d.ts +0 -7
- package/dist/lib/logger.d.ts.map +0 -1
- package/dist/lib/schema.d.ts +0 -90
- package/dist/lib/schema.d.ts.map +0 -1
- package/dist/lib/types.d.ts +0 -95
- package/dist/lib/types.d.ts.map +0 -1
- package/dist/lib/validator.d.ts +0 -3
- package/dist/lib/validator.d.ts.map +0 -1
- package/dist/sw-entry-worker.d.ts +0 -8
- package/dist/sw-entry-worker.d.ts.map +0 -1
- package/dist/sw-entry-worker.js +0 -33
- package/dist/sw-entry.d.ts +0 -7
- package/dist/sw-entry.d.ts.map +0 -1
- package/dist/sw-entry.js +0 -43
- package/dist/utils.d.ts +0 -4
- package/dist/utils.d.ts.map +0 -1
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Serwist } from "@serwist/window";
|
|
2
|
+
import { JSX, ReactNode } from "react";
|
|
3
|
+
|
|
4
|
+
//#region src/lib/context.d.ts
|
|
5
|
+
interface SerwistContextValues {
|
|
6
|
+
serwist: Serwist | null;
|
|
7
|
+
}
|
|
8
|
+
declare const useSerwist: () => SerwistContextValues;
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/index.react.d.ts
|
|
11
|
+
interface SerwistProviderProps {
|
|
12
|
+
swUrl: string;
|
|
13
|
+
disable?: boolean;
|
|
14
|
+
register?: boolean;
|
|
15
|
+
cacheOnNavigation?: boolean;
|
|
16
|
+
reloadOnOnline?: boolean;
|
|
17
|
+
options?: RegistrationOptions;
|
|
18
|
+
children?: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
declare global {
|
|
21
|
+
interface Window {
|
|
22
|
+
serwist: Serwist;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* `@serwist/window` provider for Next.js apps.
|
|
27
|
+
* @param options
|
|
28
|
+
* @returns
|
|
29
|
+
*/
|
|
30
|
+
declare function SerwistProvider({
|
|
31
|
+
swUrl,
|
|
32
|
+
disable,
|
|
33
|
+
register,
|
|
34
|
+
cacheOnNavigation,
|
|
35
|
+
reloadOnOnline,
|
|
36
|
+
options,
|
|
37
|
+
children
|
|
38
|
+
}: SerwistProviderProps): JSX.Element;
|
|
39
|
+
//#endregion
|
|
40
|
+
export { SerwistProvider, SerwistProviderProps, useSerwist };
|
|
41
|
+
//# sourceMappingURL=index.react.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.react.d.mts","names":[],"sources":["../src/lib/context.ts","../src/index.react.tsx"],"mappings":";;;;UAGiB,oBAAA;EACf,OAAA,EAAS,OAAA;AAAA;AAAA,cAKE,UAAA,QAAU,oBAAA;;;UCJN,oBAAA;EACf,KAAA;EACA,OAAA;EACA,QAAA;EACA,iBAAA;EACA,cAAA;EACA,OAAA,GAAU,mBAAA;EACV,QAAA,GAAW,SAAA;AAAA;AAAA,QAGL,MAAA;EAAA,UACI,MAAA;IACR,OAAA,EAAS,OAAA;EAAA;AAAA;AAZb;;;;;AAAA,iBAqBgB,eAAA,CAAA;EACd,KAAA;EACA,OAAA;EACA,QAAA;EACA,iBAAA;EACA,cAAA;EACA,OAAA;EACA;AAAA,GACC,oBAAA,GAAuB,GAAA,CAAI,OAAA"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { c } from "react/compiler-runtime";
|
|
2
|
+
import { Serwist } from "@serwist/window";
|
|
3
|
+
import { isCurrentPageOutOfScope } from "@serwist/window/internal";
|
|
4
|
+
import { createContext, useContext, useEffect, useState } from "react";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
//#region src/lib/context.ts
|
|
7
|
+
const SerwistContext = createContext(null);
|
|
8
|
+
const useSerwist = () => {
|
|
9
|
+
const context = useContext(SerwistContext);
|
|
10
|
+
if (!context) throw new Error("[useSerwist]: 'SerwistContext' is not available.");
|
|
11
|
+
return context;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region src/index.react.tsx
|
|
15
|
+
/**
|
|
16
|
+
* `@serwist/window` provider for Next.js apps.
|
|
17
|
+
* @param options
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
function SerwistProvider(t0) {
|
|
21
|
+
const $ = c(19);
|
|
22
|
+
const { swUrl, disable: t1, register: t2, cacheOnNavigation: t3, reloadOnOnline: t4, options, children } = t0;
|
|
23
|
+
const disable = t1 === void 0 ? false : t1;
|
|
24
|
+
const register = t2 === void 0 ? true : t2;
|
|
25
|
+
const cacheOnNavigation = t3 === void 0 ? true : t3;
|
|
26
|
+
const reloadOnOnline = t4 === void 0 ? true : t4;
|
|
27
|
+
let t5;
|
|
28
|
+
if ($[0] !== disable || $[1] !== options || $[2] !== register || $[3] !== swUrl) {
|
|
29
|
+
t5 = () => {
|
|
30
|
+
if (typeof window === "undefined") return null;
|
|
31
|
+
if (disable) return null;
|
|
32
|
+
const scope = options?.scope || "/";
|
|
33
|
+
if (!(window.serwist && window.serwist instanceof Serwist) && "serviceWorker" in navigator) {
|
|
34
|
+
window.serwist = new Serwist(swUrl, {
|
|
35
|
+
...options,
|
|
36
|
+
scope,
|
|
37
|
+
type: options?.type || "module"
|
|
38
|
+
});
|
|
39
|
+
if (register && !isCurrentPageOutOfScope(scope)) window.serwist.register();
|
|
40
|
+
}
|
|
41
|
+
return window.serwist ?? null;
|
|
42
|
+
};
|
|
43
|
+
$[0] = disable;
|
|
44
|
+
$[1] = options;
|
|
45
|
+
$[2] = register;
|
|
46
|
+
$[3] = swUrl;
|
|
47
|
+
$[4] = t5;
|
|
48
|
+
} else t5 = $[4];
|
|
49
|
+
const [serwist] = useState(t5);
|
|
50
|
+
let t6;
|
|
51
|
+
if ($[5] !== cacheOnNavigation || $[6] !== serwist) {
|
|
52
|
+
t6 = () => {
|
|
53
|
+
const cacheUrls = async (url) => {
|
|
54
|
+
if (!window.navigator.onLine || !url) return;
|
|
55
|
+
serwist?.messageSW({
|
|
56
|
+
type: "CACHE_URLS",
|
|
57
|
+
payload: { urlsToCache: [url] }
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const cacheCurrentPathname = () => cacheUrls(window.location.pathname);
|
|
61
|
+
const pushState = history.pushState;
|
|
62
|
+
const replaceState = history.replaceState;
|
|
63
|
+
if (cacheOnNavigation) {
|
|
64
|
+
history.pushState = (...t7) => {
|
|
65
|
+
const args = t7;
|
|
66
|
+
pushState.apply(history, args);
|
|
67
|
+
cacheUrls(args[2]);
|
|
68
|
+
};
|
|
69
|
+
history.replaceState = (...t8) => {
|
|
70
|
+
const args_0 = t8;
|
|
71
|
+
replaceState.apply(history, args_0);
|
|
72
|
+
cacheUrls(args_0[2]);
|
|
73
|
+
};
|
|
74
|
+
window.addEventListener("online", cacheCurrentPathname);
|
|
75
|
+
}
|
|
76
|
+
return () => {
|
|
77
|
+
history.pushState = pushState;
|
|
78
|
+
history.replaceState = replaceState;
|
|
79
|
+
window.removeEventListener("online", cacheCurrentPathname);
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
$[5] = cacheOnNavigation;
|
|
83
|
+
$[6] = serwist;
|
|
84
|
+
$[7] = t6;
|
|
85
|
+
} else t6 = $[7];
|
|
86
|
+
const t7 = serwist?.messageSW;
|
|
87
|
+
let t8;
|
|
88
|
+
if ($[8] !== cacheOnNavigation || $[9] !== t7) {
|
|
89
|
+
t8 = [t7, cacheOnNavigation];
|
|
90
|
+
$[8] = cacheOnNavigation;
|
|
91
|
+
$[9] = t7;
|
|
92
|
+
$[10] = t8;
|
|
93
|
+
} else t8 = $[10];
|
|
94
|
+
useEffect(t6, t8);
|
|
95
|
+
let t10;
|
|
96
|
+
let t9;
|
|
97
|
+
if ($[11] !== reloadOnOnline) {
|
|
98
|
+
t9 = () => {
|
|
99
|
+
const reload = _temp;
|
|
100
|
+
if (reloadOnOnline) window.addEventListener("online", reload);
|
|
101
|
+
return () => {
|
|
102
|
+
window.removeEventListener("online", reload);
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
t10 = [reloadOnOnline];
|
|
106
|
+
$[11] = reloadOnOnline;
|
|
107
|
+
$[12] = t10;
|
|
108
|
+
$[13] = t9;
|
|
109
|
+
} else {
|
|
110
|
+
t10 = $[12];
|
|
111
|
+
t9 = $[13];
|
|
112
|
+
}
|
|
113
|
+
useEffect(t9, t10);
|
|
114
|
+
let t11;
|
|
115
|
+
if ($[14] !== serwist) {
|
|
116
|
+
t11 = { serwist };
|
|
117
|
+
$[14] = serwist;
|
|
118
|
+
$[15] = t11;
|
|
119
|
+
} else t11 = $[15];
|
|
120
|
+
let t12;
|
|
121
|
+
if ($[16] !== children || $[17] !== t11) {
|
|
122
|
+
t12 = /* @__PURE__ */ jsx(SerwistContext.Provider, {
|
|
123
|
+
value: t11,
|
|
124
|
+
children
|
|
125
|
+
});
|
|
126
|
+
$[16] = children;
|
|
127
|
+
$[17] = t11;
|
|
128
|
+
$[18] = t12;
|
|
129
|
+
} else t12 = $[18];
|
|
130
|
+
return t12;
|
|
131
|
+
}
|
|
132
|
+
function _temp() {
|
|
133
|
+
return location.reload();
|
|
134
|
+
}
|
|
135
|
+
//#endregion
|
|
136
|
+
export { SerwistProvider, useSerwist };
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=index.react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.react.mjs","names":["Serwist","createContext","useContext","SerwistContextValues","serwist","SerwistContext","useSerwist","context","Error","Serwist","isCurrentPageOutOfScope","JSX","ReactNode","useEffect","useState","SerwistContext","useSerwist","SerwistProviderProps","swUrl","disable","register","cacheOnNavigation","reloadOnOnline","options","RegistrationOptions","children","global","Window","serwist","SerwistProvider","t0","$","_c","t1","t2","t3","t4","undefined","t5","window","scope","navigator","type","t6","cacheUrls","url","onLine","messageSW","payload","urlsToCache","cacheCurrentPathname","location","pathname","pushState","history","replaceState","t7","args","apply","t8","args_0","addEventListener","removeEventListener","t10","t9","reload","_temp","t11","t12"],"sources":["../src/lib/context.ts","../src/index.react.tsx"],"sourcesContent":["import type { Serwist } from \"@serwist/window\";\nimport { createContext, useContext } from \"react\";\n\nexport interface SerwistContextValues {\n serwist: Serwist | null;\n}\n\nexport const SerwistContext = createContext<SerwistContextValues>(null!);\n\nexport const useSerwist = () => {\n const context = useContext(SerwistContext);\n if (!context) {\n throw new Error(\"[useSerwist]: 'SerwistContext' is not available.\");\n }\n return context;\n};\n","import { Serwist } from \"@serwist/window\";\nimport { isCurrentPageOutOfScope } from \"@serwist/window/internal\";\nimport { type JSX, type ReactNode, useEffect, useState } from \"react\";\nimport { SerwistContext, useSerwist } from \"./lib/context.js\";\n\nexport interface SerwistProviderProps {\n swUrl: string;\n disable?: boolean;\n register?: boolean;\n cacheOnNavigation?: boolean;\n reloadOnOnline?: boolean;\n options?: RegistrationOptions;\n children?: ReactNode;\n}\n\ndeclare global {\n interface Window {\n serwist: Serwist;\n }\n}\n\n/**\n * `@serwist/window` provider for Next.js apps.\n * @param options\n * @returns\n */\nexport function SerwistProvider({\n swUrl,\n disable = false,\n register = true,\n cacheOnNavigation = true,\n reloadOnOnline = true,\n options,\n children,\n}: SerwistProviderProps): JSX.Element {\n const [serwist] = useState(() => {\n if (typeof window === \"undefined\") return null;\n if (disable) return null;\n const scope = options?.scope || \"/\";\n if (!(window.serwist && window.serwist instanceof Serwist) && \"serviceWorker\" in navigator) {\n window.serwist = new Serwist(swUrl, { ...options, scope, type: options?.type || \"module\" });\n if (register && !isCurrentPageOutOfScope(scope)) {\n void window.serwist.register();\n }\n }\n return window.serwist ?? null;\n });\n useEffect(() => {\n const cacheUrls = async (url?: string | URL | null | undefined) => {\n if (!window.navigator.onLine || !url) {\n return;\n }\n serwist?.messageSW({\n type: \"CACHE_URLS\",\n payload: { urlsToCache: [url] },\n });\n };\n const cacheCurrentPathname = () => cacheUrls(window.location.pathname);\n const pushState = history.pushState;\n const replaceState = history.replaceState;\n\n if (cacheOnNavigation) {\n history.pushState = (...args) => {\n pushState.apply(history, args);\n cacheUrls(args[2]);\n };\n history.replaceState = (...args) => {\n replaceState.apply(history, args);\n cacheUrls(args[2]);\n };\n window.addEventListener(\"online\", cacheCurrentPathname);\n }\n\n return () => {\n history.pushState = pushState;\n history.replaceState = replaceState;\n window.removeEventListener(\"online\", cacheCurrentPathname);\n };\n }, [serwist?.messageSW, cacheOnNavigation]);\n useEffect(() => {\n const reload = () => location.reload();\n if (reloadOnOnline) {\n window.addEventListener(\"online\", reload);\n }\n return () => {\n window.removeEventListener(\"online\", reload);\n };\n }, [reloadOnOnline]);\n return <SerwistContext.Provider value={{ serwist }}>{children}</SerwistContext.Provider>;\n}\n\nexport { useSerwist };\n"],"mappings":";;;;;;AAOA,MAAaK,iBAAiBJ,cAAoC,KAAM;AAExE,MAAaK,mBAAa;CACxB,MAAAC,UAAgBL,WAAWG,eAAe;AAC1C,K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AT;AAAAS,IAAA,MAAAgC;AAAAhC,IAAA,MAAAiC;QAAA;AAAAD,QAAAhC,EAAA;AAAAiC,OAAAjC,EAAA;;AARnBlB,WAAUmD,IAQPD,IAAiB;CAAA,IAAAI;AAAA,KAAApC,EAAA,QAAAH,SAAA;AACmBuC,QAAA,EAAAvC,SAAW;AAAAG,IAAA,MAAAH;AAAAG,IAAA,MAAAoC;OAAAA,OAAApC,EAAA;CAAA,IAAAqC;AAAA,KAAArC,EAAA,QAAAN,YAAAM,EAAA,QAAAoC,KAAA;AAA3CC,QAAA,oBAAA,eAAA,UAAA;GAAgC,OAAAD;GAAc1C;GAAmC,CAAA;AAAAM,IAAA,MAAAN;AAAAM,IAAA,MAAAoC;AAAApC,IAAA,MAAAqC;OAAAA,OAAArC,EAAA;AAAA,QAAjFqC;;AA9DF,SAAAF,QAAA;AAAA,QAsDkBf,SAAQc,QAAS"}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
//#region src/lib/schema.d.ts
|
|
4
|
+
declare const injectPartial: z.ZodObject<{
|
|
5
|
+
cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
|
|
6
|
+
disable: z.ZodDefault<z.ZodBoolean>;
|
|
7
|
+
register: z.ZodDefault<z.ZodBoolean>;
|
|
8
|
+
reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
10
|
+
swUrl: z.ZodDefault<z.ZodString>;
|
|
11
|
+
globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
12
|
+
}, z.core.$strict>;
|
|
13
|
+
declare const injectManifestOptions: z.ZodObject<{
|
|
14
|
+
additionalPrecacheEntries: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
|
|
15
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
16
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
17
|
+
url: z.ZodString;
|
|
18
|
+
}, z.core.$strict>]>>>;
|
|
19
|
+
dontCacheBustURLsMatching: z.ZodOptional<z.ZodCustom<RegExp, RegExp>>;
|
|
20
|
+
manifestTransforms: z.ZodOptional<z.ZodArray<z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
21
|
+
size: z.ZodNumber;
|
|
22
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
23
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
24
|
+
url: z.ZodString;
|
|
25
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
26
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
27
|
+
size: z.ZodNumber;
|
|
28
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
29
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
30
|
+
url: z.ZodString;
|
|
31
|
+
}, z.core.$strip>>;
|
|
32
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
33
|
+
}, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
34
|
+
size: z.ZodNumber;
|
|
35
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
36
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
37
|
+
url: z.ZodString;
|
|
38
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
39
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
40
|
+
size: z.ZodNumber;
|
|
41
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
42
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
43
|
+
url: z.ZodString;
|
|
44
|
+
}, z.core.$strip>>;
|
|
45
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
46
|
+
}, z.core.$strict>>>, z.ZodTransform<z.core.$InferOuterFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
47
|
+
size: z.ZodNumber;
|
|
48
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
49
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
50
|
+
url: z.ZodString;
|
|
51
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
52
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
53
|
+
size: z.ZodNumber;
|
|
54
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
55
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
56
|
+
url: z.ZodString;
|
|
57
|
+
}, z.core.$strip>>;
|
|
58
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
59
|
+
}, z.core.$strict>>, z.core.$InferInnerFunctionTypeAsync<z.ZodTuple<[z.ZodArray<z.ZodObject<{
|
|
60
|
+
size: z.ZodNumber;
|
|
61
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
62
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
63
|
+
url: z.ZodString;
|
|
64
|
+
}, z.core.$strip>>, z.ZodOptional<z.ZodUnknown>], null>, z.ZodObject<{
|
|
65
|
+
manifest: z.ZodArray<z.ZodObject<{
|
|
66
|
+
size: z.ZodNumber;
|
|
67
|
+
integrity: z.ZodOptional<z.ZodString>;
|
|
68
|
+
revision: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
69
|
+
url: z.ZodString;
|
|
70
|
+
}, z.core.$strip>>;
|
|
71
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
72
|
+
}, z.core.$strict>>>>>>;
|
|
73
|
+
maximumFileSizeToCacheInBytes: z.ZodDefault<z.ZodNumber>;
|
|
74
|
+
modifyURLPrefix: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
75
|
+
chunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
76
|
+
exclude: z.ZodDefault<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
|
|
77
|
+
excludeChunks: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
78
|
+
include: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodCustom<RegExp, RegExp>, z.ZodPipe<z.ZodCustom<z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>, z.ZodTransform<(args_0: any) => boolean, z.core.$InferInnerFunctionType<z.ZodTuple<[z.ZodAny], null>, z.ZodBoolean>>>]>>>;
|
|
79
|
+
injectionPoint: z.ZodDefault<z.ZodString>;
|
|
80
|
+
swSrc: z.ZodString;
|
|
81
|
+
swDest: z.ZodString;
|
|
82
|
+
compileSrc: z.ZodDefault<z.ZodBoolean>;
|
|
83
|
+
webpackCompilationPlugins: z.ZodOptional<z.ZodArray<z.ZodAny>>;
|
|
84
|
+
cacheOnNavigation: z.ZodDefault<z.ZodBoolean>;
|
|
85
|
+
disable: z.ZodDefault<z.ZodBoolean>;
|
|
86
|
+
register: z.ZodDefault<z.ZodBoolean>;
|
|
87
|
+
reloadOnOnline: z.ZodDefault<z.ZodBoolean>;
|
|
88
|
+
scope: z.ZodOptional<z.ZodString>;
|
|
89
|
+
swUrl: z.ZodDefault<z.ZodString>;
|
|
90
|
+
globPublicPatterns: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
91
|
+
}, z.core.$strict>;
|
|
92
|
+
//#endregion
|
|
93
|
+
export { injectManifestOptions, injectPartial };
|
|
94
|
+
//# sourceMappingURL=index.schema.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.schema.d.mts","names":[],"sources":["../src/lib/schema.ts"],"mappings":";;;cAIa,aAAA,EAAa,CAAA,CAAA,SAAA;;;;;;;;;cAUb,qBAAA,EAAqB,CAAA,CAAA,SAAA"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RuntimeCaching } from "serwist";
|
|
2
|
+
|
|
3
|
+
//#region src/index.worker.d.ts
|
|
4
|
+
declare const PAGES_CACHE_NAME: {
|
|
5
|
+
readonly rscPrefetch: "pages-rsc-prefetch";
|
|
6
|
+
readonly rsc: "pages-rsc";
|
|
7
|
+
readonly html: "pages";
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* The default, recommended list of caching strategies for applications
|
|
11
|
+
* built with Next.js.
|
|
12
|
+
*
|
|
13
|
+
* @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
|
|
14
|
+
*/
|
|
15
|
+
declare const defaultCache: RuntimeCaching[];
|
|
16
|
+
//#endregion
|
|
17
|
+
export { PAGES_CACHE_NAME, defaultCache };
|
|
18
|
+
//# sourceMappingURL=index.worker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.worker.d.mts","names":[],"sources":["../src/index.worker.ts"],"mappings":";;;cAGa,gBAAA;EAAA;;;;;;;;;;cAYA,YAAA,EAAc,cAAA"}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { CacheFirst, ExpirationPlugin, NetworkFirst, NetworkOnly, RangeRequestsPlugin, StaleWhileRevalidate } from "serwist";
|
|
2
|
+
//#region src/index.worker.ts
|
|
3
|
+
const PAGES_CACHE_NAME = {
|
|
4
|
+
rscPrefetch: "pages-rsc-prefetch",
|
|
5
|
+
rsc: "pages-rsc",
|
|
6
|
+
html: "pages"
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* The default, recommended list of caching strategies for applications
|
|
10
|
+
* built with Next.js.
|
|
11
|
+
*
|
|
12
|
+
* @see https://serwist.pages.dev/docs/next/worker-exports#default-cache
|
|
13
|
+
*/
|
|
14
|
+
const defaultCache = process.env.NODE_ENV !== "production" ? [{
|
|
15
|
+
matcher: /.*/i,
|
|
16
|
+
handler: new NetworkOnly()
|
|
17
|
+
}] : [
|
|
18
|
+
{
|
|
19
|
+
matcher: /^https:\/\/fonts\.(?:gstatic)\.com\/.*/i,
|
|
20
|
+
handler: new CacheFirst({
|
|
21
|
+
cacheName: "google-fonts-webfonts",
|
|
22
|
+
plugins: [new ExpirationPlugin({
|
|
23
|
+
maxEntries: 4,
|
|
24
|
+
maxAgeSeconds: 365 * 24 * 60 * 60,
|
|
25
|
+
maxAgeFrom: "last-used"
|
|
26
|
+
})]
|
|
27
|
+
})
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
matcher: /^https:\/\/fonts\.(?:googleapis)\.com\/.*/i,
|
|
31
|
+
handler: new StaleWhileRevalidate({
|
|
32
|
+
cacheName: "google-fonts-stylesheets",
|
|
33
|
+
plugins: [new ExpirationPlugin({
|
|
34
|
+
maxEntries: 4,
|
|
35
|
+
maxAgeSeconds: 10080 * 60,
|
|
36
|
+
maxAgeFrom: "last-used"
|
|
37
|
+
})]
|
|
38
|
+
})
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
matcher: /\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,
|
|
42
|
+
handler: new StaleWhileRevalidate({
|
|
43
|
+
cacheName: "static-font-assets",
|
|
44
|
+
plugins: [new ExpirationPlugin({
|
|
45
|
+
maxEntries: 4,
|
|
46
|
+
maxAgeSeconds: 10080 * 60,
|
|
47
|
+
maxAgeFrom: "last-used"
|
|
48
|
+
})]
|
|
49
|
+
})
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
matcher: /\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,
|
|
53
|
+
handler: new StaleWhileRevalidate({
|
|
54
|
+
cacheName: "static-image-assets",
|
|
55
|
+
plugins: [new ExpirationPlugin({
|
|
56
|
+
maxEntries: 64,
|
|
57
|
+
maxAgeSeconds: 720 * 60 * 60,
|
|
58
|
+
maxAgeFrom: "last-used"
|
|
59
|
+
})]
|
|
60
|
+
})
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
matcher: /\/_next\/static.+\.js$/i,
|
|
64
|
+
handler: new CacheFirst({
|
|
65
|
+
cacheName: "next-static-js-assets",
|
|
66
|
+
plugins: [new ExpirationPlugin({
|
|
67
|
+
maxEntries: 64,
|
|
68
|
+
maxAgeSeconds: 1440 * 60,
|
|
69
|
+
maxAgeFrom: "last-used"
|
|
70
|
+
})]
|
|
71
|
+
})
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
matcher: /\/_next\/image\?url=.+$/i,
|
|
75
|
+
handler: new StaleWhileRevalidate({
|
|
76
|
+
cacheName: "next-image",
|
|
77
|
+
plugins: [new ExpirationPlugin({
|
|
78
|
+
maxEntries: 64,
|
|
79
|
+
maxAgeSeconds: 1440 * 60,
|
|
80
|
+
maxAgeFrom: "last-used"
|
|
81
|
+
})]
|
|
82
|
+
})
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
matcher: /\.(?:mp3|wav|ogg)$/i,
|
|
86
|
+
handler: new CacheFirst({
|
|
87
|
+
cacheName: "static-audio-assets",
|
|
88
|
+
plugins: [new ExpirationPlugin({
|
|
89
|
+
maxEntries: 32,
|
|
90
|
+
maxAgeSeconds: 1440 * 60,
|
|
91
|
+
maxAgeFrom: "last-used"
|
|
92
|
+
}), new RangeRequestsPlugin()]
|
|
93
|
+
})
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
matcher: /\.(?:mp4|webm)$/i,
|
|
97
|
+
handler: new CacheFirst({
|
|
98
|
+
cacheName: "static-video-assets",
|
|
99
|
+
plugins: [new ExpirationPlugin({
|
|
100
|
+
maxEntries: 32,
|
|
101
|
+
maxAgeSeconds: 1440 * 60,
|
|
102
|
+
maxAgeFrom: "last-used"
|
|
103
|
+
}), new RangeRequestsPlugin()]
|
|
104
|
+
})
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
matcher: /\.(?:js)$/i,
|
|
108
|
+
handler: new StaleWhileRevalidate({
|
|
109
|
+
cacheName: "static-js-assets",
|
|
110
|
+
plugins: [new ExpirationPlugin({
|
|
111
|
+
maxEntries: 48,
|
|
112
|
+
maxAgeSeconds: 1440 * 60,
|
|
113
|
+
maxAgeFrom: "last-used"
|
|
114
|
+
})]
|
|
115
|
+
})
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
matcher: /\.(?:css|less)$/i,
|
|
119
|
+
handler: new StaleWhileRevalidate({
|
|
120
|
+
cacheName: "static-style-assets",
|
|
121
|
+
plugins: [new ExpirationPlugin({
|
|
122
|
+
maxEntries: 32,
|
|
123
|
+
maxAgeSeconds: 1440 * 60,
|
|
124
|
+
maxAgeFrom: "last-used"
|
|
125
|
+
})]
|
|
126
|
+
})
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
matcher: /\/_next\/data\/.+\/.+\.json$/i,
|
|
130
|
+
handler: new NetworkFirst({
|
|
131
|
+
cacheName: "next-data",
|
|
132
|
+
plugins: [new ExpirationPlugin({
|
|
133
|
+
maxEntries: 32,
|
|
134
|
+
maxAgeSeconds: 1440 * 60,
|
|
135
|
+
maxAgeFrom: "last-used"
|
|
136
|
+
})]
|
|
137
|
+
})
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
matcher: /\.(?:json|xml|csv)$/i,
|
|
141
|
+
handler: new NetworkFirst({
|
|
142
|
+
cacheName: "static-data-assets",
|
|
143
|
+
plugins: [new ExpirationPlugin({
|
|
144
|
+
maxEntries: 32,
|
|
145
|
+
maxAgeSeconds: 1440 * 60,
|
|
146
|
+
maxAgeFrom: "last-used"
|
|
147
|
+
})]
|
|
148
|
+
})
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
matcher: /\/api\/auth\/.*/,
|
|
152
|
+
handler: new NetworkOnly({ networkTimeoutSeconds: 10 })
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
matcher: ({ sameOrigin, url: { pathname } }) => sameOrigin && pathname.startsWith("/api/"),
|
|
156
|
+
method: "GET",
|
|
157
|
+
handler: new NetworkFirst({
|
|
158
|
+
cacheName: "apis",
|
|
159
|
+
plugins: [new ExpirationPlugin({
|
|
160
|
+
maxEntries: 16,
|
|
161
|
+
maxAgeSeconds: 1440 * 60,
|
|
162
|
+
maxAgeFrom: "last-used"
|
|
163
|
+
})],
|
|
164
|
+
networkTimeoutSeconds: 10
|
|
165
|
+
})
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && request.headers.get("Next-Router-Prefetch") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
169
|
+
handler: new NetworkFirst({
|
|
170
|
+
cacheName: PAGES_CACHE_NAME.rscPrefetch,
|
|
171
|
+
plugins: [new ExpirationPlugin({
|
|
172
|
+
maxEntries: 32,
|
|
173
|
+
maxAgeSeconds: 1440 * 60
|
|
174
|
+
})]
|
|
175
|
+
})
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("RSC") === "1" && sameOrigin && !pathname.startsWith("/api/"),
|
|
179
|
+
handler: new NetworkFirst({
|
|
180
|
+
cacheName: PAGES_CACHE_NAME.rsc,
|
|
181
|
+
plugins: [new ExpirationPlugin({
|
|
182
|
+
maxEntries: 32,
|
|
183
|
+
maxAgeSeconds: 1440 * 60
|
|
184
|
+
})]
|
|
185
|
+
})
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get("Content-Type")?.includes("text/html") && sameOrigin && !pathname.startsWith("/api/"),
|
|
189
|
+
handler: new NetworkFirst({
|
|
190
|
+
cacheName: PAGES_CACHE_NAME.html,
|
|
191
|
+
plugins: [new ExpirationPlugin({
|
|
192
|
+
maxEntries: 32,
|
|
193
|
+
maxAgeSeconds: 1440 * 60
|
|
194
|
+
})]
|
|
195
|
+
})
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith("/api/"),
|
|
199
|
+
handler: new NetworkFirst({
|
|
200
|
+
cacheName: "others",
|
|
201
|
+
plugins: [new ExpirationPlugin({
|
|
202
|
+
maxEntries: 32,
|
|
203
|
+
maxAgeSeconds: 1440 * 60
|
|
204
|
+
})]
|
|
205
|
+
})
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
matcher: ({ sameOrigin }) => !sameOrigin,
|
|
209
|
+
handler: new NetworkFirst({
|
|
210
|
+
cacheName: "cross-origin",
|
|
211
|
+
plugins: [new ExpirationPlugin({
|
|
212
|
+
maxEntries: 32,
|
|
213
|
+
maxAgeSeconds: 3600
|
|
214
|
+
})],
|
|
215
|
+
networkTimeoutSeconds: 10
|
|
216
|
+
})
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
matcher: /.*/i,
|
|
220
|
+
method: "GET",
|
|
221
|
+
handler: new NetworkOnly()
|
|
222
|
+
}
|
|
223
|
+
];
|
|
224
|
+
//#endregion
|
|
225
|
+
export { PAGES_CACHE_NAME, defaultCache };
|
|
226
|
+
|
|
227
|
+
//# sourceMappingURL=index.worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.worker.mjs","names":["RuntimeCaching","CacheFirst","ExpirationPlugin","NetworkFirst","NetworkOnly","RangeRequestsPlugin","StaleWhileRevalidate","PAGES_CACHE_NAME","rscPrefetch","rsc","html","const","defaultCache","process","env","NODE_ENV","matcher","handler","cacheName","plugins","maxEntries","maxAgeSeconds","maxAgeFrom","networkTimeoutSeconds","sameOrigin","url","pathname","startsWith","method","request","headers","get","includes"],"sources":["../src/index.worker.ts"],"sourcesContent":["import type { RuntimeCaching } from \"serwist\";\nimport { CacheFirst, ExpirationPlugin, NetworkFirst, NetworkOnly, RangeRequestsPlugin, StaleWhileRevalidate } from \"serwist\";\n\nexport const PAGES_CACHE_NAME = {\n rscPrefetch: \"pages-rsc-prefetch\",\n rsc: \"pages-rsc\",\n html: \"pages\",\n} as const;\n\n/**\n * The default, recommended list of caching strategies for applications\n * built with Next.js.\n *\n * @see https://serwist.pages.dev/docs/next/worker-exports#default-cache\n */\nexport const defaultCache: RuntimeCaching[] =\n process.env.NODE_ENV !== \"production\"\n ? [\n {\n matcher: /.*/i,\n handler: new NetworkOnly(),\n },\n ]\n : [\n {\n matcher: /^https:\\/\\/fonts\\.(?:gstatic)\\.com\\/.*/i,\n handler: new CacheFirst({\n cacheName: \"google-fonts-webfonts\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 365 * 24 * 60 * 60, // 365 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /^https:\\/\\/fonts\\.(?:googleapis)\\.com\\/.*/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"google-fonts-stylesheets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:eot|otf|ttc|ttf|woff|woff2|font.css)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-font-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 4,\n maxAgeSeconds: 7 * 24 * 60 * 60, // 7 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:jpg|jpeg|gif|png|svg|ico|webp)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-image-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 64,\n maxAgeSeconds: 30 * 24 * 60 * 60, // 30 days\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\/_next\\/static.+\\.js$/i,\n handler: new CacheFirst({\n cacheName: \"next-static-js-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 64,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\/_next\\/image\\?url=.+$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"next-image\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 64,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:mp3|wav|ogg)$/i,\n handler: new CacheFirst({\n cacheName: \"static-audio-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n new RangeRequestsPlugin(),\n ],\n }),\n },\n {\n matcher: /\\.(?:mp4|webm)$/i,\n handler: new CacheFirst({\n cacheName: \"static-video-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n new RangeRequestsPlugin(),\n ],\n }),\n },\n {\n matcher: /\\.(?:js)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-js-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 48,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:css|less)$/i,\n handler: new StaleWhileRevalidate({\n cacheName: \"static-style-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\/_next\\/data\\/.+\\/.+\\.json$/i,\n handler: new NetworkFirst({\n cacheName: \"next-data\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n matcher: /\\.(?:json|xml|csv)$/i,\n handler: new NetworkFirst({\n cacheName: \"static-data-assets\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n }),\n },\n {\n // Exclude /api/auth/* to fix auth callback\n // https://github.com/serwist/serwist/discussions/28\n matcher: /\\/api\\/auth\\/.*/,\n handler: new NetworkOnly({\n networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds\n }),\n },\n {\n matcher: ({ sameOrigin, url: { pathname } }) => sameOrigin && pathname.startsWith(\"/api/\"),\n method: \"GET\",\n handler: new NetworkFirst({\n cacheName: \"apis\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 16,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n maxAgeFrom: \"last-used\",\n }),\n ],\n networkTimeoutSeconds: 10, // fallback to cache if API does not response within 10 seconds\n }),\n },\n {\n matcher: ({ request, url: { pathname }, sameOrigin }) =>\n request.headers.get(\"RSC\") === \"1\" && request.headers.get(\"Next-Router-Prefetch\") === \"1\" && sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: PAGES_CACHE_NAME.rscPrefetch,\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ request, url: { pathname }, sameOrigin }) => request.headers.get(\"RSC\") === \"1\" && sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: PAGES_CACHE_NAME.rsc,\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ request, url: { pathname }, sameOrigin }) =>\n request.headers.get(\"Content-Type\")?.includes(\"text/html\") && sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: PAGES_CACHE_NAME.html,\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ url: { pathname }, sameOrigin }) => sameOrigin && !pathname.startsWith(\"/api/\"),\n handler: new NetworkFirst({\n cacheName: \"others\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 24 * 60 * 60, // 24 hours\n }),\n ],\n }),\n },\n {\n matcher: ({ sameOrigin }) => !sameOrigin,\n handler: new NetworkFirst({\n cacheName: \"cross-origin\",\n plugins: [\n new ExpirationPlugin({\n maxEntries: 32,\n maxAgeSeconds: 60 * 60, // 1 hour\n }),\n ],\n networkTimeoutSeconds: 10,\n }),\n },\n {\n matcher: /.*/i,\n method: \"GET\",\n handler: new NetworkOnly(),\n },\n ];\n"],"mappings":";;AAGA,MAAaO,mBAAmB;CAC9BC,aAAa;CACbC,KAAK;CACLC,MAAM;CACP;;;;;;;AAQD,MAAaE,eACXC,QAAQC,IAAIC,aAAa,eACrB,CACE;CACEC,SAAS;CACTC,SAAS,IAAIb,aAAY;CAC1B,CACF,GACD;CACE;EACEY,SAAS;EACTC,SAAS,IAAIhB,WAAW;GACtBiB,WAAW;GACXC,SAAS,CACP,IAAIjB,iBAAiB;IACnBkB,YAAY;IACZC,eAAe,MAAM,KAAK,KAAK;IAC/BC,YAAY;IACb,CAAC,CAAA;GAEL,CAAA;EACF;CACD;EACEN,SAAS;EACTC,SAAS,IAAIX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2
|
+
type MessageType = {
|
|
3
|
+
type: "__FRONTEND_NAV_CACHE__";
|
|
4
|
+
url: URL | string;
|
|
5
|
+
} | {
|
|
6
|
+
type: "__START_URL_CACHE__";
|
|
7
|
+
url: URL | string;
|
|
8
|
+
};
|
|
9
|
+
//#endregion
|
|
10
|
+
export { MessageType };
|
|
11
|
+
//# sourceMappingURL=sw-entry-worker.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-entry-worker.d.mts","names":[],"sources":["../src/sw-entry-worker.ts"],"mappings":";KAEY,WAAA;EAEN,IAAA;EACA,GAAA,EAAK,GAAA;AAAA;EAGL,IAAA;EACA,GAAA,EAAK,GAAA;AAAA"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/sw-entry-worker.ts
|
|
2
|
+
self.onmessage = async (ev) => {
|
|
3
|
+
switch (ev.data.type) {
|
|
4
|
+
case "__START_URL_CACHE__": {
|
|
5
|
+
const url = ev.data.url;
|
|
6
|
+
const response = await fetch(url);
|
|
7
|
+
if (!response.redirected) return (await caches.open("start-url")).put(url, response);
|
|
8
|
+
return Promise.resolve();
|
|
9
|
+
}
|
|
10
|
+
case "__FRONTEND_NAV_CACHE__": {
|
|
11
|
+
const url = ev.data.url;
|
|
12
|
+
const pagesCache = await caches.open("pages");
|
|
13
|
+
if (!!await pagesCache.match(url, { ignoreSearch: true })) return;
|
|
14
|
+
const page = await fetch(url);
|
|
15
|
+
if (!page.ok) return;
|
|
16
|
+
pagesCache.put(url, page.clone());
|
|
17
|
+
return Promise.resolve();
|
|
18
|
+
}
|
|
19
|
+
default: return Promise.resolve();
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export {};
|
|
24
|
+
|
|
25
|
+
//# sourceMappingURL=sw-entry-worker.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-entry-worker.mjs","names":["self","WorkerGlobalScope","globalThis","MessageType","type","url","URL","onmessage","ev","MessageEvent","data","response","fetch","redirected","startUrlCache","caches","open","put","Promise","resolve","pagesCache","isPageCached","match","ignoreSearch","page","ok","clone"],"sources":["../src/sw-entry-worker.ts"],"sourcesContent":["declare const self: WorkerGlobalScope & typeof globalThis;\n\nexport type MessageType =\n | {\n type: \"__FRONTEND_NAV_CACHE__\";\n url: URL | string;\n }\n | {\n type: \"__START_URL_CACHE__\";\n url: URL | string;\n };\n\nself.onmessage = async (ev: MessageEvent<MessageType>) => {\n switch (ev.data.type) {\n case \"__START_URL_CACHE__\": {\n const url = ev.data.url;\n const response = await fetch(url);\n if (!response.redirected) {\n const startUrlCache = await caches.open(\"start-url\");\n return startUrlCache.put(url, response);\n }\n return Promise.resolve();\n }\n case \"__FRONTEND_NAV_CACHE__\": {\n const url = ev.data.url;\n const pagesCache = await caches.open(\"pages\");\n\n const isPageCached = !!(await pagesCache.match(url, {\n ignoreSearch: true,\n }));\n if (isPageCached) {\n return;\n }\n\n const page = await fetch(url);\n if (!page.ok) {\n return;\n }\n pagesCache.put(url, page.clone());\n\n return Promise.resolve();\n }\n default:\n return Promise.resolve();\n }\n};\n"],"mappings":";AAYAA,KAAKO,YAAY,OAAOC,OAAkC;AACxD,SAAQA,GAAGE,KAAKN,MAAhB;EACE,KAAK,uBAAuB;GAC1B,MAAMC,MAAMG,GAAGE,KAAKL;GACpB,MAAMM,WAAW,MAAMC,MAAMP,IAAI;AACjC,OAAI,CAACM,SAASE,WAEZ,SAAOC,MADqBC,OAAOC,KAAK,YAAY,EAC/BC,IAAIZ,KAAKM,SAAS;AAEzC,UAAOO,QAAQC,SAAS;;EAE1B,KAAK,0BAA0B;GAC7B,MAAMd,MAAMG,GAAGE,KAAKL;GACpB,MAAMe,aAAa,MAAML,OAAOC,KAAK,QAAQ;AAK7C,OAAIK,CAHkB,CAAE,MAAMD,WAAWE,MAAMjB,KAAK,EAClDkB,cAAc,MACf,CAAC,CAEA;GAGF,MAAMC,OAAO,MAAMZ,MAAMP,IAAI;AAC7B,OAAI,CAACmB,KAAKC,GACR;AAEFL,cAAWH,IAAIZ,KAAKmB,KAAKE,OAAO,CAAC;AAEjC,UAAOR,QAAQC,SAAS;;EAE1B,QACE,QAAOD,QAAQC,SAAS"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sw-entry.d.mts","names":[],"sources":["../src/sw-entry.ts"],"mappings":";;;QAMQ,MAAA;EAAA,UACI,MAAA;IACR,OAAA,EAAS,OAAA;EAAA;AAAA"}
|