« get me outta code hell

data: Track.suffixDirectory, Album.directorySuffix - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/composite/wiki-data
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2024-11-03 09:59:31 -0400
committer(quasar) nebula <qznebula@protonmail.com>2024-11-14 07:59:22 -0400
commit163c541f4b8244f3c2fd8568ab3ef5cc4ed114a2 (patch)
tree6ce776cc82296686adee36b97346113634c6563c /src/data/composite/wiki-data
parent6ac3a98cb60651b82d2f93a3ced0e56162ea4be7 (diff)
data: Track.suffixDirectory, Album.directorySuffix
Diffstat (limited to 'src/data/composite/wiki-data')
-rw-r--r--src/data/composite/wiki-data/helpers/withSimpleDirectory.js52
-rw-r--r--src/data/composite/wiki-data/withDirectory.js41
2 files changed, 76 insertions, 17 deletions
diff --git a/src/data/composite/wiki-data/helpers/withSimpleDirectory.js b/src/data/composite/wiki-data/helpers/withSimpleDirectory.js
new file mode 100644
index 00000000..08ca3bfc
--- /dev/null
+++ b/src/data/composite/wiki-data/helpers/withSimpleDirectory.js
@@ -0,0 +1,52 @@
+// A "simple" directory, based only on the already-provided directory, if
+// available, or the provided name.
+
+import {input, templateCompositeFrom} from '#composite';
+
+import {isDirectory, isName} from '#validators';
+
+import {withResultOfAvailabilityCheck} from '#composite/control-flow';
+
+import withDirectoryFromName from './withDirectoryFromName.js';
+
+export default templateCompositeFrom({
+  annotation: `withSimpleDirectory`,
+
+  inputs: {
+    directory: input({
+      validate: isDirectory,
+      defaultDependency: 'directory',
+      acceptsNull: true,
+    }),
+
+    name: input({
+      validate: isName,
+      acceptsNull: true,
+    }),
+  },
+
+  outputs: ['#directory'],
+
+  steps: () => [
+    withResultOfAvailabilityCheck({
+      from: input('directory'),
+    }),
+
+    {
+      dependencies: ['#availability', input('directory')],
+      compute: (continuation, {
+        ['#availability']: availability,
+        [input('directory')]: directory,
+      }) =>
+        (availability
+          ? continuation.raiseOutput({
+              ['#directory']: directory
+            })
+          : continuation()),
+    },
+
+    withDirectoryFromName({
+      name: input('name'),
+    }),
+  ],
+});
diff --git a/src/data/composite/wiki-data/withDirectory.js b/src/data/composite/wiki-data/withDirectory.js
index a3f4ceda..f3bedf2e 100644
--- a/src/data/composite/wiki-data/withDirectory.js
+++ b/src/data/composite/wiki-data/withDirectory.js
@@ -7,9 +7,9 @@ import {input, templateCompositeFrom} from '#composite';
 
 import {isDirectory, isName} from '#validators';
 
-import {withResultOfAvailabilityCheck} from '#composite/control-flow';
+import {raiseOutputWithoutDependency} from '#composite/control-flow';
 
-import withDirectoryFromName from './helpers/withDirectoryFromName.js';
+import withSimpleDirectory from './helpers/withSimpleDirectory.js';
 
 export default templateCompositeFrom({
   annotation: `withDirectory`,
@@ -26,30 +26,37 @@ export default templateCompositeFrom({
       defaultDependency: 'name',
       acceptsNull: true,
     }),
+
+    suffix: input({
+      validate: isDirectory,
+      defaultValue: null,
+    }),
   },
 
   outputs: ['#directory'],
 
   steps: () => [
-    withResultOfAvailabilityCheck({
-      from: input('directory'),
+    withSimpleDirectory({
+      directory: input('directory'),
+      name: input('name'),
+    }),
+
+    raiseOutputWithoutDependency({
+      dependency: '#directory',
+      output: input.value({['#directory']: null}),
     }),
 
     {
-      dependencies: ['#availability', input('directory')],
+      dependencies: ['#directory', input('suffix')],
       compute: (continuation, {
-        ['#availability']: availability,
-        [input('directory')]: directory,
-      }) =>
-        (availability
-          ? continuation.raiseOutput({
-              ['#directory']: directory
-            })
-          : continuation()),
+        ['#directory']: directory,
+        [input('suffix')]: suffix,
+      }) => continuation({
+        ['#directory']:
+          (suffix
+            ? directory + '-' + suffix
+            : directory),
+      }),
     },
-
-    withDirectoryFromName({
-      name: input('name'),
-    }),
   ],
 });