diff options
Diffstat (limited to 'src/data/composite/wiki-data')
-rw-r--r-- | src/data/composite/wiki-data/index.js | 1 | ||||
-rw-r--r-- | src/data/composite/wiki-data/withResolvedArtworkReferenceList.js | 125 |
2 files changed, 126 insertions, 0 deletions
diff --git a/src/data/composite/wiki-data/index.js b/src/data/composite/wiki-data/index.js index afd8bdd2..451aa266 100644 --- a/src/data/composite/wiki-data/index.js +++ b/src/data/composite/wiki-data/index.js @@ -14,6 +14,7 @@ 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 withResolvedArtworkReferenceList} from './withResolvedArtworkReferenceList.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/withResolvedArtworkReferenceList.js b/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js new file mode 100644 index 00000000..e9c6a590 --- /dev/null +++ b/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js @@ -0,0 +1,125 @@ +import {input, templateCompositeFrom} from '#composite'; +import {stitchArrays} from '#sugar'; +import {is, isString, optional, validateArrayItems, validateProperties} + from '#validators'; + +import {withFilteredList, withMappedList, withPropertiesFromList} + from '#composite/data'; + +import inputWikiData from './inputWikiData.js'; +import withResolvedReferenceList from './withResolvedReferenceList.js'; + +export default templateCompositeFrom({ + annotation: `withResolvedArtworkReferenceList`, + + inputs: { + list: input({ + validate: + validateArrayItems( + validateProperties({ + reference: isString, + annotation: optional(isString), + })), + + acceptsNull: true, + }), + + data: inputWikiData({allowMixedTypes: false}), + find: input({type: 'function'}), + + notFoundMode: input({ + validate: is('exit', 'filter', 'null'), + defaultValue: 'filter', + }), + }, + + steps: () => [ + withPropertiesFromList({ + list: input('list'), + properties: input.value([ + 'reference', + 'annotation', + ]), + }), + + withResolvedReferenceList({ + list: '#list.reference', + data: input('data'), + find: input('find'), + notFoundMode: input.value('null'), + }), + + { + dependencies: [ + '#resolvedReferenceList', + '#list.annotation', + ], + + compute: (continuation, { + ['#resolvedReferenceList']: thing, + ['#list.annotation']: annotation, + }) => continuation({ + ['#matches']: + stitchArrays({ + thing, + annotation, + }), + }), + }, + + { + 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), + }), + + withFilteredList({ + list: '#matches', + filter: '#mappedList', + }), + + { + dependencies: ['#filteredList'], + compute: (continuation, { + ['#filteredList']: filteredList, + }) => continuation({ + ['#resolvedArtworkReferenceList']: + filteredList, + }), + }, + ], +}) |