zod 3.26.0-canary.20250703T011142 → 3.26.0-canary.20250703T025502

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 (269) hide show
  1. package/package.json +4 -4
  2. package/src/index.ts +4 -0
  3. package/src/v3/ZodError.ts +330 -0
  4. package/src/v3/benchmarks/datetime.ts +58 -0
  5. package/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  6. package/src/v3/benchmarks/index.ts +59 -0
  7. package/src/v3/benchmarks/ipv4.ts +57 -0
  8. package/src/v3/benchmarks/object.ts +69 -0
  9. package/src/v3/benchmarks/primitives.ts +162 -0
  10. package/src/v3/benchmarks/realworld.ts +63 -0
  11. package/src/v3/benchmarks/string.ts +55 -0
  12. package/src/v3/benchmarks/union.ts +80 -0
  13. package/src/v3/errors.ts +13 -0
  14. package/src/v3/external.ts +6 -0
  15. package/src/v3/helpers/enumUtil.ts +17 -0
  16. package/src/v3/helpers/errorUtil.ts +8 -0
  17. package/src/v3/helpers/parseUtil.ts +176 -0
  18. package/src/v3/helpers/partialUtil.ts +34 -0
  19. package/src/v3/helpers/typeAliases.ts +2 -0
  20. package/src/v3/helpers/util.ts +224 -0
  21. package/src/v3/index.ts +4 -0
  22. package/src/v3/locales/en.ts +124 -0
  23. package/src/v3/standard-schema.ts +113 -0
  24. package/src/v3/tests/Mocker.ts +54 -0
  25. package/src/v3/tests/all-errors.test.ts +157 -0
  26. package/src/v3/tests/anyunknown.test.ts +28 -0
  27. package/src/v3/tests/array.test.ts +71 -0
  28. package/src/v3/tests/async-parsing.test.ts +388 -0
  29. package/src/v3/tests/async-refinements.test.ts +46 -0
  30. package/src/v3/tests/base.test.ts +29 -0
  31. package/src/v3/tests/bigint.test.ts +55 -0
  32. package/src/v3/tests/branded.test.ts +53 -0
  33. package/src/v3/tests/catch.test.ts +220 -0
  34. package/src/v3/tests/coerce.test.ts +133 -0
  35. package/src/v3/tests/complex.test.ts +56 -0
  36. package/src/v3/tests/custom.test.ts +31 -0
  37. package/src/v3/tests/date.test.ts +32 -0
  38. package/src/v3/tests/deepmasking.test.ts +186 -0
  39. package/src/v3/tests/default.test.ts +112 -0
  40. package/src/v3/tests/description.test.ts +33 -0
  41. package/src/v3/tests/discriminated-unions.test.ts +315 -0
  42. package/src/v3/tests/enum.test.ts +80 -0
  43. package/src/v3/tests/error.test.ts +551 -0
  44. package/src/v3/tests/firstparty.test.ts +87 -0
  45. package/src/v3/tests/firstpartyschematypes.test.ts +21 -0
  46. package/src/v3/tests/function.test.ts +257 -0
  47. package/src/v3/tests/generics.test.ts +48 -0
  48. package/src/v3/tests/instanceof.test.ts +37 -0
  49. package/src/v3/tests/intersection.test.ts +110 -0
  50. package/src/v3/tests/language-server.source.ts +76 -0
  51. package/src/v3/tests/language-server.test.ts +207 -0
  52. package/src/v3/tests/literal.test.ts +36 -0
  53. package/src/v3/tests/map.test.ts +110 -0
  54. package/src/v3/tests/masking.test.ts +4 -0
  55. package/src/v3/tests/mocker.test.ts +19 -0
  56. package/src/v3/tests/nan.test.ts +21 -0
  57. package/src/v3/tests/nativeEnum.test.ts +87 -0
  58. package/src/v3/tests/nullable.test.ts +42 -0
  59. package/src/v3/tests/number.test.ts +176 -0
  60. package/src/v3/tests/object-augmentation.test.ts +29 -0
  61. package/src/v3/tests/object-in-es5-env.test.ts +29 -0
  62. package/src/v3/tests/object.test.ts +434 -0
  63. package/src/v3/tests/optional.test.ts +42 -0
  64. package/src/v3/tests/parseUtil.test.ts +23 -0
  65. package/src/v3/tests/parser.test.ts +41 -0
  66. package/src/v3/tests/partials.test.ts +243 -0
  67. package/src/v3/tests/pickomit.test.ts +111 -0
  68. package/src/v3/tests/pipeline.test.ts +29 -0
  69. package/src/v3/tests/preprocess.test.ts +186 -0
  70. package/src/v3/tests/primitive.test.ts +440 -0
  71. package/src/v3/tests/promise.test.ts +90 -0
  72. package/src/v3/tests/readonly.test.ts +194 -0
  73. package/src/v3/tests/record.test.ts +171 -0
  74. package/src/v3/tests/recursive.test.ts +197 -0
  75. package/src/v3/tests/refine.test.ts +313 -0
  76. package/src/v3/tests/safeparse.test.ts +27 -0
  77. package/src/v3/tests/set.test.ts +142 -0
  78. package/src/v3/tests/standard-schema.test.ts +83 -0
  79. package/src/v3/tests/string.test.ts +916 -0
  80. package/src/v3/tests/transformer.test.ts +233 -0
  81. package/src/v3/tests/tuple.test.ts +90 -0
  82. package/src/v3/tests/unions.test.ts +57 -0
  83. package/src/v3/tests/validations.test.ts +133 -0
  84. package/src/v3/tests/void.test.ts +15 -0
  85. package/src/v3/types.ts +5136 -0
  86. package/src/v4/classic/checks.ts +30 -0
  87. package/src/v4/classic/coerce.ts +27 -0
  88. package/src/v4/classic/compat.ts +66 -0
  89. package/src/v4/classic/errors.ts +75 -0
  90. package/src/v4/classic/external.ts +50 -0
  91. package/src/v4/classic/index.ts +5 -0
  92. package/src/v4/classic/iso.ts +90 -0
  93. package/src/v4/classic/parse.ts +33 -0
  94. package/src/v4/classic/schemas.ts +2055 -0
  95. package/src/v4/classic/tests/anyunknown.test.ts +26 -0
  96. package/src/v4/classic/tests/array.test.ts +264 -0
  97. package/src/v4/classic/tests/assignability.test.ts +210 -0
  98. package/src/v4/classic/tests/async-parsing.test.ts +381 -0
  99. package/src/v4/classic/tests/async-refinements.test.ts +68 -0
  100. package/src/v4/classic/tests/base.test.ts +7 -0
  101. package/src/v4/classic/tests/bigint.test.ts +54 -0
  102. package/src/v4/classic/tests/brand.test.ts +65 -0
  103. package/src/v4/classic/tests/catch.test.ts +252 -0
  104. package/src/v4/classic/tests/coalesce.test.ts +20 -0
  105. package/src/v4/classic/tests/coerce.test.ts +160 -0
  106. package/src/v4/classic/tests/continuability.test.ts +352 -0
  107. package/src/v4/classic/tests/custom.test.ts +40 -0
  108. package/src/v4/classic/tests/date.test.ts +31 -0
  109. package/src/v4/classic/tests/datetime.test.ts +296 -0
  110. package/src/v4/classic/tests/default.test.ts +313 -0
  111. package/src/v4/classic/tests/description.test.ts +32 -0
  112. package/src/v4/classic/tests/discriminated-unions.test.ts +592 -0
  113. package/src/v4/classic/tests/enum.test.ts +285 -0
  114. package/src/v4/classic/tests/error-utils.test.ts +527 -0
  115. package/src/v4/classic/tests/error.test.ts +711 -0
  116. package/src/v4/classic/tests/file.test.ts +91 -0
  117. package/src/v4/classic/tests/firstparty.test.ts +175 -0
  118. package/src/v4/classic/tests/function.test.ts +268 -0
  119. package/src/v4/classic/tests/generics.test.ts +72 -0
  120. package/src/v4/classic/tests/index.test.ts +829 -0
  121. package/src/v4/classic/tests/instanceof.test.ts +34 -0
  122. package/src/v4/classic/tests/intersection.test.ts +171 -0
  123. package/src/v4/classic/tests/json.test.ts +108 -0
  124. package/src/v4/classic/tests/lazy.test.ts +227 -0
  125. package/src/v4/classic/tests/literal.test.ts +92 -0
  126. package/src/v4/classic/tests/map.test.ts +196 -0
  127. package/src/v4/classic/tests/nan.test.ts +21 -0
  128. package/src/v4/classic/tests/nested-refine.test.ts +168 -0
  129. package/src/v4/classic/tests/nonoptional.test.ts +86 -0
  130. package/src/v4/classic/tests/nullable.test.ts +22 -0
  131. package/src/v4/classic/tests/number.test.ts +247 -0
  132. package/src/v4/classic/tests/object.test.ts +553 -0
  133. package/src/v4/classic/tests/optional.test.ts +103 -0
  134. package/src/v4/classic/tests/partial.test.ts +147 -0
  135. package/src/v4/classic/tests/pickomit.test.ts +127 -0
  136. package/src/v4/classic/tests/pipe.test.ts +81 -0
  137. package/src/v4/classic/tests/prefault.test.ts +37 -0
  138. package/src/v4/classic/tests/preprocess.test.ts +298 -0
  139. package/src/v4/classic/tests/primitive.test.ts +175 -0
  140. package/src/v4/classic/tests/promise.test.ts +81 -0
  141. package/src/v4/classic/tests/prototypes.test.ts +23 -0
  142. package/src/v4/classic/tests/readonly.test.ts +252 -0
  143. package/src/v4/classic/tests/record.test.ts +332 -0
  144. package/src/v4/classic/tests/recursive-types.test.ts +325 -0
  145. package/src/v4/classic/tests/refine.test.ts +423 -0
  146. package/src/v4/classic/tests/registries.test.ts +195 -0
  147. package/src/v4/classic/tests/set.test.ts +179 -0
  148. package/src/v4/classic/tests/standard-schema.test.ts +57 -0
  149. package/src/v4/classic/tests/string-formats.test.ts +109 -0
  150. package/src/v4/classic/tests/string.test.ts +881 -0
  151. package/src/v4/classic/tests/stringbool.test.ts +66 -0
  152. package/src/v4/classic/tests/template-literal.test.ts +758 -0
  153. package/src/v4/classic/tests/to-json-schema.test.ts +2182 -0
  154. package/src/v4/classic/tests/transform.test.ts +250 -0
  155. package/src/v4/classic/tests/tuple.test.ts +163 -0
  156. package/src/v4/classic/tests/union.test.ts +94 -0
  157. package/src/v4/classic/tests/validations.test.ts +283 -0
  158. package/src/v4/classic/tests/void.test.ts +12 -0
  159. package/src/v4/core/api.ts +1592 -0
  160. package/src/v4/core/checks.ts +1285 -0
  161. package/src/v4/core/config.ts +15 -0
  162. package/src/v4/core/core.ts +134 -0
  163. package/src/v4/core/doc.ts +44 -0
  164. package/src/v4/core/errors.ts +420 -0
  165. package/src/v4/core/function.ts +176 -0
  166. package/src/v4/core/index.ts +15 -0
  167. package/src/v4/core/json-schema.ts +143 -0
  168. package/src/v4/core/parse.ts +94 -0
  169. package/src/v4/core/regexes.ts +135 -0
  170. package/src/v4/core/registries.ts +86 -0
  171. package/src/v4/core/schemas.ts +3781 -0
  172. package/src/v4/core/standard-schema.ts +64 -0
  173. package/src/v4/core/tests/index.test.ts +46 -0
  174. package/src/v4/core/tests/locales/be.test.ts +124 -0
  175. package/src/v4/core/tests/locales/en.test.ts +22 -0
  176. package/src/v4/core/tests/locales/ru.test.ts +128 -0
  177. package/src/v4/core/tests/locales/tr.test.ts +69 -0
  178. package/src/v4/core/to-json-schema.ts +944 -0
  179. package/src/v4/core/util.ts +775 -0
  180. package/src/v4/core/versions.ts +5 -0
  181. package/src/v4/core/zsf.ts +323 -0
  182. package/src/v4/index.ts +4 -0
  183. package/src/v4/locales/ar.ts +125 -0
  184. package/src/v4/locales/az.ts +121 -0
  185. package/src/v4/locales/be.ts +184 -0
  186. package/src/v4/locales/ca.ts +127 -0
  187. package/src/v4/locales/cs.ts +142 -0
  188. package/src/v4/locales/de.ts +124 -0
  189. package/src/v4/locales/en.ts +127 -0
  190. package/src/v4/locales/es.ts +125 -0
  191. package/src/v4/locales/fa.ts +134 -0
  192. package/src/v4/locales/fi.ts +131 -0
  193. package/src/v4/locales/fr-CA.ts +126 -0
  194. package/src/v4/locales/fr.ts +124 -0
  195. package/src/v4/locales/he.ts +125 -0
  196. package/src/v4/locales/hu.ts +126 -0
  197. package/src/v4/locales/id.ts +125 -0
  198. package/src/v4/locales/index.ts +38 -0
  199. package/src/v4/locales/it.ts +125 -0
  200. package/src/v4/locales/ja.ts +122 -0
  201. package/src/v4/locales/kh.ts +126 -0
  202. package/src/v4/locales/ko.ts +131 -0
  203. package/src/v4/locales/mk.ts +127 -0
  204. package/src/v4/locales/ms.ts +124 -0
  205. package/src/v4/locales/nl.ts +126 -0
  206. package/src/v4/locales/no.ts +124 -0
  207. package/src/v4/locales/ota.ts +125 -0
  208. package/src/v4/locales/pl.ts +126 -0
  209. package/src/v4/locales/ps.ts +133 -0
  210. package/src/v4/locales/pt.ts +123 -0
  211. package/src/v4/locales/ru.ts +184 -0
  212. package/src/v4/locales/sl.ts +126 -0
  213. package/src/v4/locales/sv.ts +127 -0
  214. package/src/v4/locales/ta.ts +125 -0
  215. package/src/v4/locales/th.ts +126 -0
  216. package/src/v4/locales/tr.ts +121 -0
  217. package/src/v4/locales/ua.ts +126 -0
  218. package/src/v4/locales/ur.ts +126 -0
  219. package/src/v4/locales/vi.ts +125 -0
  220. package/src/v4/locales/zh-CN.ts +123 -0
  221. package/src/v4/locales/zh-TW.ts +125 -0
  222. package/src/v4/mini/checks.ts +32 -0
  223. package/src/v4/mini/coerce.ts +22 -0
  224. package/src/v4/mini/external.ts +40 -0
  225. package/src/v4/mini/index.ts +3 -0
  226. package/src/v4/mini/iso.ts +62 -0
  227. package/src/v4/mini/parse.ts +1 -0
  228. package/src/v4/mini/schemas.ts +1579 -0
  229. package/src/v4/mini/tests/assignability.test.ts +129 -0
  230. package/src/v4/mini/tests/brand.test.ts +51 -0
  231. package/src/v4/mini/tests/checks.test.ts +144 -0
  232. package/src/v4/mini/tests/computed.test.ts +36 -0
  233. package/src/v4/mini/tests/error.test.ts +22 -0
  234. package/src/v4/mini/tests/functions.test.ts +43 -0
  235. package/src/v4/mini/tests/index.test.ts +871 -0
  236. package/src/v4/mini/tests/number.test.ts +95 -0
  237. package/src/v4/mini/tests/object.test.ts +185 -0
  238. package/src/v4/mini/tests/prototypes.test.ts +43 -0
  239. package/src/v4/mini/tests/recursive-types.test.ts +275 -0
  240. package/src/v4/mini/tests/string.test.ts +293 -0
  241. package/src/v4-mini/index.ts +1 -0
  242. package/v4/classic/compat.cjs +1 -7
  243. package/v4/classic/compat.d.cts +0 -2
  244. package/v4/classic/compat.d.ts +0 -2
  245. package/v4/classic/compat.js +0 -6
  246. package/v4/classic/external.cjs +2 -1
  247. package/v4/classic/external.d.cts +1 -1
  248. package/v4/classic/external.d.ts +1 -1
  249. package/v4/classic/external.js +1 -1
  250. package/v4/classic/schemas.d.cts +4 -4
  251. package/v4/classic/schemas.d.ts +4 -4
  252. package/v4/core/api.cjs +11 -10
  253. package/v4/core/api.js +11 -10
  254. package/v4/core/checks.cjs +6 -4
  255. package/v4/core/checks.js +6 -4
  256. package/v4/core/core.cjs +5 -1
  257. package/v4/core/core.d.cts +2 -0
  258. package/v4/core/core.d.ts +2 -0
  259. package/v4/core/core.js +4 -0
  260. package/v4/core/schemas.cjs +12 -13
  261. package/v4/core/schemas.js +12 -13
  262. package/v4/core/util.cjs +3 -0
  263. package/v4/core/util.d.cts +1 -1
  264. package/v4/core/util.d.ts +1 -1
  265. package/v4/core/util.js +3 -0
  266. package/v4/mini/external.cjs +2 -1
  267. package/v4/mini/external.d.cts +1 -1
  268. package/v4/mini/external.d.ts +1 -1
  269. package/v4/mini/external.js +1 -1
package/v4/core/core.js CHANGED
@@ -1,3 +1,7 @@
1
+ /** A special constant with type `never` */
2
+ export const NEVER = Object.freeze({
3
+ status: "aborted",
4
+ });
1
5
  export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) {
2
6
  function init(inst, def) {
3
7
  var _a;
@@ -512,13 +512,12 @@ exports.$ZodBigInt = core.$constructor("$ZodBigInt", (inst, def) => {
512
512
  payload.value = BigInt(payload.value);
513
513
  }
514
514
  catch (_) { }
515
- const { value: input } = payload;
516
- if (typeof input === "bigint")
515
+ if (typeof payload.value === "bigint")
517
516
  return payload;
518
517
  payload.issues.push({
519
518
  expected: "bigint",
520
519
  code: "invalid_type",
521
- input,
520
+ input: payload.value,
522
521
  inst,
523
522
  });
524
523
  return payload;
@@ -531,7 +530,7 @@ exports.$ZodBigIntFormat = core.$constructor("$ZodBigInt", (inst, def) => {
531
530
  exports.$ZodSymbol = core.$constructor("$ZodSymbol", (inst, def) => {
532
531
  exports.$ZodType.init(inst, def);
533
532
  inst._zod.parse = (payload, _ctx) => {
534
- const { value: input } = payload;
533
+ const input = payload.value;
535
534
  if (typeof input === "symbol")
536
535
  return payload;
537
536
  payload.issues.push({
@@ -548,7 +547,7 @@ exports.$ZodUndefined = core.$constructor("$ZodUndefined", (inst, def) => {
548
547
  inst._zod.pattern = regexes.undefined;
549
548
  inst._zod.values = new Set([undefined]);
550
549
  inst._zod.parse = (payload, _ctx) => {
551
- const { value: input } = payload;
550
+ const input = payload.value;
552
551
  if (typeof input === "undefined")
553
552
  return payload;
554
553
  payload.issues.push({
@@ -565,7 +564,7 @@ exports.$ZodNull = core.$constructor("$ZodNull", (inst, def) => {
565
564
  inst._zod.pattern = regexes.null;
566
565
  inst._zod.values = new Set([null]);
567
566
  inst._zod.parse = (payload, _ctx) => {
568
- const { value: input } = payload;
567
+ const input = payload.value;
569
568
  if (input === null)
570
569
  return payload;
571
570
  payload.issues.push({
@@ -600,7 +599,7 @@ exports.$ZodNever = core.$constructor("$ZodNever", (inst, def) => {
600
599
  exports.$ZodVoid = core.$constructor("$ZodVoid", (inst, def) => {
601
600
  exports.$ZodType.init(inst, def);
602
601
  inst._zod.parse = (payload, _ctx) => {
603
- const { value: input } = payload;
602
+ const input = payload.value;
604
603
  if (typeof input === "undefined")
605
604
  return payload;
606
605
  payload.issues.push({
@@ -743,20 +742,20 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
743
742
  });
744
743
  const generateFastpass = (shape) => {
745
744
  const doc = new doc_js_1.Doc(["shape", "payload", "ctx"]);
746
- const { keys, optionalKeys } = _normalized.value;
745
+ const normalized = _normalized.value;
747
746
  const parseStr = (key) => {
748
747
  const k = util.esc(key);
749
748
  return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
750
749
  };
751
750
  doc.write(`const input = payload.value;`);
752
751
  const ids = Object.create(null);
753
- for (const key of keys) {
752
+ for (const key of normalized.keys) {
754
753
  ids[key] = util.randomString(15);
755
754
  }
756
755
  // A: preserve key order {
757
756
  doc.write(`const newResult = {}`);
758
- for (const key of keys) {
759
- if (optionalKeys.has(key)) {
757
+ for (const key of normalized.keys) {
758
+ if (normalized.optionalKeys.has(key)) {
760
759
  const id = ids[key];
761
760
  doc.write(`const ${id} = ${parseStr(key)};`);
762
761
  const k = util.esc(key);
@@ -803,7 +802,7 @@ exports.$ZodObject = core.$constructor("$ZodObject", (inst, def) => {
803
802
  const jit = !core.globalConfig.jitless;
804
803
  const allowsEval = util.allowsEval;
805
804
  const fastEnabled = jit && allowsEval.value; // && !def.catchall;
806
- const { catchall } = def;
805
+ const catchall = def.catchall;
807
806
  let value;
808
807
  inst._zod.parse = (payload, ctx) => {
809
808
  value ?? (value = _normalized.value);
@@ -1018,7 +1017,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1018
1017
  exports.$ZodIntersection = core.$constructor("$ZodIntersection", (inst, def) => {
1019
1018
  exports.$ZodType.init(inst, def);
1020
1019
  inst._zod.parse = (payload, ctx) => {
1021
- const { value: input } = payload;
1020
+ const input = payload.value;
1022
1021
  const left = def.left._zod.run({ value: input, issues: [] }, ctx);
1023
1022
  const right = def.right._zod.run({ value: input, issues: [] }, ctx);
1024
1023
  const async = left instanceof Promise || right instanceof Promise;
@@ -481,13 +481,12 @@ export const $ZodBigInt = /*@__PURE__*/ core.$constructor("$ZodBigInt", (inst, d
481
481
  payload.value = BigInt(payload.value);
482
482
  }
483
483
  catch (_) { }
484
- const { value: input } = payload;
485
- if (typeof input === "bigint")
484
+ if (typeof payload.value === "bigint")
486
485
  return payload;
487
486
  payload.issues.push({
488
487
  expected: "bigint",
489
488
  code: "invalid_type",
490
- input,
489
+ input: payload.value,
491
490
  inst,
492
491
  });
493
492
  return payload;
@@ -500,7 +499,7 @@ export const $ZodBigIntFormat = /*@__PURE__*/ core.$constructor("$ZodBigInt", (i
500
499
  export const $ZodSymbol = /*@__PURE__*/ core.$constructor("$ZodSymbol", (inst, def) => {
501
500
  $ZodType.init(inst, def);
502
501
  inst._zod.parse = (payload, _ctx) => {
503
- const { value: input } = payload;
502
+ const input = payload.value;
504
503
  if (typeof input === "symbol")
505
504
  return payload;
506
505
  payload.issues.push({
@@ -517,7 +516,7 @@ export const $ZodUndefined = /*@__PURE__*/ core.$constructor("$ZodUndefined", (i
517
516
  inst._zod.pattern = regexes.undefined;
518
517
  inst._zod.values = new Set([undefined]);
519
518
  inst._zod.parse = (payload, _ctx) => {
520
- const { value: input } = payload;
519
+ const input = payload.value;
521
520
  if (typeof input === "undefined")
522
521
  return payload;
523
522
  payload.issues.push({
@@ -534,7 +533,7 @@ export const $ZodNull = /*@__PURE__*/ core.$constructor("$ZodNull", (inst, def)
534
533
  inst._zod.pattern = regexes.null;
535
534
  inst._zod.values = new Set([null]);
536
535
  inst._zod.parse = (payload, _ctx) => {
537
- const { value: input } = payload;
536
+ const input = payload.value;
538
537
  if (input === null)
539
538
  return payload;
540
539
  payload.issues.push({
@@ -569,7 +568,7 @@ export const $ZodNever = /*@__PURE__*/ core.$constructor("$ZodNever", (inst, def
569
568
  export const $ZodVoid = /*@__PURE__*/ core.$constructor("$ZodVoid", (inst, def) => {
570
569
  $ZodType.init(inst, def);
571
570
  inst._zod.parse = (payload, _ctx) => {
572
- const { value: input } = payload;
571
+ const input = payload.value;
573
572
  if (typeof input === "undefined")
574
573
  return payload;
575
574
  payload.issues.push({
@@ -712,20 +711,20 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
712
711
  });
713
712
  const generateFastpass = (shape) => {
714
713
  const doc = new Doc(["shape", "payload", "ctx"]);
715
- const { keys, optionalKeys } = _normalized.value;
714
+ const normalized = _normalized.value;
716
715
  const parseStr = (key) => {
717
716
  const k = util.esc(key);
718
717
  return `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
719
718
  };
720
719
  doc.write(`const input = payload.value;`);
721
720
  const ids = Object.create(null);
722
- for (const key of keys) {
721
+ for (const key of normalized.keys) {
723
722
  ids[key] = util.randomString(15);
724
723
  }
725
724
  // A: preserve key order {
726
725
  doc.write(`const newResult = {}`);
727
- for (const key of keys) {
728
- if (optionalKeys.has(key)) {
726
+ for (const key of normalized.keys) {
727
+ if (normalized.optionalKeys.has(key)) {
729
728
  const id = ids[key];
730
729
  doc.write(`const ${id} = ${parseStr(key)};`);
731
730
  const k = util.esc(key);
@@ -772,7 +771,7 @@ export const $ZodObject = /*@__PURE__*/ core.$constructor("$ZodObject", (inst, d
772
771
  const jit = !core.globalConfig.jitless;
773
772
  const allowsEval = util.allowsEval;
774
773
  const fastEnabled = jit && allowsEval.value; // && !def.catchall;
775
- const { catchall } = def;
774
+ const catchall = def.catchall;
776
775
  let value;
777
776
  inst._zod.parse = (payload, ctx) => {
778
777
  value ?? (value = _normalized.value);
@@ -987,7 +986,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
987
986
  export const $ZodIntersection = /*@__PURE__*/ core.$constructor("$ZodIntersection", (inst, def) => {
988
987
  $ZodType.init(inst, def);
989
988
  inst._zod.parse = (payload, ctx) => {
990
- const { value: input } = payload;
989
+ const input = payload.value;
991
990
  const left = def.left._zod.run({ value: input, issues: [] }, ctx);
992
991
  const right = def.right._zod.run({ value: input, issues: [] }, ctx);
993
992
  const async = left instanceof Promise || right instanceof Promise;
package/v4/core/util.cjs CHANGED
@@ -364,6 +364,9 @@ function omit(schema, mask) {
364
364
  });
365
365
  }
366
366
  function extend(schema, shape) {
367
+ if (!isPlainObject(shape)) {
368
+ throw new Error("Invalid input to extend: expected a plain object");
369
+ }
367
370
  const def = {
368
371
  ...schema._zod.def,
369
372
  get shape() {
@@ -127,7 +127,7 @@ export declare function promiseAllObject<T extends object>(promisesObj: T): Prom
127
127
  }>;
128
128
  export declare function randomString(length?: number): string;
129
129
  export declare function esc(str: string): string;
130
- export declare const captureStackTrace: typeof Error.captureStackTrace;
130
+ export declare const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void;
131
131
  export declare function isObject(data: any): data is Record<PropertyKey, unknown>;
132
132
  export declare const allowsEval: {
133
133
  value: boolean;
package/v4/core/util.d.ts CHANGED
@@ -127,7 +127,7 @@ export declare function promiseAllObject<T extends object>(promisesObj: T): Prom
127
127
  }>;
128
128
  export declare function randomString(length?: number): string;
129
129
  export declare function esc(str: string): string;
130
- export declare const captureStackTrace: typeof Error.captureStackTrace;
130
+ export declare const captureStackTrace: (targetObject: object, constructorOpt?: Function) => void;
131
131
  export declare function isObject(data: any): data is Record<PropertyKey, unknown>;
132
132
  export declare const allowsEval: {
133
133
  value: boolean;
package/v4/core/util.js CHANGED
@@ -319,6 +319,9 @@ export function omit(schema, mask) {
319
319
  });
320
320
  }
321
321
  export function extend(schema, shape) {
322
+ if (!isPlainObject(shape)) {
323
+ throw new Error("Invalid input to extend: expected a plain object");
324
+ }
322
325
  const def = {
323
326
  ...schema._zod.def,
324
327
  get shape() {
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
26
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.coerce = exports.ZodMiniISODuration = exports.ZodMiniISOTime = exports.ZodMiniISODate = exports.ZodMiniISODateTime = exports.iso = exports.locales = exports.TimePrecision = exports.toJSONSchema = exports.flattenError = exports.formatError = exports.prettifyError = exports.treeifyError = exports.regexes = exports.clone = exports.function = exports.$brand = exports.$input = exports.$output = exports.config = exports.registry = exports.globalRegistry = exports.core = void 0;
29
+ exports.coerce = exports.ZodMiniISODuration = exports.ZodMiniISOTime = exports.ZodMiniISODate = exports.ZodMiniISODateTime = exports.iso = exports.locales = exports.NEVER = exports.TimePrecision = exports.toJSONSchema = exports.flattenError = exports.formatError = exports.prettifyError = exports.treeifyError = exports.regexes = exports.clone = exports.function = exports.$brand = exports.$input = exports.$output = exports.config = exports.registry = exports.globalRegistry = exports.core = void 0;
30
30
  exports.core = __importStar(require("../core/index.cjs"));
31
31
  __exportStar(require("./parse.cjs"), exports);
32
32
  __exportStar(require("./schemas.cjs"), exports);
@@ -47,6 +47,7 @@ Object.defineProperty(exports, "formatError", { enumerable: true, get: function
47
47
  Object.defineProperty(exports, "flattenError", { enumerable: true, get: function () { return index_js_1.flattenError; } });
48
48
  Object.defineProperty(exports, "toJSONSchema", { enumerable: true, get: function () { return index_js_1.toJSONSchema; } });
49
49
  Object.defineProperty(exports, "TimePrecision", { enumerable: true, get: function () { return index_js_1.TimePrecision; } });
50
+ Object.defineProperty(exports, "NEVER", { enumerable: true, get: function () { return index_js_1.NEVER; } });
50
51
  exports.locales = __importStar(require("../locales/index.cjs"));
51
52
  /** A special constant with type `never` */
52
53
  // export const NEVER = {} as never;
@@ -3,7 +3,7 @@ export * from "./parse.cjs";
3
3
  export * from "./schemas.cjs";
4
4
  export * from "./checks.cjs";
5
5
  export type { infer, output, input } from "../core/index.cjs";
6
- export { globalRegistry, registry, config, $output, $input, $brand, function, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, } from "../core/index.cjs";
6
+ export { globalRegistry, registry, config, $output, $input, $brand, function, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, NEVER, } from "../core/index.cjs";
7
7
  export * as locales from "../locales/index.cjs";
8
8
  /** A special constant with type `never` */
9
9
  export * as iso from "./iso.cjs";
@@ -3,7 +3,7 @@ export * from "./parse.js";
3
3
  export * from "./schemas.js";
4
4
  export * from "./checks.js";
5
5
  export type { infer, output, input } from "../core/index.js";
6
- export { globalRegistry, registry, config, $output, $input, $brand, function, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, } from "../core/index.js";
6
+ export { globalRegistry, registry, config, $output, $input, $brand, function, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, NEVER, } from "../core/index.js";
7
7
  export * as locales from "../locales/index.js";
8
8
  /** A special constant with type `never` */
9
9
  export * as iso from "./iso.js";
@@ -2,7 +2,7 @@ export * as core from "../core/index.js";
2
2
  export * from "./parse.js";
3
3
  export * from "./schemas.js";
4
4
  export * from "./checks.js";
5
- export { globalRegistry, registry, config, $output, $input, $brand, function, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, } from "../core/index.js";
5
+ export { globalRegistry, registry, config, $output, $input, $brand, function, clone, regexes, treeifyError, prettifyError, formatError, flattenError, toJSONSchema, TimePrecision, NEVER, } from "../core/index.js";
6
6
  export * as locales from "../locales/index.js";
7
7
  /** A special constant with type `never` */
8
8
  // export const NEVER = {} as never;