« 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
diff options
context:
space:
mode:
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/wiki-data/helpers/withResolvedReverse.js2
-rw-r--r--src/data/thing.js67
-rw-r--r--src/data/things/Artist.js33
-rw-r--r--src/data/things/Artwork.js2
-rw-r--r--src/data/things/MusicVideo.js38
-rw-r--r--src/data/things/contrib/Contribution.js14
6 files changed, 136 insertions, 20 deletions
diff --git a/src/data/composite/wiki-data/helpers/withResolvedReverse.js b/src/data/composite/wiki-data/helpers/withResolvedReverse.js
index 818f60b7..bad64925 100644
--- a/src/data/composite/wiki-data/helpers/withResolvedReverse.js
+++ b/src/data/composite/wiki-data/helpers/withResolvedReverse.js
@@ -5,7 +5,7 @@ import {input, templateCompositeFrom} from '#composite';
 import inputWikiData from '../inputWikiData.js';
 
 export default templateCompositeFrom({
-  annotation: `withReverseReferenceList`,
+  annotation: `withResolvedReverse`,
 
   inputs: {
     data: inputWikiData({allowMixedTypes: true}),
diff --git a/src/data/thing.js b/src/data/thing.js
index 0a6e3be4..f5afe076 100644
--- a/src/data/thing.js
+++ b/src/data/thing.js
@@ -67,14 +67,7 @@ export default class Thing extends CacheableObject {
       name = colors.yellow(`couldn't get name`);
     }
 
-    let reference;
-    try {
-      if (this.directory) {
-        reference = colors.blue(Thing.getReference(this));
-      }
-    } catch {
-      reference = colors.yellow(`couldn't get reference`);
-    }
+    let reference = Thing.inspectReference(this, {showConstructor: false});
 
     return (
       (name ? `${constructorName} ${name}` : `${constructorName}`) +
@@ -127,6 +120,64 @@ export default class Thing extends CacheableObject {
     return `${thing.constructor[Thing.referenceType]}:${thing.directory}`;
   }
 
+  static inspectReference(thing, {showConstructor = true} = {}) {
+    const referenceType =
+      thing.constructor[Thing.referenceType] ??
+      null;
+
+    const constructorPart =
+      (showConstructor
+        ? `${thing.constructor.name} `
+        : ``);
+
+    let errored = false;
+    const tryToGet = property => {
+      try {
+        return thing[property] ?? null;
+      } catch {
+        errored = true;
+        return null;
+      }
+    };
+
+    const directoryPart = this.inspectDirectory(thing);
+    const directoryErrored = directoryPart === null;
+
+    if (directoryPart && referenceType) {
+      return colors.blue(`${referenceType}:${directoryPart}`);
+    } else if (directoryPart) {
+      return constructorPart + `(${colors.blue(directoryPart)})`;
+    } else if (tryToGet('name')) {
+      return constructorPart + `(named ${inspect(thing.name)}`;
+    } else if (errored && directoryErrored) {
+      return constructorPart + `(${colors.yellow(`couldn't compute reference`)})`;
+    } else {
+      return constructorPart;
+    }
+  }
+
+  static inspectDirectory(thing) {
+    let errored = false;
+    const tryToGet = property => {
+      try {
+        return thing[property] ?? null;
+      } catch {
+        errored = true;
+        return null;
+      }
+    };
+
+    if (tryToGet('directory')) {
+      return thing.directory;
+    } else if (tryToGet('unqualifiedDirectory')) {
+      return `…${thing.unqualifiedDirectory}`;
+    } else if (errored) {
+      return null;
+    } else {
+      return '';
+    }
+  }
+
   static extendDocumentSpec(thingClass, subspec) {
     const superspec = thingClass[Thing.yamlDocumentSpec];
 
diff --git a/src/data/things/Artist.js b/src/data/things/Artist.js
index f518e31e..b82ef8bf 100644
--- a/src/data/things/Artist.js
+++ b/src/data/things/Artist.js
@@ -14,8 +14,10 @@ import {
 
 import {exitWithoutDependency, exposeConstant, exposeDependency}
   from '#composite/control-flow';
-import {withFilteredList, withPropertyFromList} from '#composite/data';
-import {withContributionListSums} from '#composite/wiki-data';
+import {withFilteredList, withMappedList, withPropertyFromList}
+  from '#composite/data';
+import {withContributionListSums, withReverseReferenceList}
+  from '#composite/wiki-data';
 
 import {
   constitutibleArtwork,
@@ -216,6 +218,33 @@ export class Artist extends Thing {
       reverse: soupyReverse.input('musicVideoContributorContributionsBy'),
     }),
 
+    otherMusicVideoArtistContributionsToOwnAlbums: [
+      withReverseReferenceList({
+        reverse: soupyReverse.input('musicVideoArtistContributionsToAlbumsBy'),
+      }).outputs({
+        '#reverseReferenceList': '#allArtistContributions',
+      }),
+
+      {
+        dependencies: [input.myself()],
+        compute: (continuation, {
+          [input.myself()]: myself,
+        }) => continuation({
+          ['#isNotMyself']: artist => artist !== myself,
+        }),
+      },
+
+      withPropertyFromList('#allArtistContributions', V('artist')),
+
+      withMappedList('#allArtistContributions.artist', '#isNotMyself')
+        .outputs({'#mappedList': '#differentArtistFilter'}),
+
+      withFilteredList('#allArtistContributions', '#differentArtistFilter')
+        .outputs({'#filteredList': '#otherArtistContributions'}),
+
+      exposeDependency('#otherArtistContributions'),
+    ],
+
     totalDuration: [
       withPropertyFromList('musicContributions', V('thing')),
       withPropertyFromList('#musicContributions.thing', V('isMainRelease')),
diff --git a/src/data/things/Artwork.js b/src/data/things/Artwork.js
index 7beb3567..d2bd31ba 100644
--- a/src/data/things/Artwork.js
+++ b/src/data/things/Artwork.js
@@ -422,7 +422,7 @@ export class Artwork extends Thing {
 
         parts.push(` for ${inspect(this.thing, newOptions)}`);
       } else {
-        parts.push(` for ${colors.blue(Thing.getReference(this.thing))}`);
+        parts.push(` for ${Thing.inspectReference(this.thing)}`);
       }
     }
 
diff --git a/src/data/things/MusicVideo.js b/src/data/things/MusicVideo.js
index 3a41caf5..77c8c619 100644
--- a/src/data/things/MusicVideo.js
+++ b/src/data/things/MusicVideo.js
@@ -167,6 +167,32 @@ export class MusicVideo extends Thing {
 
     musicVideoContributorContributionsBy:
       soupyReverse.contributionsBy('musicVideoData', 'contributorContribs'),
+
+    musicVideoArtistContributionsToAlbumsBy: {
+      bindTo: 'musicVideoData',
+
+      referencing: musicVideo => musicVideo.artistContribs,
+
+      *referenced(musicVideoContrib) {
+        const musicVideo = musicVideoContrib.thing;
+        const trackOrAlbum = musicVideo.thing;
+        if (trackOrAlbum.isTrack) {
+          const albumArtists =
+            trackOrAlbum.album.artistContribs
+              .map(albumContrib => albumContrib.artist);
+
+          for (const trackContrib of trackOrAlbum.artistContribs) {
+            if (albumArtists.includes(trackContrib.artist)) {
+              yield trackContrib.artist;
+            }
+          }
+        } else {
+          for (const albumContrib of trackOrAlbum.artistContribs) {
+            yield albumContrib.artist;
+          }
+        }
+      },
+    },
   };
 
   get path() {
@@ -179,7 +205,15 @@ export class MusicVideo extends Thing {
   [inspect.custom](depth, options, inspect) {
     const parts = [];
 
-    parts.push(Thing.prototype[inspect.custom].apply(this));
+    parts.push(this.constructor.name);
+
+    if (this.title) {
+      parts.push(` ${colors.green(`"${this.title}"`)}`);
+    } else if (this.label) {
+      parts.push(` (${colors.green(`"${this.label}"`)})`);
+    } else if (this.unqualifiedDirectory !== 'music-video') {
+      parts.push(` (${colors.blue(this.unqualifiedDirectory)})`);
+    }
 
     if (this.thing) {
       if (depth >= 0) {
@@ -193,7 +227,7 @@ export class MusicVideo extends Thing {
 
         parts.push(` for ${inspect(this.thing, newOptions)}`);
       } else {
-        parts.push(` for ${colors.blue(Thing.getReference(this.thing))}`);
+        parts.push(` for ${colors.blue(Thing.inspectReference(this.thing))}`);
       }
     }
 
diff --git a/src/data/things/contrib/Contribution.js b/src/data/things/contrib/Contribution.js
index 4352b58a..305e6a14 100644
--- a/src/data/things/contrib/Contribution.js
+++ b/src/data/things/contrib/Contribution.js
@@ -314,8 +314,7 @@ export class Contribution extends Thing {
       }
 
       if (artist) {
-        artistRef =
-          colors.blue(Thing.getReference(artist));
+        artistRef = Thing.inspectReference(artist);
       }
     } else {
       artistRef =
@@ -326,7 +325,7 @@ export class Contribution extends Thing {
       accentParts.push(`by ${artistRef}`);
     }
 
-    if (this.thing) {
+    if (this.thing) toPart: {
       if (depth >= 0) {
         const newOptions = {
           ...options,
@@ -336,10 +335,13 @@ export class Contribution extends Thing {
               : options.depth - 1),
         };
 
-        accentParts.push(`to ${inspect(this.thing, newOptions)}`);
-      } else {
-        accentParts.push(`to ${colors.blue(Thing.getReference(this.thing))}`);
+        try {
+          accentParts.push(`to ${inspect(this.thing, newOptions)}`);
+          break toPart;
+        } catch {}
       }
+
+      accentParts.push(`to ${Thing.inspectReference(this.thing)}`);
     }
 
     if (!empty(accentParts)) {