summaryrefslogtreecommitdiff
path: root/src/node_modules/class-validator/esm5/validation/Validator.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/node_modules/class-validator/esm5/validation/Validator.js')
-rw-r--r--src/node_modules/class-validator/esm5/validation/Validator.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/node_modules/class-validator/esm5/validation/Validator.js b/src/node_modules/class-validator/esm5/validation/Validator.js
new file mode 100644
index 0000000..3b430ed
--- /dev/null
+++ b/src/node_modules/class-validator/esm5/validation/Validator.js
@@ -0,0 +1,68 @@
+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