zod 4.1.0-canary.20250821T014930 → 4.1.0-canary.20250823T071040

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/index.cjs +17 -7
  2. package/package.json +1 -1
  3. package/src/v4/classic/external.ts +0 -1
  4. package/src/v4/classic/parse.ts +49 -0
  5. package/src/v4/classic/schemas.ts +145 -7
  6. package/src/v4/classic/tests/catch.test.ts +25 -0
  7. package/src/v4/classic/tests/codec-examples.test.ts +538 -0
  8. package/src/v4/classic/tests/codec.test.ts +532 -0
  9. package/src/v4/classic/tests/continuability.test.ts +1 -1
  10. package/src/v4/classic/tests/default.test.ts +32 -0
  11. package/src/v4/classic/tests/firstparty.test.ts +4 -0
  12. package/src/v4/classic/tests/function.test.ts +31 -31
  13. package/src/v4/classic/tests/hash.test.ts +68 -0
  14. package/src/v4/classic/tests/nonoptional.test.ts +15 -0
  15. package/src/v4/classic/tests/object.test.ts +31 -0
  16. package/src/v4/classic/tests/pipe.test.ts +25 -5
  17. package/src/v4/classic/tests/prefault.test.ts +25 -0
  18. package/src/v4/classic/tests/preprocess.test.ts +1 -6
  19. package/src/v4/classic/tests/refine.test.ts +76 -3
  20. package/src/v4/classic/tests/string-formats.test.ts +16 -0
  21. package/src/v4/classic/tests/string.test.ts +82 -1
  22. package/src/v4/classic/tests/stringbool.test.ts +40 -0
  23. package/src/v4/classic/tests/template-literal.test.ts +1 -1
  24. package/src/v4/classic/tests/to-json-schema.test.ts +21 -2
  25. package/src/v4/classic/tests/transform.test.ts +7 -0
  26. package/src/v4/classic/tests/union.test.ts +1 -1
  27. package/src/v4/core/api.ts +25 -35
  28. package/src/v4/core/core.ts +7 -26
  29. package/src/v4/core/index.ts +0 -1
  30. package/src/v4/core/json-schema.ts +1 -0
  31. package/src/v4/core/parse.ts +101 -0
  32. package/src/v4/core/regexes.ts +40 -1
  33. package/src/v4/core/schemas.ts +521 -129
  34. package/src/v4/core/to-json-schema.ts +43 -8
  35. package/src/v4/core/util.ts +73 -0
  36. package/src/v4/mini/external.ts +0 -1
  37. package/src/v4/mini/parse.ts +14 -1
  38. package/src/v4/mini/schemas.ts +153 -12
  39. package/src/v4/mini/tests/codec.test.ts +499 -0
  40. package/src/v4/mini/tests/object.test.ts +9 -0
  41. package/src/v4/mini/tests/string.test.ts +16 -0
  42. package/v3/index.cjs +17 -7
  43. package/v4/classic/coerce.cjs +17 -7
  44. package/v4/classic/compat.cjs +17 -7
  45. package/v4/classic/errors.cjs +17 -7
  46. package/v4/classic/external.cjs +18 -9
  47. package/v4/classic/external.d.cts +1 -1
  48. package/v4/classic/external.d.ts +1 -1
  49. package/v4/classic/external.js +1 -1
  50. package/v4/classic/index.cjs +17 -7
  51. package/v4/classic/iso.cjs +17 -7
  52. package/v4/classic/parse.cjs +27 -8
  53. package/v4/classic/parse.d.cts +8 -0
  54. package/v4/classic/parse.d.ts +8 -0
  55. package/v4/classic/parse.js +9 -0
  56. package/v4/classic/schemas.cjs +76 -11
  57. package/v4/classic/schemas.d.cts +48 -2
  58. package/v4/classic/schemas.d.ts +48 -2
  59. package/v4/classic/schemas.js +51 -3
  60. package/v4/core/api.cjs +36 -35
  61. package/v4/core/api.d.cts +3 -4
  62. package/v4/core/api.d.ts +3 -4
  63. package/v4/core/api.js +19 -24
  64. package/v4/core/checks.cjs +17 -7
  65. package/v4/core/core.cjs +8 -1
  66. package/v4/core/core.d.cts +3 -0
  67. package/v4/core/core.d.ts +3 -0
  68. package/v4/core/core.js +6 -0
  69. package/v4/core/errors.cjs +17 -7
  70. package/v4/core/index.cjs +17 -8
  71. package/v4/core/index.d.cts +0 -1
  72. package/v4/core/index.d.ts +0 -1
  73. package/v4/core/index.js +0 -1
  74. package/v4/core/json-schema.d.cts +1 -0
  75. package/v4/core/json-schema.d.ts +1 -0
  76. package/v4/core/parse.cjs +62 -8
  77. package/v4/core/parse.d.cts +24 -0
  78. package/v4/core/parse.d.ts +24 -0
  79. package/v4/core/parse.js +36 -0
  80. package/v4/core/regexes.cjs +34 -2
  81. package/v4/core/regexes.d.cts +16 -0
  82. package/v4/core/regexes.d.ts +16 -0
  83. package/v4/core/regexes.js +32 -1
  84. package/v4/core/schemas.cjs +326 -84
  85. package/v4/core/schemas.d.cts +61 -3
  86. package/v4/core/schemas.d.ts +61 -3
  87. package/v4/core/schemas.js +308 -76
  88. package/v4/core/to-json-schema.cjs +42 -5
  89. package/v4/core/to-json-schema.d.cts +4 -3
  90. package/v4/core/to-json-schema.d.ts +4 -3
  91. package/v4/core/to-json-schema.js +42 -5
  92. package/v4/core/util.cjs +69 -0
  93. package/v4/core/util.d.cts +10 -0
  94. package/v4/core/util.d.ts +10 -0
  95. package/v4/core/util.js +62 -0
  96. package/v4/locales/ar.cjs +17 -7
  97. package/v4/locales/az.cjs +17 -7
  98. package/v4/locales/be.cjs +17 -7
  99. package/v4/locales/bg.cjs +17 -7
  100. package/v4/locales/ca.cjs +17 -7
  101. package/v4/locales/cs.cjs +17 -7
  102. package/v4/locales/da.cjs +17 -7
  103. package/v4/locales/de.cjs +17 -7
  104. package/v4/locales/en.cjs +17 -7
  105. package/v4/locales/eo.cjs +17 -7
  106. package/v4/locales/es.cjs +17 -7
  107. package/v4/locales/fa.cjs +17 -7
  108. package/v4/locales/fi.cjs +17 -7
  109. package/v4/locales/fr-CA.cjs +17 -7
  110. package/v4/locales/fr.cjs +17 -7
  111. package/v4/locales/he.cjs +17 -7
  112. package/v4/locales/hu.cjs +17 -7
  113. package/v4/locales/id.cjs +17 -7
  114. package/v4/locales/is.cjs +17 -7
  115. package/v4/locales/it.cjs +17 -7
  116. package/v4/locales/ja.cjs +17 -7
  117. package/v4/locales/kh.cjs +17 -7
  118. package/v4/locales/ko.cjs +17 -7
  119. package/v4/locales/mk.cjs +17 -7
  120. package/v4/locales/ms.cjs +17 -7
  121. package/v4/locales/nl.cjs +17 -7
  122. package/v4/locales/no.cjs +17 -7
  123. package/v4/locales/ota.cjs +17 -7
  124. package/v4/locales/pl.cjs +17 -7
  125. package/v4/locales/ps.cjs +17 -7
  126. package/v4/locales/pt.cjs +17 -7
  127. package/v4/locales/ru.cjs +17 -7
  128. package/v4/locales/sl.cjs +17 -7
  129. package/v4/locales/sv.cjs +17 -7
  130. package/v4/locales/ta.cjs +17 -7
  131. package/v4/locales/th.cjs +17 -7
  132. package/v4/locales/tr.cjs +17 -7
  133. package/v4/locales/ua.cjs +17 -7
  134. package/v4/locales/ur.cjs +17 -7
  135. package/v4/locales/vi.cjs +17 -7
  136. package/v4/locales/yo.cjs +17 -7
  137. package/v4/locales/zh-CN.cjs +17 -7
  138. package/v4/locales/zh-TW.cjs +17 -7
  139. package/v4/mini/coerce.cjs +17 -7
  140. package/v4/mini/external.cjs +18 -9
  141. package/v4/mini/external.d.cts +1 -1
  142. package/v4/mini/external.d.ts +1 -1
  143. package/v4/mini/external.js +1 -1
  144. package/v4/mini/index.cjs +17 -7
  145. package/v4/mini/iso.cjs +17 -7
  146. package/v4/mini/parse.cjs +9 -1
  147. package/v4/mini/parse.d.cts +1 -1
  148. package/v4/mini/parse.d.ts +1 -1
  149. package/v4/mini/parse.js +1 -1
  150. package/v4/mini/schemas.cjs +75 -10
  151. package/v4/mini/schemas.d.cts +49 -1
  152. package/v4/mini/schemas.d.ts +49 -1
  153. package/v4/mini/schemas.js +49 -2
  154. package/src/v4/core/function.ts +0 -176
  155. package/v4/core/function.cjs +0 -102
  156. package/v4/core/function.d.cts +0 -52
  157. package/v4/core/function.d.ts +0 -52
  158. package/v4/core/function.js +0 -75
@@ -183,6 +183,13 @@ export const ZodURL = /*@__PURE__*/ core.$constructor("ZodURL", (inst, def) => {
183
183
  export function url(params) {
184
184
  return core._url(ZodURL, params);
185
185
  }
186
+ export function httpUrl(params) {
187
+ return core._url(ZodURL, {
188
+ protocol: /^https?$/,
189
+ hostname: core.regexes.domain,
190
+ ...util.normalizeParams(params),
191
+ });
192
+ }
186
193
  export const ZodEmoji = /*@__PURE__*/ core.$constructor("ZodEmoji", (inst, def) => {
187
194
  // ZodStringFormat.init(inst, def);
188
195
  core.$ZodEmoji.init(inst, def);
@@ -312,6 +319,17 @@ export function stringFormat(format, fnOrRegex, _params = {}) {
312
319
  export function hostname(_params) {
313
320
  return core._stringFormat(ZodCustomStringFormat, "hostname", core.regexes.hostname, _params);
314
321
  }
322
+ export function hex(_params) {
323
+ return core._stringFormat(ZodCustomStringFormat, "hex", core.regexes.hex, _params);
324
+ }
325
+ export function hash(alg, params) {
326
+ const enc = params?.enc ?? "hex";
327
+ const format = `${alg}_${enc}`;
328
+ const regex = core.regexes[format];
329
+ if (!regex)
330
+ throw new Error(`Unrecognized hash format: ${format}`);
331
+ return core._stringFormat(ZodCustomStringFormat, format, regex, params);
332
+ }
315
333
  export const ZodNumber = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def) => {
316
334
  core.$ZodNumber.init(inst, def);
317
335
  ZodType.init(inst, def);
@@ -488,7 +506,7 @@ export function keyof(schema) {
488
506
  return _enum(Object.keys(shape));
489
507
  }
490
508
  export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
491
- core.$ZodObject.init(inst, def);
509
+ core.$ZodObjectJIT.init(inst, def);
492
510
  ZodType.init(inst, def);
493
511
  util.defineLazy(inst, "shape", () => def.shape);
494
512
  inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
@@ -500,6 +518,9 @@ export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def
500
518
  inst.extend = (incoming) => {
501
519
  return util.extend(inst, incoming);
502
520
  };
521
+ inst.safeExtend = (incoming) => {
522
+ return util.safeExtend(inst, incoming);
523
+ };
503
524
  inst.merge = (other) => util.merge(inst, other);
504
525
  inst.pick = (mask) => util.pick(inst, mask);
505
526
  inst.omit = (mask) => util.omit(inst, mask);
@@ -746,6 +767,9 @@ export const ZodTransform = /*@__PURE__*/ core.$constructor("ZodTransform", (ins
746
767
  core.$ZodTransform.init(inst, def);
747
768
  ZodType.init(inst, def);
748
769
  inst._zod.parse = (payload, _ctx) => {
770
+ if (_ctx.direction === "backward") {
771
+ throw new core.$ZodEncodeError(inst.constructor.name);
772
+ }
749
773
  payload.addIssue = (issue) => {
750
774
  if (typeof issue === "string") {
751
775
  payload.issues.push(util.issue(issue, payload.value, def));
@@ -892,6 +916,19 @@ export function pipe(in_, out) {
892
916
  // ...util.normalizeParams(params),
893
917
  });
894
918
  }
919
+ export const ZodCodec = /*@__PURE__*/ core.$constructor("ZodCodec", (inst, def) => {
920
+ ZodPipe.init(inst, def);
921
+ core.$ZodCodec.init(inst, def);
922
+ });
923
+ export function codec(in_, out, params) {
924
+ return new ZodCodec({
925
+ type: "pipe",
926
+ in: in_,
927
+ out: out,
928
+ transform: params.decode,
929
+ reverseTransform: params.encode,
930
+ });
931
+ }
895
932
  export const ZodReadonly = /*@__PURE__*/ core.$constructor("ZodReadonly", (inst, def) => {
896
933
  core.$ZodReadonly.init(inst, def);
897
934
  ZodType.init(inst, def);
@@ -936,6 +973,18 @@ export function promise(innerType) {
936
973
  innerType: innerType,
937
974
  });
938
975
  }
976
+ export const ZodFunction = /*@__PURE__*/ core.$constructor("ZodFunction", (inst, def) => {
977
+ core.$ZodFunction.init(inst, def);
978
+ ZodType.init(inst, def);
979
+ });
980
+ export function _function(params) {
981
+ return new ZodFunction({
982
+ type: "function",
983
+ input: Array.isArray(params?.input) ? tuple(params?.input) : (params?.input ?? array(unknown())),
984
+ output: params?.output ?? unknown(),
985
+ });
986
+ }
987
+ export { _function as function };
939
988
  export const ZodCustom = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def) => {
940
989
  core.$ZodCustom.init(inst, def);
941
990
  ZodType.init(inst, def);
@@ -975,10 +1024,9 @@ function _instanceof(cls, params = {
975
1024
  export { _instanceof as instanceof };
976
1025
  // stringbool
977
1026
  export const stringbool = (...args) => core._stringbool({
978
- Pipe: ZodPipe,
1027
+ Codec: ZodCodec,
979
1028
  Boolean: ZodBoolean,
980
1029
  String: ZodString,
981
- Transform: ZodTransform,
982
1030
  }, ...args);
983
1031
  export function json(params) {
984
1032
  const jsonSchema = lazy(() => {
package/v4/core/api.cjs CHANGED
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.TimePrecision = void 0;
27
37
  exports._string = _string;
@@ -78,13 +88,9 @@ exports._nan = _nan;
78
88
  exports._lt = _lt;
79
89
  exports._lte = _lte;
80
90
  exports._max = _lte;
81
- exports._lte = _lte;
82
- exports._max = _lte;
83
91
  exports._gt = _gt;
84
92
  exports._gte = _gte;
85
93
  exports._min = _gte;
86
- exports._gte = _gte;
87
- exports._min = _gte;
88
94
  exports._positive = _positive;
89
95
  exports._negative = _negative;
90
96
  exports._nonpositive = _nonpositive;
@@ -973,7 +979,7 @@ function _superRefine(fn) {
973
979
  _issue.code ?? (_issue.code = "custom");
974
980
  _issue.input ?? (_issue.input = payload.value);
975
981
  _issue.inst ?? (_issue.inst = ch);
976
- _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
982
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
977
983
  payload.issues.push(util.issue(_issue));
978
984
  }
979
985
  };
@@ -999,13 +1005,16 @@ function _stringbool(Classes, _params) {
999
1005
  }
1000
1006
  const truthySet = new Set(truthyArray);
1001
1007
  const falsySet = new Set(falsyArray);
1002
- const _Pipe = Classes.Pipe ?? schemas.$ZodPipe;
1008
+ const _Codec = Classes.Codec ?? schemas.$ZodCodec;
1003
1009
  const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
1004
1010
  const _String = Classes.String ?? schemas.$ZodString;
1005
- const _Transform = Classes.Transform ?? schemas.$ZodTransform;
1006
- const tx = new _Transform({
1007
- type: "transform",
1008
- transform: (input, payload) => {
1011
+ const stringSchema = new _String({ type: "string", error: params.error });
1012
+ const booleanSchema = new _Boolean({ type: "boolean", error: params.error });
1013
+ const codec = new _Codec({
1014
+ type: "pipe",
1015
+ in: stringSchema,
1016
+ out: booleanSchema,
1017
+ transform: ((input, payload) => {
1009
1018
  let data = input;
1010
1019
  if (params.case !== "sensitive")
1011
1020
  data = data.toLowerCase();
@@ -1021,31 +1030,23 @@ function _stringbool(Classes, _params) {
1021
1030
  expected: "stringbool",
1022
1031
  values: [...truthySet, ...falsySet],
1023
1032
  input: payload.value,
1024
- inst: tx,
1033
+ inst: codec,
1025
1034
  continue: false,
1026
1035
  });
1027
1036
  return {};
1028
1037
  }
1029
- },
1030
- error: params.error,
1031
- });
1032
- // params.error;
1033
- const innerPipe = new _Pipe({
1034
- type: "pipe",
1035
- in: new _String({ type: "string", error: params.error }),
1036
- out: tx,
1037
- error: params.error,
1038
- });
1039
- const outerPipe = new _Pipe({
1040
- type: "pipe",
1041
- in: innerPipe,
1042
- out: new _Boolean({
1043
- type: "boolean",
1044
- error: params.error,
1038
+ }),
1039
+ reverseTransform: ((input, _payload) => {
1040
+ if (input === true) {
1041
+ return truthyArray[0] || "true";
1042
+ }
1043
+ else {
1044
+ return falsyArray[0] || "false";
1045
+ }
1045
1046
  }),
1046
1047
  error: params.error,
1047
1048
  });
1048
- return outerPipe;
1049
+ return codec;
1049
1050
  }
1050
1051
  function _stringFormat(Class, format, fnOrRegex, _params = {}) {
1051
1052
  const params = util.normalizeParams(_params);
package/v4/core/api.d.cts CHANGED
@@ -269,7 +269,7 @@ export type $ZodSuperRefineIssue<T extends errors.$ZodIssueBase = errors.$ZodIss
269
269
  type RawIssue<T extends errors.$ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
270
270
  /** The schema or check that originated this issue. */
271
271
  readonly inst?: schemas.$ZodType | checks.$ZodCheck;
272
- /** If `true`, Zod will continue executing checks/refinements after this issue. */
272
+ /** If `true`, Zod will execute subsequent checks/refinements instead of immediately aborting */
273
273
  readonly continue?: boolean | undefined;
274
274
  } & Record<string, unknown>> : never;
275
275
  export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
@@ -288,9 +288,8 @@ export interface $ZodStringBoolParams extends TypeParams {
288
288
  case?: "sensitive" | "insensitive" | undefined;
289
289
  }
290
290
  export declare function _stringbool(Classes: {
291
- Pipe?: typeof schemas.$ZodPipe;
291
+ Codec?: typeof schemas.$ZodCodec;
292
292
  Boolean?: typeof schemas.$ZodBoolean;
293
- Transform?: typeof schemas.$ZodTransform;
294
293
  String?: typeof schemas.$ZodString;
295
- }, _params?: string | $ZodStringBoolParams): schemas.$ZodPipe<schemas.$ZodPipe<schemas.$ZodString, schemas.$ZodTransform<boolean, string>>, schemas.$ZodBoolean<boolean>>;
294
+ }, _params?: string | $ZodStringBoolParams): schemas.$ZodCodec<schemas.$ZodString, schemas.$ZodBoolean>;
296
295
  export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
package/v4/core/api.d.ts CHANGED
@@ -269,7 +269,7 @@ export type $ZodSuperRefineIssue<T extends errors.$ZodIssueBase = errors.$ZodIss
269
269
  type RawIssue<T extends errors.$ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
270
270
  /** The schema or check that originated this issue. */
271
271
  readonly inst?: schemas.$ZodType | checks.$ZodCheck;
272
- /** If `true`, Zod will continue executing checks/refinements after this issue. */
272
+ /** If `true`, Zod will execute subsequent checks/refinements instead of immediately aborting */
273
273
  readonly continue?: boolean | undefined;
274
274
  } & Record<string, unknown>> : never;
275
275
  export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
@@ -288,9 +288,8 @@ export interface $ZodStringBoolParams extends TypeParams {
288
288
  case?: "sensitive" | "insensitive" | undefined;
289
289
  }
290
290
  export declare function _stringbool(Classes: {
291
- Pipe?: typeof schemas.$ZodPipe;
291
+ Codec?: typeof schemas.$ZodCodec;
292
292
  Boolean?: typeof schemas.$ZodBoolean;
293
- Transform?: typeof schemas.$ZodTransform;
294
293
  String?: typeof schemas.$ZodString;
295
- }, _params?: string | $ZodStringBoolParams): schemas.$ZodPipe<schemas.$ZodPipe<schemas.$ZodString, schemas.$ZodTransform<boolean, string>>, schemas.$ZodBoolean<boolean>>;
294
+ }, _params?: string | $ZodStringBoolParams): schemas.$ZodCodec<schemas.$ZodString, schemas.$ZodBoolean>;
296
295
  export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
package/v4/core/api.js CHANGED
@@ -838,7 +838,7 @@ export function _superRefine(fn) {
838
838
  _issue.code ?? (_issue.code = "custom");
839
839
  _issue.input ?? (_issue.input = payload.value);
840
840
  _issue.inst ?? (_issue.inst = ch);
841
- _issue.continue ?? (_issue.continue = !ch._zod.def.abort);
841
+ _issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
842
842
  payload.issues.push(util.issue(_issue));
843
843
  }
844
844
  };
@@ -864,13 +864,16 @@ export function _stringbool(Classes, _params) {
864
864
  }
865
865
  const truthySet = new Set(truthyArray);
866
866
  const falsySet = new Set(falsyArray);
867
- const _Pipe = Classes.Pipe ?? schemas.$ZodPipe;
867
+ const _Codec = Classes.Codec ?? schemas.$ZodCodec;
868
868
  const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
869
869
  const _String = Classes.String ?? schemas.$ZodString;
870
- const _Transform = Classes.Transform ?? schemas.$ZodTransform;
871
- const tx = new _Transform({
872
- type: "transform",
873
- transform: (input, payload) => {
870
+ const stringSchema = new _String({ type: "string", error: params.error });
871
+ const booleanSchema = new _Boolean({ type: "boolean", error: params.error });
872
+ const codec = new _Codec({
873
+ type: "pipe",
874
+ in: stringSchema,
875
+ out: booleanSchema,
876
+ transform: ((input, payload) => {
874
877
  let data = input;
875
878
  if (params.case !== "sensitive")
876
879
  data = data.toLowerCase();
@@ -886,31 +889,23 @@ export function _stringbool(Classes, _params) {
886
889
  expected: "stringbool",
887
890
  values: [...truthySet, ...falsySet],
888
891
  input: payload.value,
889
- inst: tx,
892
+ inst: codec,
890
893
  continue: false,
891
894
  });
892
895
  return {};
893
896
  }
894
- },
895
- error: params.error,
896
- });
897
- // params.error;
898
- const innerPipe = new _Pipe({
899
- type: "pipe",
900
- in: new _String({ type: "string", error: params.error }),
901
- out: tx,
902
- error: params.error,
903
- });
904
- const outerPipe = new _Pipe({
905
- type: "pipe",
906
- in: innerPipe,
907
- out: new _Boolean({
908
- type: "boolean",
909
- error: params.error,
897
+ }),
898
+ reverseTransform: ((input, _payload) => {
899
+ if (input === true) {
900
+ return truthyArray[0] || "true";
901
+ }
902
+ else {
903
+ return falsyArray[0] || "false";
904
+ }
910
905
  }),
911
906
  error: params.error,
912
907
  });
913
- return outerPipe;
908
+ return codec;
914
909
  }
915
910
  export function _stringFormat(Class, format, fnOrRegex, _params = {}) {
916
911
  const params = util.normalizeParams(_params);
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
16
16
  }) : function(o, v) {
17
17
  o["default"] = v;
18
18
  });
19
- var __importStar = (this && this.__importStar) || function (mod) {
20
- if (mod && mod.__esModule) return mod;
21
- var result = {};
22
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
23
- __setModuleDefault(result, mod);
24
- return result;
25
- };
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
26
36
  Object.defineProperty(exports, "__esModule", { value: true });
27
37
  exports.$ZodCheckOverwrite = exports.$ZodCheckMimeType = exports.$ZodCheckProperty = exports.$ZodCheckEndsWith = exports.$ZodCheckStartsWith = exports.$ZodCheckIncludes = exports.$ZodCheckUpperCase = exports.$ZodCheckLowerCase = exports.$ZodCheckRegex = exports.$ZodCheckStringFormat = exports.$ZodCheckLengthEquals = exports.$ZodCheckMinLength = exports.$ZodCheckMaxLength = exports.$ZodCheckSizeEquals = exports.$ZodCheckMinSize = exports.$ZodCheckMaxSize = exports.$ZodCheckBigIntFormat = exports.$ZodCheckNumberFormat = exports.$ZodCheckMultipleOf = exports.$ZodCheckGreaterThan = exports.$ZodCheckLessThan = exports.$ZodCheck = void 0;
28
38
  const core = __importStar(require("./core.cjs"));
package/v4/core/core.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.globalConfig = exports.$ZodAsyncError = exports.$brand = exports.NEVER = void 0;
3
+ exports.globalConfig = exports.$ZodEncodeError = exports.$ZodAsyncError = exports.$brand = exports.NEVER = void 0;
4
4
  exports.$constructor = $constructor;
5
5
  exports.config = config;
6
6
  /** A special constant with type `never` */
@@ -59,6 +59,13 @@ class $ZodAsyncError extends Error {
59
59
  }
60
60
  }
61
61
  exports.$ZodAsyncError = $ZodAsyncError;
62
+ class $ZodEncodeError extends Error {
63
+ constructor(name) {
64
+ super(`Encountered unidirectional transform during encode: ${name}`);
65
+ this.name = "ZodEncodeError";
66
+ }
67
+ }
68
+ exports.$ZodEncodeError = $ZodEncodeError;
62
69
  exports.globalConfig = {};
63
70
  function config(newConfig) {
64
71
  if (newConfig)
@@ -26,6 +26,9 @@ export type $ZodBranded<T extends schemas.SomeType, Brand extends string | numbe
26
26
  export declare class $ZodAsyncError extends Error {
27
27
  constructor();
28
28
  }
29
+ export declare class $ZodEncodeError extends Error {
30
+ constructor(name: string);
31
+ }
29
32
  export type input<T> = T extends {
30
33
  _zod: {
31
34
  input: any;
package/v4/core/core.d.ts CHANGED
@@ -26,6 +26,9 @@ export type $ZodBranded<T extends schemas.SomeType, Brand extends string | numbe
26
26
  export declare class $ZodAsyncError extends Error {
27
27
  constructor();
28
28
  }
29
+ export declare class $ZodEncodeError extends Error {
30
+ constructor(name: string);
31
+ }
29
32
  export type input<T> = T extends {
30
33
  _zod: {
31
34
  input: any;
package/v4/core/core.js CHANGED
@@ -53,6 +53,12 @@ export class $ZodAsyncError extends Error {
53
53
  super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
54
54
  }
55
55
  }
56
+ export class $ZodEncodeError extends Error {
57
+ constructor(name) {
58
+ super(`Encountered unidirectional transform during encode: ${name}`);
59
+ this.name = "ZodEncodeError";
60
+ }
61
+ }
56
62
  export const globalConfig = {};
57
63
  export function config(newConfig) {
58
64
  if (newConfig)
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
36
  exports.$ZodRealError = exports.$ZodError = void 0;
27
37
  exports.flattenError = flattenError;
package/v4/core/index.cjs CHANGED
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
39
  exports.JSONSchema = exports.locales = exports.regexes = exports.util = void 0;
30
40
  __exportStar(require("./core.cjs"), exports);
@@ -38,7 +48,6 @@ exports.regexes = __importStar(require("./regexes.cjs"));
38
48
  exports.locales = __importStar(require("../locales/index.cjs"));
39
49
  __exportStar(require("./registries.cjs"), exports);
40
50
  __exportStar(require("./doc.cjs"), exports);
41
- __exportStar(require("./function.cjs"), exports);
42
51
  __exportStar(require("./api.cjs"), exports);
43
52
  __exportStar(require("./to-json-schema.cjs"), exports);
44
53
  exports.JSONSchema = __importStar(require("./json-schema.cjs"));
@@ -9,7 +9,6 @@ export * as regexes from "./regexes.cjs";
9
9
  export * as locales from "../locales/index.cjs";
10
10
  export * from "./registries.cjs";
11
11
  export * from "./doc.cjs";
12
- export * from "./function.cjs";
13
12
  export * from "./api.cjs";
14
13
  export * from "./to-json-schema.cjs";
15
14
  export * as JSONSchema from "./json-schema.cjs";
@@ -9,7 +9,6 @@ export * as regexes from "./regexes.js";
9
9
  export * as locales from "../locales/index.js";
10
10
  export * from "./registries.js";
11
11
  export * from "./doc.js";
12
- export * from "./function.js";
13
12
  export * from "./api.js";
14
13
  export * from "./to-json-schema.js";
15
14
  export * as JSONSchema from "./json-schema.js";
package/v4/core/index.js CHANGED
@@ -9,7 +9,6 @@ export * as regexes from "./regexes.js";
9
9
  export * as locales from "../locales/index.js";
10
10
  export * from "./registries.js";
11
11
  export * from "./doc.js";
12
- export * from "./function.js";
13
12
  export * from "./api.js";
14
13
  export * from "./to-json-schema.js";
15
14
  export * as JSONSchema from "./json-schema.js";
@@ -56,6 +56,7 @@ export type JSONSchema = {
56
56
  deprecated?: boolean;
57
57
  readOnly?: boolean;
58
58
  writeOnly?: boolean;
59
+ nullable?: boolean;
59
60
  examples?: unknown[];
60
61
  format?: string;
61
62
  contentMediaType?: string;
@@ -56,6 +56,7 @@ export type JSONSchema = {
56
56
  deprecated?: boolean;
57
57
  readOnly?: boolean;
58
58
  writeOnly?: boolean;
59
+ nullable?: boolean;
59
60
  examples?: unknown[];
60
61
  format?: string;
61
62
  contentMediaType?: string;
package/v4/core/parse.cjs CHANGED
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
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
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.safeParseAsync = exports._safeParseAsync = exports.safeParse = exports._safeParse = exports.parseAsync = exports._parseAsync = exports.parse = exports._parse = void 0;
36
+ exports.safeDecodeAsync = exports._safeDecodeAsync = exports.safeEncodeAsync = exports._safeEncodeAsync = exports.safeDecode = exports._safeDecode = exports.safeEncode = exports._safeEncode = exports.decodeAsync = exports._decodeAsync = exports.encodeAsync = exports._encodeAsync = exports.decode = exports._decode = exports.encode = exports._encode = exports.safeParseAsync = exports._safeParseAsync = exports.safeParse = exports._safeParse = exports.parseAsync = exports._parseAsync = exports.parse = exports._parse = void 0;
27
37
  const core = __importStar(require("./core.cjs"));
28
38
  const errors = __importStar(require("./errors.cjs"));
29
39
  const util = __importStar(require("./util.cjs"));
@@ -85,3 +95,47 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
85
95
  };
86
96
  exports._safeParseAsync = _safeParseAsync;
87
97
  exports.safeParseAsync = (0, exports._safeParseAsync)(errors.$ZodRealError);
98
+ const _encode = (_Err) => (schema, value, _ctx) => {
99
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
100
+ return (0, exports._parse)(_Err)(schema, value, ctx);
101
+ };
102
+ exports._encode = _encode;
103
+ exports.encode = (0, exports._encode)(errors.$ZodRealError);
104
+ const _decode = (_Err) => (schema, value, _ctx) => {
105
+ return (0, exports._parse)(_Err)(schema, value, _ctx);
106
+ };
107
+ exports._decode = _decode;
108
+ exports.decode = (0, exports._decode)(errors.$ZodRealError);
109
+ const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
110
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
111
+ return (0, exports._parseAsync)(_Err)(schema, value, ctx);
112
+ };
113
+ exports._encodeAsync = _encodeAsync;
114
+ exports.encodeAsync = (0, exports._encodeAsync)(errors.$ZodRealError);
115
+ const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
116
+ return (0, exports._parseAsync)(_Err)(schema, value, _ctx);
117
+ };
118
+ exports._decodeAsync = _decodeAsync;
119
+ exports.decodeAsync = (0, exports._decodeAsync)(errors.$ZodRealError);
120
+ const _safeEncode = (_Err) => (schema, value, _ctx) => {
121
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
122
+ return (0, exports._safeParse)(_Err)(schema, value, ctx);
123
+ };
124
+ exports._safeEncode = _safeEncode;
125
+ exports.safeEncode = (0, exports._safeEncode)(errors.$ZodRealError);
126
+ const _safeDecode = (_Err) => (schema, value, _ctx) => {
127
+ return (0, exports._safeParse)(_Err)(schema, value, _ctx);
128
+ };
129
+ exports._safeDecode = _safeDecode;
130
+ exports.safeDecode = (0, exports._safeDecode)(errors.$ZodRealError);
131
+ const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
132
+ const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
133
+ return (0, exports._safeParseAsync)(_Err)(schema, value, ctx);
134
+ };
135
+ exports._safeEncodeAsync = _safeEncodeAsync;
136
+ exports.safeEncodeAsync = (0, exports._safeEncodeAsync)(errors.$ZodRealError);
137
+ const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
138
+ return (0, exports._safeParseAsync)(_Err)(schema, value, _ctx);
139
+ };
140
+ exports._safeDecodeAsync = _safeDecodeAsync;
141
+ exports.safeDecodeAsync = (0, exports._safeDecodeAsync)(errors.$ZodRealError);