@backloghq/opslog-s3

中文文档
0.4.1发布于 2026/05/05MITTypeScriptES Module近 30 天下载 1982

S3 storage backend for @backloghq/opslog. Enables multi-writer concurrency across machines via Amazon S3.

原始使用文档
文档目录13 节
  1. Install
  2. Usage
  3. Options
  4. Pre-configured client
  5. How It Works
  6. Storage layout
  7. WAL operations (per-batch objects)
  8. Locking
  9. Blob storage + byte-range reads
  10. Conflict resolution
  11. IAM Permissions
  12. Development
  13. License

opslog-s3

Amazon S3 storage backend for @backloghq/opslog. Store your event-sourced data in S3 and enable multi-writer concurrency across machines.

Install

npm install @backloghq/opslog @backloghq/opslog-s3

Usage

import { Store } from "@backloghq/opslog";
import { S3Backend } from "@backloghq/opslog-s3";

const store = new Store<{ title: string; status: string }>();
await store.open("my-store", {
  backend: new S3Backend({
    bucket: "my-bucket",
    prefix: "opslog/my-store",
    region: "us-east-1",
  }),
  agentId: "agent-A",
});

await store.set("task-1", { title: "Build API", status: "active" });
const task = store.get("task-1");
await store.close();

Another agent on a different machine can write to the same store:

const store = new Store<{ title: string; status: string }>();
await store.open("my-store", {
  backend: new S3Backend({
    bucket: "my-bucket",
    prefix: "opslog/my-store",
    region: "us-east-1",
  }),
  agentId: "agent-B",
});

// Sees agent-A's writes
store.get("task-1"); // { title: "Build API", status: "active" }

// Writes to its own WAL — no contention with agent-A
await store.set("task-2", { title: "Write tests", status: "active" });
await store.close();

Options

new S3Backend({
  bucket: "my-bucket",         // S3 bucket name (required)
  prefix: "path/to/store",    // Key prefix (optional, no trailing slash)
  region: "us-east-1",        // AWS region (required if no client provided)
  client: myS3Client,         // Pre-configured S3Client (optional)
  lockTtlMs: 60000,           // Lock TTL in ms (default: 60000)
});

Pre-configured client

Pass your own S3Client if you need custom configuration (credentials, endpoint, middleware):

import { S3Client } from "@aws-sdk/client-s3";

const client = new S3Client({
  region: "us-east-1",
  endpoint: "http://localhost:9000", // MinIO, LocalStack, etc.
  forcePathStyle: true,
});

const backend = new S3Backend({ bucket: "my-bucket", client });

How It Works

Storage layout

s3://bucket/prefix/
  manifest.json                       # Store metadata
  snapshots/snap-<ts>.jsonl           # Immutable state captures (JSONL)
  ops/agent-<id>-<ts>.jsonl           # Per-agent WAL files
  archive/archive-<period>.json       # Archived records

WAL operations (per-batch objects)

S3 has no native append. Instead of downloading, concatenating, and re-uploading a single growing file, the S3Backend stores each write as a separate S3 object:

ops/agent-A-1744200000/
  batch-1744200001-0000.jsonl   (ops from first write)
  batch-1744200002-0000.jsonl   (ops from second write)
  batch-1744200003-0000.jsonl   (ops from third write)
  • Append: single PutObject per write (no download needed)
  • Read: ListObjectsV2 + parallel GetObject per batch, with incremental caching (only new batches are downloaded on subsequent reads)
  • Truncate: delete last batch object (or modify if it contains multiple ops)

Stores created with v0.1.0 (single .jsonl files) are transparently supported — the backend detects the format automatically.

Locking

Uses S3 conditional writes (IfNoneMatch: *) for lock acquisition — fails atomically if the lock already exists. Lock objects carry a TTL; stale locks from crashed agents are automatically recovered.

Blob storage + byte-range reads

await backend.writeBlob("data/records.jsonl", buffer);
const full = await backend.readBlob("data/records.jsonl");
const range = await backend.readBlobRange("data/records.jsonl", 1024, 256); // HTTP Range header

readBlobRange uses S3 GetObject with Range: bytes=N-M header — reads only the requested bytes. Enables O(1) point lookups in JSONL record stores without downloading the full object.

Conflict resolution

When multiple agents write to the same key, opslog's Lamport clock ordering resolves conflicts via last-writer-wins. See opslog multi-writer docs for details.

IAM Permissions

The S3Backend needs these S3 permissions on the bucket/prefix:

{
  "Effect": "Allow",
  "Action": [
    "s3:GetObject",
    "s3:PutObject",
    "s3:DeleteObject",
    "s3:ListBucket"
  ],
  "Resource": [
    "arn:aws:s3:::my-bucket",
    "arn:aws:s3:::my-bucket/opslog/*"
  ]
}

Development

npm run build          # Compile TypeScript
npm run lint           # ESLint
npm test               # Run tests (uses in-memory mock S3, no AWS needed)
npm run test:coverage  # Tests with coverage

License

MIT

版本与发布记录

@backloghq/opslog-s3 共发布 6 个版本,首次发布于 2026/04/10;过去 12 个月发布了 6 个版本。

版本发布日期距今
0.4.1latest2026/05/056 个月前
0.4.02026/04/116 个月前
0.3.02026/04/116 个月前
0.2.02026/04/106 个月前
0.1.12026/04/106 个月前
0.1.02026/04/106 个月前

关于 @backloghq/opslog-s3 的常见问题

@backloghq/opslog-s3 是什么?

S3 storage backend for @backloghq/opslog. Enables multi-writer concurrency across machines via Amazon S3.

如何安装 @backloghq/opslog-s3?

在项目目录运行 npm install @backloghq/opslog-s3,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@backloghq/opslog(>=0.8.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@backloghq/opslog-s3 支持 TypeScript 吗?

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

@backloghq/opslog-s3 支持 ESM 还是 CommonJS?

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

@backloghq/opslog-s3 需要什么版本的 Node.js?

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

@backloghq/opslog-s3 可以商用吗?

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

@backloghq/opslog-s3 的下载量有多少?

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

@backloghq/opslog-s3 还在维护吗?

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