zod 4.5.3 → 4.6.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 (348) hide show
  1. package/compile.cjs +19 -0
  2. package/index.cjs +19 -0
  3. package/locales/index.cjs +19 -0
  4. package/mini/index.cjs +19 -0
  5. package/package.json +8 -7
  6. package/src/v3/helpers/errorUtil.ts +1 -1
  7. package/src/v4/classic/checks.ts +0 -1
  8. package/src/v4/classic/external.ts +2 -0
  9. package/src/v4/classic/from-json-schema.ts +248 -25
  10. package/src/v4/classic/schemas.ts +255 -164
  11. package/src/v4/classic/tests/assignability.test.ts +59 -9
  12. package/src/v4/classic/tests/bigint.test.ts +6 -0
  13. package/src/v4/classic/tests/continuability.test.ts +2 -2
  14. package/src/v4/classic/tests/cyclic-data.test.ts +316 -0
  15. package/src/v4/classic/tests/default.test.ts +46 -0
  16. package/src/v4/classic/tests/enum.test.ts +9 -0
  17. package/src/v4/classic/tests/error.test.ts +130 -1
  18. package/src/v4/classic/tests/firstparty.test.ts +4 -0
  19. package/src/v4/classic/tests/from-json-schema.test.ts +157 -0
  20. package/src/v4/classic/tests/iban.test.ts +81 -0
  21. package/src/v4/classic/tests/instance-footprint.test.ts +18 -2
  22. package/src/v4/classic/tests/instanceof.test.ts +27 -7
  23. package/src/v4/classic/tests/issue-schema.test.ts +88 -56
  24. package/src/v4/classic/tests/object.test.ts +56 -0
  25. package/src/v4/classic/tests/optin-ladder.test.ts +3 -2
  26. package/src/v4/classic/tests/properties.test.ts +225 -0
  27. package/src/v4/classic/tests/recursive-types.test.ts +1 -1
  28. package/src/v4/classic/tests/standard-schema.test.ts +19 -0
  29. package/src/v4/classic/tests/string.test.ts +25 -0
  30. package/src/v4/classic/tests/template-literal.test.ts +33 -1
  31. package/src/v4/classic/tests/to-json-schema.test.ts +147 -3
  32. package/src/v4/classic/tests/validate.test.ts +569 -0
  33. package/src/v4/core/api.ts +30 -6
  34. package/src/v4/core/checks.ts +1 -101
  35. package/src/v4/core/compile.ts +193 -81
  36. package/src/v4/core/doc.ts +6 -2
  37. package/src/v4/core/errors.ts +3 -6
  38. package/src/v4/core/json-schema-generator.ts +2 -2
  39. package/src/v4/core/json-schema-processors.ts +226 -68
  40. package/src/v4/core/memoizer.ts +162 -36
  41. package/src/v4/core/parse.ts +37 -16
  42. package/src/v4/core/regexes.ts +10 -4
  43. package/src/v4/core/schemas.ts +314 -83
  44. package/src/v4/core/tests/cached.test.ts +54 -0
  45. package/src/v4/core/tests/compile-generative.test.ts +445 -0
  46. package/src/v4/core/tests/compile.test.ts +222 -2
  47. package/src/v4/core/tests/email-regex.test.ts +140 -0
  48. package/src/v4/core/tests/polyfill-collision.test.ts +46 -0
  49. package/src/v4/core/to-json-schema.ts +10 -8
  50. package/src/v4/core/util.ts +222 -147
  51. package/src/v4/core/versions.ts +2 -2
  52. package/src/v4/core/visit.ts +11 -0
  53. package/src/v4/locales/ar.ts +1 -0
  54. package/src/v4/locales/az.ts +1 -0
  55. package/src/v4/locales/be.ts +1 -0
  56. package/src/v4/locales/bg.ts +1 -0
  57. package/src/v4/locales/bn.ts +1 -0
  58. package/src/v4/locales/ca.ts +1 -0
  59. package/src/v4/locales/ckb.ts +1 -0
  60. package/src/v4/locales/cs.ts +1 -0
  61. package/src/v4/locales/da.ts +1 -0
  62. package/src/v4/locales/de.ts +1 -0
  63. package/src/v4/locales/el.ts +1 -0
  64. package/src/v4/locales/en.ts +1 -0
  65. package/src/v4/locales/eo.ts +1 -0
  66. package/src/v4/locales/es.ts +1 -0
  67. package/src/v4/locales/fa.ts +1 -0
  68. package/src/v4/locales/fi.ts +1 -0
  69. package/src/v4/locales/fr-CA.ts +1 -0
  70. package/src/v4/locales/fr.ts +1 -0
  71. package/src/v4/locales/gu.ts +1 -0
  72. package/src/v4/locales/he.ts +1 -0
  73. package/src/v4/locales/hi.ts +1 -0
  74. package/src/v4/locales/hr.ts +1 -0
  75. package/src/v4/locales/hu.ts +1 -0
  76. package/src/v4/locales/hy.ts +1 -0
  77. package/src/v4/locales/id.ts +1 -0
  78. package/src/v4/locales/is.ts +1 -0
  79. package/src/v4/locales/it.ts +1 -0
  80. package/src/v4/locales/ja.ts +1 -0
  81. package/src/v4/locales/ka.ts +1 -0
  82. package/src/v4/locales/km.ts +1 -0
  83. package/src/v4/locales/kn.ts +1 -0
  84. package/src/v4/locales/ko.ts +1 -0
  85. package/src/v4/locales/lt.ts +1 -0
  86. package/src/v4/locales/mk.ts +1 -0
  87. package/src/v4/locales/ms.ts +1 -0
  88. package/src/v4/locales/ne.ts +1 -0
  89. package/src/v4/locales/nl.ts +1 -0
  90. package/src/v4/locales/nn.ts +1 -0
  91. package/src/v4/locales/no.ts +1 -0
  92. package/src/v4/locales/ota.ts +1 -0
  93. package/src/v4/locales/pl.ts +1 -0
  94. package/src/v4/locales/ps.ts +1 -0
  95. package/src/v4/locales/pt-BR.ts +1 -0
  96. package/src/v4/locales/pt.ts +1 -0
  97. package/src/v4/locales/ro.ts +1 -0
  98. package/src/v4/locales/ru.ts +1 -0
  99. package/src/v4/locales/sk.ts +1 -0
  100. package/src/v4/locales/sl.ts +1 -0
  101. package/src/v4/locales/sv.ts +1 -0
  102. package/src/v4/locales/ta.ts +1 -0
  103. package/src/v4/locales/th.ts +1 -0
  104. package/src/v4/locales/tk.ts +1 -0
  105. package/src/v4/locales/tr.ts +1 -0
  106. package/src/v4/locales/uk.ts +1 -0
  107. package/src/v4/locales/ur.ts +1 -0
  108. package/src/v4/locales/uz.ts +1 -0
  109. package/src/v4/locales/vi.ts +1 -0
  110. package/src/v4/locales/yo.ts +1 -0
  111. package/src/v4/locales/zh-CN.ts +1 -0
  112. package/src/v4/locales/zh-TW.ts +1 -0
  113. package/src/v4/mini/checks.ts +0 -1
  114. package/src/v4/mini/external.ts +2 -0
  115. package/src/v4/mini/schemas.ts +38 -2
  116. package/src/v4/mini/tests/checks.test.ts +1 -1
  117. package/src/v4/mini/tests/computed.test.ts +11 -17
  118. package/src/v4/mini/tests/index.test.ts +8 -0
  119. package/src/v4/mini/tests/string.test.ts +16 -0
  120. package/v3/ZodError.cjs +19 -0
  121. package/v3/errors.cjs +19 -0
  122. package/v3/external.cjs +19 -0
  123. package/v3/helpers/enumUtil.cjs +19 -0
  124. package/v3/helpers/errorUtil.cjs +20 -1
  125. package/v3/helpers/errorUtil.js +1 -1
  126. package/v3/helpers/parseUtil.cjs +19 -0
  127. package/v3/helpers/partialUtil.cjs +19 -0
  128. package/v3/helpers/typeAliases.cjs +19 -0
  129. package/v3/helpers/util.cjs +19 -0
  130. package/v3/index.cjs +19 -0
  131. package/v3/standard-schema.cjs +19 -0
  132. package/v3/types.cjs +19 -0
  133. package/v4/classic/checks.cjs +20 -2
  134. package/v4/classic/checks.d.cts +1 -1
  135. package/v4/classic/checks.d.ts +1 -1
  136. package/v4/classic/checks.js +1 -1
  137. package/v4/classic/coerce.cjs +19 -0
  138. package/v4/classic/compat.cjs +19 -0
  139. package/v4/classic/deep-partial.cjs +19 -0
  140. package/v4/classic/errors.cjs +19 -0
  141. package/v4/classic/external.cjs +22 -1
  142. package/v4/classic/external.d.cts +1 -1
  143. package/v4/classic/external.d.ts +1 -1
  144. package/v4/classic/external.js +1 -1
  145. package/v4/classic/from-json-schema.cjs +264 -24
  146. package/v4/classic/from-json-schema.js +245 -24
  147. package/v4/classic/in-out.cjs +19 -0
  148. package/v4/classic/index.cjs +19 -0
  149. package/v4/classic/iso.cjs +19 -0
  150. package/v4/classic/parse.cjs +19 -0
  151. package/v4/classic/schemas.cjs +100 -31
  152. package/v4/classic/schemas.d.cts +17 -1
  153. package/v4/classic/schemas.d.ts +17 -1
  154. package/v4/classic/schemas.js +77 -29
  155. package/v4/core/api.cjs +37 -2
  156. package/v4/core/api.d.cts +6 -4
  157. package/v4/core/api.d.ts +6 -4
  158. package/v4/core/api.js +17 -2
  159. package/v4/core/checks.cjs +19 -96
  160. package/v4/core/checks.d.cts +1 -1
  161. package/v4/core/checks.d.ts +1 -1
  162. package/v4/core/checks.js +0 -96
  163. package/v4/core/compile.cjs +164 -65
  164. package/v4/core/compile.d.cts +18 -4
  165. package/v4/core/compile.d.ts +18 -4
  166. package/v4/core/compile.js +145 -66
  167. package/v4/core/core.cjs +19 -0
  168. package/v4/core/doc.cjs +26 -2
  169. package/v4/core/doc.js +7 -2
  170. package/v4/core/errors.cjs +21 -5
  171. package/v4/core/errors.js +2 -5
  172. package/v4/core/index.cjs +19 -0
  173. package/v4/core/json-schema-generator.cjs +20 -1
  174. package/v4/core/json-schema-generator.js +2 -2
  175. package/v4/core/json-schema-processors.cjs +215 -63
  176. package/v4/core/json-schema-processors.d.cts +17 -0
  177. package/v4/core/json-schema-processors.d.ts +17 -0
  178. package/v4/core/json-schema-processors.js +195 -64
  179. package/v4/core/json-schema.cjs +19 -0
  180. package/v4/core/memoizer.cjs +204 -36
  181. package/v4/core/memoizer.js +162 -36
  182. package/v4/core/parse.cjs +56 -16
  183. package/v4/core/parse.js +37 -16
  184. package/v4/core/regexes.cjs +29 -6
  185. package/v4/core/regexes.d.cts +2 -0
  186. package/v4/core/regexes.d.ts +2 -0
  187. package/v4/core/regexes.js +8 -4
  188. package/v4/core/registries.cjs +19 -0
  189. package/v4/core/schemas.cjs +285 -66
  190. package/v4/core/schemas.d.cts +34 -3
  191. package/v4/core/schemas.d.ts +34 -3
  192. package/v4/core/schemas.js +264 -65
  193. package/v4/core/standard-schema.cjs +19 -0
  194. package/v4/core/to-json-schema.cjs +29 -7
  195. package/v4/core/to-json-schema.d.cts +7 -3
  196. package/v4/core/to-json-schema.d.ts +7 -3
  197. package/v4/core/to-json-schema.js +8 -7
  198. package/v4/core/util.cjs +181 -143
  199. package/v4/core/util.d.cts +25 -4
  200. package/v4/core/util.d.ts +25 -4
  201. package/v4/core/util.js +160 -143
  202. package/v4/core/versions.cjs +21 -2
  203. package/v4/core/versions.d.cts +1 -1
  204. package/v4/core/versions.d.ts +1 -1
  205. package/v4/core/versions.js +2 -2
  206. package/v4/core/visit.cjs +31 -0
  207. package/v4/core/visit.js +12 -0
  208. package/v4/index.cjs +19 -0
  209. package/v4/locales/ar.cjs +1 -0
  210. package/v4/locales/ar.js +1 -0
  211. package/v4/locales/az.cjs +1 -0
  212. package/v4/locales/az.js +1 -0
  213. package/v4/locales/be.cjs +1 -0
  214. package/v4/locales/be.js +1 -0
  215. package/v4/locales/bg.cjs +1 -0
  216. package/v4/locales/bg.js +1 -0
  217. package/v4/locales/bn.cjs +1 -0
  218. package/v4/locales/bn.js +1 -0
  219. package/v4/locales/ca.cjs +1 -0
  220. package/v4/locales/ca.js +1 -0
  221. package/v4/locales/ckb.cjs +1 -0
  222. package/v4/locales/ckb.js +1 -0
  223. package/v4/locales/cs.cjs +1 -0
  224. package/v4/locales/cs.js +1 -0
  225. package/v4/locales/da.cjs +1 -0
  226. package/v4/locales/da.js +1 -0
  227. package/v4/locales/de.cjs +1 -0
  228. package/v4/locales/de.js +1 -0
  229. package/v4/locales/el.cjs +1 -0
  230. package/v4/locales/el.js +1 -0
  231. package/v4/locales/en.cjs +1 -0
  232. package/v4/locales/en.js +1 -0
  233. package/v4/locales/eo.cjs +1 -0
  234. package/v4/locales/eo.js +1 -0
  235. package/v4/locales/es.cjs +1 -0
  236. package/v4/locales/es.js +1 -0
  237. package/v4/locales/fa.cjs +1 -0
  238. package/v4/locales/fa.js +1 -0
  239. package/v4/locales/fi.cjs +1 -0
  240. package/v4/locales/fi.js +1 -0
  241. package/v4/locales/fr-CA.cjs +1 -0
  242. package/v4/locales/fr-CA.js +1 -0
  243. package/v4/locales/fr.cjs +1 -0
  244. package/v4/locales/fr.js +1 -0
  245. package/v4/locales/gu.cjs +1 -0
  246. package/v4/locales/gu.js +1 -0
  247. package/v4/locales/he.cjs +1 -0
  248. package/v4/locales/he.js +1 -0
  249. package/v4/locales/hi.cjs +1 -0
  250. package/v4/locales/hi.js +1 -0
  251. package/v4/locales/hr.cjs +1 -0
  252. package/v4/locales/hr.js +1 -0
  253. package/v4/locales/hu.cjs +1 -0
  254. package/v4/locales/hu.js +1 -0
  255. package/v4/locales/hy.cjs +1 -0
  256. package/v4/locales/hy.js +1 -0
  257. package/v4/locales/id.cjs +1 -0
  258. package/v4/locales/id.js +1 -0
  259. package/v4/locales/index.cjs +19 -0
  260. package/v4/locales/is.cjs +1 -0
  261. package/v4/locales/is.js +1 -0
  262. package/v4/locales/it.cjs +1 -0
  263. package/v4/locales/it.js +1 -0
  264. package/v4/locales/ja.cjs +1 -0
  265. package/v4/locales/ja.js +1 -0
  266. package/v4/locales/ka.cjs +1 -0
  267. package/v4/locales/ka.js +1 -0
  268. package/v4/locales/km.cjs +1 -0
  269. package/v4/locales/km.js +1 -0
  270. package/v4/locales/kn.cjs +1 -0
  271. package/v4/locales/kn.js +1 -0
  272. package/v4/locales/ko.cjs +1 -0
  273. package/v4/locales/ko.js +1 -0
  274. package/v4/locales/lt.cjs +1 -0
  275. package/v4/locales/lt.js +1 -0
  276. package/v4/locales/mk.cjs +1 -0
  277. package/v4/locales/mk.js +1 -0
  278. package/v4/locales/ms.cjs +1 -0
  279. package/v4/locales/ms.js +1 -0
  280. package/v4/locales/ne.cjs +1 -0
  281. package/v4/locales/ne.js +1 -0
  282. package/v4/locales/nl.cjs +1 -0
  283. package/v4/locales/nl.js +1 -0
  284. package/v4/locales/nn.cjs +1 -0
  285. package/v4/locales/nn.js +1 -0
  286. package/v4/locales/no.cjs +1 -0
  287. package/v4/locales/no.js +1 -0
  288. package/v4/locales/ota.cjs +1 -0
  289. package/v4/locales/ota.js +1 -0
  290. package/v4/locales/pl.cjs +1 -0
  291. package/v4/locales/pl.js +1 -0
  292. package/v4/locales/ps.cjs +1 -0
  293. package/v4/locales/ps.js +1 -0
  294. package/v4/locales/pt-BR.cjs +1 -0
  295. package/v4/locales/pt-BR.js +1 -0
  296. package/v4/locales/pt.cjs +1 -0
  297. package/v4/locales/pt.js +1 -0
  298. package/v4/locales/ro.cjs +1 -0
  299. package/v4/locales/ro.js +1 -0
  300. package/v4/locales/ru.cjs +1 -0
  301. package/v4/locales/ru.js +1 -0
  302. package/v4/locales/sk.cjs +1 -0
  303. package/v4/locales/sk.js +1 -0
  304. package/v4/locales/sl.cjs +1 -0
  305. package/v4/locales/sl.js +1 -0
  306. package/v4/locales/sv.cjs +1 -0
  307. package/v4/locales/sv.js +1 -0
  308. package/v4/locales/ta.cjs +1 -0
  309. package/v4/locales/ta.js +1 -0
  310. package/v4/locales/th.cjs +1 -0
  311. package/v4/locales/th.js +1 -0
  312. package/v4/locales/tk.cjs +1 -0
  313. package/v4/locales/tk.js +1 -0
  314. package/v4/locales/tr.cjs +1 -0
  315. package/v4/locales/tr.js +1 -0
  316. package/v4/locales/uk.cjs +1 -0
  317. package/v4/locales/uk.js +1 -0
  318. package/v4/locales/ur.cjs +1 -0
  319. package/v4/locales/ur.js +1 -0
  320. package/v4/locales/uz.cjs +1 -0
  321. package/v4/locales/uz.js +1 -0
  322. package/v4/locales/vi.cjs +1 -0
  323. package/v4/locales/vi.js +1 -0
  324. package/v4/locales/yo.cjs +1 -0
  325. package/v4/locales/yo.js +1 -0
  326. package/v4/locales/zh-CN.cjs +1 -0
  327. package/v4/locales/zh-CN.js +1 -0
  328. package/v4/locales/zh-TW.cjs +1 -0
  329. package/v4/locales/zh-TW.js +1 -0
  330. package/v4/mini/checks.cjs +20 -2
  331. package/v4/mini/checks.d.cts +1 -1
  332. package/v4/mini/checks.d.ts +1 -1
  333. package/v4/mini/checks.js +1 -1
  334. package/v4/mini/coerce.cjs +19 -0
  335. package/v4/mini/deep-partial.cjs +19 -0
  336. package/v4/mini/external.cjs +22 -1
  337. package/v4/mini/external.d.cts +1 -1
  338. package/v4/mini/external.d.ts +1 -1
  339. package/v4/mini/external.js +1 -1
  340. package/v4/mini/in-out.cjs +19 -0
  341. package/v4/mini/index.cjs +19 -0
  342. package/v4/mini/iso.cjs +19 -0
  343. package/v4/mini/parse.cjs +19 -0
  344. package/v4/mini/schemas.cjs +42 -4
  345. package/v4/mini/schemas.d.cts +8 -0
  346. package/v4/mini/schemas.d.ts +8 -0
  347. package/v4/mini/schemas.js +19 -2
  348. package/v4-mini/index.cjs +19 -0
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.$ZodXor = exports.$ZodUnion = exports.$ZodObjectJIT = exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodCreditCard = exports.$ZodE164 = exports.$ZodBase64URL = exports.$ZodBase64 = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodMAC = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.URL_UNPARSEABLE = exports.URL_BAD_FORMAT = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
27
- exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodFunction = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPreprocess = exports.$ZodCodec = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodExactOptional = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = void 0;
26
+ exports.$ZodObject = exports.$ZodArray = exports.$ZodDate = exports.$ZodVoid = exports.$ZodNever = exports.$ZodUnknown = exports.$ZodAny = exports.$ZodNull = exports.$ZodUndefined = exports.$ZodSymbol = exports.$ZodBigIntFormat = exports.$ZodBigInt = exports.$ZodBoolean = exports.$ZodNumberFormat = exports.$ZodNumber = exports.$ZodCustomStringFormat = exports.$ZodJWT = exports.$ZodIBAN = exports.$ZodCreditCard = exports.$ZodE164 = exports.$ZodBase64URL = exports.base64urlCharset = exports.$ZodBase64 = exports.base64Charset = exports.$ZodCIDRv6 = exports.$ZodCIDRv4 = exports.$ZodMAC = exports.$ZodIPv6 = exports.$ZodIPv4 = exports.$ZodISODuration = exports.$ZodISOTime = exports.$ZodISODate = exports.$ZodISODateTime = exports.$ZodKSUID = exports.$ZodXID = exports.$ZodULID = exports.$ZodCUID2 = exports.$ZodCUID = exports.$ZodNanoID = exports.$ZodEmoji = exports.$ZodURL = exports.URL_UNPARSEABLE = exports.URL_BAD_FORMAT = exports.$ZodEmail = exports.$ZodUUID = exports.$ZodGUID = exports.$ZodStringFormat = exports.$ZodString = exports.clone = exports.$ZodType = void 0;
27
+ exports.$ZodProperties = exports.$ZodCustom = exports.$ZodLazy = exports.$ZodPromise = exports.$ZodFunction = exports.$ZodTemplateLiteral = exports.$ZodReadonly = exports.$ZodPreprocess = exports.$ZodCodec = exports.$ZodPipe = exports.$ZodNaN = exports.$ZodCatch = exports.$ZodSuccess = exports.$ZodNonOptional = exports.$ZodPrefault = exports.$ZodDefault = exports.$ZodNullable = exports.$ZodExactOptional = exports.$ZodOptional = exports.$ZodTransform = exports.$ZodFile = exports.$ZodLiteral = exports.$ZodEnum = exports.$ZodSet = exports.$ZodMap = exports.$ZodRecord = exports.$ZodTuple = exports.$ZodIntersection = exports.$ZodDiscriminatedUnion = exports.$ZodXor = exports.$ZodUnion = exports.$ZodObjectJIT = void 0;
28
28
  exports.standardProps = standardProps;
29
29
  exports.parseURLObject = parseURLObject;
30
30
  exports.stripTabAndNewline = stripTabAndNewline;
@@ -35,6 +35,7 @@ exports.isValidCIDRv6 = isValidCIDRv6;
35
35
  exports.isValidBase64 = isValidBase64;
36
36
  exports.isValidBase64URL = isValidBase64URL;
37
37
  exports.isValidCreditCard = isValidCreditCard;
38
+ exports.isValidIBAN = isValidIBAN;
38
39
  exports.isValidJWT = isValidJWT;
39
40
  exports.getDiscriminatedOption = getDiscriminatedOption;
40
41
  exports.mergeValues = mergeValues;
@@ -168,16 +169,24 @@ exports.$ZodType = core.$constructor("$ZodType", (inst, def) => {
168
169
  },
169
170
  });
170
171
  /** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
171
- const toStandardResult = (r) => r.success ? { value: r.data } : { issues: r.error?.issues };
172
+ // a Standard Schema result only reports issues, so a failure finalizes them straight off the raw payload: no ZodError, and no lazy result to read through
173
+ const toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())) } : { value: r.value };
174
+ async function validateAsync(inst, value) {
175
+ const ctx = { async: true };
176
+ return toStandardResult((await inst._zod.run({ value, issues: [] }, ctx)), ctx);
177
+ }
172
178
  function standardProps(inst) {
173
179
  return {
174
180
  validate: (value) => {
181
+ const ctx = { async: false };
175
182
  try {
176
- return toStandardResult((0, parse_js_1.safeParse)(inst, value));
177
- }
178
- catch (_) {
179
- return (0, parse_js_1.safeParseAsync)(inst, value).then(toStandardResult);
183
+ const r = inst._zod.run({ value, issues: [] }, ctx);
184
+ if (!(r instanceof Promise))
185
+ return toStandardResult(r, ctx);
180
186
  }
187
+ catch (_) { }
188
+ // async function so a synchronously throwing check rejects instead of escaping validate
189
+ return validateAsync(inst, value);
181
190
  },
182
191
  vendor: "zod",
183
192
  version: 1,
@@ -187,7 +196,8 @@ var util_js_1 = require("./util.cjs");
187
196
  Object.defineProperty(exports, "clone", { enumerable: true, get: function () { return util_js_1.clone; } });
188
197
  exports.$ZodString = core.$constructor("$ZodString", (inst, def) => {
189
198
  exports.$ZodType.init(inst, def);
190
- inst._zod.pattern = [...(inst?._zod.bag?.patterns ?? [])].pop() ?? regexes.string(inst._zod.bag);
199
+ // a format's own pattern, else unbounded; a template literal derives the check-aware form itself
200
+ inst._zod.pattern = def.pattern ?? regexes.anyString;
191
201
  inst._zod.parse = (payload, _) => {
192
202
  if (def.coerce)
193
203
  try {
@@ -373,13 +383,6 @@ exports.$ZodKSUID = core.$constructor("$ZodKSUID", (inst, def) => {
373
383
  exports.$ZodISODateTime = core.$constructor("$ZodISODateTime", (inst, def) => {
374
384
  def.pattern ?? (def.pattern = regexes.datetime(def));
375
385
  exports.$ZodStringFormat.init(inst, def);
376
- // these two drop the offset or seconds `date-time` requires — on the bag not the def, since `z.string().check(...)` lands the format on a different schema
377
- if (def.local || def.precision === -1) {
378
- inst._zod.bag.laxFormat = true;
379
- inst._zod.onattach.push((s) => {
380
- s._zod.bag.laxFormat = true;
381
- });
382
- }
383
386
  });
384
387
  exports.$ZodISODate = core.$constructor("$ZodISODate", (inst, def) => {
385
388
  def.pattern ?? (def.pattern = regexes.date);
@@ -396,7 +399,6 @@ exports.$ZodISODuration = core.$constructor("$ZodISODuration", (inst, def) => {
396
399
  exports.$ZodIPv4 = core.$constructor("$ZodIPv4", (inst, def) => {
397
400
  def.pattern ?? (def.pattern = regexes.ipv4);
398
401
  exports.$ZodStringFormat.init(inst, def);
399
- inst._zod.bag.format = `ipv4`;
400
402
  });
401
403
  /** An IPv6 address is written with hex digits, colons and dots, and nothing else. The guard is what makes the check below an IPv6 check: `new URL("http://[...]")` parses an authority, not an address, so `@` and `\` re-delimit it and `"::@1\\"` validates against the host `0.0.0.1`. The URL parser also deletes ASCII tab, LF and CR rather than failing, which is how `"::1\n"` validated as `::1`. */
402
404
  const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
@@ -415,7 +417,6 @@ function isValidIPv6(value) {
415
417
  exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
416
418
  def.pattern ?? (def.pattern = regexes.ipv6);
417
419
  exports.$ZodStringFormat.init(inst, def);
418
- inst._zod.bag.format = `ipv6`;
419
420
  inst._zod.check = (payload) => {
420
421
  if (!isValidIPv6(payload.value)) {
421
422
  payload.issues.push({
@@ -431,7 +432,6 @@ exports.$ZodIPv6 = core.$constructor("$ZodIPv6", (inst, def) => {
431
432
  exports.$ZodMAC = core.$constructor("$ZodMAC", (inst, def) => {
432
433
  def.pattern ?? (def.pattern = regexes.mac(def.delimiter));
433
434
  exports.$ZodStringFormat.init(inst, def);
434
- inst._zod.bag.format = `mac`;
435
435
  });
436
436
  exports.$ZodCIDRv4 = core.$constructor("$ZodCIDRv4", (inst, def) => {
437
437
  def.pattern ?? (def.pattern = regexes.cidrv4);
@@ -484,10 +484,11 @@ function isValidBase64(data) {
484
484
  return false;
485
485
  }
486
486
  }
487
+ // lax on purpose: the quantified regexes.base64 overflows the regex stack on multi-MB input and its leading ^$| alternation leaks through template-literal composition; isValidBase64 enforces length and padding
488
+ exports.base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
487
489
  exports.$ZodBase64 = core.$constructor("$ZodBase64", (inst, def) => {
488
- def.pattern ?? (def.pattern = regexes.base64);
490
+ def.pattern ?? (def.pattern = exports.base64Charset);
489
491
  exports.$ZodStringFormat.init(inst, def);
490
- inst._zod.bag.contentEncoding = "base64";
491
492
  inst._zod.check = (payload) => {
492
493
  if (isValidBase64(payload.value))
493
494
  return;
@@ -500,18 +501,19 @@ exports.$ZodBase64 = core.$constructor("$ZodBase64", (inst, def) => {
500
501
  });
501
502
  };
502
503
  });
503
- ////////////////////////////// ZodBase64 //////////////////////////////
504
+ ////////////////////////////// ZodBase64URL //////////////////////////////
505
+ // lax on purpose: the quantified regexes.base64url overflows the regex stack on multi-MB input; isValidBase64 enforces length on the padded string
506
+ exports.base64urlCharset = /^[A-Za-z0-9_-]*$/;
504
507
  function isValidBase64URL(data) {
505
- if (!regexes.base64url.test(data))
508
+ if (!exports.base64urlCharset.test(data))
506
509
  return false;
507
510
  const base64 = data.replace(/[-_]/g, (c) => (c === "-" ? "+" : "/"));
508
511
  const padded = base64.padEnd(Math.ceil(base64.length / 4) * 4, "=");
509
512
  return isValidBase64(padded);
510
513
  }
511
514
  exports.$ZodBase64URL = core.$constructor("$ZodBase64URL", (inst, def) => {
512
- def.pattern ?? (def.pattern = regexes.base64url);
515
+ def.pattern ?? (def.pattern = exports.base64urlCharset);
513
516
  exports.$ZodStringFormat.init(inst, def);
514
- inst._zod.bag.contentEncoding = "base64url";
515
517
  inst._zod.check = (payload) => {
516
518
  if (isValidBase64URL(payload.value))
517
519
  return;
@@ -536,7 +538,7 @@ function isLuhnAlgo(digits) {
536
538
  let bit = 1;
537
539
  let sum = 0;
538
540
  while (length) {
539
- const value = +digits[--length];
541
+ const value = digits.charCodeAt(--length) - 48;
540
542
  bit ^= 1;
541
543
  sum += bit ? [0, 2, 4, 6, 8, 1, 3, 5, 7, 9][value] : value;
542
544
  }
@@ -563,6 +565,42 @@ exports.$ZodCreditCard = core.$constructor("$ZodCreditCard", (inst, def) => {
563
565
  });
564
566
  };
565
567
  });
568
+ ////////////////////////////// ZodIBAN //////////////////////////////
569
+ // iso 7064 mod 97-10 checksum without BigInt
570
+ function isIso7064Mod97(iban) {
571
+ let remainder = 0;
572
+ const len = iban.length;
573
+ for (let i = 4; i < len; i++) {
574
+ const code = iban.charCodeAt(i);
575
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
576
+ }
577
+ for (let i = 0; i < 4; i++) {
578
+ const code = iban.charCodeAt(i);
579
+ remainder = (code >= 65 ? remainder * 100 + (code - 55) : remainder * 10 + (code - 48)) % 97;
580
+ }
581
+ return remainder === 1;
582
+ }
583
+ function isValidIBAN(input) {
584
+ if (!regexes.iban.test(input))
585
+ return false;
586
+ return isIso7064Mod97(input);
587
+ }
588
+ exports.$ZodIBAN = core.$constructor("$ZodIBAN", (inst, def) => {
589
+ // shape only — checksum is not expressible as a pattern
590
+ def.pattern ?? (def.pattern = regexes.iban);
591
+ exports.$ZodStringFormat.init(inst, def);
592
+ inst._zod.check = (payload) => {
593
+ if (isValidIBAN(payload.value))
594
+ return;
595
+ payload.issues.push({
596
+ code: "invalid_format",
597
+ format: "iban",
598
+ input: payload.value,
599
+ inst,
600
+ continue: !def.abort,
601
+ });
602
+ };
603
+ });
566
604
  ////////////////////////////// ZodJWT //////////////////////////////
567
605
  function isValidJWT(token, algorithm = null) {
568
606
  try {
@@ -616,7 +654,7 @@ exports.$ZodCustomStringFormat = core.$constructor("$ZodCustomStringFormat", (in
616
654
  });
617
655
  exports.$ZodNumber = core.$constructor("$ZodNumber", (inst, def) => {
618
656
  exports.$ZodType.init(inst, def);
619
- inst._zod.pattern = inst._zod.bag.pattern ?? regexes.number;
657
+ inst._zod.pattern = regexes.number;
620
658
  inst._zod.parse = (payload, _ctx) => {
621
659
  if (def.coerce)
622
660
  try {
@@ -824,6 +862,7 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
824
862
  }
825
863
  payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
826
864
  const proms = [];
865
+ const abortEarly = ctx?.abortEarly;
827
866
  for (let i = 0; i < input.length; i++) {
828
867
  const item = input[i];
829
868
  const result = def.element._zod.run({
@@ -835,6 +874,9 @@ exports.$ZodArray = core.$constructor("$ZodArray", (inst, def) => {
835
874
  }
836
875
  else {
837
876
  handleArrayResult(result, payload, i);
877
+ // the element's payload is authoritative here, since handleArrayResult forwards every issue; an object's is not, because it drops a failed absent optional
878
+ if (abortEarly && result.issues.length !== 0 && util.aborted(result))
879
+ break;
838
880
  }
839
881
  }
840
882
  if (proms.length) {
@@ -901,14 +943,21 @@ function normalizeDef(def) {
901
943
  optionalKeys: new Set(okeys),
902
944
  };
903
945
  }
904
- function handleCatchall(proms, input, payload, ctx, def, inst) {
946
+ function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
905
947
  const unrecognized = [];
906
948
  const keySet = def.keySet;
907
949
  const _catchall = def.catchall._zod;
908
950
  const t = _catchall.def.type;
909
951
  const optin = _catchall.optin;
910
952
  const optout = _catchall.optout;
953
+ // starts at 0, not the current length: the shape phase already ran and may have aborted
954
+ let seen = 0;
911
955
  for (const key in input) {
956
+ if (abortEarly && payload.issues.length !== seen) {
957
+ if (util.aborted(payload, seen))
958
+ break;
959
+ seen = payload.issues.length;
960
+ }
912
961
  // Must precede the __proto__ branch: a declared key is not unrecognized, even though the shape loop deliberately strips __proto__ from the parsed output.
913
962
  if (keySet.has(key))
914
963
  continue;
@@ -946,26 +995,22 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
946
995
  return payload;
947
996
  });
948
997
  }
949
- // Whichever object a def's `shape` currently answers from: the one the caller passed until the first read, the frozen copy after it. Keyed by def, so a def rebuilt by a builder is simply absent rather than inheriting the source's. Read its keys with `Object.keys`, which does not invoke them — that is what lets a discriminated union check its discriminator without resolving an option whose getters reference the union being constructed.
950
- const propShapes = new WeakMap();
951
998
  exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
952
999
  // requires cast because technically $ZodObject doesn't extend
953
1000
  exports.$ZodType.init(inst, def);
954
- // const sh = def.shape;
955
1001
  const desc = Object.getOwnPropertyDescriptor(def, "shape");
956
- if (!desc?.get) {
957
- const sh = def.shape;
958
- propShapes.set(def, sh);
959
- Object.defineProperty(def, "shape", {
960
- get: () => {
961
- const newSh = { ...sh };
962
- Object.defineProperty(def, "shape", {
963
- value: newSh,
964
- });
965
- propShapes.set(def, newSh);
966
- return newSh;
967
- },
968
- });
1002
+ // a cloned def carries its source's accessor, which knows the shape it answers from; adopting that keeps the clone's keys readable without running it
1003
+ const sh = desc?.get ? desc.get.raw : (def.shape ?? {});
1004
+ if (sh) {
1005
+ // Freezes the shape on first read, so its getters resolve once and every later read sees the same schemas.
1006
+ const get = () => {
1007
+ const newSh = { ...sh };
1008
+ Object.defineProperty(def, "shape", { value: newSh });
1009
+ get.raw = newSh;
1010
+ return newSh;
1011
+ };
1012
+ get.raw = sh;
1013
+ Object.defineProperty(def, "shape", { get });
969
1014
  }
970
1015
  const _normalized = util.cached(() => normalizeDef(def));
971
1016
  util.defineLazyInternal(inst, "propValues", (zod) => {
@@ -1006,7 +1051,14 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
1006
1051
  payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
1007
1052
  const proms = [];
1008
1053
  const shape = value.shape;
1054
+ const abortEarly = ctx?.abortEarly;
1055
+ let seen = payload.issues.length;
1009
1056
  for (const key of value.allKeys) {
1057
+ if (abortEarly && payload.issues.length !== seen) {
1058
+ if (util.aborted(payload, seen))
1059
+ break;
1060
+ seen = payload.issues.length;
1061
+ }
1010
1062
  if (key === "__proto__")
1011
1063
  continue;
1012
1064
  const el = shape[key];
@@ -1023,7 +1075,7 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
1023
1075
  if (!catchall) {
1024
1076
  return proms.length ? Promise.all(proms).then(() => payload) : payload;
1025
1077
  }
1026
- return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
1078
+ return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
1027
1079
  };
1028
1080
  });
1029
1081
  exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
@@ -1038,12 +1090,18 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
1038
1090
  // a symbol has no source literal, so it is read as `syms[i]` off the closed-over scope
1039
1091
  const doc = new doc_js_1.Doc(["payload", "ctx"], { shape, inst, memo, syms });
1040
1092
  const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
1041
- // Prefixes in place, like util.prefixIssues does for every interpreted path.
1093
+ // prefixes in place, like util.prefixIssues. newResult must land before the early return: a catchall runs after this and would otherwise write onto the caller's input
1042
1094
  const prefixStr = (id, k) => `
1095
+ let ${id}_ab = false;
1043
1096
  for (let i = 0; i < ${id}.issues.length; i++) {
1044
1097
  const iss = ${id}.issues[i];
1045
1098
  iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
1046
1099
  payload.issues.push(iss);
1100
+ if (iss.continue !== true) ${id}_ab = true;
1101
+ }
1102
+ if (${id}_ab && ctx && ctx.abortEarly) {
1103
+ payload.value = newResult;
1104
+ return payload;
1047
1105
  }`;
1048
1106
  doc.write(`const input = payload.value;`);
1049
1107
  const ids = Object.create(null);
@@ -1092,6 +1150,10 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
1092
1150
  input: undefined,
1093
1151
  path: [${k}]
1094
1152
  });
1153
+ if (ctx && ctx.abortEarly) {
1154
+ payload.value = newResult;
1155
+ return payload;
1156
+ }
1095
1157
  }
1096
1158
 
1097
1159
  if (${id}_present) {
@@ -1147,7 +1209,7 @@ exports.$ZodObjectJIT = core.$constructor("$ZodObjectJIT", (inst, def) => {
1147
1209
  payload = fastpass(payload, ctx);
1148
1210
  if (!catchall)
1149
1211
  return payload;
1150
- return handleCatchall([], input, payload, ctx, value, inst);
1212
+ return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
1151
1213
  }
1152
1214
  return superParse(payload, ctx);
1153
1215
  };
@@ -1324,9 +1386,9 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1324
1386
  }
1325
1387
  return propValues;
1326
1388
  });
1327
- // Checked now rather than in the lookup map below, so an option that lacks the discriminator fails at the `discriminatedUnion` call instead of on the first object parsed. Options whose shape cannot be enumerated without resolving it — pipes, lazies, and objects rebuilt by a builder such as `.extend()` — are left to the map.
1389
+ // Checked now rather than in the lookup map below, so an option that lacks the discriminator fails at the `discriminatedUnion` call instead of on the first object parsed. Options whose shape cannot be enumerated without resolving it — pipes and lazies — are left to the map.
1328
1390
  def.options.forEach((option, i) => {
1329
- const propShape = propShapes.get(option._zod.def);
1391
+ const propShape = util.rawShape(option._zod.def);
1330
1392
  if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) {
1331
1393
  throw new Error(`Invalid discriminated union option at index "${i}"`);
1332
1394
  }
@@ -1547,6 +1609,9 @@ exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
1547
1609
  }
1548
1610
  // Run every item in parallel, collecting results into an indexed array. The post-processing in `handleTupleResults` walks them in order so it can decide whether an absent optional-output error can truncate the tail or must be reported to preserve required output.
1549
1611
  const itemResults = new Array(items.length);
1612
+ // only tracked when there is a rest loop to skip
1613
+ const abortEarly = def.rest ? ctx?.abortEarly : undefined;
1614
+ let itemAborted = false;
1550
1615
  for (let i = 0; i < items.length; i++) {
1551
1616
  const r = items[i]._zod.run({ value: input[i], issues: [] }, ctx);
1552
1617
  if (r instanceof Promise) {
@@ -1556,12 +1621,21 @@ exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
1556
1621
  }
1557
1622
  else {
1558
1623
  itemResults[i] = r;
1624
+ if (abortEarly && !itemAborted && r.issues.length)
1625
+ itemAborted = util.aborted(r);
1559
1626
  }
1560
1627
  }
1561
- if (def.rest) {
1628
+ // sound because rest is non-empty exactly when every fixed index is present, the one case handleTupleResults cannot discard an item's issues
1629
+ if (def.rest && !itemAborted) {
1562
1630
  let i = items.length - 1;
1563
1631
  const rest = input.slice(items.length);
1632
+ let seen = payload.issues.length;
1564
1633
  for (const el of rest) {
1634
+ if (abortEarly && payload.issues.length !== seen) {
1635
+ if (util.aborted(payload, seen))
1636
+ break;
1637
+ seen = payload.issues.length;
1638
+ }
1565
1639
  i++;
1566
1640
  const result = def.rest._zod.run({ value: el, issues: [] }, ctx);
1567
1641
  if (result instanceof Promise) {
@@ -1643,6 +1717,7 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1643
1717
  });
1644
1718
  return payload;
1645
1719
  }
1720
+ // no guard in either loop below: a record's invalid_key aborts but an enclosing intersection can reconcile it, so a stopped loop hides keys the sibling does not own and the intersection then rejects nothing
1646
1721
  const proms = [];
1647
1722
  const values = def.keyType._zod.values;
1648
1723
  if (values && !def.partial) {
@@ -1814,7 +1889,14 @@ exports.$ZodMap = core.$constructor("$ZodMap", (inst, def) => {
1814
1889
  }
1815
1890
  const proms = [];
1816
1891
  payload.value = memo ? memo.alloc(inst, payload, new Map(), ctx) : new Map();
1892
+ const abortEarly = ctx?.abortEarly;
1893
+ let seen = payload.issues.length;
1817
1894
  for (const [key, value] of input) {
1895
+ if (abortEarly && payload.issues.length !== seen) {
1896
+ if (util.aborted(payload, seen))
1897
+ break;
1898
+ seen = payload.issues.length;
1899
+ }
1818
1900
  const keyResult = def.keyType._zod.run({ value: key, issues: [] }, ctx);
1819
1901
  const valueResult = def.valueType._zod.run({ value: value, issues: [] }, ctx);
1820
1902
  if (keyResult instanceof Promise || valueResult instanceof Promise) {
@@ -1880,7 +1962,14 @@ exports.$ZodSet = core.$constructor("$ZodSet", (inst, def) => {
1880
1962
  }
1881
1963
  const proms = [];
1882
1964
  payload.value = memo ? memo.alloc(inst, payload, new Set(), ctx) : new Set();
1965
+ const abortEarly = ctx?.abortEarly;
1966
+ let seen = payload.issues.length;
1883
1967
  for (const item of input) {
1968
+ if (abortEarly && payload.issues.length !== seen) {
1969
+ if (util.aborted(payload, seen))
1970
+ break;
1971
+ seen = payload.issues.length;
1972
+ }
1884
1973
  const result = def.valueType._zod.run({ value: item, issues: [] }, ctx);
1885
1974
  if (result instanceof Promise) {
1886
1975
  proms.push(result.then((result) => handleSetResult(result, payload)));
@@ -1904,9 +1993,11 @@ exports.$ZodEnum = core.$constructor("$ZodEnum", (inst, def) => {
1904
1993
  const values = util.getEnumValues(def.entries);
1905
1994
  const valuesSet = new Set(values);
1906
1995
  inst._zod.values = valuesSet;
1907
- const patternValues = values.filter((k) => util.propertyKeyTypes.has(typeof k));
1908
- // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
1909
- inst._zod.pattern = new RegExp(patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
1996
+ util.defineLazyInternal(inst, "pattern", (zod) => {
1997
+ const patternValues = util.getEnumValues(zod.def.entries).filter((k) => util.propertyKeyTypes.has(typeof k));
1998
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
1999
+ return new RegExp(patternValues.length ? `^(${patternValues.map((o) => util.escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
2000
+ });
1910
2001
  inst._zod.parse = (payload, _ctx) => {
1911
2002
  const input = payload.value;
1912
2003
  if (valuesSet.has(input)) {
@@ -1925,12 +2016,15 @@ exports.$ZodLiteral = core.$constructor("$ZodLiteral", (inst, def) => {
1925
2016
  exports.$ZodType.init(inst, def);
1926
2017
  const values = new Set(def.values);
1927
2018
  inst._zod.values = values;
1928
- // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
1929
- inst._zod.pattern = new RegExp(def.values.length
1930
- ? `^(${def.values
1931
- .map((o) => (typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o)))
1932
- .join("|")})$`
1933
- : "^[^\\s\\S]$");
2019
+ util.defineLazyInternal(inst, "pattern", (zod) => {
2020
+ const vals = zod.def.values;
2021
+ // unmatchable fallback, RE2-safe: an empty alternation would compile to /^()$/, which matches ""
2022
+ return new RegExp(vals.length
2023
+ ? `^(${vals
2024
+ .map((o) => typeof o === "string" ? util.escapeRegex(o) : o ? util.escapeRegex(o.toString()) : String(o))
2025
+ .join("|")})$`
2026
+ : "^[^\\s\\S]$");
2027
+ });
1934
2028
  inst._zod.parse = (payload, _ctx) => {
1935
2029
  const input = payload.value;
1936
2030
  if (values.has(input)) {
@@ -2294,22 +2388,67 @@ function handleReadonlyResult(payload) {
2294
2388
  payload.value = Object.freeze(payload.value);
2295
2389
  return payload;
2296
2390
  }
2391
+ // a leaf's pattern source with its own checks folded in: the last pattern-carrying check wins, else length bounds narrow the catch-all, else an integer format narrows the number form. the fold lives here instead of on `_zod.pattern` so a bundle without template literals never pays for it
2392
+ function leafPattern(schema) {
2393
+ const def = schema._zod.def;
2394
+ let pattern = def.pattern;
2395
+ let isInt = !!def.format?.includes("int");
2396
+ let minimum;
2397
+ let maximum;
2398
+ for (const ch of def.checks ?? []) {
2399
+ const d = ch._zod.def;
2400
+ if (d.pattern)
2401
+ pattern = d.pattern;
2402
+ isInt || (isInt = !!d.format?.includes("int"));
2403
+ const lo = d.minimum ?? d.length;
2404
+ const hi = d.maximum ?? d.length;
2405
+ if (lo !== undefined && (minimum === undefined || lo > minimum))
2406
+ minimum = lo;
2407
+ if (hi !== undefined && (maximum === undefined || hi < maximum))
2408
+ maximum = hi;
2409
+ }
2410
+ if (pattern)
2411
+ return pattern.source;
2412
+ // an empty range matches nothing at runtime, and `{8,5}` is not a legal quantifier
2413
+ if (minimum !== undefined && maximum !== undefined && minimum > maximum)
2414
+ return "(?!)";
2415
+ if (minimum !== undefined || maximum !== undefined)
2416
+ return regexes.string({ minimum, maximum }).source;
2417
+ const own = schema._zod.pattern;
2418
+ return (isInt && own === regexes.number ? regexes.integer : own)?.source;
2419
+ }
2420
+ // a part's pattern source. a wrapper's pattern embeds its inner pattern's source verbatim, so the folded form is substituted in place without knowing the wrapper's own composition; a union's options are joined the way the union builds its own pattern
2421
+ function partPattern(schema) {
2422
+ const def = schema._zod.def;
2423
+ const own = schema._zod.pattern?.source;
2424
+ // lazy resolves its inner on the internals, not the def
2425
+ const inner = def.innerType ?? schema._zod.innerType;
2426
+ if (inner) {
2427
+ const before = inner._zod.pattern?.source;
2428
+ const after = partPattern(inner);
2429
+ if (own && before && after && after !== before) {
2430
+ return own.replace(util.cleanRegex(before), () => util.cleanRegex(after));
2431
+ }
2432
+ return own;
2433
+ }
2434
+ if (def.options) {
2435
+ const sources = def.options.map(partPattern);
2436
+ if (sources.every(Boolean))
2437
+ return `^(${sources.map((s) => util.cleanRegex(s)).join("|")})$`;
2438
+ }
2439
+ return leafPattern(schema);
2440
+ }
2297
2441
  exports.$ZodTemplateLiteral = core.$constructor("$ZodTemplateLiteral", (inst, def) => {
2298
2442
  exports.$ZodType.init(inst, def);
2299
2443
  const regexParts = [];
2300
2444
  for (const part of def.parts) {
2301
2445
  if (typeof part === "object" && part !== null) {
2302
2446
  // is Zod schema
2303
- if (!part._zod.pattern) {
2304
- // if (!source)
2447
+ const source = partPattern(part);
2448
+ if (!source) {
2305
2449
  throw new Error(`Invalid template literal part, no pattern found: ${[...part._zod.traits].shift()}`);
2306
2450
  }
2307
- const source = part._zod.pattern instanceof RegExp ? part._zod.pattern.source : part._zod.pattern;
2308
- if (!source)
2309
- throw new Error(`Invalid template literal part: ${part._zod.traits}`);
2310
- const start = source.startsWith("^") ? 1 : 0;
2311
- const end = source.endsWith("$") ? source.length - 1 : source.length;
2312
- regexParts.push(source.slice(start, end));
2451
+ regexParts.push(util.cleanRegex(source));
2313
2452
  }
2314
2453
  else if (part === null || util.primitiveTypes.has(typeof part)) {
2315
2454
  regexParts.push(util.escapeRegex(`${part}`));
@@ -2479,3 +2618,83 @@ function handleRefineResult(result, payload, input, inst) {
2479
2618
  payload.issues.push(util.issue(_iss));
2480
2619
  }
2481
2620
  }
2621
+ // asserts in place: the child result's value is discarded, matching z.property(), because a nested object or array schema rebuilds its output even when nothing transformed
2622
+ function handlePropertiesResult(result, payload, key) {
2623
+ if (result.issues.length) {
2624
+ payload.issues.push(...util.prefixIssues(key, result.issues));
2625
+ }
2626
+ }
2627
+ exports.$ZodProperties = core.$constructor("$ZodProperties", (inst, def) => {
2628
+ // $ZodType.init prepends an instance that already carries the $ZodCheck trait to its own `checks`, which would run the shape a second time and cost the parse context. Initializing the check trait after it keeps the schema role in `parse`, where the context arrives.
2629
+ exports.$ZodType.init(inst, def);
2630
+ checks.$ZodCheck.init(inst, def);
2631
+ const memo = core.globalConfig.memoizer;
2632
+ memo?.attach(inst);
2633
+ // key and schema snapshotted together: reading one live and the other cached lets a later mutation of the caller's shape object pair a stale key with a missing schema
2634
+ let entries;
2635
+ const runShape = (payload, ctx) => {
2636
+ entries ?? (entries = Reflect.ownKeys(def.shape).map((key) => [key, def.shape[key]]));
2637
+ const input = payload.value;
2638
+ let proms;
2639
+ for (const [key, schema] of entries) {
2640
+ const result = schema._zod.run({ value: input[key], issues: [] }, ctx);
2641
+ if (result instanceof Promise) {
2642
+ proms ?? (proms = []);
2643
+ proms.push(result.then((result) => handlePropertiesResult(result, payload, key)));
2644
+ }
2645
+ else {
2646
+ handlePropertiesResult(result, payload, key);
2647
+ }
2648
+ }
2649
+ if (proms)
2650
+ return Promise.all(proms).then(() => undefined);
2651
+ return undefined;
2652
+ };
2653
+ inst._zod.parse = (payload, ctx) => {
2654
+ const input = payload.value;
2655
+ // as a schema this is the type gate, and it infers an object shape, so a primitive is a type error. A function passes: its properties read like any other object's, and z.instanceof allows one.
2656
+ if (input === null || (typeof input !== "object" && typeof input !== "function")) {
2657
+ payload.issues.push({ expected: "object", code: "invalid_type", input, inst });
2658
+ return payload;
2659
+ }
2660
+ // both sides declare the shape's input type, so the assertion runs forward in either direction; encoding the children backward would reject the very type this schema claims to take
2661
+ if (ctx.direction === "backward")
2662
+ ctx = { ...ctx, direction: "forward" };
2663
+ // the input is its own output here, so it registers as its own memo entry: a cycle re-entering this node hits the bucket instead of recursing forever
2664
+ if (memo)
2665
+ memo.alloc(inst, payload, input, ctx);
2666
+ const result = runShape(payload, ctx);
2667
+ return result instanceof Promise ? result.then(() => payload) : payload;
2668
+ };
2669
+ // as a check the base schema already typed the value, so this only asserts the properties — which read on a primitive too, matching z.property() on a string's length. It gets no context of its own, so a cycle through a spread schema is not tracked.
2670
+ inst._zod.check = (payload) => {
2671
+ if (payload.value == null) {
2672
+ payload.issues.push({ expected: "object", code: "invalid_type", input: payload.value, inst });
2673
+ return undefined;
2674
+ }
2675
+ return runShape(payload, {});
2676
+ };
2677
+ }, {
2678
+ *[Symbol.iterator]() {
2679
+ yield this;
2680
+ },
2681
+ });
2682
+
2683
+ // seal-cjs-exports
2684
+ (function () {
2685
+ var keys = Object.getOwnPropertyNames(exports);
2686
+ for (var i = 0; i < keys.length; i++) {
2687
+ var desc = Object.getOwnPropertyDescriptor(exports, keys[i]);
2688
+ if (!desc || !desc.get || !desc.configurable) continue;
2689
+ var value;
2690
+ try {
2691
+ value = desc.get();
2692
+ } catch (e) {
2693
+ continue;
2694
+ }
2695
+ // a circular require may not have settled this one yet, so leave it live
2696
+ if (value === undefined) continue;
2697
+ Object.defineProperty(exports, keys[i], { value: value, writable: false, enumerable: desc.enumerable, configurable: false });
2698
+ }
2699
+ Object.freeze(exports);
2700
+ })();