node-beanstalk
Version:
The most comprehensive beanstalk client for nodejs
69 lines • 2.73 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateJobId = exports.validateTimeout = exports.validateTTR = exports.validateDelay = exports.validatePriority = exports.validateTubeName = void 0;
var const_1 = require("../const");
var tubeNameValidateRE = /^[A-Za-z0-9\-+/;.$_()]{1,200}$/;
function validateTubeName(name) {
if (typeof name !== 'string') {
throw new TypeError("tube name should be a string, got ".concat(typeof name));
}
if (!tubeNameValidateRE.test(name)) {
throw new TypeError("tube name should satisfy regexp: ".concat(tubeNameValidateRE));
}
}
exports.validateTubeName = validateTubeName;
function validatePriority(priority) {
if (typeof priority !== 'number') {
throw new TypeError("priority should be a number, got ".concat(typeof priority));
}
if (priority < const_1.PRIORITY_MIN) {
throw new TypeError("priority should be >= ".concat(const_1.PRIORITY_MIN));
}
if (priority > const_1.PRIORITY_MAX) {
throw new TypeError("priority should be <= ".concat(const_1.PRIORITY_MAX));
}
}
exports.validatePriority = validatePriority;
function validateDelay(delay) {
if (typeof delay !== 'number') {
throw new TypeError("delay should be a number, got ".concat(typeof delay));
}
if (delay < const_1.DELAY_MIN) {
throw new TypeError("delay should be >= ".concat(const_1.DELAY_MIN));
}
if (delay > const_1.DELAY_MAX) {
throw new TypeError("delay should be <= ".concat(const_1.DELAY_MAX));
}
}
exports.validateDelay = validateDelay;
function validateTTR(ttr) {
if (typeof ttr !== 'number') {
throw new TypeError("ttr should be a number, got ".concat(typeof ttr));
}
if (ttr < const_1.TTR_MIN) {
throw new TypeError("ttr should be >= ".concat(const_1.TTR_MIN));
}
if (ttr > const_1.TTR_MAX) {
throw new TypeError("ttr should be <= ".concat(const_1.TTR_MAX));
}
}
exports.validateTTR = validateTTR;
function validateTimeout(timeout) {
if (typeof timeout !== 'number') {
throw new TypeError("timeout should be a number, got ".concat(typeof timeout));
}
if (timeout < const_1.TIMEOUT_MIN) {
throw new TypeError("timeout should be >= ".concat(const_1.TIMEOUT_MIN));
}
}
exports.validateTimeout = validateTimeout;
function validateJobId(jobId) {
if (typeof jobId !== 'number') {
throw new TypeError("job id should be a number, got ".concat(typeof jobId));
}
if (jobId < const_1.JOB_ID_MIN) {
throw new TypeError("job id should be >= ".concat(const_1.JOB_ID_MIN));
}
}
exports.validateJobId = validateJobId;
//# sourceMappingURL=validator.js.map