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
35 changes: 34 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ next release moves `metamodelVersion`.
generated code is the types and name constants its hand-written business rules use.
Editing the metadata changes the grid, the form and the API with no regeneration.
`docs/features/metadata-driven-runtime.md` measures it against the reference generators
for the same model (1,823 hand-written lines paid once, against 3,629 generated lines
for the same model (1,826 hand-written lines paid once, against 3,629 generated lines
that grow by about 726 an entity), gives the per-row cost of the metadata lookups, and
lists what the approach cannot do. It is an example on the TypeScript port, not a package.

Expand All @@ -160,6 +160,39 @@ next release moves `metamodelVersion`.

### Fixed

- **A credential is never filterable or sortable, in every port.** A field that declares a
`view.password` and that a model also marked `@filterable` or `@sortable` was on the generated
filter and sort allowlists, so a client could learn its value by probing (`filter[pinHash][eq]=...`,
a `like` prefix one character at a time, or the order of a `sort`). The allowlists are now built
without a credential (in every port a column a sibling subtype of the same single table marks as one
counts too, whichever subtype is declared first, as it does for hiding the column from responses),
so a request that names it is refused like any other field they do not hold (`400` `invalid_filter_field`
or `invalid_sort`, naming the field). The client filter type, the OpenAPI parameters and the agent UI
page leave it out too. In Java, Kotlin and C#, whose sort allowlist lists every scalar field and never read `@sortable`, a
credential was sortable with no mark at all, so the generated routes change for any model with a
credential: regenerate. Your own code is unaffected. Gated by `filter-sort-refuses-credential` in the `secret-fields/`
sub-corpus of the api-contract conformance corpus, in the generated lane of all five ports, and by
`tph-sibling-credential` in `secret-fields/tph/` for the shared-column case.

- **A numeric key is read only from canonical decimal text, in the TypeScript, Java and Python
ObjectManagers.** A path parameter or ref string for an integer, long, decimal, double or float
primary key went through the language's own number parser, which reads `0x1`, `1e0`, `0b1`, `+1`,
` 1 ` and the empty string as numbers (and Java's and Python's also `1_0`, a Unicode digit, `NaN`):
text that is no key named row 1 (or row 0), and two different texts named one row. An integer key
is now an optional `-` and ASCII digits with no leading zero; a decimal key may add `.` and at
least one digit; nothing else is a key. TypeScript refuses it with `InvalidKeyError` (a
`ValidationError`), which the mounts answer `400 {"error":"invalid_id"}` like an id the column
cannot hold; the drizzle-fastify and hono mounts and the deprecated `parseId` read ids by the
same rule, and it also refuses an integer key that is not a safe integer (beyond 2^53) and a decimal
key that is not finite: a `field.long` key above 2^53 used to round silently to another row, where
Java accepts an integer key up to `Long.MAX_VALUE`. Java refuses a ref id with `IllegalArgumentException` and Python a key argument with
`ValueError`, the errors each already raised for an unusable argument. A string or uuid key is
untouched (`0123` stays `0123`). If you pass a key as text to `findById`, `update`, `delete` or
`load`, pass its decimal spelling. The read-only mount of a raw-SQL view, which has no column type to
consult, answers `400 invalid_id` for text that reads as a number without being its canonical spelling
(`01`, `1e0`), because SQLite would convert a quoted `'01'` back to row 1. Not changed: the numeric path parameters of the generated Spring
and FastAPI routes, which those frameworks parse before the ObjectManager sees them.

- **Fix, TypeScript: `DELETE` on a missing row answers `404`, not `500`, from the
ObjectManager route mount.** `mountCrudRoutes` and `mountDeleteRoute` in
`@metaobjectsdev/runtime-ts/fastify` called `ObjectManager.delete` in its default mode, which
Expand Down
10 changes: 5 additions & 5 deletions docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/extract-conformance/`](../fixtures/extract-conformance/) | 58 | ✓ | ✓ | inherits the shared JVM engine | ✓ | ✓ |
| [`fixtures/output-prompt-conformance/`](../fixtures/output-prompt-conformance/) | 17 | ✓ | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/persistence-conformance/`](../fixtures/persistence-conformance/) | 67 (55 query + 12 migration) | all 67; the 24 `report-*` and the `-15` decimal scenarios also on SQLite, MySQL and D1, `decimal-exact` also on MySQL (a scenario's `engines:` key is exact) | 55 query (migrations TS-only, ADR-0015); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (via Exposed); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query; the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (pg8000); the `report-*` and `engines:` scenarios also on SQLite (`sqlite3`) and MySQL (PyMySQL) |
| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 139 (34 core + 14 tph + 9 m2m + 6 jsonb + 2 write-through + 2 secret-fields + 2 enum-default + 12 projection + 37 report + 11 decimal + 2 duration + 8 api-settings) | ✓ (Fastify reference + generated lane); `report/`, `decimal/` and `duration/` also on SQLite, MySQL and D1 | ✓ (embedded HTTP + JDBC); `report/`, `decimal/` and `duration/` generated controllers over OMDB on Postgres, SQLite and MySQL | ✓ (embedded HTTP + Exposed); `report/`, `decimal/` and `duration/` also on SQLite and MySQL | ✓ (Kestrel + Npgsql); `report/`, `decimal/` and `duration/` also on SQLite and MySQL | ✓ (FastAPI + pg8000); `report/`, `decimal/` and `duration/` also on SQLite and MySQL |
| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 141 (34 core + 14 tph + 9 m2m + 6 jsonb + 2 write-through + 4 secret-fields + 2 enum-default + 12 projection + 37 report + 11 decimal + 2 duration + 8 api-settings) | ✓ (Fastify reference + generated lane); `report/`, `decimal/` and `duration/` also on SQLite, MySQL and D1 | ✓ (embedded HTTP + JDBC); `report/`, `decimal/` and `duration/` generated controllers over OMDB on Postgres, SQLite and MySQL | ✓ (embedded HTTP + Exposed); `report/`, `decimal/` and `duration/` also on SQLite and MySQL | ✓ (Kestrel + Npgsql); `report/`, `decimal/` and `duration/` also on SQLite and MySQL | ✓ (FastAPI + pg8000); `report/`, `decimal/` and `duration/` also on SQLite and MySQL |
| [`fixtures/decimal-wire/`](../fixtures/decimal-wire/) | 1 vector file (format, parse, filter operand, 15-digit read) | ✓ (`runtime-ts` and the generated helper) | ✓ (`CanonicalDecimal`) | ✓ (the generated wire file) | ✓ (`DecimalWire`) | ✓ (`decimal_wire`) |
| [`fixtures/duration-wire/`](../fixtures/duration-wire/) | 1 vector file: the `wire` vectors (parse, precision, refused) every port passes, and the `codecs` groups (Postgres text read and write, stored microseconds) each port passes only for the codecs it has | ✓ (`metadata` / `runtime-ts` and the generated helper) | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/validation-conformance/`](../fixtures/validation-conformance/) | 42 cases + 43 cross-field cases (`cross-field-cases.json`, generated record model only) | ✓ (generated Zod + run-time `runValidators`) | ✓ | ✓ | ✓ | ✓ (generated Pydantic + run-time `run_validators`) |
Expand Down Expand Up @@ -497,9 +497,9 @@ REAL, a MySQL `DECIMAL` keeps its scale, a MySQL `DATETIME` is the UTC wall cloc
`report-relative-date` carries a per-engine seed (`seed-data-engine`). `op: relate` and the
write ops stay Postgres-only. See [features/reporting.md](features/reporting.md#what-the-corpus-gates).

### `fixtures/api-contract-conformance/` (139)
### `fixtures/api-contract-conformance/` (141)

All 139 scenarios → [features/api-contract.md](features/api-contract.md) (cross-port
All 141 scenarios → [features/api-contract.md](features/api-contract.md) (cross-port
REST API URL grammar + JSON wire format). Verifies every backend's emitted CRUD
routes answer identically over HTTP — list / get / create / patch+put / delete,
plus pagination (`limit`/`offset`), sort (`sort=field:dir`), the `withCount=1`
Expand All @@ -517,7 +517,7 @@ inheritance; a subtype decimal filters and refuses extra digits, and the input r
the whole hierarchy), `m2m/` (9 — 3 plain, 5 gating TPH x M:N together, the combination
each corpus alone could not reach, and 1 pinning the collection-URL spelling),
`jsonb/` (6, typed value-object columns; numbers inside them: a double stays a JSON number, a decimal is the canonical string; an undeclared member inside a value object is dropped),
`write-through/` (2, table-write + view-read entities), `secret-fields/` (2, #484: a `@formExclude` or credential `view.password` field is ignored on create, PATCH and PUT, and a credential is never returned), `enum-default/` (2, a create that omits a `field.enum` with `@default` stores the default, and a supplied value is kept), `projection/` (12, a
`write-through/` (2, table-write + view-read entities), `secret-fields/` (4, #484: a `@formExclude` or credential `view.password` field is ignored on create, PATCH and PUT, a credential is never returned, and a credential marked `@filterable` or `@sortable` is still on neither allowlist, so a filter or sort naming it is a 400; the `tph/` sub-directory is a TPH hierarchy whose subtypes share a column one of them marks as a credential, which is on no allowlist of the base or either subtype), `enum-default/` (2, a create that omits a `field.enum` with `@default` stores the default, and a supplied value is kept), `projection/` (12, a
read-only view answers reads and refuses writes with 405; a projection with no declared
identity has no item route; a projection keyed on a field not named `id` is addressed by
it, whether its identity names `@fields` or derives them; decimal and float fields filter), `decimal/` (11, ADR-0019 Amendment 1: a decimal, array element and undeclared-precision column included, is one
Expand Down Expand Up @@ -810,7 +810,7 @@ JSON and verify payload feeds it unchanged.
## Orphaned fixtures (tested but not yet documented)

The fixtures in the nine corpora mapped above (metamodel 574 + yaml 19 + verify 45
+ render 18 + persistence 67 + api-contract 139 + source-resolution 28 + scope 10 +
+ render 18 + persistence 67 + api-contract 141 + source-resolution 28 + scope 10 +
dependency 47) each map to a feature doc, and so do the two requirement corpora, `rules-check-conformance`, `shared-model-conformance`, the
`cube-model` corpus and `explorer-conformance`, whose case lists live in their own READMEs. None are orphaned today. The remaining
corpora in the totals table gate tooling contracts (registry manifests, provider
Expand Down
9 changes: 5 additions & 4 deletions docs/features/api-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ or Hono `onError` the adopter installed, answer exactly as they did before.
| Response | When |
|---|---|
| malformed JSON body | a `POST`/`PATCH`/`PUT` body that does not parse as JSON (an empty body sent as `application/json` included) → HTTP 400 `{ "error": "invalid_json" }`. An EMPTY body on a method that takes none (`GET`, `DELETE`, `HEAD`) is accepted even when the request declares `content-type: application/json`, as many clients do on every request; a non-empty `DELETE` body is still parsed. Before, Fastify answered its own `{ "statusCode": 400, "code": "FST_ERR_CTP_INVALID_JSON_BODY", … }` and Hono a Zod `validation` error about a missing object |
| malformed id | a `:id` the key column cannot hold (a malformed uuid on a Postgres uuid key, a non-numeric id on an integer key) → HTTP 400 `{ "error": "invalid_id" }` on GET, PATCH and DELETE. A malformed uuid in a POST or PATCH body's foreign key → HTTP 400 `{ "error": "validation" }`, from the insert/update schema's `8-4-4-4-12` hex check. Postgres used to answer 500 for both. The check is TS-only |
| malformed id | a `:id` the key column cannot hold (a malformed uuid on a Postgres uuid key, a non-numeric id on an integer key, or numeric text that is not the canonical spelling of a number, such as `0x1` or `1e0`) → HTTP 400 `{ "error": "invalid_id" }` on GET, PATCH and DELETE. A malformed uuid in a POST or PATCH body's foreign key → HTTP 400 `{ "error": "validation" }`, from the insert/update schema's `8-4-4-4-12` hex check. Postgres used to answer 500 for both. The check is TS-only. The TypeScript, Java and Python ObjectManagers apply the numeric rule to a key passed as text to `findById`, `update`, `delete` and `load`: an optional `-` and ASCII digits with no leading zero (a decimal key may add `.` and digits), and no exponent, hex, plus sign, whitespace or negative zero, so the caller passes the decimal spelling. A string or uuid key is untouched |
| malformed page bound | a `?limit=` or `?offset=` that is not a non-negative integer (`abc`, `-5`, `1.5`, an empty value) → HTTP 400 `{ "error": "pagination.invalid_value", "param": "limit", "value": "abc", "expected": "a non-negative integer (0 or more)" }`. Before, a non-numeric bound was dropped (every row came back) and a negative or fractional one reached SQL. An entity or a projection with declared columns has no page-size maximum unless the project sets `api.pagination` (see "A page size is a project setting" below, which answers `limit_too_large`); an opaque view (no declared columns, served by raw SQL) pages to at most 1000 rows, so there a `limit` above 1000 is refused too, with `"expected": "an integer from 0 to 1000"` (it used to be clamped silently). The same answer comes from the Drizzle mounts and the ObjectManager Fastify mount. The corpus sends a malformed bound only to a report (`report/bad-page-bound`), where every port answers this same envelope and also refuses `limit=0`; on an entity or a projection the other ports answer it as their framework does |
| database constraint violation | a write the database itself rejects → `{ "error": "constraint_violation", "constraint": "<kind>" }`, HTTP **409** for `unique` and `foreign_key` (a conflict with another row) and HTTP **400** for `check` and `not_null` (the request's own value), per the status rule under "Error response". The body names the constraint KIND only — never the SQL, the table or the bound values. A `CHECK` the model derives (an enum, a `validator.numeric`/`length`/`regex` range) is normally refused earlier by the route's own validation, as the corpus's `{ "error": "validation" }` 400; this row is the database's backstop |
| schema validation failure | a body that fails the insert/update schema → HTTP 400 `{ "error": "validation", "issues": [...] }`, each issue as Zod reports it **minus `pattern`**: Zod 4 attaches a failed `.regex()` check's source there, which for a generated `field.date` / `field.time` / `field.timestamp` check is a ~300-character calendar regex (and an authored `validator.regex` pattern is the server's to keep). The generated temporal checks carry a short `message` naming the expected format instead (`"must be an ISO date (YYYY-MM-DD)"`) |
Expand Down Expand Up @@ -683,9 +683,10 @@ pin `reject` in both lanes of every port, and `api-settings/unknown-fields-dropp
the generated lane.

Only the generated HTTP boundary changes. The entity, its DTO and the generated queries still carry the
field, so your own code writes a hash or token and reads it back. Allowlists are unchanged: a field is
filterable or sortable only if you wrote `@filterable` or `@sortable` on it, so do not put those on a credential
(a filter on a secret answers whether a guess is right). To return a credential from a route, hand-write that
field, so your own code writes a hash or token and reads it back. A credential is also never on a filter or sort
allowlist, whatever `@filterable` or `@sortable` say on it (a filter on a secret answers whether a guess is right,
and its order leaks it): the allowlist is built without it, so a request that names it is refused as any other field
the allowlist does not hold (`400` `invalid_filter_field` or `invalid_sort`, naming the field). On a single-table (TPH) hierarchy the mark holds for the shared column: a column one subtype marks as a credential is on no allowlist of the base or of any subtype. To return a credential from a route, hand-write that
route; the generated one will not. Generated forms and the api docs omit both kinds of field as well.

A served report is covered too. A report column is derived from its `@of` field, and a derived column keeps
Expand Down
4 changes: 2 additions & 2 deletions docs/features/field-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ Five rows need a footnote:
| `@maxLength` | int | Length for string types (drives `varchar(N)`). |
| `@column` | string | Physical column name (overrides the project's `naming.columns` rule). |
| `@default` | any | Default value (literal or canonical SQL default function). |
| `@filterable` | bool | Field appears in the generated server-side filter allowlist. |
| `@sortable` | bool | Field appears in the server-side sort allowlist (defaults to `@filterable`). |
| `@filterable` | bool | Field appears in the generated server-side filter allowlist, unless it is a credential (`view.password`); see [api-contract.md](api-contract.md). |
| `@sortable` | bool | Field appears in the server-side sort allowlist (defaults to `@filterable`), unless it is a credential. |

## Column naming — `@column` and the `naming` setting

Expand Down
5 changes: 1 addition & 4 deletions docs/features/metadata-driven-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,14 @@ rule below has tests in `examples/dynamic-grid/test/`.
| Constraint errors | A unique or foreign-key failure is a `409` or `400` that names no table or column. | `write-contract.test.ts` |
| Model reload | Reloads run one at a time. A schema change is applied by the migration engine's transactional applier, so one that fails part-way changes nothing and the model that was being served stays in place. | `reload-safety.test.ts` |

Three defects outside the example turned up while building this:
Two defects outside the example turned up while building this:

- `DELETE` on a missing row through the `ObjectManager` route mount in
`@metaobjectsdev/runtime-ts/fastify` answered `500`. Fixed in the package (it answers
`404`), and the example's mount does the same.
- An `offset` with no `limit` was a SQL syntax error on SQLite and MySQL in both the Kysely
and the Drizzle driver, so a list with no `api.pagination` answered `500` to `?offset=5`.
Fixed in the drivers.
- The reference route generator's filter allowlist does not leave out a credential that a
model marks `@filterable`. This mount does. The generators were out of scope here, so
that one is reported and not changed.

## Measurement

Expand Down
2 changes: 1 addition & 1 deletion docs/features/own-your-codegen.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ calls it copies the adapter's source too:

| `meta eject …` | Copies into `codegen/generators/` | Also copies into `codegen/runtime/` (verbatim from `@metaobjectsdev/runtime-ts/src`) |
|---|---|---|
| `routes` | `routes.ts` — the whole route composition (CRUD, read-only projections, M:N traversal, TPH per-subtype sets), not a call into the engine | `drizzle-fastify/*` (mounts, filter parser, list params, M:N and read-only mounts, error handler), `route-errors.ts`, `constraint-errors.ts`, `timestamp-wire.ts` |
| `routes` | `routes.ts` — the whole route composition (CRUD, read-only projections, M:N traversal, TPH per-subtype sets), not a call into the engine | `drizzle-fastify/*` (mounts, filter parser, list params, M:N and read-only mounts, error handler), `route-errors.ts`, `constraint-errors.ts`, `timestamp-wire.ts`, `decimal-wire.ts`, `duration-wire.ts`, `wire-format.ts`, `sql-dialect.ts`, `canonical-key.ts`, `errors.ts` |
| `routes-hono` | `routes-hono.ts`, likewise self-contained | `hono/*`, plus the shared parser, allowlist, envelope and timestamp files it reaches |
| `entity` | `entity.ts` | `drizzle-fastify/filter-allowlist.ts` — the `FilterAllowlist` / `SortAllowlist` types the entity module's allowlists are typed by |

Expand Down
Loading
Loading