@dcl/schemas

中文文档
27.4.0发布于 2026/10/29Apache-2.0TypeScriptCommonJS构建来源已验证近 30 天下载 5.8万

Decentraland data structure interfaces and validators for TypeScript-based projects.

原始使用文档
文档目录4 节
  1. Scoped auth-chain adoption (ADR-162)
  2. Design Guidelines
  3. Collaborator's Guide
  4. Versioning and Publishing

common-schemas

Decentraland data structure interfaces and validators for TypeScript-based projects.

Install it with:

npm i @dcl/schemas

Scoped auth-chain adoption (ADR-162)

AuthLink and AuthChain recognize ECDSA_SCOPED_EPHEMERAL and ECDSA_EIP_1654_SCOPED_EPHEMERAL. This validates the link structure only; consumers must still verify signatures and authorize the service, operation, and resource using a scoped-aware verifier.

After upgrading, chains with these types pass the schema enum check. Services that do not accept scoped logins, including Catalyst and Worlds deployments using such verifiers, reject them later during cryptographic validation instead. The error message therefore changes from a schema enum error to a verifier error.

Once this schemas version is released, core-libs can adopt these enum members and replace its temporary ScopedAuthLinkType definitions and casts. Consumers should upgrade both schemas and scoped-aware authorization before accepting scoped logins.

Design Guidelines

  • Prevent type problems across projects
  • Fail as early as possible, aim for compile-time
  • Preserve user optionality through runtime helpers
  • Prefer no-cost implementations and allow no-dependency import
  • Code is written once, read hundreds of times

Implementation decisions:

  • The main entrypoint should only export types
  • Every type is also a namespace
  • Type names are PascalCase
  • Validators and schemas are camelCase

Collaborator's Guide

Generating types, validators and schemas

This library export types that also act as values. This is achieved through TypeScript's namespaces. This means that every type imported from this library can also be used as a JS object. These types will include two properties named schema and validate. namespaces in typescript can be considered "cost imports".

Example Type Definition

// Declare type
export type MyType = {
  value: number;
};

// Declare namespace for the type
export namespace MyType {
  export const schema: Schema<MyType> = {
    type: "object",
    properties: {
      value: { type: number },
    },
    additionalProperties: false,
    required: ["value"],
  };

  export const validate = generateValidator<MyType>(schema);
}

MyType can now be both used as type const a: MyType or as an object MyType.validate(a).

Beware that validate has type ValidateFunction<T> which ajv creates automatically. When writing new validations always try to implement it as an ajv validation, even if custom code is needed. See here.

Particularly, beware of using the library like this, because reports by the validator.validate function are lost and never returned to the caller.

const validator = generateValidator<MyType>(schema);
export const validate = (mt: MyType) =>
  validator.validate(mt) && otherValidations(mt);

Code ownership

Please add types and schemas of your domain into the src/<team> folder, also add your team to the CODEOWNERS repository to make sure nobody accidentally changes it without your team noticing it.

Informing changes

Please notify about changes to the schemas to relevant teams by adding the whole team (i.e. @decentraland/dapps) as reviewers of the pull requests.

It is recommended to subscribe to this repository (using the Watch function) if you use any internal part of the Decentraland ecosystem.

Making changes

To make sure the relevant persons and groups are aware of changes in these types, there's an api-extraction process executed with https://api-extractor.com that creates a report file for review between commits. It gets included as part of PRs for easier read.

To generate the file before submitting a PR, run npm run refresh-api. This is executed by the CI by runnig npm run check-api. It also verifies that the generated file matches the exported types.

Versioning and Publishing

Versions are handled manually using Github releases and semver.

Main branch is automatically published to the @next dist tag to test integrations before final releases happen.

版本与发布记录

@dcl/schemas 共发布 720 个版本,首次发布于 2021/02/12;过去 12 个月发布了 84 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
27.4.0latest2026/10/2913 天前
27.3.1-20261028210140.commit-fe4730c2026/10/2913 天前
27.3.02026/10/1230 天前
27.2.1-20261012104125.commit-7d0fc172026/10/1230 天前
27.2.02026/09/181 个月前
27.1.1-20260917155347.commit-2f306502026/09/171 个月前

其他发布通道:rc → 1.3.0-rc,tag-add-emotes → 4.14.2-20220608182026.commit-46a9277,tag-5.14 → 5.13.2-20220829183340.commit-a539bbf,tag-fast-bootstrapping → 5.28.1-20221108202320.commit-a93fe13,tag-fast-bootstrapping-2 → 5.28.1-20221108203808.commit-3da75ad,tag-fast-bootstrapping-3 → 5.28.1-20221108204939.commit-131a7d3。

关于 @dcl/schemas 的常见问题

@dcl/schemas 是什么?

Decentraland data structure interfaces and validators for TypeScript-based projects.

如何安装 @dcl/schemas?

在项目目录运行 npm install @dcl/schemas,或使用 pnpm add / yarn add / bun add。

@dcl/schemas 支持 TypeScript 吗?

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

@dcl/schemas 支持 ESM 还是 CommonJS?

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

@dcl/schemas 可以商用吗?

@dcl/schemas 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dcl/schemas 的下载量有多少?

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

@dcl/schemas 还在维护吗?

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