@haneinfo/common

中文文档
0.7.0发布于 2026/11/04UNLICENSEDTypeScriptCommonJS近 30 天下载 5785
原始使用文档
文档目录5 节
  1. Prisma 6 and 7 consumers
  2. HTTP exception envelope
  3. Bounded Form validation errors
  4. Blocked definition publish
  5. Pagination query

@haneinfo/common

Prisma 6 and 7 consumers

PrismaModule without options retains the Prisma 6 behavior. For Prisma 7, import PrismaModule.forRoot({ adapter }) once in the App's platform composition. The App creates its own @prisma/adapter-pg adapter and configures the connection string, pool, timeout and TLS. Remove other bare PrismaModule imports so the configured module owns the single PrismaService. PRISMA_CLIENT_OPTIONS is an explicit optional injection token; no database configuration is inferred or read by this package. PrismaService forwards the options to the consumer-CWD-resolved generated client, and retains connect/disconnect lifecycle hooks.

Publish the compatibility release before upgrading consumer pins. NestJS 11 and Prisma 6 remain supported; the development tree exercises NestJS 12 and Prisma 7. NestJS 12 requires modern Node with require(esm); logger 5 requires Node 22.12+, NestJS 11.0.8+/12.0.2+, Pino 10 and pino-http 11. Prisma 7 still supports the existing prisma-client-js output used by the consumer resolver.

Prisma 7's runtime DMMF omits enums, documentation, field constraints and relation metadata. Add a second generator to the App's schema folder so prisma:generate preserves the complete datamodel alongside the default client:

generator haneinfoMetadata {
  provider = "node ./node_modules/@haneinfo/common/dist/prisma/prisma-generator.js"
  output   = "../../node_modules/.prisma/haneinfo-metadata"
}

The provider is relative to the backend working directory; the output is relative to backend/prisma/schema. PrismaService and the exported Prisma namespace keep using the App's own generated client. For Prisma 7, common loads this JSON through Node resolution and checks its schema hash against the client's embedded schema. Missing, stale or compact metadata fails explicitly. Prisma 6 continues using its original full DMMF. Drift scripts must import Prisma from @haneinfo/common; importing it directly from @prisma/client still gives compact metadata. Generate both artifacts again in a deployed dependency tree; do not copy another App's snapshot.

HTTP exception envelope

GlobalExceptionFilter retains statusCode, message, traceId, timestamp, path and the existing validation-array details behavior. It adds optional code only for a MechanismError-shaped error or a plain HTTP response with the MechanismError.toJSON() code/message shape. The code must match ^[A-Z][A-Z0-9_]{1,63}$ in its entirety, with no trailing line terminator. Recognition does not import plugin-api or invoke an exception serializer. Generic errors and arbitrary coded Error instances do not acquire code. Direct non-HTTP errors retain their existing HTTP 500 handling.

Only the code is projected. Custom exception properties, issues, diagnostic arrays, mechanism details, suggestions and stacks are never copied into the envelope. The existing message and validation-array details contracts are unchanged; UI consumers should translate known codes and display a generic error otherwise, without rendering backend prose. Server-side logging retains its existing behavior.

Apps mounting this filter receive the additive field after upgrading. Custom filters need their own adoption work; plugin-host-nest does not install or duplicate a global exception filter.

Bounded Form validation errors

For INVALID_DATA with HTTP 422, GlobalExceptionFilter projects only details.fieldErrors ({ path, code } entries) from Form diagnostics. JSON Pointers must address /values/, are limited to 300 characters, and the list is limited to 100 entries. Oversized paths or extra entries are dropped and mark details.truncated. Malformed items and codes outside the Form fill allowlist are skipped. Messages, suggestions, values and raw diagnostics are never projected. Other mechanism details retain their existing protection (only revision conflicts and rate limits).

Blocked definition publish

For PUBLISH_BLOCKED with HTTP 409 (@haneinfo/definition-registry), GlobalExceptionFilter projects details.definitions: one entry per blocked definition with its kind, code and reason (invalid for a draft being published, affected for a published definition it would break), and each diagnostic's code and JSON Pointer path only. At most 50 definitions and 100 diagnostics are projected; paths over 300 characters or extra entries are dropped and mark details.truncated. Malformed kinds, codes, diagnostic codes and pointers are skipped. Diagnostic messages and suggestions quote definition content and are never projected.

Pagination query

paginationQuerySchema accepts page from 1 to 10,000, limit from 1 to 100 (default 20) and a search of at most 200 characters; anything outside is a validation error (HTTP 400 through ZodValidationPipe).

版本与发布记录

@haneinfo/common 共发布 6 个版本,首次发布于 2026/10/02;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.7.0latest2026/11/0412 天前
0.6.12026/10/2721 天前
0.6.02026/10/2523 天前
0.5.02026/10/2226 天前
0.4.02026/10/2127 天前
0.3.42026/10/021 个月前

关于 @haneinfo/common 的常见问题

如何安装 @haneinfo/common?

在项目目录运行 npm install @haneinfo/common,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^4.4.0)、express(^5.1.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)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 haneinfo-prisma-metadata,可以用 npx haneinfo-prisma-metadata 直接运行。

@haneinfo/common 支持 TypeScript 吗?

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

@haneinfo/common 支持 ESM 还是 CommonJS?

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

@haneinfo/common 可以商用吗?

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

@haneinfo/common 的下载量有多少?

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

@haneinfo/common 还在维护吗?

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