For the complete documentation index, see llms.txt. This page is also available as Markdown.

如何创建新的实体类型

什么时候需要创建一个新实体?

首先,检查现有实体是否可以解决所需的用例,以避免对解决方案进行过度设计。如果 https://github.com/decentraland/common-schemas/blob/main/src/platform/entity.ts#L13 中定义的现有实体类型都不能满足需求,那么你可能需要创建一种新的实体类型。

首先回答:

  • 这个新实体是 NFT 集合吗?

  • 如何验证所有权?

  • 它的大小会是多少?

  • 将创建多少个实体?

步骤

首先在 https://github.com/decentraland/adr 创建一个 ADR,在其中定义 schema 以及开始验证新实体的日期。

仓库

@dcl/schemas

  1. 在枚举中创建新的实体类型:https://github.com/decentraland/common-schemas/blob/main/src/platform/entity.ts#L19

  2. 在 https://github.com/decentraland/common-schemas/tree/main/src/platform 中创建文件夹和文件,生成类型和 JSON schema,例如:https://github.com/decentraland/common-schemas/blob/main/src/platform/profile/profile.ts#L20

@dcl/content-validator

实现 ADR 中定义的校验,并考虑该 ADR 的日期,代码位于 https://github.com/decentraland/content-validator/blob/main/src/validations/timestamps.ts。例如:https://github.com/decentraland/content-validator/blob/main/src/validations/items/emotes.ts#L8

  1. 在 https://github.com/decentraland/content-validator/tree/main/src/validations/access-checker 中添加检查新实体类型所有权的代码

  2. 为新类型实现 validationForType,例如:https://github.com/decentraland/content-validator/blob/main/src/validations/profile.ts#L112

  3. 在这里你需要在 https://github.com/decentraland/content-validator/blob/main/src/validations/ADR51.ts 中定义每个实体的最大大小。

@dcl/urn-resolver

  1. 如果新实体对应的是一个集合,那么不需要添加任何内容。

  2. 如果不是,则为新实体创建一个新的 urn,并在 https://github.com/decentraland/urn-resolver 中定义它,同时在 https://github.com/decentraland/urn-resolver/blob/main/src/resolvers.ts#L23 添加一个 resolver

Catalyst:Content Server

  1. 数据库无需更改。

  2. 更新上述所有已修改的库。

Catalyst:Lambdas Server

  1. 更新上述所有已修改的库。

  2. 检查是否需要更新 profile sanitization(/lambdas/profiles 端点)

  3. 检查是否需要更新 erc collections 端点(/lambdas/collections 端点)

  4. 创建一个端点来展示该实体,例如 /lambdas/wearables-by-owner

最后更新于