From 042f60f47660a4354cad4d7a80c5beaf86c9cb62 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Thu, 14 Nov 2024 19:04:37 -0400 Subject: find: findMixedHelper directory internals --- src/find.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'src') 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, { -- cgit 1.3.0-6-gf8a5