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