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

## [Unreleased]

- **runtime-ts: a list with no `limit` answers 50 rows (breaking).** A generated entity or
projection list in a project that sets no `api.pagination` returned every matching row when the
request carried no `limit`; it now answers the first 50, the default of every port. An explicit
`limit` is still served as asked (no maximum without the setting), and a project that sets
`api.pagination` is unchanged. The OpenAPI document states the default, the `meta verify`
advisory `unbounded-list-pages` is retired, and the shared `list-query/default-page-of-fifty`
scenario pins it over a 60-row seed. Check any client that reads a whole list without a `limit`:
[docs/features/migrations/default-list-page-of-fifty.md](docs/features/migrations/default-list-page-of-fifty.md).
- **codegen-ts: the trace helper's call loop is written into the project, and
`@metaobjectsdev/ai-runtime` is no longer published.** The `trace-helper` generator now writes
`llm-call.ts` (the `LlmClient` seam and `runLlmCall`) beside the `<Entity>.trace.ts` modules,
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/) | 68 (56 query + 12 migration) | all 68; the 24 `report-*` and the `-15` decimal scenarios also on SQLite, MySQL and D1, `decimal-exact` and `guarded-update` also on MySQL (a scenario's `engines:` key is exact) | 55 query (migrations TS-only, ADR-0015; `guarded-update` deferred to L-JV-2); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (via Exposed; `guarded-update` deferred to L-KT-2); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (`guarded-update` deferred to L-CS-2); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (pg8000; `guarded-update` deferred to L-PY-2); the `report-*` and `engines:` scenarios also on SQLite (`sqlite3`) and MySQL (PyMySQL) |
| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 161 (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 + 20 list-query) | ✓ (Fastify reference + generated lane); `report/`, `decimal/` and `duration/` also on SQLite, MySQL and D1; `list-query/` is TypeScript-only until each port's 1.3.0 REST-standard work | ✓ (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/) | 162 (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 + 21 list-query) | ✓ (Fastify reference + generated lane); `report/`, `decimal/` and `duration/` also on SQLite, MySQL and D1; `list-query/` is TypeScript-only until each port's 1.3.0 REST-standard work | ✓ (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 @@ -517,9 +517,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/` (161)
### `fixtures/api-contract-conformance/` (162)

All 161 scenarios → [features/api-contract.md](features/api-contract.md) (cross-port
All 162 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 @@ -546,7 +546,7 @@ canonical string, read exactly, filtered exactly and refused past its declared d
in a calendar or clock spelling, and filtered and sorted as a span on every engine), `api-settings/` (8,
the project's `api` block: `api.pagination`'s default page, `limit_too_large` cap and refused
negative `limit`, an empty page for `limit=0`, and
`api.unknownFields: drop`), `list-query/` (20, the REST standard's list handling against a real store: search ignores case and `like` does not, `filter[or]`/`filter[and]`, the nesting cap, bare fields, a leading `%`, value formats, paging past 50, and the `invalid_json`, `invalid_id`, `pagination.invalid_value` and `constraint_violation` refusals; generated lane, TypeScript only until each port's 1.3.0 REST-standard work) and `report/` (37,
`api.unknownFields: drop`), `list-query/` (21, the REST standard's list handling against a real store: search ignores case and `like` does not, `filter[or]`/`filter[and]`, the nesting cap, bare fields, a leading `%`, value formats, a default page of 50, paging past 50, and the `invalid_json`, `invalid_id`, `pagination.invalid_value` and `constraint_violation` refusals; generated lane, TypeScript only until each port's 1.3.0 REST-standard work) and `report/` (37,
FR-044: a view-backed `object.report` is listed, filtered, sorted and paged on
its derived fields, answers `POST` with 405 and mounts no `/{id}`; a `@spine` report keeps
a row with no facts, and a measure with `@default` filters and sorts as its default). All 5 ports — TS, Java,
Expand Down Expand Up @@ -860,7 +860,7 @@ JSON and verify payload feeds it unchanged.
## Orphaned fixtures (tested but not yet documented)

The fixtures in the nine corpora mapped above (metamodel 578 + yaml 19 + verify 45
+ render 21 + persistence 68 + api-contract 161 + source-resolution 28 + scope 10 +
+ render 21 + persistence 68 + api-contract 162 + 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, `explorer-conformance` and `list-query-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
19 changes: 10 additions & 9 deletions docs/features/api-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,16 @@ each handler they register instead; an `HTTPException` is rethrown to your
traversal route (`GET /<source>/{id}/<relation>`) takes no `limit` or `offset` in any port
and is not paged by the setting: it answers the whole related set, as it always has.

**Without the setting nothing changes, and the default is per port.** With `limit` omitted,
the TypeScript mounts and the C# routes return **every** matching row, while the Java, Kotlin
and Python controllers return the first **50**, and no port caps an explicit `limit` on an
entity (`limit=100000` is honoured as asked). That is the behaviour every existing project
has, so the setting is opt-in: adding a cap on upgrade would silently truncate a client that
reads a whole list. Each port's verify advises (rule `unbounded-list-pages`, never a failure)
when a routes generator is wired and the project sets no page size: `meta verify`,
`metaobjects verify`, `mvn metaobjects:verify` (Java and Kotlin) and `dotnet meta verify
--codegen` (C# knows its generator list only when it runs it).
**Without the setting a list still pages: 50 rows, and no maximum.** With `limit` omitted, a
list answers the first **50** matching rows (`list-query/default-page-of-fifty`, over a 60-row
seed), and no port caps an explicit `limit` on an entity (`limit=100000` is honoured as asked).
The Java, Kotlin and Python controllers have always answered 50; the TypeScript mounts did so
from 1.3.0 (before, they returned **every** matching row), and the C# routes still return every
row until the same change lands there. A client that read a whole list with no `limit` now gets
the first page: send `limit`, or page with `offset` and `withCount=1`. `meta verify` no longer
advises `unbounded-list-pages`; `metaobjects verify`, `mvn metaobjects:verify` (Java and Kotlin)
and `dotnet meta verify --codegen` still name a wired routes generator with no page size (never
a failure).

**Every port reads it:** the TypeScript Fastify and Hono routes, the C# minimal-API routes, the
Java and Kotlin Spring controllers and the Python FastAPI routers, packaged and ejected (an owned
Expand Down
5 changes: 3 additions & 2 deletions docs/features/contract-emitters.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,9 @@ It also states what the routes do beyond the happy path:

- **Page size.** When the project sets `api.pagination`, a list's `limit` carries that `default` and
`maximum`, and the description names the `limit_too_large` answer. Without the setting `limit`
states neither, because the server serves what it always did. A report keeps its own row cap and
states neither either.
carries `default: 50` and no `maximum`, because the server answers 50 rows and has no ceiling
([api-contract.md](api-contract.md#sort--pagination)). A report keeps its own row cap and states
neither.
- **Undeclared body keys.** A create, `PUT` or `PATCH` body description says an undeclared key is
refused with `400 unknown_fields` (the default) or dropped under `api.unknownFields: drop`.
The shapes stay open: the server still drops a declared key a client may not set, such as the
Expand Down
2 changes: 1 addition & 1 deletion docs/features/language-differences.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ project.
| **Generated data access** | Drizzle tables and row types (`entityFile()`), CRUD queries (`queriesFile()`) | EF Core entities and `AppDbContext` | Spring DTOs and a repository interface | Exposed tables and a repository base | None: the generated router calls a repository `Protocol` you implement |
| **Runtime metadata access** | `ObjectManager` on Kysely (`@metaobjectsdev/runtime-ts`) | None yet (roadmap) | OMDB (JDBC, Spring transactions) | Through Java's OMDB | `ObjectManager` on DB-API 2; not wired to the generated router |
| **Generated REST routes** | Fastify (`routesFile()`; Hono and Drizzle mounts in `runtime-ts`) | ASP.NET minimal API | Spring `@RestController` | Spring `@RestController` | FastAPI `APIRouter` |
| **List with no `limit` and no `api.pagination`** | Every matching row | Every matching row | The first 50 | The first 50 | The first 50 |
| **List with no `limit` and no `api.pagination`** | The first 50 (every matching row before 1.3.0) | Every matching row | The first 50 | The first 50 | The first 50 |
| **Largest report page** | 10,000 rows, then 400 `report_too_large` | Same | Same | Same | Same |
| **`api.pagination`, `api.unknownFields`, the validation `issues` list** | The same in every port; defined once in [api-contract.md](api-contract.md) ([page size](api-contract.md#sort--pagination), [unknown fields](api-contract.md#unknown-request-fields-apiunknownfields), [validation issues](api-contract.md#a-validation-error-lists-every-issue)) | | | | |
| **Filter and sort errors** | 400 with `field`, plus `op`, `expected` and the allowed fields | 400 with `field` | 400 with `field` | 400 with `field` | 400 with `field` |
Expand Down
35 changes: 35 additions & 0 deletions docs/features/migrations/default-list-page-of-fifty.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Migration — a list with no `limit` answers 50 rows (`1.3.0`)

**TypeScript only; check any client that reads a whole list.** A generated list route (entity
or projection, on the Fastify, Hono and ObjectManager mounts) in a project that sets no
`api.pagination` used to answer **every** matching row when the request carried no `limit`.
From 1.3.0 it answers the first **50**, as the Java, Kotlin and Python routes always have. An
explicit `limit` is still served as asked: without `api.pagination` there is no maximum.

A project that sets `api.pagination` (every project `meta init` has scaffolded since the setting
shipped) sees no change: its `defaultLimit` and `maxLimit` apply as before.

## What to change

| Before | After |
|---|---|
| `GET /api/items` returns the whole table | it returns 50 rows; send `?limit=N`, or page with `offset` and `withCount=1` |
| a client that reads `rows.length` as the total | read `total` from `?withCount=1` |
| `meta verify` advises `unbounded-list-pages` | the advisory is gone: the lists are bounded |

The generated TanStack list hooks are not affected: the grid hook always sends a `limit`.

**An owned runtime copy** (copied by `meta eject routes` or `meta eject routes-hono`) keeps the behaviour of the copy you took. Take a
fresh copy with `meta eject routes --force` (or `routes-hono`) to get the default, or change `pageLimit` in your
copy's `drizzle-fastify/list-params.ts`.

To keep a larger default page, set it:

```json
{ "api": { "pagination": { "defaultLimit": 500, "maxLimit": 5000 } } }
```

## Why

The default page size is 50 in every port (the REST standard, `docs/features/api-contract.md`),
and a list that returns the whole table is a failure waiting for the table to grow.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface CrudRoutesOptions extends WireOptions {
/**
* The list page size (`api.pagination` in `.metaobjects/config.json`): a list with no `limit`
* returns `defaultLimit` rows, and a `limit` above `maxLimit` answers
* `400 { "error": "limit_too_large", "maxLimit": N }`. Absent → no default and no ceiling.
* `400 { "error": "limit_too_large", "maxLimit": N }`. Absent, a list with no `limit` returns 50 rows (`DEFAULT_PAGE_LIMIT`) and there is no ceiling.
*/
pagination?: PageSize;
}
Expand Down Expand Up @@ -244,7 +244,7 @@ export function mountListRoute(opts: VerbOptions): void {
if (parsed.orderBy) q = q.orderBy(...parsed.orderBy);
else if (src.id !== undefined) q = q.orderBy(asc(src.id));
const limit = pageLimit(parsed.limit, opts.pagination);
if (limit !== undefined) q = q.limit(limit);
q = q.limit(limit);
if (parsed.offset !== undefined) q = q.offset(parsed.offset);
} else {
// Legacy path — no allowlists configured. Only limit/offset (+ the TPH
Expand All @@ -253,7 +253,7 @@ export function mountListRoute(opts: VerbOptions): void {
const offset = parsePageBound(qsParsed, "offset");
if (discCond) { q = q.where(discCond); where = discCond; }
if (src.id !== undefined) q = q.orderBy(asc(src.id));
if (limit !== undefined) q = q.limit(limit);
q = q.limit(limit);
if (offset !== undefined) q = q.offset(offset);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* OPTIONAL peer): the ObjectManager mount must not pull it in.
*/

import { DEFAULT_PAGE_LIMIT } from "@metaobjectsdev/metadata";

export class FilterParseError extends Error {
constructor(public readonly code: string, message: string, public readonly details?: Record<string, unknown>) {
super(message);
Expand Down Expand Up @@ -65,10 +67,11 @@ export const ERROR_CODE_LIMIT_TOO_LARGE = "limit_too_large";
/**
* The `limit` a list route applies: the caller's, else the default page size, and a caller's
* above the maximum is refused with `400 { "error": "limit_too_large", "maxLimit": N }`. Without
* a page size the caller's `limit` (or none) passes through unchanged, as before.
* a page size a list with no `limit` answers {@link DEFAULT_PAGE_LIMIT} rows (50, as in every
* port) and a caller's `limit` is served as asked: there is no maximum to refuse it against.
*/
export function pageLimit(limit: number | undefined, pageSize: PageSize | undefined): number | undefined {
if (pageSize === undefined) return limit;
export function pageLimit(limit: number | undefined, pageSize: PageSize | undefined): number {
if (pageSize === undefined) return limit ?? DEFAULT_PAGE_LIMIT;
if (limit === undefined) return pageSize.defaultLimit;
if (limit > pageSize.maxLimit) {
throw new FilterParseError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export interface MountReadOnlyOptions extends WireOptions {
* The list page size of a projection (`api.pagination` in `.metaobjects/config.json`; ignored
* for a report, which has `reportMaxRows`, and for a raw view, which pages to at most 1000).
* A list with no `limit` returns `defaultLimit` rows; a `limit` above `maxLimit` answers
* `400 { "error": "limit_too_large", "maxLimit": N }`.
* `400 { "error": "limit_too_large", "maxLimit": N }`. Absent, a list with no `limit` returns
* 50 rows (`DEFAULT_PAGE_LIMIT`) and there is no ceiling.
*/
readonly pagination?: PageSize;
/**
Expand Down
6 changes: 3 additions & 3 deletions examples/showcase/codegen/runtime/drizzle-fastify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export interface CrudRoutesOptions extends WireOptions {
/**
* The list page size (`api.pagination` in `.metaobjects/config.json`): a list with no `limit`
* returns `defaultLimit` rows, and a `limit` above `maxLimit` answers
* `400 { "error": "limit_too_large", "maxLimit": N }`. Absent → no default and no ceiling.
* `400 { "error": "limit_too_large", "maxLimit": N }`. Absent, a list with no `limit` returns 50 rows (`DEFAULT_PAGE_LIMIT`) and there is no ceiling.
*/
pagination?: PageSize;
}
Expand Down Expand Up @@ -244,7 +244,7 @@ export function mountListRoute(opts: VerbOptions): void {
if (parsed.orderBy) q = q.orderBy(...parsed.orderBy);
else if (src.id !== undefined) q = q.orderBy(asc(src.id));
const limit = pageLimit(parsed.limit, opts.pagination);
if (limit !== undefined) q = q.limit(limit);
q = q.limit(limit);
if (parsed.offset !== undefined) q = q.offset(parsed.offset);
} else {
// Legacy path — no allowlists configured. Only limit/offset (+ the TPH
Expand All @@ -253,7 +253,7 @@ export function mountListRoute(opts: VerbOptions): void {
const offset = parsePageBound(qsParsed, "offset");
if (discCond) { q = q.where(discCond); where = discCond; }
if (src.id !== undefined) q = q.orderBy(asc(src.id));
if (limit !== undefined) q = q.limit(limit);
q = q.limit(limit);
if (offset !== undefined) q = q.offset(offset);
}

Expand Down
Loading
Loading