diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-04-06 15:47:33 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-04-10 16:02:40 -0300 |
commit | ab4d203c7df2e69e331bf4c0ae4522ddee5918cb (patch) | |
tree | 32b757ee9e54a674ca3260155e783f9f2c3c705e /src/data | |
parent | e8670dd43d70ef91df6dc1164d11397de639e3b8 (diff) |
data: constitutibleArtworkList.fromYAMLFieldSpec
Also file extension property passing.
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/composite/wiki-data/withConstitutedArtwork.js | 25 | ||||
-rw-r--r-- | src/data/composite/wiki-properties/constitutibleArtworkList.js | 74 | ||||
-rw-r--r-- | src/data/things/album.js | 16 | ||||
-rw-r--r-- | src/data/things/track.js | 14 | ||||
-rw-r--r-- | src/data/yaml.js | 23 |
5 files changed, 84 insertions, 68 deletions
diff --git a/src/data/composite/wiki-data/withConstitutedArtwork.js b/src/data/composite/wiki-data/withConstitutedArtwork.js index 9843588a..3eb3c893 100644 --- a/src/data/composite/wiki-data/withConstitutedArtwork.js +++ b/src/data/composite/wiki-data/withConstitutedArtwork.js @@ -6,9 +6,10 @@ export default templateCompositeFrom({ annotation: `withConstitutedArtwork`, inputs: { - contribsProperty: input({type: 'string'}), - artistProperty: input({type: 'string'}), - dateProperty: input({type: 'string'}), + fileExtensionFromThingProperty: input({type: 'string'}), + artistContribsFromThingProperty: input({type: 'string'}), + artistContribsArtistProperty: input({type: 'string'}), + dateFromThingProperty: input({type: 'string'}), }, outputs: ['#constitutedArtwork'], @@ -19,24 +20,30 @@ export default templateCompositeFrom({ input.myself(), 'find', - input('contribsProperty'), - input('dateProperty'), + input('fileExtensionFromThingProperty'), + input('artistContribsFromThingProperty'), + input('artistContribsArtistProperty'), + input('dateFromThingProperty'), ], compute: (continuation, { [input.myself()]: myself, ['find']: find, - [input('contribsProperty')]: contribsProperty, - [input('dateProperty')]: dateProperty, + [input('fileExtensionFromThingProperty')]: fileExtensionFromThingProperty, + [input('artistContribsFromThingProperty')]: artistContribsFromThingProperty, + [input('artistContribsArtistProperty')]: artistContribsArtistProperty, + [input('dateFromThingProperty')]: dateFromThingProperty, }) => continuation({ ['#constitutedArtwork']: Object.assign(new thingConstructors.Artwork, { thing: myself, find: find, - artistContribsFromThingProperty: contribsProperty, - dateFromThingProperty: dateProperty, + fileExtensionFromThingProperty, + artistContribsFromThingProperty, + artistContribsArtistProperty, + dateFromThingProperty, }), }), }, diff --git a/src/data/composite/wiki-properties/constitutibleArtworkList.js b/src/data/composite/wiki-properties/constitutibleArtworkList.js index 01429f03..bc56f887 100644 --- a/src/data/composite/wiki-properties/constitutibleArtworkList.js +++ b/src/data/composite/wiki-properties/constitutibleArtworkList.js @@ -1,29 +1,25 @@ +// This composition does not actually inspect the values of any properties +// specified, so it's not responsible for determining whether a constituted +// artwork should exist at all. + import {input, templateCompositeFrom} from '#composite'; -import {isContributionList, isDate, validateWikiData} from '#validators'; +import {withEntries} from '#sugar'; +import Thing from '#thing'; +import {validateWikiData} from '#validators'; -import {exitWithoutDependency, exposeUpdateValueOrContinue} - from '#composite/control-flow'; +import {exposeUpdateValueOrContinue} from '#composite/control-flow'; import {withConstitutedArtwork} from '#composite/wiki-data'; -export default templateCompositeFrom({ +const template = templateCompositeFrom({ annotation: `constitutibleArtwork`, compose: false, inputs: { - contribs: input.staticDependency({ - validate: isContributionList, - acceptsNull: true, - }), - - date: input.staticDependency({ - validate: isDate, - acceptsNull: true, - }), - - artistProperty: input.staticValue({ - type: 'string', - }), + fileExtensionFromThingProperty: input({type: 'string'}), + artistContribsFromThingProperty: input({type: 'string'}), + artistContribsArtistProperty: input({type: 'string'}), + dateFromThingProperty: input({type: 'string'}), }, steps: () => [ @@ -34,30 +30,11 @@ export default templateCompositeFrom({ })), }), - exitWithoutDependency({ - dependency: input('contribs'), - value: input.value([]), - }), - - { - dependencies: [ - input.staticDependency('contribs'), - input.staticDependency('date'), - ], - - compute: (continuation, { - [input.staticDependency('contribs')]: contribsProperty, - [input.staticDependency('date')]: dateProperty, - }) => continuation({ - ['#contribsProperty']: contribsProperty, - ['#dateProperty']: dateProperty, - }) - }, - withConstitutedArtwork({ - contribsProperty: '#contribsProperty', - artistProperty: input('artistProperty'), - dateProperty: '#dateProperty', + fileExtensionFromThingProperty: input('fileExtensionFromThingProperty'), + artistContribsFromThingProperty: input('artistContribsFromThingProperty'), + artistContribsArtistProperty: input('artistContribsArtistProperty'), + dateFromThingProperty: input('dateFromThingProperty'), }), { @@ -68,3 +45,20 @@ export default templateCompositeFrom({ }, ], }); + +template.fromYAMLFieldSpec = function(field) { + const {[Thing.yamlDocumentSpec]: documentSpec} = this; + + const {provide} = documentSpec.fields[field].transform; + + const inputs = + withEntries(provide, entries => + entries.map(([property, value]) => [ + property, + input.value(value), + ])); + + return template(inputs); +}; + +export default template; diff --git a/src/data/things/album.js b/src/data/things/album.js index df19e817..8f21f622 100644 --- a/src/data/things/album.js +++ b/src/data/things/album.js @@ -159,11 +159,16 @@ export class Album extends Thing { dimensions(), ], - coverArtworks: constitutibleArtworkList({ - contribs: 'coverArtistContribs', - date: 'coverArtDate', - artistProperty: input.value('albumCoverArtistContributions'), - }), + coverArtworks: [ + exitWithoutDependency({ + dependency: 'coverArtistContribs', + mode: input.value('empty'), + value: input.value([]), + }), + + constitutibleArtworkList.fromYAMLFieldSpec + .call(this, 'Cover Artwork'), + ], hasTrackNumbers: flag(true), isListedOnHomepage: flag(true), @@ -471,6 +476,7 @@ export class Album extends Thing { property: 'coverArtworks', transform: parseArtwork({ + fileExtensionFromThingProperty: 'coverArtFileExtension', dateFromThingProperty: 'coverArtDate', artistContribsFromThingProperty: 'coverArtistContribs', artistContribsArtistProperty: 'albumCoverArtistContributions', diff --git a/src/data/things/track.js b/src/data/things/track.js index 95e8e1fc..4d48407b 100644 --- a/src/data/things/track.js +++ b/src/data/things/track.js @@ -309,11 +309,14 @@ export class Track extends Thing { }), ], - trackArtworks: constitutibleArtworkList({ - contribs: 'coverArtistContribs', - date: 'coverArtDate', - artistProperty: input.value('trackCoverArtistContributions'), - }), + trackArtworks: [ + exitWithoutUniqueCoverArt({ + value: input.value([]), + }), + + constitutibleArtworkList.fromYAMLFieldSpec + .call(this, 'Track Artwork'), + ], artTags: [ exitWithoutUniqueCoverArt({ @@ -539,6 +542,7 @@ export class Track extends Thing { property: 'trackArtworks', transform: parseArtwork({ + fileExtensionFromThingProperty: 'coverArtFileExtension', dateFromThingProperty: 'coverArtDate', artistContribsFromThingProperty: 'coverArtistContribs', artistContribsArtistProperty: 'trackCoverArtistContributions', diff --git a/src/data/yaml.js b/src/data/yaml.js index b766e753..006513be 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -790,24 +790,29 @@ export function parseAnnotatedReferences(entries, { } export function parseArtwork({ + fileExtensionFromThingProperty, dateFromThingProperty, artistContribsFromThingProperty, artistContribsArtistProperty, }) { + const provide = { + fileExtensionFromThingProperty, + dateFromThingProperty, + artistContribsFromThingProperty, + artistContribsArtistProperty, + }; + const parseSingleEntry = (entry, {subdoc, Artwork}) => - subdoc(Artwork, entry, { - bindInto: 'thing', - provide: { - dateFromThingProperty, - artistContribsFromThingProperty, - artistContribsArtistProperty, - }, - }); + subdoc(Artwork, entry, {bindInto: 'thing', provide}); - return (value, ...args) => + const transform = (value, ...args) => (Array.isArray(value) ? value.map(entry => parseSingleEntry(entry, ...args)) : [parseSingleEntry(value, ...args)]); + + transform.provide = provide; + + return transform; } // documentModes: Symbols indicating sets of behavior for loading and processing |