@warlock.js/seal 3.0.14

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 (642) hide show
  1. package/README.md +373 -0
  2. package/cjs/config.d.ts +48 -0
  3. package/cjs/config.d.ts.map +1 -0
  4. package/cjs/config.js +42 -0
  5. package/cjs/config.js.map +1 -0
  6. package/cjs/factory/index.d.ts +3 -0
  7. package/cjs/factory/index.d.ts.map +1 -0
  8. package/cjs/factory/validate.d.ts +8 -0
  9. package/cjs/factory/validate.d.ts.map +1 -0
  10. package/cjs/factory/validate.js +21 -0
  11. package/cjs/factory/validate.js.map +1 -0
  12. package/cjs/factory/validators.d.ts +32 -0
  13. package/cjs/factory/validators.d.ts.map +1 -0
  14. package/cjs/factory/validators.js +38 -0
  15. package/cjs/factory/validators.js.map +1 -0
  16. package/cjs/helpers/date-helpers.d.ts +16 -0
  17. package/cjs/helpers/date-helpers.d.ts.map +1 -0
  18. package/cjs/helpers/date-helpers.js +25 -0
  19. package/cjs/helpers/date-helpers.js.map +1 -0
  20. package/cjs/helpers/get-field-value.d.ts +37 -0
  21. package/cjs/helpers/get-field-value.d.ts.map +1 -0
  22. package/cjs/helpers/get-field-value.js +40 -0
  23. package/cjs/helpers/get-field-value.js.map +1 -0
  24. package/cjs/helpers/index.d.ts +5 -0
  25. package/cjs/helpers/index.d.ts.map +1 -0
  26. package/cjs/helpers/path-helpers.d.ts +5 -0
  27. package/cjs/helpers/path-helpers.d.ts.map +1 -0
  28. package/cjs/helpers/path-helpers.js +8 -0
  29. package/cjs/helpers/path-helpers.js.map +1 -0
  30. package/cjs/helpers/validation-helpers.d.ts +4 -0
  31. package/cjs/helpers/validation-helpers.d.ts.map +1 -0
  32. package/cjs/helpers/validation-helpers.js +39 -0
  33. package/cjs/helpers/validation-helpers.js.map +1 -0
  34. package/cjs/index.d.ts +29 -0
  35. package/cjs/index.d.ts.map +1 -0
  36. package/cjs/index.js +1 -0
  37. package/cjs/index.js.map +1 -0
  38. package/cjs/mutators/array-mutators.d.ts +12 -0
  39. package/cjs/mutators/array-mutators.d.ts.map +1 -0
  40. package/cjs/mutators/array-mutators.js +37 -0
  41. package/cjs/mutators/array-mutators.js.map +1 -0
  42. package/cjs/mutators/date-mutators.d.ts +39 -0
  43. package/cjs/mutators/date-mutators.d.ts.map +1 -0
  44. package/cjs/mutators/date-mutators.js +120 -0
  45. package/cjs/mutators/date-mutators.js.map +1 -0
  46. package/cjs/mutators/index.d.ts +6 -0
  47. package/cjs/mutators/index.d.ts.map +1 -0
  48. package/cjs/mutators/number-mutators.d.ts +8 -0
  49. package/cjs/mutators/number-mutators.d.ts.map +1 -0
  50. package/cjs/mutators/number-mutators.js +18 -0
  51. package/cjs/mutators/number-mutators.js.map +1 -0
  52. package/cjs/mutators/object-mutators.d.ts +8 -0
  53. package/cjs/mutators/object-mutators.d.ts.map +1 -0
  54. package/cjs/mutators/object-mutators.js +50 -0
  55. package/cjs/mutators/object-mutators.js.map +1 -0
  56. package/cjs/mutators/string-mutators.d.ts +72 -0
  57. package/cjs/mutators/string-mutators.d.ts.map +1 -0
  58. package/cjs/mutators/string-mutators.js +193 -0
  59. package/cjs/mutators/string-mutators.js.map +1 -0
  60. package/cjs/plugins/index.d.ts +7 -0
  61. package/cjs/plugins/index.d.ts.map +1 -0
  62. package/cjs/plugins/plugin-system.d.ts +71 -0
  63. package/cjs/plugins/plugin-system.d.ts.map +1 -0
  64. package/cjs/plugins/plugin-system.js +68 -0
  65. package/cjs/plugins/plugin-system.js.map +1 -0
  66. package/cjs/rules/array/array-rules.d.ts +12 -0
  67. package/cjs/rules/array/array-rules.d.ts.map +1 -0
  68. package/cjs/rules/array/array-rules.js +44 -0
  69. package/cjs/rules/array/array-rules.js.map +1 -0
  70. package/cjs/rules/array/index.d.ts +2 -0
  71. package/cjs/rules/array/index.d.ts.map +1 -0
  72. package/cjs/rules/color/color-rules.d.ts +30 -0
  73. package/cjs/rules/color/color-rules.d.ts.map +1 -0
  74. package/cjs/rules/color/color-rules.js +120 -0
  75. package/cjs/rules/color/color-rules.js.map +1 -0
  76. package/cjs/rules/color/index.d.ts +2 -0
  77. package/cjs/rules/color/index.d.ts.map +1 -0
  78. package/cjs/rules/common/enum.d.ts +26 -0
  79. package/cjs/rules/common/enum.d.ts.map +1 -0
  80. package/cjs/rules/common/enum.js +55 -0
  81. package/cjs/rules/common/enum.js.map +1 -0
  82. package/cjs/rules/common/equals-field-rules.d.ts +18 -0
  83. package/cjs/rules/common/equals-field-rules.d.ts.map +1 -0
  84. package/cjs/rules/common/equals-field-rules.js +38 -0
  85. package/cjs/rules/common/equals-field-rules.js.map +1 -0
  86. package/cjs/rules/common/index.d.ts +5 -0
  87. package/cjs/rules/common/index.d.ts.map +1 -0
  88. package/cjs/rules/common/type-rules.d.ts +34 -0
  89. package/cjs/rules/common/type-rules.d.ts.map +1 -0
  90. package/cjs/rules/common/type-rules.js +104 -0
  91. package/cjs/rules/common/type-rules.js.map +1 -0
  92. package/cjs/rules/common/unknown-key.d.ts +9 -0
  93. package/cjs/rules/common/unknown-key.d.ts.map +1 -0
  94. package/cjs/rules/common/unknown-key.js +20 -0
  95. package/cjs/rules/common/unknown-key.js.map +1 -0
  96. package/cjs/rules/conditional/index.d.ts +9 -0
  97. package/cjs/rules/conditional/index.d.ts.map +1 -0
  98. package/cjs/rules/conditional/present-if-rules.d.ts +45 -0
  99. package/cjs/rules/conditional/present-if-rules.d.ts.map +1 -0
  100. package/cjs/rules/conditional/present-if-rules.js +98 -0
  101. package/cjs/rules/conditional/present-if-rules.js.map +1 -0
  102. package/cjs/rules/conditional/present-unless-rules.d.ts +11 -0
  103. package/cjs/rules/conditional/present-unless-rules.d.ts.map +1 -0
  104. package/cjs/rules/conditional/present-unless-rules.js +20 -0
  105. package/cjs/rules/conditional/present-unless-rules.js.map +1 -0
  106. package/cjs/rules/conditional/present-with-rules.d.ts +26 -0
  107. package/cjs/rules/conditional/present-with-rules.d.ts.map +1 -0
  108. package/cjs/rules/conditional/present-with-rules.js +63 -0
  109. package/cjs/rules/conditional/present-with-rules.js.map +1 -0
  110. package/cjs/rules/conditional/present-without-rules.d.ts +26 -0
  111. package/cjs/rules/conditional/present-without-rules.d.ts.map +1 -0
  112. package/cjs/rules/conditional/present-without-rules.js +63 -0
  113. package/cjs/rules/conditional/present-without-rules.js.map +1 -0
  114. package/cjs/rules/conditional/required-if-rules.d.ts +45 -0
  115. package/cjs/rules/conditional/required-if-rules.d.ts.map +1 -0
  116. package/cjs/rules/conditional/required-if-rules.js +98 -0
  117. package/cjs/rules/conditional/required-if-rules.js.map +1 -0
  118. package/cjs/rules/conditional/required-unless-rules.d.ts +11 -0
  119. package/cjs/rules/conditional/required-unless-rules.d.ts.map +1 -0
  120. package/cjs/rules/conditional/required-unless-rules.js +20 -0
  121. package/cjs/rules/conditional/required-unless-rules.js.map +1 -0
  122. package/cjs/rules/conditional/required-with-rules.d.ts +26 -0
  123. package/cjs/rules/conditional/required-with-rules.d.ts.map +1 -0
  124. package/cjs/rules/conditional/required-with-rules.js +63 -0
  125. package/cjs/rules/conditional/required-with-rules.js.map +1 -0
  126. package/cjs/rules/conditional/required-without-rules.d.ts +26 -0
  127. package/cjs/rules/conditional/required-without-rules.d.ts.map +1 -0
  128. package/cjs/rules/conditional/required-without-rules.js +63 -0
  129. package/cjs/rules/conditional/required-without-rules.js.map +1 -0
  130. package/cjs/rules/core/equal.d.ts +8 -0
  131. package/cjs/rules/core/equal.d.ts.map +1 -0
  132. package/cjs/rules/core/equal.js +13 -0
  133. package/cjs/rules/core/equal.js.map +1 -0
  134. package/cjs/rules/core/forbidden.d.ts +6 -0
  135. package/cjs/rules/core/forbidden.d.ts.map +1 -0
  136. package/cjs/rules/core/forbidden.js +13 -0
  137. package/cjs/rules/core/forbidden.js.map +1 -0
  138. package/cjs/rules/core/index.d.ts +5 -0
  139. package/cjs/rules/core/index.d.ts.map +1 -0
  140. package/cjs/rules/core/required.d.ts +11 -0
  141. package/cjs/rules/core/required.d.ts.map +1 -0
  142. package/cjs/rules/core/required.js +31 -0
  143. package/cjs/rules/core/required.js.map +1 -0
  144. package/cjs/rules/core/when.d.ts +6 -0
  145. package/cjs/rules/core/when.d.ts.map +1 -0
  146. package/cjs/rules/core/when.js +40 -0
  147. package/cjs/rules/core/when.js.map +1 -0
  148. package/cjs/rules/date/date-comparison-rules.d.ts +25 -0
  149. package/cjs/rules/date/date-comparison-rules.d.ts.map +1 -0
  150. package/cjs/rules/date/date-comparison-rules.js +78 -0
  151. package/cjs/rules/date/date-comparison-rules.js.map +1 -0
  152. package/cjs/rules/date/date-day-rules.d.ts +21 -0
  153. package/cjs/rules/date/date-day-rules.d.ts.map +1 -0
  154. package/cjs/rules/date/date-day-rules.js +65 -0
  155. package/cjs/rules/date/date-day-rules.js.map +1 -0
  156. package/cjs/rules/date/date-field-comparison-rules.d.ts +28 -0
  157. package/cjs/rules/date/date-field-comparison-rules.d.ts.map +1 -0
  158. package/cjs/rules/date/date-field-comparison-rules.js +90 -0
  159. package/cjs/rules/date/date-field-comparison-rules.js.map +1 -0
  160. package/cjs/rules/date/date-period-rules.d.ts +108 -0
  161. package/cjs/rules/date/date-period-rules.d.ts.map +1 -0
  162. package/cjs/rules/date/date-period-rules.js +566 -0
  163. package/cjs/rules/date/date-period-rules.js.map +1 -0
  164. package/cjs/rules/date/date-relative-rules.d.ts +20 -0
  165. package/cjs/rules/date/date-relative-rules.d.ts.map +1 -0
  166. package/cjs/rules/date/date-relative-rules.js +57 -0
  167. package/cjs/rules/date/date-relative-rules.js.map +1 -0
  168. package/cjs/rules/date/date-special-rules.d.ts +20 -0
  169. package/cjs/rules/date/date-special-rules.d.ts.map +1 -0
  170. package/cjs/rules/date/date-special-rules.js +72 -0
  171. package/cjs/rules/date/date-special-rules.js.map +1 -0
  172. package/cjs/rules/date/date.d.ts +93 -0
  173. package/cjs/rules/date/date.d.ts.map +1 -0
  174. package/cjs/rules/date/date.js +279 -0
  175. package/cjs/rules/date/date.js.map +1 -0
  176. package/cjs/rules/date/index.d.ts +8 -0
  177. package/cjs/rules/date/index.d.ts.map +1 -0
  178. package/cjs/rules/file/dimensions.d.ts +26 -0
  179. package/cjs/rules/file/dimensions.d.ts.map +1 -0
  180. package/cjs/rules/file/dimensions.js +56 -0
  181. package/cjs/rules/file/dimensions.js.map +1 -0
  182. package/cjs/rules/file/file-size.d.ts +14 -0
  183. package/cjs/rules/file/file-size.d.ts.map +1 -0
  184. package/cjs/rules/file/file-size.js +26 -0
  185. package/cjs/rules/file/file-size.js.map +1 -0
  186. package/cjs/rules/file/index.d.ts +11 -0
  187. package/cjs/rules/file/index.d.ts.map +1 -0
  188. package/cjs/rules/index.d.ts +19 -0
  189. package/cjs/rules/index.d.ts.map +1 -0
  190. package/cjs/rules/length/index.d.ts +2 -0
  191. package/cjs/rules/length/index.d.ts.map +1 -0
  192. package/cjs/rules/length/length-rules.d.ts +49 -0
  193. package/cjs/rules/length/length-rules.d.ts.map +1 -0
  194. package/cjs/rules/length/length-rules.js +116 -0
  195. package/cjs/rules/length/length-rules.js.map +1 -0
  196. package/cjs/rules/number/index.d.ts +2 -0
  197. package/cjs/rules/number/index.d.ts.map +1 -0
  198. package/cjs/rules/number/number-rules.d.ts +43 -0
  199. package/cjs/rules/number/number-rules.d.ts.map +1 -0
  200. package/cjs/rules/number/number-rules.js +107 -0
  201. package/cjs/rules/number/number-rules.js.map +1 -0
  202. package/cjs/rules/scalar/accepted-rule.d.ts +39 -0
  203. package/cjs/rules/scalar/accepted-rule.d.ts.map +1 -0
  204. package/cjs/rules/scalar/accepted-rule.js +110 -0
  205. package/cjs/rules/scalar/accepted-rule.js.map +1 -0
  206. package/cjs/rules/scalar/declined-rule.d.ts +39 -0
  207. package/cjs/rules/scalar/declined-rule.d.ts.map +1 -0
  208. package/cjs/rules/scalar/declined-rule.js +110 -0
  209. package/cjs/rules/scalar/declined-rule.js.map +1 -0
  210. package/cjs/rules/scalar/index.d.ts +3 -0
  211. package/cjs/rules/scalar/index.d.ts.map +1 -0
  212. package/cjs/rules/string/alpha.d.ts +14 -0
  213. package/cjs/rules/string/alpha.d.ts.map +1 -0
  214. package/cjs/rules/string/alpha.js +39 -0
  215. package/cjs/rules/string/alpha.js.map +1 -0
  216. package/cjs/rules/string/credit-card.d.ts +6 -0
  217. package/cjs/rules/string/credit-card.d.ts.map +1 -0
  218. package/cjs/rules/string/credit-card.js +31 -0
  219. package/cjs/rules/string/credit-card.js.map +1 -0
  220. package/cjs/rules/string/email.d.ts +6 -0
  221. package/cjs/rules/string/email.d.ts.map +1 -0
  222. package/cjs/rules/string/email.js +13 -0
  223. package/cjs/rules/string/email.js.map +1 -0
  224. package/cjs/rules/string/index.d.ts +17 -0
  225. package/cjs/rules/string/index.d.ts.map +1 -0
  226. package/cjs/rules/string/ip.d.ts +14 -0
  227. package/cjs/rules/string/ip.d.ts.map +1 -0
  228. package/cjs/rules/string/ip.js +39 -0
  229. package/cjs/rules/string/ip.js.map +1 -0
  230. package/cjs/rules/string/matches.d.ts +8 -0
  231. package/cjs/rules/string/matches.d.ts.map +1 -0
  232. package/cjs/rules/string/matches.js +14 -0
  233. package/cjs/rules/string/matches.js.map +1 -0
  234. package/cjs/rules/string/pattern.d.ts +8 -0
  235. package/cjs/rules/string/pattern.d.ts.map +1 -0
  236. package/cjs/rules/string/pattern.js +13 -0
  237. package/cjs/rules/string/pattern.js.map +1 -0
  238. package/cjs/rules/string/string-comparison.d.ts +26 -0
  239. package/cjs/rules/string/string-comparison.d.ts.map +1 -0
  240. package/cjs/rules/string/string-comparison.js +52 -0
  241. package/cjs/rules/string/string-comparison.js.map +1 -0
  242. package/cjs/rules/string/strong-password-rule.d.ts +14 -0
  243. package/cjs/rules/string/strong-password-rule.d.ts.map +1 -0
  244. package/cjs/rules/string/strong-password-rule.js +38 -0
  245. package/cjs/rules/string/strong-password-rule.js.map +1 -0
  246. package/cjs/rules/string/url.d.ts +6 -0
  247. package/cjs/rules/string/url.d.ts.map +1 -0
  248. package/cjs/rules/string/url.js +16 -0
  249. package/cjs/rules/string/url.js.map +1 -0
  250. package/cjs/rules/string/without-whitespace.d.ts +6 -0
  251. package/cjs/rules/string/without-whitespace.d.ts.map +1 -0
  252. package/cjs/rules/string/without-whitespace.js +13 -0
  253. package/cjs/rules/string/without-whitespace.js.map +1 -0
  254. package/cjs/types/conditional-types.d.ts +15 -0
  255. package/cjs/types/conditional-types.d.ts.map +1 -0
  256. package/cjs/types/context-types.d.ts +44 -0
  257. package/cjs/types/context-types.d.ts.map +1 -0
  258. package/cjs/types/data-transformer-types.d.ts +25 -0
  259. package/cjs/types/data-transformer-types.d.ts.map +1 -0
  260. package/cjs/types/date-types.d.ts +9 -0
  261. package/cjs/types/date-types.d.ts.map +1 -0
  262. package/cjs/types/date-types.js +12 -0
  263. package/cjs/types/date-types.js.map +1 -0
  264. package/cjs/types/index.d.ts +10 -0
  265. package/cjs/types/index.d.ts.map +1 -0
  266. package/cjs/types/inference-types.d.ts +29 -0
  267. package/cjs/types/inference-types.d.ts.map +1 -0
  268. package/cjs/types/mutator-types.d.ts +27 -0
  269. package/cjs/types/mutator-types.d.ts.map +1 -0
  270. package/cjs/types/result-types.d.ts +19 -0
  271. package/cjs/types/result-types.d.ts.map +1 -0
  272. package/cjs/types/rule-types.d.ts +53 -0
  273. package/cjs/types/rule-types.d.ts.map +1 -0
  274. package/cjs/types/schema-types.d.ts +6 -0
  275. package/cjs/types/schema-types.d.ts.map +1 -0
  276. package/cjs/validators/any-validator.d.ts +7 -0
  277. package/cjs/validators/any-validator.d.ts.map +1 -0
  278. package/cjs/validators/any-validator.js +5 -0
  279. package/cjs/validators/any-validator.js.map +1 -0
  280. package/cjs/validators/array-validator.d.ts +51 -0
  281. package/cjs/validators/array-validator.d.ts.map +1 -0
  282. package/cjs/validators/array-validator.js +120 -0
  283. package/cjs/validators/array-validator.js.map +1 -0
  284. package/cjs/validators/base-validator.d.ts +500 -0
  285. package/cjs/validators/base-validator.d.ts.map +1 -0
  286. package/cjs/validators/base-validator.js +950 -0
  287. package/cjs/validators/base-validator.js.map +1 -0
  288. package/cjs/validators/boolean-validator.d.ts +43 -0
  289. package/cjs/validators/boolean-validator.d.ts.map +1 -0
  290. package/cjs/validators/boolean-validator.js +48 -0
  291. package/cjs/validators/boolean-validator.js.map +1 -0
  292. package/cjs/validators/date-validator.d.ts +303 -0
  293. package/cjs/validators/date-validator.d.ts.map +1 -0
  294. package/cjs/validators/date-validator.js +639 -0
  295. package/cjs/validators/date-validator.js.map +1 -0
  296. package/cjs/validators/float-validator.d.ts +8 -0
  297. package/cjs/validators/float-validator.d.ts.map +1 -0
  298. package/cjs/validators/float-validator.js +9 -0
  299. package/cjs/validators/float-validator.js.map +1 -0
  300. package/cjs/validators/index.d.ts +20 -0
  301. package/cjs/validators/index.d.ts.map +1 -0
  302. package/cjs/validators/int-validator.d.ts +8 -0
  303. package/cjs/validators/int-validator.d.ts.map +1 -0
  304. package/cjs/validators/int-validator.js +9 -0
  305. package/cjs/validators/int-validator.js.map +1 -0
  306. package/cjs/validators/number-validator.d.ts +35 -0
  307. package/cjs/validators/number-validator.d.ts.map +1 -0
  308. package/cjs/validators/number-validator.js +66 -0
  309. package/cjs/validators/number-validator.js.map +1 -0
  310. package/cjs/validators/object-validator.d.ts +24 -0
  311. package/cjs/validators/object-validator.d.ts.map +1 -0
  312. package/cjs/validators/object-validator.js +120 -0
  313. package/cjs/validators/object-validator.js.map +1 -0
  314. package/cjs/validators/scalar-validator.d.ts +74 -0
  315. package/cjs/validators/scalar-validator.d.ts.map +1 -0
  316. package/cjs/validators/scalar-validator.js +145 -0
  317. package/cjs/validators/scalar-validator.js.map +1 -0
  318. package/cjs/validators/string-validator.d.ts +187 -0
  319. package/cjs/validators/string-validator.d.ts.map +1 -0
  320. package/cjs/validators/string-validator.js +404 -0
  321. package/cjs/validators/string-validator.js.map +1 -0
  322. package/esm/config.d.ts +48 -0
  323. package/esm/config.d.ts.map +1 -0
  324. package/esm/config.js +42 -0
  325. package/esm/config.js.map +1 -0
  326. package/esm/factory/index.d.ts +3 -0
  327. package/esm/factory/index.d.ts.map +1 -0
  328. package/esm/factory/validate.d.ts +8 -0
  329. package/esm/factory/validate.d.ts.map +1 -0
  330. package/esm/factory/validate.js +21 -0
  331. package/esm/factory/validate.js.map +1 -0
  332. package/esm/factory/validators.d.ts +32 -0
  333. package/esm/factory/validators.d.ts.map +1 -0
  334. package/esm/factory/validators.js +38 -0
  335. package/esm/factory/validators.js.map +1 -0
  336. package/esm/helpers/date-helpers.d.ts +16 -0
  337. package/esm/helpers/date-helpers.d.ts.map +1 -0
  338. package/esm/helpers/date-helpers.js +25 -0
  339. package/esm/helpers/date-helpers.js.map +1 -0
  340. package/esm/helpers/get-field-value.d.ts +37 -0
  341. package/esm/helpers/get-field-value.d.ts.map +1 -0
  342. package/esm/helpers/get-field-value.js +40 -0
  343. package/esm/helpers/get-field-value.js.map +1 -0
  344. package/esm/helpers/index.d.ts +5 -0
  345. package/esm/helpers/index.d.ts.map +1 -0
  346. package/esm/helpers/path-helpers.d.ts +5 -0
  347. package/esm/helpers/path-helpers.d.ts.map +1 -0
  348. package/esm/helpers/path-helpers.js +8 -0
  349. package/esm/helpers/path-helpers.js.map +1 -0
  350. package/esm/helpers/validation-helpers.d.ts +4 -0
  351. package/esm/helpers/validation-helpers.d.ts.map +1 -0
  352. package/esm/helpers/validation-helpers.js +39 -0
  353. package/esm/helpers/validation-helpers.js.map +1 -0
  354. package/esm/index.d.ts +29 -0
  355. package/esm/index.d.ts.map +1 -0
  356. package/esm/index.js +1 -0
  357. package/esm/index.js.map +1 -0
  358. package/esm/mutators/array-mutators.d.ts +12 -0
  359. package/esm/mutators/array-mutators.d.ts.map +1 -0
  360. package/esm/mutators/array-mutators.js +37 -0
  361. package/esm/mutators/array-mutators.js.map +1 -0
  362. package/esm/mutators/date-mutators.d.ts +39 -0
  363. package/esm/mutators/date-mutators.d.ts.map +1 -0
  364. package/esm/mutators/date-mutators.js +120 -0
  365. package/esm/mutators/date-mutators.js.map +1 -0
  366. package/esm/mutators/index.d.ts +6 -0
  367. package/esm/mutators/index.d.ts.map +1 -0
  368. package/esm/mutators/number-mutators.d.ts +8 -0
  369. package/esm/mutators/number-mutators.d.ts.map +1 -0
  370. package/esm/mutators/number-mutators.js +18 -0
  371. package/esm/mutators/number-mutators.js.map +1 -0
  372. package/esm/mutators/object-mutators.d.ts +8 -0
  373. package/esm/mutators/object-mutators.d.ts.map +1 -0
  374. package/esm/mutators/object-mutators.js +50 -0
  375. package/esm/mutators/object-mutators.js.map +1 -0
  376. package/esm/mutators/string-mutators.d.ts +72 -0
  377. package/esm/mutators/string-mutators.d.ts.map +1 -0
  378. package/esm/mutators/string-mutators.js +193 -0
  379. package/esm/mutators/string-mutators.js.map +1 -0
  380. package/esm/plugins/index.d.ts +7 -0
  381. package/esm/plugins/index.d.ts.map +1 -0
  382. package/esm/plugins/plugin-system.d.ts +71 -0
  383. package/esm/plugins/plugin-system.d.ts.map +1 -0
  384. package/esm/plugins/plugin-system.js +68 -0
  385. package/esm/plugins/plugin-system.js.map +1 -0
  386. package/esm/rules/array/array-rules.d.ts +12 -0
  387. package/esm/rules/array/array-rules.d.ts.map +1 -0
  388. package/esm/rules/array/array-rules.js +44 -0
  389. package/esm/rules/array/array-rules.js.map +1 -0
  390. package/esm/rules/array/index.d.ts +2 -0
  391. package/esm/rules/array/index.d.ts.map +1 -0
  392. package/esm/rules/color/color-rules.d.ts +30 -0
  393. package/esm/rules/color/color-rules.d.ts.map +1 -0
  394. package/esm/rules/color/color-rules.js +120 -0
  395. package/esm/rules/color/color-rules.js.map +1 -0
  396. package/esm/rules/color/index.d.ts +2 -0
  397. package/esm/rules/color/index.d.ts.map +1 -0
  398. package/esm/rules/common/enum.d.ts +26 -0
  399. package/esm/rules/common/enum.d.ts.map +1 -0
  400. package/esm/rules/common/enum.js +55 -0
  401. package/esm/rules/common/enum.js.map +1 -0
  402. package/esm/rules/common/equals-field-rules.d.ts +18 -0
  403. package/esm/rules/common/equals-field-rules.d.ts.map +1 -0
  404. package/esm/rules/common/equals-field-rules.js +38 -0
  405. package/esm/rules/common/equals-field-rules.js.map +1 -0
  406. package/esm/rules/common/index.d.ts +5 -0
  407. package/esm/rules/common/index.d.ts.map +1 -0
  408. package/esm/rules/common/type-rules.d.ts +34 -0
  409. package/esm/rules/common/type-rules.d.ts.map +1 -0
  410. package/esm/rules/common/type-rules.js +104 -0
  411. package/esm/rules/common/type-rules.js.map +1 -0
  412. package/esm/rules/common/unknown-key.d.ts +9 -0
  413. package/esm/rules/common/unknown-key.d.ts.map +1 -0
  414. package/esm/rules/common/unknown-key.js +20 -0
  415. package/esm/rules/common/unknown-key.js.map +1 -0
  416. package/esm/rules/conditional/index.d.ts +9 -0
  417. package/esm/rules/conditional/index.d.ts.map +1 -0
  418. package/esm/rules/conditional/present-if-rules.d.ts +45 -0
  419. package/esm/rules/conditional/present-if-rules.d.ts.map +1 -0
  420. package/esm/rules/conditional/present-if-rules.js +98 -0
  421. package/esm/rules/conditional/present-if-rules.js.map +1 -0
  422. package/esm/rules/conditional/present-unless-rules.d.ts +11 -0
  423. package/esm/rules/conditional/present-unless-rules.d.ts.map +1 -0
  424. package/esm/rules/conditional/present-unless-rules.js +20 -0
  425. package/esm/rules/conditional/present-unless-rules.js.map +1 -0
  426. package/esm/rules/conditional/present-with-rules.d.ts +26 -0
  427. package/esm/rules/conditional/present-with-rules.d.ts.map +1 -0
  428. package/esm/rules/conditional/present-with-rules.js +63 -0
  429. package/esm/rules/conditional/present-with-rules.js.map +1 -0
  430. package/esm/rules/conditional/present-without-rules.d.ts +26 -0
  431. package/esm/rules/conditional/present-without-rules.d.ts.map +1 -0
  432. package/esm/rules/conditional/present-without-rules.js +63 -0
  433. package/esm/rules/conditional/present-without-rules.js.map +1 -0
  434. package/esm/rules/conditional/required-if-rules.d.ts +45 -0
  435. package/esm/rules/conditional/required-if-rules.d.ts.map +1 -0
  436. package/esm/rules/conditional/required-if-rules.js +98 -0
  437. package/esm/rules/conditional/required-if-rules.js.map +1 -0
  438. package/esm/rules/conditional/required-unless-rules.d.ts +11 -0
  439. package/esm/rules/conditional/required-unless-rules.d.ts.map +1 -0
  440. package/esm/rules/conditional/required-unless-rules.js +20 -0
  441. package/esm/rules/conditional/required-unless-rules.js.map +1 -0
  442. package/esm/rules/conditional/required-with-rules.d.ts +26 -0
  443. package/esm/rules/conditional/required-with-rules.d.ts.map +1 -0
  444. package/esm/rules/conditional/required-with-rules.js +63 -0
  445. package/esm/rules/conditional/required-with-rules.js.map +1 -0
  446. package/esm/rules/conditional/required-without-rules.d.ts +26 -0
  447. package/esm/rules/conditional/required-without-rules.d.ts.map +1 -0
  448. package/esm/rules/conditional/required-without-rules.js +63 -0
  449. package/esm/rules/conditional/required-without-rules.js.map +1 -0
  450. package/esm/rules/core/equal.d.ts +8 -0
  451. package/esm/rules/core/equal.d.ts.map +1 -0
  452. package/esm/rules/core/equal.js +13 -0
  453. package/esm/rules/core/equal.js.map +1 -0
  454. package/esm/rules/core/forbidden.d.ts +6 -0
  455. package/esm/rules/core/forbidden.d.ts.map +1 -0
  456. package/esm/rules/core/forbidden.js +13 -0
  457. package/esm/rules/core/forbidden.js.map +1 -0
  458. package/esm/rules/core/index.d.ts +5 -0
  459. package/esm/rules/core/index.d.ts.map +1 -0
  460. package/esm/rules/core/required.d.ts +11 -0
  461. package/esm/rules/core/required.d.ts.map +1 -0
  462. package/esm/rules/core/required.js +31 -0
  463. package/esm/rules/core/required.js.map +1 -0
  464. package/esm/rules/core/when.d.ts +6 -0
  465. package/esm/rules/core/when.d.ts.map +1 -0
  466. package/esm/rules/core/when.js +40 -0
  467. package/esm/rules/core/when.js.map +1 -0
  468. package/esm/rules/date/date-comparison-rules.d.ts +25 -0
  469. package/esm/rules/date/date-comparison-rules.d.ts.map +1 -0
  470. package/esm/rules/date/date-comparison-rules.js +78 -0
  471. package/esm/rules/date/date-comparison-rules.js.map +1 -0
  472. package/esm/rules/date/date-day-rules.d.ts +21 -0
  473. package/esm/rules/date/date-day-rules.d.ts.map +1 -0
  474. package/esm/rules/date/date-day-rules.js +65 -0
  475. package/esm/rules/date/date-day-rules.js.map +1 -0
  476. package/esm/rules/date/date-field-comparison-rules.d.ts +28 -0
  477. package/esm/rules/date/date-field-comparison-rules.d.ts.map +1 -0
  478. package/esm/rules/date/date-field-comparison-rules.js +90 -0
  479. package/esm/rules/date/date-field-comparison-rules.js.map +1 -0
  480. package/esm/rules/date/date-period-rules.d.ts +108 -0
  481. package/esm/rules/date/date-period-rules.d.ts.map +1 -0
  482. package/esm/rules/date/date-period-rules.js +566 -0
  483. package/esm/rules/date/date-period-rules.js.map +1 -0
  484. package/esm/rules/date/date-relative-rules.d.ts +20 -0
  485. package/esm/rules/date/date-relative-rules.d.ts.map +1 -0
  486. package/esm/rules/date/date-relative-rules.js +57 -0
  487. package/esm/rules/date/date-relative-rules.js.map +1 -0
  488. package/esm/rules/date/date-special-rules.d.ts +20 -0
  489. package/esm/rules/date/date-special-rules.d.ts.map +1 -0
  490. package/esm/rules/date/date-special-rules.js +72 -0
  491. package/esm/rules/date/date-special-rules.js.map +1 -0
  492. package/esm/rules/date/date.d.ts +93 -0
  493. package/esm/rules/date/date.d.ts.map +1 -0
  494. package/esm/rules/date/date.js +279 -0
  495. package/esm/rules/date/date.js.map +1 -0
  496. package/esm/rules/date/index.d.ts +8 -0
  497. package/esm/rules/date/index.d.ts.map +1 -0
  498. package/esm/rules/file/dimensions.d.ts +26 -0
  499. package/esm/rules/file/dimensions.d.ts.map +1 -0
  500. package/esm/rules/file/dimensions.js +56 -0
  501. package/esm/rules/file/dimensions.js.map +1 -0
  502. package/esm/rules/file/file-size.d.ts +14 -0
  503. package/esm/rules/file/file-size.d.ts.map +1 -0
  504. package/esm/rules/file/file-size.js +26 -0
  505. package/esm/rules/file/file-size.js.map +1 -0
  506. package/esm/rules/file/index.d.ts +11 -0
  507. package/esm/rules/file/index.d.ts.map +1 -0
  508. package/esm/rules/index.d.ts +19 -0
  509. package/esm/rules/index.d.ts.map +1 -0
  510. package/esm/rules/length/index.d.ts +2 -0
  511. package/esm/rules/length/index.d.ts.map +1 -0
  512. package/esm/rules/length/length-rules.d.ts +49 -0
  513. package/esm/rules/length/length-rules.d.ts.map +1 -0
  514. package/esm/rules/length/length-rules.js +116 -0
  515. package/esm/rules/length/length-rules.js.map +1 -0
  516. package/esm/rules/number/index.d.ts +2 -0
  517. package/esm/rules/number/index.d.ts.map +1 -0
  518. package/esm/rules/number/number-rules.d.ts +43 -0
  519. package/esm/rules/number/number-rules.d.ts.map +1 -0
  520. package/esm/rules/number/number-rules.js +107 -0
  521. package/esm/rules/number/number-rules.js.map +1 -0
  522. package/esm/rules/scalar/accepted-rule.d.ts +39 -0
  523. package/esm/rules/scalar/accepted-rule.d.ts.map +1 -0
  524. package/esm/rules/scalar/accepted-rule.js +110 -0
  525. package/esm/rules/scalar/accepted-rule.js.map +1 -0
  526. package/esm/rules/scalar/declined-rule.d.ts +39 -0
  527. package/esm/rules/scalar/declined-rule.d.ts.map +1 -0
  528. package/esm/rules/scalar/declined-rule.js +110 -0
  529. package/esm/rules/scalar/declined-rule.js.map +1 -0
  530. package/esm/rules/scalar/index.d.ts +3 -0
  531. package/esm/rules/scalar/index.d.ts.map +1 -0
  532. package/esm/rules/string/alpha.d.ts +14 -0
  533. package/esm/rules/string/alpha.d.ts.map +1 -0
  534. package/esm/rules/string/alpha.js +39 -0
  535. package/esm/rules/string/alpha.js.map +1 -0
  536. package/esm/rules/string/credit-card.d.ts +6 -0
  537. package/esm/rules/string/credit-card.d.ts.map +1 -0
  538. package/esm/rules/string/credit-card.js +31 -0
  539. package/esm/rules/string/credit-card.js.map +1 -0
  540. package/esm/rules/string/email.d.ts +6 -0
  541. package/esm/rules/string/email.d.ts.map +1 -0
  542. package/esm/rules/string/email.js +13 -0
  543. package/esm/rules/string/email.js.map +1 -0
  544. package/esm/rules/string/index.d.ts +17 -0
  545. package/esm/rules/string/index.d.ts.map +1 -0
  546. package/esm/rules/string/ip.d.ts +14 -0
  547. package/esm/rules/string/ip.d.ts.map +1 -0
  548. package/esm/rules/string/ip.js +39 -0
  549. package/esm/rules/string/ip.js.map +1 -0
  550. package/esm/rules/string/matches.d.ts +8 -0
  551. package/esm/rules/string/matches.d.ts.map +1 -0
  552. package/esm/rules/string/matches.js +14 -0
  553. package/esm/rules/string/matches.js.map +1 -0
  554. package/esm/rules/string/pattern.d.ts +8 -0
  555. package/esm/rules/string/pattern.d.ts.map +1 -0
  556. package/esm/rules/string/pattern.js +13 -0
  557. package/esm/rules/string/pattern.js.map +1 -0
  558. package/esm/rules/string/string-comparison.d.ts +26 -0
  559. package/esm/rules/string/string-comparison.d.ts.map +1 -0
  560. package/esm/rules/string/string-comparison.js +52 -0
  561. package/esm/rules/string/string-comparison.js.map +1 -0
  562. package/esm/rules/string/strong-password-rule.d.ts +14 -0
  563. package/esm/rules/string/strong-password-rule.d.ts.map +1 -0
  564. package/esm/rules/string/strong-password-rule.js +38 -0
  565. package/esm/rules/string/strong-password-rule.js.map +1 -0
  566. package/esm/rules/string/url.d.ts +6 -0
  567. package/esm/rules/string/url.d.ts.map +1 -0
  568. package/esm/rules/string/url.js +16 -0
  569. package/esm/rules/string/url.js.map +1 -0
  570. package/esm/rules/string/without-whitespace.d.ts +6 -0
  571. package/esm/rules/string/without-whitespace.d.ts.map +1 -0
  572. package/esm/rules/string/without-whitespace.js +13 -0
  573. package/esm/rules/string/without-whitespace.js.map +1 -0
  574. package/esm/types/conditional-types.d.ts +15 -0
  575. package/esm/types/conditional-types.d.ts.map +1 -0
  576. package/esm/types/context-types.d.ts +44 -0
  577. package/esm/types/context-types.d.ts.map +1 -0
  578. package/esm/types/data-transformer-types.d.ts +25 -0
  579. package/esm/types/data-transformer-types.d.ts.map +1 -0
  580. package/esm/types/date-types.d.ts +9 -0
  581. package/esm/types/date-types.d.ts.map +1 -0
  582. package/esm/types/date-types.js +12 -0
  583. package/esm/types/date-types.js.map +1 -0
  584. package/esm/types/index.d.ts +10 -0
  585. package/esm/types/index.d.ts.map +1 -0
  586. package/esm/types/inference-types.d.ts +29 -0
  587. package/esm/types/inference-types.d.ts.map +1 -0
  588. package/esm/types/mutator-types.d.ts +27 -0
  589. package/esm/types/mutator-types.d.ts.map +1 -0
  590. package/esm/types/result-types.d.ts +19 -0
  591. package/esm/types/result-types.d.ts.map +1 -0
  592. package/esm/types/rule-types.d.ts +53 -0
  593. package/esm/types/rule-types.d.ts.map +1 -0
  594. package/esm/types/schema-types.d.ts +6 -0
  595. package/esm/types/schema-types.d.ts.map +1 -0
  596. package/esm/validators/any-validator.d.ts +7 -0
  597. package/esm/validators/any-validator.d.ts.map +1 -0
  598. package/esm/validators/any-validator.js +5 -0
  599. package/esm/validators/any-validator.js.map +1 -0
  600. package/esm/validators/array-validator.d.ts +51 -0
  601. package/esm/validators/array-validator.d.ts.map +1 -0
  602. package/esm/validators/array-validator.js +120 -0
  603. package/esm/validators/array-validator.js.map +1 -0
  604. package/esm/validators/base-validator.d.ts +500 -0
  605. package/esm/validators/base-validator.d.ts.map +1 -0
  606. package/esm/validators/base-validator.js +950 -0
  607. package/esm/validators/base-validator.js.map +1 -0
  608. package/esm/validators/boolean-validator.d.ts +43 -0
  609. package/esm/validators/boolean-validator.d.ts.map +1 -0
  610. package/esm/validators/boolean-validator.js +48 -0
  611. package/esm/validators/boolean-validator.js.map +1 -0
  612. package/esm/validators/date-validator.d.ts +303 -0
  613. package/esm/validators/date-validator.d.ts.map +1 -0
  614. package/esm/validators/date-validator.js +639 -0
  615. package/esm/validators/date-validator.js.map +1 -0
  616. package/esm/validators/float-validator.d.ts +8 -0
  617. package/esm/validators/float-validator.d.ts.map +1 -0
  618. package/esm/validators/float-validator.js +9 -0
  619. package/esm/validators/float-validator.js.map +1 -0
  620. package/esm/validators/index.d.ts +20 -0
  621. package/esm/validators/index.d.ts.map +1 -0
  622. package/esm/validators/int-validator.d.ts +8 -0
  623. package/esm/validators/int-validator.d.ts.map +1 -0
  624. package/esm/validators/int-validator.js +9 -0
  625. package/esm/validators/int-validator.js.map +1 -0
  626. package/esm/validators/number-validator.d.ts +35 -0
  627. package/esm/validators/number-validator.d.ts.map +1 -0
  628. package/esm/validators/number-validator.js +66 -0
  629. package/esm/validators/number-validator.js.map +1 -0
  630. package/esm/validators/object-validator.d.ts +24 -0
  631. package/esm/validators/object-validator.d.ts.map +1 -0
  632. package/esm/validators/object-validator.js +120 -0
  633. package/esm/validators/object-validator.js.map +1 -0
  634. package/esm/validators/scalar-validator.d.ts +74 -0
  635. package/esm/validators/scalar-validator.d.ts.map +1 -0
  636. package/esm/validators/scalar-validator.js +145 -0
  637. package/esm/validators/scalar-validator.js.map +1 -0
  638. package/esm/validators/string-validator.d.ts +187 -0
  639. package/esm/validators/string-validator.d.ts.map +1 -0
  640. package/esm/validators/string-validator.js +404 -0
  641. package/esm/validators/string-validator.js.map +1 -0
  642. package/package.json +29 -0
@@ -0,0 +1,950 @@
1
+ 'use strict';var reinforcements=require('@mongez/reinforcements'),supportiveIs=require('@mongez/supportive-is'),validationHelpers=require('../helpers/validation-helpers.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('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'),equalsFieldRules=require('../rules/common/equals-field-rules.js');/**
2
+ * Base validator class - foundation for all validators
3
+ */
4
+ class BaseValidator {
5
+ rules = [];
6
+ mutators = [];
7
+ defaultValue;
8
+ description;
9
+ shouldAllowEmpty = false;
10
+ shouldOmit = false;
11
+ /**
12
+ * Pipeline to transform the mutated/original data before returning it
13
+ */
14
+ dataTransformers = [];
15
+ /**
16
+ * Attributes text to be replaced on translations
17
+ * If the value is an object, it will be used as the attributes list for the rule
18
+ * If the value is a string, it will be used as the attributes list for the rule
19
+ */
20
+ attributesText = {};
21
+ /**
22
+ * Get the default value
23
+ */
24
+ getDefaultValue() {
25
+ return this.defaultValue;
26
+ }
27
+ /**
28
+ * Add transformer with optional options
29
+ *
30
+ * @param transform - The transformer callback function
31
+ * @param options - Optional options to pass to the transformer
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * // Without options
36
+ * v.date().addTransformer(data => data.toISOString())
37
+ *
38
+ * // With options
39
+ * v.date().addTransformer(
40
+ * (data, { options }) => dayjs(data).format(options.format),
41
+ * { format: 'YYYY-MM-DD' }
42
+ * )
43
+ * ```
44
+ */
45
+ addTransformer(transform, options = {}) {
46
+ this.dataTransformers.push({
47
+ transform,
48
+ options,
49
+ });
50
+ return this;
51
+ }
52
+ /**
53
+ * Transform the output value - simple one-time transformation
54
+ *
55
+ * @param callback - Simple callback receiving data and context
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * // Simple transformation
60
+ * v.string().outputAs(data => data.toUpperCase())
61
+ *
62
+ * // With context
63
+ * v.string().outputAs((data, context) => {
64
+ * console.log(`Transforming ${context.path}`);
65
+ * return data.toLowerCase();
66
+ * })
67
+ * ```
68
+ */
69
+ outputAs(callback) {
70
+ this.addTransformer((data, { context }) => callback(data, context));
71
+ return this;
72
+ }
73
+ /**
74
+ * Transform output to JSON string
75
+ *
76
+ * Works with any validator type (string, number, date, object, array, etc.)
77
+ *
78
+ * @param indent - Optional indentation for pretty printing (default: 0 for compact)
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * // Compact JSON
83
+ * v.object({ name: v.string() }).toJSON()
84
+ * // Output: '{"name":"John"}'
85
+ *
86
+ * // Pretty-printed JSON
87
+ * v.array(v.object({...})).toJSON(2)
88
+ * // Output:
89
+ * // [
90
+ * // {
91
+ * // "name": "John"
92
+ * // }
93
+ * // ]
94
+ *
95
+ * // Works with any type
96
+ * v.string().toJSON() // '"hello"'
97
+ * v.number().toJSON() // '42'
98
+ * v.date().toJSON() // '"2024-10-26T00:00:00.000Z"'
99
+ * ```
100
+ *
101
+ * @category Transformer
102
+ */
103
+ toJSON(indent) {
104
+ this.addTransformer((data, { options }) => JSON.stringify(data, null, options.indent), { indent: indent ?? 0 });
105
+ return this;
106
+ }
107
+ /**
108
+ * Start data transformation pipeline
109
+ * Context is passed at runtime, not stored
110
+ */
111
+ async startTransformationPipeline(data, context) {
112
+ for (const transformer of this.dataTransformers) {
113
+ data = await transformer.transform(data, {
114
+ options: transformer.options,
115
+ context,
116
+ });
117
+ }
118
+ return data;
119
+ }
120
+ /**
121
+ * Set attributes text to be replaced on translations
122
+ * If the value is an object, it will be used as the attributes list for the rule
123
+ * If the value is a string, it will be used as the attributes list for the rule
124
+ *
125
+ * @example
126
+ * v.string().attributes({
127
+ * name: "Name",
128
+ * email: "Email",
129
+ * });
130
+ * // Example 2: Add custom attributes for matches
131
+ * v.string().matches("confirmPassword").attributes({
132
+ * matches: {
133
+ * confirmPassword: "Confirm Password",
134
+ * },
135
+ * });
136
+ */
137
+ attributes(attributes) {
138
+ this.attributesText = attributes;
139
+ return this;
140
+ }
141
+ /**
142
+ * Add description to the validator
143
+ */
144
+ describe(description) {
145
+ this.description = description;
146
+ return this;
147
+ }
148
+ /**
149
+ * Allow empty values and skip validation if the value is empty
150
+ */
151
+ allowsEmpty() {
152
+ this.shouldAllowEmpty = true;
153
+ return this;
154
+ }
155
+ /**
156
+ * Omit this field from the validated data output
157
+ *
158
+ * Field will still be validated but not included in the final result.
159
+ * Useful for confirmation fields, captcha, terms acceptance, etc.
160
+ *
161
+ * @example
162
+ * ```ts
163
+ * v.object({
164
+ * password: v.string().required(),
165
+ * confirmPassword: v.string().required().sameAs("password").omit(),
166
+ * acceptTerms: v.boolean().required().omit(),
167
+ * });
168
+ * // Output: { password: "..." }
169
+ * // confirmPassword and acceptTerms validated but omitted
170
+ * ```
171
+ */
172
+ omit() {
173
+ this.shouldOmit = true;
174
+ return this;
175
+ }
176
+ /**
177
+ * @alias omit
178
+ */
179
+ exclude() {
180
+ return this.omit();
181
+ }
182
+ /**
183
+ * Check if this field should be omitted from the output
184
+ */
185
+ isOmitted() {
186
+ return this.shouldOmit;
187
+ }
188
+ /**
189
+ * Value must be equal to the given value
190
+ */
191
+ equal(value, errorMessage) {
192
+ const rule = this.addRule(equal.equalRule, errorMessage);
193
+ rule.context.options.value = value;
194
+ return this;
195
+ }
196
+ /**
197
+ * Value must be the same as another field's value
198
+ */
199
+ sameAs(field, errorMessage) {
200
+ const rule = this.addRule(equalsFieldRules.equalsFieldRule, errorMessage);
201
+ rule.context.options.field = field;
202
+ rule.context.options.scope = "global";
203
+ return this;
204
+ }
205
+ /**
206
+ * Value must be the same as another sibling field's value
207
+ */
208
+ sameAsSibling(field, errorMessage) {
209
+ const rule = this.addRule(equalsFieldRules.equalsFieldRule, errorMessage);
210
+ rule.context.options.field = field;
211
+ rule.context.options.scope = "sibling";
212
+ return this;
213
+ }
214
+ /**
215
+ * Value must be different from another field's value
216
+ */
217
+ differentFrom(field, errorMessage) {
218
+ const rule = this.addRule(equalsFieldRules.notEqualsFieldRule, errorMessage);
219
+ rule.context.options.field = field;
220
+ rule.context.options.scope = "global";
221
+ return this;
222
+ }
223
+ /**
224
+ * Value must be different from another sibling field's value
225
+ */
226
+ differentFromSibling(field, errorMessage) {
227
+ const rule = this.addRule(equalsFieldRules.notEqualsFieldRule, errorMessage);
228
+ rule.context.options.field = field;
229
+ rule.context.options.scope = "sibling";
230
+ return this;
231
+ }
232
+ /**
233
+ * Add rule to the validator
234
+ */
235
+ addRule(rule, errorMessage) {
236
+ const newRule = {
237
+ ...reinforcements.clone(rule),
238
+ context: {
239
+ errorMessage,
240
+ options: {},
241
+ attributesList: {},
242
+ },
243
+ };
244
+ if (errorMessage) {
245
+ newRule.errorMessage = errorMessage;
246
+ }
247
+ if (rule.sortOrder === undefined) {
248
+ newRule.sortOrder = this.rules.length + 1;
249
+ }
250
+ this.rules.push(newRule);
251
+ return newRule;
252
+ }
253
+ /**
254
+ * Use a custom or pre-built validation rule
255
+ *
256
+ * @param rule - The validation rule to apply
257
+ * @param options - Rule options including errorMessage and any rule-specific options
258
+ *
259
+ * @example
260
+ * ```ts
261
+ * import { hexColorRule } from "@warlock.js/seal-plugins/colors";
262
+ *
263
+ * v.string().useRule(hexColorRule, { errorMessage: "Invalid color" });
264
+ * ```
265
+ *
266
+ * @example
267
+ * ```ts
268
+ * // With rule options
269
+ * v.string().useRule(myCustomRule, {
270
+ * customOption: true,
271
+ * errorMessage: "Custom validation failed"
272
+ * });
273
+ * ```
274
+ */
275
+ useRule(rule, options) {
276
+ const { errorMessage, ...ruleOptions } = options || {};
277
+ const ruleInstance = this.addRule(rule, errorMessage);
278
+ // Assign rule-specific options
279
+ if (Object.keys(ruleOptions).length > 0) {
280
+ Object.assign(ruleInstance.context.options, ruleOptions);
281
+ }
282
+ return this;
283
+ }
284
+ /**
285
+ * Define custom rule
286
+ */
287
+ refine(callback) {
288
+ this.addRule({
289
+ name: "custom",
290
+ async validate(value, context) {
291
+ const result = await callback(value, context);
292
+ if (result) {
293
+ this.context.errorMessage = result;
294
+ return validationHelpers.invalidRule(this, context);
295
+ }
296
+ return validationHelpers.VALID_RULE;
297
+ },
298
+ });
299
+ return this;
300
+ }
301
+ /**
302
+ * Add mutator to the validator
303
+ */
304
+ addMutator(mutator, options = {}) {
305
+ this.mutators.push({
306
+ mutate: mutator,
307
+ context: {
308
+ options,
309
+ ctx: {},
310
+ },
311
+ });
312
+ return this;
313
+ }
314
+ /**
315
+ * Set default value for the field
316
+ */
317
+ default(value) {
318
+ this.defaultValue = value;
319
+ return this;
320
+ }
321
+ // ==================== UNCONDITIONAL STATES ====================
322
+ /**
323
+ * This value must be present and has a value
324
+ */
325
+ required(errorMessage) {
326
+ this.addRule(required.requiredRule, errorMessage);
327
+ return this;
328
+ }
329
+ /**
330
+ * Value must be present but not necessarily has a value
331
+ */
332
+ present(errorMessage) {
333
+ this.addRule(required.presentRule, errorMessage);
334
+ return this;
335
+ }
336
+ /**
337
+ * Mark the field as optional, so pass it if it has no value or has a value
338
+ * Because this is the default behavior, this method is just syntactic sugar
339
+ */
340
+ optional() {
341
+ return this;
342
+ }
343
+ // ==================== REQUIRED: BASED ON FIELD PRESENCE ====================
344
+ /**
345
+ * Value is required if another field exists
346
+ */
347
+ requiredWith(field, errorMessage) {
348
+ const rule = this.addRule(requiredWithRules.requiredWithRule, errorMessage);
349
+ rule.context.options.field = field;
350
+ rule.context.options.scope = "global";
351
+ return this;
352
+ }
353
+ /**
354
+ * Value is required if another sibling field exists
355
+ */
356
+ requiredWithSibling(field, errorMessage) {
357
+ const rule = this.addRule(requiredWithRules.requiredWithRule, errorMessage);
358
+ rule.context.options.field = field;
359
+ rule.context.options.scope = "sibling";
360
+ return this;
361
+ }
362
+ /**
363
+ * Value is required if another field is missing
364
+ */
365
+ requiredWithout(field, errorMessage) {
366
+ const rule = this.addRule(requiredWithoutRules.requiredWithoutRule, errorMessage);
367
+ rule.context.options.field = field;
368
+ rule.context.options.scope = "global";
369
+ return this;
370
+ }
371
+ /**
372
+ * Value is required if another sibling field is missing
373
+ */
374
+ requiredWithoutSibling(field, errorMessage) {
375
+ const rule = this.addRule(requiredWithoutRules.requiredWithoutRule, errorMessage);
376
+ rule.context.options.field = field;
377
+ rule.context.options.scope = "sibling";
378
+ return this;
379
+ }
380
+ // ==================== REQUIRED: BASED ON FIELD VALUE ====================
381
+ /**
382
+ * Value is required if another field equals a specific value
383
+ */
384
+ requiredIf(field, value, errorMessage) {
385
+ const rule = this.addRule(requiredIfRules.requiredIfRule, errorMessage);
386
+ rule.context.options.field = field;
387
+ rule.context.options.value = value;
388
+ rule.context.options.scope = "global";
389
+ return this;
390
+ }
391
+ /**
392
+ * Value is required if another sibling field equals a specific value
393
+ */
394
+ requiredIfSibling(field, value, errorMessage) {
395
+ const rule = this.addRule(requiredIfRules.requiredIfRule, errorMessage);
396
+ rule.context.options.field = field;
397
+ rule.context.options.value = value;
398
+ rule.context.options.scope = "sibling";
399
+ return this;
400
+ }
401
+ /**
402
+ * Value is required unless another field equals a specific value
403
+ */
404
+ requiredUnless(field, value, errorMessage) {
405
+ const rule = this.addRule(requiredUnlessRules.requiredUnlessRule, errorMessage);
406
+ rule.context.options.field = field;
407
+ rule.context.options.value = value;
408
+ rule.context.options.scope = "global";
409
+ return this;
410
+ }
411
+ /**
412
+ * Value is required unless another sibling field equals a specific value
413
+ */
414
+ requiredUnlessSibling(field, value, errorMessage) {
415
+ const rule = this.addRule(requiredUnlessRules.requiredUnlessRule, errorMessage);
416
+ rule.context.options.field = field;
417
+ rule.context.options.value = value;
418
+ rule.context.options.scope = "sibling";
419
+ return this;
420
+ }
421
+ // ==================== REQUIRED: BASED ON FIELD EMPTY STATE ====================
422
+ /**
423
+ * Value is required if another field is empty
424
+ */
425
+ requiredIfEmpty(field, errorMessage) {
426
+ const rule = this.addRule(requiredIfRules.requiredIfEmptyRule, errorMessage);
427
+ rule.context.options.field = field;
428
+ rule.context.options.scope = "global";
429
+ return this;
430
+ }
431
+ /**
432
+ * Value is required if another sibling field is empty
433
+ */
434
+ requiredIfEmptySibling(field, errorMessage) {
435
+ const rule = this.addRule(requiredIfRules.requiredIfEmptyRule, errorMessage);
436
+ rule.context.options.field = field;
437
+ rule.context.options.scope = "sibling";
438
+ return this;
439
+ }
440
+ /**
441
+ * Value is required if another field is not empty
442
+ */
443
+ requiredIfNotEmpty(field, errorMessage) {
444
+ const rule = this.addRule(requiredIfRules.requiredIfNotEmptyRule, errorMessage);
445
+ rule.context.options.field = field;
446
+ rule.context.options.scope = "global";
447
+ return this;
448
+ }
449
+ /**
450
+ * Value is required if another sibling field is not empty
451
+ */
452
+ requiredIfNotEmptySibling(field, errorMessage) {
453
+ const rule = this.addRule(requiredIfRules.requiredIfNotEmptyRule, errorMessage);
454
+ rule.context.options.field = field;
455
+ rule.context.options.scope = "sibling";
456
+ return this;
457
+ }
458
+ /**
459
+ * Value is required if another field's value is in the given array
460
+ */
461
+ requiredIfIn(field, values, errorMessage) {
462
+ const rule = this.addRule(requiredIfRules.requiredIfInRule, errorMessage);
463
+ rule.context.options.field = field;
464
+ rule.context.options.values = values;
465
+ rule.context.options.scope = "global";
466
+ return this;
467
+ }
468
+ /**
469
+ * Value is required if another sibling field's value is in the given array
470
+ */
471
+ requiredIfInSibling(field, values, errorMessage) {
472
+ const rule = this.addRule(requiredIfRules.requiredIfInRule, errorMessage);
473
+ rule.context.options.field = field;
474
+ rule.context.options.values = values;
475
+ rule.context.options.scope = "sibling";
476
+ return this;
477
+ }
478
+ /**
479
+ * Value is required if another field's value is NOT in the given array
480
+ */
481
+ requiredIfNotIn(field, values, errorMessage) {
482
+ const rule = this.addRule(requiredIfRules.requiredIfNotInRule, errorMessage);
483
+ rule.context.options.field = field;
484
+ rule.context.options.values = values;
485
+ rule.context.options.scope = "global";
486
+ return this;
487
+ }
488
+ /**
489
+ * Value is required if another sibling field's value is NOT in the given array
490
+ */
491
+ requiredIfNotInSibling(field, values, errorMessage) {
492
+ const rule = this.addRule(requiredIfRules.requiredIfNotInRule, errorMessage);
493
+ rule.context.options.field = field;
494
+ rule.context.options.values = values;
495
+ rule.context.options.scope = "sibling";
496
+ return this;
497
+ }
498
+ // ==================== REQUIRED: BASED ON MULTIPLE FIELDS (ALL) ====================
499
+ /**
500
+ * Value is required if all specified fields exist
501
+ */
502
+ requiredWithAll(fields, errorMessage) {
503
+ const rule = this.addRule(requiredWithRules.requiredWithAllRule, errorMessage);
504
+ rule.context.options.fields = fields;
505
+ rule.context.options.scope = "global";
506
+ return this;
507
+ }
508
+ /**
509
+ * Value is required if all specified sibling fields exist
510
+ */
511
+ requiredWithAllSiblings(fields, errorMessage) {
512
+ const rule = this.addRule(requiredWithRules.requiredWithAllRule, errorMessage);
513
+ rule.context.options.fields = fields;
514
+ rule.context.options.scope = "sibling";
515
+ return this;
516
+ }
517
+ /**
518
+ * Value is required if all specified fields are missing
519
+ */
520
+ requiredWithoutAll(fields, errorMessage) {
521
+ const rule = this.addRule(requiredWithoutRules.requiredWithoutAllRule, errorMessage);
522
+ rule.context.options.fields = fields;
523
+ rule.context.options.scope = "global";
524
+ return this;
525
+ }
526
+ /**
527
+ * Value is required if all specified sibling fields are missing
528
+ */
529
+ requiredWithoutAllSiblings(fields, errorMessage) {
530
+ const rule = this.addRule(requiredWithoutRules.requiredWithoutAllRule, errorMessage);
531
+ rule.context.options.fields = fields;
532
+ rule.context.options.scope = "sibling";
533
+ return this;
534
+ }
535
+ // ==================== REQUIRED: BASED ON MULTIPLE FIELDS (ANY) ====================
536
+ /**
537
+ * Value is required if any of the specified fields exists
538
+ */
539
+ requiredWithAny(fields, errorMessage) {
540
+ const rule = this.addRule(requiredWithRules.requiredWithAnyRule, errorMessage);
541
+ rule.context.options.fields = fields;
542
+ rule.context.options.scope = "global";
543
+ return this;
544
+ }
545
+ /**
546
+ * Value is required if any of the specified sibling fields exists
547
+ */
548
+ requiredWithAnySiblings(fields, errorMessage) {
549
+ const rule = this.addRule(requiredWithRules.requiredWithAnyRule, errorMessage);
550
+ rule.context.options.fields = fields;
551
+ rule.context.options.scope = "sibling";
552
+ return this;
553
+ }
554
+ /**
555
+ * Value is required if any of the specified fields is missing
556
+ */
557
+ requiredWithoutAny(fields, errorMessage) {
558
+ const rule = this.addRule(requiredWithoutRules.requiredWithoutAnyRule, errorMessage);
559
+ rule.context.options.fields = fields;
560
+ rule.context.options.scope = "global";
561
+ return this;
562
+ }
563
+ /**
564
+ * Value is required if any of the specified sibling fields is missing
565
+ */
566
+ requiredWithoutAnySiblings(fields, errorMessage) {
567
+ const rule = this.addRule(requiredWithoutRules.requiredWithoutAnyRule, errorMessage);
568
+ rule.context.options.fields = fields;
569
+ rule.context.options.scope = "sibling";
570
+ return this;
571
+ }
572
+ // ==================== PRESENT: BASED ON FIELD PRESENCE ====================
573
+ /**
574
+ * Field must be present if another field exists
575
+ */
576
+ presentWith(field, errorMessage) {
577
+ const rule = this.addRule(presentWithRules.presentWithRule, errorMessage);
578
+ rule.context.options.field = field;
579
+ rule.context.options.scope = "global";
580
+ return this;
581
+ }
582
+ /**
583
+ * Field must be present if another sibling field exists
584
+ */
585
+ presentWithSibling(field, errorMessage) {
586
+ const rule = this.addRule(presentWithRules.presentWithRule, errorMessage);
587
+ rule.context.options.field = field;
588
+ rule.context.options.scope = "sibling";
589
+ return this;
590
+ }
591
+ /**
592
+ * Field must be present if another field is missing
593
+ */
594
+ presentWithout(field, errorMessage) {
595
+ const rule = this.addRule(presentWithoutRules.presentWithoutRule, errorMessage);
596
+ rule.context.options.field = field;
597
+ rule.context.options.scope = "global";
598
+ return this;
599
+ }
600
+ /**
601
+ * Field must be present if another sibling field is missing
602
+ */
603
+ presentWithoutSibling(field, errorMessage) {
604
+ const rule = this.addRule(presentWithoutRules.presentWithoutRule, errorMessage);
605
+ rule.context.options.field = field;
606
+ rule.context.options.scope = "sibling";
607
+ return this;
608
+ }
609
+ // ==================== PRESENT: BASED ON FIELD VALUE ====================
610
+ /**
611
+ * Field must be present if another field equals a specific value
612
+ */
613
+ presentIf(field, value, errorMessage) {
614
+ const rule = this.addRule(presentIfRules.presentIfRule, errorMessage);
615
+ rule.context.options.field = field;
616
+ rule.context.options.value = value;
617
+ rule.context.options.scope = "global";
618
+ return this;
619
+ }
620
+ /**
621
+ * Field must be present if another sibling field equals a specific value
622
+ */
623
+ presentIfSibling(field, value, errorMessage) {
624
+ const rule = this.addRule(presentIfRules.presentIfRule, errorMessage);
625
+ rule.context.options.field = field;
626
+ rule.context.options.value = value;
627
+ rule.context.options.scope = "sibling";
628
+ return this;
629
+ }
630
+ /**
631
+ * Field must be present unless another field equals a specific value
632
+ */
633
+ presentUnless(field, value, errorMessage) {
634
+ const rule = this.addRule(presentUnlessRules.presentUnlessRule, errorMessage);
635
+ rule.context.options.field = field;
636
+ rule.context.options.value = value;
637
+ rule.context.options.scope = "global";
638
+ return this;
639
+ }
640
+ /**
641
+ * Field must be present unless another sibling field equals a specific value
642
+ */
643
+ presentUnlessSibling(field, value, errorMessage) {
644
+ const rule = this.addRule(presentUnlessRules.presentUnlessRule, errorMessage);
645
+ rule.context.options.field = field;
646
+ rule.context.options.value = value;
647
+ rule.context.options.scope = "sibling";
648
+ return this;
649
+ }
650
+ // ==================== PRESENT: BASED ON FIELD EMPTY STATE ====================
651
+ /**
652
+ * Field must be present if another field is empty
653
+ */
654
+ presentIfEmpty(field, errorMessage) {
655
+ const rule = this.addRule(presentIfRules.presentIfEmptyRule, errorMessage);
656
+ rule.context.options.field = field;
657
+ rule.context.options.scope = "global";
658
+ return this;
659
+ }
660
+ /**
661
+ * Field must be present if another sibling field is empty
662
+ */
663
+ presentIfEmptySibling(field, errorMessage) {
664
+ const rule = this.addRule(presentIfRules.presentIfEmptyRule, errorMessage);
665
+ rule.context.options.field = field;
666
+ rule.context.options.scope = "sibling";
667
+ return this;
668
+ }
669
+ /**
670
+ * Field must be present if another field is not empty
671
+ */
672
+ presentIfNotEmpty(field, errorMessage) {
673
+ const rule = this.addRule(presentIfRules.presentIfNotEmptyRule, errorMessage);
674
+ rule.context.options.field = field;
675
+ rule.context.options.scope = "global";
676
+ return this;
677
+ }
678
+ /**
679
+ * Field must be present if another sibling field is not empty
680
+ */
681
+ presentIfNotEmptySibling(field, errorMessage) {
682
+ const rule = this.addRule(presentIfRules.presentIfNotEmptyRule, errorMessage);
683
+ rule.context.options.field = field;
684
+ rule.context.options.scope = "sibling";
685
+ return this;
686
+ }
687
+ /**
688
+ * Field must be present if another field's value is in the given array
689
+ */
690
+ presentIfIn(field, values, errorMessage) {
691
+ const rule = this.addRule(presentIfRules.presentIfInRule, errorMessage);
692
+ rule.context.options.field = field;
693
+ rule.context.options.values = values;
694
+ rule.context.options.scope = "global";
695
+ return this;
696
+ }
697
+ /**
698
+ * Field must be present if another sibling field's value is in the given array
699
+ */
700
+ presentIfInSibling(field, values, errorMessage) {
701
+ const rule = this.addRule(presentIfRules.presentIfInRule, errorMessage);
702
+ rule.context.options.field = field;
703
+ rule.context.options.values = values;
704
+ rule.context.options.scope = "sibling";
705
+ return this;
706
+ }
707
+ /**
708
+ * Field must be present if another field's value is NOT in the given array
709
+ */
710
+ presentIfNotIn(field, values, errorMessage) {
711
+ const rule = this.addRule(presentIfRules.presentIfNotInRule, errorMessage);
712
+ rule.context.options.field = field;
713
+ rule.context.options.values = values;
714
+ rule.context.options.scope = "global";
715
+ return this;
716
+ }
717
+ /**
718
+ * Field must be present if another sibling field's value is NOT in the given array
719
+ */
720
+ presentIfNotInSibling(field, values, errorMessage) {
721
+ const rule = this.addRule(presentIfRules.presentIfNotInRule, errorMessage);
722
+ rule.context.options.field = field;
723
+ rule.context.options.values = values;
724
+ rule.context.options.scope = "sibling";
725
+ return this;
726
+ }
727
+ // ==================== PRESENT: BASED ON MULTIPLE FIELDS (ALL) ====================
728
+ /**
729
+ * Field must be present if all specified fields exist
730
+ */
731
+ presentWithAll(fields, errorMessage) {
732
+ const rule = this.addRule(presentWithRules.presentWithAllRule, errorMessage);
733
+ rule.context.options.fields = fields;
734
+ rule.context.options.scope = "global";
735
+ return this;
736
+ }
737
+ /**
738
+ * Field must be present if all specified sibling fields exist
739
+ */
740
+ presentWithAllSiblings(fields, errorMessage) {
741
+ const rule = this.addRule(presentWithRules.presentWithAllRule, errorMessage);
742
+ rule.context.options.fields = fields;
743
+ rule.context.options.scope = "sibling";
744
+ return this;
745
+ }
746
+ /**
747
+ * Field must be present if all specified fields are missing
748
+ */
749
+ presentWithoutAll(fields, errorMessage) {
750
+ const rule = this.addRule(presentWithoutRules.presentWithoutAllRule, errorMessage);
751
+ rule.context.options.fields = fields;
752
+ rule.context.options.scope = "global";
753
+ return this;
754
+ }
755
+ /**
756
+ * Field must be present if all specified sibling fields are missing
757
+ */
758
+ presentWithoutAllSiblings(fields, errorMessage) {
759
+ const rule = this.addRule(presentWithoutRules.presentWithoutAllRule, errorMessage);
760
+ rule.context.options.fields = fields;
761
+ rule.context.options.scope = "sibling";
762
+ return this;
763
+ }
764
+ // ==================== PRESENT: BASED ON MULTIPLE FIELDS (ANY) ====================
765
+ /**
766
+ * Field must be present if any of the specified fields exists
767
+ */
768
+ presentWithAny(fields, errorMessage) {
769
+ const rule = this.addRule(presentWithRules.presentWithAnyRule, errorMessage);
770
+ rule.context.options.fields = fields;
771
+ rule.context.options.scope = "global";
772
+ return this;
773
+ }
774
+ /**
775
+ * Field must be present if any of the specified sibling fields exists
776
+ */
777
+ presentWithAnySiblings(fields, errorMessage) {
778
+ const rule = this.addRule(presentWithRules.presentWithAnyRule, errorMessage);
779
+ rule.context.options.fields = fields;
780
+ rule.context.options.scope = "sibling";
781
+ return this;
782
+ }
783
+ /**
784
+ * Field must be present if any of the specified fields is missing
785
+ */
786
+ presentWithoutAny(fields, errorMessage) {
787
+ const rule = this.addRule(presentWithoutRules.presentWithoutAnyRule, errorMessage);
788
+ rule.context.options.fields = fields;
789
+ rule.context.options.scope = "global";
790
+ return this;
791
+ }
792
+ /**
793
+ * Field must be present if any of the specified sibling fields is missing
794
+ */
795
+ presentWithoutAnySiblings(fields, errorMessage) {
796
+ const rule = this.addRule(presentWithoutRules.presentWithoutAnyRule, errorMessage);
797
+ rule.context.options.fields = fields;
798
+ rule.context.options.scope = "sibling";
799
+ return this;
800
+ }
801
+ /**
802
+ * Mutate the data
803
+ */
804
+ async mutate(data, context) {
805
+ let mutatedData = data;
806
+ for (const mutator of this.mutators) {
807
+ mutator.context.ctx = context;
808
+ mutatedData = await mutator.mutate(mutatedData, mutator.context);
809
+ }
810
+ return mutatedData;
811
+ }
812
+ /**
813
+ * Value is forbidden to be present
814
+ */
815
+ forbidden(errorMessage) {
816
+ this.addRule(forbidden.forbiddenRule, errorMessage);
817
+ return this;
818
+ }
819
+ /**
820
+ * Apply different validation rules based on another field's value (global scope)
821
+ *
822
+ * Use this when you need to apply completely different validators
823
+ * based on another field's value (not just required/optional).
824
+ *
825
+ * @param field - Field name to check (can be nested with dot notation)
826
+ * @param options - Validation options per field value
827
+ *
828
+ * @example
829
+ * ```ts
830
+ * // Different allowed values based on user type
831
+ * v.object({
832
+ * userType: v.string().in(['admin', 'user']),
833
+ * role: v.string().when('userType', {
834
+ * is: {
835
+ * admin: v.string().in(['super', 'moderator']),
836
+ * user: v.string().in(['member', 'guest'])
837
+ * },
838
+ * otherwise: v.string().optional()
839
+ * })
840
+ * })
841
+ *
842
+ * // Different validation rules based on type
843
+ * v.object({
844
+ * contactType: v.string().in(['email', 'phone']),
845
+ * contact: v.string().when('contactType', {
846
+ * is: {
847
+ * email: v.string().email(),
848
+ * phone: v.string().pattern(/^\d{10}$/)
849
+ * }
850
+ * })
851
+ * })
852
+ * ```
853
+ * @category Conditional Validation
854
+ */
855
+ when(field, options) {
856
+ const rule = this.addRule(when.whenRule);
857
+ rule.context.options.field = field;
858
+ rule.context.options.is = options.is;
859
+ rule.context.options.otherwise = options.otherwise;
860
+ rule.context.options.scope = "global";
861
+ return this;
862
+ }
863
+ /**
864
+ * Apply different validation rules based on sibling field's value
865
+ *
866
+ * Use this for nested objects where you need to check a field
867
+ * within the same parent object.
868
+ *
869
+ * @param siblingField - Sibling field name to check
870
+ * @param options - Validation options per field value
871
+ *
872
+ * @example
873
+ * ```ts
874
+ * // Array of users with role-based permissions
875
+ * v.array(v.object({
876
+ * userType: v.string().in(['admin', 'user']),
877
+ * permissions: v.string().whenSibling('userType', {
878
+ * is: {
879
+ * admin: v.string().in(['read', 'write', 'delete']),
880
+ * user: v.string().in(['read'])
881
+ * }
882
+ * })
883
+ * }))
884
+ * ```
885
+ * @category Conditional Validation
886
+ */
887
+ whenSibling(siblingField, options) {
888
+ const rule = this.addRule(when.whenRule);
889
+ rule.context.options.field = siblingField;
890
+ rule.context.options.is = options.is;
891
+ rule.context.options.otherwise = options.otherwise;
892
+ rule.context.options.scope = "sibling";
893
+ return this;
894
+ }
895
+ /**
896
+ * Set the label for the validator that will be matching the :input attribute
897
+ */
898
+ label(label) {
899
+ this.attributesText.input = label;
900
+ return this;
901
+ }
902
+ /**
903
+ * Validate the data
904
+ */
905
+ async validate(data, context) {
906
+ // If allowsEmpty is enabled and the value is empty, skip validation
907
+ if (this.shouldAllowEmpty && supportiveIs.isEmpty(data)) {
908
+ return {
909
+ isValid: true,
910
+ errors: [],
911
+ data,
912
+ };
913
+ }
914
+ const mutatedData = await this.mutate(data ?? this.defaultValue, context);
915
+ const errors = [];
916
+ let isValid = true;
917
+ const isFirstErrorOnly = context.configurations?.firstErrorOnly ?? true;
918
+ for (const rule of this.rules) {
919
+ if ((rule.requiresValue ?? true) && data === undefined)
920
+ continue;
921
+ this.setRuleAttributesList(rule);
922
+ const result = await rule.validate(mutatedData, context);
923
+ if (result.isValid === false) {
924
+ isValid = false;
925
+ errors.push({
926
+ type: rule.name,
927
+ error: result.error,
928
+ input: result.path ?? context.path,
929
+ });
930
+ if (isFirstErrorOnly) {
931
+ break;
932
+ }
933
+ }
934
+ }
935
+ return {
936
+ isValid,
937
+ errors,
938
+ data: await this.startTransformationPipeline(mutatedData, context),
939
+ };
940
+ }
941
+ /**
942
+ * Set rule attributes list
943
+ */
944
+ setRuleAttributesList(rule) {
945
+ rule.context.attributesList =
946
+ typeof this.attributesText[rule.name] === "object"
947
+ ? this.attributesText[rule.name]
948
+ : this.attributesText;
949
+ }
950
+ }exports.BaseValidator=BaseValidator;//# sourceMappingURL=base-validator.js.map