@balena/pinejs

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


原始使用文档


npm version

Pine.js is a sophisticated rules-driven API engine that enables you to define rules in a structured subset of English. Those rules are used in order for Pine.js to generate a database schema and the associated OData API. This makes it very easy to rapidly create, update and maintain a backend while keeping the logic in an easily understood form, as well as providing the ability to update and maintain this logic going forward.

Rules are described in SBVR format, which stands for "Semantics of Business Vocabulary and Business Rules". SBVR provides a way to capture specifications in natural language and represent them in formal logic, so they can be machine processed.

The basic components of SBVR are as follows:

  • Terms - these are the atomic elements of your data model, defined via Term: [Term Name]. Generally speaking, these map to tables in a relational database, or attributes of other tables.
  • Fact Types - these define relations between different terms and properties of those terms, e.g. Fact type: pilot can fly plane or Fact type: pilot is experienced - these somewhat map to fields and foreign keys in a relational database.
  • Rules - these define logical constraints on the data model and is the most powerful aspect of SBVR and Pine.js itself. Rules map loosely to constraints in a relational database, but extend them to constraints that can traverse tables and generally be far more powerful than a database constraint. E.g. Rule: It is obligatory that each pilot can fly at least 1 plane. The expressive capability of SBVR rules is much more than simple SQL DDL, and has the full power of First Order Logic.

In order to get an idea of how SBVR works, visit the sbvr lab, and for more details, check out the SBVR spec.

As part of the @balena/pinejs package the following tools are installed:

  • sbvr-compiler: Can be used to compile SBVR via the SBVR chain into SQL, eg npx sbvr-compiler test.sbvr
  • odata-compiler: Can be used to compile an OData URL via the OData chain from to SQL, eg npx odata-compiler test.sbvr /test

Both tools use some of the main dependencies of Pine.js:

  • abstract-sql-compiler
  • lf-to-abstract-sql
  • sbvr-parser
  • odata-parser
  • odata-to-abstract-sql

The above packages are written in OMeta and compiled into Javascript. The following resources consitute a good starting point in order for someone to get a better understanding of OMeta and the above dependencies:

The following papers are also helpful in understanding the main concept of Pine.js:

The documentation inside /docs folder also provide a great overview of the main concepts of Pine.js, in particular:

  • docs/Migrations.md: provides information regarding sql queries or Javascript functions that are executed prior to pinejs executing a given SBVR model.
  • docs/Hooks.md: functions that you can implement in order to execute custom code when API calls are requested.
  • docs/ProjectConfig.md: provides information regarding creating and configuring a project.
  • docs/Types.md: types definitions and declarations in various systems.
  • docs/sequence-diagrams/: provide a great overview of how the main processes are executed, including OData request parsing, response processing, etc. (The sequence diagrams can be depicted in websequencediagrams.com)

One can experiment with Pine.js, its main dependencies and the above tools inside the development environment of balena.

Where to go from here:

Start by creating your very first application with Pine.js. Jump to the Getting Started guide.

Storing files and other large objects

An application can choose between two types to save file content or another large object: File or WebResource. When using a File, PineJS saves the content in the database using a binary data type like BYTEA or BLOB. When using a WebResource, PineJS saves the binary content on an external storage service and then writes metadata, including the content public URL, to the database. Client apps use the WebResource href to get the content.

Please note that WebResource is still a work in progress and as such has a few limitations. Such as (but not exclusively):

  • Filtering for specific filenames or size
  • Deletion of a file may fail and will require to manually delete the file from its storage

版本与发布记录

@balena/pinejs 共发布 2,585 个版本,首次发布于 2020/06/05;过去 12 个月发布了 566 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
25.0.8latest2026/11/11今天
25.0.8-build-begin-upload-zod-745e521cc8871a615841a159246a2abfb23114df-12026/11/11今天
25.0.8-build-fix-default-mysql-database-url-31777b8e2231692b0ef633ad7bdb390ba351e328-12026/11/11今天
25.0.8-build-renovate-patch-minio-d38e53cf37e84715e9851a15af4bf3cc08e138b5-12026/11/11今天
25.0.8-build-renovate-node-24-x-f12f4daa5b053fcb1cb2f3d792802bd301345d71-12026/11/11今天
25.0.8-build-renovate-pinejs-client-supertest-4-x-7801c355841f88976d3ede0526b0b7bb9dd950f2-12026/11/11今天

其他发布通道:build-compile-auth-29ad1af97ec6474f6930c928317468d7bf8b2905 → 19.1.0-build-compile-auth-29ad1af97ec6474f6930c928317468d7bf8b2905-1,build-compile-auth-05e7d20d315e0152fb83620384f8b01f7dae644d → 19.1.0-build-compile-auth-05e7d20d315e0152fb83620384f8b01f7dae644d-1,build-compile-auth → 19.1.0-build-compile-auth-b1f5bf70c598872417ff46c160c9efcb11f24828-1,build-add-tasks-worker-stop → 19.2.0-build-add-tasks-worker-stop-f9a85d7b6325c1d29750acb35a8eceb3861e9d3d-1,build-TEST-MOCK-ONLY-DEBUG → 19.3.0-build-TEST-MOCK-ONLY-DEBUG-6b7781dc03c946faa1095def2bc44dcad588bce9-1,build-expose-check-api-key → 19.4.0-build-expose-check-api-key-28be0bbd4d3b1c7e5bc13b3ee8daeac1787cb816-2。

关于 @balena/pinejs 的常见问题

如何安装 @balena/pinejs?

在项目目录运行 npm install @balena/pinejs,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 sbvr-compiler、odata-compiler、abstract-sql-compiler,可以用 npx sbvr-compiler 直接运行。

@balena/pinejs 支持 TypeScript 吗?

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

@balena/pinejs 支持 ESM 还是 CommonJS?

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

@balena/pinejs 需要什么版本的 Node.js?

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

@balena/pinejs 可以商用吗?

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

@balena/pinejs 的下载量有多少?

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

@balena/pinejs 还在维护吗?

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