« get me outta code hell

data: contribution: matchingPresets - 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-03-04 20:31:12 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-06-18 22:56:01 -0300
commit6d0ad85bc718c2429d8dc124bba1329cc9615d12 (patch)
tree37b9b6d62fe2054170604c252e067568d42bc82d /src
parent75505899c70594e250bdcb582fd2f5c40a971639 (diff)
data: contribution: matchingPresets
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/things/contribution/index.js1
-rw-r--r--src/data/composite/things/contribution/withMatchingContributionPresets.js70
-rw-r--r--src/data/composite/wiki-properties/index.js1
-rw-r--r--src/data/composite/wiki-properties/thing.js31
-rw-r--r--src/data/things/album.js6
-rw-r--r--src/data/things/contribution.js9
-rw-r--r--src/data/things/flash.js12
-rw-r--r--src/data/things/track.js15
-rw-r--r--src/data/yaml.js3
9 files changed, 145 insertions, 3 deletions
diff --git a/src/data/composite/things/contribution/index.js b/src/data/composite/things/contribution/index.js
index b06e8677..e912dadc 100644
--- a/src/data/composite/things/contribution/index.js
+++ b/src/data/composite/things/contribution/index.js
@@ -1,2 +1,3 @@
 export {default as withContributionArtist} from './withContributionArtist.js';
 export {default as withContributionContext} from './withContributionContext.js';
+export {default as withMatchingContributionPresets} from './withMatchingContributionPresets.js';
diff --git a/src/data/composite/things/contribution/withMatchingContributionPresets.js b/src/data/composite/things/contribution/withMatchingContributionPresets.js
new file mode 100644
index 00000000..09454164
--- /dev/null
+++ b/src/data/composite/things/contribution/withMatchingContributionPresets.js
@@ -0,0 +1,70 @@
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withPropertyFromObject} from '#composite/data';
+
+import withContributionContext from './withContributionContext.js';
+
+export default templateCompositeFrom({
+  annotation: `withMatchingContributionPresets`,
+
+  outputs: ['#matchingContributionPresets'],
+
+  steps: () => [
+    withPropertyFromObject({
+      object: 'thing',
+      property: input.value('wikiInfo'),
+      internal: input.value(true),
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#thing.wikiInfo',
+      output: input.value({
+        '#matchingContributionPresets': null,
+      }),
+    }),
+
+    withPropertyFromObject({
+      object: '#thing.wikiInfo',
+      property: input.value('contributionPresets'),
+    }).outputs({
+      '#thing.wikiInfo.contributionPresets': '#contributionPresets',
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#contributionPresets',
+      mode: input.value('empty'),
+      output: input.value({
+        '#matchingContributionPresets': [],
+      }),
+    }),
+
+    withContributionContext(),
+
+    {
+      dependencies: [
+        '#contributionPresets',
+        '#contributionTarget',
+        '#contributionProperty',
+        'annotation',
+      ],
+
+      compute: (continuation, {
+        ['#contributionPresets']: presets,
+        ['#contributionTarget']: target,
+        ['#contributionProperty']: property,
+        ['annotation']: annotation,
+      }) => continuation({
+        ['#matchingContributionPresets']:
+          presets
+            .filter(preset =>
+              preset.context[0] === target &&
+              preset.context.slice(1).includes(property) &&
+              // For now, only match if the annotation is a complete match.
+              // Partial matches (e.g. because the contribution includes "two"
+              // annotations, separated by commas) don't count.
+              preset.annotation === annotation),
+      })
+    },
+  ],
+});
diff --git a/src/data/composite/wiki-properties/index.js b/src/data/composite/wiki-properties/index.js
index 89cb6838..5328d17e 100644
--- a/src/data/composite/wiki-properties/index.js
+++ b/src/data/composite/wiki-properties/index.js
@@ -24,5 +24,6 @@ export {default as reverseReferenceList} from './reverseReferenceList.js';
 export {default as simpleDate} from './simpleDate.js';
 export {default as simpleString} from './simpleString.js';
 export {default as singleReference} from './singleReference.js';
+export {default as thing} from './thing.js';
 export {default as urls} from './urls.js';
 export {default as wikiData} from './wikiData.js';
diff --git a/src/data/composite/wiki-properties/thing.js b/src/data/composite/wiki-properties/thing.js
new file mode 100644
index 00000000..5b5d77dd
--- /dev/null
+++ b/src/data/composite/wiki-properties/thing.js
@@ -0,0 +1,31 @@
+// An individual Thing, provided directly rather than by reference.
+
+import {input, templateCompositeFrom} from '#composite';
+import {isThingClass, validateThing} from '#validators';
+
+export default templateCompositeFrom({
+  annotation: `wikiData`,
+
+  compose: false,
+
+  inputs: {
+    class: input.staticValue({
+      validate: isThingClass,
+      defaultValue: null,
+    }),
+  },
+
+  update: ({
+    [input.staticValue('class')]: thingClass,
+  }) => ({
+    validate:
+      validateThing({
+        referenceType:
+          (thingClass
+            ? thingClass[Symbol.for('Thing.referenceType')]
+            : ''),
+      }),
+  }),
+
+  steps: () => [],
+});
diff --git a/src/data/things/album.js b/src/data/things/album.js
index e9f55b2c..d2942fc7 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -37,6 +37,7 @@ import {
   simpleDate,
   simpleString,
   singleReference,
+  thing,
   urls,
   wikiData,
 } from '#composite/wiki-properties';
@@ -53,6 +54,7 @@ export class Album extends Thing {
     Group,
     Track,
     TrackSection,
+    WikiInfo,
   }) => ({
     // Update & expose
 
@@ -173,6 +175,10 @@ export class Album extends Thing {
       class: input.value(TrackSection),
     }),
 
+    wikiInfo: thing({
+      class: input.value(WikiInfo),
+    }),
+
     // Expose only
 
     commentatorArtists: commentatorArtists(),
diff --git a/src/data/things/contribution.js b/src/data/things/contribution.js
index e6479a1e..6b7f050f 100644
--- a/src/data/things/contribution.js
+++ b/src/data/things/contribution.js
@@ -13,6 +13,7 @@ import {withResolvedReference} from '#composite/wiki-data';
 import {
   withContributionArtist,
   withContributionContext,
+  withMatchingContributionPresets,
 } from '#composite/things/contribution';
 
 export class Contribution extends Thing {
@@ -66,6 +67,14 @@ export class Contribution extends Thing {
         }),
       },
     ],
+
+    matchingPresets: [
+      withMatchingContributionPresets(),
+
+      exposeDependency({
+        dependency: '#matchingContributionPresets',
+      }),
+    ],
   });
 
   [inspect.custom](depth, options, inspect) {
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index 7038df86..2c0c1417 100644
--- a/src/data/things/flash.js
+++ b/src/data/things/flash.js
@@ -30,6 +30,7 @@ import {
   name,
   referenceList,
   simpleDate,
+  thing,
   urls,
   wikiData,
 } from '#composite/wiki-properties';
@@ -40,7 +41,12 @@ import {withFlashSide} from '#composite/things/flash-act';
 export class Flash extends Thing {
   static [Thing.referenceType] = 'flash';
 
-  static [Thing.getPropertyDescriptors] = ({Artist, Track, FlashAct}) => ({
+  static [Thing.getPropertyDescriptors] = ({
+    Artist,
+    Track,
+    FlashAct,
+    WikiInfo,
+  }) => ({
     // Update & expose
 
     name: name('Unnamed Flash'),
@@ -118,6 +124,10 @@ export class Flash extends Thing {
       class: input.value(FlashAct),
     }),
 
+    wikiInfo: thing({
+      class: input.value(WikiInfo),
+    }),
+
     // Expose only
 
     commentatorArtists: commentatorArtists(),
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 11e71151..65cc1b68 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -43,8 +43,9 @@ import {
   referenceList,
   reverseReferenceList,
   simpleDate,
-  singleReference,
   simpleString,
+  singleReference,
+  thing,
   urls,
   wikiData,
 } from '#composite/wiki-properties';
@@ -66,7 +67,13 @@ import {
 export class Track extends Thing {
   static [Thing.referenceType] = 'track';
 
-  static [Thing.getPropertyDescriptors] = ({Album, ArtTag, Artist, Flash}) => ({
+  static [Thing.getPropertyDescriptors] = ({
+    Album,
+    ArtTag,
+    Artist,
+    Flash,
+    WikiInfo,
+  }) => ({
     // Update & expose
 
     name: name('Unnamed Track'),
@@ -308,6 +315,10 @@ export class Track extends Thing {
       class: input.value(Track),
     }),
 
+    wikiInfo: thing({
+      class: input.value(WikiInfo),
+    }),
+
     // Expose only
 
     commentatorArtists: commentatorArtists(),
diff --git a/src/data/yaml.js b/src/data/yaml.js
index d3c77b9e..3f096e8a 100644
--- a/src/data/yaml.js
+++ b/src/data/yaml.js
@@ -1149,6 +1149,7 @@ export function linkWikiDataArrays(wikiData) {
       'artTagData',
       'artistData',
       'groupData',
+      'wikiInfo',
     ]],
 
     [wikiData.artTagData, [
@@ -1167,6 +1168,7 @@ export function linkWikiDataArrays(wikiData) {
       'artistData',
       'flashActData',
       'trackData',
+      'wikiInfo',
     ]],
 
     [wikiData.flashActData, [
@@ -1198,6 +1200,7 @@ export function linkWikiDataArrays(wikiData) {
       'artistData',
       'flashData',
       'trackData',
+      'wikiInfo',
     ]],
 
     [[wikiData.wikiInfo], [