@durable-streams/cli

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

CLI tool for working with Durable Streams

原始使用文档
文档目录14 节
  1. Installation
  2. From npm
  3. From source (for development)
  4. Quick Start
  5. Terminal 1: Start the local server
  6. Terminal 2: Use the CLI
  7. Usage
  8. Environment Variables
  9. Global Options
  10. Write Options
  11. Commands
  12. Authentication
  13. Complete Example Workflow
  14. Development

Durable Streams CLI

A command-line tool for interacting with durable streams.

Installation

From 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

From source (for development)

# 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

Quick Start

The easiest way to get started is to run the local development server and use the CLI:

Terminal 1: Start the local server

pnpm start:dev

This will start a Durable Streams server at http://localhost:4437 with live reloading.

Terminal 2: Use the 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

Usage

Environment Variables

  • STREAM_URL - Base URL of the stream server (default: http://localhost:4437/v1/stream)
  • STREAM_AUTH - Authorization header value (e.g., Bearer my-token)

Global Options

  • --auth <value> - Authorization header value (overrides STREAM_AUTH env var)

Write Options

  • --content-type <type> - Content-Type for the message (default: application/octet-stream)
  • --json - Shorthand for --content-type application/json

Commands

Create a stream

durable-stream-dev create <stream_id>

Write to a stream

# 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 Mode Array Flattening

In JSON mode (--json or --content-type application/json), top-level arrays are flattened into individual messages:

InputMessages stored
{}1 message: {}
[{}, {}]2 messages: {}, {}
[[{}, {}]]1 message: [{}, {}]

This matches the protocol's batch semantics.

Read from a stream

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

Delete a stream

durable-stream-dev delete <stream_id>

Authentication

Use the --auth flag or STREAM_AUTH environment variable to authenticate:

# 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

Complete Example Workflow

# 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

Development

# 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 tool for working with Durable Streams

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