@warlock.js/seal 4.0.135 → 4.0.136

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 (379) hide show
  1. package/cjs/factory/validators.d.ts +1 -1
  2. package/cjs/factory/validators.d.ts.map +1 -1
  3. package/cjs/factory/validators.js +2 -2
  4. package/cjs/factory/validators.js.map +1 -1
  5. package/cjs/helpers/validation-helpers.d.ts +22 -0
  6. package/cjs/helpers/validation-helpers.d.ts.map +1 -1
  7. package/cjs/helpers/validation-helpers.js +56 -34
  8. package/cjs/helpers/validation-helpers.js.map +1 -1
  9. package/cjs/index.js +1 -1
  10. package/cjs/mutators/date-mutators.js +1 -1
  11. package/cjs/mutators/date-mutators.js.map +1 -1
  12. package/cjs/rules/array/array-rules.d.ts.map +1 -1
  13. package/cjs/rules/array/array-rules.js +1 -0
  14. package/cjs/rules/array/array-rules.js.map +1 -1
  15. package/cjs/rules/common/enum.d.ts.map +1 -1
  16. package/cjs/rules/common/enum.js +17 -3
  17. package/cjs/rules/common/enum.js.map +1 -1
  18. package/cjs/rules/common/equals-field-rules.d.ts.map +1 -1
  19. package/cjs/rules/common/equals-field-rules.js +1 -0
  20. package/cjs/rules/common/equals-field-rules.js.map +1 -1
  21. package/cjs/rules/common/type-rules.d.ts +4 -0
  22. package/cjs/rules/common/type-rules.d.ts.map +1 -1
  23. package/cjs/rules/common/type-rules.js +14 -1
  24. package/cjs/rules/common/type-rules.js.map +1 -1
  25. package/cjs/rules/common/unknown-key.js +2 -2
  26. package/cjs/rules/common/unknown-key.js.map +1 -1
  27. package/cjs/rules/conditional/forbidden-if-rules.d.ts.map +1 -1
  28. package/cjs/rules/conditional/forbidden-if-rules.js +6 -0
  29. package/cjs/rules/conditional/forbidden-if-rules.js.map +1 -1
  30. package/cjs/rules/conditional/index.d.ts +1 -0
  31. package/cjs/rules/conditional/index.d.ts.map +1 -1
  32. package/cjs/rules/conditional/present-if-rules.d.ts.map +1 -1
  33. package/cjs/rules/conditional/present-if-rules.js +2 -0
  34. package/cjs/rules/conditional/present-if-rules.js.map +1 -1
  35. package/cjs/rules/conditional/present-unless-rules.d.ts.map +1 -1
  36. package/cjs/rules/conditional/present-unless-rules.js +2 -0
  37. package/cjs/rules/conditional/present-unless-rules.js.map +1 -1
  38. package/cjs/rules/conditional/present-with-rules.d.ts.map +1 -1
  39. package/cjs/rules/conditional/present-with-rules.js +9 -2
  40. package/cjs/rules/conditional/present-with-rules.js.map +1 -1
  41. package/cjs/rules/conditional/present-without-rules.d.ts.map +1 -1
  42. package/cjs/rules/conditional/present-without-rules.js +9 -2
  43. package/cjs/rules/conditional/present-without-rules.js.map +1 -1
  44. package/cjs/rules/conditional/required-if-rules.d.ts.map +1 -1
  45. package/cjs/rules/conditional/required-if-rules.js +22 -7
  46. package/cjs/rules/conditional/required-if-rules.js.map +1 -1
  47. package/cjs/rules/conditional/required-unless-rules.d.ts.map +1 -1
  48. package/cjs/rules/conditional/required-unless-rules.js +2 -0
  49. package/cjs/rules/conditional/required-unless-rules.js.map +1 -1
  50. package/cjs/rules/conditional/required-when-rule.d.ts +18 -0
  51. package/cjs/rules/conditional/required-when-rule.d.ts.map +1 -0
  52. package/cjs/rules/conditional/required-when-rule.js +26 -0
  53. package/cjs/rules/conditional/required-when-rule.js.map +1 -0
  54. package/cjs/rules/conditional/required-with-rules.d.ts.map +1 -1
  55. package/cjs/rules/conditional/required-with-rules.js +1 -0
  56. package/cjs/rules/conditional/required-with-rules.js.map +1 -1
  57. package/cjs/rules/conditional/required-without-rules.d.ts.map +1 -1
  58. package/cjs/rules/conditional/required-without-rules.js +1 -0
  59. package/cjs/rules/conditional/required-without-rules.js.map +1 -1
  60. package/cjs/rules/core/equal.d.ts.map +1 -1
  61. package/cjs/rules/core/equal.js +1 -0
  62. package/cjs/rules/core/equal.js.map +1 -1
  63. package/cjs/rules/core/required.d.ts +1 -1
  64. package/cjs/rules/core/required.js +1 -1
  65. package/cjs/rules/date/date-comparison-rules.d.ts.map +1 -1
  66. package/cjs/rules/date/date-comparison-rules.js +2 -0
  67. package/cjs/rules/date/date-comparison-rules.js.map +1 -1
  68. package/cjs/rules/date/date-day-rules.d.ts.map +1 -1
  69. package/cjs/rules/date/date-day-rules.js +4 -1
  70. package/cjs/rules/date/date-day-rules.js.map +1 -1
  71. package/cjs/rules/date/date-field-comparison-rules.d.ts.map +1 -1
  72. package/cjs/rules/date/date-field-comparison-rules.js +4 -0
  73. package/cjs/rules/date/date-field-comparison-rules.js.map +1 -1
  74. package/cjs/rules/date/date-period-rules.d.ts +20 -4
  75. package/cjs/rules/date/date-period-rules.d.ts.map +1 -1
  76. package/cjs/rules/date/date-period-rules.js +44 -5
  77. package/cjs/rules/date/date-period-rules.js.map +1 -1
  78. package/cjs/rules/date/date-relative-rules.d.ts.map +1 -1
  79. package/cjs/rules/date/date-relative-rules.js +3 -0
  80. package/cjs/rules/date/date-relative-rules.js.map +1 -1
  81. package/cjs/rules/date/date-special-rules.d.ts.map +1 -1
  82. package/cjs/rules/date/date-special-rules.js +5 -6
  83. package/cjs/rules/date/date-special-rules.js.map +1 -1
  84. package/cjs/rules/date/date.d.ts.map +1 -1
  85. package/cjs/rules/date/date.js +15 -6
  86. package/cjs/rules/date/date.js.map +1 -1
  87. package/cjs/rules/file/dimensions.d.ts.map +1 -1
  88. package/cjs/rules/file/dimensions.js +4 -0
  89. package/cjs/rules/file/dimensions.js.map +1 -1
  90. package/cjs/rules/file/file-size.d.ts.map +1 -1
  91. package/cjs/rules/file/file-size.js +4 -22
  92. package/cjs/rules/file/file-size.js.map +1 -1
  93. package/cjs/rules/length/length-rules.d.ts.map +1 -1
  94. package/cjs/rules/length/length-rules.js +13 -22
  95. package/cjs/rules/length/length-rules.js.map +1 -1
  96. package/cjs/rules/number/number-rules.d.ts.map +1 -1
  97. package/cjs/rules/number/number-rules.js +13 -2
  98. package/cjs/rules/number/number-rules.js.map +1 -1
  99. package/cjs/rules/scalar/accepted-rule.d.ts.map +1 -1
  100. package/cjs/rules/scalar/accepted-rule.js +12 -5
  101. package/cjs/rules/scalar/accepted-rule.js.map +1 -1
  102. package/cjs/rules/scalar/declined-rule.d.ts.map +1 -1
  103. package/cjs/rules/scalar/declined-rule.js +12 -5
  104. package/cjs/rules/scalar/declined-rule.js.map +1 -1
  105. package/cjs/rules/string/matches.d.ts.map +1 -1
  106. package/cjs/rules/string/matches.js +1 -0
  107. package/cjs/rules/string/matches.js.map +1 -1
  108. package/cjs/rules/string/pattern.d.ts.map +1 -1
  109. package/cjs/rules/string/pattern.js +1 -0
  110. package/cjs/rules/string/pattern.js.map +1 -1
  111. package/cjs/rules/string/string-comparison.d.ts.map +1 -1
  112. package/cjs/rules/string/string-comparison.js +4 -0
  113. package/cjs/rules/string/string-comparison.js.map +1 -1
  114. package/cjs/types/context-types.d.ts +0 -1
  115. package/cjs/types/context-types.d.ts.map +1 -1
  116. package/cjs/types/inference-types.d.ts +10 -5
  117. package/cjs/types/inference-types.d.ts.map +1 -1
  118. package/cjs/types/rule-types.d.ts +4 -0
  119. package/cjs/types/rule-types.d.ts.map +1 -1
  120. package/cjs/validators/array-validator.d.ts +2 -2
  121. package/cjs/validators/array-validator.d.ts.map +1 -1
  122. package/cjs/validators/array-validator.js +13 -23
  123. package/cjs/validators/array-validator.js.map +1 -1
  124. package/cjs/validators/base-validator.d.ts +79 -369
  125. package/cjs/validators/base-validator.d.ts.map +1 -1
  126. package/cjs/validators/base-validator.js +144 -826
  127. package/cjs/validators/base-validator.js.map +1 -1
  128. package/cjs/validators/boolean-validator.d.ts +18 -15
  129. package/cjs/validators/boolean-validator.d.ts.map +1 -1
  130. package/cjs/validators/boolean-validator.js +46 -16
  131. package/cjs/validators/boolean-validator.js.map +1 -1
  132. package/cjs/validators/date-validator.d.ts +8 -3
  133. package/cjs/validators/date-validator.d.ts.map +1 -1
  134. package/cjs/validators/date-validator.js +176 -246
  135. package/cjs/validators/date-validator.js.map +1 -1
  136. package/cjs/validators/float-validator.js +1 -1
  137. package/cjs/validators/float-validator.js.map +1 -1
  138. package/cjs/validators/index.d.ts +5 -0
  139. package/cjs/validators/index.d.ts.map +1 -1
  140. package/cjs/validators/int-validator.js +1 -1
  141. package/cjs/validators/int-validator.js.map +1 -1
  142. package/cjs/validators/methods/equality-conditional-methods.d.ts +88 -0
  143. package/cjs/validators/methods/equality-conditional-methods.d.ts.map +1 -0
  144. package/cjs/validators/methods/equality-conditional-methods.js +118 -0
  145. package/cjs/validators/methods/equality-conditional-methods.js.map +1 -0
  146. package/cjs/validators/methods/forbidden-methods.d.ts +58 -0
  147. package/cjs/validators/methods/forbidden-methods.d.ts.map +1 -0
  148. package/cjs/validators/methods/forbidden-methods.js +122 -0
  149. package/cjs/validators/methods/forbidden-methods.js.map +1 -0
  150. package/cjs/validators/methods/present-methods.d.ts +102 -0
  151. package/cjs/validators/methods/present-methods.d.ts.map +1 -0
  152. package/cjs/validators/methods/present-methods.js +229 -0
  153. package/cjs/validators/methods/present-methods.js.map +1 -0
  154. package/cjs/validators/methods/required-methods.d.ts +174 -0
  155. package/cjs/validators/methods/required-methods.d.ts.map +1 -0
  156. package/cjs/validators/methods/required-methods.js +246 -0
  157. package/cjs/validators/methods/required-methods.js.map +1 -0
  158. package/cjs/validators/number-validator.d.ts +11 -13
  159. package/cjs/validators/number-validator.d.ts.map +1 -1
  160. package/cjs/validators/number-validator.js +60 -78
  161. package/cjs/validators/number-validator.js.map +1 -1
  162. package/cjs/validators/numeric-validator.js +1 -1
  163. package/cjs/validators/numeric-validator.js.map +1 -1
  164. package/cjs/validators/object-validator.d.ts +1 -0
  165. package/cjs/validators/object-validator.d.ts.map +1 -1
  166. package/cjs/validators/object-validator.js +21 -15
  167. package/cjs/validators/object-validator.js.map +1 -1
  168. package/cjs/validators/primitive-validator.d.ts +70 -0
  169. package/cjs/validators/primitive-validator.d.ts.map +1 -0
  170. package/cjs/validators/primitive-validator.js +80 -0
  171. package/cjs/validators/primitive-validator.js.map +1 -0
  172. package/cjs/validators/record-validator.d.ts +4 -0
  173. package/cjs/validators/record-validator.d.ts.map +1 -1
  174. package/cjs/validators/record-validator.js +7 -1
  175. package/cjs/validators/record-validator.js.map +1 -1
  176. package/cjs/validators/scalar-validator.d.ts +5 -15
  177. package/cjs/validators/scalar-validator.d.ts.map +1 -1
  178. package/cjs/validators/scalar-validator.js +20 -78
  179. package/cjs/validators/scalar-validator.js.map +1 -1
  180. package/cjs/validators/string-validator.d.ts +2 -18
  181. package/cjs/validators/string-validator.d.ts.map +1 -1
  182. package/cjs/validators/string-validator.js +71 -164
  183. package/cjs/validators/string-validator.js.map +1 -1
  184. package/cjs/validators/tuple-validator.d.ts.map +1 -1
  185. package/cjs/validators/tuple-validator.js +2 -2
  186. package/cjs/validators/tuple-validator.js.map +1 -1
  187. package/cjs/validators/union-validator.d.ts.map +1 -1
  188. package/cjs/validators/union-validator.js +1 -3
  189. package/cjs/validators/union-validator.js.map +1 -1
  190. package/esm/factory/validators.d.ts +1 -1
  191. package/esm/factory/validators.d.ts.map +1 -1
  192. package/esm/factory/validators.js +2 -2
  193. package/esm/factory/validators.js.map +1 -1
  194. package/esm/helpers/validation-helpers.d.ts +22 -0
  195. package/esm/helpers/validation-helpers.d.ts.map +1 -1
  196. package/esm/helpers/validation-helpers.js +56 -34
  197. package/esm/helpers/validation-helpers.js.map +1 -1
  198. package/esm/index.js +1 -1
  199. package/esm/mutators/date-mutators.js +1 -1
  200. package/esm/mutators/date-mutators.js.map +1 -1
  201. package/esm/rules/array/array-rules.d.ts.map +1 -1
  202. package/esm/rules/array/array-rules.js +1 -0
  203. package/esm/rules/array/array-rules.js.map +1 -1
  204. package/esm/rules/common/enum.d.ts.map +1 -1
  205. package/esm/rules/common/enum.js +18 -4
  206. package/esm/rules/common/enum.js.map +1 -1
  207. package/esm/rules/common/equals-field-rules.d.ts.map +1 -1
  208. package/esm/rules/common/equals-field-rules.js +1 -0
  209. package/esm/rules/common/equals-field-rules.js.map +1 -1
  210. package/esm/rules/common/type-rules.d.ts +4 -0
  211. package/esm/rules/common/type-rules.d.ts.map +1 -1
  212. package/esm/rules/common/type-rules.js +15 -2
  213. package/esm/rules/common/type-rules.js.map +1 -1
  214. package/esm/rules/common/unknown-key.js +2 -2
  215. package/esm/rules/common/unknown-key.js.map +1 -1
  216. package/esm/rules/conditional/forbidden-if-rules.d.ts.map +1 -1
  217. package/esm/rules/conditional/forbidden-if-rules.js +6 -0
  218. package/esm/rules/conditional/forbidden-if-rules.js.map +1 -1
  219. package/esm/rules/conditional/index.d.ts +1 -0
  220. package/esm/rules/conditional/index.d.ts.map +1 -1
  221. package/esm/rules/conditional/present-if-rules.d.ts.map +1 -1
  222. package/esm/rules/conditional/present-if-rules.js +2 -0
  223. package/esm/rules/conditional/present-if-rules.js.map +1 -1
  224. package/esm/rules/conditional/present-unless-rules.d.ts.map +1 -1
  225. package/esm/rules/conditional/present-unless-rules.js +2 -0
  226. package/esm/rules/conditional/present-unless-rules.js.map +1 -1
  227. package/esm/rules/conditional/present-with-rules.d.ts.map +1 -1
  228. package/esm/rules/conditional/present-with-rules.js +9 -2
  229. package/esm/rules/conditional/present-with-rules.js.map +1 -1
  230. package/esm/rules/conditional/present-without-rules.d.ts.map +1 -1
  231. package/esm/rules/conditional/present-without-rules.js +9 -2
  232. package/esm/rules/conditional/present-without-rules.js.map +1 -1
  233. package/esm/rules/conditional/required-if-rules.d.ts.map +1 -1
  234. package/esm/rules/conditional/required-if-rules.js +22 -7
  235. package/esm/rules/conditional/required-if-rules.js.map +1 -1
  236. package/esm/rules/conditional/required-unless-rules.d.ts.map +1 -1
  237. package/esm/rules/conditional/required-unless-rules.js +2 -0
  238. package/esm/rules/conditional/required-unless-rules.js.map +1 -1
  239. package/esm/rules/conditional/required-when-rule.d.ts +18 -0
  240. package/esm/rules/conditional/required-when-rule.d.ts.map +1 -0
  241. package/esm/rules/conditional/required-when-rule.js +26 -0
  242. package/esm/rules/conditional/required-when-rule.js.map +1 -0
  243. package/esm/rules/conditional/required-with-rules.d.ts.map +1 -1
  244. package/esm/rules/conditional/required-with-rules.js +1 -0
  245. package/esm/rules/conditional/required-with-rules.js.map +1 -1
  246. package/esm/rules/conditional/required-without-rules.d.ts.map +1 -1
  247. package/esm/rules/conditional/required-without-rules.js +1 -0
  248. package/esm/rules/conditional/required-without-rules.js.map +1 -1
  249. package/esm/rules/core/equal.d.ts.map +1 -1
  250. package/esm/rules/core/equal.js +1 -0
  251. package/esm/rules/core/equal.js.map +1 -1
  252. package/esm/rules/core/required.d.ts +1 -1
  253. package/esm/rules/core/required.js +1 -1
  254. package/esm/rules/date/date-comparison-rules.d.ts.map +1 -1
  255. package/esm/rules/date/date-comparison-rules.js +2 -0
  256. package/esm/rules/date/date-comparison-rules.js.map +1 -1
  257. package/esm/rules/date/date-day-rules.d.ts.map +1 -1
  258. package/esm/rules/date/date-day-rules.js +4 -1
  259. package/esm/rules/date/date-day-rules.js.map +1 -1
  260. package/esm/rules/date/date-field-comparison-rules.d.ts.map +1 -1
  261. package/esm/rules/date/date-field-comparison-rules.js +4 -0
  262. package/esm/rules/date/date-field-comparison-rules.js.map +1 -1
  263. package/esm/rules/date/date-period-rules.d.ts +20 -4
  264. package/esm/rules/date/date-period-rules.d.ts.map +1 -1
  265. package/esm/rules/date/date-period-rules.js +44 -5
  266. package/esm/rules/date/date-period-rules.js.map +1 -1
  267. package/esm/rules/date/date-relative-rules.d.ts.map +1 -1
  268. package/esm/rules/date/date-relative-rules.js +3 -0
  269. package/esm/rules/date/date-relative-rules.js.map +1 -1
  270. package/esm/rules/date/date-special-rules.d.ts.map +1 -1
  271. package/esm/rules/date/date-special-rules.js +5 -6
  272. package/esm/rules/date/date-special-rules.js.map +1 -1
  273. package/esm/rules/date/date.d.ts.map +1 -1
  274. package/esm/rules/date/date.js +15 -6
  275. package/esm/rules/date/date.js.map +1 -1
  276. package/esm/rules/file/dimensions.d.ts.map +1 -1
  277. package/esm/rules/file/dimensions.js +4 -0
  278. package/esm/rules/file/dimensions.js.map +1 -1
  279. package/esm/rules/file/file-size.d.ts.map +1 -1
  280. package/esm/rules/file/file-size.js +4 -22
  281. package/esm/rules/file/file-size.js.map +1 -1
  282. package/esm/rules/length/length-rules.d.ts.map +1 -1
  283. package/esm/rules/length/length-rules.js +13 -22
  284. package/esm/rules/length/length-rules.js.map +1 -1
  285. package/esm/rules/number/number-rules.d.ts.map +1 -1
  286. package/esm/rules/number/number-rules.js +13 -2
  287. package/esm/rules/number/number-rules.js.map +1 -1
  288. package/esm/rules/scalar/accepted-rule.d.ts.map +1 -1
  289. package/esm/rules/scalar/accepted-rule.js +12 -5
  290. package/esm/rules/scalar/accepted-rule.js.map +1 -1
  291. package/esm/rules/scalar/declined-rule.d.ts.map +1 -1
  292. package/esm/rules/scalar/declined-rule.js +12 -5
  293. package/esm/rules/scalar/declined-rule.js.map +1 -1
  294. package/esm/rules/string/matches.d.ts.map +1 -1
  295. package/esm/rules/string/matches.js +1 -0
  296. package/esm/rules/string/matches.js.map +1 -1
  297. package/esm/rules/string/pattern.d.ts.map +1 -1
  298. package/esm/rules/string/pattern.js +1 -0
  299. package/esm/rules/string/pattern.js.map +1 -1
  300. package/esm/rules/string/string-comparison.d.ts.map +1 -1
  301. package/esm/rules/string/string-comparison.js +4 -0
  302. package/esm/rules/string/string-comparison.js.map +1 -1
  303. package/esm/types/context-types.d.ts +0 -1
  304. package/esm/types/context-types.d.ts.map +1 -1
  305. package/esm/types/inference-types.d.ts +10 -5
  306. package/esm/types/inference-types.d.ts.map +1 -1
  307. package/esm/types/rule-types.d.ts +4 -0
  308. package/esm/types/rule-types.d.ts.map +1 -1
  309. package/esm/validators/array-validator.d.ts +2 -2
  310. package/esm/validators/array-validator.d.ts.map +1 -1
  311. package/esm/validators/array-validator.js +13 -23
  312. package/esm/validators/array-validator.js.map +1 -1
  313. package/esm/validators/base-validator.d.ts +79 -369
  314. package/esm/validators/base-validator.d.ts.map +1 -1
  315. package/esm/validators/base-validator.js +144 -826
  316. package/esm/validators/base-validator.js.map +1 -1
  317. package/esm/validators/boolean-validator.d.ts +18 -15
  318. package/esm/validators/boolean-validator.d.ts.map +1 -1
  319. package/esm/validators/boolean-validator.js +46 -16
  320. package/esm/validators/boolean-validator.js.map +1 -1
  321. package/esm/validators/date-validator.d.ts +8 -3
  322. package/esm/validators/date-validator.d.ts.map +1 -1
  323. package/esm/validators/date-validator.js +176 -246
  324. package/esm/validators/date-validator.js.map +1 -1
  325. package/esm/validators/float-validator.js +1 -1
  326. package/esm/validators/float-validator.js.map +1 -1
  327. package/esm/validators/index.d.ts +5 -0
  328. package/esm/validators/index.d.ts.map +1 -1
  329. package/esm/validators/int-validator.js +1 -1
  330. package/esm/validators/int-validator.js.map +1 -1
  331. package/esm/validators/methods/equality-conditional-methods.d.ts +88 -0
  332. package/esm/validators/methods/equality-conditional-methods.d.ts.map +1 -0
  333. package/esm/validators/methods/equality-conditional-methods.js +118 -0
  334. package/esm/validators/methods/equality-conditional-methods.js.map +1 -0
  335. package/esm/validators/methods/forbidden-methods.d.ts +58 -0
  336. package/esm/validators/methods/forbidden-methods.d.ts.map +1 -0
  337. package/esm/validators/methods/forbidden-methods.js +122 -0
  338. package/esm/validators/methods/forbidden-methods.js.map +1 -0
  339. package/esm/validators/methods/present-methods.d.ts +102 -0
  340. package/esm/validators/methods/present-methods.d.ts.map +1 -0
  341. package/esm/validators/methods/present-methods.js +229 -0
  342. package/esm/validators/methods/present-methods.js.map +1 -0
  343. package/esm/validators/methods/required-methods.d.ts +174 -0
  344. package/esm/validators/methods/required-methods.d.ts.map +1 -0
  345. package/esm/validators/methods/required-methods.js +246 -0
  346. package/esm/validators/methods/required-methods.js.map +1 -0
  347. package/esm/validators/number-validator.d.ts +11 -13
  348. package/esm/validators/number-validator.d.ts.map +1 -1
  349. package/esm/validators/number-validator.js +60 -78
  350. package/esm/validators/number-validator.js.map +1 -1
  351. package/esm/validators/numeric-validator.js +1 -1
  352. package/esm/validators/numeric-validator.js.map +1 -1
  353. package/esm/validators/object-validator.d.ts +1 -0
  354. package/esm/validators/object-validator.d.ts.map +1 -1
  355. package/esm/validators/object-validator.js +21 -15
  356. package/esm/validators/object-validator.js.map +1 -1
  357. package/esm/validators/primitive-validator.d.ts +70 -0
  358. package/esm/validators/primitive-validator.d.ts.map +1 -0
  359. package/esm/validators/primitive-validator.js +80 -0
  360. package/esm/validators/primitive-validator.js.map +1 -0
  361. package/esm/validators/record-validator.d.ts +4 -0
  362. package/esm/validators/record-validator.d.ts.map +1 -1
  363. package/esm/validators/record-validator.js +8 -2
  364. package/esm/validators/record-validator.js.map +1 -1
  365. package/esm/validators/scalar-validator.d.ts +5 -15
  366. package/esm/validators/scalar-validator.d.ts.map +1 -1
  367. package/esm/validators/scalar-validator.js +20 -78
  368. package/esm/validators/scalar-validator.js.map +1 -1
  369. package/esm/validators/string-validator.d.ts +2 -18
  370. package/esm/validators/string-validator.d.ts.map +1 -1
  371. package/esm/validators/string-validator.js +71 -164
  372. package/esm/validators/string-validator.js.map +1 -1
  373. package/esm/validators/tuple-validator.d.ts.map +1 -1
  374. package/esm/validators/tuple-validator.js +2 -2
  375. package/esm/validators/tuple-validator.js.map +1 -1
  376. package/esm/validators/union-validator.d.ts.map +1 -1
  377. package/esm/validators/union-validator.js +1 -3
  378. package/esm/validators/union-validator.js.map +1 -1
  379. package/package.json +1 -1
@@ -1,4 +1,4 @@
1
- 'use strict';var reinforcements=require('@mongez/reinforcements'),validationHelpers=require('../helpers/validation-helpers.js'),isEmptyValue=require('../helpers/is-empty-value.js'),equal=require('../rules/core/equal.js'),forbidden=require('../rules/core/forbidden.js'),required=require('../rules/core/required.js'),when=require('../rules/core/when.js');require('@mongez/supportive-is'),require('net');var requiredIfRules=require('../rules/conditional/required-if-rules.js'),requiredUnlessRules=require('../rules/conditional/required-unless-rules.js'),requiredWithRules=require('../rules/conditional/required-with-rules.js'),requiredWithoutRules=require('../rules/conditional/required-without-rules.js'),presentIfRules=require('../rules/conditional/present-if-rules.js'),presentUnlessRules=require('../rules/conditional/present-unless-rules.js'),presentWithRules=require('../rules/conditional/present-with-rules.js'),presentWithoutRules=require('../rules/conditional/present-without-rules.js'),forbiddenIfRules=require('../rules/conditional/forbidden-if-rules.js'),equalsFieldRules=require('../rules/common/equals-field-rules.js');/**
1
+ 'use strict';var reinforcements=require('@mongez/reinforcements'),validationHelpers=require('../helpers/validation-helpers.js'),isEmptyValue=require('../helpers/is-empty-value.js'),required=require('../rules/core/required.js');/**
2
2
  * Base validator class - foundation for all validators
3
3
  */
4
4
  class BaseValidator {
@@ -8,6 +8,23 @@ class BaseValidator {
8
8
  description;
9
9
  shouldOmit = false;
10
10
  isNullable = false;
11
+ isMutable = false;
12
+ /**
13
+ * Whether the field is optional.
14
+ * - false (default): field is required unless a requiredRule governs the condition.
15
+ * - true: field can be absent or empty — set by calling .optional().
16
+ *
17
+ * Also used as a TypeScript literal brand via the optional() return type.
18
+ */
19
+ isOptional = false;
20
+ /**
21
+ * The single required-condition rule for this field.
22
+ * - null: field uses strict default (always required when not optional).
23
+ * - set: the rule governs when the field is required (e.g., requiredIf).
24
+ *
25
+ * Stored separately from rules[] and prepended at validate() time.
26
+ */
27
+ requiredRule = this.createRule(required.requiredRule);
11
28
  /**
12
29
  * Pipeline to transform the mutated/original data before returning it
13
30
  */
@@ -22,6 +39,28 @@ class BaseValidator {
22
39
  * Attributed that will be always using the attribute translator
23
40
  */
24
41
  translatedAttributes = {};
42
+ /**
43
+ * Mark the validator as mutable
44
+ */
45
+ get mutable() {
46
+ this.isMutable = true;
47
+ return this;
48
+ }
49
+ /**
50
+ * Mark the validator as immutable
51
+ */
52
+ get immutable() {
53
+ this.isMutable = false;
54
+ return this;
55
+ }
56
+ /**
57
+ * Get the instance to apply changes to.
58
+ * By default (immutable), returns a clone so the original is unchanged.
59
+ * When `.mutable` is set, returns `this` to mutate in place.
60
+ */
61
+ get instance() {
62
+ return this.isMutable ? this : this.clone();
63
+ }
25
64
  /**
26
65
  * Get the default value
27
66
  * Supports lazy evaluation via callbacks
@@ -33,15 +72,17 @@ class BaseValidator {
33
72
  * Determine if value accepts null value
34
73
  */
35
74
  nullable() {
36
- this.isNullable = true;
37
- return this;
75
+ const instance = this.instance;
76
+ instance.isNullable = true;
77
+ return instance;
38
78
  }
39
79
  /**
40
80
  * Explicitly disallow null values after calling nullable
41
81
  */
42
82
  notNullable() {
43
- this.isNullable = false;
44
- return this;
83
+ const instance = this.instance;
84
+ instance.isNullable = false;
85
+ return instance;
45
86
  }
46
87
  /**
47
88
  * Add transformer with optional options
@@ -62,11 +103,33 @@ class BaseValidator {
62
103
  * ```
63
104
  */
64
105
  addTransformer(transform, options = {}) {
106
+ const instance = this.instance;
107
+ instance.addMutableTransformer(transform, options);
108
+ return instance;
109
+ }
110
+ /**
111
+ * Add transformer with optional options
112
+ *
113
+ * @param transform - The transformer callback function
114
+ * @param options - Optional options to pass to the transformer
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * // Without options
119
+ * v.date().addTransformer(data => data.toISOString())
120
+ *
121
+ * // With options
122
+ * v.date().addTransformer(
123
+ * (data, { options }) => dayjs(data).format(options.format),
124
+ * { format: 'YYYY-MM-DD' }
125
+ * )
126
+ * ```
127
+ */
128
+ addMutableTransformer(transform, options = {}) {
65
129
  this.dataTransformers.push({
66
130
  transform,
67
131
  options,
68
132
  });
69
- return this;
70
133
  }
71
134
  /**
72
135
  * Transform the output value - simple one-time transformation
@@ -86,8 +149,7 @@ class BaseValidator {
86
149
  * ```
87
150
  */
88
151
  outputAs(callback) {
89
- this.addTransformer((data, { context }) => callback(data, context));
90
- return this;
152
+ return this.addTransformer((data, { context }) => callback(data, context));
91
153
  }
92
154
  /**
93
155
  * Transform output to JSON string
@@ -120,10 +182,9 @@ class BaseValidator {
120
182
  * @category Transformer
121
183
  */
122
184
  toJSON(indent) {
123
- this.addTransformer((data, { options }) => JSON.stringify(data, null, options.indent), {
185
+ return this.addTransformer((data, { options }) => JSON.stringify(data, null, options.indent), {
124
186
  indent: indent ?? 0,
125
187
  });
126
- return this;
127
188
  }
128
189
  /**
129
190
  * Start data transformation pipeline
@@ -156,26 +217,29 @@ class BaseValidator {
156
217
  * });
157
218
  */
158
219
  attributes(attributes) {
220
+ const instance = this.instance;
159
221
  for (const key in attributes) {
160
- this.attributesText[key] = attributes[key];
222
+ instance.attributesText[key] = attributes[key];
161
223
  }
162
- return this;
224
+ return instance;
163
225
  }
164
226
  /**
165
227
  * Define a lazy getter property for each attribute in the given object and use the config attribute translator
166
228
  */
167
229
  transAttributes(attributes) {
230
+ const instance = this.instance;
168
231
  for (const key in attributes) {
169
- this.translatedAttributes[key] = attributes[key];
232
+ instance.translatedAttributes[key] = attributes[key];
170
233
  }
171
- return this;
234
+ return instance;
172
235
  }
173
236
  /**
174
237
  * Add description to the validator
175
238
  */
176
239
  describe(description) {
177
- this.description = description;
178
- return this;
240
+ const instance = this.instance;
241
+ instance.description = description;
242
+ return instance;
179
243
  }
180
244
  /**
181
245
  * Check if this validator can handle the given value's type
@@ -233,6 +297,8 @@ class BaseValidator {
233
297
  cloned.description = this.description;
234
298
  cloned.attributesText = { ...this.attributesText };
235
299
  cloned.isNullable = this.isNullable;
300
+ cloned.isOptional = this.isOptional;
301
+ cloned.requiredRule = this.requiredRule; // same reference is fine — rule is treated as immutable
236
302
  return cloned;
237
303
  }
238
304
  /**
@@ -263,8 +329,9 @@ class BaseValidator {
263
329
  * ```
264
330
  */
265
331
  omit() {
266
- this.shouldOmit = true;
267
- return this;
332
+ const instance = this.instance;
333
+ instance.shouldOmit = true;
334
+ return instance;
268
335
  }
269
336
  /**
270
337
  * @alias omit
@@ -279,60 +346,58 @@ class BaseValidator {
279
346
  return this.shouldOmit;
280
347
  }
281
348
  /**
282
- * Value must be equal to the given value
283
- */
284
- equal(value, errorMessage) {
285
- const rule = this.addRule(equal.equalRule, errorMessage);
286
- rule.context.options.value = value;
287
- return this;
288
- }
289
- /**
290
- * Value must be the same as another field's value
291
- */
292
- sameAs(field, errorMessage) {
293
- const rule = this.addRule(equalsFieldRules.equalsFieldRule, errorMessage);
294
- rule.context.options.field = field;
295
- rule.context.options.scope = "global";
296
- return this;
297
- }
298
- /**
299
- * Value must be the same as another sibling field's value
349
+ * Add rule to the validator
300
350
  */
301
- sameAsSibling(field, errorMessage) {
302
- const rule = this.addRule(equalsFieldRules.equalsFieldRule, errorMessage);
303
- rule.context.options.field = field;
304
- rule.context.options.scope = "sibling";
305
- return this;
351
+ addRule(rule, errorMessage, options = {}) {
352
+ const instance = this.instance;
353
+ instance.addMutableRule(rule, errorMessage, options);
354
+ return instance;
306
355
  }
307
356
  /**
308
- * Value must be different from another field's value
357
+ * Set the required-condition rule for this field.
358
+ *
359
+ * Unlike addRule(), this does NOT push to rules[]. The rule is stored in the
360
+ * dedicated `requiredRule` slot and is prepended to the validation pipeline
361
+ * at runtime. Only one required rule can be active per field — this replaces
362
+ * any previously set required rule.
363
+ *
364
+ * Also marks the field as not optional (isOptional = false).
365
+ *
366
+ * @example
367
+ * ```ts
368
+ * // Used internally by required(), requiredIf(), requiredWith(), etc.
369
+ * BaseValidator.prototype.required = function(msg) {
370
+ * return this.setRequiredRule(requiredRule, msg);
371
+ * };
372
+ * ```
309
373
  */
310
- differentFrom(field, errorMessage) {
311
- const rule = this.addRule(equalsFieldRules.notEqualsFieldRule, errorMessage);
312
- rule.context.options.field = field;
313
- rule.context.options.scope = "global";
314
- return this;
374
+ setRequiredRule(rule, errorMessage, options = {}) {
375
+ const instance = this.instance;
376
+ instance.isOptional = false;
377
+ instance.requiredRule = instance.createRule(rule, errorMessage, options);
378
+ return instance;
315
379
  }
316
380
  /**
317
- * Value must be different from another sibling field's value
381
+ * Add mutable rule
318
382
  */
319
- differentFromSibling(field, errorMessage) {
320
- const rule = this.addRule(equalsFieldRules.notEqualsFieldRule, errorMessage);
321
- rule.context.options.field = field;
322
- rule.context.options.scope = "sibling";
323
- return this;
383
+ addMutableRule(rule, errorMessage, options = {}) {
384
+ const newRule = this.createRule(rule, errorMessage, options);
385
+ this.rules.push(newRule);
386
+ return newRule;
324
387
  }
325
388
  /**
326
- * Add rule to the validator
389
+ * Create new rule
327
390
  */
328
- addRule(rule, errorMessage) {
391
+ createRule(rule, errorMessage, options = {}) {
329
392
  const newRule = {
330
393
  ...reinforcements.clone(rule),
331
394
  context: {
332
395
  errorMessage,
333
- options: {},
396
+ options,
334
397
  attributesList: this.attributesText,
335
398
  translatedAttributes: this.translatedAttributes,
399
+ translationParams: {},
400
+ translatableParams: {},
336
401
  },
337
402
  };
338
403
  if (errorMessage) {
@@ -341,7 +406,6 @@ class BaseValidator {
341
406
  if (rule.sortOrder === undefined) {
342
407
  newRule.sortOrder = this.rules.length + 1;
343
408
  }
344
- this.rules.push(newRule);
345
409
  return newRule;
346
410
  }
347
411
  /**
@@ -368,18 +432,13 @@ class BaseValidator {
368
432
  */
369
433
  useRule(rule, options) {
370
434
  const { errorMessage, ...ruleOptions } = options || {};
371
- const ruleInstance = this.addRule(rule, errorMessage);
372
- // Assign rule-specific options
373
- if (Object.keys(ruleOptions).length > 0) {
374
- Object.assign(ruleInstance.context.options, ruleOptions);
375
- }
376
- return this;
435
+ return this.addRule(rule, errorMessage, ruleOptions);
377
436
  }
378
437
  /**
379
438
  * Define custom rule
380
439
  */
381
440
  refine(callback) {
382
- this.addRule({
441
+ return this.addRule({
383
442
  name: "custom",
384
443
  async validate(value, context) {
385
444
  const result = await callback(value, context);
@@ -390,12 +449,19 @@ class BaseValidator {
390
449
  return validationHelpers.VALID_RULE;
391
450
  },
392
451
  });
393
- return this;
394
452
  }
395
453
  /**
396
454
  * Add mutator to the validator
397
455
  */
398
456
  addMutator(mutator, options = {}) {
457
+ const instance = this.instance;
458
+ instance.addMutableMutator(mutator, options);
459
+ return instance;
460
+ }
461
+ /**
462
+ * Add mutable mutator
463
+ */
464
+ addMutableMutator(mutator, options = {}) {
399
465
  this.mutators.push({
400
466
  mutate: mutator,
401
467
  context: {
@@ -403,567 +469,14 @@ class BaseValidator {
403
469
  ctx: {},
404
470
  },
405
471
  });
406
- return this;
407
472
  }
408
473
  /**
409
474
  * Set default value for the field
410
475
  */
411
476
  default(value) {
412
- this.defaultValue = value;
413
- return this;
414
- }
415
- // ==================== UNCONDITIONAL STATES ====================
416
- /**
417
- * This value must be present and has a value
418
- */
419
- required(errorMessage) {
420
- this.addRule(required.requiredRule, errorMessage);
421
- return this;
422
- }
423
- /**
424
- * Value must be present but not necessarily has a value
425
- */
426
- present(errorMessage) {
427
- this.addRule(required.presentRule, errorMessage);
428
- return this;
429
- }
430
- /**
431
- * Mark the field as optional, so pass it if it has no value or has a value
432
- * Because this is the default behavior, this method is just syntactic sugar
433
- */
434
- optional() {
435
- return this;
436
- }
437
- // ==================== REQUIRED: BASED ON FIELD PRESENCE ====================
438
- /**
439
- * Value is required if another field exists
440
- */
441
- requiredWith(field, errorMessage) {
442
- const rule = this.addRule(requiredWithRules.requiredWithRule, errorMessage);
443
- rule.context.options.field = field;
444
- rule.context.options.scope = "global";
445
- return this;
446
- }
447
- /**
448
- * Value is required if another sibling field exists
449
- */
450
- requiredWithSibling(field, errorMessage) {
451
- const rule = this.addRule(requiredWithRules.requiredWithRule, errorMessage);
452
- rule.context.options.field = field;
453
- rule.context.options.scope = "sibling";
454
- return this;
455
- }
456
- /**
457
- * Value is required if another field is missing
458
- */
459
- requiredWithout(field, errorMessage) {
460
- const rule = this.addRule(requiredWithoutRules.requiredWithoutRule, errorMessage);
461
- rule.context.options.field = field;
462
- rule.context.options.scope = "global";
463
- return this;
464
- }
465
- /**
466
- * Value is required if another sibling field is missing
467
- */
468
- requiredWithoutSibling(field, errorMessage) {
469
- const rule = this.addRule(requiredWithoutRules.requiredWithoutRule, errorMessage);
470
- rule.context.options.field = field;
471
- rule.context.options.scope = "sibling";
472
- return this;
473
- }
474
- // ==================== REQUIRED: BASED ON FIELD VALUE ====================
475
- /**
476
- * Value is required if another field equals a specific value
477
- */
478
- requiredIf(field, value, errorMessage) {
479
- const rule = this.addRule(requiredIfRules.requiredIfRule, errorMessage);
480
- rule.context.options.field = field;
481
- rule.context.options.value = value;
482
- rule.context.options.scope = "global";
483
- return this;
484
- }
485
- /**
486
- * Value is required if another sibling field equals a specific value
487
- */
488
- requiredIfSibling(field, value, errorMessage) {
489
- const rule = this.addRule(requiredIfRules.requiredIfRule, errorMessage);
490
- rule.context.options.field = field;
491
- rule.context.options.value = value;
492
- rule.context.options.scope = "sibling";
493
- return this;
494
- }
495
- /**
496
- * Value is required unless another field equals a specific value
497
- */
498
- requiredUnless(field, value, errorMessage) {
499
- const rule = this.addRule(requiredUnlessRules.requiredUnlessRule, errorMessage);
500
- rule.context.options.field = field;
501
- rule.context.options.value = value;
502
- rule.context.options.scope = "global";
503
- return this;
504
- }
505
- /**
506
- * Value is required unless another sibling field equals a specific value
507
- */
508
- requiredUnlessSibling(field, value, errorMessage) {
509
- const rule = this.addRule(requiredUnlessRules.requiredUnlessRule, errorMessage);
510
- rule.context.options.field = field;
511
- rule.context.options.value = value;
512
- rule.context.options.scope = "sibling";
513
- return this;
514
- }
515
- // ==================== REQUIRED: BASED ON FIELD EMPTY STATE ====================
516
- /**
517
- * Value is required if another field is empty
518
- */
519
- requiredIfEmpty(field, errorMessage) {
520
- const rule = this.addRule(requiredIfRules.requiredIfEmptyRule, errorMessage);
521
- rule.context.options.field = field;
522
- rule.context.options.scope = "global";
523
- return this;
524
- }
525
- /**
526
- * Value is required if another sibling field is empty
527
- */
528
- requiredIfEmptySibling(field, errorMessage) {
529
- const rule = this.addRule(requiredIfRules.requiredIfEmptyRule, errorMessage);
530
- rule.context.options.field = field;
531
- rule.context.options.scope = "sibling";
532
- return this;
533
- }
534
- /**
535
- * Value is required if another field is not empty
536
- */
537
- requiredIfNotEmpty(field, errorMessage) {
538
- const rule = this.addRule(requiredIfRules.requiredIfNotEmptyRule, errorMessage);
539
- rule.context.options.field = field;
540
- rule.context.options.scope = "global";
541
- return this;
542
- }
543
- /**
544
- * Value is required if another sibling field is not empty
545
- */
546
- requiredIfNotEmptySibling(field, errorMessage) {
547
- const rule = this.addRule(requiredIfRules.requiredIfNotEmptyRule, errorMessage);
548
- rule.context.options.field = field;
549
- rule.context.options.scope = "sibling";
550
- return this;
551
- }
552
- // ==================== REQUIRED: BASED ON MULTIPLE FIELDS EMPTY STATE ====================
553
- /**
554
- * Value is required if ALL specified fields are empty
555
- */
556
- requiredIfAllEmpty(fields, errorMessage) {
557
- const rule = this.addRule(requiredIfRules.requiredIfAllEmptyRule, errorMessage);
558
- rule.context.options.fields = fields;
559
- rule.context.options.scope = "global";
560
- return this;
561
- }
562
- /**
563
- * Value is required if ALL specified sibling fields are empty
564
- */
565
- requiredIfAllEmptySiblings(fields, errorMessage) {
566
- const rule = this.addRule(requiredIfRules.requiredIfAllEmptyRule, errorMessage);
567
- rule.context.options.fields = fields;
568
- rule.context.options.scope = "sibling";
569
- return this;
570
- }
571
- /**
572
- * Value is required if ANY of the specified fields is empty
573
- */
574
- requiredIfAnyEmpty(fields, errorMessage) {
575
- const rule = this.addRule(requiredIfRules.requiredIfAnyEmptyRule, errorMessage);
576
- rule.context.options.fields = fields;
577
- rule.context.options.scope = "global";
578
- return this;
579
- }
580
- /**
581
- * Value is required if ANY of the specified sibling fields is empty
582
- */
583
- requiredIfAnyEmptySiblings(fields, errorMessage) {
584
- const rule = this.addRule(requiredIfRules.requiredIfAnyEmptyRule, errorMessage);
585
- rule.context.options.fields = fields;
586
- rule.context.options.scope = "sibling";
587
- return this;
588
- }
589
- /**
590
- * Value is required if ALL specified fields are NOT empty
591
- */
592
- requiredIfAllNotEmpty(fields, errorMessage) {
593
- const rule = this.addRule(requiredIfRules.requiredIfAllNotEmptyRule, errorMessage);
594
- rule.context.options.fields = fields;
595
- rule.context.options.scope = "global";
596
- return this;
597
- }
598
- /**
599
- * Value is required if ALL specified sibling fields are NOT empty
600
- */
601
- requiredIfAllNotEmptySiblings(fields, errorMessage) {
602
- const rule = this.addRule(requiredIfRules.requiredIfAllNotEmptyRule, errorMessage);
603
- rule.context.options.fields = fields;
604
- rule.context.options.scope = "sibling";
605
- return this;
606
- }
607
- /**
608
- * Value is required if ANY of the specified fields is NOT empty
609
- */
610
- requiredIfAnyNotEmpty(fields, errorMessage) {
611
- const rule = this.addRule(requiredIfRules.requiredIfAnyNotEmptyRule, errorMessage);
612
- rule.context.options.fields = fields;
613
- rule.context.options.scope = "global";
614
- return this;
615
- }
616
- /**
617
- * Value is required if ANY of the specified sibling fields is NOT empty
618
- */
619
- requiredIfAnyNotEmptySiblings(fields, errorMessage) {
620
- const rule = this.addRule(requiredIfRules.requiredIfAnyNotEmptyRule, errorMessage);
621
- rule.context.options.fields = fields;
622
- rule.context.options.scope = "sibling";
623
- return this;
624
- }
625
- /**
626
- * Value is required if another field's value is in the given array
627
- */
628
- requiredIfIn(field, values, errorMessage) {
629
- const rule = this.addRule(requiredIfRules.requiredIfInRule, errorMessage);
630
- rule.context.options.field = field;
631
- rule.context.options.values = values;
632
- rule.context.options.scope = "global";
633
- return this;
634
- }
635
- /**
636
- * Value is required if another sibling field's value is in the given array
637
- */
638
- requiredIfInSibling(field, values, errorMessage) {
639
- const rule = this.addRule(requiredIfRules.requiredIfInRule, errorMessage);
640
- rule.context.options.field = field;
641
- rule.context.options.values = values;
642
- rule.context.options.scope = "sibling";
643
- return this;
644
- }
645
- /**
646
- * Value is required if another field's value is NOT in the given array
647
- */
648
- requiredIfNotIn(field, values, errorMessage) {
649
- const rule = this.addRule(requiredIfRules.requiredIfNotInRule, errorMessage);
650
- rule.context.options.field = field;
651
- rule.context.options.values = values;
652
- rule.context.options.scope = "global";
653
- return this;
654
- }
655
- /**
656
- * Value is required if another sibling field's value is NOT in the given array
657
- */
658
- requiredIfNotInSibling(field, values, errorMessage) {
659
- const rule = this.addRule(requiredIfRules.requiredIfNotInRule, errorMessage);
660
- rule.context.options.field = field;
661
- rule.context.options.values = values;
662
- rule.context.options.scope = "sibling";
663
- return this;
664
- }
665
- // ==================== REQUIRED: BASED ON MULTIPLE FIELDS (ALL) ====================
666
- /**
667
- * Value is required if all specified fields exist
668
- */
669
- requiredWithAll(fields, errorMessage) {
670
- const rule = this.addRule(requiredWithRules.requiredWithAllRule, errorMessage);
671
- rule.context.options.fields = fields;
672
- rule.context.options.scope = "global";
673
- return this;
674
- }
675
- /**
676
- * Value is required if all specified sibling fields exist
677
- */
678
- requiredWithAllSiblings(fields, errorMessage) {
679
- const rule = this.addRule(requiredWithRules.requiredWithAllRule, errorMessage);
680
- rule.context.options.fields = fields;
681
- rule.context.options.scope = "sibling";
682
- return this;
683
- }
684
- /**
685
- * Value is required if all specified fields are missing
686
- */
687
- requiredWithoutAll(fields, errorMessage) {
688
- const rule = this.addRule(requiredWithoutRules.requiredWithoutAllRule, errorMessage);
689
- rule.context.options.fields = fields;
690
- rule.context.options.scope = "global";
691
- return this;
692
- }
693
- /**
694
- * Value is required if all specified sibling fields are missing
695
- */
696
- requiredWithoutAllSiblings(fields, errorMessage) {
697
- const rule = this.addRule(requiredWithoutRules.requiredWithoutAllRule, errorMessage);
698
- rule.context.options.fields = fields;
699
- rule.context.options.scope = "sibling";
700
- return this;
701
- }
702
- // ==================== REQUIRED: BASED ON MULTIPLE FIELDS (ANY) ====================
703
- /**
704
- * Value is required if any of the specified fields exists
705
- */
706
- requiredWithAny(fields, errorMessage) {
707
- const rule = this.addRule(requiredWithRules.requiredWithAnyRule, errorMessage);
708
- rule.context.options.fields = fields;
709
- rule.context.options.scope = "global";
710
- return this;
711
- }
712
- /**
713
- * Value is required if any of the specified sibling fields exists
714
- */
715
- requiredWithAnySiblings(fields, errorMessage) {
716
- const rule = this.addRule(requiredWithRules.requiredWithAnyRule, errorMessage);
717
- rule.context.options.fields = fields;
718
- rule.context.options.scope = "sibling";
719
- return this;
720
- }
721
- /**
722
- * Value is required if any of the specified fields is missing
723
- */
724
- requiredWithoutAny(fields, errorMessage) {
725
- const rule = this.addRule(requiredWithoutRules.requiredWithoutAnyRule, errorMessage);
726
- rule.context.options.fields = fields;
727
- rule.context.options.scope = "global";
728
- return this;
729
- }
730
- /**
731
- * Value is required if any of the specified sibling fields is missing
732
- */
733
- requiredWithoutAnySiblings(fields, errorMessage) {
734
- const rule = this.addRule(requiredWithoutRules.requiredWithoutAnyRule, errorMessage);
735
- rule.context.options.fields = fields;
736
- rule.context.options.scope = "sibling";
737
- return this;
738
- }
739
- // ==================== PRESENT: BASED ON FIELD PRESENCE ====================
740
- /**
741
- * Field must be present if another field exists
742
- */
743
- presentWith(field, errorMessage) {
744
- const rule = this.addRule(presentWithRules.presentWithRule, errorMessage);
745
- rule.context.options.field = field;
746
- rule.context.options.scope = "global";
747
- return this;
748
- }
749
- /**
750
- * Field must be present if another sibling field exists
751
- */
752
- presentWithSibling(field, errorMessage) {
753
- const rule = this.addRule(presentWithRules.presentWithRule, errorMessage);
754
- rule.context.options.field = field;
755
- rule.context.options.scope = "sibling";
756
- return this;
757
- }
758
- /**
759
- * Field must be present if another field is missing
760
- */
761
- presentWithout(field, errorMessage) {
762
- const rule = this.addRule(presentWithoutRules.presentWithoutRule, errorMessage);
763
- rule.context.options.field = field;
764
- rule.context.options.scope = "global";
765
- return this;
766
- }
767
- /**
768
- * Field must be present if another sibling field is missing
769
- */
770
- presentWithoutSibling(field, errorMessage) {
771
- const rule = this.addRule(presentWithoutRules.presentWithoutRule, errorMessage);
772
- rule.context.options.field = field;
773
- rule.context.options.scope = "sibling";
774
- return this;
775
- }
776
- // ==================== PRESENT: BASED ON FIELD VALUE ====================
777
- /**
778
- * Field must be present if another field equals a specific value
779
- */
780
- presentIf(field, value, errorMessage) {
781
- const rule = this.addRule(presentIfRules.presentIfRule, errorMessage);
782
- rule.context.options.field = field;
783
- rule.context.options.value = value;
784
- rule.context.options.scope = "global";
785
- return this;
786
- }
787
- /**
788
- * Field must be present if another sibling field equals a specific value
789
- */
790
- presentIfSibling(field, value, errorMessage) {
791
- const rule = this.addRule(presentIfRules.presentIfRule, errorMessage);
792
- rule.context.options.field = field;
793
- rule.context.options.value = value;
794
- rule.context.options.scope = "sibling";
795
- return this;
796
- }
797
- /**
798
- * Field must be present unless another field equals a specific value
799
- */
800
- presentUnless(field, value, errorMessage) {
801
- const rule = this.addRule(presentUnlessRules.presentUnlessRule, errorMessage);
802
- rule.context.options.field = field;
803
- rule.context.options.value = value;
804
- rule.context.options.scope = "global";
805
- return this;
806
- }
807
- /**
808
- * Field must be present unless another sibling field equals a specific value
809
- */
810
- presentUnlessSibling(field, value, errorMessage) {
811
- const rule = this.addRule(presentUnlessRules.presentUnlessRule, errorMessage);
812
- rule.context.options.field = field;
813
- rule.context.options.value = value;
814
- rule.context.options.scope = "sibling";
815
- return this;
816
- }
817
- // ==================== PRESENT: BASED ON FIELD EMPTY STATE ====================
818
- /**
819
- * Field must be present if another field is empty
820
- */
821
- presentIfEmpty(field, errorMessage) {
822
- const rule = this.addRule(presentIfRules.presentIfEmptyRule, errorMessage);
823
- rule.context.options.field = field;
824
- rule.context.options.scope = "global";
825
- return this;
826
- }
827
- /**
828
- * Field must be present if another sibling field is empty
829
- */
830
- presentIfEmptySibling(field, errorMessage) {
831
- const rule = this.addRule(presentIfRules.presentIfEmptyRule, errorMessage);
832
- rule.context.options.field = field;
833
- rule.context.options.scope = "sibling";
834
- return this;
835
- }
836
- /**
837
- * Field must be present if another field is not empty
838
- */
839
- presentIfNotEmpty(field, errorMessage) {
840
- const rule = this.addRule(presentIfRules.presentIfNotEmptyRule, errorMessage);
841
- rule.context.options.field = field;
842
- rule.context.options.scope = "global";
843
- return this;
844
- }
845
- /**
846
- * Field must be present if another sibling field is not empty
847
- */
848
- presentIfNotEmptySibling(field, errorMessage) {
849
- const rule = this.addRule(presentIfRules.presentIfNotEmptyRule, errorMessage);
850
- rule.context.options.field = field;
851
- rule.context.options.scope = "sibling";
852
- return this;
853
- }
854
- /**
855
- * Field must be present if another field's value is in the given array
856
- */
857
- presentIfIn(field, values, errorMessage) {
858
- const rule = this.addRule(presentIfRules.presentIfInRule, errorMessage);
859
- rule.context.options.field = field;
860
- rule.context.options.values = values;
861
- rule.context.options.scope = "global";
862
- return this;
863
- }
864
- /**
865
- * Field must be present if another sibling field's value is in the given array
866
- */
867
- presentIfInSibling(field, values, errorMessage) {
868
- const rule = this.addRule(presentIfRules.presentIfInRule, errorMessage);
869
- rule.context.options.field = field;
870
- rule.context.options.values = values;
871
- rule.context.options.scope = "sibling";
872
- return this;
873
- }
874
- /**
875
- * Field must be present if another field's value is NOT in the given array
876
- */
877
- presentIfNotIn(field, values, errorMessage) {
878
- const rule = this.addRule(presentIfRules.presentIfNotInRule, errorMessage);
879
- rule.context.options.field = field;
880
- rule.context.options.values = values;
881
- rule.context.options.scope = "global";
882
- return this;
883
- }
884
- /**
885
- * Field must be present if another sibling field's value is NOT in the given array
886
- */
887
- presentIfNotInSibling(field, values, errorMessage) {
888
- const rule = this.addRule(presentIfRules.presentIfNotInRule, errorMessage);
889
- rule.context.options.field = field;
890
- rule.context.options.values = values;
891
- rule.context.options.scope = "sibling";
892
- return this;
893
- }
894
- // ==================== PRESENT: BASED ON MULTIPLE FIELDS (ALL) ====================
895
- /**
896
- * Field must be present if all specified fields exist
897
- */
898
- presentWithAll(fields, errorMessage) {
899
- const rule = this.addRule(presentWithRules.presentWithAllRule, errorMessage);
900
- rule.context.options.fields = fields;
901
- rule.context.options.scope = "global";
902
- return this;
903
- }
904
- /**
905
- * Field must be present if all specified sibling fields exist
906
- */
907
- presentWithAllSiblings(fields, errorMessage) {
908
- const rule = this.addRule(presentWithRules.presentWithAllRule, errorMessage);
909
- rule.context.options.fields = fields;
910
- rule.context.options.scope = "sibling";
911
- return this;
912
- }
913
- /**
914
- * Field must be present if all specified fields are missing
915
- */
916
- presentWithoutAll(fields, errorMessage) {
917
- const rule = this.addRule(presentWithoutRules.presentWithoutAllRule, errorMessage);
918
- rule.context.options.fields = fields;
919
- rule.context.options.scope = "global";
920
- return this;
921
- }
922
- /**
923
- * Field must be present if all specified sibling fields are missing
924
- */
925
- presentWithoutAllSiblings(fields, errorMessage) {
926
- const rule = this.addRule(presentWithoutRules.presentWithoutAllRule, errorMessage);
927
- rule.context.options.fields = fields;
928
- rule.context.options.scope = "sibling";
929
- return this;
930
- }
931
- // ==================== PRESENT: BASED ON MULTIPLE FIELDS (ANY) ====================
932
- /**
933
- * Field must be present if any of the specified fields exists
934
- */
935
- presentWithAny(fields, errorMessage) {
936
- const rule = this.addRule(presentWithRules.presentWithAnyRule, errorMessage);
937
- rule.context.options.fields = fields;
938
- rule.context.options.scope = "global";
939
- return this;
940
- }
941
- /**
942
- * Field must be present if any of the specified sibling fields exists
943
- */
944
- presentWithAnySiblings(fields, errorMessage) {
945
- const rule = this.addRule(presentWithRules.presentWithAnyRule, errorMessage);
946
- rule.context.options.fields = fields;
947
- rule.context.options.scope = "sibling";
948
- return this;
949
- }
950
- /**
951
- * Field must be present if any of the specified fields is missing
952
- */
953
- presentWithoutAny(fields, errorMessage) {
954
- const rule = this.addRule(presentWithoutRules.presentWithoutAnyRule, errorMessage);
955
- rule.context.options.fields = fields;
956
- rule.context.options.scope = "global";
957
- return this;
958
- }
959
- /**
960
- * Field must be present if any of the specified sibling fields is missing
961
- */
962
- presentWithoutAnySiblings(fields, errorMessage) {
963
- const rule = this.addRule(presentWithoutRules.presentWithoutAnyRule, errorMessage);
964
- rule.context.options.fields = fields;
965
- rule.context.options.scope = "sibling";
966
- return this;
477
+ const instance = this.instance;
478
+ instance.defaultValue = value;
479
+ return instance;
967
480
  }
968
481
  /**
969
482
  * Mutate the data
@@ -976,211 +489,13 @@ class BaseValidator {
976
489
  }
977
490
  return mutatedData;
978
491
  }
979
- /**
980
- * Value is forbidden to be present
981
- */
982
- forbidden(errorMessage) {
983
- this.addRule(forbidden.forbiddenRule, errorMessage);
984
- return this;
985
- }
986
- /**
987
- * Value is forbidden if another field equals a specific value (global scope)
988
- */
989
- forbiddenIf(field, value, errorMessage) {
990
- const rule = this.addRule(forbiddenIfRules.forbiddenIfRule, errorMessage);
991
- rule.context.options.field = field;
992
- rule.context.options.value = value;
993
- rule.context.options.scope = "global";
994
- return this;
995
- }
996
- /**
997
- * Value is forbidden if another field equals a specific value (sibling scope)
998
- */
999
- forbiddenIfSibling(field, value, errorMessage) {
1000
- const rule = this.addRule(forbiddenIfRules.forbiddenIfRule, errorMessage);
1001
- rule.context.options.field = field;
1002
- rule.context.options.value = value;
1003
- rule.context.options.scope = "sibling";
1004
- return this;
1005
- }
1006
- /**
1007
- * Value is forbidden if another field does NOT equal a specific value (global scope)
1008
- */
1009
- forbiddenIfNot(field, value, errorMessage) {
1010
- const rule = this.addRule(forbiddenIfRules.forbiddenIfNotRule, errorMessage);
1011
- rule.context.options.field = field;
1012
- rule.context.options.value = value;
1013
- rule.context.options.scope = "global";
1014
- return this;
1015
- }
1016
- /**
1017
- * Value is forbidden if another field does NOT equal a specific value (sibling scope)
1018
- */
1019
- forbiddenIfNotSibling(field, value, errorMessage) {
1020
- const rule = this.addRule(forbiddenIfRules.forbiddenIfNotRule, errorMessage);
1021
- rule.context.options.field = field;
1022
- rule.context.options.value = value;
1023
- rule.context.options.scope = "sibling";
1024
- return this;
1025
- }
1026
- /**
1027
- * Value is forbidden if another field is empty (global scope)
1028
- */
1029
- forbiddenIfEmpty(field, errorMessage) {
1030
- const rule = this.addRule(forbiddenIfRules.forbiddenIfEmptyRule, errorMessage);
1031
- rule.context.options.field = field;
1032
- rule.context.options.scope = "global";
1033
- return this;
1034
- }
1035
- /**
1036
- * Value is forbidden if another field is empty (sibling scope)
1037
- */
1038
- forbiddenIfEmptySibling(field, errorMessage) {
1039
- const rule = this.addRule(forbiddenIfRules.forbiddenIfEmptyRule, errorMessage);
1040
- rule.context.options.field = field;
1041
- rule.context.options.scope = "sibling";
1042
- return this;
1043
- }
1044
- /**
1045
- * Value is forbidden if another field is not empty (global scope)
1046
- */
1047
- forbiddenIfNotEmpty(field, errorMessage) {
1048
- const rule = this.addRule(forbiddenIfRules.forbiddenIfNotEmptyRule, errorMessage);
1049
- rule.context.options.field = field;
1050
- rule.context.options.scope = "global";
1051
- return this;
1052
- }
1053
- /**
1054
- * Value is forbidden if another field is not empty (sibling scope)
1055
- */
1056
- forbiddenIfNotEmptySibling(field, errorMessage) {
1057
- const rule = this.addRule(forbiddenIfRules.forbiddenIfNotEmptyRule, errorMessage);
1058
- rule.context.options.field = field;
1059
- rule.context.options.scope = "sibling";
1060
- return this;
1061
- }
1062
- /**
1063
- * Value is forbidden if another field's value is in the given array (global scope)
1064
- */
1065
- forbiddenIfIn(field, values, errorMessage) {
1066
- const rule = this.addRule(forbiddenIfRules.forbiddenIfInRule, errorMessage);
1067
- rule.context.options.field = field;
1068
- rule.context.options.values = values;
1069
- rule.context.options.scope = "global";
1070
- return this;
1071
- }
1072
- /**
1073
- * Value is forbidden if another field's value is in the given array (sibling scope)
1074
- */
1075
- forbiddenIfInSibling(field, values, errorMessage) {
1076
- const rule = this.addRule(forbiddenIfRules.forbiddenIfInRule, errorMessage);
1077
- rule.context.options.field = field;
1078
- rule.context.options.values = values;
1079
- rule.context.options.scope = "sibling";
1080
- return this;
1081
- }
1082
- /**
1083
- * Value is forbidden if another field's value is NOT in the given array (global scope)
1084
- */
1085
- forbiddenIfNotIn(field, values, errorMessage) {
1086
- const rule = this.addRule(forbiddenIfRules.forbiddenIfNotInRule, errorMessage);
1087
- rule.context.options.field = field;
1088
- rule.context.options.values = values;
1089
- rule.context.options.scope = "global";
1090
- return this;
1091
- }
1092
- /**
1093
- * Value is forbidden if another field's value is NOT in the given array (sibling scope)
1094
- */
1095
- forbiddenIfNotInSibling(field, values, errorMessage) {
1096
- const rule = this.addRule(forbiddenIfRules.forbiddenIfNotInRule, errorMessage);
1097
- rule.context.options.field = field;
1098
- rule.context.options.values = values;
1099
- rule.context.options.scope = "sibling";
1100
- return this;
1101
- }
1102
- /**
1103
- * Apply different validation rules based on another field's value (global scope)
1104
- *
1105
- * Use this when you need to apply completely different validators
1106
- * based on another field's value (not just required/optional).
1107
- *
1108
- * @param field - Field name to check (can be nested with dot notation)
1109
- * @param options - Validation options per field value
1110
- *
1111
- * @example
1112
- * ```ts
1113
- * // Different allowed values based on user type
1114
- * v.object({
1115
- * userType: v.string().in(['admin', 'user']),
1116
- * role: v.string().when('userType', {
1117
- * is: {
1118
- * admin: v.string().in(['super', 'moderator']),
1119
- * user: v.string().in(['member', 'guest'])
1120
- * },
1121
- * otherwise: v.string().optional()
1122
- * })
1123
- * })
1124
- *
1125
- * // Different validation rules based on type
1126
- * v.object({
1127
- * contactType: v.string().in(['email', 'phone']),
1128
- * contact: v.string().when('contactType', {
1129
- * is: {
1130
- * email: v.string().email(),
1131
- * phone: v.string().pattern(/^\d{10}$/)
1132
- * }
1133
- * })
1134
- * })
1135
- * ```
1136
- * @category Conditional Validation
1137
- */
1138
- when(field, options) {
1139
- const rule = this.addRule(when.whenRule);
1140
- rule.context.options.field = field;
1141
- rule.context.options.is = options.is;
1142
- rule.context.options.otherwise = options.otherwise;
1143
- rule.context.options.scope = "global";
1144
- return this;
1145
- }
1146
- /**
1147
- * Apply different validation rules based on sibling field's value
1148
- *
1149
- * Use this for nested objects where you need to check a field
1150
- * within the same parent object.
1151
- *
1152
- * @param siblingField - Sibling field name to check
1153
- * @param options - Validation options per field value
1154
- *
1155
- * @example
1156
- * ```ts
1157
- * // Array of users with role-based permissions
1158
- * v.array(v.object({
1159
- * userType: v.string().in(['admin', 'user']),
1160
- * permissions: v.string().whenSibling('userType', {
1161
- * is: {
1162
- * admin: v.string().in(['read', 'write', 'delete']),
1163
- * user: v.string().in(['read'])
1164
- * }
1165
- * })
1166
- * }))
1167
- * ```
1168
- * @category Conditional Validation
1169
- */
1170
- whenSibling(siblingField, options) {
1171
- const rule = this.addRule(when.whenRule);
1172
- rule.context.options.field = siblingField;
1173
- rule.context.options.is = options.is;
1174
- rule.context.options.otherwise = options.otherwise;
1175
- rule.context.options.scope = "sibling";
1176
- return this;
1177
- }
1178
492
  /**
1179
493
  * Set the label for the validator that will be matching the :input attribute
1180
494
  */
1181
495
  label(label) {
1182
- this.attributesText.input = label;
1183
- return this;
496
+ const instance = this.instance;
497
+ instance.attributesText.input = label;
498
+ return instance;
1184
499
  }
1185
500
  /**
1186
501
  * Validate the data
@@ -1189,14 +504,17 @@ class BaseValidator {
1189
504
  if (data === null && this.isNullable) {
1190
505
  return { isValid: true, errors: [], data: null };
1191
506
  }
1192
- const valueForMutation = data ?? this.defaultValue;
1193
- const mutatedData = await this.mutate(valueForMutation, context);
1194
- const valueForRules = valueForMutation;
507
+ const valueForRules = data ?? this.getDefaultValue();
508
+ const mutatedData = await this.mutate(valueForRules, context);
1195
509
  const errors = [];
1196
510
  let isValid = true;
1197
511
  const isFirstErrorOnly = context.configurations?.firstErrorOnly ?? true;
1198
512
  const isEmpty = isEmptyValue.isEmptyValue(valueForRules);
1199
- for (const rule of this.rules) {
513
+ console.log("isEmpty", isEmpty, valueForRules);
514
+ // Prepend the required-condition rule if set, so it always runs first.
515
+ // requiredRule has requiresValue = false so it runs even on empty values.
516
+ const rulesToRun = this.requiredRule ? [this.requiredRule, ...this.rules] : this.rules;
517
+ for (const rule of rulesToRun) {
1200
518
  if ((rule.requiresValue ?? true) && isEmpty)
1201
519
  continue;
1202
520
  this.setRuleAttributesList(rule);