Skip to content
Merged
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#; the TypeScript `service` and `service-routes` for derived CRUD, transitions, declared operations and the rules' checks).
- 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`, `service-routes` and `service-routes-hono` 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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ here.**

## [Unreleased]

- **codegen-ts: `service-routes-hono`, the service's Hono transport (ADR-0067 layer 5).**
`serviceRoutesHonoFile()` writes `<pkg path>/transport/hono.ts`, the same routes as the Fastify
transport, as `<pkg>ServiceHonoRoutes(app, { service, getActor })`, with the actor read by
`getActor(c)`. It imports the new `@metaobjectsdev/runtime-ts/service/hono` entry, and `meta eject
service-routes-hono` copies that source. A fixed path segment is added before a parameter wherever
two routes could match one request, so `GET <collection>/<query>` is not taken for
`GET <collection>/{id}`, as Fastify's router already decides.
- **The service is held to more of the shared API tests.** Its lanes, on Fastify and on Hono, now
run the `list-query/`, `api-settings/`, `enum-default/`, `jsonb/` and `duration/` corpora beside the
root and `rules/` corpora, on every engine the routes lane runs, D1 included through
`interactiveTransactions: false`. The service compile gate compiles both transports.

- **runtime-ts: the generated service keeps its rollback guarantee on a sync SQLite driver.** On
bun:sqlite and better-sqlite3, Drizzle's `transaction()` commits when its callback returns, so a
service write that awaited inside it committed at its first `await`: a hook's or a body's refusal
Expand Down
1 change: 1 addition & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/CONFORMANCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ regenerate with `ls -d fixtures/<corpus>/*/ | wc -l` for directory-shaped corpor
| [`fixtures/extract-conformance/`](../fixtures/extract-conformance/) | 58 | ✓ | ✓ | inherits the shared JVM engine | ✓ | ✓ |
| [`fixtures/output-prompt-conformance/`](../fixtures/output-prompt-conformance/) | 17 | ✓ | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/persistence-conformance/`](../fixtures/persistence-conformance/) | 68 (56 query + 12 migration) | all 68; the 24 `report-*` and the `-15` decimal scenarios also on SQLite, MySQL and D1, `decimal-exact` and `guarded-update` also on MySQL (a scenario's `engines:` key is exact) | 55 query (migrations TS-only, ADR-0015; `guarded-update` deferred to L-JV-2); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (via Exposed; `guarded-update` deferred to L-KT-2); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (`guarded-update` deferred to L-CS-2); the `report-*` and `engines:` scenarios also on SQLite and MySQL | 55 query (pg8000; `guarded-update` deferred to L-PY-2); the `report-*` and `engines:` scenarios also on SQLite (`sqlite3`) and MySQL (PyMySQL) |
| [`fixtures/api-contract-conformance/`](../fixtures/api-contract-conformance/) | 179 (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 + 17 rules) | ✓ (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, and `rules/` until each port's 1.3.0 service 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/) | 179 (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 + 17 rules) | ✓ (Fastify reference + generated lane; service lanes on Fastify and Hono for the entity sub-corpora, see the [api-contract README](../fixtures/api-contract-conformance/README.md#ts-lanes-illustrative-detail)); `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, and `rules/` until each port's 1.3.0 service work | ✓ (embedded HTTP + JDBC); `report/`, `decimal/` and `duration/` generated controllers over OMDB on Postgres, SQLite and MySQL | ✓ (embedded HTTP + Exposed); `report/`, `decimal/` and `duration/` also on SQLite and MySQL | ✓ (Kestrel + Npgsql); `report/`, `decimal/` and `duration/` also on SQLite and MySQL | ✓ (FastAPI + pg8000); `report/`, `decimal/` and `duration/` also on SQLite and MySQL |
| [`fixtures/decimal-wire/`](../fixtures/decimal-wire/) | 1 vector file (format, parse, filter operand, 15-digit read) | ✓ (`runtime-ts` and the generated helper) | ✓ (`CanonicalDecimal`) | ✓ (the generated wire file) | ✓ (`DecimalWire`) | ✓ (`decimal_wire`) |
| [`fixtures/duration-wire/`](../fixtures/duration-wire/) | 1 vector file: the `wire` vectors (parse, precision, refused) every port passes, and the `codecs` groups (Postgres text read and write, stored microseconds) each port passes only for the codecs it has | ✓ (`metadata` / `runtime-ts` and the generated helper) | ✓ | ✓ | ✓ | ✓ |
| [`fixtures/validation-conformance/`](../fixtures/validation-conformance/) | 42 cases + 43 cross-field cases (`cross-field-cases.json`, generated record model only) | ✓ (generated Zod + run-time `runValidators`) | ✓ | ✓ | ✓ | ✓ (generated Pydantic + run-time `run_validators`) |
Expand Down
27 changes: 17 additions & 10 deletions docs/features/business-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ entity's create and update records ([C# port](../ports/csharp.md)). The TypeScri
guarded update a transition writes, `ObjectManager.guardedUpdate`, held to the shared
persistence scenario `guarded-update.yaml`. The service layer starts in TypeScript: `service` writes
each package's derived list, get, create, update and delete, every write in one transaction with the
declared write rules, behind a thin Fastify transport (`service-routes`) that answers the shared API
tests as the flat routes do (see [The service layer](#the-service-layer-typescript)). It also writes
a command per transition and a shell per declared command and query, and enforces at run time what
this page declares: the permission point, the state check, the guarded update, `state_managed` and
the declared errors, held to the shared API tests' `rules/` corpus. The other ports' services are
declared write rules, behind a thin Fastify transport (`service-routes`) or Hono transport
(`service-routes-hono`) that answers the shared API tests as the flat routes do (see
[The service layer](#the-service-layer-typescript)). It also writes a command per transition and a
shell per declared command and query, and enforces at run time what this page declares: the
permission point, the state check, the guarded update, `state_managed` and the declared errors, held to the shared API tests' `rules/` corpus. The other ports' services are
later 1.3.0 work. A lifecycle in a project that wires no service generator will be advised by
`verify` once that check lands; until then the flat routes enforce nothing and `verify` says
nothing about it. Every flat generator writes byte-identical code for
Expand Down Expand Up @@ -385,7 +385,9 @@ package, the command and the option; queries are generated as usual.
`serviceRoutesFile()` (stable name `service-routes`, layer `api`, Fastify) writes the thin
transport (layer 5) beside it, `<pkg path>/transport/fastify.ts`: one plugin per package,
registered with the service it calls. Each route parses the request, calls one operation and
sends what it answered; it holds no rules and no database handle.
sends what it answered; it holds no rules and no database handle. `serviceRoutesHonoFile()`
(stable name `service-routes-hono`) writes the same routes for Hono, `<pkg path>/transport/hono.ts`,
as one function per package that adds them to your app: `shopServiceHonoRoutes(app, { service })`.

```ts
import { createShopService } from "./generated/acme/shop/service/index.js";
Expand All @@ -404,9 +406,11 @@ await withWriteTransaction(db, async (tx) => {

Both import the entity module (`entity`, for the table and the allowlists) and the contract types
(`contract-types`), written to the same target, and `@metaobjectsdev/runtime-ts`'s `service` and
`service/fastify` entries; `meta eject service` and `meta eject service-routes` copy that source into
`codegen/runtime/` as they do for the routes. The service lane of the shared API tests runs the
corpus the flat routes pass against the service behind this transport, in both layouts.
`service/fastify` (or `service/hono`) entries; `meta eject service`, `meta eject service-routes` and
`meta eject service-routes-hono` copy that source into `codegen/runtime/` as they do for the routes.
The shared API tests run the service behind each transport over a subset of the corpora the flat
routes pass; the subset and its engines are listed in the
[API contract README](../../fixtures/api-contract-conformance/README.md#ts-lanes-illustrative-detail).

### Transitions, declared operations and what you write by hand

Expand Down Expand Up @@ -443,7 +447,8 @@ API contract reserves (`not_found`, `forbidden`, `validation`, ...) is not accep

The actor is a type you define, `A`. A caller passes it per call as `opts.actor`, and the service
hands it to the policy, the bodies, the hooks and the event hook without looking inside it. The
Fastify transport takes a `getActor(request)` resolver of yours:
Fastify transport takes a `getActor(request)` resolver of yours, and the Hono transport a
`getActor(c)`:

```ts
const service = createPurchasingService<Actor>({
Expand All @@ -456,6 +461,8 @@ const service = createPurchasingService<Actor>({
events: { onWrite: (event, ctx) => writeAudit(ctx.tx, event) },
});
await app.register(purchasingServiceRoutes, { service, getActor: (req) => actorFromSession(req) });
// or, on Hono:
purchasingServiceHonoRoutes(app, { service, getActor: (c) => actorFromSession(c) });
```

The shared API tests' `fixtures/api-contract-conformance/rules/` corpus runs a model with a
Expand Down
Loading
Loading