1. /**
  2. * Batches configuration value operations for hypothesis validation.
  3. * Logs errors encountered during the process.
  4. *
  5. * @param {Array<Object>} configUpdates - An array of configuration update objects.
  6. * Each object should have 'key' and 'value' properties.
  7. * @param {Object} config - The current configuration object. This will be modified in place.
  8. */
  9. function batchConfigUpdates(configUpdates, config) {
  10. if (!Array.isArray(configUpdates)) {
  11. console.error("configUpdates must be an array.");
  12. return;
  13. }
  14. for (const update of configUpdates) {
  15. if (typeof update !== 'object' || update === null || !('key' in update) || !('value' in update)) {
  16. console.error("Invalid config update object:", update);
  17. continue; // Skip invalid updates
  18. }
  19. const key = update.key;
  20. const value = update.value;
  21. try {
  22. // Apply the update. Handle different update types appropriately.
  23. if (typeof value === 'string') {
  24. config[key] = value; // Simple string assignment
  25. } else if (typeof value === 'number') {
  26. config[key] = Number(value); // Convert to number
  27. } else if (typeof value === 'boolean') {
  28. config[key] = value; //Boolean assignment
  29. } else if (Array.isArray(value)) {
  30. config[key] = value; //Array assignment
  31. } else {
  32. console.warn(`Unsupported value type for key '${key}': ${typeof value}`);
  33. }
  34. } catch (error) {
  35. console.error(`Error updating config key '${key}':`, error);
  36. }
  37. }
  38. }

Add your comment