From 1eda04b74a60aa1f7465c348d9e3e55727c1106d Mon Sep 17 00:00:00 2001 From: Loparev Date: Tue, 12 Mar 2024 17:01:56 +0200 Subject: [PATCH 1/3] Initial naive method arguments decorator validation implementation --- src/decorator/argument/index.ts | 27 ++ src/decorator/argument/is-not-empty/index.ts | 11 + .../is-not-empty/is-not-empty-validator.ts | 9 + src/decorator/array/ArrayContains.ts | 2 +- src/decorator/array/ArrayMaxSize.ts | 2 +- src/decorator/array/ArrayMinSize.ts | 2 +- src/decorator/array/ArrayNotContains.ts | 2 +- src/decorator/array/ArrayNotEmpty.ts | 2 +- src/decorator/array/ArrayUnique.ts | 2 +- src/decorator/common/Allow.ts | 10 +- src/decorator/common/Equals.ts | 2 +- src/decorator/common/IsDefined.ts | 4 +- src/decorator/common/IsEmpty.ts | 2 +- src/decorator/common/IsIn.ts | 2 +- src/decorator/common/IsLatLong.ts | 2 +- src/decorator/common/IsLatitude.ts | 2 +- src/decorator/common/IsLongitude.ts | 2 +- src/decorator/common/IsNotEmpty.ts | 2 +- src/decorator/common/IsNotIn.ts | 2 +- src/decorator/common/IsOptional.ts | 10 +- src/decorator/common/NotEquals.ts | 2 +- src/decorator/common/Validate.ts | 12 +- src/decorator/common/ValidateBy.ts | 8 +- src/decorator/common/ValidateIf.ts | 10 +- src/decorator/common/ValidateNested.ts | 10 +- src/decorator/common/ValidatePromise.ts | 10 +- src/decorator/date/MaxDate.ts | 2 +- src/decorator/date/MinDate.ts | 2 +- src/decorator/decorators.ts | 236 +++++++++--------- src/decorator/number/IsDivisibleBy.ts | 2 +- src/decorator/number/IsNegative.ts | 2 +- src/decorator/number/IsPositive.ts | 2 +- src/decorator/number/Max.ts | 2 +- src/decorator/number/Min.ts | 2 +- src/decorator/object/IsInstance.ts | 2 +- src/decorator/object/IsNotEmptyObject.ts | 2 +- src/decorator/string/Contains.ts | 2 +- src/decorator/string/IsAlpha.ts | 2 +- src/decorator/string/IsAlphanumeric.ts | 2 +- src/decorator/string/IsAscii.ts | 2 +- src/decorator/string/IsBIC.ts | 2 +- src/decorator/string/IsBase32.ts | 2 +- src/decorator/string/IsBase58.ts | 2 +- src/decorator/string/IsBase64.ts | 2 +- src/decorator/string/IsBooleanString.ts | 2 +- src/decorator/string/IsBtcAddress.ts | 2 +- src/decorator/string/IsByteLength.ts | 2 +- src/decorator/string/IsCreditCard.ts | 2 +- src/decorator/string/IsCurrency.ts | 2 +- src/decorator/string/IsDataURI.ts | 2 +- src/decorator/string/IsDateString.ts | 2 +- src/decorator/string/IsDecimal.ts | 2 +- src/decorator/string/IsEAN.ts | 2 +- src/decorator/string/IsEmail.ts | 2 +- src/decorator/string/IsEthereumAddress.ts | 2 +- src/decorator/string/IsFQDN.ts | 2 +- src/decorator/string/IsFirebasePushId.ts | 2 +- src/decorator/string/IsFullWidth.ts | 2 +- src/decorator/string/IsHSL.ts | 2 +- src/decorator/string/IsHalfWidth.ts | 2 +- src/decorator/string/IsHash.ts | 2 +- src/decorator/string/IsHexColor.ts | 2 +- src/decorator/string/IsHexadecimal.ts | 2 +- src/decorator/string/IsIBAN.ts | 2 +- src/decorator/string/IsIP.ts | 2 +- src/decorator/string/IsISBN.ts | 2 +- src/decorator/string/IsISIN.ts | 2 +- src/decorator/string/IsISO31661Alpha2.ts | 2 +- src/decorator/string/IsISO31661Alpha3.ts | 2 +- src/decorator/string/IsISO8601.ts | 2 +- src/decorator/string/IsISRC.ts | 2 +- src/decorator/string/IsISSN.ts | 2 +- src/decorator/string/IsIdentityCard.ts | 2 +- src/decorator/string/IsJSON.ts | 2 +- src/decorator/string/IsJWT.ts | 2 +- src/decorator/string/IsLocale.ts | 2 +- src/decorator/string/IsLowercase.ts | 2 +- src/decorator/string/IsMacAddress.ts | 2 +- src/decorator/string/IsMagnetURI.ts | 2 +- src/decorator/string/IsMilitaryTime.ts | 2 +- src/decorator/string/IsMimeType.ts | 2 +- src/decorator/string/IsMobilePhone.ts | 2 +- src/decorator/string/IsMongoId.ts | 2 +- src/decorator/string/IsMultibyte.ts | 2 +- src/decorator/string/IsNumberString.ts | 2 +- src/decorator/string/IsOctal.ts | 2 +- src/decorator/string/IsPassportNumber.ts | 2 +- src/decorator/string/IsPhoneNumber.ts | 2 +- src/decorator/string/IsPort.ts | 2 +- src/decorator/string/IsPostalCode.ts | 2 +- src/decorator/string/IsRFC3339.ts | 2 +- src/decorator/string/IsRgbColor.ts | 2 +- src/decorator/string/IsSemVer.ts | 2 +- src/decorator/string/IsStrongPassword.ts | 2 +- src/decorator/string/IsSurrogatePair.ts | 2 +- src/decorator/string/IsTimeZone.ts | 2 +- src/decorator/string/IsUUID.ts | 2 +- src/decorator/string/IsUppercase.ts | 2 +- src/decorator/string/IsUrl.ts | 2 +- src/decorator/string/IsVariableWidth.ts | 2 +- src/decorator/string/Length.ts | 2 +- src/decorator/string/Matches.ts | 2 +- src/decorator/string/MaxLength.ts | 2 +- src/decorator/string/MinLength.ts | 2 +- src/decorator/string/NotContains.ts | 2 +- .../string/is-iso4217-currency-code.ts | 2 +- src/decorator/string/is-tax-id.ts | 2 +- src/decorator/typechecker/IsArray.ts | 2 +- src/decorator/typechecker/IsBoolean.ts | 2 +- src/decorator/typechecker/IsDate.ts | 2 +- src/decorator/typechecker/IsEnum.ts | 2 +- src/decorator/typechecker/IsInt.ts | 2 +- src/decorator/typechecker/IsNumber.ts | 2 +- src/decorator/typechecker/IsObject.ts | 2 +- src/decorator/typechecker/IsString.ts | 2 +- .../method-argument-decorators.spec.ts | 20 ++ 116 files changed, 331 insertions(+), 252 deletions(-) create mode 100644 src/decorator/argument/index.ts create mode 100644 src/decorator/argument/is-not-empty/index.ts create mode 100644 src/decorator/argument/is-not-empty/is-not-empty-validator.ts create mode 100644 test/functional/method-argument-decorators.spec.ts diff --git a/src/decorator/argument/index.ts b/src/decorator/argument/index.ts new file mode 100644 index 0000000000..d897032391 --- /dev/null +++ b/src/decorator/argument/index.ts @@ -0,0 +1,27 @@ +import { IsNotEmptyArgument } from "./is-not-empty"; +import { IsNotEmptyValidate } from "./is-not-empty/is-not-empty-validator"; + +export function ValidateArguments(target: any, propertyName: string, descriptor: TypedPropertyDescriptor) { + let method = descriptor.value!; + + descriptor.value = function (...args: Array) { + if (target?.validations?.length) { + for (const validation of target.validations) { + const [methodName, argumentIndex, validatorName] = validation.split(":"); + + if (method.name === methodName) { + switch (validatorName) { + case IsNotEmptyArgument.name: + const argumentValue = args[argumentIndex]; + + IsNotEmptyValidate(methodName, argumentIndex, argumentValue); + + break; + } + } + } + } + + return method.apply(this, arguments); + }; +} diff --git a/src/decorator/argument/is-not-empty/index.ts b/src/decorator/argument/is-not-empty/index.ts new file mode 100644 index 0000000000..8d8b8a3727 --- /dev/null +++ b/src/decorator/argument/is-not-empty/index.ts @@ -0,0 +1,11 @@ +export function IsNotEmptyArgument( + target: any, + methodName: string, + parameterIndex: number +) { + if (!target?.validations) { + target.validations = []; + } + + target.validations.push(`${methodName}:${parameterIndex}:${IsNotEmptyArgument.name}`); +} diff --git a/src/decorator/argument/is-not-empty/is-not-empty-validator.ts b/src/decorator/argument/is-not-empty/is-not-empty-validator.ts new file mode 100644 index 0000000000..20a968c8c8 --- /dev/null +++ b/src/decorator/argument/is-not-empty/is-not-empty-validator.ts @@ -0,0 +1,9 @@ +export function IsNotEmptyValidate( + methodName: string, + argumentIndex: number, + argumentValue: any +) { + if (argumentValue === '' || argumentValue === null || argumentValue === undefined) { + throw new Error(`Invalid empty argument at index ${argumentIndex} with "${argumentValue}" value in "${methodName}" method`); + } +} diff --git a/src/decorator/array/ArrayContains.ts b/src/decorator/array/ArrayContains.ts index b2242c15d2..828eca5569 100644 --- a/src/decorator/array/ArrayContains.ts +++ b/src/decorator/array/ArrayContains.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const ARRAY_CONTAINS = 'arrayContains'; diff --git a/src/decorator/array/ArrayMaxSize.ts b/src/decorator/array/ArrayMaxSize.ts index 726ebd6b5e..c20510c73f 100644 --- a/src/decorator/array/ArrayMaxSize.ts +++ b/src/decorator/array/ArrayMaxSize.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const ARRAY_MAX_SIZE = 'arrayMaxSize'; diff --git a/src/decorator/array/ArrayMinSize.ts b/src/decorator/array/ArrayMinSize.ts index 750b297e90..14e9d466e9 100644 --- a/src/decorator/array/ArrayMinSize.ts +++ b/src/decorator/array/ArrayMinSize.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const ARRAY_MIN_SIZE = 'arrayMinSize'; diff --git a/src/decorator/array/ArrayNotContains.ts b/src/decorator/array/ArrayNotContains.ts index fca6c4ccb5..a06266ef4c 100644 --- a/src/decorator/array/ArrayNotContains.ts +++ b/src/decorator/array/ArrayNotContains.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const ARRAY_NOT_CONTAINS = 'arrayNotContains'; diff --git a/src/decorator/array/ArrayNotEmpty.ts b/src/decorator/array/ArrayNotEmpty.ts index 432d4c5248..11d95cd711 100644 --- a/src/decorator/array/ArrayNotEmpty.ts +++ b/src/decorator/array/ArrayNotEmpty.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const ARRAY_NOT_EMPTY = 'arrayNotEmpty'; diff --git a/src/decorator/array/ArrayUnique.ts b/src/decorator/array/ArrayUnique.ts index 0979aeefc0..731088e8a0 100644 --- a/src/decorator/array/ArrayUnique.ts +++ b/src/decorator/array/ArrayUnique.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const ARRAY_UNIQUE = 'arrayUnique'; diff --git a/src/decorator/common/Allow.ts b/src/decorator/common/Allow.ts index 943722ec8c..2c97611381 100644 --- a/src/decorator/common/Allow.ts +++ b/src/decorator/common/Allow.ts @@ -1,8 +1,8 @@ -import { ValidationOptions } from '../ValidationOptions'; -import { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs'; -import { ValidationTypes } from '../../validation/ValidationTypes'; -import { ValidationMetadata } from '../../metadata/ValidationMetadata'; -import { getMetadataStorage } from '../../metadata/MetadataStorage'; +import { ValidationOptions } from '../../ValidationOptions'; +import { ValidationMetadataArgs } from '../../../metadata/ValidationMetadataArgs'; +import { ValidationTypes } from '../../../validation/ValidationTypes'; +import { ValidationMetadata } from '../../../metadata/ValidationMetadata'; +import { getMetadataStorage } from '../../../metadata/MetadataStorage'; /** * If object has both allowed and not allowed properties a validation error will be thrown. diff --git a/src/decorator/common/Equals.ts b/src/decorator/common/Equals.ts index 91ef9e65d7..778bc51a6c 100644 --- a/src/decorator/common/Equals.ts +++ b/src/decorator/common/Equals.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const EQUALS = 'equals'; diff --git a/src/decorator/common/IsDefined.ts b/src/decorator/common/IsDefined.ts index 8e445dde72..60c8c2bd26 100644 --- a/src/decorator/common/IsDefined.ts +++ b/src/decorator/common/IsDefined.ts @@ -1,6 +1,6 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from './ValidateBy'; -import { ValidationTypes } from '../../validation/ValidationTypes'; +import { ValidationTypes } from '../../../validation/ValidationTypes'; // isDefined is (yet) a special case export const IS_DEFINED = ValidationTypes.IS_DEFINED; diff --git a/src/decorator/common/IsEmpty.ts b/src/decorator/common/IsEmpty.ts index 1447811b9e..b4aa9f765f 100644 --- a/src/decorator/common/IsEmpty.ts +++ b/src/decorator/common/IsEmpty.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_EMPTY = 'isEmpty'; diff --git a/src/decorator/common/IsIn.ts b/src/decorator/common/IsIn.ts index d074dcca5e..8bb0546581 100644 --- a/src/decorator/common/IsIn.ts +++ b/src/decorator/common/IsIn.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_IN = 'isIn'; diff --git a/src/decorator/common/IsLatLong.ts b/src/decorator/common/IsLatLong.ts index becbf29c33..9caf07343f 100644 --- a/src/decorator/common/IsLatLong.ts +++ b/src/decorator/common/IsLatLong.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from './ValidateBy'; import isLatLongValidator from 'validator/lib/isLatLong'; diff --git a/src/decorator/common/IsLatitude.ts b/src/decorator/common/IsLatitude.ts index 1be12e130e..7d67778e3f 100644 --- a/src/decorator/common/IsLatitude.ts +++ b/src/decorator/common/IsLatitude.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from './ValidateBy'; import { isLatLong } from './IsLatLong'; diff --git a/src/decorator/common/IsLongitude.ts b/src/decorator/common/IsLongitude.ts index 013f5387af..f3ccb535af 100644 --- a/src/decorator/common/IsLongitude.ts +++ b/src/decorator/common/IsLongitude.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from './ValidateBy'; import { isLatLong } from './IsLatLong'; diff --git a/src/decorator/common/IsNotEmpty.ts b/src/decorator/common/IsNotEmpty.ts index 605da09edc..ee31782e72 100644 --- a/src/decorator/common/IsNotEmpty.ts +++ b/src/decorator/common/IsNotEmpty.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_NOT_EMPTY = 'isNotEmpty'; diff --git a/src/decorator/common/IsNotIn.ts b/src/decorator/common/IsNotIn.ts index 187e91d96a..4336dffc7f 100644 --- a/src/decorator/common/IsNotIn.ts +++ b/src/decorator/common/IsNotIn.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_NOT_IN = 'isNotIn'; diff --git a/src/decorator/common/IsOptional.ts b/src/decorator/common/IsOptional.ts index 38204c5659..ad751b6432 100644 --- a/src/decorator/common/IsOptional.ts +++ b/src/decorator/common/IsOptional.ts @@ -1,8 +1,8 @@ -import { ValidationOptions } from '../ValidationOptions'; -import { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs'; -import { ValidationTypes } from '../../validation/ValidationTypes'; -import { ValidationMetadata } from '../../metadata/ValidationMetadata'; -import { getMetadataStorage } from '../../metadata/MetadataStorage'; +import { ValidationOptions } from '../../ValidationOptions'; +import { ValidationMetadataArgs } from '../../../metadata/ValidationMetadataArgs'; +import { ValidationTypes } from '../../../validation/ValidationTypes'; +import { ValidationMetadata } from '../../../metadata/ValidationMetadata'; +import { getMetadataStorage } from '../../../metadata/MetadataStorage'; export const IS_OPTIONAL = 'isOptional'; diff --git a/src/decorator/common/NotEquals.ts b/src/decorator/common/NotEquals.ts index ec5ecdefc0..2cd631b08c 100644 --- a/src/decorator/common/NotEquals.ts +++ b/src/decorator/common/NotEquals.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const NOT_EQUALS = 'notEquals'; diff --git a/src/decorator/common/Validate.ts b/src/decorator/common/Validate.ts index 59c80cdd08..0028c702c0 100644 --- a/src/decorator/common/Validate.ts +++ b/src/decorator/common/Validate.ts @@ -1,9 +1,9 @@ -import { ValidationOptions } from '../ValidationOptions'; -import { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs'; -import { ValidationMetadata } from '../../metadata/ValidationMetadata'; -import { getMetadataStorage } from '../../metadata/MetadataStorage'; -import { ValidationTypes } from '../../validation/ValidationTypes'; -import { ConstraintMetadata } from '../../metadata/ConstraintMetadata'; +import { ValidationOptions } from '../../ValidationOptions'; +import { ValidationMetadataArgs } from '../../../metadata/ValidationMetadataArgs'; +import { ValidationMetadata } from '../../../metadata/ValidationMetadata'; +import { getMetadataStorage } from '../../../metadata/MetadataStorage'; +import { ValidationTypes } from '../../../validation/ValidationTypes'; +import { ConstraintMetadata } from '../../../metadata/ConstraintMetadata'; /** * Registers custom validator class. diff --git a/src/decorator/common/ValidateBy.ts b/src/decorator/common/ValidateBy.ts index 641cb00a06..6e15396770 100644 --- a/src/decorator/common/ValidateBy.ts +++ b/src/decorator/common/ValidateBy.ts @@ -1,7 +1,7 @@ -import { ValidationOptions } from '../ValidationOptions'; -import { registerDecorator } from '../../register-decorator'; -import { ValidationArguments } from '../../validation/ValidationArguments'; -import { ValidatorConstraintInterface } from '../../validation/ValidatorConstraintInterface'; +import { ValidationOptions } from '../../ValidationOptions'; +import { registerDecorator } from '../../../register-decorator'; +import { ValidationArguments } from '../../../validation/ValidationArguments'; +import { ValidatorConstraintInterface } from '../../../validation/ValidatorConstraintInterface'; export interface ValidateByOptions { name: string; diff --git a/src/decorator/common/ValidateIf.ts b/src/decorator/common/ValidateIf.ts index 14f1deeb77..e6861ed4e3 100644 --- a/src/decorator/common/ValidateIf.ts +++ b/src/decorator/common/ValidateIf.ts @@ -1,8 +1,8 @@ -import { ValidationOptions } from '../ValidationOptions'; -import { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs'; -import { ValidationTypes } from '../../validation/ValidationTypes'; -import { ValidationMetadata } from '../../metadata/ValidationMetadata'; -import { getMetadataStorage } from '../../metadata/MetadataStorage'; +import { ValidationOptions } from '../../ValidationOptions'; +import { ValidationMetadataArgs } from '../../../metadata/ValidationMetadataArgs'; +import { ValidationTypes } from '../../../validation/ValidationTypes'; +import { ValidationMetadata } from '../../../metadata/ValidationMetadata'; +import { getMetadataStorage } from '../../../metadata/MetadataStorage'; /** * Ignores the other validators on a property when the provided condition function returns false. diff --git a/src/decorator/common/ValidateNested.ts b/src/decorator/common/ValidateNested.ts index da56eaefa4..2fd12bb998 100644 --- a/src/decorator/common/ValidateNested.ts +++ b/src/decorator/common/ValidateNested.ts @@ -1,8 +1,8 @@ -import { ValidationOptions } from '../ValidationOptions'; -import { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs'; -import { ValidationTypes } from '../../validation/ValidationTypes'; -import { ValidationMetadata } from '../../metadata/ValidationMetadata'; -import { getMetadataStorage } from '../../metadata/MetadataStorage'; +import { ValidationOptions } from '../../ValidationOptions'; +import { ValidationMetadataArgs } from '../../../metadata/ValidationMetadataArgs'; +import { ValidationTypes } from '../../../validation/ValidationTypes'; +import { ValidationMetadata } from '../../../metadata/ValidationMetadata'; +import { getMetadataStorage } from '../../../metadata/MetadataStorage'; /** * Objects / object arrays marked with this decorator will also be validated. diff --git a/src/decorator/common/ValidatePromise.ts b/src/decorator/common/ValidatePromise.ts index bd90519e86..0f202d197e 100644 --- a/src/decorator/common/ValidatePromise.ts +++ b/src/decorator/common/ValidatePromise.ts @@ -1,8 +1,8 @@ -import { ValidationOptions } from '../ValidationOptions'; -import { ValidationMetadataArgs } from '../../metadata/ValidationMetadataArgs'; -import { ValidationTypes } from '../../validation/ValidationTypes'; -import { ValidationMetadata } from '../../metadata/ValidationMetadata'; -import { getMetadataStorage } from '../../metadata/MetadataStorage'; +import { ValidationOptions } from '../../ValidationOptions'; +import { ValidationMetadataArgs } from '../../../metadata/ValidationMetadataArgs'; +import { ValidationTypes } from '../../../validation/ValidationTypes'; +import { ValidationMetadata } from '../../../metadata/ValidationMetadata'; +import { getMetadataStorage } from '../../../metadata/MetadataStorage'; /** * Resolve promise before validation diff --git a/src/decorator/date/MaxDate.ts b/src/decorator/date/MaxDate.ts index 2bd062539f..3eb6d8d379 100644 --- a/src/decorator/date/MaxDate.ts +++ b/src/decorator/date/MaxDate.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const MAX_DATE = 'maxDate'; diff --git a/src/decorator/date/MinDate.ts b/src/decorator/date/MinDate.ts index a0855e798e..066fa61b0a 100644 --- a/src/decorator/date/MinDate.ts +++ b/src/decorator/date/MinDate.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const MIN_DATE = 'minDate'; diff --git a/src/decorator/decorators.ts b/src/decorator/decorators.ts index d449e9301a..9a608c72cc 100644 --- a/src/decorator/decorators.ts +++ b/src/decorator/decorators.ts @@ -1,149 +1,161 @@ // ------------------------------------------------------------------------- -// System +// System: property decorators // ------------------------------------------------------------------------- // ------------------------------------------------------------------------- // Common checkers // ------------------------------------------------------------------------- -export * from './common/Allow'; -export * from './common/IsDefined'; -export * from './common/IsOptional'; -export * from './common/Validate'; -export * from './common/ValidateBy'; -export * from './common/ValidateIf'; -export * from './common/ValidateNested'; -export * from './common/ValidatePromise'; -export * from './common/IsLatLong'; -export * from './common/IsLatitude'; -export * from './common/IsLongitude'; -export * from './common/Equals'; -export * from './common/NotEquals'; -export * from './common/IsEmpty'; -export * from './common/IsNotEmpty'; -export * from './common/IsIn'; -export * from './common/IsNotIn'; +export * from './property/common/Allow'; +export * from './property/common/IsDefined'; +export * from './property/common/IsOptional'; +export * from './property/common/Validate'; +export * from './property/common/ValidateBy'; +export * from './property/common/ValidateIf'; +export * from './property/common/ValidateNested'; +export * from './property/common/ValidatePromise'; +export * from './property/common/IsLatLong'; +export * from './property/common/IsLatitude'; +export * from './property/common/IsLongitude'; +export * from './property/common/Equals'; +export * from './property/common/NotEquals'; +export * from './property/common/IsEmpty'; +export * from './property/common/IsNotEmpty'; +export * from './property/common/IsIn'; +export * from './property/common/IsNotIn'; // ------------------------------------------------------------------------- // Number checkers // ------------------------------------------------------------------------- -export * from './number/IsDivisibleBy'; -export * from './number/IsPositive'; -export * from './number/IsNegative'; -export * from './number/Max'; -export * from './number/Min'; +export * from './property/number/IsDivisibleBy'; +export * from './property/number/IsPositive'; +export * from './property/number/IsNegative'; +export * from './property/number/Max'; +export * from './property/number/Min'; // ------------------------------------------------------------------------- // Date checkers // ------------------------------------------------------------------------- -export * from './date/MinDate'; -export * from './date/MaxDate'; +export * from './property/date/MinDate'; +export * from './property/date/MaxDate'; // ------------------------------------------------------------------------- // String checkers // ------------------------------------------------------------------------- -export * from './string/Contains'; -export * from './string/NotContains'; -export * from './string/IsAlpha'; -export * from './string/IsAlphanumeric'; -export * from './string/IsDecimal'; -export * from './string/IsAscii'; -export * from './string/IsBase64'; -export * from './string/IsByteLength'; -export * from './string/IsCreditCard'; -export * from './string/IsCurrency'; -export * from './string/IsEmail'; -export * from './string/IsFQDN'; -export * from './string/IsFullWidth'; -export * from './string/IsHalfWidth'; -export * from './string/IsVariableWidth'; -export * from './string/IsHexColor'; -export * from './string/IsHexadecimal'; -export * from './string/IsMacAddress'; -export * from './string/IsIP'; -export * from './string/IsPort'; -export * from './string/IsISBN'; -export * from './string/IsISIN'; -export * from './string/IsISO8601'; -export * from './string/IsJSON'; -export * from './string/IsJWT'; -export * from './string/IsLowercase'; -export * from './string/IsMobilePhone'; -export * from './string/IsISO31661Alpha2'; -export * from './string/IsISO31661Alpha3'; -export * from './string/IsMongoId'; -export * from './string/IsMultibyte'; -export * from './string/IsSurrogatePair'; -export * from './string/IsUrl'; -export * from './string/IsUUID'; -export * from './string/IsFirebasePushId'; -export * from './string/IsUppercase'; -export * from './string/Length'; -export * from './string/MaxLength'; -export * from './string/MinLength'; -export * from './string/Matches'; -export * from './string/IsPhoneNumber'; -export * from './string/IsMilitaryTime'; -export * from './string/IsHash'; -export * from './string/IsISSN'; -export * from './string/IsDateString'; -export * from './string/IsBooleanString'; -export * from './string/IsNumberString'; -export * from './string/IsBase32'; -export * from './string/IsBIC'; -export * from './string/IsBtcAddress'; -export * from './string/IsDataURI'; -export * from './string/IsEAN'; -export * from './string/IsEthereumAddress'; -export * from './string/IsHSL'; -export * from './string/IsIBAN'; -export * from './string/IsIdentityCard'; -export * from './string/IsISRC'; -export * from './string/IsLocale'; -export * from './string/IsMagnetURI'; -export * from './string/IsMimeType'; -export * from './string/IsOctal'; -export * from './string/IsPassportNumber'; -export * from './string/IsPostalCode'; -export * from './string/IsRFC3339'; -export * from './string/IsRgbColor'; -export * from './string/IsSemVer'; -export * from './string/IsStrongPassword'; -export * from './string/IsTimeZone'; -export * from './string/IsBase58'; -export * from './string/is-tax-id'; -export * from './string/is-iso4217-currency-code'; +export * from './property/string/Contains'; +export * from './property/string/NotContains'; +export * from './property/string/IsAlpha'; +export * from './property/string/IsAlphanumeric'; +export * from './property/string/IsDecimal'; +export * from './property/string/IsAscii'; +export * from './property/string/IsBase64'; +export * from './property/string/IsByteLength'; +export * from './property/string/IsCreditCard'; +export * from './property/string/IsCurrency'; +export * from './property/string/IsEmail'; +export * from './property/string/IsFQDN'; +export * from './property/string/IsFullWidth'; +export * from './property/string/IsHalfWidth'; +export * from './property/string/IsVariableWidth'; +export * from './property/string/IsHexColor'; +export * from './property/string/IsHexadecimal'; +export * from './property/string/IsMacAddress'; +export * from './property/string/IsIP'; +export * from './property/string/IsPort'; +export * from './property/string/IsISBN'; +export * from './property/string/IsISIN'; +export * from './property/string/IsISO8601'; +export * from './property/string/IsJSON'; +export * from './property/string/IsJWT'; +export * from './property/string/IsLowercase'; +export * from './property/string/IsMobilePhone'; +export * from './property/string/IsISO31661Alpha2'; +export * from './property/string/IsISO31661Alpha3'; +export * from './property/string/IsMongoId'; +export * from './property/string/IsMultibyte'; +export * from './property/string/IsSurrogatePair'; +export * from './property/string/IsUrl'; +export * from './property/string/IsUUID'; +export * from './property/string/IsFirebasePushId'; +export * from './property/string/IsUppercase'; +export * from './property/string/Length'; +export * from './property/string/MaxLength'; +export * from './property/string/MinLength'; +export * from './property/string/Matches'; +export * from './property/string/IsPhoneNumber'; +export * from './property/string/IsMilitaryTime'; +export * from './property/string/IsHash'; +export * from './property/string/IsISSN'; +export * from './property/string/IsDateString'; +export * from './property/string/IsBooleanString'; +export * from './property/string/IsNumberString'; +export * from './property/string/IsBase32'; +export * from './property/string/IsBIC'; +export * from './property/string/IsBtcAddress'; +export * from './property/string/IsDataURI'; +export * from './property/string/IsEAN'; +export * from './property/string/IsEthereumAddress'; +export * from './property/string/IsHSL'; +export * from './property/string/IsIBAN'; +export * from './property/string/IsIdentityCard'; +export * from './property/string/IsISRC'; +export * from './property/string/IsLocale'; +export * from './property/string/IsMagnetURI'; +export * from './property/string/IsMimeType'; +export * from './property/string/IsOctal'; +export * from './property/string/IsPassportNumber'; +export * from './property/string/IsPostalCode'; +export * from './property/string/IsRFC3339'; +export * from './property/string/IsRgbColor'; +export * from './property/string/IsSemVer'; +export * from './property/string/IsStrongPassword'; +export * from './property/string/IsTimeZone'; +export * from './property/string/IsBase58'; +export * from './property/string/is-tax-id'; +export * from './property/string/is-iso4217-currency-code'; // ------------------------------------------------------------------------- // Type checkers // ------------------------------------------------------------------------- -export * from './typechecker/IsBoolean'; -export * from './typechecker/IsDate'; -export * from './typechecker/IsNumber'; -export * from './typechecker/IsEnum'; -export * from './typechecker/IsInt'; -export * from './typechecker/IsString'; -export * from './typechecker/IsArray'; -export * from './typechecker/IsObject'; +export * from './property/typechecker/IsBoolean'; +export * from './property/typechecker/IsDate'; +export * from './property/typechecker/IsNumber'; +export * from './property/typechecker/IsEnum'; +export * from './property/typechecker/IsInt'; +export * from './property/typechecker/IsString'; +export * from './property/typechecker/IsArray'; +export * from './property/typechecker/IsObject'; // ------------------------------------------------------------------------- // Array checkers // ------------------------------------------------------------------------- -export * from './array/ArrayContains'; -export * from './array/ArrayNotContains'; -export * from './array/ArrayNotEmpty'; -export * from './array/ArrayMinSize'; -export * from './array/ArrayMaxSize'; -export * from './array/ArrayUnique'; +export * from './property/array/ArrayContains'; +export * from './property/array/ArrayNotContains'; +export * from './property/array/ArrayNotEmpty'; +export * from './property/array/ArrayMinSize'; +export * from './property/array/ArrayMaxSize'; +export * from './property/array/ArrayUnique'; // ------------------------------------------------------------------------- // Object checkers // ------------------------------------------------------------------------- -export * from './object/IsNotEmptyObject'; -export * from './object/IsInstance'; +export * from './property/object/IsNotEmptyObject'; +export * from './property/object/IsInstance'; + +// ------------------------------------------------------------------------- +// System: argument decorators +// ------------------------------------------------------------------------- + +export * from './argument'; + +// ------------------------------------------------------------------------- +// String checkers +// ------------------------------------------------------------------------- + +export * from './argument/is-not-empty'; diff --git a/src/decorator/number/IsDivisibleBy.ts b/src/decorator/number/IsDivisibleBy.ts index 439948c403..143692284f 100644 --- a/src/decorator/number/IsDivisibleBy.ts +++ b/src/decorator/number/IsDivisibleBy.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isDivisibleByValidator from 'validator/lib/isDivisibleBy'; diff --git a/src/decorator/number/IsNegative.ts b/src/decorator/number/IsNegative.ts index 85463760fa..dc4023e297 100644 --- a/src/decorator/number/IsNegative.ts +++ b/src/decorator/number/IsNegative.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_NEGATIVE = 'isNegative'; diff --git a/src/decorator/number/IsPositive.ts b/src/decorator/number/IsPositive.ts index 41c888d678..5da44571b6 100644 --- a/src/decorator/number/IsPositive.ts +++ b/src/decorator/number/IsPositive.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_POSITIVE = 'isPositive'; diff --git a/src/decorator/number/Max.ts b/src/decorator/number/Max.ts index d495af1893..8f0563831e 100644 --- a/src/decorator/number/Max.ts +++ b/src/decorator/number/Max.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const MAX = 'max'; diff --git a/src/decorator/number/Min.ts b/src/decorator/number/Min.ts index 22d665d0a3..319ee89756 100644 --- a/src/decorator/number/Min.ts +++ b/src/decorator/number/Min.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const MIN = 'min'; diff --git a/src/decorator/object/IsInstance.ts b/src/decorator/object/IsInstance.ts index e265223ca7..9f8ebd58dc 100644 --- a/src/decorator/object/IsInstance.ts +++ b/src/decorator/object/IsInstance.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_INSTANCE = 'isInstance'; diff --git a/src/decorator/object/IsNotEmptyObject.ts b/src/decorator/object/IsNotEmptyObject.ts index 64aada8014..03a5119d8c 100644 --- a/src/decorator/object/IsNotEmptyObject.ts +++ b/src/decorator/object/IsNotEmptyObject.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import { isObject } from '../typechecker/IsObject'; diff --git a/src/decorator/string/Contains.ts b/src/decorator/string/Contains.ts index da2cc335c8..1c2d8c6cc6 100644 --- a/src/decorator/string/Contains.ts +++ b/src/decorator/string/Contains.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import containsValidator from 'validator/lib/contains'; diff --git a/src/decorator/string/IsAlpha.ts b/src/decorator/string/IsAlpha.ts index 090007b390..c14044b1b7 100644 --- a/src/decorator/string/IsAlpha.ts +++ b/src/decorator/string/IsAlpha.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isAlphaValidator from 'validator/lib/isAlpha'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsAlphanumeric.ts b/src/decorator/string/IsAlphanumeric.ts index f0dc2e5f89..9aa771c18c 100644 --- a/src/decorator/string/IsAlphanumeric.ts +++ b/src/decorator/string/IsAlphanumeric.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isAlphanumericValidator from 'validator/lib/isAlphanumeric'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsAscii.ts b/src/decorator/string/IsAscii.ts index 05f74725dd..4aca944997 100644 --- a/src/decorator/string/IsAscii.ts +++ b/src/decorator/string/IsAscii.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isAsciiValidator from 'validator/lib/isAscii'; diff --git a/src/decorator/string/IsBIC.ts b/src/decorator/string/IsBIC.ts index b530e67758..53adf0afd3 100644 --- a/src/decorator/string/IsBIC.ts +++ b/src/decorator/string/IsBIC.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isBICValidator from 'validator/lib/isBIC'; diff --git a/src/decorator/string/IsBase32.ts b/src/decorator/string/IsBase32.ts index 99958d0d3e..5b965dd265 100644 --- a/src/decorator/string/IsBase32.ts +++ b/src/decorator/string/IsBase32.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isBase32Validator from 'validator/lib/isBase32'; diff --git a/src/decorator/string/IsBase58.ts b/src/decorator/string/IsBase58.ts index cd474a0c2c..3834a0b94a 100644 --- a/src/decorator/string/IsBase58.ts +++ b/src/decorator/string/IsBase58.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isBase58Validator from 'validator/lib/isBase58'; diff --git a/src/decorator/string/IsBase64.ts b/src/decorator/string/IsBase64.ts index 2c5cd3e5be..cc4c3f46ad 100644 --- a/src/decorator/string/IsBase64.ts +++ b/src/decorator/string/IsBase64.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isBase64Validator from 'validator/lib/isBase64'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsBooleanString.ts b/src/decorator/string/IsBooleanString.ts index e53d71b37b..90e58f4ae9 100644 --- a/src/decorator/string/IsBooleanString.ts +++ b/src/decorator/string/IsBooleanString.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isBooleanValidator from 'validator/lib/isBoolean'; diff --git a/src/decorator/string/IsBtcAddress.ts b/src/decorator/string/IsBtcAddress.ts index f9162adcec..58a724071f 100644 --- a/src/decorator/string/IsBtcAddress.ts +++ b/src/decorator/string/IsBtcAddress.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isBtcAddressValidator from 'validator/lib/isBtcAddress'; diff --git a/src/decorator/string/IsByteLength.ts b/src/decorator/string/IsByteLength.ts index 334e209733..89aab585f9 100644 --- a/src/decorator/string/IsByteLength.ts +++ b/src/decorator/string/IsByteLength.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isByteLengthValidator from 'validator/lib/isByteLength'; diff --git a/src/decorator/string/IsCreditCard.ts b/src/decorator/string/IsCreditCard.ts index 2511d1930c..0ca8732cbb 100644 --- a/src/decorator/string/IsCreditCard.ts +++ b/src/decorator/string/IsCreditCard.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isCreditCardValidator from 'validator/lib/isCreditCard'; diff --git a/src/decorator/string/IsCurrency.ts b/src/decorator/string/IsCurrency.ts index 8ebfdd9366..ecd06e56c4 100644 --- a/src/decorator/string/IsCurrency.ts +++ b/src/decorator/string/IsCurrency.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isCurrencyValidator from 'validator/lib/isCurrency'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsDataURI.ts b/src/decorator/string/IsDataURI.ts index f07e5fefae..3c7ea47c10 100644 --- a/src/decorator/string/IsDataURI.ts +++ b/src/decorator/string/IsDataURI.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isDataURIValidator from 'validator/lib/isDataURI'; diff --git a/src/decorator/string/IsDateString.ts b/src/decorator/string/IsDateString.ts index 5fd91af73d..c69c38f285 100644 --- a/src/decorator/string/IsDateString.ts +++ b/src/decorator/string/IsDateString.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import * as ValidatorJS from 'validator'; import { isISO8601 } from './IsISO8601'; diff --git a/src/decorator/string/IsDecimal.ts b/src/decorator/string/IsDecimal.ts index 3996d296fc..f4da49bf06 100644 --- a/src/decorator/string/IsDecimal.ts +++ b/src/decorator/string/IsDecimal.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isDecimalValidator from 'validator/lib/isDecimal'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsEAN.ts b/src/decorator/string/IsEAN.ts index 73669e969a..9ec6f2b276 100644 --- a/src/decorator/string/IsEAN.ts +++ b/src/decorator/string/IsEAN.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isEANValidator from 'validator/lib/isEAN'; diff --git a/src/decorator/string/IsEmail.ts b/src/decorator/string/IsEmail.ts index 790ee44c51..f8b1e0c43b 100644 --- a/src/decorator/string/IsEmail.ts +++ b/src/decorator/string/IsEmail.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isEmailValidator from 'validator/lib/isEmail'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsEthereumAddress.ts b/src/decorator/string/IsEthereumAddress.ts index cf8dbdbb1b..d5e4156d84 100644 --- a/src/decorator/string/IsEthereumAddress.ts +++ b/src/decorator/string/IsEthereumAddress.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isEthereumAddressValidator from 'validator/lib/isEthereumAddress'; diff --git a/src/decorator/string/IsFQDN.ts b/src/decorator/string/IsFQDN.ts index 3c6683d68e..ab11ca2183 100644 --- a/src/decorator/string/IsFQDN.ts +++ b/src/decorator/string/IsFQDN.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isFqdnValidator from 'validator/lib/isFQDN'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsFirebasePushId.ts b/src/decorator/string/IsFirebasePushId.ts index 1d81230c7b..178c9c0052 100644 --- a/src/decorator/string/IsFirebasePushId.ts +++ b/src/decorator/string/IsFirebasePushId.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_FIREBASE_PUSH_ID = 'IsFirebasePushId'; diff --git a/src/decorator/string/IsFullWidth.ts b/src/decorator/string/IsFullWidth.ts index cb9a7cc3a5..24af3a0785 100644 --- a/src/decorator/string/IsFullWidth.ts +++ b/src/decorator/string/IsFullWidth.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isFullWidthValidator from 'validator/lib/isFullWidth'; diff --git a/src/decorator/string/IsHSL.ts b/src/decorator/string/IsHSL.ts index 401cbc6fb1..127f0e8bfb 100644 --- a/src/decorator/string/IsHSL.ts +++ b/src/decorator/string/IsHSL.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isHSLValidator from 'validator/lib/isHSL'; diff --git a/src/decorator/string/IsHalfWidth.ts b/src/decorator/string/IsHalfWidth.ts index 0f04c94348..28042fdf99 100644 --- a/src/decorator/string/IsHalfWidth.ts +++ b/src/decorator/string/IsHalfWidth.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isHalfWidthValidator from 'validator/lib/isHalfWidth'; diff --git a/src/decorator/string/IsHash.ts b/src/decorator/string/IsHash.ts index 0794de5844..b355fa8c40 100644 --- a/src/decorator/string/IsHash.ts +++ b/src/decorator/string/IsHash.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isHashValidator from 'validator/lib/isHash'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsHexColor.ts b/src/decorator/string/IsHexColor.ts index c72c471135..96690f998d 100644 --- a/src/decorator/string/IsHexColor.ts +++ b/src/decorator/string/IsHexColor.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isHexColorValidator from 'validator/lib/isHexColor'; diff --git a/src/decorator/string/IsHexadecimal.ts b/src/decorator/string/IsHexadecimal.ts index 26d3eb3e34..6d29d8f178 100644 --- a/src/decorator/string/IsHexadecimal.ts +++ b/src/decorator/string/IsHexadecimal.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isHexadecimalValidator from 'validator/lib/isHexadecimal'; diff --git a/src/decorator/string/IsIBAN.ts b/src/decorator/string/IsIBAN.ts index d0a159fc83..70b62a3756 100644 --- a/src/decorator/string/IsIBAN.ts +++ b/src/decorator/string/IsIBAN.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isIBANValidator from 'validator/lib/isIBAN'; diff --git a/src/decorator/string/IsIP.ts b/src/decorator/string/IsIP.ts index 01fc55d2aa..1cfa472fe8 100644 --- a/src/decorator/string/IsIP.ts +++ b/src/decorator/string/IsIP.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isIPValidator from 'validator/lib/isIP'; diff --git a/src/decorator/string/IsISBN.ts b/src/decorator/string/IsISBN.ts index 336d62c61d..c1a79f83b2 100644 --- a/src/decorator/string/IsISBN.ts +++ b/src/decorator/string/IsISBN.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isIsbnValidator from 'validator/lib/isISBN'; diff --git a/src/decorator/string/IsISIN.ts b/src/decorator/string/IsISIN.ts index 2f9b143b1d..d301d6186d 100644 --- a/src/decorator/string/IsISIN.ts +++ b/src/decorator/string/IsISIN.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isIsinValidator from 'validator/lib/isISIN'; diff --git a/src/decorator/string/IsISO31661Alpha2.ts b/src/decorator/string/IsISO31661Alpha2.ts index 87b19551ae..ef4c2134e9 100644 --- a/src/decorator/string/IsISO31661Alpha2.ts +++ b/src/decorator/string/IsISO31661Alpha2.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isISO31661Alpha2Validator from 'validator/lib/isISO31661Alpha2'; diff --git a/src/decorator/string/IsISO31661Alpha3.ts b/src/decorator/string/IsISO31661Alpha3.ts index bf43ff519b..b91edf3642 100644 --- a/src/decorator/string/IsISO31661Alpha3.ts +++ b/src/decorator/string/IsISO31661Alpha3.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isISO31661Alpha3Validator from 'validator/lib/isISO31661Alpha3'; diff --git a/src/decorator/string/IsISO8601.ts b/src/decorator/string/IsISO8601.ts index ca1f771851..6e9368d394 100644 --- a/src/decorator/string/IsISO8601.ts +++ b/src/decorator/string/IsISO8601.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isIso8601Validator from 'validator/lib/isISO8601'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsISRC.ts b/src/decorator/string/IsISRC.ts index f41b3c3cdc..d931fa9aac 100644 --- a/src/decorator/string/IsISRC.ts +++ b/src/decorator/string/IsISRC.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isISRCValidator from 'validator/lib/isISRC'; diff --git a/src/decorator/string/IsISSN.ts b/src/decorator/string/IsISSN.ts index 6227976882..a981f43143 100644 --- a/src/decorator/string/IsISSN.ts +++ b/src/decorator/string/IsISSN.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isISSNValidator from 'validator/lib/isISSN'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsIdentityCard.ts b/src/decorator/string/IsIdentityCard.ts index 54834f8f84..4c37ebcc56 100644 --- a/src/decorator/string/IsIdentityCard.ts +++ b/src/decorator/string/IsIdentityCard.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isIdentityCardValidator from 'validator/lib/isIdentityCard'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsJSON.ts b/src/decorator/string/IsJSON.ts index 2bdf8f04b9..a58cda8a1b 100644 --- a/src/decorator/string/IsJSON.ts +++ b/src/decorator/string/IsJSON.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isJSONValidator from 'validator/lib/isJSON'; diff --git a/src/decorator/string/IsJWT.ts b/src/decorator/string/IsJWT.ts index 69ecc900a7..6eab037df3 100644 --- a/src/decorator/string/IsJWT.ts +++ b/src/decorator/string/IsJWT.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isJwtValidator from 'validator/lib/isJWT'; diff --git a/src/decorator/string/IsLocale.ts b/src/decorator/string/IsLocale.ts index 043ddf2510..71e1ac3895 100644 --- a/src/decorator/string/IsLocale.ts +++ b/src/decorator/string/IsLocale.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isLocaleValidator from 'validator/lib/isLocale'; diff --git a/src/decorator/string/IsLowercase.ts b/src/decorator/string/IsLowercase.ts index 1042dadcfd..55855fa325 100644 --- a/src/decorator/string/IsLowercase.ts +++ b/src/decorator/string/IsLowercase.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isLowercaseValidator from 'validator/lib/isLowercase'; diff --git a/src/decorator/string/IsMacAddress.ts b/src/decorator/string/IsMacAddress.ts index f2e3ea745f..130c7d3267 100644 --- a/src/decorator/string/IsMacAddress.ts +++ b/src/decorator/string/IsMacAddress.ts @@ -1,4 +1,4 @@ -import { ValidationOptions, isValidationOptions } from '../ValidationOptions'; +import { ValidationOptions, isValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isMacAddressValidator from 'validator/lib/isMACAddress'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsMagnetURI.ts b/src/decorator/string/IsMagnetURI.ts index a4758dca65..176c1f10a6 100644 --- a/src/decorator/string/IsMagnetURI.ts +++ b/src/decorator/string/IsMagnetURI.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isMagnetURIValidator from 'validator/lib/isMagnetURI'; diff --git a/src/decorator/string/IsMilitaryTime.ts b/src/decorator/string/IsMilitaryTime.ts index 6d209b2ac1..fdfddef558 100644 --- a/src/decorator/string/IsMilitaryTime.ts +++ b/src/decorator/string/IsMilitaryTime.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import matchesValidator from 'validator/lib/matches'; diff --git a/src/decorator/string/IsMimeType.ts b/src/decorator/string/IsMimeType.ts index edc5136953..576380bccb 100644 --- a/src/decorator/string/IsMimeType.ts +++ b/src/decorator/string/IsMimeType.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isMimeTypeValidator from 'validator/lib/isMimeType'; diff --git a/src/decorator/string/IsMobilePhone.ts b/src/decorator/string/IsMobilePhone.ts index 34859b5007..16983fd74c 100644 --- a/src/decorator/string/IsMobilePhone.ts +++ b/src/decorator/string/IsMobilePhone.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isMobilePhoneValidator from 'validator/lib/isMobilePhone'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsMongoId.ts b/src/decorator/string/IsMongoId.ts index fa8507fb66..fe5043c357 100644 --- a/src/decorator/string/IsMongoId.ts +++ b/src/decorator/string/IsMongoId.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isMongoIdValidator from 'validator/lib/isMongoId'; diff --git a/src/decorator/string/IsMultibyte.ts b/src/decorator/string/IsMultibyte.ts index c295b640c9..d9ba6c9f43 100644 --- a/src/decorator/string/IsMultibyte.ts +++ b/src/decorator/string/IsMultibyte.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isMultibyteValidator from 'validator/lib/isMultibyte'; diff --git a/src/decorator/string/IsNumberString.ts b/src/decorator/string/IsNumberString.ts index 45f6b67c25..e03f4e2617 100644 --- a/src/decorator/string/IsNumberString.ts +++ b/src/decorator/string/IsNumberString.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isNumericValidator from 'validator/lib/isNumeric'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsOctal.ts b/src/decorator/string/IsOctal.ts index 4427926455..aa65b26909 100644 --- a/src/decorator/string/IsOctal.ts +++ b/src/decorator/string/IsOctal.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isOctalValidator from 'validator/lib/isOctal'; diff --git a/src/decorator/string/IsPassportNumber.ts b/src/decorator/string/IsPassportNumber.ts index e900aeed2e..7e5a155ee9 100644 --- a/src/decorator/string/IsPassportNumber.ts +++ b/src/decorator/string/IsPassportNumber.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isPassportNumberValidator from 'validator/lib/isPassportNumber'; diff --git a/src/decorator/string/IsPhoneNumber.ts b/src/decorator/string/IsPhoneNumber.ts index 65744a99ab..a2280285e5 100644 --- a/src/decorator/string/IsPhoneNumber.ts +++ b/src/decorator/string/IsPhoneNumber.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import { parsePhoneNumber, CountryCode } from 'libphonenumber-js/max'; diff --git a/src/decorator/string/IsPort.ts b/src/decorator/string/IsPort.ts index d7809e3c42..7b2c8bbdc0 100644 --- a/src/decorator/string/IsPort.ts +++ b/src/decorator/string/IsPort.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isPortValidator from 'validator/lib/isPort'; diff --git a/src/decorator/string/IsPostalCode.ts b/src/decorator/string/IsPostalCode.ts index 507a462c64..1136b02f6f 100644 --- a/src/decorator/string/IsPostalCode.ts +++ b/src/decorator/string/IsPostalCode.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isPostalCodeValidator from 'validator/lib/isPostalCode'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsRFC3339.ts b/src/decorator/string/IsRFC3339.ts index 88262b79a5..a1d47721ed 100644 --- a/src/decorator/string/IsRFC3339.ts +++ b/src/decorator/string/IsRFC3339.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isRFC3339Validator from 'validator/lib/isRFC3339'; diff --git a/src/decorator/string/IsRgbColor.ts b/src/decorator/string/IsRgbColor.ts index 0fc56cc5dd..0a9f838396 100644 --- a/src/decorator/string/IsRgbColor.ts +++ b/src/decorator/string/IsRgbColor.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isRgbColorValidator from 'validator/lib/isRgbColor'; diff --git a/src/decorator/string/IsSemVer.ts b/src/decorator/string/IsSemVer.ts index e599655085..d56482f0d8 100644 --- a/src/decorator/string/IsSemVer.ts +++ b/src/decorator/string/IsSemVer.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isSemVerValidator from 'validator/lib/isSemVer'; diff --git a/src/decorator/string/IsStrongPassword.ts b/src/decorator/string/IsStrongPassword.ts index 31e6f918a3..9da32df180 100644 --- a/src/decorator/string/IsStrongPassword.ts +++ b/src/decorator/string/IsStrongPassword.ts @@ -1,5 +1,5 @@ import * as validator from 'validator'; -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_STRONG_PASSWORD = 'isStrongPassword'; diff --git a/src/decorator/string/IsSurrogatePair.ts b/src/decorator/string/IsSurrogatePair.ts index 8cd7e2a8d0..2a715ef92e 100644 --- a/src/decorator/string/IsSurrogatePair.ts +++ b/src/decorator/string/IsSurrogatePair.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isSurrogatePairValidator from 'validator/lib/isSurrogatePair'; diff --git a/src/decorator/string/IsTimeZone.ts b/src/decorator/string/IsTimeZone.ts index 3504d0aa6b..11068c2feb 100644 --- a/src/decorator/string/IsTimeZone.ts +++ b/src/decorator/string/IsTimeZone.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_TIMEZONE = 'isTimeZone'; diff --git a/src/decorator/string/IsUUID.ts b/src/decorator/string/IsUUID.ts index a1ac241cf6..37b6c10e25 100644 --- a/src/decorator/string/IsUUID.ts +++ b/src/decorator/string/IsUUID.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isUuidValidator from 'validator/lib/isUUID'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsUppercase.ts b/src/decorator/string/IsUppercase.ts index 2e22354082..3fa34d2dff 100644 --- a/src/decorator/string/IsUppercase.ts +++ b/src/decorator/string/IsUppercase.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isUppercaseValidator from 'validator/lib/isUppercase'; diff --git a/src/decorator/string/IsUrl.ts b/src/decorator/string/IsUrl.ts index 0ea6dda3a0..09db1f65c0 100644 --- a/src/decorator/string/IsUrl.ts +++ b/src/decorator/string/IsUrl.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isUrlValidator from 'validator/lib/isURL'; import * as ValidatorJS from 'validator'; diff --git a/src/decorator/string/IsVariableWidth.ts b/src/decorator/string/IsVariableWidth.ts index 0eb4d312d3..13a5be6585 100644 --- a/src/decorator/string/IsVariableWidth.ts +++ b/src/decorator/string/IsVariableWidth.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isVariableWidthValidator from 'validator/lib/isVariableWidth'; diff --git a/src/decorator/string/Length.ts b/src/decorator/string/Length.ts index 04427bdfb7..6adfd7bce3 100644 --- a/src/decorator/string/Length.ts +++ b/src/decorator/string/Length.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isLengthValidator from 'validator/lib/isLength'; diff --git a/src/decorator/string/Matches.ts b/src/decorator/string/Matches.ts index 403d5a6f15..f82c599fbe 100644 --- a/src/decorator/string/Matches.ts +++ b/src/decorator/string/Matches.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import matchesValidator from 'validator/lib/matches'; diff --git a/src/decorator/string/MaxLength.ts b/src/decorator/string/MaxLength.ts index 78dc194ccf..7c14373a28 100644 --- a/src/decorator/string/MaxLength.ts +++ b/src/decorator/string/MaxLength.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isLengthValidator from 'validator/lib/isLength'; diff --git a/src/decorator/string/MinLength.ts b/src/decorator/string/MinLength.ts index 050a51be26..5e0e3a5b49 100644 --- a/src/decorator/string/MinLength.ts +++ b/src/decorator/string/MinLength.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isLengthValidator from 'validator/lib/isLength'; diff --git a/src/decorator/string/NotContains.ts b/src/decorator/string/NotContains.ts index 5db77b9de0..f31f0be523 100644 --- a/src/decorator/string/NotContains.ts +++ b/src/decorator/string/NotContains.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import containsValidator from 'validator/lib/contains'; diff --git a/src/decorator/string/is-iso4217-currency-code.ts b/src/decorator/string/is-iso4217-currency-code.ts index 903620a146..b6bc2ed462 100644 --- a/src/decorator/string/is-iso4217-currency-code.ts +++ b/src/decorator/string/is-iso4217-currency-code.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isISO4217Validator from 'validator/lib/isISO4217'; diff --git a/src/decorator/string/is-tax-id.ts b/src/decorator/string/is-tax-id.ts index 950852f190..83f729d5c4 100644 --- a/src/decorator/string/is-tax-id.ts +++ b/src/decorator/string/is-tax-id.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; import isTaxIDValidator from 'validator/lib/isTaxID'; diff --git a/src/decorator/typechecker/IsArray.ts b/src/decorator/typechecker/IsArray.ts index 7e5f43d7de..fc034d0d71 100644 --- a/src/decorator/typechecker/IsArray.ts +++ b/src/decorator/typechecker/IsArray.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_ARRAY = 'isArray'; diff --git a/src/decorator/typechecker/IsBoolean.ts b/src/decorator/typechecker/IsBoolean.ts index 187638de22..a000054d48 100644 --- a/src/decorator/typechecker/IsBoolean.ts +++ b/src/decorator/typechecker/IsBoolean.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_BOOLEAN = 'isBoolean'; diff --git a/src/decorator/typechecker/IsDate.ts b/src/decorator/typechecker/IsDate.ts index ea12e927f8..8c11f7864b 100644 --- a/src/decorator/typechecker/IsDate.ts +++ b/src/decorator/typechecker/IsDate.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_DATE = 'isDate'; diff --git a/src/decorator/typechecker/IsEnum.ts b/src/decorator/typechecker/IsEnum.ts index eb3d6b064b..94e81cdfd0 100644 --- a/src/decorator/typechecker/IsEnum.ts +++ b/src/decorator/typechecker/IsEnum.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_ENUM = 'isEnum'; diff --git a/src/decorator/typechecker/IsInt.ts b/src/decorator/typechecker/IsInt.ts index 50f822841d..efedfafa54 100644 --- a/src/decorator/typechecker/IsInt.ts +++ b/src/decorator/typechecker/IsInt.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_INT = 'isInt'; diff --git a/src/decorator/typechecker/IsNumber.ts b/src/decorator/typechecker/IsNumber.ts index 5b6e67c13c..98a2ead78a 100644 --- a/src/decorator/typechecker/IsNumber.ts +++ b/src/decorator/typechecker/IsNumber.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_NUMBER = 'isNumber'; diff --git a/src/decorator/typechecker/IsObject.ts b/src/decorator/typechecker/IsObject.ts index 5cbd415b67..43325515fb 100644 --- a/src/decorator/typechecker/IsObject.ts +++ b/src/decorator/typechecker/IsObject.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_OBJECT = 'isObject'; diff --git a/src/decorator/typechecker/IsString.ts b/src/decorator/typechecker/IsString.ts index 4c309cd622..4524fc9025 100644 --- a/src/decorator/typechecker/IsString.ts +++ b/src/decorator/typechecker/IsString.ts @@ -1,4 +1,4 @@ -import { ValidationOptions } from '../ValidationOptions'; +import { ValidationOptions } from '../../ValidationOptions'; import { buildMessage, ValidateBy } from '../common/ValidateBy'; export const IS_STRING = 'isString'; diff --git a/test/functional/method-argument-decorators.spec.ts b/test/functional/method-argument-decorators.spec.ts new file mode 100644 index 0000000000..1de3720fea --- /dev/null +++ b/test/functional/method-argument-decorators.spec.ts @@ -0,0 +1,20 @@ +import { ValidateArguments } from "../../src/decorator/argument"; +import { IsNotEmptyArgument } from "../../src/decorator/argument/is-not-empty"; + +describe('decorator for validating method arguments', () => { + class MyClass { + @ValidateArguments + testMethod(@IsNotEmptyArgument test: string, emptyArgument?: string): void { + const someVariable = `${test}`; + } + } + + it("IsNotEmpty should throw if argument is empty (null, undefined or an empty string)", () => { + const instance = new MyClass(); + + expect(() => instance.testMethod("")).toThrow(); + expect(() => instance.testMethod(null)).toThrow(); + expect(() => instance.testMethod(undefined)).toThrow(); + expect(() => instance.testMethod("test", undefined)).not.toThrow(); + }); +}); From 73f2de33552b058f8f51146dc92058649edafade Mon Sep 17 00:00:00 2001 From: Loparev Date: Tue, 12 Mar 2024 17:13:05 +0200 Subject: [PATCH 2/3] Pretty/lint fixes --- src/decorator/argument/index.ts | 36 +++++++++---------- src/decorator/argument/is-not-empty/index.ts | 14 +++----- .../is-not-empty/is-not-empty-validator.ts | 14 ++++---- .../{ => property}/array/ArrayContains.ts | 0 .../{ => property}/array/ArrayMaxSize.ts | 0 .../{ => property}/array/ArrayMinSize.ts | 0 .../{ => property}/array/ArrayNotContains.ts | 0 .../{ => property}/array/ArrayNotEmpty.ts | 0 .../{ => property}/array/ArrayUnique.ts | 0 src/decorator/{ => property}/common/Allow.ts | 0 src/decorator/{ => property}/common/Equals.ts | 0 .../{ => property}/common/IsDefined.ts | 0 .../{ => property}/common/IsEmpty.ts | 0 .../{ => property}/common/IsIn.spec.ts | 0 src/decorator/{ => property}/common/IsIn.ts | 0 .../{ => property}/common/IsLatLong.ts | 0 .../{ => property}/common/IsLatitude.ts | 0 .../{ => property}/common/IsLongitude.ts | 0 .../{ => property}/common/IsNotEmpty.ts | 0 .../{ => property}/common/IsNotIn.ts | 0 .../{ => property}/common/IsOptional.ts | 0 .../{ => property}/common/NotEquals.ts | 0 .../{ => property}/common/Validate.ts | 0 .../{ => property}/common/ValidateBy.ts | 0 .../{ => property}/common/ValidateIf.ts | 0 .../{ => property}/common/ValidateNested.ts | 0 .../{ => property}/common/ValidatePromise.ts | 0 src/decorator/{ => property}/date/MaxDate.ts | 0 src/decorator/{ => property}/date/MinDate.ts | 0 .../{ => property}/number/IsDivisibleBy.ts | 0 .../{ => property}/number/IsNegative.ts | 0 .../{ => property}/number/IsPositive.ts | 0 src/decorator/{ => property}/number/Max.ts | 0 src/decorator/{ => property}/number/Min.ts | 0 .../{ => property}/object/IsInstance.ts | 0 .../{ => property}/object/IsNotEmptyObject.ts | 0 .../{ => property}/string/Contains.ts | 0 .../{ => property}/string/IsAlpha.ts | 0 .../{ => property}/string/IsAlphanumeric.ts | 0 .../{ => property}/string/IsAscii.ts | 0 src/decorator/{ => property}/string/IsBIC.ts | 0 .../{ => property}/string/IsBase32.ts | 0 .../{ => property}/string/IsBase58.ts | 0 .../{ => property}/string/IsBase64.ts | 0 .../{ => property}/string/IsBooleanString.ts | 0 .../{ => property}/string/IsBtcAddress.ts | 0 .../{ => property}/string/IsByteLength.ts | 0 .../{ => property}/string/IsCreditCard.ts | 0 .../{ => property}/string/IsCurrency.ts | 0 .../{ => property}/string/IsDataURI.ts | 0 .../{ => property}/string/IsDateString.ts | 0 .../{ => property}/string/IsDecimal.ts | 0 src/decorator/{ => property}/string/IsEAN.ts | 0 .../{ => property}/string/IsEmail.ts | 0 .../string/IsEthereumAddress.ts | 0 src/decorator/{ => property}/string/IsFQDN.ts | 0 .../{ => property}/string/IsFirebasePushId.ts | 0 .../{ => property}/string/IsFullWidth.ts | 0 src/decorator/{ => property}/string/IsHSL.ts | 0 .../{ => property}/string/IsHalfWidth.ts | 0 src/decorator/{ => property}/string/IsHash.ts | 0 .../{ => property}/string/IsHexColor.ts | 0 .../{ => property}/string/IsHexadecimal.ts | 0 src/decorator/{ => property}/string/IsIBAN.ts | 0 src/decorator/{ => property}/string/IsIP.ts | 0 src/decorator/{ => property}/string/IsISBN.ts | 0 src/decorator/{ => property}/string/IsISIN.ts | 0 .../{ => property}/string/IsISO31661Alpha2.ts | 0 .../{ => property}/string/IsISO31661Alpha3.ts | 0 .../{ => property}/string/IsISO8601.ts | 0 src/decorator/{ => property}/string/IsISRC.ts | 0 src/decorator/{ => property}/string/IsISSN.ts | 0 .../{ => property}/string/IsIdentityCard.ts | 0 src/decorator/{ => property}/string/IsJSON.ts | 0 src/decorator/{ => property}/string/IsJWT.ts | 0 .../{ => property}/string/IsLocale.ts | 0 .../{ => property}/string/IsLowercase.ts | 0 .../{ => property}/string/IsMacAddress.ts | 0 .../{ => property}/string/IsMagnetURI.ts | 0 .../{ => property}/string/IsMilitaryTime.ts | 0 .../{ => property}/string/IsMimeType.ts | 0 .../{ => property}/string/IsMobilePhone.ts | 0 .../{ => property}/string/IsMongoId.ts | 0 .../{ => property}/string/IsMultibyte.ts | 0 .../{ => property}/string/IsNumberString.ts | 0 .../{ => property}/string/IsOctal.ts | 0 .../{ => property}/string/IsPassportNumber.ts | 0 .../string/IsPhoneNumber.spec.ts | 0 .../{ => property}/string/IsPhoneNumber.ts | 0 src/decorator/{ => property}/string/IsPort.ts | 0 .../{ => property}/string/IsPostalCode.ts | 0 .../{ => property}/string/IsRFC3339.ts | 0 .../{ => property}/string/IsRgbColor.ts | 0 .../{ => property}/string/IsSemVer.ts | 0 .../{ => property}/string/IsStrongPassword.ts | 0 .../{ => property}/string/IsSurrogatePair.ts | 0 .../{ => property}/string/IsTimeZone.ts | 0 src/decorator/{ => property}/string/IsUUID.ts | 0 .../{ => property}/string/IsUppercase.ts | 0 src/decorator/{ => property}/string/IsUrl.ts | 0 .../{ => property}/string/IsVariableWidth.ts | 0 src/decorator/{ => property}/string/Length.ts | 0 .../{ => property}/string/Matches.ts | 0 .../{ => property}/string/MaxLength.ts | 0 .../{ => property}/string/MinLength.ts | 0 .../{ => property}/string/NotContains.ts | 0 .../string/is-iso4217-currency-code.ts | 0 .../{ => property}/string/is-tax-id.ts | 0 .../{ => property}/typechecker/IsArray.ts | 0 .../{ => property}/typechecker/IsBoolean.ts | 0 .../{ => property}/typechecker/IsDate.ts | 0 .../{ => property}/typechecker/IsEnum.ts | 0 .../{ => property}/typechecker/IsInt.ts | 0 .../{ => property}/typechecker/IsNumber.ts | 0 .../{ => property}/typechecker/IsObject.ts | 0 .../{ => property}/typechecker/IsString.ts | 0 .../method-argument-decorators.spec.ts | 12 +++---- 117 files changed, 35 insertions(+), 41 deletions(-) rename src/decorator/{ => property}/array/ArrayContains.ts (100%) rename src/decorator/{ => property}/array/ArrayMaxSize.ts (100%) rename src/decorator/{ => property}/array/ArrayMinSize.ts (100%) rename src/decorator/{ => property}/array/ArrayNotContains.ts (100%) rename src/decorator/{ => property}/array/ArrayNotEmpty.ts (100%) rename src/decorator/{ => property}/array/ArrayUnique.ts (100%) rename src/decorator/{ => property}/common/Allow.ts (100%) rename src/decorator/{ => property}/common/Equals.ts (100%) rename src/decorator/{ => property}/common/IsDefined.ts (100%) rename src/decorator/{ => property}/common/IsEmpty.ts (100%) rename src/decorator/{ => property}/common/IsIn.spec.ts (100%) rename src/decorator/{ => property}/common/IsIn.ts (100%) rename src/decorator/{ => property}/common/IsLatLong.ts (100%) rename src/decorator/{ => property}/common/IsLatitude.ts (100%) rename src/decorator/{ => property}/common/IsLongitude.ts (100%) rename src/decorator/{ => property}/common/IsNotEmpty.ts (100%) rename src/decorator/{ => property}/common/IsNotIn.ts (100%) rename src/decorator/{ => property}/common/IsOptional.ts (100%) rename src/decorator/{ => property}/common/NotEquals.ts (100%) rename src/decorator/{ => property}/common/Validate.ts (100%) rename src/decorator/{ => property}/common/ValidateBy.ts (100%) rename src/decorator/{ => property}/common/ValidateIf.ts (100%) rename src/decorator/{ => property}/common/ValidateNested.ts (100%) rename src/decorator/{ => property}/common/ValidatePromise.ts (100%) rename src/decorator/{ => property}/date/MaxDate.ts (100%) rename src/decorator/{ => property}/date/MinDate.ts (100%) rename src/decorator/{ => property}/number/IsDivisibleBy.ts (100%) rename src/decorator/{ => property}/number/IsNegative.ts (100%) rename src/decorator/{ => property}/number/IsPositive.ts (100%) rename src/decorator/{ => property}/number/Max.ts (100%) rename src/decorator/{ => property}/number/Min.ts (100%) rename src/decorator/{ => property}/object/IsInstance.ts (100%) rename src/decorator/{ => property}/object/IsNotEmptyObject.ts (100%) rename src/decorator/{ => property}/string/Contains.ts (100%) rename src/decorator/{ => property}/string/IsAlpha.ts (100%) rename src/decorator/{ => property}/string/IsAlphanumeric.ts (100%) rename src/decorator/{ => property}/string/IsAscii.ts (100%) rename src/decorator/{ => property}/string/IsBIC.ts (100%) rename src/decorator/{ => property}/string/IsBase32.ts (100%) rename src/decorator/{ => property}/string/IsBase58.ts (100%) rename src/decorator/{ => property}/string/IsBase64.ts (100%) rename src/decorator/{ => property}/string/IsBooleanString.ts (100%) rename src/decorator/{ => property}/string/IsBtcAddress.ts (100%) rename src/decorator/{ => property}/string/IsByteLength.ts (100%) rename src/decorator/{ => property}/string/IsCreditCard.ts (100%) rename src/decorator/{ => property}/string/IsCurrency.ts (100%) rename src/decorator/{ => property}/string/IsDataURI.ts (100%) rename src/decorator/{ => property}/string/IsDateString.ts (100%) rename src/decorator/{ => property}/string/IsDecimal.ts (100%) rename src/decorator/{ => property}/string/IsEAN.ts (100%) rename src/decorator/{ => property}/string/IsEmail.ts (100%) rename src/decorator/{ => property}/string/IsEthereumAddress.ts (100%) rename src/decorator/{ => property}/string/IsFQDN.ts (100%) rename src/decorator/{ => property}/string/IsFirebasePushId.ts (100%) rename src/decorator/{ => property}/string/IsFullWidth.ts (100%) rename src/decorator/{ => property}/string/IsHSL.ts (100%) rename src/decorator/{ => property}/string/IsHalfWidth.ts (100%) rename src/decorator/{ => property}/string/IsHash.ts (100%) rename src/decorator/{ => property}/string/IsHexColor.ts (100%) rename src/decorator/{ => property}/string/IsHexadecimal.ts (100%) rename src/decorator/{ => property}/string/IsIBAN.ts (100%) rename src/decorator/{ => property}/string/IsIP.ts (100%) rename src/decorator/{ => property}/string/IsISBN.ts (100%) rename src/decorator/{ => property}/string/IsISIN.ts (100%) rename src/decorator/{ => property}/string/IsISO31661Alpha2.ts (100%) rename src/decorator/{ => property}/string/IsISO31661Alpha3.ts (100%) rename src/decorator/{ => property}/string/IsISO8601.ts (100%) rename src/decorator/{ => property}/string/IsISRC.ts (100%) rename src/decorator/{ => property}/string/IsISSN.ts (100%) rename src/decorator/{ => property}/string/IsIdentityCard.ts (100%) rename src/decorator/{ => property}/string/IsJSON.ts (100%) rename src/decorator/{ => property}/string/IsJWT.ts (100%) rename src/decorator/{ => property}/string/IsLocale.ts (100%) rename src/decorator/{ => property}/string/IsLowercase.ts (100%) rename src/decorator/{ => property}/string/IsMacAddress.ts (100%) rename src/decorator/{ => property}/string/IsMagnetURI.ts (100%) rename src/decorator/{ => property}/string/IsMilitaryTime.ts (100%) rename src/decorator/{ => property}/string/IsMimeType.ts (100%) rename src/decorator/{ => property}/string/IsMobilePhone.ts (100%) rename src/decorator/{ => property}/string/IsMongoId.ts (100%) rename src/decorator/{ => property}/string/IsMultibyte.ts (100%) rename src/decorator/{ => property}/string/IsNumberString.ts (100%) rename src/decorator/{ => property}/string/IsOctal.ts (100%) rename src/decorator/{ => property}/string/IsPassportNumber.ts (100%) rename src/decorator/{ => property}/string/IsPhoneNumber.spec.ts (100%) rename src/decorator/{ => property}/string/IsPhoneNumber.ts (100%) rename src/decorator/{ => property}/string/IsPort.ts (100%) rename src/decorator/{ => property}/string/IsPostalCode.ts (100%) rename src/decorator/{ => property}/string/IsRFC3339.ts (100%) rename src/decorator/{ => property}/string/IsRgbColor.ts (100%) rename src/decorator/{ => property}/string/IsSemVer.ts (100%) rename src/decorator/{ => property}/string/IsStrongPassword.ts (100%) rename src/decorator/{ => property}/string/IsSurrogatePair.ts (100%) rename src/decorator/{ => property}/string/IsTimeZone.ts (100%) rename src/decorator/{ => property}/string/IsUUID.ts (100%) rename src/decorator/{ => property}/string/IsUppercase.ts (100%) rename src/decorator/{ => property}/string/IsUrl.ts (100%) rename src/decorator/{ => property}/string/IsVariableWidth.ts (100%) rename src/decorator/{ => property}/string/Length.ts (100%) rename src/decorator/{ => property}/string/Matches.ts (100%) rename src/decorator/{ => property}/string/MaxLength.ts (100%) rename src/decorator/{ => property}/string/MinLength.ts (100%) rename src/decorator/{ => property}/string/NotContains.ts (100%) rename src/decorator/{ => property}/string/is-iso4217-currency-code.ts (100%) rename src/decorator/{ => property}/string/is-tax-id.ts (100%) rename src/decorator/{ => property}/typechecker/IsArray.ts (100%) rename src/decorator/{ => property}/typechecker/IsBoolean.ts (100%) rename src/decorator/{ => property}/typechecker/IsDate.ts (100%) rename src/decorator/{ => property}/typechecker/IsEnum.ts (100%) rename src/decorator/{ => property}/typechecker/IsInt.ts (100%) rename src/decorator/{ => property}/typechecker/IsNumber.ts (100%) rename src/decorator/{ => property}/typechecker/IsObject.ts (100%) rename src/decorator/{ => property}/typechecker/IsString.ts (100%) diff --git a/src/decorator/argument/index.ts b/src/decorator/argument/index.ts index d897032391..f10815c304 100644 --- a/src/decorator/argument/index.ts +++ b/src/decorator/argument/index.ts @@ -1,27 +1,27 @@ -import { IsNotEmptyArgument } from "./is-not-empty"; -import { IsNotEmptyValidate } from "./is-not-empty/is-not-empty-validator"; +import { IsNotEmptyArgument } from './is-not-empty'; +import { IsNotEmptyValidate } from './is-not-empty/is-not-empty-validator'; export function ValidateArguments(target: any, propertyName: string, descriptor: TypedPropertyDescriptor) { - let method = descriptor.value!; + const method = descriptor.value; - descriptor.value = function (...args: Array) { - if (target?.validations?.length) { - for (const validation of target.validations) { - const [methodName, argumentIndex, validatorName] = validation.split(":"); + descriptor.value = function (...args: Array) { + if (target?.validations?.length) { + for (const validation of target.validations) { + const [methodName, argumentIndex, validatorName] = validation.split(':'); - if (method.name === methodName) { - switch (validatorName) { - case IsNotEmptyArgument.name: - const argumentValue = args[argumentIndex]; + if (method?.name === methodName) { + switch (validatorName) { + case IsNotEmptyArgument.name: + const argumentValue = args[argumentIndex]; - IsNotEmptyValidate(methodName, argumentIndex, argumentValue); + IsNotEmptyValidate(methodName, argumentIndex, argumentValue); - break; - } - } - } + break; + } } + } + } - return method.apply(this, arguments); - }; + return method?.apply(this, args); + }; } diff --git a/src/decorator/argument/is-not-empty/index.ts b/src/decorator/argument/is-not-empty/index.ts index 8d8b8a3727..6f2b7c76db 100644 --- a/src/decorator/argument/is-not-empty/index.ts +++ b/src/decorator/argument/is-not-empty/index.ts @@ -1,11 +1,7 @@ -export function IsNotEmptyArgument( - target: any, - methodName: string, - parameterIndex: number -) { - if (!target?.validations) { - target.validations = []; - } +export function IsNotEmptyArgument(target: any, methodName: string, parameterIndex: number) { + if (!target?.validations) { + target.validations = []; + } - target.validations.push(`${methodName}:${parameterIndex}:${IsNotEmptyArgument.name}`); + target.validations.push(`${methodName}:${parameterIndex}:${IsNotEmptyArgument.name}`); } diff --git a/src/decorator/argument/is-not-empty/is-not-empty-validator.ts b/src/decorator/argument/is-not-empty/is-not-empty-validator.ts index 20a968c8c8..30c280ffca 100644 --- a/src/decorator/argument/is-not-empty/is-not-empty-validator.ts +++ b/src/decorator/argument/is-not-empty/is-not-empty-validator.ts @@ -1,9 +1,7 @@ -export function IsNotEmptyValidate( - methodName: string, - argumentIndex: number, - argumentValue: any -) { - if (argumentValue === '' || argumentValue === null || argumentValue === undefined) { - throw new Error(`Invalid empty argument at index ${argumentIndex} with "${argumentValue}" value in "${methodName}" method`); - } +export function IsNotEmptyValidate(methodName: string, argumentIndex: number, argumentValue: any) { + if (argumentValue === '' || argumentValue === null || argumentValue === undefined) { + throw new Error( + `Invalid empty argument at index ${argumentIndex} with "${argumentValue}" value in "${methodName}" method` + ); + } } diff --git a/src/decorator/array/ArrayContains.ts b/src/decorator/property/array/ArrayContains.ts similarity index 100% rename from src/decorator/array/ArrayContains.ts rename to src/decorator/property/array/ArrayContains.ts diff --git a/src/decorator/array/ArrayMaxSize.ts b/src/decorator/property/array/ArrayMaxSize.ts similarity index 100% rename from src/decorator/array/ArrayMaxSize.ts rename to src/decorator/property/array/ArrayMaxSize.ts diff --git a/src/decorator/array/ArrayMinSize.ts b/src/decorator/property/array/ArrayMinSize.ts similarity index 100% rename from src/decorator/array/ArrayMinSize.ts rename to src/decorator/property/array/ArrayMinSize.ts diff --git a/src/decorator/array/ArrayNotContains.ts b/src/decorator/property/array/ArrayNotContains.ts similarity index 100% rename from src/decorator/array/ArrayNotContains.ts rename to src/decorator/property/array/ArrayNotContains.ts diff --git a/src/decorator/array/ArrayNotEmpty.ts b/src/decorator/property/array/ArrayNotEmpty.ts similarity index 100% rename from src/decorator/array/ArrayNotEmpty.ts rename to src/decorator/property/array/ArrayNotEmpty.ts diff --git a/src/decorator/array/ArrayUnique.ts b/src/decorator/property/array/ArrayUnique.ts similarity index 100% rename from src/decorator/array/ArrayUnique.ts rename to src/decorator/property/array/ArrayUnique.ts diff --git a/src/decorator/common/Allow.ts b/src/decorator/property/common/Allow.ts similarity index 100% rename from src/decorator/common/Allow.ts rename to src/decorator/property/common/Allow.ts diff --git a/src/decorator/common/Equals.ts b/src/decorator/property/common/Equals.ts similarity index 100% rename from src/decorator/common/Equals.ts rename to src/decorator/property/common/Equals.ts diff --git a/src/decorator/common/IsDefined.ts b/src/decorator/property/common/IsDefined.ts similarity index 100% rename from src/decorator/common/IsDefined.ts rename to src/decorator/property/common/IsDefined.ts diff --git a/src/decorator/common/IsEmpty.ts b/src/decorator/property/common/IsEmpty.ts similarity index 100% rename from src/decorator/common/IsEmpty.ts rename to src/decorator/property/common/IsEmpty.ts diff --git a/src/decorator/common/IsIn.spec.ts b/src/decorator/property/common/IsIn.spec.ts similarity index 100% rename from src/decorator/common/IsIn.spec.ts rename to src/decorator/property/common/IsIn.spec.ts diff --git a/src/decorator/common/IsIn.ts b/src/decorator/property/common/IsIn.ts similarity index 100% rename from src/decorator/common/IsIn.ts rename to src/decorator/property/common/IsIn.ts diff --git a/src/decorator/common/IsLatLong.ts b/src/decorator/property/common/IsLatLong.ts similarity index 100% rename from src/decorator/common/IsLatLong.ts rename to src/decorator/property/common/IsLatLong.ts diff --git a/src/decorator/common/IsLatitude.ts b/src/decorator/property/common/IsLatitude.ts similarity index 100% rename from src/decorator/common/IsLatitude.ts rename to src/decorator/property/common/IsLatitude.ts diff --git a/src/decorator/common/IsLongitude.ts b/src/decorator/property/common/IsLongitude.ts similarity index 100% rename from src/decorator/common/IsLongitude.ts rename to src/decorator/property/common/IsLongitude.ts diff --git a/src/decorator/common/IsNotEmpty.ts b/src/decorator/property/common/IsNotEmpty.ts similarity index 100% rename from src/decorator/common/IsNotEmpty.ts rename to src/decorator/property/common/IsNotEmpty.ts diff --git a/src/decorator/common/IsNotIn.ts b/src/decorator/property/common/IsNotIn.ts similarity index 100% rename from src/decorator/common/IsNotIn.ts rename to src/decorator/property/common/IsNotIn.ts diff --git a/src/decorator/common/IsOptional.ts b/src/decorator/property/common/IsOptional.ts similarity index 100% rename from src/decorator/common/IsOptional.ts rename to src/decorator/property/common/IsOptional.ts diff --git a/src/decorator/common/NotEquals.ts b/src/decorator/property/common/NotEquals.ts similarity index 100% rename from src/decorator/common/NotEquals.ts rename to src/decorator/property/common/NotEquals.ts diff --git a/src/decorator/common/Validate.ts b/src/decorator/property/common/Validate.ts similarity index 100% rename from src/decorator/common/Validate.ts rename to src/decorator/property/common/Validate.ts diff --git a/src/decorator/common/ValidateBy.ts b/src/decorator/property/common/ValidateBy.ts similarity index 100% rename from src/decorator/common/ValidateBy.ts rename to src/decorator/property/common/ValidateBy.ts diff --git a/src/decorator/common/ValidateIf.ts b/src/decorator/property/common/ValidateIf.ts similarity index 100% rename from src/decorator/common/ValidateIf.ts rename to src/decorator/property/common/ValidateIf.ts diff --git a/src/decorator/common/ValidateNested.ts b/src/decorator/property/common/ValidateNested.ts similarity index 100% rename from src/decorator/common/ValidateNested.ts rename to src/decorator/property/common/ValidateNested.ts diff --git a/src/decorator/common/ValidatePromise.ts b/src/decorator/property/common/ValidatePromise.ts similarity index 100% rename from src/decorator/common/ValidatePromise.ts rename to src/decorator/property/common/ValidatePromise.ts diff --git a/src/decorator/date/MaxDate.ts b/src/decorator/property/date/MaxDate.ts similarity index 100% rename from src/decorator/date/MaxDate.ts rename to src/decorator/property/date/MaxDate.ts diff --git a/src/decorator/date/MinDate.ts b/src/decorator/property/date/MinDate.ts similarity index 100% rename from src/decorator/date/MinDate.ts rename to src/decorator/property/date/MinDate.ts diff --git a/src/decorator/number/IsDivisibleBy.ts b/src/decorator/property/number/IsDivisibleBy.ts similarity index 100% rename from src/decorator/number/IsDivisibleBy.ts rename to src/decorator/property/number/IsDivisibleBy.ts diff --git a/src/decorator/number/IsNegative.ts b/src/decorator/property/number/IsNegative.ts similarity index 100% rename from src/decorator/number/IsNegative.ts rename to src/decorator/property/number/IsNegative.ts diff --git a/src/decorator/number/IsPositive.ts b/src/decorator/property/number/IsPositive.ts similarity index 100% rename from src/decorator/number/IsPositive.ts rename to src/decorator/property/number/IsPositive.ts diff --git a/src/decorator/number/Max.ts b/src/decorator/property/number/Max.ts similarity index 100% rename from src/decorator/number/Max.ts rename to src/decorator/property/number/Max.ts diff --git a/src/decorator/number/Min.ts b/src/decorator/property/number/Min.ts similarity index 100% rename from src/decorator/number/Min.ts rename to src/decorator/property/number/Min.ts diff --git a/src/decorator/object/IsInstance.ts b/src/decorator/property/object/IsInstance.ts similarity index 100% rename from src/decorator/object/IsInstance.ts rename to src/decorator/property/object/IsInstance.ts diff --git a/src/decorator/object/IsNotEmptyObject.ts b/src/decorator/property/object/IsNotEmptyObject.ts similarity index 100% rename from src/decorator/object/IsNotEmptyObject.ts rename to src/decorator/property/object/IsNotEmptyObject.ts diff --git a/src/decorator/string/Contains.ts b/src/decorator/property/string/Contains.ts similarity index 100% rename from src/decorator/string/Contains.ts rename to src/decorator/property/string/Contains.ts diff --git a/src/decorator/string/IsAlpha.ts b/src/decorator/property/string/IsAlpha.ts similarity index 100% rename from src/decorator/string/IsAlpha.ts rename to src/decorator/property/string/IsAlpha.ts diff --git a/src/decorator/string/IsAlphanumeric.ts b/src/decorator/property/string/IsAlphanumeric.ts similarity index 100% rename from src/decorator/string/IsAlphanumeric.ts rename to src/decorator/property/string/IsAlphanumeric.ts diff --git a/src/decorator/string/IsAscii.ts b/src/decorator/property/string/IsAscii.ts similarity index 100% rename from src/decorator/string/IsAscii.ts rename to src/decorator/property/string/IsAscii.ts diff --git a/src/decorator/string/IsBIC.ts b/src/decorator/property/string/IsBIC.ts similarity index 100% rename from src/decorator/string/IsBIC.ts rename to src/decorator/property/string/IsBIC.ts diff --git a/src/decorator/string/IsBase32.ts b/src/decorator/property/string/IsBase32.ts similarity index 100% rename from src/decorator/string/IsBase32.ts rename to src/decorator/property/string/IsBase32.ts diff --git a/src/decorator/string/IsBase58.ts b/src/decorator/property/string/IsBase58.ts similarity index 100% rename from src/decorator/string/IsBase58.ts rename to src/decorator/property/string/IsBase58.ts diff --git a/src/decorator/string/IsBase64.ts b/src/decorator/property/string/IsBase64.ts similarity index 100% rename from src/decorator/string/IsBase64.ts rename to src/decorator/property/string/IsBase64.ts diff --git a/src/decorator/string/IsBooleanString.ts b/src/decorator/property/string/IsBooleanString.ts similarity index 100% rename from src/decorator/string/IsBooleanString.ts rename to src/decorator/property/string/IsBooleanString.ts diff --git a/src/decorator/string/IsBtcAddress.ts b/src/decorator/property/string/IsBtcAddress.ts similarity index 100% rename from src/decorator/string/IsBtcAddress.ts rename to src/decorator/property/string/IsBtcAddress.ts diff --git a/src/decorator/string/IsByteLength.ts b/src/decorator/property/string/IsByteLength.ts similarity index 100% rename from src/decorator/string/IsByteLength.ts rename to src/decorator/property/string/IsByteLength.ts diff --git a/src/decorator/string/IsCreditCard.ts b/src/decorator/property/string/IsCreditCard.ts similarity index 100% rename from src/decorator/string/IsCreditCard.ts rename to src/decorator/property/string/IsCreditCard.ts diff --git a/src/decorator/string/IsCurrency.ts b/src/decorator/property/string/IsCurrency.ts similarity index 100% rename from src/decorator/string/IsCurrency.ts rename to src/decorator/property/string/IsCurrency.ts diff --git a/src/decorator/string/IsDataURI.ts b/src/decorator/property/string/IsDataURI.ts similarity index 100% rename from src/decorator/string/IsDataURI.ts rename to src/decorator/property/string/IsDataURI.ts diff --git a/src/decorator/string/IsDateString.ts b/src/decorator/property/string/IsDateString.ts similarity index 100% rename from src/decorator/string/IsDateString.ts rename to src/decorator/property/string/IsDateString.ts diff --git a/src/decorator/string/IsDecimal.ts b/src/decorator/property/string/IsDecimal.ts similarity index 100% rename from src/decorator/string/IsDecimal.ts rename to src/decorator/property/string/IsDecimal.ts diff --git a/src/decorator/string/IsEAN.ts b/src/decorator/property/string/IsEAN.ts similarity index 100% rename from src/decorator/string/IsEAN.ts rename to src/decorator/property/string/IsEAN.ts diff --git a/src/decorator/string/IsEmail.ts b/src/decorator/property/string/IsEmail.ts similarity index 100% rename from src/decorator/string/IsEmail.ts rename to src/decorator/property/string/IsEmail.ts diff --git a/src/decorator/string/IsEthereumAddress.ts b/src/decorator/property/string/IsEthereumAddress.ts similarity index 100% rename from src/decorator/string/IsEthereumAddress.ts rename to src/decorator/property/string/IsEthereumAddress.ts diff --git a/src/decorator/string/IsFQDN.ts b/src/decorator/property/string/IsFQDN.ts similarity index 100% rename from src/decorator/string/IsFQDN.ts rename to src/decorator/property/string/IsFQDN.ts diff --git a/src/decorator/string/IsFirebasePushId.ts b/src/decorator/property/string/IsFirebasePushId.ts similarity index 100% rename from src/decorator/string/IsFirebasePushId.ts rename to src/decorator/property/string/IsFirebasePushId.ts diff --git a/src/decorator/string/IsFullWidth.ts b/src/decorator/property/string/IsFullWidth.ts similarity index 100% rename from src/decorator/string/IsFullWidth.ts rename to src/decorator/property/string/IsFullWidth.ts diff --git a/src/decorator/string/IsHSL.ts b/src/decorator/property/string/IsHSL.ts similarity index 100% rename from src/decorator/string/IsHSL.ts rename to src/decorator/property/string/IsHSL.ts diff --git a/src/decorator/string/IsHalfWidth.ts b/src/decorator/property/string/IsHalfWidth.ts similarity index 100% rename from src/decorator/string/IsHalfWidth.ts rename to src/decorator/property/string/IsHalfWidth.ts diff --git a/src/decorator/string/IsHash.ts b/src/decorator/property/string/IsHash.ts similarity index 100% rename from src/decorator/string/IsHash.ts rename to src/decorator/property/string/IsHash.ts diff --git a/src/decorator/string/IsHexColor.ts b/src/decorator/property/string/IsHexColor.ts similarity index 100% rename from src/decorator/string/IsHexColor.ts rename to src/decorator/property/string/IsHexColor.ts diff --git a/src/decorator/string/IsHexadecimal.ts b/src/decorator/property/string/IsHexadecimal.ts similarity index 100% rename from src/decorator/string/IsHexadecimal.ts rename to src/decorator/property/string/IsHexadecimal.ts diff --git a/src/decorator/string/IsIBAN.ts b/src/decorator/property/string/IsIBAN.ts similarity index 100% rename from src/decorator/string/IsIBAN.ts rename to src/decorator/property/string/IsIBAN.ts diff --git a/src/decorator/string/IsIP.ts b/src/decorator/property/string/IsIP.ts similarity index 100% rename from src/decorator/string/IsIP.ts rename to src/decorator/property/string/IsIP.ts diff --git a/src/decorator/string/IsISBN.ts b/src/decorator/property/string/IsISBN.ts similarity index 100% rename from src/decorator/string/IsISBN.ts rename to src/decorator/property/string/IsISBN.ts diff --git a/src/decorator/string/IsISIN.ts b/src/decorator/property/string/IsISIN.ts similarity index 100% rename from src/decorator/string/IsISIN.ts rename to src/decorator/property/string/IsISIN.ts diff --git a/src/decorator/string/IsISO31661Alpha2.ts b/src/decorator/property/string/IsISO31661Alpha2.ts similarity index 100% rename from src/decorator/string/IsISO31661Alpha2.ts rename to src/decorator/property/string/IsISO31661Alpha2.ts diff --git a/src/decorator/string/IsISO31661Alpha3.ts b/src/decorator/property/string/IsISO31661Alpha3.ts similarity index 100% rename from src/decorator/string/IsISO31661Alpha3.ts rename to src/decorator/property/string/IsISO31661Alpha3.ts diff --git a/src/decorator/string/IsISO8601.ts b/src/decorator/property/string/IsISO8601.ts similarity index 100% rename from src/decorator/string/IsISO8601.ts rename to src/decorator/property/string/IsISO8601.ts diff --git a/src/decorator/string/IsISRC.ts b/src/decorator/property/string/IsISRC.ts similarity index 100% rename from src/decorator/string/IsISRC.ts rename to src/decorator/property/string/IsISRC.ts diff --git a/src/decorator/string/IsISSN.ts b/src/decorator/property/string/IsISSN.ts similarity index 100% rename from src/decorator/string/IsISSN.ts rename to src/decorator/property/string/IsISSN.ts diff --git a/src/decorator/string/IsIdentityCard.ts b/src/decorator/property/string/IsIdentityCard.ts similarity index 100% rename from src/decorator/string/IsIdentityCard.ts rename to src/decorator/property/string/IsIdentityCard.ts diff --git a/src/decorator/string/IsJSON.ts b/src/decorator/property/string/IsJSON.ts similarity index 100% rename from src/decorator/string/IsJSON.ts rename to src/decorator/property/string/IsJSON.ts diff --git a/src/decorator/string/IsJWT.ts b/src/decorator/property/string/IsJWT.ts similarity index 100% rename from src/decorator/string/IsJWT.ts rename to src/decorator/property/string/IsJWT.ts diff --git a/src/decorator/string/IsLocale.ts b/src/decorator/property/string/IsLocale.ts similarity index 100% rename from src/decorator/string/IsLocale.ts rename to src/decorator/property/string/IsLocale.ts diff --git a/src/decorator/string/IsLowercase.ts b/src/decorator/property/string/IsLowercase.ts similarity index 100% rename from src/decorator/string/IsLowercase.ts rename to src/decorator/property/string/IsLowercase.ts diff --git a/src/decorator/string/IsMacAddress.ts b/src/decorator/property/string/IsMacAddress.ts similarity index 100% rename from src/decorator/string/IsMacAddress.ts rename to src/decorator/property/string/IsMacAddress.ts diff --git a/src/decorator/string/IsMagnetURI.ts b/src/decorator/property/string/IsMagnetURI.ts similarity index 100% rename from src/decorator/string/IsMagnetURI.ts rename to src/decorator/property/string/IsMagnetURI.ts diff --git a/src/decorator/string/IsMilitaryTime.ts b/src/decorator/property/string/IsMilitaryTime.ts similarity index 100% rename from src/decorator/string/IsMilitaryTime.ts rename to src/decorator/property/string/IsMilitaryTime.ts diff --git a/src/decorator/string/IsMimeType.ts b/src/decorator/property/string/IsMimeType.ts similarity index 100% rename from src/decorator/string/IsMimeType.ts rename to src/decorator/property/string/IsMimeType.ts diff --git a/src/decorator/string/IsMobilePhone.ts b/src/decorator/property/string/IsMobilePhone.ts similarity index 100% rename from src/decorator/string/IsMobilePhone.ts rename to src/decorator/property/string/IsMobilePhone.ts diff --git a/src/decorator/string/IsMongoId.ts b/src/decorator/property/string/IsMongoId.ts similarity index 100% rename from src/decorator/string/IsMongoId.ts rename to src/decorator/property/string/IsMongoId.ts diff --git a/src/decorator/string/IsMultibyte.ts b/src/decorator/property/string/IsMultibyte.ts similarity index 100% rename from src/decorator/string/IsMultibyte.ts rename to src/decorator/property/string/IsMultibyte.ts diff --git a/src/decorator/string/IsNumberString.ts b/src/decorator/property/string/IsNumberString.ts similarity index 100% rename from src/decorator/string/IsNumberString.ts rename to src/decorator/property/string/IsNumberString.ts diff --git a/src/decorator/string/IsOctal.ts b/src/decorator/property/string/IsOctal.ts similarity index 100% rename from src/decorator/string/IsOctal.ts rename to src/decorator/property/string/IsOctal.ts diff --git a/src/decorator/string/IsPassportNumber.ts b/src/decorator/property/string/IsPassportNumber.ts similarity index 100% rename from src/decorator/string/IsPassportNumber.ts rename to src/decorator/property/string/IsPassportNumber.ts diff --git a/src/decorator/string/IsPhoneNumber.spec.ts b/src/decorator/property/string/IsPhoneNumber.spec.ts similarity index 100% rename from src/decorator/string/IsPhoneNumber.spec.ts rename to src/decorator/property/string/IsPhoneNumber.spec.ts diff --git a/src/decorator/string/IsPhoneNumber.ts b/src/decorator/property/string/IsPhoneNumber.ts similarity index 100% rename from src/decorator/string/IsPhoneNumber.ts rename to src/decorator/property/string/IsPhoneNumber.ts diff --git a/src/decorator/string/IsPort.ts b/src/decorator/property/string/IsPort.ts similarity index 100% rename from src/decorator/string/IsPort.ts rename to src/decorator/property/string/IsPort.ts diff --git a/src/decorator/string/IsPostalCode.ts b/src/decorator/property/string/IsPostalCode.ts similarity index 100% rename from src/decorator/string/IsPostalCode.ts rename to src/decorator/property/string/IsPostalCode.ts diff --git a/src/decorator/string/IsRFC3339.ts b/src/decorator/property/string/IsRFC3339.ts similarity index 100% rename from src/decorator/string/IsRFC3339.ts rename to src/decorator/property/string/IsRFC3339.ts diff --git a/src/decorator/string/IsRgbColor.ts b/src/decorator/property/string/IsRgbColor.ts similarity index 100% rename from src/decorator/string/IsRgbColor.ts rename to src/decorator/property/string/IsRgbColor.ts diff --git a/src/decorator/string/IsSemVer.ts b/src/decorator/property/string/IsSemVer.ts similarity index 100% rename from src/decorator/string/IsSemVer.ts rename to src/decorator/property/string/IsSemVer.ts diff --git a/src/decorator/string/IsStrongPassword.ts b/src/decorator/property/string/IsStrongPassword.ts similarity index 100% rename from src/decorator/string/IsStrongPassword.ts rename to src/decorator/property/string/IsStrongPassword.ts diff --git a/src/decorator/string/IsSurrogatePair.ts b/src/decorator/property/string/IsSurrogatePair.ts similarity index 100% rename from src/decorator/string/IsSurrogatePair.ts rename to src/decorator/property/string/IsSurrogatePair.ts diff --git a/src/decorator/string/IsTimeZone.ts b/src/decorator/property/string/IsTimeZone.ts similarity index 100% rename from src/decorator/string/IsTimeZone.ts rename to src/decorator/property/string/IsTimeZone.ts diff --git a/src/decorator/string/IsUUID.ts b/src/decorator/property/string/IsUUID.ts similarity index 100% rename from src/decorator/string/IsUUID.ts rename to src/decorator/property/string/IsUUID.ts diff --git a/src/decorator/string/IsUppercase.ts b/src/decorator/property/string/IsUppercase.ts similarity index 100% rename from src/decorator/string/IsUppercase.ts rename to src/decorator/property/string/IsUppercase.ts diff --git a/src/decorator/string/IsUrl.ts b/src/decorator/property/string/IsUrl.ts similarity index 100% rename from src/decorator/string/IsUrl.ts rename to src/decorator/property/string/IsUrl.ts diff --git a/src/decorator/string/IsVariableWidth.ts b/src/decorator/property/string/IsVariableWidth.ts similarity index 100% rename from src/decorator/string/IsVariableWidth.ts rename to src/decorator/property/string/IsVariableWidth.ts diff --git a/src/decorator/string/Length.ts b/src/decorator/property/string/Length.ts similarity index 100% rename from src/decorator/string/Length.ts rename to src/decorator/property/string/Length.ts diff --git a/src/decorator/string/Matches.ts b/src/decorator/property/string/Matches.ts similarity index 100% rename from src/decorator/string/Matches.ts rename to src/decorator/property/string/Matches.ts diff --git a/src/decorator/string/MaxLength.ts b/src/decorator/property/string/MaxLength.ts similarity index 100% rename from src/decorator/string/MaxLength.ts rename to src/decorator/property/string/MaxLength.ts diff --git a/src/decorator/string/MinLength.ts b/src/decorator/property/string/MinLength.ts similarity index 100% rename from src/decorator/string/MinLength.ts rename to src/decorator/property/string/MinLength.ts diff --git a/src/decorator/string/NotContains.ts b/src/decorator/property/string/NotContains.ts similarity index 100% rename from src/decorator/string/NotContains.ts rename to src/decorator/property/string/NotContains.ts diff --git a/src/decorator/string/is-iso4217-currency-code.ts b/src/decorator/property/string/is-iso4217-currency-code.ts similarity index 100% rename from src/decorator/string/is-iso4217-currency-code.ts rename to src/decorator/property/string/is-iso4217-currency-code.ts diff --git a/src/decorator/string/is-tax-id.ts b/src/decorator/property/string/is-tax-id.ts similarity index 100% rename from src/decorator/string/is-tax-id.ts rename to src/decorator/property/string/is-tax-id.ts diff --git a/src/decorator/typechecker/IsArray.ts b/src/decorator/property/typechecker/IsArray.ts similarity index 100% rename from src/decorator/typechecker/IsArray.ts rename to src/decorator/property/typechecker/IsArray.ts diff --git a/src/decorator/typechecker/IsBoolean.ts b/src/decorator/property/typechecker/IsBoolean.ts similarity index 100% rename from src/decorator/typechecker/IsBoolean.ts rename to src/decorator/property/typechecker/IsBoolean.ts diff --git a/src/decorator/typechecker/IsDate.ts b/src/decorator/property/typechecker/IsDate.ts similarity index 100% rename from src/decorator/typechecker/IsDate.ts rename to src/decorator/property/typechecker/IsDate.ts diff --git a/src/decorator/typechecker/IsEnum.ts b/src/decorator/property/typechecker/IsEnum.ts similarity index 100% rename from src/decorator/typechecker/IsEnum.ts rename to src/decorator/property/typechecker/IsEnum.ts diff --git a/src/decorator/typechecker/IsInt.ts b/src/decorator/property/typechecker/IsInt.ts similarity index 100% rename from src/decorator/typechecker/IsInt.ts rename to src/decorator/property/typechecker/IsInt.ts diff --git a/src/decorator/typechecker/IsNumber.ts b/src/decorator/property/typechecker/IsNumber.ts similarity index 100% rename from src/decorator/typechecker/IsNumber.ts rename to src/decorator/property/typechecker/IsNumber.ts diff --git a/src/decorator/typechecker/IsObject.ts b/src/decorator/property/typechecker/IsObject.ts similarity index 100% rename from src/decorator/typechecker/IsObject.ts rename to src/decorator/property/typechecker/IsObject.ts diff --git a/src/decorator/typechecker/IsString.ts b/src/decorator/property/typechecker/IsString.ts similarity index 100% rename from src/decorator/typechecker/IsString.ts rename to src/decorator/property/typechecker/IsString.ts diff --git a/test/functional/method-argument-decorators.spec.ts b/test/functional/method-argument-decorators.spec.ts index 1de3720fea..07e3521f21 100644 --- a/test/functional/method-argument-decorators.spec.ts +++ b/test/functional/method-argument-decorators.spec.ts @@ -1,20 +1,20 @@ -import { ValidateArguments } from "../../src/decorator/argument"; -import { IsNotEmptyArgument } from "../../src/decorator/argument/is-not-empty"; +import { ValidateArguments } from '../../src/decorator/argument'; +import { IsNotEmptyArgument } from '../../src/decorator/argument/is-not-empty'; describe('decorator for validating method arguments', () => { class MyClass { @ValidateArguments testMethod(@IsNotEmptyArgument test: string, emptyArgument?: string): void { - const someVariable = `${test}`; + const someVariable = `${test}`; } } - it("IsNotEmpty should throw if argument is empty (null, undefined or an empty string)", () => { + it('IsNotEmpty should throw if argument is empty (null, undefined or an empty string)', () => { const instance = new MyClass(); - expect(() => instance.testMethod("")).toThrow(); + expect(() => instance.testMethod('')).toThrow(); expect(() => instance.testMethod(null)).toThrow(); expect(() => instance.testMethod(undefined)).toThrow(); - expect(() => instance.testMethod("test", undefined)).not.toThrow(); + expect(() => instance.testMethod('test', undefined)).not.toThrow(); }); }); From 24a06b6a14760461847848558377f1a6c27b9432 Mon Sep 17 00:00:00 2001 From: Loparev Date: Tue, 12 Mar 2024 17:20:23 +0200 Subject: [PATCH 3/3] Updated readme --- README.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/README.md b/README.md index 886712dd76..47df7abbee 100644 --- a/README.md +++ b/README.md @@ -921,6 +921,21 @@ Schema-based validation without decorators is no longer supported by `class-vali Due to nature of the decorators, the validated object has to be instantiated using `new Class()` syntax. If you have your class defined using class-validator decorators and you want to validate plain JS object (literal object or returned by JSON.parse), you need to transform it to the class instance via using [class-transformer](https://github.com/pleerock/class-transformer)). +## Method's arguments runtime validation + +```typescript +import { ValidateArguments, IsNotEmptyArgument } from 'class-validator'; + +class MyClass { + @ValidateArguments + testMethod(@IsNotEmptyArgument test: string): void { + const someVariable = `${test}`; + } +} +``` + +When the value of `test` variable is read it will be validated in runtime. In case if it's invalid it will throw an exception. + ## Samples Take a look on samples in [./sample](https://github.com/pleerock/class-validator/tree/master/sample) for more examples of