@serwist/core 9.0.0-preview.2 → 9.0.0-preview.21
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 +3 -3
- package/dist/_private/SerwistError.d.ts.map +1 -1
- package/dist/_private/dontWaitFor.d.ts +1 -1
- package/dist/_private/dontWaitFor.d.ts.map +1 -1
- package/dist/_private/executeQuotaErrorCallbacks.d.ts +1 -2
- package/dist/_private/executeQuotaErrorCallbacks.d.ts.map +1 -1
- package/dist/_private/logger.d.ts +7 -0
- package/dist/_private/logger.d.ts.map +1 -1
- package/dist/_private/waitUntil.d.ts +1 -2
- package/dist/_private/waitUntil.d.ts.map +1 -1
- package/dist/cacheNames.d.ts +2 -3
- package/dist/cacheNames.d.ts.map +1 -1
- package/dist/chunks/quotaErrorCallbacks.js +6 -6
- package/dist/clientsClaim.d.ts +2 -3
- package/dist/clientsClaim.d.ts.map +1 -1
- package/dist/copyResponse.d.ts +1 -2
- package/dist/copyResponse.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.internal.js +4 -4
- package/dist/index.js +8 -8
- 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/dist/registerQuotaErrorCallback.d.ts +1 -2
- package/dist/registerQuotaErrorCallback.d.ts.map +1 -1
- package/dist/setCacheNameDetails.d.ts +2 -3
- package/dist/setCacheNameDetails.d.ts.map +1 -1
- package/dist/types.d.ts +30 -46
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/_private/SerwistError.ts +3 -4
- package/src/_private/dontWaitFor.ts +1 -1
- package/src/_private/executeQuotaErrorCallbacks.ts +2 -4
- package/src/_private/logger.ts +7 -0
- package/src/_private/waitUntil.ts +2 -4
- package/src/cacheNames.ts +2 -4
- package/src/clientsClaim.ts +3 -5
- package/src/copyResponse.ts +2 -4
- package/src/index.ts +1 -1
- package/src/models/messages/messageGenerator.ts +3 -2
- package/src/models/messages/messages.ts +10 -8
- package/src/registerQuotaErrorCallback.ts +2 -4
- package/src/setCacheNameDetails.ts +3 -5
- package/src/types.ts +31 -46
- package/src/utils/welcome.ts +1 -2
|
@@ -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.
|
|
@@ -8,7 +9,7 @@ import type { MapLikeObject } from "../types.js";
|
|
|
8
9
|
*
|
|
9
10
|
* @private
|
|
10
11
|
*/
|
|
11
|
-
declare class SerwistError extends Error {
|
|
12
|
+
export declare class SerwistError extends Error {
|
|
12
13
|
details?: MapLikeObject;
|
|
13
14
|
/**
|
|
14
15
|
*
|
|
@@ -18,7 +19,6 @@ 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
|
-
export { SerwistError };
|
|
24
24
|
//# 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,
|
|
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,qBAAa,YAAa,SAAQ,KAAK;IACrC,OAAO,CAAC,EAAE,aAAa,CAAC;IAExB;;;;;;;OAOG;gBACS,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,aAAa;CAQ3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dontWaitFor.d.ts","sourceRoot":"","sources":["../../src/_private/dontWaitFor.ts"],"names":[],"mappings":"AAOA;;;;
|
|
1
|
+
{"version":3,"file":"dontWaitFor.d.ts","sourceRoot":"","sources":["../../src/_private/dontWaitFor.ts"],"names":[],"mappings":"AAOA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,IAAI,CAGvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"executeQuotaErrorCallbacks.d.ts","sourceRoot":"","sources":["../../src/_private/executeQuotaErrorCallbacks.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"executeQuotaErrorCallbacks.d.ts","sourceRoot":"","sources":["../../src/_private/executeQuotaErrorCallbacks.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,QAAa,QAAQ,IAAI,CAe/D,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"}
|
|
@@ -7,6 +7,5 @@
|
|
|
7
7
|
* @returns
|
|
8
8
|
* @private
|
|
9
9
|
*/
|
|
10
|
-
declare
|
|
11
|
-
export { waitUntil };
|
|
10
|
+
export declare const waitUntil: <T = any>(event: ExtendableEvent, asyncFn: () => Promise<T>) => Promise<T>;
|
|
12
11
|
//# sourceMappingURL=waitUntil.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitUntil.d.ts","sourceRoot":"","sources":["../../src/_private/waitUntil.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,
|
|
1
|
+
{"version":3,"file":"waitUntil.d.ts","sourceRoot":"","sources":["../../src/_private/waitUntil.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,mBAAoB,eAAe,WAAW,MAAM,QAAQ,CAAC,CAAC,KAAG,QAAQ,CAAC,CAI/F,CAAC"}
|
package/dist/cacheNames.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Get the current cache names and prefix/suffix used by
|
|
2
|
+
* Get the current cache names and prefix/suffix used by Serwist.
|
|
3
3
|
*
|
|
4
4
|
* `cacheNames.precache` is used for precached assets,
|
|
5
5
|
* `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
|
|
@@ -10,12 +10,11 @@
|
|
|
10
10
|
*
|
|
11
11
|
* @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
|
|
12
12
|
*/
|
|
13
|
-
declare const cacheNames: {
|
|
13
|
+
export declare const cacheNames: {
|
|
14
14
|
readonly googleAnalytics: string;
|
|
15
15
|
readonly precache: string;
|
|
16
16
|
readonly prefix: string;
|
|
17
17
|
readonly runtime: string;
|
|
18
18
|
readonly suffix: string;
|
|
19
19
|
};
|
|
20
|
-
export { cacheNames };
|
|
21
20
|
//# sourceMappingURL=cacheNames.d.ts.map
|
package/dist/cacheNames.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cacheNames.d.ts","sourceRoot":"","sources":["../src/cacheNames.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,
|
|
1
|
+
{"version":3,"file":"cacheNames.d.ts","sourceRoot":"","sources":["../src/cacheNames.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,UAAU;;;;;;CAgBtB,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) {
|
|
@@ -125,10 +125,10 @@ const messages = {
|
|
|
125
125
|
return `The supplied '${paramName}' parameter must be an array of '${expectedClass}' objects. Received '${JSON.stringify(value)},'. Please check the call to ${moduleName}.${className}.${funcName}() to fix the issue.`;
|
|
126
126
|
},
|
|
127
127
|
"max-entries-or-age-required": ({ moduleName, className, funcName })=>{
|
|
128
|
-
return `You must define either config.maxEntries or config.
|
|
128
|
+
return `You must define either 'config.maxEntries' or 'config.maxAgeSeconds' in '${moduleName}.${className}.${funcName}'`;
|
|
129
129
|
},
|
|
130
130
|
"statuses-or-headers-required": ({ moduleName, className, funcName })=>{
|
|
131
|
-
return `You must define either config.statuses or config.
|
|
131
|
+
return `You must define either 'config.statuses' or 'config.headers' in '${moduleName}.${className}.${funcName}'`;
|
|
132
132
|
},
|
|
133
133
|
"invalid-string": ({ moduleName, funcName, paramName })=>{
|
|
134
134
|
if (!paramName || !moduleName || !funcName) {
|
|
@@ -186,7 +186,7 @@ const messages = {
|
|
|
186
186
|
return `The precaching request for '${url}' failed${status ? ` with an HTTP status of ${status}.` : "."}`;
|
|
187
187
|
},
|
|
188
188
|
"non-precached-url": ({ url })=>{
|
|
189
|
-
return `createHandlerBoundToURL(
|
|
189
|
+
return `'createHandlerBoundToURL("${url}")' was called, but that URL is not precached. Please pass in a URL that is precached instead.`;
|
|
190
190
|
},
|
|
191
191
|
"add-to-cache-list-conflicting-integrities": ({ url })=>{
|
|
192
192
|
return `Two of the entries passed to '@serwist/precaching.PrecacheController.addToCacheList()' had the URL ${url} with different integrity values. Please remove one of them.`;
|
|
@@ -195,10 +195,10 @@ const messages = {
|
|
|
195
195
|
return `Unable to find a precached response in ${cacheName} for ${url}.`;
|
|
196
196
|
},
|
|
197
197
|
"cross-origin-copy-response": ({ origin })=>{
|
|
198
|
-
return
|
|
198
|
+
return `'@serwist/core.copyResponse()' can only be used with same-origin responses. It was passed a response with origin ${origin}.`;
|
|
199
199
|
},
|
|
200
200
|
"opaque-streams-source": ({ type })=>{
|
|
201
|
-
const message = `One of the @serwist/streams sources resulted in an '${type}' response.`;
|
|
201
|
+
const message = `One of the '@serwist/streams' sources resulted in an '${type}' response.`;
|
|
202
202
|
if (type === "opaqueredirect") {
|
|
203
203
|
return `${message} Please do not use a navigation request that results in a redirect as a source.`;
|
|
204
204
|
}
|
package/dist/clientsClaim.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Claims any currently available clients once the service worker
|
|
3
3
|
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
4
4
|
*/
|
|
5
|
-
declare
|
|
6
|
-
export { clientsClaim };
|
|
5
|
+
export declare const clientsClaim: () => void;
|
|
7
6
|
//# sourceMappingURL=clientsClaim.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientsClaim.d.ts","sourceRoot":"","sources":["../src/clientsClaim.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"clientsClaim.d.ts","sourceRoot":"","sources":["../src/clientsClaim.ts"],"names":[],"mappings":"AAWA;;;GAGG;AACH,eAAO,MAAM,YAAY,QAAO,IAE/B,CAAC"}
|
package/dist/copyResponse.d.ts
CHANGED
|
@@ -16,6 +16,5 @@
|
|
|
16
16
|
* @param response
|
|
17
17
|
* @param modifier
|
|
18
18
|
*/
|
|
19
|
-
declare
|
|
20
|
-
export { copyResponse };
|
|
19
|
+
export declare const copyResponse: (response: Response, modifier?: ((responseInit: ResponseInit) => ResponseInit) | undefined) => Promise<Response>;
|
|
21
20
|
//# sourceMappingURL=copyResponse.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyResponse.d.ts","sourceRoot":"","sources":["../src/copyResponse.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;GAiBG;AACH,
|
|
1
|
+
{"version":3,"file":"copyResponse.d.ts","sourceRoot":"","sources":["../src/copyResponse.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,aAAoB,QAAQ,6BAA4B,YAAY,KAAK,YAAY,kBAAG,QAAQ,QAAQ,CA8BhI,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ import { setCacheNameDetails } from "./setCacheNameDetails.js";
|
|
|
8
8
|
* setting default values that need to be shared (like cache names).
|
|
9
9
|
*/
|
|
10
10
|
export { cacheNames, clientsClaim, copyResponse, registerQuotaErrorCallback, setCacheNameDetails };
|
|
11
|
-
export * from "./types.js";
|
|
11
|
+
export type * from "./types.js";
|
|
12
12
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,CAAC;AAEnG,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,CAAC;AAEnG,mBAAmB,YAAY,CAAC"}
|
package/dist/index.internal.js
CHANGED
|
@@ -58,7 +58,7 @@ function dontWaitFor(promise) {
|
|
|
58
58
|
void promise.then(()=>{});
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
async
|
|
61
|
+
const executeQuotaErrorCallbacks = async ()=>{
|
|
62
62
|
if (process.env.NODE_ENV !== "production") {
|
|
63
63
|
logger.log(`About to run ${quotaErrorCallbacks.size} callbacks to clean up caches.`);
|
|
64
64
|
}
|
|
@@ -71,7 +71,7 @@ async function executeQuotaErrorCallbacks() {
|
|
|
71
71
|
if (process.env.NODE_ENV !== "production") {
|
|
72
72
|
logger.log("Finished running callbacks.");
|
|
73
73
|
}
|
|
74
|
-
}
|
|
74
|
+
};
|
|
75
75
|
|
|
76
76
|
const getFriendlyURL = (url)=>{
|
|
77
77
|
const urlObj = new URL(String(url), location.href);
|
|
@@ -111,10 +111,10 @@ async function resultingClientExists(resultingClientId) {
|
|
|
111
111
|
return resultingWindow;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
const waitUntil = (event, asyncFn)=>{
|
|
115
115
|
const returnPromise = asyncFn();
|
|
116
116
|
event.waitUntil(returnPromise);
|
|
117
117
|
return returnPromise;
|
|
118
|
-
}
|
|
118
|
+
};
|
|
119
119
|
|
|
120
120
|
export { Deferred, cacheMatchIgnoreParams, canConstructReadableStream, dontWaitFor, executeQuotaErrorCallbacks, getFriendlyURL, logger, resultingClientExists, timeout, waitUntil };
|
package/dist/index.js
CHANGED
|
@@ -18,11 +18,11 @@ const cacheNames = {
|
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
const clientsClaim = ()=>{
|
|
22
22
|
self.addEventListener("activate", ()=>self.clients.claim());
|
|
23
|
-
}
|
|
23
|
+
};
|
|
24
24
|
|
|
25
|
-
async
|
|
25
|
+
const copyResponse = async (response, modifier)=>{
|
|
26
26
|
let origin = null;
|
|
27
27
|
if (response.url) {
|
|
28
28
|
const responseURL = new URL(response.url);
|
|
@@ -42,9 +42,9 @@ async function copyResponse(response, modifier) {
|
|
|
42
42
|
const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
|
|
43
43
|
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
|
44
44
|
return new Response(body, modifiedResponseInit);
|
|
45
|
-
}
|
|
45
|
+
};
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const registerQuotaErrorCallback = (callback)=>{
|
|
48
48
|
if (process.env.NODE_ENV !== "production") {
|
|
49
49
|
finalAssertExports.isType(callback, "function", {
|
|
50
50
|
moduleName: "@serwist/core",
|
|
@@ -56,9 +56,9 @@ function registerQuotaErrorCallback(callback) {
|
|
|
56
56
|
if (process.env.NODE_ENV !== "production") {
|
|
57
57
|
logger.log("Registered a callback to respond to quota errors.", callback);
|
|
58
58
|
}
|
|
59
|
-
}
|
|
59
|
+
};
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
const setCacheNameDetails = (details)=>{
|
|
62
62
|
if (process.env.NODE_ENV !== "production") {
|
|
63
63
|
for (const key of Object.keys(details)){
|
|
64
64
|
finalAssertExports.isType(details[key], "string", {
|
|
@@ -87,6 +87,6 @@ function setCacheNameDetails(details) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
cacheNames$1.updateDetails(details);
|
|
90
|
-
}
|
|
90
|
+
};
|
|
91
91
|
|
|
92
92
|
export { cacheNames, clientsClaim, copyResponse, registerQuotaErrorCallback, setCacheNameDetails };
|
|
@@ -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"}
|
|
@@ -4,6 +4,5 @@
|
|
|
4
4
|
*
|
|
5
5
|
* @param callback
|
|
6
6
|
*/
|
|
7
|
-
declare
|
|
8
|
-
export { registerQuotaErrorCallback };
|
|
7
|
+
export declare const registerQuotaErrorCallback: (callback: Function) => void;
|
|
9
8
|
//# sourceMappingURL=registerQuotaErrorCallback.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registerQuotaErrorCallback.d.ts","sourceRoot":"","sources":["../src/registerQuotaErrorCallback.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AAEH,
|
|
1
|
+
{"version":3,"file":"registerQuotaErrorCallback.d.ts","sourceRoot":"","sources":["../src/registerQuotaErrorCallback.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AAEH,eAAO,MAAM,0BAA0B,aAAc,QAAQ,KAAG,IAc/D,CAAC"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { PartialCacheNameDetails } from "./_private/cacheNames.js";
|
|
2
2
|
/**
|
|
3
|
-
* Modifies the default cache names used by
|
|
3
|
+
* Modifies the default cache names used by Serwist packages.
|
|
4
4
|
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
|
5
5
|
*
|
|
6
6
|
* @param details
|
|
7
7
|
*/
|
|
8
|
-
declare
|
|
9
|
-
export { setCacheNameDetails };
|
|
8
|
+
export declare const setCacheNameDetails: (details: PartialCacheNameDetails) => void;
|
|
10
9
|
//# sourceMappingURL=setCacheNameDetails.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setCacheNameDetails.d.ts","sourceRoot":"","sources":["../src/setCacheNameDetails.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAGxE;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"setCacheNameDetails.d.ts","sourceRoot":"","sources":["../src/setCacheNameDetails.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAGxE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YAAa,uBAAuB,KAAG,IAiCtE,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export type PromiseOrNot<T> = T | Promise<T>;
|
|
1
2
|
export interface MapLikeObject {
|
|
2
3
|
[key: string]: any;
|
|
3
4
|
}
|
|
@@ -26,13 +27,11 @@ export interface RouteMatchCallbackOptions {
|
|
|
26
27
|
* is a non-empty array or object, that value will be set on the handler's
|
|
27
28
|
* `options.params` argument.
|
|
28
29
|
*/
|
|
29
|
-
export
|
|
30
|
-
(options: RouteMatchCallbackOptions): any;
|
|
31
|
-
}
|
|
30
|
+
export type RouteMatchCallback = (options: RouteMatchCallbackOptions) => any;
|
|
32
31
|
/**
|
|
33
32
|
* Options passed to a `RouteHandlerCallback` function.
|
|
34
33
|
*/
|
|
35
|
-
export
|
|
34
|
+
export interface RouteHandlerCallbackOptions {
|
|
36
35
|
/**
|
|
37
36
|
* The event associated with the request.
|
|
38
37
|
*/
|
|
@@ -59,6 +58,11 @@ export interface ManualHandlerCallbackOptions {
|
|
|
59
58
|
* A request to run this strategy for.
|
|
60
59
|
*/
|
|
61
60
|
request: Request | string;
|
|
61
|
+
url?: never;
|
|
62
|
+
/**
|
|
63
|
+
* The return value from `@serwist/routing`'s `matchCallback` (if applicable).
|
|
64
|
+
*/
|
|
65
|
+
params?: never;
|
|
62
66
|
}
|
|
63
67
|
export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
|
|
64
68
|
/**
|
|
@@ -69,9 +73,7 @@ export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandler
|
|
|
69
73
|
* If a non-empty array or object is returned by the `RouteMatchCallback` it
|
|
70
74
|
* will be passed in as this handler's `options.params` argument.
|
|
71
75
|
*/
|
|
72
|
-
export
|
|
73
|
-
(options: RouteHandlerCallbackOptions): Promise<Response>;
|
|
74
|
-
}
|
|
76
|
+
export type RouteHandlerCallback = (options: RouteHandlerCallbackOptions) => Promise<Response>;
|
|
75
77
|
/**
|
|
76
78
|
* The "handler" callback is invoked whenever a `Router` matches a URL/Request
|
|
77
79
|
* to a `Route` via its `RouteMatchCallback`. This handler callback should
|
|
@@ -80,9 +82,7 @@ export interface RouteHandlerCallback {
|
|
|
80
82
|
* If a non-empty array or object is returned by the `RouteMatchCallback` it
|
|
81
83
|
* will be passed in as this handler's `options.params` argument.
|
|
82
84
|
*/
|
|
83
|
-
export
|
|
84
|
-
(options: ManualHandlerCallbackOptions): Promise<Response>;
|
|
85
|
-
}
|
|
85
|
+
export type ManualHandlerCallback = (options: ManualHandlerCallbackOptions) => Promise<Response>;
|
|
86
86
|
/**
|
|
87
87
|
* An object with a `handle` method of type `RouteHandlerCallback`.
|
|
88
88
|
*
|
|
@@ -103,9 +103,7 @@ export interface HandlerWillStartCallbackParam {
|
|
|
103
103
|
event: ExtendableEvent;
|
|
104
104
|
state?: PluginState;
|
|
105
105
|
}
|
|
106
|
-
export
|
|
107
|
-
(param: HandlerWillStartCallbackParam): Promise<any>;
|
|
108
|
-
}
|
|
106
|
+
export type HandlerWillStartCallback = (param: HandlerWillStartCallbackParam) => Promise<any>;
|
|
109
107
|
export interface CacheDidUpdateCallbackParam {
|
|
110
108
|
/**
|
|
111
109
|
* Name of the cache the responses belong to. This is included in the
|
|
@@ -130,9 +128,7 @@ export interface CacheDidUpdateCallbackParam {
|
|
|
130
128
|
oldResponse?: Response | null;
|
|
131
129
|
state?: PluginState;
|
|
132
130
|
}
|
|
133
|
-
export
|
|
134
|
-
(param: CacheDidUpdateCallbackParam): Promise<any>;
|
|
135
|
-
}
|
|
131
|
+
export type CacheDidUpdateCallback = (param: CacheDidUpdateCallbackParam) => PromiseOrNot<any>;
|
|
136
132
|
export interface CacheKeyWillBeUsedCallbackParam {
|
|
137
133
|
mode: string;
|
|
138
134
|
request: Request;
|
|
@@ -140,18 +136,14 @@ export interface CacheKeyWillBeUsedCallbackParam {
|
|
|
140
136
|
params?: any;
|
|
141
137
|
state?: PluginState;
|
|
142
138
|
}
|
|
143
|
-
export
|
|
144
|
-
(param: CacheKeyWillBeUsedCallbackParam): Promise<Request | string>;
|
|
145
|
-
}
|
|
139
|
+
export type CacheKeyWillBeUsedCallback = (param: CacheKeyWillBeUsedCallbackParam) => PromiseOrNot<Request | string>;
|
|
146
140
|
export interface CacheWillUpdateCallbackParam {
|
|
147
141
|
request: Request;
|
|
148
142
|
response: Response;
|
|
149
143
|
event: ExtendableEvent;
|
|
150
144
|
state?: PluginState;
|
|
151
145
|
}
|
|
152
|
-
export
|
|
153
|
-
(param: CacheWillUpdateCallbackParam): Promise<any>;
|
|
154
|
-
}
|
|
146
|
+
export type CacheWillUpdateCallback = (param: CacheWillUpdateCallbackParam) => PromiseOrNot<any>;
|
|
155
147
|
export interface CachedResponseWillBeUsedCallbackParam {
|
|
156
148
|
/**
|
|
157
149
|
* Name of the cache the response is in.
|
|
@@ -171,9 +163,7 @@ export interface CachedResponseWillBeUsedCallbackParam {
|
|
|
171
163
|
matchOptions?: CacheQueryOptions;
|
|
172
164
|
state?: PluginState;
|
|
173
165
|
}
|
|
174
|
-
export
|
|
175
|
-
(param: CachedResponseWillBeUsedCallbackParam): Promise<any>;
|
|
176
|
-
}
|
|
166
|
+
export type CachedResponseWillBeUsedCallback = (param: CachedResponseWillBeUsedCallbackParam) => PromiseOrNot<any>;
|
|
177
167
|
export interface FetchDidFailCallbackParam {
|
|
178
168
|
error: Error;
|
|
179
169
|
originalRequest: Request;
|
|
@@ -181,53 +171,41 @@ export interface FetchDidFailCallbackParam {
|
|
|
181
171
|
event: ExtendableEvent;
|
|
182
172
|
state?: PluginState;
|
|
183
173
|
}
|
|
184
|
-
export
|
|
185
|
-
(param: FetchDidFailCallbackParam): Promise<any>;
|
|
186
|
-
}
|
|
174
|
+
export type FetchDidFailCallback = (param: FetchDidFailCallbackParam) => PromiseOrNot<any>;
|
|
187
175
|
export interface FetchDidSucceedCallbackParam {
|
|
188
176
|
request: Request;
|
|
189
177
|
response: Response;
|
|
190
178
|
event: ExtendableEvent;
|
|
191
179
|
state?: PluginState;
|
|
192
180
|
}
|
|
193
|
-
export
|
|
194
|
-
(param: FetchDidSucceedCallbackParam): Promise<Response>;
|
|
195
|
-
}
|
|
181
|
+
export type FetchDidSucceedCallback = (param: FetchDidSucceedCallbackParam) => PromiseOrNot<Response>;
|
|
196
182
|
export interface RequestWillFetchCallbackParam {
|
|
197
183
|
request: Request;
|
|
198
184
|
event: ExtendableEvent;
|
|
199
185
|
state?: PluginState;
|
|
200
186
|
}
|
|
201
|
-
export
|
|
202
|
-
(param: RequestWillFetchCallbackParam): Promise<Request>;
|
|
203
|
-
}
|
|
187
|
+
export type RequestWillFetchCallback = (param: RequestWillFetchCallbackParam) => PromiseOrNot<Request>;
|
|
204
188
|
export interface HandlerWillRespondCallbackParam {
|
|
205
189
|
request: Request;
|
|
206
190
|
response: Response;
|
|
207
191
|
event: ExtendableEvent;
|
|
208
192
|
state?: PluginState;
|
|
209
193
|
}
|
|
210
|
-
export
|
|
211
|
-
(param: HandlerWillRespondCallbackParam): Promise<Response>;
|
|
212
|
-
}
|
|
194
|
+
export type HandlerWillRespondCallback = (param: HandlerWillRespondCallbackParam) => PromiseOrNot<Response>;
|
|
213
195
|
export interface HandlerDidErrorCallbackParam {
|
|
214
196
|
request: Request;
|
|
215
197
|
event: ExtendableEvent;
|
|
216
198
|
error: Error;
|
|
217
199
|
state?: PluginState;
|
|
218
200
|
}
|
|
219
|
-
export
|
|
220
|
-
(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
|
|
221
|
-
}
|
|
201
|
+
export type HandlerDidErrorCallback = (param: HandlerDidErrorCallbackParam) => PromiseOrNot<Response | undefined>;
|
|
222
202
|
export interface HandlerDidRespondCallbackParam {
|
|
223
203
|
request: Request;
|
|
224
204
|
event: ExtendableEvent;
|
|
225
205
|
response?: Response;
|
|
226
206
|
state?: PluginState;
|
|
227
207
|
}
|
|
228
|
-
export
|
|
229
|
-
(param: HandlerDidRespondCallbackParam): Promise<any>;
|
|
230
|
-
}
|
|
208
|
+
export type HandlerDidRespondCallback = (param: HandlerDidRespondCallbackParam) => PromiseOrNot<any>;
|
|
231
209
|
export interface HandlerDidCompleteCallbackParam {
|
|
232
210
|
request: Request;
|
|
233
211
|
error?: Error;
|
|
@@ -235,9 +213,7 @@ export interface HandlerDidCompleteCallbackParam {
|
|
|
235
213
|
response?: Response;
|
|
236
214
|
state?: PluginState;
|
|
237
215
|
}
|
|
238
|
-
export
|
|
239
|
-
(param: HandlerDidCompleteCallbackParam): Promise<any>;
|
|
240
|
-
}
|
|
216
|
+
export type HandlerDidCompleteCallback = (param: HandlerDidCompleteCallbackParam) => PromiseOrNot<any>;
|
|
241
217
|
/**
|
|
242
218
|
* An object with optional lifecycle callback properties for the fetch and
|
|
243
219
|
* cache operations.
|
|
@@ -270,4 +246,12 @@ export interface SerwistPluginCallbackParam {
|
|
|
270
246
|
handlerWillStart: HandlerWillStartCallbackParam;
|
|
271
247
|
requestWillFetch: RequestWillFetchCallbackParam;
|
|
272
248
|
}
|
|
249
|
+
export interface SerwistGlobalConfig {
|
|
250
|
+
/**
|
|
251
|
+
* Whether Serwist should disable development logging.
|
|
252
|
+
*
|
|
253
|
+
* @default false
|
|
254
|
+
*/
|
|
255
|
+
__WB_DISABLE_DEV_LOGS: boolean;
|
|
256
|
+
}
|
|
273
257
|
//# sourceMappingURL=types.d.ts.map
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAOA,MAAM,MAAM,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAE7C,MAAM,WAAW,aAAa;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;GAGG;AACH,MAAM,MAAM,WAAW,GAAG,aAAa,CAAC;AAExC;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,KAAK,EAAE,eAAe,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,GAAG,CAAC;CACV;AA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AC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,2BAA2B,CAAC;IAC5C,wBAAwB,EAAE,qCAAqC,CAAC;IAChE,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,eAAe,EAAE,4BAA4B,CAAC;IAC9C,YAAY,EAAE,yBAAyB,CAAC;IACxC,eAAe,EAAE,4BAA4B,CAAC;IAC9C,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,eAAe,EAAE,4BAA4B,CAAC;IAC9C,iBAAiB,EAAE,8BAA8B,CAAC;IAClD,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,gBAAgB,EAAE,6BAA6B,CAAC;IAChD,gBAAgB,EAAE,6BAA6B,CAAC;CACjD;AAED,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,qBAAqB,EAAE,OAAO,CAAC;CAChC"}
|
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.21",
|
|
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": [
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
],
|
|
16
16
|
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
17
17
|
"license": "MIT",
|
|
18
|
-
"repository": "serwist/serwist",
|
|
19
|
-
"bugs": "https://
|
|
18
|
+
"repository": "https://gitlab.com/serwist/serwist",
|
|
19
|
+
"bugs": "https://gitlab.com/serwist/serwist/issues",
|
|
20
20
|
"homepage": "https://serwist.pages.dev",
|
|
21
21
|
"main": "./dist/index.js",
|
|
22
22
|
"types": "./dist/index.d.ts",
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
|
-
"rollup": "4.
|
|
42
|
-
"typescript": "5.
|
|
43
|
-
"@serwist/constants": "9.0.0-preview.
|
|
41
|
+
"rollup": "4.13.0",
|
|
42
|
+
"typescript": "5.5.0-dev.20240323",
|
|
43
|
+
"@serwist/constants": "9.0.0-preview.21"
|
|
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
|
/**
|
|
@@ -18,7 +19,7 @@ import type { MapLikeObject } from "../types.js";
|
|
|
18
19
|
*
|
|
19
20
|
* @private
|
|
20
21
|
*/
|
|
21
|
-
class SerwistError extends Error {
|
|
22
|
+
export class SerwistError extends Error {
|
|
22
23
|
details?: MapLikeObject;
|
|
23
24
|
|
|
24
25
|
/**
|
|
@@ -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);
|
|
@@ -38,5 +39,3 @@ class SerwistError extends Error {
|
|
|
38
39
|
this.details = details;
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
|
-
|
|
42
|
-
export { SerwistError };
|
|
@@ -15,7 +15,7 @@ import { quotaErrorCallbacks } from "../models/quotaErrorCallbacks.js";
|
|
|
15
15
|
*
|
|
16
16
|
* @private
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
export const executeQuotaErrorCallbacks = async (): Promise<void> => {
|
|
19
19
|
if (process.env.NODE_ENV !== "production") {
|
|
20
20
|
logger.log(`About to run ${quotaErrorCallbacks.size} callbacks to clean up caches.`);
|
|
21
21
|
}
|
|
@@ -30,6 +30,4 @@ async function executeQuotaErrorCallbacks(): Promise<void> {
|
|
|
30
30
|
if (process.env.NODE_ENV !== "production") {
|
|
31
31
|
logger.log("Finished running callbacks.");
|
|
32
32
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export { executeQuotaErrorCallbacks };
|
|
33
|
+
};
|
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!
|
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
* @returns
|
|
15
15
|
* @private
|
|
16
16
|
*/
|
|
17
|
-
|
|
17
|
+
export const waitUntil = <T = any>(event: ExtendableEvent, asyncFn: () => Promise<T>): Promise<T> => {
|
|
18
18
|
const returnPromise = asyncFn();
|
|
19
19
|
event.waitUntil(returnPromise);
|
|
20
20
|
return returnPromise;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export { waitUntil };
|
|
21
|
+
};
|
package/src/cacheNames.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { cacheNames as _cacheNames } from "./_private/cacheNames.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Get the current cache names and prefix/suffix used by
|
|
12
|
+
* Get the current cache names and prefix/suffix used by Serwist.
|
|
13
13
|
*
|
|
14
14
|
* `cacheNames.precache` is used for precached assets,
|
|
15
15
|
* `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
|
|
@@ -20,7 +20,7 @@ import { cacheNames as _cacheNames } from "./_private/cacheNames.js";
|
|
|
20
20
|
*
|
|
21
21
|
* @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
|
|
22
22
|
*/
|
|
23
|
-
const cacheNames = {
|
|
23
|
+
export const cacheNames = {
|
|
24
24
|
get googleAnalytics(): string {
|
|
25
25
|
return _cacheNames.getGoogleAnalyticsName();
|
|
26
26
|
},
|
|
@@ -37,5 +37,3 @@ const cacheNames = {
|
|
|
37
37
|
return _cacheNames.getSuffix();
|
|
38
38
|
},
|
|
39
39
|
};
|
|
40
|
-
|
|
41
|
-
export { cacheNames };
|
package/src/clientsClaim.ts
CHANGED
|
@@ -10,11 +10,9 @@
|
|
|
10
10
|
declare let self: ServiceWorkerGlobalScope;
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Claims any currently available clients once the service worker
|
|
14
14
|
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
export const clientsClaim = (): void => {
|
|
17
17
|
self.addEventListener("activate", () => self.clients.claim());
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export { clientsClaim };
|
|
18
|
+
};
|
package/src/copyResponse.ts
CHANGED
|
@@ -27,7 +27,7 @@ import { canConstructResponseFromBodyStream } from "./_private/canConstructRespo
|
|
|
27
27
|
* @param response
|
|
28
28
|
* @param modifier
|
|
29
29
|
*/
|
|
30
|
-
|
|
30
|
+
export const copyResponse = async (response: Response, modifier?: (responseInit: ResponseInit) => ResponseInit): Promise<Response> => {
|
|
31
31
|
let origin = null;
|
|
32
32
|
// If response.url isn't set, assume it's cross-origin and keep origin null.
|
|
33
33
|
if (response.url) {
|
|
@@ -57,6 +57,4 @@ async function copyResponse(response: Response, modifier?: (responseInit: Respon
|
|
|
57
57
|
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
|
58
58
|
|
|
59
59
|
return new Response(body, modifiedResponseInit);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { copyResponse };
|
|
60
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -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 }) => {
|
|
@@ -130,11 +130,11 @@ export const messages: MessageMap = {
|
|
|
130
130
|
},
|
|
131
131
|
|
|
132
132
|
"max-entries-or-age-required": ({ moduleName, className, funcName }) => {
|
|
133
|
-
return `You must define either config.maxEntries or config.
|
|
133
|
+
return `You must define either 'config.maxEntries' or 'config.maxAgeSeconds' in '${moduleName}.${className}.${funcName}'`;
|
|
134
134
|
},
|
|
135
135
|
|
|
136
136
|
"statuses-or-headers-required": ({ moduleName, className, funcName }) => {
|
|
137
|
-
return `You must define either config.statuses or config.
|
|
137
|
+
return `You must define either 'config.statuses' or 'config.headers' in '${moduleName}.${className}.${funcName}'`;
|
|
138
138
|
},
|
|
139
139
|
|
|
140
140
|
"invalid-string": ({ moduleName, funcName, paramName }) => {
|
|
@@ -206,7 +206,7 @@ export const messages: MessageMap = {
|
|
|
206
206
|
},
|
|
207
207
|
|
|
208
208
|
"non-precached-url": ({ url }) => {
|
|
209
|
-
return `createHandlerBoundToURL(
|
|
209
|
+
return `'createHandlerBoundToURL("${url}")' was called, but that URL is not precached. Please pass in a URL that is precached instead.`;
|
|
210
210
|
},
|
|
211
211
|
|
|
212
212
|
"add-to-cache-list-conflicting-integrities": ({ url }) => {
|
|
@@ -218,14 +218,16 @@ export const messages: MessageMap = {
|
|
|
218
218
|
},
|
|
219
219
|
|
|
220
220
|
"cross-origin-copy-response": ({ origin }) => {
|
|
221
|
-
return
|
|
221
|
+
return `'@serwist/core.copyResponse()' can only be used with same-origin responses. It was passed a response with origin ${origin}.`;
|
|
222
222
|
},
|
|
223
223
|
|
|
224
224
|
"opaque-streams-source": ({ type }) => {
|
|
225
|
-
const message = `One of the @serwist/streams sources resulted in an '${type}' response.`;
|
|
225
|
+
const message = `One of the '@serwist/streams' sources resulted in an '${type}' response.`;
|
|
226
226
|
if (type === "opaqueredirect") {
|
|
227
227
|
return `${message} Please do not use a navigation request that results in a redirect as a source.`;
|
|
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;
|
|
@@ -17,7 +17,7 @@ import { quotaErrorCallbacks } from "./models/quotaErrorCallbacks.js";
|
|
|
17
17
|
* @param callback
|
|
18
18
|
*/
|
|
19
19
|
// biome-ignore lint/complexity/noBannedTypes: Can't change Function type
|
|
20
|
-
|
|
20
|
+
export const registerQuotaErrorCallback = (callback: Function): void => {
|
|
21
21
|
if (process.env.NODE_ENV !== "production") {
|
|
22
22
|
assert!.isType(callback, "function", {
|
|
23
23
|
moduleName: "@serwist/core",
|
|
@@ -31,6 +31,4 @@ function registerQuotaErrorCallback(callback: Function): void {
|
|
|
31
31
|
if (process.env.NODE_ENV !== "production") {
|
|
32
32
|
logger.log("Registered a callback to respond to quota errors.", callback);
|
|
33
33
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { registerQuotaErrorCallback };
|
|
34
|
+
};
|
|
@@ -12,12 +12,12 @@ import type { PartialCacheNameDetails } from "./_private/cacheNames.js";
|
|
|
12
12
|
import { cacheNames } from "./_private/cacheNames.js";
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Modifies the default cache names used by
|
|
15
|
+
* Modifies the default cache names used by Serwist packages.
|
|
16
16
|
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
|
17
17
|
*
|
|
18
18
|
* @param details
|
|
19
19
|
*/
|
|
20
|
-
|
|
20
|
+
export const setCacheNameDetails = (details: PartialCacheNameDetails): void => {
|
|
21
21
|
if (process.env.NODE_ENV !== "production") {
|
|
22
22
|
for (const key of Object.keys(details)) {
|
|
23
23
|
assert!.isType(details[key], "string", {
|
|
@@ -50,6 +50,4 @@ function setCacheNameDetails(details: PartialCacheNameDetails): void {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
cacheNames.updateDetails(details);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export { setCacheNameDetails };
|
|
53
|
+
};
|
package/src/types.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
license that can be found in the LICENSE file or at
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
|
+
export type PromiseOrNot<T> = T | Promise<T>;
|
|
8
9
|
|
|
9
10
|
export interface MapLikeObject {
|
|
10
11
|
[key: string]: any;
|
|
@@ -37,14 +38,12 @@ export interface RouteMatchCallbackOptions {
|
|
|
37
38
|
* is a non-empty array or object, that value will be set on the handler's
|
|
38
39
|
* `options.params` argument.
|
|
39
40
|
*/
|
|
40
|
-
export
|
|
41
|
-
(options: RouteMatchCallbackOptions): any;
|
|
42
|
-
}
|
|
41
|
+
export type RouteMatchCallback = (options: RouteMatchCallbackOptions) => any;
|
|
43
42
|
|
|
44
43
|
/**
|
|
45
44
|
* Options passed to a `RouteHandlerCallback` function.
|
|
46
45
|
*/
|
|
47
|
-
export
|
|
46
|
+
export interface RouteHandlerCallbackOptions {
|
|
48
47
|
/**
|
|
49
48
|
* The event associated with the request.
|
|
50
49
|
*/
|
|
@@ -71,6 +70,11 @@ export interface ManualHandlerCallbackOptions {
|
|
|
71
70
|
* A request to run this strategy for.
|
|
72
71
|
*/
|
|
73
72
|
request: Request | string;
|
|
73
|
+
url?: never;
|
|
74
|
+
/**
|
|
75
|
+
* The return value from `@serwist/routing`'s `matchCallback` (if applicable).
|
|
76
|
+
*/
|
|
77
|
+
params?: never;
|
|
74
78
|
}
|
|
75
79
|
|
|
76
80
|
export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandlerCallbackOptions;
|
|
@@ -83,9 +87,7 @@ export type HandlerCallbackOptions = RouteHandlerCallbackOptions | ManualHandler
|
|
|
83
87
|
* If a non-empty array or object is returned by the `RouteMatchCallback` it
|
|
84
88
|
* will be passed in as this handler's `options.params` argument.
|
|
85
89
|
*/
|
|
86
|
-
export
|
|
87
|
-
(options: RouteHandlerCallbackOptions): Promise<Response>;
|
|
88
|
-
}
|
|
90
|
+
export type RouteHandlerCallback = (options: RouteHandlerCallbackOptions) => Promise<Response>;
|
|
89
91
|
|
|
90
92
|
/**
|
|
91
93
|
* The "handler" callback is invoked whenever a `Router` matches a URL/Request
|
|
@@ -95,9 +97,7 @@ export interface RouteHandlerCallback {
|
|
|
95
97
|
* If a non-empty array or object is returned by the `RouteMatchCallback` it
|
|
96
98
|
* will be passed in as this handler's `options.params` argument.
|
|
97
99
|
*/
|
|
98
|
-
export
|
|
99
|
-
(options: ManualHandlerCallbackOptions): Promise<Response>;
|
|
100
|
-
}
|
|
100
|
+
export type ManualHandlerCallback = (options: ManualHandlerCallbackOptions) => Promise<Response>;
|
|
101
101
|
|
|
102
102
|
/**
|
|
103
103
|
* An object with a `handle` method of type `RouteHandlerCallback`.
|
|
@@ -122,9 +122,7 @@ export interface HandlerWillStartCallbackParam {
|
|
|
122
122
|
state?: PluginState;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
export
|
|
126
|
-
(param: HandlerWillStartCallbackParam): Promise<any>;
|
|
127
|
-
}
|
|
125
|
+
export type HandlerWillStartCallback = (param: HandlerWillStartCallbackParam) => Promise<any>;
|
|
128
126
|
|
|
129
127
|
export interface CacheDidUpdateCallbackParam {
|
|
130
128
|
/**
|
|
@@ -151,9 +149,7 @@ export interface CacheDidUpdateCallbackParam {
|
|
|
151
149
|
state?: PluginState;
|
|
152
150
|
}
|
|
153
151
|
|
|
154
|
-
export
|
|
155
|
-
(param: CacheDidUpdateCallbackParam): Promise<any>;
|
|
156
|
-
}
|
|
152
|
+
export type CacheDidUpdateCallback = (param: CacheDidUpdateCallbackParam) => PromiseOrNot<any>;
|
|
157
153
|
|
|
158
154
|
export interface CacheKeyWillBeUsedCallbackParam {
|
|
159
155
|
mode: string;
|
|
@@ -163,9 +159,7 @@ export interface CacheKeyWillBeUsedCallbackParam {
|
|
|
163
159
|
state?: PluginState;
|
|
164
160
|
}
|
|
165
161
|
|
|
166
|
-
export
|
|
167
|
-
(param: CacheKeyWillBeUsedCallbackParam): Promise<Request | string>;
|
|
168
|
-
}
|
|
162
|
+
export type CacheKeyWillBeUsedCallback = (param: CacheKeyWillBeUsedCallbackParam) => PromiseOrNot<Request | string>;
|
|
169
163
|
|
|
170
164
|
export interface CacheWillUpdateCallbackParam {
|
|
171
165
|
request: Request;
|
|
@@ -174,9 +168,7 @@ export interface CacheWillUpdateCallbackParam {
|
|
|
174
168
|
state?: PluginState;
|
|
175
169
|
}
|
|
176
170
|
|
|
177
|
-
export
|
|
178
|
-
(param: CacheWillUpdateCallbackParam): Promise<any>;
|
|
179
|
-
}
|
|
171
|
+
export type CacheWillUpdateCallback = (param: CacheWillUpdateCallbackParam) => PromiseOrNot<any>;
|
|
180
172
|
|
|
181
173
|
export interface CachedResponseWillBeUsedCallbackParam {
|
|
182
174
|
/**
|
|
@@ -198,9 +190,7 @@ export interface CachedResponseWillBeUsedCallbackParam {
|
|
|
198
190
|
state?: PluginState;
|
|
199
191
|
}
|
|
200
192
|
|
|
201
|
-
export
|
|
202
|
-
(param: CachedResponseWillBeUsedCallbackParam): Promise<any>;
|
|
203
|
-
}
|
|
193
|
+
export type CachedResponseWillBeUsedCallback = (param: CachedResponseWillBeUsedCallbackParam) => PromiseOrNot<any>;
|
|
204
194
|
|
|
205
195
|
export interface FetchDidFailCallbackParam {
|
|
206
196
|
error: Error;
|
|
@@ -210,9 +200,7 @@ export interface FetchDidFailCallbackParam {
|
|
|
210
200
|
state?: PluginState;
|
|
211
201
|
}
|
|
212
202
|
|
|
213
|
-
export
|
|
214
|
-
(param: FetchDidFailCallbackParam): Promise<any>;
|
|
215
|
-
}
|
|
203
|
+
export type FetchDidFailCallback = (param: FetchDidFailCallbackParam) => PromiseOrNot<any>;
|
|
216
204
|
|
|
217
205
|
export interface FetchDidSucceedCallbackParam {
|
|
218
206
|
request: Request;
|
|
@@ -221,9 +209,7 @@ export interface FetchDidSucceedCallbackParam {
|
|
|
221
209
|
state?: PluginState;
|
|
222
210
|
}
|
|
223
211
|
|
|
224
|
-
export
|
|
225
|
-
(param: FetchDidSucceedCallbackParam): Promise<Response>;
|
|
226
|
-
}
|
|
212
|
+
export type FetchDidSucceedCallback = (param: FetchDidSucceedCallbackParam) => PromiseOrNot<Response>;
|
|
227
213
|
|
|
228
214
|
export interface RequestWillFetchCallbackParam {
|
|
229
215
|
request: Request;
|
|
@@ -231,9 +217,7 @@ export interface RequestWillFetchCallbackParam {
|
|
|
231
217
|
state?: PluginState;
|
|
232
218
|
}
|
|
233
219
|
|
|
234
|
-
export
|
|
235
|
-
(param: RequestWillFetchCallbackParam): Promise<Request>;
|
|
236
|
-
}
|
|
220
|
+
export type RequestWillFetchCallback = (param: RequestWillFetchCallbackParam) => PromiseOrNot<Request>;
|
|
237
221
|
|
|
238
222
|
export interface HandlerWillRespondCallbackParam {
|
|
239
223
|
request: Request;
|
|
@@ -242,9 +226,7 @@ export interface HandlerWillRespondCallbackParam {
|
|
|
242
226
|
state?: PluginState;
|
|
243
227
|
}
|
|
244
228
|
|
|
245
|
-
export
|
|
246
|
-
(param: HandlerWillRespondCallbackParam): Promise<Response>;
|
|
247
|
-
}
|
|
229
|
+
export type HandlerWillRespondCallback = (param: HandlerWillRespondCallbackParam) => PromiseOrNot<Response>;
|
|
248
230
|
|
|
249
231
|
export interface HandlerDidErrorCallbackParam {
|
|
250
232
|
request: Request;
|
|
@@ -253,9 +235,7 @@ export interface HandlerDidErrorCallbackParam {
|
|
|
253
235
|
state?: PluginState;
|
|
254
236
|
}
|
|
255
237
|
|
|
256
|
-
export
|
|
257
|
-
(param: HandlerDidErrorCallbackParam): Promise<Response | undefined>;
|
|
258
|
-
}
|
|
238
|
+
export type HandlerDidErrorCallback = (param: HandlerDidErrorCallbackParam) => PromiseOrNot<Response | undefined>;
|
|
259
239
|
|
|
260
240
|
export interface HandlerDidRespondCallbackParam {
|
|
261
241
|
request: Request;
|
|
@@ -264,9 +244,7 @@ export interface HandlerDidRespondCallbackParam {
|
|
|
264
244
|
state?: PluginState;
|
|
265
245
|
}
|
|
266
246
|
|
|
267
|
-
export
|
|
268
|
-
(param: HandlerDidRespondCallbackParam): Promise<any>;
|
|
269
|
-
}
|
|
247
|
+
export type HandlerDidRespondCallback = (param: HandlerDidRespondCallbackParam) => PromiseOrNot<any>;
|
|
270
248
|
|
|
271
249
|
export interface HandlerDidCompleteCallbackParam {
|
|
272
250
|
request: Request;
|
|
@@ -276,9 +254,7 @@ export interface HandlerDidCompleteCallbackParam {
|
|
|
276
254
|
state?: PluginState;
|
|
277
255
|
}
|
|
278
256
|
|
|
279
|
-
export
|
|
280
|
-
(param: HandlerDidCompleteCallbackParam): Promise<any>;
|
|
281
|
-
}
|
|
257
|
+
export type HandlerDidCompleteCallback = (param: HandlerDidCompleteCallbackParam) => PromiseOrNot<any>;
|
|
282
258
|
|
|
283
259
|
/**
|
|
284
260
|
* An object with optional lifecycle callback properties for the fetch and
|
|
@@ -313,3 +289,12 @@ export interface SerwistPluginCallbackParam {
|
|
|
313
289
|
handlerWillStart: HandlerWillStartCallbackParam;
|
|
314
290
|
requestWillFetch: RequestWillFetchCallbackParam;
|
|
315
291
|
}
|
|
292
|
+
|
|
293
|
+
export interface SerwistGlobalConfig {
|
|
294
|
+
/**
|
|
295
|
+
* Whether Serwist should disable development logging.
|
|
296
|
+
*
|
|
297
|
+
* @default false
|
|
298
|
+
*/
|
|
299
|
+
__WB_DISABLE_DEV_LOGS: boolean;
|
|
300
|
+
}
|
package/src/utils/welcome.ts
CHANGED
|
@@ -19,7 +19,6 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
19
19
|
"You can force this with serwist.setConfig({debug: true|false}).",
|
|
20
20
|
);
|
|
21
21
|
logger.log(`📖 Read the guides and documentation\n${padding}https://developers.google.com/web/tools/workbox/`);
|
|
22
|
-
logger.log(
|
|
23
|
-
logger.log(`🐛 Found a bug? Report it on GitHub\n${padding}https://github.com/serwist/serwist/issues/new`);
|
|
22
|
+
logger.log(`🐛 Found a bug or want to ask a question? Open a new issue on GitLab\n${padding}https://gitlab.com/serwist/serwist/issues/new`);
|
|
24
23
|
logger.groupEnd();
|
|
25
24
|
}
|