Skip to content

codegen-ts: routesFileHono cannot emit expose, so its output mounts all five CRUD verbs #348

Closed

Description

@dmealing

Package: @metaobjectsdev/codegen-ts @ 0.24.5 · metamodel 0.13 · TypeScript/Hono consumer

Problem

The generated per-entity Hono wrapper calls mountCrudRoutes with no expose option, so it mounts all five CRUD verbs. expose exists on mountCrudRoutes itself, but there is no way to reach it from the generated wrapper — not through metadata, not through a generator option.

Any consumer whose tables are written through narrow, audited paths rather than generic CRUD therefore cannot use the generated routes at all.

Why this is more than an ergonomics gap

In one TypeScript/Hono consumer, mounting the generated wrappers was verified to allow a bearer-token holder to:

  • PATCH a decision row to rewrite its stored presented text and flip its status
  • POST a row that bypassed the paired audit-log write the application otherwise guarantees
  • DELETE a row, defeating a double-decision guard by enabling a re-decide

That consumer ended up hand-writing ten mountCrudRoutes({ ..., expose: ["list", "get"] }) calls — while ten generated routes files sat next to the entities, imported by nothing, each carrying the doc comment:

Customize: register this as-is for stock CRUD, ...

A later reader doing dead-code cleanup is therefore actively invited to adopt the one thing that must not be adopted. That is what happened: an adoption audit listed those files as dead weight to adopt.

Ask

An expose passthrough on the generated wrapper. Any of:

  1. a generator option — routesFileHono({ expose: (entity) => [...] })
  2. a metadata attribute the generator reads (see the sibling issue about @emitRoutes not being registerable — same shape)
  3. emitting it as an optional third parameter of the generated register<Entity>Routes(app, deps, opts)

(1) is the smallest change and composes with the existing filter option.

Workaround

Copy src/reference/routes-hono.ts into the project, stop calling renderRoutesFileHono, and render the CRUD body locally so expose can be emitted. This is what scaffold-and-own is for and it works — but it forks the renderer, so upstream template improvements have to be merged by hand. Projections still delegate to renderRoutesFileHono, since mountReadOnlyCrudRoutes is read-only already.

Activity

  1. dmealing commented on Aug 31, 2026

    @dmealing
    MemberAuthor

    Confirmed, and broader than filed — leaving this open.

    The Hono wrapper is not the only one. expose exists on all three mount helpers (runtime-ts/src/fastify/index.ts:49, drizzle-fastify/index.ts:62, hono/index.ts:83, each new Set<CrudVerb>(opts.expose ?? ALL_VERBS)), but across the generated route emitters there is exactly one call site that passes it — templates/routes-file.ts:358, expose: ["list", "get"], on the read-only projection branch. For a vanilla or write-through entity, neither the Fastify nor the Hono emitter can restrict verbs. So the title should really say "the generated route files", not routesFileHono.

    The use case is legitimate and is one we now name explicitly in the shipped agent context: a project whose tables are written through narrow, audited paths should not be mounting generic CRUD, and an emitted-but-unmounted routes file is worse than no file, because it still carries a doc comment saying to register it as-is for stock CRUD — inviting a later dead-code cleanup to adopt exactly the surface you decided against.

    Two candidate answers, and the choice matters:

    1. Own the generator. Under ADR-0034 the routes generator is yours — meta eject routes-hono puts it in your repo, and adding expose to the mountCrudRoutes call is a one-line edit to your own code. This works today with no release. What is missing is that the reference template's customize: header does not name expose as a swap point, so the move isn't discoverable from the file you're told to edit.
    2. A generator option, the way @emitGrid became tphSubtypeGrids rather than metadata vocabulary (see codegen-ts: @emitRoutes (and emitGrid/emitForm/emitTanstack) are read by codegen but not registered, so they cannot be authored #349). This is what would suit a project that hasn't ejected.

    Note that a metadata attribute is deliberately not on that list — that is the shape #349 just retired.

    Leaning toward (1) plus making it discoverable, with (2) if the ergonomics don't hold up. Input welcome on which fits your setup better, since you're the one running it.

  2. dmealing commented on Aug 31, 2026

    @dmealing
    MemberAuthor

    Fixed on main; ships in the next release. Shipped as a generator option on both emitters, not just Hono — the gap was wider than the title.

    routesFileHono({ expose: (e) => e.name === "AuditEntry" ? ["list", "get"] : undefined })
    routesFile({ expose: ["list", "get"] })

    Verbs or a per-entity function. Absent, or a function returning undefined, means all five and emits no expose key at all — so output is byte-identical for every project that doesn't use it. That's pinned as its own test rather than assumed.

    Why an option rather than the filter remedy (the one that answered #349): filter decides whether the file emits at all, per entity, so it can only remove the whole surface. Restricting to a subset of verbs is a different axis, and filter structurally cannot express it. Same reasoning that made a TPH subtype's opt-IN grid tphSubtypeGrids rather than a filter.

    Deliberately not a metadata attribute: which verbs a deployment exposes is a property of the app, not the model — the same entity is read-only in one service and writable in another, and an attribute would force one answer into the shared spine. That's the shape #349 just retired.

    One behaviour worth knowing: a TPH polymorphic mount is read-only by construction (the discriminated union has no single writable shape), so expose intersects with its fixed ["list","get"] rather than replacing it. You can narrow it to ["list"]; asking for create yields an empty set rather than a route that fails at runtime. Hono's projection branch is untouched — it calls mountReadOnlyCrudRoutes, a different helper with no writable surface to narrow.

    The reference templates carry the option too, so an ejected generator behaves identically, and CRUD_VERBS / resolveExpose / intersectExpose / exposeLine are public so an owned routes generator can compose the same call.

    One thing your report prompted that's worth naming: the verb union is restated in codegen-ts (it emits a call to the runtime helper, it never links against it), and nothing compared the two. That's the same drift class as #355. It's now gated against both runtime declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions