diff options
| author | (quasar) nebula <qznebula@protonmail.com> | 2025-11-27 21:09:29 -0400 |
|---|---|---|
| committer | (quasar) nebula <qznebula@protonmail.com> | 2025-11-27 21:09:29 -0400 |
| commit | f2161a3fe8ff9b574f53156d08ca7853427be8e4 (patch) | |
| tree | d79e117ddf638729c20c4e4deb847ae5a50d92ca /src/data/composite/wiki-properties/hasArtwork.js | |
| parent | 861810685da73fa9fd6d4a1cb965155c61c99d11 (diff) | |
data: Track, Album: concise-retouch toplevel property descriptors
notably chopped exitWithoutArtwork and contribsPresent, replaced with new hasArtwork and more exitWithoutDependency
Diffstat (limited to 'src/data/composite/wiki-properties/hasArtwork.js')
| -rw-r--r-- | src/data/composite/wiki-properties/hasArtwork.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/data/composite/wiki-properties/hasArtwork.js b/src/data/composite/wiki-properties/hasArtwork.js new file mode 100644 index 00000000..e403a7e2 --- /dev/null +++ b/src/data/composite/wiki-properties/hasArtwork.js @@ -0,0 +1,90 @@ +import {input, templateCompositeFrom, V} from '#composite'; +import {isContributionList, isThing, strictArrayOf} from '#validators'; + +import {fillMissingListItems, withFlattenedList, withPropertyFromList} + from '#composite/data'; + +import { + exitWithoutDependency, + exposeWhetherDependencyAvailable, + withResultOfAvailabilityCheck, +} from '#composite/control-flow'; + +export default templateCompositeFrom({ + annotation: 'hasArtwork', + + inputs: { + contribs: input({ + validate: isContributionList, + defaultValue: null, + }), + + artwork: input({ + validate: isThing, + defaultValue: null, + }), + + artworks: input({ + validate: strictArrayOf(isThing), + defaultValue: null, + }), + }, + + compose: false, + + steps: () => [ + withResultOfAvailabilityCheck({ + from: input('contribs'), + mode: input.value('empty'), + }), + + { + dependencies: ['#availability'], + compute: (continuation, { + ['#availability']: availability, + }) => + (availability + ? true + : continuation()), + }, + + { + dependencies: [input('artwork'), input('artworks')], + compute: (continuation, { + [input('artwork')]: artwork, + [input('artworks')]: artworks, + }) => + continuation({ + ['#artworks']: + (artwork && artworks + ? [artwork, ...artworks] + : artwork + ? [artwork] + : artworks + ? artworks + : []), + }), + }, + + exitWithoutDependency('#artworks', { + value: input.value(false), + mode: input.value('empty'), + }), + + withPropertyFromList('#artworks', { + property: input.value('artistContribs'), + internal: input.value(true), + }), + + // Since we're getting the update value for each artwork's artistContribs, + // it may not be set at all, and in that case won't be exposing as []. + fillMissingListItems('#artworks.artistContribs', V([])), + + withFlattenedList('#artworks.artistContribs'), + + exposeWhetherDependencyAvailable({ + dependency: '#flattenedList', + mode: input.value('empty'), + }), + ], +}); \ No newline at end of file |