From f1948a85f54260c8b15da61a362d63bec6f00926 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 6 Aug 2024 12:55:41 -0300 Subject: yaml: allow pushing onto existing wikiData keys by save() step --- src/data/yaml.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/data') 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}; -- cgit 1.3.0-6-gf8a5