« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/album.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/album.js')
-rw-r--r--src/data/things/album.js122
1 files changed, 89 insertions, 33 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index bd54a356..5f1788f8 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -3,15 +3,13 @@ export const DATA_ALBUM_DIRECTORY = 'album';
 import * as path from 'node:path';
 import {inspect} from 'node:util';
 
-import CacheableObject from '#cacheable-object';
 import {colors} from '#cli';
 import {input} from '#composite';
-import find from '#find';
 import {traverse} from '#node-utils';
 import {sortAlbumsTracksChronologically, sortChronologically} from '#sort';
 import {accumulateSum, empty} from '#sugar';
 import Thing from '#thing';
-import {isColor, isDate, isDirectory, validateWikiData} from '#validators';
+import {isColor, isDate, isDirectory} from '#validators';
 
 import {
   parseAdditionalFiles,
@@ -27,12 +25,8 @@ import {exitWithoutDependency, exposeDependency, exposeUpdateValueOrContinue}
   from '#composite/control-flow';
 import {withPropertyFromObject} from '#composite/data';
 
-import {
-  exitWithoutContribs,
-  withDirectory,
-  withResolvedReference,
-  withCoverArtDate,
-} from '#composite/wiki-data';
+import {exitWithoutContribs, withDirectory, withCoverArtDate}
+  from '#composite/wiki-data';
 
 import {
   additionalFiles,
@@ -50,10 +44,11 @@ import {
   name,
   referencedArtworkList,
   referenceList,
-  reverseReferencedArtworkList,
+  reverseReferenceList,
   simpleDate,
   simpleString,
-  singleReference,
+  soupyFind,
+  soupyReverse,
   thing,
   thingList,
   urls,
@@ -69,7 +64,6 @@ export class Album extends Thing {
 
   static [Thing.getPropertyDescriptors] = ({
     ArtTag,
-    Artist,
     Group,
     Track,
     TrackSection,
@@ -92,6 +86,7 @@ export class Album extends Thing {
       }),
     ],
 
+    alwaysReferenceByDirectory: flag(false),
     alwaysReferenceTracksByDirectory: flag(false),
     suffixTrackDirectories: flag(false),
 
@@ -229,8 +224,7 @@ export class Album extends Thing {
 
     groups: referenceList({
       class: input.value(Group),
-      find: input.value(find.group),
-      data: 'groupData',
+      find: soupyFind.input('group'),
     }),
 
     artTags: [
@@ -241,8 +235,7 @@ export class Album extends Thing {
 
       referenceList({
         class: input.value(ArtTag),
-        find: input.value(find.artTag),
-        data: 'artTagData',
+        find: soupyFind.input('artTag'),
       }),
     ],
 
@@ -270,26 +263,20 @@ export class Album extends Thing {
 
     // Update only
 
+    find: soupyFind(),
+    reverse: soupyReverse(),
+
+    // used for referencedArtworkList (mixedFind)
     albumData: wikiData({
       class: input.value(Album),
     }),
 
-    artistData: wikiData({
-      class: input.value(Artist),
-    }),
-
-    artTagData: wikiData({
-      class: input.value(ArtTag),
-    }),
-
-    groupData: wikiData({
-      class: input.value(Group),
-    }),
-
+    // used for referencedArtworkList (mixedFind)
     trackData: wikiData({
       class: input.value(Track),
     }),
 
+    // used for withMatchingContributionPresets (indirectly by Contribution)
     wikiInfo: thing({
       class: input.value(WikiInfo),
     }),
@@ -313,7 +300,9 @@ export class Album extends Thing {
         value: input.value([]),
       }),
 
-      reverseReferencedArtworkList(),
+      reverseReferenceList({
+        reverse: soupyReverse.input('artworksWhichReference'),
+      }),
     ],
   });
 
@@ -361,6 +350,11 @@ export class Album extends Thing {
     album: {
       referenceTypes: ['album', 'album-commentary', 'album-gallery'],
       bindTo: 'albumData',
+
+      getMatchableNames: album =>
+        (album.alwaysReferenceByDirectory 
+          ? [] 
+          : [album.name]),
     },
 
     albumWithArtwork: {
@@ -369,6 +363,60 @@ export class Album extends Thing {
 
       include: album =>
         album.hasCoverArt,
+
+      getMatchableNames: album =>
+        (album.alwaysReferenceByDirectory 
+          ? [] 
+          : [album.name]),
+    },
+  };
+
+  static [Thing.reverseSpecs] = {
+    albumsWhoseTracksInclude: {
+      bindTo: 'albumData',
+
+      referencing: album => [album],
+      referenced: album => album.tracks,
+    },
+
+    albumsWhoseTrackSectionsInclude: {
+      bindTo: 'albumData',
+
+      referencing: album => [album],
+      referenced: album => album.trackSections,
+    },
+
+    albumsWhoseArtworksFeature: {
+      bindTo: 'albumData',
+
+      referencing: album => [album],
+      referenced: album => album.artTags,
+    },
+
+    albumsWhoseGroupsInclude: {
+      bindTo: 'albumData',
+
+      referencing: album => [album],
+      referenced: album => album.groups,
+    },
+
+    albumArtistContributionsBy:
+      soupyReverse.contributionsBy('albumData', 'artistContribs'),
+
+    albumCoverArtistContributionsBy:
+      soupyReverse.contributionsBy('albumData', 'coverArtistContribs'),
+
+    albumWallpaperArtistContributionsBy:
+      soupyReverse.contributionsBy('albumData', 'wallpaperArtistContribs'),
+
+    albumBannerArtistContributionsBy:
+      soupyReverse.contributionsBy('albumData', 'bannerArtistContribs'),
+
+    albumsWithCommentaryBy: {
+      bindTo: 'albumData',
+
+      referencing: album => [album],
+      referenced: album => album.commentatorArtists,
     },
   };
 
@@ -380,6 +428,7 @@ export class Album extends Thing {
       'Directory Suffix': {property: 'directorySuffix'},
       'Suffix Track Directories': {property: 'suffixTrackDirectories'},
 
+      'Always Reference By Directory': {property: 'alwaysReferenceByDirectory'},
       'Always Reference Tracks By Directory': {
         property: 'alwaysReferenceTracksByDirectory',
       },
@@ -516,7 +565,7 @@ export class Album extends Thing {
 
   static [Thing.getYamlLoadingSpec] = ({
     documentModes: {headerAndEntries},
-    thingConstructors: {Album, Track, TrackSectionHelper},
+    thingConstructors: {Album, Track},
   }) => ({
     title: `Process album files`,
 
@@ -640,9 +689,7 @@ export class TrackSection extends Thing {
 
     // Update only
 
-    albumData: wikiData({
-      class: input.value(Album),
-    }),
+    reverse: soupyReverse(),
 
     // Expose only
 
@@ -727,6 +774,15 @@ export class TrackSection extends Thing {
     },
   };
 
+  static [Thing.reverseSpecs] = {
+    trackSectionsWhichInclude: {
+      bindTo: 'trackSectionData',
+
+      referencing: trackSection => [trackSection],
+      referenced: trackSection => trackSection.tracks,
+    },
+  };
+
   static [Thing.yamlDocumentSpec] = {
     fields: {
       'Section': {property: 'name'},