@bielu/scalar-grpc

中文文档
1.0.1发布于 2026/11/04MITTypeScriptES Module构建来源已验证近 30 天下载 6785

Interactive gRPC console plugin for the Scalar API Reference. Reads gRPC AsyncAPI bindings and lets you invoke unary and server-streaming methods over gRPC-Web.

原始使用文档
文档目录5 节
  1. Server prerequisites
  2. Standalone usage (CDN)
  3. Programmatic usage
  4. Auth
  5. Building

@bielu/scalar-grpc

An interactive gRPC console plugin for the Scalar API Reference.

It reads the grpc (or x-grpc) bindings from your AsyncAPI document(s) and renders a panel where you can pick a service, edit a JSON request prefilled from the payload schema, and invoke unary and server-streaming methods live — over gRPC-Web (browsers cannot speak native gRPC). Client- and bidirectional-streaming methods are rendered as documentation with a "not invokable from the browser" badge.

Because AsyncAPI payload schemas are JSON Schema (no protobuf field numbers), the console encodes wire messages from real protobuf descriptors fetched from the companion .NET package's {assetsPath}/descriptors endpoint (a serialized FileDescriptorSet), using @bufbuild/protobuf + @connectrpc/connect-web — fully dynamic, no codegen in the browser.

This package is produced from, and consumed by, the Bielu.AspNetCore.AsyncApi.Scalar.Grpc .NET package (which embeds the built bundle), but it is also published standalone to npm so it can be loaded from a CDN or bundled by hand.

Server prerequisites

The target ASP.NET Core app must:

  1. enable gRPC-Web: app.UseGrpcWeb(new GrpcWebOptions { DefaultEnabled = true }) (package Grpc.AspNetCore.Web), and
  2. serve the descriptor endpoint: app.MapScalarGrpcAssets() (package Bielu.AspNetCore.AsyncApi.Scalar.Grpc).

When the page and the gRPC server are on different origins, CORS must allow the gRPC-Web response headers: grpc-status and grpc-message need to be exposed (policy.WithExposedHeaders("Grpc-Status", "Grpc-Message", "Grpc-Encoding", "Grpc-Accept-Encoding")).

Standalone usage (CDN)

<div id="app"></div>
<script src="https://cdn.jsdelivr.net/npm/@bielu/scalar-grpc"></script>
<script>
  window.__BIELU_SCALAR_GRPC__ = {
    documents: [{ name: 'grpc', url: '/asyncapi/grpc.json' }],
  }
  Scalar.createApiReference('#app', {
    sources: [{ url: '/asyncapi/grpc.json' }],
  })
</script>

The gRPC documents can be provided either via the global window.__BIELU_SCALAR_GRPC__ or inline on the Scalar config as config.grpc.

Programmatic usage

import { createGrpcPlugin } from '@bielu/scalar-grpc'

Scalar.createApiReference('#app', {
  sources: [{ url: '/asyncapi/grpc.json' }],
  plugins: [createGrpcPlugin()],
})

Auth

The console picks up the credentials entered in Scalar's Authentication panel (Scalar ≥ 2.16.12) and maps them onto gRPC-Web call metadata: header API keys, Authorization: Bearer … and HTTP Basic all map directly (gRPC-Web metadata is plain HTTP headers). Additional per-call metadata can be entered in the console's metadata editor.

Building

npm install
npm run build   # → dist/plugin.js + dist/plugin.mjs + dist/scalar-plugin.mjs + dist/standalone.js + dist/types

The build inlines the private @bielu/scalar-core workspace package (document discovery, auth state, schema examples, Scalar bootstrap) — see that package's README for the shared contract.

Four build outputs, with four different contracts — they are not interchangeable:

OutputContractUsed by
dist/plugin.jsIIFE; installs itself by hooking window.Scalar.createApiReferenceMapScalarGrpcAssets(), which serves it next to Scalar's own bundle
dist/plugin.mjsES module library entry; named exports (createGrpcPlugin, …), also self-installingbundler consumers who import from this package
dist/scalar-plugin.mjsES module; default export is the plugin, registers nothing itselfScalar's pluginUrls option — how the Aspire package adds the console to the stock container
dist/standalone.jsScalar's prebuilt browser bundle with the plugin appendedpages where nothing else loads Scalar; replaces Scalar's own bundle

dist/scalar-plugin.mjs also reads its own import.meta.url to locate the protobuf descriptor endpoint, since document.currentScript is always null inside an ES module.

版本与发布记录

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

版本发布日期距今
1.0.1latest2026/11/043 天前
1.0.1-beta.20261104151236beta2026/11/043 天前
1.0.1-beta.202611041331502026/11/043 天前
1.0.1-beta.202611030955042026/11/035 天前
1.0.1-beta.202611030953582026/11/035 天前
1.0.1-beta.202610250832222026/10/2514 天前

关于 @bielu/scalar-grpc 的常见问题

@bielu/scalar-grpc 是什么?

Interactive gRPC console plugin for the Scalar API Reference. Reads gRPC AsyncAPI bindings and lets you invoke unary and server-streaming methods over gRPC-Web.

如何安装 @bielu/scalar-grpc?

在项目目录运行 npm install @bielu/scalar-grpc,或使用 pnpm add / yarn add / bun add。

@bielu/scalar-grpc 支持 TypeScript 吗?

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

@bielu/scalar-grpc 支持 ESM 还是 CommonJS?

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

@bielu/scalar-grpc 可以商用吗?

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

@bielu/scalar-grpc 的下载量有多少?

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

@bielu/scalar-grpc 还在维护吗?

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