@serwist/strategies 8.4.0 → 8.4.1
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/index.cjs +33 -31
- package/dist/index.js +33 -31
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -90,7 +90,7 @@ function toRequest(input) {
|
|
|
90
90
|
const possiblePreloadResponse = await event.preloadResponse;
|
|
91
91
|
if (possiblePreloadResponse) {
|
|
92
92
|
if (process.env.NODE_ENV !== "production") {
|
|
93
|
-
internal.logger.log(`Using a preloaded navigation response for
|
|
93
|
+
internal.logger.log(`Using a preloaded navigation response for '${internal.getFriendlyURL(request.url)}'`);
|
|
94
94
|
}
|
|
95
95
|
return possiblePreloadResponse;
|
|
96
96
|
}
|
|
@@ -122,7 +122,7 @@ function toRequest(input) {
|
|
|
122
122
|
// See https://github.com/GoogleChrome/workbox/issues/1796
|
|
123
123
|
fetchResponse = await fetch(request, request.mode === "navigate" ? undefined : this._strategy.fetchOptions);
|
|
124
124
|
if (process.env.NODE_ENV !== "production") {
|
|
125
|
-
internal.logger.debug(`Network request for
|
|
125
|
+
internal.logger.debug(`Network request for '${internal.getFriendlyURL(request.url)}' returned a response with status '${fetchResponse.status}'.`);
|
|
126
126
|
}
|
|
127
127
|
for (const callback of this.iterateCallbacks("fetchDidSucceed")){
|
|
128
128
|
fetchResponse = await callback({
|
|
@@ -134,7 +134,7 @@ function toRequest(input) {
|
|
|
134
134
|
return fetchResponse;
|
|
135
135
|
} catch (error) {
|
|
136
136
|
if (process.env.NODE_ENV !== "production") {
|
|
137
|
-
internal.logger.log(`Network request for
|
|
137
|
+
internal.logger.log(`Network request for '${internal.getFriendlyURL(request.url)}' threw an error.`, error);
|
|
138
138
|
}
|
|
139
139
|
// `originalRequest` will only exist if a `fetchDidFail` callback
|
|
140
140
|
// is being used (see above).
|
|
@@ -235,12 +235,12 @@ function toRequest(input) {
|
|
|
235
235
|
// See https://github.com/GoogleChrome/workbox/issues/2818
|
|
236
236
|
const vary = response.headers.get("Vary");
|
|
237
237
|
if (vary) {
|
|
238
|
-
internal.logger.debug(`The response for ${internal.getFriendlyURL(effectiveRequest.url)}
|
|
238
|
+
internal.logger.debug(`The response for ${internal.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.`);
|
|
239
239
|
}
|
|
240
240
|
}
|
|
241
241
|
if (!response) {
|
|
242
242
|
if (process.env.NODE_ENV !== "production") {
|
|
243
|
-
internal.logger.error(`Cannot cache non-existent response for
|
|
243
|
+
internal.logger.error(`Cannot cache non-existent response for '${internal.getFriendlyURL(effectiveRequest.url)}'.`);
|
|
244
244
|
}
|
|
245
245
|
throw new internal.SerwistError("cache-put-with-no-response", {
|
|
246
246
|
url: internal.getFriendlyURL(effectiveRequest.url)
|
|
@@ -249,7 +249,7 @@ function toRequest(input) {
|
|
|
249
249
|
const responseToCache = await this._ensureResponseSafeToCache(response);
|
|
250
250
|
if (!responseToCache) {
|
|
251
251
|
if (process.env.NODE_ENV !== "production") {
|
|
252
|
-
internal.logger.debug(`Response '${internal.getFriendlyURL(effectiveRequest.url)}'
|
|
252
|
+
internal.logger.debug(`Response '${internal.getFriendlyURL(effectiveRequest.url)}' will not be cached.`, responseToCache);
|
|
253
253
|
}
|
|
254
254
|
return false;
|
|
255
255
|
}
|
|
@@ -396,7 +396,7 @@ function toRequest(input) {
|
|
|
396
396
|
* `waitUntil()` method), otherwise the service worker thread my be killed
|
|
397
397
|
* prior to your work completing.
|
|
398
398
|
*/ async doneWaiting() {
|
|
399
|
-
let promise;
|
|
399
|
+
let promise = undefined;
|
|
400
400
|
while(promise = this._extendLifetimePromises.shift()){
|
|
401
401
|
await promise;
|
|
402
402
|
}
|
|
@@ -436,9 +436,9 @@ function toRequest(input) {
|
|
|
436
436
|
if (responseToCache) {
|
|
437
437
|
if (responseToCache.status !== 200) {
|
|
438
438
|
if (responseToCache.status === 0) {
|
|
439
|
-
internal.logger.warn(`The response for '${this.request.url}'
|
|
439
|
+
internal.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.`);
|
|
440
440
|
} else {
|
|
441
|
-
internal.logger.debug(`The response for '${this.request.url}'
|
|
441
|
+
internal.logger.debug(`The response for '${this.request.url}' returned a status code of '${response.status}' and won't be cached as a result.`);
|
|
442
442
|
}
|
|
443
443
|
}
|
|
444
444
|
}
|
|
@@ -561,8 +561,9 @@ function toRequest(input) {
|
|
|
561
561
|
}
|
|
562
562
|
if (!response) {
|
|
563
563
|
throw error;
|
|
564
|
-
}
|
|
565
|
-
|
|
564
|
+
}
|
|
565
|
+
if (process.env.NODE_ENV !== "production") {
|
|
566
|
+
throw internal.logger.log(`While responding to '${internal.getFriendlyURL(request.url)}', an ${error instanceof Error ? error.toString() : ""} error occurred. Using a fallback response provided by a handlerDidError plugin.`);
|
|
566
567
|
}
|
|
567
568
|
}
|
|
568
569
|
for (const callback of handler.iterateCallbacks("handlerWillRespond")){
|
|
@@ -575,8 +576,8 @@ function toRequest(input) {
|
|
|
575
576
|
return response;
|
|
576
577
|
}
|
|
577
578
|
async _awaitComplete(responseDone, handler, request, event) {
|
|
578
|
-
let response;
|
|
579
|
-
let error;
|
|
579
|
+
let response = undefined;
|
|
580
|
+
let error = undefined;
|
|
580
581
|
try {
|
|
581
582
|
response = await responseDone;
|
|
582
583
|
} catch (error) {
|
|
@@ -600,7 +601,7 @@ function toRequest(input) {
|
|
|
600
601
|
event,
|
|
601
602
|
request,
|
|
602
603
|
response,
|
|
603
|
-
error
|
|
604
|
+
error
|
|
604
605
|
});
|
|
605
606
|
handler.destroy();
|
|
606
607
|
if (error) {
|
|
@@ -613,7 +614,7 @@ const messages = {
|
|
|
613
614
|
strategyStart: (strategyName, request)=>`Using ${strategyName} to respond to '${internal.getFriendlyURL(request.url)}'`,
|
|
614
615
|
printFinalResponse: (response)=>{
|
|
615
616
|
if (response) {
|
|
616
|
-
internal.logger.groupCollapsed(
|
|
617
|
+
internal.logger.groupCollapsed("View the final response here.");
|
|
617
618
|
internal.logger.log(response || "[No response returned]");
|
|
618
619
|
internal.logger.groupEnd();
|
|
619
620
|
}
|
|
@@ -650,7 +651,7 @@ const messages = {
|
|
|
650
651
|
let error = undefined;
|
|
651
652
|
if (!response) {
|
|
652
653
|
if (process.env.NODE_ENV !== "production") {
|
|
653
|
-
logs.push(`No response found in the '${this.cacheName}' cache.
|
|
654
|
+
logs.push(`No response found in the '${this.cacheName}' cache. Will respond with a network request.`);
|
|
654
655
|
}
|
|
655
656
|
try {
|
|
656
657
|
response = await handler.fetchAndCachePut(request);
|
|
@@ -661,9 +662,9 @@ const messages = {
|
|
|
661
662
|
}
|
|
662
663
|
if (process.env.NODE_ENV !== "production") {
|
|
663
664
|
if (response) {
|
|
664
|
-
logs.push(
|
|
665
|
+
logs.push("Got response from network.");
|
|
665
666
|
} else {
|
|
666
|
-
logs.push(
|
|
667
|
+
logs.push("Unable to get a response from the network.");
|
|
667
668
|
}
|
|
668
669
|
}
|
|
669
670
|
} else {
|
|
@@ -715,7 +716,7 @@ const messages = {
|
|
|
715
716
|
if (process.env.NODE_ENV !== "production") {
|
|
716
717
|
internal.logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
717
718
|
if (response) {
|
|
718
|
-
internal.logger.log(`Found a cached response in the '${this.cacheName}'
|
|
719
|
+
internal.logger.log(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
719
720
|
messages.printFinalResponse(response);
|
|
720
721
|
} else {
|
|
721
722
|
internal.logger.log(`No response found in the '${this.cacheName}' cache.`);
|
|
@@ -852,11 +853,12 @@ const messages = {
|
|
|
852
853
|
* @returns
|
|
853
854
|
* @private
|
|
854
855
|
*/ _getTimeoutPromise({ request, logs, handler }) {
|
|
856
|
+
// biome-ignore lint/suspicious/noImplicitAnyLet: setTimeout is typed with Node.js's typings, so we can't use number | undefined here.
|
|
855
857
|
let timeoutId;
|
|
856
858
|
const timeoutPromise = new Promise((resolve)=>{
|
|
857
859
|
const onNetworkTimeout = async ()=>{
|
|
858
860
|
if (process.env.NODE_ENV !== "production") {
|
|
859
|
-
logs.push(`Timing out the network response at
|
|
861
|
+
logs.push(`Timing out the network response at ${this._networkTimeoutSeconds} seconds.`);
|
|
860
862
|
}
|
|
861
863
|
resolve(await handler.cacheMatch(request));
|
|
862
864
|
};
|
|
@@ -877,8 +879,8 @@ const messages = {
|
|
|
877
879
|
*
|
|
878
880
|
* @private
|
|
879
881
|
*/ async _getNetworkPromise({ timeoutId, request, logs, handler }) {
|
|
880
|
-
let error;
|
|
881
|
-
let response;
|
|
882
|
+
let error = undefined;
|
|
883
|
+
let response = undefined;
|
|
882
884
|
try {
|
|
883
885
|
response = await handler.fetchAndCachePut(request);
|
|
884
886
|
} catch (fetchError) {
|
|
@@ -891,16 +893,16 @@ const messages = {
|
|
|
891
893
|
}
|
|
892
894
|
if (process.env.NODE_ENV !== "production") {
|
|
893
895
|
if (response) {
|
|
894
|
-
logs.push(
|
|
896
|
+
logs.push("Got response from network.");
|
|
895
897
|
} else {
|
|
896
|
-
logs.push(
|
|
898
|
+
logs.push("Unable to get a response from the network. Will respond " + "with a cached response.");
|
|
897
899
|
}
|
|
898
900
|
}
|
|
899
901
|
if (error || !response) {
|
|
900
902
|
response = await handler.cacheMatch(request);
|
|
901
903
|
if (process.env.NODE_ENV !== "production") {
|
|
902
904
|
if (response) {
|
|
903
|
-
logs.push(`Found a cached response in the '${this.cacheName}'
|
|
905
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
904
906
|
} else {
|
|
905
907
|
logs.push(`No response found in the '${this.cacheName}' cache.`);
|
|
906
908
|
}
|
|
@@ -951,7 +953,7 @@ const messages = {
|
|
|
951
953
|
}
|
|
952
954
|
response = await Promise.race(promises);
|
|
953
955
|
if (!response) {
|
|
954
|
-
throw new Error(`Timed out the network response after
|
|
956
|
+
throw new Error(`Timed out the network response after ${this._networkTimeoutSeconds} seconds.`);
|
|
955
957
|
}
|
|
956
958
|
} catch (err) {
|
|
957
959
|
if (err instanceof Error) {
|
|
@@ -961,9 +963,9 @@ const messages = {
|
|
|
961
963
|
if (process.env.NODE_ENV !== "production") {
|
|
962
964
|
internal.logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
963
965
|
if (response) {
|
|
964
|
-
internal.logger.log(
|
|
966
|
+
internal.logger.log("Got response from network.");
|
|
965
967
|
} else {
|
|
966
|
-
internal.logger.log(
|
|
968
|
+
internal.logger.log("Unable to get a response from the network.");
|
|
967
969
|
}
|
|
968
970
|
messages.printFinalResponse(response);
|
|
969
971
|
internal.logger.groupEnd();
|
|
@@ -1027,14 +1029,14 @@ const messages = {
|
|
|
1027
1029
|
});
|
|
1028
1030
|
void handler.waitUntil(fetchAndCachePromise);
|
|
1029
1031
|
let response = await handler.cacheMatch(request);
|
|
1030
|
-
let error;
|
|
1032
|
+
let error = undefined;
|
|
1031
1033
|
if (response) {
|
|
1032
1034
|
if (process.env.NODE_ENV !== "production") {
|
|
1033
|
-
logs.push(`Found a cached response in the '${this.cacheName}'
|
|
1035
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache. Will update with the network response in the background.`);
|
|
1034
1036
|
}
|
|
1035
1037
|
} else {
|
|
1036
1038
|
if (process.env.NODE_ENV !== "production") {
|
|
1037
|
-
logs.push(`No response found in the '${this.cacheName}' cache.
|
|
1039
|
+
logs.push(`No response found in the '${this.cacheName}' cache. Will wait for the network response.`);
|
|
1038
1040
|
}
|
|
1039
1041
|
try {
|
|
1040
1042
|
// NOTE(philipwalton): Really annoying that we have to type cast here.
|
package/dist/index.js
CHANGED
|
@@ -88,7 +88,7 @@ function toRequest(input) {
|
|
|
88
88
|
const possiblePreloadResponse = await event.preloadResponse;
|
|
89
89
|
if (possiblePreloadResponse) {
|
|
90
90
|
if (process.env.NODE_ENV !== "production") {
|
|
91
|
-
logger.log(`Using a preloaded navigation response for
|
|
91
|
+
logger.log(`Using a preloaded navigation response for '${getFriendlyURL(request.url)}'`);
|
|
92
92
|
}
|
|
93
93
|
return possiblePreloadResponse;
|
|
94
94
|
}
|
|
@@ -120,7 +120,7 @@ function toRequest(input) {
|
|
|
120
120
|
// See https://github.com/GoogleChrome/workbox/issues/1796
|
|
121
121
|
fetchResponse = await fetch(request, request.mode === "navigate" ? undefined : this._strategy.fetchOptions);
|
|
122
122
|
if (process.env.NODE_ENV !== "production") {
|
|
123
|
-
logger.debug(`Network request for
|
|
123
|
+
logger.debug(`Network request for '${getFriendlyURL(request.url)}' returned a response with status '${fetchResponse.status}'.`);
|
|
124
124
|
}
|
|
125
125
|
for (const callback of this.iterateCallbacks("fetchDidSucceed")){
|
|
126
126
|
fetchResponse = await callback({
|
|
@@ -132,7 +132,7 @@ function toRequest(input) {
|
|
|
132
132
|
return fetchResponse;
|
|
133
133
|
} catch (error) {
|
|
134
134
|
if (process.env.NODE_ENV !== "production") {
|
|
135
|
-
logger.log(`Network request for
|
|
135
|
+
logger.log(`Network request for '${getFriendlyURL(request.url)}' threw an error.`, error);
|
|
136
136
|
}
|
|
137
137
|
// `originalRequest` will only exist if a `fetchDidFail` callback
|
|
138
138
|
// is being used (see above).
|
|
@@ -233,12 +233,12 @@ function toRequest(input) {
|
|
|
233
233
|
// See https://github.com/GoogleChrome/workbox/issues/2818
|
|
234
234
|
const vary = response.headers.get("Vary");
|
|
235
235
|
if (vary) {
|
|
236
|
-
logger.debug(`The response for ${getFriendlyURL(effectiveRequest.url)}
|
|
236
|
+
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.`);
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
if (!response) {
|
|
240
240
|
if (process.env.NODE_ENV !== "production") {
|
|
241
|
-
logger.error(`Cannot cache non-existent response for
|
|
241
|
+
logger.error(`Cannot cache non-existent response for '${getFriendlyURL(effectiveRequest.url)}'.`);
|
|
242
242
|
}
|
|
243
243
|
throw new SerwistError("cache-put-with-no-response", {
|
|
244
244
|
url: getFriendlyURL(effectiveRequest.url)
|
|
@@ -247,7 +247,7 @@ function toRequest(input) {
|
|
|
247
247
|
const responseToCache = await this._ensureResponseSafeToCache(response);
|
|
248
248
|
if (!responseToCache) {
|
|
249
249
|
if (process.env.NODE_ENV !== "production") {
|
|
250
|
-
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}'
|
|
250
|
+
logger.debug(`Response '${getFriendlyURL(effectiveRequest.url)}' will not be cached.`, responseToCache);
|
|
251
251
|
}
|
|
252
252
|
return false;
|
|
253
253
|
}
|
|
@@ -394,7 +394,7 @@ function toRequest(input) {
|
|
|
394
394
|
* `waitUntil()` method), otherwise the service worker thread my be killed
|
|
395
395
|
* prior to your work completing.
|
|
396
396
|
*/ async doneWaiting() {
|
|
397
|
-
let promise;
|
|
397
|
+
let promise = undefined;
|
|
398
398
|
while(promise = this._extendLifetimePromises.shift()){
|
|
399
399
|
await promise;
|
|
400
400
|
}
|
|
@@ -434,9 +434,9 @@ function toRequest(input) {
|
|
|
434
434
|
if (responseToCache) {
|
|
435
435
|
if (responseToCache.status !== 200) {
|
|
436
436
|
if (responseToCache.status === 0) {
|
|
437
|
-
logger.warn(`The response for '${this.request.url}'
|
|
437
|
+
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.`);
|
|
438
438
|
} else {
|
|
439
|
-
logger.debug(`The response for '${this.request.url}'
|
|
439
|
+
logger.debug(`The response for '${this.request.url}' returned a status code of '${response.status}' and won't be cached as a result.`);
|
|
440
440
|
}
|
|
441
441
|
}
|
|
442
442
|
}
|
|
@@ -559,8 +559,9 @@ function toRequest(input) {
|
|
|
559
559
|
}
|
|
560
560
|
if (!response) {
|
|
561
561
|
throw error;
|
|
562
|
-
}
|
|
563
|
-
|
|
562
|
+
}
|
|
563
|
+
if (process.env.NODE_ENV !== "production") {
|
|
564
|
+
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.`);
|
|
564
565
|
}
|
|
565
566
|
}
|
|
566
567
|
for (const callback of handler.iterateCallbacks("handlerWillRespond")){
|
|
@@ -573,8 +574,8 @@ function toRequest(input) {
|
|
|
573
574
|
return response;
|
|
574
575
|
}
|
|
575
576
|
async _awaitComplete(responseDone, handler, request, event) {
|
|
576
|
-
let response;
|
|
577
|
-
let error;
|
|
577
|
+
let response = undefined;
|
|
578
|
+
let error = undefined;
|
|
578
579
|
try {
|
|
579
580
|
response = await responseDone;
|
|
580
581
|
} catch (error) {
|
|
@@ -598,7 +599,7 @@ function toRequest(input) {
|
|
|
598
599
|
event,
|
|
599
600
|
request,
|
|
600
601
|
response,
|
|
601
|
-
error
|
|
602
|
+
error
|
|
602
603
|
});
|
|
603
604
|
handler.destroy();
|
|
604
605
|
if (error) {
|
|
@@ -611,7 +612,7 @@ const messages = {
|
|
|
611
612
|
strategyStart: (strategyName, request)=>`Using ${strategyName} to respond to '${getFriendlyURL(request.url)}'`,
|
|
612
613
|
printFinalResponse: (response)=>{
|
|
613
614
|
if (response) {
|
|
614
|
-
logger.groupCollapsed(
|
|
615
|
+
logger.groupCollapsed("View the final response here.");
|
|
615
616
|
logger.log(response || "[No response returned]");
|
|
616
617
|
logger.groupEnd();
|
|
617
618
|
}
|
|
@@ -648,7 +649,7 @@ const messages = {
|
|
|
648
649
|
let error = undefined;
|
|
649
650
|
if (!response) {
|
|
650
651
|
if (process.env.NODE_ENV !== "production") {
|
|
651
|
-
logs.push(`No response found in the '${this.cacheName}' cache.
|
|
652
|
+
logs.push(`No response found in the '${this.cacheName}' cache. Will respond with a network request.`);
|
|
652
653
|
}
|
|
653
654
|
try {
|
|
654
655
|
response = await handler.fetchAndCachePut(request);
|
|
@@ -659,9 +660,9 @@ const messages = {
|
|
|
659
660
|
}
|
|
660
661
|
if (process.env.NODE_ENV !== "production") {
|
|
661
662
|
if (response) {
|
|
662
|
-
logs.push(
|
|
663
|
+
logs.push("Got response from network.");
|
|
663
664
|
} else {
|
|
664
|
-
logs.push(
|
|
665
|
+
logs.push("Unable to get a response from the network.");
|
|
665
666
|
}
|
|
666
667
|
}
|
|
667
668
|
} else {
|
|
@@ -713,7 +714,7 @@ const messages = {
|
|
|
713
714
|
if (process.env.NODE_ENV !== "production") {
|
|
714
715
|
logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
715
716
|
if (response) {
|
|
716
|
-
logger.log(`Found a cached response in the '${this.cacheName}'
|
|
717
|
+
logger.log(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
717
718
|
messages.printFinalResponse(response);
|
|
718
719
|
} else {
|
|
719
720
|
logger.log(`No response found in the '${this.cacheName}' cache.`);
|
|
@@ -850,11 +851,12 @@ const messages = {
|
|
|
850
851
|
* @returns
|
|
851
852
|
* @private
|
|
852
853
|
*/ _getTimeoutPromise({ request, logs, handler }) {
|
|
854
|
+
// biome-ignore lint/suspicious/noImplicitAnyLet: setTimeout is typed with Node.js's typings, so we can't use number | undefined here.
|
|
853
855
|
let timeoutId;
|
|
854
856
|
const timeoutPromise = new Promise((resolve)=>{
|
|
855
857
|
const onNetworkTimeout = async ()=>{
|
|
856
858
|
if (process.env.NODE_ENV !== "production") {
|
|
857
|
-
logs.push(`Timing out the network response at
|
|
859
|
+
logs.push(`Timing out the network response at ${this._networkTimeoutSeconds} seconds.`);
|
|
858
860
|
}
|
|
859
861
|
resolve(await handler.cacheMatch(request));
|
|
860
862
|
};
|
|
@@ -875,8 +877,8 @@ const messages = {
|
|
|
875
877
|
*
|
|
876
878
|
* @private
|
|
877
879
|
*/ async _getNetworkPromise({ timeoutId, request, logs, handler }) {
|
|
878
|
-
let error;
|
|
879
|
-
let response;
|
|
880
|
+
let error = undefined;
|
|
881
|
+
let response = undefined;
|
|
880
882
|
try {
|
|
881
883
|
response = await handler.fetchAndCachePut(request);
|
|
882
884
|
} catch (fetchError) {
|
|
@@ -889,16 +891,16 @@ const messages = {
|
|
|
889
891
|
}
|
|
890
892
|
if (process.env.NODE_ENV !== "production") {
|
|
891
893
|
if (response) {
|
|
892
|
-
logs.push(
|
|
894
|
+
logs.push("Got response from network.");
|
|
893
895
|
} else {
|
|
894
|
-
logs.push(
|
|
896
|
+
logs.push("Unable to get a response from the network. Will respond " + "with a cached response.");
|
|
895
897
|
}
|
|
896
898
|
}
|
|
897
899
|
if (error || !response) {
|
|
898
900
|
response = await handler.cacheMatch(request);
|
|
899
901
|
if (process.env.NODE_ENV !== "production") {
|
|
900
902
|
if (response) {
|
|
901
|
-
logs.push(`Found a cached response in the '${this.cacheName}'
|
|
903
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache.`);
|
|
902
904
|
} else {
|
|
903
905
|
logs.push(`No response found in the '${this.cacheName}' cache.`);
|
|
904
906
|
}
|
|
@@ -949,7 +951,7 @@ const messages = {
|
|
|
949
951
|
}
|
|
950
952
|
response = await Promise.race(promises);
|
|
951
953
|
if (!response) {
|
|
952
|
-
throw new Error(`Timed out the network response after
|
|
954
|
+
throw new Error(`Timed out the network response after ${this._networkTimeoutSeconds} seconds.`);
|
|
953
955
|
}
|
|
954
956
|
} catch (err) {
|
|
955
957
|
if (err instanceof Error) {
|
|
@@ -959,9 +961,9 @@ const messages = {
|
|
|
959
961
|
if (process.env.NODE_ENV !== "production") {
|
|
960
962
|
logger.groupCollapsed(messages.strategyStart(this.constructor.name, request));
|
|
961
963
|
if (response) {
|
|
962
|
-
logger.log(
|
|
964
|
+
logger.log("Got response from network.");
|
|
963
965
|
} else {
|
|
964
|
-
logger.log(
|
|
966
|
+
logger.log("Unable to get a response from the network.");
|
|
965
967
|
}
|
|
966
968
|
messages.printFinalResponse(response);
|
|
967
969
|
logger.groupEnd();
|
|
@@ -1025,14 +1027,14 @@ const messages = {
|
|
|
1025
1027
|
});
|
|
1026
1028
|
void handler.waitUntil(fetchAndCachePromise);
|
|
1027
1029
|
let response = await handler.cacheMatch(request);
|
|
1028
|
-
let error;
|
|
1030
|
+
let error = undefined;
|
|
1029
1031
|
if (response) {
|
|
1030
1032
|
if (process.env.NODE_ENV !== "production") {
|
|
1031
|
-
logs.push(`Found a cached response in the '${this.cacheName}'
|
|
1033
|
+
logs.push(`Found a cached response in the '${this.cacheName}' cache. Will update with the network response in the background.`);
|
|
1032
1034
|
}
|
|
1033
1035
|
} else {
|
|
1034
1036
|
if (process.env.NODE_ENV !== "production") {
|
|
1035
|
-
logs.push(`No response found in the '${this.cacheName}' cache.
|
|
1037
|
+
logs.push(`No response found in the '${this.cacheName}' cache. Will wait for the network response.`);
|
|
1036
1038
|
}
|
|
1037
1039
|
try {
|
|
1038
1040
|
// NOTE(philipwalton): Really annoying that we have to type cast here.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/strategies",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A service worker helper library implementing common caching strategies.",
|
|
6
6
|
"files": [
|
|
@@ -37,16 +37,16 @@
|
|
|
37
37
|
"./package.json": "./package.json"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@serwist/core": "8.4.
|
|
40
|
+
"@serwist/core": "8.4.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"rollup": "4.9.1",
|
|
44
|
-
"@serwist/constants": "8.4.
|
|
44
|
+
"@serwist/constants": "8.4.1"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|
|
47
47
|
"build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
|
|
48
48
|
"dev": "rollup --config rollup.config.js --watch",
|
|
49
|
-
"lint": "
|
|
49
|
+
"lint": "biome lint ./src",
|
|
50
50
|
"typecheck": "tsc"
|
|
51
51
|
}
|
|
52
52
|
}
|