@cruba/crubal

中文文档
0.3.77发布于 2026/11/09Apache-2.0TypeScriptES Module零依赖近 30 天下载 9422

The CRUBAL reference implementation: read, print, check and run CRUBAL, a language and engine for data about any kind of thing.

原始使用文档

@cruba/crubal

The CRUBAL reference implementation. Pure functions, JSON in and JSON out, so a compiled core can replace the internals later behind the same API.

Level reached: Views, every chapter of the spec (1–14). Conformance claim: CRUBAL 2 · Views · corpus 2026-10-19 (the gate, 2026-10-19; CLAIM.md).

  • Reader: the text form and JSON both ways, facet types, unknown keys kept exactly, plain-words refusals with line numbers.

  • Dictionary: full definitions, publish checks on facets and classes, resolution by meet, alias and unit folding, value checks against facets and worn classes.

  • Rules: rule blocks and facet shortcuts, publish checks (layered by address, no contradictions, one spelling), and an engine that runs writes in order: refused, held, filled (including a failing gate's -), derived (templates with ?? and ?, rollups), flagged, incomplete, complete and completeness, with value-state tests and global uniqueness.

  • Store: hash-linked logs with redaction, intake through receive contracts (map, value maps, aliases, shapes, ignore, keep-raw; raw bytes and their hash kept), landing by the trust order with alternatives, matching parts before minting rows, evidence validation (independent witnesses, vetoes, version-split proposals), and migration recipes with restamping and a review queue.

  • Exchange: contract publish checks (parts per kind, defined facets, real values in value maps, credentials as names only), runs in steps (who with roles, needs, map out with nested paths, value maps and literals, act once per payload), receive runs that compare with the record and land by trust or as suggestions, offer and take where only the overlap flows and a person's values are never overridden, border wrappers verified against the presenter's key and its log, and package checks (prefixes, trust entries, extending without changing).

  • Views: shapes as maps into slots (addresses, aggregates over lower levels, templates, required slots), views with selection, context (of), pins, hides, order and pages, filters as sub-indexes with range and value buckets and counts that follow the other picks, indexable landing pages, audiences and shown to rules (new and unknown values never public), roles that narrow an audience, the portable shape, and read sets that decide which rows a write makes stale.

  • The backbone (chapters 1.12, 8.5, 9.2a, 10.7, 12.6, 14): the log as effects, rebuild from the log alone, define writes for the working package, and the journal that makes entries the only way state changes (log.ts); arrival with bindings and strong and weak keys (arrival.ts); folded and owned keys with attach, detach, archive, merge and instructions (lifecycle.ts); owners, edges, modes, the grantor chain, permission menus, gates and emergency access (access.ts); partitioned views, the projection stream and stream subscriptions with cursors and resets (views.ts, exchange.ts); the record set every module reads through, so a backend that loads only what an operation needs can stand in for the memory one (records.ts, docs/design/store.md); a package as one JSON document, printed back to the text form so the text readers stay the one parser, hashed and signed (bundle.ts), and cut as a version with members by diff, the change classifier of 4.8 and 5.11 and the recipe requirement (publish.ts, crubal publish; docs/design/publishing.md); review decisions as writes, each one entry with the define, value or release it causes (review.ts); a held value coming back when its verdict changes again; adopt, give back, clone and split (lifecycle.ts); a measurement contract landing observations, the first filling an empty value, and the version split proposed at the threshold, never made (exchange.ts, proposeSplit in store.ts); hand-made lists (select: list: over the core facet crubal:items), page shapes whose slots hold other views run with the page's record as context, dependent counts inside a filter's buckets, further shapes under shapes and the core crubal:jsonld structured data for the public (views.ts); offer and take by the offer's mode: dump copies once, observed stores a link and no value, gathered takes the presenter's updates over its own earlier values and never over the consumer's, controlled copies under the presenter's terms (expires, reshare, revocable) and withdraws what the presenter stops giving; an offer builder and an expiry sweep (exchange.ts); a person's arrival owned domain:id when the package lets a person own that kind (14.1); dated keys, keyFor picking the key whose span holds an entry's moment (11.7); a form as data from a contract's needs, the record's answers and states and the caller's edges (forms.ts, docs/design/index-and-forms.md); and a border that consults access, journals every run, and grants a consumer's edge (exchange.ts).

A run applies the rules (7.4 step 6): a value a must rule won't have is parked as a contradiction citing the rule and never lands, a suggest fills and a derivation lands with origin: derived and the rule as its via, a changed verdict holds, and each is a logged effect.

It passes every corpus folder (198 cases; crubal claim <corpus> --out CLAIM.md runs every level and writes the claim, 13.3). The corpus and this package name no adopter and no third party: test.example owns the data, market: stands for any marketplace, bench for any in-house tool, and product, unit and the like are the test package's own kinds, never the core's.

Store also checks Ed25519 signatures against the owner's published key, replays intake records from their kept bytes (deterministically, keeping earlier outcomes), reviews unknown and new values by key across all records and proposes candidate facets by recurrence, keeps non-UTF-8 payloads as base64, and lands values by the package's own trust order and facets' orders.

npm test                                   # unit tests and the Reader corpus
node bin/crubal.ts test ../../corpus --level views   # the corpus runner, case by case
node bin/crubal.ts read data.crubal --defs facets.crubal
node bin/crubal.ts print data.json --defs facets.crubal [--plain]

Needs Node 23.6 or later (it runs the TypeScript directly).

FileDoes
src/tree.tslines, comments, indentation, the pair separator (chapter 2.1)
src/lex.tsquoting, details and short lists (2.5–2.7)
src/defs.tswhat the Reader needs from definitions: types, how many, units, rows, levels (4.2, 4.5, 11.2)
src/read-text.tstext to the JSON form (2, 3)
src/print-text.tsthe JSON form to canonical text (2.9)
src/canonical.tscanonical JSON with sets sorted (3.9)
src/dictionary.tsdefinitions as JSON, publish checks, resolution, folding, value checks (4, 5)
src/conditions.tsconditions with three-valued empties (6.3)
src/units.tsa starter units table, until the standard units package exists
src/rules.tsrules, shortcuts, rule-set checks and the write engine (6)
src/store.tslogs, receive contracts and intake, landing and trust, part matching, evidence (8, 9)
src/migrate.tsmigration recipes, checks and restamping (10)
src/exchange.tscontract checks, runs, offer and take, borders (7, 8.5.1)
src/packages.tspackage files: prefixes, trust entries, extending (11)
src/views.tsshapes, views, filters, audiences and roles, projections and staleness (12)
src/corpus.tsthe conformance runner (13)

Next: make the repo public, publish @cruba/crubal, and start crubal.com.

版本与发布记录

@cruba/crubal 共发布 51 个版本,首次发布于 2026/10/15;过去 12 个月发布了 51 个版本。

版本发布日期距今
0.3.77latest2026/11/091 天前
0.3.762026/11/092 天前
0.3.752026/11/092 天前
0.3.742026/11/092 天前
0.3.732026/11/082 天前
0.3.722026/11/082 天前

关于 @cruba/crubal 的常见问题

@cruba/crubal 是什么?

The CRUBAL reference implementation: read, print, check and run CRUBAL, a language and engine for data about any kind of thing.

如何安装 @cruba/crubal?

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

@cruba/crubal 支持 TypeScript 吗?

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

@cruba/crubal 支持 ESM 还是 CommonJS?

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

@cruba/crubal 需要什么版本的 Node.js?

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

@cruba/crubal 可以商用吗?

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

@cruba/crubal 的下载量有多少?

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

@cruba/crubal 还在维护吗?

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