zod 4.0.0-beta.1 → 4.0.0-beta.20250409T222615

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