backend v4 half

This commit is contained in:
Donat committed 2025-07-18 09:20:40 +02:00
1 parent aba7a506ad
commit 725516ad6c
4183 files changed
+217684 -75056

No files matched your search

@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=ValidationArguments.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ValidationArguments.js","sourceRoot":"","sources":["../../../src/validation/ValidationArguments.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Arguments being sent to message builders - user can create message either by simply returning a string,\n * either by returning a function that accepts MessageArguments and returns a message string built based on these arguments.\n */\nexport interface ValidationArguments {\n /**\n * Validating value.\n */\n value: any;\n\n /**\n * Constraints set by this validation type.\n */\n constraints: any[];\n\n /**\n * Name of the target that is being validated.\n */\n targetName: string;\n\n /**\n * Object that is being validated.\n */\n object: object;\n\n /**\n * Name of the object's property being validated.\n */\n property: string;\n}\n"]}
@@ -0,0 +1,57 @@
/**
* Validation error description.
*/
var ValidationError = /** @class */ (function () {
function ValidationError() {
}
/**
*
* @param shouldDecorate decorate the message with ANSI formatter escape codes for better readability
* @param hasParent true when the error is a child of an another one
* @param parentPath path as string to the parent of this property
* @param showConstraintMessages show constraint messages instead of constraint names
*/
ValidationError.prototype.toString = function (shouldDecorate, hasParent, parentPath, showConstraintMessages) {
var _this = this;
if (shouldDecorate === void 0) { shouldDecorate = false; }
if (hasParent === void 0) { hasParent = false; }
if (parentPath === void 0) { parentPath = ""; }
if (showConstraintMessages === void 0) { showConstraintMessages = false; }
var boldStart = shouldDecorate ? "\u001B[1m" : "";
var boldEnd = shouldDecorate ? "\u001B[22m" : "";
var constraintsToString = function () { var _a; return (showConstraintMessages ? Object.values : Object.keys)((_a = _this.constraints) !== null && _a !== void 0 ? _a : {}).join(", "); };
var propConstraintFailed = function (propertyName) {
return " - property ".concat(boldStart).concat(parentPath).concat(propertyName).concat(boldEnd, " has failed the following constraints: ").concat(boldStart).concat(constraintsToString()).concat(boldEnd, " \n");
};
if (!hasParent) {
return ("An instance of ".concat(boldStart).concat(this.target ? this.target.constructor.name : 'an object').concat(boldEnd, " has failed the validation:\n") +
(this.constraints ? propConstraintFailed(this.property) : "") +
(this.children
? this.children
.map(function (childError) { return childError.toString(shouldDecorate, true, _this.property, showConstraintMessages); })
.join("")
: ""));
}
else {
// we format numbers as array indexes for better readability.
var formattedProperty_1 = Number.isInteger(+this.property)
? "[".concat(this.property, "]")
: "".concat(parentPath ? "." : "").concat(this.property);
if (this.constraints) {
return propConstraintFailed(formattedProperty_1);
}
else {
return this.children
? this.children
.map(function (childError) {
return childError.toString(shouldDecorate, true, "".concat(parentPath).concat(formattedProperty_1), showConstraintMessages);
})
.join("")
: "";
}
}
};
return ValidationError;
}());
export { ValidationError };
//# sourceMappingURL=ValidationError.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ValidationError.js","sourceRoot":"","sources":["../../../src/validation/ValidationError.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;IAAA;IA0FA,CAAC;IAnDC;;;;;;OAMG;IACH,kCAAQ,GAAR,UACE,cAA+B,EAC/B,SAA0B,EAC1B,UAAuB,EACvB,sBAAuC;QAJzC,iBA2CC;QA1CC,+BAAA,EAAA,sBAA+B;QAC/B,0BAAA,EAAA,iBAA0B;QAC1B,2BAAA,EAAA,eAAuB;QACvB,uCAAA,EAAA,8BAAuC;QAEvC,IAAM,SAAS,GAAG,cAAc,CAAC,CAAC,CAAC,WAAS,CAAC,CAAC,CAAC,EAAE,CAAC;QAClD,IAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,YAAU,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,IAAM,mBAAmB,GAAG,sBAC1B,OAAA,CAAC,sBAAsB,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAA,KAAI,CAAC,WAAW,mCAAI,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA,EAAA,CAAC;QAC5F,IAAM,oBAAoB,GAAG,UA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;yBACV,GAAG,CAAC,UAAA,UAAU;wBACb,OAAA,UAAU,CAAC,QAAQ,CAAC,cAAc,EAAE,IAAI,EAAE,UAAG,UAAU,SAAG,mBAAiB,CAAE,EAAE,sBAAsB,CAAC;oBAAtG,CAAsG,CACvG;yBACA,IAAI,CAAC,EAAE,CAAC;oBACb,CAAC,CAAC,EAAE,CAAC;YACT,CAAC;QACH,CAAC;IACH,CAAC;IACH,sBAAC;AAAD,CAAC,AA1FD,IA0FC","sourcesContent":["/**\n * Validation error description.\n */\nexport class ValidationError {\n /**\n * Object that was validated.\n *\n * OPTIONAL - configurable via the ValidatorOptions.validationError.target option\n */\n target?: object;\n\n /**\n * Object's property that haven't pass validation.\n */\n property: string;\n\n /**\n * Value that haven't pass a validation.\n *\n * OPTIONAL - configurable via the ValidatorOptions.validationError.value option\n */\n value?: any;\n\n /**\n * Constraints that failed validation with error messages.\n */\n constraints?: {\n [type: string]: string;\n };\n\n /**\n * Contains all nested validation errors of the property.\n */\n children?: ValidationError[];\n\n /*\n * A transient set of data passed through to the validation result for response mapping\n */\n contexts?: {\n [type: string]: any;\n };\n\n /**\n *\n * @param shouldDecorate decorate the message with ANSI formatter escape codes for better readability\n * @param hasParent true when the error is a child of an another one\n * @param parentPath path as string to the parent of this property\n * @param showConstraintMessages show constraint messages instead of constraint names\n */\n toString(\n shouldDecorate: boolean = false,\n hasParent: boolean = false,\n parentPath: string = ``,\n showConstraintMessages: boolean = false\n ): string {\n const boldStart = shouldDecorate ? `\\x1b[1m` : ``;\n const boldEnd = shouldDecorate ? `\\x1b[22m` : ``;\n const constraintsToString = () =>\n (showConstraintMessages ? Object.values : Object.keys)(this.constraints ?? {}).join(`, `);\n const propConstraintFailed = (propertyName: string): string =>\n ` - property ${boldStart}${parentPath}${propertyName}${boldEnd} has failed the following constraints: ${boldStart}${constraintsToString()}${boldEnd} \\n`;\n\n if (!hasParent) {\n return (\n `An instance of ${boldStart}${\n this.target ? this.target.constructor.name : 'an object'\n }${boldEnd} has failed the validation:\\n` +\n (this.constraints ? propConstraintFailed(this.property) : ``) +\n (this.children\n ? this.children\n .map(childError => childError.toString(shouldDecorate, true, this.property, showConstraintMessages))\n .join(``)\n : ``)\n );\n } else {\n // we format numbers as array indexes for better readability.\n const formattedProperty = Number.isInteger(+this.property)\n ? `[${this.property}]`\n : `${parentPath ? `.` : ``}${this.property}`;\n\n if (this.constraints) {\n return propConstraintFailed(formattedProperty);\n } else {\n return this.children\n ? this.children\n .map(childError =>\n childError.toString(shouldDecorate, true, `${parentPath}${formattedProperty}`, showConstraintMessages)\n )\n Line truncated
@@ -0,0 +1,351 @@
var __read = (this && this.__read) || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
};
import { ValidationError } from './ValidationError';
import { ValidationTypes } from './ValidationTypes';
import { ValidationUtils } from './ValidationUtils';
import { isPromise, convertToArray } from '../utils';
import { getMetadataStorage } from '../metadata/MetadataStorage';
/**
* Executes validation over given object.
*/
var ValidationExecutor = /** @class */ (function () {
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
function ValidationExecutor(validator, validatorOptions) {
this.validator = validator;
this.validatorOptions = validatorOptions;
// -------------------------------------------------------------------------
// Properties
// -------------------------------------------------------------------------
this.awaitingPromises = [];
this.ignoreAsyncValidations = false;
// -------------------------------------------------------------------------
// Private Properties
// -------------------------------------------------------------------------
this.metadataStorage = getMetadataStorage();
}
// -------------------------------------------------------------------------
// Public Methods
// -------------------------------------------------------------------------
ValidationExecutor.prototype.execute = function (object, targetSchema, validationErrors) {
var _this = this;
var _a, _b;
/**
* If there is no metadata registered it means possibly the dependencies are not flatterned and
* more than one instance is used.
*
* TODO: This needs proper handling, forcing to use the same container or some other proper solution.
*/
if (!this.metadataStorage.hasValidationMetaData && ((_a = this.validatorOptions) === null || _a === void 0 ? void 0 : _a.enableDebugMessages) === true) {
console.warn("No validation metadata found. No validation will be performed. There are multiple possible reasons:\n" +
" - There may be multiple class-validator versions installed. You will need to flatten your dependencies to fix the issue.\n" +
" - This validation runs before any file with validation decorator was parsed by NodeJS.");
}
var groups = this.validatorOptions ? this.validatorOptions.groups : undefined;
var strictGroups = (this.validatorOptions && this.validatorOptions.strictGroups) || false;
var always = (this.validatorOptions && this.validatorOptions.always) || false;
/** Forbid unknown values are turned on by default and any other value than false will enable it. */
var forbidUnknownValues = ((_b = this.validatorOptions) === null || _b === void 0 ? void 0 : _b.forbidUnknownValues) === undefined || this.validatorOptions.forbidUnknownValues !== false;
var targetMetadatas = this.metadataStorage.getTargetValidationMetadatas(object.constructor, targetSchema, always, strictGroups, groups);
var groupedMetadatas = this.metadataStorage.groupByPropertyName(targetMetadatas);
if (forbidUnknownValues && !targetMetadatas.length) {
var validationError = new ValidationError();
if (!this.validatorOptions ||
!this.validatorOptions.validationError ||
this.validatorOptions.validationError.target === undefined ||
this.validatorOptions.validationError.target === true)
validationError.target = object;
validationError.value = undefined;
validationError.property = undefined;
validationError.children = [];
validationError.constraints = { unknownValue: 'an unknown value was passed to the validate function' };
validationErrors.push(validationError);
return;
}
if (this.validatorOptions && this.validatorOptions.whitelist)
this.whitelist(object, groupedMetadatas, validationErrors);
// General validation
Object.keys(groupedMetadatas).forEach(function (propertyName) {
var value = object[propertyName];
var definedMetadatas = groupedMetadatas[propertyName].filter(function (metadata) { return metadata.type === ValidationTypes.IS_DEFINED; });
var metadatas = groupedMetadatas[propertyName].filter(function (metadata) { return metadata.type !== ValidationTypes.IS_DEFINED && metadata.type !== ValidationTypes.WHITELIST; });
if (value instanceof Promise &&
metadatas.find(function (metadata) { return metadata.type === ValidationTypes.PROMISE_VALIDATION; })) {
_this.awaitingPromises.push(value.then(function (resolvedValue) {
_this.performValidations(object, resolvedValue, propertyName, definedMetadatas, metadatas, validationErrors);
}));
}
else {
_this.performValidations(object, value, propertyName, definedMetadatas, metadatas, validationErrors);
}
});
};
ValidationExecutor.prototype.whitelist = function (object, groupedMetadatas, validationErrors) {
var _this = this;
var notAllowedProperties = [];
Object.keys(object).forEach(function (propertyName) {
// does this property have no metadata?
if (!groupedMetadatas[propertyName] || groupedMetadatas[propertyName].length === 0)
notAllowedProperties.push(propertyName);
});
if (notAllowedProperties.length > 0) {
if (this.validatorOptions && this.validatorOptions.forbidNonWhitelisted) {
// throw errors
notAllowedProperties.forEach(function (property) {
var _a;
var validationError = _this.generateValidationError(object, object[property], property);
validationError.constraints = (_a = {}, _a[ValidationTypes.WHITELIST] = "property ".concat(property, " should not exist"), _a);
validationError.children = undefined;
validationErrors.push(validationError);
});
}
else {
// strip non allowed properties
notAllowedProperties.forEach(function (property) { return delete object[property]; });
}
}
};
ValidationExecutor.prototype.stripEmptyErrors = function (errors) {
var _this = this;
return errors.filter(function (error) {
if (error.children) {
error.children = _this.stripEmptyErrors(error.children);
}
if (Object.keys(error.constraints).length === 0) {
if (error.children.length === 0) {
return false;
}
else {
delete error.constraints;
}
}
return true;
});
};
// -------------------------------------------------------------------------
// Private Methods
// -------------------------------------------------------------------------
ValidationExecutor.prototype.performValidations = function (object, value, propertyName, definedMetadatas, metadatas, validationErrors) {
var customValidationMetadatas = metadatas.filter(function (metadata) { return metadata.type === ValidationTypes.CUSTOM_VALIDATION; });
var nestedValidationMetadatas = metadatas.filter(function (metadata) { return metadata.type === ValidationTypes.NESTED_VALIDATION; });
var conditionalValidationMetadatas = metadatas.filter(function (metadata) { return metadata.type === ValidationTypes.CONDITIONAL_VALIDATION; });
var validationError = this.generateValidationError(object, value, propertyName);
validationErrors.push(validationError);
var canValidate = this.conditionalValidations(object, value, conditionalValidationMetadatas);
if (!canValidate) {
return;
}
// handle IS_DEFINED validation type the special way - it should work no matter skipUndefinedProperties/skipMissingProperties is set or not
this.customValidations(object, value, definedMetadatas, validationError);
this.mapContexts(object, value, definedMetadatas, validationError);
if (value === undefined && this.validatorOptions && this.validatorOptions.skipUndefinedProperties === true) {
return;
}
if (value === null && this.validatorOptions && this.validatorOptions.skipNullProperties === true) {
return;
}
if ((value === null || value === undefined) &&
this.validatorOptions &&
this.validatorOptions.skipMissingProperties === true) {
return;
}
this.customValidations(object, value, customValidationMetadatas, validationError);
this.nestedValidations(value, nestedValidationMetadatas, validationError);
this.mapContexts(object, value, metadatas, validationError);
this.mapContexts(object, value, customValidationMetadatas, validationError);
};
ValidationExecutor.prototype.generateValidationError = function (object, value, propertyName) {
var validationError = new ValidationError();
if (!this.validatorOptions ||
!this.validatorOptions.validationError ||
this.validatorOptions.validationError.target === undefined ||
this.validatorOptions.validationError.target === true)
validationError.target = object;
if (!this.validatorOptions ||
!this.validatorOptions.validationError ||
this.validatorOptions.validationError.value === undefined ||
this.validatorOptions.validationError.value === true)
validationError.value = value;
validationError.property = propertyName;
validationError.children = [];
validationError.constraints = {};
return validationError;
};
ValidationExecutor.prototype.conditionalValidations = function (object, value, metadatas) {
return metadatas
.map(function (metadata) { return metadata.constraints[0](object, value); })
.reduce(function (resultA, resultB) { return resultA && resultB; }, true);
};
ValidationExecutor.prototype.customValidations = function (object, value, metadatas, error) {
var _this = this;
metadatas.forEach(function (metadata) {
_this.metadataStorage.getTargetValidatorConstraints(metadata.constraintCls).forEach(function (customConstraintMetadata) {
if (customConstraintMetadata.async && _this.ignoreAsyncValidations)
return;
if (_this.validatorOptions &&
_this.validatorOptions.stopAtFirstError &&
Object.keys(error.constraints || {}).length > 0)
return;
var validationArguments = {
targetName: object.constructor ? object.constructor.name : undefined,
property: metadata.propertyName,
object: object,
value: value,
constraints: metadata.constraints,
};
if (!metadata.each || !(Array.isArray(value) || value instanceof Set || value instanceof Map)) {
var validatedValue = customConstraintMetadata.instance.validate(value, validationArguments);
if (isPromise(validatedValue)) {
var promise = validatedValue.then(function (isValid) {
if (!isValid) {
var _a = __read(_this.createValidationError(object, value, metadata, customConstraintMetadata), 2), type = _a[0], message = _a[1];
error.constraints[type] = message;
if (metadata.context) {
if (!error.contexts) {
error.contexts = {};
}
error.contexts[type] = Object.assign(error.contexts[type] || {}, metadata.context);
}
}
});
_this.awaitingPromises.push(promise);
}
else {
if (!validatedValue) {
var _a = __read(_this.createValidationError(object, value, metadata, customConstraintMetadata), 2), type = _a[0], message = _a[1];
error.constraints[type] = message;
}
}
return;
}
// convert set and map into array
var arrayValue = convertToArray(value);
// Validation needs to be applied to each array item
var validatedSubValues = arrayValue.map(function (subValue) {
return customConstraintMetadata.instance.validate(subValue, validationArguments);
});
var validationIsAsync = validatedSubValues.some(function (validatedSubValue) {
return isPromise(validatedSubValue);
});
if (validationIsAsync) {
// Wrap plain values (if any) in promises, so that all are async
var asyncValidatedSubValues = validatedSubValues.map(function (validatedSubValue) {
return isPromise(validatedSubValue) ? validatedSubValue : Promise.resolve(validatedSubValue);
});
var asyncValidationIsFinishedPromise = Promise.all(asyncValidatedSubValues).then(function (flatValidatedValues) {
var validationResult = flatValidatedValues.every(function (isValid) { return isValid; });
if (!validationResult) {
var _a = __read(_this.createValidationError(object, value, metadata, customConstraintMetadata), 2), type = _a[0], message = _a[1];
error.constraints[type] = message;
if (metadata.context) {
if (!error.contexts) {
error.contexts = {};
}
error.contexts[type] = Object.assign(error.contexts[type] || {}, metadata.context);
}
}
});
_this.awaitingPromises.push(asyncValidationIsFinishedPromise);
return;
}
var validationResult = validatedSubValues.every(function (isValid) { return isValid; });
if (!validationResult) {
var _b = __read(_this.createValidationError(object, value, metadata, customConstraintMetadata), 2), type = _b[0], message = _b[1];
error.constraints[type] = message;
}
});
});
};
ValidationExecutor.prototype.nestedValidations = function (value, metadatas, error) {
var _this = this;
if (value === void 0) {
return;
}
metadatas.forEach(function (metadata) {
if (metadata.type !== ValidationTypes.NESTED_VALIDATION && metadata.type !== ValidationTypes.PROMISE_VALIDATION) {
return;
}
else if (_this.validatorOptions &&
_this.validatorOptions.stopAtFirstError &&
Object.keys(error.constraints || {}).length > 0) {
return;
}
if (Array.isArray(value) || value instanceof Set || value instanceof Map) {
// Treats Set as an array - as index of Set value is value itself and it is common case to have Object as value
var arrayLikeValue = value instanceof Set ? Array.from(value) : value;
arrayLikeValue.forEach(function (subValue, index) {
_this.performValidations(value, subValue, index.toString(), [], metadatas, error.children);
});
}
else if (value instanceof Object) {
var targetSchema = typeof metadata.target === 'string' ? metadata.target : metadata.target.name;
_this.execute(value, targetSchema, error.children);
}
else {
var _a = __read(_this.createValidationError(metadata.target, value, metadata), 2), type = _a[0], message = _a[1];
error.constraints[type] = message;
}
});
};
ValidationExecutor.prototype.mapContexts = function (object, value, metadatas, error) {
var _this = this;
return metadatas.forEach(function (metadata) {
if (metadata.context) {
var customConstraint = void 0;
if (metadata.type === ValidationTypes.CUSTOM_VALIDATION) {
var customConstraints = _this.metadataStorage.getTargetValidatorConstraints(metadata.constraintCls);
customConstraint = customConstraints[0];
}
var type = _this.getConstraintType(metadata, customConstraint);
if (error.constraints[type]) {
if (!error.contexts) {
error.contexts = {};
}
error.contexts[type] = Object.assign(error.contexts[type] || {}, metadata.context);
}
}
});
};
ValidationExecutor.prototype.createValidationError = function (object, value, metadata, customValidatorMetadata) {
var targetName = object.constructor ? object.constructor.name : undefined;
var type = this.getConstraintType(metadata, customValidatorMetadata);
var validationArguments = {
targetName: targetName,
property: metadata.propertyName,
object: object,
value: value,
constraints: metadata.constraints,
};
var message = metadata.message || '';
if (!metadata.message &&
(!this.validatorOptions || (this.validatorOptions && !this.validatorOptions.dismissDefaultMessages))) {
if (customValidatorMetadata && customValidatorMetadata.instance.defaultMessage instanceof Function) {
message = customValidatorMetadata.instance.defaultMessage(validationArguments);
}
}
var messageString = ValidationUtils.replaceMessageSpecialTokens(message, validationArguments);
return [type, messageString];
};
ValidationExecutor.prototype.getConstraintType = function (metadata, customValidatorMetadata) {
var type = customValidatorMetadata && customValidatorMetadata.name ? customValidatorMetadata.name : metadata.type;
return type;
};
return ValidationExecutor;
}());
export { ValidationExecutor };
//# sourceMappingURL=ValidationExecutor.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ValidationExecutor.js","sourceRoot":"","sources":["../../../src/validation/ValidationExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEjE;;GAEG;AACH;IAcE,4EAA4E;IAC5E,cAAc;IACd,4EAA4E;IAE5E,4BAAoB,SAAoB,EAAU,gBAAmC;QAAjE,cAAS,GAAT,SAAS,CAAW;QAAU,qBAAgB,GAAhB,gBAAgB,CAAmB;QAjBrF,4EAA4E;QAC5E,aAAa;QACb,4EAA4E;QAE5E,qBAAgB,GAAmB,EAAE,CAAC;QACtC,2BAAsB,GAAY,KAAK,CAAC;QAExC,4EAA4E;QAC5E,qBAAqB;QACrB,4EAA4E;QAEpE,oBAAe,GAAG,kBAAkB,EAAE,CAAC;IAMyC,CAAC;IAEzF,4EAA4E;IAC5E,iBAAiB;IACjB,4EAA4E;IAE5E,oCAAO,GAAP,UAAQ,MAAc,EAAE,YAAoB,EAAE,gBAAmC;QAAjF,iBA8EC;;QA7EC;;;;;WAKG;QACH,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,qBAAqB,IAAI,CAAA,MAAA,IAAI,CAAC,gBAAgB,0CAAE,mBAAmB,MAAK,IAAI,EAAE,CAAC;YACvG,OAAO,CAAC,IAAI,CACV,wGAAwG;gBACtG,8HAA8H;gBAC9H,0FAA0F,CAC7F,CAAC;QACJ,CAAC;QAED,IAAM,MAAM,GAAG,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAg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BC;QAfC,OAAO,MAAM,CAAC,MAAM,CAAC,UAAA,KAAK;YACxB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;gBACnB,KAAK,CAAC,QAAQ,GAAG,KAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;YACzD,CAAC;YAED,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAChD,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAChC,OAAO,KAAK,CAAC;gBACf,CAAC;qBAAM,CAAC;oBACN,OAAO,KAAK,CAAC,WAAW,CAAC;gBAC3B,CAAC;YACH,CAAC;YAED,OAAO,IAAI,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC;IAED,4EAA4E;IAC5E,kBAAkB;IAClB,4EAA4E;IAEpE,+CAAkB,GAA1B,UACE,MAAW,EACX,KAAU,EACV,YAAoB,EACpB,gBAAsC,EACtC,SAA+B,EAC/B,gBAAmC;QAEnC,IAAM,yBAAyB,GAAG,SAAS,CAAC,MAAM,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,IAAI,KAAK,eAAe,CAAC,iBAAiB,EAAnD,CAAmD,CAAC,CAAC;QACpH,IAAM,yBAAyB,GAAG,SAAS,CAAC,MAAM,CAAC,UAAA,QAAQ,IAAI,OAAA,QAAQ,CAAC,IAAI,KAAK,eAAe,CAAC,iBAAiB,EAAnD,CAAmD,CALine truncated
@@ -0,0 +1,28 @@
/**
* Validation types.
*/
var ValidationTypes = /** @class */ (function () {
function ValidationTypes() {
}
/**
* Checks if validation type is valid.
*/
ValidationTypes.isValid = function (type) {
var _this = this;
return (type !== 'isValid' &&
type !== 'getMessage' &&
Object.keys(this)
.map(function (key) { return _this[key]; })
.indexOf(type) !== -1);
};
/* system */
ValidationTypes.CUSTOM_VALIDATION = 'customValidation'; // done
ValidationTypes.NESTED_VALIDATION = 'nestedValidation'; // done
ValidationTypes.PROMISE_VALIDATION = 'promiseValidation'; // done
ValidationTypes.CONDITIONAL_VALIDATION = 'conditionalValidation'; // done
ValidationTypes.WHITELIST = 'whitelistValidation'; // done
ValidationTypes.IS_DEFINED = 'isDefined'; // done
return ValidationTypes;
}());
export { ValidationTypes };
//# sourceMappingURL=ValidationTypes.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ValidationTypes.js","sourceRoot":"","sources":["../../../src/validation/ValidationTypes.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH;IAAA;IAqBA,CAAC;IAZC;;OAEG;IACI,uBAAO,GAAd,UAAe,IAAY;QAA3B,iBAQC;QAPC,OAAO,CACL,IAAI,KAAK,SAAS;YAClB,IAAI,KAAK,YAAY;YACrB,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC;iBACd,GAAG,CAAC,UAAA,GAAG,IAAI,OAAC,KAAY,CAAC,GAAG,CAAC,EAAlB,CAAkB,CAAC;iBAC9B,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CACxB,CAAC;IACJ,CAAC;IAnBD,YAAY;IACL,iCAAiB,GAAG,kBAAkB,CAAC,CAAC,OAAO;IAC/C,iCAAiB,GAAG,kBAAkB,CAAC,CAAC,OAAO;IAC/C,kCAAkB,GAAG,mBAAmB,CAAC,CAAC,OAAO;IACjD,sCAAsB,GAAG,uBAAuB,CAAC,CAAC,OAAO;IACzD,yBAAS,GAAG,qBAAqB,CAAC,CAAC,OAAO;IAC1C,0BAAU,GAAG,WAAW,CAAC,CAAC,OAAO;IAc1C,sBAAC;CAAA,AArBD,IAqBC;SArBY,eAAe","sourcesContent":["/**\n * Validation types.\n */\nexport class ValidationTypes {\n /* system */\n static CUSTOM_VALIDATION = 'customValidation'; // done\n static NESTED_VALIDATION = 'nestedValidation'; // done\n static PROMISE_VALIDATION = 'promiseValidation'; // done\n static CONDITIONAL_VALIDATION = 'conditionalValidation'; // done\n static WHITELIST = 'whitelistValidation'; // done\n static IS_DEFINED = 'isDefined'; // done\n\n /**\n * Checks if validation type is valid.\n */\n static isValid(type: string): boolean {\n return (\n type !== 'isValid' &&\n type !== 'getMessage' &&\n Object.keys(this)\n .map(key => (this as any)[key])\n .indexOf(type) !== -1\n );\n }\n}\n"]}
@@ -0,0 +1,43 @@
/**
* Convert the constraint to a string to be shown in an error
*/
export function constraintToString(constraint) {
if (Array.isArray(constraint)) {
return constraint.join(', ');
}
if (typeof constraint === 'symbol') {
constraint = constraint.description;
}
return "".concat(constraint);
}
var ValidationUtils = /** @class */ (function () {
function ValidationUtils() {
}
ValidationUtils.replaceMessageSpecialTokens = function (message, validationArguments) {
var messageString;
if (message instanceof Function) {
messageString = message(validationArguments);
}
else if (typeof message === 'string') {
messageString = message;
}
if (messageString && Array.isArray(validationArguments.constraints)) {
validationArguments.constraints.forEach(function (constraint, index) {
messageString = messageString.replace(new RegExp("\\$constraint".concat(index + 1), 'g'), constraintToString(constraint));
});
}
if (messageString &&
validationArguments.value !== undefined &&
validationArguments.value !== null &&
['string', 'boolean', 'number'].includes(typeof validationArguments.value))
messageString = messageString.replace(/\$value/g, validationArguments.value);
if (messageString)
messageString = messageString.replace(/\$property/g, validationArguments.property);
if (messageString)
messageString = messageString.replace(/\$target/g, validationArguments.targetName);
return messageString;
};
return ValidationUtils;
}());
export { ValidationUtils };
//# sourceMappingURL=ValidationUtils.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ValidationUtils.js","sourceRoot":"","sources":["../../../src/validation/ValidationUtils.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAmB;IACpD,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE,CAAC;QACnC,UAAU,GAAG,UAAU,CAAC,WAAW,CA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ACvB,CAAC;IACH,sBAAC;AAAD,CAAC,AAjCD,IAiCC","sourcesContent":["import { ValidationArguments } from './ValidationArguments';\n\n/**\n * Convert the constraint to a string to be shown in an error\n */\nexport function constraintToString(constraint: unknown): string {\n if (Array.isArray(constraint)) {\n return constraint.join(', ');\n }\n\n if (typeof constraint === 'symbol') {\n constraint = constraint.description;\n }\n\n return `${constraint}`;\n}\n\nexport class ValidationUtils {\n static replaceMessageSpecialTokens(\n message: string | ((args: ValidationArguments) => string),\n validationArguments: ValidationArguments\n ): string {\n let messageString: string;\n if (message instanceof Function) {\n messageString = (message as (args: ValidationArguments) => string)(validationArguments);\n } else if (typeof message === 'string') {\n messageString = message;\n }\n\n if (messageString && Array.isArray(validationArguments.constraints)) {\n validationArguments.constraints.forEach((constraint, index) => {\n messageString = messageString.replace(\n new RegExp(`\\\\$constraint${index + 1}`, 'g'),\n constraintToString(constraint)\n );\n });\n }\n\n if (\n messageString &&\n validationArguments.value !== undefined &&\n validationArguments.value !== null &&\n ['string', 'boolean', 'number'].includes(typeof validationArguments.value)\n )\n messageString = messageString.replace(/\\$value/g, validationArguments.value);\n if (messageString) messageString = messageString.replace(/\\$property/g, validationArguments.property);\n if (messageString) messageString = messageString.replace(/\\$target/g, validationArguments.targetName);\n\n return messageString;\n }\n}\n"]}
@@ -0,0 +1,102 @@
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
import { ValidationExecutor } from './ValidationExecutor';
/**
* Validator performs validation of the given object based on its metadata.
*/
var Validator = /** @class */ (function () {
function Validator() {
}
/**
* Performs validation of the given object based on decorators or validation schema.
*/
Validator.prototype.validate = function (objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
return this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions);
};
/**
* Performs validation of the given object based on decorators or validation schema and reject on error.
*/
Validator.prototype.validateOrReject = function (objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
return __awaiter(this, void 0, void 0, function () {
var errors;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions)];
case 1:
errors = _a.sent();
if (errors.length)
return [2 /*return*/, Promise.reject(errors)];
return [2 /*return*/];
}
});
});
};
/**
* Performs validation of the given object based on decorators or validation schema.
*/
Validator.prototype.validateSync = function (objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
var object = typeof objectOrSchemaName === 'string' ? objectOrValidationOptions : objectOrSchemaName;
var options = typeof objectOrSchemaName === 'string' ? maybeValidatorOptions : objectOrValidationOptions;
var schema = typeof objectOrSchemaName === 'string' ? objectOrSchemaName : undefined;
var executor = new ValidationExecutor(this, options);
executor.ignoreAsyncValidations = true;
var validationErrors = [];
executor.execute(object, schema, validationErrors);
return executor.stripEmptyErrors(validationErrors);
};
// -------------------------------------------------------------------------
// Private Properties
// -------------------------------------------------------------------------
/**
* Performs validation of the given object based on decorators or validation schema.
* Common method for `validateOrReject` and `validate` methods.
*/
Validator.prototype.coreValidate = function (objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions) {
var object = typeof objectOrSchemaName === 'string' ? objectOrValidationOptions : objectOrSchemaName;
var options = typeof objectOrSchemaName === 'string' ? maybeValidatorOptions : objectOrValidationOptions;
var schema = typeof objectOrSchemaName === 'string' ? objectOrSchemaName : undefined;
var executor = new ValidationExecutor(this, options);
var validationErrors = [];
executor.execute(object, schema, validationErrors);
return Promise.all(executor.awaitingPromises).then(function () {
return executor.stripEmptyErrors(validationErrors);
});
};
return Validator;
}());
export { Validator };
//# sourceMappingURL=Validator.js.map
@@ -0,0 +1 @@
{"version":3,"file":"Validator.js","sourceRoot":"","sources":["../../../src/validation/Validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D;;GAEG;AACH;IAAA;IAwGA,CAAC;IAzFC;;OAEG;IACH,4BAAQ,GAAR,UACE,kBAAmC,EACnC,yBAAqD,EACrD,q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AwC;QAExC,IAAM,MAAM,GAAG,OAAO,kBAAkB,KAAK,QAAQ,CAAC,CAAC,CAAE,yBAAoC,CAAC,CAAC,CAAC,kBAAkB,CAAC;QACnH,IAAM,OAAO,GACX,OAAO,kBAAkB,KAAK,QAAQ,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAE,yBAA+C,CAAC;QACpH,IAAM,MAAM,GAAG,OAAO,kBAAkB,KAAK,QAAQ,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC;QAEvF,IAAM,QAAQ,GAAG,IAAI,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACvD,IAAM,gBAAgB,GAAsB,EAAE,CAAC;QAC/C,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,CAAC,CAAC;QAEnD,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,IAAI,CAAC;YACjD,OAAO,QAAQ,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACL,CAAC;IACH,gBAAC;AAAD,CAAC,AAxGD,IAwGC","sourcesContent":["import { ValidationError } from './ValidationError';\nimport { ValidatorOptions } from './ValidatorOptions';\nimport { ValidationExecutor } from './ValidationExecutor';\nimport { ValidationOptions } from '../decorator/ValidationOptions';\n\n/**\n * Validator performs validation of the given object based on its metadata.\n */\nexport class Validator {\n // -------------------------------------------------------------------------\n // Public Methods\n // -------------------------------------------------------------------------\n\n /**\n * Performs validation of the given object based on decorators used in given object class.\n */\n validate(object: object, options?: ValidatorOptions): Promise<ValidationError[]>;\n\n /**\n * Performs validation of the given object based on validation schema.\n */\n validate(schemaName: string, object: object, options?: ValidatorOptions): Promise<ValidationError[]>;\n\n /**\n * Performs validation of the given object based on decorators or validation schema.\n */\n validate(\n objectOrSchemaName: object | string,\n objectOrValidationOptions: object | ValidationOptions,\n maybeValidatorOptions?: ValidatorOptions\n ): Promise<ValidationError[]> {\n return this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions);\n }\n\n /**\n * Performs validation of the given object based on decorators used in given object class and reject on error.\n */\n validateOrReject(object: object, options?: ValidatorOptions): Promise<void>;\n\n /**\n * Performs validation of the given object based on validation schema and reject on error.\n */\n validateOrReject(schemaName: string, object: object, options?: ValidatorOptions): Promise<void>;\n\n /**\n * Performs validation of the given object based on decorators or validation schema and reject on error.\n */\n async validateOrReject(\n objectOrSchemaName: object | string,\n objectOrValidationOptions: object | ValidationOptions,\n maybeValidatorOptions?: ValidatorOptions\n ): Promise<void> {\n const errors = await this.coreValidate(objectOrSchemaName, objectOrValidationOptions, maybeValidatorOptions);\n if (errors.length) return Promise.reject(errors);\n }\n\n /**\n * Performs validation of the given object based on decorators used in given object class.\n * NOTE: This method completely ignores all async validations.\n */\n validateSync(object: object, options?: ValidatorOptions): ValidationError[];\n\n /**\n * Performs validation of the given object based on validation schema.\n */\n validateSync(schemaName: string, object: object, options?: ValidatorOptions): ValidationError[];\n\n /**\n * Performs validation of the given object based on decorators or validation schema.\n */\n validateSync(\n objectOrSchemaName: object | string,\n objectOrValidationOptions: object | ValidationOptions,\n maybeValidatorOptions?: ValidatorOptions\n ): ValidationError[] {\n const object = typeof objecLine truncated
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=ValidatorConstraintInterface.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ValidatorConstraintInterface.js","sourceRoot":"","sources":["../../../src/validation/ValidatorConstraintInterface.ts"],"names":[],"mappings":"","sourcesContent":["import { ValidationArguments } from './ValidationArguments';\n/**\n * Custom validators must implement this interface to provide custom validation logic.\n */\nexport interface ValidatorConstraintInterface {\n /**\n * Method to be called to perform custom validation over given value.\n */\n validate(value: any, validationArguments?: ValidationArguments): Promise<boolean> | boolean;\n\n /**\n * Gets default message when validation for this constraint fail.\n */\n defaultMessage?(validationArguments?: ValidationArguments): string;\n}\n"]}
@@ -0,0 +1,2 @@
export {};
//# sourceMappingURL=ValidatorOptions.js.map
@@ -0,0 +1 @@
{"version":3,"file":"ValidatorOptions.js","sourceRoot":"","sources":["../../../src/validation/ValidatorOptions.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Options passed to validator during validation.\n */\nexport interface ValidatorOptions {\n /**\n * If set to true then class-validator will print extra warning messages to the console when something is not right.\n */\n enableDebugMessages?: boolean;\n\n /**\n * If set to true then validator will skip validation of all properties that are undefined in the validating object.\n */\n skipUndefinedProperties?: boolean;\n\n /**\n * If set to true then validator will skip validation of all properties that are null in the validating object.\n */\n skipNullProperties?: boolean;\n\n /**\n * If set to true then validator will skip validation of all properties that are null or undefined in the validating object.\n */\n skipMissingProperties?: boolean;\n\n /**\n * If set to true validator will strip validated object of any properties that do not have any decorators.\n *\n * Tip: if no other decorator is suitable for your property use @Allow decorator.\n */\n whitelist?: boolean;\n\n /**\n * If set to true, instead of stripping non-whitelisted properties validator will throw an error\n */\n forbidNonWhitelisted?: boolean;\n\n /**\n * Groups to be used during validation of the object.\n */\n groups?: string[];\n\n /**\n * Set default for `always` option of decorators. Default can be overridden in decorator options.\n */\n always?: boolean;\n\n /**\n * If [groups]{@link ValidatorOptions#groups} is not given or is empty,\n * ignore decorators with at least one group.\n */\n strictGroups?: boolean;\n\n /**\n * If set to true, the validation will not use default messages.\n * Error message always will be undefined if its not explicitly set.\n */\n dismissDefaultMessages?: boolean;\n\n /**\n * ValidationError special options.\n */\n validationError?: {\n /**\n * Indicates if target should be exposed in ValidationError.\n */\n target?: boolean;\n\n /**\n * Indicates if validated value should be exposed in ValidationError.\n */\n value?: boolean;\n };\n\n /**\n * Fails validation for objects unknown to class-validator. Defaults to true.\n *\n * For instance, since a plain empty object has no annotations used for validation:\n * - `validate({})` // fails.\n * - `validate({}, { forbidUnknownValues: true })` // fails.\n * - `validate({}, { forbidUnknownValues: false })` // passes.\n * - `validate(new SomeAnnotatedEmptyClass(), { forbidUnknownValues: true })` // passes.\n */\n forbidUnknownValues?: boolean;\n\n /**\n * When set to true, validation of the given property will stop after encountering the first error. Defaults to false.\n */\n stopAtFirstError?: boolean;\n}\n"]}