« get me outta code hell

data: annotatedReferenceList, reference-list-helpers - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-16 14:07:15 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-17 13:40:00 -0400
commit35137cbe060a2c2ec8fcdc09fc6b6bd9e932239f (patch)
tree90820a774fc87cad75c4967620a1e5301dcc628d /src/data
parentd28e04697429b607c38042ac09418adfceb06baf (diff)
data: annotatedReferenceList, reference-list-helpers
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/wiki-properties/annotatedReferenceList.js39
-rw-r--r--src/data/composite/wiki-properties/helpers/reference-list-helpers.js44
-rw-r--r--src/data/composite/wiki-properties/index.js1
-rw-r--r--src/data/composite/wiki-properties/referenceList.js32
-rw-r--r--src/data/composite/wiki-properties/referencedArtworkList.js15
5 files changed, 97 insertions, 34 deletions
diff --git a/src/data/composite/wiki-properties/annotatedReferenceList.js b/src/data/composite/wiki-properties/annotatedReferenceList.js
new file mode 100644
index 00000000..e8e5ac8c
--- /dev/null
+++ b/src/data/composite/wiki-properties/annotatedReferenceList.js
@@ -0,0 +1,39 @@
+import {input, templateCompositeFrom} from '#composite';
+import find from '#find';
+import {validateAnnotatedReferenceList} from '#validators';
+import {combineWikiDataArrays} from '#wiki-data';
+
+import {exposeDependency} from '#composite/control-flow';
+import {inputWikiData, withResolvedAnnotatedReferenceList}
+  from '#composite/wiki-data';
+
+import {referenceListInputDescriptions, referenceListUpdateDescription}
+  from './helpers/reference-list-helpers.js';
+
+export default templateCompositeFrom({
+  annotation: `referencedArtworkList`,
+
+  compose: false,
+
+  inputs: {
+    ...referenceListInputDescriptions(),
+
+    data: inputWikiData({allowMixedTypes: true}),
+    find: input({type: 'function'}),
+  },
+
+  update:
+    referenceListUpdateDescription({
+      validateReferenceList: validateAnnotatedReferenceList,
+    }),
+
+  steps: () => [
+    withResolvedAnnotatedReferenceList({
+      list: input.updateValue(),
+      data: input('data'),
+      find: input('find'),
+    }),
+
+    exposeDependency({dependency: '#resolvedAnnotatedReferenceList'}),
+  ],
+});
diff --git a/src/data/composite/wiki-properties/helpers/reference-list-helpers.js b/src/data/composite/wiki-properties/helpers/reference-list-helpers.js
new file mode 100644
index 00000000..dfdc6b41
--- /dev/null
+++ b/src/data/composite/wiki-properties/helpers/reference-list-helpers.js
@@ -0,0 +1,44 @@
+import {input} from '#composite';
+import {anyOf, isString, isThingClass, validateArrayItems} from '#validators';
+
+export function referenceListInputDescriptions() {
+  return {
+    class: input.staticValue({
+      validate:
+        anyOf(
+          isThingClass,
+          validateArrayItems(isThingClass)),
+
+      acceptsNull: true,
+      defaultValue: null,
+    }),
+
+    referenceType: input.staticValue({
+      validate:
+        anyOf(
+          isString,
+          validateArrayItems(isString)),
+
+      acceptsNull: true,
+      defaultValue: null,
+    }),
+  };
+}
+
+export function referenceListUpdateDescription({
+  validateReferenceList,
+}) {
+  return ({
+    [input.staticValue('class')]: thingClass,
+    [input.staticValue('referenceType')]: referenceType,
+  }) => ({
+    validate:
+      validateReferenceList(
+        (Array.isArray(thingClass)
+          ? thingClass.map(thingClass =>
+              thingClass[Symbol.for('Thing.referenceType')])
+       : thingClass
+          ? thingClass[Symbol.for('Thing.referenceType')]
+          : referenceType)),
+  });
+}
diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js
index d39bff3a..62d476c6 100644
--- a/src/data/composite/wiki-properties/index.js
+++ b/src/data/composite/wiki-properties/index.js
@@ -5,6 +5,7 @@
 
 export {default as additionalFiles} from './additionalFiles.js';
 export {default as additionalNameList} from './additionalNameList.js';
+export {default as annotatedReferenceList} from './annotatedReferenceList.js';
 export {default as color} from './color.js';
 export {default as commentary} from './commentary.js';
 export {default as commentatorArtists} from './commentatorArtists.js';
diff --git a/src/data/composite/wiki-properties/referenceList.js b/src/data/composite/wiki-properties/referenceList.js
index bf718551..4d4cb106 100644
--- a/src/data/composite/wiki-properties/referenceList.js
+++ b/src/data/composite/wiki-properties/referenceList.js
@@ -8,44 +8,30 @@
 //
 
 import {input, templateCompositeFrom} from '#composite';
-import {isThingClass, validateReferenceList} from '#validators';
+import {validateReferenceList} from '#validators';
 
 import {exposeDependency} from '#composite/control-flow';
 import {inputWikiData, withResolvedReferenceList} from '#composite/wiki-data';
 
+import {referenceListInputDescriptions, referenceListUpdateDescription}
+  from './helpers/reference-list-helpers.js';
+
 export default templateCompositeFrom({
   annotation: `referenceList`,
 
   compose: false,
 
   inputs: {
-    class: input.staticValue({
-      validate: isThingClass,
-      acceptsNull: true,
-      defaultValue: null,
-    }),
-
-    referenceType: input.staticValue({
-      type: 'string',
-      acceptsNull: true,
-      defaultValue: null,
-    }),
+    ...referenceListInputDescriptions(),
 
     data: inputWikiData({allowMixedTypes: true}),
-
     find: input({type: 'function'}),
   },
 
-  update: ({
-    [input.staticValue('class')]: thingClass,
-    [input.staticValue('referenceType')]: referenceType,
-  }) => ({
-    validate:
-      validateReferenceList(
-        (thingClass
-          ? thingClass[Symbol.for('Thing.referenceType')]
-          : referenceType)),
-  }),
+  update:
+    referenceListUpdateDescription({
+      validateReferenceList: validateReferenceList,
+    }),
 
   steps: () => [
     withResolvedReferenceList({
diff --git a/src/data/composite/wiki-properties/referencedArtworkList.js b/src/data/composite/wiki-properties/referencedArtworkList.js
index db4d4637..74790443 100644
--- a/src/data/composite/wiki-properties/referencedArtworkList.js
+++ b/src/data/composite/wiki-properties/referencedArtworkList.js
@@ -1,18 +1,13 @@
 import {input, templateCompositeFrom} from '#composite';
 import find from '#find';
-import {validateAnnotatedReferenceList} from '#validators';
 import {combineWikiDataArrays} from '#wiki-data';
 
-import {exposeDependency} from '#composite/control-flow';
-import {withResolvedAnnotatedReferenceList} from '#composite/wiki-data';
+import annotatedReferenceList from './annotatedReferenceList.js';
 
 export default templateCompositeFrom({
   annotation: `referencedArtworkList`,
 
-  update: {
-    validate:
-      validateAnnotatedReferenceList(['album', 'track']),
-  },
+  compose: false,
 
   steps: () => [
     {
@@ -43,12 +38,10 @@ export default templateCompositeFrom({
       }),
     },
 
-    withResolvedAnnotatedReferenceList({
-      list: input.updateValue(),
+    annotatedReferenceList({
+      referenceType: input.value(['album', 'track']),
       data: '#data',
       find: '#find',
     }),
-
-    exposeDependency({dependency: '#resolvedAnnotatedReferenceList'}),
   ],
 });