zod 3.25.12-alpha.0 → 3.25.13

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 (191) hide show
  1. package/package.json +16 -17
  2. package/dist/types/index.d.ts +0 -3
  3. package/dist/types/index.js +0 -3
  4. package/dist/types/v3/ZodError.d.ts +0 -164
  5. package/dist/types/v3/ZodError.js +0 -132
  6. package/dist/types/v3/benchmarks/datetime.d.ts +0 -5
  7. package/dist/types/v3/benchmarks/datetime.js +0 -49
  8. package/dist/types/v3/benchmarks/discriminatedUnion.d.ts +0 -5
  9. package/dist/types/v3/benchmarks/discriminatedUnion.js +0 -74
  10. package/dist/types/v3/benchmarks/index.d.ts +0 -1
  11. package/dist/types/v3/benchmarks/index.js +0 -54
  12. package/dist/types/v3/benchmarks/ipv4.d.ts +0 -5
  13. package/dist/types/v3/benchmarks/ipv4.js +0 -49
  14. package/dist/types/v3/benchmarks/object.d.ts +0 -5
  15. package/dist/types/v3/benchmarks/object.js +0 -65
  16. package/dist/types/v3/benchmarks/primitives.d.ts +0 -5
  17. package/dist/types/v3/benchmarks/primitives.js +0 -154
  18. package/dist/types/v3/benchmarks/realworld.d.ts +0 -5
  19. package/dist/types/v3/benchmarks/realworld.js +0 -51
  20. package/dist/types/v3/benchmarks/string.d.ts +0 -5
  21. package/dist/types/v3/benchmarks/string.js +0 -50
  22. package/dist/types/v3/benchmarks/union.d.ts +0 -5
  23. package/dist/types/v3/benchmarks/union.js +0 -74
  24. package/dist/types/v3/errors.d.ts +0 -5
  25. package/dist/types/v3/errors.js +0 -9
  26. package/dist/types/v3/external.d.ts +0 -6
  27. package/dist/types/v3/external.js +0 -6
  28. package/dist/types/v3/helpers/enumUtil.d.ts +0 -8
  29. package/dist/types/v3/helpers/enumUtil.js +0 -1
  30. package/dist/types/v3/helpers/errorUtil.d.ts +0 -9
  31. package/dist/types/v3/helpers/errorUtil.js +0 -6
  32. package/dist/types/v3/helpers/parseUtil.d.ts +0 -78
  33. package/dist/types/v3/helpers/parseUtil.js +0 -109
  34. package/dist/types/v3/helpers/partialUtil.d.ts +0 -8
  35. package/dist/types/v3/helpers/partialUtil.js +0 -1
  36. package/dist/types/v3/helpers/typeAliases.d.ts +0 -2
  37. package/dist/types/v3/helpers/typeAliases.js +0 -1
  38. package/dist/types/v3/helpers/util.d.ts +0 -85
  39. package/dist/types/v3/helpers/util.js +0 -133
  40. package/dist/types/v3/index.d.ts +0 -4
  41. package/dist/types/v3/index.js +0 -4
  42. package/dist/types/v3/locales/en.d.ts +0 -3
  43. package/dist/types/v3/locales/en.js +0 -107
  44. package/dist/types/v3/standard-schema.d.ts +0 -102
  45. package/dist/types/v3/standard-schema.js +0 -1
  46. package/dist/types/v3/tests/Mocker.d.ts +0 -17
  47. package/dist/types/v3/tests/Mocker.js +0 -53
  48. package/dist/types/v3/tests/language-server.source.d.ts +0 -70
  49. package/dist/types/v3/tests/language-server.source.js +0 -45
  50. package/dist/types/v3/types.d.ts +0 -1031
  51. package/dist/types/v3/types.js +0 -3713
  52. package/dist/types/v4/classic/checks.d.ts +0 -1
  53. package/dist/types/v4/classic/checks.js +0 -1
  54. package/dist/types/v4/classic/coerce.d.ts +0 -17
  55. package/dist/types/v4/classic/coerce.js +0 -17
  56. package/dist/types/v4/classic/compat.d.ts +0 -48
  57. package/dist/types/v4/classic/compat.js +0 -33
  58. package/dist/types/v4/classic/errors.d.ts +0 -30
  59. package/dist/types/v4/classic/errors.js +0 -41
  60. package/dist/types/v4/classic/external.d.ts +0 -8
  61. package/dist/types/v4/classic/external.js +0 -11
  62. package/dist/types/v4/classic/index.d.ts +0 -4
  63. package/dist/types/v4/classic/index.js +0 -4
  64. package/dist/types/v4/classic/iso.d.ts +0 -22
  65. package/dist/types/v4/classic/iso.js +0 -30
  66. package/dist/types/v4/classic/parse.d.ts +0 -23
  67. package/dist/types/v4/classic/parse.js +0 -6
  68. package/dist/types/v4/classic/schemas.d.ts +0 -653
  69. package/dist/types/v4/classic/schemas.js +0 -1012
  70. package/dist/types/v4/core/api.d.ts +0 -273
  71. package/dist/types/v4/core/api.js +0 -867
  72. package/dist/types/v4/core/checks.d.ts +0 -277
  73. package/dist/types/v4/core/checks.js +0 -535
  74. package/dist/types/v4/core/config.d.ts +0 -9
  75. package/dist/types/v4/core/config.js +0 -6
  76. package/dist/types/v4/core/core.d.ts +0 -43
  77. package/dist/types/v4/core/core.js +0 -53
  78. package/dist/types/v4/core/doc.d.ts +0 -14
  79. package/dist/types/v4/core/doc.js +0 -36
  80. package/dist/types/v4/core/errors.d.ts +0 -204
  81. package/dist/types/v4/core/errors.js +0 -206
  82. package/dist/types/v4/core/function.d.ts +0 -35
  83. package/dist/types/v4/core/function.js +0 -70
  84. package/dist/types/v4/core/index.d.ts +0 -15
  85. package/dist/types/v4/core/index.js +0 -15
  86. package/dist/types/v4/core/json-schema.d.ts +0 -100
  87. package/dist/types/v4/core/json-schema.js +0 -1
  88. package/dist/types/v4/core/parse.d.ts +0 -25
  89. package/dist/types/v4/core/parse.js +0 -57
  90. package/dist/types/v4/core/regexes.d.ts +0 -62
  91. package/dist/types/v4/core/regexes.js +0 -93
  92. package/dist/types/v4/core/registries.d.ts +0 -32
  93. package/dist/types/v4/core/registries.js +0 -42
  94. package/dist/types/v4/core/schemas.d.ts +0 -975
  95. package/dist/types/v4/core/schemas.js +0 -1740
  96. package/dist/types/v4/core/standard-schema.d.ts +0 -55
  97. package/dist/types/v4/core/standard-schema.js +0 -1
  98. package/dist/types/v4/core/to-json-schema.d.ts +0 -84
  99. package/dist/types/v4/core/to-json-schema.js +0 -665
  100. package/dist/types/v4/core/util.d.ts +0 -186
  101. package/dist/types/v4/core/util.js +0 -469
  102. package/dist/types/v4/core/versions.d.ts +0 -5
  103. package/dist/types/v4/core/versions.js +0 -5
  104. package/dist/types/v4/core/zsf.d.ts +0 -91
  105. package/dist/types/v4/core/zsf.js +0 -171
  106. package/dist/types/v4/index.d.ts +0 -3
  107. package/dist/types/v4/index.js +0 -3
  108. package/dist/types/v4/locales/ar.d.ts +0 -7
  109. package/dist/types/v4/locales/ar.js +0 -115
  110. package/dist/types/v4/locales/az.d.ts +0 -7
  111. package/dist/types/v4/locales/az.js +0 -114
  112. package/dist/types/v4/locales/be.d.ts +0 -7
  113. package/dist/types/v4/locales/be.js +0 -163
  114. package/dist/types/v4/locales/ca.d.ts +0 -7
  115. package/dist/types/v4/locales/ca.js +0 -117
  116. package/dist/types/v4/locales/cs.d.ts +0 -7
  117. package/dist/types/v4/locales/cs.js +0 -134
  118. package/dist/types/v4/locales/de.d.ts +0 -7
  119. package/dist/types/v4/locales/de.js +0 -115
  120. package/dist/types/v4/locales/en.d.ts +0 -7
  121. package/dist/types/v4/locales/en.js +0 -117
  122. package/dist/types/v4/locales/es.d.ts +0 -7
  123. package/dist/types/v4/locales/es.js +0 -116
  124. package/dist/types/v4/locales/fa.d.ts +0 -7
  125. package/dist/types/v4/locales/fa.js +0 -121
  126. package/dist/types/v4/locales/fi.d.ts +0 -7
  127. package/dist/types/v4/locales/fi.js +0 -121
  128. package/dist/types/v4/locales/fr.d.ts +0 -7
  129. package/dist/types/v4/locales/fr.js +0 -115
  130. package/dist/types/v4/locales/frCA.d.ts +0 -7
  131. package/dist/types/v4/locales/frCA.js +0 -116
  132. package/dist/types/v4/locales/he.d.ts +0 -7
  133. package/dist/types/v4/locales/he.js +0 -116
  134. package/dist/types/v4/locales/hu.d.ts +0 -7
  135. package/dist/types/v4/locales/hu.js +0 -116
  136. package/dist/types/v4/locales/id.d.ts +0 -7
  137. package/dist/types/v4/locales/id.js +0 -115
  138. package/dist/types/v4/locales/index.d.ts +0 -34
  139. package/dist/types/v4/locales/index.js +0 -34
  140. package/dist/types/v4/locales/it.d.ts +0 -7
  141. package/dist/types/v4/locales/it.js +0 -116
  142. package/dist/types/v4/locales/ja.d.ts +0 -7
  143. package/dist/types/v4/locales/ja.js +0 -114
  144. package/dist/types/v4/locales/ko.d.ts +0 -7
  145. package/dist/types/v4/locales/ko.js +0 -120
  146. package/dist/types/v4/locales/mk.d.ts +0 -7
  147. package/dist/types/v4/locales/mk.js +0 -117
  148. package/dist/types/v4/locales/ms.d.ts +0 -7
  149. package/dist/types/v4/locales/ms.js +0 -115
  150. package/dist/types/v4/locales/no.d.ts +0 -7
  151. package/dist/types/v4/locales/no.js +0 -115
  152. package/dist/types/v4/locales/ota.d.ts +0 -7
  153. package/dist/types/v4/locales/ota.js +0 -116
  154. package/dist/types/v4/locales/pl.d.ts +0 -7
  155. package/dist/types/v4/locales/pl.js +0 -116
  156. package/dist/types/v4/locales/pt.d.ts +0 -7
  157. package/dist/types/v4/locales/pt.js +0 -115
  158. package/dist/types/v4/locales/ru.d.ts +0 -7
  159. package/dist/types/v4/locales/ru.js +0 -163
  160. package/dist/types/v4/locales/sl.d.ts +0 -7
  161. package/dist/types/v4/locales/sl.js +0 -116
  162. package/dist/types/v4/locales/ta.d.ts +0 -7
  163. package/dist/types/v4/locales/ta.js +0 -116
  164. package/dist/types/v4/locales/th.d.ts +0 -7
  165. package/dist/types/v4/locales/th.js +0 -116
  166. package/dist/types/v4/locales/tr.d.ts +0 -7
  167. package/dist/types/v4/locales/tr.js +0 -114
  168. package/dist/types/v4/locales/ua.d.ts +0 -7
  169. package/dist/types/v4/locales/ua.js +0 -116
  170. package/dist/types/v4/locales/ur.d.ts +0 -7
  171. package/dist/types/v4/locales/ur.js +0 -116
  172. package/dist/types/v4/locales/vi.d.ts +0 -7
  173. package/dist/types/v4/locales/vi.js +0 -115
  174. package/dist/types/v4/locales/zh-CN.d.ts +0 -7
  175. package/dist/types/v4/locales/zh-CN.js +0 -115
  176. package/dist/types/v4/locales/zh-tw.d.ts +0 -7
  177. package/dist/types/v4/locales/zh-tw.js +0 -116
  178. package/dist/types/v4/mini/checks.d.ts +0 -1
  179. package/dist/types/v4/mini/checks.js +0 -1
  180. package/dist/types/v4/mini/coerce.d.ts +0 -7
  181. package/dist/types/v4/mini/coerce.js +0 -17
  182. package/dist/types/v4/mini/external.d.ts +0 -7
  183. package/dist/types/v4/mini/external.js +0 -7
  184. package/dist/types/v4/mini/index.d.ts +0 -3
  185. package/dist/types/v4/mini/index.js +0 -3
  186. package/dist/types/v4/mini/iso.d.ts +0 -22
  187. package/dist/types/v4/mini/iso.js +0 -30
  188. package/dist/types/v4/mini/parse.d.ts +0 -1
  189. package/dist/types/v4/mini/parse.js +0 -1
  190. package/dist/types/v4/mini/schemas.d.ts +0 -405
  191. package/dist/types/v4/mini/schemas.js +0 -738
@@ -1,1012 +0,0 @@
1
- import * as core from "zod/v4/core";
2
- import { util } from "zod/v4/core";
3
- import * as checks from "./checks.js";
4
- import * as iso from "./iso.js";
5
- import * as parse from "./parse.js";
6
- export * as iso from "./iso.js";
7
- export * as coerce from "./coerce.js";
8
- export const ZodType = /*@__PURE__*/ core.$constructor("ZodType", (inst, def) => {
9
- core.$ZodType.init(inst, def);
10
- inst.def = def;
11
- inst._def = def;
12
- // base methods
13
- inst.check = (...checks) => {
14
- return inst.clone({
15
- ...def,
16
- checks: [
17
- ...(def.checks ?? []),
18
- ...checks.map((ch) => typeof ch === "function" ? { _zod: { check: ch, def: { check: "custom" }, onattach: [] } } : ch),
19
- ],
20
- }
21
- // { parent: true }
22
- );
23
- };
24
- inst.clone = (def, params) => core.clone(inst, def, params);
25
- inst.brand = () => inst;
26
- inst.register = ((reg, meta) => {
27
- reg.add(inst, meta);
28
- return inst;
29
- });
30
- // const parse: <T extends core.$ZodType>(
31
- // schema: T,
32
- // value: unknown,
33
- // _ctx?: core.ParseContext<core.$ZodIssue>
34
- // ) => core.output<T> = /* @__PURE__ */ core._parse(ZodError, parse) as any;
35
- // const safeParse: <T extends core.$ZodType>(
36
- // schema: T,
37
- // value: unknown,
38
- // _ctx?: core.ParseContext<core.$ZodIssue>
39
- // ) => ZodSafeParseResult<core.output<T>> = /* @__PURE__ */ core._safeParse(ZodError) as any;
40
- // const parseAsync: <T extends core.$ZodType>(
41
- // schema: T,
42
- // value: unknown,
43
- // _ctx?: core.ParseContext<core.$ZodIssue>
44
- // ) => Promise<core.output<T>> = /* @__PURE__ */ core._parseAsync(ZodError) as any;
45
- // const safeParseAsync: <T extends core.$ZodType>(
46
- // schema: T,
47
- // value: unknown,
48
- // _ctx?: core.ParseContext<core.$ZodIssue>
49
- // ) => Promise<ZodSafeParseResult<core.output<T>>> = /* @__PURE__ */ core._safeParseAsync(ZodError) as any;
50
- // parsing
51
- inst.parse = (data, params) => parse.parse(inst, data, params, { callee: inst.parse });
52
- inst.safeParse = (data, params) => parse.safeParse(inst, data, params);
53
- inst.parseAsync = async (data, params) => parse.parseAsync(inst, data, params, { callee: inst.parseAsync });
54
- inst.safeParseAsync = async (data, params) => parse.safeParseAsync(inst, data, params);
55
- inst.spa = inst.safeParseAsync;
56
- // refinements
57
- inst.refine = (check, params) => inst.check(refine(check, params));
58
- inst.superRefine = (refinement) => inst.check(superRefine(refinement));
59
- inst.overwrite = (fn) => inst.check(checks.overwrite(fn));
60
- // wrappers
61
- inst.optional = () => optional(inst);
62
- inst.nullable = () => nullable(inst);
63
- inst.nullish = () => optional(nullable(inst));
64
- inst.nonoptional = (params) => nonoptional(inst, params);
65
- inst.array = () => array(inst);
66
- inst.or = (arg) => union([inst, arg]);
67
- inst.and = (arg) => intersection(inst, arg);
68
- inst.transform = (tx) => pipe(inst, transform(tx));
69
- inst.default = (def) => _default(inst, def);
70
- inst.prefault = (def) => prefault(inst, def);
71
- // inst.coalesce = (def, params) => coalesce(inst, def, params);
72
- inst.catch = (params) => _catch(inst, params);
73
- inst.pipe = (target) => pipe(inst, target);
74
- inst.readonly = () => readonly(inst);
75
- // meta
76
- inst.describe = (description) => {
77
- const cl = inst.clone();
78
- core.globalRegistry.add(cl, { description });
79
- return cl;
80
- };
81
- Object.defineProperty(inst, "description", {
82
- get() {
83
- return core.globalRegistry.get(inst)?.description;
84
- },
85
- configurable: true,
86
- });
87
- inst.meta = (...args) => {
88
- if (args.length === 0) {
89
- return core.globalRegistry.get(inst);
90
- }
91
- const cl = inst.clone();
92
- core.globalRegistry.add(cl, args[0]);
93
- return cl;
94
- };
95
- // helpers
96
- inst.isOptional = () => inst.safeParse(undefined).success;
97
- inst.isNullable = () => inst.safeParse(null).success;
98
- return inst;
99
- });
100
- /** @internal */
101
- export const _ZodString = /*@__PURE__*/ core.$constructor("_ZodString", (inst, def) => {
102
- core.$ZodString.init(inst, def);
103
- ZodType.init(inst, def);
104
- const bag = inst._zod.bag;
105
- inst.format = bag.format ?? null;
106
- inst.minLength = bag.minimum ?? null;
107
- inst.maxLength = bag.maximum ?? null;
108
- // validations
109
- inst.regex = (...args) => inst.check(checks.regex(...args));
110
- inst.includes = (...args) => inst.check(checks.includes(...args));
111
- inst.startsWith = (params) => inst.check(checks.startsWith(params));
112
- inst.endsWith = (params) => inst.check(checks.endsWith(params));
113
- inst.min = (...args) => inst.check(checks.minLength(...args));
114
- inst.max = (...args) => inst.check(checks.maxLength(...args));
115
- inst.length = (...args) => inst.check(checks.length(...args));
116
- inst.nonempty = (...args) => inst.check(checks.minLength(1, ...args));
117
- inst.lowercase = (params) => inst.check(checks.lowercase(params));
118
- inst.uppercase = (params) => inst.check(checks.uppercase(params));
119
- // transforms
120
- inst.trim = () => inst.check(checks.trim());
121
- inst.normalize = (...args) => inst.check(checks.normalize(...args));
122
- inst.toLowerCase = () => inst.check(checks.toLowerCase());
123
- inst.toUpperCase = () => inst.check(checks.toUpperCase());
124
- });
125
- export const ZodString = /*@__PURE__*/ core.$constructor("ZodString", (inst, def) => {
126
- core.$ZodString.init(inst, def);
127
- _ZodString.init(inst, def);
128
- inst.email = (params) => inst.check(core._email(ZodEmail, params));
129
- inst.url = (params) => inst.check(core._url(ZodURL, params));
130
- inst.jwt = (params) => inst.check(core._jwt(ZodJWT, params));
131
- inst.emoji = (params) => inst.check(core._emoji(ZodEmoji, params));
132
- inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
133
- inst.uuid = (params) => inst.check(core._uuid(ZodUUID, params));
134
- inst.uuidv4 = (params) => inst.check(core._uuidv4(ZodUUID, params));
135
- inst.uuidv6 = (params) => inst.check(core._uuidv6(ZodUUID, params));
136
- inst.uuidv7 = (params) => inst.check(core._uuidv7(ZodUUID, params));
137
- inst.nanoid = (params) => inst.check(core._nanoid(ZodNanoID, params));
138
- inst.guid = (params) => inst.check(core._guid(ZodGUID, params));
139
- inst.cuid = (params) => inst.check(core._cuid(ZodCUID, params));
140
- inst.cuid2 = (params) => inst.check(core._cuid2(ZodCUID2, params));
141
- inst.ulid = (params) => inst.check(core._ulid(ZodULID, params));
142
- inst.base64 = (params) => inst.check(core._base64(ZodBase64, params));
143
- inst.base64url = (params) => inst.check(core._base64url(ZodBase64URL, params));
144
- inst.xid = (params) => inst.check(core._xid(ZodXID, params));
145
- inst.ksuid = (params) => inst.check(core._ksuid(ZodKSUID, params));
146
- inst.ipv4 = (params) => inst.check(core._ipv4(ZodIPv4, params));
147
- inst.ipv6 = (params) => inst.check(core._ipv6(ZodIPv6, params));
148
- inst.cidrv4 = (params) => inst.check(core._cidrv4(ZodCIDRv4, params));
149
- inst.cidrv6 = (params) => inst.check(core._cidrv6(ZodCIDRv6, params));
150
- inst.e164 = (params) => inst.check(core._e164(ZodE164, params));
151
- // iso
152
- inst.datetime = (params) => inst.check(iso.datetime(params));
153
- inst.date = (params) => inst.check(iso.date(params));
154
- inst.time = (params) => inst.check(iso.time(params));
155
- inst.duration = (params) => inst.check(iso.duration(params));
156
- });
157
- export function string(params) {
158
- return core._string(ZodString, params);
159
- }
160
- export const ZodStringFormat = /*@__PURE__*/ core.$constructor("ZodStringFormat", (inst, def) => {
161
- core.$ZodStringFormat.init(inst, def);
162
- _ZodString.init(inst, def);
163
- });
164
- export const ZodEmail = /*@__PURE__*/ core.$constructor("ZodEmail", (inst, def) => {
165
- // ZodStringFormat.init(inst, def);
166
- core.$ZodEmail.init(inst, def);
167
- ZodStringFormat.init(inst, def);
168
- });
169
- export function email(params) {
170
- return core._email(ZodEmail, params);
171
- }
172
- export const ZodGUID = /*@__PURE__*/ core.$constructor("ZodGUID", (inst, def) => {
173
- // ZodStringFormat.init(inst, def);
174
- core.$ZodGUID.init(inst, def);
175
- ZodStringFormat.init(inst, def);
176
- });
177
- export function guid(params) {
178
- return core._guid(ZodGUID, params);
179
- }
180
- export const ZodUUID = /*@__PURE__*/ core.$constructor("ZodUUID", (inst, def) => {
181
- // ZodStringFormat.init(inst, def);
182
- core.$ZodUUID.init(inst, def);
183
- ZodStringFormat.init(inst, def);
184
- });
185
- export function uuid(params) {
186
- return core._uuid(ZodUUID, params);
187
- }
188
- export function uuidv4(params) {
189
- return core._uuidv4(ZodUUID, params);
190
- }
191
- // ZodUUIDv6
192
- export function uuidv6(params) {
193
- return core._uuidv6(ZodUUID, params);
194
- }
195
- // ZodUUIDv7
196
- export function uuidv7(params) {
197
- return core._uuidv7(ZodUUID, params);
198
- }
199
- export const ZodURL = /*@__PURE__*/ core.$constructor("ZodURL", (inst, def) => {
200
- // ZodStringFormat.init(inst, def);
201
- core.$ZodURL.init(inst, def);
202
- ZodStringFormat.init(inst, def);
203
- });
204
- export function url(params) {
205
- return core._url(ZodURL, params);
206
- }
207
- export const ZodEmoji = /*@__PURE__*/ core.$constructor("ZodEmoji", (inst, def) => {
208
- // ZodStringFormat.init(inst, def);
209
- core.$ZodEmoji.init(inst, def);
210
- ZodStringFormat.init(inst, def);
211
- });
212
- export function emoji(params) {
213
- return core._emoji(ZodEmoji, params);
214
- }
215
- export const ZodNanoID = /*@__PURE__*/ core.$constructor("ZodNanoID", (inst, def) => {
216
- // ZodStringFormat.init(inst, def);
217
- core.$ZodNanoID.init(inst, def);
218
- ZodStringFormat.init(inst, def);
219
- });
220
- export function nanoid(params) {
221
- return core._nanoid(ZodNanoID, params);
222
- }
223
- export const ZodCUID = /*@__PURE__*/ core.$constructor("ZodCUID", (inst, def) => {
224
- // ZodStringFormat.init(inst, def);
225
- core.$ZodCUID.init(inst, def);
226
- ZodStringFormat.init(inst, def);
227
- });
228
- export function cuid(params) {
229
- return core._cuid(ZodCUID, params);
230
- }
231
- export const ZodCUID2 = /*@__PURE__*/ core.$constructor("ZodCUID2", (inst, def) => {
232
- // ZodStringFormat.init(inst, def);
233
- core.$ZodCUID2.init(inst, def);
234
- ZodStringFormat.init(inst, def);
235
- });
236
- export function cuid2(params) {
237
- return core._cuid2(ZodCUID2, params);
238
- }
239
- export const ZodULID = /*@__PURE__*/ core.$constructor("ZodULID", (inst, def) => {
240
- // ZodStringFormat.init(inst, def);
241
- core.$ZodULID.init(inst, def);
242
- ZodStringFormat.init(inst, def);
243
- });
244
- export function ulid(params) {
245
- return core._ulid(ZodULID, params);
246
- }
247
- export const ZodXID = /*@__PURE__*/ core.$constructor("ZodXID", (inst, def) => {
248
- // ZodStringFormat.init(inst, def);
249
- core.$ZodXID.init(inst, def);
250
- ZodStringFormat.init(inst, def);
251
- });
252
- export function xid(params) {
253
- return core._xid(ZodXID, params);
254
- }
255
- export const ZodKSUID = /*@__PURE__*/ core.$constructor("ZodKSUID", (inst, def) => {
256
- // ZodStringFormat.init(inst, def);
257
- core.$ZodKSUID.init(inst, def);
258
- ZodStringFormat.init(inst, def);
259
- });
260
- export function ksuid(params) {
261
- return core._ksuid(ZodKSUID, params);
262
- }
263
- export const ZodIPv4 = /*@__PURE__*/ core.$constructor("ZodIPv4", (inst, def) => {
264
- // ZodStringFormat.init(inst, def);
265
- core.$ZodIPv4.init(inst, def);
266
- ZodStringFormat.init(inst, def);
267
- });
268
- export function ipv4(params) {
269
- return core._ipv4(ZodIPv4, params);
270
- }
271
- export const ZodIPv6 = /*@__PURE__*/ core.$constructor("ZodIPv6", (inst, def) => {
272
- // ZodStringFormat.init(inst, def);
273
- core.$ZodIPv6.init(inst, def);
274
- ZodStringFormat.init(inst, def);
275
- });
276
- export function ipv6(params) {
277
- return core._ipv6(ZodIPv6, params);
278
- }
279
- export const ZodCIDRv4 = /*@__PURE__*/ core.$constructor("ZodCIDRv4", (inst, def) => {
280
- core.$ZodCIDRv4.init(inst, def);
281
- ZodStringFormat.init(inst, def);
282
- });
283
- export function cidrv4(params) {
284
- return core._cidrv4(ZodCIDRv4, params);
285
- }
286
- export const ZodCIDRv6 = /*@__PURE__*/ core.$constructor("ZodCIDRv6", (inst, def) => {
287
- core.$ZodCIDRv6.init(inst, def);
288
- ZodStringFormat.init(inst, def);
289
- });
290
- export function cidrv6(params) {
291
- return core._cidrv6(ZodCIDRv6, params);
292
- }
293
- export const ZodBase64 = /*@__PURE__*/ core.$constructor("ZodBase64", (inst, def) => {
294
- // ZodStringFormat.init(inst, def);
295
- core.$ZodBase64.init(inst, def);
296
- ZodStringFormat.init(inst, def);
297
- });
298
- export function base64(params) {
299
- return core._base64(ZodBase64, params);
300
- }
301
- export const ZodBase64URL = /*@__PURE__*/ core.$constructor("ZodBase64URL", (inst, def) => {
302
- // ZodStringFormat.init(inst, def);
303
- core.$ZodBase64URL.init(inst, def);
304
- ZodStringFormat.init(inst, def);
305
- });
306
- export function base64url(params) {
307
- return core._base64url(ZodBase64URL, params);
308
- }
309
- export const ZodE164 = /*@__PURE__*/ core.$constructor("ZodE164", (inst, def) => {
310
- // ZodStringFormat.init(inst, def);
311
- core.$ZodE164.init(inst, def);
312
- ZodStringFormat.init(inst, def);
313
- });
314
- export function e164(params) {
315
- return core._e164(ZodE164, params);
316
- }
317
- export const ZodJWT = /*@__PURE__*/ core.$constructor("ZodJWT", (inst, def) => {
318
- // ZodStringFormat.init(inst, def);
319
- core.$ZodJWT.init(inst, def);
320
- ZodStringFormat.init(inst, def);
321
- });
322
- export function jwt(params) {
323
- return core._jwt(ZodJWT, params);
324
- }
325
- export const ZodNumber = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def) => {
326
- core.$ZodNumber.init(inst, def);
327
- ZodType.init(inst, def);
328
- inst.gt = (value, params) => inst.check(checks.gt(value, params));
329
- inst.gte = (value, params) => inst.check(checks.gte(value, params));
330
- inst.min = (value, params) => inst.check(checks.gte(value, params));
331
- inst.lt = (value, params) => inst.check(checks.lt(value, params));
332
- inst.lte = (value, params) => inst.check(checks.lte(value, params));
333
- inst.max = (value, params) => inst.check(checks.lte(value, params));
334
- inst.int = (params) => inst.check(int(params));
335
- inst.safe = (params) => inst.check(int(params));
336
- inst.positive = (params) => inst.check(checks.gt(0, params));
337
- inst.nonnegative = (params) => inst.check(checks.gte(0, params));
338
- inst.negative = (params) => inst.check(checks.lt(0, params));
339
- inst.nonpositive = (params) => inst.check(checks.lte(0, params));
340
- inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
341
- inst.step = (value, params) => inst.check(checks.multipleOf(value, params));
342
- // inst.finite = (params) => inst.check(core.finite(params));
343
- inst.finite = () => inst;
344
- const bag = inst._zod.bag;
345
- inst.minValue =
346
- Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
347
- inst.maxValue =
348
- Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
349
- inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? 0.5);
350
- inst.isFinite = true;
351
- inst.format = bag.format ?? null;
352
- });
353
- export function number(params) {
354
- return core._number(ZodNumber, params);
355
- }
356
- export const ZodNumberFormat = /*@__PURE__*/ core.$constructor("ZodNumberFormat", (inst, def) => {
357
- core.$ZodNumberFormat.init(inst, def);
358
- ZodNumber.init(inst, def);
359
- });
360
- export function int(params) {
361
- return core._int(ZodNumberFormat, params);
362
- }
363
- export function float32(params) {
364
- return core._float32(ZodNumberFormat, params);
365
- }
366
- export function float64(params) {
367
- return core._float64(ZodNumberFormat, params);
368
- }
369
- export function int32(params) {
370
- return core._int32(ZodNumberFormat, params);
371
- }
372
- export function uint32(params) {
373
- return core._uint32(ZodNumberFormat, params);
374
- }
375
- export const ZodBoolean = /*@__PURE__*/ core.$constructor("ZodBoolean", (inst, def) => {
376
- core.$ZodBoolean.init(inst, def);
377
- ZodType.init(inst, def);
378
- });
379
- export function boolean(params) {
380
- return core._boolean(ZodBoolean, params);
381
- }
382
- export const ZodBigInt = /*@__PURE__*/ core.$constructor("ZodBigInt", (inst, def) => {
383
- core.$ZodBigInt.init(inst, def);
384
- ZodType.init(inst, def);
385
- inst.gte = (value, params) => inst.check(checks.gte(value, params));
386
- inst.min = (value, params) => inst.check(checks.gte(value, params));
387
- inst.gt = (value, params) => inst.check(checks.gt(value, params));
388
- inst.gte = (value, params) => inst.check(checks.gte(value, params));
389
- inst.min = (value, params) => inst.check(checks.gte(value, params));
390
- inst.lt = (value, params) => inst.check(checks.lt(value, params));
391
- inst.lte = (value, params) => inst.check(checks.lte(value, params));
392
- inst.max = (value, params) => inst.check(checks.lte(value, params));
393
- inst.positive = (params) => inst.check(checks.gt(BigInt(0), params));
394
- inst.negative = (params) => inst.check(checks.lt(BigInt(0), params));
395
- inst.nonpositive = (params) => inst.check(checks.lte(BigInt(0), params));
396
- inst.nonnegative = (params) => inst.check(checks.gte(BigInt(0), params));
397
- inst.multipleOf = (value, params) => inst.check(checks.multipleOf(value, params));
398
- const bag = inst._zod.bag;
399
- inst.minValue = bag.minimum ?? null;
400
- inst.maxValue = bag.maximum ?? null;
401
- inst.format = bag.format ?? null;
402
- });
403
- export function bigint(params) {
404
- return core._bigint(ZodBigInt, params);
405
- }
406
- export const ZodBigIntFormat = /*@__PURE__*/ core.$constructor("ZodBigIntFormat", (inst, def) => {
407
- core.$ZodBigIntFormat.init(inst, def);
408
- ZodBigInt.init(inst, def);
409
- });
410
- // int64
411
- export function int64(params) {
412
- return core._int64(ZodBigIntFormat, params);
413
- }
414
- // uint64
415
- export function uint64(params) {
416
- return core._uint64(ZodBigIntFormat, params);
417
- }
418
- export const ZodSymbol = /*@__PURE__*/ core.$constructor("ZodSymbol", (inst, def) => {
419
- core.$ZodSymbol.init(inst, def);
420
- ZodType.init(inst, def);
421
- });
422
- export function symbol(params) {
423
- return core._symbol(ZodSymbol, params);
424
- }
425
- export const ZodUndefined = /*@__PURE__*/ core.$constructor("ZodUndefined", (inst, def) => {
426
- core.$ZodUndefined.init(inst, def);
427
- ZodType.init(inst, def);
428
- });
429
- function _undefined(params) {
430
- return core._undefined(ZodUndefined, params);
431
- }
432
- export { _undefined as undefined };
433
- export const ZodNull = /*@__PURE__*/ core.$constructor("ZodNull", (inst, def) => {
434
- core.$ZodNull.init(inst, def);
435
- ZodType.init(inst, def);
436
- });
437
- function _null(params) {
438
- return core._null(ZodNull, params);
439
- }
440
- export { _null as null };
441
- export const ZodAny = /*@__PURE__*/ core.$constructor("ZodAny", (inst, def) => {
442
- core.$ZodAny.init(inst, def);
443
- ZodType.init(inst, def);
444
- });
445
- export function any() {
446
- return core._any(ZodAny);
447
- }
448
- export const ZodUnknown = /*@__PURE__*/ core.$constructor("ZodUnknown", (inst, def) => {
449
- core.$ZodUnknown.init(inst, def);
450
- ZodType.init(inst, def);
451
- });
452
- export function unknown() {
453
- return core._unknown(ZodUnknown);
454
- }
455
- export const ZodNever = /*@__PURE__*/ core.$constructor("ZodNever", (inst, def) => {
456
- core.$ZodNever.init(inst, def);
457
- ZodType.init(inst, def);
458
- });
459
- export function never(params) {
460
- return core._never(ZodNever, params);
461
- }
462
- export const ZodVoid = /*@__PURE__*/ core.$constructor("ZodVoid", (inst, def) => {
463
- core.$ZodVoid.init(inst, def);
464
- ZodType.init(inst, def);
465
- });
466
- function _void(params) {
467
- return core._void(ZodVoid, params);
468
- }
469
- export { _void as void };
470
- export const ZodDate = /*@__PURE__*/ core.$constructor("ZodDate", (inst, def) => {
471
- core.$ZodDate.init(inst, def);
472
- ZodType.init(inst, def);
473
- inst.min = (value, params) => inst.check(checks.gte(value, params));
474
- inst.max = (value, params) => inst.check(checks.lte(value, params));
475
- const c = inst._zod.bag;
476
- inst.minDate = c.minimum ? new Date(c.minimum) : null;
477
- inst.maxDate = c.maximum ? new Date(c.maximum) : null;
478
- });
479
- export function date(params) {
480
- return core._date(ZodDate, params);
481
- }
482
- export const ZodArray = /*@__PURE__*/ core.$constructor("ZodArray", (inst, def) => {
483
- core.$ZodArray.init(inst, def);
484
- ZodType.init(inst, def);
485
- inst.element = def.element;
486
- inst.min = (minLength, params) => inst.check(checks.minLength(minLength, params));
487
- inst.nonempty = (params) => inst.check(checks.minLength(1, params));
488
- inst.max = (maxLength, params) => inst.check(checks.maxLength(maxLength, params));
489
- inst.length = (len, params) => inst.check(checks.length(len, params));
490
- });
491
- export function array(element, params) {
492
- return core._array(ZodArray, element, params);
493
- }
494
- // .keyof
495
- export function keyof(schema) {
496
- const shape = schema._zod.def.shape;
497
- return literal(Object.keys(shape));
498
- }
499
- export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
500
- core.$ZodObject.init(inst, def);
501
- ZodType.init(inst, def);
502
- util.defineLazy(inst, "shape", () => {
503
- return Object.fromEntries(Object.entries(inst._zod.def.shape));
504
- });
505
- inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
506
- inst.catchall = (catchall) => inst.clone({ ...inst._zod.def, catchall });
507
- inst.passthrough = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
508
- // inst.nonstrict = () => inst.clone({ ...inst._zod.def, catchall: api.unknown() });
509
- inst.loose = () => inst.clone({ ...inst._zod.def, catchall: unknown() });
510
- inst.strict = () => inst.clone({ ...inst._zod.def, catchall: never() });
511
- inst.strip = () => inst.clone({ ...inst._zod.def, catchall: undefined });
512
- inst.extend = (incoming) => {
513
- return util.extend(inst, incoming);
514
- };
515
- inst.merge = (other) => util.merge(inst, other);
516
- inst.pick = (mask) => util.pick(inst, mask);
517
- inst.omit = (mask) => util.omit(inst, mask);
518
- inst.partial = (...args) => util.partial(ZodOptional, inst, args[0]);
519
- inst.required = (...args) => util.required(ZodNonOptional, inst, args[0]);
520
- });
521
- export function object(shape, params) {
522
- const def = {
523
- type: "object",
524
- get shape() {
525
- util.assignProp(this, "shape", { ...shape });
526
- return this.shape;
527
- },
528
- ...util.normalizeParams(params),
529
- };
530
- return new ZodObject(def);
531
- }
532
- // strictObject
533
- export function strictObject(shape, params) {
534
- return new ZodObject({
535
- type: "object",
536
- get shape() {
537
- util.assignProp(this, "shape", { ...shape });
538
- return this.shape;
539
- },
540
- catchall: never(),
541
- ...util.normalizeParams(params),
542
- });
543
- }
544
- // looseObject
545
- export function looseObject(shape, params) {
546
- return new ZodObject({
547
- type: "object",
548
- get shape() {
549
- util.assignProp(this, "shape", { ...shape });
550
- return this.shape;
551
- },
552
- catchall: unknown(),
553
- ...util.normalizeParams(params),
554
- });
555
- }
556
- export const ZodUnion = /*@__PURE__*/ core.$constructor("ZodUnion", (inst, def) => {
557
- core.$ZodUnion.init(inst, def);
558
- ZodType.init(inst, def);
559
- inst.options = def.options;
560
- });
561
- export function union(options, params) {
562
- return new ZodUnion({
563
- type: "union",
564
- options,
565
- ...util.normalizeParams(params),
566
- });
567
- }
568
- export const ZodDiscriminatedUnion = /*@__PURE__*/ core.$constructor("ZodDiscriminatedUnion", (inst, def) => {
569
- ZodUnion.init(inst, def);
570
- core.$ZodDiscriminatedUnion.init(inst, def);
571
- });
572
- export function discriminatedUnion(discriminator, options, params) {
573
- // const [options, params] = args;
574
- return new ZodDiscriminatedUnion({
575
- type: "union",
576
- options,
577
- discriminator,
578
- ...util.normalizeParams(params),
579
- });
580
- }
581
- export const ZodIntersection = /*@__PURE__*/ core.$constructor("ZodIntersection", (inst, def) => {
582
- core.$ZodIntersection.init(inst, def);
583
- ZodType.init(inst, def);
584
- });
585
- export function intersection(left, right) {
586
- return new ZodIntersection({
587
- type: "intersection",
588
- left,
589
- right,
590
- });
591
- }
592
- export const ZodTuple = /*@__PURE__*/ core.$constructor("ZodTuple", (inst, def) => {
593
- core.$ZodTuple.init(inst, def);
594
- ZodType.init(inst, def);
595
- inst.rest = (rest) => inst.clone({
596
- ...inst._zod.def,
597
- rest,
598
- });
599
- });
600
- export function tuple(items, _paramsOrRest, _params) {
601
- const hasRest = _paramsOrRest instanceof core.$ZodType;
602
- const params = hasRest ? _params : _paramsOrRest;
603
- const rest = hasRest ? _paramsOrRest : null;
604
- return new ZodTuple({
605
- type: "tuple",
606
- items,
607
- rest,
608
- ...util.normalizeParams(params),
609
- });
610
- }
611
- export const ZodRecord = /*@__PURE__*/ core.$constructor("ZodRecord", (inst, def) => {
612
- core.$ZodRecord.init(inst, def);
613
- ZodType.init(inst, def);
614
- inst.keyType = def.keyType;
615
- inst.valueType = def.valueType;
616
- });
617
- export function record(keyType, valueType, params) {
618
- return new ZodRecord({
619
- type: "record",
620
- keyType,
621
- valueType,
622
- ...util.normalizeParams(params),
623
- });
624
- }
625
- export function partialRecord(keyType, valueType, params) {
626
- return new ZodRecord({
627
- type: "record",
628
- keyType: union([keyType, never()]),
629
- valueType,
630
- ...util.normalizeParams(params),
631
- });
632
- }
633
- export const ZodMap = /*@__PURE__*/ core.$constructor("ZodMap", (inst, def) => {
634
- core.$ZodMap.init(inst, def);
635
- ZodType.init(inst, def);
636
- inst.keyType = def.keyType;
637
- inst.valueType = def.valueType;
638
- });
639
- export function map(keyType, valueType, params) {
640
- return new ZodMap({
641
- type: "map",
642
- keyType,
643
- valueType,
644
- ...util.normalizeParams(params),
645
- });
646
- }
647
- export const ZodSet = /*@__PURE__*/ core.$constructor("ZodSet", (inst, def) => {
648
- core.$ZodSet.init(inst, def);
649
- ZodType.init(inst, def);
650
- inst.min = (...args) => inst.check(core._minSize(...args));
651
- inst.nonempty = (params) => inst.check(core._minSize(1, params));
652
- inst.max = (...args) => inst.check(core._maxSize(...args));
653
- inst.size = (...args) => inst.check(core._size(...args));
654
- });
655
- export function set(valueType, params) {
656
- return new ZodSet({
657
- type: "set",
658
- valueType,
659
- ...util.normalizeParams(params),
660
- });
661
- }
662
- export const ZodEnum = /*@__PURE__*/ core.$constructor("ZodEnum", (inst, def) => {
663
- core.$ZodEnum.init(inst, def);
664
- ZodType.init(inst, def);
665
- inst.enum = def.entries;
666
- inst.options = Object.values(def.entries);
667
- const keys = new Set(Object.keys(def.entries));
668
- inst.extract = (values, params) => {
669
- const newEntries = {};
670
- for (const value of values) {
671
- if (keys.has(value)) {
672
- newEntries[value] = def.entries[value];
673
- }
674
- else
675
- throw new Error(`Key ${value} not found in enum`);
676
- }
677
- return new ZodEnum({
678
- ...def,
679
- checks: [],
680
- ...util.normalizeParams(params),
681
- entries: newEntries,
682
- });
683
- };
684
- inst.exclude = (values, params) => {
685
- const newEntries = { ...def.entries };
686
- for (const value of values) {
687
- if (keys.has(value)) {
688
- delete newEntries[value];
689
- }
690
- else
691
- throw new Error(`Key ${value} not found in enum`);
692
- }
693
- return new ZodEnum({
694
- ...def,
695
- checks: [],
696
- ...util.normalizeParams(params),
697
- entries: newEntries,
698
- });
699
- };
700
- });
701
- function _enum(values, params) {
702
- const entries = Array.isArray(values) ? Object.fromEntries(values.map((v) => [v, v])) : values;
703
- return new ZodEnum({
704
- type: "enum",
705
- entries,
706
- ...util.normalizeParams(params),
707
- });
708
- }
709
- export { _enum as enum };
710
- /** @deprecated This API has been merged into `z.enum()`. Use `z.enum()` instead.
711
- *
712
- * ```ts
713
- * enum Colors { red, green, blue }
714
- * z.enum(Colors);
715
- * ```
716
- */
717
- export function nativeEnum(entries, params) {
718
- return new ZodEnum({
719
- type: "enum",
720
- entries,
721
- ...util.normalizeParams(params),
722
- });
723
- }
724
- export const ZodLiteral = /*@__PURE__*/ core.$constructor("ZodLiteral", (inst, def) => {
725
- core.$ZodLiteral.init(inst, def);
726
- ZodType.init(inst, def);
727
- inst.values = new Set(def.values);
728
- });
729
- export function literal(value, params) {
730
- return new ZodLiteral({
731
- type: "literal",
732
- values: Array.isArray(value) ? value : [value],
733
- ...util.normalizeParams(params),
734
- });
735
- }
736
- export const ZodFile = /*@__PURE__*/ core.$constructor("ZodFile", (inst, def) => {
737
- core.$ZodFile.init(inst, def);
738
- ZodType.init(inst, def);
739
- inst.min = (size, params) => inst.check(core._minSize(size, params));
740
- inst.max = (size, params) => inst.check(core._maxSize(size, params));
741
- inst.mime = (types, params) => inst.check(core._mime(types, params));
742
- });
743
- export function file(params) {
744
- return core._file(ZodFile, params);
745
- }
746
- export const ZodTransform = /*@__PURE__*/ core.$constructor("ZodTransform", (inst, def) => {
747
- core.$ZodTransform.init(inst, def);
748
- ZodType.init(inst, def);
749
- inst._zod.parse = (payload, _ctx) => {
750
- payload.addIssue = (issue) => {
751
- if (typeof issue === "string") {
752
- payload.issues.push(util.issue(issue, payload.value, def));
753
- }
754
- else {
755
- // for Zod 3 backwards compatibility
756
- const _issue = issue;
757
- if (_issue.fatal)
758
- _issue.continue = false;
759
- _issue.code ?? (_issue.code = "custom");
760
- _issue.input ?? (_issue.input = payload.value);
761
- _issue.inst ?? (_issue.inst = inst);
762
- _issue.continue ?? (_issue.continue = true);
763
- payload.issues.push(util.issue(_issue));
764
- }
765
- };
766
- const output = def.transform(payload.value, payload);
767
- if (output instanceof Promise) {
768
- return output.then((output) => {
769
- payload.value = output;
770
- return payload;
771
- });
772
- }
773
- payload.value = output;
774
- return payload;
775
- };
776
- });
777
- export function transform(fn) {
778
- return new ZodTransform({
779
- type: "transform",
780
- transform: fn,
781
- });
782
- }
783
- export const ZodOptional = /*@__PURE__*/ core.$constructor("ZodOptional", (inst, def) => {
784
- core.$ZodOptional.init(inst, def);
785
- ZodType.init(inst, def);
786
- inst.unwrap = () => inst._zod.def.innerType;
787
- });
788
- export function optional(innerType) {
789
- return new ZodOptional({
790
- type: "optional",
791
- innerType,
792
- });
793
- }
794
- export const ZodNullable = /*@__PURE__*/ core.$constructor("ZodNullable", (inst, def) => {
795
- core.$ZodNullable.init(inst, def);
796
- ZodType.init(inst, def);
797
- inst.unwrap = () => inst._zod.def.innerType;
798
- });
799
- export function nullable(innerType) {
800
- return new ZodNullable({
801
- type: "nullable",
802
- innerType,
803
- });
804
- }
805
- // nullish
806
- export function nullish(innerType) {
807
- return optional(nullable(innerType));
808
- }
809
- export const ZodDefault = /*@__PURE__*/ core.$constructor("ZodDefault", (inst, def) => {
810
- core.$ZodDefault.init(inst, def);
811
- ZodType.init(inst, def);
812
- inst.unwrap = () => inst._zod.def.innerType;
813
- inst.removeDefault = inst.unwrap;
814
- });
815
- export function _default(innerType, defaultValue) {
816
- return new ZodDefault({
817
- type: "default",
818
- innerType,
819
- get defaultValue() {
820
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
821
- },
822
- });
823
- }
824
- export const ZodPrefault = /*@__PURE__*/ core.$constructor("ZodPrefault", (inst, def) => {
825
- core.$ZodPrefault.init(inst, def);
826
- ZodType.init(inst, def);
827
- inst.unwrap = () => inst._zod.def.innerType;
828
- });
829
- export function prefault(innerType, defaultValue) {
830
- return new ZodPrefault({
831
- type: "prefault",
832
- innerType,
833
- get defaultValue() {
834
- return typeof defaultValue === "function" ? defaultValue() : defaultValue;
835
- },
836
- });
837
- }
838
- export const ZodNonOptional = /*@__PURE__*/ core.$constructor("ZodNonOptional", (inst, def) => {
839
- core.$ZodNonOptional.init(inst, def);
840
- ZodType.init(inst, def);
841
- inst.unwrap = () => inst._zod.def.innerType;
842
- });
843
- export function nonoptional(innerType, params) {
844
- return new ZodNonOptional({
845
- type: "nonoptional",
846
- innerType,
847
- ...util.normalizeParams(params),
848
- });
849
- }
850
- export const ZodSuccess = /*@__PURE__*/ core.$constructor("ZodSuccess", (inst, def) => {
851
- core.$ZodSuccess.init(inst, def);
852
- ZodType.init(inst, def);
853
- inst.unwrap = () => inst._zod.def.innerType;
854
- });
855
- export function success(innerType) {
856
- return new ZodSuccess({
857
- type: "success",
858
- innerType,
859
- });
860
- }
861
- export const ZodCatch = /*@__PURE__*/ core.$constructor("ZodCatch", (inst, def) => {
862
- core.$ZodCatch.init(inst, def);
863
- ZodType.init(inst, def);
864
- inst.unwrap = () => inst._zod.def.innerType;
865
- inst.removeCatch = inst.unwrap;
866
- });
867
- function _catch(innerType, catchValue) {
868
- return new ZodCatch({
869
- type: "catch",
870
- innerType,
871
- catchValue: (typeof catchValue === "function" ? catchValue : () => catchValue),
872
- });
873
- }
874
- export { _catch as catch };
875
- export const ZodNaN = /*@__PURE__*/ core.$constructor("ZodNaN", (inst, def) => {
876
- core.$ZodNaN.init(inst, def);
877
- ZodType.init(inst, def);
878
- });
879
- export function nan(params) {
880
- return core._nan(ZodNaN, params);
881
- }
882
- export const ZodPipe = /*@__PURE__*/ core.$constructor("ZodPipe", (inst, def) => {
883
- core.$ZodPipe.init(inst, def);
884
- ZodType.init(inst, def);
885
- inst.in = def.in;
886
- inst.out = def.out;
887
- });
888
- export function pipe(in_, out) {
889
- return new ZodPipe({
890
- type: "pipe",
891
- in: in_,
892
- out,
893
- // ...util.normalizeParams(params),
894
- });
895
- }
896
- export const ZodReadonly = /*@__PURE__*/ core.$constructor("ZodReadonly", (inst, def) => {
897
- core.$ZodReadonly.init(inst, def);
898
- ZodType.init(inst, def);
899
- });
900
- export function readonly(innerType) {
901
- return new ZodReadonly({
902
- type: "readonly",
903
- innerType,
904
- });
905
- }
906
- export const ZodTemplateLiteral = /*@__PURE__*/ core.$constructor("ZodTemplateLiteral", (inst, def) => {
907
- core.$ZodTemplateLiteral.init(inst, def);
908
- ZodType.init(inst, def);
909
- });
910
- export function templateLiteral(parts, params) {
911
- return new ZodTemplateLiteral({
912
- type: "template_literal",
913
- parts,
914
- ...util.normalizeParams(params),
915
- });
916
- }
917
- export const ZodLazy = /*@__PURE__*/ core.$constructor("ZodLazy", (inst, def) => {
918
- core.$ZodLazy.init(inst, def);
919
- ZodType.init(inst, def);
920
- inst.unwrap = () => inst._zod.def.getter();
921
- });
922
- export function lazy(getter) {
923
- return new ZodLazy({
924
- type: "lazy",
925
- getter,
926
- });
927
- }
928
- export const ZodPromise = /*@__PURE__*/ core.$constructor("ZodPromise", (inst, def) => {
929
- core.$ZodPromise.init(inst, def);
930
- ZodType.init(inst, def);
931
- inst.unwrap = () => inst._zod.def.innerType;
932
- });
933
- export function promise(innerType) {
934
- return new ZodPromise({
935
- type: "promise",
936
- innerType,
937
- });
938
- }
939
- export const ZodCustom = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def) => {
940
- core.$ZodCustom.init(inst, def);
941
- ZodType.init(inst, def);
942
- });
943
- // custom checks
944
- export function check(fn, params) {
945
- const ch = new core.$ZodCheck({
946
- check: "custom",
947
- ...util.normalizeParams(params),
948
- });
949
- ch._zod.check = fn;
950
- return ch;
951
- }
952
- export function custom(fn, _params) {
953
- return core._custom(ZodCustom, fn ?? (() => true), _params);
954
- }
955
- export function refine(fn, _params = {}) {
956
- return core._custom(ZodCustom, fn, _params);
957
- }
958
- // superRefine
959
- export function superRefine(fn, params) {
960
- const ch = check((payload) => {
961
- payload.addIssue = (issue) => {
962
- if (typeof issue === "string") {
963
- payload.issues.push(util.issue(issue, payload.value, ch._zod.def));
964
- }
965
- else {
966
- // for Zod 3 backwards compatibility
967
- const _issue = issue;
968
- if (_issue.fatal)
969
- _issue.continue = false;
970
- _issue.code ?? (_issue.code = "custom");
971
- _issue.input ?? (_issue.input = payload.value);
972
- _issue.inst ?? (_issue.inst = ch);
973
- _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
974
- payload.issues.push(util.issue(_issue));
975
- }
976
- };
977
- return fn(payload.value, payload);
978
- }, params);
979
- return ch;
980
- }
981
- function _instanceof(cls, params = {
982
- error: `Input not instance of ${cls.name}`,
983
- }) {
984
- const inst = new ZodCustom({
985
- type: "custom",
986
- check: "custom",
987
- fn: (data) => data instanceof cls,
988
- abort: true,
989
- ...util.normalizeParams(params),
990
- });
991
- inst._zod.bag.Class = cls;
992
- return inst;
993
- }
994
- export { _instanceof as instanceof };
995
- // stringbool
996
- export const stringbool =
997
- /*@__PURE__*/ core._stringbool.bind(null, {
998
- Pipe: ZodPipe,
999
- Boolean: ZodBoolean,
1000
- Unknown: ZodUnknown,
1001
- });
1002
- export function json(params) {
1003
- const jsonSchema = lazy(() => {
1004
- return union([string(params), number(), boolean(), _null(), array(jsonSchema), record(string(), jsonSchema)]);
1005
- });
1006
- return jsonSchema;
1007
- }
1008
- // preprocess
1009
- // /** @deprecated Use `z.pipe()` and `z.transform()` instead. */
1010
- export function preprocess(fn, schema) {
1011
- return pipe(transform(fn), schema);
1012
- }