zod 4.1.11 → 4.1.13-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/index.cjs CHANGED
@@ -10,24 +10,17 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
10
10
  if (k2 === undefined) k2 = k;
11
11
  o[k2] = m[k];
12
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 (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
- };
25
13
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
15
  };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
28
19
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.z = void 0;
30
- const z = __importStar(require("./v4/classic/external.cjs"));
31
- exports.z = z;
32
- __exportStar(require("./v4/classic/external.cjs"), exports);
33
- exports.default = z;
20
+ const index_js_1 = __importDefault(require("./v4/classic/index.cjs"));
21
+ __exportStar(require("./v4/classic/index.cjs"), exports);
22
+ // export { z };
23
+ exports.default = index_js_1.default;
24
+ // import z4 from "./classic/index.js";
25
+ // export * from "./classic/index.js";
26
+ // export default z4;
package/index.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- import * as z from "./v4/classic/external.cjs";
2
- export * from "./v4/classic/external.cjs";
3
- export { z };
4
- export default z;
1
+ import z4 from "./v4/classic/index.cjs";
2
+ export * from "./v4/classic/index.cjs";
3
+ export default z4;
package/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as z from "./v4/classic/external.js";
2
- export * from "./v4/classic/external.js";
3
- export { z };
4
- export default z;
1
+ import z4 from "./v4/classic/index.js";
2
+ export * from "./v4/classic/index.js";
3
+ export default z4;
package/index.js CHANGED
@@ -1,4 +1,7 @@
1
- import * as z from "./v4/classic/external.js";
2
- export * from "./v4/classic/external.js";
3
- export { z };
4
- export default z;
1
+ import z4 from "./v4/classic/index.js";
2
+ export * from "./v4/classic/index.js";
3
+ // export { z };
4
+ export default z4;
5
+ // import z4 from "./classic/index.js";
6
+ // export * from "./classic/index.js";
7
+ // export default z4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zod",
3
- "version": "4.1.11",
3
+ "version": "4.1.13-beta.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "author": "Colin McDonnell <zod@colinhacks.com>",
package/src/index.ts CHANGED
@@ -1,4 +1,9 @@
1
- import * as z from "./v4/classic/external.js";
2
- export * from "./v4/classic/external.js";
3
- export { z };
4
- export default z;
1
+ import z4 from "./v4/classic/index.js";
2
+ export * from "./v4/classic/index.js";
3
+ // export { z };
4
+ export default z4;
5
+
6
+ // import z4 from "./classic/index.js";
7
+ // export * from "./classic/index.js";
8
+
9
+ // export default z4;
@@ -296,7 +296,7 @@ export class ZodError<T = any> extends Error {
296
296
  flatten(): typeToFlattenedError<T>;
297
297
  flatten<U>(mapper?: (issue: ZodIssue) => U): typeToFlattenedError<T, U>;
298
298
  flatten<U = string>(mapper: (issue: ZodIssue) => U = (issue: ZodIssue) => issue.message as any): any {
299
- const fieldErrors: any = {};
299
+ const fieldErrors: any = Object.create(null);
300
300
  const formErrors: U[] = [];
301
301
  for (const sub of this.issues) {
302
302
  if (sub.path.length > 0) {
@@ -19,7 +19,14 @@ export /*@__NO_SIDE_EFFECTS__*/ function $constructor<T extends ZodTrait, D = T[
19
19
  initializer: (inst: T, def: D) => void,
20
20
  params?: { Parent?: typeof Class }
21
21
  ): $constructor<T, D> {
22
+ // const initCache = new WeakMap<any, boolean>();
22
23
  function init(inst: T, def: D) {
24
+ // if (initCache.get(def)) {
25
+ // console.log("skipping init", name);
26
+ // return;
27
+ // }
28
+ // console.log("init", name);
29
+ // initCache.set(def, true);
23
30
  Object.defineProperty(inst, "_zod", {
24
31
  value: inst._zod ?? {},
25
32
  enumerable: false,
@@ -226,9 +226,9 @@ type _FlattenedError<T, U = string> = {
226
226
 
227
227
  export function flattenError<T>(error: $ZodError<T>): _FlattenedError<T>;
228
228
  export function flattenError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): _FlattenedError<T, U>;
229
- export function flattenError(error: $ZodError, mapper = (issue: $ZodIssue) => issue.message): any {
230
- const fieldErrors: any = {};
231
- const formErrors: any[] = [];
229
+ export function flattenError<T, U>(error: $ZodError<T>, mapper = (issue: $ZodIssue) => issue.message as U) {
230
+ const fieldErrors: Record<PropertyKey, any> = {};
231
+ const formErrors: U[] = [];
232
232
  for (const sub of error.issues) {
233
233
  if (sub.path.length > 0) {
234
234
  fieldErrors[sub.path[0]!] = fieldErrors[sub.path[0]!] || [];
@@ -254,12 +254,7 @@ export type $ZodFormattedError<T, U = string> = {
254
254
 
255
255
  export function formatError<T>(error: $ZodError<T>): $ZodFormattedError<T>;
256
256
  export function formatError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodFormattedError<T, U>;
257
- export function formatError<T>(error: $ZodError, _mapper?: any) {
258
- const mapper: (issue: $ZodIssue) => any =
259
- _mapper ||
260
- function (issue: $ZodIssue) {
261
- return issue.message;
262
- };
257
+ export function formatError<T, U>(error: $ZodError<T>, mapper = (issue: $ZodIssue) => issue.message as U) {
263
258
  const fieldErrors: $ZodFormattedError<T> = { _errors: [] } as any;
264
259
  const processError = (error: { issues: $ZodIssue[] }) => {
265
260
  for (const issue of error.issues) {
@@ -307,13 +302,8 @@ export type $ZodErrorTree<T, U = string> = T extends util.Primitive
307
302
 
308
303
  export function treeifyError<T>(error: $ZodError<T>): $ZodErrorTree<T>;
309
304
  export function treeifyError<T, U>(error: $ZodError<T>, mapper?: (issue: $ZodIssue) => U): $ZodErrorTree<T, U>;
310
- export function treeifyError<T>(error: $ZodError, _mapper?: any) {
311
- const mapper: (issue: $ZodIssue) => any =
312
- _mapper ||
313
- function (issue: $ZodIssue) {
314
- return issue.message;
315
- };
316
- const result: $ZodErrorTree<T> = { errors: [] } as any;
305
+ export function treeifyError<T, U>(error: $ZodError<T>, mapper = (issue: $ZodIssue) => issue.message as U) {
306
+ const result: $ZodErrorTree<T, U> = { errors: [] } as any;
317
307
  const processError = (error: { issues: $ZodIssue[] }, path: PropertyKey[] = []) => {
318
308
  for (const issue of error.issues) {
319
309
  if (issue.code === "invalid_union" && issue.errors.length) {
@@ -489,7 +489,7 @@ export const $ZodURL: core.$constructor<$ZodURL> = /*@__PURE__*/ core.$construct
489
489
  code: "invalid_format",
490
490
  format: "url",
491
491
  note: "Invalid hostname",
492
- pattern: regexes.hostname.source,
492
+ pattern: def.hostname.source,
493
493
  input: payload.value,
494
494
  inst,
495
495
  continue: !def.abort,
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 11 as number,
4
+ patch: 12 as number,
5
5
  } as const;
@@ -1,6 +1,7 @@
1
1
  export { default as ar } from "./ar.js";
2
2
  export { default as az } from "./az.js";
3
3
  export { default as be } from "./be.js";
4
+ export { default as bg } from "./bg.js";
4
5
  export { default as ca } from "./ca.js";
5
6
  export { default as cs } from "./cs.js";
6
7
  export { default as da } from "./da.js";
package/v3/ZodError.cjs CHANGED
@@ -113,7 +113,7 @@ class ZodError extends Error {
113
113
  return this.issues.length === 0;
114
114
  }
115
115
  flatten(mapper = (issue) => issue.message) {
116
- const fieldErrors = {};
116
+ const fieldErrors = Object.create(null);
117
117
  const formErrors = [];
118
118
  for (const sub of this.issues) {
119
119
  if (sub.path.length > 0) {
package/v3/ZodError.js CHANGED
@@ -109,7 +109,7 @@ export class ZodError extends Error {
109
109
  return this.issues.length === 0;
110
110
  }
111
111
  flatten(mapper = (issue) => issue.message) {
112
- const fieldErrors = {};
112
+ const fieldErrors = Object.create(null);
113
113
  const formErrors = [];
114
114
  for (const sub of this.issues) {
115
115
  if (sub.path.length > 0) {
package/v4/core/core.cjs CHANGED
@@ -8,8 +8,15 @@ exports.NEVER = Object.freeze({
8
8
  status: "aborted",
9
9
  });
10
10
  function $constructor(name, initializer, params) {
11
+ // const initCache = new WeakMap<any, boolean>();
11
12
  function init(inst, def) {
12
13
  var _a;
14
+ // if (initCache.get(def)) {
15
+ // console.log("skipping init", name);
16
+ // return;
17
+ // }
18
+ // console.log("init", name);
19
+ // initCache.set(def, true);
13
20
  Object.defineProperty(inst, "_zod", {
14
21
  value: inst._zod ?? {},
15
22
  enumerable: false,
package/v4/core/core.js CHANGED
@@ -3,8 +3,15 @@ export const NEVER = Object.freeze({
3
3
  status: "aborted",
4
4
  });
5
5
  export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) {
6
+ // const initCache = new WeakMap<any, boolean>();
6
7
  function init(inst, def) {
7
8
  var _a;
9
+ // if (initCache.get(def)) {
10
+ // console.log("skipping init", name);
11
+ // return;
12
+ // }
13
+ // console.log("init", name);
14
+ // initCache.set(def, true);
8
15
  Object.defineProperty(inst, "_zod", {
9
16
  value: inst._zod ?? {},
10
17
  enumerable: false,
@@ -63,11 +63,7 @@ function flattenError(error, mapper = (issue) => issue.message) {
63
63
  }
64
64
  return { formErrors, fieldErrors };
65
65
  }
66
- function formatError(error, _mapper) {
67
- const mapper = _mapper ||
68
- function (issue) {
69
- return issue.message;
70
- };
66
+ function formatError(error, mapper = (issue) => issue.message) {
71
67
  const fieldErrors = { _errors: [] };
72
68
  const processError = (error) => {
73
69
  for (const issue of error.issues) {
@@ -105,11 +101,7 @@ function formatError(error, _mapper) {
105
101
  processError(error);
106
102
  return fieldErrors;
107
103
  }
108
- function treeifyError(error, _mapper) {
109
- const mapper = _mapper ||
110
- function (issue) {
111
- return issue.message;
112
- };
104
+ function treeifyError(error, mapper = (issue) => issue.message) {
113
105
  const result = { errors: [] };
114
106
  const processError = (error, path = []) => {
115
107
  var _a, _b;
package/v4/core/errors.js CHANGED
@@ -32,11 +32,7 @@ export function flattenError(error, mapper = (issue) => issue.message) {
32
32
  }
33
33
  return { formErrors, fieldErrors };
34
34
  }
35
- export function formatError(error, _mapper) {
36
- const mapper = _mapper ||
37
- function (issue) {
38
- return issue.message;
39
- };
35
+ export function formatError(error, mapper = (issue) => issue.message) {
40
36
  const fieldErrors = { _errors: [] };
41
37
  const processError = (error) => {
42
38
  for (const issue of error.issues) {
@@ -74,11 +70,7 @@ export function formatError(error, _mapper) {
74
70
  processError(error);
75
71
  return fieldErrors;
76
72
  }
77
- export function treeifyError(error, _mapper) {
78
- const mapper = _mapper ||
79
- function (issue) {
80
- return issue.message;
81
- };
73
+ export function treeifyError(error, mapper = (issue) => issue.message) {
82
74
  const result = { errors: [] };
83
75
  const processError = (error, path = []) => {
84
76
  var _a, _b;
@@ -237,7 +237,7 @@ exports.$ZodURL = core.$constructor("$ZodURL", (inst, def) => {
237
237
  code: "invalid_format",
238
238
  format: "url",
239
239
  note: "Invalid hostname",
240
- pattern: regexes.hostname.source,
240
+ pattern: def.hostname.source,
241
241
  input: payload.value,
242
242
  inst,
243
243
  continue: !def.abort,
@@ -206,7 +206,7 @@ export const $ZodURL = /*@__PURE__*/ core.$constructor("$ZodURL", (inst, def) =>
206
206
  code: "invalid_format",
207
207
  format: "url",
208
208
  note: "Invalid hostname",
209
- pattern: regexes.hostname.source,
209
+ pattern: def.hostname.source,
210
210
  input: payload.value,
211
211
  inst,
212
212
  continue: !def.abort,
@@ -4,5 +4,5 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 1,
7
- patch: 11,
7
+ patch: 12,
8
8
  };
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 1,
4
- patch: 11,
4
+ patch: 12,
5
5
  };
@@ -3,13 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.yo = exports.zhTW = exports.zhCN = exports.vi = exports.ur = exports.uk = exports.ua = exports.tr = exports.th = exports.ta = exports.sv = exports.sl = exports.ru = exports.pt = exports.pl = exports.ps = exports.ota = exports.no = exports.nl = exports.ms = exports.mk = exports.lt = exports.ko = exports.km = exports.kh = exports.ka = exports.ja = exports.it = exports.is = exports.id = exports.hu = exports.he = exports.frCA = exports.fr = exports.fi = exports.fa = exports.es = exports.eo = exports.en = exports.de = exports.da = exports.cs = exports.ca = exports.be = exports.az = exports.ar = void 0;
6
+ exports.yo = exports.zhTW = exports.zhCN = exports.vi = exports.ur = exports.uk = exports.ua = exports.tr = exports.th = exports.ta = exports.sv = exports.sl = exports.ru = exports.pt = exports.pl = exports.ps = exports.ota = exports.no = exports.nl = exports.ms = exports.mk = exports.lt = exports.ko = exports.km = exports.kh = exports.ka = exports.ja = exports.it = exports.is = exports.id = exports.hu = exports.he = exports.frCA = exports.fr = exports.fi = exports.fa = exports.es = exports.eo = exports.en = exports.de = exports.da = exports.cs = exports.ca = exports.bg = exports.be = exports.az = exports.ar = void 0;
7
7
  var ar_js_1 = require("./ar.cjs");
8
8
  Object.defineProperty(exports, "ar", { enumerable: true, get: function () { return __importDefault(ar_js_1).default; } });
9
9
  var az_js_1 = require("./az.cjs");
10
10
  Object.defineProperty(exports, "az", { enumerable: true, get: function () { return __importDefault(az_js_1).default; } });
11
11
  var be_js_1 = require("./be.cjs");
12
12
  Object.defineProperty(exports, "be", { enumerable: true, get: function () { return __importDefault(be_js_1).default; } });
13
+ var bg_js_1 = require("./bg.cjs");
14
+ Object.defineProperty(exports, "bg", { enumerable: true, get: function () { return __importDefault(bg_js_1).default; } });
13
15
  var ca_js_1 = require("./ca.cjs");
14
16
  Object.defineProperty(exports, "ca", { enumerable: true, get: function () { return __importDefault(ca_js_1).default; } });
15
17
  var cs_js_1 = require("./cs.cjs");
@@ -1,6 +1,7 @@
1
1
  export { default as ar } from "./ar.cjs";
2
2
  export { default as az } from "./az.cjs";
3
3
  export { default as be } from "./be.cjs";
4
+ export { default as bg } from "./bg.cjs";
4
5
  export { default as ca } from "./ca.cjs";
5
6
  export { default as cs } from "./cs.cjs";
6
7
  export { default as da } from "./da.cjs";
@@ -1,6 +1,7 @@
1
1
  export { default as ar } from "./ar.js";
2
2
  export { default as az } from "./az.js";
3
3
  export { default as be } from "./be.js";
4
+ export { default as bg } from "./bg.js";
4
5
  export { default as ca } from "./ca.js";
5
6
  export { default as cs } from "./cs.js";
6
7
  export { default as da } from "./da.js";
@@ -1,6 +1,7 @@
1
1
  export { default as ar } from "./ar.js";
2
2
  export { default as az } from "./az.js";
3
3
  export { default as be } from "./be.js";
4
+ export { default as bg } from "./bg.js";
4
5
  export { default as ca } from "./ca.js";
5
6
  export { default as cs } from "./cs.js";
6
7
  export { default as da } from "./da.js";