zod 4.6.0 → 4.6.2
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/package.json +1 -1
- package/src/v4/classic/tests/discriminated-unions.test.ts +112 -6
- package/src/v4/classic/tests/prefault.test.ts +70 -0
- package/src/v4/classic/tests/recursive-types.test.ts +45 -0
- package/src/v4/core/compile.ts +9 -7
- package/src/v4/core/schemas.ts +45 -39
- package/src/v4/core/tests/locales/tg.test.ts +85 -0
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/locales/index.ts +1 -0
- package/src/v4/locales/tg.ts +134 -0
- package/src/v4/mini/schemas.ts +1 -1
- package/src/v4/mini/tests/index.test.ts +22 -0
- package/src/v4/mini/tests/recursive-types.test.ts +16 -0
- package/v4/core/compile.cjs +8 -7
- package/v4/core/compile.js +8 -7
- package/v4/core/schemas.cjs +46 -37
- package/v4/core/schemas.d.cts +9 -5
- package/v4/core/schemas.d.ts +9 -5
- package/v4/core/schemas.js +46 -37
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/locales/index.cjs +3 -1
- package/v4/locales/index.d.cts +1 -0
- package/v4/locales/index.d.ts +1 -0
- package/v4/locales/index.js +1 -0
- package/v4/locales/tg.cjs +143 -0
- package/v4/locales/tg.d.cts +5 -0
- package/v4/locales/tg.d.ts +4 -0
- package/v4/locales/tg.js +116 -0
- package/v4/mini/schemas.d.cts +1 -1
- package/v4/mini/schemas.d.ts +1 -1
package/v4/core/schemas.js
CHANGED
|
@@ -869,7 +869,7 @@ function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
|
869
869
|
return;
|
|
870
870
|
}
|
|
871
871
|
if (result.value === undefined) {
|
|
872
|
-
if (isPresent) {
|
|
872
|
+
if (isPresent || (optin === "defaulted" && !isOptionalOut)) {
|
|
873
873
|
final.value[key] = undefined;
|
|
874
874
|
}
|
|
875
875
|
}
|
|
@@ -1124,16 +1124,17 @@ export const $ZodObjectJIT = /*@__PURE__*/ core.$constructor("$ZodObjectJIT", (i
|
|
|
1124
1124
|
doc.write(`
|
|
1125
1125
|
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1126
1126
|
}
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1127
|
+
`);
|
|
1128
|
+
if (optin === "defaulted") {
|
|
1129
|
+
doc.write(`newResult[${k}] = ${id}.value;`);
|
|
1130
|
+
}
|
|
1131
|
+
else {
|
|
1132
|
+
doc.write(`
|
|
1133
|
+
if (${id}.value !== undefined || ${isPresent}) {
|
|
1133
1134
|
newResult[${k}] = ${id}.value;
|
|
1134
1135
|
}
|
|
1135
|
-
|
|
1136
1136
|
`);
|
|
1137
|
+
}
|
|
1137
1138
|
}
|
|
1138
1139
|
}
|
|
1139
1140
|
doc.write(`payload.value = newResult;`);
|
|
@@ -1304,22 +1305,38 @@ export const $ZodXor = /*@__PURE__*/ core.$constructor("$ZodXor", (inst, def) =>
|
|
|
1304
1305
|
});
|
|
1305
1306
|
};
|
|
1306
1307
|
});
|
|
1307
|
-
/** Returns the option
|
|
1308
|
+
/** Returns the option whose discriminator claims `value`, or throws if ambiguous. */
|
|
1308
1309
|
export function getDiscriminatedOption(union, value) {
|
|
1309
1310
|
const internals = union._zod;
|
|
1310
1311
|
let map = internals.bag.optionsMap;
|
|
1311
1312
|
if (!map) {
|
|
1312
|
-
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
|
-
}
|
|
1313
|
+
map = discriminatorMap(internals.def);
|
|
1320
1314
|
internals.bag.optionsMap = map;
|
|
1321
1315
|
}
|
|
1322
|
-
|
|
1316
|
+
const option = map.get(value);
|
|
1317
|
+
if (option === null)
|
|
1318
|
+
throw new Error(`Ambiguous discriminator value "${String(value)}"`);
|
|
1319
|
+
return option;
|
|
1320
|
+
}
|
|
1321
|
+
function discriminatorMap(def) {
|
|
1322
|
+
const map = new Map();
|
|
1323
|
+
for (const option of def.options) {
|
|
1324
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
1325
|
+
if (!values || values.size === 0)
|
|
1326
|
+
throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
1327
|
+
for (const value of values) {
|
|
1328
|
+
if (map.has(value)) {
|
|
1329
|
+
if (value !== undefined)
|
|
1330
|
+
throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
1331
|
+
// keep the collision marked so a later member cannot reclaim it
|
|
1332
|
+
map.set(value, null);
|
|
1333
|
+
}
|
|
1334
|
+
else {
|
|
1335
|
+
map.set(value, option);
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1339
|
+
return map;
|
|
1323
1340
|
}
|
|
1324
1341
|
export const $ZodDiscriminatedUnion =
|
|
1325
1342
|
/*@__PURE__*/
|
|
@@ -1329,10 +1346,13 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
|
1329
1346
|
const _super = inst._zod.parse;
|
|
1330
1347
|
util.defineLazyInternal(inst, "propValues", (zod) => {
|
|
1331
1348
|
const propValues = {};
|
|
1349
|
+
let undefinedCount = 0;
|
|
1332
1350
|
for (const option of zod.def.options) {
|
|
1333
1351
|
const pv = option._zod.propValues;
|
|
1334
1352
|
if (!pv || Object.keys(pv).length === 0)
|
|
1335
1353
|
throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
1354
|
+
if (pv[zod.def.discriminator]?.has(undefined))
|
|
1355
|
+
undefinedCount++;
|
|
1336
1356
|
for (const [k, v] of Object.entries(pv)) {
|
|
1337
1357
|
if (!Object.prototype.hasOwnProperty.call(propValues, k)) {
|
|
1338
1358
|
util.assignProp(propValues, k, new Set());
|
|
@@ -1342,6 +1362,8 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
|
1342
1362
|
}
|
|
1343
1363
|
}
|
|
1344
1364
|
}
|
|
1365
|
+
if (!zod.def.unionFallback && undefinedCount > 1)
|
|
1366
|
+
propValues[zod.def.discriminator]?.delete(undefined);
|
|
1345
1367
|
return propValues;
|
|
1346
1368
|
});
|
|
1347
1369
|
// 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 +1373,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
|
1351
1373
|
throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
1352
1374
|
}
|
|
1353
1375
|
});
|
|
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
|
-
});
|
|
1376
|
+
const disc = util.cached(() => discriminatorMap(def));
|
|
1370
1377
|
inst._zod.parse = (payload, ctx) => {
|
|
1371
1378
|
const input = payload.value;
|
|
1372
1379
|
if (!util.isObject(input)) {
|
|
@@ -1378,8 +1385,10 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
|
1378
1385
|
});
|
|
1379
1386
|
return payload;
|
|
1380
1387
|
}
|
|
1381
|
-
const
|
|
1382
|
-
|
|
1388
|
+
const value = input?.[def.discriminator];
|
|
1389
|
+
const opt = disc.value.get(value);
|
|
1390
|
+
// forward metadata cannot choose an encoder for an absent tag
|
|
1391
|
+
if (opt && (value !== undefined || ctx.direction !== "backward")) {
|
|
1383
1392
|
return opt._zod.run(payload, ctx);
|
|
1384
1393
|
}
|
|
1385
1394
|
// Fall back to union matching when the fast discriminator path fails:
|
|
@@ -1394,7 +1403,7 @@ core.$constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
|
1394
1403
|
errors: [],
|
|
1395
1404
|
note: "No matching discriminator",
|
|
1396
1405
|
discriminator: def.discriminator,
|
|
1397
|
-
options: Array.from(disc.value.keys()),
|
|
1406
|
+
options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
|
|
1398
1407
|
input,
|
|
1399
1408
|
path: [def.discriminator],
|
|
1400
1409
|
inst,
|
package/v4/core/versions.cjs
CHANGED
package/v4/core/versions.js
CHANGED
package/v4/locales/index.cjs
CHANGED
|
@@ -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");
|
package/v4/locales/index.d.cts
CHANGED
|
@@ -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";
|
package/v4/locales/index.d.ts
CHANGED
|
@@ -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";
|
package/v4/locales/index.js
CHANGED
|
@@ -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;
|
package/v4/locales/tg.js
ADDED
|
@@ -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
|
+
}
|
package/v4/mini/schemas.d.cts
CHANGED
|
@@ -367,7 +367,7 @@ export declare function _default<T extends SomeType>(innerType: T, defaultValue:
|
|
|
367
367
|
export interface ZodMiniPrefault<T extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodPrefaultInternals<T>> {
|
|
368
368
|
}
|
|
369
369
|
export declare const ZodMiniPrefault: core.$constructor<ZodMiniPrefault>;
|
|
370
|
-
export declare function prefault<T extends SomeType>(innerType: T, defaultValue:
|
|
370
|
+
export declare function prefault<T extends SomeType>(innerType: T, defaultValue: core.input<T> | (() => core.input<T>)): ZodMiniPrefault<T>;
|
|
371
371
|
export interface ZodMiniNonOptional<T extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodNonOptionalInternals<T>> {
|
|
372
372
|
}
|
|
373
373
|
export declare const ZodMiniNonOptional: core.$constructor<ZodMiniNonOptional>;
|
package/v4/mini/schemas.d.ts
CHANGED
|
@@ -367,7 +367,7 @@ export declare function _default<T extends SomeType>(innerType: T, defaultValue:
|
|
|
367
367
|
export interface ZodMiniPrefault<T extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodPrefaultInternals<T>> {
|
|
368
368
|
}
|
|
369
369
|
export declare const ZodMiniPrefault: core.$constructor<ZodMiniPrefault>;
|
|
370
|
-
export declare function prefault<T extends SomeType>(innerType: T, defaultValue:
|
|
370
|
+
export declare function prefault<T extends SomeType>(innerType: T, defaultValue: core.input<T> | (() => core.input<T>)): ZodMiniPrefault<T>;
|
|
371
371
|
export interface ZodMiniNonOptional<T extends SomeType = core.$ZodType> extends _ZodMiniType<core.$ZodNonOptionalInternals<T>> {
|
|
372
372
|
}
|
|
373
373
|
export declare const ZodMiniNonOptional: core.$constructor<ZodMiniNonOptional>;
|