@serwist/core 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.
Files changed (89) hide show
  1. package/README.md +1 -1
  2. package/dist/index.d.ts +2 -11
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.internal.d.ts +1 -15
  5. package/dist/index.internal.d.ts.map +1 -1
  6. package/dist/index.internal.js +1 -120
  7. package/dist/index.js +1 -92
  8. package/package.json +8 -5
  9. package/src/index.internal.ts +4 -21
  10. package/src/index.ts +42 -13
  11. package/dist/_private/Deferred.d.ts +0 -19
  12. package/dist/_private/Deferred.d.ts.map +0 -1
  13. package/dist/_private/SerwistError.d.ts +0 -24
  14. package/dist/_private/SerwistError.d.ts.map +0 -1
  15. package/dist/_private/assert.d.ts +0 -11
  16. package/dist/_private/assert.d.ts.map +0 -1
  17. package/dist/_private/cacheMatchIgnoreParams.d.ts +0 -15
  18. package/dist/_private/cacheMatchIgnoreParams.d.ts.map +0 -1
  19. package/dist/_private/cacheNames.d.ts +0 -40
  20. package/dist/_private/cacheNames.d.ts.map +0 -1
  21. package/dist/_private/canConstructReadableStream.d.ts +0 -12
  22. package/dist/_private/canConstructReadableStream.d.ts.map +0 -1
  23. package/dist/_private/canConstructResponseFromBodyStream.d.ts +0 -11
  24. package/dist/_private/canConstructResponseFromBodyStream.d.ts.map +0 -1
  25. package/dist/_private/dontWaitFor.d.ts +0 -7
  26. package/dist/_private/dontWaitFor.d.ts.map +0 -1
  27. package/dist/_private/executeQuotaErrorCallbacks.d.ts +0 -8
  28. package/dist/_private/executeQuotaErrorCallbacks.d.ts.map +0 -1
  29. package/dist/_private/getFriendlyURL.d.ts +0 -3
  30. package/dist/_private/getFriendlyURL.d.ts.map +0 -1
  31. package/dist/_private/logger.d.ts +0 -24
  32. package/dist/_private/logger.d.ts.map +0 -1
  33. package/dist/_private/resultingClientExists.d.ts +0 -12
  34. package/dist/_private/resultingClientExists.d.ts.map +0 -1
  35. package/dist/_private/timeout.d.ts +0 -10
  36. package/dist/_private/timeout.d.ts.map +0 -1
  37. package/dist/_private/waitUntil.d.ts +0 -11
  38. package/dist/_private/waitUntil.d.ts.map +0 -1
  39. package/dist/cacheNames.d.ts +0 -20
  40. package/dist/cacheNames.d.ts.map +0 -1
  41. package/dist/chunks/quotaErrorCallbacks.js +0 -355
  42. package/dist/clientsClaim.d.ts +0 -6
  43. package/dist/clientsClaim.d.ts.map +0 -1
  44. package/dist/copyResponse.d.ts +0 -20
  45. package/dist/copyResponse.d.ts.map +0 -1
  46. package/dist/models/messages/messageGenerator.d.ts +0 -4
  47. package/dist/models/messages/messageGenerator.d.ts.map +0 -1
  48. package/dist/models/messages/messages.d.ts +0 -44
  49. package/dist/models/messages/messages.d.ts.map +0 -1
  50. package/dist/models/pluginEvents.d.ts +0 -10
  51. package/dist/models/pluginEvents.d.ts.map +0 -1
  52. package/dist/models/quotaErrorCallbacks.d.ts +0 -3
  53. package/dist/models/quotaErrorCallbacks.d.ts.map +0 -1
  54. package/dist/registerQuotaErrorCallback.d.ts +0 -8
  55. package/dist/registerQuotaErrorCallback.d.ts.map +0 -1
  56. package/dist/setCacheNameDetails.d.ts +0 -9
  57. package/dist/setCacheNameDetails.d.ts.map +0 -1
  58. package/dist/types.d.ts +0 -257
  59. package/dist/types.d.ts.map +0 -1
  60. package/dist/utils/pluginUtils.d.ts +0 -5
  61. package/dist/utils/pluginUtils.d.ts.map +0 -1
  62. package/dist/utils/welcome.d.ts +0 -2
  63. package/dist/utils/welcome.d.ts.map +0 -1
  64. package/src/_private/Deferred.ts +0 -33
  65. package/src/_private/SerwistError.ts +0 -41
  66. package/src/_private/assert.ts +0 -89
  67. package/src/_private/cacheMatchIgnoreParams.ts +0 -54
  68. package/src/_private/cacheNames.ts +0 -87
  69. package/src/_private/canConstructReadableStream.ts +0 -34
  70. package/src/_private/canConstructResponseFromBodyStream.ts +0 -37
  71. package/src/_private/dontWaitFor.ts +0 -16
  72. package/src/_private/executeQuotaErrorCallbacks.ts +0 -33
  73. package/src/_private/getFriendlyURL.ts +0 -16
  74. package/src/_private/logger.ts +0 -95
  75. package/src/_private/resultingClientExists.ts +0 -58
  76. package/src/_private/timeout.ts +0 -19
  77. package/src/_private/waitUntil.ts +0 -21
  78. package/src/cacheNames.ts +0 -39
  79. package/src/clientsClaim.ts +0 -18
  80. package/src/copyResponse.ts +0 -60
  81. package/src/models/messages/messageGenerator.ts +0 -29
  82. package/src/models/messages/messages.ts +0 -233
  83. package/src/models/pluginEvents.ts +0 -17
  84. package/src/models/quotaErrorCallbacks.ts +0 -13
  85. package/src/registerQuotaErrorCallback.ts +0 -34
  86. package/src/setCacheNameDetails.ts +0 -53
  87. package/src/types.ts +0 -300
  88. package/src/utils/pluginUtils.ts +0 -15
  89. package/src/utils/welcome.ts +0 -24
@@ -1,33 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import { logger } from "../_private/logger.js";
10
- import { quotaErrorCallbacks } from "../models/quotaErrorCallbacks.js";
11
-
12
- /**
13
- * Runs all of the callback functions, one at a time sequentially, in the order
14
- * in which they were registered.
15
- *
16
- * @private
17
- */
18
- export const executeQuotaErrorCallbacks = async (): Promise<void> => {
19
- if (process.env.NODE_ENV !== "production") {
20
- logger.log(`About to run ${quotaErrorCallbacks.size} callbacks to clean up caches.`);
21
- }
22
-
23
- for (const callback of quotaErrorCallbacks) {
24
- await callback();
25
- if (process.env.NODE_ENV !== "production") {
26
- logger.log(callback, "is complete.");
27
- }
28
- }
29
-
30
- if (process.env.NODE_ENV !== "production") {
31
- logger.log("Finished running callbacks.");
32
- }
33
- };
@@ -1,16 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- const getFriendlyURL = (url: URL | string): string => {
10
- const urlObj = new URL(String(url), location.href);
11
- // See https://github.com/GoogleChrome/workbox/issues/2323
12
- // We want to include everything, except for the origin if it's same-origin.
13
- return urlObj.href.replace(new RegExp(`^${location.origin}`), "");
14
- };
15
-
16
- export { getFriendlyURL };
@@ -1,95 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Use of this source code is governed by an MIT-style
4
- license that can be found in the LICENSE file or at
5
- https://opensource.org/licenses/MIT.
6
- */
7
-
8
- // logger is used inside of both service workers and the window global scope.
9
- declare global {
10
- interface WorkerGlobalScope {
11
- __WB_DISABLE_DEV_LOGS: boolean;
12
- }
13
-
14
- interface Window {
15
- __WB_DISABLE_DEV_LOGS: boolean;
16
- }
17
- }
18
-
19
- /**
20
- * The logger used by Serwist inside of both service workers and the window global scope.
21
- *
22
- * Note: This is forcibly `null` in production mode to reduce bundle size. Do check whether
23
- * you are currently in development mode (by using `process.env.NODE_ENV !== "production"`)
24
- * before using it.
25
- */
26
- export const logger =
27
- process.env.NODE_ENV === "production"
28
- ? null!
29
- : (() => {
30
- // Don't overwrite this value if it's already set.
31
- // See https://github.com/GoogleChrome/workbox/pull/2284#issuecomment-560470923
32
- if (!("__WB_DISABLE_DEV_LOGS" in globalThis)) {
33
- self.__WB_DISABLE_DEV_LOGS = false;
34
- }
35
-
36
- let inGroup = false;
37
-
38
- const methodToColorMap = {
39
- debug: "#7f8c8d", // Gray
40
- log: "#2ecc71", // Green
41
- warn: "#f39c12", // Yellow
42
- error: "#c0392b", // Red
43
- groupCollapsed: "#3498db", // Blue
44
- groupEnd: null, // No colored prefix on groupEnd
45
- };
46
-
47
- type LoggerMethods = keyof typeof methodToColorMap;
48
-
49
- const print = (method: LoggerMethods, args: any[]) => {
50
- if (self.__WB_DISABLE_DEV_LOGS) {
51
- return;
52
- }
53
-
54
- if (method === "groupCollapsed") {
55
- // Safari doesn't print all console.groupCollapsed() arguments:
56
- // https://bugs.webkit.org/show_bug.cgi?id=182754
57
- if (typeof navigator !== "undefined" && /^((?!chrome|android).)*safari/i.test(navigator.userAgent)) {
58
- console[method](...args);
59
- return;
60
- }
61
- }
62
-
63
- const styles = [
64
- `background: ${methodToColorMap[method]!}`,
65
- "border-radius: 0.5em",
66
- "color: white",
67
- "font-weight: bold",
68
- "padding: 2px 0.5em",
69
- ];
70
-
71
- // When in a group, the serwist prefix is not displayed.
72
- const logPrefix = inGroup ? [] : ["%cserwist", styles.join(";")];
73
-
74
- console[method](...logPrefix, ...args);
75
-
76
- if (method === "groupCollapsed") {
77
- inGroup = true;
78
- }
79
- if (method === "groupEnd") {
80
- inGroup = false;
81
- }
82
- };
83
-
84
- const loggerMethods = Object.keys(methodToColorMap) as LoggerMethods[];
85
-
86
- return loggerMethods.reduce(
87
- (api, method) => {
88
- api[method] = (...args: any[]) => {
89
- print(method, args);
90
- };
91
- return api;
92
- },
93
- {} as { [method in LoggerMethods]: (...args: any[]) => void },
94
- );
95
- })();
@@ -1,58 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Use of this source code is governed by an MIT-style
4
- license that can be found in the LICENSE file or at
5
- https://opensource.org/licenses/MIT.
6
- */
7
-
8
- import { timeout } from "./timeout.js";
9
-
10
- // Give TypeScript the correct global.
11
- declare let self: ServiceWorkerGlobalScope;
12
-
13
- const MAX_RETRY_TIME = 2000;
14
-
15
- /**
16
- * Returns a promise that resolves to a window client matching the passed
17
- * `resultingClientId`. For browsers that don't support `resultingClientId`
18
- * or if waiting for the resulting client to apper takes too long, resolve to
19
- * `undefined`.
20
- *
21
- * @param resultingClientId
22
- * @returns
23
- * @private
24
- */
25
- export async function resultingClientExists(resultingClientId?: string): Promise<Client | undefined> {
26
- if (!resultingClientId) {
27
- return;
28
- }
29
-
30
- let existingWindows = await self.clients.matchAll({ type: "window" });
31
- const existingWindowIds = new Set(existingWindows.map((w) => w.id));
32
-
33
- let resultingWindow: Client | undefined = undefined;
34
- const startTime = performance.now();
35
-
36
- // Only wait up to `MAX_RETRY_TIME` to find a matching client.
37
- while (performance.now() - startTime < MAX_RETRY_TIME) {
38
- existingWindows = await self.clients.matchAll({ type: "window" });
39
-
40
- resultingWindow = existingWindows.find((w) => {
41
- if (resultingClientId) {
42
- // If we have a `resultingClientId`, we can match on that.
43
- return w.id === resultingClientId;
44
- }
45
- // Otherwise match on finding a window not in `existingWindowIds`.
46
- return !existingWindowIds.has(w.id);
47
- });
48
-
49
- if (resultingWindow) {
50
- break;
51
- }
52
-
53
- // Sleep for 100ms and retry.
54
- await timeout(100);
55
- }
56
-
57
- return resultingWindow;
58
- }
@@ -1,19 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
- Use of this source code is governed by an MIT-style
4
- license that can be found in the LICENSE file or at
5
- https://opensource.org/licenses/MIT.
6
- */
7
-
8
- /**
9
- * Returns a promise that resolves and the passed number of milliseconds.
10
- * This utility is an async/await-friendly version of `setTimeout`.
11
- *
12
- * @param ms
13
- * @returns
14
- * @private
15
- */
16
-
17
- export function timeout(ms: number): Promise<unknown> {
18
- return new Promise((resolve) => setTimeout(resolve, ms));
19
- }
@@ -1,21 +0,0 @@
1
- /*
2
- Copyright 2020 Google LLC
3
- Use of this source code is governed by an MIT-style
4
- license that can be found in the LICENSE file or at
5
- https://opensource.org/licenses/MIT.
6
- */
7
-
8
- /**
9
- * A utility method that makes it easier to use `event.waitUntil` with
10
- * async functions and return the result.
11
- *
12
- * @param event
13
- * @param asyncFn
14
- * @returns
15
- * @private
16
- */
17
- export const waitUntil = <T = any>(event: ExtendableEvent, asyncFn: () => Promise<T>): Promise<T> => {
18
- const returnPromise = asyncFn();
19
- event.waitUntil(returnPromise);
20
- return returnPromise;
21
- };
package/src/cacheNames.ts DELETED
@@ -1,39 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import { cacheNames as _cacheNames } from "./_private/cacheNames.js";
10
-
11
- /**
12
- * Get the current cache names and prefix/suffix used by Serwist.
13
- *
14
- * `cacheNames.precache` is used for precached assets,
15
- * `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
16
- * store `analytics.js`, and `cacheNames.runtime` is used for everything else.
17
- *
18
- * `cacheNames.prefix` can be used to retrieve just the current prefix value.
19
- * `cacheNames.suffix` can be used to retrieve just the current suffix value.
20
- *
21
- * @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
22
- */
23
- export const cacheNames = {
24
- get googleAnalytics(): string {
25
- return _cacheNames.getGoogleAnalyticsName();
26
- },
27
- get precache(): string {
28
- return _cacheNames.getPrecacheName();
29
- },
30
- get prefix(): string {
31
- return _cacheNames.getPrefix();
32
- },
33
- get runtime(): string {
34
- return _cacheNames.getRuntimeName();
35
- },
36
- get suffix(): string {
37
- return _cacheNames.getSuffix();
38
- },
39
- };
@@ -1,18 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- // Give TypeScript the correct global.
10
- declare let self: ServiceWorkerGlobalScope;
11
-
12
- /**
13
- * Claims any currently available clients once the service worker
14
- * becomes active. This is normally used in conjunction with `skipWaiting()`.
15
- */
16
- export const clientsClaim = (): void => {
17
- self.addEventListener("activate", () => self.clients.claim());
18
- };
@@ -1,60 +0,0 @@
1
- /*
2
- Copyright 2019 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import { SerwistError } from "./_private/SerwistError.js";
10
- import { canConstructResponseFromBodyStream } from "./_private/canConstructResponseFromBodyStream.js";
11
-
12
- /**
13
- * Allows developers to copy a response and modify its `headers`, `status`,
14
- * or `statusText` values (the values settable via a
15
- * [`ResponseInit`](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#Syntax)
16
- * object in the constructor).
17
- * To modify these values, pass a function as the second argument. That
18
- * function will be invoked with a single object with the response properties
19
- * `{headers, status, statusText}`. The return value of this function will
20
- * be used as the `ResponseInit` for the new `Response`. To change the values
21
- * either modify the passed parameter(s) and return it, or return a totally
22
- * new object.
23
- *
24
- * This method is intentionally limited to same-origin responses, regardless of
25
- * whether CORS was used or not.
26
- *
27
- * @param response
28
- * @param modifier
29
- */
30
- export const copyResponse = async (response: Response, modifier?: (responseInit: ResponseInit) => ResponseInit): Promise<Response> => {
31
- let origin = null;
32
- // If response.url isn't set, assume it's cross-origin and keep origin null.
33
- if (response.url) {
34
- const responseURL = new URL(response.url);
35
- origin = responseURL.origin;
36
- }
37
-
38
- if (origin !== self.location.origin) {
39
- throw new SerwistError("cross-origin-copy-response", { origin });
40
- }
41
-
42
- const clonedResponse = response.clone();
43
-
44
- // Create a fresh `ResponseInit` object by cloning the headers.
45
- const responseInit: ResponseInit = {
46
- headers: new Headers(clonedResponse.headers),
47
- status: clonedResponse.status,
48
- statusText: clonedResponse.statusText,
49
- };
50
-
51
- // Apply any user modifications.
52
- const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
53
-
54
- // Create the new response from the body stream and `ResponseInit`
55
- // modifications. Note: not all browsers support the Response.body stream,
56
- // so fall back to reading the entire body into memory as a blob.
57
- const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
58
-
59
- return new Response(body, modifiedResponseInit);
60
- };
@@ -1,29 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- import type { MapLikeObject } from "../../types.js";
10
- import { type MessageKey, messages } from "./messages.js";
11
-
12
- const fallback = (code: string, ...args: any[]) => {
13
- let msg = code;
14
- if (args.length > 0) {
15
- msg += ` :: ${JSON.stringify(args)}`;
16
- }
17
- return msg;
18
- };
19
-
20
- const generatorFunction = (code: MessageKey, details: MapLikeObject = {}) => {
21
- const message = messages[code];
22
- if (!message) {
23
- throw new Error(`Unable to find message for code '${code}'.`);
24
- }
25
-
26
- return message(details);
27
- };
28
-
29
- export const messageGenerator = process.env.NODE_ENV === "production" ? fallback : generatorFunction;
@@ -1,233 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- interface LoggableObject {
10
- [key: string]: string | number;
11
- }
12
- interface MessageMap {
13
- [messageID: string]: (param: LoggableObject) => string;
14
- }
15
-
16
- export const messages = {
17
- "invalid-value": ({ paramName, validValueDescription, value }) => {
18
- if (!paramName || !validValueDescription) {
19
- throw new Error(`Unexpected input to 'invalid-value' error.`);
20
- }
21
- return (
22
- `The '${paramName}' parameter was given a value with an ` +
23
- `unexpected value. ${validValueDescription} Received a value of ` +
24
- `${JSON.stringify(value)}.`
25
- );
26
- },
27
-
28
- "not-an-array": ({ moduleName, className, funcName, paramName }) => {
29
- if (!moduleName || !className || !funcName || !paramName) {
30
- throw new Error(`Unexpected input to 'not-an-array' error.`);
31
- }
32
- return `The parameter '${paramName}' passed into ` + `'${moduleName}.${className}.${funcName}()' must be an array.`;
33
- },
34
-
35
- "incorrect-type": ({ expectedType, paramName, moduleName, className, funcName }) => {
36
- if (!expectedType || !paramName || !moduleName || !funcName) {
37
- throw new Error(`Unexpected input to 'incorrect-type' error.`);
38
- }
39
- const classNameStr = className ? `${className}.` : "";
40
- return `The parameter '${paramName}' passed into ` + `'${moduleName}.${classNameStr}` + `${funcName}()' must be of type ${expectedType}.`;
41
- },
42
-
43
- "incorrect-class": ({ expectedClassName, paramName, moduleName, className, funcName, isReturnValueProblem }) => {
44
- if (!expectedClassName || !moduleName || !funcName) {
45
- throw new Error(`Unexpected input to 'incorrect-class' error.`);
46
- }
47
- const classNameStr = className ? `${className}.` : "";
48
- if (isReturnValueProblem) {
49
- return `The return value from '${moduleName}.${classNameStr}${funcName}()' must be an instance of class ${expectedClassName}.`;
50
- }
51
-
52
- return (
53
- `The parameter '${paramName}' passed into ` +
54
- `'${moduleName}.${classNameStr}${funcName}()' ` +
55
- `must be an instance of class ${expectedClassName}.`
56
- );
57
- },
58
-
59
- "missing-a-method": ({ expectedMethod, paramName, moduleName, className, funcName }) => {
60
- if (!expectedMethod || !paramName || !moduleName || !className || !funcName) {
61
- throw new Error(`Unexpected input to 'missing-a-method' error.`);
62
- }
63
- return `${moduleName}.${className}.${funcName}() expected the ` + `'${paramName}' parameter to expose a '${expectedMethod}' method.`;
64
- },
65
-
66
- "add-to-cache-list-unexpected-type": ({ entry }) => {
67
- return `An unexpected entry was passed to '@serwist/precaching.PrecacheController.addToCacheList()' The entry '${JSON.stringify(
68
- entry,
69
- )}' isn't supported. You must supply an array of strings with one or more characters, objects with a url property or Request objects.`;
70
- },
71
-
72
- "add-to-cache-list-conflicting-entries": ({ firstEntry, secondEntry }) => {
73
- if (!firstEntry || !secondEntry) {
74
- throw new Error("Unexpected input to " + `'add-to-cache-list-duplicate-entries' error.`);
75
- }
76
-
77
- return `Two of the entries passed to '@serwist/precaching.PrecacheController.addToCacheList()' had the URL ${firstEntry} but different revision details. Serwist is unable to cache and version the asset correctly. Please remove one of the entries.`;
78
- },
79
-
80
- "plugin-error-request-will-fetch": ({ thrownErrorMessage }) => {
81
- if (!thrownErrorMessage) {
82
- throw new Error("Unexpected input to " + `'plugin-error-request-will-fetch', error.`);
83
- }
84
-
85
- return `An error was thrown by a plugin's 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
86
- },
87
-
88
- "invalid-cache-name": ({ cacheNameId, value }) => {
89
- if (!cacheNameId) {
90
- throw new Error(`Expected a 'cacheNameId' for error 'invalid-cache-name'`);
91
- }
92
-
93
- return `You must provide a name containing at least one character for setCacheDetails({${cacheNameId}: '...'}). Received a value of '${JSON.stringify(
94
- value,
95
- )}'`;
96
- },
97
-
98
- "unregister-route-but-not-found-with-method": ({ method }) => {
99
- if (!method) {
100
- throw new Error("Unexpected input to " + `'unregister-route-but-not-found-with-method' error.`);
101
- }
102
-
103
- return `The route you're trying to unregister was not previously registered for the method type '${method}'.`;
104
- },
105
-
106
- "unregister-route-route-not-registered": () => {
107
- return `The route you're trying to unregister was not previously ` + "registered.";
108
- },
109
-
110
- "queue-replay-failed": ({ name }) => {
111
- return `Replaying the background sync queue '${name}' failed.`;
112
- },
113
-
114
- "duplicate-queue-name": ({ name }) => {
115
- return `The Queue name '${name}' is already being used. All instances of backgroundSync.Queue must be given unique names.`;
116
- },
117
-
118
- "expired-test-without-max-age": ({ methodName, paramName }) => {
119
- return `The '${methodName}()' method can only be used when the ` + `'${paramName}' is used in the constructor.`;
120
- },
121
-
122
- "unsupported-route-type": ({ moduleName, className, funcName, paramName }) => {
123
- return `The supplied '${paramName}' parameter was an unsupported type. Please check the docs for ${moduleName}.${className}.${funcName} for valid input types.`;
124
- },
125
-
126
- "not-array-of-class": ({ value, expectedClass, moduleName, className, funcName, paramName }) => {
127
- return `The supplied '${paramName}' parameter must be an array of '${expectedClass}' objects. Received '${JSON.stringify(
128
- value,
129
- )},'. Please check the call to ${moduleName}.${className}.${funcName}() to fix the issue.`;
130
- },
131
-
132
- "max-entries-or-age-required": ({ moduleName, className, funcName }) => {
133
- return `You must define either 'config.maxEntries' or 'config.maxAgeSeconds' in '${moduleName}.${className}.${funcName}'`;
134
- },
135
-
136
- "statuses-or-headers-required": ({ moduleName, className, funcName }) => {
137
- return `You must define either 'config.statuses' or 'config.headers' in '${moduleName}.${className}.${funcName}'`;
138
- },
139
-
140
- "invalid-string": ({ moduleName, funcName, paramName }) => {
141
- if (!paramName || !moduleName || !funcName) {
142
- throw new Error(`Unexpected input to 'invalid-string' error.`);
143
- }
144
- return `When using strings, the '${paramName}' parameter must start with 'http' (for cross-origin matches) or '/' (for same-origin matches). Please see the docs for ${moduleName}.${funcName}() for more info.`;
145
- },
146
-
147
- "channel-name-required": () => {
148
- return "You must provide a channelName to construct a " + "BroadcastCacheUpdate instance.";
149
- },
150
-
151
- "invalid-responses-are-same-args": () => {
152
- return "The arguments passed into responsesAreSame() appear to be " + "invalid. Please ensure valid Responses are used.";
153
- },
154
-
155
- "expire-custom-caches-only": () => {
156
- return `You must provide a 'cacheName' property when using the ` + "expiration plugin with a runtime caching strategy.";
157
- },
158
-
159
- "unit-must-be-bytes": ({ normalizedRangeHeader }) => {
160
- if (!normalizedRangeHeader) {
161
- throw new Error(`Unexpected input to 'unit-must-be-bytes' error.`);
162
- }
163
- return `The 'unit' portion of the Range header must be set to 'bytes'. The Range header provided was "${normalizedRangeHeader}"`;
164
- },
165
-
166
- "single-range-only": ({ normalizedRangeHeader }) => {
167
- if (!normalizedRangeHeader) {
168
- throw new Error(`Unexpected input to 'single-range-only' error.`);
169
- }
170
- return `Multiple ranges are not supported. Please use a single start value, and optional end value. The Range header provided was "${normalizedRangeHeader}"`;
171
- },
172
-
173
- "invalid-range-values": ({ normalizedRangeHeader }) => {
174
- if (!normalizedRangeHeader) {
175
- throw new Error(`Unexpected input to 'invalid-range-values' error.`);
176
- }
177
- return `The Range header is missing both start and end values. At least one of those values is needed. The Range header provided was "${normalizedRangeHeader}"`;
178
- },
179
-
180
- "no-range-header": () => {
181
- return "No Range header was found in the Request provided.";
182
- },
183
-
184
- "range-not-satisfiable": ({ size, start, end }) => {
185
- return `The start (${start}) and end (${end}) values in the Range are ` + `not satisfiable by the cached response, which is ${size} bytes.`;
186
- },
187
-
188
- "attempt-to-cache-non-get-request": ({ url, method }) => {
189
- return `Unable to cache '${url}' because it is a '${method}' request and only 'GET' requests can be cached.`;
190
- },
191
-
192
- "cache-put-with-no-response": ({ url }) => {
193
- return `There was an attempt to cache '${url}' but the response was not defined.`;
194
- },
195
-
196
- "no-response": ({ url, error }) => {
197
- let message = `The strategy could not generate a response for '${url}'.`;
198
- if (error) {
199
- message += ` The underlying error is ${error}.`;
200
- }
201
- return message;
202
- },
203
-
204
- "bad-precaching-response": ({ url, status }) => {
205
- return `The precaching request for '${url}' failed${status ? ` with an HTTP status of ${status}.` : "."}`;
206
- },
207
-
208
- "non-precached-url": ({ url }) => {
209
- return `'createHandlerBoundToURL("${url}")' was called, but that URL is not precached. Please pass in a URL that is precached instead.`;
210
- },
211
-
212
- "add-to-cache-list-conflicting-integrities": ({ url }) => {
213
- return `Two of the entries passed to '@serwist/precaching.PrecacheController.addToCacheList()' had the URL ${url} with different integrity values. Please remove one of them.`;
214
- },
215
-
216
- "missing-precache-entry": ({ cacheName, url }) => {
217
- return `Unable to find a precached response in ${cacheName} for ${url}.`;
218
- },
219
-
220
- "cross-origin-copy-response": ({ origin }) => {
221
- return `'@serwist/core.copyResponse()' can only be used with same-origin responses. It was passed a response with origin ${origin}.`;
222
- },
223
-
224
- "opaque-streams-source": ({ type }) => {
225
- const message = `One of the '@serwist/streams' sources resulted in an '${type}' response.`;
226
- if (type === "opaqueredirect") {
227
- return `${message} Please do not use a navigation request that results in a redirect as a source.`;
228
- }
229
- return `${message} Please ensure your sources are CORS-enabled.`;
230
- },
231
- } satisfies MessageMap;
232
-
233
- export type MessageKey = keyof typeof messages;
@@ -1,17 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- export enum pluginEvents {
10
- CACHE_DID_UPDATE = "cacheDidUpdate",
11
- CACHE_KEY_WILL_BE_USED = "cacheKeyWillBeUsed",
12
- CACHE_WILL_UPDATE = "cacheWillUpdate",
13
- CACHED_RESPONSE_WILL_BE_USED = "cachedResponseWillBeUsed",
14
- FETCH_DID_FAIL = "fetchDidFail",
15
- FETCH_DID_SUCCEED = "fetchDidSucceed",
16
- REQUEST_WILL_FETCH = "requestWillFetch",
17
- }
@@ -1,13 +0,0 @@
1
- /*
2
- Copyright 2018 Google LLC
3
-
4
- Use of this source code is governed by an MIT-style
5
- license that can be found in the LICENSE file or at
6
- https://opensource.org/licenses/MIT.
7
- */
8
-
9
- // Callbacks to be executed whenever there's a quota error.
10
- // biome-ignore lint/complexity/noBannedTypes: Can't change Function type right now.
11
- const quotaErrorCallbacks: Set<Function> = new Set();
12
-
13
- export { quotaErrorCallbacks };