@willaimg/yatsp 4.3.6

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 (830) hide show
  1. package/README.md +22 -0
  2. package/compile.cjs +96 -0
  3. package/compile.d.cts +1 -0
  4. package/compile.d.ts +1 -0
  5. package/compile.js +52 -0
  6. package/index.cjs +52 -0
  7. package/index.d.cts +3 -0
  8. package/index.d.ts +3 -0
  9. package/index.js +7 -0
  10. package/locales/index.cjs +36 -0
  11. package/locales/index.d.cts +1 -0
  12. package/locales/index.d.ts +1 -0
  13. package/locales/index.js +1 -0
  14. package/mini/index.cjs +51 -0
  15. package/mini/index.d.cts +3 -0
  16. package/mini/index.d.ts +3 -0
  17. package/mini/index.js +3 -0
  18. package/package.json +142 -0
  19. package/src/compile.ts +56 -0
  20. package/src/index.ts +7 -0
  21. package/src/locales/index.ts +1 -0
  22. package/src/mini/index.ts +3 -0
  23. package/src/v3/YatspError.ts +340 -0
  24. package/src/v3/benchmarks/datetime.ts +58 -0
  25. package/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  26. package/src/v3/benchmarks/index.ts +59 -0
  27. package/src/v3/benchmarks/ipv4.ts +57 -0
  28. package/src/v3/benchmarks/object.ts +69 -0
  29. package/src/v3/benchmarks/primitives.ts +162 -0
  30. package/src/v3/benchmarks/realworld.ts +63 -0
  31. package/src/v3/benchmarks/string.ts +55 -0
  32. package/src/v3/benchmarks/union.ts +80 -0
  33. package/src/v3/errors.ts +13 -0
  34. package/src/v3/external.ts +6 -0
  35. package/src/v3/helpers/enumUtil.ts +17 -0
  36. package/src/v3/helpers/errorUtil.ts +8 -0
  37. package/src/v3/helpers/parseUtil.ts +176 -0
  38. package/src/v3/helpers/partialUtil.ts +34 -0
  39. package/src/v3/helpers/typeAliases.ts +2 -0
  40. package/src/v3/helpers/util.ts +224 -0
  41. package/src/v3/index.ts +4 -0
  42. package/src/v3/locales/en.ts +124 -0
  43. package/src/v3/standard-schema.ts +113 -0
  44. package/src/v3/tests/Mocker.ts +54 -0
  45. package/src/v3/tests/all-errors.test.ts +157 -0
  46. package/src/v3/tests/anyunknown.test.ts +28 -0
  47. package/src/v3/tests/array.test.ts +71 -0
  48. package/src/v3/tests/async-parsing.test.ts +388 -0
  49. package/src/v3/tests/async-refinements.test.ts +46 -0
  50. package/src/v3/tests/base.test.ts +29 -0
  51. package/src/v3/tests/bigint.test.ts +55 -0
  52. package/src/v3/tests/branded.test.ts +53 -0
  53. package/src/v3/tests/catch.test.ts +220 -0
  54. package/src/v3/tests/coerce.test.ts +133 -0
  55. package/src/v3/tests/complex.test.ts +70 -0
  56. package/src/v3/tests/custom.test.ts +31 -0
  57. package/src/v3/tests/date.test.ts +32 -0
  58. package/src/v3/tests/deepmasking.test.ts +186 -0
  59. package/src/v3/tests/default.test.ts +112 -0
  60. package/src/v3/tests/description.test.ts +33 -0
  61. package/src/v3/tests/discriminated-unions.test.ts +315 -0
  62. package/src/v3/tests/enum.test.ts +80 -0
  63. package/src/v3/tests/error.test.ts +586 -0
  64. package/src/v3/tests/firstparty.test.ts +87 -0
  65. package/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  66. package/src/v3/tests/function.test.ts +261 -0
  67. package/src/v3/tests/generics.test.ts +48 -0
  68. package/src/v3/tests/instanceof.test.ts +37 -0
  69. package/src/v3/tests/intersection.test.ts +128 -0
  70. package/src/v3/tests/language-server.source.ts +76 -0
  71. package/src/v3/tests/language-server.test.ts +206 -0
  72. package/src/v3/tests/literal.test.ts +36 -0
  73. package/src/v3/tests/map.test.ts +110 -0
  74. package/src/v3/tests/masking.test.ts +4 -0
  75. package/src/v3/tests/mocker.test.ts +19 -0
  76. package/src/v3/tests/nan.test.ts +24 -0
  77. package/src/v3/tests/nativeEnum.test.ts +87 -0
  78. package/src/v3/tests/nullable.test.ts +42 -0
  79. package/src/v3/tests/number.test.ts +176 -0
  80. package/src/v3/tests/object-augmentation.test.ts +29 -0
  81. package/src/v3/tests/object-in-es5-env.test.ts +29 -0
  82. package/src/v3/tests/object.test.ts +431 -0
  83. package/src/v3/tests/optional.test.ts +42 -0
  84. package/src/v3/tests/parseUtil.test.ts +23 -0
  85. package/src/v3/tests/parser.test.ts +41 -0
  86. package/src/v3/tests/partials.test.ts +243 -0
  87. package/src/v3/tests/pickomit.test.ts +111 -0
  88. package/src/v3/tests/pipeline.test.ts +29 -0
  89. package/src/v3/tests/preprocess.test.ts +186 -0
  90. package/src/v3/tests/primitive.test.ts +440 -0
  91. package/src/v3/tests/promise.test.ts +90 -0
  92. package/src/v3/tests/readonly.test.ts +114 -0
  93. package/src/v3/tests/record.test.ts +171 -0
  94. package/src/v3/tests/recursive.test.ts +197 -0
  95. package/src/v3/tests/refine.test.ts +313 -0
  96. package/src/v3/tests/safeparse.test.ts +27 -0
  97. package/src/v3/tests/set.test.ts +142 -0
  98. package/src/v3/tests/standard-schema.test.ts +83 -0
  99. package/src/v3/tests/string.test.ts +922 -0
  100. package/src/v3/tests/transformer.test.ts +233 -0
  101. package/src/v3/tests/tuple.test.ts +90 -0
  102. package/src/v3/tests/unions.test.ts +57 -0
  103. package/src/v3/tests/validations.test.ts +133 -0
  104. package/src/v3/tests/void.test.ts +15 -0
  105. package/src/v3/types.ts +5162 -0
  106. package/src/v4/classic/checks.ts +33 -0
  107. package/src/v4/classic/coerce.ts +27 -0
  108. package/src/v4/classic/compat.ts +78 -0
  109. package/src/v4/classic/deep-partial.ts +76 -0
  110. package/src/v4/classic/errors.ts +97 -0
  111. package/src/v4/classic/external.ts +57 -0
  112. package/src/v4/classic/from-json-schema.ts +944 -0
  113. package/src/v4/classic/in-out.ts +45 -0
  114. package/src/v4/classic/index.ts +5 -0
  115. package/src/v4/classic/iso.ts +20 -0
  116. package/src/v4/classic/parse.ts +88 -0
  117. package/src/v4/classic/schemas.ts +2994 -0
  118. package/src/v4/classic/tests/anyunknown.test.ts +26 -0
  119. package/src/v4/classic/tests/apply.test.ts +86 -0
  120. package/src/v4/classic/tests/array.test.ts +264 -0
  121. package/src/v4/classic/tests/assignability.test.ts +402 -0
  122. package/src/v4/classic/tests/async-parsing.test.ts +381 -0
  123. package/src/v4/classic/tests/async-refinements.test.ts +68 -0
  124. package/src/v4/classic/tests/base.test.ts +7 -0
  125. package/src/v4/classic/tests/bigint.test.ts +89 -0
  126. package/src/v4/classic/tests/brand.test.ts +106 -0
  127. package/src/v4/classic/tests/catch.test.ts +604 -0
  128. package/src/v4/classic/tests/coalesce.test.ts +20 -0
  129. package/src/v4/classic/tests/codec-examples.test.ts +572 -0
  130. package/src/v4/classic/tests/codec.test.ts +704 -0
  131. package/src/v4/classic/tests/coerce.test.ts +160 -0
  132. package/src/v4/classic/tests/continuability.test.ts +374 -0
  133. package/src/v4/classic/tests/credit-card.test.ts +76 -0
  134. package/src/v4/classic/tests/custom.test.ts +40 -0
  135. package/src/v4/classic/tests/cyclic-data.test.ts +985 -0
  136. package/src/v4/classic/tests/date.test.ts +92 -0
  137. package/src/v4/classic/tests/datetime.test.ts +316 -0
  138. package/src/v4/classic/tests/deep-partial.test.ts +380 -0
  139. package/src/v4/classic/tests/default-locale.test.ts +32 -0
  140. package/src/v4/classic/tests/default.test.ts +455 -0
  141. package/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  142. package/src/v4/classic/tests/description.test.ts +32 -0
  143. package/src/v4/classic/tests/detached-methods.test.ts +226 -0
  144. package/src/v4/classic/tests/discriminated-unions.test.ts +942 -0
  145. package/src/v4/classic/tests/enum.test.ts +305 -0
  146. package/src/v4/classic/tests/error-utils.test.ts +917 -0
  147. package/src/v4/classic/tests/error.test.ts +1108 -0
  148. package/src/v4/classic/tests/file.test.ts +96 -0
  149. package/src/v4/classic/tests/firstparty.test.ts +179 -0
  150. package/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  151. package/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
  152. package/src/v4/classic/tests/function.test.ts +391 -0
  153. package/src/v4/classic/tests/generics.test.ts +72 -0
  154. package/src/v4/classic/tests/global-config.test.ts +32 -0
  155. package/src/v4/classic/tests/hash.test.ts +67 -0
  156. package/src/v4/classic/tests/iban.test.ts +81 -0
  157. package/src/v4/classic/tests/in-out.test.ts +159 -0
  158. package/src/v4/classic/tests/index.test.ts +958 -0
  159. package/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  160. package/src/v4/classic/tests/instanceof.test.ts +127 -0
  161. package/src/v4/classic/tests/intersection.test.ts +334 -0
  162. package/src/v4/classic/tests/issue-schema.test.ts +215 -0
  163. package/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
  164. package/src/v4/classic/tests/json.test.ts +109 -0
  165. package/src/v4/classic/tests/lazy.test.ts +262 -0
  166. package/src/v4/classic/tests/literal.test.ts +128 -0
  167. package/src/v4/classic/tests/locales_ka.test.ts +29 -0
  168. package/src/v4/classic/tests/locales_ro.test.ts +24 -0
  169. package/src/v4/classic/tests/map.test.ts +342 -0
  170. package/src/v4/classic/tests/nan.test.ts +21 -0
  171. package/src/v4/classic/tests/nested-refine.test.ts +168 -0
  172. package/src/v4/classic/tests/nonoptional.test.ts +101 -0
  173. package/src/v4/classic/tests/nullable.test.ts +22 -0
  174. package/src/v4/classic/tests/number.test.ts +401 -0
  175. package/src/v4/classic/tests/object.test.ts +1006 -0
  176. package/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  177. package/src/v4/classic/tests/optional.test.ts +366 -0
  178. package/src/v4/classic/tests/partial.test.ts +497 -0
  179. package/src/v4/classic/tests/pickomit.test.ts +211 -0
  180. package/src/v4/classic/tests/pipe.test.ts +101 -0
  181. package/src/v4/classic/tests/prefault.test.ts +144 -0
  182. package/src/v4/classic/tests/preprocess-types.test.ts +44 -0
  183. package/src/v4/classic/tests/preprocess.test.ts +351 -0
  184. package/src/v4/classic/tests/primitive.test.ts +175 -0
  185. package/src/v4/classic/tests/promise.test.ts +81 -0
  186. package/src/v4/classic/tests/properties.test.ts +141 -0
  187. package/src/v4/classic/tests/prototypes.test.ts +23 -0
  188. package/src/v4/classic/tests/readonly.test.ts +184 -0
  189. package/src/v4/classic/tests/record.test.ts +885 -0
  190. package/src/v4/classic/tests/recursive-types.test.ts +707 -0
  191. package/src/v4/classic/tests/redos.test.ts +68 -0
  192. package/src/v4/classic/tests/refine.test.ts +693 -0
  193. package/src/v4/classic/tests/registries.test.ts +243 -0
  194. package/src/v4/classic/tests/set.test.ts +190 -0
  195. package/src/v4/classic/tests/standard-schema.test.ts +153 -0
  196. package/src/v4/classic/tests/string-formats.test.ts +125 -0
  197. package/src/v4/classic/tests/string.test.ts +1440 -0
  198. package/src/v4/classic/tests/stringbool.test.ts +124 -0
  199. package/src/v4/classic/tests/template-literal.test.ts +814 -0
  200. package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  201. package/src/v4/classic/tests/to-json-schema.test.ts +4733 -0
  202. package/src/v4/classic/tests/transform.test.ts +378 -0
  203. package/src/v4/classic/tests/tuple.test.ts +511 -0
  204. package/src/v4/classic/tests/union.test.ts +310 -0
  205. package/src/v4/classic/tests/url.test.ts +13 -0
  206. package/src/v4/classic/tests/validate.test.ts +645 -0
  207. package/src/v4/classic/tests/validations.test.ts +283 -0
  208. package/src/v4/classic/tests/void.test.ts +12 -0
  209. package/src/v4/core/api.ts +1913 -0
  210. package/src/v4/core/checks.ts +1274 -0
  211. package/src/v4/core/compile.ts +2315 -0
  212. package/src/v4/core/core.ts +230 -0
  213. package/src/v4/core/doc.ts +52 -0
  214. package/src/v4/core/errors.ts +546 -0
  215. package/src/v4/core/index.ts +19 -0
  216. package/src/v4/core/json-schema-generator.ts +131 -0
  217. package/src/v4/core/json-schema-processors.ts +934 -0
  218. package/src/v4/core/json-schema.ts +148 -0
  219. package/src/v4/core/memoizer.ts +331 -0
  220. package/src/v4/core/parse.ts +309 -0
  221. package/src/v4/core/regexes.ts +217 -0
  222. package/src/v4/core/registries.ts +109 -0
  223. package/src/v4/core/schemas.ts +5295 -0
  224. package/src/v4/core/standard-schema.ts +159 -0
  225. package/src/v4/core/tests/cached.test.ts +54 -0
  226. package/src/v4/core/tests/compile-differential.test.ts +1004 -0
  227. package/src/v4/core/tests/compile-generative.test.ts +445 -0
  228. package/src/v4/core/tests/compile-global.test.ts +89 -0
  229. package/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  230. package/src/v4/core/tests/compile-stats.test.ts +34 -0
  231. package/src/v4/core/tests/compile.test.ts +2040 -0
  232. package/src/v4/core/tests/email-regex.test.ts +140 -0
  233. package/src/v4/core/tests/extend.test.ts +59 -0
  234. package/src/v4/core/tests/index.test.ts +46 -0
  235. package/src/v4/core/tests/locales/be.test.ts +124 -0
  236. package/src/v4/core/tests/locales/el.test.ts +214 -0
  237. package/src/v4/core/tests/locales/en.test.ts +22 -0
  238. package/src/v4/core/tests/locales/es.test.ts +180 -0
  239. package/src/v4/core/tests/locales/fr.test.ts +72 -0
  240. package/src/v4/core/tests/locales/he.test.ts +379 -0
  241. package/src/v4/core/tests/locales/hr.test.ts +163 -0
  242. package/src/v4/core/tests/locales/nl.test.ts +46 -0
  243. package/src/v4/core/tests/locales/parity.test.ts +42 -0
  244. package/src/v4/core/tests/locales/ru.test.ts +128 -0
  245. package/src/v4/core/tests/locales/tg.test.ts +85 -0
  246. package/src/v4/core/tests/locales/tk.test.ts +69 -0
  247. package/src/v4/core/tests/locales/tr.test.ts +69 -0
  248. package/src/v4/core/tests/locales/uz.test.ts +105 -0
  249. package/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  250. package/src/v4/core/tests/record-constructor.test.ts +125 -0
  251. package/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  252. package/src/v4/core/tests/treeshake.test.ts +51 -0
  253. package/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  254. package/src/v4/core/to-json-schema.ts +857 -0
  255. package/src/v4/core/util.ts +1284 -0
  256. package/src/v4/core/versions.ts +5 -0
  257. package/src/v4/core/visit.ts +193 -0
  258. package/src/v4/core/zsf.ts +323 -0
  259. package/src/v4/index.ts +4 -0
  260. package/src/v4/locales/ar.ts +120 -0
  261. package/src/v4/locales/az.ts +116 -0
  262. package/src/v4/locales/be.ts +188 -0
  263. package/src/v4/locales/bg.ts +133 -0
  264. package/src/v4/locales/bn.ts +123 -0
  265. package/src/v4/locales/ca.ts +121 -0
  266. package/src/v4/locales/ckb.ts +140 -0
  267. package/src/v4/locales/cs.ts +123 -0
  268. package/src/v4/locales/da.ts +128 -0
  269. package/src/v4/locales/de.ts +121 -0
  270. package/src/v4/locales/el.ts +124 -0
  271. package/src/v4/locales/en.ts +136 -0
  272. package/src/v4/locales/eo.ts +123 -0
  273. package/src/v4/locales/es.ts +145 -0
  274. package/src/v4/locales/fa.ts +131 -0
  275. package/src/v4/locales/fi.ts +126 -0
  276. package/src/v4/locales/fr-CA.ts +121 -0
  277. package/src/v4/locales/fr.ts +139 -0
  278. package/src/v4/locales/gu.ts +123 -0
  279. package/src/v4/locales/he.ts +253 -0
  280. package/src/v4/locales/hi.ts +126 -0
  281. package/src/v4/locales/hr.ts +135 -0
  282. package/src/v4/locales/hu.ts +122 -0
  283. package/src/v4/locales/hy.ts +175 -0
  284. package/src/v4/locales/id.ts +120 -0
  285. package/src/v4/locales/index.ts +63 -0
  286. package/src/v4/locales/is.ts +124 -0
  287. package/src/v4/locales/it.ts +121 -0
  288. package/src/v4/locales/ja.ts +119 -0
  289. package/src/v4/locales/ka.ts +128 -0
  290. package/src/v4/locales/kh.ts +7 -0
  291. package/src/v4/locales/km.ts +124 -0
  292. package/src/v4/locales/kn.ts +126 -0
  293. package/src/v4/locales/ko.ts +126 -0
  294. package/src/v4/locales/lt.ts +243 -0
  295. package/src/v4/locales/mk.ts +123 -0
  296. package/src/v4/locales/ms.ts +120 -0
  297. package/src/v4/locales/ne.ts +128 -0
  298. package/src/v4/locales/nl.ts +126 -0
  299. package/src/v4/locales/nn.ts +121 -0
  300. package/src/v4/locales/no.ts +121 -0
  301. package/src/v4/locales/ota.ts +122 -0
  302. package/src/v4/locales/pl.ts +123 -0
  303. package/src/v4/locales/ps.ts +131 -0
  304. package/src/v4/locales/pt-BR.ts +161 -0
  305. package/src/v4/locales/pt.ts +159 -0
  306. package/src/v4/locales/ro.ts +132 -0
  307. package/src/v4/locales/ru.ts +188 -0
  308. package/src/v4/locales/sk.ts +123 -0
  309. package/src/v4/locales/sl.ts +123 -0
  310. package/src/v4/locales/sv.ts +124 -0
  311. package/src/v4/locales/ta.ts +123 -0
  312. package/src/v4/locales/tg.ts +135 -0
  313. package/src/v4/locales/th.ts +124 -0
  314. package/src/v4/locales/tk.ts +113 -0
  315. package/src/v4/locales/tr.ts +116 -0
  316. package/src/v4/locales/ua.ts +7 -0
  317. package/src/v4/locales/uk.ts +122 -0
  318. package/src/v4/locales/ur.ts +124 -0
  319. package/src/v4/locales/uz.ts +120 -0
  320. package/src/v4/locales/vi.ts +122 -0
  321. package/src/v4/locales/yo.ts +129 -0
  322. package/src/v4/locales/zh-CN.ts +121 -0
  323. package/src/v4/locales/zh-TW.ts +120 -0
  324. package/src/v4/mini/checks.ts +33 -0
  325. package/src/v4/mini/coerce.ts +27 -0
  326. package/src/v4/mini/deep-partial.ts +73 -0
  327. package/src/v4/mini/external.ts +52 -0
  328. package/src/v4/mini/in-out.ts +45 -0
  329. package/src/v4/mini/index.ts +3 -0
  330. package/src/v4/mini/iso.ts +66 -0
  331. package/src/v4/mini/parse.ts +16 -0
  332. package/src/v4/mini/schemas.ts +2093 -0
  333. package/src/v4/mini/tests/apply.test.ts +57 -0
  334. package/src/v4/mini/tests/assignability.test.ts +190 -0
  335. package/src/v4/mini/tests/brand.test.ts +94 -0
  336. package/src/v4/mini/tests/checks.test.ts +158 -0
  337. package/src/v4/mini/tests/codec.test.ts +582 -0
  338. package/src/v4/mini/tests/computed.test.ts +30 -0
  339. package/src/v4/mini/tests/cyclic-data.test.ts +84 -0
  340. package/src/v4/mini/tests/deep-partial.test.ts +54 -0
  341. package/src/v4/mini/tests/error.test.ts +41 -0
  342. package/src/v4/mini/tests/functions.test.ts +14 -0
  343. package/src/v4/mini/tests/index.test.ts +1148 -0
  344. package/src/v4/mini/tests/number.test.ts +109 -0
  345. package/src/v4/mini/tests/object.test.ts +292 -0
  346. package/src/v4/mini/tests/prototypes.test.ts +43 -0
  347. package/src/v4/mini/tests/recursive-types.test.ts +341 -0
  348. package/src/v4/mini/tests/standard-schema.test.ts +50 -0
  349. package/src/v4/mini/tests/string.test.ts +396 -0
  350. package/src/v4-mini/index.ts +3 -0
  351. package/v3/YatspError.cjs +167 -0
  352. package/v3/YatspError.d.cts +164 -0
  353. package/v3/YatspError.d.ts +164 -0
  354. package/v3/YatspError.js +143 -0
  355. package/v3/errors.cjs +36 -0
  356. package/v3/errors.d.cts +5 -0
  357. package/v3/errors.d.ts +5 -0
  358. package/v3/errors.js +9 -0
  359. package/v3/external.cjs +41 -0
  360. package/v3/external.d.cts +6 -0
  361. package/v3/external.d.ts +6 -0
  362. package/v3/external.js +6 -0
  363. package/v3/helpers/enumUtil.cjs +21 -0
  364. package/v3/helpers/enumUtil.d.cts +8 -0
  365. package/v3/helpers/enumUtil.d.ts +8 -0
  366. package/v3/helpers/enumUtil.js +1 -0
  367. package/v3/helpers/errorUtil.cjs +28 -0
  368. package/v3/helpers/errorUtil.d.cts +9 -0
  369. package/v3/helpers/errorUtil.d.ts +9 -0
  370. package/v3/helpers/errorUtil.js +6 -0
  371. package/v3/helpers/parseUtil.cjs +143 -0
  372. package/v3/helpers/parseUtil.d.cts +78 -0
  373. package/v3/helpers/parseUtil.d.ts +78 -0
  374. package/v3/helpers/parseUtil.js +109 -0
  375. package/v3/helpers/partialUtil.cjs +21 -0
  376. package/v3/helpers/partialUtil.d.cts +8 -0
  377. package/v3/helpers/partialUtil.d.ts +8 -0
  378. package/v3/helpers/partialUtil.js +1 -0
  379. package/v3/helpers/typeAliases.cjs +21 -0
  380. package/v3/helpers/typeAliases.d.cts +2 -0
  381. package/v3/helpers/typeAliases.d.ts +2 -0
  382. package/v3/helpers/typeAliases.js +1 -0
  383. package/v3/helpers/util.cjs +156 -0
  384. package/v3/helpers/util.d.cts +85 -0
  385. package/v3/helpers/util.d.ts +85 -0
  386. package/v3/helpers/util.js +133 -0
  387. package/v3/index.cjs +52 -0
  388. package/v3/index.d.cts +4 -0
  389. package/v3/index.d.ts +4 -0
  390. package/v3/index.js +4 -0
  391. package/v3/locales/en.cjs +112 -0
  392. package/v3/locales/en.d.cts +3 -0
  393. package/v3/locales/en.d.ts +3 -0
  394. package/v3/locales/en.js +109 -0
  395. package/v3/standard-schema.cjs +21 -0
  396. package/v3/standard-schema.d.cts +102 -0
  397. package/v3/standard-schema.d.ts +102 -0
  398. package/v3/standard-schema.js +1 -0
  399. package/v3/types.cjs +3798 -0
  400. package/v3/types.d.cts +1034 -0
  401. package/v3/types.d.ts +1034 -0
  402. package/v3/types.js +3697 -0
  403. package/v4/classic/checks.cjs +53 -0
  404. package/v4/classic/checks.d.cts +1 -0
  405. package/v4/classic/checks.d.ts +1 -0
  406. package/v4/classic/checks.js +1 -0
  407. package/v4/classic/coerce.cjs +66 -0
  408. package/v4/classic/coerce.d.cts +17 -0
  409. package/v4/classic/coerce.d.ts +17 -0
  410. package/v4/classic/coerce.js +17 -0
  411. package/v4/classic/compat.cjs +80 -0
  412. package/v4/classic/compat.d.cts +48 -0
  413. package/v4/classic/compat.d.ts +48 -0
  414. package/v4/classic/compat.js +31 -0
  415. package/v4/classic/deep-partial.cjs +58 -0
  416. package/v4/classic/deep-partial.d.cts +14 -0
  417. package/v4/classic/deep-partial.d.ts +14 -0
  418. package/v4/classic/deep-partial.js +13 -0
  419. package/v4/classic/errors.cjs +102 -0
  420. package/v4/classic/errors.d.cts +29 -0
  421. package/v4/classic/errors.d.ts +29 -0
  422. package/v4/classic/errors.js +57 -0
  423. package/v4/classic/external.cjs +97 -0
  424. package/v4/classic/external.d.cts +19 -0
  425. package/v4/classic/external.d.ts +19 -0
  426. package/v4/classic/external.js +17 -0
  427. package/v4/classic/from-json-schema.cjs +926 -0
  428. package/v4/classic/from-json-schema.d.cts +12 -0
  429. package/v4/classic/from-json-schema.d.ts +12 -0
  430. package/v4/classic/from-json-schema.js +881 -0
  431. package/v4/classic/in-out.cjs +82 -0
  432. package/v4/classic/in-out.d.cts +8 -0
  433. package/v4/classic/in-out.d.ts +8 -0
  434. package/v4/classic/in-out.js +36 -0
  435. package/v4/classic/index.cjs +52 -0
  436. package/v4/classic/index.d.cts +3 -0
  437. package/v4/classic/index.d.ts +3 -0
  438. package/v4/classic/index.js +4 -0
  439. package/v4/classic/iso.cjs +68 -0
  440. package/v4/classic/iso.d.cts +7 -0
  441. package/v4/classic/iso.d.ts +7 -0
  442. package/v4/classic/iso.js +15 -0
  443. package/v4/classic/parse.cjs +63 -0
  444. package/v4/classic/parse.d.cts +44 -0
  445. package/v4/classic/parse.d.ts +44 -0
  446. package/v4/classic/parse.js +16 -0
  447. package/v4/classic/schemas.cjs +1676 -0
  448. package/v4/classic/schemas.d.cts +816 -0
  449. package/v4/classic/schemas.d.ts +816 -0
  450. package/v4/classic/schemas.js +1535 -0
  451. package/v4/core/api.cjs +1269 -0
  452. package/v4/core/api.d.cts +335 -0
  453. package/v4/core/api.d.ts +335 -0
  454. package/v4/core/api.js +1107 -0
  455. package/v4/core/checks.cjs +561 -0
  456. package/v4/core/checks.d.cts +294 -0
  457. package/v4/core/checks.d.ts +294 -0
  458. package/v4/core/checks.js +516 -0
  459. package/v4/core/compile.cjs +1908 -0
  460. package/v4/core/compile.d.cts +65 -0
  461. package/v4/core/compile.d.ts +65 -0
  462. package/v4/core/compile.js +1858 -0
  463. package/v4/core/core.cjs +167 -0
  464. package/v4/core/core.d.cts +82 -0
  465. package/v4/core/core.d.ts +82 -0
  466. package/v4/core/core.js +141 -0
  467. package/v4/core/doc.cjs +61 -0
  468. package/v4/core/doc.d.cts +16 -0
  469. package/v4/core/doc.d.ts +16 -0
  470. package/v4/core/doc.js +38 -0
  471. package/v4/core/errors.cjs +317 -0
  472. package/v4/core/errors.d.cts +225 -0
  473. package/v4/core/errors.d.ts +225 -0
  474. package/v4/core/errors.js +267 -0
  475. package/v4/core/index.cjs +70 -0
  476. package/v4/core/index.d.cts +19 -0
  477. package/v4/core/index.d.ts +19 -0
  478. package/v4/core/index.js +19 -0
  479. package/v4/core/json-schema-generator.cjs +122 -0
  480. package/v4/core/json-schema-generator.d.cts +65 -0
  481. package/v4/core/json-schema-generator.d.ts +65 -0
  482. package/v4/core/json-schema-generator.js +99 -0
  483. package/v4/core/json-schema-processors.cjs +929 -0
  484. package/v4/core/json-schema-processors.d.cts +65 -0
  485. package/v4/core/json-schema-processors.d.ts +65 -0
  486. package/v4/core/json-schema-processors.js +843 -0
  487. package/v4/core/json-schema.cjs +21 -0
  488. package/v4/core/json-schema.d.cts +89 -0
  489. package/v4/core/json-schema.d.ts +89 -0
  490. package/v4/core/json-schema.js +1 -0
  491. package/v4/core/memoizer.cjs +360 -0
  492. package/v4/core/memoizer.d.cts +15 -0
  493. package/v4/core/memoizer.d.ts +15 -0
  494. package/v4/core/memoizer.js +311 -0
  495. package/v4/core/parse.cjs +233 -0
  496. package/v4/core/parse.d.cts +52 -0
  497. package/v4/core/parse.d.ts +52 -0
  498. package/v4/core/parse.js +175 -0
  499. package/v4/core/regexes.cjs +209 -0
  500. package/v4/core/regexes.d.cts +90 -0
  501. package/v4/core/regexes.d.ts +90 -0
  502. package/v4/core/regexes.js +156 -0
  503. package/v4/core/registries.cjs +76 -0
  504. package/v4/core/registries.d.cts +35 -0
  505. package/v4/core/registries.d.ts +35 -0
  506. package/v4/core/registries.js +52 -0
  507. package/v4/core/schemas.cjs +2669 -0
  508. package/v4/core/schemas.d.cts +1273 -0
  509. package/v4/core/schemas.d.ts +1273 -0
  510. package/v4/core/schemas.js +2606 -0
  511. package/v4/core/standard-schema.cjs +21 -0
  512. package/v4/core/standard-schema.d.cts +126 -0
  513. package/v4/core/standard-schema.d.ts +126 -0
  514. package/v4/core/standard-schema.js +1 -0
  515. package/v4/core/to-json-schema.cjs +681 -0
  516. package/v4/core/to-json-schema.d.cts +154 -0
  517. package/v4/core/to-json-schema.d.ts +154 -0
  518. package/v4/core/to-json-schema.js +651 -0
  519. package/v4/core/util.cjs +949 -0
  520. package/v4/core/util.d.cts +278 -0
  521. package/v4/core/util.d.ts +278 -0
  522. package/v4/core/util.js +859 -0
  523. package/v4/core/versions.cjs +27 -0
  524. package/v4/core/versions.d.cts +5 -0
  525. package/v4/core/versions.d.ts +5 -0
  526. package/v4/core/versions.js +5 -0
  527. package/v4/core/visit.cjs +214 -0
  528. package/v4/core/visit.d.cts +30 -0
  529. package/v4/core/visit.d.ts +30 -0
  530. package/v4/core/visit.js +169 -0
  531. package/v4/index.cjs +51 -0
  532. package/v4/index.d.cts +3 -0
  533. package/v4/index.d.ts +3 -0
  534. package/v4/index.js +4 -0
  535. package/v4/locales/ar.cjs +138 -0
  536. package/v4/locales/ar.d.cts +5 -0
  537. package/v4/locales/ar.d.ts +4 -0
  538. package/v4/locales/ar.js +111 -0
  539. package/v4/locales/az.cjs +137 -0
  540. package/v4/locales/az.d.cts +5 -0
  541. package/v4/locales/az.d.ts +4 -0
  542. package/v4/locales/az.js +110 -0
  543. package/v4/locales/be.cjs +195 -0
  544. package/v4/locales/be.d.cts +5 -0
  545. package/v4/locales/be.d.ts +4 -0
  546. package/v4/locales/be.js +168 -0
  547. package/v4/locales/bg.cjs +152 -0
  548. package/v4/locales/bg.d.cts +5 -0
  549. package/v4/locales/bg.d.ts +4 -0
  550. package/v4/locales/bg.js +125 -0
  551. package/v4/locales/bn.cjs +140 -0
  552. package/v4/locales/bn.d.cts +5 -0
  553. package/v4/locales/bn.d.ts +4 -0
  554. package/v4/locales/bn.js +113 -0
  555. package/v4/locales/ca.cjs +139 -0
  556. package/v4/locales/ca.d.cts +5 -0
  557. package/v4/locales/ca.d.ts +4 -0
  558. package/v4/locales/ca.js +112 -0
  559. package/v4/locales/ckb.cjs +160 -0
  560. package/v4/locales/ckb.d.cts +5 -0
  561. package/v4/locales/ckb.d.ts +4 -0
  562. package/v4/locales/ckb.js +133 -0
  563. package/v4/locales/cs.cjs +143 -0
  564. package/v4/locales/cs.d.cts +5 -0
  565. package/v4/locales/cs.d.ts +4 -0
  566. package/v4/locales/cs.js +116 -0
  567. package/v4/locales/da.cjs +147 -0
  568. package/v4/locales/da.d.cts +5 -0
  569. package/v4/locales/da.d.ts +4 -0
  570. package/v4/locales/da.js +120 -0
  571. package/v4/locales/de.cjs +140 -0
  572. package/v4/locales/de.d.cts +5 -0
  573. package/v4/locales/de.d.ts +4 -0
  574. package/v4/locales/de.js +113 -0
  575. package/v4/locales/el.cjs +139 -0
  576. package/v4/locales/el.d.cts +5 -0
  577. package/v4/locales/el.d.ts +4 -0
  578. package/v4/locales/el.js +112 -0
  579. package/v4/locales/en.cjs +152 -0
  580. package/v4/locales/en.d.cts +5 -0
  581. package/v4/locales/en.d.ts +4 -0
  582. package/v4/locales/en.js +125 -0
  583. package/v4/locales/eo.cjs +141 -0
  584. package/v4/locales/eo.d.cts +5 -0
  585. package/v4/locales/eo.d.ts +4 -0
  586. package/v4/locales/eo.js +114 -0
  587. package/v4/locales/es.cjs +163 -0
  588. package/v4/locales/es.d.cts +5 -0
  589. package/v4/locales/es.d.ts +4 -0
  590. package/v4/locales/es.js +136 -0
  591. package/v4/locales/fa.cjs +146 -0
  592. package/v4/locales/fa.d.cts +5 -0
  593. package/v4/locales/fa.d.ts +4 -0
  594. package/v4/locales/fa.js +119 -0
  595. package/v4/locales/fi.cjs +144 -0
  596. package/v4/locales/fi.d.cts +5 -0
  597. package/v4/locales/fi.d.ts +4 -0
  598. package/v4/locales/fi.js +117 -0
  599. package/v4/locales/fr-CA.cjs +139 -0
  600. package/v4/locales/fr-CA.d.cts +5 -0
  601. package/v4/locales/fr-CA.d.ts +4 -0
  602. package/v4/locales/fr-CA.js +112 -0
  603. package/v4/locales/fr.cjs +156 -0
  604. package/v4/locales/fr.d.cts +5 -0
  605. package/v4/locales/fr.d.ts +4 -0
  606. package/v4/locales/fr.js +129 -0
  607. package/v4/locales/gu.cjs +140 -0
  608. package/v4/locales/gu.d.cts +5 -0
  609. package/v4/locales/gu.d.ts +4 -0
  610. package/v4/locales/gu.js +113 -0
  611. package/v4/locales/he.cjs +248 -0
  612. package/v4/locales/he.d.cts +5 -0
  613. package/v4/locales/he.d.ts +4 -0
  614. package/v4/locales/he.js +221 -0
  615. package/v4/locales/hi.cjs +138 -0
  616. package/v4/locales/hi.d.cts +5 -0
  617. package/v4/locales/hi.d.ts +4 -0
  618. package/v4/locales/hi.js +111 -0
  619. package/v4/locales/hr.cjs +153 -0
  620. package/v4/locales/hr.d.cts +5 -0
  621. package/v4/locales/hr.d.ts +4 -0
  622. package/v4/locales/hr.js +126 -0
  623. package/v4/locales/hu.cjs +140 -0
  624. package/v4/locales/hu.d.cts +5 -0
  625. package/v4/locales/hu.d.ts +4 -0
  626. package/v4/locales/hu.js +113 -0
  627. package/v4/locales/hy.cjs +185 -0
  628. package/v4/locales/hy.d.cts +5 -0
  629. package/v4/locales/hy.d.ts +4 -0
  630. package/v4/locales/hy.js +158 -0
  631. package/v4/locales/id.cjs +138 -0
  632. package/v4/locales/id.d.cts +5 -0
  633. package/v4/locales/id.d.ts +4 -0
  634. package/v4/locales/id.js +111 -0
  635. package/v4/locales/index.cjs +152 -0
  636. package/v4/locales/index.d.cts +63 -0
  637. package/v4/locales/index.d.ts +63 -0
  638. package/v4/locales/index.js +63 -0
  639. package/v4/locales/is.cjs +141 -0
  640. package/v4/locales/is.d.cts +5 -0
  641. package/v4/locales/is.d.ts +4 -0
  642. package/v4/locales/is.js +114 -0
  643. package/v4/locales/it.cjs +140 -0
  644. package/v4/locales/it.d.cts +5 -0
  645. package/v4/locales/it.d.ts +4 -0
  646. package/v4/locales/it.js +113 -0
  647. package/v4/locales/ja.cjs +139 -0
  648. package/v4/locales/ja.d.cts +5 -0
  649. package/v4/locales/ja.d.ts +4 -0
  650. package/v4/locales/ja.js +112 -0
  651. package/v4/locales/ka.cjs +144 -0
  652. package/v4/locales/ka.d.cts +5 -0
  653. package/v4/locales/ka.d.ts +4 -0
  654. package/v4/locales/ka.js +117 -0
  655. package/v4/locales/kh.cjs +12 -0
  656. package/v4/locales/kh.d.cts +5 -0
  657. package/v4/locales/kh.d.ts +5 -0
  658. package/v4/locales/kh.js +5 -0
  659. package/v4/locales/km.cjs +142 -0
  660. package/v4/locales/km.d.cts +5 -0
  661. package/v4/locales/km.d.ts +4 -0
  662. package/v4/locales/km.js +115 -0
  663. package/v4/locales/kn.cjs +143 -0
  664. package/v4/locales/kn.d.cts +5 -0
  665. package/v4/locales/kn.d.ts +4 -0
  666. package/v4/locales/kn.js +116 -0
  667. package/v4/locales/ko.cjs +143 -0
  668. package/v4/locales/ko.d.cts +5 -0
  669. package/v4/locales/ko.d.ts +4 -0
  670. package/v4/locales/ko.js +116 -0
  671. package/v4/locales/lt.cjs +234 -0
  672. package/v4/locales/lt.d.cts +5 -0
  673. package/v4/locales/lt.d.ts +4 -0
  674. package/v4/locales/lt.js +207 -0
  675. package/v4/locales/mk.cjs +141 -0
  676. package/v4/locales/mk.d.cts +5 -0
  677. package/v4/locales/mk.d.ts +4 -0
  678. package/v4/locales/mk.js +114 -0
  679. package/v4/locales/ms.cjs +139 -0
  680. package/v4/locales/ms.d.cts +5 -0
  681. package/v4/locales/ms.d.ts +4 -0
  682. package/v4/locales/ms.js +112 -0
  683. package/v4/locales/ne.cjs +138 -0
  684. package/v4/locales/ne.d.cts +5 -0
  685. package/v4/locales/ne.d.ts +4 -0
  686. package/v4/locales/ne.js +111 -0
  687. package/v4/locales/nl.cjs +142 -0
  688. package/v4/locales/nl.d.cts +5 -0
  689. package/v4/locales/nl.d.ts +4 -0
  690. package/v4/locales/nl.js +115 -0
  691. package/v4/locales/nn.cjs +140 -0
  692. package/v4/locales/nn.d.cts +5 -0
  693. package/v4/locales/nn.d.ts +4 -0
  694. package/v4/locales/nn.js +113 -0
  695. package/v4/locales/no.cjs +140 -0
  696. package/v4/locales/no.d.cts +5 -0
  697. package/v4/locales/no.d.ts +4 -0
  698. package/v4/locales/no.js +113 -0
  699. package/v4/locales/ota.cjs +141 -0
  700. package/v4/locales/ota.d.cts +5 -0
  701. package/v4/locales/ota.d.ts +4 -0
  702. package/v4/locales/ota.js +114 -0
  703. package/v4/locales/pl.cjs +141 -0
  704. package/v4/locales/pl.d.cts +5 -0
  705. package/v4/locales/pl.d.ts +4 -0
  706. package/v4/locales/pl.js +114 -0
  707. package/v4/locales/ps.cjs +146 -0
  708. package/v4/locales/ps.d.cts +5 -0
  709. package/v4/locales/ps.d.ts +4 -0
  710. package/v4/locales/ps.js +119 -0
  711. package/v4/locales/pt-BR.cjs +170 -0
  712. package/v4/locales/pt-BR.d.cts +5 -0
  713. package/v4/locales/pt-BR.d.ts +4 -0
  714. package/v4/locales/pt-BR.js +143 -0
  715. package/v4/locales/pt.cjs +169 -0
  716. package/v4/locales/pt.d.cts +5 -0
  717. package/v4/locales/pt.d.ts +4 -0
  718. package/v4/locales/pt.js +142 -0
  719. package/v4/locales/ro.cjs +149 -0
  720. package/v4/locales/ro.d.cts +5 -0
  721. package/v4/locales/ro.d.ts +4 -0
  722. package/v4/locales/ro.js +122 -0
  723. package/v4/locales/ru.cjs +195 -0
  724. package/v4/locales/ru.d.cts +5 -0
  725. package/v4/locales/ru.d.ts +4 -0
  726. package/v4/locales/ru.js +168 -0
  727. package/v4/locales/sk.cjs +143 -0
  728. package/v4/locales/sk.d.cts +5 -0
  729. package/v4/locales/sk.d.ts +4 -0
  730. package/v4/locales/sk.js +116 -0
  731. package/v4/locales/sl.cjs +141 -0
  732. package/v4/locales/sl.d.cts +5 -0
  733. package/v4/locales/sl.d.ts +4 -0
  734. package/v4/locales/sl.js +114 -0
  735. package/v4/locales/sv.cjs +142 -0
  736. package/v4/locales/sv.d.cts +5 -0
  737. package/v4/locales/sv.d.ts +4 -0
  738. package/v4/locales/sv.js +115 -0
  739. package/v4/locales/ta.cjs +142 -0
  740. package/v4/locales/ta.d.cts +5 -0
  741. package/v4/locales/ta.d.ts +4 -0
  742. package/v4/locales/ta.js +115 -0
  743. package/v4/locales/tg.cjs +144 -0
  744. package/v4/locales/tg.d.cts +5 -0
  745. package/v4/locales/tg.d.ts +4 -0
  746. package/v4/locales/tg.js +117 -0
  747. package/v4/locales/th.cjs +142 -0
  748. package/v4/locales/th.d.cts +5 -0
  749. package/v4/locales/th.d.ts +4 -0
  750. package/v4/locales/th.js +115 -0
  751. package/v4/locales/tk.cjs +134 -0
  752. package/v4/locales/tk.d.cts +5 -0
  753. package/v4/locales/tk.d.ts +4 -0
  754. package/v4/locales/tk.js +107 -0
  755. package/v4/locales/tr.cjs +137 -0
  756. package/v4/locales/tr.d.cts +5 -0
  757. package/v4/locales/tr.d.ts +4 -0
  758. package/v4/locales/tr.js +110 -0
  759. package/v4/locales/ua.cjs +12 -0
  760. package/v4/locales/ua.d.cts +5 -0
  761. package/v4/locales/ua.d.ts +5 -0
  762. package/v4/locales/ua.js +5 -0
  763. package/v4/locales/uk.cjs +140 -0
  764. package/v4/locales/uk.d.cts +5 -0
  765. package/v4/locales/uk.d.ts +4 -0
  766. package/v4/locales/uk.js +113 -0
  767. package/v4/locales/ur.cjs +142 -0
  768. package/v4/locales/ur.d.cts +5 -0
  769. package/v4/locales/ur.d.ts +4 -0
  770. package/v4/locales/ur.js +115 -0
  771. package/v4/locales/uz.cjs +140 -0
  772. package/v4/locales/uz.d.cts +5 -0
  773. package/v4/locales/uz.d.ts +4 -0
  774. package/v4/locales/uz.js +113 -0
  775. package/v4/locales/vi.cjs +140 -0
  776. package/v4/locales/vi.d.cts +5 -0
  777. package/v4/locales/vi.d.ts +4 -0
  778. package/v4/locales/vi.js +113 -0
  779. package/v4/locales/yo.cjs +139 -0
  780. package/v4/locales/yo.d.cts +5 -0
  781. package/v4/locales/yo.d.ts +4 -0
  782. package/v4/locales/yo.js +112 -0
  783. package/v4/locales/zh-CN.cjs +141 -0
  784. package/v4/locales/zh-CN.d.cts +5 -0
  785. package/v4/locales/zh-CN.d.ts +4 -0
  786. package/v4/locales/zh-CN.js +114 -0
  787. package/v4/locales/zh-TW.cjs +139 -0
  788. package/v4/locales/zh-TW.d.cts +5 -0
  789. package/v4/locales/zh-TW.d.ts +4 -0
  790. package/v4/locales/zh-TW.js +112 -0
  791. package/v4/mini/checks.cjs +54 -0
  792. package/v4/mini/checks.d.cts +1 -0
  793. package/v4/mini/checks.d.ts +1 -0
  794. package/v4/mini/checks.js +1 -0
  795. package/v4/mini/coerce.cjs +71 -0
  796. package/v4/mini/coerce.d.cts +7 -0
  797. package/v4/mini/coerce.d.ts +7 -0
  798. package/v4/mini/coerce.js +22 -0
  799. package/v4/mini/deep-partial.cjs +58 -0
  800. package/v4/mini/deep-partial.d.cts +14 -0
  801. package/v4/mini/deep-partial.d.ts +14 -0
  802. package/v4/mini/deep-partial.js +13 -0
  803. package/v4/mini/external.cjs +95 -0
  804. package/v4/mini/external.d.cts +16 -0
  805. package/v4/mini/external.d.ts +16 -0
  806. package/v4/mini/external.js +16 -0
  807. package/v4/mini/in-out.cjs +82 -0
  808. package/v4/mini/in-out.d.cts +8 -0
  809. package/v4/mini/in-out.d.ts +8 -0
  810. package/v4/mini/in-out.js +36 -0
  811. package/v4/mini/index.cjs +51 -0
  812. package/v4/mini/index.d.cts +3 -0
  813. package/v4/mini/index.d.ts +3 -0
  814. package/v4/mini/index.js +3 -0
  815. package/v4/mini/iso.cjs +83 -0
  816. package/v4/mini/iso.d.cts +22 -0
  817. package/v4/mini/iso.d.ts +22 -0
  818. package/v4/mini/iso.js +34 -0
  819. package/v4/mini/parse.cjs +37 -0
  820. package/v4/mini/parse.d.cts +1 -0
  821. package/v4/mini/parse.d.ts +1 -0
  822. package/v4/mini/parse.js +1 -0
  823. package/v4/mini/schemas.cjs +1149 -0
  824. package/v4/mini/schemas.d.cts +480 -0
  825. package/v4/mini/schemas.d.ts +480 -0
  826. package/v4/mini/schemas.js +1004 -0
  827. package/v4-mini/index.cjs +51 -0
  828. package/v4-mini/index.d.cts +3 -0
  829. package/v4-mini/index.d.ts +3 -0
  830. package/v4-mini/index.js +3 -0
@@ -0,0 +1,1148 @@
1
+ import { expect, expectTypeOf, test } from "vitest";
2
+ import * as z from "yatsp/mini";
3
+ import type { util } from "yatsp/v4/core";
4
+
5
+ test("factory checks", () => {
6
+ const string = z.string({ checks: [z.minLength(1), z.maxLength(3)] as const });
7
+ const number = z.number({ checks: [z.minimum(1), z.maximum(3)] as const });
8
+ expectTypeOf<z.output<typeof string>>().toEqualTypeOf<string>();
9
+ expectTypeOf<z.output<typeof number>>().toEqualTypeOf<number>();
10
+ for (const [schema, valid, invalid] of [
11
+ [string, "ab", ""],
12
+ [number, 2, 4],
13
+ ] as const) {
14
+ expect(z.validate(schema, valid)).toBe(true);
15
+ expect(z.validate(schema, invalid)).toBe(false);
16
+ expect(schema._yatsp.parent).toBeUndefined();
17
+ expect(z.validate(z.compile(schema), valid)).toBe(true);
18
+ expect(z.validate(z.compile(schema), invalid)).toBe(false);
19
+ }
20
+ // @ts-expect-error numeric checks cannot validate strings
21
+ z.string({ checks: [z.minimum(1)] });
22
+ // @ts-expect-error length checks cannot validate numbers
23
+ z.number({ checks: [z.minLength(1)] });
24
+ });
25
+
26
+ test("factory checks snapshot caller arrays", () => {
27
+ for (const factory of [z.string, z.coerce.string]) {
28
+ const checks = [z.minLength(1)];
29
+ const schema = factory({ checks });
30
+ let reads = 0;
31
+ factory({
32
+ get checks() {
33
+ if (++reads > 1) throw new Error("checks read twice");
34
+ return checks;
35
+ },
36
+ });
37
+ expect(reads).toBe(1);
38
+ checks.push(z.minLength(10));
39
+ expect(z.validate(schema, "long")).toBe(true);
40
+ expect(z.validate(z.compile(schema), "long")).toBe(true);
41
+ expect(z.toJSONSchema(schema).minLength).toBe(1);
42
+ }
43
+ for (const factory of [z.number, z.coerce.number]) {
44
+ const checks = [z.minimum(1)];
45
+ const schema = factory({ checks });
46
+ let reads = 0;
47
+ factory({
48
+ get checks() {
49
+ if (++reads > 1) throw new Error("checks read twice");
50
+ return checks;
51
+ },
52
+ });
53
+ expect(reads).toBe(1);
54
+ checks.push(z.minimum(10));
55
+ expect(z.validate(schema, 3)).toBe(true);
56
+ expect(z.validate(z.compile(schema), 3)).toBe(true);
57
+ expect(z.toJSONSchema(schema).minimum).toBe(1);
58
+ }
59
+ });
60
+
61
+ test("z.boolean", () => {
62
+ const a = z.boolean();
63
+ expect(z.parse(a, true)).toEqual(true);
64
+ expect(z.parse(a, false)).toEqual(false);
65
+ expect(() => z.parse(a, 123)).toThrow();
66
+ expect(() => z.parse(a, "true")).toThrow();
67
+ type a = z.output<typeof a>;
68
+ expectTypeOf<a>().toEqualTypeOf<boolean>();
69
+ });
70
+
71
+ test("z.bigint", () => {
72
+ const a = z.bigint();
73
+ expect(z.parse(a, BigInt(123))).toEqual(BigInt(123));
74
+ expect(() => z.parse(a, 123)).toThrow();
75
+ expect(() => z.parse(a, "123")).toThrow();
76
+ });
77
+
78
+ test("z.symbol", () => {
79
+ const a = z.symbol();
80
+ const sym = Symbol();
81
+ expect(z.parse(a, sym)).toEqual(sym);
82
+ expect(() => z.parse(a, "symbol")).toThrow();
83
+ });
84
+
85
+ test("z.date", () => {
86
+ const a = z.date();
87
+ const date = new Date();
88
+ expect(z.parse(a, date)).toEqual(date);
89
+ expect(() => z.parse(a, "date")).toThrow();
90
+ });
91
+
92
+ test("z.coerce.string", () => {
93
+ const a = z.coerce.string();
94
+ expect(z.parse(a, 123)).toEqual("123");
95
+ expect(z.parse(a, true)).toEqual("true");
96
+ expect(z.parse(a, null)).toEqual("null");
97
+ expect(z.parse(a, undefined)).toEqual("undefined");
98
+ });
99
+
100
+ test("z.coerce.number", () => {
101
+ const a = z.coerce.number();
102
+ expect(z.parse(a, "123")).toEqual(123);
103
+ expect(z.parse(a, "123.45")).toEqual(123.45);
104
+ expect(z.parse(a, true)).toEqual(1);
105
+ expect(z.parse(a, false)).toEqual(0);
106
+ expect(() => z.parse(a, "abc")).toThrow();
107
+ });
108
+
109
+ test("z.coerce.boolean", () => {
110
+ const a = z.coerce.boolean();
111
+ // test booleans
112
+ expect(z.parse(a, true)).toEqual(true);
113
+ expect(z.parse(a, false)).toEqual(false);
114
+ expect(z.parse(a, "true")).toEqual(true);
115
+ expect(z.parse(a, "false")).toEqual(true);
116
+ expect(z.parse(a, 1)).toEqual(true);
117
+ expect(z.parse(a, 0)).toEqual(false);
118
+ expect(z.parse(a, {})).toEqual(true);
119
+ expect(z.parse(a, [])).toEqual(true);
120
+ expect(z.parse(a, undefined)).toEqual(false);
121
+ expect(z.parse(a, null)).toEqual(false);
122
+ expect(z.parse(a, "")).toEqual(false);
123
+ });
124
+
125
+ test("z.coerce.bigint", () => {
126
+ const a = z.coerce.bigint();
127
+ expect(z.parse(a, "123")).toEqual(BigInt(123));
128
+ expect(z.parse(a, 123)).toEqual(BigInt(123));
129
+ expect(() => z.parse(a, "abc")).toThrow();
130
+ });
131
+
132
+ test("z.coerce.date", () => {
133
+ const a = z.coerce.date();
134
+ const date = new Date();
135
+ expect(z.parse(a, date.toISOString())).toEqual(date);
136
+ expect(z.parse(a, date.getTime())).toEqual(date);
137
+ expect(() => z.parse(a, "invalid date")).toThrow();
138
+ });
139
+
140
+ test("z.iso.datetime", () => {
141
+ const d1 = "2021-01-01T00:00:00Z";
142
+ const d2 = "2021-01-01T00:00:00.123Z";
143
+ const d3 = "2021-01-01T00:00:00";
144
+ const d4 = "2021-01-01T00:00:00+07:00";
145
+ const d5 = "bad data";
146
+
147
+ // local: false, offset: false, precision: null
148
+ const a = z.iso.datetime();
149
+ expect(z.safeParse(a, d1).success).toEqual(true);
150
+ expect(z.safeParse(a, d2).success).toEqual(true);
151
+ expect(z.safeParse(a, d3).success).toEqual(false);
152
+ expect(z.safeParse(a, d4).success).toEqual(false);
153
+ expect(z.safeParse(a, d5).success).toEqual(false);
154
+
155
+ const b = z.iso.datetime({ local: true });
156
+ expect(z.safeParse(b, d1).success).toEqual(true);
157
+ expect(z.safeParse(b, d2).success).toEqual(true);
158
+ expect(z.safeParse(b, d3).success).toEqual(true);
159
+ expect(z.safeParse(b, d4).success).toEqual(false);
160
+ expect(z.safeParse(b, d5).success).toEqual(false);
161
+
162
+ const c = z.iso.datetime({ offset: true });
163
+ expect(z.safeParse(c, d1).success).toEqual(true);
164
+ expect(z.safeParse(c, d2).success).toEqual(true);
165
+ expect(z.safeParse(c, d3).success).toEqual(false);
166
+ expect(z.safeParse(c, d4).success).toEqual(true);
167
+ expect(z.safeParse(c, d5).success).toEqual(false);
168
+
169
+ const d = z.iso.datetime({ precision: 3 });
170
+ expect(z.safeParse(d, d1).success).toEqual(false);
171
+ expect(z.safeParse(d, d2).success).toEqual(true);
172
+ expect(z.safeParse(d, d3).success).toEqual(false);
173
+ expect(z.safeParse(d, d4).success).toEqual(false);
174
+ expect(z.safeParse(d, d5).success).toEqual(false);
175
+ });
176
+
177
+ test("z.iso.date", () => {
178
+ const d1 = "2021-01-01";
179
+ const d2 = "bad data";
180
+
181
+ const a = z.iso.date();
182
+ expect(z.safeParse(a, d1).success).toEqual(true);
183
+ expect(z.safeParse(a, d2).success).toEqual(false);
184
+
185
+ const b = z.string().check(z.iso.date());
186
+ expect(z.safeParse(b, d1).success).toEqual(true);
187
+ expect(z.safeParse(b, d2).success).toEqual(false);
188
+ });
189
+
190
+ test("z.iso.time", () => {
191
+ const d1 = "00:00:00";
192
+ const d2 = "00:00:00.123";
193
+ const d3 = "bad data";
194
+
195
+ const a = z.iso.time();
196
+ expect(z.safeParse(a, d1).success).toEqual(true);
197
+ expect(z.safeParse(a, d2).success).toEqual(true);
198
+ expect(z.safeParse(a, d3).success).toEqual(false);
199
+
200
+ const b = z.iso.time({ precision: 3 });
201
+ expect(z.safeParse(b, d1).success).toEqual(false);
202
+ expect(z.safeParse(b, d2).success).toEqual(true);
203
+ expect(z.safeParse(b, d3).success).toEqual(false);
204
+
205
+ const c = z.string().check(z.iso.time());
206
+ expect(z.safeParse(c, d1).success).toEqual(true);
207
+ expect(z.safeParse(c, d2).success).toEqual(true);
208
+ expect(z.safeParse(c, d3).success).toEqual(false);
209
+ });
210
+
211
+ test("z.iso.duration", () => {
212
+ const d1 = "P3Y6M4DT12H30M5S";
213
+ const d2 = "bad data";
214
+
215
+ const a = z.iso.duration();
216
+ expect(z.safeParse(a, d1).success).toEqual(true);
217
+ expect(z.safeParse(a, d2).success).toEqual(false);
218
+
219
+ const b = z.string().check(z.iso.duration());
220
+ expect(z.safeParse(b, d1).success).toEqual(true);
221
+ expect(z.safeParse(b, d2).success).toEqual(false);
222
+ });
223
+
224
+ test("z.prefault preserves undefined output", async () => {
225
+ const field = z.prefault(z.union([z.string(), z.undefined()]), () => undefined);
226
+ const schema = z.object({ a: field });
227
+ expectTypeOf<z.output<typeof field>>().toEqualTypeOf<string | undefined>();
228
+ expectTypeOf<z.output<typeof schema>>().toEqualTypeOf<{ a: string | undefined }>();
229
+ expect(z.parse(schema, {})).toStrictEqual({ a: undefined });
230
+ expect(z.parse(schema, { a: undefined })).toStrictEqual({ a: undefined });
231
+ expect(z.parse(schema, { a: "value" })).toStrictEqual({ a: "value" });
232
+ expect(z.safeParse(schema, { a: 123 }).success).toBe(false);
233
+ expect(await z.parseAsync(schema, {})).toStrictEqual({ a: undefined });
234
+ expect(z.parse(z.object({ a: z.prefault(z.optional(z.string()), undefined) }), {})).toStrictEqual({ a: undefined });
235
+ const transformed = z.prefault(
236
+ z.pipe(
237
+ z.string(),
238
+ z.transform(() => undefined)
239
+ ),
240
+ "fallback"
241
+ );
242
+ expectTypeOf<z.output<typeof transformed>>().toEqualTypeOf<undefined>();
243
+ expect(z.parse(z.object({ a: transformed }), {})).toStrictEqual({ a: undefined });
244
+ });
245
+
246
+ test("z.undefined", () => {
247
+ const a = z.undefined();
248
+ expect(z.parse(a, undefined)).toEqual(undefined);
249
+ expect(() => z.parse(a, "undefined")).toThrow();
250
+ });
251
+
252
+ test("z.null", () => {
253
+ const a = z.null();
254
+ expect(z.parse(a, null)).toEqual(null);
255
+ expect(() => z.parse(a, "null")).toThrow();
256
+ });
257
+
258
+ test("z.any", () => {
259
+ const a = z.any();
260
+ expect(z.parse(a, "hello")).toEqual("hello");
261
+ expect(z.parse(a, 123)).toEqual(123);
262
+ expect(z.parse(a, true)).toEqual(true);
263
+ expect(z.parse(a, null)).toEqual(null);
264
+ expect(z.parse(a, undefined)).toEqual(undefined);
265
+ z.parse(a, {});
266
+ z.parse(a, []);
267
+ z.parse(a, Symbol());
268
+ z.parse(a, new Date());
269
+ });
270
+
271
+ test("z.unknown", () => {
272
+ const a = z.unknown();
273
+ expect(z.parse(a, "hello")).toEqual("hello");
274
+ expect(z.parse(a, 123)).toEqual(123);
275
+ expect(z.parse(a, true)).toEqual(true);
276
+ expect(z.parse(a, null)).toEqual(null);
277
+ expect(z.parse(a, undefined)).toEqual(undefined);
278
+ z.parse(a, {});
279
+ z.parse(a, []);
280
+ z.parse(a, Symbol());
281
+ z.parse(a, new Date());
282
+ });
283
+
284
+ test("z.never", () => {
285
+ const a = z.never();
286
+ expect(() => z.parse(a, "hello")).toThrow();
287
+ });
288
+
289
+ test("z.void", () => {
290
+ const a = z.void();
291
+ expect(z.parse(a, undefined)).toEqual(undefined);
292
+ expect(() => z.parse(a, null)).toThrow();
293
+ });
294
+
295
+ test("z.array", () => {
296
+ const a = z.array(z.string());
297
+ expect(z.parse(a, ["hello", "world"])).toEqual(["hello", "world"]);
298
+ expect(() => z.parse(a, [123])).toThrow();
299
+ expect(() => z.parse(a, "hello")).toThrow();
300
+ });
301
+
302
+ test("z.union", () => {
303
+ const a = z.union([z.string(), z.number()]);
304
+ expect(z.parse(a, "hello")).toEqual("hello");
305
+ expect(z.parse(a, 123)).toEqual(123);
306
+ expect(() => z.parse(a, true)).toThrow();
307
+ });
308
+
309
+ test("z.union([]) / z.xor([]) / z.discriminatedUnion(_, []) construct and reject all input", () => {
310
+ for (const schema of [z.union([]), z.xor([])]) {
311
+ const r = schema.safeParse("anything");
312
+ expect(r.success).toEqual(false);
313
+ if (!r.success) {
314
+ expect(r.error.issues[0].code).toBe("invalid_union");
315
+ expect((r.error.issues[0] as any).errors).toEqual([]);
316
+ }
317
+ }
318
+ const disc = z.discriminatedUnion("type", [] as any);
319
+ const r = disc.safeParse({ type: "x" });
320
+ expect(r.success).toEqual(false);
321
+ if (!r.success) {
322
+ expect(r.error.issues[0].code).toBe("invalid_union");
323
+ expect((r.error.issues[0] as any).errors).toEqual([]);
324
+ expect((r.error.issues[0] as any).options).toEqual([]);
325
+ }
326
+ });
327
+
328
+ test("z.discriminatedUnion rejects object options missing the discriminator", () => {
329
+ expect(() => z.discriminatedUnion("type", [z.object({ value: z.string() })])).toThrow(
330
+ /Invalid discriminated union option at index "0"/
331
+ );
332
+
333
+ // An option whose shape cannot be listed without resolving it is left to the lookup map, on the first object parsed.
334
+ const viaPipe = z.discriminatedUnion("type", [
335
+ z.pipe(z.object({ value: z.literal("x") }), z.object({ value: z.literal("x") })),
336
+ ]);
337
+ expect(() => z.safeParse(viaPipe, { value: "x" })).toThrow(/Invalid discriminated union option at index "0"/);
338
+ });
339
+
340
+ test("z.discriminatedUnion infers mutually-recursive getter options", () => {
341
+ const variantA = z.object({
342
+ kind: z.literal("a"),
343
+ get child() {
344
+ return z.optional(tree);
345
+ },
346
+ });
347
+
348
+ const variantB = z.object({
349
+ kind: z.literal("b"),
350
+ get sibling() {
351
+ return z.optional(tree);
352
+ },
353
+ });
354
+
355
+ const tree = z.discriminatedUnion("kind", [variantA, variantB]);
356
+
357
+ type _Tree = { kind: "a"; child?: _Tree | undefined } | { kind: "b"; sibling?: _Tree | undefined };
358
+
359
+ expectTypeOf<z.input<typeof tree>>().toEqualTypeOf<_Tree>();
360
+ expectTypeOf<z.input<typeof tree>>().not.toBeAny();
361
+
362
+ expect(z.parse(tree, { kind: "a", child: { kind: "b" } })).toEqual({ kind: "a", child: { kind: "b" } });
363
+ expect(() => z.parse(tree, { kind: "c" })).toThrow();
364
+ });
365
+
366
+ test("z.intersection", () => {
367
+ const a = z.intersection(z.object({ a: z.string() }), z.object({ b: z.number() }));
368
+ expect(z.parse(a, { a: "hello", b: 123 })).toEqual({ a: "hello", b: 123 });
369
+ expect(() => z.parse(a, { a: "hello" })).toThrow();
370
+ expect(() => z.parse(a, { b: 123 })).toThrow();
371
+ expect(() => z.parse(a, "hello")).toThrow();
372
+ });
373
+
374
+ test("z.tuple", () => {
375
+ const a = z.tuple([z.string(), z.number()]);
376
+ expect(z.parse(a, ["hello", 123])).toEqual(["hello", 123]);
377
+ expect(() => z.parse(a, ["hello", "world"])).toThrow();
378
+ expect(() => z.parse(a, [123, 456])).toThrow();
379
+ expect(() => z.parse(a, "hello")).toThrow();
380
+
381
+ // tuple with rest
382
+ const b = z.tuple([z.string(), z.number(), z.optional(z.string())], z.boolean());
383
+ type b = z.output<typeof b>;
384
+
385
+ expectTypeOf<b>().toEqualTypeOf<[string, number, (string | undefined)?, ...boolean[]]>();
386
+ const datas = [
387
+ ["hello", 123],
388
+ ["hello", 123, "world"],
389
+ ["hello", 123, "world", true],
390
+ ["hello", 123, "world", true, false, true],
391
+ ];
392
+ for (const data of datas) {
393
+ expect(z.parse(b, data)).toEqual(data);
394
+ }
395
+
396
+ expect(() => z.parse(b, ["hello", 123, 123])).toThrow();
397
+ expect(() => z.parse(b, ["hello", 123, "world", 123])).toThrow();
398
+
399
+ // tuple with readonly args
400
+ const cArgs = [z.string(), z.number(), z.optional(z.string())] as const;
401
+ const c = z.tuple(cArgs, z.boolean());
402
+ type c = z.output<typeof c>;
403
+ expectTypeOf<c>().toEqualTypeOf<[string, number, (string | undefined)?, ...boolean[]]>();
404
+ });
405
+
406
+ test("z.record", () => {
407
+ // record schema with enum keys
408
+ const a = z.record(z.string(), z.string());
409
+ type a = z.output<typeof a>;
410
+ expectTypeOf<a>().toEqualTypeOf<Record<string, string>>();
411
+
412
+ const b = z.record(z.union([z.string(), z.number(), z.symbol()]), z.string());
413
+ type b = z.output<typeof b>;
414
+ expectTypeOf<b>().toEqualTypeOf<Record<string | number | symbol, string>>();
415
+ expect(z.parse(b, { a: "hello", 1: "world", [Symbol.for("asdf")]: "symbol" })).toEqual({
416
+ a: "hello",
417
+ 1: "world",
418
+ [Symbol.for("asdf")]: "symbol",
419
+ });
420
+
421
+ // enum keys
422
+ const c = z.record(z.enum(["a", "b", "c"]), z.string());
423
+ type c = z.output<typeof c>;
424
+ expectTypeOf<c>().toEqualTypeOf<Record<"a" | "b" | "c", string>>();
425
+ expect(z.parse(c, { a: "hello", b: "world", c: "world" })).toEqual({
426
+ a: "hello",
427
+ b: "world",
428
+ c: "world",
429
+ });
430
+ // missing keys
431
+ expect(() => z.parse(c, { a: "hello", b: "world" })).toThrow();
432
+ // extra keys
433
+ expect(() => z.parse(c, { a: "hello", b: "world", c: "world", d: "world" })).toThrow();
434
+
435
+ // literal union keys
436
+ const d = z.record(z.union([z.literal("a"), z.literal(0)]), z.string());
437
+ type d = z.output<typeof d>;
438
+ expectTypeOf<d>().toEqualTypeOf<Record<"a" | 0, string>>();
439
+ expect(z.parse(d, { a: "hello", 0: "world" })).toEqual({
440
+ a: "hello",
441
+ 0: "world",
442
+ });
443
+
444
+ // TypeScript enum keys
445
+ enum Enum {
446
+ A = 0,
447
+ B = "hi",
448
+ }
449
+
450
+ const e = z.record(z.enum(Enum), z.string());
451
+ type e = z.output<typeof e>;
452
+ expectTypeOf<e>().toEqualTypeOf<Record<Enum, string>>();
453
+ expect(z.parse(e, { [Enum.A]: "hello", [Enum.B]: "world" })).toEqual({
454
+ [Enum.A]: "hello",
455
+ [Enum.B]: "world",
456
+ });
457
+
458
+ const partial = z.partialRecord(z.enum(["__proto__", "b"]), z.string());
459
+ type partial = z.output<typeof partial>;
460
+ expectTypeOf<partial>().toEqualTypeOf<Partial<Record<"__proto__" | "b", string>>>();
461
+ const parsed: any = z.parse(partial, Object.fromEntries([["__proto__", "declared"]]));
462
+ expect(Object.getPrototypeOf(parsed)).toBe(Object.prototype);
463
+ expect(Object.prototype.hasOwnProperty.call(parsed, "__proto__")).toBe(false);
464
+ expect(parsed).toEqual({});
465
+ expect(z.parse(partial, {})).toEqual({});
466
+
467
+ // v3-compat single-arg form: z.record(valueType) defaults keyType to z.string()
468
+ const f = (z.record as any)(z.number());
469
+ expect(f._yatsp.def.keyType._yatsp.def.type).toEqual("string");
470
+ expect(f._yatsp.def.valueType._yatsp.def.type).toEqual("number");
471
+ expect(z.parse(f, { a: 1, b: 2 })).toEqual({ a: 1, b: 2 });
472
+ });
473
+
474
+ test("z.map", () => {
475
+ const a = z.map(z.string(), z.number());
476
+ type a = z.output<typeof a>;
477
+ expectTypeOf<a>().toEqualTypeOf<Map<string, number>>();
478
+ expect(z.parse(a, new Map([["hello", 123]]))).toEqual(new Map([["hello", 123]]));
479
+ expect(() => z.parse(a, new Map([["hello", "world"]]))).toThrow();
480
+ expect(() => z.parse(a, new Map([[1243, "world"]]))).toThrow();
481
+ expect(() => z.parse(a, "hello")).toThrow();
482
+
483
+ const r1 = z.safeParse(a, new Map([[123, 123]]));
484
+ expect(r1.error?.issues[0].code).toEqual("invalid_type");
485
+ expect(r1.error?.issues[0].path).toEqual([123]);
486
+
487
+ const r2: any = z.safeParse(a, new Map([[BigInt(123), 123]]));
488
+ expect(r2.error!.issues[0].code).toEqual("invalid_key");
489
+ expect(r2.error!.issues[0].path).toEqual([]);
490
+
491
+ const r3: any = z.safeParse(a, new Map([["hello", "world"]]));
492
+ expect(r3.error!.issues[0].code).toEqual("invalid_type");
493
+ expect(r3.error!.issues[0].path).toEqual(["hello"]);
494
+ });
495
+
496
+ test("z.map invalid_element", () => {
497
+ const a = z.map(z.bigint(), z.number());
498
+ const r1 = z.safeParse(a, new Map([[BigInt(123), BigInt(123)]]));
499
+
500
+ expect(r1.error!.issues[0].code).toEqual("invalid_element");
501
+ expect(r1.error!.issues[0].path).toEqual([]);
502
+ });
503
+
504
+ test("z.map async", async () => {
505
+ const a = z.map(z.string().check(z.refine(async () => true)), z.number().check(z.refine(async () => true)));
506
+ const d1 = new Map([["hello", 123]]);
507
+ expect(await z.parseAsync(a, d1)).toEqual(d1);
508
+
509
+ await expect(z.parseAsync(a, new Map([[123, 123]]))).rejects.toThrow();
510
+ await expect(z.parseAsync(a, new Map([["hi", "world"]]))).rejects.toThrow();
511
+ await expect(z.parseAsync(a, new Map([[1243, "world"]]))).rejects.toThrow();
512
+ await expect(z.parseAsync(a, "hello")).rejects.toThrow();
513
+
514
+ const r = await z.safeParseAsync(a, new Map([[123, 123]]));
515
+ expect(r.success).toEqual(false);
516
+ expect(r.error!.issues[0].code).toEqual("invalid_type");
517
+ expect(r.error!.issues[0].path).toEqual([123]);
518
+ });
519
+
520
+ test("z.set", () => {
521
+ const a = z.set(z.string());
522
+ type a = z.output<typeof a>;
523
+ expectTypeOf<a>().toEqualTypeOf<Set<string>>();
524
+ expect(z.parse(a, new Set(["hello", "world"]))).toEqual(new Set(["hello", "world"]));
525
+ expect(() => z.parse(a, new Set([123]))).toThrow();
526
+ expect(() => z.parse(a, ["hello", "world"])).toThrow();
527
+ expect(() => z.parse(a, "hello")).toThrow();
528
+
529
+ const b = z.set(z.number());
530
+ expect(z.parse(b, new Set([1, 2, 3]))).toEqual(new Set([1, 2, 3]));
531
+ expect(() => z.parse(b, new Set(["hello"]))).toThrow();
532
+ expect(() => z.parse(b, [1, 2, 3])).toThrow();
533
+ expect(() => z.parse(b, 123)).toThrow();
534
+ });
535
+
536
+ test("z.enum", () => {
537
+ const a = z.enum(["A", "B", "C"]);
538
+ type a = z.output<typeof a>;
539
+ expectTypeOf<a>().toEqualTypeOf<"A" | "B" | "C">();
540
+ expect(z.parse(a, "A")).toEqual("A");
541
+ expect(z.parse(a, "B")).toEqual("B");
542
+ expect(z.parse(a, "C")).toEqual("C");
543
+ expect(() => z.parse(a, "D")).toThrow();
544
+ expect(() => z.parse(a, 123)).toThrow();
545
+
546
+ // expect(a.enum.A).toEqual("A");
547
+ // expect(a.enum.B).toEqual("B");
548
+ // expect(a.enum.C).toEqual("C");
549
+ // expect((a.enum as any).D).toEqual(undefined);
550
+ });
551
+
552
+ test("z.enum - native", () => {
553
+ enum NativeEnum {
554
+ A = "A",
555
+ B = "B",
556
+ C = "C",
557
+ }
558
+ const a = z.enum(NativeEnum);
559
+ type a = z.output<typeof a>;
560
+ expectTypeOf<a>().toEqualTypeOf<NativeEnum>();
561
+ expect(z.parse(a, NativeEnum.A)).toEqual(NativeEnum.A);
562
+ expect(z.parse(a, NativeEnum.B)).toEqual(NativeEnum.B);
563
+ expect(z.parse(a, NativeEnum.C)).toEqual(NativeEnum.C);
564
+ expect(() => z.parse(a, "D")).toThrow();
565
+ expect(() => z.parse(a, 123)).toThrow();
566
+
567
+ // test a.enum
568
+ a;
569
+ // expect(a.enum.A).toEqual(NativeEnum.A);
570
+ // expect(a.enum.B).toEqual(NativeEnum.B);
571
+ // expect(a.enum.C).toEqual(NativeEnum.C);
572
+
573
+ enum NumericEnum {
574
+ A = 0,
575
+ B = 1,
576
+ }
577
+
578
+ // numeric enums carry reverse-mapping keys; options lists only what parse accepts
579
+ expect(z.enum(NumericEnum).options).toEqual([NumericEnum.A, NumericEnum.B]);
580
+ });
581
+
582
+ test("z.nativeEnum", () => {
583
+ enum NativeEnum {
584
+ A = "A",
585
+ B = "B",
586
+ C = "C",
587
+ }
588
+ const a = z.nativeEnum(NativeEnum);
589
+ type a = z.output<typeof a>;
590
+ expectTypeOf<a>().toEqualTypeOf<NativeEnum>();
591
+ expect(z.parse(a, NativeEnum.A)).toEqual(NativeEnum.A);
592
+ expect(z.parse(a, NativeEnum.B)).toEqual(NativeEnum.B);
593
+ expect(z.parse(a, NativeEnum.C)).toEqual(NativeEnum.C);
594
+ expect(() => z.parse(a, "D")).toThrow();
595
+ expect(() => z.parse(a, 123)).toThrow();
596
+
597
+ // test a.enum
598
+ a;
599
+ // expect(a.enum.A).toEqual(NativeEnum.A);
600
+ // expect(a.enum.B).toEqual(NativeEnum.B);
601
+ // expect(a.enum.C).toEqual(NativeEnum.C);
602
+ });
603
+
604
+ test("z.literal", () => {
605
+ const a = z.literal("hello");
606
+ type a = z.output<typeof a>;
607
+ expectTypeOf<a>().toEqualTypeOf<"hello">();
608
+ expect(z.parse(a, "hello")).toEqual("hello");
609
+ expect(() => z.parse(a, "world")).toThrow();
610
+ expect(() => z.parse(a, 123)).toThrow();
611
+
612
+ z.literal(["adf"] as const);
613
+ });
614
+
615
+ test("z.file", () => {
616
+ const a = z.file();
617
+ const file = new File(["content"], "filename.txt", { type: "text/plain" });
618
+ expect(z.parse(a, file)).toEqual(file);
619
+ expect(() => z.parse(a, "file")).toThrow();
620
+ expect(() => z.parse(a, 123)).toThrow();
621
+ });
622
+
623
+ test("z.transform", () => {
624
+ const a = z.pipe(
625
+ z.string(),
626
+ z.transform((val) => val.toUpperCase())
627
+ );
628
+ type a = z.output<typeof a>;
629
+ expectTypeOf<a>().toEqualTypeOf<string>();
630
+ expect(z.parse(a, "hello")).toEqual("HELLO");
631
+ expect(() => z.parse(a, 123)).toThrow();
632
+ });
633
+
634
+ test("z.transform async", async () => {
635
+ const a = z.pipe(
636
+ z.string(),
637
+ z.transform(async (val) => val.toUpperCase())
638
+ );
639
+ type a = z.output<typeof a>;
640
+ expectTypeOf<a>().toEqualTypeOf<string>();
641
+ expect(await z.parseAsync(a, "hello")).toEqual("HELLO");
642
+ await expect(() => z.parseAsync(a, 123)).rejects.toThrow();
643
+ });
644
+
645
+ test("z.preprocess", () => {
646
+ const a = z.pipe(
647
+ z.transform((val) => String(val).toUpperCase()),
648
+ z.string()
649
+ );
650
+ type a = z.output<typeof a>;
651
+ expectTypeOf<a>().toEqualTypeOf<string>();
652
+ expect(z.parse(a, 123)).toEqual("123");
653
+ expect(z.parse(a, true)).toEqual("TRUE");
654
+ expect(z.parse(a, BigInt(1234))).toEqual("1234");
655
+ // expect(() => z.parse(a, Symbol("asdf"))).toThrow();
656
+ });
657
+
658
+ // test("z.preprocess async", () => {
659
+ // const a = z.preprocess(async (val) => String(val), z.string());
660
+ // type a = z.output<typeof a>;
661
+ // expectTypeOf<a>().toEqualTypeOf<string>();
662
+ // expect(z.parse(a, 123)).toEqual("123");
663
+ // expect(z.parse(a, true)).toEqual("true");
664
+ // expect(() => z.parse(a, {})).toThrow();
665
+ // });
666
+
667
+ test("z.optional", () => {
668
+ const a = z.optional(z.string());
669
+ type a = z.output<typeof a>;
670
+ expectTypeOf<a>().toEqualTypeOf<string | undefined>();
671
+ expect(z.parse(a, "hello")).toEqual("hello");
672
+ expect(z.parse(a, undefined)).toEqual(undefined);
673
+ expect(() => z.parse(a, 123)).toThrow();
674
+ });
675
+
676
+ test("z.nullable", () => {
677
+ const a = z.nullable(z.string());
678
+ type a = z.output<typeof a>;
679
+ expectTypeOf<a>().toEqualTypeOf<string | null>();
680
+ expect(z.parse(a, "hello")).toEqual("hello");
681
+ expect(z.parse(a, null)).toEqual(null);
682
+ expect(() => z.parse(a, 123)).toThrow();
683
+ });
684
+
685
+ test("z.default", () => {
686
+ const a = z._default(z.string(), "default");
687
+ type a = z.output<typeof a>;
688
+ expectTypeOf<a>().toEqualTypeOf<string>();
689
+ expect(z.parse(a, undefined)).toEqual("default");
690
+ expect(z.parse(a, "hello")).toEqual("hello");
691
+ expect(() => z.parse(a, 123)).toThrow();
692
+
693
+ const b = z._default(z.string(), () => "default");
694
+ expect(z.parse(b, undefined)).toEqual("default");
695
+ expect(z.parse(b, "hello")).toEqual("hello");
696
+ expect(() => z.parse(b, 123)).toThrow();
697
+ });
698
+
699
+ test("z.catch", () => {
700
+ const a = z.catch(z.string(), "default");
701
+ type a = z.output<typeof a>;
702
+ expectTypeOf<a>().toEqualTypeOf<string>();
703
+ expect(z.parse(a, "hello")).toEqual("hello");
704
+ expect(z.parse(a, 123)).toEqual("default");
705
+
706
+ const b = z.catch(z.string(), () => "default");
707
+ expect(z.parse(b, "hello")).toEqual("hello");
708
+ expect(z.parse(b, 123)).toEqual("default");
709
+
710
+ const c = z.catch(z.string(), (ctx) => {
711
+ return `${ctx.error.issues.length}issues`;
712
+ });
713
+ expect(z.parse(c, 1234)).toEqual("1issues");
714
+ });
715
+
716
+ test("z.nan", () => {
717
+ const a = z.nan();
718
+ type a = z.output<typeof a>;
719
+ expectTypeOf<a>().toEqualTypeOf<number>();
720
+ expect(z.parse(a, Number.NaN)).toEqual(Number.NaN);
721
+ expect(() => z.parse(a, 123)).toThrow();
722
+ expect(() => z.parse(a, "NaN")).toThrow();
723
+ });
724
+
725
+ test("z.pipe", () => {
726
+ const a = z.pipe(
727
+ z.pipe(
728
+ z.string(),
729
+ z.transform((val) => val.length)
730
+ ),
731
+ z.number()
732
+ );
733
+ type a_in = z.input<typeof a>;
734
+ expectTypeOf<a_in>().toEqualTypeOf<string>();
735
+ type a_out = z.output<typeof a>;
736
+ expectTypeOf<a_out>().toEqualTypeOf<number>();
737
+
738
+ expect(z.parse(a, "123")).toEqual(3);
739
+ expect(z.parse(a, "hello")).toEqual(5);
740
+ expect(() => z.parse(a, 123)).toThrow();
741
+ });
742
+
743
+ test("z.readonly", () => {
744
+ const a = z.readonly(z.string());
745
+ type a = z.output<typeof a>;
746
+ expectTypeOf<a>().toEqualTypeOf<Readonly<string>>();
747
+ expect(z.parse(a, "hello")).toEqual("hello");
748
+ expect(() => z.parse(a, 123)).toThrow();
749
+ });
750
+
751
+ test("z.templateLiteral", () => {
752
+ const a = z.templateLiteral([z.string(), z.number()]);
753
+ type a = z.output<typeof a>;
754
+ expectTypeOf<a>().toEqualTypeOf<`${string}${number}`>();
755
+ expect(z.parse(a, "hello123")).toEqual("hello123");
756
+ expect(() => z.parse(a, "hello")).toThrow();
757
+ expect(() => z.parse(a, 123)).toThrow();
758
+
759
+ // multipart
760
+ const b = z.templateLiteral([z.string(), z.number(), z.string()]);
761
+ type b = z.output<typeof b>;
762
+ expectTypeOf<b>().toEqualTypeOf<`${string}${number}${string}`>();
763
+ expect(z.parse(b, "hello123world")).toEqual("hello123world");
764
+ expect(z.parse(b, "123")).toEqual("123");
765
+ expect(() => z.parse(b, "hello")).toThrow();
766
+ expect(() => z.parse(b, 123)).toThrow();
767
+
768
+ // include boolean
769
+ const c = z.templateLiteral([z.string(), z.boolean()]);
770
+ type c = z.output<typeof c>;
771
+ expectTypeOf<c>().toEqualTypeOf<`${string}${boolean}`>();
772
+ expect(z.parse(c, "hellotrue")).toEqual("hellotrue");
773
+ expect(z.parse(c, "hellofalse")).toEqual("hellofalse");
774
+ expect(() => z.parse(c, "hello")).toThrow();
775
+ expect(() => z.parse(c, 123)).toThrow();
776
+
777
+ // include literal prefix
778
+ const d = z.templateLiteral([z.literal("hello"), z.number()]);
779
+ type d = z.output<typeof d>;
780
+ expectTypeOf<d>().toEqualTypeOf<`hello${number}`>();
781
+ expect(z.parse(d, "hello123")).toEqual("hello123");
782
+ expect(() => z.parse(d, 123)).toThrow();
783
+ expect(() => z.parse(d, "world123")).toThrow();
784
+
785
+ // include literal union
786
+ const e = z.templateLiteral([z.literal(["aa", "bb"]), z.number()]);
787
+ type e = z.output<typeof e>;
788
+ expectTypeOf<e>().toEqualTypeOf<`aa${number}` | `bb${number}`>();
789
+ expect(z.parse(e, "aa123")).toEqual("aa123");
790
+ expect(z.parse(e, "bb123")).toEqual("bb123");
791
+ expect(() => z.parse(e, "cc123")).toThrow();
792
+ expect(() => z.parse(e, 123)).toThrow();
793
+ });
794
+
795
+ // this returns both a schema and a check
796
+ test("z.custom", () => {
797
+ const a = z.custom((val) => {
798
+ return typeof val === "string";
799
+ });
800
+ expect(z.parse(a, "hello")).toEqual("hello");
801
+ expect(() => z.parse(a, 123)).toThrow();
802
+
803
+ const b = z.string().check(z.custom((val) => val.length > 3));
804
+
805
+ expect(z.parse(b, "hello")).toEqual("hello");
806
+ expect(() => z.parse(b, "hi")).toThrow();
807
+ });
808
+
809
+ test("z.check", () => {
810
+ // this is a more flexible version of z.custom that accepts an arbitrary _parse logic the function should return core.$YatspResult
811
+ const a = z.any().check(
812
+ z.check<string>((ctx) => {
813
+ if (typeof ctx.value === "string") return;
814
+ ctx.issues.push({
815
+ code: "custom",
816
+ origin: "custom",
817
+ message: "Expected a string",
818
+ input: ctx.value,
819
+ });
820
+ })
821
+ );
822
+ expect(z.safeParse(a, "hello")).toMatchObject({
823
+ success: true,
824
+ data: "hello",
825
+ });
826
+ expect(z.safeParse(a, 123)).toMatchObject({
827
+ success: false,
828
+ error: { issues: [{ code: "custom", message: "Expected a string" }] },
829
+ });
830
+ });
831
+
832
+ test("z.with (alias for z.check)", () => {
833
+ // .with() should work exactly the same as .check()
834
+ const a = z.any().with(
835
+ z.check<string>((ctx) => {
836
+ if (typeof ctx.value === "string") return;
837
+ ctx.issues.push({
838
+ code: "custom",
839
+ origin: "custom",
840
+ message: "Expected a string",
841
+ input: ctx.value,
842
+ });
843
+ })
844
+ );
845
+ expect(z.safeParse(a, "hello")).toMatchObject({
846
+ success: true,
847
+ data: "hello",
848
+ });
849
+ expect(z.safeParse(a, 123)).toMatchObject({
850
+ success: false,
851
+ error: { issues: [{ code: "custom", message: "Expected a string" }] },
852
+ });
853
+
854
+ // Test with refine
855
+ const b = z.string().with(z.refine((val) => val.length > 3, "Must be longer than 3"));
856
+ expect(z.safeParse(b, "hello").success).toBe(true);
857
+ expect(z.safeParse(b, "hi").success).toBe(false);
858
+
859
+ // Test with function
860
+ const c = z.string().with(({ value, issues }) => {
861
+ if (value.length <= 3) {
862
+ issues.push({
863
+ code: "custom",
864
+ input: value,
865
+ message: "Must be longer than 3",
866
+ });
867
+ }
868
+ });
869
+ expect(z.safeParse(c, "hello").success).toBe(true);
870
+ expect(z.safeParse(c, "hi").success).toBe(false);
871
+ });
872
+
873
+ test("z.instanceof", () => {
874
+ class A {}
875
+
876
+ const a = z.instanceof(A);
877
+ expect(z.parse(a, new A())).toBeInstanceOf(A);
878
+ expect(() => z.parse(a, {})).toThrow();
879
+ });
880
+
881
+ test("z.refine", () => {
882
+ const a = z.number().check(
883
+ z.refine((val) => val > 3),
884
+ z.refine((val) => val < 10)
885
+ );
886
+ expect(z.parse(a, 5)).toEqual(5);
887
+ expect(() => z.parse(a, 2)).toThrow();
888
+ expect(() => z.parse(a, 11)).toThrow();
889
+ expect(() => z.parse(a, "hi")).toThrow();
890
+ });
891
+
892
+ // test("z.superRefine", () => {
893
+ // const a = z.number([
894
+ // z.superRefine((val, ctx) => {
895
+ // if (val < 3) {
896
+ // return ctx.addIssue({
897
+ // code: "custom",
898
+ // origin: "custom",
899
+ // message: "Too small",
900
+ // input: val,
901
+ // });
902
+ // }
903
+ // if (val > 10) {
904
+ // return ctx.addIssue("Too big");
905
+ // }
906
+ // }),
907
+ // ]);
908
+
909
+ // expect(z.parse(a, 5)).toEqual(5);
910
+ // expect(() => z.parse(a, 2)).toThrow();
911
+ // expect(() => z.parse(a, 11)).toThrow();
912
+ // expect(() => z.parse(a, "hi")).toThrow();
913
+ // });
914
+
915
+ test("z.transform", () => {
916
+ const a = z.transform((val: number) => {
917
+ return `${val}`;
918
+ });
919
+ type a_in = z.input<typeof a>;
920
+ expectTypeOf<a_in>().toEqualTypeOf<number>();
921
+ type a_out = z.output<typeof a>;
922
+ expectTypeOf<a_out>().toEqualTypeOf<string>();
923
+ expect(z.parse(a, 123)).toEqual("123");
924
+ });
925
+
926
+ test("z.$brand()", () => {
927
+ const a = z.string().brand<"my-brand">();
928
+ type a = z.output<typeof a>;
929
+ const branded = (_: a) => {};
930
+ // @ts-expect-error
931
+ branded("asdf");
932
+ });
933
+
934
+ test("z.lazy", () => {
935
+ const a = z.lazy(() => z.string());
936
+ type a = z.output<typeof a>;
937
+ expectTypeOf<a>().toEqualTypeOf<string>();
938
+ expect(z.parse(a, "hello")).toEqual("hello");
939
+ expect(() => z.parse(a, 123)).toThrow();
940
+ });
941
+
942
+ // schema that validates JSON-like data
943
+ test("z.json", () => {
944
+ const a = z.json();
945
+ type a = z.output<typeof a>;
946
+ a._yatsp.output;
947
+
948
+ expectTypeOf<a>().toEqualTypeOf<util.JSONType>();
949
+
950
+ expect(z.parse(a, "hello")).toEqual("hello");
951
+ expect(z.parse(a, 123)).toEqual(123);
952
+ expect(z.parse(a, true)).toEqual(true);
953
+ expect(z.parse(a, null)).toEqual(null);
954
+ expect(z.parse(a, {})).toEqual({});
955
+ expect(z.parse(a, { a: "hello" })).toEqual({ a: "hello" });
956
+ expect(z.parse(a, [1, 2, 3])).toEqual([1, 2, 3]);
957
+ expect(z.parse(a, [{ a: "hello" }])).toEqual([{ a: "hello" }]);
958
+
959
+ // fail cases
960
+ expect(() => z.parse(a, new Date())).toThrow();
961
+ expect(() => z.parse(a, Symbol())).toThrow();
962
+ expect(() => z.parse(a, { a: new Date() })).toThrow();
963
+ expect(() => z.parse(a, undefined)).toThrow();
964
+ expect(() => z.parse(a, { a: undefined })).toThrow();
965
+ });
966
+
967
+ test("z.stringbool", () => {
968
+ const a = z.stringbool();
969
+
970
+ expect(z.parse(a, "true")).toEqual(true);
971
+ expect(z.parse(a, "yes")).toEqual(true);
972
+ expect(z.parse(a, "1")).toEqual(true);
973
+ expect(z.parse(a, "on")).toEqual(true);
974
+ expect(z.parse(a, "y")).toEqual(true);
975
+ expect(z.parse(a, "enabled")).toEqual(true);
976
+ expect(z.parse(a, "TRUE")).toEqual(true);
977
+
978
+ expect(z.parse(a, "false")).toEqual(false);
979
+ expect(z.parse(a, "no")).toEqual(false);
980
+ expect(z.parse(a, "0")).toEqual(false);
981
+ expect(z.parse(a, "off")).toEqual(false);
982
+ expect(z.parse(a, "n")).toEqual(false);
983
+ expect(z.parse(a, "disabled")).toEqual(false);
984
+ expect(z.parse(a, "FALSE")).toEqual(false);
985
+
986
+ expect(z.safeParse(a, "other")).toMatchObject({ success: false });
987
+ expect(z.safeParse(a, "")).toMatchObject({ success: false });
988
+ expect(z.safeParse(a, undefined)).toMatchObject({ success: false });
989
+ expect(z.safeParse(a, {})).toMatchObject({ success: false });
990
+ expect(z.safeParse(a, true)).toMatchObject({ success: false });
991
+ expect(z.safeParse(a, false)).toMatchObject({ success: false });
992
+
993
+ const b = z.stringbool({
994
+ truthy: ["y"],
995
+ falsy: ["n"],
996
+ });
997
+ expect(z.parse(b, "y")).toEqual(true);
998
+ expect(z.parse(b, "n")).toEqual(false);
999
+ expect(z.safeParse(b, "true")).toMatchObject({ success: false });
1000
+ expect(z.safeParse(b, "false")).toMatchObject({ success: false });
1001
+ expect(b._yatsp.bag.truthy).toEqual(["y"]);
1002
+ expect(b._yatsp.bag.falsy).toEqual(["n"]);
1003
+
1004
+ const c = z.stringbool({
1005
+ case: "sensitive",
1006
+ });
1007
+ expect(z.parse(c, "true")).toEqual(true);
1008
+ expect(z.safeParse(c, "TRUE")).toMatchObject({ success: false });
1009
+ expect(c._yatsp.bag.case).toEqual("sensitive");
1010
+ });
1011
+
1012
+ // promise
1013
+ test("z.promise", async () => {
1014
+ const a = z.promise(z.string());
1015
+ type a = z.output<typeof a>;
1016
+ expectTypeOf<a>().toEqualTypeOf<Promise<string>>();
1017
+
1018
+ expect(await z.safeParseAsync(a, Promise.resolve("hello"))).toMatchObject({
1019
+ success: true,
1020
+ data: "hello",
1021
+ });
1022
+ expect(await z.safeParseAsync(a, Promise.resolve(123))).toMatchObject({
1023
+ success: false,
1024
+ });
1025
+
1026
+ const b = z.string();
1027
+ expect(() => z.parse(b, Promise.resolve("hello"))).toThrow();
1028
+ });
1029
+
1030
+ // test("type assertions", () => {
1031
+ // const schema = z.pipe(
1032
+ // z.string(),
1033
+ // z.transform((val) => val.length)
1034
+ // );
1035
+ // schema.assertInput<string>();
1036
+ // // @ts-expect-error
1037
+ // schema.assertInput<number>();
1038
+
1039
+ // schema.assertOutput<number>();
1040
+ // // @ts-expect-error
1041
+ // schema.assertOutput<string>();
1042
+ // });
1043
+
1044
+ test("z.pipe type enforcement", () => {
1045
+ z.pipe(
1046
+ z.pipe(
1047
+ z.string().check(z.regex(/asdf/)),
1048
+ z.transform((v) => new Date(v))
1049
+ ),
1050
+ z.date().check(z.maximum(new Date()))
1051
+ );
1052
+ });
1053
+
1054
+ test("def typing", () => {
1055
+ z.string().def.type satisfies "string";
1056
+ z.email().def.format satisfies "email";
1057
+ z.number().def.type satisfies "number";
1058
+ z.float64().def.format satisfies z.core.$YatspNumberFormats;
1059
+ z.bigint().def.type satisfies "bigint";
1060
+ z.boolean().def.type satisfies "boolean";
1061
+ z.date().def.type satisfies "date";
1062
+ z.symbol().def.type satisfies "symbol";
1063
+ z.undefined().def.type satisfies "undefined";
1064
+ z.nullable(z.string()).def.type satisfies "nullable";
1065
+ z.null().def.type satisfies "null";
1066
+ z.any().def.type satisfies "any";
1067
+ z.unknown().def.type satisfies "unknown";
1068
+ z.never().def.type satisfies "never";
1069
+ z.void().def.type satisfies "void";
1070
+ z.array(z.string()).def.type satisfies "array";
1071
+ z.object({ key: z.string() }).def.type satisfies "object";
1072
+ z.union([z.string(), z.number()]).def.type satisfies "union";
1073
+ z.intersection(z.string(), z.number()).def.type satisfies "intersection";
1074
+ z.tuple([z.string(), z.number()]).def.type satisfies "tuple";
1075
+ z.record(z.string(), z.number()).def.type satisfies "record";
1076
+ z.map(z.string(), z.number()).def.type satisfies "map";
1077
+ z.set(z.string()).def.type satisfies "set";
1078
+ z.literal("example").def.type satisfies "literal";
1079
+ expectTypeOf(z.literal("example").def.values).toEqualTypeOf<"example"[]>();
1080
+ z.enum(["a", "b", "c"]).def.type satisfies "enum";
1081
+ z.promise(z.string()).def.type satisfies "promise";
1082
+ z.lazy(() => z.string()).def.type satisfies "lazy";
1083
+ z.optional(z.string()).def.type satisfies "optional";
1084
+ z._default(z.string(), "default").def.type satisfies "default";
1085
+ z.templateLiteral([z.literal("a"), z.literal("b")]).def.type satisfies "template_literal";
1086
+ z.custom<string>((val) => typeof val === "string").def.type satisfies "custom";
1087
+ z.transform((val) => val as string).def.type satisfies "transform";
1088
+ z.nonoptional(z.string()).def.type satisfies "nonoptional";
1089
+ z.readonly(z.unknown()).def.type satisfies "readonly";
1090
+ z.nan().def.type satisfies "nan";
1091
+ z.pipe(z.unknown(), z.number()).def.type satisfies "pipe";
1092
+ z.success(z.string()).def.type satisfies "success";
1093
+ z.catch(z.string(), "fallback").def.type satisfies "catch";
1094
+ z.file().def.type satisfies "file";
1095
+ });
1096
+
1097
+ test("defaulted object schema returns shallow clone", () => {
1098
+ const schema = z._default(
1099
+ z.object({
1100
+ a: z.string(),
1101
+ }),
1102
+ { a: "x" }
1103
+ );
1104
+ const result1 = schema.parse(undefined);
1105
+ const result2 = schema.parse(undefined);
1106
+ expect(result1).not.toBe(result2);
1107
+ expect(result1).toEqual(result2);
1108
+ });
1109
+
1110
+ test("runtime type property exists and returns correct values", () => {
1111
+ const stringSchema = z.string();
1112
+ expect(stringSchema.type).toBe("string");
1113
+ });
1114
+
1115
+ test("type narrowing works with type property", () => {
1116
+ type ArrayOrRecord =
1117
+ | z.YatspMiniArray<z.YatspMiniString>
1118
+ | z.YatspMiniRecord<z.YatspMiniString<string>, z.YatspMiniAny>;
1119
+ const arraySchema = z.array(z.string()) as ArrayOrRecord;
1120
+
1121
+ if (arraySchema.type === "array") {
1122
+ expectTypeOf(arraySchema).toEqualTypeOf<z.YatspMiniArray<z.YatspMiniString<unknown>>>();
1123
+ expect(arraySchema.def.element).toBeDefined();
1124
+ }
1125
+ });
1126
+
1127
+ test("getDiscriminatedOption", () => {
1128
+ const a = z.object({ type: z.literal("a"), x: z.string() });
1129
+ const b = z.object({ type: z.literal("b"), y: z.number() });
1130
+ const schema = z.discriminatedUnion("type", [a, b]);
1131
+
1132
+ expect(z.getDiscriminatedOption(schema, "a")).toBe(a);
1133
+ expect(z.getDiscriminatedOption(schema, "b")).toBe(b);
1134
+ expectTypeOf(z.getDiscriminatedOption(schema, "a")).toEqualTypeOf<typeof a>();
1135
+ });
1136
+
1137
+ test("z.partial on a tuple", () => {
1138
+ const schema = z.partial(z.tuple([z.string(), z.number()]));
1139
+ expectTypeOf<z.infer<typeof schema>>().toEqualTypeOf<[(string | undefined)?, (number | undefined)?]>();
1140
+
1141
+ expect(z.safeParse(schema, []).success).toEqual(true);
1142
+ expect(z.safeParse(schema, ["a"]).success).toEqual(true);
1143
+ expect(z.safeParse(schema, ["a", 1]).success).toEqual(true);
1144
+ expect(z.safeParse(schema, ["a", "b"]).success).toEqual(false);
1145
+
1146
+ const refined = z.tuple([z.string(), z.number()]).check(z.refine(([a]) => a.length > 0));
1147
+ expect(() => z.partial(refined)).toThrow("cannot be used on tuple schemas containing refinements");
1148
+ });