« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/data/things/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/data/things/index.js')
-rw-r--r--src/data/things/index.js35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/data/things/index.js b/src/data/things/index.js
index 11b6b1a..3bf8409 100644
--- a/src/data/things/index.js
+++ b/src/data/things/index.js
@@ -1,12 +1,12 @@
-import {logError} from '../../util/cli.js';
-import {openAggregate, showAggregate} from '../../util/sugar.js';
+import * as path from 'node:path';
+import {fileURLToPath} from 'node:url';
 
-import * as path from 'path';
-import {fileURLToPath} from 'url';
+import {openAggregate, showAggregate} from '#aggregate';
+import {logError} from '#cli';
+import {compositeFrom} from '#composite';
+import * as serialize from '#serialize';
 
-import Thing from './thing.js';
-import * as validators from './validators.js';
-import * as serialize from '../serialize.js';
+import Thing from '#thing';
 
 import * as albumClasses from './album.js';
 import * as artTagClasses from './art-tag.js';
@@ -79,6 +79,8 @@ function errorDuplicateClassNames() {
 function flattenClassLists() {
   for (const classes of Object.values(allClassLists)) {
     for (const [name, constructor] of Object.entries(classes)) {
+      if (typeof constructor !== 'function') continue;
+      if (!(constructor.prototype instanceof Thing)) continue;
       allClasses[name] = constructor;
     }
   }
@@ -116,7 +118,7 @@ function descriptorAggregateHelper({
 }
 
 function evaluatePropertyDescriptors() {
-  const opts = {...allClasses, validators};
+  const opts = {...allClasses};
 
   return descriptorAggregateHelper({
     message: `Errors evaluating Thing class property descriptors`,
@@ -126,8 +128,21 @@ function evaluatePropertyDescriptors() {
         throw new Error(`Missing [Thing.getPropertyDescriptors] function`);
       }
 
-      constructor.propertyDescriptors =
-        constructor[Thing.getPropertyDescriptors](opts);
+      const results = constructor[Thing.getPropertyDescriptors](opts);
+
+      for (const [key, value] of Object.entries(results)) {
+        if (Array.isArray(value)) {
+          results[key] = compositeFrom({
+            annotation: `${constructor.name}.${key}`,
+            compose: false,
+            steps: value,
+          });
+        } else if (value.toResolvedComposition) {
+          results[key] = compositeFrom(value.toResolvedComposition());
+        }
+      }
+
+      constructor.propertyDescriptors = results;
     },
 
     showFailedClasses(failedClasses) {