« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/composite')
-rw-r--r--src/data/composite/wiki-data/index.js1
-rw-r--r--src/data/composite/wiki-data/withResolvedArtworkReferenceList.js125
-rw-r--r--src/data/composite/wiki-properties/index.js1
-rw-r--r--src/data/composite/wiki-properties/referencedArtworkList.js47
4 files changed, 174 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,
+      }),
+    },
+  ],
+})
diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js
index 32916771..d39bff3a 100644
--- a/src/data/composite/wiki-properties/index.js
+++ b/src/data/composite/wiki-properties/index.js
@@ -19,6 +19,7 @@ export {default as fileExtension} from './fileExtension.js';
 export {default as flag} from './flag.js';
 export {default as name} from './name.js';
 export {default as referenceList} from './referenceList.js';
+export {default as referencedArtworkList} from './referencedArtworkList.js';
 export {default as reverseContributionList} from './reverseContributionList.js';
 export {default as reverseReferenceList} from './reverseReferenceList.js';
 export {default as reverseSingleReferenceList} from './reverseSingleReferenceList.js';
diff --git a/src/data/composite/wiki-properties/referencedArtworkList.js b/src/data/composite/wiki-properties/referencedArtworkList.js
new file mode 100644
index 00000000..bd2962de
--- /dev/null
+++ b/src/data/composite/wiki-properties/referencedArtworkList.js
@@ -0,0 +1,47 @@
+import {input, templateCompositeFrom} from '#composite';
+import {isThingClass, validateAnnotatedReferenceList} from '#validators';
+
+import {exposeDependency} from '#composite/control-flow';
+import {inputWikiData, withResolvedArtworkReferenceList} from '#composite/wiki-data';
+
+export default templateCompositeFrom({
+  annotation: `referencedArtworkList`,
+
+  inputs: {
+    class: input.staticValue({
+      validate: isThingClass,
+      acceptsNull: true,
+      defaultValue: null,
+    }),
+
+    referenceType: input.staticValue({
+      type: 'string',
+      acceptsNull: true,
+      defaultValue: null,
+    }),
+
+    data: inputWikiData({allowMixedTypes: false}),
+    find: input({type: 'function'}),
+  },
+
+  update: ({
+    [input.staticValue('class')]: thingClass,
+    [input.staticValue('referenceType')]: referenceType,
+  }) => ({
+    validate:
+      validateAnnotatedReferenceList(
+        (thingClass
+          ? thingClass[Symbol.for('Thing.referenceType')]
+          : referenceType)),
+  }),
+
+  steps: () => [
+    withResolvedArtworkReferenceList({
+      list: input.updateValue(),
+      data: input('data'),
+      find: input('find'),
+    }),
+
+    exposeDependency({dependency: '#resolvedArtworkReferenceList'}),
+  ],
+});