reliant-type 1.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 (345) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1305 -0
  3. package/dist/cjs/constants/SECURITY_CONSTANTS.js +49 -0
  4. package/dist/cjs/constants/SECURITY_CONSTANTS.js.map +1 -0
  5. package/dist/cjs/constants/VALIDATION_CONSTANTS.js +103 -0
  6. package/dist/cjs/constants/VALIDATION_CONSTANTS.js.map +1 -0
  7. package/dist/cjs/core/schema/extensions/SmartInference.js +200 -0
  8. package/dist/cjs/core/schema/extensions/SmartInference.js.map +1 -0
  9. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/Docs.js +100 -0
  10. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/Docs.js.map +1 -0
  11. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js +192 -0
  12. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js.map +1 -0
  13. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js +174 -0
  14. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js.map +1 -0
  15. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js +54 -0
  16. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js.map +1 -0
  17. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js +50 -0
  18. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js.map +1 -0
  19. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/index.js +15 -0
  20. package/dist/cjs/core/schema/extensions/components/AutoDocumentation/index.js.map +1 -0
  21. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js +70 -0
  22. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js.map +1 -0
  23. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js +40 -0
  24. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js.map +1 -0
  25. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js +19 -0
  26. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js.map +1 -0
  27. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js +20 -0
  28. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js.map +1 -0
  29. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js +49 -0
  30. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js.map +1 -0
  31. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/index.js +98 -0
  32. package/dist/cjs/core/schema/extensions/components/ConditionalValidation/index.js.map +1 -0
  33. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/FormValidator.js +85 -0
  34. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/FormValidator.js.map +1 -0
  35. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/LiveValidator.js +133 -0
  36. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/LiveValidator.js.map +1 -0
  37. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/StreamValidator.js +351 -0
  38. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/StreamValidator.js.map +1 -0
  39. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/index.js +109 -0
  40. package/dist/cjs/core/schema/extensions/components/RealtimeValidation/index.js.map +1 -0
  41. package/dist/cjs/core/schema/extensions/index.js +61 -0
  42. package/dist/cjs/core/schema/extensions/index.js.map +1 -0
  43. package/dist/cjs/core/schema/extensions/mods/index.js +51 -0
  44. package/dist/cjs/core/schema/extensions/mods/index.js.map +1 -0
  45. package/dist/cjs/core/schema/extensions/mods/openapi-converter.js +227 -0
  46. package/dist/cjs/core/schema/extensions/mods/openapi-converter.js.map +1 -0
  47. package/dist/cjs/core/schema/extensions/mods/typescript-generator.js +287 -0
  48. package/dist/cjs/core/schema/extensions/mods/typescript-generator.js.map +1 -0
  49. package/dist/cjs/core/schema/extensions/mods/validation-engine.js +224 -0
  50. package/dist/cjs/core/schema/extensions/mods/validation-engine.js.map +1 -0
  51. package/dist/cjs/core/schema/mode/interfaces/Interface.js +277 -0
  52. package/dist/cjs/core/schema/mode/interfaces/Interface.js.map +1 -0
  53. package/dist/cjs/core/schema/mode/interfaces/InterfaceSchema.js +1431 -0
  54. package/dist/cjs/core/schema/mode/interfaces/InterfaceSchema.js.map +1 -0
  55. package/dist/cjs/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js +520 -0
  56. package/dist/cjs/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js.map +1 -0
  57. package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js +624 -0
  58. package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js.map +1 -0
  59. package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js +811 -0
  60. package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js.map +1 -0
  61. package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js +599 -0
  62. package/dist/cjs/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js.map +1 -0
  63. package/dist/cjs/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js +89 -0
  64. package/dist/cjs/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js.map +1 -0
  65. package/dist/cjs/core/schema/mode/interfaces/errors/ErrorHandler.js +356 -0
  66. package/dist/cjs/core/schema/mode/interfaces/errors/ErrorHandler.js.map +1 -0
  67. package/dist/cjs/core/schema/mode/interfaces/errors/types/errors.type.js +80 -0
  68. package/dist/cjs/core/schema/mode/interfaces/errors/types/errors.type.js.map +1 -0
  69. package/dist/cjs/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js +778 -0
  70. package/dist/cjs/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js.map +1 -0
  71. package/dist/cjs/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js +523 -0
  72. package/dist/cjs/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js.map +1 -0
  73. package/dist/cjs/core/schema/mode/interfaces/typescript/ConditionalTypes.js +681 -0
  74. package/dist/cjs/core/schema/mode/interfaces/typescript/ConditionalTypes.js.map +1 -0
  75. package/dist/cjs/core/schema/mode/interfaces/typescript/IDESupport.js +430 -0
  76. package/dist/cjs/core/schema/mode/interfaces/typescript/IDESupport.js.map +1 -0
  77. package/dist/cjs/core/schema/mode/interfaces/typescript/TypeInference.js +225 -0
  78. package/dist/cjs/core/schema/mode/interfaces/typescript/TypeInference.js.map +1 -0
  79. package/dist/cjs/core/schema/mode/interfaces/typescript/index.js +44 -0
  80. package/dist/cjs/core/schema/mode/interfaces/typescript/index.js.map +1 -0
  81. package/dist/cjs/core/schema/mode/interfaces/validators/ConstraintParser.js +1134 -0
  82. package/dist/cjs/core/schema/mode/interfaces/validators/ConstraintParser.js.map +1 -0
  83. package/dist/cjs/core/schema/mode/interfaces/validators/TypeGuards.js +256 -0
  84. package/dist/cjs/core/schema/mode/interfaces/validators/TypeGuards.js.map +1 -0
  85. package/dist/cjs/core/schema/mode/interfaces/validators/TypeValidators.js +429 -0
  86. package/dist/cjs/core/schema/mode/interfaces/validators/TypeValidators.js.map +1 -0
  87. package/dist/cjs/core/schema/mode/interfaces/validators/UnionCache.js +404 -0
  88. package/dist/cjs/core/schema/mode/interfaces/validators/UnionCache.js.map +1 -0
  89. package/dist/cjs/core/schema/mode/interfaces/validators/ValidationHelpers.js +851 -0
  90. package/dist/cjs/core/schema/mode/interfaces/validators/ValidationHelpers.js.map +1 -0
  91. package/dist/cjs/core/schema/mode/interfaces/validators/mods/passValidator.js +262 -0
  92. package/dist/cjs/core/schema/mode/interfaces/validators/mods/passValidator.js.map +1 -0
  93. package/dist/cjs/core/schema/mode/interfaces/validators/mods/securityValidator.js +887 -0
  94. package/dist/cjs/core/schema/mode/interfaces/validators/mods/securityValidator.js.map +1 -0
  95. package/dist/cjs/core/schema/mode/interfaces/validators/mods/urlValidation.js +191 -0
  96. package/dist/cjs/core/schema/mode/interfaces/validators/mods/urlValidation.js.map +1 -0
  97. package/dist/cjs/core/schema/optimization/ObjectValidationCache.js +462 -0
  98. package/dist/cjs/core/schema/optimization/ObjectValidationCache.js.map +1 -0
  99. package/dist/cjs/core/schema/optimization/PerformanceMonitor.js +773 -0
  100. package/dist/cjs/core/schema/optimization/PerformanceMonitor.js.map +1 -0
  101. package/dist/cjs/core/schema/optimization/SchemaCompiler.js +600 -0
  102. package/dist/cjs/core/schema/optimization/SchemaCompiler.js.map +1 -0
  103. package/dist/cjs/core/types/ValidatorTypes.js +70 -0
  104. package/dist/cjs/core/types/ValidatorTypes.js.map +1 -0
  105. package/dist/cjs/core/types/parser.type.js +12 -0
  106. package/dist/cjs/core/types/parser.type.js.map +1 -0
  107. package/dist/cjs/core/utils/Make.js +61 -0
  108. package/dist/cjs/core/utils/Make.js.map +1 -0
  109. package/dist/cjs/core/utils/Mod.js +1033 -0
  110. package/dist/cjs/core/utils/Mod.js.map +1 -0
  111. package/dist/cjs/core/utils/UrlArgs.js +102 -0
  112. package/dist/cjs/core/utils/UrlArgs.js.map +1 -0
  113. package/dist/cjs/core/utils/arrayToEnum.js +18 -0
  114. package/dist/cjs/core/utils/arrayToEnum.js.map +1 -0
  115. package/dist/cjs/core/utils/createUrlArgsEnumFArray.js +13 -0
  116. package/dist/cjs/core/utils/createUrlArgsEnumFArray.js.map +1 -0
  117. package/dist/cjs/core/utils/securityHelpers.js +215 -0
  118. package/dist/cjs/core/utils/securityHelpers.js.map +1 -0
  119. package/dist/cjs/core/utils/securityValidatorHelpers.js +65 -0
  120. package/dist/cjs/core/utils/securityValidatorHelpers.js.map +1 -0
  121. package/dist/cjs/index.js +31 -0
  122. package/dist/cjs/index.js.map +1 -0
  123. package/dist/cjs/package.json +3 -0
  124. package/dist/esm/constants/SECURITY_CONSTANTS.js +47 -0
  125. package/dist/esm/constants/SECURITY_CONSTANTS.js.map +1 -0
  126. package/dist/esm/constants/VALIDATION_CONSTANTS.js +98 -0
  127. package/dist/esm/constants/VALIDATION_CONSTANTS.js.map +1 -0
  128. package/dist/esm/core/schema/extensions/SmartInference.js +197 -0
  129. package/dist/esm/core/schema/extensions/SmartInference.js.map +1 -0
  130. package/dist/esm/core/schema/extensions/components/AutoDocumentation/Docs.js +98 -0
  131. package/dist/esm/core/schema/extensions/components/AutoDocumentation/Docs.js.map +1 -0
  132. package/dist/esm/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js +190 -0
  133. package/dist/esm/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.js.map +1 -0
  134. package/dist/esm/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js +172 -0
  135. package/dist/esm/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.js.map +1 -0
  136. package/dist/esm/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js +52 -0
  137. package/dist/esm/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.js.map +1 -0
  138. package/dist/esm/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js +48 -0
  139. package/dist/esm/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.js.map +1 -0
  140. package/dist/esm/core/schema/extensions/components/AutoDocumentation/index.js +12 -0
  141. package/dist/esm/core/schema/extensions/components/AutoDocumentation/index.js.map +1 -0
  142. package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js +68 -0
  143. package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.js.map +1 -0
  144. package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js +38 -0
  145. package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalElse.js.map +1 -0
  146. package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js +17 -0
  147. package/dist/esm/core/schema/extensions/components/ConditionalValidation/ConditionalThen.js.map +1 -0
  148. package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js +18 -0
  149. package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.js.map +1 -0
  150. package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js +45 -0
  151. package/dist/esm/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.js.map +1 -0
  152. package/dist/esm/core/schema/extensions/components/ConditionalValidation/index.js +92 -0
  153. package/dist/esm/core/schema/extensions/components/ConditionalValidation/index.js.map +1 -0
  154. package/dist/esm/core/schema/extensions/components/RealtimeValidation/FormValidator.js +83 -0
  155. package/dist/esm/core/schema/extensions/components/RealtimeValidation/FormValidator.js.map +1 -0
  156. package/dist/esm/core/schema/extensions/components/RealtimeValidation/LiveValidator.js +131 -0
  157. package/dist/esm/core/schema/extensions/components/RealtimeValidation/LiveValidator.js.map +1 -0
  158. package/dist/esm/core/schema/extensions/components/RealtimeValidation/StreamValidator.js +349 -0
  159. package/dist/esm/core/schema/extensions/components/RealtimeValidation/StreamValidator.js.map +1 -0
  160. package/dist/esm/core/schema/extensions/components/RealtimeValidation/index.js +103 -0
  161. package/dist/esm/core/schema/extensions/components/RealtimeValidation/index.js.map +1 -0
  162. package/dist/esm/core/schema/extensions/index.js +53 -0
  163. package/dist/esm/core/schema/extensions/index.js.map +1 -0
  164. package/dist/esm/core/schema/extensions/mods/index.js +47 -0
  165. package/dist/esm/core/schema/extensions/mods/index.js.map +1 -0
  166. package/dist/esm/core/schema/extensions/mods/openapi-converter.js +225 -0
  167. package/dist/esm/core/schema/extensions/mods/openapi-converter.js.map +1 -0
  168. package/dist/esm/core/schema/extensions/mods/typescript-generator.js +284 -0
  169. package/dist/esm/core/schema/extensions/mods/typescript-generator.js.map +1 -0
  170. package/dist/esm/core/schema/extensions/mods/validation-engine.js +222 -0
  171. package/dist/esm/core/schema/extensions/mods/validation-engine.js.map +1 -0
  172. package/dist/esm/core/schema/mode/interfaces/Interface.js +269 -0
  173. package/dist/esm/core/schema/mode/interfaces/Interface.js.map +1 -0
  174. package/dist/esm/core/schema/mode/interfaces/InterfaceSchema.js +1429 -0
  175. package/dist/esm/core/schema/mode/interfaces/InterfaceSchema.js.map +1 -0
  176. package/dist/esm/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js +518 -0
  177. package/dist/esm/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.js.map +1 -0
  178. package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js +620 -0
  179. package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalAST.js.map +1 -0
  180. package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js +809 -0
  181. package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.js.map +1 -0
  182. package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js +597 -0
  183. package/dist/esm/core/schema/mode/interfaces/conditional/parser/ConditionalParser.js.map +1 -0
  184. package/dist/esm/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js +89 -0
  185. package/dist/esm/core/schema/mode/interfaces/conditional/types/ConditionalTypes.js.map +1 -0
  186. package/dist/esm/core/schema/mode/interfaces/errors/ErrorHandler.js +354 -0
  187. package/dist/esm/core/schema/mode/interfaces/errors/ErrorHandler.js.map +1 -0
  188. package/dist/esm/core/schema/mode/interfaces/errors/types/errors.type.js +80 -0
  189. package/dist/esm/core/schema/mode/interfaces/errors/types/errors.type.js.map +1 -0
  190. package/dist/esm/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js +776 -0
  191. package/dist/esm/core/schema/mode/interfaces/precompilation/FieldPrecompilers.js.map +1 -0
  192. package/dist/esm/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js +521 -0
  193. package/dist/esm/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.js.map +1 -0
  194. package/dist/esm/core/schema/mode/interfaces/typescript/ConditionalTypes.js +681 -0
  195. package/dist/esm/core/schema/mode/interfaces/typescript/ConditionalTypes.js.map +1 -0
  196. package/dist/esm/core/schema/mode/interfaces/typescript/IDESupport.js +428 -0
  197. package/dist/esm/core/schema/mode/interfaces/typescript/IDESupport.js.map +1 -0
  198. package/dist/esm/core/schema/mode/interfaces/typescript/TypeInference.js +223 -0
  199. package/dist/esm/core/schema/mode/interfaces/typescript/TypeInference.js.map +1 -0
  200. package/dist/esm/core/schema/mode/interfaces/typescript/index.js +35 -0
  201. package/dist/esm/core/schema/mode/interfaces/typescript/index.js.map +1 -0
  202. package/dist/esm/core/schema/mode/interfaces/validators/ConstraintParser.js +1132 -0
  203. package/dist/esm/core/schema/mode/interfaces/validators/ConstraintParser.js.map +1 -0
  204. package/dist/esm/core/schema/mode/interfaces/validators/TypeGuards.js +254 -0
  205. package/dist/esm/core/schema/mode/interfaces/validators/TypeGuards.js.map +1 -0
  206. package/dist/esm/core/schema/mode/interfaces/validators/TypeValidators.js +427 -0
  207. package/dist/esm/core/schema/mode/interfaces/validators/TypeValidators.js.map +1 -0
  208. package/dist/esm/core/schema/mode/interfaces/validators/UnionCache.js +400 -0
  209. package/dist/esm/core/schema/mode/interfaces/validators/UnionCache.js.map +1 -0
  210. package/dist/esm/core/schema/mode/interfaces/validators/ValidationHelpers.js +849 -0
  211. package/dist/esm/core/schema/mode/interfaces/validators/ValidationHelpers.js.map +1 -0
  212. package/dist/esm/core/schema/mode/interfaces/validators/mods/passValidator.js +260 -0
  213. package/dist/esm/core/schema/mode/interfaces/validators/mods/passValidator.js.map +1 -0
  214. package/dist/esm/core/schema/mode/interfaces/validators/mods/securityValidator.js +881 -0
  215. package/dist/esm/core/schema/mode/interfaces/validators/mods/securityValidator.js.map +1 -0
  216. package/dist/esm/core/schema/mode/interfaces/validators/mods/urlValidation.js +189 -0
  217. package/dist/esm/core/schema/mode/interfaces/validators/mods/urlValidation.js.map +1 -0
  218. package/dist/esm/core/schema/optimization/ObjectValidationCache.js +460 -0
  219. package/dist/esm/core/schema/optimization/ObjectValidationCache.js.map +1 -0
  220. package/dist/esm/core/schema/optimization/PerformanceMonitor.js +771 -0
  221. package/dist/esm/core/schema/optimization/PerformanceMonitor.js.map +1 -0
  222. package/dist/esm/core/schema/optimization/SchemaCompiler.js +598 -0
  223. package/dist/esm/core/schema/optimization/SchemaCompiler.js.map +1 -0
  224. package/dist/esm/core/types/ValidatorTypes.js +65 -0
  225. package/dist/esm/core/types/ValidatorTypes.js.map +1 -0
  226. package/dist/esm/core/types/parser.type.js +12 -0
  227. package/dist/esm/core/types/parser.type.js.map +1 -0
  228. package/dist/esm/core/utils/Make.js +59 -0
  229. package/dist/esm/core/utils/Make.js.map +1 -0
  230. package/dist/esm/core/utils/Mod.js +1031 -0
  231. package/dist/esm/core/utils/Mod.js.map +1 -0
  232. package/dist/esm/core/utils/UrlArgs.js +98 -0
  233. package/dist/esm/core/utils/UrlArgs.js.map +1 -0
  234. package/dist/esm/core/utils/arrayToEnum.js +16 -0
  235. package/dist/esm/core/utils/arrayToEnum.js.map +1 -0
  236. package/dist/esm/core/utils/createUrlArgsEnumFArray.js +11 -0
  237. package/dist/esm/core/utils/createUrlArgsEnumFArray.js.map +1 -0
  238. package/dist/esm/core/utils/securityHelpers.js +207 -0
  239. package/dist/esm/core/utils/securityHelpers.js.map +1 -0
  240. package/dist/esm/core/utils/securityValidatorHelpers.js +62 -0
  241. package/dist/esm/core/utils/securityValidatorHelpers.js.map +1 -0
  242. package/dist/esm/index.js +12 -0
  243. package/dist/esm/index.js.map +1 -0
  244. package/dist/esm/package.json +3 -0
  245. package/dist/schema.d.ts +2595 -0
  246. package/docs/ALL_TYPES.md +120 -0
  247. package/docs/API-STABILITY.md +336 -0
  248. package/docs/CONDITIONAL-VALIDATION.md +637 -0
  249. package/docs/EXAMPLES.md +876 -0
  250. package/docs/FIELD-TYPES.md +829 -0
  251. package/docs/GETTING-STARTED.md +394 -0
  252. package/docs/LIVE-UTILITY.md +1137 -0
  253. package/docs/QUICK-REFERENCE.md +346 -0
  254. package/docs/README.md +205 -0
  255. package/docs/VSCODE-EXTENSION.md +458 -0
  256. package/package.json +219 -0
  257. package/src/bench/BENCHMARK-RESULTS.md +211 -0
  258. package/src/bench/benchmark-results.json +148 -0
  259. package/src/bench/performance-comparison.ts +218 -0
  260. package/src/bench/precompilation-benchmark.ts +218 -0
  261. package/src/constants/SECURITY_CONSTANTS.ts +44 -0
  262. package/src/constants/VALIDATION_CONSTANTS.ts +176 -0
  263. package/src/core/README.md +395 -0
  264. package/src/core/compiler/SchemaTransformer.ts +279 -0
  265. package/src/core/compiler/TypeAnalyzer.ts +378 -0
  266. package/src/core/compiler/TypeScriptCompilerIntegration.ts +220 -0
  267. package/src/core/compiler/TypeToSchemaConverter.ts +288 -0
  268. package/src/core/index.ts +70 -0
  269. package/src/core/schema/extensions/AutoDocumentation.ts +572 -0
  270. package/src/core/schema/extensions/ConditionalValidation.ts +330 -0
  271. package/src/core/schema/extensions/README.md +171 -0
  272. package/src/core/schema/extensions/RealtimeValidation.ts +656 -0
  273. package/src/core/schema/extensions/SmartInference.ts +224 -0
  274. package/src/core/schema/extensions/components/AutoDocumentation/Docs.ts +98 -0
  275. package/src/core/schema/extensions/components/AutoDocumentation/DocumentationGenerator.ts +201 -0
  276. package/src/core/schema/extensions/components/AutoDocumentation/InteractiveDocumentationGenerator.ts +176 -0
  277. package/src/core/schema/extensions/components/AutoDocumentation/OpenAPIGenerator.ts +175 -0
  278. package/src/core/schema/extensions/components/AutoDocumentation/SchemaAnalyzer.ts +49 -0
  279. package/src/core/schema/extensions/components/AutoDocumentation/TypeScriptGenerator.ts +54 -0
  280. package/src/core/schema/extensions/components/AutoDocumentation/index.ts +17 -0
  281. package/src/core/schema/extensions/components/ConditionalValidation/ConditionalBuilder.ts +101 -0
  282. package/src/core/schema/extensions/components/ConditionalValidation/ConditionalElse.ts +65 -0
  283. package/src/core/schema/extensions/components/ConditionalValidation/ConditionalThen.ts +33 -0
  284. package/src/core/schema/extensions/components/ConditionalValidation/Extend.ts +75 -0
  285. package/src/core/schema/extensions/components/ConditionalValidation/MultiConditionalBuilder.ts +16 -0
  286. package/src/core/schema/extensions/components/ConditionalValidation/MultiConditionalThen.ts +50 -0
  287. package/src/core/schema/extensions/components/ConditionalValidation/index.ts +104 -0
  288. package/src/core/schema/extensions/components/RealtimeValidation/FormValidator.ts +88 -0
  289. package/src/core/schema/extensions/components/RealtimeValidation/LiveValidator.ts +171 -0
  290. package/src/core/schema/extensions/components/RealtimeValidation/StreamValidator.ts +397 -0
  291. package/src/core/schema/extensions/components/RealtimeValidation/index.ts +114 -0
  292. package/src/core/schema/extensions/index.ts +76 -0
  293. package/src/core/schema/extensions/mods/index.ts +131 -0
  294. package/src/core/schema/extensions/mods/openapi-converter.ts +338 -0
  295. package/src/core/schema/extensions/mods/typescript-generator.ts +379 -0
  296. package/src/core/schema/extensions/mods/validation-engine.ts +295 -0
  297. package/src/core/schema/mode/interfaces/Interface.ts +364 -0
  298. package/src/core/schema/mode/interfaces/InterfaceSchema.ts +1838 -0
  299. package/src/core/schema/mode/interfaces/README.md +278 -0
  300. package/src/core/schema/mode/interfaces/conditional/evaluator/ConditionalEvaluator.ts +657 -0
  301. package/src/core/schema/mode/interfaces/conditional/parser/ConditionalAST.ts +826 -0
  302. package/src/core/schema/mode/interfaces/conditional/parser/ConditionalLexer.ts +992 -0
  303. package/src/core/schema/mode/interfaces/conditional/parser/ConditionalParser.ts +803 -0
  304. package/src/core/schema/mode/interfaces/conditional/parser/readme.md +406 -0
  305. package/src/core/schema/mode/interfaces/conditional/types/ConditionalTypes.ts +273 -0
  306. package/src/core/schema/mode/interfaces/errors/ErrorHandler.ts +624 -0
  307. package/src/core/schema/mode/interfaces/errors/types/errors.type.ts +102 -0
  308. package/src/core/schema/mode/interfaces/precompilation/FieldPrecompilers.ts +962 -0
  309. package/src/core/schema/mode/interfaces/precompilation/SchemaPrecompiler.ts +667 -0
  310. package/src/core/schema/mode/interfaces/typescript/ConditionalTypes.ts +1534 -0
  311. package/src/core/schema/mode/interfaces/typescript/IDESupport.ts +534 -0
  312. package/src/core/schema/mode/interfaces/typescript/TypeInference.ts +737 -0
  313. package/src/core/schema/mode/interfaces/typescript/index.ts +92 -0
  314. package/src/core/schema/mode/interfaces/validators/ConstraintParser.ts +1438 -0
  315. package/src/core/schema/mode/interfaces/validators/EnhancedErrorReporting.ts +227 -0
  316. package/src/core/schema/mode/interfaces/validators/TypeGuards.ts +288 -0
  317. package/src/core/schema/mode/interfaces/validators/TypeValidators.ts +660 -0
  318. package/src/core/schema/mode/interfaces/validators/UnionCache.ts +508 -0
  319. package/src/core/schema/mode/interfaces/validators/ValidationHelpers.ts +1257 -0
  320. package/src/core/schema/mode/interfaces/validators/index.ts +21 -0
  321. package/src/core/schema/mode/interfaces/validators/mods/passValidator.ts +424 -0
  322. package/src/core/schema/mode/interfaces/validators/mods/securityValidator.ts +1634 -0
  323. package/src/core/schema/mode/interfaces/validators/mods/urlValidation.ts +333 -0
  324. package/src/core/schema/optimization/ObjectValidationCache.ts +560 -0
  325. package/src/core/schema/optimization/PerformanceInitializer.ts +188 -0
  326. package/src/core/schema/optimization/PerformanceMonitor.ts +898 -0
  327. package/src/core/schema/optimization/SchemaCompiler.ts +730 -0
  328. package/src/core/testing/TestDataGenerator.ts +590 -0
  329. package/src/core/types/SchemaValidator.type.ts +210 -0
  330. package/src/core/types/ValidatorTypes.ts +93 -0
  331. package/src/core/types/extension.type.ts +109 -0
  332. package/src/core/types/objValidationCache.ts +17 -0
  333. package/src/core/types/parser.type.ts +15 -0
  334. package/src/core/types/perfoMonitor.ts +37 -0
  335. package/src/core/types/scompiler.ts +22 -0
  336. package/src/core/types/securityValidator.type.ts +10 -0
  337. package/src/core/types/types.ts +154 -0
  338. package/src/core/utils/Make.ts +97 -0
  339. package/src/core/utils/Mod.ts +1168 -0
  340. package/src/core/utils/UrlArgs.ts +124 -0
  341. package/src/core/utils/arrayToEnum.ts +89 -0
  342. package/src/core/utils/createUrlArgsEnumFArray.ts +11 -0
  343. package/src/core/utils/securityHelpers.ts +341 -0
  344. package/src/core/utils/securityValidatorHelpers.ts +76 -0
  345. package/src/index.ts +124 -0
@@ -0,0 +1,624 @@
1
+ /**
2
+ * Centralized Error Handler Module
3
+ *
4
+ * Provides a unified system for creating, formatting, and managing validation errors.
5
+ * This makes error handling consistent across the codebase and easier to modify in the future.
6
+ */
7
+
8
+ import { ValidationError } from "../../../../types/types";
9
+ import { ErrorCode, ErrorConfig } from "./types/errors.type";
10
+
11
+ /**
12
+ * Centralized error handler class with enhanced functionality
13
+ */
14
+ export class ErrorHandler {
15
+ private static readonly DEFAULT_CONFIG: ErrorConfig = {
16
+ includeReceivedValue: true,
17
+ maxPathDepth: 10,
18
+ maxMessageLength: 500,
19
+ };
20
+
21
+ private static readonly TYPE_MAPPING = new Map([
22
+ ["object", "Object"],
23
+ ["array", "Array"],
24
+ ["string", "String"],
25
+ ["number", "Number"],
26
+ ["boolean", "Boolean"],
27
+ ["function", "Function"],
28
+ ["symbol", "Symbol"],
29
+ ["bigint", "BigInt"],
30
+ ["null", "null"],
31
+ ["undefined", "undefined"],
32
+ ]);
33
+
34
+ /**
35
+ * Normalize and validate path input
36
+ */
37
+ private static normalizePath(path: string | string[]): string[] {
38
+ if (typeof path === "string") {
39
+ return path
40
+ .split(".")
41
+ .filter((segment) => segment.length > 0)
42
+ .slice(0, this.DEFAULT_CONFIG.maxPathDepth);
43
+ }
44
+
45
+ if (Array.isArray(path)) {
46
+ return path
47
+ .filter((segment) => typeof segment === "string" && segment.length > 0)
48
+ .slice(0, this.DEFAULT_CONFIG.maxPathDepth);
49
+ }
50
+
51
+ return [];
52
+ }
53
+
54
+ /**
55
+ * Sanitize and truncate message content
56
+ */
57
+ private static sanitizeMessage(message: string): string {
58
+ if (typeof message !== "string") {
59
+ message = String(message);
60
+ }
61
+
62
+ // Remove potentially harmful characters and excessive whitespace
63
+ const sanitized = message
64
+ .replace(/[\x00-\x1F\x7F]/g, "") // Remove control characters
65
+ .replace(/\s+/g, " ") // Normalize whitespace
66
+ .trim();
67
+
68
+ // Truncate if too long
69
+ return sanitized.length > this.DEFAULT_CONFIG.maxMessageLength
70
+ ? sanitized.substring(0, this.DEFAULT_CONFIG.maxMessageLength - 3) + "..."
71
+ : sanitized;
72
+ }
73
+
74
+ /**
75
+ * Enhanced value type detection with better precision
76
+ */
77
+ private static detectValueType(value: unknown): string {
78
+ // Handle primitive null/undefined first
79
+ if (value === null) return "null";
80
+ if (value === undefined) return "undefined";
81
+
82
+ // Handle built-in objects with instanceof checks
83
+ const builtInChecks = [
84
+ [Array, "array"],
85
+ [Date, "date"],
86
+ [RegExp, "regexp"],
87
+ [Error, "error"],
88
+ [Map, "map"],
89
+ [Set, "set"],
90
+ [WeakMap, "weakmap"],
91
+ [WeakSet, "weakset"],
92
+ [Promise, "promise"],
93
+ ] as const;
94
+
95
+ for (const [constructor, typeName] of builtInChecks) {
96
+ if (value instanceof constructor) {
97
+ return typeName;
98
+ }
99
+ }
100
+
101
+ // Handle primitives and functions
102
+ const primitiveType = typeof value;
103
+ return this.TYPE_MAPPING.get(primitiveType) || primitiveType;
104
+ }
105
+
106
+ /**
107
+ * Create a validation error object with standardized format
108
+ */
109
+ static createError(
110
+ path: string | string[],
111
+ message: string,
112
+ code: ErrorCode | string,
113
+ expected: string,
114
+ received: any,
115
+ context?: {
116
+ suggestion?: string;
117
+ allowedValues?: any[];
118
+ constraints?: Record<string, any>;
119
+ }
120
+ ): ValidationError {
121
+ const normalizedPath = this.normalizePath(path);
122
+ const sanitizedMessage = this.sanitizeMessage(message);
123
+ const detectedType = this.detectValueType(received);
124
+
125
+ return {
126
+ path: normalizedPath,
127
+ message: sanitizedMessage,
128
+ code: code,
129
+ expected: typeof expected === "string" ? expected.trim() : "unknown",
130
+ received,
131
+ receivedType: detectedType,
132
+ context: context ? { ...context } : undefined, // Shallow clone for safety
133
+ };
134
+ }
135
+
136
+ /**
137
+ * Create a type error (when value is of wrong type)
138
+ */
139
+ static createTypeError(
140
+ path: string | string[],
141
+ expected: string,
142
+ received: unknown
143
+ ): ValidationError {
144
+ const receivedType = this.detectValueType(received);
145
+ const sanitizedValue = this.sanitizeReceivedValue(received);
146
+
147
+ // Create a user-friendly message that includes the actual value
148
+ const message =
149
+ expected === "phone"
150
+ ? `Invalid phone number format: received "${sanitizedValue}" instead of valid phone number`
151
+ : `Expected ${this.capitalizeFirstLetter(expected)}, but received ${this.capitalizeFirstLetter(receivedType)}: "${sanitizedValue}"`;
152
+
153
+ return this.createError(
154
+ path,
155
+ message,
156
+ ErrorCode.TYPE_ERROR,
157
+ expected,
158
+ received
159
+ );
160
+ }
161
+
162
+ /**
163
+ * Create a string validation error
164
+ */
165
+ static createStringError(
166
+ path: string | string[],
167
+ constraint: string,
168
+ received: any,
169
+ code: ErrorCode = ErrorCode.INVALID_STRING_FORMAT
170
+ ): ValidationError {
171
+ const sanitizedConstraint =
172
+ typeof constraint === "string" ? constraint.trim() : "validation failed";
173
+
174
+ return this.createError(
175
+ path,
176
+ `String ${sanitizedConstraint}`,
177
+ code,
178
+ `string ${sanitizedConstraint}`,
179
+ received
180
+ );
181
+ }
182
+
183
+ /**
184
+ * Create a number validation error
185
+ */
186
+ static createNumberError(
187
+ path: string | string[],
188
+ constraint: string,
189
+ received: any,
190
+ code: ErrorCode = ErrorCode.INVALID_TYPE
191
+ ): ValidationError {
192
+ const sanitizedConstraint =
193
+ typeof constraint === "string" ? constraint.trim() : "validation failed";
194
+
195
+ return this.createError(
196
+ path,
197
+ `Number ${sanitizedConstraint}`,
198
+ code,
199
+ `number ${sanitizedConstraint}`,
200
+ received
201
+ );
202
+ }
203
+
204
+ /**
205
+ * Create an array validation error
206
+ */
207
+ static createArrayError(
208
+ path: string | string[],
209
+ constraint: string,
210
+ received: any,
211
+ code: ErrorCode = ErrorCode.INVALID_TYPE
212
+ ): ValidationError {
213
+ const sanitizedConstraint =
214
+ typeof constraint === "string" ? constraint.trim() : "validation failed";
215
+
216
+ return this.createError(
217
+ path,
218
+ `Array ${sanitizedConstraint}`,
219
+ code,
220
+ `array ${sanitizedConstraint}`,
221
+ received
222
+ );
223
+ }
224
+
225
+ /**
226
+ * Create a URL validation error
227
+ */
228
+ static createUrlError(
229
+ path: string | string[],
230
+ received: any,
231
+ urlType?: string
232
+ ): ValidationError {
233
+ const sanitizedUrlType = urlType?.trim();
234
+ const expected = sanitizedUrlType ? `url.${sanitizedUrlType}` : "url";
235
+ const message = sanitizedUrlType
236
+ ? `Invalid URL format for ${sanitizedUrlType}`
237
+ : "Invalid URL format";
238
+
239
+ return this.createError(
240
+ path,
241
+ message,
242
+ ErrorCode.INVALID_URL,
243
+ expected,
244
+ received
245
+ );
246
+ }
247
+
248
+ /**
249
+ * Create an email validation error
250
+ */
251
+ static createEmailError(
252
+ path: string | string[],
253
+ received: any,
254
+ details?: string
255
+ ): ValidationError {
256
+ const sanitizedDetails = details?.trim();
257
+ const message = sanitizedDetails
258
+ ? `Invalid email format: ${sanitizedDetails}`
259
+ : "Invalid email format";
260
+
261
+ return this.createError(
262
+ path,
263
+ message,
264
+ ErrorCode.INVALID_EMAIL,
265
+ "email",
266
+ received
267
+ );
268
+ }
269
+
270
+ /**
271
+ * Create a union validation error
272
+ */
273
+ static createUnionError(
274
+ path: string | string[],
275
+ allowedValues: any[],
276
+ received: any
277
+ ): ValidationError {
278
+ const safeAllowedValues = Array.isArray(allowedValues) ? allowedValues : [];
279
+ const expected = safeAllowedValues
280
+ .map((val) => (typeof val === "string" ? val : String(val)))
281
+ .join(" | ");
282
+
283
+ return this.createError(
284
+ path,
285
+ `Expected one of: ${expected}`,
286
+ ErrorCode.INVALID_UNION,
287
+ expected,
288
+ received,
289
+ { allowedValues: safeAllowedValues }
290
+ );
291
+ }
292
+
293
+ /**
294
+ * Get detailed type information for values (legacy method name for compatibility)
295
+ */
296
+ static getValueType(value: unknown): string {
297
+ return this.detectValueType(value);
298
+ }
299
+
300
+ /**
301
+ * Convert string errors to ValidationError objects
302
+ * (for backward compatibility)
303
+ */
304
+ static convertStringToError(
305
+ error: string | any,
306
+ code: ErrorCode
307
+ ): ValidationError {
308
+ // If it's already a ValidationError object, return as is
309
+ if (this.isValidationError(error)) {
310
+ return error;
311
+ }
312
+ // console.log("converting string to error. Code: ", code);
313
+ // Handle ValidationError-like objects
314
+ if (
315
+ error &&
316
+ typeof error === "object" &&
317
+ typeof error.message === "string"
318
+ ) {
319
+ return this.createError(
320
+ error.path || [],
321
+ error.message,
322
+ code || ErrorCode.VALIDATION_ERROR,
323
+ error.expected || "unknown",
324
+ error.received
325
+ );
326
+ }
327
+
328
+ // Convert to string safely
329
+ const errorString = this.extractErrorMessage(error);
330
+
331
+ // Extract path if it exists (format: "path: message")
332
+ const pathMatch = errorString.match(/^([^:]+):\s*(.+)$/);
333
+
334
+ if (pathMatch) {
335
+ const [, path, message] = pathMatch;
336
+ return this.createError(
337
+ path.trim(),
338
+ message.trim(),
339
+ code,
340
+ "unknown",
341
+ undefined
342
+ );
343
+ }
344
+
345
+ // No path found, use generic error
346
+ return this.createError([], errorString, code, "unknown", undefined);
347
+ }
348
+
349
+ /**
350
+ * Check if an object is a valid ValidationError
351
+ */
352
+ private static isValidationError(obj: any): obj is ValidationError {
353
+ return (
354
+ obj &&
355
+ typeof obj === "object" &&
356
+ Array.isArray(obj.path) &&
357
+ typeof obj.message === "string" &&
358
+ typeof obj.code === "string"
359
+ );
360
+ }
361
+
362
+ /**
363
+ * Safely extract error message from various error types
364
+ */
365
+ private static extractErrorMessage(error: any): string {
366
+ if (typeof error === "string") {
367
+ return error;
368
+ }
369
+
370
+ if (error && typeof error === "object") {
371
+ if (error.message) {
372
+ return String(error.message);
373
+ }
374
+
375
+ if (error.toString && error.toString !== Object.prototype.toString) {
376
+ return error.toString();
377
+ }
378
+
379
+ try {
380
+ return JSON.stringify(error);
381
+ } catch {
382
+ return "[Object]";
383
+ }
384
+ }
385
+
386
+ return String(error);
387
+ }
388
+
389
+ /**
390
+ * Convert string array to ValidationError array
391
+ * (for backward compatibility)
392
+ */
393
+ static convertStringArrayToErrors(
394
+ errors: string[],
395
+ code: string
396
+ ): ValidationError[] {
397
+ if (!Array.isArray(errors)) {
398
+ return [];
399
+ }
400
+ return errors.map((error) => this.convertStringToError(error, code as any));
401
+ }
402
+
403
+ /**
404
+ * Create a simple validation error with minimal information
405
+ */
406
+ static createSimpleError(
407
+ message: string,
408
+ path: string | string[] = [],
409
+ code: ErrorCode | string = ErrorCode.VALIDATION_ERROR
410
+ ): ValidationError {
411
+ return this.createError(path, message, code, "valid value", undefined);
412
+ }
413
+
414
+ /**
415
+ * Create an error for missing required fields
416
+ */
417
+ static createMissingFieldError(
418
+ path: string | string[],
419
+ fieldName: string
420
+ ): ValidationError {
421
+ const sanitizedFieldName =
422
+ typeof fieldName === "string" ? fieldName.trim() : "unknown";
423
+
424
+ return this.createError(
425
+ path,
426
+ `Missing required field: ${sanitizedFieldName}`,
427
+ ErrorCode.MISSING_REQUIRED_FIELD,
428
+ `required field: ${sanitizedFieldName}`,
429
+ undefined
430
+ );
431
+ }
432
+
433
+ /**
434
+ * create constant error
435
+ */
436
+ static createConstantError(
437
+ path: string | string[],
438
+ expected: string | number | boolean,
439
+ received: any,
440
+ constantValue: any
441
+ ): ValidationError {
442
+ const safeConstantValue =
443
+ constantValue !== null && constantValue !== undefined
444
+ ? String(constantValue)
445
+ : "null";
446
+
447
+ return this.createError(
448
+ path,
449
+ `Expected constant value: ${safeConstantValue}, received ${String(received)}`,
450
+ ErrorCode.CONSTANT_ERROR,
451
+ `constant: ${safeConstantValue}`,
452
+ received
453
+ );
454
+ }
455
+
456
+ /**
457
+ * Create an error for unknown fields
458
+ */
459
+ static createUnknownFieldError(
460
+ path: string | string[],
461
+ fieldName: string
462
+ ): ValidationError {
463
+ const sanitizedFieldName =
464
+ typeof fieldName === "string" ? fieldName.trim() : "unknown";
465
+
466
+ return this.createError(
467
+ path,
468
+ `Unknown field: ${sanitizedFieldName}`,
469
+ ErrorCode.UNKNOWN_FIELD,
470
+ "known field",
471
+ fieldName
472
+ );
473
+ }
474
+
475
+ /**
476
+ * Create an error for invalid fields
477
+ */
478
+ static createInvalidFieldError(
479
+ path: string | string[],
480
+ fieldName: string,
481
+ expected: string,
482
+ received: any
483
+ ): ValidationError {
484
+ const sanitizedFieldName =
485
+ typeof fieldName === "string" ? fieldName.trim() : "unknown";
486
+
487
+ return this.createError(
488
+ path,
489
+ `Invalid field: ${sanitizedFieldName}`,
490
+ ErrorCode.INVALID_FIELD,
491
+ expected,
492
+ received
493
+ );
494
+ }
495
+
496
+ /**
497
+ * conditional error
498
+ */
499
+ static createConditionalError(
500
+ path: string | string[],
501
+ message: string,
502
+ received: any
503
+ ): ValidationError {
504
+ return this.createError(
505
+ path,
506
+ message,
507
+ ErrorCode.CONDITION_ERROR,
508
+ "condition met",
509
+ received
510
+ );
511
+ }
512
+
513
+ /**
514
+ * Create a syntax error
515
+ */
516
+ static createSyntaxError(
517
+ path: string | string[],
518
+ message: string,
519
+ received: any
520
+ ): ValidationError {
521
+ return this.createError(
522
+ path,
523
+ message,
524
+ ErrorCode.SYNTAX_ERROR,
525
+ "valid syntax",
526
+ received
527
+ );
528
+ }
529
+
530
+ /**
531
+ * password error
532
+ */
533
+ static createPasswordError(
534
+ path: string | string[],
535
+ message: string,
536
+ received: any
537
+ ): ValidationError {
538
+ return this.createError(
539
+ path,
540
+ message,
541
+ ErrorCode.INVALID_PASSWORD,
542
+ "strong password",
543
+ received
544
+ );
545
+ }
546
+
547
+ /**
548
+ * createDateError
549
+ */
550
+ static createDateError(
551
+ path: string | string[],
552
+ received: any
553
+ ): ValidationError {
554
+ return this.createError(
555
+ path,
556
+ "Invalid date format",
557
+ ErrorCode.INVALID_DATE,
558
+ "valid date format",
559
+ received
560
+ );
561
+ }
562
+
563
+ /**
564
+ * Validation error
565
+ */
566
+ static createValidationError(
567
+ path: string | string[],
568
+ message: string,
569
+ received: any
570
+ ): ValidationError {
571
+ // console.log("createValidationError", message);
572
+ return this.createError(
573
+ path,
574
+ `Validation failed: ${message}`,
575
+ ErrorCode.VALIDATION_ERROR,
576
+ "valid value",
577
+ received
578
+ );
579
+ }
580
+
581
+ /**
582
+ * Url components validation error
583
+ */
584
+ static createUrlCValidationErr(
585
+ path: string | string[],
586
+ message: string,
587
+ received: any
588
+ ): ValidationError {
589
+ return this.createError(
590
+ path,
591
+ message,
592
+ ErrorCode.INVALID_URL_ARGS,
593
+ "valid url components",
594
+ received
595
+ );
596
+ }
597
+
598
+ /**
599
+ * Safely capitalize first letter of a string
600
+ */
601
+ private static capitalizeFirstLetter(str: string): string {
602
+ if (typeof str !== "string" || str.length === 0) {
603
+ return str;
604
+ }
605
+ return str.charAt(0).toUpperCase() + str.slice(1);
606
+ }
607
+
608
+ /**
609
+ * Sanitize received value for safe display in error messages
610
+ */
611
+ private static sanitizeReceivedValue(value: any): string {
612
+ if (value === null) return "null";
613
+ if (value === undefined) return "undefined";
614
+ if (typeof value === "string") {
615
+ return value.length > 50
616
+ ? `"${value.substring(0, 47)}..."`
617
+ : `"${value}"`;
618
+ }
619
+ if (typeof value === "object") {
620
+ return `[${this.detectValueType(value)}]`;
621
+ }
622
+ return String(value);
623
+ }
624
+ }
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Error codes for different validation scenarios
3
+ */
4
+ /**
5
+ * Error codes for different validation scenarios
6
+ */
7
+ export enum ErrorCode {
8
+ // Type validation errors
9
+ TYPE_ERROR = "ETYPE",
10
+ TYPE_MISMATCH = "ETYPEMISMATCH",
11
+ INVALID_TYPE = "EINVALIDTYPE",
12
+
13
+ // String validation errors
14
+ STRING_TOO_SHORT = "ESTRINGSHORT",
15
+ STRING_TOO_LONG = "ESTRINGLONG",
16
+ INVALID_STRING_FORMAT = "ESTRINGFORMAT",
17
+ PATTERN_MISMATCH = "EPATTERNMISMATCH",
18
+
19
+ // Number validation errors
20
+ NUMBER_TOO_SMALL = "ENUMSMALL",
21
+ NUMBER_TOO_LARGE = "ENUMLARGE",
22
+ NOT_INTEGER = "ENOTINTEGER",
23
+ NOT_POSITIVE = "ENOTPOSITIVE",
24
+ NOT_NEGATIVE = "ENOTNEGATIVE",
25
+
26
+ // Array validation errors
27
+ ARRAY_TOO_SHORT = "EARRAYSHORT",
28
+ ARRAY_TOO_LONG = "EARRAYLONG",
29
+ INVALID_ARRAY_ITEM = "EARRAYITEM",
30
+ INVALID_ARRAY_LENGTH = "EARRAYLENGTH",
31
+ DUPLICATE_ARRAY_ITEM = "EARRDUPLICATE",
32
+ ARRAY_VALUES_NOT_UNIQUE = "EARRAYNOTUNIQUE",
33
+
34
+ // Object validation errors
35
+ MISSING_REQUIRED_FIELD = "EMISSINGFIELD",
36
+ INVALID_FIELD = "EINVALIDFIELD",
37
+ UNKNOWN_FIELD = "EUNKNOWNFIELD",
38
+
39
+ // Conditional validation errors
40
+ CONDITION_ERROR = "ECONDITION",
41
+ SYNTAX_ERROR = "ESYNTAX",
42
+
43
+ // URL validation errors
44
+ INVALID_URL = "EINVALIDURL",
45
+ INVALID_URL_ARGUMENT = "EINVALIDURLARG",
46
+
47
+ // Email validation errors
48
+ INVALID_EMAIL = "EINVALIDEMAIL",
49
+
50
+ // Date validation errors
51
+ INVALID_DATE = "EINVALIDDATE",
52
+ DATE_TOO_EARLY = "EDATEEARLY",
53
+ DATE_TOO_LATE = "EDATELATE",
54
+
55
+ // Union validation errors
56
+ INVALID_UNION = "EINVALIDUNION",
57
+
58
+ // Constant validation errors
59
+ CONSTANT_ERROR = "ECONSTANT",
60
+
61
+ // Password validation errors
62
+ INVALID_PASSWORD = "EPWDVIOLATION",
63
+
64
+ // JSON validation errors
65
+ INVALID_JSON = "EINVALIDJSON",
66
+
67
+ // Security errors
68
+ SECURITY_VIOLATION = "ESECVIOLATION",
69
+
70
+ // URL components validation errors
71
+ INVALID_URL_ARGS = "EINVALIDURLARGS",
72
+
73
+ // Network and connection errors
74
+ CONNECTION_REFUSED = "ECONNREFUSED",
75
+ CONNECTION_TIMEOUT = "ECONNECTIONTIMEOUT",
76
+ CONNECTION_RESET = "ECONNRESET",
77
+ NETWORK_UNREACHABLE = "ENETUNREACH",
78
+ HOST_UNREACHABLE = "EHOSTUNREACH",
79
+ ADDRESS_NOT_AVAILABLE = "EADDRNOTAVAIL",
80
+
81
+ // HTTP errors
82
+ HTTP_ERROR = "EHTTPERROR",
83
+ REQUEST_TIMEOUT = "EREQUESTTIMEOUT",
84
+ BAD_REQUEST = "EBADREQUEST",
85
+ UNAUTHORIZED = "EUNAUTHORIZED",
86
+ FORBIDDEN = "EFORBIDDEN",
87
+ NOT_FOUND = "ENOTFOUND",
88
+ INTERNAL_SERVER_ERROR = "ESERVERERROR",
89
+
90
+ // Generic errors
91
+ VALIDATION_ERROR = "EVALIDATION",
92
+ UNKNOWN_ERROR = "EUNKNOWN",
93
+ }
94
+
95
+ /**
96
+ * Configuration for error message templates and formatting
97
+ */
98
+ export interface ErrorConfig {
99
+ includeReceivedValue: boolean;
100
+ maxPathDepth: number;
101
+ maxMessageLength: number;
102
+ }