From 913f418eadb0b085c805ff1c83b749a0ce620741 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 14 Nov 2024 07:37:14 -0400 Subject: data: annotated artwork references Not used on-site, but this is all coded internally. --- .../wiki-data/withResolvedArtworkReferenceList.js | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 src/data/composite/wiki-data/withResolvedArtworkReferenceList.js (limited to 'src/data/composite/wiki-data/withResolvedArtworkReferenceList.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, + }), + }, + ], +}) -- cgit 1.3.0-6-gf8a5