@codaco/protocol-validation

中文文档
15.0.0发布于 2026/10/13GPL-3.0-or-laterTypeScriptES Module构建来源已验证近 30 天下载 1.6万

Utilities for validating and migrating Network Canvas protocol files.

原始使用文档

@codaco/protocol-validation

This npm package implements methods for validating Network Canvas protocol files against an appropriate JSON schema.

It exports three primary methods for protocol validation:

  1. validateSchema - validates a schema against the JSON schema
const { hasErrors, errors } = validateSchema(schemaJson);
  1. validateLogic - validates the logic of the protocol to ensure there are no inconsistencies. This includes validations that cannot be implemented within the JSON schema.
const { hasErrors, errors } = validateLogic(protocolJson);
  1. validateProtocol - validates the protocol against the schema and logic.
const result = await validateProtocol(protocolJson);
if (result.success) {
  // protocol is valid, validated data available in result.data
} else {
  // protocol is invalid
  // result.error contains the Zod error
  console.error(result.error);
}

It also exports several utility methods for managing protocol validation.

  1. migrateProtocol - migrates protocols from one version to another
const migratedProtocol = migrateProtocol(8, protocolJson);
  1. canUpgrade - checks if protocol can be upgraded from one schema version to another
const canProtocolUpgrade = canUpgrade(7, 8);
  1. getMigrationNotes - returns migration notes on the changes between a source schema version and a target schema version.
const migrationNotes = getMigrationNotes(7, 8);
  1. getVariableNamesFromNetwork - returns variable names from an external network data source
const variableNames = getVariableNamesFromNetwork(network);
  1. validateNames - validates variable names to ensure they only contain letters, numbers, and the symbols ._-:
const validationResult = validateNames(variableNamesArray);

版本与发布记录

@codaco/protocol-validation 共发布 55 个版本,首次发布于 2023/10/09;过去 12 个月发布了 33 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
15.0.0latest2026/10/1327 天前
14.0.02026/09/291 个月前
13.0.12026/09/022 个月前
13.0.02026/08/312 个月前
12.1.12026/08/112 个月前
12.1.02026/07/313 个月前

其他发布通道:alpha → 11.4.0-alpha.0。

关于 @codaco/protocol-validation 的常见问题

@codaco/protocol-validation 是什么?

Utilities for validating and migrating Network Canvas protocol files.

如何安装 @codaco/protocol-validation?

在项目目录运行 npm install @codaco/protocol-validation,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 @codaco/protocol-validation,可以用 npx @codaco/protocol-validation 直接运行。

@codaco/protocol-validation 支持 TypeScript 吗?

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

@codaco/protocol-validation 支持 ESM 还是 CommonJS?

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

@codaco/protocol-validation 可以商用吗?

@codaco/protocol-validation 使用 GPL-3.0-or-later 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以 GPL-3.0 兼容许可开源,并附带专利与反锁定条款。仅内部使用不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@codaco/protocol-validation 的下载量有多少?

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

@codaco/protocol-validation 还在维护吗?

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