# @durable-streams/cli 中文文档

规范地址：https://npmcn.com/package/%40durable-streams/cli/

版本：0\.2\.7
npm 元数据更新时间：2026-09-10T17:20:00.171Z
中文译文更新时间：2026-11-13T04:53:53.275Z
软件包许可：Apache-2\.0

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

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

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

- 包体积（解压后）：57.9 kB，8 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=18\.0\.0
- 运行依赖：1 个
- 首次发布：2025-12-23T17:50:37.367Z
- 最新版本发布：2026-09-10T17:19:59.792Z
- 近 30 天下载量：2281（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：18（近 12 个月 18 个）

## 中文简介

与持久流合作的CLI工具

## 安装

```sh
npm install @durable-streams/cli
```

也可以使用：`pnpm add @durable-streams/cli`、`yarn add @durable-streams/cli`、`bun add @durable-streams/cli`

## README

# 持久性流式CLI

用于与可持久流交互的命令行工具 .

## 安装

### 从 npm

```bash
# Global installation
npm install -g @durable-streams/cli

# Or run directly with npx
npx @durable-streams/cli create my-stream
npx @durable-streams/cli read my-stream
```

### 从来源(促进发展)

```bash
# Clone the repository
git clone https://github.com/durable-streams/durable-streams.git
cd durable-streams

# Install dependencies
pnpm install

# Build the CLI
pnpm build

# Link globally for development (uses tsx, no rebuild needed)
cd packages/cli
pnpm link:dev

# Now you can use durable-stream-dev anywhere
durable-stream-dev create my-stream
```

## 快速启动

最容易启动的方法是运行本地开发服务器并使用 CLI :

### 第1终端:启动本地服务器

```bash
pnpm start:dev
```

这将启动持久流服务器 `http://localhost:4437` 现场重装.

### 终端2:使用 CLI

```bash
# Set the server URL (optional, defaults to http://localhost:4437/v1/stream)
export STREAM_URL=http://localhost:4437/v1/stream

# Create a stream
durable-stream-dev create my-stream

# Stream IDs may include slashes for hierarchical names
durable-stream-dev create account-123/chat/room-1

# Write to the stream
durable-stream-dev write my-stream "Hello, world!"

# Read from the stream (follows live)
durable-stream-dev read my-stream
```

## 使用量

### 环境变量

-   `STREAM_URL` - 流服务器的基础 URL( 默认 ): `http://localhost:4437/v1/stream`(中文(简体) )
-   `STREAM_AUTH` - 授权标题值(例如, `Bearer my-token`(中文(简体) )

### 全球选项

-   `--auth <value>` - 授权页眉值(覆盖) `STREAM_AUTH` (原始内容存档于2019-09-21) (英语). env var

### 写入选项

-   `--content-type <type>` - 消息的内容类型( 默认 : `application/octet-stream`(中文(简体) )
-   `--json` - 简指 `--content-type application/json`

### 图标

#### 创建流

```bash
durable-stream-dev create <stream_id>
```

#### 写入到流中

```bash
# Write content as arguments
durable-stream-dev write <stream_id> "Hello, world!"

# Pipe content from stdin
echo "Hello from stdin" | durable-stream-dev write <stream_id>
cat file.txt | durable-stream-dev write <stream_id>

# Specify content type
durable-stream-dev write <stream_id> '{"key": "value"}' --content-type application/json

# Shorthand for JSON
durable-stream-dev write <stream_id> '{"key": "value"}' --json
```

##### JSON 模式阵列平滑

在 JSON 模式中 (`--json` 或者说 `--content-type application/json`),顶级数组被平整为单个消息:

| 投入 | 存储的信件 |
| --- | --- |
| `{}` | 1条信息: `{}` |
| `[{}, {}]` | 2个消息: `{}`, (中文(简体) ), `{}` |
| `[[{}, {}]]` | 1条信息: `[{}, {}]` |

这符合协议的批量语义.

#### 从流中读取

```bash
# Follows the stream and outputs new data to stdout
durable-stream-dev read <stream_id>
```

#### 删除流

```bash
durable-stream-dev delete <stream_id>
```

### 认证

使用 `--auth` 旗帜或 `STREAM_AUTH` 要认证的环境变量 :

```bash
# Using environment variable
export STREAM_AUTH="Bearer my-token"
durable-stream-dev read my-stream

# Using --auth flag (overrides env var)
durable-stream-dev --auth "Bearer my-token" read my-stream

# Works with any auth scheme
durable-stream-dev --auth "Basic dXNlcjpwYXNz" read my-stream
durable-stream-dev --auth "ApiKey abc123" read my-stream
```

## 完成示例工作流程

```bash
# Terminal 1: Start the local development server
pnpm start:dev

# Terminal 2: Set up the stream
export STREAM_URL=http://localhost:4437/v1/stream
durable-stream-dev create test-stream

# Terminal 3: Start reading (will show data as it arrives)
export STREAM_URL=http://localhost:4437/v1/stream
durable-stream-dev read test-stream

# Back in Terminal 2: Write data and watch it appear in Terminal 3
durable-stream-dev write test-stream "First message"
durable-stream-dev write test-stream "Second message"
echo "Piped content!" | durable-stream-dev write test-stream
```

## 发展

```bash
# Start the example server with live reloading
pnpm start:dev

# Watch mode for CLI development (rebuilds dist/)
pnpm dev

# Build
pnpm build

# Link globally for development (uses tsx, no rebuild needed)
pnpm link:dev
```

## 常见问题

### @durable-streams/cli 是什么？

与持久流合作的CLI工具

### 如何安装 @durable-streams/cli？

在项目目录运行 npm install @durable-streams/cli，或使用 pnpm add / yarn add / bun add。它还提供命令行工具 cli、durable-stream、durable-stream-dev，可以用 npx cli 直接运行。

### @durable-streams/cli 支持 TypeScript 吗？

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

### @durable-streams/cli 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @durable-streams/cli 需要什么版本的 Node\.js？

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

### @durable-streams/cli 可以商用吗？

@durable-streams/cli 使用 Apache-2\.0 许可。宽松许可：允许商业使用、修改和再分发，并附带明确的专利授权；分发时需保留许可与 NOTICE 文件，修改过的文件要注明改动。以上为概括，不构成法律意见，请以许可原文为准。

### @durable-streams/cli 的下载量有多少？

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

### @durable-streams/cli 还在维护吗？

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

