@durable-streams/cli

中文文档
0.2.7发布于 2026/09/11Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 2281

与持久流合作的CLI工具

中文使用文档
文档目录14 节
  1. 安装
  2. 从 npm
  3. 从来源(促进发展)
  4. 快速启动
  5. 第1终端:启动本地服务器
  6. 终端2:使用 CLI
  7. 使用量
  8. 环境变量
  9. 全球选项
  10. 写入选项
  11. 图标
  12. 认证
  13. 完成示例工作流程
  14. 发展

持久性流式CLI

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

安装

从 npm

# 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

从来源(促进发展)

# 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终端:启动本地服务器

pnpm start:dev

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

终端2:使用 CLI

# 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

图标

创建流

durable-stream-dev create <stream_id>

写入到流中

# 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条信息: [{}, {}]

这符合协议的批量语义.

从流中读取

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

删除流

durable-stream-dev delete <stream_id>

认证

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

# 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

完成示例工作流程

# 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

发展

# 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 共发布 18 个版本,首次发布于 2025/12/24;过去 12 个月发布了 18 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.2.7latest2026/09/112 个月前
0.2.62026/06/015 个月前
0.2.52026/05/285 个月前
0.2.42026/05/195 个月前
0.2.32026/03/247 个月前
0.2.22026/03/078 个月前

关于 @durable-streams/cli 的常见问题

@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 和提交记录判断。