« get me outta code hell

data: Album.coverArt{Date,FileExtension}: depend on contribs - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-09-08 10:54:58 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-08 10:54:58 -0300
commitee46a4f78f1bfc8348834fbd3349849148f178a8 (patch)
treee572a41f13c81d19a1ef56cc03feb52f93559d4e
parent3344a16a02a2c680d9e9eaf27c81890e17b9b5f4 (diff)
data: Album.coverArt{Date,FileExtension}: depend on contribs
-rw-r--r--src/data/things/album.js36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 88308182..3726a463 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -2,6 +2,13 @@ import find from '#find';
 import {empty} from '#sugar';
 import {isDate, isDimensions, isTrackSectionList} from '#validators';
 
+import {
+  compositeFrom,
+  exitWithoutDependency,
+  exposeDependency,
+  exposeUpdateValueOrContinue,
+} from '#composite';
+
 import Thing, {
   additionalFiles,
   commentary,
@@ -18,6 +25,7 @@ import Thing, {
   simpleString,
   urls,
   wikiData,
+  withResolvedContribs,
 } from './thing.js';
 
 export class Album extends Thing {
@@ -35,19 +43,16 @@ export class Album extends Thing {
     trackArtDate: simpleDate(),
     dateAddedToWiki: simpleDate(),
 
-    coverArtDate: {
-      flags: {update: true, expose: true},
+    coverArtDate: compositeFrom(`Album.coverArtDate`, [
+      withResolvedContribs({from: 'coverArtistContribs'}),
+      exitWithoutDependency({dependency: '#resolvedContribs', mode: 'empty'}),
 
-      update: {validate: isDate},
-
-      expose: {
-        dependencies: ['date', 'coverArtistContribs'],
-        transform: (coverArtDate, {coverArtistContribs, date}) =>
-          (!empty(coverArtistContribs)
-            ? coverArtDate ?? date ?? null
-            : null),
-      },
-    },
+      exposeUpdateValueOrContinue(),
+      exposeDependency({
+        dependency: 'date',
+        update: {validate: isDate},
+      }),
+    ]),
 
     artistContribs: contributionList(),
     coverArtistContribs: contributionList(),
@@ -102,7 +107,12 @@ export class Album extends Thing {
       },
     },
 
-    coverArtFileExtension: fileExtension('jpg'),
+    coverArtFileExtension: compositeFrom(`Album.coverArtFileExtension`, [
+      withResolvedContribs({from: 'coverArtistContribs'}),
+      exitWithoutDependency({dependency: '#resolvedContribs', mode: 'empty'}),
+      fileExtension('jpg'),
+    ]),
+
     trackCoverArtFileExtension: fileExtension('jpg'),
 
     wallpaperStyle: simpleString(),