« get me outta code hell

data, infra: import validators directly - 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-09-07 12:06:06 -0300
committer(quasar) nebula <qznebula@protonmail.com>2023-09-07 12:07:03 -0300
commit6889c764caef5542ba9ad8362acf6e8b7b879ea9 (patch)
treea89bb9a9bd9884ffd1c51e4926a04469618f73b3
parent8b379954c9d74f0d47ac32ef395627353940c728 (diff)
data, infra: import validators directly
-rw-r--r--src/data/things/album.js16
-rw-r--r--src/data/things/art-tag.js5
-rw-r--r--src/data/things/artist.js12
-rw-r--r--src/data/things/flash.js27
-rw-r--r--src/data/things/group.js8
-rw-r--r--src/data/things/homepage-layout.js36
-rw-r--r--src/data/things/index.js3
-rw-r--r--src/data/things/language.js8
-rw-r--r--src/data/things/static-page.js8
-rw-r--r--src/data/things/track.js15
-rw-r--r--src/data/things/wiki-info.js11
11 files changed, 41 insertions, 108 deletions
diff --git a/src/data/things/album.js b/src/data/things/album.js
index 81f04f7..da01885 100644
--- a/src/data/things/album.js
+++ b/src/data/things/album.js
@@ -1,23 +1,13 @@
-import {empty} from '#sugar';
 import find from '#find';
+import {empty} from '#sugar';
+import {isDate, isDimensions, isTrackSectionList} from '#validators';
 
 import Thing from './thing.js';
 
 export class Album extends Thing {
   static [Thing.referenceType] = 'album';
 
-  static [Thing.getPropertyDescriptors] = ({
-    ArtTag,
-    Artist,
-    Group,
-    Track,
-
-    validators: {
-      isDate,
-      isDimensions,
-      isTrackSectionList,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({ArtTag, Artist, Group, Track}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Album'),
diff --git a/src/data/things/art-tag.js b/src/data/things/art-tag.js
index bb36e09..5d7d0cb 100644
--- a/src/data/things/art-tag.js
+++ b/src/data/things/art-tag.js
@@ -5,10 +5,7 @@ import Thing from './thing.js';
 export class ArtTag extends Thing {
   static [Thing.referenceType] = 'tag';
 
-  static [Thing.getPropertyDescriptors] = ({
-    Album,
-    Track,
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Album, Track}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Art Tag'),
diff --git a/src/data/things/artist.js b/src/data/things/artist.js
index b238305..93a1b51 100644
--- a/src/data/things/artist.js
+++ b/src/data/things/artist.js
@@ -1,20 +1,12 @@
 import find from '#find';
+import {isName, validateArrayItems} from '#validators';
 
 import Thing from './thing.js';
 
 export class Artist extends Thing {
   static [Thing.referenceType] = 'artist';
 
-  static [Thing.getPropertyDescriptors] = ({
-    Album,
-    Flash,
-    Track,
-
-    validators: {
-      isName,
-      validateArrayItems,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Album, Flash, Track}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Artist'),
diff --git a/src/data/things/flash.js b/src/data/things/flash.js
index baef23d..ce2e7fa 100644
--- a/src/data/things/flash.js
+++ b/src/data/things/flash.js
@@ -1,22 +1,19 @@
 import find from '#find';
 
+import {
+  isColor,
+  isDirectory,
+  isNumber,
+  isString,
+  oneOf,
+} from '#validators';
+
 import Thing from './thing.js';
 
 export class Flash extends Thing {
   static [Thing.referenceType] = 'flash';
 
-  static [Thing.getPropertyDescriptors] = ({
-    Artist,
-    Track,
-    FlashAct,
-
-    validators: {
-      isDirectory,
-      isNumber,
-      isString,
-      oneOf,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Artist, Track, FlashAct}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Flash'),
@@ -111,11 +108,7 @@ export class Flash extends Thing {
 }
 
 export class FlashAct extends Thing {
-  static [Thing.getPropertyDescriptors] = ({
-    validators: {
-      isColor,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = () => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Flash Act'),
diff --git a/src/data/things/group.js b/src/data/things/group.js
index d04fcf5..6c71284 100644
--- a/src/data/things/group.js
+++ b/src/data/things/group.js
@@ -5,9 +5,7 @@ import Thing from './thing.js';
 export class Group extends Thing {
   static [Thing.referenceType] = 'group';
 
-  static [Thing.getPropertyDescriptors] = ({
-    Album,
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Album}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Group'),
@@ -76,9 +74,7 @@ export class Group extends Thing {
 }
 
 export class GroupCategory extends Thing {
-  static [Thing.getPropertyDescriptors] = ({
-    Group,
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Group}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Group Category'),
diff --git a/src/data/things/homepage-layout.js b/src/data/things/homepage-layout.js
index c478bc4..59656b4 100644
--- a/src/data/things/homepage-layout.js
+++ b/src/data/things/homepage-layout.js
@@ -1,17 +1,18 @@
 import find from '#find';
 
+import {
+  is,
+  isCountingNumber,
+  isString,
+  isStringNonEmpty,
+  validateArrayItems,
+  validateInstanceOf,
+} from '#validators';
+
 import Thing from './thing.js';
 
 export class HomepageLayout extends Thing {
-  static [Thing.getPropertyDescriptors] = ({
-    HomepageLayoutRow,
-
-    validators: {
-      isStringNonEmpty,
-      validateArrayItems,
-      validateInstanceOf,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({HomepageLayoutRow}) => ({
     // Update & expose
 
     sidebarContent: Thing.common.simpleString(),
@@ -32,10 +33,7 @@ export class HomepageLayout extends Thing {
 }
 
 export class HomepageLayoutRow extends Thing {
-  static [Thing.getPropertyDescriptors] = ({
-    Album,
-    Group,
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Album, Group}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Homepage Row'),
@@ -63,17 +61,7 @@ export class HomepageLayoutRow extends Thing {
 }
 
 export class HomepageLayoutAlbumsRow extends HomepageLayoutRow {
-  static [Thing.getPropertyDescriptors] = (opts, {
-    Album,
-    Group,
-
-    validators: {
-      is,
-      isCountingNumber,
-      isString,
-      validateArrayItems,
-    },
-  } = opts) => ({
+  static [Thing.getPropertyDescriptors] = (opts, {Album, Group} = opts) => ({
     ...HomepageLayoutRow[Thing.getPropertyDescriptors](opts),
 
     // Update & expose
diff --git a/src/data/things/index.js b/src/data/things/index.js
index 2d4f77d..3b73a77 100644
--- a/src/data/things/index.js
+++ b/src/data/things/index.js
@@ -4,7 +4,6 @@ import {fileURLToPath} from 'node:url';
 import {logError} from '#cli';
 import * as serialize from '#serialize';
 import {openAggregate, showAggregate} from '#sugar';
-import * as validators from '#validators';
 
 import Thing from './thing.js';
 
@@ -121,7 +120,7 @@ function descriptorAggregateHelper({
 }
 
 function evaluatePropertyDescriptors() {
-  const opts = {...allClasses, validators};
+  const opts = {...allClasses};
 
   return descriptorAggregateHelper({
     message: `Errors evaluating Thing class property descriptors`,
diff --git a/src/data/things/language.js b/src/data/things/language.js
index 7755c50..0638afa 100644
--- a/src/data/things/language.js
+++ b/src/data/things/language.js
@@ -1,11 +1,9 @@
+import {isLanguageCode} from '#validators';
+
 import Thing from './thing.js';
 
 export class Language extends Thing {
-  static [Thing.getPropertyDescriptors] = ({
-    validators: {
-      isLanguageCode,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = () => ({
     // Update & expose
 
     // General language code. This is used to identify the language distinctly
diff --git a/src/data/things/static-page.js b/src/data/things/static-page.js
index 3d8d474..ae0ca42 100644
--- a/src/data/things/static-page.js
+++ b/src/data/things/static-page.js
@@ -1,13 +1,11 @@
+import {isName} from '#validators';
+
 import Thing from './thing.js';
 
 export class StaticPage extends Thing {
   static [Thing.referenceType] = 'static';
 
-  static [Thing.getPropertyDescriptors] = ({
-    validators: {
-      isName,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = () => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Static Page'),
diff --git a/src/data/things/track.js b/src/data/things/track.js
index 7dde88d..10b966a 100644
--- a/src/data/things/track.js
+++ b/src/data/things/track.js
@@ -3,6 +3,7 @@ import {inspect} from 'node:util';
 import {color} from '#cli';
 import find from '#find';
 import {empty} from '#sugar';
+import {isColor, isDate, isDuration, isFileExtension} from '#validators';
 
 import {
   compositeFrom,
@@ -23,19 +24,7 @@ import Thing, {
 export class Track extends Thing {
   static [Thing.referenceType] = 'track';
 
-  static [Thing.getPropertyDescriptors] = ({
-    Album,
-    ArtTag,
-    Artist,
-    Flash,
-
-    validators: {
-      isColor,
-      isDate,
-      isDuration,
-      isFileExtension,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Album, ArtTag, Artist, Flash}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Track'),
diff --git a/src/data/things/wiki-info.js b/src/data/things/wiki-info.js
index d6790c5..0ccef5e 100644
--- a/src/data/things/wiki-info.js
+++ b/src/data/things/wiki-info.js
@@ -1,17 +1,10 @@
 import find from '#find';
+import {isLanguageCode, isName, isURL} from '#validators';
 
 import Thing from './thing.js';
 
 export class WikiInfo extends Thing {
-  static [Thing.getPropertyDescriptors] = ({
-    Group,
-
-    validators: {
-      isLanguageCode,
-      isName,
-      isURL,
-    },
-  }) => ({
+  static [Thing.getPropertyDescriptors] = ({Group}) => ({
     // Update & expose
 
     name: Thing.common.name('Unnamed Wiki'),