diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-08-06 12:55:41 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-08-06 12:56:19 -0300 |
commit | f1948a85f54260c8b15da61a362d63bec6f00926 (patch) | |
tree | 9ad279950a94be99eab43947bddd1cd5fb659570 /src/data/yaml.js | |
parent | 91469b51fe10fbedaece83dafb07e1fd6730e11c (diff) |
yaml: allow pushing onto existing wikiData keys by save() step
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r-- | src/data/yaml.js | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/data/yaml.js b/src/data/yaml.js index ffda5991..ae8e2dd6 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -1116,7 +1116,25 @@ export function saveThingsFromDataSteps(thingLists, dataSteps) { }) .filter(Boolean) .forEach(saveResult => { - Object.assign(wikiData, saveResult); + for (const [saveKey, saveValue] of Object.entries(saveResult)) { + if (Object.hasOwn(wikiData, saveKey)) { + if (Array.isArray(wikiData[saveKey])) { + if (Array.isArray(saveValue)) { + wikiData[saveKey].push(...saveValue); + } else { + throw new Error(`${saveKey} already present, expected array of items to push`); + } + } else { + if (Array.isArray(saveValue)) { + throw new Error(`${saveKey} already present and not an array, refusing to overwrite`); + } else { + throw new Error(`${saveKey} already present, refusing to overwrite`); + } + } + } else { + wikiData[saveKey] = saveValue; + } + } }); return {aggregate, result: wikiData}; |