@bare-ts/tools

中文文档
0.19.0发布于 2026/01/27MITES Module零依赖构建来源已验证近 30 天下载 1.1万

Compiler for Binary Application Record Encoding (BARE) schemas

原始使用文档
文档目录3 节
  1. Getting started
  2. Why BARE?
  3. Why bare-ts?

bare-ts

A TypeScript code generator for the BARE binary format

NPM package bundle size - minified and gzipped Coverage

Binary Application Record Encoding (BARE) is a schema-based binary format that favors compactness and composability. @bare-ts/tools provides a compiler to generate Typescript and JavaScript codes from a BARE schema.

Warning: BARE specification is currently an IEF draft. The specification is now pretty stable. However, it may still evolve before its final release.

Getting started

@bare-ts/tools NPM version @bare-ts/lib NPM version

First, install @bare-ts/tools and @bare-ts/lib:

npm install --save-dev @bare-ts/tools
npm install @bare-ts/lib
  • @bare-ts/tools enables to generate decoders and encoders from a schema

  • @bare-ts/lib provides basic decoders and encoders

Alternatively, you can download a bundled and executable version of @bare-ts/tools named bare in the section Assets of every release on GitHub.

Then, write a schema:

type Gender enum {
    FEMALE
    FLUID
    MALE
}

type Person struct {
    name: str
    email: str
    gender: optional<Gender>
}

type Organization struct {
    name: str
    email: str
}

type Contact union { Person | Organization }

type Contacts list<Contact>

Compile your schema into code:

bare schema.bare --out=code.ts

Once the code is generated, encode and decode messages:

import { Gender, decodeContacts, encodeContacts } from "./code.js"
import { strict } from "node:assert"

const contacts = [
    {
        tag: "Person",
        val: {
            name: "Seldon",
            email: "[email protected]",
            gender: Gender.Male,
        },
    },
]

const payload = encodeContacts(contacts)
const contacts2 = decodeContacts(payload)

strict.deepEqual(contacts, contacts2)

Refer to our types documentation page to find the correspondence between BARE types and TypeScript types, as well as how some CLI options affect this.

Why BARE?

Compact messages: in contrast to BSON, CBOR, and MessagePack, BARE messages do not embed schema information.

Bijective encoding when possible: most of BARE values have a single binary representation. This makes easier the support of use-cases such as message deduplication.

Focus on modern platforms: messages are octet-aligned and use little-endian representation.

Simple: in contrast to Protocol Buffer and Flat Buffer, BARE doesn't constrain its binary format to support schema evolution. Protocol Buffer embeds metadata in every message and makes optional every field. BARE recommends using a tagged union as message type to support backward compatibility.

Why bare-ts?

Pragmatic error reporting: bare-ts distinguishes recoverable errors from API misuses. Decoders may emit recoverable errors (BareError) and provide enough information to understand why the message is malformed. An API misuse emits an AssertionError. AssertionError are only emitted when the development exports condition is set or when the NODE_ENV environment variable is set to development. Moreover, bare-ts assumes the use of TypeScript that reduces the number of API misuses to check.

Optimized bundle size: bare-ts adopts functional and procedural programming styles. This enables to take advantage of modern dead-code elimination techniques, such as tree-shaking. Using bundlers such as ESbuild, Rollup, or Webpack, your bundle contains only the functions which are actually used.

Generation of efficient code bare-ts takes care to generate code that modern JavaScript engines may optimize.

版本与发布记录

@bare-ts/tools 共发布 22 个版本,首次发布于 2022/01/04;过去 12 个月发布了 1 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.19.0latest2026/01/279 个月前
0.18.02025/10/271 年前
0.16.12025/10/131.1 年前
0.17.12025/10/131.1 年前
0.17.02025/05/041.5 年前
0.16.02024/11/022 年前

关于 @bare-ts/tools 的常见问题

@bare-ts/tools 是什么?

Compiler for Binary Application Record Encoding (BARE) schemas

如何安装 @bare-ts/tools?

在项目目录运行 npm install @bare-ts/tools,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bare-ts/lib(>=0.5.0)、typescript(>=5.7.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。它还提供命令行工具 bare,可以用 npx bare 直接运行。

@bare-ts/tools 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bare-ts__tools 是否存在。

@bare-ts/tools 支持 ESM 还是 CommonJS?

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

@bare-ts/tools 需要什么版本的 Node.js?

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

@bare-ts/tools 可以商用吗?

@bare-ts/tools 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@bare-ts/tools 的下载量有多少?

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

@bare-ts/tools 还在维护吗?

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