mirror of
https://gitee.com/bimuziyan/ccc-obfuscated-code.git
synced 2026-05-08 03:55:53 +08:00
69 lines
3.4 KiB
JavaScript
69 lines
3.4 KiB
JavaScript
import * as tslib_1 from "tslib";
|
|
import { ValidationExecutor } from "./ValidationExecutor";
|
|
/**
|
|
* Validator performs validation of the given object based on its metadata.
|
|
*/
|
|
var Validator = /** @class */ (function () {
|
|
function Validator() {
|
|
}
|
|
// -------------------------------------------------------------------------
|
|
// 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);
|
|
});
|
|
};
|
|
/**
|
|
* 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 tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
var errors;
|
|
return tslib_1.__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);
|
|
};
|
|
return Validator;
|
|
}());
|
|
export { Validator };
|
|
|
|
//# sourceMappingURL=Validator.js.map
|