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
22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ here.**

## [Unreleased]

- **Java and Kotlin: template and documentation output is recorded in the hash manifest.** The
`template` and `mustache` generators, the api, HTML, JSON and PlantUML documentation pages and the
`META-INF/services` registration wrote through a byte compare only, so a hand edit to one of them
was overwritten without the refusal every other generated file gets. They now go through
`GeneratedFileWriter.writeUnmarked`: each file is recorded under `.metaobjects/.gen-state/.hashes/`,
unchanged bytes are not rewritten, and a hand edit is refused by name under `handEdits: keep`. An
existing file at one of these paths that the manifest has no record of is taken as generated
output on the first run (it can carry no `GENERATED` marker), so upgrading refuses nothing. The
orphan sweep and `metaobjects:verify` now see these files too: one a template stops emitting is
deleted when untouched, as other generated files are. The documentation generators also no longer
create an empty file before writing, so `metaobjects:verify`'s in-memory render leaves nothing on
disk.
- **Java and Kotlin: a gate that every generator writes through `GeneratedFileWriter`.**
`GeneratorWritePathTest` runs every registered Java and Kotlin generator over the shared fitness
corpus and fails when a file is left on disk that the writer did not write, or when a second run
changes a file's bytes or modification time, so a new generator cannot skip the hash manifest or
the unchanged-bytes check.
- **Java and Kotlin: `mvn metaobjects:eject -Dforce=true` no longer rewrites an identical copy.** An
owned generator, template, support or runtime file, or the `codegen/pom.xml`, that already holds
exactly the reference content is left alone and reported as identical, with or without `force`.
The codegen fingerprint, `metaobjects:fmt` and `metaobjects:init` also compare before they write.

- **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
19 changes: 7 additions & 12 deletions docs/features/codegen-concepts.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ thing in git and the only thing anyone reads.
## 7. Safety: never clobbering hand edits

The backstop under every strategy above is that the generator will not silently eat your
work. **Every port decides from the committed hash manifest, and the `@generated` header is
not the decision:**
work. **Every port decides from the committed hash manifest. The `@generated` header is not
the decision, except on Java and Kotlin for a file the manifest has no record of:**

- **TypeScript** decides from `.metaobjects/.gen-state/` — the snapshot body if this
machine has one (three-way merge), otherwise the committed `.hashes/` (byte-for-byte
Expand All @@ -175,14 +175,9 @@ not the decision:**
marker, refuse one without it — and in that mode the header IS load-bearing, in both
directions. Neither `dotnet meta gen` nor `metaobjects gen` can put you there: both
always supply the directory. If you embed either runner, supply one too.
- **Java and Kotlin** decide from the same committed hash manifest since 8.1.0 (ADR-0060):
`GeneratedFileWriter` records what it writes, and an edited file is refused. The
`GENERATED` header token decides only for a file the manifest has no record of: one that
carries it is adopted as generated output, one that does not is refused. A refusal there
is a warning, not a build failure.

Both are stated in full, per port, in
[own-your-codegen.md](own-your-codegen.md).
- **Java and Kotlin** decide from the same committed manifest, and their refusal is a
warning, not a build failure. The full rule is in
[own-your-codegen.md](own-your-codegen.md#hand-edits-and-the-hash-manifest-every-port).

## 8. Bind metadata → native types at build time, never runtime reflection

Expand Down Expand Up @@ -298,8 +293,8 @@ registered escaper formats; a `target` field is **rejected** (the CLI ports have
output-target concept). The same neutral data dict, output-pattern grammar, and
conformance corpus apply, so a spec renders byte-identically across ports. The standard
write path decides from the hash manifest, not the header (section 7), so a template need
not emit the `@generated` marker. The JVM's `TemplateScopeGenerator` writes directly and
keeps no manifest record.)
not emit the `@generated` marker. The JVM's `TemplateScopeGenerator` is recorded in the same
manifest (see [own-your-codegen.md](own-your-codegen.md#hand-edits-and-the-hash-manifest-every-port)).

**The spec is declared, never discovered.** Through 1.0 both CLI ports also read a
`--template-spec` flag or a project-root `template-spec.json` on their own. Since 1.1.0 a spec
Expand Down
40 changes: 32 additions & 8 deletions docs/features/field-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,8 @@ deferred (see [enum-datatype-design.md](../superpowers/specs/2026-05-23-enum-dat

Two rules follow from int-backing being a **persistence-layer codec**:

- **An array is mapped element by element.** An enum field with `isArray: true` that
carries `@intValueMap` (its own, or inherited from a shared enum) stores each element as
its declared integer: an `integer[]` column on Postgres, and a JSON array of numbers
(`[5,0]`) where an engine keeps arrays as JSON text (SQLite, D1, MySQL). Each element reads
back as its member. A null array stays null and an empty one stays empty. The array column
has no `CHECK`, the same as a string-backed enum array. Where a port's runtime stores no
primitive array on an engine, see that port's page under [docs/ports/](../ports/) for what it
does there.
- **An array is mapped element by element.** See [Int-backed enum arrays](#int-backed-enum-arrays)
below.
- **A stored integer that maps to no member throws on read**, in every port. The row holds
data the model says is impossible (a hand-written `INSERT`, or a member removed without a
migration); surfacing the raw integer would hand you a "member" that is not one — and is
Expand Down Expand Up @@ -278,6 +272,36 @@ the Drizzle column codec, the runtime ObjectManager and the view, report and Cub
(TypeScript); the OMDB codec (Java); the Exposed `customEnumeration` (Kotlin); the generated
Spring enum's `dbValue()` (for a hand-written repository); the Python ObjectManager.

### Int-backed enum arrays

This section is the one description of the int-backed enum array for every port; the port pages
name only their own classes and point here.

An enum field with `isArray: true` that carries `@intValueMap` (its own, or inherited from a
shared enum) stores each element as its declared integer: an `integer[]` column on Postgres, and
a JSON array of numbers (`[5,0]`) where an engine keeps arrays as JSON text (SQLite, D1, MySQL).
Each element reads back as its member, in order. A null array stays null and an empty one stays
empty. A stored integer with no member throws on read, as it does for a scalar. The array column
has no `CHECK` (membership of an enum array is checked by the application), while a scalar column
sharing the enum keeps its integer `CHECK`. The generated type is the port's list of the enum
(`List<E>`, `IList<TEnum>`, an array of the union).

| Port | Engines it stores the array on | Where the mapping lives |
|---|---|---|
| TypeScript | Postgres, SQLite, D1, MySQL | the Drizzle column codec and the runtime ObjectManager |
| 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 |

The `roundtrip-int-enum-array` persistence scenario
([fixtures/persistence-conformance/README.md](../../fixtures/persistence-conformance/README.md#int-backed-enum-array-scenario))
gates the Postgres, MySQL, SQLite and D1 columns of this table on the ports that run it. Derby is
not in that corpus. A **string-backed** enum array is a different case: Java's OMDB
maps no native array column for it, and Kotlin's Exposed generator emits a scalar column for it,
so a generated Kotlin controller for such an entity does not compile
([KNOWN_GAPS.md](../../server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KNOWN_GAPS.md)).

### Sharing one enum — abstract `field.enum` + `extends`

Reuse a constraint set across entities by declaring one **abstract** `field.enum`
Expand Down
2 changes: 1 addition & 1 deletion docs/features/migrations-and-drift.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ There are **7 drift sources**, and the toolchain has a guard for each.
| **Code-vs-API-doc** | Cross-port codegen from the same metadata. | Build time |
| **DB-vs-metadata** | `meta verify --db` (TS CLI) — introspects the live DB and fails if it has drifted from metadata. Includes modeled projection **view bodies** (a changed `CREATE VIEW` is drift, reported with what differs: the first differing excerpt of the text on SQLite/D1, the deparsed body on Postgres's scratch-database path, a fingerprint mismatch otherwise). A view `meta migrate` drops and recreates only because the migration alters a table it reads, with its definition unchanged, is not drift and is not reported; a hand-authored *unmodeled* view is unmanaged and never flagged. A schema concern owned by the Node toolchain regardless of server language; on the JVM ports the runtime auto-create/validator path was removed (ADR-0015) and the `metaobjects:verify` Maven goal is not available. Cloudflare D1 has no client wire protocol, so it can't go through `--db`'s Kysely-driver introspection — use `meta verify --dialect d1 [--d1 <binding>] [--remote]` instead (the same wrangler-shelled-out path `meta migrate --dialect d1` uses); `--remote` is required to check the *deployed* database, not the local `wrangler dev` shadow copy. Pointing `--db file:` at wrangler's local D1 state directory (`.wrangler/state/**/d1/**`) still runs, but only verifies that local copy — `verify` warns when it detects this. | CI on every PR |
| **Migration-vs-metadata** | The Node `meta migrate` emits migrations FROM metadata diffs — they cannot drift from metadata by construction. Schema migrations for **every** port are owned by this Node toolchain (`@metaobjectsdev/cli migrate`, ADR-0015); the C# and Python migrate surfaces were removed. | Build time |
| **Generated-edited** | `@generated` headers in emitted code + a committed hash manifest that refuses an edited file by name; in TypeScript only, a three-way merge also preserves hand-edits on the machine that generated the file. `verify --codegen` names each edited file in every port. In TypeScript it fails on one when `.metaobjects/config.json` sets `"verify": { "handEdits": "fail" }` (what `meta init` writes) and reports it as a notice otherwise; the C#, Java, Kotlin and Python gates compare bytes, so an edit always fails there ([cli.md](cli.md)). | Build time (CI) |
| **Generated-edited** | A committed hash manifest refuses an edited generated file by name in every port; only TypeScript also three-way merges, on the machine that generated it. The rule is in [own-your-codegen.md](own-your-codegen.md#hand-edits-and-the-hash-manifest-every-port). `verify --codegen` names each edited file in every port. In TypeScript it fails on one when `.metaobjects/config.json` sets `"verify": { "handEdits": "fail" }` (what `meta init` writes) and reports it as a notice otherwise; the C#, Java, Kotlin and Python gates compare bytes, so an edit always fails there ([cli.md](cli.md)). | Build time (CI) |
| **Prompt-vs-payload** | FR-004 `Renderer.verify` parses `{{...}}` references in templates and checks each one exists on the payload VO. | Build time + runtime |
| **Generated-vs-runtime** | Kotlin / Java `MetadataStartupValidator` (from Spring `ApplicationReadyEvent`) re-loads metadata at startup and asserts the generated table objects match. | App startup |

Expand Down
23 changes: 9 additions & 14 deletions docs/features/migrations/jvm-codegen-hash-manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ Through 8.0.x, `mvn metaobjects:generate` decided whether it could overwrite a f
had edited it. A file that was no longer generated (a renamed value object, a deleted entity)
stayed on disk forever, because nothing recorded what a run had written.

From 8.1.0 the Java and Kotlin generators record every file they write in a committed hash
manifest, the same one TypeScript, Python and C# use:
From 8.1.0 the Java and Kotlin generators record the generated source they write in a committed
hash manifest, the same one TypeScript, Python and C# use:

```
<module basedir>/.metaobjects/.gen-state/.hashes/<package>.json
Expand All @@ -39,14 +39,8 @@ generator of your own) and that generator's output directory within the module:
}
```

With it:

- a file that still matches its record is overwritten as before;
- **a file you edited is refused by name**, and the build logs a warning (it does not fail);
- **a file no generator emits any more is deleted** when it still matches its record, and
refused by name when you edited it;
- a file the manifest has no record of, and that has no `GENERATED` token, is refused, as
before.
The rules that apply now, for every port, are stated once in
[Hand edits and the hash manifest](../own-your-codegen.md#hand-edits-and-the-hash-manifest-every-port).

## What to do

Expand Down Expand Up @@ -122,11 +116,12 @@ also deleted, when every generator writing into its directory sets `overwrite`.
That still works: deleting the line is an edit, so the file no longer matches its record and
is refused.

## What does not change
## What does not change, and what 1.3.0 adds

- User templates (`TemplateScopeGenerator`, `MustacheTemplateGenerator`), the api-docs pages
and the `META-INF/services` registration are not recorded. They are written on every run as
before, and the run never deletes them.
- User templates, the documentation pages and the `META-INF/services` registration were not
recorded in 8.1.0, so they had no hand-edit protection there. From 1.3.0 they are
recorded like every other generated file. An existing file at such a path with no record
is adopted on the first run, not refused (see the CHANGELOG, 1.3.0 section).
- A refusal is still a warning on the JVM. `mvn metaobjects:verify` is the gate that fails:
it reports a stale file, says whether `generate` deletes it, and tells you to delete an
edited one yourself.
21 changes: 14 additions & 7 deletions docs/features/own-your-codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,10 @@ diff -u node_modules/@metaobjectsdev/codegen-ts/src/templates/zod-validators.ts
codegen/templates/zod-validators.ts
```

## Hand edits and the hash manifest (every port)

This is the one statement of the hand-edit guard. The other docs point here.

Whatever you own, hand-edits inside a generated file survive regeneration — but *how* they
survive depends on what the toolchain can see, and it is worth knowing which case you
are in:
Expand Down Expand Up @@ -534,12 +538,13 @@ adopts every generated file, deletes nothing, and prints one notice to commit th
The token alone decides only when no manifest is configured, which `mvn metaobjects:generate`
never does (an embedder driving a generator directly can).

**Four write paths bypass the guard on purpose**, and they are not oversights: user-supplied
templates (`TemplateScopeGenerator`, `MustacheTemplateGenerator`), the `api-docs` generators'
pages, and the `META-INF/services` registration whose entire content is a bare
fully-qualified name. None of them emits content MetaObjects authors, so none is recorded in
the manifest. They are overwritten on every run, and the orphan sweep never deletes them.
`GeneratedFileWriter`'s javadoc lists them.
**Output that cannot carry the `GENERATED` token takes the unmarked path.** User-supplied
templates (`TemplateScopeGenerator`, `MustacheTemplateGenerator`), the api, HTML, JSON and
PlantUML documentation pages and the `META-INF/services` registration (a bare fully-qualified
name, with nowhere to put a token) are recorded in the manifest like every other generated file.
An unchanged file is not rewritten, and a hand edit is refused by name. The one difference is
adoption: a file at such a path that the manifest has no record of is taken as this toolchain's
output, because the path was only ever written by it. `GeneratedFileWriter`'s javadoc lists them.

Two consequences to hold on to:

Expand Down Expand Up @@ -1204,7 +1209,9 @@ Eject never edits an existing pom. It prints the three things to wire: the `<mod
entry for your parent pom, a plugin `<dependency>` on the codegen module for the module
that runs `metaobjects:generate`, and the new `<classname>` for each `<generator>`. It
never overwrites a copy without `-Dforce`, and `-Dlist` marks each owned copy `identical`
or `DIFFERS: N behind, M of your own`. A copy is `identical` only when every file it owns is:
or `DIFFERS: N behind, M of your own`. A file that already holds exactly the reference bytes
is reported `IDENTICAL` and left unwritten, with or without `-Dforce`, so its timestamp does
not move. A copy is `identical` only when every file it owns is:
the classes copied with it, its templates, the shared support classes it imports and the helper
runtime its output imports. A differing one is named
(`[owned — DIFFERS: 0 behind, 1 of your own; differing: api/index.md.mustache]`), so a resync
Expand Down
7 changes: 3 additions & 4 deletions docs/ports/csharp.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,10 +463,9 @@ The codegen emits:
enum-as-string via `HasConversion<string>()`. An int-backed enum (`@intValueMap`) gets a
converter pair that stores the declared integer and throws on a stored integer the map does
not describe, and on a write of a value it does not describe (a cast integer, say), rather
than storing another member's integer. On an `isArray` enum that pair is the element converter of an EF Core primitive
collection, so a Postgres column is `integer[]` and a SQLite or MySQL column is a JSON array
of numbers (`[5,0]`). A non-required int-backed enum array is an `IList<TEnum>?`, so a NULL
column reads back as null.
than storing another member's integer. On an `isArray` enum that pair is the element converter
of an EF Core primitive collection; see
[Int-backed enum arrays](../features/field-types.md#int-backed-enum-arrays).
- `AuthorRoutes.g.cs` — CRUD minimal-API endpoints.
- `AuthorFilterAllowlist.g.cs` — the server-side filter/sort allowlist feeding the
generated list handler.
Expand Down
Loading
Loading