@anthonyalayo/zod 0.0.0-stage → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (842) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +217 -2
  3. package/compile.cjs +96 -0
  4. package/compile.d.cts +1 -0
  5. package/compile.d.ts +1 -0
  6. package/compile.js +52 -0
  7. package/index.cjs +52 -0
  8. package/index.d.cts +3 -0
  9. package/index.d.ts +3 -0
  10. package/index.js +7 -0
  11. package/locales/index.cjs +36 -0
  12. package/locales/index.d.cts +1 -0
  13. package/locales/index.d.ts +1 -0
  14. package/locales/index.js +1 -0
  15. package/locales/package.json +7 -0
  16. package/mini/index.cjs +51 -0
  17. package/mini/index.d.cts +3 -0
  18. package/mini/index.d.ts +3 -0
  19. package/mini/index.js +3 -0
  20. package/mini/package.json +7 -0
  21. package/package.json +144 -4
  22. package/src/compile.ts +56 -0
  23. package/src/index.ts +7 -0
  24. package/src/locales/index.ts +1 -0
  25. package/src/mini/index.ts +3 -0
  26. package/src/v3/ZodError.ts +340 -0
  27. package/src/v3/benchmarks/datetime.ts +58 -0
  28. package/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  29. package/src/v3/benchmarks/index.ts +59 -0
  30. package/src/v3/benchmarks/ipv4.ts +57 -0
  31. package/src/v3/benchmarks/object.ts +69 -0
  32. package/src/v3/benchmarks/primitives.ts +162 -0
  33. package/src/v3/benchmarks/realworld.ts +63 -0
  34. package/src/v3/benchmarks/string.ts +55 -0
  35. package/src/v3/benchmarks/union.ts +80 -0
  36. package/src/v3/errors.ts +13 -0
  37. package/src/v3/external.ts +6 -0
  38. package/src/v3/helpers/enumUtil.ts +17 -0
  39. package/src/v3/helpers/errorUtil.ts +8 -0
  40. package/src/v3/helpers/parseUtil.ts +176 -0
  41. package/src/v3/helpers/partialUtil.ts +34 -0
  42. package/src/v3/helpers/typeAliases.ts +2 -0
  43. package/src/v3/helpers/util.ts +224 -0
  44. package/src/v3/index.ts +4 -0
  45. package/src/v3/locales/en.ts +124 -0
  46. package/src/v3/standard-schema.ts +113 -0
  47. package/src/v3/tests/Mocker.ts +54 -0
  48. package/src/v3/tests/all-errors.test.ts +157 -0
  49. package/src/v3/tests/anyunknown.test.ts +28 -0
  50. package/src/v3/tests/array.test.ts +92 -0
  51. package/src/v3/tests/async-parsing.test.ts +388 -0
  52. package/src/v3/tests/async-refinements.test.ts +46 -0
  53. package/src/v3/tests/base.test.ts +29 -0
  54. package/src/v3/tests/bigint.test.ts +55 -0
  55. package/src/v3/tests/branded.test.ts +53 -0
  56. package/src/v3/tests/catch.test.ts +220 -0
  57. package/src/v3/tests/coerce.test.ts +133 -0
  58. package/src/v3/tests/complex.test.ts +70 -0
  59. package/src/v3/tests/custom.test.ts +31 -0
  60. package/src/v3/tests/date.test.ts +32 -0
  61. package/src/v3/tests/deepmasking.test.ts +186 -0
  62. package/src/v3/tests/default.test.ts +112 -0
  63. package/src/v3/tests/description.test.ts +33 -0
  64. package/src/v3/tests/discriminated-unions.test.ts +315 -0
  65. package/src/v3/tests/enum.test.ts +80 -0
  66. package/src/v3/tests/error.test.ts +586 -0
  67. package/src/v3/tests/firstparty.test.ts +87 -0
  68. package/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  69. package/src/v3/tests/function.test.ts +261 -0
  70. package/src/v3/tests/generics.test.ts +48 -0
  71. package/src/v3/tests/instanceof.test.ts +37 -0
  72. package/src/v3/tests/intersection.test.ts +136 -0
  73. package/src/v3/tests/language-server.source.ts +76 -0
  74. package/src/v3/tests/language-server.test.ts +206 -0
  75. package/src/v3/tests/literal.test.ts +36 -0
  76. package/src/v3/tests/map.test.ts +110 -0
  77. package/src/v3/tests/masking.test.ts +4 -0
  78. package/src/v3/tests/mocker.test.ts +19 -0
  79. package/src/v3/tests/nan.test.ts +24 -0
  80. package/src/v3/tests/nativeEnum.test.ts +87 -0
  81. package/src/v3/tests/nullable.test.ts +42 -0
  82. package/src/v3/tests/number.test.ts +176 -0
  83. package/src/v3/tests/object-augmentation.test.ts +29 -0
  84. package/src/v3/tests/object-in-es5-env.test.ts +29 -0
  85. package/src/v3/tests/object.test.ts +431 -0
  86. package/src/v3/tests/optional.test.ts +42 -0
  87. package/src/v3/tests/parseUtil.test.ts +23 -0
  88. package/src/v3/tests/parser.test.ts +41 -0
  89. package/src/v3/tests/partials.test.ts +243 -0
  90. package/src/v3/tests/pickomit.test.ts +111 -0
  91. package/src/v3/tests/pipeline.test.ts +29 -0
  92. package/src/v3/tests/preprocess.test.ts +186 -0
  93. package/src/v3/tests/primitive.test.ts +440 -0
  94. package/src/v3/tests/promise.test.ts +90 -0
  95. package/src/v3/tests/readonly.test.ts +114 -0
  96. package/src/v3/tests/record.test.ts +171 -0
  97. package/src/v3/tests/recursive.test.ts +197 -0
  98. package/src/v3/tests/refine.test.ts +313 -0
  99. package/src/v3/tests/safeparse.test.ts +27 -0
  100. package/src/v3/tests/set.test.ts +148 -0
  101. package/src/v3/tests/standard-schema.test.ts +83 -0
  102. package/src/v3/tests/string.test.ts +922 -0
  103. package/src/v3/tests/transformer.test.ts +233 -0
  104. package/src/v3/tests/tuple.test.ts +90 -0
  105. package/src/v3/tests/unions.test.ts +57 -0
  106. package/src/v3/tests/validations.test.ts +133 -0
  107. package/src/v3/tests/void.test.ts +15 -0
  108. package/src/v3/types.ts +5149 -0
  109. package/src/v4/classic/checks.ts +33 -0
  110. package/src/v4/classic/coerce.ts +27 -0
  111. package/src/v4/classic/compat.ts +78 -0
  112. package/src/v4/classic/deep-partial.ts +76 -0
  113. package/src/v4/classic/errors.ts +97 -0
  114. package/src/v4/classic/external.ts +57 -0
  115. package/src/v4/classic/from-json-schema.ts +944 -0
  116. package/src/v4/classic/in-out.ts +45 -0
  117. package/src/v4/classic/index.ts +5 -0
  118. package/src/v4/classic/iso.ts +20 -0
  119. package/src/v4/classic/parse.ts +88 -0
  120. package/src/v4/classic/schemas.ts +3009 -0
  121. package/src/v4/classic/tests/anyunknown.test.ts +26 -0
  122. package/src/v4/classic/tests/apply.test.ts +86 -0
  123. package/src/v4/classic/tests/array.test.ts +339 -0
  124. package/src/v4/classic/tests/assignability.test.ts +402 -0
  125. package/src/v4/classic/tests/async-parsing.test.ts +381 -0
  126. package/src/v4/classic/tests/async-refinements.test.ts +68 -0
  127. package/src/v4/classic/tests/base.test.ts +7 -0
  128. package/src/v4/classic/tests/bigint.test.ts +89 -0
  129. package/src/v4/classic/tests/brand.test.ts +106 -0
  130. package/src/v4/classic/tests/catch.test.ts +604 -0
  131. package/src/v4/classic/tests/coalesce.test.ts +20 -0
  132. package/src/v4/classic/tests/codec-examples.test.ts +572 -0
  133. package/src/v4/classic/tests/codec.test.ts +704 -0
  134. package/src/v4/classic/tests/coerce.test.ts +160 -0
  135. package/src/v4/classic/tests/continuability.test.ts +374 -0
  136. package/src/v4/classic/tests/credit-card.test.ts +76 -0
  137. package/src/v4/classic/tests/custom.test.ts +40 -0
  138. package/src/v4/classic/tests/cyclic-data.test.ts +1248 -0
  139. package/src/v4/classic/tests/date.test.ts +92 -0
  140. package/src/v4/classic/tests/datetime.test.ts +316 -0
  141. package/src/v4/classic/tests/deep-partial.test.ts +380 -0
  142. package/src/v4/classic/tests/default-locale.test.ts +32 -0
  143. package/src/v4/classic/tests/default.test.ts +455 -0
  144. package/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
  145. package/src/v4/classic/tests/description.test.ts +32 -0
  146. package/src/v4/classic/tests/detached-methods.test.ts +221 -0
  147. package/src/v4/classic/tests/discriminated-unions.test.ts +942 -0
  148. package/src/v4/classic/tests/enum.test.ts +305 -0
  149. package/src/v4/classic/tests/error-utils.test.ts +917 -0
  150. package/src/v4/classic/tests/error.test.ts +1108 -0
  151. package/src/v4/classic/tests/file.test.ts +96 -0
  152. package/src/v4/classic/tests/firstparty.test.ts +179 -0
  153. package/src/v4/classic/tests/fix-json-issue.test.ts +26 -0
  154. package/src/v4/classic/tests/from-json-schema.test.ts +1467 -0
  155. package/src/v4/classic/tests/function.test.ts +391 -0
  156. package/src/v4/classic/tests/generics.test.ts +72 -0
  157. package/src/v4/classic/tests/global-config.test.ts +32 -0
  158. package/src/v4/classic/tests/hash.test.ts +67 -0
  159. package/src/v4/classic/tests/iban.test.ts +81 -0
  160. package/src/v4/classic/tests/in-out.test.ts +159 -0
  161. package/src/v4/classic/tests/index.test.ts +958 -0
  162. package/src/v4/classic/tests/instance-footprint.test.ts +319 -0
  163. package/src/v4/classic/tests/instanceof.test.ts +127 -0
  164. package/src/v4/classic/tests/intersection.test.ts +368 -0
  165. package/src/v4/classic/tests/issue-schema.test.ts +215 -0
  166. package/src/v4/classic/tests/jitless-allows-eval.test.ts +39 -0
  167. package/src/v4/classic/tests/json.test.ts +109 -0
  168. package/src/v4/classic/tests/lazy.test.ts +276 -0
  169. package/src/v4/classic/tests/literal.test.ts +128 -0
  170. package/src/v4/classic/tests/locales_ka.test.ts +29 -0
  171. package/src/v4/classic/tests/locales_ro.test.ts +24 -0
  172. package/src/v4/classic/tests/map.test.ts +349 -0
  173. package/src/v4/classic/tests/nan.test.ts +21 -0
  174. package/src/v4/classic/tests/nested-refine.test.ts +168 -0
  175. package/src/v4/classic/tests/nonoptional.test.ts +101 -0
  176. package/src/v4/classic/tests/nullable.test.ts +22 -0
  177. package/src/v4/classic/tests/number.test.ts +401 -0
  178. package/src/v4/classic/tests/object.test.ts +1015 -0
  179. package/src/v4/classic/tests/optin-ladder.test.ts +235 -0
  180. package/src/v4/classic/tests/optional.test.ts +366 -0
  181. package/src/v4/classic/tests/partial.test.ts +497 -0
  182. package/src/v4/classic/tests/pickomit.test.ts +211 -0
  183. package/src/v4/classic/tests/pipe.test.ts +101 -0
  184. package/src/v4/classic/tests/prefault.test.ts +144 -0
  185. package/src/v4/classic/tests/preprocess-types.test.ts +44 -0
  186. package/src/v4/classic/tests/preprocess.test.ts +351 -0
  187. package/src/v4/classic/tests/primitive.test.ts +175 -0
  188. package/src/v4/classic/tests/promise.test.ts +81 -0
  189. package/src/v4/classic/tests/properties.test.ts +141 -0
  190. package/src/v4/classic/tests/prototypes.test.ts +23 -0
  191. package/src/v4/classic/tests/readonly.test.ts +184 -0
  192. package/src/v4/classic/tests/record.test.ts +901 -0
  193. package/src/v4/classic/tests/recursive-types.test.ts +707 -0
  194. package/src/v4/classic/tests/redos.test.ts +68 -0
  195. package/src/v4/classic/tests/refine.test.ts +720 -0
  196. package/src/v4/classic/tests/registries.test.ts +243 -0
  197. package/src/v4/classic/tests/set.test.ts +196 -0
  198. package/src/v4/classic/tests/standard-schema.test.ts +153 -0
  199. package/src/v4/classic/tests/string-formats.test.ts +125 -0
  200. package/src/v4/classic/tests/string.test.ts +1440 -0
  201. package/src/v4/classic/tests/stringbool.test.ts +124 -0
  202. package/src/v4/classic/tests/template-literal.test.ts +864 -0
  203. package/src/v4/classic/tests/to-json-schema-methods.test.ts +438 -0
  204. package/src/v4/classic/tests/to-json-schema.test.ts +4811 -0
  205. package/src/v4/classic/tests/transform.test.ts +414 -0
  206. package/src/v4/classic/tests/tuple.test.ts +520 -0
  207. package/src/v4/classic/tests/union.test.ts +358 -0
  208. package/src/v4/classic/tests/update.test.ts +92 -0
  209. package/src/v4/classic/tests/url.test.ts +13 -0
  210. package/src/v4/classic/tests/validate.test.ts +645 -0
  211. package/src/v4/classic/tests/validations.test.ts +283 -0
  212. package/src/v4/classic/tests/void.test.ts +12 -0
  213. package/src/v4/core/api.ts +1875 -0
  214. package/src/v4/core/checks.ts +1266 -0
  215. package/src/v4/core/compile.ts +2323 -0
  216. package/src/v4/core/core.ts +230 -0
  217. package/src/v4/core/doc.ts +52 -0
  218. package/src/v4/core/errors.ts +543 -0
  219. package/src/v4/core/index.ts +19 -0
  220. package/src/v4/core/json-schema-generator.ts +131 -0
  221. package/src/v4/core/json-schema-processors.ts +944 -0
  222. package/src/v4/core/json-schema.ts +148 -0
  223. package/src/v4/core/memoizer.ts +404 -0
  224. package/src/v4/core/parse.ts +309 -0
  225. package/src/v4/core/regexes.ts +217 -0
  226. package/src/v4/core/registries.ts +105 -0
  227. package/src/v4/core/schemas.ts +5271 -0
  228. package/src/v4/core/standard-schema.ts +159 -0
  229. package/src/v4/core/tests/cached.test.ts +54 -0
  230. package/src/v4/core/tests/compile-differential.test.ts +1004 -0
  231. package/src/v4/core/tests/compile-generative.test.ts +445 -0
  232. package/src/v4/core/tests/compile-global.test.ts +89 -0
  233. package/src/v4/core/tests/compile-off-by-default.test.ts +26 -0
  234. package/src/v4/core/tests/compile-stats.test.ts +34 -0
  235. package/src/v4/core/tests/compile.test.ts +2056 -0
  236. package/src/v4/core/tests/email-regex.test.ts +140 -0
  237. package/src/v4/core/tests/extend.test.ts +59 -0
  238. package/src/v4/core/tests/index.test.ts +46 -0
  239. package/src/v4/core/tests/locales/be.test.ts +124 -0
  240. package/src/v4/core/tests/locales/el.test.ts +214 -0
  241. package/src/v4/core/tests/locales/en.test.ts +22 -0
  242. package/src/v4/core/tests/locales/es.test.ts +180 -0
  243. package/src/v4/core/tests/locales/fr.test.ts +72 -0
  244. package/src/v4/core/tests/locales/he.test.ts +391 -0
  245. package/src/v4/core/tests/locales/hr.test.ts +163 -0
  246. package/src/v4/core/tests/locales/hy.test.ts +15 -0
  247. package/src/v4/core/tests/locales/nl.test.ts +46 -0
  248. package/src/v4/core/tests/locales/parity.test.ts +67 -0
  249. package/src/v4/core/tests/locales/ru.test.ts +128 -0
  250. package/src/v4/core/tests/locales/tg.test.ts +85 -0
  251. package/src/v4/core/tests/locales/tk.test.ts +69 -0
  252. package/src/v4/core/tests/locales/tr.test.ts +69 -0
  253. package/src/v4/core/tests/locales/uz.test.ts +105 -0
  254. package/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  255. package/src/v4/core/tests/record-constructor.test.ts +125 -0
  256. package/src/v4/core/tests/recursive-tuples.test.ts +45 -0
  257. package/src/v4/core/tests/treeshake.test.ts +51 -0
  258. package/src/v4/core/tests/url-no-canparse.test.ts +133 -0
  259. package/src/v4/core/to-json-schema.ts +857 -0
  260. package/src/v4/core/util.ts +1322 -0
  261. package/src/v4/core/versions.ts +5 -0
  262. package/src/v4/core/visit.ts +193 -0
  263. package/src/v4/core/zsf.ts +323 -0
  264. package/src/v4/index.ts +4 -0
  265. package/src/v4/locales/ar.ts +120 -0
  266. package/src/v4/locales/az.ts +116 -0
  267. package/src/v4/locales/be.ts +188 -0
  268. package/src/v4/locales/bg.ts +133 -0
  269. package/src/v4/locales/bn.ts +123 -0
  270. package/src/v4/locales/ca.ts +121 -0
  271. package/src/v4/locales/ckb.ts +140 -0
  272. package/src/v4/locales/cs.ts +123 -0
  273. package/src/v4/locales/da.ts +128 -0
  274. package/src/v4/locales/de.ts +121 -0
  275. package/src/v4/locales/el.ts +124 -0
  276. package/src/v4/locales/en.ts +136 -0
  277. package/src/v4/locales/eo.ts +123 -0
  278. package/src/v4/locales/es.ts +146 -0
  279. package/src/v4/locales/fa.ts +131 -0
  280. package/src/v4/locales/fi.ts +126 -0
  281. package/src/v4/locales/fr-CA.ts +121 -0
  282. package/src/v4/locales/fr.ts +140 -0
  283. package/src/v4/locales/gu.ts +123 -0
  284. package/src/v4/locales/he.ts +254 -0
  285. package/src/v4/locales/hi.ts +126 -0
  286. package/src/v4/locales/hr.ts +136 -0
  287. package/src/v4/locales/hu.ts +122 -0
  288. package/src/v4/locales/hy.ts +175 -0
  289. package/src/v4/locales/id.ts +120 -0
  290. package/src/v4/locales/index.ts +63 -0
  291. package/src/v4/locales/is.ts +124 -0
  292. package/src/v4/locales/it.ts +121 -0
  293. package/src/v4/locales/ja.ts +119 -0
  294. package/src/v4/locales/ka.ts +128 -0
  295. package/src/v4/locales/kh.ts +7 -0
  296. package/src/v4/locales/km.ts +124 -0
  297. package/src/v4/locales/kn.ts +126 -0
  298. package/src/v4/locales/ko.ts +126 -0
  299. package/src/v4/locales/lt.ts +260 -0
  300. package/src/v4/locales/mk.ts +123 -0
  301. package/src/v4/locales/ms.ts +120 -0
  302. package/src/v4/locales/ne.ts +128 -0
  303. package/src/v4/locales/nl.ts +126 -0
  304. package/src/v4/locales/nn.ts +121 -0
  305. package/src/v4/locales/no.ts +121 -0
  306. package/src/v4/locales/ota.ts +122 -0
  307. package/src/v4/locales/pl.ts +123 -0
  308. package/src/v4/locales/ps.ts +131 -0
  309. package/src/v4/locales/pt-BR.ts +161 -0
  310. package/src/v4/locales/pt.ts +159 -0
  311. package/src/v4/locales/ro.ts +132 -0
  312. package/src/v4/locales/ru.ts +188 -0
  313. package/src/v4/locales/sk.ts +123 -0
  314. package/src/v4/locales/sl.ts +123 -0
  315. package/src/v4/locales/sv.ts +124 -0
  316. package/src/v4/locales/ta.ts +123 -0
  317. package/src/v4/locales/tg.ts +135 -0
  318. package/src/v4/locales/th.ts +124 -0
  319. package/src/v4/locales/tk.ts +113 -0
  320. package/src/v4/locales/tr.ts +116 -0
  321. package/src/v4/locales/ua.ts +7 -0
  322. package/src/v4/locales/uk.ts +122 -0
  323. package/src/v4/locales/ur.ts +124 -0
  324. package/src/v4/locales/uz.ts +120 -0
  325. package/src/v4/locales/vi.ts +122 -0
  326. package/src/v4/locales/yo.ts +129 -0
  327. package/src/v4/locales/zh-CN.ts +121 -0
  328. package/src/v4/locales/zh-TW.ts +120 -0
  329. package/src/v4/mini/checks.ts +33 -0
  330. package/src/v4/mini/coerce.ts +27 -0
  331. package/src/v4/mini/deep-partial.ts +73 -0
  332. package/src/v4/mini/external.ts +52 -0
  333. package/src/v4/mini/in-out.ts +45 -0
  334. package/src/v4/mini/index.ts +3 -0
  335. package/src/v4/mini/iso.ts +66 -0
  336. package/src/v4/mini/parse.ts +16 -0
  337. package/src/v4/mini/schemas.ts +2051 -0
  338. package/src/v4/mini/tests/apply.test.ts +57 -0
  339. package/src/v4/mini/tests/assignability.test.ts +190 -0
  340. package/src/v4/mini/tests/brand.test.ts +94 -0
  341. package/src/v4/mini/tests/checks.test.ts +158 -0
  342. package/src/v4/mini/tests/codec.test.ts +582 -0
  343. package/src/v4/mini/tests/computed.test.ts +30 -0
  344. package/src/v4/mini/tests/cyclic-data.test.ts +97 -0
  345. package/src/v4/mini/tests/deep-partial.test.ts +54 -0
  346. package/src/v4/mini/tests/error.test.ts +41 -0
  347. package/src/v4/mini/tests/functions.test.ts +14 -0
  348. package/src/v4/mini/tests/index.test.ts +1175 -0
  349. package/src/v4/mini/tests/number.test.ts +109 -0
  350. package/src/v4/mini/tests/object.test.ts +292 -0
  351. package/src/v4/mini/tests/prototypes.test.ts +43 -0
  352. package/src/v4/mini/tests/recursive-types.test.ts +341 -0
  353. package/src/v4/mini/tests/standard-schema.test.ts +50 -0
  354. package/src/v4/mini/tests/string.test.ts +396 -0
  355. package/src/v4-mini/index.ts +3 -0
  356. package/v3/ZodError.cjs +167 -0
  357. package/v3/ZodError.d.cts +164 -0
  358. package/v3/ZodError.d.ts +164 -0
  359. package/v3/ZodError.js +143 -0
  360. package/v3/errors.cjs +36 -0
  361. package/v3/errors.d.cts +5 -0
  362. package/v3/errors.d.ts +5 -0
  363. package/v3/errors.js +9 -0
  364. package/v3/external.cjs +41 -0
  365. package/v3/external.d.cts +6 -0
  366. package/v3/external.d.ts +6 -0
  367. package/v3/external.js +6 -0
  368. package/v3/helpers/enumUtil.cjs +21 -0
  369. package/v3/helpers/enumUtil.d.cts +8 -0
  370. package/v3/helpers/enumUtil.d.ts +8 -0
  371. package/v3/helpers/enumUtil.js +1 -0
  372. package/v3/helpers/errorUtil.cjs +28 -0
  373. package/v3/helpers/errorUtil.d.cts +9 -0
  374. package/v3/helpers/errorUtil.d.ts +9 -0
  375. package/v3/helpers/errorUtil.js +6 -0
  376. package/v3/helpers/parseUtil.cjs +143 -0
  377. package/v3/helpers/parseUtil.d.cts +78 -0
  378. package/v3/helpers/parseUtil.d.ts +78 -0
  379. package/v3/helpers/parseUtil.js +109 -0
  380. package/v3/helpers/partialUtil.cjs +21 -0
  381. package/v3/helpers/partialUtil.d.cts +8 -0
  382. package/v3/helpers/partialUtil.d.ts +8 -0
  383. package/v3/helpers/partialUtil.js +1 -0
  384. package/v3/helpers/typeAliases.cjs +21 -0
  385. package/v3/helpers/typeAliases.d.cts +2 -0
  386. package/v3/helpers/typeAliases.d.ts +2 -0
  387. package/v3/helpers/typeAliases.js +1 -0
  388. package/v3/helpers/util.cjs +156 -0
  389. package/v3/helpers/util.d.cts +85 -0
  390. package/v3/helpers/util.d.ts +85 -0
  391. package/v3/helpers/util.js +133 -0
  392. package/v3/index.cjs +52 -0
  393. package/v3/index.d.cts +4 -0
  394. package/v3/index.d.ts +4 -0
  395. package/v3/index.js +4 -0
  396. package/v3/locales/en.cjs +112 -0
  397. package/v3/locales/en.d.cts +3 -0
  398. package/v3/locales/en.d.ts +3 -0
  399. package/v3/locales/en.js +109 -0
  400. package/v3/package.json +7 -0
  401. package/v3/standard-schema.cjs +21 -0
  402. package/v3/standard-schema.d.cts +102 -0
  403. package/v3/standard-schema.d.ts +102 -0
  404. package/v3/standard-schema.js +1 -0
  405. package/v3/types.cjs +3806 -0
  406. package/v3/types.d.cts +1034 -0
  407. package/v3/types.d.ts +1034 -0
  408. package/v3/types.js +3705 -0
  409. package/v4/classic/checks.cjs +53 -0
  410. package/v4/classic/checks.d.cts +1 -0
  411. package/v4/classic/checks.d.ts +1 -0
  412. package/v4/classic/checks.js +1 -0
  413. package/v4/classic/coerce.cjs +66 -0
  414. package/v4/classic/coerce.d.cts +17 -0
  415. package/v4/classic/coerce.d.ts +17 -0
  416. package/v4/classic/coerce.js +17 -0
  417. package/v4/classic/compat.cjs +80 -0
  418. package/v4/classic/compat.d.cts +48 -0
  419. package/v4/classic/compat.d.ts +48 -0
  420. package/v4/classic/compat.js +31 -0
  421. package/v4/classic/deep-partial.cjs +58 -0
  422. package/v4/classic/deep-partial.d.cts +14 -0
  423. package/v4/classic/deep-partial.d.ts +14 -0
  424. package/v4/classic/deep-partial.js +13 -0
  425. package/v4/classic/errors.cjs +102 -0
  426. package/v4/classic/errors.d.cts +29 -0
  427. package/v4/classic/errors.d.ts +29 -0
  428. package/v4/classic/errors.js +57 -0
  429. package/v4/classic/external.cjs +97 -0
  430. package/v4/classic/external.d.cts +19 -0
  431. package/v4/classic/external.d.ts +19 -0
  432. package/v4/classic/external.js +17 -0
  433. package/v4/classic/from-json-schema.cjs +926 -0
  434. package/v4/classic/from-json-schema.d.cts +12 -0
  435. package/v4/classic/from-json-schema.d.ts +12 -0
  436. package/v4/classic/from-json-schema.js +881 -0
  437. package/v4/classic/in-out.cjs +82 -0
  438. package/v4/classic/in-out.d.cts +8 -0
  439. package/v4/classic/in-out.d.ts +8 -0
  440. package/v4/classic/in-out.js +36 -0
  441. package/v4/classic/index.cjs +52 -0
  442. package/v4/classic/index.d.cts +3 -0
  443. package/v4/classic/index.d.ts +3 -0
  444. package/v4/classic/index.js +4 -0
  445. package/v4/classic/iso.cjs +68 -0
  446. package/v4/classic/iso.d.cts +7 -0
  447. package/v4/classic/iso.d.ts +7 -0
  448. package/v4/classic/iso.js +15 -0
  449. package/v4/classic/package.json +7 -0
  450. package/v4/classic/parse.cjs +63 -0
  451. package/v4/classic/parse.d.cts +44 -0
  452. package/v4/classic/parse.d.ts +44 -0
  453. package/v4/classic/parse.js +16 -0
  454. package/v4/classic/schemas.cjs +1750 -0
  455. package/v4/classic/schemas.d.cts +819 -0
  456. package/v4/classic/schemas.d.ts +819 -0
  457. package/v4/classic/schemas.js +1609 -0
  458. package/v4/core/api.cjs +1269 -0
  459. package/v4/core/api.d.cts +335 -0
  460. package/v4/core/api.d.ts +335 -0
  461. package/v4/core/api.js +1107 -0
  462. package/v4/core/checks.cjs +561 -0
  463. package/v4/core/checks.d.cts +294 -0
  464. package/v4/core/checks.d.ts +294 -0
  465. package/v4/core/checks.js +516 -0
  466. package/v4/core/compile.cjs +1915 -0
  467. package/v4/core/compile.d.cts +65 -0
  468. package/v4/core/compile.d.ts +65 -0
  469. package/v4/core/compile.js +1865 -0
  470. package/v4/core/core.cjs +167 -0
  471. package/v4/core/core.d.cts +82 -0
  472. package/v4/core/core.d.ts +82 -0
  473. package/v4/core/core.js +141 -0
  474. package/v4/core/doc.cjs +61 -0
  475. package/v4/core/doc.d.cts +16 -0
  476. package/v4/core/doc.d.ts +16 -0
  477. package/v4/core/doc.js +38 -0
  478. package/v4/core/errors.cjs +317 -0
  479. package/v4/core/errors.d.cts +225 -0
  480. package/v4/core/errors.d.ts +225 -0
  481. package/v4/core/errors.js +267 -0
  482. package/v4/core/index.cjs +70 -0
  483. package/v4/core/index.d.cts +19 -0
  484. package/v4/core/index.d.ts +19 -0
  485. package/v4/core/index.js +19 -0
  486. package/v4/core/json-schema-generator.cjs +122 -0
  487. package/v4/core/json-schema-generator.d.cts +65 -0
  488. package/v4/core/json-schema-generator.d.ts +65 -0
  489. package/v4/core/json-schema-generator.js +99 -0
  490. package/v4/core/json-schema-processors.cjs +945 -0
  491. package/v4/core/json-schema-processors.d.cts +65 -0
  492. package/v4/core/json-schema-processors.d.ts +65 -0
  493. package/v4/core/json-schema-processors.js +859 -0
  494. package/v4/core/json-schema.cjs +21 -0
  495. package/v4/core/json-schema.d.cts +89 -0
  496. package/v4/core/json-schema.d.ts +89 -0
  497. package/v4/core/json-schema.js +1 -0
  498. package/v4/core/memoizer.cjs +424 -0
  499. package/v4/core/memoizer.d.cts +15 -0
  500. package/v4/core/memoizer.d.ts +15 -0
  501. package/v4/core/memoizer.js +375 -0
  502. package/v4/core/package.json +7 -0
  503. package/v4/core/parse.cjs +233 -0
  504. package/v4/core/parse.d.cts +52 -0
  505. package/v4/core/parse.d.ts +52 -0
  506. package/v4/core/parse.js +175 -0
  507. package/v4/core/regexes.cjs +209 -0
  508. package/v4/core/regexes.d.cts +90 -0
  509. package/v4/core/regexes.d.ts +90 -0
  510. package/v4/core/regexes.js +156 -0
  511. package/v4/core/registries.cjs +75 -0
  512. package/v4/core/registries.d.cts +35 -0
  513. package/v4/core/registries.d.ts +35 -0
  514. package/v4/core/registries.js +51 -0
  515. package/v4/core/schemas.cjs +2754 -0
  516. package/v4/core/schemas.d.cts +1277 -0
  517. package/v4/core/schemas.d.ts +1277 -0
  518. package/v4/core/schemas.js +2691 -0
  519. package/v4/core/standard-schema.cjs +21 -0
  520. package/v4/core/standard-schema.d.cts +126 -0
  521. package/v4/core/standard-schema.d.ts +126 -0
  522. package/v4/core/standard-schema.js +1 -0
  523. package/v4/core/to-json-schema.cjs +681 -0
  524. package/v4/core/to-json-schema.d.cts +154 -0
  525. package/v4/core/to-json-schema.d.ts +154 -0
  526. package/v4/core/to-json-schema.js +651 -0
  527. package/v4/core/util.cjs +997 -0
  528. package/v4/core/util.d.cts +284 -0
  529. package/v4/core/util.d.ts +284 -0
  530. package/v4/core/util.js +904 -0
  531. package/v4/core/versions.cjs +27 -0
  532. package/v4/core/versions.d.cts +5 -0
  533. package/v4/core/versions.d.ts +5 -0
  534. package/v4/core/versions.js +5 -0
  535. package/v4/core/visit.cjs +214 -0
  536. package/v4/core/visit.d.cts +30 -0
  537. package/v4/core/visit.d.ts +30 -0
  538. package/v4/core/visit.js +169 -0
  539. package/v4/index.cjs +51 -0
  540. package/v4/index.d.cts +3 -0
  541. package/v4/index.d.ts +3 -0
  542. package/v4/index.js +4 -0
  543. package/v4/locales/ar.cjs +138 -0
  544. package/v4/locales/ar.d.cts +5 -0
  545. package/v4/locales/ar.d.ts +4 -0
  546. package/v4/locales/ar.js +111 -0
  547. package/v4/locales/az.cjs +137 -0
  548. package/v4/locales/az.d.cts +5 -0
  549. package/v4/locales/az.d.ts +4 -0
  550. package/v4/locales/az.js +110 -0
  551. package/v4/locales/be.cjs +195 -0
  552. package/v4/locales/be.d.cts +5 -0
  553. package/v4/locales/be.d.ts +4 -0
  554. package/v4/locales/be.js +168 -0
  555. package/v4/locales/bg.cjs +152 -0
  556. package/v4/locales/bg.d.cts +5 -0
  557. package/v4/locales/bg.d.ts +4 -0
  558. package/v4/locales/bg.js +125 -0
  559. package/v4/locales/bn.cjs +140 -0
  560. package/v4/locales/bn.d.cts +5 -0
  561. package/v4/locales/bn.d.ts +4 -0
  562. package/v4/locales/bn.js +113 -0
  563. package/v4/locales/ca.cjs +139 -0
  564. package/v4/locales/ca.d.cts +5 -0
  565. package/v4/locales/ca.d.ts +4 -0
  566. package/v4/locales/ca.js +112 -0
  567. package/v4/locales/ckb.cjs +160 -0
  568. package/v4/locales/ckb.d.cts +5 -0
  569. package/v4/locales/ckb.d.ts +4 -0
  570. package/v4/locales/ckb.js +133 -0
  571. package/v4/locales/cs.cjs +143 -0
  572. package/v4/locales/cs.d.cts +5 -0
  573. package/v4/locales/cs.d.ts +4 -0
  574. package/v4/locales/cs.js +116 -0
  575. package/v4/locales/da.cjs +147 -0
  576. package/v4/locales/da.d.cts +5 -0
  577. package/v4/locales/da.d.ts +4 -0
  578. package/v4/locales/da.js +120 -0
  579. package/v4/locales/de.cjs +140 -0
  580. package/v4/locales/de.d.cts +5 -0
  581. package/v4/locales/de.d.ts +4 -0
  582. package/v4/locales/de.js +113 -0
  583. package/v4/locales/el.cjs +139 -0
  584. package/v4/locales/el.d.cts +5 -0
  585. package/v4/locales/el.d.ts +4 -0
  586. package/v4/locales/el.js +112 -0
  587. package/v4/locales/en.cjs +152 -0
  588. package/v4/locales/en.d.cts +5 -0
  589. package/v4/locales/en.d.ts +4 -0
  590. package/v4/locales/en.js +125 -0
  591. package/v4/locales/eo.cjs +141 -0
  592. package/v4/locales/eo.d.cts +5 -0
  593. package/v4/locales/eo.d.ts +4 -0
  594. package/v4/locales/eo.js +114 -0
  595. package/v4/locales/es.cjs +164 -0
  596. package/v4/locales/es.d.cts +5 -0
  597. package/v4/locales/es.d.ts +4 -0
  598. package/v4/locales/es.js +137 -0
  599. package/v4/locales/fa.cjs +146 -0
  600. package/v4/locales/fa.d.cts +5 -0
  601. package/v4/locales/fa.d.ts +4 -0
  602. package/v4/locales/fa.js +119 -0
  603. package/v4/locales/fi.cjs +144 -0
  604. package/v4/locales/fi.d.cts +5 -0
  605. package/v4/locales/fi.d.ts +4 -0
  606. package/v4/locales/fi.js +117 -0
  607. package/v4/locales/fr-CA.cjs +139 -0
  608. package/v4/locales/fr-CA.d.cts +5 -0
  609. package/v4/locales/fr-CA.d.ts +4 -0
  610. package/v4/locales/fr-CA.js +112 -0
  611. package/v4/locales/fr.cjs +157 -0
  612. package/v4/locales/fr.d.cts +5 -0
  613. package/v4/locales/fr.d.ts +4 -0
  614. package/v4/locales/fr.js +130 -0
  615. package/v4/locales/gu.cjs +140 -0
  616. package/v4/locales/gu.d.cts +5 -0
  617. package/v4/locales/gu.d.ts +4 -0
  618. package/v4/locales/gu.js +113 -0
  619. package/v4/locales/he.cjs +249 -0
  620. package/v4/locales/he.d.cts +5 -0
  621. package/v4/locales/he.d.ts +4 -0
  622. package/v4/locales/he.js +222 -0
  623. package/v4/locales/hi.cjs +138 -0
  624. package/v4/locales/hi.d.cts +5 -0
  625. package/v4/locales/hi.d.ts +4 -0
  626. package/v4/locales/hi.js +111 -0
  627. package/v4/locales/hr.cjs +154 -0
  628. package/v4/locales/hr.d.cts +5 -0
  629. package/v4/locales/hr.d.ts +4 -0
  630. package/v4/locales/hr.js +127 -0
  631. package/v4/locales/hu.cjs +140 -0
  632. package/v4/locales/hu.d.cts +5 -0
  633. package/v4/locales/hu.d.ts +4 -0
  634. package/v4/locales/hu.js +113 -0
  635. package/v4/locales/hy.cjs +185 -0
  636. package/v4/locales/hy.d.cts +5 -0
  637. package/v4/locales/hy.d.ts +4 -0
  638. package/v4/locales/hy.js +158 -0
  639. package/v4/locales/id.cjs +138 -0
  640. package/v4/locales/id.d.cts +5 -0
  641. package/v4/locales/id.d.ts +4 -0
  642. package/v4/locales/id.js +111 -0
  643. package/v4/locales/index.cjs +152 -0
  644. package/v4/locales/index.d.cts +63 -0
  645. package/v4/locales/index.d.ts +63 -0
  646. package/v4/locales/index.js +63 -0
  647. package/v4/locales/is.cjs +141 -0
  648. package/v4/locales/is.d.cts +5 -0
  649. package/v4/locales/is.d.ts +4 -0
  650. package/v4/locales/is.js +114 -0
  651. package/v4/locales/it.cjs +140 -0
  652. package/v4/locales/it.d.cts +5 -0
  653. package/v4/locales/it.d.ts +4 -0
  654. package/v4/locales/it.js +113 -0
  655. package/v4/locales/ja.cjs +139 -0
  656. package/v4/locales/ja.d.cts +5 -0
  657. package/v4/locales/ja.d.ts +4 -0
  658. package/v4/locales/ja.js +112 -0
  659. package/v4/locales/ka.cjs +144 -0
  660. package/v4/locales/ka.d.cts +5 -0
  661. package/v4/locales/ka.d.ts +4 -0
  662. package/v4/locales/ka.js +117 -0
  663. package/v4/locales/kh.cjs +12 -0
  664. package/v4/locales/kh.d.cts +5 -0
  665. package/v4/locales/kh.d.ts +5 -0
  666. package/v4/locales/kh.js +5 -0
  667. package/v4/locales/km.cjs +142 -0
  668. package/v4/locales/km.d.cts +5 -0
  669. package/v4/locales/km.d.ts +4 -0
  670. package/v4/locales/km.js +115 -0
  671. package/v4/locales/kn.cjs +143 -0
  672. package/v4/locales/kn.d.cts +5 -0
  673. package/v4/locales/kn.d.ts +4 -0
  674. package/v4/locales/kn.js +116 -0
  675. package/v4/locales/ko.cjs +143 -0
  676. package/v4/locales/ko.d.cts +5 -0
  677. package/v4/locales/ko.d.ts +4 -0
  678. package/v4/locales/ko.js +116 -0
  679. package/v4/locales/lt.cjs +251 -0
  680. package/v4/locales/lt.d.cts +5 -0
  681. package/v4/locales/lt.d.ts +4 -0
  682. package/v4/locales/lt.js +224 -0
  683. package/v4/locales/mk.cjs +141 -0
  684. package/v4/locales/mk.d.cts +5 -0
  685. package/v4/locales/mk.d.ts +4 -0
  686. package/v4/locales/mk.js +114 -0
  687. package/v4/locales/ms.cjs +139 -0
  688. package/v4/locales/ms.d.cts +5 -0
  689. package/v4/locales/ms.d.ts +4 -0
  690. package/v4/locales/ms.js +112 -0
  691. package/v4/locales/ne.cjs +138 -0
  692. package/v4/locales/ne.d.cts +5 -0
  693. package/v4/locales/ne.d.ts +4 -0
  694. package/v4/locales/ne.js +111 -0
  695. package/v4/locales/nl.cjs +142 -0
  696. package/v4/locales/nl.d.cts +5 -0
  697. package/v4/locales/nl.d.ts +4 -0
  698. package/v4/locales/nl.js +115 -0
  699. package/v4/locales/nn.cjs +140 -0
  700. package/v4/locales/nn.d.cts +5 -0
  701. package/v4/locales/nn.d.ts +4 -0
  702. package/v4/locales/nn.js +113 -0
  703. package/v4/locales/no.cjs +140 -0
  704. package/v4/locales/no.d.cts +5 -0
  705. package/v4/locales/no.d.ts +4 -0
  706. package/v4/locales/no.js +113 -0
  707. package/v4/locales/ota.cjs +141 -0
  708. package/v4/locales/ota.d.cts +5 -0
  709. package/v4/locales/ota.d.ts +4 -0
  710. package/v4/locales/ota.js +114 -0
  711. package/v4/locales/package.json +7 -0
  712. package/v4/locales/pl.cjs +141 -0
  713. package/v4/locales/pl.d.cts +5 -0
  714. package/v4/locales/pl.d.ts +4 -0
  715. package/v4/locales/pl.js +114 -0
  716. package/v4/locales/ps.cjs +146 -0
  717. package/v4/locales/ps.d.cts +5 -0
  718. package/v4/locales/ps.d.ts +4 -0
  719. package/v4/locales/ps.js +119 -0
  720. package/v4/locales/pt-BR.cjs +170 -0
  721. package/v4/locales/pt-BR.d.cts +5 -0
  722. package/v4/locales/pt-BR.d.ts +4 -0
  723. package/v4/locales/pt-BR.js +143 -0
  724. package/v4/locales/pt.cjs +169 -0
  725. package/v4/locales/pt.d.cts +5 -0
  726. package/v4/locales/pt.d.ts +4 -0
  727. package/v4/locales/pt.js +142 -0
  728. package/v4/locales/ro.cjs +149 -0
  729. package/v4/locales/ro.d.cts +5 -0
  730. package/v4/locales/ro.d.ts +4 -0
  731. package/v4/locales/ro.js +122 -0
  732. package/v4/locales/ru.cjs +195 -0
  733. package/v4/locales/ru.d.cts +5 -0
  734. package/v4/locales/ru.d.ts +4 -0
  735. package/v4/locales/ru.js +168 -0
  736. package/v4/locales/sk.cjs +143 -0
  737. package/v4/locales/sk.d.cts +5 -0
  738. package/v4/locales/sk.d.ts +4 -0
  739. package/v4/locales/sk.js +116 -0
  740. package/v4/locales/sl.cjs +141 -0
  741. package/v4/locales/sl.d.cts +5 -0
  742. package/v4/locales/sl.d.ts +4 -0
  743. package/v4/locales/sl.js +114 -0
  744. package/v4/locales/sv.cjs +142 -0
  745. package/v4/locales/sv.d.cts +5 -0
  746. package/v4/locales/sv.d.ts +4 -0
  747. package/v4/locales/sv.js +115 -0
  748. package/v4/locales/ta.cjs +142 -0
  749. package/v4/locales/ta.d.cts +5 -0
  750. package/v4/locales/ta.d.ts +4 -0
  751. package/v4/locales/ta.js +115 -0
  752. package/v4/locales/tg.cjs +144 -0
  753. package/v4/locales/tg.d.cts +5 -0
  754. package/v4/locales/tg.d.ts +4 -0
  755. package/v4/locales/tg.js +117 -0
  756. package/v4/locales/th.cjs +142 -0
  757. package/v4/locales/th.d.cts +5 -0
  758. package/v4/locales/th.d.ts +4 -0
  759. package/v4/locales/th.js +115 -0
  760. package/v4/locales/tk.cjs +134 -0
  761. package/v4/locales/tk.d.cts +5 -0
  762. package/v4/locales/tk.d.ts +4 -0
  763. package/v4/locales/tk.js +107 -0
  764. package/v4/locales/tr.cjs +137 -0
  765. package/v4/locales/tr.d.cts +5 -0
  766. package/v4/locales/tr.d.ts +4 -0
  767. package/v4/locales/tr.js +110 -0
  768. package/v4/locales/ua.cjs +12 -0
  769. package/v4/locales/ua.d.cts +5 -0
  770. package/v4/locales/ua.d.ts +5 -0
  771. package/v4/locales/ua.js +5 -0
  772. package/v4/locales/uk.cjs +140 -0
  773. package/v4/locales/uk.d.cts +5 -0
  774. package/v4/locales/uk.d.ts +4 -0
  775. package/v4/locales/uk.js +113 -0
  776. package/v4/locales/ur.cjs +142 -0
  777. package/v4/locales/ur.d.cts +5 -0
  778. package/v4/locales/ur.d.ts +4 -0
  779. package/v4/locales/ur.js +115 -0
  780. package/v4/locales/uz.cjs +140 -0
  781. package/v4/locales/uz.d.cts +5 -0
  782. package/v4/locales/uz.d.ts +4 -0
  783. package/v4/locales/uz.js +113 -0
  784. package/v4/locales/vi.cjs +140 -0
  785. package/v4/locales/vi.d.cts +5 -0
  786. package/v4/locales/vi.d.ts +4 -0
  787. package/v4/locales/vi.js +113 -0
  788. package/v4/locales/yo.cjs +139 -0
  789. package/v4/locales/yo.d.cts +5 -0
  790. package/v4/locales/yo.d.ts +4 -0
  791. package/v4/locales/yo.js +112 -0
  792. package/v4/locales/zh-CN.cjs +141 -0
  793. package/v4/locales/zh-CN.d.cts +5 -0
  794. package/v4/locales/zh-CN.d.ts +4 -0
  795. package/v4/locales/zh-CN.js +114 -0
  796. package/v4/locales/zh-TW.cjs +139 -0
  797. package/v4/locales/zh-TW.d.cts +5 -0
  798. package/v4/locales/zh-TW.d.ts +4 -0
  799. package/v4/locales/zh-TW.js +112 -0
  800. package/v4/mini/checks.cjs +54 -0
  801. package/v4/mini/checks.d.cts +1 -0
  802. package/v4/mini/checks.d.ts +1 -0
  803. package/v4/mini/checks.js +1 -0
  804. package/v4/mini/coerce.cjs +71 -0
  805. package/v4/mini/coerce.d.cts +7 -0
  806. package/v4/mini/coerce.d.ts +7 -0
  807. package/v4/mini/coerce.js +22 -0
  808. package/v4/mini/deep-partial.cjs +58 -0
  809. package/v4/mini/deep-partial.d.cts +14 -0
  810. package/v4/mini/deep-partial.d.ts +14 -0
  811. package/v4/mini/deep-partial.js +13 -0
  812. package/v4/mini/external.cjs +95 -0
  813. package/v4/mini/external.d.cts +16 -0
  814. package/v4/mini/external.d.ts +16 -0
  815. package/v4/mini/external.js +16 -0
  816. package/v4/mini/in-out.cjs +82 -0
  817. package/v4/mini/in-out.d.cts +8 -0
  818. package/v4/mini/in-out.d.ts +8 -0
  819. package/v4/mini/in-out.js +36 -0
  820. package/v4/mini/index.cjs +51 -0
  821. package/v4/mini/index.d.cts +3 -0
  822. package/v4/mini/index.d.ts +3 -0
  823. package/v4/mini/index.js +3 -0
  824. package/v4/mini/iso.cjs +83 -0
  825. package/v4/mini/iso.d.cts +22 -0
  826. package/v4/mini/iso.d.ts +22 -0
  827. package/v4/mini/iso.js +34 -0
  828. package/v4/mini/package.json +7 -0
  829. package/v4/mini/parse.cjs +37 -0
  830. package/v4/mini/parse.d.cts +1 -0
  831. package/v4/mini/parse.d.ts +1 -0
  832. package/v4/mini/parse.js +1 -0
  833. package/v4/mini/schemas.cjs +1147 -0
  834. package/v4/mini/schemas.d.cts +480 -0
  835. package/v4/mini/schemas.d.ts +480 -0
  836. package/v4/mini/schemas.js +1002 -0
  837. package/v4/package.json +7 -0
  838. package/v4-mini/index.cjs +51 -0
  839. package/v4-mini/index.d.cts +3 -0
  840. package/v4-mini/index.d.ts +3 -0
  841. package/v4-mini/index.js +3 -0
  842. package/v4-mini/package.json +7 -0
@@ -0,0 +1,1248 @@
1
+ import v8 from "node:v8";
2
+ import vm from "node:vm";
3
+ import { expect, test } from "vitest";
4
+ import * as z from "zod/v4";
5
+
6
+ test("parses a self-referential object and preserves identity", () => {
7
+ const Node: any = z.object({
8
+ id: z.number(),
9
+ get self() {
10
+ return Node;
11
+ },
12
+ });
13
+
14
+ const input: any = { id: 1 };
15
+ input.self = input;
16
+
17
+ const result = Node.parse(input);
18
+ expect(result.id).toBe(1);
19
+ expect(result.self).toBe(result);
20
+ expect(result).not.toBe(input);
21
+ });
22
+
23
+ test("validates a node against every schema that reaches it", () => {
24
+ const A: any = z.object({
25
+ x: z.string(),
26
+ get b() {
27
+ return B;
28
+ },
29
+ });
30
+ const B: any = z.object({
31
+ y: z.number(),
32
+ get a() {
33
+ return A;
34
+ },
35
+ });
36
+
37
+ const input: any = { x: "s", y: 1 };
38
+ input.b = input;
39
+ input.a = input;
40
+
41
+ const result = A.parse(input);
42
+ expect(Object.keys(result).sort()).toEqual(["b", "x"]);
43
+ expect(Object.keys(result.b).sort()).toEqual(["a", "y"]);
44
+ expect(result.b.y).toBe(1);
45
+ expect(result.b.a).toBe(result);
46
+
47
+ const bad: any = { x: "s", y: "not a number" };
48
+ bad.b = bad;
49
+ bad.a = bad;
50
+ expect(A.safeParse(bad).success).toBe(false);
51
+ });
52
+
53
+ test("breaks cycles through every container", () => {
54
+ const cases: [string, () => { schema: any; input: any }][] = [
55
+ [
56
+ "array",
57
+ () => {
58
+ const S: any = z.object({
59
+ id: z.number(),
60
+ get kids() {
61
+ return z.array(S);
62
+ },
63
+ });
64
+ const a: any = { id: 1, kids: [] };
65
+ a.kids.push(a);
66
+ return { schema: S, input: a };
67
+ },
68
+ ],
69
+ [
70
+ "record",
71
+ () => {
72
+ const S: any = z.object({
73
+ id: z.number(),
74
+ get kids() {
75
+ return z.record(z.string(), S);
76
+ },
77
+ });
78
+ const a: any = { id: 1, kids: {} };
79
+ a.kids.self = a;
80
+ return { schema: S, input: a };
81
+ },
82
+ ],
83
+ [
84
+ "tuple",
85
+ () => {
86
+ const S: any = z.object({
87
+ id: z.number(),
88
+ get pair() {
89
+ return z.tuple([z.number(), S]);
90
+ },
91
+ });
92
+ const a: any = { id: 1 };
93
+ a.pair = [1, a];
94
+ return { schema: S, input: a };
95
+ },
96
+ ],
97
+ [
98
+ "set",
99
+ () => {
100
+ const S: any = z.object({
101
+ id: z.number(),
102
+ get peers() {
103
+ return z.set(S);
104
+ },
105
+ });
106
+ const a: any = { id: 1, peers: new Set() };
107
+ a.peers.add(a);
108
+ return { schema: S, input: a };
109
+ },
110
+ ],
111
+ [
112
+ "map",
113
+ () => {
114
+ const S: any = z.object({
115
+ id: z.number(),
116
+ get links() {
117
+ return z.map(z.string(), S);
118
+ },
119
+ });
120
+ const a: any = { id: 1, links: new Map() };
121
+ a.links.set("s", a);
122
+ return { schema: S, input: a };
123
+ },
124
+ ],
125
+ [
126
+ "union",
127
+ () => {
128
+ const S: any = z.object({
129
+ id: z.number(),
130
+ get self() {
131
+ return z.union([z.string(), S]);
132
+ },
133
+ });
134
+ const a: any = { id: 1 };
135
+ a.self = a;
136
+ return { schema: S, input: a };
137
+ },
138
+ ],
139
+ [
140
+ "discriminated union",
141
+ () => {
142
+ const S: any = z.discriminatedUnion("kind", [
143
+ z.object({ kind: z.literal("leaf"), v: z.number() }),
144
+ z.object({
145
+ kind: z.literal("branch"),
146
+ get next() {
147
+ return S;
148
+ },
149
+ }),
150
+ ]);
151
+ const a: any = { kind: "branch" };
152
+ a.next = a;
153
+ return { schema: S, input: a };
154
+ },
155
+ ],
156
+ [
157
+ "lazy",
158
+ () => {
159
+ const S: any = z.object({ id: z.number(), self: z.lazy(() => S) });
160
+ const a: any = { id: 1 };
161
+ a.self = a;
162
+ return { schema: S, input: a };
163
+ },
164
+ ],
165
+ [
166
+ "mutual recursion five hops apart",
167
+ () => {
168
+ const A: any = z.object({
169
+ get b() {
170
+ return B;
171
+ },
172
+ });
173
+ const B: any = z.object({
174
+ get c() {
175
+ return C;
176
+ },
177
+ });
178
+ const C: any = z.object({
179
+ get d() {
180
+ return D;
181
+ },
182
+ });
183
+ const D: any = z.object({
184
+ get e() {
185
+ return E;
186
+ },
187
+ });
188
+ const E: any = z.object({
189
+ get a() {
190
+ return A;
191
+ },
192
+ });
193
+ const a: any = {};
194
+ a.b = { c: { d: { e: { a } } } };
195
+ return { schema: A, input: a };
196
+ },
197
+ ],
198
+ ];
199
+
200
+ for (const [name, build] of cases) {
201
+ for (const jitless of [false, true]) {
202
+ const { schema, input } = build();
203
+ expect(() => schema.parse(input, { jitless }), `${name} (jitless: ${jitless})`).not.toThrow();
204
+ }
205
+ }
206
+ });
207
+
208
+ test("checks run once per node and never against a half-built object", () => {
209
+ const seen: number[] = [];
210
+ const Node: any = z
211
+ .object({
212
+ id: z.number(),
213
+ get self() {
214
+ return Node;
215
+ },
216
+ })
217
+ .refine((value: any) => {
218
+ seen.push(Object.keys(value).length);
219
+ return true;
220
+ });
221
+
222
+ const input: any = { id: 1 };
223
+ input.self = input;
224
+ Node.parse(input);
225
+
226
+ expect(seen).toEqual([2]);
227
+ });
228
+
229
+ test("reports a failing check inside a cycle", () => {
230
+ const Node: any = z
231
+ .object({
232
+ id: z.number(),
233
+ get self() {
234
+ return Node;
235
+ },
236
+ })
237
+ .refine((value: any) => value.id > 100, "too small");
238
+
239
+ const input: any = { id: 1 };
240
+ input.self = input;
241
+ expect(Node.safeParse(input).success).toBe(false);
242
+ });
243
+
244
+ test("reports an invalid value inside a cycle once, at its own path", () => {
245
+ const Node: any = z.object({
246
+ id: z.number(),
247
+ get self() {
248
+ return Node;
249
+ },
250
+ });
251
+
252
+ const input: any = { id: "nope" };
253
+ input.self = input;
254
+
255
+ const result = Node.safeParse(input);
256
+ expect(result.success).toBe(false);
257
+ expect(result.error!.issues).toHaveLength(1);
258
+ expect(result.error!.issues[0].path).toEqual(["id"]);
259
+ });
260
+
261
+ test("rejects a cycle that closes through a transform", () => {
262
+ const Inner: any = z.object({
263
+ name: z.string(),
264
+ get self() {
265
+ return Wrapped;
266
+ },
267
+ });
268
+ const Wrapped: any = Inner.transform((value: any) => ({ wrapped: value }));
269
+
270
+ const input: any = { name: "x" };
271
+ input.self = input;
272
+
273
+ expect(() => Wrapped.parse(input)).toThrow(/reference cycle/);
274
+ });
275
+
276
+ test("leaves a transform that is not on the cycle alone", () => {
277
+ const Node: any = z.object({
278
+ n: z.number().transform((value: number) => value * 2),
279
+ get self() {
280
+ return Node;
281
+ },
282
+ });
283
+
284
+ const input: any = { n: 21 };
285
+ input.self = input;
286
+
287
+ const result = Node.parse(input);
288
+ expect(result.n).toBe(42);
289
+ expect(result.self).toBe(result);
290
+ });
291
+
292
+ test("encodes through a cycle", () => {
293
+ const Stringified = z.codec(z.string(), z.number(), {
294
+ decode: (value) => Number(value),
295
+ encode: (value) => String(value),
296
+ });
297
+ const Node: any = z.object({
298
+ n: Stringified,
299
+ get self() {
300
+ return Node;
301
+ },
302
+ });
303
+
304
+ const input: any = { n: 5 };
305
+ input.self = input;
306
+
307
+ const result: any = z.encode(Node, input);
308
+ expect(result.n).toBe("5");
309
+ expect(result.self).toBe(result);
310
+ });
311
+
312
+ test("an encode checks every node below a checked recursive container, as a decode does", async () => {
313
+ const Node: any = z
314
+ .object({
315
+ n: z.number().max(5),
316
+ get kids() {
317
+ return z.array(Node);
318
+ },
319
+ })
320
+ .refine((v: any) => v.n !== 3, "three");
321
+ const paths = (r: any) => r.error?.issues.map((iss: z.core.$ZodIssue) => iss.path);
322
+
323
+ const nested = { n: 1, kids: [{ n: 10, kids: [] }] };
324
+ expect(paths(z.safeEncode(Node, nested))).toEqual([["kids", 0, "n"]]);
325
+ expect(paths(z.safeDecode(Node, nested))).toEqual([["kids", 0, "n"]]);
326
+
327
+ const cyclic: any = { n: 1, kids: [] };
328
+ cyclic.kids.push({ n: 10, kids: [cyclic] });
329
+ expect(paths(z.safeEncode(Node, cyclic))).toEqual([["kids", 0, "n"]]);
330
+
331
+ // an encode runs a node's own check before parsing it, so the second visit must not repeat the first one's
332
+ const shared = { n: 3, kids: [{ n: 10, kids: [] }] };
333
+ const twice = { n: 1, kids: [shared, shared] };
334
+ const expected = [
335
+ ["kids", 0],
336
+ ["kids", 0, "kids", 0, "n"],
337
+ ["kids", 1],
338
+ ["kids", 1, "kids", 0, "n"],
339
+ ];
340
+ expect(paths(z.safeEncode(Node, twice))).toEqual(expected);
341
+ expect(paths(await z.safeEncodeAsync(Node, twice))).toEqual(expected);
342
+ });
343
+
344
+ test("keeps separate parses independent", () => {
345
+ const Node: any = z.object({
346
+ id: z.number(),
347
+ get self() {
348
+ return Node;
349
+ },
350
+ });
351
+
352
+ const input: any = { id: 1 };
353
+ input.self = input;
354
+
355
+ const first = Node.parse(input);
356
+ const second = Node.parse(input);
357
+ expect(first).not.toBe(second);
358
+ expect(first.self).toBe(first);
359
+ expect(second.self).toBe(second);
360
+
361
+ const bad: any = { id: "x" };
362
+ bad.self = bad;
363
+ expect(Node.safeParse(bad).success).toBe(false);
364
+ expect(Node.safeParse(input).success).toBe(true);
365
+ });
366
+
367
+ test("parses a cycle asynchronously", async () => {
368
+ const Node: any = z.object({
369
+ id: z.number().refine(async (value: number) => value > 0),
370
+ get self() {
371
+ return Node;
372
+ },
373
+ });
374
+
375
+ const input: any = { id: 1 };
376
+ input.self = input;
377
+
378
+ const result = await Node.parseAsync(input);
379
+ expect(result.self).toBe(result);
380
+
381
+ const bad: any = { id: -1 };
382
+ bad.self = bad;
383
+ expect((await Node.safeParseAsync(bad)).success).toBe(false);
384
+ });
385
+
386
+ const Slow: any = z.object({
387
+ id: z.number(),
388
+ slow: z.string().refine(async (s) => s === "ok"),
389
+ kids: z.array(z.lazy(() => Slow)),
390
+ });
391
+ const Either = (shape: any) => z.union([z.object(shape), z.object({ ...shape, extra: z.number().optional() })]);
392
+
393
+ test("a union option does not swallow the issues of a node its sibling is still parsing", async () => {
394
+ const U = Either({ child: Slow });
395
+
396
+ expect((await U.safeParseAsync({ child: { id: "nope", slow: "ok", kids: [] } })).success).toBe(false);
397
+ expect((await U.safeParseAsync({ child: { id: 1, slow: "x", kids: [] } })).success).toBe(false);
398
+ expect((await U.safeParseAsync({ child: { id: 1, slow: "ok", kids: [] } })).success).toBe(true);
399
+
400
+ const cyclic: any = { id: 1, slow: "ok", kids: [] };
401
+ cyclic.kids.push(cyclic);
402
+ const out: any = await U.parseAsync({ child: cyclic });
403
+ expect(out.child.kids[0]).toBe(out.child);
404
+ });
405
+
406
+ test("a .catch() that takes a shared node's issues leaves them for the other reference", async () => {
407
+ const Pair = z.object({ a: Slow.catch({ id: 0, slow: "ok", kids: [] }), b: Slow });
408
+ const x = { id: "nope", slow: "ok", kids: [] };
409
+ const r = await Pair.safeParseAsync({ a: x, b: x });
410
+ expect(r.error?.issues.map((iss) => iss.path)).toEqual([["b", "id"]]);
411
+ });
412
+
413
+ test("a concurrent reference reports issues and runs checks and transforms as a sync parse does", async () => {
414
+ const build = (slow: any) => {
415
+ const Node: any = z
416
+ .object({
417
+ id: z.number(),
418
+ slow,
419
+ kids: z.array(z.lazy(() => Node)),
420
+ })
421
+ .refine((n: any) => n.id !== 0, { path: ["refined"] });
422
+ return z.object({ a: Node, b: Node, c: Node.transform((n: any) => n.id) });
423
+ };
424
+ const paths = (r: any) => r.error.issues.map((iss: any) => iss.path);
425
+ const bad = { id: 0, slow: "ok", kids: [{ id: "nope", slow: "ok", kids: [] }] };
426
+ const input = { a: bad, b: bad, c: bad };
427
+
428
+ const sync = build(z.string()).safeParse(input);
429
+ const asynced = await build(z.string().refine(async () => true)).safeParseAsync(input);
430
+ expect(paths(asynced)).toEqual(paths(sync));
431
+ expect(paths(asynced)).toContainEqual(["b", "kids", 0, "id"]);
432
+
433
+ const good = { id: 1, slow: "ok", kids: [] };
434
+ const out: any = await build(z.string().refine(async () => true)).parseAsync({ a: good, b: good, c: good });
435
+ expect(out.a).toBe(out.b);
436
+ expect(out.c).toBe(1);
437
+ });
438
+
439
+ // every edge is reached only after an await, so nothing about the call stack marks a cycle
440
+ const AfterAwait: any = z.object({
441
+ id: z.number(),
442
+ next: z.preprocess(async (v) => v, z.array(z.lazy(() => AfterAwait))),
443
+ });
444
+ const graph = (edges: number[][]) => {
445
+ const nodes: any[] = edges.map((_, id) => ({ id }));
446
+ for (const [i, to] of edges.entries()) nodes[i].next = to.map((j) => nodes[j]);
447
+ return nodes;
448
+ };
449
+
450
+ test("a cycle that closes after an await is a back-edge, not a wait", async () => {
451
+ const [x] = graph([[0]]);
452
+ const out: any = await AfterAwait.parseAsync(x);
453
+ expect(out.next[0]).toBe(out);
454
+
455
+ // the sibling option has to wait while the ancestor must not
456
+ x.id = "nope";
457
+ expect((await Either({ child: AfterAwait }).safeParseAsync({ child: x })).success).toBe(false);
458
+ });
459
+
460
+ test.each([
461
+ ["each waits on the other", [[1], [0]]],
462
+ ["around a ring", [[1], [2], [0]]],
463
+ ["a node waited on twice, the first closing the loop", [[2], [2], [0]]],
464
+ ["a node waiting twice, the first closing the loop", [[1, 2], [0], []]],
465
+ ])("visits that would wait on each other resolve: %s", async (_, edges) => {
466
+ const out: any = await z.array(AfterAwait).parseAsync(graph(edges));
467
+ for (const [i, to] of edges.entries()) for (const [k, j] of to.entries()) expect(out[i].next[k]).toBe(out[j]);
468
+
469
+ const bad = graph(edges);
470
+ bad[0].id = "nope";
471
+ expect((await Either({ all: z.array(AfterAwait) }).safeParseAsync({ all: bad })).success).toBe(false);
472
+ });
473
+
474
+ test("repeat references to a node a visit already waits on don't re-walk what waits above it", async () => {
475
+ const n = 500;
476
+ const y = { id: 0, next: [] };
477
+ const x = { id: 1, next: Array(n).fill(y) };
478
+ const wrappers = Array.from({ length: n }, () => ({ id: 2, next: [x] }));
479
+
480
+ // counts Set.add, which the wait-cycle walk calls per visit; re-walking per reference reaches ~n²
481
+ let added = 0;
482
+ const { add } = Set.prototype;
483
+ Set.prototype.add = function (this: Set<unknown>, value: unknown) {
484
+ added++;
485
+ return add.call(this, value);
486
+ };
487
+ try {
488
+ expect((await z.array(AfterAwait).safeParseAsync([y, ...wrappers, x])).success).toBe(true);
489
+ } finally {
490
+ Set.prototype.add = add;
491
+ }
492
+ expect(added).toBeLessThan(n * 40);
493
+ });
494
+
495
+ test("an async encode does not swallow the issues of a shared node", async () => {
496
+ const Codec = z.codec(z.string(), z.string(), { decode: async (s) => s, encode: async (s) => s });
497
+ const Node: any = z.object({ id: z.number(), slow: Codec, kids: z.array(z.lazy(() => Node)) });
498
+ const U = Either({ child: Node });
499
+
500
+ expect((await z.safeEncodeAsync(U, { child: { id: "nope", slow: "x", kids: [] } } as any)).success).toBe(false);
501
+ expect((await z.safeEncodeAsync(U, { child: { id: 1, slow: "x", kids: [] } } as any)).success).toBe(true);
502
+
503
+ const cyclic: any = { id: 1, slow: "x", kids: [] };
504
+ cyclic.kids.push(cyclic);
505
+ const out: any = await z.encodeAsync(U, { child: cyclic } as any);
506
+ expect(out.child.kids[0]).toBe(out.child);
507
+ });
508
+
509
+ test("a non-recursive schema still copies a shared reference twice", () => {
510
+ const Leaf = z.object({ v: z.number() });
511
+ const Pair = z.object({ a: Leaf, b: Leaf });
512
+
513
+ const shared = { v: 1 };
514
+ const result = Pair.parse({ a: shared, b: shared });
515
+
516
+ expect(result.a).not.toBe(result.b);
517
+ expect(result.a.v).toBe(1);
518
+ expect(result.b.v).toBe(1);
519
+ });
520
+
521
+ test("a recursive schema shares one output node per input node", () => {
522
+ const Node: any = z.object({
523
+ v: z.number(),
524
+ get kids() {
525
+ return z.array(Node);
526
+ },
527
+ });
528
+
529
+ const shared: any = { v: 1, kids: [] };
530
+ const result = Node.parse({ v: 0, kids: [shared, shared] });
531
+
532
+ expect(result.kids[0]).toBe(result.kids[1]);
533
+ });
534
+
535
+ test("sync and async agree on a shared reference", async () => {
536
+ const build = (asyncCheck: boolean) => {
537
+ const Node: any = z.object({
538
+ v: asyncCheck ? z.number().refine(async (n: number) => n >= 0) : z.number(),
539
+ get kids() {
540
+ return z.array(Node);
541
+ },
542
+ });
543
+ return Node;
544
+ };
545
+
546
+ const shared: any = { v: 1, kids: [] };
547
+ const input = { v: 0, kids: [shared, shared] };
548
+
549
+ const syncResult = build(false).parse(input);
550
+ const asyncResult = await build(true).parseAsync(input);
551
+
552
+ expect(syncResult.kids[0]).toBe(syncResult.kids[1]);
553
+ expect(asyncResult.kids[0]).toBe(asyncResult.kids[1]);
554
+ });
555
+
556
+ test("a cycle through .readonly() keeps the node intact", () => {
557
+ const Node: any = z.object({
558
+ id: z.number(),
559
+ get self() {
560
+ return Node.readonly();
561
+ },
562
+ });
563
+
564
+ const input: any = { id: 1 };
565
+ input.self = input;
566
+
567
+ // Freezing a node that is still being built would make its remaining keys fail to assign, silently, because generated code is not strict mode.
568
+ const result = Node.parse(input);
569
+ expect(Object.keys(result).sort()).toEqual(["id", "self"]);
570
+ expect(result.self).toBe(result);
571
+ });
572
+
573
+ test("a cycle through z.intersection validates but does not mirror the graph", () => {
574
+ const Node: any = z.object({
575
+ id: z.number(),
576
+ get self() {
577
+ return z.intersection(Node, z.object({ id: z.number() }));
578
+ },
579
+ });
580
+
581
+ const input: any = { id: 7 };
582
+ input.self = input;
583
+
584
+ // The merged value is built after both sides are parsed, so it cannot be the object a back-edge already resolved to. Values are right, the graph is not.
585
+ const result = Node.parse(input);
586
+ expect(result.id).toBe(7);
587
+ expect(result.self.id).toBe(7);
588
+ expect(result.self).not.toBe(result);
589
+ expect(result.self.self).toBeUndefined();
590
+
591
+ const bad: any = { id: "nope" };
592
+ bad.self = bad;
593
+ expect(Node.safeParse(bad).success).toBe(false);
594
+ });
595
+
596
+ test("keeps two cycles and a shared node distinct in one input", () => {
597
+ const Node: any = z.object({
598
+ id: z.number(),
599
+ get kids() {
600
+ return z.array(Node);
601
+ },
602
+ });
603
+
604
+ const shared: any = { id: 9, kids: [] };
605
+ const root: any = { id: 0, kids: [shared, shared] };
606
+ root.kids.push(root);
607
+
608
+ const result = Node.parse(root);
609
+ expect(result.kids[0]).toBe(result.kids[1]);
610
+ expect(result.kids[2]).toBe(result);
611
+ });
612
+
613
+ test("closes a cycle through a Map key and a Set member", () => {
614
+ const Keyed: any = z.object({
615
+ id: z.number(),
616
+ get keyed() {
617
+ return z.map(Keyed, z.string());
618
+ },
619
+ });
620
+ const k: any = { id: 1, keyed: new Map() };
621
+ k.keyed.set(k, "v");
622
+ const keyedOut = Keyed.parse(k);
623
+ expect([...keyedOut.keyed.keys()][0]).toBe(keyedOut);
624
+
625
+ const Peered: any = z.object({
626
+ id: z.number(),
627
+ get peers() {
628
+ return z.set(Peered);
629
+ },
630
+ });
631
+ const p: any = { id: 1, peers: new Set() };
632
+ p.peers.add(p);
633
+ const peeredOut = Peered.parse(p);
634
+ expect([...peeredOut.peers][0]).toBe(peeredOut);
635
+ });
636
+
637
+ test("does not mutate the input, and tolerates a frozen one", () => {
638
+ const Node: any = z.object({
639
+ id: z.number(),
640
+ get self() {
641
+ return Node;
642
+ },
643
+ });
644
+
645
+ const input: any = { id: 1 };
646
+ input.self = input;
647
+ Object.freeze(input);
648
+
649
+ const result = Node.parse(input);
650
+ expect(result).not.toBe(input);
651
+ expect(result.self).toBe(result);
652
+ expect(Reflect.ownKeys(input)).toEqual(["id", "self"]);
653
+ });
654
+
655
+ test("keys identity on the schema, not just the input", () => {
656
+ const Node: any = z.object({
657
+ id: z.number(),
658
+ get self() {
659
+ return Node.optional();
660
+ },
661
+ });
662
+ const Partial: any = Node.partial();
663
+
664
+ const input: any = { id: 1 };
665
+ input.self = input;
666
+
667
+ // `Partial` and `Node` are different schemas, so the root and the node its cycle points back to are different output objects. Same rule that lets one input node be validated against two schemas in mutual recursion.
668
+ const result = Partial.parse(input);
669
+ expect(result.self).not.toBe(result);
670
+ expect(result.self.self).toBe(result.self);
671
+ expect(result.id).toBe(1);
672
+ expect(result.self.id).toBe(1);
673
+ });
674
+
675
+ test("keeps concurrent async parses of one schema independent", async () => {
676
+ const Node: any = z.object({
677
+ id: z.number().refine(async (n: number) => {
678
+ await new Promise((r) => setTimeout(r, 5 + (n % 3)));
679
+ return true;
680
+ }),
681
+ get self() {
682
+ return Node;
683
+ },
684
+ });
685
+
686
+ const make = (id: number) => {
687
+ const o: any = { id };
688
+ o.self = o;
689
+ return o;
690
+ };
691
+
692
+ const [a, b, c] = await Promise.all([Node.parseAsync(make(1)), Node.parseAsync(make(2)), Node.parseAsync(make(3))]);
693
+
694
+ expect([a.id, b.id, c.id]).toEqual([1, 2, 3]);
695
+ expect(a.self).toBe(a);
696
+ expect(b.self).toBe(b);
697
+ expect(c.self).toBe(c);
698
+ });
699
+
700
+ test("runs checks once per reference, as it does without a cycle", () => {
701
+ let calls = 0;
702
+ const Node: any = z
703
+ .object({
704
+ id: z.number(),
705
+ get kids() {
706
+ return z.array(Node);
707
+ },
708
+ })
709
+ .refine(() => {
710
+ calls++;
711
+ return true;
712
+ });
713
+
714
+ const shared: any = { id: 1, kids: [] };
715
+ Node.parse({ id: 0, kids: [shared, shared] });
716
+
717
+ // Memoization skips the container's parse, not the checks layered on it.
718
+ expect(calls).toBe(3);
719
+ });
720
+
721
+ test("a schema wrapped at the root adds one node and no more", () => {
722
+ const Node: any = z.object({
723
+ id: z.number(),
724
+ get self() {
725
+ return Node.optional();
726
+ },
727
+ });
728
+
729
+ const input: any = { id: 1 };
730
+ input.self = input;
731
+
732
+ // The root is keyed on the wrapper, everything under it on `Node`, so the graph closes one level down rather than at the root. It does not compound: stacking wrappers still yields exactly two nodes.
733
+ const count = (root: any) => {
734
+ const seen: any[] = [];
735
+ let n = root;
736
+ while (n && !seen.includes(n)) {
737
+ seen.push(n);
738
+ n = n.self;
739
+ }
740
+ return seen.length;
741
+ };
742
+
743
+ expect(count(Node.parse(input))).toBe(1);
744
+ expect(count(Node.partial().parse(input))).toBe(2);
745
+ expect(count(Node.partial().partial().parse(input))).toBe(2);
746
+ expect(count(Node.extend({ extra: z.string().optional() }).parse(input))).toBe(2);
747
+ });
748
+
749
+ test("resolves a recursive reference once, however it is written", () => {
750
+ // This is what bounds the above: core caches a shape getter and a lazy getter, so a getter returning a fresh clone still yields a finite schema graph rather than a new schema per node.
751
+ let getterCalls = 0;
752
+ const ViaGetter: any = z.object({
753
+ id: z.number(),
754
+ get self() {
755
+ getterCalls++;
756
+ return ViaGetter.partial();
757
+ },
758
+ });
759
+
760
+ let lazyCalls = 0;
761
+ const ViaLazy: any = z.object({
762
+ id: z.number(),
763
+ self: z.lazy(() => {
764
+ lazyCalls++;
765
+ return ViaLazy.partial();
766
+ }),
767
+ });
768
+
769
+ const input: any = { id: 1 };
770
+ input.self = input;
771
+
772
+ expect(() => ViaGetter.parse(input)).not.toThrow();
773
+ expect(() => ViaLazy.parse(input)).not.toThrow();
774
+ expect(getterCalls).toBe(1);
775
+ expect(lazyCalls).toBe(1);
776
+ });
777
+
778
+ // The second visitor of a shared node must not prefix onto the first visitor's path.
779
+ test.each([false, true])("prefixes a shared node's issues once per reference (jitless: %s)", (jitless) => {
780
+ z.config({ jitless });
781
+ try {
782
+ const Node: any = z.object({
783
+ name: z.string(),
784
+ get left() {
785
+ return z.optional(Node);
786
+ },
787
+ get right() {
788
+ return z.optional(Node);
789
+ },
790
+ });
791
+
792
+ const shared: any = { name: 123 };
793
+ const result = Node.safeParse({ name: "root", left: shared, right: shared });
794
+
795
+ expect(result.success).toBe(false);
796
+ expect(result.error.issues.map((iss: any) => iss.path)).toEqual([
797
+ ["left", "name"],
798
+ ["right", "name"],
799
+ ]);
800
+ } finally {
801
+ z.config({ jitless: false });
802
+ }
803
+ });
804
+
805
+ test("the default memoizer is installed before the first container reads it", () => {
806
+ // the delete manufactures the fresh-process state; a container with only getter keys then constructs no leaf before the config read
807
+ delete z.config().memoizer;
808
+ const Node: any = z.object({
809
+ get self() {
810
+ return Node;
811
+ },
812
+ });
813
+ const input: any = {};
814
+ input.self = input;
815
+ const out = Node.parse(input);
816
+ expect(out.self).toBe(out);
817
+ });
818
+
819
+ test("guards a transform built before any container", () => {
820
+ // the guard attaches at construction, so a transform predating the first container must still get the default
821
+ delete z.config().memoizer;
822
+ const wrap = z.transform((value: any) => ({ wrapped: value }));
823
+ const Inner: any = z.object({
824
+ name: z.string(),
825
+ get self() {
826
+ return Wrapped;
827
+ },
828
+ });
829
+ const Wrapped: any = z.pipe(Inner, wrap);
830
+
831
+ const input: any = { name: "x" };
832
+ input.self = input;
833
+
834
+ expect(() => Wrapped.parse(input)).toThrow(/reference cycle/);
835
+ });
836
+
837
+ test("detects a cycle reachable only through a merged catchall", () => {
838
+ const Cyclic: any = z.object({
839
+ id: z.string(),
840
+ get next() {
841
+ return z.optional(Root);
842
+ },
843
+ });
844
+ const Root: any = z.object({ tag: z.string() }).merge(z.object({}).catchall(Cyclic));
845
+
846
+ const input: any = { tag: "root" };
847
+ input.child = { id: "1", next: input };
848
+
849
+ const out: any = Root.parse(input);
850
+ expect(out.child.next).toBe(out);
851
+ });
852
+
853
+ // the per-type switch can only enumerate kinds Zod ships, so an unknown `def.type` falls back to scanning the def; without it a cycle through a third-party container overflows the stack
854
+ test("detects a cycle through a user-defined container type", () => {
855
+ const MyBox: any = z.core.$constructor("MyBox", (inst: any, def: any) => {
856
+ z.core.$ZodType.init(inst, def);
857
+ inst._zod.parse = (payload: any, ctx: any) => {
858
+ if (payload.value === null || typeof payload.value !== "object") return payload;
859
+ const inner = def.inner._zod.run({ value: payload.value.v, issues: [] }, ctx);
860
+ payload.value = { v: inner.value };
861
+ return payload;
862
+ };
863
+ });
864
+
865
+ const Node: any = z.object({
866
+ id: z.string(),
867
+ get boxed() {
868
+ return z.optional(new MyBox({ type: "mybox", inner: z.lazy(() => Node) }));
869
+ },
870
+ });
871
+
872
+ const input: any = { id: "1" };
873
+ input.boxed = { v: input };
874
+
875
+ const out: any = Node.parse(input);
876
+ expect(out.boxed.v).toBe(out);
877
+ });
878
+
879
+ // #6526: a factory returns fresh instances, so the identity walk never revisits a node; it descends until the stack overflows unless it stops at the deferred edge
880
+ test("parses a factory-built recursive schema", () => {
881
+ const Node = (): any =>
882
+ z.object({
883
+ id: z.number(),
884
+ get kids() {
885
+ return z.array(Node());
886
+ },
887
+ });
888
+
889
+ const S = z.object({ root: Node() });
890
+ const out = S.parse({ root: { id: 1, kids: [{ id: 2, kids: [] }] } });
891
+ expect(out.root.kids[0].id).toBe(2);
892
+ expect(S.safeParse({ root: { id: 1, kids: [{ id: "x", kids: [] }] } }).success).toBe(false);
893
+ });
894
+
895
+ test("parses a factory-built recursive discriminated union at the root and nested", () => {
896
+ const Geometry = (): any =>
897
+ z.discriminatedUnion("type", [
898
+ z.object({ type: z.literal("Point"), coordinates: z.array(z.number()) }),
899
+ z.looseObject({
900
+ type: z.literal("GeometryCollection"),
901
+ get geometries() {
902
+ return z.array(Geometry());
903
+ },
904
+ }),
905
+ ]);
906
+
907
+ const collection = { type: "GeometryCollection", geometries: [{ type: "Point", coordinates: [1, 2] }] };
908
+ expect(Geometry().parse(collection).geometries[0].coordinates).toEqual([1, 2]);
909
+ expect(z.object({ g: Geometry() }).parse({ g: collection }).g.type).toBe("GeometryCollection");
910
+ });
911
+
912
+ test("the walk reports a cycle for a deferred edge instead of resolving it", () => {
913
+ const Node = (): any =>
914
+ z.object({
915
+ get self() {
916
+ return Node();
917
+ },
918
+ });
919
+ expect(z.core.isRecursiveSchema(Node())).toBe(true);
920
+
921
+ // conservative by design: a getter that closes no cycle is reported too, and pays only the memoizer it keeps
922
+ const Leaf = z.object({ id: z.string() });
923
+ const forward: any = z.object({
924
+ get leaf() {
925
+ return Leaf;
926
+ },
927
+ });
928
+ expect(z.core.isRecursiveSchema(forward)).toBe(true);
929
+
930
+ // a lazy is followed one hop, which is what lets z.compile see past it; past that hop it is deferred like any other edge
931
+ expect(z.core.isRecursiveSchema(z.lazy(() => Leaf) as any)).toBe(false);
932
+ expect(z.core.isRecursiveSchema(z.lazy(() => z.lazy(() => Leaf)) as any)).toBe(true);
933
+ });
934
+
935
+ // the builders answer `shape` from an accessor that resolves the source's getters, so the walk has to reach the source schema itself
936
+ test("parses a factory-built recursive schema through every object builder", () => {
937
+ const wraps: [string, (base: () => any) => any][] = [
938
+ ["extend", (b) => b().extend({ x: z.string() })],
939
+ ["safeExtend", (b) => b().safeExtend({ x: z.string() })],
940
+ ["merge", (b) => z.object({ x: z.string() }).merge(b())],
941
+ ["partial", (b) => b().partial()],
942
+ ["required", (b) => b().required()],
943
+ ["pick", (b) => b().pick({ self: true })],
944
+ ["omit", (b) => b().omit({ y: true })],
945
+ ["chained", (b) => b().extend({ x: z.string() }).partial()],
946
+ // rebuilds the def without touching the shape, so the clone carries the source's accessor rather than a shape of its own
947
+ ["strict", (b) => b().extend({ x: z.string() }).strict()],
948
+ ["catchall", (b) => b().extend({ x: z.string() }).catchall(z.unknown())],
949
+ ["meta", (b) => b().extend({ x: z.string() }).meta({ id: "node" })],
950
+ ];
951
+
952
+ for (const [name, wrap] of wraps) {
953
+ const Node = (): any =>
954
+ wrap(() =>
955
+ z.object({
956
+ y: z.string(),
957
+ get self() {
958
+ return z.optional(Node());
959
+ },
960
+ })
961
+ );
962
+ const S = z.object({ r: Node() });
963
+ for (const attempt of ["first", "second"]) {
964
+ expect(() => S.safeParse({ r: { y: "s", x: "s" } }), `${name} (${attempt} parse)`).not.toThrow();
965
+ }
966
+ }
967
+ });
968
+
969
+ test("an ordinary builder stays exact, so it still compiles", () => {
970
+ const plain = z.object({ a: z.string(), b: z.number() });
971
+ const derived: [string, any][] = [
972
+ ["extend", plain.extend({ c: z.boolean() })],
973
+ ["merge", plain.merge(z.object({ d: z.string() }))],
974
+ ["partial", plain.partial()],
975
+ ["required", plain.partial().required()],
976
+ ["pick", plain.pick({ a: true })],
977
+ ["omit", plain.omit({ a: true })],
978
+ ["strict", plain.extend({ c: z.boolean() }).strict()],
979
+ ["catchall", plain.extend({ c: z.boolean() }).catchall(z.unknown())],
980
+ ["meta", plain.extend({ c: z.boolean() }).meta({ id: "plain" })],
981
+ ];
982
+ for (const [name, schema] of derived) {
983
+ expect(z.core.isRecursiveSchema(schema), name).toBe(false);
984
+ expect(() => z.compile(schema, { strict: true }), name).not.toThrow();
985
+ }
986
+ });
987
+
988
+ // a derived shape mirrors its source's descriptors, so dropping or overwriting the key that carries the cycle leaves nothing deferred and the walk is exact before anything parses
989
+ test("a builder that drops the recursive key ends up exact", () => {
990
+ const Node: any = z.object({
991
+ id: z.number(),
992
+ get self() {
993
+ return z.optional(Node);
994
+ },
995
+ });
996
+
997
+ const derived: [string, any, any][] = [
998
+ ["omit", Node.omit({ self: true }), { id: 1 }],
999
+ ["pick", Node.pick({ id: true }), { id: 1 }],
1000
+ ["extend overwrites it", Node.extend({ self: z.string() }), { id: 1, self: "x" }],
1001
+ ];
1002
+ for (const [name, schema, input] of derived) {
1003
+ expect(z.core.isRecursiveSchema(schema), name).toBe(false);
1004
+ expect(() => z.compile(schema, { strict: true }), name).not.toThrow();
1005
+ expect(schema.parse(input), name).toEqual(input);
1006
+ }
1007
+
1008
+ // the branch that stays is still found
1009
+ const kept = Node.extend({ x: z.string() });
1010
+ expect(z.core.isRecursiveSchema(kept)).toBe(true);
1011
+ });
1012
+
1013
+ // resolving a lazy runs user code, which can re-enter the walk; a walk that kept its certainty outside its own frames would have the inner one clobber the outer
1014
+ test("a nested walk can't corrupt the one that resolved into it", () => {
1015
+ const Node: any = z.object({
1016
+ id: z.number(),
1017
+ self: z.lazy(() => {
1018
+ z.compile(z.string(), { strict: true });
1019
+ return z.optional(Node);
1020
+ }),
1021
+ });
1022
+
1023
+ const omitted = Node.omit({ self: true });
1024
+ // exact before anything parses: the mirrored shape kept only `id`, so nothing here is deferred
1025
+ expect(z.core.isRecursiveSchema(omitted)).toBe(false);
1026
+ omitted.parse({ id: 1 });
1027
+ expect(z.core.isRecursiveSchema(omitted)).toBe(false);
1028
+ expect(() => z.compile(omitted, { strict: true })).not.toThrow();
1029
+
1030
+ const shared = { id: 1 };
1031
+ const out: any = z.object({ a: omitted, b: omitted }).parse({ a: shared, b: shared });
1032
+ expect(out.a).not.toBe(out.b);
1033
+ expect(z.core.isRecursiveSchema(Node)).toBe(true);
1034
+ });
1035
+
1036
+ test("detects a cycle that closes through a builder", () => {
1037
+ const Node: any = z
1038
+ .object({
1039
+ id: z.number(),
1040
+ get self() {
1041
+ return z.optional(Node);
1042
+ },
1043
+ })
1044
+ .extend({ x: z.string() });
1045
+
1046
+ const input: any = { id: 1, x: "s" };
1047
+ input.self = input;
1048
+ const out = Node.parse(input);
1049
+ expect(out.self).toBe(out);
1050
+ });
1051
+
1052
+ test("a deferred edge stops being assumed a cycle once the graph resolves", () => {
1053
+ const Leaf = z.object({ n: z.number() });
1054
+ const Forward: any = z.object({
1055
+ get a() {
1056
+ return Leaf;
1057
+ },
1058
+ });
1059
+ expect(z.core.isRecursiveSchema(Forward)).toBe(true);
1060
+ Forward.parse({ a: { n: 1 } });
1061
+ // the parse resolved the getter, so the walk can follow it and drop the assumption
1062
+ expect(z.core.isRecursiveSchema(Forward)).toBe(false);
1063
+
1064
+ // a factory hands back a fresh subtree every time, so no parse ever resolves it into a finite graph
1065
+ const Node = (): any =>
1066
+ z.object({
1067
+ get kids() {
1068
+ return z.array(Node());
1069
+ },
1070
+ });
1071
+ const Generated = Node();
1072
+ expect(z.core.isRecursiveSchema(Generated)).toBe(true);
1073
+ Generated.parse({ kids: [] });
1074
+ expect(z.core.isRecursiveSchema(Generated)).toBe(true);
1075
+
1076
+ // a lazy that closes a real cycle stays recursive however often it resolves
1077
+ const Cyclic: any = z.object({ id: z.number(), self: z.lazy(() => z.optional(Cyclic)) });
1078
+ Cyclic.parse({ id: 1 });
1079
+ expect(z.core.isRecursiveSchema(Cyclic)).toBe(true);
1080
+ });
1081
+
1082
+ // `z.object` resolves its shape by spread, so a non-enumerable key is no part of it
1083
+ test("a non-enumerable key does not count for z.object", () => {
1084
+ const object = (enumerable: boolean) => {
1085
+ const shape: Record<string, any> = { id: z.number() };
1086
+ const O: any = z.object(shape);
1087
+ Object.defineProperty(shape, "next", { value: z.lazy(() => z.optional(O)), enumerable, configurable: true });
1088
+ return O;
1089
+ };
1090
+ expect(z.core.isRecursiveSchema(object(true))).toBe(true);
1091
+ // the spread drops it, so nothing can ever parse it
1092
+ expect(z.core.isRecursiveSchema(object(false))).toBe(false);
1093
+ });
1094
+
1095
+ test("the walk stays exact where nothing is deferred", () => {
1096
+ let deep: any = z.string();
1097
+ for (let i = 0; i < 300; i++) deep = z.object({ v: deep });
1098
+ expect(z.core.isRecursiveSchema(deep)).toBe(false);
1099
+ });
1100
+
1101
+ test("parses a factory-built recursive schema through z.lazy", () => {
1102
+ const Node = (): any =>
1103
+ z.object({
1104
+ id: z.number(),
1105
+ child: z.lazy(() => z.optional(Node())),
1106
+ });
1107
+
1108
+ const out = z.object({ root: Node() }).parse({ root: { id: 1, child: { id: 2, child: undefined } } });
1109
+ expect(out.root.child.id).toBe(2);
1110
+ });
1111
+
1112
+ test.each([
1113
+ ["parse", z.number()],
1114
+ ["parseAsync", z.number().refine(async () => true)],
1115
+ ])("a finished %s pins nothing on the schema", async (method, id) => {
1116
+ // es2020 is the target, and its lib predates WeakRef
1117
+ type Weak<T extends object> = { deref(): T | undefined };
1118
+ const { WeakRef: Weak } = globalThis as unknown as { WeakRef: new <T extends object>(target: T) => Weak<T> };
1119
+ // vitest carries no --expose-gc, so reach the collector the way node's own tests do
1120
+ v8.setFlagsFromString("--expose-gc");
1121
+ const gc = vm.runInNewContext("gc") as () => void;
1122
+
1123
+ const Node: any = z.object({
1124
+ id,
1125
+ get next() {
1126
+ return z.optional(Node);
1127
+ },
1128
+ });
1129
+
1130
+ const refs = await (async (): Promise<Weak<object>[]> => {
1131
+ const input = { id: 1, next: { id: 2, next: undefined } };
1132
+ return [new Weak(input), new Weak(await Node[method](input))];
1133
+ })();
1134
+
1135
+ for (let attempt = 0; attempt < 10 && refs.some((ref) => ref.deref()); attempt++) {
1136
+ // the input stays on the stack until a macrotask boundary
1137
+ await new Promise((resolve) => setTimeout(resolve, 0));
1138
+ gc();
1139
+ }
1140
+
1141
+ expect(refs.map((ref) => ref.deref())).toEqual([undefined, undefined]);
1142
+ });
1143
+
1144
+ test("a repeat visit reports the first visit's issues at its own path", async () => {
1145
+ const Node: any = z.object({
1146
+ v: z.number(),
1147
+ get kids() {
1148
+ return z.array(Node);
1149
+ },
1150
+ });
1151
+ const leaf = { v: "y", kids: [] };
1152
+ const shared = { v: "x", kids: [leaf, leaf] };
1153
+ const cyclic: any = { v: "z", kids: [] };
1154
+ cyclic.kids.push(cyclic);
1155
+ const input = { v: 0, kids: [shared, shared, cyclic, cyclic] };
1156
+
1157
+ const paths = [
1158
+ ["kids", 0, "v"],
1159
+ ["kids", 0, "kids", 0, "v"],
1160
+ ["kids", 0, "kids", 1, "v"],
1161
+ ["kids", 1, "v"],
1162
+ ["kids", 1, "kids", 0, "v"],
1163
+ ["kids", 1, "kids", 1, "v"],
1164
+ ["kids", 2, "v"],
1165
+ ["kids", 3, "v"],
1166
+ ];
1167
+ for (const r of [Node.safeParse(input), Node.safeParse(input, { jitless: true }), await Node.safeParseAsync(input)]) {
1168
+ expect(r.error!.issues.map((iss: z.core.$ZodIssue) => iss.path)).toEqual(paths);
1169
+ }
1170
+ });
1171
+
1172
+ test("union options that re-run one child report its issues as the first run did", () => {
1173
+ const U: any = z.union([
1174
+ z.object({
1175
+ kind: z.literal("a"),
1176
+ x: z.string().refine((s) => s.length > 1, "short"),
1177
+ get child() {
1178
+ return U.optional();
1179
+ },
1180
+ }),
1181
+ z.object({
1182
+ kind: z.literal("b"),
1183
+ y: z.number(),
1184
+ get child() {
1185
+ return U.optional();
1186
+ },
1187
+ }),
1188
+ ]);
1189
+ // only the second option matches, so the child's issues it forwards are the repeat ones
1190
+ expect(U.safeParse({ kind: "b", y: 1, child: { kind: "a", x: "z" } }).error!.issues).toEqual([
1191
+ { code: "custom", path: ["child", "x"], message: "short" },
1192
+ ]);
1193
+
1194
+ const [{ errors }] = U.safeParse({ kind: "a", x: "q", child: { kind: "b", y: "no" } }).error!.issues as any;
1195
+ expect(errors[1].at(-1)).toEqual(errors[0].at(-1));
1196
+ expect(errors[0].at(-1).errors.map((o: any) => o.map((iss: any) => iss.path))).toEqual([[["kind"], ["x"]], [["y"]]]);
1197
+
1198
+ // an issue with no path yet stays without one, though the first visit's copy has gained one since
1199
+ const X: any = z.strictObject({
1200
+ get self() {
1201
+ return X.optional();
1202
+ },
1203
+ });
1204
+ const seen: unknown[] = [];
1205
+ const w = { extra: 1 };
1206
+ const r = z.object({ a: X, b: z.union([X, X.readonly()]) }).safeParse(
1207
+ { a: w, b: w },
1208
+ {
1209
+ error: (iss) => {
1210
+ if (iss.code === "unrecognized_keys") seen.push(iss.path);
1211
+ return undefined;
1212
+ },
1213
+ }
1214
+ );
1215
+ expect(r.error!.issues.map((iss) => iss.path)).toEqual([["a"], ["b"]]);
1216
+ expect(seen).toEqual([undefined, undefined, ["a"]]);
1217
+ });
1218
+
1219
+ test("a deep failure holds memory in proportion to its issues, not its depth", () => {
1220
+ v8.setFlagsFromString("--expose-gc");
1221
+ const gc = vm.runInNewContext("gc") as () => void;
1222
+ const used = () => v8.getHeapStatistics().used_heap_size;
1223
+
1224
+ const T: any = z.lazy(() => z.object({ next: T.optional(), vals: z.array(z.number()).optional() }));
1225
+ let base = 0;
1226
+ let held = 0;
1227
+ // runs while every node's cached result is still reachable
1228
+ const Probe = T.refine(
1229
+ () => {
1230
+ gc();
1231
+ held = used() - base;
1232
+ return true;
1233
+ },
1234
+ { when: () => true }
1235
+ );
1236
+ const measure = (depth: number) => {
1237
+ let input: any = { vals: Array(1000).fill("x") };
1238
+ for (let i = 0; i < depth; i++) input = { next: input };
1239
+ gc();
1240
+ base = used();
1241
+ expect(Probe.safeParse(input).success).toBe(false);
1242
+ return held;
1243
+ };
1244
+
1245
+ // the error grows linearly with depth here, so a cache copying it per level grows quadratically
1246
+ const small = measure(25);
1247
+ expect(measure(200) / small).toBeLessThan(16);
1248
+ });