« get me outta code hell

data, content: stub multiple artworks - 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>2025-04-02 15:10:58 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-04-10 16:02:38 -0300
commit58fba5a7a859c5398e0e58f31d7e8e5a649db63b (patch)
tree39f4ac7ed8292d2af453263f63ecdfaf93cba42d /src/data
parent4030a62fc518627071dc792e2754d9d99fa46546 (diff)
data, content: stub multiple artworks
Only for tracks as of this commit, most anything else is in a
severely broken state aye
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/data/withPropertyFromList.js22
-rw-r--r--src/data/composite/things/track/withHasUniqueCoverArt.js20
-rw-r--r--src/data/composite/wiki-properties/constitutibleArtworkList.js (renamed from src/data/composite/wiki-properties/constitutibleArtwork.js)17
-rw-r--r--src/data/composite/wiki-properties/index.js2
-rw-r--r--src/data/composite/wiki-properties/soupyReverse.js5
-rw-r--r--src/data/things/album.js14
-rw-r--r--src/data/things/track.js8
-rw-r--r--src/data/yaml.js7
8 files changed, 62 insertions, 33 deletions
diff --git a/src/data/composite/data/withPropertyFromList.js b/src/data/composite/data/withPropertyFromList.js
index 65ebf77b..760095c2 100644
--- a/src/data/composite/data/withPropertyFromList.js
+++ b/src/data/composite/data/withPropertyFromList.js
@@ -5,11 +5,15 @@
 // original list are kept null here. Objects which don't have the specified
 // property are retained in-place as null.
 //
+// If the `internal` input is true, this reads the CacheableObject update value
+// of each object rather than its exposed value.
+//
 // See also:
 //  - withPropertiesFromList
 //  - withPropertyFromObject
 //
 
+import CacheableObject from '#cacheable-object';
 import {input, templateCompositeFrom} from '#composite';
 
 function getOutputName({list, property, prefix}) {
@@ -26,6 +30,7 @@ export default templateCompositeFrom({
     list: input({type: 'array'}),
     property: input({type: 'string'}),
     prefix: input.staticValue({type: 'string', defaultValue: null}),
+    internal: input({type: 'boolean', defaultValue: false}),
   },
 
   outputs: ({
@@ -37,13 +42,26 @@ export default templateCompositeFrom({
 
   steps: () => [
     {
-      dependencies: [input('list'), input('property')],
+      dependencies: [
+        input('list'),
+        input('property'),
+        input('internal'),
+      ],
+
       compute: (continuation, {
         [input('list')]: list,
         [input('property')]: property,
+        [input('internal')]: internal,
       }) => continuation({
         ['#values']:
-          list.map(item => item[property] ?? null),
+          list.map(item =>
+            (item === null
+              ? null
+           : internal
+              ? CacheableObject.getUpdateValue(item, property)
+                  ?? null
+              : item[property]
+                  ?? null)),
       }),
     },
 
diff --git a/src/data/composite/things/track/withHasUniqueCoverArt.js b/src/data/composite/things/track/withHasUniqueCoverArt.js
index 2ea845f6..e0a435fe 100644
--- a/src/data/composite/things/track/withHasUniqueCoverArt.js
+++ b/src/data/composite/things/track/withHasUniqueCoverArt.js
@@ -10,7 +10,7 @@ import {input, templateCompositeFrom} from '#composite';
 import {empty} from '#sugar';
 
 import {raiseOutputWithoutDependency} from '#composite/control-flow';
-import {withPropertyFromObject} from '#composite/data';
+import {withFlattenedList, withPropertyFromList} from '#composite/data';
 import {withResolvedContribs} from '#composite/wiki-data';
 
 import withPropertyFromAlbum from './withPropertyFromAlbum.js';
@@ -65,20 +65,24 @@ export default templateCompositeFrom({
             })),
     },
 
-    withPropertyFromObject({
-      object: 'trackArtwork',
+    raiseOutputWithoutDependency({
+      dependency: 'trackArtworks',
+      mode: input.value('empty'),
+      output: input.value({'#hasUniqueCoverArt': false}),
+    }),
+
+    withPropertyFromList({
+      list: 'trackArtworks',
       property: input.value('artistContribs'),
       internal: input.value(true),
     }),
 
-    raiseOutputWithoutDependency({
-      dependency: '#trackArtwork.artistContribs',
-      mode: input.value('empty'),
-      output: input.value({'#hasUniqueCoverArt': false}),
+    withFlattenedList({
+      list: '#trackArtworks.artistContribs',
     }),
 
     withResolvedContribs({
-      from: '#trackArtwork.artistContribs',
+      from: '#flattenedList',
       date: input.value(null),
     }),
 
diff --git a/src/data/composite/wiki-properties/constitutibleArtwork.js b/src/data/composite/wiki-properties/constitutibleArtworkList.js
index e0f0f521..01429f03 100644
--- a/src/data/composite/wiki-properties/constitutibleArtwork.js
+++ b/src/data/composite/wiki-properties/constitutibleArtworkList.js
@@ -1,7 +1,7 @@
 import {input, templateCompositeFrom} from '#composite';
-import {isContributionList, isDate, validateThing} from '#validators';
+import {isContributionList, isDate, validateWikiData} from '#validators';
 
-import {exitWithoutDependency, exposeDependency, exposeUpdateValueOrContinue}
+import {exitWithoutDependency, exposeUpdateValueOrContinue}
   from '#composite/control-flow';
 import {withConstitutedArtwork} from '#composite/wiki-data';
 
@@ -29,14 +29,14 @@ export default templateCompositeFrom({
   steps: () => [
     exposeUpdateValueOrContinue({
       validate: input.value(
-        validateThing({
+        validateWikiData({
           referenceType: 'artwork',
         })),
     }),
 
     exitWithoutDependency({
       dependency: input('contribs'),
-      value: input.value(null),
+      value: input.value([]),
     }),
 
     {
@@ -60,8 +60,11 @@ export default templateCompositeFrom({
       dateProperty: '#dateProperty',
     }),
 
-    exposeDependency({
-      dependency: '#constitutedArtwork',
-    }),
+    {
+      dependencies: ['#constitutedArtwork'],
+      compute: ({
+        ['#constitutedArtwork']: constitutedArtwork,
+      }) => [constitutedArtwork],
+    },
   ],
 });
diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js
index 7583630d..d346c7e5 100644
--- a/src/data/composite/wiki-properties/index.js
+++ b/src/data/composite/wiki-properties/index.js
@@ -9,7 +9,7 @@ export {default as annotatedReferenceList} from './annotatedReferenceList.js';
 export {default as color} from './color.js';
 export {default as commentary} from './commentary.js';
 export {default as commentatorArtists} from './commentatorArtists.js';
-export {default as constitutibleArtwork} from './constitutibleArtwork.js';
+export {default as constitutibleArtworkList} from './constitutibleArtworkList.js';
 export {default as contentString} from './contentString.js';
 export {default as contribsPresent} from './contribsPresent.js';
 export {default as contributionList} from './contributionList.js';
diff --git a/src/data/composite/wiki-properties/soupyReverse.js b/src/data/composite/wiki-properties/soupyReverse.js
index a3171738..b99c45da 100644
--- a/src/data/composite/wiki-properties/soupyReverse.js
+++ b/src/data/composite/wiki-properties/soupyReverse.js
@@ -24,9 +24,8 @@ soupyReverse.artworkContributionsBy =
     bindTo,
 
     referencing: thing =>
-      (thing[artworkProperty]
-        ? thing[artworkProperty].artistContribs
-        : []),
+      thing[artworkProperty]
+        .flatMap(artwork => artwork.artistContribs),
 
     referenced: contrib => [contrib.artist],
   });
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 4321635e..36069afb 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -35,7 +35,7 @@ import {
   commentary,
   color,
   commentatorArtists,
-  constitutibleArtwork,
+  constitutibleArtworkList,
   contentString,
   contribsPresent,
   contributionList,
@@ -159,7 +159,7 @@ export class Album extends Thing {
       dimensions(),
     ],
 
-    coverArtwork: constitutibleArtwork({
+    coverArtworks: constitutibleArtworkList({
       contribs: 'coverArtistContribs',
       date: 'coverArtDate',
       artistProperty: input.value('albumCoverArtistContributions'),
@@ -411,7 +411,7 @@ export class Album extends Thing {
       soupyReverse.contributionsBy('albumData', 'artistContribs'),
 
     albumCoverArtistContributionsBy:
-      soupyReverse.artworkContributionsBy('albumData', 'coverArtwork'),
+      soupyReverse.artworkContributionsBy('albumData', 'coverArtworks'),
 
     albumWallpaperArtistContributionsBy:
       soupyReverse.contributionsBy('albumData', 'wallpaperArtistContribs'),
@@ -468,7 +468,7 @@ export class Album extends Thing {
       'Listed in Galleries': {property: 'isListedInGalleries'},
 
       'Cover Artwork': {
-        property: 'coverArtwork',
+        property: 'coverArtworks',
         transform:
           parseArtwork({
             dateFromThingProperty: 'coverArtDate',
@@ -644,9 +644,7 @@ export class Album extends Thing {
           currentTrackSectionTracks.push(entry);
           trackData.push(entry);
 
-          if (entry.trackArtwork) {
-            artworkData.push(entry.trackArtwork);
-          }
+          artworkData.push(...entry.trackArtworks);
 
           entry.dataSourceAlbum = albumRef;
         }
@@ -655,6 +653,8 @@ export class Album extends Thing {
 
         albumData.push(album);
 
+        artworkData.push(...album.coverArtworks);
+
         album.trackSections = trackSections;
       }
 
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 6954bda2..7188178a 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -39,7 +39,7 @@ import {
   additionalNameList,
   commentary,
   commentatorArtists,
-  constitutibleArtwork,
+  constitutibleArtworkList,
   contentString,
   contributionList,
   dimensions,
@@ -341,7 +341,7 @@ export class Track extends Thing {
       }),
     ],
 
-    trackArtwork: constitutibleArtwork({
+    trackArtworks: constitutibleArtworkList({
       contribs: 'coverArtistContribs',
       date: 'coverArtDate',
       artistProperty: input.value('trackCoverArtistContributions'),
@@ -573,7 +573,7 @@ export class Track extends Thing {
       },
 
       'Track Artwork': {
-        property: 'trackArtwork',
+        property: 'trackArtworks',
         transform:
           parseArtwork({
             dateFromThingProperty: 'coverArtDate',
@@ -704,7 +704,7 @@ export class Track extends Thing {
       soupyReverse.contributionsBy('trackData', 'contributorContribs'),
 
     trackCoverArtistContributionsBy:
-      soupyReverse.artworkContributionsBy('trackData', 'trackArtwork'),
+      soupyReverse.artworkContributionsBy('trackData', 'trackArtworks'),
 
     tracksWithCommentaryBy: {
       bindTo: 'trackData',
diff --git a/src/data/yaml.js b/src/data/yaml.js
index d30bb54c..b766e753 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -794,7 +794,7 @@ export function parseArtwork({
   artistContribsFromThingProperty,
   artistContribsArtistProperty,
 }) {
-  return (entry, {subdoc, Artwork}) =>
+  const parseSingleEntry = (entry, {subdoc, Artwork}) =>
     subdoc(Artwork, entry, {
       bindInto: 'thing',
       provide: {
@@ -803,6 +803,11 @@ export function parseArtwork({
         artistContribsArtistProperty,
       },
     });
+
+  return (value, ...args) =>
+    (Array.isArray(value)
+      ? value.map(entry => parseSingleEntry(entry, ...args))
+      : [parseSingleEntry(value, ...args)]);
 }
 
 // documentModes: Symbols indicating sets of behavior for loading and processing