@drzl/validation-core

中文文档
3.23.0发布于 2026/08/14Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 3340
原始使用文档

@drzl/validation-core

CI npm

Shared interfaces and helpers used by validation generators.

💚 Sponsor DRZL

DRZL is crafted nights & weekends. Sponsorships keep the generators fast, tested, and free.

Sponsor DRZL

  • Every dollar speeds up CI hardware and offsets long test runs on my aging laptop.
  • Sponsors get roadmap input and priority responses in GitHub Issues.
  • Prefer a quick overview? The current goals and thank-yous are at https://use-drzl.github.io/drzl/sponsor.

Exports (essentials)

  • ValidationLibrary: 'zod' | 'valibot' | 'arktype' | 'typebox'
  • ValidationRenderer
    • library
    • renderTable(table, opts)
    • renderIndex?(analysis, opts)
  • Helpers
    • insertColumns(table), updateColumns(table), selectColumns(table)
    • formatCode(code, filePath, formatOpts)
  • File names (shared by every generator that writes a file and a barrel)
    • moduleFileName(tsName, fileSuffix) -> users.zod.ts
    • moduleSpecifier(tsName, fileSuffix, importExtension?) -> ./users.zod.js, the specifier a sibling module needs to import that file.
    • importSpecifier(relativePath, importExtension?) does the same for a path a generator already has in hand, e.g. ./types/users.ts -> ./types/users.js.
    • Both read the same fileSuffix, so a barrel can never name a file that was not written.
    • ImportExtension is 'js' | 'none' | 'ts', defaulting to DEFAULT_IMPORT_EXTENSION ('js'). 'js' is the only form that resolves under bundler, node10, node16 and nodenext, in both CommonJS and ESM, with no compiler flag. 'none' is the pre-2.0 output and misses node16/nodenext ES modules. 'ts' needs allowImportingTsExtensions. .mts and .cts become .mjs and .cjs under both 'js' and 'none', since an extensionless specifier never resolves to them.
  • CHECK constraints (shared by every generator that reads them)
    • parseCheck(expression, name) -> the parts of a CHECK that can be stated with certainty: column comparisons, BETWEEN, IN (...), top-level AND, length()/char_length(), octet_length(), cardinality()/array_length(col, 1), and comparisons between two columns. A negation, an unrecognised function call and a regex match are all refused whole rather than half-applied, and a disjunction is read only where the whole of it pins one column to a set.
    • lengthMeasure(column, check) -> how to answer a count on a given column, as one of 'codePoints', 'utf8Bytes' or 'byteLength', or nothing where no expression answers it. The unit is on the check and the answer needs the column too: measured on PostgreSQL 17.5, length() is the character count on a text and the byte count on a bytea, and char_length(bytea) is not a function that exists. measureExpression(measure, variable) renders it and lengthCheckLabel(check) renders the message the ledger keys on.
    • COLUMN_FORMATS -> patterns for the column formats that are expressible, which is a short list: Postgres accepts today, January 8, 1999 and allballs, so a date or time pattern would reject rows the database takes. numeric is Postgres's numeric input grammar, and pgBigint/mysqlBigint are the two answers a bigint({ mode: 'string' }) column has, since Postgres parses that text as an integer literal (0x1f and 1_000 included) and MySQL parses it as a decimal number it then rounds (12.5 becomes 13). Each was measured against its own server; neither states the magnitude, and the entry says why.
    • CODEPOINT_LENGTH -> [...v].length, since varchar(n) counts characters and JavaScript's .length counts UTF-16 units. All four generators use it.
    • isIntegerColumn(c)
  • Constraints as data (shared by the generators that emit a ledger)
    • tableConstraints(table) -> every CHECK, unique constraint, primary key and foreign key on a table, each with a stable id, the columns it names, the rule as a sentence, whether a generated schema enforces it, and, where it does, the exact message it attaches. A folded numeric CHECK carries its bounds and a folded IN list its values, because those are what is left to match on once the library writes the failure message itself.
    • classifyTableChecks(table) -> the one reading of parseCheck plus the column-shape guards, shared with meta, so "the database also checks this and no schema does" is one answer rather than two.
    • renderConstraintsModule(tables, opts) -> the source of constraints.ts: the data above plus, unless errorMap is false, constraintForIssue(table, issue). Plain objects with no import of any kind, and the matcher reads zod's path items and valibot's alike.
    • resolveConstraints(option) expands the true shorthand; CONSTRAINTS_MODULE is the file name every generator writes it to.
  • Uniqueness
    • renderDuplicateFinder(table, fnName, rowType) -> the source of a function returning the rows in a batch that collide with an earlier row on the primary key or a unique constraint. Plain TypeScript with no reference to any validation library, so every validator generator emits the same one. Null and absent columns skip a constraint, matching SQL, so rows that leave a generated key to the database report nothing on it.
  • Naming (shared by every generator that emits a schema name)
    • resolveAffix({ affix, schemaSuffix }) -> ResolvedAffix
    • schemaName(mode, tsName, resolved), typeName(mode, tsName, resolved)
    • validateAffix(affix, schemaSuffix) -> issues for unusable or colliding names
    • pascalCase(s), applyTableCase(tsName, 'preserve' | 'pascal')
    • Calling resolveAffix() with no options reproduces the original naming exactly, so the generators and the oRPC router can never interpret one config two ways.

版本与发布记录

@drzl/validation-core 共发布 41 个版本,首次发布于 2025/09/06;过去 12 个月发布了 34 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.23.0latest2026/08/142 个月前
3.22.62026/08/113 个月前
3.22.52026/08/113 个月前
3.22.42026/08/113 个月前
3.22.32026/08/113 个月前
3.22.22026/08/113 个月前

关于 @drzl/validation-core 的常见问题

如何安装 @drzl/validation-core?

在项目目录运行 npm install @drzl/validation-core,或使用 pnpm add / yarn add / bun add。

@drzl/validation-core 支持 TypeScript 吗?

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

@drzl/validation-core 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@drzl/validation-core 需要什么版本的 Node.js?

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

@drzl/validation-core 可以商用吗?

@drzl/validation-core 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@drzl/validation-core 的下载量有多少?

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

@drzl/validation-core 还在维护吗?

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