UNPKG

@ts-fluentvalidation/core

Version:

Core library of @ts-fluentvalidation providing validations in a fluent syntax.

28 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateAsync = validateAsync; const tslib_1 = require("tslib"); const utils_1 = require("./utils"); const validate_key_async_1 = require("./validate-key-async"); /** * Validates the given model asynchronously. * * @param validationContext - The validation context to validate. * @param validations - The validations to apply. * @param validatorConfig - The configuration to apply. */ function validateAsync(validationContext, validations, validatorConfig) { return tslib_1.__awaiter(this, void 0, void 0, function* () { var _a, _b; const includedProperties = validatorConfig.includeProperties ? (0, utils_1.wrapAsArray)(validatorConfig.includeProperties) : undefined; const validationEntries = includedProperties ? validations.filter(({ key }) => includedProperties === null || includedProperties === void 0 ? void 0 : includedProperties.includes(key)) : validations; for (const { key, validations, cascadeMode } of validationEntries) { const keyCascadeMode = (_b = (_a = validatorConfig.propertyCascadeMode) !== null && _a !== void 0 ? _a : cascadeMode) !== null && _b !== void 0 ? _b : 'Continue'; yield (0, validate_key_async_1.validateKeyAsync)(validationContext, key, validations, keyCascadeMode, validatorConfig.throwOnFailures); if (validationContext.failures.length > 0 && validatorConfig.cascadeMode === 'Stop') { break; } } }); } //# sourceMappingURL=validate-async.js.map