« get me outta code hell

brb gonna make these into one file now - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-02-12 15:27:14 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-02-12 15:27:14 -0400
commitcfa02cb03a363c46408db7f0ec54bd3a7e4ad018 (patch)
tree9dbd2f26cc200838717404163037953924f3e194 /src/thing
parentf028105cbb268af2c3039215557ed6f531c688d4 (diff)
brb gonna make these into one file now
Diffstat (limited to 'src/thing')
-rw-r--r--src/thing/album.js16
-rw-r--r--src/thing/thing.js30
-rw-r--r--src/thing/track.js20
3 files changed, 52 insertions, 14 deletions
diff --git a/src/thing/album.js b/src/thing/album.js
index 426796b0..ba75352d 100644
--- a/src/thing/album.js
+++ b/src/thing/album.js
@@ -20,6 +20,8 @@ import {
     validateReferenceList,
 } from './validators.js';
 
+import Artist from './artist.js';
+import ArtTag from './art-tag.js';
 import Track from './track.js';
 
 import find from '../util/find.js';
@@ -75,7 +77,7 @@ export class TrackGroup extends CacheableObject {
                         : [])
                 )
             }
-        }
+        },
     };
 }
 
@@ -238,13 +240,17 @@ export default class Album extends Thing {
 
         // Update only
 
-        trackData: {
-            flags: {update: true},
-            update: {validate: validateArrayItems(x => x instanceof Track)}
-        },
+        artistData: Thing.genWikiDataProperty(Artist),
+        trackData: Thing.genWikiDataProperty(Track),
 
         // Expose only
 
+        // Previously known as: (album).artists
+        artistContribs: {
+            flags: {expose: true},
+            expose: Thing.genContribsExpose('artistContribsByRef')
+        },
+
         tracks: {
             flags: {expose: true},
 
diff --git a/src/thing/thing.js b/src/thing/thing.js
index 54a278d1..2d6def62 100644
--- a/src/thing/thing.js
+++ b/src/thing/thing.js
@@ -3,7 +3,12 @@
 
 import CacheableObject from './cacheable-object.js';
 
+import {
+    validateArrayItems,
+} from './validators.js';
+
 import { getKebabCase } from '../util/wiki-data.js';
+import find from '../util/find.js';
 
 export default class Thing extends CacheableObject {
     static referenceType = Symbol('Thing.referenceType');
@@ -20,6 +25,31 @@ export default class Thing extends CacheableObject {
         }
     };
 
+    static genContribsExpose(contribsByRefProperty) {
+        return {
+            dependencies: ['artistData', contribsByRefProperty],
+            compute: ({ artistData, [contribsByRefProperty]: contribsByRef }) => (
+                (contribsByRef && artistData
+                    ? (contribsByRef
+                        .map(({ who: ref, what }) => ({
+                            who: find.artist(ref, {wikiData: {artistData}}),
+                            what
+                        }))
+                        .filter(({ who }) => who))
+                    : [])
+            )
+        };
+    }
+
+    static genWikiDataProperty(thingClass) {
+        return {
+            flags: {update: true},
+            update: {
+                validate: validateArrayItems(x => x instanceof thingClass)
+            }
+        };
+    }
+
     static getReference(thing) {
         if (!thing.constructor[Thing.referenceType])
             throw TypeError(`Passed Thing is ${thing.constructor.name}, which provides no [Thing.referenceType]`);
diff --git a/src/thing/track.js b/src/thing/track.js
index d0e88acf..3edabc92 100644
--- a/src/thing/track.js
+++ b/src/thing/track.js
@@ -17,6 +17,7 @@ import {
 } from './validators.js';
 
 import Album from './album.js';
+import Artist from './artist.js';
 import ArtTag from './art-tag.js';
 
 import find from '../util/find.js';
@@ -100,6 +101,7 @@ export default class Track extends Thing {
             update: {validate: validateReferenceList('tag')}
         },
 
+        // Previously known as: (track).aka
         originalReleaseTrackByRef: {
             flags: {update: true, expose: true},
             update: {validate: validateReference('track')}
@@ -117,15 +119,9 @@ export default class Track extends Thing {
 
         // Update only
 
-        albumData: {
-            flags: {update: true},
-            update: {validate: validateArrayItems(x => x instanceof Album)}
-        },
-
-        artTagData: {
-            flags: {update: true},
-            update: {validate: validateArrayItems(x => x instanceof ArtTag)}
-        },
+        albumData: Thing.genWikiDataProperty(Album),
+        artistData: Thing.genWikiDataProperty(Artist),
+        artTagData: Thing.genWikiDataProperty(ArtTag),
 
         // Expose only
 
@@ -152,6 +148,12 @@ export default class Track extends Thing {
             }
         },
 
+        // Previously known as: (track).artists
+        artistContribs: {
+            flags: {expose: true},
+            expose: Thing.genContribsExpose('artistContribsByRef')
+        },
+
         artTags: {
             flags: {expose: true},