名称 : “ 获取社区验证器 ” 说明:“用于Get Community定义和验证整个应用程序所用数据结构的验证库” 类别:“网络开发” 寄存器:"https://github.com/getcommunity/gc-validers" 页面存档备份,存于互联网档案馆 作者:"乔伊可口" 作者Url:"https://github.com/joeygrable94" (中文(简体) ) 标记 : ["获得社区", "家庭建设者数字营销", "网站开发",, "验证库", "电视剧", "节点JS", "ValiBot" (英语) 上次更新: "2025- 10"
GC验证器
项目概况
Get社区验证器软件包提供一套验证规则和公用事业,以确保Get社区应用程序的数据完整性和一致性。 它界定和验证整个应用程序使用的数据结构,确保所有数据符合预期的格式和业务规则.
技术堆栈
使用的主要技术和工具:
- 类型脚本
- 节点JS
- 瓦利鲍特
- N
- 国家预防机制
国家预防机制
典型的工作流程 :
npm version 0.0.271-alpha.0
npm publish --tag alpha
随后的α释放:
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(中文(简体) )
- 类型应在PascalCase中(例如,
- 函数命名 : (骆驼Case)
- 函数名使用骆驼Case(例如,
datePlusDays, (中文(简体) ),hasPermission(中文(简体) )
- 函数名使用骆驼Case(例如,
- 类和Schema 命名 :( pascalCase)
- 将PascalCase用于课程和计划(例如,
PermissionCheck, (中文(简体) ),RolesWithPermissions(中文(简体) ) - 前缀实体动作计划有"S"和 CRUD 操作(例如,
UpdateClientDocument, (中文(简体) ),CreateContentPillarDocument(中文(简体) )
- 将PascalCase用于课程和计划(例如,
Git 工作流程
分支战略
production分支用于生产释放main分枝用于分级生产dev分支用于开发test分支用于测试upgrade分支用于升级依赖性feat-*分支用于新特性bugfix-*用于错误修正的分支
提交信件格式
- 获取社区跟随 常规武器委员会 输入消息的规格.
拉动请求进程
- 所有拉动请求均应由至少另一名团队成员审查,并由代码管理者批准后再合并.
- 确保所有测试在合并前通过.
- 使用描述性标题并在PR描述中提供上下文.
实例
检查用户是否可以被指定特定的资源权限
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
检查用户是否有权限访问指定的客户端实体
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