Reference
Programmatic API
Generate from a build script without the CLI.
Everything the CLI does is available as functions from @dudousxd/nestjs-codegen.
generate
import { loadConfig, generate } from '@dudousxd/nestjs-codegen';
const config = await loadConfig(process.cwd()); // reads nestjs-codegen.config.ts
await generate(config /*, routes */);generate emits pages.d.ts/components.json from the resolved config, plus
routes.ts/api.ts/forms.ts when routes are provided.
watch
import { loadConfig, watch } from '@dudousxd/nestjs-codegen';
const config = await loadConfig();
const watcher = watch(config); // regenerates on change; holds a lock file
// later: await watcher.close();Lower-level building blocks
import {
extractSchemaFromDto, // class-validator class → SchemaModule (IR)
resolveAdapter, // adapter instance → ValidationAdapter (string names throw)
emitRoutes,
emitApi,
emitForms,
} from '@dudousxd/nestjs-codegen';
import { zodAdapter } from '@dudousxd/nestjs-codegen-zod'; // render a SchemaModule to zod textThe validation IR (SchemaNode/SchemaModule), the ValidationAdapter interface, and
the discovery types (RouteDescriptor, ContractSource) are all exported for building
your own tooling or adapters.
emit-api options
emitApi(routes, outDir, opts) accepts:
import { tanstackQuery } from '@dudousxd/nestjs-codegen-tanstack';
emitApi(routes, 'src/generated', {
extensions: [tanstackQuery()], // api.ts hooks (TanStack handles, etc.)
fetcherImportPath: '@dudousxd/nestjs-client', // where the Fetcher type comes from
});