Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,22 @@ four `rules.*` and `verify.lifecycle.unreachable` settings, held to `fixtures/ru
reference, never because its text matches a name, and a map-valued attribute such as
`@filter` prints its keys sorted. A theme ejected from an rc needs no change.
Generated-output change — regenerate to pick it up; three-way merge preserves hand edits.
- **codegen-ts: the `template` generator renders the docs view.** Documentation pages are
ordinary configured Mustache templates. Two new scopes walk the docs view: `perNode` (one file
per top-level node of any type, filtered with `match`: `"<type>.<subType>"`, `"<type>.*"`, `"*"`
or a list; `"*"` skips requirement nodes, which `perRequirement` owns) and `perRequirement` (one per requirement at any depth). `perModel` and `perPackage`
read the view with `data: "docsView"`; without it they keep the per-entity dictionary, so an
existing spec renders the same bytes. `{path}` in `outputPattern` is the page the view gives a
node or requirement, and every docs-view page gets `root`, the way back to the site root, so
`{{root}}{{path}}` links from any page. `subDir` sets the directory the paths are relative to,
`assets: { from }` copies a directory of text files into `subDir`, and `linkCheck: true`
fails the run, writing nothing, when a relative link in an entry's HTML pages lands on no file or
anchor. The same keys work in a JSON template spec (`template-spec.schema.json`).
`Generator.checkRunOutput` is the hook that runs the check once every generator has rendered;
`@metaobjectsdev/docs-site` exports the link check as `findDanglingLinks`. Gated by the new
`docs-view/` case of `fixtures/template-codegen-conformance/`, which TypeScript runs today and
the other ports take on with their own docs view. The explorer site is unchanged. See
`docs/features/codegen-concepts.md`, "Templates over the docs view".
- **`@flattenedColumnPrefix`: name a flattened value object's columns.** On a `field.object` with
`@storage: "flattened"`, it replaces the default prefix (the field's column and `_`) verbatim;
`""` keeps the members' own column names. It sits on the embedding field because one value
Expand Down
2 changes: 1 addition & 1 deletion docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/registry-conformance/`](../fixtures/registry-conformance/) | 1 canonical manifest | ✓ (reference emitter) | ✓ | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/object-model-conformance/`](../fixtures/object-model-conformance/) | 1 shared metadata fixture (per-port scenarios) | ✓ | ✓ | ✓ | ✓ | ✓ | — |
| [`fixtures/codegen-conformance/`](../fixtures/codegen-conformance/) | 7 shared inputs; `shared-provided-enum` carries the enum-type decision table and `cross-package-binding` the reference-binding decision table (ADR-0059) every port answers; `xpkg-value-object-refs` (ruling R52) is run by C# and TypeScript only so far — Java, Kotlin and Python in [#544](https://github.com/metaobjectsdev/metaobjects/issues/544)–#549 | ✓ | ✓ | ✓ | ✓ | ✓ | — |
| [`fixtures/template-codegen-conformance/`](../fixtures/template-codegen-conformance/) | 3 | ✓ | ✓ | ✓ | ✓ | ✓ | — |
| [`fixtures/template-codegen-conformance/`](../fixtures/template-codegen-conformance/) | 3 + the `docs-view/` case (16 files: the docs-view scopes, `{path}`, `subDir`, assets and the link check) | ✓ (both) | ✓ (root case; `docs-view/` planned) | ✓ (root case; `docs-view/` planned) | ✓ (root case; `docs-view/` planned) | ✓ (root case; `docs-view/` planned) | — |
| [`fixtures/template-output-render-conformance/`](../fixtures/template-output-render-conformance/) | 5 | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ (generated `render-helper` crates) |
| [`fixtures/generator-registry-conformance/`](../fixtures/generator-registry-conformance/) | 1 canonical manifest | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/provider-composition-conformance/`](../fixtures/provider-composition-conformance/) | 18 (11 error-shape + 4 compose-load + 3 attr-ownership) | ✓ | ✓ | — (JVM registry via Java) | ✓ | ✓ | — |
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ docs/
│ ├── yaml-authoring.md
│ ├── cli.md # CLI command matrix across all five ports
│ ├── language-differences.md # what differs by language: Node for the schema, list defaults, error bodies, names, data access
│ ├── codegen-concepts.md # declarative template-codegen scopes (perEntity/perPackage/perModel)
│ ├── codegen-concepts.md # declarative template-codegen scopes (perEntity/perPackage/perModel; TypeScript adds the docs-view scopes)
│ ├── codegen-data-shapes.md # the neutral template data dict shared cross-port
│ ├── downstream-metadata-decisions.md # guidance for adopters extending the metamodel
│ ├── semantic-modelling.md # how to shape vocabulary of your own: type, subtype, generator and configuration
Expand Down
58 changes: 56 additions & 2 deletions docs/features/codegen-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ pattern instead of hand-rolled grouping.
### Declarative template scopes

A `templateGenerator` can take the scope walk declaratively instead of a hand-written
`walk` — pass `scope` (`"perEntity" | "perPackage" | "perModel"`) plus an
`outputPattern`, and the generator derives the neutral template data dict per unit and
`walk` — pass `scope` (`"perEntity" | "perPackage" | "perModel"`; TypeScript also
takes the docs-view scopes, below) plus an `outputPattern`, and the generator derives the neutral template data dict per unit and
names each file via the pattern. `walk` and `scope` are mutually exclusive — provide
exactly one. The `outputPattern` placeholders are `{name}`, `{Name}`, and `{package}`
(an unknown placeholder throws); `{package}` resolves through `effectivePackage` and
Expand All @@ -267,6 +267,60 @@ templateGenerator({
});
```

#### Templates over the docs view (TypeScript)

A template can also read the **docs view** ([docs-view.md](docs-view.md)): every top-level
node of every type, its effective attributes, members, references both ways, the
requirements that claim it, and the requirement tree. Documentation is then ordinary
template codegen, configured like any other entry. Two scopes walk it:

- **`perNode`**: one file per top-level node of any type, filtered with `match`: a
pattern `"<type>.<subType>"`, `"<type>.*"` or `"*"` (the default), or a list of them.
`"*"` skips requirement nodes, because `perRequirement` owns their pages; a pattern that
names the requirement type (`"requirement.*"`) still selects them.
- **`perRequirement`**: one file per requirement at any depth, filtered the same way
(`"requirement.functional"`).

`perModel` and `perPackage` read the view when the entry says `data: "docsView"`;
without it they keep the per-entity dictionary above, so an existing spec is unchanged.
A docs-view page's data is the whole view, plus the unit (`node`, `requirement` or
`package`) and `root`, the way from the page back to the site root. `{path}` in the
`outputPattern` is the page the view gives a node or requirement, so a link is
`<a href="{{root}}{{path}}">` and lands whichever page it is written from.

Three more keys build a site:

- **`subDir`**: the directory under the target the output paths, and `root`, are
relative to.
- **`assets`**: `{ "from": "<dir>" }` copies every file under a project directory into
`subDir`, at its path relative to `from`. Text files only; a file that is not UTF-8 is
refused.
- **`linkCheck: true`** (with `format: "html"`): once the whole run has rendered, every
relative link in the entry's pages must name a file the run wrote (or one already on
disk, unless it is a generated file a full run no longer produces and so deletes) and,
with `#anchor`, an element with that `id`. A link that lands on nothing fails
the run, naming the page and the link, and nothing is written.

```json
{ "generators": [
{ "name": "site-index", "template": "index", "scope": "perModel", "data": "docsView", "subDir": "site",
"outputPattern": "index.html", "format": "html", "assets": { "from": "site-assets" } },
{ "name": "site-objects", "template": "object", "scope": "perNode", "match": "object.*", "subDir": "site",
"outputPattern": "{path}", "format": "html", "linkCheck": true },
{ "name": "site-requirements", "template": "requirement", "scope": "perRequirement", "subDir": "site",
"outputPattern": "{path}", "format": "html", "linkCheck": true }
] }
```

The view is built from the model the run loaded, the requirement ledger `meta gen`
computed and the files and routes the rest of the run produced, so an entry that reads it
runs after the other generators. Templates should stay inside the subset every port's
engine renders alike: the view supplies counts and booleans, so a template never needs
`.length`, a number's truth or a dotted name shadowed inside a loop. TypeScript runs these
scopes today, gated by `fixtures/template-codegen-conformance/docs-view/`; the other ports
take them on with their own docs view. The model explorer (`docsSiteFile()`) is not built
this way yet.

The same declarative surface is available on the **JVM (Java + Kotlin)** via
`TemplateScopeGenerator` (`com.metaobjects.generator.template`), a Maven-wirable
generator over the byte-equivalent render engine. Wire it as a standard
Expand Down
7 changes: 6 additions & 1 deletion docs/features/codegen-data-shapes.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ it. The field names are a byte-gated **cross-port contract** (the
`fixtures/template-codegen-conformance/` corpus locks them) — change them only via
the spec.

The `perNode` and `perRequirement` scopes, and `data: "docsView"` on `perModel` and
`perPackage`, feed the **docs view** instead ([docs-view.md](docs-view.md)), the same facts
the documentation pages read, pinned by `fixtures/template-codegen-conformance/docs-view/`
([codegen-concepts.md](codegen-concepts.md#templates-over-the-docs-view-typescript)).

```ts
interface FieldTemplateData {
name: string;
Expand Down Expand Up @@ -244,5 +249,5 @@ Mermaid diagram):
5. Document the new shape on this page under a new section.

The `templateGenerator()` factory does the rest — no new generator scaffolding is
needed. Take the built-in `scope` + `outputPattern` walk when one of the three scopes
needed. Take the built-in `scope` + `outputPattern` walk when one of the scopes
fits; supply your own `walk` only when it does not.
10 changes: 8 additions & 2 deletions docs/features/docs-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,14 @@ writes the same bytes for the same model, and the shared corpus
TypeScript builds it today. `buildDocsView` and `serializeDocsView` are exported from
`@metaobjectsdev/metadata`, and `docsSiteFile()` writes the result as the site's
`explorer.json` (see [explorer-site.md](explorer-site.md)). The other ports build it as their
own step of the same plan. The explorer pages still render their HTML in TypeScript; moving that
into templates is a later step.
own step of the same plan. The explorer pages still render their HTML in TypeScript.

A page of your own is a template over the view: the TypeScript `template` generator renders it
with the `perNode` and `perRequirement` scopes (and `data: "docsView"` on `perModel` and
`perPackage`), writes each page at its `path` with `{path}` in the output pattern, and hands
every page a `root` so `{{root}}{{path}}` links from anywhere. It can copy a directory of
assets beside the pages and check that every link lands. See
[codegen-concepts.md](codegen-concepts.md#templates-over-the-docs-view-typescript).

## What it is built from

Expand Down
8 changes: 5 additions & 3 deletions docs/ports/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default defineConfig({
templateGenerator({
name: "entity-service", // kebab-case; surfaces in diagnostics
template: "service/entity-service", // → templates/service/entity-service.mustache
scope: "perEntity", // "perEntity" | "perPackage" | "perModel"
scope: "perEntity", // "perEntity" | "perPackage" | "perModel" | "perNode" | "perRequirement"
outputPattern: "{package}/{Name}Service.ts",
// format: "text", // optional escaper; defaults to "text"
// target: "api", // optional named output target
Expand All @@ -219,8 +219,10 @@ Templates resolve through the project's `templates/` directory first, then the f
defaults — so `template: "service/entity-service"` reads
`<projectRoot>/templates/service/entity-service.mustache`. The `outputPattern`
placeholders are `{name}`, `{Name}` and `{package}` (whose `::` segments become nested
directories); an unknown placeholder throws. Abstract objects are excluded from every
scope.
directories), and `{path}` for the docs-view scopes `perNode` and `perRequirement`
([templates over the docs view](../features/codegen-concepts.md#templates-over-the-docs-view-typescript));
an unknown placeholder throws. Abstract objects are excluded from every
scope that reads the per-entity dictionary; the docs-view scopes include them.

`scope` and `walk` are mutually exclusive — supply exactly one. Take a `scope` when one
of the three walks fits; supply your own `walk` when it does not.
Expand Down
26 changes: 24 additions & 2 deletions fixtures/template-codegen-conformance/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Every port runs `spec.json` (a list of `{ name, template, scope, outputPattern }
generators) over `metadata/meta.shop.json`, resolving templates from `templates/`,
and must produce output **byte-identical** to `expected/`.

The corpus exercises all three built-in scopes:
The root case exercises the three per-entity-dictionary scopes:

- **`perEntity`** (`entity.mustache` → `<Name>.txt`) — the neutral per-entity data
dict: fields (name/type/required/isArray/maxLength), and Order's `product`
Expand All @@ -20,6 +20,28 @@ this corpus gates the *new* surface: the structural data dict, the scope names
(`perEntity`/`perPackage`/`perModel`), and the output-pattern grammar
(`{name}`/`{Name}`/`{package}`).

## The `docs-view/` case

`docs-view/` is a second case with its own `spec.json`, `metadata/` (every file, loaded
together), `templates/`, `site-assets/` and `expected/`. Its entries read the **docs view**
(`docs/features/docs-view.md`) of the model alone: no verify payload, manifest or routes,
so `sources` is all `false`. It gates:

- the `perNode` scope with `match` (`"object.*"`, and a list `["object.entity"]`) and the
`perRequirement` scope, each at `{path}`;
- `data: "docsView"` on `perModel` and `perPackage`;
- `subDir` (the site under `site/`) and `root`, the way back to it, used by every link
(`{{root}}{{path}}`) and by a Markdown entry outside the site (`briefs/`);
- `assets` (`site-assets/assets/` copied to `site/assets/`);
- `linkCheck`: every relative link in the checked entries lands on a file and an anchor,
including links to pages a later entry renders.

The templates stay inside the subset every port's engine renders alike: no `.length`, no
number's truth, no dotted name inside a loop. TypeScript runs this case today; another port
runs it once it builds the docs view. A port that has no link check still matches the bytes.

Regenerate `expected/` after an intentional change to the data dict or scope walks
by pointing the generator at the `expected/` directory and committing the result
(see each port's conformance test).
(see each port's conformance test). In TypeScript:
`UPDATE_TEMPLATE_CONFORMANCE=1 bun test packages/codegen-ts/test/template-codegen/conformance.test.ts`
from `server/typescript/` rewrites both cases.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Invoice

Site root: `../../../`
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# BaseEntity

Site root: `../../../`
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Customer

Site root: `../../../`
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Order

Site root: `../../../`
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
body { font-family: sans-serif; }
.missing { color: #b00; }
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<link rel="stylesheet" href="assets/css/site.css">
<p><a href="index.html">Home</a></p>

<h1>Model</h1>
<p>6 nodes, 4 requirements.</p>
<ul>
<li>acme::billing (1)</li>
<li>acme::shop (5)</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!doctype html>
<link rel="stylesheet" href="../../../assets/css/site.css">
<p><a href="../../../index.html">Home</a></p>

<h1>Invoice</h1>
<p class="kind">object.entity</p>


<h2>source (1)</h2>
<table>
<tr id="m-source-0"><td></td><td>rdb</td><td></td></tr>
</table>
<h2>field (2)</h2>
<table>
<tr id="m-id"><td>id</td><td>long</td><td></td></tr>
<tr id="m-orderId"><td>orderId</td><td>long</td><td></td></tr>
</table>
<h2>identity (1)</h2>
<table>
<tr id="m-identity-pk"><td>pk</td><td>primary</td><td></td></tr>
</table>
<h2>relationship (1)</h2>
<table>
<tr id="m-relationship-order"><td>order</td><td>association</td><td></td></tr>
</table>
<h2>References</h2>
<ul>
<li>objectRef on <a href="../../../model/acme/billing/Invoice.html#m-relationship-order">Invoice.order</a>: <a href="../../../model/acme/shop/Order.html">Order</a></li>
</ul>
<h2>Referenced by</h2>
<ul>
</ul>
<h2>Claimed by</h2>
<ul>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!doctype html>
<link rel="stylesheet" href="../../../assets/css/site.css">
<p><a href="../../../index.html">Home</a></p>

<h1>BaseEntity</h1>
<p class="kind">object.entity (abstract)</p>


<h2>field (1)</h2>
<table>
<tr id="m-id"><td>id</td><td>long</td><td></td></tr>
</table>
<h2>identity (1)</h2>
<table>
<tr id="m-identity-pk"><td>pk</td><td>primary</td><td></td></tr>
</table>
<h2>References</h2>
<ul>
</ul>
<h2>Referenced by</h2>
<ul>
<li><a href="../../../model/acme/shop/Customer.html">Customer</a> (extends)</li>
<li><a href="../../../model/acme/shop/Order.html">Order</a> (extends)</li>
</ul>
<h2>Claimed by</h2>
<ul>
<li><a href="../../../requirements/acme/shop/Addressable.html">Addressable</a> live</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!doctype html>
<link rel="stylesheet" href="../../../assets/css/site.css">
<p><a href="../../../index.html">Home</a></p>

<h1>Customer</h1>
<p class="kind">object.entity</p>
<p>Someone who buys from the shop.</p>
<p>Extends <a href="../../../model/acme/shop/BaseEntity.html">BaseEntity</a></p>
<h2>field (2)</h2>
<table>
<tr id="m-id"><td>id</td><td>long</td><td>from <a href="../../../model/acme/shop/BaseEntity.html">BaseEntity</a></td></tr>
<tr id="m-email"><td>email</td><td>string</td><td></td></tr>
</table>
<h2>identity (1)</h2>
<table>
<tr id="m-identity-pk"><td>pk</td><td>primary</td><td>from <a href="../../../model/acme/shop/BaseEntity.html">BaseEntity</a></td></tr>
</table>
<h2>source (1)</h2>
<table>
<tr id="m-source-2"><td></td><td>rdb</td><td></td></tr>
</table>
<h2>References</h2>
<ul>
<li>extends: <a href="../../../model/acme/shop/BaseEntity.html">BaseEntity</a></li>
</ul>
<h2>Referenced by</h2>
<ul>
<li><a href="../../../model/acme/shop/Order.html">Order</a> (objectRef)</li>
<li><a href="../../../model/acme/shop/Order.html">Order</a> (references)</li>
</ul>
<h2>Claimed by</h2>
<ul>
</ul>
Loading
Loading