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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ PyPI has had no product change since `0.25.0` — nothing is broken.
- **Kotlin** — `codegen-kotlin` (KotlinPoet on JVM): entity + Exposed table + Spring controller + payload + relations + filter allowlist + validator + stored-proc + output-parser generators. `integration-tests-kotlin` runs the persistence-conformance corpus through Exposed against Testcontainers Postgres.

**Cross-port conformance corpora** (every port runs the shared corpus):
- Metamodel: `fixtures/conformance/` (510 fixtures; 40 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green.
- Metamodel: `fixtures/conformance/` (510 fixtures; 41 shared corpora in total — per-corpus counts + the corpus x port matrix live in `docs/CONFORMANCE.md`). TS / C# / Java / Python all green.
- Render: `fixtures/render-conformance/`. TS / C# / Java / Kotlin / Python byte-identical.
- Persistence: `fixtures/persistence-conformance/`. **Query** scenarios run on every port (TS / C# / Java / Kotlin / Python), each provisioning its test DB by executing the committed, TS-produced `canonical/schema.postgres.sql` (Postgres only — Derby dropped for the cross-port query corpus, ADR-0015; the FR-044 `report-*` scenarios also run on SQLite, MySQL and D1 where a port has the engine, see [docs/CONFORMANCE.md](docs/CONFORMANCE.md)). The **migration** scenarios are exercised by **TS only** (TS owns schema migrations). **The corpus now gates WRITES, not just reads (SP-H):** an `op: roundtrip` scenario type INSERTs through each port's runtime/ORM write codec (NOT raw SQL), reads the row back, and asserts the wire-normalized value. The `AllTypes` entity (`roundtrip-all-types.yaml`) carries one field of **every** persistable `field.*` subtype — string/int/long/double/float/decimal/boolean/date/time/timestamp(+tz)/currency/enum/uuid/object — plus an **array-of-VO** `field.object @isArray @storage:jsonb` column (`labels`, written as 2-element / empty-`[]` / single-element arrays across the three rows) — so every subtype write+read (incl. the array-of-value-object jsonb codec) round-trips through every port against Testcontainers PG. (`field.byte`/`field.short`/`field.class` were cut as non-functional registration-only stubs — the matrix tracks only genuinely-supported subtypes; see `fixtures/registry-conformance/README.md` → "Per-subtype write-round-trip matrix".)
- API-contract: `fixtures/api-contract-conformance/`. TS / C# / Java / Kotlin / Python all green — each port runs **two lanes**: a hand-rolled reference server AND its **generated** API artifact booted over HTTP (the deployed controller/routes; TS+C# full-stack vs Testcontainers PG, Java/Kotlin/Python generated controller + in-memory repo behind the consumer seam). The generated fan-out found 10 real deployment bugs golden snapshots missed. Three sub-corpora run the **generated lane only, on all five ports** — `write-through/`, `projection/` (F22: a view-only `object.projection` serves GET list + GET by id and answers every write verb with `405 {"error": "method_not_allowed"}`) and `report/` (FR-044: a view-backed `object.report` serves GET list, answers `POST` with that same `405`, and mounts no `/{id}` route). That is deliberate, not a gap: what is under test is whether a port's GENERATOR emits those routes, and a hand-rolled reference server would answer every scenario by construction. The `m2m/` sub-corpus also gates **TPH x M:N together** (base-declared, subtype-declared, abstract-mid-declared, a non-subtype source onto a subtype TARGET, and the cross-subtype source id answering `200 []`) — the two corpora were originally built disjoint (`tph/` had no relationships, `m2m/` no discriminators), which is precisely how that defect class survived.
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ loaded before stops loading. This vocabulary ships in 1.3.0 with `metamodelVersi

### Added

- **A code writer for generators: `CodeWriter` and `TsWriter` in `@metaobjectsdev/codegen-ts`**
(ADR-0063). A generator says what a line contains, and the writer decides where it sits. It
builds the file in memory with no formatter. It collects imports while the body is written,
treats blank lines as requests that collapse, and prints a list on one line when the line fits
120 columns, otherwise one item per line. `TsWriter` accepts ts-poet `Code` fragments and
collects their `imp()` imports, so a generator can move to it one function at a time. The
writer is exported from the package root and from `@metaobjectsdev/codegen-ts/engine`, so an
owned (ejected) generator can use it too. Both classes are built to be extended: every
method is public or protected, so a subclass can override one step, such as import order,
and keep the rest. ADR-0063 also rules that reference generators will be extended the same
way, one overridable method per piece of output, without promising those methods are stable
between minor versions. The contract is `spec/code-writer.md`, pinned by
the new `fixtures/writer-conformance/` corpus. No shipped generator uses the writer yet, so
generated output does not change in this release.

- **A page size for generated list routes: `api.pagination`, in every port.** An external review
of 1.2.0 found that list endpoints had no hard cap: the TypeScript and C# routes returned the
whole table when `limit` was omitted, and `?limit=100000` was accepted in every port. The new
Expand Down
6 changes: 4 additions & 2 deletions docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Conformance coverage

The MetaObjects standard ships **40 shared conformance corpora** under
The MetaObjects standard ships **41 shared conformance corpora** under
[`fixtures/`](../fixtures/). Every port runs every corpus that is *applicable to
it* and asserts the same expected behaviour against the same fixtures. **This page
is the inverse index**: fixture → feature doc + per-port pass status, and it is the
Expand Down Expand Up @@ -64,6 +64,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/foreign-key-index-conformance/`](../fixtures/foreign-key-index-conformance/) (the indexes `migrate.foreignKeyIndexes` adds: which foreign keys are uncovered, and each index's name per dialect, a name over 63 bytes cut on Postgres; and the name each declared `identity.secondary` / `index.lookup` is created under) | 1 model, 4 expected files (FK and declared, postgres and sqlite) | ✓ (reference, `migrate-ts`; the Drizzle tables declare the declared names) | — (no index in a generated model) | ✓ (the Exposed tables declare them) | ✓ (the EF context declares them) | — (same as Java) |
| [`fixtures/codegen-noop/`](../fixtures/codegen-noop/) (FR-044 — reporting vocabulary: what is lowered, what stays inert) | 1 model pair (`reporting/with` vs `reporting/without`) | ✓ (codegen + migrate) | ✓ | ✓ | ✓ | ✓ |
| [`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) | 41 cases (31 core + 10 TypeScript) | ✓ (the first writer; core and TypeScript dialect) | — (writer not built yet) | — (writer not built yet) | — (writer not built yet) | — (writer not built yet) |
| [`fixtures/contract-conformance/`](../fixtures/contract-conformance/) (FR-022 — the `contract-schema` and `openapi` generators' golden trees and refusals) | 19 cases (14 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 `explorer.json` data spine: `meta export --effective` + `meta verify --format json` + the generated-file manifest in, one explorer document out) | 1 case (`shop`) | ✓ (the builder is TypeScript, and reads only port-neutral inputs) | — | — | — | — |

Expand Down Expand Up @@ -97,7 +98,8 @@ the corpora above do two different jobs. Only the first is a promise to adopters
A red cell here is a MetaObjects bug.
- **Template quality checks — not a promise.** The generated lane of
`api-contract-conformance/`, `generator-registry-conformance/` (stable generator names),
`codegen-noop/` (vocabulary with no lowering yet emits nothing), `contract-conformance/` (the JSON Schema and OpenAPI output), `cube-model/` (the Cube
`codegen-noop/` (vocabulary with no lowering yet emits nothing), `writer-conformance/` (the code
writer the reference generators write through, ADR-0063), `contract-conformance/` (the JSON Schema and OpenAPI output), `cube-model/` (the Cube
exporter's output, a TypeScript reference helper),
`requirement-test-identity-conformance/` (which tests the `requirement-tests` reference
generator yields from a ledger and what each is called; the text it writes is not
Expand Down
4 changes: 3 additions & 1 deletion docs/features/own-your-codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ holds), the naming tables and the type-mapping tables (`names.ts`, `naming.ts`,
projection and report lowering that `meta migrate` and `meta verify` run. An owned file
imports the engine from the package's engine entry, `@metaobjectsdev/codegen-ts/engine`,
which also exports the code printer's `code`, `imp` and `joinCode` (`poet.ts`, the package's
vendored copy of `ts-poet`). The list is `ENGINE_MODULES`, exported from that entry; a module
vendored copy of `ts-poet`) and the code writer (`CodeWriter`, `TsWriter`, ADR-0063),
which lays a file out but decides nothing about what the file contains, so like the
printer it stays with the engine. The list is `ENGINE_MODULES`, exported from that entry; a module
that is not on it and that a generator reaches is copied. An owned generator therefore
imports no packaged module that returns emitted text, and a test ejects each generator alone
into an empty project to prove it: it compiles as your `tsconfig.codegen.json` checks it and
Expand Down
2 changes: 1 addition & 1 deletion examples/showcase/site-payload.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
},
"counts": {
"fixtures": 510,
"corpora": 40,
"corpora": 41,
"baseTypes": 17
},
"snippets": {
Expand Down
4 changes: 3 additions & 1 deletion fixtures/generator-registry-conformance/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@
"codegen-ts/src/templates/find-inbound.ts",
"codegen-ts/src/templates/find-templates.ts",
"codegen-ts/src/tph.ts",
"codegen-ts/src/view-context.ts"
"codegen-ts/src/view-context.ts",
"codegen-ts/src/writer/code-writer.ts",
"codegen-ts/src/writer/ts-writer.ts"
]
},
"csharp": {
Expand Down
15 changes: 15 additions & 0 deletions fixtures/writer-conformance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Writer conformance

The shared cases for the code writer every port's generators write through
([ADR-0063](../../spec/decisions/ADR-0063-generators-own-layout.md)). The contract and the case
format are in [`spec/code-writer.md`](../../spec/code-writer.md).

- `cases/*.json` with `"dialect": "core"` pin the language-neutral core: indentation, blocks,
blank-line requests, snippets, fit-or-break lists, line endings and the error codes. Every
port's writer runs them with the options the case states.
- Cases with a language dialect (`"dialect": "typescript"`) pin that language's writer: import
collection and ordering, doc comments and its defaults.

Runner: TypeScript, `server/typescript/packages/codegen-ts/test/writer-conformance.test.ts`.
The other ports run the `core` cases when their writers land, and add cases for their own
dialect beside these.
31 changes: 31 additions & 0 deletions fixtures/writer-conformance/cases/blank-after-open-dropped.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"description": "No blank line directly after the line that opens a block.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"open",
"f() {"
],
[
"blank"
],
[
"line",
"a;"
],
[
"close",
"}"
]
],
"expected": [
"f() {",
" a;",
"}"
]
}
21 changes: 21 additions & 0 deletions fixtures/writer-conformance/cases/blank-at-file-end-dropped.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"description": "A blank-line request after the last line writes nothing.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"line",
"a;"
],
[
"blank"
]
],
"expected": [
"a;"
]
}
21 changes: 21 additions & 0 deletions fixtures/writer-conformance/cases/blank-at-file-start-dropped.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"description": "A blank-line request before the first line writes nothing.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"blank"
],
[
"line",
"a;"
]
],
"expected": [
"a;"
]
}
31 changes: 31 additions & 0 deletions fixtures/writer-conformance/cases/blank-before-close-dropped.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"description": "No blank line directly before the line that closes a block.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"open",
"f() {"
],
[
"line",
"a;"
],
[
"blank"
],
[
"close",
"}"
]
],
"expected": [
"f() {",
" a;",
"}"
]
}
37 changes: 37 additions & 0 deletions fixtures/writer-conformance/cases/blank-between-blocks-kept.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"description": "A request between two blocks gives one blank line between them.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"open",
"a() {"
],
[
"close",
"}"
],
[
"blank"
],
[
"open",
"b() {"
],
[
"close",
"}"
]
],
"expected": [
"a() {",
"}",
"",
"b() {",
"}"
]
}
30 changes: 30 additions & 0 deletions fixtures/writer-conformance/cases/blank-requests-collapse.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"description": "Two blank-line requests in a row give one blank line.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"line",
"a;"
],
[
"blank"
],
[
"blank"
],
[
"line",
"b;"
]
],
"expected": [
"a;",
"",
"b;"
]
}
15 changes: 15 additions & 0 deletions fixtures/writer-conformance/cases/empty-file.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"description": "A writer with nothing written produces the empty string, not a lone newline.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"blank"
]
],
"expected": []
}
36 changes: 36 additions & 0 deletions fixtures/writer-conformance/cases/empty-line-is-blank-request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"description": "A line whose text is empty is a blank-line request, so it collapses and is dropped like one.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"line",
"a;"
],
[
"line",
""
],
[
"line",
""
],
[
"line",
"b;"
],
[
"line",
""
]
],
"expected": [
"a;",
"",
"b;"
]
}
20 changes: 20 additions & 0 deletions fixtures/writer-conformance/cases/error-close-without-open.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"description": "close() with no block open is an error.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"line",
"a;"
],
[
"close",
"}"
]
],
"error": "ERR_WRITER_UNBALANCED_CLOSE"
}
16 changes: 16 additions & 0 deletions fixtures/writer-conformance/cases/error-newline-in-line.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "line() refuses text containing a line break; each line is written separately.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"line",
"a;\nb;"
]
],
"error": "ERR_WRITER_NEWLINE_IN_LINE"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"description": "line() refuses text ending in a line break; the break is not trimmed away first.",
"dialect": "core",
"options": {
"indent": " ",
"width": 40,
"trailingComma": true
},
"ops": [
[
"line",
"a;\n"
]
],
"error": "ERR_WRITER_NEWLINE_IN_LINE"
}
Loading
Loading