redis-smq
Version:
A high-performance, reliable, and scalable message queue for Node.js.
54 lines • 2.38 kB
JavaScript
import { async } from 'redis-smq-common';
import { EQueueOperation } from './types/index.js';
import { withSharedPoolConnection } from '../common/redis/redis-connection-pool/with-shared-pool-connection.js';
import { _parseQueueParams } from '../queue-manager/_/_parse-queue-params.js';
import { _checkOperation } from './_/_check-operation.js';
export class QueueOperationValidator {
static checkOperation(queue, operation, cb) {
return async.withOptionalCallback(cb, (callback) => {
const queueParams = _parseQueueParams(queue);
if (queueParams instanceof Error)
return callback(queueParams);
withSharedPoolConnection((client, cb) => {
_checkOperation(client, queueParams, operation, (err, result) => cb(err, result?.allowed));
}, callback);
});
}
static canConsume(queue, cb) {
return this.checkOperation(queue, EQueueOperation.CONSUME, cb);
}
static canProduce(queue, cb) {
return this.checkOperation(queue, EQueueOperation.PRODUCE, cb);
}
static canDelete(queue, cb) {
return this.checkOperation(queue, EQueueOperation.DELETE, cb);
}
static canDeleteMessage(queue, cb) {
return this.checkOperation(queue, EQueueOperation.DELETE_MESSAGE, cb);
}
static canPurge(queue, cb) {
return this.checkOperation(queue, EQueueOperation.PURGE, cb);
}
static canRequeue(queue, cb) {
return this.checkOperation(queue, EQueueOperation.REQUEUE_MESSAGE, cb);
}
static canSetRateLimit(queue, cb) {
return this.checkOperation(queue, EQueueOperation.SET_RATE_LIMIT, cb);
}
static canClearRateLimit(queue, cb) {
return this.checkOperation(queue, EQueueOperation.CLEAR_RATE_LIMIT, cb);
}
static canCreateConsumerGroup(queue, cb) {
return this.checkOperation(queue, EQueueOperation.CREATE_CONSUMER_GROUP, cb);
}
static canDeleteConsumerGroup(queue, cb) {
return this.checkOperation(queue, EQueueOperation.DELETE_CONSUMER_GROUP, cb);
}
static canBindExchange(queue, cb) {
return this.checkOperation(queue, EQueueOperation.BIND_EXCHANGE, cb);
}
static canUnbindExchange(queue, cb) {
return this.checkOperation(queue, EQueueOperation.UNBIND_EXCHANGE, cb);
}
}
//# sourceMappingURL=queue-operation-validator.js.map