@actuallab/fusion-rpc

中文文档
15.1.24发布于 2026/11/07MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3305

Bridge between Fusion and RPC - FusionHub, compute service registration

原始使用文档
文档目录7 节
  1. Installation
  2. Quick start
  3. How invalidation flows
  4. API surface
  5. Notes
  6. Documentation
  7. License

@actuallab/fusion-rpc

npm Documentation License

The bridge between @actuallab/fusion and @actuallab/rpc: FusionHub — a compute-aware RPC hub whose client proxies cache results locally and drop them the moment the .NET server says the value changed. This is the TypeScript equivalent of Fusion's client-side RPC infrastructure (Remote Compute Service interceptor, RpcComputeCallType).

This is the package you want if your goal is "call Fusion Compute Services running on a .NET server from a JS/TS client, and get real-time updates".

Installation

npm install @actuallab/fusion-rpc

ESM-first with a CJS fallback; ships its own .d.ts. Pulls in @actuallab/core, @actuallab/fusion, and @actuallab/rpc.

Quick start

import { FusionHub, defineComputeService } from '@actuallab/fusion-rpc';
import { RpcClientPeer, RpcPeerStateMonitor } from '@actuallab/rpc';

// 1. Define the service — the name must match the .NET interface name exactly.
const TodoApiDef = defineComputeService('ITodoApi', {
    // Compute methods: cached locally, invalidated by the server
    Get: { args: ['', ''] },                     // (session, id) → TodoItem
    ListIds: { args: ['', 0] },                  // (session, count) → string[]
    GetSummary: { args: [''] },                  // (session) → TodoSummary

    // Commands: opt out of compute caching
    AddOrUpdate: { args: [{}], callTypeId: 0 },
    Remove: { args: [{}], callTypeId: 0 },
});

// 2. Hub + peer. The RpcClientPeer ctor starts the connect/reconnect loop.
const hub = new FusionHub();
const peer = new RpcClientPeer(hub, 'ws://localhost:5005/rpc/ws');
hub.addPeer(peer);

// 3. Typed client proxy — addClient is idempotent per (peer, service),
//    so every consumer shares one Computed and one invalidation stream.
const api = hub.addClient<ITodoApi>(peer, TodoApiDef);

// 4. Optional: connection status for the UI
const monitor = new RpcPeerStateMonitor(peer);

// Cached until the server invalidates it
const ids = await api.ListIds('~', 10);

Render it with useComputedState and the component refreshes itself whenever the server-side data changes.

How invalidation flows

  1. The client calls a compute method — FusionHub sends it with CallType = 1.
  2. The server computes, responds with $sys.Ok; the client caches the result locally.
  3. Server-side data changes and the server-side Computed<T> is invalidated.
  4. The server sends $sys-c.Invalidate for that call id.
  5. The client invalidates its local replica; the invalidation cascades into every dependent @computeMethod and ComputedState<T> — and React re-renders.

An Invalidate that arrives before the result retries the call transparently (up to 3 attempts while connected). On disconnect, compute replicas self-invalidate instead of being re-sent, since the server's tracking for them is gone; regular in-flight calls are re-sent as usual.

API surface

APIDescription
FusionHubRpcHub + compute-aware proxies, invalidation wiring, acceptConnection(ws) for hosting
defineComputeService(name, methods)Service definition where methods default to callTypeId: 1 (compute); use callTypeId: 0 for commands
FUSION_CALL_TYPE_IDThe compute call type id (1)
RpcOutboundComputeCallThe outbound call type that carries invalidation handling

Notes

  • Cancellation. A caller's AbortSignal travels through AsyncContext (abortSignalKey); aborting sends $sys.Cancel, and the resulting cancellation error is never cached.
  • Hosting compute services in Node. hub.addService(def, impl) wraps compute methods and wires invalidation to $sys-c.Invalidate. Use a class with @computeMethod members whenever service methods call each other — a plain-object impl calls them as raw functions and loses the dependency edges.

Documentation

License

MIT — see LICENSE.

版本与发布记录

@actuallab/fusion-rpc 共发布 54 个版本,首次发布于 2026/02/18;过去 12 个月发布了 54 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
15.1.24latest2026/11/07今天
15.1.222026/11/07今天
15.1.152026/11/07今天
15.1.112026/11/07今天
15.1.62026/11/07今天
15.0.212026/10/2414 天前

关于 @actuallab/fusion-rpc 的常见问题

@actuallab/fusion-rpc 是什么?

Bridge between Fusion and RPC - FusionHub, compute service registration

如何安装 @actuallab/fusion-rpc?

在项目目录运行 npm install @actuallab/fusion-rpc,或使用 pnpm add / yarn add / bun add。

@actuallab/fusion-rpc 支持 TypeScript 吗?

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

@actuallab/fusion-rpc 支持 ESM 还是 CommonJS?

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

@actuallab/fusion-rpc 可以商用吗?

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

@actuallab/fusion-rpc 的下载量有多少?

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

@actuallab/fusion-rpc 还在维护吗?

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