« get me outta code hell

find, data: move find specs into Thing subclasses - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/artist.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-01-30 14:04:41 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-01-30 14:30:06 -0400
commitad146774480bb29cff04b50d887e132f3bd3f64f (patch)
tree9c789f74cf21793d9e3672f92628aa237f61eec3 /src/data/things/artist.js
parent7fbc5b87ed05bce433ed959ca18119b72835ee41 (diff)
find, data: move find specs into Thing subclasses
Diffstat (limited to 'src/data/things/artist.js')
-rw-r--r--src/data/things/artist.js61
1 files changed, 60 insertions, 1 deletions
diff --git a/src/data/things/artist.js b/src/data/things/artist.js
index a12dc96..589eca9 100644
--- a/src/data/things/artist.js
+++ b/src/data/things/artist.js
@@ -9,7 +9,7 @@ import find from '#find';
 import {stitchArrays, unique} from '#sugar';
 import Thing from '#thing';
 import {isName, validateArrayItems} from '#validators';
-import {sortAlphabetically} from '#wiki-data';
+import {getKebabCase, sortAlphabetically} from '#wiki-data';
 
 import {withReverseContributionList} from '#composite/wiki-data';
 
@@ -28,6 +28,7 @@ import {
 
 export class Artist extends Thing {
   static [Thing.referenceType] = 'artist';
+  static [Thing.wikiDataArray] = 'artistData';
 
   static [Thing.getPropertyDescriptors] = ({Album, Flash, Track}) => ({
     // Update & expose
@@ -247,6 +248,64 @@ export class Artist extends Thing {
     flashesAsContributor: S.toRefs,
   });
 
+  static [Thing.findSpecs] = {
+    artist: {
+      referenceTypes: ['artist', 'artist-gallery'],
+      bindTo: 'artistData',
+
+      include: artist => !artist.isAlias,
+    },
+
+    artistIncludingAliases: {
+      referenceTypes: ['artist', 'artist-gallery'],
+      bindTo: 'artistData',
+
+      getMatchableDirectories(artist) {
+        // Regular artists are always matchable by their directory.
+        if (!artist.isAlias) {
+          return [artist.directory];
+        }
+
+        const originalArtist = artist.aliasedArtist;
+
+        // Aliases never match by the same directory as the original.
+        if (artist.directory === originalArtist.directory) {
+          return [];
+        }
+
+        // Aliases never match by the same directory as some *previous* alias
+        // in the original's alias list. This is honestly a bit awkward, but it
+        // avoids artist aliases conflicting with each other when checking for
+        // duplicate directories.
+        for (const aliasName of originalArtist.aliasNames) {
+          // These are trouble. We should be accessing aliases' directories
+          // directly, but artists currently don't expose a reverse reference
+          // list for aliases. (This is pending a cleanup of "reverse reference"
+          // behavior in general.) It doesn't actually cause problems *here*
+          // because alias directories are computed from their names 100% of the
+          // time, but that *is* an assumption this code makes.
+          if (aliasName === artist.name) continue;
+          if (artist.directory === getKebabCase(aliasName)) {
+            return [];
+          }
+        }
+
+        // And, aliases never return just a blank string. This part is pretty
+        // spooky because it doesn't handle two differently named aliases, on
+        // different artists, who have names that are similar *apart* from a
+        // character that's shortened. But that's also so fundamentally scary
+        // that we can't support it properly with existing code, anyway - we
+        // would need to be able to specifically set a directory *on an alias,*
+        // which currently can't be done in YAML data files.
+        if (artist.directory === '') {
+          return [];
+        }
+
+        return [artist.directory];
+      },
+    },
+  };
+
   static [Thing.yamlDocumentSpec] = {
     fields: {
       'Artist': {property: 'name'},