@serwist/sw 9.0.0-preview.1 → 9.0.0-preview.2

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,2 +1,5 @@
1
+ /**
2
+ * Disables Serwist's logging in development mode.
3
+ */
1
4
  export declare const disableDevLogs: () => void;
2
5
  //# sourceMappingURL=disableDevLogs.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"disableDevLogs.d.ts","sourceRoot":"","sources":["../src/disableDevLogs.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc,YAE1B,CAAC"}
1
+ {"version":3,"file":"disableDevLogs.d.ts","sourceRoot":"","sources":["../src/disableDevLogs.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,cAAc,YAE1B,CAAC"}
@@ -25,9 +25,26 @@ export interface FallbackEntry {
25
25
  cacheMatchOptions?: MultiCacheQueryOptions;
26
26
  }
27
27
  export interface FallbacksOptions {
28
+ /**
29
+ * Your previous `RuntimeCaching` array.
30
+ */
28
31
  runtimeCaching: RuntimeCaching[];
32
+ /**
33
+ * A list of fallback entries.
34
+ */
29
35
  entries: FallbackEntry[];
36
+ /**
37
+ * Precache options that will be used for your
38
+ * fallback entries.
39
+ */
30
40
  precacheOptions?: PrecacheRouteOptions;
31
41
  }
42
+ /**
43
+ * Precaches routes so that they can be used as a fallback when
44
+ * a `RuntimeCaching` handler fails.
45
+ * @param options
46
+ * @returns The modified `RuntimeCaching` array. Using this value
47
+ * is not needed, as it is simply the provided array.
48
+ */
32
49
  export declare const fallbacks: ({ runtimeCaching, entries, precacheOptions }: FallbacksOptions) => RuntimeCaching[];
33
50
  //# sourceMappingURL=fallbacks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fallbacks.d.ts","sourceRoot":"","sources":["../src/fallbacks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAClE,OAAO,KAAK,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ACjC;;OAEG;IACH,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;CACxC;AAED;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,iDAAkD,gBAAgB,KAAG,cAAc,EA4BxG,CAAC"}
@@ -1,14 +1,41 @@
1
1
  import type { PrecacheEntry, PrecacheRouteOptions } from "@serwist/precaching";
2
2
  export type HandlePrecachingOptions = {
3
+ /**
4
+ * A list of fallback entries.
5
+ */
3
6
  precacheEntries?: (PrecacheEntry | string)[];
7
+ /**
8
+ * Precache options for the provided entries.
9
+ */
4
10
  precacheOptions?: PrecacheRouteOptions;
11
+ /**
12
+ * Whether outdated caches should be removed.
13
+ *
14
+ * @default false
15
+ */
5
16
  cleanupOutdatedCaches?: boolean;
6
17
  } & ({
18
+ /**
19
+ * An URL that should point to a HTML
20
+ * file with which navigation requests for URLs that aren't precached will be fulfilled.
21
+ * For more complex cases, consider `@serwist/sw.fallbacks`instead.
22
+ */
7
23
  navigateFallback: string;
24
+ /**
25
+ * URLs that should be allowed to use the `navigateFallback` handler.
26
+ */
8
27
  navigateFallbackAllowlist?: RegExp[];
28
+ /**
29
+ * URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
30
+ * over `navigateFallbackAllowlist`.
31
+ */
9
32
  navigateFallbackDenylist?: RegExp[];
10
33
  } | {
11
34
  navigateFallback?: never;
12
35
  });
13
- export declare const handlePrecaching: ({ precacheEntries, precacheOptions, cleanupOutdatedCaches: shouldCleanupOutdatedCaches, ...options }: HandlePrecachingOptions) => void;
36
+ /**
37
+ * Handles a list of precache entries and cleans up outdated caches.
38
+ * @param options
39
+ */
40
+ export declare const handlePrecaching: ({ precacheEntries, precacheOptions, cleanupOutdatedCaches, ...options }: HandlePrecachingOptions) => void;
14
41
  //# sourceMappingURL=handlePrecaching.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlePrecaching.d.ts","sourceRoot":"","sources":["../src/handlePrecaching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAI/E,MAAM,MAAM,uBAAuB,GAAG;IACpC,eAAe,CAAC,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IAC7C,eAAe,CAAC,EAAE,oBAAoB,CAAC;IAEvC,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,GAAG,CAAC;IAAE,gBAAgB,EAAE,MAAM,CAAC;IAAC,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC,CAAC;AAE7I,eAAO,MAAM,gBAAgB,yGAK1B,uBAAuB,SAoBzB,CAAC"}
1
+ {"version":3,"file":"handlePrecaching.d.ts","sourceRoot":"","sources":["../src/handlePrecaching.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAI/E,MAAM,MAAM,uBAAuB,GAAG;IACpC;;OAEG;IACH,eAAe,CAAC,EAAE,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,CAAC;IAC7C;;OAEG;IACH,eAAe,CAAC,EAAE,oBAAoB,CAAC;IACvC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;CACjC,GAAG,CACA;IACE;;;;OAIG;IACH,gBAAgB,EAAE,MAAM,CAAC;IACzB;;OAEG;IACH,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAC;IACrC;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;CACrC,GACD;IAAE,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,CAC/B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,gBAAgB,4EAAqF,uBAAuB,SAoBxI,CAAC"}
package/dist/index.js CHANGED
@@ -44,11 +44,11 @@ const fallbacks = ({ runtimeCaching, entries, precacheOptions })=>{
44
44
  return runtimeCaching;
45
45
  };
46
46
 
47
- const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches: shouldCleanupOutdatedCaches = false, ...options })=>{
47
+ const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches: cleanupOutdatedCaches$1 = false, ...options })=>{
48
48
  if (!!precacheEntries && precacheEntries.length > 0) {
49
49
  precacheAndRoute(precacheEntries, precacheOptions);
50
50
  }
51
- if (shouldCleanupOutdatedCaches) cleanupOutdatedCaches();
51
+ if (cleanupOutdatedCaches$1) cleanupOutdatedCaches();
52
52
  if (options.navigateFallback) {
53
53
  registerRoute(new NavigationRoute(createHandlerBoundToURL(options.navigateFallback), {
54
54
  allowlist: options.navigateFallbackAllowlist,
@@ -71,7 +71,7 @@ const registerRuntimeCaching = (...runtimeCachingList)=>{
71
71
  self.__WB_FORCE_RUNTIME_CACHING = false;
72
72
  }
73
73
  if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
74
- logger.info("registerRuntimeCaching is disabled in development mode.");
74
+ logger.log("registerRuntimeCaching is disabled in development mode.");
75
75
  return;
76
76
  }
77
77
  for (const rcEntry of runtimeCachingList){
@@ -135,7 +135,7 @@ const installSerwist = ({ precacheEntries, precacheOptions, cleanupOutdatedCache
135
135
  self.__WB_FORCE_RUNTIME_CACHING = false;
136
136
  }
137
137
  if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
138
- logger.info("runtimeCaching and fallbacks are disabled in development mode.");
138
+ logger.log("runtimeCaching and fallbacks are disabled in development mode.");
139
139
  } else {
140
140
  if (fallbacks$1 !== undefined) {
141
141
  runtimeCaching = fallbacks({
@@ -1,3 +1,9 @@
1
1
  import type { RuntimeCaching } from "./types.js";
2
+ /**
3
+ * Registers caching strategies to a singleton Router instance. It is a simple
4
+ * syntatic sugar for `@serwist/routing.registerRoute`.
5
+ * @param runtimeCachingList
6
+ * @returns
7
+ */
2
8
  export declare const registerRuntimeCaching: (...runtimeCachingList: RuntimeCaching[]) => void;
3
9
  //# sourceMappingURL=registerRuntimeCaching.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"registerRuntimeCaching.d.ts","sourceRoot":"","sources":["../src/registerRuntimeCaching.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,YAAY,CAAC;AAY/D,eAAO,MAAM,sBAAsB,0BAA2B,cAAc,EAAE,SAsD7E,CAAC"}
1
+ {"version":3,"file":"registerRuntimeCaching.d.ts","sourceRoot":"","sources":["../src/registerRuntimeCaching.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAgB,MAAM,YAAY,CAAC;AAY/D;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,0BAA2B,cAAc,EAAE,SAsD7E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/sw",
3
- "version": "9.0.0-preview.1",
3
+ "version": "9.0.0-preview.2",
4
4
  "type": "module",
5
5
  "description": "This module makes it easy to get started with the Serwist service worker libraries.",
6
6
  "files": [
@@ -28,23 +28,23 @@
28
28
  "./package.json": "./package.json"
29
29
  },
30
30
  "dependencies": {
31
- "@serwist/background-sync": "9.0.0-preview.1",
32
- "@serwist/broadcast-update": "9.0.0-preview.1",
33
- "@serwist/cacheable-response": "9.0.0-preview.1",
34
- "@serwist/core": "9.0.0-preview.1",
35
- "@serwist/expiration": "9.0.0-preview.1",
36
- "@serwist/google-analytics": "9.0.0-preview.1",
37
- "@serwist/navigation-preload": "9.0.0-preview.1",
38
- "@serwist/precaching": "9.0.0-preview.1",
39
- "@serwist/range-requests": "9.0.0-preview.1",
40
- "@serwist/routing": "9.0.0-preview.1",
41
- "@serwist/strategies": "9.0.0-preview.1"
31
+ "@serwist/background-sync": "9.0.0-preview.2",
32
+ "@serwist/broadcast-update": "9.0.0-preview.2",
33
+ "@serwist/cacheable-response": "9.0.0-preview.2",
34
+ "@serwist/core": "9.0.0-preview.2",
35
+ "@serwist/expiration": "9.0.0-preview.2",
36
+ "@serwist/google-analytics": "9.0.0-preview.2",
37
+ "@serwist/navigation-preload": "9.0.0-preview.2",
38
+ "@serwist/precaching": "9.0.0-preview.2",
39
+ "@serwist/range-requests": "9.0.0-preview.2",
40
+ "@serwist/routing": "9.0.0-preview.2",
41
+ "@serwist/strategies": "9.0.0-preview.2"
42
42
  },
43
43
  "devDependencies": {
44
44
  "rollup": "4.9.6",
45
- "typescript": "5.4.0-dev.20240203",
46
- "@serwist/constants": "9.0.0-preview.1",
47
- "@serwist/utils": "9.0.0-preview.1"
45
+ "typescript": "5.4.0-dev.20240206",
46
+ "@serwist/constants": "9.0.0-preview.2",
47
+ "@serwist/utils": "9.0.0-preview.2"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "typescript": ">=5.0.0"
@@ -2,6 +2,9 @@ declare const self: WorkerGlobalScope & {
2
2
  __WB_DISABLE_DEV_LOGS: boolean;
3
3
  };
4
4
 
5
+ /**
6
+ * Disables Serwist's logging in development mode.
7
+ */
5
8
  export const disableDevLogs = () => {
6
9
  self.__WB_DISABLE_DEV_LOGS = true;
7
10
  };
package/src/fallbacks.ts CHANGED
@@ -30,12 +30,29 @@ export interface FallbackEntry {
30
30
  }
31
31
 
32
32
  export interface FallbacksOptions {
33
+ /**
34
+ * Your previous `RuntimeCaching` array.
35
+ */
33
36
  runtimeCaching: RuntimeCaching[];
37
+ /**
38
+ * A list of fallback entries.
39
+ */
34
40
  entries: FallbackEntry[];
41
+ /**
42
+ * Precache options that will be used for your
43
+ * fallback entries.
44
+ */
35
45
  precacheOptions?: PrecacheRouteOptions;
36
46
  }
37
47
 
38
- export const fallbacks = ({ runtimeCaching, entries, precacheOptions }: FallbacksOptions) => {
48
+ /**
49
+ * Precaches routes so that they can be used as a fallback when
50
+ * a `RuntimeCaching` handler fails.
51
+ * @param options
52
+ * @returns The modified `RuntimeCaching` array. Using this value
53
+ * is not needed, as it is simply the provided array.
54
+ */
55
+ export const fallbacks = ({ runtimeCaching, entries, precacheOptions }: FallbacksOptions): RuntimeCaching[] => {
39
56
  precacheAndRoute(
40
57
  entries.map(({ url, revision }) => ({ url: typeof url === "string" ? url : url.toString(), revision })),
41
58
  precacheOptions,
@@ -1,20 +1,48 @@
1
1
  import type { PrecacheEntry, PrecacheRouteOptions } from "@serwist/precaching";
2
- import { cleanupOutdatedCaches, createHandlerBoundToURL, precacheAndRoute } from "@serwist/precaching";
2
+ import { cleanupOutdatedCaches as cleanupOutdatedCachesImpl, createHandlerBoundToURL, precacheAndRoute } from "@serwist/precaching";
3
3
  import { NavigationRoute, registerRoute } from "@serwist/routing";
4
4
 
5
5
  export type HandlePrecachingOptions = {
6
+ /**
7
+ * A list of fallback entries.
8
+ */
6
9
  precacheEntries?: (PrecacheEntry | string)[];
10
+ /**
11
+ * Precache options for the provided entries.
12
+ */
7
13
  precacheOptions?: PrecacheRouteOptions;
8
-
14
+ /**
15
+ * Whether outdated caches should be removed.
16
+ *
17
+ * @default false
18
+ */
9
19
  cleanupOutdatedCaches?: boolean;
10
- } & ({ navigateFallback: string; navigateFallbackAllowlist?: RegExp[]; navigateFallbackDenylist?: RegExp[] } | { navigateFallback?: never });
20
+ } & (
21
+ | {
22
+ /**
23
+ * An URL that should point to a HTML
24
+ * file with which navigation requests for URLs that aren't precached will be fulfilled.
25
+ * For more complex cases, consider `@serwist/sw.fallbacks`instead.
26
+ */
27
+ navigateFallback: string;
28
+ /**
29
+ * URLs that should be allowed to use the `navigateFallback` handler.
30
+ */
31
+ navigateFallbackAllowlist?: RegExp[];
32
+ /**
33
+ * URLs that should not be allowed to use the `navigateFallback` handler. This takes precedence
34
+ * over `navigateFallbackAllowlist`.
35
+ */
36
+ navigateFallbackDenylist?: RegExp[];
37
+ }
38
+ | { navigateFallback?: never }
39
+ );
11
40
 
12
- export const handlePrecaching = ({
13
- precacheEntries,
14
- precacheOptions,
15
- cleanupOutdatedCaches: shouldCleanupOutdatedCaches = false,
16
- ...options
17
- }: HandlePrecachingOptions) => {
41
+ /**
42
+ * Handles a list of precache entries and cleans up outdated caches.
43
+ * @param options
44
+ */
45
+ export const handlePrecaching = ({ precacheEntries, precacheOptions, cleanupOutdatedCaches = false, ...options }: HandlePrecachingOptions) => {
18
46
  if (!!precacheEntries && precacheEntries.length > 0) {
19
47
  /**
20
48
  * The precacheAndRoute() method efficiently caches and responds to
@@ -24,7 +52,7 @@ export const handlePrecaching = ({
24
52
  precacheAndRoute(precacheEntries, precacheOptions);
25
53
  }
26
54
 
27
- if (shouldCleanupOutdatedCaches) cleanupOutdatedCaches();
55
+ if (cleanupOutdatedCaches) cleanupOutdatedCachesImpl();
28
56
 
29
57
  if (options.navigateFallback) {
30
58
  registerRoute(
@@ -82,7 +82,7 @@ export const installSerwist = ({
82
82
  self.__WB_FORCE_RUNTIME_CACHING = false;
83
83
  }
84
84
  if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
85
- logger.info("runtimeCaching and fallbacks are disabled in development mode.");
85
+ logger.log("runtimeCaching and fallbacks are disabled in development mode.");
86
86
  } else {
87
87
  if (fallbacks !== undefined) {
88
88
  runtimeCaching = fallbacksImpl({
@@ -21,13 +21,19 @@ const HANDLER_NAME_TO_METHOD = {
21
21
  StaleWhileRevalidate,
22
22
  } satisfies Record<StrategyName, unknown>;
23
23
 
24
+ /**
25
+ * Registers caching strategies to a singleton Router instance. It is a simple
26
+ * syntatic sugar for `@serwist/routing.registerRoute`.
27
+ * @param runtimeCachingList
28
+ * @returns
29
+ */
24
30
  export const registerRuntimeCaching = (...runtimeCachingList: RuntimeCaching[]) => {
25
31
  if (!("__WB_FORCE_RUNTIME_CACHING" in globalThis)) {
26
32
  self.__WB_FORCE_RUNTIME_CACHING = false;
27
33
  }
28
34
 
29
35
  if (!self.__WB_FORCE_RUNTIME_CACHING && process.env.NODE_ENV !== "production") {
30
- logger.info("registerRuntimeCaching is disabled in development mode.");
36
+ logger.log("registerRuntimeCaching is disabled in development mode.");
31
37
  return;
32
38
  }
33
39