kafka-pub-sub
Version:
Enterprise-grade Kafka publish/subscribe library for Node.js — producer pool, batch sending, DLQ, SSL/SASL, multi-broker, and real-world industry examples.
28 lines (23 loc) • 687 B
JavaScript
const Joi = require('joi');
/**
* Validates a Kafka message event (the key prefix).
*
* Rules:
* - Must be a non-empty string
* - 1–100 characters
*
* @param {string} event - The event name to validate.
* @throws {Error} When the event is invalid.
*/
const validateEvent = (event) => {
const schema = Joi.object()
.keys({
event: Joi.string().min(1).max(100).required().description('Kafka message event name'),
})
.unknown();
const { error } = schema.prefs({ errors: { label: 'key' } }).validate({ event });
if (error) {
throw new Error('Invalid event: must be a non-empty string up to 100 characters');
}
};
module.exports = validateEvent;