@beblurt/blurt-rpc-core

中文文档
0.1.0发布于 2026/06/22MITTypeScriptES Module零依赖近 30 天下载 7098

Generic JSON-RPC 2.0 core for transports, retries, endpoint pools, hooks and observability.

原始使用文档
文档目录10 节
  1. Status
  2. Install
  3. Scripts
  4. Minimal usage
  5. Raw responses
  6. Multiple endpoints and retry/failover
  7. Explicit cache
  8. Hooks and metrics
  9. Documentation
  10. Non-goals

blurt-rpc-core

Generic JSON-RPC 2.0 core for TypeScript projects.

This package is intentionally domain-agnostic. It provides implemented primitives for:

  • JSON-RPC requests and responses;
  • a RpcClient facade for single calls, raw calls, notifications and batches;
  • fetch-based HTTP transport with timeout and abort support;
  • retries and backoff;
  • endpoint pools and selection strategies;
  • ordered lifecycle hooks;
  • generic metrics;
  • optional explicit cache;
  • structured public errors;
  • testing helpers.

It does not implement blockchain logic, health checks, scoring, cryptographic signatures, chain validation or MCP server behavior.

Status

MVP implemented. The core is usable as a generic JSON-RPC engine and is covered by unit tests for client orchestration, transport, retry/failover, node-pool selection, cache, hooks, metrics and structured errors.

Install

npm install @beblurt/blurt-rpc-core

The package is ESM-only, targets Node.js >= 18, and also runs in browser runtimes that provide fetch, AbortController, URL and setTimeout.

Scripts

npm run build
npm run typecheck
npm run lint
npm test
npm audit --audit-level=high

Minimal usage

import { RpcClient } from '@beblurt/blurt-rpc-core'

const rpc = new RpcClient('https://rpc.example.org', { timeoutMs: 4000 })
const result = await rpc.call('namespace.method', { limit: 10 })

Raw responses

const response = await rpc.call('namespace.method', { limit: 10 }, { responseMode: 'response' })

Multiple endpoints and retry/failover

import { fixedBackoff, RpcClient } from '@beblurt/blurt-rpc-core'

const rpc = new RpcClient(['https://rpc-a.example.org', 'https://rpc-b.example.org'], {
  retry: { maxAttempts: 3, backoff: fixedBackoff(250) }
})

const value = await rpc.call('namespace.method')

Explicit cache

Caching is never implicit and the core never decides cacheability from method names.

import { MemoryCacheProvider, RpcClient } from '@beblurt/blurt-rpc-core'

const rpc = new RpcClient('https://rpc.example.org', {
  cache: { provider: new MemoryCacheProvider(), ttlMs: 5000 }
})

await rpc.call('namespace.method', { limit: 10 }, { cache: { ttlMs: 5000 } })

Hooks and metrics

import { InMemoryMetricsCollector, RpcClient } from '@beblurt/blurt-rpc-core'

const metrics = new InMemoryMetricsCollector()
const rpc = new RpcClient('https://rpc.example.org', {
  metrics,
  hooks: {
    beforeRequest: (request, context) => {
      // Return a replacement request to mutate, or void to continue unchanged.
    },
    afterAttempt: (outcome) => {
      // Observe success/error for each concrete attempt.
    }
  }
})

Documentation

Start with:

  • ARCHITECTURE.md
  • API.md
  • DESIGN_DECISIONS.md
  • docs/public-api.md
  • docs/release-0.1.0.md
  • module reference pages under docs/

Non-goals

No blockchain, scoring, signatures, health checks, method-specific behavior or MCP server code belongs in this package.

版本与发布记录

@beblurt/blurt-rpc-core 共发布 1 个版本,首次发布于 2026/06/22;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.1.0latest2026/06/224 个月前

关于 @beblurt/blurt-rpc-core 的常见问题

@beblurt/blurt-rpc-core 是什么?

Generic JSON-RPC 2.0 core for transports, retries, endpoint pools, hooks and observability.

如何安装 @beblurt/blurt-rpc-core?

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

@beblurt/blurt-rpc-core 支持 TypeScript 吗?

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

@beblurt/blurt-rpc-core 支持 ESM 还是 CommonJS?

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

@beblurt/blurt-rpc-core 需要什么版本的 Node.js?

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

@beblurt/blurt-rpc-core 可以商用吗?

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

@beblurt/blurt-rpc-core 的下载量有多少?

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

@beblurt/blurt-rpc-core 还在维护吗?

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