« get me outta code hell

data: Track: chop withMainRelease - 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>2025-11-25 15:38:49 -0400
committer(quasar) nebula <qznebula@protonmail.com>2025-11-25 15:38:49 -0400
commite0ed41638ac5f76968499a16628f7054eae11158 (patch)
tree3771f13d308a3cdac56c347d5c3ea6cd8f90a079 /src
parente4125608ed4f88ba3115ffc888035922c798705c (diff)
data: Track: chop withMainRelease
Diffstat (limited to 'src')
-rw-r--r--src/data/composite/things/track/index.js1
-rw-r--r--src/data/composite/things/track/withMainRelease.js137
-rw-r--r--src/data/composite/things/track/withMainReleaseTrack.js14
-rw-r--r--src/data/things/track.js91
4 files changed, 89 insertions, 154 deletions
diff --git a/src/data/composite/things/track/index.js b/src/data/composite/things/track/index.js
index 1a696b1b..20bc3ff2 100644
--- a/src/data/composite/things/track/index.js
+++ b/src/data/composite/things/track/index.js
@@ -4,7 +4,6 @@ export {default as inheritContributionListFromMainRelease} from './inheritContri
 export {default as inheritFromMainRelease} from './inheritFromMainRelease.js';
 export {default as withAllReleases} from './withAllReleases.js';
 export {default as withDirectorySuffix} from './withDirectorySuffix.js';
-export {default as withMainRelease} from './withMainRelease.js';
 export {default as withMainReleaseTrack} from './withMainReleaseTrack.js';
 export {default as withOtherReleases} from './withOtherReleases.js';
 export {default as withPropertyFromAlbum} from './withPropertyFromAlbum.js';
diff --git a/src/data/composite/things/track/withMainRelease.js b/src/data/composite/things/track/withMainRelease.js
deleted file mode 100644
index fb1342ec..00000000
--- a/src/data/composite/things/track/withMainRelease.js
+++ /dev/null
@@ -1,137 +0,0 @@
-// Resolves this track's `mainRelease` reference, using weird-ass atypical
-// machinery that operates on soupyFind and does not operate on findMixed,
-// let alone a prim and proper standalone find spec.
-//
-// Raises null only if there is no `mainRelease` reference provided at all.
-// This will early exit (with notFoundValue) if the reference doesn't resolve.
-//
-
-import {input, templateCompositeFrom} from '#composite';
-
-import {raiseOutputWithoutDependency} from '#composite/control-flow';
-import {withPropertyFromObject} from '#composite/data';
-import {withResolvedReference} from '#composite/wiki-data';
-import {soupyFind} from '#composite/wiki-properties';
-
-export default templateCompositeFrom({
-  annotation: `withMainRelease`,
-
-  inputs: {
-    from: input({
-      defaultDependency: '_mainRelease',
-      acceptsNull: true,
-    }),
-
-    notFoundValue: input({defaultValue: null}),
-  },
-
-  outputs: ['#mainRelease'],
-
-  steps: () => [
-    raiseOutputWithoutDependency({
-      dependency: input('from'),
-      output: input.value({'#mainRelease': null}),
-    }),
-
-    {
-      dependencies: [input('from'), 'name'],
-      compute: (continuation, {
-        [input('from')]: ref,
-        ['name']: ownName,
-      }) =>
-        (ref === 'same name single'
-          ? continuation({
-              ['#albumOrTrackReference']: null,
-              ['#sameNameSingleReference']: ownName,
-            })
-          : continuation({
-              ['#albumOrTrackReference']: ref,
-              ['#sameNameSingleReference']: null,
-            })),
-    },
-
-    withResolvedReference({
-      ref: '#albumOrTrackReference',
-      find: soupyFind.input('trackMainReleasesOnly'),
-    }).outputs({
-      '#resolvedReference': '#matchingTrack',
-    }),
-
-    withResolvedReference({
-      ref: '#albumOrTrackReference',
-      find: soupyFind.input('album'),
-    }).outputs({
-      '#resolvedReference': '#matchingAlbum',
-    }),
-
-    withResolvedReference({
-      ref: '#sameNameSingleReference',
-      find: soupyFind.input('albumSinglesOnly'),
-      findOptions: input.value({
-        fuzz: {
-          capitalization: true,
-          kebab: true,
-        },
-      }),
-    }).outputs({
-      '#resolvedReference': '#sameNameSingle',
-    }),
-
-    {
-      dependencies: ['#sameNameSingle'],
-      compute: (continuation, {
-        ['#sameNameSingle']: sameNameSingle,
-      }) =>
-        (sameNameSingle
-          ? continuation.raiseOutput({
-              ['#mainRelease']:
-                sameNameSingle,
-            })
-          : continuation()),
-    },
-
-    {
-      dependencies: [
-        '#matchingTrack',
-        '#matchingAlbum',
-        input('notFoundValue'),
-      ],
-
-      compute: (continuation, {
-        ['#matchingTrack']: matchingTrack,
-        ['#matchingAlbum']: matchingAlbum,
-        [input('notFoundValue')]: notFoundValue,
-      }) =>
-        (matchingTrack && matchingAlbum
-          ? continuation()
-       : matchingTrack ?? matchingAlbum
-          ? continuation.raiseOutput({
-              ['#mainRelease']:
-                matchingTrack ?? matchingAlbum,
-            })
-          : continuation.exit(notFoundValue)),
-    },
-
-    withPropertyFromObject({
-      object: '#matchingAlbum',
-      property: input.value('tracks'),
-    }),
-
-    {
-      dependencies: [
-        '#matchingAlbum.tracks',
-        '#matchingTrack',
-        input('notFoundValue'),
-      ],
-
-      compute: (continuation, {
-        ['#matchingAlbum.tracks']: matchingAlbumTracks,
-        ['#matchingTrack']: matchingTrack,
-        [input('notFoundValue')]: notFoundValue,
-      }) =>
-        (matchingAlbumTracks.includes(matchingTrack)
-          ? continuation.raiseOutput({'#mainRelease': matchingTrack})
-          : continuation.exit(notFoundValue)),
-    },
-  ],
-});
diff --git a/src/data/composite/things/track/withMainReleaseTrack.js b/src/data/composite/things/track/withMainReleaseTrack.js
index 70d55dd4..c92c2246 100644
--- a/src/data/composite/things/track/withMainReleaseTrack.js
+++ b/src/data/composite/things/track/withMainReleaseTrack.js
@@ -21,8 +21,6 @@ import {
   withPropertyFromObject,
 } from '#composite/data';
 
-import withMainRelease from './withMainRelease.js';
-
 export default templateCompositeFrom({
   annotation: `withMainReleaseTrack`,
 
@@ -58,23 +56,21 @@ export default templateCompositeFrom({
             })),
     },
 
-    withMainRelease(),
-
     exitWithoutDependency({
-      dependency: '#mainRelease',
+      dependency: 'mainRelease',
       value: input('notFoundValue'),
     }),
 
     withPropertyFromObject({
-      object: '#mainRelease',
+      object: 'mainRelease',
       property: input.value('isTrack'),
     }),
 
     {
-      dependencies: ['#mainRelease', '#mainRelease.isTrack'],
+      dependencies: ['mainRelease', '#mainRelease.isTrack'],
 
       compute: (continuation, {
-        ['#mainRelease']: mainRelease,
+        ['mainRelease']: mainRelease,
         ['#mainRelease.isTrack']: mainReleaseIsTrack,
       }) =>
         (mainReleaseIsTrack
@@ -113,7 +109,7 @@ export default templateCompositeFrom({
     },
 
     withPropertyFromObject({
-      object: '#mainRelease',
+      object: 'mainRelease',
       property: input.value('tracks'),
     }),
 
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 8ae4864d..7712d6c7 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -32,6 +32,7 @@ import {
 
 import {
   exitWithoutDependency,
+  exitWithoutUpdateValue,
   exposeConstant,
   exposeDependency,
   exposeDependencyOrContinue,
@@ -51,6 +52,7 @@ import {
   withRecontextualizedContributionList,
   withRedatedContributionList,
   withResolvedContribs,
+  withResolvedReference,
 } from '#composite/wiki-data';
 
 import {
@@ -83,7 +85,6 @@ import {
   inheritFromMainRelease,
   withAllReleases,
   withDirectorySuffix,
-  withMainRelease,
   withMainReleaseTrack,
   withOtherReleases,
   withPropertyFromAlbum,
@@ -168,16 +169,92 @@ export class Track extends Thing {
     // whether or not a matching track is found on a provided album, for
     // example. When presenting or processing, read `mainReleaseTrack`.
     mainRelease: [
-      withMainRelease({
-        from: input.updateValue({
-          validate:
-            validateReference(['album', 'track']),
+      exitWithoutUpdateValue({
+        validate: input.value(
+          validateReference(['album', 'track'])),
+      }),
+
+      {
+        dependencies: ['name'],
+        transform: (ref, continuation, {name: ownName}) =>
+          (ref === 'same name single'
+            ? continuation(ref, {
+                ['#albumOrTrackReference']: null,
+                ['#sameNameSingleReference']: ownName,
+              })
+            : continuation(ref, {
+                ['#albumOrTrackReference']: ref,
+                ['#sameNameSingleReference']: null,
+              })),
+      },
+
+      withResolvedReference({
+        ref: '#albumOrTrackReference',
+        find: soupyFind.input('trackMainReleasesOnly'),
+      }).outputs({
+        '#resolvedReference': '#matchingTrack',
+      }),
+
+      withResolvedReference({
+        ref: '#albumOrTrackReference',
+        find: soupyFind.input('album'),
+      }).outputs({
+        '#resolvedReference': '#matchingAlbum',
+      }),
+
+      withResolvedReference({
+        ref: '#sameNameSingleReference',
+        find: soupyFind.input('albumSinglesOnly'),
+        findOptions: input.value({
+          fuzz: {
+            capitalization: true,
+            kebab: true,
+          },
         }),
+      }).outputs({
+        '#resolvedReference': '#sameNameSingle',
       }),
 
-      exposeDependency({
-        dependency: '#mainRelease',
+      exposeDependencyOrContinue({
+        dependency: '#sameNameSingle',
+      }),
+
+      {
+        dependencies: [
+          '#matchingTrack',
+          '#matchingAlbum',
+        ],
+
+        compute: (continuation, {
+          ['#matchingTrack']: matchingTrack,
+          ['#matchingAlbum']: matchingAlbum,
+        }) =>
+          (matchingTrack && matchingAlbum
+            ? continuation()
+         : matchingTrack ?? matchingAlbum
+            ? matchingTrack ?? matchingAlbum
+            : null),
+      },
+
+      withPropertyFromObject({
+        object: '#matchingAlbum',
+        property: input.value('tracks'),
       }),
+
+      {
+        dependencies: [
+          '#matchingAlbum.tracks',
+          '#matchingTrack',
+        ],
+
+        compute: ({
+          ['#matchingAlbum.tracks']: matchingAlbumTracks,
+          ['#matchingTrack']: matchingTrack,
+        }) =>
+          (matchingAlbumTracks.includes(matchingTrack)
+            ? matchingTrack
+            : null),
+      },
     ],
 
     bandcampTrackIdentifier: simpleString(),