@dudousxd/nestjs-inertia-codegen-extension

中文文档
0.5.0发布于 2026/11/12MITTypeScriptES Module构建来源已验证近 30 天下载 2068

nestjs-codegen extension for @dudousxd/nestjs-inertia — adds the Inertia navigate() helper to the generated api.ts, plus opt-in shared.ts and page-excludes.ts emission.

原始使用文档
文档目录6 节
  1. Install
  2. Setup
  3. What it adds
  4. How it fits
  5. Links
  6. License

@dudousxd/nestjs-inertia-codegen-extension

The Inertia extension for @dudousxd/nestjs-codegen — adds an Inertia router import and a type-safe navigate() helper to the generated typed client.

npm

The typed client codegen lives in the standalone @dudousxd/nestjs-codegen package. This package is just the Inertia extension for it: register nestjsInertiaCodegen() and the generated api.ts gains a navigate() helper backed by Inertia's router, so your mutations and links can drive Inertia visits with full route-name and params autocomplete.

Install

pnpm add -D @dudousxd/nestjs-inertia-codegen-extension

It is an extension for the core codegen, so install that alongside it (the Inertia adapter for React provides router):

pnpm add -D @dudousxd/nestjs-codegen
pnpm add @inertiajs/react
Peer dependencyRange
@dudousxd/nestjs-codegen>=0.1.0
@inertiajs/react>=1.0.0

Setup

Register the extension in the codegen's extensions: [...] array — either via the Nest module or in defineConfig for CLI/CI runs.

import { NestjsCodegenModule } from '@dudousxd/nestjs-codegen/nest';
import { nestjsInertiaCodegen } from '@dudousxd/nestjs-inertia-codegen-extension';

NestjsCodegenModule.forRoot({
  contracts: { glob: 'src/**/*.controller.ts' },
  pages: { glob: 'inertia/pages/**/*.tsx' },
  app: { moduleEntry: 'src/app.module.ts' },
  codegen: { outDir: '.nestjs-inertia' },
  extensions: [nestjsInertiaCodegen()],
});

The same array works in nestjs-codegen.config.ts (defineConfig) — keep one source of truth and import it into both.

What it adds

nestjsInertiaCodegen() is a CodegenExtension whose apiHeader hook contributes to the generated api.ts:

  • an import of Inertia's router — import { router } from '@inertiajs/react';
  • a NavigateOptions type (method, data, preserveState, preserveScroll, replace)
  • a type-safe navigate() helper that resolves a named route to its URL and calls router.visit()
import { navigate } from '~codegen/api';

// Route name autocompleted; params required when the route has :id
navigate('users.show', { params: { id: '42' } });
navigate('showDashboard.show');

// With Inertia visit options
navigate('users.list', { preserveState: true, replace: true });

Opt-in files: shared emits shared.ts (InertiaSharedProps), scopes: { <scope>: { shared } } adds each forFeature scope's shared props to it (InertiaScopeSharedProps, ScopeSharedProps<S>), and pageExcludes: true emits page-excludes.ts.

Without the extension, api.ts is a plain typed-fetch client and @inertiajs/react's router is never imported. The extension owns only the Inertia surface of api.ts — Inertia page discovery (pages.d.ts / components.json) and shared props are still handled by the core pages / app config.

How it fits

@dudousxd/nestjs-codegen runs a discovery → IR → emit pipeline and exposes an extension contract at @dudousxd/nestjs-codegen/extension. Integrations aren't config flags — they're extensions you register in extensions: [...], and each one shapes routes, emits extra files, or augments api.ts. This package implements that contract with a single apiHeader hook:

import type { CodegenExtension } from '@dudousxd/nestjs-codegen/extension';

export function nestjsInertiaCodegen(): CodegenExtension {
  return {
    name: 'nestjs-inertia',
    apiHeader() {
      return {
        imports: ["import { router } from '@inertiajs/react';"],
        statements: [/* NavigateOptions + navigate() */],
      };
    },
  };
}

It composes with the other companion extensions — e.g. tanstackQuery() (@dudousxd/nestjs-codegen-tanstack) for queryOptions/mutationOptions and nestjsFilterCodegen() (@dudousxd/nestjs-filter-codegen) for typed filters.

License

MIT

版本与发布记录

@dudousxd/nestjs-inertia-codegen-extension 共发布 6 个版本,首次发布于 2026/06/11;过去 12 个月发布了 6 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.0latest2026/11/122 天前
0.4.12026/11/086 天前
0.4.02026/09/301 个月前
0.3.02026/07/114 个月前
0.2.02026/06/184 个月前
0.1.02026/06/115 个月前

关于 @dudousxd/nestjs-inertia-codegen-extension 的常见问题

@dudousxd/nestjs-inertia-codegen-extension 是什么?

nestjs-codegen extension for @dudousxd/nestjs-inertia — adds the Inertia navigate() helper to the generated api.ts, plus opt-in shared.ts and page-excludes.ts emission.

如何安装 @dudousxd/nestjs-inertia-codegen-extension?

在项目目录运行 npm install @dudousxd/nestjs-inertia-codegen-extension,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@inertiajs/react(>=1.0.0)、@dudousxd/nestjs-codegen(>=0.2.1)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dudousxd/nestjs-inertia-codegen-extension 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dudousxd/nestjs-inertia-codegen-extension 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dudousxd/nestjs-inertia-codegen-extension 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=24。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dudousxd/nestjs-inertia-codegen-extension 可以商用吗?

@dudousxd/nestjs-inertia-codegen-extension 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dudousxd/nestjs-inertia-codegen-extension 的下载量有多少?

根据 npm 官方下载统计,@dudousxd/nestjs-inertia-codegen-extension 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,068 次,日均约 69 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dudousxd/nestjs-inertia-codegen-extension 还在维护吗?

最新版本 0.5.0 发布于 2026/11/12(2 天前);至今共发布 6 个版本,其中过去 12 个月发布了 6 个;首次发布于 2026/06/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。