schema-dsl 1.2.4 → 2.0.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.
Files changed (242) hide show
  1. package/CHANGELOG.md +87 -210
  2. package/README.md +391 -2249
  3. package/dist/DslBuilder-DQDN0ZxZ.d.cts +341 -0
  4. package/dist/DslBuilder-DkLaOo9Q.d.ts +341 -0
  5. package/dist/Validator-C7GsVQOH.d.cts +192 -0
  6. package/dist/Validator-hFWKGxir.d.ts +192 -0
  7. package/dist/index.cjs +6594 -0
  8. package/dist/index.d.cts +1145 -0
  9. package/dist/index.d.ts +1145 -0
  10. package/dist/index.js +6528 -0
  11. package/dist/plugin-CIKtTMtS.d.cts +246 -0
  12. package/dist/plugin-CIKtTMtS.d.ts +246 -0
  13. package/dist/plugins/custom-format.cjs +3802 -0
  14. package/dist/plugins/custom-format.d.cts +12 -0
  15. package/dist/plugins/custom-format.d.ts +12 -0
  16. package/dist/plugins/custom-format.js +3772 -0
  17. package/dist/plugins/custom-type-example.cjs +3795 -0
  18. package/dist/plugins/custom-type-example.d.cts +8 -0
  19. package/dist/plugins/custom-type-example.d.ts +8 -0
  20. package/dist/plugins/custom-type-example.js +3765 -0
  21. package/dist/plugins/custom-validator.cjs +146 -0
  22. package/dist/plugins/custom-validator.d.cts +10 -0
  23. package/dist/plugins/custom-validator.d.ts +10 -0
  24. package/dist/plugins/custom-validator.js +121 -0
  25. package/docs/FEATURE-INDEX.md +102 -68
  26. package/docs/add-custom-locale.md +48 -35
  27. package/docs/add-keyword.md +24 -0
  28. package/docs/api-reference.md +396 -154
  29. package/docs/api.md +13 -0
  30. package/docs/best-practices-project-structure.md +19 -10
  31. package/docs/best-practices.md +93 -53
  32. package/docs/cache-manager.md +23 -15
  33. package/docs/compile.md +45 -0
  34. package/docs/conditional-api.md +40 -11
  35. package/docs/custom-extensions-guide.md +80 -152
  36. package/docs/design-philosophy.md +76 -71
  37. package/docs/doc-index.md +324 -0
  38. package/docs/dsl-syntax.md +69 -19
  39. package/docs/dynamic-locale.md +24 -14
  40. package/docs/enum.md +12 -5
  41. package/docs/error-handling.md +53 -44
  42. package/docs/export-guide.md +47 -8
  43. package/docs/export-limitations.md +27 -11
  44. package/docs/faq.md +86 -67
  45. package/docs/frontend-i18n-guide.md +26 -12
  46. package/docs/i18n-user-guide.md +60 -47
  47. package/docs/i18n.md +51 -32
  48. package/docs/index.md +48 -0
  49. package/docs/json-schema-basics.md +40 -0
  50. package/docs/label-vs-description.md +12 -3
  51. package/docs/markdown-exporter.md +15 -6
  52. package/docs/mongodb-exporter.md +11 -4
  53. package/docs/multi-language.md +26 -0
  54. package/docs/multi-type-support.md +26 -33
  55. package/docs/mysql-exporter.md +9 -2
  56. package/docs/number-operators.md +12 -5
  57. package/docs/optional-marker-guide.md +28 -23
  58. package/docs/performance-guide.md +49 -0
  59. package/docs/plugin-system.md +205 -366
  60. package/docs/plugin-type-registration.md +34 -0
  61. package/docs/postgresql-exporter.md +9 -2
  62. package/docs/public/favicon.svg +5 -0
  63. package/docs/quick-start.md +37 -363
  64. package/docs/runtime-locale-support.md +20 -9
  65. package/docs/schema-helper.md +10 -5
  66. package/docs/schema-utils-advanced-issues.md +23 -0
  67. package/docs/schema-utils-best-practices.md +20 -0
  68. package/docs/schema-utils-chaining.md +7 -0
  69. package/docs/schema-utils.md +76 -42
  70. package/docs/security-checklist.md +20 -0
  71. package/docs/string-extensions.md +17 -9
  72. package/docs/troubleshooting.md +36 -21
  73. package/docs/type-converter.md +41 -50
  74. package/docs/type-reference.md +38 -15
  75. package/docs/typescript-guide.md +53 -42
  76. package/docs/union-type-guide.md +11 -1
  77. package/docs/union-types.md +10 -3
  78. package/docs/validate-async.md +36 -25
  79. package/docs/validate-batch.md +49 -0
  80. package/docs/validate-dsl-object-support.md +33 -28
  81. package/docs/validate.md +36 -16
  82. package/docs/validation-guide.md +25 -7
  83. package/docs/validator.md +39 -0
  84. package/package.json +85 -27
  85. package/plugins/custom-format.cjs +8 -0
  86. package/plugins/custom-type-example.cjs +8 -0
  87. package/plugins/custom-validator.cjs +8 -0
  88. package/src/adapters/DslAdapter.ts +111 -0
  89. package/src/adapters/index.ts +1 -0
  90. package/src/config/constants.ts +83 -0
  91. package/src/config/index.ts +2 -0
  92. package/src/config/patterns.ts +77 -0
  93. package/src/core/CacheManager.ts +159 -0
  94. package/src/core/ConditionalBuilder.ts +382 -0
  95. package/src/core/ConditionalRuntime.ts +28 -0
  96. package/src/core/ConditionalValidator.ts +255 -0
  97. package/src/core/DslBuilder.ts +677 -0
  98. package/src/core/ErrorCodes.ts +38 -0
  99. package/src/core/ErrorFormatter.ts +271 -0
  100. package/src/core/JSONSchemaCore.ts +65 -0
  101. package/src/core/Locale.ts +187 -0
  102. package/src/core/MessageTemplate.ts +42 -0
  103. package/src/core/ObjectDslBuilder.ts +64 -0
  104. package/src/core/PluginManager.ts +326 -0
  105. package/src/core/StringExtensions.ts +140 -0
  106. package/src/core/TemplateEngine.ts +44 -0
  107. package/src/core/Validator.ts +448 -0
  108. package/src/errors/I18nError.ts +159 -0
  109. package/src/errors/ValidationError.ts +105 -0
  110. package/src/exporters/BaseExporter.ts +60 -0
  111. package/src/exporters/MarkdownExporter.ts +305 -0
  112. package/src/exporters/MongoDBExporter.ts +126 -0
  113. package/src/exporters/MySQLExporter.ts +155 -0
  114. package/src/exporters/PostgreSQLExporter.ts +222 -0
  115. package/src/exporters/index.ts +18 -0
  116. package/src/index.ts +633 -0
  117. package/{lib/locales/en-US.js → src/locales/en-US.ts} +21 -37
  118. package/{lib/locales/es-ES.js → src/locales/es-ES.ts} +63 -16
  119. package/{lib/locales/fr-FR.js → src/locales/fr-FR.ts} +74 -27
  120. package/src/locales/index.ts +103 -0
  121. package/{lib/locales/ja-JP.js → src/locales/ja-JP.ts} +59 -17
  122. package/src/locales/types.ts +156 -0
  123. package/{lib/locales/zh-CN.js → src/locales/zh-CN.ts} +21 -38
  124. package/src/parser/ConstraintParser.ts +101 -0
  125. package/src/parser/DslParser.ts +470 -0
  126. package/src/parser/SchemaCompiler.ts +66 -0
  127. package/src/parser/TypeRegistry.ts +250 -0
  128. package/src/parser/index.ts +6 -0
  129. package/src/plugins/custom-format.ts +126 -0
  130. package/src/plugins/custom-type-example.ts +108 -0
  131. package/src/plugins/custom-validator.ts +140 -0
  132. package/src/types/conditional.ts +28 -0
  133. package/src/types/config.ts +59 -0
  134. package/src/types/dsl.ts +131 -0
  135. package/src/types/error.ts +60 -0
  136. package/src/types/index.ts +17 -0
  137. package/src/types/infer.ts +128 -0
  138. package/src/types/plugin.ts +58 -0
  139. package/src/types/safe-regex.d.ts +9 -0
  140. package/src/types/schema.ts +66 -0
  141. package/src/types/validate.ts +71 -0
  142. package/src/utils/SchemaHelper.ts +196 -0
  143. package/src/utils/SchemaUtils.ts +346 -0
  144. package/src/utils/TypeConverter.ts +215 -0
  145. package/src/utils/index.ts +10 -0
  146. package/src/validators/CustomKeywords.ts +477 -0
  147. package/.eslintignore +0 -11
  148. package/.eslintrc.json +0 -27
  149. package/CONTRIBUTING.md +0 -368
  150. package/STATUS.md +0 -491
  151. package/changelogs/v1.0.0.md +0 -328
  152. package/changelogs/v1.0.9.md +0 -367
  153. package/changelogs/v1.1.0.md +0 -389
  154. package/changelogs/v1.1.1.md +0 -308
  155. package/changelogs/v1.1.2.md +0 -183
  156. package/changelogs/v1.1.3.md +0 -161
  157. package/changelogs/v1.1.4.md +0 -432
  158. package/changelogs/v1.1.5.md +0 -493
  159. package/changelogs/v1.1.6.md +0 -211
  160. package/changelogs/v1.1.8.md +0 -376
  161. package/changelogs/v1.2.3.md +0 -124
  162. package/docs/INDEX.md +0 -252
  163. package/docs/issues-resolved-summary.md +0 -196
  164. package/docs/performance-benchmark-report.md +0 -179
  165. package/docs/performance-quick-reference.md +0 -123
  166. package/docs/user-questions-answered.md +0 -353
  167. package/docs/validation-rules-v1.0.2.md +0 -1608
  168. package/examples/README.md +0 -81
  169. package/examples/array-dsl-example.js +0 -227
  170. package/examples/conditional-example.js +0 -288
  171. package/examples/conditional-non-object.js +0 -129
  172. package/examples/conditional-validate-example.js +0 -321
  173. package/examples/custom-extension.js +0 -85
  174. package/examples/dsl-match-example.js +0 -74
  175. package/examples/dsl-style.js +0 -118
  176. package/examples/dynamic-locale-configuration.js +0 -348
  177. package/examples/dynamic-locale-example.js +0 -287
  178. package/examples/enum.examples.js +0 -324
  179. package/examples/export-demo.js +0 -130
  180. package/examples/express-integration.js +0 -376
  181. package/examples/i18n-error-handling-complete.js +0 -381
  182. package/examples/i18n-error-handling-quickstart.md +0 -0
  183. package/examples/i18n-error.examples.js +0 -181
  184. package/examples/i18n-full-demo.js +0 -301
  185. package/examples/i18n-memory-safety.examples.js +0 -268
  186. package/examples/markdown-export.js +0 -71
  187. package/examples/middleware-usage.js +0 -93
  188. package/examples/new-features-comparison.js +0 -315
  189. package/examples/password-reset/README.md +0 -153
  190. package/examples/password-reset/schema.js +0 -26
  191. package/examples/password-reset/test.js +0 -101
  192. package/examples/plugin-system.examples.js +0 -205
  193. package/examples/schema-utils-chaining.examples.js +0 -250
  194. package/examples/simple-example.js +0 -122
  195. package/examples/slug.examples.js +0 -179
  196. package/examples/string-extensions.js +0 -297
  197. package/examples/union-type-example.js +0 -127
  198. package/examples/union-types-example.js +0 -77
  199. package/examples/user-registration/README.md +0 -156
  200. package/examples/user-registration/routes.js +0 -92
  201. package/examples/user-registration/schema.js +0 -150
  202. package/examples/user-registration/server.js +0 -74
  203. package/index.d.ts +0 -3540
  204. package/index.js +0 -457
  205. package/index.mjs +0 -60
  206. package/lib/adapters/DslAdapter.js +0 -871
  207. package/lib/adapters/index.js +0 -20
  208. package/lib/config/constants.js +0 -286
  209. package/lib/config/patterns/common.js +0 -47
  210. package/lib/config/patterns/creditCard.js +0 -9
  211. package/lib/config/patterns/idCard.js +0 -9
  212. package/lib/config/patterns/index.js +0 -9
  213. package/lib/config/patterns/licensePlate.js +0 -4
  214. package/lib/config/patterns/passport.js +0 -4
  215. package/lib/config/patterns/phone.js +0 -9
  216. package/lib/config/patterns/postalCode.js +0 -5
  217. package/lib/core/CacheManager.js +0 -376
  218. package/lib/core/ConditionalBuilder.js +0 -503
  219. package/lib/core/DslBuilder.js +0 -1400
  220. package/lib/core/ErrorCodes.js +0 -233
  221. package/lib/core/ErrorFormatter.js +0 -445
  222. package/lib/core/JSONSchemaCore.js +0 -347
  223. package/lib/core/Locale.js +0 -130
  224. package/lib/core/MessageTemplate.js +0 -98
  225. package/lib/core/PluginManager.js +0 -448
  226. package/lib/core/StringExtensions.js +0 -240
  227. package/lib/core/Validator.js +0 -654
  228. package/lib/errors/I18nError.js +0 -328
  229. package/lib/errors/ValidationError.js +0 -191
  230. package/lib/exporters/MarkdownExporter.js +0 -420
  231. package/lib/exporters/MongoDBExporter.js +0 -162
  232. package/lib/exporters/MySQLExporter.js +0 -212
  233. package/lib/exporters/PostgreSQLExporter.js +0 -289
  234. package/lib/exporters/index.js +0 -24
  235. package/lib/locales/index.js +0 -8
  236. package/lib/utils/LRUCache.js +0 -174
  237. package/lib/utils/SchemaHelper.js +0 -240
  238. package/lib/utils/SchemaUtils.js +0 -445
  239. package/lib/utils/TypeConverter.js +0 -245
  240. package/lib/utils/index.js +0 -13
  241. package/lib/validators/CustomKeywords.js +0 -616
  242. package/lib/validators/index.js +0 -11
@@ -1,4 +1,6 @@
1
- module.exports = {
1
+ import type { LocaleMessages } from './types.js'
2
+
3
+ const enUS: LocaleMessages = {
2
4
  // Generic
3
5
  required: '{{#label}} is required',
4
6
  type: '{{#label}} should be {{#expected}}, got {{#actual}}',
@@ -12,12 +14,12 @@ module.exports = {
12
14
  'max-depth': 'Maximum recursion depth ({{#depth}}) exceeded at {{#label}}',
13
15
  exception: '{{#label}} validation exception: {{#message}}',
14
16
 
15
- // Conditional (ConditionalBuilder)
17
+ // Conditional
16
18
  'conditional.underAge': 'Minors cannot register',
17
19
  'conditional.blocked': 'Account has been blocked',
18
20
  'conditional.notAllowed': 'Registration not allowed',
19
21
 
20
- // I18nError - General errors (v1.1.1)
22
+ // I18nError generic
21
23
  'error.notFound': '{{#resource}} not found',
22
24
  'error.forbidden': 'Access to {{#resource}} is forbidden',
23
25
  'error.unauthorized': 'Unauthorized, please log in',
@@ -25,34 +27,27 @@ module.exports = {
25
27
  'error.duplicate': '{{#resource}} already exists',
26
28
  'error.conflict': 'Operation conflict: {{#reason}}',
27
29
 
28
- // I18nError - Account related (v1.1.1)
29
- // v1.1.5: Using object format for some examples
30
- 'account.notFound': {
31
- code: 'ACCOUNT_NOT_FOUND',
32
- message: 'Account not found'
33
- },
30
+ // Account
31
+ 'account.notFound': { code: 'ACCOUNT_NOT_FOUND', message: 'Account not found' },
34
32
  'account.inactive': 'Account is inactive',
35
33
  'account.banned': 'Account has been banned',
36
34
  'account.insufficientBalance': {
37
35
  code: 'INSUFFICIENT_BALANCE',
38
- message: 'Insufficient balance, current: {{#balance}}, required: {{#required}}'
36
+ message: 'Insufficient balance, current: {{#balance}}, required: {{#required}}',
39
37
  },
40
38
  'account.insufficientCredits': 'Insufficient credits, current: {{#credits}}, required: {{#required}}',
41
39
 
42
- // I18nError - User related (v1.1.1)
40
+ // User
43
41
  'user.notFound': 'User not found',
44
42
  'user.notVerified': 'User is not verified',
45
43
  'user.noPermission': 'No admin permission',
46
44
 
47
- // I18nError - Order related (v1.1.1)
48
- 'order.notPaid': {
49
- code: 'ORDER_NOT_PAID',
50
- message: 'Order not paid'
51
- },
45
+ // Order
46
+ 'order.notPaid': { code: 'ORDER_NOT_PAID', message: 'Order not paid' },
52
47
  'order.paymentMissing': 'Payment information missing',
53
48
  'order.addressMissing': 'Shipping address missing',
54
49
 
55
- // Formats
50
+ // Format
56
51
  'format.email': '{{#label}} must be a valid email address',
57
52
  'format.url': '{{#label}} must be a valid URL',
58
53
  'format.uuid': '{{#label}} must be a valid UUID',
@@ -67,7 +62,6 @@ module.exports = {
67
62
  'string.hostname': '{{#label}} must be a valid hostname',
68
63
  'string.pattern': '{{#label}} format does not match required pattern',
69
64
  'string.enum': '{{#label}} must be one of: {{#valids}}',
70
- // v1.0.2
71
65
  'string.length': '{{#label}} length must be exactly {{#limit}} characters',
72
66
  'string.alphanum': '{{#label}} must only contain alphanumeric characters',
73
67
  'string.trim': '{{#label}} must not have leading or trailing whitespace',
@@ -81,7 +75,6 @@ module.exports = {
81
75
  'number.integer': '{{#label}} must be an integer',
82
76
  'number.positive': '{{#label}} must be a positive number',
83
77
  'number.negative': '{{#label}} must be a negative number',
84
- // v1.0.2
85
78
  'number.precision': '{{#label}} must have at most {{#limit}} decimal places',
86
79
  'number.port': '{{#label}} must be a valid port number (1-65535)',
87
80
 
@@ -93,10 +86,8 @@ module.exports = {
93
86
  'object.min': '{{#label}} must have at least {{#limit}} properties',
94
87
  'object.max': '{{#label}} must have at most {{#limit}} properties',
95
88
  'object.unknown': '{{#label}} contains unknown property: {{#key}}',
96
- // v1.0.2
97
89
  'object.missing': '{{#label}} is missing required properties',
98
90
  'object.schema': '{{#label}} contains additional properties',
99
- // v1.1.6 - additionalProperties
100
91
  'additionalProperties': '{{#label}} must NOT have additional properties: {{#key}}',
101
92
 
102
93
  // Array
@@ -105,7 +96,6 @@ module.exports = {
105
96
  'array.max': '{{#label}} must have at most {{#limit}} items',
106
97
  'array.length': '{{#label}} must have exactly {{#limit}} items',
107
98
  'array.unique': '{{#label}} must not contain duplicate items',
108
- // v1.0.2
109
99
  'array.sparse': '{{#label}} must not be a sparse array',
110
100
  'array.includesRequired': '{{#label}} must include required items',
111
101
 
@@ -113,7 +103,6 @@ module.exports = {
113
103
  'date.base': '{{#label}} must be a valid date',
114
104
  'date.min': '{{#label}} must be no earlier than {{#limit}}',
115
105
  'date.max': '{{#label}} must be no later than {{#limit}}',
116
- // v1.0.2
117
106
  'date.format': '{{#label}} date format is invalid',
118
107
  'date.greater': '{{#label}} must be after {{#limit}}',
119
108
  'date.less': '{{#label}} must be before {{#limit}}',
@@ -124,7 +113,7 @@ module.exports = {
124
113
  'any.only': '{{#label}} must match {{#valids}}',
125
114
  'any.unknown': 'Field {{#key}} is not allowed',
126
115
 
127
- // Patterns (Legacy/Specific)
116
+ // Patterns
128
117
  'pattern.phone': 'Invalid phone number',
129
118
  'pattern.phone.international': 'Invalid international phone number',
130
119
  'pattern.idCard': 'Invalid ID card number',
@@ -143,34 +132,29 @@ module.exports = {
143
132
  'pattern.macAddress': 'Invalid MAC Address',
144
133
  'pattern.cron': 'Invalid Cron Expression',
145
134
  'pattern.slug': 'URL slug can only contain lowercase letters, numbers, and hyphens',
146
- // v1.0.2 新增
147
135
  'pattern.domain': '{{#label}} must be a valid domain name',
148
136
  'pattern.ip': '{{#label}} must be a valid IP address',
149
137
  'pattern.base64': '{{#label}} must be a valid Base64 string',
150
138
  'pattern.jwt': '{{#label}} must be a valid JWT token',
151
139
  'pattern.json': '{{#label}} must be a valid JSON string',
152
-
153
- // Username & Password
154
140
  'pattern.username': 'Username must start with a letter and contain only letters, numbers, and underscores',
155
141
  'pattern.password.weak': 'Password must be at least 6 characters',
156
142
  'pattern.password.medium': 'Password must be at least 8 characters and contain letters and numbers',
157
143
  'pattern.password.strong': 'Password must be at least 8 characters and contain uppercase, lowercase letters and numbers',
158
144
  'pattern.password.veryStrong': 'Password must be at least 10 characters and contain uppercase, lowercase letters, numbers and special characters',
159
-
160
- // Union Type
161
145
  'pattern.emailOrPhone': 'Must be an email or phone number',
162
146
  'pattern.usernameOrEmail': 'Must be a username or email',
163
147
  'pattern.httpOrHttps': 'Must be a URL starting with http or https',
164
148
 
165
- // oneOf (cross-type union) - v1.1.0
149
+ // oneOf
166
150
  oneOf: '{{#label}} must match one of the following types',
167
151
  'oneOf.invalid': '{{#label}} value does not match any allowed type',
168
152
 
169
- // Unknown error fallback
170
- 'UNKNOWN_ERROR': 'Unknown validation error',
153
+ // Error fallback
154
+ UNKNOWN_ERROR: 'Unknown validation error',
155
+ CUSTOM_VALIDATION_FAILED: 'Validation failed',
156
+ ASYNC_VALIDATION_NOT_SUPPORTED: 'Async validation not supported in synchronous validate()',
157
+ VALIDATE_MUST_BE_FUNCTION: 'validate must be a function',
158
+ }
171
159
 
172
- // Custom validation
173
- 'CUSTOM_VALIDATION_FAILED': 'Validation failed',
174
- 'ASYNC_VALIDATION_NOT_SUPPORTED': 'Async validation not supported in synchronous validate()',
175
- 'VALIDATE_MUST_BE_FUNCTION': 'validate must be a function'
176
- };
160
+ export default enUS
@@ -1,4 +1,6 @@
1
- module.exports = {
1
+ import type { LocaleMessages } from './types.js'
2
+
3
+ const esES: LocaleMessages = {
2
4
  // Generic
3
5
  required: '{{#label}} es obligatorio',
4
6
  type: '{{#label}} debe ser de tipo {{#expected}}, pero se obtuvo {{#actual}}',
@@ -12,7 +14,40 @@ module.exports = {
12
14
  'max-depth': 'Profundidad máxima de recursión ({{#depth}}) excedida en {{#label}}',
13
15
  exception: 'Excepción de validación en {{#label}}: {{#message}}',
14
16
 
15
- // Formats
17
+ // Conditional (v2 additions)
18
+ 'conditional.underAge': 'Los menores de edad no pueden registrarse',
19
+ 'conditional.blocked': 'La cuenta ha sido bloqueada',
20
+ 'conditional.notAllowed': 'El registro no está permitido',
21
+
22
+ // I18nError — generic (v2 additions)
23
+ 'error.notFound': '{{#resource}} no encontrado',
24
+ 'error.forbidden': 'Acceso a {{#resource}} está prohibido',
25
+ 'error.unauthorized': 'No autorizado, por favor inicie sesión',
26
+ 'error.invalid': '{{#field}} no es válido',
27
+ 'error.duplicate': '{{#resource}} ya existe',
28
+ 'error.conflict': 'Conflicto de operación: {{#reason}}',
29
+
30
+ // Account (v2 additions)
31
+ 'account.notFound': { code: 'ACCOUNT_NOT_FOUND', message: 'Cuenta no encontrada' },
32
+ 'account.inactive': 'La cuenta está inactiva',
33
+ 'account.banned': 'La cuenta ha sido suspendida',
34
+ 'account.insufficientBalance': {
35
+ code: 'INSUFFICIENT_BALANCE',
36
+ message: 'Saldo insuficiente, actual: {{#balance}}, requerido: {{#required}}',
37
+ },
38
+ 'account.insufficientCredits': 'Créditos insuficientes, actual: {{#credits}}, requerido: {{#required}}',
39
+
40
+ // User (v2 additions)
41
+ 'user.notFound': 'Usuario no encontrado',
42
+ 'user.notVerified': 'El usuario no está verificado',
43
+ 'user.noPermission': 'Sin permisos de administrador',
44
+
45
+ // Order (v2 additions)
46
+ 'order.notPaid': { code: 'ORDER_NOT_PAID', message: 'Pedido no pagado' },
47
+ 'order.paymentMissing': 'Falta información de pago',
48
+ 'order.addressMissing': 'Falta la dirección de envío',
49
+
50
+ // Format
16
51
  'format.email': '{{#label}} debe ser una dirección de correo electrónico válida',
17
52
  'format.url': '{{#label}} debe ser una URL válida',
18
53
  'format.uuid': '{{#label}} debe ser un UUID válido',
@@ -27,6 +62,11 @@ module.exports = {
27
62
  'string.hostname': '{{#label}} debe ser un nombre de host válido',
28
63
  'string.pattern': 'El formato de {{#label}} no coincide con el patrón requerido',
29
64
  'string.enum': '{{#label}} debe ser uno de: {{#valids}}',
65
+ 'string.length': 'La longitud de {{#label}} debe ser exactamente {{#limit}} caracteres',
66
+ 'string.alphanum': '{{#label}} solo puede contener caracteres alfanuméricos',
67
+ 'string.trim': '{{#label}} no debe tener espacios al principio ni al final',
68
+ 'string.lowercase': '{{#label}} debe estar en minúsculas',
69
+ 'string.uppercase': '{{#label}} debe estar en mayúsculas',
30
70
 
31
71
  // Number
32
72
  'number.base': '{{#label}} debe ser un número',
@@ -35,6 +75,8 @@ module.exports = {
35
75
  'number.integer': '{{#label}} debe ser un número entero',
36
76
  'number.positive': '{{#label}} debe ser un número positivo',
37
77
  'number.negative': '{{#label}} debe ser un número negativo',
78
+ 'number.precision': '{{#label}} debe tener como máximo {{#limit}} decimales',
79
+ 'number.port': '{{#label}} debe ser un número de puerto válido (1-65535)',
38
80
 
39
81
  // Boolean
40
82
  'boolean.base': '{{#label}} debe ser un booleano',
@@ -44,7 +86,8 @@ module.exports = {
44
86
  'object.min': '{{#label}} debe tener al menos {{#limit}} propiedades',
45
87
  'object.max': '{{#label}} debe tener como máximo {{#limit}} propiedades',
46
88
  'object.unknown': '{{#label}} contiene una propiedad desconocida: {{#key}}',
47
- // v1.1.6 - additionalProperties
89
+ 'object.missing': 'A {{#label}} le faltan propiedades requeridas',
90
+ 'object.schema': '{{#label}} contiene propiedades adicionales',
48
91
  'additionalProperties': '{{#label}} NO debe tener propiedades adicionales: {{#key}}',
49
92
 
50
93
  // Array
@@ -53,11 +96,16 @@ module.exports = {
53
96
  'array.max': '{{#label}} debe tener como máximo {{#limit}} elementos',
54
97
  'array.length': '{{#label}} debe tener exactamente {{#limit}} elementos',
55
98
  'array.unique': '{{#label}} no debe contener elementos duplicados',
99
+ 'array.sparse': '{{#label}} no debe ser un array disperso',
100
+ 'array.includesRequired': '{{#label}} debe incluir los elementos requeridos',
56
101
 
57
102
  // Date
58
103
  'date.base': '{{#label}} debe ser una fecha válida',
59
104
  'date.min': '{{#label}} no debe ser anterior a {{#limit}}',
60
105
  'date.max': '{{#label}} no debe ser posterior a {{#limit}}',
106
+ 'date.format': 'El formato de fecha de {{#label}} no es válido',
107
+ 'date.greater': '{{#label}} debe ser posterior a {{#limit}}',
108
+ 'date.less': '{{#label}} debe ser anterior a {{#limit}}',
61
109
 
62
110
  // Any
63
111
  'any.required': '{{#label}} es obligatorio',
@@ -65,7 +113,7 @@ module.exports = {
65
113
  'any.only': '{{#label}} debe coincidir con {{#valids}}',
66
114
  'any.unknown': 'El campo {{#key}} no está permitido',
67
115
 
68
- // Patterns (Legacy/Specific)
116
+ // Patterns
69
117
  'pattern.phone': 'Número de teléfono no válido',
70
118
  'pattern.phone.international': 'Número de teléfono internacional no válido',
71
119
  'pattern.idCard': 'Número de tarjeta de identificación no válido',
@@ -84,30 +132,29 @@ module.exports = {
84
132
  'pattern.macAddress': 'Dirección MAC no válida',
85
133
  'pattern.cron': 'Expresión Cron no válida',
86
134
  'pattern.slug': 'El slug de URL solo puede contener letras minúsculas, números y guiones',
87
- // v1.0.2 新增
88
135
  'pattern.domain': '{{#label}} debe ser un nombre de dominio válido',
89
136
  'pattern.ip': '{{#label}} debe ser una dirección IP válida',
90
137
  'pattern.base64': '{{#label}} debe ser una cadena Base64 válida',
91
138
  'pattern.jwt': '{{#label}} debe ser un token JWT válido',
92
139
  'pattern.json': '{{#label}} debe ser una cadena JSON válida',
93
-
94
- // Username & Password
95
140
  'pattern.username': 'El nombre de usuario debe comenzar con una letra y contener solo letras, números y guiones bajos',
96
141
  'pattern.password.weak': 'La contraseña debe tener al menos 6 caracteres',
97
142
  'pattern.password.medium': 'La contraseña debe tener al menos 8 caracteres y contener letras y números',
98
143
  'pattern.password.strong': 'La contraseña debe tener al menos 8 caracteres y contener letras mayúsculas, minúsculas y números',
99
144
  'pattern.password.veryStrong': 'La contraseña debe tener al menos 10 caracteres y contener letras mayúsculas, minúsculas, números y caracteres especiales',
145
+ 'pattern.emailOrPhone': 'Debe ser un correo electrónico o número de teléfono',
146
+ 'pattern.usernameOrEmail': 'Debe ser un nombre de usuario o correo electrónico',
147
+ 'pattern.httpOrHttps': 'Debe ser una URL que comience con http o https',
100
148
 
101
- // Unknown error fallback
102
- 'UNKNOWN_ERROR': 'Error de validación desconocido',
103
-
104
- // oneOf (unión entre tipos) - v1.1.0
149
+ // oneOf
105
150
  oneOf: '{{#label}} debe coincidir con uno de los siguientes tipos',
106
151
  'oneOf.invalid': 'El valor de {{#label}} no coincide con ningún tipo permitido',
107
152
 
108
- // Custom validation
109
- 'CUSTOM_VALIDATION_FAILED': 'Validación fallida',
110
- 'ASYNC_VALIDATION_NOT_SUPPORTED': 'La validación asíncrona no es compatible en validate() síncrono',
111
- 'VALIDATE_MUST_BE_FUNCTION': 'validate debe ser una función'
112
- };
153
+ // Error fallback
154
+ UNKNOWN_ERROR: 'Error de validación desconocido',
155
+ CUSTOM_VALIDATION_FAILED: 'Validación fallida',
156
+ ASYNC_VALIDATION_NOT_SUPPORTED: 'La validación asíncrona no es compatible en validate() síncrono',
157
+ VALIDATE_MUST_BE_FUNCTION: 'validate debe ser una función',
158
+ }
113
159
 
160
+ export default esES
@@ -1,18 +1,53 @@
1
- module.exports = {
1
+ import type { LocaleMessages } from './types.js'
2
+
3
+ const frFR: LocaleMessages = {
2
4
  // Generic
3
5
  required: '{{#label}} est requis',
4
- type: '{{#label}} doit être de type {{#expected}}, mais {{#actual}} a été reçu',
5
- min: 'La longueur de {{#label}} doit être d\'au moins {{#limit}}',
6
- max: 'La longueur de {{#label}} doit être d\'au plus {{#limit}}',
6
+ type: "{{#label}} doit être de type {{#expected}}, mais {{#actual}} a été reçu",
7
+ min: "La longueur de {{#label}} doit être d'au moins {{#limit}}",
8
+ max: "La longueur de {{#label}} doit être d'au plus {{#limit}}",
7
9
  length: 'La longueur de {{#label}} doit être exactement {{#expected}}',
8
- pattern: 'Le format de {{#label}} n\'est pas valide',
10
+ pattern: "Le format de {{#label}} n'est pas valide",
9
11
  enum: '{{#label}} doit être l\'un de : {{#allowed}}',
10
12
  custom: 'Validation échouée pour {{#label}} : {{#message}}',
11
13
  circular: 'Référence circulaire détectée dans {{#label}}',
12
14
  'max-depth': 'Profondeur maximale de récursion ({{#depth}}) dépassée dans {{#label}}',
13
15
  exception: 'Exception de validation dans {{#label}} : {{#message}}',
14
16
 
15
- // Formats
17
+ // Conditional (v2 additions)
18
+ 'conditional.underAge': 'Les mineurs ne peuvent pas s\'inscrire',
19
+ 'conditional.blocked': 'Le compte a été bloqué',
20
+ 'conditional.notAllowed': 'L\'inscription n\'est pas autorisée',
21
+
22
+ // I18nError — generic (v2 additions)
23
+ 'error.notFound': '{{#resource}} introuvable',
24
+ 'error.forbidden': 'Accès à {{#resource}} interdit',
25
+ 'error.unauthorized': 'Non autorisé, veuillez vous connecter',
26
+ 'error.invalid': '{{#field}} n\'est pas valide',
27
+ 'error.duplicate': '{{#resource}} existe déjà',
28
+ 'error.conflict': 'Conflit d\'opération : {{#reason}}',
29
+
30
+ // Account (v2 additions)
31
+ 'account.notFound': { code: 'ACCOUNT_NOT_FOUND', message: 'Compte introuvable' },
32
+ 'account.inactive': 'Le compte est inactif',
33
+ 'account.banned': 'Le compte a été banni',
34
+ 'account.insufficientBalance': {
35
+ code: 'INSUFFICIENT_BALANCE',
36
+ message: 'Solde insuffisant, actuel : {{#balance}}, requis : {{#required}}',
37
+ },
38
+ 'account.insufficientCredits': 'Crédits insuffisants, actuels : {{#credits}}, requis : {{#required}}',
39
+
40
+ // User (v2 additions)
41
+ 'user.notFound': 'Utilisateur introuvable',
42
+ 'user.notVerified': "L'utilisateur n'est pas vérifié",
43
+ 'user.noPermission': 'Pas de permission d\'administrateur',
44
+
45
+ // Order (v2 additions)
46
+ 'order.notPaid': { code: 'ORDER_NOT_PAID', message: 'Commande non payée' },
47
+ 'order.paymentMissing': 'Informations de paiement manquantes',
48
+ 'order.addressMissing': 'Adresse de livraison manquante',
49
+
50
+ // Format
16
51
  'format.email': '{{#label}} doit être une adresse e-mail valide',
17
52
  'format.url': '{{#label}} doit être une URL valide',
18
53
  'format.uuid': '{{#label}} doit être un UUID valide',
@@ -24,9 +59,14 @@ module.exports = {
24
59
  'format.binary': '{{#label}} doit être une chaîne base64 valide',
25
60
 
26
61
  // String
27
- 'string.hostname': '{{#label}} doit être un nom d\'hôte valide',
62
+ 'string.hostname': "{{#label}} doit être un nom d'hôte valide",
28
63
  'string.pattern': 'Le format de {{#label}} ne correspond pas au modèle requis',
29
64
  'string.enum': '{{#label}} doit être l\'un de : {{#valids}}',
65
+ 'string.length': 'La longueur de {{#label}} doit être exactement {{#limit}} caractères',
66
+ 'string.alphanum': '{{#label}} ne doit contenir que des caractères alphanumériques',
67
+ 'string.trim': '{{#label}} ne doit pas avoir d\'espaces en début ou en fin',
68
+ 'string.lowercase': '{{#label}} doit être en minuscules',
69
+ 'string.uppercase': '{{#label}} doit être en majuscules',
30
70
 
31
71
  // Number
32
72
  'number.base': '{{#label}} doit être un nombre',
@@ -35,6 +75,8 @@ module.exports = {
35
75
  'number.integer': '{{#label}} doit être un nombre entier',
36
76
  'number.positive': '{{#label}} doit être un nombre positif',
37
77
  'number.negative': '{{#label}} doit être un nombre négatif',
78
+ 'number.precision': '{{#label}} doit avoir au plus {{#limit}} décimales',
79
+ 'number.port': '{{#label}} doit être un numéro de port valide (1-65535)',
38
80
 
39
81
  // Boolean
40
82
  'boolean.base': '{{#label}} doit être un booléen',
@@ -44,7 +86,8 @@ module.exports = {
44
86
  'object.min': '{{#label}} doit avoir au moins {{#limit}} propriétés',
45
87
  'object.max': '{{#label}} doit avoir au plus {{#limit}} propriétés',
46
88
  'object.unknown': '{{#label}} contient une propriété inconnue : {{#key}}',
47
- // v1.1.6 - additionalProperties
89
+ 'object.missing': '{{#label}} est manquant les propriétés requises',
90
+ 'object.schema': '{{#label}} contient des propriétés supplémentaires',
48
91
  'additionalProperties': '{{#label}} NE doit PAS avoir de propriétés supplémentaires : {{#key}}',
49
92
 
50
93
  // Array
@@ -53,11 +96,16 @@ module.exports = {
53
96
  'array.max': '{{#label}} doit avoir au plus {{#limit}} éléments',
54
97
  'array.length': '{{#label}} doit avoir exactement {{#limit}} éléments',
55
98
  'array.unique': '{{#label}} ne doit pas contenir d\'éléments en double',
99
+ 'array.sparse': '{{#label}} ne doit pas être un tableau clairsemé',
100
+ 'array.includesRequired': '{{#label}} doit inclure les éléments requis',
56
101
 
57
102
  // Date
58
103
  'date.base': '{{#label}} doit être une date valide',
59
104
  'date.min': '{{#label}} ne doit pas être antérieur à {{#limit}}',
60
105
  'date.max': '{{#label}} ne doit pas être postérieur à {{#limit}}',
106
+ 'date.format': "Le format de date de {{#label}} n'est pas valide",
107
+ 'date.greater': '{{#label}} doit être après {{#limit}}',
108
+ 'date.less': '{{#label}} doit être avant {{#limit}}',
61
109
 
62
110
  // Any
63
111
  'any.required': '{{#label}} est requis',
@@ -65,10 +113,10 @@ module.exports = {
65
113
  'any.only': '{{#label}} doit correspondre à {{#valids}}',
66
114
  'any.unknown': 'Le champ {{#key}} n\'est pas autorisé',
67
115
 
68
- // Patterns (Legacy/Specific)
116
+ // Patterns
69
117
  'pattern.phone': 'Numéro de téléphone non valide',
70
118
  'pattern.phone.international': 'Numéro de téléphone international non valide',
71
- 'pattern.idCard': 'Numéro de carte d\'identité non valide',
119
+ 'pattern.idCard': "Numéro de carte d'identité non valide",
72
120
  'pattern.creditCard': 'Numéro de carte de crédit non valide',
73
121
  'pattern.creditCard.visa': 'Numéro de carte Visa non valide',
74
122
  'pattern.creditCard.mastercard': 'Numéro Mastercard non valide',
@@ -76,38 +124,37 @@ module.exports = {
76
124
  'pattern.creditCard.discover': 'Numéro de carte Discover non valide',
77
125
  'pattern.creditCard.jcb': 'Numéro de carte JCB non valide',
78
126
  'pattern.creditCard.unionpay': 'Numéro de carte UnionPay non valide',
79
- 'pattern.licensePlate': 'Numéro de plaque d\'immatriculation non valide',
127
+ "pattern.licensePlate": "Numéro de plaque d'immatriculation non valide",
80
128
  'pattern.postalCode': 'Code postal non valide',
81
129
  'pattern.passport': 'Numéro de passeport non valide',
82
130
  'pattern.objectId': 'ObjectId non valide',
83
131
  'pattern.hexColor': 'Couleur hexadécimale non valide',
84
132
  'pattern.macAddress': 'Adresse MAC non valide',
85
133
  'pattern.cron': 'Expression Cron non valide',
86
- 'pattern.slug': 'Le slug d\'URL ne peut contenir que des lettres minuscules, des chiffres et des tirets',
87
- // v1.0.2 新增
134
+ "pattern.slug": "Le slug d'URL ne peut contenir que des lettres minuscules, des chiffres et des tirets",
88
135
  'pattern.domain': '{{#label}} doit être un nom de domaine valide',
89
136
  'pattern.ip': '{{#label}} doit être une adresse IP valide',
90
137
  'pattern.base64': '{{#label}} doit être une chaîne Base64 valide',
91
138
  'pattern.jwt': '{{#label}} doit être un token JWT valide',
92
139
  'pattern.json': '{{#label}} doit être une chaîne JSON valide',
93
-
94
- // Username & Password
95
- 'pattern.username': 'Le nom d\'utilisateur doit commencer par une lettre et contenir uniquement des lettres, des chiffres et des tirets bas',
140
+ "pattern.username": "Le nom d'utilisateur doit commencer par une lettre et contenir uniquement des lettres, des chiffres et des tirets bas",
96
141
  'pattern.password.weak': 'Le mot de passe doit contenir au moins 6 caractères',
97
142
  'pattern.password.medium': 'Le mot de passe doit contenir au moins 8 caractères et inclure des lettres et des chiffres',
98
143
  'pattern.password.strong': 'Le mot de passe doit contenir au moins 8 caractères et inclure des lettres majuscules, minuscules et des chiffres',
99
144
  'pattern.password.veryStrong': 'Le mot de passe doit contenir au moins 10 caractères et inclure des lettres majuscules, minuscules, des chiffres et des caractères spéciaux',
145
+ 'pattern.emailOrPhone': 'Doit être un e-mail ou un numéro de téléphone',
146
+ 'pattern.usernameOrEmail': "Doit être un nom d'utilisateur ou un e-mail",
147
+ 'pattern.httpOrHttps': 'Doit être une URL commençant par http ou https',
100
148
 
101
- // Unknown error fallback
102
- 'UNKNOWN_ERROR': 'Erreur de validation inconnue',
103
-
104
- // oneOf (union de types) - v1.1.0
105
- oneOf: '{{#label}} doit correspondre à l\'un des types suivants',
106
- 'oneOf.invalid': 'La valeur de {{#label}} ne correspond à aucun type autorisé',
149
+ // oneOf
150
+ oneOf: "{{#label}} doit correspondre à l'un des types suivants",
151
+ 'oneOf.invalid': '{{#label}} ne correspond à aucun type autorisé',
107
152
 
108
- // Custom validation
109
- 'CUSTOM_VALIDATION_FAILED': 'Validation échouée',
110
- 'ASYNC_VALIDATION_NOT_SUPPORTED': 'La validation asynchrone n\'est pas prise en charge dans validate() synchrone',
111
- 'VALIDATE_MUST_BE_FUNCTION': 'validate doit être une fonction'
112
- };
153
+ // Error fallback
154
+ UNKNOWN_ERROR: 'Erreur de validation inconnue',
155
+ CUSTOM_VALIDATION_FAILED: 'Validation échouée',
156
+ ASYNC_VALIDATION_NOT_SUPPORTED: 'La validation asynchrone n\'est pas prise en charge dans validate() synchrone',
157
+ VALIDATE_MUST_BE_FUNCTION: 'validate doit être une fonction',
158
+ }
113
159
 
160
+ export default frFR
@@ -0,0 +1,103 @@
1
+ import type { LocaleKey, LocaleMessage, LocaleMessages } from './types.js'
2
+ import zhCN from './zh-CN.js'
3
+ import enUS from './en-US.js'
4
+ import jaJP from './ja-JP.js'
5
+ import esES from './es-ES.js'
6
+ import frFR from './fr-FR.js'
7
+
8
+ export type { LocaleKey, LocaleMessage, LocaleMessages }
9
+
10
+ // ─── Supported locale registry ─────────────────────────────────────────────────────────
11
+ const LOCALES: Readonly<Record<string, LocaleMessages>> = {
12
+ 'zh-CN': zhCN,
13
+ 'en-US': enUS,
14
+ 'ja-JP': jaJP,
15
+ 'es-ES': esES,
16
+ 'fr-FR': frFR,
17
+ }
18
+
19
+ /** Default locale (global fallback base) */
20
+ const DEFAULT_LOCALE = 'en-US'
21
+
22
+ /** en-US acts as secondary fallback (used when any locale is missing a key) */
23
+ const FALLBACK_LOCALE = 'en-US'
24
+
25
+ /**
26
+ * Look up a locale message entry (with fallback chain).
27
+ *
28
+ * Fallback chain: locale → en-US (if locale ≠ en-US) → key itself
29
+ */
30
+ export function getMessage(
31
+ key: LocaleKey,
32
+ locale: string = DEFAULT_LOCALE
33
+ ): LocaleMessage {
34
+ const messages = LOCALES[locale]
35
+ if (messages && key in messages) {
36
+ return messages[key]
37
+ }
38
+
39
+ // Primary fallback: en-US
40
+ if (locale !== DEFAULT_LOCALE) {
41
+ const defaultMessages = LOCALES[DEFAULT_LOCALE]
42
+ if (defaultMessages && key in defaultMessages) {
43
+ return defaultMessages[key]
44
+ }
45
+ }
46
+
47
+ // Secondary fallback: en-US
48
+ const fallbackMessages = LOCALES[FALLBACK_LOCALE]
49
+ if (fallbackMessages && key in fallbackMessages) {
50
+ return fallbackMessages[key]
51
+ }
52
+
53
+ // Final fallback: return the key itself (never returns undefined)
54
+ return key
55
+ }
56
+
57
+ /**
58
+ * Get the resolved string for a message (unwraps {code, message} object format).
59
+ */
60
+ export function getMessageString(
61
+ key: LocaleKey,
62
+ locale: string = DEFAULT_LOCALE
63
+ ): string {
64
+ const msg = getMessage(key, locale)
65
+ if (typeof msg === 'string') return msg
66
+ return msg.message
67
+ }
68
+
69
+ /**
70
+ * Get the error code of a message (if the value is a {code, message} object).
71
+ */
72
+ export function getMessageCode(
73
+ key: LocaleKey,
74
+ locale: string = DEFAULT_LOCALE
75
+ ): string | number | undefined {
76
+ const msg = getMessage(key, locale)
77
+ if (typeof msg === 'object') return msg.code
78
+ return undefined
79
+ }
80
+
81
+ /**
82
+ * Get the complete message map for the given locale.
83
+ */
84
+ export function getMessages(locale: string = DEFAULT_LOCALE): LocaleMessages {
85
+ return LOCALES[locale] ?? LOCALES[DEFAULT_LOCALE]!
86
+ }
87
+
88
+ /**
89
+ * Check whether a locale is supported.
90
+ */
91
+ export function isSupportedLocale(locale: string): boolean {
92
+ return locale in LOCALES
93
+ }
94
+
95
+ /**
96
+ * Get all supported locale codes.
97
+ */
98
+ export function getSupportedLocales(): string[] {
99
+ return Object.keys(LOCALES)
100
+ }
101
+
102
+ export { zhCN, enUS, jaJP, esES, frFR }
103
+ export default LOCALES