/** * A node as a page can name it: any entity the registry holds (a stub, an * identified company included), else the name its source printed. * * Lives apart from ./store because it needs the full registry, and the * registry's derived sources read the store: see lib/entities/directory.ts. */ import { resolveDirectoryEntity } from '@/lib/entities/directory'; import { resolveEntity } from '@/lib/entities/registry'; import type { EntityId } from '@/lib/entities/types'; import { graphStore, type GraphNode, type GraphStore } from './store'; export function graphNode(id: string, s: GraphStore = graphStore()): GraphNode { const entity = resolveEntity(id); const minted = s.nodes.get(id); const kind = id.slice(0, id.indexOf(':')); return { id: id as EntityId, name: entity?.name ?? minted?.name ?? id.slice(id.indexOf(':') + 1), inDirectory: Boolean(resolveDirectoryEntity(id)), kind, iso2: minted?.iso2 ?? (kind === 'country' ? [id.slice(id.indexOf(':') + 1)] : []), ...(minted?.commodities ? { commodities: minted.commodities } : {}), }; }