Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
64b47cf
docs(adr-0066): state that input validation precedes the permission p…
dmealing Nov 22, 2026
972f9d3
feat(runtime-ts,codegen-ts): sync SQLite rollback in the service, and…
dmealing Nov 22, 2026
f19a7c8
no-mistakes(document): service tx and D1 facts current in docs
dmealing Nov 22, 2026
cc031da
no-mistakes(document): service options list interactiveTransactions
dmealing Nov 22, 2026
d4923db
feat(codegen-ts,runtime-ts): service lane on the entity sub-corpora, …
dmealing Nov 22, 2026
9682efa
Merge remote-tracking branch 'origin/main' into fm/mo-130-lane-ts-2-b9
dmealing Nov 22, 2026
6452eb1
no-mistakes(document): Document Hono transport and service lanes
dmealing Nov 22, 2026
8ece420
no-mistakes(document): Document Hono transport and service lanes
dmealing Nov 22, 2026
299c45f
wip(runtime-ts): extract framework-neutral read-only and M:N reads fr…
dmealing Nov 22, 2026
57b7446
wip(codegen-ts,runtime-ts): service coverage walk, read-only transpor…
dmealing Nov 22, 2026
85b4c7b
Merge remote-tracking branch 'origin/main' into fm/mo-130-lane-ts-2-b10
dmealing Nov 22, 2026
ab5d255
wip(codegen-ts): service operations for read-only, write-through, TPH…
dmealing Nov 22, 2026
5fe60d9
wip: service lane on report/tph/m2m/decimal/secret-fields; served rep…
dmealing Nov 22, 2026
4d59b36
fix: examples own the read-only and M:N read modules; the eject contr…
dmealing Nov 22, 2026
3adb794
fix(codegen-ts): a single-table subtype's transition commands and key…
dmealing Nov 22, 2026
b2de19f
refactor(codegen-ts): one key-and-scope condition builder for the ser…
dmealing Nov 22, 2026
240919e
Merge remote-tracking branch 'origin/main' into fm/mo-130-lane-ts-2-b10
dmealing Nov 22, 2026
3fcb389
no-mistakes(test): Move typed-create compile test temp dirs to scratch
dmealing Nov 22, 2026
ae4f2dc
no-mistakes(document): docs: service lane coverage in api-contract docs
dmealing Nov 22, 2026
dfe371f
no-mistakes(lint): Report site transcript capture failures distinctly
dmealing Nov 22, 2026
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
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ here.**
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.
- **The service covers every object the flat routes serve.** Projections and served reports get
their reads, and their transports answer writes `405`. A report keeps its row cap, through the
new `serviceFile({ reportMaxRows })` option, and its `?format=` export. Write-through entities
read through their view and read a write back through it. A single-table hierarchy gets the
polymorphic base reads and per-subtype operations scoped to the discriminator. Each
many-to-many relationship gets a query and a `GET <path>/{id}/<relation>` route. The
`projection/`, `report/` (Postgres, MySQL, SQLite and D1), `write-through/`, `tph/`, `m2m/`,
`decimal/` and `secret-fields/` corpora now run on both service lanes. runtime-ts: the read-only
and many-to-many reads (`readOnlyList`, `readOnlyGet`, `m2mRelated`) are framework-neutral
functions, which the flat Fastify mounts and the service both call.
- **codegen-ts: a `runGen` with no project no longer leaves its gen-state in the scratch root.**
The state of such a run is kept for that process's later runs only, and is removed when the
process exits normally (a process killed by a signal still leaves it). Before this fix, each such process left `meta-gen-state-<pid>` behind
permanently. The test harnesses that generate with no project had left hundreds of those
directories, about 3 GB, in a RAM-backed `$DEV_SCRATCH`.

- **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
Expand Down
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; 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/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, `projection/`, `report/`, `write-through/`, `tph/`, `m2m/`, `decimal/` and `secret-fields/` 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
18 changes: 16 additions & 2 deletions docs/features/business-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,22 @@ generated service, under the default settings and under `rules.lifecycle.create:
`rules.lifecycle.commands: all` and `none`. Its README specifies the hand-written pieces, so every
port's lane implements the same ones.

Not covered yet, and still served by the flat generators: write-through entities, single-table (TPH)
hierarchies, many-to-many traversal, projections and reports.
The service covers every object the flat routes serve, with the same answers:

- A projection and a served report get a list (and a get, when the projection is keyed). Their
transports answer every write `405 method_not_allowed`. A report keeps its row cap
(`serviceFile({ reportMaxRows })`, as `routesFile` takes it) and, with `report-export` wired,
its `?format=` export.
- A write-through entity reads through its replica view and answers a write by reading the row
back through that view.
- A single-table (TPH) hierarchy's base gets the polymorphic list and get. Each concrete subtype
gets the five operations at its own path, on the base table, scoped to its discriminator value.
- A many-to-many relationship gets a query, `<relation>Of<Entity>(id)`, served at
`GET <path>/{id}/<relation>`.

The `projection/`, `report/`, `write-through/`, `tph/`, `m2m/`, `decimal/` and `secret-fields/`
corpora run on the service lanes as well as the routes lane. An entity with a composite key has no
derived operations.

## Requirements can claim operations and transitions

Expand Down
7 changes: 5 additions & 2 deletions docs/ports/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,9 @@ and give it its own `target` to put the layer in a package the transport and cli
`serviceFile()` (stable name `service`, layer `service`) is layer 4 of ADR-0067. It writes one
module per metadata package, under the package's directory in either layout: a file per operation
in `<pkg path>/service/` (each entity's derived list, get, create, update and delete, every write in
one transaction by default, with the declared write rules) and `service/index.ts` with the `<Pkg>Service`
one transaction by default, with the declared write rules; the reads of a projection or a served
report; a single-table subtype's operations, scoped to its discriminator; a query per many-to-many
relationship) and `service/index.ts` with the `<Pkg>Service`
interface and `create<Pkg>Service(deps)`. A model with ADR-0066 rules also gets a file per
derived transition command and per declared command and query, each running the rules' checks
around a hand-written body; the policy, bodies, hooks and event hook are passed in `deps`.
Expand All @@ -764,7 +766,8 @@ routes that call it, with a `getActor(request)` option for the app's actor.
`<pkg path>/transport/hono.ts`, with `getActor(c)`. Each needs `entity` and `contract-types` in the
same target. None is scaffolded; add them to `generators` or `meta eject` them. On SQLite the
service takes a sync or an async Drizzle driver. A store that holds no transaction across
application code (Cloudflare D1) takes `serviceFile({ interactiveTransactions: false })`.
application code (Cloudflare D1) takes `serviceFile({ interactiveTransactions: false })`, and a
report's row cap is `serviceFile({ reportMaxRows })`, as `routesFile` takes it.
See [Business rules](../features/business-rules.md#the-service-layer-typescript).

### Prove it works
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
// that checks the source row's own discriminator first.

import type { FastifyInstance, RouteShorthandOptions } from "fastify";
import { and, eq, or, inArray } from "drizzle-orm";
import { coerceIdForColumn } from "./util.js";
import { m2mRelated } from "../m2m-read.js";
import { InvalidIdError } from "../read-only-read.js";
import { timestampWire } from "../timestamp-wire.js";
import { withWire, type WireOptions } from "../wire-format.js";
import { withContractErrorHandler } from "./route-error-handler.js";
Expand Down Expand Up @@ -92,97 +92,11 @@ export function mountM2mRoute(opts: M2mRouteOptions): void {

opts.fastify.get(route, ro, async (req, reply) => {
const { id } = req.params as { id: string };

const srcCol = columnRef(opts.junctionTable, opts.sourceColumn);
const tgtCol = columnRef(opts.junctionTable, opts.targetColumn);

// Compare against the junction FK's real type — a numeric-LOOKING id on a
// TEXT fk must stay a string ('0123' ≠ '123'), or affinity traverses the
// WRONG source row's relations.
const sourceId = coerceIdForColumn(srcCol, id);
if (sourceId === undefined) {
return reply.code(400).send({ error: "invalid_id" });
}

// Stage 0 — the source id must name a row of THIS subtype. Skipping it would let
// `/auths/bridge/{a Coupon's id}/linkedAuths` return that Coupon's relations, because
// the junction FK cannot tell the subtypes apart: it points at the shared base table.
const srcDisc = opts.sourceDiscriminator;
if (srcDisc !== undefined) {
const srcPk = columnRef(srcDisc.table, srcDisc.pkColumn);
const ownId = coerceIdForColumn(srcPk, id);
if (ownId === undefined) {
return reply.code(400).send({ error: "invalid_id" });
}
const owner = await opts.db
.select({ d: columnRef(srcDisc.table, srcDisc.column) })
.from(srcDisc.table)
.where(eq(srcPk, ownId))
.limit(1);
if (owner.length === 0 || String(owner[0]?.d) !== srcDisc.value) return [];
}

// Stage 1 — junction rows for this source id.
const joinWhere = opts.symmetric
? or(eq(srcCol, sourceId), eq(tgtCol, sourceId))
: eq(srcCol, sourceId);
const joinRows = (await opts.db
.select({ src: srcCol, tgt: tgtCol })
.from(opts.junctionTable)
.where(joinWhere)) as Array<{ src: unknown; tgt: unknown }>;

// Collect the related target ids. Symmetric: the related endpoint is the
// column that is NOT the source id (compared by string key to bridge
// number/bigint-as-string driver skew). Otherwise: always the target column.
const sourceKey = String(sourceId);
const relatedIds = new Set<string | number | bigint>();
for (const r of joinRows) {
if (!opts.symmetric) {
addId(relatedIds, r.tgt);
continue;
}
const srcIsSource = r.src != null && String(r.src) === sourceKey;
// Self-loop (a,a): src matches → relate to a itself (single occurrence).
if (srcIsSource) addId(relatedIds, r.tgt);
else addId(relatedIds, r.src);
try {
return (await m2mRelated(opts.db, opts, id)).map(toWire);
} catch (e) {
if (e instanceof InvalidIdError) return reply.code(400).send({ error: "invalid_id" });
throw e;
}

if (relatedIds.size === 0) return [];

// Stage 2 — load the target rows.
const pkCol = columnRef(opts.targetTable, targetPk);
const byPk = inArray(pkCol, [...relatedIds]);
const disc = opts.targetDiscriminator;
const rows = await opts.db
.select()
.from(opts.targetTable)
.where(disc ? and(byPk, eq(columnRef(opts.targetTable, disc.column), disc.value)) : byPk);
return (rows as unknown[]).map(toWire);
});
}

function addId(set: Set<string | number | bigint>, v: unknown): void {
if (v === null || v === undefined) return;
// Keep bigint AS bigint — Number(bigint) silently loses precision above
// 2^53, so a field.long id could round to a DIFFERENT row's key. Drizzle
// binds bigint params natively; the driver never needed the narrowing.
if (typeof v === "number" || typeof v === "string" || typeof v === "bigint") set.add(v);
}

/**
* Resolve a physical column name to its Drizzle column object. Drizzle exposes
* columns on the table object keyed by the TS property name, but the underlying
* `.name` is the physical column. The descriptor carries physical names (what
* the junction/target SQL uses), so match on `.name` and fall back to the key.
*/
// biome-ignore lint/suspicious/noExplicitAny: returns a Drizzle column ref for the loose query builder
function columnRef(table: AnyTable, physicalName: string): any {
for (const key of Object.keys(table)) {
const col = table[key];
if (col && typeof col === "object" && col.name === physicalName) return col;
}
// Fall back to the property-name lookup (covers tables whose TS key == column).
const direct = table[physicalName];
if (direct !== undefined) return direct;
throw new Error(`mountM2mRoute: column '${physicalName}' not found on table`);
}
Loading
Loading