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 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 (error instanceof z.ZodError) {
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
- Unknown: exports.ZodUnknown,
1088
+ String: exports.ZodString,
1089
+ Transform: exports.ZodTransform,
1089
1090
  }, ...args);
1090
1091
  exports.stringbool = stringbool;
1091
1092
  function json(params) {
@@ -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
- const trueValues = new Set(truthy ?? ["true", "1", "yes", "on", "y", "enabled"]);
961
- const falseValues = new Set(falsy ?? ["false", "0", "no", "off", "n", "disabled"]);
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 _Unknown = Classes.Unknown ?? schemas.$ZodUnknown;
965
- const inst = new _Unknown({
966
- type: "unknown",
967
- checks: [
968
- {
969
- _zod: {
970
- check: (ctx) => {
971
- if (typeof ctx.value === "string") {
972
- let data = ctx.value;
973
- if (_case !== "sensitive")
974
- data = data.toLowerCase();
975
- if (trueValues.has(data)) {
976
- ctx.value = true;
977
- }
978
- else if (falseValues.has(data)) {
979
- ctx.value = false;
980
- }
981
- else {
982
- ctx.issues.push({
983
- code: "invalid_value",
984
- expected: "stringbool",
985
- values: [...trueValues, ...falseValues],
986
- input: ctx.value,
987
- inst,
988
- });
989
- }
990
- }
991
- else {
992
- ctx.issues.push({
993
- code: "invalid_type",
994
- expected: "string",
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
- return new _Pipe({
1003
+ const outerPipe = new _Pipe({
1009
1004
  type: "pipe",
1010
- in: inst,
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
- Unknown: exports.ZodMiniUnknown,
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
- Unknown: ZodUnknown,
987
+ String: ZodString,
988
+ Transform: ZodTransform,
988
989
  }, ...args);
989
990
  export function json(params) {
990
991
  const jsonSchema = lazy(() => {
@@ -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
- const trueValues = new Set(truthy ?? ["true", "1", "yes", "on", "y", "enabled"]);
830
- const falseValues = new Set(falsy ?? ["false", "0", "no", "off", "n", "disabled"]);
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 _Unknown = Classes.Unknown ?? schemas.$ZodUnknown;
834
- const inst = new _Unknown({
835
- type: "unknown",
836
- checks: [
837
- {
838
- _zod: {
839
- check: (ctx) => {
840
- if (typeof ctx.value === "string") {
841
- let data = ctx.value;
842
- if (_case !== "sensitive")
843
- data = data.toLowerCase();
844
- if (trueValues.has(data)) {
845
- ctx.value = true;
846
- }
847
- else if (falseValues.has(data)) {
848
- ctx.value = false;
849
- }
850
- else {
851
- ctx.issues.push({
852
- code: "invalid_value",
853
- expected: "stringbool",
854
- values: [...trueValues, ...falseValues],
855
- input: ctx.value,
856
- inst,
857
- });
858
- }
859
- }
860
- else {
861
- ctx.issues.push({
862
- code: "invalid_type",
863
- expected: "string",
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
- return new _Pipe({
872
+ const outerPipe = new _Pipe({
878
873
  type: "pipe",
879
- in: inst,
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
- Unknown: ZodMiniUnknown,
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 Array<util.Literal>>(value: T, params?: string | core.$ZodLiteralParams): ZodLiteral<T[number]>;
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<ZodUnknown, ZodBoolean>;
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
- * Defaults to `"insensitive"`
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
- Unknown?: typeof schemas.$ZodUnknown;
273
- }, _params?: string | $ZodStringBoolParams): schemas.$ZodPipe<schemas.$ZodUnknown, schemas.$ZodBoolean<boolean>>;
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.$ZodIssueTooSmall<T>;
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 Array<util.Literal>>(value: T, params?: string | core.$ZodLiteralParams): ZodMiniLiteral<T[number]>;
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<ZodMiniUnknown, ZodMiniBoolean<boolean>>;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "3.25.56",
3
+ "version": "3.25.57",
4
4
  "type": "module",
5
5
  "author": "Colin McDonnell <zod@colinhacks.com>",
6
6
  "description": "TypeScript-first schema declaration and validation library with static type inference",