@serwist/strategies
Advanced tools
Comparing version 8.4.0 to 8.4.1
@@ -91,3 +91,3 @@ import { assert, Deferred, logger, getFriendlyURL, SerwistError, timeout, cacheMatchIgnoreParams, executeQuotaErrorCallbacks, privateCacheNames } from '@serwist/core/internal'; | ||
if (process.env.NODE_ENV !== "production") { | ||
logger.log(`Using a preloaded navigation response for ` + `'${getFriendlyURL(request.url)}'`); | ||
logger.log(`Using a preloaded navigation response for '${getFriendlyURL(request.url)}'`); | ||
} | ||
@@ -124,3 +124,3 @@ return possiblePreloadResponse; | ||
if (process.env.NODE_ENV !== "production") { | ||
logger.debug(`Network request for ` + `'${getFriendlyURL(request.url)}' returned a response with ` + `status '${fetchResponse.status}'.`); | ||
logger.debug(`Network request for '${getFriendlyURL(request.url)}' returned a response with status '${fetchResponse.status}'.`); | ||
} | ||
@@ -137,3 +137,3 @@ for (const callback of this.iterateCallbacks("fetchDidSucceed")){ | ||
if (process.env.NODE_ENV !== "production") { | ||
logger.log(`Network request for ` + `'${getFriendlyURL(request.url)}' threw an error.`, error); | ||
logger.log(`Network request for '${getFriendlyURL(request.url)}' threw an error.`, error); | ||
} | ||
@@ -239,3 +239,3 @@ // `originalRequest` will only exist if a `fetchDidFail` callback | ||
if (vary) { | ||
logger.debug(`The response for ${getFriendlyURL(effectiveRequest.url)} ` + `has a 'Vary: ${vary}' header. ` + `Consider setting the {ignoreVary: true} option on your strategy ` + `to ensure cache matching and deletion works as expected.`); | ||
logger.debug(`The response for ${getFriendlyURL(effectiveRequest.url)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`); | ||
} | ||
@@ -245,3 +245,3 @@ } | ||
if (process.env.NODE_ENV !== "production") { | ||
logger.error(`Cannot cache non-existent response for ` + `'${getFriendlyURL(effectiveRequest.url)}'.`); | ||
logger.error(`Cannot cache non-existent response for '${getFriendlyURL(effectiveRequest.url)}'.`); | ||
} | ||
@@ -255,3 +255,3 @@ throw new SerwistError("cache-put-with-no-response", { | ||
if (process.env.NODE_ENV !== "production") { | ||
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' ` + `will not be cached.`, responseToCache); | ||
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will not be cached.`, responseToCache); | ||
} | ||
@@ -403,3 +403,3 @@ return false; | ||
*/ async doneWaiting() { | ||
let promise; | ||
let promise = undefined; | ||
while(promise = this._extendLifetimePromises.shift()){ | ||
@@ -444,5 +444,5 @@ await promise; | ||
if (responseToCache.status === 0) { | ||
logger.warn(`The response for '${this.request.url}' ` + `is an opaque response. The caching strategy that you're ` + `using will not cache opaque responses by default.`); | ||
logger.warn(`The response for '${this.request.url}' is an opaque response. The caching strategy that you're using will not cache opaque responses by default.`); | ||
} else { | ||
logger.debug(`The response for '${this.request.url}' ` + `returned a status code of '${response.status}' and won't ` + `be cached as a result.`); | ||
logger.debug(`The response for '${this.request.url}' returned a status code of '${response.status}' and won't be cached as a result.`); | ||
} | ||
@@ -570,5 +570,6 @@ } | ||
throw error; | ||
} else if (process.env.NODE_ENV !== "production") { | ||
throw logger.log(`While responding to '${getFriendlyURL(request.url)}', ` + `an ${error instanceof Error ? error.toString() : ""} error occurred. Using a fallback response provided by ` + `a handlerDidError plugin.`); | ||
} | ||
if (process.env.NODE_ENV !== "production") { | ||
throw logger.log(`While responding to '${getFriendlyURL(request.url)}', an ${error instanceof Error ? error.toString() : ""} error occurred. Using a fallback response provided by a handlerDidError plugin.`); | ||
} | ||
} | ||
@@ -585,4 +586,4 @@ for (const callback of handler.iterateCallbacks("handlerWillRespond")){ | ||
async _awaitComplete(responseDone, handler, request, event) { | ||
let response; | ||
let error; | ||
let response = undefined; | ||
let error = undefined; | ||
try { | ||
@@ -611,3 +612,3 @@ response = await responseDone; | ||
response, | ||
error: error | ||
error | ||
}); | ||
@@ -625,3 +626,3 @@ handler.destroy(); | ||
if (response) { | ||
logger.groupCollapsed(`View the final response here.`); | ||
logger.groupCollapsed("View the final response here."); | ||
logger.log(response || "[No response returned]"); | ||
@@ -663,3 +664,3 @@ logger.groupEnd(); | ||
if (process.env.NODE_ENV !== "production") { | ||
logs.push(`No response found in the '${this.cacheName}' cache. ` + `Will respond with a network request.`); | ||
logs.push(`No response found in the '${this.cacheName}' cache. Will respond with a network request.`); | ||
} | ||
@@ -675,5 +676,5 @@ try { | ||
if (response) { | ||
logs.push(`Got response from network.`); | ||
logs.push("Got response from network."); | ||
} else { | ||
logs.push(`Unable to get a response from the network.`); | ||
logs.push("Unable to get a response from the network."); | ||
} | ||
@@ -730,3 +731,3 @@ } | ||
if (response) { | ||
logger.log(`Found a cached response in the '${this.cacheName}' ` + `cache.`); | ||
logger.log(`Found a cached response in the '${this.cacheName}' cache.`); | ||
messages.printFinalResponse(response); | ||
@@ -868,2 +869,3 @@ } else { | ||
*/ _getTimeoutPromise({ request, logs, handler }) { | ||
// biome-ignore lint/suspicious/noImplicitAnyLet: setTimeout is typed with Node.js's typings, so we can't use number | undefined here. | ||
let timeoutId; | ||
@@ -873,3 +875,3 @@ const timeoutPromise = new Promise((resolve)=>{ | ||
if (process.env.NODE_ENV !== "production") { | ||
logs.push(`Timing out the network response at ` + `${this._networkTimeoutSeconds} seconds.`); | ||
logs.push(`Timing out the network response at ${this._networkTimeoutSeconds} seconds.`); | ||
} | ||
@@ -895,4 +897,4 @@ resolve(await handler.cacheMatch(request)); | ||
*/ async _getNetworkPromise({ timeoutId, request, logs, handler }) { | ||
let error; | ||
let response; | ||
let error = undefined; | ||
let response = undefined; | ||
try { | ||
@@ -910,5 +912,5 @@ response = await handler.fetchAndCachePut(request); | ||
if (response) { | ||
logs.push(`Got response from network.`); | ||
logs.push("Got response from network."); | ||
} else { | ||
logs.push(`Unable to get a response from the network. Will respond ` + `with a cached response.`); | ||
logs.push("Unable to get a response from the network. Will respond " + "with a cached response."); | ||
} | ||
@@ -920,3 +922,3 @@ } | ||
if (response) { | ||
logs.push(`Found a cached response in the '${this.cacheName}'` + ` cache.`); | ||
logs.push(`Found a cached response in the '${this.cacheName}' cache.`); | ||
} else { | ||
@@ -972,3 +974,3 @@ logs.push(`No response found in the '${this.cacheName}' cache.`); | ||
if (!response) { | ||
throw new Error(`Timed out the network response after ` + `${this._networkTimeoutSeconds} seconds.`); | ||
throw new Error(`Timed out the network response after ${this._networkTimeoutSeconds} seconds.`); | ||
} | ||
@@ -983,5 +985,5 @@ } catch (err) { | ||
if (response) { | ||
logger.log(`Got response from network.`); | ||
logger.log("Got response from network."); | ||
} else { | ||
logger.log(`Unable to get a response from the network.`); | ||
logger.log("Unable to get a response from the network."); | ||
} | ||
@@ -1050,10 +1052,10 @@ messages.printFinalResponse(response); | ||
let response = await handler.cacheMatch(request); | ||
let error; | ||
let error = undefined; | ||
if (response) { | ||
if (process.env.NODE_ENV !== "production") { | ||
logs.push(`Found a cached response in the '${this.cacheName}'` + ` cache. Will update with the network response in the background.`); | ||
logs.push(`Found a cached response in the '${this.cacheName}' cache. Will update with the network response in the background.`); | ||
} | ||
} else { | ||
if (process.env.NODE_ENV !== "production") { | ||
logs.push(`No response found in the '${this.cacheName}' cache. ` + `Will wait for the network response.`); | ||
logs.push(`No response found in the '${this.cacheName}' cache. Will wait for the network response.`); | ||
} | ||
@@ -1060,0 +1062,0 @@ try { |
{ | ||
"name": "@serwist/strategies", | ||
"version": "8.4.0", | ||
"version": "8.4.1", | ||
"type": "module", | ||
@@ -40,7 +40,7 @@ "description": "A service worker helper library implementing common caching strategies.", | ||
"dependencies": { | ||
"@serwist/core": "8.4.0" | ||
"@serwist/core": "8.4.1" | ||
}, | ||
"devDependencies": { | ||
"rollup": "4.9.1", | ||
"@serwist/constants": "8.4.0" | ||
"@serwist/constants": "8.4.1" | ||
}, | ||
@@ -50,5 +50,5 @@ "scripts": { | ||
"dev": "rollup --config rollup.config.js --watch", | ||
"lint": "eslint src --ext ts,tsx,js,jsx,cjs,mjs", | ||
"lint": "biome lint ./src", | ||
"typecheck": "tsc" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
108335
2588
+ Added@serwist/core@8.4.1(transitive)
- Removed@serwist/core@8.4.0(transitive)
Updated@serwist/core@8.4.1