class-validator-extended
Version:
Additional validators for class-validator.
43 lines (42 loc) • 1.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IS_AWS_ARN = void 0;
exports.IsAwsARN = IsAwsARN;
const class_validator_1 = require("class-validator");
const is_aws_arn_predicate_1 = require("./is-aws-arn.predicate");
/** @hidden */
exports.IS_AWS_ARN = 'isAwsArn';
/**
* Checks if the given value is an AWS ARN string (as specified in the [AWS Documentation](https://docs.aws.amazon.com/quicksight/latest/APIReference/qs-arn-format.html)).
*
* Beware that this decorator only checks for syntactic validity, it does not check if the partition, service or region
* really exists. The region and account id are always optional, even if required for the specific service.
*
* For example, the following strings are considered valid if though they are technically not:
* - `arn:aws:foo:eu-central-1:bar`
* (there is no `foo` AWS service)
* - `arn:aws:ec2::123456789012:instance/i-1234567890abcdef0`
* (EC2 requires a region which is omitted)
* - `arn:aws:ec2:us-east-42:123456789012:instance/i-1234567890abcdef0`
* (the region `us-east-42` does not exist)
*
* #### Example
* ```typescript
* // Ensure the value is a valid looking AWS ARN string
* @IsAwsARN()
* arn: string = 'arn:aws:clouddirectory:us-west-2:123456789012:schema/development/cognito'
* ```
*
* @category String
* @deprecated
* @param options Generic class-validator options.
*/
function IsAwsARN(options) {
return (0, class_validator_1.ValidateBy)({
name: exports.IS_AWS_ARN,
validator: {
validate: (value, _arguments) => (0, is_aws_arn_predicate_1.isAwsARN)(value),
defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must be an AWS ARN string`, options),
},
}, options);
}