« get me outta code hell

data: linkWikiDataArrays: use getNestedProp - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-02-11 10:20:51 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-02-12 07:43:58 -0400
commit1cd87253681074907db8e6751fd787e37b7d17b5 (patch)
tree20d2ac84857d6014e94b9e021517ba2f343bd56d /src/data
parent6d691b3e99c67c07f53e368f376c24c8944233b8 (diff)
data: linkWikiDataArrays: use getNestedProp
Diffstat (limited to 'src/data')
-rw-r--r--src/data/checks.js6
-rw-r--r--src/data/yaml.js33
2 files changed, 24 insertions, 15 deletions
diff --git a/src/data/checks.js b/src/data/checks.js
index 57d0c1a4..74d0d9f9 100644
--- a/src/data/checks.js
+++ b/src/data/checks.js
@@ -237,7 +237,11 @@ export function filterReferenceErrors(wikiData, {
   const aggregate = openAggregate({message: `Errors validating between-thing references in data`});
   for (const [thingDataProp, propSpec] of referenceSpec) {
     const thingData = getNestedProp(wikiData, thingDataProp);
-    const things = Array.isArray(thingData) ? thingData.flat(Infinity) : [thingData];
+    const things =
+      (Array.isArray(thingData)
+        ? thingData.flat(Infinity)
+        : [thingData]);
+
     aggregate.nest({message: `Reference errors in ${colors.green('wikiData.' + thingDataProp)}`}, ({nest}) => {
       for (const thing of things) {
         nest({message: `Reference errors in ${inspect(thing)}`}, ({nest, push, filter}) => {
diff --git a/src/data/yaml.js b/src/data/yaml.js
index a1eb73fb..fbe5b7d4 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -30,6 +30,7 @@ import {
   atOffset,
   empty,
   filterProperties,
+  getNestedProp,
   stitchArrays,
   typeAppearance,
   withEntries,
@@ -1230,39 +1231,39 @@ export function linkWikiDataArrays(wikiData, {bindFind, bindReverse}) {
     // entries must be present here even without any properties to explicitly
     // link if the 'find' or 'reverse' properties will be implicitly linked
 
-    [wikiData.albumData, [
+    ['albumData', [
       'albumData',
       'trackData',
       'wikiInfo',
     ]],
 
-    [wikiData.artTagData, [/* reverse */]],
+    ['artTagData', [/* reverse */]],
 
-    [wikiData.artistData, [/* find, reverse */]],
+    ['artistData', [/* find, reverse */]],
 
-    [wikiData.flashData, [
+    ['flashData', [
       'wikiInfo',
     ]],
 
-    [wikiData.flashActData, [/* find, reverse */]],
+    ['flashActData', [/* find, reverse */]],
 
-    [wikiData.flashSideData, [/* find */]],
+    ['flashSideData', [/* find */]],
 
-    [wikiData.groupData, [/* find, reverse */]],
+    ['groupData', [/* find, reverse */]],
 
-    [wikiData.groupCategoryData, [/* find */]],
+    ['groupCategoryData', [/* find */]],
 
-    [wikiData.homepageLayout.rows, [/* find */]],
+    ['homepageLayout.rows', [/* find */]],
 
-    [wikiData.trackData, [
+    ['trackData', [
       'albumData',
       'trackData',
       'wikiInfo',
     ]],
 
-    [wikiData.trackSectionData, [/* reverse */]],
+    ['trackSectionData', [/* reverse */]],
 
-    [[wikiData.wikiInfo], [/* find */]],
+    ['wikiInfo', [/* find */]],
   ]);
 
   const constructorHasFindMap = new Map();
@@ -1271,8 +1272,12 @@ export function linkWikiDataArrays(wikiData, {bindFind, bindReverse}) {
   const boundFind = bindFind(wikiData);
   const boundReverse = bindReverse(wikiData);
 
-  for (const [things, keys] of linkWikiDataSpec.entries()) {
-    if (things === undefined) continue;
+  for (const [thingDataProp, keys] of linkWikiDataSpec.entries()) {
+    const thingData = getNestedProp(wikiData, thingDataProp);
+    const things =
+      (Array.isArray(thingData)
+        ? thingData.flat(Infinity)
+        : [thingData]);
 
     for (const thing of things) {
       if (thing === undefined) continue;