« get me outta code hell

coverArtDate and Thing unit tests - 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>2022-02-13 16:30:49 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-13 16:30:49 -0400
commit5bb1f8573990e5c5c92f416f7fda9811547c0580 (patch)
tree96c48a253bc5af280dc4e86cdf8cfb42e9505903 /src/data
parentcd5c1775883712ed52a135d8d24bfd2db698a832 (diff)
coverArtDate and Thing unit tests
Diffstat (limited to 'src/data')
-rw-r--r--src/data/things.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/data/things.js b/src/data/things.js
index b5d6f109..e061d581 100644
--- a/src/data/things.js
+++ b/src/data/things.js
@@ -252,6 +252,9 @@ Thing.common = {
     })
 };
 
+// Get a reference to a thing (e.g. track:showtime-piano-refrain), using its
+// constructor's [Thing.referenceType] as the prefix. This will throw an error
+// if the thing's directory isn't yet provided/computable.
 Thing.getReference = function(thing) {
     if (!thing.constructor[Thing.referenceType])
         throw TypeError(`Passed Thing is ${thing.constructor.name}, which provides no [Thing.referenceType]`);
@@ -398,7 +401,6 @@ Track.propertyDescriptors = {
 
     urls: Thing.common.urls(),
     dateFirstReleased: Thing.common.simpleDate(),
-    coverArtDate: Thing.common.simpleDate(),
 
     hasCoverArt: Thing.common.flag(true),
     hasURLs: Thing.common.flag(true),
@@ -451,9 +453,32 @@ Track.propertyDescriptors = {
         }
     },
 
+    coverArtDate: {
+        flags: {update: true, expose: true},
+
+        update: {validate: isDate},
+
+        expose: {
+            dependencies: ['albumData', 'dateFirstReleased'],
+            transform: (coverArtDate, { albumData, dateFirstReleased, [Track.instance]: track }) => (
+                coverArtDate ??
+                dateFirstReleased ??
+                albumData?.find(album => album.tracks.includes(track))?.trackArtDate ??
+                albumData?.find(album => album.tracks.includes(track))?.date ??
+                null
+            )
+        }
+    },
+
     // Previously known as: (track).artists
     artistContribs: Thing.common.dynamicContribs('artistContribsByRef'),
 
+    // Previously known as: (track).contributors
+    contributorContribs: Thing.common.dynamicContribs('contributorContribsByRef'),
+
+    // Previously known as: (track).coverArtists
+    coverArtistContribs: Thing.common.dynamicContribs('coverArtistContribsByRef'),
+
     artTags: {
         flags: {expose: true},