zod 4.6.0 → 4.6.1

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.
@@ -1346,22 +1346,38 @@ exports.$ZodXor = core.$constructor("$ZodXor", (inst, def) => {
1346
1346
  });
1347
1347
  };
1348
1348
  });
1349
- /** Returns the option of `union` whose discriminator claims `value`. */
1349
+ /** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
1350
1350
  function getDiscriminatedOption(union, value) {
1351
1351
  const internals = union._zod;
1352
1352
  let map = internals.bag.optionsMap;
1353
1353
  if (!map) {
1354
- map = new Map();
1355
- const { options, discriminator } = internals.def;
1356
- for (const option of options) {
1357
- // First declaration wins, matching the order the parse path resolves a duplicate in.
1358
- for (const v of option._zod.propValues?.[discriminator] ?? [])
1359
- if (!map.has(v))
1360
- map.set(v, option);
1361
- }
1354
+ map = discriminatorMap(internals.def);
1362
1355
  internals.bag.optionsMap = map;
1363
1356
  }
1364
- return map.get(value);
1357
+ const option = map.get(value);
1358
+ if (option === null)
1359
+ throw new Error(`Ambiguous discriminator value "${String(value)}"`);
1360
+ return option;
1361
+ }
1362
+ function discriminatorMap(def) {
1363
+ const map = new Map();
1364
+ for (const option of def.options) {
1365
+ const values = option._zod.propValues?.[def.discriminator];
1366
+ if (!values || values.size === 0)
1367
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1368
+ for (const value of values) {
1369
+ if (map.has(value)) {
1370
+ if (value !== undefined)
1371
+ throw new Error(`Duplicate discriminator value "${String(value)}"`);
1372
+ // keep the collision marked so a later member cannot reclaim it
1373
+ map.set(value, null);
1374
+ }
1375
+ else {
1376
+ map.set(value, option);
1377
+ }
1378
+ }
1379
+ }
1380
+ return map;
1365
1381
  }
1366
1382
  exports.$ZodDiscriminatedUnion =
1367
1383
  /*@__PURE__*/
@@ -1371,10 +1387,13 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1371
1387
  const _super = inst._zod.parse;
1372
1388
  util.defineLazyInternal(inst, "propValues", (zod) => {
1373
1389
  const propValues = {};
1390
+ let undefinedCount = 0;
1374
1391
  for (const option of zod.def.options) {
1375
1392
  const pv = option._zod.propValues;
1376
1393
  if (!pv || Object.keys(pv).length === 0)
1377
1394
  throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
1395
+ if (pv[zod.def.discriminator]?.has(undefined))
1396
+ undefinedCount++;
1378
1397
  for (const [k, v] of Object.entries(pv)) {
1379
1398
  if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
1380
1399
  util.assignProp(propValues, k, new Set());
@@ -1384,6 +1403,8 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1384
1403
  }
1385
1404
  }
1386
1405
  }
1406
+ if (!zod.def.unionFallback && undefinedCount > 1)
1407
+ propValues[zod.def.discriminator]?.delete(undefined);
1387
1408
  return propValues;
1388
1409
  });
1389
1410
  // Checked now rather than in the lookup map below, so an option that lacks the discriminator fails at the `discriminatedUnion` call instead of on the first object parsed. Options whose shape cannot be enumerated without resolving it — pipes and lazies — are left to the map.
@@ -1393,22 +1414,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1393
1414
  throw new Error(`Invalid discriminated union option at index "${i}"`);
1394
1415
  }
1395
1416
  });
1396
- const disc = util.cached(() => {
1397
- const opts = def.options;
1398
- const map = new Map();
1399
- for (const o of opts) {
1400
- const values = o._zod.propValues?.[def.discriminator];
1401
- if (!values || values.size === 0)
1402
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1403
- for (const v of values) {
1404
- if (map.has(v)) {
1405
- throw new Error(`Duplicate discriminator value "${String(v)}"`);
1406
- }
1407
- map.set(v, o);
1408
- }
1409
- }
1410
- return map;
1411
- });
1417
+ const disc = util.cached(() => discriminatorMap(def));
1412
1418
  inst._zod.parse = (payload, ctx) => {
1413
1419
  const input = payload.value;
1414
1420
  if (!util.isObject(input)) {
@@ -1420,8 +1426,10 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1420
1426
  });
1421
1427
  return payload;
1422
1428
  }
1423
- const opt = disc.value.get(input?.[def.discriminator]);
1424
- if (opt) {
1429
+ const value = input?.[def.discriminator];
1430
+ const opt = disc.value.get(value);
1431
+ // forward metadata cannot choose an encoder for an absent tag
1432
+ if (opt && (value !== undefined || ctx.direction !== "backward")) {
1425
1433
  return opt._zod.run(payload, ctx);
1426
1434
  }
1427
1435
  // Fall back to union matching when the fast discriminator path fails:
@@ -1436,7 +1444,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1436
1444
  errors: [],
1437
1445
  note: "No matching discriminator",
1438
1446
  discriminator: def.discriminator,
1439
- options: Array.from(disc.value.keys()),
1447
+ options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
1440
1448
  input,
1441
1449
  path: [def.discriminator],
1442
1450
  inst,
@@ -631,12 +631,16 @@ type OptionalInSchema = {
631
631
  optin: "optional" | "defaulted";
632
632
  };
633
633
  };
634
- export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.output<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
634
+ export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : {
635
+ [k in string]: core.output<T[keyof T]>;
636
+ } : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
635
637
  -readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]["_zod"]["output"];
636
638
  } & {
637
639
  -readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]["_zod"]["output"];
638
640
  } & Extra>;
639
- export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.input<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
641
+ export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : {
642
+ [k in string]: core.input<T[keyof T]>;
643
+ } : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
640
644
  -readonly [k in keyof T as T[k] extends OptionalInSchema ? never : k]: T[k]["_zod"]["input"];
641
645
  } & {
642
646
  -readonly [k in keyof T as T[k] extends OptionalInSchema ? k : never]?: T[k]["_zod"]["input"];
@@ -729,7 +733,7 @@ export interface $ZodDiscriminatedUnionInternals<Options extends readonly SomeTy
729
733
  def: $ZodDiscriminatedUnionDef<Options, Disc>;
730
734
  propValues: util.PropValues;
731
735
  bag: util.LoosePartial<{
732
- optionsMap: Map<util.Primitive, $ZodType>;
736
+ optionsMap: Map<util.Primitive, $ZodType | null>;
733
737
  }>;
734
738
  }
735
739
  /** The discriminator values a member of `Options` can declare. An omittable discriminator contributes `undefined`, matching what `propValues` claims for it. */
@@ -748,7 +752,7 @@ export type $DiscriminatedOption<Options extends readonly SomeType[], Disc exten
748
752
  };
749
753
  } ? Disc extends keyof Out ? V extends Out[Disc] ? Options[I] : never : never : never;
750
754
  }[number];
751
- /** Returns the option of `union` whose discriminator claims `value`. */
755
+ /** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
752
756
  export declare function getDiscriminatedOption<Options extends readonly SomeType[], Disc extends string, const V extends $DiscriminatorValue<Options, Disc>>(union: $ZodDiscriminatedUnion<Options, Disc>, value: V): $DiscriminatedOption<Options, Disc, V>;
753
757
  export interface $ZodDiscriminatedUnion<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodType {
754
758
  _zod: $ZodDiscriminatedUnionInternals<Options, Disc>;
@@ -631,12 +631,16 @@ type OptionalInSchema = {
631
631
  optin: "optional" | "defaulted";
632
632
  };
633
633
  };
634
- export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.output<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
634
+ export type $InferObjectOutput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : {
635
+ [k in string]: core.output<T[keyof T]>;
636
+ } : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
635
637
  -readonly [k in keyof T as T[k] extends OptionalOutSchema ? never : k]: T[k]["_zod"]["output"];
636
638
  } & {
637
639
  -readonly [k in keyof T as T[k] extends OptionalOutSchema ? k : never]?: T[k]["_zod"]["output"];
638
640
  } & Extra>;
639
- export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : Record<string, core.input<T[keyof T]>> : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
641
+ export type $InferObjectInput<T extends $ZodLooseShape, Extra extends Record<string, unknown>> = string extends keyof T ? util.IsAny<T[keyof T]> extends true ? Record<string, unknown> : {
642
+ [k in string]: core.input<T[keyof T]>;
643
+ } : keyof (T & Extra) extends never ? Record<string, never> : util.Prettify<{
640
644
  -readonly [k in keyof T as T[k] extends OptionalInSchema ? never : k]: T[k]["_zod"]["input"];
641
645
  } & {
642
646
  -readonly [k in keyof T as T[k] extends OptionalInSchema ? k : never]?: T[k]["_zod"]["input"];
@@ -729,7 +733,7 @@ export interface $ZodDiscriminatedUnionInternals<Options extends readonly SomeTy
729
733
  def: $ZodDiscriminatedUnionDef<Options, Disc>;
730
734
  propValues: util.PropValues;
731
735
  bag: util.LoosePartial<{
732
- optionsMap: Map<util.Primitive, $ZodType>;
736
+ optionsMap: Map<util.Primitive, $ZodType | null>;
733
737
  }>;
734
738
  }
735
739
  /** The discriminator values a member of `Options` can declare. An omittable discriminator contributes `undefined`, matching what `propValues` claims for it. */
@@ -748,7 +752,7 @@ export type $DiscriminatedOption<Options extends readonly SomeType[], Disc exten
748
752
  };
749
753
  } ? Disc extends keyof Out ? V extends Out[Disc] ? Options[I] : never : never : never;
750
754
  }[number];
751
- /** Returns the option of `union` whose discriminator claims `value`. */
755
+ /** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
752
756
  export declare function getDiscriminatedOption<Options extends readonly SomeType[], Disc extends string, const V extends $DiscriminatorValue<Options, Disc>>(union: $ZodDiscriminatedUnion<Options, Disc>, value: V): $DiscriminatedOption<Options, Disc, V>;
753
757
  export interface $ZodDiscriminatedUnion<Options extends readonly SomeType[] = readonly $ZodType[], Disc extends string = string> extends $ZodType {
754
758
  _zod: $ZodDiscriminatedUnionInternals<Options, Disc>;
@@ -1304,22 +1304,38 @@ export const $ZodXor = /*@__PURE__*/ core.$constructor("$ZodXor", (inst, def) =>
1304
1304
  });
1305
1305
  };
1306
1306
  });
1307
- /** Returns the option of `union` whose discriminator claims `value`. */
1307
+ /** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
1308
1308
  export function getDiscriminatedOption(union, value) {
1309
1309
  const internals = union._zod;
1310
1310
  let map = internals.bag.optionsMap;
1311
1311
  if (!map) {
1312
- map = new Map();
1313
- const { options, discriminator } = internals.def;
1314
- for (const option of options) {
1315
- // First declaration wins, matching the order the parse path resolves a duplicate in.
1316
- for (const v of option._zod.propValues?.[discriminator] ?? [])
1317
- if (!map.has(v))
1318
- map.set(v, option);
1319
- }
1312
+ map = discriminatorMap(internals.def);
1320
1313
  internals.bag.optionsMap = map;
1321
1314
  }
1322
- return map.get(value);
1315
+ const option = map.get(value);
1316
+ if (option === null)
1317
+ throw new Error(`Ambiguous discriminator value "${String(value)}"`);
1318
+ return option;
1319
+ }
1320
+ function discriminatorMap(def) {
1321
+ const map = new Map();
1322
+ for (const option of def.options) {
1323
+ const values = option._zod.propValues?.[def.discriminator];
1324
+ if (!values || values.size === 0)
1325
+ throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
1326
+ for (const value of values) {
1327
+ if (map.has(value)) {
1328
+ if (value !== undefined)
1329
+ throw new Error(`Duplicate discriminator value "${String(value)}"`);
1330
+ // keep the collision marked so a later member cannot reclaim it
1331
+ map.set(value, null);
1332
+ }
1333
+ else {
1334
+ map.set(value, option);
1335
+ }
1336
+ }
1337
+ }
1338
+ return map;
1323
1339
  }
1324
1340
  export const $ZodDiscriminatedUnion =
1325
1341
  /*@__PURE__*/
@@ -1329,10 +1345,13 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1329
1345
  const _super = inst._zod.parse;
1330
1346
  util.defineLazyInternal(inst, "propValues", (zod) => {
1331
1347
  const propValues = {};
1348
+ let undefinedCount = 0;
1332
1349
  for (const option of zod.def.options) {
1333
1350
  const pv = option._zod.propValues;
1334
1351
  if (!pv || Object.keys(pv).length === 0)
1335
1352
  throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
1353
+ if (pv[zod.def.discriminator]?.has(undefined))
1354
+ undefinedCount++;
1336
1355
  for (const [k, v] of Object.entries(pv)) {
1337
1356
  if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
1338
1357
  util.assignProp(propValues, k, new Set());
@@ -1342,6 +1361,8 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1342
1361
  }
1343
1362
  }
1344
1363
  }
1364
+ if (!zod.def.unionFallback && undefinedCount > 1)
1365
+ propValues[zod.def.discriminator]?.delete(undefined);
1345
1366
  return propValues;
1346
1367
  });
1347
1368
  // Checked now rather than in the lookup map below, so an option that lacks the discriminator fails at the `discriminatedUnion` call instead of on the first object parsed. Options whose shape cannot be enumerated without resolving it — pipes and lazies — are left to the map.
@@ -1351,22 +1372,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1351
1372
  throw new Error(`Invalid discriminated union option at index "${i}"`);
1352
1373
  }
1353
1374
  });
1354
- const disc = util.cached(() => {
1355
- const opts = def.options;
1356
- const map = new Map();
1357
- for (const o of opts) {
1358
- const values = o._zod.propValues?.[def.discriminator];
1359
- if (!values || values.size === 0)
1360
- throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
1361
- for (const v of values) {
1362
- if (map.has(v)) {
1363
- throw new Error(`Duplicate discriminator value "${String(v)}"`);
1364
- }
1365
- map.set(v, o);
1366
- }
1367
- }
1368
- return map;
1369
- });
1375
+ const disc = util.cached(() => discriminatorMap(def));
1370
1376
  inst._zod.parse = (payload, ctx) => {
1371
1377
  const input = payload.value;
1372
1378
  if (!util.isObject(input)) {
@@ -1378,8 +1384,10 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1378
1384
  });
1379
1385
  return payload;
1380
1386
  }
1381
- const opt = disc.value.get(input?.[def.discriminator]);
1382
- if (opt) {
1387
+ const value = input?.[def.discriminator];
1388
+ const opt = disc.value.get(value);
1389
+ // forward metadata cannot choose an encoder for an absent tag
1390
+ if (opt && (value !== undefined || ctx.direction !== "backward")) {
1383
1391
  return opt._zod.run(payload, ctx);
1384
1392
  }
1385
1393
  // Fall back to union matching when the fast discriminator path fails:
@@ -1394,7 +1402,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
1394
1402
  errors: [],
1395
1403
  note: "No matching discriminator",
1396
1404
  discriminator: def.discriminator,
1397
- options: Array.from(disc.value.keys()),
1405
+ options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
1398
1406
  input,
1399
1407
  path: [def.discriminator],
1400
1408
  inst,
@@ -4,7 +4,7 @@ exports.version = void 0;
4
4
  exports.version = {
5
5
  major: 4,
6
6
  minor: 6,
7
- patch: 0,
7
+ patch: 1,
8
8
  };
9
9
 
10
10
  // seal-cjs-exports
@@ -1,5 +1,5 @@
1
1
  export const version = {
2
2
  major: 4,
3
3
  minor: 6,
4
- patch: 0,
4
+ patch: 1,
5
5
  };
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.sv = exports.sl = exports.sk = exports.ru = exports.ro = exports.ptBR = exports.pt = exports.pl = exports.ps = exports.ota = exports.no = exports.nn = exports.nl = exports.ne = exports.ms = exports.mk = exports.lt = exports.ko = exports.kn = exports.km = exports.kh = exports.ka = exports.ja = exports.it = exports.is = exports.id = exports.hy = exports.hu = exports.hr = exports.hi = exports.he = exports.gu = exports.frCA = exports.fr = exports.fi = exports.fa = exports.es = exports.eo = exports.en = exports.el = exports.de = exports.da = exports.cs = exports.ckb = exports.ca = exports.bn = exports.bg = exports.be = exports.az = exports.ar = void 0;
7
- exports.yo = exports.zhTW = exports.zhCN = exports.vi = exports.uz = exports.ur = exports.uk = exports.ua = exports.tr = exports.tk = exports.th = exports.ta = void 0;
7
+ exports.yo = exports.zhTW = exports.zhCN = exports.vi = exports.uz = exports.ur = exports.uk = exports.ua = exports.tr = exports.tk = exports.th = exports.tg = exports.ta = void 0;
8
8
  var ar_js_1 = require("./ar.cjs");
9
9
  Object.defineProperty(exports, "ar", { enumerable: true, get: function () { return __importDefault(ar_js_1).default; } });
10
10
  var az_js_1 = require("./az.cjs");
@@ -107,6 +107,8 @@ var sv_js_1 = require("./sv.cjs");
107
107
  Object.defineProperty(exports, "sv", { enumerable: true, get: function () { return __importDefault(sv_js_1).default; } });
108
108
  var ta_js_1 = require("./ta.cjs");
109
109
  Object.defineProperty(exports, "ta", { enumerable: true, get: function () { return __importDefault(ta_js_1).default; } });
110
+ var tg_js_1 = require("./tg.cjs");
111
+ Object.defineProperty(exports, "tg", { enumerable: true, get: function () { return __importDefault(tg_js_1).default; } });
110
112
  var th_js_1 = require("./th.cjs");
111
113
  Object.defineProperty(exports, "th", { enumerable: true, get: function () { return __importDefault(th_js_1).default; } });
112
114
  var tk_js_1 = require("./tk.cjs");
@@ -49,6 +49,7 @@ export { default as sk } from "./sk.cjs";
49
49
  export { default as sl } from "./sl.cjs";
50
50
  export { default as sv } from "./sv.cjs";
51
51
  export { default as ta } from "./ta.cjs";
52
+ export { default as tg } from "./tg.cjs";
52
53
  export { default as th } from "./th.cjs";
53
54
  export { default as tk } from "./tk.cjs";
54
55
  export { default as tr } from "./tr.cjs";
@@ -49,6 +49,7 @@ export { default as sk } from "./sk.js";
49
49
  export { default as sl } from "./sl.js";
50
50
  export { default as sv } from "./sv.js";
51
51
  export { default as ta } from "./ta.js";
52
+ export { default as tg } from "./tg.js";
52
53
  export { default as th } from "./th.js";
53
54
  export { default as tk } from "./tk.js";
54
55
  export { default as tr } from "./tr.js";
@@ -49,6 +49,7 @@ export { default as sk } from "./sk.js";
49
49
  export { default as sl } from "./sl.js";
50
50
  export { default as sv } from "./sv.js";
51
51
  export { default as ta } from "./ta.js";
52
+ export { default as tg } from "./tg.js";
52
53
  export { default as th } from "./th.js";
53
54
  export { default as tk } from "./tk.js";
54
55
  export { default as tr } from "./tr.js";
@@ -0,0 +1,143 @@
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.default = default_1;
27
+ const util = __importStar(require("../core/util.cjs"));
28
+ const error = () => {
29
+ // singular units after numerals in Tajik
30
+ const Sizable = {
31
+ string: { unit: "аломат", verb: "дошта бошад" },
32
+ file: { unit: "байт", verb: "дошта бошад" },
33
+ array: { unit: "унсур", verb: "дошта бошад" },
34
+ set: { unit: "унсур", verb: "дошта бошад" },
35
+ map: { unit: "сабт", verb: "дошта бошад" },
36
+ };
37
+ function getSizing(origin) {
38
+ return Sizable[origin] ?? null;
39
+ }
40
+ const FormatDictionary = {
41
+ regex: "вуруд",
42
+ email: "суроғаи email",
43
+ url: "URL",
44
+ emoji: "эмоҷи",
45
+ uuid: "UUID",
46
+ uuidv4: "UUIDv4",
47
+ uuidv6: "UUIDv6",
48
+ nanoid: "nanoid",
49
+ guid: "GUID",
50
+ cuid: "cuid",
51
+ cuid2: "cuid2",
52
+ ulid: "ULID",
53
+ xid: "XID",
54
+ ksuid: "KSUID",
55
+ datetime: "санаву вақти ISO",
56
+ date: "санаи ISO",
57
+ time: "вақти ISO",
58
+ duration: "давомнокии ISO",
59
+ ipv4: "суроғаи IPv4",
60
+ ipv6: "суроғаи IPv6",
61
+ mac: "суроғаи MAC",
62
+ cidrv4: "маҳдудаи IPv4",
63
+ cidrv6: "маҳдудаи IPv6",
64
+ base64: "сатри дар формати base64",
65
+ base64url: "сатри дар формати base64url",
66
+ json_string: "сатри JSON",
67
+ e164: "рақами E.164",
68
+ credit_card: "рақами корти кредитӣ",
69
+ iban: "IBAN",
70
+ jwt: "JWT",
71
+ template_literal: "вуруд",
72
+ };
73
+ const TypeDictionary = {
74
+ nan: "NaN",
75
+ number: "рақам",
76
+ string: "сатр",
77
+ array: "массив",
78
+ object: "объект",
79
+ date: "сана",
80
+ };
81
+ return (issue) => {
82
+ switch (issue.code) {
83
+ case "invalid_type": {
84
+ const expected = TypeDictionary[issue.expected] ?? issue.expected;
85
+ const receivedType = util.parsedType(issue.input);
86
+ const received = TypeDictionary[receivedType] ?? receivedType;
87
+ return `Вуруди нодуруст: ${expected} интизор мерафт, ${received} гирифта шуд`;
88
+ }
89
+ case "invalid_value":
90
+ if (issue.values.length === 1)
91
+ return `Вуруди нодуруст: ${util.stringifyPrimitive(issue.values[0])} интизор мерафт`;
92
+ return `Интихоби нодуруст: яке аз ${util.joinValues(issue.values, "|")} интизор мерафт`;
93
+ case "too_big": {
94
+ const adj = issue.inclusive ? "<=" : "<";
95
+ const sizing = getSizing(issue.origin);
96
+ if (sizing)
97
+ return `Хеле калон: ${issue.origin ?? "қимат"} бояд ${adj}${issue.maximum.toString()} ${sizing.unit} ${sizing.verb}`;
98
+ return `Хеле калон: ${issue.origin ?? "қимат"} бояд ${adj}${issue.maximum.toString()} бошад`;
99
+ }
100
+ case "too_small": {
101
+ const adj = issue.inclusive ? ">=" : ">";
102
+ const sizing = getSizing(issue.origin);
103
+ if (sizing)
104
+ return `Хеле хурд: ${issue.origin} бояд ${adj}${issue.minimum.toString()} ${sizing.unit} ${sizing.verb}`;
105
+ return `Хеле хурд: ${issue.origin} бояд ${adj}${issue.minimum.toString()} бошад`;
106
+ }
107
+ case "invalid_format": {
108
+ const _issue = issue;
109
+ if (_issue.format === "starts_with")
110
+ return `Сатри нодуруст: бояд бо "${_issue.prefix}" оғоз шавад`;
111
+ if (_issue.format === "ends_with")
112
+ return `Сатри нодуруст: бояд бо "${_issue.suffix}" анҷом ёбад`;
113
+ if (_issue.format === "includes")
114
+ return `Сатри нодуруст: бояд "${_issue.includes}"-ро дар бар гирад`;
115
+ if (_issue.format === "regex")
116
+ return `Сатри нодуруст: бояд ба намунаи ${_issue.pattern} мувофиқат кунад`;
117
+ return `${FormatDictionary[_issue.format] ?? issue.format}-и нодуруст`;
118
+ }
119
+ case "not_multiple_of":
120
+ return `Рақами нодуруст: бояд ба ${issue.divisor} бе бақия тақсим шавад`;
121
+ case "unrecognized_keys":
122
+ return `Калид${issue.keys.length > 1 ? "ҳои" : "и"} номаълум: ${util.joinValues(issue.keys, ", ")}`;
123
+ case "invalid_key":
124
+ return `Калиди нодуруст дар ${issue.origin}`;
125
+ case "invalid_union":
126
+ if (issue.options && Array.isArray(issue.options) && issue.options.length > 0) {
127
+ const opts = issue.options.map((o) => `'${o}'`).join(" | ");
128
+ return `Қимати нодурусти дискриминатор: ${opts} интизор мерафт`;
129
+ }
130
+ return "Вуруди нодуруст";
131
+ case "invalid_element":
132
+ return `Қимати нодуруст дар ${issue.origin}`;
133
+ default:
134
+ return `Вуруди нодуруст`;
135
+ }
136
+ };
137
+ };
138
+ function default_1() {
139
+ return {
140
+ localeError: error(),
141
+ };
142
+ }
143
+ module.exports = exports.default;
@@ -0,0 +1,5 @@
1
+ import type * as errors from "../core/errors.cjs";
2
+ declare function _default(): {
3
+ localeError: errors.$ZodErrorMap;
4
+ };
5
+ export = _default;
@@ -0,0 +1,4 @@
1
+ import type * as errors from "../core/errors.js";
2
+ export default function (): {
3
+ localeError: errors.$ZodErrorMap;
4
+ };
@@ -0,0 +1,116 @@
1
+ import * as util from "../core/util.js";
2
+ const error = () => {
3
+ // singular units after numerals in Tajik
4
+ const Sizable = {
5
+ string: { unit: "аломат", verb: "дошта бошад" },
6
+ file: { unit: "байт", verb: "дошта бошад" },
7
+ array: { unit: "унсур", verb: "дошта бошад" },
8
+ set: { unit: "унсур", verb: "дошта бошад" },
9
+ map: { unit: "сабт", verb: "дошта бошад" },
10
+ };
11
+ function getSizing(origin) {
12
+ return Sizable[origin] ?? null;
13
+ }
14
+ const FormatDictionary = {
15
+ regex: "вуруд",
16
+ email: "суроғаи email",
17
+ url: "URL",
18
+ emoji: "эмоҷи",
19
+ uuid: "UUID",
20
+ uuidv4: "UUIDv4",
21
+ uuidv6: "UUIDv6",
22
+ nanoid: "nanoid",
23
+ guid: "GUID",
24
+ cuid: "cuid",
25
+ cuid2: "cuid2",
26
+ ulid: "ULID",
27
+ xid: "XID",
28
+ ksuid: "KSUID",
29
+ datetime: "санаву вақти ISO",
30
+ date: "санаи ISO",
31
+ time: "вақти ISO",
32
+ duration: "давомнокии ISO",
33
+ ipv4: "суроғаи IPv4",
34
+ ipv6: "суроғаи IPv6",
35
+ mac: "суроғаи MAC",
36
+ cidrv4: "маҳдудаи IPv4",
37
+ cidrv6: "маҳдудаи IPv6",
38
+ base64: "сатри дар формати base64",
39
+ base64url: "сатри дар формати base64url",
40
+ json_string: "сатри JSON",
41
+ e164: "рақами E.164",
42
+ credit_card: "рақами корти кредитӣ",
43
+ iban: "IBAN",
44
+ jwt: "JWT",
45
+ template_literal: "вуруд",
46
+ };
47
+ const TypeDictionary = {
48
+ nan: "NaN",
49
+ number: "рақам",
50
+ string: "сатр",
51
+ array: "массив",
52
+ object: "объект",
53
+ date: "сана",
54
+ };
55
+ return (issue) => {
56
+ switch (issue.code) {
57
+ case "invalid_type": {
58
+ const expected = TypeDictionary[issue.expected] ?? issue.expected;
59
+ const receivedType = util.parsedType(issue.input);
60
+ const received = TypeDictionary[receivedType] ?? receivedType;
61
+ return `Вуруди нодуруст: ${expected} интизор мерафт, ${received} гирифта шуд`;
62
+ }
63
+ case "invalid_value":
64
+ if (issue.values.length === 1)
65
+ return `Вуруди нодуруст: ${util.stringifyPrimitive(issue.values[0])} интизор мерафт`;
66
+ return `Интихоби нодуруст: яке аз ${util.joinValues(issue.values, "|")} интизор мерафт`;
67
+ case "too_big": {
68
+ const adj = issue.inclusive ? "<=" : "<";
69
+ const sizing = getSizing(issue.origin);
70
+ if (sizing)
71
+ return `Хеле калон: ${issue.origin ?? "қимат"} бояд ${adj}${issue.maximum.toString()} ${sizing.unit} ${sizing.verb}`;
72
+ return `Хеле калон: ${issue.origin ?? "қимат"} бояд ${adj}${issue.maximum.toString()} бошад`;
73
+ }
74
+ case "too_small": {
75
+ const adj = issue.inclusive ? ">=" : ">";
76
+ const sizing = getSizing(issue.origin);
77
+ if (sizing)
78
+ return `Хеле хурд: ${issue.origin} бояд ${adj}${issue.minimum.toString()} ${sizing.unit} ${sizing.verb}`;
79
+ return `Хеле хурд: ${issue.origin} бояд ${adj}${issue.minimum.toString()} бошад`;
80
+ }
81
+ case "invalid_format": {
82
+ const _issue = issue;
83
+ if (_issue.format === "starts_with")
84
+ return `Сатри нодуруст: бояд бо "${_issue.prefix}" оғоз шавад`;
85
+ if (_issue.format === "ends_with")
86
+ return `Сатри нодуруст: бояд бо "${_issue.suffix}" анҷом ёбад`;
87
+ if (_issue.format === "includes")
88
+ return `Сатри нодуруст: бояд "${_issue.includes}"-ро дар бар гирад`;
89
+ if (_issue.format === "regex")
90
+ return `Сатри нодуруст: бояд ба намунаи ${_issue.pattern} мувофиқат кунад`;
91
+ return `${FormatDictionary[_issue.format] ?? issue.format}-и нодуруст`;
92
+ }
93
+ case "not_multiple_of":
94
+ return `Рақами нодуруст: бояд ба ${issue.divisor} бе бақия тақсим шавад`;
95
+ case "unrecognized_keys":
96
+ return `Калид${issue.keys.length > 1 ? "ҳои" : "и"} номаълум: ${util.joinValues(issue.keys, ", ")}`;
97
+ case "invalid_key":
98
+ return `Калиди нодуруст дар ${issue.origin}`;
99
+ case "invalid_union":
100
+ if (issue.options && Array.isArray(issue.options) && issue.options.length > 0) {
101
+ const opts = issue.options.map((o) => `'${o}'`).join(" | ");
102
+ return `Қимати нодурусти дискриминатор: ${opts} интизор мерафт`;
103
+ }
104
+ return "Вуруди нодуруст";
105
+ case "invalid_element":
106
+ return `Қимати нодуруст дар ${issue.origin}`;
107
+ default:
108
+ return `Вуруди нодуруст`;
109
+ }
110
+ };
111
+ };
112
+ export default function () {
113
+ return {
114
+ localeError: error(),
115
+ };
116
+ }