@godspeedai/cognate-store-memory

中文文档
0.10.0发布于 2026/11/16Apache-2.0ES Module构建来源已验证近 30 天下载 3600

In-memory DurableStore with the same semantics as the SQLite store (tests, ephemeral runtimes).

原始使用文档
文档目录6 节
  1. Installation
  2. Quick start
  3. What the store guarantees
  4. Limitations
  5. Related packages
  6. License

@godspeedai/cognate-store-memory

An in-memory Cognate event store with the same observable semantics as @godspeedai/cognate-store-sqlite: atomic multi-part commits, optimistic concurrency, idempotent commits, an outbox, projection checkpoints, content-addressed blobs, and payload erasure.

When to use this package: tests, examples, and throwaway prototypes. Everything lives in process memory — nothing survives a restart — so production applications that must outlive the process need the SQLite store instead. Both implement the same @godspeedai/cognate-events store contract, so an app can switch between them with one line.

Installation

bun add @godspeedai/cognate-store-memory

Requires Bun >= 1.4.0.

Quick start

import { createMemoryStore } from "@godspeedai/cognate-store-memory";

const store = createMemoryStore();

const outcome = await store.commit({
  idempotency: { scope: "alice:order", key: "order-1", fingerprint: "fp-1" },
  appends: [
    {
      streamId: "order-1",
      expectedVersion: 0,
      events: [
        {
          eventType: "order.placed",
          schemaVersion: 1,
          occurredAt: new Date().toISOString(),
          tenant: "tenant-a",
          correlationId: "corr-1",
          causationId: null,
          runId: null,
          scopeId: "root",
          payload: { sku: "widget", quantity: 2 },
        },
      ],
    },
  ],
  result: { placed: true },
});
// { kind: "committed", events: [...], records: [], result: { placed: true } }

Pass the store to createRuntime from @godspeedai/cognate-runtime-bun for an ephemeral runtime — fast to create, isolated per test:

const runtime = await createRuntime({ store: { store: createMemoryStore() } /* agents, policy, ... */ });

(The runtime's store: ":memory:" shortcut is a different store — the SQLite implementation running on a database that is never written to a file. Equally ephemeral, but with SQLite's durability configuration behind it.)

What the store guarantees

  • Atomic decisions. Stream appends, record writes, outbox intents, and the idempotency result commit together; a failure in any part leaves none of it visible.
  • Optimistic concurrency. Appending against a stale stream version throws ConcurrencyError; a stale record write throws RecordConflictError. Exactly one of several racing writers wins.
  • Idempotency. A repeated key returns the recorded result without writing a second fact; a reused key with a different request fingerprint throws IdempotencyMismatchError.
  • Deterministic ordering. Reads come back by per-stream sequence and store-wide position, and key/id listings use code-point order — the same order the SQLite store produces, so replay comparisons are store-independent.
  • Erasure. erasePayload nulls the payload, keeps the envelope, and appends a tombstone event to the $erasures stream.

Commits are serialized internally (a promise queue), so concurrent commit calls resolve one at a time even though the API is async. Every value returned from the store is a deep copy; mutating a result never affects store state.

Limitations

  • Not persistent. All state lives in process memory and disappears when the process exits. There is no reopen, no durability, and no backup story — use @godspeedai/cognate-store-sqlite when data must survive.
  • Single process. The store exists only inside the process that created it; it cannot be shared across processes or machines.

License

Apache-2.0

版本与发布记录

@godspeedai/cognate-store-memory 共发布 20 个版本,首次发布于 2026/10/09;过去 12 个月发布了 20 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.10.0latest2026/11/16今天
0.9.22026/11/152 天前
0.9.12026/11/143 天前
0.9.02026/11/0610 天前
0.8.02026/10/2720 天前
0.7.12026/10/2523 天前

关于 @godspeedai/cognate-store-memory 的常见问题

@godspeedai/cognate-store-memory 是什么?

In-memory DurableStore with the same semantics as the SQLite store (tests, ephemeral runtimes).

如何安装 @godspeedai/cognate-store-memory?

在项目目录运行 npm install @godspeedai/cognate-store-memory,或使用 pnpm add / yarn add / bun add。

@godspeedai/cognate-store-memory 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/godspeedai__cognate-store-memory 是否存在。

@godspeedai/cognate-store-memory 支持 ESM 还是 CommonJS?

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

@godspeedai/cognate-store-memory 可以商用吗?

@godspeedai/cognate-store-memory 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@godspeedai/cognate-store-memory 的下载量有多少?

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

@godspeedai/cognate-store-memory 还在维护吗?

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