typedconverter
Advanced tools
Comparing version 1.0.0-beta.5 to 1.0.0-beta.6
@@ -11,2 +11,5 @@ "use strict"; | ||
exports.PartialValidator = PartialValidator; | ||
// --------------------------------------------------------------------- // | ||
// ----------------------------- DECORATORS ---------------------------- // | ||
// --------------------------------------------------------------------- // | ||
function createValidation(validator) { | ||
@@ -24,2 +27,17 @@ return tinspector_1.decorateProperty({ type: "tc:validator", validator }); | ||
exports.partial = partial; | ||
// --------------------------------------------------------------------- // | ||
// ------------------------------ HELPERS ------------------------------ // | ||
// --------------------------------------------------------------------- // | ||
function isOptional(i) { | ||
return i.decorators.find((x) => x.validator === OptionalValidator); | ||
} | ||
function isPartial(i) { | ||
return i.parent && i.parent.decorators.find((x) => x.validator === PartialValidator); | ||
} | ||
function isEmpty(result) { | ||
return (result.value === undefined || result.value === null) && result.issues === undefined; | ||
} | ||
// --------------------------------------------------------------------- // | ||
// ------------------------------ VISITORS ----------------------------- // | ||
// --------------------------------------------------------------------- // | ||
/** | ||
@@ -31,6 +49,3 @@ * When registered to the converter, this visitor will make all variable or properties required by default, except optional decorator added | ||
const result = i.proceed(); | ||
const isEmpty = () => (result.value === undefined || result.value === null) && result.issues === undefined; | ||
const isOptional = () => i.decorators.find((x) => x.validator === OptionalValidator); | ||
const isPartial = () => i.parent && i.parent.decorators.find((x) => x.validator === PartialValidator); | ||
if (isEmpty() && !isOptional() && !isPartial()) | ||
if (isEmpty(result) && !isOptional(i) && !isPartial(i)) | ||
return visitor_1.Result.error(i.path, `Required`); | ||
@@ -48,4 +63,7 @@ else | ||
const validators = getValidators(i); | ||
if (validators.length > 0) { | ||
const result = i.proceed(); | ||
const result = i.proceed(); | ||
//if empty then don't do any more validation | ||
if (isEmpty(result) || validators.length === 0) | ||
return result; | ||
else { | ||
const messages = []; | ||
@@ -61,5 +79,3 @@ for (const validator of validators) { | ||
} | ||
else | ||
return i.proceed(); | ||
} | ||
exports.validatorVisitor = validatorVisitor; |
{ | ||
"name": "typedconverter", | ||
"version": "1.0.0-beta.5", | ||
"version": "1.0.0-beta.6", | ||
"description": "Convert object into classes match with TypeScript type annotation", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
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
39649
807