Skip to content

codegen-ts: @emitRoutes (and emitGrid/emitForm/emitTanstack) are read by codegen but not registered, so they cannot be authored #349

Closed

Description

@dmealing

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

Problem

@metaobjectsdev/codegen-ts exports these and gates its generators on them:

export const CODEGEN_ATTR_EMIT_TANSTACK = "emitTanstack";
export const CODEGEN_ATTR_EMIT_GRID     = "emitGrid";
export const CODEGEN_ATTR_EMIT_FORM     = "emitForm";
export const CODEGEN_ATTR_EMIT_ROUTES   = "emitRoutes";

e.g. e.attr(CODEGEN_ATTR_EMIT_ROUTES) !== false in the routes generators.

But authoring the attribute fails the load:

meta: failed to load metadata: Unknown attribute '@emitRoutes' on object.entity 'Xxx'
      — not declared by any registered provider for object.entity
{ "object.entity": { "name": "Session", "@emitRoutes": false, "children": [ ... ] } }

So the per-entity opt-out that the agent-facing docs describe —

Per-entity opt-outs exist (e.g. skipping client-side artifacts for a given entity) and are set as attributes on the entity in metadata, not in code.

— is not reachable without the consumer writing a provider to register an attribute the codegen package already defines and consumes.

Ask

Register these four attributes on object.entity in the codegen package's own provider, so the documented opt-out loads. If they are deliberately consumer-registered, the docs should say so and show the provider wiring.

Why it matters beyond ergonomics

The natural way to say "this table has no REST surface" is @emitRoutes: false on the entity. Without it, the consumer expresses the same fact in generator config instead — which works, but puts it outside the metadata that is supposed to be the single spine.

The concrete case: a project found its routes generator emitting route files for its credential tables (a pin_hash table and a token_hash session table). Nothing mounted them, so nothing leaked — but the fix wanted to be one metadata attribute on two entities, and had to become a generator-config allowlist instead.

Activity

  1. dmealing commented on Aug 31, 2026

    @dmealing
    MemberAuthor

    Fixed on main, ships in the next release.

    The five @emit* attributes are retired rather than registered. The report is right that they were read and never registered — and the behaviour was worse than "cannot be authored": meta gen loads OPEN and honoured them, while meta verify loads STRICT (ADR-0023) and rejected them. So the attribute worked and the drift gate documented beside it went red. Half-working, which is worse than either half.

    command load mode result
    meta gen open the attribute worked — the artifact was suppressed
    meta verify strict ERR_UNKNOWN_ATTR — the build failed

    Registering them was refused deliberately: it would move metamodelVersion and oblige four other registries to publish for a TypeScript-only generator kill switch none of them will ever read. The replacement already existed — decide per generator what you consume: wire only the generators whose output you import, and narrow one with its own filter.

    routesFile({ filter: (e) => e.name !== "InternalAudit" }),

    The five names became entries in the metadata package's RETIRED_VOCABULARY, which already feeds both the loader diagnostic and meta upgrade's rewriter — so meta upgrade --apply removes them for you, and meta gen names every object still carrying one until you do.

    @emitGrid is the one exception. It was opt-IN (a TPH subtype's own per-subtype grid) and a filter is ANDed with the built-in gates, so it can only ever narrow. It is now tphSubtypeGrids?: (entity) => boolean on tanstackGrid() and tanstackGridHook(). Pass the same predicate to both, or you reproduce #287 exactly.

    Breaking if you ejected a generator on 0.24.5 or earlier: CODEGEN_ATTR_EMIT_ROUTES and its three siblings were public exports imported by the shipped reference templates, so an owned codegen/generators/*.ts fails with TS2305 after upgrading. Loud rather than silent, by choice — delete the import and the clause that used it.

    Migration guide: docs/features/migrations/emit-attrs-to-generator-config.md.

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