zod 4.1.0-canary.20250729T005826 → 4.1.0-canary.20250729T053738

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 (124) hide show
  1. package/package.json +6 -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/number.test.ts +23 -0
  6. package/src/v4/classic/tests/recursive-types.test.ts +39 -0
  7. package/src/v4/classic/tests/string.test.ts +38 -0
  8. package/src/v4/classic/tests/tuple.test.ts +2 -2
  9. package/src/v4/core/api.ts +51 -7
  10. package/src/v4/core/checks.ts +2 -0
  11. package/src/v4/core/errors.ts +26 -23
  12. package/src/v4/core/regexes.ts +7 -4
  13. package/src/v4/core/schemas.ts +41 -4
  14. package/src/v4/core/util.ts +11 -1
  15. package/src/v4/core/versions.ts +1 -1
  16. package/src/v4/mini/schemas.ts +11 -0
  17. package/v3/locales/en.cjs +1 -0
  18. package/v3/locales/en.d.cts +1 -1
  19. package/v4/classic/checks.d.cts +1 -1
  20. package/v4/classic/checks.d.ts +1 -1
  21. package/v4/classic/schemas.cjs +5 -20
  22. package/v4/classic/schemas.d.cts +5 -7
  23. package/v4/classic/schemas.d.ts +5 -7
  24. package/v4/classic/schemas.js +4 -20
  25. package/v4/core/api.cjs +33 -7
  26. package/v4/core/api.d.cts +12 -0
  27. package/v4/core/api.d.ts +12 -0
  28. package/v4/core/api.js +31 -7
  29. package/v4/core/checks.cjs +2 -0
  30. package/v4/core/checks.js +2 -0
  31. package/v4/core/errors.d.cts +17 -16
  32. package/v4/core/errors.d.ts +17 -16
  33. package/v4/core/regexes.cjs +6 -5
  34. package/v4/core/regexes.d.cts +1 -0
  35. package/v4/core/regexes.d.ts +1 -0
  36. package/v4/core/regexes.js +5 -4
  37. package/v4/core/schemas.cjs +8 -3
  38. package/v4/core/schemas.d.cts +3 -1
  39. package/v4/core/schemas.d.ts +3 -1
  40. package/v4/core/schemas.js +8 -3
  41. package/v4/core/util.cjs +9 -1
  42. package/v4/core/util.js +9 -1
  43. package/v4/core/versions.cjs +1 -1
  44. package/v4/core/versions.js +1 -1
  45. package/v4/locales/ar.cjs +1 -0
  46. package/v4/locales/ar.d.cts +2 -1
  47. package/v4/locales/az.cjs +1 -0
  48. package/v4/locales/az.d.cts +2 -1
  49. package/v4/locales/be.cjs +1 -0
  50. package/v4/locales/be.d.cts +2 -1
  51. package/v4/locales/ca.cjs +1 -0
  52. package/v4/locales/ca.d.cts +2 -1
  53. package/v4/locales/cs.cjs +1 -0
  54. package/v4/locales/cs.d.cts +2 -1
  55. package/v4/locales/da.cjs +1 -0
  56. package/v4/locales/da.d.cts +2 -1
  57. package/v4/locales/de.cjs +1 -0
  58. package/v4/locales/de.d.cts +2 -1
  59. package/v4/locales/es.cjs +1 -0
  60. package/v4/locales/es.d.cts +2 -1
  61. package/v4/locales/fa.cjs +1 -0
  62. package/v4/locales/fa.d.cts +2 -1
  63. package/v4/locales/fi.cjs +1 -0
  64. package/v4/locales/fi.d.cts +2 -1
  65. package/v4/locales/fr-CA.cjs +1 -0
  66. package/v4/locales/fr-CA.d.cts +2 -1
  67. package/v4/locales/fr.cjs +1 -0
  68. package/v4/locales/fr.d.cts +2 -1
  69. package/v4/locales/he.cjs +1 -0
  70. package/v4/locales/he.d.cts +2 -1
  71. package/v4/locales/hu.cjs +1 -0
  72. package/v4/locales/hu.d.cts +2 -1
  73. package/v4/locales/id.cjs +1 -0
  74. package/v4/locales/id.d.cts +2 -1
  75. package/v4/locales/it.cjs +1 -0
  76. package/v4/locales/it.d.cts +2 -1
  77. package/v4/locales/ja.cjs +1 -0
  78. package/v4/locales/ja.d.cts +2 -1
  79. package/v4/locales/kh.cjs +1 -0
  80. package/v4/locales/kh.d.cts +2 -1
  81. package/v4/locales/ko.cjs +1 -0
  82. package/v4/locales/ko.d.cts +2 -1
  83. package/v4/locales/mk.cjs +1 -0
  84. package/v4/locales/mk.d.cts +2 -1
  85. package/v4/locales/ms.cjs +1 -0
  86. package/v4/locales/ms.d.cts +2 -1
  87. package/v4/locales/nl.cjs +1 -0
  88. package/v4/locales/nl.d.cts +2 -1
  89. package/v4/locales/no.cjs +1 -0
  90. package/v4/locales/no.d.cts +2 -1
  91. package/v4/locales/ota.cjs +1 -0
  92. package/v4/locales/ota.d.cts +2 -1
  93. package/v4/locales/pl.cjs +1 -0
  94. package/v4/locales/pl.d.cts +2 -1
  95. package/v4/locales/ps.cjs +1 -0
  96. package/v4/locales/ps.d.cts +2 -1
  97. package/v4/locales/pt.cjs +1 -0
  98. package/v4/locales/pt.d.cts +2 -1
  99. package/v4/locales/ru.cjs +1 -0
  100. package/v4/locales/ru.d.cts +2 -1
  101. package/v4/locales/sl.cjs +1 -0
  102. package/v4/locales/sl.d.cts +2 -1
  103. package/v4/locales/sv.cjs +1 -0
  104. package/v4/locales/sv.d.cts +2 -1
  105. package/v4/locales/ta.cjs +1 -0
  106. package/v4/locales/ta.d.cts +2 -1
  107. package/v4/locales/th.cjs +1 -0
  108. package/v4/locales/th.d.cts +2 -1
  109. package/v4/locales/ua.cjs +1 -0
  110. package/v4/locales/ua.d.cts +2 -1
  111. package/v4/locales/ur.cjs +1 -0
  112. package/v4/locales/ur.d.cts +2 -1
  113. package/v4/locales/vi.cjs +1 -0
  114. package/v4/locales/vi.d.cts +2 -1
  115. package/v4/locales/yo.cjs +1 -0
  116. package/v4/locales/yo.d.cts +2 -1
  117. package/v4/locales/zh-CN.cjs +1 -0
  118. package/v4/locales/zh-CN.d.cts +2 -1
  119. package/v4/locales/zh-TW.cjs +1 -0
  120. package/v4/locales/zh-TW.d.cts +2 -1
  121. package/v4/mini/schemas.cjs +9 -0
  122. package/v4/mini/schemas.d.cts +2 -0
  123. package/v4/mini/schemas.d.ts +2 -0
  124. package/v4/mini/schemas.js +7 -0
package/v4/core/api.js CHANGED
@@ -814,13 +814,6 @@ export function _custom(Class, fn, _params) {
814
814
  });
815
815
  return schema;
816
816
  }
817
- // export function _refine<T>(
818
- // Class: util.SchemaClass<schemas.$ZodCustom>,
819
- // fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>,
820
- // _params: string | $ZodCustomParams = {}
821
- // ): checks.$ZodCheck<T> {
822
- // return _custom(Class, fn, _params);
823
- // }
824
817
  // same as _custom but defaults to abort:false
825
818
  export function _refine(Class, fn, _params) {
826
819
  const schema = new Class({
@@ -831,6 +824,36 @@ export function _refine(Class, fn, _params) {
831
824
  });
832
825
  return schema;
833
826
  }
827
+ export function _superRefine(fn) {
828
+ const ch = _check((payload) => {
829
+ payload.addIssue = (issue) => {
830
+ if (typeof issue === "string") {
831
+ payload.issues.push(util.issue(issue, payload.value, ch._zod.def));
832
+ }
833
+ else {
834
+ // for Zod 3 backwards compatibility
835
+ const _issue = issue;
836
+ if (_issue.fatal)
837
+ _issue.continue = false;
838
+ _issue.code ?? (_issue.code = "custom");
839
+ _issue.input ?? (_issue.input = payload.value);
840
+ _issue.inst ?? (_issue.inst = ch);
841
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
842
+ payload.issues.push(util.issue(_issue));
843
+ }
844
+ };
845
+ return fn(payload.value, payload);
846
+ });
847
+ return ch;
848
+ }
849
+ export function _check(fn, params) {
850
+ const ch = new checks.$ZodCheck({
851
+ check: "custom",
852
+ ...util.normalizeParams(params),
853
+ });
854
+ ch._zod.check = fn;
855
+ return ch;
856
+ }
834
857
  export function _stringbool(Classes, _params) {
835
858
  const params = util.normalizeParams(_params);
836
859
  let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
@@ -864,6 +887,7 @@ export function _stringbool(Classes, _params) {
864
887
  values: [...truthySet, ...falsySet],
865
888
  input: payload.value,
866
889
  inst: tx,
890
+ continue: false,
867
891
  });
868
892
  return {};
869
893
  }
@@ -151,6 +151,7 @@ exports.$ZodCheckNumberFormat = core.$constructor("$ZodCheckNumberFormat", (inst
151
151
  expected: origin,
152
152
  format: def.format,
153
153
  code: "invalid_type",
154
+ continue: false,
154
155
  input,
155
156
  inst,
156
157
  });
@@ -580,6 +581,7 @@ exports.$ZodCheckMimeType = core.$constructor("$ZodCheckMimeType", (inst, def) =
580
581
  values: def.mime,
581
582
  input: payload.value.type,
582
583
  inst,
584
+ continue: !def.abort,
583
585
  });
584
586
  };
585
587
  });
package/v4/core/checks.js CHANGED
@@ -125,6 +125,7 @@ export const $ZodCheckNumberFormat = /*@__PURE__*/ core.$constructor("$ZodCheckN
125
125
  expected: origin,
126
126
  format: def.format,
127
127
  code: "invalid_type",
128
+ continue: false,
128
129
  input,
129
130
  inst,
130
131
  });
@@ -554,6 +555,7 @@ export const $ZodCheckMimeType = /*@__PURE__*/ core.$constructor("$ZodCheckMimeT
554
555
  values: def.mime,
555
556
  input: payload.value.type,
556
557
  inst,
558
+ continue: !def.abort,
557
559
  });
558
560
  };
559
561
  });
@@ -12,7 +12,7 @@ export interface $ZodIssueBase {
12
12
  export interface $ZodIssueInvalidType<Input = unknown> extends $ZodIssueBase {
13
13
  readonly code: "invalid_type";
14
14
  readonly expected: $ZodType["_zod"]["def"]["type"];
15
- readonly input: Input;
15
+ readonly input?: Input;
16
16
  }
17
17
  export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
18
18
  readonly code: "too_big";
@@ -20,7 +20,7 @@ export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
20
20
  readonly maximum: number | bigint;
21
21
  readonly inclusive?: boolean;
22
22
  readonly exact?: boolean;
23
- readonly input: Input;
23
+ readonly input?: Input;
24
24
  }
25
25
  export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
26
26
  readonly code: "too_small";
@@ -30,52 +30,52 @@ export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
30
30
  readonly inclusive?: boolean;
31
31
  /** True if the allowed value is fixed (e.g.` z.length(5)`), not a range (`z.minLength(5)`) */
32
32
  readonly exact?: boolean;
33
- readonly input: Input;
33
+ readonly input?: Input;
34
34
  }
35
35
  export interface $ZodIssueInvalidStringFormat extends $ZodIssueBase {
36
36
  readonly code: "invalid_format";
37
37
  readonly format: $ZodStringFormats | (string & {});
38
38
  readonly pattern?: string;
39
- readonly input: string;
39
+ readonly input?: string;
40
40
  }
41
41
  export interface $ZodIssueNotMultipleOf<Input extends number | bigint = number | bigint> extends $ZodIssueBase {
42
42
  readonly code: "not_multiple_of";
43
43
  readonly divisor: number;
44
- readonly input: Input;
44
+ readonly input?: Input;
45
45
  }
46
46
  export interface $ZodIssueUnrecognizedKeys extends $ZodIssueBase {
47
47
  readonly code: "unrecognized_keys";
48
48
  readonly keys: string[];
49
- readonly input: Record<string, unknown>;
49
+ readonly input?: Record<string, unknown>;
50
50
  }
51
51
  export interface $ZodIssueInvalidUnion extends $ZodIssueBase {
52
52
  readonly code: "invalid_union";
53
53
  readonly errors: $ZodIssue[][];
54
- readonly input: unknown;
54
+ readonly input?: unknown;
55
55
  readonly discriminator?: string | undefined;
56
56
  }
57
57
  export interface $ZodIssueInvalidKey<Input = unknown> extends $ZodIssueBase {
58
58
  readonly code: "invalid_key";
59
59
  readonly origin: "map" | "record";
60
60
  readonly issues: $ZodIssue[];
61
- readonly input: Input;
61
+ readonly input?: Input;
62
62
  }
63
63
  export interface $ZodIssueInvalidElement<Input = unknown> extends $ZodIssueBase {
64
64
  readonly code: "invalid_element";
65
65
  readonly origin: "map" | "set";
66
66
  readonly key: unknown;
67
67
  readonly issues: $ZodIssue[];
68
- readonly input: Input;
68
+ readonly input?: Input;
69
69
  }
70
70
  export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
71
71
  readonly code: "invalid_value";
72
72
  readonly values: util.Primitive[];
73
- readonly input: Input;
73
+ readonly input?: Input;
74
74
  }
75
75
  export interface $ZodIssueCustom extends $ZodIssueBase {
76
76
  readonly code: "custom";
77
77
  readonly params?: Record<string, any> | undefined;
78
- readonly input: unknown;
78
+ readonly input?: unknown;
79
79
  }
80
80
  export interface $ZodIssueStringCommonFormats extends $ZodIssueInvalidStringFormat {
81
81
  format: Exclude<$ZodStringFormats, "regex" | "jwt" | "starts_with" | "ends_with" | "includes">;
@@ -103,15 +103,16 @@ export interface $ZodIssueStringIncludes extends $ZodIssueInvalidStringFormat {
103
103
  export type $ZodStringFormatIssues = $ZodIssueStringCommonFormats | $ZodIssueStringInvalidRegex | $ZodIssueStringInvalidJWT | $ZodIssueStringStartsWith | $ZodIssueStringEndsWith | $ZodIssueStringIncludes;
104
104
  export type $ZodIssue = $ZodIssueInvalidType | $ZodIssueTooBig | $ZodIssueTooSmall | $ZodIssueInvalidStringFormat | $ZodIssueNotMultipleOf | $ZodIssueUnrecognizedKeys | $ZodIssueInvalidUnion | $ZodIssueInvalidKey | $ZodIssueInvalidElement | $ZodIssueInvalidValue | $ZodIssueCustom;
105
105
  export type $ZodIssueCode = $ZodIssue["code"];
106
- export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
107
- type RawIssue<T extends $ZodIssueBase> = util.Flatten<util.MakePartial<T, "message" | "path"> & {
106
+ export type $ZodInternalIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
107
+ type RawIssue<T extends $ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
108
108
  /** The input data */
109
- readonly input?: unknown;
109
+ readonly input: unknown;
110
110
  /** The schema or check that originated this issue. */
111
111
  readonly inst?: $ZodType | $ZodCheck;
112
- /** If `true`, Zod will continue executing validation despite this issue. */
112
+ /** If `true`, Zod will continue executing checks/refinements after this issue. */
113
113
  readonly continue?: boolean | undefined;
114
- } & Record<string, any>>;
114
+ } & Record<string, unknown>> : never;
115
+ export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = $ZodInternalIssue<T>;
115
116
  export interface $ZodErrorMap<T extends $ZodIssueBase = $ZodIssue> {
116
117
  (issue: $ZodRawIssue<T>): {
117
118
  message: string;
@@ -12,7 +12,7 @@ export interface $ZodIssueBase {
12
12
  export interface $ZodIssueInvalidType<Input = unknown> extends $ZodIssueBase {
13
13
  readonly code: "invalid_type";
14
14
  readonly expected: $ZodType["_zod"]["def"]["type"];
15
- readonly input: Input;
15
+ readonly input?: Input;
16
16
  }
17
17
  export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
18
18
  readonly code: "too_big";
@@ -20,7 +20,7 @@ export interface $ZodIssueTooBig<Input = unknown> extends $ZodIssueBase {
20
20
  readonly maximum: number | bigint;
21
21
  readonly inclusive?: boolean;
22
22
  readonly exact?: boolean;
23
- readonly input: Input;
23
+ readonly input?: Input;
24
24
  }
25
25
  export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
26
26
  readonly code: "too_small";
@@ -30,52 +30,52 @@ export interface $ZodIssueTooSmall<Input = unknown> extends $ZodIssueBase {
30
30
  readonly inclusive?: boolean;
31
31
  /** True if the allowed value is fixed (e.g.` z.length(5)`), not a range (`z.minLength(5)`) */
32
32
  readonly exact?: boolean;
33
- readonly input: Input;
33
+ readonly input?: Input;
34
34
  }
35
35
  export interface $ZodIssueInvalidStringFormat extends $ZodIssueBase {
36
36
  readonly code: "invalid_format";
37
37
  readonly format: $ZodStringFormats | (string & {});
38
38
  readonly pattern?: string;
39
- readonly input: string;
39
+ readonly input?: string;
40
40
  }
41
41
  export interface $ZodIssueNotMultipleOf<Input extends number | bigint = number | bigint> extends $ZodIssueBase {
42
42
  readonly code: "not_multiple_of";
43
43
  readonly divisor: number;
44
- readonly input: Input;
44
+ readonly input?: Input;
45
45
  }
46
46
  export interface $ZodIssueUnrecognizedKeys extends $ZodIssueBase {
47
47
  readonly code: "unrecognized_keys";
48
48
  readonly keys: string[];
49
- readonly input: Record<string, unknown>;
49
+ readonly input?: Record<string, unknown>;
50
50
  }
51
51
  export interface $ZodIssueInvalidUnion extends $ZodIssueBase {
52
52
  readonly code: "invalid_union";
53
53
  readonly errors: $ZodIssue[][];
54
- readonly input: unknown;
54
+ readonly input?: unknown;
55
55
  readonly discriminator?: string | undefined;
56
56
  }
57
57
  export interface $ZodIssueInvalidKey<Input = unknown> extends $ZodIssueBase {
58
58
  readonly code: "invalid_key";
59
59
  readonly origin: "map" | "record";
60
60
  readonly issues: $ZodIssue[];
61
- readonly input: Input;
61
+ readonly input?: Input;
62
62
  }
63
63
  export interface $ZodIssueInvalidElement<Input = unknown> extends $ZodIssueBase {
64
64
  readonly code: "invalid_element";
65
65
  readonly origin: "map" | "set";
66
66
  readonly key: unknown;
67
67
  readonly issues: $ZodIssue[];
68
- readonly input: Input;
68
+ readonly input?: Input;
69
69
  }
70
70
  export interface $ZodIssueInvalidValue<Input = unknown> extends $ZodIssueBase {
71
71
  readonly code: "invalid_value";
72
72
  readonly values: util.Primitive[];
73
- readonly input: Input;
73
+ readonly input?: Input;
74
74
  }
75
75
  export interface $ZodIssueCustom extends $ZodIssueBase {
76
76
  readonly code: "custom";
77
77
  readonly params?: Record<string, any> | undefined;
78
- readonly input: unknown;
78
+ readonly input?: unknown;
79
79
  }
80
80
  export interface $ZodIssueStringCommonFormats extends $ZodIssueInvalidStringFormat {
81
81
  format: Exclude<$ZodStringFormats, "regex" | "jwt" | "starts_with" | "ends_with" | "includes">;
@@ -103,15 +103,16 @@ export interface $ZodIssueStringIncludes extends $ZodIssueInvalidStringFormat {
103
103
  export type $ZodStringFormatIssues = $ZodIssueStringCommonFormats | $ZodIssueStringInvalidRegex | $ZodIssueStringInvalidJWT | $ZodIssueStringStartsWith | $ZodIssueStringEndsWith | $ZodIssueStringIncludes;
104
104
  export type $ZodIssue = $ZodIssueInvalidType | $ZodIssueTooBig | $ZodIssueTooSmall | $ZodIssueInvalidStringFormat | $ZodIssueNotMultipleOf | $ZodIssueUnrecognizedKeys | $ZodIssueInvalidUnion | $ZodIssueInvalidKey | $ZodIssueInvalidElement | $ZodIssueInvalidValue | $ZodIssueCustom;
105
105
  export type $ZodIssueCode = $ZodIssue["code"];
106
- export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
107
- type RawIssue<T extends $ZodIssueBase> = util.Flatten<util.MakePartial<T, "message" | "path"> & {
106
+ export type $ZodInternalIssue<T extends $ZodIssueBase = $ZodIssue> = T extends any ? RawIssue<T> : never;
107
+ type RawIssue<T extends $ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
108
108
  /** The input data */
109
- readonly input?: unknown;
109
+ readonly input: unknown;
110
110
  /** The schema or check that originated this issue. */
111
111
  readonly inst?: $ZodType | $ZodCheck;
112
- /** If `true`, Zod will continue executing validation despite this issue. */
112
+ /** If `true`, Zod will continue executing checks/refinements after this issue. */
113
113
  readonly continue?: boolean | undefined;
114
- } & Record<string, any>>;
114
+ } & Record<string, unknown>> : never;
115
+ export type $ZodRawIssue<T extends $ZodIssueBase = $ZodIssue> = $ZodInternalIssue<T>;
115
116
  export interface $ZodErrorMap<T extends $ZodIssueBase = $ZodIssue> {
116
117
  (issue: $ZodRawIssue<T>): {
117
118
  message: string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uppercase = exports.lowercase = exports.undefined = exports.null = exports.boolean = exports.number = exports.integer = exports.bigint = exports.string = exports.date = exports.e164 = exports.domain = exports.hostname = exports.base64url = exports.base64 = exports.cidrv6 = exports.cidrv4 = exports.ipv6 = exports.ipv4 = exports.browserEmail = exports.unicodeEmail = exports.rfc5322Email = exports.html5Email = exports.email = exports.uuid7 = exports.uuid6 = exports.uuid4 = exports.uuid = exports.guid = exports.extendedDuration = exports.duration = exports.nanoid = exports.ksuid = exports.xid = exports.ulid = exports.cuid2 = exports.cuid = void 0;
3
+ exports.uppercase = exports.lowercase = exports.undefined = exports.null = exports.boolean = exports.number = exports.integer = exports.bigint = exports.string = exports.date = exports.e164 = exports.domain = exports.hostname = exports.base64url = exports.base64 = exports.cidrv6 = exports.cidrv4 = exports.ipv6 = exports.ipv4 = exports.browserEmail = exports.idnEmail = exports.unicodeEmail = exports.rfc5322Email = exports.html5Email = exports.email = exports.uuid7 = exports.uuid6 = exports.uuid4 = exports.uuid = exports.guid = exports.extendedDuration = exports.duration = exports.nanoid = exports.ksuid = exports.xid = exports.ulid = exports.cuid2 = exports.cuid = void 0;
4
4
  exports.emoji = emoji;
5
5
  exports.time = time;
6
6
  exports.datetime = datetime;
@@ -36,6 +36,7 @@ exports.html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9
36
36
  exports.rfc5322Email = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
37
37
  /** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
38
38
  exports.unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
39
+ exports.idnEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
39
40
  exports.browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
40
41
  // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
41
42
  const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
@@ -50,9 +51,8 @@ exports.cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})
50
51
  exports.base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
51
52
  exports.base64url = /^[A-Za-z0-9_-]*$/;
52
53
  // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
53
- // export const hostname: RegExp =
54
- // /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
55
- exports.hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
54
+ // export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
55
+ exports.hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
56
56
  exports.domain = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
57
57
  // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
58
58
  exports.e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
@@ -79,8 +79,9 @@ function datetime(args) {
79
79
  const opts = ["Z"];
80
80
  if (args.local)
81
81
  opts.push("");
82
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
82
83
  if (args.offset)
83
- opts.push(`([+-]\\d{2}:\\d{2})`);
84
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
84
85
  const timeRegex = `${time}(?:${opts.join("|")})`;
85
86
  return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
86
87
  }
@@ -25,6 +25,7 @@ export declare const html5Email: RegExp;
25
25
  export declare const rfc5322Email: RegExp;
26
26
  /** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
27
27
  export declare const unicodeEmail: RegExp;
28
+ export declare const idnEmail: RegExp;
28
29
  export declare const browserEmail: RegExp;
29
30
  export declare function emoji(): RegExp;
30
31
  export declare const ipv4: RegExp;
@@ -25,6 +25,7 @@ export declare const html5Email: RegExp;
25
25
  export declare const rfc5322Email: RegExp;
26
26
  /** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
27
27
  export declare const unicodeEmail: RegExp;
28
+ export declare const idnEmail: RegExp;
28
29
  export declare const browserEmail: RegExp;
29
30
  export declare function emoji(): RegExp;
30
31
  export declare const ipv4: RegExp;
@@ -29,6 +29,7 @@ export const html5Email = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA
29
29
  export const rfc5322Email = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
30
30
  /** A loose regex that allows Unicode characters, enforces length limits, and that's about it. */
31
31
  export const unicodeEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
32
+ export const idnEmail = /^[^\s@"]{1,64}@[^\s@]{1,255}$/u;
32
33
  export const browserEmail = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
33
34
  // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
34
35
  const _emoji = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
@@ -43,9 +44,8 @@ export const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{
43
44
  export const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
44
45
  export const base64url = /^[A-Za-z0-9_-]*$/;
45
46
  // based on https://stackoverflow.com/questions/106179/regular-expression-to-match-dns-hostname-or-ip-address
46
- // export const hostname: RegExp =
47
- // /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)+([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/;
48
- export const hostname = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
47
+ // export const hostname: RegExp = /^([a-zA-Z0-9-]+\.)*[a-zA-Z0-9-]+$/;
48
+ export const hostname = /^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/;
49
49
  export const domain = /^([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/;
50
50
  // https://blog.stevenlevithan.com/archives/validate-phone-number#r4-3 (regex sans spaces)
51
51
  export const e164 = /^\+(?:[0-9]){6,14}[0-9]$/;
@@ -72,8 +72,9 @@ export function datetime(args) {
72
72
  const opts = ["Z"];
73
73
  if (args.local)
74
74
  opts.push("");
75
+ // if (args.offset) opts.push(`([+-]\\d{2}:\\d{2})`);
75
76
  if (args.offset)
76
- opts.push(`([+-]\\d{2}:\\d{2})`);
77
+ opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
77
78
  const timeRegex = `${time}(?:${opts.join("|")})`;
78
79
  return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
79
80
  }
@@ -892,7 +892,12 @@ exports.$ZodUnion = core.$constructor("$ZodUnion", (inst, def) => {
892
892
  }
893
893
  return undefined;
894
894
  });
895
+ const single = def.options.length === 1;
896
+ const first = def.options[0]._zod.run;
895
897
  inst._zod.parse = (payload, ctx) => {
898
+ if (single) {
899
+ return first(payload, ctx);
900
+ }
896
901
  let async = false;
897
902
  const results = [];
898
903
  for (const option of def.options) {
@@ -1084,10 +1089,10 @@ exports.$ZodTuple = core.$constructor("$ZodTuple", (inst, def) => {
1084
1089
  const tooSmall = input.length < optStart - 1;
1085
1090
  if (tooBig || tooSmall) {
1086
1091
  payload.issues.push({
1092
+ ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
1087
1093
  input,
1088
1094
  inst,
1089
1095
  origin: "array",
1090
- ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
1091
1096
  });
1092
1097
  return payload;
1093
1098
  }
@@ -1199,8 +1204,8 @@ exports.$ZodRecord = core.$constructor("$ZodRecord", (inst, def) => {
1199
1204
  }
1200
1205
  if (keyResult.issues.length) {
1201
1206
  payload.issues.push({
1202
- origin: "record",
1203
1207
  code: "invalid_key",
1208
+ origin: "record",
1204
1209
  issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1205
1210
  input: key,
1206
1211
  path: [key],
@@ -1271,8 +1276,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1271
1276
  }
1272
1277
  else {
1273
1278
  final.issues.push({
1274
- origin: "map",
1275
1279
  code: "invalid_key",
1280
+ origin: "map",
1276
1281
  input,
1277
1282
  inst,
1278
1283
  issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
@@ -634,11 +634,13 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
634
634
  left: Left;
635
635
  right: Right;
636
636
  }
637
- export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
637
+ export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends _$ZodTypeInternals {
638
638
  def: $ZodIntersectionDef<A, B>;
639
639
  isst: never;
640
640
  optin: A["_zod"]["optin"] | B["_zod"]["optin"];
641
641
  optout: A["_zod"]["optout"] | B["_zod"]["optout"];
642
+ output: core.output<A> & core.output<B>;
643
+ input: core.input<A> & core.input<B>;
642
644
  }
643
645
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
644
646
  _zod: $ZodIntersectionInternals<A, B>;
@@ -634,11 +634,13 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
634
634
  left: Left;
635
635
  right: Right;
636
636
  }
637
- export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>> {
637
+ export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends _$ZodTypeInternals {
638
638
  def: $ZodIntersectionDef<A, B>;
639
639
  isst: never;
640
640
  optin: A["_zod"]["optin"] | B["_zod"]["optin"];
641
641
  optout: A["_zod"]["optout"] | B["_zod"]["optout"];
642
+ output: core.output<A> & core.output<B>;
643
+ input: core.input<A> & core.input<B>;
642
644
  }
643
645
  export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
644
646
  _zod: $ZodIntersectionInternals<A, B>;
@@ -861,7 +861,12 @@ export const $ZodUnion = /*@__PURE__*/ core.$constructor("$ZodUnion", (inst, def
861
861
  }
862
862
  return undefined;
863
863
  });
864
+ const single = def.options.length === 1;
865
+ const first = def.options[0]._zod.run;
864
866
  inst._zod.parse = (payload, ctx) => {
867
+ if (single) {
868
+ return first(payload, ctx);
869
+ }
865
870
  let async = false;
866
871
  const results = [];
867
872
  for (const option of def.options) {
@@ -1053,10 +1058,10 @@ export const $ZodTuple = /*@__PURE__*/ core.$constructor("$ZodTuple", (inst, def
1053
1058
  const tooSmall = input.length < optStart - 1;
1054
1059
  if (tooBig || tooSmall) {
1055
1060
  payload.issues.push({
1061
+ ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
1056
1062
  input,
1057
1063
  inst,
1058
1064
  origin: "array",
1059
- ...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
1060
1065
  });
1061
1066
  return payload;
1062
1067
  }
@@ -1168,8 +1173,8 @@ export const $ZodRecord = /*@__PURE__*/ core.$constructor("$ZodRecord", (inst, d
1168
1173
  }
1169
1174
  if (keyResult.issues.length) {
1170
1175
  payload.issues.push({
1171
- origin: "record",
1172
1176
  code: "invalid_key",
1177
+ origin: "record",
1173
1178
  issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
1174
1179
  input: key,
1175
1180
  path: [key],
@@ -1240,8 +1245,8 @@ function handleMapResult(keyResult, valueResult, final, key, input, inst, ctx) {
1240
1245
  }
1241
1246
  else {
1242
1247
  final.issues.push({
1243
- origin: "map",
1244
1248
  code: "invalid_key",
1249
+ origin: "map",
1245
1250
  input,
1246
1251
  inst,
1247
1252
  issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
package/v4/core/util.cjs CHANGED
@@ -94,7 +94,14 @@ function cleanRegex(source) {
94
94
  }
95
95
  function floatSafeRemainder(val, step) {
96
96
  const valDecCount = (val.toString().split(".")[1] || "").length;
97
- const stepDecCount = (step.toString().split(".")[1] || "").length;
97
+ const stepString = step.toString();
98
+ let stepDecCount = (stepString.split(".")[1] || "").length;
99
+ if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
100
+ const match = stepString.match(/\d?e-(\d?)/);
101
+ if (match?.[1]) {
102
+ stepDecCount = Number.parseInt(match[1]);
103
+ }
104
+ }
98
105
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
99
106
  const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
100
107
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
@@ -483,6 +490,7 @@ function required(Class, schema, mask) {
483
490
  });
484
491
  return clone(schema, def);
485
492
  }
493
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
486
494
  function aborted(x, startIndex = 0) {
487
495
  for (let i = startIndex; i < x.issues.length; i++) {
488
496
  if (x.issues[i]?.continue !== true) {
package/v4/core/util.js CHANGED
@@ -48,7 +48,14 @@ export function cleanRegex(source) {
48
48
  }
49
49
  export function floatSafeRemainder(val, step) {
50
50
  const valDecCount = (val.toString().split(".")[1] || "").length;
51
- const stepDecCount = (step.toString().split(".")[1] || "").length;
51
+ const stepString = step.toString();
52
+ let stepDecCount = (stepString.split(".")[1] || "").length;
53
+ if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
54
+ const match = stepString.match(/\d?e-(\d?)/);
55
+ if (match?.[1]) {
56
+ stepDecCount = Number.parseInt(match[1]);
57
+ }
58
+ }
52
59
  const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
53
60
  const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
54
61
  const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
@@ -436,6 +443,7 @@ export function required(Class, schema, mask) {
436
443
  });
437
444
  return clone(schema, def);
438
445
  }
446
+ // invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
439
447
  export function aborted(x, startIndex = 0) {
440
448
  for (let i = startIndex; i < x.issues.length; i++) {
441
449
  if (x.issues[i]?.continue !== true) {
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 0,
7
- patch: 10,
7
+ patch: 11,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 0,
4
- patch: 10,
4
+ patch: 11,
5
5
  };
package/v4/locales/ar.cjs CHANGED
@@ -140,3 +140,4 @@ function default_1() {
140
140
  localeError: error(),
141
141
  };
142
142
  }
143
+ module.exports = exports.default;
@@ -1,4 +1,5 @@
1
1
  import type * as errors from "../core/errors.cjs";
2
- export default function (): {
2
+ declare function _default(): {
3
3
  localeError: errors.$ZodErrorMap;
4
4
  };
5
+ export = _default;
package/v4/locales/az.cjs CHANGED
@@ -139,3 +139,4 @@ function default_1() {
139
139
  localeError: error(),
140
140
  };
141
141
  }
142
+ module.exports = exports.default;
@@ -1,4 +1,5 @@
1
1
  import type * as errors from "../core/errors.cjs";
2
- export default function (): {
2
+ declare function _default(): {
3
3
  localeError: errors.$ZodErrorMap;
4
4
  };
5
+ export = _default;
package/v4/locales/be.cjs CHANGED
@@ -188,3 +188,4 @@ function default_1() {
188
188
  localeError: error(),
189
189
  };
190
190
  }
191
+ module.exports = exports.default;
@@ -1,4 +1,5 @@
1
1
  import type * as errors from "../core/errors.cjs";
2
- export default function (): {
2
+ declare function _default(): {
3
3
  localeError: errors.$ZodErrorMap;
4
4
  };
5
+ export = _default;
package/v4/locales/ca.cjs CHANGED
@@ -142,3 +142,4 @@ function default_1() {
142
142
  localeError: error(),
143
143
  };
144
144
  }
145
+ module.exports = exports.default;
@@ -1,4 +1,5 @@
1
1
  import type * as errors from "../core/errors.cjs";
2
- export default function (): {
2
+ declare function _default(): {
3
3
  localeError: errors.$ZodErrorMap;
4
4
  };
5
+ export = _default;
package/v4/locales/cs.cjs CHANGED
@@ -159,3 +159,4 @@ function default_1() {
159
159
  localeError: error(),
160
160
  };
161
161
  }
162
+ module.exports = exports.default;
@@ -1,4 +1,5 @@
1
1
  import type * as errors from "../core/errors.cjs";
2
- export default function (): {
2
+ declare function _default(): {
3
3
  localeError: errors.$ZodErrorMap;
4
4
  };
5
+ export = _default;