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
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/plugins/custom-validator.ts
21
+ var custom_validator_exports = {};
22
+ __export(custom_validator_exports, {
23
+ customValidatorPlugin: () => customValidatorPlugin,
24
+ default: () => custom_validator_default
25
+ });
26
+ module.exports = __toCommonJS(custom_validator_exports);
27
+ function getValidator(core) {
28
+ const coreRecord = core;
29
+ const validator = coreRecord.getDefaultValidator?.();
30
+ if (!validator) {
31
+ throw new Error("getDefaultValidator() is not available. Please provide schema-dsl core object.");
32
+ }
33
+ return validator;
34
+ }
35
+ function getPluginBucket() {
36
+ const globalRecord = globalThis;
37
+ if (!globalRecord.__schemaDsl_plugins) {
38
+ globalRecord.__schemaDsl_plugins = {};
39
+ }
40
+ return globalRecord.__schemaDsl_plugins;
41
+ }
42
+ var customValidatorPlugin = {
43
+ name: "custom-validator",
44
+ version: "1.0.0",
45
+ description: "Custom validator plugin \u2014 adds business-specific validation rules",
46
+ install(core, _options = {}, _context) {
47
+ const validator = getValidator(core);
48
+ this.addCustomKeywords(validator);
49
+ getPluginBucket()["custom-validator"] = this;
50
+ console.log("[Plugin] custom-validator installed");
51
+ },
52
+ uninstall() {
53
+ delete getPluginBucket()["custom-validator"];
54
+ console.log("[Plugin] custom-validator uninstalled");
55
+ },
56
+ addCustomKeywords(validator) {
57
+ const ajv = validator.getAjv();
58
+ if (!ajv.getKeyword?.("unique")) {
59
+ validator.addKeyword("unique", {
60
+ async: true,
61
+ type: "string",
62
+ validate: async function validateUnique(schema) {
63
+ if (!schema) return true;
64
+ const { table, field } = schema;
65
+ const exists = false;
66
+ if (exists) {
67
+ ;
68
+ validateUnique.errors = [{
69
+ keyword: "unique",
70
+ message: `${field} already exists in ${table}`,
71
+ params: { table, field }
72
+ }];
73
+ return false;
74
+ }
75
+ return true;
76
+ }
77
+ });
78
+ }
79
+ if (!ajv.getKeyword?.("passwordStrength")) {
80
+ validator.addKeyword("passwordStrength", {
81
+ type: "string",
82
+ validate: function validatePasswordStrength(schema, data) {
83
+ if (!schema) return true;
84
+ const strength = String(schema);
85
+ const value = String(data ?? "");
86
+ const rules = {
87
+ weak: /^.{6,}$/,
88
+ medium: /^(?=.*[a-z])(?=.*[A-Z]).{8,}$/,
89
+ strong: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}$/
90
+ };
91
+ const pattern = rules[strength];
92
+ if (!pattern) return true;
93
+ if (!pattern.test(value)) {
94
+ ;
95
+ validatePasswordStrength.errors = [{
96
+ keyword: "passwordStrength",
97
+ message: `Password does not meet ${strength} strength requirements`,
98
+ params: { strength }
99
+ }];
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ });
105
+ }
106
+ if (!ajv.getKeyword?.("idCard")) {
107
+ validator.addKeyword("idCard", {
108
+ type: "string",
109
+ validate: (schema, data) => {
110
+ if (!schema) return true;
111
+ const value = String(data ?? "");
112
+ const pattern = /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
113
+ if (!pattern.test(value)) {
114
+ return false;
115
+ }
116
+ return customValidatorPlugin._validateIdCardChecksum(value);
117
+ }
118
+ });
119
+ }
120
+ },
121
+ _validateIdCardChecksum(idCard) {
122
+ const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
123
+ const checksums = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
124
+ let sum = 0;
125
+ for (let i = 0; i < 17; i += 1) {
126
+ sum += Number.parseInt(idCard[i], 10) * weights[i];
127
+ }
128
+ const checksum = checksums[sum % 11];
129
+ return idCard[17].toUpperCase() === checksum;
130
+ },
131
+ hooks: {
132
+ onBeforeValidate() {
133
+ },
134
+ onAfterValidate() {
135
+ },
136
+ onError(error) {
137
+ console.error("[custom-validator] Error:", error.message);
138
+ }
139
+ }
140
+ };
141
+ var custom_validator_default = customValidatorPlugin;
142
+ // Annotate the CommonJS export names for ESM import in node:
143
+ 0 && (module.exports = {
144
+ customValidatorPlugin
145
+ });
146
+ //# sourceMappingURL=custom-validator.cjs.map
@@ -0,0 +1,10 @@
1
+ import { P as Plugin } from '../plugin-CIKtTMtS.cjs';
2
+ import { V as Validator } from '../Validator-C7GsVQOH.cjs';
3
+ import 'ajv';
4
+
5
+ declare const customValidatorPlugin: Plugin & {
6
+ addCustomKeywords: (validator: Validator) => void;
7
+ _validateIdCardChecksum: (idCard: string) => boolean;
8
+ };
9
+
10
+ export { customValidatorPlugin, customValidatorPlugin as default };
@@ -0,0 +1,10 @@
1
+ import { P as Plugin } from '../plugin-CIKtTMtS.js';
2
+ import { V as Validator } from '../Validator-hFWKGxir.js';
3
+ import 'ajv';
4
+
5
+ declare const customValidatorPlugin: Plugin & {
6
+ addCustomKeywords: (validator: Validator) => void;
7
+ _validateIdCardChecksum: (idCard: string) => boolean;
8
+ };
9
+
10
+ export { customValidatorPlugin, customValidatorPlugin as default };
@@ -0,0 +1,121 @@
1
+ // src/plugins/custom-validator.ts
2
+ function getValidator(core) {
3
+ const coreRecord = core;
4
+ const validator = coreRecord.getDefaultValidator?.();
5
+ if (!validator) {
6
+ throw new Error("getDefaultValidator() is not available. Please provide schema-dsl core object.");
7
+ }
8
+ return validator;
9
+ }
10
+ function getPluginBucket() {
11
+ const globalRecord = globalThis;
12
+ if (!globalRecord.__schemaDsl_plugins) {
13
+ globalRecord.__schemaDsl_plugins = {};
14
+ }
15
+ return globalRecord.__schemaDsl_plugins;
16
+ }
17
+ var customValidatorPlugin = {
18
+ name: "custom-validator",
19
+ version: "1.0.0",
20
+ description: "Custom validator plugin \u2014 adds business-specific validation rules",
21
+ install(core, _options = {}, _context) {
22
+ const validator = getValidator(core);
23
+ this.addCustomKeywords(validator);
24
+ getPluginBucket()["custom-validator"] = this;
25
+ console.log("[Plugin] custom-validator installed");
26
+ },
27
+ uninstall() {
28
+ delete getPluginBucket()["custom-validator"];
29
+ console.log("[Plugin] custom-validator uninstalled");
30
+ },
31
+ addCustomKeywords(validator) {
32
+ const ajv = validator.getAjv();
33
+ if (!ajv.getKeyword?.("unique")) {
34
+ validator.addKeyword("unique", {
35
+ async: true,
36
+ type: "string",
37
+ validate: async function validateUnique(schema) {
38
+ if (!schema) return true;
39
+ const { table, field } = schema;
40
+ const exists = false;
41
+ if (exists) {
42
+ ;
43
+ validateUnique.errors = [{
44
+ keyword: "unique",
45
+ message: `${field} already exists in ${table}`,
46
+ params: { table, field }
47
+ }];
48
+ return false;
49
+ }
50
+ return true;
51
+ }
52
+ });
53
+ }
54
+ if (!ajv.getKeyword?.("passwordStrength")) {
55
+ validator.addKeyword("passwordStrength", {
56
+ type: "string",
57
+ validate: function validatePasswordStrength(schema, data) {
58
+ if (!schema) return true;
59
+ const strength = String(schema);
60
+ const value = String(data ?? "");
61
+ const rules = {
62
+ weak: /^.{6,}$/,
63
+ medium: /^(?=.*[a-z])(?=.*[A-Z]).{8,}$/,
64
+ strong: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{10,}$/
65
+ };
66
+ const pattern = rules[strength];
67
+ if (!pattern) return true;
68
+ if (!pattern.test(value)) {
69
+ ;
70
+ validatePasswordStrength.errors = [{
71
+ keyword: "passwordStrength",
72
+ message: `Password does not meet ${strength} strength requirements`,
73
+ params: { strength }
74
+ }];
75
+ return false;
76
+ }
77
+ return true;
78
+ }
79
+ });
80
+ }
81
+ if (!ajv.getKeyword?.("idCard")) {
82
+ validator.addKeyword("idCard", {
83
+ type: "string",
84
+ validate: (schema, data) => {
85
+ if (!schema) return true;
86
+ const value = String(data ?? "");
87
+ const pattern = /^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dXx]$/;
88
+ if (!pattern.test(value)) {
89
+ return false;
90
+ }
91
+ return customValidatorPlugin._validateIdCardChecksum(value);
92
+ }
93
+ });
94
+ }
95
+ },
96
+ _validateIdCardChecksum(idCard) {
97
+ const weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
98
+ const checksums = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"];
99
+ let sum = 0;
100
+ for (let i = 0; i < 17; i += 1) {
101
+ sum += Number.parseInt(idCard[i], 10) * weights[i];
102
+ }
103
+ const checksum = checksums[sum % 11];
104
+ return idCard[17].toUpperCase() === checksum;
105
+ },
106
+ hooks: {
107
+ onBeforeValidate() {
108
+ },
109
+ onAfterValidate() {
110
+ },
111
+ onError(error) {
112
+ console.error("[custom-validator] Error:", error.message);
113
+ }
114
+ }
115
+ };
116
+ var custom_validator_default = customValidatorPlugin;
117
+ export {
118
+ customValidatorPlugin,
119
+ custom_validator_default as default
120
+ };
121
+ //# sourceMappingURL=custom-validator.js.map
@@ -1,7 +1,7 @@
1
1
  # schema-dsl 功能索引
2
2
 
3
3
 
4
- > **更新时间**: 2025-12-25
4
+ > **更新时间**: 2026-04-30
5
5
  > **用途**: 快速查找所有功能及其文档位置
6
6
 
7
7
  ---
@@ -43,7 +43,7 @@ const schema = dsl({
43
43
  - 📖 [快速开始](./quick-start.md)
44
44
  - 📖 [DSL语法指南](./dsl-syntax.md)
45
45
 
46
- **代码位置**: `lib/adapters/DslAdapter.js`
46
+ **代码位置**: `src/index.ts` / `src/adapters/DslAdapter.ts`
47
47
 
48
48
  ---
49
49
 
@@ -59,7 +59,8 @@ const schema = dsl({
59
59
  - ✅ `custom(fn)` - 自定义验证器
60
60
  - ✅ `when(field, opts)` - 条件验证
61
61
  - ✅ `default(value)` - 默认值
62
- - ✅ `toSchema()` - 转为JSON Schema
62
+ - ✅ `toSchema()` - 转为JSON Schema(含内部标记字段)
63
+ - ✅ `toJsonSchema()` - 转为纯净 JSON Schema(自动清理 `_required`/`_customMessages` 等内部标记,适用于 OpenAPI / 外部系统)🆕 v1.2.5
63
64
  - ✅ `validate(data)` - 验证数据
64
65
  - ✅ `validateNestingDepth(schema, maxDepth)` - 检测嵌套深度(静态方法)
65
66
 
@@ -88,7 +89,7 @@ const userSchema = dsl({
88
89
  - 📖 [API参考 - DslBuilder类](./api-reference.md#dslbuilder-类)
89
90
  - 📖 [String扩展文档](./string-extensions.md)
90
91
 
91
- **代码位置**: `lib/core/DslBuilder.js`
92
+ **代码位置**: `src/core/DslBuilder.ts`
92
93
 
93
94
  ---
94
95
 
@@ -108,10 +109,10 @@ const schema = dsl({
108
109
 
109
110
  **文档位置**:
110
111
  - 📖 [String扩展完整文档](./string-extensions.md)
111
- - 📖 [README](../README.md)
112
+ - 📖 [README](https://github.com/vextjs/schema-dsl/blob/main/README.md)
112
113
 
113
114
 
114
- **代码位置**: `lib/core/StringExtensions.js`
115
+ **代码位置**: `src/core/StringExtensions.ts`
115
116
 
116
117
  ---
117
118
 
@@ -124,7 +125,7 @@ const schema = dsl({
124
125
  **可用方法**:
125
126
  - ✅ `validate(schema, data, options)` - 验证数据
126
127
  - ✅ `compile(schema, cacheKey)` - 编译Schema
127
- - ✅ `validateBatch(schema, dataArray, options)` - 批量验证
128
+ - ✅ `validateBatch(schema, dataArray)` - 批量验证
128
129
  - ✅ `addKeyword(name, definition)` - 添加自定义关键字
129
130
  - ✅ `addFormat(name, validator)` - 添加自定义格式
130
131
  - ✅ `clearCache()` - 清空缓存
@@ -147,7 +148,7 @@ console.log(result.errors); // 错误列表
147
148
  - 📖 [validate方法详解](./validate.md)
148
149
  - 📖 [快速开始](./quick-start.md)
149
150
 
150
- **代码位置**: `lib/core/Validator.js`
151
+ **代码位置**: `src/core/Validator.ts`
151
152
 
152
153
  ---
153
154
 
@@ -167,7 +168,7 @@ const result = validate(schema, { email: 'test@example.com' });
167
168
  - 📖 [API参考 - validate()函数](./api-reference.md)
168
169
  - 📖 [快速开始](./quick-start.md#1-hello-world30秒)
169
170
 
170
- **代码位置**: `index.js` (单例实现)
171
+ **代码位置**: `src/index.ts`(默认单例导出)
171
172
 
172
173
  ---
173
174
 
@@ -196,10 +197,10 @@ console.log(command);
196
197
  ```
197
198
 
198
199
  **文档位置**:
199
- - 📖 [README - 数据库导出](../README.md#️-数据库导出)
200
- - 📖 [示例代码](../examples/export-demo.js)
200
+ - 📖 [数据库导出指南](./export-guide.md)
201
+ - 📖 [示例代码](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/feature-index.ts)
201
202
 
202
- **代码位置**: `lib/exporters/MongoDBExporter.js`
203
+ **代码位置**: `src/exporters/MongoDBExporter.ts`
203
204
 
204
205
  ---
205
206
 
@@ -226,10 +227,10 @@ console.log(ddl);
226
227
  ```
227
228
 
228
229
  **文档位置**:
229
- - 📖 [README - 数据库导出](../README.md#mysql-ddl)
230
- - 📖 [示例代码](../examples/export-demo.js)
230
+ - 📖 [数据库导出指南](./export-guide.md)
231
+ - 📖 [示例代码](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/feature-index.ts)
231
232
 
232
- **代码位置**: `lib/exporters/MySQLExporter.js`
233
+ **代码位置**: `src/exporters/MySQLExporter.ts`
233
234
 
234
235
  ---
235
236
 
@@ -256,10 +257,10 @@ console.log(ddl);
256
257
  ```
257
258
 
258
259
  **文档位置**:
259
- - 📖 [README - 数据库导出](../README.md#postgresql-ddl)
260
- - 📖 [示例代码](../examples/export-demo.js)
260
+ - 📖 [数据库导出指南](./export-guide.md)
261
+ - 📖 [示例代码](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/feature-index.ts)
261
262
 
262
- **代码位置**: `lib/exporters/PostgreSQLExporter.js`
263
+ **代码位置**: `src/exporters/PostgreSQLExporter.ts`
263
264
 
264
265
  ---
265
266
 
@@ -272,10 +273,12 @@ console.log(ddl);
272
273
  **可用方法**:
273
274
  - ✅ `reusable(factory)` - 创建可复用片段
274
275
  - ✅ `createLibrary(fragments)` - 创建片段库
275
- - ✅ `merge(...schemas)` - 合并多个Schema
276
276
  - ✅ `extend(baseSchema, extensions)` - 扩展Schema
277
277
  - ✅ `pick(schema, fields)` - 筛选字段
278
278
  - ✅ `omit(schema, fields)` - 排除字段
279
+ - ✅ `partial(schema, fields?)` - 将字段改为可选
280
+ - ✅ `validateBatch(schema, dataArray, ajvInstance)` - 带汇总统计的批量验证
281
+ - ✅ `withPerformance(validator)` - 为 Validator 包装性能信息
279
282
  - ✅ `toMarkdown(schema)` - 导出为Markdown
280
283
  - ✅ `toHTML(schema)` - 导出为HTML
281
284
  - ✅ `clone(schema)` - 深度克隆
@@ -297,7 +300,7 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
297
300
  **文档位置**:
298
301
  - 📖 [API参考 - SchemaUtils](./api-reference.md#工具函数)
299
302
 
300
- **代码位置**: `lib/utils/SchemaUtils.js`
303
+ **代码位置**: `src/utils/SchemaUtils.ts`
301
304
 
302
305
  ---
303
306
 
@@ -306,15 +309,17 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
306
309
  **功能**: 类型转换工具(JSON Schema ↔ 数据库类型)
307
310
 
308
311
  **可用方法**:
309
- - ✅ `toMongoType(jsonSchemaType)` - 转为MongoDB BSON类型
310
- - ✅ `toMySQLType(jsonSchemaProperty)` - 转为MySQL数据类型
311
- - ✅ `toPostgreSQLType(jsonSchemaProperty)` - 转为PostgreSQL数据类型
312
+ - ✅ `toJSONSchemaType(nativeType)` - 转为 JSON Schema `type` 字符串
313
+ - ✅ `toMongoDBType(jsonSchemaType)` - 转为 MongoDB BSON 类型
314
+ - ✅ `toMySQLType(jsonSchemaType, schema?)` - 转为 MySQL 数据类型
315
+ - ✅ `toPostgreSQLType(jsonSchemaType, schema?)` - 转为 PostgreSQL 数据类型
316
+ - ✅ `normalizePropertyName(name)` - 规范化属性名
312
317
  - ✅ `formatToRegex(format)` - 格式验证转正则
313
318
 
314
319
  **文档位置**:
315
- - 📖 [API参考 - TypeConverter](./api-reference.md#typeconverter)
320
+ - 📖 [TypeConverter 文档](./type-converter.md)
316
321
 
317
- **代码位置**: `lib/utils/TypeConverter.js`
322
+ **代码位置**: `src/utils/TypeConverter.ts`
318
323
 
319
324
  ---
320
325
 
@@ -323,16 +328,22 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
323
328
  **功能**: Schema分析和辅助工具
324
329
 
325
330
  **可用方法**:
326
- - ✅ `validate(schema)` - 验证Schema有效性
331
+ - ✅ `isValidSchema(schema)` - 验证 Schema 有效性
332
+ - ✅ `generateSchemaId(schema)` - 生成基于内容的 Schema ID
327
333
  - ✅ `getFieldPaths(schema)` - 提取字段路径
328
- - ✅ `flatten(schema)` - 扁平化Schema
329
- - ✅ `clone(schema)` - 克隆Schema
330
- - ✅ `getComplexity(schema)` - 评估复杂度
334
+ - ✅ `flattenSchema(schema)` - 扁平化 Schema
335
+ - ✅ `cloneSchema(schema)` - 克隆 Schema
336
+ - ✅ `extractRequiredFields(schema)` - 提取 required 字段
337
+ - ✅ `compareSchemas(schema1, schema2)` - 比较 Schema
338
+ - ✅ `simplifySchema(schema)` - 精简 Schema
339
+ - ✅ `isValidPropertyName(name)` - 校验属性名
340
+ - ✅ `getSchemaComplexity(schema)` - 评估复杂度
341
+ - ✅ `summarizeSchema(schema)` - 生成摘要
331
342
 
332
343
  **文档位置**:
333
- - 📖 [API参考 - SchemaHelper](./api-reference.md#schemahelper)
344
+ - 📖 [SchemaHelper 文档](./schema-helper.md)
334
345
 
335
- **代码位置**: `lib/utils/SchemaHelper.js`
346
+ **代码位置**: `src/utils/SchemaHelper.ts`
336
347
 
337
348
  ---
338
349
 
@@ -343,16 +354,15 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
343
354
  **功能**: 格式化验证错误信息
344
355
 
345
356
  **可用方法**:
346
- - ✅ `format(errors, options)` - 格式化错误列表
347
- - ✅ `formatSingle(error, options)` - 格式化单个错误
348
- - ✅ `toJSON(errors)` - 转为JSON格式
349
- - ✅ `toText(errors)` - 转为文本格式
357
+ - ✅ `new ErrorFormatter(locale?, messages?)` - 创建格式化器
358
+ - ✅ `format(error, locale?)` - 格式化单个错误为消息字符串
359
+ - ✅ `formatDetailed(errors, locale?, customMessages?, alreadyMerged?)` - 格式化错误数组为标准错误项
350
360
 
351
361
  **文档位置**:
352
- - 📖 [API参考 - ErrorFormatter](./api-reference.md)
362
+ - 📖 [API参考 - ErrorFormatter / MessageTemplate / 底层解析工具](./api-reference.md)
353
363
  - 📖 [错误处理文档](./error-handling.md)
354
364
 
355
- **代码位置**: `lib/core/ErrorFormatter.js`
365
+ **代码位置**: `src/core/ErrorFormatter.ts`
356
366
 
357
367
  ---
358
368
 
@@ -360,7 +370,7 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
360
370
 
361
371
  **功能**: 错误码定义
362
372
 
363
- **代码位置**: `lib/core/ErrorCodes.js`
373
+ **代码位置**: `src/core/ErrorCodes.ts`
364
374
 
365
375
  ---
366
376
 
@@ -374,9 +384,25 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
374
384
  - ✅ `MessageTemplate.renderBatch(templates, vars)` - 批量渲染(静态方法)
375
385
 
376
386
  **文档位置**:
377
- - 📖 [API参考 - MessageTemplate](./api-reference.md)
387
+ - 📖 [API参考 - MessageTemplate](./api-reference.md#messagetemplate)
378
388
 
379
- **代码位置**: `lib/core/MessageTemplate.js`
389
+ **代码位置**: `src/core/MessageTemplate.ts`
390
+
391
+ ---
392
+
393
+ ### 类型注册与模板工具
394
+
395
+ **功能**: 面向进阶集成的模板渲染、JSON Schema 外观与自定义类型注册能力
396
+
397
+ **可用导出**:
398
+ - ✅ `renderTemplate(template, params)`
399
+ - ✅ `JSONSchemaCore`
400
+ - ✅ `TypeRegistry`
401
+
402
+ **文档位置**:
403
+ - 📖 [API参考 - renderTemplate / JSONSchemaCore / 类型注册与内部解析边界](./api-reference.md)
404
+
405
+ **代码位置**: `src/core/TemplateEngine.ts` / `src/core/JSONSchemaCore.ts` / `src/parser/TypeRegistry.ts`
380
406
 
381
407
  ---
382
408
 
@@ -396,11 +422,14 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
396
422
  **支持语言**:
397
423
  - ✅ en-US(英语)
398
424
  - ✅ zh-CN(中文)
425
+ - ✅ ja-JP(日语)
426
+ - ✅ es-ES(西班牙语)
427
+ - ✅ fr-FR(法语)
399
428
 
400
429
  **文档位置**:
401
430
  - 📖 [API参考 - Locale](./api-reference.md)
402
431
 
403
- **代码位置**: `lib/core/Locale.js`
432
+ **代码位置**: `src/core/Locale.ts`
404
433
 
405
434
  ---
406
435
 
@@ -419,9 +448,9 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
419
448
  - ✅ `size()` - 缓存大小
420
449
 
421
450
  **文档位置**:
422
- - 📖 [API参考 - CacheManager](./api-reference.md)
451
+ - 📖 [CacheManager 文档](./cache-manager.md)
423
452
 
424
- **代码位置**: `lib/core/CacheManager.js`
453
+ **代码位置**: `src/core/CacheManager.ts`
425
454
 
426
455
  ---
427
456
 
@@ -431,8 +460,7 @@ const extended = SchemaUtils.extend(schema1, { age: 'number' });
431
460
 
432
461
  **可用关键字**:
433
462
  - ✅ `regex` - 正则验证
434
- - ✅ `validate` - 函数验证
435
- - ✅ `range` - 数值范围
463
+ - ✅ `validate` - 自定义函数验证
436
464
 
437
465
  **使用示例**:
438
466
  ```javascript
@@ -448,9 +476,9 @@ const schema = {
448
476
  ```
449
477
 
450
478
  **文档位置**:
451
- - 📖 [README - 自定义验证](../README.md#-自定义验证)
479
+ - 📖 [错误处理文档](./error-handling.md)
452
480
 
453
- **代码位置**: `lib/validators/CustomKeywords.js`
481
+ **代码位置**: `src/validators/CustomKeywords.ts`
454
482
 
455
483
  ---
456
484
 
@@ -459,15 +487,15 @@ const schema = {
459
487
  ### 完整示例目录
460
488
 
461
489
  **基础示例**:
462
- - 📄 [dsl-style.js](../examples/dsl-style.js) - DSL基础用法
463
- - 📄 [string-extensions.js](../examples/string-extensions.js) - String扩展示例
490
+ - 📄 [dsl-syntax.ts](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/dsl-syntax.ts) - DSL基础用法
491
+ - 📄 [string-extensions.ts](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/string-extensions.ts) - String扩展示例
464
492
 
465
493
  **场景示例**:
466
- - 📁 [user-registration/](../examples/user-registration/) - 用户注册表单验证
467
- - 📁 [password-reset/](../examples/password-reset/) - 密码重置流程
494
+ - 📄 [quick-start.ts](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/quick-start.ts) - 用户注册式的基础表单验证起点
495
+ - 📄 [validation-guide.ts](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/validation-guide.ts) - 失败路径、错误处理与规则组合示例
468
496
 
469
497
  **导出示例**:
470
- - 📄 [export-demo.js](../examples/export-demo.js) - 数据库导出示例
498
+ - 📄 [feature-index.ts](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/feature-index.ts) - 功能索引代表性示例
471
499
 
472
500
  ---
473
501
 
@@ -480,40 +508,46 @@ const schema = {
480
508
  3. ✅ Validator类 - `docs/validate.md`
481
509
  4. ✅ API参考 - `docs/api-reference.md`
482
510
  5. ✅ 快速开始 - `docs/quick-start.md`
483
- 6. ✅ 数据库导出 - `README.md` + `examples/export-demo.js`
511
+ 6. ✅ 数据库导出 - `README.md` + `docs/export-guide.md`
484
512
  7. ✅ 自定义验证 - `README.md`
485
- 8. ✅ Schema工具 - `examples/schema-utils-chaining.examples.js`
513
+ 8. ✅ Schema工具 - `docs/schema-utils.md` + `docs/schema-helper.md`
486
514
 
487
515
  ### ⚠️ 文档需要补充
488
516
 
489
- 1. ⚠️ ErrorFormatter - 缺少独立文档
490
- 2. ⚠️ CacheManager - 缺少独立文档
491
- 3. ⚠️ TypeConverter - 缺少独立文档
492
- 4. ⚠️ SchemaHelper - 缺少独立文档
493
- 5. ⚠️ 错误处理 - 需要完整文档
517
+ 1. ⚠️ ErrorFormatter - 当前已在 API 参考与错误处理文档中覆盖;如需更聚焦入口,可后续增补专项文档
518
+ 2. ⚠️ PluginManager - 可补一份更聚焦的 API/Hook 速查
519
+ 3. ⚠️ 性能与基准测试 - 可继续补充独立诊断手册
520
+ 4. ⚠️ 示例运行方式 - 可补充统一的 TypeScript 示例编译说明
521
+ 5. ⚠️ 错误处理 - 可继续补充更完整的框架集成案例
494
522
 
495
523
  ### 📝 计划补充
496
524
 
497
- - [ ] 创建 `docs/error-handling.md` - 错误处理完整指南
498
- - [ ] 创建 `docs/utilities.md` - 工具函数完整文档
499
- - [ ] 创建 `docs/advanced.md` - 高级用法指南
500
- - [ ] 创建 `docs/performance.md` - 性能优化指南
525
+ - [ ] 增补 `ErrorFormatter` 专项文档
526
+ - [ ] 增补 Plugin Hook 速查文档
527
+ - [ ] 增补 TypeScript 示例统一运行说明
528
+ - [ ] 增补性能调优/基准解读手册
501
529
 
502
530
  ---
503
531
 
504
532
  ## 相关文档
505
533
 
506
- - 📖 [README.md](../README.md) - 项目介绍
534
+ - 📖 [README.md](https://github.com/vextjs/schema-dsl/blob/main/README.md) - 项目介绍
507
535
  - 📖 [快速开始](./quick-start.md) - 5分钟入门
508
536
  - 📖 [DSL语法指南](./dsl-syntax.md) - 完整语法
509
537
  - 📖 [String扩展](./string-extensions.md) - String扩展特性
510
538
  - 📖 [API参考](./api-reference.md) - 完整API
511
- - 📖 [CHANGELOG](../CHANGELOG.md) - 更新日志
512
- - 📖 [STATUS](../STATUS.md) - 项目状态
539
+ - 📖 [CHANGELOG](https://github.com/vextjs/schema-dsl/blob/main/CHANGELOG.md) - 更新日志
540
+
541
+ ---
542
+
543
+ ## 对应示例文件
544
+
545
+ **示例入口**: [feature-index.ts](https://github.com/vextjs/schema-dsl/blob/main/examples/docs/feature-index.ts)
546
+ **说明**: 以单文件串联 DSL、String 扩展和导出器三个代表性能力,作为功能索引页的快速落地入口。
513
547
 
514
548
  ---
515
549
 
516
- **最后更新**: 2025-12-29
517
- **维护者**: SchemaI-DSL Team
550
+ **最后更新**: 2026-05-08
551
+ **维护者**: schema-dsl Team
518
552
 
519
553