diff options
Diffstat (limited to 'src/data/composite/wiki-data')
4 files changed, 141 insertions, 104 deletions
diff --git a/src/data/composite/wiki-data/raiseResolvedReferenceList.js b/src/data/composite/wiki-data/raiseResolvedReferenceList.js new file mode 100644 index 00000000..d5980bfe --- /dev/null +++ b/src/data/composite/wiki-data/raiseResolvedReferenceList.js @@ -0,0 +1,98 @@ +// Concludes compositions like withResolvedReferenceList, which share behavior +// in processing the resolved results before continuing further. + +import {input, templateCompositeFrom} from '#composite'; + +import {withFilteredList} from '#composite/data'; + +import inputNotFoundMode from './inputNotFoundMode.js'; + +export default templateCompositeFrom({ + inputs: { + notFoundMode: inputNotFoundMode(), + + results: input({type: 'array'}), + filter: input({type: 'array'}), + + exitValue: input({defaultValue: []}), + + outputs: input.staticValue({type: 'string'}), + }, + + // TODO: Is it even necessary to specify outputs if you're using + // raiseOutputAbove?? + outputs: ({ + [input.staticValue('outputs')]: outputs, + }) => [outputs], + + steps: () => [ + { + dependencies: [ + input('results'), + input('filter'), + input('outputs'), + ], + + compute: (continuation, { + [input('results')]: results, + [input('filter')]: filter, + [input('outputs')]: outputs, + }) => + (filter.every(keep => keep) + ? continuation.raiseOutput({[outputs]: results}) + : continuation()), + }, + + { + dependencies: [ + input('notFoundMode'), + input('exitValue'), + ], + + compute: (continuation, { + [input('notFoundMode')]: notFoundMode, + [input('exitValue')]: exitValue, + }) => + (notFoundMode === 'exit' + ? continuation.exit(exitValue) + : continuation()), + }, + + { + dependencies: [ + input('results'), + input('notFoundMode'), + input('outputs'), + ], + + compute: (continuation, { + [input('results')]: results, + [input('notFoundMode')]: notFoundMode, + [input('outputs')]: outputs, + }) => + (notFoundMode === 'null' + ? continuation.raiseOutput({[outputs]: results}) + : continuation()), + }, + + withFilteredList({ + list: input('results'), + filter: input('filter'), + }), + + { + dependencies: [ + '#filteredList', + input('outputs'), + ], + + compute: (continuation, { + ['#filteredList']: filteredList, + [input('outputs')]: outputs, + }) => continuation({ + [outputs]: + filteredList, + }), + }, + ], +}); diff --git a/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js b/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js index ae1952be..38c65a8d 100644 --- a/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js +++ b/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js @@ -3,11 +3,12 @@ import {stitchArrays} from '#sugar'; import {isString, optional, validateArrayItems, validateProperties} from '#validators'; -import {withFilteredList, withMappedList, withPropertiesFromList} - from '#composite/data'; +import {withAvailabilityFilter} from '#composite/control-flow'; +import {withPropertiesFromList} from '#composite/data'; import inputNotFoundMode from './inputNotFoundMode.js'; import inputWikiData from './inputWikiData.js'; +import raiseResolvedReferenceList from './raiseResolvedReferenceList.js'; import withResolvedReferenceList from './withResolvedReferenceList.js'; export default templateCompositeFrom({ @@ -67,59 +68,15 @@ export default templateCompositeFrom({ }), }, - { - dependencies: ['#matches'], - compute: (continuation, {'#matches': matches}) => - (matches.every(match => match) - ? continuation.raiseOutput({ - ['#resolvedArtworkReferenceList']: - matches, - }) - : continuation()), - }, - - { - dependencies: [input('notFoundMode')], - compute: (continuation, { - [input('notFoundMode')]: notFoundMode, - }) => - (notFoundMode === 'exit' - ? continuation.exit([]) - : continuation()), - }, - - { - dependencies: ['#matches', input('notFoundMode')], - compute: (continuation, { - ['#matches']: matches, - [input('notFoundMode')]: notFoundMode, - }) => - (notFoundMode === 'null' - ? continuation.raiseOutput({ - ['#resolvedArtworkReferenceList']: - matches, - }) - : continuation()), - }, - - withMappedList({ - list: '#resolvedReferenceList', - map: input.value(thing => thing !== null), + withAvailabilityFilter({ + from: '#resolvedReferenceList', }), - withFilteredList({ - list: '#matches', - filter: '#mappedList', + raiseResolvedReferenceList({ + notFoundMode: input('notFoundMode'), + results: '#matches', + filter: '#availabilityFilter', + outputs: input.value('#resolvedArtworkReferenceList'), }), - - { - dependencies: ['#filteredList'], - compute: (continuation, { - ['#filteredList']: filteredList, - }) => continuation({ - ['#resolvedArtworkReferenceList']: - filteredList, - }), - }, ], }) diff --git a/src/data/composite/wiki-data/withResolvedContribs.js b/src/data/composite/wiki-data/withResolvedContribs.js index 764d7770..b4119604 100644 --- a/src/data/composite/wiki-data/withResolvedContribs.js +++ b/src/data/composite/wiki-data/withResolvedContribs.js @@ -5,15 +5,16 @@ // any artist. import {input, templateCompositeFrom} from '#composite'; -import find from '#find'; import {filterMultipleArrays, stitchArrays} from '#sugar'; import thingConstructors from '#things'; import {isContributionList, isDate, isStringNonEmpty} from '#validators'; -import {raiseOutputWithoutDependency} from '#composite/control-flow'; -import {withPropertiesFromList} from '#composite/data'; +import {raiseOutputWithoutDependency, withAvailabilityFilter} + from '#composite/control-flow'; +import {withPropertyFromList, withPropertiesFromList} from '#composite/data'; import inputNotFoundMode from './inputNotFoundMode.js'; +import raiseResolvedReferenceList from './raiseResolvedReferenceList.js'; export default templateCompositeFrom({ annotation: `withResolvedContribs`, @@ -133,16 +134,20 @@ export default templateCompositeFrom({ }), }, - { - dependencies: ['#contributions'], + withPropertyFromList({ + list: '#contributions', + property: input.value('thing'), + }), - compute: (continuation, { - ['#contributions']: contributions, - }) => continuation({ - ['#resolvedContribs']: - contributions - .filter(contrib => contrib.artist), - }), - }, + withAvailabilityFilter({ + from: '#contributions.thing', + }), + + raiseResolvedReferenceList({ + notFoundMode: input('notFoundMode'), + results: '#contributions', + filter: '#availabilityFilter', + outputs: input.value('#resolvedContribs'), + }), ], }); diff --git a/src/data/composite/wiki-data/withResolvedReferenceList.js b/src/data/composite/wiki-data/withResolvedReferenceList.js index f929d400..790a962f 100644 --- a/src/data/composite/wiki-data/withResolvedReferenceList.js +++ b/src/data/composite/wiki-data/withResolvedReferenceList.js @@ -7,11 +7,15 @@ import {input, templateCompositeFrom} from '#composite'; import {isString, validateArrayItems} from '#validators'; -import {exitWithoutDependency, raiseOutputWithoutDependency} - from '#composite/control-flow'; +import { + exitWithoutDependency, + raiseOutputWithoutDependency, + withAvailabilityFilter, +} from '#composite/control-flow'; import inputNotFoundMode from './inputNotFoundMode.js'; import inputWikiData from './inputWikiData.js'; +import raiseResolvedReferenceList from './raiseResolvedReferenceList.js'; export default templateCompositeFrom({ annotation: `withResolvedReferenceList`, @@ -56,42 +60,15 @@ export default templateCompositeFrom({ }), }, - { - dependencies: ['#matches'], - compute: (continuation, {'#matches': matches}) => - (matches.every(match => match) - ? continuation.raiseOutput({ - ['#resolvedReferenceList']: matches, - }) - : continuation()), - }, - - { - dependencies: ['#matches', input('notFoundMode')], - compute(continuation, { - ['#matches']: matches, - [input('notFoundMode')]: notFoundMode, - }) { - switch (notFoundMode) { - case 'exit': - return continuation.exit([]); - - case 'filter': - return continuation.raiseOutput({ - ['#resolvedReferenceList']: - matches.filter(match => match), - }); - - case 'null': - return continuation.raiseOutput({ - ['#resolvedReferenceList']: - matches.map(match => match ?? null), - }); + withAvailabilityFilter({ + from: '#matches', + }), - default: - throw new TypeError(`Expected notFoundMode to be exit, filter, or null`); - } - }, - }, + raiseResolvedReferenceList({ + notFoundMode: input('notFoundMode'), + results: '#matches', + filter: '#availabilityFilter', + outputs: input.value('#resolvedReferenceList'), + }), ], }); |