UNPKG

class-validator-extended

Version:
36 lines (35 loc) 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MAP_NOT_CONTAINS_KEYS = void 0; exports.MapNotContainsKeys = MapNotContainsKeys; const class_validator_1 = require("class-validator"); const map_not_contains_keys_predicate_1 = require("./map-not-contains-keys.predicate"); /** @hidden */ exports.MAP_NOT_CONTAINS_KEYS = 'mapNotContainsKeys'; /** * Checks if the given value is a [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) * which does not contain any of the forbidden keys. * * #### Example * ```typescript * // Ensure the map does not contain the keys 13 and 42. * @MapNotContainsKeys([13, 42]) * values: Map<number, string> * ``` * * @category Map * @param forbidden The values forbidden in the given map. * @param options Generic class-validator options. * @typeParam Key The type of keys to check for. */ function MapNotContainsKeys(forbidden, options) { return (0, class_validator_1.ValidateBy)({ name: exports.MAP_NOT_CONTAINS_KEYS, validator: { validate: (value, _arguments) => (0, map_not_contains_keys_predicate_1.mapNotContainsKeys)(value, forbidden), defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must not contain any of the following keys: ${[ ...forbidden, ].join(', ')}`, options), }, }, options); }