From 7887c641423f6046116f556adb117d24dd4c69ce Mon Sep 17 00:00:00 2001 From: denbon05 Date: Mon, 18 Dec 2023 17:28:38 +0100 Subject: [PATCH] Upgrade pkgs Fix deprecation warning for using fastify request.routerPath Use CI workflow in publish file --- .github/workflows/ci.yml | 22 +++---- .github/workflows/npm.yml | 3 + README.md | 16 +++-- lib/helpers.ts | 8 +-- lib/index.ts | 1 + package-lock.json | 132 +++++++++++++++++++++++++++----------- package.json | 9 +-- tsconfig.json | 4 -- 8 files changed, 126 insertions(+), 69 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 27bab6c..0c09d73 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,19 +1,18 @@ -name: Node CI +name: CI on: + workflow_call: pull_request: branches: - main - push: - branches: - - main jobs: - build: - runs-on: ubuntu-latest + run-checks: + runs-on: ${{ matrix.os }} strategy: matrix: + os: [ubuntu-latest] # only LTS versions node-version: [16.x, 18.x, 20.x] @@ -28,11 +27,12 @@ jobs: - run: npm run build - run: npm run lint - run: npm test - - name: Check fastify v3 compatibility - run: | - npm i -D fastify@3 - npm run build - npm test + # TODO uncomment with Fastify v5 dependency + # - name: Check fastify v4 compatibility + # run: | + # npm i -D fastify@4 + # npm run build + # npm test - name: Test & publish code coverage if: ${{ github.ref == 'refs/heads/main' || github.actor == 'dependabot[bot]' }} diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml index e3b7d2e..2fc773f 100644 --- a/.github/workflows/npm.yml +++ b/.github/workflows/npm.yml @@ -5,6 +5,9 @@ on: types: [created] jobs: + ci: + uses: denbon05/fastify-lcache/.github/workflows/ci.yml@main + publish: runs-on: ubuntu-latest diff --git a/README.md b/README.md index bf094c2..d0b75b2 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,7 @@ [![Test Coverage](https://api.codeclimate.com/v1/badges/6dfec3501aa3eb441bab/test_coverage)](https://codeclimate.com/github/denbon05/fastify-lcache/test_coverage)

fastify-lcache plugin for Fastify for memorize -data on first request and use next time until ttl expires

- -

Supports Fastify version since ^3

+data on first request and use it next time until ttl expires

```bash npm i fastify-lcache @@ -49,7 +47,7 @@ axios.get(url); ```
-
IMPORTANT
+
⚠️ IMPORTANT
Restarting your app resets the cache
@@ -72,9 +70,6 @@ axios.get(url);

app.lcache available inside your app

```ts -// you can specify payload data type: -// app.lcache.get<{ name: string }>('person') - interface CachedResponse { payload: T; headers?: { [key: string]: string | number | string[] }; @@ -98,3 +93,10 @@ interface IStorage { destroy(): void; } ``` + +### Fastify version compatibility + +| Fastify | lcache | +| :-----: | :----: | +| 3-4.9 | 1-1.2 | +| ^4.10 | 2.x | diff --git a/lib/helpers.ts b/lib/helpers.ts index bfad1f9..45c4f5a 100644 --- a/lib/helpers.ts +++ b/lib/helpers.ts @@ -1,4 +1,3 @@ -/* eslint-disable import/prefer-default-export */ import type { FastifyRequest } from 'fastify'; import type { RequestMethod, @@ -12,7 +11,7 @@ export const formatOptions = (opts: ICacheOptions): ICachePluginOptions => ({ ...opts, methodsToCache: new Set(opts.methodsToCache), statusesToCache: new Set(opts.statusesToCache), - excludeRoutes: new Set(opts.excludeRoutes?.map((r) => r.trim())), + excludeRoutes: new Set(opts.excludeRoutes?.map((route) => route.trim())), ttl: getMilliseconds(opts.ttlInMinutes), }); @@ -22,12 +21,11 @@ export const shouldBeCached = ( statusCode: number ): boolean => { const { methodsToCache, statusesToCache, excludeRoutes } = opts; - // TODO use routeOptions.url - test compatibility - const { routerPath, method } = request; + const { method, routeOptions } = request; return ( methodsToCache.has(method as RequestMethod) && statusesToCache.has(statusCode) && - !excludeRoutes.has(routerPath) + !excludeRoutes.has(routeOptions.url) ); }; diff --git a/lib/index.ts b/lib/index.ts index 60df679..9e12383 100644 --- a/lib/index.ts +++ b/lib/index.ts @@ -63,6 +63,7 @@ const cache: FastifyPluginCallback = ( const lcache = fp(cache, { name: '@fastify/lcache', + fastify: '>=4.10', }); /** diff --git a/package-lock.json b/package-lock.json index b37f300..e85cf0b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "fastify-lcache", - "version": "1.2.2", + "version": "2.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fastify-lcache", - "version": "1.2.2", + "version": "2.0.0", "license": "MIT", "dependencies": { "fastify-plugin": "^3.0.1" @@ -21,8 +21,9 @@ "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-typescript": "^2.7.1", "eslint-plugin-import": "^2.26.0", - "fastify": "^4.24.3", + "fastify": "^4.25.1", "jest": "^28.1.1", + "prettier": "^3.1.1", "ts-jest": "^28.0.4", "ts-node": "^10.8.1", "typescript": "^5.2.2" @@ -31,7 +32,7 @@ "node": ">=16.x" }, "peerDependencies": { - "fastify": ">=3.0.0" + "fastify": ">=4.10.0" } }, "node_modules/@aashutoshrathi/word-wrap": { @@ -3175,9 +3176,9 @@ "dev": true }, "node_modules/fast-json-stringify": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.8.0.tgz", - "integrity": "sha512-VVwK8CFMSALIvt14U8AvrSzQAwN/0vaVRiFFUVlpnXSnDGrSkOAO5MtzyN8oQNjLd5AqTW5OZRgyjoNuAuR3jQ==", + "version": "5.9.1", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.9.1.tgz", + "integrity": "sha512-NMrf+uU9UJnTzfxaumMDXK1NWqtPCfGoM9DYIE+ESlaTQqjlANFBy0VAbsm6FB88Mx0nceyi18zTo5kIEUlzxg==", "dev": true, "dependencies": { "@fastify/deepmerge": "^1.0.0", @@ -3185,6 +3186,7 @@ "ajv-formats": "^2.1.1", "fast-deep-equal": "^3.1.3", "fast-uri": "^2.1.0", + "json-schema-ref-resolver": "^1.0.1", "rfdc": "^1.2.0" } }, @@ -3241,9 +3243,9 @@ "dev": true }, "node_modules/fastify": { - "version": "4.24.3", - "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.24.3.tgz", - "integrity": "sha512-6HHJ+R2x2LS3y1PqxnwEIjOTZxFl+8h4kSC/TuDPXtA+v2JnV9yEtOsNSKK1RMD7sIR2y1ZsA4BEFaid/cK5pg==", + "version": "4.25.1", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.25.1.tgz", + "integrity": "sha512-D8d0rv61TwqoAS7lom2tvIlgVMlx88lLsiwXyWNjA7CU/LC/mx/Gp2WAlC0S/ABq19U+y/aRvYFG5xLUu2aMrg==", "dev": true, "dependencies": { "@fastify/ajv-compiler": "^3.5.0", @@ -3255,8 +3257,8 @@ "fast-json-stringify": "^5.8.0", "find-my-way": "^7.7.0", "light-my-request": "^5.11.0", - "pino": "^8.16.0", - "process-warning": "^2.2.0", + "pino": "^8.17.0", + "process-warning": "^3.0.0", "proxy-addr": "^2.0.7", "rfdc": "^1.3.0", "secure-json-parse": "^2.7.0", @@ -3269,6 +3271,12 @@ "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-3.0.1.tgz", "integrity": "sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA==" }, + "node_modules/fastify/node_modules/process-warning": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-3.0.0.tgz", + "integrity": "sha512-mqn0kFRl0EoqhnL0GQ0veqFHyIN1yig9RHh/InzORTUiZHFRAur+aMtRkELNwGs9aNwKS6tg/An4NYBPGwvtzQ==", + "dev": true + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -4761,6 +4769,15 @@ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", "dev": true }, + "node_modules/json-schema-ref-resolver": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-schema-ref-resolver/-/json-schema-ref-resolver-1.0.1.tgz", + "integrity": "sha512-EJAj1pgHc1hxF6vo2Z3s69fMjO1INq6eGHXZ8Z6wCQeldCuwxGK9Sxf4/cScGn3FZubCVUehfWtcDM/PLteCQw==", + "dev": true, + "dependencies": { + "fast-deep-equal": "^3.1.3" + } + }, "node_modules/json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -5284,9 +5301,9 @@ } }, "node_modules/pino": { - "version": "8.16.1", - "resolved": "https://registry.npmjs.org/pino/-/pino-8.16.1.tgz", - "integrity": "sha512-3bKsVhBmgPjGV9pyn4fO/8RtoVDR8ssW1ev819FsRXlRNgW8gR/9Kx+gCK4UPWd4JjrRDLWpzd/pb1AyWm3MGA==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/pino/-/pino-8.17.1.tgz", + "integrity": "sha512-YoN7/NJgnsJ+fkADZqjhRt96iepWBndQHeClmSBH0sQWCb8zGD74t00SK4eOtKFi/f8TUmQnfmgglEhd2kI1RQ==", "dev": true, "dependencies": { "atomic-sleep": "^1.0.0", @@ -5403,6 +5420,21 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "28.1.3", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.1.3.tgz", @@ -5513,9 +5545,9 @@ "dev": true }, "node_modules/readable-stream": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.2.tgz", - "integrity": "sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.1.tgz", + "integrity": "sha512-uQjbf34vmf/asGnOHQEw07Q4llgMACQZTWWa4MmICS0IKJoHbLwKCy71H3eR99Dw5iYejc6W+pqZZEeqRtUFAw==", "dev": true, "dependencies": { "abort-controller": "^3.0.0", @@ -6159,9 +6191,9 @@ } }, "node_modules/toad-cache": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.3.0.tgz", - "integrity": "sha512-3oDzcogWGHZdkwrHyvJVpPjA7oNzY6ENOV3PsWJY9XYPZ6INo94Yd47s5may1U+nleBPwDhrRiTPMIvKaa3MQg==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.4.1.tgz", + "integrity": "sha512-T0m3MxP3wcqW0LaV3dF1mHBU294sgYSm4FOpa5eEJaYO7PqJZBOjZEQI1y4YaKNnih1FXCEYTWDS9osCoTUefg==", "dev": true, "engines": { "node": ">=12" @@ -9019,9 +9051,9 @@ "dev": true }, "fast-json-stringify": { - "version": "5.8.0", - "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.8.0.tgz", - "integrity": "sha512-VVwK8CFMSALIvt14U8AvrSzQAwN/0vaVRiFFUVlpnXSnDGrSkOAO5MtzyN8oQNjLd5AqTW5OZRgyjoNuAuR3jQ==", + "version": "5.9.1", + "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-5.9.1.tgz", + "integrity": "sha512-NMrf+uU9UJnTzfxaumMDXK1NWqtPCfGoM9DYIE+ESlaTQqjlANFBy0VAbsm6FB88Mx0nceyi18zTo5kIEUlzxg==", "dev": true, "requires": { "@fastify/deepmerge": "^1.0.0", @@ -9029,6 +9061,7 @@ "ajv-formats": "^2.1.1", "fast-deep-equal": "^3.1.3", "fast-uri": "^2.1.0", + "json-schema-ref-resolver": "^1.0.1", "rfdc": "^1.2.0" }, "dependencies": { @@ -9080,9 +9113,9 @@ "dev": true }, "fastify": { - "version": "4.24.3", - "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.24.3.tgz", - "integrity": "sha512-6HHJ+R2x2LS3y1PqxnwEIjOTZxFl+8h4kSC/TuDPXtA+v2JnV9yEtOsNSKK1RMD7sIR2y1ZsA4BEFaid/cK5pg==", + "version": "4.25.1", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.25.1.tgz", + "integrity": "sha512-D8d0rv61TwqoAS7lom2tvIlgVMlx88lLsiwXyWNjA7CU/LC/mx/Gp2WAlC0S/ABq19U+y/aRvYFG5xLUu2aMrg==", "dev": true, "requires": { "@fastify/ajv-compiler": "^3.5.0", @@ -9094,13 +9127,21 @@ "fast-json-stringify": "^5.8.0", "find-my-way": "^7.7.0", "light-my-request": "^5.11.0", - "pino": "^8.16.0", - "process-warning": "^2.2.0", + "pino": "^8.17.0", + "process-warning": "^3.0.0", "proxy-addr": "^2.0.7", "rfdc": "^1.3.0", "secure-json-parse": "^2.7.0", "semver": "^7.5.4", "toad-cache": "^3.3.0" + }, + "dependencies": { + "process-warning": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/process-warning/-/process-warning-3.0.0.tgz", + "integrity": "sha512-mqn0kFRl0EoqhnL0GQ0veqFHyIN1yig9RHh/InzORTUiZHFRAur+aMtRkELNwGs9aNwKS6tg/An4NYBPGwvtzQ==", + "dev": true + } } }, "fastify-plugin": { @@ -10188,6 +10229,15 @@ "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", "dev": true }, + "json-schema-ref-resolver": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json-schema-ref-resolver/-/json-schema-ref-resolver-1.0.1.tgz", + "integrity": "sha512-EJAj1pgHc1hxF6vo2Z3s69fMjO1INq6eGHXZ8Z6wCQeldCuwxGK9Sxf4/cScGn3FZubCVUehfWtcDM/PLteCQw==", + "dev": true, + "requires": { + "fast-deep-equal": "^3.1.3" + } + }, "json-schema-traverse": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", @@ -10582,9 +10632,9 @@ "dev": true }, "pino": { - "version": "8.16.1", - "resolved": "https://registry.npmjs.org/pino/-/pino-8.16.1.tgz", - "integrity": "sha512-3bKsVhBmgPjGV9pyn4fO/8RtoVDR8ssW1ev819FsRXlRNgW8gR/9Kx+gCK4UPWd4JjrRDLWpzd/pb1AyWm3MGA==", + "version": "8.17.1", + "resolved": "https://registry.npmjs.org/pino/-/pino-8.17.1.tgz", + "integrity": "sha512-YoN7/NJgnsJ+fkADZqjhRt96iepWBndQHeClmSBH0sQWCb8zGD74t00SK4eOtKFi/f8TUmQnfmgglEhd2kI1RQ==", "dev": true, "requires": { "atomic-sleep": "^1.0.0", @@ -10676,6 +10726,12 @@ "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==", "dev": true }, + "prettier": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.1.1.tgz", + "integrity": "sha512-22UbSzg8luF4UuZtzgiUOfcGM8s4tjBv6dJRT7j275NXsy2jb4aJa4NNveul5x4eqlF1wuhuR2RElK71RvmVaw==", + "dev": true + }, "pretty-format": { "version": "28.1.3", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-28.1.3.tgz", @@ -10753,9 +10809,9 @@ "dev": true }, "readable-stream": { - "version": "4.4.2", - "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.4.2.tgz", - "integrity": "sha512-Lk/fICSyIhodxy1IDK2HazkeGjSmezAWX2egdtJnYhtzKEsBPJowlI6F6LPb5tqIQILrMbx22S5o3GuJavPusA==", + "version": "4.5.1", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.1.tgz", + "integrity": "sha512-uQjbf34vmf/asGnOHQEw07Q4llgMACQZTWWa4MmICS0IKJoHbLwKCy71H3eR99Dw5iYejc6W+pqZZEeqRtUFAw==", "dev": true, "requires": { "abort-controller": "^3.0.0", @@ -11223,9 +11279,9 @@ } }, "toad-cache": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.3.0.tgz", - "integrity": "sha512-3oDzcogWGHZdkwrHyvJVpPjA7oNzY6ENOV3PsWJY9XYPZ6INo94Yd47s5may1U+nleBPwDhrRiTPMIvKaa3MQg==", + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.4.1.tgz", + "integrity": "sha512-T0m3MxP3wcqW0LaV3dF1mHBU294sgYSm4FOpa5eEJaYO7PqJZBOjZEQI1y4YaKNnih1FXCEYTWDS9osCoTUefg==", "dev": true }, "ts-jest": { diff --git a/package.json b/package.json index 78ba4e3..3aef8ef 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fastify-lcache", - "version": "1.2.2", + "version": "2.0.0", "description": "Light cache plugin for fastify", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -32,7 +32,7 @@ "node": ">=16.x" }, "peerDependencies": { - "fastify": ">=3.0.0" + "fastify": ">=4.10.0" }, "devDependencies": { "@types/jest": "^28.1.1", @@ -44,8 +44,9 @@ "eslint-config-prettier": "^9.0.0", "eslint-import-resolver-typescript": "^2.7.1", "eslint-plugin-import": "^2.26.0", - "fastify": "^4.24.3", + "fastify": "^4.25.1", "jest": "^28.1.1", + "prettier": "^3.1.1", "ts-jest": "^28.0.4", "ts-node": "^10.8.1", "typescript": "^5.2.2" @@ -53,4 +54,4 @@ "dependencies": { "fastify-plugin": "^3.0.1" } -} \ No newline at end of file +} diff --git a/tsconfig.json b/tsconfig.json index fee104e..61f9392 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,10 +8,6 @@ "outDir": "dist", "resolveJsonModule": true, "declaration": true, - "typeRoots": [ - "./node_modules/@types", - "./lib/types" - ], "types": [ "node", "jest"