zod 4.0.9 → 4.0.11
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 +4 -4
- package/src/v4/classic/checks.ts +1 -0
- package/src/v4/classic/schemas.ts +12 -28
- package/src/v4/classic/tests/datetime.test.ts +6 -0
- package/src/v4/classic/tests/discriminated-unions.test.ts +1 -0
- package/src/v4/classic/tests/file.test.ts +5 -2
- package/src/v4/classic/tests/number.test.ts +23 -0
- package/src/v4/classic/tests/recursive-types.test.ts +39 -0
- package/src/v4/classic/tests/string.test.ts +38 -0
- package/src/v4/classic/tests/tuple.test.ts +2 -2
- package/src/v4/core/api.ts +51 -7
- package/src/v4/core/checks.ts +2 -0
- package/src/v4/core/errors.ts +27 -23
- package/src/v4/core/regexes.ts +7 -4
- package/src/v4/core/schemas.ts +44 -6
- package/src/v4/core/util.ts +11 -1
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/locales/index.ts +1 -0
- package/src/v4/locales/yo.ts +131 -0
- package/src/v4/mini/schemas.ts +11 -0
- package/v3/locales/en.cjs +1 -0
- package/v3/locales/en.d.cts +1 -1
- package/v4/classic/checks.d.cts +1 -1
- package/v4/classic/checks.d.ts +1 -1
- package/v4/classic/schemas.cjs +5 -20
- package/v4/classic/schemas.d.cts +5 -7
- package/v4/classic/schemas.d.ts +5 -7
- package/v4/classic/schemas.js +4 -20
- package/v4/core/api.cjs +33 -7
- package/v4/core/api.d.cts +12 -0
- package/v4/core/api.d.ts +12 -0
- package/v4/core/api.js +31 -7
- package/v4/core/checks.cjs +2 -0
- package/v4/core/checks.js +2 -0
- package/v4/core/errors.d.cts +18 -16
- package/v4/core/errors.d.ts +18 -16
- package/v4/core/regexes.cjs +6 -5
- package/v4/core/regexes.d.cts +1 -0
- package/v4/core/regexes.d.ts +1 -0
- package/v4/core/regexes.js +5 -4
- package/v4/core/schemas.cjs +9 -3
- package/v4/core/schemas.d.cts +5 -3
- package/v4/core/schemas.d.ts +5 -3
- package/v4/core/schemas.js +9 -3
- package/v4/core/util.cjs +9 -1
- package/v4/core/util.js +9 -1
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/locales/ar.cjs +1 -0
- package/v4/locales/ar.d.cts +2 -1
- package/v4/locales/az.cjs +1 -0
- package/v4/locales/az.d.cts +2 -1
- package/v4/locales/be.cjs +1 -0
- package/v4/locales/be.d.cts +2 -1
- package/v4/locales/ca.cjs +1 -0
- package/v4/locales/ca.d.cts +2 -1
- package/v4/locales/cs.cjs +1 -0
- package/v4/locales/cs.d.cts +2 -1
- package/v4/locales/da.cjs +1 -0
- package/v4/locales/da.d.cts +2 -1
- package/v4/locales/de.cjs +1 -0
- package/v4/locales/de.d.cts +2 -1
- package/v4/locales/es.cjs +1 -0
- package/v4/locales/es.d.cts +2 -1
- package/v4/locales/fa.cjs +1 -0
- package/v4/locales/fa.d.cts +2 -1
- package/v4/locales/fi.cjs +1 -0
- package/v4/locales/fi.d.cts +2 -1
- package/v4/locales/fr-CA.cjs +1 -0
- package/v4/locales/fr-CA.d.cts +2 -1
- package/v4/locales/fr.cjs +1 -0
- package/v4/locales/fr.d.cts +2 -1
- package/v4/locales/he.cjs +1 -0
- package/v4/locales/he.d.cts +2 -1
- package/v4/locales/hu.cjs +1 -0
- package/v4/locales/hu.d.cts +2 -1
- package/v4/locales/id.cjs +1 -0
- package/v4/locales/id.d.cts +2 -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/it.cjs +1 -0
- package/v4/locales/it.d.cts +2 -1
- package/v4/locales/ja.cjs +1 -0
- package/v4/locales/ja.d.cts +2 -1
- package/v4/locales/kh.cjs +1 -0
- package/v4/locales/kh.d.cts +2 -1
- package/v4/locales/ko.cjs +1 -0
- package/v4/locales/ko.d.cts +2 -1
- package/v4/locales/mk.cjs +1 -0
- package/v4/locales/mk.d.cts +2 -1
- package/v4/locales/ms.cjs +1 -0
- package/v4/locales/ms.d.cts +2 -1
- package/v4/locales/nl.cjs +1 -0
- package/v4/locales/nl.d.cts +2 -1
- package/v4/locales/no.cjs +1 -0
- package/v4/locales/no.d.cts +2 -1
- package/v4/locales/ota.cjs +1 -0
- package/v4/locales/ota.d.cts +2 -1
- package/v4/locales/pl.cjs +1 -0
- package/v4/locales/pl.d.cts +2 -1
- package/v4/locales/ps.cjs +1 -0
- package/v4/locales/ps.d.cts +2 -1
- package/v4/locales/pt.cjs +1 -0
- package/v4/locales/pt.d.cts +2 -1
- package/v4/locales/ru.cjs +1 -0
- package/v4/locales/ru.d.cts +2 -1
- package/v4/locales/sl.cjs +1 -0
- package/v4/locales/sl.d.cts +2 -1
- package/v4/locales/sv.cjs +1 -0
- package/v4/locales/sv.d.cts +2 -1
- package/v4/locales/ta.cjs +1 -0
- package/v4/locales/ta.d.cts +2 -1
- package/v4/locales/th.cjs +1 -0
- package/v4/locales/th.d.cts +2 -1
- package/v4/locales/ua.cjs +1 -0
- package/v4/locales/ua.d.cts +2 -1
- package/v4/locales/ur.cjs +1 -0
- package/v4/locales/ur.d.cts +2 -1
- package/v4/locales/vi.cjs +1 -0
- package/v4/locales/vi.d.cts +2 -1
- package/v4/locales/yo.cjs +142 -0
- package/v4/locales/yo.d.cts +5 -0
- package/v4/locales/yo.d.ts +4 -0
- package/v4/locales/yo.js +115 -0
- package/v4/locales/zh-CN.cjs +1 -0
- package/v4/locales/zh-CN.d.cts +2 -1
- package/v4/locales/zh-TW.cjs +1 -0
- package/v4/locales/zh-TW.d.cts +2 -1
- package/v4/mini/schemas.cjs +9 -0
- package/v4/mini/schemas.d.cts +2 -0
- package/v4/mini/schemas.d.ts +2 -0
- package/v4/mini/schemas.js +7 -0
package/src/v4/core/schemas.ts
CHANGED
|
@@ -319,6 +319,7 @@ export const $ZodString: core.$constructor<$ZodString> = /*@__PURE__*/ core.$con
|
|
|
319
319
|
payload.issues.push({
|
|
320
320
|
expected: "string",
|
|
321
321
|
code: "invalid_type",
|
|
322
|
+
|
|
322
323
|
input: payload.value,
|
|
323
324
|
inst,
|
|
324
325
|
});
|
|
@@ -1041,6 +1042,7 @@ export const $ZodNumber: core.$constructor<$ZodNumber> = /*@__PURE__*/ core.$con
|
|
|
1041
1042
|
payload.issues.push({
|
|
1042
1043
|
expected: "number",
|
|
1043
1044
|
code: "invalid_type",
|
|
1045
|
+
|
|
1044
1046
|
input,
|
|
1045
1047
|
inst,
|
|
1046
1048
|
...(received ? { received } : {}),
|
|
@@ -1111,6 +1113,7 @@ export const $ZodBoolean: core.$constructor<$ZodBoolean> = /*@__PURE__*/ core.$c
|
|
|
1111
1113
|
payload.issues.push({
|
|
1112
1114
|
expected: "boolean",
|
|
1113
1115
|
code: "invalid_type",
|
|
1116
|
+
|
|
1114
1117
|
input,
|
|
1115
1118
|
inst,
|
|
1116
1119
|
});
|
|
@@ -1163,6 +1166,7 @@ export const $ZodBigInt: core.$constructor<$ZodBigInt> = /*@__PURE__*/ core.$con
|
|
|
1163
1166
|
payload.issues.push({
|
|
1164
1167
|
expected: "bigint",
|
|
1165
1168
|
code: "invalid_type",
|
|
1169
|
+
|
|
1166
1170
|
input: payload.value,
|
|
1167
1171
|
inst,
|
|
1168
1172
|
});
|
|
@@ -1222,6 +1226,7 @@ export const $ZodSymbol: core.$constructor<$ZodSymbol> = /*@__PURE__*/ core.$con
|
|
|
1222
1226
|
payload.issues.push({
|
|
1223
1227
|
expected: "symbol",
|
|
1224
1228
|
code: "invalid_type",
|
|
1229
|
+
|
|
1225
1230
|
input,
|
|
1226
1231
|
inst,
|
|
1227
1232
|
});
|
|
@@ -1266,6 +1271,7 @@ export const $ZodUndefined: core.$constructor<$ZodUndefined> = /*@__PURE__*/ cor
|
|
|
1266
1271
|
payload.issues.push({
|
|
1267
1272
|
expected: "undefined",
|
|
1268
1273
|
code: "invalid_type",
|
|
1274
|
+
|
|
1269
1275
|
input,
|
|
1270
1276
|
inst,
|
|
1271
1277
|
});
|
|
@@ -1308,6 +1314,7 @@ export const $ZodNull: core.$constructor<$ZodNull> = /*@__PURE__*/ core.$constru
|
|
|
1308
1314
|
payload.issues.push({
|
|
1309
1315
|
expected: "null",
|
|
1310
1316
|
code: "invalid_type",
|
|
1317
|
+
|
|
1311
1318
|
input,
|
|
1312
1319
|
inst,
|
|
1313
1320
|
});
|
|
@@ -1399,6 +1406,7 @@ export const $ZodNever: core.$constructor<$ZodNever> = /*@__PURE__*/ core.$const
|
|
|
1399
1406
|
payload.issues.push({
|
|
1400
1407
|
expected: "never",
|
|
1401
1408
|
code: "invalid_type",
|
|
1409
|
+
|
|
1402
1410
|
input: payload.value,
|
|
1403
1411
|
inst,
|
|
1404
1412
|
});
|
|
@@ -1436,6 +1444,7 @@ export const $ZodVoid: core.$constructor<$ZodVoid> = /*@__PURE__*/ core.$constru
|
|
|
1436
1444
|
payload.issues.push({
|
|
1437
1445
|
expected: "void",
|
|
1438
1446
|
code: "invalid_type",
|
|
1447
|
+
|
|
1439
1448
|
input,
|
|
1440
1449
|
inst,
|
|
1441
1450
|
});
|
|
@@ -1486,6 +1495,7 @@ export const $ZodDate: core.$constructor<$ZodDate> = /*@__PURE__*/ core.$constru
|
|
|
1486
1495
|
payload.issues.push({
|
|
1487
1496
|
expected: "date",
|
|
1488
1497
|
code: "invalid_type",
|
|
1498
|
+
|
|
1489
1499
|
input,
|
|
1490
1500
|
...(isDate ? { received: "Invalid Date" } : {}),
|
|
1491
1501
|
inst,
|
|
@@ -1535,6 +1545,7 @@ export const $ZodArray: core.$constructor<$ZodArray> = /*@__PURE__*/ core.$const
|
|
|
1535
1545
|
payload.issues.push({
|
|
1536
1546
|
expected: "array",
|
|
1537
1547
|
code: "invalid_type",
|
|
1548
|
+
|
|
1538
1549
|
input,
|
|
1539
1550
|
inst,
|
|
1540
1551
|
});
|
|
@@ -1801,6 +1812,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
|
|
|
1801
1812
|
payload.issues.push({
|
|
1802
1813
|
expected: "object",
|
|
1803
1814
|
code: "invalid_type",
|
|
1815
|
+
|
|
1804
1816
|
input,
|
|
1805
1817
|
inst,
|
|
1806
1818
|
});
|
|
@@ -1854,6 +1866,7 @@ export const $ZodObject: core.$constructor<$ZodObject> = /*@__PURE__*/ core.$con
|
|
|
1854
1866
|
if (unrecognized.length) {
|
|
1855
1867
|
payload.issues.push({
|
|
1856
1868
|
code: "unrecognized_keys",
|
|
1869
|
+
|
|
1857
1870
|
keys: unrecognized,
|
|
1858
1871
|
input,
|
|
1859
1872
|
inst,
|
|
@@ -1918,6 +1931,7 @@ function handleUnionResults(results: ParsePayload[], final: ParsePayload, inst:
|
|
|
1918
1931
|
|
|
1919
1932
|
final.issues.push({
|
|
1920
1933
|
code: "invalid_union",
|
|
1934
|
+
|
|
1921
1935
|
input: final.value,
|
|
1922
1936
|
inst,
|
|
1923
1937
|
errors: results.map((result) => result.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config()))),
|
|
@@ -1952,7 +1966,13 @@ export const $ZodUnion: core.$constructor<$ZodUnion> = /*@__PURE__*/ core.$const
|
|
|
1952
1966
|
return undefined;
|
|
1953
1967
|
});
|
|
1954
1968
|
|
|
1969
|
+
const single = def.options.length === 1;
|
|
1970
|
+
const first = def.options[0]._zod.run;
|
|
1971
|
+
|
|
1955
1972
|
inst._zod.parse = (payload, ctx) => {
|
|
1973
|
+
if (single) {
|
|
1974
|
+
return first(payload, ctx);
|
|
1975
|
+
}
|
|
1956
1976
|
let async = false;
|
|
1957
1977
|
|
|
1958
1978
|
const results: util.MaybeAsync<ParsePayload>[] = [];
|
|
@@ -2048,6 +2068,7 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
|
2048
2068
|
if (!util.isObject(input)) {
|
|
2049
2069
|
payload.issues.push({
|
|
2050
2070
|
code: "invalid_type",
|
|
2071
|
+
|
|
2051
2072
|
expected: "object",
|
|
2052
2073
|
input,
|
|
2053
2074
|
inst,
|
|
@@ -2067,8 +2088,10 @@ export const $ZodDiscriminatedUnion: core.$constructor<$ZodDiscriminatedUnion> =
|
|
|
2067
2088
|
// no matching discriminator
|
|
2068
2089
|
payload.issues.push({
|
|
2069
2090
|
code: "invalid_union",
|
|
2091
|
+
|
|
2070
2092
|
errors: [],
|
|
2071
2093
|
note: "No matching discriminator",
|
|
2094
|
+
discriminator: def.discriminator,
|
|
2072
2095
|
input,
|
|
2073
2096
|
path: [def.discriminator],
|
|
2074
2097
|
inst,
|
|
@@ -2094,11 +2117,14 @@ export interface $ZodIntersectionDef<Left extends SomeType = $ZodType, Right ext
|
|
|
2094
2117
|
}
|
|
2095
2118
|
|
|
2096
2119
|
export interface $ZodIntersectionInternals<A extends SomeType = $ZodType, B extends SomeType = $ZodType>
|
|
2097
|
-
extends $ZodTypeInternals
|
|
2120
|
+
extends _$ZodTypeInternals {
|
|
2121
|
+
// $ZodTypeInternals<core.output<A> & core.output<B>, core.input<A> & core.input<B>>
|
|
2098
2122
|
def: $ZodIntersectionDef<A, B>;
|
|
2099
2123
|
isst: never;
|
|
2100
2124
|
optin: A["_zod"]["optin"] | B["_zod"]["optin"];
|
|
2101
2125
|
optout: A["_zod"]["optout"] | B["_zod"]["optout"];
|
|
2126
|
+
output: core.output<A> & core.output<B>;
|
|
2127
|
+
input: core.input<A> & core.input<B>;
|
|
2102
2128
|
}
|
|
2103
2129
|
|
|
2104
2130
|
export interface $ZodIntersection<A extends SomeType = $ZodType, B extends SomeType = $ZodType> extends $ZodType {
|
|
@@ -2293,10 +2319,11 @@ export const $ZodTuple: core.$constructor<$ZodTuple> = /*@__PURE__*/ core.$const
|
|
|
2293
2319
|
const tooSmall = input.length < optStart - 1;
|
|
2294
2320
|
if (tooBig || tooSmall) {
|
|
2295
2321
|
payload.issues.push({
|
|
2322
|
+
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
|
|
2323
|
+
|
|
2296
2324
|
input,
|
|
2297
2325
|
inst,
|
|
2298
2326
|
origin: "array" as const,
|
|
2299
|
-
...(tooBig ? { code: "too_big", maximum: items.length } : { code: "too_small", minimum: items.length }),
|
|
2300
2327
|
});
|
|
2301
2328
|
return payload;
|
|
2302
2329
|
}
|
|
@@ -2431,6 +2458,7 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2431
2458
|
payload.issues.push({
|
|
2432
2459
|
expected: "record",
|
|
2433
2460
|
code: "invalid_type",
|
|
2461
|
+
|
|
2434
2462
|
input,
|
|
2435
2463
|
inst,
|
|
2436
2464
|
});
|
|
@@ -2474,6 +2502,7 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2474
2502
|
if (unrecognized && unrecognized.length > 0) {
|
|
2475
2503
|
payload.issues.push({
|
|
2476
2504
|
code: "unrecognized_keys",
|
|
2505
|
+
|
|
2477
2506
|
input,
|
|
2478
2507
|
inst,
|
|
2479
2508
|
keys: unrecognized,
|
|
@@ -2491,8 +2520,9 @@ export const $ZodRecord: core.$constructor<$ZodRecord> = /*@__PURE__*/ core.$con
|
|
|
2491
2520
|
|
|
2492
2521
|
if (keyResult.issues.length) {
|
|
2493
2522
|
payload.issues.push({
|
|
2494
|
-
origin: "record",
|
|
2495
2523
|
code: "invalid_key",
|
|
2524
|
+
|
|
2525
|
+
origin: "record",
|
|
2496
2526
|
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
2497
2527
|
input: key,
|
|
2498
2528
|
path: [key],
|
|
@@ -2563,6 +2593,7 @@ export const $ZodMap: core.$constructor<$ZodMap> = /*@__PURE__*/ core.$construct
|
|
|
2563
2593
|
payload.issues.push({
|
|
2564
2594
|
expected: "map",
|
|
2565
2595
|
code: "invalid_type",
|
|
2596
|
+
|
|
2566
2597
|
input,
|
|
2567
2598
|
inst,
|
|
2568
2599
|
});
|
|
@@ -2606,8 +2637,9 @@ function handleMapResult(
|
|
|
2606
2637
|
final.issues.push(...util.prefixIssues(key as PropertyKey, keyResult.issues));
|
|
2607
2638
|
} else {
|
|
2608
2639
|
final.issues.push({
|
|
2609
|
-
origin: "map",
|
|
2610
2640
|
code: "invalid_key",
|
|
2641
|
+
|
|
2642
|
+
origin: "map",
|
|
2611
2643
|
input,
|
|
2612
2644
|
inst,
|
|
2613
2645
|
issues: keyResult.issues.map((iss) => util.finalizeIssue(iss, ctx, core.config())),
|
|
@@ -2621,6 +2653,7 @@ function handleMapResult(
|
|
|
2621
2653
|
final.issues.push({
|
|
2622
2654
|
origin: "map",
|
|
2623
2655
|
code: "invalid_element",
|
|
2656
|
+
|
|
2624
2657
|
input,
|
|
2625
2658
|
inst,
|
|
2626
2659
|
key: key,
|
|
@@ -2745,6 +2778,7 @@ export const $ZodEnum: core.$constructor<$ZodEnum> = /*@__PURE__*/ core.$constru
|
|
|
2745
2778
|
}
|
|
2746
2779
|
payload.issues.push({
|
|
2747
2780
|
code: "invalid_value",
|
|
2781
|
+
|
|
2748
2782
|
values,
|
|
2749
2783
|
input,
|
|
2750
2784
|
inst,
|
|
@@ -2800,6 +2834,7 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
|
|
|
2800
2834
|
}
|
|
2801
2835
|
payload.issues.push({
|
|
2802
2836
|
code: "invalid_value",
|
|
2837
|
+
|
|
2803
2838
|
values: def.values,
|
|
2804
2839
|
input,
|
|
2805
2840
|
inst,
|
|
@@ -2862,8 +2897,8 @@ export const $ZodLiteral: core.$constructor<$ZodLiteral> = /*@__PURE__*/ core.$c
|
|
|
2862
2897
|
type _File = typeof globalThis extends { File: infer F extends new (...args: any[]) => any } ? InstanceType<F> : {};
|
|
2863
2898
|
/** Do not reference this directly. */
|
|
2864
2899
|
export interface File extends _File {
|
|
2865
|
-
type: string;
|
|
2866
|
-
size: number;
|
|
2900
|
+
readonly type: string;
|
|
2901
|
+
readonly size: number;
|
|
2867
2902
|
}
|
|
2868
2903
|
|
|
2869
2904
|
export interface $ZodFileDef extends $ZodTypeDef {
|
|
@@ -2894,6 +2929,7 @@ export const $ZodFile: core.$constructor<$ZodFile> = /*@__PURE__*/ core.$constru
|
|
|
2894
2929
|
payload.issues.push({
|
|
2895
2930
|
expected: "file",
|
|
2896
2931
|
code: "invalid_type",
|
|
2932
|
+
|
|
2897
2933
|
input,
|
|
2898
2934
|
inst,
|
|
2899
2935
|
});
|
|
@@ -3202,6 +3238,7 @@ function handleNonOptionalResult(payload: ParsePayload, inst: $ZodNonOptional) {
|
|
|
3202
3238
|
if (!payload.issues.length && payload.value === undefined) {
|
|
3203
3239
|
payload.issues.push({
|
|
3204
3240
|
code: "invalid_type",
|
|
3241
|
+
|
|
3205
3242
|
expected: "nonoptional",
|
|
3206
3243
|
input: payload.value,
|
|
3207
3244
|
inst,
|
|
@@ -3622,6 +3659,7 @@ export const $ZodTemplateLiteral: core.$constructor<$ZodTemplateLiteral> = /*@__
|
|
|
3622
3659
|
payload.issues.push({
|
|
3623
3660
|
input: payload.value,
|
|
3624
3661
|
inst,
|
|
3662
|
+
|
|
3625
3663
|
code: "invalid_format",
|
|
3626
3664
|
format: def.format ?? "template_literal",
|
|
3627
3665
|
pattern: inst._zod.pattern.source,
|
package/src/v4/core/util.ts
CHANGED
|
@@ -123,6 +123,7 @@ export type Identity<T> = T;
|
|
|
123
123
|
export type Flatten<T> = Identity<{ [k in keyof T]: T[k] }>;
|
|
124
124
|
export type Mapped<T> = { [k in keyof T]: T[k] };
|
|
125
125
|
export type Prettify<T> = {
|
|
126
|
+
// @ts-ignore
|
|
126
127
|
[K in keyof T]: T[K];
|
|
127
128
|
} & {};
|
|
128
129
|
|
|
@@ -241,7 +242,15 @@ export function cleanRegex(source: string): string {
|
|
|
241
242
|
|
|
242
243
|
export function floatSafeRemainder(val: number, step: number): number {
|
|
243
244
|
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
244
|
-
const
|
|
245
|
+
const stepString = step.toString();
|
|
246
|
+
let stepDecCount = (stepString.split(".")[1] || "").length;
|
|
247
|
+
if (stepDecCount === 0 && /\d?e-\d?/.test(stepString)) {
|
|
248
|
+
const match = stepString.match(/\d?e-(\d?)/);
|
|
249
|
+
if (match?.[1]) {
|
|
250
|
+
stepDecCount = Number.parseInt(match[1]);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
245
254
|
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
246
255
|
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
247
256
|
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
@@ -717,6 +726,7 @@ export function required(
|
|
|
717
726
|
|
|
718
727
|
export type Constructor<T, Def extends any[] = any[]> = new (...args: Def) => T;
|
|
719
728
|
|
|
729
|
+
// invalid_type | too_big | too_small | invalid_format | not_multiple_of | unrecognized_keys | invalid_union | invalid_key | invalid_element | invalid_value | custom
|
|
720
730
|
export function aborted(x: schemas.ParsePayload, startIndex = 0): boolean {
|
|
721
731
|
for (let i = startIndex; i < x.issues.length; i++) {
|
|
722
732
|
if (x.issues[i]?.continue !== true) {
|
package/src/v4/core/versions.ts
CHANGED
package/src/v4/locales/index.ts
CHANGED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import type { $ZodStringFormats } from "../core/checks.js";
|
|
2
|
+
import type * as errors from "../core/errors.js";
|
|
3
|
+
import * as util from "../core/util.js";
|
|
4
|
+
|
|
5
|
+
const error: () => errors.$ZodErrorMap = () => {
|
|
6
|
+
const Sizable: Record<string, { unit: string; verb: string }> = {
|
|
7
|
+
string: { unit: "àmi", verb: "ní" },
|
|
8
|
+
file: { unit: "bytes", verb: "ní" },
|
|
9
|
+
array: { unit: "nkan", verb: "ní" },
|
|
10
|
+
set: { unit: "nkan", verb: "ní" },
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function getSizing(origin: string): { unit: string; verb: string } | null {
|
|
14
|
+
return Sizable[origin] ?? null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const parsedType = (data: any): string => {
|
|
18
|
+
const t = typeof data;
|
|
19
|
+
|
|
20
|
+
switch (t) {
|
|
21
|
+
case "number": {
|
|
22
|
+
return Number.isNaN(data) ? "NaN" : "nọ́mbà";
|
|
23
|
+
}
|
|
24
|
+
case "object": {
|
|
25
|
+
if (Array.isArray(data)) {
|
|
26
|
+
return "akopọ";
|
|
27
|
+
}
|
|
28
|
+
if (data === null) {
|
|
29
|
+
return "null";
|
|
30
|
+
}
|
|
31
|
+
if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
|
|
32
|
+
return data.constructor.name;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return t;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const Nouns: {
|
|
40
|
+
[k in $ZodStringFormats | (string & {})]?: string;
|
|
41
|
+
} = {
|
|
42
|
+
regex: "ẹ̀rọ ìbáwọlé",
|
|
43
|
+
email: "àdírẹ́sì ìmẹ́lì",
|
|
44
|
+
url: "URL",
|
|
45
|
+
emoji: "emoji",
|
|
46
|
+
uuid: "UUID",
|
|
47
|
+
uuidv4: "UUIDv4",
|
|
48
|
+
uuidv6: "UUIDv6",
|
|
49
|
+
nanoid: "nanoid",
|
|
50
|
+
guid: "GUID",
|
|
51
|
+
cuid: "cuid",
|
|
52
|
+
cuid2: "cuid2",
|
|
53
|
+
ulid: "ULID",
|
|
54
|
+
xid: "XID",
|
|
55
|
+
ksuid: "KSUID",
|
|
56
|
+
datetime: "àkókò ISO",
|
|
57
|
+
date: "ọjọ́ ISO",
|
|
58
|
+
time: "àkókò ISO",
|
|
59
|
+
duration: "àkókò tó pé ISO",
|
|
60
|
+
ipv4: "àdírẹ́sì IPv4",
|
|
61
|
+
ipv6: "àdírẹ́sì IPv6",
|
|
62
|
+
cidrv4: "àgbègbè IPv4",
|
|
63
|
+
cidrv6: "àgbègbè IPv6",
|
|
64
|
+
base64: "ọ̀rọ̀ tí a kọ́ ní base64",
|
|
65
|
+
base64url: "ọ̀rọ̀ base64url",
|
|
66
|
+
json_string: "ọ̀rọ̀ JSON",
|
|
67
|
+
e164: "nọ́mbà E.164",
|
|
68
|
+
jwt: "JWT",
|
|
69
|
+
template_literal: "ẹ̀rọ ìbáwọlé",
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
return (issue) => {
|
|
73
|
+
switch (issue.code) {
|
|
74
|
+
case "invalid_type":
|
|
75
|
+
return `Ìbáwọlé aṣìṣe: a ní láti fi ${issue.expected}, àmọ̀ a rí ${parsedType(issue.input)}`;
|
|
76
|
+
|
|
77
|
+
case "invalid_value":
|
|
78
|
+
if (issue.values.length === 1) return `Ìbáwọlé aṣìṣe: a ní láti fi ${util.stringifyPrimitive(issue.values[0])}`;
|
|
79
|
+
return `Àṣàyàn aṣìṣe: yan ọ̀kan lára ${util.joinValues(issue.values, "|")}`;
|
|
80
|
+
|
|
81
|
+
case "too_big": {
|
|
82
|
+
const adj = issue.inclusive ? "<=" : "<";
|
|
83
|
+
const sizing = getSizing(issue.origin);
|
|
84
|
+
if (sizing)
|
|
85
|
+
return `Tó pọ̀ jù: a ní láti jẹ́ pé ${issue.origin ?? "iye"} ${sizing.verb} ${adj}${issue.maximum} ${sizing.unit}`;
|
|
86
|
+
return `Tó pọ̀ jù: a ní láti jẹ́ ${adj}${issue.maximum}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
case "too_small": {
|
|
90
|
+
const adj = issue.inclusive ? ">=" : ">";
|
|
91
|
+
const sizing = getSizing(issue.origin);
|
|
92
|
+
if (sizing)
|
|
93
|
+
return `Kéré ju: a ní láti jẹ́ pé ${issue.origin} ${sizing.verb} ${adj}${issue.minimum} ${sizing.unit}`;
|
|
94
|
+
return `Kéré ju: a ní láti jẹ́ ${adj}${issue.minimum}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
case "invalid_format": {
|
|
98
|
+
const _issue = issue as errors.$ZodStringFormatIssues;
|
|
99
|
+
if (_issue.format === "starts_with") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ bẹ̀rẹ̀ pẹ̀lú "${_issue.prefix}"`;
|
|
100
|
+
if (_issue.format === "ends_with") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ parí pẹ̀lú "${_issue.suffix}"`;
|
|
101
|
+
if (_issue.format === "includes") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ ní "${_issue.includes}"`;
|
|
102
|
+
if (_issue.format === "regex") return `Ọ̀rọ̀ aṣìṣe: gbọ́dọ̀ bá àpẹẹrẹ mu ${_issue.pattern}`;
|
|
103
|
+
return `Aṣìṣe: ${Nouns[_issue.format] ?? issue.format}`;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
case "not_multiple_of":
|
|
107
|
+
return `Nọ́mbà aṣìṣe: gbọ́dọ̀ jẹ́ èyà pípín ti ${issue.divisor}`;
|
|
108
|
+
|
|
109
|
+
case "unrecognized_keys":
|
|
110
|
+
return `Bọtìnì àìmọ̀: ${util.joinValues(issue.keys, ", ")}`;
|
|
111
|
+
|
|
112
|
+
case "invalid_key":
|
|
113
|
+
return `Bọtìnì aṣìṣe nínú ${issue.origin}`;
|
|
114
|
+
|
|
115
|
+
case "invalid_union":
|
|
116
|
+
return "Ìbáwọlé aṣìṣe";
|
|
117
|
+
|
|
118
|
+
case "invalid_element":
|
|
119
|
+
return `Iye aṣìṣe nínú ${issue.origin}`;
|
|
120
|
+
|
|
121
|
+
default:
|
|
122
|
+
return "Ìbáwọlé aṣìṣe";
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export default function (): { localeError: errors.$ZodErrorMap } {
|
|
128
|
+
return {
|
|
129
|
+
localeError: error(),
|
|
130
|
+
};
|
|
131
|
+
}
|
package/src/v4/mini/schemas.ts
CHANGED
|
@@ -436,6 +436,10 @@ export function stringFormat<Format extends string>(
|
|
|
436
436
|
return core._stringFormat(ZodMiniCustomStringFormat, format, fnOrRegex, _params) as any;
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
+
export function hostname(_params?: string | core.$ZodStringFormatParams): ZodMiniCustomStringFormat<"hostname"> {
|
|
440
|
+
return core._stringFormat(ZodMiniCustomStringFormat, "hostname", core.regexes.hostname, _params) as any;
|
|
441
|
+
}
|
|
442
|
+
|
|
439
443
|
// ZodMiniNumber
|
|
440
444
|
interface _ZodMiniNumber<T extends core.$ZodNumberInternals<unknown> = core.$ZodNumberInternals<unknown>>
|
|
441
445
|
extends _ZodMiniType<T>,
|
|
@@ -1520,6 +1524,13 @@ export function refine<T>(
|
|
|
1520
1524
|
return core._refine(ZodMiniCustom, fn, _params);
|
|
1521
1525
|
}
|
|
1522
1526
|
|
|
1527
|
+
// superRefine
|
|
1528
|
+
export function superRefine<T>(
|
|
1529
|
+
fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>
|
|
1530
|
+
): core.$ZodCheck<T> {
|
|
1531
|
+
return core._superRefine(fn);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1523
1534
|
// instanceof
|
|
1524
1535
|
abstract class Class {
|
|
1525
1536
|
constructor(..._args: any[]) {}
|
package/v3/locales/en.cjs
CHANGED
package/v3/locales/en.d.cts
CHANGED
package/v4/classic/checks.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.cjs";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
|
package/v4/classic/checks.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.js";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
|
package/v4/classic/schemas.cjs
CHANGED
|
@@ -49,6 +49,7 @@ exports.base64url = base64url;
|
|
|
49
49
|
exports.e164 = e164;
|
|
50
50
|
exports.jwt = jwt;
|
|
51
51
|
exports.stringFormat = stringFormat;
|
|
52
|
+
exports.hostname = hostname;
|
|
52
53
|
exports.number = number;
|
|
53
54
|
exports.int = int;
|
|
54
55
|
exports.float32 = float32;
|
|
@@ -416,6 +417,9 @@ exports.ZodCustomStringFormat = core.$constructor("ZodCustomStringFormat", (inst
|
|
|
416
417
|
function stringFormat(format, fnOrRegex, _params = {}) {
|
|
417
418
|
return core._stringFormat(exports.ZodCustomStringFormat, format, fnOrRegex, _params);
|
|
418
419
|
}
|
|
420
|
+
function hostname(_params) {
|
|
421
|
+
return core._stringFormat(exports.ZodCustomStringFormat, "hostname", core.regexes.hostname, _params);
|
|
422
|
+
}
|
|
419
423
|
exports.ZodNumber = core.$constructor("ZodNumber", (inst, def) => {
|
|
420
424
|
core.$ZodNumber.init(inst, def);
|
|
421
425
|
exports.ZodType.init(inst, def);
|
|
@@ -1056,26 +1060,7 @@ function refine(fn, _params = {}) {
|
|
|
1056
1060
|
}
|
|
1057
1061
|
// superRefine
|
|
1058
1062
|
function superRefine(fn) {
|
|
1059
|
-
|
|
1060
|
-
payload.addIssue = (issue) => {
|
|
1061
|
-
if (typeof issue === "string") {
|
|
1062
|
-
payload.issues.push(index_js_1.util.issue(issue, payload.value, ch._zod.def));
|
|
1063
|
-
}
|
|
1064
|
-
else {
|
|
1065
|
-
// for Zod 3 backwards compatibility
|
|
1066
|
-
const _issue = issue;
|
|
1067
|
-
if (_issue.fatal)
|
|
1068
|
-
_issue.continue = false;
|
|
1069
|
-
_issue.code ?? (_issue.code = "custom");
|
|
1070
|
-
_issue.input ?? (_issue.input = payload.value);
|
|
1071
|
-
_issue.inst ?? (_issue.inst = ch);
|
|
1072
|
-
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
1073
|
-
payload.issues.push(index_js_1.util.issue(_issue));
|
|
1074
|
-
}
|
|
1075
|
-
};
|
|
1076
|
-
return fn(payload.value, payload);
|
|
1077
|
-
});
|
|
1078
|
-
return ch;
|
|
1063
|
+
return core._superRefine(fn);
|
|
1079
1064
|
}
|
|
1080
1065
|
function _instanceof(cls, params = {
|
|
1081
1066
|
error: `Input not instance of ${cls.name}`,
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as core from "../core/index.cjs";
|
|
2
2
|
import { util } from "../core/index.cjs";
|
|
3
3
|
import * as parse from "./parse.cjs";
|
|
4
|
-
export interface RefinementCtx<T = unknown> extends core.ParsePayload<T> {
|
|
5
|
-
addIssue(arg: string | core.$ZodRawIssue | Partial<core.$ZodIssueCustom>): void;
|
|
6
|
-
}
|
|
7
4
|
export interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
|
|
8
5
|
def: Internals["def"];
|
|
9
6
|
type: Internals["def"]["type"];
|
|
@@ -25,7 +22,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
25
22
|
safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
|
|
26
23
|
spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
|
|
27
24
|
refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
|
|
28
|
-
superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
|
|
25
|
+
superRefine(refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>): this;
|
|
29
26
|
overwrite(fn: (x: core.output<this>) => core.output<this>): this;
|
|
30
27
|
optional(): ZodOptional<this>;
|
|
31
28
|
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
|
|
@@ -38,7 +35,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
38
35
|
array(): ZodArray<this>;
|
|
39
36
|
or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
|
|
40
37
|
and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
|
|
41
|
-
transform<NewOut>(transform: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
|
|
38
|
+
transform<NewOut>(transform: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
|
|
42
39
|
catch(def: core.output<this>): ZodCatch<this>;
|
|
43
40
|
catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
|
|
44
41
|
pipe<T extends core.$ZodType<any, core.output<this>>>(target: T | core.$ZodType<any, core.output<this>>): ZodPipe<this, T>;
|
|
@@ -257,6 +254,7 @@ export interface ZodCustomStringFormat<Format extends string = string> extends Z
|
|
|
257
254
|
}
|
|
258
255
|
export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat>;
|
|
259
256
|
export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
|
|
257
|
+
export declare function hostname(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hostname">;
|
|
260
258
|
export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals> extends _ZodType<Internals> {
|
|
261
259
|
gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
|
|
262
260
|
/** Identical to .min() */
|
|
@@ -596,7 +594,7 @@ export declare const ZodCustom: core.$constructor<ZodCustom>;
|
|
|
596
594
|
export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
|
|
597
595
|
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
|
|
598
596
|
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
599
|
-
export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
|
|
597
|
+
export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
|
|
600
598
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
601
599
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
|
|
602
600
|
export { _instanceof as instanceof };
|
|
@@ -618,4 +616,4 @@ export interface ZodJSONSchema extends _ZodJSONSchema {
|
|
|
618
616
|
_zod: ZodJSONSchemaInternals;
|
|
619
617
|
}
|
|
620
618
|
export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
|
|
621
|
-
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
|
|
619
|
+
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import * as core from "../core/index.js";
|
|
2
2
|
import { util } from "../core/index.js";
|
|
3
3
|
import * as parse from "./parse.js";
|
|
4
|
-
export interface RefinementCtx<T = unknown> extends core.ParsePayload<T> {
|
|
5
|
-
addIssue(arg: string | core.$ZodRawIssue | Partial<core.$ZodIssueCustom>): void;
|
|
6
|
-
}
|
|
7
4
|
export interface ZodType<out Output = unknown, out Input = unknown, out Internals extends core.$ZodTypeInternals<Output, Input> = core.$ZodTypeInternals<Output, Input>> extends core.$ZodType<Output, Input, Internals> {
|
|
8
5
|
def: Internals["def"];
|
|
9
6
|
type: Internals["def"]["type"];
|
|
@@ -25,7 +22,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
25
22
|
safeParseAsync(data: unknown, params?: core.ParseContext<core.$ZodIssue>): Promise<parse.ZodSafeParseResult<core.output<this>>>;
|
|
26
23
|
spa: (data: unknown, params?: core.ParseContext<core.$ZodIssue>) => Promise<parse.ZodSafeParseResult<core.output<this>>>;
|
|
27
24
|
refine(check: (arg: core.output<this>) => unknown | Promise<unknown>, params?: string | core.$ZodCustomParams): this;
|
|
28
|
-
superRefine(refinement: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => void | Promise<void>): this;
|
|
25
|
+
superRefine(refinement: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => void | Promise<void>): this;
|
|
29
26
|
overwrite(fn: (x: core.output<this>) => core.output<this>): this;
|
|
30
27
|
optional(): ZodOptional<this>;
|
|
31
28
|
nonoptional(params?: string | core.$ZodNonOptionalParams): ZodNonOptional<this>;
|
|
@@ -38,7 +35,7 @@ export interface ZodType<out Output = unknown, out Input = unknown, out Internal
|
|
|
38
35
|
array(): ZodArray<this>;
|
|
39
36
|
or<T extends core.SomeType>(option: T): ZodUnion<[this, T]>;
|
|
40
37
|
and<T extends core.SomeType>(incoming: T): ZodIntersection<this, T>;
|
|
41
|
-
transform<NewOut>(transform: (arg: core.output<this>, ctx: RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
|
|
38
|
+
transform<NewOut>(transform: (arg: core.output<this>, ctx: core.$RefinementCtx<core.output<this>>) => NewOut | Promise<NewOut>): ZodPipe<this, ZodTransform<Awaited<NewOut>, core.output<this>>>;
|
|
42
39
|
catch(def: core.output<this>): ZodCatch<this>;
|
|
43
40
|
catch(def: (ctx: core.$ZodCatchCtx) => core.output<this>): ZodCatch<this>;
|
|
44
41
|
pipe<T extends core.$ZodType<any, core.output<this>>>(target: T | core.$ZodType<any, core.output<this>>): ZodPipe<this, T>;
|
|
@@ -257,6 +254,7 @@ export interface ZodCustomStringFormat<Format extends string = string> extends Z
|
|
|
257
254
|
}
|
|
258
255
|
export declare const ZodCustomStringFormat: core.$constructor<ZodCustomStringFormat>;
|
|
259
256
|
export declare function stringFormat<Format extends string>(format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<Format>;
|
|
257
|
+
export declare function hostname(_params?: string | core.$ZodStringFormatParams): ZodCustomStringFormat<"hostname">;
|
|
260
258
|
export interface _ZodNumber<Internals extends core.$ZodNumberInternals = core.$ZodNumberInternals> extends _ZodType<Internals> {
|
|
261
259
|
gt(value: number, params?: string | core.$ZodCheckGreaterThanParams): this;
|
|
262
260
|
/** Identical to .min() */
|
|
@@ -596,7 +594,7 @@ export declare const ZodCustom: core.$constructor<ZodCustom>;
|
|
|
596
594
|
export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<O>;
|
|
597
595
|
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
|
|
598
596
|
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
599
|
-
export declare function superRefine<T>(fn: (arg: T, payload: RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
|
|
597
|
+
export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
|
|
600
598
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
601
599
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
|
|
602
600
|
export { _instanceof as instanceof };
|
|
@@ -618,4 +616,4 @@ export interface ZodJSONSchema extends _ZodJSONSchema {
|
|
|
618
616
|
_zod: ZodJSONSchemaInternals;
|
|
619
617
|
}
|
|
620
618
|
export declare function json(params?: string | core.$ZodCustomParams): ZodJSONSchema;
|
|
621
|
-
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
|
|
619
|
+
export declare function preprocess<A, U extends core.SomeType, B = unknown>(fn: (arg: B, ctx: core.$RefinementCtx) => A, schema: U): ZodPipe<ZodTransform<A, B>, U>;
|