@serwist/expiration 8.3.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 CHANGED
@@ -154,7 +154,7 @@ const normalizeURL = (unNormalizedUrl)=>{
154
154
  // Creating an ID from the URL and cache name won't be necessary once
155
155
  // Edge switches to Chromium and all browsers we support work with
156
156
  // array keyPaths.
157
- return this._cacheName + "|" + normalizeURL(url);
157
+ return `${this._cacheName}|${normalizeURL(url)}`;
158
158
  }
159
159
  /**
160
160
  * Returns an open connection to the database.
@@ -245,10 +245,12 @@ const normalizeURL = (unNormalizedUrl)=>{
245
245
  if (urlsExpired.length > 0) {
246
246
  internal.logger.groupCollapsed(`Expired ${urlsExpired.length} ` + `${urlsExpired.length === 1 ? "entry" : "entries"} and removed ` + `${urlsExpired.length === 1 ? "it" : "them"} from the ` + `'${this._cacheName}' cache.`);
247
247
  internal.logger.log(`Expired the following ${urlsExpired.length === 1 ? "URL" : "URLs"}:`);
248
- urlsExpired.forEach((url)=>internal.logger.log(` ${url}`));
248
+ for (const url of urlsExpired){
249
+ internal.logger.log(` ${url}`);
250
+ }
249
251
  internal.logger.groupEnd();
250
252
  } else {
251
- internal.logger.debug(`Cache expiration ran and found no entries to remove.`);
253
+ internal.logger.debug("Cache expiration ran and found no entries to remove.");
252
254
  }
253
255
  }
254
256
  this._isRunning = false;
@@ -287,17 +289,16 @@ const normalizeURL = (unNormalizedUrl)=>{
287
289
  */ async isURLExpired(url) {
288
290
  if (!this._maxAgeSeconds) {
289
291
  if (process.env.NODE_ENV !== "production") {
290
- throw new internal.SerwistError(`expired-test-without-max-age`, {
292
+ throw new internal.SerwistError("expired-test-without-max-age", {
291
293
  methodName: "isURLExpired",
292
294
  paramName: "maxAgeSeconds"
293
295
  });
294
296
  }
295
297
  return false;
296
- } else {
297
- const timestamp = await this._timestampModel.getTimestamp(url);
298
- const expireOlderThan = Date.now() - this._maxAgeSeconds * 1000;
299
- return timestamp !== undefined ? timestamp < expireOlderThan : true;
300
298
  }
299
+ const timestamp = await this._timestampModel.getTimestamp(url);
300
+ const expireOlderThan = Date.now() - this._maxAgeSeconds * 1000;
301
+ return timestamp !== undefined ? timestamp < expireOlderThan : true;
301
302
  }
302
303
  /**
303
304
  * Removes the IndexedDB object store used to keep track of cache expiration
@@ -418,7 +419,7 @@ const normalizeURL = (unNormalizedUrl)=>{
418
419
  if (process.env.NODE_ENV !== "production") {
419
420
  // The event may not be a fetch event; only log the URL if it is.
420
421
  if ("request" in event) {
421
- internal.logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache entry for ` + `'${internal.getFriendlyURL(event.request.url)}'.`);
422
+ internal.logger.warn(`Unable to ensure service worker stays alive when updating cache entry for '${internal.getFriendlyURL(event.request.url)}'.`);
422
423
  }
423
424
  }
424
425
  }
@@ -463,7 +464,7 @@ const normalizeURL = (unNormalizedUrl)=>{
463
464
  const headerTime = parsedDate.getTime();
464
465
  // If the Date header was invalid for some reason, parsedDate.getTime()
465
466
  // will return NaN.
466
- if (isNaN(headerTime)) {
467
+ if (Number.isNaN(headerTime)) {
467
468
  return null;
468
469
  }
469
470
  return headerTime;
package/dist/index.js CHANGED
@@ -152,7 +152,7 @@ const normalizeURL = (unNormalizedUrl)=>{
152
152
  // Creating an ID from the URL and cache name won't be necessary once
153
153
  // Edge switches to Chromium and all browsers we support work with
154
154
  // array keyPaths.
155
- return this._cacheName + "|" + normalizeURL(url);
155
+ return `${this._cacheName}|${normalizeURL(url)}`;
156
156
  }
157
157
  /**
158
158
  * Returns an open connection to the database.
@@ -243,10 +243,12 @@ const normalizeURL = (unNormalizedUrl)=>{
243
243
  if (urlsExpired.length > 0) {
244
244
  logger.groupCollapsed(`Expired ${urlsExpired.length} ` + `${urlsExpired.length === 1 ? "entry" : "entries"} and removed ` + `${urlsExpired.length === 1 ? "it" : "them"} from the ` + `'${this._cacheName}' cache.`);
245
245
  logger.log(`Expired the following ${urlsExpired.length === 1 ? "URL" : "URLs"}:`);
246
- urlsExpired.forEach((url)=>logger.log(` ${url}`));
246
+ for (const url of urlsExpired){
247
+ logger.log(` ${url}`);
248
+ }
247
249
  logger.groupEnd();
248
250
  } else {
249
- logger.debug(`Cache expiration ran and found no entries to remove.`);
251
+ logger.debug("Cache expiration ran and found no entries to remove.");
250
252
  }
251
253
  }
252
254
  this._isRunning = false;
@@ -285,17 +287,16 @@ const normalizeURL = (unNormalizedUrl)=>{
285
287
  */ async isURLExpired(url) {
286
288
  if (!this._maxAgeSeconds) {
287
289
  if (process.env.NODE_ENV !== "production") {
288
- throw new SerwistError(`expired-test-without-max-age`, {
290
+ throw new SerwistError("expired-test-without-max-age", {
289
291
  methodName: "isURLExpired",
290
292
  paramName: "maxAgeSeconds"
291
293
  });
292
294
  }
293
295
  return false;
294
- } else {
295
- const timestamp = await this._timestampModel.getTimestamp(url);
296
- const expireOlderThan = Date.now() - this._maxAgeSeconds * 1000;
297
- return timestamp !== undefined ? timestamp < expireOlderThan : true;
298
296
  }
297
+ const timestamp = await this._timestampModel.getTimestamp(url);
298
+ const expireOlderThan = Date.now() - this._maxAgeSeconds * 1000;
299
+ return timestamp !== undefined ? timestamp < expireOlderThan : true;
299
300
  }
300
301
  /**
301
302
  * Removes the IndexedDB object store used to keep track of cache expiration
@@ -416,7 +417,7 @@ const normalizeURL = (unNormalizedUrl)=>{
416
417
  if (process.env.NODE_ENV !== "production") {
417
418
  // The event may not be a fetch event; only log the URL if it is.
418
419
  if ("request" in event) {
419
- logger.warn(`Unable to ensure service worker stays alive when ` + `updating cache entry for ` + `'${getFriendlyURL(event.request.url)}'.`);
420
+ logger.warn(`Unable to ensure service worker stays alive when updating cache entry for '${getFriendlyURL(event.request.url)}'.`);
420
421
  }
421
422
  }
422
423
  }
@@ -461,7 +462,7 @@ const normalizeURL = (unNormalizedUrl)=>{
461
462
  const headerTime = parsedDate.getTime();
462
463
  // If the Date header was invalid for some reason, parsedDate.getTime()
463
464
  // will return NaN.
464
- if (isNaN(headerTime)) {
465
+ if (Number.isNaN(headerTime)) {
465
466
  return null;
466
467
  }
467
468
  return headerTime;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@serwist/expiration",
3
- "version": "8.3.0",
3
+ "version": "8.4.1",
4
4
  "type": "module",
5
5
  "description": "A service worker helper library that expires cached responses based on age or maximum number of entries.",
6
6
  "files": [
@@ -18,7 +18,7 @@
18
18
  "license": "MIT",
19
19
  "repository": "serwist/serwist",
20
20
  "bugs": "https://github.com/serwist/serwist/issues",
21
- "homepage": "https://serwist.vercel.app",
21
+ "homepage": "https://serwist.pages.dev",
22
22
  "module": "./dist/index.js",
23
23
  "main": "./dist/index.cjs",
24
24
  "types": "./dist/index.d.ts",
@@ -37,15 +37,16 @@
37
37
  },
38
38
  "dependencies": {
39
39
  "idb": "8.0.0",
40
- "@serwist/core": "8.3.0"
40
+ "@serwist/core": "8.4.1"
41
41
  },
42
42
  "devDependencies": {
43
43
  "rollup": "4.9.1",
44
- "@serwist/constants": "8.3.0"
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
- "lint": "eslint src --ext ts,tsx,js,jsx,cjs,mjs",
48
+ "dev": "rollup --config rollup.config.js --watch",
49
+ "lint": "biome lint ./src",
49
50
  "typecheck": "tsc"
50
51
  }
51
52
  }