« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/find.js24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/find.js b/src/find.js
index 157597c2..2f1db9df 100644
--- a/src/find.js
+++ b/src/find.js
@@ -1,7 +1,7 @@
 import {inspect} from 'node:util';
 
 import {colors, logWarn} from '#cli';
-import {compareObjects, typeAppearance} from '#sugar';
+import {compareObjects, stitchArrays, typeAppearance} from '#sugar';
 import thingConstructors from '#things';
 import {isFunction, validateArrayItems} from '#validators';
 
@@ -347,9 +347,27 @@ function findMixedHelper(config) {
       });
     }
 
+    const byDirectory =
+      Object.fromEntries(
+        stitchArrays({
+          referenceType: keys,
+          spec: specs,
+        }).map(({referenceType, spec}) => [
+            referenceType,
+            processAvailableMatchesByDirectory(data, spec).results,
+          ]));
+
     return matchHelper(fullRef, mode, {
-      matchByDirectory:
-        () => null, /* TODO: Do something */
+      matchByDirectory: (referenceType, directory) => {
+        if (!keys.includes(referenceType)) {
+          return oopsWrongReferenceType(mode, {
+            referenceType,
+            referenceTypes: keys,
+          });
+        }
+
+        return byDirectory[referenceType][directory];
+      },
 
       matchByName:
         prepareMatchByName(mode, {