zod 4.0.9 → 4.0.11

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 (134) hide show
  1. package/package.json +4 -4
  2. package/src/v4/classic/checks.ts +1 -0
  3. package/src/v4/classic/schemas.ts +12 -28
  4. package/src/v4/classic/tests/datetime.test.ts +6 -0
  5. package/src/v4/classic/tests/discriminated-unions.test.ts +1 -0
  6. package/src/v4/classic/tests/file.test.ts +5 -2
  7. package/src/v4/classic/tests/number.test.ts +23 -0
  8. package/src/v4/classic/tests/recursive-types.test.ts +39 -0
  9. package/src/v4/classic/tests/string.test.ts +38 -0
  10. package/src/v4/classic/tests/tuple.test.ts +2 -2
  11. package/src/v4/core/api.ts +51 -7
  12. package/src/v4/core/checks.ts +2 -0
  13. package/src/v4/core/errors.ts +27 -23
  14. package/src/v4/core/regexes.ts +7 -4
  15. package/src/v4/core/schemas.ts +44 -6
  16. package/src/v4/core/util.ts +11 -1
  17. package/src/v4/core/versions.ts +1 -1
  18. package/src/v4/locales/index.ts +1 -0
  19. package/src/v4/locales/yo.ts +131 -0
  20. package/src/v4/mini/schemas.ts +11 -0
  21. package/v3/locales/en.cjs +1 -0
  22. package/v3/locales/en.d.cts +1 -1
  23. package/v4/classic/checks.d.cts +1 -1
  24. package/v4/classic/checks.d.ts +1 -1
  25. package/v4/classic/schemas.cjs +5 -20
  26. package/v4/classic/schemas.d.cts +5 -7
  27. package/v4/classic/schemas.d.ts +5 -7
  28. package/v4/classic/schemas.js +4 -20
  29. package/v4/core/api.cjs +33 -7
  30. package/v4/core/api.d.cts +12 -0
  31. package/v4/core/api.d.ts +12 -0
  32. package/v4/core/api.js +31 -7
  33. package/v4/core/checks.cjs +2 -0
  34. package/v4/core/checks.js +2 -0
  35. package/v4/core/errors.d.cts +18 -16
  36. package/v4/core/errors.d.ts +18 -16
  37. package/v4/core/regexes.cjs +6 -5
  38. package/v4/core/regexes.d.cts +1 -0
  39. package/v4/core/regexes.d.ts +1 -0
  40. package/v4/core/regexes.js +5 -4
  41. package/v4/core/schemas.cjs +9 -3
  42. package/v4/core/schemas.d.cts +5 -3
  43. package/v4/core/schemas.d.ts +5 -3
  44. package/v4/core/schemas.js +9 -3
  45. package/v4/core/util.cjs +9 -1
  46. package/v4/core/util.js +9 -1
  47. package/v4/core/versions.cjs +1 -1
  48. package/v4/core/versions.js +1 -1
  49. package/v4/locales/ar.cjs +1 -0
  50. package/v4/locales/ar.d.cts +2 -1
  51. package/v4/locales/az.cjs +1 -0
  52. package/v4/locales/az.d.cts +2 -1
  53. package/v4/locales/be.cjs +1 -0
  54. package/v4/locales/be.d.cts +2 -1
  55. package/v4/locales/ca.cjs +1 -0
  56. package/v4/locales/ca.d.cts +2 -1
  57. package/v4/locales/cs.cjs +1 -0
  58. package/v4/locales/cs.d.cts +2 -1
  59. package/v4/locales/da.cjs +1 -0
  60. package/v4/locales/da.d.cts +2 -1
  61. package/v4/locales/de.cjs +1 -0
  62. package/v4/locales/de.d.cts +2 -1
  63. package/v4/locales/es.cjs +1 -0
  64. package/v4/locales/es.d.cts +2 -1
  65. package/v4/locales/fa.cjs +1 -0
  66. package/v4/locales/fa.d.cts +2 -1
  67. package/v4/locales/fi.cjs +1 -0
  68. package/v4/locales/fi.d.cts +2 -1
  69. package/v4/locales/fr-CA.cjs +1 -0
  70. package/v4/locales/fr-CA.d.cts +2 -1
  71. package/v4/locales/fr.cjs +1 -0
  72. package/v4/locales/fr.d.cts +2 -1
  73. package/v4/locales/he.cjs +1 -0
  74. package/v4/locales/he.d.cts +2 -1
  75. package/v4/locales/hu.cjs +1 -0
  76. package/v4/locales/hu.d.cts +2 -1
  77. package/v4/locales/id.cjs +1 -0
  78. package/v4/locales/id.d.cts +2 -1
  79. package/v4/locales/index.cjs +3 -1
  80. package/v4/locales/index.d.cts +1 -0
  81. package/v4/locales/index.d.ts +1 -0
  82. package/v4/locales/index.js +1 -0
  83. package/v4/locales/it.cjs +1 -0
  84. package/v4/locales/it.d.cts +2 -1
  85. package/v4/locales/ja.cjs +1 -0
  86. package/v4/locales/ja.d.cts +2 -1
  87. package/v4/locales/kh.cjs +1 -0
  88. package/v4/locales/kh.d.cts +2 -1
  89. package/v4/locales/ko.cjs +1 -0
  90. package/v4/locales/ko.d.cts +2 -1
  91. package/v4/locales/mk.cjs +1 -0
  92. package/v4/locales/mk.d.cts +2 -1
  93. package/v4/locales/ms.cjs +1 -0
  94. package/v4/locales/ms.d.cts +2 -1
  95. package/v4/locales/nl.cjs +1 -0
  96. package/v4/locales/nl.d.cts +2 -1
  97. package/v4/locales/no.cjs +1 -0
  98. package/v4/locales/no.d.cts +2 -1
  99. package/v4/locales/ota.cjs +1 -0
  100. package/v4/locales/ota.d.cts +2 -1
  101. package/v4/locales/pl.cjs +1 -0
  102. package/v4/locales/pl.d.cts +2 -1
  103. package/v4/locales/ps.cjs +1 -0
  104. package/v4/locales/ps.d.cts +2 -1
  105. package/v4/locales/pt.cjs +1 -0
  106. package/v4/locales/pt.d.cts +2 -1
  107. package/v4/locales/ru.cjs +1 -0
  108. package/v4/locales/ru.d.cts +2 -1
  109. package/v4/locales/sl.cjs +1 -0
  110. package/v4/locales/sl.d.cts +2 -1
  111. package/v4/locales/sv.cjs +1 -0
  112. package/v4/locales/sv.d.cts +2 -1
  113. package/v4/locales/ta.cjs +1 -0
  114. package/v4/locales/ta.d.cts +2 -1
  115. package/v4/locales/th.cjs +1 -0
  116. package/v4/locales/th.d.cts +2 -1
  117. package/v4/locales/ua.cjs +1 -0
  118. package/v4/locales/ua.d.cts +2 -1
  119. package/v4/locales/ur.cjs +1 -0
  120. package/v4/locales/ur.d.cts +2 -1
  121. package/v4/locales/vi.cjs +1 -0
  122. package/v4/locales/vi.d.cts +2 -1
  123. package/v4/locales/yo.cjs +142 -0
  124. package/v4/locales/yo.d.cts +5 -0
  125. package/v4/locales/yo.d.ts +4 -0
  126. package/v4/locales/yo.js +115 -0
  127. package/v4/locales/zh-CN.cjs +1 -0
  128. package/v4/locales/zh-CN.d.cts +2 -1
  129. package/v4/locales/zh-TW.cjs +1 -0
  130. package/v4/locales/zh-TW.d.cts +2 -1
  131. package/v4/mini/schemas.cjs +9 -0
  132. package/v4/mini/schemas.d.cts +2 -0
  133. package/v4/mini/schemas.d.ts +2 -0
  134. package/v4/mini/schemas.js +7 -0
@@ -319,6 +319,7 @@ export const $ZodString: core.$constructor<$ZodString> = /*@__PURE__*/ core.$con
319
319
  payload.issues.push({
320
320
  expected: "string",
321
321
  code: "invalid_type",
322
+
322
323
  input: payload.value,
323
324
  inst,
324
325
  });
@@ -1041,6 +1042,7 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
1041
1042
  payload.issues.push({
1042
1043
  expected: "number",
1043
1044
  code: "invalid_type",
1045
+
1044
1046
  input,
1045
1047
  inst,
1046
1048
  ...(received ? { received } : {}),
@@ -1111,6 +1113,7 @@ export const $ZodBoolean: core.$constructor<$ZodBoolean> = /*@__PURE__*/ core.$c
1111
1113
  payload.issues.push({
1112
1114
  expected: "boolean",
1113
1115
  code: "invalid_type",
1116
+
1114
1117
  input,
1115
1118
  inst,
1116
1119
  });
@@ -1163,6 +1166,7 @@ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$con
1163
1166
  payload.issues.push({
1164
1167
  expected: "bigint",
1165
1168
  code: "invalid_type",
1169
+
1166
1170
  input: payload.value,
1167
1171
  inst,
1168
1172
  });
@@ -1222,6 +1226,7 @@ export const $ZodSymbol: core.$constructor<$ZodSymbol> = /*@__PURE__*/ core.$con
1222
1226
  payload.issues.push({
1223
1227
  expected: "symbol",
1224
1228
  code: "invalid_type",
1229
+
1225
1230
  input,
1226
1231
  inst,
1227
1232
  });
@@ -1266,6 +1271,7 @@ export const $ZodUndefined: core.$constructor<$ZodUndefined> = /*@__PURE__*/ cor
1266
1271
  payload.issues.push({
1267
1272
  expected: "undefined",
1268
1273
  code: "invalid_type",
1274
+
1269
1275
  input,
1270
1276
  inst,
1271
1277
  });
@@ -1308,6 +1314,7 @@ export const $ZodNull: core.$constructor<$ZodNull> = /*@__PURE__*/ core.$constru
1308
1314
  payload.issues.push({
1309
1315
  expected: "null",
1310
1316
  code: "invalid_type",
1317
+
1311
1318
  input,
1312
1319
  inst,
1313
1320
  });
@@ -1399,6 +1406,7 @@ export const $ZodNever: core.$constructor<$ZodNever> = /*@__PURE__*/ core.$const
1399
1406
  payload.issues.push({
1400
1407
  expected: "never",
1401
1408
  code: "invalid_type",
1409
+
1402
1410
  input: payload.value,
1403
1411
  inst,
1404
1412
  });
@@ -1436,6 +1444,7 @@ export const $ZodVoid: core.$constructor<$ZodVoid> = /*@__PURE__*/ core.$constru
1436
1444
  payload.issues.push({
1437
1445
  expected: "void",
1438
1446
  code: "invalid_type",
1447
+
1439
1448
  input,
1440
1449
  inst,
1441
1450
  });
@@ -1486,6 +1495,7 @@ export const $ZodDate: core.$constructor<$ZodDate> = /*@__PURE__*/ core.$constru
1486
1495
  payload.issues.push({
1487
1496
  expected: "date",
1488
1497
  code: "invalid_type",
1498
+
1489
1499
  input,
1490
1500
  ...(isDate ? { received: "Invalid Date" } : {}),
1491
1501
  inst,
@@ -1535,6 +1545,7 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
1535
1545
  payload.issues.push({
1536
1546
  expected: "array",
1537
1547
  code: "invalid_type",
1548
+
1538
1549
  input,
1539
1550
  inst,
1540
1551
  });
@@ -1801,6 +1812,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1801
1812
  payload.issues.push({
1802
1813
  expected: "object",
1803
1814
  code: "invalid_type",
1815
+
1804
1816
  input,
1805
1817
  inst,
1806
1818
  });
@@ -1854,6 +1866,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
1854
1866
  if (unrecognized.length) {
1855
1867
  payload.issues.push({
1856
1868
  code: "unrecognized_keys",
1869
+
1857
1870
  keys: unrecognized,
1858
1871
  input,
1859
1872
  inst,
@@ -1918,6 +1931,7 @@ function handleUnionResults(results: ParsePayload[], final: ParsePayload, inst:
1918
1931
 
1919
1932
  final.issues.push({
1920
1933
  code: "invalid_union",
1934
+
1921
1935
  input: final.value,
1922
1936
  inst,
1923
1937
  errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
@@ -1952,7 +1966,13 @@ export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$const
1952
1966
  return undefined;
1953
1967
  });
1954
1968
 
1969
+ const single = def.options.length === 1;
1970
+ const first = def.options[0]._zod.run;
1971
+
1955
1972
  inst._zod.parse = (payload, ctx) => {
1973
+ if (single) {
1974
+ return first(payload, ctx);
1975
+ }
1956
1976
  let async = false;
1957
1977
 
1958
1978
  const results: util.MaybeAsync<ParsePayload>[] = [];
@@ -2048,6 +2068,7 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
2048
2068
  if (!util.isObject(input)) {
2049
2069
  payload.issues.push({
2050
2070
  code: "invalid_type",
2071
+
2051
2072
  expected: "object",
2052
2073
  input,
2053
2074
  inst,
@@ -2067,8 +2088,10 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
2067
2088
  // no matching discriminator
2068
2089
  payload.issues.push({
2069
2090
  code: "invalid_union",
2091
+
2070
2092
  errors: [],
2071
2093
  note: "No matching discriminator",
2094
+ discriminator: def.discriminator,
2072
2095
  input,
2073
2096
  path: [def.discriminator],
2074
2097
  inst,
@@ -2094,11 +2117,14 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
2094
2117
  }
2095
2118
 
2096
2119
  export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
2097
- extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
2120
+ extends _$ZodTypeInternals {
2121
+ // $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>>
2098
2122
  def: $ZodIntersectionDef<A, B>;
2099
2123
  isst: never;
2100
2124
  optin: A["_zod"]["optin"] | B["_zod"]["optin"];
2101
2125
  optout: A["_zod"]["optout"] | B["_zod"]["optout"];
2126
+ output: core.output<A> & core.output<B>;
2127
+ input: core.input<A> & core.input<B>;
2102
2128
  }
2103
2129
 
2104
2130
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
@@ -2293,10 +2319,11 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
2293
2319
  const tooSmall = input.length < optStart - 1;
2294
2320
  if (tooBig || tooSmall) {
2295
2321
  payload.issues.push({
2322
+ ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
2323
+
2296
2324
  input,
2297
2325
  inst,
2298
2326
  origin: "array" as const,
2299
- ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
2300
2327
  });
2301
2328
  return payload;
2302
2329
  }
@@ -2431,6 +2458,7 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2431
2458
  payload.issues.push({
2432
2459
  expected: "record",
2433
2460
  code: "invalid_type",
2461
+
2434
2462
  input,
2435
2463
  inst,
2436
2464
  });
@@ -2474,6 +2502,7 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2474
2502
  if (unrecognized && unrecognized.length > 0) {
2475
2503
  payload.issues.push({
2476
2504
  code: "unrecognized_keys",
2505
+
2477
2506
  input,
2478
2507
  inst,
2479
2508
  keys: unrecognized,
@@ -2491,8 +2520,9 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
2491
2520
 
2492
2521
  if (keyResult.issues.length) {
2493
2522
  payload.issues.push({
2494
- origin: "record",
2495
2523
  code: "invalid_key",
2524
+
2525
+ origin: "record",
2496
2526
  issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
2497
2527
  input: key,
2498
2528
  path: [key],
@@ -2563,6 +2593,7 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
2563
2593
  payload.issues.push({
2564
2594
  expected: "map",
2565
2595
  code: "invalid_type",
2596
+
2566
2597
  input,
2567
2598
  inst,
2568
2599
  });
@@ -2606,8 +2637,9 @@ function handleMapResult(
2606
2637
  final.issues.push(...util.prefixIssues(key as PropertyKey, keyResult.issues));
2607
2638
  } else {
2608
2639
  final.issues.push({
2609
- origin: "map",
2610
2640
  code: "invalid_key",
2641
+
2642
+ origin: "map",
2611
2643
  input,
2612
2644
  inst,
2613
2645
  issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
@@ -2621,6 +2653,7 @@ function handleMapResult(
2621
2653
  final.issues.push({
2622
2654
  origin: "map",
2623
2655
  code: "invalid_element",
2656
+
2624
2657
  input,
2625
2658
  inst,
2626
2659
  key: key,
@@ -2745,6 +2778,7 @@ export const $ZodEnum: core.$constructor<$ZodEnum> = /*@__PURE__*/ core.$constru
2745
2778
  }
2746
2779
  payload.issues.push({
2747
2780
  code: "invalid_value",
2781
+
2748
2782
  values,
2749
2783
  input,
2750
2784
  inst,
@@ -2800,6 +2834,7 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
2800
2834
  }
2801
2835
  payload.issues.push({
2802
2836
  code: "invalid_value",
2837
+
2803
2838
  values: def.values,
2804
2839
  input,
2805
2840
  inst,
@@ -2862,8 +2897,8 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
2862
2897
  type _File = typeof globalThis extends { File: infer F extends new (...args: any[]) => any } ? InstanceType<F> : {};
2863
2898
  /** Do not reference this directly. */
2864
2899
  export interface File extends _File {
2865
- type: string;
2866
- size: number;
2900
+ readonly type: string;
2901
+ readonly size: number;
2867
2902
  }
2868
2903
 
2869
2904
  export interface $ZodFileDef extends $ZodTypeDef {
@@ -2894,6 +2929,7 @@ export const $ZodFile: core.$constructor<$ZodFile> = /*@__PURE__*/ core.$constru
2894
2929
  payload.issues.push({
2895
2930
  expected: "file",
2896
2931
  code: "invalid_type",
2932
+
2897
2933
  input,
2898
2934
  inst,
2899
2935
  });
@@ -3202,6 +3238,7 @@ function handleNonOptionalResult(payload: ParsePayload, inst: $ZodNonOptional) {
3202
3238
  if (!payload.issues.length && payload.value === undefined) {
3203
3239
  payload.issues.push({
3204
3240
  code: "invalid_type",
3241
+
3205
3242
  expected: "nonoptional",
3206
3243
  input: payload.value,
3207
3244
  inst,
@@ -3622,6 +3659,7 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
3622
3659
  payload.issues.push({
3623
3660
  input: payload.value,
3624
3661
  inst,
3662
+
3625
3663
  code: "invalid_format",
3626
3664
  format: def.format ?? "template_literal",
3627
3665
  pattern: inst._zod.pattern.source,
@@ -123,6 +123,7 @@ export type Identity<T> = T;
123
123
  export type Flatten<T> = Identity<{ [k in keyof T]: T[k] }>;
124
124
  export type Mapped<T> = { [k in keyof T]: T[k] };
125
125
  export type Prettify<T> = {
126
+ // @ts-ignore
126
127
  [K in keyof T]: T[K];
127
128
  } & {};
128
129
 
@@ -241,7 +242,15 @@ export function cleanRegex(source: string): string {
241
242
 
242
243
  export function floatSafeRemainder(val: number, step: number): number {
243
244
  const valDecCount = (val.toString().split(".")[1] || "").length;
244
- const stepDecCount = (step.toString().split(".")[1] || "").length;
245
+ const stepString = step.toString();
246
+ let stepDecCount = (stepString.split(".")[1] || "").length;
247
+ if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
248
+ const match = stepString.match(/\d?e-(\d?)/);
249
+ if (match?.[1]) {
250
+ stepDecCount = Number.parseInt(match[1]);
251
+ }
252
+ }
253
+
245
254
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
246
255
  const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
247
256
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
@@ -717,6 +726,7 @@ export function required(
717
726
 
718
727
  export type Constructor<T, Def extends any[] = any[]> = new (...args: Def) => T;
719
728
 
729
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
720
730
  export function aborted(x: schemas.ParsePayload, startIndex = 0): boolean {
721
731
  for (let i = startIndex; i < x.issues.length; i++) {
722
732
  if (x.issues[i]?.continue !== true) {
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 0,
4
- patch: 9 as number,
4
+ patch: 11 as number,
5
5
  } as const;
@@ -39,3 +39,4 @@ export { default as ur } from "./ur.js";
39
39
  export { default as vi } from "./vi.js";
40
40
  export { default as zhCN } from "./zh-CN.js";
41
41
  export { default as zhTW } from "./zh-TW.js";
42
+ export { default as yo } from "./yo.js";
@@ -0,0 +1,131 @@
1
+ import type { $ZodStringFormats } from "../core/checks.js";
2
+ import type * as errors from "../core/errors.js";
3
+ import * as util from "../core/util.js";
4
+
5
+ const error: () => errors.$ZodErrorMap = () => {
6
+ const Sizable: Record<string, { unit: string; verb: string }> = {
7
+ string: { unit: "àmi", verb: "ní" },
8
+ file: { unit: "bytes", verb: "ní" },
9
+ array: { unit: "nkan", verb: "ní" },
10
+ set: { unit: "nkan", verb: "ní" },
11
+ };
12
+
13
+ function getSizing(origin: string): { unit: string; verb: string } | null {
14
+ return Sizable[origin] ?? null;
15
+ }
16
+
17
+ const parsedType = (data: any): string => {
18
+ const t = typeof data;
19
+
20
+ switch (t) {
21
+ case "number": {
22
+ return Number.isNaN(data) ? "NaN" : "nọ́mbà";
23
+ }
24
+ case "object": {
25
+ if (Array.isArray(data)) {
26
+ return "akopọ";
27
+ }
28
+ if (data === null) {
29
+ return "null";
30
+ }
31
+ if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
32
+ return data.constructor.name;
33
+ }
34
+ }
35
+ }
36
+ return t;
37
+ };
38
+
39
+ const Nouns: {
40
+ [k in $ZodStringFormats | (string & {})]?: string;
41
+ } = {
42
+ regex: "ẹ̀rọ ìbáwọlé",
43
+ email: "àdírẹ́sì ìmẹ́lì",
44
+ url: "URL",
45
+ emoji: "emoji",
46
+ uuid: "UUID",
47
+ uuidv4: "UUIDv4",
48
+ uuidv6: "UUIDv6",
49
+ nanoid: "nanoid",
50
+ guid: "GUID",
51
+ cuid: "cuid",
52
+ cuid2: "cuid2",
53
+ ulid: "ULID",
54
+ xid: "XID",
55
+ ksuid: "KSUID",
56
+ datetime: "àkókò ISO",
57
+ date: "ọjọ́ ISO",
58
+ time: "àkókò ISO",
59
+ duration: "àkókò tó pé ISO",
60
+ ipv4: "àdírẹ́sì IPv4",
61
+ ipv6: "àdírẹ́sì IPv6",
62
+ cidrv4: "àgbègbè IPv4",
63
+ cidrv6: "àgbègbè IPv6",
64
+ base64: "ọ̀rọ̀ tí a kọ́ ní base64",
65
+ base64url: "ọ̀rọ̀ base64url",
66
+ json_string: "ọ̀rọ̀ JSON",
67
+ e164: "nọ́mbà E.164",
68
+ jwt: "JWT",
69
+ template_literal: "ẹ̀rọ ìbáwọlé",
70
+ };
71
+
72
+ return (issue) => {
73
+ switch (issue.code) {
74
+ case "invalid_type":
75
+ return `Ìbáwọlé aṣìṣe: a ní láti fi ${issue.expected}, àmọ̀ a rí ${parsedType(issue.input)}`;
76
+
77
+ case "invalid_value":
78
+ if (issue.values.length === 1) return `Ìbáwọlé aṣìṣe: a ní láti fi ${util.stringifyPrimitive(issue.values[0])}`;
79
+ return `Àṣàyàn aṣìṣe: yan ọ̀kan lára ${util.joinValues(issue.values, "|")}`;
80
+
81
+ case "too_big": {
82
+ const adj = issue.inclusive ? "<=" : "<";
83
+ const sizing = getSizing(issue.origin);
84
+ if (sizing)
85
+ return `Tó pọ̀ jù: a ní láti jẹ́ pé ${issue.origin ?? "iye"} ${sizing.verb} ${adj}${issue.maximum} ${sizing.unit}`;
86
+ return `Tó pọ̀ jù: a ní láti jẹ́ ${adj}${issue.maximum}`;
87
+ }
88
+
89
+ case "too_small": {
90
+ const adj = issue.inclusive ? ">=" : ">";
91
+ const sizing = getSizing(issue.origin);
92
+ if (sizing)
93
+ return `Kéré ju: a ní láti jẹ́ pé ${issue.origin} ${sizing.verb} ${adj}${issue.minimum} ${sizing.unit}`;
94
+ return `Kéré ju: a ní láti jẹ́ ${adj}${issue.minimum}`;
95
+ }
96
+
97
+ case "invalid_format": {
98
+ const _issue = issue as errors.$ZodStringFormatIssues;
99
+ if (_issue.format === "starts_with") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ bẹ̀rẹ̀ pẹ̀lú "${_issue.prefix}"`;
100
+ if (_issue.format === "ends_with") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ parí pẹ̀lú "${_issue.suffix}"`;
101
+ if (_issue.format === "includes") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ ní "${_issue.includes}"`;
102
+ if (_issue.format === "regex") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ bá àpẹẹrẹ mu ${_issue.pattern}`;
103
+ return `Aṣìṣe: ${Nouns[_issue.format] ?? issue.format}`;
104
+ }
105
+
106
+ case "not_multiple_of":
107
+ return `Nọ́mbà aṣìṣe: gbọ́dọ̀ jẹ́ èyà pípín ti ${issue.divisor}`;
108
+
109
+ case "unrecognized_keys":
110
+ return `Bọtìnì àìmọ̀: ${util.joinValues(issue.keys, ", ")}`;
111
+
112
+ case "invalid_key":
113
+ return `Bọtìnì aṣìṣe nínú ${issue.origin}`;
114
+
115
+ case "invalid_union":
116
+ return "Ìbáwọlé aṣìṣe";
117
+
118
+ case "invalid_element":
119
+ return `Iye aṣìṣe nínú ${issue.origin}`;
120
+
121
+ default:
122
+ return "Ìbáwọlé aṣìṣe";
123
+ }
124
+ };
125
+ };
126
+
127
+ export default function (): { localeError: errors.$ZodErrorMap } {
128
+ return {
129
+ localeError: error(),
130
+ };
131
+ }
@@ -436,6 +436,10 @@ export function stringFormat<Format extends string>(
436
436
  return core._stringFormat(ZodMiniCustomStringFormat, format, fnOrRegex, _params) as any;
437
437
  }
438
438
 
439
+ export function hostname(_params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<"hostname"> {
440
+ return core._stringFormat(ZodMiniCustomStringFormat, "hostname", core.regexes.hostname, _params) as any;
441
+ }
442
+
439
443
  // ZodMiniNumber
440
444
  interface _ZodMiniNumber<T extends core.$ZodNumberInternals<unknown> = core.$ZodNumberInternals<unknown>>
441
445
  extends _ZodMiniType<T>,
@@ -1520,6 +1524,13 @@ export function refine<T>(
1520
1524
  return core._refine(ZodMiniCustom, fn, _params);
1521
1525
  }
1522
1526
 
1527
+ // superRefine
1528
+ export function superRefine<T>(
1529
+ fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>
1530
+ ): core.$ZodCheck<T> {
1531
+ return core._superRefine(fn);
1532
+ }
1533
+
1523
1534
  // instanceof
1524
1535
  abstract class Class {
1525
1536
  constructor(..._args: any[]) {}
package/v3/locales/en.cjs CHANGED
@@ -109,3 +109,4 @@ const errorMap = (issue, _ctx) => {
109
109
  return { message };
110
110
  };
111
111
  exports.default = errorMap;
112
+ module.exports = exports.default;
@@ -1,3 +1,3 @@
1
1
  import { type ZodErrorMap } from "../ZodError.cjs";
2
2
  declare const errorMap: ZodErrorMap;
3
- export default errorMap;
3
+ export = errorMap;
@@ -1 +1 @@
1
- export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.cjs";
1
+ export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
@@ -1 +1 @@
1
- export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.js";
1
+ export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
@@ -49,6 +49,7 @@ exports.base64url = base64url;
49
49
  exports.e164 = e164;
50
50
  exports.jwt = jwt;
51
51
  exports.stringFormat = stringFormat;
52
+ exports.hostname = hostname;
52
53
  exports.number = number;
53
54
  exports.int = int;
54
55
  exports.float32 = float32;
@@ -416,6 +417,9 @@ exports.ZodCustomStringFormat = core.$constructor("ZodCustomStringFormat", (inst
416
417
  function stringFormat(format, fnOrRegex, _params = {}) {
417
418
  return core._stringFormat(exports.ZodCustomStringFormat, format, fnOrRegex, _params);
418
419
  }
420
+ function hostname(_params) {
421
+ return core._stringFormat(exports.ZodCustomStringFormat, "hostname", core.regexes.hostname, _params);
422
+ }
419
423
  exports.ZodNumber = core.$constructor("ZodNumber", (inst, def) => {
420
424
  core.$ZodNumber.init(inst, def);
421
425
  exports.ZodType.init(inst, def);
@@ -1056,26 +1060,7 @@ function refine(fn, _params = {}) {
1056
1060
  }
1057
1061
  // superRefine
1058
1062
  function superRefine(fn) {
1059
- const ch = check((payload) => {
1060
- payload.addIssue = (issue) => {
1061
- if (typeof issue === "string") {
1062
- payload.issues.push(index_js_1.util.issue(issue, payload.value, ch._zod.def));
1063
- }
1064
- else {
1065
- // for Zod 3 backwards compatibility
1066
- const _issue = issue;
1067
- if (_issue.fatal)
1068
- _issue.continue = false;
1069
- _issue.code ?? (_issue.code = "custom");
1070
- _issue.input ?? (_issue.input = payload.value);
1071
- _issue.inst ?? (_issue.inst = ch);
1072
- _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
1073
- payload.issues.push(index_js_1.util.issue(_issue));
1074
- }
1075
- };
1076
- return fn(payload.value, payload);
1077
- });
1078
- return ch;
1063
+ return core._superRefine(fn);
1079
1064
  }
1080
1065
  function _instanceof(cls, params = {
1081
1066
  error: `Input not instance of ${cls.name}`,
@@ -1,9 +1,6 @@
1
1
  import * as core from "../core/index.cjs";
2
2
  import { util } from "../core/index.cjs";
3
3
  import * as parse from "./parse.cjs";
4
- export interface RefinementCtx<T = unknown> extends core.ParsePayload<T> {
5
- addIssue(arg: string | core.$ZodRawIssue | Partial<core.$ZodIssueCustom>): void;
6
- }
7
4
  export interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
8
5
  def: Internals["def"];
9
6
  type: Internals["def"]["type"];
@@ -25,7 +22,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
25
22
  safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
26
23
  spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
27
24
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
28
- superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
25
+ superRefine(refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>): this;
29
26
  overwrite(fn: (x: core.output<this>) => core.output<this>): this;
30
27
  optional(): ZodOptional<this>;
31
28
  nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
@@ -38,7 +35,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
38
35
  array(): ZodArray<this>;
39
36
  or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
40
37
  and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
41
- transform<NewOut>(transform: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
38
+ transform<NewOut>(transform: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
42
39
  catch(def: core.output<this>): ZodCatch<this>;
43
40
  catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
44
41
  pipe<T extends core.$ZodType<any, core.output<this>>>(target: T | core.$ZodType<any, core.output<this>>): ZodPipe<this, T>;
@@ -257,6 +254,7 @@ export interface ZodCustomStringFormat<Format extends string = string> extends Z
257
254
  }
258
255
  export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat>;
259
256
  export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
257
+ export declare function hostname(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hostname">;
260
258
  export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals> extends _ZodType<Internals> {
261
259
  gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
262
260
  /** Identical to .min() */
@@ -596,7 +594,7 @@ export declare const ZodCustom: core.$constructor<ZodCustom>;
596
594
  export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
597
595
  export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
598
596
  export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
599
- export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
597
+ export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
600
598
  type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
601
599
  declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
602
600
  export { _instanceof as instanceof };
@@ -618,4 +616,4 @@ export interface ZodJSONSchema extends _ZodJSONSchema {
618
616
  _zod: ZodJSONSchemaInternals;
619
617
  }
620
618
  export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
621
- export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
619
+ export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
@@ -1,9 +1,6 @@
1
1
  import * as core from "../core/index.js";
2
2
  import { util } from "../core/index.js";
3
3
  import * as parse from "./parse.js";
4
- export interface RefinementCtx<T = unknown> extends core.ParsePayload<T> {
5
- addIssue(arg: string | core.$ZodRawIssue | Partial<core.$ZodIssueCustom>): void;
6
- }
7
4
  export interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
8
5
  def: Internals["def"];
9
6
  type: Internals["def"]["type"];
@@ -25,7 +22,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
25
22
  safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
26
23
  spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
27
24
  refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
28
- superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
25
+ superRefine(refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>): this;
29
26
  overwrite(fn: (x: core.output<this>) => core.output<this>): this;
30
27
  optional(): ZodOptional<this>;
31
28
  nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
@@ -38,7 +35,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
38
35
  array(): ZodArray<this>;
39
36
  or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
40
37
  and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
41
- transform<NewOut>(transform: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
38
+ transform<NewOut>(transform: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
42
39
  catch(def: core.output<this>): ZodCatch<this>;
43
40
  catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
44
41
  pipe<T extends core.$ZodType<any, core.output<this>>>(target: T | core.$ZodType<any, core.output<this>>): ZodPipe<this, T>;
@@ -257,6 +254,7 @@ export interface ZodCustomStringFormat<Format extends string = string> extends Z
257
254
  }
258
255
  export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat>;
259
256
  export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
257
+ export declare function hostname(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hostname">;
260
258
  export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals> extends _ZodType<Internals> {
261
259
  gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
262
260
  /** Identical to .min() */
@@ -596,7 +594,7 @@ export declare const ZodCustom: core.$constructor<ZodCustom>;
596
594
  export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
597
595
  export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
598
596
  export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
599
- export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
597
+ export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
600
598
  type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
601
599
  declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
602
600
  export { _instanceof as instanceof };
@@ -618,4 +616,4 @@ export interface ZodJSONSchema extends _ZodJSONSchema {
618
616
  _zod: ZodJSONSchemaInternals;
619
617
  }
620
618
  export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
621
- export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
619
+ export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;