zod 3.25.71 → 3.25.73

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 (45) hide show
  1. package/index.cjs +2 -2
  2. package/index.d.cts +2 -2
  3. package/index.d.ts +2 -2
  4. package/index.js +2 -2
  5. package/package.json +1 -1
  6. package/src/index.ts +2 -2
  7. package/src/v4/classic/schemas.ts +4 -2
  8. package/src/v4/classic/tests/brand.test.ts +1 -3
  9. package/src/v4/classic/tests/discriminated-unions.test.ts +27 -0
  10. package/src/v4/classic/tests/index.test.ts +1 -1
  11. package/src/v4/classic/tests/object.test.ts +11 -1
  12. package/src/v4/classic/tests/optional.test.ts +20 -0
  13. package/src/v4/classic/tests/record.test.ts +7 -1
  14. package/src/v4/classic/tests/recursive-types.test.ts +3 -2
  15. package/src/v4/classic/tests/to-json-schema.test.ts +101 -1
  16. package/src/v4/core/schemas.ts +52 -18
  17. package/src/v4/core/to-json-schema.ts +16 -9
  18. package/src/v4/locales/eo.ts +125 -0
  19. package/src/v4/locales/index.ts +1 -0
  20. package/src/v4/mini/schemas.ts +2 -2
  21. package/src/v4/mini/tests/string.test.ts +6 -0
  22. package/v4/classic/schemas.cjs +1 -1
  23. package/v4/classic/schemas.d.cts +2 -1
  24. package/v4/classic/schemas.d.ts +2 -1
  25. package/v4/classic/schemas.js +1 -1
  26. package/v4/core/schemas.cjs +18 -5
  27. package/v4/core/schemas.d.cts +18 -9
  28. package/v4/core/schemas.d.ts +18 -9
  29. package/v4/core/schemas.js +18 -5
  30. package/v4/core/to-json-schema.cjs +3 -6
  31. package/v4/core/to-json-schema.d.cts +5 -1
  32. package/v4/core/to-json-schema.d.ts +5 -1
  33. package/v4/core/to-json-schema.js +3 -6
  34. package/v4/locales/eo.cjs +144 -0
  35. package/v4/locales/eo.d.cts +5 -0
  36. package/v4/locales/eo.d.ts +5 -0
  37. package/v4/locales/eo.js +116 -0
  38. package/v4/locales/index.cjs +3 -1
  39. package/v4/locales/index.d.cts +1 -0
  40. package/v4/locales/index.d.ts +1 -0
  41. package/v4/locales/index.js +1 -0
  42. package/v4/mini/schemas.cjs +1 -1
  43. package/v4/mini/schemas.d.cts +1 -1
  44. package/v4/mini/schemas.d.ts +1 -1
  45. package/v4/mini/schemas.js +1 -1
@@ -32,7 +32,7 @@ export class JSONSchemaGenerator {
32
32
  return seen.schema;
33
33
  }
34
34
  // initialize
35
- const result = { schema: {}, count: 1, cycle: undefined };
35
+ const result = { schema: {}, count: 1, cycle: undefined, path: _params.path };
36
36
  this.seen.set(schema, result);
37
37
  // custom method overrides default behavior
38
38
  const overrideSchema = schema._zod.toJSONSchema?.();
@@ -137,11 +137,6 @@ export class JSONSchemaGenerator {
137
137
  }
138
138
  break;
139
139
  }
140
- case "undefined": {
141
- const json = _json;
142
- json.type = "null";
143
- break;
144
- }
145
140
  case "null": {
146
141
  _json.type = "null";
147
142
  break;
@@ -152,6 +147,7 @@ export class JSONSchemaGenerator {
152
147
  case "unknown": {
153
148
  break;
154
149
  }
150
+ case "undefined":
155
151
  case "never": {
156
152
  _json.not = {};
157
153
  break;
@@ -650,6 +646,7 @@ export class JSONSchemaGenerator {
650
646
  this.override({
651
647
  zodSchema: zodSchema,
652
648
  jsonSchema: schema,
649
+ path: seen.path ?? [],
653
650
  });
654
651
  };
655
652
  for (const entry of [...this.seen.entries()].reverse()) {
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.parsedType = void 0;
27
+ exports.default = default_1;
28
+ const util = __importStar(require("../core/util.cjs"));
29
+ const parsedType = (data) => {
30
+ const t = typeof data;
31
+ switch (t) {
32
+ case "number": {
33
+ return Number.isNaN(data) ? "NaN" : "nombro";
34
+ }
35
+ case "object": {
36
+ if (Array.isArray(data)) {
37
+ return "tabelo";
38
+ }
39
+ if (data === null) {
40
+ return "senvalora";
41
+ }
42
+ if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
43
+ return data.constructor.name;
44
+ }
45
+ }
46
+ }
47
+ return t;
48
+ };
49
+ exports.parsedType = parsedType;
50
+ const error = () => {
51
+ const Sizable = {
52
+ string: { unit: "karaktrojn", verb: "havi" },
53
+ file: { unit: "bajtojn", verb: "havi" },
54
+ array: { unit: "elementojn", verb: "havi" },
55
+ set: { unit: "elementojn", verb: "havi" },
56
+ };
57
+ function getSizing(origin) {
58
+ return Sizable[origin] ?? null;
59
+ }
60
+ const Nouns = {
61
+ regex: "enigo",
62
+ email: "retadreso",
63
+ url: "URL",
64
+ emoji: "emoĝio",
65
+ uuid: "UUID",
66
+ uuidv4: "UUIDv4",
67
+ uuidv6: "UUIDv6",
68
+ nanoid: "nanoid",
69
+ guid: "GUID",
70
+ cuid: "cuid",
71
+ cuid2: "cuid2",
72
+ ulid: "ULID",
73
+ xid: "XID",
74
+ ksuid: "KSUID",
75
+ datetime: "ISO-datotempo",
76
+ date: "ISO-dato",
77
+ time: "ISO-tempo",
78
+ duration: "ISO-daŭro",
79
+ ipv4: "IPv4-adreso",
80
+ ipv6: "IPv6-adreso",
81
+ cidrv4: "IPv4-rango",
82
+ cidrv6: "IPv6-rango",
83
+ base64: "64-ume kodita karaktraro",
84
+ base64url: "URL-64-ume kodita karaktraro",
85
+ json_string: "JSON-karaktraro",
86
+ e164: "E.164-nombro",
87
+ jwt: "JWT",
88
+ template_literal: "enigo",
89
+ };
90
+ return (issue) => {
91
+ switch (issue.code) {
92
+ case "invalid_type":
93
+ return `Nevalida enigo: atendiĝis ${issue.expected}, riceviĝis ${(0, exports.parsedType)(issue.input)}`;
94
+ case "invalid_value":
95
+ if (issue.values.length === 1)
96
+ return `Nevalida enigo: atendiĝis ${util.stringifyPrimitive(issue.values[0])}`;
97
+ return `Nevalida opcio: atendiĝis unu el ${util.joinValues(issue.values, "|")}`;
98
+ case "too_big": {
99
+ const adj = issue.inclusive ? "<=" : "<";
100
+ const sizing = getSizing(issue.origin);
101
+ if (sizing)
102
+ return `Tro granda: atendiĝis ke ${issue.origin ?? "valoro"} havu ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elementojn"}`;
103
+ return `Tro granda: atendiĝis ke ${issue.origin ?? "valoro"} havu ${adj}${issue.maximum.toString()}`;
104
+ }
105
+ case "too_small": {
106
+ const adj = issue.inclusive ? ">=" : ">";
107
+ const sizing = getSizing(issue.origin);
108
+ if (sizing) {
109
+ return `Tro malgranda: atendiĝis ke ${issue.origin} havu ${adj}${issue.minimum.toString()} ${sizing.unit}`;
110
+ }
111
+ return `Tro malgranda: atendiĝis ke ${issue.origin} estu ${adj}${issue.minimum.toString()}`;
112
+ }
113
+ case "invalid_format": {
114
+ const _issue = issue;
115
+ if (_issue.format === "starts_with")
116
+ return `Nevalida karaktraro: devas komenciĝi per "${_issue.prefix}"`;
117
+ if (_issue.format === "ends_with")
118
+ return `Nevalida karaktraro: devas finiĝi per "${_issue.suffix}"`;
119
+ if (_issue.format === "includes")
120
+ return `Nevalida karaktraro: devas inkluzivi "${_issue.includes}"`;
121
+ if (_issue.format === "regex")
122
+ return `Nevalida karaktraro: devas kongrui kun la modelo ${_issue.pattern}`;
123
+ return `Nevalida ${Nouns[_issue.format] ?? issue.format}`;
124
+ }
125
+ case "not_multiple_of":
126
+ return `Nevalida nombro: devas esti oblo de ${issue.divisor}`;
127
+ case "unrecognized_keys":
128
+ return `Nekonata${issue.keys.length > 1 ? "j" : ""} ŝlosilo${issue.keys.length > 1 ? "j" : ""}: ${util.joinValues(issue.keys, ", ")}`;
129
+ case "invalid_key":
130
+ return `Nevalida ŝlosilo en ${issue.origin}`;
131
+ case "invalid_union":
132
+ return "Nevalida enigo";
133
+ case "invalid_element":
134
+ return `Nevalida valoro en ${issue.origin}`;
135
+ default:
136
+ return `Nevalida enigo`;
137
+ }
138
+ };
139
+ };
140
+ function default_1() {
141
+ return {
142
+ localeError: error(),
143
+ };
144
+ }
@@ -0,0 +1,5 @@
1
+ import type * as errors from "../core/errors.cjs";
2
+ export declare const parsedType: (data: any) => string;
3
+ export default function (): {
4
+ localeError: errors.$ZodErrorMap;
5
+ };
@@ -0,0 +1,5 @@
1
+ import type * as errors from "../core/errors.js";
2
+ export declare const parsedType: (data: any) => string;
3
+ export default function (): {
4
+ localeError: errors.$ZodErrorMap;
5
+ };
@@ -0,0 +1,116 @@
1
+ import * as util from "../core/util.js";
2
+ export const parsedType = (data) => {
3
+ const t = typeof data;
4
+ switch (t) {
5
+ case "number": {
6
+ return Number.isNaN(data) ? "NaN" : "nombro";
7
+ }
8
+ case "object": {
9
+ if (Array.isArray(data)) {
10
+ return "tabelo";
11
+ }
12
+ if (data === null) {
13
+ return "senvalora";
14
+ }
15
+ if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
16
+ return data.constructor.name;
17
+ }
18
+ }
19
+ }
20
+ return t;
21
+ };
22
+ const error = () => {
23
+ const Sizable = {
24
+ string: { unit: "karaktrojn", verb: "havi" },
25
+ file: { unit: "bajtojn", verb: "havi" },
26
+ array: { unit: "elementojn", verb: "havi" },
27
+ set: { unit: "elementojn", verb: "havi" },
28
+ };
29
+ function getSizing(origin) {
30
+ return Sizable[origin] ?? null;
31
+ }
32
+ const Nouns = {
33
+ regex: "enigo",
34
+ email: "retadreso",
35
+ url: "URL",
36
+ emoji: "emoĝio",
37
+ uuid: "UUID",
38
+ uuidv4: "UUIDv4",
39
+ uuidv6: "UUIDv6",
40
+ nanoid: "nanoid",
41
+ guid: "GUID",
42
+ cuid: "cuid",
43
+ cuid2: "cuid2",
44
+ ulid: "ULID",
45
+ xid: "XID",
46
+ ksuid: "KSUID",
47
+ datetime: "ISO-datotempo",
48
+ date: "ISO-dato",
49
+ time: "ISO-tempo",
50
+ duration: "ISO-daŭro",
51
+ ipv4: "IPv4-adreso",
52
+ ipv6: "IPv6-adreso",
53
+ cidrv4: "IPv4-rango",
54
+ cidrv6: "IPv6-rango",
55
+ base64: "64-ume kodita karaktraro",
56
+ base64url: "URL-64-ume kodita karaktraro",
57
+ json_string: "JSON-karaktraro",
58
+ e164: "E.164-nombro",
59
+ jwt: "JWT",
60
+ template_literal: "enigo",
61
+ };
62
+ return (issue) => {
63
+ switch (issue.code) {
64
+ case "invalid_type":
65
+ return `Nevalida enigo: atendiĝis ${issue.expected}, riceviĝis ${parsedType(issue.input)}`;
66
+ case "invalid_value":
67
+ if (issue.values.length === 1)
68
+ return `Nevalida enigo: atendiĝis ${util.stringifyPrimitive(issue.values[0])}`;
69
+ return `Nevalida opcio: atendiĝis unu el ${util.joinValues(issue.values, "|")}`;
70
+ case "too_big": {
71
+ const adj = issue.inclusive ? "<=" : "<";
72
+ const sizing = getSizing(issue.origin);
73
+ if (sizing)
74
+ return `Tro granda: atendiĝis ke ${issue.origin ?? "valoro"} havu ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elementojn"}`;
75
+ return `Tro granda: atendiĝis ke ${issue.origin ?? "valoro"} havu ${adj}${issue.maximum.toString()}`;
76
+ }
77
+ case "too_small": {
78
+ const adj = issue.inclusive ? ">=" : ">";
79
+ const sizing = getSizing(issue.origin);
80
+ if (sizing) {
81
+ return `Tro malgranda: atendiĝis ke ${issue.origin} havu ${adj}${issue.minimum.toString()} ${sizing.unit}`;
82
+ }
83
+ return `Tro malgranda: atendiĝis ke ${issue.origin} estu ${adj}${issue.minimum.toString()}`;
84
+ }
85
+ case "invalid_format": {
86
+ const _issue = issue;
87
+ if (_issue.format === "starts_with")
88
+ return `Nevalida karaktraro: devas komenciĝi per "${_issue.prefix}"`;
89
+ if (_issue.format === "ends_with")
90
+ return `Nevalida karaktraro: devas finiĝi per "${_issue.suffix}"`;
91
+ if (_issue.format === "includes")
92
+ return `Nevalida karaktraro: devas inkluzivi "${_issue.includes}"`;
93
+ if (_issue.format === "regex")
94
+ return `Nevalida karaktraro: devas kongrui kun la modelo ${_issue.pattern}`;
95
+ return `Nevalida ${Nouns[_issue.format] ?? issue.format}`;
96
+ }
97
+ case "not_multiple_of":
98
+ return `Nevalida nombro: devas esti oblo de ${issue.divisor}`;
99
+ case "unrecognized_keys":
100
+ return `Nekonata${issue.keys.length > 1 ? "j" : ""} ŝlosilo${issue.keys.length > 1 ? "j" : ""}: ${util.joinValues(issue.keys, ", ")}`;
101
+ case "invalid_key":
102
+ return `Nevalida ŝlosilo en ${issue.origin}`;
103
+ case "invalid_union":
104
+ return "Nevalida enigo";
105
+ case "invalid_element":
106
+ return `Nevalida valoro en ${issue.origin}`;
107
+ default:
108
+ return `Nevalida enigo`;
109
+ }
110
+ };
111
+ };
112
+ export default function () {
113
+ return {
114
+ localeError: error(),
115
+ };
116
+ }
@@ -3,7 +3,7 @@ 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.zhTW = exports.zhCN = exports.vi = exports.ur = 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.ko = exports.kh = exports.ja = exports.it = exports.id = exports.hu = exports.he = exports.frCA = exports.fr = exports.fi = exports.fa = exports.es = exports.en = exports.de = exports.cs = exports.ca = exports.be = exports.az = exports.ar = void 0;
6
+ exports.zhTW = exports.zhCN = exports.vi = exports.ur = 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.ko = exports.kh = exports.ja = exports.it = exports.id = exports.hu = exports.he = exports.frCA = exports.fr = exports.fi = exports.fa = exports.es = exports.eo = exports.en = exports.de = exports.cs = exports.ca = 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");
@@ -18,6 +18,8 @@ var de_js_1 = require("./de.cjs");
18
18
  Object.defineProperty(exports, "de", { enumerable: true, get: function () { return __importDefault(de_js_1).default; } });
19
19
  var en_js_1 = require("./en.cjs");
20
20
  Object.defineProperty(exports, "en", { enumerable: true, get: function () { return __importDefault(en_js_1).default; } });
21
+ var eo_js_1 = require("./eo.cjs");
22
+ Object.defineProperty(exports, "eo", { enumerable: true, get: function () { return __importDefault(eo_js_1).default; } });
21
23
  var es_js_1 = require("./es.cjs");
22
24
  Object.defineProperty(exports, "es", { enumerable: true, get: function () { return __importDefault(es_js_1).default; } });
23
25
  var fa_js_1 = require("./fa.cjs");
@@ -5,6 +5,7 @@ export { default as ca } from "./ca.cjs";
5
5
  export { default as cs } from "./cs.cjs";
6
6
  export { default as de } from "./de.cjs";
7
7
  export { default as en } from "./en.cjs";
8
+ export { default as eo } from "./eo.cjs";
8
9
  export { default as es } from "./es.cjs";
9
10
  export { default as fa } from "./fa.cjs";
10
11
  export { default as fi } from "./fi.cjs";
@@ -5,6 +5,7 @@ export { default as ca } from "./ca.js";
5
5
  export { default as cs } from "./cs.js";
6
6
  export { default as de } from "./de.js";
7
7
  export { default as en } from "./en.js";
8
+ export { default as eo } from "./eo.js";
8
9
  export { default as es } from "./es.js";
9
10
  export { default as fa } from "./fa.js";
10
11
  export { default as fi } from "./fi.js";
@@ -5,6 +5,7 @@ export { default as ca } from "./ca.js";
5
5
  export { default as cs } from "./cs.js";
6
6
  export { default as de } from "./de.js";
7
7
  export { default as en } from "./en.js";
8
+ export { default as eo } from "./eo.js";
8
9
  export { default as es } from "./es.js";
9
10
  export { default as fa } from "./fa.js";
10
11
  export { default as fi } from "./fi.js";
@@ -565,7 +565,7 @@ function partialRecord(keyType, valueType, params) {
565
565
  return new exports.ZodMiniRecord({
566
566
  type: "record",
567
567
  keyType: union([keyType, never()]),
568
- valueType: valueType,
568
+ valueType: optional(valueType),
569
569
  ...index_js_1.util.normalizeParams(params),
570
570
  });
571
571
  }
@@ -234,7 +234,7 @@ export interface ZodMiniRecord<Key extends core.$ZodRecordKey = core.$ZodRecordK
234
234
  }
235
235
  export declare const ZodMiniRecord: core.$constructor<ZodMiniRecord>;
236
236
  export declare function record<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key, Value>;
237
- export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<ZodMiniUnion<[Key, ZodMiniNever]>, Value>;
237
+ export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key, ZodMiniOptional<Value>>;
238
238
  export interface ZodMiniMap<Key extends SomeType = core.$ZodType, Value extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodMapInternals<Key, Value>> {
239
239
  }
240
240
  export declare const ZodMiniMap: core.$constructor<ZodMiniMap>;
@@ -234,7 +234,7 @@ export interface ZodMiniRecord<Key extends core.$ZodRecordKey = core.$ZodRecordK
234
234
  }
235
235
  export declare const ZodMiniRecord: core.$constructor<ZodMiniRecord>;
236
236
  export declare function record<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key, Value>;
237
- export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<ZodMiniUnion<[Key, ZodMiniNever]>, Value>;
237
+ export declare function partialRecord<Key extends core.$ZodRecordKey, Value extends SomeType>(keyType: Key, valueType: Value, params?: string | core.$ZodRecordParams): ZodMiniRecord<Key, ZodMiniOptional<Value>>;
238
238
  export interface ZodMiniMap<Key extends SomeType = core.$ZodType, Value extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodMapInternals<Key, Value>> {
239
239
  }
240
240
  export declare const ZodMiniMap: core.$constructor<ZodMiniMap>;
@@ -455,7 +455,7 @@ export function partialRecord(keyType, valueType, params) {
455
455
  return new ZodMiniRecord({
456
456
  type: "record",
457
457
  keyType: union([keyType, never()]),
458
- valueType: valueType,
458
+ valueType: optional(valueType),
459
459
  ...util.normalizeParams(params),
460
460
  });
461
461
  }