« get me outta code hell

data: Contribution.artistProperty - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-06-17 21:13:19 -0300
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:14 -0300
commitc6713a38edf084c27a6c58457bf26a23247714ef (patch)
tree1627ff0954916a535a7ff78a76fa60529241784b
parentd4e361e32e144d559b0a20c97025b7581dc4a1d5 (diff)
data: Contribution.artistProperty
-rw-r--r--src/data/composite/wiki-data/withRecontextualizedContributionList.js28
-rw-r--r--src/data/composite/wiki-data/withResolvedContribs.js8
-rw-r--r--src/data/composite/wiki-properties/contributionList.js8
-rw-r--r--src/data/things/contribution.js5
4 files changed, 42 insertions, 7 deletions
diff --git a/src/data/composite/wiki-data/withRecontextualizedContributionList.js b/src/data/composite/wiki-data/withRecontextualizedContributionList.js
index 06c997b5..d2401eac 100644
--- a/src/data/composite/wiki-data/withRecontextualizedContributionList.js
+++ b/src/data/composite/wiki-data/withRecontextualizedContributionList.js
@@ -1,12 +1,14 @@
 // Clones all the contributions in a list, with thing and thingProperty both
 // updated to match the current thing. Overwrites the provided dependency.
-// Doesn't do anything if the provided dependency is null.
+// Optionally updates artistProperty as well. Doesn't do anything if
+// the provided dependency is null.
 //
 // See also:
 //  - withRedatedContributionList
 //
 
 import {input, templateCompositeFrom} from '#composite';
+import {isStringNonEmpty} from '#validators';
 
 import {raiseOutputWithoutDependency} from '#composite/control-flow';
 import {withClonedThings} from '#composite/wiki-data';
@@ -19,6 +21,11 @@ export default templateCompositeFrom({
       type: 'array',
       acceptsNull: true,
     }),
+
+    artistProperty: input({
+      validate: isStringNonEmpty,
+      defaultValue: null,
+    }),
   },
 
   outputs: ({
@@ -47,16 +54,25 @@ export default templateCompositeFrom({
     },
 
     {
-      dependencies: [input.myself(), input.thisProperty()],
+      dependencies: [
+        input.myself(),
+        input.thisProperty(),
+        input('artistProperty'),
+      ],
 
       compute: (continuation, {
         [input.myself()]: myself,
         [input.thisProperty()]: thisProperty,
+        [input('artistProperty')]: artistProperty,
       }) => continuation({
-        ['#assignment']: {
-          thing: myself,
-          thingProperty: thisProperty,
-        },
+        ['#assignment']:
+          Object.assign(
+            {thing: myself},
+            {thingProperty: thisProperty},
+
+            (artistProperty
+              ? {artistProperty}
+              : {})),
       }),
     },
 
diff --git a/src/data/composite/wiki-data/withResolvedContribs.js b/src/data/composite/wiki-data/withResolvedContribs.js
index 23b91691..b5d7255b 100644
--- a/src/data/composite/wiki-data/withResolvedContribs.js
+++ b/src/data/composite/wiki-data/withResolvedContribs.js
@@ -36,6 +36,11 @@ export default templateCompositeFrom({
       validate: isStringNonEmpty,
       defaultValue: null,
     }),
+
+    artistProperty: input({
+      validate: isStringNonEmpty,
+      defaultValue: null,
+    }),
   },
 
   outputs: ['#resolvedContribs'],
@@ -103,12 +108,14 @@ export default templateCompositeFrom({
       dependencies: [
         '#details',
         '#thingProperty',
+        input('artistProperty'),
         input.myself(),
       ],
 
       compute: (continuation, {
         ['#details']: details,
         ['#thingProperty']: thingProperty,
+        [input('artistProperty')]: artistProperty,
         [input.myself()]: myself,
       }) => continuation({
         ['#contributions']:
@@ -119,6 +126,7 @@ export default templateCompositeFrom({
               ...details,
               thing: myself,
               thingProperty: thingProperty,
+              artistProperty: artistProperty,
             });
 
             return contrib;
diff --git a/src/data/composite/wiki-properties/contributionList.js b/src/data/composite/wiki-properties/contributionList.js
index a0e6e52b..d9a6b417 100644
--- a/src/data/composite/wiki-properties/contributionList.js
+++ b/src/data/composite/wiki-properties/contributionList.js
@@ -15,7 +15,7 @@
 //
 
 import {input, templateCompositeFrom} from '#composite';
-import {isContributionList, isDate} from '#validators';
+import {isContributionList, isDate, isStringNonEmpty} from '#validators';
 
 import {exposeConstant, exposeDependencyOrContinue} from '#composite/control-flow';
 import {withResolvedContribs} from '#composite/wiki-data';
@@ -30,6 +30,11 @@ export default templateCompositeFrom({
       validate: isDate,
       acceptsNull: true,
     }),
+
+    artistProperty: input({
+      validate: isStringNonEmpty,
+      defaultValue: null,
+    }),
   },
 
   update: {validate: isContributionList},
@@ -38,6 +43,7 @@ export default templateCompositeFrom({
     withResolvedContribs({
       from: input.updateValue(),
       thingProperty: input.thisProperty(),
+      artistProperty: input('artistProperty'),
       date: input('date'),
     }),
 
diff --git a/src/data/things/contribution.js b/src/data/things/contribution.js
index 9d6a9711..b542dcf3 100644
--- a/src/data/things/contribution.js
+++ b/src/data/things/contribution.js
@@ -35,6 +35,11 @@ export class Contribution extends Thing {
       update: {validate: isStringNonEmpty},
     },
 
+    artistProperty: {
+      flags: {update: true, expose: true},
+      update: {validate: isStringNonEmpty},
+    },
+
     date: simpleDate(),
 
     artist: [