From ba6431a0fb32b7d122289292a18242982fe19611 Mon Sep 17 00:00:00 2001 From: Bruno Tot Date: Wed, 27 Sep 2023 12:03:10 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=84=20[chore]:=20Automated=20commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/index.ts | 8 ++-- .../core/src/decorators/decorator.facade.ts | 39 --------------- .../core/src/decorators/decorator.factory.ts | 43 ----------------- .../core/src/decorators/decorator.utils.ts | 13 +++-- .../index.ts} | 10 ++-- .../decorators/service/decorator.service.ts | 47 +++++++++++++++++++ .../decorators/service/validator.service.ts | 43 +++++++++++++++++ packages/core/src/localization/index.ts | 28 +++++------ .../impl/reflection.service.validation.ts | 2 +- .../reflection/service/reflection.service.ts | 2 +- packages/core/validators/any/Falsy.ts | 6 +-- packages/core/validators/any/Required.ts | 6 +-- packages/core/validators/any/Rule.ts | 4 +- packages/core/validators/any/Truthy.ts | 6 +-- packages/core/validators/any/valid.ts | 4 +- .../core/validators/array/ArrayContains.ts | 6 +-- packages/core/validators/array/ArrayEmpty.ts | 6 +-- packages/core/validators/array/ArrayEvery.ts | 6 +-- packages/core/validators/array/ArrayNone.ts | 6 +-- packages/core/validators/array/ArrayOne.ts | 6 +-- .../core/validators/array/ArraySizeExact.ts | 7 ++- .../core/validators/array/ArraySizeMax.ts | 6 +-- .../core/validators/array/ArraySizeMin.ts | 6 +-- .../core/validators/array/ArraySizeRange.ts | 6 +-- packages/core/validators/array/ArraySome.ts | 6 +-- packages/core/validators/array/ArrayUnique.ts | 6 +-- packages/core/validators/array/foreach.ts | 10 ++-- packages/core/validators/date/FutureDate.ts | 20 +++----- packages/core/validators/date/PastDate.ts | 19 +++----- packages/core/validators/date/TodayDate.ts | 30 +++++------- packages/core/validators/number/Decimal.ts | 7 ++- packages/core/validators/number/Digits.ts | 7 ++- packages/core/validators/number/Integer.ts | 6 +-- packages/core/validators/number/Negative.ts | 6 +-- .../core/validators/number/NonNegative.ts | 6 +-- .../core/validators/number/NonPositive.ts | 6 +-- packages/core/validators/number/Positive.ts | 6 +-- packages/core/validators/number/ValueMax.ts | 6 +-- packages/core/validators/number/ValueMin.ts | 6 +-- packages/core/validators/number/ValueRange.ts | 6 +-- .../core/validators/string/ExactLength.ts | 6 +-- packages/core/validators/string/Length.ts | 6 +-- packages/core/validators/string/MaxLength.ts | 6 +-- packages/core/validators/string/MinLength.ts | 6 +-- packages/core/validators/string/Password.ts | 4 +- .../core/validators/string/regex/Pattern.ts | 6 +-- .../validators/string/regex/impl/Alpha.ts | 6 +-- .../string/regex/impl/Alphanumeric.ts | 6 +-- .../validators/string/regex/impl/Email.ts | 6 +-- .../validators/string/regex/impl/IPAddress.ts | 6 +-- .../validators/string/regex/impl/Lowercase.ts | 6 +-- .../validators/string/regex/impl/Numeric.ts | 6 +-- .../core/validators/string/regex/impl/URL.ts | 6 +-- .../validators/string/regex/impl/Uppercase.ts | 6 +-- 54 files changed, 269 insertions(+), 282 deletions(-) delete mode 100644 packages/core/src/decorators/decorator.facade.ts delete mode 100644 packages/core/src/decorators/decorator.factory.ts rename packages/core/src/{types/namespace/decorator.namespace.ts => decorators/index.ts} (88%) create mode 100644 packages/core/src/decorators/service/decorator.service.ts create mode 100644 packages/core/src/decorators/service/validator.service.ts diff --git a/packages/core/index.ts b/packages/core/index.ts index 8917a4562..457f39b3d 100644 --- a/packages/core/index.ts +++ b/packages/core/index.ts @@ -1,4 +1,6 @@ -import makeValidator from "./src/decorators/decorator.facade"; +import Decorator from "./src/decorators"; +import DecoratorService from "./src/decorators/service/decorator.service"; +import ValidatorService from "./src/decorators/service/validator.service"; import Localization from "./src/localization"; import CacheMap from "./src/models/cache.map"; import EntityProcessor from "./src/reflection/models/entity.processor"; @@ -33,7 +35,6 @@ import PrimitiveArrayStrat, { import PrimitiveStrat from "./src/reflection/strategy/impl/primitive.strategy"; import ValidationStrategy from "./src/reflection/strategy/strategy"; import TdvCore from "./src/types"; -import Decorator from "./src/types/namespace/decorator.namespace"; import Validation from "./src/types/namespace/validation.namespace"; import Class from "./src/types/validation/class.type"; import DetailedErrors from "./src/types/validation/detailed-errors.type"; @@ -53,6 +54,7 @@ export type { CacheMap, Class, Decorator, + DecoratorService, DescriptorProps, DetailedErrors, Errors, @@ -76,6 +78,7 @@ export type { StrategyOptional, TdvCore, Validation, + ValidatorService, }; export { @@ -90,6 +93,5 @@ export { ValidationMetaService, ValidationStrategy, getClassFieldNames, - makeValidator, validators, }; diff --git a/packages/core/src/decorators/decorator.facade.ts b/packages/core/src/decorators/decorator.facade.ts deleted file mode 100644 index ad115558b..000000000 --- a/packages/core/src/decorators/decorator.facade.ts +++ /dev/null @@ -1,39 +0,0 @@ -import Decorator from "../types/namespace/decorator.namespace"; -import Validation from "../types/namespace/validation.namespace"; -import makeDecorator from "./decorator.factory"; - -/** - * Creates a new validator function using the provided validation builder options. - * - * @typeParam T - The type of the value being validated. - * - * @param groups - An array of group names that this validator belongs to. Validators in the same group can be executed together. - * @param isValid - A function that performs the actual validation logic. It takes a value of type `T` and returns a boolean indicating whether the value is valid. - * - * @returns A decorator function that can be applied to class properties to add the validation logic. - * - * @remarks - * This function leverages the `makeDecorator` function to create a new decorator. - * It uses the `validationMetaService` to add the new validator to the metadata for the property it decorates. - * - * @example - * ```typescript - * const IsPositive = makeValidator({ - * groups: ['group1'], - * isValid: (value) => value > 0 - * }); - * - * class MyClass { - * //@IsPositive - * public myValue: number; - * } - * ``` - */ -export default function makeValidator({ - groups, - isValid, -}: Validation.Builder): Decorator.Type { - return makeDecorator((key, validationMetaService) => - validationMetaService.addValidator(key, isValid, groups) - ); -} diff --git a/packages/core/src/decorators/decorator.factory.ts b/packages/core/src/decorators/decorator.factory.ts deleted file mode 100644 index 9ffd141da..000000000 --- a/packages/core/src/decorators/decorator.factory.ts +++ /dev/null @@ -1,43 +0,0 @@ -import ValidationMetaService from "../reflection/service/impl/reflection.service.validation"; -import Decorator from "../types/namespace/decorator.namespace"; - -/** - * Creates a new decorator using the provided supplier function. - * - * @typeParam T - The type of the value being validated. - * - * @param supplier - A function that defines the behavior of the decorator. It takes the property name, an instance of `ValidationMetaService`, and the decorator context. - * - * @returns A decorator function that can be applied to class properties. - * - * @remarks - * This function serves as a factory for creating new decorators. It uses dependency injection to get an instance of `ValidationMetaService`. - * - * The function handles both TypeScript's Stage 2 decorators and the current decorators. It determines the stage based on the type of the `context` parameter. - * - * The `supplier` function is responsible for adding any necessary metadata or validation logic via the `ValidationMetaService`. - * - * @example - * ```typescript - * const MyDecorator = makeDecorator((key, metaService, context) => { - * metaService.addValidator(key, (value) => value > 0); - * }); - * - * class MyClass { - * //@MyDecorator - * public myValue: number; - * } - * ``` - */ -export default function makeDecorator( - supplier: Decorator.Supplier -): Decorator.Type { - return function (target, context) { - const isStage2 = typeof context === "string"; - const nameEval = isStage2 ? context : context.name; - const strategyEval = isStage2 ? target.constructor : context; - const contextEval = isStage2 ? { name: context, metadata: {} } : context; - const metaService = ValidationMetaService.inject(strategyEval); - supplier(nameEval, metaService, contextEval as any); - }; -} diff --git a/packages/core/src/decorators/decorator.utils.ts b/packages/core/src/decorators/decorator.utils.ts index ba951d8fd..5a3edf20e 100644 --- a/packages/core/src/decorators/decorator.utils.ts +++ b/packages/core/src/decorators/decorator.utils.ts @@ -1,6 +1,6 @@ +import Decorator from "."; import Localization from "../localization"; import $ from "../types"; -import Decorator from "../types/namespace/decorator.namespace"; import Objects from "../types/namespace/objects.namespace"; import Validation from "../types/namespace/validation.namespace"; @@ -61,9 +61,12 @@ export function extractGroups( * * @returns `true` if the value is null or undefined, or the result of `isValid` otherwise. */ -export function evaluateNullableValidity( - object: $.Objects.Optional, - isValid: (value: T) => boolean +export function isValidNullable( + nullableValue: T, + isValid: (nonNullableValue: NonNullable) => boolean ) { - return !$.Objects.hasValue(object) ? true : isValid(object); + return ( + !$.Objects.hasValue(nullableValue) || + isValid(nullableValue as NonNullable) + ); } diff --git a/packages/core/src/types/namespace/decorator.namespace.ts b/packages/core/src/decorators/index.ts similarity index 88% rename from packages/core/src/types/namespace/decorator.namespace.ts rename to packages/core/src/decorators/index.ts index bb567ac13..a39586a7b 100644 --- a/packages/core/src/types/namespace/decorator.namespace.ts +++ b/packages/core/src/decorators/index.ts @@ -1,5 +1,5 @@ -import ValidationMetaService from "../../reflection/service/impl/reflection.service.validation"; -import Validation from "./validation.namespace"; +import ValidationMetaService from "../reflection/service/impl/reflection.service.validation"; +import Validation from "../types/namespace/validation.namespace"; /** * @namespace Decorator @@ -14,7 +14,7 @@ namespace Decorator { * @description * Type definition for a decorator function. */ - export type Type = ( + export type Instance = ( target: any, context: Decorator.Context ) => void; @@ -86,8 +86,4 @@ namespace Decorator { }; } -/** - * @description - * The default export for the `Decorator` namespace. - */ export default Decorator; diff --git a/packages/core/src/decorators/service/decorator.service.ts b/packages/core/src/decorators/service/decorator.service.ts new file mode 100644 index 000000000..dd5276cf9 --- /dev/null +++ b/packages/core/src/decorators/service/decorator.service.ts @@ -0,0 +1,47 @@ +import Decorator from ".."; +import ValidationMetaService from "../../reflection/service/impl/reflection.service.validation"; + +namespace DecoratorService { + /** + * Creates a new decorator using the provided supplier function. + * + * @typeParam T - The type of the value being validated. + * + * @param supplier - A function that defines the behavior of the decorator. It takes the property name, an instance of `ValidationMetaService`, and the decorator context. + * + * @returns A decorator function that can be applied to class properties. + * + * @remarks + * This function serves as a factory for creating new decorators. It uses dependency injection to get an instance of `ValidationMetaService`. + * + * The function handles both TypeScript's Stage 2 decorators and the current decorators. It determines the stage based on the type of the `context` parameter. + * + * The `supplier` function is responsible for adding any necessary metadata or validation logic via the `ValidationMetaService`. + * + * @example + * ```typescript + * const MyDecorator = makeDecorator((key, metaService, context) => { + * metaService.addValidator(key, (value) => value > 0); + * }); + * + * class MyClass { + * //@MyDecorator + * public myValue: number; + * } + * ``` + */ + export function create( + supplier: Decorator.Supplier + ): Decorator.Instance { + return function (target, context) { + const isStage2 = typeof context === "string"; + const nameEval = isStage2 ? context : context.name; + const strategyEval = isStage2 ? target.constructor : context; + const contextEval = isStage2 ? { name: context, metadata: {} } : context; + const metaService = ValidationMetaService.inject(strategyEval); + supplier(nameEval, metaService, contextEval as any); + }; + } +} + +export default DecoratorService; diff --git a/packages/core/src/decorators/service/validator.service.ts b/packages/core/src/decorators/service/validator.service.ts new file mode 100644 index 000000000..b9407663e --- /dev/null +++ b/packages/core/src/decorators/service/validator.service.ts @@ -0,0 +1,43 @@ +import Decorator from ".."; +import Validation from "../../types/namespace/validation.namespace"; +import DecoratorService from "./decorator.service"; + +namespace ValidatorService { + /** + * Creates a new validator function using the provided validation builder options. + * + * @typeParam T - The type of the value being validated. + * + * @param groups - An array of group names that this validator belongs to. Validators in the same group can be executed together. + * @param isValid - A function that performs the actual validation logic. It takes a value of type `T` and returns a boolean indicating whether the value is valid. + * + * @returns A decorator function that can be applied to class properties to add the validation logic. + * + * @remarks + * This function leverages the `makeDecorator` function to create a new decorator. + * It uses the `validationMetaService` to add the new validator to the metadata for the property it decorates. + * + * @example + * ```typescript + * const IsPositive = ValidatorService.create({ + * groups: ['group1'], + * isValid: (value) => value > 0 + * }); + * + * class MyClass { + * //@IsPositive + * public myValue: number; + * } + * ``` + */ + export function create({ + groups, + isValid, + }: Validation.Builder): Decorator.Instance { + return DecoratorService.create((key, validationMetaService) => + validationMetaService.addValidator(key, isValid, groups) + ); + } +} + +export default ValidatorService; diff --git a/packages/core/src/localization/index.ts b/packages/core/src/localization/index.ts index 3a8e5747a..8d3cea2b3 100644 --- a/packages/core/src/localization/index.ts +++ b/packages/core/src/localization/index.ts @@ -11,28 +11,27 @@ namespace Localization { */ export type Messages = Record>; - let locale: Localization.Locale = "en"; + let locale: Locale = "en"; - export function getLocale(): Localization.Locale { + export function getLocale(): Locale { return locale; } - export function setLocale(localeValue: Localization.Locale) { + export function setLocale(localeValue: Locale) { locale = localeValue; } export namespace Resolver { - const DEFAULT_CONFIGURER: ( - locale: Localization.Locale, + export type ResolverConfigurer = ( + locale: Locale, message: string - ) => string = (_locale, message) => message; + ) => string; - let configurer: (locale: Localization.Locale, message: string) => string = - DEFAULT_CONFIGURER; + const DEFAULT_CONFIGURER: ResolverConfigurer = (_, message) => message; - export function configure( - handler?: (locale: Localization.Locale, message: string) => string - ) { + let configurer: ResolverConfigurer = DEFAULT_CONFIGURER; + + export function configure(handler?: ResolverConfigurer) { configurer = handler ?? DEFAULT_CONFIGURER; } @@ -40,9 +39,10 @@ namespace Localization { try { return configurer(locale, message); } catch (error) { - throw new Error( - `An error occurred while resolving \"${message}\" for locale \"${locale}\". To fix, check your Localization.Resolver.configure() implementation.\n\n${error}` - ); + const title = `An error occurred while resolving \"${message}\" for locale \"${locale}\".`; + const descr = `To fix, check your Localization.Resolver.configure() implementation.`; + const stacktrace = `\n\n${error}`; + throw new Error(`${title} ${descr} ${stacktrace}`); } } } diff --git a/packages/core/src/reflection/service/impl/reflection.service.validation.ts b/packages/core/src/reflection/service/impl/reflection.service.validation.ts index c7d1735ec..e008b5fee 100644 --- a/packages/core/src/reflection/service/impl/reflection.service.validation.ts +++ b/packages/core/src/reflection/service/impl/reflection.service.validation.ts @@ -1,5 +1,5 @@ +import Decorator from "../../../decorators"; import { extractGroups } from "../../../decorators/decorator.utils"; -import Decorator from "../../../types/namespace/decorator.namespace"; import Validation from "../../../types/namespace/validation.namespace"; import Class from "../../../types/validation/class.type"; import ReflectionDescriptor from "../../models/reflection.descriptor"; diff --git a/packages/core/src/reflection/service/reflection.service.ts b/packages/core/src/reflection/service/reflection.service.ts index 75c2cfc02..f0a6dc9af 100644 --- a/packages/core/src/reflection/service/reflection.service.ts +++ b/packages/core/src/reflection/service/reflection.service.ts @@ -1,4 +1,4 @@ -import Decorator from "../../types/namespace/decorator.namespace"; +import Decorator from "../../decorators"; import Class from "../../types/validation/class.type"; /** diff --git a/packages/core/validators/any/Falsy.ts b/packages/core/validators/any/Falsy.ts index 61917c06a..8b09d83e2 100644 --- a/packages/core/validators/any/Falsy.ts +++ b/packages/core/validators/any/Falsy.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Creates a validator decorator for falsy value validation. @@ -32,7 +32,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function Falsy( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Falsy", diff --git a/packages/core/validators/any/Required.ts b/packages/core/validators/any/Required.ts index 0fc5adbd3..f514f528d 100644 --- a/packages/core/validators/any/Required.ts +++ b/packages/core/validators/any/Required.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Creates a validator decorator for required value validation. @@ -32,7 +32,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function Required( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Required", diff --git a/packages/core/validators/any/Rule.ts b/packages/core/validators/any/Rule.ts index 95ee2244f..14a6ccf42 100644 --- a/packages/core/validators/any/Rule.ts +++ b/packages/core/validators/any/Rule.ts @@ -1,4 +1,4 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import ValidatorService from "../../src/decorators/service/validator.service"; import Validation from "../../src/types/namespace/validation.namespace"; /** @@ -33,7 +33,7 @@ export default function Rule( groups?: Validation.GroupsParam; } ) { - return makeValidator({ + return ValidatorService.create({ isValid: "isValid" in props ? props.isValid : props, groups: "isValid" in props ? props.groups : [], }); diff --git a/packages/core/validators/any/Truthy.ts b/packages/core/validators/any/Truthy.ts index 4bb74aded..60d40daac 100644 --- a/packages/core/validators/any/Truthy.ts +++ b/packages/core/validators/any/Truthy.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Creates a decorator to validate that a value is truthy. @@ -31,7 +31,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function Truthy( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Truthy", diff --git a/packages/core/validators/any/valid.ts b/packages/core/validators/any/valid.ts index 830f8564d..e46aa3d9e 100644 --- a/packages/core/validators/any/valid.ts +++ b/packages/core/validators/any/valid.ts @@ -1,4 +1,4 @@ -import makeDecorator from "../../src/decorators/decorator.factory"; +import DecoratorService from "../../src/decorators/service/decorator.service"; import $ from "../../src/types"; import Class from "../../src/types/validation/class.type"; @@ -19,7 +19,7 @@ import Class from "../../src/types/validation/class.type"; export default function valid>( clazz: Class ) { - return makeDecorator<$.Objects.Optional>((name, meta) => { + return DecoratorService.create<$.Objects.Optional>((name, meta) => { meta.getUntypedDescriptor(name).thisClass = clazz; }); } diff --git a/packages/core/validators/array/ArrayContains.ts b/packages/core/validators/array/ArrayContains.ts index 8a807d054..bbc79564b 100644 --- a/packages/core/validators/array/ArrayContains.ts +++ b/packages/core/validators/array/ArrayContains.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that an array contains a specific value. @@ -35,7 +35,7 @@ export default function ArrayContains( } > ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArrayContains", diff --git a/packages/core/validators/array/ArrayEmpty.ts b/packages/core/validators/array/ArrayEmpty.ts index 2996191a9..622e2ca37 100644 --- a/packages/core/validators/array/ArrayEmpty.ts +++ b/packages/core/validators/array/ArrayEmpty.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that an array is empty. @@ -27,7 +27,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function ArrayEmpty( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArrayEmpty", diff --git a/packages/core/validators/array/ArrayEvery.ts b/packages/core/validators/array/ArrayEvery.ts index ae1514f12..61e003c7a 100644 --- a/packages/core/validators/array/ArrayEvery.ts +++ b/packages/core/validators/array/ArrayEvery.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that every element in an array passes a specified test. @@ -30,7 +30,7 @@ export default function ArrayEvery( test: $.Objects.ArrayPredicate; }> ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArrayEvery", diff --git a/packages/core/validators/array/ArrayNone.ts b/packages/core/validators/array/ArrayNone.ts index a6bf1fbcb..e308c2116 100644 --- a/packages/core/validators/array/ArrayNone.ts +++ b/packages/core/validators/array/ArrayNone.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that none of the elements in an array pass a specified test. @@ -30,7 +30,7 @@ export default function ArrayNone( test: $.Objects.ArrayPredicate; }> ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArrayNone", diff --git a/packages/core/validators/array/ArrayOne.ts b/packages/core/validators/array/ArrayOne.ts index c5cdfebce..5d60f8012 100644 --- a/packages/core/validators/array/ArrayOne.ts +++ b/packages/core/validators/array/ArrayOne.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that exactly one element in an array passes a specified test. @@ -30,7 +30,7 @@ export default function ArrayOne( test: $.Objects.ArrayPredicate; }> ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArrayOne", diff --git a/packages/core/validators/array/ArraySizeExact.ts b/packages/core/validators/array/ArraySizeExact.ts index ae6dcb73c..7110eef2f 100644 --- a/packages/core/validators/array/ArraySizeExact.ts +++ b/packages/core/validators/array/ArraySizeExact.ts @@ -1,10 +1,9 @@ -import makeValidator from "../../src/decorators/decorator.facade"; -import Decorator from "../../src/types/namespace/decorator.namespace"; - +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; /** @@ -35,7 +34,7 @@ export default function ArraySizeExact( > ) { const exact = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArraySizeExact", diff --git a/packages/core/validators/array/ArraySizeMax.ts b/packages/core/validators/array/ArraySizeMax.ts index 4d11dcef6..c47b505a4 100644 --- a/packages/core/validators/array/ArraySizeMax.ts +++ b/packages/core/validators/array/ArraySizeMax.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that an array has a maximum number of elements. @@ -34,7 +34,7 @@ export default function ArraySizeMax( > ) { const max = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArraySizeMax", diff --git a/packages/core/validators/array/ArraySizeMin.ts b/packages/core/validators/array/ArraySizeMin.ts index 9f3125606..63de51215 100644 --- a/packages/core/validators/array/ArraySizeMin.ts +++ b/packages/core/validators/array/ArraySizeMin.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that an array has a maximum number of elements. @@ -34,7 +34,7 @@ export default function ArraySizeMin( > ) { const min = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArraySizeMin", diff --git a/packages/core/validators/array/ArraySizeRange.ts b/packages/core/validators/array/ArraySizeRange.ts index 1e717a7db..6edb25b78 100644 --- a/packages/core/validators/array/ArraySizeRange.ts +++ b/packages/core/validators/array/ArraySizeRange.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that an array falls within a specified size range. @@ -40,7 +40,7 @@ export default function ArraySizeRange( ) { const min = typeof props === "number" ? props : props.min; const max = typeof props === "number" ? props : props.max; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArraySizeRange", diff --git a/packages/core/validators/array/ArraySome.ts b/packages/core/validators/array/ArraySome.ts index 2d26b7410..fcd743423 100644 --- a/packages/core/validators/array/ArraySome.ts +++ b/packages/core/validators/array/ArraySome.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that at least one element in an array passes a specific test. @@ -30,7 +30,7 @@ export default function ArraySome( test: $.Objects.ArrayPredicate; }> ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArraySome", diff --git a/packages/core/validators/array/ArrayUnique.ts b/packages/core/validators/array/ArrayUnique.ts index 0fe6bf67d..e70ddaeec 100644 --- a/packages/core/validators/array/ArrayUnique.ts +++ b/packages/core/validators/array/ArrayUnique.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; import Objects from "../../src/types/namespace/objects.namespace"; const DEFAULTS: Decorator.ImpartialProps<{ @@ -58,7 +58,7 @@ export default function ArrayUnique( const hashFn = typeof props === "string" ? $.Objects.hash : props.hash ?? $.Objects.hash; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (array, _, locale) => ({ key: "ArrayUnique", diff --git a/packages/core/validators/array/foreach.ts b/packages/core/validators/array/foreach.ts index d6362c8ae..9ba6ef358 100644 --- a/packages/core/validators/array/foreach.ts +++ b/packages/core/validators/array/foreach.ts @@ -1,6 +1,6 @@ -import makeDecorator from "../../src/decorators/decorator.factory"; +import Decorator from "../../src/decorators"; +import DecoratorService from "../../src/decorators/service/decorator.service"; import $ from "../../src/types/index"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for applying multiple validators to each element in an array property. @@ -19,9 +19,9 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; * This example applies the `MinLength` and `MaxLength` validators to each element in the `names` array property. */ export default function foreach any[])>>( - ...validators: Decorator.Type<$.Helper.ExtractArrayType>[] -): Decorator.Type { - return makeDecorator((property, processor, context) => { + ...validators: Decorator.Instance<$.Helper.ExtractArrayType>[] +): Decorator.Instance { + return DecoratorService.create((property, processor, context) => { const validationProcessor = processor.getUntypedDescriptor(property); validationProcessor.thisDefault = []; validators.forEach((validator) => { diff --git a/packages/core/validators/date/FutureDate.ts b/packages/core/validators/date/FutureDate.ts index 230bfa6d0..57d38e1f7 100644 --- a/packages/core/validators/date/FutureDate.ts +++ b/packages/core/validators/date/FutureDate.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { - evaluateNullableValidity, extractGroups, extractMessage, + isValidNullable, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating if a date is in the future. @@ -24,27 +24,19 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; * ``` * This example applies the `FutureDate` validator to the `eventDate` property to ensure it is a date in the future. */ -function isFutureDate(date: $.Objects.Optional): boolean { - // TODO: Maybe bump nullable validity to higher hierarchy - return evaluateNullableValidity(date, (d) => { - const currentDate = new Date(); - return d.getTime() > currentDate.getTime(); - }); -} - export default function FutureDate>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), - isValid: (date, _, locale) => ({ + isValid: (date, _context, locale) => ({ key: "FutureDate", message: extractMessage( props, TranslationService.translate(locale, "FutureDate", date!), locale ), - valid: isFutureDate(date), + valid: isValidNullable(date, (d) => d.getTime() > new Date().getTime()), }), }); } diff --git a/packages/core/validators/date/PastDate.ts b/packages/core/validators/date/PastDate.ts index 748b9a109..bab7a72b9 100644 --- a/packages/core/validators/date/PastDate.ts +++ b/packages/core/validators/date/PastDate.ts @@ -1,19 +1,12 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { - evaluateNullableValidity, extractGroups, extractMessage, + isValidNullable, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; - -function isPastDate(date: $.Objects.Optional): boolean { - return evaluateNullableValidity(date, (d) => { - const currentDate = new Date(); - return d.getTime() < currentDate.getTime(); - }); -} /** * Decorator for validating if a date is in the past. @@ -34,16 +27,16 @@ function isPastDate(date: $.Objects.Optional): boolean { export default function PastDate>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), - isValid: (date, _, locale) => ({ + isValid: (date, _context, locale) => ({ key: "PastDate", message: extractMessage( props, TranslationService.translate(locale, "PastDate", date!), locale ), - valid: isPastDate(date), + valid: isValidNullable(date, (d) => d.getTime() < new Date().getTime()), }), }); } diff --git a/packages/core/validators/date/TodayDate.ts b/packages/core/validators/date/TodayDate.ts index 635f23a3d..9848a2b61 100644 --- a/packages/core/validators/date/TodayDate.ts +++ b/packages/core/validators/date/TodayDate.ts @@ -1,23 +1,12 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { - evaluateNullableValidity, extractGroups, extractMessage, + isValidNullable, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; - -function isTodayDate(date: $.Objects.Optional): boolean { - return evaluateNullableValidity(date, (d) => { - const currentDate = new Date(); - return ( - d.getDate() === currentDate.getDate() && - d.getMonth() === currentDate.getMonth() && - d.getFullYear() === currentDate.getFullYear() - ); - }); -} /** * Decorator for validating if a date is today's date. @@ -38,16 +27,23 @@ function isTodayDate(date: $.Objects.Optional): boolean { export default function TodayDate>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), - isValid: (date, _, locale) => ({ + isValid: (date, _context, locale) => ({ key: "TodayDate", message: extractMessage( props, TranslationService.translate(locale, "TodayDate", date!), locale ), - valid: isTodayDate(date), + valid: isValidNullable(date, (d) => { + const currentDate = new Date(); + return ( + d.getDate() === currentDate.getDate() && + d.getMonth() === currentDate.getMonth() && + d.getFullYear() === currentDate.getFullYear() + ); + }), }), }); } diff --git a/packages/core/validators/number/Decimal.ts b/packages/core/validators/number/Decimal.ts index 23de5dc0c..26d9a594c 100644 --- a/packages/core/validators/number/Decimal.ts +++ b/packages/core/validators/number/Decimal.ts @@ -1,10 +1,9 @@ -import makeValidator from "../../src/decorators/decorator.facade"; -import Decorator from "../../src/types/namespace/decorator.namespace"; - +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; @@ -27,7 +26,7 @@ import $ from "../../src/types"; export default function Decimal>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Decimal", diff --git a/packages/core/validators/number/Digits.ts b/packages/core/validators/number/Digits.ts index 1a52e0bed..0917ad071 100644 --- a/packages/core/validators/number/Digits.ts +++ b/packages/core/validators/number/Digits.ts @@ -1,10 +1,9 @@ -import makeValidator from "../../src/decorators/decorator.facade"; -import Decorator from "../../src/types/namespace/decorator.namespace"; - +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import Localization from "../../src/localization"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; @@ -68,7 +67,7 @@ export default function Digits>( > ) { const { maxInteger = Infinity, maxFraction = Infinity } = props; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Digits", diff --git a/packages/core/validators/number/Integer.ts b/packages/core/validators/number/Integer.ts index 4b0f34cfd..b05f57c85 100644 --- a/packages/core/validators/number/Integer.ts +++ b/packages/core/validators/number/Integer.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that a value is an integer. @@ -26,7 +26,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function Integer>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (num, _, locale) => ({ key: "Integer", diff --git a/packages/core/validators/number/Negative.ts b/packages/core/validators/number/Negative.ts index 93321ca04..9ae06bc0c 100644 --- a/packages/core/validators/number/Negative.ts +++ b/packages/core/validators/number/Negative.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Decorator for validating that a value is a negative number. @@ -26,7 +26,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function Negative>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (num, _, locale) => ({ key: "Negative", diff --git a/packages/core/validators/number/NonNegative.ts b/packages/core/validators/number/NonNegative.ts index 095963ce2..6cc5290c2 100644 --- a/packages/core/validators/number/NonNegative.ts +++ b/packages/core/validators/number/NonNegative.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * NonNegative decorator for validating that a numeric value is non-negative. @@ -35,7 +35,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function NonNegative>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (num, _, locale) => ({ key: "NonNegative", diff --git a/packages/core/validators/number/NonPositive.ts b/packages/core/validators/number/NonPositive.ts index 6b2e0123a..37ced022b 100644 --- a/packages/core/validators/number/NonPositive.ts +++ b/packages/core/validators/number/NonPositive.ts @@ -1,8 +1,8 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractMessage } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * NonPositive decorator for validating that a numeric value is non-positive. @@ -32,7 +32,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function NonPositive>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ isValid: (num, _, locale) => ({ key: "NonPositive", message: extractMessage( diff --git a/packages/core/validators/number/Positive.ts b/packages/core/validators/number/Positive.ts index edb1b90eb..bf86374db 100644 --- a/packages/core/validators/number/Positive.ts +++ b/packages/core/validators/number/Positive.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Positive decorator for validating that a numeric value is positive. @@ -35,7 +35,7 @@ import Decorator from "../../src/types/namespace/decorator.namespace"; export default function Positive>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (num, _, locale) => ({ key: "Positive", diff --git a/packages/core/validators/number/ValueMax.ts b/packages/core/validators/number/ValueMax.ts index afc7a2fbd..405958c8c 100644 --- a/packages/core/validators/number/ValueMax.ts +++ b/packages/core/validators/number/ValueMax.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * ValueMax decorator for validating that a numeric value is less than or equal to a specified maximum value. @@ -42,7 +42,7 @@ export default function ValueMax>( > ) { const max = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "ValueMax", diff --git a/packages/core/validators/number/ValueMin.ts b/packages/core/validators/number/ValueMin.ts index db2b340b2..27f0a208c 100644 --- a/packages/core/validators/number/ValueMin.ts +++ b/packages/core/validators/number/ValueMin.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * ValueMin decorator for validating that a numeric value is greater than or equal to a specified minimum value. @@ -42,7 +42,7 @@ export default function ValueMin>( > ) { const min = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "ValueMin", diff --git a/packages/core/validators/number/ValueRange.ts b/packages/core/validators/number/ValueRange.ts index 410b5a51d..680c19015 100644 --- a/packages/core/validators/number/ValueRange.ts +++ b/packages/core/validators/number/ValueRange.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * ValueRange decorator for validating that a numeric value falls within a specified range. @@ -47,7 +47,7 @@ export default function ValueRange>( > ) { const { min, max } = props; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "ValueRange", diff --git a/packages/core/validators/string/ExactLength.ts b/packages/core/validators/string/ExactLength.ts index fa0a9a5e3..98827b9e7 100644 --- a/packages/core/validators/string/ExactLength.ts +++ b/packages/core/validators/string/ExactLength.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Creates a validator decorator for exact length validation. @@ -37,7 +37,7 @@ export default function ExactLength>( props: Decorator.PartialProps ) { const exact = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "ExactLength", diff --git a/packages/core/validators/string/Length.ts b/packages/core/validators/string/Length.ts index 423a3b3c9..064ac78b2 100644 --- a/packages/core/validators/string/Length.ts +++ b/packages/core/validators/string/Length.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Creates a validator decorator for length range validation. @@ -42,7 +42,7 @@ export default function Length>( }> ) { const { min, max } = props; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Length", diff --git a/packages/core/validators/string/MaxLength.ts b/packages/core/validators/string/MaxLength.ts index 60eaa8eaa..7fc0c0e2c 100644 --- a/packages/core/validators/string/MaxLength.ts +++ b/packages/core/validators/string/MaxLength.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Creates a validator decorator for maximum length validation. @@ -37,7 +37,7 @@ export default function MaxLength>( props: Decorator.PartialProps ) { const max = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "MaxLength", diff --git a/packages/core/validators/string/MinLength.ts b/packages/core/validators/string/MinLength.ts index 5e425bf16..2131f672e 100644 --- a/packages/core/validators/string/MinLength.ts +++ b/packages/core/validators/string/MinLength.ts @@ -1,11 +1,11 @@ -import makeValidator from "../../src/decorators/decorator.facade"; +import Decorator from "../../src/decorators"; import { extractGroups, extractMessage, } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import TranslationService from "../../src/localization/service/translation.service"; import $ from "../../src/types"; -import Decorator from "../../src/types/namespace/decorator.namespace"; /** * Creates a validator decorator for minimum length validation. @@ -37,7 +37,7 @@ export default function MinLength>( props: Decorator.PartialProps ) { const min = typeof props === "number" ? props : props.value; - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "MinLength", diff --git a/packages/core/validators/string/Password.ts b/packages/core/validators/string/Password.ts index 167cee350..2e55404fc 100644 --- a/packages/core/validators/string/Password.ts +++ b/packages/core/validators/string/Password.ts @@ -1,5 +1,5 @@ -import makeValidator from "../../src/decorators/decorator.facade"; import { extractGroups } from "../../src/decorators/decorator.utils"; +import ValidatorService from "../../src/decorators/service/validator.service"; import Localization from "../../src/localization"; import TranslationService from "../../src/localization/service/translation.service"; import RegexConst from "../../src/models/regex.constants"; @@ -106,7 +106,7 @@ export default function Password>(props?: { return buildConstraintViolation("", true); } - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (str, _, locale) => isValid(str ?? "", locale), }); diff --git a/packages/core/validators/string/regex/Pattern.ts b/packages/core/validators/string/regex/Pattern.ts index 2e328107a..9c46cc384 100644 --- a/packages/core/validators/string/regex/Pattern.ts +++ b/packages/core/validators/string/regex/Pattern.ts @@ -1,10 +1,10 @@ -import makeValidator from "../../../src/decorators/decorator.facade"; +import Decorator from "../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../src/decorators/service/validator.service"; import $ from "../../../src/types"; -import Decorator from "../../../src/types/namespace/decorator.namespace"; /** * Creates a validator decorator that checks if a string value matches a regular expression pattern. @@ -43,7 +43,7 @@ export default function Pattern>( groups?: $.Validation.GroupsParam; }> ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props.groups), isValid: (value, _, locale) => ({ key: props.key ?? "Pattern", diff --git a/packages/core/validators/string/regex/impl/Alpha.ts b/packages/core/validators/string/regex/impl/Alpha.ts index 9d7d556c9..8d7797f78 100644 --- a/packages/core/validators/string/regex/impl/Alpha.ts +++ b/packages/core/validators/string/regex/impl/Alpha.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "../Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "../Pattern"; export default function Alpha>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Alpha", diff --git a/packages/core/validators/string/regex/impl/Alphanumeric.ts b/packages/core/validators/string/regex/impl/Alphanumeric.ts index 794ffe0a1..b1452b462 100644 --- a/packages/core/validators/string/regex/impl/Alphanumeric.ts +++ b/packages/core/validators/string/regex/impl/Alphanumeric.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "../Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "../Pattern"; export default function Alphanumeric>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Alphanumeric", diff --git a/packages/core/validators/string/regex/impl/Email.ts b/packages/core/validators/string/regex/impl/Email.ts index c2beb3c8f..db7d19ae0 100644 --- a/packages/core/validators/string/regex/impl/Email.ts +++ b/packages/core/validators/string/regex/impl/Email.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "./../../regex/Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "./../../regex/Pattern"; export default function Email>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Email", diff --git a/packages/core/validators/string/regex/impl/IPAddress.ts b/packages/core/validators/string/regex/impl/IPAddress.ts index c6fa59850..ff6e31442 100644 --- a/packages/core/validators/string/regex/impl/IPAddress.ts +++ b/packages/core/validators/string/regex/impl/IPAddress.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "./../../regex/Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "./../../regex/Pattern"; export default function IPAddress>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "IPAddress", diff --git a/packages/core/validators/string/regex/impl/Lowercase.ts b/packages/core/validators/string/regex/impl/Lowercase.ts index 3341782d4..24dc20cfc 100644 --- a/packages/core/validators/string/regex/impl/Lowercase.ts +++ b/packages/core/validators/string/regex/impl/Lowercase.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "../Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "../Pattern"; export default function Lowercase>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Lowercase", diff --git a/packages/core/validators/string/regex/impl/Numeric.ts b/packages/core/validators/string/regex/impl/Numeric.ts index 08d6342fd..c0e434020 100644 --- a/packages/core/validators/string/regex/impl/Numeric.ts +++ b/packages/core/validators/string/regex/impl/Numeric.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "../Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "../Pattern"; export default function Numeric>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Numeric", diff --git a/packages/core/validators/string/regex/impl/URL.ts b/packages/core/validators/string/regex/impl/URL.ts index 22dd0618b..a64ff3a9b 100644 --- a/packages/core/validators/string/regex/impl/URL.ts +++ b/packages/core/validators/string/regex/impl/URL.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "./../../regex/Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "./../../regex/Pattern"; export default function URL>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "URL", diff --git a/packages/core/validators/string/regex/impl/Uppercase.ts b/packages/core/validators/string/regex/impl/Uppercase.ts index cbff03f76..0ed7bd214 100644 --- a/packages/core/validators/string/regex/impl/Uppercase.ts +++ b/packages/core/validators/string/regex/impl/Uppercase.ts @@ -1,12 +1,12 @@ -import makeValidator from "../../../../src/decorators/decorator.facade"; +import Decorator from "../../../../src/decorators"; import { extractGroups, extractMessage, } from "../../../../src/decorators/decorator.utils"; +import ValidatorService from "../../../../src/decorators/service/validator.service"; import TranslationService from "../../../../src/localization/service/translation.service"; import RegexConst from "../../../../src/models/regex.constants"; import $ from "../../../../src/types"; -import Decorator from "../../../../src/types/namespace/decorator.namespace"; import { testRegex } from "../Pattern"; /** @@ -39,7 +39,7 @@ import { testRegex } from "../Pattern"; export default function Uppercase>( props?: Decorator.PartialProps ) { - return makeValidator({ + return ValidatorService.create({ groups: extractGroups(props), isValid: (value, _, locale) => ({ key: "Uppercase",