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
23 changes: 23 additions & 0 deletions changelog.d/explorer-rust.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- **Rust: the model explorer with no Node.** The Rust port builds the docs view from its loaded
model (`metaobjects::docs_view::build`), byte for byte what TypeScript builds for every
`fixtures/explorer-conformance/` case. A new opt-in `docs-site` generator writes
`explorer.json`, the explorer app, `explorer-model.js` and `explorer-stamp.js` under
`site/`. It reads prompt texts from the metadata directories, `templates/` and a `prompts`
directory, and takes `subDir`, `title`, `stamp`, `verifyFile` and `routesFile` as options.
Each node lists the files generated for it: this run's (the engine runs the site after every
other generator) and the committed manifest's outside the run, so `cargo meta verify` renders
what `gen` wrote. The site builder is engine, as in every port: `cargo meta eject docs-site`
refuses, `gen --list` marks it `[package-only]`, and an owned theme in `codegen/docs-site/`
replaces the shipped one. The app files are a canonical copy in the crate
(`metaobjects-codegen/explorer-app/`, held to the root `explorer-app/` by the
`explorer app copies` gate) and ship in the published package. The running application can serve
the same view at `{apiPrefix}/_meta/docs`: `metaobjects::meta_endpoint::docs` builds it once and
carries its ETag, and the host mounts it as it mounts `/_meta` (`meta_endpoint::meta_json`,
new in Rust too).

Rust codegen now also records which node each generated file came from, `{ "hash",
"generatedBy", "sourceNode" }` in the hash manifest, held to the shared `provenance` vector in
`fixtures/codegen-skip-conformance/manifests.json`. A file rendered for no single node, such as
a shared `meta_*` crate's, keeps the plain hash. Upgrading: the next `cargo meta gen` rewrites
the committed `.metaobjects/.gen-state/.hashes/` files once. Commit them; generated source
files do not change.
5 changes: 3 additions & 2 deletions docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/cube-model/`](../fixtures/cube-model/) (FR-044 Plan 4 — the `cube-model` generator's golden Cube files, plus the canonical model's golden) | 46 cases (36 trees + 10 errors) + 1 canonical golden | ✓ (the exporter is TypeScript-only, spec R6; its `cube` lane also loads the files into a real Cube) | — | — | — | — | — |
| [`fixtures/writer-conformance/`](../fixtures/writer-conformance/) (ADR-0063 — the code writer generators write through) | 88 cases (31 core + 10 TypeScript + 9 Java + 12 Kotlin + 6 C# + 12 Python + 8 Rust) | ✓ (the first writer; core and TypeScript dialect) | ✓ (core and Java dialect; `JavaWriter` in `codegen-base`) | ✓ (core and Kotlin dialect; `KotlinWriter` in `codegen-kotlin`) | ✓ (core and C# dialect) | ✓ (core and Python dialect) | ✓ (core and Rust dialect) |
| [`fixtures/contract-conformance/`](../fixtures/contract-conformance/) (FR-022 — the `contract-schema` and `openapi` generators' golden trees and refusals) | 22 cases (17 trees + 5 errors) | ✓ (one neutral engine, ADR-0034 Amendment 10; the generated API lanes also hold real traffic to the documents) | — | — | — | — | — |
| [`fixtures/explorer-conformance/`](../fixtures/explorer-conformance/) (the docs view: a loaded project + the verify payload, manifest and routes in, one `explorer.json` out) | 3 cases (`shop`, `crm`, `model-alone`) | ✓ | ✓ (`DocsView`, and the `docs-site` generator end to end) | ✓ (the JVM builder, through `codegen-kotlin`'s `docs-site`) | ✓ (`MetaObjects.DocsView`, and the `docs-site` generator end to end) | ✓ (`metaobjects.docs_view`, and the `docs-site` generator end to end) | — |
| [`fixtures/explorer-conformance/`](../fixtures/explorer-conformance/) (the docs view: a loaded project + the verify payload, manifest and routes in, one `explorer.json` out) | 3 cases (`shop`, `crm`, `model-alone`) | ✓ | ✓ (`DocsView`, and the `docs-site` generator end to end) | ✓ (the JVM builder, through `codegen-kotlin`'s `docs-site`) | ✓ (`MetaObjects.DocsView`, and the `docs-site` generator end to end) | ✓ (`metaobjects.docs_view`, and the `docs-site` generator end to end) | ✓ (`metaobjects::docs_view`, and the `docs-site` generator end to end) |

**Rust (ADR-0065)** joined the table with its service stack. Its ledgers (the metamodel
corpus's `server/rust/metaobjects/tests/conformance-expected-failures.json`, empty; the YAML
Expand Down Expand Up @@ -916,7 +916,8 @@ Java (`metadata`'s `DocsViewConformanceTest`, and `codegen-base`'s `ExplorerSite
generator) and Kotlin (`KotlinDocsSiteConformanceTest`, through its registry's `docs-site`) build
every case byte for byte; the JVM has one builder, which Kotlin calls rather than re-implements.
C# (`MetaObjects.DocsView`, through `DocsSiteGenerator` and `MetaEndpoint.MetaDocs`) and Python
(`metaobjects.docs_view`, through `docs-site` and `meta_docs`) build every case byte for byte too.
(`metaobjects.docs_view`, through `docs-site` and `meta_docs`) build every case byte for byte too; and Rust
(`metaobjects::docs_view`, through `docs-site` and `meta_endpoint::docs`) does too.

**TypeScript runs it** in
`server/typescript/packages/metadata/test/docs-view-conformance.test.ts` (the view) and
Expand Down
11 changes: 5 additions & 6 deletions docs/features/docs-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ writes the same bytes for the same model, and the shared corpus
[`fixtures/explorer-conformance/`](../../fixtures/explorer-conformance/) holds them to that.

TypeScript builds it today, and so do Java and Kotlin (one JVM builder, `DocsView` in
`metadata`), C# (`MetaObjects.DocsView`) and Python (`metaobjects.docs_view`). `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)). Rust will build
it as its own step of the same plan ([explorer-data.md](explorer-data.md#not-built-yet)). The
explorer pages still render their HTML in TypeScript; the JVM, C# and Python copy the app and
write the same `explorer.json`.
`metadata`), C# (`MetaObjects.DocsView`), Python (`metaobjects.docs_view`) and Rust
(`metaobjects::docs_view`). `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 explorer pages still render their HTML in
TypeScript; the JVM, C#, Python and Rust copy the app and write the same `explorer.json`.

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
Expand Down
10 changes: 4 additions & 6 deletions docs/features/explorer-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ manifest reader takes `hash` from either form.
`gen --list` shows, in every port. The provenance field is named `generatedBy`, not `generator`. In a Java or Kotlin module's
manifest, `generator` means that generator owns the file (ADR-0060), and the orphan sweep acts
on that ownership, so a JVM entry carries both: `{ "hash", "generator", "outputDir",
"generatedBy", "sourceNode" }`. The four ports that write provenance write the same entry for the
"generatedBy", "sourceNode" }`. The five ports that write provenance write the same entry for the
same records; the shared vector `provenance` in
[`fixtures/codegen-skip-conformance/manifests.json`](../../fixtures/codegen-skip-conformance/manifests.json)
holds TypeScript, C#, Java and Python to it. Kotlin and Rust write no provenance yet.
holds TypeScript, C#, Java, Python and Rust to it. Kotlin writes no provenance yet.

## Building it by hand

Expand Down Expand Up @@ -157,10 +157,8 @@ malformed leaves its part of the view empty.

- **`usage`**: which hand-written modules import a generated module. The design marks it
optional, and nothing builds it yet.
- **Provenance from the Kotlin and Rust generators.** Their manifest entries have no
`sourceNode` yet, so for those ports a node lists no files.
- **The docs view in Rust.** TypeScript, Java, Kotlin, C# and Python build it today, each held
to the corpus byte for byte; Rust will be held to the same corpus.
- **Provenance from the Kotlin generators.** Their manifest entries have no
`sourceNode` yet, so for that port a node lists no files.

## Verified by

Expand Down
16 changes: 10 additions & 6 deletions docs/features/explorer-site.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ same model and inputs: every port that builds the docs view is held to
| Kotlin | the same JVM `DocsSiteGenerator`, through `codegen-kotlin`'s registry | The app only | As Java; the Kotlin generators do not record provenance in the manifest yet, so their files are not listed |
| C# | `docs-site` (`dotnet meta gen`, `MetaObjects.Codegen.Generators.DocsSiteGenerator`), no Node | The app only | The model, the files generated per node (this run's, and what the committed hash manifest records outside the directories the run's orphan sweep clears), and a `verify --format json` payload (`VerifyFile`) and a routes file (`RoutesFile`) when you name them |
| Python | `docs-site` (`metaobjects gen`, `metaobjects.codegen.generators.docs_site_generator`), no Node | The app only | As C# (`verify_file`, `routes_file`) |
| Rust | not yet | | |
| Rust | `docs-site` (`cargo meta gen`, `metaobjects_codegen::DocsSiteGenerator`), no Node | The app only | As C# (`verifyFile`, `routesFile`). Options and the owned theme: [the Rust port](../ports/rust.md#docs-site-the-model-explorer) |

On the JVM, wire it like any other generator, with its own output directory:

Expand Down Expand Up @@ -299,14 +299,11 @@ a dangling link. `createExplorer` (the page table both outputs draw from) and

- An LLM-written summary, a test-result overlay, zoom levels and lenses on the map, and
publishing the site.
- The docs view route and the app in Rust: the contract is in
[metadata-api.md](metadata-api.md#the-docs-view-endpoint-get-_metadocs). Java, Kotlin, C#
and Python ship both.
- The static export and the classic site outside TypeScript.
- "Hand-written code that imports it": the site reads no import graph, so the object pages say
it was not scanned.
- Generated-file provenance from the Kotlin and Rust generators (see
[explorer-data.md](explorer-data.md)), so for those ports the generated-file lists are empty.
- Generated-file provenance from the Kotlin generators (see
[explorer-data.md](explorer-data.md)), so for that port the generated-file lists are empty.

## Verified by

Expand All @@ -317,6 +314,13 @@ a dangling link. `createExplorer` (the page table both outputs draw from) and
stamp, an owned theme wins, and the generator lists the manifest's files.
- `server/java/metadata/src/test/java/com/metaobjects/io/json/MetaDocsEndpointTest.java`: the
JVM docs view route body is the `model-alone` view, and its ETag is TypeScript's.
- `server/rust/metaobjects/tests/docs_view_conformance.rs`: the Rust docs view builder writes
every `fixtures/explorer-conformance/` case byte for byte, and the `/_meta/docs` body is the
`model-alone` view with TypeScript's ETag.
- `server/rust/metaobjects-codegen/tests/docs_site.rs`: the Rust site's app files are the
canonical copy, its model script has TypeScript's bytes and stamp, an owned theme wins, prompt
texts are read only inside the prompt directories, and a `cargo meta gen` run writes the shop
case's `explorer.json` over the manifest's files and verifies clean.
- `server/typescript/packages/docs-site/test/explorer-app.test.ts`: the files the app output
writes, the model and stamp files, owned templates and theme, and the committed bundle, run
outside a browser, drawing every page the static export writes byte for byte on the shop, crm
Expand Down
43 changes: 41 additions & 2 deletions docs/features/metadata-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ the package, including consumers with no HTTP surface at all.
| Java (`metaobjects-metadata`) | `com.metaobjects.io.json.MetaEndpoint.META_ROUTE_PATH`, `MetaEndpoint.metaJson(MetaData root)` | Host mounts — `core-spring` carries `spring-context` but no `spring-web` |
| Kotlin | consumes the Java `MetaEndpoint` symbol directly via the `metadata-ktx` facade — there is no separate Kotlin implementation | Host mounts |
| Python (`metaobjects`) | `META_ROUTE_PATH`, `meta_json(root)` (both exported from the package root) | Host mounts — neither `metaobjects.runtime` nor `metaobjects.codegen.runtime` imports a web framework |
| Rust (`metaobjects`) | `metaobjects::meta_endpoint::META_ROUTE_PATH`, `meta_endpoint::meta_json(&tree, root)` | Host mounts — the `metaobjects` crate depends on no web framework |

The response body is not a new thing to gate: each helper is a thin wrapper
over that port's already-conformance-gated effective serializer
(`canonicalSerializeEffective` / `SerializerJson.CanonicalSerializeEffective`
/ `CanonicalJsonSerializer.canonicalSerializeEffective` /
`canonical_serialize_effective`), so `/_meta`'s bytes ride on the existing
`canonical_serialize_effective`, in Python and in Rust), so `/_meta`'s bytes ride on the existing
metadata conformance corpus rather than a new one built for this endpoint.
The exact `content-type` header value is a per-port detail, not a pinned
cross-port byte — TypeScript's mounts emit
Expand Down Expand Up @@ -153,6 +154,20 @@ def meta() -> Response:
return Response(meta_json(root), media_type="application/json")
```

### Rust — axum

```rust
use axum::{Router, routing::get};
use metaobjects::meta_endpoint::{META_ROUTE_PATH, meta_json};

// tree, root: the model this app loaded. Serialized once: the model does not change after load.
let body = meta_json(&tree, root);
let app = Router::new().route(
&format!("/api{META_ROUTE_PATH}"),
get(move || async move { ([("content-type", "application/json")], body) }),
);
```

## Exposure

Mounting `/_meta` is **opt-in** in every port — nothing registers it
Expand Down Expand Up @@ -263,7 +278,31 @@ under the same guard. C#: `MetaEndpoint.MetaDocs(root)` gives the body, `ETag` a
`Matches(ifNoneMatch)` (`MetaEndpoint.MetaDocsRoutePath`, `MetaDocsJson(root, routes)`).
Python: `meta_docs(root)` gives `body`, `etag` and `matches(if_none_match)`
(`META_DOCS_ROUTE_PATH`, `meta_docs_json(root, routes)`). Each helper's doc comment shows the
ASP.NET or FastAPI mount. Rust serves the route once it has its docs view builder.
ASP.NET or FastAPI mount.

Rust ships the same helper in `metaobjects::meta_endpoint`, framework-free, and leaves the mount
to the host under the same guard: `docs(&tree, root, routes)` builds the view once and gives
`body`, `etag` and `matches(if_none_match)` (`META_DOCS_ROUTE_PATH`,
`meta_docs_json(&tree, root, routes)`, `meta_docs_etag`). With axum:

```rust
use axum::{http::{HeaderMap, StatusCode, header}, response::IntoResponse, routing::get};
use metaobjects::meta_endpoint::{META_DOCS_ROUTE_PATH, docs};

let docs = std::sync::Arc::new(docs(&tree, root, None));
let app = app.route(
&format!("/api{META_DOCS_ROUTE_PATH}"),
get(move |headers: HeaderMap| async move {
let tag = headers.get(header::IF_NONE_MATCH).and_then(|v| v.to_str().ok());
let common = [(header::ETAG, docs.etag.clone()), (header::CACHE_CONTROL, "no-cache".into())];
if docs.matches(tag) {
(StatusCode::NOT_MODIFIED, common).into_response()
} else {
(common, [(header::CONTENT_TYPE, "application/json")], docs.body.clone()).into_response()
}
}),
);
```

## Browser consumption

Expand Down
Loading
Loading