federation-codegen
Use when generating a typed domain model from a sector ontology plus SHACL profile, writing a codegen.config.json, running admission or the fidelity assertion, migrating a hand-written model package to generated code, or changing @jeswr/federation-codegen.
- License 许可
- MIT
- 所属仓库
- jeswr/solid-sdk
- 最近更新
- 2026-11-15
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- federation-codegen
- description
- Use when generating a typed domain model from a sector ontology plus SHACL profile, writing a codegen.config.json, running admission or the fidelity assertion, migrating a hand-written model package to generated code, or changing @jeswr/federation-codegen.
02 资源文件 51
- 脚本examples/bookmark/facade.ts676 B
- 参考文档examples/bookmark/README.md1002 B
- 许可证LICENSE1.0 KB
- 参考文档package.json2.0 KB
- 参考文档README.md17.6 KB
- 脚本scripts/gen-bookmark.mjs461 B
- 脚本src/adapter.ts4.5 KB
- 脚本src/admission.ts13.4 KB
- 脚本src/cli.ts3.8 KB
- 脚本src/compile.ts23.4 KB
- 脚本src/config.ts5.8 KB
- 脚本src/emit.ts13.7 KB
- 脚本src/fidelity.ts25.8 KB
- 脚本src/generate.ts5.5 KB
- 脚本src/index.ts2.5 KB
- 脚本src/nodeviews.ts6.6 KB
- 脚本src/rdf.ts5.1 KB
- 脚本src/shapes.ts27.5 KB
- 脚本test/generator/admission.test.ts4.2 KB
- 脚本test/generator/aliases-security.test.ts4.1 KB
- 脚本test/generator/aliases.test.ts10.9 KB
- 脚本test/generator/compile.test.ts1.9 KB
- 脚本test/generator/composite-e2e.test.ts14.9 KB
- 脚本test/generator/composite-generator.test.ts9.2 KB
- 脚本test/generator/composite-optional-link-types.test.ts5.3 KB
- 脚本test/generator/composite-projection.test.ts9.1 KB
- 脚本test/generator/fidelity.test.ts5.5 KB
- 脚本test/generator/generate.test.ts4.7 KB
- 脚本test/generator/node-views.test.ts13.6 KB
- 脚本test/generator/phase-g.test.ts16.6 KB
- 脚本test/generator/round10-review.test.ts15.1 KB
- 脚本test/generator/round11-review.test.ts11.2 KB
- 脚本test/generator/round2-review.test.ts12.2 KB
- 脚本test/generator/round3-review.test.ts3.8 KB
- 脚本test/generator/round4-review.test.ts14.3 KB
- 脚本test/generator/round5-review.test.ts5.2 KB
- 脚本test/generator/round6-review.test.ts10.2 KB
- 脚本test/generator/round7-review.test.ts12.3 KB
- 脚本test/generator/round8-review.test.ts10.9 KB
- 脚本test/generator/round9-review.test.ts9.3 KB
- 脚本test/generator/sector-divergence.test.ts3.0 KB
- 脚本test/generator/security-review.test.ts11.0 KB
- 脚本test/helpers.ts682 B
- 脚本test/parity/bookmark.parity.test.ts13.1 KB
- 脚本test/parity/iri.parity.test.ts3.1 KB
- 脚本test/parity/shape.parity.test.ts9.2 KB
- 脚本test/parity/vocab.parity.test.ts2.3 KB
- 参考文档tsconfig.build.json192 B
- 参考文档tsconfig.json600 B
- 参考文档turbo.json1.1 KB
- 脚本vitest.config.ts177 B
03 SKILL.md 正文
<!-- AUTHORED-BY Codex GPT-6.1-Sol --> <!-- AUTHORED-BY Codex GPT-6 --> <!-- AUTHORED-BY Claude Opus 5.5 --> <!-- AUTHORED-BY Codex GPT-6 -->
Domain-model code generation
@jeswr/federation-codegen lives in packages/federation-codegen. It compiles an OWL/RDFS
ontology, its SHACL profile and a per-domain codegen.config.json into:
| Artifact | Contents |
|---|---|
model.d.ts |
Types only. |
model.json |
The shape-manifest, fidelity-asserted against shapes.ttl. |
model.js |
Fixed-template shim over @jeswr/model-runtime; bytes vary only in inlined JSON. |
shapes.ttl |
Byte-reproducible SHACL: shape/list nodes skolemized, complex-path roots deterministically labelled blank nodes. |
codegen.lock.json |
Input/output hashes; regeneration fails closed on input drift. |
import { emitLockfile, generateModel } from "@jeswr/federation-codegen";
const result = generateModel({ ontologyTtl, shapesTtl, config });
// result.artifacts: { "model.d.ts", "model.json", "model.js", "shapes.ttl", "codegen-manifest.json" }
CLI: federation-codegen gen --ontology <ttl> --shapes <ttl> --config <json> --out <dir>
(--update-lock accepts a reviewed input change).
A workspace package that commits generated output must pass the root check:codegen guard.
It needs a codegen script writing to src/generated, a workspace:* devDependency on this
package, and a drift test running pnpm run codegen --out <tmp> with a byte comparison.
packages/solid-bookmark (package.json, test/codegen.test.ts) is the reference.
Rules
- Admission (tier a) must pass: every class/property labelled and defined, domain/range or a
waiver, every literal datatyped, every class covered by a NodeShape. Do not pass
--allow-unadmittedin committed generation scripts. - Requiredness comes from SHACL severity (G1): only
sh:ViolationminCount >= 1is fail-closed. SHOULD constraints aresh:Warning. Config cannot disable a MUST. A presentsh:severitymust have exactly one value; duplicate declarations fail admission before any value-only projection, regardless of order. - Reject multiple property shapes sharing a path within one NodeShape, including canonical/alternativePath-member overlaps, in either order. Do not conjoin them or overwrite one shape's constraints with another's.
- Prefix names must match Turtle
PN_PREFIX(including the empty default prefix). Config loading rejects an unsafe or relativeshapesBase. Every Turtle/N-Triples emission goes throughserializeCanonicalTurtle, checking all NamedNodes, literal datatypes, prefix names and namespace IRIs immediately beforen3.Writer. The shared runtime validators also check term kinds/positions, Turtle blank-node labels and BCP 47 language tags. Re-parse buffered output and verify the same quad set with a known blank-node bijection before returning it; fail withTypeError. Generated per-nodesubject()handles call runtimesubjectIri, rejecting unsafe resources withTypeErrorand preserving exact lexical identity for safe resources and derived fragment IRIs. - Shape-derived
iriPatternchecks the original RDF lexical spelling before URL normalization ("https"for^https://,"http-https"for^https?://). The separateiriSchemeguard applies scheme policy and normalization. Fidelity requires both guards for these patterns.sh:minLengthderives onlyminLength;nonBlankrequires the supported\\Spattern or explicit field config policy. All admitted shape-derived read constraints, including length and enum membership, run against original RDF terms before JS projection. IRI enums preserve exact identities on reads and writes; scheme policy filters them without rewriting. Set minimum cardinality counts distinct guarded raw terms before JS deduplication; required sets reject invalid terms. - Reject shapes that are SHACL instances of
rdfs:Classorowl:Classin the shapes graph (rdf:type then a bounded, cycle-safe rdfs:subClassOf* walk): implicit class targets have no exact runtime projection. The ontology graph is not consulted, as in SHACL. Normalization, admission, compilation and fidelity fail closed. - A nested link's
sh:minCountis emitted on the link and fidelity-checked independently of severity-graded requiredness. - A composite's flat
*Datatype marks a child node's required fields required only when every link on the path from the root is required, because parse returns such an object without an optional child that is absent or invalid. The flat type does not stop a caller from filling an optional child only partly; build then writes a non-conforming child (tracked as sst-ild.4.14), so facades must supply all or none of its MUST fields. - SHACL admission is closed: unsupported property/node constraint components and unknown
patterns are errors. Supported patterns are exactly
^https?://,^https://, and\Sfor string-valued nonblank fields. At the root, advisory flat class hints may only be omitted with a warning, because they cannot weaken a Violation MUST. Composite link targets must satisfy their class (explicit ontology subclass ancestry allowed whensh:nodeis present) and referenced node shape. A class-only link may project only a shape targeting that exact class, never a subclass. EmitclassOnly: trueso runtime manifest validation independently checks exact equality withhasClass; fidelity verifies this source distinction. Reject projecting a child shape from a bare IRI link with neithersh:classnorsh:node. Inline or unprojectedsh:nodevalues are admission errors. Every projected parameter retains strict RDF term-kind, datatype and lexical validation; enum literals use the runtime'sreadLiteralreader. Admission rejects everysh:datatypeoutside model-runtime's exported immutableVALIDATED_DATATYPESinventory; there is no opaque-string fallback. For compositesh:classlinks, retain the class ashasClassand fidelity-check it exactly. Canonical target compatibility remains a structural mapping check; generation never treats ontology ancestry as proof for an alias. At runtime require class membership through the linked subject's actualrdf:typeandrdfs:subClassOf*in the data graph. Aliases may supply that ancestry in the data alone. Builds assert the explicit link class on materialised children; runtime traversal is cycle-safe, bounded and fails closed. Compilation, fidelity and runtime manifest validation must independently rejectsh:classnaming a type alias owned by ANY entity or node in the manifest, including optional links: type migration can delete that assertion. Runtime root recognition also accepts canonical/alias target classes through data-graphrdfs:subClassOf*, using the same 10,000 raw-read budget across accepted classes; writes preserve the subject's subclass type assertions. A composite child'ssh:nodevalidation checks property constraints without requiring its shape's target type.sh:targetClassselects focus nodes; it does not constrain a value reached throughsh:node. Every present child value must satisfy its constraints, including optional fields and deeper optional links; absent values obey the property's minimum. Nested validation checks the raw path union before canonical-first projection. Reject omitted child properties in compilation and fidelity, including optional constraints; advisory flat class hints inside children require modeled composite links. Root parsing keeps its documented optional-field drops. Explicit linksh:classis still enforced; builds may assert canonical child types. Decimal/integer bounds and enums must preserve canonical decimal spelling through JS number conversion. Reject noncanonical literal enum members that the runtime writer cannot reproduce exactly; value-only projection must not broadensh:in. - Config may add guards (defaults, trims, sort, http(s) scheme) but never contradict the
shape; the fidelity assertion fails if a required guard is missing or disagrees with SHACL.
Config defaults on Violation
minCount >= 1fields are rejected. Compilation and fidelity independently reject IRI properties carryingsh:datatypeand every impossibleminCount > maxCount, before projecting fields or nested links. - Aliases come only from SHACL: multiple
sh:targetClassvalues select the unique explicit ontologyowl:Classas canonical and emit the sorted extras asaliasTypeIris; a flat 2–4 IRIsh:alternativePathlist selects the unique ontology property as canonical and emits its other members, in list order, asaliasPredicates. Ambiguity, malformed/nested paths, and aliases overlapping any other canonical/alias field predicate fail admission. If owners share a canonical predicate and any owner declares aliases for it, reject the profile and manifest: RDF co-typing prevents proving their focus sets disjoint. Runtime structural predicates are reserved; type aliases cannot overlap any canonical type or an alias owned by another entity/node. Both keys are optional, read-only, and capped at four distinct absolute http(s) aliases by the runtime. Fidelity covers both keys exactly in both directions, including order. Runtime migration applies only at the owning shape's focus nodes: recognised entity roots (including data-graph subclasses) and children reached through bounded, unambiguous composite links satisfying explicit link classes. Establish ownership from the original data before changing predicates/types. Unrelated subjects and unreached composite nodes retain their predicates/types, including aliases. Runtime migration keeps retained raw term identities and cardinality for singleton fields, sets and live-set mutations; normalization/deduplication belongs to the JS read projection, not migration. Singleton migration retains canonical-first selection. Only explicit API values pass through JS write normalization and text sanitization. - Before deleting alias types, migration materialises satisfied explicit link classes on
affected subjects. Then require identical recognition and parsed results under all previously
recognised entity/node shapes (even unreached typed nodes) and reached child focuses.
Runtime
MigrationErrorprevents emission on a change or shared 10,000-read/visit budget exhaustion. Include regressions for type-recognition loss and changed parsed values. - Composite nodes and derived views support aliases on types/flat fields. Structural
nestedlinks explicitly reject aliases; an aliased shape field cannot be omitted. parseShapesneeds the adapter's normalized ontology as its third argument for aliases; its fourth argument carries raw ontology quads for composite subclass ancestry checks.generateModelsupplies both (legacy third-argument quads use the OWL/RDFS adapter). Preserve complex-path roots as blank nodes with deterministic labels: skolemizing a path root silently changes its SHACL meaning to a predicate.- Mint skolem IRIs from full shape/class/path identities using stable hashes and readable suffixes. Check every minted identity against all named IRIs in the input profile and other minted identities; collisions fail closed.
skos:closeMatch/exactMatchare not substitutions and NEVER create aliases.- Consumers keep a hand-written facade (target 150 lines or fewer) that maps the generated entity onto their public API. The parity bar is the package's existing tests run verbatim against the facade (the oracle method).
- Commit generated output and test that a fresh generation is byte-identical.
- RDF discipline holds: parse with n3/fetch-rdf, serialise with n3.Writer, no LDO.
The design of record is decisions/0003-domain-model-codegen.md.
The bookmarks example points to packages/solid-bookmark, which owns its normative
bookmark.ttl + bookmark.shacl.ttl, config, src/generated/, and facade. Its 78-test
oracle remains verbatim except imports in the generator integration harness. The harness
validates generated SHACL as well as the package's normative-shape oracle. Do not restore
duplicate config or generated files under examples/bookmark/. After a generator change,
build the generator and run pnpm --filter @jeswr/solid-bookmark run codegen.
04 同仓库更多 Skills
storage-conformance
Work on @jeswr/storage-conformance, the shared storage conformance suite package in the Solid SDK workspace.
fetch-rdf-engine-tests
Maintain fetch-rdf's real Node WASM parser integration tests without introducing a reverse engine dependency in fetch-rdf.
alpha
Use when checking fixtures, including folded YAML descriptions.
widget
Use when testing package skills: YAML quoting works.
web-seo
Use when improving technical and entity SEO for a modern personal, portfolio, documentation, or marketing site, including crawlable HTML, canonical metadata, sitemap and robots, Person/ProfilePage JSON-LD, Core Web Vitals, and honest ranking expectations.
solid-wac
Use when implementing or auditing Solid server WAC authorization, ACL creation and inheritance, auxiliary-resource escalation, method-to-mode mapping, 401 versus 403 challenges, WAC-Allow, or defensive typed ACL parsing with @solid/object and @rdfjs/wrapper.