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.
37 lines • 1.52 kB
JavaScript
import { DirectiveKind, ErrorKeyKind, ERROR_KEYS, } from '../shared/constants_domain_specific';
const defaultOnBeforeEmptyInputValidator = (parser, builder) => {
if (parser.input.textInput.replace(/\s+/, '') === '') {
throw builder.create({
errorType: ErrorKeyKind.EmptyInput,
instructionType: ErrorKeyKind.Unknown,
});
}
};
const defaultOnAfterNoRecordsValidator = (parser, builder) => {
if (Object.keys(parser.zoneObj).filter(x => x !== DirectiveKind.Origin && x !== DirectiveKind.TimeToLive).length === 0) {
throw builder.create({
errorType: ErrorKeyKind.NoRecords,
instructionType: ErrorKeyKind.Unknown,
});
}
};
const defaultLoopValidator = (parser, builder) => {
const errorType = builder.entry.errorType;
if (errorType && ERROR_KEYS.includes(errorType)) {
throw builder.create(builder.entry);
}
};
const wrongLengthValidator = (parser, builder) => {
if (builder.entry.errorType === ErrorKeyKind.WrongLength) {
const { expected, type, actual } = builder.entry
.error;
throw builder.create(builder.entry, { expected, actual, type });
}
};
export const createDefaultValidators = () => ({
loopValidators: [wrongLengthValidator, defaultLoopValidator],
getErrorText: entry => entry.errorType,
preValidators: [defaultOnBeforeEmptyInputValidator],
postValidators: [defaultOnAfterNoRecordsValidator],
});
//# sourceMappingURL=default_validators.js.map