UNPKG

class-validator-extended

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