@finnair/v-validation
Advanced tools
Comparing version 6.0.2 to 6.1.0
@@ -6,2 +6,9 @@ # Change Log | ||
# [6.1.0](https://github.com/finnair/v-validation/compare/v6.0.2...v6.1.0) (2024-10-21) | ||
### Features | ||
- UUID v7 support ([#115](https://github.com/finnair/v-validation/issues/115)) ([2312c94](https://github.com/finnair/v-validation/commit/2312c943d3362fc85a242903381654c4db7dd5c6)) | ||
- validation result as unknown instead of any ([#116](https://github.com/finnair/v-validation/issues/116)) ([124f14e](https://github.com/finnair/v-validation/commit/124f14ef949f4b9a11143d49d6554efdc8b955f4)) | ||
## [6.0.2](https://github.com/finnair/v-validation/compare/v6.0.1...v6.0.2) (2024-09-17) | ||
@@ -8,0 +15,0 @@ |
import { SchemaValidator, SchemaModel } from './schema.js'; | ||
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, RequiredValidator, SetValidator } from './validators.js'; | ||
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, SetValidator, UuidValidator } from './validators.js'; | ||
export declare const V: { | ||
@@ -24,3 +24,3 @@ fn: (fn: ValidatorFn, type?: string) => ValidatorFnWrapper; | ||
emptyTo: (defaultValue: any) => ValueMapper; | ||
uuid: (version?: number) => AssertTrueValidator; | ||
uuid: (version?: number) => UuidValidator; | ||
pattern: (pattern: string | RegExp, flags?: string) => PatternValidator; | ||
@@ -27,0 +27,0 @@ toPattern: (pattern: string | RegExp, flags?: string) => PatternNormalizer; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.V = void 0; | ||
const uuid_validate_1 = __importDefault(require("uuid-validate")); | ||
const schema_js_1 = require("./schema.js"); | ||
@@ -31,3 +27,3 @@ const validators_js_1 = require("./validators.js"); | ||
emptyTo: (defaultValue) => new validators_js_1.ValueMapper((value) => ((0, validators_js_1.isNullOrUndefined)(value) || value === '' ? defaultValue : value)), | ||
uuid: (version) => new validators_js_1.AssertTrueValidator((value) => !(0, validators_js_1.isNullOrUndefined)(value) && (0, uuid_validate_1.default)(value, version), 'UUID'), | ||
uuid: (version) => new validators_js_1.UuidValidator(version), | ||
pattern: (pattern, flags) => new validators_js_1.PatternValidator(pattern, flags), | ||
@@ -34,0 +30,0 @@ toPattern: (pattern, flags) => new validators_js_1.PatternNormalizer(pattern, flags), |
@@ -48,6 +48,6 @@ import { Path } from '@finnair/path'; | ||
private violations?; | ||
constructor(violations?: Violation[], value?: any); | ||
constructor(violations?: Violation[], value?: unknown); | ||
isSuccess(): boolean; | ||
isFailure(): boolean; | ||
getValue(): any; | ||
getValue(): unknown; | ||
getViolations(): Violation[]; | ||
@@ -377,2 +377,7 @@ } | ||
} | ||
export declare class UuidValidator extends Validator { | ||
readonly version?: number | undefined; | ||
constructor(version?: number | undefined); | ||
validatePath(value: any, path: Path, ctx: ValidationContext): PromiseLike<ValidationResult>; | ||
} | ||
export declare class HasValueValidator extends Validator { | ||
@@ -379,0 +384,0 @@ readonly expectedValue: any; |
@@ -7,5 +7,6 @@ "use strict"; | ||
exports.SizeValidator = exports.NotEmptyValidator = exports.IsNullOrUndefinedValidator = exports.NotNullOrUndefinedValidator = exports.StringNormalizer = exports.StringValidator = exports.isSimplePrimitive = exports.isString = exports.AnyValidator = exports.JsonSet = exports.SetValidator = 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.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 = exports.BooleanValidator = exports.NotBlankValidator = 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.UuidValidator = exports.AssertTrueValidator = exports.EnumValidator = exports.MaxValidator = exports.MinValidator = exports.NumberNormalizer = exports.NumberValidator = exports.isNumber = exports.NumberFormat = exports.BooleanNormalizer = exports.BooleanValidator = exports.NotBlankValidator = void 0; | ||
const deep_equal_1 = __importDefault(require("deep-equal")); | ||
const path_1 = require("@finnair/path"); | ||
const uuid_1 = require("uuid"); | ||
const ROOT = path_1.Path.ROOT; | ||
@@ -1314,2 +1315,25 @@ class ValidationContext { | ||
exports.AssertTrueValidator = AssertTrueValidator; | ||
class UuidValidator extends Validator { | ||
version; | ||
constructor(version) { | ||
super(); | ||
this.version = version; | ||
} | ||
validatePath(value, path, ctx) { | ||
if (isNullOrUndefined(value)) { | ||
return ctx.failurePromise(exports.defaultViolations.notNull(path), value); | ||
} | ||
if (!isString(value)) { | ||
return ctx.failurePromise(exports.defaultViolations.string(value, path), value); | ||
} | ||
if (!(0, uuid_1.validate)(value)) { | ||
return ctx.failurePromise(new Violation(path, 'UUID', value), value); | ||
} | ||
if (this.version && (0, uuid_1.version)(value) !== this.version) { | ||
return ctx.failurePromise(new Violation(path, `UUIDv${this.version}`, value), value); | ||
} | ||
return ctx.successPromise(value); | ||
} | ||
} | ||
exports.UuidValidator = UuidValidator; | ||
class HasValueValidator extends Validator { | ||
@@ -1316,0 +1340,0 @@ expectedValue; |
import { SchemaValidator, SchemaModel } from './schema.js'; | ||
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, RequiredValidator, SetValidator } from './validators.js'; | ||
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, SetValidator, UuidValidator } from './validators.js'; | ||
export declare const V: { | ||
@@ -24,3 +24,3 @@ fn: (fn: ValidatorFn, type?: string) => ValidatorFnWrapper; | ||
emptyTo: (defaultValue: any) => ValueMapper; | ||
uuid: (version?: number) => AssertTrueValidator; | ||
uuid: (version?: number) => UuidValidator; | ||
pattern: (pattern: string | RegExp, flags?: string) => PatternValidator; | ||
@@ -27,0 +27,0 @@ toPattern: (pattern: string | RegExp, flags?: string) => PatternNormalizer; |
@@ -1,4 +0,3 @@ | ||
import { default as validateUuid } from 'uuid-validate'; | ||
import { SchemaValidator } from './schema.js'; | ||
import { IgnoreValidator, ArrayNormalizer, AnyValidator, StringValidator, StringNormalizer, NotNullOrUndefinedValidator, IsNullOrUndefinedValidator, NotEmptyValidator, NotBlankValidator, ValueMapper, isNullOrUndefined, BooleanValidator, NumberValidator, NumberFormat, NumberNormalizer, DateValidator, ValidatorType, ValidatorFnWrapper, CheckValidator, maybeAllOfValidator, OptionalValidator, IfValidator, Conditional, WhenGroupValidator, WhenGroup, AssertTrueValidator, PatternValidator, PatternNormalizer, BooleanNormalizer, MinValidator, MaxValidator, ObjectValidator, ObjectNormalizer, MapValidator, MapNormalizer, ArrayValidator, SizeValidator, AllOfValidator, AnyOfValidator, OneOfValidator, CompositionValidator, EnumValidator, HasValueValidator, JsonValidator, RequiredValidator, SetValidator, } from './validators.js'; | ||
import { IgnoreValidator, ArrayNormalizer, AnyValidator, StringValidator, StringNormalizer, NotNullOrUndefinedValidator, IsNullOrUndefinedValidator, NotEmptyValidator, NotBlankValidator, ValueMapper, isNullOrUndefined, BooleanValidator, NumberValidator, NumberFormat, NumberNormalizer, DateValidator, ValidatorType, ValidatorFnWrapper, CheckValidator, maybeAllOfValidator, OptionalValidator, IfValidator, Conditional, WhenGroupValidator, WhenGroup, AssertTrueValidator, PatternValidator, PatternNormalizer, BooleanNormalizer, MinValidator, MaxValidator, ObjectValidator, ObjectNormalizer, MapValidator, MapNormalizer, ArrayValidator, SizeValidator, AllOfValidator, AnyOfValidator, OneOfValidator, CompositionValidator, EnumValidator, HasValueValidator, JsonValidator, RequiredValidator, SetValidator, UuidValidator, } from './validators.js'; | ||
const ignoreValidator = new IgnoreValidator(), anyValidator = new AnyValidator(), stringValidator = new StringValidator(), toStringValidator = new StringNormalizer(), notNullValidator = new NotNullOrUndefinedValidator(), nullOrUndefinedValidator = new IsNullOrUndefinedValidator(), notEmptyValidator = new NotEmptyValidator(), notBlankValidator = new NotBlankValidator(), emptyToNullValidator = new ValueMapper((value) => (isNullOrUndefined(value) || value === '' ? null : value)), emptyToUndefinedValidator = new ValueMapper((value) => (isNullOrUndefined(value) || value === '' ? undefined : value)), undefinedToNullValidator = new ValueMapper((value) => (value === undefined ? null : value)), booleanValidator = new BooleanValidator(), numberValidator = new NumberValidator(NumberFormat.number), toNumberValidator = new NumberNormalizer(NumberFormat.number), integerValidator = new NumberValidator(NumberFormat.integer), toIntegerValidator = new NumberNormalizer(NumberFormat.integer), dateValidator = new DateValidator(ValidatorType.Date); | ||
@@ -25,3 +24,3 @@ export const V = { | ||
emptyTo: (defaultValue) => new ValueMapper((value) => (isNullOrUndefined(value) || value === '' ? defaultValue : value)), | ||
uuid: (version) => new AssertTrueValidator((value) => !isNullOrUndefined(value) && validateUuid(value, version), 'UUID'), | ||
uuid: (version) => new UuidValidator(version), | ||
pattern: (pattern, flags) => new PatternValidator(pattern, flags), | ||
@@ -28,0 +27,0 @@ toPattern: (pattern, flags) => new PatternNormalizer(pattern, flags), |
@@ -48,6 +48,6 @@ import { Path } from '@finnair/path'; | ||
private violations?; | ||
constructor(violations?: Violation[], value?: any); | ||
constructor(violations?: Violation[], value?: unknown); | ||
isSuccess(): boolean; | ||
isFailure(): boolean; | ||
getValue(): any; | ||
getValue(): unknown; | ||
getViolations(): Violation[]; | ||
@@ -377,2 +377,7 @@ } | ||
} | ||
export declare class UuidValidator extends Validator { | ||
readonly version?: number | undefined; | ||
constructor(version?: number | undefined); | ||
validatePath(value: any, path: Path, ctx: ValidationContext): PromiseLike<ValidationResult>; | ||
} | ||
export declare class HasValueValidator extends Validator { | ||
@@ -379,0 +384,0 @@ readonly expectedValue: any; |
import deepEqual from 'deep-equal'; | ||
import { Path } from '@finnair/path'; | ||
import { validate as uuidValidate, version as uuidVersion } from 'uuid'; | ||
const ROOT = Path.ROOT; | ||
@@ -1248,2 +1249,24 @@ export class ValidationContext { | ||
} | ||
export class UuidValidator extends Validator { | ||
version; | ||
constructor(version) { | ||
super(); | ||
this.version = version; | ||
} | ||
validatePath(value, path, ctx) { | ||
if (isNullOrUndefined(value)) { | ||
return ctx.failurePromise(defaultViolations.notNull(path), value); | ||
} | ||
if (!isString(value)) { | ||
return ctx.failurePromise(defaultViolations.string(value, path), value); | ||
} | ||
if (!uuidValidate(value)) { | ||
return ctx.failurePromise(new Violation(path, 'UUID', value), value); | ||
} | ||
if (this.version && uuidVersion(value) !== this.version) { | ||
return ctx.failurePromise(new Violation(path, `UUIDv${this.version}`, value), value); | ||
} | ||
return ctx.successPromise(value); | ||
} | ||
} | ||
export class HasValueValidator extends Validator { | ||
@@ -1250,0 +1273,0 @@ expectedValue; |
{ | ||
"name": "@finnair/v-validation", | ||
"version": "6.0.2", | ||
"version": "6.1.0", | ||
"private": false, | ||
@@ -43,5 +43,5 @@ "description": "V-validation core package", | ||
"@types/deep-equal": "1.0.1", | ||
"@types/uuid-validate": "0.0.1", | ||
"@types/uuid": "10.0.0", | ||
"deep-equal": "2.0.5", | ||
"uuid-validate": "0.0.3" | ||
"uuid": "10.0.0" | ||
}, | ||
@@ -52,5 +52,5 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@finnair/path": "^6.0.2" | ||
"@finnair/path": "^6.1.0" | ||
}, | ||
"gitHead": "0dd874f22590eea1c9691a62f1e19e28707005e5" | ||
"gitHead": "24a7a43d0a5201a29d650e8bb767195d14af9784" | ||
} |
@@ -543,4 +543,4 @@ ![CI](https://github.com/finnair/v-validation/workflows/CI/badge.svg?branch=master) | ||
| notBlank | | Requires non-null, non-undefined and not blank (whitespace only string) values. | | ||
| uuid | version?: number | Uses `uuid-validate` package to validate input. | | ||
| pattern | pattern: string \| RegExp, flags?: string | Tests input against the pattern. | | ||
| uuid | version?: number | Uses `uuid` package to validate input. | | ||
| pattern | pattern: string \| RegExp, flags?: string | Tests input against the pattern. | | ||
| toPattern | | Combines `toString` normalization with pattern validator. | | ||
@@ -547,0 +547,0 @@ | boolean | | Requires that input is primitive boolean. | |
Sorry, the diff of this file is not supported yet
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
260760
4685
+ Added@types/uuid@10.0.0
+ Addeduuid@10.0.0
+ Added@types/uuid@10.0.0(transitive)
+ Addeduuid@10.0.0(transitive)
- Removed@types/uuid-validate@0.0.1
- Removeduuid-validate@0.0.3
- Removed@types/uuid-validate@0.0.1(transitive)
- Removeduuid-validate@0.0.3(transitive)