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.

41 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createDefaultValidators = void 0; const constants_domain_specific_1 = require("../shared/constants_domain_specific"); const defaultOnBeforeEmptyInputValidator = (parser, builder) => { if (parser.input.textInput.replace(/\s+/, '') === '') { throw builder.create({ errorType: constants_domain_specific_1.ErrorKeyKind.EmptyInput, instructionType: constants_domain_specific_1.ErrorKeyKind.Unknown, }); } }; const defaultOnAfterNoRecordsValidator = (parser, builder) => { if (Object.keys(parser.zoneObj).filter(x => x !== constants_domain_specific_1.DirectiveKind.Origin && x !== constants_domain_specific_1.DirectiveKind.TimeToLive).length === 0) { throw builder.create({ errorType: constants_domain_specific_1.ErrorKeyKind.NoRecords, instructionType: constants_domain_specific_1.ErrorKeyKind.Unknown, }); } }; const defaultLoopValidator = (parser, builder) => { const errorType = builder.entry.errorType; if (errorType && constants_domain_specific_1.ERROR_KEYS.includes(errorType)) { throw builder.create(builder.entry); } }; const wrongLengthValidator = (parser, builder) => { if (builder.entry.errorType === constants_domain_specific_1.ErrorKeyKind.WrongLength) { const { expected, type, actual } = builder.entry .error; throw builder.create(builder.entry, { expected, actual, type }); } }; const createDefaultValidators = () => ({ loopValidators: [wrongLengthValidator, defaultLoopValidator], getErrorText: entry => entry.errorType, preValidators: [defaultOnBeforeEmptyInputValidator], postValidators: [defaultOnAfterNoRecordsValidator], }); exports.createDefaultValidators = createDefaultValidators; //# sourceMappingURL=default_validators.js.map