From 538bfdc307baeb6a068dd76890752e645d1e2127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Sat, 6 Jan 2024 20:35:08 +0000 Subject: [PATCH 1/5] [Snyk] Upgrade fastify from 4.24.3 to 4.25.0 (#104) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

This PR was automatically created by Snyk using the credentials of a real user.


Snyk has created this PR to upgrade fastify from 4.24.3 to 4.25.0.

:information_source: Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.
- The recommended version is **1 version** ahead of your current version. - The recommended version was released **22 days ago**, on 2023-12-13.
Release notes
Package name: fastify from fastify GitHub release notes
Commit messages
Package name: fastify
  • 635acc8 Bumped v4.25.0
  • b8f2d9e chore: remove unused type assertion (#5184)
  • 1b588a0 fix(#5049): Remove duplicated calls to onReady (#5051)
  • b3a0e67 types: nullish error types in callback function's parameter for `after` and `ready` method (#5191)
  • 7c778af chore: update process-warning (#5206)
  • cd84d13 fix(#5180): close secondary bindings after primary is closed (#5201)
  • 49b62f5 fix: allow async hooks in `RouteShorthandOptions` without breaking `request` and `reply` types (#5147)
  • e9764f3 ci: fix broken ci by skipping tests if node v > 18.19.0 (#5195)
  • 6dcd4b6 chore: Bump actions/github-script from 6 to 7 (#5183)
  • 85b0018 docs(ecosystem): add http-wizard (#5132)
  • b9336a3 ci: pin node 18 to 18.18.2 (#5197)
  • 49272d1 test: add tests for TOC of errors.md (#5194)
  • 5e23534 types: added http header types to reply (#5046)
  • f2be4c5 docs: update preHandler hook example (#5189)
  • 5d29f5c docs(ecosystem): adds @ blastorg/fastify/aws-dynamodb-cache to community plugins list (#5158)
  • 84ad944 Update reply.context deprecation warning (#5179)
  • d61f384 docs(ecosystem): Add Apitally (#5175)
  • b1b44fc chore: gitpodify (#5168)
  • 7a134b5 Fix: small typo in docs
  • f808f96 fix: type FastifyInstance['route'] and RouteShorthandMethod (#5155)
  • 1891f24 docs(reference/hooks): add information about prehandler (#5163)
  • 9ab24be docs(#5142): aligned errors and warnings documentation (#5162)
  • 6a337b0 docs: clarify handling of streams and buffers (#5166)
  • 99a405a docs: removed unmaintained fastify-nodemailer from ecosystem
Compare

**Note:** *You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.* For more information: 🧐 [View latest project report](https://app.snyk.io/org/jlenon7/project/f15ac352-d8b8-407e-9f29-b569d1087684?utm_source=github&utm_medium=referral&page=upgrade-pr) 🛠 [Adjust upgrade PR settings](https://app.snyk.io/org/jlenon7/project/f15ac352-d8b8-407e-9f29-b569d1087684/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr) 🔕 [Ignore this dependency or unsubscribe from future upgrade PRs](https://app.snyk.io/org/jlenon7/project/f15ac352-d8b8-407e-9f29-b569d1087684/settings/integration?pkg=fastify&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades) Co-authored-by: snyk-bot --- package-lock.json | 36 +++++++++++++++++++++++------------- package.json | 2 +- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index fcd4026..a1d1f75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "change-case": "^4.1.2", "collect.js": "^4.36.1", "execa": "^8.0.1", - "fastify": "^4.24.3", + "fastify": "^4.25.0", "got": "^12.6.1", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", @@ -4412,9 +4412,9 @@ "integrity": "sha512-cIusKBIt/R/oI6z/1nyfe2FvGKVTohVRfvkOhvx0nCEW+xf5NoCXjAHcWp93uOUBchzYcsvPlrapAdX1uW+YGg==" }, "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.0", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.25.0.tgz", + "integrity": "sha512-2XANZZDadl/PccnVbmrIC8BmUtb16MO5Hyfnqv1cZIslvf7GYTVwlPuVxLKL23NNxWRc5BikY8HyhWj+NJvokA==", "dependencies": { "@fastify/ajv-compiler": "^3.5.0", "@fastify/error": "^3.4.0", @@ -4425,8 +4425,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", @@ -4439,6 +4439,11 @@ "resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-4.5.1.tgz", "integrity": "sha512-stRHYGeuqpEZTL1Ef0Ovr2ltazUT9g844X5z/zEBFLG8RYlpDiOCIG+ATvYEp+/zmc7sN29mcIMp8gvYplYPIQ==" }, + "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==" + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -7888,16 +7893,16 @@ } }, "node_modules/pino": { - "version": "8.16.2", - "resolved": "https://registry.npmjs.org/pino/-/pino-8.16.2.tgz", - "integrity": "sha512-2advCDGVEvkKu9TTVSa/kWW7Z3htI/sBKEZpqiHk6ive0i/7f5b1rsU8jn0aimxqfnSz5bj/nOYkwhBUn5xxvg==", + "version": "8.17.2", + "resolved": "https://registry.npmjs.org/pino/-/pino-8.17.2.tgz", + "integrity": "sha512-LA6qKgeDMLr2ux2y/YiUt47EfgQ+S9LznBWOJdN3q1dx2sv0ziDLUBeVpyVv17TEcGCBuWf0zNtg3M5m1NhhWQ==", "dependencies": { "atomic-sleep": "^1.0.0", "fast-redact": "^3.1.1", "on-exit-leak-free": "^2.1.0", "pino-abstract-transport": "v1.1.0", "pino-std-serializers": "^6.0.0", - "process-warning": "^2.0.0", + "process-warning": "^3.0.0", "quick-format-unescaped": "^4.0.3", "real-require": "^0.2.0", "safe-stable-stringify": "^2.3.1", @@ -7941,9 +7946,9 @@ } }, "node_modules/pino-abstract-transport/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.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz", + "integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==", "dependencies": { "abort-controller": "^3.0.0", "buffer": "^6.0.3", @@ -7968,6 +7973,11 @@ "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-6.2.2.tgz", "integrity": "sha512-cHjPPsE+vhj/tnhCy/wiMh3M3z3h/j15zHQX+S9GkTBgqJuTuJzYJ4gUyACLhDaJ7kk9ba9iRDmbH2tJU03OiA==" }, + "node_modules/pino/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==" + }, "node_modules/pkg-dir": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz", diff --git a/package.json b/package.json index 0834d7e..8e34c52 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "change-case": "^4.1.2", "collect.js": "^4.36.1", "execa": "^8.0.1", - "fastify": "^4.24.3", + "fastify": "^4.25.0", "got": "^12.6.1", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", From 1e4fca4208d52a2fa5d30861eb3fdad308853ecb Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Sat, 6 Jan 2024 20:37:41 +0000 Subject: [PATCH 2/5] chore(npm): update dependencies --- package-lock.json | 58 +++++++++++++++++++++++------------------------ package.json | 4 ++-- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/package-lock.json b/package-lock.json index a1d1f75..641db31 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "4.25.0", + "version": "4.26.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "4.25.0", + "version": "4.26.0", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", @@ -35,7 +35,7 @@ "youch-terminal": "^2.2.2" }, "devDependencies": { - "@athenna/test": "^4.16.0", + "@athenna/test": "^4.17.0", "@athenna/tsconfig": "^4.12.0", "@types/bytes": "^3.1.1", "@types/callsite": "^1.0.31", @@ -103,15 +103,15 @@ "dev": true }, "node_modules/@athenna/test": { - "version": "4.16.0", - "resolved": "https://registry.npmjs.org/@athenna/test/-/test-4.16.0.tgz", - "integrity": "sha512-NK3HHivJP9ao9A0uGaIfdvfXdC9bM0N6vlR7WwQ7/LWndb3EQpLTpwOzH6a/n822NzVS+at/2eNFODLl3ger2w==", + "version": "4.17.0", + "resolved": "https://registry.npmjs.org/@athenna/test/-/test-4.17.0.tgz", + "integrity": "sha512-NRYXxjDf8+owgUZmrp217L68E4oVI7lnHEAohsAtKuwjPvqXtTxDKLYO8AviB+QOPo0zUFr6X0mMkNVGLH5MCA==", "dev": true, "dependencies": { "@japa/assert": "^2.1.0", "@japa/runner": "^3.1.1", "@types/sinon": "^10.0.20", - "c8": "^8.0.1", + "c8": "^9.0.0", "sinon": "^15.1.0" }, "engines": { @@ -2482,19 +2482,18 @@ } }, "node_modules/c8": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/c8/-/c8-8.0.1.tgz", - "integrity": "sha512-EINpopxZNH1mETuI0DzRA4MZpAUH+IFiRhnmFD3vFr3vdrgxqi3VfE3KL0AIL+zDq8rC9bZqwM/VDmmoe04y7w==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/c8/-/c8-9.0.0.tgz", + "integrity": "sha512-nFJhU2Cz6Frh2awk3IW7wwk3wx27/U2v8ojQCHGc1GWTCHS6aMu4lal327/ZnnYj7oSThGF1X3qUP1yzAJBcOQ==", "dev": true, "dependencies": { "@bcoe/v8-coverage": "^0.2.3", "@istanbuljs/schema": "^0.1.3", "find-up": "^5.0.0", - "foreground-child": "^2.0.0", + "foreground-child": "^3.1.1", "istanbul-lib-coverage": "^3.2.0", "istanbul-lib-report": "^3.0.1", "istanbul-reports": "^3.1.6", - "rimraf": "^3.0.2", "test-exclude": "^6.0.0", "v8-to-istanbul": "^9.0.0", "yargs": "^17.7.2", @@ -2504,19 +2503,20 @@ "c8": "bin/c8.js" }, "engines": { - "node": ">=12" + "node": ">=14.14.0" } }, - "node_modules/c8/node_modules/rimraf": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", - "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "node_modules/c8/node_modules/foreground-child": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.1.1.tgz", + "integrity": "sha512-TMKDUnIte6bfb5nWv7V/caI169OHgvwjb7V4WkeUvbQQdjr5rWKqHFiKWb/fcOwB+CzBT+qbWjvj+DVwRskpIg==", "dev": true, "dependencies": { - "glob": "^7.1.3" + "cross-spawn": "^7.0.0", + "signal-exit": "^4.0.1" }, - "bin": { - "rimraf": "bin.js" + "engines": { + "node": ">=14" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -6166,9 +6166,9 @@ } }, "node_modules/istanbul-lib-coverage": { - "version": "3.2.0", - "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.0.tgz", - "integrity": "sha512-eOeJ5BHCmHYvQK7xt9GkdHuzuCGS1Y6g9Gvnx3Ym33fz/HpLRYxiS0wHNr+m/MBC8B647Xt608vCDEvhl9c6Mw==", + "version": "3.2.2", + "resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz", + "integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==", "dev": true, "engines": { "node": ">=8" @@ -9671,9 +9671,9 @@ "dev": true }, "node_modules/v8-to-istanbul": { - "version": "9.1.3", - "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.1.3.tgz", - "integrity": "sha512-9lDD+EVI2fjFsMWXc6dy5JJzBsVTcQ2fVkfBvncZ6xJWG9wtBhOldG+mHkSL0+V1K/xgZz0JDO5UT5hFwHUghg==", + "version": "9.2.0", + "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.2.0.tgz", + "integrity": "sha512-/EH/sDgxU2eGxajKdwLCDmQ4FWq+kpi3uCmBGpw1xJtnAxEjlD8j8PEiGWpCIMIs3ciNAgH0d3TTJiUkYzyZjA==", "dev": true, "dependencies": { "@jridgewell/trace-mapping": "^0.3.12", @@ -9685,9 +9685,9 @@ } }, "node_modules/v8-to-istanbul/node_modules/@jridgewell/trace-mapping": { - "version": "0.3.19", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.19.tgz", - "integrity": "sha512-kf37QtfW+Hwx/buWGMPcR60iF9ziHa6r/CZJIHbmcm4+0qrXiVdxegAH0F6yddEVQ7zdkjcGCgCzUu+BcbhQxw==", + "version": "0.3.20", + "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.20.tgz", + "integrity": "sha512-R8LcPeWZol2zR8mmH3JeKQ6QRCFb7XgUhV9ZlGhHLGyg4wpPiPZNQOOWhFZhxKw8u//yTbNGI42Bx/3paXEQ+Q==", "dev": true, "dependencies": { "@jridgewell/resolve-uri": "^3.1.0", diff --git a/package.json b/package.json index 8e34c52..9becbf0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/common", - "version": "4.25.0", + "version": "4.26.0", "description": "The Athenna common helpers to use in any Node.js ESM project.", "license": "MIT", "author": "João Lenon ", @@ -80,7 +80,7 @@ "youch-terminal": "^2.2.2" }, "devDependencies": { - "@athenna/test": "^4.16.0", + "@athenna/test": "^4.17.0", "@athenna/tsconfig": "^4.12.0", "@types/bytes": "^3.1.1", "@types/callsite": "^1.0.31", From 87e10d2d0f1482d963c321212d050d1d60b2e34c Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Tue, 9 Jan 2024 15:52:12 +0000 Subject: [PATCH 3/5] chore(npm): update dependencies --- package-lock.json | 12 ++++++------ package.json | 4 ++-- src/globals/Array.ts | 33 ++++++++++++++++++++++++++++----- src/helpers/Collection.ts | 11 ++++++++++- tests/unit/CollectionTest.ts | 21 +++++++++++++++++++-- 5 files changed, 65 insertions(+), 16 deletions(-) diff --git a/package-lock.json b/package-lock.json index 641db31..bf952c7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "4.26.0", + "version": "4.27.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "4.26.0", + "version": "4.27.0", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", @@ -35,7 +35,7 @@ "youch-terminal": "^2.2.2" }, "devDependencies": { - "@athenna/test": "^4.17.0", + "@athenna/test": "^4.18.0", "@athenna/tsconfig": "^4.12.0", "@types/bytes": "^3.1.1", "@types/callsite": "^1.0.31", @@ -103,9 +103,9 @@ "dev": true }, "node_modules/@athenna/test": { - "version": "4.17.0", - "resolved": "https://registry.npmjs.org/@athenna/test/-/test-4.17.0.tgz", - "integrity": "sha512-NRYXxjDf8+owgUZmrp217L68E4oVI7lnHEAohsAtKuwjPvqXtTxDKLYO8AviB+QOPo0zUFr6X0mMkNVGLH5MCA==", + "version": "4.18.0", + "resolved": "https://registry.npmjs.org/@athenna/test/-/test-4.18.0.tgz", + "integrity": "sha512-HpW6XFZ5GqAd31mj2FB9H7eiBe+Wx/3DAEbiFcaf9JhGoi20GstbS2Bno4YAKv84NxsaLJgJxMZExjonu/uSuw==", "dev": true, "dependencies": { "@japa/assert": "^2.1.0", diff --git a/package.json b/package.json index 9becbf0..1f92593 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/common", - "version": "4.26.0", + "version": "4.27.0", "description": "The Athenna common helpers to use in any Node.js ESM project.", "license": "MIT", "author": "João Lenon ", @@ -80,7 +80,7 @@ "youch-terminal": "^2.2.2" }, "devDependencies": { - "@athenna/test": "^4.17.0", + "@athenna/test": "^4.18.0", "@athenna/tsconfig": "^4.12.0", "@types/bytes": "^3.1.1", "@types/callsite": "^1.0.31", diff --git a/src/globals/Array.ts b/src/globals/Array.ts index d23df1c..bb9a05d 100644 --- a/src/globals/Array.ts +++ b/src/globals/Array.ts @@ -13,25 +13,48 @@ export {} declare global { interface Array { + /** + * Call the toJSON method of each item + * inside the array. + */ + toAthennaJSON(): Record[] + /** * Call the toResource method of each item * inside the array. */ - toResource(criterias?: any): T[] + toAthennaResource(criterias?: any): T[] /** * Transform the array to an Athenna collection. */ - toCollection(): Collection + toAthennaCollection(): Collection } } // eslint-disable-next-line no-extend-native -Array.prototype.toResource = function (criterias = {}) { - return this.map(model => model.toResource(criterias)) +Array.prototype.toAthennaJSON = function () { + return this.map(model => { + if (model && model.toJSON) { + return model.toJSON() + } + + return null + }).filter(Boolean) +} + +// eslint-disable-next-line no-extend-native +Array.prototype.toAthennaResource = function (criterias = {}) { + return this.map(model => { + if (model && model.toResource) { + return model.toResource(criterias) + } + + return null + }).filter(Boolean) } // eslint-disable-next-line no-extend-native -Array.prototype.toCollection = function () { +Array.prototype.toAthennaCollection = function () { return new Collection(this) } diff --git a/src/helpers/Collection.ts b/src/helpers/Collection.ts index 9ac93c7..6a7ce0d 100644 --- a/src/helpers/Collection.ts +++ b/src/helpers/Collection.ts @@ -29,13 +29,22 @@ export class Collection extends CollectJS { return [...new Set(this.all())] } + /** + * Execute the toJSON method inside objects if exists. + */ + public toJSON(): Record[] { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + return this.all().toAthennaJSON() + } + /** * Execute the toResource method inside objects if exists. */ public toResource(criterias = {}): T[] { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore - return this.all().map(item => item.toResource(criterias)) + return this.all().toAthennaResource(criterias) } } diff --git a/tests/unit/CollectionTest.ts b/tests/unit/CollectionTest.ts index 2cc8790..12af9b2 100644 --- a/tests/unit/CollectionTest.ts +++ b/tests/unit/CollectionTest.ts @@ -25,17 +25,34 @@ export default class CollectionTest { assert.deepEqual(new Collection().test(), { hello: 'world' }) } + @Test() + public async shouldBeAbleToExecuteTheToJSONMethodInsideObjectsOfCollections({ assert }: Context) { + const models = [ + undefined, + {}, + { + toJSON: () => ({ id: 1 }) + } + ] + + assert.deepEqual(models.toAthennaJSON(), [{ id: 1 }]) + assert.deepEqual(models.toAthennaCollection().toJSON(), [{ id: 1 }]) + assert.deepEqual(new Collection(models).toJSON(), [{ id: 1 }]) + } + @Test() public async shouldBeAbleToExecuteTheToResourceMethodInsideObjectsOfCollections({ assert }: Context) { const models = [ + undefined, + {}, { toResource: () => ({ id: 1 }) }, { toResource: criterias => criterias } ] - assert.deepEqual(models.toResource({ id: 2 }), [{ id: 1 }, { id: 2 }]) - assert.deepEqual(models.toCollection().toResource({ id: 2 }), [{ id: 1 }, { id: 2 }]) + assert.deepEqual(models.toAthennaResource({ id: 2 }), [{ id: 1 }, { id: 2 }]) + assert.deepEqual(models.toAthennaCollection().toResource({ id: 2 }), [{ id: 1 }, { id: 2 }]) assert.deepEqual(new Collection(models).toResource({ id: 2 }), [{ id: 1 }, { id: 2 }]) } } From 1ba2e5be04741d85f989b5e08bc9a45355883dcf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lenon?= Date: Tue, 9 Jan 2024 20:14:23 +0000 Subject: [PATCH 4/5] [Snyk] Upgrade fastify from 4.25.0 to 4.25.1 (#106) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

This PR was automatically created by Snyk using the credentials of a real user.


Snyk has created this PR to upgrade fastify from 4.25.0 to 4.25.1.

:information_source: Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.
- The recommended version is **1 version** ahead of your current version. - The recommended version was released **23 days ago**, on 2023-12-15.
Release notes
Package name: fastify from fastify GitHub release notes
Commit messages
Package name: fastify
  • e3a07ea Bumped v4.25.1
  • af8bd46 chore: at-large project (#5211)
  • e495eaa fix: Better plugin name detection for FSTWRN002 (#5209)
  • 256fb2c fix: route constraints (#5207)
Compare

**Note:** *You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.* For more information: 🧐 [View latest project report](https://app.snyk.io/org/jlenon7/project/f15ac352-d8b8-407e-9f29-b569d1087684?utm_source=github&utm_medium=referral&page=upgrade-pr) 🛠 [Adjust upgrade PR settings](https://app.snyk.io/org/jlenon7/project/f15ac352-d8b8-407e-9f29-b569d1087684/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr) 🔕 [Ignore this dependency or unsubscribe from future upgrade PRs](https://app.snyk.io/org/jlenon7/project/f15ac352-d8b8-407e-9f29-b569d1087684/settings/integration?pkg=fastify&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades) Co-authored-by: snyk-bot --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index bf952c7..a44e6cc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,7 +16,7 @@ "change-case": "^4.1.2", "collect.js": "^4.36.1", "execa": "^8.0.1", - "fastify": "^4.25.0", + "fastify": "^4.25.1", "got": "^12.6.1", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", @@ -4412,9 +4412,9 @@ "integrity": "sha512-cIusKBIt/R/oI6z/1nyfe2FvGKVTohVRfvkOhvx0nCEW+xf5NoCXjAHcWp93uOUBchzYcsvPlrapAdX1uW+YGg==" }, "node_modules/fastify": { - "version": "4.25.0", - "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.25.0.tgz", - "integrity": "sha512-2XANZZDadl/PccnVbmrIC8BmUtb16MO5Hyfnqv1cZIslvf7GYTVwlPuVxLKL23NNxWRc5BikY8HyhWj+NJvokA==", + "version": "4.25.1", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.25.1.tgz", + "integrity": "sha512-D8d0rv61TwqoAS7lom2tvIlgVMlx88lLsiwXyWNjA7CU/LC/mx/Gp2WAlC0S/ABq19U+y/aRvYFG5xLUu2aMrg==", "dependencies": { "@fastify/ajv-compiler": "^3.5.0", "@fastify/error": "^3.4.0", diff --git a/package.json b/package.json index 1f92593..75497c5 100644 --- a/package.json +++ b/package.json @@ -61,7 +61,7 @@ "change-case": "^4.1.2", "collect.js": "^4.36.1", "execa": "^8.0.1", - "fastify": "^4.25.0", + "fastify": "^4.25.1", "got": "^12.6.1", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", From 1f485e1b3627bfc8e12a2afa3f8707511c1db57a Mon Sep 17 00:00:00 2001 From: jlenon7 Date: Wed, 10 Jan 2024 11:36:52 +0000 Subject: [PATCH 5/5] chore(exception): add details to exception --- package-lock.json | 12 ++++++------ package.json | 4 ++-- src/globals/Error.ts | 1 + src/helpers/Exception.ts | 23 ++++++++++++++++++++++- src/types/json/ExceptionJson.ts | 1 + tests/unit/ExceptionTest.ts | 25 +++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index bf952c7..6cafef9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@athenna/common", - "version": "4.27.0", + "version": "4.28.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@athenna/common", - "version": "4.27.0", + "version": "4.28.0", "license": "MIT", "dependencies": { "@fastify/formbody": "^7.4.0", @@ -16,7 +16,7 @@ "change-case": "^4.1.2", "collect.js": "^4.36.1", "execa": "^8.0.1", - "fastify": "^4.25.0", + "fastify": "^4.25.2", "got": "^12.6.1", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", @@ -4412,9 +4412,9 @@ "integrity": "sha512-cIusKBIt/R/oI6z/1nyfe2FvGKVTohVRfvkOhvx0nCEW+xf5NoCXjAHcWp93uOUBchzYcsvPlrapAdX1uW+YGg==" }, "node_modules/fastify": { - "version": "4.25.0", - "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.25.0.tgz", - "integrity": "sha512-2XANZZDadl/PccnVbmrIC8BmUtb16MO5Hyfnqv1cZIslvf7GYTVwlPuVxLKL23NNxWRc5BikY8HyhWj+NJvokA==", + "version": "4.25.2", + "resolved": "https://registry.npmjs.org/fastify/-/fastify-4.25.2.tgz", + "integrity": "sha512-SywRouGleDHvRh054onj+lEZnbC1sBCLkR0UY3oyJwjD4BdZJUrxBqfkfCaqn74pVCwBaRHGuL3nEWeHbHzAfw==", "dependencies": { "@fastify/ajv-compiler": "^3.5.0", "@fastify/error": "^3.4.0", diff --git a/package.json b/package.json index 1f92593..d9da340 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@athenna/common", - "version": "4.27.0", + "version": "4.28.0", "description": "The Athenna common helpers to use in any Node.js ESM project.", "license": "MIT", "author": "João Lenon ", @@ -61,7 +61,7 @@ "change-case": "^4.1.2", "collect.js": "^4.36.1", "execa": "^8.0.1", - "fastify": "^4.25.0", + "fastify": "^4.25.2", "got": "^12.6.1", "http-status-codes": "^2.2.0", "is-wsl": "^2.2.0", diff --git a/src/globals/Error.ts b/src/globals/Error.ts index b30e0be..9960dbb 100644 --- a/src/globals/Error.ts +++ b/src/globals/Error.ts @@ -30,6 +30,7 @@ Error.prototype.toAthennaException = function (options: ExceptionJson = {}) { options.stack = options.stack || this.stack options.message = options.message || this.message options.code = options.code || changeCase.constantCase(options.name) + options.details = options.details || this.details || this.errors return new Exception(options) } diff --git a/src/helpers/Exception.ts b/src/helpers/Exception.ts index 3f183b7..5f28e01 100644 --- a/src/helpers/Exception.ts +++ b/src/helpers/Exception.ts @@ -15,11 +15,13 @@ import YouchTerminal from 'youch-terminal' import { Color } from '#src/helpers/Color' import { Options } from '#src/helpers/Options' import type { ExceptionJson } from '#src/types' +import { Is } from '@athenna/common' export class Exception extends Error { public code?: string public help?: any public status?: number + public details?: any[] public isAthennaException = true /** @@ -46,6 +48,10 @@ export class Exception extends Error { this.help = options.help } + if (options.details) { + this.details = options.details + } + if (options.stack) { this.stack = options.stack } else { @@ -65,6 +71,7 @@ export class Exception extends Error { json.message = this.message if (this.help) json.help = this.help + if (this.details) json.details = this.details if (stack) json.stack = this.stack return json @@ -92,11 +99,24 @@ export class Exception extends Error { const separator = Color.cyan('-----') const helpKey = Color.gray.bold.bgGreen(' HELP ') + const detailsKey = Color.gray.bold.bgHex('#f18b0e')(' DETAILS ') const title = Color.gray.bold.bgRed(` ${this.code || this.name} `) let help = '' let message = `${title}\n\n${Color.apply(this.message)}` + if (this.details && this.details.length) { + message = `${message}\n\n${detailsKey}\n\n${this.details + .map(detail => { + if (Is.String(detail)) { + return Color.orange(Color.apply(detail)) + } + + return Color.orange(JSON.stringify(detail, null, 2)) + }) + .join('\n')}` + } + if (this.help && this.help !== '') { help = `${helpKey}\n\n ${Color.green( Color.apply(this.help) @@ -111,7 +131,8 @@ export class Exception extends Error { message, code: this.code, stack: this.stack, - status: this.status + status: this.status, + details: this.details }), {} ).toJSON() diff --git a/src/types/json/ExceptionJson.ts b/src/types/json/ExceptionJson.ts index 18a4bc1..dabb960 100644 --- a/src/types/json/ExceptionJson.ts +++ b/src/types/json/ExceptionJson.ts @@ -13,5 +13,6 @@ export interface ExceptionJson { status?: number message?: string help?: any + details?: any[] stack?: string } diff --git a/tests/unit/ExceptionTest.ts b/tests/unit/ExceptionTest.ts index cba8516..7f57289 100644 --- a/tests/unit/ExceptionTest.ts +++ b/tests/unit/ExceptionTest.ts @@ -75,6 +75,31 @@ export default class ExceptionTest { const prettyError = await exception.prettify() + console.log(prettyError) + + assert.isDefined(prettyError) + assert.typeOf(prettyError, 'string') + } + + @Test() + public async shouldBeAbleToPrettifyTheExceptionWithDetails({ assert }: Context) { + class InternalServerException extends Exception { + constructor(content = 'Internal Server Error.', status = 500) { + super({ + status, + message: content, + details: ['Machine error', 'Runtime error'], + code: 'E_RUNTIME_EXCEPTION', + help: 'Restart your computer, works always. 👍' + }) + } + } + + const exception = new InternalServerException() + const prettyError = await exception.prettify() + + console.log(prettyError) + assert.isDefined(prettyError) assert.typeOf(prettyError, 'string') }