@composer-js/core
Advanced tools
Comparing version 6.0.0-rc.17 to 6.0.0-rc.19
@@ -19,7 +19,9 @@ "use strict"; | ||
* @param obj The object or array of objects to validate. | ||
* @param clazz The class type that contains the validation metadata. | ||
* @param recurse Set to `true` to validate all child objects. | ||
*/ | ||
static validate(obj, recurse) { | ||
static validate(obj, clazz, recurse) { | ||
const objs = Array.isArray(obj) ? obj : [obj]; | ||
for (const obj of objs) { | ||
const metadataObj = !clazz || obj instanceof clazz ? obj : new clazz(); | ||
// Iterate through all properties of the object | ||
@@ -29,3 +31,3 @@ for (const member of Object.getOwnPropertyNames(obj)) { | ||
continue; | ||
const nullable = Reflect.getMetadata("cjs:nullable", obj, member); | ||
const nullable = Reflect.getMetadata("cjs:nullable", metadataObj, member); | ||
// Value of '0' is valid. Don't throw on such values. | ||
@@ -35,3 +37,3 @@ if (!nullable && (obj[member] === null || obj[member] === undefined || obj[member] === "")) { | ||
} | ||
const validator = Reflect.getMetadata("cjs:validator", obj, member); | ||
const validator = Reflect.getMetadata("cjs:validator", metadataObj, member); | ||
if (validator && obj[member] && !validator(obj[member])) { | ||
@@ -38,0 +40,0 @@ throw new Error(`Property ${member} is invalid.`); |
@@ -13,5 +13,6 @@ import "reflect-metadata"; | ||
* @param obj The object or array of objects to validate. | ||
* @param clazz The class type that contains the validation metadata. | ||
* @param recurse Set to `true` to validate all child objects. | ||
*/ | ||
static validate(obj: any, recurse?: boolean): void; | ||
static validate(obj: any, clazz?: any, recurse?: boolean): void; | ||
} |
{ | ||
"name": "@composer-js/core", | ||
"version": "6.0.0-rc.17", | ||
"version": "6.0.0-rc.19", | ||
"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
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
220745
3635