@equationalapplications/prisma-outbox

中文文档
8.4.0发布于 2026/11/13MITTypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3949

Sync core-llm-wiki SQLite outbox events to your Prisma-backed database using the transactional outbox pattern — at-least-once delivery with ordering guarantees.

原始使用文档
文档目录8 节
  1. Installation
  2. Quick start
  3. API
  4. PrismaOutboxWorker
  5. PrismaOutboxConfig
  6. How it works
  7. Limitations
  8. Monorepo Ecosystem

@equationalapplications/prisma-outbox

Sync @equationalapplications/core-llm-wiki SQLite outbox events to your Prisma-backed database using the transactional outbox pattern — at-least-once delivery with ordering guarantees.

npm version TypeScript License: MIT

📖 Docs · GitHub · ScopeLab · WikiDemo · Changelog · Issues

Polls the SQLite outbox table written by @equationalapplications/core-llm-wiki and syncs events to your Prisma-backed system inside a Prisma transaction, with configurable batch size, poll interval, error handling, and a concurrency guard.

For the GraphRAG retrieval surface (traverseGraph, useWikiTraversal, formatGraphContext), see GraphRAG guide.

Installation

npm install @equationalapplications/prisma-outbox
# peer deps
npm install @equationalapplications/core-llm-wiki @prisma/client

Quick start

import { PrismaOutboxWorker } from '@equationalapplications/prisma-outbox';
import { WikiMemory } from '@equationalapplications/core-llm-wiki';
import { PrismaClient } from '@prisma/client';

const wiki = new WikiMemory(db, {
  llmProvider,
  config: { enableOutbox: true },
});
await wiki.setup();

const prisma = new PrismaClient();

const worker = new PrismaOutboxWorker({
  wikiMemory: wiki,
  prisma,
  mapEvent: async (event, tx) => {
    // mapEvent must be idempotent: at-least-once delivery means the same event
    // can be retried if acknowledgement fails after the Prisma transaction commits.
    if (event.operation === 'INSERT' && event.table_name.includes('entries')) {
      await tx.wikiEntry.upsert({
        where: { id: event.record_id },
        create: { id: event.record_id, ...(event.payload as Record<string, unknown>) },
        update: {},
      });
    }
  },
  pollIntervalMs: 5000,
  batchSize: 100,
  onError: (err, event) => {
    console.error('Outbox event failed', event.id, err);
    return false; // halt to preserve ordering; return true to skip poison-pill
  },
});

worker.start();

// On shutdown:
worker.stop();

API

PrismaOutboxWorker

MethodDescription
start()Begins polling on the configured interval. Idempotent.
stop()Clears the poll interval and any pending backlog timeout.
syncBatch()Manually trigger one poll cycle (useful for testing).

PrismaOutboxConfig

FieldTypeDefaultDescription
wikiMemoryWikiMemoryrequiredThe WikiMemory instance to poll.
prismaPrismaLike<TTx>requiredAny Prisma client with a $transaction method (your generated PrismaClient satisfies this).
mapEvent(event, tx: TTx) => Promise<void>requiredMaps one outbox event to Prisma operations inside a transaction. tx is inferred from your PrismaClient.
batchSizenumber100Max events fetched per cycle.
pollIntervalMsnumber5000Milliseconds between poll cycles.
onError(err, event) => boolean | undefined—Return true to skip a failing event; false/undefined to halt.
onWorkerError(err: Error) => void—Called for worker-level errors (SQLite read/ack failures) not delivered to onError.

How it works

  1. Every WikiMemory mutation (when enableOutbox: true) atomically writes an event to the SQLite outbox table in the same transaction as the domain write.
  2. PrismaOutboxWorker polls getUnprocessedOutboxEvents() and calls mapEvent inside a Prisma transaction for each event.
  3. Successfully processed event IDs are passed to markOutboxEventsProcessed(), which deletes them from SQLite.
  4. If a full batch is consumed without error, an immediate follow-up cycle runs (backlog optimization) to drain queues faster than the poll interval.

Limitations

  • Single-instance only. The worker does not use row-level locking or leases. Running two PrismaOutboxWorker instances against the same SQLite file will cause duplicate Prisma writes. Run exactly one worker per SQLite database. mapEvent must still be idempotent to tolerate at-least-once delivery (acknowledgement can fail after a successful Prisma commit).

Monorepo Ecosystem

PackagePurpose
@equationalapplications/core-llm-wikiPersistent episodic memory
@equationalapplications/expo-llm-wikiPersistent episodic memory for Expo/React Native
@equationalapplications/react-llm-wikiPersistent episodic memory for Web
@equationalapplications/prisma-outboxSync SQLite outbox events to Prisma
@equationalapplications/core-llm-toolsGemini tool schemas and capability injector
@equationalapplications/core-okfZero-dependency Open Knowledge Format (OKF) v0.1 + v0.2 primitives — parse and produce interoperable knowledge bundles.
@equationalapplications/schema-org-llm-wikiCurated schema.org warm-agent ontology manifest
@equationalapplications/schema-software-orgSoftware-organization executive ontology manifest — 17 node types, 40 edges, warm-agent superset, data-only
@equationalapplications/mcp-serverMCP server exposing SynapseTree memory tools to coding agents

Made with ❤️ by Equational Applications LLC. https://equationalapplications.com/

版本与发布记录

@equationalapplications/prisma-outbox 共发布 91 个版本,首次发布于 2026/05/17;过去 12 个月发布了 91 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
8.4.0latest2026/11/131 天前
8.3.02026/11/131 天前
8.2.02026/11/122 天前
8.1.02026/11/122 天前
8.0.52026/11/112 天前
8.0.42026/11/112 天前

关于 @equationalapplications/prisma-outbox 的常见问题

@equationalapplications/prisma-outbox 是什么?

Sync core-llm-wiki SQLite outbox events to your Prisma-backed database using the transactional outbox pattern — at-least-once delivery with ordering guarantees.

如何安装 @equationalapplications/prisma-outbox?

在项目目录运行 npm install @equationalapplications/prisma-outbox,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@prisma/client(^5.0.0 || ^6.0.0 || ^7.0.0)、@equationalapplications/core-llm-wiki(8.4.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@equationalapplications/prisma-outbox 支持 TypeScript 吗?

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

@equationalapplications/prisma-outbox 支持 ESM 还是 CommonJS?

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

@equationalapplications/prisma-outbox 需要什么版本的 Node.js?

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

@equationalapplications/prisma-outbox 可以商用吗?

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

@equationalapplications/prisma-outbox 的下载量有多少?

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

@equationalapplications/prisma-outbox 还在维护吗?

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