15815213711
2024-08-26 67b8b6731811983447e053d4396b3708c14dfe3c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Validate = exports.ValidatorConstraint = void 0;
const ValidationMetadata_1 = require("../../metadata/ValidationMetadata");
const MetadataStorage_1 = require("../../metadata/MetadataStorage");
const ValidationTypes_1 = require("../../validation/ValidationTypes");
const ConstraintMetadata_1 = require("../../metadata/ConstraintMetadata");
/**
 * Registers custom validator class.
 */
function ValidatorConstraint(options) {
    return function (target) {
        const isAsync = options && options.async;
        let name = options && options.name ? options.name : '';
        if (!name) {
            name = target.name;
            if (!name)
                // generate name if it was not given
                name = name.replace(/\.?([A-Z]+)/g, (x, y) => '_' + y.toLowerCase()).replace(/^_/, '');
        }
        const metadata = new ConstraintMetadata_1.ConstraintMetadata(target, name, isAsync);
        (0, MetadataStorage_1.getMetadataStorage)().addConstraintMetadata(metadata);
    };
}
exports.ValidatorConstraint = ValidatorConstraint;
function Validate(constraintClass, constraintsOrValidationOptions, maybeValidationOptions) {
    return function (object, propertyName) {
        const args = {
            type: ValidationTypes_1.ValidationTypes.CUSTOM_VALIDATION,
            target: object.constructor,
            propertyName: propertyName,
            constraintCls: constraintClass,
            constraints: Array.isArray(constraintsOrValidationOptions) ? constraintsOrValidationOptions : undefined,
            validationOptions: !Array.isArray(constraintsOrValidationOptions)
                ? constraintsOrValidationOptions
                : maybeValidationOptions,
        };
        (0, MetadataStorage_1.getMetadataStorage)().addValidationMetadata(new ValidationMetadata_1.ValidationMetadata(args));
    };
}
exports.Validate = Validate;
//# sourceMappingURL=Validate.js.map