Skip to content
Merged
2 changes: 1 addition & 1 deletion .claude/rules/cross-language-porting.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Preserve the following contracts exactly across all language ports:
- Currency attrs: `@currency` (ISO 4217), `@locale` (BCP 47)
- Schema attrs: `@schema` on `source.rdb` (DB schema name; Postgres default `public`, SQLite rejects non-default values)
- Storage attrs: `@storage` on `field.object` (with `@objectRef`) — values `flattened` / `jsonb` / `subdocument`. Unifies "owned types" (flattened storage) and "structured JSONB" (jsonb storage). Defaults to single-jsonb-column when absent (back-compat).
- Enum: `field.enum` is a first-class field subtype (peer of `currency`), string-backed. Required `@values` string-array attr (member symbols). Members must be a non-empty set, each matching `^[A-Za-z_][A-Za-z0-9_]*$`, no duplicates — every port's loader enforces this (own-only) emitting `ERR_BAD_ATTR_VALUE` (missing `@values` → `ERR_MISSING_REQUIRED_ATTR`). Reuse via abstract `field.enum` + `extends`. Codegen: TS union + `z.enum`, C# `enum` + EF `HasConversion<string>()`, DB `varchar` + `CHECK`. **Int-backed storage shipped** (`@intValueMap`, a `{memberSymbol: int}` map, switches the column to `integer` + int `CHECK` while the wire format, the generated type and every runtime value stay the member SYMBOL; a MAP rather than a positional array so reordering `@values` cannot silently re-map every member; an int-backed enum array loads in every port and stores each element as its declared integer — TypeScript, C#, Java (OMDB) and Kotlin (Exposed) persist it on every engine, Python on Postgres only; an unmapped stored integer THROWS in all five ports). Display labels and native PG enum remain deferred (see `docs/superpowers/specs/2026-05-23-enum-datatype-design.md`).
- Enum: `field.enum` is a first-class field subtype (peer of `currency`), string-backed. Required `@values` string-array attr (member symbols). Members must be a non-empty set, each matching `^[A-Za-z_][A-Za-z0-9_]*$`, no duplicates — every port's loader enforces this (own-only) emitting `ERR_BAD_ATTR_VALUE` (missing `@values` → `ERR_MISSING_REQUIRED_ATTR`). Reuse via abstract `field.enum` + `extends`. Codegen: TS union + `z.enum`, C# `enum` + EF `HasConversion<string>()`, DB `varchar` + `CHECK`. **Int-backed storage shipped** (`@intValueMap`, a `{memberSymbol: int}` map, switches the column to `integer` + int `CHECK` while the wire format, the generated type and every runtime value stay the member SYMBOL; a MAP rather than a positional array so reordering `@values` cannot silently re-map every member; an int-backed enum array loads in every port and stores each element as its declared integer — TypeScript, C#, Java (OMDB), Kotlin (Exposed) and Python persist it on every engine; an unmapped stored integer THROWS in all five ports). Display labels and native PG enum remain deferred (see `docs/superpowers/specs/2026-05-23-enum-datatype-design.md`).
- Documentation common attrs (any node): `description`, `title`, `notes`, `deprecated`, `replacedBy`, `seeAlso`, `aliases`. Registered via the cross-language `commonAttrs` registry hook (`registerCommonAttrs` / `RegisterCommonAttrs` / `register_common_attrs` / Java `MetaDataRegistry.registerCommonAttribute` — wired in all four ports). `notes` is the internal-only rationale slot — never emitted to user-facing doc-gen (JSDoc / XML-doc / Postgres `COMMENT ON` / Mermaid prose). **The `description` / `notes` split is by CONTENT KIND, not audience** — an audience split invites writing the same content twice at two levels of politeness. `description` states what the element IS and COVERS (scope and boundary, derivable from the model); `notes` states what you had to look OUTSIDE the model to learn (evidence, citations, what breaks if it changes). Mechanical test: a sentence belongs in `notes` exactly when it would have to change because the IMPLEMENTATION changed while the model did not. `title` is a noun phrase, `summary` a one-line sentence. TS doc-gen ships all three tiers; C# ships XML-doc + COMMENT ON. See `docs/superpowers/specs/2026-05-24-documentation-provider-design.md`.

**Wire format:**
Expand Down
49 changes: 47 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,29 @@ here.**
Python had none. `Renderer` now strips standalone comment lines before mustache.java parses them. A
template with such a line renders differently in Java, so a prompt body with one changes bytes (and
its prompt-cache prefix) on upgrade. The `render-standalone-*` fixtures pin the whitespace rules.
- **Python: the entity model generator writes through the code writer (ADR-0063).** The model
modules (`<Name>.py` with `<Name>Create` and `<Name>Patch`), the shared `enums.py` and the
`_duration_wire.py` banner are built on a `PyWriter`, and `ruff` no longer runs over them, so the
bytes no longer depend on whether `ruff` is installed. Over 1,561 model modules generated from the
repository's fixtures, 1,146 are byte-identical, and the other 415 match once both versions are
put through the same `ruff` import sort and format. What moves: the standard-library and
third-party imports share one section (no blank line between `import datetime` and
`from pydantic import ...`, the writer's import order); a `Field(...)` too long for its line puts
one keyword per line; and a `field.duration` annotation too long for its line breaks inside
`Annotated[...]`. `PyWriter.gap()` asked for before the first body line now gives the two blank
lines PEP 8 sets after the imports and before a top-level class (a new `py-gap-after-imports`
writer-conformance case). For subclasses of `EntityModelGenerator` (not a stability contract,
ADR-0063 item 7): `_emit_field_lines`, `_emit_create_lines` and `_emit_patch_lines` return writer
pieces without indentation (`"name: int | None = None"`) instead of indented strings,
`_emit_cross_field_rules` returns a step that writes the method onto the writer (or `None`) instead
of lines, a new `_write_model` writes one class, and `render_entity_model` returns the finished
module rather than text for `ruff` to tidy.
- **Python: `@union` and `@grain` projections are checked at load.** A union member whose fields
differ in name, subtype, array-ness, `@column` or enum shape, a member that is the projection
itself or declares its own `@union`, `@unionAll` without `@union`, a `@grain` that does not name a
base-entity `field.object` jsonb array with `@objectRef`, an aggregate in a `@grain` view, and a
malformed `@grainOrdinal` are now `ERR_BAD_ATTR_VALUE`, as in TypeScript and C#. Python passes the
`error-projection-union-shape` and `error-projection-grain-not-object-array` fixtures.
- **C#: an unchanged file is never rewritten.** `dotnet meta gen` already left identical output alone
when the project keeps a hash manifest. It now does the same on the path with no manifest (output
written outside the project, or a program that runs the generators with no state directory), which
Expand Down Expand Up @@ -178,6 +201,28 @@ here.**
included every filterable text field, and an int-backed (`@intValueMap`) enum is an integer
column, so Postgres refused the ILIKE. Search now covers only fields whose operator band
includes `like`.
- **Python: a primitive array persists on SQLite and MySQL.** The `ObjectManagerDb`'s SQLite and
MySQL dialects bound no list, so an `isArray` string, number, date, uuid or enum field could not be
written there. The column the TypeScript-owned schema gives it (`TEXT` on SQLite, `JSON` on MySQL)
now holds a JSON array, an int-backed enum's as its integers (`[5,0]`), and each element reads back
through the scalar decode. `roundtrip-int-enum-array` runs on both engines instead of being deferred.
A `field.date`, `field.time` or `field.timestamp` array was refused on write on every engine,
Postgres included (the list was parsed as one value); it is now parsed element by element.
- **Python: an unrestricted `routes` is no longer refused for objects it writes no router for.**
`metaobjects gen` refused a config that limits `filter-allowlist` (or `entity`) to some packages
while `routes` is left unlimited, whenever another package held an abstract or sourceless object,
saying `routes` covered it. `routes` writes nothing for those objects, so only the objects it
routes count now. A routed object's model still imports the abstract base it `extends`, the value
objects its fields reference and its M:N targets, so limiting `entity` away from one of those is
still refused. So is the concrete subtype of a routed discriminator base, whose `Create` and
`Patch` models the base's router imports.
- **Python: `metaobjects eject --force` no longer rewrites an identical copy.** It compares each file
with the reference before writing, and one that already matches is left alone and reported
`unchanged`.
- **Python: a reverse finder over a flattened value-object member is named by its flat key.** A
reference whose `@fields` names a member such as `address.countryId` emitted a method name with a
dot in it, which is not Python. It is now `find_plans_by_address_country`, as TypeScript names it,
so the generated finder name changes for such a model on upgrade.
- **C#: a `@sequenceStart` whose migrations project lacks the design-time services line is a generation
error.** When `dotnet meta gen` can see the context's `ModelSnapshot.cs` in another project and that
project does not carry `[assembly: DesignTimeServicesReference]`, the next `dotnet ef migrations add`
Expand Down Expand Up @@ -869,8 +914,8 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
the only int-backed enum, projection and report-row enum arrays get the element converter
(they read stored ints as ordinals before), and a non-required int-backed enum array is
nullable.
- Python: ObjectManager maps elements on write, read and filter operands on Postgres. Its
SQLite and MySQL dialects store no primitive array, so the new scenario is deferred there.
- Python: ObjectManager maps elements on write, read and filter operands, on Postgres, SQLite
and MySQL (the last two store a JSON array of numbers).
- Java: OMDB stores an int-backed enum array as a native `integer[]` on Postgres and a JSON array
of numbers on SQLite, MySQL and Derby; a member with no declared integer is refused on write,
and a stored integer with no member fails the read. Kotlin: the Exposed table generator emits an
Expand Down
2 changes: 1 addition & 1 deletion docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/codegen-skip-conformance/`](../fixtures/codegen-skip-conformance/) (when `gen` may skip and what a local `verify --codegen` may answer, ADR-0064) | one case table in `cases.json`, plus the manifest layout vectors in `manifests.json` (ADR-0064 Amendment 1) | ✓ | ✓ | ✓ (through the Java runner) | ✓ | ✓ |
| [`fixtures/codegen-noop/`](../fixtures/codegen-noop/) (vocabulary with no lowering yet: FR-044 reporting, what is lowered and what stays inert; ADR-0066 business rules, inert everywhere) | 2 model pairs (`reporting/` and `rules/`, each `with` vs `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) | 67 cases (31 core + 10 TypeScript + 9 Java + 6 C# + 11 Python) | ✓ (the first writer; core and TypeScript dialect) | ✓ (core and Java dialect; `JavaWriter` in `codegen-base`) | — (writer not built yet) | ✓ (core and C# dialect) | ✓ (core and Python dialect) |
| [`fixtures/writer-conformance/`](../fixtures/writer-conformance/) (ADR-0063 — the code writer generators write through) | 68 cases (31 core + 10 TypeScript + 9 Java + 6 C# + 12 Python) | ✓ (the first writer; core and TypeScript dialect) | ✓ (core and Java dialect; `JavaWriter` in `codegen-base`) | — (writer not built yet) | ✓ (core and C# dialect) | ✓ (core and Python dialect) |
| [`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
2 changes: 1 addition & 1 deletion docs/features/field-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ sharing the enum keeps its integer `CHECK`. The generated type is the port's lis
| C# | Postgres, SQLite, MySQL | the element converter of an EF Core primitive collection; a non-required array is `IList<TEnum>?` |
| Java | Postgres, SQLite, MySQL, Derby | the OMDB codec (`JdbcCodecs`; `PostgresDriver.nativeArrayElementType` on Postgres). A member with no declared integer is refused on write with an `SQLException` naming the field. A repository you write yourself maps each element through the generated enum's `dbValue()` and `fromDbValue(int)` |
| Kotlin | Postgres, SQLite, MySQL | the generated `portableIntEnumArray<E>(name, { toInt }, { fromInt })` column, emitted into `MetaIntEnumArrayColumnType.kt` only in a package that has such a column. Its two lambdas are generated `when` expressions, so a member with no integer is a compile error |
| Python | Postgres only | the codec in `metaobjects.runtime.values`, called by `ObjectManagerDb`. SQLite and MySQL store no primitive array in this runtime, so an enum array of either kind is Postgres-only there |
| Python | Postgres, SQLite, MySQL | the codec in `metaobjects.runtime.values`, called by `ObjectManagerDb`; the SQLite and MySQL dialects bind the array as JSON text and decode each element |

The `roundtrip-int-enum-array` persistence scenario
([fixtures/persistence-conformance/README.md](../../fixtures/persistence-conformance/README.md#int-backed-enum-array-scenario))
Expand Down
29 changes: 20 additions & 9 deletions docs/ports/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ never disagree about what was generated. A target whose `generators` is empty wr
nothing and says so. With no `metaobjects.config.yaml` at all, `gen` and `verify --codegen`
fail with exit 2 and write nothing: there is no list to run. `routes` needs `entity` and
`filter-allowlist` beside it (the router imports both), and `metaobjects gen` warns when one
is missing.
is missing. A `packages` or `entities` limit on either one is refused when it leaves out an
object the routed objects import: for `filter-allowlist`, the routed objects; for `entity`, the
routed objects and the models they import (the abstract base each `extends`, the value objects
they reference, their M:N targets, and the concrete subtypes of a routed discriminator base). An
abstract or sourceless object that `routes` writes no router for needs neither.

The 1.0 form `metaobjects gen <metadata_dir> --out <dir> --generators <names>` is not read:
the metadata directory is `metadata` and each output directory is a target's `outDir`.
Expand Down Expand Up @@ -429,8 +433,10 @@ A declared name wins over the pluralizer. Either one is snake_cased with an acro
split, so `FAQs` becomes `faqs`, not `fa_qs`. The router, the API docs, the M:N routes and the
collision check all read one function, `collection_segment`. The same name also gives the
reverse finders: `@collectionName: CaseHistory` on an object turns
`find_<plural>_by_<fk>` into `find_case_history_by_<fk>` (and `..._in`). A project that sets
neither keeps every route and finder name it has today. The shared cases are in
`find_<plural>_by_<fk>` into `find_case_history_by_<fk>` (and `..._in`). A reference whose
`@fields` names a member of a flattened value object (`address.countryId`) takes that member's
flat key in `<fk>`, so the finder is `find_plans_by_address_country`, as TypeScript names it. A
project that sets neither keeps every route and finder name it has today. The shared cases are in
`fixtures/naming-conformance/collection-segments.json`.

### Page size and undeclared body keys: the `api` block
Expand Down Expand Up @@ -781,10 +787,13 @@ that file's root package, so `package` on such a node is already the full
A `field.enum` with `@intValueMap` (own or inherited from a shared abstract enum) is stored as its
declared integers while `ObjectManager` callers pass and receive member symbols. The codec in
`metaobjects.runtime.values` (called by `ObjectManagerDb`) encodes on every write and on filter operands, and decodes on
every read. On an `isArray: true` field it does this for each element, on Postgres only (see
every read. On an `isArray: true` field it does this for each element, on every engine (see
[Int-backed enum arrays](../features/field-types.md#int-backed-enum-arrays)); a null element stays
a null element. An int that has no member raises `ValueError` on read, whether it is a scalar or an
array element.
array element. On SQLite and MySQL, which have no array type, the column is `TEXT` / `JSON` holding a
JSON array (`[5,0]`). This holds for every primitive array (strings, numbers, dates, uuids): each
element is written as the JSON form of what the scalar column binds and read back through the scalar
decode.

### Run-time validation

Expand Down Expand Up @@ -1053,10 +1062,12 @@ already have it. The `[email]` extra is needed as soon as any field carries
generator types that field `EmailStr`, which imports `email-validator` when the class is
defined. Without it the generated module fails at import, not at `gen`.

**Note on emitted output.** Both generators run `ruff_format(content)` on the
file before writing, so the literal emitted layout may reflow whitespace
slightly vs the snippets above. Function signatures, class definitions, and
import lines are stable.
**Note on emitted output.** The entity generator lays its modules out with the
Python code writer (ADR-0063); no formatter runs over them, so what is written does
not depend on whether `ruff` is installed. The output-parser generator still runs
`ruff_format(content)` on the file until it is converted, so its literal layout may
reflow whitespace slightly vs the snippets above. Function signatures, class
definitions, and import lines are stable.

## Capability snapshot

Expand Down
24 changes: 24 additions & 0 deletions fixtures/writer-conformance/cases/py-gap-after-imports.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"description": "gap() asked for before the first body line puts two blank lines between the imports and the body, so a class or def right after the imports gets the two PEP 8 sets before a top-level definition; without it the sections stay one blank line apart.",
"dialect": "python",
"ops": [
["header", "# @generated by MetaObjects."],
["use", "annotations", "__future__"],
["use", "BaseModel", "pydantic"],
["gap"],
["open", "class A(BaseModel):"],
["line", "x: int"],
["dedent"]
],
"expected": [
"# @generated by MetaObjects.",
"",
"from __future__ import annotations",
"",
"from pydantic import BaseModel",
"",
"",
"class A(BaseModel):",
" x: int"
]
}
Loading
Loading