@arxo/law-types

中文文档
0.3.4发布于 2026/10/16Apache-2.0TypeScriptES Module零依赖近 30 天下载 2218

TypeScript types for Arxo Law Core 0.1, generated from the normative JSON schemas (legal IR, evaluation documents, diagnostics, lockfiles, decision tables, queries), plus the machine-readable registry of LDC diagnostic codes. Types only: no runtime engine

原始使用文档
文档目录8 节
  1. Install
  2. Use
  3. Where these types come from
  4. Diagnostic codes
  5. Match on the code, not on the message
  6. Versioning
  7. License
  8. Building from source

@arxo/law-types

TypeScript types for Arxo Law Core 0.1: the legal IR (CLIR), evaluation documents, diagnostics, package manifests, lockfiles, decision tables, parameter datasets, queries and the rest of the normative document model.

Types only. No runtime engine, no dependencies, one small generated runtime module for the diagnostic-code registry. To actually run law, use @arxo/law-engine; these are the same types it ships, published separately so a consumer that only talks to the engine over a wire does not have to pull 4.5 MB of WebAssembly.

Install

npm install --save-dev @arxo/law-types

Use

import type { EvaluationDocument, Diagnostic, LegalIr } from '@arxo/law-types';

function firstIssue(doc: EvaluationDocument) {
  return doc.issues?.[0];
}

Where these types come from

They are generated, never hand-written. The normative JSON schemas define the shape of every document; a code generator turns them into TypeScript, and automated checks verify that the schema directory, the generator's registry, the generated files and this package's build list agree. A schema change that does not reach the types fails the build rather than shipping a lie.

Where a schema uses conditional composition (allOf / if-then) the generated type is deliberately wide and says so in a comment. A type whose precision was not derived must be visible, not pretend to be exact.

Diagnostic codes

import type { LawDiagnosticCode } from '@arxo/law-types/diagnostics';
import {
  KNOWN_DIAGNOSTIC_CODES,
  isKnownDiagnosticCode,
} from '@arxo/law-types/diagnostics';

KnownDiagnosticCode is the union of every LDC-… code collected from the two engine implementations and from the specification prose. Four classes are distinguished in the registry the union is built from:

  • emitted — at least one implementation actually produces this code;
  • documented — the specification names it, no implementation emits it yet;
  • reserved — named only by a companion document; the LDC-E8xxx range is reserved for proposals that are not yet part of conformance.

The consumer-facing type is deliberately open:

export type LawDiagnosticCode = KnownDiagnosticCode | (string & {});

Codes are additive — the frozen 0.1 semantics grows by addition — so an engine newer than this package will legitimately answer with a code the union has never heard of. A closed enum would reject that answer, which would be a lie about the engine, not a check on it. string & {} keeps editor autocompletion for the known codes while accepting the unknown one. For the same reason isKnownDiagnosticCode(code) === false means "not known to this package version", never "not a real code".

Match on the code, not on the message

Engine messages are Russian, and their exact text is part of a byte-level contract between two independent implementations of the same semantics — it cannot be translated on one side without breaking the contract. The stable, language-independent handle for a static diagnostic is its code:

// yes
if (diagnostic.code === 'LDC-E1104') { … }

// no — this string is a contract between two engines, not an API
if (diagnostic.message.includes('пакет')) { … }

If you are building a user-facing product, map codes to your own localized strings rather than passing engine text through. The same holds for the doc comments in the generated types: they carry the schemas' Russian prose, because the schemas are the normative source and translating them here would create a second, unchecked description.

Versioning

Independent semver per package, with the engine and the client versioned separately. 0.x releases pin exact compatible versions of sibling packages.

License

Apache-2.0. See LICENSE and NOTICE.

Building from source

In a source checkout:

npm run build -- --public --package-out /tmp/new-law-types-package

The build copies the prepared generated types and the public diagnostic registry; it does not run Cargo or regenerate schemas.

The registry also supports historical codes retired by a recorded change. Structural types describe document formats; their presence does not promise that every operation producing that format is in this distribution.

版本与发布记录

@arxo/law-types 共发布 18 个版本,首次发布于 2026/09/14;过去 12 个月发布了 18 个版本。

版本发布日期距今
0.3.4latest2026/10/1622 天前
0.3.32026/10/1425 天前
0.3.22026/10/1326 天前
0.3.12026/10/1226 天前
0.3.02026/10/1227 天前
0.2.112026/10/1028 天前

其他发布通道:next → 0.2.0。

关于 @arxo/law-types 的常见问题

@arxo/law-types 是什么?

TypeScript types for Arxo Law Core 0.1, generated from the normative JSON schemas (legal IR, evaluation documents, diagnostics, lockfiles, decision tables, queries), plus the machine-readable registry of LDC diagnostic codes. Types only: no runtime engine

如何安装 @arxo/law-types?

在项目目录运行 npm install @arxo/law-types,或使用 pnpm add / yarn add / bun add。

@arxo/law-types 支持 TypeScript 吗?

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

@arxo/law-types 支持 ESM 还是 CommonJS?

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

@arxo/law-types 需要什么版本的 Node.js?

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

@arxo/law-types 可以商用吗?

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

@arxo/law-types 的下载量有多少?

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

@arxo/law-types 还在维护吗?

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