Generator Architecture
The schema generator turns the Schema.org JSON-LD vocabulary into typed code, helpers, and validation assets. This document outlines the moving parts so you can safely extend the pipeline.
Entry points
src/generator/utils.tshandles downloading the canonical Schema.org vocabulary and splitting it into curated JSON files undersrc/schema/data/.src/generator/generate.tsorchestrates the full build by first ensuring the data files exist (writeFiles) and then invokingsrc/generator/generateSchema.ts.
Data ingest
writeFiles()checkssrc/schema/data/schema.json. If absent, it fetches the latest vocabulary fromhttps://schema.org/version/latest/schemaorg-all-https.jsonldand caches it locally.- The Extractors (
extractDatatypes,extractClasses,extractProperties,extractOtherTypes) split the graph into dedicated JSON files.
Graph rendering
src/generator/generateSchema.ts builds an in-memory graph using @avensio/graph:
- Each Schema.org class becomes a
Vertexannotated with its identifier. - Properties join the graph with metadata that powers validator emission.
- A
VertexEmittercoordinates renderers fromsrc/renderers/index.tsto create class definitions, creators, and validator modules.
The emitter writes code fragments into temporary buffers (FILE_CHUNKS) so multiple renderers can contribute to the same output file before anything touches the filesystem.
Output and post-processing
- Buffered files flush to
dist/with normalized newlines. validationCoreSrc/validationCoreTypesseed shared helpers underdist/validation/.writeIndexFiles()generates re-export barrels and type aggregators for classes and validators.writePrimitiveDatatypeStubsAndValidators()adds the branded primitive bindings (Number,Text, etc.).copyAssets()copies package metadata plus the raw schema data into the distribution so consumers can inspect the bundled snapshot.
Extending the pipeline
- Add data: drop new JSON fragments under
src/schema/data/or enrich the download/split logic inutils.ts. - Add renderers: register a new emitter function inside
src/renderers/index.tsto create additional file types. - Adjust outputs: update helper writers in
src/generator/helpers.tsif new folders or manifest data are needed.
Always finish modifications with:
bash
pnpm run generate:schema # regenerates schema data + dist/
pnpm test -- --runThese commands ensure dist/ reflects the current generator logic and that the published artifacts remain in sync with the raw schema snapshot.