UNPKG

amazon-route-53-dns-zone-file

Version:

Makes DNS Zone File easy. Parses and validates BIND zone files and can be extended for custom features. Functionality is modular. Features are made open for extension and closed for runtime mutation. Written in TypeScript.

63 lines 2.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Validator = void 0; const error_builder_1 = require("./error_builder"); const default_validators_1 = require("./default_validators"); /** @mutates */ const mergeOptions = (target, partial) => { const keys = Object.keys(partial); keys.forEach(key => { if (key === 'getErrorText') { target[key] = partial[key]; } else if (Array.isArray(target[key])) { target[key] = [...target[key], ...partial[key]]; } }); }; class Validator { constructor(options = {}) { this.errors = []; this.options = default_validators_1.createDefaultValidators(); this.errorBuilder = new error_builder_1.ErrorBuilder(); this.mergeOptions(options); } mergeOptions(partial) { mergeOptions(this.options, partial); this.errorBuilder.getErrorText = this.options.getErrorText; return this; } validate(parser) { this.options.preValidators.forEach(validator => { try { validator(parser, this.errorBuilder); } catch (beforeError) { this.errors.push(beforeError); } }); for (const [parsingLineNumber, entry] of parser.parsingMeta) { this.errorBuilder.update(parsingLineNumber, entry); this.options.loopValidators.forEach(validator => { try { validator(parser, this.errorBuilder); } catch (loopError) { this.errors.push(loopError); } }); } this.errorBuilder.update(0, {}); this.options.postValidators.forEach(validator => { try { validator(parser, this.errorBuilder); } catch (afterError) { this.errors.push(afterError); } }); return this; } } exports.Validator = Validator; //# sourceMappingURL=validator.js.map