GEN-1: expose CATALOG seed view (Name/CanonicalGenotype/SortOrder) for DATA-2 + round-trip test

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-05 23:47:11 +02:00
parent 3cf6413fcc
commit 3629e89e87
3 changed files with 65 additions and 4 deletions

View File

@@ -14,8 +14,8 @@
* - rennmaus-info.jimdoweb.com (loci & colourpoint series)
* - clan-of-topolino.ch, rennmauswelten.jimdofree.com (Zobel, Schimmel)
*/
import type { LocusKey } from './loci'
import type { Genotype } from './genotype'
import { LOCUS_ORDER, type LocusKey } from './loci'
import { makeGenotype, toDisplayString, wildType, type AllelePair, type Genotype } from './genotype'
import { phenotypeTokens, type PhenotypeTokens } from './phenotype'
export interface FarbschlagEntry {
@@ -105,5 +105,41 @@ export function genotypeToFarbschlag(g: Genotype): string {
return farbschlagFor(g).name
}
/**
* A representative full genotype for a catalog entry: each specified locus is
* homozygous for its token allele; unspecified loci take the wild-type allele.
* This is the entry's CanonicalGenotype for DB seeding.
*/
export function representativeGenotype(entry: FarbschlagEntry): Genotype {
const base = wildType()
const out = {} as Record<LocusKey, AllelePair>
for (const locus of LOCUS_ORDER) {
const token = entry.tokens[locus]
out[locus] = token ? [token, token] : base[locus]
}
return makeGenotype(out)
}
/**
* DB seed view for DATA-2's ColorVariety table. Each row mirrors the table
* shape (Name, CanonicalGenotype, SortOrder). SortOrder = catalog position.
*
* IMPORTANT: `name` values become DB keys the UI filters on — renames are
* BREAKING changes and must be routed through god. Adding new varieties is safe.
*/
export interface ColorVarietySeed {
readonly name: string
readonly english?: string
readonly canonicalGenotype: string
readonly sortOrder: number
}
export const CATALOG: readonly ColorVarietySeed[] = BASE_COLORS.map((entry, i) => ({
name: entry.name,
english: entry.english,
canonicalGenotype: toDisplayString(representativeGenotype(entry)),
sortOrder: i,
}))
/** Number of base-colour varieties currently catalogued. */
export const CATALOG_SIZE = BASE_COLORS.length