« get me outta code hell

data: raiseResolvedReferenceList - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-16 13:29:52 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-17 13:40:00 -0400
commit65ff74446f22976613caf352d42253c8c17e172d (patch)
tree880a7887294f8b791fef87d143ac934117dd04ee /src
parentf2464c6031d83108d12b08df83af2b2f8e426002 (diff)
data: raiseResolvedReferenceList
This commit also implements raiseResolvedReferenceList across
the compositions which have a notFoundMode input. This causes
no semantic changes at all, except that notFoundMode is no
longer ignored(!!) in withResolvedContribs.
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/wiki-data/raiseResolvedReferenceList.js98
-rw-r--r--src/data/composite/wiki-data/withResolvedArtworkReferenceList.js63
-rw-r--r--src/data/composite/wiki-data/withResolvedContribs.js31
-rw-r--r--src/data/composite/wiki-data/withResolvedReferenceList.js53
4 files changed, 141 insertions, 104 deletions
diff --git a/src/data/composite/wiki-data/raiseResolvedReferenceList.js b/src/data/composite/wiki-data/raiseResolvedReferenceList.js
new file mode 100644
index 00000000..d5980bfe
--- /dev/null
+++ b/src/data/composite/wiki-data/raiseResolvedReferenceList.js
@@ -0,0 +1,98 @@
+// Concludes compositions like withResolvedReferenceList, which share behavior
+// in processing the resolved results before continuing further.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {withFilteredList} from '#composite/data';
+
+import inputNotFoundMode from './inputNotFoundMode.js';
+
+export default templateCompositeFrom({
+  inputs: {
+    notFoundMode: inputNotFoundMode(),
+
+    results: input({type: 'array'}),
+    filter: input({type: 'array'}),
+
+    exitValue: input({defaultValue: []}),
+
+    outputs: input.staticValue({type: 'string'}),
+  },
+
+  // TODO: Is it even necessary to specify outputs if you're using
+  // raiseOutputAbove??
+  outputs: ({
+    [input.staticValue('outputs')]: outputs,
+  }) => [outputs],
+
+  steps: () => [
+    {
+      dependencies: [
+        input('results'),
+        input('filter'),
+        input('outputs'),
+      ],
+
+      compute: (continuation, {
+        [input('results')]: results,
+        [input('filter')]: filter,
+        [input('outputs')]: outputs,
+      }) =>
+        (filter.every(keep => keep)
+          ? continuation.raiseOutput({[outputs]: results})
+          : continuation()),
+    },
+
+    {
+      dependencies: [
+        input('notFoundMode'),
+        input('exitValue'),
+      ],
+
+      compute: (continuation, {
+        [input('notFoundMode')]: notFoundMode,
+        [input('exitValue')]: exitValue,
+      }) =>
+        (notFoundMode === 'exit'
+          ? continuation.exit(exitValue)
+          : continuation()),
+    },
+
+    {
+      dependencies: [
+        input('results'),
+        input('notFoundMode'),
+        input('outputs'),
+      ],
+
+      compute: (continuation, {
+        [input('results')]: results,
+        [input('notFoundMode')]: notFoundMode,
+        [input('outputs')]: outputs,
+      }) =>
+        (notFoundMode === 'null'
+          ? continuation.raiseOutput({[outputs]: results})
+          : continuation()),
+    },
+
+    withFilteredList({
+      list: input('results'),
+      filter: input('filter'),
+    }),
+
+    {
+      dependencies: [
+        '#filteredList',
+        input('outputs'),
+      ],
+
+      compute: (continuation, {
+        ['#filteredList']: filteredList,
+        [input('outputs')]: outputs,
+      }) => continuation({
+        [outputs]:
+          filteredList,
+      }),
+    },
+  ],
+});
diff --git a/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js b/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js
index ae1952be..38c65a8d 100644
--- a/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js
+++ b/src/data/composite/wiki-data/withResolvedArtworkReferenceList.js
@@ -3,11 +3,12 @@ import {stitchArrays} from '#sugar';
 import {isString, optional, validateArrayItems, validateProperties}
   from '#validators';
 
-import {withFilteredList, withMappedList, withPropertiesFromList}
-  from '#composite/data';
+import {withAvailabilityFilter} from '#composite/control-flow';
+import {withPropertiesFromList} from '#composite/data';
 
 import inputNotFoundMode from './inputNotFoundMode.js';
 import inputWikiData from './inputWikiData.js';
+import raiseResolvedReferenceList from './raiseResolvedReferenceList.js';
 import withResolvedReferenceList from './withResolvedReferenceList.js';
 
 export default templateCompositeFrom({
@@ -67,59 +68,15 @@ export default templateCompositeFrom({
       }),
     },
 
-    {
-      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),
+    withAvailabilityFilter({
+      from: '#resolvedReferenceList',
     }),
 
-    withFilteredList({
-      list: '#matches',
-      filter: '#mappedList',
+    raiseResolvedReferenceList({
+      notFoundMode: input('notFoundMode'),
+      results: '#matches',
+      filter: '#availabilityFilter',
+      outputs: input.value('#resolvedArtworkReferenceList'),
     }),
-
-    {
-      dependencies: ['#filteredList'],
-      compute: (continuation, {
-        ['#filteredList']: filteredList,
-      }) => continuation({
-        ['#resolvedArtworkReferenceList']:
-          filteredList,
-      }),
-    },
   ],
 })
diff --git a/src/data/composite/wiki-data/withResolvedContribs.js b/src/data/composite/wiki-data/withResolvedContribs.js
index 764d7770..b4119604 100644
--- a/src/data/composite/wiki-data/withResolvedContribs.js
+++ b/src/data/composite/wiki-data/withResolvedContribs.js
@@ -5,15 +5,16 @@
 // any artist.
 
 import {input, templateCompositeFrom} from '#composite';
-import find from '#find';
 import {filterMultipleArrays, stitchArrays} from '#sugar';
 import thingConstructors from '#things';
 import {isContributionList, isDate, isStringNonEmpty} from '#validators';
 
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-import {withPropertiesFromList} from '#composite/data';
+import {raiseOutputWithoutDependency, withAvailabilityFilter}
+  from '#composite/control-flow';
+import {withPropertyFromList, withPropertiesFromList} from '#composite/data';
 
 import inputNotFoundMode from './inputNotFoundMode.js';
+import raiseResolvedReferenceList from './raiseResolvedReferenceList.js';
 
 export default templateCompositeFrom({
   annotation: `withResolvedContribs`,
@@ -133,16 +134,20 @@ export default templateCompositeFrom({
       }),
     },
 
-    {
-      dependencies: ['#contributions'],
+    withPropertyFromList({
+      list: '#contributions',
+      property: input.value('thing'),
+    }),
 
-      compute: (continuation, {
-        ['#contributions']: contributions,
-      }) => continuation({
-        ['#resolvedContribs']:
-          contributions
-            .filter(contrib => contrib.artist),
-      }),
-    },
+    withAvailabilityFilter({
+      from: '#contributions.thing',
+    }),
+
+    raiseResolvedReferenceList({
+      notFoundMode: input('notFoundMode'),
+      results: '#contributions',
+      filter: '#availabilityFilter',
+      outputs: input.value('#resolvedContribs'),
+    }),
   ],
 });
diff --git a/src/data/composite/wiki-data/withResolvedReferenceList.js b/src/data/composite/wiki-data/withResolvedReferenceList.js
index f929d400..790a962f 100644
--- a/src/data/composite/wiki-data/withResolvedReferenceList.js
+++ b/src/data/composite/wiki-data/withResolvedReferenceList.js
@@ -7,11 +7,15 @@
 import {input, templateCompositeFrom} from '#composite';
 import {isString, validateArrayItems} from '#validators';
 
-import {exitWithoutDependency, raiseOutputWithoutDependency}
-  from '#composite/control-flow';
+import {
+  exitWithoutDependency,
+  raiseOutputWithoutDependency,
+  withAvailabilityFilter,
+} from '#composite/control-flow';
 
 import inputNotFoundMode from './inputNotFoundMode.js';
 import inputWikiData from './inputWikiData.js';
+import raiseResolvedReferenceList from './raiseResolvedReferenceList.js';
 
 export default templateCompositeFrom({
   annotation: `withResolvedReferenceList`,
@@ -56,42 +60,15 @@ export default templateCompositeFrom({
         }),
     },
 
-    {
-      dependencies: ['#matches'],
-      compute: (continuation, {'#matches': matches}) =>
-        (matches.every(match => match)
-          ? continuation.raiseOutput({
-              ['#resolvedReferenceList']: matches,
-            })
-          : continuation()),
-    },
-
-    {
-      dependencies: ['#matches', input('notFoundMode')],
-      compute(continuation, {
-        ['#matches']: matches,
-        [input('notFoundMode')]: notFoundMode,
-      }) {
-        switch (notFoundMode) {
-          case 'exit':
-            return continuation.exit([]);
-
-          case 'filter':
-            return continuation.raiseOutput({
-              ['#resolvedReferenceList']:
-                matches.filter(match => match),
-            });
-
-          case 'null':
-            return continuation.raiseOutput({
-              ['#resolvedReferenceList']:
-                matches.map(match => match ?? null),
-            });
+    withAvailabilityFilter({
+      from: '#matches',
+    }),
 
-          default:
-            throw new TypeError(`Expected notFoundMode to be exit, filter, or null`);
-        }
-      },
-    },
+    raiseResolvedReferenceList({
+      notFoundMode: input('notFoundMode'),
+      results: '#matches',
+      filter: '#availabilityFilter',
+      outputs: input.value('#resolvedReferenceList'),
+    }),
   ],
 });