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