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.
24 lines (18 loc) • 595 B
JavaScript
const Joi = require('joi');
/**
* Validates Kafka message data.
*
* @param {Object} data - The payload object to validate.
* @throws {Error} When data is missing or not a plain object.
*/
const validateData = (data) => {
if (data === undefined || data === null) {
throw new Error('Invalid data: No data found to produce');
}
const schema = Joi.object().keys().unknown();
const { error } = schema.prefs({ errors: { label: 'key' } }).validate(data);
if (error) {
throw new Error('Invalid data: The type of data should be object');
}
};
module.exports = validateData;