@finnair/v-validation
Advanced tools
Comparing version 3.0.0-alpha.2 to 3.0.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [3.0.0](https://github.com/finnair/v-validation/compare/v2.0.0...v3.0.0) (2022-10-03) | ||
**Note:** Version bump only for package @finnair/v-validation | ||
# [3.0.0-alpha.2](https://github.com/finnair/v-validation/compare/v2.0.0...v3.0.0-alpha.2) (2022-09-28) | ||
@@ -8,0 +16,0 @@ |
import { SchemaValidator, SchemaModel } from './schema'; | ||
import { Path } from '@finnair/path'; | ||
import { IgnoreValidator, ArrayNormalizer, AnyValidator, StringValidator, StringNormalizer, NotNullOrUndefinedValidator, IsNullOrUndefinedValidator, NotEmptyValidator, NotBlankValidator, ValueMapper, BooleanValidator, NumberValidator, NumberNormalizer, DateValidator, ValidatorFn, ValidatorFnWrapper, MappingFn, Validator, CheckValidator, OptionalValidator, AssertTrue, IfValidator, GroupOrName, WhenGroupValidator, AssertTrueValidator, PatternValidator, PatternNormalizer, BooleanNormalizer, MinValidator, MaxValidator, ObjectModel, ObjectValidator, ObjectNormalizer, MapValidator, MapNormalizer, ArrayValidator, SizeValidator, AllOfValidator, AnyOfValidator, OneOfValidator, CompositionValidator, EnumValidator, HasValueValidator, JsonValidator } from './validators'; | ||
import { IgnoreValidator, ArrayNormalizer, AnyValidator, StringValidator, StringNormalizer, NotNullOrUndefinedValidator, IsNullOrUndefinedValidator, NotEmptyValidator, NotBlankValidator, ValueMapper, BooleanValidator, NumberValidator, NumberNormalizer, DateValidator, ValidatorFn, ValidatorFnWrapper, MappingFn, Validator, CheckValidator, OptionalValidator, AssertTrue, IfValidator, GroupOrName, WhenGroupValidator, AssertTrueValidator, PatternValidator, PatternNormalizer, BooleanNormalizer, MinValidator, MaxValidator, ObjectModel, ObjectValidator, ObjectNormalizer, MapValidator, MapNormalizer, ArrayValidator, SizeValidator, AllOfValidator, AnyOfValidator, OneOfValidator, CompositionValidator, EnumValidator, HasValueValidator, JsonValidator, RequiredValidator } from './validators'; | ||
declare const V: { | ||
@@ -11,3 +11,3 @@ fn: (fn: ValidatorFn, type?: string) => ValidatorFnWrapper; | ||
optional: (type: Validator, ...allOf: Validator[]) => OptionalValidator; | ||
required: (type: Validator, ...allOf: Validator[]) => Validator; | ||
required: (type: Validator, ...allOf: Validator[]) => RequiredValidator; | ||
if: (fn: AssertTrue, ...allOf: Validator[]) => IfValidator; | ||
@@ -14,0 +14,0 @@ whenGroup: (group: GroupOrName, ...allOf: Validator[]) => WhenGroupValidator; |
@@ -17,3 +17,3 @@ "use strict"; | ||
optional: (type, ...allOf) => new validators_1.OptionalValidator(type, allOf), | ||
required: (type, ...allOf) => new validators_1.NotNullOrUndefinedValidator().next(type).next(...allOf), | ||
required: (type, ...allOf) => new validators_1.RequiredValidator(type, allOf), | ||
if: (fn, ...allOf) => new validators_1.IfValidator([new validators_1.Conditional(fn, allOf)]), | ||
@@ -20,0 +20,0 @@ whenGroup: (group, ...allOf) => new validators_1.WhenGroupValidator([new validators_1.WhenGroup(group, allOf)]), |
@@ -399,2 +399,7 @@ import { Path } from '@finnair/path'; | ||
} | ||
export declare class RequiredValidator extends Validator { | ||
private readonly validator; | ||
constructor(type: Validator, allOf: Validator[]); | ||
validatePath(value: any, path: Path, ctx: ValidationContext): PromiseLike<ValidationResult>; | ||
} | ||
export declare class ValueMapper extends Validator { | ||
@@ -401,0 +406,0 @@ readonly fn: MappingFn; |
@@ -16,3 +16,3 @@ "use strict"; | ||
exports.BooleanValidator = exports.NotBlankValidator = exports.SizeValidator = exports.NotEmptyValidator = exports.IsNullOrUndefinedValidator = exports.NotNullOrUndefinedValidator = exports.StringNormalizer = exports.StringValidator = exports.isSimplePrimitive = exports.isString = exports.AnyValidator = exports.JsonMap = exports.MapNormalizer = exports.MapValidator = exports.WhenGroup = exports.WhenGroupValidator = exports.Conditional = exports.IfValidator = exports.AnyOfValidator = exports.OneOfValidator = exports.CompositionValidator = exports.CheckValidator = exports.NextValidator = exports.ArrayNormalizer = exports.ArrayValidator = exports.MapEntryValidator = exports.ObjectNormalizer = exports.ObjectValidator = exports.mergeProperties = exports.ValidatorFnWrapper = exports.defaultViolations = exports.ValidatorType = exports.isNullOrUndefined = exports.Groups = exports.Group = exports.SizeViolation = exports.MaxViolation = exports.MinViolation = exports.OneOfMismatch = exports.PatternViolation = exports.HasValueViolation = exports.ErrorViolation = exports.EnumMismatch = exports.TypeMismatch = exports.Violation = exports.ValidationError = exports.ValidationResult = exports.Validator = exports.SyncPromise = exports.ValidationContext = void 0; | ||
exports.JsonValidator = exports.IgnoreValidator = exports.isPromise = exports.ValueMapper = exports.OptionalValidator = exports.PatternNormalizer = exports.PatternValidator = exports.DateValidator = exports.AllOfValidator = exports.maybeAllOfValidator = exports.HasValueValidator = exports.AssertTrueValidator = exports.EnumValidator = exports.MaxValidator = exports.MinValidator = exports.NumberNormalizer = exports.NumberValidator = exports.isNumber = exports.NumberFormat = exports.BooleanNormalizer = void 0; | ||
exports.JsonValidator = exports.IgnoreValidator = exports.isPromise = exports.ValueMapper = exports.RequiredValidator = exports.OptionalValidator = exports.PatternNormalizer = exports.PatternValidator = exports.DateValidator = exports.AllOfValidator = exports.maybeAllOfValidator = exports.HasValueValidator = exports.AssertTrueValidator = exports.EnumValidator = exports.MaxValidator = exports.MinValidator = exports.NumberNormalizer = exports.NumberValidator = exports.isNumber = exports.NumberFormat = exports.BooleanNormalizer = void 0; | ||
const deep_equal_1 = __importDefault(require("deep-equal")); | ||
@@ -27,4 +27,3 @@ const path_1 = require("@finnair/path"); | ||
failure(violation, value) { | ||
let violations = []; | ||
violations = violations.concat(violation); | ||
const violations = [].concat(violation); | ||
if (violations.length === 1) { | ||
@@ -100,5 +99,3 @@ if (this.ignoreViolation(violations[0])) { | ||
validate(value, options) { | ||
return new Promise((resolve, reject) => { | ||
this.validatePath(value, ROOT, new ValidationContext(options || {})).then(resolve, reject); | ||
}); | ||
return Promise.resolve(this.validatePath(value, ROOT, new ValidationContext(options || {}))); | ||
} | ||
@@ -1370,2 +1367,21 @@ next(...allOf) { | ||
exports.OptionalValidator = OptionalValidator; | ||
class RequiredValidator extends Validator { | ||
constructor(type, allOf) { | ||
super(); | ||
if (allOf && allOf.length > 0) { | ||
this.validator = new NextValidator(type, maybeAllOfValidator(allOf)); | ||
} | ||
else { | ||
this.validator = type; | ||
} | ||
Object.freeze(this); | ||
} | ||
validatePath(value, path, ctx) { | ||
if (isNullOrUndefined(value)) { | ||
return ctx.failurePromise(exports.defaultViolations.notNull(path), value); | ||
} | ||
return this.validator.validatePath(value, path, ctx); | ||
} | ||
} | ||
exports.RequiredValidator = RequiredValidator; | ||
class ValueMapper extends Validator { | ||
@@ -1372,0 +1388,0 @@ constructor(fn, error) { |
{ | ||
"name": "@finnair/v-validation", | ||
"version": "3.0.0-alpha.2", | ||
"version": "3.0.0", | ||
"private": false, | ||
@@ -27,3 +27,3 @@ "description": "V-validation core package", | ||
"dependencies": { | ||
"@finnair/path": "^3.0.0-alpha.2", | ||
"@finnair/path": "^3.0.0", | ||
"@types/deep-equal": "1.0.1", | ||
@@ -34,3 +34,3 @@ "@types/uuid-validate": "0.0.1", | ||
}, | ||
"gitHead": "d42bd7583bb684429e48ce8e5db3938cb95ffd5f" | ||
"gitHead": "597b85f1fcef99722bccf47c6d30260973d6d88c" | ||
} |
@@ -186,3 +186,3 @@ ![CI](https://github.com/finnair/v-validation/workflows/CI/badge.svg?branch=master) | ||
- No need to register custom validators | ||
- All the validators are immutable | ||
- All the validators are effectively immutable | ||
- Supports recursive types/validators (e.g. linked list) | ||
@@ -189,0 +189,0 @@ - Supports cyclic data: allow or disallow by configuration |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
135845
2267
0
Updated@finnair/path@^3.0.0