« get me outta code hell

data: annotated artwork references - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-14 07:37:14 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-14 07:37:14 -0400
commit913f418eadb0b085c805ff1c83b749a0ce620741 (patch)
tree6d369056d724552ac5191930ae87c05b93ee64fc /src/data/composite/wiki-data/withResolvedArtworkReferenceList.js
parentdb0fd78ca60fc695f87d1f3adf53967bdae2796f (diff)
data: annotated artwork references
Not used on-site, but this is all coded internally.
Diffstat (limited to 'src/data/composite/wiki-data/withResolvedArtworkReferenceList.js')
-rw-r--r--src/data/composite/wiki-data/withResolvedArtworkReferenceList.js125
1 files changed, 125 insertions, 0 deletions
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,
+      }),
+    },
+  ],
+})