« get me outta code hell

data: Artwork.{artTags,artistContribs}: inherit from attached - 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>2025-04-22 18:03:53 -0300
committer(quasar) nebula <qznebula@protonmail.com>2025-04-22 18:03:53 -0300
commitb39f8dcaba0b2f0778a2cbb20505b59cb3d3c57e (patch)
treec371953093d373b2cef93286bbdd319978e56461 /src/data
parent35cb9954edae70266dd3b174897648032fa084bc (diff)
data: Artwork.{artTags,artistContribs}: inherit from attached
Diffstat (limited to 'src/data')
-rw-r--r--src/data/composite/data/withPropertyFromObject.js38
-rw-r--r--src/data/composite/things/artwork/index.js2
-rw-r--r--src/data/composite/things/artwork/withContribsFromMainArtwork.js29
-rw-r--r--src/data/composite/things/artwork/withPropertyFromMainArtwork.js100
-rw-r--r--src/data/things/artwork.js22
5 files changed, 170 insertions, 21 deletions
diff --git a/src/data/composite/data/withPropertyFromObject.js b/src/data/composite/data/withPropertyFromObject.js
index 4f240506..7b452b99 100644
--- a/src/data/composite/data/withPropertyFromObject.js
+++ b/src/data/composite/data/withPropertyFromObject.js
@@ -13,6 +13,21 @@
 import CacheableObject from '#cacheable-object';
 import {input, templateCompositeFrom} from '#composite';
 
+function getOutputName({
+  [input.staticDependency('object')]: object,
+  [input.staticValue('property')]: property,
+}) {
+  if (object && property) {
+    if (object.startsWith('#')) {
+      return `${object}.${property}`;
+    } else {
+      return `#${object}.${property}`;
+    }
+  } else {
+    return '#value';
+  }
+}
+
 export default templateCompositeFrom({
   annotation: `withPropertyFromObject`,
 
@@ -22,15 +37,7 @@ export default templateCompositeFrom({
     internal: input({type: 'boolean', defaultValue: false}),
   },
 
-  outputs: ({
-    [input.staticDependency('object')]: object,
-    [input.staticValue('property')]: property,
-  }) =>
-    (object && property
-      ? (object.startsWith('#')
-          ? [`${object}.${property}`]
-          : [`#${object}.${property}`])
-      : ['#value']),
+  outputs: inputs => [getOutputName(inputs)],
 
   steps: () => [
     {
@@ -39,17 +46,8 @@ export default templateCompositeFrom({
         input.staticValue('property'),
       ],
 
-      compute: (continuation, {
-        [input.staticDependency('object')]: object,
-        [input.staticValue('property')]: property,
-      }) => continuation({
-        '#output':
-          (object && property
-            ? (object.startsWith('#')
-                ? `${object}.${property}`
-                : `#${object}.${property}`)
-            : '#value'),
-      }),
+      compute: (continuation, inputs) =>
+        continuation({'#output': getOutputName(inputs)}),
     },
 
     {
diff --git a/src/data/composite/things/artwork/index.js b/src/data/composite/things/artwork/index.js
index e2661b50..5a592777 100644
--- a/src/data/composite/things/artwork/index.js
+++ b/src/data/composite/things/artwork/index.js
@@ -1,2 +1,4 @@
 export {default as withContainingArtworkList} from './withContainingArtworkList.js';
+export {default as withContribsFromMainArtwork} from './withContribsFromMainArtwork.js';
 export {default as withDate} from './withDate.js';
+export {default as withPropertyFromMainArtwork} from './withPropertyFromMainArtwork.js';
diff --git a/src/data/composite/things/artwork/withContribsFromMainArtwork.js b/src/data/composite/things/artwork/withContribsFromMainArtwork.js
new file mode 100644
index 00000000..25616ad6
--- /dev/null
+++ b/src/data/composite/things/artwork/withContribsFromMainArtwork.js
@@ -0,0 +1,29 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withPropertyFromObject} from '#composite/data';
+import {withRecontextualizedContributionList} from '#composite/wiki-data';
+
+import withPropertyFromMainArtwork from './withPropertyFromMainArtwork.js';
+
+export default templateCompositeFrom({
+  annotaion: `withContribsFromMainArtwork`,
+
+  outputs: ['#mainArtwork.artistContribs'],
+
+  steps: () => [
+    withPropertyFromMainArtwork({
+      property: input.value('artistContribs'),
+      onlyIfAttached: input.value(true),
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#mainArtwork.artistContribs',
+      output: input.value({'#mainArtwork.artistContribs': null}),
+    }),
+
+    withRecontextualizedContributionList({
+      list: '#mainArtwork.artistContribs',
+    }),
+  ],
+});
diff --git a/src/data/composite/things/artwork/withPropertyFromMainArtwork.js b/src/data/composite/things/artwork/withPropertyFromMainArtwork.js
new file mode 100644
index 00000000..a0233119
--- /dev/null
+++ b/src/data/composite/things/artwork/withPropertyFromMainArtwork.js
@@ -0,0 +1,100 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {withResultOfAvailabilityCheck} from '#composite/control-flow';
+import {withPropertyFromObject} from '#composite/data';
+
+import withContainingArtworkList from './withContainingArtworkList.js';
+
+function getOutputName({
+  [input.staticValue('property')]: property,
+}) {
+  if (property) {
+    return `#mainArtwork.${property}`;
+  } else {
+    return '#value';
+  }
+}
+
+export default templateCompositeFrom({
+  annotation: `withPropertyFromMainArtwork`,
+
+  inputs: {
+    property: input({type: 'string'}),
+    onlyIfAttached: input({type: 'boolean', defaultValue: false}),
+  },
+
+  outputs: inputs => [getOutputName(inputs)],
+
+  steps: () => [
+    {
+      dependencies: [input.staticValue('property')],
+      compute: (continuation, inputs) =>
+        continuation({'#output': getOutputName(inputs)}),
+    },
+
+    {
+      dependencies: [input('onlyIfAttached'), 'attachAbove', '#output'],
+      compute: (continuation, {
+        [input('onlyIfAttached')]: onlyIfAttached,
+        ['attachAbove']: attachAbove,
+        ['#output']: output,
+      }) =>
+        (onlyIfAttached && attachAbove
+          ? continuation()
+       : onlyIfAttached
+          ? continuation.raiseOutput({[output]: null})
+          : continuation()),
+    },
+
+    withContainingArtworkList(),
+
+    withResultOfAvailabilityCheck({
+      from: '#containingArtworkList',
+    }),
+
+    {
+      dependencies: ['#availability', '#output'],
+      compute: (continuation, {
+        ['#availability']: availability,
+        ['#output']: output,
+      }) =>
+        (availability
+          ? continuation()
+          : continuation.raiseOutput({[output]: null})),
+    },
+
+    {
+      dependencies: ['#containingArtworkList'],
+      compute: (continuation, {
+        ['#containingArtworkList']: list,
+      }) =>
+        continuation({'#mainArtwork': list[0]}),
+    },
+
+    {
+      dependencies: [input.myself(), '#mainArtwork', '#output'],
+      compute: (continuation, {
+        [input.myself()]: myself,
+        ['#mainArtwork']: mainArtwork,
+        ['#output']: output,
+      }) =>
+        (myself === mainArtwork
+          ? continuation.raiseOutput({[output]: null})
+          : continuation()),
+    },
+
+    withPropertyFromObject({
+      object: '#mainArtwork',
+      property: input('property'),
+    }),
+
+    {
+      dependencies: ['#value', '#output'],
+      compute: (continuation, {
+        ['#value']: value,
+        ['#output']: output,
+      }) =>
+        continuation.raiseOutput({[output]: value}),
+    },
+  ],
+});
diff --git a/src/data/things/artwork.js b/src/data/things/artwork.js
index 079eefa4..8c88dea7 100644
--- a/src/data/things/artwork.js
+++ b/src/data/things/artwork.js
@@ -53,7 +53,12 @@ import {
   wikiData,
 } from '#composite/wiki-properties';
 
-import {withContainingArtworkList, withDate} from '#composite/things/artwork';
+import {
+  withContainingArtworkList,
+  withContribsFromMainArtwork,
+  withPropertyFromMainArtwork,
+  withDate,
+} from '#composite/things/artwork';
 
 export class Artwork extends Thing {
   static [Thing.referenceType] = 'artwork';
@@ -173,6 +178,12 @@ export class Artwork extends Thing {
         mode: input.value('empty'),
       }),
 
+      withContribsFromMainArtwork(),
+
+      exposeDependencyOrContinue({
+        dependency: '#mainArtwork.artistContribs',
+      }),
+
       exitWithoutDependency({
         dependency: 'artistContribsFromThingProperty',
         value: input.value([]),
@@ -211,6 +222,15 @@ export class Artwork extends Thing {
         mode: input.value('empty'),
       }),
 
+      withPropertyFromMainArtwork({
+        property: input.value('artTags'),
+        onlyIfAttached: input.value(true),
+      }),
+
+      exposeDependencyOrContinue({
+        dependency: '#mainArtwork.artTags',
+      }),
+
       exitWithoutDependency({
         dependency: 'artTagsFromThingProperty',
         value: input.value([]),