# @getcommunity/gc-validators 中文文档

规范地址：https://npmcn.com/package/%40getcommunity/gc-validators/

版本：0\.0\.343
npm 元数据更新时间：2026-11-03T00:03:01.294Z
中文译文更新时间：2026-11-16T07:10:44.975Z
软件包许可：ISC

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40getcommunity/gc-validators
原文对照：https://npmcn.com/package/%40getcommunity/gc-validators/?lang=original
项目主页：https://github.com/getcommunity/gc-validators#readme
源码仓库：https://github.com/GetCommunity/gc-validators

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：2.5 MB，853 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：1 个
- peer 依赖：randexp ^0\.5\.3，valibot ^1\.4\.1
- 首次发布：2025-07-15T15:37:00.689Z
- 最新版本发布：2026-11-03T00:03:01.115Z
- 近 30 天下载量：2538（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：372（近 12 个月 231 个）

## 中文简介

GetCommunity Web- stack 类型的 Schema 校验器

## 安装

```sh
npm install @getcommunity/gc-validators
```

也可以使用：`pnpm add @getcommunity/gc-validators`、`yarn add @getcommunity/gc-validators`、`bun add @getcommunity/gc-validators`

## README

* * *

## 名称 : “ 获取社区验证器 ” 说明:“用于Get Community定义和验证整个应用程序所用数据结构的验证库” 类别:“网络开发” 寄存器:"https://github.com/getcommunity/gc-validers" 页面存档备份,存于互联网档案馆 作者:"乔伊可口" 作者Url:"https://github.com/joeygrable94" (中文(简体) ) 标记 : \["获得社区", "家庭建设者数字营销", "网站开发",, "验证库", "电视剧", "节点JS", "ValiBot" (英语) 上次更新: "2025- 10"

# GC验证器

[@ getcommunity/ gc- 验证器](https://github.com/getcommunity/gc-validators)

## 项目概况

Get社区验证器软件包提供一套验证规则和公用事业,以确保Get社区应用程序的数据完整性和一致性。 它界定和验证整个应用程序使用的数据结构,确保所有数据符合预期的格式和业务规则.

## 技术堆栈

使用的主要技术和工具:

-   类型脚本
-   节点JS
-   瓦利鲍特
-   N
-   国家预防机制

## 国家预防机制

典型的工作流程 :

```bash
npm version 0.0.271-alpha.0
npm publish --tag alpha
```

随后的α释放:

```bash
npm version 0.0.271-alpha.1
npm publish --tag alpha
```

## 发展指导方针

### 代码样式

-   使用一致的代码格式化工具
    -   使用 Pretier 代码格式化
    -   使用 ESLint 进行林入
    -   使用预先承诺的钩子进行代码质量检查
-   遵循特定语文的最佳做法
-   保持代码清洁和可读

### 命名公约

-   文件命名 : (snake- case)
    -   所有带连字符的小写
    -   附加文件类型为后缀
    -   例如, `entity-name.tsx`, (中文(简体) ), `pagination-constants.ts`
-   变量命名 : (PascalCase, 或 UPPER SNAKE CASE)
    -   类型应在PascalCase中(例如, `ClientDocument`, (中文(简体) ), `BlogPostDocument`(中文(简体) )
    -   全球常数应在UPPER SNAKE CASE中(例如, `LIMIT_SHORT_STRING_MAX_LENGTH`(中文(简体) )
-   函数命名 : (骆驼Case)
    -   函数名使用骆驼Case(例如, `datePlusDays`, (中文(简体) ), `hasPermission`(中文(简体) )
-   类和Schema 命名 :( pascalCase)
    -   将PascalCase用于课程和计划(例如, `PermissionCheck`, (中文(简体) ), `RolesWithPermissions`(中文(简体) )
    -   前缀实体动作计划有"S"和 CRUD 操作(例如, `UpdateClientDocument`, (中文(简体) ), `CreateContentPillarDocument`(中文(简体) )

### Git 工作流程

#### 分支战略

-   `production` 分支用于生产释放
-   `main` 分枝用于分级生产
-   `dev` 分支用于开发
-   `test` 分支用于测试
-   `upgrade` 分支用于升级依赖性
-   `feat-*` 分支用于新特性
-   `bugfix-*` 用于错误修正的分支

#### 提交信件格式

-   获取社区跟随 [常规武器委员会](https://www.conventionalcommits.org/en/v1.0.0/#summary) 输入消息的规格.

#### 拉动请求进程

-   所有拉动请求均应由至少另一名团队成员审查,并由代码管理者批准后再合并.
-   确保所有测试在合并前通过.
-   使用描述性标题并在PR描述中提供上下文.

## 实例

### 检查用户是否可以被指定特定的资源权限

```ts
const userDoc: UserDocument = {
  id: 1,
  documentId: "1234asdfhjkl",
  createdAt: "2024-01-01T00:00:00.000Z",
  updatedAt: "2024-01-01T00:00:00.000Z",
  publishedAt: "2024-01-01T00:00:00.000Z",
  username: "tester",
  email: "test@test.com",
  provider: "local",
  confirmed: true,
  blocked: true,
  clerk_user_id: "",
}
const user: AuthorizedUserDocument = {
  ...userDoc,
  role: {
    id: 1,
    documentId: "1234asdfhjkl",
    createdAt: "2024-01-01T00:00:00.000Z",
    updatedAt: "2024-01-01T00:00:00.000Z",
    publishedAt: "2024-01-01T00:00:00.000Z",
    type: "employee",
    name: "Employee",
    description: "Employee role with access to client data",
    permissions: [],
  },
  account: {
    id: 1,
    documentId: "1234asdfhjkl",
    createdAt: "2024-01-01T00:00:00.000Z",
    updatedAt: "2024-01-01T00:00:00.000Z",
    publishedAt: "2024-01-01T00:00:00.000Z",
    preferred_name: "Test Account",
    first_name: "Test",
    last_name: "User",
  },
}

// Check if user can be assigned permission to create client projects
canAssignPermission(user, "client-project", "create")
// true
```

### 检查用户是否有权限访问指定的客户端实体

```ts
const userDoc: UserDocument = {
  id: 1,
  documentId: "1234asdfhjkl",
  createdAt: "2024-01-01T00:00:00.000Z",
  updatedAt: "2024-01-01T00:00:00.000Z",
  publishedAt: "2024-01-01T00:00:00.000Z",
  username: "tester",
  email: "test@test.com",
  provider: "local",
  confirmed: true,
  blocked: true,
  clerk_user_id: ""
}
const user: AuthorizedUserDocument = {
  ...userDoc,
  role: {
    id: 1,
    documentId: "1234asdfhjkl",
    createdAt: "2024-01-01T00:00:00.000Z",
    updatedAt: "2024-01-01T00:00:00.000Z",
    publishedAt: "2024-01-01T00:00:00.000Z",
    type: "employee",
    name: "Employee",
    description: "Employee role with access to client data",
    permissions: []
  },
  account: {
    id: 1,
    documentId: "1234asdfhjkl",
    createdAt: "2024-01-01T00:00:00.000Z",
    updatedAt: "2024-01-01T00:00:00.000Z",
    publishedAt: "2024-01-01T00:00:00.000Z",
    preferred_name: "Test Account",
    first_name: "Test",
    last_name: "User"
  }
}
const client: ClientDocument = {
  id: 1,
  documentId: "1234asdfhjkl",
  createdAt: "2024-01-01T00:00:00.000Z",
  updatedAt: "2024-01-01T00:00:00.000Z",
  publishedAt: "2024-01-01T00:00:00.000Z",
  title: "Test Client",
  teamwork_name: "Test Client",
  teamwork_id: "123456",
  is_featured: true,
  utm_sheet_id: "asdkjhflawhfl",
  allow_create_utm_link: true,
  is_organic_social: true,
  is_paid_media: true,
  is_active: true,
  classification: ["organic", "paid"]
}
const clientUserStatus: ClientUserDocumentStatus = {
  verified: true,
  clientUser: {
    id: 1,
    documentId: "1234asdfhjkl",
    createdAt: "2024-01-01T00:00:00.000Z",
    updatedAt: "2024-01-01T00:00:00.000Z",
    publishedAt: "2024-01-01T00:00:00.000Z",
    client: client,
    user: userDoc,
    scopes: ["client:access", "client:manager", "client-project:udate"]
  },
  scopes: ["client:access", "client:manager", "client-project:udate"]
}
const clientProject: ClientProjectDocument = {
  id: 1,
  documentId: "1234asdfhjkl",
  createdAt: "2024-01-01T00:00:00.000Z",
  updatedAt: "2024-01-01T00:00:00.000Z",
  publishedAt: "2024-01-01T00:00:00.000Z",
  title: "Test Client Project",
  slug: "test-client-project",
  project_status: ["for-sale"]
  project_phase: "p1"
  featured_image: null
}

// Check if user has permission to create a client project
hasPermission(user, clientUserStatus, "client-project", "create")
// > false

// Check if user has permission to update a client project
hasPermission(user, clientUserStatus, "client-project", "update", clientProject)
// > true

// Check if user has permission to access a client
hasPermission(user, clientUserStatus, "client", "access", client)
// > true
```

## 常见问题

### @getcommunity/gc-validators 是什么？

GetCommunity Web- stack 类型的 Schema 校验器

### 如何安装 @getcommunity/gc-validators？

在项目目录运行 npm install @getcommunity/gc-validators，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：randexp（^0\.5\.3）、valibot（^1\.4\.1）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @getcommunity/gc-validators 支持 TypeScript 吗？

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

### @getcommunity/gc-validators 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @getcommunity/gc-validators 可以商用吗？

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

### @getcommunity/gc-validators 的下载量有多少？

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

### @getcommunity/gc-validators 还在维护吗？

最新版本 0\.0\.343 发布于 2026/11/03（13 天前）；至今共发布 372 个版本，其中过去 12 个月发布了 231 个；首次发布于 2025/07/15。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

