/**
* Validates configuration for binary files for short-lived tasks with a dry-run mode.
*
* @param {object} config - Configuration object.
* @param {boolean} dryRun - Whether to perform a dry run. Defaults to false.
* @returns {object} - Validation results.
*/
function validateBinaryConfig(config, dryRun = false) {
const validationResults = {
errors: [],
warnings: [],
};
// Validate required fields
if (!config.inputFile || !config.outputFile || !config.task) {
validationResults.errors.push("Missing required configuration fields (inputFile, outputFile, task).");
return validationResults;
}
// Validate input file
if (!/^[a-zA-Z0-9._-]+$/.test(config.inputFile)) {
validationResults.errors.push("Invalid input file name. Only alphanumeric characters, dots, underscores, and hyphens are allowed.");
}
// Validate output file
if (!/^[a-zA-Z0-9._-]+$/.test(config.outputFile)) {
validationResults.errors.push("Invalid output file name. Only alphanumeric characters, dots, underscores, and hyphens are allowed.");
}
// Validate task
if (typeof config.task !== 'function') {
validationResults.errors.push("Task must be a function.");
}
// Validate task arguments
if (config.task.length > 3) {
validationResults.warnings.push("Task accepts more than 3 arguments. Consider refactoring.");
}
// Validate file size limits (example)
if (config.maxFileSize && config.inputFile.length > config.maxFileSize) {
validationResults.warnings.push(`Input file exceeds maximum size of ${config.maxFileSize} bytes.`);
}
// Dry-run mode
if (dryRun) {
validationResults.message = "Dry run mode enabled. No actual file operations performed.";
}
return validationResults;
}
Add your comment