« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/thing/album.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/thing/album.js')
-rw-r--r--src/thing/album.js284
1 files changed, 237 insertions, 47 deletions
diff --git a/src/thing/album.js b/src/thing/album.js
index e99cfc36..8a9fde2c 100644
--- a/src/thing/album.js
+++ b/src/thing/album.js
@@ -1,62 +1,252 @@
+import CacheableObject from './cacheable-object.js';
 import Thing from './thing.js';
+import find from '../util/find.js';
 
 import {
-    validateDirectory,
-    validateReference
-} from './structures.js';
+    isBoolean,
+    isColor,
+    isCommentary,
+    isContributionList,
+    isDate,
+    isDimensions,
+    isDirectory,
+    isFileExtension,
+    isName,
+    isURL,
+    isString,
+    validateArrayItems,
+    validateInstanceOf,
+    validateReference,
+    validateReferenceList,
+} from './validators.js';
 
-import {
-    showAggregate,
-    withAggregate
-} from '../util/sugar.js';
+export class TrackGroup extends CacheableObject {
+    static propertyDescriptors = {
+        // Update & expose
 
-export default class Album extends Thing {
-    #directory = null;
-    #tracks = [];
+        name: {
+            flags: {update: true, expose: true},
+            update: {default: 'Unnamed Track Group', validate: isName}
+        },
+
+        color: {
+            flags: {update: true, expose: true},
+            update: {validate: isColor}
+        },
+
+        dateOriginallyReleased: {
+            flags: {update: true, expose: true},
+            update: {validate: isDate}
+        },
+
+        tracksByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: validateReferenceList('track')}
+        },
+
+        isDefaultTrackGroup: {
+            flags: {update: true, expose: true},
+            update: {validate: isBoolean}
+        },
+
+        // Update only
+
+        trackData: {
+            flags: {update: true},
+            update: {validate: validateArrayItems(item => isInstance(item, Track))}
+        },
 
-    static updateError = {
-        directory: Thing.extendPropertyError('directory'),
-        tracks: Thing.extendPropertyError('tracks')
+        // Expose only
+
+        tracks: {
+            flags: {expose: true},
+
+            expose: {
+                dependencies: ['tracksByRef', 'trackData'],
+                compute: ({ tracksByRef, trackData }) => (
+                    tracksByRef.map(ref => find.track(ref, {wikiData: {trackData}})))
+            }
+        }
     };
+}
+
+export default class Album extends Thing {
+    static [Thing.referenceType] = 'album';
+
+    static propertyDescriptors = {
+        // Update & expose
 
-    update(source) {
-        const err = this.constructor.updateError;
+        name: {
+            flags: {update: true, expose: true},
+            update: {default: 'Unnamed Album', validate: isName}
+        },
 
-        withAggregate(({ nest, filter, throws }) => {
+        color: {
+            flags: {update: true, expose: true},
+            update: {validate: isColor}
+        },
 
-            if (source.directory) {
-                nest(throws(err.directory), ({ call }) => {
-                    if (call(validateDirectory, source.directory)) {
-                        this.#directory = source.directory;
-                    }
-                });
+        directory: {
+            flags: {update: true, expose: true},
+            update: {validate: isDirectory},
+            expose: Thing.directoryExpose
+        },
+
+        urls: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateArrayItems(isURL)
             }
+        },
 
-            if (source.tracks)
-                this.#tracks = filter(source.tracks, validateReference('track'), throws(err.tracks));
-        });
-    }
+        date: {
+            flags: {update: true, expose: true},
+            update: {validate: isDate}
+        },
 
-    get directory() { return this.#directory; }
-    get tracks() { return this.#tracks; }
-}
+        coverArtDate: {
+            flags: {update: true, expose: true},
+            update: {validate: isDate}
+        },
 
-const album = new Album();
-
-console.log('tracks (before):', album.tracks);
-
-try {
-    album.update({
-        directory: 'oh yes',
-        tracks: [
-            'lol',
-            123,
-            'track:oh-yeah',
-            'group:what-am-i-doing-here'
-        ]
-    });
-} catch (error) {
-    showAggregate(error);
-}
+        trackArtDate: {
+            flags: {update: true, expose: true},
+            update: {validate: isDate}
+        },
+
+        dateAddedToWiki: {
+            flags: {update: true, expose: true},
+
+            update: {validate: isDate}
+        },
+
+        artistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        coverArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        trackCoverArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        wallpaperArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        bannerArtistContribsByRef: {
+            flags: {update: true, expose: true},
+            update: {validate: isContributionList}
+        },
+
+        groupsByRef: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateReferenceList('group')
+            }
+        },
 
-console.log('tracks (after):', album.tracks);
+        artTagsByRef: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateReferenceList('tag')
+            }
+        },
+
+        trackGroups: {
+            flags: {update: true, expose: true},
+
+            update: {
+                validate: validateArrayItems(validateInstanceOf(TrackGroup))
+            }
+        },
+
+        wallpaperStyle: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        wallpaperFileExtension: {
+            flags: {update: true, expose: true},
+            update: {validate: isFileExtension}
+        },
+
+        bannerStyle: {
+            flags: {update: true, expose: true},
+            update: {validate: isString}
+        },
+
+        bannerFileExtension: {
+            flags: {update: true, expose: true},
+            update: {validate: isFileExtension}
+        },
+
+        bannerDimensions: {
+            flags: {update: true, expose: true},
+            update: {validate: isDimensions}
+        },
+
+        hasTrackArt: {
+            flags: {update: true, expose: true},
+
+            update: {
+                default: true,
+                validate: isBoolean
+            }
+        },
+
+        isMajorRelease: {
+            flags: {update: true, expose: true},
+
+            update: {
+                default: false,
+                validate: isBoolean
+            }
+        },
+
+        isListedOnHomepage: {
+            flags: {update: true, expose: true},
+
+            update: {
+                default: true,
+                validate: isBoolean
+            }
+        },
+
+        commentary: {
+            flags: {update: true, expose: true},
+            update: {validate: isCommentary}
+        },
+
+        // Expose only
+
+        /*
+        tracks: {
+            flags: {expose: true},
+
+            expose: {
+                dependencies: ['trackReferences', 'wikiData'],
+                compute: ({trackReferences, wikiData}) => (
+                    trackReferences.map(ref => find.track(ref, {wikiData})))
+            }
+        },
+        */
+
+        // Update only
+
+        /*
+        wikiData: {
+            flags: {update: true}
+        }
+        */
+    };
+}