@serwist/core 9.0.0-preview.4 → 9.0.0-preview.5
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/_private/SerwistError.d.ts +2 -1
- package/dist/_private/SerwistError.d.ts.map +1 -1
- package/dist/_private/logger.d.ts +7 -0
- package/dist/_private/logger.d.ts.map +1 -1
- package/dist/chunks/quotaErrorCallbacks.js +1 -1
- package/dist/models/messages/messageGenerator.d.ts +3 -1
- package/dist/models/messages/messageGenerator.d.ts.map +1 -1
- package/dist/models/messages/messages.d.ts +39 -4
- package/dist/models/messages/messages.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/_private/SerwistError.ts +2 -1
- package/src/_private/logger.ts +7 -0
- package/src/models/messages/messageGenerator.ts +3 -2
- package/src/models/messages/messages.ts +5 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { MessageKey } from "../models/messages/messages.js";
|
|
1
2
|
import type { MapLikeObject } from "../types.js";
|
|
2
3
|
/**
|
|
3
4
|
* Serwist errors should be thrown with this class.
|
|
@@ -18,7 +19,7 @@ declare class SerwistError extends Error {
|
|
|
18
19
|
* that will help developers identify issues should
|
|
19
20
|
* be added as a key on the context object.
|
|
20
21
|
*/
|
|
21
|
-
constructor(errorCode:
|
|
22
|
+
constructor(errorCode: MessageKey, details?: MapLikeObject);
|
|
22
23
|
}
|
|
23
24
|
export { SerwistError };
|
|
24
25
|
//# sourceMappingURL=SerwistError.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SerwistError.d.ts","sourceRoot":"","sources":["../../src/_private/SerwistError.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;GAQG;AACH,cAAM,YAAa,SAAQ,KAAK;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;;;;OAOG;gBACS,SAAS,EAAE,
|
|
1
|
+
{"version":3,"file":"SerwistError.d.ts","sourceRoot":"","sources":["../../src/_private/SerwistError.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;;;GAQG;AACH,cAAM,YAAa,SAAQ,KAAK;IAC9B,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;;;;OAOG;gBACS,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,aAAa;CAQ3D;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
|
|
@@ -6,6 +6,13 @@ declare global {
|
|
|
6
6
|
__WB_DISABLE_DEV_LOGS: boolean;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* The logger used by Serwist inside of both service workers and the window global scope.
|
|
11
|
+
*
|
|
12
|
+
* Note: This is forcibly `null` in production mode to reduce bundle size. Do check whether
|
|
13
|
+
* you are currently in development mode (by using `process.env.NODE_ENV !== "production"`)
|
|
14
|
+
* before using it.
|
|
15
|
+
*/
|
|
9
16
|
export declare const logger: {
|
|
10
17
|
error: (...args: any[]) => void;
|
|
11
18
|
debug: (...args: any[]) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/_private/logger.ts"],"names":[],"mappings":"AAQA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB,qBAAqB,EAAE,OAAO,CAAC;KAChC;IAED,UAAU,MAAM;QACd,qBAAqB,EAAE,OAAO,CAAC;KAChC;CACF;AAED,eAAO,MAAM,MAAM;qBAmEoC,GAAG,EAAE,KAAK,IAAI;qBAAd,GAAG,EAAE,KAAK,IAAI;mBAAd,GAAG,EAAE,KAAK,IAAI;oBAAd,GAAG,EAAE,KAAK,IAAI;8BAAd,GAAG,EAAE,KAAK,IAAI;wBAAd,GAAG,EAAE,KAAK,IAAI;CAE3D,CAAC"}
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/_private/logger.ts"],"names":[],"mappings":"AAQA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,iBAAiB;QACzB,qBAAqB,EAAE,OAAO,CAAC;KAChC;IAED,UAAU,MAAM;QACd,qBAAqB,EAAE,OAAO,CAAC;KAChC;CACF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,MAAM;qBAmEoC,GAAG,EAAE,KAAK,IAAI;qBAAd,GAAG,EAAE,KAAK,IAAI;mBAAd,GAAG,EAAE,KAAK,IAAI;oBAAd,GAAG,EAAE,KAAK,IAAI;8BAAd,GAAG,EAAE,KAAK,IAAI;wBAAd,GAAG,EAAE,KAAK,IAAI;CAE3D,CAAC"}
|
|
@@ -92,7 +92,7 @@ const messages = {
|
|
|
92
92
|
if (!thrownErrorMessage) {
|
|
93
93
|
throw new Error("Unexpected input to " + `'plugin-error-request-will-fetch', error.`);
|
|
94
94
|
}
|
|
95
|
-
return `An error was thrown by a
|
|
95
|
+
return `An error was thrown by a plugin's 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
|
|
96
96
|
},
|
|
97
97
|
"invalid-cache-name": ({ cacheNameId, value })=>{
|
|
98
98
|
if (!cacheNameId) {
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import type { MapLikeObject } from "../../types.js";
|
|
2
|
+
import { type MessageKey } from "./messages.js";
|
|
3
|
+
export declare const messageGenerator: ((code: string, ...args: any[]) => string) | ((code: MessageKey, details?: MapLikeObject) => string);
|
|
2
4
|
//# sourceMappingURL=messageGenerator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messageGenerator.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messageGenerator.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"messageGenerator.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messageGenerator.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,KAAK,UAAU,EAAY,MAAM,eAAe,CAAC;AAmB1D,eAAO,MAAM,gBAAgB,UAjBL,MAAM,WAAW,GAAG,EAAE,uBAQb,UAAU,YAAW,aAAa,YASiC,CAAC"}
|
|
@@ -1,9 +1,44 @@
|
|
|
1
1
|
interface LoggableObject {
|
|
2
2
|
[key: string]: string | number;
|
|
3
3
|
}
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
4
|
+
export declare const messages: {
|
|
5
|
+
"invalid-value": ({ paramName, validValueDescription, value }: LoggableObject) => string;
|
|
6
|
+
"not-an-array": ({ moduleName, className, funcName, paramName }: LoggableObject) => string;
|
|
7
|
+
"incorrect-type": ({ expectedType, paramName, moduleName, className, funcName }: LoggableObject) => string;
|
|
8
|
+
"incorrect-class": ({ expectedClassName, paramName, moduleName, className, funcName, isReturnValueProblem }: LoggableObject) => string;
|
|
9
|
+
"missing-a-method": ({ expectedMethod, paramName, moduleName, className, funcName }: LoggableObject) => string;
|
|
10
|
+
"add-to-cache-list-unexpected-type": ({ entry }: LoggableObject) => string;
|
|
11
|
+
"add-to-cache-list-conflicting-entries": ({ firstEntry, secondEntry }: LoggableObject) => string;
|
|
12
|
+
"plugin-error-request-will-fetch": ({ thrownErrorMessage }: LoggableObject) => string;
|
|
13
|
+
"invalid-cache-name": ({ cacheNameId, value }: LoggableObject) => string;
|
|
14
|
+
"unregister-route-but-not-found-with-method": ({ method }: LoggableObject) => string;
|
|
15
|
+
"unregister-route-route-not-registered": () => string;
|
|
16
|
+
"queue-replay-failed": ({ name }: LoggableObject) => string;
|
|
17
|
+
"duplicate-queue-name": ({ name }: LoggableObject) => string;
|
|
18
|
+
"expired-test-without-max-age": ({ methodName, paramName }: LoggableObject) => string;
|
|
19
|
+
"unsupported-route-type": ({ moduleName, className, funcName, paramName }: LoggableObject) => string;
|
|
20
|
+
"not-array-of-class": ({ value, expectedClass, moduleName, className, funcName, paramName }: LoggableObject) => string;
|
|
21
|
+
"max-entries-or-age-required": ({ moduleName, className, funcName }: LoggableObject) => string;
|
|
22
|
+
"statuses-or-headers-required": ({ moduleName, className, funcName }: LoggableObject) => string;
|
|
23
|
+
"invalid-string": ({ moduleName, funcName, paramName }: LoggableObject) => string;
|
|
24
|
+
"channel-name-required": () => string;
|
|
25
|
+
"invalid-responses-are-same-args": () => string;
|
|
26
|
+
"expire-custom-caches-only": () => string;
|
|
27
|
+
"unit-must-be-bytes": ({ normalizedRangeHeader }: LoggableObject) => string;
|
|
28
|
+
"single-range-only": ({ normalizedRangeHeader }: LoggableObject) => string;
|
|
29
|
+
"invalid-range-values": ({ normalizedRangeHeader }: LoggableObject) => string;
|
|
30
|
+
"no-range-header": () => string;
|
|
31
|
+
"range-not-satisfiable": ({ size, start, end }: LoggableObject) => string;
|
|
32
|
+
"attempt-to-cache-non-get-request": ({ url, method }: LoggableObject) => string;
|
|
33
|
+
"cache-put-with-no-response": ({ url }: LoggableObject) => string;
|
|
34
|
+
"no-response": ({ url, error }: LoggableObject) => string;
|
|
35
|
+
"bad-precaching-response": ({ url, status }: LoggableObject) => string;
|
|
36
|
+
"non-precached-url": ({ url }: LoggableObject) => string;
|
|
37
|
+
"add-to-cache-list-conflicting-integrities": ({ url }: LoggableObject) => string;
|
|
38
|
+
"missing-precache-entry": ({ cacheName, url }: LoggableObject) => string;
|
|
39
|
+
"cross-origin-copy-response": ({ origin }: LoggableObject) => string;
|
|
40
|
+
"opaque-streams-source": ({ type }: LoggableObject) => string;
|
|
41
|
+
};
|
|
42
|
+
export type MessageKey = keyof typeof messages;
|
|
8
43
|
export {};
|
|
9
44
|
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messages.ts"],"names":[],"mappings":"AAQA,UAAU,cAAc;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messages.ts"],"names":[],"mappings":"AAQA,UAAU,cAAc;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AAKD,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuNC,CAAC;AAEvB,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/core",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "This module is used by a number of the other Serwist modules to share common code.",
|
|
6
6
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"rollup": "4.9.6",
|
|
42
42
|
"typescript": "5.4.0-dev.20240206",
|
|
43
|
-
"@serwist/constants": "9.0.0-preview.
|
|
43
|
+
"@serwist/constants": "9.0.0-preview.5"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"typescript": ">=5.0.0"
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { messageGenerator } from "../models/messages/messageGenerator.js";
|
|
10
|
+
import type { MessageKey } from "../models/messages/messages.js";
|
|
10
11
|
import type { MapLikeObject } from "../types.js";
|
|
11
12
|
|
|
12
13
|
/**
|
|
@@ -29,7 +30,7 @@ class SerwistError extends Error {
|
|
|
29
30
|
* that will help developers identify issues should
|
|
30
31
|
* be added as a key on the context object.
|
|
31
32
|
*/
|
|
32
|
-
constructor(errorCode:
|
|
33
|
+
constructor(errorCode: MessageKey, details?: MapLikeObject) {
|
|
33
34
|
const message = messageGenerator(errorCode, details);
|
|
34
35
|
|
|
35
36
|
super(message);
|
package/src/_private/logger.ts
CHANGED
|
@@ -16,6 +16,13 @@ declare global {
|
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
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
|
+
*/
|
|
19
26
|
export const logger =
|
|
20
27
|
process.env.NODE_ENV === "production"
|
|
21
28
|
? null!
|
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import type { MapLikeObject } from "../../types.js";
|
|
10
|
+
import { type MessageKey, messages } from "./messages.js";
|
|
10
11
|
|
|
11
12
|
const fallback = (code: string, ...args: any[]) => {
|
|
12
13
|
let msg = code;
|
|
@@ -16,7 +17,7 @@ const fallback = (code: string, ...args: any[]) => {
|
|
|
16
17
|
return msg;
|
|
17
18
|
};
|
|
18
19
|
|
|
19
|
-
const generatorFunction = (code:
|
|
20
|
+
const generatorFunction = (code: MessageKey, details: MapLikeObject = {}) => {
|
|
20
21
|
const message = messages[code];
|
|
21
22
|
if (!message) {
|
|
22
23
|
throw new Error(`Unable to find message for code '${code}'.`);
|
|
@@ -13,7 +13,7 @@ interface MessageMap {
|
|
|
13
13
|
[messageID: string]: (param: LoggableObject) => string;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export const messages
|
|
16
|
+
export const messages = {
|
|
17
17
|
"invalid-value": ({ paramName, validValueDescription, value }) => {
|
|
18
18
|
if (!paramName || !validValueDescription) {
|
|
19
19
|
throw new Error(`Unexpected input to 'invalid-value' error.`);
|
|
@@ -82,7 +82,7 @@ export const messages: MessageMap = {
|
|
|
82
82
|
throw new Error("Unexpected input to " + `'plugin-error-request-will-fetch', error.`);
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
return `An error was thrown by a
|
|
85
|
+
return `An error was thrown by a plugin's 'requestWillFetch()' method. The thrown error message was: '${thrownErrorMessage}'.`;
|
|
86
86
|
},
|
|
87
87
|
|
|
88
88
|
"invalid-cache-name": ({ cacheNameId, value }) => {
|
|
@@ -228,4 +228,6 @@ export const messages: MessageMap = {
|
|
|
228
228
|
}
|
|
229
229
|
return `${message} Please ensure your sources are CORS-enabled.`;
|
|
230
230
|
},
|
|
231
|
-
};
|
|
231
|
+
} satisfies MessageMap;
|
|
232
|
+
|
|
233
|
+
export type MessageKey = keyof typeof messages;
|