zod 3.25.56 → 3.25.57
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 +1 -1
- package/dist/cjs/v4/classic/schemas.js +2 -1
- package/dist/cjs/v4/core/api.js +42 -46
- package/dist/cjs/v4/mini/schemas.js +2 -1
- package/dist/esm/v4/classic/schemas.js +2 -1
- package/dist/esm/v4/core/api.js +42 -46
- package/dist/esm/v4/mini/schemas.js +2 -1
- package/dist/types/v4/classic/schemas.d.ts +2 -2
- package/dist/types/v4/core/api.d.ts +5 -4
- package/dist/types/v4/core/checks.d.ts +1 -1
- package/dist/types/v4/mini/schemas.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -138,7 +138,7 @@ When validation fails, the `.parse()` method will throw a `ZodError` instance wi
|
|
|
138
138
|
try {
|
|
139
139
|
Player.parse({ username: 42, xp: "100" });
|
|
140
140
|
} catch (err) {
|
|
141
|
-
if (
|
|
141
|
+
if (err instanceof z.ZodError) {
|
|
142
142
|
err.issues;
|
|
143
143
|
/* [
|
|
144
144
|
{
|
|
@@ -1085,7 +1085,8 @@ function _instanceof(cls, params = {
|
|
|
1085
1085
|
const stringbool = (...args) => core._stringbool({
|
|
1086
1086
|
Pipe: exports.ZodPipe,
|
|
1087
1087
|
Boolean: exports.ZodBoolean,
|
|
1088
|
-
|
|
1088
|
+
String: exports.ZodString,
|
|
1089
|
+
Transform: exports.ZodTransform,
|
|
1089
1090
|
}, ...args);
|
|
1090
1091
|
exports.stringbool = stringbool;
|
|
1091
1092
|
function json(params) {
|
package/dist/cjs/v4/core/api.js
CHANGED
|
@@ -957,61 +957,57 @@ function _refine(Class, fn, _params) {
|
|
|
957
957
|
}
|
|
958
958
|
function _stringbool(Classes, _params) {
|
|
959
959
|
const { case: _case, error, truthy, falsy } = util.normalizeParams(_params);
|
|
960
|
-
|
|
961
|
-
|
|
960
|
+
let truthyArray = truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
|
|
961
|
+
let falsyArray = falsy ?? ["false", "0", "no", "off", "n", "disabled"];
|
|
962
|
+
if (_case !== "sensitive") {
|
|
963
|
+
truthyArray = truthyArray.map((v) => (typeof v === "string" ? v.toLowerCase() : v));
|
|
964
|
+
falsyArray = falsyArray.map((v) => (typeof v === "string" ? v.toLowerCase() : v));
|
|
965
|
+
}
|
|
966
|
+
const truthySet = new Set(truthyArray);
|
|
967
|
+
const falsySet = new Set(falsyArray);
|
|
962
968
|
const _Pipe = Classes.Pipe ?? schemas.$ZodPipe;
|
|
963
969
|
const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
|
|
964
|
-
const
|
|
965
|
-
const
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
input: ctx.value,
|
|
996
|
-
});
|
|
997
|
-
}
|
|
998
|
-
},
|
|
999
|
-
def: {
|
|
1000
|
-
check: "custom",
|
|
1001
|
-
},
|
|
1002
|
-
onattach: [],
|
|
1003
|
-
},
|
|
1004
|
-
},
|
|
1005
|
-
],
|
|
970
|
+
const _String = Classes.String ?? schemas.$ZodString;
|
|
971
|
+
const _Transform = Classes.Transform ?? schemas.$ZodTransform;
|
|
972
|
+
const tx = new _Transform({
|
|
973
|
+
type: "transform",
|
|
974
|
+
transform: (input, payload) => {
|
|
975
|
+
let data = input;
|
|
976
|
+
if (_case !== "sensitive")
|
|
977
|
+
data = data.toLowerCase();
|
|
978
|
+
if (truthySet.has(data)) {
|
|
979
|
+
return true;
|
|
980
|
+
}
|
|
981
|
+
else if (falsySet.has(data)) {
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
payload.issues.push({
|
|
986
|
+
code: "invalid_value",
|
|
987
|
+
expected: "stringbool",
|
|
988
|
+
values: [...truthySet, ...falsySet],
|
|
989
|
+
input: payload.value,
|
|
990
|
+
inst: tx,
|
|
991
|
+
});
|
|
992
|
+
return {};
|
|
993
|
+
}
|
|
994
|
+
},
|
|
995
|
+
error,
|
|
996
|
+
});
|
|
997
|
+
const innerPipe = new _Pipe({
|
|
998
|
+
type: "pipe",
|
|
999
|
+
in: new _String({ type: "string", error }),
|
|
1000
|
+
out: tx,
|
|
1006
1001
|
error,
|
|
1007
1002
|
});
|
|
1008
|
-
|
|
1003
|
+
const outerPipe = new _Pipe({
|
|
1009
1004
|
type: "pipe",
|
|
1010
|
-
in:
|
|
1005
|
+
in: innerPipe,
|
|
1011
1006
|
out: new _Boolean({
|
|
1012
1007
|
type: "boolean",
|
|
1013
1008
|
error,
|
|
1014
1009
|
}),
|
|
1015
1010
|
error,
|
|
1016
1011
|
});
|
|
1012
|
+
return outerPipe;
|
|
1017
1013
|
}
|
|
@@ -814,7 +814,8 @@ function _instanceof(cls, params = {
|
|
|
814
814
|
const stringbool = (...args) => core._stringbool({
|
|
815
815
|
Pipe: exports.ZodMiniPipe,
|
|
816
816
|
Boolean: exports.ZodMiniBoolean,
|
|
817
|
-
|
|
817
|
+
String: exports.ZodMiniString,
|
|
818
|
+
Transform: exports.ZodMiniTransform,
|
|
818
819
|
}, ...args);
|
|
819
820
|
exports.stringbool = stringbool;
|
|
820
821
|
function json() {
|
|
@@ -984,7 +984,8 @@ export { _instanceof as instanceof };
|
|
|
984
984
|
export const stringbool = (...args) => core._stringbool({
|
|
985
985
|
Pipe: ZodPipe,
|
|
986
986
|
Boolean: ZodBoolean,
|
|
987
|
-
|
|
987
|
+
String: ZodString,
|
|
988
|
+
Transform: ZodTransform,
|
|
988
989
|
}, ...args);
|
|
989
990
|
export function json(params) {
|
|
990
991
|
const jsonSchema = lazy(() => {
|
package/dist/esm/v4/core/api.js
CHANGED
|
@@ -826,61 +826,57 @@ export function _refine(Class, fn, _params) {
|
|
|
826
826
|
}
|
|
827
827
|
export function _stringbool(Classes, _params) {
|
|
828
828
|
const { case: _case, error, truthy, falsy } = util.normalizeParams(_params);
|
|
829
|
-
|
|
830
|
-
|
|
829
|
+
let truthyArray = truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
|
|
830
|
+
let falsyArray = falsy ?? ["false", "0", "no", "off", "n", "disabled"];
|
|
831
|
+
if (_case !== "sensitive") {
|
|
832
|
+
truthyArray = truthyArray.map((v) => (typeof v === "string" ? v.toLowerCase() : v));
|
|
833
|
+
falsyArray = falsyArray.map((v) => (typeof v === "string" ? v.toLowerCase() : v));
|
|
834
|
+
}
|
|
835
|
+
const truthySet = new Set(truthyArray);
|
|
836
|
+
const falsySet = new Set(falsyArray);
|
|
831
837
|
const _Pipe = Classes.Pipe ?? schemas.$ZodPipe;
|
|
832
838
|
const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
|
|
833
|
-
const
|
|
834
|
-
const
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
input: ctx.value,
|
|
865
|
-
});
|
|
866
|
-
}
|
|
867
|
-
},
|
|
868
|
-
def: {
|
|
869
|
-
check: "custom",
|
|
870
|
-
},
|
|
871
|
-
onattach: [],
|
|
872
|
-
},
|
|
873
|
-
},
|
|
874
|
-
],
|
|
839
|
+
const _String = Classes.String ?? schemas.$ZodString;
|
|
840
|
+
const _Transform = Classes.Transform ?? schemas.$ZodTransform;
|
|
841
|
+
const tx = new _Transform({
|
|
842
|
+
type: "transform",
|
|
843
|
+
transform: (input, payload) => {
|
|
844
|
+
let data = input;
|
|
845
|
+
if (_case !== "sensitive")
|
|
846
|
+
data = data.toLowerCase();
|
|
847
|
+
if (truthySet.has(data)) {
|
|
848
|
+
return true;
|
|
849
|
+
}
|
|
850
|
+
else if (falsySet.has(data)) {
|
|
851
|
+
return false;
|
|
852
|
+
}
|
|
853
|
+
else {
|
|
854
|
+
payload.issues.push({
|
|
855
|
+
code: "invalid_value",
|
|
856
|
+
expected: "stringbool",
|
|
857
|
+
values: [...truthySet, ...falsySet],
|
|
858
|
+
input: payload.value,
|
|
859
|
+
inst: tx,
|
|
860
|
+
});
|
|
861
|
+
return {};
|
|
862
|
+
}
|
|
863
|
+
},
|
|
864
|
+
error,
|
|
865
|
+
});
|
|
866
|
+
const innerPipe = new _Pipe({
|
|
867
|
+
type: "pipe",
|
|
868
|
+
in: new _String({ type: "string", error }),
|
|
869
|
+
out: tx,
|
|
875
870
|
error,
|
|
876
871
|
});
|
|
877
|
-
|
|
872
|
+
const outerPipe = new _Pipe({
|
|
878
873
|
type: "pipe",
|
|
879
|
-
in:
|
|
874
|
+
in: innerPipe,
|
|
880
875
|
out: new _Boolean({
|
|
881
876
|
type: "boolean",
|
|
882
877
|
error,
|
|
883
878
|
}),
|
|
884
879
|
error,
|
|
885
880
|
});
|
|
881
|
+
return outerPipe;
|
|
886
882
|
}
|
|
@@ -710,7 +710,8 @@ export { _instanceof as instanceof };
|
|
|
710
710
|
export const stringbool = (...args) => core._stringbool({
|
|
711
711
|
Pipe: ZodMiniPipe,
|
|
712
712
|
Boolean: ZodMiniBoolean,
|
|
713
|
-
|
|
713
|
+
String: ZodMiniString,
|
|
714
|
+
Transform: ZodMiniTransform,
|
|
714
715
|
}, ...args);
|
|
715
716
|
export function json() {
|
|
716
717
|
const jsonSchema = _lazy(() => {
|
|
@@ -511,7 +511,7 @@ export interface ZodLiteral<T extends util.Primitive = util.Primitive> extends _
|
|
|
511
511
|
value: T;
|
|
512
512
|
}
|
|
513
513
|
export declare const ZodLiteral: core.$constructor<ZodLiteral>;
|
|
514
|
-
export declare function literal<const T extends
|
|
514
|
+
export declare function literal<const T extends ReadonlyArray<util.Literal>>(value: T, params?: string | core.$ZodLiteralParams): ZodLiteral<T[number]>;
|
|
515
515
|
export declare function literal<const T extends util.Literal>(value: T, params?: string | core.$ZodLiteralParams): ZodLiteral<T>;
|
|
516
516
|
export interface ZodFile extends _ZodType<core.$ZodFileInternals>, core.$ZodFile {
|
|
517
517
|
min(size: number, params?: string | core.$ZodCheckMinSizeParams): this;
|
|
@@ -603,7 +603,7 @@ export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) =
|
|
|
603
603
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
604
604
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
|
|
605
605
|
export { _instanceof as instanceof };
|
|
606
|
-
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodPipe<
|
|
606
|
+
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodPipe<ZodPipe<ZodString, ZodTransform<boolean, string>>, ZodBoolean>;
|
|
607
607
|
type _ZodJSONSchema = ZodUnion<[
|
|
608
608
|
ZodString,
|
|
609
609
|
ZodNumber,
|
|
@@ -260,14 +260,15 @@ export interface $ZodStringBoolParams extends TypeParams {
|
|
|
260
260
|
truthy?: string[];
|
|
261
261
|
falsy?: string[];
|
|
262
262
|
/**
|
|
263
|
-
* Options `"sensitive"`, `"insensitive"`
|
|
263
|
+
* Options: `"sensitive"`, `"insensitive"`
|
|
264
264
|
*
|
|
265
|
-
*
|
|
265
|
+
* @default `"insensitive"`
|
|
266
266
|
*/
|
|
267
267
|
case?: "sensitive" | "insensitive" | undefined;
|
|
268
268
|
}
|
|
269
269
|
export declare function _stringbool(Classes: {
|
|
270
270
|
Pipe?: typeof schemas.$ZodPipe;
|
|
271
271
|
Boolean?: typeof schemas.$ZodBoolean;
|
|
272
|
-
|
|
273
|
-
|
|
272
|
+
Transform?: typeof schemas.$ZodTransform;
|
|
273
|
+
String?: typeof schemas.$ZodString;
|
|
274
|
+
}, _params?: string | $ZodStringBoolParams): schemas.$ZodPipe<schemas.$ZodPipe<schemas.$ZodString, schemas.$ZodTransform<boolean, string>>, schemas.$ZodBoolean<boolean>>;
|
|
@@ -27,7 +27,7 @@ export interface $ZodCheckLessThanDef extends $ZodCheckDef {
|
|
|
27
27
|
}
|
|
28
28
|
export interface $ZodCheckLessThanInternals<T extends util.Numeric = util.Numeric> extends $ZodCheckInternals<T> {
|
|
29
29
|
def: $ZodCheckLessThanDef;
|
|
30
|
-
issc: errors.$
|
|
30
|
+
issc: errors.$ZodIssueTooBig<T>;
|
|
31
31
|
}
|
|
32
32
|
export interface $ZodCheckLessThan<T extends util.Numeric = util.Numeric> extends $ZodCheck<T> {
|
|
33
33
|
_zod: $ZodCheckLessThanInternals<T>;
|
|
@@ -254,7 +254,7 @@ export declare function nativeEnum<T extends util.EnumLike>(entries: T, params?:
|
|
|
254
254
|
export interface ZodMiniLiteral<T extends util.Primitive = util.Primitive> extends _ZodMiniType<core.$ZodLiteralInternals<T>> {
|
|
255
255
|
}
|
|
256
256
|
export declare const ZodMiniLiteral: core.$constructor<ZodMiniLiteral>;
|
|
257
|
-
export declare function literal<const T extends
|
|
257
|
+
export declare function literal<const T extends ReadonlyArray<util.Literal>>(value: T, params?: string | core.$ZodLiteralParams): ZodMiniLiteral<T[number]>;
|
|
258
258
|
export declare function literal<const T extends util.Literal>(value: T, params?: string | core.$ZodLiteralParams): ZodMiniLiteral<T>;
|
|
259
259
|
export interface ZodMiniFile extends _ZodMiniType<core.$ZodFileInternals> {
|
|
260
260
|
}
|
|
@@ -330,7 +330,7 @@ declare abstract class Class {
|
|
|
330
330
|
}
|
|
331
331
|
declare function _instanceof<T extends typeof Class>(cls: T, params?: core.$ZodCustomParams): ZodMiniCustom<InstanceType<T>, InstanceType<T>>;
|
|
332
332
|
export { _instanceof as instanceof };
|
|
333
|
-
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodMiniPipe<
|
|
333
|
+
export declare const stringbool: (_params?: string | core.$ZodStringBoolParams) => ZodMiniPipe<ZodMiniPipe<ZodMiniString, ZodMiniTransform<boolean, string>>, ZodMiniBoolean>;
|
|
334
334
|
type _ZodMiniJSONSchema = ZodMiniUnion<[
|
|
335
335
|
ZodMiniString,
|
|
336
336
|
ZodMiniNumber,
|
package/package.json
CHANGED