@altnovatrail/contracts

中文文档
0.9.7发布于 2026/11/08Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 3187

The code of NovaTrail's API contracts for TypeScript, which protoc-gen-es generates from their protobuf files: the messages and enums of each contract, with their descriptors, for @bufbuild/protobuf and Connect.

原始使用文档
文档目录4 节
  1. Test vectors
  2. Versions
  3. Checking the archive
  4. License

@altnovatrail/contracts

The code of NovaTrail's API contracts for TypeScript: the messages and enums of each contract, with their descriptors, for protobuf-es and Connect. The contracts are the protobuf files under contracts/ in altnovatrail/spec, and their text is contracts/README.md. protoc-gen-es generates this code from them: JavaScript with its declarations. Go code takes the same contracts from the Go module github.com/altnovatrail/spec/contracts, at the tag contracts/vX.Y.Z of the same number.

Each file of code is exported by its path, the path of its .proto file with _pb.js in the place of .proto:

import { create, fromJson, toJson } from "@bufbuild/protobuf";
import { ObservationSchema, Unreadable } from "@altnovatrail/contracts/novatrail/observation/v1/observation_pb.js";

const observation = fromJson(ObservationSchema, json);
const written = toJson(ObservationSchema, observation, { useProtoFieldName: true });

The code imports the runtime of protobuf-es, @bufbuild/protobuf, which the package depends on at the exact version of protoc-gen-es that wrote it. Take the runtime at that version too, or let npm install it with the package.

JSON of a contract names each field by its protobuf name, in snake case, as the files of spec do: whatever writes it passes useProtoFieldName: true to toJson. A reader takes both the protobuf name and the lowerCamelCase one, as fromJson does (the contracts' text, section 6). The package has no types of JSON: protoc-gen-es would spell them in lowerCamelCase.

The package is read through its exports, under "moduleResolution": "nodenext", "node16" or "bundler". spec checks its declarations with TypeScript 7 under both, strictly, and runs its code under Node.

Test vectors

The package carries the test vectors of the rules that the device and the eval runner share — how a history of writing folds, the groups of strokes, the crop, which strokes a box of a model snaps to and which box of a workbook a stroke fills (the contracts' text, section 12) — each exported by its path, as JSON:

import { fromJson } from "@bufbuild/protobuf";
import { HistorySchema } from "@altnovatrail/contracts/novatrail/eval/v1/sample_pb.js";
import groups from "@altnovatrail/contracts/vectors/eval/v1/groups.json" with { type: "json" };

for (const one of groups.cases) {
  const history = fromJson(HistorySchema, one.history);
  // fold the history, make its groups, and compare them with one.visible, one.groups, ...
}

Their messages are written with the protobuf names and every field, and a reader takes each with the schema of its message from this package's code. Code that follows the rules passes every case. The vectors of the observation are in the Go module alone: TypeScript gives no verdict.

Versions

The package's version is the tag of the release of altnovatrail/spec it comes from, without its v: 0.7.0 is v0.7.0. Every release from the line 0.7 on carries one, even when the contracts have not changed. Take it at an exact version, the same tag as the spec submodule and the Go modules of spec you hold, and move all of them together. Leave it out of Dependabot, as the Go modules: a release of spec comes out with each change of its documents. Dependabot's ignore matches a dependency by the name the manifest gives it, @altnovatrail/contracts here, and github.com/altnovatrail/spec/contracts for the Go module.

Within a contract's package — its last part, v1 — a release only adds. A change that breaks it comes as a new package, v2, beside the old one, in a new line of spec (the contracts' text, section 2).

Checking the archive

The archive in npm is the file altnovatrail-contracts-<version>.tgz of that release, which the release signs with cosign and whose attestation names it. A NovaTrail repository lets the package into its code only once spec's release-verify-npm has accepted its lock file, in CI of the pull request that changes it (decision R77 of spec; RULES.md, Hard rules). It runs from the repository's spec submodule:

just -f spec/justfile release-verify-npm package-lock.json

For this package, it downloads the archive from the registry and checks it against Sigstore's trust root and the cosign bundle of the file of the same name in the release of altnovatrail/spec. The archive must be signed by spec's own .github/workflows/release.yml on main, and is tied to its tag by the version its package.json holds. Last, the lock file's integrity must be the hash of the bytes so checked. A single archive, with its bundle beside it, is checked by just -f spec/justfile release-verify spec v0.7.0 altnovatrail-contracts-0.7.0.tgz.

The release's attestation ties the archive to the release, not to a commit, and gh release verify-asset checks it apart:

npm pack @altnovatrail/[email protected]
gh release verify-asset v0.7.0 altnovatrail-contracts-0.7.0.tgz -R altnovatrail/spec

The release publishes that file to npm itself, by trusted publishing, and npm gives each version it publishes that way a provenance attestation. The provenance names .github/workflows/release.yml of altnovatrail/spec and the commit of the run that published it, which is the tip of main when the run began rather than always the commit the release was cut from. 0.7.0 was published by hand and has no provenance. A release whose run did not publish its version — one that came out before the release published this package, or one whose publish failed and was not run again — has none in npm, so take a tag whose version is there.

License

Apache-2.0. The runtime, @bufbuild/protobuf, is under Apache-2.0 and BSD-3-Clause.

版本与发布记录

@altnovatrail/contracts 共发布 25 个版本,首次发布于 2026/11/03;过去 12 个月发布了 25 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.9.7latest2026/11/08今天
0.9.62026/11/07今天
0.9.52026/11/07今天
0.9.42026/11/07今天
0.9.32026/11/071 天前
0.9.22026/11/043 天前

关于 @altnovatrail/contracts 的常见问题

@altnovatrail/contracts 是什么?

The code of NovaTrail's API contracts for TypeScript, which protoc-gen-es generates from their protobuf files: the messages and enums of each contract, with their descriptors, for @bufbuild/protobuf and Connect.

如何安装 @altnovatrail/contracts?

在项目目录运行 npm install @altnovatrail/contracts,或使用 pnpm add / yarn add / bun add。

@altnovatrail/contracts 支持 TypeScript 吗?

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

@altnovatrail/contracts 支持 ESM 还是 CommonJS?

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

@altnovatrail/contracts 可以商用吗?

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

@altnovatrail/contracts 的下载量有多少?

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

@altnovatrail/contracts 还在维护吗?

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