« get me outta code hell

reverse: artworksWhichReference - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2025-01-11 17:35:02 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-01-11 17:35:02 -0400
commitcde9bdcdd35ecf9246552af192876a84d21f60ea (patch)
tree797706b05ec45d309764870bd14c5b817518e925 /src
parent1cc21e130e691d79677c62362a17070597e1ee93 (diff)
reverse: artworksWhichReference
Diffstat (limited to 'src')
-rw-r--r--src/reverse.js23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/reverse.js b/src/reverse.js
index 9b642e39..22746d24 100644
--- a/src/reverse.js
+++ b/src/reverse.js
@@ -74,7 +74,28 @@ function reverseHelper(spec) {
   };
 }
 
-const hardcodedReverseSpecs = {};
+const hardcodedReverseSpecs = {
+  // Artworks aren't Thing objects.
+  // This spec operates on albums and tracks alike!
+  artworksWhichReference: {
+    bindTo: 'wikiData',
+
+    referencing: ({albumData, trackData}) =>
+      [...albumData, ...trackData]
+        .flatMap(referencingThing =>
+          referencingThing.referencedArtworks
+            .map(({thing: referencedThing, ...referenceDetails}) => ({
+              referencingThing,
+              referencedThing,
+              referenceDetails,
+            }))),
+
+    referenced: ({referencedThing}) => [referencedThing],
+
+    tidy: ({referencingThing, referenceDetails}) =>
+      ({thing: referencingThing, ...referenceDetails}),
+  },
+};
 
 const findReverseHelperConfig = {
   word: `reverse`,