diff options
5 files changed, 159 insertions, 4 deletions
diff --git a/src/data/composite/things/track/inheritContributionListFromOriginalRelease.js b/src/data/composite/things/track/inheritContributionListFromOriginalRelease.js index 9e01f119..f4ae3ddb 100644 --- a/src/data/composite/things/track/inheritContributionListFromOriginalRelease.js +++ b/src/data/composite/things/track/inheritContributionListFromOriginalRelease.js @@ -5,8 +5,10 @@ import {input, templateCompositeFrom} from '#composite'; import {exposeDependency, raiseOutputWithoutDependency} from '#composite/control-flow'; -import {withRecontextualizedContributionList} from '#composite/wiki-data'; +import {withRecontextualizedContributionList, withRedatedContributionList} + from '#composite/wiki-data'; +import withDate from './withDate.js'; import withPropertyFromOriginalRelease from './withPropertyFromOriginalRelease.js'; @@ -28,6 +30,13 @@ export default templateCompositeFrom({ list: '#originalValue', }), + withDate(), + + withRedatedContributionList({ + list: '#originalValue', + date: '#date', + }), + exposeDependency({ dependency: '#originalValue', }), diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index b16ef761..5f17ca3a 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -13,6 +13,7 @@ export {default as withDirectory} from './withDirectory.js'; export {default as withDirectoryFromName} from './withDirectoryFromName.js'; export {default as withParsedCommentaryEntries} from './withParsedCommentaryEntries.js'; export {default as withRecontextualizedContributionList} from './withRecontextualizedContributionList.js'; +export {default as withRedatedContributionList} from './withRedatedContributionList.js'; export {default as withResolvedContribs} from './withResolvedContribs.js'; export {default as withResolvedReference} from './withResolvedReference.js'; export {default as withResolvedReferenceList} from './withResolvedReferenceList.js'; diff --git a/src/data/composite/wiki-data/withRecontextualizedContributionList.js b/src/data/composite/wiki-data/withRecontextualizedContributionList.js index 1c86c0ab..06c997b5 100644 --- a/src/data/composite/wiki-data/withRecontextualizedContributionList.js +++ b/src/data/composite/wiki-data/withRecontextualizedContributionList.js @@ -1,6 +1,10 @@ // Clones all the contributions in a list, with thing and thingProperty both -// updated to match the current thing. Overwrite the provided dependency. +// updated to match the current thing. Overwrites the provided dependency. // Doesn't do anything if the provided dependency is null. +// +// See also: +// - withRedatedContributionList +// import {input, templateCompositeFrom} from '#composite'; diff --git a/src/data/composite/wiki-data/withRedatedContributionList.js b/src/data/composite/wiki-data/withRedatedContributionList.js new file mode 100644 index 00000000..12f3e16b --- /dev/null +++ b/src/data/composite/wiki-data/withRedatedContributionList.js @@ -0,0 +1,127 @@ +// Clones all the contributions in a list, with date updated to the provided +// value. Overwrites the provided dependency. Doesn't do anything if the +// provided dependency is null, or the provided date is null. +// +// If 'override' is true (the default), then so long as the provided date has +// a value at all, it's always written onto the (cloned) contributions. +// +// If 'override' is false, and any of the contributions were already dated, +// those will keep their existing dates. +// +// See also: +// - withRecontextualizedContributionList +// + +import {input, templateCompositeFrom} from '#composite'; +import {isDate} from '#validators'; + +import {withMappedList, withPropertyFromList} from '#composite/data'; +import {withClonedThings} from '#composite/wiki-data'; + +export default templateCompositeFrom({ + annotation: `withRedatedContributionList`, + + inputs: { + list: input.staticDependency({ + type: 'array', + acceptsNull: true, + }), + + date: input({ + validate: isDate, + acceptsNull: true, + }), + + override: input({ + type: 'boolean', + defaultValue: true, + }), + }, + + outputs: ({ + [input.staticDependency('list')]: list, + }) => [list], + + steps: () => [ + // TODO: Is raiseOutputWithoutDependency workable here? + // Is it true that not specifying any output wouldn't overwrite + // the provided dependency? + { + dependencies: [ + input.staticDependency('list'), + input('list'), + input('date'), + ], + + compute: (continuation, { + [input.staticDependency('list')]: dependency, + [input('list')]: list, + [input('date')]: date, + }) => + (list && date + ? continuation() + : continuation.raiseOutput({ + [dependency]: list, + })), + }, + + withPropertyFromList({ + list: input('list'), + property: input.value('date'), + }).outputs({ + '#list.date': '#existingDates', + }), + + { + dependencies: [ + input('date'), + input('override'), + '#existingDates', + ], + + compute: (continuation, { + [input('date')]: date, + [input('override')]: override, + '#existingDates': existingDates, + }) => continuation({ + ['#assignmentMap']: + // TODO: Should be mapping over withIndicesFromList + (_, index) => + (!override && existingDates[index] + ? {date: existingDates[index]} + : date + ? {date} + : {}), + }), + }, + + withMappedList({ + list: input('list'), + map: '#assignmentMap', + }).outputs({ + '#mappedList': '#assignment', + }), + + withClonedThings({ + things: input('list'), + assignEach: '#assignment', + }).outputs({ + '#clonedThings': '#newContributions', + }), + + { + dependencies: [ + input.staticDependency('list'), + '#newContributions', + ], + + compute: (continuation, { + [input.staticDependency('list')]: listDependency, + ['#newContributions']: newContributions, + }) => continuation({ + [listDependency]: + newContributions, + }), + }, + ], +}); diff --git a/src/data/things/track.js b/src/data/things/track.js index 5410889f..2f916b1d 100644 --- a/src/data/things/track.js +++ b/src/data/things/track.js @@ -18,8 +18,6 @@ import { } from '#yaml'; import {withPropertyFromObject} from '#composite/data'; -import {withRecontextualizedContributionList, withResolvedContribs} - from '#composite/wiki-data'; import { exitWithoutDependency, @@ -31,6 +29,12 @@ import { } from '#composite/control-flow'; import { + withRecontextualizedContributionList, + withRedatedContributionList, + withResolvedContribs, +} from '#composite/wiki-data'; + +import { additionalFiles, additionalNameList, commentary, @@ -217,6 +221,11 @@ export class Track extends Thing { list: '#album.artistContribs', }), + withRedatedContributionList({ + list: '#album.artistContribs', + date: '#date', + }), + exposeDependency({dependency: '#album.artistContribs'}), ], @@ -261,6 +270,11 @@ export class Track extends Thing { list: '#album.trackCoverArtistContribs', }), + withRedatedContributionList({ + list: '#album.trackCoverArtistContribs', + date: '#trackArtDate', + }), + exposeDependency({dependency: '#album.trackCoverArtistContribs'}), ], |