config-loader: normalize data paths to ensure consistent behavior

This commit is contained in:
Patrik Oldsberg
2020-11-15 21:29:30 +01:00
parent cb1634e818
commit f6ed7d5d0d
3 changed files with 15 additions and 11 deletions
@@ -56,7 +56,11 @@ export function compileConfigSchemas(
return false;
}
if (visibility) {
visibilityByPath.set(dataPath, visibility);
const normalizedPath = dataPath.replace(
/\['?(.*?)'?\]/g,
(_, segment) => `.${segment}`,
);
visibilityByPath.set(normalizedPath, visibility);
}
return true;
};
@@ -40,18 +40,18 @@ const data = {
const visiblity = new Map<string, ConfigVisibility>(
Object.entries({
'.arr[0]': 'frontend',
'.arr[1]': 'backend',
'.arr[2]': 'secret',
'.arr.0': 'frontend',
'.arr.1': 'backend',
'.arr.2': 'secret',
'.obj.f': 'frontend',
'.obj.b': 'backend',
'.obj.b.s': 'secret',
'.objArr[0].f': 'frontend',
'.objArr[0].b': 'backend',
'.objArr[0].s': 'secret',
'.objArr[1].f': 'frontend',
'.objArr[1].b': 'backend',
'.objArr[1].s': 'secret',
'.objArr.0.f': 'frontend',
'.objArr.0.b': 'backend',
'.objArr.0.s': 'secret',
'.objArr.1.f': 'frontend',
'.objArr.1.b': 'backend',
'.objArr.1.s': 'secret',
'.arrF': 'frontend',
'.arrB': 'backend',
'.arrS': 'secret',
@@ -49,7 +49,7 @@ export function filterByVisibility(
const arr = new Array<JsonValue>();
for (const [index, value] of jsonVal.entries()) {
const out = transform(value, `${path}[${index}]`);
const out = transform(value, `${path}.${index}`);
if (out !== undefined) {
arr.push(out);
}