@haneinfo/domain-events

中文文档
11.1.8发布于 2026/11/17UNLICENSEDTypeScriptCommonJS近 30 天下载 5060
原始使用文档

@haneinfo/domain-events

Transaction-bound domain event recording and database-backed delivery for Haneinfo Apps. See the Prisma model pattern for the App-owned schema and drift checks.

Register stable handlers with DomainEventRegistry. Call DomainEventsService.record(tx, input) inside the same transaction as the business write; event creation and delivery fanout then commit or roll back together. Handler-key contributors receive that same transaction.

The dispatcher claims bounded batches with PostgreSQL FOR UPDATE SKIP LOCKED. Each claim has a unique lease, and completion compares that lease so a stale worker cannot overwrite another claim or an administrator's decision. Delivery is at least once: retries and stale-lock recovery may repeat external effects, so handlers must be idempotent.

Resolver and handler errors use the same per-delivery classification. Ignored errors become IGNORED, terminal errors become DEAD_LETTER, and other failures retry with bounded backoff until maxAttempts. An absent handler is ignored. A resolver failure does not stop later deliveries in the claimed batch. Disabled integration bindings remain pending without consuming attempts.

DomainEventsModule.forRoot({ dispatcher }) accepts dispatcher options. Environment-based configuration is also available through dispatcherOptionsFromEnvironment(). Use autoStart: false for explicit test/operator ticks. Stopping the dispatcher clears its poll timer; handlers already in progress remain responsible for finishing safely. Polling intervals must be integers from 1 through 2,147,483,647 milliseconds. Invalid environment intervals use the default; invalid direct options fail at startup. Explicitly undefined options retain their defaults, including auto-start.

Integration events pin their payload schema, binding and digests when recorded. Webhook helpers validate destinations and signatures; inbound receipt processing joins the business transaction. Do not put secrets in event payloads or handler errors.

Dispatcher shutdown

The dispatcher stops accepting ticks at shutdown and waits for an active batch. shutdownTimeoutMs defaults to 30000 and accepts integers from 1 to 2147483647. A timeout logs a warning and does not cancel the batch or an external handler.

版本与发布记录

@haneinfo/domain-events 共发布 36 个版本,首次发布于 2026/10/02;过去 12 个月发布了 36 个版本。

版本发布日期距今
11.1.8latest2026/11/17今天
11.1.72026/11/161 天前
11.1.62026/11/0412 天前
11.1.52026/11/0214 天前
11.1.42026/11/0115 天前
11.1.32026/10/3017 天前

关于 @haneinfo/domain-events 的常见问题

如何安装 @haneinfo/domain-events?

在项目目录运行 npm install @haneinfo/domain-events,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^4.4.0)、@nestjs/core(^11.0.0 || ^12.0.0)、@nestjs/common(^11.0.0 || ^12.0.0)、@prisma/client(^6.19.0 || ^7.10.1)、@haneinfo/common(^0.6.1 || ^0.7.0)、@haneinfo/plugin-host-nest(^2.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@haneinfo/domain-events 支持 TypeScript 吗?

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

@haneinfo/domain-events 支持 ESM 还是 CommonJS?

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

@haneinfo/domain-events 可以商用吗?

@haneinfo/domain-events 使用 UNLICENSED 许可。作者声明为 UNLICENSED,即不授予公开使用许可(与公共领域的 Unlicense 不同)。使用前需获得作者授权。以上为概括,不构成法律意见,请以许可原文为准。

@haneinfo/domain-events 的下载量有多少?

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

@haneinfo/domain-events 还在维护吗?

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