fix: Parse Server databaseOptions nested keys incorrectly identified as invalid (#9213)

This commit is contained in:
Manuel
2024-07-17 17:48:33 +02:00
committed by GitHub
parent f384767d68
commit 77206d8044
7 changed files with 194 additions and 45 deletions

View File

@@ -370,6 +370,35 @@ class Utils {
}
}
}
/**
* Moves the nested keys of a specified key in an object to the root of the object.
*
* @param {Object} obj The object to modify.
* @param {String} key The key whose nested keys will be moved to root.
* @returns {Object} The modified object, or the original object if no modification happened.
* @example
* const obj = {
* a: 1,
* b: {
* c: 2,
* d: 3
* },
* e: 4
* };
* addNestedKeysToRoot(obj, 'b');
* console.log(obj);
* // Output: { a: 1, e: 4, c: 2, d: 3 }
*/
static addNestedKeysToRoot(obj, key) {
if (obj[key] && typeof obj[key] === 'object') {
// Add nested keys to root
Object.assign(obj, { ...obj[key] });
// Delete original nested key
delete obj[key];
}
return obj;
}
}
module.exports = Utils;