Skip to content

Commit

Permalink
fix: Ensure to preserve undefined valued propeties as undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Oct 9, 2020
1 parent 244ae11 commit 2e26e07
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/classes/ConfigSchemaHandler/index.js
Expand Up @@ -27,7 +27,7 @@ const normalizeSchemaObject = (object, instanceSchema) => {
// normalizedObjectsMap allows to handle circular structures without issues
const normalizeUserConfig = userConfig => {
const normalizedObjectsSet = new WeakSet();
const nullPaths = [];
const removedValuesMap = [];
const normalizeObject = (object, path) => {
if (normalizedObjectsSet.has(object)) return;
normalizedObjectsSet.add(object);
Expand All @@ -38,7 +38,7 @@ const normalizeUserConfig = userConfig => {
} else {
for (const [key, value] of Object.entries(object)) {
if (value == null) {
nullPaths.push(path.concat(key));
removedValuesMap.push({ path: path.concat(key), value });
delete object[key];
} else if (_.isObject(value)) {
normalizeObject(value, path.concat(key));
Expand All @@ -47,10 +47,12 @@ const normalizeUserConfig = userConfig => {
}
};
normalizeObject(userConfig, []);
return { nullPaths };
return { removedValuesMap };
};
const denormalizeUserConfig = (userConfig, { nullPaths }) => {
for (const nullPath of nullPaths) _.set(userConfig, nullPath, null);
const denormalizeUserConfig = (userConfig, { removedValuesMap }) => {
for (const removedValueData of removedValuesMap) {
_.set(userConfig, removedValueData.path, removedValueData.value);
}
};

class ConfigSchemaHandler {
Expand Down

0 comments on commit 2e26e07

Please sign in to comment.