@tomerlichtash/md-registry
v0.1.0
Published
Entity registry for markdown corpora: alias map, polymorphic byline resolution, unknown-ref policy, zod reference()
Readme
@tomerlichtash/md-registry
Entity registry for markdown corpora — the thing Astro's reference() does
for content collections, but framework-free. One canonical record per entity
(author, translator, subject), an alias map from display strings to ids,
polymorphic byline resolution, and a per-call-site policy for unknown refs.
Core has zero dependencies and does no file I/O: it takes a plain entries
array from any loader (@tomerlichtash/md-collections,
your own, mocks).
import { createRegistry } from '@tomerlichtash/md-registry';
const people = createRegistry(entries, { nameField: 'name', aliasField: 'aka' });
// frontmatter `author:` may be a legacy free string, an id, or a list of ids
people.resolveDisplay(page.author, { join: ' & ', override: page.display_author });
people.idsOf(page.author); // → ['ada-quill']
// unknown-ref policy per call site
people.resolveRef('rio-marsh', { onUnknown: 'error' }); // typo fails the build
people.resolveRef('rio-marsh', { onUnknown: 'passthrough' }); // legacy strings flow through
people.resolveRef('rio-marsh', { onUnknown: 'unresolved' }); // placeholder for unknowable identitiesNames can be plain strings or per-locale records ({ en, fr }); pass
defaultLocale and/or a locale per call. An alias shared by two entities
resolves to both — the combined-credit split. The building blocks
(buildAliasMap, resolveDisplay, idsOf) are also exported as pure
functions.
./reference — zod helper
import { reference } from '@tomerlichtash/md-registry/reference';
refs: z.array(reference(() => people)); // parse-time build fail on a typo'd idzod is a peer dependency of this subpath only. Only want validation?
z.string().refine((id) => knownIds.has(id)) covers it without this package.
