From e5b2188a634db46740912d9f6d54a914805f8d95 Mon Sep 17 00:00:00 2001 From: will Farrell Date: Sun, 17 Sep 2023 09:11:05 -0600 Subject: [PATCH] fix: refactor to not require esbuid as dep --- packages/validator/package-lock.json | 361 +++--------------------- packages/validator/package.json | 11 +- packages/validator/transpile.js | 38 ++- website/docs/middlewares/third-party.md | 13 +- website/docs/middlewares/validator.md | 26 +- 5 files changed, 99 insertions(+), 350 deletions(-) diff --git a/packages/validator/package-lock.json b/packages/validator/package-lock.json index 0d21707ac..68d39a817 100644 --- a/packages/validator/package-lock.json +++ b/packages/validator/package-lock.json @@ -10,12 +10,19 @@ "license": "MIT", "dependencies": { "@middy/util": "4.6.2", - "ajv-cmd": "0.3.4" + "ajv": "8.12.0", + "ajv-errors": "3.0.0", + "ajv-formats": "2.1.1", + "ajv-formats-draft2019": "1.6.1", + "ajv-ftl-i18n": "0.1.1", + "ajv-keywords": "5.1.0", + "fast-uri": "2.2.0" }, "devDependencies": { "@middy/core": "4.6.2", "@types/http-errors": "^2.0.0", - "ajv-bsontype": "^1.0.7" + "ajv-bsontype": "^1.0.7", + "ajv-cmd": "0.3.4" }, "engines": { "node": ">=16" @@ -29,6 +36,7 @@ "version": "10.1.0", "resolved": "https://registry.npmjs.org/@apidevtools/json-schema-ref-parser/-/json-schema-ref-parser-10.1.0.tgz", "integrity": "sha512-3e+viyMuXdrcK8v5pvP+SDoAQ77FH6OyRmuK48SZKmdHJRFm87RsSs8qm6kP39a/pOPURByJw+OXzQIqcfmKtA==", + "dev": true, "dependencies": { "@jsdevtools/ono": "^7.1.3", "@types/json-schema": "^7.0.11", @@ -43,51 +51,6 @@ "url": "https://github.com/sponsors/philsturgeon" } }, - "node_modules/@esbuild/android-arm": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.17.18.tgz", - "integrity": "sha512-EmwL+vUBZJ7mhFCs5lA4ZimpUH3WMAoqvOIYhVQwdIgSpHC8ImHdsRyhHAVxpDYUSm0lWvd63z0XH1IlImS2Qw==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-arm64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.17.18.tgz", - "integrity": "sha512-/iq0aK0eeHgSC3z55ucMAHO05OIqmQehiGay8eP5l/5l+iEr4EIbh4/MI8xD9qRFjqzgkc0JkX0LculNC9mXBw==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/android-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.17.18.tgz", - "integrity": "sha512-x+0efYNBF3NPW2Xc5bFOSFW7tTXdAcpfEg2nXmxegm4mJuVeS+i109m/7HMiOQ6M12aVGGFlqJX3RhNdYM2lWg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "android" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@esbuild/darwin-arm64": { "version": "0.17.18", "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.17.18.tgz", @@ -95,6 +58,7 @@ "cpu": [ "arm64" ], + "dev": true, "optional": true, "os": [ "darwin" @@ -103,276 +67,6 @@ "node": ">=12" } }, - "node_modules/@esbuild/darwin-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.17.18.tgz", - "integrity": "sha512-Qq84ykvLvya3dO49wVC9FFCNUfSrQJLbxhoQk/TE1r6MjHo3sFF2tlJCwMjhkBVq3/ahUisj7+EpRSz0/+8+9A==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-arm64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.17.18.tgz", - "integrity": "sha512-fw/ZfxfAzuHfaQeMDhbzxp9mc+mHn1Y94VDHFHjGvt2Uxl10mT4CDavHm+/L9KG441t1QdABqkVYwakMUeyLRA==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/freebsd-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.17.18.tgz", - "integrity": "sha512-FQFbRtTaEi8ZBi/A6kxOC0V0E9B/97vPdYjY9NdawyLd4Qk5VD5g2pbWN2VR1c0xhzcJm74HWpObPszWC+qTew==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.17.18.tgz", - "integrity": "sha512-jW+UCM40LzHcouIaqv3e/oRs0JM76JfhHjCavPxMUti7VAPh8CaGSlS7cmyrdpzSk7A+8f0hiedHqr/LMnfijg==", - "cpu": [ - "arm" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-arm64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.17.18.tgz", - "integrity": "sha512-R7pZvQZFOY2sxUG8P6A21eq6q+eBv7JPQYIybHVf1XkQYC+lT7nDBdC7wWKTrbvMXKRaGudp/dzZCwL/863mZQ==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ia32": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.17.18.tgz", - "integrity": "sha512-ygIMc3I7wxgXIxk6j3V00VlABIjq260i967Cp9BNAk5pOOpIXmd1RFQJQX9Io7KRsthDrQYrtcx7QCof4o3ZoQ==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-loong64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.17.18.tgz", - "integrity": "sha512-bvPG+MyFs5ZlwYclCG1D744oHk1Pv7j8psF5TfYx7otCVmcJsEXgFEhQkbhNW8otDHL1a2KDINW20cfCgnzgMQ==", - "cpu": [ - "loong64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-mips64el": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.17.18.tgz", - "integrity": "sha512-oVqckATOAGuiUOa6wr8TXaVPSa+6IwVJrGidmNZS1cZVx0HqkTMkqFGD2HIx9H1RvOwFeWYdaYbdY6B89KUMxA==", - "cpu": [ - "mips64el" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-ppc64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.17.18.tgz", - "integrity": "sha512-3dLlQO+b/LnQNxgH4l9rqa2/IwRJVN9u/bK63FhOPB4xqiRqlQAU0qDU3JJuf0BmaH0yytTBdoSBHrb2jqc5qQ==", - "cpu": [ - "ppc64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-riscv64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.17.18.tgz", - "integrity": "sha512-/x7leOyDPjZV3TcsdfrSI107zItVnsX1q2nho7hbbQoKnmoeUWjs+08rKKt4AUXju7+3aRZSsKrJtaRmsdL1xA==", - "cpu": [ - "riscv64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-s390x": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.17.18.tgz", - "integrity": "sha512-cX0I8Q9xQkL/6F5zWdYmVf5JSQt+ZfZD2bJudZrWD+4mnUvoZ3TDDXtDX2mUaq6upMFv9FlfIh4Gfun0tbGzuw==", - "cpu": [ - "s390x" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/linux-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.17.18.tgz", - "integrity": "sha512-66RmRsPlYy4jFl0vG80GcNRdirx4nVWAzJmXkevgphP1qf4dsLQCpSKGM3DUQCojwU1hnepI63gNZdrr02wHUA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/netbsd-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.17.18.tgz", - "integrity": "sha512-95IRY7mI2yrkLlTLb1gpDxdC5WLC5mZDi+kA9dmM5XAGxCME0F8i4bYH4jZreaJ6lIZ0B8hTrweqG1fUyW7jbg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/openbsd-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.17.18.tgz", - "integrity": "sha512-WevVOgcng+8hSZ4Q3BKL3n1xTv5H6Nb53cBrtzzEjDbbnOmucEVcZeGCsCOi9bAOcDYEeBZbD2SJNBxlfP3qiA==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/sunos-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.17.18.tgz", - "integrity": "sha512-Rzf4QfQagnwhQXVBS3BYUlxmEbcV7MY+BH5vfDZekU5eYpcffHSyjU8T0xucKVuOcdCsMo+Ur5wmgQJH2GfNrg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-arm64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.17.18.tgz", - "integrity": "sha512-Kb3Ko/KKaWhjeAm2YoT/cNZaHaD1Yk/pa3FTsmqo9uFh1D1Rfco7BBLIPdDOozrObj2sahslFuAQGvWbgWldAg==", - "cpu": [ - "arm64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-ia32": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.17.18.tgz", - "integrity": "sha512-0/xUMIdkVHwkvxfbd5+lfG7mHOf2FRrxNbPiKWg9C4fFrB8H0guClmaM3BFiRUYrznVoyxTIyC/Ou2B7QQSwmw==", - "cpu": [ - "ia32" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, - "node_modules/@esbuild/win32-x64": { - "version": "0.17.18", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.17.18.tgz", - "integrity": "sha512-qU25Ma1I3NqTSHJUOKi9sAH1/Mzuvlke0ioMJRthLXKm7JiSKVwFghlGbDLOO2sARECGhja4xYfRAZNPAkooYg==", - "cpu": [ - "x64" - ], - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=12" - } - }, "node_modules/@fluent/syntax": { "version": "0.18.1", "resolved": "https://registry.npmjs.org/@fluent/syntax/-/syntax-0.18.1.tgz", @@ -385,12 +79,13 @@ "node_modules/@jsdevtools/ono": { "version": "7.1.3", "resolved": "https://registry.npmjs.org/@jsdevtools/ono/-/ono-7.1.3.tgz", - "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==" + "integrity": "sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==", + "dev": true }, "node_modules/@middy/core": { - "version": "4.6.1", - "resolved": "https://registry.npmjs.org/@middy/core/-/core-4.6.1.tgz", - "integrity": "sha512-3fBaaL2fTX0564pkniDBcTm3S8qOatHVZKDZ8GG3ZrmEJhVkWGkv1e4iWywjtBsLaXzho75uuSUFwdeEbl3x5A==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/@middy/core/-/core-4.6.2.tgz", + "integrity": "sha512-pEy2tAvlQfo3hyskZBkgeEi2kjjc7ZQoblcLHKanyfgubf1NPfzW35oHj1jW5GNK4lDpJoV3LAflAMH1NxdX2Q==", "dev": true, "engines": { "node": ">=16" @@ -401,9 +96,9 @@ } }, "node_modules/@middy/util": { - "version": "4.6.1", - "resolved": "https://registry.npmjs.org/@middy/util/-/util-4.6.1.tgz", - "integrity": "sha512-EylBSkcSU+vg8dBFUu0x494EXzjG3DrTSzePf5pFHzaGeTh0GliButSQXO4PU4eK1p2XUW2Cx0vCYoTbsNAtYA==", + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/@middy/util/-/util-4.6.2.tgz", + "integrity": "sha512-VPxAEGNKJ/Rn1Wa3stElHDajTdyLTsctPdXgr2n8dB6QooT/EvAAzw94IvTzfpXvNKEXAYo+PZBRRLnErwp6Xw==", "engines": { "node": ">=16" }, @@ -421,17 +116,20 @@ "node_modules/@types/json-schema": { "version": "7.0.12", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.12.tgz", - "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==" + "integrity": "sha512-Hr5Jfhc9eYOQNPYO5WLDq/n4jqijdHNlDXjuAQkkt+mWdQR+XJToOHrsD4cPaMXpn6KO7y2+wM8AZEs8VpBLVA==", + "dev": true }, "node_modules/@types/lodash": { "version": "4.14.198", "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.198.tgz", - "integrity": "sha512-trNJ/vtMZYMLhfN45uLq4ShQSw0/S7xCTLLVM+WM1rmFpba/VS42jVUgaO3w/NOLiWR/09lnYk0yMaA/atdIsg==" + "integrity": "sha512-trNJ/vtMZYMLhfN45uLq4ShQSw0/S7xCTLLVM+WM1rmFpba/VS42jVUgaO3w/NOLiWR/09lnYk0yMaA/atdIsg==", + "dev": true }, "node_modules/@types/lodash.clonedeep": { "version": "4.5.7", "resolved": "https://registry.npmjs.org/@types/lodash.clonedeep/-/lodash.clonedeep-4.5.7.tgz", "integrity": "sha512-ccNqkPptFIXrpVqUECi60/DFxjNKsfoQxSQsgcBJCX/fuX1wgyQieojkcWH/KpE3xzLoWN/2k+ZeGqIN3paSvw==", + "dev": true, "dependencies": { "@types/lodash": "*" } @@ -461,6 +159,7 @@ "version": "0.3.4", "resolved": "https://registry.npmjs.org/ajv-cmd/-/ajv-cmd-0.3.4.tgz", "integrity": "sha512-akxHaDtcOo6sIZkfLoSCcIfBsQ8hDgzE4BmVQHloJcXr4j8h+KBD283MOwnoptrPSvXKJMSBJgBmTzTbVpCq0w==", + "dev": true, "dependencies": { "@apidevtools/json-schema-ref-parser": "10.1.0", "ajv": "8.12.0", @@ -548,6 +247,7 @@ "version": "4.2.0", "resolved": "https://registry.npmjs.org/ajv-i18n/-/ajv-i18n-4.2.0.tgz", "integrity": "sha512-v/ei2UkCEeuKNXh8RToiFsUclmU+G57LO1Oo22OagNMENIw+Yb8eMwvHu7Vn9fmkjJyv6XclhJ8TbuigSglPkg==", + "dev": true, "peerDependencies": { "ajv": "^8.0.0-beta.0" } @@ -566,7 +266,8 @@ "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", - "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==", + "dev": true }, "node_modules/camel-case": { "version": "4.1.2", @@ -610,6 +311,7 @@ "version": "10.0.1", "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz", "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==", + "dev": true, "engines": { "node": ">=14" } @@ -642,6 +344,7 @@ "version": "0.17.18", "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.17.18.tgz", "integrity": "sha512-z1lix43jBs6UKjcZVKOw2xx69ffE2aG0PygLL5qJ9OS/gy0Ewd1gW/PUQIOIQGXBHWNywSc0floSKoMFF8aK2w==", + "dev": true, "hasInstallScript": true, "bin": { "esbuild": "bin/esbuild" @@ -723,6 +426,7 @@ "version": "4.1.0", "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz", "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==", + "dev": true, "dependencies": { "argparse": "^2.0.1" }, @@ -738,7 +442,8 @@ "node_modules/lodash.clonedeep": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", - "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" + "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==", + "dev": true }, "node_modules/lower-case": { "version": "2.0.2", diff --git a/packages/validator/package.json b/packages/validator/package.json index b83d78536..289d3cb7a 100644 --- a/packages/validator/package.json +++ b/packages/validator/package.json @@ -79,12 +79,19 @@ }, "dependencies": { "@middy/util": "4.6.2", - "ajv-cmd": "0.3.4" + "ajv": "8.12.0", + "ajv-errors": "3.0.0", + "ajv-formats": "2.1.1", + "ajv-formats-draft2019": "1.6.1", + "ajv-ftl-i18n": "0.1.1", + "ajv-keywords": "5.1.0", + "fast-uri": "2.2.0" }, "devDependencies": { "@middy/core": "4.6.2", "@types/http-errors": "^2.0.0", - "ajv-bsontype": "^1.0.7" + "ajv-bsontype": "^1.0.7", + "ajv-cmd": "0.3.4" }, "gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431" } diff --git a/packages/validator/transpile.js b/packages/validator/transpile.js index 4a2279e6f..50bd6c221 100644 --- a/packages/validator/transpile.js +++ b/packages/validator/transpile.js @@ -1,5 +1,39 @@ -import compileSchema from 'ajv-cmd/compile' -import transpileFTL from 'ajv-cmd/ftl' +import Ajv from 'ajv/dist/2020.js' +import ajvFormats from 'ajv-formats' +import ajvFormatsDraft2019 from 'ajv-formats-draft2019' +import ajvKeywords from 'ajv-keywords' +import ajvErrors from 'ajv-errors' +import uriResolver from 'fast-uri' + +import { transpile } from 'ajv-ftl-i18n' + +// import transpileFTL from 'ajv-cmd/ftl' +export const transpileFTL = transpile + +/* Start `ajv-cmd/compile` */ +// import compileSchema from 'ajv-cmd/compile' + +const defaultOptions = { + uriResolver // faster than default +} + +const instance = (options = {}) => { + options = { ...defaultOptions, ...options, keywords: [] } + + const ajv = new Ajv(options) + ajvFormats(ajv) + ajvFormatsDraft2019(ajv) + ajvKeywords(ajv) + ajvErrors(ajv) + return ajv +} + +const compileSchema = (schema, options = {}) => { + options = { ...defaultOptions, ...options, keywords: [] } + const ajv = instance(options) + return ajv.compile(schema) +} +/* End `ajv-cmd/compile` */ const ajvDefaults = { strict: true, diff --git a/website/docs/middlewares/third-party.md b/website/docs/middlewares/third-party.md index af7d27aad..41df98a13 100644 --- a/website/docs/middlewares/third-party.md +++ b/website/docs/middlewares/third-party.md @@ -9,16 +9,17 @@ If your middleware is missing, feel free to [open a Pull Request](https://github ## Version 2.x - 4.x - [dazn-lambda-powertools](https://github.com/getndazn/dazn-lambda-powertools): A collection of middlewares, AWS clients and helper libraries that make working with lambda easier. -- [middy-sparks-joi](https://www.npmjs.com/package/middy-sparks-joi): Joi validator +- [middy-ajv](https://www.npmjs.com/package/middy-ajv): AJV validator optimized for performance +- [middy-console-logger](https://github.com/serkan-ozal/middy-console-logger): Middleware for filtering logs printed over console logging methods. If the level of the console logging method is equal or bigger than configured level, the log is printed, Otherwise, it is ignored. +- [middy-event-loop-tracer](https://github.com/serkan-ozal/middy-event-loop-tracer): Middleware for dumping active tasks with their stacktraces in the event queue just before AWS Lambda function timeouts. So you can understand what was going on in the function when timeout happens. - [middy-idempotent](https://www.npmjs.com/package/middy-idempotent): idempotency middleware for middy +- [middy-invocation](https://github.com/serkan-ozal/middy-invocation): Middleware for accessing current AWS Lambda invocation event and context from anywhere without need to passing event and context as arguments through your code.- [middy-lesslog](https://www.npmjs.com/package/middy-lesslog): Middleware for `lesslog`, a teeny-tiny and severless-ready logging utility - [middy-jsonapi](https://www.npmjs.com/package/middy-jsonapi): JSONAPI middleware for middy - [middy-lesslog](https://www.npmjs.com/package/middy-lesslog): Middleware for `lesslog`, a teeny-tiny and severless-ready logging utility +- [middy-profiler](https://github.com/serkan-ozal/middy-profiler): Middleware for profiling CPU on AWS Lambda during invocation and shows what methods/modules consume what percent of CPU time - [middy-rds](https://www.npmjs.com/package/middy-rds): Creates RDS connection using `knex` or `pg` - [middy-recaptcha](https://www.npmjs.com/package/middy-recaptcha): reCAPTCHA validation middleware -- [middy-event-loop-tracer](https://github.com/serkan-ozal/middy-event-loop-tracer): Middleware for dumping active tasks with their stacktraces in the event queue just before AWS Lambda function timeouts. So you can understand what was going on in the function when timeout happens. -- [middy-console-logger](https://github.com/serkan-ozal/middy-console-logger): Middleware for filtering logs printed over console logging methods. If the level of the console logging method is equal or bigger than configured level, the log is printed, Otherwise, it is ignored. -- [middy-invocation](https://github.com/serkan-ozal/middy-invocation): Middleware for accessing current AWS Lambda invocation event and context from anywhere without need to passing event and context as arguments through your code. -- [middy-profiler](https://github.com/serkan-ozal/middy-profiler): Middleware for profiling CPU on AWS Lambda during invocation and shows what methods/modules consume what percent of CPU time +- [middy-sparks-joi](https://www.npmjs.com/package/middy-sparks-joi): Joi validator ## Version 2.x - 3.x @@ -29,8 +30,6 @@ If your middleware is missing, feel free to [open a Pull Request](https://github - [parameters](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/utilities/parameters/): The Parameters utility provides high-level functions to retrieve one or multiple parameter values from AWS Systems Manager Parameter Store, AWS Secrets Manager, AWS AppConfig, Amazon DynamoDB, or your own parameter store. - [tracer](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/core/tracer/#lambda-handler): Utilities to trace Lambda function handlers, and both synchronous and asynchronous functions -- [middy-ajv](https://www.npmjs.com/package/middy-ajv): AJV validator optimized for performance - ## Version 1.x - [middy-redis](https://www.npmjs.com/package/middy-redis): Redis connection middleware diff --git a/website/docs/middlewares/validator.md b/website/docs/middlewares/validator.md index 6838f6577..884ac3224 100644 --- a/website/docs/middlewares/validator.md +++ b/website/docs/middlewares/validator.md @@ -5,6 +5,11 @@ title: validator This middleware automatically validates incoming events and outgoing responses against custom schemas defined with the [JSON schema syntax](http://json-schema.org/). +Want to use another validator? Try one of the community validators: + +- [ajv](https://www.npmjs.com/package/middy-ajv) +- [middy-sparks-joi](https://www.npmjs.com/package/middy-sparks-joi) + If an incoming event fails validation a `BadRequest` error is raised. If an outgoing response fails validation a `InternalServerError` error is raised. @@ -23,6 +28,7 @@ To install this middleware you can use NPM: ```bash npm2yarn npm install --save @middy/validator +npm install --save-dev ajv-cmd ``` ## Options @@ -154,22 +160,20 @@ const schema = { type: 'object', required: ['name', 'email'], properties: { - name: { type: 'string' }, - email: { type: 'string', format: 'email' } + name: { type: 'string' }, + email: { type: 'string', format: 'email' } // schema options https://ajv.js.org/json-schema.html#json-data-type - }, - }, + } + } } } // to validate the body we need to parse it first -handler - .use(httpJsonBodyParser()) - .use( - validator({ - eventSchema: transpileSchema(schema) - }) - ) +handler.use(httpJsonBodyParser()).use( + validator({ + eventSchema: transpileSchema(schema) + }) +) ``` ## Pre-transpiling example (recommended)