« get me outta code hell

data: use key/value-style for all compositional utility args - 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>2023-09-07 11:56:05 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-07 11:56:05 -0300
commit8b379954c9d74f0d47ac32ef395627353940c728 (patch)
treee77d5fb5a68350e588c8e72a0b5e82319d33608e /src
parent4541b2aa65a2f5ccfb7f9a13d5605311fd8ef801 (diff)
data: use key/value-style for all compositional utility args
Diffstat (limited to 'src')
-rw-r--r--src/data/things/composite.js25
-rw-r--r--src/data/things/thing.js39
-rw-r--r--src/data/things/track.js65
3 files changed, 81 insertions, 48 deletions
diff --git a/src/data/things/composite.js b/src/data/things/composite.js
index 976f780..5b6de90 100644
--- a/src/data/things/composite.js
+++ b/src/data/things/composite.js
@@ -801,9 +801,10 @@ export function debugComposite(fn) {
 // compositional step, the property will be exposed as undefined instead
 // of null.
 //
-export function exposeDependency(dependency, {
+export function exposeDependency({
+  dependency,
   update = false,
-} = {}) {
+}) {
   return {
     annotation: `exposeDependency`,
     flags: {expose: true, update: !!update},
@@ -826,9 +827,10 @@ export function exposeDependency(dependency, {
 // exit with some other value, with the exposeConstant base serving as the
 // fallback default value. Like exposeDependency, set {update} to true or
 // an object to indicate that the property as a whole updates.
-export function exposeConstant(value, {
+export function exposeConstant({
+  value,
   update = false,
-} = {}) {
+}) {
   return {
     annotation: `exposeConstant`,
     flags: {expose: true, update: !!update},
@@ -912,9 +914,10 @@ export function withResultOfAvailabilityCheck({
 
 // Exposes a dependency as it is, or continues if it's unavailable.
 // See withResultOfAvailabilityCheck for {mode} options!
-export function exposeDependencyOrContinue(dependency, {
+export function exposeDependencyOrContinue({
+  dependency,
   mode = 'null',
-} = {}) {
+}) {
   return compositeFrom(`exposeDependencyOrContinue`, [
     withResultOfAvailabilityCheck({
       fromDependency: dependency,
@@ -990,10 +993,11 @@ export function exitIfAvailabilityCheckFailed({
 
 // Early exits if a dependency isn't available.
 // See withResultOfAvailabilityCheck for {mode} options!
-export function exitWithoutDependency(dependency, {
+export function exitWithoutDependency({
+  dependency,
   mode = 'null',
   value = null,
-} = {}) {
+}) {
   return compositeFrom(`exitWithoutDependency`, [
     withResultOfAvailabilityCheck({fromDependency: dependency, mode}),
     exitIfAvailabilityCheckFailed({value}),
@@ -1014,11 +1018,12 @@ export function exitWithoutUpdateValue({
 
 // Raises if a dependency isn't available.
 // See withResultOfAvailabilityCheck for {mode} options!
-export function raiseWithoutDependency(dependency, {
+export function raiseWithoutDependency({
+  dependency,
   mode = 'null',
   map = {},
   raise = {},
-} = {}) {
+}) {
   return compositeFrom(`raiseWithoutDependency`, [
     withResultOfAvailabilityCheck({fromDependency: dependency, mode}),
 
diff --git a/src/data/things/thing.js b/src/data/things/thing.js
index 16003b0..98dec3c 100644
--- a/src/data/things/thing.js
+++ b/src/data/things/thing.js
@@ -205,7 +205,8 @@ export default class Thing extends CacheableObject {
           list, data, find,
           notFoundMode: 'filter',
         }),
-        exposeDependency('#resolvedReferenceList'),
+
+        exposeDependency({dependency: '#resolvedReferenceList'}),
       ]);
     },
 
@@ -213,7 +214,7 @@ export default class Thing extends CacheableObject {
     resolvedReference({ref, data, find}) {
       return compositeFrom(`Thing.common.resolvedReference`, [
         withResolvedReference({ref, data, find}),
-        exposeDependency('#resolvedReference'),
+        exposeDependency({dependency: '#resolvedReference'}),
       ]);
     },
 
@@ -239,7 +240,7 @@ export default class Thing extends CacheableObject {
           into: '#contribs',
         }),
 
-        exposeDependency('#contribs'),
+        exposeDependency({dependency: '#contribs'}),
       ]);
     },
 
@@ -265,7 +266,7 @@ export default class Thing extends CacheableObject {
     reverseReferenceList({data, list}) {
       return compositeFrom(`Thing.common.reverseReferenceList`, [
         withReverseReferenceList({data, list}),
-        exposeDependency('#reverseReferenceList'),
+        exposeDependency({dependency: '#reverseReferenceList'}),
       ]);
     },
 
@@ -337,7 +338,8 @@ export default class Thing extends CacheableObject {
 // object, and filtering out those whose "who" doesn't match any artist.
 export function withResolvedContribs({from, into}) {
   return compositeFrom(`withResolvedContribs`, [
-    raiseWithoutDependency(from, {
+    raiseWithoutDependency({
+      dependency: from,
       mode: 'empty',
       map: {into},
       raise: {into: []},
@@ -391,8 +393,15 @@ export function withResolvedReference({
   }
 
   return compositeFrom(`withResolvedReference`, [
-    raiseWithoutDependency(ref, {map: {into}, raise: {into: null}}),
-    exitWithoutDependency(data),
+    raiseWithoutDependency({
+      dependency: ref,
+      map: {into},
+      raise: {into: null},
+    }),
+
+    exitWithoutDependency({
+      dependency: data,
+    }),
 
     {
       options: {findFunction, notFoundMode},
@@ -429,11 +438,16 @@ export function withResolvedReferenceList({
   }
 
   return compositeFrom(`withResolvedReferenceList`, [
-    exitWithoutDependency(data, {value: []}),
-    raiseWithoutDependency(list, {
+    exitWithoutDependency({
+      dependency: data,
+      value: [],
+    }),
+
+    raiseWithoutDependency({
+      dependency: list,
+      mode: 'empty',
       map: {into},
       raise: {into: []},
-      mode: 'empty',
     }),
 
     {
@@ -473,7 +487,10 @@ export function withReverseReferenceList({
   into = '#reverseReferenceList',
 }) {
   return compositeFrom(`Thing.common.reverseReferenceList`, [
-    exitWithoutDependency(data, {value: []}),
+    exitWithoutDependency({
+      dependency: data,
+      value: [],
+    }),
 
     {
       dependencies: ['this'],
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 1adfe71..7dde88d 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -73,8 +73,10 @@ export class Track extends Thing {
             : continuation()),
       },
 
-      withAlbumProperty('color'),
-      exposeDependency('#album.color', {
+      withAlbumProperty({property: 'color'}),
+
+      exposeDependency({
+        dependency: '#album.color',
         update: {validate: isColor},
       }),
     ]),
@@ -93,17 +95,18 @@ export class Track extends Thing {
       // No cover art file extension if the track doesn't have unique artwork
       // in the first place.
       withHasUniqueCoverArt(),
-      exitWithoutDependency('#hasUniqueCoverArt', {mode: 'falsy'}),
+      exitWithoutDependency({dependency: '#hasUniqueCoverArt', mode: 'falsy'}),
 
       // Expose custom coverArtFileExtension update value first.
       exposeUpdateValueOrContinue(),
 
       // Expose album's trackCoverArtFileExtension if no update value set.
-      withAlbumProperty('trackCoverArtFileExtension'),
-      exposeDependencyOrContinue('#album.trackCoverArtFileExtension'),
+      withAlbumProperty({property: 'trackCoverArtFileExtension'}),
+      exposeDependencyOrContinue({dependency: '#album.trackCoverArtFileExtension'}),
 
       // Fallback to 'jpg'.
-      exposeConstant('jpg', {
+      exposeConstant({
+        value: 'jpg',
         update: {validate: isFileExtension},
       }),
     ]),
@@ -114,12 +117,13 @@ export class Track extends Thing {
     // is specified, this value is null.
     coverArtDate: compositeFrom(`Track.coverArtDate`, [
       withHasUniqueCoverArt(),
-      exitWithoutDependency('#hasUniqueCoverArt', {mode: 'falsy'}),
+      exitWithoutDependency({dependency: '#hasUniqueCoverArt', mode: 'falsy'}),
 
       exposeUpdateValueOrContinue(),
 
-      withAlbumProperty('trackArtDate'),
-      exposeDependency('#album.trackArtDate', {
+      withAlbumProperty({property: 'trackArtDate'}),
+      exposeDependency({
+        dependency: '#album.trackArtDate',
         update: {validate: isDate},
       }),
     ]),
@@ -148,7 +152,7 @@ export class Track extends Thing {
 
     album: compositeFrom(`Track.album`, [
       withAlbum(),
-      exposeDependency('#album'),
+      exposeDependency({dependency: '#album'}),
     ]),
 
     // Note - this is an internal property used only to help identify a track.
@@ -165,9 +169,9 @@ export class Track extends Thing {
     }),
 
     date: compositeFrom(`Track.date`, [
-      exposeDependencyOrContinue('dateFirstReleased'),
-      withAlbumProperty('date'),
-      exposeDependency('#album.date'),
+      exposeDependencyOrContinue({dependency: 'dateFirstReleased'}),
+      withAlbumProperty({property: 'date'}),
+      exposeDependency({dependency: '#album.date'}),
     ]),
 
     // Whether or not the track has "unique" cover artwork - a cover which is
@@ -179,16 +183,16 @@ export class Track extends Thing {
     // album.)
     hasUniqueCoverArt: compositeFrom(`Track.hasUniqueCoverArt`, [
       withHasUniqueCoverArt(),
-      exposeDependency('#hasUniqueCoverArt'),
+      exposeDependency({dependency: '#hasUniqueCoverArt'}),
     ]),
 
     originalReleaseTrack: compositeFrom(`Track.originalReleaseTrack`, [
       withOriginalRelease(),
-      exposeDependency('#originalRelease'),
+      exposeDependency({dependency: '#originalRelease'}),
     ]),
 
     otherReleases: compositeFrom(`Track.otherReleases`, [
-      exitWithoutDependency('trackData', {mode: 'empty'}),
+      exitWithoutDependency({dependency: 'trackData', mode: 'empty'}),
       withOriginalRelease({selfIfOriginal: true}),
 
       {
@@ -227,8 +231,8 @@ export class Track extends Thing {
             : contribsFromTrack),
       },
 
-      withAlbumProperty('artistContribs'),
-      exposeDependency('#album.artistContribs'),
+      withAlbumProperty({property: 'artistContribs'}),
+      exposeDependency({dependency: '#album.artistContribs'}),
     ]),
 
     contributorContribs: compositeFrom(`Track.contributorContribs`, [
@@ -261,8 +265,8 @@ export class Track extends Thing {
             : contribsFromTrack),
       },
 
-      withAlbumProperty('trackCoverArtistContribs'),
-      exposeDependency('#album.trackCoverArtistContribs'),
+      withAlbumProperty({property: 'trackCoverArtistContribs'}),
+      exposeDependency({dependency: '#album.trackCoverArtistContribs'}),
     ]),
 
     referencedTracks: compositeFrom(`Track.referencedTracks`, [
@@ -297,10 +301,14 @@ export class Track extends Thing {
     // counting the number of times a track has been referenced, for use in
     // the "Tracks - by Times Referenced" listing page (or other data
     // processing).
-    referencedByTracks: trackReverseReferenceList('referencedTracks'),
+    referencedByTracks: trackReverseReferenceList({
+      property: 'referencedTracks',
+    }),
 
     // For the same reasoning, exclude re-releases from sampled tracks too.
-    sampledByTracks: trackReverseReferenceList('sampledTracks'),
+    sampledByTracks: trackReverseReferenceList({
+      property: 'sampledTracks',
+    }),
 
     featuredInFlashes: Thing.common.reverseReferenceList({
       data: 'flashData',
@@ -419,10 +427,11 @@ function withAlbum({
 // property name prefixed with '#album.' (by default). If the track's album
 // isn't available, then by default, the property will be provided as null;
 // set {notFoundMode: 'exit'} to early exit instead.
-function withAlbumProperty(property, {
+function withAlbumProperty({
+  property,
   into = '#album.' + property,
   notFoundMode = 'null',
-} = {}) {
+}) {
   return compositeFrom(`withAlbumProperty`, [
     withAlbum({notFoundMode}),
 
@@ -493,7 +502,7 @@ function withContainingTrackSection({
   }
 
   return compositeFrom(`withContainingTrackSection`, [
-    withAlbumProperty('trackSections', {notFoundMode}),
+    withAlbumProperty({property: 'trackSections', notFoundMode}),
 
     {
       dependencies: ['this', '#album.trackSections'],
@@ -592,7 +601,7 @@ function withHasUniqueCoverArt({
           : continuation.raise({into: true})),
     },
 
-    withAlbumProperty('trackCoverArtistContribs'),
+    withAlbumProperty({property: 'trackCoverArtistContribs'}),
 
     {
       dependencies: ['#album.trackCoverArtistContribs'],
@@ -605,7 +614,9 @@ function withHasUniqueCoverArt({
   ]);
 }
 
-function trackReverseReferenceList(refListProperty) {
+function trackReverseReferenceList({
+  property: refListProperty,
+}) {
   return compositeFrom(`trackReverseReferenceList`, [
     withReverseReferenceList({
       data: 'trackData',