@getcommunity/gc-validators

中文文档
0.0.343发布于 2026/11/03ISCTypeScriptESM + CJS近 30 天下载 2538

Schema Validator for GetCommunity web-stack types

原始使用文档
文档目录11 节
  1. name: "Get Community Validators" description: "A validation…
  2. Project Overview
  3. Tech Stack
  4. NPM Prereleases
  5. Development Guidelines
  6. Code Style
  7. Naming Conventions
  8. Git Workflow
  9. Examples
  10. Check if a user can be assigned a specific resource permiss…
  11. Check if a user has permission to access a client assigned …

name: "Get Community Validators" description: "A validation library for Get Community defining and validating data structures used throughout the application." category: "Web Development" repository: "https://github.com/getcommunity/gc-validators" author: "Joey Grable" authorUrl: "https://github.com/joeygrable94" tags: ["Get Community", "homebuilder digital marketing", "website development", "validation library", "TypeScript", "NodeJS", "ValiBot"] lastUpdated: "2025-10"

🪨 GC Validators

@getcommunity/gc-validators

Project Overview

The Get Community Validators package provides a set of validation rules and utilities for ensuring data integrity and consistency across the Get Community application. It defines and validates data structures used throughout the application, ensuring that all data conforms to expected formats and business rules.

Tech Stack

Main technologies and tools used:

  • TypeScript
  • NodeJS
  • ValiBot
  • Pnpm
  • NPM

NPM Prereleases

Typical workflow:

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

Then subsequent alpha releases:

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

Development Guidelines

Code Style

  • Use consistent code formatting tools
    • Use Prettier for code formatting
    • Use ESLint for linting
    • Use pre-commit hooks for code quality checks
  • Follow language-specific best practices
  • Keep code clean and readable

Naming Conventions

  • File naming: (snake-case)
    • all lowercase with hyphens
    • append file type as suffix
    • e.g., entity-name.tsx, pagination-constants.ts
  • Variable naming: (PascalCase, or UPPER_SNAKE_CASE)
    • types should be in PascalCase (e.g., ClientDocument, BlogPostDocument)
    • global constants should be in UPPER_SNAKE_CASE (e.g., LIMIT_SHORT_STRING_MAX_LENGTH)
  • Function naming: (camelCase)
    • use camelCase for function names (e.g., datePlusDays, hasPermission)
  • Class and Schema naming: (PascalCase)
    • use PascalCase for classes and schemas (e.g., PermissionCheck, RolesWithPermissions)
    • prefix entity action schemas with "S" and the CRUD operation (e.g., UpdateClientDocument, CreateContentPillarDocument)

Git Workflow

Branching Strategy

  • production branch is used for production releases
  • main branch is used for staged production
  • dev branch is used for development
  • test branch is used for testing
  • upgrade branch is used for upgrading dependencies
  • feat-* branches are used for new features
  • bugfix-* branches are used for bug fixes

Commit message format

Pull Request process

  • All pull requests should be reviewed by at least one other team member and approved by by a code manager before merging.
  • Ensure that all tests pass before merging.
  • Use descriptive titles and provide context in the PR description.

Examples

Check if a user can be assigned a specific resource permission

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: "[email protected]",
  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

Check if a user has permission to access a client assigned entity

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: "[email protected]",
  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 共发布 372 个版本,首次发布于 2025/07/15;过去 12 个月发布了 231 个版本。

版本发布日期距今
0.0.343latest2026/11/0313 天前
0.0.3422026/11/0313 天前
0.0.3412026/10/2720 天前
0.0.3402026/10/2720 天前
0.0.3392026/10/2720 天前
0.0.3382026/10/2720 天前

其他发布通道:alpha → 0.0.288-alpha.5。

关于 @getcommunity/gc-validators 的常见问题

@getcommunity/gc-validators 是什么?

Schema Validator for GetCommunity web-stack types

如何安装 @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 和提交记录判断。