/**
* Batches configuration value operations for hypothesis validation.
* Logs errors encountered during the process.
*
* @param {Array<Object>} configUpdates - An array of configuration update objects.
* Each object should have 'key' and 'value' properties.
* @param {Object} config - The current configuration object. This will be modified in place.
*/
function batchConfigUpdates(configUpdates, config) {
if (!Array.isArray(configUpdates)) {
console.error("configUpdates must be an array.");
return;
}
for (const update of configUpdates) {
if (typeof update !== 'object' || update === null || !('key' in update) || !('value' in update)) {
console.error("Invalid config update object:", update);
continue; // Skip invalid updates
}
const key = update.key;
const value = update.value;
try {
// Apply the update. Handle different update types appropriately.
if (typeof value === 'string') {
config[key] = value; // Simple string assignment
} else if (typeof value === 'number') {
config[key] = Number(value); // Convert to number
} else if (typeof value === 'boolean') {
config[key] = value; //Boolean assignment
} else if (Array.isArray(value)) {
config[key] = value; //Array assignment
} else {
console.warn(`Unsupported value type for key '${key}': ${typeof value}`);
}
} catch (error) {
console.error(`Error updating config key '${key}':`, error);
}
}
}
Add your comment