« get me outta code hell

album.js « things « data « src - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/album.js
blob: 883081825649f9e435d9c60013bb832bed03a3b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import find from '#find';
import {empty} from '#sugar';
import {isDate, isDimensions, isTrackSectionList} from '#validators';

import Thing, {
  additionalFiles,
  commentary,
  color,
  commentatorArtists,
  contribsPresent,
  contributionList,
  directory,
  fileExtension,
  flag,
  name,
  referenceList,
  simpleDate,
  simpleString,
  urls,
  wikiData,
} from './thing.js';

export class Album extends Thing {
  static [Thing.referenceType] = 'album';

  static [Thing.getPropertyDescriptors] = ({ArtTag, Artist, Group, Track}) => ({
    // Update & expose

    name: name('Unnamed Album'),
    color: color(),
    directory: directory(),
    urls: urls(),

    date: simpleDate(),
    trackArtDate: simpleDate(),
    dateAddedToWiki: simpleDate(),

    coverArtDate: {
      flags: {update: true, expose: true},

      update: {validate: isDate},

      expose: {
        dependencies: ['date', 'coverArtistContribs'],
        transform: (coverArtDate, {coverArtistContribs, date}) =>
          (!empty(coverArtistContribs)
            ? coverArtDate ?? date ?? null
            : null),
      },
    },

    artistContribs: contributionList(),
    coverArtistContribs: contributionList(),
    trackCoverArtistContribs: contributionList(),
    wallpaperArtistContribs: contributionList(),
    bannerArtistContribs: contributionList(),

    groups: referenceList({
      class: Group,
      find: find.group,
      data: 'groupData',
    }),

    artTags: referenceList({
      class: ArtTag,
      find: find.artTag,
      data: 'artTagData',
    }),

    trackSections: {
      flags: {update: true, expose: true},

      update: {
        validate: isTrackSectionList,
      },

      expose: {
        dependencies: ['color', 'trackData'],
        transform(trackSections, {
          color: albumColor,
          trackData,
        }) {
          let startIndex = 0;
          return trackSections?.map(section => ({
            name: section.name ?? null,
            color: section.color ?? albumColor ?? null,
            dateOriginallyReleased: section.dateOriginallyReleased ?? null,
            isDefaultTrackSection: section.isDefaultTrackSection ?? false,

            startIndex: (
              startIndex += section.tracks.length,
              startIndex - section.tracks.length
            ),

            tracks:
              (trackData && section.tracks
                ?.map(ref => find.track(ref, trackData, {mode: 'quiet'}))
                .filter(Boolean)) ??
              [],
          }));
        },
      },
    },

    coverArtFileExtension: fileExtension('jpg'),
    trackCoverArtFileExtension: fileExtension('jpg'),

    wallpaperStyle: simpleString(),
    wallpaperFileExtension: fileExtension('jpg'),

    bannerStyle: simpleString(),
    bannerFileExtension: fileExtension('jpg'),
    bannerDimensions: {
      flags: {update: true, expose: true},
      update: {validate: isDimensions},
    },

    hasTrackNumbers: flag(true),
    isListedOnHomepage: flag(true),
    isListedInGalleries: flag(true),

    commentary: commentary(),
    additionalFiles: additionalFiles(),

    // Update only

    artistData: wikiData(Artist),
    artTagData: wikiData(ArtTag),
    groupData: wikiData(Group),
    trackData: wikiData(Track),

    // Expose only

    commentatorArtists: commentatorArtists(),

    hasCoverArt: contribsPresent('coverArtistContribs'),
    hasWallpaperArt: contribsPresent('wallpaperArtistContribs'),
    hasBannerArt: contribsPresent('bannerArtistContribs'),

    tracks: {
      flags: {expose: true},

      expose: {
        dependencies: ['trackSections', 'trackData'],
        compute: ({trackSections, trackData}) =>
          (trackSections && trackData
            ? trackSections
                .flatMap(section => section.tracks ?? [])
                .map(ref => find.track(ref, trackData, {mode: 'quiet'}))
                .filter(Boolean)
            : []),
      },
    },
  });

  static [Thing.getSerializeDescriptors] = ({
    serialize: S,
  }) => ({
    name: S.id,
    color: S.id,
    directory: S.id,
    urls: S.id,

    date: S.id,
    coverArtDate: S.id,
    trackArtDate: S.id,
    dateAddedToWiki: S.id,

    artistContribs: S.toContribRefs,
    coverArtistContribs: S.toContribRefs,
    trackCoverArtistContribs: S.toContribRefs,
    wallpaperArtistContribs: S.toContribRefs,
    bannerArtistContribs: S.toContribRefs,

    coverArtFileExtension: S.id,
    trackCoverArtFileExtension: S.id,
    wallpaperStyle: S.id,
    wallpaperFileExtension: S.id,
    bannerStyle: S.id,
    bannerFileExtension: S.id,
    bannerDimensions: S.id,

    hasTrackArt: S.id,
    isListedOnHomepage: S.id,

    commentary: S.id,
    additionalFiles: S.id,

    tracks: S.toRefs,
    groups: S.toRefs,
    artTags: S.toRefs,
    commentatorArtists: S.toRefs,
  });
}

export class TrackSectionHelper extends Thing {
  static [Thing.getPropertyDescriptors] = () => ({
    name: name('Unnamed Track Group'),
    color: color(),
    dateOriginallyReleased: simpleDate(),
    isDefaultTrackGroup: flag(false),
  })
}