@forestadmin-experimental/rpc-agent

中文文档
2.11.0发布于 2026/10/26GPL-3.0TypeScriptCommonJS构建来源已验证近 30 天下载 3341

The RPC agent is created to split your data into microservice, combined with a real agent and a RPC data source, you wil be able to acces all your collection as this is a normal agent.

原始使用文档
文档目录5 节
  1. Examples
  2. Case 1 declaring relationship inside the gateway
  3. Case 2 using RPC datasource inside RPC agent
  4. Case 2 declaring relationship between RPC datasource on a R…
  5. Examples

The RPC agent is created to split your data into microservice, combined with a real agent and a RPC data source, you wil be able to acces all your collection as this is a normal agent.

Installation

  • install the package @forestadmin-experimental/rpc-agent.
  • give options like a real agent.
const { createRpcAgent } = require('@forestadmin-experimental/rpc-agent');

const agent = createRpcAgent({
  authSecret: process.env.FOREST_AUTH_SECRET,
  isProduction: process.env.NODE_ENV === 'production',
  loggerLevel: 'Info',
});
// use the agent like a real one.

Deal with nested RPC data source and relationship

Be cautious when using an RPC data source within an RPC agent. Since an RPC agent behaves similarly to a real one, a schema is created and utilized by the RPC data source. Therefore, all collections added to it should be within this schema, which can potentially cause duplication issues.

Unlike removeCollection, the markCollectionsAsRpc function removes the collection from the schema but retains the defined relationships. If you declare relationships on a collection marked as RPC, you should use the provided plugin on the gateway to perform the reconciliation.

Examples

Given this structure:

  • One RPC agent used to manage Users.
  • One RPC agent used to manage Groups.
  • One RPC agent used to manage Projects.
  • One agent used as a gateway.

Case 1 declaring relationship inside the gateway

Declare your relation as usual, like below:

gateway
  .createRpcDataSource(/*from the user RPC agent*/)
  .createRpcDataSource(/*from the project RPC agent*/)
  .createRpcDataSource(/*from the group RPC agent*/)
  .customizeCollection('user', collection => {
    collection.addManyToOneRelation('group', 'group', {
      foreignKey: 'group_id',
    });
  })
  .customizeCollection('project', collection => {
    collection.addManyToOneRelation('group', 'group', {
      foreignKey: 'group_id',
    });
  })
  .customizeCollection('group', collection => {
    collection
      .addOneToManyRelation('users', 'user', {
        originKey: 'group_id',
      })
      .addOneToManyRelation('projects', 'project', {
        originKey: 'group_id',
      });
  });

Case 2 using RPC datasource inside RPC agent

You should combine the data sources before using them on the gateway. In this example, you only use the group agent in the user agent, not in multiple places. Therefore, there is no need to use markCollectionsAsRpc, as shown below:

/* define user agent and use group agent as a RPC data source
* define some relationship between both data source
*/
userAgent
  .createcreateSqlDataSource(...)
  .createRpcDataSource(/*from the group RPC agent*/)
  .customizeCollection('user', collection => {
    collection.addManyToOneRelation('group', 'group', {
      foreignKey: 'group_id',
    });
  })
  .customizeCollection('group', collection => {
    collection.addOneToManyRelation('users', 'user', {
      originKey: 'group_id',
    });
  });

/* define the gateway and use agragated agent
* all collection and relationship defined in the user agent will be import as a datasource
*/
gateway
  .createRpcDataSource(/*from the user RPC agent*/)
  .createRpcDataSource(/*from the project RPC agent*/)

Case 2 declaring relationship between RPC datasource on a RPC agent

If you have complex datasource relationship and usage, see how to use markCollectionsAsRpc and the reconciliateRpc plugin below.

/* define user agent and use group agent as a RPC data source
* define some relationship between both data source
*/
userAgent
  .createcreateSqlDataSource(...)
  .createRpcDataSource(/*from the group RPC agent*/)
  .customizeCollection('user', collection => {
    collection.addManyToOneRelation('group', 'group', {
      foreignKey: 'group_id',
    });
  })
  .customizeCollection('group', collection => {
    collection.addOneToManyRelation('users', 'user', {
      originKey: 'group_id',
    });
  })
  .markCollectionsAsRpc('group');

/* define project agent and use group agent as a RPC data source
* define some relationship between both data source
*/
projectAgent
  .createcreateSqlDataSource(...)
  .createRpcDataSource(/*from the group RPC agent*/)
  .customizeCollection('project', collection => {
    collection.addManyToOneRelation('group', 'group', {
      foreignKey: 'group_id',
    });
  })
  .customizeCollection('group', collection => {
    collection.addOneToManyRelation('projects', 'project', {
      originKey: 'group_id',
    });
  })
  .markCollectionsAsRpc('group');

// define the gateway
gateway
  .createRpcDataSource(/*from the user RPC agent*/)
  .createRpcDataSource(/*from the project RPC agent*/)
  .createRpcDataSource(/*from the group RPC agent*/)
  .use(reconciliateRpc);

Deal with disableSearch customization

To make disableSearch customization work on the gateway, you should use the provided plugin

Examples


/* define project agent and disable the search behavior on the collection
*/
projectAgent
  .createcreateSqlDataSource(...)
  .customizeCollection('project', collection => {
    collecion.disableSearch();
  });

// define the gateway
gateway
  .createRpcDataSource(/*from the project RPC agent*/)
  .use(reconciliateRpc);

版本与发布记录

@forestadmin-experimental/rpc-agent 共发布 20 个版本,首次发布于 2024/07/10;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
2.11.0latest2026/10/2620 天前
2.10.12026/06/164 个月前
2.10.02026/05/275 个月前
2.9.22026/05/215 个月前
2.9.12026/05/066 个月前
2.9.02026/03/277 个月前

关于 @forestadmin-experimental/rpc-agent 的常见问题

@forestadmin-experimental/rpc-agent 是什么?

The RPC agent is created to split your data into microservice, combined with a real agent and a RPC data source, you wil be able to acces all your collection as this is a normal agent.

如何安装 @forestadmin-experimental/rpc-agent?

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

@forestadmin-experimental/rpc-agent 支持 TypeScript 吗?

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

@forestadmin-experimental/rpc-agent 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@forestadmin-experimental/rpc-agent 可以商用吗?

@forestadmin-experimental/rpc-agent 使用 GPL-3.0 许可。强 Copyleft:分发包含该代码的软件时,整个作品需以 GPL-3.0 兼容许可开源,并附带专利与反锁定条款。仅内部使用不触发此义务。以上为概括,不构成法律意见,请以许可原文为准。

@forestadmin-experimental/rpc-agent 的下载量有多少?

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

@forestadmin-experimental/rpc-agent 还在维护吗?

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