From 850ba97214e9414e8d76cbe4aa4e73bbfacea4e9 Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Sun, 22 Nov 2026 01:58:01 -0500 Subject: [PATCH 1/4] feat(runtime-ts): a list with no limit answers 50 rows (D11-TS) 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 (DEFAULT_PAGE_LIMIT in metadata), the default of every port; an explicit `limit` is still served as asked, since there is no maximum without the setting. A project that sets the block is unchanged. - pageLimit returns the default when there is no page size, on the Fastify, Hono and ObjectManager mounts and on projection lists. - The OpenAPI document states the default (and no maximum) when the project sets no page size; contract-conformance goldens regenerated. - The `meta verify` advisory `unbounded-list-pages` is retired. - New shared scenario api-contract list-query/default-page-of-fifty over the 60-row seed; counts updated. - Docs: api-contract, language differences, CHANGELOG, and an upgrade guide (docs/features/migrations/default-list-page-of-fifty.md). Owned example runtime copies and the site payload resynced. --- CHANGELOG.md | 8 +++ docs/CONFORMANCE.md | 10 ++-- docs/features/api-contract.md | 19 ++++--- docs/features/language-differences.md | 2 +- .../migrations/default-list-page-of-fifty.md | 35 ++++++++++++ .../codegen/runtime/drizzle-fastify/index.ts | 6 +- .../runtime/drizzle-fastify/list-params.ts | 9 ++- .../drizzle-fastify/mount-read-only.ts | 3 +- .../codegen/runtime/drizzle-fastify/index.ts | 6 +- .../runtime/drizzle-fastify/list-params.ts | 9 ++- .../drizzle-fastify/mount-read-only.ts | 3 +- examples/showcase/site-payload.json | 2 +- fixtures/api-contract-conformance/README.md | 4 +- .../list-query/README.md | 3 + .../scenarios/default-page-of-fifty.yaml | 37 ++++++++++++ .../expected/openapi.json | 8 ++- .../expected/openapi.json | 8 ++- .../all-fields/expected/openapi.json | 8 ++- .../api-settings-drop/expected/openapi.json | 4 +- .../blog/expected/openapi.json | 4 +- .../decimal/expected/openapi.json | 8 ++- .../jsonb/expected/openapi.json | 4 +- .../list-query/expected/openapi.json | 4 +- .../m2m/expected/openapi.json | 56 ++++++++++++++----- .../nullable-members/expected/openapi.json | 8 ++- .../projection/expected/openapi.json | 20 +++++-- .../report/expected/openapi.json | 28 +++++++--- .../secret-fields/expected/openapi.json | 4 +- .../tph-shared-marks/expected/openapi.json | 12 +++- .../tph/expected/openapi.json | 16 ++++-- .../write-through/expected/openapi.json | 8 ++- .../packages/cli/src/commands/init.ts | 10 ++-- .../packages/cli/src/commands/verify.ts | 22 -------- .../packages/cli/src/lib/advisory.ts | 22 -------- .../cli/src/lib/pagination-advisory.ts | 48 ---------------- .../typescript/packages/cli/test/init.test.ts | 2 +- .../cli/test/pagination-advisory.test.ts | 42 -------------- .../packages/codegen-ts/src/api-surface.ts | 5 +- .../codegen-ts/src/contract/build-openapi.ts | 23 +++++--- .../test/contract/contract-behaviours.test.ts | 4 +- .../packages/metadata/src/api-pagination.ts | 11 +++- .../typescript/packages/metadata/src/index.ts | 2 +- .../runtime-ts/src/drizzle-fastify/index.ts | 6 +- .../src/drizzle-fastify/list-params.ts | 9 ++- .../src/drizzle-fastify/mount-read-only.ts | 3 +- .../packages/runtime-ts/src/fastify/index.ts | 6 +- .../packages/runtime-ts/src/hono/index.ts | 6 +- .../runtime-ts/src/hono/mount-read-only.ts | 3 +- .../runtime-ts/test/list-page-size.test.ts | 22 ++++---- 49 files changed, 342 insertions(+), 260 deletions(-) create mode 100644 docs/features/migrations/default-list-page-of-fifty.md create mode 100644 fixtures/api-contract-conformance/list-query/scenarios/default-page-of-fifty.yaml delete mode 100644 server/typescript/packages/cli/src/lib/pagination-advisory.ts delete mode 100644 server/typescript/packages/cli/test/pagination-advisory.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e116617b1..1deba5648e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 `.trace.ts` modules, diff --git a/docs/CONFORMANCE.md b/docs/CONFORMANCE.md index 0bd32486d3..3b6c0debc8 100644 --- a/docs/CONFORMANCE.md +++ b/docs/CONFORMANCE.md @@ -36,7 +36,7 @@ regenerate with `ls -d fixtures//*/ | 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`) | @@ -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` @@ -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, @@ -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 diff --git a/docs/features/api-contract.md b/docs/features/api-contract.md index bfb1d55f6e..a1c0f89187 100644 --- a/docs/features/api-contract.md +++ b/docs/features/api-contract.md @@ -308,15 +308,16 @@ each handler they register instead; an `HTTPException` is rethrown to your traversal route (`GET //{id}/`) 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 diff --git a/docs/features/language-differences.md b/docs/features/language-differences.md index 0a71234c87..1324109fe2 100644 --- a/docs/features/language-differences.md +++ b/docs/features/language-differences.md @@ -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` | diff --git a/docs/features/migrations/default-list-page-of-fifty.md b/docs/features/migrations/default-list-page-of-fifty.md new file mode 100644 index 0000000000..1b91299afb --- /dev/null +++ b/docs/features/migrations/default-list-page-of-fifty.md @@ -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** (`meta eject runtime`) keeps the behaviour of the copy you took. Take a +fresh copy with `meta eject runtime --force` 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. diff --git a/examples/advanced-modeling/codegen/runtime/drizzle-fastify/index.ts b/examples/advanced-modeling/codegen/runtime/drizzle-fastify/index.ts index 225721b86a..a25a004dfc 100644 --- a/examples/advanced-modeling/codegen/runtime/drizzle-fastify/index.ts +++ b/examples/advanced-modeling/codegen/runtime/drizzle-fastify/index.ts @@ -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; } @@ -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 @@ -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); } diff --git a/examples/advanced-modeling/codegen/runtime/drizzle-fastify/list-params.ts b/examples/advanced-modeling/codegen/runtime/drizzle-fastify/list-params.ts index 1a1bdc3412..927687abc5 100644 --- a/examples/advanced-modeling/codegen/runtime/drizzle-fastify/list-params.ts +++ b/examples/advanced-modeling/codegen/runtime/drizzle-fastify/list-params.ts @@ -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) { super(message); @@ -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( diff --git a/examples/advanced-modeling/codegen/runtime/drizzle-fastify/mount-read-only.ts b/examples/advanced-modeling/codegen/runtime/drizzle-fastify/mount-read-only.ts index c06f5fdaec..cec28d7fa5 100644 --- a/examples/advanced-modeling/codegen/runtime/drizzle-fastify/mount-read-only.ts +++ b/examples/advanced-modeling/codegen/runtime/drizzle-fastify/mount-read-only.ts @@ -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; /** diff --git a/examples/showcase/codegen/runtime/drizzle-fastify/index.ts b/examples/showcase/codegen/runtime/drizzle-fastify/index.ts index 225721b86a..a25a004dfc 100644 --- a/examples/showcase/codegen/runtime/drizzle-fastify/index.ts +++ b/examples/showcase/codegen/runtime/drizzle-fastify/index.ts @@ -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; } @@ -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 @@ -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); } diff --git a/examples/showcase/codegen/runtime/drizzle-fastify/list-params.ts b/examples/showcase/codegen/runtime/drizzle-fastify/list-params.ts index 1a1bdc3412..927687abc5 100644 --- a/examples/showcase/codegen/runtime/drizzle-fastify/list-params.ts +++ b/examples/showcase/codegen/runtime/drizzle-fastify/list-params.ts @@ -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) { super(message); @@ -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( diff --git a/examples/showcase/codegen/runtime/drizzle-fastify/mount-read-only.ts b/examples/showcase/codegen/runtime/drizzle-fastify/mount-read-only.ts index c06f5fdaec..cec28d7fa5 100644 --- a/examples/showcase/codegen/runtime/drizzle-fastify/mount-read-only.ts +++ b/examples/showcase/codegen/runtime/drizzle-fastify/mount-read-only.ts @@ -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; /** diff --git a/examples/showcase/site-payload.json b/examples/showcase/site-payload.json index ad7b2811ca..519bdc3369 100644 --- a/examples/showcase/site-payload.json +++ b/examples/showcase/site-payload.json @@ -74,7 +74,7 @@ }, "verify-transcript": { "lang": "console", - "inline": "meta verify — requirements: 1 entries (1 functional, 0 architectural) — 1 live; 1/1 entities claimed, counted over 1 metadata file(s).\nmeta verify — not run: schema (--db <url>), codegen (--codegen), deps (--deps), replay (--replay)\nmeta: [subscriberBlurb] (prompt) ERR_VAR_NOT_ON_PAYLOAD: name (templates/subscriber/blurb.mustache:1)\nmeta: meta verify — 1 drift error(s) across 1 template(s).\nmeta: meta verify — generated list routes have no page size (advisory — does not fail the build):\nmeta: .metaobjects/config.json: routes-file is wired and the project sets no api.pagination, so a generated list route with no ?limit= returns the whole table and accepts any ?limit=. Add \"api\": { \"pagination\": { \"defaultLimit\": 50, \"maxLimit\": 1000 } } to give every list a default page size and answer a larger ?limit= with 400 limit_too_large.", + "inline": "meta verify — requirements: 1 entries (1 functional, 0 architectural) — 1 live; 1/1 entities claimed, counted over 1 metadata file(s).\nmeta verify — not run: schema (--db <url>), codegen (--codegen), deps (--deps), replay (--replay)\nmeta: [subscriberBlurb] (prompt) ERR_VAR_NOT_ON_PAYLOAD: name (templates/subscriber/blurb.mustache:1)\nmeta: meta verify — 1 drift error(s) across 1 template(s).", "full": null, "lineCount": null }, diff --git a/fixtures/api-contract-conformance/README.md b/fixtures/api-contract-conformance/README.md index c3feaea637..96b2f880b2 100644 --- a/fixtures/api-contract-conformance/README.md +++ b/fixtures/api-contract-conformance/README.md @@ -57,7 +57,7 @@ fixtures/api-contract-conformance/ ``` Beside the 34 core scenarios above sit twelve **sub-corpora**, each a directory with its -own `meta.json`, `seed.json`, `scenarios/` and `README.md` (127 scenarios in all, 161 with the +own `meta.json`, `seed.json`, `scenarios/` and `README.md` (128 scenarios in all, 162 with the core): | Directory | Scenarios | Gates | Lanes | @@ -72,7 +72,7 @@ core): | `report/` | 37 | a view-backed `object.report` (FR-044): list, filter, sort and paging on derived fields, `POST` is `405`, no `/{id}` route; a `@spine` report keeps a row with no facts, and a measure with `@default` filters and sorts as its default; a dimension over an array or a map is neither filterable nor sortable. Also carries `schema.postgres.sql`, the TypeScript-produced table and views the C# lane executes | generated only | | `decimal/` | 11 | `field.decimal` is an exact canonical string on the wire (ADR-0019 Amendment 1): read, filter, sort, write and a report over decimals. A scenario's `engines:` key is exact; the `-15` twins run on SQLite and D1 as well. Also carries `schema.postgres.sql` / `schema.sqlite.sql` / `schema.mysql.sql` | generated only | | `api-settings/` | 8 | the `api` block in the sub-corpus's own `.metaobjects/config.json`: `api.pagination` (default 2, max 4) — a list with no `limit` answers the default page, `offset` and `withCount=1` page past it, `limit` at the cap is served, one above it is `400 {"error": "limit_too_large", "maxLimit": 4}` and a negative one is `400 pagination.invalid_value`, while `limit=0` is an empty page — and `api.unknownFields: drop`, under which an undeclared body key is ignored rather than refused | generated only | -| `list-query/` | 20 | the REST standard's list handling against a real store, over a 60-row seed: `?search` ignores case and `like` does not, `filter[or]` / `filter[and]`, the nesting cap, a bare field refused, a leading `%` refused, value formats refused, paging past 50, and the `invalid_json`, `invalid_id`, `pagination.invalid_value` and `constraint_violation` refusals. The parse itself is pinned with no server by `fixtures/list-query-conformance/`. TypeScript only until each port's 1.3.0 REST-standard work | generated only | +| `list-query/` | 21 | the REST standard's list handling against a real store, over a 60-row seed: `?search` ignores case and `like` does not, `filter[or]` / `filter[and]`, the nesting cap, a bare field refused, a leading `%` refused, value formats refused, a default page of 50, paging past 50, and the `invalid_json`, `invalid_id`, `pagination.invalid_value` and `constraint_violation` refusals. The parse itself is pinned with no server by `fixtures/list-query-conformance/`. TypeScript only until each port's 1.3.0 REST-standard work | generated only | | `duration/` | 2 | `field.duration` is a canonical ISO-8601 span on the wire under `"wire": { "durations": "iso" }`: write, read, refuse, and filter and sort as a span on every engine. Also carries `schema.postgres.sql` / `schema.sqlite.sql` / `schema.mysql.sql` | generated only | `meta.json` declares a single canonical `Author` entity in the `acme::blog` diff --git a/fixtures/api-contract-conformance/list-query/README.md b/fixtures/api-contract-conformance/list-query/README.md index a2546ea4ef..741d9ec664 100644 --- a/fixtures/api-contract-conformance/list-query/README.md +++ b/fixtures/api-contract-conformance/list-query/README.md @@ -27,6 +27,9 @@ boundary sits inside the table. Four names differ only in case and position, so - a page bound that is not a non-negative integer is `pagination.invalid_value`. An unknown parameter such as a cache-buster is ignored. +- **The default page is 50:** with no `limit` (the corpus sets no `api.pagination`), a list + answers rows 1 to 50, `offset=50` answers 51 to 60, `limit=60` answers all 60 (no maximum + without the setting), and `withCount=1` answers 50 rows with `total: 60`. - **Paging past 50:** - `limit=51` answers 51 rows; - `limit=5&offset=51` answers rows 52 to 56; diff --git a/fixtures/api-contract-conformance/list-query/scenarios/default-page-of-fifty.yaml b/fixtures/api-contract-conformance/list-query/scenarios/default-page-of-fifty.yaml new file mode 100644 index 0000000000..7aab8945cb --- /dev/null +++ b/fixtures/api-contract-conformance/list-query/scenarios/default-page-of-fifty.yaml @@ -0,0 +1,37 @@ +name: default-page-of-fifty +description: > + A list with no `limit`, in a project that sets no `api.pagination`, answers the first 50 rows: + the default page size of every port. The seed has 60 rows, so a port that returns the whole + table answers 60. An explicit `limit` above 50 is served as asked (there is no maximum without + the setting), and `withCount=1` still counts every row. +requests: + - id: r1 + method: GET + path: "/api/parts?sort=id:asc" + expect: + status: 200 + body: + length: 50 + - id: r2 + method: GET + path: "/api/parts?offset=50&sort=id:asc" + expect: + status: 200 + body: + ids: [51, 52, 53, 54, 55, 56, 57, 58, 59, 60] + - id: r3 + method: GET + path: "/api/parts?limit=60&sort=id:asc" + expect: + status: 200 + body: + length: 60 + - id: r4 + method: GET + path: "/api/parts?withCount=1" + expect: + status: 200 + body: + envelope: true + rowsLength: 50 + total: 60 diff --git a/fixtures/contract-conformance/all-fields-wire-string-emit/expected/openapi.json b/fixtures/contract-conformance/all-fields-wire-string-emit/expected/openapi.json index 934111d29e..d39a09495b 100644 --- a/fixtures/contract-conformance/all-fields-wire-string-emit/expected/openapi.json +++ b/fixtures/contract-conformance/all-fields-wire-string-emit/expected/openapi.json @@ -1027,9 +1027,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1352,9 +1354,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/all-fields-wire-string-omit/expected/openapi.json b/fixtures/contract-conformance/all-fields-wire-string-omit/expected/openapi.json index 494998511b..aa34076c4c 100644 --- a/fixtures/contract-conformance/all-fields-wire-string-omit/expected/openapi.json +++ b/fixtures/contract-conformance/all-fields-wire-string-omit/expected/openapi.json @@ -1027,9 +1027,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1352,9 +1354,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/all-fields/expected/openapi.json b/fixtures/contract-conformance/all-fields/expected/openapi.json index c4486d1fc8..6a0f02cad6 100644 --- a/fixtures/contract-conformance/all-fields/expected/openapi.json +++ b/fixtures/contract-conformance/all-fields/expected/openapi.json @@ -1027,9 +1027,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1352,9 +1354,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/api-settings-drop/expected/openapi.json b/fixtures/contract-conformance/api-settings-drop/expected/openapi.json index 93e470d7a9..473519d9c4 100644 --- a/fixtures/contract-conformance/api-settings-drop/expected/openapi.json +++ b/fixtures/contract-conformance/api-settings-drop/expected/openapi.json @@ -306,9 +306,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/blog/expected/openapi.json b/fixtures/contract-conformance/blog/expected/openapi.json index 10c6a967c6..3f8b078215 100644 --- a/fixtures/contract-conformance/blog/expected/openapi.json +++ b/fixtures/contract-conformance/blog/expected/openapi.json @@ -306,9 +306,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/decimal/expected/openapi.json b/fixtures/contract-conformance/decimal/expected/openapi.json index ff2ef9ef8c..7303e21c96 100644 --- a/fixtures/contract-conformance/decimal/expected/openapi.json +++ b/fixtures/contract-conformance/decimal/expected/openapi.json @@ -255,9 +255,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1372,9 +1374,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/jsonb/expected/openapi.json b/fixtures/contract-conformance/jsonb/expected/openapi.json index 63be12d3b3..bb0d337bba 100644 --- a/fixtures/contract-conformance/jsonb/expected/openapi.json +++ b/fixtures/contract-conformance/jsonb/expected/openapi.json @@ -180,9 +180,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/list-query/expected/openapi.json b/fixtures/contract-conformance/list-query/expected/openapi.json index 4f54fa0b97..8569544afb 100644 --- a/fixtures/contract-conformance/list-query/expected/openapi.json +++ b/fixtures/contract-conformance/list-query/expected/openapi.json @@ -364,9 +364,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/m2m/expected/openapi.json b/fixtures/contract-conformance/m2m/expected/openapi.json index 3f9012f178..d1498b8976 100644 --- a/fixtures/contract-conformance/m2m/expected/openapi.json +++ b/fixtures/contract-conformance/m2m/expected/openapi.json @@ -239,9 +239,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -602,9 +604,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1201,9 +1205,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1628,9 +1634,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1953,9 +1961,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -2278,9 +2288,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -2603,9 +2615,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -2928,9 +2942,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -3321,9 +3337,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -3714,9 +3732,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -4039,9 +4059,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -4364,9 +4386,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -4689,9 +4713,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -5014,9 +5040,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/nullable-members/expected/openapi.json b/fixtures/contract-conformance/nullable-members/expected/openapi.json index a17efbac6f..9807674ee6 100644 --- a/fixtures/contract-conformance/nullable-members/expected/openapi.json +++ b/fixtures/contract-conformance/nullable-members/expected/openapi.json @@ -15,9 +15,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -341,9 +343,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/projection/expected/openapi.json b/fixtures/contract-conformance/projection/expected/openapi.json index b2c45b2868..94ddb07e68 100644 --- a/fixtures/contract-conformance/projection/expected/openapi.json +++ b/fixtures/contract-conformance/projection/expected/openapi.json @@ -15,9 +15,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -656,9 +658,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -940,9 +944,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1224,9 +1230,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1575,9 +1583,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/report/expected/openapi.json b/fixtures/contract-conformance/report/expected/openapi.json index 50ee300f02..843a67dff4 100644 --- a/fixtures/contract-conformance/report/expected/openapi.json +++ b/fixtures/contract-conformance/report/expected/openapi.json @@ -15,9 +15,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -669,9 +671,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -994,9 +998,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -3159,9 +3165,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -4342,9 +4350,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -4941,9 +4951,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -6062,9 +6074,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/secret-fields/expected/openapi.json b/fixtures/contract-conformance/secret-fields/expected/openapi.json index f721f84354..0369bde447 100644 --- a/fixtures/contract-conformance/secret-fields/expected/openapi.json +++ b/fixtures/contract-conformance/secret-fields/expected/openapi.json @@ -180,9 +180,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/tph-shared-marks/expected/openapi.json b/fixtures/contract-conformance/tph-shared-marks/expected/openapi.json index a5f9ea7be7..d38c5da6c8 100644 --- a/fixtures/contract-conformance/tph-shared-marks/expected/openapi.json +++ b/fixtures/contract-conformance/tph-shared-marks/expected/openapi.json @@ -15,9 +15,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -132,9 +134,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -457,9 +461,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/tph/expected/openapi.json b/fixtures/contract-conformance/tph/expected/openapi.json index 22cc1e2755..c01c628935 100644 --- a/fixtures/contract-conformance/tph/expected/openapi.json +++ b/fixtures/contract-conformance/tph/expected/openapi.json @@ -242,9 +242,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -599,9 +601,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1164,9 +1168,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -1701,9 +1707,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/fixtures/contract-conformance/write-through/expected/openapi.json b/fixtures/contract-conformance/write-through/expected/openapi.json index 88f8c1f2fd..9f7c4101e9 100644 --- a/fixtures/contract-conformance/write-through/expected/openapi.json +++ b/fixtures/contract-conformance/write-through/expected/openapi.json @@ -15,9 +15,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { @@ -340,9 +342,11 @@ { "name": "limit", "in": "query", + "description": "Rows per page. Absent, the server answers 50.", "schema": { "type": "integer", - "minimum": 0 + "minimum": 0, + "default": 50 } }, { diff --git a/server/typescript/packages/cli/src/commands/init.ts b/server/typescript/packages/cli/src/commands/init.ts index e8142a2820..42aa92e594 100644 --- a/server/typescript/packages/cli/src/commands/init.ts +++ b/server/typescript/packages/cli/src/commands/init.ts @@ -622,10 +622,12 @@ async function writeConfigFile(opts: InitOptions, result: InitResult, agentDir: // New-project defaults, each written as its own visible setting (a project that predates // a setting keeps the behaviour it had, because the key is absent there): every foreign key // gets an index, a hand edit to a generated file fails `meta verify --codegen`, and every - // generated list route has a page size. They are written here and not into DEFAULT_CONFIG: - // the merge below must not add them to an existing project on `--force` (a page size added - // on upgrade would truncate a client that reads a whole list). `unknownFields` is written out - // at its default, so the choice is visible where a project would change it. + // generated list route refuses a `?limit=` above 1000. They are written here and not into + // DEFAULT_CONFIG: the merge below must not add them to an existing project on `--force` (a + // maximum added on upgrade would refuse a client that asks for a large page; with no block a + // list already answers 50 rows when `limit` is absent). `pagination.defaultLimit` and + // `unknownFields` are written out at their defaults, so the choice is visible where a project + // would change it. // MySQL writes no `migrate` block at all: MetaObjects does not own MySQL schema, and InnoDB // indexes every foreign key itself. const freshConfig = ConfigSchema.parse({ diff --git a/server/typescript/packages/cli/src/commands/verify.ts b/server/typescript/packages/cli/src/commands/verify.ts index 4c0c6ed8ca..a0b2a3dc6f 100644 --- a/server/typescript/packages/cli/src/commands/verify.ts +++ b/server/typescript/packages/cli/src/commands/verify.ts @@ -23,7 +23,6 @@ import { unindexedFkRows, warnAdvisory, referentialActionConflictRows, - unboundedListRows, advisoryHelpLines, } from "../lib/advisory.js"; import { scanForUnprovenancedLibraryPrefix } from "../lib/library-prefix-advisory.js"; @@ -33,7 +32,6 @@ import { warnIfAgentContextMissesRequirements, warnIfAgentContextStale } from ". import { warnIfManifestIgnored } from "../lib/manifest-ignored-check.js"; import { scanSourceForAntiPatterns } from "../lib/anti-patterns.js"; import { scanForMissingBaseUrl, type BaseUrlFinding } from "../lib/base-url-advisory.js"; -import { scanForUnsetPagination, type PaginationFinding } from "../lib/pagination-advisory.js"; import { scanForRemovedProps, type RemovedPropFinding } from "../lib/removed-prop-advisory.js"; import { replayRemedy } from "../lib/replay-remedy.js"; import { FileProvider, templateReferenceLine } from "../lib/file-provider.js"; @@ -1168,18 +1166,6 @@ export async function verifyCommand( // advisory only — a model the schema builder refuses is migrate's to report. } - // Generated list routes with no page size: a route generator is wired and the project - // sets no `api.pagination`. Same discipline as its siblings. - let unboundedLists: PaginationFinding[] = []; - try { - unboundedLists = scanForUnsetPagination( - (forgeConfig?.generators ?? []).map((g) => (typeof g === "string" ? g : g.name)), - collection.apiPagination, - ); - } catch { - // advisory only. - } - const unindexedFkSummary = summarizeUnindexedFks(unindexedFks); antiPatternSection = ranSection([ ...antiPatternRows(findings), @@ -1188,7 +1174,6 @@ export async function verifyCommand( ...libraryPrefixRows(libraryPrefix), ...unindexedFkRows(unindexedFkSummary === undefined ? [] : [unindexedFkSummary]), ...referentialActionConflictRows(actionConflicts), - ...unboundedListRows(unboundedLists), ]); if (findings.length > 0) { log.warn( @@ -1211,13 +1196,6 @@ export async function verifyCommand( ); warnAdvisory(removedProps.map((f) => ` ${f.message}`), flags.limit, { structured }); } - if (unboundedLists.length > 0) { - log.warn( - `meta verify — generated list routes have no page size ` + - `(advisory — does not fail the build):`, - ); - warnAdvisory(unboundedLists.map((f) => ` ${f.message}`), flags.limit, { structured }); - } if (unindexedFkSummary !== undefined) { log.warn( `meta verify — ${unindexedFks.length} foreign key(s) with no index on the referencing ` + diff --git a/server/typescript/packages/cli/src/lib/advisory.ts b/server/typescript/packages/cli/src/lib/advisory.ts index c616aeeb30..da51667589 100644 --- a/server/typescript/packages/cli/src/lib/advisory.ts +++ b/server/typescript/packages/cli/src/lib/advisory.ts @@ -115,7 +115,6 @@ export const RULE_REMOVED_PROP_PREFIX = "removed-prop:"; export const RULE_LIBRARY_PREFIX = "library-prefix-unprovenanced"; export const RULE_UNINDEXED_FK = "unindexed-foreign-key"; export const RULE_REFERENTIAL_ACTION_CONFLICT = "overridden-referential-action"; -export const RULE_UNBOUNDED_LIST = "unbounded-list-pages"; /** The next-step line for `n` rows of one advisory kind, each naming what the rows are. */ const ADVISORY_HELP: ReadonlyArray<{ matches: (rule: string) => boolean; line: (n: number) => string }> = [ @@ -129,11 +128,6 @@ const ADVISORY_HELP: ReadonlyArray<{ matches: (rule: string) => boolean; line: ( line: (n) => `${n} foreign key(s) whose two sides disagree on the referential action — see antiPatterns.rows[] (rule "${RULE_REFERENTIAL_ACTION_CONFLICT}")`, }, - { - matches: (r) => r === RULE_UNBOUNDED_LIST, - line: () => - `generated list routes with no page size — see antiPatterns.rows[] (rule "${RULE_UNBOUNDED_LIST}"), which names the api.pagination block to add`, - }, { matches: (r) => r === RULE_MISSING_BASE_URL, line: (n) => @@ -268,22 +262,6 @@ export function referentialActionConflictRows( })); } -/** - * Generated list routes with no page size, in the same row shape. `construct` is the wired - * route generator; the fix goes in the config file the row names. - */ -export function unboundedListRows( - findings: readonly { file: string; generator: string; message: string }[], -): AdvisoryFindingRow[] { - return findings.map((f) => ({ - file: f.file, - line: 0, - rule: RULE_UNBOUNDED_LIST, - construct: f.generator, - message: f.message, - })); -} - // --------------------------------------------------------------------------- // text output // --------------------------------------------------------------------------- diff --git a/server/typescript/packages/cli/src/lib/pagination-advisory.ts b/server/typescript/packages/cli/src/lib/pagination-advisory.ts deleted file mode 100644 index 700c2dd6de..0000000000 --- a/server/typescript/packages/cli/src/lib/pagination-advisory.ts +++ /dev/null @@ -1,48 +0,0 @@ -// Advisory: generated list routes with no page size. -// -// `api.pagination` in `.metaobjects/config.json` gives every generated list route a default -// page size and a hard cap on `?limit=`. A project that predates it keeps its old behaviour — -// a list with no `limit` returns the whole table, and any `limit` is accepted — because adding -// a cap on upgrade would silently truncate a client that reads a full list. So nothing turns -// it on behind the adopter's back; this names the gap instead. Advisory only: it never reaches -// an exit code. - -import { join } from "node:path"; -import { DEFAULT_METAOBJECTS_DIR } from "@metaobjectsdev/sdk"; - -/** The reference route generators whose list endpoints read `api.pagination`. */ -export const PAGINATED_ROUTE_GENERATORS: readonly string[] = [ - "routes-file", "routes-file-hono", // the factory names (`routesFile()`, `routesFileHono()`) - "routes", "routes-hono", // the stable string ids a config may name instead -]; - -export interface PaginationFinding { - /** The config file the setting goes in, relative to the project root. */ - file: string; - /** The wired generator whose list routes are unbounded. */ - generator: string; - message: string; -} - -/** - * One finding when a route generator that reads `api.pagination` is wired and the project - * declares none; otherwise none. - */ -export function scanForUnsetPagination( - generatorNames: readonly string[], - pagination: unknown, -): PaginationFinding[] { - if (pagination !== undefined) return []; - const generator = generatorNames.find((n) => PAGINATED_ROUTE_GENERATORS.includes(n)); - if (generator === undefined) return []; - const file = join(DEFAULT_METAOBJECTS_DIR, "config.json"); - return [{ - file, - generator, - message: - `${file}: ${generator} is wired and the project sets no api.pagination, so a generated ` + - `list route with no ?limit= returns the whole table and accepts any ?limit=. Add ` + - `"api": { "pagination": { "defaultLimit": 50, "maxLimit": 1000 } } to give every list ` + - `a default page size and answer a larger ?limit= with 400 limit_too_large.`, - }]; -} diff --git a/server/typescript/packages/cli/test/init.test.ts b/server/typescript/packages/cli/test/init.test.ts index d7c0d2d881..48bcc9a0a4 100644 --- a/server/typescript/packages/cli/test/init.test.ts +++ b/server/typescript/packages/cli/test/init.test.ts @@ -428,7 +428,7 @@ describe("init() --force config preservation", () => { expect(reloaded.pending_in_git).toBe(false); expect(reloaded.confidence_thresholds.pending_promote).toBe(0.95); expect(reloaded.sources).toEqual([{ package: "@acme/entities" }]); - // An existing project keeps its unbounded lists: --force must not add a page size. + // An existing project keeps its page settings: --force must not add a maximum page size. expect(reloaded.api).toBeUndefined(); }); diff --git a/server/typescript/packages/cli/test/pagination-advisory.test.ts b/server/typescript/packages/cli/test/pagination-advisory.test.ts deleted file mode 100644 index a99b625ff8..0000000000 --- a/server/typescript/packages/cli/test/pagination-advisory.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -// A generated list route with no page size returns the whole table. `meta verify` names that -// when a route generator is wired and the project declares no `api.pagination`, and stays -// silent otherwise. Advisory only. - -import { describe, test, expect } from "bun:test"; -import { scanForUnsetPagination } from "../src/lib/pagination-advisory.js"; -import { unboundedListRows, advisoryHelpLines, RULE_UNBOUNDED_LIST } from "../src/lib/advisory.js"; - -const PAGE = { defaultLimit: 50, maxLimit: 1000 }; - -describe("scanForUnsetPagination", () => { - test("routes wired, no page size: one finding naming the block to add", () => { - const [f, ...rest] = scanForUnsetPagination(["entity-file", "routes-file"], undefined); - expect(rest).toEqual([]); - expect(f!.generator).toBe("routes-file"); - expect(f!.file).toBe(".metaobjects/config.json"); - expect(f!.message).toContain('"api": { "pagination": { "defaultLimit": 50, "maxLimit": 1000 } }'); - expect(f!.message).toContain("limit_too_large"); - }); - - test("the Hono routes and the stable string ids count too", () => { - for (const name of ["routes-file-hono", "routes", "routes-hono"]) { - expect(scanForUnsetPagination([name], undefined).length).toBe(1); - } - }); - - test("silent when the project sets a page size", () => { - expect(scanForUnsetPagination(["routes-file"], PAGE)).toEqual([]); - }); - - test("silent when no route generator is wired", () => { - expect(scanForUnsetPagination(["entity-file", "queries-file"], undefined)).toEqual([]); - expect(scanForUnsetPagination([], undefined)).toEqual([]); - }); - - test("rides the advisory row shape under its own rule and help line", () => { - const rows = unboundedListRows(scanForUnsetPagination(["routes-file"], undefined)); - expect(rows.map((r) => r.rule)).toEqual([RULE_UNBOUNDED_LIST]); - expect(rows[0]!.construct).toBe("routes-file"); - expect(advisoryHelpLines(rows).join("\n")).toContain(RULE_UNBOUNDED_LIST); - }); -}); diff --git a/server/typescript/packages/codegen-ts/src/api-surface.ts b/server/typescript/packages/codegen-ts/src/api-surface.ts index d197637d18..72f11c3404 100644 --- a/server/typescript/packages/codegen-ts/src/api-surface.ts +++ b/server/typescript/packages/codegen-ts/src/api-surface.ts @@ -277,8 +277,9 @@ export function knownFieldsLine(entity: MetaObject, indent: string, root?: MetaD /** * The `pagination` option of a list mount: the project's page size (`api.pagination` in * `.metaobjects/config.json`), or nothing when the project declares none, which keeps the output - * byte-identical and the route unbounded, as before. `root` is the loaded root the setting is - * read from (`ctx.loadedRoot`); without one the object's own root answers. + * byte-identical; the mount then answers 50 rows when `limit` is absent and has no ceiling + * (`DEFAULT_PAGE_LIMIT`). `root` is the loaded root the setting is read from (`ctx.loadedRoot`); + * without one the object's own root answers. */ export function paginationLine(entity: MetaObject, indent: string, root?: MetaData): string { const page = apiPaginationOf(root ?? entity); diff --git a/server/typescript/packages/codegen-ts/src/contract/build-openapi.ts b/server/typescript/packages/codegen-ts/src/contract/build-openapi.ts index 8bf8ab8e15..3d44b97b64 100644 --- a/server/typescript/packages/codegen-ts/src/contract/build-openapi.ts +++ b/server/typescript/packages/codegen-ts/src/contract/build-openapi.ts @@ -16,6 +16,7 @@ import { flatSurfaceFields } from "../flattened.js"; import { type ApiPagination, + DEFAULT_PAGE_LIMIT, apiPaginationOf, apiUnknownFieldsOf, type MetaField, @@ -207,22 +208,28 @@ function sortParameter(obj: MetaObject, excludeField: string | undefined, root: /** * The page parameters. A project that sets `api.pagination` serves `defaultLimit` rows when `limit` - * is absent and refuses a `limit` above `maxLimit`, so the document says both. A report keeps its - * own row cap (a generator option the model does not hold), so it states neither. + * is absent and refuses a `limit` above `maxLimit`, so the document says both; one that sets none + * serves `DEFAULT_PAGE_LIMIT` (50) and has no maximum. A report keeps its own row cap (a generator + * option the model does not hold), so it states neither. */ -function pageParameters(minLimit: number, page: ApiPagination | undefined): JsonSchema[] { +function pageParameters(minLimit: number, page: ApiPagination | undefined, report: boolean): JsonSchema[] { + const defaultLimit = page?.defaultLimit ?? DEFAULT_PAGE_LIMIT; const limit: JsonSchema = { type: "integer", minimum: minLimit, - ...(page !== undefined && { maximum: page.maxLimit, default: page.defaultLimit }), + ...(!report && page !== undefined && { maximum: page.maxLimit }), + ...(!report && { default: defaultLimit }), }; + const description = report + ? undefined + : page !== undefined + ? `Rows per page. Absent, the server answers ${page.defaultLimit}; above ${page.maxLimit} it answers 400 limit_too_large.` + : `Rows per page. Absent, the server answers ${defaultLimit}.`; return [ { name: "limit", in: "query", - ...(page !== undefined && { - description: `Rows per page. Absent, the server answers ${page.defaultLimit}; above ${page.maxLimit} it answers 400 limit_too_large.`, - }), + ...(description !== undefined && { description }), schema: limit, }, { name: "offset", in: "query", schema: { type: "integer", minimum: 0 } }, @@ -291,7 +298,7 @@ function listOperation(r: ResourceOps): JsonSchema { ...filterParameters(filterable), ...listQueryParameters(filterable), ...sortParameter(row, r.excludeField, r.root), - ...pageParameters(r.report ? 1 : 0, r.report ? undefined : apiPaginationOf(r.root)), + ...pageParameters(r.report ? 1 : 0, r.report ? undefined : apiPaginationOf(r.root), r.report), ...(r.reportExport ? [{ name: "format", in: "query", schema: { type: "string", enum: ["csv", "json", "xml"] } }] : []), ]; r.refs.listed.add(row); diff --git a/server/typescript/packages/codegen-ts/test/contract/contract-behaviours.test.ts b/server/typescript/packages/codegen-ts/test/contract/contract-behaviours.test.ts index dfb9de9c91..12f9dc26a5 100644 --- a/server/typescript/packages/codegen-ts/test/contract/contract-behaviours.test.ts +++ b/server/typescript/packages/codegen-ts/test/contract/contract-behaviours.test.ts @@ -398,10 +398,10 @@ describe("the document states what the routes do beyond the happy path", () => { (((doc["paths"] as JsonDoc)[path] as JsonDoc)[method]) as Operation; const document = async (name: string): Promise => jsonAt(await emit(corpusCase(name), [openApiFile({ title: "t", version: "1" })]), "openapi.json"); - test("a project's page size is the limit's default and maximum, and absent it states neither", async () => { + test("a project's page size is the limit's default and maximum, and absent it the default is 50 with no maximum", async () => { const limitOf = (doc: JsonDoc) => operation(doc, "/api/authors", "get").parameters?.find((p) => p.name === "limit")?.schema; expect(limitOf(await document("api-settings"))).toEqual({ type: "integer", minimum: 0, maximum: 1000, default: 50 }); - expect(limitOf(await document("blog"))).toEqual({ type: "integer", minimum: 0 }); + expect(limitOf(await document("blog"))).toEqual({ type: "integer", minimum: 0, default: 50 }); }); test("a write says an undeclared key is refused by default, and dropped under api.unknownFields: drop", async () => { diff --git a/server/typescript/packages/metadata/src/api-pagination.ts b/server/typescript/packages/metadata/src/api-pagination.ts index 2e94b6a264..35dc7d66fb 100644 --- a/server/typescript/packages/metadata/src/api-pagination.ts +++ b/server/typescript/packages/metadata/src/api-pagination.ts @@ -1,6 +1,7 @@ // The page size of a generated list route: `api.pagination` in .metaobjects/config.json, // carried on the loaded root beside the naming rules and read through `apiPaginationOf`. -// A project without the block has none, and its routes behave as they always have. +// A project without the block still pages: a list with no `limit` answers DEFAULT_PAGE_LIMIT rows, +// the same default in every port, and no maximum is enforced. import type { MetaData } from "./shared/meta-data.js"; @@ -10,8 +11,14 @@ export const API_KEY_PAGINATION = "pagination"; export const PAGINATION_KEY_DEFAULT_LIMIT = "defaultLimit"; export const PAGINATION_KEY_MAX_LIMIT = "maxLimit"; +/** + * The rows a list with no `limit` answers when the project sets no `api.pagination`: the same 50 + * in every port. Without the block there is no maximum, so an explicit `limit` is served as asked. + */ +export const DEFAULT_PAGE_LIMIT = 50; + /** What `meta init` writes for a new project. */ -export const INIT_DEFAULT_LIMIT = 50; +export const INIT_DEFAULT_LIMIT = DEFAULT_PAGE_LIMIT; export const INIT_MAX_LIMIT = 1000; /** diff --git a/server/typescript/packages/metadata/src/index.ts b/server/typescript/packages/metadata/src/index.ts index 1a3675230f..8168027aee 100644 --- a/server/typescript/packages/metadata/src/index.ts +++ b/server/typescript/packages/metadata/src/index.ts @@ -458,7 +458,7 @@ export { resolveEnumMaxLength, enumDefaultsOf, DEFAULT_ENUM_DEFAULTS, ENUMS_KEY_ export type { EnumDefaults } from "./enum-length.js"; export { apiPaginationOf, API_KEY_PAGINATION, PAGINATION_KEY_DEFAULT_LIMIT, PAGINATION_KEY_MAX_LIMIT, - INIT_DEFAULT_LIMIT, INIT_MAX_LIMIT, + DEFAULT_PAGE_LIMIT, INIT_DEFAULT_LIMIT, INIT_MAX_LIMIT, apiUnknownFieldsOf, API_KEY_UNKNOWN_FIELDS, UNKNOWN_FIELDS_REJECT, UNKNOWN_FIELDS_DROP, UNKNOWN_FIELDS_MODES, DEFAULT_UNKNOWN_FIELDS, ERROR_UNKNOWN_FIELDS, } from "./api-pagination.js"; diff --git a/server/typescript/packages/runtime-ts/src/drizzle-fastify/index.ts b/server/typescript/packages/runtime-ts/src/drizzle-fastify/index.ts index 225721b86a..a25a004dfc 100644 --- a/server/typescript/packages/runtime-ts/src/drizzle-fastify/index.ts +++ b/server/typescript/packages/runtime-ts/src/drizzle-fastify/index.ts @@ -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; } @@ -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 @@ -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); } diff --git a/server/typescript/packages/runtime-ts/src/drizzle-fastify/list-params.ts b/server/typescript/packages/runtime-ts/src/drizzle-fastify/list-params.ts index 1a1bdc3412..927687abc5 100644 --- a/server/typescript/packages/runtime-ts/src/drizzle-fastify/list-params.ts +++ b/server/typescript/packages/runtime-ts/src/drizzle-fastify/list-params.ts @@ -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) { super(message); @@ -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( diff --git a/server/typescript/packages/runtime-ts/src/drizzle-fastify/mount-read-only.ts b/server/typescript/packages/runtime-ts/src/drizzle-fastify/mount-read-only.ts index c06f5fdaec..cec28d7fa5 100644 --- a/server/typescript/packages/runtime-ts/src/drizzle-fastify/mount-read-only.ts +++ b/server/typescript/packages/runtime-ts/src/drizzle-fastify/mount-read-only.ts @@ -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; /** diff --git a/server/typescript/packages/runtime-ts/src/fastify/index.ts b/server/typescript/packages/runtime-ts/src/fastify/index.ts index 1ca92c64b9..20128d9639 100644 --- a/server/typescript/packages/runtime-ts/src/fastify/index.ts +++ b/server/typescript/packages/runtime-ts/src/fastify/index.ts @@ -91,7 +91,7 @@ export interface CrudRoutesOptions { /** * 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; } @@ -143,7 +143,7 @@ export function mountListRoute(opts: SingleVerbOptions): void { const om = await opts.om(); let query: ListQuery; - let limit: number | undefined; + let limit: number; try { query = opts.filterAllowlist !== undefined ? parseListQuery({ @@ -160,7 +160,7 @@ export function mountListRoute(opts: SingleVerbOptions): void { } const readOpts: { limit?: number; offset?: number; orderBy?: [string, "asc" | "desc"] | [string, "asc" | "desc"][] } = {}; - if (limit !== undefined) readOpts.limit = limit; + readOpts.limit = limit; if (query.offset !== undefined) readOpts.offset = query.offset; // No `?sort`: the key, ascending, so a page holds the same rows on every engine, as the // Drizzle mounts order by `id`. diff --git a/server/typescript/packages/runtime-ts/src/hono/index.ts b/server/typescript/packages/runtime-ts/src/hono/index.ts index 77bb958ea7..4654067406 100644 --- a/server/typescript/packages/runtime-ts/src/hono/index.ts +++ b/server/typescript/packages/runtime-ts/src/hono/index.ts @@ -132,7 +132,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; } @@ -233,13 +233,13 @@ export function mountListRoute(opts: VerbOptions): void { if (combinedWhere) { q = q.where(combinedWhere); where = combinedWhere; } if (parsed.orderBy) q = q.orderBy(...parsed.orderBy); 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 { // No allowlists configured. Only limit/offset. const limit = pageLimit(parsePageBound(qsParsed, "limit"), opts.pagination); const offset = parsePageBound(qsParsed, "offset"); - if (limit !== undefined) q = q.limit(limit); + q = q.limit(limit); if (offset !== undefined) q = q.offset(offset); } diff --git a/server/typescript/packages/runtime-ts/src/hono/mount-read-only.ts b/server/typescript/packages/runtime-ts/src/hono/mount-read-only.ts index 527e462c1f..730c90bdf1 100644 --- a/server/typescript/packages/runtime-ts/src/hono/mount-read-only.ts +++ b/server/typescript/packages/runtime-ts/src/hono/mount-read-only.ts @@ -64,7 +64,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; /** Report export, as on the Fastify mount: `?format=csv|json|xml`, capped by `export.maxRows`. */ diff --git a/server/typescript/packages/runtime-ts/test/list-page-size.test.ts b/server/typescript/packages/runtime-ts/test/list-page-size.test.ts index 26bb2820ef..b1900d3dc5 100644 --- a/server/typescript/packages/runtime-ts/test/list-page-size.test.ts +++ b/server/typescript/packages/runtime-ts/test/list-page-size.test.ts @@ -15,6 +15,7 @@ import { pageLimit, ERROR_CODE_LIMIT_TOO_LARGE, } from "../src/drizzle-fastify/index.js"; +import { DEFAULT_PAGE_LIMIT } from "@metaobjectsdev/metadata"; import { FilterParseError } from "../src/drizzle-fastify/filter-parser.js"; import { mountCrudRoutes as mountHonoCrud } from "../src/hono/index.js"; @@ -29,13 +30,14 @@ function itemsTable() { async function seeded(): Promise { const client = createClient({ url: ":memory:" }); await client.execute(`CREATE TABLE items (id INTEGER PRIMARY KEY, title TEXT NOT NULL)`); - for (let i = 1; i <= 5; i++) await client.execute(`INSERT INTO items (id, title) VALUES (${i}, 'item ${i}')`); + for (let i = 1; i <= 55; i++) await client.execute(`INSERT INTO items (id, title) VALUES (${i}, 'item ${i}')`); return client; } describe("pageLimit", () => { - test("no page size: the request's limit, or none", () => { - expect(pageLimit(undefined, undefined)).toBeUndefined(); + test("no page size: the request's limit, or the default page of 50", () => { + expect(pageLimit(undefined, undefined)).toBe(DEFAULT_PAGE_LIMIT); + expect(DEFAULT_PAGE_LIMIT).toBe(50); expect(pageLimit(100000, undefined)).toBe(100000); }); test("no limit: the default page size", () => { @@ -77,14 +79,14 @@ function listBehaviour(name: string, setup: (pagination: typeof PAGE | undefined expect(r.body).toEqual({ error: "limit_too_large", maxLimit: 4 }); }); test("offset pages past the default", async () => { - const r = await h.get("/items?offset=4"); - expect((r.body as Array<{ id: number }>).map((x) => x.id)).toEqual([5]); + const r = await h.get("/items?offset=54"); + expect((r.body as Array<{ id: number }>).map((x) => x.id)).toEqual([55]); }); test("withCount reports the full total with the default page", async () => { const r = await h.get("/items?withCount=1"); const body = r.body as { rows: unknown[]; total: number }; expect(body.rows.length).toBe(2); - expect(body.total).toBe(5); + expect(body.total).toBe(55); }); }); @@ -93,13 +95,13 @@ function listBehaviour(name: string, setup: (pagination: typeof PAGE | undefined beforeAll(async () => { h = await setup(undefined); }); afterAll(async () => { await h.close(); }); - test("no ?limit= answers every row, as before", async () => { - expect(((await h.get("/items")).body as unknown[]).length).toBe(5); + test("no ?limit= answers the default page of 50, not the whole table", async () => { + expect(((await h.get("/items")).body as unknown[]).length).toBe(50); }); - test("a large ?limit= is accepted, as before", async () => { + test("a large ?limit= is accepted: there is no maximum without the setting", async () => { const r = await h.get("/items?limit=100000"); expect(r.status).toBe(200); - expect((r.body as unknown[]).length).toBe(5); + expect((r.body as unknown[]).length).toBe(55); }); }); } From 5fe9fc7835dd1cea24a0428adf7849402a8c9a3f Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Sun, 22 Nov 2026 02:12:13 -0500 Subject: [PATCH 2/4] no-mistakes(review): test default page of 50 on read-only and OM mounts --- .../drizzle-fastify/mount-read-only.test.ts | 43 +++++++++++++++++++ .../test/fastify/mount-list-parity.test.ts | 32 ++++++++++++++ .../test/hono/mount-read-only.test.ts | 41 ++++++++++++++++++ 3 files changed, 116 insertions(+) diff --git a/server/typescript/packages/runtime-ts/test/drizzle-fastify/mount-read-only.test.ts b/server/typescript/packages/runtime-ts/test/drizzle-fastify/mount-read-only.test.ts index db40fd8c80..2e3716c516 100644 --- a/server/typescript/packages/runtime-ts/test/drizzle-fastify/mount-read-only.test.ts +++ b/server/typescript/packages/runtime-ts/test/drizzle-fastify/mount-read-only.test.ts @@ -415,3 +415,46 @@ describe("mountReadOnlyCrudRoutes — report row cap", () => { } } }); + +describe("mountReadOnlyCrudRoutes — default page without api.pagination", () => { + let fastify: FastifyInstance; + let client: ReturnType; + + beforeAll(async () => { + client = createClient({ url: ":memory:" }); + await client.execute(`CREATE TABLE sales (id INTEGER PRIMARY KEY, amount INTEGER NOT NULL)`); + await client.execute(`CREATE VIEW v_totals AS SELECT id, amount FROM sales`); + for (let i = 1; i <= 55; i++) await client.execute(`INSERT INTO sales (id, amount) VALUES (${i}, ${i * 10})`); + fastify = Fastify(); + mountReadOnlyCrudRoutes({ + fastify, + path: "/totals", + db: drizzle(client), + view: sqliteView("v_totals", { + id: integer("id").notNull(), + amount: integer("amount").notNull(), + }).existing(), + filterAllowlist: {}, + sortAllowlist: { id: { defaultOrder: "asc" } }, + dialect: "sqlite", + }); + await fastify.ready(); + }); + + afterAll(async () => { + await fastify.close(); + client.close(); + }); + + test("no ?limit= answers 50 rows, not the whole view", async () => { + const res = await fastify.inject({ method: "GET", url: "/totals" }); + expect(res.statusCode).toBe(200); + expect(JSON.parse(res.body)).toHaveLength(50); + }); + + test("a large ?limit= answers every row: no maximum without the setting", async () => { + const res = await fastify.inject({ method: "GET", url: "/totals?limit=100000" }); + expect(res.statusCode).toBe(200); + expect(JSON.parse(res.body)).toHaveLength(55); + }); +}); diff --git a/server/typescript/packages/runtime-ts/test/fastify/mount-list-parity.test.ts b/server/typescript/packages/runtime-ts/test/fastify/mount-list-parity.test.ts index af7bd55b50..5d9f4f7eac 100644 --- a/server/typescript/packages/runtime-ts/test/fastify/mount-list-parity.test.ts +++ b/server/typescript/packages/runtime-ts/test/fastify/mount-list-parity.test.ts @@ -178,3 +178,35 @@ for (const d of DRIVERS) { }); }); } + +describe("ObjectManager Fastify list mount — default page without api.pagination", () => { + let app: FastifyInstance; + + beforeAll(async () => { + const rows: Row[] = Array.from({ length: 55 }, (_, i) => ({ id: i + 1, name: `part ${i + 1}`, category: "tool", stock: 1, notes: null })); + const driver = inMemoryDriver({ seed: { parts: rows }, pkFields: { parts: ["id"] } }); + const om = new ObjectManager({ metadata: await load(), driver }); + app = Fastify(); + mountCrudRoutes({ + fastify: app, path: "/parts", entity: "Part", insertSchema: z.object({}), updateSchema: z.object({}), + om: async () => om, expose: ["list"] as const, + }); + await app.ready(); + }); + + afterAll(async () => { + await app.close(); + }); + + test("no ?limit= answers 50 rows, not the whole table", async () => { + const res = await app.inject({ method: "GET", url: "/parts" }); + expect(res.statusCode).toBe(200); + expect(res.json()).toHaveLength(50); + }); + + test("a large ?limit= answers every row: no maximum without the setting", async () => { + const res = await app.inject({ method: "GET", url: "/parts?limit=100000" }); + expect(res.statusCode).toBe(200); + expect(res.json()).toHaveLength(55); + }); +}); diff --git a/server/typescript/packages/runtime-ts/test/hono/mount-read-only.test.ts b/server/typescript/packages/runtime-ts/test/hono/mount-read-only.test.ts index 73ba8295e5..81a63b1b3f 100644 --- a/server/typescript/packages/runtime-ts/test/hono/mount-read-only.test.ts +++ b/server/typescript/packages/runtime-ts/test/hono/mount-read-only.test.ts @@ -118,3 +118,44 @@ describe("hono mountReadOnlyCrudRoutes — GET :id addresses idColumn", () => { } }); }); + +describe("hono mountReadOnlyCrudRoutes — default page without api.pagination", () => { + let client: ReturnType; + let app: Hono; + + beforeAll(async () => { + client = createClient({ url: ":memory:" }); + await client.execute(`CREATE TABLE sales (id INTEGER PRIMARY KEY, amount INTEGER NOT NULL)`); + await client.execute(`CREATE VIEW v_totals AS SELECT id, amount FROM sales`); + for (let i = 1; i <= 55; i++) await client.execute(`INSERT INTO sales (id, amount) VALUES (${i}, ${i * 10})`); + app = new Hono(); + mountReadOnlyCrudRoutes({ + app, + path: "/totals", + db: drizzle(client), + view: sqliteView("v_totals", { + id: integer("id").notNull(), + amount: integer("amount").notNull(), + }).existing(), + filterAllowlist: {}, + sortAllowlist: { id: { defaultOrder: "asc" } }, + dialect: "sqlite", + }); + }); + + afterAll(() => { + client.close(); + }); + + test("no ?limit= answers 50 rows, not the whole view", async () => { + const res = await app.request("/totals"); + expect(res.status).toBe(200); + expect(await res.json()).toHaveLength(50); + }); + + test("a large ?limit= answers every row: no maximum without the setting", async () => { + const res = await app.request("/totals?limit=100000"); + expect(res.status).toBe(200); + expect(await res.json()).toHaveLength(55); + }); +}); From 81a011e6fd97cbb45be01f4a6057d1de487ff7eb Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Sun, 22 Nov 2026 02:13:17 -0500 Subject: [PATCH 3/4] no-mistakes(review): apply reviewer inline fixes --- docs/features/migrations/default-list-page-of-fifty.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/features/migrations/default-list-page-of-fifty.md b/docs/features/migrations/default-list-page-of-fifty.md index 1b91299afb..8f0eab05a5 100644 --- a/docs/features/migrations/default-list-page-of-fifty.md +++ b/docs/features/migrations/default-list-page-of-fifty.md @@ -19,8 +19,8 @@ shipped) sees no change: its `defaultLimit` and `maxLimit` apply as before. The generated TanStack list hooks are not affected: the grid hook always sends a `limit`. -**An owned runtime copy** (`meta eject runtime`) keeps the behaviour of the copy you took. Take a -fresh copy with `meta eject runtime --force` to get the default, or change `pageLimit` in your +**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: From 2caef5fd1ff04ff20ad7629209059e9530237fbf Mon Sep 17 00:00:00 2001 From: Doug Mealing Date: Sun, 22 Nov 2026 02:22:36 -0500 Subject: [PATCH 4/4] no-mistakes(document): docs: default list page of 50 in OpenAPI docs --- docs/features/contract-emitters.md | 5 +++-- .../packages/integration-tests/src/load-metadata.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/features/contract-emitters.md b/docs/features/contract-emitters.md index 7bffe8f5f1..f3ef7f8a61 100644 --- a/docs/features/contract-emitters.md +++ b/docs/features/contract-emitters.md @@ -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 diff --git a/server/typescript/packages/integration-tests/src/load-metadata.ts b/server/typescript/packages/integration-tests/src/load-metadata.ts index 620a310b32..d321f8d610 100644 --- a/server/typescript/packages/integration-tests/src/load-metadata.ts +++ b/server/typescript/packages/integration-tests/src/load-metadata.ts @@ -24,7 +24,7 @@ export function applyNearestNaming(root: MetaRoot, startDir: string): MetaRoot { // `enums.maxLength` sizes an enum column, so a corpus that sets it gets the schema it pins. root.enumDefaults = enumDefaultsFromConfig(config); // `api.pagination` gives generated list routes a page size; a corpus without it keeps the - // unbounded lists every other corpus is written against. + // default page of 50 with no maximum that every other corpus is written against. const page = apiPaginationFromConfig(config); if (page !== undefined) root.apiPagination = page; const unknownFields = apiUnknownFieldsFromConfig(config);