zod 3.24.0 → 3.24.2
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/README.md +62 -16
- package/lib/ZodError.d.ts +16 -16
- package/lib/ZodError.js +3 -3
- package/lib/external.js +5 -1
- package/lib/helpers/errorUtil.d.ts +2 -2
- package/lib/helpers/errorUtil.js +1 -1
- package/lib/helpers/parseUtil.d.ts +11 -11
- package/lib/helpers/parseUtil.js +3 -3
- package/lib/helpers/typeAliases.d.ts +2 -2
- package/lib/helpers/util.d.ts +9 -9
- package/lib/helpers/util.js +2 -2
- package/lib/index.js +5 -1
- package/lib/index.mjs +80 -55
- package/lib/index.umd.js +80 -55
- package/lib/standard-schema.d.ts +1 -1
- package/lib/types.d.ts +130 -221
- package/lib/types.js +75 -50
- package/package.json +2 -2
package/lib/types.js
CHANGED
|
@@ -84,40 +84,6 @@ function processCreateParams(params) {
|
|
|
84
84
|
return { errorMap: customMap, description };
|
|
85
85
|
}
|
|
86
86
|
class ZodType {
|
|
87
|
-
constructor(def) {
|
|
88
|
-
/** Alias of safeParseAsync */
|
|
89
|
-
this.spa = this.safeParseAsync;
|
|
90
|
-
this._def = def;
|
|
91
|
-
this.parse = this.parse.bind(this);
|
|
92
|
-
this.safeParse = this.safeParse.bind(this);
|
|
93
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
94
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
95
|
-
this.spa = this.spa.bind(this);
|
|
96
|
-
this.refine = this.refine.bind(this);
|
|
97
|
-
this.refinement = this.refinement.bind(this);
|
|
98
|
-
this.superRefine = this.superRefine.bind(this);
|
|
99
|
-
this.optional = this.optional.bind(this);
|
|
100
|
-
this.nullable = this.nullable.bind(this);
|
|
101
|
-
this.nullish = this.nullish.bind(this);
|
|
102
|
-
this.array = this.array.bind(this);
|
|
103
|
-
this.promise = this.promise.bind(this);
|
|
104
|
-
this.or = this.or.bind(this);
|
|
105
|
-
this.and = this.and.bind(this);
|
|
106
|
-
this.transform = this.transform.bind(this);
|
|
107
|
-
this.brand = this.brand.bind(this);
|
|
108
|
-
this.default = this.default.bind(this);
|
|
109
|
-
this.catch = this.catch.bind(this);
|
|
110
|
-
this.describe = this.describe.bind(this);
|
|
111
|
-
this.pipe = this.pipe.bind(this);
|
|
112
|
-
this.readonly = this.readonly.bind(this);
|
|
113
|
-
this.isNullable = this.isNullable.bind(this);
|
|
114
|
-
this.isOptional = this.isOptional.bind(this);
|
|
115
|
-
this["~standard"] = {
|
|
116
|
-
version: 1,
|
|
117
|
-
vendor: "zod",
|
|
118
|
-
validate: (data) => this["~validate"](data),
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
87
|
get description() {
|
|
122
88
|
return this._def.description;
|
|
123
89
|
}
|
|
@@ -182,7 +148,7 @@ class ZodType {
|
|
|
182
148
|
return handleResult(ctx, result);
|
|
183
149
|
}
|
|
184
150
|
"~validate"(data) {
|
|
185
|
-
var _a, _b
|
|
151
|
+
var _a, _b;
|
|
186
152
|
const ctx = {
|
|
187
153
|
common: {
|
|
188
154
|
issues: [],
|
|
@@ -206,7 +172,7 @@ class ZodType {
|
|
|
206
172
|
};
|
|
207
173
|
}
|
|
208
174
|
catch (err) {
|
|
209
|
-
if ((
|
|
175
|
+
if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
|
|
210
176
|
this["~standard"].async = true;
|
|
211
177
|
}
|
|
212
178
|
ctx.common = {
|
|
@@ -309,6 +275,40 @@ class ZodType {
|
|
|
309
275
|
superRefine(refinement) {
|
|
310
276
|
return this._refinement(refinement);
|
|
311
277
|
}
|
|
278
|
+
constructor(def) {
|
|
279
|
+
/** Alias of safeParseAsync */
|
|
280
|
+
this.spa = this.safeParseAsync;
|
|
281
|
+
this._def = def;
|
|
282
|
+
this.parse = this.parse.bind(this);
|
|
283
|
+
this.safeParse = this.safeParse.bind(this);
|
|
284
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
285
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
286
|
+
this.spa = this.spa.bind(this);
|
|
287
|
+
this.refine = this.refine.bind(this);
|
|
288
|
+
this.refinement = this.refinement.bind(this);
|
|
289
|
+
this.superRefine = this.superRefine.bind(this);
|
|
290
|
+
this.optional = this.optional.bind(this);
|
|
291
|
+
this.nullable = this.nullable.bind(this);
|
|
292
|
+
this.nullish = this.nullish.bind(this);
|
|
293
|
+
this.array = this.array.bind(this);
|
|
294
|
+
this.promise = this.promise.bind(this);
|
|
295
|
+
this.or = this.or.bind(this);
|
|
296
|
+
this.and = this.and.bind(this);
|
|
297
|
+
this.transform = this.transform.bind(this);
|
|
298
|
+
this.brand = this.brand.bind(this);
|
|
299
|
+
this.default = this.default.bind(this);
|
|
300
|
+
this.catch = this.catch.bind(this);
|
|
301
|
+
this.describe = this.describe.bind(this);
|
|
302
|
+
this.pipe = this.pipe.bind(this);
|
|
303
|
+
this.readonly = this.readonly.bind(this);
|
|
304
|
+
this.isNullable = this.isNullable.bind(this);
|
|
305
|
+
this.isOptional = this.isOptional.bind(this);
|
|
306
|
+
this["~standard"] = {
|
|
307
|
+
version: 1,
|
|
308
|
+
vendor: "zod",
|
|
309
|
+
validate: (data) => this["~validate"](data),
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
312
|
optional() {
|
|
313
313
|
return ZodOptional.create(this, this._def);
|
|
314
314
|
}
|
|
@@ -870,7 +870,10 @@ class ZodString extends ZodType {
|
|
|
870
870
|
}
|
|
871
871
|
base64url(message) {
|
|
872
872
|
// base64url encoding is a modification of base64 that can safely be used in URLs and filenames
|
|
873
|
-
return this._addCheck({
|
|
873
|
+
return this._addCheck({
|
|
874
|
+
kind: "base64url",
|
|
875
|
+
...errorUtil_1.errorUtil.errToObj(message),
|
|
876
|
+
});
|
|
874
877
|
}
|
|
875
878
|
jwt(options) {
|
|
876
879
|
return this._addCheck({ kind: "jwt", ...errorUtil_1.errorUtil.errToObj(options) });
|
|
@@ -971,8 +974,7 @@ class ZodString extends ZodType {
|
|
|
971
974
|
});
|
|
972
975
|
}
|
|
973
976
|
/**
|
|
974
|
-
*
|
|
975
|
-
* @see {@link ZodString.min}
|
|
977
|
+
* Equivalent to `.min(1)`
|
|
976
978
|
*/
|
|
977
979
|
nonempty(message) {
|
|
978
980
|
return this.min(1, errorUtil_1.errorUtil.errToObj(message));
|
|
@@ -3652,7 +3654,23 @@ ZodReadonly.create = (type, params) => {
|
|
|
3652
3654
|
...processCreateParams(params),
|
|
3653
3655
|
});
|
|
3654
3656
|
};
|
|
3655
|
-
|
|
3657
|
+
////////////////////////////////////////
|
|
3658
|
+
////////////////////////////////////////
|
|
3659
|
+
////////// //////////
|
|
3660
|
+
////////// z.custom //////////
|
|
3661
|
+
////////// //////////
|
|
3662
|
+
////////////////////////////////////////
|
|
3663
|
+
////////////////////////////////////////
|
|
3664
|
+
function cleanParams(params, data) {
|
|
3665
|
+
const p = typeof params === "function"
|
|
3666
|
+
? params(data)
|
|
3667
|
+
: typeof params === "string"
|
|
3668
|
+
? { message: params }
|
|
3669
|
+
: params;
|
|
3670
|
+
const p2 = typeof p === "string" ? { message: p } : p;
|
|
3671
|
+
return p2;
|
|
3672
|
+
}
|
|
3673
|
+
function custom(check, _params = {},
|
|
3656
3674
|
/**
|
|
3657
3675
|
* @deprecated
|
|
3658
3676
|
*
|
|
@@ -3667,16 +3685,23 @@ fatal) {
|
|
|
3667
3685
|
if (check)
|
|
3668
3686
|
return ZodAny.create().superRefine((data, ctx) => {
|
|
3669
3687
|
var _a, _b;
|
|
3670
|
-
|
|
3671
|
-
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
3675
|
-
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3688
|
+
const r = check(data);
|
|
3689
|
+
if (r instanceof Promise) {
|
|
3690
|
+
return r.then((r) => {
|
|
3691
|
+
var _a, _b;
|
|
3692
|
+
if (!r) {
|
|
3693
|
+
const params = cleanParams(_params, data);
|
|
3694
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3695
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3696
|
+
}
|
|
3697
|
+
});
|
|
3698
|
+
}
|
|
3699
|
+
if (!r) {
|
|
3700
|
+
const params = cleanParams(_params, data);
|
|
3701
|
+
const _fatal = (_b = (_a = params.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3702
|
+
ctx.addIssue({ code: "custom", ...params, fatal: _fatal });
|
|
3679
3703
|
}
|
|
3704
|
+
return;
|
|
3680
3705
|
});
|
|
3681
3706
|
return ZodAny.create();
|
|
3682
3707
|
}
|
|
@@ -3722,7 +3747,7 @@ var ZodFirstPartyTypeKind;
|
|
|
3722
3747
|
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
3723
3748
|
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
3724
3749
|
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
3725
|
-
})(ZodFirstPartyTypeKind
|
|
3750
|
+
})(ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = ZodFirstPartyTypeKind = {}));
|
|
3726
3751
|
// requires TS 4.4+
|
|
3727
3752
|
class Class {
|
|
3728
3753
|
constructor(..._) { }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zod",
|
|
3
|
-
"version": "3.24.
|
|
3
|
+
"version": "3.24.2",
|
|
4
4
|
"author": "Colin McDonnell <colin@colinhacks.com>",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"ts-node": "^10.9.1",
|
|
45
45
|
"tslib": "^2.3.1",
|
|
46
46
|
"tsx": "^3.8.0",
|
|
47
|
-
"typescript": "
|
|
47
|
+
"typescript": "^5.0.0",
|
|
48
48
|
"vitest": "^0.32.2"
|
|
49
49
|
},
|
|
50
50
|
"exports": {
|