@serwist/precaching 8.0.0

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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/PrecacheController.d.ts +138 -0
  4. package/dist/PrecacheController.d.ts.map +1 -0
  5. package/dist/PrecacheFallbackPlugin.d.ts +44 -0
  6. package/dist/PrecacheFallbackPlugin.d.ts.map +1 -0
  7. package/dist/PrecacheRoute.d.ts +20 -0
  8. package/dist/PrecacheRoute.d.ts.map +1 -0
  9. package/dist/PrecacheStrategy.d.ts +67 -0
  10. package/dist/PrecacheStrategy.d.ts.map +1 -0
  11. package/dist/_types.d.ts +37 -0
  12. package/dist/_types.d.ts.map +1 -0
  13. package/dist/addPlugins.d.ts +9 -0
  14. package/dist/addPlugins.d.ts.map +1 -0
  15. package/dist/addRoute.d.ts +16 -0
  16. package/dist/addRoute.d.ts.map +1 -0
  17. package/dist/cleanupOutdatedCaches.d.ts +7 -0
  18. package/dist/cleanupOutdatedCaches.d.ts.map +1 -0
  19. package/dist/createHandlerBoundToURL.d.ts +18 -0
  20. package/dist/createHandlerBoundToURL.d.ts.map +1 -0
  21. package/dist/getCacheKeyForURL.d.ts +20 -0
  22. package/dist/getCacheKeyForURL.d.ts.map +1 -0
  23. package/dist/index.d.ts +25 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +917 -0
  26. package/dist/index.old.cjs +930 -0
  27. package/dist/matchPrecache.d.ts +15 -0
  28. package/dist/matchPrecache.d.ts.map +1 -0
  29. package/dist/precache.d.ts +20 -0
  30. package/dist/precache.d.ts.map +1 -0
  31. package/dist/precacheAndRoute.d.ts +15 -0
  32. package/dist/precacheAndRoute.d.ts.map +1 -0
  33. package/dist/utils/PrecacheCacheKeyPlugin.d.ts +17 -0
  34. package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
  35. package/dist/utils/PrecacheInstallReportPlugin.d.ts +15 -0
  36. package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
  37. package/dist/utils/createCacheKey.d.ts +16 -0
  38. package/dist/utils/createCacheKey.d.ts.map +1 -0
  39. package/dist/utils/deleteOutdatedCaches.d.ts +19 -0
  40. package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -0
  41. package/dist/utils/generateURLVariations.d.ts +12 -0
  42. package/dist/utils/generateURLVariations.d.ts.map +1 -0
  43. package/dist/utils/getCacheKeyForURL.d.ts +14 -0
  44. package/dist/utils/getCacheKeyForURL.d.ts.map +1 -0
  45. package/dist/utils/getOrCreatePrecacheController.d.ts +7 -0
  46. package/dist/utils/getOrCreatePrecacheController.d.ts.map +1 -0
  47. package/dist/utils/printCleanupDetails.d.ts +6 -0
  48. package/dist/utils/printCleanupDetails.d.ts.map +1 -0
  49. package/dist/utils/printInstallDetails.d.ts +7 -0
  50. package/dist/utils/printInstallDetails.d.ts.map +1 -0
  51. package/dist/utils/removeIgnoredSearchParams.d.ts +12 -0
  52. package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -0
  53. package/package.json +46 -0
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Helper function that calls `PrecacheController#matchPrecache`
3
+ * on the default `PrecacheController` instance.
4
+ *
5
+ * If you are creating your own `PrecacheController`, then call
6
+ * `PrecacheController#matchPrecache` on that instance,
7
+ * instead of using this function.
8
+ *
9
+ * @param request The key (without revisioning parameters)
10
+ * to look up in the precache.
11
+ * @returns
12
+ */
13
+ declare function matchPrecache(request: string | Request): Promise<Response | undefined>;
14
+ export { matchPrecache };
15
+ //# sourceMappingURL=matchPrecache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matchPrecache.d.ts","sourceRoot":"","sources":["../src/matchPrecache.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC,CAG/E;AAED,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { PrecacheEntry } from "./_types.js";
2
+ /**
3
+ * Adds items to the precache list, removing any duplicates and
4
+ * stores the files in the precache cache when the service
5
+ * worker installs.
6
+ *
7
+ * This method can be called multiple times.
8
+ *
9
+ * Please note: This method **will not** serve any of the cached files for you.
10
+ * It only precaches files. To respond to a network request you call
11
+ * `@serwist/precaching.addRoute`.
12
+ *
13
+ * If you have a single array of files to precache, you can just call
14
+ * `@serwist/precaching.precacheAndRoute`.
15
+ *
16
+ * @param entries Array of entries to precache.
17
+ */
18
+ declare function precache(entries: Array<PrecacheEntry | string>): void;
19
+ export { precache };
20
+ //# sourceMappingURL=precache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"precache.d.ts","sourceRoot":"","sources":["../src/precache.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD;;;;;;;;;;;;;;;GAeG;AACH,iBAAS,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,GAAG,IAAI,CAG9D;AAED,OAAO,EAAE,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { PrecacheEntry, PrecacheRouteOptions } from "./_types.js";
2
+ /**
3
+ * This method will add entries to the precache list and add a route to
4
+ * respond to fetch events.
5
+ *
6
+ * This is a convenience method that will call
7
+ * `@serwist/precaching.precache` and
8
+ * `@serwist/precaching.addRoute` in a single call.
9
+ *
10
+ * @param entries Array of entries to precache.
11
+ * @param options See the `@serwist/precaching.PrecacheRoute` options.
12
+ */
13
+ declare function precacheAndRoute(entries: Array<PrecacheEntry | string>, options?: PrecacheRouteOptions): void;
14
+ export { precacheAndRoute };
15
+ //# sourceMappingURL=precacheAndRoute.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"precacheAndRoute.d.ts","sourceRoot":"","sources":["../src/precacheAndRoute.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAIvE;;;;;;;;;;GAUG;AACH,iBAAS,gBAAgB,CAAC,OAAO,EAAE,KAAK,CAAC,aAAa,GAAG,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,IAAI,CAGtG;AAED,OAAO,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { SerwistPlugin } from "@serwist/core";
2
+ import type { PrecacheController } from "../PrecacheController.js";
3
+ /**
4
+ * A plugin, designed to be used with PrecacheController, to translate URLs into
5
+ * the corresponding cache key, based on the current revision info.
6
+ *
7
+ * @private
8
+ */
9
+ declare class PrecacheCacheKeyPlugin implements SerwistPlugin {
10
+ private readonly _precacheController;
11
+ constructor({ precacheController }: {
12
+ precacheController: PrecacheController;
13
+ });
14
+ cacheKeyWillBeUsed: SerwistPlugin["cacheKeyWillBeUsed"];
15
+ }
16
+ export { PrecacheCacheKeyPlugin };
17
+ //# sourceMappingURL=PrecacheCacheKeyPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrecacheCacheKeyPlugin.d.ts","sourceRoot":"","sources":["../../src/utils/PrecacheCacheKeyPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,eAAe,CAAC;AAE/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAEnE;;;;;GAKG;AACH,cAAM,sBAAuB,YAAW,aAAa;IACnD,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAqB;gBAE7C,EAAE,kBAAkB,EAAE,EAAE;QAAE,kBAAkB,EAAE,kBAAkB,CAAA;KAAE;IAI9E,kBAAkB,EAAE,aAAa,CAAC,oBAAoB,CAAC,CAOrD;CACH;AAED,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { SerwistPlugin } from "@serwist/core";
2
+ /**
3
+ * A plugin, designed to be used with PrecacheController, to determine the
4
+ * of assets that were updated (or not updated) during the install event.
5
+ *
6
+ * @private
7
+ */
8
+ declare class PrecacheInstallReportPlugin implements SerwistPlugin {
9
+ updatedURLs: string[];
10
+ notUpdatedURLs: string[];
11
+ handlerWillStart: SerwistPlugin["handlerWillStart"];
12
+ cachedResponseWillBeUsed: SerwistPlugin["cachedResponseWillBeUsed"];
13
+ }
14
+ export { PrecacheInstallReportPlugin };
15
+ //# sourceMappingURL=PrecacheInstallReportPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrecacheInstallReportPlugin.d.ts","sourceRoot":"","sources":["../../src/utils/PrecacheInstallReportPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAA8B,MAAM,eAAe,CAAC;AAE/E;;;;;GAKG;AACH,cAAM,2BAA4B,YAAW,aAAa;IACxD,WAAW,EAAE,MAAM,EAAE,CAAM;IAC3B,cAAc,EAAE,MAAM,EAAE,CAAM;IAE9B,gBAAgB,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAKjD;IAEF,wBAAwB,EAAE,aAAa,CAAC,0BAA0B,CAAC,CAkBjE;CACH;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
@@ -0,0 +1,16 @@
1
+ import type { PrecacheEntry } from "../_types.js";
2
+ interface CacheKey {
3
+ cacheKey: string;
4
+ url: string;
5
+ }
6
+ /**
7
+ * Converts a manifest entry into a versioned URL suitable for precaching.
8
+ *
9
+ * @param entry
10
+ * @returns A URL with versioning info.
11
+ *
12
+ * @private
13
+ */
14
+ export declare function createCacheKey(entry: PrecacheEntry | string): CacheKey;
15
+ export {};
16
+ //# sourceMappingURL=createCacheKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCacheKey.d.ts","sourceRoot":"","sources":["../../src/utils/createCacheKey.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,UAAU,QAAQ;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAKD;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,aAAa,GAAG,MAAM,GAAG,QAAQ,CAuCtE"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Cleans up incompatible precaches that were created by older versions of
3
+ * Serwist, by a service worker registered under the current scope.
4
+ *
5
+ * This is meant to be called as part of the `activate` event.
6
+ *
7
+ * This should be safe to use as long as you don't include `substringToFind`
8
+ * (defaulting to `-precache-`) in your non-precache cache names.
9
+ *
10
+ * @param currentPrecacheName The cache name currently in use for
11
+ * precaching. This cache won't be deleted.
12
+ * @param substringToFind Cache names which include this
13
+ * substring will be deleted (excluding `currentPrecacheName`).
14
+ * @returns A list of all the cache names that were deleted.
15
+ * @private
16
+ */
17
+ declare const deleteOutdatedCaches: (currentPrecacheName: string, substringToFind?: string) => Promise<string[]>;
18
+ export { deleteOutdatedCaches };
19
+ //# sourceMappingURL=deleteOutdatedCaches.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deleteOutdatedCaches.d.ts","sourceRoot":"","sources":["../../src/utils/deleteOutdatedCaches.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;;GAeG;AACH,QAAA,MAAM,oBAAoB,wBAA+B,MAAM,oBAAmB,MAAM,KAAuB,QAAQ,MAAM,EAAE,CAU9H,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { PrecacheRouteOptions } from "../_types.js";
2
+ /**
3
+ * Generator function that yields possible variations on the original URL to
4
+ * check, one at a time.
5
+ *
6
+ * @param url
7
+ * @param options
8
+ *
9
+ * @private
10
+ */
11
+ export declare function generateURLVariations(url: string, { ignoreURLParametersMatching, directoryIndex, cleanURLs, urlManipulation }?: PrecacheRouteOptions): Generator<string, void, unknown>;
12
+ //# sourceMappingURL=generateURLVariations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateURLVariations.d.ts","sourceRoot":"","sources":["../../src/utils/generateURLVariations.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAGzD;;;;;;;;GAQG;AACH,wBAAiB,qBAAqB,CACpC,GAAG,EAAE,MAAM,EACX,EAAE,2BAAmD,EAAE,cAA6B,EAAE,SAAgB,EAAE,eAAe,EAAE,GAAE,oBAAyB,GACnJ,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CA0BlC"}
@@ -0,0 +1,14 @@
1
+ import type { PrecacheRouteOptions } from "../_types.js";
2
+ /**
3
+ * This function will take the request URL and manipulate it based on the
4
+ * configuration options.
5
+ *
6
+ * @param url
7
+ * @param options
8
+ * @returns Returns the URL in the cache that matches the request,
9
+ * if possible.
10
+ *
11
+ * @private
12
+ */
13
+ export declare const getCacheKeyForURL: (url: string, options: PrecacheRouteOptions) => string | void;
14
+ //# sourceMappingURL=getCacheKeyForURL.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCacheKeyForURL.d.ts","sourceRoot":"","sources":["../../src/utils/getCacheKeyForURL.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAIzD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,iBAAiB,QAAS,MAAM,WAAW,oBAAoB,KAAG,MAAM,GAAG,IAUvF,CAAC"}
@@ -0,0 +1,7 @@
1
+ import { PrecacheController } from "../PrecacheController.js";
2
+ /**
3
+ * @returns
4
+ * @private
5
+ */
6
+ export declare const getOrCreatePrecacheController: () => PrecacheController;
7
+ //# sourceMappingURL=getOrCreatePrecacheController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getOrCreatePrecacheController.d.ts","sourceRoot":"","sources":["../../src/utils/getOrCreatePrecacheController.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI9D;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAO,kBAKhD,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @param deletedURLs
3
+ * @private
4
+ */
5
+ export declare function printCleanupDetails(deletedURLs: string[]): void;
6
+ //# sourceMappingURL=printCleanupDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printCleanupDetails.d.ts","sourceRoot":"","sources":["../../src/utils/printCleanupDetails.ts"],"names":[],"mappings":"AA0BA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,EAAE,GAAG,IAAI,CAO/D"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @param urlsToPrecache
3
+ * @param urlsAlreadyPrecached
4
+ * @private
5
+ */
6
+ export declare function printInstallDetails(urlsToPrecache: string[], urlsAlreadyPrecached: string[]): void;
7
+ //# sourceMappingURL=printInstallDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"printInstallDetails.d.ts","sourceRoot":"","sources":["../../src/utils/printInstallDetails.ts"],"names":[],"mappings":"AA8BA;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,cAAc,EAAE,MAAM,EAAE,EAAE,oBAAoB,EAAE,MAAM,EAAE,GAAG,IAAI,CAiBlG"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Removes any URL search parameters that should be ignored.
3
+ *
4
+ * @param urlObject The original URL.
5
+ * @param ignoreURLParametersMatching RegExps to test against
6
+ * each search parameter name. Matches mean that the search parameter should be
7
+ * ignored.
8
+ * @returns The URL with any ignored search parameters removed.
9
+ * @private
10
+ */
11
+ export declare function removeIgnoredSearchParams(urlObject: URL, ignoreURLParametersMatching?: RegExp[]): URL;
12
+ //# sourceMappingURL=removeIgnoredSearchParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removeIgnoredSearchParams.d.ts","sourceRoot":"","sources":["../../src/utils/removeIgnoredSearchParams.ts"],"names":[],"mappings":"AAQA;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,GAAG,EAAE,2BAA2B,GAAE,MAAM,EAAO,GAAG,GAAG,CAUzG"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@serwist/precaching",
3
+ "version": "8.0.0",
4
+ "type": "module",
5
+ "description": "This module efficiently precaches assets.",
6
+ "files": [
7
+ "dist",
8
+ "!dist/**/dts"
9
+ ],
10
+ "keywords": [
11
+ "serwist",
12
+ "serwistjs",
13
+ "service worker",
14
+ "sw"
15
+ ],
16
+ "author": "Google's Web DevRel Team, Serwist's Team",
17
+ "license": "MIT",
18
+ "repository": "serwist/serwist",
19
+ "bugs": "https://github.com/serwist/serwist/issues",
20
+ "homepage": "https://ducanh-next-pwa.vercel.app",
21
+ "module": "./dist/index.js",
22
+ "main": "./dist/index.old.cjs",
23
+ "types": "./dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": "./dist/index.js",
27
+ "require": "./dist/index.old.cjs",
28
+ "types": "./dist/index.d.ts"
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "dependencies": {
33
+ "@serwist/core": "8.0.0",
34
+ "@serwist/routing": "8.0.0",
35
+ "@serwist/strategies": "8.0.0"
36
+ },
37
+ "devDependencies": {
38
+ "rollup": "3.28.1",
39
+ "@serwist/constants": "8.0.0"
40
+ },
41
+ "scripts": {
42
+ "build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
43
+ "lint": "eslint src --ext ts,tsx,js,jsx,cjs,mjs",
44
+ "typecheck": "tsc"
45
+ }
46
+ }