@ceramicnetwork/rpc-postmessage

中文文档
0.6.1发布于 2022/03/25(Apache-2.0 OR MIT)TypeScriptES Module近 30 天下载 2200
中文使用文档
文档目录15 节
  1. 安装
  2. 使用量
  3. 类型
  4. 请求下载
  5. 已处理的
  6. 服务器选项
  7. 命名空间服务器选项
  8. 命名空间客户端运输
  9. APIs 密码
  10. 服务( )
  11. 创建Name 空间请求汉德勒操作器( )
  12. 创建Name spaceServer ()
  13. 创建Name 空间发送请求 ()
  14. 创建“ 空间密度 ”
  15. 许可证

后Message RPC 软件

RPC 公用事业 使用 邮件

安装

npm install @ceramicnetwork/rpc-postmessage

使用量

import { createNamespaceClient, createNamespaceServer } from '@ceramicnetwork/rpc-postmessage'

type Methods = {
  foo: { result: string }
}

const server = createNamespaceServer<Methods>({
  target: window, // Listens to requests on window
  namespace: 'test',
  methods: { foo: () => 'bar' },
}).subscribe()

// Sends requests and receives responses on window
const transport = createPostMessageTransport(window, window, { postMessageArguments: ['*'] })

const client = createNamespaceClient(transport, 'test')
await client.request('foo') // 'bar'

// Stop server when done
server.unsubscribe()

类型

请求下载

用途 RPCMethods 财务报告和审定财务报表 RPCRequest

type RequestPayload<Message, Methods extends RPCMethods, K extends keyof Methods> = {
  type: 'request'
  message: Message
  request: RPCRequest<Methods, K>
}

已处理的

用途 RPCMethods, (中文(简体) ), RPCRequest 财务报告和审定财务报表 RPCResponse

type HandledPayload<Message, Methods extends RPCMethods, K extends keyof Methods> = {
  type: 'handled'
  message: Message
  request: RPCRequest<Methods, K>
  response: RPCResponse<Methods, K> | null
}

服务器选项

用途 RPCMethods, (中文(简体) ), HandlerMethods 财务报告和审定财务报表 HandlerOptions

type ServerOptions<Context, Methods extends RPCMethods> = HandlerOptions<Context, Methods> & {
  target: PostMessageTarget
  methods: HandlerMethods<Context, Methods>
}

命名空间服务器选项

type NamespaceServerOptions<
  Methods extends RPCMethods,
  Namespace extends string = string,
  Message = IncomingMessage<Wrapped<RPCRequest<Methods, keyof Methods>, Namespace>>
> = ServerOptions<Message, Methods> & {
  namespace: Namespace
  filter?: string | Array<string> | MessageFilter
}

命名空间客户端运输

type NamespaceClientTransport<
  Methods extends RPCMethods,
  Namespace extends string,
  Incoming = IncomingMessage<Wrapped<RPCResponse<Methods, keyof Methods>, Namespace>>,
  Outgoing = Wrapped<RPCRequest<Methods, keyof Methods>, Namespace>
> = TransportSubject<Incoming, Outgoing>

APIs 密码

服务( )

接收请求并发送对所提供的答复 target

类型参数

  1. Methods extends RPCMethods

参数

  1. options: ServerOptions<null, Methods>

回返 Subscription

创建Name 空间请求汉德勒操作器( )

类型参数

  1. Methods extends RPCMethods
  2. Namespace extends string = string
  3. Message = IncomingMessage<Wrapped<RPCRequest<Methods, keyof Methods>, Namespace>>

参数

  1. methods: HandlerMethods<Message, Methods>
  2. namespace: Namespace
  3. options?: HandlerOptions<Message, Methods> = {}

回返 OperatorFunction<Message, HandledPayload<Message, Methods, keyof Methods>>

创建Name spaceServer ()

类型参数

  1. Methods extends RPCMethods
  2. Namespace extends string = string
  3. Request = Wrapped<RPCRequest<Methods, keyof Methods>, Namespace>

参数

  1. options: NamespaceServerOptions<Methods, Namespace, IncomingMessage<Request>>

回返 Observable<HandledPayload<IncomingMessage<Request>, Methods, keyof Methods>>

创建Name 空间发送请求 ()

类型参数

  1. Methods extends RPCMethods
  2. Namespace extends string = string

参数

  1. transport: NamespaceClientTransport<Methods, Namespace>
  2. namespace: Namespace
  3. options?: UnwrapObservableOptions

回返 SendRequestFunc<Methods>

创建“ 空间密度 ”

类型参数

  1. Methods extends RPCMethods
  2. Namespace extends string = string

参数

  1. transport: NamespaceClientTransport<Methods, Namespace>
  2. namespace: Namespace
  3. options?: UnwrapObservableOptions

回返 RPCClient<Methods>

许可证

Apache-2.0或麻省理工学院

版本与发布记录

@ceramicnetwork/rpc-postmessage 共发布 10 个版本,首次发布于 2021/03/08;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.6.1latest2022/03/254 年前
0.6.02022/01/184 年前
0.5.02021/09/295 年前
0.4.12021/09/095 年前
0.4.02021/03/315 年前
0.3.12021/03/255 年前

关于 @ceramicnetwork/rpc-postmessage 的常见问题

@ceramicnetwork/rpc-postmessage 是什么?

RPC 公用事业 使用 邮件

如何安装 @ceramicnetwork/rpc-postmessage?

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

@ceramicnetwork/rpc-postmessage 支持 TypeScript 吗?

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

@ceramicnetwork/rpc-postmessage 支持 ESM 还是 CommonJS?

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

@ceramicnetwork/rpc-postmessage 需要什么版本的 Node.js?

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

@ceramicnetwork/rpc-postmessage 可以商用吗?

@ceramicnetwork/rpc-postmessage 使用 (Apache-2.0 OR MIT) 许可。可在 Apache-2.0、MIT 中任选其一遵守。选择 Apache-2.0 时,宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@ceramicnetwork/rpc-postmessage 的下载量有多少?

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

@ceramicnetwork/rpc-postmessage 还在维护吗?

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