@genesislcap/event-type-codegen

中文文档
15.96.2发布于 2026/11/16SEE LICENSE IN license.txtTypeScriptCommonJS近 30 天下载 2.2万

Build-time TypeScript codegen from Kotlin event handler DTOs

原始使用文档
文档目录6 节
  1. Configuration
  2. CLI
  3. Limitations (v1)
  4. Typed commits
  5. Metadata dump path (FUI-2608)
  6. Migration

@genesislcap/event-type-codegen

Build-time TypeScript interfaces for Genesis event DETAILS payloads, discovered from Kotlin PAL event handlers without a running server.

Configuration

Enable via genx.config.* or the genx / genesis key in package.json:

{
  "genx": {
    "eventTypes": {
      "enabled": true,
      "serverModule": "../server/my-app",
      "kotlinSources": [
        "src/main/kotlin/**/dto/**/*.kt",
        "src/main/genesis/scripts/**/*.kts"
      ],
      "generatedDaoSources": [
        "build/internal-modules/**/*-generated-dao/build/generated/sources/dao/global/genesis/gen/dao/**/*.kt"
      ],
      "handlerScan": [
        "src/main/kotlin/**/*.kt",
        "src/main/genesis/scripts/**/*.kts"
      ],
      "output": "src/generated/genesis-event-types.ts",
      "runOnBuild": true
    }
  }
}

When enabled is false or the block is omitted, codegen is skipped.

generatedDaoSources globs are resolved against both the app module (serverModule) and its parent Gradle server/ directory (where dictionary-cache DAOs usually live). Defaults cover common monorepo layouts after ./gradlew … has generated DAO sources. Custom data class DTOs always override a generated DAO with the same class name.

CLI

From a client app directory:

genx generate event-types

genx build runs codegen first when eventTypes.enabled and runOnBuild (default true when enabled).

In the showcase server Gradle build, generateDao is finalizedBy generateEventTypes, which runs genx generate event-types in react-client when genx is available (after monorepo bootstrap). Disable with -PenableEventTypeCodegen=false.

Limitations (v1)

  • Discovery uses Kotlin source parsing, not the compiler or live JSON Schema.
  • Only handlers with a resolvable DETAILS shape (custom DTO or generated table/index from generatedDaoSources) get *Details types and EventDetailsMap entries. Anything else is listed in a comment at the top of the generated file.
  • Full table DAO handlers (e.g. eventHandler<Trade>("TRADE_INSERT")) and index handlers (e.g. eventHandler<Trade.ById>("TRADE_DELETE")) are mapped when generated DAO .kt sources are present under generatedDaoSources.
  • Class-based handler sources named *EventHandler.kt under a dto/ path are skipped. The dto/** glob is for input data classes only; those files are usually SyncValidatingEventHandler implementations and are not PAL eventHandler { } scripts. PAL handlers in *-eventhandler.kts (and other handlerScan paths) are still discovered.
  • Generate DAO sources (Gradle) before client codegen in CI if the trees are not committed.
  • Dictionary ENUM fields: string literal unions when enum class and/or companion Field.Type.ENUM values = "…" appear under generatedDaoSources (gen/dao/**/*.kt).
  • Enum exports are named after the Kotlin enum, and are qualified with the owning table only when declarations disagree. Genesis emits an enum either unscoped, in the flat global.genesis.gen.dao.enums, or table-scoped, in …enums.<dictionary>.<table> — so several declarations can share a simple name. Identical value sets share one export; differing ones are qualified (AxeStatus / RfqStatus / OrderStatus) so no table's fields point at another's values. Where an unscoped declaration is among them it keeps the bare name, because that is the one a PAL script's default import resolves to.
  • A field's enum is resolved the way Kotlin resolves the name, against the file that wrote it: a type the file declares itself, then an explicit import, then the file's own package, then star imports. Each rung shadows those below it — an explicit import that names something outside the generated tree yields unknown, never a same-named generated enum.
  • PAL scripts (.kts under genesis/scripts/) additionally carry the default imports the Genesis compiler supplies (…gen.dao.enums.*, …gen.dao.* and the generated config/view packages), which is why val feeType: FeeType resolves there with no import line. Star imports do not recurse, so a table-scoped enum named with no import in a script still resolves to unknown: Genesis does supply those as explicit default imports via tables-info.json, but that tier is not modelled yet. A plain .kt source, and anything under genesis/cfg/, gets no defaults.

Typed commits

  • *Details interfaces — DETAILS payload from Kotlin DTOs.
  • GenesisEvent (from @genesislcap/foundation-comms) — abstract base; subclass sets MESSAGE_TYPE.
  • Per-handler classes — e.g. EventAqsCounterpartyInsert.
import { commitGenesisEvent } from '@genesislcap/foundation-comms';
import { EventAqsCounterpartyInsert } from './generated/genesis-event-types';

await commitGenesisEvent(
  connect,
  new EventAqsCounterpartyInsert({ COUNTERPARTY_ID: 'x' }),
);

Metadata dump path (FUI-2608)

Generate from a live-server snapshot instead of (or in addition to) Kotlin source scan:

  1. In a connected app with foundation-header, press Ctrl/Cmd+Shift+E (dev builds only) to download event-metadata.json.
  2. Run:
genx generate event-types --from-metadata event-metadata.json

This uses inbound JSON Schema DETAILS (field names, JSON_TYPE, requiredness) as the contract — useful for comparing against the Kotlin-scan output and for handlers the source scanner misses.

Wire field naming for the Kotlin path matches genesis-server toUpperUnderscoreWithAcronyms (e.g. addressLine1 → ADDRESS_LINE_1). Date/DateTime Kotlin types map to TypeScript number (epoch millis / JSON_TYPE: integer).

Migration

AppAction
New genx templateEnable eventTypes, commit or gitignore generated output
LegacyAdd config, run genx generate event-types, adopt typed commits incrementally
No Kotlin DTOsLeave disabled

版本与发布记录

@genesislcap/event-type-codegen 共发布 416 个版本,首次发布于 2026/07/16;过去 12 个月发布了 416 个版本。

版本发布日期距今
15.96.2latest2026/11/16今天
15.96.12026/11/16今天
15.96.0-GENC-1665.32026/11/142 天前
15.96.02026/11/142 天前
15.95.2-GENC-1665.22026/11/132 天前
15.95.22026/11/133 天前

其他发布通道:FUI-2567 → 15.1.0-FUI-2567.3,GENC-1461 → 15.1.0-GENC-1461.6,FUI-2571-formatters → 15.3.2-FUI-2571-formatters.1,FUI-2591 → 15.3.2-FUI-2591.1,GENC-1475 → 15.6.2-GENC-1475.8,ts7-migration → 15.6.1-ts7-migration.1。

关于 @genesislcap/event-type-codegen 的常见问题

@genesislcap/event-type-codegen 是什么?

Build-time TypeScript codegen from Kotlin event handler DTOs

如何安装 @genesislcap/event-type-codegen?

在项目目录运行 npm install @genesislcap/event-type-codegen,或使用 pnpm add / yarn add / bun add。

@genesislcap/event-type-codegen 支持 TypeScript 吗?

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

@genesislcap/event-type-codegen 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@genesislcap/event-type-codegen 需要什么版本的 Node.js?

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

@genesislcap/event-type-codegen 可以商用吗?

@genesislcap/event-type-codegen 使用 SEE LICENSE IN license.txt 许可。许可条款写在包内的独立文件中,请阅读该文件确认可否商用。以上为概括,不构成法律意见,请以许可原文为准。

@genesislcap/event-type-codegen 的下载量有多少?

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

@genesislcap/event-type-codegen 还在维护吗?

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