@composer-js/core
Advanced tools
Comparing version 6.0.0-rc.14 to 6.0.0-rc.16
@@ -26,2 +26,3 @@ "use strict"; | ||
__exportStar(require("./ObjectFactory"), exports); | ||
__exportStar(require("./ObjectUtils"), exports); | ||
__exportStar(require("./OASUtils"), exports); | ||
@@ -28,0 +29,0 @@ __exportStar(require("./StringUtils"), exports); |
@@ -15,25 +15,28 @@ "use strict"; | ||
/** | ||
* Performs validation of the given object. Validation is performed by scanning the object class for properties | ||
* Performs validation of the given object or array. Validation is performed by scanning the object class for properties | ||
* decorated with `@Validator` and executing the provided validation function. | ||
* | ||
* @param obj The object to validate. | ||
* @param obj The object or array of objects to validate. | ||
* @param recurse Set to `true` to validate all child objects. | ||
*/ | ||
static validate(obj, recurse) { | ||
// Iterate through all properties of the object | ||
for (const member of Object.getOwnPropertyNames(obj)) { | ||
if (member === 'constructor') | ||
continue; | ||
const nullable = Reflect.getMetadata("cjs:nullable", obj, member); | ||
if (!nullable && !obj[member]) { | ||
throw new Error(`Property ${member} cannot be null.`); | ||
const objs = Array.isArray(obj) ? obj : [obj]; | ||
for (const obj of objs) { | ||
// Iterate through all properties of the object | ||
for (const member of Object.getOwnPropertyNames(obj)) { | ||
if (member === 'constructor') | ||
continue; | ||
const nullable = Reflect.getMetadata("cjs:nullable", obj, member); | ||
if (!nullable && !obj[member]) { | ||
throw new Error(`Property ${member} cannot be null.`); | ||
} | ||
const validator = Reflect.getMetadata("cjs:validator", obj, member); | ||
if (validator && obj[member] && !validator(obj[member])) { | ||
throw new Error(`Property ${member} is invalid.`); | ||
} | ||
// If recursion is requested validate the child object | ||
if (recurse && typeof obj[member] === "object") { | ||
ObjectUtils.validate(obj[member], recurse); | ||
} | ||
} | ||
const validator = Reflect.getMetadata("cjs:validator", obj, member); | ||
if (validator && obj[member] && !validator(obj[member])) { | ||
throw new Error(`Property ${member} is invalid.`); | ||
} | ||
// If recursion is requested validate the child object | ||
if (recurse && typeof obj[member] === "object") { | ||
ObjectUtils.validate(obj[member], recurse); | ||
} | ||
} | ||
@@ -40,0 +43,0 @@ } |
@@ -10,2 +10,3 @@ export * from "./ApiError"; | ||
export * from "./ObjectFactory"; | ||
export * from "./ObjectUtils"; | ||
export * from "./OASUtils"; | ||
@@ -12,0 +13,0 @@ export * from "./StringUtils"; |
@@ -9,6 +9,6 @@ import "reflect-metadata"; | ||
/** | ||
* Performs validation of the given object. Validation is performed by scanning the object class for properties | ||
* Performs validation of the given object or array. Validation is performed by scanning the object class for properties | ||
* decorated with `@Validator` and executing the provided validation function. | ||
* | ||
* @param obj The object to validate. | ||
* @param obj The object or array of objects to validate. | ||
* @param recurse Set to `true` to validate all child objects. | ||
@@ -15,0 +15,0 @@ */ |
{ | ||
"name": "@composer-js/core", | ||
"version": "6.0.0-rc.14", | ||
"version": "6.0.0-rc.16", | ||
"description": "A collection of common utilities and core functionality for composerjs applications.", | ||
@@ -5,0 +5,0 @@ "repository": "https://gitlab.acceleratxr.com/composerjs/composer-core.git", |
Sorry, the diff of this file is not supported yet
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
220130
3631