« get me outta code hell

data: individual custom additional name list props - 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>2023-12-03 13:26:52 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-12-03 13:26:52 -0400
commit4ba84964a90ec93d6d30d577e9e00c3e5b4fca83 (patch)
treeb9d603370471360f62e43e9dfecf9c64c07b3d99 /src/data/composite
parent5c1d9fb97b8ecc61c0343d6eee63a735c34e53c9 (diff)
data: individual custom additional name list props
Diffstat (limited to 'src/data/composite')
-rw-r--r--src/data/composite/things/track/index.js5
-rw-r--r--src/data/composite/things/track/inferredAdditionalNameList.js67
-rw-r--r--src/data/composite/things/track/sharedAdditionalNameList.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/composite/wiki-properties/additionalNameList.js1
6 files changed, 108 insertions, 129 deletions
diff --git a/src/data/composite/things/track/index.js b/src/data/composite/things/track/index.js
index b5f1e3e2..cc723a24 100644
--- a/src/data/composite/things/track/index.js
+++ b/src/data/composite/things/track/index.js
@@ -1,12 +1,11 @@
 export {default as exitWithoutUniqueCoverArt} from './exitWithoutUniqueCoverArt.js';
+export {default as inferredAdditionalNameList} from './inferredAdditionalNameList.js';
 export {default as inheritFromOriginalRelease} from './inheritFromOriginalRelease.js';
-export {default as trackAdditionalNameList} from './trackAdditionalNameList.js';
+export {default as sharedAdditionalNameList} from './sharedAdditionalNameList.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/inferredAdditionalNameList.js b/src/data/composite/things/track/inferredAdditionalNameList.js
new file mode 100644
index 00000000..9cf158c6
--- /dev/null
+++ b/src/data/composite/things/track/inferredAdditionalNameList.js
@@ -0,0 +1,67 @@
+// Infers additional name entries from other releases that were titled
+// differently; the corresponding releases are stored in eacn entry's "from"
+// array, which will include multiple items, if more than one other release
+// shares the same name differing from this one's.
+
+import {input, templateCompositeFrom} from '#composite';
+import {chunkByProperties} from '#wiki-data';
+
+import {exitWithoutDependency} from '#composite/control-flow';
+import {withFilteredList, withPropertyFromList} from '#composite/data';
+import {withThingsSortedAlphabetically} from '#composite/wiki-data';
+
+import withOtherReleases from './withOtherReleases.js';
+
+export default templateCompositeFrom({
+  annotation: `inferredAdditionalNameList`,
+
+  compose: false,
+
+  steps: () => [
+    withOtherReleases(),
+
+    exitWithoutDependency({
+      dependency: '#otherReleases',
+      mode: input.value('empty'),
+      value: input.value([]),
+    }),
+
+    withPropertyFromList({
+      list: '#otherReleases',
+      property: input.value('name'),
+    }),
+
+    {
+      dependencies: ['#otherReleases.name', 'name'],
+      compute: (continuation, {
+        ['#otherReleases.name']: releaseNames,
+        ['name']: ownName,
+      }) => continuation({
+        ['#nameFilter']:
+          releaseNames.map(name => name !== ownName),
+      }),
+    },
+
+    withFilteredList({
+      list: '#otherReleases',
+      filter: '#nameFilter',
+    }).outputs({
+      '#filteredList': '#differentlyNamedReleases',
+    }),
+
+    withThingsSortedAlphabetically({
+      things: '#differentlyNamedReleases',
+    }).outputs({
+      '#sortedThings': '#differentlyNamedReleases',
+    }),
+
+    {
+      dependencies: ['#differentlyNamedReleases'],
+      compute: ({
+        ['#differentlyNamedReleases']: releases,
+      }) =>
+        chunkByProperties(releases, ['name'])
+          .map(({name, chunk}) => ({name, from: chunk})),
+    },
+  ],
+});
diff --git a/src/data/composite/things/track/sharedAdditionalNameList.js b/src/data/composite/things/track/sharedAdditionalNameList.js
new file mode 100644
index 00000000..1806ec80
--- /dev/null
+++ b/src/data/composite/things/track/sharedAdditionalNameList.js
@@ -0,0 +1,38 @@
+// Compiles additional names directly provided by other releases.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {exitWithoutDependency, exposeDependency}
+  from '#composite/control-flow';
+import {withFlattenedList, withPropertyFromList} from '#composite/data';
+
+import withOtherReleases from './withOtherReleases.js';
+
+export default templateCompositeFrom({
+  annotation: `sharedAdditionalNameList`,
+
+  compose: false,
+
+  steps: () => [
+    withOtherReleases(),
+
+    exitWithoutDependency({
+      dependency: '#otherReleases',
+      mode: input.value('empty'),
+      value: input.value([]),
+    }),
+
+    withPropertyFromList({
+      list: '#otherReleases',
+      property: input.value('additionalNames'),
+    }),
+
+    withFlattenedList({
+      list: '#otherReleases.additionalNames',
+    }),
+
+    exposeDependency({
+      dependency: '#flattenedList',
+    }),
+  ],
+});
diff --git a/src/data/composite/things/track/withInferredAdditionalNames.js b/src/data/composite/things/track/withInferredAdditionalNames.js
deleted file mode 100644
index 659d6b8f..00000000
--- a/src/data/composite/things/track/withInferredAdditionalNames.js
+++ /dev/null
@@ -1,80 +0,0 @@
-// 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
deleted file mode 100644
index bba675c9..00000000
--- a/src/data/composite/things/track/withSharedAdditionalNames.js
+++ /dev/null
@@ -1,46 +0,0 @@
-// 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({'#sharedAdditionalNames': []}),
-    }),
-
-    // 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/composite/wiki-properties/additionalNameList.js b/src/data/composite/wiki-properties/additionalNameList.js
index d1302224..c5971d4a 100644
--- a/src/data/composite/wiki-properties/additionalNameList.js
+++ b/src/data/composite/wiki-properties/additionalNameList.js
@@ -9,5 +9,6 @@ export default function() {
   return {
     flags: {update: true, expose: true},
     update: {validate: isAdditionalNameList},
+    expose: {transform: value => value ?? []},
   };
 }