repo-structure-navigate
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseValibot Repository Structure
Valibot 仓库结构
Monorepo Layout
单仓库(Monorepo)布局
valibot/
├── library/ # Core valibot package (zero dependencies)
├── packages/
│ ├── i18n/ # Translated error messages (25+ languages)
│ └── to-json-schema/ # JSON Schema converter
├── codemod/
│ ├── migrate-to-v0.31.0/ # Version migration
│ └── zod-to-valibot/ # Zod converter
├── website/ # valibot.dev (Qwik + Vite)
├── brand/ # Brand assets
├── skills/ # Agent skills (this folder)
└── prompts/ # Legacy AI agent guidesvalibot/
├── library/ # 核心Valibot包(零依赖)
├── packages/
│ ├── i18n/ # 多语言错误提示(支持25+种语言)
│ └── to-json-schema/ # JSON Schema转换器
├── codemod/
│ ├── migrate-to-v0.31.0/ # 版本迁移工具
│ └── zod-to-valibot/ # Zod转Valibot工具
├── website/ # valibot.dev官网(基于Qwik + Vite)
├── brand/ # 品牌资源
├── skills/ # Agent技能(当前目录)
└── prompts/ # 旧版AI Agent指南Core Library (/library/src/
)
/library/src/核心库(/library/src/
)
/library/src/Directory Structure
目录结构
| Directory | Purpose | Examples |
|---|---|---|
| Data type validators | |
| Validation & transformation | |
| High-level API | |
| TypeScript definitions | |
| Internal helpers (prefixed | |
| Global state | Config, message storage |
| 目录 | 用途 | 示例 |
|---|---|---|
| 数据类型验证器 | |
| 验证与转换操作 | |
| 高级API | |
| TypeScript类型定义 | |
| 内部辅助工具(前缀 | |
| 全局状态管理 | 配置、消息存储 |
Schema Categories
Schema分类
- Primitives: ,
string,number,boolean,bigint,date,symbol,blobfile - Objects: ,
object,strictObject,looseObjectobjectWithRest - Arrays: ,
array,tuple,strictTuple,looseTupletupleWithRest - Advanced: ,
union,variant,intersect,record,map,set,lazycustom - Modifiers: ,
optional,nullable,nullish,nonNullable,nonNullishnonOptional
- 基础类型:,
string,number,boolean,bigint,date,symbol,blobfile - 对象类型:,
object,strictObject,looseObjectobjectWithRest - 数组类型:,
array,tuple,strictTuple,looseTupletupleWithRest - 高级类型:,
union,variant,intersect,record,map,set,lazycustom - 修饰符:,
optional,nullable,nullish,nonNullable,nonNullishnonOptional
Action Types
Action类型
Validation (return issues): , , , , , ,
emailurluuidregexminLengthmaxValuecheckTransformation (modify data): , , , ,
trimtoLowerCasetoUpperCasemapItemstransformMetadata: , , , ,
brandflavormetadatadescriptiontitle验证类(返回错误信息):, , , , , ,
emailurluuidregexminLengthmaxValuecheck转换类(修改数据):, , , ,
trimtoLowerCasetoUpperCasemapItemstransform元数据类:, , , ,
brandflavormetadatadescriptiontitleFile Naming Convention
文件命名规范
Each schema/action/method has its own directory:
schemas/string/
├── string.ts # Implementation
├── string.test.ts # Runtime tests
├── string.test-d.ts # Type tests
└── index.ts # Re-export每个schema/action/method都有独立目录:
schemas/string/
├── string.ts # 实现代码
├── string.test.ts # 运行时测试
├── string.test-d.ts # 类型测试
└── index.ts # 导出入口Core Patterns
核心模式
Schemas define data types:
typescript
export interface StringSchema<TMessage> extends BaseSchema<...> {
readonly kind: 'schema';
readonly type: 'string';
// ...
}Actions validate/transform in pipelines:
typescript
export interface EmailAction<TInput, TMessage> extends BaseValidation<...> {
readonly kind: 'validation';
readonly type: 'email';
// ...
}Methods provide API functions:
typescript
export function parse<TSchema>(
schema: TSchema,
input: unknown
): InferOutput<TSchema>;Schemas定义数据类型:
typescript
export interface StringSchema<TMessage> extends BaseSchema<...> {
readonly kind: 'schema';
readonly type: 'string';
// ...
}Actions在流水线中执行验证/转换:
typescript
export interface EmailAction<TInput, TMessage> extends BaseValidation<...> {
readonly kind: 'validation';
readonly type: 'email';
// ...
}Methods提供API函数:
typescript
export function parse<TSchema>(
schema: TSchema,
input: unknown
): InferOutput<TSchema>;Key Types
关键类型
- ,
BaseSchema,BaseValidation- Base interfacesBaseTransformation - ,
InferOutput<T>,InferInput<T>- Type inferenceInferIssue<T> - ,
Config,ErrorMessage<T>- Configuration and errorsBaseIssue<T> - property - Standard Schema compatibility
'~standard'
- ,
BaseSchema,BaseValidation- 基础接口BaseTransformation - ,
InferOutput<T>,InferInput<T>- 类型推断InferIssue<T> - ,
Config,ErrorMessage<T>- 配置与错误相关BaseIssue<T> - 属性 - 兼容Standard Schema
'~standard'
Website (/website/src/routes/
)
/website/src/routes/官网(/website/src/routes/
)
/website/src/routes/API Documentation
API文档
routes/api/
├── (schemas)/string/ # Schema docs
│ ├── index.mdx # MDX content
│ └── properties.ts # Type definitions
├── (actions)/email/ # Action docs
├── (methods)/parse/ # Method docs
├── (types)/StringSchema/ # Type docs
└── menu.md # Navigationroutes/api/
├── (schemas)/string/ # Schema文档
│ ├── index.mdx # MDX内容
│ └── properties.ts # 类型定义
├── (actions)/email/ # Action文档
├── (methods)/parse/ # Method文档
├── (types)/StringSchema/ # 类型文档
└── menu.md # 导航菜单Guides
指南文档
routes/guides/
├── (get-started)/ # Intro, installation
├── (main-concepts)/ # Schemas, pipelines, parsing
├── (schemas)/ # Objects, arrays, unions
├── (advanced)/ # Async, i18n, JSON Schema
├── (migration)/ # Version upgrades
└── menu.md # Navigationroutes/guides/
├── (get-started)/ # 入门、安装
├── (main-concepts)/ # Schema、流水线、解析
├── (schemas)/ # 对象、数组、联合类型
├── (advanced)/ # 异步、i18n、JSON Schema
├── (migration)/ # 版本升级
└── menu.md # 导航菜单Development
开发相关
Playground
实验场
Use for quick experimentation.
library/playground.ts使用进行快速实验。
library/playground.tsAdding a Schema/Action
添加新的Schema/Action
- Create directory:
library/src/schemas/yourSchema/ - Create files: ,
yourSchema.ts,yourSchema.test.ts,yourSchema.test-d.tsindex.ts - Follow existing patterns (copy similar implementation)
- Export from category
index.ts - Run
pnpm -C library test
- 创建目录:
library/src/schemas/yourSchema/ - 创建文件:,
yourSchema.ts,yourSchema.test.ts,yourSchema.test-d.tsindex.ts - 遵循现有代码模式(复制类似实现)
- 在分类的中导出
index.ts - 运行
pnpm -C library test
Modifying Core Types
修改核心类型
⚠️ Changes to affect the entire library. Always run full test suite.
library/src/types/⚠️ 修改会影响整个库。请务必运行完整测试套件。
library/src/types/Quick Lookups
快速查询
| Looking for... | Location |
|---|---|
| Schema implementation | |
| Action implementation | |
| Method implementation | |
| Type definitions | |
| Internal utilities | |
| Error messages (i18n) | |
| API docs page | |
| Guide page | |
| Tests | Same directory as source, |
| Type tests | Same directory as source, |
| 查找内容 | 位置 |
|---|---|
| Schema实现代码 | |
| Action实现代码 | |
| Method实现代码 | |
| 类型定义 | |
| 内部辅助工具 | |
| 多语言错误提示 | |
| API文档页面 | |
| 指南文档页面 | |
| 运行时测试 | 与源码同目录,后缀 |
| 类型测试 | 与源码同目录,后缀 |
Commands
命令
bash
undefinedbash
undefinedLibrary
核心库
pnpm -C library build # Build
pnpm -C library test # Run tests
pnpm -C library lint # Lint
pnpm -C library format # Format
pnpm -C library build # 构建
pnpm -C library test # 运行测试
pnpm -C library lint # 代码检查
pnpm -C library format # 代码格式化
Website
官网
pnpm -C website dev # Dev server
pnpm -C website build # Production build
pnpm -C website dev # 启动开发服务器
pnpm -C website build # 生产构建
Root
根目录
pnpm install # Install all
pnpm format # Format all
undefinedpnpm install # 安装所有依赖
pnpm format # 格式化所有代码
undefinedKey Principles
核心原则
- Modularity - Small, focused functions; one per file
- Zero dependencies - Core library has no runtime deps
- 100% test coverage - Required for library
- Tree-shakable - Use annotation
// @__NO_SIDE_EFFECTS__ - Type-safe - Full TypeScript with strict mode
- ESM only - Imports include extensions
.ts
- 模块化 - 小巧、专注的函数;每个函数对应一个文件
- 零依赖 - 核心库无运行时依赖
- 100%测试覆盖率 - 核心库必须满足
- 可摇树优化 - 使用注解
// @__NO_SIDE_EFFECTS__ - 类型安全 - 完整的TypeScript严格模式支持
- 仅ESM - 导入需包含扩展名
.ts
Do's and Don'ts
注意事项
Do:
- Follow existing code patterns
- Write runtime and type tests
- Add JSDoc documentation
- Keep functions small and focused
- Check bundle size impact
Don't:
- Add external dependencies
- Modify core types without full test run
- Skip tests
- Create large multi-purpose functions
- Modify generated files (,
dist/)coverage/
建议:
- 遵循现有代码模式
- 编写运行时和类型测试
- 添加JSDoc文档
- 保持函数小巧且专注
- 检查对包体积的影响
禁止:
- 添加外部依赖
- 修改核心类型后不运行完整测试
- 跳过测试
- 创建大型多用途函数
- 修改生成文件(,
dist/)coverage/