schema-dsl 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +10 -0
- package/.eslintrc.json +27 -0
- package/.github/CODE_OF_CONDUCT.md +45 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +57 -0
- package/.github/ISSUE_TEMPLATE/config.yml +11 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +45 -0
- package/.github/ISSUE_TEMPLATE/question.md +31 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +70 -0
- package/.github/SECURITY.md +184 -0
- package/.github/workflows/ci.yml +35 -0
- package/CHANGELOG.md +633 -0
- package/CONTRIBUTING.md +368 -0
- package/LICENSE +21 -0
- package/README.md +1122 -0
- package/STATUS.md +273 -0
- package/docs/FEATURE-INDEX.md +521 -0
- package/docs/INDEX.md +224 -0
- package/docs/api-reference.md +1098 -0
- package/docs/best-practices.md +672 -0
- package/docs/cache-manager.md +336 -0
- package/docs/design-philosophy.md +602 -0
- package/docs/dsl-syntax.md +654 -0
- package/docs/dynamic-locale.md +552 -0
- package/docs/error-handling.md +703 -0
- package/docs/export-guide.md +459 -0
- package/docs/faq.md +576 -0
- package/docs/frontend-i18n-guide.md +290 -0
- package/docs/i18n-user-guide.md +488 -0
- package/docs/label-vs-description.md +262 -0
- package/docs/markdown-exporter.md +398 -0
- package/docs/mongodb-exporter.md +279 -0
- package/docs/multi-type-support.md +319 -0
- package/docs/mysql-exporter.md +257 -0
- package/docs/plugin-system.md +542 -0
- package/docs/postgresql-exporter.md +290 -0
- package/docs/quick-start.md +761 -0
- package/docs/schema-helper.md +340 -0
- package/docs/schema-utils.md +492 -0
- package/docs/string-extensions.md +480 -0
- package/docs/troubleshooting.md +471 -0
- package/docs/type-converter.md +319 -0
- package/docs/type-reference.md +219 -0
- package/docs/validate.md +486 -0
- package/docs/validation-guide.md +484 -0
- package/examples/array-dsl-example.js +227 -0
- package/examples/custom-extension.js +85 -0
- package/examples/dsl-match-example.js +74 -0
- package/examples/dsl-style.js +118 -0
- package/examples/dynamic-locale-configuration.js +348 -0
- package/examples/dynamic-locale-example.js +287 -0
- package/examples/export-demo.js +130 -0
- package/examples/i18n-full-demo.js +310 -0
- package/examples/i18n-memory-safety.examples.js +268 -0
- package/examples/markdown-export.js +71 -0
- package/examples/middleware-usage.js +93 -0
- package/examples/password-reset/README.md +153 -0
- package/examples/password-reset/schema.js +26 -0
- package/examples/password-reset/test.js +101 -0
- package/examples/plugin-system.examples.js +205 -0
- package/examples/simple-example.js +122 -0
- package/examples/string-extensions.js +297 -0
- package/examples/user-registration/README.md +156 -0
- package/examples/user-registration/routes.js +92 -0
- package/examples/user-registration/schema.js +150 -0
- package/examples/user-registration/server.js +74 -0
- package/index.d.ts +1999 -0
- package/index.js +270 -0
- package/index.mjs +30 -0
- package/lib/adapters/DslAdapter.js +653 -0
- package/lib/adapters/index.js +20 -0
- package/lib/config/constants.js +286 -0
- package/lib/config/patterns/creditCard.js +9 -0
- package/lib/config/patterns/idCard.js +9 -0
- package/lib/config/patterns/index.js +8 -0
- package/lib/config/patterns/licensePlate.js +4 -0
- package/lib/config/patterns/passport.js +4 -0
- package/lib/config/patterns/phone.js +9 -0
- package/lib/config/patterns/postalCode.js +5 -0
- package/lib/core/CacheManager.js +376 -0
- package/lib/core/DslBuilder.js +740 -0
- package/lib/core/ErrorCodes.js +233 -0
- package/lib/core/ErrorFormatter.js +342 -0
- package/lib/core/JSONSchemaCore.js +347 -0
- package/lib/core/Locale.js +119 -0
- package/lib/core/MessageTemplate.js +89 -0
- package/lib/core/PluginManager.js +448 -0
- package/lib/core/StringExtensions.js +209 -0
- package/lib/core/Validator.js +316 -0
- package/lib/exporters/MarkdownExporter.js +420 -0
- package/lib/exporters/MongoDBExporter.js +162 -0
- package/lib/exporters/MySQLExporter.js +212 -0
- package/lib/exporters/PostgreSQLExporter.js +289 -0
- package/lib/exporters/index.js +24 -0
- package/lib/locales/en-US.js +65 -0
- package/lib/locales/es-ES.js +66 -0
- package/lib/locales/fr-FR.js +66 -0
- package/lib/locales/index.js +8 -0
- package/lib/locales/ja-JP.js +66 -0
- package/lib/locales/zh-CN.js +93 -0
- package/lib/utils/LRUCache.js +174 -0
- package/lib/utils/SchemaHelper.js +240 -0
- package/lib/utils/SchemaUtils.js +313 -0
- package/lib/utils/TypeConverter.js +245 -0
- package/lib/utils/index.js +13 -0
- package/lib/validators/CustomKeywords.js +203 -0
- package/lib/validators/index.js +11 -0
- package/package.json +70 -0
- package/plugins/custom-format.js +101 -0
- package/plugins/custom-validator.js +200 -0
package/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
# 贡献指南
|
|
2
|
+
|
|
3
|
+
感谢您对 schema-dsl 的关注!我们欢迎所有形式的贡献。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📋 目录
|
|
8
|
+
|
|
9
|
+
- [行为准则](#行为准则)
|
|
10
|
+
- [如何贡献](#如何贡献)
|
|
11
|
+
- [开发流程](#开发流程)
|
|
12
|
+
- [代码规范](#代码规范)
|
|
13
|
+
- [提交规范](#提交规范)
|
|
14
|
+
- [测试要求](#测试要求)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 行为准则
|
|
19
|
+
|
|
20
|
+
请遵守我们的行为准则,保持尊重和友好的交流环境。
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
## 如何贡献
|
|
25
|
+
|
|
26
|
+
### 报告 Bug
|
|
27
|
+
|
|
28
|
+
发现 Bug?请[创建 Issue](https://github.com/yourusername/schema-dsl/issues),并提供以下信息:
|
|
29
|
+
|
|
30
|
+
- **环境信息**: Node.js 版本、操作系统
|
|
31
|
+
- **重现步骤**: 详细的步骤描述
|
|
32
|
+
- **期望行为**: 您期望发生什么
|
|
33
|
+
- **实际行为**: 实际发生了什么
|
|
34
|
+
- **错误信息**: 完整的错误堆栈
|
|
35
|
+
|
|
36
|
+
**示例**:
|
|
37
|
+
```markdown
|
|
38
|
+
### 环境
|
|
39
|
+
- Node.js: v18.0.0
|
|
40
|
+
- OS: Windows 11
|
|
41
|
+
|
|
42
|
+
### 重现步骤
|
|
43
|
+
1. 运行 `const schema = dsl('string:3-32!')`
|
|
44
|
+
2. 验证数据 `validator.validate(schema, 'ab')`
|
|
45
|
+
3. 期望返回验证失败,但返回成功
|
|
46
|
+
|
|
47
|
+
### 期望行为
|
|
48
|
+
应该验证失败,因为长度小于3
|
|
49
|
+
|
|
50
|
+
### 实际行为
|
|
51
|
+
验证通过
|
|
52
|
+
|
|
53
|
+
### 错误信息
|
|
54
|
+
无错误信息
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### 提出功能请求
|
|
58
|
+
|
|
59
|
+
有好的想法?请[创建 Feature Request](https://github.com/yourusername/schema-dsl/issues),说明:
|
|
60
|
+
|
|
61
|
+
- **功能描述**: 您想要什么功能
|
|
62
|
+
- **使用场景**: 这个功能解决什么问题
|
|
63
|
+
- **期望API**: 您期望的API设计
|
|
64
|
+
- **替代方案**: 是否有替代方案
|
|
65
|
+
|
|
66
|
+
### 提交代码
|
|
67
|
+
|
|
68
|
+
1. Fork 本仓库
|
|
69
|
+
2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
|
|
70
|
+
3. 提交更改 (`git commit -m 'feat: add amazing feature'`)
|
|
71
|
+
4. 推送到分支 (`git push origin feature/amazing-feature`)
|
|
72
|
+
5. 创建 Pull Request
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## 开发流程
|
|
77
|
+
|
|
78
|
+
### 1. 克隆仓库
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
git clone https://github.com/yourusername/schema-dsl.git
|
|
82
|
+
cd schema-dsl
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 2. 安装依赖
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
npm install
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
### 3. 运行测试
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
# 运行单元测试
|
|
95
|
+
npm test
|
|
96
|
+
|
|
97
|
+
# 运行集成测试
|
|
98
|
+
npm run test:integration
|
|
99
|
+
|
|
100
|
+
# 运行所有测试
|
|
101
|
+
npm run test:all
|
|
102
|
+
|
|
103
|
+
# 生成覆盖率报告
|
|
104
|
+
npm run coverage
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 4. 运行示例
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
# 运行 Joi 风格示例
|
|
111
|
+
node examples/joi-style.js
|
|
112
|
+
|
|
113
|
+
# 运行 DSL 风格示例
|
|
114
|
+
node examples/dsl-style.js
|
|
115
|
+
|
|
116
|
+
# 运行导出示例
|
|
117
|
+
node examples/export-demo.js
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### 5. 代码检查
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
npm run lint
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### 6. 提交代码
|
|
127
|
+
|
|
128
|
+
请遵循[提交规范](#提交规范)。
|
|
129
|
+
|
|
130
|
+
---
|
|
131
|
+
|
|
132
|
+
## 代码规范
|
|
133
|
+
|
|
134
|
+
### 命名规范
|
|
135
|
+
|
|
136
|
+
- **变量/函数**: camelCase(`userName`, `getUserName`)
|
|
137
|
+
- **类**: PascalCase(`Validator`, `JSONSchemaCore`)
|
|
138
|
+
- **常量**: UPPER_SNAKE_CASE(`MAX_LENGTH`, `DEFAULT_VALUE`)
|
|
139
|
+
- **私有方法**: 前缀下划线(`_internalMethod`)
|
|
140
|
+
|
|
141
|
+
### 代码风格
|
|
142
|
+
|
|
143
|
+
- 使用 2 空格缩进
|
|
144
|
+
- 字符串使用单引号 `'`
|
|
145
|
+
- 分号结尾
|
|
146
|
+
- 每行最多 100 字符
|
|
147
|
+
- 函数最多 50 行
|
|
148
|
+
|
|
149
|
+
### 注释规范
|
|
150
|
+
|
|
151
|
+
使用 JSDoc 注释:
|
|
152
|
+
|
|
153
|
+
```javascript
|
|
154
|
+
/**
|
|
155
|
+
* 验证数据
|
|
156
|
+
*
|
|
157
|
+
* @param {Object} schema - JSON Schema 对象
|
|
158
|
+
* @param {*} data - 待验证的数据
|
|
159
|
+
* @param {Object} options - 验证选项
|
|
160
|
+
* @returns {Object} 验证结果
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* const result = validator.validate(schema, data);
|
|
164
|
+
*/
|
|
165
|
+
validate(schema, data, options = {}) {
|
|
166
|
+
// 实现...
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 错误处理
|
|
171
|
+
|
|
172
|
+
必须包含错误处理:
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
try {
|
|
176
|
+
// 可能抛出错误的代码
|
|
177
|
+
const result = dangerousOperation();
|
|
178
|
+
return result;
|
|
179
|
+
} catch (error) {
|
|
180
|
+
// 记录错误
|
|
181
|
+
console.error('Operation failed:', error);
|
|
182
|
+
// 抛出或返回错误
|
|
183
|
+
throw new Error(`Operation failed: ${error.message}`);
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 提交规范
|
|
190
|
+
|
|
191
|
+
### Git 忽略规则
|
|
192
|
+
|
|
193
|
+
以下目录包含 AI 生成的临时文件或本地报告,**不应提交到 Git**:
|
|
194
|
+
|
|
195
|
+
- `plans/`: 需求分析、设计方案、技术规划文档
|
|
196
|
+
- `reports/`: 执行报告、分析报告、审计日志
|
|
197
|
+
- `.temp/`: 临时状态文件
|
|
198
|
+
|
|
199
|
+
请确保您的 `.gitignore` 文件包含以上目录。
|
|
200
|
+
|
|
201
|
+
使用 [Conventional Commits](https://www.conventionalcommits.org/) 规范。
|
|
202
|
+
|
|
203
|
+
### 提交类型
|
|
204
|
+
|
|
205
|
+
- `feat`: 新功能
|
|
206
|
+
- `fix`: Bug修复
|
|
207
|
+
- `docs`: 文档更新
|
|
208
|
+
- `style`: 代码格式调整(不影响功能)
|
|
209
|
+
- `refactor`: 代码重构
|
|
210
|
+
- `perf`: 性能优化
|
|
211
|
+
- `test`: 测试相关
|
|
212
|
+
- `chore`: 构建/工具相关
|
|
213
|
+
|
|
214
|
+
### 提交格式
|
|
215
|
+
|
|
216
|
+
```
|
|
217
|
+
<type>(<scope>): <subject>
|
|
218
|
+
|
|
219
|
+
<body>
|
|
220
|
+
|
|
221
|
+
<footer>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
**示例**:
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
feat(validator): add batch validation support
|
|
228
|
+
|
|
229
|
+
Add validateBatch() method to validate multiple data items at once.
|
|
230
|
+
This improves performance when validating large datasets.
|
|
231
|
+
|
|
232
|
+
Closes #123
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
```
|
|
236
|
+
fix(dsl): fix enum parsing with spaces
|
|
237
|
+
|
|
238
|
+
Fixed issue where enum values with spaces were not trimmed correctly.
|
|
239
|
+
|
|
240
|
+
Before: ['a ', ' b', ' c']
|
|
241
|
+
After: ['a', 'b', 'c']
|
|
242
|
+
|
|
243
|
+
Fixes #456
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Scope 说明
|
|
247
|
+
|
|
248
|
+
- `core`: 核心类(JSONSchemaCore, Validator)
|
|
249
|
+
- `adapters`: 适配器(Joi, DSL)
|
|
250
|
+
- `exporters`: 导出器(MongoDB, MySQL, PostgreSQL)
|
|
251
|
+
- `validators`: 验证器扩展
|
|
252
|
+
- `utils`: 工具函数
|
|
253
|
+
- `docs`: 文档
|
|
254
|
+
- `tests`: 测试
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## 测试要求
|
|
259
|
+
|
|
260
|
+
### 单元测试
|
|
261
|
+
|
|
262
|
+
每个新功能必须包含单元测试:
|
|
263
|
+
|
|
264
|
+
```javascript
|
|
265
|
+
describe('新功能', () => {
|
|
266
|
+
it('应该正常工作', () => {
|
|
267
|
+
const result = newFeature();
|
|
268
|
+
expect(result).to.equal(expectedValue);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('应该处理边界情况', () => {
|
|
272
|
+
expect(() => newFeature(null)).to.throw();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### 测试覆盖率
|
|
278
|
+
|
|
279
|
+
- **目标覆盖率**: ≥ 80%
|
|
280
|
+
- **核心功能**: ≥ 90%
|
|
281
|
+
- **工具函数**: ≥ 70%
|
|
282
|
+
|
|
283
|
+
### 运行测试
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
# 快速测试
|
|
287
|
+
npm test
|
|
288
|
+
|
|
289
|
+
# 完整测试+覆盖率
|
|
290
|
+
npm run coverage
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## Pull Request 流程
|
|
296
|
+
|
|
297
|
+
### 1. 创建 PR
|
|
298
|
+
|
|
299
|
+
- 标题清晰描述更改
|
|
300
|
+
- 详细说明更改内容
|
|
301
|
+
- 关联相关 Issue
|
|
302
|
+
- 提供测试结果
|
|
303
|
+
|
|
304
|
+
### 2. PR 检查清单
|
|
305
|
+
|
|
306
|
+
- [ ] 代码通过所有测试
|
|
307
|
+
- [ ] 添加了新的测试
|
|
308
|
+
- [ ] 更新了相关文档
|
|
309
|
+
- [ ] 遵循代码规范
|
|
310
|
+
- [ ] 提交信息符合规范
|
|
311
|
+
- [ ] 无合并冲突
|
|
312
|
+
|
|
313
|
+
### 3. 代码审查
|
|
314
|
+
|
|
315
|
+
维护者会审查您的代码,可能会:
|
|
316
|
+
|
|
317
|
+
- 提出修改建议
|
|
318
|
+
- 请求补充测试
|
|
319
|
+
- 讨论实现方案
|
|
320
|
+
|
|
321
|
+
请耐心等待并积极响应反馈。
|
|
322
|
+
|
|
323
|
+
### 4. 合并
|
|
324
|
+
|
|
325
|
+
通过审查后,维护者会合并您的 PR。
|
|
326
|
+
|
|
327
|
+
---
|
|
328
|
+
|
|
329
|
+
## 开发技巧
|
|
330
|
+
|
|
331
|
+
### 调试
|
|
332
|
+
|
|
333
|
+
使用 Node.js 调试器:
|
|
334
|
+
|
|
335
|
+
```bash
|
|
336
|
+
node inspect examples/joi-style.js
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
或使用 VSCode 调试配置。
|
|
340
|
+
|
|
341
|
+
### 性能测试
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
node test/benchmarks/validation-speed.js
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### 文档预览
|
|
348
|
+
|
|
349
|
+
更新文档后,可以使用 Markdown 预览工具查看效果。
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
## 获取帮助
|
|
354
|
+
|
|
355
|
+
- **提问**: [GitHub Discussions](https://github.com/yourusername/schema-dsl/discussions)
|
|
356
|
+
- **Bug 报告**: [GitHub Issues](https://github.com/yourusername/schema-dsl/issues)
|
|
357
|
+
- **邮件**: your-email@example.com
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## 许可证
|
|
362
|
+
|
|
363
|
+
贡献代码即表示您同意将代码以 [MIT](LICENSE) 许可证发布。
|
|
364
|
+
|
|
365
|
+
---
|
|
366
|
+
|
|
367
|
+
**感谢您的贡献!** 🎉
|
|
368
|
+
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 vextjs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|