From 2e5c82d427df107f98d319a6379da899b1b5d1b2 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 16 Feb 2024 16:10:09 -0400 Subject: data-checks: factor out findArtistOrAlias logic --- src/data/checks.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/data/checks.js b/src/data/checks.js index 96f4cd8c..e98f04de 100644 --- a/src/data/checks.js +++ b/src/data/checks.js @@ -113,6 +113,20 @@ export function reportDuplicateDirectories(wikiData, { }); } +function bindFindArtistOrAlias(boundFind) { + return artistRef => { + const alias = boundFind.artistAlias(artistRef, {mode: 'quiet'}); + if (alias) { + // No need to check if the original exists here. Aliases are automatically + // created from a field on the original, so the original certainly exists. + const original = alias.aliasedArtist; + throw new Error(`Reference ${colors.red(artistRef)} is to an alias, should be ${colors.green(original.name)}`); + } + + return boundFind.artist(artistRef); + }; +} + // Warn about references across data which don't match anything. This involves // using the find() functions on all references, setting it to 'error' mode, and // collecting everything in a structured logged (which gets logged if there are @@ -168,18 +182,7 @@ export function filterReferenceErrors(wikiData, { ]; const boundFind = bindFind(wikiData, {mode: 'error'}); - - const findArtistOrAlias = artistRef => { - const alias = boundFind.artistAlias(artistRef, {mode: 'quiet'}); - if (alias) { - // No need to check if the original exists here. Aliases are automatically - // created from a field on the original, so the original certainly exists. - const original = alias.aliasedArtist; - throw new Error(`Reference ${colors.red(artistRef)} is to an alias, should be ${colors.green(original.name)}`); - } - - return boundFind.artist(artistRef); - }; + const findArtistOrAlias = bindFindArtistOrAlias(boundFind); const aggregate = openAggregate({message: `Errors validating between-thing references in data`}); for (const [thingDataProp, propSpec] of referenceSpec) { -- cgit 1.3.0-6-gf8a5