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,1031 @@
1
+ import { InterfaceSchema } from '../schema/mode/interfaces/InterfaceSchema.js';
2
+
3
+ /**
4
+ * Enhanced schema modification utilities - transform, combine, and manipulate schemas
5
+ */
6
+ class Mod {
7
+ /**
8
+ * Safely access schema internals with proper typing
9
+ */
10
+ static getSchemaInternals(schema) {
11
+ return {
12
+ definition: schema
13
+ .definition,
14
+ options: schema.options || {},
15
+ };
16
+ }
17
+ /**
18
+ * Merge multiple schemas into a single schema
19
+ * @example
20
+ * ```typescript
21
+ * const UserSchema = Interface({ id: "number", name: "string" });
22
+ * const ProfileSchema = Interface({ bio: "string?", avatar: "url?" });
23
+ *
24
+ * const MergedSchema = Mod.merge(UserSchema, ProfileSchema);
25
+ * // Result: { id: number, name: string, bio?: string, avatar?: string }
26
+ * ```
27
+ */
28
+ static merge(schema1, schema2) {
29
+ const { definition: def1 } = this.getSchemaInternals(schema1);
30
+ const { definition: def2 } = this.getSchemaInternals(schema2);
31
+ const mergedDefinition = {
32
+ ...def1,
33
+ ...def2,
34
+ };
35
+ const { options: options1 } = this.getSchemaInternals(schema1);
36
+ const { options: options2 } = this.getSchemaInternals(schema2);
37
+ const mergedOptions = { ...options1, ...options2 };
38
+ return new InterfaceSchema(mergedDefinition, mergedOptions);
39
+ }
40
+ /**
41
+ * Merge multiple schemas with conflict resolution
42
+ * @example
43
+ * ```typescript
44
+ * const schema1 = Interface({ id: "number", name: "string" });
45
+ * const schema2 = Interface({ id: "uuid", email: "email" });
46
+ *
47
+ * const merged = Mod.mergeDeep(schema1, schema2, "second"); // id becomes "uuid"
48
+ * ```
49
+ */
50
+ static mergeDeep(schema1, schema2, strategy = "second") {
51
+ const def1 = schema1.definition;
52
+ const def2 = schema2.definition;
53
+ const mergedDefinition = { ...def1 };
54
+ for (const [key, value] of Object.entries(def2)) {
55
+ if (key in mergedDefinition) {
56
+ switch (strategy) {
57
+ case "first":
58
+ // Keep first schema's value
59
+ break;
60
+ case "second":
61
+ mergedDefinition[key] = value;
62
+ break;
63
+ case "merge":
64
+ // Attempt to merge if both are objects
65
+ if (typeof mergedDefinition[key] === "object" &&
66
+ typeof value === "object") {
67
+ mergedDefinition[key] = { ...mergedDefinition[key], ...value };
68
+ }
69
+ else {
70
+ mergedDefinition[key] = value;
71
+ }
72
+ break;
73
+ }
74
+ }
75
+ else {
76
+ mergedDefinition[key] = value;
77
+ }
78
+ }
79
+ const options1 = schema1.options || {};
80
+ const options2 = schema2.options || {};
81
+ const mergedOptions = { ...options1, ...options2 };
82
+ return new InterfaceSchema(mergedDefinition, mergedOptions);
83
+ }
84
+ /**
85
+ * Pick specific fields from a schema
86
+ */
87
+ static pick(schema, keys) {
88
+ const { definition, options } = this.getSchemaInternals(schema);
89
+ const pickedDefinition = {};
90
+ for (const key of keys) {
91
+ const keyStr = key;
92
+ if (keyStr in definition) {
93
+ pickedDefinition[keyStr] = definition[keyStr];
94
+ }
95
+ }
96
+ return new InterfaceSchema(pickedDefinition, options);
97
+ }
98
+ /**
99
+ * Omit specific fields from a schema
100
+ */
101
+ static omit(schema, keys) {
102
+ const { definition, options } = this.getSchemaInternals(schema);
103
+ const omittedDefinition = { ...definition };
104
+ for (const key of keys) {
105
+ const keyStr = key;
106
+ delete omittedDefinition[keyStr];
107
+ }
108
+ const newOptions = {
109
+ ...options,
110
+ _omittedFields: [
111
+ ...(options._omittedFields || []),
112
+ ...keys.map((k) => k),
113
+ ],
114
+ };
115
+ return new InterfaceSchema(omittedDefinition, newOptions);
116
+ }
117
+ /**
118
+ * Make all fields in a schema optional
119
+ */
120
+ static partial(schema) {
121
+ const definition = schema.definition;
122
+ const options = schema.options || {};
123
+ const partialDefinition = {};
124
+ for (const [key, value] of Object.entries(definition)) {
125
+ if (typeof value === "string" && !value.endsWith("?")) {
126
+ partialDefinition[key] = value + "?";
127
+ }
128
+ else {
129
+ partialDefinition[key] = value;
130
+ }
131
+ }
132
+ return new InterfaceSchema(partialDefinition, options);
133
+ }
134
+ /**
135
+ * Make all fields in a schema required
136
+ */
137
+ static required(schema) {
138
+ const definition = schema.definition;
139
+ const options = schema.options || {};
140
+ const requiredDefinition = {};
141
+ for (const [key, value] of Object.entries(definition)) {
142
+ if (typeof value === "string" && value.endsWith("?")) {
143
+ requiredDefinition[key] = value.slice(0, -1);
144
+ }
145
+ else {
146
+ requiredDefinition[key] = value;
147
+ }
148
+ }
149
+ return new InterfaceSchema(requiredDefinition, options);
150
+ }
151
+ /**
152
+ * Make specific fields optional in a schema without modifying field types
153
+ *
154
+ * This method allows you to selectively make certain fields optional while keeping
155
+ * all other fields required. It's particularly useful when you want to create
156
+ * flexible versions of strict schemas for different use cases (e.g., partial updates,
157
+ * form validation, API endpoints with optional parameters).
158
+ *
159
+ * The method works with both primitive types and nested objects, properly handling
160
+ * the optional nature at the validation level while maintaining type safety.
161
+ *
162
+ * @param schema - The source schema to modify
163
+ * @param keys - Array of field names to make optional
164
+ * @returns A new schema with specified fields made optional
165
+ *
166
+ * @example Making primitive fields optional
167
+ * ```typescript
168
+ * const UserSchema = Interface({
169
+ * id: "number",
170
+ * name: "string",
171
+ * email: "email",
172
+ * phone: "string"
173
+ * });
174
+ *
175
+ * const FlexibleUserSchema = Mod.makeOptional(UserSchema, ["email", "phone"]);
176
+ *
177
+ * // Now accepts both:
178
+ * FlexibleUserSchema.parse({ id: 1, name: "John" }); // ✅ email and phone optional
179
+ * FlexibleUserSchema.parse({ id: 1, name: "John", email: "john@example.com" }); // ✅
180
+ * ```
181
+ *
182
+ * @example Making nested objects optional
183
+ * ```typescript
184
+ * const ProfileSchema = Interface({
185
+ * id: "number",
186
+ * name: "string",
187
+ * preferences: {
188
+ * theme: "light|dark",
189
+ * notifications: "boolean",
190
+ * language: "en|es|fr"
191
+ * },
192
+ * settings: {
193
+ * privacy: "public|private",
194
+ * newsletter: "boolean"
195
+ * }
196
+ * });
197
+ *
198
+ * const FlexibleProfileSchema = Mod.makeOptional(ProfileSchema, ["preferences", "settings"]);
199
+ *
200
+ * // Now accepts:
201
+ * FlexibleProfileSchema.parse({ id: 1, name: "John" }); // ✅ nested objects optional
202
+ * FlexibleProfileSchema.parse({
203
+ * id: 1,
204
+ * name: "John",
205
+ * preferences: { theme: "dark", notifications: true, language: "en" }
206
+ * }); // ✅
207
+ * ```
208
+ *
209
+ * @example Use case: API endpoints with optional parameters
210
+ * ```typescript
211
+ * const CreateUserSchema = Interface({
212
+ * name: "string",
213
+ * email: "email",
214
+ * password: "string",
215
+ * role: "admin|user|moderator",
216
+ * department: "string",
217
+ * startDate: "date"
218
+ * });
219
+ *
220
+ * // For user registration (minimal required fields)
221
+ * const RegisterSchema = Mod.makeOptional(CreateUserSchema, ["role", "department", "startDate"]);
222
+ *
223
+ * // For admin creation (all fields required)
224
+ * const AdminCreateSchema = CreateUserSchema;
225
+ *
226
+ * // For profile updates (most fields optional)
227
+ * const UpdateProfileSchema = Mod.makeOptional(CreateUserSchema, ["password", "role", "department", "startDate"]);
228
+ * ```
229
+ */
230
+ static makeOptional(schema, keys) {
231
+ const { definition, options } = this.getSchemaInternals(schema);
232
+ // Create new definition with specified fields made optional
233
+ const newDefinition = { ...definition };
234
+ for (const key of keys) {
235
+ const keyStr = key;
236
+ if (keyStr in newDefinition) {
237
+ const fieldType = newDefinition[keyStr];
238
+ if (typeof fieldType === "string" && !fieldType.endsWith("?")) {
239
+ newDefinition[keyStr] = fieldType + "?";
240
+ }
241
+ else if (typeof fieldType === "object") {
242
+ // For nested objects, we need to wrap them in an optional schema interface
243
+ // This tells the validation system that the entire nested object is optional
244
+ newDefinition[keyStr] = {
245
+ schema: fieldType,
246
+ optional: true,
247
+ };
248
+ }
249
+ }
250
+ }
251
+ return new InterfaceSchema(newDefinition, options);
252
+ }
253
+ /**
254
+ * Extend a schema with additional fields
255
+ */
256
+ static extend(schema, extension) {
257
+ const definition = schema.definition;
258
+ const options = schema.options || {};
259
+ const extendedDefinition = {
260
+ ...definition,
261
+ ...extension,
262
+ };
263
+ return new InterfaceSchema(extendedDefinition, options);
264
+ }
265
+ /**
266
+ * Create a deep partial version of a schema (makes ALL fields optional recursively)
267
+ *
268
+ * Unlike the regular `partial()` method which only makes top-level fields optional,
269
+ * `deepPartial()` recursively traverses the entire schema structure and makes every
270
+ * field at every nesting level optional. This is particularly useful for update
271
+ * operations, patch APIs, or form validation where users might only provide
272
+ * partial data at any level of nesting.
273
+ *
274
+ * @param schema - The source schema to make deeply partial
275
+ * @returns A new schema where all fields at all levels are optional
276
+ *
277
+ * @example Basic deep partial transformation
278
+ * ```typescript
279
+ * const UserSchema = Interface({
280
+ * id: "number",
281
+ * name: "string",
282
+ * profile: {
283
+ * bio: "string",
284
+ * avatar: "string",
285
+ * social: {
286
+ * twitter: "string",
287
+ * linkedin: "string"
288
+ * }
289
+ * }
290
+ * });
291
+ *
292
+ * const DeepPartialSchema = Mod.deepPartial(UserSchema);
293
+ *
294
+ * // All of these are now valid:
295
+ * DeepPartialSchema.parse({}); // ✅ Everything optional
296
+ * DeepPartialSchema.parse({ id: 1 }); // ✅ Only id provided
297
+ * DeepPartialSchema.parse({
298
+ * profile: {
299
+ * bio: "Developer"
300
+ * }
301
+ * }); // ✅ Partial nested data
302
+ * DeepPartialSchema.parse({
303
+ * profile: {
304
+ * social: {
305
+ * twitter: "@john"
306
+ * }
307
+ * }
308
+ * }); // ✅ Deep nested partial data
309
+ * ```
310
+ *
311
+ * @example Use case: API PATCH endpoints
312
+ * ```typescript
313
+ * const ArticleSchema = Interface({
314
+ * id: "number",
315
+ * title: "string",
316
+ * content: "string",
317
+ * metadata: {
318
+ * tags: "string[]",
319
+ * category: "string",
320
+ * seo: {
321
+ * title: "string",
322
+ * description: "string",
323
+ * keywords: "string[]"
324
+ * }
325
+ * },
326
+ * author: {
327
+ * id: "number",
328
+ * name: "string"
329
+ * }
330
+ * });
331
+ *
332
+ * // For PATCH /articles/:id - allow partial updates at any level
333
+ * const PatchArticleSchema = Mod.deepPartial(ArticleSchema);
334
+ *
335
+ * // Users can update just the SEO title:
336
+ * PatchArticleSchema.parse({
337
+ * metadata: {
338
+ * seo: {
339
+ * title: "New SEO Title"
340
+ * }
341
+ * }
342
+ * }); // ✅
343
+ * ```
344
+ *
345
+ * @example Difference from regular partial()
346
+ * ```typescript
347
+ * const NestedSchema = Interface({
348
+ * user: {
349
+ * name: "string",
350
+ * email: "email"
351
+ * }
352
+ * });
353
+ *
354
+ * const RegularPartial = Mod.partial(NestedSchema);
355
+ * // Type: { user?: { name: string, email: string } }
356
+ * // user is optional, but if provided, name and email are required
357
+ *
358
+ * const DeepPartial = Mod.deepPartial(NestedSchema);
359
+ * // Type: { user?: { name?: string, email?: string } }
360
+ * // user is optional, and if provided, name and email are also optional
361
+ * ```
362
+ */
363
+ static deepPartial(schema) {
364
+ const definition = schema.definition;
365
+ const options = schema.options || {};
366
+ const deepPartialDefinition = {};
367
+ for (const [key, value] of Object.entries(definition)) {
368
+ if (typeof value === "object" && value !== null) {
369
+ // Recursively make nested objects partial
370
+ const nestedSchema = new InterfaceSchema(value, {});
371
+ const partialNested = this.deepPartial(nestedSchema);
372
+ // Make the nested object field optional by wrapping it
373
+ deepPartialDefinition[key] = {
374
+ schema: partialNested.definition,
375
+ optional: true,
376
+ };
377
+ }
378
+ else if (typeof value === "string" && !value.endsWith("?")) {
379
+ deepPartialDefinition[key] = value + "?";
380
+ }
381
+ else {
382
+ deepPartialDefinition[key] = value;
383
+ }
384
+ }
385
+ return new InterfaceSchema(deepPartialDefinition, options);
386
+ }
387
+ /**
388
+ * Transform field types using a mapper function
389
+ * @example
390
+ * ```typescript
391
+ * const UserSchema = Interface({ id: "number", name: "string" });
392
+ * const StringifiedSchema = Mod.transform(UserSchema, (type) =>
393
+ * type.replace("number", "string")
394
+ * );
395
+ * // Result: { id: string, name: string }
396
+ * ```
397
+ */
398
+ static transform(schema, mapper) {
399
+ const definition = schema.definition;
400
+ const options = schema.options || {};
401
+ const transformedDefinition = {};
402
+ for (const [key, value] of Object.entries(definition)) {
403
+ if (typeof value === "string") {
404
+ transformedDefinition[key] = mapper(value, key);
405
+ }
406
+ else if (typeof value === "object" && value !== null) {
407
+ // Recursively transform nested objects
408
+ const nestedSchema = new InterfaceSchema(value, {});
409
+ const transformedNested = this.transform(nestedSchema, mapper);
410
+ transformedDefinition[key] = transformedNested.definition;
411
+ }
412
+ else {
413
+ transformedDefinition[key] = value;
414
+ }
415
+ }
416
+ return new InterfaceSchema(transformedDefinition, options);
417
+ }
418
+ /**
419
+ * Rename fields in a schema
420
+ * @example
421
+ * ```typescript
422
+ * const UserSchema = Interface({ user_id: "number", user_name: "string" });
423
+ * const RenamedSchema = Mod.rename(UserSchema, {
424
+ * user_id: "id",
425
+ * user_name: "name"
426
+ * });
427
+ * // Result: { id: number, name: string }
428
+ * ```
429
+ */
430
+ static rename(schema, fieldMap) {
431
+ const definition = schema.definition;
432
+ const options = schema.options || {};
433
+ const renamedDefinition = {};
434
+ for (const [key, value] of Object.entries(definition)) {
435
+ const newKey = fieldMap[key] || key;
436
+ renamedDefinition[newKey] = value;
437
+ }
438
+ return new InterfaceSchema(renamedDefinition, options);
439
+ }
440
+ /**
441
+ * Create a schema with default values that are automatically applied during validation
442
+ *
443
+ * This method allows you to specify default values that will be automatically applied
444
+ * to fields when they are missing or undefined in the input data. This is particularly
445
+ * useful for API endpoints, form processing, and configuration objects where you want
446
+ * to ensure certain fields always have sensible default values.
447
+ *
448
+ * Default values are applied during the validation process, so they don't modify the
449
+ * original schema definition but are included in the validated output.
450
+ *
451
+ * @param schema - The source schema to add defaults to
452
+ * @param defaultValues - Object mapping field names to their default values
453
+ * @returns A new schema that applies default values during validation
454
+ *
455
+ * @example Basic default values
456
+ * ```typescript
457
+ * const UserSchema = Interface({
458
+ * id: "number",
459
+ * name: "string",
460
+ * role: "string?",
461
+ * active: "boolean?",
462
+ * createdAt: "date?"
463
+ * });
464
+ *
465
+ * const UserWithDefaults = Mod.defaults(UserSchema, {
466
+ * role: "user",
467
+ * active: true,
468
+ * createdAt: new Date()
469
+ * });
470
+ *
471
+ * const result = UserWithDefaults.parse({
472
+ * id: 1,
473
+ * name: "John Doe"
474
+ * // role, active, and createdAt will be filled with defaults
475
+ * });
476
+ *
477
+ * console.log(result.data);
478
+ * // {
479
+ * // id: 1,
480
+ * // name: "John Doe",
481
+ * // role: "user",
482
+ * // active: true,
483
+ * // createdAt: 2023-12-01T10:30:00.000Z
484
+ * // }
485
+ * ```
486
+ *
487
+ * @example API configuration with defaults
488
+ * ```typescript
489
+ * const ApiConfigSchema = Interface({
490
+ * host: "string",
491
+ * port: "number?",
492
+ * timeout: "number?",
493
+ * retries: "number?",
494
+ * ssl: "boolean?",
495
+ * compression: "boolean?"
496
+ * });
497
+ *
498
+ * const ApiConfigWithDefaults = Mod.defaults(ApiConfigSchema, {
499
+ * port: 3000,
500
+ * timeout: 5000,
501
+ * retries: 3,
502
+ * ssl: false,
503
+ * compression: true
504
+ * });
505
+ *
506
+ * // Users only need to provide the host
507
+ * const config = ApiConfigWithDefaults.parse({
508
+ * host: "api.example.com"
509
+ * });
510
+ * // All other fields get sensible defaults
511
+ * ```
512
+ *
513
+ * @example Form processing with defaults
514
+ * ```typescript
515
+ * const ProfileFormSchema = Interface({
516
+ * name: "string",
517
+ * email: "email",
518
+ * theme: "string?",
519
+ * notifications: "boolean?",
520
+ * language: "string?"
521
+ * });
522
+ *
523
+ * const ProfileWithDefaults = Mod.defaults(ProfileFormSchema, {
524
+ * theme: "light",
525
+ * notifications: true,
526
+ * language: "en"
527
+ * });
528
+ *
529
+ * // Form submissions get defaults for unchecked/unselected fields
530
+ * const profile = ProfileWithDefaults.parse({
531
+ * name: "Jane Smith",
532
+ * email: "jane@example.com"
533
+ * // theme, notifications, language get defaults
534
+ * });
535
+ * ```
536
+ *
537
+ * @example Conditional defaults based on environment
538
+ * ```typescript
539
+ * const AppConfigSchema = Interface({
540
+ * environment: "development|staging|production",
541
+ * debug: "boolean?",
542
+ * logLevel: "string?",
543
+ * cacheEnabled: "boolean?"
544
+ * });
545
+ *
546
+ * const isDevelopment = process.env.NODE_ENV === "development";
547
+ *
548
+ * const AppConfigWithDefaults = Mod.defaults(AppConfigSchema, {
549
+ * debug: isDevelopment,
550
+ * logLevel: isDevelopment ? "debug" : "info",
551
+ * cacheEnabled: !isDevelopment
552
+ * });
553
+ * ```
554
+ */
555
+ static defaults(schema, defaultValues) {
556
+ const definition = schema.definition;
557
+ const options = schema.options || {};
558
+ // Store default values in options for the validation system to use
559
+ const defaultsOptions = {
560
+ ...options,
561
+ defaults: {
562
+ ...(options.defaults || {}),
563
+ ...defaultValues,
564
+ },
565
+ };
566
+ return new InterfaceSchema(definition, defaultsOptions);
567
+ }
568
+ /**
569
+ * Create a strict version of a schema that rejects any additional properties
570
+ *
571
+ * By default, ReliantType ignores extra properties in the input data (they're
572
+ * simply not included in the validated output). The `strict()` method changes this
573
+ * behavior to actively reject any properties that aren't defined in the schema,
574
+ * making validation fail with an error.
575
+ *
576
+ * This is useful for APIs where you want to ensure clients aren't sending
577
+ * unexpected data, form validation where extra fields indicate errors, or
578
+ * configuration parsing where unknown options should be flagged.
579
+ *
580
+ * @param schema - The source schema to make strict
581
+ * @returns A new schema that rejects additional properties
582
+ *
583
+ * @example Basic strict validation
584
+ * ```typescript
585
+ * const UserSchema = Interface({
586
+ * id: "number",
587
+ * name: "string",
588
+ * email: "email"
589
+ * });
590
+ *
591
+ * const StrictUserSchema = Mod.strict(UserSchema);
592
+ *
593
+ * // This will succeed
594
+ * StrictUserSchema.parse({
595
+ * id: 1,
596
+ * name: "John",
597
+ * email: "john@example.com"
598
+ * }); // ✅
599
+ *
600
+ * // This will fail due to extra property
601
+ * StrictUserSchema.parse({
602
+ * id: 1,
603
+ * name: "John",
604
+ * email: "john@example.com",
605
+ * age: 30 // ❌ Error: Unexpected properties: age
606
+ * });
607
+ * ```
608
+ *
609
+ * @example API endpoint validation
610
+ * ```typescript
611
+ * const CreatePostSchema = Interface({
612
+ * title: "string",
613
+ * content: "string",
614
+ * tags: "string[]?",
615
+ * published: "boolean?"
616
+ * });
617
+ *
618
+ * const StrictCreatePostSchema = Mod.strict(CreatePostSchema);
619
+ *
620
+ * // Protect against typos or malicious extra data
621
+ * app.post('/posts', (req, res) => {
622
+ * const result = StrictCreatePostSchema.safeParse(req.body);
623
+ *
624
+ * if (!result.success) {
625
+ * return res.status(400).json({
626
+ * error: "Invalid request data",
627
+ * details: result.errors
628
+ * });
629
+ * }
630
+ *
631
+ * // Guaranteed to only contain expected fields
632
+ * const post = result.data;
633
+ * });
634
+ * ```
635
+ *
636
+ * @example Configuration validation
637
+ * ```typescript
638
+ * const DatabaseConfigSchema = Interface({
639
+ * host: "string",
640
+ * port: "number",
641
+ * username: "string",
642
+ * password: "string",
643
+ * database: "string"
644
+ * });
645
+ *
646
+ * const StrictDatabaseConfig = Mod.strict(DatabaseConfigSchema);
647
+ *
648
+ * // Catch configuration typos early
649
+ * const config = StrictDatabaseConfig.parse({
650
+ * host: "localhost",
651
+ * port: 5432,
652
+ * username: "admin",
653
+ * password: "secret",
654
+ * database: "myapp",
655
+ * connectionTimeout: 5000 // ❌ Error: Unknown config option
656
+ * });
657
+ * ```
658
+ *
659
+ * @example Comparison with default behavior
660
+ * ```typescript
661
+ * const Schema = Interface({ name: "string" });
662
+ * const StrictSchema = Mod.strict(Schema);
663
+ *
664
+ * const input = { name: "John", extra: "ignored" };
665
+ *
666
+ * // Default behavior: extra properties ignored
667
+ * const defaultResult = Schema.parse(input);
668
+ * console.log(defaultResult); // { name: "John" } - extra property ignored
669
+ *
670
+ * // Strict behavior: extra properties cause error
671
+ * const strictResult = StrictSchema.safeParse(input);
672
+ * console.log(strictResult.success); // false
673
+ * console.log(strictResult.errors); // [{ message: "Unexpected properties: extra" }]
674
+ * ```
675
+ */
676
+ static strict(schema) {
677
+ const definition = schema.definition;
678
+ const options = schema.options || {};
679
+ const strictOptions = {
680
+ ...options,
681
+ strict: true,
682
+ additionalProperties: false,
683
+ };
684
+ return new InterfaceSchema(definition, strictOptions);
685
+ }
686
+ /**
687
+ * Create a passthrough version of a schema that preserves additional properties
688
+ *
689
+ * By default, ReliantType ignores extra properties in the input data (they're
690
+ * not included in the validated output). The `passthrough()` method changes this
691
+ * behavior to explicitly include all additional properties in the validated result,
692
+ * effectively making the schema more permissive.
693
+ *
694
+ * This is useful for proxy APIs, data transformation pipelines, or situations
695
+ * where you want to validate known fields while preserving unknown ones for
696
+ * later processing or forwarding to other systems.
697
+ *
698
+ * @param schema - The source schema to make passthrough
699
+ * @returns A new schema that includes additional properties in the output
700
+ *
701
+ * @example Basic passthrough behavior
702
+ * ```typescript
703
+ * const UserSchema = Interface({
704
+ * id: "number",
705
+ * name: "string",
706
+ * email: "email"
707
+ * });
708
+ *
709
+ * const PassthroughUserSchema = Mod.passthrough(UserSchema);
710
+ *
711
+ * const result = PassthroughUserSchema.parse({
712
+ * id: 1,
713
+ * name: "John",
714
+ * email: "john@example.com",
715
+ * age: 30, // Extra property
716
+ * department: "IT" // Extra property
717
+ * });
718
+ *
719
+ * console.log(result);
720
+ * // {
721
+ * // id: 1,
722
+ * // name: "John",
723
+ * // email: "john@example.com",
724
+ * // age: 30, // ✅ Preserved
725
+ * // department: "IT" // ✅ Preserved
726
+ * // }
727
+ * ```
728
+ *
729
+ * @example API proxy with validation
730
+ * ```typescript
731
+ * const KnownUserFieldsSchema = Interface({
732
+ * id: "number",
733
+ * name: "string",
734
+ * email: "email",
735
+ * role: "admin|user|moderator"
736
+ * });
737
+ *
738
+ * const ProxyUserSchema = Mod.passthrough(KnownUserFieldsSchema);
739
+ *
740
+ * // Validate known fields while preserving unknown ones
741
+ * app.post('/users/proxy', (req, res) => {
742
+ * const result = ProxyUserSchema.safeParse(req.body);
743
+ *
744
+ * if (!result.success) {
745
+ * return res.status(400).json({
746
+ * error: "Invalid known fields",
747
+ * details: result.errors
748
+ * });
749
+ * }
750
+ *
751
+ * // Forward to another service with all data preserved
752
+ * const response = await externalAPI.createUser(result.data);
753
+ * res.json(response);
754
+ * });
755
+ * ```
756
+ *
757
+ * @example Data transformation pipeline
758
+ * ```typescript
759
+ * const CoreDataSchema = Interface({
760
+ * timestamp: "date",
761
+ * userId: "number",
762
+ * action: "string"
763
+ * });
764
+ *
765
+ * const FlexibleDataSchema = Mod.passthrough(CoreDataSchema);
766
+ *
767
+ * // Process events with varying additional metadata
768
+ * function processEvent(rawEvent: unknown) {
769
+ * const result = FlexibleDataSchema.safeParse(rawEvent);
770
+ *
771
+ * if (!result.success) {
772
+ * throw new Error("Invalid core event structure");
773
+ * }
774
+ *
775
+ * const event = result.data;
776
+ *
777
+ * // Core fields are validated and typed
778
+ * console.log(`User ${event.userId} performed ${event.action} at ${event.timestamp}`);
779
+ *
780
+ * // Additional metadata is preserved for downstream processing
781
+ * if ('metadata' in event) {
782
+ * processMetadata(event.metadata);
783
+ * }
784
+ *
785
+ * return event; // All data preserved
786
+ * }
787
+ * ```
788
+ *
789
+ * @example Comparison with default and strict behavior
790
+ * ```typescript
791
+ * const Schema = Interface({ name: "string" });
792
+ * const PassthroughSchema = Mod.passthrough(Schema);
793
+ * const StrictSchema = Mod.strict(Schema);
794
+ *
795
+ * const input = { name: "John", extra: "data", more: "fields" };
796
+ *
797
+ * // Default: extra properties ignored
798
+ * const defaultResult = Schema.parse(input);
799
+ * console.log(defaultResult); // { name: "John" }
800
+ *
801
+ * // Passthrough: extra properties included
802
+ * const passthroughResult = PassthroughSchema.parse(input);
803
+ * console.log(passthroughResult); // { name: "John", extra: "data", more: "fields" }
804
+ *
805
+ * // Strict: extra properties cause error
806
+ * const strictResult = StrictSchema.safeParse(input);
807
+ * console.log(strictResult.success); // false
808
+ * ```
809
+ */
810
+ static passthrough(schema) {
811
+ const definition = schema.definition;
812
+ const options = schema.options || {};
813
+ const passthroughOptions = {
814
+ ...options,
815
+ strict: false,
816
+ additionalProperties: true,
817
+ };
818
+ return new InterfaceSchema(definition, passthroughOptions);
819
+ }
820
+ /**
821
+ * Create a schema that accepts null values for all fields
822
+ * @example
823
+ * ```typescript
824
+ * const UserSchema = Interface({ id: "number", name: "string" });
825
+ * const NullableSchema = Mod.nullable(UserSchema);
826
+ * // Result: { id: number | null, name: string | null }
827
+ * ```
828
+ */
829
+ static nullable(schema) {
830
+ const definition = schema.definition;
831
+ const options = schema.options || {};
832
+ const nullableDefinition = {};
833
+ for (const [key, value] of Object.entries(definition)) {
834
+ if (typeof value === "string") {
835
+ // Add null union to the type
836
+ nullableDefinition[key] = value.includes("|")
837
+ ? `${value}|null`
838
+ : `${value}|null`;
839
+ }
840
+ else {
841
+ nullableDefinition[key] = value;
842
+ }
843
+ }
844
+ return new InterfaceSchema(nullableDefinition, options);
845
+ }
846
+ /**
847
+ * Get comprehensive metadata and statistics about a schema
848
+ *
849
+ * This method analyzes a schema and returns detailed information about its structure,
850
+ * including field counts, types, and other useful metadata. This is particularly
851
+ * useful for debugging, documentation generation, schema analysis tools, or
852
+ * building dynamic UIs based on schema structure.
853
+ *
854
+ * @param schema - The schema to analyze
855
+ * @returns Object containing detailed schema metadata
856
+ *
857
+ * @example Basic schema analysis
858
+ * ```typescript
859
+ * const UserSchema = Interface({
860
+ * id: "number",
861
+ * name: "string",
862
+ * email: "email?",
863
+ * profile: {
864
+ * bio: "string?",
865
+ * avatar: "string"
866
+ * },
867
+ * tags: "string[]?"
868
+ * });
869
+ *
870
+ * const info = Mod.info(UserSchema);
871
+ * console.log(info);
872
+ * // {
873
+ * // fieldCount: 5,
874
+ * // requiredFields: 3,
875
+ * // optionalFields: 2,
876
+ * // types: ["number", "string", "email?", "object", "string[]?"],
877
+ * // fields: ["id", "name", "email", "profile", "tags"]
878
+ * // }
879
+ * ```
880
+ *
881
+ * @example Using info for documentation generation
882
+ * ```typescript
883
+ * function generateSchemaDoc(schema: InterfaceSchema<any>, name: string) {
884
+ * const info = Mod.info(schema);
885
+ *
886
+ * return `
887
+ * ## ${name} Schema
888
+ *
889
+ * **Fields:** ${info.fieldCount} total (${info.requiredFields} required, ${info.optionalFields} optional)
890
+ *
891
+ * **Field Types:**
892
+ * ${info.fields.map((field, i) => `- ${field}: ${info.types[i]}`).join('\n')}
893
+ * `;
894
+ * }
895
+ *
896
+ * const doc = generateSchemaDoc(UserSchema, "User");
897
+ * console.log(doc);
898
+ * ```
899
+ *
900
+ * @example Schema complexity analysis
901
+ * ```typescript
902
+ * function analyzeSchemaComplexity(schema: InterfaceSchema<any>) {
903
+ * const info = Mod.info(schema);
904
+ *
905
+ * const complexity = {
906
+ * simple: info.fieldCount <= 5,
907
+ * hasOptionalFields: info.optionalFields > 0,
908
+ * hasArrays: info.types.some(type => type.includes('[]')),
909
+ * hasNestedObjects: info.types.includes('object'),
910
+ * typeVariety: new Set(info.types.map(type =>
911
+ * type.replace(/\?|\[\]/g, '')
912
+ * )).size
913
+ * };
914
+ *
915
+ * return complexity;
916
+ * }
917
+ *
918
+ * const complexity = analyzeSchemaComplexity(UserSchema);
919
+ * console.log(complexity);
920
+ * // {
921
+ * // simple: false,
922
+ * // hasOptionalFields: true,
923
+ * // hasArrays: true,
924
+ * // hasNestedObjects: true,
925
+ * // typeVariety: 4
926
+ * // }
927
+ * ```
928
+ *
929
+ * @example Dynamic form generation
930
+ * ```typescript
931
+ * function generateFormFields(schema: InterfaceSchema<any>) {
932
+ * const info = Mod.info(schema);
933
+ *
934
+ * return info.fields.map((fieldName, index) => {
935
+ * const fieldType = info.types[index];
936
+ * const isRequired = !fieldType.includes('?');
937
+ * const baseType = fieldType.replace(/\?|\[\]/g, '');
938
+ *
939
+ * return {
940
+ * name: fieldName,
941
+ * type: baseType,
942
+ * required: isRequired,
943
+ * isArray: fieldType.includes('[]'),
944
+ * inputType: getInputType(baseType) // Custom function
945
+ * };
946
+ * });
947
+ * }
948
+ *
949
+ * function getInputType(type: string): string {
950
+ * switch (type) {
951
+ * case 'string': return 'text';
952
+ * case 'number': return 'number';
953
+ * case 'email': return 'email';
954
+ * case 'date': return 'date';
955
+ * case 'boolean': return 'checkbox';
956
+ * default: return 'text';
957
+ * }
958
+ * }
959
+ *
960
+ * const formFields = generateFormFields(UserSchema);
961
+ * ```
962
+ *
963
+ * @example Schema validation and testing
964
+ * ```typescript
965
+ * function validateSchemaStructure(schema: InterfaceSchema<any>) {
966
+ * const info = Mod.info(schema);
967
+ * const issues: string[] = [];
968
+ *
969
+ * if (info.fieldCount === 0) {
970
+ * issues.push("Schema has no fields");
971
+ * }
972
+ *
973
+ * if (info.requiredFields === 0) {
974
+ * issues.push("Schema has no required fields");
975
+ * }
976
+ *
977
+ * if (info.fieldCount > 20) {
978
+ * issues.push("Schema might be too complex (>20 fields)");
979
+ * }
980
+ *
981
+ * const unknownTypes = info.types.filter(type =>
982
+ * !['string', 'number', 'boolean', 'date', 'email', 'object'].some(known =>
983
+ * type.replace(/\?|\[\]/g, '').includes(known)
984
+ * )
985
+ * );
986
+ *
987
+ * if (unknownTypes.length > 0) {
988
+ * issues.push(`Unknown types found: ${unknownTypes.join(', ')}`);
989
+ * }
990
+ *
991
+ * return {
992
+ * valid: issues.length === 0,
993
+ * issues,
994
+ * info
995
+ * };
996
+ * }
997
+ * ```
998
+ */
999
+ static info(schema) {
1000
+ const definition = schema.definition;
1001
+ const fields = Object.keys(definition);
1002
+ const types = Object.values(definition).map((v) => typeof v === "string" ? v : "object");
1003
+ const optionalFields = types.filter((type) => typeof type === "string" && type.endsWith("?")).length;
1004
+ const requiredFields = fields.length - optionalFields;
1005
+ return {
1006
+ fieldCount: fields.length,
1007
+ requiredFields,
1008
+ optionalFields,
1009
+ types,
1010
+ fields,
1011
+ };
1012
+ }
1013
+ /**
1014
+ * Clone a schema with optional modifications
1015
+ * @example
1016
+ * ```typescript
1017
+ * const UserSchema = Interface({ id: "number", name: "string" });
1018
+ * const ClonedSchema = Mod.clone(UserSchema, { preserveOptions: true });
1019
+ * ```
1020
+ */
1021
+ static clone(schema, options = {}) {
1022
+ const definition = schema.definition;
1023
+ const schemaOptions = options.preserveOptions
1024
+ ? schema.options || {}
1025
+ : {};
1026
+ return new InterfaceSchema(JSON.parse(JSON.stringify(definition)), schemaOptions);
1027
+ }
1028
+ }
1029
+
1030
+ export { Mod };
1031
+ //# sourceMappingURL=Mod.js.map