diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-04-08 18:20:58 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-04-10 16:02:42 -0300 |
commit | a0a7f15520b55043d9321a455a49a33558254aa1 (patch) | |
tree | 45100197560ff46178f33b975ef5d287260b0c69 /src/data | |
parent | 670d442f1840586085094c9d59d354f8e3b54549 (diff) |
data: constitutibleArtwork & related infrastructure
Diffstat (limited to 'src/data')
-rw-r--r-- | src/data/composite/wiki-properties/constitutibleArtwork.js | 62 | ||||
-rw-r--r-- | src/data/composite/wiki-properties/constitutibleArtworkList.js | 2 | ||||
-rw-r--r-- | src/data/composite/wiki-properties/index.js | 1 | ||||
-rw-r--r-- | src/data/composite/wiki-properties/soupyReverse.js | 10 | ||||
-rw-r--r-- | src/data/yaml.js | 3 |
5 files changed, 74 insertions, 4 deletions
diff --git a/src/data/composite/wiki-properties/constitutibleArtwork.js b/src/data/composite/wiki-properties/constitutibleArtwork.js new file mode 100644 index 00000000..fc5612ba --- /dev/null +++ b/src/data/composite/wiki-properties/constitutibleArtwork.js @@ -0,0 +1,62 @@ +// 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 {withEntries} from '#sugar'; +import Thing from '#thing'; +import {validateThing} from '#validators'; + +import {exposeDependency, exposeUpdateValueOrContinue} + from '#composite/control-flow'; +import {withConstitutedArtwork} from '#composite/wiki-data'; + +const template = templateCompositeFrom({ + annotation: `constitutibleArtwork`, + + compose: false, + + inputs: { + fileExtensionFromThingProperty: input({type: 'string'}), + artistContribsFromThingProperty: input({type: 'string'}), + artistContribsArtistProperty: input({type: 'string'}), + dateFromThingProperty: input({type: 'string'}), + }, + + steps: () => [ + exposeUpdateValueOrContinue({ + validate: input.value( + validateThing({ + referenceType: 'artwork', + })), + }), + + withConstitutedArtwork({ + fileExtensionFromThingProperty: input('fileExtensionFromThingProperty'), + artistContribsFromThingProperty: input('artistContribsFromThingProperty'), + artistContribsArtistProperty: input('artistContribsArtistProperty'), + dateFromThingProperty: input('dateFromThingProperty'), + }), + + exposeDependency({ + dependency: '#constitutedArtwork', + }), + ], +}); + +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/composite/wiki-properties/constitutibleArtworkList.js b/src/data/composite/wiki-properties/constitutibleArtworkList.js index bc56f887..7fc4bbc0 100644 --- a/src/data/composite/wiki-properties/constitutibleArtworkList.js +++ b/src/data/composite/wiki-properties/constitutibleArtworkList.js @@ -11,7 +11,7 @@ import {exposeUpdateValueOrContinue} from '#composite/control-flow'; import {withConstitutedArtwork} from '#composite/wiki-data'; const template = templateCompositeFrom({ - annotation: `constitutibleArtwork`, + annotation: `constitutibleArtworkList`, compose: false, diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js index d346c7e5..06a627ec 100644 --- a/src/data/composite/wiki-properties/index.js +++ b/src/data/composite/wiki-properties/index.js @@ -9,6 +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'; diff --git a/src/data/composite/wiki-properties/soupyReverse.js b/src/data/composite/wiki-properties/soupyReverse.js index b99c45da..784a66b4 100644 --- a/src/data/composite/wiki-properties/soupyReverse.js +++ b/src/data/composite/wiki-properties/soupyReverse.js @@ -20,12 +20,16 @@ soupyReverse.contributionsBy = }); soupyReverse.artworkContributionsBy = - (bindTo, artworkProperty) => ({ + (bindTo, artworkProperty, {single = false} = {}) => ({ bindTo, referencing: thing => - thing[artworkProperty] - .flatMap(artwork => artwork.artistContribs), + (single + ? (thing[artworkProperty] + ? thing[artworkProperty].artistContribs + : []) + : thing[artworkProperty] + .flatMap(artwork => artwork.artistContribs)), referenced: contrib => [contrib.artist], }); diff --git a/src/data/yaml.js b/src/data/yaml.js index c875c34f..f5944a99 100644 --- a/src/data/yaml.js +++ b/src/data/yaml.js @@ -790,6 +790,7 @@ export function parseAnnotatedReferences(entries, { } export function parseArtwork({ + single = false, fileExtensionFromThingProperty, dateFromThingProperty, artistContribsFromThingProperty, @@ -808,6 +809,8 @@ export function parseArtwork({ const transform = (value, ...args) => (Array.isArray(value) ? value.map(entry => parseSingleEntry(entry, ...args)) + : single + ? parseSingleEntry(value, ...args) : [parseSingleEntry(value, ...args)]); transform.provide = provide; |