« get me outta code hell

data: transparent basic Contribution objects - 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:
author(quasar) nebula <qznebula@protonmail.com>2024-03-04 13:34:56 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:00 -0300
commit06cf8a27117cf1b77104b75e1e34375f064134ed (patch)
tree7135f458a5f49544521e73b5e9e14169d3272765 /src/data/composite
parent94469a4c77e02a51c3d15cc86a7fc4b3fbf63785 (diff)
data: transparent basic Contribution objects
Diffstat (limited to 'src/data/composite')
-rw-r--r--src/data/composite/things/contribution/index.js1
-rw-r--r--src/data/composite/things/contribution/withContributionArtist.js31
-rw-r--r--src/data/composite/wiki-data/withResolvedContribs.js57
3 files changed, 70 insertions, 19 deletions
diff --git a/src/data/composite/things/contribution/index.js b/src/data/composite/things/contribution/index.js
new file mode 100644
index 00000000..c0506a2b
--- /dev/null
+++ b/src/data/composite/things/contribution/index.js
@@ -0,0 +1 @@
+export {default as withContributionArtist} from './withContributionArtist.js';
diff --git a/src/data/composite/things/contribution/withContributionArtist.js b/src/data/composite/things/contribution/withContributionArtist.js
new file mode 100644
index 00000000..9e588936
--- /dev/null
+++ b/src/data/composite/things/contribution/withContributionArtist.js
@@ -0,0 +1,31 @@
+import {input, templateCompositeFrom} from '#composite';
+import find from '#find';
+
+import {withPropertyFromObject} from '#composite/data';
+import {withResolvedReference} from '#composite/wiki-data';
+
+export default templateCompositeFrom({
+  annotation: `withOwnContributionArtist`,
+
+  inputs: {
+    ref: input({type: 'string'}),
+  },
+
+  outputs: ['#artist'],
+
+  steps: () => [
+    withPropertyFromObject({
+      object: 'thing',
+      property: input.value('artistData'),
+      internal: input.value(true),
+    }),
+
+    withResolvedReference({
+      ref: input('ref'),
+      data: '#thing.artistData',
+      find: input.value(find.artist),
+    }).outputs({
+      '#resolvedReference': '#artist',
+    }),
+  ],
+});
diff --git a/src/data/composite/wiki-data/withResolvedContribs.js b/src/data/composite/wiki-data/withResolvedContribs.js
index 95266382..7ff7b1bc 100644
--- a/src/data/composite/wiki-data/withResolvedContribs.js
+++ b/src/data/composite/wiki-data/withResolvedContribs.js
@@ -7,17 +7,11 @@
 import {input, templateCompositeFrom} from '#composite';
 import find from '#find';
 import {filterMultipleArrays, stitchArrays} from '#sugar';
+import thingConstructors from '#things';
 import {is, isContributionList} from '#validators';
 
-import {
-  raiseOutputWithoutDependency,
-} from '#composite/control-flow';
-
-import {
-  withPropertiesFromList,
-} from '#composite/data';
-
-import withResolvedReferenceList from './withResolvedReferenceList.js';
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withPropertiesFromList} from '#composite/data';
 
 export default templateCompositeFrom({
   annotation: `withResolvedContribs`,
@@ -51,15 +45,6 @@ export default templateCompositeFrom({
       prefix: input.value('#contribs'),
     }),
 
-    withResolvedReferenceList({
-      list: '#contribs.artist',
-      data: 'artistData',
-      find: input.value(find.artist),
-      notFoundMode: input('notFoundMode'),
-    }).outputs({
-      ['#resolvedReferenceList']: '#contribs.artist',
-    }),
-
     {
       dependencies: ['#contribs.artist', '#contribs.annotation'],
 
@@ -68,11 +53,45 @@ export default templateCompositeFrom({
         ['#contribs.annotation']: annotation,
       }) {
         filterMultipleArrays(artist, annotation, (artist, _annotation) => artist);
+
         return continuation({
-          ['#resolvedContribs']:
+          ['#details']:
             stitchArrays({artist, annotation}),
         });
       },
     },
+
+    {
+      dependencies: ['#details', input.myself()],
+
+      compute: (continuation, {
+        ['#details']: details,
+        [input.myself()]: myself,
+      }) => continuation({
+        ['#contributions']:
+          details.map(details => {
+            const contrib = new thingConstructors.Contribution();
+
+            Object.assign(contrib, {
+              ...details,
+              thing: myself,
+            });
+
+            return contrib;
+          }),
+      }),
+    },
+
+    {
+      dependencies: ['#contributions'],
+
+      compute: (continuation, {
+        ['#contributions']: contributions,
+      }) => continuation({
+        ['#resolvedContribs']:
+          contributions
+            .filter(contrib => contrib.artist),
+      }),
+    },
   ],
 });