@serwist/strategies 9.0.0-preview.7 → 9.0.0-preview.9
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/StrategyHandler.d.ts +1 -2
- package/dist/StrategyHandler.d.ts.map +1 -1
- package/dist/index.js +7 -5
- package/package.json +3 -3
- package/src/StrategyHandler.ts +15 -16
|
@@ -6,7 +6,7 @@ import type { Strategy } from "./Strategy.js";
|
|
|
6
6
|
* and keeps track of when the strategy is "done" (i.e. all added `event.waitUntil()` promises
|
|
7
7
|
* have resolved).
|
|
8
8
|
*/
|
|
9
|
-
declare class StrategyHandler {
|
|
9
|
+
export declare class StrategyHandler {
|
|
10
10
|
/**
|
|
11
11
|
* The request the strategy is performing (passed to the strategy's
|
|
12
12
|
* `handle()` or `handleAll()` method).
|
|
@@ -184,5 +184,4 @@ declare class StrategyHandler {
|
|
|
184
184
|
*/
|
|
185
185
|
_ensureResponseSafeToCache(response: Response): Promise<Response | undefined>;
|
|
186
186
|
}
|
|
187
|
-
export { StrategyHandler };
|
|
188
187
|
//# sourceMappingURL=StrategyHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../src/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAiB,aAAa,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAYtH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"StrategyHandler.d.ts","sourceRoot":"","sources":["../src/StrategyHandler.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,sBAAsB,EAAiB,aAAa,EAAE,0BAA0B,EAAE,MAAM,eAAe,CAAC;AAYtH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAM9C;;;;;GAKG;AACH,q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AAM,WAAW,CAAC,aAAa,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3I;;;;;;;;OAQG;IACF,gBAAgB,CAAC,CAAC,SAAS,MAAM,aAAa,EAAE,IAAI,EAAE,CAAC,GAAG,SAAS,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;IAgBnG;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAK7C;;;;;;;;OAQG;IACG,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC;IAOlC;;;OAGG;IACH,OAAO,IAAI,IAAI;IAIf;;;;;;;OAOG;IACG,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,GAAG,SAAS,CAAC;CAuCpF"}
|
package/dist/index.js
CHANGED
|
@@ -141,10 +141,6 @@ class StrategyHandler {
|
|
|
141
141
|
method: effectiveRequest.method
|
|
142
142
|
});
|
|
143
143
|
}
|
|
144
|
-
const vary = response.headers.get("Vary");
|
|
145
|
-
if (vary) {
|
|
146
|
-
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.`);
|
|
147
|
-
}
|
|
148
144
|
}
|
|
149
145
|
if (!response) {
|
|
150
146
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -163,12 +159,18 @@ class StrategyHandler {
|
|
|
163
159
|
}
|
|
164
160
|
const { cacheName, matchOptions } = this._strategy;
|
|
165
161
|
const cache = await self.caches.open(cacheName);
|
|
162
|
+
if (process.env.NODE_ENV !== "production") {
|
|
163
|
+
const vary = response.headers.get("Vary");
|
|
164
|
+
if (vary && matchOptions?.ignoreVary !== true) {
|
|
165
|
+
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.`);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
166
168
|
const hasCacheUpdateCallback = this.hasCallback("cacheDidUpdate");
|
|
167
169
|
const oldResponse = hasCacheUpdateCallback ? await cacheMatchIgnoreParams(cache, effectiveRequest.clone(), [
|
|
168
170
|
"__WB_REVISION__"
|
|
169
171
|
], matchOptions) : null;
|
|
170
172
|
if (process.env.NODE_ENV !== "production") {
|
|
171
|
-
logger.debug(`Updating the '${cacheName}' cache with a new Response
|
|
173
|
+
logger.debug(`Updating the '${cacheName}' cache with a new Response for ${getFriendlyURL(effectiveRequest.url)}.`);
|
|
172
174
|
}
|
|
173
175
|
try {
|
|
174
176
|
await cache.put(effectiveRequest, hasCacheUpdateCallback ? responseToCache.clone() : responseToCache);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/strategies",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.9",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A service worker helper library implementing common caching strategies.",
|
|
6
6
|
"files": [
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
"./package.json": "./package.json"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@serwist/core": "9.0.0-preview.
|
|
33
|
+
"@serwist/core": "9.0.0-preview.9"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"rollup": "4.9.6",
|
|
37
37
|
"typescript": "5.4.0-dev.20240206",
|
|
38
|
-
"@serwist/constants": "9.0.0-preview.
|
|
38
|
+
"@serwist/constants": "9.0.0-preview.9"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"typescript": ">=5.0.0"
|
package/src/StrategyHandler.ts
CHANGED
|
@@ -30,7 +30,7 @@ function toRequest(input: RequestInfo) {
|
|
|
30
30
|
* and keeps track of when the strategy is "done" (i.e. all added `event.waitUntil()` promises
|
|
31
31
|
* have resolved).
|
|
32
32
|
*/
|
|
33
|
-
class StrategyHandler {
|
|
33
|
+
export class StrategyHandler {
|
|
34
34
|
/**
|
|
35
35
|
* The request the strategy is performing (passed to the strategy's
|
|
36
36
|
* `handle()` or `handleAll()` method).
|
|
@@ -281,16 +281,6 @@ class StrategyHandler {
|
|
|
281
281
|
method: effectiveRequest.method,
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
|
-
|
|
285
|
-
// See https://github.com/GoogleChrome/workbox/issues/2818
|
|
286
|
-
const vary = response.headers.get("Vary");
|
|
287
|
-
if (vary) {
|
|
288
|
-
logger.debug(
|
|
289
|
-
`The response for ${getFriendlyURL(
|
|
290
|
-
effectiveRequest.url,
|
|
291
|
-
)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`,
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
284
|
}
|
|
295
285
|
|
|
296
286
|
if (!response) {
|
|
@@ -315,6 +305,18 @@ class StrategyHandler {
|
|
|
315
305
|
const { cacheName, matchOptions } = this._strategy;
|
|
316
306
|
const cache = await self.caches.open(cacheName);
|
|
317
307
|
|
|
308
|
+
if (process.env.NODE_ENV !== "production") {
|
|
309
|
+
// See https://github.com/GoogleChrome/workbox/issues/2818
|
|
310
|
+
const vary = response.headers.get("Vary");
|
|
311
|
+
if (vary && matchOptions?.ignoreVary !== true) {
|
|
312
|
+
logger.debug(
|
|
313
|
+
`The response for ${getFriendlyURL(
|
|
314
|
+
effectiveRequest.url,
|
|
315
|
+
)} has a 'Vary: ${vary}' header. Consider setting the {ignoreVary: true} option on your strategy to ensure cache matching and deletion works as expected.`,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
318
320
|
const hasCacheUpdateCallback = this.hasCallback("cacheDidUpdate");
|
|
319
321
|
const oldResponse = hasCacheUpdateCallback
|
|
320
322
|
? await cacheMatchIgnoreParams(
|
|
@@ -329,7 +331,7 @@ class StrategyHandler {
|
|
|
329
331
|
: null;
|
|
330
332
|
|
|
331
333
|
if (process.env.NODE_ENV !== "production") {
|
|
332
|
-
logger.debug(`Updating the '${cacheName}' cache with a new Response
|
|
334
|
+
logger.debug(`Updating the '${cacheName}' cache with a new Response for ${getFriendlyURL(effectiveRequest.url)}.`);
|
|
333
335
|
}
|
|
334
336
|
|
|
335
337
|
try {
|
|
@@ -379,8 +381,7 @@ class StrategyHandler {
|
|
|
379
381
|
mode,
|
|
380
382
|
request: effectiveRequest,
|
|
381
383
|
event: this.event,
|
|
382
|
-
|
|
383
|
-
params: this.params, // eslint-disable-line
|
|
384
|
+
params: this.params,
|
|
384
385
|
}),
|
|
385
386
|
);
|
|
386
387
|
}
|
|
@@ -541,5 +542,3 @@ class StrategyHandler {
|
|
|
541
542
|
return responseToCache;
|
|
542
543
|
}
|
|
543
544
|
}
|
|
544
|
-
|
|
545
|
-
export { StrategyHandler };
|