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
2 changes: 1 addition & 1 deletion .claude/rules/cross-language-porting.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Preserve the following contracts exactly across all language ports:
- Relationship subtypes: `association`, `aggregation`, `composition`. Cardinality via `@cardinality: one|many`; target via `@objectRef`. **M:N (FR-018) slim vocabulary:** `@cardinality: "many"` + `@objectRef` (target) + `@through` (the junction/through entity — a third entity that MUST declare two `identity.reference` children, one per FK side). The relationship's FK fields are **derived** from those references (the `identity.reference` SSOT for FK direction), never restated. `@sourceRefField` (optional) disambiguates a *directed* self-join by naming the source-side FK field on the junction (the other reference is the target side); on a `@cardinality: one` relationship it instead names which of several `identity.reference` nodes onto the same target this relationship navigates, short-circuiting the unique-candidate/`@sourceRefField`/name-pairing ladder (#368, [ADR-0029](spec/decisions/ADR-0029-entity-child-extends-and-via-inference.md) Amendment 1) — an unresolvable 1:N reference set is `ERR_INVALID_RELATIONSHIP` at load. `@symmetric` (optional boolean) marks an *undirected* self-join (union-on-read) — valid only when `@objectRef` == the declaring entity, and mutually exclusive with `@sourceRefField`. The pre-FR-018 `@joinEntity`/`@joinFields` attrs are REMOVED. Validation errors: symmetric-on-hetero / symmetric+sourceRefField → `ERR_BAD_ATTR_VALUE`; junction-missing-two-references / sourceRefField-not-matching / M:N-attr-on-1:N / **junction-unpairable** → `ERR_INVALID_RELATIONSHIP`. **Unpairable means the junction declares its two references but neither resolves to the navigating entity, or neither to the `@objectRef` target** — declaring two references is NOT enough, and the loader now checks WHAT they point at (owner ruling 2026-09-20). It does so by running the real FK derivation and converting its failure, never a parallel re-implementation, so the loader and the derivation cannot drift; scope mirrors codegen's own iteration exactly — every CONCRETE, non-projection object crossed with its EFFECTIVE relationships, NOT deduped by declaration, because pairing is a property of the navigating entity and an inherited M:N can pair from one subtype and not another. Before the ruling this loaded clean and then diverged: TS and C# warned and emitted no traversal route (a silent 404), while Java, Kotlin and Python failed the build. Gated by `fixtures/conformance/error-relationship-m2m-junction-unpairable/`.
- Index subtypes: `index.lookup` (non-unique retrieval index; uniqueness is encoded in the **type**: `identity.secondary` = unique alternate key, `index.lookup` = non-unique; `@unique` is REMOVED from `identity.secondary` — `ERR_UNKNOWN_ATTR` on any legacy `@unique`). RDB-physical escapes `@using`/`@expr`/`@where`/`@orders` are registered by the db provider on **both** `identity.secondary` and `index.lookup`. `index.fulltext` / `index.vector` / `index.spatial` are reserved on the subtype axis — documented, NOT registered (YAGNI + 1.0 vocab freeze). See [ADR-0040](spec/decisions/ADR-0040-index-type-and-secondary-key-purity.md).
- Layout subtypes: `dataGrid`
- API subtypes: `api.base` / `api.operational` (request/response surface, a root child; subtype axis = interaction model, NEVER protocol — protocol lives in `binding.*` per operation: `binding.rest` (`@method`, `@path`) now, `messaging`/`grpc` reserved; the event/streaming sibling of `api.operational` is reserved). Children: `operation.query` (`@outputRef`, `@many`) / `operation.command` (`@inputRef` → `object.value`, `@transitions`, `@errors`); both take `@inputRef`, `@outputRef`, `@objectRef` (only when the target cannot be derived), `@permission`, `@public`. Derived CRUD (FR-008/009) stays the zero-config default; declared `api` extends it. Org-tier modeling (application/service/network/deployment) stays OUT of core — provider SPI, FQN references. See [ADR-0030](spec/decisions/ADR-0030-declared-api-surface-and-org-tier-boundary.md). **Registered in all five ports since 1.3.0, experimental** (may change in a MINOR) ([ADR-0066](spec/decisions/ADR-0066-business-rules-operations-and-lifecycles.md)), with the loader rules (`error-rules-*` fixtures) and the `verify` rules gate (`fixtures/rules-check-conformance/`); the flat generators generate nothing from it (`fixtures/codegen-noop/rules/`); the ADR-0067 layer generators do (`rules-names` and `contract-types` in TypeScript and C#, and the TypeScript `service` and `service-routes` for derived CRUD so far).
- API subtypes: `api.base` / `api.operational` (request/response surface, a root child; subtype axis = interaction model, NEVER protocol — protocol lives in `binding.*` per operation: `binding.rest` (`@method`, `@path`) now, `messaging`/`grpc` reserved; the event/streaming sibling of `api.operational` is reserved). Children: `operation.query` (`@outputRef`, `@many`) / `operation.command` (`@inputRef` → `object.value`, `@transitions`, `@errors`); both take `@inputRef`, `@outputRef`, `@objectRef` (only when the target cannot be derived), `@permission`, `@public`. Derived CRUD (FR-008/009) stays the zero-config default; declared `api` extends it. Org-tier modeling (application/service/network/deployment) stays OUT of core — provider SPI, FQN references. See [ADR-0030](spec/decisions/ADR-0030-declared-api-surface-and-org-tier-boundary.md). **Registered in all five ports since 1.3.0, experimental** (may change in a MINOR) ([ADR-0066](spec/decisions/ADR-0066-business-rules-operations-and-lifecycles.md)), with the loader rules (`error-rules-*` fixtures) and the `verify` rules gate (`fixtures/rules-check-conformance/`); the flat generators generate nothing from it (`fixtures/codegen-noop/rules/`); the ADR-0067 layer generators do (`rules-names` and `contract-types` in TypeScript and C#; the TypeScript `service` and `service-routes` for derived CRUD, transitions, declared operations and the rules' checks).
- Transition subtypes: `transition.action` (a child of `field.enum` on an `object.entity`: `@from`, `@to`, `@condition` in the validators' grammar, `@permission`, `@public`); `transition.base` is the abstract root and `transition.timed` is reserved, not registered. An enum with a transition IS a lifecycle — states, initial state (`@default`), terminal states and each unclaimed transition's command are derived, never declared (ADR-0066). A transition's `@from` lists enum members, not object references: every port's ref-bearing-attr check excludes `transition.*` nodes. A lifecycle belongs to the declaring entity and its `extends` descendants, NEVER to an entity whose field merely `extends` the lifecycle field (filter by the declaring field's owner); a command claims a transition NODE for its target and every entity extending it. Transition and operation names compare case-insensitively; operation names are unique per PACKAGE across its APIs, except one operation declared identically in two APIs (a versioned API). A lifecycle on an entity with no source loads and is inert (no derived command, no permission checks); the writable-source check applies once a source exists. A `@permission` is a dotted identifier path (a package prefix may use `::`); an absent one derives `<package>.<operation>` for an operation and `<package>.<Entity>.<transition>` for a transition's command.
- Currency attrs: `@currency` (ISO 4217), `@locale` (BCP 47)
- Schema attrs: `@schema` on `source.rdb` (DB schema name; Postgres default `public`, SQLite rejects non-default values)
Expand Down
47 changes: 40 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,38 @@ here.**

## [Unreleased]

- **codegen-ts: the service layer, part 2 — the rules run (ADR-0066 §6, ADR-0067 §4 and §7).** The
`service` generator now writes a command per transition that derives one (`POST
<collection>/{id}/<transition>`) and a shell per declared command and query, at its binding or
derived path, and enforces ADR-0066's checks in order, in one transaction: the row (404), the
permission point (403 `forbidden`), the state (409 `invalid_transition`), the hand-written body,
the guarded update (409 `invalid_transition` or `transition_condition_failed`) and the event hook.
The generic update answers a changed lifecycle field 409 `state_managed`. What an app writes is
passed to `create<Pkg>Service(deps)` through generated interfaces: `<Pkg>Policy`, `<Pkg>Bodies`
(a command returns the move to make or `"none"`, and `ctx.refuse` answers a declared error),
optional `<Pkg>Hooks` on the derived writes and `<Pkg>Events` told about every write. Any of
them may refuse, which rolls the write back. The actor is an app-defined type parameter, passed
as `opts.actor` and resolved by the Fastify transport's `getActor(request)`. Three settings now
act on the generated side: `rules.lifecycle.create` (`initial` fills an omitted state and refuses
another; `any` accepts any), `rules.lifecycle.commands` (which transitions get a command) and
`rules.permissions.names: require` (generation refuses a point with no `@permission`, naming the
derived one). A transport refuses two routes on one method and path. New shared API tests,
`fixtures/api-contract-conformance/rules/`, cover 403, the three 409 codes, a declared error, a
derived command, a declared command and query, a public operation and a hook's and the event
hook's refusal rolling back, with three settings variants; the TypeScript lane runs them in both
layouts, and the service compile gate builds the model in every dialect. `ServiceDeps`, the
service interface and the factory take the actor type `A` (default `unknown`), so existing calls
compile unchanged. `@metaobjectsdev/runtime-ts/service` gains the helpers they call
(`checkPermission`, `checkState`, `makeTransition`, `checkStateManaged`, `checkCreateState`,
`emitWrite`, `handlerContext`) and their types.
- **The install-size budget rises to 51.7 MB, by ruling.** Installing `@metaobjectsdev/cli` now
measures 51.5 MB against a 51.0 MB budget. The growth since #622 (the service generator and the
1.3.0 codegen and runtime work) was measured late because hosted CI does not run `ts-slow`.
Declaration maps stay, so go-to-definition still reaches the shipped source.
`scripts/check-install-size.mjs` now accepts a raise only when the newest `history` entry in
`scripts/install-size-budget.json` records it with its reason and ruling. It also reads
`origin/main` when a checkout has no local `main`; before this, such a checkout skipped the
never-rises rule entirely.
- **codegen-ts: the service layer, part 1 (ADR-0067 layers 4 and 5).** Two new generators, neither
scaffolded. `service` (the new `service` layer label, shared by every port's catalog) writes one
module per metadata package: a function per derived list, get, create, update and delete of each
Expand All @@ -20,8 +52,8 @@ here.**
shared corpus against the service behind its transport, in both layouts, and passes as the flat
routes do; a compile gate builds the tier in every dialect. `@metaobjectsdev/runtime-ts` gains
the `./service` and `./service/fastify` entries they import, and `meta eject` copies them.
Write-through, TPH, many-to-many, projections, reports, transitions and declared operations stay
on the flat generators for now: [docs/features/business-rules.md](docs/features/business-rules.md#the-service-layer-typescript).
Write-through, TPH, many-to-many, projections and reports stay on the flat generators for now:
[docs/features/business-rules.md](docs/features/business-rules.md#the-service-layer-typescript).
- **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
Expand Down Expand Up @@ -730,18 +762,19 @@ Each item below is described in full under Security, Added, Changed or Fixed; th
`fixtures/rules-check-conformance/` corpus.
- New settings in `.metaobjects/config.json`: `rules.permissions.names`,
`rules.lifecycle.commands`, `rules.lifecycle.create` and `verify.lifecycle.unreachable`.
Absent, each behaves as before. `rules.lifecycle.create` is read and validated and has no
effect yet: the service shells that act on it are later work.
Absent, each behaves as before. The service generators act on `rules.lifecycle.create` and
`rules.lifecycle.commands` (TypeScript's first, see [Unreleased]).
- A requirement's `@implementedBy` may name an operation (`Purchasing.decide`) or a
transition (`PurchaseRequest.status.submit`).
- The Rust port (ADR-0065) registers the same vocabulary and runs the same loader
rules with the same messages, so it still passes `registry-conformance` byte for byte and
the whole metamodel corpus (574 of 574, ledger empty). It reads and validates the new
settings. It has no `verify`, so the rules gate does not run there.

Nothing is generated from the vocabulary yet: the enforcing service shells are later work
(ADR-0067: service generators an app chooses like any other, not a named set), and
`fixtures/codegen-noop/rules/` holds every generator to byte-identical output.
The flat generators generate nothing from the vocabulary: the enforcing shells are the service
generators (ADR-0067: generators an app chooses like any other, not a named set; TypeScript's
first, see [Unreleased]), and `fixtures/codegen-noop/rules/` holds every flat generator to
byte-identical output.
A model that declares none of it sees no change. See `docs/features/business-rules.md`.
ADR-0067 records the layering and service-seam design (a layer is a generator an app chooses; the
actor is a type the app defines), and amends ADR-0045.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,12 @@ to nothing, and does not check that each claimed node complies).
`naming` block of `.metaobjects/config.json` (column and table rules, read by every port)
and per-target output dirs: hunt these values hard-coded in multiple places instead of
resolved from config.
- **CALIBRATION — registered, nothing generated yet:** the declared-API surface
- **CALIBRATION — registered; generated by TypeScript only:** the declared-API surface
(`api.operational`, `operation.query`, `operation.command`, `binding.rest`) and lifecycles
(`transition.action` under a `field.enum`) are registered since 1.3.0 (ADR-0066), checked at
load and by `verify`, but no generator emits from them yet. Their absence is not an adopter
defect; do NOT audit for them. MCP exposure of declared prompts/tools is planned and not in
load and by `verify`. TypeScript's service generator emits from them (transition commands,
declared command and query shells, permission points); the other ports do not yet. Their
absence in a non-TypeScript port is not an adopter defect; do NOT audit for them. MCP exposure of declared prompts/tools is planned and not in
the registry.
- **CALIBRATION — cross-port version skew is by design:** TS/C#/Python on the `0.x` line vs
Java/Kotlin on the `7.x` Maven line is correct — **never flag it.** Flag only *intra-port*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
- **C#** has no ObjectManager runtime tier (EF Core is the runtime) — hand services over the generated `DbContext` are expected.
- **Cut subtypes** — `field.byte` / `field.short` / `field.class` are removed; never recommend them.
- **TS/web-only** — `view.*` widget subtypes load in every port but are consumed only by TS/web; only `view.base` / `view.currency` are cross-port-gated.
- **CALIBRATION — registered, nothing generated yet** — the declared-API surface (`api.operational`, `operation.query`, `operation.command`, `binding.rest`) and lifecycles (`transition.action` under a `field.enum`) are registered since 1.3.0 (ADR-0066), checked at load and by `verify`, but no generator emits from them yet. Their absence is not an adopter defect; do NOT audit for them. MCP exposure of declared prompts/tools is planned and not in the registry.
- **CALIBRATION — registered; generated by TypeScript only** — the declared-API surface (`api.operational`, `operation.query`, `operation.command`, `binding.rest`) and lifecycles (`transition.action` under a `field.enum`) are registered since 1.3.0 (ADR-0066), checked at load and by `verify`. TypeScript's service generator emits from them (transition commands, declared command and query shells, permission points); the other ports do not yet. Their absence in a non-TypeScript port is not an adopter defect; do NOT audit for them. MCP exposure of declared prompts/tools is planned and not in the registry.
- **Cross-port version-NUMBER skew is by design** — TS/C#/Python `0.x` vs Java/Kotlin `7.x` Maven is correct; never flag the *number lines* differing. But that is exactly why you can't eyeball cross-language drift: compare **`metamodelVersion`** (Phase 0 cross-language consistency item), not the package numbers. A `metamodelVersion` MISMATCH across ports *is* a finding; so is a port lagging its ecosystem's latest release. A MATCH does not prove parity: added vocabulary does not move `metamodelVersion`, so ports on one metamodel version can still disagree on which attributes they know. Also flag *intra-port* drift (mixed versions within one port, or a runtime package in `devDependencies`).
- **Stale upstream prose** — "hand-write the Spring controller" (Java/Kotlin) is out of date; trust `meta gen --list`, not stale prose.
- **Include-only templates are not duplicates.** A prompt template whose body is only `{{> partial }}` includes is already the shared-partial fix the template-duplication check recommends. Identical stubs are the shape to want, never a byte-identical cluster to report (`references/prompt-anti-patterns.md`, template-text duplication).
Expand Down
Loading
Loading