From 61c2f91e9412cdd6c4a4557c47661cc4c11e4420 Mon Sep 17 00:00:00 2001 From: Tomer Shvadron Date: Wed, 17 Jul 2024 18:03:18 +0300 Subject: [PATCH 1/3] Set Typebox version to be constant --- package.json | 3 ++- pnpm-lock.yaml | 22 ++++++++++++++++++---- src/ajv-options.ts | 5 +++++ src/decorators.ts | 9 ++++++++- 4 files changed, 33 insertions(+), 6 deletions(-) create mode 100644 src/ajv-options.ts diff --git a/package.json b/package.json index a249aca..256c407 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@nestjs/swagger": "^6.1.1 || ^7.0.11", "@sinclair/typebox": "^0.32.4", "ajv": "^8.14.0", + "ajv-formats": "^2.1.1", "rxjs": "^7.5.6" }, "dependencies": { @@ -37,7 +38,7 @@ "@nestjs/common": "^10.0.5", "@nestjs/core": "^10.0.5", "@nestjs/swagger": "^7.1.1", - "@sinclair/typebox": "^0.32.4", + "@sinclair/typebox": "0.32.15", "@types/node": "^20.4.1", "@typescript-eslint/eslint-plugin": "^6.0.0", "@typescript-eslint/parser": "^6.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b137295..2eca1ad 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: ajv: specifier: ^8.14.0 version: 8.14.0 + ajv-formats: + specifier: ^2.1.1 + version: 2.1.1(ajv@8.14.0) fast-uri: specifier: ^2.3.0 version: 2.3.0 @@ -26,8 +29,8 @@ devDependencies: specifier: ^7.1.1 version: 7.3.1(@nestjs/common@10.3.8)(@nestjs/core@10.3.8)(reflect-metadata@0.2.2) '@sinclair/typebox': - specifier: ^0.32.4 - version: 0.32.31 + specifier: 0.32.15 + version: 0.32.15 '@types/node': specifier: ^20.4.1 version: 20.13.0 @@ -517,8 +520,8 @@ packages: engines: {node: ^12.20.0 || ^14.18.0 || >=16.0.0} dev: true - /@sinclair/typebox@0.32.31: - resolution: {integrity: sha512-rYB0tgGHawpom3ZwwsGidvI0NI+W/rRHu1dyyO1KlIoH8iMdg3esSnYQxQtyJ8eflhqxmzEV7Nu8zT4JY7CHKw==} + /@sinclair/typebox@0.32.15: + resolution: {integrity: sha512-5Lrwo7VOiWEBJBhHmqNmf3TPB9ll8gcEshvYJyAIJyCZ2PF48MFOtiDHJNj8+FsNcqImaQYmxVkKBCBlyAa/wg==} dev: true /@types/json-schema@7.0.15: @@ -701,6 +704,17 @@ packages: hasBin: true dev: true + /ajv-formats@2.1.1(ajv@8.14.0): + resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==} + peerDependencies: + ajv: ^8.0.0 + peerDependenciesMeta: + ajv: + optional: true + dependencies: + ajv: 8.14.0 + dev: false + /ajv@6.12.6: resolution: {integrity: sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==} dependencies: diff --git a/src/ajv-options.ts b/src/ajv-options.ts new file mode 100644 index 0000000..69df064 --- /dev/null +++ b/src/ajv-options.ts @@ -0,0 +1,5 @@ +import type { Options } from 'ajv'; + +export const ajvOptions = { + keywords: ['transform'], +} satisfies Options; diff --git a/src/decorators.ts b/src/decorators.ts index 43e6593..8058d43 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -7,7 +7,6 @@ import { DECORATORS } from '@nestjs/swagger/dist/constants.js'; import { Static, TSchema, Type, TypeGuard } from '@sinclair/typebox'; import Ajv from 'ajv'; import fastUri from 'fast-uri'; - import { AjvValidationException } from './exceptions.js'; import { TypeboxTransformInterceptor } from './interceptors.js'; import type { @@ -23,6 +22,9 @@ import type { } from './types.js'; import { capitalize, coerceType, isObj } from './util.js'; +import AjvFormats from 'ajv-formats'; +import { ajvOptions } from './ajv-options.js'; + const ajv = new Ajv({ coerceTypes: 'array', useDefaults: true, @@ -32,8 +34,13 @@ const ajv = new Ajv({ // Explicitly set allErrors to `false`. // When set to `true`, a DoS attack is possible. allErrors: false, + + // Our custom options: + ...ajvOptions, }); +AjvFormats.default(ajv); + export function isSchemaValidator( // eslint-disable-next-line @typescript-eslint/no-explicit-any type: any From ddb6328d7ac0e199baf9a342cf8738e971887a8e Mon Sep 17 00:00:00 2001 From: Tomer Shvadron Date: Wed, 17 Jul 2024 18:07:58 +0300 Subject: [PATCH 2/3] version bump --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 256c407..96f0510 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ballerine-nestjs-typebox", - "version": "3.0.2-next.8", + "version": "3.0.2-next.9", "description": "", "author": "Andrew Smiley ", "license": "MIT", From a3f969ac412d066e9746d1339018081992662148 Mon Sep 17 00:00:00 2001 From: Tomer Shvadron Date: Wed, 17 Jul 2024 18:12:00 +0300 Subject: [PATCH 3/3] inlined variable --- src/ajv-options.ts | 5 ----- src/decorators.ts | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 src/ajv-options.ts diff --git a/src/ajv-options.ts b/src/ajv-options.ts deleted file mode 100644 index 69df064..0000000 --- a/src/ajv-options.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { Options } from 'ajv'; - -export const ajvOptions = { - keywords: ['transform'], -} satisfies Options; diff --git a/src/decorators.ts b/src/decorators.ts index 8058d43..367f785 100644 --- a/src/decorators.ts +++ b/src/decorators.ts @@ -23,7 +23,6 @@ import type { import { capitalize, coerceType, isObj } from './util.js'; import AjvFormats from 'ajv-formats'; -import { ajvOptions } from './ajv-options.js'; const ajv = new Ajv({ coerceTypes: 'array', @@ -36,7 +35,7 @@ const ajv = new Ajv({ allErrors: false, // Our custom options: - ...ajvOptions, + keywords: ['transform'], }); AjvFormats.default(ajv);