# @getanthill/datastore 中文文档

规范地址：https://npmcn.com/package/%40getanthill/datastore/

版本：0\.95\.6
npm 元数据更新时间：2026-01-16T10:01:09.818Z
中文译文更新时间：2026-11-16T07:10:11.866Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40getanthill/datastore
原文对照：https://npmcn.com/package/%40getanthill/datastore/?lang=original
项目主页：https://gitlab.com/getanthill/datastore#readme
源码仓库：https://gitlab.com/getanthill/datastore

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：3.5 MB，392 个文件
- 模块格式：CommonJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=16
- 运行依赖：27 个
- peer 依赖：@getanthill/telemetry 1\.12\.1，@shelf/jest-mongodb 4\.x
- 首次发布：2020-11-25T19:59:51.402Z
- 最新版本发布：2026-01-16T10:01:09.642Z
- 近 30 天下载量：2554（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：446（近 12 个月 13 个）

## 中文简介

事件源数据库

## 安装

```sh
npm install @getanthill/datastore
```

也可以使用：`pnpm add @getanthill/datastore`、`yarn add @getanthill/datastore`、`bun add @getanthill/datastore`

## README

# `getanthill` 数据存储器

[![pipeline](https://gitlab.com/getanthill/datastore/badges/master/pipeline.svg?ignore_skipped=true)](https://gitlab.com/getanthill/datastore/-/commits/master) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=getanthill%2Fdatastore&metric=alert_status)](https://sonarcloud.io/dashboard?id=getanthill%2Fdatastore)

[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=getanthill%2Fdatastore&metric=coverage)](https://sonarcloud.io/dashboard?id=getanthill%2Fdatastore) [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=getanthill%2Fdatastore&metric=security_rating)](https://sonarcloud.io/dashboard?id=getanthill%2Fdatastore) [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=getanthill%2Fdatastore&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=getanthill%2Fdatastore)

[![Docker pulls](https://img.shields.io/docker/pulls/getanthill/datastore)](https://hub.docker.com/r/getanthill/datastore) [![npm downloads](https://img.shields.io/npm/d18m/@getanthill/datastore?label=npm)](https://www.npmjs.com/package/@getanthill/datastore)

## 目标

这个项目的目标是提供一个系统,以方便地获取全部电力 [事件来源](https://martinfowler.com/eaaDev/EventSourcing.html) 编号 : [季度调查](https://martinfowler.com/bliki/CQRS.html) 系统.

## 页:1

> [https://datastore.getanthill.org/ 互联网档案馆的存檔,存档日期2013-12-21](https://datastore.getanthill.org/)

## 关键特性

这个 `getanthill` 数据存储器被设计出来,赋予开发者以强大的,可扩展的,可高度可观察的数据管理系统,以现代建筑模式为基础.

**CQRS 事件判定( E)**:作为其核心,Datastore完全拥抱了指令查询责任隔离(CQRS)和事件判定. 将每个数据实体管理成一个不可改变的事件流,能够精确地进行原子更新,将实体历史重建到任何过去状态,以及先进的"时间-旅行"调试.

**与JSON Schema的第一次合同开发**: Datastore内部的所有数据模型都使用JSON Schema标准进行严格的合同化. 这确保了数据的完整性,并为每件信息提供了严格,机器可读的合同,为可靠的API互动和事件处理打下基础.

**OpenAPI 3.0 压缩 API 和自动文档**: 利用其JSON Schema合同, Datastore 自动生成一个 OpenAPI 3.0(原为 Swagger) 规格. 这为您的 RESTful API 提供了全面、最新和互动的文档,简化了整合,并确保了所有消费者的清晰度.

**实时数据流**: 实时处理综合数据 `stream` API出入口. 部署具有自动重联能力的工人,强力模式匹配和内置伐木,从而能够立即对数据变化作出反应.

**灵活消息媒介集成**: Datastore提供与MQTT和RabitMQ(AMQP)等流行消息经纪人的无缝集成. 这样可以灵活地进行事件分布,使先进的同步通信模式和微服务架构成为可能.

**精细访问控制**: 以基于角色的全面访问控制系统来保护您的数据. 四个不同的准入级别(`READ`, (中文(简体) ), `DECRYPT`, (中文(简体) ), `WRITE`, (中文(简体) ), `ADMIN`)允许颗粒许可,保护敏感信息和操作.

**数据加密**: 方便加密数据中的敏感字段,提供强大的数据安全. 该系统支持多键,密钥旋转,以及点播文档加密,确保数据隐私,甚至在休息时.

**高级数据聚合和预测**: 多个数据存储实例的链式复杂数据预测和汇总。 这种强大的管道使业务逻辑、数据转换和事件跟踪成为可能,有利于先进的分析和报告.

**可配置和可观察**: 使 Datastore 适应您的需要, 并设置安全性、 OpenAPI 行为和特性启用的灵活配置选项。 综合遥测和记录可以深入了解系统的运作,简化监测和调试.

## QQ 命令行接口( CLI)

Datastore 提供了强大的命令行接口,用于管理您数据和系统的各个方面.

### CLI 特性

-   **数据存储管理**: 与不同的数据存储实例进行交互,通过 `DATASTORE_CONFIGS` 环境变量.
-   **数据操作**: 在您的数据模型上执行 CRUD 操作 .
-   **模型处理**: 管理和检查使用合同化的数据模型 `json-schema`。 。 。 .
-   **警卫**: 配置和管理与安全有关的方面.
-   **事件串流**:从不同的连接器(如HTTP,AMQP)流出实体变化或事件并同步到其他数据存储器.
-   **交互式贝壳**: 使用交互式 `run` 命令,用于执行连续会话中的 CLI 命令,完成命令历史和自动补全.
-   **心跳检查**: 验证数据存储服务的可用性.

## \* 安装

就为了开始 `getanthill` 数据存储器,遵循这些步骤:

1.  **清除仓库**数字 :
    
    ```bash
    git clone https://gitlab.com/getanthill/datastore.git
    cd datastore
    ```
    
2.  **安装依赖关系**数字 :
    
    ```bash
    npm install
    ```
    
3.  **环境变量**数字 : 创建一个 `.env` 在根目录中文件并配置必要的环境变量. 示例
    
    ```
    DATASTORE_API_URL=http://localhost:3001
    DATASTORE_ACCESS_TOKEN=your_secret_token
    ```
    
4.  **运行数据存储**数字 :
    
    ```bash
    npm start
    ```
    

## 使用实例

### 运行 API 服务器

```bash
npm start
```

API将在 `http://localhost:3001` (或您的配置) `DATASTORE_API_URL`) (中文(简体) ).

### 使用 CLI

**交互式 Shell :**

```bash
npm run cli run
```

**串流事件 :**

```bash
npm run cli stream <model> <source> -- --datastore default --output entity --connector http
```

**检查心跳 :**

```bash
npm run cli heartbeat
```

## 捐款

我们欢迎社区的贡献! 协助 `getanthill` 数据存储器请遵循本指南:

1.  **叉子存储器**。 。 。 .
2.  **创建新分支**数字 : `git checkout -b feature/your-feature-name` 或者说 `bugfix/your-bugfix-name`。 。 。 .
3.  **做你的改变,并做出他们**: 跟着我们 [承诺信息准则](https://npmcn.com/package/%40getanthill/datastore/CONTRIBUTING.md)。 。 。 .
4.  **推到叉子边** 打开 a **拉请求**。 。 。 .

请确保您的代码符合我们的编码标准,并通过所有测试.

## 鸣谢

-   感谢所有帮助改善这个项目的捐助者!
-   特别感谢开源社区的宝贵工具和灵感.

## 常见问题

### @getanthill/datastore 是什么？

事件源数据库

### 如何安装 @getanthill/datastore？

在项目目录运行 npm install @getanthill/datastore，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：@getanthill/telemetry（1\.12\.1）、@shelf/jest-mongodb（4\.x）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。它还提供命令行工具 datastore、ds，可以用 npx datastore 直接运行。

### @getanthill/datastore 支持 TypeScript 吗？

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

### @getanthill/datastore 支持 ESM 还是 CommonJS？

以 CommonJS 形式发布，可以直接 require\(\)；在 ES Module 项目中也可以用 import 引入（Node\.js 会把 module\.exports 作为默认导出）。

### @getanthill/datastore 需要什么版本的 Node\.js？

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

### @getanthill/datastore 可以商用吗？

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

### @getanthill/datastore 的下载量有多少？

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

### @getanthill/datastore 还在维护吗？

最新版本 0\.95\.6 发布于 2026/01/16（9 个月前）；至今共发布 446 个版本，其中过去 12 个月发布了 13 个；首次发布于 2020/11/26。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

