schema-dsl 1.0.9 → 1.1.1

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.
Files changed (47) hide show
  1. package/CHANGELOG.md +325 -2
  2. package/README.md +419 -189
  3. package/STATUS.md +65 -3
  4. package/docs/FEATURE-INDEX.md +1 -1
  5. package/docs/best-practices.md +3 -3
  6. package/docs/cache-manager.md +1 -1
  7. package/docs/conditional-api.md +1278 -0
  8. package/docs/dsl-syntax.md +1 -1
  9. package/docs/dynamic-locale.md +2 -2
  10. package/docs/error-handling.md +2 -2
  11. package/docs/export-guide.md +2 -2
  12. package/docs/export-limitations.md +3 -3
  13. package/docs/faq.md +6 -6
  14. package/docs/frontend-i18n-guide.md +1 -1
  15. package/docs/mongodb-exporter.md +3 -3
  16. package/docs/multi-type-support.md +12 -2
  17. package/docs/mysql-exporter.md +1 -1
  18. package/docs/plugin-system.md +4 -4
  19. package/docs/postgresql-exporter.md +1 -1
  20. package/docs/quick-start.md +4 -4
  21. package/docs/troubleshooting.md +2 -2
  22. package/docs/type-reference.md +5 -5
  23. package/docs/typescript-guide.md +5 -6
  24. package/docs/union-type-guide.md +147 -0
  25. package/docs/union-types.md +277 -0
  26. package/docs/validate-async.md +1 -1
  27. package/examples/array-dsl-example.js +1 -1
  28. package/examples/conditional-example.js +288 -0
  29. package/examples/conditional-non-object.js +129 -0
  30. package/examples/conditional-validate-example.js +321 -0
  31. package/examples/i18n-error.examples.js +181 -0
  32. package/examples/union-type-example.js +127 -0
  33. package/examples/union-types-example.js +77 -0
  34. package/index.d.ts +655 -7
  35. package/index.js +54 -3
  36. package/lib/adapters/DslAdapter.js +14 -5
  37. package/lib/core/ConditionalBuilder.js +503 -0
  38. package/lib/core/DslBuilder.js +113 -0
  39. package/lib/core/Locale.js +13 -8
  40. package/lib/core/Validator.js +250 -2
  41. package/lib/errors/I18nError.js +222 -0
  42. package/lib/locales/en-US.js +39 -0
  43. package/lib/locales/es-ES.js +4 -0
  44. package/lib/locales/fr-FR.js +4 -0
  45. package/lib/locales/ja-JP.js +9 -0
  46. package/lib/locales/zh-CN.js +39 -0
  47. package/package.json +3 -1
@@ -12,6 +12,36 @@ module.exports = {
12
12
  'max-depth': 'Maximum recursion depth ({{#depth}}) exceeded at {{#label}}',
13
13
  exception: '{{#label}} validation exception: {{#message}}',
14
14
 
15
+ // Conditional (ConditionalBuilder)
16
+ 'conditional.underAge': 'Minors cannot register',
17
+ 'conditional.blocked': 'Account has been blocked',
18
+ 'conditional.notAllowed': 'Registration not allowed',
19
+
20
+ // I18nError - General errors (v1.1.1)
21
+ 'error.notFound': '{{#resource}} not found',
22
+ 'error.forbidden': 'Access to {{#resource}} is forbidden',
23
+ 'error.unauthorized': 'Unauthorized, please log in',
24
+ 'error.invalid': 'Invalid {{#field}}',
25
+ 'error.duplicate': '{{#resource}} already exists',
26
+ 'error.conflict': 'Operation conflict: {{#reason}}',
27
+
28
+ // I18nError - Account related (v1.1.1)
29
+ 'account.notFound': 'Account not found',
30
+ 'account.inactive': 'Account is inactive',
31
+ 'account.banned': 'Account has been banned',
32
+ 'account.insufficientBalance': 'Insufficient balance, current: {{#balance}}, required: {{#required}}',
33
+ 'account.insufficientCredits': 'Insufficient credits, current: {{#credits}}, required: {{#required}}',
34
+
35
+ // I18nError - User related (v1.1.1)
36
+ 'user.notFound': 'User not found',
37
+ 'user.notVerified': 'User is not verified',
38
+ 'user.noPermission': 'No admin permission',
39
+
40
+ // I18nError - Order related (v1.1.1)
41
+ 'order.notPaid': 'Order not paid',
42
+ 'order.paymentMissing': 'Payment information missing',
43
+ 'order.addressMissing': 'Shipping address missing',
44
+
15
45
  // Formats
16
46
  'format.email': '{{#label}} must be a valid email address',
17
47
  'format.url': '{{#label}} must be a valid URL',
@@ -115,6 +145,15 @@ module.exports = {
115
145
  'pattern.password.strong': 'Password must be at least 8 characters and contain uppercase, lowercase letters and numbers',
116
146
  'pattern.password.veryStrong': 'Password must be at least 10 characters and contain uppercase, lowercase letters, numbers and special characters',
117
147
 
148
+ // Union Type
149
+ 'pattern.emailOrPhone': 'Must be an email or phone number',
150
+ 'pattern.usernameOrEmail': 'Must be a username or email',
151
+ 'pattern.httpOrHttps': 'Must be a URL starting with http or https',
152
+
153
+ // oneOf (cross-type union) - v1.1.0
154
+ oneOf: '{{#label}} must match one of the following types',
155
+ 'oneOf.invalid': '{{#label}} value does not match any allowed type',
156
+
118
157
  // Unknown error fallback
119
158
  'UNKNOWN_ERROR': 'Unknown validation error',
120
159
 
@@ -99,6 +99,10 @@ module.exports = {
99
99
  // Unknown error fallback
100
100
  'UNKNOWN_ERROR': 'Error de validación desconocido',
101
101
 
102
+ // oneOf (unión entre tipos) - v1.1.0
103
+ oneOf: '{{#label}} debe coincidir con uno de los siguientes tipos',
104
+ 'oneOf.invalid': 'El valor de {{#label}} no coincide con ningún tipo permitido',
105
+
102
106
  // Custom validation
103
107
  'CUSTOM_VALIDATION_FAILED': 'Validación fallida',
104
108
  'ASYNC_VALIDATION_NOT_SUPPORTED': 'La validación asíncrona no es compatible en validate() síncrono',
@@ -99,6 +99,10 @@ module.exports = {
99
99
  // Unknown error fallback
100
100
  'UNKNOWN_ERROR': 'Erreur de validation inconnue',
101
101
 
102
+ // oneOf (union de types) - v1.1.0
103
+ oneOf: '{{#label}} doit correspondre à l\'un des types suivants',
104
+ 'oneOf.invalid': 'La valeur de {{#label}} ne correspond à aucun type autorisé',
105
+
102
106
  // Custom validation
103
107
  'CUSTOM_VALIDATION_FAILED': 'Validation échouée',
104
108
  'ASYNC_VALIDATION_NOT_SUPPORTED': 'La validation asynchrone n\'est pas prise en charge dans validate() synchrone',
@@ -12,6 +12,11 @@ module.exports = {
12
12
  'max-depth': '{{#label}}で最大再帰深度 ({{#depth}}) を超えました',
13
13
  exception: '{{#label}}の検証例外: {{#message}}',
14
14
 
15
+ // Conditional (ConditionalBuilder)
16
+ 'conditional.underAge': '未成年者は登録できません',
17
+ 'conditional.blocked': 'アカウントがブロックされています',
18
+ 'conditional.notAllowed': '登録は許可されていません',
19
+
15
20
  // Formats
16
21
  'format.email': '{{#label}}は有効なメールアドレスである必要があります',
17
22
  'format.url': '{{#label}}は有効なURLである必要があります',
@@ -96,6 +101,10 @@ module.exports = {
96
101
  'pattern.password.strong': 'パスワードは少なくとも8文字で、大文字、小文字、数字を含む必要があります',
97
102
  'pattern.password.veryStrong': 'パスワードは少なくとも10文字で、大文字、小文字、数字、特殊文字を含む必要があります',
98
103
 
104
+ // oneOf (型の結合) - v1.1.0
105
+ oneOf: '{{#label}}は次のいずれかの型に一致する必要があります',
106
+ 'oneOf.invalid': '{{#label}}の値は許可された型のいずれとも一致しません',
107
+
99
108
  // Unknown error fallback
100
109
  'UNKNOWN_ERROR': '不明な検証エラー',
101
110
 
@@ -12,6 +12,36 @@ module.exports = {
12
12
  'max-depth': '超过最大递归深度 ({{#depth}}) at {{#label}}',
13
13
  exception: '{{#label}}验证异常: {{#message}}',
14
14
 
15
+ // Conditional (ConditionalBuilder)
16
+ 'conditional.underAge': '未成年用户不能注册',
17
+ 'conditional.blocked': '账号已被封禁',
18
+ 'conditional.notAllowed': '不允许注册',
19
+
20
+ // I18nError - 通用错误消息 (v1.1.1)
21
+ 'error.notFound': '找不到{{#resource}}',
22
+ 'error.forbidden': '没有权限访问{{#resource}}',
23
+ 'error.unauthorized': '未授权,请先登录',
24
+ 'error.invalid': '{{#field}}无效',
25
+ 'error.duplicate': '{{#resource}}已存在',
26
+ 'error.conflict': '操作冲突: {{#reason}}',
27
+
28
+ // I18nError - 账户相关 (v1.1.1)
29
+ 'account.notFound': '账户不存在',
30
+ 'account.inactive': '账户未激活',
31
+ 'account.banned': '账户已被封禁',
32
+ 'account.insufficientBalance': '余额不足,当前余额{{#balance}},需要{{#required}}',
33
+ 'account.insufficientCredits': '积分不足,当前积分{{#credits}},需要{{#required}}',
34
+
35
+ // I18nError - 用户相关 (v1.1.1)
36
+ 'user.notFound': '用户不存在',
37
+ 'user.notVerified': '用户未验证',
38
+ 'user.noPermission': '没有管理员权限',
39
+
40
+ // I18nError - 订单相关 (v1.1.1)
41
+ 'order.notPaid': '订单未支付',
42
+ 'order.paymentMissing': '缺少支付信息',
43
+ 'order.addressMissing': '缺少收货地址',
44
+
15
45
  // Formats
16
46
  'format.email': '{{#label}}必须是有效的邮箱地址',
17
47
  'format.url': '{{#label}}必须是有效的URL地址',
@@ -115,6 +145,15 @@ module.exports = {
115
145
  'pattern.password.strong': '密码至少8位,需包含大小写字母和数字',
116
146
  'pattern.password.veryStrong': '密码至少10位,需包含大小写字母、数字和特殊字符',
117
147
 
148
+ // Union Type (联合类型)
149
+ 'pattern.emailOrPhone': '必须是邮箱或手机号',
150
+ 'pattern.usernameOrEmail': '必须是用户名或邮箱',
151
+ 'pattern.httpOrHttps': '必须是 http 或 https 开头的 URL',
152
+
153
+ // oneOf (跨类型联合) - v1.1.0 新增
154
+ oneOf: '{{#label}}必须匹配以下类型之一',
155
+ 'oneOf.invalid': '{{#label}}的值不匹配任何允许的类型',
156
+
118
157
  // Unknown error fallback
119
158
  'UNKNOWN_ERROR': '未知的验证错误',
120
159
 
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "schema-dsl",
3
- "version": "1.0.9",
3
+ "version": "1.1.1",
4
4
  "description": "简洁强大的JSON Schema验证库 - DSL语法 + String扩展 + 便捷validate",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "exports": {
7
8
  ".": {
8
9
  "require": "./index.js",
@@ -60,6 +61,7 @@
60
61
  "benchmark": "^2.1.4",
61
62
  "chai": "^4.5.0",
62
63
  "eslint": "^8.57.1",
64
+ "express": "^5.2.1",
63
65
  "joi": "^18.0.2",
64
66
  "mocha": "^10.8.2",
65
67
  "monsqlize": "^1.0.1",