redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
58 lines • 2.88 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.QueueOperationValidator = void 0;
const redis_smq_common_1 = require("redis-smq-common");
const index_js_1 = require("./types/index.js");
const with_shared_pool_connection_js_1 = require("../common/redis/redis-connection-pool/with-shared-pool-connection.js");
const _parse_queue_params_js_1 = require("../queue-manager/_/_parse-queue-params.js");
const _check_operation_js_1 = require("./_/_check-operation.js");
class QueueOperationValidator {
static checkOperation(queue, operation, cb) {
return redis_smq_common_1.async.withOptionalCallback(cb, (callback) => {
const queueParams = (0, _parse_queue_params_js_1._parseQueueParams)(queue);
if (queueParams instanceof Error)
return callback(queueParams);
(0, with_shared_pool_connection_js_1.withSharedPoolConnection)((client, cb) => {
(0, _check_operation_js_1._checkOperation)(client, queueParams, operation, (err, result) => cb(err, result === null || result === void 0 ? void 0 : result.allowed));
}, callback);
});
}
static canConsume(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.CONSUME, cb);
}
static canProduce(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.PRODUCE, cb);
}
static canDelete(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.DELETE, cb);
}
static canDeleteMessage(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.DELETE_MESSAGE, cb);
}
static canPurge(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.PURGE, cb);
}
static canRequeue(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.REQUEUE_MESSAGE, cb);
}
static canSetRateLimit(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.SET_RATE_LIMIT, cb);
}
static canClearRateLimit(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.CLEAR_RATE_LIMIT, cb);
}
static canCreateConsumerGroup(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.CREATE_CONSUMER_GROUP, cb);
}
static canDeleteConsumerGroup(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.DELETE_CONSUMER_GROUP, cb);
}
static canBindExchange(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.BIND_EXCHANGE, cb);
}
static canUnbindExchange(queue, cb) {
return this.checkOperation(queue, index_js_1.EQueueOperation.UNBIND_EXCHANGE, cb);
}
}
exports.QueueOperationValidator = QueueOperationValidator;
//# sourceMappingURL=queue-operation-validator.js.map