1. /**
  2. * Strips metadata from configuration values for scheduled runs.
  3. *
  4. * @param {object} config The configuration object.
  5. * @returns {object} A new configuration object with metadata stripped.
  6. */
  7. function stripMetadata(config) {
  8. if (!config) {
  9. return {}; // Return empty object if input is null or undefined
  10. }
  11. const strippedConfig = {};
  12. for (const key in config) {
  13. if (config.hasOwnProperty(key)) {
  14. const value = config[key];
  15. if (typeof value === 'string') {
  16. // Remove metadata from strings (e.g., from a JSON string)
  17. strippedConfig[key] = JSON.parse(value);
  18. } else if (typeof value === 'object' && value !== null) {
  19. // Recursively strip metadata from objects
  20. strippedConfig[key] = stripMetadata(value);
  21. } else {
  22. // Keep primitive values as they are
  23. strippedConfig[key] = value;
  24. }
  25. }
  26. }
  27. return strippedConfig;
  28. }

Add your comment