/** * Codegen AST extractor (plan: `.plans/refactor/queued/codegen-ast.md` · design: * `docs/codegen-ast-approach.md`). Parses a controller's source with **oxc** and * reads, declaratively from the AST, everything the codegen front-end needs — this * (with `astResolve`/`astEmit`) is the whole front-end; the old regex/char-loop * reconstruction and boot-time reflection have been removed. * * Per controller source it returns: * - `imports`: binding → { specifier, kind, orig? }. Keyed on the LOCAL * import binding, read straight off the import node — so the * binding-vs-class-name problem (`import Auth` for class * `AuthMiddleware`) that `importResolution` solved by live-class * identity matching simply never arises. * - `extendsName`: the EXPORTED class's parent identifier (or `null`). * - `routes`: method → path → { handler, hasRequest, hasQuery, hasParams }. * - `middleware`: name-tagged `[{ scope, bindings }]`, or `undefined` when the * controller declares none (inherits its parent's). * * `routes` and `middleware` are extracted INDEPENDENTLY: a dynamic `routes` getter * doesn't discard a literal `middleware` Map (the base `AbstractController` has * exactly that shape — a `logger.warn` + stub `return {}` for routes, a literal * Map for middleware). When a getter isn't a literal structure, the relevant * aspect is flagged via `ok: false` / `reason`; codegen can't statically analyze * that controller and the run throws (no boot fallback — declarative-only). * * oxc, not the TypeScript API: `ts.createSourceFile` is dropped in TS 7's Go port * (its `unstable/ast` replacement exposes a scanner/visitor but no standalone file * parser, and `unstable/sync` is the full Program/Checker API). oxc is a stable * in-process napi parser, and codegen needs only syntactic extraction — it emits * type expressions, it never resolves types. The parser is an OPTIONAL peer loaded * lazily; see `parser.ts`. */ export interface ImportInfo { specifier: string; kind: 'default' | 'named' | 'namespace'; /** Original export name when the binding is a renamed named import. */ orig?: string; } export interface RouteInfo { method: string; path: string; /** Handler method name (`this.`), or `null` if unidentifiable. */ handler: string | null; hasRequest: boolean; hasQuery: boolean; /** A route-level `params:` schema is declared (validated path params). */ hasParams: boolean; /** Media-type keys when `request` is a content-type map (`{ 'application/json': * … }`); absent for a single-schema request. */ requestContentTypes?: string[]; /** Route-level middleware binding names (`{ handler, middleware: [X] }`). */ middleware?: string[]; } export interface MiddlewareScope { scope: string; bindings: string[]; } export interface ExtractResult { /** False when a getter isn't a literal structure → not statically analyzable. */ ok: boolean; reason?: string; className?: string; extendsName?: string | null; imports: Record; routes: RouteInfo[]; /** `undefined` = no own middleware (inherits); `[]` is a real empty map. */ middleware?: MiddlewareScope[]; /** A `static get middleware()` is defined here but isn't a literal `new Map([…])` * — so `middleware` is `undefined` for a reason the extends-walk must NOT treat * as "inherits from above" (that would silently drop the real middleware). */ middlewareDynamic?: boolean; /** Literal `getHttpPath()` return (e.g. `'/'`), if the method returns a string * literal. `undefined` = method not defined (caller uses the default mount). */ httpPath?: string; /** `getHttpPath()` is defined but not a literal return → mount path unknown. */ httpPathDynamic?: boolean; /** Top-level class declarations in this file → whether each is exported. Lets * the resolver tell a controller's OWN locally-declared middleware (keep it, * importing from this module) from a genuinely foreign bleed-in (drop it). */ localClasses: Record; } /** Parse a controller source and extract its declarative codegen shape. */ export declare function extractController(src: string, fileName: string): ExtractResult;