@12-apps/realtime

中文文档
2.10.0发布于 2026/11/05MITES Module构建来源已验证近 30 天下载 3.3万

Generic, portable realtime EVENT SYSTEM. Framework-free core (typed topic/event envelopes and a publish/subscribe bus behind a swappable driver port: Redis pub/sub across processes, inline in-process for dev and tests), host-mounted backend surface (./ser

原始使用文档

@12-apps/realtime

A portable realtime event system: the bus, the subscribe surface that authorizes and streams it, a runnable WebSocket gateway, a transactional outbox, the browser client, and the gate that keeps a subscribable domain from shipping silent.

Two factories, one config object each — full contract in ADOPTING.md.

// backend
const events = eventsRouter({ surfaces, outbox: { db: () => prisma } });
app.route("/api", events.router);
await events.start();

// frontend
const web = createWebEvents({ apiBase: "/api" });
const { status } = web.useTopics({ topics: ["kitchen"], onMessage: invalidate });
useQuery({ /* … */ refetchInterval: reconcileRefetchInterval(status, POLL_MS, RECONCILE_MS) });
SubpathWhat it is
.the framework-free bus: topics, publishRealtimeEvent, subscribeRealtime, the driver port, the inline driver
./redisthe cross-process driver, behind its own subpath so an emit site never drags ioredis into a bundle
./ticketconnection tickets: mint, verify, single-use guard
./servercreateApiEvents — topic registry, the authorization seam, the SSE transport, connection caps, the outbox
./honoeventsRouter — one-call mount (hono is an optional peer)
./gatewaystartRealtimeGateway, plus a realtime-gateway bin (ws is an optional peer)
./reactcreateWebEvents — client, reconnect policy, ws→sse demotion, liveness watch, hooks
./nodethe same client from a runtime with no EventSource — an event-stream WireSource over fetch, for a desktop agent, a worker or a CLI
./workerthe SharedWorker body, for a host that wants one connection per person
./paritythe publisher-parity gate: library + CLI
prisma/the outbox model + its migration, copied into a host's schema folder

The three rules everything else follows from

  • Publishing never throws. Realtime is a latency optimisation over the consumers' polling fallback, so a bus outage degrades to "the next poll sees it" — never to a failed mutation.
  • Delivery is best-effort and there is no replay. Every event is a hint to RE-READ; the database stays the source of truth and the poll is a permanent floor that realtime only relaxes. data carries identifiers, never state — a payload here would be a second, unguarded copy of an authorization decision.
  • The gateway performs no authorization. The API surface decides with the host's own rules and signs the RESOLVED topic names into a short-lived, single-use ticket. A topic that was never handed over is never subscribed to, so a gateway bug can break the socket but cannot leak another tenant's events.

Presence follows the connection. A surface's authorize may name presence keys; the process holding the connection announces them held while it is open (renewed from the server) and released when it closes, and the API's presence.onChange hears every holder — no heartbeat poll in any browser. See ADOPTING.md, "Presence".

The outbox is the one durable exception to "best-effort", and its guarantee is stated plainly: exactly-once persistence, at-least-once publish with idempotent consumers, no total order. See ADOPTING.md — it is not exactly-once and does not pretend to be.

版本与发布记录

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

版本发布日期距今
2.10.0latest2026/11/051 天前
2.9.02026/10/1819 天前
2.8.02026/10/1423 天前
2.7.22026/09/291 个月前
2.7.12026/09/231 个月前
2.7.02026/09/221 个月前

关于 @12-apps/realtime 的常见问题

@12-apps/realtime 是什么?

Generic, portable realtime EVENT SYSTEM. Framework-free core (typed topic/event envelopes and a publish/subscribe bus behind a swappable driver port: Redis pub/sub across processes, inline in-process for dev and tests), host-mounted backend surface (./ser

如何安装 @12-apps/realtime?

在项目目录运行 npm install @12-apps/realtime,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 realtime-gateway,可以用 npx realtime-gateway 直接运行。

@12-apps/realtime 支持 TypeScript 吗?

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

@12-apps/realtime 支持 ESM 还是 CommonJS?

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

@12-apps/realtime 需要什么版本的 Node.js?

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

@12-apps/realtime 可以商用吗?

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

@12-apps/realtime 的下载量有多少?

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

@12-apps/realtime 还在维护吗?

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