Files
CatoandClaude dd88dbefce feat(registry): the frontier registry, the add command, areas, and the migration of the 793 admitted companies (#275)
One JSON file per company in registry/companies, one per area in registry/areas,
validated on load (no cite, no value). The registry is the list; the old filter
is a proposer. The 793 admitted companies are migrated with identical output.
pnpm run company:add resolves identity from Wikipedia and Wikidata. /areas and
/areas/[slug] are new.


Claude-Session: https://claude.ai/code/session_018WZnBnaLP6RhwFkLxRTKgE

Co-authored-by: Claude <noreply@anthropic.com>
2026-10-27 19:39:10 +01:00

47 lines
1.6 KiB
TypeScript

/** Turn a resolved identity into a registry company file. Pure. */
import { slugify } from '@/lib/links';
import type { Company, Kind } from './schema';
import type { Resolved } from './resolve';
export interface DraftOptions {
name?: string;
slug?: string;
kind?: Kind;
areas: { area: string; role?: string }[];
aliases?: string[];
today: string;
by?: string;
}
/** An area placement rests on the sentence that says what the company does: same quote, field area:<slug>. */
function areaRows(r: Resolved, o: DraftOptions) {
const s = r.evidence.find((e) => e.field === 'summary');
if (!s) return [];
return o.areas.map((a) => ({ ...s, field: `area:${a.area}` }));
}
export function draftCompany(r: Resolved, o: DraftOptions): Company {
const name = o.name ?? r.page.title.replace(/\s*\(.*\)$/, '');
const summary = r.evidence.find((e) => e.field === 'summary')?.quote;
const kind: Kind = o.kind ?? (r.ids.ticker && r.ids.exchange ? 'public' : 'unclassified');
const has = new Set(r.evidence.map((e) => e.field));
const c: Company = {
slug: o.slug ?? slugify(name),
name,
aliases: o.aliases ?? [],
kind,
status: 'active',
jurisdictions: [],
ids: r.ids,
areas: o.areas,
figures: [],
evidence: [...r.evidence, ...areaRows(r, o)],
origin: { by: o.by ?? 'company:add', on: o.today },
...(summary && summary.length >= 20 ? { summary } : {}),
...(has.has('country') && r.record?.country ? { country: r.record.country } : {}),
...(has.has('hq') && r.record?.hq ? { hq: r.record.hq } : {}),
};
if (kind === 'public' && !(c.ids.ticker && c.ids.exchange)) c.kind = 'unclassified';
return c;
}