« get me outta code hell

yaml: allow pushing onto existing wikiData keys by save() step - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/yaml.js
diff options
context:
space:
mode:
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
commitf1948a85f54260c8b15da61a362d63bec6f00926 (patch)
tree9ad279950a94be99eab43947bddd1cd5fb659570 /src/data/yaml.js
parent91469b51fe10fbedaece83dafb07e1fd6730e11c (diff)
yaml: allow pushing onto existing wikiData keys by save() step
Diffstat (limited to 'src/data/yaml.js')
-rw-r--r--src/data/yaml.js20
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};