« get me outta code hell

data: shared & inferred additional names (for tracks) - 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>2023-11-26 17:32:28 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-26 17:32:28 -0400
commit49537d408b17f7583cd00d0866f5de6797a0591e (patch)
treed7b811bb4c6fc0042ec56847b91ecdebe74ca1f2
parent09f67bdb9438618fe8632d0d8ceda8fee12b8cb7 (diff)
data: shared & inferred additional names (for tracks)
-rw-r--r--src/data/composite/things/track/index.js3
-rw-r--r--src/data/composite/things/track/trackAdditionalNameList.js38
-rw-r--r--src/data/composite/things/track/withInferredAdditionalNames.js80
-rw-r--r--src/data/composite/things/track/withSharedAdditionalNames.js46
-rw-r--r--src/data/things/track.js4
5 files changed, 169 insertions, 2 deletions
diff --git a/src/data/composite/things/track/index.js b/src/data/composite/things/track/index.js
index 3354b1c4..b5f1e3e2 100644
--- a/src/data/composite/things/track/index.js
+++ b/src/data/composite/things/track/index.js
@@ -1,9 +1,12 @@
 export {default as exitWithoutUniqueCoverArt} from './exitWithoutUniqueCoverArt.js';
 export {default as inheritFromOriginalRelease} from './inheritFromOriginalRelease.js';
+export {default as trackAdditionalNameList} from './trackAdditionalNameList.js';
 export {default as trackReverseReferenceList} from './trackReverseReferenceList.js';
 export {default as withAlbum} from './withAlbum.js';
 export {default as withAlwaysReferenceByDirectory} from './withAlwaysReferenceByDirectory.js';
 export {default as withContainingTrackSection} from './withContainingTrackSection.js';
 export {default as withHasUniqueCoverArt} from './withHasUniqueCoverArt.js';
+export {default as withInferredAdditionalNames} from './withInferredAdditionalNames.js';
 export {default as withOtherReleases} from './withOtherReleases.js';
 export {default as withPropertyFromAlbum} from './withPropertyFromAlbum.js';
+export {default as withSharedAdditionalNames} from './withSharedAdditionalNames.js';
diff --git a/src/data/composite/things/track/trackAdditionalNameList.js b/src/data/composite/things/track/trackAdditionalNameList.js
new file mode 100644
index 00000000..65a2263d
--- /dev/null
+++ b/src/data/composite/things/track/trackAdditionalNameList.js
@@ -0,0 +1,38 @@
+// Compiles additional names from various sources.
+
+import {input, templateCompositeFrom} from '#composite';
+import {isAdditionalNameList} from '#validators';
+
+import withInferredAdditionalNames from './withInferredAdditionalNames.js';
+import withSharedAdditionalNames from './withSharedAdditionalNames.js';
+
+export default templateCompositeFrom({
+  annotation: `trackAdditionalNameList`,
+
+  compose: false,
+
+  update: {validate: isAdditionalNameList},
+
+  steps: () => [
+    withInferredAdditionalNames(),
+    withSharedAdditionalNames(),
+
+    {
+      dependencies: [
+        '#inferredAdditionalNames',
+        '#sharedAdditionalNames',
+        input.updateValue(),
+      ],
+
+      compute: ({
+        ['#inferredAdditionalNames']: inferredAdditionalNames,
+        ['#sharedAdditionalNames']: sharedAdditionalNames,
+        [input.updateValue()]: providedAdditionalNames,
+      }) => [
+        ...providedAdditionalNames ?? [],
+        ...sharedAdditionalNames,
+        ...inferredAdditionalNames,
+      ],
+    },
+  ],
+});
diff --git a/src/data/composite/things/track/withInferredAdditionalNames.js b/src/data/composite/things/track/withInferredAdditionalNames.js
new file mode 100644
index 00000000..659d6b8f
--- /dev/null
+++ b/src/data/composite/things/track/withInferredAdditionalNames.js
@@ -0,0 +1,80 @@
+// Infers additional name entries from other releases that were titled
+// differently, linking to the respective release via annotation.
+
+import {input, templateCompositeFrom} from '#composite';
+import {stitchArrays} from '#sugar';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withPropertiesFromList, withPropertyFromList} from '#composite/data';
+
+import withOtherReleases from './withOtherReleases.js';
+
+export default templateCompositeFrom({
+  annotation: `withInferredAdditionalNames`,
+
+  outputs: ['#inferredAdditionalNames'],
+
+  steps: () => [
+    withOtherReleases(),
+
+    raiseOutputWithoutDependency({
+      dependency: '#otherReleases',
+      mode: input.value('empty'),
+      output: input.value({'#inferredAdditionalNames': []}),
+    }),
+
+    {
+      dependencies: ['#otherReleases', 'name'],
+      compute: (continuation, {
+        ['#otherReleases']: otherReleases,
+        ['name']: name,
+      }) => continuation({
+        ['#differentlyNamedReleases']:
+          otherReleases.filter(release => release.name !== name),
+      }),
+    },
+
+    withPropertiesFromList({
+      list: '#differentlyNamedReleases',
+      properties: input.value(['name', 'directory', 'album']),
+    }),
+
+    withPropertyFromList({
+      list: '#differentlyNamedReleases.album',
+      property: input.value('name'),
+    }),
+
+    {
+      dependencies: [
+        '#differentlyNamedReleases.directory',
+        '#differentlyNamedReleases.album.name',
+      ],
+
+      compute: (continuation, {
+        ['#differentlyNamedReleases.directory']: trackDirectories,
+        ['#differentlyNamedReleases.album.name']: albumNames,
+      }) => continuation({
+        ['#annotations']:
+          stitchArrays({
+            trackDirectory: trackDirectories,
+            albumName: albumNames,
+          }).map(({trackDirectory, albumName}) =>
+              `[[track:${trackDirectory}|on ${albumName}]]`)
+      })
+    },
+
+    {
+      dependencies: ['#differentlyNamedReleases.name', '#annotations'],
+      compute: (continuation, {
+        ['#differentlyNamedReleases.name']: names,
+        ['#annotations']: annotations,
+      }) => continuation({
+        ['#inferredAdditionalNames']:
+          stitchArrays({
+            name: names,
+            annotation: annotations,
+          }),
+      }),
+    },
+  ],
+});
diff --git a/src/data/composite/things/track/withSharedAdditionalNames.js b/src/data/composite/things/track/withSharedAdditionalNames.js
new file mode 100644
index 00000000..d205dc89
--- /dev/null
+++ b/src/data/composite/things/track/withSharedAdditionalNames.js
@@ -0,0 +1,46 @@
+// Compiles additional names directly provided on other releases.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
+import {withFlattenedList} from '#composite/data';
+
+import CacheableObject from '#cacheable-object';
+
+import withOtherReleases from './withOtherReleases.js';
+
+export default templateCompositeFrom({
+  annotation: `withSharedAdditionalNames`,
+
+  outputs: ['#sharedAdditionalNames'],
+
+  steps: () => [
+    withOtherReleases(),
+
+    raiseOutputWithoutDependency({
+      dependency: '#otherReleases',
+      mode: input.value('empty'),
+      output: input.value({'#inferredAdditionalNames': []}),
+    }),
+
+    // TODO: Using getUpdateValue is always a bit janky.
+
+    {
+      dependencies: ['#otherReleases'],
+      compute: (continuation, {
+        ['#otherReleases']: otherReleases,
+      }) => continuation({
+        ['#otherReleases.additionalNames']:
+          otherReleases.map(release =>
+            CacheableObject.getUpdateValue(release, 'additionalNames')
+              ?? []),
+      }),
+    },
+
+    withFlattenedList({
+      list: '#otherReleases.additionalNames',
+    }).outputs({
+      '#flattenedList': '#sharedAdditionalNames',
+    }),
+  ],
+});
diff --git a/src/data/things/track.js b/src/data/things/track.js
index f6320677..1f99ef53 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -24,7 +24,6 @@ import {
 
 import {
   additionalFiles,
-  additionalNameList,
   commentary,
   commentatorArtists,
   contributionList,
@@ -44,6 +43,7 @@ import {
 import {
   exitWithoutUniqueCoverArt,
   inheritFromOriginalRelease,
+  trackAdditionalNameList,
   trackReverseReferenceList,
   withAlbum,
   withAlwaysReferenceByDirectory,
@@ -64,7 +64,7 @@ export class Track extends Thing {
 
     name: name('Unnamed Track'),
     directory: directory(),
-    additionalNames: additionalNameList(),
+    additionalNames: trackAdditionalNameList(),
 
     duration: duration(),
     urls: urls(),