From 5164e43339f5445fd0ece38aed144b211c6cbc49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Dugu=C3=A9?= Date: Fri, 15 Sep 2023 16:40:26 +0200 Subject: [PATCH 1/2] feat(chore): cleanup and bump deps Signed-off-by: joris --- index.js | 10 +++------- package.json | 11 ++++++----- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index dfc2184..cd8eea6 100644 --- a/index.js +++ b/index.js @@ -3,7 +3,7 @@ /* eslint no-prototype-builtins: 0 */ const fp = require('fastify-plugin') -const uidSafe = require('uid-safe') +const { sync } = require('uid-safe') const abstractCache = require('abstract-cache') const defaultOptions = { @@ -21,11 +21,7 @@ function cachingExpires (date) { } function etag (value, lifetime) { - if (value) { - this.header('ETag', value) - } else { - this.header('ETag', uidSafe.sync(18)) - } + this.header('ETag', value ?? sync(18)) this._etagLife = Number.isInteger(lifetime) ? lifetime : 3600000 return this } @@ -35,7 +31,7 @@ function etagHandleRequest (req, res, next) { const etag = req.headers['if-none-match'] this.cache.get({ id: etag, segment: this.cacheSegment }, (err, cached) => { if (err) return next(err) - if (cached && cached.item) { + if (cached?.item) { return res.status(304).send() } next() diff --git a/package.json b/package.json index 5ab366b..ba53724 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "types": "types/index.d.ts", "scripts": { "lint": "standard --verbose | snazzy", + "lint:fix": "standard --verbose --fix | snazzy", "test": "npm run test:unit && npm run test:typescript", "test:typescript": "tsd", "test:unit": "tap", @@ -33,16 +34,16 @@ "homepage": "https://github.com/fastify/fastify-caching#readme", "devDependencies": { "@fastify/pre-commit": "^2.0.2", - "@types/node": "^20.1.0", - "fastify": "^4.0.0-rc.3", + "@types/node": "^20.6.1", + "fastify": "^4.23.2", "snazzy": "^9.0.0", - "standard": "^17.0.0", - "tap": "^16.0.0", + "standard": "^17.1.0", + "tap": "^16.3.8", "tsd": "^0.29.0" }, "dependencies": { "abstract-cache": "^1.0.1", - "fastify-plugin": "^4.0.0", + "fastify-plugin": "^4.5.1", "uid-safe": "^2.1.5" }, "publishConfig": { From eac09fc13fb02ed26981408788a189c98324e081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joris=20Dugu=C3=A9?= Date: Fri, 15 Sep 2023 17:06:44 +0200 Subject: [PATCH 2/2] fix(ci): resolve problem with ci and implement missing cleanup Signed-off-by: joris --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index cd8eea6..832bd7a 100644 --- a/index.js +++ b/index.js @@ -21,7 +21,7 @@ function cachingExpires (date) { } function etag (value, lifetime) { - this.header('ETag', value ?? sync(18)) + this.header('ETag', value || sync(18)) this._etagLife = Number.isInteger(lifetime) ? lifetime : 3600000 return this } @@ -71,7 +71,7 @@ function fastifyCaching (instance, options, next) { } instance.addHook('onRequest', (req, res, next) => { - if (res.hasHeader('Cache-control') === false) { + if (!res.hasHeader('Cache-control')) { res.header('Cache-control', value) } next()